Search is not available for this dataset
text
string
meta
dict
module ImportTests.ExtractCaseSplit where open import ExtractCaseSplit open import Data.Maybe open import Data.Bool test : Bool test = func (just false)
{ "alphanum_fraction": 0.8129032258, "avg_line_length": 19.375, "ext": "agda", "hexsha": "943b365bbe5f3078ee09b1ec9097c1c11e191a6f", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-01-31T08:40:41.000Z", "max_forks_repo_forks_event_min_datetime": "2019-01-31T08:40:41.000Z", "max_forks_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "omega12345/RefactorAgda", "max_forks_repo_path": "RefactorAgdaEngine/Test/Tests/output/ImportTests/ExtractCaseSplit.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b", "max_issues_repo_issues_event_max_datetime": "2019-02-05T12:53:36.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-31T08:03:07.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "omega12345/RefactorAgda", "max_issues_repo_path": "RefactorAgdaEngine/Test/Tests/output/ImportTests/ExtractCaseSplit.agda", "max_line_length": 41, "max_stars_count": 5, "max_stars_repo_head_hexsha": "52d1034aed14c578c9e077fb60c3db1d0791416b", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "omega12345/RefactorAgda", "max_stars_repo_path": "RefactorAgdaEngine/Test/Tests/output/ImportTests/ExtractCaseSplit.agda", "max_stars_repo_stars_event_max_datetime": "2019-05-03T10:03:36.000Z", "max_stars_repo_stars_event_min_datetime": "2019-01-31T14:10:18.000Z", "num_tokens": 37, "size": 155 }
-- Andreas, 2016-06-11, issue reported by Mietek Bak data Foo : Foo → Set where -- WAS: Panic: unbound name Foo -- NOW: Not in scope: Foo
{ "alphanum_fraction": 0.6737588652, "avg_line_length": 17.625, "ext": "agda", "hexsha": "e929f39d676b79e0fec31621bb480bde29b865ae", "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/Issue2024-data.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/Issue2024-data.agda", "max_line_length": 52, "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/Issue2024-data.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": 46, "size": 141 }
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.types.Paths open import lib.types.Pi open import lib.types.Sigma module lib.types.Pointed where Ptd : ∀ i → Type (lsucc i) Ptd i = Σ (Type i) (λ A → A) Ptd₀ = Ptd lzero ⊙[_,_] : ∀ {i} (A : Type i) (a : A) → Ptd i ⊙[_,_] = _,_ infixr 0 _⊙→_ _⊙→_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j) (A , a₀) ⊙→ (B , b₀) = ⊙[ Σ (A → B) (λ f → f a₀ == b₀) , ((λ _ → b₀), idp) ] infix 30 _⊙≃_ _⊙≃_ : ∀ {i j} → Ptd i → Ptd j → Type (lmax i j) X ⊙≃ Y = Σ (fst (X ⊙→ Y)) (λ {(f , _) → is-equiv f}) ⊙≃-in : ∀ {i j} {X : Ptd i} {Y : Ptd j} (e : fst X ≃ fst Y) (p : –> e (snd X) == snd Y) → X ⊙≃ Y ⊙≃-in (f , ie) p = ((f , p) , ie) ⊙≃-out : ∀ {i j} {X : Ptd i} {Y : Ptd j} → X ⊙≃ Y → Σ (fst X ≃ fst Y) (λ e → –> e (snd X) == snd Y) ⊙≃-out ((f , p) , ie) = (f , ie) , p ⊙idf : ∀ {i} (X : Ptd i) → fst (X ⊙→ X) ⊙idf A = ((λ x → x) , idp) ⊙cst : ∀ {i j} {X : Ptd i} {Y : Ptd j} → fst (X ⊙→ Y) ⊙cst {Y = Y} = ((λ x → snd Y) , idp) infixr 80 _⊙∘_ _⊙∘_ : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} (g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y)) → fst (X ⊙→ Z) (g , gpt) ⊙∘ (f , fpt) = (g ∘ f) , (ap g fpt ∙ gpt) infixr 80 _⊙∘e_ _⊙∘e_ : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} (g : Y ⊙≃ Z) (f : X ⊙≃ Y) → X ⊙≃ Z (g , g-eq) ⊙∘e (f , f-eq) = (g ⊙∘ f , g-eq ∘ise f-eq) ⊙∘-unit-l : ∀ {i j} {X : Ptd i} {Y : Ptd j} (f : fst (X ⊙→ Y)) → ⊙idf Y ⊙∘ f == f ⊙∘-unit-l (f , idp) = idp ⊙∘-unit-r : ∀ {i j} {X : Ptd i} {Y : Ptd j} (f : fst (X ⊙→ Y)) → f ⊙∘ ⊙idf X == f ⊙∘-unit-r f = idp ⊙∘-assoc : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l} (h : fst (Z ⊙→ W)) (g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y)) → ((h ⊙∘ g) ⊙∘ f) == (h ⊙∘ (g ⊙∘ f)) ⊙∘-assoc (h , hpt) (g , gpt) (f , fpt) = pair= idp (lemma fpt gpt hpt) where lemma : ∀ {x₁ x₂} (fpt : x₁ == x₂) → ∀ gpt → ∀ hpt → ap (h ∘ g) fpt ∙ ap h gpt ∙ hpt == ap h (ap g fpt ∙ gpt) ∙ hpt lemma idp gpt hpt = idp ⊙Σ : ∀ {i j} (X : Ptd i) → (fst X → Ptd j) → Ptd (lmax i j) ⊙Σ (A , a₀) Y = ⊙[ Σ A (fst ∘ Y) , (a₀ , snd (Y a₀)) ] infixr 80 _⊙×_ _⊙×_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j) X ⊙× Y = ⊙Σ X (λ _ → Y) ⊙dfst : ∀ {i j} {X : Ptd i} (Y : fst X → Ptd j) → fst (⊙Σ X Y ⊙→ X) ⊙dfst Y = (fst , idp) ⊙fst : ∀ {i j} {X : Ptd i} {Y : Ptd j} → fst (X ⊙× Y ⊙→ X) ⊙fst = ⊙dfst _ ⊙snd : ∀ {i j} {X : Ptd i} {Y : Ptd j} → fst (X ⊙× Y ⊙→ Y) ⊙snd = (snd , idp) ⊙diag : ∀ {i} {X : Ptd i} → fst (X ⊙→ X ⊙× X) ⊙diag = ((λ x → (x , x)) , idp) ⊙×-in : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} → fst (X ⊙→ Y) → fst (X ⊙→ Z) → fst (X ⊙→ Y ⊙× Z) ⊙×-in (f , fpt) (g , gpt) = (λ x → (f x , g x)) , ap2 _,_ fpt gpt ⊙fst-⊙×-in : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} (f : fst (X ⊙→ Y)) (g : fst (X ⊙→ Z)) → ⊙fst ⊙∘ ⊙×-in f g == f ⊙fst-⊙×-in (f , idp) (g , idp) = idp ⊙snd-⊙×-in : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} (f : fst (X ⊙→ Y)) (g : fst (X ⊙→ Z)) → ⊙snd ⊙∘ ⊙×-in f g == g ⊙snd-⊙×-in (f , idp) (g , idp) = idp ⊙×-in-pre∘ : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l} (f : fst (Y ⊙→ Z)) (g : fst (Y ⊙→ W)) (h : fst (X ⊙→ Y)) → ⊙×-in f g ⊙∘ h == ⊙×-in (f ⊙∘ h) (g ⊙∘ h) ⊙×-in-pre∘ (f , idp) (g , idp) (h , idp) = idp pair⊙→ : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l} → fst (X ⊙→ Y) → fst (Z ⊙→ W) → fst ((X ⊙× Z) ⊙→ (Y ⊙× W)) pair⊙→ (f , fpt) (g , gpt) = ((λ {(x , z) → (f x , g z)}) , pair×= fpt gpt) {- ⊙→ preserves hlevel -} ⊙→-level : ∀ {i j} {X : Ptd i} {Y : Ptd j} {n : ℕ₋₂} → has-level n (fst Y) → has-level n (fst (X ⊙→ Y)) ⊙→-level pY = Σ-level (Π-level (λ _ → pY)) (λ _ → =-preserves-level _ pY) {- function extensionality for pointed functions -} ⊙λ= : ∀ {i j} {X : Ptd i} {Y : Ptd j} {f g : fst (X ⊙→ Y)} (p : ∀ x → fst f x == fst g x) (α : snd f == p (snd X) ∙ snd g) → f == g ⊙λ= {g = g} p α = pair= (λ= p) (↓-app=cst-in (α ∙ ap (λ w → w ∙ snd g) (! (app=-β p _)))) {- Extracting data from an pointed equivalence -} module _ {i j} {X : Ptd i} {Y : Ptd j} (⊙e : X ⊙≃ Y) where private e : fst X ≃ fst Y e = (fst (fst ⊙e) , snd ⊙e) p = snd (fst ⊙e) ⊙≃-to-≃ = e ⊙–> : fst (X ⊙→ Y) ⊙–> = fst ⊙e ⊙<– : fst (Y ⊙→ X) ⊙<– = (<– e , ap (<– e) (! p) ∙ <–-inv-l e (snd X)) ⊙<–-inv-l : ⊙<– ⊙∘ ⊙–> == ⊙idf _ ⊙<–-inv-l = ⊙λ= (<–-inv-l e) $ ap (<– e) p ∙ ap (<– e) (! p) ∙ <–-inv-l e (snd X) =⟨ ! (∙-assoc (ap (<– e) p) (ap (<– e) (! p)) (<–-inv-l e (snd X))) ⟩ (ap (<– e) p ∙ ap (<– e) (! p)) ∙ <–-inv-l e (snd X) =⟨ ∙-ap (<– e) p (! p) ∙ ap (ap (<– e)) (!-inv-r p) |in-ctx (λ w → w ∙ <–-inv-l e (snd X)) ⟩ <–-inv-l e (snd X) =⟨ ! (∙-unit-r _) ⟩ <–-inv-l e (snd X) ∙ idp ∎ ⊙<–-inv-r : ⊙–> ⊙∘ ⊙<– == ⊙idf _ ⊙<–-inv-r = ⊙λ= (<–-inv-r e) $ ap (–> e) (ap (<– e) (! p) ∙ <–-inv-l e (snd X)) ∙ p =⟨ ap-∙ (–> e) (ap (<– e) (! p)) (<–-inv-l e (snd X)) |in-ctx (λ w → w ∙ p) ⟩ (ap (–> e) (ap (<– e) (! p)) ∙ ap (–> e) (<–-inv-l e (snd X))) ∙ p =⟨ <–-inv-adj e (snd X) |in-ctx (λ w → (ap (–> e) (ap (<– e) (! p)) ∙ w) ∙ p) ⟩ (ap (–> e) (ap (<– e) (! p)) ∙ <–-inv-r e (–> e (snd X))) ∙ p =⟨ ∘-ap (–> e) (<– e) (! p) |in-ctx (λ w → (w ∙ <–-inv-r e (–> e (snd X))) ∙ p) ⟩ (ap (–> e ∘ <– e) (! p) ∙ <–-inv-r e (–> e (snd X))) ∙ p =⟨ htpy-lemma (<–-inv-r e) p ⟩ <–-inv-r e (snd Y) =⟨ ! (∙-unit-r _) ⟩ <–-inv-r e (snd Y) ∙ idp ∎ where htpy-lemma : ∀ {i} {A : Type i} {f : A → A} (p : ∀ z → f z == z) {x y : A} (q : x == y) → (ap f (! q) ∙ p x) ∙ q == p y htpy-lemma p idp = ∙-unit-r _ {- Equality of pointed types -} ⊙ua : ∀ {i} {X Y : Ptd i} → X ⊙≃ Y → X == Y ⊙ua ((f , p) , ie) = pair= (ua (f , ie)) (↓-idf-ua-in (f , ie) p)
{ "alphanum_fraction": 0.3796539067, "avg_line_length": 32.1404494382, "ext": "agda", "hexsha": "c693380d36c1af948ddbbc38b08c4659463d059c", "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/Pointed.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/Pointed.agda", "max_line_length": 76, "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/Pointed.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3263, "size": 5721 }
------------------------------------------------------------------------ -- Indices ------------------------------------------------------------------------ module Parallel.Index where open import Data.Product.Record import Data.Product as Prod; open Prod using () renaming (_,_ to pair) open import Data.Bool using (Bool; true; false; _∨_; _∧_; if_then_else_) open import Data.Bool.Properties as Bool open import Data.Nat using (ℕ; zero; suc; _⊔_) open import Data.Nat.Properties open import Algebra import Algebra.Props.BooleanAlgebra as BAlg import Algebra.Props.DistributiveLattice as DL private module NR = CommutativeSemiringWithoutOne ⊔-⊓-0-commutativeSemiringWithoutOne module NL = DL distributiveLattice module BR = CommutativeSemiring Bool.commutativeSemiring-∨-∧ module BA = BAlg Bool.booleanAlgebra import Relation.Binary.PropositionalEquality as PropEq open PropEq hiding (setoid) open ≡-Reasoning open import Data.Function open import Relation.Nullary ------------------------------------------------------------------------ -- The index type -- Does the parser accept the empty string? Empty : Set Empty = Bool -- The maximum "distance" to the next parser which is guaranteed to -- either consume a token or fail. Distance : Set Distance = ℕ -- Parser indices. Note that it is important that the record type used -- here has η-equality, since otherwise it would be harder to infer -- the types. Index : Set Index = Empty × Distance import Algebra.FunctionProperties as P; open P (PropEq.setoid Index) ------------------------------------------------------------------------ -- The basic operations on indices infixl 50 _·I_ infixl 40 _∣I_ 0I : Index 0I = (false , zero) 1I : Index 1I = (true , zero) _·I_ : Index -> Index -> Index i₁ ·I i₂ = ( proj₁ i₁ ∧ proj₁ i₂ , (if proj₁ i₁ then proj₂ i₁ ⊔ proj₂ i₂ else proj₂ i₁) ) _∣I_ : Index -> Index -> Index i₁ ∣I i₂ = (proj₁ i₁ ∨ proj₁ i₂ , proj₂ i₁ ⊔ proj₂ i₂) ------------------------------------------------------------------------ -- These operations satisfy some algebraic properties private -- TODO: General code for taking the product of two commutative -- monoids. However, I don't want to define this operation for both -- Data.Product and Data.Product.Record. Hence I'll probably wait -- (at least) until pattern matching on records is possible, since I -- plan to merge Data.Product and Data.Product.Record then. ∣-assoc : Associative _∣I_ ∣-assoc i₁ i₂ i₃ = cong₂ _,_ (BR.+-assoc (proj₁ i₁) (proj₁ i₂) (proj₁ i₃)) (NR.+-assoc (proj₂ i₁) (proj₂ i₂) (proj₂ i₃)) ∣-comm : Commutative _∣I_ ∣-comm i₁ i₂ = cong₂ _,_ (BR.+-comm (proj₁ i₁) (proj₁ i₂)) (NR.+-comm (proj₂ i₁) (proj₂ i₂)) ∣-identity : Identity 0I _∣I_ ∣-identity = pair (\i -> cong₂ _,_ (Prod.proj₁ BR.+-identity (proj₁ i)) (Prod.proj₁ NR.+-identity (proj₂ i))) (\i -> cong₂ _,_ (Prod.proj₂ BR.+-identity (proj₁ i)) (Prod.proj₂ NR.+-identity (proj₂ i))) ·-assoc : Associative _·I_ ·-assoc i₁ i₂ i₃ with proj₁ i₁ | proj₁ i₂ ·-assoc i₁ i₂ i₃ | false | e₂ = refl ·-assoc i₁ i₂ i₃ | true | false = refl ·-assoc i₁ i₂ i₃ | true | true = cong (_,_ (proj₁ i₃)) (NR.+-assoc (proj₂ i₁) (proj₂ i₂) (proj₂ i₃)) ·-identity : Identity 1I _·I_ ·-identity = pair (\_ -> refl) (\x -> helper (proj₁ x) (proj₂ x)) where helper : forall e d -> _≡_ {a = Index} (e ∧ true , (if e then d ⊔ zero else d)) (e , d) helper false d = refl helper true d = cong (_,_ true) (Prod.proj₂ NR.+-identity d) ·-∣-distrib : _·I_ DistributesOver _∣I_ ·-∣-distrib = pair (\i₁ i₂ i₃ -> cong₂ _,_ (Prod.proj₁ BR.distrib (proj₁ i₁) (proj₁ i₂) (proj₁ i₃)) (distribˡ₂ (proj₂ i₁) (proj₂ i₂) (proj₂ i₃) (proj₁ i₁))) (\i₁ i₂ i₃ -> cong₂ _,_ (Prod.proj₂ BR.distrib (proj₁ i₁) (proj₁ i₂) (proj₁ i₃)) (distribʳ₂ (proj₂ i₁) (proj₂ i₂) (proj₂ i₃) (proj₁ i₂) (proj₁ i₃))) where lemma : forall d₁ d₂ d₃ -> d₁ ⊔ (d₂ ⊔ d₃) ≡ d₁ ⊔ d₂ ⊔ (d₁ ⊔ d₃) lemma d₁ d₂ d₃ = begin d₁ ⊔ (d₂ ⊔ d₃) ≡⟨ sym (NL.∧-idempotent d₁) ⟨ NR.+-pres-≈ ⟩ byDef {x = d₂ ⊔ d₃} ⟩ d₁ ⊔ d₁ ⊔ (d₂ ⊔ d₃) ≡⟨ NR.+-assoc d₁ d₁ (d₂ ⊔ d₃) ⟩ d₁ ⊔ (d₁ ⊔ (d₂ ⊔ d₃)) ≡⟨ byDef {x = d₁} ⟨ NR.+-pres-≈ ⟩ sym (NR.+-assoc d₁ d₂ d₃) ⟩ d₁ ⊔ (d₁ ⊔ d₂ ⊔ d₃) ≡⟨ byDef {x = d₁} ⟨ NR.+-pres-≈ ⟩ (NR.+-comm d₁ d₂ ⟨ NR.+-pres-≈ ⟩ byDef {x = d₃}) ⟩ d₁ ⊔ (d₂ ⊔ d₁ ⊔ d₃) ≡⟨ byDef {x = d₁} ⟨ NR.+-pres-≈ ⟩ NR.+-assoc d₂ d₁ d₃ ⟩ d₁ ⊔ (d₂ ⊔ (d₁ ⊔ d₃)) ≡⟨ sym $ NR.+-assoc d₁ d₂ (d₁ ⊔ d₃) ⟩ d₁ ⊔ d₂ ⊔ (d₁ ⊔ d₃) ∎ distribˡ₂ : forall d₁ d₂ d₃ e₁ -> (if e₁ then d₁ ⊔ (d₂ ⊔ d₃) else d₁) ≡ (if e₁ then d₁ ⊔ d₂ else d₁) ⊔ (if e₁ then d₁ ⊔ d₃ else d₁) distribˡ₂ d₁ d₂ d₃ true = lemma d₁ d₂ d₃ distribˡ₂ d₁ d₂ d₃ false = sym (NL.∧-idempotent d₁) distribʳ₂ : forall d₁ d₂ d₃ e₂ e₃ -> (if e₂ ∨ e₃ then d₂ ⊔ d₃ ⊔ d₁ else d₂ ⊔ d₃) ≡ (if e₂ then d₂ ⊔ d₁ else d₂) ⊔ (if e₃ then d₃ ⊔ d₁ else d₃) distribʳ₂ d₁ d₂ d₃ true true = begin d₂ ⊔ d₃ ⊔ d₁ ≡⟨ NR.+-comm (d₂ ⊔ d₃) d₁ ⟩ d₁ ⊔ (d₂ ⊔ d₃) ≡⟨ lemma d₁ d₂ d₃ ⟩ d₁ ⊔ d₂ ⊔ (d₁ ⊔ d₃) ≡⟨ NR.+-comm d₁ d₂ ⟨ NR.+-pres-≈ ⟩ NR.+-comm d₁ d₃ ⟩ d₂ ⊔ d₁ ⊔ (d₃ ⊔ d₁) ∎ distribʳ₂ d₁ d₂ d₃ true false = begin d₂ ⊔ d₃ ⊔ d₁ ≡⟨ NR.+-assoc d₂ d₃ d₁ ⟩ d₂ ⊔ (d₃ ⊔ d₁) ≡⟨ byDef {x = d₂} ⟨ NR.+-pres-≈ ⟩ NR.+-comm d₃ d₁ ⟩ d₂ ⊔ (d₁ ⊔ d₃) ≡⟨ sym $ NR.+-assoc d₂ d₁ d₃ ⟩ d₂ ⊔ d₁ ⊔ d₃ ∎ distribʳ₂ d₁ d₂ d₃ false true = NR.+-assoc d₂ d₃ d₁ distribʳ₂ d₁ d₂ d₃ false false = refl ·-idempotent : Idempotent _·I_ ·-idempotent i = cong₂ _,_ (BA.∧-idempotent (proj₁ i)) (lemma (proj₁ i) (proj₂ i)) where lemma : forall b x -> (if b then x ⊔ x else x) ≡ x lemma true x = NL.∧-idempotent x lemma false x = refl ∣-idempotent : Idempotent _∣I_ ∣-idempotent i = cong₂ _,_ (BA.∨-idempotent (proj₁ i)) (NL.∧-idempotent (proj₂ i)) -- Not quite a semiring, but the proper name is too long... indexSemiring : SemiringWithoutAnnihilatingZero indexSemiring = record { setoid = PropEq.setoid Index ; _+_ = _∣I_ ; _*_ = _·I_ ; 0# = 0I ; 1# = 1I ; isSemiringWithoutAnnihilatingZero = record { +-isCommutativeMonoid = record { isMonoid = record { isSemigroup = record { assoc = ∣-assoc ; ∙-pres-≈ = cong₂ _∣I_ } ; identity = ∣-identity } ; comm = ∣-comm } ; *-isMonoid = record { isSemigroup = record { assoc = ·-assoc ; ∙-pres-≈ = cong₂ _·I_ } ; identity = ·-identity } ; distrib = ·-∣-distrib } } module IndexSemiring = SemiringWithoutAnnihilatingZero indexSemiring nearSemiring : NearSemiring nearSemiring = record { setoid = setoid ; _+_ = _+_ ; _*_ = _*_ ; 0# = 0# ; isNearSemiring = record { +-isMonoid = +-isMonoid ; *-isSemigroup = *-isSemigroup ; distribʳ = Prod.proj₂ distrib ; zeroˡ = \_ -> PropEq.refl } } where open IndexSemiring private lemma : suc zero ≢ zero lemma () -- The indices very nearly form a semiring (∣I, ·I, 0I, 1I). The -- only missing piece is that 0I is not a right zero for ·I: notRightZero : ¬ RightZero 0I _·I_ notRightZero zeroʳ = lemma $ cong proj₂ $ zeroʳ (false , suc zero) -- It might also be worth noting that ·I is not commutative: notCommutative : ¬ Commutative _·I_ notCommutative comm = lemma $ cong proj₂ $ comm (true , suc zero) (false , zero) -- Note that we don't want these properties to be true. The second -- one implies the first, and the first implies that -- p = p ⊛> symbol -- is an OK definition, even though it is left recursive.
{ "alphanum_fraction": 0.5313727825, "avg_line_length": 32.5542635659, "ext": "agda", "hexsha": "c9e19765b18902344da98d9d16030c105dea8a02", "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": "76774f54f466cfe943debf2da731074fe0c33644", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_path": "misc/Parallel/Index.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z", "max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/parser-combinators", "max_issues_repo_path": "misc/Parallel/Index.agda", "max_line_length": 72, "max_stars_count": 7, "max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yurrriq/parser-combinators", "max_stars_repo_path": "misc/Parallel/Index.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z", "max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z", "num_tokens": 3021, "size": 8399 }
------------------------------------------------------------------------ -- Small coinductive higher lenses with erased "proofs" ------------------------------------------------------------------------ {-# OPTIONS --guardedness #-} import Equality.Path as P module Lens.Non-dependent.Higher.Coinductive.Small.Erased {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where open P.Derived-definitions-and-properties eq open import Logical-equivalence using (_⇔_) open import Prelude as P hiding (id) open import Bijection equality-with-J as B using (_↔_) open import Equality.Decidable-UIP equality-with-J using (Constant) open import Equality.Path.Isomorphisms eq open import Equivalence equality-with-J as Eq using (_≃_; Is-equivalence) open import Equivalence.Erased.Cubical eq as EEq using (_≃ᴱ_) open import Equivalence.Erased.Contractible-preimages.Cubical eq as ECP using (_⁻¹ᴱ_) open import Erased.Cubical eq open import Function-universe equality-with-J as F hiding (id; _∘_) open import H-level equality-with-J open import H-level.Closure equality-with-J open import H-level.Truncation.Propositional eq using (∥_∥) open import Preimage equality-with-J using (_⁻¹_) open import Tactic.Sigma-cong equality-with-J open import Univalence-axiom equality-with-J open import Lens.Non-dependent eq import Lens.Non-dependent.Higher.Capriotti.Variant.Erased.Variant eq as V open import Lens.Non-dependent.Higher.Coherently.Coinductive eq import Lens.Non-dependent.Higher.Coinductive eq as C import Lens.Non-dependent.Higher.Coinductive.Erased eq as CE import Lens.Non-dependent.Higher.Coinductive.Small eq as S import Lens.Non-dependent.Higher.Erased eq as E private variable a b c d : Level A B : Type a l g p s : A P : A → Type p f : (x : A) → P x univ : Univalence a ------------------------------------------------------------------------ -- Weakly constant functions -- Weakly constant type-valued functions. -- -- Note that the definition does not use _≃ᴱ_: the right-to-left -- directions of the equivalences are erased. Constantᴱ : {A : Type a} → (A → Type p) → Type (a ⊔ p) Constantᴱ P = ∀ x y → ∃ λ (f : P x → P y) → Erased (Is-equivalence f) -- In erased contexts Constantᴱ is pointwise equivalent to Constant -- (assuming univalence). @0 Constantᴱ≃Constant : {P : A → Type p} → Univalence p → Constantᴱ P ≃ Constant P Constantᴱ≃Constant {P = P} univ = Constantᴱ P ↔⟨⟩ (∀ x y → ∃ λ (f : P x → P y) → Erased (Is-equivalence f)) ↔⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∃-cong λ _ → erased Erased↔) ⟩ (∀ x y → ∃ λ (f : P x → P y) → Is-equivalence f) ↔⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → inverse Eq.≃-as-Σ) ⟩ (∀ x y → P x ≃ P y) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → inverse $ ≡≃≃ univ) ⟩ (∀ x y → P x ≡ P y) ↔⟨⟩ Constant P □ -- In erased contexts Constantᴱ is pointwise equivalent to -- S.Constant-≃. @0 Constantᴱ≃Constant-≃ : Constantᴱ P ≃ S.Constant-≃ P Constantᴱ≃Constant-≃ {P = P} = Constantᴱ P ↔⟨⟩ (∀ x y → ∃ λ (f : P x → P y) → Erased (Is-equivalence f)) ↔⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∃-cong λ _ → erased Erased↔) ⟩ (∀ x y → ∃ λ (f : P x → P y) → Is-equivalence f) ↔⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → inverse Eq.≃-as-Σ) ⟩ (∀ x y → P x ≃ P y) ↔⟨⟩ S.Constant-≃ P □ -- In erased contexts Constantᴱ (f ⁻¹ᴱ_) is pointwise equivalent to -- S.Constant-≃ (f ⁻¹_). @0 Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹ : Constantᴱ (f ⁻¹ᴱ_) ≃ S.Constant-≃ (f ⁻¹_) Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹ {f = f} = Constantᴱ (f ⁻¹ᴱ_) ↝⟨ Constantᴱ≃Constant-≃ ⟩ S.Constant-≃ (f ⁻¹ᴱ_) ↔⟨⟩ (∀ b₁ b₂ → f ⁻¹ᴱ b₁ ≃ f ⁻¹ᴱ b₂) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → Eq.≃-preserves ext (inverse ECP.⁻¹≃⁻¹ᴱ) (inverse ECP.⁻¹≃⁻¹ᴱ)) ⟩ (∀ b₁ b₂ → f ⁻¹ b₁ ≃ f ⁻¹ b₂) ↔⟨⟩ S.Constant-≃ (f ⁻¹_) □ -- In erased contexts Constantᴱ (f ⁻¹ᴱ_) is pointwise equivalent to -- Constant (f ⁻¹_) (assuming univalence). @0 Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹ : Block "Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹" → {A : Type a} {B : Type b} {f : A → B} → Univalence (a ⊔ b) → Constantᴱ (f ⁻¹ᴱ_) ≃ Constant (f ⁻¹_) Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹ ⊠ {f = f} univ = Constantᴱ (f ⁻¹ᴱ_) ↝⟨ Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹ ⟩ S.Constant-≃ (f ⁻¹_) ↝⟨ inverse $ S.Constant≃Constant-≃ univ ⟩□ Constant (f ⁻¹_) □ -- A "computation" rule for Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹. @0 proj₁-from-Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹ : (bl : Block "Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹") → ∀ {A : Type a} {B : Type b} {f : A → B} {univ : Univalence (a ⊔ b)} {c : Constant (f ⁻¹_)} {b₁ b₂} → proj₁ (_≃_.from (Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹ bl univ) c b₁ b₂) ≡ ECP.⁻¹→⁻¹ᴱ ∘ subst P.id (c b₁ b₂) ∘ ECP.⁻¹ᴱ→⁻¹ proj₁-from-Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹ ⊠ {c = c} {b₁ = b₁} {b₂ = b₂} = ⟨ext⟩ λ (a , [ eq ]) → ECP.⁻¹→⁻¹ᴱ (≡⇒→ (c b₁ b₂) (a , eq)) ≡⟨ cong ECP.⁻¹→⁻¹ᴱ $ sym $ subst-id-in-terms-of-≡⇒↝ equivalence ⟩∎ ECP.⁻¹→⁻¹ᴱ (subst P.id (c b₁ b₂) (a , eq)) ∎ -- Constantᴱ (get ⁻¹ᴱ_) can be expressed (up to _≃ᴱ_) in terms of a -- "setter" and an erased "get-set" law that, in a certain way, form -- an erased family of equivalences. -- -- This lemma is based on a lemma suggested by Andrea Vezzosi, see -- S.Constant-≃-get-⁻¹-≃. Constantᴱ-⁻¹ᴱ-≃ᴱ : {A : Type a} {B : Type b} {get : A → B} → Block "Constantᴱ-⁻¹ᴱ-≃ᴱ" → Constantᴱ (get ⁻¹ᴱ_) ≃ᴱ (∃ λ (set : A → B → A) → Erased (∃ λ (get-set : ∀ a b → get (set a b) ≡ b) → ∀ b₁ b₂ → let f : get ⁻¹ b₁ → get ⁻¹ b₂ f = λ (a , _) → set a b₂ , get-set a b₂ in Is-equivalence f)) Constantᴱ-⁻¹ᴱ-≃ᴱ {A = A} {B = B} {get = get} ⊠ = Constantᴱ (get ⁻¹ᴱ_) ↔⟨⟩ (∀ b₁ b₂ → ∃ λ (f : get ⁻¹ᴱ b₁ → get ⁻¹ᴱ b₂) → Erased (Is-equivalence f)) ↔⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∃-cong λ f → Erased-cong ( Is-equivalence≃Is-equivalence-∘ˡ {k = equivalence} ext $ _≃_.is-equivalence $ from-bijection $ ∃-cong λ _ → erased Erased↔)) ⟩ (∀ b₁ b₂ → ∃ λ (f : get ⁻¹ᴱ b₁ → get ⁻¹ᴱ b₂) → Erased (Is-equivalence (Σ-map P.id erased ∘ f))) ↔⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → ∃-cong λ f → Erased-cong ( Is-equivalence≃Is-equivalence-∘ʳ {k = equivalence} ext $ _≃_.is-equivalence $ from-bijection $ ∃-cong λ _ → inverse $ erased Erased↔)) ⟩ (∀ b₁ b₂ → ∃ λ (f : get ⁻¹ᴱ b₁ → get ⁻¹ᴱ b₂) → Erased (Is-equivalence (Σ-map P.id erased ∘ f ∘ Σ-map P.id [_]→))) ↔⟨ Π-comm ⟩ (∀ b₂ b₁ → ∃ λ (f : get ⁻¹ᴱ b₁ → get ⁻¹ᴱ b₂) → Erased (Is-equivalence (Σ-map P.id erased ∘ f ∘ Σ-map P.id [_]→))) ↔⟨ (∀-cong ext λ _ → ΠΣ-comm) ⟩ (∀ b₂ → ∃ λ (f : ∀ b₁ → get ⁻¹ᴱ b₁ → get ⁻¹ᴱ b₂) → ∀ b₁ → Erased (Is-equivalence (Σ-map P.id erased ∘ f b₁ ∘ Σ-map P.id [_]→))) ↔⟨ (∀-cong ext λ _ → ∃-cong λ _ → inverse Erased-Π↔Π) ⟩ (∀ b₂ → ∃ λ (f : ∀ b₁ → get ⁻¹ᴱ b₁ → get ⁻¹ᴱ b₂) → Erased (∀ b₁ → Is-equivalence (Σ-map P.id erased ∘ f b₁ ∘ Σ-map P.id [_]→))) ↔⟨ (∀-cong ext λ _ → Σ-cong {k₂ = equivalence} (inverse (∀-cong ext λ _ → currying) F.∘ Π-comm F.∘ (∀-cong ext λ _ → currying)) (λ _ → Eq.id)) ⟩ (∀ b₂ → ∃ λ (f : ∀ a → (∃ λ b₁ → Erased (get a ≡ b₁)) → get ⁻¹ᴱ b₂) → Erased (∀ b₁ → let g : get ⁻¹ b₁ → get ⁻¹ b₂ g = λ (a , eq) → Σ-map P.id erased (f a (b₁ , [ eq ])) in Is-equivalence g)) ↝⟨ (∀-cong ext λ _ → EEq.Σ-cong-≃ᴱ-Erased (∀-cong ext λ _ → EEq.drop-⊤-left-Π-≃ᴱ ext Erased-other-singleton≃ᴱ⊤ (λ _ _ → F.id)) λ f → Erased-cong ( ∀-cong ext λ b₁ → Is-equivalence-cong ext λ (a , eq) → Σ-map P.id erased (f a (b₁ , [ eq ])) ≡⟨ cong (Σ-map P.id erased ∘ f a) $ sym $ erased (proj₂ Contractibleᴱ-Erased-other-singleton) _ ⟩ Σ-map P.id erased (f a (get a , [ refl _ ])) ≡⟨ cong (Σ-map P.id erased) $ sym $ subst-refl _ _ ⟩∎ Σ-map P.id erased (subst (const _) (refl _) (f a (get a , [ refl _ ]))) ∎)) ⟩ (∀ b₂ → ∃ λ (f : A → get ⁻¹ᴱ b₂) → Erased (∀ b₁ → let g : get ⁻¹ b₁ → get ⁻¹ b₂ g = λ (a , _) → Σ-map P.id erased (f a) in Is-equivalence g)) ↔⟨ ΠΣ-comm ⟩ (∃ λ (f : ∀ b → A → get ⁻¹ᴱ b) → ∀ b₂ → Erased (∀ b₁ → let g : get ⁻¹ b₁ → get ⁻¹ b₂ g = λ (a , _) → Σ-map P.id erased (f b₂ a) in Is-equivalence g)) ↔⟨ (∃-cong λ _ → inverse Erased-Π↔Π) ⟩ (∃ λ (f : ∀ b → A → get ⁻¹ᴱ b) → Erased (∀ b₂ b₁ → let g : get ⁻¹ b₁ → get ⁻¹ b₂ g = λ (a , _) → Σ-map P.id erased (f b₂ a) in Is-equivalence g)) ↔⟨ Σ-cong Π-comm (λ _ → Erased-cong Π-comm) ⟩ (∃ λ (f : A → ∀ b → get ⁻¹ᴱ b) → Erased (∀ b₁ b₂ → let g : get ⁻¹ b₁ → get ⁻¹ b₂ g = λ (a , _) → Σ-map P.id erased (f a b₂) in Is-equivalence g)) ↔⟨ Σ-cong (∀-cong ext λ _ → ΠΣ-comm) (λ _ → Eq.id) ⟩ (∃ λ (f : A → ∃ λ (set : B → A) → ∀ b → Erased (get (set b) ≡ b)) → Erased (∀ b₁ b₂ → let g : get ⁻¹ b₁ → get ⁻¹ b₂ g = λ (a , _) → proj₁ (f a) b₂ , erased (proj₂ (f a) b₂) in Is-equivalence g)) ↔⟨ Σ-cong (∀-cong ext λ _ → ∃-cong λ _ → inverse Erased-Π↔Π) (λ _ → Eq.id) ⟩ (∃ λ (f : A → ∃ λ (set : B → A) → Erased (∀ b → get (set b) ≡ b)) → Erased (∀ b₁ b₂ → let g : get ⁻¹ b₁ → get ⁻¹ b₂ g = λ (a , _) → proj₁ (f a) b₂ , erased (proj₂ (f a)) b₂ in Is-equivalence g)) ↔⟨ Σ-cong-id {k₂ = equivalence} ΠΣ-comm ⟩ (∃ λ ((set , get-set) : ∃ λ (set : A → B → A) → ∀ a → Erased (∀ b → get (set a b) ≡ b)) → Erased (∀ b₁ b₂ → let f : get ⁻¹ b₁ → get ⁻¹ b₂ f = λ (a , _) → set a b₂ , erased (get-set a) b₂ in Is-equivalence f)) ↔⟨ Σ-cong (∃-cong λ _ → inverse Erased-Π↔Π) (λ _ → Eq.id) ⟩ (∃ λ ((set , [ get-set ]) : ∃ λ (set : A → B → A) → Erased (∀ a b → get (set a b) ≡ b)) → Erased (∀ b₁ b₂ → let f : get ⁻¹ b₁ → get ⁻¹ b₂ f = λ (a , _) → set a b₂ , get-set a b₂ in Is-equivalence f)) ↔⟨ inverse Σ-assoc ⟩ (∃ λ (set : A → B → A) → ∃ λ (([ get-set ]) : Erased (∀ a b → get (set a b) ≡ b)) → Erased (∀ b₁ b₂ → Is-equivalence λ (a , _) → set a b₂ , get-set a b₂)) ↔⟨ (∃-cong λ _ → inverse Erased-Σ↔Σ) ⟩□ (∃ λ (set : A → B → A) → Erased (∃ λ (get-set : ∀ a b → get (set a b) ≡ b) → ∀ b₁ b₂ → Is-equivalence λ (a , _) → set a b₂ , get-set a b₂)) □ -- A lemma relating S.Constant-≃-get-⁻¹-≃, -- Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹ and Constantᴱ-⁻¹ᴱ-≃ᴱ. @0 to-Constant-≃-get-⁻¹-≃-to-Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹-≡ : (bl : Block "Constant-≃-get-⁻¹-≃") {A : Type a} {B : Type b} {get : A → B} → (c : Constantᴱ (get ⁻¹ᴱ_)) → _≃_.to (S.Constant-≃-get-⁻¹-≃ bl) (_≃_.to Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹ c) ≡ Σ-map P.id erased (_≃ᴱ_.to (Constantᴱ-⁻¹ᴱ-≃ᴱ bl) c) to-Constant-≃-get-⁻¹-≃-to-Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹-≡ bl {get = get} c = _≃_.from (Eq.≃-≡ $ Eq.↔⇒≃ $ inverse Σ-assoc) $ Σ-≡,≡→≡ (lemma bl) ((Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Eq.propositional ext _) _ _) where lemma : (bl : Block "Constant-≃-get-⁻¹-≃") → (proj₁ $ _↔_.to Σ-assoc $ _≃_.to (S.Constant-≃-get-⁻¹-≃ bl) (_≃_.to Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹ c)) ≡ (proj₁ $ _↔_.to Σ-assoc $ Σ-map P.id erased (_≃ᴱ_.to (Constantᴱ-⁻¹ᴱ-≃ᴱ bl) c)) lemma ⊠ = Σ-≡,≡→≡ (⟨ext⟩ λ a → ⟨ext⟩ λ b → proj₁ (proj₁ (c (get a) b) (a , [ refl _ ])) ≡⟨ cong proj₁ $ sym $ subst-refl _ _ ⟩∎ proj₁ (subst (λ _ → get ⁻¹ᴱ b) (refl _) (proj₁ (c (get a) b) (a , [ refl _ ]))) ∎) (⟨ext⟩ λ a → ⟨ext⟩ λ b → subst (λ set → ∀ a b → get (set a b) ≡ b) (⟨ext⟩ λ a → ⟨ext⟩ λ b → cong {x = proj₁ (c (get a) b) (a , [ refl _ ])} proj₁ $ sym $ subst-refl _ _) (λ a b → erased (proj₂ (proj₁ (c (get a) b) (a , [ refl _ ])))) a b ≡⟨ sym $ trans (push-subst-application _ _) $ cong (_$ b) $ push-subst-application _ _ ⟩ subst (λ set → get (set a b) ≡ b) (⟨ext⟩ λ _ → ⟨ext⟩ λ _ → cong proj₁ $ sym $ subst-refl _ _) (erased (proj₂ (proj₁ (c (get a) b) (a , [ refl _ ])))) ≡⟨ trans (subst-ext _ _) $ subst-ext _ _ ⟩ subst (λ s → get s ≡ b) (cong proj₁ $ sym $ subst-refl _ _) (erased (proj₂ (proj₁ (c (get a) b) (a , [ refl _ ])))) ≡⟨ sym $ subst-∘ _ _ _ ⟩ subst (λ (s , _) → get s ≡ b) (sym $ subst-refl _ _) (erased (proj₂ (proj₁ (c (get a) b) (a , [ refl _ ])))) ≡⟨ elim¹ (λ {p} eq → subst (λ (s , _) → get s ≡ b) eq (erased (proj₂ (proj₁ (c (get a) b) (a , [ refl _ ])))) ≡ erased (proj₂ p)) (subst-refl _ _) _ ⟩∎ erased (proj₂ (subst (λ _ → get ⁻¹ᴱ b) (refl _) (proj₁ (c (get a) b) (a , [ refl _ ])))) ∎) ------------------------------------------------------------------------ -- Coherently constant families of fibres -- Coherently constant families of fibres (with erased proofs), -- defined using univalence. Coherently-constant-fibres : {A : Type a} {B : Type b} → @0 Univalence (a ⊔ b) → (A → B) → Type (a ⊔ b) Coherently-constant-fibres {A = A} {B = B} univ get = ∃ λ (set : A → B → A) → Erased (∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → set ≡ S.Lens.set {univ = univ} (record { get⁻¹-coherently-constant = c })) -- Coherently-constant-fibres univ get is equivalent (with erased -- proofs) to CE.Coherently-constant (get ⁻¹ᴱ_) (assuming univalence). Coherently-constant-fibres≃ᴱCoherently-constant-⁻¹ᴱ : {A : Type a} {B : Type b} {get : A → B} → @0 Univalence (lsuc (a ⊔ b)) → (@0 univ : Univalence (a ⊔ b)) → Coherently-constant-fibres univ get ≃ᴱ CE.Coherently-constant (get ⁻¹ᴱ_) Coherently-constant-fibres≃ᴱCoherently-constant-⁻¹ᴱ {a = a} {b = b} {A = A} {B = B} {get = get} univ′ univ = block λ bl → Coherently-constant-fibres univ get ↔⟨⟩ (∃ λ (set : A → B → A) → Erased (∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → set ≡ S.Lens.set {univ = univ} (record { get⁻¹-coherently-constant = c }))) ↔⟨ (∃-cong λ _ → Erased-cong (∃-cong λ c → ≡⇒≃ $ cong (_ ≡_) $ S.Lens.set≡ {univ = univ} (record { get⁻¹-coherently-constant = c }) bl)) ⟩ (∃ λ (set : A → B → A) → Erased (∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → set ≡ proj₁ (_≃_.to (S.Constant-≃-get-⁻¹-≃ bl) (c .property)))) ↔⟨ (∃-cong λ _ → Erased-cong (∃-cong λ _ → inverse $ ≡-comm F.∘ drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ other-singleton-contractible _)) ⟩ (∃ λ (set : A → B → A) → Erased (∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → ∃ λ (p : proj₁ (_≃_.to (S.Constant-≃-get-⁻¹-≃ bl) (c .property)) ≡ set) → ∃ λ (q : ∃ λ (get-set : (a : A) (b : B) → get (set a b) ≡ b) → ∀ b₁ b₂ → let f : get ⁻¹ b₁ → get ⁻¹ b₂ f = λ (a , _) → set a b₂ , get-set a b₂ in Is-equivalence f) → subst (λ set → ∃ λ (get-set : (a : A) (b : B) → get (set a b) ≡ b) → ∀ b₁ b₂ → let f : get ⁻¹ b₁ → get ⁻¹ b₂ f = λ (a , _) → set a b₂ , get-set a b₂ in Is-equivalence f) p (proj₂ (_≃_.to (S.Constant-≃-get-⁻¹-≃ bl) (c .property))) ≡ q)) ↔⟨ (∃-cong λ _ → Erased-cong (∃-cong λ _ → (∃-cong λ _ → ∃-comm) F.∘ ∃-comm F.∘ (∃-cong λ _ → inverse Σ-assoc))) ⟩ (∃ λ (set : A → B → A) → Erased (∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → ∃ λ (get-set : (a : A) (b : B) → get (set a b) ≡ b) → ∃ λ (eq : ∀ b₁ b₂ → let f : get ⁻¹ b₁ → get ⁻¹ b₂ f = λ (a , _) → set a b₂ , get-set a b₂ in Is-equivalence f) → ∃ λ (p : proj₁ (_≃_.to (S.Constant-≃-get-⁻¹-≃ bl) (c .property)) ≡ set) → subst (λ set → ∃ λ (get-set : (a : A) (b : B) → get (set a b) ≡ b) → ∀ b₁ b₂ → let f : get ⁻¹ b₁ → get ⁻¹ b₂ f = λ (a , _) → set a b₂ , get-set a b₂ in Is-equivalence f) p (proj₂ (_≃_.to (S.Constant-≃-get-⁻¹-≃ bl) (c .property))) ≡ (get-set , eq))) ↔⟨ (∃-cong λ _ → Erased-cong (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → B.Σ-≡,≡↔≡)) ⟩ (∃ λ (set : A → B → A) → Erased (∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → ∃ λ (get-set : (a : A) (b : B) → get (set a b) ≡ b) → ∃ λ (eq : ∀ b₁ b₂ → let f : get ⁻¹ b₁ → get ⁻¹ b₂ f = λ (a , _) → set a b₂ , get-set a b₂ in Is-equivalence f) → _≃_.to (S.Constant-≃-get-⁻¹-≃ bl) (c .property) ≡ (set , get-set , eq))) ↔⟨ (∃-cong λ _ → Erased-cong (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ≡⇒≃ (cong (_≡ _) $ _≃_.left-inverse-of (S.Constant-≃-get-⁻¹-≃ bl) _) F.∘ inverse (Eq.≃-≡ $ inverse $ S.Constant-≃-get-⁻¹-≃ bl))) ⟩ (∃ λ (set : A → B → A) → Erased (∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → ∃ λ (get-set : (a : A) (b : B) → get (set a b) ≡ b) → ∃ λ (eq : ∀ b₁ b₂ → let f : get ⁻¹ b₁ → get ⁻¹ b₂ f = λ (a , _) → set a b₂ , get-set a b₂ in Is-equivalence f) → c .property ≡ S.Constant-≃-get-⁻¹-≃⁻¹ (set , get-set , eq))) ↔⟨ (Σ-assoc F.∘ (∃-cong λ _ → Erased-Σ↔Σ F.∘ Erased-cong (Σ-assoc F.∘ (∃-cong λ _ → ∃-comm) F.∘ ∃-comm))) ⟩ (∃ λ ((set , [ get-set , eq ]) : ∃ λ (set : A → B → A) → Erased (∃ λ (get-set : (a : A) (b : B) → get (set a b) ≡ b) → ∀ b₁ b₂ → let f : get ⁻¹ b₁ → get ⁻¹ b₂ f = λ (a , _) → set a b₂ , get-set a b₂ in Is-equivalence f)) → Erased (∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → c .property ≡ S.Constant-≃-get-⁻¹-≃⁻¹ (set , get-set , eq))) ↝⟨ (inverse $ EEq.Σ-cong-≃ᴱ-Erased (Constantᴱ-⁻¹ᴱ-≃ᴱ bl) λ c → Erased-cong (∃-cong λ c′ → ≡⇒↝ _ (cong (c′ .property ≡_) ( _≃_.to Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹ c ≡⟨ sym $ _≃_.to-from (S.Constant-≃-get-⁻¹-≃ bl) $ to-Constant-≃-get-⁻¹-≃-to-Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹-≡ bl c ⟩∎ S.Constant-≃-get-⁻¹-≃⁻¹ (Σ-map P.id erased $ _≃ᴱ_.to (Constantᴱ-⁻¹ᴱ-≃ᴱ bl) c) ∎)))) ⟩ (∃ λ (c : Constantᴱ (get ⁻¹ᴱ_)) → Erased (∃ λ (c′ : S.Coherently-constant univ (get ⁻¹_)) → c′ .property ≡ _≃_.to Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹ c)) ↔⟨ (∃-cong λ c → Erased-cong (inverse $ Σ-cong (S.Coinductive-coherently-constant≃Coherently-constant univ′ univ) λ c′ → lemma₁ bl c (c′ .property))) ⟩ (∃ λ (c : Constantᴱ (get ⁻¹ᴱ_)) → Erased (∃ λ (c′ : C.Coherently-constant (get ⁻¹_)) → c′ .property ≡ _≃_.to (Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹ bl univ) c)) ↔⟨ (∃-cong λ c → Erased-cong (lemma₃ bl c)) ⟩ (∃ λ (c : Constantᴱ (get ⁻¹ᴱ_)) → Erased ( ∃ λ (c′ : C.Coherently-constant (get ⁻¹ᴱ_)) → ∀ b₁ b₂ → proj₁ (c b₁ b₂) ≡ subst P.id (c′ .property b₁ b₂))) ↔⟨ inverse Σ-assoc F.∘ (Σ-cong (ΠΣ-comm F.∘ ∀-cong ext λ _ → ΠΣ-comm) λ _ → F.id) ⟩ (∃ λ (get⁻¹ᴱ-const : ∀ b₁ b₂ → get ⁻¹ᴱ b₁ → get ⁻¹ᴱ b₂) → (∀ b₁ b₂ → Erased (Is-equivalence (get⁻¹ᴱ-const b₁ b₂))) × Erased ( ∃ λ (c′ : C.Coherently-constant (get ⁻¹ᴱ_)) → ∀ b₁ b₂ → get⁻¹ᴱ-const b₁ b₂ ≡ subst P.id (c′ .property b₁ b₂))) ↔⟨ (∃-cong {k = bijection} λ _ → drop-⊤-left-× λ ([ _ , eq ]) → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → H-level-Erased 1 (Eq.propositional ext _)) (λ x y → [ Eq.respects-extensional-equality (ext⁻¹ (sym (eq x y))) (_≃_.is-equivalence $ Eq.subst-as-equivalence _ _) ])) ⟩ (∃ λ (get⁻¹ᴱ-const : ∀ b₁ b₂ → get ⁻¹ᴱ b₁ → get ⁻¹ᴱ b₂) → Erased ( ∃ λ (c′ : C.Coherently-constant (get ⁻¹ᴱ_)) → ∀ b₁ b₂ → get⁻¹ᴱ-const b₁ b₂ ≡ subst P.id (c′ .property b₁ b₂))) ↔⟨⟩ CE.Coherently-constant (get ⁻¹ᴱ_) □ where @0 lemma₁ : ∀ _ _ _ → _ ≃ _ lemma₁ bl c c′ = c′ ≡ _≃_.to (Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹ bl univ) c ↝⟨ ≡⇒≃ $ cong (c′ ≡_) $ unblock bl (λ bl → _≃_.to (Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹ bl univ) c ≡ _≃_.from (S.Constant≃Constant-≃ univ) (_≃_.to Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹ c)) (refl _) ⟩ c′ ≡ _≃_.from (S.Constant≃Constant-≃ univ) (_≃_.to Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹ c) ↝⟨ inverse $ Eq.≃-≡ (S.Constant≃Constant-≃ univ) ⟩ _≃_.to (S.Constant≃Constant-≃ univ) c′ ≡ _≃_.to (S.Constant≃Constant-≃ univ) (_≃_.from (S.Constant≃Constant-≃ univ) (_≃_.to Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹ c)) ↝⟨ ≡⇒≃ $ cong (_≃_.to (S.Constant≃Constant-≃ univ) c′ ≡_) $ _≃_.right-inverse-of (S.Constant≃Constant-≃ univ) _ ⟩□ _≃_.to (S.Constant≃Constant-≃ univ) c′ ≡ _≃_.to Constantᴱ-⁻¹ᴱ-≃-Constant-≃-⁻¹ c □ @0 lemma₂ : ∀ _ _ _ _ → _ lemma₂ bl c′ b₁ b₂ = proj₁ (_≃_.from (Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹ bl univ) (c′ .property) b₁ b₂) ≡⟨ proj₁-from-Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹ bl ⟩ ECP.⁻¹→⁻¹ᴱ ∘ subst P.id (c′ .property b₁ b₂) ∘ ECP.⁻¹ᴱ→⁻¹ ≡⟨ sym $ cong₂ (λ f g → f ∘ subst P.id (c′ .property b₁ b₂) ∘ g) (trans (⟨ext⟩ λ _ → subst-id-in-terms-of-≡⇒↝ equivalence) $ cong _≃_.to $ _≃_.right-inverse-of (≡≃≃ univ) _) (trans (⟨ext⟩ λ _ → subst-id-in-terms-of-inverse∘≡⇒↝ equivalence) $ cong _≃_.from $ _≃_.right-inverse-of (≡≃≃ univ) _) ⟩ subst P.id (≃⇒≡ univ ECP.⁻¹≃⁻¹ᴱ) ∘ subst P.id (c′ .property b₁ b₂) ∘ subst P.id (sym (≃⇒≡ univ ECP.⁻¹≃⁻¹ᴱ)) ≡⟨ (⟨ext⟩ λ _ → trans (subst-subst _ _ _ _) $ subst-subst _ _ _ _) ⟩ subst P.id (trans (sym (≃⇒≡ univ (ECP.⁻¹≃⁻¹ᴱ {y = b₁}))) (trans (c′ .property b₁ b₂) (≃⇒≡ univ (ECP.⁻¹≃⁻¹ᴱ {y = b₂})))) ≡⟨ sym $ cong (λ f → subst P.id (trans (sym (f b₁)) (trans (c′ .property b₁ b₂) (f b₂)))) $ _≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext) _ ⟩ subst P.id (trans (sym (cong (_$ b₁) $ ⟨ext⟩ λ _ → ≃⇒≡ univ ECP.⁻¹≃⁻¹ᴱ)) (trans (c′ .property b₁ b₂) (cong (_$ b₂) $ ⟨ext⟩ λ b₂ → ≃⇒≡ univ (ECP.⁻¹≃⁻¹ᴱ {y = b₂})))) ≡⟨ cong (subst P.id) $ elim¹ (λ eq → trans (sym (cong (_$ b₁) eq)) (trans (c′ .property b₁ b₂) (cong (_$ b₂) eq)) ≡ ≡⇒→ (cong C.Coherently-constant eq) c′ .property b₁ b₂) ( trans (sym (cong (_$ b₁) (refl _))) (trans (c′ .property b₁ b₂) (cong (_$ b₂) (refl (get ⁻¹_)))) ≡⟨ trans (cong (flip trans _) $ trans (cong sym $ cong-refl _) $ sym-refl) $ trans (trans-reflˡ _) $ trans (cong (trans _) $ cong-refl _) $ trans-reflʳ _ ⟩ c′ .property b₁ b₂ ≡⟨ cong (λ eq → _≃_.to eq c′ .property b₁ b₂) $ sym $ trans (cong ≡⇒≃ $ cong-refl C.Coherently-constant) ≡⇒↝-refl ⟩∎ ≡⇒→ (cong C.Coherently-constant (refl _)) c′ .property b₁ b₂ ∎) _ ⟩∎ subst P.id (≡⇒→ (cong C.Coherently-constant $ ⟨ext⟩ λ _ → ≃⇒≡ univ ECP.⁻¹≃⁻¹ᴱ) c′ .property b₁ b₂) ∎ @0 lemma₃ : ∀ _ _ → _ ≃ _ lemma₃ bl c = (∃ λ (c′ : C.Coherently-constant (get ⁻¹_)) → c′ .property ≡ _≃_.to (Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹ bl univ) c) ↝⟨ (∃-cong λ _ → (∀-cong ext λ _ → ∀-cong ext λ _ → from-bijection $ inverse $ ≡-comm F.∘ ignore-propositional-component (H-level-Erased 1 (Eq.propositional ext _))) F.∘ inverse (Eq.extensionality-isomorphism bad-ext F.∘ (∀-cong ext λ _ → Eq.extensionality-isomorphism bad-ext)) F.∘ (≡⇒≃ $ cong (_ ≡_) $ _≃_.left-inverse-of (Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹ bl univ) _) F.∘ (inverse $ Eq.≃-≡ $ inverse $ Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹ bl univ)) ⟩ (∃ λ (c′ : C.Coherently-constant (get ⁻¹_)) → ∀ b₁ b₂ → proj₁ (c b₁ b₂) ≡ proj₁ (_≃_.from (Constantᴱ-⁻¹ᴱ-≃-Constant-⁻¹ bl univ) (c′ .property) b₁ b₂)) ↝⟨ (Σ-cong (≡⇒≃ $ cong C.Coherently-constant $ ⟨ext⟩ λ _ → ≃⇒≡ univ ECP.⁻¹≃⁻¹ᴱ) λ c′ → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ → ≡⇒≃ $ cong (proj₁ (c b₁ b₂) ≡_) (lemma₂ bl c′ b₁ b₂)) ⟩□ (∃ λ (c′ : C.Coherently-constant (get ⁻¹ᴱ_)) → ∀ b₁ b₂ → proj₁ (c b₁ b₂) ≡ subst P.id (c′ .property b₁ b₂)) □ -- In erased contexts Coherently-constant-fibres univ get is -- equivalent to S.Coherently-constant univ (get ⁻¹_). @0 Coherently-constant-fibres≃Coherently-constant-⁻¹ : (bl : Block "Constant-≃-get-⁻¹-≃") {A : Type a} {B : Type b} {get : A → B} → (univ : Univalence (a ⊔ b)) → Coherently-constant-fibres univ get ≃ S.Coherently-constant univ (get ⁻¹_) Coherently-constant-fibres≃Coherently-constant-⁻¹ bl {A = A} {B = B} {get = get} univ = Coherently-constant-fibres univ get ↔⟨⟩ (∃ λ (set : A → B → A) → Erased (∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → set ≡ S.Lens.set {univ = univ} (record { get⁻¹-coherently-constant = c }))) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩ (∃ λ (set : A → B → A) → ∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → set ≡ S.Lens.set {univ = univ} (record { get⁻¹-coherently-constant = c })) ↔⟨ ∃-comm ⟩ (∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → ∃ λ (set : A → B → A) → set ≡ S.Lens.set {univ = univ} (record { get⁻¹-coherently-constant = c })) ↔⟨ (drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ singleton-contractible _) ⟩□ S.Coherently-constant univ (get ⁻¹_) □ ------------------------------------------------------------------------ -- The lens type family -- Small coinductive lenses. -- -- The lens type is defined using (erased) univalence. The use of a -- record type makes it easier for Agda to infer the argument univ -- from a value of type Lens univ A B. -- -- Note that everything is erased, except for the getter and the -- setter. record Lens (@0 univ : Univalence (a ⊔ b)) (A : Type a) (B : Type b) : Type (a ⊔ b) where field -- A getter. get : A → B -- A setter. set : A → B → A -- The family get ⁻¹_ is coherently constant (in erased contexts). @0 get⁻¹-coherently-constant : S.Coherently-constant univ (get ⁻¹_) -- Using get and get⁻¹-coherently-constant we can construct an -- erased lens. @0 erased-lens : S.Lens univ A B erased-lens = record { get = get ; get⁻¹-coherently-constant = get⁻¹-coherently-constant } field -- The setter that we get from this lens is equal to set. @0 set≡set : set ≡ S.Lens.set erased-lens -- The family of fibres of the getter is coherently constant. coherently-constant-fibres-get : Coherently-constant-fibres univ get coherently-constant-fibres-get = set , [ (get⁻¹-coherently-constant , set≡set) ] instance -- The lenses defined above have getters and setters. has-getter-and-setter : {@0 univ : Univalence (a ⊔ b)} → Has-getter-and-setter (Lens {a = a} {b = b} univ) has-getter-and-setter = record { get = Lens.get ; set = Lens.set } -- Lens can be expressed as a Σ-type. Lens-as-Σ : {A : Type a} {B : Type b} {@0 univ : Univalence (a ⊔ b)} → Lens univ A B ≃ ∃ λ (get : A → B) → Coherently-constant-fibres univ get Lens-as-Σ = Eq.↔→≃ (λ l → Lens.get l , Lens.coherently-constant-fibres-get l) _ refl refl -- Lens univ A B is equivalent to CE.Lens A B (with erased proofs, -- assuming univalence). Lens≃ᴱLens : Block "Lens≃ᴱLens" → {A : Type a} {B : Type b} → @0 Univalence (lsuc (a ⊔ b)) → (@0 univ : Univalence (a ⊔ b)) → Lens univ A B ≃ᴱ CE.Lens A B Lens≃ᴱLens ⊠ {A = A} {B = B} univ′ univ = Lens univ A B ↔⟨ Lens-as-Σ ⟩ (∃ λ (get : A → B) → Coherently-constant-fibres univ get) ↝⟨ (∃-cong λ _ → Coherently-constant-fibres≃ᴱCoherently-constant-⁻¹ᴱ univ′ univ) ⟩□ (∃ λ (get : A → B) → CE.Coherently-constant (get ⁻¹ᴱ_)) □ -- The equivalence preserves getters and setters. Lens≃ᴱLens-preserves-getters-and-setters : (bl : Block "Lens≃ᴱLens") {A : Type a} {B : Type b} (@0 univ′ : Univalence (lsuc (a ⊔ b))) (@0 univ : Univalence (a ⊔ b)) → Preserves-getters-and-setters-⇔ A B (_≃ᴱ_.logical-equivalence (Lens≃ᴱLens bl univ′ univ)) Lens≃ᴱLens-preserves-getters-and-setters ⊠ univ′ univ = (λ _ → refl _ , refl _) , (λ l → let open CE.Lens l in refl _ , ⟨ext⟩ λ a → ⟨ext⟩ λ b → proj₁ (subst (λ _ → get ⁻¹ᴱ b) (refl tt) (get⁻¹ᴱ-const (get a) b (a , [ refl (get a) ]))) ≡⟨ cong proj₁ $ subst-refl _ _ ⟩∎ proj₁ (get⁻¹ᴱ-const (get a) b (a , [ refl (get a) ])) ∎) -- Lens univ A B is equivalent to E.Lens A B (with erased proofs, -- assuming univalence). Lens≃ᴱLensᴱ : Block "Lens≃ᴱLensᴱ" → {A : Type a} {B : Type b} {@0 univ : Univalence (a ⊔ b)} → @0 Univalence (lsuc (a ⊔ b)) → Lens univ A B ≃ᴱ E.Lens A B Lens≃ᴱLensᴱ bl {A = A} {B = B} {univ = univ} univ′ = Lens univ A B ↝⟨ Lens≃ᴱLens bl univ′ univ ⟩ CE.Lens A B ↝⟨ CE.Lens≃ᴱLens bl univ′ univ ⟩ V.Lens A B ↝⟨ V.Lens≃ᴱHigher-lens bl univ ⟩□ E.Lens A B □ -- The equivalence preserves getters and setters (in erased contexts). @0 Lens≃ᴱLensᴱ-preserves-getters-and-setters : (bl : Block "Lens→Lens") {A : Type a} {B : Type b} (@0 univ′ : Univalence (lsuc (a ⊔ b))) (@0 univ : Univalence (a ⊔ b)) → Preserves-getters-and-setters-⇔ A B (_≃ᴱ_.logical-equivalence (Lens≃ᴱLensᴱ bl {univ = univ} univ′)) Lens≃ᴱLensᴱ-preserves-getters-and-setters bl univ′ univ = Preserves-getters-and-setters-⇔-∘ {f = _≃ᴱ_.logical-equivalence (V.Lens≃ᴱHigher-lens bl univ) F.∘ _≃ᴱ_.logical-equivalence (CE.Lens≃ᴱLens bl univ′ univ)} {g = _≃ᴱ_.logical-equivalence (Lens≃ᴱLens bl univ′ univ)} (Preserves-getters-and-setters-⇔-∘ {f = _≃ᴱ_.logical-equivalence (V.Lens≃ᴱHigher-lens bl univ)} {g = _≃ᴱ_.logical-equivalence (CE.Lens≃ᴱLens bl univ′ univ)} (V.Lens≃ᴱHigher-lens-preserves-getters-and-setters bl univ) (CE.Lens≃ᴱLens-preserves-getters-and-setters bl univ′ univ)) (Lens≃ᴱLens-preserves-getters-and-setters bl univ′ univ) -- In erased contexts Lens univ A B is equivalent to S.Lens univ A B. @0 Lens≃Lens : (bl : Block "Constant-≃-get-⁻¹-≃") → Lens univ A B ≃ S.Lens univ A B Lens≃Lens {univ = univ} {A = A} {B = B} bl = Lens univ A B ↝⟨ Lens-as-Σ ⟩ (∃ λ (get : A → B) → Coherently-constant-fibres univ get) ↝⟨ (∃-cong λ _ → Coherently-constant-fibres≃Coherently-constant-⁻¹ bl univ) ⟩ (∃ λ (get : A → B) → S.Coherently-constant univ (get ⁻¹_)) ↝⟨ inverse S.Lens-as-Σ ⟩□ S.Lens univ A B □ -- Lens≃Lens preserves getters and setters. @0 Lens≃Lens-preserves-getters-and-setters : (bl : Block "Lens≃Lens") {A : Type a} {B : Type b} {univ : Univalence (a ⊔ b)} → Preserves-getters-and-setters-⇔ A B (_≃_.logical-equivalence (Lens≃Lens {univ = univ} bl)) Lens≃Lens-preserves-getters-and-setters ⊠ = (λ l → let open Lens l in refl _ , (S.Lens.set erased-lens ≡⟨ sym set≡set ⟩∎ set ∎)) , (λ _ → refl _ , refl _) -- Lenses with stable view types are equal if their setters are equal -- (in erased contexts, assuming univalence). @0 lenses-equal-if-setters-equal : {A : Type a} {B : Type b} → Univalence (lsuc (a ⊔ b)) → (univ : Univalence (a ⊔ b)) → (l₁ l₂ : Lens univ A B) → (∥ B ∥ → B) → Lens.set l₁ ≡ Lens.set l₂ → l₁ ≡ l₂ lenses-equal-if-setters-equal univ′ univ l₁ l₂ stable = block λ bl → Lens.set l₁ ≡ Lens.set l₂ ↔⟨ ≡⇒≃ $ sym $ cong₂ _≡_ (proj₂ $ proj₁ (Lens≃Lens-preserves-getters-and-setters bl) l₁) (proj₂ $ proj₁ (Lens≃Lens-preserves-getters-and-setters bl) l₂) ⟩ S.Lens.set (_≃_.to (Lens≃Lens bl) l₁) ≡ S.Lens.set (_≃_.to (Lens≃Lens bl) l₂) ↝⟨ S.lenses-equal-if-setters-equal univ′ _ _ _ stable ⟩ _≃_.to (Lens≃Lens bl) l₁ ≡ _≃_.to (Lens≃Lens bl) l₂ ↔⟨ Eq.≃-≡ $ Lens≃Lens bl ⟩□ l₁ ≡ l₂ □ ------------------------------------------------------------------------ -- Changing the implementation of the getter and the setter -- One can change the getter of a lens, provided that the new -- implementation is extensionally equal to the old one. with-other-getter : {A : Type a} {B : Type b} (@0 univ : Univalence (a ⊔ b)) (l : Lens univ A B) (get : A → B) → @0 get ≡ Lens.get l → Lens univ A B with-other-getter {A = A} {B = B} univ l get p = record l { get = get ; get⁻¹-coherently-constant = subst (S.Coherently-constant univ ∘ _⁻¹_) (sym p) L.get⁻¹-coherently-constant ; set≡set = L.set ≡⟨ L.set≡set ⟩ S.Lens.set l₁ ≡⟨ cong S.Lens.set $ sym l₂≡l₁ ⟩∎ S.Lens.set l₂ ∎ } where module L = Lens l @0 l₁ l₂ : S.Lens univ A B l₁ = record { get = L.get ; get⁻¹-coherently-constant = L.get⁻¹-coherently-constant } l₂ = record { get = get ; get⁻¹-coherently-constant = subst (S.Coherently-constant univ ∘ _⁻¹_) (sym p) L.get⁻¹-coherently-constant } @0 l₂≡l₁ : l₂ ≡ l₁ l₂≡l₁ = _≃_.to (Eq.≃-≡ S.Lens-as-Σ) $ Σ-≡,≡→≡ p (subst (S.Coherently-constant univ ∘ _⁻¹_) p (subst (S.Coherently-constant univ ∘ _⁻¹_) (sym p) L.get⁻¹-coherently-constant) ≡⟨ subst-subst-sym _ _ _ ⟩∎ L.get⁻¹-coherently-constant ∎) _ : Lens.get (with-other-getter univ l g p) ≡ g _ = refl _ _ : Lens.set (with-other-getter univ l g p) ≡ Lens.set l _ = refl _ -- The resulting lens is equal to the old one (if the equality proof -- is not erased). with-other-getter≡ : {A : Type a} {B : Type b} (@0 univ : Univalence (a ⊔ b)) (l : Lens univ A B) (get : A → B) (p : get ≡ Lens.get l) → with-other-getter univ l get p ≡ l with-other-getter≡ {A = A} {B = B} univ l get p = _≃_.to (Eq.≃-≡ Lens-as-Σ) $ Σ-≡,≡→≡ p (subst (Coherently-constant-fibres univ) p L′.coherently-constant-fibres-get ≡⟨ push-subst-pair-× _ _ ⟩ L.set , subst (λ get → Erased (∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → L.set ≡ S.Lens.set {univ = univ} (record { get⁻¹-coherently-constant = c }))) p [ (L′.get⁻¹-coherently-constant , L′.set≡set) ] ≡⟨ cong (L.set ,_) push-subst-[] ⟩ L.set , [ subst (λ get → ∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → L.set ≡ S.Lens.set {univ = univ} (record { get⁻¹-coherently-constant = c })) p (L′.get⁻¹-coherently-constant , L′.set≡set) ] ≡⟨ cong (L.set ,_) $ []-cong [ push-subst-pair′ _ _ _ ] ⟩ L.set , [ ( L.get⁻¹-coherently-constant , subst (λ ((get , c) : ∃ (S.Coherently-constant univ ∘ _⁻¹_)) → L.set ≡ S.Lens.set {univ = univ} (record { get⁻¹-coherently-constant = c })) (Σ-≡,≡→≡ p (subst-subst-sym _ _ _)) L′.set≡set ) ] ≡⟨⟩ L.set , [ ( L.get⁻¹-coherently-constant , let q = Σ-≡,≡→≡ {p₂ = _ , L.get⁻¹-coherently-constant} p (subst-subst-sym _ _ _) in subst (λ ((get , c) : ∃ (S.Coherently-constant univ ∘ _⁻¹_)) → L.set ≡ S.Lens.set {univ = univ} (record { get⁻¹-coherently-constant = c })) q (trans L.set≡set (cong (S.Lens.set {univ = univ}) $ sym $ _≃_.to (Eq.≃-≡ S.Lens-as-Σ) q)) ) ] ≡⟨ cong (L.set ,_) $ []-cong [ cong (L.get⁻¹-coherently-constant ,_) $ elim₁ (λ q → subst (λ ((get , c) : ∃ (S.Coherently-constant univ ∘ _⁻¹_)) → L.set ≡ S.Lens.set {univ = univ} (record { get⁻¹-coherently-constant = c })) q (trans L.set≡set (cong (S.Lens.set {univ = univ}) $ sym $ _≃_.to (Eq.≃-≡ S.Lens-as-Σ) q)) ≡ L.set≡set) (trans (subst-refl _ _) $ trans (cong (trans _) $ trans (cong (cong _) $ trans (cong sym (Eq.to-≃-≡-refl S.Lens-as-Σ)) sym-refl) $ cong-refl _) $ trans-reflʳ _) _ ] ⟩ L.set , [ (L.get⁻¹-coherently-constant , L.set≡set) ] ≡⟨⟩ L.coherently-constant-fibres-get ∎) where module L = Lens l l′ : Lens univ A B l′ = record { get = get ; get⁻¹-coherently-constant = subst (S.Coherently-constant univ ∘ _⁻¹_) (sym p) L.get⁻¹-coherently-constant } module L′ = Lens l′ -- One can change the setter of a lens, provided that the new -- implementation is extensionally equal to the old one. with-other-setter : {A : Type a} {B : Type b} {@0 univ : Univalence (a ⊔ b)} (l : Lens univ A B) (set : A → B → A) → @0 set ≡ Lens.set l → Lens univ A B with-other-setter l set p = record l { set = set ; set≡set = trans p (Lens.set≡set l) } _ : Lens.get (with-other-setter l s p) ≡ Lens.get l _ = refl _ _ : Lens.set (with-other-setter l s p) ≡ s _ = refl _ -- The resulting lens is equal to the old one (if the equality proof -- is not erased). with-other-setter≡ : {A : Type a} {B : Type b} {@0 univ : Univalence (a ⊔ b)} (l : Lens univ A B) (set : A → B → A) (p : set ≡ Lens.set l) → with-other-setter l set p ≡ l with-other-setter≡ {univ = univ} l set p = _≃_.to (Eq.≃-≡ Lens-as-Σ) $ cong (get ,_) $ Σ-≡,≡→≡ p (subst (λ set → Erased (∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → set ≡ S.Lens.set {univ = univ} (record { get⁻¹-coherently-constant = c }))) p [ (get⁻¹-coherently-constant , trans p set≡set) ] ≡⟨ push-subst-[] ⟩ [ subst (λ set → ∃ λ (c : S.Coherently-constant univ (get ⁻¹_)) → set ≡ S.Lens.set {univ = univ} (record { get⁻¹-coherently-constant = c })) p (get⁻¹-coherently-constant , trans p set≡set) ] ≡⟨ []-cong [ push-subst-pair-× _ _ ] ⟩ [ ( get⁻¹-coherently-constant , subst (_≡ S.Lens.set {univ = univ} (record { get⁻¹-coherently-constant = get⁻¹-coherently-constant })) p (trans p set≡set) ) ] ≡⟨ []-cong [ cong (_ ,_) subst-trans-sym ] ⟩ [ ( get⁻¹-coherently-constant , trans (sym p) (trans p set≡set) ) ] ≡⟨ []-cong [ cong (_ ,_) $ trans-sym-[trans] _ _ ] ⟩∎ [ (get⁻¹-coherently-constant , set≡set) ] ∎) where open Lens l ------------------------------------------------------------------------ -- Code for converting from S.Lens to Lens -- Data corresponding to the erased proofs of a lens. record Erased-proofs {A : Type a} {B : Type b} (univ : Univalence (a ⊔ b)) (get : A → B) (set : A → B → A) : Type (a ⊔ b) where field @0 get⁻¹-coherently-constant : S.Coherently-constant univ (get ⁻¹_) @0 erased-lens : S.Lens univ A B erased-lens = record { get = get ; get⁻¹-coherently-constant = get⁻¹-coherently-constant } field @0 set≡set : set ≡ S.Lens.set erased-lens -- Extracts "erased proofs" from a lens (in erased contexts). @0 Lens→Erased-proofs : (l : S.Lens univ A B) → Erased-proofs univ (S.Lens.get l) (S.Lens.set l) Lens→Erased-proofs {univ = univ} l = proofs ⊠ where module _ (bl : Unit) where open Erased-proofs l′ = _≃_.from (Lens≃Lens bl) l proofs : Erased-proofs univ (Lens.get l′) (Lens.set l′) proofs .get⁻¹-coherently-constant = Lens.get⁻¹-coherently-constant l′ proofs .set≡set = Lens.set≡set l′ -- Converts two functions and some erased proofs to a lens. -- -- Note that Agda can in many cases infer "get" and "set" from the -- first explicit argument, see (for instance) id below. Erased-proofs→Lens : {A : Type a} {B : Type b} {get : A → B} {set : A → B → A} {@0 univ : Univalence (a ⊔ b)} → @0 Erased-proofs univ get set → Lens univ A B Erased-proofs→Lens {get = get} {set = set} ep = λ where .Lens.get → get .Lens.set → set .Lens.get⁻¹-coherently-constant → Erased-proofs.get⁻¹-coherently-constant ep .Lens.set≡set → Erased-proofs.set≡set ep ------------------------------------------------------------------------ -- Identity and composition -- An identity lens. id : {A : Type a} (@0 univ : Univalence a) → Lens univ A A id univ = Erased-proofs→Lens (Lens→Erased-proofs (S.id univ)) -- Composition. infix 9 ⟨_,_⟩_∘_ ⟨_,_⟩_∘_ : {A : Type a} {B : Type b} {C : Type c} {@0 univ₁ : Univalence (b ⊔ c)} {@0 univ₂ : Univalence (a ⊔ b)} (@0 univ₃ : Univalence (a ⊔ c)) → @0 Univalence (a ⊔ b ⊔ c) → Lens univ₁ B C → Lens univ₂ A B → Lens univ₃ A C ⟨ univ₃ , univ ⟩ l₁ ∘ l₂ = Erased-proofs→Lens (subst (Erased-proofs _ _) (⟨ext⟩ λ a → ⟨ext⟩ λ c → S.Lens.set l₂′ a (S.Lens.set l₁′ (get l₂ a) c) ≡⟨ cong (λ s → s a (S.Lens.set l₁′ (get l₂ a) c)) $ proj₂ $ proj₁ (Lens≃Lens-preserves-getters-and-setters ⊠) l₂ ⟩ set l₂ a (S.Lens.set l₁′ (get l₂ a) c) ≡⟨ cong (λ s → set l₂ a (s (get l₂ a) c)) $ proj₂ $ proj₁ (Lens≃Lens-preserves-getters-and-setters ⊠) l₁ ⟩∎ set l₂ a (set l₁ (get l₂ a) c) ∎) $ Lens→Erased-proofs (S.⟨ univ₃ , univ ⟩ l₁′ ∘ l₂′)) where open Lens @0 l₁′ : _ l₁′ = _≃_.to (Lens≃Lens ⊠) l₁ @0 l₂′ : _ l₂′ = _≃_.to (Lens≃Lens ⊠) l₂ -- The setter of a lens formed using composition is defined in the -- "right" way. set-∘ : ∀ {A : Type a} {B : Type b} {C : Type c} {@0 univ₁ : Univalence (b ⊔ c)} {@0 univ₂ : Univalence (a ⊔ b)} (@0 univ₃ : Univalence (a ⊔ c)) (@0 univ₄ : Univalence (a ⊔ b ⊔ c)) (l₁ : Lens univ₁ B C) (l₂ : Lens univ₂ A B) {a c} → Lens.set (⟨ univ₃ , univ₄ ⟩ l₁ ∘ l₂) a c ≡ Lens.set l₂ a (Lens.set l₁ (Lens.get l₂ a) c) set-∘ _ _ _ _ = refl _ -- Composition is associative if the view type of the resulting lens -- is stable (in erased contexts, assuming univalence). @0 associativity : {A : Type a} {B : Type b} {C : Type c} {D : Type d} → (∥ D ∥ → D) → (univ₁ : Univalence (c ⊔ d)) (univ₂ : Univalence (b ⊔ c)) (univ₃ : Univalence (a ⊔ b)) (univ₄ : Univalence (a ⊔ d)) (univ₅ : Univalence (a ⊔ c ⊔ d)) (univ₆ : Univalence (a ⊔ c)) (univ₇ : Univalence (a ⊔ b ⊔ c)) (univ₈ : Univalence (a ⊔ b ⊔ d)) (univ₉ : Univalence (b ⊔ d)) (univ₁₀ : Univalence (b ⊔ c ⊔ d)) → Univalence (lsuc (a ⊔ d)) → (l₁ : Lens univ₁ C D) (l₂ : Lens univ₂ B C) (l₃ : Lens univ₃ A B) → ⟨ univ₄ , univ₅ ⟩ l₁ ∘ (⟨ univ₆ , univ₇ ⟩ l₂ ∘ l₃) ≡ ⟨ univ₄ , univ₈ ⟩ (⟨ univ₉ , univ₁₀ ⟩ l₁ ∘ l₂) ∘ l₃ associativity stable _ _ _ univ₄ _ _ _ _ _ _ univ₁₁ l₁ l₂ l₃ = lenses-equal-if-setters-equal univ₁₁ univ₄ _ _ stable (refl _) -- The identity lens is a left identity of composition if the view -- type of the resulting lens is stable (assuming univalence). @0 left-identity : {A : Type a} {B : Type b} → (∥ B ∥ → B) → (univ₁ : Univalence (a ⊔ b)) (univ₂ : Univalence (a ⊔ b)) (univ₃ : Univalence b) → Univalence (lsuc (a ⊔ b)) → (l : Lens univ₁ A B) → ⟨ univ₁ , univ₂ ⟩ id univ₃ ∘ l ≡ l left-identity stable univ₁ univ₂ univ₃ univ₄ l = lenses-equal-if-setters-equal univ₄ univ₁ _ _ stable (refl _) -- The identity lens is a right identity of composition if the view -- type of the resulting lens is stable (assuming univalence). @0 right-identity : {A : Type a} {B : Type b} → (∥ B ∥ → B) → (univ₁ : Univalence (a ⊔ b)) (univ₂ : Univalence (a ⊔ b)) (univ₃ : Univalence a) → Univalence (lsuc (a ⊔ b)) → (l : Lens univ₁ A B) → ⟨ univ₁ , univ₂ ⟩ l ∘ id univ₃ ≡ l right-identity stable univ₁ univ₂ univ₃ univ₄ l = lenses-equal-if-setters-equal univ₄ univ₁ _ _ stable (refl _)
{ "alphanum_fraction": 0.3996801446, "avg_line_length": 45.0830721003, "ext": "agda", "hexsha": "f580a3250bef5571dbe1582e6e982d796d01b16d", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2020-07-01T14:33:26.000Z", "max_forks_repo_forks_event_min_datetime": "2020-07-01T14:33:26.000Z", "max_forks_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/dependent-lenses", "max_forks_repo_path": "src/Lens/Non-dependent/Higher/Coinductive/Small/Erased.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/dependent-lenses", "max_issues_repo_path": "src/Lens/Non-dependent/Higher/Coinductive/Small/Erased.agda", "max_line_length": 150, "max_stars_count": 3, "max_stars_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/dependent-lenses", "max_stars_repo_path": "src/Lens/Non-dependent/Higher/Coinductive/Small/Erased.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:55:52.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-16T12:10:46.000Z", "num_tokens": 19017, "size": 57526 }
module perm-keep-length where open import nat open import list open import nondet open import bool open import bool-thms open import eq open import nat-thms open import nondet-thms -- Non-deterministic insert: ndinsert : {a : Set} → a → 𝕃 a → ND (𝕃 a) ndinsert x [] = Val (x :: []) ndinsert x (y :: ys) = Val (x :: y :: ys) ?? (_::_ y) $* (ndinsert x ys) -- Permutation: perm : {a : Set} → 𝕃 a → ND (𝕃 a) perm [] = Val [] perm (x :: xs) = ndinsert x *$* (perm xs) ---------------------------------------------------------------------- -- Non-deterministic insertion increases the list length by one: insert-inc-length : {a : Set} (x : a) → (xs : 𝕃 a) → (ndinsert x xs) satisfy (λ ys → length ys =ℕ suc (length xs)) ≡ tt insert-inc-length x [] = refl insert-inc-length x (y :: ys) rewrite =ℕ-refl (length ys) | satisfy-$* (_::_ y) (ndinsert x ys) (λ zs → length zs =ℕ suc (suc (length ys))) | insert-inc-length x ys = refl -- If the length of the input list is n, ndinsert increases it to (suc n): insert-suc-length : {a : Set} → (n : ℕ) (x : a) (xs : 𝕃 a) → length xs =ℕ n ≡ tt → ndinsert x xs satisfy (λ ys → length ys =ℕ suc n) ≡ tt insert-suc-length n x [] p = p insert-suc-length n x (y :: ys) p rewrite =ℕ-to-≡ {suc (length ys)} {n} p | =ℕ-refl n | satisfy-$* (_::_ y) (ndinsert x ys) (λ zs → length zs =ℕ suc n) | sym (=ℕ-to-≡ {suc (length ys)} {n} p) | insert-inc-length x ys = refl -- The previous lemma is also valid on non-deterministic lists: ins-suc-nondet : {a : Set} → (n : ℕ) → (x : a) → (t : ND (𝕃 a)) → t satisfy (λ xs → length xs =ℕ n) ≡ tt → (ndinsert x *$* t) satisfy (λ xs → length xs =ℕ suc n) ≡ tt ins-suc-nondet n x (Val xs) p = insert-suc-length n x xs p ins-suc-nondet n x (t1 ?? t2) p rewrite ins-suc-nondet n x t1 (&&-fst p) | ins-suc-nondet n x t2 (&&-snd {t1 satisfy (λ xs → length xs =ℕ n)} p) = refl -- The length of a permuted list is identical to the length of the list: perm-length : {a : Set} → (xs : 𝕃 a) → (perm xs) satisfy (λ ys → length ys =ℕ length xs) ≡ tt perm-length [] = refl perm-length (x :: xs) = ins-suc-nondet (length xs) x (perm xs) (perm-length xs)
{ "alphanum_fraction": 0.5496049166, "avg_line_length": 36.1587301587, "ext": "agda", "hexsha": "c32477c2e87213a70c0bf9174ab700e0f8614578", "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": "b7cfdda11cdadeba882b6b72d75448acd8b0a294", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "mihanus/curry-agda", "max_forks_repo_path": "nondet/perm-keep-length.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294", "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": "mihanus/curry-agda", "max_issues_repo_path": "nondet/perm-keep-length.agda", "max_line_length": 79, "max_stars_count": null, "max_stars_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "mihanus/curry-agda", "max_stars_repo_path": "nondet/perm-keep-length.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 780, "size": 2278 }
------------------------------------------------------------------------ -- Total recognisers which can handle left recursion ------------------------------------------------------------------------ -- The recognisers are parametrised on the alphabet. module TotalRecognisers.LeftRecursion (Tok : Set) where open import Algebra open import Codata.Musical.Notation open import Data.Bool as Bool hiding (_∧_; _≤_) import Data.Bool.Properties as Bool private module BoolCS = CommutativeSemiring Bool.∧-∨-commutativeSemiring open import Function.Base open import Function.Equality using (_⟨$⟩_) open import Function.Equivalence as Eq using (_⇔_; equivalence; module Equivalence) renaming (_∘_ to _⟨∘⟩_) open import Data.List using (List; []; _∷_; _++_; [_]) import Data.List.Properties private module ListMonoid {A : Set} = Monoid (Data.List.Properties.++-monoid A) open import Data.Product as Prod open import Relation.Binary.PropositionalEquality hiding ([_]) open import Relation.Nullary open import Relation.Nullary.Decidable as Decidable ------------------------------------------------------------------------ -- A "right-strict" variant of _∧_ -- If the left-strict variant of _∧_ were used to type _·_ below, then -- the inferred definition of D-nullable would not be total; it would -- contain expressions of the form "D-nullable t (♭ p₁) ∧ false". With -- the right-strict definition of _∧_ such expressions reduce to -- "false". infixr 6 _∧_ _∧_ : Bool → Bool → Bool b ∧ true = b b ∧ false = false -- A lemma. left-zero : ∀ b → false ∧ b ≡ false left-zero true = refl left-zero false = refl ------------------------------------------------------------------------ -- Recogniser combinators infixl 10 _·_ infixl 5 _∣_ mutual -- The index is true if the corresponding language contains the empty -- string (is nullable). data P : Bool → Set where fail : P false empty : P true sat : (Tok → Bool) → P false _∣_ : ∀ {n₁ n₂} → P n₁ → P n₂ → P (n₁ ∨ n₂) _·_ : ∀ {n₁ n₂} → ∞⟨ n₂ ⟩P n₁ → ∞⟨ n₁ ⟩P n₂ → P (n₁ ∧ n₂) nonempty : ∀ {n} → P n → P false cast : ∀ {n₁ n₂} → n₁ ≡ n₂ → P n₁ → P n₂ -- Delayed if the index is /false/. ∞⟨_⟩P : Bool → Bool → Set ∞⟨ false ⟩P n = ∞ (P n) ∞⟨ true ⟩P n = P n -- Note that fail, nonempty and cast could be defined as derived -- combinators. (For cast this is obvious, fail could be defined -- either using sat or the combinator leftRight below, and nonempty is -- defined in the module AlternativeNonempty. Note also that the proof -- in TotalRecognisers.LeftRecursion.ExpressiveStrength does not rely -- on these constructors.) However, Agda uses /guarded/ corecursion, -- so the fact that nonempty and cast are constructors can be very -- convenient when constructing other recognisers. -- For an example of the use of nonempty, see the Kleene star example -- in TotalRecognisers.LeftRecursion.Lib. For examples of the use of -- cast, see TotalRecognisers.LeftRecursion.ExpressiveStrength and -- TotalRecognisers.LeftRecursion.NotOnlyContextFree. ------------------------------------------------------------------------ -- Helpers ♭? : ∀ {b n} → ∞⟨ b ⟩P n → P n ♭? {b = false} x = ♭ x ♭? {b = true} x = x ♯? : ∀ {b n} → P n → ∞⟨ b ⟩P n ♯? {b = false} x = ♯ x ♯? {b = true} x = x forced? : ∀ {b n} → ∞⟨ b ⟩P n → Bool forced? {b = b} _ = b -- A lemma. ♭?♯? : ∀ b {n} {p : P n} → ♭? {b} (♯? p) ≡ p ♭?♯? false = refl ♭?♯? true = refl ------------------------------------------------------------------------ -- Semantics -- The semantics is defined inductively: s ∈ p iff the string s is -- contained in the language defined by p. infix 4 _∈_ data _∈_ : ∀ {n} → List Tok → P n → Set where empty : [] ∈ empty sat : ∀ {f t} → T (f t) → [ t ] ∈ sat f ∣-left : ∀ {s n₁ n₂} {p₁ : P n₁} {p₂ : P n₂} → s ∈ p₁ → s ∈ p₁ ∣ p₂ ∣-right : ∀ {s n₁ n₂} {p₁ : P n₁} {p₂ : P n₂} → s ∈ p₂ → s ∈ p₁ ∣ p₂ _·_ : ∀ {s₁ s₂ n₁ n₂} {p₁ : ∞⟨ n₂ ⟩P n₁} {p₂ : ∞⟨ n₁ ⟩P n₂} → s₁ ∈ ♭? p₁ → s₂ ∈ ♭? p₂ → s₁ ++ s₂ ∈ p₁ · p₂ nonempty : ∀ {n t s} {p : P n} → t ∷ s ∈ p → t ∷ s ∈ nonempty p cast : ∀ {n₁ n₂ s} {p : P n₁} {eq : n₁ ≡ n₂} → s ∈ p → s ∈ cast eq p infix 4 _≤_ _≈_ -- p₁ ≤ p₂ iff the language (defined by) p₂ contains all the strings -- in the language p₁. _≤_ : ∀ {n₁ n₂} → P n₁ → P n₂ → Set p₁ ≤ p₂ = ∀ {s} → s ∈ p₁ → s ∈ p₂ -- p₁ ≈ p₂ iff the languages p₁ and p₂ contain the same strings. _≈_ : ∀ {n₁ n₂} → P n₁ → P n₂ → Set p₁ ≈ p₂ = ∀ {s} → s ∈ p₁ ⇔ s ∈ p₂ -- p₁ ≈ p₂ iff both p₁ ≤ p₂ and p₂ ≤ p₁. ≈⇔≤≥ : ∀ {n₁ n₂} {p₁ : P n₁} {p₂ : P n₂} → p₁ ≈ p₂ ⇔ (p₁ ≤ p₂ × p₂ ≤ p₁) ≈⇔≤≥ = equivalence (λ p₁≈p₂ → ((λ {s} → _⟨$⟩_ (Equivalence.to (p₁≈p₂ {s = s}))) , λ {s} → _⟨$⟩_ (Equivalence.from (p₁≈p₂ {s = s})))) (λ p₁≤≥p₂ {s} → equivalence (proj₁ p₁≤≥p₂ {s = s}) (proj₂ p₁≤≥p₂ {s = s})) -- Some lemmas. cast∈ : ∀ {n} {p p′ : P n} {s s′} → s ≡ s′ → p ≡ p′ → s ∈ p → s′ ∈ p′ cast∈ refl refl s∈ = s∈ drop-♭♯ : ∀ n {n′} {p : P n′} → ♭? (♯? {n} p) ≤ p drop-♭♯ n = cast∈ refl (♭?♯? n) add-♭♯ : ∀ n {n′} {p : P n′} → p ≤ ♭? (♯? {n} p) add-♭♯ n = cast∈ refl (sym $ ♭?♯? n) ------------------------------------------------------------------------ -- Example: A definition which is left and right recursive leftRight : P false leftRight = ♯ leftRight · ♯ leftRight -- Note that leftRight is equivalent to fail, so fail does not need to -- be a primitive combinator. leftRight≈fail : leftRight ≈ fail leftRight≈fail = equivalence ≤fail (λ ()) where ≤fail : ∀ {s A} → s ∈ leftRight → A ≤fail (∈₁ · ∈₂) = ≤fail ∈₁ -- For more examples, see TotalRecognisers.LeftRecursion.Lib. ------------------------------------------------------------------------ -- Nullability -- The nullability index is correct. ⇒ : ∀ {n} {p : P n} → [] ∈ p → n ≡ true ⇒ pr = ⇒′ pr refl where ⇒′ : ∀ {n s} {p : P n} → s ∈ p → s ≡ [] → n ≡ true ⇒′ empty refl = refl ⇒′ (sat _) () ⇒′ (∣-left pr₁) refl with ⇒ pr₁ ⇒′ (∣-left pr₁) refl | refl = refl ⇒′ (∣-right pr₂) refl with ⇒ pr₂ ⇒′ (∣-right {n₁ = n₁} pr₂) refl | refl = proj₂ BoolCS.zero n₁ ⇒′ (nonempty p) () ⇒′ (cast {eq = refl} p) refl = ⇒′ p refl ⇒′ (_·_ {[]} pr₁ pr₂) refl = cong₂ _∧_ (⇒ pr₁) (⇒ pr₂) ⇒′ (_·_ {_ ∷ _} pr₁ pr₂) () ⇐ : ∀ {n} (p : P n) → n ≡ true → [] ∈ p ⇐ fail () ⇐ empty refl = empty ⇐ (sat f) () ⇐ (_∣_ {true} p₁ p₂) refl = ∣-left (⇐ p₁ refl) ⇐ (_∣_ {false} {true} p₁ p₂) refl = ∣-right {p₁ = p₁} (⇐ p₂ refl) ⇐ (_∣_ {false} {false} p₁ p₂) () ⇐ (nonempty p) () ⇐ (cast refl p) refl = cast (⇐ p refl) ⇐ (_·_ {.true} {true} p₁ p₂) refl = ⇐ p₁ refl · ⇐ p₂ refl ⇐ (_·_ {_} {false} p₁ p₂) () index-correct : ∀ {n} {p : P n} → [] ∈ p ⇔ n ≡ true index-correct = equivalence ⇒ (⇐ _) -- We can decide if the empty string belongs to a given language. nullable? : ∀ {n} (p : P n) → Dec ([] ∈ p) nullable? {n} p = Decidable.map (Eq.sym index-correct) (Bool._≟_ n true) ------------------------------------------------------------------------ -- Derivative -- The index of the derivative. D-nullable : ∀ {n} → Tok → P n → Bool D-nullable t fail = false D-nullable t empty = false D-nullable t (sat f) = f t D-nullable t (p₁ ∣ p₂) = D-nullable t p₁ ∨ D-nullable t p₂ D-nullable t (nonempty p) = D-nullable t p D-nullable t (cast _ p) = D-nullable t p D-nullable t (p₁ · p₂) with forced? p₁ | forced? p₂ ... | true | false = D-nullable t p₁ ... | false | false = false ... | true | true = D-nullable t p₁ ∨ D-nullable t p₂ ... | false | true = D-nullable t p₂ -- D t p is the "derivative" of p with respect to t. It is specified -- by the equivalence s ∈ D t p ⇔ t ∷ s ∈ p (proved below). D : ∀ {n} (t : Tok) (p : P n) → P (D-nullable t p) D t fail = fail D t empty = fail D t (sat f) with f t ... | true = empty ... | false = fail D t (p₁ ∣ p₂) = D t p₁ ∣ D t p₂ D t (nonempty p) = D t p D t (cast _ p) = D t p D t (p₁ · p₂) with forced? p₁ | forced? p₂ ... | true | false = D t p₁ · ♯? (♭ p₂) ... | false | false = ♯ D t (♭ p₁) · ♯? (♭ p₂) ... | true | true = D t p₁ · ♯? p₂ ∣ D t p₂ ... | false | true = ♯ D t (♭ p₁) · ♯? p₂ ∣ D t p₂ -- D is correct. D-sound : ∀ {n s t} {p : P n} → s ∈ D t p → t ∷ s ∈ p D-sound s∈ = D-sound′ _ _ s∈ where sat-lemma : ∀ {s} f t → s ∈ D t (sat f) → T (f t) × s ≡ [] sat-lemma f t ∈ with f t sat-lemma f t empty | true = (_ , refl) sat-lemma f t () | false D-sound′ : ∀ {s n} (p : P n) t → s ∈ D t p → t ∷ s ∈ p D-sound′ fail t () D-sound′ empty t () D-sound′ (sat f) t s∈ with sat-lemma f t s∈ ... | (ok , refl) = sat ok D-sound′ (p₁ ∣ p₂) t (∣-left ∈₁) = ∣-left (D-sound′ p₁ t ∈₁) D-sound′ (p₁ ∣ p₂) t (∣-right ∈₂) = ∣-right {p₁ = p₁} (D-sound′ p₂ t ∈₂) D-sound′ (nonempty p) t ∈ = nonempty (D-sound ∈) D-sound′ (cast _ p) t ∈ = cast (D-sound ∈) D-sound′ (p₁ · p₂) t s∈ with forced? p₁ | forced? p₂ D-sound′ (p₁ · p₂) t (∣-left (∈₁ · ∈₂)) | true | true = D-sound ∈₁ · drop-♭♯ (D-nullable t p₁) ∈₂ D-sound′ (p₁ · p₂) t (∣-right ∈₂) | true | true = ⇐ p₁ refl · D-sound′ p₂ t ∈₂ D-sound′ (p₁ · p₂) t (∣-left (∈₁ · ∈₂)) | false | true = D-sound ∈₁ · drop-♭♯ (D-nullable t (♭ p₁)) ∈₂ D-sound′ (p₁ · p₂) t (∣-right ∈₂) | false | true = ⇐ (♭ p₁) refl · D-sound′ p₂ t ∈₂ D-sound′ (p₁ · p₂) t (∈₁ · ∈₂) | true | false = D-sound ∈₁ · drop-♭♯ (D-nullable t p₁ ) ∈₂ D-sound′ (p₁ · p₂) t (∈₁ · ∈₂) | false | false = D-sound ∈₁ · drop-♭♯ (D-nullable t (♭ p₁)) ∈₂ D-complete : ∀ {n s t} {p : P n} → t ∷ s ∈ p → s ∈ D t p D-complete {t = t} t∷s∈ = D-complete′ _ t∷s∈ refl where D-complete′ : ∀ {s s′ n} (p : P n) → s′ ∈ p → s′ ≡ t ∷ s → s ∈ D t p D-complete′ fail () refl D-complete′ empty () refl D-complete′ (sat f) (sat ok) refl with f t D-complete′ (sat f) (sat ok) refl | true = empty D-complete′ (sat f) (sat ()) refl | false D-complete′ (p₁ ∣ p₂) (∣-left ∈₁) refl = ∣-left (D-complete ∈₁) D-complete′ (p₁ ∣ p₂) (∣-right ∈₂) refl = ∣-right {p₁ = D t p₁} (D-complete ∈₂) D-complete′ (nonempty p) (nonempty ∈) refl = D-complete ∈ D-complete′ (cast _ p) (cast ∈) refl = D-complete ∈ D-complete′ (p₁ · p₂) _ _ with forced? p₁ | forced? p₂ D-complete′ (p₁ · p₂) (_·_ {[]} ∈₁ ∈₂) refl | true | true = ∣-right {p₁ = D t p₁ · _} (D-complete ∈₂) D-complete′ (p₁ · p₂) (_·_ {._ ∷ _} ∈₁ ∈₂) refl | true | true = ∣-left (D-complete ∈₁ · add-♭♯ (D-nullable t p₁) ∈₂) D-complete′ (p₁ · p₂) (_·_ {[]} ∈₁ ∈₂) refl | true | false with ⇒ ∈₁ D-complete′ (p₁ · p₂) (_·_ {[]} ∈₁ ∈₂) refl | true | false | () D-complete′ (p₁ · p₂) (_·_ {._ ∷ _} ∈₁ ∈₂) refl | true | false = D-complete ∈₁ · add-♭♯ (D-nullable t p₁) ∈₂ D-complete′ (p₁ · p₂) (_·_ {[]} ∈₁ ∈₂) refl | false | true = ∣-right {p₁ = _·_ {n₂ = false} _ _} (D-complete ∈₂) D-complete′ (p₁ · p₂) (_·_ {._ ∷ _} ∈₁ ∈₂) refl | false | true = ∣-left (D-complete ∈₁ · add-♭♯ (D-nullable t (♭ p₁)) ∈₂) D-complete′ (p₁ · p₂) (_·_ {[]} ∈₁ ∈₂) refl | false | false with ⇒ ∈₁ D-complete′ (p₁ · p₂) (_·_ {[]} ∈₁ ∈₂) refl | false | false | () D-complete′ (p₁ · p₂) (_·_ {._ ∷ _} ∈₁ ∈₂) refl | false | false = D-complete ∈₁ · add-♭♯ (D-nullable t (♭ p₁)) ∈₂ D-correct : ∀ {n s t} {p : P n} → s ∈ D t p ⇔ t ∷ s ∈ p D-correct = equivalence D-sound D-complete ------------------------------------------------------------------------ -- _∈_ is decidable -- _∈?_ runs a recogniser. Note that the result is yes or no plus a -- /proof/ verifying that the answer is correct. infix 4 _∈?_ _∈?_ : ∀ {n} (s : List Tok) (p : P n) → Dec (s ∈ p) [] ∈? p = nullable? p t ∷ s ∈? p with s ∈? D t p t ∷ s ∈? p | yes s∈Dtp = yes (D-sound s∈Dtp) t ∷ s ∈? p | no s∉Dtp = no (s∉Dtp ∘ D-complete) -- The last three lines could be replaced by the following one: -- -- t ∷ s ∈? p = Decidable.map D-correct (s ∈? D t p) ------------------------------------------------------------------------ -- Alternative characterisation of equality infix 5 _∷_ infix 4 _≈′_ -- Two recognisers/languages are equal if their nullability indices -- are equal and all their derivatives are equal (coinductively). Note -- that the elements of this type are bisimulations. data _≈′_ {n₁ n₂} (p₁ : P n₁) (p₂ : P n₂) : Set where _∷_ : n₁ ≡ n₂ → (∀ t → ∞ (D t p₁ ≈′ D t p₂)) → p₁ ≈′ p₂ -- This definition is equivalent to the one above. ≈′-sound : ∀ {n₁ n₂} {p₁ : P n₁} {p₂ : P n₂} → p₁ ≈′ p₂ → p₁ ≈ p₂ ≈′-sound (refl ∷ rest) {[]} = Eq.sym index-correct ⟨∘⟩ index-correct ≈′-sound (refl ∷ rest) {t ∷ s} = D-correct ⟨∘⟩ ≈′-sound (♭ (rest t)) ⟨∘⟩ Eq.sym D-correct same-nullability : ∀ {n₁ n₂} {p₁ : P n₁} {p₂ : P n₂} → p₁ ≈ p₂ → n₁ ≡ n₂ same-nullability p₁≈p₂ = Bool.⇔→≡ (index-correct ⟨∘⟩ p₁≈p₂ ⟨∘⟩ Eq.sym index-correct) D-cong : ∀ {n₁ n₂} {p₁ : P n₁} {p₂ : P n₂} {t} → p₁ ≈ p₂ → D t p₁ ≈ D t p₂ D-cong p₁≈p₂ = Eq.sym D-correct ⟨∘⟩ p₁≈p₂ ⟨∘⟩ D-correct ≈′-complete : ∀ {n₁ n₂} {p₁ : P n₁} {p₂ : P n₂} → p₁ ≈ p₂ → p₁ ≈′ p₂ ≈′-complete p₁≈p₂ = same-nullability p₁≈p₂ ∷ λ _ → ♯ ≈′-complete (D-cong p₁≈p₂) ≈′-correct : ∀ {n₁ n₂} {p₁ : P n₁} {p₂ : P n₂} → p₁ ≈′ p₂ ⇔ p₁ ≈ p₂ ≈′-correct = equivalence ≈′-sound ≈′-complete ------------------------------------------------------------------------ -- The combinator nonempty does not need to be primitive -- The variant of nonempty which is defined below (nonempty′) makes -- many recognisers larger, though. module AlternativeNonempty where nonempty′ : ∀ {n} → P n → P false nonempty′ fail = fail nonempty′ empty = fail nonempty′ (sat f) = sat f nonempty′ (p₁ ∣ p₂) = nonempty′ p₁ ∣ nonempty′ p₂ nonempty′ (nonempty p) = nonempty′ p nonempty′ (cast eq p) = nonempty′ p nonempty′ (p₁ · p₂) with forced? p₁ | forced? p₂ ... | false | _ = p₁ · p₂ ... | true | false = p₁ · p₂ ... | true | true = nonempty′ p₁ ∣ nonempty′ p₂ ∣ ♯ nonempty′ p₁ · ♯ nonempty′ p₂ sound : ∀ {n} {p : P n} → nonempty′ p ≤ nonempty p sound {s = []} pr with ⇒ pr ... | () sound {s = _ ∷ _} pr = nonempty (sound′ _ pr refl) where sound′ : ∀ {n t s s′} (p : P n) → s′ ∈ nonempty′ p → s′ ≡ t ∷ s → t ∷ s ∈ p sound′ fail () refl sound′ empty () refl sound′ (sat f) (sat ok) refl = sat ok sound′ (p₁ ∣ p₂) (∣-left pr) refl = ∣-left (sound′ p₁ pr refl) sound′ (p₁ ∣ p₂) (∣-right pr) refl = ∣-right {p₁ = p₁} (sound′ p₂ pr refl) sound′ (nonempty p) pr refl = nonempty (sound′ p pr refl) sound′ (cast _ p) pr refl = cast (sound′ p pr refl) sound′ (p₁ · p₂) pr _ with forced? p₁ | forced? p₂ sound′ (p₁ · p₂) pr refl | false | _ = pr sound′ (p₁ · p₂) pr refl | true | false = pr sound′ (p₁ · p₂) (∣-left (∣-left pr)) refl | true | true = cast∈ (proj₂ ListMonoid.identity _) refl $ sound′ p₁ pr refl · ⇐ p₂ refl sound′ (p₁ · p₂) (∣-left (∣-right pr)) refl | true | true = ⇐ p₁ refl · sound′ p₂ pr refl sound′ (p₁ · p₂) (∣-right (_·_ {[]} pr₁ pr₂)) refl | true | true with ⇒ pr₁ ... | () sound′ (p₁ · p₂) (∣-right (_·_ {_ ∷ _} pr₁ pr₂)) refl | true | true with sound {p = p₂} pr₂ ... | nonempty pr₂′ = sound′ p₁ pr₁ refl · pr₂′ complete : ∀ {n} {p : P n} → nonempty p ≤ nonempty′ p complete (nonempty pr) = complete′ _ pr refl where complete′ : ∀ {n t s s′} (p : P n) → s ∈ p → s ≡ t ∷ s′ → t ∷ s′ ∈ nonempty′ p complete′ fail () refl complete′ empty () refl complete′ (sat f) (sat ok) refl = sat ok complete′ (p₁ ∣ p₂) (∣-left pr) refl = ∣-left (complete′ p₁ pr refl) complete′ (p₁ ∣ p₂) (∣-right pr) refl = ∣-right {n₁ = false} (complete′ p₂ pr refl) complete′ (nonempty p) (nonempty pr) refl = complete′ p pr refl complete′ (cast _ p) (cast pr) refl = complete′ p pr refl complete′ (p₁ · p₂) pr _ with forced? p₁ | forced? p₂ complete′ (p₁ · p₂) pr refl | false | _ = pr complete′ (p₁ · p₂) pr refl | true | false = pr complete′ (p₁ · p₂) (_·_ {[]} pr₁ pr₂) refl | true | true = ∣-left (∣-right {n₁ = false} (complete′ p₂ pr₂ refl)) complete′ (p₁ · p₂) (_·_ {_ ∷ _} {[]} pr₁ pr₂) refl | true | true = cast∈ (sym $ proj₂ ListMonoid.identity _) refl $ ∣-left (∣-left {n₂ = false} (complete′ p₁ pr₁ refl)) complete′ (p₁ · p₂) (_·_ {_ ∷ _} {_ ∷ _} pr₁ pr₂) refl | true | true = ∣-right {n₁ = false} (complete′ p₁ pr₁ refl · complete′ p₂ pr₂ refl) correct : ∀ {n} {p : P n} → nonempty′ p ≈ nonempty p correct = equivalence sound complete
{ "alphanum_fraction": 0.4728822882, "avg_line_length": 41.4123006834, "ext": "agda", "hexsha": "9e54962440762ae3df52cb8ff8e7ada4b332c403", "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": "76774f54f466cfe943debf2da731074fe0c33644", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/parser-combinators", "max_forks_repo_path": "TotalRecognisers/LeftRecursion.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "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/parser-combinators", "max_issues_repo_path": "TotalRecognisers/LeftRecursion.agda", "max_line_length": 134, "max_stars_count": 1, "max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/parser-combinators", "max_stars_repo_path": "TotalRecognisers/LeftRecursion.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z", "num_tokens": 6790, "size": 18180 }
open import Formalization.PredicateLogic.Signature module Formalization.PredicateLogic.Syntax (𝔏 : Signature) where open Signature(𝔏) open import Data.ListSized import Lvl open import Functional using (_∘_ ; _∘₂_ ; swap) open import Numeral.Finite open import Numeral.Natural open import Sets.PredicateSet using (PredSet) open import Type private variable ℓ : Lvl.Level private variable args vars : ℕ data Term (vars : ℕ) : Type{ℓₒ} where var : 𝕟(vars) → Term(vars) -- Variables func : Obj(args) → List(Term(vars))(args) → Term(vars) -- Constants/functions -- Formulas. -- Inductive definition of the grammatical elements of the language of predicate logic. data Formula : ℕ → Type{ℓₚ Lvl.⊔ ℓₒ} where _$_ : Prop(args) → List(Term(vars))(args) → Formula(vars) -- Relations ⊤ : Formula(vars) -- Tautology (Top / True) ⊥ : Formula(vars) -- Contradiction (Bottom / False) _∧_ : Formula(vars) → Formula(vars) → Formula(vars) -- Conjunction (And) _∨_ : Formula(vars) → Formula(vars) → Formula(vars) -- Disjunction (Or) _⟶_ : Formula(vars) → Formula(vars) → Formula(vars) -- Implication Ɐ : Formula(𝐒(vars)) → Formula(vars) ∃ : Formula(𝐒(vars)) → Formula(vars) -- A sentence is a formula with no variables occurring. Sentence = Formula(𝟎) infix 1011 _$_ infixr 1005 _∧_ infixr 1004 _∨_ infixr 1000 _⟶_ -- Negation ¬_ : Formula(vars) → Formula(vars) ¬_ = _⟶ ⊥ -- Double negation ¬¬_ : Formula(vars) → Formula(vars) ¬¬_ = (¬_) ∘ (¬_) -- Reverse implication _⟵_ : Formula(vars) → Formula(vars) → Formula(vars) _⟵_ = swap(_⟶_) -- Equivalence _⟷_ : Formula(vars) → Formula(vars) → Formula(vars) p ⟷ q = (p ⟵ q) ∧ (p ⟶ q) -- (Nor) _⊽_ : Formula(vars) → Formula(vars) → Formula(vars) _⊽_ = (¬_) ∘₂ (_∨_) -- (Nand) _⊼_ : Formula(vars) → Formula(vars) → Formula(vars) _⊼_ = (¬_) ∘₂ (_∧_) -- (Exclusive or / Xor) _⊻_ : Formula(vars) → Formula(vars) → Formula(vars) _⊻_ = (¬_) ∘₂ (_⟷_) infix 1010 ¬_ ¬¬_ infixl 1000 _⟵_ _⟷_ Ɐ₊ : Formula(vars) → Sentence Ɐ₊{𝟎} φ = φ Ɐ₊{𝐒 v} φ = Ɐ₊{v} (Ɐ φ) ∃₊ : Formula(vars) → Sentence ∃₊{𝟎} φ = φ ∃₊{𝐒 v} φ = ∃₊{v} (∃ φ)
{ "alphanum_fraction": 0.6415719697, "avg_line_length": 25.756097561, "ext": "agda", "hexsha": "d5fddfa0ff57dd76d099b5498d4cd907e9d6214f", "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/Syntax.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/Syntax.agda", "max_line_length": 87, "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/Syntax.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": 781, "size": 2112 }
{- In order to solve the metavariables in this example we need to solve a constraint of the form _1 := unit₂ (_2 y) With the flex removal feature the occurs check will spot the bad variable 'y' in the instantiation and remove it by instantiating _2 := λ y → _3 for a fresh metavariable _3. The instantiation of _1 can then proceed. -} module FlexRemoval where record Unit : Set where data Unit₂ : Set where unit₂ : Unit → Unit₂ mutual data D : Set where c₁ : D c₂ : (x : Unit₂) → (Unit → D₂ x) → D D₂ : Unit₂ → Set D₂ (unit₂ x) = D foo : D foo = c₂ _ (λ y → c₁) {- 2011-04-05 Andreas This test case and the explanation is no longer up to date. What happens is _2 y : Unit is solved by eta-expansion _2 = λ y -> record {} and then _1 = unit₂ (record {}) is in solved form. -}
{ "alphanum_fraction": 0.6503579952, "avg_line_length": 15.5185185185, "ext": "agda", "hexsha": "dc120ff8cd1f8e1bccf9512bc63c8805e6465160", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/succeed/FlexRemoval.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/succeed/FlexRemoval.agda", "max_line_length": 61, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/succeed/FlexRemoval.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": 267, "size": 838 }
{-# OPTIONS --without-K #-} open import HoTT open import cohomology.Theory {- Cohomology groups of the n-torus (S¹)ⁿ. - We have Ĉᵏ(Tⁿ) == C⁰(S⁰)^(n choose' k) where _choose'_ defined as below. - This argument could give Cᵏ((Sᵐ)ⁿ) with a little more work. -} module cohomology.Torus {i} (OT : OrdinaryTheory i) where open OrdinaryTheory OT open import cohomology.Sn OT open import cohomology.SphereProduct cohomology-theory open import cohomology.Unit cohomology-theory {- Almost n choose k, but with n choose' O = 0 for any n. -} _choose'_ : ℕ → ℤ → ℕ n choose' (neg _) = 0 n choose' O = 0 n choose' pos O = n O choose' (pos (S k)) = 0 S n choose' pos (S k) = (n choose' (pos k)) + (n choose' (pos (S k))) _-⊙Torus : ℕ → Ptd i O -⊙Torus = ⊙Lift ⊙Unit (S n) -⊙Torus = (⊙Sphere {i} 1) ⊙× (n -⊙Torus) C-nTorus : (k : ℤ) (n : ℕ) → C k (n -⊙Torus) == (C O (⊙Sphere 0)) ^ᴳ (n choose' k) C-nTorus (neg k) O = C-Unit-is-trivial (neg k) C-nTorus (neg k) (S n) = C-Sphere× (neg k) 1 (n -⊙Torus) ∙ ap (λ K → K ×ᴳ (C (neg k) (⊙Susp^ 1 (n -⊙Torus)) ×ᴳ C (neg k) (n -⊙Torus))) (C-Sphere-≠ (neg k) 1 (ℤ-neg≠pos _ _)) ∙ ×ᴳ-unit-l {G = C (neg k) (⊙Susp (n -⊙Torus)) ×ᴳ C (neg k) (n -⊙Torus)} ∙ ap (λ K → C (neg k) (⊙Susp (n -⊙Torus)) ×ᴳ K) (C-nTorus (neg k) n) ∙ ×ᴳ-unit-r {G = C (neg k) (⊙Susp (n -⊙Torus))} ∙ C-Susp (neg (S k)) (n -⊙Torus) ∙ C-nTorus (neg (S k)) n C-nTorus O O = C-Unit-is-trivial O C-nTorus O (S n) = C-Sphere× O 1 (n -⊙Torus) ∙ ap (λ K → K ×ᴳ (C O (⊙Susp (n -⊙Torus)) ×ᴳ C O (n -⊙Torus))) (C-Sphere-≠ O 1 (ℤ-O≠pos _)) ∙ ×ᴳ-unit-l {G = C O (⊙Susp (n -⊙Torus)) ×ᴳ C O (n -⊙Torus)} ∙ ap (λ K → C O (⊙Susp (n -⊙Torus)) ×ᴳ K) (C-nTorus O n) ∙ ×ᴳ-unit-r {G = C O (⊙Susp (n -⊙Torus))} ∙ C-Susp (neg O) (n -⊙Torus) ∙ C-nTorus (neg O) n C-nTorus (pos O) O = C-Unit-is-trivial (pos O) C-nTorus (pos O) (S n) = C-Sphere× (pos O) 1 (n -⊙Torus) ∙ ap (λ K → K ×ᴳ (C (pos O) (⊙Susp (n -⊙Torus)) ×ᴳ C (pos O) (n -⊙Torus))) (C-Sphere-diag 1) ∙ ap (λ K → C O (⊙Sphere O) ×ᴳ K) (ap2 _×ᴳ_ (C-Susp O (n -⊙Torus) ∙ C-nTorus O n) (C-nTorus (pos O) n) ∙ ×ᴳ-unit-l {G = C O (⊙Sphere 0) ^ᴳ (n choose' pos O)}) C-nTorus (pos (S k)) O = C-Unit-is-trivial (pos (S k)) C-nTorus (pos (S k)) (S n) = C-Sphere× (pos (S k)) 1 (n -⊙Torus) ∙ ap (λ K → K ×ᴳ (C (pos (S k)) (⊙Susp (n -⊙Torus)) ×ᴳ C (pos (S k)) (n -⊙Torus))) (C-Sphere-≠ (pos (S k)) 1 (ℕ-S≠O k ∘ pos-injective (S k) 0)) ∙ ×ᴳ-unit-l {G = (C (pos (S k)) (⊙Susp (n -⊙Torus)) ×ᴳ (C (pos (S k)) (n -⊙Torus)))} ∙ ap2 _×ᴳ_ (C-Susp (pos k) (n -⊙Torus) ∙ C-nTorus (pos k) n) (C-nTorus (pos (S k)) n) ∙ ^ᴳ-sum (C O (⊙Sphere 0)) (n choose' pos k) (n choose' pos (S k))
{ "alphanum_fraction": 0.5028070175, "avg_line_length": 32.0224719101, "ext": "agda", "hexsha": "92ad38abee8a5cd1dc9a1c798017cd838cef2532", "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": "1695a7f3dc60177457855ae846bbd86fcd96983e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "danbornside/HoTT-Agda", "max_forks_repo_path": "cohomology/Torus.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "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": "danbornside/HoTT-Agda", "max_issues_repo_path": "cohomology/Torus.agda", "max_line_length": 76, "max_stars_count": null, "max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "danbornside/HoTT-Agda", "max_stars_repo_path": "cohomology/Torus.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1429, "size": 2850 }
module Numeral.Natural.Function.GreatestCommonDivisor where import Lvl open import Data open import Data.Tuple as Tuple using (_⨯_ ; _,_) open import Functional open import Logic.Propositional open import Numeral.CoordinateVector as Vector using (Vector) open import Numeral.Finite using (𝕟 ; 𝟎 ; 𝐒) open import Numeral.Natural open import Numeral.Natural.Oper open import Numeral.Natural.Oper.FlooredDivision open import Numeral.Natural.Oper.Modulo open import Numeral.Natural.Oper.Proofs open import Numeral.Natural.Relation.Divisibility open import Numeral.Natural.Relation.Order open import Numeral.Natural.Relation.Order.Classical open import Type -- TODO: Prove that gcd is the infimum in a lattice of ℕ with divisibility as its ordering {-# TERMINATING #-} gcdFold : ∀{ℓ}{T : Type{ℓ}} → ((a : ℕ) → (b : ℕ) → (a ≥ b) → (b > 𝟎) → T → T → T) → ((a : ℕ) → (b : ℕ) → (a < b) → (b > 𝟎) → T → T → T) → T → ℕ → ℕ → (ℕ ⨯ T) gcdFold f g x (a)(𝟎) = (a , x) gcdFold f g x (a)(𝐒(b)) with [≥]-or-[<] {a}{𝐒(b)} ... | [∨]-introₗ ab = Tuple.mapRight (f a (𝐒(b)) ab (succ min) x) (gcdFold f g x (𝐒(b))(a mod 𝐒(b))) ... | [∨]-introᵣ ba = Tuple.mapRight (g a (𝐒(b)) ba (succ min) x) (gcdFold f g x (𝐒(b))(a)) -- An algorithm for computing the greatest common divisor for two numbers. -- Also called: Euclid's algorithm. -- Termination: See `Gcd-existence` for a functionally equal variant of this function that passes the termination checker. It is equal in the sense that the same algorithm is used to construct the existence and to compute the value of this function. This is even more evident when looking at `Gcd-gcd`. -- Alternative implementation: -- gcd(a)(𝟎) = a -- gcd(a)(𝐒(b)) with [≥]-or-[<] {a}{𝐒(b)} -- ... | [∨]-introₗ _ = gcd(𝐒(b))(a mod 𝐒(b)) -- ... | [∨]-introᵣ _ = gcd(𝐒(b))(a) gcd : ℕ → ℕ → ℕ gcd a b = Tuple.left(gcdFold(\_ _ _ _ _ _ → <>) (\_ _ _ _ _ _ → <>) (<>{Lvl.𝟎}) a b) lcm : ℕ → ℕ → ℕ lcm(a)(b) = (a ⋅ b) ⌊/⌋₀ gcd(a)(b) -- `Gcd a b D` is the specialization for 2 elements and states that `D` is a divisor of both `a` and `b`, and the greatest one of them. -- Example: -- Divisor(24) = {1,2,3,4, 6,8, 12, 24} -- Divisor(60) = {1,2,3,4,5,6 ,10,12,15,20, 30,60} -- 24 = 2³ ⋅ 3¹ -- 60 = 2² ⋅ 3¹ ⋅ 5¹ -- Gcd 24 60 = {max(Divisor(24) ∩ Divisor(60))} = 2² ⋅ 3¹ = 12 -- Divisor of first : 24 / 12 = 2 -- Divisor of second: 60 / 12 = 5 record GreatestCommonDivisor(n : ℕ) (v : Vector(n)(ℕ)) (D : ℕ) : Type{Lvl.𝟎} where constructor intro field divisor : ∀(i) → (D ∣ v(i)) maximum : ∀{d} → (∀(i) → (d ∣ v(i))) → (d ∣ D) Gcd = GreatestCommonDivisor(2) ∘₂ Vector.pair module Gcd {a b D} where intro₂ : _ → _ → (∀{d} → _ → _ → (d ∣ D)) → Gcd a b D intro₂ divisorₗ divisorᵣ maximum = intro{2}{Vector.pair a b} (\{𝟎 → divisorₗ ; (𝐒(𝟎)) → divisorᵣ}) (\dv → maximum (dv 𝟎) (dv (𝐒 𝟎))) module _ (inst : Gcd a b D) where open GreatestCommonDivisor(inst) public divisorₗ = divisor 𝟎 divisorᵣ = divisor(𝐒 𝟎) maximum₂ = \{d} a b → maximum{d} \{𝟎 → a ; (𝐒(𝟎)) → b} -- `Lcm a b M` is the specialization for 2 elements and states that `M` is a multiple of both `a` and `b`, and the smallest one of them. -- Example: -- 360 = 2³ ⋅ 3² ⋅ 5¹ -- 8400 = 2⁴ ⋅ 3¹ ⋅ 5² ⋅ 7¹ -- Lcm 360 8400 = {min(Multiple(360) ∩ Multiple(8400))} = 2⁴ ⋅ 3² ⋅ 5² ⋅ 7¹ = 25200 -- Multiple of first : 360 ⋅ 2¹ ⋅ 5¹ ⋅ 7¹ = 360 ⋅ 70 = 25200 -- Multiple of second: 8400 ⋅ 3¹ = 25200 record LeastCommonMultiple(n : ℕ) (v : Vector(n)(ℕ)) (M : ℕ) : Type{Lvl.𝟎} where constructor intro field multiple : ∀(i) → (v(i) ∣ M) minimum : ∀{m} → (∀(i) → (v(i) ∣ m)) → (M ∣ m) Lcm = LeastCommonMultiple(2) ∘₂ Vector.pair module Lcm {a b M} where intro₂ : _ → _ → (∀{m} → _ → _ → (M ∣ m)) → Lcm a b M intro₂ multipleₗ multipleᵣ minimum = intro{2}{Vector.pair a b} (\{𝟎 → multipleₗ ; (𝐒(𝟎)) → multipleᵣ}) (\dv → minimum (dv 𝟎) (dv (𝐒 𝟎))) module _ (inst : Lcm a b M) where open LeastCommonMultiple(inst) public multipleₗ = multiple 𝟎 multipleᵣ = multiple(𝐒 𝟎) minimum₂ = \{m} a b → minimum{m} \{𝟎 → a ; (𝐒(𝟎)) → b} open import Logic.Predicate open import Numeral.Natural.Inductions open import Numeral.Natural.Oper.Modulo.Proofs open import Numeral.Natural.Relation.Divisibility.Proofs open import Numeral.Natural.Relation.Divisibility.Proofs.Modulo open import Numeral.Natural.Relation.Order.Proofs open import Relator.Equals open import Relator.Equals.Proofs open import Sets.PredicateSet using (_∈_ ; _⊆_) open import Structure.Relator.Properties open import Structure.Setoid.Uniqueness open import Syntax.Function private variable a b d : ℕ Gcd-unique : Unique(Gcd a b) Gcd-unique p q = antisymmetry(_∣_)(_≡_) (Gcd.maximum₂ q (Gcd.divisorₗ p) (Gcd.divisorᵣ p)) (Gcd.maximum₂ p (Gcd.divisorₗ q) (Gcd.divisorᵣ q)) Gcd-base : (a ∈ Gcd(a)(𝟎)) Gcd-base = Gcd.intro₂ divides-reflexivity Div𝟎 const Gcd-step : (a ≥ 𝐒(b)) → Gcd(a mod 𝐒(b))(𝐒(b)) ⊆ Gcd(a)(𝐒(b)) Gcd-step ab p = Gcd.intro₂ ([↔]-to-[←] (divides-mod (Gcd.divisorᵣ p)) (Gcd.divisorₗ p)) (Gcd.divisorᵣ p) (\da db → Gcd.maximum₂ p ([↔]-to-[→] (divides-mod db) da) db) Gcd-swap : Gcd(a)(b) ⊆ Gcd(b)(a) Gcd-swap p = Gcd.intro₂ (Gcd.divisorᵣ p) (Gcd.divisorₗ p) (swap(Gcd.maximum₂ p)) -- Note: The construction for the existence is following the same steps as in the definition of the function `gcd`, but unlike `gcd` which does not pass the termination checker, this uses [ℕ]-strong-induction to pass it. Gcd-existence : ∃(Gcd a b) Gcd-existence{a}{b} = [ℕ]-strong-induction {φ = b ↦ ∀{a} → ∃(Gcd a b)} base step {b}{a} where base : ∀{a} → ∃(Gcd a 𝟎) base{a} = [∃]-intro a ⦃ Gcd-base ⦄ step : ∀{i} → (∀{j} → (j ≤ i) → ∀{a} → ∃(Gcd a j)) → ∀{a} → ∃(Gcd a (𝐒(i))) step {i} prev {a} with [≥]-or-[<] {a}{𝐒(i)} ... | [∨]-introₗ ia = [∃]-map-proof (Gcd-step ia ∘ Gcd-swap) (prev{a mod 𝐒(i)} ([≤]-without-[𝐒] (mod-maxᵣ{a}{𝐒(i)})) {𝐒(i)}) ... | [∨]-introᵣ (succ ai) = [∃]-map-proof Gcd-swap(prev {a} ai {𝐒(i)}) Gcd-gcdFold : ∀{a b}{ℓ}{T : Type{ℓ}}{f}{g}{x : T} → Gcd a b (Tuple.left(gcdFold f g x a b)) Gcd-gcdFold{a}{b}{f = f}{g}{x} = [ℕ]-strong-induction {φ = b ↦ ∀{a} → Gcd a b (Tuple.left(gcdFold f g x a b))} base step {b}{a} where base : ∀{a} → Gcd a 𝟎 (Tuple.left(gcdFold f g x a 𝟎)) base{a} = Gcd-base step : ∀{i} → (∀{j} → (j ≤ i) → ∀{a} → Gcd a j (Tuple.left(gcdFold f g x a j))) → ∀{a} → Gcd a (𝐒(i)) (Tuple.left(gcdFold f g x a (𝐒(i)))) step {i} prev {a} with [≥]-or-[<] {a}{𝐒(i)} ... | [∨]-introₗ ia = (Gcd-step ia ∘ Gcd-swap) (prev{a mod 𝐒(i)} ([≤]-without-[𝐒] (mod-maxᵣ{a}{𝐒(i)})) {𝐒(i)}) ... | [∨]-introᵣ (succ ai) = Gcd-swap(prev {a} ai {𝐒(i)}) -- Usage: This allows the transferrence of proofs between `Gcd` and `gcd`. It is sometimes easier to prove properties by using `Gcd` first and then transfering them so that the proofs also hold for `gcd`. Gcd-gcdFold-value : ∀{a b D}{ℓ}{T : Type{ℓ}}{f}{g}{x : T} → (Gcd a b D) ↔ (Tuple.left(gcdFold f g x a b) ≡ D) Gcd-gcdFold-value = [↔]-intro (\{[≡]-intro → Gcd-gcdFold}) (Gcd-unique Gcd-gcdFold) Gcd-gcd : Gcd a b (gcd a b) Gcd-gcd = Gcd-gcdFold Gcd-gcd-value : (Gcd a b d) ↔ (gcd a b ≡ d) Gcd-gcd-value = Gcd-gcdFold-value
{ "alphanum_fraction": 0.6124041812, "avg_line_length": 44.018404908, "ext": "agda", "hexsha": "abaefa9cf070edfb04f954214c6fd96224a0ef93", "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": "Numeral/Natural/Function/GreatestCommonDivisor.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": "Numeral/Natural/Function/GreatestCommonDivisor.agda", "max_line_length": 302, "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": "Numeral/Natural/Function/GreatestCommonDivisor.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": 3032, "size": 7175 }
{-# OPTIONS --without-K --exact-split --safe #-} open import Fragment.Algebra.Signature module Fragment.Algebra.Quotient (Σ : Signature) where open import Fragment.Algebra.Algebra Σ open import Fragment.Algebra.Homomorphism Σ open import Fragment.Setoid.Morphism using (_↝_) open import Level using (Level; Setω; _⊔_; suc) open import Data.Vec.Properties using (map-id) open import Relation.Binary using (Setoid; IsEquivalence; Rel) import Relation.Binary.PropositionalEquality as PE private variable a b ℓ₁ ℓ₂ ℓ₃ ℓ₄ : Level module _ (A : Algebra {a} {ℓ₁}) (_≈_ : Rel ∥ A ∥ ℓ₂) where private setoid' : IsEquivalence _≈_ → Setoid _ _ setoid' isEquivalence = record { Carrier = ∥ A ∥ ; _≈_ = _≈_ ; isEquivalence = isEquivalence } record IsDenominator : Set (a ⊔ suc ℓ₁ ⊔ suc ℓ₂) where field isEquivalence : IsEquivalence _≈_ isCoarser : ∀ {x y} → x =[ A ] y → x ≈ y isCompatible : Congruence (setoid' isEquivalence) (A ⟦_⟧_) module _ (A : Algebra {a} {ℓ₁}) (_≈_ : Rel ∥ A ∥ ℓ₄) {{isDenom : IsDenominator A _≈_}} where record IsQuotient (A/≈ : Algebra {b} {ℓ₂}) : Setω where field inc : A ⟿ A/≈ factor : ∀ {c ℓ₃} {X : Algebra {c} {ℓ₃}} → (f : A ⟿ X) → (Congruent _≈_ ≈[ X ] ∣ f ∣) → A/≈ ⟿ X commute : ∀ {c ℓ₃} {X : Algebra {c} {ℓ₃}} → (f : A ⟿ X) → (cong : Congruent _≈_ ≈[ X ] ∣ f ∣) → factor f cong ⊙ inc ≗ f universal : ∀ {c ℓ₃} {X : Algebra {c} {ℓ₃}} → (f : A ⟿ X) → (cong : Congruent _≈_ ≈[ X ] ∣ f ∣) → {h : A/≈ ⟿ X} → h ⊙ inc ≗ f → factor f cong ≗ h open IsDenominator isDenom ∥_∥/_ : Setoid _ _ ∥_∥/_ = record { Carrier = ∥ A ∥ ; _≈_ = _≈_ ; isEquivalence = isEquivalence } _/_-isAlgebra : IsAlgebra ∥_∥/_ _/_-isAlgebra = record { ⟦_⟧ = A ⟦_⟧_ ; ⟦⟧-cong = isCompatible } _/_ : Algebra _/_ = record { ∥_∥/≈ = ∥_∥/_ ; ∥_∥/≈-isAlgebra = _/_-isAlgebra } private ∣inc∣⃗ : ∥ A ∥/≈ ↝ ∥_∥/_ ∣inc∣⃗ = record { ∣_∣ = λ x → x ; ∣_∣-cong = isCoarser } ∣inc∣-hom : Homomorphic A _/_ (λ x → x) ∣inc∣-hom f xs = Setoid.reflexive ∥_∥/_ (PE.cong (A ⟦ f ⟧_) (map-id xs)) inc : A ⟿ _/_ inc = record { ∣_∣⃗ = ∣inc∣⃗ ; ∣_∣-hom = ∣inc∣-hom } module _ {c ℓ₃} {X : Algebra {c} {ℓ₃}} (f : A ⟿ X) (cong : Congruent _≈_ ≈[ X ] ∣ f ∣) where private ∣factor∣⃗ : ∥_∥/_ ↝ ∥ X ∥/≈ ∣factor∣⃗ = record { ∣_∣ = ∣ f ∣ ; ∣_∣-cong = cong } factor : _/_ ⟿ X factor = record { ∣_∣⃗ = ∣factor∣⃗ ; ∣_∣-hom = ∣ f ∣-hom } factor-commute : factor ⊙ inc ≗ f factor-commute = Setoid.refl ∥ X ∥/≈ factor-universal : ∀ {h : _/_ ⟿ X} → h ⊙ inc ≗ f → factor ≗ h factor-universal p {x} = sym (p {x}) where open Setoid ∥ X ∥/≈ _/_-isQuotient : IsQuotient (_/_) _/_-isQuotient = record { inc = inc ; factor = factor ; commute = factor-commute ; universal = factor-universal }
{ "alphanum_fraction": 0.4474203552, "avg_line_length": 27.0763358779, "ext": "agda", "hexsha": "e6194a27626a3b946b3a937b7f0624dbe9787198", "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/Algebra/Quotient.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/Algebra/Quotient.agda", "max_line_length": 65, "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/Algebra/Quotient.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": 1334, "size": 3547 }
-- Non-index (plain) monads in form of Kleisli triple. module Control.Monad where open import Function using () renaming (_∘′_ to _∘_) open import Relation.Binary.PropositionalEquality open ≡-Reasoning open import Axiom.FunctionExtensionality open import Control.Functor -- The operations of a monad. module T-MonadOps (M : Set → Set) where T-return = ∀ {A} (a : A) → M A T-bind = ∀ {A B} (m : M A) (k : A → M B) → M B record MonadOps (M : Set → Set) : Set₁ where open T-MonadOps M infixr 6 _>>=_ field return : T-return _>>=_ : T-bind bind = _>>=_ functorOps : FunctorOps M functorOps = record { map = λ f m → m >>= λ a → return (f a) } open FunctorOps functorOps public -- The laws of a monad (Kleisli triple variant). module T-MonadLaws {M : Set → Set} (ops : MonadOps M) where open MonadOps ops public T-bind-β = ∀ {A B} (k : A → M B) (a : A) → return a >>= k ≡ k a T-bind-η = ∀ {A} (m : M A) → m >>= return ≡ m T-bind-assoc = ∀ {A B C} (m : M A) {k : A → M B} {l : B → M C} → (m >>= k) >>= l ≡ m >>= λ a → (k a >>= l) -- Provable laws. -- A variant of bind-β using function extensionality. T-bind-β-ext = ∀ {A B C : Set} (f : A → B) (k : B → M C) → (λ a → return (f a) >>= k) ≡ k ∘ f T-map-after-bind = ∀ {A B C} (m : M A) {k : A → M B} {f : B → C} → f <$> (m >>= k) ≡ m >>= λ a → f <$> k a T-bind-after-map = ∀ {A B C} (m : M A) {k : B → M C} {f : A → B} → (f <$> m) >>= k ≡ m >>= λ a → k (f a) record MonadLaws {M : Set → Set} (ops : MonadOps M) : Set₁ where open T-MonadLaws ops -- Axioms. field bind-β : T-bind-β bind-η : T-bind-η bind-assoc : T-bind-assoc -- Derived laws. bind-β-ext : T-bind-β-ext bind-β-ext f k = fun-ext (λ a → bind-β k (f a)) map-after-bind : T-map-after-bind map-after-bind m = bind-assoc m -- A more detailed proof. (NF: trans (bind-assoc m) refl) private map-after-bind′ : T-map-after-bind map-after-bind′ m {k = k} {f = f} = begin f <$> (m >>= k) ≡⟨⟩ -- definition of map ((m >>= k) >>= λ b → return (f b)) ≡⟨ bind-assoc m ⟩ -- associativity of bind m >>= (λ a → k a >>= λ b → return (f b)) ≡⟨⟩ -- definition of map m >>= (λ a → f <$> k a) ∎ bind-after-map : T-bind-after-map bind-after-map m {k = k} {f = f} = begin (f <$> m) >>= k ≡⟨⟩ -- definition of map (m >>= λ a → return (f a)) >>= k ≡⟨ bind-assoc m ⟩ -- associativity of bind m >>= (λ a → return (f a) >>= k) ≡⟨ cong (_>>=_ m) (bind-β-ext _ _) ⟩ -- beta for bind m >>= (λ a → k (f a)) ∎ -- Functor laws. open T-FunctorLaws functorOps using (T-map-∘) private abstract map-comp : T-map-∘ map-comp {f = f} {g = g} = fun-ext λ m → begin g ∘ f <$> m ≡⟨⟩ (m >>= λ a → return (g (f a))) ≡⟨ cong (_>>=_ m) (sym (bind-β-ext _ _)) ⟩ (m >>= λ a → return (f a) >>= λ b → return (g b)) ≡⟨ sym (bind-assoc m) ⟩ (m >>= λ a → return (f a)) >>= (λ b → return (g b)) ≡⟨⟩ g <$> f <$> m ∎ functorLaws : FunctorLaws functorOps functorLaws = record { map-id = fun-ext bind-η ; map-∘ = map-comp } open FunctorLaws functorLaws public record IsMonad (M : Set → Set) : Set₁ where field ops : MonadOps M laws : MonadLaws ops open MonadOps ops public open MonadLaws laws public {- -- The operations of a monad. record MonadOps (M : Set → Set) : Set₁ where infixr 6 _>>=_ T-return = ∀ {A} (a : A) → M A T-bind = ∀ {A B} (m : M A) (k : A → M B) → M B field return : T-return _>>=_ : T-bind bind = _>>=_ functorOps : FunctorOps M functorOps = record { _<$>_ = λ f m → m >>= λ a → return (f a) } open FunctorOps functorOps public -- The laws of a monad (Kleisli triple variant). record MonadLaws {M : Set → Set} (ops : MonadOps M) : Set₁ where open MonadOps ops T-bind-β = ∀ {A B} (a : A) (k : A → M B) → return a >>= k ≡ k a T-bind-η = ∀ {A} (m : M A) → m >>= return ≡ m T-bind-assoc = ∀ {A B C} (m : M A) {k : A → M B} {l : B → M C} → (m >>= k) >>= l ≡ m >>= λ a → (k a >>= l) field bind-β : T-bind-β bind-η : T-bind-η bind-assoc : T-bind-assoc private abstract map-comp : FunctorLaws.T-map-∘ {!!} map-comp = {!!} functorLaws : FunctorLaws functorOps functorLaws = record { map-id = bind-η ; map-∘ = {!!} } record IsMonad (M : Set → Set) : Set₁ where record IsMonad (M : Set → Set) : Set₁ where infixr 6 _>>=_ field return : ∀ {A} (a : A) → M A _>>=_ : ∀ {A B} (m : M A) (k : A → M B) → M B -- Laws bind-β : ∀ {A B} (a : A) (k : A → M B) → return a >>= k ≡ k a bind-η : ∀ {A} (m : M A) → m >>= return ≡ m bind-assoc : ∀ {A B C} (m : M A) {k : A → M B} {l : B → M C} → (m >>= k) >>= l ≡ m >>= λ a → (k a >>= l) bind = _>>=_ private map : Map-T F map = λ f m → m >>= λ a → return (f a) abstract map-comp : Map-Comp-T map functor : IsFunctor M functor = record { _<$>_ = λ f m → m >>= λ a → return (f a) ; map-id = bind-η ; map-∘ = map-comp where x = {!bind-assoc!} } -}
{ "alphanum_fraction": 0.4611546686, "avg_line_length": 22.2698412698, "ext": "agda", "hexsha": "e3a74c1958c213a71a639b260c8acea6d2720880", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andreasabel/cubical", "max_forks_repo_path": "src/Control/Monad.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andreasabel/cubical", "max_issues_repo_path": "src/Control/Monad.agda", "max_line_length": 105, "max_stars_count": null, "max_stars_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "andreasabel/cubical", "max_stars_repo_path": "src/Control/Monad.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2051, "size": 5612 }
module Issue278 where abstract module A where Foo : Set₁ Foo = Set module B where open A Foo≡Set : Foo ≡ Set Foo≡Set = refl
{ "alphanum_fraction": 0.6066666667, "avg_line_length": 12.5, "ext": "agda", "hexsha": "0b9732b5c3c78cdf5b13bb5ff4b9bebd7a989e4d", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/fail/Issue278.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/fail/Issue278.agda", "max_line_length": 23, "max_stars_count": 3, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/Fail/Issue278.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": 52, "size": 150 }
{-# OPTIONS --cubical --safe #-} module Data.Nat.Show where open import Prelude open import Data.Nat open import Data.Nat.DivMod open import Data.String open import Data.List showDig : ℕ → Char showDig 0 = '0' showDig 1 = '1' showDig 2 = '2' showDig 3 = '3' showDig 4 = '4' showDig 5 = '5' showDig 6 = '6' showDig 7 = '7' showDig 8 = '8' showDig 9 = '9' showDig _ = '!' showsℕ : ℕ → List Char → List Char showsℕ n xs = go xs n n where go : List Char → ℕ → ℕ → List Char go a zero _ = a go a n@(suc _) (suc t) = go (showDig (rem n 10) ∷ a) (n ÷ 10) t go a (suc _) zero = a showℕ : ℕ → String showℕ n = pack (showsℕ n [])
{ "alphanum_fraction": 0.599078341, "avg_line_length": 19.1470588235, "ext": "agda", "hexsha": "2ca780f21b04b613f64d33c50f96626522c8140f", "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/Nat/Show.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/Nat/Show.agda", "max_line_length": 65, "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/Nat/Show.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": 256, "size": 651 }
module Data.List.Prefix where open import Level open import Data.Nat open import Data.List open import Data.List.At open import Data.List.Membership.Propositional open import Data.List.Relation.Unary.Any hiding (map) open import Data.List.Relation.Binary.Pointwise as P hiding (refl; map) open import Relation.Binary open import Relation.Binary.PropositionalEquality as ≡ -- prefix predicate for lists infix 4 _⊑_ data _⊑_ {a} {A : Set a} : List A → List A → Set a where [] : ∀ {ys} → [] ⊑ ys _∷_ : ∀ x {xs ys} → xs ⊑ ys → x ∷ xs ⊑ x ∷ ys ⊑-refl : ∀ {a} {A : Set a} → Reflexive (_⊑_ {A = A}) ⊑-refl {x = []} = [] ⊑-refl {x = x ∷ xs} = x ∷ ⊑-refl ⊑-trans : ∀ {a} {A : Set a} → Transitive (_⊑_ {A = A}) ⊑-trans [] _ = [] ⊑-trans (x ∷ p) (.x ∷ q) = x ∷ ⊑-trans p q open import Relation.Binary.PropositionalEquality ⊑-unique : ∀ {a}{A : Set a}{k l : List A}(xs ys : k ⊑ l) → xs ≡ ys ⊑-unique [] [] = refl ⊑-unique (x ∷ xs) (.x ∷ ys) = cong (λ u → x ∷ u) (⊑-unique xs ys) ⊑-trans-refl : ∀ {a}{A : Set a}{k l}{xs : k ⊑ l} → ⊑-trans {A = A} ⊑-refl xs ≡ xs ⊑-trans-refl {xs = []} = refl ⊑-trans-refl {xs = x ∷ xs} = cong (λ u → x ∷ u) ⊑-trans-refl ⊑-trans-refl' : ∀ {a}{A : Set a}{k l}{xs : k ⊑ l} → ⊑-trans {A = A} xs ⊑-refl ≡ xs ⊑-trans-refl' {xs = []} = refl ⊑-trans-refl' {xs = x ∷ xs} = cong (λ u → x ∷ u) ⊑-trans-refl' ⊑-trans-assoc : ∀ {a}{A : Set a}{k l m n : List A}{p : k ⊑ l}{q : l ⊑ m}{r : m ⊑ n} → ⊑-trans p (⊑-trans q r) ≡ ⊑-trans (⊑-trans p q) r ⊑-trans-assoc {p = []} {q} = refl ⊑-trans-assoc {p = x ∷ p} {.x ∷ q} {.x ∷ r} = cong (λ u → x ∷ u) ⊑-trans-assoc remainder : ∀ {a}{A : Set a}{xs ys : List A} → xs ⊑ ys → List A remainder ([] {ys}) = ys remainder (x ∷ xs) = remainder xs -- list extensions; reverse prefix relation infix 4 _⊒_ _⊒_ : ∀ {a} {A : Set a} → List A → List A → Set a xs ⊒ ys = ys ⊑ xs -- appending to a list gives a list extension; -- or, appending to a list makes the original a prefix ∷ʳ-⊒ : ∀ {a} {A : Set a} (x : A) xs → xs ∷ʳ x ⊒ xs ∷ʳ-⊒ x [] = [] ∷ʳ-⊒ x (x₁ ∷ Σ₁) = x₁ ∷ (∷ʳ-⊒ x Σ₁) -- indexes into a prefix point to the same element in extensions xs⊒ys[i] : ∀ {a} {A : Set a} {xs : List A} {ys : List A} {i y} → xs [ i ]= y → (p : ys ⊒ xs) → ys [ i ]= y xs⊒ys[i] () [] xs⊒ys[i] {i = zero} p (x ∷ a) = p xs⊒ys[i] {i = suc i} p (x ∷ a) = xs⊒ys[i] p a -- prefix is preserved by map ⊑-map : ∀ {a b} {A : Set a} {B : Set b} {xs ys : List A} {f : A → B} → xs ⊑ ys → map f xs ⊑ map f ys ⊑-map [] = [] ⊑-map {f = f} (x ∷ p) = f x ∷ (⊑-map p) -- all elemens in a list, also exist in it's extensions ∈-⊒ : ∀ {a}{A : Set a}{xs : List A}{x} → x ∈ xs → ∀ {ys} → ys ⊒ xs → x ∈ ys ∈-⊒ () [] ∈-⊒ (here px) (x ∷ q) = here px ∈-⊒ (there p) (x ∷ q) = there (∈-⊒ p q) ∈-⊒-refl : ∀ {a}{A : Set a}{xs : List A}{x}{p : x ∈ xs} → ∈-⊒ p ⊑-refl ≡ p ∈-⊒-refl {p = here px} = refl ∈-⊒-refl {p = there p} = cong there ∈-⊒-refl ∈-⊒-trans : ∀ {a}{A : Set a}{xs ys zs : List A}{x}{p : x ∈ xs}(q : ys ⊒ xs)(r : zs ⊒ ys) → ∈-⊒ p (⊑-trans q r) ≡ ∈-⊒ (∈-⊒ p q) r ∈-⊒-trans {p = here px} (x ∷ l) (.x ∷ r) = refl ∈-⊒-trans {p = there p} (x ∷ l) (.x ∷ r) = cong there (∈-⊒-trans l r) open import Relation.Binary open import Relation.Binary.Core open import Relation.Nullary module Decidable {a}{A : Set a}(_≟_ : Decidable (_≡_ {A = A})) where _⊑?_ : Decidable (_⊑_ {A = A}) [] ⊑? _ = yes [] (x ∷ xs) ⊑? [] = no (λ ()) (x ∷ xs) ⊑? (y ∷ ys) with x ≟ y (x ∷ xs) ⊑? (y ∷ ys) | no ¬p = no (λ{ (.x ∷ z) → ¬p refl }) (x ∷ xs) ⊑? (.x ∷ ys) | yes refl with xs ⊑? ys ... | yes px = yes (x ∷ px) ... | no ¬px = no (λ{ (.x ∷ px) → ¬px px}) _⊒?_ : Decidable (_⊒_ {A = A}) xs ⊒? ys = ys ⊑? xs import Relation.Binary.PropositionalEquality.Core as PC ⊑-preorder : ∀ {ℓ}{A : Set ℓ} → Preorder ℓ ℓ ℓ ⊑-preorder {A = A} = record { Carrier = List A ; _≈_ = _≡_ ; _∼_ = _⊑_ ; isPreorder = record { isEquivalence = ≡.isEquivalence ; reflexive = λ{ refl → ⊑-refl } ; trans = ⊑-trans } } ⊒-preorder : ∀ {ℓ}{A : Set ℓ} → Preorder _ _ _ ⊒-preorder {A = A} = record { Carrier = List A ; _≈_ = _≡_ ; _∼_ = _⊒_ ; isPreorder = record { isEquivalence = ≡.isEquivalence ; reflexive = λ{ refl → ⊑-refl } ; trans = λ p q → ⊑-trans q p } }
{ "alphanum_fraction": 0.5110530069, "avg_line_length": 35.0583333333, "ext": "agda", "hexsha": "ed08a855778f79f18f575d35099214a9f473226c", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z", "max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "metaborg/mj.agda", "max_forks_repo_path": "src/Data/List/Prefix.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z", "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "metaborg/mj.agda", "max_issues_repo_path": "src/Data/List/Prefix.agda", "max_line_length": 128, "max_stars_count": 10, "max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "metaborg/mj.agda", "max_stars_repo_path": "src/Data/List/Prefix.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z", "max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z", "num_tokens": 2000, "size": 4207 }
{-# OPTIONS --without-K #-} open import Types open import Functions open import Paths open import HLevel open import Equivalences open import Univalence open import Funext module HLevelBis where abstract -- Every map between contractible types is an equivalence contr-to-contr-is-equiv : ∀ {i j} {A : Set i} {B : Set j} (f : A → B) → (is-contr A → is-contr B → is-equiv f) contr-to-contr-is-equiv f cA cB y = ((π₁ cA , (contr-has-all-paths cB _ _)) , (λ _ → Σ-eq (contr-has-all-paths cA _ _) (contr-has-all-paths (≡-is-truncated _ cB) _ _))) is-contr-is-prop : ∀ {i} {A : Set i} → is-prop (is-contr A) is-contr-is-prop {A = A} = all-paths-is-prop (λ x y → Σ-eq (π₂ y (π₁ x)) (funext (lemma x y (π₂ y (π₁ x))))) where lemma : (x y : is-contr A) (p : π₁ x ≡ π₁ y) (t : A) → transport (λ v → (z : A) → z ≡ v) p (π₂ x) t ≡ π₂ y t lemma (x , p) (.x , q) refl t = contr-has-all-paths (≡-is-truncated _ (x , p)) _ _ -- Equivalent types have the same truncation level equiv-types-truncated : ∀ {i j} {A : Set i} {B : Set j} (n : ℕ₋₂) (f : A ≃ B) → (is-truncated n A → is-truncated n B) equiv-types-truncated ⟨-2⟩ (f , e) (x , p) = (f x , (λ y → ! (inverse-right-inverse (f , e) y) ∘ ap f (p _))) equiv-types-truncated (S n) f c = λ x y → equiv-types-truncated n (equiv-ap (f ⁻¹) x y ⁻¹) (c (f ⁻¹ ☆ x) (f ⁻¹ ☆ y)) Π-is-truncated : ∀ {i j} (n : ℕ₋₂) {A : Set i} {P : A → Set j} → (((x : A) → is-truncated n (P x)) → is-truncated n (Π A P)) Π-is-truncated ⟨-2⟩ p = ((λ x → π₁ (p x)) , (λ f → funext (λ x → π₂ (p x) (f x)))) Π-is-truncated (S n) p = λ f g → equiv-types-truncated n funext-equiv (Π-is-truncated n (λ x → p x (f x) (g x))) →-is-truncated : ∀ {i j} (n : ℕ₋₂) {A : Set i} {B : Set j} → (is-truncated n B → is-truncated n (A → B)) →-is-truncated n p = Π-is-truncated n (λ _ → p) is-truncated-is-prop : ∀ {i} (n : ℕ₋₂) {A : Set i} → is-prop (is-truncated n A) is-truncated-is-prop ⟨-2⟩ = is-contr-is-prop is-truncated-is-prop (S n) = Π-is-truncated _ (λ x → Π-is-truncated _ (λ y → is-truncated-is-prop n)) is-set-is-prop : ∀ {i} {A : Set i} → is-prop (is-set A) is-set-is-prop = is-truncated-is-prop ⟨0⟩ Σ-is-truncated : ∀ {i j} (n : ℕ₋₂) {A : Set i} {P : A → Set j} → (is-truncated n A → ((x : A) → is-truncated n (P x)) → is-truncated n (Σ A P)) Σ-is-truncated ⟨-2⟩ p q = ((π₁ p , (π₁ (q (π₁ p)))) , (λ y → Σ-eq (π₂ p _) (π₂ (q _) _))) Σ-is-truncated (S n) p q = λ x y → equiv-types-truncated n total-Σ-eq-equiv (Σ-is-truncated n (p _ _) (λ _ → q _ _ _)) ×-is-truncated : ∀ {i j} (n : ℕ₋₂) {A : Set i} {B : Set j} → (is-truncated n A → is-truncated n B → is-truncated n (A × B)) ×-is-truncated n pA pB = Σ-is-truncated n pA (λ x → pB) subtype-truncated-S-is-truncated-S : ∀ {i j} (n : ℕ₋₂) {A : Set i} {P : A → Set j} → (is-truncated (S n) A → ((x : A) → is-prop (P x)) → is-truncated (S n) (Σ A P)) subtype-truncated-S-is-truncated-S n p q = Σ-is-truncated (S n) p (λ x → prop-is-truncated-S n (q x)) is-equiv-is-prop : ∀ {i j} {A : Set i} {B : Set j} (f : A → B) → is-prop (is-equiv f) is-equiv-is-prop f = Π-is-truncated _ (λ x → is-contr-is-prop) -- Specilization module _ where Π-is-prop : ∀ {i j} {A : Set i} {P : A → Set j} → (((x : A) → is-prop (P x)) → is-prop (Π A P)) Π-is-prop = Π-is-truncated ⟨-1⟩ Π-is-set : ∀ {i j} {A : Set i} {P : A → Set j} → (((x : A) → is-set (P x)) → is-set (Π A P)) Π-is-set = Π-is-truncated ⟨0⟩ →-is-set : ∀ {i j} {A : Set i} {B : Set j} → (is-set B → is-set (A → B)) →-is-set = →-is-truncated ⟨0⟩ →-is-prop : ∀ {i j} {A : Set i} {B : Set j} → (is-prop B → is-prop (A → B)) →-is-prop = →-is-truncated ⟨-1⟩ -- Type of all n-truncated types Type≤ : (n : ℕ₋₂) (i : Level) → Set (suc i) Type≤ n i = Σ (Set i) (is-truncated n) hProp : (i : Level) → Set (suc i) hProp = Type≤ ⟨-1⟩ hSet : (i : Level) → Set (suc i) hSet = Type≤ ⟨0⟩ -- [Type≤ n] is (n+1)-truncated abstract ≃-is-truncated : ∀ {i} (n : ℕ₋₂) {A B : Set i} → (is-truncated n A → is-truncated n B → is-truncated n (A ≃ B)) ≃-is-truncated ⟨-2⟩ pA pB = (((λ _ → π₁ pB) , contr-to-contr-is-equiv _ pA pB) , (λ _ → Σ-eq (funext (λ _ → contr-has-all-paths pB _ _)) (π₁ (is-equiv-is-prop _ _ _)))) ≃-is-truncated (S n) pA pB = Σ-is-truncated (S n) (→-is-truncated (S n) pB) (λ _ → prop-is-truncated-S n (is-equiv-is-prop _)) ≃-is-set : ∀ {i} {A B : Set i} → (is-set A → is-set B → is-set (A ≃ B)) ≃-is-set = ≃-is-truncated ⟨0⟩ universe-≡-is-truncated : ∀ {i} (n : ℕ₋₂) {A B : Set i} → (is-truncated n A → is-truncated n B → is-truncated n (A ≡ B)) universe-≡-is-truncated n pA pB = equiv-types-truncated n eq-to-path-equiv $ ≃-is-truncated n pA pB universe-≡-is-set : ∀ {i} {A B : Set i} → (is-set A → is-set B → is-set (A ≡ B)) universe-≡-is-set = universe-≡-is-truncated ⟨0⟩ Type≤-is-truncated : (n : ℕ₋₂) (i : Level) → is-truncated (S n) (Type≤ n i) Type≤-is-truncated n i A B = equiv-types-truncated n total-Σ-eq-equiv (Σ-is-truncated n (universe-≡-is-truncated n (π₂ A) (π₂ B)) (λ _ → contr-is-truncated n (≡-is-truncated _ (inhab-prop-is-contr (π₂ B) (is-truncated-is-prop n {-(π₁ B)-}))))) hProp-is-set : (i : Level) → is-set (hProp i) hProp-is-set = Type≤-is-truncated _ hSet-is-gpd : (i : Level) → is-gpd (hSet i) hSet-is-gpd = Type≤-is-truncated _
{ "alphanum_fraction": 0.5178821879, "avg_line_length": 37.5263157895, "ext": "agda", "hexsha": "8ca6641a04cb7539f5c97d576dfef0c7b650d13c", "lang": "Agda", "max_forks_count": 50, "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "old/HLevelBis.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "old/HLevelBis.agda", "max_line_length": 79, "max_stars_count": 294, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "old/HLevelBis.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": 2287, "size": 5704 }
open import Coinduction using ( ♭ ; ♯_ ) open import Data.Empty using ( ⊥-elim ) open import System.IO.Transducers.Session using ( Session ; I ; Σ ; IsΣ ; Γ ; _/_ ; _∼_ ) open import System.IO.Transducers.Trace using ( Trace ; [] ; _∷_ ; _⊨_✓ ; _✓ ; _⊑_ ) open import System.IO.Transducers.Lazy using ( _⇒_ ; inp ; out ; done ; ⟦_⟧ ; _≃_ ; equiv ) open import System.IO.Transducers.Reflective using ( Reflective ; inp ; out ; done ) open import System.IO.Transducers.Strict using ( Strict ; inp ; done ) open import Relation.Binary.PropositionalEquality using ( _≡_ ; refl ; sym ; trans ; cong ) open import Relation.Nullary using ( Dec ; ¬_ ; yes ; no ) module System.IO.Transducers.Properties.Lemmas where open Relation.Binary.PropositionalEquality.≡-Reasoning -- ≃ is an equivalence ≃-refl : ∀ {S T} {f : Trace S → Trace T} → (f ≃ f) ≃-refl as = refl ≃-sym : ∀ {S T} {f g : Trace S → Trace T} → (f ≃ g) → (g ≃ f) ≃-sym f≃g as = sym (f≃g as) ≃-trans : ∀ {S T} {f g h : Trace S → Trace T} → (f ≃ g) → (g ≃ h) → (f ≃ h) ≃-trans f≃g g≃h as = trans (f≃g as) (g≃h as) -- Completion is decidable ✓-tl : ∀ {S a as} → (S ⊨ a ∷ as ✓) → (S / a ⊨ as ✓) ✓-tl (a ∷ as✓) = as✓ ✓? : ∀ {S} as → (Dec (S ⊨ as ✓)) ✓? {I} [] = yes [] ✓? {Σ V F} [] = no (λ ()) ✓? (a ∷ as) with ✓? as ✓? (a ∷ as) | yes as✓ = yes (a ∷ as✓) ✓? (a ∷ as) | no ¬as✓ = no (λ a∷as✓ → ¬as✓ (✓-tl a∷as✓)) -- Eta conversion for traces of type I I-η : ∀ (as : Trace I) → (as ≡ []) I-η [] = refl I-η (() ∷ as) -- All traces at type I are complete I-✓ : ∀ (as : Trace I) → (as ✓) I-✓ [] = [] I-✓ (() ∷ as) -- Cons is invertable ∷-refl-≡₁ : ∀ {S a b} {as bs : Trace S} {cs ds} → (as ≡ a ∷ cs) → (bs ≡ b ∷ ds) → (as ≡ bs) → (a ≡ b) ∷-refl-≡₁ refl refl refl = refl ∷-refl-≡₂ : ∀ {S a} {as bs : Trace S} {cs ds} → (as ≡ a ∷ cs) → (bs ≡ a ∷ ds) → (as ≡ bs) → (cs ≡ ds) ∷-refl-≡₂ refl refl refl = refl -- Make a function reflective liat : ∀ {S} → (Trace S) → (Trace S) liat [] = [] liat (a ∷ []) = [] liat (a ∷ b ∷ bs) = a ∷ liat (b ∷ bs) incomplete : ∀ {S} → (Trace S) → (Trace S) incomplete as with ✓? as incomplete as | yes ✓as = liat as incomplete as | no ¬✓as = as reflective : ∀ {S T} → (Trace S → Trace T) → (Trace S → Trace T) reflective f as with ✓? as reflective f as | yes ✓as = f as reflective f as | no ¬✓as = incomplete (f as) liat-¬✓ : ∀ {S} a as → ¬ (S ⊨ liat (a ∷ as) ✓) liat-¬✓ a (b ∷ bs) (.a ∷ ✓cs) = liat-¬✓ b bs ✓cs liat-¬✓ {I} () [] []✓ liat-¬✓ {Σ V F} a [] () incomplete-¬✓ : ∀ {S} {isΣ : IsΣ S} (as : Trace S) → ¬ (incomplete as ✓) incomplete-¬✓ as with ✓? as incomplete-¬✓ {I} {} [] | yes [] incomplete-¬✓ {Σ V F} [] | yes () incomplete-¬✓ (a ∷ as) | yes ✓a∷as = liat-¬✓ a as incomplete-¬✓ as | no ¬✓as = ¬✓as reflective-refl-✓ : ∀ {S T} {isΣ : IsΣ T} (f : Trace S → Trace T) as → (reflective f as ✓) → (as ✓) reflective-refl-✓ f as ✓bs with ✓? as reflective-refl-✓ f as ✓bs | yes ✓as = ✓as reflective-refl-✓ {S} {Σ V F} f as ✓bs | no ¬✓as = ⊥-elim (incomplete-¬✓ (f as) ✓bs) reflective-refl-✓ {S} {I} {} f as ✓bs | no ¬✓as reflective-≡-✓ : ∀ {S T} (f : Trace S → Trace T) {as} → (as ✓) → (reflective f as ≡ f as) reflective-≡-✓ f {as} ✓as with ✓? as reflective-≡-✓ f {as} ✓as | yes _ = refl reflective-≡-✓ f {as} ✓as | no ¬✓as = ⊥-elim (¬✓as ✓as) -- All transducers are monotone ⟦⟧-mono : ∀ {S T} (P : S ⇒ T) as bs → (as ⊑ bs) → (⟦ P ⟧ as ⊑ ⟦ P ⟧ bs) ⟦⟧-mono (inp P) .[] bs [] = [] ⟦⟧-mono (inp P) (.a ∷ as) (.a ∷ bs) (a ∷ as⊑bs) = ⟦⟧-mono (♭ P a) as bs as⊑bs ⟦⟧-mono (out b P) as bs as⊑bs = b ∷ (⟦⟧-mono P as bs as⊑bs) ⟦⟧-mono done as bs as⊑bs = as⊑bs -- All transducers respect completion ⟦⟧-resp-✓ : ∀ {S T} (P : S ⇒ T) as → (as ✓) → (⟦ P ⟧ as ✓) ⟦⟧-resp-✓ (inp P) (a ∷ as) (.a ∷ ✓as) = ⟦⟧-resp-✓ (♭ P a) as ✓as ⟦⟧-resp-✓ (out b P) as ✓as = b ∷ ⟦⟧-resp-✓ P as ✓as ⟦⟧-resp-✓ done as ✓as = ✓as ⟦⟧-resp-✓ (inp P) [] () -- Reflective transducers reflect completion ⟦⟧-refl-✓ : ∀ {S T} {P : S ⇒ T} → (Reflective P) → ∀ as → (⟦ P ⟧ as ✓) → (as ✓) ⟦⟧-refl-✓ (inp ⟳P) (a ∷ as) bs✓ = a ∷ ⟦⟧-refl-✓ (♭ ⟳P a) as bs✓ ⟦⟧-refl-✓ (out b ⟳P) as bs✓ = ⟦⟧-refl-✓ ⟳P as (✓-tl bs✓) ⟦⟧-refl-✓ done as bs✓ = bs✓ ⟦⟧-refl-✓ (inp ⟳P) [] () -- Any transducer which reflects completion is reflective ⟦⟧-refl-✓⁻¹ : ∀ {S T} (P : S ⇒ T) → (∀ as → (⟦ P ⟧ as ✓) → (as ✓)) → (Reflective P) ⟦⟧-refl-✓⁻¹ {Σ V F} {Σ W G} (inp P) H = inp (♯ λ a → ⟦⟧-refl-✓⁻¹ (♭ P a) (λ as → λ bs✓ → ✓-tl (H (a ∷ as) bs✓))) ⟦⟧-refl-✓⁻¹ (out b P) H = out b (⟦⟧-refl-✓⁻¹ P (λ as bs✓ → H as (b ∷ bs✓))) ⟦⟧-refl-✓⁻¹ done H = done ⟦⟧-refl-✓⁻¹ {Σ V F} {I} (inp P) H with H [] [] ⟦⟧-refl-✓⁻¹ {Σ V F} {I} (inp P) H | () -- Strict transducers respect emptiness. ⟦⟧-resp-[] : ∀ {S T} {P : S ⇒ T} → (Strict P) → (⟦ P ⟧ [] ≡ []) ⟦⟧-resp-[] (inp P) = refl ⟦⟧-resp-[] done = refl -- Any transducer which respects emptiness is strict. ⟦⟧-resp-[]⁻¹ : ∀ {S T} (P : S ⇒ T) → (∀ {as} → (as ≡ []) → (⟦ P ⟧ as ≡ [])) → (Strict P) ⟦⟧-resp-[]⁻¹ (inp P) H = inp P ⟦⟧-resp-[]⁻¹ (out b P) H with H refl ⟦⟧-resp-[]⁻¹ (out b P) H | () ⟦⟧-resp-[]⁻¹ done H = done -- Coherence wrt ∼ ⟦⟧-resp-∼ : ∀ {S T} (eq₁ eq₂ : S ∼ T) → ⟦ equiv eq₁ ⟧ ≃ ⟦ equiv eq₂ ⟧ ⟦⟧-resp-∼ I I as = refl ⟦⟧-resp-∼ (Σ V F) (Σ .V G) [] = refl ⟦⟧-resp-∼ (Σ V F) (Σ .V G) (a ∷ as) = cong (_∷_ a) (⟦⟧-resp-∼ (♭ F a) (♭ G a) as) -- IsEquiv P is inhabited whenever P is equivalent to an equivalence data IsEquiv {S T : Session} (P : S ⇒ T) : Set₁ where isEquiv : (S∼T : S ∼ T) → (⟦ P ⟧ ≃ ⟦ equiv S∼T ⟧) → (IsEquiv P) -- Equivalences are equivalent ≃-equiv : ∀ {S T} {P Q : S ⇒ T} → (IsEquiv P) → (IsEquiv Q) → (⟦ P ⟧ ≃ ⟦ Q ⟧) ≃-equiv {S} {T} {P} {Q} (isEquiv eq₁ P≃eq₁) (isEquiv eq₂ Q≃eq₂) as = begin ⟦ P ⟧ as ≡⟨ P≃eq₁ as ⟩ ⟦ equiv eq₁ ⟧ as ≡⟨ ⟦⟧-resp-∼ eq₁ eq₂ as ⟩ ⟦ equiv eq₂ ⟧ as ≡⟨ sym (Q≃eq₂ as) ⟩ ⟦ Q ⟧ as ∎
{ "alphanum_fraction": 0.4730882836, "avg_line_length": 35.0229885057, "ext": "agda", "hexsha": "83c4f4fc2a4ccecd2884061b88182af5641d7e9b", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:23.000Z", "max_forks_repo_forks_event_min_datetime": "2017-08-10T06:12:54.000Z", "max_forks_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ilya-fiveisky/agda-system-io", "max_forks_repo_path": "src/System/IO/Transducers/Properties/Lemmas.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371", "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": "ilya-fiveisky/agda-system-io", "max_issues_repo_path": "src/System/IO/Transducers/Properties/Lemmas.agda", "max_line_length": 114, "max_stars_count": 10, "max_stars_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ilya-fiveisky/agda-system-io", "max_stars_repo_path": "src/System/IO/Transducers/Properties/Lemmas.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-15T04:35:41.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-04T13:45:16.000Z", "num_tokens": 2972, "size": 6094 }
{-# OPTIONS --universe-polymorphism #-} -- Should give some unsolved metas module Issue203b where open import Imports.Level -- Should work but give unsolved metas (type of b) data ↓ {a b} (A : Set a) : Set a where [_] : (x : A) → ↓ A -- Shouldn't instantiate the level of Σ to a data Σ {a b} (A : Set a) (B : A → Set b) : Set _ where _,_ : (x : A) (y : B x) → Σ A B
{ "alphanum_fraction": 0.6069518717, "avg_line_length": 24.9333333333, "ext": "agda", "hexsha": "7900c7a85087e52e799f2d2cec322d7cf1193117", "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/Issue203b.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/Issue203b.agda", "max_line_length": 54, "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/Issue203b.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": 133, "size": 374 }
{-# OPTIONS --cubical #-} module _ where open import Agda.Primitive.Cubical open import Agda.Builtin.Cubical.Path data S1 : Set where base : S1 loop : base ≡ base postulate weird : S1 → I bad : (x : S1) → I bad base = {!!} bad (loop x) = {!!}
{ "alphanum_fraction": 0.625984252, "avg_line_length": 14.1111111111, "ext": "agda", "hexsha": "21dfa592547f27245eae7190bfa5312d343959a1", "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": "2fa8ede09451d43647f918dbfb24ff7b27c52edc", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "phadej/agda", "max_forks_repo_path": "test/Fail/Issue3314.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc", "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": "phadej/agda", "max_issues_repo_path": "test/Fail/Issue3314.agda", "max_line_length": 37, "max_stars_count": null, "max_stars_repo_head_hexsha": "2fa8ede09451d43647f918dbfb24ff7b27c52edc", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "phadej/agda", "max_stars_repo_path": "test/Fail/Issue3314.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 88, "size": 254 }
{-# OPTIONS --allow-unsolved-metas #-} module HasSubstantiveDischarge where open import OscarPrelude record HasSubstitution (T : Set) (S : Set) : Set where field _◃_ : S → T → T open HasSubstitution ⦃ … ⦄ public record HasPairUnification (T : Set) (S : Set) : Set where field ⦃ hasSubstitution ⦄ : HasSubstitution T S Property : Set₁ Property = S × S → Set Nothing : Property → Set Nothing P = ∀ s → P s → ⊥ IsPairUnifier : (t₁ t₂ : T) → Property IsPairUnifier t₁ t₂ s = let s₁ , s₂ = s in s₁ ◃ t₁ ≡ s₂ ◃ t₂ field unify : (t₁ t₂ : T) → Dec ∘ ∃ $ IsPairUnifier t₁ t₂ open HasPairUnification ⦃ … ⦄ public open import HasNegation record HasSubstantiveDischarge (A : Set) : Set₁ where field _o≽o_ : A → A → Set field ⦃ hasNegation ⦄ : HasNegation A _⋡_ : A → A → Set _⋡_ (+) (-) = ¬ + o≽o - field ≽-reflexive : (x : A) → x o≽o x ≽-consistent : (+ - : A) → + o≽o - → + ⋡ ~ - ≽-contrapositive : ∀ x y → ~ x o≽o y → x o≽o ~ y ≽-contrapositive' : ∀ x y → x o≽o ~ y → ~ x o≽o y ≽-contrapositive' = {!!} open HasSubstantiveDischarge ⦃ … ⦄ public {-# DISPLAY HasSubstantiveDischarge._o≽o_ _ = _o≽o_ #-} open import Membership record HasGenericSubstantiveDischarge (A : Set) (B : Set) : Set₁ where field _≽_ : A → B → Set open HasGenericSubstantiveDischarge ⦃ … ⦄ public {-# DISPLAY HasGenericSubstantiveDischarge._≽_ _ = _≽_ #-} instance HasGenericSubstantiveDischargeReflexive : ∀ {A} ⦃ _ : HasSubstantiveDischarge A ⦄ → HasGenericSubstantiveDischarge A A HasGenericSubstantiveDischarge._≽_ HasGenericSubstantiveDischargeReflexive = _o≽o_ instance HasGenericSubstantiveDischargeAList : ∀ {A} ⦃ _ : HasSubstantiveDischarge A ⦄ → HasGenericSubstantiveDischarge A (List A) HasGenericSubstantiveDischarge._≽_ (HasGenericSubstantiveDischargeAList {A}) (+) -s = ∃ λ (i : A) → i ∈ -s × (+ ≽ i) instance HasGenericSubstantiveDischargeListA : ∀ {A} ⦃ _ : HasSubstantiveDischarge A ⦄ → HasGenericSubstantiveDischarge (List A) A HasGenericSubstantiveDischarge._≽_ (HasGenericSubstantiveDischargeListA {A}) (+s) (-) = ∃ λ (c : A) → c ∈ +s × c ≽ - instance HasGenericSubstantiveDischargeListList : ∀ {A} ⦃ _ : HasSubstantiveDischarge A ⦄ → HasGenericSubstantiveDischarge (List A) (List A) HasGenericSubstantiveDischarge._≽_ (HasGenericSubstantiveDischargeListList {A}) +s -s = ∀ (i : A) → i ∈ -s → +s ≽ i ⋆≽⋆-reflexive : ∀ {A} ⦃ _ : HasSubstantiveDischarge A ⦄ → (xs : List A) → xs ≽ xs ⋆≽⋆-reflexive _ i i∈ys⋆ = _ , i∈ys⋆ , ≽-reflexive i ◁_ : ∀ {A} ⦃ _ : HasSubstantiveDischarge A ⦄ → List A → Set ◁_ {A} +s = ∃ λ (s : A) → s ∈ +s × +s ≽ ~ s ⋪_ : ∀ {A} ⦃ _ : HasSubstantiveDischarge A ⦄ → List A → Set ⋪_ = ¬_ ∘ ◁_ record HasDecidableSubstantiveDischarge (A : Set) : Set₁ where field ⦃ hasSubstantiveDischarge ⦄ : HasSubstantiveDischarge A _≽?_ : (+ - : A) → Dec $ + o≽o - open HasDecidableSubstantiveDischarge ⦃ … ⦄ public {-# DISPLAY HasDecidableSubstantiveDischarge._≽?_ _ = _≽?_ #-} _⋆≽?_ : ∀ {A} ⦃ _ : HasDecidableSubstantiveDischarge A ⦄ → (+s : List A) → (- : A) → Dec (+s ≽ -) _⋆≽?_ [] - = no λ { (_ , () , _)} _⋆≽?_ (+ ∷ +s) - with + ≽? - … | yes +≽- = yes $ _ , zero , +≽- … | no +⋡- with +s ⋆≽? - … | yes (+' , +'∈+s , +'≽-) = yes $ _ , suc +'∈+s , +'≽- … | no +s⋡- = no λ { (_ , zero , +≽-) → +⋡- +≽- ; (+' , suc +'∈+s , +'≽-) → +s⋡- $ _ , +'∈+s , +'≽- } _≽⋆?_ : ∀ {A} ⦃ _ : HasDecidableSubstantiveDischarge A ⦄ → (+ : A) → (-s : List A) → Dec (+ ≽ -s) + ≽⋆? [] = no (λ { (fst₁ , () , snd₁)}) + ≽⋆? (- ∷ -s) with + ≽? - … | yes +≽- = yes (_ , zero , +≽-) … | no +⋡- with + ≽⋆? -s … | yes (_ , i∈-s , +≽⋆i) = yes (_ , suc i∈-s , +≽⋆i) … | no +⋡⋆-s = no (λ { (_ , zero , +≽-) → +⋡- +≽- ; (_ , suc -'∈-s , +≽-') → +⋡⋆-s (_ , -'∈-s , +≽-')}) _⋆≽⋆?_ : ∀ {A} ⦃ _ : HasDecidableSubstantiveDischarge A ⦄ → (+s : List A) → (-s : List A) → Dec (+s ≽ -s) _⋆≽⋆?_ +s [] = yes λ _ () _⋆≽⋆?_ +s (- ∷ -s) with +s ⋆≽? - … | no +s⋡- = no λ +s≽-∷-s → +s⋡- $ +s≽-∷-s (-) zero … | yes +s≽- with +s ⋆≽⋆? -s … | yes +s≽-s = yes λ { _ zero → +s≽- ; -' (suc -'∈-∷-s) → +s≽-s -' -'∈-∷-s } … | no +s⋡-s = no λ +s≽-∷-s → +s⋡-s λ +' +'∈-s → +s≽-∷-s +' (suc +'∈-s) ◁?_ : ∀ {+} ⦃ _ : HasDecidableSubstantiveDischarge (+) ⦄ → (+s : List +) → Dec $ ◁ +s ◁? [] = no λ {(_ , () , _)} ◁?_ (+ ∷ +s) with +s ⋆≽? ~ + … | yes (_ , +'∈+s , +'≽~+) = yes $ _ , zero , _ , suc +'∈+s , +'≽~+ … | no +s⋆⋡~+ with ~ + ≽⋆? +s … | yes (_ , c∈+s , ~+≽c) = yes (_ , suc c∈+s , _ , zero , ≽-contrapositive (+) _ ~+≽c) … | no ~+⋡⋆+s with ◁? +s … | yes (s , s∈+s , c , c∈+s , c≽~s) = yes $ _ , suc s∈+s , _ , suc c∈+s , c≽~s … | no ⋪+s = no λ { (_ , zero , _ , zero , c≽~s) → ≽-consistent (+) (+) (≽-reflexive +) c≽~s ; (_ , zero , c , suc c∈+s , c≽~s) → +s⋆⋡~+ (_ , c∈+s , c≽~s) ; (s , suc s∈+s , .+ , zero , +≽~s) → ~+⋡⋆+s (_ , s∈+s , ≽-contrapositive' (+) s +≽~s) ; (s , suc s∈+s , c , suc c∈+s , c≽~s) → ⋪+s (_ , s∈+s , _ , c∈+s , c≽~s) }
{ "alphanum_fraction": 0.5172760145, "avg_line_length": 36.0724637681, "ext": "agda", "hexsha": "beb4cedeabf50ec27e03469c3f487ca5cb9707fd", "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/HasSubstantiveDischarge.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/HasSubstantiveDischarge.agda", "max_line_length": 140, "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/HasSubstantiveDischarge.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2433, "size": 4978 }
{-# OPTIONS --without-K --safe #-} module Cats.Category.Constructions.Thin where open import Cats.Category.Base open import Level using (_⊔_) open import Relation.Binary.PropositionalEquality using (_≡_) module _ {lo la l≈} (C : Category lo la l≈) where open Category C Thin : Set (lo ⊔ la ⊔ l≈) Thin = ∀ {A B} {f g : A ⇒ B} → f ≈ g StronglyThin : Set (lo ⊔ la) StronglyThin = ∀ {A B} {f g : A ⇒ B} → f ≡ g StronglyThin→Thin : ∀ {lo la l≈} {C : Category lo la l≈} → StronglyThin C → Thin C StronglyThin→Thin {C = C} sthin = ≈.reflexive sthin where open Category C
{ "alphanum_fraction": 0.6306913997, "avg_line_length": 21.1785714286, "ext": "agda", "hexsha": "d4e4fb0797ec5bf05c5e60f833b0cf91effe2596", "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/Constructions/Thin.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/Constructions/Thin.agda", "max_line_length": 61, "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/Constructions/Thin.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": 209, "size": 593 }
------------------------------------------------------------------------------ -- All the group theory modules ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module GroupTheory.Everything where open import GroupTheory.Base open import GroupTheory.Base.Consistency.Axioms open import GroupTheory.AbelianGroup.Base open import GroupTheory.AbelianGroup.Base.Consistency.Axioms open import GroupTheory.AbelianGroup.PropertiesATP open import GroupTheory.Commutator open import GroupTheory.Commutator.PropertiesATP open import GroupTheory.Commutator.PropertiesI open import GroupTheory.PropertiesATP open import GroupTheory.PropertiesI
{ "alphanum_fraction": 0.6226190476, "avg_line_length": 33.6, "ext": "agda", "hexsha": "92975b7799970dbf4abffb0ade514cd716ef43f8", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/GroupTheory/Everything.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/GroupTheory/Everything.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/GroupTheory/Everything.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 149, "size": 840 }
{-# OPTIONS --warning=error #-} module _ (A : Set) where {-# POLARITY A #-}
{ "alphanum_fraction": 0.5641025641, "avg_line_length": 13, "ext": "agda", "hexsha": "5d44c285a0f7993ddcf8975d49198f061c257989", "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/Polarity-pragma-for-module-parameter.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/Polarity-pragma-for-module-parameter.agda", "max_line_length": 31, "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/Polarity-pragma-for-module-parameter.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": 22, "size": 78 }
open import prelude renaming (_≟String_ to _≟_) infixl 5 _$_ -- Copied pretty much verbatim Var = String data Term : Set where var : Var → Term fun : Var → Term → Term _$_ : Term → Term → Term data Value : Term → Set where fun : (x : Var) → (t : Term) → Value(fun x t) -- Free variables of a term. -- (Turns out to be easiest to define when a variable isn't free rather than when it is.) data _∉FV_ : Var → Term → Set where var : ∀ {x y} → x ≢ y → ------------- x ∉FV(var y) fun₁ : ∀ {x y t} → (x ≡ y) → --------------- x ∉FV(fun y t) fun₂ : ∀ {x y t} → (x ∉FV(t)) → --------------- x ∉FV(fun y t) app : ∀ {x t₁ t₂} → (x ∉FV(t₁)) → (x ∉FV(t₂)) → ----------------- (x ∉FV(t₁ $ t₂)) -- Substitution -- TAPL defines substitution as a partial function, which Agda doesn't implement. -- So instead we keep track of the derivation tree. data [_↦_]_is_ : Var → Term → Term → Term → Set where yes : ∀ {x y s} → (x ≡ y) → ---------------------- [ x ↦ s ] (var y) is s no : ∀ {x y s} → (x ≢ y) → ---------------------------- [ x ↦ s ] (var y) is (var y) fun₁ : ∀ {x y s t} → (x ≡ y) → -------------------------------- [ x ↦ s ] (fun y t) is (fun y t) fun₂ : ∀ {x y s t t′} → (x ≢ y) → (y ∉FV(s)) → [ x ↦ s ] t is t′ → --------------------------------- [ x ↦ s ] (fun y t) is (fun y t′) app : ∀ {x s t₁ t₁′ t₂ t₂′} → [ x ↦ s ] t₁ is t₁′ → [ x ↦ s ] t₂ is t₂′ → --------------------------------- [ x ↦ s ] (t₁ $ t₂) is (t₁′ $ t₂′) -- Reduction is as per TAPL data _⟶_ : Term → Term → Set where E─App1 : ∀ {t₁ t₁′ t₂} → (t₁ ⟶ t₁′) → ------------------------ (t₁ $ t₂) ⟶ (t₁′ $ t₂) E─App2 : ∀ {t₁ t₂ t₂′} → (t₂ ⟶ t₂′) → ------------------------ (t₁ $ t₂) ⟶ (t₁ $ t₂′) E─AppAbs : ∀ {x t₁ t₂ t₃} → [ x ↦ t₂ ] t₁ is t₃ → ---------------------- (fun x t₁ $ t₂) ⟶ t₃ -- A redex is a term which can reduce data Redex : Term → Set where redex : ∀ {t t′} → t ⟶ t′ → -------- Redex(t) -- A closed term is one with no free variables Closed : Term → Set Closed(t) = ∀ {x} → x ∉FV(t) -- Proving that substitution is well-defined for closed terms data [_↦_]_⇓ : Var → Term → Term → Set where subst : ∀ {x s t t′} → ([ x ↦ s ] t is t′) → ([ x ↦ s ] t ⇓) substDef : (x : Var) → (s t : Term) → Closed(s) → ([ x ↦ s ] t ⇓) substDef x s (var y) c = helper (x ≟ y) where helper : Dec(x ≡ y) → ([ x ↦ s ] (var y) ⇓) helper (yes p) = subst (yes p) helper (no p) = subst (no p) substDef x s (fun y t) c = helper₁ (x ≟ y) where helper₂ : (x ≢ y) → ([ x ↦ s ] t ⇓) → ([ x ↦ s ] (fun y t) ⇓) helper₂ p (subst s) = subst (fun₂ p c s) helper₁ : Dec(x ≡ y) → ([ x ↦ s ] (fun y t) ⇓) helper₁ (yes p) = subst (fun₁ p) helper₁ (no p) = helper₂ p (substDef x s t c) substDef x s (t₁ $ t₂) c = helper (substDef x s t₁ c) (substDef x s t₂ c) where helper : ([ x ↦ s ] t₁ ⇓) → ([ x ↦ s ] t₂ ⇓) → ([ x ↦ s ] (t₁ $ t₂) ⇓) helper (subst s₁) (subst s₂) = subst (app s₁ s₂) -- Proving that closed terms stay closed closed₁ : ∀ {t₁ t₂ x} → (x ∉FV(t₁ $ t₂)) → (x ∉FV(t₁)) closed₁ (app p₁ p₂) = p₁ closed₂ : ∀ {t₁ t₂ x} → (x ∉FV(t₁ $ t₂)) → (x ∉FV(t₂)) closed₂ (app p₁ p₂) = p₂ substClosed₁ : ∀ {y s t t′} → (y ∉FV(s)) → ([ y ↦ s ] t is t′) → (y ∉FV(t′)) substClosed₁ p (yes refl) = p substClosed₁ p (no q) = var q substClosed₁ p (fun₁ q) = fun₁ q substClosed₁ p (fun₂ x x₁ q) = fun₂ (substClosed₁ p q) substClosed₁ p (app q₁ q₂) = app (substClosed₁ p q₁) (substClosed₁ p q₂) substClosed₂ : ∀ {x y s t t′} → (x ∉FV(t)) → (x ∉FV(s)) → ([ y ↦ s ] t is t′) → (x ∉FV(t′)) substClosed₂ p q (yes refl) = q substClosed₂ p q (no r) = p substClosed₂ p q (fun₁ refl) = p substClosed₂ (fun₁ p) q (fun₂ x x₁ r) = fun₁ p substClosed₂ (fun₂ p) q (fun₂ x x₁ r) = fun₂ (substClosed₂ p q r) substClosed₂ (app p₁ p₂) q (app r₁ r₂) = app (substClosed₂ p₁ q r₁) (substClosed₂ p₂ q r₂) substClosed₃ : ∀ {x y s t t′} → x ∉FV(fun y t) → x ∉FV(s) → ([ y ↦ s ] t is t′) → x ∉FV(t′) substClosed₃ (fun₁ refl) q r = substClosed₁ q r substClosed₃ (fun₂ p) q r = substClosed₂ p q r redexClosed : ∀ {t t′} → Closed(t) → (t ⟶ t′) → Closed(t′) redexClosed c (E─App1 r) = app (redexClosed (closed₁ c) r) (closed₂ c) redexClosed c (E─App2 r) = app (closed₁ c) (redexClosed (closed₂ c) r) redexClosed c (E─AppAbs s) = substClosed₃ (closed₁ c) (closed₂ c) s -- Proving that every closed term is a value or a redex data ValueOrRedex : Term → Set where value : ∀ {t} → (Value(t)) → --------------- ValueOrRedex(t) redex : ∀ {t t′} → t ⟶ t′ → --------------- ValueOrRedex(t) valueOrRedex : (t : Term) → Closed(t) → ValueOrRedex(t) valueOrRedex (var x) c = CONTRADICTION (helper c) where helper : (x ∉FV(var x)) → FALSE helper (var p) = p refl valueOrRedex (fun x t) c = value (fun x t) valueOrRedex (t₁ $ t₂) c = helper₁ (valueOrRedex t₁ (closed₁ c)) where helper₃ : ∀ {x s t} → ([ x ↦ s ] t ⇓) → ValueOrRedex((fun x t) $ s) helper₃ (subst s) = redex (E─AppAbs s) helper₂ : ∀ {t₁} → Value(t₁) → ValueOrRedex(t₂) → ValueOrRedex(t₁ $ t₂) helper₂ (fun x t) (value v) = helper₃ (substDef x t₂ t (closed₂ c)) helper₂ (fun x t) (redex r) = redex (E─App2 r) helper₁ : ValueOrRedex(t₁) → ValueOrRedex(t₁ $ t₂) helper₁ (value v₁) = helper₂ v₁ (valueOrRedex t₂ (closed₂ c)) helper₁ (redex r) = redex (E─App1 r) -- Interpreter! data _⟶*_ : Term → Term → Set where done : ∀ {t} → -------- t ⟶* t redex : ∀ {t t′ t″} → t ⟶ t′ → t′ ⟶* t″ → ---------- t ⟶* t″ -- An interpreter result data Result : Term → Set where result : ∀ {t t′} → t ⟶* t′ → Value(t′) → --------- Result(t) -- The interpreter just calls `valueOrRedex` until it is a value. -- This might bot terminate! {-# NON_TERMINATING #-} interp : (t : Term) → Closed(t) → Result(t) interp t c = helper₂ (valueOrRedex t c) where helper₁ : ∀ {t′} → (t ⟶ t′) → Result(t′) → Result(t) helper₁ r (result s v) = result (redex r s) v helper₂ : ValueOrRedex(t) → Result(t) helper₂ (value v) = result done v helper₂ (redex {t′ = t′} r) = helper₁ r (interp t′ (redexClosed c r)) -- Examples zer : Term zer = fun "z" (fun "s" (var "z")) succ : Term succ = fun "x" (fun "z" (fun "s" (var "s" $ var "x"))) add : Term add = fun "x" (fun "y" (var "x" $ var "y" $ succ)) two : Term two = succ $ (succ $ zer) four : Term four = add $ two $ two zerC : Closed(zer) zerC {x} with (x ≟ "z") ... | yes refl = fun₁ refl ... | no p = fun₂ (fun₂ (var p)) succC : Closed(succ) succC {x} with (x ≟ "x") | (x ≟ "s") ... | yes refl | _ = fun₁ refl ... | no p | yes refl = fun₂ (fun₂ (fun₁ refl)) ... | no p | no q = fun₂ (fun₂ (fun₂ (app (var q) (var p)))) addC : Closed(add) addC {x} with (x ≟ "x") | (x ≟ "y") ... | yes refl | _ = fun₁ refl ... | no p | yes refl = fun₂ (fun₁ refl) ... | no p | no q = fun₂ (fun₂ (app (app (var p) (var q)) succC)) twoC : Closed(two) twoC = app succC (app succC zerC) fourC : Closed(four) fourC = app (app addC twoC) twoC
{ "alphanum_fraction": 0.5027049521, "avg_line_length": 24.03, "ext": "agda", "hexsha": "695e592b208b7ac225e48373879b9f9ad8ed31d3", "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": "de2ae6c24d001b85a5032c9e06cc731557dbc5e5", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "asajeffrey/tapl", "max_forks_repo_path": "ch5.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "de2ae6c24d001b85a5032c9e06cc731557dbc5e5", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "asajeffrey/tapl", "max_issues_repo_path": "ch5.agda", "max_line_length": 91, "max_stars_count": 3, "max_stars_repo_head_hexsha": "de2ae6c24d001b85a5032c9e06cc731557dbc5e5", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "asajeffrey/tapl", "max_stars_repo_path": "ch5.agda", "max_stars_repo_stars_event_max_datetime": "2021-03-15T12:09:59.000Z", "max_stars_repo_stars_event_min_datetime": "2021-03-12T22:44:19.000Z", "num_tokens": 2930, "size": 7209 }
-- Reported by fredrik.forsberg, Oct 21, 2014 -- The following code gives an internal error -- "An internal error has occurred. Please report this as a bug. -- Location of the error: src/full/Agda/TypeChecking/InstanceArguments.hs:269" -- on Agda head, since "n ≠ zero" is not expanded. open import Common.Prelude open import Common.Equality ¬ : (A : Set) → Set ¬ A = A → ⊥ _≠_ : {A : Set} → (A → A → Set) x ≠ y = ¬ (x ≡ y) f : (n : Nat) ⦃ _ : n ≠ zero ⦄ -> Nat f n = n g : Nat g = f (suc zero)
{ "alphanum_fraction": 0.6274900398, "avg_line_length": 21.8260869565, "ext": "agda", "hexsha": "b1cbbb10aaabfdcdcc25861e1d8eaed0a5eb493d", "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": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "alhassy/agda", "max_forks_repo_path": "test/Fail/Issue1321.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "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": "alhassy/agda", "max_issues_repo_path": "test/Fail/Issue1321.agda", "max_line_length": 78, "max_stars_count": 3, "max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "alhassy/agda", "max_stars_repo_path": "test/Fail/Issue1321.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": 175, "size": 502 }
module C where open import B C : Set C = B
{ "alphanum_fraction": 0.6444444444, "avg_line_length": 6.4285714286, "ext": "agda", "hexsha": "e9fdae86f65c89d8c99b1f74639c7e8f479c0c92", "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/relocatable/originals/C.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/relocatable/originals/C.agda", "max_line_length": 14, "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/relocatable/originals/C.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": 16, "size": 45 }
open import Data.Sum using ( _⊎_ ; inj₁ ; inj₂ ) open import Relation.Binary.PropositionalEquality using ( refl ) open import Web.Semantic.DL.ABox.Interp using ( ⌊_⌋ ; ind ; _*_ ) open import Web.Semantic.DL.ABox.Model using ( _⊨a_ ; ⊨a-resp-≡³ ; on-bnode ; bnodes ; _,_ ) open import Web.Semantic.DL.Category.Object using ( Object ; IN ) open import Web.Semantic.DL.Category.Morphism using ( _⇒_ ; BN ; impl ; _⊑_ ; _≣_ ; _,_ ) open import Web.Semantic.DL.Category.Composition using ( _∙_ ) open import Web.Semantic.DL.Category.Tensor using ( _⊗_ ; _⟨⊗⟩_ ) open import Web.Semantic.DL.Category.Wiring using ( identity ; id✓ ) open import Web.Semantic.DL.Category.Properties.Composition.Lemmas using ( compose-left ; compose-right ; compose-resp-⊨a ) open import Web.Semantic.DL.Category.Properties.Tensor.Lemmas using ( tensor-up ; tensor-down ; tensor-resp-⊨a ) open import Web.Semantic.DL.Category.Properties.Tensor.RespectsWiring using ( tensor-resp-wiring ) open import Web.Semantic.DL.Signature using ( Signature ) open import Web.Semantic.DL.TBox using ( TBox ) open import Web.Semantic.DL.TBox.Interp using ( Δ ) open import Web.Semantic.Util using ( id ; _∘_ ; _⊕_⊕_ ; inode ; bnode ; enode ; left ; right ; up ; down ) module Web.Semantic.DL.Category.Properties.Tensor.Functor {Σ : Signature} {S T : TBox Σ} where tensor-resp-id : ∀ (A₁ A₂ : Object S T) → ((identity A₁ ⟨⊗⟩ identity A₂) ≣ identity (A₁ ⊗ A₂)) tensor-resp-id A₁ A₂ = tensor-resp-wiring A₁ A₂ A₁ A₂ id (id✓ A₁) id (id✓ A₂) id (id✓ (A₁ ⊗ A₂)) (λ x → refl) (λ x → refl) tensor-resp-compose : ∀ {A₁ A₂ B₁ B₂ C₁ C₂ : Object S T} (F₁ : A₁ ⇒ B₁) (F₂ : A₂ ⇒ B₂) (G₁ : B₁ ⇒ C₁) (G₂ : B₂ ⇒ C₂) → (((F₁ ∙ G₁) ⟨⊗⟩ (F₂ ∙ G₂)) ≣ ((F₁ ⟨⊗⟩ F₂) ∙ (G₁ ⟨⊗⟩ G₂))) tensor-resp-compose {A₁} {A₂} {B₁} {B₂} {C₁} {C₂} F₁ F₂ G₁ G₂ = (LHS⊑RHS , RHS⊑LHS) where LHS⊑RHS : (F₁ ∙ G₁) ⟨⊗⟩ (F₂ ∙ G₂) ⊑ (F₁ ⟨⊗⟩ F₂) ∙ (G₁ ⟨⊗⟩ G₂) LHS⊑RHS I I⊨STA₁A₂ I⊨LHS = (f , I⊨RHS) where f : ((BN F₁ ⊎ BN F₂) ⊕ (IN B₁ ⊎ IN B₂) ⊕ (BN G₁ ⊎ BN G₂)) → Δ ⌊ I ⌋ f (inode (inj₁ v)) = ind I (bnode (inj₁ (inode v))) f (inode (inj₂ v)) = ind I (bnode (inj₂ (inode v))) f (bnode (inj₁ y)) = ind I (bnode (inj₁ (bnode y))) f (bnode (inj₂ y)) = ind I (bnode (inj₂ (bnode y))) f (enode (inj₁ w)) = ind I (bnode (inj₁ (enode w))) f (enode (inj₂ w)) = ind I (bnode (inj₂ (enode w))) Iˡ₁⊨F₁ : up * left * bnodes I f ⊨a impl F₁ Iˡ₁⊨F₁ = ⊨a-resp-≡³ (left * up * I) (on-bnode f (ind I) ∘ left ∘ up) refl (impl F₁) (compose-left F₁ G₁ (up * I) (tensor-up (F₁ ∙ G₁) (F₂ ∙ G₂) I I⊨LHS)) Iˡ₂⊨F₂ : down * (left * bnodes I f) ⊨a impl F₂ Iˡ₂⊨F₂ = ⊨a-resp-≡³ (left * down * I) (on-bnode f (ind I) ∘ left ∘ down) refl (impl F₂) (compose-left F₂ G₂ (down * I) (tensor-down (F₁ ∙ G₁) (F₂ ∙ G₂) I I⊨LHS)) Iʳ₁⊨G₁ : up * (right * bnodes I f) ⊨a impl G₁ Iʳ₁⊨G₁ = ⊨a-resp-≡³ (right * up * I) (on-bnode f (ind I) ∘ right ∘ up) refl (impl G₁) (compose-right F₁ G₁ (up * I) (tensor-up (F₁ ∙ G₁) (F₂ ∙ G₂) I I⊨LHS)) Iʳ₂⊨G₂ : down * (right * bnodes I f) ⊨a impl G₂ Iʳ₂⊨G₂ = ⊨a-resp-≡³ (right * down * I) (on-bnode f (ind I) ∘ right ∘ down) refl (impl G₂) (compose-right F₂ G₂ (down * I) (tensor-down (F₁ ∙ G₁) (F₂ ∙ G₂) I I⊨LHS)) I⊨RHS : bnodes I f ⊨a impl ((F₁ ⟨⊗⟩ F₂) ∙ (G₁ ⟨⊗⟩ G₂)) I⊨RHS = compose-resp-⊨a (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) (bnodes I f) (tensor-resp-⊨a F₁ F₂ (left * bnodes I f) Iˡ₁⊨F₁ Iˡ₂⊨F₂) (tensor-resp-⊨a G₁ G₂ (right * bnodes I f) Iʳ₁⊨G₁ Iʳ₂⊨G₂) RHS⊑LHS : (F₁ ⟨⊗⟩ F₂) ∙ (G₁ ⟨⊗⟩ G₂) ⊑ (F₁ ∙ G₁) ⟨⊗⟩ (F₂ ∙ G₂) RHS⊑LHS I I⊨STA₁A₂ I⊨RHS = (f , I⊨LHS) where f : ((BN F₁ ⊕ IN B₁ ⊕ BN G₁) ⊎ (BN F₂ ⊕ IN B₂ ⊕ BN G₂)) → Δ ⌊ I ⌋ f (inj₁ (inode v)) = ind I (bnode (inode (inj₁ v))) f (inj₁ (bnode y)) = ind I (bnode (bnode (inj₁ y))) f (inj₁ (enode w)) = ind I (bnode (enode (inj₁ w))) f (inj₂ (inode v)) = ind I (bnode (inode (inj₂ v))) f (inj₂ (bnode y)) = ind I (bnode (bnode (inj₂ y))) f (inj₂ (enode w)) = ind I (bnode (enode (inj₂ w))) I₁ˡ⊨F₁ : left * up * bnodes I f ⊨a impl F₁ I₁ˡ⊨F₁ = ⊨a-resp-≡³ (up * left * I) (on-bnode f (ind I) ∘ up ∘ left) refl (impl F₁) (tensor-up F₁ F₂ (left * I) (compose-left (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) I I⊨RHS)) I₁ʳ⊨G₁ : right * up * bnodes I f ⊨a impl G₁ I₁ʳ⊨G₁ = ⊨a-resp-≡³ (up * right * I) (on-bnode f (ind I) ∘ up ∘ right) refl (impl G₁) (tensor-up G₁ G₂ (right * I) (compose-right (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) I I⊨RHS)) I₂ˡ⊨F₂ : left * down * bnodes I f ⊨a impl F₂ I₂ˡ⊨F₂ = ⊨a-resp-≡³ (down * left * I) (on-bnode f (ind I) ∘ down ∘ left) refl (impl F₂) (tensor-down F₁ F₂ (left * I) (compose-left (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) I I⊨RHS)) I₂ʳ⊨G₂ : right * down * bnodes I f ⊨a impl G₂ I₂ʳ⊨G₂ = ⊨a-resp-≡³ (down * right * I) (on-bnode f (ind I) ∘ down ∘ right) refl (impl G₂) (tensor-down G₁ G₂ (right * I) (compose-right (F₁ ⟨⊗⟩ F₂) (G₁ ⟨⊗⟩ G₂) I I⊨RHS)) I⊨LHS : bnodes I f ⊨a impl ((F₁ ∙ G₁) ⟨⊗⟩ (F₂ ∙ G₂)) I⊨LHS = tensor-resp-⊨a (F₁ ∙ G₁) (F₂ ∙ G₂) (bnodes I f) (compose-resp-⊨a F₁ G₁ (up * bnodes I f) I₁ˡ⊨F₁ I₁ʳ⊨G₁) (compose-resp-⊨a F₂ G₂ (down * bnodes I f) I₂ˡ⊨F₂ I₂ʳ⊨G₂)
{ "alphanum_fraction": 0.5656913368, "avg_line_length": 47.1081081081, "ext": "agda", "hexsha": "f75d055a1873f3d879ebda6e32fb15912b83309f", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z", "max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z", "max_forks_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "agda/agda-web-semantic", "max_forks_repo_path": "src/Web/Semantic/DL/Category/Properties/Tensor/Functor.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab", "max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "agda/agda-web-semantic", "max_issues_repo_path": "src/Web/Semantic/DL/Category/Properties/Tensor/Functor.agda", "max_line_length": 85, "max_stars_count": 9, "max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "agda/agda-web-semantic", "max_stars_repo_path": "src/Web/Semantic/DL/Category/Properties/Tensor/Functor.agda", "max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z", "num_tokens": 2592, "size": 5229 }
{-# OPTIONS --without-K --safe #-} module Fragment.Examples.Semigroup.Arith.Reasoning where open import Fragment.Examples.Semigroup.Arith.Base +-direct : ∀ {m n} → (m + 2) + (3 + n) ≡ m + (5 + n) +-direct {m} {n} = begin (m + 2) + (3 + n) ≡⟨ fragment SemigroupFrex +-semigroup ⟩ m + (5 + n) ∎ open import Data.Nat.Properties using (*-distribˡ-+) +-inner : ∀ {m n k} → k * (m + 2) + k * (3 + n) ≡ k * (m + 5 + n) +-inner {m} {n} {k} = begin k * (m + 2) + k * (3 + n) ≡⟨ sym (*-distribˡ-+ k (m + 2) (3 + n)) ⟩ k * ((m + 2) + (3 + n)) ≡⟨ cong (k *_) (fragment SemigroupFrex +-semigroup) ⟩ k * (m + 5 + n) ∎
{ "alphanum_fraction": 0.4945226917, "avg_line_length": 26.625, "ext": "agda", "hexsha": "78dff3e56c95bf806f2d777515da35d2001afd0b", "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/Examples/Semigroup/Arith/Reasoning.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/Examples/Semigroup/Arith/Reasoning.agda", "max_line_length": 65, "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/Examples/Semigroup/Arith/Reasoning.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": 283, "size": 639 }
{-# OPTIONS --allow-unsolved-metas #-} module nfa where -- open import Level renaming ( suc to succ ; zero to Zero ) open import Data.Nat open import Data.List open import Data.Fin hiding ( _<_ ) open import Data.Maybe hiding ( zip ) open import Relation.Nullary open import Data.Empty -- open import Data.Bool using ( Bool ; true ; false ; _∧_ ; _∨_ ) open import Relation.Binary.PropositionalEquality hiding ( [_] ) open import Relation.Nullary using (¬_; Dec; yes; no) open import logic data States1 : Set where sr : States1 ss : States1 st : States1 data In2 : Set where i0 : In2 i1 : In2 record NAutomaton ( Q : Set ) ( Σ : Set ) : Set where field Nδ : Q → Σ → Q → Bool Nend : Q → Bool open NAutomaton LStates1 : List States1 LStates1 = sr ∷ ss ∷ st ∷ [] -- one of qs q is true existsS1 : ( States1 → Bool ) → Bool existsS1 qs = qs sr \/ qs ss \/ qs st -- extract list of q which qs q is true to-listS1 : ( States1 → Bool ) → List States1 to-listS1 qs = ss1 LStates1 where ss1 : List States1 → List States1 ss1 [] = [] ss1 (x ∷ t) with qs x ... | true = x ∷ ss1 t ... | false = ss1 t Nmoves : { Q : Set } { Σ : Set } → NAutomaton Q Σ → (exists : ( Q → Bool ) → Bool) → ( Qs : Q → Bool ) → (s : Σ ) → ( Q → Bool ) Nmoves {Q} { Σ} M exists Qs s = λ q → exists ( λ qn → (Qs qn /\ ( Nδ M qn s q ) )) Naccept : { Q : Set } { Σ : Set } → NAutomaton Q Σ → (exists : ( Q → Bool ) → Bool) → (Nstart : Q → Bool) → List Σ → Bool Naccept M exists sb [] = exists ( λ q → sb q /\ Nend M q ) Naccept M exists sb (i ∷ t ) = Naccept M exists (λ q → exists ( λ qn → (sb qn /\ ( Nδ M qn i q ) ))) t {-# TERMINATING #-} NtraceDepth : { Q : Set } { Σ : Set } → NAutomaton Q Σ → (Nstart : Q → Bool) → List Q → List Σ → List (List ( Σ ∧ Q )) NtraceDepth {Q} {Σ} M sb all is = ndepth all sb is [] [] where ndepth : List Q → (q : Q → Bool ) → List Σ → List ( Σ ∧ Q ) → List (List ( Σ ∧ Q ) ) → List (List ( Σ ∧ Q ) ) ndepth1 : Q → Σ → List Q → List Σ → List ( Σ ∧ Q ) → List ( List ( Σ ∧ Q )) → List ( List ( Σ ∧ Q )) ndepth1 q i [] is t t1 = t1 ndepth1 q i (x ∷ qns) is t t1 = ndepth all (Nδ M x i) is (⟪ i , q ⟫ ∷ t) (ndepth1 q i qns is t t1 ) ndepth [] sb is t t1 = t1 ndepth (q ∷ qs) sb [] t t1 with sb q /\ Nend M q ... | true = ndepth qs sb [] t ( t ∷ t1 ) ... | false = ndepth qs sb [] t t1 ndepth (q ∷ qs) sb (i ∷ is) t t1 with sb q ... | true = ndepth qs sb (i ∷ is) t (ndepth1 q i all is t t1 ) ... | false = ndepth qs sb (i ∷ is) t t1 -- trace in state set -- Ntrace : { Q : Set } { Σ : Set } → NAutomaton Q Σ → (exists : ( Q → Bool ) → Bool) → (to-list : ( Q → Bool ) → List Q ) → (Nstart : Q → Bool) → List Σ → List (List Q) Ntrace M exists to-list sb [] = to-list ( λ q → sb q /\ Nend M q ) ∷ [] Ntrace M exists to-list sb (i ∷ t ) = to-list (λ q → sb q ) ∷ Ntrace M exists to-list (λ q → exists ( λ qn → (sb qn /\ ( Nδ M qn i q ) ))) t data-fin-00 : ( Fin 3 ) → Bool data-fin-00 zero = true data-fin-00 (suc zero) = true data-fin-00 (suc (suc zero)) = true data-fin-00 (suc (suc (suc ()))) data-fin-01 : (x : ℕ ) → x < 3 → Bool data-fin-01 zero lt = true data-fin-01 (suc zero) lt = true data-fin-01 (suc (suc zero)) lt = true data-fin-01 (suc (suc (suc x))) (s≤s (s≤s (s≤s ()))) transition3 : States1 → In2 → States1 → Bool transition3 sr i0 sr = true transition3 sr i1 ss = true transition3 sr i1 sr = true transition3 ss i0 sr = true transition3 ss i1 st = true transition3 st i0 sr = true transition3 st i1 st = true transition3 _ _ _ = false fin1 : States1 → Bool fin1 st = true fin1 ss = false fin1 sr = false test5 = existsS1 (λ q → fin1 q ) test6 = to-listS1 (λ q → fin1 q ) start1 : States1 → Bool start1 sr = true start1 _ = false am2 : NAutomaton States1 In2 am2 = record { Nδ = transition3 ; Nend = fin1} example2-1 = Naccept am2 existsS1 start1 ( i0 ∷ i1 ∷ i0 ∷ [] ) example2-2 = Naccept am2 existsS1 start1 ( i1 ∷ i1 ∷ i1 ∷ [] ) t-1 : List ( List States1 ) t-1 = Ntrace am2 existsS1 to-listS1 start1 ( i1 ∷ i1 ∷ i1 ∷ [] ) -- (sr ∷ []) ∷ (sr ∷ ss ∷ []) ∷ (sr ∷ ss ∷ st ∷ []) ∷ (st ∷ []) ∷ [] t-2 = Ntrace am2 existsS1 to-listS1 start1 ( i0 ∷ i1 ∷ i0 ∷ [] ) -- (sr ∷ []) ∷ (sr ∷ []) ∷ (sr ∷ ss ∷ []) ∷ [] ∷ [] t-3 = NtraceDepth am2 start1 LStates1 ( i1 ∷ i1 ∷ i1 ∷ [] ) t-4 = NtraceDepth am2 start1 LStates1 ( i0 ∷ i1 ∷ i0 ∷ [] ) t-5 = NtraceDepth am2 start1 LStates1 ( i0 ∷ i1 ∷ [] ) transition4 : States1 → In2 → States1 → Bool transition4 sr i0 sr = true transition4 sr i1 ss = true transition4 sr i1 sr = true transition4 ss i0 ss = true transition4 ss i1 st = true transition4 st i0 st = true transition4 st i1 st = true transition4 _ _ _ = false fin4 : States1 → Bool fin4 st = true fin4 _ = false start4 : States1 → Bool start4 ss = true start4 _ = false am4 : NAutomaton States1 In2 am4 = record { Nδ = transition4 ; Nend = fin4} example4-1 = Naccept am4 existsS1 start4 ( i0 ∷ i1 ∷ i1 ∷ i0 ∷ [] ) example4-2 = Naccept am4 existsS1 start4 ( i0 ∷ i1 ∷ i1 ∷ i1 ∷ [] ) fin0 : States1 → Bool fin0 st = false fin0 ss = false fin0 sr = false test0 : Bool test0 = existsS1 fin0 test1 : Bool test1 = existsS1 fin1 test2 = Nmoves am2 existsS1 start1 open import automaton am2def : Automaton (States1 → Bool ) In2 am2def = record { δ = λ qs s q → existsS1 (λ qn → qs q /\ Nδ am2 q s qn ) ; aend = λ qs → existsS1 (λ q → qs q /\ Nend am2 q) } dexample4-1 = accept am2def start1 ( i0 ∷ i1 ∷ i1 ∷ i0 ∷ [] ) texample4-1 = trace am2def start1 ( i0 ∷ i1 ∷ i1 ∷ i0 ∷ [] ) -- LStates1 contains all states in States1 -- a list of Q contains (q : Q) eqState1? : (x y : States1) → Dec ( x ≡ y ) eqState1? sr sr = yes refl eqState1? ss ss = yes refl eqState1? st st = yes refl eqState1? sr ss = no (λ ()) eqState1? sr st = no (λ ()) eqState1? ss sr = no (λ ()) eqState1? ss st = no (λ ()) eqState1? st sr = no (λ ()) eqState1? st ss = no (λ ()) list-contains : {Q : Set} → ( (x y : Q ) → Dec ( x ≡ y ) ) → (qs : List Q) → (q : Q ) → Bool list-contains {Q} eq? [] q = false list-contains {Q} eq? (x ∷ qs) q with eq? x q ... | yes _ = true ... | no _ = list-contains eq? qs q containsP : {Q : Set} → ( eq? : (x y : Q ) → Dec ( x ≡ y )) → (qs : List Q) → (q : Q ) → Set containsP eq? qs q = list-contains eq? qs q ≡ true contains-all : (q : States1 ) → containsP eqState1? LStates1 q contains-all sr = refl contains-all ss = refl contains-all st = refl -- foldr : (A → B → B) → B → List A → B -- foldr c n [] = n -- foldr c n (x ∷ xs) = c x (foldr c n xs) ssQ : {Q : Set } ( qs : Q → Bool ) → List Q → List Q ssQ qs [] = [] ssQ qs (x ∷ t) with qs x ... | true = x ∷ ssQ qs t ... | false = ssQ qs t bool-t1 : {b : Bool } → b ≡ true → (true /\ b) ≡ true bool-t1 refl = refl bool-1t : {b : Bool } → b ≡ true → (b /\ true) ≡ true bool-1t refl = refl to-list1 : {Q : Set } (qs : Q → Bool ) → (all : List Q) → foldr (λ q x → qs q /\ x ) true (ssQ qs all ) ≡ true to-list1 qs [] = refl to-list1 qs (x ∷ all) with qs x | inspect qs x ... | false | record { eq = eq } = to-list1 qs all ... | true | record { eq = eq } = subst (λ k → k /\ foldr (λ q → _/\_ (qs q)) true (ssQ qs all) ≡ true ) (sym eq) ( bool-t1 (to-list1 qs all) ) existsS1-valid : ¬ ( (qs : States1 → Bool ) → ( existsS1 qs ≡ true ) ) existsS1-valid n = ¬-bool refl ( n ( λ x → false )) -- -- using finiteSet -- open import finiteSet open import finiteSetUtil open FiniteSet allQ : {Q : Set } (finq : FiniteSet Q) → List Q allQ {Q} finq = to-list finq (λ x → true) existQ : {Q : Set } (finq : FiniteSet Q) → (Q → Bool) → Bool existQ finq qs = exists finq qs eqQ? : {Q : Set } (finq : FiniteSet Q) → (x y : Q ) → Bool eqQ? finq x y = equal? finq x y finState1 : FiniteSet States1 finState1 = record { finite = finite0 ; Q←F = Q←F0 ; F←Q = F←Q0 ; finiso→ = finiso→0 ; finiso← = finiso←0 } where finite0 : ℕ finite0 = 3 Q←F0 : Fin finite0 → States1 Q←F0 zero = sr Q←F0 (suc zero) = ss Q←F0 (suc (suc zero)) = st F←Q0 : States1 → Fin finite0 F←Q0 sr = # 0 F←Q0 ss = # 1 F←Q0 st = # 2 finiso→0 : (q : States1) → Q←F0 ( F←Q0 q ) ≡ q finiso→0 sr = refl finiso→0 ss = refl finiso→0 st = refl finiso←0 : (f : Fin finite0 ) → F←Q0 ( Q←F0 f ) ≡ f finiso←0 zero = refl finiso←0 (suc zero) = refl finiso←0 (suc (suc zero)) = refl
{ "alphanum_fraction": 0.553344968, "avg_line_length": 30.264084507, "ext": "agda", "hexsha": "e0722ee099321de88e19bbc57b9e32737a9a347f", "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": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "shinji-kono/automaton-in-agda", "max_forks_repo_path": "src/nfa.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "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": "shinji-kono/automaton-in-agda", "max_issues_repo_path": "src/nfa.agda", "max_line_length": 144, "max_stars_count": null, "max_stars_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "shinji-kono/automaton-in-agda", "max_stars_repo_path": "src/nfa.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3481, "size": 8595 }
module Acme.Type where open import Agda.Builtin.Bool using (Bool; true; false) public open import Agda.Builtin.Char using (Char) renaming (primCharEquality to _==_) public open import Agda.Builtin.Equality using (_≡_; refl) public open import Agda.Builtin.List using (List; []; _∷_) public open import Agda.Builtin.String using (String) renaming (primStringToList to unpack) public open import Agda.Builtin.Unit using (⊤; tt) public open import Agda.Builtin.TrustMe using () renaming (primTrustMe to trustMe) public Type : Set Type = List Char → Bool data ⊥ : Set where IsTrue : Bool → Set IsTrue true = ⊤ IsTrue false = ⊥ _∈_ : List Char → Type → Set x ∈ A = IsTrue (A x) record Elt (A : Type) : Set where constructor [_] field value : List Char @0 {{check}} : value ∈ A open Elt public infix 100 _∋_ _∋_ : (A : Type) (str : String) → {{unpack str ∈ A}} → Elt A A ∋ str = record { value = unpack str } infixr 3 _&&_ _&&_ : Bool → Bool → Bool true && b = b false && b = false infixr 2 _||_ _||_ : Bool → Bool → Bool true || b = true false || b = b isNil : List Char → Bool isNil [] = true isNil _ = false data Reflects (a : Char) : Char → Bool → Set where true : Reflects a a true false : ∀ {b} → Reflects a b false mkTrue : ∀ {a b} → a ≡ b → Reflects a b true mkTrue refl = true _≟_ : (a b : Char) → Reflects a b (a == b) a ≟ b with a == b ... | false = false ... | true = mkTrue trustMe private variable A B : Set x y z : A cong : (f : A → B) → x ≡ y → f x ≡ f y cong f refl = refl sym : x ≡ y → y ≡ x sym refl = refl trans : x ≡ y → y ≡ z → x ≡ z trans refl eq = eq
{ "alphanum_fraction": 0.6242312423, "avg_line_length": 21.1168831169, "ext": "agda", "hexsha": "e6cbf5cba42380d1e7f15f1aed8be3786e3f2d3d", "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": "9e83fe708271b4437ae4e259175397d96d10aaf6", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "gallais/STRINaGda", "max_forks_repo_path": "src/Acme/Type.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9e83fe708271b4437ae4e259175397d96d10aaf6", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "gallais/STRINaGda", "max_issues_repo_path": "src/Acme/Type.agda", "max_line_length": 62, "max_stars_count": 2, "max_stars_repo_head_hexsha": "9e83fe708271b4437ae4e259175397d96d10aaf6", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "gallais/STRINaGda", "max_stars_repo_path": "src/Acme/Type.agda", "max_stars_repo_stars_event_max_datetime": "2021-04-01T20:56:37.000Z", "max_stars_repo_stars_event_min_datetime": "2018-02-14T22:26:17.000Z", "num_tokens": 571, "size": 1626 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Indexed binary relations ------------------------------------------------------------------------ -- The contents of this module should be accessed via -- `Relation.Binary.Indexed.Heterogeneous`. {-# OPTIONS --without-K --safe #-} module Relation.Binary.Indexed.Heterogeneous.Bundles where open import Function.Base open import Level using (suc; _⊔_) open import Relation.Binary using (_⇒_) open import Relation.Binary.PropositionalEquality.Core as P using (_≡_) open import Relation.Binary.Indexed.Heterogeneous.Core open import Relation.Binary.Indexed.Heterogeneous.Structures ------------------------------------------------------------------------ -- Definitions record IndexedSetoid {i} (I : Set i) c ℓ : Set (suc (i ⊔ c ⊔ ℓ)) where infix 4 _≈_ field Carrier : I → Set c _≈_ : IRel Carrier ℓ isEquivalence : IsIndexedEquivalence Carrier _≈_ open IsIndexedEquivalence isEquivalence public record IndexedPreorder {i} (I : Set i) c ℓ₁ ℓ₂ : Set (suc (i ⊔ c ⊔ ℓ₁ ⊔ ℓ₂)) where infix 4 _≈_ _∼_ field Carrier : I → Set c _≈_ : IRel Carrier ℓ₁ -- The underlying equality. _∼_ : IRel Carrier ℓ₂ -- The relation. isPreorder : IsIndexedPreorder Carrier _≈_ _∼_ open IsIndexedPreorder isPreorder public
{ "alphanum_fraction": 0.5804394047, "avg_line_length": 32.0681818182, "ext": "agda", "hexsha": "18d191506468614764f4a732b931cedae7755786", "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/Indexed/Heterogeneous/Bundles.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/Indexed/Heterogeneous/Bundles.agda", "max_line_length": 72, "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/Indexed/Heterogeneous/Bundles.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": 355, "size": 1411 }
-- Partly based on code due to Andrea Vezzosi. {-# OPTIONS --cubical-compatible --safe #-} open import Agda.Builtin.Bool data D : Set where run-time : Bool → D @0 compile-time : Bool → D g : D → D g (run-time x) = run-time x g (compile-time x) = compile-time x h : D → @0 D → D h (run-time x) _ = run-time x h (compile-time x) (run-time y) = compile-time y h (compile-time x) (compile-time y) = compile-time x i : @0 D → D → D i _ (run-time y) = run-time y i (run-time x) (compile-time y) = compile-time x i (compile-time x) (compile-time y) = compile-time y data E (@0 A : Set) : Set where c₁ c₂ : E A @0 c₃ : A → E A m : {@0 A : Set} → @0 A → E A → E A m _ c₁ = c₂ m _ c₂ = c₁ m x (c₃ _) = c₃ x
{ "alphanum_fraction": 0.5437017995, "avg_line_length": 23.5757575758, "ext": "agda", "hexsha": "b666dd0a11beaf079c1a066ac364a6e6659d77ba", "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/Succeed/Issue4638.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/Succeed/Issue4638.agda", "max_line_length": 52, "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/Succeed/Issue4638.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 283, "size": 778 }
open import Agda.Builtin.Unit open import Agda.Builtin.List open import Agda.Builtin.Reflection postulate foo : Set macro bar : Term → TC ⊤ bar = unify (def (quote foo) []) test : Set test = {!bar!}
{ "alphanum_fraction": 0.6842105263, "avg_line_length": 13.9333333333, "ext": "agda", "hexsha": "b8fd6e3ade48f484623700d7280f70f4f0e2da19", "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": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "shlevy/agda", "max_forks_repo_path": "test/interaction/Issue4975.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/interaction/Issue4975.agda", "max_line_length": 35, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/interaction/Issue4975.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": 65, "size": 209 }
{-# OPTIONS --warning=error --safe --without-K #-} open import LogicalFormulae open import Categories.Definition module Categories.Dual.Definition where dual : {a b : _} → Category {a} {b} → Category {a} {b} dual record { objects = objects ; arrows = arrows ; id = id ; _∘_ = _∘_ ; rightId = rightId ; leftId = leftId ; compositionAssociative = associative } = record { objects = objects ; arrows = λ i j → arrows j i ; id = id ; _∘_ = λ {x y z} g f → f ∘ g ; rightId = λ {x y} f → leftId f ; leftId = λ {x y} f → rightId f ; compositionAssociative = λ {x y z w} f g h → equalityCommutative (associative h g f) }
{ "alphanum_fraction": 0.650974026, "avg_line_length": 61.6, "ext": "agda", "hexsha": "73a79940180de61ed83db1c1738d8dd5b452813d", "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": "Categories/Dual/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": "Categories/Dual/Definition.agda", "max_line_length": 404, "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": "Categories/Dual/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": 196, "size": 616 }
--------------------------------------------- -- Consequences of the axiom of regularity --------------------------------------------- {-# OPTIONS --allow-unsolved-meta #-} module sv20.assign2.SetTheory.Regularity where open import sv20.assign2.SetTheory.Logic open import sv20.assign2.SetTheory.Algebra open import sv20.assign2.SetTheory.Subset open import sv20.assign2.SetTheory.ZAxioms open import sv20.assign2.SetTheory.Pairs -- Theorem 105, p. 54 A∉A : (A : 𝓢) → A ∉ A A∉A A h = cont _ (p₄ , notEmpty) where A∈Aₛ : A ∈ singleton A A∈Aₛ = singletonp₂ A A∈Aₛ∩A : A ∈ (singleton A ∩ A) A∈Aₛ∩A = ∩-d₂ _ _ _ (A∈Aₛ , h) notEmpty : (singleton A ∩ A) ≢ ∅ notEmpty = prop-∅ A _ A∈Aₛ∩A Aₛ≢∅ : singleton A ≢ ∅ Aₛ≢∅ x = prop-∅ _ _ A∈Aₛ x reg-step : ∃ (λ x → x ∈ singleton A ∧ ((y : 𝓢) → y ∈ x → y ∉ singleton A)) reg-step = reg (singleton A) Aₛ≢∅ aux : 𝓢 aux = proj₁ reg-step aux-p : aux ∈ singleton A ∧ ((y : 𝓢) → y ∈ aux → y ∉ singleton A) aux-p = proj₂ _ reg-step p : aux ∈ singleton A p = ∧-proj₁ aux-p aux∈auxₛ : aux ∈ singleton aux aux∈auxₛ = singletonp₂ aux prop : A ∈ singleton aux → A ∩ singleton aux ≡ ∅ prop = singletonp₄ A aux prop₂ : aux ≡ A prop₂ = singletonp _ p imp : A ∩ singleton aux ≡ ∅ imp = prop (subs (λ w → w ∈ singleton aux) (prop₂) aux∈auxₛ) p₃ : singleton aux ∩ A ≡ ∅ p₃ = subs (λ w → w ≡ ∅) (∩-sym _ _) imp p₄ : singleton A ∩ A ≡ ∅ p₄ = subs (λ w → singleton w ∩ A ≡ ∅) prop₂ p₃ reg-cons : (A B : 𝓢) → ¬ (A ∈ B ∧ B ∈ A) reg-cons A B h = {!!} where p₁ : A ∈ A ₚ B p₁ = pair-d₂ _ _ (inj₁ refl) p₂ : A ∈ B p₂ = ∧-proj₁ h p₃ : A ∈ A ₚ B ∩ B p₃ = ∩-d₂ _ _ _ (p₁ , p₂) p₄ : (A ₚ B) ≢ ∅ p₄ = prop-∅ _ _ p₁ reg-step : ∃ (λ x → x ∈ A ₚ B ∧ ((y : 𝓢) → y ∈ x → y ∉ A ₚ B)) reg-step = {!!} x : 𝓢 x = proj₁ reg-step x-p : x ∈ A ₚ B ∧ ((y : 𝓢) → y ∈ x → y ∉ A ₚ B) x-p = proj₂ _ reg-step p₆ : (A ₚ B ∩ x) ≡ ∅ p₆ = {!!} p₇ : x ∈ A ₚ B p₇ = ∧-proj₁ x-p p₈ : x ≡ A ∨ x ≡ B p₈ = pair-d₁ _ _ p₇ -- 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.5374059318, "avg_line_length": 22.3663366337, "ext": "agda", "hexsha": "6cc41f060d6a5a0ab9cebc8fd594bd6535e72c73", "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/Regularity.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/Regularity.agda", "max_line_length": 76, "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/Regularity.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 991, "size": 2259 }
module FFI.Data.Scientific where {-# FOREIGN GHC import qualified Data.Scientific #-} postulate Scientific : Set {-# COMPILE GHC Scientific = type Data.Scientific.Scientific #-}
{ "alphanum_fraction": 0.7611111111, "avg_line_length": 25.7142857143, "ext": "agda", "hexsha": "8a5be39e2228116d54f50c827126469be3deeebd", "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/FFI/Data/Scientific.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/FFI/Data/Scientific.agda", "max_line_length": 64, "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/FFI/Data/Scientific.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": 40, "size": 180 }
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics open import lib.NType2 open import lib.types.Int open import lib.types.Group open import lib.types.List open import lib.types.Word open import lib.groups.Homomorphism open import lib.groups.Isomorphism open import lib.groups.FreeAbelianGroup open import lib.types.SetQuotient module lib.groups.Int where ℤ-group-structure : GroupStructure ℤ ℤ-group-structure = record { ident = 0 ; inv = ℤ~ ; comp = _ℤ+_ ; unit-l = ℤ+-unit-l ; assoc = ℤ+-assoc ; inv-l = ℤ~-inv-l } ℤ-group : Group₀ ℤ-group = group _ ℤ-group-structure ℤ-group-is-abelian : is-abelian ℤ-group ℤ-group-is-abelian = ℤ+-comm ℤ-abgroup : AbGroup₀ ℤ-abgroup = ℤ-group , ℤ-group-is-abelian ℤ-iso-FreeAbGroup-Unit : ℤ-group ≃ᴳ FreeAbGroup.grp Unit ℤ-iso-FreeAbGroup-Unit = ≃-to-≃ᴳ (equiv to from to-from from-to) to-pres-comp where to = FreeAbGroup.exp Unit fs[ inl unit :: nil ] from = FormalSum-extend ℤ-abgroup (λ _ → 1) abstract to-pres-comp = FreeAbGroup.exp-+ Unit fs[ inl unit :: nil ] to-from' : ∀ l → to (Word-extendᴳ ℤ-group (λ _ → 1) l) == fs[ l ] to-from' nil = idp to-from' (inl unit :: l) = FreeAbGroup.exp-succ Unit fs[ inl unit :: nil ] (Word-extendᴳ ℤ-group (λ _ → 1) l) ∙ ap (FreeAbGroup.comp Unit fs[ inl unit :: nil ]) (to-from' l) to-from' (inr unit :: l) = FreeAbGroup.exp-pred Unit fs[ inl unit :: nil ] (Word-extendᴳ ℤ-group (λ _ → 1) l) ∙ ap (FreeAbGroup.comp Unit fs[ inr unit :: nil ]) (to-from' l) to-from : ∀ fs → to (from fs) == fs to-from = FormalSum-elim to-from' (λ _ → prop-has-all-paths-↓) from-to : ∀ z → from (to z) == z from-to (pos 0) = idp from-to (pos 1) = idp from-to (negsucc 0) = idp from-to (pos (S (S n))) = GroupHom.pres-comp (FreeAbGroup-extend ℤ-abgroup (λ _ → 1)) fs[ inl unit :: nil ] (FreeAbGroup.exp Unit fs[ inl unit :: nil ] (pos (S n))) ∙ ap succ (from-to (pos (S n))) from-to (negsucc (S n)) = GroupHom.pres-comp (FreeAbGroup-extend ℤ-abgroup (λ _ → 1)) fs[ inr unit :: nil ] (FreeAbGroup.exp Unit fs[ inl unit :: nil ] (negsucc n)) ∙ ap pred (from-to (negsucc n)) exp-shom : ∀ {i} {GEl : Type i} (GS : GroupStructure GEl) (g : GEl) → ℤ-group-structure →ᴳˢ GS exp-shom GS g = group-structure-hom (GroupStructure.exp GS g) (GroupStructure.exp-+ GS g) exp-hom : ∀ {i} (G : Group i) (g : Group.El G) → ℤ-group →ᴳ G exp-hom G g = group-hom (Group.exp G g) (Group.exp-+ G g)
{ "alphanum_fraction": 0.6245516142, "avg_line_length": 34.8472222222, "ext": "agda", "hexsha": "766f557ef827300a5854fa3e2d572d9d0c2af7d6", "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": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "timjb/HoTT-Agda", "max_forks_repo_path": "core/lib/groups/Int.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "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": "timjb/HoTT-Agda", "max_issues_repo_path": "core/lib/groups/Int.agda", "max_line_length": 94, "max_stars_count": null, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "core/lib/groups/Int.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 900, "size": 2509 }
import cedille-options open import general-util module untyped-spans (options : cedille-options.options) {F : Set → Set} ⦃ monadF : monad F ⦄ where open import ctxt open import cedille-types open import constants open import conversion open import free-vars open import rename open import spans options {F} ⦃ monadF ⦄ open import subst open import syntax-util open import to-string options open import type-util open import elab-util options {-# TERMINATING #-} untyped-term : ctxt → ex-tm → spanM term untyped-type : ctxt → ex-tp → spanM type untyped-kind : ctxt → ex-kd → spanM kind untyped-tpkd : ctxt → ex-tk → spanM tpkd untyped-arg : ctxt → ex-arg → spanM arg untyped-args : ctxt → ex-args → spanM args untyped-let : ctxt → ex-def → erased? → posinfo → posinfo → spanM (ctxt × var × tagged-val × (∀ {ed : exprd} → ⟦ ed ⟧ → ⟦ ed ⟧) × (term → term)) untyped-cases : ctxt → ex-cases → renamectxt → spanM cases untyped-case : ctxt → ex-case → (siblings : ℕ) → (ℕ → err-m) → renamectxt → spanM (case × (ℕ → err-m) × maybe ℕ) untyped-let Γ (ExDefTerm pi x Tₑ? t) e? fm to = maybe-map (untyped-type Γ) Tₑ? >>=? λ Tₑ?~ → untyped-term Γ t >>= λ t~ → elim-pair (compileFail-in Γ t~) λ tvs e → let Tₑ~ = maybe-else' Tₑ?~ (TpHole pi) id in [- Var-span (Γ , pi - x :` Tkt Tₑ~) pi x untyped tvs e -] return (ctxt-term-def pi localScope opacity-open x (just t~) Tₑ~ Γ , pi % x , binder-data Γ pi x (Tkt Tₑ~) e? (just t~) fm to , (λ {ed} T' → [ Γ - t~ / (pi % x) ] T') , (λ t' → LetTm e? x nothing t~ ([ Γ - Var x / (pi % x) ] t'))) untyped-let Γ (ExDefType pi x k T) e? fm to = untyped-kind Γ k >>= λ k~ → untyped-type Γ T >>= λ T~ → [- TpVar-span (Γ , pi - x :` Tkk k~) pi x untyped [] nothing -] return (ctxt-type-def pi localScope opacity-open x (just T~) k~ Γ , pi % x , binder-data Γ pi x (Tkk k~) e? (just T~) fm to , (λ {ed} T' → [ Γ - T~ / (pi % x) ] T') , (λ t' → LetTp x k~ T~ ([ Γ - TpVar x / (pi % x) ] t'))) untyped-term Γ (ExApp t e t') = [- App-span tt (term-start-pos t) (term-end-pos t') untyped [] nothing -] untyped-term Γ t >>= λ t~ → untyped-term Γ t' >>= λ t'~ → return (if e then t~ else App t~ t'~) untyped-term Γ (ExAppTp t T) = [- AppTp-span tt (term-start-pos t) (type-end-pos T) untyped [] nothing -] untyped-type Γ T >>= λ T~ → untyped-term Γ t untyped-term Γ (ExBeta pi t? t?') = maybe-map (λ {(PosTm t pi) → untyped-term Γ t}) t? >>=? λ t?~ → maybe-map (λ {(PosTm t pi) → untyped-term Γ t}) t?' >>=? λ t?'~ → [- Beta-span pi (term-end-pos (ExBeta pi t? t?')) untyped [] nothing -] return (maybe-else' t?'~ id-term id) untyped-term Γ (ExChi pi T? t) = maybe-map (untyped-type Γ) T? >>=? λ T?~ → [- Chi-span Γ pi T?~ t untyped [] nothing -] untyped-term Γ t untyped-term Γ (ExDelta pi T? t) = [- Delta-span pi t untyped [] nothing -] maybe-map (untyped-type Γ) T? >>=? λ T?~ → untyped-term Γ t >>= λ t~ → return id-term untyped-term Γ (ExEpsilon pi lr -? t) = [- Epsilon-span pi lr -? t untyped [] nothing -] untyped-term Γ t untyped-term Γ (ExHole pi) = [- hole-span Γ pi nothing untyped [] -] return (Hole pi) untyped-term Γ (ExIotaPair pi t₁ t₂ Tₘ? pi') = let tv-f = λ {(ExGuide pi'' x Tₘ) → [ binder-data Γ pi'' x (Tkt (TpHole pi'')) ff nothing (type-start-pos Tₘ) (type-end-pos Tₘ) ]} in [- IotaPair-span pi pi' untyped (maybe-else' Tₘ? [] tv-f) nothing -] untyped-term Γ t₁ >>= λ t₁~ → untyped-term Γ t₂ >>= λ t₂~ → maybe-map (λ {(ExGuide pi'' x Tₘ) → untyped-type (ctxt-term-decl pi'' x (TpHole pi'') Γ) Tₘ}) Tₘ? >>=? λ Tₘ?~ → return t₁~ untyped-term Γ (ExIotaProj t n pi) = [- IotaProj-span t pi untyped [] nothing -] untyped-term Γ t untyped-term Γ (ExLam pi e pi' x tk? t) = (return tk? on-fail return (Tkt (TpHole pi')) >>=m untyped-tpkd Γ) >>= λ tk~ → untyped-term (Γ , pi' - x :` tk~) t >>= λ t~ → let eₖ? = tk? >>= λ _ → ifMaybej (tk-is-type tk~ && ~ e) "λ-terms must bind a term, not a type (use Λ instead)" eₑ? = ifMaybej (e && is-free-in (pi' % x) (erase t~)) "The Λ-bound variable occurs free in the erasure of the body" in [- var-span e (Γ , pi' - x :` tk~) pi' x untyped tk~ eₑ? -] [- Lam-span Γ untyped pi pi' e x tk~ t [] eₖ? -] return (if e then t~ else Lam ff x nothing ([ Γ - Var x / (pi' % x) ] t~)) untyped-term Γ (ExLet pi e? d t) = untyped-let Γ d e? (term-start-pos t) (term-end-pos t) >>= λ where (Γ' , x , tv , σ , f) → untyped-term Γ' t >>= λ t~ → [- punctuation-span "Parens (let)" pi (term-end-pos t) -] [- Let-span e? pi (term-end-pos t) untyped [] (ifMaybej (e? && is-free-in x t~) (unqual-local x ^ "occurs free in the body of the term")) -] return (if is-free-in x t~ then f t~ else t~) untyped-term Γ (ExOpen pi o pi' x t) = [- Var-span Γ pi' x untyped [ not-for-navigation ] nothing -] [- Open-span o pi x t untyped [] nothing -] untyped-term Γ t untyped-term Γ (ExParens pi t pi') = [- punctuation-span "Parens (term)" pi pi' -] untyped-term Γ t untyped-term Γ (ExPhi pi t₌ t₁ t₂ pi') = [- Phi-span pi pi' untyped [] nothing -] untyped-term Γ t₌ >> untyped-term Γ t₁ >> untyped-term Γ t₂ untyped-term Γ (ExRho pi ρ+? ρ<ns>? t₌ Tₘ? t) = [- Rho-span pi t₌ t untyped ρ+? (maybe-else' Tₘ? (inj₁ 1) λ {(ExGuide pi' x Tₘ) → inj₂ x}) [] nothing -] untyped-term Γ t₌ >> maybe-map (λ {(ExGuide pi' x Tₘ) → untyped-type (ctxt-var-decl-loc pi' x Γ) Tₘ}) Tₘ? >>=? λ Tₘ?~ → untyped-term Γ t untyped-term Γ (ExVarSigma pi t) = [- VarSigma-span pi t untyped [] nothing -] untyped-term Γ t untyped-term Γ (ExTheta pi θ t ts) = [- Theta-span Γ pi θ t ts untyped [] nothing -] untyped-term Γ t >>= λ t~ → untyped-args Γ (map (λ {(Lterm e t) → ExTmArg e t}) ts) >>= λ as~ → return (recompose-apps (map Arg (erase-args as~)) t~) untyped-term Γ (ExMu pi pi''' x t Tₘ? pi' ms pi'') = untyped-term Γ t >>= λ t~ → maybe-map (untyped-type Γ) Tₘ? >>=? λ Tₘ~? → [- Var-span Γ pi''' x untyped [] nothing -] let Γ' = ctxt-term-decl pi''' x (TpHole pi''') Γ ρ = renamectxt-single (pi''' % x) x tvs = [ binder-data Γ' pi''' x (Tkt (TpHole pi''')) ff nothing pi' pi'' ] in untyped-cases Γ' ms ρ >>= λ ms~ → -- Make sure we aren't matching upon a "False" datatype (e.g., one -- with no constructors) before any datatypes have been declared maybe-else' (head2 (trie-mappings (ctxt.μ Γ))) ([- Mu-span Γ pi pi'' Tₘ~? untyped tvs (just "No datatypes have been declared yet") -] return (Hole pi)) λ where (Dₓ , ps , kᵢ , k , cs , eds , ecs) → [- Mu-span Γ pi pi'' Tₘ~? untyped tvs nothing -] return (Mu x t~ nothing (mk-data-info Dₓ Dₓ (params-to-args ps) [] ps kᵢ k cs cs eds ecs) ms~) untyped-term Γ (ExSigma pi t? t Tₘ? pi' ms pi'') = untyped-term Γ t >>= λ t~ → maybe-map (untyped-type Γ) Tₘ? >>=? λ Tₘ~? → maybe-map (untyped-term Γ) t? >>=? λ t~? → let ρ = empty-renamectxt μ~ = t~? tvs = [] in untyped-cases Γ ms ρ >>= λ ms~ → -- Make sure we aren't matching upon a "False" datatype (e.g., one -- with no constructors) before any datatypes have been declared maybe-else' (head2 (trie-mappings (ctxt.μ Γ))) ([- Mu-span Γ pi pi'' Tₘ~? untyped tvs (just "No datatypes have been declared yet") -] return (Hole pi)) λ where (Dₓ , ps , kᵢ , k , cs , eds , ecs) → [- Mu-span Γ pi pi'' Tₘ~? untyped tvs nothing -] return (Sigma μ~ t~ nothing (mk-data-info Dₓ Dₓ (params-to-args ps) [] ps kᵢ k cs cs eds ecs) ms~) -- x untyped-term Γ (ExVar pi x) = maybe-else' (ctxt-binds-term-var Γ x) ([- Var-span Γ pi x untyped [] (just "Not a term variable") -] return (Var x)) λ {(qx , as) → [- Var-span Γ pi x untyped [] nothing -] return (recompose-apps (map Arg (erase-args as)) (Var qx))} -- ∀/Π x : tk. T untyped-type Γ (ExTpAbs pi e pi' x tk T) = untyped-tpkd Γ tk >>= λ tk~ → untyped-type (Γ , pi' - x :` tk~) T >>= λ T~ → let T~ = rename-var Γ (pi' % x) x T~ in [- punctuation-span "Forall" pi (posinfo-plus pi 1) -] [- var-span e (Γ , pi' - x :` tk~) pi' x untyped tk~ nothing -] [- TpQuant-span Γ e pi pi' x tk~ T untyped [] nothing -] return (TpAbs e x tk~ T~) -- ι x : T₁. T₂ untyped-type Γ (ExTpIota pi pi' x T₁ T₂) = untyped-type Γ T₁ >>= λ T₁~ → untyped-type (Γ , pi' - x :` Tkt T₁~) T₂ >>= λ T₂~ → let T₂~ = rename-var Γ (pi' % x) x T₂~ in [- punctuation-span "Forall" pi (posinfo-plus pi 1) -] [- var-span ff (Γ , pi' - x :` Tkt T₁~) pi' x untyped (Tkt T₁~) nothing -] [- Iota-span Γ pi pi' x T₂~ T₂ untyped [] nothing -] return (TpIota x T₁~ T₂~) -- {^ T ^} (generated by theta) untyped-type Γ (ExTpNoSpans T pi) = untyped-type Γ T >>=spand return -- [d] - T untyped-type Γ (ExTpLet pi d T) = untyped-let Γ d ff (type-start-pos T) (type-end-pos T) >>= λ where (Γ' , x , tv , σ , f) → untyped-type Γ' T >>= λ T~ → [- punctuation-span "Parens (let)" pi (type-end-pos T) -] [- TpLet-span pi (type-end-pos T) untyped [ tv ] -] return (σ T~) -- T · T' untyped-type Γ (ExTpApp T T') = untyped-type Γ T >>= λ T~ → untyped-type Γ T' >>= λ T'~ → [- TpApp-span (type-start-pos T) (type-end-pos T) untyped [] nothing -] return (TpAppTp T~ T'~) -- T t untyped-type Γ (ExTpAppt T t) = untyped-type Γ T >>= λ T~ → untyped-term Γ t >>= λ t~ → [- TpAppt-span (type-start-pos T) (term-end-pos t) untyped [] nothing -] return (TpAppTm T~ t~) -- T ➔/➾ T' untyped-type Γ (ExTpArrow T e T') = untyped-type Γ T >>= λ T~ → untyped-type Γ T' >>= λ T'~ → [- TpArrow-span T T' untyped [] nothing -] return (TpAbs e ignored-var (Tkt T~) T'~) -- { t₁ ≃ t₂ } untyped-type Γ (ExTpEq pi t₁ t₂ pi') = untyped-term Γ t₁ >>= λ t₁~ → untyped-term Γ t₂ >>= λ t₂~ → [- punctuation-span "Parens (equation)" pi pi' -] [- TpEq-span pi pi' untyped [] nothing -] return (TpEq t₁~ t₂~) -- ● untyped-type Γ (ExTpHole pi) = [- tp-hole-span Γ pi nothing untyped [] -] return (TpHole pi) -- λ x : tk. T untyped-type Γ (ExTpLam pi pi' x tk T) = untyped-tpkd Γ tk >>= λ tk~ → untyped-type (Γ , pi' - x :` tk~) T >>= λ T~ → [- punctuation-span "Lambda (type)" pi (posinfo-plus pi 1) -] [- var-span ff (Γ , pi' - x :` tk~) pi' x untyped tk~ nothing -] [- TpLambda-span Γ pi pi' x tk~ T untyped [] nothing -] return (TpLam x tk~ (rename-var Γ (pi' % x) x T~)) -- (T) untyped-type Γ (ExTpParens pi T pi') = [- punctuation-span "Parens (type)" pi pi' -] untyped-type Γ T -- x untyped-type Γ (ExTpVar pi x) = maybe-else' (ctxt-binds-type-var Γ x) ([- TpVar-span Γ pi x untyped [] (just "Undefined type variable") -] return (TpVar x)) λ {(qx , as) → [- TpVar-span Γ pi x untyped [] nothing -] return (apps-type (TpVar qx) (erase-args-keep as))} -- Π x : tk. k untyped-kind Γ (ExKdAbs pi pi' x tk k) = untyped-tpkd Γ tk >>= λ tk~ → untyped-kind (Γ , pi' - x :` tk~) k >>= λ k~ → [- KdAbs-span Γ pi pi' x tk~ k untyped nothing -] [- var-span ff (Γ , pi' - x :` tk~) pi' x untyped tk~ nothing -] [- punctuation-span "Pi (kind)" pi (posinfo-plus pi 1) -] return (KdAbs x tk~ (rename-var Γ (pi' % x) x k~)) -- tk ➔ k untyped-kind Γ (ExKdArrow tk k) = untyped-tpkd Γ tk >>= λ tk~ → untyped-kind Γ k >>= λ k~ → [- KdArrow-span tk k untyped nothing -] return (KdAbs ignored-var tk~ k~) -- ● untyped-kind Γ (ExKdHole pi) = [- kd-hole-span pi untyped -] return (KdHole pi) -- (k) untyped-kind Γ (ExKdParens pi k pi') = [- punctuation-span "Parens (kind)" pi pi' -] untyped-kind Γ k -- ★ untyped-kind Γ (ExKdStar pi) = [- Star-span pi untyped nothing -] return KdStar -- κ as... untyped-kind Γ (ExKdVar pi κ as) = case ctxt-lookup-kind-var-def Γ κ of λ where nothing → [- KdVar-span Γ (pi , κ) (args-end-pos (posinfo-plus-str pi κ) as) [] untyped [] (just "Undefined kind variable") -] return (KdHole pi) (just (ps , k)) → untyped-args Γ as >>= λ as~ → [- KdVar-span Γ (pi , κ) (args-end-pos (posinfo-plus-str pi κ) as) ps untyped (params-data Γ ps) (unless (length as =ℕ length ps) ("Expected " ^ ℕ-to-string (length ps) ^ " argument" ^ (if length ps =ℕ 1 then "" else "s") ^ ", but got " ^ ℕ-to-string (length as))) -] return (fst (subst-params-args' Γ ps as~ k)) untyped-arg Γ (ExTmArg ff t) = inj₁ <$> untyped-term Γ t untyped-arg Γ (ExTmArg tt t) = (inj₂ ∘ inj₁) <$> untyped-term Γ t untyped-arg Γ (ExTpArg T) = (inj₂ ∘ inj₂) <$> untyped-type Γ T untyped-args Γ = sequenceA ∘ map (untyped-arg Γ) untyped-tpkd Γ (ExTkt T) = Tkt <$> untyped-type Γ T untyped-tpkd Γ (ExTkk k) = Tkk <$> untyped-kind Γ k untyped-cases Γ ms ρ = let msₗ = length ms in foldl (λ m rec ms f → untyped-case Γ m msₗ f ρ >>= uncurry₂ λ m asₗ n? → rec (maybe-else' n? ms (λ n → set-nth n (just m) ms)) asₗ) (const ∘ return) ms (repeat (length ms) nothing) (λ _ → nothing) >>=r drop-nothing untyped-case-args : ctxt → posinfo → ex-case-args → ex-tm → renamectxt → spanM (case-args × term) untyped-case-args Γ pi cas t ρ = foldr {B = ctxt → renamectxt → 𝕃 tagged-val → (term → spanM ⊤) → spanM (case-args × term)} (λ {(ExCaseArg me pi x) rec Γ' ρ tvs sm → let tk = case me of λ {ExCaseArgTp → Tkk (KdHole pi-gen); ExCaseArgTm → Tkt (TpHole pi-gen); ExCaseArgEr → Tkt (TpHole pi-gen)} in rec (ctxt-tk-decl pi x tk Γ') (renamectxt-insert ρ (pi % x) x) (binder-data Γ' pi x tk (ex-case-arg-erased me) nothing (term-start-pos t) (term-end-pos t) :: tvs) (λ t → [- var-span (ex-case-arg-erased me) Γ' pi x untyped tk (when (ex-case-arg-erased me && is-free-in (pi % x) (erase t)) "The bound variable occurs free in the erasure of the body (not allowed)") -] sm t) >>=c λ cas → return2 (case me of λ {ExCaseArgTm → CaseArg ff x nothing :: cas; _ → cas})}) (λ Γ' ρ tvs sm → [- pattern-clause-span pi t (reverse tvs) -] untyped-term Γ' t >>= λ t~ → sm t~ >> return2 [] (subst-renamectxt Γ' ρ t~)) cas Γ ρ [] λ _ → spanMok untyped-case Γ (ExCase pi x cas t) csₗ asₗ ρ = untyped-case-args Γ pi cas t ρ >>=c λ cas~ t~ → case (qual-lookup Γ x) of λ where (just (qx , as , ctr-def ps T Cₗ cᵢ cₐ , loc)) → let c~ = Case qx cas~ t~ [] eᵢ = "This constructor overlaps with " ^ x eₐ = unless (length cas~ =ℕ cₐ) ("Expected " ^ ℕ-to-string cₐ ^ " arguments after erasure, but got " ^ ℕ-to-string (length cas~)) eₗ = unless (Cₗ =ℕ csₗ) ("Constructor's datatype has " ^ ℕ-to-string Cₗ ^ (if Cₗ =ℕ 1 then " constructor" else " constructors") ^ ", but expected " ^ ℕ-to-string csₗ) in [- Var-span Γ pi x untyped [] (asₗ cᵢ ||-maybe (eₐ ||-maybe eₗ)) -] return2 c~ ((λ cᵢ' → when (cᵢ =ℕ cᵢ') eᵢ) , (maybe-not (asₗ cᵢ) >> just cᵢ)) _ → [- Var-span Γ pi x untyped [] (just $ "This is not a valid constructor name") -] return2 (Case x cas~ t~ []) (asₗ , nothing)
{ "alphanum_fraction": 0.5608791494, "avg_line_length": 38.2729528536, "ext": "agda", "hexsha": "f9cc265d7a4e4b1795445b443bf12d5001e6f8bb", "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": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "ice1k/cedille", "max_forks_repo_path": "src/untyped-spans.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "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": "ice1k/cedille", "max_issues_repo_path": "src/untyped-spans.agda", "max_line_length": 144, "max_stars_count": null, "max_stars_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "ice1k/cedille", "max_stars_repo_path": "src/untyped-spans.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 5699, "size": 15424 }
module AlonzoPrelude where open import RTN public import RTP -- magic module - Run Time Primitives Int : Set Int = RTP.Int Float : Set Float = RTP.Float String : Set String = RTP.String Char : Set Char = RTP.Char data True : Set where tt : True {- record True : Set where tt : True tt = record{} -} data False : Set where elim-False : {A : Set} -> False -> A elim-False () -- _∘_ : {A,B,C:Set} -> (B -> C) -> (A -> B) -> A -> C -- f ∘ g = \x -> f (g x) id : {A : Set} -> A -> A id x = x infixr 90 _○_ _○_ : {A B C : Set} -> (B -> C) -> (A -> B) -> A -> C (f ○ g) x = f (g x) infixr 0 _$_ _$_ : {A B : Set} -> (A -> B) -> A -> B f $ x = f x flip : {A B C : Set} -> (A -> B -> C) -> B -> A -> C flip f x y = f y x const : {A B : Set} -> A -> B -> A const x _ = x typeOf : {A : Set} -> A -> Set typeOf {A} _ = A data _×_ (A B : Set) : Set where <_,_> : A -> B -> A × B fst : {A B : Set} -> A × B -> A fst < x , y > = x snd : {A B : Set} -> A × B -> B snd < x , y > = y {- infixr 10 _::_ data List (A:Set) : Set where nil : List A _::_ : A -> List A -> List A [_] : {A:Set} -> A -> List A [ x ] = x :: nil -} {-# BUILTIN INTEGER Int #-} -- {-# BUILTIN STRING String #-} -- {-# BUILTIN FLOAT Float #-} {-# BUILTIN CHAR Char #-}
{ "alphanum_fraction": 0.4411337209, "avg_line_length": 17.2, "ext": "agda", "hexsha": "3541e266a567b7ad17c7fa8a234aeda066824bd8", "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/Alonzo/AlonzoPrelude.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/Alonzo/AlonzoPrelude.agda", "max_line_length": 56, "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/Alonzo/AlonzoPrelude.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": 556, "size": 1376 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Base.Types import LibraBFT.Impl.Consensus.ConsensusTypes.Block as Block import LibraBFT.Impl.Execution.ExecutorTypes.StateComputeResult as StateComputeResult import LibraBFT.Impl.OBM.Crypto as Crypto open import LibraBFT.ImplShared.Base.Types open import LibraBFT.ImplShared.Consensus.Types open import Optics.All open import Util.Prelude module LibraBFT.Impl.Consensus.ConsensusTypes.ExecutedBlock where isNilBlock : ExecutedBlock → Bool isNilBlock eb = Block.isNilBlock (eb ^∙ ebBlock) blockInfo : ExecutedBlock → BlockInfo blockInfo eb = Block.genBlockInfo (eb ^∙ ebBlock) (Crypto.obmHashVersion -- OBM-LBFT-DIFF - see SafetyRules.extensionCheck (eb ^∙ ebStateComputeResult ∙ scrObmNumLeaves)) (eb ^∙ ebStateComputeResult ∙ scrObmNumLeaves) (eb ^∙ ebStateComputeResult ∙ scrEpochState) maybeSignedVoteProposal : ExecutedBlock → MaybeSignedVoteProposal maybeSignedVoteProposal self = MaybeSignedVoteProposal∙new (VoteProposal∙new (StateComputeResult.extensionProof (self ^∙ ebStateComputeResult)) (self ^∙ ebBlock) (self ^∙ ebStateComputeResult ∙ scrEpochState))
{ "alphanum_fraction": 0.7407912688, "avg_line_length": 40.7222222222, "ext": "agda", "hexsha": "1d0c02576e146353a45a8d094e4d691a8ece1969", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_forks_repo_path": "src/LibraBFT/Impl/Consensus/ConsensusTypes/ExecutedBlock.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_issues_repo_path": "src/LibraBFT/Impl/Consensus/ConsensusTypes/ExecutedBlock.agda", "max_line_length": 111, "max_stars_count": null, "max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda", "max_stars_repo_path": "src/LibraBFT/Impl/Consensus/ConsensusTypes/ExecutedBlock.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 387, "size": 1466 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Bisimilarity for Covecs ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe --sized-types #-} module Codata.Covec.Bisimilarity where open import Level using (_⊔_) open import Size open import Codata.Thunk open import Codata.Conat hiding (_⊔_) open import Codata.Covec open import Relation.Binary open import Relation.Binary.PropositionalEquality as Eq using (_≡_) data Bisim {a b r} {A : Set a} {B : Set b} (R : A → B → Set r) (i : Size) : ∀ m n (xs : Covec A ∞ m) (ys : Covec B ∞ n) → Set (r ⊔ a ⊔ b) where [] : Bisim R i zero zero [] [] _∷_ : ∀ {x y m n xs ys} → R x y → Thunk^R (λ i → Bisim R i (m .force) (n .force)) i xs ys → Bisim R i (suc m) (suc n) (x ∷ xs) (y ∷ ys) module _ {a r} {A : Set a} {R : A → A → Set r} where reflexive : Reflexive R → ∀ {i m} → Reflexive (Bisim R i m m) reflexive refl^R {i} {m} {[]} = [] reflexive refl^R {i} {m} {r ∷ rs} = refl^R ∷ λ where .force → reflexive refl^R module _ {a b} {A : Set a} {B : Set b} {r} {P : A → B → Set r} {Q : B → A → Set r} where symmetric : Sym P Q → ∀ {i m n} → Sym (Bisim P i m n) (Bisim Q i n m) symmetric sym^PQ [] = [] symmetric sym^PQ (p ∷ ps) = sym^PQ p ∷ λ where .force → symmetric sym^PQ (ps .force) module _ {a b c} {A : Set a} {B : Set b} {C : Set c} {r} {P : A → B → Set r} {Q : B → C → Set r} {R : A → C → Set r} where transitive : Trans P Q R → ∀ {i m n p} → Trans (Bisim P i m n) (Bisim Q i n p) (Bisim R i m p) transitive trans^PQR [] [] = [] transitive trans^PQR (p ∷ ps) (q ∷ qs) = trans^PQR p q ∷ λ where .force → transitive trans^PQR (ps .force) (qs .force) -- Pointwise Equality as a Bisimilarity ------------------------------------------------------------------------ module _ {ℓ} {A : Set ℓ} where infix 1 _,_⊢_≈_ _,_⊢_≈_ : ∀ i m → Covec A ∞ m → Covec A ∞ m → Set ℓ _,_⊢_≈_ i m = Bisim _≡_ i m m refl : ∀ {i m} → Reflexive (i , m ⊢_≈_) refl = reflexive Eq.refl sym : ∀ {i m} → Symmetric (i , m ⊢_≈_) sym = symmetric Eq.sym trans : ∀ {i m} → Transitive (i , m ⊢_≈_) trans = transitive Eq.trans
{ "alphanum_fraction": 0.5046812305, "avg_line_length": 35.046875, "ext": "agda", "hexsha": "ba60fce6d0ca788be934c7f009c1bfe1c9d21319", "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": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Codata/Covec/Bisimilarity.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Codata/Covec/Bisimilarity.agda", "max_line_length": 95, "max_stars_count": 5, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Codata/Covec/Bisimilarity.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": 821, "size": 2243 }
------------------------------------------------------------------------ -- Some omniscience principles ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Equality module Omniscience {c⁺} (eq : ∀ {a p} → Equality-with-J a p c⁺) where open Derived-definitions-and-properties eq open import Logical-equivalence using (_⇔_) open import Prelude open import Equality.Decision-procedures eq open import Excluded-middle eq open import Function-universe eq hiding (id; _∘_) open import H-level eq open import H-level.Closure eq open import Nat eq -- I don't know who first stated LPO and WLPO, or who first proved -- various properties about these principles. -- The limited principle of omniscience. LPO : Type LPO = (f : ℕ → Bool) → (∀ n → f n ≡ false) ⊎ (∃ λ n → f n ≡ true) -- The weak limited principle of omniscience. WLPO : Type WLPO = (f : ℕ → Bool) → Dec (∀ n → f n ≡ false) -- WLPO is propositional (assuming extensionality). WLPO-propositional : Extensionality lzero lzero → Is-proposition WLPO WLPO-propositional ext = Π-closure ext 1 λ f → Dec-closure-propositional ext (Π-closure ext 1 λ _ → Bool-set) -- LPO implies WLPO. LPO→WLPO : LPO → WLPO LPO→WLPO LPO f = ⊎-map id (uncurry λ n fn≡true ∀n→fn≡false → Bool.true≢false ( true ≡⟨ sym fn≡true ⟩ f n ≡⟨ ∀n→fn≡false n ⟩∎ false ∎)) (LPO f) -- WLPO follows from excluded middle (assuming extensionality). -- -- This follows from LPO→WLPO and LEM→LPO (see below), but this proof -- is less complicated. LEM→WLPO : Extensionality lzero lzero → Excluded-middle lzero → WLPO LEM→WLPO ext em = λ _ → em (Π-closure ext 1 λ _ → Bool-set) mutual -- There is a propositional property that is logically equivalent to -- LPO (assuming extensionality). -- -- I think that Escardo has proved some variant of this property. The -- proof below uses a technique suggested by Exercise 3.19 in the HoTT -- book. LPO⇔propositional : Extensionality lzero lzero → ∃ λ (P : Type) → Is-proposition P × (LPO ⇔ P) LPO⇔propositional ext = let P , P-prop , LPO⇔ = LPO⇔propositional′ ext in (∀ f → P f ⊎ ¬ P f) , (Π-closure ext 1 λ f → ⊎-closure-propositional (flip _$_) (P-prop f) (¬-propositional ext)) , LPO⇔ -- A variant of the previous property. LPO⇔propositional′ : Extensionality lzero lzero → ∃ λ (P : (ℕ → Bool) → Type) → (∀ f → Is-proposition (P f)) × (LPO ⇔ ∀ f → P f ⊎ ¬ P f) LPO⇔propositional′ ext = P , P-prop , (((f : ℕ → Bool) → (∀ n → f n ≡ false) ⊎ (∃ λ n → f n ≡ true)) ↝⟨ (∀-cong _ λ _ → record { to = ≡false→¬P; from = ¬P→≡false } ⊎-cong record { to = ≡true→P; from = Σ-map id proj₁ }) ⟩ ((f : ℕ → Bool) → ¬ P f ⊎ P f) ↝⟨ (∀-cong _ λ _ → from-bijection ⊎-comm) ⟩□ ((f : ℕ → Bool) → P f ⊎ ¬ P f) □) where P = λ (f : ℕ → Bool) → ∃ λ n → f n ≡ true × ∀ {m} → m < n → f m ≡ false P-prop : ∀ f → Is-proposition (P f) P-prop f (n₁ , fn₁≡true , <n₁→≡false) (n₂ , fn₂≡true , <n₂→≡false) = Σ-≡,≡→≡ (case n₁ <⊎≡⊎> n₂ of λ where (inj₁ n₁<n₂) → ⊥-elim (Bool.true≢false ( true ≡⟨ sym fn₁≡true ⟩ f n₁ ≡⟨ <n₂→≡false n₁<n₂ ⟩∎ false ∎)) (inj₂ (inj₁ n₁≡n₂)) → n₁≡n₂ (inj₂ (inj₂ n₁>n₂)) → ⊥-elim (Bool.true≢false ( true ≡⟨ sym fn₂≡true ⟩ f n₂ ≡⟨ <n₁→≡false n₁>n₂ ⟩∎ false ∎))) (×-closure 1 (Bool-set) (implicit-Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Bool-set) _ _) ¬P→≡false : ∀ {f} → ¬ (P f) → (∀ n → f n ≡ false) ¬P→≡false {f} ¬Pf = well-founded-elim _ λ n hyp → case inspect (f n) of λ where (false , fn≡false) → fn≡false (true , fn≡true) → ⊥-elim (¬Pf (n , fn≡true , hyp)) ≡false→¬P : ∀ {f} → (∀ n → f n ≡ false) → ¬ (P f) ≡false→¬P {f} ≡false (n , ≡true , _) = Bool.true≢false ( true ≡⟨ sym ≡true ⟩ f n ≡⟨ ≡false n ⟩∎ false ∎) ≡true→P : ∀ {f} → (∃ λ n → f n ≡ true) → P f ≡true→P {f} (n , fn≡true) = helper (≤→≤↑ (zero≤ _)) (λ o<0 → ⊥-elim (≮0 _ o<0)) where helper : ∀ {m} → m ≤↑ n → (∀ {o} → o < m → f o ≡ false) → P f helper {m} (≤↑-refl m≡n) <→≡false = n , fn≡true , λ {o} → o < n ↝⟨ subst (o <_) (sym m≡n) ⟩ o < m ↝⟨ <→≡false ⟩□ f o ≡ false □ helper {m} (≤↑-step m<n) <→≡false with inspect (f m) ... | true , fm≡true = m , fm≡true , <→≡false ... | false , fm≡false = helper m<n λ {o} o<1+m → case ≤→≤↑ o<1+m of λ where (≤↑-refl 1+o≡1+m) → f o ≡⟨ cong f (cancel-suc 1+o≡1+m) ⟩ f m ≡⟨ fm≡false ⟩∎ false ∎ (≤↑-step 1+o<1+m) → <→≡false (pred-mono (≤↑→≤ 1+o<1+m)) -- LPO follows from excluded middle (assuming extensionality). LEM→LPO : Extensionality lzero lzero → Excluded-middle lzero → LPO LEM→LPO ext = let P , P-prop , LPO⇔P = LPO⇔propositional′ ext in ({P : Type} → Is-proposition P → Dec P) ↝⟨ _∘ P-prop ⟩ (∀ f → P f ⊎ ¬ P f) ↝⟨ _⇔_.from LPO⇔P ⟩□ LPO □
{ "alphanum_fraction": 0.4557477111, "avg_line_length": 35.1071428571, "ext": "agda", "hexsha": "b3b2ae7b7494c58faed85bafe27dd2a3d6e60b58", "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/Omniscience.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/Omniscience.agda", "max_line_length": 125, "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/Omniscience.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": 2064, "size": 5898 }
-------------------------------------------------------------------------------- -- This is part of Agda Inference Systems {-# OPTIONS --guardedness #-} module is-lib.InfSys {𝓁} where open import is-lib.InfSys.Base {𝓁} public open import is-lib.InfSys.Induction {𝓁} public open import is-lib.InfSys.Coinduction {𝓁} public open import is-lib.InfSys.FlexCoinduction {𝓁} public open MetaRule public open FinMetaRule public open IS public
{ "alphanum_fraction": 0.6084070796, "avg_line_length": 34.7692307692, "ext": "agda", "hexsha": "1224f08ac9fdd65c80e17556af5f7e763570bdc3", "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": "c4b78e70c3caf68d509f4360b9171d9f80ecb825", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "boystrange/FairSubtypingAgda", "max_forks_repo_path": "src/is-lib/InfSys.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825", "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": "boystrange/FairSubtypingAgda", "max_issues_repo_path": "src/is-lib/InfSys.agda", "max_line_length": 80, "max_stars_count": 4, "max_stars_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "boystrange/FairSubtypingAgda", "max_stars_repo_path": "src/is-lib/InfSys.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-24T14:38:47.000Z", "max_stars_repo_stars_event_min_datetime": "2021-07-29T14:32:30.000Z", "num_tokens": 116, "size": 452 }
module Issue121 where id : Set → Set id A = A data Bool : Set where true : Bool false : Bool F : Bool → Set → Set F true = id F false = id G : Bool → Set → Set G true = id G false = λ A → A data D : Set where nop : (b : Bool) → F b D → D bop : (b : Bool) → G b D → D
{ "alphanum_fraction": 0.5441696113, "avg_line_length": 12.8636363636, "ext": "agda", "hexsha": "956cf396bb327d3e6bd6c65ada054c980a47e52b", "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/Issue121.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/Issue121.agda", "max_line_length": 30, "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/Issue121.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": 111, "size": 283 }
{- This second-order signature was created from the following second-order syntax description: syntax Group | G type * : 0-ary term unit : * | ε add : * * -> * | _⊕_ l20 neg : * -> * | ⊖_ r40 theory (εU⊕ᴸ) a |> add (unit, a) = a (εU⊕ᴿ) a |> add (a, unit) = a (⊕A) a b c |> add (add(a, b), c) = add (a, add(b, c)) (⊖N⊕ᴸ) a |> add (neg (a), a) = unit (⊖N⊕ᴿ) a |> add (a, neg (a)) = unit -} module Group.Signature where open import SOAS.Context open import SOAS.Common open import SOAS.Syntax.Signature *T public open import SOAS.Syntax.Build *T public -- Operator symbols data Gₒ : Set where unitₒ addₒ negₒ : Gₒ -- Term signature G:Sig : Signature Gₒ G:Sig = sig λ { unitₒ → ⟼₀ * ; addₒ → (⊢₀ *) , (⊢₀ *) ⟼₂ * ; negₒ → (⊢₀ *) ⟼₁ * } open Signature G:Sig public
{ "alphanum_fraction": 0.5661764706, "avg_line_length": 18.1333333333, "ext": "agda", "hexsha": "3c5d6f7db04810a6b06769ceaf9e59c38f8015da", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z", "max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JoeyEremondi/agda-soas", "max_forks_repo_path": "out/Group/Signature.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JoeyEremondi/agda-soas", "max_issues_repo_path": "out/Group/Signature.agda", "max_line_length": 91, "max_stars_count": 39, "max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JoeyEremondi/agda-soas", "max_stars_repo_path": "out/Group/Signature.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z", "max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z", "num_tokens": 356, "size": 816 }
------------------------------------------------------------------------------ -- Properties stated in the Burstall's paper ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Program.SortList.PropertiesI where open import Common.FOL.Relation.Binary.EqReasoning open import FOTC.Base open import FOTC.Base.List open import FOTC.Data.Bool open import FOTC.Data.Bool.PropertiesI open import FOTC.Data.Nat.Inequalities open import FOTC.Data.Nat.Inequalities.PropertiesI open import FOTC.Data.Nat.List.Type open import FOTC.Data.Nat.Type open import FOTC.Data.List open import FOTC.Data.List.PropertiesI open import FOTC.Program.SortList.Properties.Totality.BoolI open import FOTC.Program.SortList.Properties.Totality.ListN-I open import FOTC.Program.SortList.Properties.Totality.OrdList.FlattenI open import FOTC.Program.SortList.Properties.Totality.OrdListI open import FOTC.Program.SortList.Properties.Totality.OrdTreeI open import FOTC.Program.SortList.Properties.Totality.TreeI open import FOTC.Program.SortList.SortList ------------------------------------------------------------------------------ -- Induction on lit. ind-lit : (A : D → Set) (f : D) → ∀ y₀ {xs} → ListN xs → A y₀ → (∀ {x} → N x → ∀ y → A y → A (f · x · y)) → A (lit f xs y₀) ind-lit A f y₀ lnnil Ay₀ ih = subst A (sym (lit-[] f y₀)) Ay₀ ind-lit A f y₀ (lncons {i} {is} Ni LNis) Ay₀ ih = subst A (sym (lit-∷ f i is y₀)) (ih Ni (lit f is y₀) (ind-lit A f y₀ LNis Ay₀ ih)) ------------------------------------------------------------------------------ -- Burstall's lemma: If t is ordered then totree(i, t) is ordered. toTree-OrdTree : ∀ {item t} → N item → Tree t → OrdTree t → OrdTree (toTree · item · t) toTree-OrdTree {item} Nitem tnil _ = ordTree (toTree · item · nil) ≡⟨ subst (λ x → ordTree (toTree · item · nil) ≡ ordTree x) (toTree-nil item) refl ⟩ ordTree (tip item) ≡⟨ ordTree-tip item ⟩ true ∎ toTree-OrdTree {item} Nitem (ttip {i} Ni) _ = case prf₁ prf₂ (x>y∨x≤y Ni Nitem) where prf₁ : i > item → OrdTree (toTree · item · tip i) prf₁ i>item = ordTree (toTree · item · tip i) ≡⟨ subst (λ t → ordTree (toTree · item · tip i) ≡ ordTree t) (toTree-tip item i) refl ⟩ ordTree (if (le i item) then (node (tip i) item (tip item)) else (node (tip item) i (tip i))) ≡⟨ subst (λ t → ordTree (if (le i item) then (node (tip i) item (tip item)) else (node (tip item) i (tip i))) ≡ ordTree (if t then (node (tip i) item (tip item)) else (node (tip item) i (tip i)))) (x>y→x≰y Ni Nitem i>item) refl ⟩ ordTree (if false then (node (tip i) item (tip item)) else (node (tip item) i (tip i))) ≡⟨ subst (λ t → ordTree (if false then (node (tip i) item (tip item)) else (node (tip item) i (tip i))) ≡ ordTree t) (if-false (node (tip item) i (tip i))) refl ⟩ ordTree (node (tip item) i (tip i)) ≡⟨ ordTree-node (tip item) i (tip i) ⟩ ordTree (tip item) && ordTree (tip i) && le-TreeItem (tip item) i && le-ItemTree i (tip i) ≡⟨ subst (λ t → ordTree (tip item) && ordTree (tip i) && le-TreeItem (tip item) i && le-ItemTree i (tip i) ≡ t && ordTree (tip i) && le-TreeItem (tip item) i && le-ItemTree i (tip i)) (ordTree-tip item) refl ⟩ true && ordTree (tip i) && le-TreeItem (tip item) i && le-ItemTree i (tip i) ≡⟨ subst (λ t → true && ordTree (tip i) && le-TreeItem (tip item) i && le-ItemTree i (tip i) ≡ true && t && le-TreeItem (tip item) i && le-ItemTree i (tip i)) (ordTree-tip i) refl ⟩ true && true && le-TreeItem (tip item) i && le-ItemTree i (tip i) ≡⟨ subst (λ t → true && true && le-TreeItem (tip item) i && le-ItemTree i (tip i) ≡ true && true && t && le-ItemTree i (tip i)) (le-TreeItem-tip item i) refl ⟩ true && true && le item i && le-ItemTree i (tip i) ≡⟨ subst (λ t → true && true && le item i && le-ItemTree i (tip i) ≡ true && true && t && le-ItemTree i (tip i)) (x<y→x≤y Nitem Ni i>item) refl ⟩ true && true && true && le-ItemTree i (tip i) ≡⟨ subst (λ t → true && true && true && le-ItemTree i (tip i) ≡ true && true && true && t) (le-ItemTree-tip i i) refl ⟩ true && true && true && le i i ≡⟨ subst (λ t → true && true && true && le i i ≡ true && true && true && t) (x≤x Ni) refl ⟩ true && true && true && true ≡⟨ subst (λ t → true && true && true && true ≡ true && true && t) (t&&x≡x true) refl ⟩ true && true && true ≡⟨ subst (λ t → true && true && true ≡ true && t) (t&&x≡x true) refl ⟩ true && true ≡⟨ t&&x≡x true ⟩ true ∎ prf₂ : i ≤ item → OrdTree (toTree · item · tip i) prf₂ i≤item = ordTree (toTree · item · tip i) ≡⟨ subst (λ t → ordTree (toTree · item · tip i) ≡ ordTree t) (toTree-tip item i) refl ⟩ ordTree (if (le i item) then (node (tip i) item (tip item)) else (node (tip item) i (tip i))) ≡⟨ subst (λ t → ordTree (if (le i item) then (node (tip i) item (tip item)) else (node (tip item) i (tip i))) ≡ ordTree (if t then (node (tip i) item (tip item)) else (node (tip item) i (tip i)))) i≤item refl ⟩ ordTree (if true then (node (tip i) item (tip item)) else (node (tip item) i (tip i))) ≡⟨ subst (λ t → ordTree (if true then (node (tip i) item (tip item)) else (node (tip item) i (tip i))) ≡ ordTree t) (if-true (node (tip i) item (tip item))) refl ⟩ ordTree (node (tip i) item (tip item)) ≡⟨ ordTree-node (tip i) item (tip item) ⟩ ordTree (tip i) && ordTree (tip item) && le-TreeItem (tip i) item && le-ItemTree item (tip item) ≡⟨ subst (λ t → ordTree (tip i) && ordTree (tip item) && le-TreeItem (tip i) item && le-ItemTree item (tip item) ≡ t && ordTree (tip item) && le-TreeItem (tip i) item && le-ItemTree item (tip item)) (ordTree-tip i) refl ⟩ true && ordTree (tip item) && le-TreeItem (tip i) item && le-ItemTree item (tip item) ≡⟨ subst (λ t → true && ordTree (tip item) && le-TreeItem (tip i) item && le-ItemTree item (tip item) ≡ true && t && le-TreeItem (tip i) item && le-ItemTree item (tip item)) (ordTree-tip item) refl ⟩ true && true && le-TreeItem (tip i) item && le-ItemTree item (tip item) ≡⟨ subst (λ t → true && true && le-TreeItem (tip i) item && le-ItemTree item (tip item) ≡ true && true && t && le-ItemTree item (tip item)) (le-TreeItem-tip i item) refl ⟩ true && true && le i item && le-ItemTree item (tip item) ≡⟨ subst (λ t → true && true && le i item && le-ItemTree item (tip item) ≡ true && true && t && le-ItemTree item (tip item)) i≤item refl ⟩ true && true && true && le-ItemTree item (tip item) ≡⟨ subst (λ t → true && true && true && le-ItemTree item (tip item) ≡ true && true && true && t) (le-ItemTree-tip item item) refl ⟩ true && true && true && le item item ≡⟨ subst (λ t → true && true && true && le item item ≡ true && true && true && t) (x≤x Nitem) refl ⟩ true && true && true && true ≡⟨ subst (λ t → true && true && true && true ≡ true && true && t) (t&&x≡x true) refl ⟩ true && true && true ≡⟨ subst (λ t → true && true && true ≡ true && t) (t&&x≡x true) refl ⟩ true && true ≡⟨ t&&x≡x true ⟩ true ∎ toTree-OrdTree {item} Nitem (tnode {t₁} {i} {t₂} Tt₁ Ni Tt₂) OTtnode = case prf₁ prf₂ (x>y∨x≤y Ni Nitem) where prf₁ : i > item → OrdTree (toTree · item · node t₁ i t₂) prf₁ i>item = ordTree (toTree · item · node t₁ i t₂) ≡⟨ subst (λ t → ordTree (toTree · item · node t₁ i t₂) ≡ ordTree t) (toTree-node item t₁ i t₂) refl ⟩ ordTree (if (le i item) then (node t₁ i (toTree · item · t₂)) else (node (toTree · item · t₁) i t₂)) ≡⟨ subst (λ t → ordTree (if (le i item) then (node t₁ i (toTree · item · t₂)) else (node (toTree · item · t₁) i t₂)) ≡ ordTree (if t then (node t₁ i (toTree · item · t₂)) else (node (toTree · item · t₁) i t₂))) (x>y→x≰y Ni Nitem i>item) refl ⟩ ordTree (if false then (node t₁ i (toTree · item · t₂)) else (node (toTree · item · t₁) i t₂)) ≡⟨ subst (λ t → ordTree (if false then (node t₁ i (toTree · item · t₂)) else (node (toTree · item · t₁) i t₂)) ≡ ordTree t) (if-false (node (toTree · item · t₁) i t₂)) refl ⟩ ordTree (node (toTree · item · t₁) i t₂) ≡⟨ ordTree-node (toTree · item · t₁) i t₂ ⟩ ordTree (toTree · item · t₁) && ordTree t₂ && le-TreeItem (toTree · item · t₁) i && le-ItemTree i t₂ ≡⟨ subst (λ t → ordTree (toTree · item · t₁) && ordTree t₂ && le-TreeItem (toTree · item · t₁) i && le-ItemTree i t₂ ≡ t && ordTree t₂ && le-TreeItem (toTree · item · t₁) i && le-ItemTree i t₂) (toTree-OrdTree Nitem Tt₁ (leftSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode)) refl ⟩ true && ordTree t₂ && le-TreeItem (toTree · item · t₁) i && le-ItemTree i t₂ ≡⟨ subst (λ t → true && ordTree t₂ && le-TreeItem (toTree · item · t₁) i && le-ItemTree i t₂ ≡ true && t && le-TreeItem (toTree · item · t₁) i && le-ItemTree i t₂) (rightSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode) refl ⟩ true && true && le-TreeItem (toTree · item · t₁) i && le-ItemTree i t₂ ≡⟨ subst (λ t → true && true && le-TreeItem (toTree · item · t₁) i && le-ItemTree i t₂ ≡ true && true && t && le-ItemTree i t₂) (toTree-OrdTree-helper₁ Ni Nitem i>item Tt₁ ((&&-list₄-t₃ (ordTree-Bool Tt₁) (ordTree-Bool Tt₂) (le-TreeItem-Bool Tt₁ Ni) (le-ItemTree-Bool Ni Tt₂) (trans (sym (ordTree-node t₁ i t₂)) OTtnode)))) refl ⟩ true && true && true && le-ItemTree i t₂ ≡⟨ subst (λ t → true && true && true && le-ItemTree i t₂ ≡ true && true && true && t) (&&-list₄-t₄ (ordTree-Bool Tt₁) (ordTree-Bool Tt₂) (le-TreeItem-Bool Tt₁ Ni) (le-ItemTree-Bool Ni Tt₂) (trans (sym (ordTree-node t₁ i t₂)) OTtnode)) refl ⟩ true && true && true && true ≡⟨ subst (λ t → true && true && true && true ≡ true && true && t) (t&&x≡x true) refl ⟩ true && true && true ≡⟨ subst (λ t → true && true && true ≡ true && t) (t&&x≡x true) refl ⟩ true && true ≡⟨ t&&x≡x true ⟩ true ∎ prf₂ : i ≤ item → OrdTree (toTree · item · node t₁ i t₂) prf₂ i≤item = ordTree (toTree · item · node t₁ i t₂) ≡⟨ subst (λ t → ordTree (toTree · item · node t₁ i t₂) ≡ ordTree t) (toTree-node item t₁ i t₂) refl ⟩ ordTree (if (le i item) then (node t₁ i (toTree · item · t₂)) else (node (toTree · item · t₁) i t₂)) ≡⟨ subst (λ t → ordTree (if (le i item) then (node t₁ i (toTree · item · t₂)) else (node (toTree · item · t₁) i t₂)) ≡ ordTree (if t then (node t₁ i (toTree · item · t₂)) else (node (toTree · item · t₁) i t₂))) i≤item refl ⟩ ordTree (if true then (node t₁ i (toTree · item · t₂)) else (node (toTree · item · t₁) i t₂)) ≡⟨ subst (λ t → ordTree (if true then (node t₁ i (toTree · item · t₂)) else (node (toTree · item · t₁) i t₂)) ≡ ordTree t) (if-true (node t₁ i (toTree · item · t₂))) refl ⟩ ordTree (node t₁ i (toTree · item · t₂)) ≡⟨ ordTree-node t₁ i (toTree · item · t₂) ⟩ ordTree t₁ && ordTree (toTree · item · t₂) && le-TreeItem t₁ i && le-ItemTree i (toTree · item · t₂) ≡⟨ subst (λ t → ordTree t₁ && ordTree (toTree · item · t₂) && le-TreeItem t₁ i && le-ItemTree i (toTree · item · t₂) ≡ t && ordTree (toTree · item · t₂) && le-TreeItem t₁ i && le-ItemTree i (toTree · item · t₂)) (leftSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode) refl ⟩ true && ordTree (toTree · item · t₂) && le-TreeItem t₁ i && le-ItemTree i (toTree · item · t₂) ≡⟨ subst (λ t → true && ordTree (toTree · item · t₂) && le-TreeItem t₁ i && le-ItemTree i (toTree · item · t₂) ≡ true && t && le-TreeItem t₁ i && le-ItemTree i (toTree · item · t₂)) (toTree-OrdTree Nitem Tt₂ (rightSubTree-OrdTree Tt₁ Ni Tt₂ OTtnode)) refl ⟩ true && true && le-TreeItem t₁ i && le-ItemTree i (toTree · item · t₂) ≡⟨ subst (λ t → true && true && le-TreeItem t₁ i && le-ItemTree i (toTree · item · t₂) ≡ true && true && t && le-ItemTree i (toTree · item · t₂)) (&&-list₄-t₃ (ordTree-Bool Tt₁) (ordTree-Bool Tt₂) (le-TreeItem-Bool Tt₁ Ni) (le-ItemTree-Bool Ni Tt₂) (trans (sym (ordTree-node t₁ i t₂)) OTtnode)) refl ⟩ true && true && true && le-ItemTree i (toTree · item · t₂) ≡⟨ subst (λ t → true && true && true && le-ItemTree i (toTree · item · t₂) ≡ true && true && true && t) (toTree-OrdTree-helper₂ Ni Nitem i≤item Tt₂ ((&&-list₄-t₄ (ordTree-Bool Tt₁) (ordTree-Bool Tt₂) (le-TreeItem-Bool Tt₁ Ni) (le-ItemTree-Bool Ni Tt₂) (trans (sym (ordTree-node t₁ i t₂)) OTtnode)))) refl ⟩ true && true && true && true ≡⟨ subst (λ t → true && true && true && true ≡ true && true && t) (t&&x≡x true) refl ⟩ true && true && true ≡⟨ subst (λ t → true && true && true ≡ true && t) (t&&x≡x true) refl ⟩ true && true ≡⟨ t&&x≡x true ⟩ true ∎ ------------------------------------------------------------------------------ -- Burstall's lemma: ord(maketree(is)). -- makeTree-TreeOrd : ∀ {is} → ListN is → OrdTree (makeTree is) -- makeTree-TreeOrd LNis = -- ind-lit OrdTree toTree nil LNis ordTree-nil -- (λ Nx y TOy → toTree-OrdTree Nx {!!} TOy) makeTree-OrdTree : ∀ {is} → ListN is → OrdTree (makeTree is) makeTree-OrdTree lnnil = ordTree (lit toTree [] nil) ≡⟨ subst (λ t → ordTree (lit toTree [] nil) ≡ ordTree t) (lit-[] toTree nil) refl ⟩ ordTree nil ≡⟨ ordTree-nil ⟩ true ∎ makeTree-OrdTree (lncons {i} {is} Ni Lis) = ordTree (lit toTree (i ∷ is) nil) ≡⟨ subst (λ t → ordTree (lit toTree (i ∷ is) nil) ≡ ordTree t) (lit-∷ toTree i is nil) refl ⟩ ordTree (toTree · i · (lit toTree is nil)) ≡⟨ toTree-OrdTree Ni (makeTree-Tree Lis) (makeTree-OrdTree Lis) ⟩ true ∎ ------------------------------------------------------------------------------ -- Burstall's lemma: If ord(is1) and ord(is2) and is1 ≤ is2 then -- ord(concat(is1, is2)). ++-OrdList : ∀ {is js} → ListN is → ListN js → OrdList is → OrdList js → ≤-Lists is js → OrdList (is ++ js) ++-OrdList {js = js} lnnil LNjs LOis LOjs is≤js = subst OrdList (sym (++-leftIdentity js)) LOjs ++-OrdList {js = js} (lncons {i} {is} Ni LNis) LNjs LOi∷is LOjs i∷is≤js = subst OrdList (sym (++-∷ i is js)) lemma where lemma : OrdList (i ∷ is ++ js) lemma = ordList (i ∷ is ++ js) ≡⟨ ordList-∷ i (is ++ js) ⟩ le-ItemList i (is ++ js) && ordList (is ++ js) ≡⟨ subst (λ t → le-ItemList i (is ++ js) && ordList (is ++ js) ≡ t && ordList (is ++ js)) (++-OrdList-helper Ni LNis LNjs (&&-list₂-t₁ (le-ItemList-Bool Ni LNis) (ordList-Bool LNis) (trans (sym (ordList-∷ i is)) LOi∷is)) (&&-list₂-t₁ (le-ItemList-Bool Ni LNjs) (le-Lists-Bool LNis LNjs) (trans (sym (le-Lists-∷ i is js)) i∷is≤js)) (&&-list₂-t₂ (le-ItemList-Bool Ni LNjs) (le-Lists-Bool LNis LNjs) (trans (sym (le-Lists-∷ i is js)) i∷is≤js)) ) refl ⟩ true && ordList (is ++ js) ≡⟨ subst (λ t → true && ordList (is ++ js) ≡ true && t) (++-OrdList LNis LNjs (subList-OrdList Ni LNis LOi∷is) LOjs (&&-list₂-t₂ (le-ItemList-Bool Ni LNjs) (le-Lists-Bool LNis LNjs) (trans (sym (le-Lists-∷ i is js)) i∷is≤js))) refl ⟩ true && true ≡⟨ t&&x≡x true ⟩ true ∎ ------------------------------------------------------------------------------ -- Burstall's lemma: If t is ordered then (flatten t) is ordered. flatten-OrdList : ∀ {t} → Tree t → OrdTree t → OrdList (flatten t) flatten-OrdList tnil OTt = subst OrdList (sym flatten-nil) ordList-[] flatten-OrdList (ttip {i} Ni) OTt = ordList (flatten (tip i)) ≡⟨ subst (λ t → ordList (flatten (tip i)) ≡ ordList t) (flatten-tip i) refl ⟩ ordList (i ∷ []) ≡⟨ ordList-∷ i [] ⟩ le-ItemList i [] && ordList [] ≡⟨ subst₂ (λ t₁ t₂ → le-ItemList i [] && ordList [] ≡ t₁ && t₂) (le-ItemList-[] i) ordList-[] refl ⟩ true && true ≡⟨ t&&x≡x true ⟩ true ∎ flatten-OrdList (tnode {t₁} {i} {t₂} Tt₁ Ni Tt₂) OTt = ordList (flatten (node t₁ i t₂)) ≡⟨ subst (λ t → ordList (flatten (node t₁ i t₂)) ≡ ordList t) (flatten-node t₁ i t₂) refl ⟩ ordList (flatten t₁ ++ flatten t₂) ≡⟨ ++-OrdList (flatten-ListN Tt₁) (flatten-ListN Tt₂) (flatten-OrdList Tt₁ (leftSubTree-OrdTree Tt₁ Ni Tt₂ OTt)) (flatten-OrdList Tt₂ (rightSubTree-OrdTree Tt₁ Ni Tt₂ OTt)) (flatten-OrdList-helper Tt₁ Ni Tt₂ OTt) ⟩ true ∎
{ "alphanum_fraction": 0.4080389235, "avg_line_length": 40.1654929577, "ext": "agda", "hexsha": "01e87c7bb81a461eb4f9a69be4eb112ae4ad5d6c", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/FOTC/Program/SortList/PropertiesI.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/FOTC/Program/SortList/PropertiesI.agda", "max_line_length": 80, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/FOTC/Program/SortList/PropertiesI.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 6539, "size": 22814 }
module Basic.Compiler.CorrectFrom where open import Basic.AST open import Basic.BigStep open import Basic.Compiler.Code open import Basic.Compiler.SplitCode open import Utils.NatOrdLemmas open import Utils.Decidable open import Utils.Monoid open import Data.Fin using (Fin; #_) open import Data.Vec hiding (_∷ʳ_; _++_; [_]; _∈_; foldr) open import Data.Nat open import Data.Nat.Properties.Simple open import Data.Nat.Properties open import Data.Empty open import Data.Bool renaming (not to notBool; if_then_else_ to ifBool_then_else) open import Data.List hiding ([_]) open import Data.List.Properties open import Relation.Binary.PropositionalEquality open import Function open import Data.Product open import Relation.Nullary open import Relation.Nullary.Decidable import Level as L open import Algebra private module LM {a A} = Algebra.Monoid (Data.List.monoid {a} A) open import Relation.Unary open import Induction.Nat open import Induction.WellFounded {- Lemma 3.22 This proof caused me considerable headache. First I started to prove it by strctural recursion on the to-be-compiled statement, but then Agda complained that it was not structurally recursive. And indeed it isn't. In the "while-true" case, we start with a program derivation of the type: ⟨ 𝓒⟦ S ⟧ˢ ++ LOOP 𝓒⟦ b ⟧ᵉ 𝓒⟦ S ⟧ˢ ∷ [] , [] , s ⟩▷*⟨ [] , e , s' ⟩ And a statement with the following form: while b do S Then we split this derivation into two parts: ⟨ 𝓒⟦ S ⟧ˢ , [] , s ⟩▷*⟨ [] , e'' , s'' ⟩ ⟨ LOOP 𝓒⟦ b ⟧ᵉ 𝓒⟦ S ⟧ˢ ∷ [] , e'' , s'' ⟩▷*⟨ [] , e , s' ⟩ But now if we recurse on the second derivation, the corresponding statement will be again "while b do S". Thus Agda will not be able to prove termination. So I had to use well-founded induction. It is a standard library machinery that allows us to do induction on a well-ordered set. Here's an introduction to how it works: http://blog.ezyang.com/2010/06/well-founded-recursion-in-agda/ We usually prefer to not use well-founded recursion, because it demands us proofs of decreasing order even on cases where recursion is otherwise evidently structural, and it also makes certain proofs rather difficult. -} -- Well-foundedness lemmas ------------------------------------------------------------ {- We do well-founded recursion on the length of derivation sequences. But we also have to prove that splitting a derivation sequence will never produce empty sequences, or else the lenghts will not be strictly decreasing. To show this, we have to show that - compilation into abstract machine code never outputs an empty list of instructions - computation sequences starting with a non-empty instruction list are never empty -} ∷ʳ-nonempty : ∀ {a}{A : Set a}(xs : List A) x → xs ∷ʳ x ≢ [] ∷ʳ-nonempty [] x () ∷ʳ-nonempty (x ∷ xs) x₁ () ++-xs-empty : ∀ {a}{A : Set a}(xs : List A) {ys} → xs <> ys ≡ [] → xs ≡ [] ++-xs-empty [] p = refl ++-xs-empty (x ∷ xs) () {- Compiled statement are non-empty -} 𝓒ˢ-nonempty : ∀ {n}(S : St n) → 𝓒⟦ S ⟧ˢ ≢ [] 𝓒ˢ-nonempty (x := x₁) = ∷ʳ-nonempty 𝓒⟦ x₁ ⟧ᵉ (STORE x) 𝓒ˢ-nonempty (S , S₁) = 𝓒ˢ-nonempty S ∘ ++-xs-empty 𝓒⟦ S ⟧ˢ 𝓒ˢ-nonempty (if x then S else S₁) = ∷ʳ-nonempty 𝓒⟦ x ⟧ᵉ (BRANCH 𝓒⟦ S ⟧ˢ 𝓒⟦ S₁ ⟧ˢ) 𝓒ˢ-nonempty (while x do S) () 𝓒ˢ-nonempty skip () {- Compiled expressions are non-empty -} 𝓒-Exp-nonempty : ∀ {n t} (e : Exp n t) → 𝓒⟦ e ⟧ᵉ ≢ [] 𝓒-Exp-nonempty (add e e₁) = ∷ʳ-nonempty (𝓒⟦ e₁ ⟧ᵉ <> 𝓒⟦ e ⟧ᵉ) ADD 𝓒-Exp-nonempty (mul e e₁) = ∷ʳ-nonempty (𝓒⟦ e₁ ⟧ᵉ <> 𝓒⟦ e ⟧ᵉ) MUL 𝓒-Exp-nonempty (sub e e₁) = ∷ʳ-nonempty (𝓒⟦ e₁ ⟧ᵉ <> 𝓒⟦ e ⟧ᵉ) SUB 𝓒-Exp-nonempty (eq e e₁) = ∷ʳ-nonempty (𝓒⟦ e₁ ⟧ᵉ <> 𝓒⟦ e ⟧ᵉ) EQ 𝓒-Exp-nonempty (lte e e₁) = ∷ʳ-nonempty (𝓒⟦ e₁ ⟧ᵉ <> 𝓒⟦ e ⟧ᵉ) LTE 𝓒-Exp-nonempty (lt e e₁) = ∷ʳ-nonempty (𝓒⟦ e₁ ⟧ᵉ <> 𝓒⟦ e ⟧ᵉ) LT 𝓒-Exp-nonempty (Exp.and e e₁) = ∷ʳ-nonempty (𝓒⟦ e₁ ⟧ᵉ <> 𝓒⟦ e ⟧ᵉ) AND 𝓒-Exp-nonempty (not e) = ∷ʳ-nonempty 𝓒⟦ e ⟧ᵉ NOT 𝓒-Exp-nonempty (lit x) () 𝓒-Exp-nonempty (var x) () 𝓒-Exp-nonempty tt () 𝓒-Exp-nonempty ff () {-Computations sequences for non-empty code are non-zero length -} ▷*-S-nonempty : ∀ {n S}{s s' : State n}{e e'} (p : ⟨ 𝓒⟦ S ⟧ˢ , e , s ⟩▷*⟨ [] , e' , s' ⟩) → ▷*-length p ≢ 0 ▷*-S-nonempty{_}{S} p x with 𝓒ˢ-nonempty S | 𝓒⟦ S ⟧ˢ | inspect 𝓒⟦_⟧ˢ S ▷*-S-nonempty done x | ¬empty | [] | [ remember ] = ¬empty remember ▷*-S-nonempty (() ∷ p) x₁ | ¬empty | [] | [ remember ] ▷*-S-nonempty (x₁ ∷ p) () | ¬empty | x ∷ cs | [ remember ] {- misc ordering lemmas -} a<′a+sb : ∀ a b → b ≢ 0 → a <′ a + b a<′a+sb a zero x = ⊥-elim (x refl) a<′a+sb a (suc b) x rewrite +-comm a (suc b) = ≤⇒≤′ $ a<sb+a a b a<′b+sa : ∀ a b → a <′ b + suc a a<′b+sa a zero = ≤′-refl a<′b+sa a (suc b) = ≤′-step (a<′b+sa a b) ≤′-weaken-l : ∀ {a b} c → a ≤′ b → a ≤′ c + b ≤′-weaken-l zero p = p ≤′-weaken-l (suc c) p = ≤′-step (≤′-weaken-l c p) -- Correctness ------------------------------------------------------------ {- This is a shorthand for the actual type of the theorem. We use this because otherwise we'd have to write out the type three times in the following code. -} 𝓒-correct-from-Ty : {_ : ℕ} → ℕ → Set 𝓒-correct-from-Ty {n} size = ∀ {S : St n} {e s s'} → (p : ⟨ 𝓒⟦ S ⟧ˢ , [] , s ⟩▷*⟨ [] , e , s' ⟩) → size ≡ ▷*-length p → ⟨ S , s ⟩⟱ s' × e ≡ [] 𝓒-correct-from : ∀ {n} size → 𝓒-correct-from-Ty {n} size 𝓒-correct-from {n} = <-rec _ go where {- Note: we use ▷*-deterministic quite a few times below. We separately use ▷*-split to split the sequence and 𝓒-Exp to establish the contents of the stack after evaluating an expression, but these remain separate facts until we use determinism to prove that the first split sequence and 𝓒-Exp's resulting sequence are the same. We see 𝓒-Exp , ▷*-split and ▷*-deterministic chained together several times below. This is admittedly pretty ugly and it would be better to factor out this pattern and possibly include all the relevant information in the output of ▷*-split. -} {- "go" is the helper function for well-founded recursion. "<-rec" can be viewed as a sort of a fixpoint operator that demands a proof that the argument strictly decreases on every recursion. "size" is the size argument, and we recurse via the "recurse" argument. -} go : ∀ size → (∀ y → y <′ size → 𝓒-correct-from-Ty {n} y) → 𝓒-correct-from-Ty {n} size -- Assignment go size recurse {x := exp}{e}{s} p sizeEq with ▷*-split 𝓒⟦ exp ⟧ᵉ p | 𝓒-Exp-nat {e = []}{s = s} exp go size recurse {.x := exp} p sizeEq | s₁ , ._ , p1 , STORE x ∷ () ∷ p2 , eqn | exp' go size recurse {.x := exp} p sizeEq | s₁ , ._ , p1 , STORE x ∷ done , eqn | exp' with ▷*-deterministic p1 exp' ... | _ , eqe , eqs rewrite eqs with ∷-injective eqe ... | eq-cond , e≡[] rewrite nat-inj eq-cond = ass , e≡[] -- Skip go size recurse {skip} (NOOP ∷ done) sizeEq = skip , refl go size recurse {skip} (NOOP ∷ () ∷ p) sizeEq -- Sequencing go size recurse {S , S₁} p sizeEq with ▷*-split 𝓒⟦ S ⟧ˢ p ... | s'' , e'' , p1 , p2 , size+eq rewrite sizeEq | sym size+eq with recurse _ (a<′a+sb _ _ (▷*-S-nonempty {S = S₁} p2)) {S} p1 refl ... | p1' , e''≡[] rewrite e''≡[] | +-comm (▷*-length p1) (▷*-length p2) with recurse _ (a<′a+sb _ _ (▷*-S-nonempty {S = S} p1)) {S₁} p2 refl ... | p2' , e≡[] = (p1' , p2') , e≡[] -- If then else go size recurse {if b then S else S₁} {e}{s}{s'} p sizeEq with ▷*-split 𝓒⟦ b ⟧ᵉ p | 𝓒-Exp-bool {e = []}{s = s} b ... | s'' , ._ , p1 , BRANCH ∷ p2 , size+eq | b' with ▷*-deterministic p1 b' ... | _ , eqe , eqs rewrite eqs with ∷-injective eqe ... | eq-cond , e'≡[] rewrite bool-inj eq-cond | e'≡[] | proj₂ LM.identity (ifBool ⟦ b ⟧ᵉ s then 𝓒⟦ S ⟧ˢ else 𝓒⟦ S₁ ⟧ˢ) | sizeEq | sym size+eq with ⟦ b ⟧ᵉ s | inspect ⟦ b ⟧ᵉ s ... | true | [ condTrue ] = (if-true (≡true→T condTrue) (proj₁ rest)) , proj₂ rest where rest : ⟨ S , s ⟩⟱ s' × e ≡ [] rest = recurse (▷*-length p2) (a<′b+sa (▷*-length p2) (▷*-length p1)) p2 refl ... | false | [ condFalse ] = (if-false (≡false→F condFalse) (proj₁ rest)) , proj₂ rest where rest : ⟨ S₁ , s ⟩⟱ s' × e ≡ [] rest = recurse (▷*-length p2) (a<′b+sa (▷*-length p2) (▷*-length p1)) p2 refl -- While go size recurse {while b do S}{e}{s}{s'} (LOOP ∷ p) sizeEq with 𝓒-Exp-bool {e = []}{s = s} b | ▷*-split 𝓒⟦ b ⟧ᵉ p ... | b' | s'' , ._ , p1 , BRANCH ∷ p2 , size+eq with ▷*-deterministic p1 b' ... | _ , eqe , eqs rewrite eqs with ∷-injective eqe ... | eq-cond , e'≡[] rewrite bool-inj eq-cond | e'≡[] | proj₂ LM.identity (ifBool ⟦ b ⟧ᵉ s then 𝓒⟦ S ⟧ˢ ++ LOOP 𝓒⟦ b ⟧ᵉ 𝓒⟦ S ⟧ˢ ∷ [] else (NOOP ∷ [])) | sym size+eq | sizeEq with ⟦ b ⟧ᵉ s | inspect ⟦ b ⟧ᵉ s {- Here we the proofs are a bit messed up by the two recursive calls with hideous hand-crafted proofs of size decrease. This is the sort of thing where Coq's solvers and tactics for arithmetic are really handy. Unfortunately we don't yet have those things in Agda, although there is some infrastructure already in place that could be used to create more automatization (like typeclasses and goal reflection) -} -- while-true ... | true | [ condTrue ] = 𝓒-while-true condTrue p2 refl where 𝓒-while-true : ∀ {s s' : State n}{b e S} → ⟦ b ⟧ᵉ s ≡ true → (p3 : ⟨ 𝓒⟦ S ⟧ˢ ++ LOOP 𝓒⟦ b ⟧ᵉ 𝓒⟦ S ⟧ˢ ∷ [] , [] , s ⟩▷*⟨ [] , e , s' ⟩) → (▷*-length p3 ≡ ▷*-length p2) → (⟨ while b do S , s ⟩⟱ s') × e ≡ [] 𝓒-while-true {s}{s'}{b}{e}{S} condTrue p3 ≡len with ▷*-split 𝓒⟦ S ⟧ˢ p3 ... | s'' , e'' , p1_new , p2_new , size+eq rewrite sym size+eq with recurse (▷*-length p1_new) (≤′-step (subst (λ x → suc (▷*-length p1_new) ≤′ ▷*-length p1 + suc x) ≡len (≤′-weaken-l (▷*-length p1) (≤′-step (a<′a+sb (▷*-length p1_new) (▷*-length p2_new) (▷*-S-nonempty {S = while b do S} p2_new)))))) {S} p1_new refl ... | p1' , e''≡[] rewrite e''≡[] with recurse (▷*-length p2_new) (≤′-step (subst (λ x → suc (▷*-length p2_new) ≤′ ▷*-length p1 + suc x) ≡len (≤′-weaken-l (▷*-length p1) (≤′-step ( subst (λ x → ▷*-length p2_new <′ x) (+-comm (▷*-length p2_new) (▷*-length p1_new)) (a<′a+sb (▷*-length p2_new) (▷*-length p1_new) (▷*-S-nonempty {S = S} p1_new))))))) {while b do S} p2_new refl ... | p2' , e≡[] = (while-true (≡true→T condTrue) p1' p2') , e≡[] -- while-false ... | false | [ condFalse ] = 𝓒-while-false condFalse p2 where 𝓒-while-false : ∀ {n}{s s' : State n}{e b S} → ⟦ b ⟧ᵉ s ≡ false → ⟨ NOOP ∷ [] , [] , s ⟩▷*⟨ [] , e , s' ⟩ → (⟨ while b do S , s ⟩⟱ s' × e ≡ []) 𝓒-while-false f (NOOP ∷ done) = (while-false (≡false→F f)) , refl 𝓒-while-false f (NOOP ∷ () ∷ p)
{ "alphanum_fraction": 0.5636347455, "avg_line_length": 36.9605263158, "ext": "agda", "hexsha": "24506f60606c599154d8a015346b225acc1497a5", "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": "05200d60b4a4b2c6fa37806ced9247055d24db94", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "AndrasKovacs/SemanticsWithApplications", "max_forks_repo_path": "Basic/Compiler/CorrectFrom.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94", "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": "AndrasKovacs/SemanticsWithApplications", "max_issues_repo_path": "Basic/Compiler/CorrectFrom.agda", "max_line_length": 101, "max_stars_count": 8, "max_stars_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "AndrasKovacs/SemanticsWithApplications", "max_stars_repo_path": "Basic/Compiler/CorrectFrom.agda", "max_stars_repo_stars_event_max_datetime": "2020-02-02T10:01:52.000Z", "max_stars_repo_stars_event_min_datetime": "2016-09-12T04:25:39.000Z", "num_tokens": 4371, "size": 11236 }
{-# OPTIONS --type-in-type #-} record ⊤ : Set where constructor tt data ⊥ : Set where data _==_ {A : Set} (x : A) : A → Set where refl : x == x module _ (A : Set) (B : A → Set) where record Σ : Set where constructor _,_ field π₁ : A π₂ : B π₁ open Σ public syntax Σ A (λ x → B) = Σ[ x ∶ A ] B isContr : Set → Set isContr A = Σ[ x ∶ A ] (∀ y → x == y) Σ! : (A : Set) (B : A → Set) → Set Σ! A B = isContr (Σ A B) syntax Σ! A (λ x → B) = Σ![ x ∶ A ] B _×_ : (A B : Set) → Set A × B = Σ A λ _ → B P : Set → Set P A = A → Set module _ {A : Set} where empty : P A empty = λ x → ⊥ full : P A full = λ x → ⊤ _∩_ : P A → P A → P A U ∩ V = λ x → (U x) × (V x) _⊆_ : P A → P A → Set U ⊆ V = ∀ x → U x → V x ⋃[_] : P (P A) → P A ⋃[_] S = λ x → Σ[ U ∶ P A ] S U × U x record Topology (X : Set) : Set where field O : P (P X) empty-open : O empty full-open : O full inter-open : ∀ {U V} → O U → O V → O (U ∩ V) union-open : ∀ {S} → S ⊆ O → O ⋃[ S ] record Equivalence {A : Set} (R : A → A → Set) : Set where field reflexivity : {x : A} → R x x !_ : {x y : A} → R x y → R y x _∙_ : {x y z : A} → R y z → R x y → R x z infixr 9 _∙_ instance ==-equiv : ∀ {A} → Equivalence (_==_ {A}) ==-equiv = record { reflexivity = refl ; !_ = λ { {_} {._} refl → refl }; _∙_ = λ { {_} {._} {_} refl q → q } } record Category : Set where field Ob : Set Hom : Ob → Ob → Set _~_ : ∀ {A B} → Hom A B → Hom A B → Set ~-equiv : ∀ {A B} → Equivalence (_~_ {A} {B}) id : ∀ {A} → Hom A A _∘_ : ∀ {A B C} → Hom B C → Hom A B → Hom A C left-id : ∀ {A B} {f : Hom A B} → (id ∘ f) ~ f right-id : ∀ {A B} {f : Hom A B} → (f ∘ id) ~ f assoc : ∀ {A B C D} {f : Hom A B} {g : Hom B C} {h : Hom C D} → ((h ∘ g) ∘ f) ~ (h ∘ (g ∘ f)) instance ~-equiv-instance = ~-equiv opposite : Category opposite = let open Equivalence {{...}} in record { Ob = Ob ; Hom = λ A B → Hom B A ; _~_ = _~_ ; ~-equiv = ~-equiv ; id = id ; _∘_ = λ f g → g ∘ f ; left-id = λ {A} {B} → right-id ; right-id = λ {A} {B} → left-id ; assoc = λ {A} {B} {C} {D} {f} {g} {h} → ! assoc } record Functor (C D : Category) : Set where module C = Category C module D = Category D field apply : C.Ob → D.Ob map : ∀ {A B} → C.Hom A B → D.Hom (apply A) (apply B) id-law : ∀ {A} → map (C.id {A}) D.~ D.id comp-law : ∀ {A B C} (f : C.Hom B C) (g : C.Hom A B) → map (f C.∘ g) D.~ (map f D.∘ map g) instance open Equivalence {{...}} Types : Category Types = record { Ob = Set ; Hom = λ A B → A → B ; _~_ = λ f g → ∀ x → f x == g x ; ~-equiv = record { reflexivity = λ x → refl ; !_ = λ {f} {g} p x → ! p x ; _∙_ = λ {f} {g} {h} p q r → p r ∙ q r } ; id = λ {A} z → z ; _∘_ = λ {A} {B} {C} f g x → f (g x) ; left-id = λ {A} {B} {f} x → refl ; right-id = λ {A} {B} {f} x → refl ; assoc = λ x → refl } module _ (X : Set) (T : Topology X) where private module T = Topology T instance OpenSets : Category OpenSets = record { Ob = Σ _ T.O ; Hom = λ U V → π₁ U ⊆ π₁ V ; _~_ = _==_ ; ~-equiv = ==-equiv ; id = λ x z → z ; _∘_ = λ z z₁ x z₂ → z x (z₁ x z₂) ; left-id = refl ; right-id = refl ; assoc = refl } Presheaf : Set Presheaf = Functor (Category.opposite OpenSets) Types module _ (U : P X) (U-open : T.O U) where record Cover : Set where field Index : Set at : (i : Index) → P X at-open : (i : Index) → T.O (at i) at-subset : (i : Index) → at i ⊆ U covering : (x : X) → U x → Σ[ i ∶ Index ] at i x module _ (F : Presheaf) (<U> : Cover) where private module F = Functor F module <U> = Cover <U> Section : Set Section = ∀ i → F.apply (<U>.at i , <U>.at-open i) Coherence : Section → Set Coherence <s> = ∀ i j → let <U>ij = (<U>.at i ∩ <U>.at j) , (T.inter-open (<U>.at-open i) (<U>.at-open j) ) in F.map {<U>.at i , <U>.at-open i} {<U>ij} (λ _ → π₁) (<s> i) == F.map {<U>.at j , <U>.at-open j} {<U>ij} (λ _ → π₂) (<s> j) Sheaf : Presheaf → Set Sheaf F = let module F = Functor F in (U : P X) (U-open : T.O U) (<U> : Cover U U-open) (<s> : Section U _ F <U>) (coh : Coherence U _ F <U> <s>) → let module <U> = Cover _ _ <U> in Σ![ s ∶ F.apply (U , U-open) ] (∀ i → F.map {U , U-open} (<U>.at-subset i) s == <s> i)
{ "alphanum_fraction": 0.4314516129, "avg_line_length": 23.9187817259, "ext": "agda", "hexsha": "30bd9361df0b673f9ee0314193b289e807691a6e", "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": "8a06162a8f0f7df308458db91d720cf8f7345d69", "max_forks_repo_licenses": [ "CC-BY-4.0" ], "max_forks_repo_name": "jonsterling/Agda-Sheaves", "max_forks_repo_path": "sheaves.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "8a06162a8f0f7df308458db91d720cf8f7345d69", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC-BY-4.0" ], "max_issues_repo_name": "jonsterling/Agda-Sheaves", "max_issues_repo_path": "sheaves.agda", "max_line_length": 113, "max_stars_count": 1, "max_stars_repo_head_hexsha": "8a06162a8f0f7df308458db91d720cf8f7345d69", "max_stars_repo_licenses": [ "CC-BY-4.0" ], "max_stars_repo_name": "jonsterling/Agda-Sheaves", "max_stars_repo_path": "sheaves.agda", "max_stars_repo_stars_event_max_datetime": "2015-05-08T22:58:35.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-08T22:58:35.000Z", "num_tokens": 1946, "size": 4712 }
module Agda.Builtin.Nat where open import Agda.Builtin.Bool data Nat : Set where zero : Nat suc : (n : Nat) → Nat {-# BUILTIN NATURAL Nat #-} infix 4 _==_ _<_ infixl 6 _+_ _-_ infixl 7 _*_ _+_ : Nat → Nat → Nat zero + m = m suc n + m = suc (n + m) {-# BUILTIN NATPLUS _+_ #-} _-_ : Nat → Nat → Nat n - zero = n zero - suc m = zero suc n - suc m = n - m {-# BUILTIN NATMINUS _-_ #-} _*_ : Nat → Nat → Nat zero * m = zero suc n * m = m + n * m {-# BUILTIN NATTIMES _*_ #-} _==_ : Nat → Nat → Bool zero == zero = true suc n == suc m = n == m _ == _ = false {-# BUILTIN NATEQUALS _==_ #-} _<_ : Nat → Nat → Bool _ < zero = false zero < suc _ = true suc n < suc m = n < m {-# BUILTIN NATLESS _<_ #-} div-helper : Nat → Nat → Nat → Nat → Nat div-helper k m zero j = k div-helper k m (suc n) zero = div-helper (suc k) m n m div-helper k m (suc n) (suc j) = div-helper k m n j {-# BUILTIN NATDIVSUCAUX div-helper #-} mod-helper : Nat → Nat → Nat → Nat → Nat mod-helper k m zero j = k mod-helper k m (suc n) zero = mod-helper 0 m n m mod-helper k m (suc n) (suc j) = mod-helper (suc k) m n j {-# BUILTIN NATMODSUCAUX mod-helper #-}
{ "alphanum_fraction": 0.5556485356, "avg_line_length": 19.2741935484, "ext": "agda", "hexsha": "0e7c880b2195c173b2dd94e89882c8a0904aaa73", "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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "redfish64/autonomic-agda", "max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/Nat.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "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": "redfish64/autonomic-agda", "max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/Nat.agda", "max_line_length": 57, "max_stars_count": null, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/Nat.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 450, "size": 1195 }
{-# OPTIONS --safe #-} module Definition.Conversion.Reduction where open import Definition.Untyped open import Definition.Typed open import Definition.Typed.Properties open import Definition.Conversion -- Weak head expansion of algorithmic equality of types. reductionConv↑ : ∀ {A A′ B B′ r Γ} → Γ ⊢ A ⇒* A′ ^ r → Γ ⊢ B ⇒* B′ ^ r → Whnf A′ → Whnf B′ → Γ ⊢ A′ [conv↑] B′ ^ r → Γ ⊢ A [conv↑] B ^ r reductionConv↑ x x₁ x₂ x₃ ([↑] A″ B″ D D′ whnfA′ whnfB′ A′<>B′) rewrite whnfRed* D x₂ | whnfRed* D′ x₃ = [↑] A″ B″ x x₁ whnfA′ whnfB′ A′<>B′ -- Weak head expansion of algorithmic equality of terms. reductionConv↑Term : ∀ {t t′ u u′ A B Γ l} → Γ ⊢ A ⇒* B ^ [ ! , l ] → Γ ⊢ t ⇒* t′ ∷ B ^ l → Γ ⊢ u ⇒* u′ ∷ B ^ l → Whnf B → Whnf t′ → Whnf u′ → Γ ⊢ t′ [conv↑] u′ ∷ B ^ l → Γ ⊢ t [conv↑] u ∷ A ^ l reductionConv↑Term x x₁ x₂ x₃ x₄ x₅ ([↑]ₜ B₁ t″ u″ D d d′ whnfB whnft′ whnfu′ t<>u) rewrite whnfRed* D x₃ | whnfRed*Term d x₄ | whnfRed*Term d′ x₅ = [↑]ₜ B₁ t″ u″ x x₁ x₂ whnfB whnft′ whnfu′ t<>u
{ "alphanum_fraction": 0.4544049459, "avg_line_length": 34.0526315789, "ext": "agda", "hexsha": "ada986f14981666d635f4225de246176bce8855d", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z", "max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z", "max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "CoqHott/logrel-mltt", "max_forks_repo_path": "Definition/Conversion/Reduction.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "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": "CoqHott/logrel-mltt", "max_issues_repo_path": "Definition/Conversion/Reduction.agda", "max_line_length": 83, "max_stars_count": 2, "max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "CoqHott/logrel-mltt", "max_stars_repo_path": "Definition/Conversion/Reduction.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z", "max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z", "num_tokens": 466, "size": 1294 }
open import Agda.Builtin.IO open import Agda.Builtin.Size open import Agda.Builtin.Unit data D (i : Size) : Set where {-# FOREIGN GHC data Empty i #-} {-# COMPILE GHC D = data Empty () #-} f : ∀ {i} → D i → D i f () {-# COMPILE GHC f as f #-} postulate return : {A : Set} → A → IO A {-# COMPILE GHC return = \_ -> return #-} main : IO ⊤ main = return _
{ "alphanum_fraction": 0.5858310627, "avg_line_length": 14.68, "ext": "agda", "hexsha": "84418479a46592cbd1396ecaca174364031b583c", "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/Compiler/simple/Issue2879-1.agda", "max_issues_count": 16, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2019-09-08T13:47:04.000Z", "max_issues_repo_issues_event_min_datetime": "2018-10-08T00:32:04.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Compiler/simple/Issue2879-1.agda", "max_line_length": 41, "max_stars_count": 7, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Compiler/simple/Issue2879-1.agda", "max_stars_repo_stars_event_max_datetime": "2018-11-06T16:38:43.000Z", "max_stars_repo_stars_event_min_datetime": "2018-11-05T22:13:36.000Z", "num_tokens": 117, "size": 367 }
module Oscar.Class.Reflexive where open import Oscar.Level open import Oscar.Property.IsReflexive record Reflexive {𝔬} (⋆ : Set 𝔬) ℓ : Set (𝔬 ⊔ lsuc ℓ) where field _≣_ : ⋆ → ⋆ → Set ℓ isReflexive : IsReflexive ⋆ _≣_ open IsReflexive isReflexive public
{ "alphanum_fraction": 0.6940298507, "avg_line_length": 20.6153846154, "ext": "agda", "hexsha": "42695c6ffd213469e668f387eda71351d45877d0", "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/Class/Reflexive.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/Class/Reflexive.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-2/Oscar/Class/Reflexive.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 108, "size": 268 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category using (Category; module Commutation) open import Categories.Category.Monoidal.Core using (Monoidal) open import Categories.Category.Monoidal.Braided using (Braided) -- Braided monoidal categories satisfy the "four middle interchange" module Categories.Category.Monoidal.Interchange.Braided {o ℓ e} {C : Category o ℓ e} {M : Monoidal C} (B : Braided M) where open import Level using (_⊔_) open import Data.Product using (_,_) import Categories.Category.Construction.Core C as Core import Categories.Category.Monoidal.Construction.Product as MonoidalProduct open import Categories.Category.Monoidal.Braided.Properties as BraidedProps using (braiding-coherence; inv-Braided; inv-braiding-coherence) open import Categories.Category.Monoidal.Interchange using (HasInterchange) open import Categories.Category.Monoidal.Properties using (module Kelly's) import Categories.Category.Monoidal.Reasoning as MonoidalReasoning import Categories.Category.Monoidal.Utilities as MonoidalUtilities open import Categories.Category.Product using (_⁂_; assocˡ) open import Categories.Functor using (_∘F_) open import Categories.NaturalTransformation.NaturalIsomorphism using (_≃_; niHelper) open import Categories.Morphism.Reasoning C open Category C open Commutation C private variable W W₁ W₂ X X₁ X₂ Y Y₁ Y₂ Z Z₁ Z₂ : Obj f g h i : X ⇒ Y -- Braided monoidal categories have an interchange map. open MonoidalReasoning M open MonoidalUtilities M open Braided B renaming (associator to α) open Core.Shorthands -- for idᵢ, _∘ᵢ_, ... open Shorthands -- for λ⇒, ρ⇒, α⇒, ... open BraidedProps.Shorthands B -- for σ⇒, ... -- The "four middle interchange" for braided tensor products. swapInner : (W ⊗₀ X) ⊗₀ (Y ⊗₀ Z) ≅ (W ⊗₀ Y) ⊗₀ (X ⊗₀ Z) swapInner = α ⁻¹ ∘ᵢ idᵢ ⊗ᵢ (α ∘ᵢ σ ⊗ᵢ idᵢ ∘ᵢ α ⁻¹) ∘ᵢ α module swapInner {W X Y Z} = _≅_ (swapInner {W} {X} {Y} {Z}) private i⇒ = swapInner.from i⇐ = swapInner.to -- to shorten things, it is convenient to name some items that recur -- swapˡ is the inner part of 'swapInner' private swapˡ : X ⊗₀ (Y ⊗₀ Z) ⇒ Y ⊗₀ (X ⊗₀ Z) swapˡ = α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐ swapˡ-act : swapˡ ∘ g ⊗₁ (h ⊗₁ i) ≈ h ⊗₁ (g ⊗₁ i) ∘ swapˡ swapˡ-act {g = g} {h = h} {i = i} = begin (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ g ⊗₁ (h ⊗₁ i) ≈⟨ pullʳ (pullʳ assoc-commute-to) ⟩ α⇒ ∘ σ⇒ ⊗₁ id ∘ (g ⊗₁ h) ⊗₁ i ∘ α⇐ ≈⟨ refl⟩∘⟨ extendʳ (parallel (braiding.⇒.commute _) id-comm-sym) ⟩ α⇒ ∘ (h ⊗₁ g) ⊗₁ i ∘ σ⇒ ⊗₁ id ∘ α⇐ ≈⟨ extendʳ assoc-commute-from ⟩ h ⊗₁ (g ⊗₁ i) ∘ α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐ ∎ swapInner-natural : i⇒ ∘ (f ⊗₁ g) ⊗₁ (h ⊗₁ i) ≈ (f ⊗₁ h) ⊗₁ (g ⊗₁ i) ∘ i⇒ swapInner-natural {f = f} {g = g} {h = h} {i = i} = begin (α⇐ ∘ id ⊗₁ swapˡ ∘ α⇒) ∘ (f ⊗₁ g) ⊗₁ (h ⊗₁ i) ≈⟨ pullʳ (pullʳ assoc-commute-from) ⟩ α⇐ ∘ id ⊗₁ swapˡ ∘ f ⊗₁ g ⊗₁ (h ⊗₁ i) ∘ α⇒ ≈⟨ refl⟩∘⟨ extendʳ (parallel id-comm-sym swapˡ-act) ⟩ α⇐ ∘ f ⊗₁ h ⊗₁ (g ⊗₁ i) ∘ id ⊗₁ swapˡ ∘ α⇒ ≈⟨ extendʳ assoc-commute-to ⟩ (f ⊗₁ h) ⊗₁ (g ⊗₁ i) ∘ α⇐ ∘ id ⊗₁ swapˡ ∘ α⇒ ∎ swapInner-naturalIsomorphism : ⊗ ∘F (⊗ ⁂ ⊗) ≃ ⊗ ∘F MonoidalProduct.⊗ M M swapInner-naturalIsomorphism = niHelper (record { η = λ _ → i⇒ ; η⁻¹ = λ _ → i⇐ ; commute = λ _ → swapInner-natural ; iso = λ _ → swapInner.iso }) -- Another version of the interchange that associates differently. -- -- Why are there two versions and what's the difference? The domain -- (X₁ ⊗ X₂) ⊗₀ (Y₁ ⊗ Y₂) and codomain (X₁ ⊗ Y₁) ⊗₀ (X₁ ⊗ Y₂) of the -- interchange map are perfectly symmetric/balanced. But in order to -- apply the braiding to the middle X₂ and Y₁, we need to -- re-associate and that breaks the symmetry. We must first -- re-associate the whole expression in one direction and then the -- larger subterm in the other. This can be done in two ways, -- associate to the right first, then to the left, resulting in X₁ ⊗ -- ((Y₂ ⊗₀ X₁) ⊗ Y₂), or vice versa, resulting in (X₁ ⊗ (Y₂ ⊗₀ X₁)) -- ⊗ Y₂. The choice is arbitrary and results in two distinct -- interchange maps that behave the same way (as witnessed by -- swapInner-coherent below). -- -- Why define both? Because the proofs of some coherence laws become -- easier when the core of the expression is associated in one -- direction vs. the other. For example swapInner-unitˡ is easier to -- prove for the second definition, while swapInner-unitʳ is easier -- to prove for the first; swapInner-assoc uses both. swapInner′ : (W ⊗₀ X) ⊗₀ (Y ⊗₀ Z) ≅ (W ⊗₀ Y) ⊗₀ (X ⊗₀ Z) swapInner′ = α ∘ᵢ (α ⁻¹ ∘ᵢ idᵢ ⊗ᵢ σ ∘ᵢ α) ⊗ᵢ idᵢ ∘ᵢ α ⁻¹ module swapInner′ {W X Y Z} = _≅_ (swapInner′ {W} {X} {Y} {Z}) private j⇒ = swapInner′.from j⇐ = swapInner′.to swapʳ : (X ⊗₀ Y) ⊗₀ Z ⇒ (X ⊗₀ Z) ⊗₀ Y swapʳ = α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ -- Derived coherence laws. swapInner-coherent : [ (X₁ ⊗₀ X₂) ⊗₀ (Y₁ ⊗₀ Y₂) ⇒ (X₁ ⊗₀ Y₁) ⊗₀ (X₂ ⊗₀ Y₂) ]⟨ i⇒ ≈ j⇒ ⟩ swapInner-coherent = begin α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒ ≈⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩ α⇐ ∘ id ⊗₁ α⇒ ∘ id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒ ≈⟨ refl⟩∘⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩ α⇐ ∘ id ⊗₁ α⇒ ∘ id ⊗₁ (σ⇒ ⊗₁ id) ∘ id ⊗₁ α⇐ ∘ α⇒ ≈⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ conjugate-from α (idᵢ ⊗ᵢ α) (⟺ pentagon) ⟩ α⇐ ∘ id ⊗₁ α⇒ ∘ id ⊗₁ (σ⇒ ⊗₁ id) ∘ (α⇒ ∘ α⇒ ⊗₁ id) ∘ α⇐ ≈˘⟨ pullʳ (pullʳ (extendʳ (pushˡ assoc-commute-from))) ⟩ (α⇐ ∘ id ⊗₁ α⇒ ∘ α⇒ ∘ (id ⊗₁ σ⇒) ⊗₁ id) ∘ α⇒ ⊗₁ id ∘ α⇐ ≈⟨ pushʳ sym-assoc ⟩∘⟨refl ⟩ ((α⇐ ∘ id ⊗₁ α⇒ ∘ α⇒) ∘ (id ⊗₁ σ⇒) ⊗₁ id) ∘ α⇒ ⊗₁ id ∘ α⇐ ≈⟨ pushˡ (conjugate-from (α ⊗ᵢ idᵢ) α (assoc ○ pentagon)) ⟩∘⟨refl ⟩ (α⇒ ∘ α⇐ ⊗₁ id ∘ (id ⊗₁ σ⇒) ⊗₁ id) ∘ α⇒ ⊗₁ id ∘ α⇐ ≈˘⟨ pushʳ (pushʳ (pushˡ split₁ˡ)) ⟩ α⇒ ∘ α⇐ ⊗₁ id ∘ (id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐ ≈˘⟨ refl⟩∘⟨ pushˡ split₁ˡ ⟩ α⇒ ∘ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐ ∎ private α-mid : ∀ {X} {Y} {Z} {W} → X ⊗₀ ((Y ⊗₀ Z) ⊗₀ W) ⇒ (X ⊗₀ Y) ⊗₀ (Z ⊗₀ W) α-mid = α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐ private serialize-assoc : α⇒ {X₁} {Y₁} {Z₁} ⊗₁ α⇒ {X₂} {Y₂} {Z₂} ≈ id ⊗₁ α⇒ ∘ α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐) ∘ α⇒ ∘ id ⊗₁ α⇐ ∘ α⇒ serialize-assoc = begin α⇒ ⊗₁ α⇒ ≈⟨ serialize₂₁ ⟩ id ⊗₁ α⇒ ∘ α⇒ ⊗₁ id ≈⟨ refl⟩∘⟨ (begin α⇒ ⊗₁ id ≈⟨ switch-fromtoˡ α (switch-fromtoˡ (idᵢ ⊗ᵢ α) pentagon) ⟩ α⇐ ∘ id ⊗₁ α⇐ ∘ α⇒ ∘ α⇒ ≈˘⟨ refl⟩∘⟨ refl⟩⊗⟨ cancelˡ α.isoʳ ⟩∘⟨refl ⟩ α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇐ ∘ α⇐) ∘ α⇒ ∘ α⇒ ≈˘⟨ refl⟩∘⟨ refl⟩⊗⟨ pullʳ pentagon-inv ⟩∘⟨refl ⟩ α⇐ ∘ id ⊗₁ (α-mid ∘ id ⊗₁ α⇐) ∘ α⇒ ∘ α⇒ ≈⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩ α⇐ ∘ id ⊗₁ α-mid ∘ id ⊗₁ (id ⊗₁ α⇐) ∘ α⇒ ∘ α⇒ ≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ extendʳ assoc-commute-from ⟩ α⇐ ∘ id ⊗₁ α-mid ∘ α⇒ ∘ (id ⊗₁ id) ⊗₁ α⇐ ∘ α⇒ ≈⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ ⊗.identity ⟩⊗⟨refl ⟩∘⟨refl ⟩ α⇐ ∘ id ⊗₁ α-mid ∘ α⇒ ∘ id ⊗₁ α⇐ ∘ α⇒ ∎) ⟩ id ⊗₁ α⇒ ∘ α⇐ ∘ id ⊗₁ α-mid ∘ α⇒ ∘ id ⊗₁ α⇐ ∘ α⇒ ∎ swapInner-assoc : [ ((X₁ ⊗₀ X₂) ⊗₀ (Y₁ ⊗₀ Y₂)) ⊗₀ (Z₁ ⊗₀ Z₂) ⇒ (X₁ ⊗₀ (Y₁ ⊗₀ Z₁)) ⊗₀ (X₂ ⊗₀ (Y₂ ⊗₀ Z₂)) ]⟨ i⇒ ⊗₁ id ⇒⟨ ((X₁ ⊗₀ Y₁) ⊗₀ (X₂ ⊗₀ Y₂)) ⊗₀ (Z₁ ⊗₀ Z₂) ⟩ i⇒ ⇒⟨ ((X₁ ⊗₀ Y₁) ⊗₀ Z₁) ⊗₀ ((X₂ ⊗₀ Y₂) ⊗₀ Z₂) ⟩ α⇒ ⊗₁ α⇒ ≈ α⇒ ⇒⟨ (X₁ ⊗₀ X₂) ⊗₀ ((Y₁ ⊗₀ Y₂) ⊗₀ (Z₁ ⊗₀ Z₂)) ⟩ id ⊗₁ i⇒ ⇒⟨ (X₁ ⊗₀ X₂) ⊗₀ ((Y₁ ⊗₀ Z₁) ⊗₀ (Y₂ ⊗₀ Z₂)) ⟩ i⇒ ⟩ swapInner-assoc = begin α⇒ ⊗₁ α⇒ ∘ i⇒ ∘ i⇒ ⊗₁ id ≈⟨ serialize-assoc ⟩∘⟨refl ⟩ (id ⊗₁ α⇒ ∘ α⇐ ∘ id ⊗₁ α-mid ∘ α⇒ ∘ id ⊗₁ α⇐ ∘ α⇒) ∘ i⇒ ∘ i⇒ ⊗₁ id ≈˘⟨ pullˡ (pushˡ (⊗.identity ⟩⊗⟨refl ⟩∘⟨refl)) ⟩ ((id ⊗₁ id) ⊗₁ α⇒ ∘ α⇐) ∘ (id ⊗₁ α-mid ∘ α⇒ ∘ id ⊗₁ α⇐ ∘ α⇒) ∘ i⇒ ∘ i⇒ ⊗₁ id ≈⟨ ⟺ assoc-commute-to ⟩∘⟨ pullʳ (pullʳ (pushʳ (pushˡ (pushʳ (pushˡ split₂ˡ))))) ⟩ (α⇐ ∘ id ⊗₁ (id ⊗₁ α⇒)) ∘ id ⊗₁ α-mid ∘ α⇒ ∘ ((id ⊗₁ α⇐ ∘ α⇒) ∘ α⇐ ∘ id ⊗₁ α⇒) ∘ (id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘ i⇒ ⊗₁ id ≈⟨ pullʳ (refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ elimˡ (_≅_.isoˡ (α ⁻¹ ∘ᵢ idᵢ ⊗ᵢ α))) ⟩ α⇐ ∘ id ⊗₁ (id ⊗₁ α⇒) ∘ id ⊗₁ α-mid ∘ α⇒ ∘ (id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘ i⇒ ⊗₁ id ≈⟨ refl⟩∘⟨ merge₂ sym-assoc ⟩∘⟨ pushʳ ((⟺ ⊗.identity ⟩⊗⟨refl) ⟩∘⟨refl ⟩∘⟨ split₁ˡ) ⟩ α⇐ ∘ id ⊗₁ ((id ⊗₁ α⇒ ∘ α⇒) ∘ α⇐ ⊗₁ id ∘ α⇐) ∘ (α⇒ ∘ (id ⊗₁ id) ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘ α⇐ ⊗₁ id ∘ (id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ⊗₁ id ≈⟨ refl⟩∘⟨ refl⟩⊗⟨ extendʳ (pushˡ (switch-fromtoʳ (α ⊗ᵢ idᵢ) (assoc ○ pentagon))) ⟩∘⟨ extendʳ assoc-commute-from ⟩∘⟨refl ⟩ α⇐ ∘ id ⊗₁ ((α⇒ ∘ α⇒) ∘ (α⇐ ⊗₁ id ∘ α⇐ ⊗₁ id) ∘ α⇐) ∘ (id ⊗₁ (id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐)) ∘ (α⇒ ∘ α⇒)) ∘ α⇐ ⊗₁ id ∘ (id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ⊗₁ id ≈˘⟨ refl⟩∘⟨ refl⟩⊗⟨ pushʳ (refl⟩∘⟨ split₁ˡ ⟩∘⟨refl) ⟩∘⟨ pushʳ (extendʳ (switch-fromtoʳ (α ⊗ᵢ idᵢ) (assoc ○ pentagon))) ⟩ α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐) ∘ id ⊗₁ (id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐)) ∘ id ⊗₁ α⇒ ∘ α⇒ ∘ (id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ⊗₁ id ≈⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ split₁ˡ ⟩ α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐) ∘ id ⊗₁ (id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐)) ∘ id ⊗₁ α⇒ ∘ α⇒ ∘ (id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐)) ⊗₁ id ∘ α⇒ ⊗₁ id ≈⟨ refl⟩∘⟨ merge₂ assoc²' ○ (refl⟩∘⟨ refl⟩∘⟨ assoc) ⟩∘⟨ refl⟩∘⟨ extendʳ assoc-commute-from ⟩ α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐)) ∘ id ⊗₁ α⇒ ∘ id ⊗₁ ((α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id) ∘ α⇒ ∘ α⇒ ⊗₁ id ≈⟨ refl⟩∘⟨ merge₂ (assoc²' ○ (refl⟩∘⟨ refl⟩∘⟨ assoc²')) ⟩∘⟨ refl⟩∘⟨ switch-fromtoˡ (idᵢ ⊗ᵢ α) pentagon ⟩ α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘ id ⊗₁ ((α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id) ∘ id ⊗₁ α⇐ ∘ α⇒ ∘ α⇒ ≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩ α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒) ∘ id ⊗₁ ((α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐) ∘ α⇒ ∘ α⇒ ≈⟨ refl⟩∘⟨ merge₂ assoc²' ○ (refl⟩∘⟨ refl⟩∘⟨ (assoc²' ○ (refl⟩∘⟨ refl⟩∘⟨ assoc))) ⟩∘⟨ Equiv.refl ⟩ α⇐ ∘ id ⊗₁ (α⇒ ∘ α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒ ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐) ∘ α⇒ ∘ α⇒ ≈⟨ refl⟩∘⟨ refl⟩⊗⟨ pushʳ (begin α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒ ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐ ≈⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ extendʳ (pushˡ split₂ˡ) ⟩ α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (σ⇒ ⊗₁ id) ∘ (id ⊗₁ α⇐ ∘ α⇒) ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐ ≈⟨ refl⟩∘⟨ refl⟩∘⟨ (extendʳ assoc-commute-to ○ (refl⟩∘⟨ sym-assoc)) ⟩ α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ (id ⊗₁ σ⇒) ⊗₁ id ∘ (α⇐ ∘ (id ⊗₁ α⇐ ∘ α⇒)) ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐ ≈⟨ refl⟩∘⟨ refl⟩∘⟨ refl⟩∘⟨ (sym-assoc ○ (conjugate-to α (α ⊗ᵢ idᵢ) (sym-assoc ○ pentagon-inv))) ⟩∘⟨refl ⟩ α⇒ ∘ (α⇐ ∘ α⇐) ⊗₁ id ∘ (id ⊗₁ σ⇒) ⊗₁ id ∘ (α⇒ ⊗₁ id ∘ α⇐) ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐ ≈˘⟨ refl⟩∘⟨ split₁ Equiv.refl ⟩∘⟨ pushʳ (refl⟩∘⟨ refl⟩⊗⟨ ⊗.identity ⟩∘⟨refl) ⟩ α⇒ ∘ ((α⇐ ∘ α⇐) ∘ id ⊗₁ σ⇒) ⊗₁ id ∘ α⇒ ⊗₁ id ∘ α⇐ ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ (id ⊗₁ id) ∘ α⇐ ≈⟨ refl⟩∘⟨ merge₁ assoc² ⟩∘⟨ extendʳ assoc-commute-to ⟩ α⇒ ∘ (α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ ((α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id) ⊗₁ id ∘ α⇐ ∘ α⇐ ≈˘⟨ refl⟩∘⟨ pushˡ split₁ˡ ⟩ α⇒ ∘ ((α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id) ⊗₁ id ∘ α⇐ ∘ α⇐ ≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ (sym-assoc ○ pentagon-inv) ⟩ α⇒ ∘ ((α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id) ⊗₁ id ∘ α⇐ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇐ ≈⟨ refl⟩∘⟨ pullˡ (⟺ split₁ˡ ○ (assoc ⟩⊗⟨refl)) ⟩ α⇒ ∘ ((α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇐ ≈⟨ refl⟩∘⟨ (begin (α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐ ≈⟨ pushˡ (pushʳ sym-assoc) ⟩ (α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒) ∘ α⇒ ∘ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐ ≈⟨ (refl⟩∘⟨ extendʳ (pushʳ split₁ˡ)) ⟩ (α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒) ∘ (α⇒ ∘ α⇒ ⊗₁ id) ∘ (σ⇒ ⊗₁ id ∘ α⇐) ⊗₁ id ∘ α⇐ ≈⟨ pushʳ (switch-fromtoˡ (idᵢ ⊗ᵢ α) pentagon ⟩∘⟨ pushˡ split₁ˡ) ⟩ ((α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒) ∘ (id ⊗₁ α⇐ ∘ α⇒ ∘ α⇒)) ∘ (σ⇒ ⊗₁ id) ⊗₁ id ∘ α⇐ ⊗₁ id ∘ α⇐ ≈⟨ pushˡ (sym-assoc ○ (pullˡ (pullʳ assoc ⟩∘⟨refl))) ⟩ ((α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ id ⊗₁ α⇐) ∘ α⇒) ∘ α⇒ ∘ (σ⇒ ⊗₁ id) ⊗₁ id ∘ α⇐ ⊗₁ id ∘ α⇐ ≈⟨ pullʳ (refl⟩∘⟨ extendʳ assoc-commute-from) ⟩ (α⇐ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ id ⊗₁ α⇐) ∘ α⇒ ∘ σ⇒ ⊗₁ (id ⊗₁ id) ∘ α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐ ≈⟨ (refl⟩∘⟨ refl⟩∘⟨ ⟺ split₂ˡ) ⟩∘⟨ refl⟩∘⟨ (refl⟩⊗⟨ ⊗.identity ⟩∘⟨ conjugate-from (idᵢ ⊗ᵢ (α ⁻¹)) (α ⁻¹) pentagon-inv) ⟩ (α⇐ ∘ α⇐ ∘ id ⊗₁ (σ⇒ ∘ α⇐)) ∘ α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒ ≈˘⟨ extendʳ (sym-assoc ○ pentagon-inv) ⟩∘⟨refl ⟩ (α⇐ ⊗₁ id ∘ (α⇐ ∘ id ⊗₁ α⇐) ∘ id ⊗₁ (σ⇒ ∘ α⇐)) ∘ α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒ ≈˘⟨ (refl⟩∘⟨ pushʳ split₂ˡ) ⟩∘⟨refl ⟩ (α⇐ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (α⇐ ∘ σ⇒ ∘ α⇐)) ∘ α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒ ≈˘⟨ pushˡ ((refl⟩∘⟨ refl⟩∘⟨ refl⟩⊗⟨ (sym-assoc ○ hexagon₂ ○ assoc)) ⟩∘⟨refl) ⟩ ((α⇐ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ σ⇒)) ∘ α⇒) ∘ σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒ ≈⟨ pushˡ (pushʳ (pushʳ split₂ˡ)) ⟩∘⟨refl ⟩ ((α⇐ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ σ⇒ ⊗₁ id) ∘ id ⊗₁ (α⇐ ∘ id ⊗₁ σ⇒) ∘ α⇒) ∘ σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒ ≈⟨ pushʳ (pushˡ split₂ˡ) ⟩∘⟨refl ⟩ (((α⇐ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ σ⇒ ⊗₁ id) ∘ id ⊗₁ α⇐) ∘ id ⊗₁ id ⊗₁ σ⇒ ∘ α⇒) ∘ σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒ ≈⟨ ((pushˡ (pushʳ assoc-commute-to) ⟩∘⟨ ⟺ assoc-commute-from) ○ (pullʳ sym-assoc)) ⟩∘⟨refl ⟩ ((α⇐ ⊗₁ id ∘ (id ⊗₁ σ⇒) ⊗₁ id) ∘ ((α⇐ ∘ id ⊗₁ α⇐) ∘ α⇒) ∘ (id ⊗₁ id) ⊗₁ σ⇒) ∘ σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒ ≈⟨ pullˡ (⟺ split₁ˡ ⟩∘⟨ conjugate-from α (idᵢ ⊗ᵢ α ∘ᵢ α) (⟺ (assoc ○ pentagon))) ⟩∘⟨refl ⟩ (((α⇐ ∘ id ⊗₁ σ⇒) ⊗₁ id ∘ α⇒ ⊗₁ id ∘ α⇐) ∘ (id ⊗₁ id) ⊗₁ σ⇒) ∘ σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒ ≈⟨ (pullˡ (⟺ split₁ˡ) ⟩∘⟨ ⊗.identity ⟩⊗⟨refl) ⟩∘⟨refl ⟩ ((((α⇐ ∘ id ⊗₁ σ⇒) ∘ α⇒) ⊗₁ id ∘ α⇐) ∘ id ⊗₁ σ⇒) ∘ σ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇒ ≈⟨ extend² (⟺ serialize₂₁ ○ serialize₁₂) ⟩ ((((α⇐ ∘ id ⊗₁ σ⇒) ∘ α⇒) ⊗₁ id ∘ α⇐) ∘ σ⇒ ⊗₁ id) ∘ id ⊗₁ σ⇒ ∘ α⇐ ∘ id ⊗₁ α⇒ ≈˘⟨ pushʳ (refl⟩∘⟨ refl⟩⊗⟨ ⊗.identity) ⟩∘⟨ ⊗.identity ⟩⊗⟨refl ⟩∘⟨refl ⟩ (((α⇐ ∘ id ⊗₁ σ⇒) ∘ α⇒) ⊗₁ id ∘ α⇐ ∘ σ⇒ ⊗₁ id ⊗₁ id) ∘ (id ⊗₁ id) ⊗₁ σ⇒ ∘ α⇐ ∘ id ⊗₁ α⇒ ≈⟨ pushʳ assoc-commute-to ⟩∘⟨ extendʳ (⟺ assoc-commute-to) ⟩ ((((α⇐ ∘ id ⊗₁ σ⇒) ∘ α⇒) ⊗₁ id ∘ (σ⇒ ⊗₁ id) ⊗₁ id) ∘ α⇐) ∘ α⇐ ∘ id ⊗₁ id ⊗₁ σ⇒ ∘ id ⊗₁ α⇒ ≈˘⟨ ((sym-assoc ○ sym-assoc) ⟩⊗⟨refl ○ split₁ˡ) ⟩∘⟨refl ⟩∘⟨ refl⟩∘⟨ split₂ˡ ⟩ (((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ⊗₁ id) ∘ α⇐) ∘ α⇐ ∘ id ⊗₁ (id ⊗₁ σ⇒ ∘ α⇒) ≈˘⟨ extend² (sym-assoc ○ pentagon-inv) ⟩ (((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ⊗₁ id) ∘ α⇐ ⊗₁ id) ∘ (α⇐ ∘ id ⊗₁ α⇐) ∘ id ⊗₁ (id ⊗₁ σ⇒ ∘ α⇒) ≈˘⟨ split₁ˡ ⟩∘⟨ pushʳ split₂ˡ ⟩ ((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ∎) ⟩⊗⟨refl ⟩∘⟨refl ⟩ α⇒ ∘ (((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒)) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇐ ≈⟨ (refl⟩∘⟨ pushˡ ((sym-assoc ⟩⊗⟨refl) ○ split₁ˡ)) ⟩ α⇒ ∘ (((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ id ∘ α⇐) ⊗₁ id ∘ (id ⊗₁ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒)) ⊗₁ id ∘ α⇐ ∘ id ⊗₁ α⇐ ≈⟨ (refl⟩∘⟨ split₁ˡ ⟩∘⟨ extendʳ (⟺ assoc-commute-to)) ○ pushʳ assoc ⟩ (α⇒ ∘ (((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ id) ⊗₁ id) ∘ α⇐ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ id ⊗₁ α⇐ ≈⟨ pushˡ assoc-commute-from ⟩ ((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ (id ⊗₁ id) ∘ α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ id ⊗₁ α⇐ ≈˘⟨ refl⟩∘⟨ pullʳ (pullʳ (refl⟩∘⟨ split₂ˡ)) ⟩ ((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ (id ⊗₁ id) ∘ (α⇒ ∘ α⇐ ⊗₁ id ∘ α⇐) ∘ id ⊗₁ ((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐) ≈˘⟨ pullʳ (pullˡ (conjugate-from (α ∘ᵢ α ⊗ᵢ idᵢ) α pentagon)) ⟩ (((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ (id ⊗₁ id) ∘ α⇐) ∘ id ⊗₁ α⇒ ∘ id ⊗₁ ((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐) ≈⟨ refl⟩⊗⟨ ⊗.identity ⟩∘⟨refl ⟩∘⟨ ⟺ split₂ˡ ⟩ (((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ id ∘ α⇐) ∘ id ⊗₁ (α⇒ ∘ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐) ≡⟨⟩ (((α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐) ⊗₁ id ∘ α⇐) ∘ id ⊗₁ j⇒ ≈˘⟨ switch-fromtoʳ α (switch-fromtoˡ α (⟺ hexagon₁)) ⟩⊗⟨refl ⟩∘⟨refl ⟩∘⟨refl ⟩ (σ⇒ ⊗₁ id ∘ α⇐) ∘ id ⊗₁ j⇒ ∎) ⟩∘⟨refl ⟩ α⇐ ∘ id ⊗₁ ((α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ id ⊗₁ j⇒) ∘ α⇒ ∘ α⇒ ≈⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩ α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ id ⊗₁ id ⊗₁ j⇒ ∘ α⇒ ∘ α⇒ ≈˘⟨ pullʳ (pullʳ (extendʳ assoc-commute-from)) ⟩ (α⇐ ∘ id ⊗₁ swapˡ ∘ α⇒) ∘ (id ⊗₁ id) ⊗₁ j⇒ ∘ α⇒ ≡⟨⟩ i⇒ ∘ (id ⊗₁ id) ⊗₁ j⇒ ∘ α⇒ ≈⟨ refl⟩∘⟨ ⊗.identity ⟩⊗⟨ ⟺ swapInner-coherent ⟩∘⟨refl ⟩ i⇒ ∘ id ⊗₁ i⇒ ∘ α⇒ ∎ private mid-1-elim-coh : [ X ⊗₀ (unit ⊗₀ Y) ⇒ X ⊗₀ Y ]⟨ λ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐ ≈ id ⊗₁ λ⇒ ⟩ mid-1-elim-coh = begin λ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐ ≈⟨ pullˡ (Kelly's.coherence₁ M) ⟩ λ⇒ ⊗₁ id ∘ σ⇒ ⊗₁ id ∘ α⇐ ≈˘⟨ pushˡ split₁ˡ ⟩ (λ⇒ ∘ σ⇒) ⊗₁ id ∘ α⇐ ≈⟨ braiding-coherence B ⟩⊗⟨refl ⟩∘⟨refl ⟩ ρ⇒ ⊗₁ id ∘ α⇐ ≈˘⟨ switch-fromtoʳ α triangle ⟩ id ⊗₁ λ⇒ ∎ Kelly₁′ : [ unit ⊗₀ (X ⊗₀ Y) ⇒ X ⊗₀ Y ]⟨ λ⇒ ⊗₁ id ∘ α⇐ ≈ λ⇒ ⟩ Kelly₁′ = ⟺ (switch-fromtoʳ α (Kelly's.coherence₁ M)) Kelly₂′ : [ X ⊗₀ (Y ⊗₀ unit) ⇒ X ⊗₀ Y ]⟨ ρ⇒ ∘ α⇐ ≈ id ⊗₁ ρ⇒ ⟩ Kelly₂′ = ⟺ (switch-fromtoʳ α (Kelly's.coherence₂ M)) σ⁻¹-coherence : [ unit ⊗₀ X ⇒ X ]⟨ ρ⇒ ∘ σ⇒ ≈ λ⇒ ⟩ σ⁻¹-coherence = inv-braiding-coherence (inv-Braided B) swapInner-unitˡ : [ unit ⊗₀ (X ⊗₀ Y) ⇒ (X ⊗₀ Y) ]⟨ λ⇐ ⊗₁ id ⇒⟨ (unit ⊗₀ unit) ⊗₀ (X ⊗₀ Y) ⟩ i⇒ ⇒⟨ (unit ⊗₀ X) ⊗₀ (unit ⊗₀ Y) ⟩ λ⇒ ⊗₁ λ⇒ ≈ λ⇒ ⟩ swapInner-unitˡ = begin λ⇒ ⊗₁ λ⇒ ∘ i⇒ ∘ λ⇐ ⊗₁ id ≈⟨ refl⟩∘⟨ swapInner-coherent ⟩∘⟨ (Kelly's.coherence-inv₃ M ⟩⊗⟨refl) ⟩ λ⇒ ⊗₁ λ⇒ ∘ j⇒ ∘ ρ⇐ ⊗₁ id ≈⟨ pullˡ (pushˡ serialize₁₂) ⟩ (λ⇒ ⊗₁ id ∘ id ⊗₁ λ⇒ ∘ α⇒ ∘ swapʳ ⊗₁ id ∘ α⇐) ∘ ρ⇐ ⊗₁ id ≈⟨ (refl⟩∘⟨ (begin id ⊗₁ λ⇒ ∘ α⇒ ∘ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐ ≈⟨ pullˡ triangle ⟩ ρ⇒ ⊗₁ id ∘ (α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐ ≈˘⟨ pushˡ split₁ˡ ⟩ (ρ⇒ ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐ ≈⟨ (pullˡ Kelly₂′ ⟩⊗⟨refl ⟩∘⟨refl) ⟩ (id ⊗₁ ρ⇒ ∘ id ⊗₁ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐ ≈˘⟨ pushˡ split₂ˡ ⟩⊗⟨refl ⟩∘⟨refl ⟩ (id ⊗₁ (ρ⇒ ∘ σ⇒) ∘ α⇒) ⊗₁ id ∘ α⇐ ≈⟨ (refl⟩⊗⟨ σ⁻¹-coherence ⟩∘⟨refl) ⟩⊗⟨refl ⟩∘⟨refl ⟩ (id ⊗₁ λ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐ ≈⟨ triangle ⟩⊗⟨refl ⟩∘⟨refl ⟩ (ρ⇒ ⊗₁ id) ⊗₁ id ∘ α⇐ ≈˘⟨ assoc-commute-to ⟩ α⇐ ∘ ρ⇒ ⊗₁ (id ⊗₁ id) ∎)) ⟩∘⟨refl ⟩ (λ⇒ ⊗₁ id ∘ α⇐ ∘ ρ⇒ ⊗₁ (id ⊗₁ id)) ∘ ρ⇐ ⊗₁ id ≈⟨ (sym-assoc ○ (Kelly₁′ ⟩∘⟨ refl⟩⊗⟨ ⊗.identity)) ⟩∘⟨refl ⟩ (λ⇒ ∘ ρ⇒ ⊗₁ id) ∘ ρ⇐ ⊗₁ id ≈⟨ cancelʳ (_≅_.isoʳ (unitorʳ ⊗ᵢ idᵢ)) ⟩ λ⇒ ∎ swapInner-unitʳ : [ (X ⊗₀ Y) ⊗₀ unit ⇒ (X ⊗₀ Y) ]⟨ id ⊗₁ λ⇐ ⇒⟨ (X ⊗₀ Y) ⊗₀ (unit ⊗₀ unit) ⟩ i⇒ ⇒⟨ (X ⊗₀ unit) ⊗₀ (Y ⊗₀ unit) ⟩ ρ⇒ ⊗₁ ρ⇒ ≈ ρ⇒ ⟩ swapInner-unitʳ = begin ρ⇒ ⊗₁ ρ⇒ ∘ i⇒ ∘ id ⊗₁ λ⇐ ≡⟨⟩ ρ⇒ ⊗₁ ρ⇒ ∘ (α⇐ ∘ id ⊗₁ swapˡ ∘ α⇒) ∘ id ⊗₁ λ⇐ ≈⟨ pullˡ (pushˡ serialize₂₁) ⟩ (id ⊗₁ ρ⇒ ∘ ρ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ swapˡ ∘ α⇒) ∘ id ⊗₁ λ⇐ ≈⟨ (refl⟩∘⟨ (begin ρ⇒ ⊗₁ id ∘ α⇐ ∘ id ⊗₁ swapˡ ∘ α⇒ ≈˘⟨ pushˡ (switch-fromtoʳ α triangle) ⟩ id ⊗₁ λ⇒ ∘ id ⊗₁ swapˡ ∘ α⇒ ≈˘⟨ pushˡ split₂ˡ ⟩ id ⊗₁ (λ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒ ≈⟨ refl⟩⊗⟨ mid-1-elim-coh ⟩∘⟨refl ⟩ id ⊗₁ (id ⊗₁ λ⇒) ∘ α⇒ ≈˘⟨ assoc-commute-from ⟩ α⇒ ∘ (id ⊗₁ id) ⊗₁ λ⇒ ≈⟨ refl⟩∘⟨ ⊗.identity ⟩⊗⟨refl ⟩ α⇒ ∘ id ⊗₁ λ⇒ ∎)) ⟩∘⟨refl ⟩ (id ⊗₁ ρ⇒ ∘ α⇒ ∘ id ⊗₁ λ⇒) ∘ id ⊗₁ λ⇐ ≈⟨ (sym-assoc ○ (Kelly's.coherence₂ M ⟩∘⟨refl )) ⟩∘⟨refl ⟩ (ρ⇒ ∘ id ⊗₁ λ⇒) ∘ id ⊗₁ λ⇐ ≈⟨ cancelʳ (_≅_.isoʳ (idᵢ ⊗ᵢ unitorˡ)) ⟩ ρ⇒ ∎ -- Two different ways of swapping things around are the same private [23][14]ʳ : [ (X ⊗₀ Y) ⊗₀ (Z ⊗₀ W) ⇒ (Y ⊗₀ Z) ⊗₀ (X ⊗₀ W) ]⟨ α⇒ ∘ swapʳ ⊗₁ id ∘ (σ⇒ ⊗₁ id) ⊗₁ id ∘ α⇐ ≈ (α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇒ ⊗₁ id ∘ α⇐ ⟩ [23][14]ʳ = begin (α⇒ ∘ swapʳ ⊗₁ id ∘ (σ⇒ ⊗₁ id) ⊗₁ id ∘ α⇐) ≈˘⟨ refl⟩∘⟨ pushˡ split₁ˡ ⟩ (α⇒ ∘ (swapʳ ∘ σ⇒ ⊗₁ id) ⊗₁ id ∘ α⇐) ≈⟨ refl⟩∘⟨ pullʳ (assoc ○ hexagon₁) ⟩⊗⟨refl ⟩∘⟨refl ⟩ (α⇒ ∘ (α⇐ ∘ α⇒ ∘ σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐) ≈⟨ refl⟩∘⟨ cancelˡ α.isoˡ ⟩⊗⟨refl ⟩∘⟨refl ⟩ (α⇒ ∘ (σ⇒ ∘ α⇒) ⊗₁ id ∘ α⇐) ≈⟨ extendʳ (pushʳ split₁ˡ) ⟩ ((α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇒ ⊗₁ id ∘ α⇐) ∎ [13][42]ˡ : [ (X ⊗₀ Y) ⊗₀ (Z ⊗₀ W) ⇒ (X ⊗₀ Z) ⊗₀ (W ⊗₀ Y) ]⟨ α⇐ ∘ id ⊗₁ (id ⊗₁ σ⇒) ∘ id ⊗₁ swapˡ ∘ α⇒ ≈ (α⇐ ∘ id ⊗₁ α⇒) ∘ id ⊗₁ σ⇒ ∘ α⇒ ⟩ [13][42]ˡ = begin α⇐ ∘ id ⊗₁ (id ⊗₁ σ⇒) ∘ id ⊗₁ swapˡ ∘ α⇒ ≈˘⟨ refl⟩∘⟨ pushˡ split₂ˡ ⟩ α⇐ ∘ id ⊗₁ (id ⊗₁ σ⇒ ∘ α⇒ ∘ σ⇒ ⊗₁ id ∘ α⇐) ∘ α⇒ ≈⟨ refl⟩∘⟨ refl⟩⊗⟨ (⟺ assoc ○ (pullˡ (assoc ○ hexagon₁))) ⟩∘⟨refl ⟩ α⇐ ∘ id ⊗₁ ((α⇒ ∘ σ⇒ ∘ α⇒) ∘ α⇐) ∘ α⇒ ≈⟨ refl⟩∘⟨ refl⟩⊗⟨ pullʳ (cancelʳ α.isoʳ) ⟩∘⟨refl ⟩ α⇐ ∘ id ⊗₁ (α⇒ ∘ σ⇒) ∘ α⇒ ≈⟨ extendʳ (pushʳ split₂ˡ) ⟩ (α⇐ ∘ id ⊗₁ α⇒) ∘ id ⊗₁ σ⇒ ∘ α⇒ ∎ swapInner-braiding : [ (W ⊗₀ X) ⊗₀ (Y ⊗₀ Z) ⇒ (Y ⊗₀ Z) ⊗₀ (W ⊗₀ X) ]⟨ i⇒ ⇒⟨ (W ⊗₀ Y) ⊗₀ (X ⊗₀ Z) ⟩ σ⇒ ⊗₁ σ⇒ ⇒⟨ (Y ⊗₀ W) ⊗₀ (Z ⊗₀ X) ⟩ i⇒ ≈ σ⇒ ⟩ swapInner-braiding = begin i⇒ ∘ σ⇒ ⊗₁ σ⇒ ∘ i⇒ ≡⟨⟩ i⇒ ∘ σ⇒ ⊗₁ σ⇒ ∘ α⇐ ∘ id ⊗₁ swapˡ ∘ α⇒ ≈⟨ swapInner-coherent ⟩∘⟨ pushˡ serialize₁₂ ⟩ j⇒ ∘ σ⇒ ⊗₁ id ∘ id ⊗₁ σ⇒ ∘ α⇐ ∘ id ⊗₁ swapˡ ∘ α⇒ ≈˘⟨ ((refl⟩∘⟨ refl⟩⊗⟨ ⊗.identity) ⟩∘⟨ ⊗.identity ⟩⊗⟨refl ⟩∘⟨refl) ○ assoc ⟩ ((α⇒ ∘ swapʳ ⊗₁ id ∘ α⇐) ∘ σ⇒ ⊗₁ (id ⊗₁ id)) ∘ (id ⊗₁ id) ⊗₁ σ⇒ ∘ α⇐ ∘ id ⊗₁ swapˡ ∘ α⇒ ≈⟨ pullʳ (pullʳ assoc-commute-to) ⟩∘⟨ extendʳ (⟺ assoc-commute-to) ⟩ (α⇒ ∘ swapʳ ⊗₁ id ∘ (σ⇒ ⊗₁ id) ⊗₁ id ∘ α⇐) ∘ α⇐ ∘ id ⊗₁ (id ⊗₁ σ⇒) ∘ id ⊗₁ swapˡ ∘ α⇒ ≈⟨ [23][14]ʳ ⟩∘⟨ [13][42]ˡ ⟩ ((α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇒ ⊗₁ id ∘ α⇐) ∘ (α⇐ ∘ id ⊗₁ α⇒) ∘ id ⊗₁ σ⇒ ∘ α⇒ ≈˘⟨ extendʳ (pushʳ (pushʳ assoc)) ⟩ (α⇒ ∘ σ⇒ ⊗₁ id) ∘ (α⇒ ⊗₁ id ∘ (α⇐ ∘ α⇐) ∘ id ⊗₁ α⇒) ∘ id ⊗₁ σ⇒ ∘ α⇒ ≈˘⟨ refl⟩∘⟨ switch-tofromˡ (α ⊗ᵢ idᵢ) (switch-tofromʳ (idᵢ ⊗ᵢ α) pentagon-inv) ⟩∘⟨refl ⟩ (α⇒ ∘ σ⇒ ⊗₁ id) ∘ α⇐ ∘ id ⊗₁ σ⇒ ∘ α⇒ ≈⟨ pullʳ (sym-assoc ○ pullˡ hexagon₂) ⟩ α⇒ ∘ ((α⇐ ∘ σ⇒) ∘ α⇐) ∘ α⇒ ≈⟨ (refl⟩∘⟨ cancelʳ α.isoˡ) ⟩ α⇒ ∘ (α⇐ ∘ σ⇒) ≈⟨ cancelˡ α.isoʳ ⟩ σ⇒ ∎ -- Braided monoidal categories have an interchange. hasInterchange : HasInterchange M hasInterchange = record { swapInner = swapInner ; natural = swapInner-natural ; assoc = swapInner-assoc ; unitˡ = swapInner-unitˡ ; unitʳ = swapInner-unitʳ } open HasInterchange hasInterchange public using (naturalIso)
{ "alphanum_fraction": 0.3773663644, "avg_line_length": 62.6104513064, "ext": "agda", "hexsha": "f5d225f5d4440fac20e229360e484683b7dcd716", "lang": "Agda", "max_forks_count": 64, "max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z", "max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_path": "src/Categories/Category/Monoidal/Interchange/Braided.agda", "max_issues_count": 236, "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Code-distancing/agda-categories", "max_issues_repo_path": "src/Categories/Category/Monoidal/Interchange/Braided.agda", "max_line_length": 158, "max_stars_count": 279, "max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Trebor-Huang/agda-categories", "max_stars_repo_path": "src/Categories/Category/Monoidal/Interchange/Braided.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z", "num_tokens": 15078, "size": 26359 }
module Min where open import Data.Nat using (ℕ; zero; suc) open import Algebra.Bundles using (CommutativeRing) open import Algebra.Module.Bundles using (Module) open import Data.Product using (Σ-syntax; ∃-syntax; _×_; proj₁; proj₂; _,_) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Relation.Binary.Core using (Rel) import Algebra.Module.Construct.Zero as Zero import Algebra.Module.Construct.DirectProduct as Prod import Algebra.Module.Construct.TensorUnit as Unit module _ {r ℓr} {CR : CommutativeRing r ℓr} {ma ℓma} (MA : Module CR ma ℓma) {mb ℓmb} (MB : Module CR mb ℓmb) where open import Linear MA MB module _ {rel} (_<_ : Rel (CommutativeRing.Carrier CR) rel) (∥_∥ᴬ : A → R) (∥_∥ᴮ : B → R) (_÷_ : B → R → B) where _LimitOf_x→_ Limit-syntax : (L : B) (f : A → B) (c : A)→ Set _ L LimitOf f x→ c = ∀ ε → ∃[ δ ] ∥ (f (c +ᴬ δ) -ᴮ L) ∥ᴮ < ∥ ε ∥ᴮ Limit-syntax = _LimitOf_x→_ syntax Limit-syntax L (λ h → f) c = L LimitOf f ∶ h ⟶ c Diff' : (f : A → B) (x : A) (f' : A → A → B) → Set _ Diff' f x f' = 0ᴮ LimitOf tmp dx ∶ dx ⟶ 0ᴬ where tmp : (dx : A) → B tmp dx = (f (x +ᴬ dx) -ᴮ f x -ᴮ f' x dx) ÷ ∥ dx ∥ᴬ Differentiable : (f : A → B) → A → Set _ Differentiable f x = Σ[ f' ∈ (A → A → B) ] Linear (f' x) -- × ∀ dy → ∃[ dx ] (∥ ((f (x +ᴬ dx) -ᴮ f x) -ᴮ (f' x dx)) ∥ᴮ) < (∥ dy ∥ᴮ) D : {f : A → B} {x : A} (d : Differentiable f x) → A → B D {x = x} d = proj₁ d x n-module : ∀ {a b} {S : CommutativeRing a b} → ℕ → Module S a b n-module zero = Zero.⟨module⟩ n-module (suc n) = Prod.⟨module⟩ Unit.⟨module⟩ (n-module n) open import Tactic.RingSolver module Line {a b} (CR : CommutativeRing a b) where open CommutativeRing CR open import Relation.Binary.Reasoning.Setoid setoid open import Tactic.RingSolver.Core.AlmostCommutativeRing line : Carrier → Carrier → Carrier → Carrier line m b x = m * x + b x+y-x≈y : ∀ x y → (x + y) - x ≈ y x+y-x≈y x y = begin (x + y) - x ≈⟨ +-assoc x y (- x) ⟩ x + (y - x) ≈⟨ +-cong refl (+-comm y (- x)) ⟩ x + (- x + y) ≈⟨ sym (+-assoc x (- x) y) ⟩ (x - x) + y ≈⟨ +-cong (proj₂ -‿inverse x) refl ⟩ 0# + y ≈⟨ +-identityˡ y ⟩ y ∎ x+y+z≈x+z+y : ∀ x y z → x + y + z ≈ x + z + y x+y+z≈x+z+y x y z = begin (x + y) + z ≈⟨ +-assoc x y z ⟩ x + (y + z) ≈⟨ +-cong refl (+-comm y z) ⟩ x + (z + y) ≈⟨ sym (+-assoc x z y) ⟩ (x + z) + y ∎ linear-diff : ∀ m b x dy → line m b (x + dy) - line m b x ≈ m * dy linear-diff m b x dy = begin m * (x + dy) + b - (m * x + b) ≈⟨ +-cong (+-cong (distribˡ m x dy) refl) refl ⟩ m * x + m * dy + b - (m * x + b) ≈⟨ +-cong (x+y+z≈x+z+y (m * x) (m * dy) b) refl ⟩ m * x + b + m * dy - (m * x + b) ≈⟨ x+y-x≈y (m * x + b) (m * dy) ⟩ m * dy ∎
{ "alphanum_fraction": 0.5005142269, "avg_line_length": 26.5181818182, "ext": "agda", "hexsha": "a9dc5f56b1ea7b5a16f26221bffa8675e237ce62", "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": "78c3dec24834ffeca5e74cb75578e9b210a5be62", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "cspollard/diff", "max_forks_repo_path": "src/Min.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "78c3dec24834ffeca5e74cb75578e9b210a5be62", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "cspollard/diff", "max_issues_repo_path": "src/Min.agda", "max_line_length": 82, "max_stars_count": null, "max_stars_repo_head_hexsha": "78c3dec24834ffeca5e74cb75578e9b210a5be62", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "cspollard/diff", "max_stars_repo_path": "src/Min.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1257, "size": 2917 }
{- This file contains: - Properties of groupoid truncations -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.GroupoidTruncation.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Univalence open import Cubical.HITs.GroupoidTruncation.Base private variable ℓ : Level A : Type ℓ rec : ∀ {B : Type ℓ} → isGroupoid B → (A → B) → ∥ A ∥₃ → B rec gB f ∣ x ∣₃ = f x rec gB f (squash₃ x y p q r s i j k) = gB _ _ _ _ (λ m n → rec gB f (r m n)) (λ m n → rec gB f (s m n)) i j k elim : {B : ∥ A ∥₃ → Type ℓ} (bG : (x : ∥ A ∥₃) → isGroupoid (B x)) (f : (x : A) → B ∣ x ∣₃) (x : ∥ A ∥₃) → B x elim bG f (∣ x ∣₃) = f x elim bG f (squash₃ x y p q r s i j k) = isOfHLevel→isOfHLevelDep 3 bG _ _ _ _ (λ j k → elim bG f (r j k)) (λ j k → elim bG f (s j k)) (squash₃ x y p q r s) i j k elim2 : {B : ∥ A ∥₃ → ∥ A ∥₃ → Type ℓ} (gB : ((x y : ∥ A ∥₃) → isGroupoid (B x y))) (g : (a b : A) → B ∣ a ∣₃ ∣ b ∣₃) (x y : ∥ A ∥₃) → B x y elim2 gB g = elim (λ _ → isGroupoidΠ (λ _ → gB _ _)) (λ a → elim (λ _ → gB _ _) (g a)) elim3 : {B : (x y z : ∥ A ∥₃) → Type ℓ} (gB : ((x y z : ∥ A ∥₃) → isGroupoid (B x y z))) (g : (a b c : A) → B ∣ a ∣₃ ∣ b ∣₃ ∣ c ∣₃) (x y z : ∥ A ∥₃) → B x y z elim3 gB g = elim2 (λ _ _ → isGroupoidΠ (λ _ → gB _ _ _)) (λ a b → elim (λ _ → gB _ _ _) (g a b)) groupoidTruncIsGroupoid : isGroupoid ∥ A ∥₃ groupoidTruncIsGroupoid a b p q r s = squash₃ a b p q r s groupoidTruncIdempotent≃ : isGroupoid A → ∥ A ∥₃ ≃ A groupoidTruncIdempotent≃ {A = A} hA = isoToEquiv f where f : Iso ∥ A ∥₃ A Iso.fun f = rec hA (idfun A) Iso.inv f x = ∣ x ∣₃ Iso.rightInv f _ = refl Iso.leftInv f = elim (λ _ → isGroupoid→is2Groupoid groupoidTruncIsGroupoid _ _) (λ _ → refl) groupoidTruncIdempotent : isGroupoid A → ∥ A ∥₃ ≡ A groupoidTruncIdempotent hA = ua (groupoidTruncIdempotent≃ hA)
{ "alphanum_fraction": 0.5710944808, "avg_line_length": 31.4411764706, "ext": "agda", "hexsha": "dbf8f9ace5df8e4fd89f1d7c666c05216522e9c0", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/HITs/GroupoidTruncation/Properties.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/HITs/GroupoidTruncation/Properties.agda", "max_line_length": 94, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/HITs/GroupoidTruncation/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 941, "size": 2138 }
{-# OPTIONS --cubical --no-import-sorts --guardedness --safe #-} module Cubical.Codata.M.AsLimit.Coalg where open import Cubical.Codata.M.AsLimit.Coalg.Base public
{ "alphanum_fraction": 0.7530120482, "avg_line_length": 27.6666666667, "ext": "agda", "hexsha": "da0ed579edc00c5a67a68aa149ef22f377ceb923", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/Codata/M/AsLimit/Coalg.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "dan-iel-lee/cubical", "max_issues_repo_path": "Cubical/Codata/M/AsLimit/Coalg.agda", "max_line_length": 64, "max_stars_count": null, "max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "dan-iel-lee/cubical", "max_stars_repo_path": "Cubical/Codata/M/AsLimit/Coalg.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 43, "size": 166 }
module Oscar.Property.Extensionality where open import Oscar.Level record Extensionality {a} {A : Set a} {b} {B : A → Set b} {ℓ₁} (_≤₁_ : (x : A) → B x → Set ℓ₁) {c} {C : A → Set c} {d} {D : ∀ {x} → B x → Set d} {ℓ₂} (_≤₂_ : ∀ {x} → C x → ∀ {y : B x} → D y → Set ℓ₂) (μ₁ : (x : A) → C x) (μ₂ : ∀ {x} → (y : B x) → D y) : Set (a ⊔ ℓ₁ ⊔ b ⊔ ℓ₂) where field extensionality : ∀ {x} {y : B x} → x ≤₁ y → μ₁ x ≤₂ μ₂ y open Extensionality ⦃ … ⦄ public extension : ∀ {a} {A : Set a} {b} {B : A → Set b} {ℓ₁} {_≤₁_ : (x : A) → B x → Set ℓ₁} {c} {C : A → Set c} {d} {D : ∀ {x} → B x → Set d} {ℓ₂} (_≤₂_ : ∀ {x} → C x → ∀ {y : B x} → D y → Set ℓ₂) {μ₁ : (x : A) → C x} {μ₂ : ∀ {x} → (y : B x) → D y} ⦃ _ : Extensionality _≤₁_ _≤₂_ μ₁ μ₂ ⦄ {x} {y : B x} → x ≤₁ y → μ₁ x ≤₂ μ₂ y extension _≤₂_ = extensionality {_≤₂_ = _≤₂_}
{ "alphanum_fraction": 0.4311717861, "avg_line_length": 28.3548387097, "ext": "agda", "hexsha": "31f718821773ee9ce7bdd8bbbfecb3f878f79948", "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/Property/Extensionality.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/Property/Extensionality.agda", "max_line_length": 60, "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/Property/Extensionality.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 452, "size": 879 }
{-# OPTIONS --without-K #-} open import Base open import Homotopy.Truncation open import Integers -- Formalization of 0-truncated groups module Algebra.Groups where -- A pregroup is a group whose carrier is not a required to be a set (but -- without higher coherences) record pregroup i : Set (suc i) where -- constructor pregroup field -- Stuff carrier : Set i -- \| -- Structure _∙_ : carrier → carrier → carrier -- \. e : carrier _′ : carrier → carrier -- \' -- Properties assoc : ∀ x y z → (x ∙ y) ∙ z ≡ x ∙ (y ∙ z) right-unit : ∀ x → x ∙ e ≡ x left-unit : ∀ x → e ∙ x ≡ x right-inverse : ∀ x → x ∙ (x ′) ≡ e left-inverse : ∀ x → (x ′) ∙ x ≡ e record group i : Set (suc i) where -- constructor group field pre : pregroup i open pregroup pre field set : is-set carrier open pregroup pre public -- Group structure on [unit] unit-group : ∀ {i} → group i unit-group {i} = record { pre = record { carrier = unit ; _∙_ = λ _ _ → tt ; e = tt ; _′ = λ _ → tt ; assoc = λ _ _ _ → refl ; right-unit = λ _ → refl ; left-unit = λ _ → refl ; right-inverse = λ _ → refl ; left-inverse = λ _ → refl } ; set = unit-is-set } postulate -- Tedious because I have a terrible definition of groups unit-group-unique : ∀ {i} (G : group i) → let open group G in (c : is-contr carrier) → G ≡ unit-group -- Every pregroup can be truncated to a group π₀-pregroup : ∀ {i} → pregroup i → group i π₀-pregroup pre = record { pre = record { carrier = carrier₀ ; _∙_ = _•₀_ ; e = e₀ ; _′ = _′₀ ; assoc = assoc₀ ; right-unit = right-unit₀ ; left-unit = left-unit₀ ; right-inverse = right-inverse₀ ; left-inverse = left-inverse₀ } ; set = carrier₀-is-set } where open pregroup pre carrier₀ : Set _ carrier₀ = π₀ carrier carrier₀-is-set : is-set carrier₀ carrier₀-is-set = π₀-is-set carrier _•₀_ : carrier₀ → carrier₀ → carrier₀ _•₀_ = π₀-extend-nondep ⦃ →-is-set $ carrier₀-is-set ⦄ (λ x → π₀-extend-nondep ⦃ carrier₀-is-set ⦄ (λ y → proj (x ∙ y))) e₀ : π₀ carrier e₀ = proj e _′₀ : carrier₀ → carrier₀ _′₀ = π₀-extend-nondep ⦃ carrier₀-is-set ⦄ (λ x → proj (x ′)) abstract assoc₀ : ∀ x y z → (x •₀ y) •₀ z ≡ x •₀ (y •₀ z) assoc₀ = (π₀-extend ⦃ λ _ → Π-is-set λ _ → Π-is-set λ _ → ≡-is-set carrier₀-is-set ⦄ (λ x → π₀-extend ⦃ λ _ → Π-is-set λ _ → ≡-is-set carrier₀-is-set ⦄ (λ y → π₀-extend ⦃ λ _ → ≡-is-set carrier₀-is-set ⦄ (λ z → ap proj (assoc x y z))))) abstract right-unit₀ : ∀ x → x •₀ e₀ ≡ x right-unit₀ = (π₀-extend ⦃ λ _ → ≡-is-set carrier₀-is-set ⦄ (ap proj ◯ right-unit)) abstract left-unit₀ : ∀ x → e₀ •₀ x ≡ x left-unit₀ = (π₀-extend ⦃ λ _ → ≡-is-set carrier₀-is-set ⦄ (ap proj ◯ left-unit)) abstract right-inverse₀ : ∀ x → x •₀ (x ′₀) ≡ e₀ right-inverse₀ = (π₀-extend ⦃ λ _ → ≡-is-set carrier₀-is-set ⦄ (ap proj ◯ right-inverse)) abstract left-inverse₀ : ∀ x → (x ′₀) •₀ x ≡ e₀ left-inverse₀ = (π₀-extend ⦃ λ _ → ≡-is-set carrier₀-is-set ⦄ (ap proj ◯ left-inverse)) -- Not used -- is-group-morphism : ∀ {i j} (A : Group i) (B : Group j) -- (f : ∣ g A ∣ → ∣ g B ∣) -- → Set (max i j) -- is-group-morphism A B f = -- (x y : ∣ g A ∣) → f (_∙_ (g A) x y) ≡ _∙_ (g B) (f x) (f y) -- _≈_ : ∀ {i j} (A : Group i) (B : Group j) → Set (max i j) -- A ≈ B = Σ (∣ g A ∣ → ∣ g B ∣) (λ f → is-equiv f × is-group-morphism A B f)
{ "alphanum_fraction": 0.5306623058, "avg_line_length": 26.3956834532, "ext": "agda", "hexsha": "51ceb201d2f62eeed1aaadaf70c3121d9cf85050", "lang": "Agda", "max_forks_count": 50, "max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z", "max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nicolaikraus/HoTT-Agda", "max_forks_repo_path": "old/Algebra/Groups.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z", "max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nicolaikraus/HoTT-Agda", "max_issues_repo_path": "old/Algebra/Groups.agda", "max_line_length": 83, "max_stars_count": 294, "max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "timjb/HoTT-Agda", "max_stars_repo_path": "old/Algebra/Groups.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": 1356, "size": 3669 }
{- Definition of the integers as a HIT ported from the redtt library: https://github.com/RedPRL/redtt/blob/master/library/cool/biinv-int.red For the naive, but incorrect, way to define the integers as a HIT, see HITs.IsoInt This file contains: - definition of BiInvInt - proof that Int ≡ BiInvInt - [discreteBiInvInt] and [isSetBiInvInt] - versions of the point constructors of BiInvInt which satisfy the path constructors judgmentally -} {-# OPTIONS --cubical --safe #-} module Cubical.HITs.Ints.BiInvInt.Base where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Data.Nat open import Cubical.Data.Int open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.BiInvEquiv open import Cubical.Foundations.HAEquiv open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.Properties open import Cubical.Relation.Nullary data BiInvInt : Type₀ where zero : BiInvInt suc : BiInvInt -> BiInvInt -- suc is a bi-invertible equivalence: predr : BiInvInt -> BiInvInt suc-predr : ∀ z -> suc (predr z) ≡ z predl : BiInvInt -> BiInvInt predl-suc : ∀ z -> predl (suc z) ≡ z suc-biinvequiv : BiInvEquiv BiInvInt BiInvInt suc-biinvequiv = record { fun = suc ; invr = predr ; invr-rightInv = suc-predr ; invl = predl ; invl-leftInv = predl-suc } predr-suc : ∀ z -> predr (suc z) ≡ z predr-suc = BiInvEquiv.invr-leftInv suc-biinvequiv -- since we want to use suc-adj and pred-adj (defined below) later on, we will need the -- definition of suc-predl taken from HAEquiv instead of from BiInvEquiv suc-haequiv : HAEquiv BiInvInt BiInvInt suc-haequiv = biInvEquiv→HAEquiv suc-biinvequiv suc-predl : ∀ z -> suc (predl z) ≡ z suc-predl = isHAEquiv.ret (snd suc-haequiv) -- predr and predl (as well as suc-predr and suc-predl - up to a path) are indistinguishable, -- so we can safely define 'pred' to just be predl predl≡predr : ∀ z -> predl z ≡ predr z predl≡predr z i = cong fst (isContr→isProp (isContr-section (biInvEquiv→Equiv-left suc-biinvequiv)) (predl , suc-predl) (predr , suc-predr)) i z suc-predl≡predr : ∀ z -> PathP (λ j → suc (predl≡predr z j) ≡ z) (suc-predl z) (suc-predr z) suc-predl≡predr z i = cong snd (isContr→isProp (isContr-section (biInvEquiv→Equiv-left suc-biinvequiv)) (predl , suc-predl) (predr , suc-predr)) i z pred : BiInvInt -> BiInvInt pred = predl suc-pred = suc-predl pred-suc = predl-suc -- these paths from HAEquiv will be useful later suc-adj : ∀ z → (λ i → suc (pred-suc z i)) ≡ suc-pred (suc z) pred-adj : ∀ z → (λ i → pred (suc-pred z i)) ≡ pred-suc (pred z) suc-adj z = isHAEquiv.com (snd suc-haequiv) z pred-adj z = isHAEquiv.com-op (snd suc-haequiv) z -- Int ≡ BiInvInt fwd : Int -> BiInvInt fwd (pos zero) = zero fwd (pos (suc n)) = suc (fwd (pos n)) fwd (negsuc zero) = pred zero fwd (negsuc (suc n)) = pred (fwd (negsuc n)) bwd : BiInvInt -> Int bwd zero = pos zero bwd (suc z) = sucInt (bwd z) bwd (predr z) = predInt (bwd z) bwd (suc-predr z i) = sucPred (bwd z) i bwd (predl z) = predInt (bwd z) bwd (predl-suc z i) = predSuc (bwd z) i bwd-fwd : ∀ (x : Int) -> bwd (fwd x) ≡ x bwd-fwd (pos zero) = refl bwd-fwd (pos (suc n)) = cong sucInt (bwd-fwd (pos n)) bwd-fwd (negsuc zero) = refl bwd-fwd (negsuc (suc n)) = cong predInt (bwd-fwd (negsuc n)) fwd-sucInt : ∀ (x : Int) → fwd (sucInt x) ≡ suc (fwd x) fwd-sucInt (pos n) = refl fwd-sucInt (negsuc zero) = sym (suc-pred (fwd (pos zero))) fwd-sucInt (negsuc (suc n)) = sym (suc-pred (fwd (negsuc n))) fwd-predInt : ∀ (x : Int) → fwd (predInt x) ≡ pred (fwd x) fwd-predInt (pos zero) = refl fwd-predInt (pos (suc n)) = sym (predl-suc (fwd (pos n))) fwd-predInt (negsuc n) = refl private sym-filler : ∀ {ℓ} {A : Type ℓ} {x y : A} (p : x ≡ y) → Square {- (j = i0) -} refl {- (i = i0) -} (sym p) {- (i = i1) -} refl {- (j = i1) -} p sym-filler {y = y} p i j = hcomp (λ k → λ { (j = i0) → y ; (i = i0) → p ((~ j) ∨ (~ k)) ; (i = i1) → y ; (j = i1) → p (i ∨ (~ k)) }) y fwd-sucPred : ∀ (x : Int) → Square {- (j = i0) -} (λ i → fwd (sucPred x i)) {- (i = i0) -} (fwd-sucInt (predInt x) ∙ (λ i → suc (fwd-predInt x i))) {- (i = i1) -} (λ _ → fwd x) {- (j = i1) -} (suc-pred (fwd x)) fwd-sucPred (pos zero) i j = hcomp (λ k → λ { (j = i0) → fwd (pos zero) ; (i = i0) → rUnit (sym (suc-pred (fwd (pos zero)))) k j -- because fwd-sucInt (predInt (pos zero)) ≡ sym (suc-pred (fwd (pos zero))) ; (i = i1) → fwd (pos zero) ; (j = i1) → suc-pred (fwd (pos zero)) i }) (sym-filler (suc-pred (fwd (pos zero))) i j) fwd-sucPred (pos (suc n)) i j = hcomp (λ k → λ { (j = i0) → suc (fwd (pos n)) ; (i = i0) → lUnit (λ i → suc (sym (predl-suc (fwd (pos n))) i)) k j -- because fwd-predInt (pos (suc n)) ≡ sym (predl-suc (fwd (pos n))) ; (i = i1) → suc (fwd (pos n)) ; (j = i1) → suc-adj (fwd (pos n)) k i }) (suc (sym-filler (pred-suc (fwd (pos n))) i j)) fwd-sucPred (negsuc n) i j = hcomp (λ k → λ { (j = i0) → fwd (negsuc n) ; (i = i0) → rUnit (sym (suc-pred (fwd (negsuc n)))) k j -- because fwd-sucInt (predInt (negsuc n)) ≡ sym (suc-pred (fwd (negsuc n))) ; (i = i1) → fwd (negsuc n) ; (j = i1) → suc-pred (fwd (negsuc n)) i }) (sym-filler (suc-pred (fwd (negsuc n))) i j) fwd-predSuc : ∀ (x : Int) → Square {- (j = i0) -} (λ i → fwd (predSuc x i)) {- (i = i0) -} (fwd-predInt (sucInt x) ∙ (λ i → pred (fwd-sucInt x i))) {- (i = i1) -} (λ _ → fwd x) {- (j = i1) -} (pred-suc (fwd x)) fwd-predSuc (pos n) i j = hcomp (λ k → λ { (j = i0) → fwd (pos n) ; (i = i0) → rUnit (sym (pred-suc (fwd (pos n)))) k j -- because fwd-predInt (sucInt (pos n)) ≡ sym (pred-suc (fwd (pos n))) ; (i = i1) → fwd (pos n) ; (j = i1) → pred-suc (fwd (pos n)) i }) (sym-filler (pred-suc (fwd (pos n))) i j) fwd-predSuc (negsuc zero) i j = hcomp (λ k → λ { (j = i0) → fwd (negsuc zero) ; (i = i0) → lUnit (λ i → pred (sym (suc-pred (fwd (pos zero))) i)) k j -- because fwd-sucInt (negsuc zero) ≡ sym (suc-pred (fwd (pos zero))) ; (i = i1) → fwd (negsuc zero) ; (j = i1) → pred-adj (fwd (pos zero)) k i }) (pred (sym-filler (suc-pred (fwd (pos zero))) i j)) fwd-predSuc (negsuc (suc n)) i j = hcomp (λ k → λ { (j = i0) → fwd (negsuc (suc n)) ; (i = i0) → lUnit (λ i → pred (sym (suc-pred (fwd (negsuc n))) i)) k j -- because fwd-sucInt (negsuc (suc n)) ≡ sym (suc-pred (fwd (negsuc n))) ; (i = i1) → fwd (negsuc (suc n)) ; (j = i1) → pred-adj (fwd (negsuc n)) k i }) (pred (sym-filler (suc-pred (fwd (negsuc n))) i j)) fwd-bwd : ∀ (z : BiInvInt) -> fwd (bwd z) ≡ z fwd-bwd zero = refl fwd-bwd (suc z) = fwd-sucInt (bwd z) ∙ (λ i → suc (fwd-bwd z i)) fwd-bwd (predr z) = fwd-predInt (bwd z) ∙ (λ i → predl≡predr (fwd-bwd z i) i) fwd-bwd (predl z) = fwd-predInt (bwd z) ∙ (λ i → pred (fwd-bwd z i)) fwd-bwd (suc-predr z i) j = hcomp (λ k → λ { (j = i0) → fwd (sucPred (bwd z) i) ; (i = i0) → (fwd-sucInt (predInt (bwd z)) ∙ (λ i → suc (compPath-filler (fwd-predInt (bwd z)) (λ i' → predl≡predr (fwd-bwd z i') i') k i))) j ; (i = i1) → fwd-bwd z (j ∧ k) ; (j = i1) → suc-predl≡predr (fwd-bwd z k) k i }) (fwd-sucPred (bwd z) i j) fwd-bwd (predl-suc z i) j = hcomp (λ k → λ { (j = i0) → fwd (predSuc (bwd z) i) ; (i = i0) → (fwd-predInt (sucInt (bwd z)) ∙ (λ i → pred (compPath-filler (fwd-sucInt (bwd z)) (λ i' → suc (fwd-bwd z i')) k i))) j ; (i = i1) → fwd-bwd z (j ∧ k) ; (j = i1) → pred-suc (fwd-bwd z k) i }) (fwd-predSuc (bwd z) i j) Int≡BiInvInt : Int ≡ BiInvInt Int≡BiInvInt = isoToPath (iso fwd bwd fwd-bwd bwd-fwd) discreteBiInvInt : Discrete BiInvInt discreteBiInvInt = subst Discrete Int≡BiInvInt discreteInt isSetBiInvInt : isSet BiInvInt isSetBiInvInt = subst isSet Int≡BiInvInt isSetInt -- suc' is equal to suc (suc≡suc') but cancels pred *exactly* (see suc'-pred) suc'ᵖ : (z : BiInvInt) -> Σ BiInvInt (suc z ≡_) suc' = fst ∘ suc'ᵖ suc≡suc' = snd ∘ suc'ᵖ suc'ᵖ zero = suc zero , refl suc'ᵖ (suc z) = suc (suc z) , refl suc'ᵖ (predr z) = z , suc-predr z suc'ᵖ (suc-predr z i) = let filler : I → I → BiInvInt filler j i = hfill (λ j → λ { (i = i0) → suc (suc (predr z)) ; (i = i1) → suc≡suc' z j }) (inS (suc (suc-predr z i))) j in filler i1 i , λ j → filler j i suc'ᵖ (predl z) = z , suc-predl z suc'ᵖ (predl-suc z i) = let filler : I → I → BiInvInt filler j i = hfill (λ j → λ { (i = i0) → suc-predl (suc z) j ; (i = i1) → suc≡suc' z j }) (inS (suc (predl-suc z i))) j in filler i1 i , λ j → filler j i private suc'-pred : ∀ z → suc' (pred z) ≡ z suc'-pred z = refl -- pred' is equal to pred (pred≡pred') but cancels suc *exactly* (see pred'-suc) predr'ᵖ : (z : BiInvInt) -> Σ BiInvInt (predr z ≡_) predr' = fst ∘ predr'ᵖ predr≡predr' = snd ∘ predr'ᵖ predr'ᵖ zero = predr zero , refl predr'ᵖ (suc z) = z , predr-suc z predr'ᵖ (predr z) = predr (predr z) , refl predr'ᵖ (suc-predr z i) = let filler : I → I → BiInvInt filler j i = hfill (λ j → λ { (i = i0) → predr-suc (predr z) j ; (i = i1) → predr≡predr' z j }) (inS (predr (suc-predr z i))) j in filler i1 i , λ j → filler j i predr'ᵖ (predl z) = predr (predl z) , refl predr'ᵖ (predl-suc z i) = let filler : I → I → BiInvInt filler j i = hfill (λ j → λ { (i = i0) → predr (predl (suc z)) ; (i = i1) → predr≡predr' z j }) (inS (predr (predl-suc z i))) j in filler i1 i , λ j → filler j i predl'ᵖ : (z : BiInvInt) -> Σ BiInvInt (predl z ≡_) predl' = fst ∘ predl'ᵖ predl≡predl' = snd ∘ predl'ᵖ predl'ᵖ zero = predl zero , refl predl'ᵖ (suc z) = z , predl-suc z predl'ᵖ (predr z) = predl (predr z) , refl predl'ᵖ (suc-predr z i) = let filler : I → I → BiInvInt filler j i = hfill (λ j → λ { (i = i0) → predl-suc (predr z) j ; (i = i1) → predl≡predl' z j }) (inS (predl (suc-predr z i))) j in filler i1 i , λ j → filler j i predl'ᵖ (predl z) = predl (predl z) , refl predl'ᵖ (predl-suc z i) = let filler : I → I → BiInvInt filler j i = hfill (λ j → λ { (i = i0) → predl (predl (suc z)) ; (i = i1) → predl≡predl' z j }) (inS (predl (predl-suc z i))) j in filler i1 i , λ j → filler j i private predr'-suc : ∀ z → predr' (suc z) ≡ z predr'-suc z = refl predl'-suc : ∀ z → predl' (suc z) ≡ z predl'-suc z = refl
{ "alphanum_fraction": 0.4781964272, "avg_line_length": 41.2186495177, "ext": "agda", "hexsha": "d99c91d33e0806791dd56bcb178316329e734166", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cj-xu/cubical", "max_forks_repo_path": "Cubical/HITs/Ints/BiInvInt/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cj-xu/cubical", "max_issues_repo_path": "Cubical/HITs/Ints/BiInvInt/Base.agda", "max_line_length": 108, "max_stars_count": null, "max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cj-xu/cubical", "max_stars_repo_path": "Cubical/HITs/Ints/BiInvInt/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4582, "size": 12819 }
module Numeral.Natural.Oper.Summation.Range.Proofs where import Lvl open import Data.List open import Data.List.Functions open Data.List.Functions.LongOper open import Data.List.Proofs open import Data.List.Equiv.Id open import Data.List.Proofs.Length open import Functional as Fn using (_$_ ; _∘_ ; const) open import Numeral.Natural open import Numeral.Natural.Oper open import Numeral.Natural.Oper.Summation.Range open import Numeral.Natural.Relation.Order open import Numeral.Natural.Relation.Order.Proofs open import Relator.Equals hiding (_≡_) open import Relator.Equals.Proofs.Equiv open import Structure.Function open import Structure.Function.Multi open import Structure.Setoid open import Syntax.Transitivity open import Type Range-empty : ∀{a} → (a ‥ a ≡ ∅) Range-empty {𝟎} = [≡]-intro Range-empty {𝐒 a} rewrite Range-empty {a} = [≡]-intro {-# REWRITE Range-empty #-} Range-reversed : ∀{a b} → ⦃ _ : (a ≥ b) ⦄ → (a ‥ b ≡ ∅) Range-reversed {a} {𝟎} ⦃ min ⦄ = [≡]-intro Range-reversed {𝐒 a} {𝐒 b} ⦃ succ p ⦄ rewrite Range-reversed {a} {b} ⦃ p ⦄ = [≡]-intro Range-succ : ∀{a b} → (map 𝐒(a ‥ b) ≡ 𝐒(a) ‥ 𝐒(b)) Range-succ = [≡]-intro Range-prepend : ∀{a b} → ⦃ _ : (a < b) ⦄ → (a ‥ b ≡ prepend a (𝐒(a) ‥ b)) Range-prepend {𝟎} {𝐒 b} = [≡]-intro Range-prepend {𝐒 a} {𝐒 b} ⦃ succ ab ⦄ rewrite Range-prepend {a} {b} ⦃ ab ⦄ = [≡]-intro Range-postpend : ∀{a b} → ⦃ _ : (a < 𝐒(b)) ⦄ → (a ‥ 𝐒(b) ≡ postpend b (a ‥ b)) Range-postpend {𝟎} {𝟎} ⦃ [≤]-with-[𝐒] ⦄ = [≡]-intro Range-postpend {𝟎} {𝐒 b} ⦃ [≤]-with-[𝐒] ⦄ = congruence₁(prepend 𝟎) $ map 𝐒(𝟎 ‥ 𝐒(b)) 🝖[ _≡_ ]-[ congruence₁(map 𝐒) (Range-postpend {𝟎}{b}) ] map 𝐒(postpend b (𝟎 ‥ b)) 🝖[ _≡_ ]-[ map-postpend ] postpend (𝐒(b)) (map 𝐒(𝟎 ‥ b)) 🝖-end Range-postpend {𝐒 a} {𝐒 b} ⦃ succ 𝐒ab ⦄ rewrite Range-postpend {a} {b} ⦃ 𝐒ab ⦄ = map-postpend Range-length : ∀{a b} → (length(a ‥ b) ≡ b −₀ a) Range-length {𝟎} {𝟎} = [≡]-intro Range-length {𝟎} {𝐒 b} rewrite length-map{f = 𝐒}{x = 𝟎 ‥ b} rewrite Range-length {𝟎} {b} = congruence₁(𝐒) [≡]-intro Range-length {𝐒 a} {𝟎} = [≡]-intro Range-length {𝐒 a} {𝐒 b} rewrite length-map{f = 𝐒}{x = a ‥ b} rewrite Range-length {a} {b} = [≡]-intro Range-length-zero : ∀{b} → (length(𝟎 ‥ b) ≡ b) Range-length-zero {b} = Range-length {𝟎}{b} Range-singleton : ∀{a} → (a ‥ 𝐒(a) ≡ singleton(a)) Range-singleton {𝟎} = [≡]-intro Range-singleton {𝐒 a} rewrite Range-singleton {a} = [≡]-intro {-# REWRITE Range-singleton #-} Range-concat : ∀{a b c} → ⦃ ab : (a ≤ b) ⦄ ⦃ bc : (b < c) ⦄ → ((a ‥ b) ++ (b ‥ c) ≡ a ‥ c) Range-concat {𝟎} {𝟎} {𝐒 c} ⦃ min ⦄ ⦃ succ bc ⦄ = [≡]-intro Range-concat {𝟎} {𝐒 b} {𝐒 c} ⦃ min ⦄ ⦃ succ bc ⦄ = congruence₁ (prepend 0) $ map 𝐒(𝟎 ‥ b) ++ map 𝐒 (b ‥ c) 🝖[ _≡_ ]-[ preserving₂(map 𝐒)(_++_)(_++_) {𝟎 ‥ b}{b ‥ c} ]-sym map 𝐒((𝟎 ‥ b) ++ (b ‥ c)) 🝖[ _≡_ ]-[ congruence₁(map 𝐒) (Range-concat {𝟎} {b} {c}) ] map 𝐒(𝟎 ‥ c) 🝖-end where instance _ = bc Range-concat {𝐒 a} {𝐒 b} {𝐒 c} ⦃ succ ab ⦄ ⦃ succ bc ⦄ = map 𝐒(a ‥ b) ++ map 𝐒 (b ‥ c) 🝖[ _≡_ ]-[ preserving₂(map 𝐒)(_++_)(_++_) {a ‥ b}{b ‥ c} ]-sym map 𝐒((a ‥ b) ++ (b ‥ c)) 🝖[ _≡_ ]-[ congruence₁(map 𝐒) (Range-concat {a} {b} {c}) ] map 𝐒(a ‥ c) 🝖-end where instance _ = ab instance _ = bc
{ "alphanum_fraction": 0.5703861356, "avg_line_length": 37.375, "ext": "agda", "hexsha": "db9d9fa82db30fcfcb71f423950eebb4537b7307", "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": "Numeral/Natural/Oper/Summation/Range/Proofs.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": "Numeral/Natural/Oper/Summation/Range/Proofs.agda", "max_line_length": 94, "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": "Numeral/Natural/Oper/Summation/Range/Proofs.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": 1550, "size": 3289 }
module Section9 where open import Section8 public -- 9. A decision algorithm for terms -- ================================= -- -- The reduction defined above can be used for deciding if two well-typed terms are convertible -- with each other or not: reduce the terms and check if the results are equal. This algorithm -- is implicit in Martin-Löf’s notes [13]. -- -- The decision algorithm is complete: -- Theorem 11. postulate thm₁₁ : ∀ {Γ A t₀ t₁} → Γ ⊢ t₀ ≊ t₁ ∷ A → Σ 𝕋 (λ t → Γ ⊢ t₀ ⇓ t ∷ A × Γ ⊢ t₁ ⇓ t ∷ A) -- Proof: By Lemma 14 and Lemma 12 we know that there exist proof trees `M, N` such -- that `t₀` is equal to `M ⁻` and `t₁` is equal to `N ⁻`. By Theorem 9 we get that `M ≅ N`. We can -- choose `nf M ⁻` for `t` since, by Lemma 8, `Γ ⊢ M ⁻ ⇓ nf M ⁻ ∷ A`, `Γ ⊢ N ⁻ ⇓ nf N ⁻ ∷ A` -- and by Theorem 6 we have `nf M ≡ nf N` and hence that `nf M ⁻` and `nf N ⁻` are the -- same. -- -- This decision algorithm is correct, i.e., -- Theorem 12. postulate thm₁₂ : ∀ {Γ A t} → (M N : Γ ⊢ A) → Γ ⊢ M ⁻ ⇓ t ∷ A → Γ ⊢ N ⁻ ⇓ t ∷ A → M ≅ N -- Proof: We have `nf M ⁻ ≡ nf N ⁻` since, by Lemma 8, `Γ ⊢ M ⁻ ⇓ nf M ⁻ ∷ A` -- and `Γ ⊢ N ⁻ ⇓ nf N ⁻ ∷ A` and the reduction is deterministic. By Corollary 2 we get -- `M ≅ N`.
{ "alphanum_fraction": 0.5503512881, "avg_line_length": 33.7105263158, "ext": "agda", "hexsha": "e563662b0f2cddaf8bbf7af7fb815e47aa0ebe90", "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": "7c000654c4f97024d2939c412702f64dc821d4ec", "max_forks_repo_licenses": [ "X11" ], "max_forks_repo_name": "mietek/coquand", "max_forks_repo_path": "src/Section9.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7c000654c4f97024d2939c412702f64dc821d4ec", "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/coquand", "max_issues_repo_path": "src/Section9.agda", "max_line_length": 101, "max_stars_count": 4, "max_stars_repo_head_hexsha": "7c000654c4f97024d2939c412702f64dc821d4ec", "max_stars_repo_licenses": [ "X11" ], "max_stars_repo_name": "mietek/coquand", "max_stars_repo_path": "src/Section9.agda", "max_stars_repo_stars_event_max_datetime": "2017-09-07T12:44:40.000Z", "max_stars_repo_stars_event_min_datetime": "2017-03-27T01:29:58.000Z", "num_tokens": 495, "size": 1281 }
-- Andreas, 2019-12-03, issue #4205, reported by Smaug123, -- first shrinking by Jesper Cockx record R : Set₂ where field f : Set₁ postulate r : R open R r test : R R.f test with Set₃ f test | _ = Set -- WAS: internal error in getOriginalProjection -- EXPECTED: -- With clause pattern f is not an instance of its parent pattern R.f -- when checking that the clause -- R.f test with Set₃ -- f test | _ = Set -- has type R
{ "alphanum_fraction": 0.6788990826, "avg_line_length": 17.44, "ext": "agda", "hexsha": "15f8898ac2a9b1ecd2e3e5259082d1d4a17988c6", "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/Issue4205.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/Issue4205.agda", "max_line_length": 69, "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/Issue4205.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": 139, "size": 436 }
module Ints.Add.Invert where open import Ints open import Ints.Properties open import Ints.Add.Comm open import Nats.Add.Invert open import Data.Empty open import Relation.Nullary open import Equality open import Function ------------------------------------------------------------------------ -- internal stuffs private nat→int′ : ∀ a b → -[1+ nsuc $ a :+: a ] ≡ -[1+ nsuc $ b :+: b ] → a ≡ b nat→int′ a b = nat-add-invert a b ∘ nat-add-invert-1 (a :+: a) (b :+: b) ∘ eq-neg-int-to-nat impossible : ∀ a b → ¬ (+ a + + a ≡ -[1+ b ] + -[1+ b ]) impossible a b () +-invert : ∀ a b → (a + a ≡ b + b) → a ≡ b +-invert (+ a ) (+ b ) = eq-nat-to-int ∘ nat-add-invert a b ∘ eq-int-to-nat +-invert (+ a ) -[1+ b ] = ⊥-elim ∘ impossible a b +-invert -[1+ a ] (+ b ) = ⊥-elim ∘ impossible b a ∘ sym +-invert -[1+ a ] -[1+ b ] = eq-neg-nat-to-int ∘ nat→int′ a b ------------------------------------------------------------------------ -- public aliases int-add-invert : ∀ a b → (a + a ≡ b + b) → a ≡ b int-add-invert = +-invert
{ "alphanum_fraction": 0.4777251185, "avg_line_length": 28.5135135135, "ext": "agda", "hexsha": "4a39a3349ed7ed28b31a98b34dc4c77b7eb78092", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "ice1k/Theorems", "max_forks_repo_path": "src/Ints/Add/Invert.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "ice1k/Theorems", "max_issues_repo_path": "src/Ints/Add/Invert.agda", "max_line_length": 94, "max_stars_count": 1, "max_stars_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "ice1k/Theorems", "max_stars_repo_path": "src/Ints/Add/Invert.agda", "max_stars_repo_stars_event_max_datetime": "2020-04-15T15:28:03.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-15T15:28:03.000Z", "num_tokens": 360, "size": 1055 }
-- {-# OPTIONS -v impossible:100 -v tc.lhs.imp:100 #-} -- {-# OPTIONS -v impossible:100 -v tc.cover:20 #-} {-# OPTIONS --copatterns #-} module Copatterns where open import Common.Equality record _×_ (A B : Set) : Set where constructor _,_ field fst : A snd : B open _×_ pair : {A B : Set} → A → B → A × B fst (pair a b) = a snd (pair a b) = b swap : {A B : Set} → A × B → B × A fst (swap p) = snd p snd (swap p) = fst p swap3 : {A B C : Set} → A × (B × C) → C × (B × A) fst (swap3 t) = snd (snd t) fst (snd (swap3 t)) = fst (snd t) snd (snd (swap3 t)) = fst t -- should also work if we shuffle the clauses swap4 : {A B C D : Set} → A × (B × (C × D)) → D × (C × (B × A)) fst (snd (swap4 t)) = fst (snd (snd t)) snd (snd (snd (swap4 t))) = fst t fst (swap4 t) = snd (snd (snd t)) fst (snd (snd (swap4 t))) = fst (snd t) -- multiple clauses with abstractions fswap3 : {A B C X : Set} → (X → A) × ((X → B) × C) → (X → C) × (X → (B × A)) fst (fswap3 t) x = snd (snd t) fst (snd (fswap3 t) y) = fst (snd t) y snd (snd (fswap3 t) z) = fst t z -- State monad example -- The State newtype record State (S A : Set) : Set where constructor state field runState : S → A × S open State -- The Monad type class record Monad (M : Set → Set) : Set1 where constructor monad field return : {A : Set} → A → M A _>>=_ : {A B : Set} → M A → (A → M B) → M B module NoInstance where -- State is an instance of Monad stateMonad : {S : Set} → Monad (State S) runState (Monad.return stateMonad a ) s = a , s runState (Monad._>>=_ stateMonad m k) s₀ = let a , s₁ = runState m s₀ in runState (k a) s₁ module InstantiatedModule {S : Set} where open Monad (stateMonad {S}) leftId : {A B : Set}(a : A)(k : A → State S B) → (return a >>= k) ≡ k a leftId a k = refl rightId : {A B : Set}(m : State S A) → (m >>= return) ≡ m rightId m = refl assoc : {A B C : Set}(m : State S A)(k : A → State S B)(l : B → State S C) → ((m >>= k) >>= l) ≡ (m >>= λ a → (k a >>= l)) assoc m k l = refl module VisibleArgument where open Monad leftId : {A B S : Set}(a : A)(k : A → State S B) → (_>>=_ stateMonad (return stateMonad a) k) ≡ k a leftId a k = refl rightId : {A B S : Set}(m : State S A) → (_>>=_ stateMonad m (return stateMonad)) ≡ m rightId m = refl assoc : {A B C S : Set}(m : State S A)(k : A → State S B)(l : B → State S C) → (_>>=_ stateMonad (_>>=_ stateMonad m k) l) ≡ (_>>=_ stateMonad m λ a → _>>=_ stateMonad (k a) l) assoc m k l = refl module HiddenArgument where return : ∀ {M}{dict : Monad M}{A : Set} → A → M A return {dict = dict} = Monad.return dict _>>=_ : ∀ {M}{dict : Monad M}{A B : Set} → M A → (A → M B) → M B _>>=_ {dict = dict} = Monad._>>=_ dict leftId : {A B S : Set}(a : A)(k : A → State S B) → (_>>=_ {dict = stateMonad} (return {dict = stateMonad} a) k) ≡ k a leftId a k = refl {- LOTS OF YELLOW: leftId : {A B S : Set}(a : A)(k : A → State S B) → (return {dict = stateMonad {S}} a >>= k) ≡ k a leftId a k = refl rightId : {A B S : Set}(m : State S A) → (m >>= return) ≡ m rightId m = refl assoc : {A B C S : Set}(m : State S A)(k : A → State S B)(l : B → State S C) → ((m >>= k) >>= l) ≡ (m >>= λ a → k a >>= l) assoc m k l = refl -} {- WORKS NOT YET module InstanceArgument where open Monad {{...}} -- State is an instance of Monad -- TODO: this does not work with hidden argument yet stateMonad : {S : Set} → Monad (State S) runState (return {{stateMonad {S}}} a ) s = a , s runState (_>>=_ {{stateMonad {S}}} m k) s₀ = let a , s₁ = runState m s₀ in runState (k a) s₁ _~_ : {S A : Set} → State S A → State S A → Set m ~ m' = ∀ {s} → runState m s ≡ runState m' s -- the following identities should also hold with _≡_ -- but that would need a back-translation of copatterns to -- record expressions, which does not preserve SN for recursive cases leftId : {A B S : Set}(a : A)(k : A → State S B) → (return a >>= k) ≡ k a leftId a k = refl rightId : {A B S : Set}(m : State S A) → (m >>= return) ~ m rightId m = refl assoc : {A B C S : Set}(m : State S A)(k : A → State S B)(l : B → State S C) → ((m >>= k) >>= l) ~ (m >>= λ a → k a >>= l) assoc m k l = refl -}
{ "alphanum_fraction": 0.5259090909, "avg_line_length": 27.3291925466, "ext": "agda", "hexsha": "c3e1a13d84532ab5d50cda85c8e5f324c8fd74d9", "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": "477c8c37f948e6038b773409358fd8f38395f827", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "larrytheliquid/agda", "max_forks_repo_path": "test/succeed/Copatterns.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "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": "larrytheliquid/agda", "max_issues_repo_path": "test/succeed/Copatterns.agda", "max_line_length": 101, "max_stars_count": null, "max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "larrytheliquid/agda", "max_stars_repo_path": "test/succeed/Copatterns.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1640, "size": 4400 }
{-# OPTIONS --without-K #-} module hott.level.closure.lift where open import level open import function.isomorphism.lift open import hott.level.core open import hott.level.closure.core -- lifting preserves h-levels ↑-level : ∀ {i n} j {X : Set i} → h n X → h n (↑ j X) ↑-level j {X} = iso-level (lift-iso j X)
{ "alphanum_fraction": 0.6524390244, "avg_line_length": 23.4285714286, "ext": "agda", "hexsha": "2711bfdf52d86df49ae0db72837570581b746dfa", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z", "max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "pcapriotti/agda-base", "max_forks_repo_path": "src/hott/level/closure/lift.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "pcapriotti/agda-base", "max_issues_repo_path": "src/hott/level/closure/lift.agda", "max_line_length": 40, "max_stars_count": 27, "max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "HoTT/M-types", "max_stars_repo_path": "hott/level/closure/lift.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z", "num_tokens": 95, "size": 328 }
{-# OPTIONS --safe --warning=error --without-K #-} open import Numbers.Naturals.Definition open import LogicalFormulae open import Groups.Definition open import Groups.Orders.Partial.Definition open import Setoids.Orders.Partial.Definition open import Setoids.Setoids open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) module Groups.Orders.Archimedean {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {G : Group S _+_} {c : _} {_<_ : A → A → Set c} {pOrder : SetoidPartialOrder S _<_} (p : PartiallyOrderedGroup G pOrder) where open Setoid S open import Groups.Cyclic.Definition G open Group G Archimedean : Set (a ⊔ c) Archimedean = (x y : A) → (0G < x) → (0G < y) → Sg ℕ (λ n → y < (positiveEltPower x n))
{ "alphanum_fraction": 0.693877551, "avg_line_length": 36.75, "ext": "agda", "hexsha": "c145c27dd58356563008b7718e3c402e73c8c0cf", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z", "max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Smaug123/agdaproofs", "max_forks_repo_path": "Groups/Orders/Archimedean.agda", "max_issues_count": 14, "max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Smaug123/agdaproofs", "max_issues_repo_path": "Groups/Orders/Archimedean.agda", "max_line_length": 222, "max_stars_count": 4, "max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Smaug123/agdaproofs", "max_stars_repo_path": "Groups/Orders/Archimedean.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": 241, "size": 735 }
open import Common.Prelude _test_ : Nat → Nat → Nat m test_ = m +_
{ "alphanum_fraction": 0.6764705882, "avg_line_length": 13.6, "ext": "agda", "hexsha": "9e93d80fb16e90e3c8573a80f231767c95ef1d39", "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/Sections-10.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/Sections-10.agda", "max_line_length": 26, "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/Sections-10.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": 22, "size": 68 }
{-# OPTIONS --rewriting --without-K #-} open import Agda.Primitive open import Prelude import GSeTT.Typed-Syntax import Globular-TT.Syntax {- Type theory for globular sets -} module Globular-TT.Uniqueness-Derivations {l} (index : Set l) (rule : index → GSeTT.Typed-Syntax.Ctx × (Globular-TT.Syntax.Pre-Ty index)) (eqdec-index : eqdec index) where open import Globular-TT.Syntax index open import Globular-TT.Rules index rule open import Globular-TT.Eqdec-syntax index eqdec-index lΓ≤n→n∉Γ : ∀ {Γ A} n → Γ ⊢C → C-length Γ ≤ n → ¬ (n # A ∈ Γ) lΓ≤n→n∉Γ n (cc Γ⊢ Γ⊢A idp) Sl≤n (inl x) = lΓ≤n→n∉Γ n Γ⊢ (≤T (n≤Sn _) Sl≤n) x lΓ≤n→n∉Γ n (cc Γ⊢ Γ⊢A idp) Sl≤n (inr (idp , idp)) = Sn≰n _ Sl≤n lΓ∉Γ : ∀ {Γ A} → Γ ⊢C → ¬ (C-length Γ # A ∈ Γ) lΓ∉Γ Γ⊢ = lΓ≤n→n∉Γ _ Γ⊢ (n≤n _) has-all-paths-∈ : ∀ {Γ x A} → Γ ⊢C → has-all-paths (x # A ∈ Γ) has-all-paths-∈ {Γ ∙ y # B} {x} {A} (cc Γ⊢ γ⊢A idp) (inl x∈Γ) (inl x∈'Γ) = ap inl (has-all-paths-∈ Γ⊢ x∈Γ x∈'Γ) has-all-paths-∈ {Γ ∙ y # B} {x} {A} (cc Γ⊢ γ⊢A idp) (inr (p , q)) (inr (p' , q')) = inr= (,= (is-prop-has-all-paths (eqdec-is-set eqdecℕ _ _) p p') (is-prop-has-all-paths (eqdec-is-set eqdec-Ty _ _) q q')) has-all-paths-∈ {Γ ∙ y # B} {x} {A} (cc Γ⊢ γ⊢A idp) (inl x∈Γ) (inr (idp , idp)) = ⊥-elim (lΓ∉Γ Γ⊢ x∈Γ) has-all-paths-∈ {Γ ∙ y # B} {x} {A} (cc Γ⊢ γ⊢A idp) (inr (idp , idp)) (inl x∈Γ) = ⊥-elim (lΓ∉Γ Γ⊢ x∈Γ) has-all-paths-⊢C : ∀ {Γ} → has-all-paths (Γ ⊢C) has-all-paths-⊢T : ∀ {Γ A} → has-all-paths (Γ ⊢T A) has-all-paths-⊢t : ∀ {Γ A t} → has-all-paths (Γ ⊢t t # A) has-all-paths-⊢S : ∀ {Δ Γ γ} → has-all-paths (Δ ⊢S γ > Γ) has-all-paths-⊢C {⊘} ec ec = idp has-all-paths-⊢C {Γ ∙ x # A} (cc Γ⊢ Γ⊢A p) (cc Γ⊢' Γ⊢'A q) = ap³ cc (has-all-paths-⊢C Γ⊢ Γ⊢') (has-all-paths-⊢T Γ⊢A Γ⊢'A) (is-prop-has-all-paths (eqdec-is-set (eqdecℕ) _ _) p q) has-all-paths-⊢T {Γ} {∗} (ob Γ⊢) (ob Γ⊢') = ap ob (has-all-paths-⊢C Γ⊢ Γ⊢') has-all-paths-⊢T {Γ} {⇒ A t u} (ar Γ⊢A Γ⊢t:A Γ⊢u:A) (ar Γ⊢'A Γ⊢'t:A Γ⊢'u:A) = ap³ ar (has-all-paths-⊢T Γ⊢A Γ⊢'A) (has-all-paths-⊢t Γ⊢t:A Γ⊢'t:A) (has-all-paths-⊢t Γ⊢u:A Γ⊢'u:A) has-all-paths-⊢t {Γ} {A} {Var x} (var Γ⊢ x∈Γ) (var Γ⊢' x∈'Γ) = ap² var (has-all-paths-⊢C Γ⊢ Γ⊢') (has-all-paths-∈ Γ⊢ x∈Γ x∈'Γ) has-all-paths-⊢t {Γ} {A} {Tm-constructor i γ} (tm Ci⊢Ti Γ⊢γ p) (tm Ci⊢'Ti Γ⊢'γ p') = ap³ tm (has-all-paths-⊢T Ci⊢Ti Ci⊢'Ti) (has-all-paths-⊢S Γ⊢γ Γ⊢'γ) (is-prop-has-all-paths (eqdec-is-set eqdec-Ty _ _) p p') has-all-paths-⊢S {Δ} {Γ} {<>} (es Δ⊢) (es Δ⊢')= ap es (has-all-paths-⊢C Δ⊢ Δ⊢') has-all-paths-⊢S {Δ} {Γ} {< γ , x ↦ t >} (sc Δ⊢γ Γ+⊢ Δ⊢t p) (sc Δ⊢'γ Γ+⊢' Δ⊢'t q) = ap⁴ sc (has-all-paths-⊢S Δ⊢γ Δ⊢'γ) (has-all-paths-⊢C Γ+⊢ Γ+⊢') (has-all-paths-⊢t Δ⊢t Δ⊢'t) (is-prop-has-all-paths (eqdec-is-set (eqdecℕ) _ _) p q) is-prop-⊢C : ∀ Γ → is-prop (Γ ⊢C) is-prop-⊢T : ∀ Γ A → is-prop (Γ ⊢T A) is-prop-⊢t : ∀ Γ A t → is-prop (Γ ⊢t t # A) is-prop-⊢S : ∀ Δ Γ γ → is-prop (Δ ⊢S γ > Γ) is-prop-⊢C Γ = has-all-paths-is-prop has-all-paths-⊢C is-prop-⊢T Γ A = has-all-paths-is-prop has-all-paths-⊢T is-prop-⊢t Γ A t = has-all-paths-is-prop has-all-paths-⊢t is-prop-⊢S Γ Δ γ = has-all-paths-is-prop has-all-paths-⊢S unique-type : ∀ {Γ t u A B} → (Γ ⊢t t # A) → (Γ ⊢t u # B) → t == u → A == B unique-type (var (cc Γ⊢ _ idp) (inl a)) (var _ (inl b)) idp = unique-type (var Γ⊢ a) (var Γ⊢ b) idp unique-type (var (cc Γ⊢ _ idp) (inr (idp , _))) (var _ (inl l∈Γ)) idp = ⊥-elim (lΓ∉Γ Γ⊢ l∈Γ) unique-type (var (cc Γ⊢ _ idp) (inl l∈Γ)) (var _ (inr (idp , _))) idp = ⊥-elim (lΓ∉Γ Γ⊢ l∈Γ) unique-type (var (cc Γ⊢ _ idp) (inr (idp , idp))) (var _ (inr (idp , idp))) _ = idp unique-type (tm _ _ p) (tm _ _ q) idp = p >> (q ^)
{ "alphanum_fraction": 0.5414273995, "avg_line_length": 57.140625, "ext": "agda", "hexsha": "e826fad76851d256f5574ab5fc54ef907b04480f", "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": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "thibautbenjamin/catt-formalization", "max_forks_repo_path": "Globular-TT/Uniqueness-Derivations.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "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": "thibautbenjamin/catt-formalization", "max_issues_repo_path": "Globular-TT/Uniqueness-Derivations.agda", "max_line_length": 232, "max_stars_count": null, "max_stars_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thibautbenjamin/catt-formalization", "max_stars_repo_path": "Globular-TT/Uniqueness-Derivations.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2136, "size": 3657 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Relation.Binary.Raw.Construct.Never where open import Cubical.Core.Everything open import Cubical.Relation.Binary.Raw open import Cubical.Relation.Binary.Raw.Construct.Constant open import Cubical.Data.Empty.Polymorphic using (⊥) ------------------------------------------------------------------------ -- Definition Never : ∀ {a ℓ} {A : Type a} → RawRel A ℓ Never = Const ⊥
{ "alphanum_fraction": 0.6269662921, "avg_line_length": 29.6666666667, "ext": "agda", "hexsha": "0389d61de892cd29057fec8c2f1d174b5e55bb43", "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/Relation/Binary/Raw/Construct/Never.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/Relation/Binary/Raw/Construct/Never.agda", "max_line_length": 72, "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/Relation/Binary/Raw/Construct/Never.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 104, "size": 445 }
open import Relation.Binary.Core module TreeSort.Impl1 {A : Set} (_≤_ : A → A → Set) (tot≤ : Total _≤_) where open import BTree {A} open import Data.List open import Data.Sum insert : A → BTree → BTree insert x leaf = node x leaf leaf insert x (node y l r) with tot≤ x y ... | inj₁ x≤y = node y (insert x l) r ... | inj₂ y≤x = node y l (insert x r) treeSort : List A → BTree treeSort [] = leaf treeSort (x ∷ xs) = insert x (treeSort xs)
{ "alphanum_fraction": 0.5860655738, "avg_line_length": 19.52, "ext": "agda", "hexsha": "230581f6984d3aa2d3b109a078ec9fa2d7b8bb0f", "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": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bgbianchi/sorting", "max_forks_repo_path": "agda/TreeSort/Impl1.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "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": "bgbianchi/sorting", "max_issues_repo_path": "agda/TreeSort/Impl1.agda", "max_line_length": 43, "max_stars_count": 6, "max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bgbianchi/sorting", "max_stars_repo_path": "agda/TreeSort/Impl1.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z", "num_tokens": 163, "size": 488 }
------------------------------------------------------------------------------ -- Using setoids for formalizing FOTC ------------------------------------------------------------------------------ {-# OPTIONS --no-positivity-check #-} {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} {- From Peter emails: At that time I was considering an inductive data type D and an inductively defined equality on D. But I think what we are doing now is better. For =: The reason is that with the propositional identity we have identity elimination which lets us replace equals by equals. We cannot do that in general if we have setoid equality. For D: the reason why I prefer to postulate D is that we have no use for the inductive structure of D, and this inductive structure would make e g 0 + 0 different from 0. So in that case we need setoid equality. -} module FOTC where module Aczel-CA where -- From Peter's slides -- http://www.cse.chalmers.se/~peterd/slides/Amagasaki.pdf -- We add 3 to the fixities of the Agda standard library 0.8.1 (see -- Algebra.agda and Relation/Binary/Core.agda). infixl 9 _·_ infix 7 _≐_ data D : Set where K S : D _·_ : D → D → D -- The setoid equality. data _≐_ : D → D → Set where ≐-refl : ∀ {x} → x ≐ x ≐-sym : ∀ {x y} → x ≐ y → y ≐ x ≐-trans : ∀ {x y z} → x ≐ y → y ≐ z → x ≐ z ≐-cong : ∀ {x x' y y'} → x ≐ y → x' ≐ y' → x · x' ≐ y · y' K-eq : ∀ x y → K · x · y ≐ x S-eq : ∀ x y z → S · x · y · z ≐ x · z · (y · z) -- The identity type. data _≡_ (x : D) : D → Set where refl : x ≡ x ---------------------------------------------------------------------------- -- 14 May 2012: Using the inductive structure we cannot prove -- -- K · x · y ≡ x, -- -- we need the setoid equality. -- K-eq : ∀ {x y} → (K · x · y) ≡ x ---------------------------------------------------------------------------- -- 14 May 2012. We cannot define the identity elimination using the -- setoid equality. -- -- Adapted from Peter's email: -- Given postulate ≐-subst : (A : D → Set) → ∀ {x y} → x ≐ y → A x → A y -- we can proof ≐→≡ : ∀ {x y} → x ≐ y → x ≡ y ≐→≡ {x} h = ≐-subst (λ z → x ≡ z) h refl -- but this doesn't hold because "x ≡ y" (propositional equality) -- means identical expressions. We do NOT have K · x · y ≡ x. -- -- The point is that ≐ is a non-trivial equivalence relation, and -- not all properties preserve it. However, all properties are -- preserved by ≡. ------------------------------------------------------------------------------ module FOTC where infixl 9 _·_ -- The symbol is '\cdot'. infix 7 _≐_ data D : Set where _·_ : D → D → D lam fix : (D → D) → D true false if zero succ pred iszero : D -- The setoid equality. data _≐_ : D → D → Set where ≐-refl : ∀ {x} → x ≐ x ≐-sym : ∀ {x y} → x ≐ y → y ≐ x ≐-trans : ∀ {x y z} → x ≐ y → y ≐ z → x ≐ z ≐-cong : ∀ {x₁ x₂ y₁ y₂} → x₁ ≐ y₁ → x₂ ≐ y₂ → x₁ · x₂ ≐ y₁ · y₂ if-true : ∀ t t' → if · true · t · t' ≐ t if-false : ∀ t t' → if · false · t · t' ≐ t' pred-0 : pred · zero ≐ zero pred-S : ∀ n → pred · (succ · n) ≐ n iszero-0 : iszero · zero ≐ true iszero-S : ∀ n → iszero · (succ · n) ≐ false beta : ∀ f a → lam f · a ≐ f a fix-eq : ∀ f → fix f ≐ f (fix f) ------------------------------------------------------------------------------ module LeibnizEquality where infixl 9 _·_ infix 7 _≡_ data D : Set where _·_ : D → D → D lam fix : (D → D) → D true false if zero succ pred iszero : D -- (Barthe et al. 2003, p. 262) use the Leibniz equality when -- they talk about setoids. -- Using the Leibniz equality (adapted from -- Agda/examples/lib/Logic/Leibniz.agda) _≡_ : D → D → Set₁ x ≡ y = (A : D → Set) → A x → A y -- we can prove the setoids properties refl : ∀ x → x ≡ x refl x A Ax = Ax sym : ∀ {x y} → x ≡ y → y ≡ x sym {x} h A Ay = h (λ z → A z → A x) (λ Ax → Ax) Ay trans : ∀ x y z → x ≡ y → y ≡ z → x ≡ z trans x y z h₁ h₂ A Ax = h₂ A (h₁ A Ax) -- and the identity elimination subst : (A : D → Set) → ∀ {x y} → x ≡ y → A x → A y subst A h = h A -- and the congruency cong : ∀ {x x' y y'} → x ≡ x' → y ≡ y' → x · y ≡ x' · y' cong {x} {x'} {y} {y'} h₁ h₂ A Axx' = h₂ (λ z → A (x' · z)) (h₁ (λ z → A (z · y)) Axx') ------------------------------------------------------------------------------ -- References -- -- Barthe, Gilles, Capretta, Venanzio and Pons, Olivier -- (2003). Setoids in type theory. Journal of Functional Programming -- 13.2, pp. 261–293.
{ "alphanum_fraction": 0.4804188482, "avg_line_length": 29.2944785276, "ext": "agda", "hexsha": "724dbaacaef6f082ef0f4bb7f842b954350d2cfb", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "notes/setoids/FOTC.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "notes/setoids/FOTC.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "notes/setoids/FOTC.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 1642, "size": 4775 }
------------------------------------------------------------------------ -- Restricted hypotheses ------------------------------------------------------------------------ -- A restricted hypothesis is a hypothesis where both types are -- sub/terms/ of either one of two given types. open import RecursiveTypes.Syntax module RecursiveTypes.Subterm.RestrictedHypothesis {n} (χ₁ χ₂ : Ty n) where open import Category.Monad open import Function open import Function.Equality using (_⟨$⟩_) open import Function.Inverse using (module Inverse) open import Data.List as List open import Data.List.Relation.Unary.Any as Any open import Data.List.Relation.Unary.Any.Properties import Data.List.Categorical import Data.List.Countdown as Countdown open import Data.List.Membership.Propositional using (_∈_) open import Data.List.Membership.Propositional.Properties import Data.List.Membership.Setoid open import Data.Product as Prod open import Data.Sum as Sum open import Level open import Relation.Nullary open import Relation.Binary import Relation.Binary.Construct.On as On open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl) open RawMonad (Data.List.Categorical.monad {ℓ = zero}) open import RecursiveTypes.Subterm as ST using (_⊑_; _∗) ------------------------------------------------------------------------ -- Restricted hypotheses -- Types which are subterms of either χ₁ or χ₂. Subterm : Ty n → Set Subterm σ = σ ⊑ χ₁ ⊎ σ ⊑ χ₂ -- The Subterm predicate is anti-monotone. anti-mono : ∀ {σ₁ σ₂} → σ₂ ⊑ σ₁ → Subterm σ₁ → Subterm σ₂ anti-mono σ₂⊑σ₁ = Sum.map (ST.trans σ₂⊑σ₁) (ST.trans σ₂⊑σ₁) -- Hypotheses where both types are subterms. RestrictedHyp : Set RestrictedHyp = ∃ Subterm × ∃ Subterm -- Computes the underlying hypothesis/es. ⟨_⟩ : RestrictedHyp → Hyp n ⟨_⟩ = Prod.map proj₁ proj₁ ⟨_⟩⋆ : List RestrictedHyp → List (Hyp n) ⟨_⟩⋆ = List.map ⟨_⟩ -- Equality of restricted hypotheses (ignores the subterm proofs). _≈_ : Rel RestrictedHyp zero _≈_ = _≡_ on ⟨_⟩ -- List membership relation for restricted hypotheses. open Data.List.Membership.Setoid (record { isEquivalence = On.isEquivalence (⟨_⟩) PropEq.isEquivalence }) using () renaming (_∈_ to _⟨∈⟩_) ------------------------------------------------------------------------ -- Computing all possible restricted hypotheses -- Computes all the subterms of the given type. subtermsOf : ∀ τ → (∀ {σ} → σ ⊑ τ → Subterm σ) → List (∃ Subterm) subtermsOf τ f = List.map (Prod.map id f) (ST.subtermsOf τ) subtermsOf-complete : ∀ {τ} (f : ∀ {σ} → σ ⊑ τ → Subterm σ) {σ} → σ ⊑ τ → ∃ λ σ⊑τ → (σ , f σ⊑τ) ∈ subtermsOf τ f subtermsOf-complete f σ⊑τ = Prod.map id (λ ∈ → Inverse.to (map-∈↔ _) ⟨$⟩ (_ , ∈ , refl)) $ ST.subtermsOf-complete σ⊑τ subtermsOf²-complete : ∀ {σ₁ τ₁ σ₂ τ₂} (f : ∀ {σ} → σ ⊑ τ₁ → Subterm σ) (g : ∀ {σ} → σ ⊑ τ₂ → Subterm σ) → (σ₁⊑τ₁ : σ₁ ⊑ τ₁) (σ₂⊑τ₂ : σ₂ ⊑ τ₂) → ((σ₁ , f σ₁⊑τ₁) ≲ (σ₂ , g σ₂⊑τ₂)) ⟨∈⟩ (subtermsOf τ₁ f ⊗ subtermsOf τ₂ g) subtermsOf²-complete f g σ₁⊑τ₁ σ₂⊑τ₂ = Any.map (PropEq.cong $ Prod.map proj₁ proj₁) $ Inverse.to ⊗-∈↔ ⟨$⟩ ( proj₂ (subtermsOf-complete f σ₁⊑τ₁) , proj₂ (subtermsOf-complete g σ₂⊑τ₂) ) -- All subterms of χ₁. ⊑-χ₁ : List (∃ Subterm) ⊑-χ₁ = subtermsOf χ₁ inj₁ -- All subterms of χ₂. ⊑-χ₂ : List (∃ Subterm) ⊑-χ₂ = subtermsOf χ₂ inj₂ -- All possible restricted hypotheses. restrictedHyps : List RestrictedHyp restrictedHyps = (⊑-χ₁ ⊗ ⊑-χ₂) ++ (⊑-χ₂ ⊗ ⊑-χ₁) ++ (⊑-χ₁ ⊗ ⊑-χ₁) ++ (⊑-χ₂ ⊗ ⊑-χ₂) complete : ∀ h → h ⟨∈⟩ restrictedHyps complete ((σ , inj₁ σ⊑χ₁) ≲ (τ , inj₂ τ⊑χ₂)) = Inverse.to ++↔ ⟨$⟩ (inj₁ $ subtermsOf²-complete inj₁ inj₂ σ⊑χ₁ τ⊑χ₂) complete ((σ , inj₂ σ⊑χ₂) ≲ (τ , inj₁ τ⊑χ₁)) = Inverse.to (++↔ {xs = ⊑-χ₁ ⊗ ⊑-χ₂}) ⟨$⟩ (inj₂ $ Inverse.to ++↔ ⟨$⟩ (inj₁ $ subtermsOf²-complete inj₂ inj₁ σ⊑χ₂ τ⊑χ₁)) complete ((σ , inj₁ σ⊑χ₁) ≲ (τ , inj₁ τ⊑χ₁)) = Inverse.to (++↔ {xs = ⊑-χ₁ ⊗ ⊑-χ₂}) ⟨$⟩ (inj₂ $ Inverse.to (++↔ {xs = ⊑-χ₂ ⊗ ⊑-χ₁}) ⟨$⟩ (inj₂ $ Inverse.to ++↔ ⟨$⟩ (inj₁ $ subtermsOf²-complete inj₁ inj₁ σ⊑χ₁ τ⊑χ₁))) complete ((σ , inj₂ σ⊑χ₂) ≲ (τ , inj₂ τ⊑χ₂)) = Inverse.to (++↔ {xs = ⊑-χ₁ ⊗ ⊑-χ₂}) ⟨$⟩ (inj₂ $ Inverse.to (++↔ {xs = ⊑-χ₂ ⊗ ⊑-χ₁}) ⟨$⟩ (inj₂ $ Inverse.to (++↔ {xs = ⊑-χ₁ ⊗ ⊑-χ₁}) ⟨$⟩ (inj₂ $ subtermsOf²-complete inj₂ inj₂ σ⊑χ₂ τ⊑χ₂))) ------------------------------------------------------------------------ -- A countdown structure for restricted hypotheses -- Equality of restricted hypotheses can be decided. _≟_ : Decidable (_≡_ {A = Hyp n}) ( σ₁ ≲ σ₂) ≟ (τ₁ ≲ τ₂) with σ₁ ≡? τ₁ | σ₂ ≡? τ₂ (.τ₁ ≲ .τ₂) ≟ (τ₁ ≲ τ₂) | yes refl | yes refl = yes refl ... | no σ₁≢τ₁ | _ = no (σ₁≢τ₁ ∘ PropEq.cong proj₁) ... | _ | no σ₂≢τ₂ = no (σ₂≢τ₂ ∘ PropEq.cong proj₂) isDecEquivalence : IsDecEquivalence _≈_ isDecEquivalence = On.isDecEquivalence ⟨_⟩ $ DecSetoid.isDecEquivalence (PropEq.decSetoid _≟_) -- The countdown data structure can be used to keep track of (an upper -- bound of) the number of hypotheses which have not been inserted -- into a given list of hypotheses yet. private open module C = Countdown (record { isDecEquivalence = isDecEquivalence }) public hiding (empty; emptyFromList) -- An initialised countdown structure. empty : [] ⊕ length restrictedHyps empty = C.emptyFromList restrictedHyps complete
{ "alphanum_fraction": 0.6030832095, "avg_line_length": 31.8579881657, "ext": "agda", "hexsha": "3ac12ec1566bdeccca8ae5edde0963544669604a", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/codata", "max_forks_repo_path": "RecursiveTypes/Subterm/RestrictedHypothesis.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/codata", "max_issues_repo_path": "RecursiveTypes/Subterm/RestrictedHypothesis.agda", "max_line_length": 72, "max_stars_count": 1, "max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/codata", "max_stars_repo_path": "RecursiveTypes/Subterm/RestrictedHypothesis.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z", "max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z", "num_tokens": 1917, "size": 5384 }
------------------------------------------------------------------------ -- Monads ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Equality module Monad {reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where open import Logical-equivalence using (_⇔_) open import Prelude open import Bijection eq using (_↔_) open Derived-definitions-and-properties eq open import Function-universe eq using (inverse) ------------------------------------------------------------------------ -- Basic definitions -- Raw monads and raw monad transformers. open import Monad.Raw public -- Monads. record Monad {d c} (M : Type d → Type c) : Type (lsuc d ⊔ c) where constructor mk field ⦃ raw-monad ⦄ : Raw-monad M left-identity : ∀ {A B} (x : A) (f : A → M B) → return x >>= f ≡ f x right-identity : ∀ {A} (x : M A) → x >>= return ≡ x associativity : ∀ {A B C} → (x : M A) (f : A → M B) (g : B → M C) → x >>= (λ x → f x >>= g) ≡ x >>= f >>= g -- Monads are functors. map-id : ∀ {A} (x : M A) → map id x ≡ x map-id x = x >>= return ∘ id ≡⟨⟩ x >>= return ≡⟨ right-identity _ ⟩∎ x ∎ map-∘ : Extensionality d c → ∀ {A B C} (f : B → C) (g : A → B) (x : M A) → map (f ∘ g) x ≡ map f (map g x) map-∘ ext f g x = x >>= return ∘ (f ∘ g) ≡⟨ cong (x >>=_) (apply-ext ext λ _ → sym $ left-identity _ _) ⟩ x >>= (λ x → return (g x) >>= return ∘ f) ≡⟨ associativity _ _ _ ⟩∎ (x >>= return ∘ g) >>= return ∘ f ∎ -- More lemmas. map-return : ∀ {A B} (f : A → B) (x : A) → map {M = M} f (return x) ≡ return (f x) map-return f x = return x >>= return ∘ f ≡⟨ left-identity _ _ ⟩∎ return (f x) ∎ map->>= : ∀ {A B C} (f : B → C) (x : M A) (g : A → M B) → map f (x >>= g) ≡ x >>= map f ∘ g map->>= f x g = x >>= g >>= return ∘ f ≡⟨ sym $ associativity _ _ _ ⟩ x >>= (λ x → g x >>= return ∘ f) ≡⟨⟩ x >>= (λ x → map f (g x)) ≡⟨ refl _ ⟩∎ x >>= map f ∘ g ∎ >>=-map : Extensionality d c → ∀ {A B C} (f : A → B) (x : M A) (g : B → M C) → map f x >>= g ≡ x >>= g ∘ f >>=-map ext f x g = (x >>= return ∘ f) >>= g ≡⟨ sym $ associativity _ _ _ ⟩ x >>= (λ x → return (f x) >>= g) ≡⟨ cong (x >>=_) (apply-ext ext λ _ → left-identity _ _) ⟩∎ x >>= g ∘ f ∎ open Monad ⦃ … ⦄ public hiding (raw-monad) -- Monad transformers. record Monad-transformer {d c₁ c₂} (F : (Type d → Type c₁) → (Type d → Type c₂)) : Type (lsuc (c₁ ⊔ d) ⊔ c₂) where constructor mk field transform : ∀ {M} ⦃ is-monad : Monad M ⦄ → Monad (F M) liftᵐ : ∀ {M A} ⦃ is-monad : Monad M ⦄ → M A → F M A lift-return : ∀ {M A} ⦃ is-monad : Monad M ⦄ (x : A) → let module M = Raw-monad (Monad.raw-monad transform) in liftᵐ {M = M} (return x) ≡ M.return x lift->>= : ∀ {M A B} ⦃ is-monad : Monad M ⦄ (x : M A) (f : A → M B) → let module M = Raw-monad (Monad.raw-monad transform) in liftᵐ (x >>= f) ≡ liftᵐ x M.>>= liftᵐ ∘ f open Monad-transformer ⦃ … ⦄ public using (liftᵐ; lift-return; lift->>=) ------------------------------------------------------------------------ -- Preservation lemmas -- If F and G are pointwise logically equivalent, then Raw-monad F and -- Raw-monad G are logically equivalent. ⇔→raw⇔raw : ∀ {a f g} {F : Type a → Type f} {G : Type a → Type g} → (∀ x → F x ⇔ G x) → Raw-monad F ⇔ Raw-monad G ⇔→raw⇔raw {a} = λ F⇔G → record { to = to F⇔G ; from = to (inverse ∘ F⇔G) } where to : ∀ {f g} {F : Type a → Type f} {G : Type a → Type g} → (∀ x → F x ⇔ G x) → Raw-monad F → Raw-monad G Raw-monad.return (to F⇔G F-monad) x = _⇔_.to (F⇔G _) (F.return x) where module F = Raw-monad F-monad Raw-monad._>>=_ (to F⇔G F-monad) x f = _⇔_.to (F⇔G _) (_⇔_.from (F⇔G _) x F.>>= λ x → _⇔_.from (F⇔G _) (f x)) where module F = Raw-monad F-monad -- If F and G are pointwise isomorphic, then Raw-monad F and -- Raw-monad G are isomorphic (assuming extensionality). ↔→raw↔raw : ∀ {a f g} → Extensionality (lsuc a ⊔ f ⊔ g) (lsuc a ⊔ f ⊔ g) → {F : Type a → Type f} {G : Type a → Type g} → (∀ x → F x ↔ G x) → Raw-monad F ↔ Raw-monad G ↔→raw↔raw {a} {f} {g} = λ ext F↔G → record { surjection = record { logical-equivalence = ⇔→raw⇔raw (_↔_.logical-equivalence ∘ F↔G) ; right-inverse-of = to∘to (lower-extensionality f f ext) (inverse ∘ F↔G) } ; left-inverse-of = to∘to (lower-extensionality g g ext) F↔G } where to∘to : ∀ {f g} {F : Type a → Type f} {G : Type a → Type g} → Extensionality (lsuc a ⊔ f) (lsuc a ⊔ f) → (F↔G : ∀ x → F x ↔ G x) (F-monad : Raw-monad F) → let eq = ⇔→raw⇔raw (_↔_.logical-equivalence ∘ F↔G) in _⇔_.from eq (_⇔_.to eq F-monad) ≡ F-monad to∘to {f} ext F↔G (mk return _>>=_) = cong₂ mk (implicit-extensionality (lower-extensionality f (lsuc a) ext) λ _ → apply-ext (lower-extensionality _ (lsuc a) ext) λ x → _↔_.from (F↔G _) (_↔_.to (F↔G _) (return x)) ≡⟨ _↔_.left-inverse-of (F↔G _) _ ⟩∎ return x ∎) (implicit-extensionality (lower-extensionality f lzero ext) λ _ → implicit-extensionality (lower-extensionality f (lsuc a) ext) λ _ → apply-ext (lower-extensionality (lsuc a) (lsuc a) ext) λ x → apply-ext (lower-extensionality (lsuc a) (lsuc a) ext) λ f → _↔_.from (F↔G _) (_↔_.to (F↔G _) (_↔_.from (F↔G _) (_↔_.to (F↔G _) x) >>= λ x → _↔_.from (F↔G _) (_↔_.to (F↔G _) (f x)))) ≡⟨ _↔_.left-inverse-of (F↔G _) _ ⟩ (_↔_.from (F↔G _) (_↔_.to (F↔G _) x) >>= λ x → _↔_.from (F↔G _) (_↔_.to (F↔G _) (f x))) ≡⟨ cong₂ _>>=_ (_↔_.left-inverse-of (F↔G _) _) (apply-ext (lower-extensionality _ (lsuc a) ext) λ _ → _↔_.left-inverse-of (F↔G _) _) ⟩∎ x >>= f ∎) -- If F and G are pointwise isomorphic, then Monad F and Monad G are -- logically equivalent (assuming extensionality). ↔→⇔ : ∀ {a f g} → Extensionality a (f ⊔ g) → {F : Type a → Type f} {G : Type a → Type g} → (∀ x → F x ↔ G x) → Monad F ⇔ Monad G ↔→⇔ {a} {f} {g} = λ ext F↔G → record { to = to (lower-extensionality lzero g ext) F↔G ; from = to (lower-extensionality lzero f ext) (inverse ∘ F↔G) } where to : ∀ {f g} {F : Type a → Type f} {G : Type a → Type g} → Extensionality a f → (∀ x → F x ↔ G x) → Monad F → Monad G Monad.raw-monad (to ext F↔G F-monad) = _⇔_.to (⇔→raw⇔raw (_↔_.logical-equivalence ∘ F↔G)) F.raw-monad where module F = Monad F-monad Monad.left-identity (to ext F↔G F-monad) x f = _↔_.to (F↔G _) (_↔_.from (F↔G _) (_↔_.to (F↔G _) (FR.return x)) FR.>>= λ x → _↔_.from (F↔G _) (f x)) ≡⟨ cong (λ y → _↔_.to (F↔G _) (y FR.>>= _)) (_↔_.left-inverse-of (F↔G _) _) ⟩ _↔_.to (F↔G _) (FR.return x FR.>>= λ x → _↔_.from (F↔G _) (f x)) ≡⟨ cong (_↔_.to (F↔G _)) (FM.left-identity _ _) ⟩ _↔_.to (F↔G _) (_↔_.from (F↔G _) (f x)) ≡⟨ _↔_.right-inverse-of (F↔G _) _ ⟩∎ f x ∎ where module FM = Monad F-monad module FR = Raw-monad FM.raw-monad Monad.right-identity (to ext F↔G F-monad) x = _↔_.to (F↔G _) (_↔_.from (F↔G _) x FR.>>= λ x → _↔_.from (F↔G _) (_↔_.to (F↔G _) (FR.return x))) ≡⟨ cong (λ g → _↔_.to (F↔G _) (_ FR.>>= g)) (apply-ext ext λ _ → _↔_.left-inverse-of (F↔G _) _) ⟩ _↔_.to (F↔G _) (_↔_.from (F↔G _) x FR.>>= FR.return) ≡⟨ cong (_↔_.to (F↔G _)) (FM.right-identity _) ⟩ _↔_.to (F↔G _) (_↔_.from (F↔G _) x) ≡⟨ _↔_.right-inverse-of (F↔G _) _ ⟩∎ x ∎ where module FM = Monad F-monad module FR = Raw-monad FM.raw-monad Monad.associativity (to ext F↔G F-monad) x f g = _↔_.to (F↔G _) (_↔_.from (F↔G _) x FR.>>= λ x → _↔_.from (F↔G _) (_↔_.to (F↔G _) (_↔_.from (F↔G _) (f x) FR.>>= λ x → _↔_.from (F↔G _) (g x)))) ≡⟨ cong (λ g → _↔_.to (F↔G _) (_↔_.from (F↔G _) x FR.>>= g)) (apply-ext ext λ _ → _↔_.left-inverse-of (F↔G _) _) ⟩ _↔_.to (F↔G _) (_↔_.from (F↔G _) x FR.>>= λ x → _↔_.from (F↔G _) (f x) FR.>>= λ x → _↔_.from (F↔G _) (g x)) ≡⟨ cong (_↔_.to (F↔G _)) (FM.associativity _ _ _) ⟩ _↔_.to (F↔G _) ((_↔_.from (F↔G _) x FR.>>= λ x → _↔_.from (F↔G _) (f x)) FR.>>= λ x → _↔_.from (F↔G _) (g x)) ≡⟨ cong (λ y → _↔_.to (F↔G _) (y FR.>>= _)) (sym $ _↔_.left-inverse-of (F↔G _) _) ⟩∎ _↔_.to (F↔G _) (_↔_.from (F↔G _) (_↔_.to (F↔G _) (_↔_.from (F↔G _) x FR.>>= λ x → _↔_.from (F↔G _) (f x))) FR.>>= λ x → _↔_.from (F↔G _) (g x)) ∎ where module FM = Monad F-monad module FR = Raw-monad FM.raw-monad ------------------------------------------------------------------------ -- Identity monads -- The identity monad. identity-monad : ∀ {ℓ} → Monad {d = ℓ} id Raw-monad.return (Monad.raw-monad identity-monad) x = x Raw-monad._>>=_ (Monad.raw-monad identity-monad) x f = f x Monad.left-identity identity-monad x f = refl (f x) Monad.right-identity identity-monad x = refl x Monad.associativity identity-monad x f g = refl (g (f x)) -- The identity monad, defined using a wrapper type to make instance -- resolution easier. record Id {a} (A : Type a) : Type a where constructor wrap field run : A open Id public instance Id-raw-monad : ∀ {ℓ} → Raw-monad {d = ℓ} Id run (Raw-monad.return Id-raw-monad x) = x run (Raw-monad._>>=_ Id-raw-monad x f) = run (f (run x)) Id-monad : ∀ {ℓ} → Monad {d = ℓ} Id Monad.raw-monad Id-monad = Id-raw-monad Monad.left-identity Id-monad x f = cong wrap (refl (run (f x))) Monad.right-identity Id-monad x = cong wrap (refl (run x)) Monad.associativity Id-monad x f g = cong wrap (refl (run (g (run (f (run x))))))
{ "alphanum_fraction": 0.4487120726, "avg_line_length": 38.9607142857, "ext": "agda", "hexsha": "79e608ad75044aa95fcfe222234e43e49dbb8bde", "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/Monad.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/Monad.agda", "max_line_length": 147, "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/Monad.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": 4085, "size": 10909 }
module Structure.Operator where import Lvl open import Functional using (_$_) open import Lang.Instance open import Logic.Predicate open import Logic open import Structure.Setoid open import Structure.Function.Names open import Structure.Function open import Structure.Relator.Properties open import Syntax.Function open import Syntax.Transitivity open import Type private variable ℓ ℓₒ ℓₒ₁ ℓₒ₂ ℓₒ₃ ℓₒ₄ ℓₗ ℓₗ₁ ℓₗ₂ ℓₗ₃ ℓₗ₄ : Lvl.Level private variable A₁ A₂ A₃ B : Type{ℓ} module _ ⦃ equiv-A₁ : Equiv{ℓₗ₁}(A₁) ⦄ ⦃ equiv-A₂ : Equiv{ℓₗ₂}(A₂) ⦄ ⦃ equiv-B : Equiv{ℓₗ₃}(B) ⦄ (_▫_ : A₁ → A₂ → B) where -- The operator `_▫_` "(behaves like)/is a function" in the context of `_≡_` from the Equiv instance. -- `congruence` is the defining property of a binary operation. record BinaryOperator : Type{Lvl.of(A₁) Lvl.⊔ Lvl.of(A₂) Lvl.⊔ ℓₗ₁ Lvl.⊔ ℓₗ₂ Lvl.⊔ ℓₗ₃} where constructor intro field congruence : Congruence₂(_▫_) instance left : ∀{x} → Function(_▫ x) left = intro(proof ↦ congruence proof (reflexivity(_≡_))) instance right : ∀{x} → Function(x ▫_) right = intro(proof ↦ congruence (reflexivity(_≡_)) proof) congruenceₗ : ∀{x₁ x₂}{y} → (x₁ ≡ x₂) → (x₁ ▫ y ≡ x₂ ▫ y) congruenceₗ = Function.congruence(left) congruenceᵣ : ∀{x}{y₁ y₂} → (y₁ ≡ y₂) → (x ▫ y₁ ≡ x ▫ y₂) congruenceᵣ = Function.congruence(right) [≡]-congruence2-left : ⦃ inst : BinaryOperator ⦄ → (x : _) → Function(_▫ x) [≡]-congruence2-left = x ↦ inst-fn(BinaryOperator.left) {x} [≡]-congruence2-right : ⦃ inst : BinaryOperator ⦄ → (x : _) → Function(x ▫_) [≡]-congruence2-right = x ↦ inst-fn(BinaryOperator.right) {x} congruence₂ = inst-fn BinaryOperator.congruence congruence₂ₗ : ⦃ inst : BinaryOperator ⦄ → (a : A₂) → ∀{x y : A₁} → (x ≡ y) → (x ▫ a ≡ y ▫ a) congruence₂ₗ _ = inst-fn BinaryOperator.congruenceₗ -- (congruence₁(_▫ a) ⦃ [≡]-congruence2-left ⦃ inst ⦄ a ⦄) congruence₂ᵣ : ⦃ inst : BinaryOperator ⦄ → (a : A₁) → ∀{x y : A₂} → (x ≡ y) → (a ▫ x ≡ a ▫ y) congruence₂ᵣ _ = inst-fn BinaryOperator.congruenceᵣ functions-to-binaryOperator : ⦃ l : ∀{y} → Function(_▫ y) ⦄ ⦃ r : ∀{x} → Function(x ▫_) ⦄ → BinaryOperator BinaryOperator.congruence functions-to-binaryOperator {x₁} {y₁} {x₂} {y₂} leq req = (x₁ ▫ x₂) 🝖[ _≡_ ]-[ congruence₁(_▫ x₂) leq ] (y₁ ▫ x₂) 🝖[ _≡_ ]-[ congruence₁(y₁ ▫_) req ] (y₁ ▫ y₂) 🝖-end module _ ⦃ equiv-A₁ : Equiv{ℓₗ₁}(A₁) ⦄ ⦃ equiv-A₂ : Equiv{ℓₗ₂}(A₂) ⦄ ⦃ equiv-A₃ : Equiv{ℓₗ₃}(A₃) ⦄ ⦃ equiv-B : Equiv{ℓₗ₄}(B) ⦄ (_▫_▫_ : A₁ → A₂ → A₃ → B) where record TrinaryOperator : Type{Lvl.of(A₁) Lvl.⊔ Lvl.of(A₂) Lvl.⊔ Lvl.of(A₃) Lvl.⊔ ℓₗ₁ Lvl.⊔ ℓₗ₂ Lvl.⊔ ℓₗ₃ Lvl.⊔ ℓₗ₄} where constructor intro field congruence : Congruence₃(_▫_▫_) congruence₃ = inst-fn TrinaryOperator.congruence
{ "alphanum_fraction": 0.6394727467, "avg_line_length": 35.5316455696, "ext": "agda", "hexsha": "0e0aeaa8372529803c9c5a53a87f6133cce3229b", "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.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.agda", "max_line_length": 123, "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.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": 1283, "size": 2807 }
{-# OPTIONS --cubical-compatible #-} open import Agda.Primitive open import Agda.Builtin.Nat open import Agda.Builtin.Equality data ⊥ : Set where record Σ {a} {b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where constructor _,_ field fst : A snd : B fst no : _≡_ {A = Σ Set (λ X → X)} (Nat , 0) (Nat , 1) → ⊥ no ()
{ "alphanum_fraction": 0.5848484848, "avg_line_length": 19.4117647059, "ext": "agda", "hexsha": "d7197ca03240644c0b5917eb0eb703f9a4efbca1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "KDr2/agda", "max_forks_repo_path": "test/Fail/Issue2721.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z", "max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "KDr2/agda", "max_issues_repo_path": "test/Fail/Issue2721.agda", "max_line_length": 64, "max_stars_count": null, "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "KDr2/agda", "max_stars_repo_path": "test/Fail/Issue2721.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 127, "size": 330 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Properties for Conats ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe --sized-types #-} module Codata.Conat.Properties where open import Data.Nat open import Codata.Thunk open import Codata.Conat open import Codata.Conat.Bisimilarity open import Function open import Relation.Nullary open import Relation.Binary sℕ≤s⁻¹ : ∀ {m n} → suc m ℕ≤ suc n → m ℕ≤ n .force sℕ≤s⁻¹ (sℕ≤s p) = p _ℕ≤?_ : Decidable _ℕ≤_ zero ℕ≤? n = yes zℕ≤n suc m ℕ≤? zero = no (λ ()) suc m ℕ≤? suc n with m ℕ≤? n .force ... | yes p = yes (sℕ≤s p) ... | no ¬p = no (¬p ∘′ sℕ≤s⁻¹) 0ℕ+-identity : ∀ {i n} → i ⊢ 0 ℕ+ n ≈ n 0ℕ+-identity = refl +ℕ0-identity : ∀ {i n} → i ⊢ n +ℕ 0 ≈ n +ℕ0-identity {n = zero} = zero +ℕ0-identity {n = suc n} = suc λ where .force → +ℕ0-identity
{ "alphanum_fraction": 0.5200433369, "avg_line_length": 26.3714285714, "ext": "agda", "hexsha": "0ad0da9f3034d5f6f0d4083453bec7387c7beced", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Codata/Conat/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Codata/Conat/Properties.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/Codata/Conat/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 340, "size": 923 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Monoid.Properties where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Data.Nat open import Cubical.Data.NatPlusOne open import Cubical.Data.Sigma hiding (_×_) open import Cubical.Data.Prod open import Cubical.Algebra open import Cubical.Algebra.Properties open import Cubical.Algebra.Monoid.Morphism open import Cubical.Algebra.Semigroup.Properties as Semigroup using (isPropIsSemigroup) open import Cubical.Relation.Binary.Reasoning.Equality open import Cubical.Relation.Unary as Unary open import Cubical.Relation.Binary as Binary open import Cubical.Algebra.Monoid.MorphismProperties public using (MonoidPath; uaMonoid; carac-uaMonoid; Monoid≡; caracMonoid≡) private variable ℓ : Level isPropIsMonoid : ∀ {M : Type ℓ} {_•_ ε} → isProp (IsMonoid M _•_ ε) isPropIsMonoid {_} {_} {_•_} {ε} (ismonoid aSemi aId) (ismonoid bSemi bId) = cong₂ ismonoid (isPropIsSemigroup aSemi bSemi) (isPropIdentity (IsSemigroup.is-set aSemi) _•_ ε aId bId) module MonoidLemmas (M : Monoid ℓ) where open Monoid M ε-comm : ∀ x → x • ε ≡ ε • x ε-comm x = identityʳ x ∙ sym (identityˡ x) ^-zeroˡ : LeftZero ε _^_ ^-zeroˡ zero = refl ^-zeroˡ (suc n) = identityˡ (ε ^ n) ∙ ^-zeroˡ n ^-suc : ∀ x n → x ^ suc n ≡ x ^ n • x ^-suc x zero = ε-comm x ^-suc x (suc n) = x ^ suc (suc n) ≡⟨⟩ x • x ^ suc n ≡⟨ cong (x •_) (^-suc x n) ⟩ x • (x ^ n • x) ≡˘⟨ assoc x (x ^ n) x ⟩ x • x ^ n • x ≡⟨⟩ x ^ suc n • x ∎ ^-plus : ∀ x → Homomorphic₂ (x ^_) _+_ _•_ ^-plus x zero n = sym (identityˡ (x ^ n)) ^-plus x (suc m) n = x ^ (suc m + n) ≡⟨⟩ x • x ^ (m + n) ≡⟨ cong (x •_) (^-plus x m n) ⟩ x • (x ^ m • x ^ n) ≡˘⟨ assoc x (x ^ m) (x ^ n) ⟩ x • x ^ m • x ^ n ≡⟨⟩ x ^ suc m • x ^ n ∎ infixl 10 _^′_ _^′_ = Semigroup._^_ semigroup ^semi≡^ : ∀ x n → x ^′ n ≡ x ^ (ℕ₊₁→ℕ n) ^semi≡^ x one = sym (identityʳ x) ^semi≡^ x (2+ n) = cong (x •_) (^semi≡^ x (1+ n)) -- Invertible elements module Invertible (M : Monoid ℓ) where open Monoid M Inverses′ : RawRel ⟨ M ⟩ ℓ Inverses′ x y = (x • y ≡ ε) × (y • x ≡ ε) isPropInverses : Binary.isPropValued Inverses′ isPropInverses _ _ = isPropProd (is-set _ _) (is-set _ _) Inverses : Rel ⟨ M ⟩ ℓ Inverses = Binary.fromRaw Inverses′ isPropInverses inv-unique′ : ∀ {x y z} → x • y ≡ ε → z • x ≡ ε → y ≡ z inv-unique′ {x} {y} {z} xy≡ε zx≡ε = y ≡˘⟨ identityˡ y ⟩ ε • y ≡˘⟨ cong (_• y) zx≡ε ⟩ (z • x) • y ≡⟨ assoc z x y ⟩ z • (x • y) ≡⟨ cong (z •_) xy≡ε ⟩ z • ε ≡⟨ identityʳ z ⟩ z ∎ inv-unique : ∀ {x y z} → ⟨ Inverses x y ⟩ → ⟨ Inverses x z ⟩ → y ≡ z inv-unique (xy≡ε , _) (_ , zx≡ε) = inv-unique′ xy≡ε zx≡ε Invertible′ : RawPred ⟨ M ⟩ ℓ Invertible′ x = Σ ⟨ M ⟩ (Inverses′ x) isPropInvertible : Unary.isPropValued Invertible′ isPropInvertible x (y , x-y) (z , x-z) = ΣPathTransport→PathΣ (y , x-y) (z , x-z) (inv-unique x-y x-z , isPropInverses _ _ _ _) Invertible : Pred ⟨ M ⟩ ℓ Invertible = Unary.fromRaw Invertible′ isPropInvertible εInverses : ⟨ Inverses ε ε ⟩ εInverses = identityˡ ε , identityˡ ε εInvertible : ε ∈ Invertible εInvertible = ε , εInverses module Kernel {ℓ ℓ′} {M : Monoid ℓ} {N : Monoid ℓ′} (hom : MonoidHom M N) = Semigroup.Kernel (MonoidHom→SemigroupHom hom)
{ "alphanum_fraction": 0.5928449744, "avg_line_length": 29.5966386555, "ext": "agda", "hexsha": "5a8fa833f32d1a5af0db14cbe0afdba2881b1646", "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/Monoid/Properties.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/Monoid/Properties.agda", "max_line_length": 106, "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/Monoid/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1460, "size": 3522 }
-- Andreas, 2017-05-13, issue reported by nad module Issue2579 where open import Common.Bool open import Issue2579.Import import Issue2579.Instance Bool true -- imports instances theWrapped : {{w : Wrap Bool}} → Bool theWrapped {{w}} = Wrap.wrapped w test : Bool test = theWrapped
{ "alphanum_fraction": 0.7421602787, "avg_line_length": 19.1333333333, "ext": "agda", "hexsha": "8900d82e0b361ac6df78bfa5567a4cf1a5d17f4b", "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": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "alhassy/agda", "max_forks_repo_path": "test/Succeed/Issue2579.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "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": "alhassy/agda", "max_issues_repo_path": "test/Succeed/Issue2579.agda", "max_line_length": 57, "max_stars_count": 1, "max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "alhassy/agda", "max_stars_repo_path": "test/Succeed/Issue2579.agda", "max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z", "max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z", "num_tokens": 78, "size": 287 }
-- Andreas, 2013-03-22 -- cut down from https://github.com/agda/agda-assoc-free/src/AssocFree/DList.agda -- {-# OPTIONS -v tc.cover.splittree:10 -v tc.cc:30 #-} module Issue827 where open import Common.Equality -- need to keep this record ! record List (A : Set) : Set where constructor list -- need to keep this constructor field bla : A postulate _++_ : ∀ {A} → List A → List A → List A _∈_ : ∀ {A} (a : A) (as : List A) → Set _≪_ : ∀ {A} {a : A} {as} → (a ∈ as) → ∀ bs → (a ∈ (as ++ bs)) _≫_ : ∀ {A} {a : A} as {bs} → (a ∈ bs) → (a ∈ (as ++ bs)) -- Case on membership data Case {A} a (as bs : List A) : Set where inj₁ : (a∈as : a ∈ as) → Case a as bs inj₂ : (a∈bs : a ∈ bs) → Case a as bs -- Three-way case, used for proving associativity properties data Case₃ {A} (a : A) as bs cs : Set where inj₁ : (a ∈ as) → Case₃ a as bs cs inj₂ : (a ∈ bs) → Case₃ a as bs cs inj₃ : (a ∈ cs) → Case₃ a as bs cs -- Associating case₃ to the right gives case case : ∀ {A} {a : A} {as bs cs} → Case₃ a as bs cs → Case a as (bs ++ cs) case {cs = cs} (inj₂ a∈bs) = inj₂ (a∈bs ≪ cs) case {bs = bs} (inj₃ a∈cs) = inj₂ (bs ≫ a∈cs) case (inj₁ a∈as) = inj₁ a∈as works : ∀ {A} {a : A} {as bs cs : List A} {a∈bs : a ∈ bs} → case {as = as} (inj₂ a∈bs) ≡ inj₂ (a∈bs ≪ cs) works = refl -- Different order of clauses fails: case′ : ∀ {A} {a : A} {as bs cs} → Case₃ a as bs cs → Case a as (bs ++ cs) case′ (inj₁ a∈as) = inj₁ a∈as case′ {cs = cs} (inj₂ a∈bs) = inj₂ (a∈bs ≪ cs) case′ {bs = bs} (inj₃ a∈cs) = inj₂ (bs ≫ a∈cs) fails : ∀ {A} {a : A} {as bs cs : List A} {a∈bs : a ∈ bs} → case′ {as = as} (inj₂ a∈bs) ≡ inj₂ (a∈bs ≪ cs) fails = refl -- There was a bug in the record pattern translation. -- Solution: expand all catch-alls in position of a record -- pattern split. Then record pattern translation works fine.
{ "alphanum_fraction": 0.567115903, "avg_line_length": 32.5438596491, "ext": "agda", "hexsha": "eafaaa0c7e6cdb6374dbe9697f99fd17638bf73e", "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/Issue827.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/Issue827.agda", "max_line_length": 82, "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/Issue827.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": 770, "size": 1855 }
{-# OPTIONS --without-K --safe #-} module Cats.Category.Constructions.Initial where open import Data.Product using (proj₁ ; proj₂) open import Level open import Cats.Category.Base import Cats.Category.Constructions.Iso as Iso import Cats.Category.Constructions.Unique as Unique module Build {lo la l≈} (Cat : Category lo la l≈) where open Category Cat open Iso.Build Cat open Unique.Build Cat IsInitial : Obj → Set (lo ⊔ la ⊔ l≈) IsInitial ⊥ = ∀ X → ∃! ⊥ X record HasInitial : Set (lo ⊔ la ⊔ l≈) where field ⊥ : Obj isInitial : IsInitial ⊥ ¡ : ∀ X → ⊥ ⇒ X ¡ X = ∃!′.arr (isInitial X) ¡-unique : ∀ {X} (f : ⊥ ⇒ X) → ¡ X ≈ f ¡-unique {X} f = ∃!′.unique (isInitial X) _ ⊥⇒-unique : ∀ {X} (f g : ⊥ ⇒ X) → f ≈ g ⊥⇒-unique f g = ≈.trans (≈.sym (¡-unique f)) (¡-unique g) ⊥-unique : ∀ {X} → IsInitial X → X ≅ ⊥ ⊥-unique {X} init = record { forth = init ⊥ .∃!′.arr ; back = ¡ X ; back-forth = ≈.trans (≈.sym (init X .∃!′.unique _)) (init X .∃!′.unique _) ; forth-back = ⊥⇒-unique _ _ } initial-unique : ∀ {X Y} → IsInitial X → IsInitial Y → X ≅ Y initial-unique X-init Y-init = HasInitial.⊥-unique (record { isInitial = Y-init }) X-init open Build public using (HasInitial) private open module Build′ {lo la l≈} {C : Category lo la l≈} = Build C public using (IsInitial ; initial-unique)
{ "alphanum_fraction": 0.5749822317, "avg_line_length": 23.0655737705, "ext": "agda", "hexsha": "97f0fca9a1ca7f58c601c86c27f75399bf7090ac", "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/Constructions/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/Constructions/Initial.agda", "max_line_length": 82, "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/Constructions/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": 509, "size": 1407 }
{-# OPTIONS --safe --warning=error #-} open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import LogicalFormulae open import Functions.Definition open import Boolean.Definition open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order open import Vectors module Logic.PropositionalLogic where data Propositions {a : _} (primitives : Set a) : Set a where ofPrimitive : primitives → Propositions primitives false : Propositions primitives implies : (a b : Propositions primitives) → Propositions primitives prNot : {a : _} {pr : Set a} → Propositions pr → Propositions pr prNot p = implies p false impliesIsBigger : {a : _} {pr : Set a} {P Q : Propositions pr} → Q ≡ implies P Q → False impliesIsBigger {P = P} {Q} () impliesInjectiveL : {a : _} {A : Set a} → {p q r : Propositions A} → implies p q ≡ implies r q → p ≡ r impliesInjectiveL refl = refl impliesInjectiveR : {a : _} {A : Set a} → {p q r : Propositions A} → implies p q ≡ implies p r → q ≡ r impliesInjectiveR refl = refl impliesInjective : {a : _} {A : Set a} → {p q r s : Propositions A} → implies p q ≡ implies r s → (p ≡ r) && (q ≡ s) impliesInjective refl = refl ,, refl record Valuation {a : _} (primitives : Set a) : Set a where field v : Propositions primitives → Bool vFalse : v false ≡ BoolFalse vImplicationF : {p q : Propositions primitives} → v p ≡ BoolTrue → v q ≡ BoolFalse → v (implies p q) ≡ BoolFalse vImplicationVacuous : {p q : Propositions primitives} → v p ≡ BoolFalse → v (implies p q) ≡ BoolTrue vImplicationT : {p q : Propositions primitives} → v q ≡ BoolTrue → v (implies p q) ≡ BoolTrue -- Proposition 1a valuationIsDetermined : {a : _} {pr : Set a} → (v1 v2 : Valuation pr) → ({x : pr} → Valuation.v v1 (ofPrimitive x) ≡ Valuation.v v2 (ofPrimitive x)) → {x : Propositions pr} → Valuation.v v1 x ≡ Valuation.v v2 x valuationIsDetermined v1 v2 pr {ofPrimitive x} = pr valuationIsDetermined v1 v2 pr {false} rewrite Valuation.vFalse v1 | Valuation.vFalse v2 = refl valuationIsDetermined v1 v2 pr {implies x y} with valuationIsDetermined v1 v2 pr {x} valuationIsDetermined v1 v2 pr {implies x y} | eqX with valuationIsDetermined v1 v2 pr {y} ... | eqY with inspect (Valuation.v v1 x) valuationIsDetermined v1 v2 pr {implies x y} | eqX | eqY | BoolTrue with≡ p with inspect (Valuation.v v1 y) valuationIsDetermined v1 v2 pr {implies x y} | eqX | eqY | BoolTrue with≡ p | BoolTrue with≡ q rewrite p | q | Valuation.vImplicationT v2 {p = x} {q = y} (equalityCommutative eqY) | Valuation.vImplicationT v1 {p = x} {q = y} q = refl valuationIsDetermined v1 v2 pr {implies x y} | eqX | eqY | BoolTrue with≡ p | BoolFalse with≡ q rewrite p | q | Valuation.vImplicationF v1 p q | Valuation.vImplicationF v2 (equalityCommutative eqX) (equalityCommutative eqY) = refl valuationIsDetermined v1 v2 pr {implies x y} | eqX | eqY | BoolFalse with≡ p rewrite p | Valuation.vImplicationVacuous v1 {q = y} p | Valuation.vImplicationVacuous v2 {q = y} (equalityCommutative eqX) = refl extendValuationV : {a : _} {pr : Set a} → (w : pr → Bool) → Propositions pr → Bool extendValuationV w (ofPrimitive x) = w x extendValuationV w false = BoolFalse extendValuationV w (implies x y) with extendValuationV w x ... | BoolTrue with extendValuationV w y extendValuationV w (implies x y) | BoolTrue | BoolTrue = BoolTrue ... | BoolFalse = BoolFalse extendValuationV w (implies x y) | BoolFalse = BoolTrue extendValuation : {a : _} {pr : Set a} → (w : pr → Bool) → Valuation pr Valuation.v (extendValuation w) = extendValuationV w Valuation.vFalse (extendValuation w) = refl Valuation.vImplicationF (extendValuation w) {p} {q} pT qF with Valuation.v (extendValuation w) p Valuation.vImplicationF (extendValuation w) {p} {q} refl qF | BoolTrue with Valuation.v (extendValuation w) q Valuation.vImplicationF (extendValuation w) {p} {q} refl () | BoolTrue | BoolTrue Valuation.vImplicationF (extendValuation w) {p} {q} refl refl | BoolTrue | BoolFalse = refl Valuation.vImplicationF (extendValuation w) {p} {q} () qF | BoolFalse Valuation.vImplicationVacuous (extendValuation w) {p} {q} pF with Valuation.v (extendValuation w) p Valuation.vImplicationVacuous (extendValuation w) {p} {q} () | BoolTrue Valuation.vImplicationVacuous (extendValuation w) {p} {q} refl | BoolFalse = refl Valuation.vImplicationT (extendValuation w) {p} {q} qT with Valuation.v (extendValuation w) p Valuation.vImplicationT (extendValuation w) {p} {q} qT | BoolTrue with Valuation.v (extendValuation w) q Valuation.vImplicationT (extendValuation w) {p} {q} refl | BoolTrue | BoolTrue = refl Valuation.vImplicationT (extendValuation w) {p} {q} () | BoolTrue | BoolFalse Valuation.vImplicationT (extendValuation w) {p} {q} qT | BoolFalse = refl -- Proposition 1b valuationsAreFree : {a : _} {pr : Set a} → (w : pr → Bool) → {x : pr} → Valuation.v (extendValuation w) (ofPrimitive x) ≡ w x valuationsAreFree w = refl Tautology : {a : _} {pr : Set a} (prop : Propositions pr) → Set a Tautology {pr = pr} prop = (v : Valuation pr) → Valuation.v v prop ≡ BoolTrue record IsSubset {a b : _} (sub : Set a) (super : Set b) : Set (a ⊔ b) where field ofElt : sub → super mapProp : {a b : _} {pr1 : Set a} {pr2 : Set b} → (pr1 → pr2) → Propositions pr1 → Propositions pr2 mapProp f (ofPrimitive x) = ofPrimitive (f x) mapProp f false = false mapProp f (implies p q) = implies (mapProp f p) (mapProp f q) inheritedValuation : {a b : _} {sub : Set a} {super : Set b} → (IsSubset sub super) → Valuation super → Valuation sub Valuation.v (inheritedValuation isSub v) prop = Valuation.v v (mapProp (IsSubset.ofElt isSub) prop) Valuation.vFalse (inheritedValuation isSub v) = Valuation.vFalse v Valuation.vImplicationF (inheritedValuation isSub v) pT qF = Valuation.vImplicationF v pT qF Valuation.vImplicationVacuous (inheritedValuation isSub v) pF = Valuation.vImplicationVacuous v pF Valuation.vImplicationT (inheritedValuation isSub v) qT = Valuation.vImplicationT v qT inheritedValuation' : {a b : _} {sub : Set a} {super : Set b} → (IsSubset sub (Propositions super)) → Valuation super → (x : sub) → Bool inheritedValuation' subset v x = Valuation.v v (IsSubset.ofElt subset x) Entails : {a b : _} {sub : Set a} {super : Set b} (S : IsSubset sub (Propositions super)) (P : Propositions super) → Set (a ⊔ b) Entails {sub = sub} {super = super} S P = {v : Valuation super} → ({s : sub} → inheritedValuation' S v s ≡ BoolTrue) → Valuation.v v P ≡ BoolTrue data ThreeElements : Set where One : ThreeElements Two : ThreeElements Three : ThreeElements indexAxiom : {a : _} (A : Set a) → ThreeElements → Set a indexAxiom A One = Propositions A && Propositions A indexAxiom A Two = Propositions A & Propositions A & Propositions A indexAxiom A Three = Propositions A indexPropositionalAxioms : {a : _} {A : Set a} → Set a indexPropositionalAxioms {A = A} = Sg ThreeElements (indexAxiom A) -- An axiom system is simply a subset of a set of propositions. propositionalAxioms : {a : _} {A : Set a} → IsSubset (indexPropositionalAxioms {A = A}) (Propositions A) IsSubset.ofElt propositionalAxioms (One , (p ,, q)) = implies p (implies q p) IsSubset.ofElt propositionalAxioms (Two , record { one = p ; two = q ; three = r }) = implies (implies p (implies q r)) (implies (implies p q) (implies p r)) IsSubset.ofElt propositionalAxioms (Three , p) = implies (prNot (prNot p)) p record Selection {a : _} {A : Set a} {n : ℕ} (l : Vec A n) : Set a where field element : A position : ℕ pos<N : position <N n elementIsAt : vecIndex l position pos<N ≡ element data Proof {a b c : _} {A : Set a} {axioms : Set b} (axiomsSubset : IsSubset axioms (Propositions A)) {givens : Set c} (givensSubset : IsSubset givens (Propositions A)) : (n : ℕ) → Set (a ⊔ b ⊔ c) data ProofStep {a b c : _} {A : Set a} {axioms : Set b} (axiomsSubset : IsSubset axioms (Propositions A)) {givens : Set c} (givensSubset : IsSubset givens (Propositions A)) {n : ℕ} (proofSoFar : Proof {a} {b} {c} {A} {axioms} axiomsSubset {givens} givensSubset n) : Set (a ⊔ b ⊔ c) toSteps : {a b c : _} {A : Set a} {axioms : Set b} {axiomsSubset : IsSubset axioms (Propositions A)} {givens : Set c} {givensSubset : IsSubset givens (Propositions A)} {n : ℕ} (pr : Proof {axioms = axioms} axiomsSubset {givens = givens} givensSubset n) → Vec (Propositions A) n data ProofStep {a} {b} {c} {A} {axioms} axiomsSubset {givens} givensSubset proofSoFar where axiom : axioms → ProofStep axiomsSubset givensSubset proofSoFar given : givens → ProofStep axiomsSubset givensSubset proofSoFar modusPonens : (implication : Selection (toSteps proofSoFar)) → (argument : Selection (toSteps proofSoFar)) → (conclusion : Propositions A) → (Selection.element implication ≡ implies (Selection.element argument) conclusion) → ProofStep axiomsSubset givensSubset proofSoFar data Proof {a} {b} {c} {A} {axioms} axiomsSubset {givens} givensSubset where empty : Proof axiomsSubset givensSubset 0 nextStep : (n : ℕ) → (previous : Proof {axioms = axioms} axiomsSubset {givens = givens} givensSubset n) → ProofStep axiomsSubset givensSubset previous → Proof axiomsSubset givensSubset (succ n) toSteps empty = [] toSteps {axiomsSubset = axiomsSubset} (nextStep n pr (axiom x)) = (IsSubset.ofElt axiomsSubset x) ,- toSteps pr toSteps {givensSubset = givensSubset} (nextStep n pr (given x)) = IsSubset.ofElt givensSubset x ,- toSteps pr toSteps (nextStep n pr (modusPonens implication argument conclusion x)) = conclusion ,- toSteps pr record Proves {a b c : _} {A : Set a} {axioms : Set b} (axiomsSubset : IsSubset axioms (Propositions A)) {givens : Set c} (givensSubset : IsSubset givens (Propositions A)) (P : Propositions A) : Set (a ⊔ b ⊔ c) where field n : ℕ proof : Proof axiomsSubset givensSubset (succ n) ofStatement : vecIndex (toSteps proof) 0 (succIsPositive n) ≡ P addSingletonSet : {a : _} → Set a → Set a addSingletonSet A = True || A interpretSingletonSet : {a b c : _} {A : Set a} {B : Set b} {C : Set c} → IsSubset A B → (c : C) → (addSingletonSet A) → C || B interpretSingletonSet A<B c (inl x) = inl c interpretSingletonSet A<B _ (inr x) = inr (IsSubset.ofElt A<B x) inrInjective : {a b : _} {A : Set a} {B : Set b} {b1 b2 : B} → inr {a = a} {A = A} b1 ≡ inr b2 → b1 ≡ b2 inrInjective refl = refl singletonSubset : {a b c : _} {A : Set a} {B : Set b} {C : Set c} → IsSubset A B → (c : C) → IsSubset (addSingletonSet A) (C || B) IsSubset.ofElt (singletonSubset subs c) = interpretSingletonSet subs c adjoinGiven : {a b : _} {A : Set a} {givens : Set b} (givensSubset : IsSubset givens A) (P : A) → IsSubset (addSingletonSet givens) A IsSubset.ofElt (adjoinGiven record { ofElt = ofElt } P) (inl x) = P IsSubset.ofElt (adjoinGiven record { ofElt = ofElt } _) (inr x) = ofElt x vecIndexRefl : {a : _} {A : Set a} {n : ℕ} {v1 v2 : Vec A n} → {pos : ℕ} → {pos<N1 pos<N2 : pos <N n} → v1 ≡ v2 → vecIndex v1 pos pos<N1 ≡ vecIndex v2 pos pos<N2 vecIndexRefl {v1 = v1} {.v1} {pos} {pos<N1} {pos<N2} refl = refl {- proofRemainsValidOnAddingGivens : {a b c : _} {A : Set a} {axioms : Set b} {axiomsSubset : IsSubset axioms (Propositions A)} {givens : Set c} {givensSubset : IsSubset givens (Propositions A)} {n : ℕ} → {Q : Propositions A} → Proof axiomsSubset givensSubset n → Proof axiomsSubset (adjoinGiven givensSubset Q) n pr' : {a b c : _} {A : Set a} {axioms : Set b} {axiomsSubset : IsSubset axioms (Propositions A)} {givens : Set c} {givensSubset : IsSubset givens (Propositions A)} {n : ℕ} → {Q : Propositions A} → (pr : Proof axiomsSubset givensSubset n) → toSteps pr ≡ toSteps (proofRemainsValidOnAddingGivens {Q = Q} pr) pr' empty = refl pr' (nextStep n pr (axiom x)) rewrite pr' pr = refl pr' (nextStep n pr (given x)) rewrite pr' pr = refl pr' (nextStep n pr (modusPonens implication argument conclusion x)) rewrite pr' pr = refl proofRemainsValidOnAddingGivens {Q = Q} empty = empty proofRemainsValidOnAddingGivens {Q = Q} (nextStep n pr (axiom x)) = nextStep n (proofRemainsValidOnAddingGivens pr) (axiom x) proofRemainsValidOnAddingGivens {Q = Q} (nextStep n pr (given x)) = nextStep n (proofRemainsValidOnAddingGivens pr) (given (inr x)) proofRemainsValidOnAddingGivens {A = A} {axiomsSubset = axiomsSubset} {givensSubset = givensSubset} {Q = Q} (nextStep n pr (modusPonens implication argument conclusion x)) = nextStep n (proofRemainsValidOnAddingGivens pr) (modusPonens (record { element = Selection.element implication ; position = Selection.position implication ; pos<N = Selection.pos<N implication ; elementIsAt = lemma implication }) (record { element = Selection.element argument ; position = Selection.position argument ; pos<N = Selection.pos<N argument ; elementIsAt = lemma argument }) conclusion x) where lemma : (sel : Selection (toSteps pr)) → vecIndex (toSteps (proofRemainsValidOnAddingGivens pr)) (Selection.position sel) (Selection.pos<N sel) ≡ Selection.element sel lemma sel with proofRemainsValidOnAddingGivens {Q = Q} pr ... | nextStep n bl x = {!!} -} {- proofImpliesProves : {a b c : _} {A : Set a} {axioms : Set b} {axiomsSubset : IsSubset axioms (Propositions A)} {givens : Set c} {givensSubset : IsSubset givens (Propositions A)} {n : ℕ} (0<n : 0 <N n) → (p : Proof axiomsSubset givensSubset n) → (pr : Propositions A) → vecIndex (toSteps p) 0 0<n ≡ pr → Proves axiomsSubset givensSubset pr proofImpliesProves {n = zero} () p pr x proofImpliesProves {n = succ n} _ p pr x = record { n = n ; proof = p ; ofStatement = transitivity (vecIndexRefl {v1 = toSteps p} refl) x } deductionTheorem' : {a b c : _} {A : Set a} {axioms : Set b} {axiomsSubset : IsSubset axioms (Propositions A)} {givens : Set c} {givensSubset : IsSubset givens (Propositions A)} {n : ℕ} → {P Q : Propositions A} → Proves axiomsSubset givensSubset (implies P Q) → Proves axiomsSubset {givens = addSingletonSet givens} (adjoinGiven givensSubset P) Q Proves.n (deductionTheorem' record { n = n ; proof = proof ; ofStatement = ofStatement }) = succ (succ n) Proves.proof (deductionTheorem' {P = P} {Q = Q} record { n = n ; proof = proof ; ofStatement = ofStatement }) = nextStep (succ (succ n)) (nextStep (succ n) (proofRemainsValidOnAddingGivens proof) (given (inl record {}))) (modusPonens (record { element = implies P Q ; position = 1 ; pos<N = succPreservesInequality (succIsPositive _) ; elementIsAt = transitivity (equalityCommutative (vecIndexRefl (pr' proof))) ofStatement }) (record { element = P ; position = 0 ; pos<N = succIsPositive _ ; elementIsAt = refl }) Q refl) Proves.ofStatement (deductionTheorem' record { n = n ; proof = proof ; ofStatement = ofStatement }) = refl deductionTheorem : {a b c : _} {A : Set a} {givens : Set c} {givensSubset : IsSubset givens (Propositions A)} {n : ℕ} → {P Q : Propositions A} → Proves propositionalAxioms {givens = addSingletonSet givens} (adjoinGiven givensSubset P) Q → Proves propositionalAxioms givensSubset (implies P Q) deductionTheorem {P = P} {Q} record { n = n ; proof = (nextStep .n proof (axiom x)) ; ofStatement = ofStatement } = {!!} --... | bl = record { n = {!!} ; proof = nextStep (succ (succ (succ n))) (nextStep (succ (succ n)) (nextStep (succ n) {!deductionTheorem proof!} (axiom x)) (axiom (One , (Q ,, P)))) (modusPonens (record { element = implies Q (implies P Q) ; position = 0 ; pos<N = succIsPositive _ ; elementIsAt = refl }) (record { element = Q ; position = 1 ; pos<N = succPreservesInequality (succIsPositive _) ; elementIsAt = ofStatement }) (implies P Q) refl) ; ofStatement = {!!} } deductionTheorem {P = P} {Q} record { n = n ; proof = (nextStep .n proof (given x)) ; ofStatement = ofStatement } = {!!} deductionTheorem {P = P} {Q} record { n = n ; proof = (nextStep .n proof (modusPonens implication argument conclusion x)) ; ofStatement = ofStatement } = {!!} {- Proves.n (deductionTheorem {P = P} {Q} record { n = n ; proof = (nextStep .n proof (axiom x)) ; ofStatement = ofStatement }) = succ (succ (succ n)) Proves.proof (deductionTheorem {P = P} {Q} record { n = n ; proof = (nextStep .n proof (axiom x)) ; ofStatement = ofStatement }) = nextStep (succ (succ (succ n))) (nextStep (succ (succ n)) (nextStep (succ n) {!!} (axiom x)) (axiom (One , (Q ,, P)))) (modusPonens (record { element = implies Q (implies P Q) ; position = 0 ; pos<N = succIsPositive _ ; elementIsAt = refl }) (record { element = Q ; position = 1 ; pos<N = succPreservesInequality (succIsPositive _) ; elementIsAt = ofStatement }) (implies P Q) refl) Proves.ofStatement (deductionTheorem {P = P} {Q} record { n = n ; proof = (nextStep .n proof (axiom x)) ; ofStatement = ofStatement }) = {!!} deductionTheorem {P = P} {Q} record { n = n ; proof = (nextStep .n proof (given x)) ; ofStatement = ofStatement } = {!!} deductionTheorem {P = P} {Q} record { n = n ; proof = (nextStep .n proof (modusPonens implication argument conclusion x)) ; ofStatement = ofStatement } = {!!} -} propositionalLogicSound : {a b c : _} {A : Set a} {givens : Set c} {givensSubset : IsSubset givens (Propositions A)} → {P : Propositions A} → Proves propositionalAxioms givensSubset P → Entails givensSubset P Entails.entails (propositionalLogicSound {P = .(IsSubset.ofElt propositionalAxioms x)} record { n = .0 ; proof = (nextStep .0 empty (axiom x)) ; ofStatement = refl }) {v} values = propositionalAxiomsTautology x {v} Entails.entails (propositionalLogicSound {P = P} record { n = .0 ; proof = (nextStep .0 empty (given x)) ; ofStatement = ofStatement }) {v} values rewrite equalityCommutative ofStatement = values {x} Entails.entails (propositionalLogicSound {P = P} record { n = .0 ; proof = (nextStep .0 empty (modusPonens record { element = element ; position = zero ; pos<N = (le x₁ ()) ; elementIsAt = elementIsAt } argument conclusion x)) ; ofStatement = ofStatement }) {v} values Entails.entails (propositionalLogicSound {P = P} record { n = .0 ; proof = (nextStep .0 empty (modusPonens record { element = element ; position = (succ position) ; pos<N = (le x₁ ()) ; elementIsAt = elementIsAt } argument conclusion x)) ; ofStatement = ofStatement }) {v} values Entails.entails (propositionalLogicSound {P = P} record { n = .(succ n) ; proof = (nextStep .(succ n) (nextStep n proof y) x) ; ofStatement = ofStatement }) {v} values = {!!} -}
{ "alphanum_fraction": 0.6969463972, "avg_line_length": 78.1459227468, "ext": "agda", "hexsha": "6c62c5c97c169a75da7bf737d2fb8da82772d1ce", "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": "Logic/PropositionalLogic.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": "Logic/PropositionalLogic.agda", "max_line_length": 574, "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": "Logic/PropositionalLogic.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": 6148, "size": 18208 }
{-# OPTIONS --warning=error --safe #-} open import LogicalFormulae open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import Functions.Definition open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order module Numbers.Naturals.WithK where <NRefl : {a b : ℕ} → (p1 p2 : a <N b) → (p1 ≡ p2) <NRefl {a} {.(succ (p1 +N a))} (le p1 refl) (le p2 proof2) = help p1=p2 proof2 where p1=p2 : p1 ≡ p2 p1=p2 = equalityCommutative (canSubtractFromEqualityRight {p2} {a} {p1} (succInjective proof2)) help : (p1 ≡ p2) → (pr2 : succ (p2 +N a) ≡ succ (p1 +N a)) → le p1 refl ≡ le p2 pr2 help refl refl = refl
{ "alphanum_fraction": 0.6635514019, "avg_line_length": 35.6666666667, "ext": "agda", "hexsha": "6476fa9e3e144e28db166f1b95ef814e6f8dee7b", "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/Naturals/WithK.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/Naturals/WithK.agda", "max_line_length": 99, "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/Naturals/WithK.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": 244, "size": 642 }
module bool-to-string where open import bool open import string 𝔹-to-string : 𝔹 → string 𝔹-to-string tt = "tt" 𝔹-to-string ff = "ff"
{ "alphanum_fraction": 0.7089552239, "avg_line_length": 16.75, "ext": "agda", "hexsha": "76644424fefa2b62490c13859ab6320f04bbedf6", "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": "bool-to-string.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": "bool-to-string.agda", "max_line_length": 27, "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": "bool-to-string.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": 46, "size": 134 }
------------------------------------------------------------------------ -- The two semantical definitions of subtyping are equivalent ------------------------------------------------------------------------ module RecursiveTypes.Subtyping.Semantic.Equivalence where open import Data.Nat open import Codata.Musical.Notation open import Function.Base open import RecursiveTypes.Syntax open import RecursiveTypes.Subtyping.Semantic.Inductive open import RecursiveTypes.Subtyping.Semantic.Coinductive mutual ≤∞⇒≤↓ : ∀ {n} {σ τ : Tree n} → σ ≤∞ τ → σ ≤↓ τ ≤∞⇒≤↓ le zero = ⊥ ≤∞⇒≤↓ ⊥ (suc k) = ⊥ ≤∞⇒≤↓ ⊤ (suc k) = ⊤ ≤∞⇒≤↓ var (suc k) = refl ≤∞⇒≤↓ (τ₁≤σ₁ ⟶ σ₂≤τ₂) (suc k) = ≤∞⇒≤↑ (♭ τ₁≤σ₁) k ⟶ ≤∞⇒≤↓ (♭ σ₂≤τ₂) k ≤∞⇒≤↑ : ∀ {n} {σ τ : Tree n} → σ ≤∞ τ → σ ≤↑ τ ≤∞⇒≤↑ le zero = ⊤ ≤∞⇒≤↑ ⊥ (suc k) = ⊥ ≤∞⇒≤↑ ⊤ (suc k) = ⊤ ≤∞⇒≤↑ var (suc k) = refl ≤∞⇒≤↑ (τ₁≤σ₁ ⟶ σ₂≤τ₂) (suc k) = ≤∞⇒≤↓ (♭ τ₁≤σ₁) k ⟶ ≤∞⇒≤↑ (♭ σ₂≤τ₂) k domain : ∀ {n} {σ₁ σ₂ τ₁ τ₂ : FinTree n} → σ₁ ⟶ σ₂ ≤Fin τ₁ ⟶ τ₂ → σ₂ ≤Fin τ₂ domain refl = refl domain (τ₁≤σ₁ ⟶ σ₂≤τ₂) = σ₂≤τ₂ codomain : ∀ {n} {σ₁ σ₂ τ₁ τ₂ : FinTree n} → σ₁ ⟶ σ₂ ≤Fin τ₁ ⟶ τ₂ → τ₁ ≤Fin σ₁ codomain refl = refl codomain (τ₁≤σ₁ ⟶ σ₂≤τ₂) = τ₁≤σ₁ mutual ≤↑⇒≤∞ : ∀ {n} (σ τ : Tree n) → σ ≤↑ τ → σ ≤∞ τ ≤↑⇒≤∞ ⊥ _ le = ⊥ ≤↑⇒≤∞ _ ⊤ le = ⊤ ≤↑⇒≤∞ ⊤ ⊥ le with le 1 ... | () ≤↑⇒≤∞ ⊤ (var x) le with le 1 ... | () ≤↑⇒≤∞ ⊤ (σ ⟶ τ) le with le 1 ... | () ≤↑⇒≤∞ (var x) ⊥ le with le 1 ... | () ≤↑⇒≤∞ (var x) (var x′) le with le 1 ≤↑⇒≤∞ (var x) (var .x) le | refl = var ≤↑⇒≤∞ (var x) (σ ⟶ τ) le with le 1 ... | () ≤↑⇒≤∞ (σ₁ ⟶ τ₁) ⊥ le with le 1 ... | () ≤↑⇒≤∞ (σ₁ ⟶ τ₁) (var x) le with le 1 ... | () ≤↑⇒≤∞ (σ₁ ⟶ τ₁) (σ₂ ⟶ τ₂) le = ♯ ≤↓⇒≤∞ (♭ σ₂) (♭ σ₁) (codomain ∘ le ∘ suc) ⟶ ♯ ≤↑⇒≤∞ (♭ τ₁) (♭ τ₂) (domain ∘ le ∘ suc) ≤↓⇒≤∞ : ∀ {n} (σ τ : Tree n) → σ ≤↓ τ → σ ≤∞ τ ≤↓⇒≤∞ ⊥ _ le = ⊥ ≤↓⇒≤∞ _ ⊤ le = ⊤ ≤↓⇒≤∞ ⊤ ⊥ le with le 1 ... | () ≤↓⇒≤∞ ⊤ (var x) le with le 1 ... | () ≤↓⇒≤∞ ⊤ (σ ⟶ τ) le with le 1 ... | () ≤↓⇒≤∞ (var x) ⊥ le with le 1 ... | () ≤↓⇒≤∞ (var x) (var x′) le with le 1 ≤↓⇒≤∞ (var x) (var .x) le | refl = var ≤↓⇒≤∞ (var x) (σ ⟶ τ) le with le 1 ... | () ≤↓⇒≤∞ (σ₁ ⟶ τ₁) ⊥ le with le 1 ... | () ≤↓⇒≤∞ (σ₁ ⟶ τ₁) (var x) le with le 1 ... | () ≤↓⇒≤∞ (σ₁ ⟶ τ₁) (σ₂ ⟶ τ₂) le = ♯ ≤↑⇒≤∞ (♭ σ₂) (♭ σ₁) (codomain ∘ le ∘ suc) ⟶ ♯ ≤↓⇒≤∞ (♭ τ₁) (♭ τ₂) (domain ∘ le ∘ suc) Ind⇒Coind : ∀ {n} {σ τ : Ty n} → σ ≤Ind τ → σ ≤Coind τ Ind⇒Coind = ≤↓⇒≤∞ _ _ Coind⇒Ind : ∀ {n} {σ τ : Ty n} → σ ≤Coind τ → σ ≤Ind τ Coind⇒Ind = ≤∞⇒≤↓
{ "alphanum_fraction": 0.3786372007, "avg_line_length": 28.8829787234, "ext": "agda", "hexsha": "a13e0384d1bdb73931e1214f63f79f45adb1d24f", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/codata", "max_forks_repo_path": "RecursiveTypes/Subtyping/Semantic/Equivalence.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/codata", "max_issues_repo_path": "RecursiveTypes/Subtyping/Semantic/Equivalence.agda", "max_line_length": 72, "max_stars_count": 1, "max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/codata", "max_stars_repo_path": "RecursiveTypes/Subtyping/Semantic/Equivalence.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z", "max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z", "num_tokens": 1551, "size": 2715 }
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- Based on (Vene, 2000). module Functors where infixr 1 _+_ infixr 2 _×_ data Bool : Set where false true : Bool data _+_ (A B : Set) : Set where inl : A → A + B inr : B → A + B data _×_ (A B : Set) : Set where _,_ : A → B → A × B -- The terminal object. data ⊤ : Set where <> : ⊤ postulate -- The least fixed-point. -- Haskell definitions: -- data Mu f = In (f (Mu f)) -- unIn :: Mu f → f (Mu f) -- unIn (In x) = x μ : (Set → Set) → Set In : {F : Set → Set} → F (μ F) → μ F unIn : {F : Set → Set} → μ F → F (μ F) postulate -- The greatest fixed-point. -- Haskell definitions: -- data Nu f = Wrap (f (Nu f)) -- out :: Nu f → (f (Nu f)) -- out (Wrap x) = x ν : (Set → Set) → Set Wrap : {F : Set → Set} → F (ν F) → ν F out : {F : Set → Set} → ν F → F (ν F) ------------------------------------------------------------------------------ -- Functors -- The identity functor (the functor for the empty and unit types). IdF : Set → Set IdF X = X -- The (co)natural numbers functor. NatF : Set → Set NatF X = ⊤ + X -- The (co)list functor. ListF : Set → Set → Set ListF A X = ⊤ + A × X -- The stream functor. StreamF : Set → Set → Set StreamF A X = A × X ------------------------------------------------------------------------------ -- Types as least fixed-points -- The empty type is a least fixed-point. ⊥ : Set ⊥ = μ IdF -- The natural numbers type is a least fixed-point. N : Set N = μ NatF -- The data constructors for the natural numbers. zero : N zero = In (inl <>) succ : N → N succ n = In (inr n) -- The list type is a least fixed-point. List : Set → Set List A = μ (ListF A) -- The data constructors for List. nil : {A : Set} → List A nil = In (inl <>) cons : {A : Set} → A → List A → List A cons x xs = In (inr (x , xs)) ------------------------------------------------------------------------------ -- Types as greatest fixed-points -- The unit type is a greatest fixed-point. Unit : Set Unit = ν IdF -- Non-structural recursion -- unit : Nu IdF -- unit = Wrap IdF {!unit!} -- The conat type is a greatest fixed-point. Conat : Set Conat = ν NatF zeroC : Conat zeroC = Wrap (inl <>) succC : Conat → Conat succC cn = Wrap (inr cn) -- Non-structural recursion for the definition of ∞C. -- ∞C : Conat -- ∞C = succC {!∞C!} -- The pred function is the conat destructor. pred : Conat → ⊤ + Conat pred cn with out cn ... | inl _ = inl <> ... | inr x = inr x -- The colist type is a greatest fixed-point. Colist : Set → Set Colist A = ν (ListF A) -- The colist data constructors. nilCL : {A : Set} → Colist A nilCL = Wrap (inl <>) consCL : {A : Set} → A → Colist A → Colist A consCL x xs = Wrap (inr (x , xs)) -- The colist destructors. nullCL : {A : Set} → Colist A → Bool nullCL xs with out xs ... | inl _ = true ... | inr _ = false -- headCL : {A : Set} → Colist A → A -- headCL {A} xs with out (ListF A) xs -- ... | inl t = -- Impossible -- ... | inr (x , _) = x -- tailCL : {A : Set} → Colist A → Colist A -- tailCL {A} xs with out (ListF A) xs -- ... | inl t = -- Impossible -- ... | inr (_ , xs') = xs' -- The stream type is a greatest fixed-point. Stream : Set → Set Stream A = ν (StreamF A) -- The stream data constructor. consS : {A : Set} → A → Stream A → Stream A consS x xs = Wrap (x , xs) -- The stream destructors. headS : {A : Set} → Stream A → A headS xs with out xs ... | x , _ = x tailS : {A : Set} → Stream A → Stream A tailS xs with out xs ... | _ , xs' = xs' -- From (Leclerc and Paulin-Mohring 1994, p. 195). -- -- TODO (07 January 2014): Agda doesn't accept the definition of -- Stream-build. {-# TERMINATING #-} Stream-build : {A X : Set} → (X → StreamF A X) → X → Stream A Stream-build h x with h x ... | a , x' = Wrap (a , Stream-build h x') -- From (Giménez, 1995, p. 40). -- -- TODO (07 January 2014): Agda doesn't accept the definition of -- Stream-corec. {-# TERMINATING #-} Stream-corec : {A X : Set} → (X → (A × (Stream A + X))) → X → Stream A Stream-corec h x with h x ... | a , inl xs = Wrap (a , xs) ... | a , inr x' = Wrap (a , (Stream-corec h x')) ------------------------------------------------------------------------------ -- References -- -- Giménez, E. (1995). Codifying guarded definitions with recursive -- schemes. In: Types for Proofs and Programs (TYPES ’94). Ed. by -- Dybjer, P., Nordström, B. and Smith, J. Vol. 996. LNCS. Springer, -- pp. 39–59. -- -- Leclerc, F. and Paulin-Mohring, C. (1994). Programming with Streams -- in Coq. A case study : the Sieve of Eratosthenes. In: Types for -- Proofs and Programs (TYPES ’93). Ed. by Barendregt, H. and Nipkow, -- T. Vol. 806. LNCS. Springer, pp. 191–212. -- -- Vene, Varmo (2000). Categorical programming with inductive and -- coinductive types. PhD thesis. Faculty of Mathematics: University -- of Tartu.
{ "alphanum_fraction": 0.5462168097, "avg_line_length": 22.8721461187, "ext": "agda", "hexsha": "bec56ddb0627c619e9dbdb87eed27f4401aefc55", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "notes/fixed-points/Functors.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "notes/fixed-points/Functors.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "notes/fixed-points/Functors.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 1644, "size": 5009 }
-- {-# OPTIONS -v interaction:100 #-} module Issue810 where postulate T : Set → Set introHid : {A : Set} → T A introHid = {!!} data Sg {A : Set} : A → Set where sg : (a : A) → Sg a intro : ∀ {A}{a : A} → Sg a intro = {!!} intro′ : ∀ {A}(a : A) → Sg a intro′ = {!!}
{ "alphanum_fraction": 0.5, "avg_line_length": 15.2222222222, "ext": "agda", "hexsha": "a9255d814164810dac31b90ca1ab5b695621263d", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/interaction/Issue810.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/interaction/Issue810.agda", "max_line_length": 37, "max_stars_count": 1, "max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "redfish64/autonomic-agda", "max_stars_repo_path": "test/interaction/Issue810.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": 111, "size": 274 }
{-# OPTIONS --without-K --rewriting #-} open import lib.Base open import lib.PathGroupoid open import lib.path-seq.Concat open import lib.path-seq.Inversion open import lib.path-seq.Reasoning module lib.path-seq.Rotations {i} {A : Type i} where {- The order of the arguments p, q, r follows the occurrences of these variables in the output type -} pre-rotate-in : {a a' a'' : A} {q : a' =-= a''} {p : a == a'} {r : a =-= a''} → p ◃∙ q =ₛ r → q =ₛ ! p ◃∙ r pre-rotate-in {q = q} {p = idp} {r = r} e = q =ₛ⟨ =ₛ-in (! (↯-∙∙ (idp ◃∎) q)) ⟩ idp ◃∙ q =ₛ⟨ e ⟩ r =ₛ⟨ =ₛ-in (! (↯-∙∙ (idp ◃∎) r)) ⟩ idp ◃∙ r ∎ₛ pre-rotate-out : {a a' a'' : A} {p : a == a'} {q : a' =-= a''} {r : a =-= a''} → q =ₛ ! p ◃∙ r → p ◃∙ q =ₛ r pre-rotate-out {p = idp} {q = q} {r = r} e = idp ◃∙ q =ₛ⟨ =ₛ-in (↯-∙∙ (idp ◃∎) q) ⟩ q =ₛ⟨ e ⟩ idp ◃∙ r =ₛ⟨ =ₛ-in (↯-∙∙ (idp ◃∎) r) ⟩ r ∎ₛ pre-rotate'-in : {a a' a'' : A} {p : a == a'} {r : a =-= a''} {q : a' =-= a''} → r =ₛ p ◃∙ q → ! p ◃∙ r =ₛ q pre-rotate'-in e = !ₛ (pre-rotate-in (!ₛ e)) pre-rotate'-out : {a a' a'' : A} {r : a =-= a''} {p : a == a'} {q : a' =-= a''} → ! p ◃∙ r =ₛ q → r =ₛ p ◃∙ q pre-rotate'-out e = !ₛ (pre-rotate-out (!ₛ e)) pre-rotate-seq-in : {a a' a'' : A} {q : a' =-= a''} {p : a =-= a'} {r : a =-= a''} → p ∙∙ q =ₛ r → q =ₛ seq-! p ∙∙ r pre-rotate-seq-in {q = q} {p = []} {r = r} e = e pre-rotate-seq-in {q = q} {p = p ◃∙ s} {r = r} e = q =ₛ⟨ pre-rotate-seq-in {q = q} {p = s} {r = ! p ◃∙ r} (pre-rotate-in e) ⟩ seq-! s ∙∙ ! p ◃∙ r =ₛ⟨ =ₛ-in (ap ↯ (! (∙∙-assoc (seq-! s) (! p ◃∎) r))) ⟩ seq-! (p ◃∙ s) ∙∙ r ∎ₛ pre-rotate'-seq-in : {a a' a'' : A} {p : a =-= a'} {r : a =-= a''} {q : a' =-= a''} → r =ₛ p ∙∙ q → seq-! p ∙∙ r =ₛ q pre-rotate'-seq-in {p = p} {r = r} {q = q} e = !ₛ (pre-rotate-seq-in {q = q} {p} {r} (!ₛ e)) post-rotate'-in : {a a' a'' : A} → {r : a =-= a''} {q : a' == a''} {p : a =-= a'} → r =ₛ p ∙▹ q → r ∙▹ ! q =ₛ p post-rotate'-in {r = r} {q = idp} {p = p} e = r ∙▹ idp =ₛ⟨ =ₛ-in (↯-∙∙ r (idp ◃∎) ∙ ∙-unit-r (↯ r)) ⟩ r =ₛ⟨ e ⟩ p ∙▹ idp =ₛ⟨ =ₛ-in (↯-∙∙ p (idp ◃∎) ∙ ∙-unit-r (↯ p)) ⟩ p ∎ₛ post-rotate-in : {a a' a'' : A} → {p : a =-= a'} {r : a =-= a''} {q : a' == a''} → p ∙▹ q =ₛ r → p =ₛ r ∙▹ ! q post-rotate-in {p = p} {r = r} {q = q} e = !ₛ (post-rotate'-in (!ₛ e)) post-rotate-out : {a a' a'' : A} → {p : a =-= a'} {q : a' == a''} {r : a =-= a''} → p =ₛ r ∙▹ ! q → p ∙▹ q =ₛ r post-rotate-out {p = p} {q = q} {r = r} e = =ₛ-in $ ↯ (p ∙▹ q) =⟨ ap (λ v → ↯ (p ∙▹ v)) (! (!-! q)) ⟩ ↯ (p ∙▹ ! (! q)) =⟨ =ₛ-out (post-rotate'-in {r = p} {q = ! q} {p = r} e) ⟩ ↯ r =∎ post-rotate'-seq-in : {a a' a'' : A} → {r : a =-= a''} {q : a' =-= a''} {p : a =-= a'} → r =ₛ p ∙∙ q → r ∙∙ seq-! q =ₛ p post-rotate'-seq-in {r = r} {q = []} {p = p} e = r ∙∙ [] =ₛ⟨ =ₛ-in (ap ↯ (∙∙-unit-r r)) ⟩ r =ₛ⟨ e ⟩ p ∙∙ [] =ₛ⟨ =ₛ-in (ap ↯ (∙∙-unit-r p)) ⟩ p ∎ₛ post-rotate'-seq-in {r = r} {q = q ◃∙ s} {p = p} e = r ∙∙ (seq-! s ∙▹ ! q) =ₛ⟨ =ₛ-in (ap ↯ (! (∙∙-assoc r (seq-! s) (! q ◃∎)))) ⟩ (r ∙∙ seq-! s) ∙▹ ! q =ₛ⟨ post-rotate'-in {r = r ∙∙ seq-! s} {q = q} {p = p} $ post-rotate'-seq-in {r = r} {s} {p ∙▹ q} $ r =ₛ⟨ e ⟩ p ∙∙ (q ◃∙ s) =ₛ⟨ =ₛ-in (ap ↯ (! (∙∙-assoc p (q ◃∎) s))) ⟩ (p ∙▹ q) ∙∙ s ∎ₛ ⟩ p ∎ₛ post-rotate-seq-in : {a a' a'' : A} → {p : a =-= a'} {r : a =-= a''} {q : a' =-= a''} → p ∙∙ q =ₛ r → p =ₛ r ∙∙ (seq-! q) post-rotate-seq-in {p = p} {r = r} {q = q} e = !ₛ (post-rotate'-seq-in {r = r} {q = q} {p = p} (!ₛ e)) post-rotate'-seq-out : {a a' a'' : A} → {r : a =-= a''} {p : a =-= a'} {q : a' =-= a''} → r ∙∙ seq-! q =ₛ p → r =ₛ p ∙∙ q post-rotate'-seq-out {r = r} {p = p} {q = q} e = r =ₛ⟨ post-rotate-seq-in {p = r} {r = p} {q = seq-! q} e ⟩ p ∙∙ seq-! (seq-! q) =ₛ⟨ =ₛ-in (ap (λ v → ↯ (p ∙∙ v)) (seq-!-seq-! q)) ⟩ p ∙∙ q ∎ₛ post-rotate-seq-out : {a a' a'' : A} → {p : a =-= a'} {q : a' =-= a''} {r : a =-= a''} → p =ₛ r ∙∙ seq-! q → p ∙∙ q =ₛ r post-rotate-seq-out e = !ₛ (post-rotate'-seq-out (!ₛ e))
{ "alphanum_fraction": 0.3666666667, "avg_line_length": 27.417218543, "ext": "agda", "hexsha": "9a380ca6520505867f4712e0eefd0a3f76402512", "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/Rotations.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/Rotations.agda", "max_line_length": 83, "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/Rotations.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": 2395, "size": 4140 }
------------------------------------------------------------------------ -- Is-equivalence, defined in terms of contractible fibres ------------------------------------------------------------------------ -- Partly based on Voevodsky's work on univalent foundations. {-# OPTIONS --without-K --safe #-} open import Equality module Equivalence.Contractible-preimages {e⁺} (eq : ∀ {a p} → Equality-with-J a p e⁺) where open Derived-definitions-and-properties eq open import Prelude as P hiding (id) open import Bijection eq using (_↔_) open import Equality.Decision-procedures eq open import H-level eq as H-level open import H-level.Closure eq open import Preimage eq as Preimage using (_⁻¹_) open import Surjection eq using (_↠_) private variable a b ℓ p q : Level A B : Type a f g : A → B ------------------------------------------------------------------------ -- Is-equivalence -- A function f is an equivalence if all preimages under f are -- contractible. Is-equivalence : {A : Type a} {B : Type b} → (A → B) → Type (a ⊔ b) Is-equivalence f = ∀ y → Contractible (f ⁻¹ y) abstract -- Is-equivalence f is a proposition, assuming extensional equality. propositional : Extensionality (a ⊔ b) (a ⊔ b) → {A : Type a} {B : Type b} (f : A → B) → Is-proposition (Is-equivalence f) propositional {a = a} ext f = Π-closure (lower-extensionality a lzero ext) 1 λ _ → Contractible-propositional ext -- If the domain is contractible and the codomain is propositional, -- then Is-equivalence f is contractible. sometimes-contractible : Extensionality (a ⊔ b) (a ⊔ b) → {A : Type a} {B : Type b} {f : A → B} → Contractible A → Is-proposition B → Contractible (Is-equivalence f) sometimes-contractible {a = a} ext A-contr B-prop = Π-closure (lower-extensionality a lzero ext) 0 λ _ → cojoin ext (Σ-closure 0 A-contr (λ _ → +⇒≡ B-prop)) -- Is-equivalence f is not always contractible. not-always-contractible₁ : ∃ λ (A : Type a) → ∃ λ (B : Type b) → ∃ λ (f : A → B) → Is-proposition A × Contractible B × ¬ Contractible (Is-equivalence f) not-always-contractible₁ = ⊥ , ↑ _ ⊤ , const (lift tt) , ⊥-propositional , ↑-closure 0 ⊤-contractible , λ c → ⊥-elim (proj₁ (proj₁ (proj₁ c (lift tt)))) not-always-contractible₂ : ∃ λ (A : Type a) → ∃ λ (B : Type b) → ∃ λ (f : A → B) → Contractible A × Is-set B × ¬ Contractible (Is-equivalence f) not-always-contractible₂ = ↑ _ ⊤ , ↑ _ Bool , const (lift true) , ↑-closure 0 ⊤-contractible , ↑-closure 2 Bool-set , λ c → Bool.true≢false (cong lower (proj₂ (proj₁ (proj₁ c (lift false))))) -- Is-equivalence respects extensional equality. respects-extensional-equality : (∀ x → f x ≡ g x) → Is-equivalence f → Is-equivalence g respects-extensional-equality f≡g f-eq = λ b → H-level.respects-surjection (_↔_.surjection (Preimage.respects-extensional-equality f≡g)) 0 (f-eq b) -- If f is an equivalence, then it has an inverse. inverse : {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} → Is-equivalence f → B → A inverse eq y = proj₁ (proj₁ (eq y)) right-inverse-of : {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} → (eq : Is-equivalence f) → ∀ x → f (inverse eq x) ≡ x right-inverse-of eq x = proj₂ (proj₁ (eq x)) abstract left-inverse-of : (eq : Is-equivalence f) → ∀ x → inverse eq (f x) ≡ x left-inverse-of {f = f} eq x = cong (proj₁ {B = λ x′ → f x′ ≡ f x}) ( proj₁ (eq (f x)) ≡⟨ proj₂ (eq (f x)) (x , refl (f x)) ⟩∎ (x , refl (f x)) ∎) -- All fibres of an equivalence over a given point are equal to a -- given fibre. irrelevance : {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} → (eq : Is-equivalence f) → ∀ y (p : f ⁻¹ y) → (inverse eq y , right-inverse-of eq y) ≡ p irrelevance eq y = proj₂ (eq y) abstract -- The two proofs left-inverse-of and right-inverse-of are -- related. left-right-lemma : (eq : Is-equivalence f) → ∀ x → cong f (left-inverse-of eq x) ≡ right-inverse-of eq (f x) left-right-lemma {f = f} eq x = lemma₁ f _ _ (lemma₂ (irrelevance eq (f x) (x , refl (f x)))) where lemma₁ : {x y : A} (f : A → B) (p : x ≡ y) (q : f x ≡ f y) → refl (f y) ≡ trans (cong f (sym p)) q → cong f p ≡ q lemma₁ f = elim (λ {x y} p → ∀ q → refl (f y) ≡ trans (cong f (sym p)) q → cong f p ≡ q) (λ x q hyp → cong f (refl x) ≡⟨ cong-refl f ⟩ refl (f x) ≡⟨ hyp ⟩ trans (cong f (sym (refl x))) q ≡⟨ cong (λ p → trans (cong f p) q) sym-refl ⟩ trans (cong f (refl x)) q ≡⟨ cong (λ p → trans p q) (cong-refl f) ⟩ trans (refl (f x)) q ≡⟨ trans-reflˡ _ ⟩∎ q ∎) lemma₂ : ∀ {f : A → B} {y} {f⁻¹y₁ f⁻¹y₂ : f ⁻¹ y} (p : f⁻¹y₁ ≡ f⁻¹y₂) → proj₂ f⁻¹y₂ ≡ trans (cong f (sym (cong (proj₁ {B = λ x → f x ≡ y}) p))) (proj₂ f⁻¹y₁) lemma₂ {f = f} {y = y} = let pr = proj₁ {B = λ x → f x ≡ y} in elim {A = f ⁻¹ y} (λ {f⁻¹y₁ f⁻¹y₂} p → proj₂ f⁻¹y₂ ≡ trans (cong f (sym (cong pr p))) (proj₂ f⁻¹y₁)) (λ f⁻¹y → proj₂ f⁻¹y ≡⟨ sym $ trans-reflˡ _ ⟩ trans (refl (f (proj₁ f⁻¹y))) (proj₂ f⁻¹y) ≡⟨ cong (λ p → trans p (proj₂ f⁻¹y)) (sym (cong-refl f)) ⟩ trans (cong f (refl (proj₁ f⁻¹y))) (proj₂ f⁻¹y) ≡⟨ cong (λ p → trans (cong f p) (proj₂ f⁻¹y)) (sym sym-refl) ⟩ trans (cong f (sym (refl (proj₁ f⁻¹y)))) (proj₂ f⁻¹y) ≡⟨ cong (λ p → trans (cong f (sym p)) (proj₂ f⁻¹y)) (sym (cong-refl pr)) ⟩∎ trans (cong f (sym (cong pr (refl f⁻¹y)))) (proj₂ f⁻¹y) ∎) right-left-lemma : (eq : Is-equivalence f) → ∀ x → cong (inverse eq) (right-inverse-of eq x) ≡ left-inverse-of eq (inverse eq x) right-left-lemma {f = f} eq x = let f⁻¹ = inverse eq in subst (λ x → cong f⁻¹ (right-inverse-of eq x) ≡ left-inverse-of eq (f⁻¹ x)) (right-inverse-of eq x) (cong f⁻¹ (right-inverse-of eq (f (f⁻¹ x))) ≡⟨ cong (cong f⁻¹) $ sym $ left-right-lemma eq _ ⟩ cong f⁻¹ (cong f (left-inverse-of eq (f⁻¹ x))) ≡⟨ cong-∘ f⁻¹ f _ ⟩ cong (f⁻¹ ∘ f) (left-inverse-of eq (f⁻¹ x)) ≡⟨ cong-roughly-id (f⁻¹ ∘ f) (λ _ → true) (left-inverse-of eq _) _ _ (λ z _ → left-inverse-of eq z) ⟩ trans (left-inverse-of eq (f⁻¹ (f (f⁻¹ x)))) (trans (left-inverse-of eq (f⁻¹ x)) (sym (left-inverse-of eq (f⁻¹ x)))) ≡⟨ cong (trans _) $ trans-symʳ _ ⟩ trans (left-inverse-of eq (f⁻¹ (f (f⁻¹ x)))) (refl _) ≡⟨ trans-reflʳ _ ⟩∎ left-inverse-of eq (f⁻¹ (f (f⁻¹ x))) ∎) abstract -- If Σ-map P.id f is an equivalence, then f is also an equivalence. drop-Σ-map-id : {A : Type a} {P : A → Type p} {Q : A → Type q} (f : ∀ {x} → P x → Q x) → Is-equivalence {A = Σ A P} {B = Σ A Q} (Σ-map P.id f) → ∀ x → Is-equivalence (f {x = x}) drop-Σ-map-id {p = ℓp} {q = ℓq} {A = A} {P = P} {Q = Q} f eq x z = H-level.respects-surjection surj 0 (eq (x , z)) where map-f : Σ A P → Σ A Q map-f = Σ-map P.id f to-P : ∀ {x y} {p : ∃ Q} → (x , f y) ≡ p → Type (ℓp ⊔ ℓq) to-P {y = y} {p} _ = ∃ λ y′ → f y′ ≡ proj₂ p to : map-f ⁻¹ (x , z) → f ⁻¹ z to ((x′ , y) , eq) = elim¹ to-P (y , refl (f y)) eq from : f ⁻¹ z → map-f ⁻¹ (x , z) from (y , eq) = (x , y) , cong (_,_ x) eq to∘from : ∀ p → to (from p) ≡ p to∘from (y , eq) = elim¹ (λ {z′} (eq : f y ≡ z′) → _≡_ {A = ∃ λ (y : P x) → f y ≡ z′} (elim¹ to-P (y , refl (f y)) (cong (_,_ x) eq)) (y , eq)) (elim¹ to-P (y , refl (f y)) (cong (_,_ x) (refl (f y))) ≡⟨ cong (elim¹ to-P (y , refl (f y))) $ cong-refl (_,_ x) ⟩ elim¹ to-P (y , refl (f y)) (refl (x , f y)) ≡⟨ elim¹-refl to-P _ ⟩∎ (y , refl (f y)) ∎) eq surj : map-f ⁻¹ (x , z) ↠ f ⁻¹ z surj = record { logical-equivalence = record { to = to; from = from } ; right-inverse-of = to∘from } -- A "computation" rule for drop-Σ-map-id. inverse-drop-Σ-map-id : {A : Type a} {P : A → Type p} {Q : A → Type q} {f : ∀ {x} → P x → Q x} {x : A} {y : Q x} {eq : Is-equivalence {A = Σ A P} {B = Σ A Q} (Σ-map P.id f)} → inverse (drop-Σ-map-id f eq x) y ≡ subst P (cong proj₁ (right-inverse-of eq (x , y))) (proj₂ (inverse eq (x , y))) inverse-drop-Σ-map-id {P = P} {Q = Q} {f = f} {x = x} {y = y} {eq = eq} = let lemma = elim¹ (λ {q′} eq → cong proj₁ (proj₂ (other-singleton-contractible (Σ-map P.id f p′)) (q′ , eq)) ≡ eq) (cong proj₁ (proj₂ (other-singleton-contractible (Σ-map P.id f p′)) (Σ-map P.id f p′ , refl _)) ≡⟨ cong (cong proj₁) $ other-singleton-contractible-refl _ ⟩ cong proj₁ (refl _) ≡⟨ cong-refl _ ⟩∎ refl _ ∎) _ in proj₁ (subst (λ ((_ , y) , _) → f ⁻¹ y) (proj₂ (other-singleton-contractible (Σ-map P.id f p′)) (q′ , right-inverse-of eq q′)) (proj₂ p′ , refl _)) ≡⟨ cong proj₁ $ push-subst-pair _ _ ⟩ subst (λ ((x , _) , _) → P x) (proj₂ (other-singleton-contractible (Σ-map P.id f p′)) (q′ , right-inverse-of eq q′)) (proj₂ p′) ≡⟨ trans (subst-∘ _ _ _) (subst-∘ _ _ _) ⟩ subst P (cong proj₁ $ cong proj₁ $ proj₂ (other-singleton-contractible (Σ-map P.id f p′)) (q′ , right-inverse-of eq q′)) (proj₂ p′) ≡⟨ cong (λ eq → subst P (cong proj₁ eq) (proj₂ p′)) lemma ⟩∎ subst P (cong proj₁ (right-inverse-of eq q′)) (proj₂ p′) ∎ where q′ : ∃ Q q′ = x , y p′ : ∃ P p′ = inverse eq q′ ------------------------------------------------------------------------ -- _≃_ -- A notion of equivalence. infix 4 _≃_ _≃_ : Type a → Type b → Type (a ⊔ b) A ≃ B = ∃ λ (f : A → B) → Is-equivalence f -- An identity equivalence. id : A ≃ A id = P.id , singleton-contractible -- Equalities can be converted to equivalences. ≡⇒≃ : A ≡ B → A ≃ B ≡⇒≃ = elim (λ {A B} _ → A ≃ B) (λ _ → id) -- If ≡⇒≃ is applied to reflexivity, then the result is equal to id. ≡⇒≃-refl : ≡⇒≃ (refl A) ≡ id ≡⇒≃-refl = elim-refl (λ {A B} _ → A ≃ B) (λ _ → id) -- Univalence for fixed types. Univalence′ : (A B : Type ℓ) → Type (lsuc ℓ) Univalence′ A B = Is-equivalence (≡⇒≃ {A = A} {B = B}) -- Univalence. Univalence : ∀ ℓ → Type (lsuc ℓ) Univalence ℓ = {A B : Type ℓ} → Univalence′ A B
{ "alphanum_fraction": 0.4666724302, "avg_line_length": 34.1209439528, "ext": "agda", "hexsha": "9c5b9bd23709eb8706683ad4fa20972b1f13b004", "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/Equivalence/Contractible-preimages.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/Equivalence/Contractible-preimages.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/Equivalence/Contractible-preimages.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": 4117, "size": 11567 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Decidable setoid membership over lists ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary using (Decidable; DecSetoid) module Data.List.Membership.DecSetoid {a ℓ} (DS : DecSetoid a ℓ) where open import Data.List.Relation.Unary.Any using (any) open DecSetoid DS ------------------------------------------------------------------------ -- Re-export contents of propositional membership open import Data.List.Membership.Setoid (DecSetoid.setoid DS) public ------------------------------------------------------------------------ -- Other operations infix 4 _∈?_ _∈?_ : Decidable _∈_ x ∈? xs = any (x ≟_) xs
{ "alphanum_fraction": 0.4665012407, "avg_line_length": 28.7857142857, "ext": "agda", "hexsha": "9aedee23edd5540a0642bdbaed10f82056d797d8", "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": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Membership/DecSetoid.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "omega12345/agda-mode", "max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Membership/DecSetoid.agda", "max_line_length": 72, "max_stars_count": 5, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Membership/DecSetoid.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": 155, "size": 806 }
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- If we could prove ifInjective then we could true ≡ false (see Dan -- Licata example in -- http://thread.gmane.org/gmane.comp.lang.agda/4511). module FOTC.Base.Consistency.IfInjective where open import FOTC.Base ------------------------------------------------------------------------------ postulate ifInjective : ∀ {b b' t t'} → (if b then t else t') ≡ (if b' then t else t') → b ≡ b' {-# ATP prove ifInjective #-} true≡false : true ≡ false true≡false = ifInjective {true} {false} {true} {true} (trans (if-true true) (sym (if-false true)))
{ "alphanum_fraction": 0.5175097276, "avg_line_length": 33.5217391304, "ext": "agda", "hexsha": "46f2ec4e496fadc59ea0a83e6cfebdc982279457", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "src/fot/FOTC/Base/Consistency/IfInjective.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "src/fot/FOTC/Base/Consistency/IfInjective.agda", "max_line_length": 79, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "src/fot/FOTC/Base/Consistency/IfInjective.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z", "num_tokens": 193, "size": 771 }
open import Data.Tuple as Tuple using (_⨯_ ; _,_) open import Logic.Classical open import Logic import Lvl open import Type open import Structure.Setoid -- Elementary Plane Geometry. -- An axiomatic approach to plane geometry in first order logic. -- The axiomatic system used here is usually called "Tarski's axioms", and plane geometry is also known as two-dimensional Euclidean geometry. module Geometry.Axioms {ℓₚ ℓₚₑ ℓₗₗₑ ℓₗᵢₗ} (Point : Type{ℓₚ}) ⦃ Point-equiv : Equiv{ℓₚₑ}(Point) ⦄ (Equidistanced : (Point ⨯ Point) → (Point ⨯ Point) → Stmt{ℓₗₗₑ}) -- Two pairs of points have the same distance between each other. (Aligned : Point → Point → Point → Stmt{ℓₗᵢₗ}) -- Three points are aligned in a weak order. The second point is between the first and the third in a line. ⦃ classical : ∀{ℓ}{P : Stmt{ℓ}} → Classical(P) ⦄ where open import Data.Tuple.Equivalence open import Functional open import Functional.Combinations open import Logic.Predicate open import Logic.Propositional open import Logic.Propositional.Theorems open import Sets.ExtensionalPredicateSet renaming (_≡_ to _≡ₛ_) open import Structure.Relator.Equivalence open import Structure.Relator.Ordering open import Structure.Relator.Properties open import Structure.Relator open import Structure.Setoid.Uniqueness open import Syntax.Function open import Syntax.Implication open import Syntax.Transitivity open import Syntax.Type private variable ℓ ℓ₁ ℓ₂ ℓₗ ℓₗ₁ ℓₗ₂ : Lvl.Level private variable p a b c d e p₁ p₂ pᵢ pₒ pᵣ a₁ a₂ b₁ b₂ c₁ c₂ d₁ d₂ e₁ e₂ i m₁ m₂ : Point private variable P Q : Point → Stmt{ℓ} -- Three points are aligned in a strict order. The second point is between the first and the third in a line without being the first or the second. Between : Point → Point → Point → Stmt Between a b c = (Aligned a b c) ∧ ((a ≢ b) ∧ (b ≢ c)) -- Three points are collinear when they all are points of a single line. Collinear : Point → Point → Point → Stmt Collinear a b c = (Aligned a b c) ∨ (Aligned b c a) ∨ (Aligned c a b) Aligned₄ : Point → Point → Point → Point → Stmt Aligned₄ = combine₄Fn₃Op₂ Aligned (_∧_) -- The equivalence on points. _≡ₚ_ = Equiv._≡_ Point-equiv -- Source: Tarski's axioms of geometry (https://en.wikipedia.org/wiki/Tarski%27s_axioms @ 2020-06-14). -- TODO: Are there any modifications of the axioms when working in constructive logic? record Axioms : Typeω where field ⦃ Equidistanced-relator ⦄ : BinaryRelator(Equidistanced) ⦃ Aligned-relator ⦄ : TrinaryRelator(Aligned) -- ⦃ Point-equivalence-classical ⦄ : Classical₂(_≡ₚ_) -- ⦃ Equidistanced-classical ⦄ : Classical₂(Equidistanced) -- ⦃ Aligned-classical ⦄ : Classical₃(Aligned) -- The distance between p₁ and p₂ is the same as the distance between p₂ and p₁. -- The order of the points in the equidistance relation does not matter. -- Example: -- • (p₁) <--- (p₂) -- • (p₁) ---> (p₂) -- These two drawings depict lines between points p₁ and p₂. They have the same length. -- So there is no need to draw an arrow head on the lines when referring to the length of a line. -- Also called: A1 in Metamathematische Methoden in der Geometrie. Equidistanced-flipped : Equidistanced(p₁ , p₂)(p₂ , p₁) -- Equidistance is a transitive relation. -- Example: -- la: (a₁) ---- (a₂) -- lb: (b₁) ---- (b₂) -- lc: (c₁) ---- (c₂) -- Here is a drawing of three lines. -- The line la have the same length as lb, and the line la have the same length as lc. Then lb have the same length as lc. -- Also called: A2 in Metamathematische Methoden in der Geometrie. Equidistanced-symmetric-transitivity : Equidistanced(a₁ , a₂)(b₁ , b₂) → Equidistanced(a₁ , a₂)(c₁ , c₂) → Equidistanced(b₁ , b₂)(c₁ , c₂) -- If two points have the same distance as the distance between a single point with itself, then they are the same point. -- Essentially, if two points have no distance between each other, they are the same point. -- Example: -- (p₁) ---------- (p₂) -- (p) -- Here p₁ and p₂ are arbitrary points, and a line between them is depicted. -- The line from p to p is also depicted (as a point). -- Currently, these lines do not have the same length, and for p₁ and p₂ to have the same distance as the single point line consisting of p, the line must collapse to a single point, making p₁ and p₂ the same point. -- Also called: -- • Identity axiom for the `Equidistance` relation. -- • A3 in Metamathematische Methoden in der Geometrie. Equidistanced-point : Equidistanced(p₁ , p₂)(p , p) → (p₁ ≡ p₂) -- Given two lines, there exists a line extending the first line so that the extension part is of the same length as the second line. -- Essentially, given a starting point and a direction, it is always possible to construct a line of the same length as an another already existing line. -- Or: It is always possible to extend a line by the length of another line. -- Example: -- Given two lines: -- (p) <-- (a₁) -- (a₂) ------> (b₂) -- it is possible to construct an extension of the first line like this: -- (b₁) <------(p)-- (a₁) -- The extension from a₁ to b₁ have the same direction as the first line (a₁ to p) and the same length as the second line (from a₂ to b₂). -- Also called: -- • A4 in Metamathematische Methoden in der Geometrie. segment-construction : ∃(b₁ ↦ (Aligned a₁ p b₁) ∧ Equidistanced(p , b₁)(a₂ , b₂)) -- Given two bisected triangles, if all except one of the non-bisected sides of the first triangle have the same length as the second one's, then the unknown side of the first triangle is also congruent to the unknown side of the second. -- -- Note: If any of the points other than (a,b) or (a,d) are equal, then the result follows from the assumptions. -- (d)\__ -- / \_ \__ -- / \_ \__ -- / \ \ -- (a)__________(b)___(c) -- -- Also called: -- • A5 in Metamathematische Methoden in der Geometrie. five-segment : (a₁ ≢ b₁) → (Aligned a₁ b₁ c₁) → (Aligned a₂ b₂ c₂) → Equidistanced(a₁ , b₁)(a₂ , b₂) → Equidistanced(b₁ , c₁)(b₂ , c₂) → Equidistanced(a₁ , d₁)(a₂ , d₂) → Equidistanced(b₁ , d₁)(b₂ , d₂) → Equidistanced(c₁ , d₁)(c₂ , d₂) -- If a point is between two identical points, then they are the same point. -- Alternatively, if a point is in a line consisting of only a single point, then the point is the single point. -- Example: -- (p₁) ------(a)--- (p₂) -- Here, a line from p₁ to p₂ is depicted, and a point a is in this line. -- But if p₁ and p₂ would be the same point p, then the line would collapse to a single point, making a and p the same. -- Also called: -- • Identity axiom for the `Aligned` relation. -- • A6 in Metamathematische Methoden in der Geometrie. Aligned-point : (Aligned p a p) → (a ≡ p) -- Given two connected lines and one point in each of the lines, two lines connecting the points and the endpoints of the other line have an intersection point. -- Example: -- (c) -- / \ -- (m₁)\ /(m₂) -- / _(i)_ \ -- (a)__/ \__(b) -- Also called: -- • Axiom of Pasch. -- • Inner Pasch. -- • A7 in Metamathematische Methoden in der Geometrie. Aligned-intersection : (Aligned a m₁ c) → (Aligned b m₂ c) → ∃(i ↦ (Aligned m₁ i b) ∧ (Aligned m₂ i a)) -- Also called: -- • Axiom schema of Continuity -- • A11' in Metamathematische Methoden in der Geometrie. Aligned-continuity : ∃(a ↦ ∀{x y} → P(x) → Q(y) → (Aligned a x y)) → ∃(a ↦ ∀{x y} → P(x) → Q(y) → (Aligned x a y)) -- A triangle exists. -- This excludes the possibility of this theory describing 0 or 1-dimensional spaces when using the standard interpretation of the axioms. -- Example: -- (c) -- / \ -- (a)___(b) -- Also called: -- • A8 in Metamathematische Methoden in der Geometrie. lower-dimension₂ : ∃{Obj = Point ⨯ Point ⨯ Point}(\(a , b , c) → (¬ Aligned a b c) ∧ (¬ Aligned b c a) ∧ (¬ Aligned c a b)) -- Also called: -- • A9 in Metamathematische Methoden in der Geometrie. upper-dimension₂ : Equidistanced(a , p₁)(a , p₂) → Equidistanced(b , p₁)(b , p₂) → Equidistanced(c , p₁)(c , p₂) → (p₁ ≢ p₂) → (Aligned a b c) ∨ (Aligned b c a) ∨ (Aligned c a b) -- Given three points, they are either collinear (forming a line), or there is a circumcentered point for the triangle of the three points (a point where the distance between this point and all three vertices are equal). -- Example: -- Here is an example of the different cases depicted: -- • (a) ----(b)------ (c) -- • (b) ----(c)------ (a) -- • (c) ----(a)------ (b) -- • (a)\__ -- / ‖ \__ -- / ‖ \ -- (b)______‖______(c) -- \___ ‖ ___/ -- \_(m)_/ -- or when the triangle is equilateral: -- (a) -- / \ -- / \ -- / (m) \ -- /_______\ -- (b) (c) -- Also called: -- • Axiom of Euclid. -- • Variant of A10 in Metamathematische Methoden in der Geometrie. center-of-3 : (Collinear a b c) ∨ ∃(m ↦ Equidistanced(a , m)(b , m) ∧ Equidistanced(a , m)(c , m)) module _ ⦃ axioms : Axioms ⦄ where open Axioms(axioms) -- A line constructed by the points `a` and `b` have an intersection point on a circle with the center point `c` and radius point `pᵣ` when a part of the line. -- Also called: -- • CA in Metamathematische Methoden in der Geometrie. -- circle-line-intersection : (Aligned₄ c pᵢ pᵣ pₒ) → Equidistanced(c , a)(c , pᵢ) → Equidistanced(c , b)(c , pₒ) → ∃(i ↦ Equidistanced(c , i)(c , pᵣ) ∧ (Aligned a i b)) instance -- Identical pairs of points have the same distance between each other. -- Also called: 2.1 in Metamathematische Methoden in der Geometrie. Equidistanced-reflexivity : Reflexivity(Equidistanced) Reflexivity.proof Equidistanced-reflexivity {p₁ , p₂} = Equidistanced-symmetric-transitivity (Equidistanced-flipped {p₂}{p₁}) (Equidistanced-flipped {p₂}{p₁}) instance -- Also called: 2.2 in Metamathematische Methoden in der Geometrie. Equidistanced-symmetry : Symmetry(Equidistanced) Symmetry.proof Equidistanced-symmetry p = Equidistanced-symmetric-transitivity p (reflexivity(Equidistanced)) instance -- Also called: 2.3 in Metamathematische Methoden in der Geometrie. Equidistanced-transitivity : Transitivity(Equidistanced) Transitivity.proof Equidistanced-transitivity p q = Equidistanced-symmetric-transitivity (symmetry(Equidistanced) p) q instance -- Also called: 2.7 in Metamathematische Methoden in der Geometrie. Equidistanced-equivalence : Equivalence(Equidistanced) Equidistanced-equivalence = intro -- The distance between a point and itself is the same for all points. -- Also called: 2.8 in Metamathematische Methoden in der Geometrie. Equidistanced-points : Equidistanced(a , a) (b , b) Equidistanced-points {a}{b} with [∃]-intro p ⦃ [∧]-intro _ bpaa ⦄ ← segment-construction{a}{b} {a}{a} = • (b ≡ b) ∧ (p ≡ b) :-[ [∧]-intro (reflexivity(_≡_)) (symmetry(_≡_) (Equidistanced-point bpaa)) ] • Equidistanced(b , p) (b , p) :-[ reflexivity(Equidistanced) ] ⇒₂-[ substitute₂ᵣ(Equidistanced) ] Equidistanced(b , p) (b , b) ⇒-[ Equidistanced-symmetric-transitivity bpaa ] Equidistanced(a , a) (b , b) ⇒-end -- Addition of two distances when the points are in a line. -- Also called: 2.11 in Metamathematische Methoden in der Geometrie. segment-sum : (Aligned a₁ b₁ c₁) → (Aligned a₂ b₂ c₂) → Equidistanced(a₁ , b₁)(a₂ , b₂) → Equidistanced(b₁ , c₁)(b₂ , c₂) → Equidistanced(a₁ , c₁)(a₂ , c₂) segment-sum {a₁ = a₁}{b₁ = b₁} abc₁ abc₂ ab₁ab₂ bc₁bc₂ with excluded-middle(a₁ ≡ b₁) ... | [∨]-introₗ a₁b₁ with a₂b₂ ← Equidistanced-point (symmetry(Equidistanced) (substitute₂ₗ(Equidistanced) ([∧]-intro a₁b₁ (reflexivity(_≡ₚ_))) ab₁ab₂)) = substitute₂(Equidistanced) ([∧]-intro (symmetry(_≡ₚ_) a₁b₁) (reflexivity(_≡ₚ_))) ([∧]-intro (symmetry(_≡ₚ_) a₂b₂) (reflexivity(_≡ₚ_))) bc₁bc₂ ... | [∨]-introᵣ na₁b₁ = Equidistanced-flipped 🝖 (five-segment na₁b₁ abc₁ abc₂ ab₁ab₂ bc₁bc₂ Equidistanced-points (Equidistanced-flipped 🝖 ab₁ab₂ 🝖 Equidistanced-flipped) ) 🝖 Equidistanced-flipped -- The segment extension axiom constructs unique points when the given pair of points forms a line segment to extend. -- Also called: 2.12 in Metamathematische Methoden in der Geometrie. segment-construction-uniqueness : (a₁ ≢ p) → Unique(b₁ ↦ (Aligned a₁ p b₁) ∧ Equidistanced(p , b₁)(a₂ , b₂)) segment-construction-uniqueness na₁p ([∧]-intro al-a₁p₁x eq-p₁xa₂b₂) ([∧]-intro al-a₁p₁y eq-p₁ya₂b₂) with pxpy ← transitivity(Equidistanced) eq-p₁xa₂b₂ (symmetry(Equidistanced) eq-p₁ya₂b₂) with a₁xa₁y ← segment-sum al-a₁p₁x al-a₁p₁y (reflexivity(Equidistanced)) pxpy = Equidistanced-point (five-segment na₁p al-a₁p₁x al-a₁p₁y (reflexivity(Equidistanced)) pxpy (reflexivity(Equidistanced)) (reflexivity(Equidistanced))) -- Two points are always aligned. -- Also called: 3.1 in Metamathematische Methoden in der Geometrie. Aligned-reflexivityᵣ : Aligned a b b Aligned-reflexivityᵣ {a}{b} with [∃]-intro p ⦃ [∧]-intro alig equi ⦄ ← segment-construction{a}{b} {a}{a} = substitute₃-unary₃(Aligned) (symmetry(_≡_) (Equidistanced-point equi)) alig -- A single point is always aligned with itself. Aligned-reflexivity : Aligned a a a Aligned-reflexivity = Aligned-reflexivityᵣ -- When three points are aligned in one direction, they are also aligned in the opposite direction. -- Also called: 3.2 in Metamathematische Methoden in der Geometrie. Aligned-symmetry : Aligned a b c → Aligned c b a Aligned-symmetry {a}{b}{c} alig with [∃]-intro p ⦃ [∧]-intro bpb cpa ⦄ ← Aligned-intersection{a}{b}{_}{b}{c} alig Aligned-reflexivityᵣ with pb ← Aligned-point bpb = substitute₃-unary₂(Aligned) pb cpa -- Two points are always aligned. -- Also called: 3.3 in Metamathematische Methoden in der Geometrie. Aligned-reflexivityₗ : Aligned a a b Aligned-reflexivityₗ = Aligned-symmetry Aligned-reflexivityᵣ -- Also called: 3.4 in Metamathematische Methoden in der Geometrie. Aligned-antisymmetryₗ : (Aligned a b c) → (Aligned b a c) → (a ≡ b) Aligned-antisymmetryₗ {a}{b}{c} al-abc al-bac with [∃]-intro i ⦃ [∧]-intro al-bib al-aia ⦄ ← Aligned-intersection{a}{b}{c} al-abc al-bac with ia ← Aligned-point al-aia with ib ← Aligned-point al-bib = symmetry(_≡_) ia 🝖 ib Aligned-antisymmetryᵣ : (Aligned a b c) → (Aligned a c b) → (b ≡ c) Aligned-antisymmetryᵣ al-abc al-acb = symmetry(_≡_) (Aligned-antisymmetryₗ (Aligned-symmetry al-abc) (Aligned-symmetry al-acb)) -- Also called: 3.6(1) in Metamathematische Methoden in der Geometrie. Aligned-transitivityᵣ-exchange : (Aligned a b c) → (Aligned a c d) → (Aligned b c d) Aligned-transitivityᵣ-exchange abc acd with [∃]-intro i ⦃ [∧]-intro bid cic ⦄ ← Aligned-intersection (Aligned-symmetry abc) (Aligned-symmetry acd) with ic ← Aligned-point cic = substitute₃-unary₂(Aligned) ic bid -- Also called: 3.5(1) in Metamathematische Methoden in der Geometrie. Aligned-transitivityₗ-exchange : (Aligned a b d) → (Aligned b c d) → (Aligned a b c) Aligned-transitivityₗ-exchange abd bcd = Aligned-symmetry (Aligned-transitivityᵣ-exchange (Aligned-symmetry bcd) (Aligned-symmetry abd)) -- Also called: 3.7(1) in Metamathematische Methoden in der Geometrie. Aligned-semitransitivityᵣ : (Aligned a b c) → (Aligned b c d) → (b ≢ c) → (Aligned a c d) Aligned-semitransitivityᵣ {a}{b}{c}{d} abc bcd nbc with [∃]-intro x ⦃ [∧]-intro acx cxcd ⦄ ← segment-construction{a}{c}{c}{d} with bcx ← Aligned-transitivityᵣ-exchange abc acx with xd ← segment-construction-uniqueness nbc ([∧]-intro bcx cxcd) ([∧]-intro bcd (reflexivity(Equidistanced))) = substitute₃-unary₃(Aligned) xd acx -- Also called: 3.5(2) in Metamathematische Methoden in der Geometrie. Aligned-transitivityₗ-merge : (Aligned a b d) → (Aligned b c d) → (Aligned a c d) Aligned-transitivityₗ-merge {a}{b}{d}{c} abd bcd with excluded-middle(b ≡ₚ c) ... | [∨]-introₗ bc = substitute₃-unary₂(Aligned) bc abd ... | [∨]-introᵣ nbc = Aligned-semitransitivityᵣ (Aligned-transitivityₗ-exchange abd bcd) bcd nbc -- Also called: 3.6(2) in Metamathematische Methoden in der Geometrie. Aligned-transitivityᵣ-merge : (Aligned a b c) → (Aligned a c d) → (Aligned a b d) Aligned-transitivityᵣ-merge abc acd = Aligned-symmetry (Aligned-transitivityₗ-merge (Aligned-symmetry acd) (Aligned-symmetry abc)) -- Also called: 3.7(2) in Metamathematische Methoden in der Geometrie. Aligned-semitransitivityₗ : (Aligned a b c) → (Aligned b c d) → (b ≢ c) → (Aligned a b d) Aligned-semitransitivityₗ abc bcd nbc = Aligned-symmetry(Aligned-semitransitivityᵣ (Aligned-symmetry bcd) (Aligned-symmetry abc) (nbc ∘ symmetry(_≡ₚ_))) Aligned₄-intro-[123,134] : (Aligned a b c) → (Aligned a c d) → (Aligned₄ a b c d) Aligned₄-intro-[123,134] abc acd = abc , abd , acd , bcd where abd = Aligned-transitivityᵣ-merge abc acd bcd = Aligned-transitivityᵣ-exchange abc acd Aligned₄-intro-[124,234] : (Aligned a b d) → (Aligned b c d) → (Aligned₄ a b c d) Aligned₄-intro-[124,234] abd bcd = abc , abd , acd , bcd where abc = Aligned-transitivityₗ-exchange abd bcd acd = Aligned-transitivityₗ-merge abd bcd -- Existence of two distinct points. -- Also called: 3.13 in Metamathematische Methoden in der Geometrie. lower-dimension₁ : ∃{Obj = Point ⨯ Point}(\{(a , b) → a ≢ b}) lower-dimension₁ with [∃]-intro (a , b , _) ⦃ [∧]-intro ([∧]-intro p _) _ ⦄ ← lower-dimension₂ = [∃]-intro (a , b) ⦃ ab ↦ p(substitute₃-unary₂(Aligned) ab Aligned-reflexivityₗ) ⦄ -- Also called: 3.14 in Metamathematische Methoden in der Geometrie. extension-existence : ∃(e ↦ (Aligned a b e) ∧ (b ≢ e)) extension-existence{a}{b} with [∃]-intro (x , y) ⦃ nab ⦄ ← lower-dimension₁ with [∃]-intro e ⦃ [∧]-intro abe bexy ⦄ ← segment-construction{a}{b}{x}{y} = [∃]-intro e ⦃ [∧]-intro abe (nab ∘ (be ↦ Equidistanced-point(symmetry(Equidistanced) (substitute₂ₗ(Equidistanced) ([∧]-intro be (reflexivity(_≡ₚ_))) bexy)))) ⦄ -- Also called: 3.17 in Metamathematische Methoden in der Geometrie. triangle-edge-lines-intersection : (Aligned a₁ b₁ c) → (Aligned a₂ b₂ c) → (Aligned a₁ p a₂) → ∃(i ↦ (Aligned p i c) ∧ (Aligned b₁ i b₂)) triangle-edge-lines-intersection a₁b₁c a₂b₂c a₁pa₂ with [∃]-intro j ⦃ [∧]-intro pjc b₂ja₁ ⦄ ← Aligned-intersection a₁pa₂ (Aligned-symmetry a₂b₂c) with [∃]-intro i ⦃ [∧]-intro b₁ib₂ jic ⦄ ← Aligned-intersection (Aligned-symmetry a₁b₁c) (b₂ja₁) = [∃]-intro i ⦃ [∧]-intro (Aligned-transitivityₗ-merge pjc jic) b₁ib₂ ⦄ -- Also called: 4.6 in Metamathematische Methoden in der Geometrie. postulate equidistanced-points-are-aligned : Equidistanced₃(a₁ , b₁ , c₁)(a₂ , b₂ , c₂) → (Aligned a₁ b₁ c₁) → (Aligned a₂ b₂ c₂) -- Also called: 5.1 in Metamathematische Methoden in der Geometrie. postulate Aligned-order-cases₃-skip₂ : (a ≢ b) → (Aligned a b c₁) → (Aligned a b c₂) → ((Aligned a c₁ c₂) ∨ (Aligned a c₂ c₁)) -- Also called: 5.2 in Metamathematische Methoden in der Geometrie. postulate Aligned-order-cases₃-skip₁ : (a ≢ b) → (Aligned a b c₁) → (Aligned a b c₂) → ((Aligned b c₁ c₂) ∨ (Aligned b c₂ c₁)) -- Also called: 5.3 in Metamathematische Methoden in der Geometrie. postulate Aligned-order-cases₂-skip₃ : (Aligned a b₁ c) → (Aligned a b₂ c) → ((Aligned a b₁ b₂) ∨ (Aligned a b₂ b₁)) -- The distance between the first pair of points are lesser or equal to the distance between the second pair of points. -- The definition states that there should exist a point bₘ such that a (b₁,bₘ) is a subline of (b₁,b₂) and such that the subline is of the same length as (a₁,a₂). -- Also called: 5.4 in Metamathematische Methoden in der Geometrie. LeDistanced : (Point ⨯ Point) → (Point ⨯ Point) → Stmt LeDistanced(a₁ , a₂)(b₁ , b₂) = ∃(bₘ ↦ (Aligned b₁ bₘ b₂) ∧ Equidistanced(a₁ , a₂)(b₁ , bₘ)) -- Also called: 5.4 in Metamathematische Methoden in der Geometrie. GeDistanced : (Point ⨯ Point) → (Point ⨯ Point) → Stmt GeDistanced = swap LeDistanced -- Also called: 5.5 in Metamathematische Methoden in der Geometrie. postulate LeDistanced-alternative : LeDistanced(a₁ , a₂)(b₁ , b₂) ↔ ∃(aₒ ↦ (Aligned a₁ a₂ aₒ) ∧ Equidistanced(a₁ , aₒ)(b₁ , b₂)) -- Also called: 5.7 in Metamathematische Methoden in der Geometrie. instance postulate LeDistanced-reflexivity : Reflexivity(LeDistanced) -- Also called: 5.8 in Metamathematische Methoden in der Geometrie. instance postulate LeDistanced-transitivity : Transitivity(LeDistanced) -- Also called: 5.9 in Metamathematische Methoden in der Geometrie. instance postulate LeDistanced-antisymmetry : Antisymmetry(LeDistanced)(Equidistanced) -- Also called: 5.10 in Metamathematische Methoden in der Geometrie. instance postulate LeDistanced-converseTotal : ConverseTotal(LeDistanced) -- Also called: 5.11 in Metamathematische Methoden in der Geometrie. instance postulate LeDistanced-minimal : Weak.Properties.LE.Minimum(LeDistanced)(p , p) -- Also called: 5.12 in Metamathematische Methoden in der Geometrie. postulate Collinear-aligned-ledistanced-equivalence : (Collinear a b c) → ((Aligned a b c) ↔ (LeDistanced(a , b)(a , c) ∧ LeDistanced(b , c)(a , c))) -- Also called: 5.14 in Metamathematische Methoden in der Geometrie. LtDistanced : (Point ⨯ Point) → (Point ⨯ Point) → Stmt LtDistanced(a₁ , a₂)(b₁ , b₂) = LeDistanced(a₁ , a₂)(b₁ , b₂) ∧ (¬ Equidistanced(a₁ , a₂)(b₁ , b₂)) -- Also called: 5.14 in Metamathematische Methoden in der Geometrie. GtDistanced : (Point ⨯ Point) → (Point ⨯ Point) → Stmt GtDistanced = swap GeDistanced aligned-equidistanced-equality : (Aligned a b₁ b₂) → Equidistanced(a , b₁)(a , b₂) → (b₁ ≡ₚ b₂) aligned-equidistanced-equality ab₁b₂ ab₁ab₂ = {!!} aligned-equidistanced-last-equality : (a ≢ b) → (Aligned a b c₁) → (Aligned a b c₂) → Equidistanced(b , c₁)(b , c₂) → (c₁ ≡ c₂) aligned-equidistanced-last-equality nab abc₁ abc₂ bc₁bc₂ = {!Aligned-order-cases₃-skip₁ nab abc₁ abc₂!} Aligned-classical : Classical₃(Aligned) Classical.excluded-middle (Aligned-classical {a} {b} {c}) with [∃]-intro d ⦃ [∧]-intro abd bdbc ⦄ ← segment-construction{a}{b}{b}{c} with excluded-middle(a ≡ₚ b) | excluded-middle(c ≡ₚ d) ... | _ | [∨]-introₗ cd = [∨]-introₗ (substitute₃-unary₃(Aligned) (symmetry(_≡ₚ_) cd) abd) ... | [∨]-introₗ ab | [∨]-introᵣ ncd = [∨]-introₗ (substitute₃-unary₂(Aligned) ab Aligned-reflexivityₗ) ... | [∨]-introᵣ nab | [∨]-introᵣ ncd = [∨]-introᵣ (abc ↦ ncd(aligned-equidistanced-last-equality nab abc abd (symmetry(Equidistanced) bdbc))) {- -- Also called: 6.14 in Metamathematische Methoden in der Geometrie. lineSet : (a : Point) → (b : Point) → ⦃ distinct : (a ≢ b) ⦄ → PredSet(Point) lineSet a b ∋ p = Collinear a p b PredSet.preserve-equiv (lineSet a b) = {!TrinaryRelator.unary₂(Collinear)!} -- TODO-} -- Example: -- (c) -- / \ -- (m₁)\ /(m₂) -- / _(i)_ \ -- (a)__/ \__(b) -- Also called: Outer Pasch. postulate Aligned-outer-intersection : (Aligned a i m₂) → (Aligned b m₂ c) → ∃(m₁ ↦ (Aligned a m₁ c) ∧ (Aligned b i m₁)) {-Aligned-outer-intersection {a}{i}{m₂}{b}{c} aim2 bm2c with excluded-middle(Collinear b i m₂) ⦃ classical ⦄ Aligned-outer-intersection {a}{i}{m₂}{b}{c} aim2 bm2c | [∨]-introₗ coll-bim2 with excluded-middle(Aligned b i m₂) ⦃ classical ⦄ ... | [∨]-introₗ al-bim2 = [∃]-intro c ⦃ [∧]-intro {!!} ([∨]-elim ([∨]-elim (al-bim2 ↦ {!!}) (al-im2b ↦ {!!})) (al-m2bi ↦ {!!}) coll-bim2) ⦄ ... | [∨]-introᵣ x = {!!} Aligned-outer-intersection {a}{i}{m₂}{b}{c} aim2 bm2c | [∨]-introᵣ x = {!!}-} {-with [∃]-intro ii ⦃ p ⦄ ← Aligned-intersection {!!} {!!} = {!!}-} {- -- A point on the bisecting ray of the given line. -- Example: -- ⋮ -- | -- (p) -- / | \ -- / | \ -- (a)-----(b) -- | -- ⋮ BisectingRayPoint : Point → Point → Point → Stmt BisectingRayPoint a p b = Equidistanced(a , p)(b , p) -- The points are all aligned in a line with the second point being in the center of the line constructed from the other points. -- Example: -- (a)---(m)---(b) -- `m` is the centerpoint (in the middle) of `a` and `b`. CenterAligned : Point → Point → Point → Stmt CenterAligned a m b = (BisectingRayPoint a m b) ∧ (Aligned a m b) -- The points form a perpendicular triangle with b being the corner where the perpendicular angle is residing. -- Example: -- (a) -- / | \ -- / | \ -- / | \ -- (c)--(b)--(cₘ) PerpendicularCorner : Point → Point → Point → Stmt PerpendicularCorner a b c = ∃(cₘ ↦ (CenterAligned c b cₘ) ∧ (BisectingRayPoint c a cₘ)) -- The distance between the first pair of points are lesser or equal to the distance between the second pair of points. -- This is defined by considering points on a bisecting ray in the center of each of the two lines constructed from the pairs of points. If there is a function that maps points on the second bisecting ray to the first bisecting ray such that this mapping preserves the distance to one of the endpoints of its corresponding line, then the distance between the first pair is lesser than the second. -- Example: -- (bBisect) -- /|\ -- / | \ -- / | \ -- (b₁)=====(b₂) -- (aBisect) -- /|\ -- / | \ -- | | | -- (a₁)===(a₂) -- -- Here, b₁ and b₂ are equally distanced to bBisect. -- The definition then states that there exists a similiar construction aBisect on a₁ and a₂, and it does. -- And this second construction (aBisect) should have the same distance to its endpoints (for example a₂) as the first (bBisect) have (for example b₂), which it does. -- Now, in the extreme case where the distance between bBisect and the endpoints are shrunk, bBisect would collapse into being a center point of the line (b₁,b₂), but because the distance between a₁ and a₂ is smaller, aBisect will still be outside of the line (a₁,a₂). Though, it still exists. -- This would not be the case if the relation was reversed. LeDistanced2 : (Point ⨯ Point) → (Point ⨯ Point) → Stmt LeDistanced2(a₁ , a₂)(b₁ , b₂) = ∀{bBisect} → (BisectingRayPoint b₁ bBisect b₂) → ∃(aBisect ↦ (BisectingRayPoint a₁ aBisect a₂) ∧ Equidistanced(a₂ , aBisect)(b₂ , bBisect)) -- Aligned-Distanced-equivalence : (Aligned a b c) ↔ (∀{d} → LeDistanced2(a , d)(a , b) → LeDistanced2(c , d)(b , c) → (b ≡ d)) -- Note: The only purpose of this definition is so that instance search works (because it do not work on functions, and negation is defined as a function). record DistinctPoints (a b : Point) : Type{ℓₚₑ} where constructor intro field proof : (a ≢ b) -- A line segment is a geometric figure defined by two distinct points -- The interpretation is that these two points connect each other, and the set of points of the figure are the points between these two points. record LineSegment : Type{ℓₚ Lvl.⊔ ℓₚₑ} where constructor lineSegment field from : Point to : Point ⦃ distinct ⦄ : DistinctPoints from to -- A point on the line segment. point : Point point = [∃]-witness (Aligned-intersection {to}{from} {from} {to}{from} Aligned-reflexivityᵣ Aligned-reflexivityᵣ) -- The line segment flipped. flip : LineSegment flip = record{from = to ; to = from ; distinct = intro(DistinctPoints.proof distinct ∘ symmetry(_≡_))} copyTo : Point → LineSegment copyTo base = {!!} -- TODO: This is apparently difficult to construct center : Point -- center = {!!} -- The bisector (TODO: which one?) line of this line segment. (TODO: Too unspecific. Where does it start and end?) bisector : LineSegment -- bisector = {!!} private variable l l₁ l₂ l₃ : LineSegment -- Point inclusion in line segment (a point is in a line segment). _∈₂_ : Point → LineSegment → Type p ∈₂ lineSegment a b = Aligned a p b -- Line segment congruence (two line segments are of equal length) _⎶_ : LineSegment → LineSegment → Type lineSegment a₁ a₂ ⎶ lineSegment b₁ b₂ = Equidistanced(a₁ , a₂)(b₁ , b₂) Perpendicular : LineSegment → LineSegment → Stmt Perpendicular(lineSegment a₁ a₂)(lineSegment b₁ b₂) = ∃(c ↦ (Collinear a₁ a₂ c) ∧ (Collinear b₁ b₂ c) ∧ (PerpendicularCorner a₂ c b₂)) Parallel : LineSegment → LineSegment → Stmt Parallel a b = Perpendicular a (LineSegment.bisector b) point-in-lineSegment : LineSegment.point(l) ∈₂ l point-in-lineSegment{l} = [∧]-elimₗ([∃]-proof (Aligned-intersection Aligned-reflexivityᵣ Aligned-reflexivityᵣ)) -- A triangle is a geometric figure defined by three unaligned points. -- The interpretation is that these three points connect each other, forming three line segments, and the set of points of the figure are the points inside the line segments. record Triangle : Type{ℓₚ Lvl.⊔ ℓₗᵢₗ} where constructor triangle field point₁ : Point point₂ : Point point₃ : Point ⦃ distinct₁ ⦄ : ¬ Aligned point₁ point₂ point₃ ⦃ distinct₂ ⦄ : ¬ Aligned point₂ point₃ point₁ ⦃ distinct₃ ⦄ : ¬ Aligned point₃ point₁ point₂ side₁₂ : LineSegment side₁₂ = line point₁ point₂ ⦃ intro(contrapositiveᵣ (p1p2 ↦ substitute₃-unary₁(Aligned) (symmetry(_≡_) p1p2) Aligned-reflexivityₗ) distinct₁) ⦄ side₂₃ : LineSegment side₂₃ = line point₂ point₃ ⦃ intro(contrapositiveᵣ (p2p3 ↦ substitute₃-unary₁(Aligned) (symmetry(_≡_) p2p3) Aligned-reflexivityₗ) distinct₂) ⦄ side₃₁ : LineSegment side₃₁ = line point₃ point₁ ⦃ intro(contrapositiveᵣ (p3p1 ↦ substitute₃-unary₁(Aligned) (symmetry(_≡_) p3p1) Aligned-reflexivityₗ) distinct₃) ⦄ private variable tri tri₁ tri₂ : Triangle -- A triangle exists. -- This comes directly from an axiom. Triangle-existence : Triangle Triangle-existence with [∃]-intro(x , y , z) ⦃ [∧]-intro ([∧]-intro p q) r ⦄ ← lower-dimension = triangle x y z ⦃ p ⦄ ⦃ q ⦄ ⦃ r ⦄ Aligned-four : (Aligned a b c) → (Aligned p₁ b c) → (Aligned a b p₂) → (Aligned p₁ b p₂) Aligned-four abc p₁bc abp₂ with [∃]-intro d ⦃ [∧]-intro bdp₂ bdc ⦄ ← Aligned-intersection (Aligned-symmetry abc) (Aligned-symmetry abp₂) with [∃]-intro e ⦃ [∧]-intro bep₁ bea ⦄ ← Aligned-intersection abc p₁bc = {!Aligned-transitivityᵣ abp₂ p₁bc!} Aligned-alternative-start : (Aligned a₁ b c)→ (Aligned a₂ b c) → ((Aligned a₁ a₂ b) ∨ (Aligned a₂ a₁ b)) -- Note: The difference between segment-construction and this is that this is not extending the line (a₁,b₁). segment-equidistanced-copy constructs a new line which is of the same length as (a₂,b₂) but starting from a₁ and is in the direction of p. -- TODO: A proof idea is to use center-of-3 and eliminate the last case. For the different cases, one uses different segment-constructions as usual segment-equidistanced-copy : ∃(p ↦ ((Aligned a₁ b₁ p) ∨ (Aligned a₁ p b₁)) ∧ Equidistanced(a₁ , p)(a₂ , b₂)) segment-equidistanced-copy {a₁}{b₁} {a₂}{b₂} with [∃]-intro ext ⦃ [∧]-intro al-b₁a₁ext d-a₁ext-a₂b₂ ⦄ ← segment-construction{b₁}{a₁} {a₂}{b₂} with [∃]-intro p ⦃ [∧]-intro al-exta₁p d-a₁p-exta₁ ⦄ ← segment-construction{ext}{a₁} {ext}{a₁} with center-of-3 {a₁}{b₁}{p} ... | [∨]-introₗ ([∨]-introₗ ([∨]-introₗ al-a₁b₁p)) = [∃]-intro p ⦃ [∧]-intro ([∨]-introₗ al-a₁b₁p) (d-a₁p-exta₁ 🝖 Equidistanced-flipped 🝖 d-a₁ext-a₂b₂) ⦄ ... | [∨]-introₗ ([∨]-introₗ ([∨]-introᵣ al-b₁pa₁)) = [∃]-intro p ⦃ [∧]-intro ([∨]-introᵣ (Aligned-symmetry al-b₁pa₁)) (d-a₁p-exta₁ 🝖 Equidistanced-flipped 🝖 d-a₁ext-a₂b₂) ⦄ ... | [∨]-introₗ ([∨]-introᵣ al-pa₁b₁) = [∃]-intro p ⦃ [∧]-intro ([∨]-introᵣ {!!}) (d-a₁p-exta₁ 🝖 Equidistanced-flipped 🝖 d-a₁ext-a₂b₂) ⦄ -- TODO: Use Aligned-four to prove (a₁ ≡ ext), which implies (a₁ ≡ p), so therefore ( Aligned a₁ a₁ b₁) by substitution. Note that this is the case when (a₂ ≡ b₂), but it is not used in the proof. ... | [∨]-introᵣ x = {!!} -- TODO: x essentially states that a₁ b₁ p is not in a line, which can be proven that they are like in the cases above by Aligned-alternative-start -- A circle is a geometric figure defined by two distinct points. -- The interpretation is that the first point is the center point, and the second point lies on the arc of the circle. -- The distance between the points is the radius of the circle, and all points within the radius from the center point defines the set of points of the circle. record Circle : Type{ℓₚ Lvl.⊔ ℓₚₑ} where constructor circle field center : Point outer : Point ⦃ distinct ⦄ : DistinctPoints center outer -- A line from the center point to the arc. radiusLineSegment : LineSegment radiusLineSegment = lineSegment center outer {- TODO -- A line from the center point to the arc in the direction of the given point. radiusLineSegmentTowards : Point → LineSegment radiusLineSegmentTowards p with [∃]-intro q ⦃ [∧]-intro cpq pqco ⦄ ← segment-construction{center}{p} {center}{outer} = lineSegment center q ⦃ intro(cq ↦ ( • ( • center ≡ q :-[ cq ] • Aligned center p q :-[ cpq ] ⇒₂-[ substitute₃-unary₁(Aligned) ] Aligned q p q ⇒-[ Aligned-point ] p ≡ q ⇒-[ pq ↦ [∧]-intro pq (reflexivity(_≡_)) ] (p ≡ q) ∧ (q ≡ q) ⇒-end ) • Equidistanced(p , q) (center , outer) :-[ pqco ] ⇒₂-[ substitute₂ₗ(Equidistanced) ] Equidistanced(q , q) (center , outer) ⇒-[ symmetry(Equidistanced) ] Equidistanced(center , outer) (q , q) ⇒-[ Equidistanced-point ] center ≡ outer ⇒-[ DistinctPoints.proof distinct ] ⊥ ⇒-end )) ⦄ -- TODO: I am confused. Is the point (LineSegment.to(radiusLineTowards p)) always further away than p? radiusLineTowards-aligned : Aligned center p (Line.to(radiusLineSegmentTowards p)) radiusLineTowards-aligned{p} with [∃]-intro q ⦃ [∧]-intro cpq pqco ⦄ ← segment-construction{center}{p} {center}{outer} = cpq radiusLineSegmentTowards-radius : Equidistanced(center , LineSegment.to(radiusLineSegmentTowards p)) (center , outer) radiusLineSegmentTowards-radius{p} with [∃]-intro q ⦃ [∧]-intro cpq pqco ⦄ ← segment-construction{center}{p} {center}{outer} = {!pqco!} -- TODO: pqco is actually stating that (p,q) and (center,outer) is equally distanced, which is not what we want, so radiusLineTowards should be modified to use segment-construction-alt -} -- TODO: Two circles' intersection points are either 0, 1, 2 or they are the same circle. -- intersection : ∀{C₁ C₂} → (∀{p} → ¬(p ∈ₒ C₁) ∧ ¬(p ∈ₒ C₂)) ∨ ∃!(p ↦ (p ∈ₒ C₁) ∧ (p ∈ₒ C₂)) ∨ ∃(p₁ ↦ ∃(p₂ ↦ (p ∈ₒ C₁) ∧ (p ∈ₒ C₂))) ∨ (C₁ ≡ C₂) -- Point inclusion in circle (a point is in a circle). _∈ₒ_ : Point → Circle → Type p ∈ₒ circle c o = LeDistanced(c , p)(c , o) -- TODO: Is this equivalent? ∃(op ↦ Equidistanced(c , o)(c , op) ∧ (Aligned c p op)) It extends the line (c,p) instead of shrinking the line (c,o) -}
{ "alphanum_fraction": 0.657019825, "avg_line_length": 53.3776119403, "ext": "agda", "hexsha": "7590c82e401761dcbb4077342e90edb1c066d1bd", "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": "Geometry/Axioms.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": "Geometry/Axioms.agda", "max_line_length": 398, "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": "Geometry/Axioms.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": 12287, "size": 35763 }
{-# OPTIONS --cubical --safe #-} module Cubical.Structures.Everything where open import Cubical.Structures.Pointed public open import Cubical.Structures.InftyMagma public open import Cubical.Structures.Monoid public open import Cubical.Structures.Queue public open import Cubical.Structures.TypeEqvTo public
{ "alphanum_fraction": 0.8322580645, "avg_line_length": 31, "ext": "agda", "hexsha": "1896bd25e99bf749dfc3cdc646040e1978b196c4", "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": "cefeb3669ffdaea7b88ae0e9dd258378418819ca", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "borsiemir/cubical", "max_forks_repo_path": "Cubical/Structures/Everything.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca", "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": "borsiemir/cubical", "max_issues_repo_path": "Cubical/Structures/Everything.agda", "max_line_length": 48, "max_stars_count": null, "max_stars_repo_head_hexsha": "cefeb3669ffdaea7b88ae0e9dd258378418819ca", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "borsiemir/cubical", "max_stars_repo_path": "Cubical/Structures/Everything.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 72, "size": 310 }
module PLRTree.Heap {A : Set}(_≤_ : A → A → Set) where open import PLRTree {A} data _≤*_ : A → PLRTree → Set where lf≤* : (x : A) → x ≤* leaf nd≤* : {t : Tag}{x y : A}{l r : PLRTree} → x ≤ y → x ≤* l → x ≤* r → x ≤* node t y l r data Heap : PLRTree → Set where leaf : Heap leaf node : {t : Tag}{x : A}{l r : PLRTree} → x ≤* l → x ≤* r → Heap l → Heap r → Heap (node t x l r)
{ "alphanum_fraction": 0.3339041096, "avg_line_length": 26.5454545455, "ext": "agda", "hexsha": "d837ef77d9470bf98d213b51b6eebd4b00907125", "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": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bgbianchi/sorting", "max_forks_repo_path": "agda/PLRTree/Heap.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "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": "bgbianchi/sorting", "max_issues_repo_path": "agda/PLRTree/Heap.agda", "max_line_length": 54, "max_stars_count": 6, "max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bgbianchi/sorting", "max_stars_repo_path": "agda/PLRTree/Heap.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z", "num_tokens": 191, "size": 584 }
{-# OPTIONS --safe #-} module Cubical.HITs.S2.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Pointed data S² : Type₀ where base : S² surf : PathP (λ i → base ≡ base) refl refl S²∙ : Pointed ℓ-zero S²∙ = S² , base S²ToSetElim : ∀ {ℓ} {A : S² → Type ℓ} → ((x : S²) → isSet (A x)) → A base → (x : S²) → A x S²ToSetElim set b base = b S²ToSetElim set b (surf i j) = isOfHLevel→isOfHLevelDep 2 set b b {a0 = refl} {a1 = refl} refl refl surf i j -- Wedge connectivity lemmas for S² (binary maps 2-groupoids) wedgeconFunS² : ∀ {ℓ} {P : S² → S² → Type ℓ} → ((x y : _) → isOfHLevel 4 (P x y)) → (l : ((x : S²) → P x base)) → (r : (x : S²) → P base x) → l base ≡ r base → (x y : _) → P x y wedgeconFunS² {P = P} hlev l r p base y = r y wedgeconFunS² {P = P} hlev l r p (surf i i₁) y = help y i i₁ where help : (y : S²) → SquareP (λ i j → P (surf i j) y) (λ _ → r y) (λ _ → r y) (λ _ → r y) λ _ → r y help = S²ToSetElim (λ _ → isOfHLevelPathP' 2 (isOfHLevelPathP' 3 (hlev _ _) _ _) _ _) λ w j → hcomp (λ k → λ { (j = i0) → p k ; (j = i1) → p k ; (w = i0) → p k ; (w = i1) → p k}) (l (surf w j)) wedgeconFunS²Id : ∀ {ℓ} {P : S² → S² → Type ℓ} → (h : ((x y : _) → isOfHLevel 4 (P x y))) → (l : ((x : S²) → P x base)) → (r : (x : S²) → P base x) → (p : l base ≡ r base) → (x : S²) → wedgeconFunS² h l r p x base ≡ l x wedgeconFunS²Id h l r p base = sym p wedgeconFunS²Id h l r p (surf i j) k = hcomp (λ w → λ {(i = i0) → p (~ k ∧ w) ; (i = i1) → p (~ k ∧ w) ; (j = i0) → p (~ k ∧ w) ; (j = i1) → p (~ k ∧ w) ; (k = i1) → l (surf i j)}) (l (surf i j))
{ "alphanum_fraction": 0.4356338718, "avg_line_length": 35.224137931, "ext": "agda", "hexsha": "6b156b5542f87af7324292266ea6456f63417e47", "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": "58f2d0dd07e51f8aa5b348a522691097b6695d1c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Seanpm2001-web/cubical", "max_forks_repo_path": "Cubical/HITs/S2/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c", "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": "Seanpm2001-web/cubical", "max_issues_repo_path": "Cubical/HITs/S2/Base.agda", "max_line_length": 82, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "FernandoLarrain/cubical", "max_stars_repo_path": "Cubical/HITs/S2/Base.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z", "max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z", "num_tokens": 781, "size": 2043 }
{-# OPTIONS --without-K --safe #-} module PiFracDynDef where open import Data.Bool open import Data.Empty open import Data.Unit open import Data.Nat open import Data.Nat.Properties open import Data.Sum open import Data.Product open import Data.Maybe open import Function open import Relation.Binary.PropositionalEquality renaming ([_] to R[_]) open import Relation.Binary.Core open import Relation.Nullary infix 70 _×ᵤ_ infix 60 _+ᵤ_ infix 40 _↔_ infixr 50 _⊚_ data ◯ : Set where ○ : ◯ -- Pi mutual data 𝕌 : Set where 𝟘 : 𝕌 𝟙 : 𝕌 _+ᵤ_ : 𝕌 → 𝕌 → 𝕌 _×ᵤ_ : 𝕌 → 𝕌 → 𝕌 𝟙/_ : 𝕌 → 𝕌 ⟦_⟧ : 𝕌 → Set ⟦ 𝟘 ⟧ = ⊥ ⟦ 𝟙 ⟧ = ⊤ ⟦ t₁ +ᵤ t₂ ⟧ = ⟦ t₁ ⟧ ⊎ ⟦ t₂ ⟧ ⟦ t₁ ×ᵤ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧ ⟦ 𝟙/ t ⟧ = ◯ data _↔_ : 𝕌 → 𝕌 → Set where unite₊l : {t : 𝕌} → 𝟘 +ᵤ t ↔ t uniti₊l : {t : 𝕌} → t ↔ 𝟘 +ᵤ t unite₊r : {t : 𝕌} → t +ᵤ 𝟘 ↔ t uniti₊r : {t : 𝕌} → t ↔ t +ᵤ 𝟘 swap₊ : {t₁ t₂ : 𝕌} → t₁ +ᵤ t₂ ↔ t₂ +ᵤ t₁ assocl₊ : {t₁ t₂ t₃ : 𝕌} → t₁ +ᵤ (t₂ +ᵤ t₃) ↔ (t₁ +ᵤ t₂) +ᵤ t₃ assocr₊ : {t₁ t₂ t₃ : 𝕌} → (t₁ +ᵤ t₂) +ᵤ t₃ ↔ t₁ +ᵤ (t₂ +ᵤ t₃) unite⋆l : {t : 𝕌} → 𝟙 ×ᵤ t ↔ t uniti⋆l : {t : 𝕌} → t ↔ 𝟙 ×ᵤ t unite⋆r : {t : 𝕌} → t ×ᵤ 𝟙 ↔ t uniti⋆r : {t : 𝕌} → t ↔ t ×ᵤ 𝟙 swap⋆ : {t₁ t₂ : 𝕌} → t₁ ×ᵤ t₂ ↔ t₂ ×ᵤ t₁ assocl⋆ : {t₁ t₂ t₃ : 𝕌} → t₁ ×ᵤ (t₂ ×ᵤ t₃) ↔ (t₁ ×ᵤ t₂) ×ᵤ t₃ assocr⋆ : {t₁ t₂ t₃ : 𝕌} → (t₁ ×ᵤ t₂) ×ᵤ t₃ ↔ t₁ ×ᵤ (t₂ ×ᵤ t₃) absorbr : {t : 𝕌} → 𝟘 ×ᵤ t ↔ 𝟘 absorbl : {t : 𝕌} → t ×ᵤ 𝟘 ↔ 𝟘 factorzr : {t : 𝕌} → 𝟘 ↔ t ×ᵤ 𝟘 factorzl : {t : 𝕌} → 𝟘 ↔ 𝟘 ×ᵤ t dist : {t₁ t₂ t₃ : 𝕌} → (t₁ +ᵤ t₂) ×ᵤ t₃ ↔ (t₁ ×ᵤ t₃) +ᵤ (t₂ ×ᵤ t₃) factor : {t₁ t₂ t₃ : 𝕌} → (t₁ ×ᵤ t₃) +ᵤ (t₂ ×ᵤ t₃) ↔ (t₁ +ᵤ t₂) ×ᵤ t₃ distl : {t₁ t₂ t₃ : 𝕌} → t₁ ×ᵤ (t₂ +ᵤ t₃) ↔ (t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃) factorl : {t₁ t₂ t₃ : 𝕌 } → (t₁ ×ᵤ t₂) +ᵤ (t₁ ×ᵤ t₃) ↔ t₁ ×ᵤ (t₂ +ᵤ t₃) id↔ : {t : 𝕌} → t ↔ t _⊚_ : {t₁ t₂ t₃ : 𝕌} → (t₁ ↔ t₂) → (t₂ ↔ t₃) → (t₁ ↔ t₃) _⊕_ : {t₁ t₂ t₃ t₄ : 𝕌} → (t₁ ↔ t₃) → (t₂ ↔ t₄) → (t₁ +ᵤ t₂ ↔ t₃ +ᵤ t₄) _⊗_ : {t₁ t₂ t₃ t₄ : 𝕌} → (t₁ ↔ t₃) → (t₂ ↔ t₄) → (t₁ ×ᵤ t₂ ↔ t₃ ×ᵤ t₄) η : {t : 𝕌} {t≠0 : ¬ card t ≡ 0} → 𝟙 ↔ t ×ᵤ (𝟙/ t) ε : {t : 𝕌} {t≠0 : ¬ card t ≡ 0} → t ×ᵤ (𝟙/ t) ↔ 𝟙 -- Number of points in type card : (t : 𝕌) → ℕ card 𝟘 = 0 card 𝟙 = 1 card (t₁ +ᵤ t₂) = card t₁ + card t₂ card (t₁ ×ᵤ t₂) = card t₁ * card t₂ card (𝟙/ t) = 1 -- If number of points is zero then it is impossible to find a value -- of the type 0empty : {t : 𝕌} → card t ≡ 0 → (v : ⟦ t ⟧) → ⊥ 0empty {𝟘} _ () 0empty {𝟙} () tt 0empty {t₁ +ᵤ t₂} s (inj₁ v₁) with card t₁ | card t₂ | inspect card t₁ 0empty {t₁ +ᵤ t₂} refl (inj₁ v₁) | 0 | 0 | R[ s₁ ] = 0empty {t₁} s₁ v₁ 0empty {t₁ +ᵤ t₂} s (inj₂ v₂) with card t₁ | card t₂ | inspect card t₂ 0empty {t₁ +ᵤ t₂} refl (inj₂ v₂) | ℕ.zero | ℕ.zero | R[ s₂ ] = 0empty {t₂} s₂ v₂ 0empty {t₁ ×ᵤ t₂} s (v₁ , v₂) with card t₁ | card t₂ | inspect card t₁ | inspect card t₂ 0empty {t₁ ×ᵤ t₂} refl (v₁ , v₂) | ℕ.zero | _ | R[ s₁ ] | _ = 0empty {t₁} s₁ v₁ 0empty {t₁ ×ᵤ t₂} s (v₁ , v₂) | ℕ.suc n₁ | ℕ.zero | R[ s₁ ] | R[ s₂ ] = 0empty {t₂} s₂ v₂ 0empty {𝟙/ t} () f default : (t : 𝕌) → {t≠0 : ¬ card t ≡ 0} → ⟦ t ⟧ default 𝟘 {t≠0} = ⊥-elim (t≠0 refl) default 𝟙 = tt default (t₁ +ᵤ t₂) {p≠0} with card t₁ | card t₂ | inspect card t₁ | inspect card t₂ ... | 0 | 0 | R[ s₁ ] | R[ s₂ ] = ⊥-elim (p≠0 refl) ... | 0 | suc n | R[ s₁ ] | R[ s₂ ] = inj₂ (default t₂ {λ t2≡0 → ⊥-elim (p≠0 (trans (sym s₂) t2≡0))}) ... | suc m | 0 | R[ s₁ ] | R[ s₂ ] = inj₁ (default t₁ {λ t1≡0 → ⊥-elim (p≠0 ((trans (sym (trans s₁ (sym (+-identityʳ (suc m))))) t1≡0)))}) ... | suc m | suc n | R[ s₁ ] | R[ s₂ ] = inj₁ (default t₁ {λ t1≡0 → ⊥-elim (1+n≢0 (trans (sym s₁) t1≡0))}) default (t₁ ×ᵤ t₂) {p≠0} with card t₁ | card t₂ | inspect card t₁ | inspect card t₂ ... | 0 | 0 | R[ s₁ ] | R[ s₂ ] = ⊥-elim (p≠0 refl) ... | 0 | suc n | R[ s₁ ] | R[ s₂ ] = ⊥-elim (p≠0 refl) ... | suc m | 0 | R[ s₁ ] | R[ s₂ ] = ⊥-elim (p≠0 (*-zeroʳ (suc m))) ... | suc m | suc n | R[ s₁ ] | R[ s₂ ] = default t₁ {λ t1≡0 → ⊥-elim (1+n≢0 (trans (sym s₁) t1≡0))}, default t₂ {λ t2≡0 → ⊥-elim (1+n≢0 (trans (sym s₂) t2≡0))} default (𝟙/ t) = ○ 𝕌dec : (t : 𝕌) → Decidable (_≡_ {A = ⟦ t ⟧}) 𝕌dec 𝟘 () 𝕌dec 𝟙 tt tt = yes refl 𝕌dec (t₁ +ᵤ t₂) (inj₁ x) (inj₁ y) with 𝕌dec t₁ x y 𝕌dec (t₁ +ᵤ t₂) (inj₁ x) (inj₁ .x) | yes refl = yes refl 𝕌dec (t₁ +ᵤ t₂) (inj₁ x) (inj₁ y) | no ¬p = no (λ {refl → ¬p refl}) 𝕌dec (t₁ +ᵤ t₂) (inj₁ x) (inj₂ y) = no (λ ()) 𝕌dec (t₁ +ᵤ t₂) (inj₂ x) (inj₁ y) = no (λ ()) 𝕌dec (t₁ +ᵤ t₂) (inj₂ x) (inj₂ y) with 𝕌dec t₂ x y 𝕌dec (t₁ +ᵤ t₂) (inj₂ x) (inj₂ .x) | yes refl = yes refl 𝕌dec (t₁ +ᵤ t₂) (inj₂ x) (inj₂ y) | no ¬p = no (λ {refl → ¬p refl}) 𝕌dec (t₁ ×ᵤ t₂) (x₁ , y₁) (x₂ , y₂) with 𝕌dec t₁ x₁ x₂ | 𝕌dec t₂ y₁ y₂ 𝕌dec (t₁ ×ᵤ t₂) (x₁ , y₁) (.x₁ , .y₁) | yes refl | yes refl = yes refl 𝕌dec (t₁ ×ᵤ t₂) (x₁ , y₁) (.x₁ , y₂) | yes refl | no ¬p = no (λ p → ¬p (cong proj₂ p)) 𝕌dec (t₁ ×ᵤ t₂) (x₁ , y₁) (x₂ , .y₁) | no ¬p | yes refl = no (λ p → ¬p (cong proj₁ p)) 𝕌dec (t₁ ×ᵤ t₂) (x₁ , y₁) (x₂ , y₂) | no ¬p | no ¬p₁ = no (λ p → ¬p (cong proj₁ p)) 𝕌dec (𝟙/ t) ○ ○ = yes refl _≟ᵤ_ : {t : 𝕌} → Decidable (_≡_ {A = ⟦ t ⟧}) _≟ᵤ_ {t} v w = 𝕌dec t v w interp : {t₁ t₂ : 𝕌} → (t₁ ↔ t₂) → ⟦ t₁ ⟧ → Maybe ⟦ t₂ ⟧ interp unite₊l (inj₁ ()) interp unite₊l (inj₂ v) = just v interp uniti₊l v = just (inj₂ v) interp unite₊r (inj₁ v) = just v interp unite₊r (inj₂ ()) interp uniti₊r v = just (inj₁ v) interp swap₊ (inj₁ v) = just (inj₂ v) interp swap₊ (inj₂ v) = just (inj₁ v) interp assocl₊ (inj₁ v) = just (inj₁ (inj₁ v)) interp assocl₊ (inj₂ (inj₁ v)) = just (inj₁ (inj₂ v)) interp assocl₊ (inj₂ (inj₂ v)) = just (inj₂ v) interp assocr₊ (inj₁ (inj₁ v)) = just (inj₁ v) interp assocr₊ (inj₁ (inj₂ v)) = just (inj₂ (inj₁ v)) interp assocr₊ (inj₂ v) = just (inj₂ (inj₂ v)) interp unite⋆l v = just (proj₂ v) interp uniti⋆l v = just (tt , v) interp unite⋆r v = just (proj₁ v) interp uniti⋆r v = just (v , tt) interp swap⋆ (v₁ , v₂) = just (v₂ , v₁) interp assocl⋆ (v₁ , v₂ , v₃) = just ((v₁ , v₂) , v₃) interp assocr⋆ ((v₁ , v₂) , v₃) = just (v₁ , v₂ , v₃) interp absorbr (() , v) interp absorbl (v , ()) interp factorzr () interp factorzl () interp dist (inj₁ v₁ , v₃) = just (inj₁ (v₁ , v₃)) interp dist (inj₂ v₂ , v₃) = just (inj₂ (v₂ , v₃)) interp factor (inj₁ (v₁ , v₃)) = just (inj₁ v₁ , v₃) interp factor (inj₂ (v₂ , v₃)) = just (inj₂ v₂ , v₃) interp distl (v₁ , inj₁ v₂) = just (inj₁ (v₁ , v₂)) interp distl (v₁ , inj₂ v₃) = just (inj₂ (v₁ , v₃)) interp factorl (inj₁ (v₁ , v₂)) = just (v₁ , inj₁ v₂) interp factorl (inj₂ (v₁ , v₃)) = just (v₁ , inj₂ v₃) interp id↔ v = just v interp (c₁ ⊚ c₂) v = interp c₁ v >>= interp c₂ interp (c₁ ⊕ c₂) (inj₁ v) = interp c₁ v >>= just ∘ inj₁ interp (c₁ ⊕ c₂) (inj₂ v) = interp c₂ v >>= just ∘ inj₂ interp (c₁ ⊗ c₂) (v₁ , v₂) = interp c₁ v₁ >>= (λ v₁' → interp c₂ v₂ >>= λ v₂' → just (v₁' , v₂')) interp (η {t} {t≠0}) tt = just (default t {t≠0} , ○) interp (ε {t} {t≠0}) (v' , ○) with 𝕌dec t (default t {t≠0}) v' interp (ε {t}) (v' , ○) | yes _ = just tt interp (ε {t}) (v' , ○) | no _ = nothing -- if v ≡ v' then tt else throw Error --- Examples 𝟚 : 𝕌 𝟚 = 𝟙 +ᵤ 𝟙 𝔽 𝕋 : ⟦ 𝟚 ⟧ 𝔽 = inj₁ tt 𝕋 = inj₂ tt xorr xorl : 𝟚 ×ᵤ 𝟚 ↔ 𝟚 ×ᵤ 𝟚 xorr = dist ⊚ (id↔ ⊕ (id↔ ⊗ swap₊)) ⊚ factor xorl = distl ⊚ (id↔ ⊕ (swap₊ ⊗ id↔)) ⊚ factorl 𝟚≠0 : ¬ (card 𝟚 ≡ 0) 𝟚≠0 () η𝟚 : 𝟙 ↔ 𝟚 ×ᵤ (𝟙/ 𝟚) η𝟚 = η {t≠0 = 𝟚≠0} ε𝟚 : 𝟚 ×ᵤ (𝟙/ 𝟚) ↔ 𝟙 ε𝟚 = ε {t≠0 = 𝟚≠0} -- ─────┬────⊕─── ─────── -- | | ⨉ -- ┌──⊕────┴─── ───┐ -- └────────────────┘ id' : 𝟚 ↔ 𝟚 id' = uniti⋆r ⊚ (id↔ ⊗ η𝟚) ⊚ assocl⋆ ⊚ ((xorr ⊚ xorl ⊚ swap⋆) ⊗ id↔) ⊚ assocr⋆ ⊚ (id↔ ⊗ ε𝟚) ⊚ unite⋆r ex1 : interp id' 𝕋 ≡ just 𝕋 ex1 = refl ex2 : interp id' 𝔽 ≡ just 𝔽 ex2 = refl -- ┌────── ───────┐ -- └──────╲╱───────┘ -- ╱╲ -- ┌───── ──────┐ -- └───────────────┘ switch : 𝟙 ↔ 𝟙 switch = uniti⋆r ⊚ (η𝟚 ⊗ η𝟚) ⊚ assocl⋆ ⊚ (((swap⋆ ⊗ id↔) ⊚ assocr⋆ ⊚ (id↔ ⊗ swap⋆) ⊚ assocl⋆ ⊚ (swap⋆ ⊗ id↔)) ⊗ id↔) ⊚ assocr⋆ ⊚ (ε𝟚 ⊗ ε𝟚) ⊚ unite⋆r bad : 𝟚 ↔ 𝟚 bad = uniti⋆r ⊚ (id↔ ⊗ η𝟚) ⊚ assocl⋆ ⊚ ((xorr ⊚ swap⋆) ⊗ id↔) ⊚ assocr⋆ ⊚ (id↔ ⊗ ε𝟚) ⊚ unite⋆r ex3 : interp bad 𝔽 ≡ just 𝔽 ex3 = refl ex4 : interp bad 𝕋 ≡ nothing ex4 = refl {-- shouldn't_type_check : 𝟙 ↔ 𝟙 shouldn't_type_check = η {v = 𝔽} ⊚ ε {v = 𝕋} ex5 : interp shouldn't_type_check tt ≡ nothing ex5 = refl more : 𝟙 ↔ 𝟙 more = η {v = 𝔽} ⊚ (swap₊ ⊗ id↔) ⊚ ε {v = 𝕋} ex6 : interp more tt ≡ just tt ex6 = refl --}
{ "alphanum_fraction": 0.4970553592, "avg_line_length": 32.6538461538, "ext": "agda", "hexsha": "d96ef8f34577ab5b16e4bce8a5706cbfcc069d32", "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": "fracGC/PiFracDynDef.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": "fracGC/PiFracDynDef.agda", "max_line_length": 97, "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": "fracGC/PiFracDynDef.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": 4974, "size": 8490 }
module Isomorphism where open import Library record Iso {a b}(A : Set a)(B : Set b) : Set (a ⊔ b) where field fun : A → B inv : B → A law1 : ∀ b → fun (inv b) ≅ b law2 : ∀ a → inv (fun a) ≅ a
{ "alphanum_fraction": 0.5045454545, "avg_line_length": 22, "ext": "agda", "hexsha": "e0edfc5e34b8e5d06054c210ac7749cc5fd99018", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z", "max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "jmchapman/Relative-Monads", "max_forks_repo_path": "Isomorphism.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z", "max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "jmchapman/Relative-Monads", "max_issues_repo_path": "Isomorphism.agda", "max_line_length": 58, "max_stars_count": 21, "max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "jmchapman/Relative-Monads", "max_stars_repo_path": "Isomorphism.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z", "max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z", "num_tokens": 83, "size": 220 }
{-# OPTIONS --without-K #-} open import HoTT.Base open import HoTT.Equivalence module HoTT.Identity.Product where open variables private variable x y : A × B _=×_ : A × B → A × B → 𝒰 _ x =× y = pr₁ x == pr₁ y × pr₂ x == pr₂ y -- Theorem 2.6.2 =× : x == y ≃ x =× y =× {x = _ , _} {_ , _} = let open Iso in iso→eqv λ where .f refl → refl , refl .g (refl , refl) → refl .η refl → refl .ε (refl , refl) → refl module _ {x y : A × B} where open Iso (eqv→iso (=× {x = x} {y})) public renaming (f to =×-elim ; g to =×-intro ; η to =×-η ; ε to =×-β) ×-pair⁼ = =×-intro
{ "alphanum_fraction": 0.5421686747, "avg_line_length": 22.3461538462, "ext": "agda", "hexsha": "e8ef88270430640545e38390a7929337a184e8ad", "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": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508", "max_forks_repo_licenses": [ "0BSD" ], "max_forks_repo_name": "michaelforney/hott", "max_forks_repo_path": "HoTT/Identity/Product.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508", "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": "michaelforney/hott", "max_issues_repo_path": "HoTT/Identity/Product.agda", "max_line_length": 67, "max_stars_count": null, "max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508", "max_stars_repo_licenses": [ "0BSD" ], "max_stars_repo_name": "michaelforney/hott", "max_stars_repo_path": "HoTT/Identity/Product.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 239, "size": 581 }
module Golden.RedBlack where open import Prelude hiding (insert) -- Version of comparison that lets us use instance search for the proof objects. data Comparison! {a} {A : Set a} (_<_ : A → A → Set a) (x y : A) : Set a where less : {{_ : x < y}} → Comparison! _<_ x y equal : {{_ : x ≡ y}} → Comparison! _<_ x y greater : {{_ : y < x}} → Comparison! _<_ x y compare! : ∀ {a} {A : Set a} {{_ : Ord A}} (x y : A) → Comparison! _<_ x y compare! x y = case compare x y of λ where (less lt) → less {{lt}} (equal eq) → equal {{eq}} (greater gt) → greater {{gt}} record Prf (A : Set) : Set where constructor ! field {{prf}} : A data Bound (A : Set) : Set where -∞ ∞ : Bound A # : A → Bound A module _ {A : Set} {{_ : Ord A}} where LessBound : Bound A → Bound A → Set LessBound ∞ _ = ⊥ LessBound _ ∞ = ⊤ LessBound _ -∞ = ⊥ LessBound -∞ _ = ⊤ LessBound (# x) (# y) = x < y instance OrdBound : Ord (Bound A) OrdBound = defaultOrd compareBound where compareBound : (a b : Bound A) → Comparison LessBound a b compareBound -∞ -∞ = equal refl compareBound -∞ ∞ = less _ compareBound -∞ (# x) = less _ compareBound ∞ -∞ = greater tt compareBound ∞ ∞ = equal refl compareBound ∞ (# x) = greater tt compareBound (# x) -∞ = greater tt compareBound (# x) ∞ = less tt compareBound (# x) (# y) with compare x y ... | less lt = less lt ... | greater gt = greater gt compareBound (# x) (# .x) | equal refl = equal refl Bounds : Set → Set Bounds A = Bound A × Bound A Rel : Set → Set₁ Rel A = Bounds A → Set module _ {A : Set} where PrfR : Rel A → Rel A PrfR R b = Prf (R b) data _∧_ (S T : Rel A) : Rel A where pivot : ∀ {l u} p → S (l , # p) → T (# p , u) → (S ∧ T) (l , u) pattern -⟨_⟩- p = pivot p ! ! pattern _⟨_⟩_ l p r = pivot p l r module _ {A : Set} {{_ : Ord A}} where Less : Rel A Less = PrfR (uncurry _<_) Bounded : Rel A Bounded = Less ∧ Less data Color : Set where red black : Color module _ (A : Set) {{_ : Ord A}} where data Tree′ (b : Bounds A) : Nat → Color → Set Tree : Nat → Color → Rel A Tree n c b = Tree′ b n c data Tree′ b where leaf′ : Less b → Tree 0 black b red : ∀ {n} → (Tree n black ∧ Tree n black) b → Tree n red b black : ∀ {c₁ c₂ n} → (Tree n c₁ ∧ Tree n c₂) b → Tree (suc n) black b pattern leaf = leaf′ ! data PreTree′ (b : Bounds A) (n : Nat) : Color → Set PreTree : Nat → Color → Bounds A → Set PreTree n c b = PreTree′ b n c data PreTree′ b n where red : ∀ {c₁ c₂} → (Tree n c₁ ∧ Tree n c₂) b → PreTree n red b maybe-black : ∀ {c} → Tree n c b → PreTree n black b pattern _b⟨_⟩_ l x r = black (l ⟨ x ⟩ r) pattern _r⟨_⟩_ l x r = red (l ⟨ x ⟩ r) pattern _pb⟨_⟩_ l x r = maybe-black (black (l ⟨ x ⟩ r)) pattern _pbr⟨_⟩_ l x r = maybe-black (red (l ⟨ x ⟩ r)) pattern _rbb⟨_⟩_ l x r = red {c₁ = black} {c₂ = black} (l ⟨ x ⟩ r) module _ {A : Set} {{_ : Ord A}} where balance-l : ∀ {b c₁ c₂ n} → (PreTree A n c₁ ∧ Tree A n c₂) b → PreTree A (suc n) black b balance-l (((l₁ r⟨ z ⟩ l₂) r⟨ x ⟩ l₃) ⟨ y ⟩ r) = (l₁ b⟨ z ⟩ l₂) pbr⟨ x ⟩ (l₃ b⟨ y ⟩ r) balance-l ((l₁ r⟨ z ⟩ (l₂ r⟨ x ⟩ l₃)) ⟨ y ⟩ r) = (l₁ b⟨ z ⟩ l₂) pbr⟨ x ⟩ (l₃ b⟨ y ⟩ r) balance-l ((l₁ rbb⟨ x ⟩ l₂) ⟨ y ⟩ r) = (l₁ r⟨ x ⟩ l₂) pb⟨ y ⟩ r balance-l (maybe-black l ⟨ y ⟩ r) = l pb⟨ y ⟩ r balance-r : ∀ {b c₁ c₂ n} → (Tree A n c₁ ∧ PreTree A n c₂) b → PreTree A (suc n) black b balance-r (l ⟨ y ⟩ ((r₁ r⟨ z ⟩ r₂) r⟨ x ⟩ r₃)) = (l b⟨ y ⟩ r₁) pbr⟨ z ⟩ (r₂ b⟨ x ⟩ r₃) balance-r (l ⟨ y ⟩ (r₁ r⟨ x ⟩ (r₂ r⟨ z ⟩ r₃))) = (l b⟨ y ⟩ r₁) pbr⟨ x ⟩ (r₂ b⟨ z ⟩ r₃) balance-r (l ⟨ y ⟩ (r₁ rbb⟨ x ⟩ r₂)) = l pb⟨ y ⟩ (r₁ r⟨ x ⟩ r₂) balance-r (l ⟨ y ⟩ maybe-black r) = l pb⟨ y ⟩ r ins : ∀ {b c n} → Bounded b → Tree A n c b → PreTree A n c b ins -⟨ x ⟩- leaf = leaf pbr⟨ x ⟩ leaf ins -⟨ x ⟩- (red (l ⟨ y ⟩ r)) = case compare! x y of λ where less → case ins -⟨ x ⟩- l of λ { (maybe-black l′) → l′ r⟨ y ⟩ r } greater → case ins -⟨ x ⟩- r of λ { (maybe-black r′) → l r⟨ y ⟩ r′ } equal → l r⟨ y ⟩ r ins -⟨ x ⟩- (black (l ⟨ y ⟩ r)) = case compare! x y of λ where less → balance-l (ins -⟨ x ⟩- l ⟨ y ⟩ r) greater → balance-r (l ⟨ y ⟩ ins -⟨ x ⟩- r) equal → l pb⟨ y ⟩ r data RedBlackTree (A : Set) {{_ : Ord A}} : Set where mkT : ∀ {n} → Tree A n black (-∞ , ∞) → RedBlackTree A module _ {A : Set} {{_ : Ord A}} where insert : A → RedBlackTree A → RedBlackTree A insert x (mkT t) with ins -⟨ x ⟩- t ... | l pbr⟨ y ⟩ r = mkT $ l b⟨ y ⟩ r ... | l pb⟨ y ⟩ r = mkT $ l b⟨ y ⟩ r ... | maybe-black leaf = mkT leaf fromList : List A → RedBlackTree A fromList = foldr insert (mkT leaf) toList′ : ∀ {b n c} → Tree′ A b n c → List A → List A toList′ (leaf′ _) xs = xs toList′ (l r⟨ x ⟩ r) xs = toList′ l (x ∷ toList′ r xs) toList′ (l b⟨ x ⟩ r) xs = toList′ l (x ∷ toList′ r xs) toList : RedBlackTree A → List A toList (mkT t) = toList′ t [] treeSort : List A → List A treeSort = toList ∘ fromList -- Example test : List Nat test = treeSort $ 5 ∷ 1 ∷ 2 ∷ 10 ∷ 13 ∷ 0 ∷ 141 ∷ 7 ∷ [] hest : String hest = show test main : IO Unit main = putStrLn hest
{ "alphanum_fraction": 0.5103896104, "avg_line_length": 29.9444444444, "ext": "agda", "hexsha": "9238894d1fc246acb0cc5a3842f1f5143e0d8edc", "lang": "Agda", "max_forks_count": 7, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:48.000Z", "max_forks_repo_forks_event_min_datetime": "2018-05-24T10:45:59.000Z", "max_forks_repo_head_hexsha": "e38b699870ba638221828b07b12948d70a1bdaec", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "agda/agda-ocaml", "max_forks_repo_path": "test/agda-ocaml/Golden/RedBlack.agda", "max_issues_count": 8, "max_issues_repo_head_hexsha": "e38b699870ba638221828b07b12948d70a1bdaec", "max_issues_repo_issues_event_max_datetime": "2018-11-05T21:28:57.000Z", "max_issues_repo_issues_event_min_datetime": "2017-03-29T13:37:52.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "agda/agda-ocaml", "max_issues_repo_path": "test/agda-ocaml/Golden/RedBlack.agda", "max_line_length": 80, "max_stars_count": 48, "max_stars_repo_head_hexsha": "e38b699870ba638221828b07b12948d70a1bdaec", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "agda/agda-ocaml", "max_stars_repo_path": "test/agda-ocaml/Golden/RedBlack.agda", "max_stars_repo_stars_event_max_datetime": "2021-08-15T09:08:14.000Z", "max_stars_repo_stars_event_min_datetime": "2017-03-29T14:19:31.000Z", "num_tokens": 2244, "size": 5390 }
-- Andreas, 2018-06-19, issue #3130 module Issue3130 where -- A pattern variable should not shadow a postfix projection -- in the same scope. module Shadow where record R : Set₁ where field y : Set → Set open R -- Should succeed or maybe complain about pattern variable y, -- but not about the postfix projection pattern. test : R test .y y = y -- Disambiguation module Parens where record R : Set₁ where field p : Set open R data D : (R → Set) → Set₁ where c : D p test : (f : R → Set) (x : D f) → Set₁ test .(p) c = Set
{ "alphanum_fraction": 0.6402116402, "avg_line_length": 17.1818181818, "ext": "agda", "hexsha": "f121c4aee68c5bdf003823fc0d24ea6d0e58ed0a", "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/Issue3130.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/Issue3130.agda", "max_line_length": 63, "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/Issue3130.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": 177, "size": 567 }