Search is not available for this dataset
text
string
meta
dict
------------------------------------------------------------------------ -- The Agda standard library -- -- Bounded vectors ------------------------------------------------------------------------ -- Vectors of a specified maximum length. {-# OPTIONS --without-K --safe #-} module Data.BoundedVec where open import Data.Nat open import Data.List.Base as List using (List) open import Data.Vec as Vec using (Vec) import Data.BoundedVec.Inefficient as Ineff open import Relation.Binary.PropositionalEquality open import Data.Nat.Solver open +-*-Solver ------------------------------------------------------------------------ -- The type abstract data BoundedVec {a} (A : Set a) : ℕ → Set a where bVec : ∀ {m n} (xs : Vec A n) → BoundedVec A (n + m) [] : ∀ {a n} {A : Set a} → BoundedVec A n [] = bVec Vec.[] infixr 5 _∷_ _∷_ : ∀ {a n} {A : Set a} → A → BoundedVec A n → BoundedVec A (suc n) x ∷ bVec xs = bVec (Vec._∷_ x xs) ------------------------------------------------------------------------ -- Pattern matching infixr 5 _∷v_ data View {a} (A : Set a) : ℕ → Set a where []v : ∀ {n} → View A n _∷v_ : ∀ {n} (x : A) (xs : BoundedVec A n) → View A (suc n) abstract view : ∀ {a n} {A : Set a} → BoundedVec A n → View A n view (bVec Vec.[]) = []v view (bVec (Vec._∷_ x xs)) = x ∷v bVec xs ------------------------------------------------------------------------ -- Increasing the bound abstract ↑ : ∀ {a n} {A : Set a} → BoundedVec A n → BoundedVec A (suc n) ↑ {A = A} (bVec {m = m} {n = n} xs) = subst (BoundedVec A) lemma (bVec {m = suc m} xs) where lemma : n + (1 + m) ≡ 1 + (n + m) lemma = solve 2 (λ m n → n :+ (con 1 :+ m) := con 1 :+ (n :+ m)) refl m n ------------------------------------------------------------------------ -- Conversions module _ {a} {A : Set a} where abstract fromList : (xs : List A) → BoundedVec A (List.length xs) fromList xs = subst (BoundedVec A) lemma (bVec {m = zero} (Vec.fromList xs)) where lemma : List.length xs + 0 ≡ List.length xs lemma = solve 1 (λ m → m :+ con 0 := m) refl _ toList : ∀ {n} → BoundedVec A n → List A toList (bVec xs) = Vec.toList xs toInefficient : ∀ {n} → BoundedVec A n → Ineff.BoundedVec A n toInefficient xs with view xs ... | []v = Ineff.[] ... | y ∷v ys = y Ineff.∷ toInefficient ys fromInefficient : ∀ {n} → Ineff.BoundedVec A n → BoundedVec A n fromInefficient Ineff.[] = [] fromInefficient (x Ineff.∷ xs) = x ∷ fromInefficient xs
{ "alphanum_fraction": 0.4738675958, "avg_line_length": 27.7741935484, "ext": "agda", "hexsha": "388ba72f60f4ef9fb0a00202415e8c0833769ada", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/BoundedVec.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/BoundedVec.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/BoundedVec.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 808, "size": 2583 }
primitive data D : Set where -- Bad error message WAS: -- A postulate block can only contain type signatures or instance blocks
{ "alphanum_fraction": 0.7557251908, "avg_line_length": 21.8333333333, "ext": "agda", "hexsha": "97da45ec6fbadda77d1af8f599cef322ee025e0f", "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/Issue1698-primitive.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/Issue1698-primitive.agda", "max_line_length": 72, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue1698-primitive.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": 29, "size": 131 }
-- Andreas, 2016-07-29 issue #707, comment of 2012-10-31 open import Common.Nat data Vec (A : Set) : Nat → Set where [] : Vec A zero _∷_ : ∀ {n} (x : A) (xs : Vec A n) → Vec A (suc n) v0 v1 v2 : Vec Nat _ v0 = [] v1 = 0 ∷ v0 v2 = 1 ∷ v1 -- Works, but maybe questionable. -- The _ is triplicated into three different internal metas.
{ "alphanum_fraction": 0.6070381232, "avg_line_length": 21.3125, "ext": "agda", "hexsha": "07a68b2f0fdf19f45af2a0de868faf6d907727a3", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue707-Vec.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue707-Vec.agda", "max_line_length": 60, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue707-Vec.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": 135, "size": 341 }
{-# OPTIONS --without-K --safe --no-universe-polymorphism --no-sized-types --no-guardedness --no-subtyping #-} module Agda.Builtin.Unit where record ⊤ : Set where instance constructor tt {-# BUILTIN UNIT ⊤ #-} {-# COMPILE GHC ⊤ = data () (()) #-}
{ "alphanum_fraction": 0.6174242424, "avg_line_length": 24, "ext": "agda", "hexsha": "08a07104f8762175efc3f31a61ee7055d2db8ecf", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-04-18T13:34:07.000Z", "max_forks_repo_forks_event_min_datetime": "2021-04-18T13:34:07.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/Unit.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2015-09-15T15:49:15.000Z", "max_issues_repo_issues_event_min_datetime": "2015-09-15T15:49:15.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/Unit.agda", "max_line_length": 64, "max_stars_count": 1, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/Unit.agda", "max_stars_repo_stars_event_max_datetime": "2016-05-20T13:58:52.000Z", "max_stars_repo_stars_event_min_datetime": "2016-05-20T13:58:52.000Z", "num_tokens": 69, "size": 264 }
{- The trivial resource -} module Relation.Ternary.Separation.Construct.Unit where open import Data.Unit open import Data.Product open import Relation.Unary open import Relation.Binary hiding (_⇒_) open import Relation.Binary.PropositionalEquality as P open import Relation.Ternary.Separation open RawSep instance unit-raw-sep : RawSep ⊤ _⊎_≣_ unit-raw-sep = λ _ _ _ → ⊤ instance unit-has-sep : IsSep unit-raw-sep unit-has-sep = record { ⊎-comm = λ _ → tt ; ⊎-assoc = λ _ _ → tt , tt , tt } instance unit-is-unital : IsUnitalSep _ _ unit-is-unital = record { isSep = unit-has-sep ; ⊎-idˡ = tt ; ⊎-id⁻ˡ = λ where tt → refl } instance unit-sep : Separation _ unit-sep = record { isSep = unit-has-sep }
{ "alphanum_fraction": 0.6998616874, "avg_line_length": 23.3225806452, "ext": "agda", "hexsha": "09d02c6ff6ce04fccadb85913e09b82286018ce1", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z", "max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z", "max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "laMudri/linear.agda", "max_forks_repo_path": "src/Relation/Ternary/Separation/Construct/Unit.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "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": "laMudri/linear.agda", "max_issues_repo_path": "src/Relation/Ternary/Separation/Construct/Unit.agda", "max_line_length": 55, "max_stars_count": 34, "max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "laMudri/linear.agda", "max_stars_repo_path": "src/Relation/Ternary/Separation/Construct/Unit.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z", "max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z", "num_tokens": 239, "size": 723 }
{-# OPTIONS --with-K #-} open import Axiom.Extensionality.Propositional using (Extensionality) open import Relation.Nullary.Negation using (contradiction) open import Relation.Binary using (Irrelevant) open import Relation.Binary.PropositionalEquality using (_≡_; _≢_) open import Relation.Binary.PropositionalEquality.WithK using (≡-erase) -- acursed and unmentionable -- turn back traveller module AKS.Unsafe where open import Relation.Binary.PropositionalEquality.TrustMe using (trustMe) public postulate TODO : ∀ {a} {A : Set a} → A BOTTOM : ∀ {a} {A : Set a} → A .irrelevance : ∀ {a} {A : Set a} -> .A -> A ≡-recomp : ∀ {a} {A : Set a} {x y : A} → .(x ≡ y) → x ≡ y fun-ext : ∀ {ℓ₁ ℓ₂} → Extensionality ℓ₁ ℓ₂ ≡-recomputable : ∀ {a} {A : Set a} {x y : A} → .(x ≡ y) → x ≡ y ≡-recomputable x≡y = ≡-erase (≡-recomp x≡y) ≢-irrelevant : ∀ {a} {A : Set a} → Irrelevant {A = A} _≢_ ≢-irrelevant {x} {y} [x≉y]₁ [x≉y]₂ = trustMe
{ "alphanum_fraction": 0.6521276596, "avg_line_length": 34.8148148148, "ext": "agda", "hexsha": "c51e0156c7be482697f590c2a0db2d98b37f0ae6", "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": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mckeankylej/thesis", "max_forks_repo_path": "proofs/AKS/Unsafe.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "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": "mckeankylej/thesis", "max_issues_repo_path": "proofs/AKS/Unsafe.agda", "max_line_length": 80, "max_stars_count": 1, "max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mckeankylej/thesis", "max_stars_repo_path": "proofs/AKS/Unsafe.agda", "max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z", "max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z", "num_tokens": 353, "size": 940 }
module _ where module A where postulate !_ : Set₂ → Set₃ infix 1 !_ module B where postulate !_ : Set₀ → Set₁ infix 3 !_ open A open B postulate #_ : Set₁ → Set₂ infix 2 #_ ok₁ : Set₁ → Set₃ ok₁ X = ! # X ok₂ : Set₀ → Set₂ ok₂ X = # ! X
{ "alphanum_fraction": 0.4526627219, "avg_line_length": 11.2666666667, "ext": "agda", "hexsha": "c351d9a89b7bd6ccb6ba53a32e7cf942e02b248e", "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/Issue1436-14.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/Issue1436-14.agda", "max_line_length": 24, "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/Issue1436-14.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": 121, "size": 338 }
module foldl where import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; sym; trans; cong) open Eq.≡-Reasoning open import lists using (List; []; _∷_; [_,_,_]) foldl : ∀ {A B : Set} → (B → A → B) → B → List A → B foldl _⊗_ e [] = e foldl _⊗_ e (x ∷ xs) = foldl _⊗_ (e ⊗ x) xs test-foldl : ∀ {A B : Set} → (_⊗_ : B → A → B) → (e : B) → (x y z : A) → foldl _⊗_ e [ x , y , z ] ≡ ((e ⊗ x) ⊗ y) ⊗ z test-foldl _⊗_ e x y z = refl
{ "alphanum_fraction": 0.5304347826, "avg_line_length": 28.75, "ext": "agda", "hexsha": "62658bed86df99bfffa5a1b82a5a5e8a2bea0d1b", "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": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "akiomik/plfa-solutions", "max_forks_repo_path": "part1/lists/foldl.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547", "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": "akiomik/plfa-solutions", "max_issues_repo_path": "part1/lists/foldl.agda", "max_line_length": 70, "max_stars_count": 1, "max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "akiomik/plfa-solutions", "max_stars_repo_path": "part1/lists/foldl.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z", "num_tokens": 211, "size": 460 }
------------------------------------------------------------------------ -- The Agda standard library -- -- The extensional sublist relation over setoid equality. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Data.List.Relation.Binary.Subset.Setoid {c ℓ} (S : Setoid c ℓ) where open import Data.List using (List) open import Data.List.Membership.Setoid S using (_∈_) open import Level using (_⊔_) open import Relation.Nullary using (¬_) open Setoid S renaming (Carrier to A) ------------------------------------------------------------------------ -- Definitions infix 4 _⊆_ _⊈_ _⊆_ : Rel (List A) (c ⊔ ℓ) xs ⊆ ys = ∀ {x} → x ∈ xs → x ∈ ys _⊈_ : Rel (List A) (c ⊔ ℓ) xs ⊈ ys = ¬ xs ⊆ ys
{ "alphanum_fraction": 0.4817610063, "avg_line_length": 25.6451612903, "ext": "agda", "hexsha": "9e2b5c2cd3ece4d6f50d9102723e61aae610a6a0", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "omega12345/agda-mode", "max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Subset/Setoid.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/Relation/Binary/Subset/Setoid.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "omega12345/agda-mode", "max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Subset/Setoid.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 199, "size": 795 }
open import MJ.Types import MJ.Classtable.Core as Core import MJ.Classtable.Code as Code import MJ.Syntax as Syntax module MJ.Semantics.Objects.Flat {c}(Ct : Core.Classtable c)(ℂ : Code.Code Ct) where open import Prelude open import Level renaming (suc to lsuc; zero to lzero) open import Data.Vec hiding (_++_; lookup; drop) open import Data.Star open import Data.List open import Data.List.First.Properties open import Data.List.Membership.Propositional open import Data.List.Any.Properties open import Data.List.All as All open import Data.List.All.Properties.Extra open import Data.List.Prefix open import Data.List.Properties.Extra open import Data.Maybe as Maybe open import Data.Maybe.Relation.Unary.All as MayAll using () open import Data.String using (String) open import Relation.Binary.PropositionalEquality open import MJ.Semantics.Values Ct open import MJ.Semantics.Objects Ct open import MJ.Syntax Ct open Code Ct open Core c open Classtable Ct open import MJ.Classtable.Membership Ct private collect : ∀ {cid}(chain : Σ ⊢ cid <: Object) ns → List (String × typing ns) collect (super {cid} ◅ ch) ns = Class.decls (Σ (cls cid)) ns ++ collect ch ns collect ε ns = Class.decls (Σ Object) ns {- We define collect members by delegation to collection of members over a particular inheritance chain. This makes the definition structurally recursive and is sound by the fact that inheritance chains are unique. -} collect-members : ∀ cid ns → List (String × typing ns) collect-members cid ns = collect (rooted cid) ns {- An Object is then simply represented by a list of values for all it's members. -} Obj : (World c) → (cid : _) → Set Obj W cid = All (λ d → Val W (proj₂ d)) (collect-members cid FIELD) weaken-obj : ∀ {W W'} cid → W' ⊒ W → Obj W cid → Obj W' cid weaken-obj cid ext O = All.map (weaken-val ext) O {- We can relate the flat Object structure with the hierarchical notion of membership through the definition of `collect`. This allows us to get and set members on Objects. -} {-# TERMINATING #-} getter : ∀ {W n a} cid → Obj W cid → IsMember cid FIELD n a → Val W a getter cid O q with rooted cid getter .Object O (.Object , ε , def) | ε = ∈-all (proj₁ (first⟶∈ def)) O getter .Object O (_ , () ◅ _ , _) | ε getter ._ O (._ , ε , def) | super {cid} ◅ z with split-++ (Class.decls (Σ (cls _)) FIELD) _ O ... | own , inherited = ∈-all (proj₁ (first⟶∈ def)) own getter ._ O (pid , super {cid} ◅ s , def) | super ◅ z with split-++ (Class.decls (Σ (cls _)) FIELD) _ O ... | own , inherited rewrite <:-unique z (rooted (Class.parent (Σ (cls cid)))) = getter _ inherited (pid , s , def) {-# TERMINATING #-} setter : ∀ {W f a} cid → Obj W cid → IsMember cid FIELD f a → Val W a → Obj W cid setter (cls cid) O q v with rooted (cls cid) setter (cls cid) O (._ , ε , def) v | super ◅ z with split-++ (Class.decls (Σ (cls _)) FIELD) _ O ... | own , inherited = (own All.[ proj₁ (first⟶∈ def) ]≔ v) ++-all inherited setter (cls cid) O (._ , super ◅ s , def) v | super ◅ z with split-++ (Class.decls (Σ (cls _)) FIELD) _ O ... | own , inherited rewrite <:-unique z (rooted (Class.parent (Σ (cls cid)))) = own ++-all setter _ inherited (_ , s , def) v setter Object O mem v = ⊥-elim (∉Object mem) {- A default object instance can be created for every class simply by tabulating `default` over the types of all fields of a class. -} defaultObject' : ∀ {W cid} → (ch : Σ ⊢ cid <: Object) → All (λ d → Val W (proj₂ d)) (collect ch FIELD) defaultObject' ε rewrite Σ-Object = [] defaultObject' {cid = Object} (() ◅ _) defaultObject' {cid = cls x} (super ◅ z) = All.tabulate {xs = Class.decls (Σ (cls x)) FIELD} (λ{ {_ , ty} _ → default ty}) ++-all defaultObject' z {- We collect these definitions under the abstract ObjEncoding interface for usage in the semantics -} encoding : ObjEncoding encoding = record { Obj = Obj ; weaken-obj = λ cid ext O → weaken-obj cid ext O ; getter = getter ; setter = setter ; defaultObject = λ cid → defaultObject' (rooted cid) }
{ "alphanum_fraction": 0.6661012842, "avg_line_length": 37.5181818182, "ext": "agda", "hexsha": "ee0594d534a86911997ca83507399be422f6737a", "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/MJ/Semantics/Objects/Flat.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/MJ/Semantics/Objects/Flat.agda", "max_line_length": 107, "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/MJ/Semantics/Objects/Flat.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": 1232, "size": 4127 }
-- Andreas, 2020-05-01, issue #4631 -- -- We should not allow @-patterns to shadow constructors! open import Agda.Builtin.Bool test : Set → Set test true@_ = true -- WAS: succees -- EXPECTED: -- -- Bool !=< Set -- when checking that the expression true has type Set -- -- ———— Warning(s) ———————————————————————————————————————————— -- Name bound in @-pattern ignored because it shadows constructor -- when scope checking the left-hand side test true@A in the -- definition of test
{ "alphanum_fraction": 0.6296296296, "avg_line_length": 23.1428571429, "ext": "agda", "hexsha": "9a3f4af52680adc29da1e16dcbf780108b74bcda", "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/Fail/Issue4631AsPatternShadowsConstructor.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/Issue4631AsPatternShadowsConstructor.agda", "max_line_length": 65, "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/Issue4631AsPatternShadowsConstructor.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": 127, "size": 486 }
------------------------------------------------------------------------------ -- Propositional equality on inductive PA ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- This file contains some definitions which are reexported by -- PA.Inductive.Base. module PA.Inductive.Relation.Binary.PropositionalEquality where open import Common.FOL.FOL using ( ¬_ ) open import PA.Inductive.Base.Core infix 4 _≡_ _≢_ ------------------------------------------------------------------------------ -- The identity type on PA. data _≡_ (x : ℕ) : ℕ → Set where refl : x ≡ x -- Inequality. _≢_ : ℕ → ℕ → Set x ≢ y = ¬ x ≡ y {-# ATP definition _≢_ #-} -- Identity properties sym : ∀ {x y} → x ≡ y → y ≡ x sym refl = refl trans : ∀ {x y z} → x ≡ y → y ≡ z → x ≡ z trans refl h = h subst : (A : ℕ → Set) → ∀ {x y} → x ≡ y → A x → A y subst A refl Ax = Ax cong : (f : ℕ → ℕ) → ∀ {x y} → x ≡ y → f x ≡ f y cong f refl = refl cong₂ : (f : ℕ → ℕ → ℕ) → ∀ {x x' y y'} → x ≡ y → x' ≡ y' → f x x' ≡ f y y' cong₂ f refl refl = refl
{ "alphanum_fraction": 0.4453507341, "avg_line_length": 26.652173913, "ext": "agda", "hexsha": "39529018339db884ed4bb6615840b16f8a3642a8", "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/PA/Inductive/Relation/Binary/PropositionalEquality.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/PA/Inductive/Relation/Binary/PropositionalEquality.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/PA/Inductive/Relation/Binary/PropositionalEquality.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": 360, "size": 1226 }
{-# OPTIONS --without-K #-} open import lib.Basics module lib.types.Sigma where -- Cartesian product _×_ : ∀ {i j} (A : Type i) (B : Type j) → Type (lmax i j) A × B = Σ A (λ _ → B) infixr 5 _×_ module _ {i j} {A : Type i} {B : A → Type j} where pair : (a : A) (b : B a) → Σ A B pair a b = (a , b) -- pair= has already been defined fst= : {ab a'b' : Σ A B} (p : ab == a'b') → (fst ab == fst a'b') fst= = ap fst snd= : {ab a'b' : Σ A B} (p : ab == a'b') → (snd ab == snd a'b' [ B ↓ fst= p ]) snd= {._} {_} idp = idp fst=-β : {a a' : A} (p : a == a') {b : B a} {b' : B a'} (q : b == b' [ B ↓ p ]) → fst= (pair= p q) == p fst=-β idp idp = idp snd=-β : {a a' : A} (p : a == a') {b : B a} {b' : B a'} (q : b == b' [ B ↓ p ]) → snd= (pair= p q) == q [ (λ v → b == b' [ B ↓ v ]) ↓ fst=-β p q ] snd=-β idp idp = idp pair=-η : {ab a'b' : Σ A B} (p : ab == a'b') → p == pair= (fst= p) (snd= p) pair=-η {._} {_} idp = idp pair== : {a a' : A} {p p' : a == a'} (α : p == p') {b : B a} {b' : B a'} {q : b == b' [ B ↓ p ]} {q' : b == b' [ B ↓ p' ]} (β : q == q' [ (λ u → b == b' [ B ↓ u ]) ↓ α ]) → pair= p q == pair= p' q' pair== idp idp = idp module _ {i j} {A : Type i} {B : Type j} where fst×= : {ab a'b' : A × B} (p : ab == a'b') → (fst ab == fst a'b') fst×= = ap fst snd×= : {ab a'b' : A × B} (p : ab == a'b') → (snd ab == snd a'b') snd×= = ap snd fst×=-β : {a a' : A} (p : a == a') {b b' : B} (q : b == b') → fst×= (pair×= p q) == p fst×=-β idp idp = idp snd×=-β : {a a' : A} (p : a == a') {b b' : B} (q : b == b') → snd×= (pair×= p q) == q snd×=-β idp idp = idp pair×=-η : {ab a'b' : A × B} (p : ab == a'b') → p == pair×= (fst×= p) (snd×= p) pair×=-η {._} {_} idp = idp module _ {i j} {A : Type i} {B : A → Type j} where =Σ : (x y : Σ A B) → Type (lmax i j) =Σ (a , b) (a' , b') = Σ (a == a') (λ p → b == b' [ B ↓ p ]) =Σ-eqv : (x y : Σ A B) → (=Σ x y) ≃ (x == y) =Σ-eqv x y = equiv (λ pq → pair= (fst pq) (snd pq)) (λ p → fst= p , snd= p) (λ p → ! (pair=-η p)) (λ pq → pair= (fst=-β (fst pq) (snd pq)) (snd=-β (fst pq) (snd pq))) =Σ-path : (x y : Σ A B) → (=Σ x y) == (x == y) =Σ-path x y = ua (=Σ-eqv x y) Σ= : ∀ {i j} {A A' : Type i} (p : A == A') {B : A → Type j} {B' : A' → Type j} (q : B == B' [ (λ X → (X → Type j)) ↓ p ]) → Σ A B == Σ A' B' Σ= idp idp = idp abstract Σ-level : ∀ {i j} {n : ℕ₋₂} {A : Type i} {P : A → Type j} → (has-level n A → ((x : A) → has-level n (P x)) → has-level n (Σ A P)) Σ-level {n = ⟨-2⟩} p q = ((fst p , (fst (q (fst p)))) , (λ y → pair= (snd p _) (from-transp! _ _ (snd (q _) _)))) Σ-level {n = S n} p q = λ x y → equiv-preserves-level (=Σ-eqv x y) (Σ-level (p _ _) (λ _ → equiv-preserves-level ((to-transp-equiv _ _)⁻¹) (q _ _ _))) ×-level : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} → (has-level n A → has-level n B → has-level n (A × B)) ×-level pA pB = Σ-level pA (λ x → pB) -- Equivalences in a Σ-type equiv-Σ-fst : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k) {h : A → B} → is-equiv h → (Σ A (P ∘ h)) ≃ (Σ B P) equiv-Σ-fst {A = A} {B = B} P {h = h} e = equiv f g f-g g-f where f : Σ A (P ∘ h) → Σ B P f (a , r) = (h a , r) g : Σ B P → Σ A (P ∘ h) g (b , s) = (is-equiv.g e b , transport P (! (is-equiv.f-g e b)) s) f-g : ∀ y → f (g y) == y f-g (b , s) = pair= (is-equiv.f-g e b) (trans-↓ P (is-equiv.f-g e b) s) g-f : ∀ x → g (f x) == x g-f (a , r) = pair= (is-equiv.g-f e a) (transport (λ q → transport P (! q) r == r [ P ∘ h ↓ is-equiv.g-f e a ]) (is-equiv.adj e a) (trans-ap-↓ P h (is-equiv.g-f e a) r) ) equiv-Σ-snd : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} → (∀ x → B x ≃ C x) → Σ A B ≃ Σ A C equiv-Σ-snd {A = A} {B = B} {C = C} k = equiv f g f-g g-f where f : Σ A B → Σ A C f (a , b) = (a , fst (k a) b) g : Σ A C → Σ A B g (a , c) = (a , is-equiv.g (snd (k a)) c) f-g : ∀ p → f (g p) == p f-g (a , c) = pair= idp (is-equiv.f-g (snd (k a)) c) g-f : ∀ p → g (f p) == p g-f (a , b) = pair= idp (is-equiv.g-f (snd (k a)) b) -- Two ways of simultaneously applying equivalences in each component. module _ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : A₀ → Type j₀} {B₁ : A₁ → Type j₁} where equiv-Σ : (u : A₀ ≃ A₁) (v : ∀ a → B₀ (<– u a) ≃ B₁ a) → Σ A₀ B₀ ≃ Σ A₁ B₁ equiv-Σ u v = Σ A₀ B₀ ≃⟨ equiv-Σ-fst _ (snd (u ⁻¹)) ⁻¹ ⟩ Σ A₁ (B₀ ∘ <– u) ≃⟨ equiv-Σ-snd v ⟩ Σ A₁ B₁ ≃∎ equiv-Σ' : (u : A₀ ≃ A₁) (v : ∀ a → B₀ a ≃ B₁ (–> u a)) → Σ A₀ B₀ ≃ Σ A₁ B₁ equiv-Σ' u v = Σ A₀ B₀ ≃⟨ equiv-Σ-snd v ⟩ Σ A₀ (B₁ ∘ –> u) ≃⟨ equiv-Σ-fst _ (snd u) ⟩ Σ A₁ B₁ ≃∎ -- Implementation of [_∙'_] on Σ Σ-∙' : ∀ {i j} {A : Type i} {B : A → Type j} {x y z : A} {p : x == y} {p' : y == z} {u : B x} {v : B y} {w : B z} (q : u == v [ B ↓ p ]) (r : v == w [ B ↓ p' ]) → (pair= p q ∙' pair= p' r) == pair= (p ∙' p') (q ∙'ᵈ r) Σ-∙' {p = idp} {p' = idp} q idp = idp -- Implementation of [_∙_] on Σ Σ-∙ : ∀ {i j} {A : Type i} {B : A → Type j} {x y z : A} {p : x == y} {p' : y == z} {u : B x} {v : B y} {w : B z} (q : u == v [ B ↓ p ]) (r : v == w [ B ↓ p' ]) → (pair= p q ∙ pair= p' r) == pair= (p ∙ p') (q ∙ᵈ r) Σ-∙ {p = idp} {p' = idp} idp r = idp -- Implementation of [!] on Σ Σ-! : ∀ {i j} {A : Type i} {B : A → Type j} {x y : A} {p : x == y} {u : B x} {v : B y} (q : u == v [ B ↓ p ]) → ! (pair= p q) == pair= (! p) (!ᵈ q) Σ-! {p = idp} idp = idp -- Implementation of [_∙'_] on × ×-∙' : ∀ {i j} {A : Type i} {B : Type j} {x y z : A} (p : x == y) (p' : y == z) {u v w : B} (q : u == v) (q' : v == w) → (pair×= p q ∙' pair×= p' q') == pair×= (p ∙' p') (q ∙' q') ×-∙' idp idp q idp = idp -- Implementation of [_∙_] on × ×-∙ : ∀ {i j} {A : Type i} {B : Type j} {x y z : A} (p : x == y) (p' : y == z) {u v w : B} (q : u == v) (q' : v == w) → (pair×= p q ∙ pair×= p' q') == pair×= (p ∙ p') (q ∙ q') ×-∙ idp idp idp r = idp -- Implementation of [!] on × ×-! : ∀ {i j} {A : Type i} {B : Type j} {x y : A} (p : x == y) {u v : B} (q : u == v) → ! (pair×= p q) == pair×= (! p) (! q) ×-! idp idp = idp -- Special case of [ap-,] ap-cst,id : ∀ {i j} {A : Type i} (B : A → Type j) {a : A} {x y : B a} (p : x == y) → ap (λ x → _,_ {B = B} a x) p == pair= idp p ap-cst,id B idp = idp -- hfiber fst == B module _ {i j} {A : Type i} {B : A → Type j} where private to : ∀ a → hfiber (fst :> (Σ A B → A)) a → B a to a ((.a , b) , idp) = b from : ∀ (a : A) → B a → hfiber (fst :> (Σ A B → A)) a from a b = (a , b) , idp to-from : ∀ (a : A) (b : B a) → to a (from a b) == b to-from a b = idp from-to : ∀ a b′ → from a (to a b′) == b′ from-to a ((.a , b) , idp) = idp hfiber-fst : ∀ a → hfiber (fst :> (Σ A B → A)) a ≃ B a hfiber-fst a = to a , is-eq (to a) (from a) (to-from a) (from-to a) {- Dependent paths in a Σ-type -} module _ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k} where ↓-Σ-in : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : C x r} {s' : C x' r'} (q : r == r' [ B ↓ p ]) → s == s' [ uncurry C ↓ pair= p q ] → (r , s) == (r' , s') [ (λ x → Σ (B x) (C x)) ↓ p ] ↓-Σ-in {p = idp} idp t = pair= idp t ↓-Σ-fst : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : C x r} {s' : C x' r'} → (r , s) == (r' , s') [ (λ x → Σ (B x) (C x)) ↓ p ] → r == r' [ B ↓ p ] ↓-Σ-fst {p = idp} u = fst= u ↓-Σ-snd : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : C x r} {s' : C x' r'} → (u : (r , s) == (r' , s') [ (λ x → Σ (B x) (C x)) ↓ p ]) → s == s' [ uncurry C ↓ pair= p (↓-Σ-fst u) ] ↓-Σ-snd {p = idp} idp = idp ↓-Σ-β-fst : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : C x r} {s' : C x' r'} (q : r == r' [ B ↓ p ]) (t : s == s' [ uncurry C ↓ pair= p q ]) → ↓-Σ-fst (↓-Σ-in q t) == q ↓-Σ-β-fst {p = idp} idp idp = idp ↓-Σ-β-snd : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : C x r} {s' : C x' r'} (q : r == r' [ B ↓ p ]) (t : s == s' [ uncurry C ↓ pair= p q ]) → ↓-Σ-snd (↓-Σ-in q t) == t [ (λ q' → s == s' [ uncurry C ↓ pair= p q' ]) ↓ ↓-Σ-β-fst q t ] ↓-Σ-β-snd {p = idp} idp idp = idp ↓-Σ-η : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : C x r} {s' : C x' r'} (u : (r , s) == (r' , s') [ (λ x → Σ (B x) (C x)) ↓ p ]) → ↓-Σ-in (↓-Σ-fst u) (↓-Σ-snd u) == u ↓-Σ-η {p = idp} idp = idp {- Dependent paths in a ×-type -} module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} where ↓-×-in : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : C x} {s' : C x'} → r == r' [ B ↓ p ] → s == s' [ C ↓ p ] → (r , s) == (r' , s') [ (λ x → B x × C x) ↓ p ] ↓-×-in {p = idp} q t = pair×= q t module _ where -- An orphan lemma. ↓-cst×app-in : ∀ {i j k} {A : Type i} {B : Type j} {C : A → B → Type k} {a₁ a₂ : A} (p : a₁ == a₂) {b₁ b₂ : B} (q : b₁ == b₂) {c₁ : C a₁ b₁}{c₂ : C a₂ b₂} → c₁ == c₂ [ uncurry C ↓ pair×= p q ] → (b₁ , c₁) == (b₂ , c₂) [ (λ x → Σ B (C x)) ↓ p ] ↓-cst×app-in idp idp idp = idp {- pair= and pair×= where one argument is reflexivity -} pair=-idp-l : ∀ {i j} {A : Type i} {B : A → Type j} (a : A) {b₁ b₂ : B a} (q : b₁ == b₂) → pair= {B = B} idp q == ap (λ y → (a , y)) q pair=-idp-l _ idp = idp pair×=-idp-l : ∀ {i j} {A : Type i} {B : Type j} (a : A) {b₁ b₂ : B} (q : b₁ == b₂) → pair×= idp q == ap (λ y → (a , y)) q pair×=-idp-l _ idp = idp pair×=-idp-r : ∀ {i j} {A : Type i} {B : Type j} {a₁ a₂ : A} (p : a₁ == a₂) (b : B) → pair×= p idp == ap (λ x → (x , b)) p pair×=-idp-r idp _ = idp pair×=-split-l : ∀ {i j} {A : Type i} {B : Type j} {a₁ a₂ : A} (p : a₁ == a₂) {b₁ b₂ : B} (q : b₁ == b₂) → pair×= p q == ap (λ a → (a , b₁)) p ∙ ap (λ b → (a₂ , b)) q pair×=-split-l idp idp = idp pair×=-split-r : ∀ {i j} {A : Type i} {B : Type j} {a₁ a₂ : A} (p : a₁ == a₂) {b₁ b₂ : B} (q : b₁ == b₂) → pair×= p q == ap (λ b → (a₁ , b)) q ∙ ap (λ a → (a , b₂)) p pair×=-split-r idp idp = idp -- Commutativity of products and derivatives. module _ {i j} {A : Type i} {B : Type j} where ×-comm : Σ A (λ _ → B) ≃ Σ B (λ _ → A) ×-comm = equiv (λ {(a , b) → (b , a)}) (λ {(b , a) → (a , b)}) (λ _ → idp) (λ _ → idp) module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} where Σ₂-×-comm : Σ (Σ A B) (λ ab → C (fst ab)) ≃ Σ (Σ A C) (λ ac → B (fst ac)) Σ₂-×-comm = Σ-assoc ⁻¹ ∘e equiv-Σ-snd (λ a → ×-comm) ∘e Σ-assoc module _ {i j k} {A : Type i} {B : Type j} {C : A → B → Type k} where Σ₁-×-comm : Σ A (λ a → Σ B (λ b → C a b)) ≃ Σ B (λ b → Σ A (λ a → C a b)) Σ₁-×-comm = Σ-assoc ∘e equiv-Σ-fst _ (snd ×-comm) ∘e Σ-assoc ⁻¹
{ "alphanum_fraction": 0.3865041833, "avg_line_length": 33.9382716049, "ext": "agda", "hexsha": "54d715be3fe2f8c2e2f058ada8a4737c9a0e0e34", "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": "lib/types/Sigma.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": "lib/types/Sigma.agda", "max_line_length": 88, "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": "lib/types/Sigma.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 5430, "size": 10996 }
{-# OPTIONS --without-K --exact-split --safe #-} module 06-universes where import 05-identity-types open 05-identity-types public -------------------------------------------------------------------------------- -- Section 6.3 Observational equality on the natural numbers -- Definition 6.3.1 Eq-ℕ : ℕ → ℕ → UU lzero Eq-ℕ zero-ℕ zero-ℕ = 𝟙 Eq-ℕ zero-ℕ (succ-ℕ n) = 𝟘 Eq-ℕ (succ-ℕ m) zero-ℕ = 𝟘 Eq-ℕ (succ-ℕ m) (succ-ℕ n) = Eq-ℕ m n -- Lemma 6.3.2 refl-Eq-ℕ : (n : ℕ) → Eq-ℕ n n refl-Eq-ℕ zero-ℕ = star refl-Eq-ℕ (succ-ℕ n) = refl-Eq-ℕ n -- Proposition 6.3.3 Eq-ℕ-eq : {x y : ℕ} → Id x y → Eq-ℕ x y Eq-ℕ-eq {x} {.x} refl = refl-Eq-ℕ x eq-Eq-ℕ : (x y : ℕ) → Eq-ℕ x y → Id x y eq-Eq-ℕ zero-ℕ zero-ℕ e = refl eq-Eq-ℕ (succ-ℕ x) (succ-ℕ y) e = ap succ-ℕ (eq-Eq-ℕ x y e) -------------------------------------------------------------------------------- -- Section 6.4 Peano's seventh and eighth axioms -- Theorem 6.4.1 is-injective-succ-ℕ : (x y : ℕ) → Id (succ-ℕ x) (succ-ℕ y) → Id x y is-injective-succ-ℕ x y e = eq-Eq-ℕ x y (Eq-ℕ-eq e) Peano-7 : (x y : ℕ) → ((Id x y) → (Id (succ-ℕ x) (succ-ℕ y))) × ((Id (succ-ℕ x) (succ-ℕ y)) → (Id x y)) Peano-7 x y = pair (ap succ-ℕ) (is-injective-succ-ℕ x y) -- Theorem 6.4.2 Peano-8 : (x : ℕ) → ¬ (Id zero-ℕ (succ-ℕ x)) Peano-8 x p = Eq-ℕ-eq p -------------------------------------------------------------------------------- -- Exercises -- Exercise 6.1 -- Exercise 6.1 (a) is-injective-add-ℕ : (k m n : ℕ) → Id (add-ℕ m k) (add-ℕ n k) → Id m n is-injective-add-ℕ zero-ℕ m n = id is-injective-add-ℕ (succ-ℕ k) m n p = is-injective-add-ℕ k m n (is-injective-succ-ℕ (add-ℕ m k) (add-ℕ n k) p) -- Exercise 6.1 (b) is-injective-mul-ℕ : (k m n : ℕ) → Id (mul-ℕ m (succ-ℕ k)) (mul-ℕ n (succ-ℕ k)) → Id m n is-injective-mul-ℕ k zero-ℕ zero-ℕ p = refl is-injective-mul-ℕ k (succ-ℕ m) (succ-ℕ n) p = ap succ-ℕ ( is-injective-mul-ℕ k m n ( is-injective-add-ℕ ( succ-ℕ k) ( mul-ℕ m (succ-ℕ k)) ( mul-ℕ n (succ-ℕ k)) ( ( inv (left-successor-law-mul-ℕ m (succ-ℕ k))) ∙ ( ( p) ∙ ( left-successor-law-mul-ℕ n (succ-ℕ k)))))) -- Exercise 6.1 (c) neq-add-ℕ : (m n : ℕ) → ¬ (Id m (add-ℕ m (succ-ℕ n))) neq-add-ℕ (succ-ℕ m) n p = neq-add-ℕ m n ( ( is-injective-succ-ℕ m (add-ℕ (succ-ℕ m) n) p) ∙ ( left-successor-law-add-ℕ m n)) -- Exercise 6.1 (d) neq-mul-ℕ : (m n : ℕ) → ¬ (Id (succ-ℕ m) (mul-ℕ (succ-ℕ m) (succ-ℕ (succ-ℕ n)))) neq-mul-ℕ m n p = neq-add-ℕ ( succ-ℕ m) ( add-ℕ (mul-ℕ m (succ-ℕ n)) n) ( ( p) ∙ ( ( right-successor-law-mul-ℕ (succ-ℕ m) (succ-ℕ n)) ∙ ( ap (add-ℕ (succ-ℕ m)) (left-successor-law-mul-ℕ m (succ-ℕ n))))) -- Exercise 6.2 -- Exercise 6.2 (a) Eq-𝟚 : bool → bool → UU lzero Eq-𝟚 true true = unit Eq-𝟚 true false = empty Eq-𝟚 false true = empty Eq-𝟚 false false = unit -- Exercise 6.2 (b) reflexive-Eq-𝟚 : (x : bool) → Eq-𝟚 x x reflexive-Eq-𝟚 true = star reflexive-Eq-𝟚 false = star Eq-eq-𝟚 : {x y : bool} → Id x y → Eq-𝟚 x y Eq-eq-𝟚 {x = x} refl = reflexive-Eq-𝟚 x eq-Eq-𝟚 : {x y : bool} → Eq-𝟚 x y → Id x y eq-Eq-𝟚 {true} {true} star = refl eq-Eq-𝟚 {false} {false} star = refl -- Exercise 6.2 (c) neq-neg-𝟚 : (b : bool) → ¬ (Id b (neg-𝟚 b)) neq-neg-𝟚 true = Eq-eq-𝟚 neq-neg-𝟚 false = Eq-eq-𝟚 neq-false-true-𝟚 : ¬ (Id false true) neq-false-true-𝟚 = Eq-eq-𝟚 -- Exercise 6.3 -- Exercise 6.3 (a) leq-ℕ : ℕ → ℕ → UU lzero leq-ℕ zero-ℕ m = unit leq-ℕ (succ-ℕ n) zero-ℕ = empty leq-ℕ (succ-ℕ n) (succ-ℕ m) = leq-ℕ n m _≤_ = leq-ℕ -- Some trivialities that will be useful later leq-zero-ℕ : (n : ℕ) → leq-ℕ zero-ℕ n leq-zero-ℕ n = star eq-leq-zero-ℕ : (x : ℕ) → leq-ℕ x zero-ℕ → Id zero-ℕ x eq-leq-zero-ℕ zero-ℕ star = refl succ-leq-ℕ : (n : ℕ) → leq-ℕ n (succ-ℕ n) succ-leq-ℕ zero-ℕ = star succ-leq-ℕ (succ-ℕ n) = succ-leq-ℕ n concatenate-eq-leq-eq-ℕ : {x1 x2 x3 x4 : ℕ} → Id x1 x2 → leq-ℕ x2 x3 → Id x3 x4 → leq-ℕ x1 x4 concatenate-eq-leq-eq-ℕ refl H refl = H concatenate-leq-eq-ℕ : (m : ℕ) {n n' : ℕ} → leq-ℕ m n → Id n n' → leq-ℕ m n' concatenate-leq-eq-ℕ m H refl = H concatenate-eq-leq-ℕ : {m m' : ℕ} (n : ℕ) → Id m' m → leq-ℕ m n → leq-ℕ m' n concatenate-eq-leq-ℕ n refl H = H -- Exercise 6.3 (b) reflexive-leq-ℕ : (n : ℕ) → leq-ℕ n n reflexive-leq-ℕ zero-ℕ = star reflexive-leq-ℕ (succ-ℕ n) = reflexive-leq-ℕ n leq-eq-ℕ : (m n : ℕ) → Id m n → leq-ℕ m n leq-eq-ℕ m .m refl = reflexive-leq-ℕ m transitive-leq-ℕ : (n m l : ℕ) → (n ≤ m) → (m ≤ l) → (n ≤ l) transitive-leq-ℕ zero-ℕ m l p q = star transitive-leq-ℕ (succ-ℕ n) (succ-ℕ m) (succ-ℕ l) p q = transitive-leq-ℕ n m l p q preserves-leq-succ-ℕ : (m n : ℕ) → leq-ℕ m n → leq-ℕ m (succ-ℕ n) preserves-leq-succ-ℕ m n p = transitive-leq-ℕ m n (succ-ℕ n) p (succ-leq-ℕ n) anti-symmetric-leq-ℕ : (m n : ℕ) → leq-ℕ m n → leq-ℕ n m → Id m n anti-symmetric-leq-ℕ zero-ℕ zero-ℕ p q = refl anti-symmetric-leq-ℕ (succ-ℕ m) (succ-ℕ n) p q = ap succ-ℕ (anti-symmetric-leq-ℕ m n p q) -- Exercise 6.3 (c) decide-leq-ℕ : (m n : ℕ) → coprod (leq-ℕ m n) (leq-ℕ n m) decide-leq-ℕ zero-ℕ zero-ℕ = inl star decide-leq-ℕ zero-ℕ (succ-ℕ n) = inl star decide-leq-ℕ (succ-ℕ m) zero-ℕ = inr star decide-leq-ℕ (succ-ℕ m) (succ-ℕ n) = decide-leq-ℕ m n -- Exercise 6.3 (d) preserves-order-add-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (add-ℕ m k) (add-ℕ n k) preserves-order-add-ℕ zero-ℕ m n = id preserves-order-add-ℕ (succ-ℕ k) m n = preserves-order-add-ℕ k m n reflects-order-add-ℕ : (k m n : ℕ) → leq-ℕ (add-ℕ m k) (add-ℕ n k) → leq-ℕ m n reflects-order-add-ℕ zero-ℕ m n = id reflects-order-add-ℕ (succ-ℕ k) m n = reflects-order-add-ℕ k m n -- Exercise 6.3 (e) preserves-order-mul-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (mul-ℕ m k) (mul-ℕ n k) preserves-order-mul-ℕ k zero-ℕ n p = star preserves-order-mul-ℕ k (succ-ℕ m) (succ-ℕ n) p = preserves-order-add-ℕ k ( mul-ℕ m k) ( mul-ℕ n k) ( preserves-order-mul-ℕ k m n p) reflects-order-mul-ℕ : (k m n : ℕ) → leq-ℕ (mul-ℕ m (succ-ℕ k)) (mul-ℕ n (succ-ℕ k)) → leq-ℕ m n reflects-order-mul-ℕ k zero-ℕ n p = star reflects-order-mul-ℕ k (succ-ℕ m) (succ-ℕ n) p = reflects-order-mul-ℕ k m n ( reflects-order-add-ℕ ( succ-ℕ k) ( mul-ℕ m (succ-ℕ k)) ( mul-ℕ n (succ-ℕ k)) ( p)) -- Exercise 6.3 (f) leq-min-ℕ : (k m n : ℕ) → leq-ℕ k m → leq-ℕ k n → leq-ℕ k (min-ℕ m n) leq-min-ℕ zero-ℕ zero-ℕ zero-ℕ H K = star leq-min-ℕ zero-ℕ zero-ℕ (succ-ℕ n) H K = star leq-min-ℕ zero-ℕ (succ-ℕ m) zero-ℕ H K = star leq-min-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ n) H K = star leq-min-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H K = leq-min-ℕ k m n H K leq-left-leq-min-ℕ : (k m n : ℕ) → leq-ℕ k (min-ℕ m n) → leq-ℕ k m leq-left-leq-min-ℕ zero-ℕ zero-ℕ zero-ℕ H = star leq-left-leq-min-ℕ zero-ℕ zero-ℕ (succ-ℕ n) H = star leq-left-leq-min-ℕ zero-ℕ (succ-ℕ m) zero-ℕ H = star leq-left-leq-min-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ n) H = star leq-left-leq-min-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H = leq-left-leq-min-ℕ k m n H leq-right-leq-min-ℕ : (k m n : ℕ) → leq-ℕ k (min-ℕ m n) → leq-ℕ k n leq-right-leq-min-ℕ zero-ℕ zero-ℕ zero-ℕ H = star leq-right-leq-min-ℕ zero-ℕ zero-ℕ (succ-ℕ n) H = star leq-right-leq-min-ℕ zero-ℕ (succ-ℕ m) zero-ℕ H = star leq-right-leq-min-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ n) H = star leq-right-leq-min-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H = leq-right-leq-min-ℕ k m n H leq-max-ℕ : (k m n : ℕ) → leq-ℕ m k → leq-ℕ n k → leq-ℕ (max-ℕ m n) k leq-max-ℕ zero-ℕ zero-ℕ zero-ℕ H K = star leq-max-ℕ (succ-ℕ k) zero-ℕ zero-ℕ H K = star leq-max-ℕ (succ-ℕ k) zero-ℕ (succ-ℕ n) H K = K leq-max-ℕ (succ-ℕ k) (succ-ℕ m) zero-ℕ H K = H leq-max-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H K = leq-max-ℕ k m n H K leq-left-leq-max-ℕ : (k m n : ℕ) → leq-ℕ (max-ℕ m n) k → leq-ℕ m k leq-left-leq-max-ℕ k zero-ℕ zero-ℕ H = star leq-left-leq-max-ℕ k zero-ℕ (succ-ℕ n) H = star leq-left-leq-max-ℕ k (succ-ℕ m) zero-ℕ H = H leq-left-leq-max-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H = leq-left-leq-max-ℕ k m n H leq-right-leq-max-ℕ : (k m n : ℕ) → leq-ℕ (max-ℕ m n) k → leq-ℕ n k leq-right-leq-max-ℕ k zero-ℕ zero-ℕ H = star leq-right-leq-max-ℕ k zero-ℕ (succ-ℕ n) H = H leq-right-leq-max-ℕ k (succ-ℕ m) zero-ℕ H = star leq-right-leq-max-ℕ (succ-ℕ k) (succ-ℕ m) (succ-ℕ n) H = leq-right-leq-max-ℕ k m n H -- Exercise 6.4 -- Exercise 6.4 (a) -- We define a distance function on ℕ -- dist-ℕ : ℕ → ℕ → ℕ dist-ℕ zero-ℕ n = n dist-ℕ (succ-ℕ m) zero-ℕ = succ-ℕ m dist-ℕ (succ-ℕ m) (succ-ℕ n) = dist-ℕ m n dist-ℕ' : ℕ → ℕ → ℕ dist-ℕ' m n = dist-ℕ n m ap-dist-ℕ : {m n m' n' : ℕ} → Id m m' → Id n n' → Id (dist-ℕ m n) (dist-ℕ m' n') ap-dist-ℕ refl refl = refl {- We show that two natural numbers are equal if and only if their distance is zero. -} eq-dist-ℕ : (m n : ℕ) → Id zero-ℕ (dist-ℕ m n) → Id m n eq-dist-ℕ zero-ℕ zero-ℕ p = refl eq-dist-ℕ (succ-ℕ m) (succ-ℕ n) p = ap succ-ℕ (eq-dist-ℕ m n p) dist-eq-ℕ' : (n : ℕ) → Id zero-ℕ (dist-ℕ n n) dist-eq-ℕ' zero-ℕ = refl dist-eq-ℕ' (succ-ℕ n) = dist-eq-ℕ' n dist-eq-ℕ : (m n : ℕ) → Id m n → Id zero-ℕ (dist-ℕ m n) dist-eq-ℕ m .m refl = dist-eq-ℕ' m -- The distance function is symmetric -- symmetric-dist-ℕ : (m n : ℕ) → Id (dist-ℕ m n) (dist-ℕ n m) symmetric-dist-ℕ zero-ℕ zero-ℕ = refl symmetric-dist-ℕ zero-ℕ (succ-ℕ n) = refl symmetric-dist-ℕ (succ-ℕ m) zero-ℕ = refl symmetric-dist-ℕ (succ-ℕ m) (succ-ℕ n) = symmetric-dist-ℕ m n -- We compute the distance from zero -- left-zero-law-dist-ℕ : (n : ℕ) → Id (dist-ℕ zero-ℕ n) n left-zero-law-dist-ℕ zero-ℕ = refl left-zero-law-dist-ℕ (succ-ℕ n) = refl right-zero-law-dist-ℕ : (n : ℕ) → Id (dist-ℕ n zero-ℕ) n right-zero-law-dist-ℕ zero-ℕ = refl right-zero-law-dist-ℕ (succ-ℕ n) = refl -- We prove the triangle inequality -- ap-add-ℕ : {m n m' n' : ℕ} → Id m m' → Id n n' → Id (add-ℕ m n) (add-ℕ m' n') ap-add-ℕ refl refl = refl triangle-inequality-dist-ℕ : (m n k : ℕ) → leq-ℕ (dist-ℕ m n) (add-ℕ (dist-ℕ m k) (dist-ℕ k n)) triangle-inequality-dist-ℕ zero-ℕ zero-ℕ zero-ℕ = star triangle-inequality-dist-ℕ zero-ℕ zero-ℕ (succ-ℕ k) = star triangle-inequality-dist-ℕ zero-ℕ (succ-ℕ n) zero-ℕ = tr ( leq-ℕ (succ-ℕ n)) ( inv (left-unit-law-add-ℕ (succ-ℕ n))) ( reflexive-leq-ℕ (succ-ℕ n)) triangle-inequality-dist-ℕ zero-ℕ (succ-ℕ n) (succ-ℕ k) = concatenate-eq-leq-eq-ℕ ( inv (ap succ-ℕ (left-zero-law-dist-ℕ n))) ( triangle-inequality-dist-ℕ zero-ℕ n k) ( ( ap (succ-ℕ ∘ (add-ℕ' (dist-ℕ k n))) (left-zero-law-dist-ℕ k)) ∙ ( inv (left-successor-law-add-ℕ k (dist-ℕ k n)))) triangle-inequality-dist-ℕ (succ-ℕ m) zero-ℕ zero-ℕ = reflexive-leq-ℕ (succ-ℕ m) triangle-inequality-dist-ℕ (succ-ℕ m) zero-ℕ (succ-ℕ k) = concatenate-eq-leq-eq-ℕ ( inv (ap succ-ℕ (right-zero-law-dist-ℕ m))) ( triangle-inequality-dist-ℕ m zero-ℕ k) ( ap (succ-ℕ ∘ (add-ℕ (dist-ℕ m k))) (right-zero-law-dist-ℕ k)) triangle-inequality-dist-ℕ (succ-ℕ m) (succ-ℕ n) zero-ℕ = concatenate-leq-eq-ℕ ( dist-ℕ m n) ( transitive-leq-ℕ ( dist-ℕ m n) ( succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n))) ( succ-ℕ (succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n)))) ( transitive-leq-ℕ ( dist-ℕ m n) ( add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n)) ( succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n))) ( triangle-inequality-dist-ℕ m n zero-ℕ) ( succ-leq-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n)))) ( succ-leq-ℕ (succ-ℕ (add-ℕ (dist-ℕ m zero-ℕ) (dist-ℕ zero-ℕ n))))) ( ( ap (succ-ℕ ∘ succ-ℕ) ( ap-add-ℕ (right-zero-law-dist-ℕ m) (left-zero-law-dist-ℕ n))) ∙ ( inv (left-successor-law-add-ℕ m (succ-ℕ n)))) triangle-inequality-dist-ℕ (succ-ℕ m) (succ-ℕ n) (succ-ℕ k) = triangle-inequality-dist-ℕ m n k -- We show that dist-ℕ x y is a solution to a simple equation. leq-dist-ℕ : (x y : ℕ) → leq-ℕ x y → Id (add-ℕ x (dist-ℕ x y)) y leq-dist-ℕ zero-ℕ zero-ℕ H = refl leq-dist-ℕ zero-ℕ (succ-ℕ y) star = left-unit-law-add-ℕ (succ-ℕ y) leq-dist-ℕ (succ-ℕ x) (succ-ℕ y) H = ( left-successor-law-add-ℕ x (dist-ℕ x y)) ∙ ( ap succ-ℕ (leq-dist-ℕ x y H)) rewrite-left-add-dist-ℕ : (x y z : ℕ) → Id (add-ℕ x y) z → Id x (dist-ℕ y z) rewrite-left-add-dist-ℕ zero-ℕ zero-ℕ .zero-ℕ refl = refl rewrite-left-add-dist-ℕ zero-ℕ (succ-ℕ y) .(succ-ℕ (add-ℕ zero-ℕ y)) refl = ( dist-eq-ℕ' y) ∙ ( inv (ap (dist-ℕ (succ-ℕ y)) (left-unit-law-add-ℕ (succ-ℕ y)))) rewrite-left-add-dist-ℕ (succ-ℕ x) zero-ℕ .(succ-ℕ x) refl = refl rewrite-left-add-dist-ℕ (succ-ℕ x) (succ-ℕ y) .(succ-ℕ (add-ℕ (succ-ℕ x) y)) refl = rewrite-left-add-dist-ℕ (succ-ℕ x) y (add-ℕ (succ-ℕ x) y) refl rewrite-left-dist-add-ℕ : (x y z : ℕ) → leq-ℕ y z → Id x (dist-ℕ y z) → Id (add-ℕ x y) z rewrite-left-dist-add-ℕ .(dist-ℕ y z) y z H refl = ( commutative-add-ℕ (dist-ℕ y z) y) ∙ ( leq-dist-ℕ y z H) rewrite-right-add-dist-ℕ : (x y z : ℕ) → Id (add-ℕ x y) z → Id y (dist-ℕ x z) rewrite-right-add-dist-ℕ x y z p = rewrite-left-add-dist-ℕ y x z (commutative-add-ℕ y x ∙ p) rewrite-right-dist-add-ℕ : (x y z : ℕ) → leq-ℕ x z → Id y (dist-ℕ x z) → Id (add-ℕ x y) z rewrite-right-dist-add-ℕ x .(dist-ℕ x z) z H refl = leq-dist-ℕ x z H -- We show that dist-ℕ is translation invariant translation-invariant-dist-ℕ : (k m n : ℕ) → Id (dist-ℕ (add-ℕ k m) (add-ℕ k n)) (dist-ℕ m n) translation-invariant-dist-ℕ zero-ℕ m n = ap-dist-ℕ (left-unit-law-add-ℕ m) (left-unit-law-add-ℕ n) translation-invariant-dist-ℕ (succ-ℕ k) m n = ( ap-dist-ℕ (left-successor-law-add-ℕ k m) (left-successor-law-add-ℕ k n)) ∙ ( translation-invariant-dist-ℕ k m n) -- We show that dist-ℕ is linear with respect to scalar multiplication linear-dist-ℕ : (m n k : ℕ) → Id (dist-ℕ (mul-ℕ k m) (mul-ℕ k n)) (mul-ℕ k (dist-ℕ m n)) linear-dist-ℕ zero-ℕ zero-ℕ zero-ℕ = refl linear-dist-ℕ zero-ℕ zero-ℕ (succ-ℕ k) = linear-dist-ℕ zero-ℕ zero-ℕ k linear-dist-ℕ zero-ℕ (succ-ℕ n) zero-ℕ = refl linear-dist-ℕ zero-ℕ (succ-ℕ n) (succ-ℕ k) = ap (dist-ℕ' (mul-ℕ (succ-ℕ k) (succ-ℕ n))) (right-zero-law-mul-ℕ (succ-ℕ k)) linear-dist-ℕ (succ-ℕ m) zero-ℕ zero-ℕ = refl linear-dist-ℕ (succ-ℕ m) zero-ℕ (succ-ℕ k) = ap (dist-ℕ (mul-ℕ (succ-ℕ k) (succ-ℕ m))) (right-zero-law-mul-ℕ (succ-ℕ k)) linear-dist-ℕ (succ-ℕ m) (succ-ℕ n) zero-ℕ = refl linear-dist-ℕ (succ-ℕ m) (succ-ℕ n) (succ-ℕ k) = ( ap-dist-ℕ ( right-successor-law-mul-ℕ (succ-ℕ k) m) ( right-successor-law-mul-ℕ (succ-ℕ k) n)) ∙ ( ( translation-invariant-dist-ℕ ( succ-ℕ k) ( mul-ℕ (succ-ℕ k) m) ( mul-ℕ (succ-ℕ k) n)) ∙ ( linear-dist-ℕ m n (succ-ℕ k))) -- Exercise 6.6 {- In this exercise we were asked to define the relations ≤ and < on the integers. As a criterion of correctness, we were then also asked to show that the type of all integers l satisfying k ≤ l satisfy the induction principle of the natural numbers. -} diff-ℤ : ℤ → ℤ → ℤ diff-ℤ k l = add-ℤ (neg-ℤ k) l is-non-negative-ℤ : ℤ → UU lzero is-non-negative-ℤ (inl x) = empty is-non-negative-ℤ (inr k) = unit leq-ℤ : ℤ → ℤ → UU lzero leq-ℤ k l = is-non-negative-ℤ (diff-ℤ k l) reflexive-leq-ℤ : (k : ℤ) → leq-ℤ k k reflexive-leq-ℤ k = tr is-non-negative-ℤ (inv (left-inverse-law-add-ℤ k)) star is-non-negative-succ-ℤ : (k : ℤ) → is-non-negative-ℤ k → is-non-negative-ℤ (succ-ℤ k) is-non-negative-succ-ℤ (inr (inl star)) p = star is-non-negative-succ-ℤ (inr (inr x)) p = star is-non-negative-add-ℤ : (k l : ℤ) → is-non-negative-ℤ k → is-non-negative-ℤ l → is-non-negative-ℤ (add-ℤ k l) is-non-negative-add-ℤ (inr (inl star)) (inr (inl star)) p q = star is-non-negative-add-ℤ (inr (inl star)) (inr (inr n)) p q = star is-non-negative-add-ℤ (inr (inr zero-ℕ)) (inr (inl star)) p q = star is-non-negative-add-ℤ (inr (inr (succ-ℕ n))) (inr (inl star)) star star = is-non-negative-succ-ℤ ( add-ℤ (inr (inr n)) (inr (inl star))) ( is-non-negative-add-ℤ (inr (inr n)) (inr (inl star)) star star) is-non-negative-add-ℤ (inr (inr zero-ℕ)) (inr (inr m)) star star = star is-non-negative-add-ℤ (inr (inr (succ-ℕ n))) (inr (inr m)) star star = is-non-negative-succ-ℤ ( add-ℤ (inr (inr n)) (inr (inr m))) ( is-non-negative-add-ℤ (inr (inr n)) (inr (inr m)) star star) triangle-diff-ℤ : (k l m : ℤ) → Id (add-ℤ (diff-ℤ k l) (diff-ℤ l m)) (diff-ℤ k m) triangle-diff-ℤ k l m = ( associative-add-ℤ (neg-ℤ k) l (diff-ℤ l m)) ∙ ( ap ( add-ℤ (neg-ℤ k)) ( ( inv (associative-add-ℤ l (neg-ℤ l) m)) ∙ ( ( ap (λ x → add-ℤ x m) (right-inverse-law-add-ℤ l)) ∙ ( left-unit-law-add-ℤ m)))) transitive-leq-ℤ : (k l m : ℤ) → leq-ℤ k l → leq-ℤ l m → leq-ℤ k m transitive-leq-ℤ k l m p q = tr is-non-negative-ℤ ( triangle-diff-ℤ k l m) ( is-non-negative-add-ℤ ( add-ℤ (neg-ℤ k) l) ( add-ℤ (neg-ℤ l) m) ( p) ( q)) succ-leq-ℤ : (k : ℤ) → leq-ℤ k (succ-ℤ k) succ-leq-ℤ k = tr is-non-negative-ℤ ( inv ( ( right-successor-law-add-ℤ (neg-ℤ k) k) ∙ ( ap succ-ℤ (left-inverse-law-add-ℤ k)))) ( star) leq-ℤ-succ-leq-ℤ : (k l : ℤ) → leq-ℤ k l → leq-ℤ k (succ-ℤ l) leq-ℤ-succ-leq-ℤ k l p = transitive-leq-ℤ k l (succ-ℤ l) p (succ-leq-ℤ l) is-positive-ℤ : ℤ → UU lzero is-positive-ℤ k = is-non-negative-ℤ (pred-ℤ k) le-ℤ : ℤ → ℤ → UU lzero le-ℤ (inl zero-ℕ) (inl x) = empty le-ℤ (inl zero-ℕ) (inr y) = unit le-ℤ (inl (succ-ℕ x)) (inl zero-ℕ) = unit le-ℤ (inl (succ-ℕ x)) (inl (succ-ℕ y)) = le-ℤ (inl x) (inl y) le-ℤ (inl (succ-ℕ x)) (inr y) = unit le-ℤ (inr x) (inl y) = empty le-ℤ (inr (inl star)) (inr (inl star)) = empty le-ℤ (inr (inl star)) (inr (inr x)) = unit le-ℤ (inr (inr x)) (inr (inl star)) = empty le-ℤ (inr (inr zero-ℕ)) (inr (inr zero-ℕ)) = empty le-ℤ (inr (inr zero-ℕ)) (inr (inr (succ-ℕ y))) = unit le-ℤ (inr (inr (succ-ℕ x))) (inr (inr zero-ℕ)) = empty le-ℤ (inr (inr (succ-ℕ x))) (inr (inr (succ-ℕ y))) = le-ℤ (inr (inr x)) (inr (inr y)) -- Extra material -- We show that ℕ is an ordered semi-ring left-law-leq-add-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (add-ℕ m k) (add-ℕ n k) left-law-leq-add-ℕ zero-ℕ m n = id left-law-leq-add-ℕ (succ-ℕ k) m n H = left-law-leq-add-ℕ k m n H right-law-leq-add-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (add-ℕ k m) (add-ℕ k n) right-law-leq-add-ℕ k m n H = concatenate-eq-leq-eq-ℕ ( commutative-add-ℕ k m) ( left-law-leq-add-ℕ k m n H) ( commutative-add-ℕ n k) preserves-leq-add-ℕ : {m m' n n' : ℕ} → leq-ℕ m m' → leq-ℕ n n' → leq-ℕ (add-ℕ m n) (add-ℕ m' n') preserves-leq-add-ℕ {m} {m'} {n} {n'} H K = transitive-leq-ℕ ( add-ℕ m n) ( add-ℕ m' n) ( add-ℕ m' n') ( left-law-leq-add-ℕ n m m' H) ( right-law-leq-add-ℕ m' n n' K) {- right-law-leq-mul-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (mul-ℕ k m) (mul-ℕ k n) right-law-leq-mul-ℕ zero-ℕ m n H = star right-law-leq-mul-ℕ (succ-ℕ k) m n H = {!!} -} {- preserves-leq-add-ℕ { m = mul-ℕ k m} { m' = mul-ℕ k n} ( right-law-leq-mul-ℕ k m n H) H left-law-leq-mul-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (mul-ℕ m k) (mul-ℕ n k) left-law-leq-mul-ℕ k m n H = concatenate-eq-leq-eq-ℕ ( commutative-mul-ℕ k m) ( commutative-mul-ℕ k n) ( right-law-leq-mul-ℕ k m n H) -} -- We show that ℤ is an ordered ring {- leq-add-ℤ : (m k l : ℤ) → leq-ℤ k l → leq-ℤ (add-ℤ m k) (add-ℤ m l) leq-add-ℤ (inl zero-ℕ) k l H = {!!} leq-add-ℤ (inl (succ-ℕ x)) k l H = {!!} leq-add-ℤ (inr m) k l H = {!!} -} -- Section 5.5 Identity systems succ-fam-Eq-ℕ : {i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i) → (m n : ℕ) → Eq-ℕ m n → UU i succ-fam-Eq-ℕ R m n e = R (succ-ℕ m) (succ-ℕ n) e succ-refl-fam-Eq-ℕ : {i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i) (ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) → (n : ℕ) → (succ-fam-Eq-ℕ R n n (refl-Eq-ℕ n)) succ-refl-fam-Eq-ℕ R ρ n = ρ (succ-ℕ n) path-ind-Eq-ℕ : {i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i) ( ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) → ( m n : ℕ) (e : Eq-ℕ m n) → R m n e path-ind-Eq-ℕ R ρ zero-ℕ zero-ℕ star = ρ zero-ℕ path-ind-Eq-ℕ R ρ zero-ℕ (succ-ℕ n) () path-ind-Eq-ℕ R ρ (succ-ℕ m) zero-ℕ () path-ind-Eq-ℕ R ρ (succ-ℕ m) (succ-ℕ n) e = path-ind-Eq-ℕ ( λ m n e → R (succ-ℕ m) (succ-ℕ n) e) ( λ n → ρ (succ-ℕ n)) m n e comp-path-ind-Eq-ℕ : {i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i) ( ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) → ( n : ℕ) → Id (path-ind-Eq-ℕ R ρ n n (refl-Eq-ℕ n)) (ρ n) comp-path-ind-Eq-ℕ R ρ zero-ℕ = refl comp-path-ind-Eq-ℕ R ρ (succ-ℕ n) = comp-path-ind-Eq-ℕ ( λ m n e → R (succ-ℕ m) (succ-ℕ n) e) ( λ n → ρ (succ-ℕ n)) n {- -- Graphs Gph : (i : Level) → UU (lsuc i) Gph i = Σ (UU i) (λ X → (X → X → (UU i))) -- Reflexive graphs rGph : (i : Level) → UU (lsuc i) rGph i = Σ (UU i) (λ X → Σ (X → X → (UU i)) (λ R → (x : X) → R x x)) -} -- Exercise 3.7 {- With the construction of the divisibility relation we open the door to basic number theory. -} divides : (d n : ℕ) → UU lzero divides d n = Σ ℕ (λ m → Eq-ℕ (mul-ℕ d m) n) -- We prove some lemmas about inequalities -- leq-add-ℕ : (m n : ℕ) → leq-ℕ m (add-ℕ m n) leq-add-ℕ m zero-ℕ = reflexive-leq-ℕ m leq-add-ℕ m (succ-ℕ n) = transitive-leq-ℕ m (add-ℕ m n) (succ-ℕ (add-ℕ m n)) ( leq-add-ℕ m n) ( succ-leq-ℕ (add-ℕ m n)) leq-add-ℕ' : (m n : ℕ) → leq-ℕ m (add-ℕ n m) leq-add-ℕ' m n = concatenate-leq-eq-ℕ m (leq-add-ℕ m n) (commutative-add-ℕ m n) leq-leq-add-ℕ : (m n x : ℕ) → leq-ℕ (add-ℕ m x) (add-ℕ n x) → leq-ℕ m n leq-leq-add-ℕ m n zero-ℕ H = H leq-leq-add-ℕ m n (succ-ℕ x) H = leq-leq-add-ℕ m n x H leq-leq-add-ℕ' : (m n x : ℕ) → leq-ℕ (add-ℕ x m) (add-ℕ x n) → leq-ℕ m n leq-leq-add-ℕ' m n x H = leq-leq-add-ℕ m n x ( concatenate-eq-leq-eq-ℕ ( commutative-add-ℕ m x) ( H) ( commutative-add-ℕ x n)) leq-leq-mul-ℕ : (m n x : ℕ) → leq-ℕ (mul-ℕ (succ-ℕ x) m) (mul-ℕ (succ-ℕ x) n) → leq-ℕ m n leq-leq-mul-ℕ zero-ℕ zero-ℕ x H = star leq-leq-mul-ℕ zero-ℕ (succ-ℕ n) x H = star leq-leq-mul-ℕ (succ-ℕ m) zero-ℕ x H = ex-falso ( concatenate-leq-eq-ℕ ( mul-ℕ (succ-ℕ x) (succ-ℕ m)) ( H) ( right-zero-law-mul-ℕ (succ-ℕ x))) leq-leq-mul-ℕ (succ-ℕ m) (succ-ℕ n) x H = leq-leq-mul-ℕ m n x ( leq-leq-add-ℕ' (mul-ℕ (succ-ℕ x) m) (mul-ℕ (succ-ℕ x) n) (succ-ℕ x) ( concatenate-eq-leq-eq-ℕ ( inv (right-successor-law-mul-ℕ (succ-ℕ x) m)) ( H) ( right-successor-law-mul-ℕ (succ-ℕ x) n))) leq-leq-mul-ℕ' : (m n x : ℕ) → leq-ℕ (mul-ℕ m (succ-ℕ x)) (mul-ℕ n (succ-ℕ x)) → leq-ℕ m n leq-leq-mul-ℕ' m n x H = leq-leq-mul-ℕ m n x ( concatenate-eq-leq-eq-ℕ ( commutative-mul-ℕ (succ-ℕ x) m) ( H) ( commutative-mul-ℕ n (succ-ℕ x))) {- succ-relation-ℕ : {i : Level} (R : ℕ → ℕ → UU i) → ℕ → ℕ → UU i succ-relation-ℕ R m n = R (succ-ℕ m) (succ-ℕ n) succ-reflexivity-ℕ : {i : Level} (R : ℕ → ℕ → UU i) (ρ : (n : ℕ) → R n n) → (n : ℕ) → succ-relation-ℕ R n n succ-reflexivity-ℕ R ρ n = ρ (succ-ℕ n) {- In the book we suggest that first the order of the variables should be swapped, in order to make the inductive hypothesis stronger. Agda's pattern matching mechanism allows us to bypass this step and give a more direct construction. -} least-reflexive-Eq-ℕ : {i : Level} (R : ℕ → ℕ → UU i) (ρ : (n : ℕ) → R n n) → (m n : ℕ) → Eq-ℕ m n → R m n least-reflexive-Eq-ℕ R ρ zero-ℕ zero-ℕ star = ρ zero-ℕ least-reflexive-Eq-ℕ R ρ zero-ℕ (succ-ℕ n) () least-reflexive-Eq-ℕ R ρ (succ-ℕ m) zero-ℕ () least-reflexive-Eq-ℕ R ρ (succ-ℕ m) (succ-ℕ n) e = least-reflexive-Eq-ℕ (succ-relation-ℕ R) (succ-reflexivity-ℕ R ρ) m n e -} -- The definition of < le-ℕ : ℕ → ℕ → UU lzero le-ℕ m zero-ℕ = empty le-ℕ zero-ℕ (succ-ℕ m) = unit le-ℕ (succ-ℕ n) (succ-ℕ m) = le-ℕ n m _<_ = le-ℕ anti-reflexive-le-ℕ : (n : ℕ) → ¬ (n < n) anti-reflexive-le-ℕ zero-ℕ = ind-empty anti-reflexive-le-ℕ (succ-ℕ n) = anti-reflexive-le-ℕ n transitive-le-ℕ : (n m l : ℕ) → (le-ℕ n m) → (le-ℕ m l) → (le-ℕ n l) transitive-le-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ l) p q = star transitive-le-ℕ (succ-ℕ n) (succ-ℕ m) (succ-ℕ l) p q = transitive-le-ℕ n m l p q succ-le-ℕ : (n : ℕ) → le-ℕ n (succ-ℕ n) succ-le-ℕ zero-ℕ = star succ-le-ℕ (succ-ℕ n) = succ-le-ℕ n anti-symmetric-le-ℕ : (m n : ℕ) → le-ℕ m n → le-ℕ n m → Id m n anti-symmetric-le-ℕ (succ-ℕ m) (succ-ℕ n) p q = ap succ-ℕ (anti-symmetric-le-ℕ m n p q) {- -------------------------------------------------------------------------------- data Fin-Tree : UU lzero where constr : (n : ℕ) → (Fin n → Fin-Tree) → Fin-Tree root-Fin-Tree : Fin-Tree root-Fin-Tree = constr zero-ℕ ex-falso succ-Fin-Tree : Fin-Tree → Fin-Tree succ-Fin-Tree t = constr one-ℕ (λ i → t) map-assoc-coprod : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {C : UU l3} → coprod (coprod A B) C → coprod A (coprod B C) map-assoc-coprod (inl (inl x)) = inl x map-assoc-coprod (inl (inr x)) = inr (inl x) map-assoc-coprod (inr x) = inr (inr x) map-coprod-Fin : (m n : ℕ) → Fin (add-ℕ m n) → coprod (Fin m) (Fin n) map-coprod-Fin m zero-ℕ = inl map-coprod-Fin m (succ-ℕ n) = map-assoc-coprod ∘ (functor-coprod (map-coprod-Fin m n) (id {A = unit})) add-Fin-Tree : Fin-Tree → Fin-Tree → Fin-Tree add-Fin-Tree (constr n x) (constr m y) = constr (add-ℕ n m) ((ind-coprod (λ i → Fin-Tree) x y) ∘ (map-coprod-Fin n m)) -------------------------------------------------------------------------------- data labeled-Bin-Tree {l1 : Level} (A : UU l1) : UU l1 where leaf : A → labeled-Bin-Tree A constr : (bool → labeled-Bin-Tree A) → labeled-Bin-Tree A mul-leaves-labeled-Bin-Tree : {l1 : Level} {A : UU l1} (μ : A → (A → A)) → labeled-Bin-Tree A → A mul-leaves-labeled-Bin-Tree μ (leaf x) = x mul-leaves-labeled-Bin-Tree μ (constr f) = μ ( mul-leaves-labeled-Bin-Tree μ (f false)) ( mul-leaves-labeled-Bin-Tree μ (f true)) pick-list : {l1 : Level} {A : UU l1} → ℕ → list A → coprod A unit pick-list zero-ℕ nil = inr star pick-list zero-ℕ (cons a x) = inl a pick-list (succ-ℕ n) nil = inr star pick-list (succ-ℕ n) (cons a x) = pick-list n x -}
{ "alphanum_fraction": 0.5687461204, "avg_line_length": 31.205811138, "ext": "agda", "hexsha": "738d12e5cce3f7f297099bf4486a08514a9af6fa", "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": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "max_forks_repo_licenses": [ "CC-BY-4.0" ], "max_forks_repo_name": "UlrikBuchholtz/HoTT-Intro", "max_forks_repo_path": "Agda/06-universes.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "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": "UlrikBuchholtz/HoTT-Intro", "max_issues_repo_path": "Agda/06-universes.agda", "max_line_length": 80, "max_stars_count": null, "max_stars_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9", "max_stars_repo_licenses": [ "CC-BY-4.0" ], "max_stars_repo_name": "UlrikBuchholtz/HoTT-Intro", "max_stars_repo_path": "Agda/06-universes.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 12543, "size": 25776 }
{-# OPTIONS --cubical --no-import-sorts --allow-unsolved-metas #-} module Number.Instances.QuoQ.Definitions where open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero) open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc) open import Cubical.Foundations.Logic renaming (inl to inlᵖ; inr to inrᵖ) open import Cubical.Relation.Nullary.Base renaming (¬_ to ¬ᵗ_) open import Cubical.Relation.Binary.Base open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_) open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_) open import Cubical.Data.Sigma open import Cubical.Data.Bool as Bool using (Bool; not; true; false) open import Cubical.Data.Empty renaming (elim to ⊥-elim; ⊥ to ⊥⊥) -- `⊥` and `elim` open import Cubical.Foundations.Logic renaming (¬_ to ¬ᵖ_; inl to inlᵖ; inr to inrᵖ) open import Function.Base using (it; _∋_; _$_) open import Cubical.Foundations.Isomorphism open import Cubical.HITs.PropositionalTruncation --.Properties open import Utils using (!_; !!_) open import MoreLogic.Reasoning open import MoreLogic.Definitions open import MoreLogic.Properties open import MorePropAlgebra.Definitions hiding (_≤''_) open import MorePropAlgebra.Structures open import MorePropAlgebra.Bundles open import MorePropAlgebra.Consequences open import Number.Structures2 open import Number.Bundles2 open import Cubical.Data.NatPlusOne using (HasFromNat; 1+_; ℕ₊₁; ℕ₊₁→ℕ) open import Cubical.HITs.SetQuotients as SetQuotient using () renaming (_/_ to _//_) open import Cubical.Data.Nat.Literals open import Cubical.Data.Bool open import Number.Prelude.Nat open import Number.Prelude.QuoInt open import Cubical.HITs.Ints.QuoInt using (HasFromNat) open import Cubical.HITs.Rationals.QuoQ using ( ℚ ; onCommonDenom ; onCommonDenomSym ; eq/ ; _//_ ; _∼_ ) renaming ( [_] to [_]ᶠ ; ℕ₊₁→ℤ to [1+_ⁿ]ᶻ ) abstract private lemma1 : ∀ a b₁ b₂ c → (a ·ᶻ b₁) ·ᶻ (b₂ ·ᶻ c) ≡ (a ·ᶻ c) ·ᶻ (b₂ ·ᶻ b₁) lemma1 a b₁ b₂ c = (a ·ᶻ b₁) ·ᶻ (b₂ ·ᶻ c) ≡⟨ sym $ ·ᶻ-assoc a b₁ (b₂ ·ᶻ c) ⟩ a ·ᶻ (b₁ ·ᶻ (b₂ ·ᶻ c)) ≡⟨ (λ i → a ·ᶻ ·ᶻ-assoc b₁ b₂ c i) ⟩ a ·ᶻ ((b₁ ·ᶻ b₂) ·ᶻ c) ≡⟨ (λ i → a ·ᶻ ·ᶻ-comm (b₁ ·ᶻ b₂) c i) ⟩ a ·ᶻ (c ·ᶻ (b₁ ·ᶻ b₂)) ≡⟨ ·ᶻ-assoc a c (b₁ ·ᶻ b₂) ⟩ (a ·ᶻ c) ·ᶻ (b₁ ·ᶻ b₂) ≡⟨ (λ i → (a ·ᶻ c) ·ᶻ ·ᶻ-comm b₁ b₂ i) ⟩ (a ·ᶻ c) ·ᶻ (b₂ ·ᶻ b₁) ∎ ·ᶻ-commʳ : ∀ a b c → (a ·ᶻ b) ·ᶻ c ≡ (a ·ᶻ c) ·ᶻ b ·ᶻ-commʳ a b c = (a ·ᶻ b) ·ᶻ c ≡⟨ sym $ ·ᶻ-assoc a b c ⟩ a ·ᶻ (b ·ᶻ c) ≡⟨ (λ i → a ·ᶻ ·ᶻ-comm b c i) ⟩ a ·ᶻ (c ·ᶻ b) ≡⟨ ·ᶻ-assoc a c b ⟩ (a ·ᶻ c) ·ᶻ b ∎ ∼-preserves-<ᶻ : ∀ aᶻ aⁿ bᶻ bⁿ → (aᶻ , aⁿ) ∼ (bᶻ , bⁿ) → [ ((aᶻ <ᶻ 0) ⇒ (bᶻ <ᶻ 0)) ⊓ ((0 <ᶻ aᶻ) ⇒ (0 <ᶻ bᶻ)) ] ∼-preserves-<ᶻ aᶻ aⁿ bᶻ bⁿ r = γ where aⁿᶻ = [1+ aⁿ ⁿ]ᶻ bⁿᶻ = [1+ bⁿ ⁿ]ᶻ 0<aⁿᶻ : [ 0 <ᶻ aⁿᶻ ] 0<aⁿᶻ = ℕ₊₁.n aⁿ , +ⁿ-comm (ℕ₊₁.n aⁿ) 1 0<bⁿᶻ : [ 0 <ᶻ bⁿᶻ ] 0<bⁿᶻ = ℕ₊₁.n bⁿ , +ⁿ-comm (ℕ₊₁.n bⁿ) 1 γ : [ ((aᶻ <ᶻ 0) ⇒ (bᶻ <ᶻ 0)) ⊓ ((0 <ᶻ aᶻ) ⇒ (0 <ᶻ bᶻ)) ] γ .fst aᶻ<0 = ( aᶻ <ᶻ 0 ⇒ᵖ⟨ ·ᶻ-preserves-<ᶻ aᶻ 0 bⁿᶻ 0<bⁿᶻ ⟩ aᶻ ·ᶻ bⁿᶻ <ᶻ 0 ·ᶻ bⁿᶻ ⇒ᵖ⟨ (subst (λ p → [ aᶻ ·ᶻ bⁿᶻ <ᶻ p ]) $ ·ᶻ-nullifiesˡ bⁿᶻ) ⟩ aᶻ ·ᶻ bⁿᶻ <ᶻ 0 ⇒ᵖ⟨ subst (λ p → [ p <ᶻ 0 ]) r ⟩ bᶻ ·ᶻ aⁿᶻ <ᶻ 0 ⇒ᵖ⟨ subst (λ p → [ bᶻ ·ᶻ aⁿᶻ <ᶻ p ]) (sym (·ᶻ-nullifiesˡ aⁿᶻ)) ⟩ bᶻ ·ᶻ aⁿᶻ <ᶻ 0 ·ᶻ aⁿᶻ ⇒ᵖ⟨ ·ᶻ-reflects-<ᶻ bᶻ 0 aⁿᶻ 0<aⁿᶻ ⟩ bᶻ <ᶻ 0 ◼ᵖ) .snd aᶻ<0 γ .snd 0<aᶻ = ( 0 <ᶻ aᶻ ⇒ᵖ⟨ ·ᶻ-preserves-<ᶻ 0 aᶻ bⁿᶻ 0<bⁿᶻ ⟩ 0 ·ᶻ bⁿᶻ <ᶻ aᶻ ·ᶻ bⁿᶻ ⇒ᵖ⟨ (subst (λ p → [ p <ᶻ aᶻ ·ᶻ bⁿᶻ ]) $ ·ᶻ-nullifiesˡ bⁿᶻ) ⟩ 0 <ᶻ aᶻ ·ᶻ bⁿᶻ ⇒ᵖ⟨ subst (λ p → [ 0 <ᶻ p ]) r ⟩ 0 <ᶻ bᶻ ·ᶻ aⁿᶻ ⇒ᵖ⟨ subst (λ p → [ p <ᶻ bᶻ ·ᶻ aⁿᶻ ]) (sym (·ᶻ-nullifiesˡ aⁿᶻ)) ⟩ 0 ·ᶻ aⁿᶻ <ᶻ bᶻ ·ᶻ aⁿᶻ ⇒ᵖ⟨ ·ᶻ-reflects-<ᶻ 0 bᶻ aⁿᶻ 0<aⁿᶻ ⟩ 0 <ᶻ bᶻ ◼ᵖ) .snd 0<aᶻ -- < on ℤ × ℕ₊₁ in terms of < on ℤ _<'_ : ℤ × ℕ₊₁ → ℤ × ℕ₊₁ → hProp ℓ-zero (aᶻ , aⁿ) <' (bᶻ , bⁿ) = let aⁿᶻ = [1+ aⁿ ⁿ]ᶻ bⁿᶻ = [1+ bⁿ ⁿ]ᶻ in (aᶻ ·ᶻ bⁿᶻ) <ᶻ (bᶻ ·ᶻ aⁿᶻ) private lem1 : ∀ x y z → [ 0 <ᶻ y ] → [ 0 <ᶻ z ] → (0 <ᶻ (x ·ᶻ y)) ≡ (0 <ᶻ (x ·ᶻ z)) lem1 x y z p q = 0 <ᶻ (x ·ᶻ y) ≡⟨ (λ i → ·ᶻ-nullifiesˡ y (~ i) <ᶻ x ·ᶻ y) ⟩ (0 ·ᶻ y) <ᶻ (x ·ᶻ y) ≡⟨ sym $ ·ᶻ-creates-<ᶻ-≡ 0 x y p ⟩ 0 <ᶻ x ≡⟨ ·ᶻ-creates-<ᶻ-≡ 0 x z q ⟩ (0 ·ᶻ z) <ᶻ (x ·ᶻ z) ≡⟨ (λ i → ·ᶻ-nullifiesˡ z i <ᶻ x ·ᶻ z) ⟩ 0 <ᶻ (x ·ᶻ z) ∎ <'-respects-∼ˡ : ∀ a b x → a ∼ b → a <' x ≡ b <' x <'-respects-∼ˡ a@(aᶻ , aⁿ) b@(bᶻ , bⁿ) x@(xᶻ , xⁿ) a~b = γ where aⁿᶻ = [1+ aⁿ ⁿ]ᶻ; 0<aⁿᶻ : [ 0 <ᶻ aⁿᶻ ]; 0<aⁿᶻ = 0<ᶻpos[suc] _ bⁿᶻ = [1+ bⁿ ⁿ]ᶻ; 0<bⁿᶻ : [ 0 <ᶻ bⁿᶻ ]; 0<bⁿᶻ = 0<ᶻpos[suc] _ xⁿᶻ = [1+ xⁿ ⁿ]ᶻ p : aᶻ ·ᶻ bⁿᶻ ≡ bᶻ ·ᶻ aⁿᶻ p = a~b γ : ((aᶻ ·ᶻ xⁿᶻ) <ᶻ (xᶻ ·ᶻ aⁿᶻ)) ≡ ((bᶻ ·ᶻ xⁿᶻ) <ᶻ (xᶻ ·ᶻ bⁿᶻ)) γ = aᶻ ·ᶻ xⁿᶻ <ᶻ xᶻ ·ᶻ aⁿᶻ ≡⟨ ·ᶻ-creates-<ᶻ-≡ (aᶻ ·ᶻ xⁿᶻ) (xᶻ ·ᶻ aⁿᶻ) bⁿᶻ 0<bⁿᶻ ⟩ aᶻ ·ᶻ xⁿᶻ ·ᶻ bⁿᶻ <ᶻ xᶻ ·ᶻ aⁿᶻ ·ᶻ bⁿᶻ ≡⟨ (λ i → ·ᶻ-commʳ aᶻ xⁿᶻ bⁿᶻ i <ᶻ xᶻ ·ᶻ aⁿᶻ ·ᶻ bⁿᶻ) ⟩ aᶻ ·ᶻ bⁿᶻ ·ᶻ xⁿᶻ <ᶻ xᶻ ·ᶻ aⁿᶻ ·ᶻ bⁿᶻ ≡⟨ (λ i → p i ·ᶻ xⁿᶻ <ᶻ xᶻ ·ᶻ aⁿᶻ ·ᶻ bⁿᶻ) ⟩ bᶻ ·ᶻ aⁿᶻ ·ᶻ xⁿᶻ <ᶻ xᶻ ·ᶻ aⁿᶻ ·ᶻ bⁿᶻ ≡⟨ (λ i → ·ᶻ-commʳ bᶻ aⁿᶻ xⁿᶻ i <ᶻ ·ᶻ-commʳ xᶻ aⁿᶻ bⁿᶻ i) ⟩ bᶻ ·ᶻ xⁿᶻ ·ᶻ aⁿᶻ <ᶻ xᶻ ·ᶻ bⁿᶻ ·ᶻ aⁿᶻ ≡⟨ sym $ ·ᶻ-creates-<ᶻ-≡ (bᶻ ·ᶻ xⁿᶻ) (xᶻ ·ᶻ bⁿᶻ) aⁿᶻ 0<aⁿᶻ ⟩ bᶻ ·ᶻ xⁿᶻ <ᶻ xᶻ ·ᶻ bⁿᶻ ∎ <'-respects-∼ʳ : ∀ x a b → a ∼ b → x <' a ≡ x <' b <'-respects-∼ʳ x@(xᶻ , xⁿ) a@(aᶻ , aⁿ) b@(bᶻ , bⁿ) a~b = let aⁿᶻ = [1+ aⁿ ⁿ]ᶻ; 0<aⁿᶻ : [ 0 <ᶻ aⁿᶻ ]; 0<aⁿᶻ = 0<ᶻpos[suc] _ bⁿᶻ = [1+ bⁿ ⁿ]ᶻ; 0<bⁿᶻ : [ 0 <ᶻ bⁿᶻ ]; 0<bⁿᶻ = 0<ᶻpos[suc] _ xⁿᶻ = [1+ xⁿ ⁿ]ᶻ p : aᶻ ·ᶻ bⁿᶻ ≡ bᶻ ·ᶻ aⁿᶻ p = a~b in xᶻ ·ᶻ aⁿᶻ <ᶻ aᶻ ·ᶻ xⁿᶻ ≡⟨ (λ i → xᶻ ·ᶻ aⁿᶻ <ᶻ ·ᶻ-comm aᶻ xⁿᶻ i) ⟩ xᶻ ·ᶻ aⁿᶻ <ᶻ xⁿᶻ ·ᶻ aᶻ ≡⟨ ·ᶻ-creates-<ᶻ-≡ (xᶻ ·ᶻ aⁿᶻ) (xⁿᶻ ·ᶻ aᶻ) bⁿᶻ 0<bⁿᶻ ⟩ xᶻ ·ᶻ aⁿᶻ ·ᶻ bⁿᶻ <ᶻ xⁿᶻ ·ᶻ aᶻ ·ᶻ bⁿᶻ ≡⟨ (λ i → xᶻ ·ᶻ aⁿᶻ ·ᶻ bⁿᶻ <ᶻ ·ᶻ-assoc xⁿᶻ aᶻ bⁿᶻ (~ i)) ⟩ xᶻ ·ᶻ aⁿᶻ ·ᶻ bⁿᶻ <ᶻ xⁿᶻ ·ᶻ (aᶻ ·ᶻ bⁿᶻ) ≡⟨ (λ i → xᶻ ·ᶻ aⁿᶻ ·ᶻ bⁿᶻ <ᶻ xⁿᶻ ·ᶻ (p i)) ⟩ xᶻ ·ᶻ aⁿᶻ ·ᶻ bⁿᶻ <ᶻ xⁿᶻ ·ᶻ (bᶻ ·ᶻ aⁿᶻ) ≡⟨ (λ i → ·ᶻ-commʳ xᶻ aⁿᶻ bⁿᶻ i <ᶻ ·ᶻ-assoc xⁿᶻ bᶻ aⁿᶻ i) ⟩ xᶻ ·ᶻ bⁿᶻ ·ᶻ aⁿᶻ <ᶻ xⁿᶻ ·ᶻ bᶻ ·ᶻ aⁿᶻ ≡⟨ sym $ ·ᶻ-creates-<ᶻ-≡ (xᶻ ·ᶻ bⁿᶻ) (xⁿᶻ ·ᶻ bᶻ) aⁿᶻ 0<aⁿᶻ ⟩ xᶻ ·ᶻ bⁿᶻ <ᶻ xⁿᶻ ·ᶻ bᶻ ≡⟨ (λ i → xᶻ ·ᶻ bⁿᶻ <ᶻ ·ᶻ-comm xⁿᶻ bᶻ i) ⟩ xᶻ ·ᶻ bⁿᶻ <ᶻ bᶻ ·ᶻ xⁿᶻ ∎ infixl 4 _<_ _<_ : hPropRel ℚ ℚ ℓ-zero a < b = SetQuotient.rec2 {R = _∼_} {B = hProp ℓ-zero} isSetHProp _<'_ <'-respects-∼ˡ <'-respects-∼ʳ a b _≤_ : hPropRel ℚ ℚ ℓ-zero x ≤ y = ¬ᵖ (y < x) min' : ℤ × ℕ₊₁ → ℤ × ℕ₊₁ → ℤ min' (aᶻ , aⁿ) (bᶻ , bⁿ) = let aⁿᶻ = [1+ aⁿ ⁿ]ᶻ bⁿᶻ = [1+ bⁿ ⁿ]ᶻ in minᶻ (aᶻ ·ᶻ bⁿᶻ) (bᶻ ·ᶻ aⁿᶻ) max' : ℤ × ℕ₊₁ → ℤ × ℕ₊₁ → ℤ max' (aᶻ , aⁿ) (bᶻ , bⁿ) = let aⁿᶻ = [1+ aⁿ ⁿ]ᶻ bⁿᶻ = [1+ bⁿ ⁿ]ᶻ in maxᶻ (aᶻ ·ᶻ bⁿᶻ) (bᶻ ·ᶻ aⁿᶻ) min'-sym : ∀ x y → min' x y ≡ min' y x min'-sym (aᶻ , aⁿ) (bᶻ , bⁿ) = minᶻ-comm (aᶻ ·ᶻ [1+ bⁿ ⁿ]ᶻ) (bᶻ ·ᶻ [1+ aⁿ ⁿ]ᶻ) max'-sym : ∀ x y → max' x y ≡ max' y x max'-sym (aᶻ , aⁿ) (bᶻ , bⁿ) = maxᶻ-comm (aᶻ ·ᶻ [1+ bⁿ ⁿ]ᶻ) (bᶻ ·ᶻ [1+ aⁿ ⁿ]ᶻ) min'-respects-∼ : (a@(aᶻ , aⁿ) b@(bᶻ , bⁿ) x@(xᶻ , xⁿ) : ℤ × ℕ₊₁) → a ∼ b → [1+ bⁿ ⁿ]ᶻ ·ᶻ min' a x ≡ [1+ aⁿ ⁿ]ᶻ ·ᶻ min' b x min'-respects-∼ a@(aᶻ , aⁿ) b@(bᶻ , bⁿ) x@(xᶻ , xⁿ) a~b = bⁿᶻ ·ᶻ minᶻ (aᶻ ·ᶻ xⁿᶻ) (xᶻ ·ᶻ aⁿᶻ) ≡⟨ ·ᶻ-minᶻ-distribˡ (aᶻ ·ᶻ xⁿᶻ) (xᶻ ·ᶻ aⁿᶻ) bⁿᶻ 0≤bⁿᶻ ⟩ minᶻ (bⁿᶻ ·ᶻ (aᶻ ·ᶻ xⁿᶻ)) (bⁿᶻ ·ᶻ (xᶻ ·ᶻ aⁿᶻ)) ≡⟨ (λ i → minᶻ (·ᶻ-assoc bⁿᶻ aᶻ xⁿᶻ i) (bⁿᶻ ·ᶻ (xᶻ ·ᶻ aⁿᶻ))) ⟩ minᶻ ((bⁿᶻ ·ᶻ aᶻ) ·ᶻ xⁿᶻ) (bⁿᶻ ·ᶻ (xᶻ ·ᶻ aⁿᶻ)) ≡⟨ (λ i → minᶻ ((·ᶻ-comm bⁿᶻ aᶻ i) ·ᶻ xⁿᶻ) (bⁿᶻ ·ᶻ (xᶻ ·ᶻ aⁿᶻ))) ⟩ minᶻ ((aᶻ ·ᶻ bⁿᶻ) ·ᶻ xⁿᶻ) (bⁿᶻ ·ᶻ (xᶻ ·ᶻ aⁿᶻ)) ≡⟨ (λ i → minᶻ (p i ·ᶻ xⁿᶻ) (bⁿᶻ ·ᶻ (xᶻ ·ᶻ aⁿᶻ))) ⟩ minᶻ ((bᶻ ·ᶻ aⁿᶻ) ·ᶻ xⁿᶻ) (bⁿᶻ ·ᶻ (xᶻ ·ᶻ aⁿᶻ)) ≡⟨ (λ i → minᶻ (·ᶻ-comm bᶻ aⁿᶻ i ·ᶻ xⁿᶻ) (·ᶻ-assoc bⁿᶻ xᶻ aⁿᶻ i)) ⟩ minᶻ ((aⁿᶻ ·ᶻ bᶻ) ·ᶻ xⁿᶻ) ((bⁿᶻ ·ᶻ xᶻ) ·ᶻ aⁿᶻ) ≡⟨ (λ i → minᶻ (·ᶻ-assoc aⁿᶻ bᶻ xⁿᶻ (~ i)) (·ᶻ-comm (bⁿᶻ ·ᶻ xᶻ) aⁿᶻ i)) ⟩ minᶻ (aⁿᶻ ·ᶻ (bᶻ ·ᶻ xⁿᶻ)) (aⁿᶻ ·ᶻ (bⁿᶻ ·ᶻ xᶻ)) ≡⟨ sym $ ·ᶻ-minᶻ-distribˡ (bᶻ ·ᶻ xⁿᶻ) (bⁿᶻ ·ᶻ xᶻ) aⁿᶻ 0≤aⁿᶻ ⟩ aⁿᶻ ·ᶻ minᶻ (bᶻ ·ᶻ xⁿᶻ) (bⁿᶻ ·ᶻ xᶻ) ≡⟨ (λ i → aⁿᶻ ·ᶻ minᶻ (bᶻ ·ᶻ xⁿᶻ) (·ᶻ-comm bⁿᶻ xᶻ i)) ⟩ aⁿᶻ ·ᶻ minᶻ (bᶻ ·ᶻ xⁿᶻ) (xᶻ ·ᶻ bⁿᶻ) ∎ where aⁿᶻ = [1+ aⁿ ⁿ]ᶻ bⁿᶻ = [1+ bⁿ ⁿ]ᶻ xⁿᶻ = [1+ xⁿ ⁿ]ᶻ p : aᶻ ·ᶻ bⁿᶻ ≡ bᶻ ·ᶻ aⁿᶻ p = a~b 0≤aⁿᶻ : [ 0 ≤ᶻ aⁿᶻ ] 0≤aⁿᶻ (k , p) = snotzⁿ $ sym (+ⁿ-suc k _) ∙ p 0≤bⁿᶻ : [ 0 ≤ᶻ bⁿᶻ ] 0≤bⁿᶻ (k , p) = snotzⁿ $ sym (+ⁿ-suc k _) ∙ p -- same proof as for min max'-respects-∼ : (a@(aᶻ , aⁿ) b@(bᶻ , bⁿ) x@(xᶻ , xⁿ) : ℤ × ℕ₊₁) → a ∼ b → [1+ bⁿ ⁿ]ᶻ ·ᶻ max' a x ≡ [1+ aⁿ ⁿ]ᶻ ·ᶻ max' b x max'-respects-∼ a@(aᶻ , aⁿ) b@(bᶻ , bⁿ) x@(xᶻ , xⁿ) a~b = bⁿᶻ ·ᶻ maxᶻ (aᶻ ·ᶻ xⁿᶻ) (xᶻ ·ᶻ aⁿᶻ) ≡⟨ ·ᶻ-maxᶻ-distribˡ (aᶻ ·ᶻ xⁿᶻ) (xᶻ ·ᶻ aⁿᶻ) bⁿᶻ 0≤bⁿᶻ ⟩ maxᶻ (bⁿᶻ ·ᶻ (aᶻ ·ᶻ xⁿᶻ)) (bⁿᶻ ·ᶻ (xᶻ ·ᶻ aⁿᶻ)) ≡⟨ (λ i → maxᶻ (·ᶻ-assoc bⁿᶻ aᶻ xⁿᶻ i) (bⁿᶻ ·ᶻ (xᶻ ·ᶻ aⁿᶻ))) ⟩ maxᶻ ((bⁿᶻ ·ᶻ aᶻ) ·ᶻ xⁿᶻ) (bⁿᶻ ·ᶻ (xᶻ ·ᶻ aⁿᶻ)) ≡⟨ (λ i → maxᶻ ((·ᶻ-comm bⁿᶻ aᶻ i) ·ᶻ xⁿᶻ) (bⁿᶻ ·ᶻ (xᶻ ·ᶻ aⁿᶻ))) ⟩ maxᶻ ((aᶻ ·ᶻ bⁿᶻ) ·ᶻ xⁿᶻ) (bⁿᶻ ·ᶻ (xᶻ ·ᶻ aⁿᶻ)) ≡⟨ (λ i → maxᶻ (p i ·ᶻ xⁿᶻ) (bⁿᶻ ·ᶻ (xᶻ ·ᶻ aⁿᶻ))) ⟩ maxᶻ ((bᶻ ·ᶻ aⁿᶻ) ·ᶻ xⁿᶻ) (bⁿᶻ ·ᶻ (xᶻ ·ᶻ aⁿᶻ)) ≡⟨ (λ i → maxᶻ (·ᶻ-comm bᶻ aⁿᶻ i ·ᶻ xⁿᶻ) (·ᶻ-assoc bⁿᶻ xᶻ aⁿᶻ i)) ⟩ maxᶻ ((aⁿᶻ ·ᶻ bᶻ) ·ᶻ xⁿᶻ) ((bⁿᶻ ·ᶻ xᶻ) ·ᶻ aⁿᶻ) ≡⟨ (λ i → maxᶻ (·ᶻ-assoc aⁿᶻ bᶻ xⁿᶻ (~ i)) (·ᶻ-comm (bⁿᶻ ·ᶻ xᶻ) aⁿᶻ i)) ⟩ maxᶻ (aⁿᶻ ·ᶻ (bᶻ ·ᶻ xⁿᶻ)) (aⁿᶻ ·ᶻ (bⁿᶻ ·ᶻ xᶻ)) ≡⟨ sym $ ·ᶻ-maxᶻ-distribˡ (bᶻ ·ᶻ xⁿᶻ) (bⁿᶻ ·ᶻ xᶻ) aⁿᶻ 0≤aⁿᶻ ⟩ aⁿᶻ ·ᶻ maxᶻ (bᶻ ·ᶻ xⁿᶻ) (bⁿᶻ ·ᶻ xᶻ) ≡⟨ (λ i → aⁿᶻ ·ᶻ maxᶻ (bᶻ ·ᶻ xⁿᶻ) (·ᶻ-comm bⁿᶻ xᶻ i)) ⟩ aⁿᶻ ·ᶻ maxᶻ (bᶻ ·ᶻ xⁿᶻ) (xᶻ ·ᶻ bⁿᶻ) ∎ where aⁿᶻ = [1+ aⁿ ⁿ]ᶻ bⁿᶻ = [1+ bⁿ ⁿ]ᶻ xⁿᶻ = [1+ xⁿ ⁿ]ᶻ p : aᶻ ·ᶻ bⁿᶻ ≡ bᶻ ·ᶻ aⁿᶻ p = a~b 0≤aⁿᶻ : [ 0 ≤ᶻ aⁿᶻ ] 0≤aⁿᶻ (k , p) = snotzⁿ $ sym (+ⁿ-suc k _) ∙ p 0≤bⁿᶻ : [ 0 ≤ᶻ bⁿᶻ ] 0≤bⁿᶻ (k , p) = snotzⁿ $ sym (+ⁿ-suc k _) ∙ p min : ℚ → ℚ → ℚ min a b = onCommonDenomSym min' min'-sym min'-respects-∼ a b max : ℚ → ℚ → ℚ max a b = onCommonDenomSym max' max'-sym max'-respects-∼ a b -- injᶻⁿ⁺¹ : ∀ x → [ 0 <ᶻ x ] → Σ[ y ∈ ℕ₊₁ ] x ≡ [1+ y ⁿ]ᶻ -- injᶻⁿ⁺¹ (signed spos zero) p = ⊥-elim {A = λ _ → Σ[ y ∈ ℕ₊₁ ] ℤ.posneg i0 ≡ [1+ y ⁿ]ᶻ} (¬-<ⁿ-zero p) -- injᶻⁿ⁺¹ (signed sneg zero) p = ⊥-elim {A = λ _ → Σ[ y ∈ ℕ₊₁ ] ℤ.posneg i1 ≡ [1+ y ⁿ]ᶻ} (¬-<ⁿ-zero p) -- injᶻⁿ⁺¹ (ℤ.posneg i) p = ⊥-elim {A = λ _ → Σ[ y ∈ ℕ₊₁ ] ℤ.posneg i ≡ [1+ y ⁿ]ᶻ} (¬-<ⁿ-zero p) -- injᶻⁿ⁺¹ (signed spos (suc n)) p = 1+ n , refl absᶻ⁺¹ : ℤ → ℕ₊₁ absᶻ⁺¹ (pos zero) = 1+ 0 absᶻ⁺¹ (neg zero) = 1+ 0 absᶻ⁺¹ (posneg i) = 1+ 0 absᶻ⁺¹ (pos (suc n)) = 1+ n absᶻ⁺¹ (neg (suc n)) = 1+ n -- absᶻ⁺¹-identity⁺ : ∀ x → [ 0 <ⁿ x ] → [1+ absᶻ⁺¹ (pos x) ⁿ]ᶻ ≡ pos x -- absᶻ⁺¹-identity⁺ zero p = ⊥-elim {A = λ _ → [1+ absᶻ⁺¹ (pos zero) ⁿ]ᶻ ≡ pos zero} (<ⁿ-irrefl 0 p) -- absᶻ⁺¹-identity⁺ (suc x) p = refl -- -- absᶻ⁺¹-identity⁻ : ∀ x → [ 0 <ⁿ x ] → [1+ absᶻ⁺¹ (neg x) ⁿ]ᶻ ≡ pos x -- absᶻ⁺¹-identity⁻ zero p = ⊥-elim {A = λ _ → [1+ absᶻ⁺¹ (neg zero) ⁿ]ᶻ ≡ pos zero} (<ⁿ-irrefl 0 p) -- absᶻ⁺¹-identity⁻ (suc x) p = refl absᶻ⁺¹-identity : ∀ x → [ x #ᶻ 0 ] → [1+ absᶻ⁺¹ x ⁿ]ᶻ ≡ pos (absᶻ x) absᶻ⁺¹-identity (pos zero) p = ⊥-elim {A = λ _ → pos 1 ≡ pos 0} $ #ᶻ⇒≢ (posneg i0) p refl absᶻ⁺¹-identity (neg zero) p = ⊥-elim {A = λ _ → pos 1 ≡ pos 0} $ #ᶻ⇒≢ (posneg i1) p posneg absᶻ⁺¹-identity (posneg i) p = ⊥-elim {A = λ _ → pos 1 ≡ pos 0} $ #ᶻ⇒≢ (posneg i ) p (λ j → posneg (i ∧ j)) absᶻ⁺¹-identity (pos (suc n)) p = refl absᶻ⁺¹-identity (neg (suc n)) p = refl absᶻ⁺¹-identityⁿ : ∀ x → [ x #ᶻ 0 ] → suc (ℕ₊₁.n (absᶻ⁺¹ x)) ≡ absᶻ x absᶻ⁺¹-identityⁿ x p i = absᶻ (absᶻ⁺¹-identity x p i) sign' : ℤ × ℕ₊₁ → Sign sign' (z , n) = signᶻ z sign'-preserves-∼ : (a b : ℤ × ℕ₊₁) → a ∼ b → sign' a ≡ sign' b sign'-preserves-∼ a@(aᶻ , aⁿ) b@(bᶻ , bⁿ) p = sym (lem aᶻ bⁿ) ∙ ψ ∙ lem bᶻ aⁿ where a' = absᶻ aᶻ ·ⁿ suc (ℕ₊₁.n bⁿ) b' = absᶻ bᶻ ·ⁿ suc (ℕ₊₁.n aⁿ) γ : signed (signᶻ aᶻ ⊕ spos) a' ≡ signed (signᶻ bᶻ ⊕ spos) b' γ = p ψ : signᶻ (signed (signᶻ aᶻ ⊕ spos) a') ≡ signᶻ (signed (signᶻ bᶻ ⊕ spos) b') ψ i = signᶻ (γ i) lem : ∀ x y → signᶻ (signed (signᶻ x ⊕ spos) (absᶻ x ·ⁿ suc (ℕ₊₁.n y))) ≡ signᶻ x lem (pos zero) y = refl lem (neg zero) y = refl lem (posneg i) y = refl lem (pos (suc n)) y = refl lem (neg (suc n)) y = refl sign : ℚ → Sign sign = SetQuotient.rec {R = _∼_} {B = Sign} Bool.isSetBool sign' sign'-preserves-∼ sign-signᶻ-identity : ∀ z n → sign [ z , n ]ᶠ ≡ signᶻ z sign-signᶻ-identity z n = refl
{ "alphanum_fraction": 0.505274093, "avg_line_length": 45.3405797101, "ext": "agda", "hexsha": "82ba5091f8cbd8d3190a2fae885185ba24f5de58", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mchristianl/synthetic-reals", "max_forks_repo_path": "agda/Number/Instances/QuoQ/Definitions.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mchristianl/synthetic-reals", "max_issues_repo_path": "agda/Number/Instances/QuoQ/Definitions.agda", "max_line_length": 122, "max_stars_count": 3, "max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mchristianl/synthetic-reals", "max_stars_repo_path": "agda/Number/Instances/QuoQ/Definitions.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z", "num_tokens": 9567, "size": 12514 }
-- TODO: Generalize and move to Structure.Categorical.Proofs module Structure.Category.Proofs where import Lvl open import Data open import Data.Tuple as Tuple using (_,_) open import Functional using (const ; swap ; _$_) open import Lang.Instance open import Logic open import Logic.Propositional open import Logic.Predicate open import Structure.Category open import Structure.Categorical.Names open import Structure.Categorical.Properties import Structure.Operator.Properties as Properties open import Structure.Operator open import Structure.Relator.Equivalence open import Structure.Relator.Properties open import Structure.Setoid open import Syntax.Function open import Syntax.Transitivity open import Type module _ {ℓₒ ℓₘ ℓₑ : Lvl.Level} {Obj : Type{ℓₒ}} {Morphism : Obj → Obj → Type{ℓₘ}} ⦃ morphism-equiv : ∀{x y} → Equiv{ℓₑ}(Morphism x y) ⦄ (cat : Category(Morphism)) where open Category(cat) open Category.ArrowNotation(cat) open Morphism.OperModule(\{x} → _∘_ {x}) open Morphism.IdModule(\{x} → _∘_ {x})(id) private open module [≡]-Equivalence {x}{y} = Equivalence (Equiv-equivalence ⦃ morphism-equiv{x}{y} ⦄) using () private variable x y z : Obj private variable f g h i : x ⟶ y associate4-123-321 : (((f ∘ g) ∘ h) ∘ i ≡ f ∘ (g ∘ (h ∘ i))) associate4-123-321 = Morphism.associativity(_∘_) 🝖 Morphism.associativity(_∘_) associate4-123-213 : (((f ∘ g) ∘ h) ∘ i ≡ (f ∘ (g ∘ h)) ∘ i) associate4-123-213 = congruence₂ₗ(_∘_)(_) (Morphism.associativity(_∘_)) associate4-321-231 : (f ∘ (g ∘ (h ∘ i)) ≡ f ∘ ((g ∘ h) ∘ i)) associate4-321-231 = congruence₂ᵣ(_∘_)(_) (symmetry(_≡_) (Morphism.associativity(_∘_))) associate4-213-121 : ((f ∘ (g ∘ h)) ∘ i ≡ (f ∘ g) ∘ (h ∘ i)) associate4-213-121 = symmetry(_≡_) (congruence₂ₗ(_∘_)(_) (Morphism.associativity(_∘_))) 🝖 Morphism.associativity(_∘_) associate4-231-213 : f ∘ ((g ∘ h) ∘ i) ≡ (f ∘ (g ∘ h)) ∘ i associate4-231-213 = symmetry(_≡_) (Morphism.associativity(_∘_)) associate4-231-123 : f ∘ ((g ∘ h) ∘ i) ≡ ((f ∘ g) ∘ h) ∘ i associate4-231-123 = associate4-231-213 🝖 symmetry(_≡_) associate4-123-213 associate4-231-121 : (f ∘ ((g ∘ h) ∘ i) ≡ (f ∘ g) ∘ (h ∘ i)) associate4-231-121 = congruence₂ᵣ(_∘_)(_) (Morphism.associativity(_∘_)) 🝖 symmetry(_≡_) (Morphism.associativity(_∘_)) id-automorphism : Automorphism(id{x}) ∃.witness id-automorphism = id ∃.proof id-automorphism = intro(Morphism.identityₗ(_∘_)(id)) , intro(Morphism.identityᵣ(_∘_)(id)) inverse-isomorphism : (f : x ⟶ y) → ⦃ _ : Isomorphism(f) ⦄ → Isomorphism(inv f) ∃.witness (inverse-isomorphism f) = f ∃.proof (inverse-isomorphism f) = intro (inverseᵣ(f)(inv f)) , intro (inverseₗ(f)(inv f)) where open Isomorphism(f) module _ ⦃ op : ∀{x y z} → BinaryOperator(_∘_ {x}{y}{z}) ⦄ where op-closed-under-isomorphism : ∀{A B C : Obj} → (f : B ⟶ C) → (g : A ⟶ B) → ⦃ _ : Isomorphism(f) ⦄ → ⦃ _ : Isomorphism(g) ⦄ → Isomorphism(f ∘ g) ∃.witness (op-closed-under-isomorphism f g) = inv g ∘ inv f Tuple.left (∃.proof (op-closed-under-isomorphism f g)) = intro $ (inv g ∘ inv f) ∘ (f ∘ g) 🝖-[ associate4-213-121 ]-sym (inv g ∘ (inv f ∘ f)) ∘ g 🝖-[ congruence₂ₗ(_∘_) ⦃ op ⦄ (g) (congruence₂ᵣ(_∘_) ⦃ op ⦄ (inv g) (Morphism.inverseₗ(_∘_)(id) (f)(inv f))) ] (inv g ∘ id) ∘ g 🝖-[ congruence₂ₗ(_∘_) ⦃ op ⦄ (g) (Morphism.identityᵣ(_∘_)(id)) ] inv g ∘ g 🝖-[ Morphism.inverseₗ(_∘_)(id) (g)(inv g) ] id 🝖-end where open Isomorphism(f) open Isomorphism(g) Tuple.right (∃.proof (op-closed-under-isomorphism f g)) = intro $ (f ∘ g) ∘ (inv g ∘ inv f) 🝖-[ associate4-213-121 ]-sym (f ∘ (g ∘ inv g)) ∘ inv f 🝖-[ congruence₂ₗ(_∘_) ⦃ op ⦄ (_) (congruence₂ᵣ(_∘_) ⦃ op ⦄ (_) (Morphism.inverseᵣ(_∘_)(id) (_)(_))) ] (f ∘ id) ∘ inv f 🝖-[ congruence₂ₗ(_∘_) ⦃ op ⦄ (_) (Morphism.identityᵣ(_∘_)(id)) ] f ∘ inv f 🝖-[ Morphism.inverseᵣ(_∘_)(id) (_)(_) ] id 🝖-end where open Isomorphism(f) open Isomorphism(g) instance Isomorphic-reflexivity : Reflexivity(Isomorphic) ∃.witness (Reflexivity.proof Isomorphic-reflexivity) = id ∃.proof (Reflexivity.proof Isomorphic-reflexivity) = id-automorphism instance Isomorphic-symmetry : Symmetry(Isomorphic) ∃.witness (Symmetry.proof Isomorphic-symmetry iso-xy) = inv(∃.witness iso-xy) ∃.proof (Symmetry.proof Isomorphic-symmetry iso-xy) = inverse-isomorphism(∃.witness iso-xy) module _ ⦃ op : ∀{x y z} → BinaryOperator(_∘_ {x}{y}{z}) ⦄ where instance Isomorphic-transitivity : Transitivity(Isomorphic) ∃.witness (Transitivity.proof Isomorphic-transitivity ([∃]-intro xy) ([∃]-intro yz)) = yz ∘ xy ∃.proof (Transitivity.proof Isomorphic-transitivity ([∃]-intro xy) ([∃]-intro yz)) = op-closed-under-isomorphism ⦃ op ⦄ yz xy instance Isomorphic-equivalence : Equivalence(Isomorphic) Isomorphic-equivalence = record{}
{ "alphanum_fraction": 0.6258462764, "avg_line_length": 44.8392857143, "ext": "agda", "hexsha": "e1732defcce2283399030afa6a3549832a2a8809", "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/Category/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": "Structure/Category/Proofs.agda", "max_line_length": 147, "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/Category/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": 1922, "size": 5022 }
module OscarEverything where open import OscarPrelude open import HasSubstantiveDischarge
{ "alphanum_fraction": 0.8901098901, "avg_line_length": 18.2, "ext": "agda", "hexsha": "5e61e05a5b929dc0c4483ab96736888cffe2ff46", "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/OscarEverything.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/OscarEverything.agda", "max_line_length": 35, "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/OscarEverything.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 20, "size": 91 }
{-# OPTIONS --cubical --safe #-} module Cardinality.Finite.SplitEnumerable.Instances where open import Cardinality.Finite.SplitEnumerable open import Cardinality.Finite.SplitEnumerable.Inductive open import Cardinality.Finite.ManifestBishop using (_|Π|_) open import Data.Fin open import Prelude open import Data.List.Membership open import Data.Tuple import Data.Unit.UniversePolymorphic as Poly private infixr 4 _?×_ data _?×_ (A : Type a) (B : Type b) : Type (a ℓ⊔ b) where pair : A → B → A ?× B instance poly-inst : ∀ {a} → Poly.⊤ {a} poly-inst = Poly.tt module _ {a b} {A : Type a} (B : A → Type b) where Im-Type : (xs : List A) → Type (a ℓ⊔ b) Im-Type = foldr (λ x xs → ℰ! (B x) ?× xs) Poly.⊤ Tup-Im-Lookup : ∀ x (xs : List A) → x ∈ xs → Im-Type xs → ℰ! (B x) Tup-Im-Lookup x (y ∷ xs) (f0 , y≡x ) (pair ℰ!⟨Bx⟩ _) = subst (ℰ! ∘ B) y≡x ℰ!⟨Bx⟩ Tup-Im-Lookup x (y ∷ xs) (fs n , x∈ys) (pair _ tup) = Tup-Im-Lookup x xs (n , x∈ys) tup Tup-Im-Pi : (xs : ℰ! A) → Im-Type (xs .fst) → ∀ x → ℰ! (B x) Tup-Im-Pi xs tup x = Tup-Im-Lookup x (xs .fst) (xs .snd x) tup instance inst-pair : ⦃ lhs : A ⦄ ⦃ rhs : B ⦄ → A ?× B inst-pair ⦃ lhs ⦄ ⦃ rhs ⦄ = pair lhs rhs instance fin-sigma : ⦃ lhs : ℰ! A ⦄ {B : A → Type b} → ⦃ rhs : Im-Type B (lhs .fst) ⦄ → ℰ! (Σ A B) fin-sigma ⦃ lhs ⦄ ⦃ rhs ⦄ = lhs |Σ| Tup-Im-Pi _ lhs rhs instance fin-pi : ⦃ lhs : ℰ! A ⦄ {B : A → Type b} → ⦃ rhs : Im-Type B (lhs .fst) ⦄ → (ℰ! ((x : A) → B x)) fin-pi ⦃ lhs ⦄ ⦃ rhs ⦄ = lhs |Π| Tup-Im-Pi _ lhs rhs -- instance -- fin-prod : ⦃ lhs : ℰ! A ⦄ ⦃ rhs : ℰ! B ⦄ → ℰ! (A × B) -- fin-prod ⦃ lhs ⦄ ⦃ rhs ⦄ = lhs |×| rhs -- instance -- fin-fun : {A B : Type₀} ⦃ lhs : ℰ! A ⦄ ⦃ rhs : ℰ! B ⦄ → ℰ! (A → B) -- fin-fun ⦃ lhs ⦄ ⦃ rhs ⦄ = lhs |Π| λ _ → rhs instance fin-sum : ⦃ lhs : ℰ! A ⦄ ⦃ rhs : ℰ! B ⦄ → ℰ! (A ⊎ B) fin-sum ⦃ lhs ⦄ ⦃ rhs ⦄ = lhs |⊎| rhs instance fin-bool : ℰ! Bool fin-bool = ℰ!⟨2⟩ instance fin-top : ℰ! ⊤ fin-top = ℰ!⟨⊤⟩ instance fin-bot : ℰ! ⊥ fin-bot = ℰ!⟨⊥⟩ instance fin-fin : ∀ {n} → ℰ! (Fin n) fin-fin = ℰ!⟨Fin⟩
{ "alphanum_fraction": 0.5464612422, "avg_line_length": 27.6933333333, "ext": "agda", "hexsha": "6a7f2197c3641caff8c2f4e1292da38cbd0978f2", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z", "max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "oisdk/combinatorics-paper", "max_forks_repo_path": "agda/Cardinality/Finite/SplitEnumerable/Instances.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/combinatorics-paper", "max_issues_repo_path": "agda/Cardinality/Finite/SplitEnumerable/Instances.agda", "max_line_length": 98, "max_stars_count": 4, "max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "oisdk/combinatorics-paper", "max_stars_repo_path": "agda/Cardinality/Finite/SplitEnumerable/Instances.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z", "max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z", "num_tokens": 996, "size": 2077 }
-- 2012-03-08 Andreas module _ where {-# TERMINATING #-} -- error: misplaced pragma
{ "alphanum_fraction": 0.6744186047, "avg_line_length": 12.2857142857, "ext": "agda", "hexsha": "e532db62b7ff029fc3ec5c7b7911a48144db0f3f", "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/NoTerminationCheck5.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/NoTerminationCheck5.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/Succeed/NoTerminationCheck5.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": 24, "size": 86 }
-- Andreas, 2014-01-16, issue 1406 -- Agda with K again is inconsistent with classical logic -- {-# OPTIONS --cubical-compatible #-} open import Common.Level open import Common.Prelude open import Common.Equality cast : {A B : Set} (p : A ≡ B) (a : A) → B cast refl a = a data HEq {α} {A : Set α} (a : A) : {B : Set α} (b : B) → Set (lsuc α) where refl : HEq a a mkHet : {A B : Set} (eq : A ≡ B) (a : A) → HEq a (cast eq a) mkHet refl a = refl -- Type with a big forced index. (Allowed unless --cubical-compatible.) -- This definition is allowed in Agda master since 2014-10-17 -- https://github.com/agda/agda/commit/9a4ebdd372dc0510e2d77e726fb0f4e6f56781e8 -- However, probably the consequences of this new feature have not -- been grasped fully yet. data SING : (F : Set → Set) → Set where sing : (F : Set → Set) → SING F -- The following theorem is the culprit. -- It needs K. -- It allows us to unify forced indices, which I think is wrong. thm : ∀{F G : Set → Set} (a : SING F) (b : SING G) (p : HEq a b) → F ≡ G thm (sing F) (sing .F) refl = refl -- Note that a direct matching fails, as it generates heterogeneous constraints. -- thm a .a refl = refl -- However, by matching on the constructor sing, the forced index -- is exposed to unification. -- As a consequence of thm, -- SING is injective which it clearly should not be. SING-inj : ∀ (F G : Set → Set) (p : SING F ≡ SING G) → F ≡ G SING-inj F G p = thm (sing F) _ (mkHet p (sing F)) -- The rest is an adaption of Chung-Kil Hur's proof (2010) data Either {α} (A B : Set α) : Set α where inl : A → Either A B inr : B → Either A B data Inv (A : Set) : Set1 where inv : (F : Set → Set) (eq : SING F ≡ A) → Inv A ¬ : ∀{α} → Set α → Set α ¬ A = A → ⊥ -- Classical logic postulate em : ∀{α} (A : Set α) → Either A (¬ A) Cantor' : (A : Set) → Either (Inv A) (¬ (Inv A)) → Set Cantor' A (inl (inv F eq)) = ¬ (F A) Cantor' A (inr _) = ⊤ Cantor : Set → Set Cantor A = Cantor' A (em (Inv A)) C : Set C = SING Cantor ic : Inv C ic = inv Cantor refl cast' : ∀{F G} → SING F ≡ SING G → ¬ (F C) → ¬ (G C) cast' eq = subst (λ F → ¬ (F C)) (SING-inj _ _ eq) -- Self application 1 diag : ¬ (Cantor C) diag c with em (Inv C) | c diag c | inl (inv F eq) | c' = cast' eq c' c diag _ | inr f | _ = f ic -- Self application 2 diag' : Cantor C diag' with em (Inv C) diag' | inl (inv F eq) = cast' (sym eq) diag diag' | inr _ = _ absurd : ⊥ absurd = diag diag'
{ "alphanum_fraction": 0.603406326, "avg_line_length": 26.8043478261, "ext": "agda", "hexsha": "cb886a6dc1374a026311ba866745cfbf825dee33", "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/Issue1406.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/Issue1406.agda", "max_line_length": 80, "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/Issue1406.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 908, "size": 2466 }
{-# OPTIONS --cubical-compatible #-} ------------------------------------------------------------------------ -- Universe levels ------------------------------------------------------------------------ module Common.Level where open import Agda.Primitive public using (Level; lzero; lsuc; _⊔_) -- Lifting. record Lift {a ℓ} (A : Set a) : Set (a ⊔ ℓ) where constructor lift field lower : A open Lift public
{ "alphanum_fraction": 0.443373494, "avg_line_length": 24.4117647059, "ext": "agda", "hexsha": "28d2d09fb071791e5abf05d09813abd0eca530ca", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_forks_repo_licenses": [ "BSD-2-Clause" ], "max_forks_repo_name": "KDr2/agda", "max_forks_repo_path": "test/Common/Level.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z", "max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z", "max_issues_repo_licenses": [ "BSD-2-Clause" ], "max_issues_repo_name": "KDr2/agda", "max_issues_repo_path": "test/Common/Level.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75", "max_stars_repo_licenses": [ "BSD-2-Clause" ], "max_stars_repo_name": "KDr2/agda", "max_stars_repo_path": "test/Common/Level.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 86, "size": 415 }
{- 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 -} {-# OPTIONS --allow-unsolved-metas #-} -- This module provides some scaffolding to define the handlers for our fake/simple "implementation" -- and connect them to the interface of the SystemModel. open import Optics.All open import LibraBFT.Prelude open import LibraBFT.Lemmas open import LibraBFT.Base.ByteString open import LibraBFT.Base.Encode open import LibraBFT.Base.KVMap open import LibraBFT.Base.PKCS open import LibraBFT.Hash open import LibraBFT.Impl.Base.Types open import LibraBFT.Impl.Consensus.Types open import LibraBFT.Impl.Util.Util open import LibraBFT.Impl.Properties.Aux -- TODO-1: maybe Aux properties should be in this file? open import LibraBFT.Concrete.System impl-sps-avp open import LibraBFT.Concrete.System.Parameters open EpochConfig open import LibraBFT.Yasm.Yasm (ℓ+1 0ℓ) EpochConfig epochId authorsN ConcSysParms NodeId-PK-OK open Structural impl-sps-avp module LibraBFT.Impl.Handle.Properties (hash : BitString → Hash) (hash-cr : ∀{x y} → hash x ≡ hash y → Collision hash x y ⊎ x ≡ y) where open import LibraBFT.Impl.Consensus.ChainedBFT.EventProcessor hash hash-cr open import LibraBFT.Impl.Handle hash hash-cr ----- Properties that bridge the system model gap to the handler ----- msgsToSendWereSent1 : ∀ {pid ts pm vm} {st : EventProcessor} → send (V vm) ∈ proj₂ (peerStep pid (P pm) ts st) → ∃[ αs ] (SendVote vm αs ∈ LBFT-outs (handle pid (P pm) ts) st) msgsToSendWereSent1 {pid} {ts} {pm} {vm} {st} send∈acts with send∈acts -- The fake handler sends only to node 0 (fakeAuthor), so this doesn't -- need to be very general yet. -- TODO-1: generalize this proof so it will work when the set of recipients is -- not hard coded. -- The system model allows any message sent to be received by any peer (so the list of -- recipients it essentially ignored), meaning that our safety proofs will be for a slightly -- stronger model. Progress proofs will require knowledge of recipients, though, so we will -- keep the implementation model faithful to the implementation. ...| here refl = fakeAuthor ∷ [] , here refl msgsToSendWereSent : ∀ {pid ts nm m} {st : EventProcessor} → m ∈ proj₂ (peerStepWrapper pid nm st) → ∃[ vm ] (m ≡ V vm × send (V vm) ∈ proj₂ (peerStep pid nm ts st)) msgsToSendWereSent {pid} {nm = nm} {m} {st} m∈outs with nm ...| C _ = ⊥-elim (¬Any[] m∈outs) ...| V _ = ⊥-elim (¬Any[] m∈outs) ...| P pm with m∈outs ...| here v∈outs with m ...| P _ = ⊥-elim (P≢V v∈outs) ...| C _ = ⊥-elim (C≢V v∈outs) ...| V vm rewrite sym v∈outs = vm , refl , here refl ----- Properties that relate handler to system state ----- postulate -- TODO-2: this will be proved for the implementation, confirming that honest -- participants only store QCs comprising votes that have actually been sent. -- Votes stored in highesQuorumCert and highestCommitCert were sent before. -- Note that some implementations might not ensure this, but LibraBFT does -- because even the leader of the next round sends its own vote to itself, -- as opposed to using it to construct a QC using its own unsent vote. qcVotesSentB4 : ∀{e pid ps vs pk q vm}{st : SystemState e} → ReachableSystemState st → initialised st pid ≡ initd → ps ≡ peerStates st pid → q QC∈VoteMsg vm → vm ^∙ vmSyncInfo ≡ mkSyncInfo (ps ^∙ epHighestQC) (ps ^∙ epHighestCommitQC) → vs ∈ qcVotes q → MsgWithSig∈ pk (proj₂ vs) (msgPool st)
{ "alphanum_fraction": 0.6690482266, "avg_line_length": 45.5697674419, "ext": "agda", "hexsha": "a651ec4114ab928bd47e99a7e666806bc2be8265", "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": "34e4627855fb198665d0c98f377403a906ba75d7", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "haroldcarr/bft-consensus-agda", "max_forks_repo_path": "LibraBFT/Impl/Handle/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7", "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": "haroldcarr/bft-consensus-agda", "max_issues_repo_path": "LibraBFT/Impl/Handle/Properties.agda", "max_line_length": 111, "max_stars_count": null, "max_stars_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "haroldcarr/bft-consensus-agda", "max_stars_repo_path": "LibraBFT/Impl/Handle/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1107, "size": 3919 }
module utm where open import turing open import Data.Product -- open import Data.Bool open import Data.List open import Data.Nat open import logic data utmStates : Set where reads : utmStates read0 : utmStates read1 : utmStates read2 : utmStates read3 : utmStates read4 : utmStates read5 : utmStates read6 : utmStates loc0 : utmStates loc1 : utmStates loc2 : utmStates loc3 : utmStates loc4 : utmStates loc5 : utmStates loc6 : utmStates fetch0 : utmStates fetch1 : utmStates fetch2 : utmStates fetch3 : utmStates fetch4 : utmStates fetch5 : utmStates fetch6 : utmStates fetch7 : utmStates print0 : utmStates print1 : utmStates print2 : utmStates print3 : utmStates print4 : utmStates print5 : utmStates print6 : utmStates print7 : utmStates mov0 : utmStates mov1 : utmStates mov2 : utmStates mov3 : utmStates mov4 : utmStates mov5 : utmStates mov6 : utmStates tidy0 : utmStates tidy1 : utmStates halt : utmStates data utmΣ : Set where 0 : utmΣ 1 : utmΣ B : utmΣ * : utmΣ $ : utmΣ ^ : utmΣ X : utmΣ Y : utmΣ Z : utmΣ @ : utmΣ b : utmΣ utmδ : utmStates → utmΣ → utmStates × (Write utmΣ) × Move utmδ reads x = read0 , wnone , mnone utmδ read0 * = read1 , write * , left utmδ read0 x = read0 , write x , right utmδ read1 x = read2 , write @ , right utmδ read2 ^ = read3 , write ^ , right utmδ read2 x = read2 , write x , right utmδ read3 0 = read4 , write 0 , left utmδ read3 1 = read5 , write 1 , left utmδ read3 b = read6 , write b , left utmδ read4 @ = loc0 , write 0 , right utmδ read4 x = read4 , write x , left utmδ read5 @ = loc0 , write 1 , right utmδ read5 x = read5 , write x , left utmδ read6 @ = loc0 , write B , right utmδ read6 x = read6 , write x , left utmδ loc0 0 = loc0 , write X , left utmδ loc0 1 = loc0 , write Y , left utmδ loc0 B = loc0 , write Z , left utmδ loc0 $ = loc1 , write $ , right utmδ loc0 x = loc0 , write x , left utmδ loc1 X = loc2 , write 0 , right utmδ loc1 Y = loc3 , write 1 , right utmδ loc1 Z = loc4 , write B , right utmδ loc1 * = fetch0 , write * , right utmδ loc1 x = loc1 , write x , right utmδ loc2 0 = loc5 , write X , right utmδ loc2 1 = loc6 , write Y , right utmδ loc2 B = loc6 , write Z , right utmδ loc2 x = loc2 , write x , right utmδ loc3 1 = loc5 , write Y , right utmδ loc3 0 = loc6 , write X , right utmδ loc3 B = loc6 , write Z , right utmδ loc3 x = loc3 , write x , right utmδ loc4 B = loc5 , write Z , right utmδ loc4 0 = loc6 , write X , right utmδ loc4 1 = loc6 , write Y , right utmδ loc4 x = loc4 , write x , right utmδ loc5 $ = loc1 , write $ , right utmδ loc5 x = loc5 , write x , left utmδ loc6 $ = halt , write $ , right utmδ loc6 * = loc0 , write * , left utmδ loc6 x = loc6 , write x , right utmδ fetch0 0 = fetch1 , write X , left utmδ fetch0 1 = fetch2 , write Y , left utmδ fetch0 B = fetch3 , write Z , left utmδ fetch0 x = fetch0 , write x , right utmδ fetch1 $ = fetch4 , write $ , right utmδ fetch1 x = fetch1 , write x , left utmδ fetch2 $ = fetch5 , write $ , right utmδ fetch2 x = fetch2 , write x , left utmδ fetch3 $ = fetch6 , write $ , right utmδ fetch3 x = fetch3 , write x , left utmδ fetch4 0 = fetch7 , write X , right utmδ fetch4 1 = fetch7 , write X , right utmδ fetch4 B = fetch7 , write X , right utmδ fetch4 * = print0 , write * , left utmδ fetch4 x = fetch4 , write x , right utmδ fetch5 0 = fetch7 , write Y , right utmδ fetch5 1 = fetch7 , write Y , right utmδ fetch5 B = fetch7 , write Y , right utmδ fetch5 * = print0 , write * , left utmδ fetch5 x = fetch5 , write x , right utmδ fetch6 0 = fetch7 , write Z , right utmδ fetch6 1 = fetch7 , write Z , right utmδ fetch6 B = fetch7 , write Z , right utmδ fetch6 * = print0 , write * , left utmδ fetch6 x = fetch6 , write x , right utmδ fetch7 * = fetch0 , write * , right utmδ fetch7 x = fetch7 , write x , right utmδ print0 X = print1 , write X , right utmδ print0 Y = print2 , write Y , right utmδ print0 Z = print3 , write Z , right utmδ print1 ^ = print4 , write ^ , right utmδ print1 x = print1 , write x , right utmδ print2 ^ = print5 , write ^ , right utmδ print2 x = print2 , write x , right utmδ print3 ^ = print6 , write ^ , right utmδ print3 x = print3 , write x , right utmδ print4 x = print7 , write 0 , left utmδ print5 x = print7 , write 1 , left utmδ print6 x = print7 , write B , left utmδ print7 X = mov0 , write X , right utmδ print7 Y = mov1 , write Y , right utmδ print7 x = print7 , write x , left utmδ mov0 ^ = mov2 , write ^ , left utmδ mov0 x = mov0 , write x , right utmδ mov1 ^ = mov3 , write ^ , right utmδ mov1 x = mov1 , write x , right utmδ mov2 0 = mov4 , write ^ , right utmδ mov2 1 = mov5 , write ^ , right utmδ mov2 B = mov6 , write ^ , right utmδ mov3 0 = mov4 , write ^ , left utmδ mov3 1 = mov5 , write ^ , left utmδ mov3 B = mov6 , write ^ , left utmδ mov4 ^ = tidy0 , write 0 , left utmδ mov5 ^ = tidy0 , write 1 , left utmδ mov6 ^ = tidy0 , write B , left utmδ tidy0 $ = tidy1 , write $ , left utmδ tidy0 x = tidy0 , write x , left utmδ tidy1 X = tidy1 , write 0 , left utmδ tidy1 Y = tidy1 , write 1 , left utmδ tidy1 Z = tidy1 , write B , left utmδ tidy1 $ = reads , write $ , right utmδ tidy1 x = tidy1 , write x , left utmδ _ x = halt , write x , mnone U-TM : Turing utmStates utmΣ U-TM = record { tδ = utmδ ; tstart = read0 ; tend = tend ; tnone = b } where tend : utmStates → Bool tend halt = true tend _ = false -- Copyδ : CopyStates → ℕ → CopyStates × ( Write ℕ ) × Move -- Copyδ s1 0 = H , wnone , mnone -- Copyδ s1 1 = s2 , write 0 , right -- Copyδ s2 0 = s3 , write 0 , right -- Copyδ s2 1 = s2 , write 1 , right -- Copyδ s3 0 = s4 , write 1 , left -- Copyδ s3 1 = s3 , write 1 , right -- Copyδ s4 0 = s5 , write 0 , left -- Copyδ s4 1 = s4 , write 1 , left -- Copyδ s5 0 = s1 , write 1 , right -- Copyδ s5 1 = s5 , write 1 , left -- Copyδ H _ = H , wnone , mnone -- Copyδ _ (suc (suc _)) = H , wnone , mnone Copyδ-encode : List utmΣ Copyδ-encode = 0 ∷ 0 ∷ 1 ∷ 0 ∷ 1 ∷ 1 ∷ 0 ∷ 0 ∷ 0 ∷ 0 ∷ -- s1 0 = H , wnone , mnone * ∷ 0 ∷ 0 ∷ 1 ∷ 1 ∷ 0 ∷ 1 ∷ 0 ∷ 0 ∷ 0 ∷ 1 ∷ -- s1 1 = s2 , write 0 , right * ∷ 0 ∷ 1 ∷ 0 ∷ 0 ∷ 0 ∷ 1 ∷ 1 ∷ 0 ∷ 0 ∷ 1 ∷ -- s2 0 = s3 , write 0 , right * ∷ 0 ∷ 1 ∷ 0 ∷ 1 ∷ 0 ∷ 1 ∷ 0 ∷ 1 ∷ 0 ∷ 1 ∷ -- s2 1 = s2 , write 1 , right * ∷ 0 ∷ 1 ∷ 1 ∷ 0 ∷ 1 ∷ 0 ∷ 0 ∷ 1 ∷ 0 ∷ 0 ∷ -- s3 0 = s4 , write 1 , left * ∷ 0 ∷ 1 ∷ 1 ∷ 1 ∷ 0 ∷ 1 ∷ 1 ∷ 1 ∷ 0 ∷ 1 ∷ -- s3 1 = s3 , write 1 , right * ∷ 1 ∷ 0 ∷ 0 ∷ 0 ∷ 1 ∷ 0 ∷ 1 ∷ 0 ∷ 0 ∷ 0 ∷ -- s4 0 = s5 , write 0 , left * ∷ 1 ∷ 0 ∷ 0 ∷ 1 ∷ 1 ∷ 0 ∷ 0 ∷ 1 ∷ 0 ∷ 0 ∷ -- s4 1 = s4 , write 1 , left * ∷ 1 ∷ 0 ∷ 1 ∷ 0 ∷ 0 ∷ 0 ∷ 1 ∷ 1 ∷ 0 ∷ 1 ∷ -- s5 0 = s1 , write 1 , right * ∷ 1 ∷ 0 ∷ 1 ∷ 1 ∷ 1 ∷ 0 ∷ 1 ∷ 1 ∷ 0 ∷ 0 ∷ -- s5 1 = s5 , write 1 , left [] input-encode : List utmΣ input-encode = 1 ∷ 1 ∷ 0 ∷ 0 ∷ 0 ∷ [] input+Copyδ : List utmΣ input+Copyδ = ( $ ∷ 0 ∷ 0 ∷ 0 ∷ 0 ∷ * ∷ [] ) -- start state ++ Copyδ-encode ++ ( $ ∷ ^ ∷ input-encode ) short-input : List utmΣ short-input = $ ∷ 0 ∷ 0 ∷ 0 ∷ * ∷ 0 ∷ 0 ∷ 0 ∷ 1 ∷ 0 ∷ 1 ∷ 1 ∷ * ∷ 0 ∷ 0 ∷ 1 ∷ 0 ∷ 1 ∷ 1 ∷ 1 ∷ * ∷ 0 ∷ 1 ∷ B ∷ 1 ∷ 0 ∷ 1 ∷ 0 ∷ * ∷ 1 ∷ 0 ∷ 0 ∷ 0 ∷ 1 ∷ 1 ∷ 1 ∷ $ ∷ ^ ∷ 0 ∷ 0 ∷ 1 ∷ 1 ∷ [] utm-test1 : List utmΣ → utmStates × ( List utmΣ ) × ( List utmΣ ) utm-test1 inp = Turing.taccept U-TM inp {-# TERMINATING #-} utm-test2 : ℕ → List utmΣ → utmStates × ( List utmΣ ) × ( List utmΣ ) utm-test2 n inp = loop n (Turing.tstart U-TM) inp [] where loop : ℕ → utmStates → ( List utmΣ ) → ( List utmΣ ) → utmStates × ( List utmΣ ) × ( List utmΣ ) loop zero q L R = ( q , L , R ) loop (suc n) q L R with move {utmStates} {utmΣ} {0} {utmδ} q L R | q ... | nq , nL , nR | reads = loop n nq nL nR ... | nq , nL , nR | _ = loop (suc n) nq nL nR t1 = utm-test2 20 short-input t : (n : ℕ) → utmStates × ( List utmΣ ) × ( List utmΣ ) -- t n = utm-test2 n input+Copyδ t n = utm-test2 n short-input
{ "alphanum_fraction": 0.5519511048, "avg_line_length": 33.7619047619, "ext": "agda", "hexsha": "d1cf16a614597a513781f4326b4dfffef1ec84f2", "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/utm.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/utm.agda", "max_line_length": 109, "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/utm.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3806, "size": 8508 }
{-# OPTIONS --safe #-} module Cubical.HITs.TypeQuotients where open import Cubical.HITs.TypeQuotients.Base public open import Cubical.HITs.TypeQuotients.Properties public
{ "alphanum_fraction": 0.8139534884, "avg_line_length": 28.6666666667, "ext": "agda", "hexsha": "0059b89aad88427f7905daf7ada60c4f391a7c57", "lang": "Agda", "max_forks_count": 134, "max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z", "max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z", "max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "marcinjangrzybowski/cubical", "max_forks_repo_path": "Cubical/HITs/TypeQuotients.agda", "max_issues_count": 584, "max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z", "max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "marcinjangrzybowski/cubical", "max_issues_repo_path": "Cubical/HITs/TypeQuotients.agda", "max_line_length": 56, "max_stars_count": 301, "max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "marcinjangrzybowski/cubical", "max_stars_repo_path": "Cubical/HITs/TypeQuotients.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z", "num_tokens": 45, "size": 172 }
data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x cong : ∀ {A B : Set} (f : A → B) {x y : A} → x ≡ y → f x ≡ f y cong f refl = refl data ℕ : Set where zero : ℕ suc : ℕ → ℕ data Fin : ℕ → Set where zero : {n : ℕ} → Fin (suc n) suc : {n : ℕ} (i : Fin n) → Fin (suc n) data _≤_ : ℕ → ℕ → Set where zero : ∀ {n} → zero ≤ n suc : ∀ {m n} (le : m ≤ n) → suc m ≤ suc n _<_ : ℕ → ℕ → Set m < n = suc m ≤ n toℕ : ∀ {n} → Fin n → ℕ toℕ zero = zero toℕ (suc i) = suc (toℕ i) fromℕ≤ : ∀ {m n} → m < n → Fin n fromℕ≤ (suc zero) = zero fromℕ≤ (suc (suc m≤n)) = suc (fromℕ≤ (suc m≤n)) -- If we treat constructors as inert this fails to solve. Not entirely sure why. fromℕ≤-toℕ : ∀ {m} (i : Fin m) (i<m : toℕ i < m) → fromℕ≤ i<m ≡ i fromℕ≤-toℕ zero (suc zero) = refl fromℕ≤-toℕ (suc i) (suc (suc m≤n)) = cong suc (fromℕ≤-toℕ i (suc m≤n))
{ "alphanum_fraction": 0.4853603604, "avg_line_length": 25.3714285714, "ext": "agda", "hexsha": "b798db037c86a1163f28d76558c877f934d6cbbc", "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/InertFailure.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/InertFailure.agda", "max_line_length": 80, "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/InertFailure.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": 435, "size": 888 }
{-# OPTIONS --no-positivity-check #-} module IIRDg where import LF import DefinitionalEquality import IIRD open LF open DefinitionalEquality open IIRD mutual data Ug {I : Set}{D : I -> Set1}(γ : OPg I D) : I -> Set where introg : (a : Gu γ (Ug γ) (Tg γ)) -> Ug γ (Gi γ (Ug γ) (Tg γ) a) Tg : {I : Set}{D : I -> Set1}(γ : OPg I D)(i : I) -> Ug γ i -> D i Tg γ .(Gi γ (Ug γ) (Tg γ) a) (introg a) = Gt γ (Ug γ) (Tg γ) a Arg : {I : Set}{D : I -> Set1}(γ : OPg I D) -> Set Arg γ = Gu γ (Ug γ) (Tg γ) index : {I : Set}{D : I -> Set1}(γ : OPg I D) -> Arg γ -> I index γ a = Gi γ (Ug γ) (Tg γ) a IH : {I : Set}{D : I -> Set1}(γ : OPg I D)(F : (i : I) -> Ug γ i -> Set1) -> Arg γ -> Set1 IH γ = KIH γ (Ug γ) (Tg γ) -- Elimination rule Rg : {I : Set}{D : I -> Set1}(γ : OPg I D)(F : (i : I) -> Ug γ i -> Set1) -> (h : (a : Arg γ) -> IH γ F a -> F (index γ a) (introg a)) -> (i : I)(u : Ug γ i) -> F i u Rg γ F h .(index γ a) (introg a) = h a (Kmap γ (Ug γ) (Tg γ) F (Rg γ F h) a) {- -- We don't have general IIRDs so we have to postulate Ug/Tg postulate Ug : {I : Set}{D : I -> Set1} -> OPg I D -> I -> Set Tg : {I : Set}{D : I -> Set1}(γ : OPg I D)(i : I) -> Ug γ i -> D i introg : {I : Set}{D : I -> Set1}(γ : OPg I D)(a : Gu γ (Ug γ) (Tg γ)) -> Ug γ (Gi γ (Ug γ) (Tg γ) a) Tg-equality : {I : Set}{D : I -> Set1}(γ : OPg I D)(a : Gu γ (Ug γ) (Tg γ)) -> Tg γ (Gi γ (Ug γ) (Tg γ) a) (introg γ a) ≡₁ Gt γ (Ug γ) (Tg γ) a Rg : {I : Set}{D : I -> Set1}(γ : OPg I D)(F : (i : I) -> Ug γ i -> Set1) (h : (a : Gu γ (Ug γ) (Tg γ)) -> KIH γ (Ug γ) (Tg γ) F a -> F (Gi γ (Ug γ) (Tg γ) a) (introg γ a)) (i : I)(u : Ug γ i) -> F i u Rg-equality : {I : Set}{D : I -> Set1}(γ : OPg I D)(F : (i : I) -> Ug γ i -> Set1) (h : (a : Gu γ (Ug γ) (Tg γ)) -> KIH γ (Ug γ) (Tg γ) F a -> F (Gi γ (Ug γ) (Tg γ) a) (introg γ a)) (a : Gu γ (Ug γ) (Tg γ)) -> Rg γ F h (Gi γ (Ug γ) (Tg γ) a) (introg γ a) ≡₁ h a (Kmap γ (Ug γ) (Tg γ) F (Rg γ F h) a) -- Helpers ι★g : {I : Set}(i : I) -> OPg I (\_ -> One') ι★g i = ι < i | ★' >' -- Examples module Martin-Löf-Identity where IdOP : {A : Set} -> OPg (A * A) (\_ -> One') IdOP {A} = σ A \a -> ι★g < a | a > _==_ : {A : Set}(x y : A) -> Set x == y = Ug IdOP < x | y > refl : {A : Set}(x : A) -> x == x refl x = introg IdOP < x | ★ > -- We have to work slightly harder than desired since we don't have η for × and One. private -- F C is just uncurry C but dependent and at high universes. F : {A : Set}(C : (x y : A) -> x == y -> Set1)(i : A * A) -> Ug IdOP i -> Set1 F C < x | y > p = C x y p h' : {A : Set}(C : (x y : A) -> x == y -> Set1) (h : (x : A) -> C x x (refl x)) (a : Gu IdOP (Ug IdOP) (Tg IdOP)) -> KIH IdOP (Ug IdOP) (Tg IdOP) (F C) a -> F C (Gi IdOP (Ug IdOP) (Tg IdOP) a) (introg IdOP a) h' C h < x | ★ > _ = h x J : {A : Set}(C : (x y : A) -> x == y -> Set1) (h : (x : A) -> C x x (refl x)) (x y : A)(p : x == y) -> C x y p J {A} C h x y p = Rg IdOP (F C) (h' C h) < x | y > p J-equality : {A : Set}(C : (x y : A) -> x == y -> Set1) (h : (x : A) -> C x x (refl x))(x : A) -> J C h x x (refl x) ≡₁ h x J-equality {A} C h x = Rg-equality IdOP (F C) (h' C h) < x | ★ > module Christine-Identity where IdOP : {A : Set}(a : A) -> OPg A (\_ -> One') IdOP {A} a = ι★g a _==_ : {A : Set}(x y : A) -> Set x == y = Ug (IdOP x) y refl : {A : Set}(x : A) -> x == x refl x = introg (IdOP x) ★ private h' : {A : Set}(x : A)(C : (y : A) -> x == y -> Set1) (h : C x (refl x))(a : Gu (IdOP x) (Ug (IdOP x)) (Tg (IdOP x))) -> KIH (IdOP x) (Ug (IdOP x)) (Tg (IdOP x)) C a -> C (Gi (IdOP x) (Ug (IdOP x)) (Tg (IdOP x)) a) (introg (IdOP x) a) h' x C h ★ _ = h H : {A : Set}(x : A)(C : (y : A) -> x == y -> Set1) (h : C x (refl x)) (y : A)(p : x == y) -> C y p H x C h y p = Rg (IdOP x) C (h' x C h) y p H-equality : {A : Set}(x : A)(C : (y : A) -> x == y -> Set1) (h : C x (refl x)) -> H x C h x (refl x) ≡₁ h H-equality x C h = Rg-equality (IdOP x) C (h' x C h) ★ open Christine-Identity -}
{ "alphanum_fraction": 0.4285380117, "avg_line_length": 33.3984375, "ext": "agda", "hexsha": "0c37d688e7716190419f7dac82fcb639976046bc", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "examples/outdated-and-incorrect/iird/IIRDg.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "examples/outdated-and-incorrect/iird/IIRDg.agda", "max_line_length": 114, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "examples/outdated-and-incorrect/iird/IIRDg.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": 1955, "size": 4275 }
module Oscar.Category.Setoid where open import Oscar.Builtin.Objectevel open import Oscar.Property record IsSetoid {𝔬} {𝔒 : Ø 𝔬} {𝔮} (_≋_ : 𝑴 1 𝔒 𝔮) : Ø 𝔬 ∙̂ 𝔮 where field reflexivity : ∀ x → x ≋ x symmetry : ∀ {x y} → x ≋ y → y ≋ x transitivity : ∀ {x y} → x ≋ y → ∀ {z} → y ≋ z → x ≋ z open IsSetoid ⦃ … ⦄ public record Setoid 𝔬 𝔮 : Ø ↑̂ (𝔬 ∙̂ 𝔮) where constructor ↑_ infix 4 _≋_ field {⋆} : Set 𝔬 _≋_ : ⋆ → ⋆ → Set 𝔮 ⦃ isSetoid ⦄ : IsSetoid _≋_ open IsSetoid isSetoid public
{ "alphanum_fraction": 0.5628626692, "avg_line_length": 22.4782608696, "ext": "agda", "hexsha": "e043e266dc74927ea8a92e02027261277b78f1ec", "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/Category/Setoid.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/Category/Setoid.agda", "max_line_length": 66, "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/Category/Setoid.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 255, "size": 517 }
module _ where data Flat (A : Set) : Set where flat : @♭ A → Flat A -- the lambda cohesion annotation must match the domain. into : {A : Set} → A → Flat A into = λ (@♭ a) → flat a
{ "alphanum_fraction": 0.6086956522, "avg_line_length": 20.4444444444, "ext": "agda", "hexsha": "3d042242579ded224959de5edee318512b4d9230", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z", "max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.000Z", "max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "Agda-zh/agda", "max_forks_repo_path": "test/Fail/Issue3945.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Fail/Issue3945.agda", "max_line_length": 56, "max_stars_count": 2, "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/Issue3945.agda", "max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z", "max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z", "num_tokens": 61, "size": 184 }
{-# OPTIONS --cubical --safe #-} module Data.String where open import Agda.Builtin.String using (String) public open import Agda.Builtin.String open import Agda.Builtin.String.Properties open import Agda.Builtin.Char using (Char) public open import Agda.Builtin.Char open import Agda.Builtin.Char.Properties open import Relation.Binary open import Relation.Binary.Construct.On import Data.Nat.Order as ℕ open import Function.Injective open import Function open import Path open import Data.List open import Data.List.Relation.Binary.Lexicographic unpack : String → List Char unpack = primStringToList pack : List Char → String pack = primStringFromList charOrd : TotalOrder Char _ _ charOrd = on-ord primCharToNat lemma ℕ.totalOrder where lemma : Injective primCharToNat lemma x y p = builtin-eq-to-path (primCharToNatInjective x y (path-to-builtin-eq p )) listCharOrd : TotalOrder (List Char) _ _ listCharOrd = listOrd charOrd stringOrd : TotalOrder String _ _ stringOrd = on-ord primStringToList lemma listCharOrd where lemma : Injective primStringToList lemma x y p = builtin-eq-to-path (primStringToListInjective x y (path-to-builtin-eq p))
{ "alphanum_fraction": 0.7903780069, "avg_line_length": 29.1, "ext": "agda", "hexsha": "ca19bd1bf3a12c54595f97bcbc5a64822caf9c90", "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/String.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/String.agda", "max_line_length": 89, "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/String.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": 301, "size": 1164 }
-- Example usage of solver {-# OPTIONS --without-K --safe #-} open import Categories.Category module Experiment.Categories.Solver.Category.Example {o ℓ e} (𝒞 : Category o ℓ e) where open import Experiment.Categories.Solver.Category 𝒞 open Category 𝒞 open HomReasoning private variable A B C D E : Obj module _ (f : D ⇒ E) (g : C ⇒ D) (h : B ⇒ C) (i : A ⇒ B) where _ : (f ∘ id ∘ g) ∘ id ∘ h ∘ i ≈ f ∘ (g ∘ h) ∘ i _ = solve ((∥-∥ :∘ :id :∘ ∥-∥) :∘ :id :∘ ∥-∥ :∘ ∥-∥) (∥-∥ :∘ (∥-∥ :∘ ∥-∥) :∘ ∥-∥) refl
{ "alphanum_fraction": 0.520295203, "avg_line_length": 22.5833333333, "ext": "agda", "hexsha": "9c8b3dde0bdb253437cded53f67a86d1532a8c35", "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": "37200ea91d34a6603d395d8ac81294068303f577", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "rei1024/agda-misc", "max_forks_repo_path": "Experiment/Categories/Solver/Category/Example.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577", "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": "rei1024/agda-misc", "max_issues_repo_path": "Experiment/Categories/Solver/Category/Example.agda", "max_line_length": 62, "max_stars_count": 3, "max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "rei1024/agda-misc", "max_stars_repo_path": "Experiment/Categories/Solver/Category/Example.agda", "max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z", "max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z", "num_tokens": 233, "size": 542 }
---------------------------------------------------------------- -- This file contains the definition of isomorphisms. -- ---------------------------------------------------------------- module Category.Iso where open import Category.Category record Iso {l : Level}{ℂ : Cat {l}}{A B : Obj ℂ} (f : el (Hom ℂ A B)) : Set l where field inv : el (Hom ℂ B A) left-inv-ax : ⟨ Hom ℂ A A ⟩[ f ○[ comp ℂ ] inv ≡ id ℂ ] right-inv-ax : ⟨ Hom ℂ B B ⟩[ inv ○[ comp ℂ ] f ≡ id ℂ ] open Iso public
{ "alphanum_fraction": 0.4294117647, "avg_line_length": 31.875, "ext": "agda", "hexsha": "4f1e29bce2d669af342a71530e1ffb2db3ec0213", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "heades/AUGL", "max_forks_repo_path": "setoid-cats/Category/Iso.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "heades/AUGL", "max_issues_repo_path": "setoid-cats/Category/Iso.agda", "max_line_length": 83, "max_stars_count": null, "max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "heades/AUGL", "max_stars_repo_path": "setoid-cats/Category/Iso.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 146, "size": 510 }
------------------------------------------------------------------------ -- The Agda standard library -- -- The Cowriter type and some operations ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe --sized-types #-} module Codata.Cowriter where open import Size import Level as L open import Codata.Thunk using (Thunk; force) open import Codata.Conat open import Codata.Delay using (Delay; later; now) open import Codata.Stream as Stream using (Stream; _∷_) open import Data.Unit open import Data.List using (List; []; _∷_) open import Data.List.NonEmpty using (List⁺; _∷_) open import Data.Nat.Base as Nat using (ℕ; zero; suc) open import Data.Product as Prod using (_×_; _,_) open import Data.Sum as Sum using (_⊎_; inj₁; inj₂) open import Data.Vec using (Vec; []; _∷_) open import Data.BoundedVec as BVec using (BoundedVec) open import Function data Cowriter {w a} (W : Set w) (A : Set a) (i : Size) : Set (a L.⊔ w) where [_] : A → Cowriter W A i _∷_ : W → Thunk (Cowriter W A) i → Cowriter W A i ------------------------------------------------------------------------ -- Relationship to Delay. module _ {a} {A : Set a} where fromDelay : ∀ {i} → Delay A i → Cowriter ⊤ A i fromDelay (now a) = [ a ] fromDelay (later da) = _ ∷ λ where .force → fromDelay (da .force) module _ {w a} {W : Set w} {A : Set a} where toDelay : ∀ {i} → Cowriter W A i → Delay A i toDelay [ a ] = now a toDelay (_ ∷ ca) = later λ where .force → toDelay (ca .force) ------------------------------------------------------------------------ -- Basic functions. fromStream : ∀ {i} → Stream W i → Cowriter W A i fromStream (w ∷ ws) = w ∷ λ where .force → fromStream (ws .force) repeat : W → Cowriter W A ∞ repeat = fromStream ∘′ Stream.repeat length : ∀ {i} → Cowriter W A i → Conat i length [ _ ] = zero length (w ∷ cw) = suc λ where .force → length (cw .force) splitAt : ∀ (n : ℕ) → Cowriter W A ∞ → (Vec W n × Cowriter W A ∞) ⊎ (BoundedVec W n × A) splitAt zero cw = inj₁ ([] , cw) splitAt (suc n) [ a ] = inj₂ (BVec.[] , a) splitAt (suc n) (w ∷ cw) = Sum.map (Prod.map₁ (w ∷_)) (Prod.map₁ (w BVec.∷_)) $ splitAt n (cw .force) take : ∀ (n : ℕ) → Cowriter W A ∞ → Vec W n ⊎ (BoundedVec W n × A) take n = Sum.map₁ Prod.proj₁ ∘′ splitAt n infixr 5 _++_ _⁺++_ _++_ : ∀ {i} → List W → Cowriter W A i → Cowriter W A i [] ++ ca = ca (w ∷ ws) ++ ca = w ∷ λ where .force → ws ++ ca _⁺++_ : ∀ {i} → List⁺ W → Thunk (Cowriter W A) i → Cowriter W A i (w ∷ ws) ⁺++ ca = w ∷ λ where .force → ws ++ ca .force concat : ∀ {i} → Cowriter (List⁺ W) A i → Cowriter W A i concat [ a ] = [ a ] concat (w ∷ ca) = w ⁺++ λ where .force → concat (ca .force) module _ {w x a b} {W : Set w} {X : Set x} {A : Set a} {B : Set b} where ------------------------------------------------------------------------ -- Functor, Applicative and Monad map : ∀ {i} → (W → X) → (A → B) → Cowriter W A i → Cowriter X B i map f g [ a ] = [ g a ] map f g (w ∷ cw) = f w ∷ λ where .force → map f g (cw .force) module _ {w a r} {W : Set w} {A : Set a} {R : Set r} where map₁ : ∀ {i} → (W → R) → Cowriter W A i → Cowriter R A i map₁ f = map f id map₂ : ∀ {i} → (A → R) → Cowriter W A i → Cowriter W R i map₂ = map id ap : ∀ {i} → Cowriter W (A → R) i → Cowriter W A i → Cowriter W R i ap [ f ] ca = map₂ f ca ap (w ∷ cf) ca = w ∷ λ where .force → ap (cf .force) ca _>>=_ : ∀ {i} → Cowriter W A i → (A → Cowriter W R i) → Cowriter W R i [ a ] >>= f = f a (w ∷ ca) >>= f = w ∷ λ where .force → ca .force >>= f ------------------------------------------------------------------------ -- Construction. module _ {w s a} {W : Set w} {S : Set s} {A : Set a} where unfold : ∀ {i} → (S → (W × S) ⊎ A) → S → Cowriter W A i unfold next seed with next seed ... | inj₁ (w , seed') = w ∷ λ where .force → unfold next seed' ... | inj₂ a = [ a ]
{ "alphanum_fraction": 0.4982543641, "avg_line_length": 34.8695652174, "ext": "agda", "hexsha": "873faee7a2b82da992bf3302427e1858356df70f", "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/Cowriter.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/Cowriter.agda", "max_line_length": 90, "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/Cowriter.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1368, "size": 4010 }
module Dave.Algebra.Naturals.Bin where open import Dave.Algebra.Naturals.Definition open import Dave.Algebra.Naturals.Addition open import Dave.Algebra.Naturals.Multiplication open import Dave.Embedding data Bin : Set where ⟨⟩ : Bin _t : Bin → Bin _f : Bin → Bin inc : Bin → Bin inc ⟨⟩ = ⟨⟩ t inc (b t) = (inc b) f inc (b f) = b t to : ℕ → Bin to zero = ⟨⟩ f to (suc n) = inc (to n) from : Bin → ℕ from ⟨⟩ = zero from (b t) = 1 + 2 * (from b) from (b f) = 2 * (from b) from6 = from (⟨⟩ t t f) from23 = from (⟨⟩ t f t t t) from23WithZeros = from (⟨⟩ f f f t f t t t) Bin-ℕ-Suc-Homomorph : ∀ (b : Bin) → from (inc b) ≡ suc (from b) Bin-ℕ-Suc-Homomorph ⟨⟩ = refl Bin-ℕ-Suc-Homomorph (b t) = begin from (inc (b t)) ≡⟨⟩ from ((inc b) f) ≡⟨⟩ 2 * (from (inc b)) ≡⟨ cong (λ a → 2 * a) (Bin-ℕ-Suc-Homomorph b) ⟩ 2 * suc (from b) ≡⟨⟩ 2 * (1 + (from b)) ≡⟨ *-distrib1ₗ-+ₗ 2 (from b) ⟩ 2 + 2 * (from b) ≡⟨⟩ suc (1 + 2 * (from b)) ≡⟨⟩ suc (from (b t)) ∎ Bin-ℕ-Suc-Homomorph (b f) = begin from (inc (b f)) ≡⟨⟩ from (b t) ≡⟨⟩ 1 + 2 * (from b) ≡⟨⟩ suc (2 * from b) ≡⟨⟩ suc (from (b f)) ∎ to-inverse-from : ∀ (n : ℕ) → from (to n) ≡ n to-inverse-from zero = refl to-inverse-from (suc n) = begin from (to (suc n)) ≡⟨⟩ from (inc (to n)) ≡⟨ Bin-ℕ-Suc-Homomorph (to n) ⟩ suc (from (to n)) ≡⟨ cong (λ a → suc a) (to-inverse-from n) ⟩ suc n ∎ ℕ≲Bin : ℕ ≲ Bin ℕ≲Bin = record { to = to; from = from; from∘to = to-inverse-from }
{ "alphanum_fraction": 0.5082278481, "avg_line_length": 25.4838709677, "ext": "agda", "hexsha": "a99553e83823367de27c7bb40db9d43090c0f6fb", "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": "05213fb6ab1f51f770f9858b61526ba950e06232", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DavidStahl97/formal-proofs", "max_forks_repo_path": "Dave/Algebra/Naturals/Bin.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232", "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": "DavidStahl97/formal-proofs", "max_issues_repo_path": "Dave/Algebra/Naturals/Bin.agda", "max_line_length": 70, "max_stars_count": null, "max_stars_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "DavidStahl97/formal-proofs", "max_stars_repo_path": "Dave/Algebra/Naturals/Bin.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 724, "size": 1580 }
open import ExtractSac as ES using () open import Extract (ES.kompile-fun) open import Data.Nat as N using (ℕ; zero; suc; _≤_; _≥_; _<_; _>_; s≤s; z≤n; _∸_) import Data.Nat.DivMod as N open import Data.Nat.Properties as N open import Data.List as L using (List; []; _∷_) open import Data.Vec as V using (Vec; []; _∷_) import Data.Vec.Properties as V open import Data.Fin as F using (Fin; zero; suc; #_) import Data.Fin.Properties as F open import Data.Product as Prod using (Σ; _,_; curry; uncurry) renaming (_×_ to _×ₜ_) open import Data.String open import Relation.Binary.PropositionalEquality open import Structures open import Function open import Array.Base open import Array.Properties open import APL2 open import Agda.Builtin.Float open import Reflection open import ReflHelper pattern I0 = (zero ∷ []) pattern I1 = (suc zero ∷ []) pattern I2 = (suc (suc zero) ∷ []) pattern I3 = (suc (suc (suc zero)) ∷ []) -- backin←{(d w in)←⍵⋄⊃+/,w{(⍴in)↑(-⍵+⍴d)↑⍺×d}¨⍳⍴w} backin : ∀ {n s s₁} → (inp : Ar Float n s) → (w : Ar Float n s₁) → {≥ : ▴ s ≥a ▴ s₁} → (d : Ar Float n $ ▾ ((s - s₁){≥} + 1)) → Ar Float n s backin {n}{s}{s₁} inp w d = let ixs = ι ρ w use-ixs i,pf = let i , pf = i,pf iv = a→ix i (ρ w) pf wᵢ = sel w (subst-ix (λ i → V.lookup∘tabulate _ i) iv) --x = pre-pad i 0.0 (d ×ᵣ wᵢ) x = (i + ρ d) -↑⟨ 0.0 ⟩ (d ×ᵣ wᵢ) y = (ρ inp) ↑⟨ 0.0 ⟩ x in y s = reduce-1d _+ᵣ_ (cst 0.0) (, use-ixs ̈ ixs) in subst-ar (λ i → V.lookup∘tabulate _ i) s kbin = kompile backin (quote _≥a_ ∷ quote reduce-1d ∷ quote _↑⟨_⟩_ ∷ quote _-↑⟨_⟩_ ∷ quote a→ix ∷ []) [] rkbin = frefl backin (quote _≥a_ ∷ quote reduce-1d ∷ quote _↑⟨_⟩_ ∷ quote _-↑⟨_⟩_ ∷ quote a→ix ∷ []) fin-id : ∀ {n} → Fin n → Fin n fin-id x = x s-w+1≤s : ∀ {s w} → s ≥ w → s > 0 → w > 0 → s N.∸ w N.+ 1 ≤ s s-w+1≤s {suc s} {suc w} (s≤s s≥w) s>0 w>0 rewrite (+-comm (s ∸ w) 1) = s≤s (m∸n≤m s w) helper : ∀ {n} {sI sw : Vec ℕ n} → s→a sI ≥a s→a sw → (cst 0) <a s→a sI → (cst 0) <a s→a sw → (iv : Ix 1 (n ∷ [])) → V.lookup sI (ix-lookup iv zero) ≥ V.lookup (V.tabulate (λ i → V.lookup sI i ∸ V.lookup sw i N.+ 1)) (ix-lookup iv zero) helper {sI = sI} {sw} sI≥sw sI>0 sw>0 (x ∷ []) rewrite (V.lookup∘tabulate (λ i → V.lookup sI i ∸ V.lookup sw i N.+ 1) x) = s-w+1≤s (sI≥sw (x ∷ [])) (sI>0 (x ∷ [])) (sw>0 (x ∷ [])) a≤b⇒b≡c⇒a≤c : ∀ {a b c} → a ≤ b → b ≡ c → a ≤ c a≤b⇒b≡c⇒a≤c a≤b refl = a≤b -- sI - (sI - sw + 1) + 1 = sw shape-same : ∀ {n} {sI sw : Vec ℕ n} → s→a sI ≥a s→a sw → (cst 0) <a s→a sI → (cst 0) <a s→a sw → (i : Fin n) → V.lookup (V.tabulate (λ i₁ → V.lookup sI i₁ ∸ V.lookup (V.tabulate (λ i₂ → V.lookup sI i₂ ∸ V.lookup sw i₂ N.+ 1)) i₁ N.+ 1)) i ≡ V.lookup sw i shape-same {suc n} {x ∷ sI} {y ∷ sw} I≥w I>0 w>0 zero = begin x ∸ (x ∸ y N.+ 1) N.+ 1 ≡⟨ sym $ +-∸-comm {m = x} 1 {o = (x ∸ y N.+ 1)} (s-w+1≤s (I≥w I0) (I>0 I0) (w>0 I0)) ⟩ x N.+ 1 ∸ (x ∸ y N.+ 1) ≡⟨ cong (x N.+ 1 ∸_) (sym $ +-∸-comm {m = x} 1 {o = y} (I≥w I0)) ⟩ x N.+ 1 ∸ (x N.+ 1 ∸ y) ≡⟨ m∸[m∸n]≡n {m = x N.+ 1} {n = y} (a≤b⇒b≡c⇒a≤c (≤-step $ I≥w I0) (+-comm 1 x)) ⟩ y ∎ where open ≡-Reasoning shape-same {suc n} {x ∷ sI} {x₁ ∷ sw} I≥w I>0 w>0 (suc i) = shape-same {sI = sI} {sw = sw} (λ { (i ∷ []) → I≥w (suc i ∷ []) }) (λ { (i ∷ []) → I>0 (suc i ∷ []) }) (λ { (i ∷ []) → w>0 (suc i ∷ []) }) i {-backmulticonv ← { (d_out weights in bias) ← ⍵ d_in ← +⌿d_out {backin ⍺ ⍵ in} ⍤((⍴⍴in), (⍴⍴in)) ⊢ weights d_w ← {⍵ conv in} ⍤(⍴⍴in) ⊢ d_out d_bias ← backbias ⍤(⍴⍴in) ⊢ d_out d_in d_w d_bias }-} backmulticonv : ∀ {n m}{sI sw so} → (W : Ar (Ar Float n sw) m so) → (I : Ar Float n sI) → (B : Ar Float m so) -- We can get rid of these two expressions if we rewrite -- the convolution to accept s+1 ≥ w, and not s ≥ w. → {>I : (cst 0) <a s→a sI} → {>w : (cst 0) <a s→a sw} → {≥ : s→a sI ≥a s→a sw} → (δo : Ar (Ar Float n (a→s $ (s→a sI - s→a sw) {≥} + 1)) m so) → {- (typeOf W) ×ₜ-} (typeOf I) --×ₜ (typeOf B) backmulticonv {n} {sI = sI} {sw} {so} W I B {sI>0} {sw>0} {sI≥sw} δo = let δI = reduce-1d _+ᵣ_ (cst 0.0) (, (W ̈⟨ (λ x y → backin I x {sI≥sw} y) ⟩ δo)) {- δW = (λ x → (x conv I) {≥ = λ { iv@(i ∷ []) → subst₂ _≤_ (sym $ V.lookup∘tabulate _ i) refl $ s-w+1≤s (sI≥sw iv) (sI>0 iv) (sw>0 iv) } }) ̈ δo δB = backbias ̈ δo -} in --(imap (λ iv → subst-ar (shape-same {sI = sI} {sw = sw} sI≥sw sI>0 sw>0) (sel δW iv)) , δI {-, imap (λ iv → ▾ (sel δB iv))) -} where open import Example-04 open import Example-03 kbckmconv = kompile backmulticonv (quote _≥a_ ∷ quote _<a_ ∷ quote reduce-1d ∷ quote _↑⟨_⟩_ ∷ quote _-↑⟨_⟩_ ∷ quote a→ix ∷ quote _conv_ ∷ []) [] where open import Example-04 conv-fns : List (String ×ₜ Name) conv-fns = ("blog" , quote blog) ∷ ("backbias" , quote backbias) ∷ ("logistic" , quote logistic) ∷ ("meansqerr" , quote meansqerr) ∷ ("backavgpool" , quote backavgpool) ∷ ("avgpool" , quote avgpool) ∷ ("conv" , quote _conv_) ∷ ("multiconv" , quote multiconv) ∷ ("backin", quote backin) ∷ ("backmulticonv" , quote backmulticonv) ∷ [] where open import Example-03 open import Example-04 -- * test-zhang -- * train-zhang
{ "alphanum_fraction": 0.4711934156, "avg_line_length": 35.3454545455, "ext": "agda", "hexsha": "b82f5faddd9f361239aa1d43dad9e20231c4d7da", "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": "c8954c8acd8089ced82af9e05084fbbc7fedb36c", "max_forks_repo_licenses": [ "0BSD" ], "max_forks_repo_name": "ashinkarov/agda-extractor", "max_forks_repo_path": "Example-05.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "0BSD" ], "max_issues_repo_name": "ashinkarov/agda-extractor", "max_issues_repo_path": "Example-05.agda", "max_line_length": 144, "max_stars_count": 1, "max_stars_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c", "max_stars_repo_licenses": [ "0BSD" ], "max_stars_repo_name": "ashinkarov/agda-extractor", "max_stars_repo_path": "Example-05.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-11T14:52:59.000Z", "max_stars_repo_stars_event_min_datetime": "2021-01-11T14:52:59.000Z", "num_tokens": 2596, "size": 5832 }
module Properties.Base where open import Data.Maybe hiding (All) open import Data.List open import Data.List.All open import Data.Product open import Data.Sum open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Typing open import Global open import Values open import Session open import Schedule one-step : ∀ {G} → (∃ λ G' → ThreadPool (G' ++ G)) → Event × (∃ λ G → ThreadPool G) one-step{G} (G1 , tp) with ssplit-refl-left-inactive (G1 ++ G) ... | G' , ina-G' , ss-GG' with Alternative.step ss-GG' tp (tnil ina-G') ... | ev , tp' = ev , ( _ , tp') restart : ∀ {G} → Command G → Command G restart (Ready ss v κ) = apply-cont ss κ v restart cmd = cmd -- auxiliary lemmas lift-unrestricted : ∀ {t G} (unrt : Unr t) (v : Val G t) → unrestricted-val unrt (lift-val v) ≡ ::-inactive (unrestricted-val unrt v) lift-unrestricted-venv : ∀ {Φ G} (unrt : All Unr Φ) (ϱ : VEnv G Φ) → unrestricted-venv unrt (lift-venv ϱ) ≡ ::-inactive (unrestricted-venv unrt ϱ) lift-unrestricted UUnit (VUnit inaG) = refl lift-unrestricted UInt (VInt i inaG) = refl lift-unrestricted (UPair unrt unrt₁) (VPair ss-GG₁G₂ v v₁) rewrite lift-unrestricted unrt v | lift-unrestricted unrt₁ v₁ = refl lift-unrestricted UFun (VFun (inj₁ ()) ϱ e) lift-unrestricted UFun (VFun (inj₂ y) ϱ e) = lift-unrestricted-venv y ϱ lift-unrestricted-venv [] (vnil ina) = refl lift-unrestricted-venv (px ∷ unrt) (vcons ssp v ϱ) rewrite lift-unrestricted px v | lift-unrestricted-venv unrt ϱ = refl unrestricted-empty : ∀ {t} → (unrt : Unr t) (v : Val [] t) → unrestricted-val unrt v ≡ []-inactive unrestricted-empty-venv : ∀ {t} → (unrt : All Unr t) (v : VEnv [] t) → unrestricted-venv unrt v ≡ []-inactive unrestricted-empty UUnit (VUnit []-inactive) = refl unrestricted-empty UInt (VInt i []-inactive) = refl unrestricted-empty (UPair unrt unrt₁) (VPair ss-[] v v₁) rewrite unrestricted-empty unrt v | unrestricted-empty unrt₁ v₁ = refl unrestricted-empty UFun (VFun (inj₁ ()) ϱ e) unrestricted-empty UFun (VFun (inj₂ y) ϱ e) = unrestricted-empty-venv y ϱ unrestricted-empty-venv [] (vnil []-inactive) = refl unrestricted-empty-venv (px ∷ unrt) (vcons ss-[] v v₁) rewrite unrestricted-empty px v | unrestricted-empty-venv unrt v₁ = refl split-env-lemma : ∀ { Φ Φ₁ Φ₂ } (sp : Split Φ Φ₁ Φ₂) (ϱ : VEnv [] Φ) → ∃ λ ϱ₁ → ∃ λ ϱ₂ → split-env sp (lift-venv ϱ) ≡ (((nothing ∷ []) , (nothing ∷ [])) , (ss-both ss-[]) , lift-venv ϱ₁ , lift-venv ϱ₂) split-env-lemma [] (vnil []-inactive) = (vnil []-inactive) , ((vnil []-inactive) , refl) split-env-lemma (dupl unrt sp) (vcons ss-[] v ϱ) with split-env-lemma sp ϱ | unrestricted-val unrt v ... | ϱ₁ , ϱ₂ , spe== | unr-v rewrite inactive-left-ssplit ss-[] unr-v | lift-unrestricted unrt v | unrestricted-empty unrt v | spe== with ssplit-compose3 (ss-both ss-[]) (ss-both ss-[]) ... | ssc3 = (vcons ss-[] v ϱ₁) , (vcons ss-[] v ϱ₂) , refl split-env-lemma (Split.drop unrt sp) (vcons ss-[] v ϱ) with split-env-lemma sp ϱ | unrestricted-val unrt v ... | ϱ₁ , ϱ₂ , spe== | unr-v rewrite lift-unrestricted unrt v | unrestricted-empty unrt v = ϱ₁ , ϱ₂ , spe== split-env-lemma (left sp) (vcons ss-[] v ϱ) with split-env-lemma sp ϱ ... | ϱ₁ , ϱ₂ , spe== rewrite spe== with ssplit-compose3 (ss-both ss-[]) (ss-both ss-[]) ... | ssc3 = (vcons ss-[] v ϱ₁) , (ϱ₂ , refl) split-env-lemma (rght sp) (vcons ss-[] v ϱ) with split-env-lemma sp ϱ ... | ϱ₁ , ϱ₂ , spe== rewrite spe== with ssplit-compose4 (ss-both ss-[]) (ss-both ss-[]) ... | ssc4 = ϱ₁ , (vcons ss-[] v ϱ₂) , refl split-env-right-lemma : ∀ {Φ} (ϱ : VEnv [] Φ) → split-env (split-all-right Φ) (lift-venv ϱ) ≡ (((nothing ∷ []) , (nothing ∷ [])) , (ss-both ss-[]) , vnil (::-inactive []-inactive) , lift-venv ϱ) split-env-right-lemma (vnil []-inactive) = refl split-env-right-lemma (vcons ss-[] v ϱ) with split-env-right-lemma ϱ ... | sperl rewrite sperl with ssplit-compose4 (ss-both ss-[]) (ss-both ss-[]) ... | ssc4 = refl split-env-right-lemma0 : ∀ {Φ} (ϱ : VEnv [] Φ) → split-env (split-all-right Φ) ϱ ≡ (([] , []) , ss-[] , vnil []-inactive , ϱ) split-env-right-lemma0 (vnil []-inactive) = refl split-env-right-lemma0 (vcons ss-[] v ϱ) rewrite split-env-right-lemma0 ϱ = refl split-env-left-lemma0 : ∀ {Φ} (ϱ : VEnv [] Φ) → split-env (split-all-left Φ) ϱ ≡ (([] , []) , ss-[] , ϱ , vnil []-inactive) split-env-left-lemma0 (vnil []-inactive) = refl split-env-left-lemma0 (vcons ss-[] v ϱ) rewrite split-env-left-lemma0 ϱ = refl split-env-lemma-2T : Set split-env-lemma-2T = ∀ { Φ Φ₁ Φ₂ } (sp : Split Φ Φ₁ Φ₂) (ϱ : VEnv [] Φ) → ∃ λ ϱ₁ → ∃ λ ϱ₂ → split-env sp (lift-venv ϱ) ≡ (_ , (ss-both ss-[]) , lift-venv ϱ₁ , lift-venv ϱ₂) × split-env sp ϱ ≡ (_ , ss-[] , ϱ₁ , ϱ₂) split-env-lemma-2 : split-env-lemma-2T split-env-lemma-2 [] (vnil []-inactive) = (vnil []-inactive) , ((vnil []-inactive) , (refl , refl)) split-env-lemma-2 (dupl unrt sp) (vcons ss-[] v ϱ) with split-env-lemma-2 sp ϱ ... | ϱ₁ , ϱ₂ , selift-ind , se-ind rewrite se-ind | lift-unrestricted unrt v with unrestricted-val unrt v ... | []-inactive rewrite selift-ind with ssplit-compose3 (ss-both ss-[]) (ss-both ss-[]) ... | ssc3 = (vcons ss-[] v ϱ₁) , (vcons ss-[] v ϱ₂) , refl , refl split-env-lemma-2 (Split.drop unrt sp) (vcons ss-[] v ϱ) with split-env-lemma-2 sp ϱ ... | ϱ₁ , ϱ₂ , selift-ind , se-ind rewrite se-ind | lift-unrestricted unrt v with unrestricted-val unrt v ... | []-inactive = ϱ₁ , ϱ₂ , selift-ind , se-ind split-env-lemma-2 (left sp) (vcons ss-[] v ϱ) with split-env-lemma-2 sp ϱ ... | ϱ₁ , ϱ₂ , selift-ind , se-ind rewrite se-ind | selift-ind with ssplit-compose3 (ss-both ss-[]) (ss-both ss-[]) ... | ssc3 = (vcons ss-[] v ϱ₁) , ϱ₂ , refl , refl split-env-lemma-2 (rght sp) (vcons ss-[] v ϱ) with split-env-lemma-2 sp ϱ ... | ϱ₁ , ϱ₂ , selift-ind , se-ind rewrite se-ind | selift-ind with ssplit-compose4 (ss-both ss-[]) (ss-both ss-[]) ... | ssc4 = ϱ₁ , (vcons ss-[] v ϱ₂) , refl , refl split-rotate-lemma : ∀ {Φ} → split-rotate (split-all-left Φ) (split-all-right Φ) ≡ (Φ , split-all-right Φ , split-all-left Φ) split-rotate-lemma {[]} = refl split-rotate-lemma {x ∷ Φ} rewrite split-rotate-lemma {Φ} = refl split-rotate-lemma' : ∀ {Φ Φ₁ Φ₂} (sp : Split Φ Φ₁ Φ₂) → split-rotate (split-all-left Φ) sp ≡ (Φ₂ , sp , split-all-left Φ₂) split-rotate-lemma' {[]} [] = refl split-rotate-lemma' {x ∷ Φ} (dupl un-x sp) rewrite split-rotate-lemma' {Φ} sp = refl split-rotate-lemma' {x ∷ Φ} {Φ₁} {Φ₂} (Split.drop un-x sp) rewrite split-rotate-lemma' {Φ} sp = refl split-rotate-lemma' {x ∷ Φ} (left sp) rewrite split-rotate-lemma' {Φ} sp = refl split-rotate-lemma' {x ∷ Φ} (rght sp) rewrite split-rotate-lemma' {Φ} sp = refl ssplit-compose-lemma : ∀ ss → ssplit-compose ss-[] ss ≡ ([] , ss-[] , ss-[]) ssplit-compose-lemma ss-[] = refl
{ "alphanum_fraction": 0.6162724423, "avg_line_length": 31.4708520179, "ext": "agda", "hexsha": "8d1aa34bf53fa0a2c1c1f6011294c0d063f1e27b", "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": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "peterthiemann/definitional-session", "max_forks_repo_path": "src/Properties/Base.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "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": "peterthiemann/definitional-session", "max_issues_repo_path": "src/Properties/Base.agda", "max_line_length": 109, "max_stars_count": 9, "max_stars_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "peterthiemann/definitional-session", "max_stars_repo_path": "src/Properties/Base.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-18T08:10:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-01-19T16:33:27.000Z", "num_tokens": 2704, "size": 7018 }
open import Oscar.Prelude open import Oscar.Class.IsFunctor open import Oscar.Class.Reflexivity open import Oscar.Class.Smap open import Oscar.Class.Surjection open import Oscar.Class.Transitivity module Oscar.Class.Functor where record Functor 𝔬₁ 𝔯₁ ℓ₁ 𝔬₂ 𝔯₂ ℓ₂ : Ø ↑̂ (𝔬₁ ∙̂ 𝔯₁ ∙̂ ℓ₁ ∙̂ 𝔬₂ ∙̂ 𝔯₂ ∙̂ ℓ₂) where constructor ∁ field {𝔒₁} : Ø 𝔬₁ _∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁ _∼̇₁_ : ∀ {x y} → x ∼₁ y → x ∼₁ y → Ø ℓ₁ ε₁ : Reflexivity.type _∼₁_ _↦₁_ : Transitivity.type _∼₁_ {𝔒₂} : Ø 𝔬₂ _∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂ _∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂ ε₂ : Reflexivity.type _∼₂_ _↦₂_ : Transitivity.type _∼₂_ {μ} : Surjection.type 𝔒₁ 𝔒₂ functor-smap : Smap.type _∼₁_ _∼₂_ μ μ -- FIXME cannot name this § or smap b/c of namespace conflict ⦃ `IsFunctor ⦄ : IsFunctor _∼₁_ _∼̇₁_ ε₁ _↦₁_ _∼₂_ _∼̇₂_ ε₂ _↦₂_ functor-smap
{ "alphanum_fraction": 0.6271777003, "avg_line_length": 31.8888888889, "ext": "agda", "hexsha": "849311fad2c0ff32908140c2f8880129f3d9bab1", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_forks_repo_licenses": [ "RSA-MD" ], "max_forks_repo_name": "m0davis/oscar", "max_forks_repo_path": "archive/agda-3/src/Oscar/Class/Functor.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z", "max_issues_repo_licenses": [ "RSA-MD" ], "max_issues_repo_name": "m0davis/oscar", "max_issues_repo_path": "archive/agda-3/src/Oscar/Class/Functor.agda", "max_line_length": 104, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-3/src/Oscar/Class/Functor.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 437, "size": 861 }
------------------------------------------------------------------------ -- INCREMENTAL λ-CALCULUS -- -- Overloading ⟦_⟧ notation -- -- This module defines a general mechanism for overloading the -- ⟦_⟧ notation, using Agda’s instance arguments. ------------------------------------------------------------------------ module Base.Denotation.Notation where open import Level record Meaning (Syntax : Set) {ℓ : Level} : Set (suc ℓ) where constructor meaning field {Semantics} : Set ℓ ⟨_⟩⟦_⟧ : Syntax → Semantics open Meaning {{...}} public renaming (⟨_⟩⟦_⟧ to ⟦_⟧) open Meaning public using (⟨_⟩⟦_⟧)
{ "alphanum_fraction": 0.516025641, "avg_line_length": 24, "ext": "agda", "hexsha": "20e8a7f9eba112b5bfc7bc9aeb7f1a919879c47e", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "inc-lc/ilc-agda", "max_forks_repo_path": "Base/Denotation/Notation.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "inc-lc/ilc-agda", "max_issues_repo_path": "Base/Denotation/Notation.agda", "max_line_length": 72, "max_stars_count": 10, "max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "inc-lc/ilc-agda", "max_stars_repo_path": "Base/Denotation/Notation.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z", "num_tokens": 167, "size": 624 }
{-# OPTIONS --allow-unsolved-metas #-} module IsLiteralProblem where open import OscarPrelude open import IsLiteralSequent open import Problem record IsLiteralProblem (𝔓 : Problem) : Set where constructor _¶_ field {problem} : Problem isLiteralInferences : All IsLiteralSequent (inferences 𝔓) isLiteralInterest : IsLiteralSequent (interest 𝔓) open IsLiteralProblem public instance EqIsLiteralProblem : ∀ {𝔓} → Eq (IsLiteralProblem 𝔓) EqIsLiteralProblem = {!!}
{ "alphanum_fraction": 0.7650727651, "avg_line_length": 24.05, "ext": "agda", "hexsha": "9906c3f218318c619777f1740de143852cc7d24d", "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/IsLiteralProblem.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/IsLiteralProblem.agda", "max_line_length": 61, "max_stars_count": null, "max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb", "max_stars_repo_licenses": [ "RSA-MD" ], "max_stars_repo_name": "m0davis/oscar", "max_stars_repo_path": "archive/agda-1/IsLiteralProblem.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 132, "size": 481 }
module Pi-.Invariants where open import Data.Empty open import Data.Unit open import Data.Sum open import Data.Product open import Relation.Binary.Core open import Relation.Binary open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Data.Nat open import Data.Nat.Properties open import Function using (_∘_) open import Pi-.Syntax open import Pi-.Opsem open import Pi-.NoRepeat open import Pi-.Dir -- Direction of values dir𝕍 : ∀ {t} → ⟦ t ⟧ → Dir dir𝕍 {𝟘} () dir𝕍 {𝟙} v = ▷ dir𝕍 {_ +ᵤ _} (inj₁ x) = dir𝕍 x dir𝕍 {_ +ᵤ _} (inj₂ y) = dir𝕍 y dir𝕍 {_ ×ᵤ _} (x , y) = dir𝕍 x ×ᵈⁱʳ dir𝕍 y dir𝕍 { - _} (- v) = -ᵈⁱʳ (dir𝕍 v) -- Execution direction of states dirState : State → Dir dirState ⟨ _ ∣ _ ∣ _ ⟩▷ = ▷ dirState [ _ ∣ _ ∣ _ ]▷ = ▷ dirState ⟨ _ ∣ _ ∣ _ ⟩◁ = ◁ dirState [ _ ∣ _ ∣ _ ]◁ = ◁ dirCtx : ∀ {A B} → Context {A} {B} → Dir dirCtx ☐ = ▷ dirCtx (☐⨾ c₂ • κ) = dirCtx κ dirCtx (c₁ ⨾☐• κ) = dirCtx κ dirCtx (☐⊕ c₂ • κ) = dirCtx κ dirCtx (c₁ ⊕☐• κ) = dirCtx κ dirCtx (☐⊗[ c₂ , x ]• κ) = dir𝕍 x ×ᵈⁱʳ dirCtx κ dirCtx ([ c₁ , x ]⊗☐• κ) = dir𝕍 x ×ᵈⁱʳ dirCtx κ dirState𝕍 : State → Dir dirState𝕍 ⟨ _ ∣ v ∣ κ ⟩▷ = dir𝕍 v ×ᵈⁱʳ dirCtx κ dirState𝕍 [ _ ∣ v ∣ κ ]▷ = dir𝕍 v ×ᵈⁱʳ dirCtx κ dirState𝕍 ⟨ _ ∣ v ∣ κ ⟩◁ = dir𝕍 v ×ᵈⁱʳ dirCtx κ dirState𝕍 [ _ ∣ v ∣ κ ]◁ = dir𝕍 v ×ᵈⁱʳ dirCtx κ δdir : ∀ {A B} (c : A ↔ B) {b : base c} → (v : ⟦ A ⟧) → dir𝕍 v ≡ dir𝕍 (δ c {b} v) δdir unite₊l (inj₂ v) = refl δdir uniti₊l v = refl δdir swap₊ (inj₁ x) = refl δdir swap₊ (inj₂ y) = refl δdir assocl₊ (inj₁ v) = refl δdir assocl₊ (inj₂ (inj₁ v)) = refl δdir assocl₊ (inj₂ (inj₂ v)) = refl δdir assocr₊ (inj₁ (inj₁ v)) = refl δdir assocr₊ (inj₁ (inj₂ v)) = refl δdir assocr₊ (inj₂ v) = refl δdir unite⋆l (tt , v) = identˡᵈⁱʳ (dir𝕍 v) δdir uniti⋆l v = sym (identˡᵈⁱʳ (dir𝕍 v)) δdir swap⋆ (x , y) = commᵈⁱʳ _ _ δdir assocl⋆ (v₁ , (v₂ , v₃)) = assoclᵈⁱʳ _ _ _ δdir assocr⋆ ((v₁ , v₂) , v₃) = sym (assoclᵈⁱʳ _ _ _) δdir dist (inj₁ v₁ , v₃) = refl δdir dist (inj₂ v₂ , v₃) = refl δdir factor (inj₁ (v₁ , v₃)) = refl δdir factor (inj₂ (v₂ , v₃)) = refl -- Invariant of directions dirInvariant : ∀ {st st'} → st ↦ st' → dirState st ×ᵈⁱʳ dirState𝕍 st ≡ dirState st' ×ᵈⁱʳ dirState𝕍 st' dirInvariant {⟨ c ∣ v ∣ κ ⟩▷} (↦⃗₁ {b = b}) rewrite δdir c {b} v = refl dirInvariant ↦⃗₂ = refl dirInvariant ↦⃗₃ = refl dirInvariant ↦⃗₄ = refl dirInvariant ↦⃗₅ = refl dirInvariant {⟨ c₁ ⊗ c₂ ∣ (x , y) ∣ κ ⟩▷} ↦⃗₆ rewrite assoclᵈⁱʳ (dir𝕍 x) (dir𝕍 y) (dirCtx κ) = refl dirInvariant ↦⃗₇ = refl dirInvariant {[ c₁ ∣ x ∣ ☐⊗[ c₂ , y ]• κ ]▷} ↦⃗₈ rewrite assoc-commᵈⁱʳ (dir𝕍 x) (dir𝕍 y) (dirCtx κ) = refl dirInvariant {[ c₂ ∣ y ∣ [ c₁ , x ]⊗☐• κ ]▷} ↦⃗₉ rewrite assocl-commᵈⁱʳ (dir𝕍 y) (dir𝕍 x) (dirCtx κ) = refl dirInvariant ↦⃗₁₀ = refl dirInvariant ↦⃗₁₁ = refl dirInvariant ↦⃗₁₂ = refl dirInvariant {_} {⟨ c ∣ v ∣ κ ⟩◁} (↦⃖₁ {b = b}) rewrite δdir c {b} v = refl dirInvariant ↦⃖₂ = refl dirInvariant ↦⃖₃ = refl dirInvariant ↦⃖₄ = refl dirInvariant ↦⃖₅ = refl dirInvariant {⟨ c₁ ∣ x ∣ ☐⊗[ c₂ , y ]• κ ⟩◁} ↦⃖₆ rewrite assoclᵈⁱʳ (dir𝕍 x) (dir𝕍 y) (dirCtx κ) = refl dirInvariant ↦⃖₇ = refl dirInvariant {⟨ c₂ ∣ y ∣ [ c₁ , x ]⊗☐• κ ⟩◁} ↦⃖₈ rewrite assoc-commᵈⁱʳ (dir𝕍 y) (dir𝕍 x) (dirCtx κ) = refl dirInvariant {[ c₁ ⊗ c₂ ∣ (x , y) ∣ κ ]◁ } ↦⃖₉ rewrite assoclᵈⁱʳ (dir𝕍 y) (dir𝕍 x) (dirCtx κ) | commᵈⁱʳ (dir𝕍 y) (dir𝕍 x) = refl dirInvariant ↦⃖₁₀ = refl dirInvariant ↦⃖₁₁ = refl dirInvariant ↦⃖₁₂ = refl dirInvariant {[ η₊ ∣ inj₁ v ∣ κ ]◁} ↦η₁ with dir𝕍 v ... | ◁ with dirCtx κ ... | ◁ = refl ... | ▷ = refl dirInvariant {[ η₊ ∣ inj₁ v ∣ κ ]◁} ↦η₁ | ▷ with dirCtx κ ... | ◁ = refl ... | ▷ = refl dirInvariant {[ η₊ ∣ inj₂ (- v) ∣ κ ]◁} ↦η₂ with dir𝕍 v ... | ◁ with dirCtx κ ... | ◁ = refl ... | ▷ = refl dirInvariant {[ η₊ ∣ inj₂ (- v) ∣ κ ]◁} ↦η₂ | ▷ with dirCtx κ ... | ◁ = refl ... | ▷ = refl dirInvariant {⟨ ε₊ ∣ inj₁ v ∣ κ ⟩▷} ↦ε₁ with dir𝕍 v ... | ◁ with dirCtx κ ... | ◁ = refl ... | ▷ = refl dirInvariant {⟨ ε₊ ∣ inj₁ v ∣ κ ⟩▷} ↦ε₁ | ▷ with dirCtx κ ... | ◁ = refl ... | ▷ = refl dirInvariant {⟨ ε₊ ∣ inj₂ (- v) ∣ κ ⟩▷} ↦ε₂ with dir𝕍 v ... | ◁ with dirCtx κ ... | ◁ = refl ... | ▷ = refl dirInvariant {⟨ ε₊ ∣ inj₂ (- v) ∣ κ ⟩▷} ↦ε₂ | ▷ with dirCtx κ ... | ◁ = refl ... | ▷ = refl -- Reconstruct the whole combinator from context getℂκ : ∀ {A B} → A ↔ B → Context {A} {B} → ∃[ C ] ∃[ D ] (C ↔ D) getℂκ c ☐ = _ , _ , c getℂκ c (☐⨾ c₂ • κ) = getℂκ (c ⨾ c₂) κ getℂκ c (c₁ ⨾☐• κ) = getℂκ (c₁ ⨾ c) κ getℂκ c (☐⊕ c₂ • κ) = getℂκ (c ⊕ c₂) κ getℂκ c (c₁ ⊕☐• κ) = getℂκ (c₁ ⊕ c) κ getℂκ c (☐⊗[ c₂ , x ]• κ) = getℂκ (c ⊗ c₂) κ getℂκ c ([ c₁ , x ]⊗☐• κ) = getℂκ (c₁ ⊗ c) κ getℂ : State → ∃[ A ] ∃[ B ] (A ↔ B) getℂ ⟨ c ∣ _ ∣ κ ⟩▷ = getℂκ c κ getℂ [ c ∣ _ ∣ κ ]▷ = getℂκ c κ getℂ ⟨ c ∣ _ ∣ κ ⟩◁ = getℂκ c κ getℂ [ c ∣ _ ∣ κ ]◁ = getℂκ c κ -- The reconstructed combinator stays the same ℂInvariant : ∀ {st st'} → st ↦ st' → getℂ st ≡ getℂ st' ℂInvariant ↦⃗₁ = refl ℂInvariant ↦⃗₂ = refl ℂInvariant ↦⃗₃ = refl ℂInvariant ↦⃗₄ = refl ℂInvariant ↦⃗₅ = refl ℂInvariant ↦⃗₆ = refl ℂInvariant ↦⃗₇ = refl ℂInvariant ↦⃗₈ = refl ℂInvariant ↦⃗₉ = refl ℂInvariant ↦⃗₁₀ = refl ℂInvariant ↦⃗₁₁ = refl ℂInvariant ↦⃗₁₂ = refl ℂInvariant ↦⃖₁ = refl ℂInvariant ↦⃖₂ = refl ℂInvariant ↦⃖₃ = refl ℂInvariant ↦⃖₄ = refl ℂInvariant ↦⃖₅ = refl ℂInvariant ↦⃖₆ = refl ℂInvariant ↦⃖₇ = refl ℂInvariant ↦⃖₈ = refl ℂInvariant ↦⃖₉ = refl ℂInvariant ↦⃖₁₀ = refl ℂInvariant ↦⃖₁₁ = refl ℂInvariant ↦⃖₁₂ = refl ℂInvariant ↦η₁ = refl ℂInvariant ↦η₂ = refl ℂInvariant ↦ε₁ = refl ℂInvariant ↦ε₂ = refl ℂInvariant* : ∀ {st st'} → st ↦* st' → getℂ st ≡ getℂ st' ℂInvariant* ◾ = refl ℂInvariant* (r ∷ rs) = trans (ℂInvariant r) (ℂInvariant* rs) -- Get the type of the deepest context get𝕌 : ∀ {A B} → Context {A} {B} → 𝕌 × 𝕌 get𝕌 {A} {B} ☐ = A , B get𝕌 (☐⨾ c₂ • κ) = get𝕌 κ get𝕌 (c₁ ⨾☐• κ) = get𝕌 κ get𝕌 (☐⊕ c₂ • κ) = get𝕌 κ get𝕌 (c₁ ⊕☐• κ) = get𝕌 κ get𝕌 (☐⊗[ c₂ , x ]• κ) = get𝕌 κ get𝕌 ([ c₁ , x ]⊗☐• κ) = get𝕌 κ get𝕌State : State → 𝕌 × 𝕌 get𝕌State ⟨ c ∣ v ∣ κ ⟩▷ = get𝕌 κ get𝕌State [ c ∣ v ∣ κ ]▷ = get𝕌 κ get𝕌State ⟨ c ∣ v ∣ κ ⟩◁ = get𝕌 κ get𝕌State [ c ∣ v ∣ κ ]◁ = get𝕌 κ -- Append a context to another context appendκ : ∀ {A B} → (ctx : Context {A} {B}) → let (C , D) = get𝕌 ctx in Context {C} {D} → Context {A} {B} appendκ ☐ ctx = ctx appendκ (☐⨾ c₂ • κ) ctx = ☐⨾ c₂ • appendκ κ ctx appendκ (c₁ ⨾☐• κ) ctx = c₁ ⨾☐• appendκ κ ctx appendκ (☐⊕ c₂ • κ) ctx = ☐⊕ c₂ • appendκ κ ctx appendκ (c₁ ⊕☐• κ) ctx = c₁ ⊕☐• appendκ κ ctx appendκ (☐⊗[ c₂ , x ]• κ) ctx = ☐⊗[ c₂ , x ]• appendκ κ ctx appendκ ([ c₁ , x ]⊗☐• κ) ctx = [ c₁ , x ]⊗☐• appendκ κ ctx appendκState : ∀ st → let (A , B) = get𝕌State st in Context {A} {B} → State appendκState ⟨ c ∣ v ∣ κ ⟩▷ ctx = ⟨ c ∣ v ∣ appendκ κ ctx ⟩▷ appendκState [ c ∣ v ∣ κ ]▷ ctx = [ c ∣ v ∣ appendκ κ ctx ]▷ appendκState ⟨ c ∣ v ∣ κ ⟩◁ ctx = ⟨ c ∣ v ∣ appendκ κ ctx ⟩◁ appendκState [ c ∣ v ∣ κ ]◁ ctx = [ c ∣ v ∣ appendκ κ ctx ]◁ -- The type of context does not change during execution 𝕌Invariant : ∀ {st st'} → st ↦ st' → get𝕌State st ≡ get𝕌State st' 𝕌Invariant ↦⃗₁ = refl 𝕌Invariant ↦⃗₂ = refl 𝕌Invariant ↦⃗₃ = refl 𝕌Invariant ↦⃗₄ = refl 𝕌Invariant ↦⃗₅ = refl 𝕌Invariant ↦⃗₆ = refl 𝕌Invariant ↦⃗₇ = refl 𝕌Invariant ↦⃗₈ = refl 𝕌Invariant ↦⃗₉ = refl 𝕌Invariant ↦⃗₁₀ = refl 𝕌Invariant ↦⃗₁₁ = refl 𝕌Invariant ↦⃗₁₂ = refl 𝕌Invariant ↦⃖₁ = refl 𝕌Invariant ↦⃖₂ = refl 𝕌Invariant ↦⃖₃ = refl 𝕌Invariant ↦⃖₄ = refl 𝕌Invariant ↦⃖₅ = refl 𝕌Invariant ↦⃖₆ = refl 𝕌Invariant ↦⃖₇ = refl 𝕌Invariant ↦⃖₈ = refl 𝕌Invariant ↦⃖₉ = refl 𝕌Invariant ↦⃖₁₀ = refl 𝕌Invariant ↦⃖₁₁ = refl 𝕌Invariant ↦⃖₁₂ = refl 𝕌Invariant ↦η₁ = refl 𝕌Invariant ↦η₂ = refl 𝕌Invariant ↦ε₁ = refl 𝕌Invariant ↦ε₂ = refl 𝕌Invariant* : ∀ {st st'} → st ↦* st' → get𝕌State st ≡ get𝕌State st' 𝕌Invariant* ◾ = refl 𝕌Invariant* (r ∷ rs) = trans (𝕌Invariant r) (𝕌Invariant* rs) -- Appending context does not affect reductions appendκ↦ : ∀ {st st'} → (r : st ↦ st') (eq : get𝕌State st ≡ get𝕌State st') → (κ : Context {proj₁ (get𝕌State st)} {proj₂ (get𝕌State st)}) → appendκState st κ ↦ appendκState st' (subst (λ {(A , B) → Context {A} {B}}) eq κ) appendκ↦ ↦⃗₁ refl ctx = ↦⃗₁ appendκ↦ ↦⃗₂ refl ctx = ↦⃗₂ appendκ↦ ↦⃗₃ refl ctx = ↦⃗₃ appendκ↦ ↦⃗₄ refl ctx = ↦⃗₄ appendκ↦ ↦⃗₅ refl ctx = ↦⃗₅ appendκ↦ ↦⃗₆ refl ctx = ↦⃗₆ appendκ↦ ↦⃗₇ refl ctx = ↦⃗₇ appendκ↦ ↦⃗₈ refl ctx = ↦⃗₈ appendκ↦ ↦⃗₉ refl ctx = ↦⃗₉ appendκ↦ ↦⃗₁₀ refl ctx = ↦⃗₁₀ appendκ↦ ↦⃗₁₁ refl ctx = ↦⃗₁₁ appendκ↦ ↦⃗₁₂ refl ctx = ↦⃗₁₂ appendκ↦ ↦⃖₁ refl ctx = ↦⃖₁ appendκ↦ ↦⃖₂ refl ctx = ↦⃖₂ appendκ↦ ↦⃖₃ refl ctx = ↦⃖₃ appendκ↦ ↦⃖₄ refl ctx = ↦⃖₄ appendκ↦ ↦⃖₅ refl ctx = ↦⃖₅ appendκ↦ ↦⃖₆ refl ctx = ↦⃖₆ appendκ↦ ↦⃖₇ refl ctx = ↦⃖₇ appendκ↦ ↦⃖₈ refl ctx = ↦⃖₈ appendκ↦ ↦⃖₉ refl ctx = ↦⃖₉ appendκ↦ ↦⃖₁₀ refl ctx = ↦⃖₁₀ appendκ↦ ↦⃖₁₁ refl ctx = ↦⃖₁₁ appendκ↦ ↦⃖₁₂ refl ctx = ↦⃖₁₂ appendκ↦ ↦η₁ refl ctx = ↦η₁ appendκ↦ ↦η₂ refl ctx = ↦η₂ appendκ↦ ↦ε₁ refl ctx = ↦ε₁ appendκ↦ ↦ε₂ refl ctx = ↦ε₂ appendκ↦* : ∀ {st st'} → (r : st ↦* st') (eq : get𝕌State st ≡ get𝕌State st') → (κ : Context {proj₁ (get𝕌State st)} {proj₂ (get𝕌State st)}) → appendκState st κ ↦* appendκState st' (subst (λ {(A , B) → Context {A} {B}}) eq κ) appendκ↦* ◾ refl ctx = ◾ appendκ↦* (↦⃗₁ {b = b} {v} {κ} ∷ rs) eq ctx = appendκ↦ (↦⃗₁ {b = b} {v} {κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃗₂ {v = v} {κ} ∷ rs) eq ctx = appendκ↦ (↦⃗₂ {v = v} {κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃗₃ {v = v} {κ} ∷ rs) eq ctx = appendκ↦ (↦⃗₃ {v = v} {κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃗₄ {x = x} {κ} ∷ rs) eq ctx = appendκ↦ (↦⃗₄ {x = x} {κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃗₅ {y = y} {κ} ∷ rs) eq ctx = appendκ↦ (↦⃗₅ {y = y} {κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃗₆ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦⃗₆ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃗₇ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦⃗₇ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃗₈ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦⃗₈ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃗₉ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦⃗₉ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃗₁₀ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦⃗₁₀ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃗₁₁ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦⃗₁₁ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃗₁₂ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦⃗₁₂ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃖₁ {b = b} {v} {κ} ∷ rs) eq ctx = appendκ↦ (↦⃖₁ {b = b} {v} {κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃖₂ {v = v} {κ} ∷ rs) eq ctx = appendκ↦ (↦⃖₂ {v = v} {κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃖₃ {v = v} {κ} ∷ rs) eq ctx = appendκ↦ (↦⃖₃ {v = v} {κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃖₄ {x = x} {κ} ∷ rs) eq ctx = appendκ↦ (↦⃖₄ {x = x} {κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃖₅ {y = y} {κ} ∷ rs) eq ctx = appendκ↦ (↦⃖₅ {y = y} {κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃖₆ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦⃖₆ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃖₇ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦⃖₇ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃖₈ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦⃖₈ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃖₉ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦⃖₉ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃖₁₀ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦⃖₁₀ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃖₁₁ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦⃖₁₁ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦⃖₁₂ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦⃖₁₂ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦η₁ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦η₁ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦η₂ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦η₂ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦ε₁ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦ε₁ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx appendκ↦* (↦ε₂ {κ = κ} ∷ rs) eq ctx = appendκ↦ (↦ε₂ {κ = κ}) refl ctx ∷ appendκ↦* rs eq ctx
{ "alphanum_fraction": 0.5646839834, "avg_line_length": 38.1258064516, "ext": "agda", "hexsha": "541052c433b05f97e144af68f8a772ce938c3f09", "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": "Pi-/Invariants.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": "Pi-/Invariants.agda", "max_line_length": 128, "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": "Pi-/Invariants.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": 6624, "size": 11819 }
------------------------------------------------------------------------ -- Two logically equivalent axiomatisations of equality ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Equality where open import Logical-equivalence hiding (id; _∘_) open import Prelude private variable ℓ : Level A B C D : Type ℓ P : A → Type ℓ a a₁ a₂ a₃ b c p u v x x₁ x₂ y y₁ y₂ z : A f g : (x : A) → P x ------------------------------------------------------------------------ -- Reflexive relations record Reflexive-relation a : Type (lsuc a) where no-eta-equality infix 4 _≡_ field -- "Equality". _≡_ : {A : Type a} → A → A → Type a -- Reflexivity. refl : (x : A) → x ≡ x -- Some definitions. module Reflexive-relation′ (reflexive : ∀ ℓ → Reflexive-relation ℓ) where private open module R {ℓ} = Reflexive-relation (reflexive ℓ) public -- Non-equality. infix 4 _≢_ _≢_ : {A : Type a} → A → A → Type a x ≢ y = ¬ (x ≡ y) -- The property of having decidable equality. Decidable-equality : Type ℓ → Type ℓ Decidable-equality A = Decidable (_≡_ {A = A}) -- A type is contractible if it is inhabited and all elements are -- equal. Contractible : Type ℓ → Type ℓ Contractible A = ∃ λ (x : A) → ∀ y → x ≡ y -- The property of being a proposition. Is-proposition : Type ℓ → Type ℓ Is-proposition A = (x y : A) → x ≡ y -- The property of being a set. Is-set : Type ℓ → Type ℓ Is-set A = {x y : A} → Is-proposition (x ≡ y) -- Uniqueness of identity proofs (for a specific universe level). Uniqueness-of-identity-proofs : ∀ ℓ → Type (lsuc ℓ) Uniqueness-of-identity-proofs ℓ = {A : Type ℓ} → Is-set A -- The K rule (without computational content). K-rule : ∀ a p → Type (lsuc (a ⊔ p)) K-rule a p = {A : Type a} (P : {x : A} → x ≡ x → Type p) → (∀ x → P (refl x)) → ∀ {x} (x≡x : x ≡ x) → P x≡x -- Singleton x is a set which contains all elements which are equal -- to x. Singleton : {A : Type a} → A → Type a Singleton x = ∃ λ y → y ≡ x -- A variant of Singleton. Other-singleton : {A : Type a} → A → Type a Other-singleton x = ∃ λ y → x ≡ y -- The inspect idiom. inspect : (x : A) → Other-singleton x inspect x = x , refl x -- Extensionality for functions of a certain type. Extensionality′ : (A : Type a) → (A → Type b) → Type (a ⊔ b) Extensionality′ A B = {f g : (x : A) → B x} → (∀ x → f x ≡ g x) → f ≡ g -- Extensionality for functions at certain levels. -- -- The definition is wrapped in a record type in order to avoid -- certain problems related to Agda's handling of implicit -- arguments. record Extensionality (a b : Level) : Type (lsuc (a ⊔ b)) where no-eta-equality field apply-ext : {A : Type a} {B : A → Type b} → Extensionality′ A B open Extensionality public -- Proofs of extensionality which behave well when applied to -- reflexivity. Well-behaved-extensionality : (A : Type a) → (A → Type b) → Type (a ⊔ b) Well-behaved-extensionality A B = ∃ λ (ext : Extensionality′ A B) → ∀ f → ext (λ x → refl (f x)) ≡ refl f ------------------------------------------------------------------------ -- Abstract definition of equality based on the J rule -- Parametrised by a reflexive relation. record Equality-with-J₀ a p (reflexive : ∀ ℓ → Reflexive-relation ℓ) : Type (lsuc (a ⊔ p)) where open Reflexive-relation′ reflexive field -- The J rule. elim : ∀ {A : Type a} {x y} (P : {x y : A} → x ≡ y → Type p) → (∀ x → P (refl x)) → (x≡y : x ≡ y) → P x≡y -- The usual computational behaviour of the J rule. elim-refl : ∀ {A : Type a} {x} (P : {x y : A} → x ≡ y → Type p) (r : ∀ x → P (refl x)) → elim P r (refl x) ≡ r x -- Extended variants of Reflexive-relation and Equality-with-J₀ with -- some extra fields. These fields can be derived from -- Equality-with-J₀ (see J₀⇒Equivalence-relation⁺ and J₀⇒J below), but -- those derived definitions may not have the intended computational -- behaviour (in particular, not when the paths of Cubical Agda are -- used). -- A variant of Reflexive-relation: equivalence relations with some -- extra structure. record Equivalence-relation⁺ a : Type (lsuc a) where no-eta-equality field reflexive-relation : Reflexive-relation a open Reflexive-relation reflexive-relation field -- Symmetry. sym : {A : Type a} {x y : A} → x ≡ y → y ≡ x sym-refl : {A : Type a} {x : A} → sym (refl x) ≡ refl x -- Transitivity. trans : {A : Type a} {x y z : A} → x ≡ y → y ≡ z → x ≡ z trans-refl-refl : {A : Type a} {x : A} → trans (refl x) (refl x) ≡ refl x -- A variant of Equality-with-J₀. record Equality-with-J a b (e⁺ : ∀ ℓ → Equivalence-relation⁺ ℓ) : Type (lsuc (a ⊔ b)) where no-eta-equality private open module R {ℓ} = Equivalence-relation⁺ (e⁺ ℓ) open module R₀ {ℓ} = Reflexive-relation (reflexive-relation {ℓ}) field equality-with-J₀ : Equality-with-J₀ a b (λ _ → reflexive-relation) open Equality-with-J₀ equality-with-J₀ field -- Congruence. cong : {A : Type a} {B : Type b} {x y : A} (f : A → B) → x ≡ y → f x ≡ f y cong-refl : {A : Type a} {B : Type b} {x : A} (f : A → B) → cong f (refl x) ≡ refl (f x) -- Substitutivity. subst : {A : Type a} {x y : A} (P : A → Type b) → x ≡ y → P x → P y subst-refl : ∀ {A : Type a} {x} (P : A → Type b) p → subst P (refl x) p ≡ p -- A dependent variant of cong. dcong : ∀ {A : Type a} {P : A → Type b} {x y} (f : (x : A) → P x) (x≡y : x ≡ y) → subst P x≡y (f x) ≡ f y dcong-refl : ∀ {A : Type a} {P : A → Type b} {x} (f : (x : A) → P x) → dcong f (refl x) ≡ subst-refl _ _ -- Equivalence-relation⁺ can be derived from Equality-with-J₀. J₀⇒Equivalence-relation⁺ : ∀ {ℓ reflexive} → Equality-with-J₀ ℓ ℓ reflexive → Equivalence-relation⁺ ℓ J₀⇒Equivalence-relation⁺ {ℓ} {r} eq = record { reflexive-relation = r ℓ ; sym = sym ; sym-refl = sym-refl ; trans = trans ; trans-refl-refl = trans-refl-refl } where open Reflexive-relation (r ℓ) open Equality-with-J₀ eq cong : (f : A → B) → x ≡ y → f x ≡ f y cong f = elim (λ {u v} _ → f u ≡ f v) (λ x → refl (f x)) subst : (P : A → Type ℓ) → x ≡ y → P x → P y subst P = elim (λ {u v} _ → P u → P v) (λ _ p → p) subst-refl : (P : A → Type ℓ) (p : P x) → subst P (refl x) p ≡ p subst-refl P p = cong (_$ p) $ elim-refl (λ {u} _ → P u → _) _ sym : x ≡ y → y ≡ x sym {x = x} x≡y = subst (λ z → x ≡ z → z ≡ x) x≡y id x≡y abstract sym-refl : sym (refl x) ≡ refl x sym-refl = cong (_$ _) $ subst-refl (λ z → _ ≡ z → z ≡ _) _ trans : x ≡ y → y ≡ z → x ≡ z trans {x = x} = flip (subst (x ≡_)) abstract trans-refl-refl : trans (refl x) (refl x) ≡ refl x trans-refl-refl = subst-refl _ _ -- Equality-with-J (for arbitrary universe levels) can be derived from -- Equality-with-J₀ (for arbitrary universe levels). J₀⇒J : ∀ {reflexive} → (eq : ∀ {a p} → Equality-with-J₀ a p reflexive) → ∀ {a p} → Equality-with-J a p (λ _ → J₀⇒Equivalence-relation⁺ eq) J₀⇒J {r} eq {a} {b} = record { equality-with-J₀ = eq ; cong = cong ; cong-refl = cong-refl ; subst = subst ; subst-refl = subst-refl ; dcong = dcong ; dcong-refl = dcong-refl } where open module R {ℓ} = Reflexive-relation (r ℓ) open module E {a} {b} = Equality-with-J₀ (eq {a} {b}) cong : (f : A → B) → x ≡ y → f x ≡ f y cong f = elim (λ {u v} _ → f u ≡ f v) (λ x → refl (f x)) abstract cong-refl : (f : A → B) → cong f (refl x) ≡ refl (f x) cong-refl _ = elim-refl _ _ subst : (P : A → Type b) → x ≡ y → P x → P y subst P = elim (λ {u v} _ → P u → P v) (λ _ p → p) subst-refl≡id : (P : A → Type b) → subst P (refl x) ≡ id subst-refl≡id P = elim-refl (λ {u v} _ → P u → P v) (λ _ p → p) subst-refl : ∀ (P : A → Type b) p → subst P (refl x) p ≡ p subst-refl P p = cong (_$ p) (subst-refl≡id P) dcong : (f : (x : A) → P x) (x≡y : x ≡ y) → subst P x≡y (f x) ≡ f y dcong {A = A} {P = P} f x≡y = elim (λ {x y} (x≡y : x ≡ y) → (f : (x : A) → P x) → subst P x≡y (f x) ≡ f y) (λ _ _ → subst-refl _ _) x≡y f abstract dcong-refl : (f : (x : A) → P x) → dcong f (refl x) ≡ subst-refl _ _ dcong-refl {P = P} f = cong (_$ f) $ elim-refl (λ _ → (_ : ∀ x → P x) → _) _ -- Some derived properties. module Equality-with-J′ {e⁺ : ∀ ℓ → Equivalence-relation⁺ ℓ} (eq : ∀ {a p} → Equality-with-J a p e⁺) where private open module E⁺ {ℓ} = Equivalence-relation⁺ (e⁺ ℓ) public open module E {a b} = Equality-with-J (eq {a} {b}) public hiding (subst; subst-refl) open module E₀ {a p} = Equality-with-J₀ (equality-with-J₀ {a} {p}) public open Reflexive-relation′ (λ ℓ → reflexive-relation {ℓ}) public -- Substitutivity. subst : (P : A → Type p) → x ≡ y → P x → P y subst = E.subst subst-refl : (P : A → Type p) (p : P x) → subst P (refl x) p ≡ p subst-refl = E.subst-refl -- Singleton types are contractible. private irr : (p : Singleton x) → (x , refl x) ≡ p irr p = elim (λ {u v} u≡v → (v , refl v) ≡ (u , u≡v)) (λ _ → refl _) (proj₂ p) singleton-contractible : (x : A) → Contractible (Singleton x) singleton-contractible x = ((x , refl x) , irr) abstract -- "Evaluation rule" for singleton-contractible. singleton-contractible-refl : (x : A) → proj₂ (singleton-contractible x) (x , refl x) ≡ refl (x , refl x) singleton-contractible-refl _ = elim-refl _ _ ------------------------------------------------------------------------ -- Abstract definition of equality based on substitutivity and -- contractibility of singleton types record Equality-with-substitutivity-and-contractibility a p (reflexive : ∀ ℓ → Reflexive-relation ℓ) : Type (lsuc (a ⊔ p)) where no-eta-equality open Reflexive-relation′ reflexive field -- Substitutivity. subst : {A : Type a} {x y : A} (P : A → Type p) → x ≡ y → P x → P y -- The usual computational behaviour of substitutivity. subst-refl : {A : Type a} {x : A} (P : A → Type p) (p : P x) → subst P (refl x) p ≡ p -- Singleton types are contractible. singleton-contractible : {A : Type a} (x : A) → Contractible (Singleton x) -- Some derived properties. module Equality-with-substitutivity-and-contractibility′ {reflexive : ∀ ℓ → Reflexive-relation ℓ} (eq : ∀ {a p} → Equality-with-substitutivity-and-contractibility a p reflexive) where private open Reflexive-relation′ reflexive public open module E {a p} = Equality-with-substitutivity-and-contractibility (eq {a} {p}) public hiding (singleton-contractible) open module E′ {a} = Equality-with-substitutivity-and-contractibility (eq {a} {a}) public using (singleton-contractible) abstract -- Congruence. cong : (f : A → B) → x ≡ y → f x ≡ f y cong {x = x} f x≡y = subst (λ y → x ≡ y → f x ≡ f y) x≡y (λ _ → refl (f x)) x≡y -- Symmetry. sym : x ≡ y → y ≡ x sym {x = x} x≡y = subst (λ z → x ≡ z → z ≡ x) x≡y id x≡y abstract -- "Evaluation rule" for sym. sym-refl : sym (refl x) ≡ refl x sym-refl {x = x} = cong (λ f → f (refl x)) $ subst-refl (λ z → x ≡ z → z ≡ x) _ -- Transitivity. trans : x ≡ y → y ≡ z → x ≡ z trans {x = x} = flip (subst (_≡_ x)) abstract -- "Evaluation rule" for trans. trans-refl-refl : trans (refl x) (refl x) ≡ refl x trans-refl-refl = subst-refl _ _ abstract -- The J rule. elim : (P : {x y : A} → x ≡ y → Type p) → (∀ x → P (refl x)) → (x≡y : x ≡ y) → P x≡y elim {x = x} {y = y} P p x≡y = let lemma = proj₂ (singleton-contractible y) in subst (P ∘ proj₂) (trans (sym (lemma (y , refl y))) (lemma (x , x≡y))) (p y) -- Transitivity and symmetry sometimes cancel each other out. trans-sym : (x≡y : x ≡ y) → trans (sym x≡y) x≡y ≡ refl y trans-sym = elim (λ {x y} (x≡y : x ≡ y) → trans (sym x≡y) x≡y ≡ refl y) (λ _ → trans (cong (λ p → trans p _) sym-refl) trans-refl-refl) -- "Evaluation rule" for elim. elim-refl : (P : {x y : A} → x ≡ y → Type p) (p : ∀ x → P (refl x)) → elim P p (refl x) ≡ p x elim-refl {x = x} _ _ = let lemma = proj₂ (singleton-contractible x) (x , refl x) in trans (cong (λ q → subst _ q _) (trans-sym lemma)) (subst-refl _ _) ------------------------------------------------------------------------ -- The two abstract definitions are logically equivalent J⇒subst+contr : ∀ {reflexive} → (∀ {a p} → Equality-with-J₀ a p reflexive) → ∀ {a p} → Equality-with-substitutivity-and-contractibility a p reflexive J⇒subst+contr eq = record { subst = subst ; subst-refl = subst-refl ; singleton-contractible = singleton-contractible } where open Equality-with-J′ (J₀⇒J eq) subst+contr⇒J : ∀ {reflexive} → (∀ {a p} → Equality-with-substitutivity-and-contractibility a p reflexive) → ∀ {a p} → Equality-with-J₀ a p reflexive subst+contr⇒J eq = record { elim = elim ; elim-refl = elim-refl } where open Equality-with-substitutivity-and-contractibility′ eq ------------------------------------------------------------------------ -- Some derived definitions and properties module Derived-definitions-and-properties {e⁺} (equality-with-J : ∀ {a p} → Equality-with-J a p e⁺) where -- This module reexports most of the definitions and properties -- introduced above. open Equality-with-J′ equality-with-J public private variable eq u≡v v≡w x≡y y≡z x₁≡x₂ : x ≡ y -- Equational reasoning combinators. infix -1 finally _∎ infixr -2 step-≡ _≡⟨⟩_ _∎ : (x : A) → x ≡ x x ∎ = refl x -- It can be easier for Agda to type-check typical equational -- reasoning chains if the transitivity proof gets the equality -- arguments in the opposite order, because then the y argument is -- (perhaps more) known once the proof of x ≡ y is type-checked. -- -- The idea behind this optimisation came up in discussions with Ulf -- Norell. step-≡ : ∀ x → y ≡ z → x ≡ y → x ≡ z step-≡ _ = flip trans syntax step-≡ x y≡z x≡y = x ≡⟨ x≡y ⟩ y≡z _≡⟨⟩_ : ∀ x → x ≡ y → x ≡ y _ ≡⟨⟩ x≡y = x≡y finally : (x y : A) → x ≡ y → x ≡ y finally _ _ x≡y = x≡y syntax finally x y x≡y = x ≡⟨ x≡y ⟩∎ y ∎ -- A minor variant of Christine Paulin-Mohring's version of the J -- rule. -- -- This definition is based on Martin Hofmann's (see the addendum -- to Thomas Streicher's Habilitation thesis). Note that it is -- also very similar to the definition of -- Equality-with-substitutivity-and-contractibility.elim. elim₁ : (P : ∀ {x} → x ≡ y → Type p) → P (refl y) → (x≡y : x ≡ y) → P x≡y elim₁ {y = y} {x = x} P p x≡y = subst (P ∘ proj₂) (proj₂ (singleton-contractible y) (x , x≡y)) p abstract -- "Evaluation rule" for elim₁. elim₁-refl : (P : ∀ {x} → x ≡ y → Type p) (p : P (refl y)) → elim₁ P p (refl y) ≡ p elim₁-refl {y = y} P p = subst (P ∘ proj₂) (proj₂ (singleton-contractible y) (y , refl y)) p ≡⟨ cong (λ q → subst (P ∘ proj₂) q _) (singleton-contractible-refl _) ⟩ subst (P ∘ proj₂) (refl (y , refl y)) p ≡⟨ subst-refl _ _ ⟩∎ p ∎ -- A variant of singleton-contractible. private irr : (p : Other-singleton x) → (x , refl x) ≡ p irr p = elim (λ {u v} u≡v → (u , refl u) ≡ (v , u≡v)) (λ _ → refl _) (proj₂ p) other-singleton-contractible : (x : A) → Contractible (Other-singleton x) other-singleton-contractible x = ((x , refl x) , irr) abstract -- "Evaluation rule" for other-singleton-contractible. other-singleton-contractible-refl : (x : A) → proj₂ (other-singleton-contractible x) (x , refl x) ≡ refl (x , refl x) other-singleton-contractible-refl _ = elim-refl _ _ -- Christine Paulin-Mohring's version of the J rule. elim¹ : (P : ∀ {y} → x ≡ y → Type p) → P (refl x) → (x≡y : x ≡ y) → P x≡y elim¹ {x = x} {y = y} P p x≡y = subst (P ∘ proj₂) (proj₂ (other-singleton-contractible x) (y , x≡y)) p abstract -- "Evaluation rule" for elim¹. elim¹-refl : (P : ∀ {y} → x ≡ y → Type p) (p : P (refl x)) → elim¹ P p (refl x) ≡ p elim¹-refl {x = x} P p = subst (P ∘ proj₂) (proj₂ (other-singleton-contractible x) (x , refl x)) p ≡⟨ cong (λ q → subst (P ∘ proj₂) q _) (other-singleton-contractible-refl _) ⟩ subst (P ∘ proj₂) (refl (x , refl x)) p ≡⟨ subst-refl _ _ ⟩∎ p ∎ -- Every conceivable alternative implementation of cong (for two -- specific types) is pointwise equal to cong. monomorphic-cong-canonical : (cong′ : {x y : A} (f : A → B) → x ≡ y → f x ≡ f y) → ({x : A} (f : A → B) → cong′ f (refl x) ≡ refl (f x)) → cong′ f x≡y ≡ cong f x≡y monomorphic-cong-canonical {f = f} cong′ cong′-refl = elim (λ x≡y → cong′ f x≡y ≡ cong f x≡y) (λ x → cong′ f (refl x) ≡⟨ cong′-refl _ ⟩ refl (f x) ≡⟨ sym $ cong-refl _ ⟩∎ cong f (refl x) ∎) _ -- Every conceivable alternative implementation of cong (for -- arbitrary types) is pointwise equal to cong. cong-canonical : (cong′ : ∀ {a b} {A : Type a} {B : Type b} {x y : A} (f : A → B) → x ≡ y → f x ≡ f y) → (∀ {a b} {A : Type a} {B : Type b} {x : A} (f : A → B) → cong′ f (refl x) ≡ refl (f x)) → cong′ f x≡y ≡ cong f x≡y cong-canonical cong′ cong′-refl = monomorphic-cong-canonical cong′ cong′-refl -- A generalisation of dcong. dcong′ : (f : (x : A) → x ≡ y → P x) (x≡y : x ≡ y) → subst P x≡y (f x x≡y) ≡ f y (refl y) dcong′ {y = y} {P = P} f x≡y = elim₁ (λ {x} (x≡y : x ≡ y) → (f : ∀ x → x ≡ y → P x) → subst P x≡y (f x x≡y) ≡ f y (refl y)) (λ f → subst P (refl y) (f y (refl y)) ≡⟨ subst-refl _ _ ⟩∎ f y (refl y) ∎) x≡y f abstract -- "Evaluation rule" for dcong′. dcong′-refl : (f : (x : A) → x ≡ y → P x) → dcong′ f (refl y) ≡ subst-refl _ _ dcong′-refl {y = y} {P = P} f = cong (_$ f) $ elim₁-refl (λ _ → (f : ∀ x → x ≡ y → P x) → _) _ -- Binary congruence. cong₂ : (f : A → B → C) → x ≡ y → u ≡ v → f x u ≡ f y v cong₂ {x = x} {y = y} {u = u} {v = v} f x≡y u≡v = f x u ≡⟨ cong (flip f u) x≡y ⟩ f y u ≡⟨ cong (f y) u≡v ⟩∎ f y v ∎ abstract -- "Evaluation rule" for cong₂. cong₂-refl : (f : A → B → C) → cong₂ f (refl x) (refl y) ≡ refl (f x y) cong₂-refl {x = x} {y = y} f = trans (cong (flip f y) (refl x)) (cong (f x) (refl y)) ≡⟨ cong₂ trans (cong-refl _) (cong-refl _) ⟩ trans (refl (f x y)) (refl (f x y)) ≡⟨ trans-refl-refl ⟩∎ refl (f x y) ∎ -- The K rule is logically equivalent to uniqueness of identity -- proofs (at least for certain combinations of levels). K⇔UIP : K-rule ℓ ℓ ⇔ Uniqueness-of-identity-proofs ℓ K⇔UIP = record { from = λ UIP P r {x} x≡x → subst P (UIP (refl x) x≡x) (r x) ; to = λ K → elim (λ p → ∀ q → p ≡ q) (λ x → K (λ {x} p → refl x ≡ p) (λ x → refl (refl x))) } abstract -- Extensionality at given levels works at lower levels as well. lower-extensionality : ∀ â b̂ → Extensionality (a ⊔ â) (b ⊔ b̂) → Extensionality a b apply-ext (lower-extensionality â b̂ ext) f≡g = cong (λ h → lower ∘ h ∘ lift) $ apply-ext ext {A = ↑ â _} {B = ↑ b̂ ∘ _} (cong lift ∘ f≡g ∘ lower) -- Extensionality for explicit function types works for implicit -- function types as well. implicit-extensionality : Extensionality a b → {A : Type a} {B : A → Type b} {f g : {x : A} → B x} → (∀ x → f {x} ≡ g {x}) → (λ {x} → f {x}) ≡ g implicit-extensionality ext f≡g = cong (λ f {x} → f x) $ apply-ext ext f≡g -- A bunch of lemmas that can be used to rearrange equalities. abstract trans-reflʳ : (x≡y : x ≡ y) → trans x≡y (refl y) ≡ x≡y trans-reflʳ = elim (λ {u v} u≡v → trans u≡v (refl v) ≡ u≡v) (λ _ → trans-refl-refl) trans-reflˡ : (x≡y : x ≡ y) → trans (refl x) x≡y ≡ x≡y trans-reflˡ = elim (λ {u v} u≡v → trans (refl u) u≡v ≡ u≡v) (λ _ → trans-refl-refl) trans-assoc : (x≡y : x ≡ y) (y≡z : y ≡ z) (z≡u : z ≡ u) → trans (trans x≡y y≡z) z≡u ≡ trans x≡y (trans y≡z z≡u) trans-assoc = elim (λ x≡y → ∀ y≡z z≡u → trans (trans x≡y y≡z) z≡u ≡ trans x≡y (trans y≡z z≡u)) (λ y y≡z z≡u → trans (trans (refl y) y≡z) z≡u ≡⟨ cong₂ trans (trans-reflˡ _) (refl _) ⟩ trans y≡z z≡u ≡⟨ sym $ trans-reflˡ _ ⟩∎ trans (refl y) (trans y≡z z≡u) ∎) sym-sym : (x≡y : x ≡ y) → sym (sym x≡y) ≡ x≡y sym-sym = elim (λ {u v} u≡v → sym (sym u≡v) ≡ u≡v) (λ x → sym (sym (refl x)) ≡⟨ cong sym sym-refl ⟩ sym (refl x) ≡⟨ sym-refl ⟩∎ refl x ∎) sym-trans : (x≡y : x ≡ y) (y≡z : y ≡ z) → sym (trans x≡y y≡z) ≡ trans (sym y≡z) (sym x≡y) sym-trans = elim (λ x≡y → ∀ y≡z → sym (trans x≡y y≡z) ≡ trans (sym y≡z) (sym x≡y)) (λ y y≡z → sym (trans (refl y) y≡z) ≡⟨ cong sym (trans-reflˡ _) ⟩ sym y≡z ≡⟨ sym $ trans-reflʳ _ ⟩ trans (sym y≡z) (refl y) ≡⟨ cong (trans (sym y≡z)) (sym sym-refl) ⟩∎ trans (sym y≡z) (sym (refl y)) ∎) trans-symˡ : (p : x ≡ y) → trans (sym p) p ≡ refl y trans-symˡ = elim (λ p → trans (sym p) p ≡ refl _) (λ x → trans (sym (refl x)) (refl x) ≡⟨ trans-reflʳ _ ⟩ sym (refl x) ≡⟨ sym-refl ⟩∎ refl x ∎) trans-symʳ : (p : x ≡ y) → trans p (sym p) ≡ refl _ trans-symʳ = elim (λ p → trans p (sym p) ≡ refl _) (λ x → trans (refl x) (sym (refl x)) ≡⟨ trans-reflˡ _ ⟩ sym (refl x) ≡⟨ sym-refl ⟩∎ refl x ∎) cong-trans : (f : A → B) (x≡y : x ≡ y) (y≡z : y ≡ z) → cong f (trans x≡y y≡z) ≡ trans (cong f x≡y) (cong f y≡z) cong-trans f = elim (λ x≡y → ∀ y≡z → cong f (trans x≡y y≡z) ≡ trans (cong f x≡y) (cong f y≡z)) (λ y y≡z → cong f (trans (refl y) y≡z) ≡⟨ cong (cong f) (trans-reflˡ _) ⟩ cong f y≡z ≡⟨ sym $ trans-reflˡ _ ⟩ trans (refl (f y)) (cong f y≡z) ≡⟨ cong₂ trans (sym (cong-refl _)) (refl _) ⟩∎ trans (cong f (refl y)) (cong f y≡z) ∎) cong-id : (x≡y : x ≡ y) → x≡y ≡ cong id x≡y cong-id = elim (λ u≡v → u≡v ≡ cong id u≡v) (λ x → refl x ≡⟨ sym (cong-refl _) ⟩∎ cong id (refl x) ∎) cong-const : (x≡y : x ≡ y) → cong (const z) x≡y ≡ refl z cong-const {z = z} = elim (λ u≡v → cong (const z) u≡v ≡ refl z) (λ x → cong (const z) (refl x) ≡⟨ cong-refl _ ⟩∎ refl z ∎) cong-∘ : (f : B → C) (g : A → B) (x≡y : x ≡ y) → cong f (cong g x≡y) ≡ cong (f ∘ g) x≡y cong-∘ f g = elim (λ x≡y → cong f (cong g x≡y) ≡ cong (f ∘ g) x≡y) (λ x → cong f (cong g (refl x)) ≡⟨ cong (cong f) (cong-refl _) ⟩ cong f (refl (g x)) ≡⟨ cong-refl _ ⟩ refl (f (g x)) ≡⟨ sym (cong-refl _) ⟩∎ cong (f ∘ g) (refl x) ∎) cong-uncurry-cong₂-, : {x≡y : x ≡ y} {u≡v : u ≡ v} → cong (uncurry f) (cong₂ _,_ x≡y u≡v) ≡ cong₂ f x≡y u≡v cong-uncurry-cong₂-, {y = y} {u = u} {f = f} {x≡y = x≡y} {u≡v} = cong (uncurry f) (trans (cong (flip _,_ u) x≡y) (cong (_,_ y) u≡v)) ≡⟨ cong-trans _ _ _ ⟩ trans (cong (uncurry f) (cong (flip _,_ u) x≡y)) (cong (uncurry f) (cong (_,_ y) u≡v)) ≡⟨ cong₂ trans (cong-∘ _ _ _) (cong-∘ _ _ _) ⟩∎ trans (cong (flip f u) x≡y) (cong (f y) u≡v) ∎ cong-proj₁-cong₂-, : (x≡y : x ≡ y) (u≡v : u ≡ v) → cong proj₁ (cong₂ _,_ x≡y u≡v) ≡ x≡y cong-proj₁-cong₂-, {y = y} x≡y u≡v = cong proj₁ (cong₂ _,_ x≡y u≡v) ≡⟨ cong-uncurry-cong₂-, ⟩ cong₂ const x≡y u≡v ≡⟨⟩ trans (cong id x≡y) (cong (const y) u≡v) ≡⟨ cong₂ trans (sym $ cong-id _) (cong-const _) ⟩ trans x≡y (refl y) ≡⟨ trans-reflʳ _ ⟩∎ x≡y ∎ cong-proj₂-cong₂-, : (x≡y : x ≡ y) (u≡v : u ≡ v) → cong proj₂ (cong₂ _,_ x≡y u≡v) ≡ u≡v cong-proj₂-cong₂-, {u = u} x≡y u≡v = cong proj₂ (cong₂ _,_ x≡y u≡v) ≡⟨ cong-uncurry-cong₂-, ⟩ cong₂ (const id) x≡y u≡v ≡⟨⟩ trans (cong (const u) x≡y) (cong id u≡v) ≡⟨ cong₂ trans (cong-const _) (sym $ cong-id _) ⟩ trans (refl u) u≡v ≡⟨ trans-reflˡ _ ⟩∎ u≡v ∎ cong₂-reflˡ : {u≡v : u ≡ v} (f : A → B → C) → cong₂ f (refl x) u≡v ≡ cong (f x) u≡v cong₂-reflˡ {u = u} {x = x} {u≡v = u≡v} f = trans (cong (flip f u) (refl x)) (cong (f x) u≡v) ≡⟨ cong₂ trans (cong-refl _) (refl _) ⟩ trans (refl (f x u)) (cong (f x) u≡v) ≡⟨ trans-reflˡ _ ⟩∎ cong (f x) u≡v ∎ cong₂-reflʳ : (f : A → B → C) {x≡y : x ≡ y} → cong₂ f x≡y (refl u) ≡ cong (flip f u) x≡y cong₂-reflʳ {y = y} {u = u} f {x≡y} = trans (cong (flip f u) x≡y) (cong (f y) (refl u)) ≡⟨ cong (trans _) (cong-refl _) ⟩ trans (cong (flip f u) x≡y) (refl (f y u)) ≡⟨ trans-reflʳ _ ⟩∎ cong (flip f u) x≡y ∎ cong-sym : (f : A → B) (x≡y : x ≡ y) → cong f (sym x≡y) ≡ sym (cong f x≡y) cong-sym f = elim (λ x≡y → cong f (sym x≡y) ≡ sym (cong f x≡y)) (λ x → cong f (sym (refl x)) ≡⟨ cong (cong f) sym-refl ⟩ cong f (refl x) ≡⟨ cong-refl _ ⟩ refl (f x) ≡⟨ sym sym-refl ⟩ sym (refl (f x)) ≡⟨ cong sym $ sym (cong-refl _) ⟩∎ sym (cong f (refl x)) ∎) cong₂-sym : cong₂ f (sym x≡y) (sym u≡v) ≡ sym (cong₂ f x≡y u≡v) cong₂-sym {f = f} {x≡y = x≡y} {u≡v = u≡v} = elim¹ (λ u≡v → cong₂ f (sym x≡y) (sym u≡v) ≡ sym (cong₂ f x≡y u≡v)) (cong₂ f (sym x≡y) (sym (refl _)) ≡⟨ cong (cong₂ _ _) sym-refl ⟩ cong₂ f (sym x≡y) (refl _) ≡⟨ cong₂-reflʳ _ ⟩ cong (flip f _) (sym x≡y) ≡⟨ cong-sym _ _ ⟩ sym (cong (flip f _) x≡y) ≡⟨ cong sym $ sym $ cong₂-reflʳ _ ⟩∎ sym (cong₂ f x≡y (refl _)) ∎) u≡v cong₂-trans : {f : A → B → C} → cong₂ f (trans x≡y y≡z) (trans u≡v v≡w) ≡ trans (cong₂ f x≡y u≡v) (cong₂ f y≡z v≡w) cong₂-trans {x≡y = x≡y} {y≡z = y≡z} {u≡v = u≡v} {v≡w = v≡w} {f = f} = elim₁ (λ x≡y → cong₂ f (trans x≡y y≡z) (trans u≡v v≡w) ≡ trans (cong₂ f x≡y u≡v) (cong₂ f y≡z v≡w)) (elim₁ (λ u≡v → cong₂ f (trans (refl _) y≡z) (trans u≡v v≡w) ≡ trans (cong₂ f (refl _) u≡v) (cong₂ f y≡z v≡w)) (cong₂ f (trans (refl _) y≡z) (trans (refl _) v≡w) ≡⟨ cong₂ (cong₂ f) (trans-reflˡ _) (trans-reflˡ _) ⟩ cong₂ f y≡z v≡w ≡⟨ sym $ trans (cong (flip trans _) $ cong₂-refl _) $ trans-reflˡ _ ⟩∎ trans (cong₂ f (refl _) (refl _)) (cong₂ f y≡z v≡w) ∎) u≡v) x≡y cong₂-∘ˡ : {f : B → C → D} {g : A → B} {x≡y : x ≡ y} {u≡v : u ≡ v} → cong₂ (f ∘ g) x≡y u≡v ≡ cong₂ f (cong g x≡y) u≡v cong₂-∘ˡ {y = y} {u = u} {f = f} {g = g} {x≡y = x≡y} {u≡v} = trans (cong (flip (f ∘ g) u) x≡y) (cong (f (g y)) u≡v) ≡⟨ cong (flip trans _) $ sym $ cong-∘ _ _ _ ⟩∎ trans (cong (flip f u) (cong g x≡y)) (cong (f (g y)) u≡v) ∎ cong₂-∘ʳ : {x≡y : x ≡ y} {u≡v : u ≡ v} → cong₂ (λ x → f x ∘ g) x≡y u≡v ≡ cong₂ f x≡y (cong g u≡v) cong₂-∘ʳ {y = y} {u = u} {f = f} {g = g} {x≡y = x≡y} {u≡v} = trans (cong (flip f (g u)) x≡y) (cong (f y ∘ g) u≡v) ≡⟨ cong (trans _) $ sym $ cong-∘ _ _ _ ⟩∎ trans (cong (flip f (g u)) x≡y) (cong (f y) (cong g u≡v)) ∎ cong₂-cong-cong : (f : A → B) (g : A → C) (h : B → C → D) → cong₂ h (cong f eq) (cong g eq) ≡ cong (λ x → h (f x) (g x)) eq cong₂-cong-cong f g h = elim¹ (λ eq → cong₂ h (cong f eq) (cong g eq) ≡ cong (λ x → h (f x) (g x)) eq) (cong₂ h (cong f (refl _)) (cong g (refl _)) ≡⟨ cong₂ (cong₂ h) (cong-refl _) (cong-refl _) ⟩ cong₂ h (refl _) (refl _) ≡⟨ cong₂-refl h ⟩ refl _ ≡⟨ sym $ cong-refl _ ⟩∎ cong (λ x → h (f x) (g x)) (refl _) ∎) _ cong-≡id : {f : A → A} (f≡id : f ≡ id) → cong (λ g → g (f x)) f≡id ≡ cong (λ g → f (g x)) f≡id cong-≡id = elim₁ (λ {f} p → cong (λ g → g (f _)) p ≡ cong (λ g → f (g _)) p) (refl _) cong-≡id-≡-≡id : (f≡id : ∀ x → f x ≡ x) → cong f (f≡id x) ≡ f≡id (f x) cong-≡id-≡-≡id {f = f} {x = x} f≡id = cong f (f≡id x) ≡⟨ elim¹ (λ {y} (p : f x ≡ y) → cong f p ≡ trans (f≡id (f x)) (trans p (sym (f≡id y)))) ( cong f (refl _) ≡⟨ cong-refl _ ⟩ refl _ ≡⟨ sym $ trans-symʳ _ ⟩ trans (f≡id (f x)) (sym (f≡id (f x))) ≡⟨ cong (trans (f≡id (f x))) $ sym $ trans-reflˡ _ ⟩∎ trans (f≡id (f x)) (trans (refl _) (sym (f≡id (f x)))) ∎) (f≡id x)⟩ trans (f≡id (f x)) (trans (f≡id x) (sym (f≡id x))) ≡⟨ cong (trans (f≡id (f x))) $ trans-symʳ _ ⟩ trans (f≡id (f x)) (refl _) ≡⟨ trans-reflʳ _ ⟩ f≡id (f x) ∎ elim-∘ : (P Q : ∀ {x y} → x ≡ y → Type p) (f : ∀ {x y} {x≡y : x ≡ y} → P x≡y → Q x≡y) (r : ∀ x → P (refl x)) {x≡y : x ≡ y} → f (elim P r x≡y) ≡ elim Q (f ∘ r) x≡y elim-∘ {x = x} P Q f r {x≡y} = elim¹ (λ x≡y → f (elim P r x≡y) ≡ elim Q (f ∘ r) x≡y) (f (elim P r (refl x)) ≡⟨ cong f $ elim-refl _ _ ⟩ f (r x) ≡⟨ sym $ elim-refl _ _ ⟩∎ elim Q (f ∘ r) (refl x) ∎) x≡y elim-cong : (P : B → B → Type p) (f : A → B) (r : ∀ x → P x x) {x≡y : x ≡ y} → elim (λ {x y} _ → P x y) r (cong f x≡y) ≡ elim (λ {x y} _ → P (f x) (f y)) (r ∘ f) x≡y elim-cong {x = x} P f r {x≡y} = elim¹ (λ x≡y → elim (λ {x y} _ → P x y) r (cong f x≡y) ≡ elim (λ {x y} _ → P (f x) (f y)) (r ∘ f) x≡y) (elim (λ {x y} _ → P x y) r (cong f (refl x)) ≡⟨ cong (elim (λ {x y} _ → P x y) _) $ cong-refl _ ⟩ elim (λ {x y} _ → P x y) r (refl (f x)) ≡⟨ elim-refl _ _ ⟩ r (f x) ≡⟨ sym $ elim-refl _ _ ⟩∎ elim (λ {x y} _ → P (f x) (f y)) (r ∘ f) (refl x) ∎) x≡y subst-const : ∀ (x₁≡x₂ : x₁ ≡ x₂) {b} → subst (const B) x₁≡x₂ b ≡ b subst-const {B = B} x₁≡x₂ {b} = elim¹ (λ x₁≡x₂ → subst (const B) x₁≡x₂ b ≡ b) (subst-refl _ _) x₁≡x₂ abstract -- One can express sym in terms of subst. sym-subst : sym x≡y ≡ subst (λ z → x ≡ z → z ≡ x) x≡y id x≡y sym-subst = elim (λ {x} x≡y → sym x≡y ≡ subst (λ z → x ≡ z → z ≡ x) x≡y id x≡y) (λ x → sym (refl x) ≡⟨ sym-refl ⟩ refl x ≡⟨ cong (_$ refl x) $ sym $ subst-refl (λ z → x ≡ z → _) _ ⟩∎ subst (λ z → x ≡ z → z ≡ x) (refl x) id (refl x) ∎) _ -- One can express trans in terms of subst (in several ways). trans-subst : {x≡y : x ≡ y} {y≡z : y ≡ z} → trans x≡y y≡z ≡ subst (x ≡_) y≡z x≡y trans-subst {z = z} = elim (λ {x y} x≡y → (y≡z : y ≡ z) → trans x≡y y≡z ≡ subst (x ≡_) y≡z x≡y) (λ y → elim (λ {y} y≡z → trans (refl y) y≡z ≡ subst (y ≡_) y≡z (refl y)) (λ x → trans (refl x) (refl x) ≡⟨ trans-refl-refl ⟩ refl x ≡⟨ sym $ subst-refl _ _ ⟩∎ subst (x ≡_) (refl x) (refl x) ∎)) _ _ subst-trans : (x≡y : x ≡ y) {y≡z : y ≡ z} → subst (_≡ z) (sym x≡y) y≡z ≡ trans x≡y y≡z subst-trans {y = y} {z} x≡y {y≡z} = elim₁ (λ x≡y → subst (λ x → x ≡ z) (sym x≡y) y≡z ≡ trans x≡y y≡z) (subst (λ x → x ≡ z) (sym (refl y)) y≡z ≡⟨ cong (λ eq → subst (λ x → x ≡ z) eq _) sym-refl ⟩ subst (λ x → x ≡ z) (refl y) y≡z ≡⟨ subst-refl _ _ ⟩ y≡z ≡⟨ sym $ trans-reflˡ _ ⟩∎ trans (refl y) y≡z ∎) x≡y subst-trans-sym : {y≡x : y ≡ x} {y≡z : y ≡ z} → subst (_≡ z) y≡x y≡z ≡ trans (sym y≡x) y≡z subst-trans-sym {z = z} {y≡x = y≡x} {y≡z = y≡z} = subst (_≡ z) y≡x y≡z ≡⟨ cong (flip (subst (_≡ z)) _) $ sym $ sym-sym _ ⟩ subst (_≡ z) (sym (sym y≡x)) y≡z ≡⟨ subst-trans _ ⟩∎ trans (sym y≡x) y≡z ∎ -- One can express subst in terms of elim. subst-elim : subst P x≡y p ≡ elim (λ {u v} _ → P u → P v) (λ _ → id) x≡y p subst-elim {P = P} = elim (λ x≡y → ∀ p → subst P x≡y p ≡ elim (λ {u v} _ → P u → P v) (λ _ → id) x≡y p) (λ x p → subst P (refl x) p ≡⟨ subst-refl _ _ ⟩ p ≡⟨ cong (_$ p) $ sym $ elim-refl (λ {u} _ → P u → _) _ ⟩∎ elim (λ {u v} _ → P u → P v) (λ _ → id) (refl x) p ∎) _ _ subst-∘ : (P : B → Type p) (f : A → B) (x≡y : x ≡ y) {p : P (f x)} → subst (P ∘ f) x≡y p ≡ subst P (cong f x≡y) p subst-∘ P f _ {p} = elim¹ (λ x≡y → subst (P ∘ f) x≡y p ≡ subst P (cong f x≡y) p) (subst (P ∘ f) (refl _) p ≡⟨ subst-refl _ _ ⟩ p ≡⟨ sym $ subst-refl _ _ ⟩ subst P (refl _) p ≡⟨ cong (flip (subst _) _) $ sym $ cong-refl _ ⟩∎ subst P (cong f (refl _)) p ∎) _ subst-↑ : (P : A → Type p) {p : ↑ ℓ (P x)} → subst (↑ ℓ ∘ P) x≡y p ≡ lift (subst P x≡y (lower p)) subst-↑ {ℓ = ℓ} P {p} = elim¹ (λ x≡y → subst (↑ ℓ ∘ P) x≡y p ≡ lift (subst P x≡y (lower p))) (subst (↑ ℓ ∘ P) (refl _) p ≡⟨ subst-refl _ _ ⟩ p ≡⟨ cong lift $ sym $ subst-refl _ _ ⟩∎ lift (subst P (refl _) (lower p)) ∎) _ -- A fusion law for subst. subst-subst : (P : A → Type p) (x≡y : x ≡ y) (y≡z : y ≡ z) (p : P x) → subst P y≡z (subst P x≡y p) ≡ subst P (trans x≡y y≡z) p subst-subst P x≡y y≡z p = elim (λ {x y} x≡y → ∀ {z} (y≡z : y ≡ z) p → subst P y≡z (subst P x≡y p) ≡ subst P (trans x≡y y≡z) p) (λ x y≡z p → subst P y≡z (subst P (refl x) p) ≡⟨ cong (subst P _) $ subst-refl _ _ ⟩ subst P y≡z p ≡⟨ cong (λ q → subst P q _) (sym $ trans-reflˡ _) ⟩∎ subst P (trans (refl x) y≡z) p ∎) x≡y y≡z p -- "Computation rules" for subst-subst. subst-subst-reflˡ : ∀ (P : A → Type p) {p} → subst-subst P (refl x) x≡y p ≡ cong₂ (flip (subst P)) (subst-refl _ _) (sym $ trans-reflˡ x≡y) subst-subst-reflˡ P = cong (λ f → f _ _) $ elim-refl (λ {x y} x≡y → ∀ {z} (y≡z : y ≡ z) p → subst P y≡z (subst P x≡y p) ≡ _) _ subst-subst-refl-refl : ∀ (P : A → Type p) {p} → subst-subst P (refl x) (refl x) p ≡ cong₂ (flip (subst P)) (subst-refl _ _) (sym trans-refl-refl) subst-subst-refl-refl {x = x} P {p} = subst-subst P (refl x) (refl x) p ≡⟨ subst-subst-reflˡ _ ⟩ cong₂ (flip (subst P)) (subst-refl _ _) (sym $ trans-reflˡ (refl x)) ≡⟨ cong (cong₂ (flip (subst P)) (subst-refl _ _) ∘ sym) $ elim-refl _ _ ⟩∎ cong₂ (flip (subst P)) (subst-refl _ _) (sym trans-refl-refl) ∎ -- Substitutivity and symmetry sometimes cancel each other out. subst-subst-sym : (P : A → Type p) (x≡y : x ≡ y) (p : P y) → subst P x≡y (subst P (sym x≡y) p) ≡ p subst-subst-sym P = elim¹ (λ x≡y → ∀ p → subst P x≡y (subst P (sym x≡y) p) ≡ p) (λ p → subst P (refl _) (subst P (sym (refl _)) p) ≡⟨ subst-refl _ _ ⟩ subst P (sym (refl _)) p ≡⟨ cong (flip (subst P) _) sym-refl ⟩ subst P (refl _) p ≡⟨ subst-refl _ _ ⟩∎ p ∎) subst-sym-subst : (P : A → Type p) {x≡y : x ≡ y} {p : P x} → subst P (sym x≡y) (subst P x≡y p) ≡ p subst-sym-subst P {x≡y = x≡y} {p = p} = elim¹ (λ x≡y → ∀ p → subst P (sym x≡y) (subst P x≡y p) ≡ p) (λ p → subst P (sym (refl _)) (subst P (refl _) p) ≡⟨ cong (flip (subst P) _) sym-refl ⟩ subst P (refl _) (subst P (refl _) p) ≡⟨ subst-refl _ _ ⟩ subst P (refl _) p ≡⟨ subst-refl _ _ ⟩∎ p ∎) x≡y p -- Some "computation rules". subst-subst-sym-refl : (P : A → Type p) {p : P x} → subst-subst-sym P (refl x) p ≡ trans (subst-refl _ _) (trans (cong (flip (subst P) _) sym-refl) (subst-refl _ _)) subst-subst-sym-refl P {p = p} = cong (_$ _) $ elim¹-refl (λ x≡y → ∀ p → subst P x≡y (subst P (sym x≡y) p) ≡ p) _ subst-sym-subst-refl : (P : A → Type p) {p : P x} → subst-sym-subst P {x≡y = refl x} {p = p} ≡ trans (cong (flip (subst P) _) sym-refl) (trans (subst-refl _ _) (subst-refl _ _)) subst-sym-subst-refl P = cong (_$ _) $ elim¹-refl (λ x≡y → ∀ p → subst P (sym x≡y) (subst P x≡y p) ≡ p) _ -- Some corollaries and variants. trans-[trans-sym]- : (a≡b : a ≡ b) (c≡b : c ≡ b) → trans (trans a≡b (sym c≡b)) c≡b ≡ a≡b trans-[trans-sym]- a≡b c≡b = trans (trans a≡b (sym c≡b)) c≡b ≡⟨ trans-subst ⟩ subst (_ ≡_) c≡b (trans a≡b (sym c≡b)) ≡⟨ cong (subst _ _) trans-subst ⟩ subst (_ ≡_) c≡b (subst (_ ≡_) (sym c≡b) a≡b) ≡⟨ subst-subst-sym _ _ _ ⟩∎ a≡b ∎ trans-[trans]-sym : (a≡b : a ≡ b) (b≡c : b ≡ c) → trans (trans a≡b b≡c) (sym b≡c) ≡ a≡b trans-[trans]-sym a≡b b≡c = trans (trans a≡b b≡c) (sym b≡c) ≡⟨ sym $ cong (λ eq → trans (trans _ eq) (sym b≡c)) $ sym-sym _ ⟩ trans (trans a≡b (sym (sym b≡c))) (sym b≡c) ≡⟨ trans-[trans-sym]- _ _ ⟩∎ a≡b ∎ trans--[trans-sym] : (b≡a : b ≡ a) (b≡c : b ≡ c) → trans b≡a (trans (sym b≡a) b≡c) ≡ b≡c trans--[trans-sym] b≡a b≡c = trans b≡a (trans (sym b≡a) b≡c) ≡⟨ sym $ trans-assoc _ _ _ ⟩ trans (trans b≡a (sym b≡a)) b≡c ≡⟨ cong (flip trans _) $ trans-symʳ _ ⟩ trans (refl _) b≡c ≡⟨ trans-reflˡ _ ⟩∎ b≡c ∎ trans-sym-[trans] : (a≡b : a ≡ b) (b≡c : b ≡ c) → trans (sym a≡b) (trans a≡b b≡c) ≡ b≡c trans-sym-[trans] a≡b b≡c = trans (sym a≡b) (trans a≡b b≡c) ≡⟨ cong (λ p → trans (sym _) (trans p _)) $ sym $ sym-sym _ ⟩ trans (sym a≡b) (trans (sym (sym a≡b)) b≡c) ≡⟨ trans--[trans-sym] _ _ ⟩∎ b≡c ∎ -- The lemmas subst-refl and subst-const can cancel each other -- out. subst-refl-subst-const : trans (sym $ subst-refl (λ _ → B) b) (subst-const (refl x)) ≡ refl b subst-refl-subst-const {b = b} {x = x} = trans (sym $ subst-refl _ _) (elim¹ (λ eq → subst (λ _ → _) eq b ≡ b) (subst-refl _ _) (refl _)) ≡⟨ cong (trans _) (elim¹-refl _ _) ⟩ trans (sym $ subst-refl _ _) (subst-refl _ _) ≡⟨ trans-symˡ _ ⟩∎ refl _ ∎ -- In non-dependent cases one can express dcong using subst-const -- and cong. -- -- This is (similar to) Lemma 2.3.8 in the HoTT book. dcong-subst-const-cong : (f : A → B) (x≡y : x ≡ y) → dcong f x≡y ≡ (subst (const B) x≡y (f x) ≡⟨ subst-const _ ⟩ f x ≡⟨ cong f x≡y ⟩∎ f y ∎) dcong-subst-const-cong f = elim (λ {x y} x≡y → dcong f x≡y ≡ trans (subst-const x≡y) (cong f x≡y)) (λ x → dcong f (refl x) ≡⟨ dcong-refl _ ⟩ subst-refl _ _ ≡⟨ sym $ trans-reflʳ _ ⟩ trans (subst-refl _ _) (refl (f x)) ≡⟨ cong₂ trans (sym $ elim¹-refl _ _) (sym $ cong-refl _) ⟩∎ trans (subst-const _) (cong f (refl x)) ∎) -- A corollary. dcong≡→cong≡ : {x≡y : x ≡ y} {fx≡fy : f x ≡ f y} → dcong f x≡y ≡ trans (subst-const _) fx≡fy → cong f x≡y ≡ fx≡fy dcong≡→cong≡ {f = f} {x≡y = x≡y} {fx≡fy} hyp = cong f x≡y ≡⟨ sym $ trans-sym-[trans] _ _ ⟩ trans (sym $ subst-const _) (trans (subst-const _) $ cong f x≡y) ≡⟨ cong (trans (sym $ subst-const _)) $ sym $ dcong-subst-const-cong _ _ ⟩ trans (sym $ subst-const _) (dcong f x≡y) ≡⟨ cong (trans (sym $ subst-const _)) hyp ⟩ trans (sym $ subst-const _) (trans (subst-const _) fx≡fy) ≡⟨ trans-sym-[trans] _ _ ⟩∎ fx≡fy ∎ -- A kind of symmetry for "dependent paths". dsym : {x≡y : x ≡ y} {P : A → Type p} {p : P x} {q : P y} → subst P x≡y p ≡ q → subst P (sym x≡y) q ≡ p dsym {x≡y = x≡y} {P = P} p≡q = elim (λ {x y} x≡y → ∀ {p : P x} {q : P y} → subst P x≡y p ≡ q → subst P (sym x≡y) q ≡ p) (λ _ {p q} p≡q → subst P (sym (refl _)) q ≡⟨ cong (flip (subst P) _) sym-refl ⟩ subst P (refl _) q ≡⟨ subst-refl _ _ ⟩ q ≡⟨ sym p≡q ⟩ subst P (refl _) p ≡⟨ subst-refl _ _ ⟩∎ p ∎) x≡y p≡q -- A "computation rule" for dsym. dsym-subst-refl : {P : A → Type p} {p : P x} → dsym (subst-refl P p) ≡ trans (cong (flip (subst P) _) sym-refl) (subst-refl _ _) dsym-subst-refl {P = P} = dsym (subst-refl _ _) ≡⟨ cong (λ f → f (subst-refl _ _)) $ elim-refl (λ {x y} x≡y → ∀ {p : P x} {q : P y} → subst P x≡y p ≡ q → subst P (sym x≡y) q ≡ p) _ ⟩ trans (cong (flip (subst P) _) sym-refl) (trans (subst-refl _ _) (trans (sym (subst-refl P _)) (subst-refl _ _))) ≡⟨ cong (trans (cong (flip (subst P) _) sym-refl)) $ trans--[trans-sym] _ _ ⟩∎ trans (cong (flip (subst P) _) sym-refl) (subst-refl _ _) ∎ -- A kind of transitivity for "dependent paths". -- -- This lemma is suggested in the HoTT book (first edition, -- Exercise 6.1). dtrans : {x≡y : x ≡ y} {y≡z : y ≡ z} (P : A → Type p) {p : P x} {q : P y} {r : P z} → subst P x≡y p ≡ q → subst P y≡z q ≡ r → subst P (trans x≡y y≡z) p ≡ r dtrans {x≡y = x≡y} {y≡z = y≡z} P {p = p} {q = q} {r = r} p≡q q≡r = subst P (trans x≡y y≡z) p ≡⟨ sym $ subst-subst _ _ _ _ ⟩ subst P y≡z (subst P x≡y p) ≡⟨ cong (subst P y≡z) p≡q ⟩ subst P y≡z q ≡⟨ q≡r ⟩∎ r ∎ -- "Computation rules" for dtrans. dtrans-reflˡ : {x≡y : x ≡ y} {y≡z : y ≡ z} {P : A → Type p} {p : P x} {r : P z} {p≡r : subst P y≡z (subst P x≡y p) ≡ r} → dtrans P (refl _) p≡r ≡ trans (sym $ subst-subst _ _ _ _) p≡r dtrans-reflˡ {y≡z = y≡z} {P = P} {p≡r = p≡r} = trans (sym $ subst-subst _ _ _ _) (trans (cong (subst P y≡z) (refl _)) p≡r) ≡⟨ cong (trans (sym $ subst-subst _ _ _ _) ∘ flip trans _) $ cong-refl _ ⟩ trans (sym $ subst-subst _ _ _ _) (trans (refl _) p≡r) ≡⟨ cong (trans (sym $ subst-subst _ _ _ _)) $ trans-reflˡ _ ⟩∎ trans (sym $ subst-subst _ _ _ _) p≡r ∎ dtrans-reflʳ : {x≡y : x ≡ y} {y≡z : y ≡ z} {P : A → Type p} {p : P x} {q : P y} {p≡q : subst P x≡y p ≡ q} → dtrans P p≡q (refl (subst P y≡z q)) ≡ trans (sym $ subst-subst _ _ _ _) (cong (subst P y≡z) p≡q) dtrans-reflʳ {x≡y = x≡y} {y≡z = y≡z} {P = P} {p≡q = p≡q} = trans (sym $ subst-subst _ _ _ _) (trans (cong (subst P y≡z) p≡q) (refl _)) ≡⟨ cong (trans _) $ trans-reflʳ _ ⟩∎ trans (sym $ subst-subst _ _ _ _) (cong (subst P y≡z) p≡q) ∎ dtrans-subst-reflˡ : {x≡y : x ≡ y} {P : A → Type p} {p : P x} {q : P y} {p≡q : subst P x≡y p ≡ q} → dtrans P (subst-refl _ _) p≡q ≡ trans (cong (flip (subst P) _) (trans-reflˡ _)) p≡q dtrans-subst-reflˡ {x≡y = x≡y} {P = P} {p≡q = p≡q} = trans (sym $ subst-subst _ _ _ _) (trans (cong (subst P x≡y) (subst-refl _ _)) p≡q) ≡⟨ cong (λ eq → trans (sym eq) (trans (cong (subst P x≡y) (subst-refl _ _)) _)) $ subst-subst-reflˡ _ ⟩ trans (sym $ trans (cong (subst P _) (subst-refl _ _)) (cong (flip (subst P) _) (sym $ trans-reflˡ _))) (trans (cong (subst P _) (subst-refl _ _)) p≡q) ≡⟨ cong (flip trans _) $ sym-trans _ _ ⟩ trans (trans (sym $ cong (flip (subst P) _) (sym $ trans-reflˡ _)) (sym $ cong (subst P _) (subst-refl _ _))) (trans (cong (subst P _) (subst-refl _ _)) p≡q) ≡⟨ trans-assoc _ _ _ ⟩ trans (sym $ cong (flip (subst P) _) (sym $ trans-reflˡ _)) (trans (sym $ cong (subst P _) (subst-refl _ _)) (trans (cong (subst P _) (subst-refl _ _)) p≡q)) ≡⟨ cong (trans _) $ trans-sym-[trans] _ _ ⟩ trans (sym $ cong (flip (subst P) _) (sym $ trans-reflˡ _)) p≡q ≡⟨ cong (flip trans _ ∘ sym) $ cong-sym _ _ ⟩ trans (sym $ sym $ cong (flip (subst P) _) (trans-reflˡ _)) p≡q ≡⟨ cong (flip trans _) $ sym-sym _ ⟩∎ trans (cong (flip (subst P) _) (trans-reflˡ _)) p≡q ∎ dtrans-subst-reflʳ : {x≡y : x ≡ y} {P : A → Type p} {p : P x} {q : P y} {p≡q : subst P x≡y p ≡ q} → dtrans P p≡q (subst-refl _ _) ≡ trans (cong (flip (subst P) _) (trans-reflʳ _)) p≡q dtrans-subst-reflʳ {x≡y = x≡y} {P = P} {p = p} {p≡q = p≡q} = elim¹ (λ x≡y → ∀ {q} (p≡q : subst P x≡y p ≡ q) → dtrans P p≡q (subst-refl _ _) ≡ trans (cong (flip (subst P) _) (trans-reflʳ _)) p≡q) (λ p≡q → trans (sym $ subst-subst _ _ _ _) (trans (cong (subst P (refl _)) p≡q) (subst-refl _ _)) ≡⟨ cong (λ eq → trans (sym eq) (trans (cong (subst P (refl _)) _) (subst-refl _ _))) $ subst-subst-refl-refl _ ⟩ trans (sym $ cong₂ (flip (subst P)) (subst-refl _ _) $ sym trans-refl-refl) (trans (cong (subst P (refl _)) p≡q) (subst-refl _ _)) ≡⟨⟩ trans (sym $ trans (cong (subst P _) (subst-refl _ _)) (cong (flip (subst P) _) (sym trans-refl-refl))) (trans (cong (subst P (refl _)) p≡q) (subst-refl _ _)) ≡⟨ cong (flip trans _) $ sym-trans _ _ ⟩ trans (trans (sym $ cong (flip (subst P) _) (sym trans-refl-refl)) (sym $ cong (subst P _) (subst-refl _ _))) (trans (cong (subst P (refl _)) p≡q) (subst-refl _ _)) ≡⟨ lemma₁ p≡q ⟩ trans (cong (flip (subst P) _) trans-refl-refl) p≡q ≡⟨ cong (λ eq → trans (cong (flip (subst P) _) eq) _) $ sym $ elim-refl _ _ ⟩∎ trans (cong (flip (subst P) _) (trans-reflʳ _)) p≡q ∎) x≡y p≡q where lemma₂ : cong (subst P (refl _)) (subst-refl P p) ≡ cong id (subst-refl P (subst P (refl _) p)) lemma₂ = cong (subst P (refl _)) (subst-refl P p) ≡⟨ cong-≡id-≡-≡id (subst-refl P) ⟩ subst-refl P (subst P (refl _) p) ≡⟨ cong-id _ ⟩∎ cong id (subst-refl P (subst P (refl _) p)) ∎ lemma₁ : ∀ {q} (p≡q : subst P (refl _) p ≡ q) → trans (trans (sym $ cong (flip (subst P) _) (sym trans-refl-refl)) (sym $ cong (subst P (refl _)) (subst-refl _ _))) (trans (cong (subst P (refl _)) p≡q) (subst-refl _ _)) ≡ trans (cong (flip (subst P) _) trans-refl-refl) p≡q lemma₁ = elim¹ (λ p≡q → trans (trans (sym $ cong (flip (subst P) _) (sym trans-refl-refl)) (sym $ cong (subst P (refl _)) (subst-refl _ _))) (trans (cong (subst P (refl _)) p≡q) (subst-refl _ _)) ≡ trans (cong (flip (subst P) _) trans-refl-refl) p≡q) (trans (trans (sym $ cong (flip (subst P) _) (sym trans-refl-refl)) (sym $ cong (subst P (refl _)) (subst-refl _ _))) (trans (cong (subst P (refl _)) (refl _)) (subst-refl _ _)) ≡⟨ cong (λ eq → trans (trans (sym $ cong (flip (subst P) _) (sym trans-refl-refl)) (sym $ cong (subst P _) (subst-refl _ _))) (trans eq (subst-refl _ _))) $ cong-refl (subst P (refl _)) ⟩ trans (trans (sym $ cong (flip (subst P) _) (sym trans-refl-refl)) (sym $ cong (subst P (refl _)) (subst-refl _ _))) (trans (refl _) (subst-refl _ _)) ≡⟨ cong (trans _) $ trans-reflˡ _ ⟩ trans (trans (sym $ cong (flip (subst P) _) (sym trans-refl-refl)) (sym $ cong (subst P (refl _)) (subst-refl _ _))) (subst-refl _ _) ≡⟨ cong (λ eq → trans (trans (sym $ cong (flip (subst P) _) _) (sym eq)) (subst-refl _ _)) lemma₂ ⟩ trans (trans (sym $ cong (flip (subst P) _) (sym trans-refl-refl)) (sym $ cong id (subst-refl _ _))) (subst-refl _ _) ≡⟨ cong (λ eq → trans (trans (sym $ cong (flip (subst P) _) (sym trans-refl-refl)) (sym eq)) (subst-refl _ _)) $ sym $ cong-id _ ⟩ trans (trans (sym $ cong (flip (subst P) _) (sym trans-refl-refl)) (sym $ subst-refl _ _)) (subst-refl _ _) ≡⟨ trans-[trans-sym]- _ _ ⟩ sym (cong (flip (subst P) _) (sym trans-refl-refl)) ≡⟨ cong sym $ cong-sym _ _ ⟩ sym (sym (cong (flip (subst P) _) trans-refl-refl)) ≡⟨ sym-sym _ ⟩ cong (flip (subst P) _) trans-refl-refl ≡⟨ sym $ trans-reflʳ _ ⟩∎ trans (cong (flip (subst P) _) trans-refl-refl) (refl _) ∎) -- A lemma relating dcong, trans and dtrans. -- -- This lemma is suggested in the HoTT book (first edition, -- Exercise 6.1). dcong-trans : {f : (x : A) → P x} {x≡y : x ≡ y} {y≡z : y ≡ z} → dcong f (trans x≡y y≡z) ≡ dtrans P (dcong f x≡y) (dcong f y≡z) dcong-trans {P = P} {f = f} {x≡y = x≡y} {y≡z = y≡z} = elim₁ (λ x≡y → dcong f (trans x≡y y≡z) ≡ dtrans P (dcong f x≡y) (dcong f y≡z)) (dcong f (trans (refl _) y≡z) ≡⟨ elim₁ (λ {p} eq → dcong f p ≡ trans (cong (flip (subst P) _) eq) (dcong f y≡z)) ( dcong f y≡z ≡⟨ sym $ trans-reflˡ _ ⟩ trans (refl _) (dcong f y≡z) ≡⟨ cong (flip trans _) $ sym $ cong-refl _ ⟩∎ trans (cong (flip (subst P) _) (refl _)) (dcong f y≡z) ∎) (trans-reflˡ _) ⟩ trans (cong (flip (subst P) _) (trans-reflˡ _)) (dcong f y≡z) ≡⟨ sym dtrans-subst-reflˡ ⟩ dtrans P (subst-refl _ _) (dcong f y≡z) ≡⟨ cong (λ eq → dtrans P eq (dcong f y≡z)) $ sym $ dcong-refl f ⟩∎ dtrans P (dcong f (refl _)) (dcong f y≡z) ∎) x≡y -- An equality between pairs can be proved using a pair of -- equalities. Σ-≡,≡→≡ : {B : A → Type b} {p₁ p₂ : Σ A B} → (p : proj₁ p₁ ≡ proj₁ p₂) → subst B p (proj₂ p₁) ≡ proj₂ p₂ → p₁ ≡ p₂ Σ-≡,≡→≡ {B = B} p q = elim (λ {x₁ y₁} (p : x₁ ≡ y₁) → ∀ {x₂ y₂} → subst B p x₂ ≡ y₂ → (x₁ , x₂) ≡ (y₁ , y₂)) (λ z₁ {x₂} {y₂} x₂≡y₂ → cong (_,_ z₁) ( x₂ ≡⟨ sym $ subst-refl _ _ ⟩ subst B (refl z₁) x₂ ≡⟨ x₂≡y₂ ⟩∎ y₂ ∎)) p q -- The uncurried form of Σ-≡,≡→≡ has an inverse, Σ-≡,≡←≡. (For a -- proof, see Bijection.Σ-≡,≡↔≡.) Σ-≡,≡←≡ : {B : A → Type b} {p₁ p₂ : Σ A B} → p₁ ≡ p₂ → ∃ λ (p : proj₁ p₁ ≡ proj₁ p₂) → subst B p (proj₂ p₁) ≡ proj₂ p₂ Σ-≡,≡←≡ {A = A} {B = B} = elim (λ {p₁ p₂ : Σ A B} _ → ∃ λ (p : proj₁ p₁ ≡ proj₁ p₂) → subst B p (proj₂ p₁) ≡ proj₂ p₂) (λ p → refl _ , subst-refl _ _) abstract -- "Evaluation rules" for Σ-≡,≡→≡. Σ-≡,≡→≡-reflˡ : ∀ {B : A → Type b} {y₁ y₂} → (y₁≡y₂ : subst B (refl x) y₁ ≡ y₂) → Σ-≡,≡→≡ (refl x) y₁≡y₂ ≡ cong (x ,_) (trans (sym $ subst-refl _ _) y₁≡y₂) Σ-≡,≡→≡-reflˡ {B = B} y₁≡y₂ = cong (λ f → f y₁≡y₂) $ elim-refl (λ {x₁ y₁} (p : x₁ ≡ y₁) → ∀ {x₂ y₂} → subst B p x₂ ≡ y₂ → (x₁ , x₂) ≡ (y₁ , y₂)) _ Σ-≡,≡→≡-refl-refl : ∀ {B : A → Type b} {y} → Σ-≡,≡→≡ (refl x) (refl (subst B (refl x) y)) ≡ cong (x ,_) (sym (subst-refl _ _)) Σ-≡,≡→≡-refl-refl {x = x} = Σ-≡,≡→≡ (refl x) (refl _) ≡⟨ Σ-≡,≡→≡-reflˡ (refl _) ⟩ cong (x ,_) (trans (sym $ subst-refl _ _) (refl _)) ≡⟨ cong (cong (x ,_)) (trans-reflʳ _) ⟩∎ cong (x ,_) (sym (subst-refl _ _)) ∎ Σ-≡,≡→≡-refl-subst-refl : {B : A → Type b} {p : Σ A B} → Σ-≡,≡→≡ (refl _) (subst-refl _ _) ≡ refl p Σ-≡,≡→≡-refl-subst-refl {B = B} = Σ-≡,≡→≡ (refl _) (subst-refl B _) ≡⟨ Σ-≡,≡→≡-reflˡ _ ⟩ cong (_ ,_) (trans (sym $ subst-refl _ _) (subst-refl _ _)) ≡⟨ cong (cong _) (trans-symˡ _) ⟩ cong (_ ,_) (refl _) ≡⟨ cong-refl _ ⟩∎ refl _ ∎ Σ-≡,≡→≡-refl-subst-const : {p : A × B} → Σ-≡,≡→≡ (refl _) (subst-const _) ≡ refl p Σ-≡,≡→≡-refl-subst-const = Σ-≡,≡→≡ (refl _) (subst-const _) ≡⟨ Σ-≡,≡→≡-reflˡ _ ⟩ cong (_ ,_) (trans (sym $ subst-refl _ _) (subst-const _)) ≡⟨ cong (cong _) subst-refl-subst-const ⟩ cong (_ ,_) (refl _) ≡⟨ cong-refl _ ⟩∎ refl _ ∎ -- "Evaluation rule" for Σ-≡,≡←≡. Σ-≡,≡←≡-refl : {B : A → Type b} {p : Σ A B} → Σ-≡,≡←≡ (refl p) ≡ (refl _ , subst-refl _ _) Σ-≡,≡←≡-refl = elim-refl _ _ -- Proof transformation rules for Σ-≡,≡→≡. proj₁-Σ-≡,≡→≡ : ∀ {B : A → Type b} {y₁ y₂} (x₁≡x₂ : x₁ ≡ x₂) (y₁≡y₂ : subst B x₁≡x₂ y₁ ≡ y₂) → cong proj₁ (Σ-≡,≡→≡ x₁≡x₂ y₁≡y₂) ≡ x₁≡x₂ proj₁-Σ-≡,≡→≡ {B = B} {y₁ = y₁} x₁≡x₂ y₁≡y₂ = elim¹ (λ x₁≡x₂ → ∀ {y₂} (y₁≡y₂ : subst B x₁≡x₂ y₁ ≡ y₂) → cong proj₁ (Σ-≡,≡→≡ x₁≡x₂ y₁≡y₂) ≡ x₁≡x₂) (λ y₁≡y₂ → cong proj₁ (Σ-≡,≡→≡ (refl _) y₁≡y₂) ≡⟨ cong (cong proj₁) $ Σ-≡,≡→≡-reflˡ _ ⟩ cong proj₁ (cong (_,_ _) (trans (sym $ subst-refl _ _) y₁≡y₂)) ≡⟨ cong-∘ _ (_,_ _) _ ⟩ cong (const _) (trans (sym $ subst-refl _ _) y₁≡y₂) ≡⟨ cong-const _ ⟩∎ refl _ ∎) x₁≡x₂ y₁≡y₂ Σ-≡,≡→≡-cong : {B : A → Type b} {p₁ p₂ : Σ A B} {q₁ q₂ : proj₁ p₁ ≡ proj₁ p₂} (q₁≡q₂ : q₁ ≡ q₂) {r₁ : subst B q₁ (proj₂ p₁) ≡ proj₂ p₂} {r₂ : subst B q₂ (proj₂ p₁) ≡ proj₂ p₂} (r₁≡r₂ : (subst B q₂ (proj₂ p₁) ≡⟨ cong (flip (subst B) _) (sym q₁≡q₂) ⟩ subst B q₁ (proj₂ p₁) ≡⟨ r₁ ⟩∎ proj₂ p₂ ∎) ≡ r₂) → Σ-≡,≡→≡ q₁ r₁ ≡ Σ-≡,≡→≡ q₂ r₂ Σ-≡,≡→≡-cong {B = B} = elim (λ {q₁ q₂} q₁≡q₂ → ∀ {r₁ r₂} (r₁≡r₂ : trans (cong (flip (subst B) _) (sym q₁≡q₂)) r₁ ≡ r₂) → Σ-≡,≡→≡ q₁ r₁ ≡ Σ-≡,≡→≡ q₂ r₂) (λ q {r₁ r₂} r₁≡r₂ → cong (Σ-≡,≡→≡ q) ( r₁ ≡⟨ sym $ trans-reflˡ _ ⟩ trans (refl (subst B q _)) r₁ ≡⟨ cong (flip trans _) $ sym $ cong-refl _ ⟩ trans (cong (flip (subst B) _) (refl q)) r₁ ≡⟨ cong (λ e → trans (cong (flip (subst B) _) e) _) $ sym sym-refl ⟩ trans (cong (flip (subst B) _) (sym (refl q))) r₁ ≡⟨ r₁≡r₂ ⟩∎ r₂ ∎)) trans-Σ-≡,≡→≡ : {B : A → Type b} {p₁ p₂ p₃ : Σ A B} → (q₁₂ : proj₁ p₁ ≡ proj₁ p₂) (q₂₃ : proj₁ p₂ ≡ proj₁ p₃) (r₁₂ : subst B q₁₂ (proj₂ p₁) ≡ proj₂ p₂) (r₂₃ : subst B q₂₃ (proj₂ p₂) ≡ proj₂ p₃) → trans (Σ-≡,≡→≡ q₁₂ r₁₂) (Σ-≡,≡→≡ q₂₃ r₂₃) ≡ Σ-≡,≡→≡ (trans q₁₂ q₂₃) (subst B (trans q₁₂ q₂₃) (proj₂ p₁) ≡⟨ sym $ subst-subst _ _ _ _ ⟩ subst B q₂₃ (subst B q₁₂ (proj₂ p₁)) ≡⟨ cong (subst _ _) r₁₂ ⟩ subst B q₂₃ (proj₂ p₂) ≡⟨ r₂₃ ⟩∎ proj₂ p₃ ∎) trans-Σ-≡,≡→≡ {B = B} q₁₂ q₂₃ r₁₂ r₂₃ = elim (λ {p₂₁ p₃₁} q₂₃ → ∀ {p₁₁} (q₁₂ : p₁₁ ≡ p₂₁) {p₁₂ p₂₂} (r₁₂ : subst B q₁₂ p₁₂ ≡ p₂₂) {p₃₂} (r₂₃ : subst B q₂₃ p₂₂ ≡ p₃₂) → trans (Σ-≡,≡→≡ q₁₂ r₁₂) (Σ-≡,≡→≡ q₂₃ r₂₃) ≡ Σ-≡,≡→≡ (trans q₁₂ q₂₃) (trans (sym $ subst-subst _ _ _ _) (trans (cong (subst _ _) r₁₂) r₂₃))) (λ x → elim₁ (λ q₁₂ → ∀ {p₁₂ p₂₂} (r₁₂ : subst B q₁₂ p₁₂ ≡ p₂₂) {p₃₂} (r₂₃ : subst B (refl _) p₂₂ ≡ p₃₂) → trans (Σ-≡,≡→≡ q₁₂ r₁₂) (Σ-≡,≡→≡ (refl _) r₂₃) ≡ Σ-≡,≡→≡ (trans q₁₂ (refl _)) (trans (sym $ subst-subst _ _ _ _) (trans (cong (subst _ _) r₁₂) r₂₃))) (λ {y} → elim¹ (λ {p₂₂} r₁₂ → ∀ {p₃₂} (r₂₃ : subst B (refl _) p₂₂ ≡ p₃₂) → trans (Σ-≡,≡→≡ (refl _) r₁₂) (Σ-≡,≡→≡ (refl _) r₂₃) ≡ Σ-≡,≡→≡ (trans (refl _) (refl _)) (trans (sym $ subst-subst _ _ _ _) (trans (cong (subst _ _) r₁₂) r₂₃))) (elim¹ (λ r₂₃ → trans (Σ-≡,≡→≡ (refl _) (refl _)) (Σ-≡,≡→≡ (refl _) r₂₃) ≡ Σ-≡,≡→≡ (trans (refl _) (refl _)) (trans (sym $ subst-subst _ _ _ _) (trans (cong (subst _ _) (refl _)) r₂₃))) (let lemma₁ = sym (cong (subst B _) (subst-refl _ _)) ≡⟨ sym $ trans-sym-[trans] _ _ ⟩ trans (sym $ cong (flip (subst B) _) trans-refl-refl) (trans (cong (flip (subst B) _) trans-refl-refl) (sym (cong (subst B _) (subst-refl _ _)))) ≡⟨ cong (flip trans _) $ sym $ cong-sym _ _ ⟩∎ trans (cong (flip (subst B) _) (sym trans-refl-refl)) (trans (cong (flip (subst B) _) trans-refl-refl) (sym (cong (subst B _) (subst-refl _ _)))) ∎ lemma₂ = trans (cong (flip (subst B) _) trans-refl-refl) (sym (cong (subst B _) (subst-refl _ _))) ≡⟨ cong (λ e → trans (cong (flip (subst B) _) e) (sym $ cong (subst B _) (subst-refl _ _))) $ sym $ sym-sym _ ⟩ trans (cong (flip (subst B) _) (sym $ sym trans-refl-refl)) (sym (cong (subst B _) (subst-refl _ _))) ≡⟨ cong (flip trans _) $ cong-sym _ _ ⟩ trans (sym (cong (flip (subst B) _) (sym trans-refl-refl))) (sym (cong (subst B _) (subst-refl _ _))) ≡⟨ sym $ sym-trans _ _ ⟩ sym (trans (cong (subst B _) (subst-refl _ _)) (cong (flip (subst B) _) (sym trans-refl-refl))) ≡⟨⟩ sym (cong₂ (flip (subst B)) (subst-refl _ _) (sym trans-refl-refl)) ≡⟨ cong sym $ sym $ subst-subst-refl-refl _ ⟩ sym (subst-subst _ _ _ _) ≡⟨ sym $ trans-reflʳ _ ⟩ trans (sym $ subst-subst _ _ _ _) (refl _) ≡⟨ cong (trans (sym $ subst-subst _ _ _ _)) $ sym trans-refl-refl ⟩ trans (sym $ subst-subst _ _ _ _) (trans (refl _) (refl _)) ≡⟨ cong (λ x → trans (sym $ subst-subst _ _ _ _) (trans x (refl _))) $ sym $ cong-refl _ ⟩∎ trans (sym $ subst-subst _ _ _ _) (trans (cong (subst _ _) (refl _)) (refl _)) ∎ in trans (Σ-≡,≡→≡ (refl _) (refl _)) (Σ-≡,≡→≡ (refl _) (refl _)) ≡⟨ cong₂ trans Σ-≡,≡→≡-refl-refl Σ-≡,≡→≡-refl-refl ⟩ trans (cong (_ ,_) (sym (subst-refl _ _))) (cong (_ ,_) (sym (subst-refl B _))) ≡⟨ sym $ cong-trans _ _ _ ⟩ cong (_ ,_) (trans (sym (subst-refl _ _)) (sym (subst-refl _ _))) ≡⟨ cong (cong (_ ,_) ∘ trans (sym (subst-refl _ _)) ∘ sym) $ sym $ cong-≡id-≡-≡id (subst-refl B) ⟩ cong (_ ,_) (trans (sym (subst-refl _ _)) (sym (cong (subst B _) (subst-refl _ _)))) ≡⟨ sym $ Σ-≡,≡→≡-reflˡ _ ⟩ Σ-≡,≡→≡ (refl _) (sym (cong (subst B _) (subst-refl _ _))) ≡⟨ cong (Σ-≡,≡→≡ _) lemma₁ ⟩ Σ-≡,≡→≡ (refl _) (trans (cong (flip (subst B) _) (sym trans-refl-refl)) (trans (cong (flip (subst B) _) trans-refl-refl) (sym (cong (subst B _) (subst-refl _ _))))) ≡⟨ sym $ Σ-≡,≡→≡-cong _ (refl _) ⟩ Σ-≡,≡→≡ (trans (refl _) (refl _)) (trans (cong (flip (subst B) _) trans-refl-refl) (sym (cong (subst B _) (subst-refl _ _)))) ≡⟨ cong (Σ-≡,≡→≡ (trans (refl _) (refl _))) lemma₂ ⟩∎ Σ-≡,≡→≡ (trans (refl _) (refl _)) (trans (sym $ subst-subst _ _ _ _) (trans (cong (subst _ _) (refl _)) (refl _))) ∎)))) q₂₃ q₁₂ r₁₂ r₂₃ Σ-≡,≡→≡-subst-const : {p₁ p₂ : A × B} → (p : proj₁ p₁ ≡ proj₁ p₂) (q : proj₂ p₁ ≡ proj₂ p₂) → Σ-≡,≡→≡ p (trans (subst-const _) q) ≡ cong₂ _,_ p q Σ-≡,≡→≡-subst-const p q = elim (λ {x₁ y₁} (p : x₁ ≡ y₁) → Σ-≡,≡→≡ p (trans (subst-const _) q) ≡ cong₂ _,_ p q) (λ x → let lemma = trans (sym $ subst-refl _ _) (trans (subst-const _) q) ≡⟨ sym $ trans-assoc _ _ _ ⟩ trans (trans (sym $ subst-refl _ _) (subst-const _)) q ≡⟨ cong₂ trans subst-refl-subst-const (refl _) ⟩ trans (refl _) q ≡⟨ trans-reflˡ _ ⟩∎ q ∎ in Σ-≡,≡→≡ (refl x) (trans (subst-const _) q) ≡⟨ Σ-≡,≡→≡-reflˡ _ ⟩ cong (x ,_) (trans (sym $ subst-refl _ _) (trans (subst-const _) q)) ≡⟨ cong (cong (x ,_)) lemma ⟩ cong (x ,_) q ≡⟨ sym $ cong₂-reflˡ _,_ ⟩∎ cong₂ _,_ (refl x) q ∎) p Σ-≡,≡→≡-subst-const-refl : Σ-≡,≡→≡ x₁≡x₂ (subst-const _) ≡ cong₂ _,_ x₁≡x₂ (refl y) Σ-≡,≡→≡-subst-const-refl {x₁≡x₂ = x₁≡x₂} {y = y} = Σ-≡,≡→≡ x₁≡x₂ (subst-const _) ≡⟨ cong (Σ-≡,≡→≡ x₁≡x₂) $ sym $ trans-reflʳ _ ⟩ Σ-≡,≡→≡ x₁≡x₂ (trans (subst-const _) (refl _)) ≡⟨ Σ-≡,≡→≡-subst-const _ _ ⟩∎ cong₂ _,_ x₁≡x₂ (refl y) ∎ -- Proof simplification rule for Σ-≡,≡←≡. proj₁-Σ-≡,≡←≡ : {B : A → Type b} {p₁ p₂ : Σ A B} (p₁≡p₂ : p₁ ≡ p₂) → proj₁ (Σ-≡,≡←≡ p₁≡p₂) ≡ cong proj₁ p₁≡p₂ proj₁-Σ-≡,≡←≡ = elim (λ p₁≡p₂ → proj₁ (Σ-≡,≡←≡ p₁≡p₂) ≡ cong proj₁ p₁≡p₂) (λ p → proj₁ (Σ-≡,≡←≡ (refl p)) ≡⟨ cong proj₁ $ Σ-≡,≡←≡-refl ⟩ refl (proj₁ p) ≡⟨ sym $ cong-refl _ ⟩∎ cong proj₁ (refl p) ∎) -- A binary variant of subst. subst₂ : ∀ {B : A → Type b} (P : Σ A B → Type p) {x₁ x₂ y₁ y₂} → (x₁≡x₂ : x₁ ≡ x₂) → subst B x₁≡x₂ y₁ ≡ y₂ → P (x₁ , y₁) → P (x₂ , y₂) subst₂ P x₁≡x₂ y₁≡y₂ = subst P (Σ-≡,≡→≡ x₁≡x₂ y₁≡y₂) abstract -- "Evaluation rule" for subst₂. subst₂-refl-refl : ∀ {B : A → Type b} (P : Σ A B → Type p) {y p} → subst₂ P (refl _) (refl _) p ≡ subst (curry P x) (sym $ subst-refl B y) p subst₂-refl-refl {x = x} P {p = p} = subst P (Σ-≡,≡→≡ (refl _) (refl _)) p ≡⟨ cong (λ eq₁ → subst P eq₁ _) Σ-≡,≡→≡-refl-refl ⟩ subst P (cong (x ,_) (sym (subst-refl _ _))) p ≡⟨ sym $ subst-∘ _ _ _ ⟩∎ subst (curry P x) (sym $ subst-refl _ _) p ∎ -- The subst function can be "pushed" inside pairs. push-subst-pair : ∀ (B : A → Type b) (C : Σ A B → Type c) {p} → subst (λ x → Σ (B x) (curry C x)) y≡z p ≡ (subst B y≡z (proj₁ p) , subst₂ C y≡z (refl _) (proj₂ p)) push-subst-pair {y≡z = y≡z} B C {p} = elim¹ (λ y≡z → subst (λ x → Σ (B x) (curry C x)) y≡z p ≡ (subst B y≡z (proj₁ p) , subst₂ C y≡z (refl _) (proj₂ p))) (subst (λ x → Σ (B x) (curry C x)) (refl _) p ≡⟨ subst-refl _ _ ⟩ p ≡⟨ Σ-≡,≡→≡ (sym (subst-refl _ _)) (sym (subst₂-refl-refl _)) ⟩∎ (subst B (refl _) (proj₁ p) , subst₂ C (refl _) (refl _) (proj₂ p)) ∎) y≡z -- A proof transformation rule for push-subst-pair. proj₁-push-subst-pair-refl : ∀ {A : Type a} {y : A} (B : A → Type b) (C : Σ A B → Type c) {p} → cong proj₁ (push-subst-pair {y≡z = refl y} B C {p = p}) ≡ trans (cong proj₁ (subst-refl (λ _ → Σ _ _) _)) (sym $ subst-refl _ _) proj₁-push-subst-pair-refl B C = cong proj₁ (push-subst-pair _ _) ≡⟨ cong (cong proj₁) $ elim¹-refl (λ y≡z → subst (λ x → Σ (B x) (curry C x)) y≡z _ ≡ (subst B y≡z _ , subst₂ C y≡z (refl _) _)) _ ⟩ cong proj₁ (trans (subst-refl (λ _ → Σ _ _) _) (Σ-≡,≡→≡ (sym $ subst-refl B _) (sym (subst₂-refl-refl _)))) ≡⟨ cong-trans _ _ _ ⟩ trans (cong proj₁ (subst-refl _ _)) (cong proj₁ (Σ-≡,≡→≡ (sym $ subst-refl _ _) (sym (subst₂-refl-refl _)))) ≡⟨ cong (trans _) $ proj₁-Σ-≡,≡→≡ _ _ ⟩∎ trans (cong proj₁ (subst-refl _ _)) (sym $ subst-refl _ _) ∎ -- Corollaries of push-subst-pair. push-subst-pair′ : ∀ (B : A → Type b) (C : Σ A B → Type c) {p p₁} → (p₁≡p₁ : subst B y≡z (proj₁ p) ≡ p₁) → subst (λ x → Σ (B x) (curry C x)) y≡z p ≡ (p₁ , subst₂ C y≡z p₁≡p₁ (proj₂ p)) push-subst-pair′ {y≡z = y≡z} B C {p} = elim¹ (λ {p₁} p₁≡p₁ → subst (λ x → Σ (B x) (curry C x)) y≡z p ≡ (p₁ , subst₂ C y≡z p₁≡p₁ (proj₂ p))) (push-subst-pair _ _) push-subst-pair-× : ∀ {y≡z : y ≡ z} (B : Type b) (C : A × B → Type c) {p} → subst (λ x → Σ B (curry C x)) y≡z p ≡ (proj₁ p , subst (λ x → C (x , proj₁ p)) y≡z (proj₂ p)) push-subst-pair-× {y≡z = y≡z} B C {p} = subst (λ x → Σ B (curry C x)) y≡z p ≡⟨ push-subst-pair′ _ C (subst-const _) ⟩ (proj₁ p , subst₂ C y≡z (subst-const _) (proj₂ p)) ≡⟨ cong (_ ,_) $ elim¹ (λ y≡z → subst₂ C y≡z (subst-const y≡z) (proj₂ p) ≡ subst (λ x → C (x , proj₁ p)) y≡z (proj₂ p)) ( subst₂ C (refl _) (subst-const _) (proj₂ p) ≡⟨⟩ subst C (Σ-≡,≡→≡ (refl _) (subst-const _)) (proj₂ p) ≡⟨ cong (λ eq → subst C eq _) Σ-≡,≡→≡-refl-subst-const ⟩ subst C (refl _) (proj₂ p) ≡⟨ subst-refl _ _ ⟩ proj₂ p ≡⟨ sym $ subst-refl _ _ ⟩∎ subst (λ x → C (x , _)) (refl _) (proj₂ p) ∎) y≡z ⟩ (proj₁ p , subst (λ x → C (x , _)) y≡z (proj₂ p)) ∎ -- A proof simplification rule for subst₂. subst₂-proj₁ : ∀ {B : A → Type b} {y₁ y₂} {x₁≡x₂ : x₁ ≡ x₂} {y₁≡y₂ : subst B x₁≡x₂ y₁ ≡ y₂} (P : A → Type p) {p} → subst₂ {B = B} (P ∘ proj₁) x₁≡x₂ y₁≡y₂ p ≡ subst P x₁≡x₂ p subst₂-proj₁ {x₁≡x₂ = x₁≡x₂} {y₁≡y₂} P {p} = subst₂ (P ∘ proj₁) x₁≡x₂ y₁≡y₂ p ≡⟨ subst-∘ _ _ _ ⟩ subst P (cong proj₁ (Σ-≡,≡→≡ x₁≡x₂ y₁≡y₂)) p ≡⟨ cong (λ eq → subst P eq _) (proj₁-Σ-≡,≡→≡ _ _) ⟩∎ subst P x₁≡x₂ p ∎ -- The subst function can be "pushed" inside non-dependent pairs. push-subst-, : ∀ (B : A → Type b) (C : A → Type c) {p} → subst (λ x → B x × C x) y≡z p ≡ (subst B y≡z (proj₁ p) , subst C y≡z (proj₂ p)) push-subst-, {y≡z = y≡z} B C {x , y} = subst (λ x → B x × C x) y≡z (x , y) ≡⟨ push-subst-pair _ _ ⟩ (subst B y≡z x , subst (C ∘ proj₁) (Σ-≡,≡→≡ y≡z (refl _)) y) ≡⟨ cong (_,_ _) $ subst₂-proj₁ _ ⟩∎ (subst B y≡z x , subst C y≡z y) ∎ -- A proof transformation rule for push-subst-,. proj₁-push-subst-,-refl : ∀ {A : Type a} {y : A} (B : A → Type b) (C : A → Type c) {p} → cong proj₁ (push-subst-, {y≡z = refl y} B C {p = p}) ≡ trans (cong proj₁ (subst-refl (λ _ → _ × _) _)) (sym $ subst-refl _ _) proj₁-push-subst-,-refl _ _ = cong proj₁ (trans (push-subst-pair _ _) (cong (_,_ _) $ subst₂-proj₁ _)) ≡⟨ cong-trans _ _ _ ⟩ trans (cong proj₁ (push-subst-pair _ _)) (cong proj₁ (cong (_,_ _) $ subst₂-proj₁ _)) ≡⟨ cong (trans _) $ cong-∘ _ _ _ ⟩ trans (cong proj₁ (push-subst-pair _ _)) (cong (const _) $ subst₂-proj₁ _) ≡⟨ trans (cong (trans _) (cong-const _)) $ trans-reflʳ _ ⟩ cong proj₁ (push-subst-pair _ _) ≡⟨ proj₁-push-subst-pair-refl _ _ ⟩∎ trans (cong proj₁ (subst-refl _ _)) (sym $ subst-refl _ _) ∎ -- The subst function can be "pushed" inside inj₁ and inj₂. push-subst-inj₁ : ∀ (B : A → Type b) (C : A → Type c) {x} → subst (λ x → B x ⊎ C x) y≡z (inj₁ x) ≡ inj₁ (subst B y≡z x) push-subst-inj₁ {y≡z = y≡z} B C {x} = elim¹ (λ y≡z → subst (λ x → B x ⊎ C x) y≡z (inj₁ x) ≡ inj₁ (subst B y≡z x)) (subst (λ x → B x ⊎ C x) (refl _) (inj₁ x) ≡⟨ subst-refl _ _ ⟩ inj₁ x ≡⟨ cong inj₁ $ sym $ subst-refl _ _ ⟩∎ inj₁ (subst B (refl _) x) ∎) y≡z push-subst-inj₂ : ∀ (B : A → Type b) (C : A → Type c) {x} → subst (λ x → B x ⊎ C x) y≡z (inj₂ x) ≡ inj₂ (subst C y≡z x) push-subst-inj₂ {y≡z = y≡z} B C {x} = elim¹ (λ y≡z → subst (λ x → B x ⊎ C x) y≡z (inj₂ x) ≡ inj₂ (subst C y≡z x)) (subst (λ x → B x ⊎ C x) (refl _) (inj₂ x) ≡⟨ subst-refl _ _ ⟩ inj₂ x ≡⟨ cong inj₂ $ sym $ subst-refl _ _ ⟩∎ inj₂ (subst C (refl _) x) ∎) y≡z -- The subst function can be "pushed" inside applications. push-subst-application : {B : A → Type b} (x₁≡x₂ : x₁ ≡ x₂) (C : (x : A) → B x → Type c) {f : (x : A) → B x} {g : (y : B x₁) → C x₁ y} → subst (λ x → C x (f x)) x₁≡x₂ (g (f x₁)) ≡ subst (λ x → (y : B x) → C x y) x₁≡x₂ g (f x₂) push-subst-application {x₁ = x₁} x₁≡x₂ C {f} {g} = elim¹ (λ {x₂} x₁≡x₂ → subst (λ x → C x (f x)) x₁≡x₂ (g (f x₁)) ≡ subst (λ x → ∀ y → C x y) x₁≡x₂ g (f x₂)) (subst (λ x → C x (f x)) (refl _) (g (f x₁)) ≡⟨ subst-refl _ _ ⟩ g (f x₁) ≡⟨ cong (_$ f x₁) $ sym $ subst-refl (λ x → ∀ y → C x y) _ ⟩∎ subst (λ x → ∀ y → C x y) (refl _) g (f x₁) ∎) x₁≡x₂ push-subst-implicit-application : {B : A → Type b} (x₁≡x₂ : x₁ ≡ x₂) (C : (x : A) → B x → Type c) {f : (x : A) → B x} {g : {y : B x₁} → C x₁ y} → subst (λ x → C x (f x)) x₁≡x₂ (g {y = f x₁}) ≡ subst (λ x → {y : B x} → C x y) x₁≡x₂ g {y = f x₂} push-subst-implicit-application {x₁ = x₁} x₁≡x₂ C {f} {g} = elim¹ (λ {x₂} x₁≡x₂ → subst (λ x → C x (f x)) x₁≡x₂ (g {y = f x₁}) ≡ subst (λ x → ∀ {y} → C x y) x₁≡x₂ g {y = f x₂}) (subst (λ x → C x (f x)) (refl _) (g {y = f x₁}) ≡⟨ subst-refl _ _ ⟩ g {y = f x₁} ≡⟨ cong (λ g → g {y = f x₁}) $ sym $ subst-refl (λ x → ∀ {y} → C x y) _ ⟩∎ subst (λ x → ∀ {y} → C x y) (refl _) g {y = f x₁} ∎) x₁≡x₂ subst-∀-sym : ∀ {B : A → Type b} {y : B x₁} {C : (x : A) → B x → Type c} {f : (y : B x₂) → C x₂ y} {x₁≡x₂ : x₁ ≡ x₂} → subst (λ x → (y : B x) → C x y) (sym x₁≡x₂) f y ≡ subst (uncurry C) (sym $ Σ-≡,≡→≡ x₁≡x₂ (refl _)) (f (subst B x₁≡x₂ y)) subst-∀-sym {B = B} {C = C} {x₁≡x₂ = x₁≡x₂} = elim (λ {x₁ x₂} x₁≡x₂ → {y : B x₁} (f : (y : B x₂) → C x₂ y) → subst (λ x → (y : B x) → C x y) (sym x₁≡x₂) f y ≡ subst (uncurry C) (sym $ Σ-≡,≡→≡ x₁≡x₂ (refl _)) (f (subst B x₁≡x₂ y))) (λ x {y} f → let lemma = cong (x ,_) (subst-refl B y) ≡⟨ cong (cong (x ,_)) $ sym $ sym-sym _ ⟩ cong (x ,_) (sym $ sym $ subst-refl B y) ≡⟨ cong-sym _ _ ⟩ sym $ cong (x ,_) (sym $ subst-refl B y) ≡⟨ cong sym $ sym Σ-≡,≡→≡-refl-refl ⟩∎ sym $ Σ-≡,≡→≡ (refl x) (refl _) ∎ in subst (λ x → (y : B x) → C x y) (sym (refl x)) f y ≡⟨ cong (λ eq → subst (λ x → (y : B x) → C x y) eq _ _) sym-refl ⟩ subst (λ x → (y : B x) → C x y) (refl x) f y ≡⟨ cong (_$ y) $ subst-refl (λ x → (_ : B x) → _) _ ⟩ f y ≡⟨ sym $ dcong f _ ⟩ subst (C x) (subst-refl B _) (f (subst B (refl x) y)) ≡⟨ subst-∘ _ _ _ ⟩ subst (uncurry C) (cong (x ,_) (subst-refl B y)) (f (subst B (refl x) y)) ≡⟨ cong (λ eq → subst (uncurry C) eq (f (subst B (refl x) y))) lemma ⟩∎ subst (uncurry C) (sym $ Σ-≡,≡→≡ (refl x) (refl _)) (f (subst B (refl x) y)) ∎) x₁≡x₂ _ subst-∀ : ∀ {B : A → Type b} {y : B x₂} {C : (x : A) → B x → Type c} {f : (y : B x₁) → C x₁ y} {x₁≡x₂ : x₁ ≡ x₂} → subst (λ x → (y : B x) → C x y) x₁≡x₂ f y ≡ subst (uncurry C) (sym $ Σ-≡,≡→≡ (sym x₁≡x₂) (refl _)) (f (subst B (sym x₁≡x₂) y)) subst-∀ {B = B} {y = y} {C = C} {f = f} {x₁≡x₂ = x₁≡x₂} = subst (λ x → (y : B x) → C x y) x₁≡x₂ f y ≡⟨ cong (λ eq → subst (λ x → (y : B x) → C x y) eq _ _) $ sym $ sym-sym _ ⟩ subst (λ x → (y : B x) → C x y) (sym (sym x₁≡x₂)) f y ≡⟨ subst-∀-sym ⟩∎ subst (uncurry C) (sym $ Σ-≡,≡→≡ (sym x₁≡x₂) (refl _)) (f (subst B (sym x₁≡x₂) y)) ∎ subst-→ : {B : A → Type b} {y : B x₂} {C : A → Type c} {f : B x₁ → C x₁} → subst (λ x → B x → C x) x₁≡x₂ f y ≡ subst C x₁≡x₂ (f (subst B (sym x₁≡x₂) y)) subst-→ {x₁≡x₂ = x₁≡x₂} {B = B} {y = y} {C} {f} = subst (λ x → B x → C x) x₁≡x₂ f y ≡⟨ cong (λ eq → subst (λ x → B x → C x) eq f y) $ sym $ sym-sym _ ⟩ subst (λ x → B x → C x) (sym $ sym x₁≡x₂) f y ≡⟨ subst-∀-sym ⟩ subst (C ∘ proj₁) (sym $ Σ-≡,≡→≡ (sym x₁≡x₂) (refl _)) (f (subst B (sym x₁≡x₂) y)) ≡⟨ subst-∘ _ _ _ ⟩ subst C (cong proj₁ $ sym $ Σ-≡,≡→≡ (sym x₁≡x₂) (refl _)) (f (subst B (sym x₁≡x₂) y)) ≡⟨ cong (λ eq → subst C eq (f (subst B (sym x₁≡x₂) y))) $ cong-sym _ _ ⟩ subst C (sym $ cong proj₁ $ Σ-≡,≡→≡ (sym x₁≡x₂) (refl _)) (f (subst B (sym x₁≡x₂) y)) ≡⟨ cong (λ eq → subst C (sym eq) (f (subst B (sym x₁≡x₂) y))) $ proj₁-Σ-≡,≡→≡ _ _ ⟩ subst C (sym $ sym x₁≡x₂) (f (subst B (sym x₁≡x₂) y)) ≡⟨ cong (λ eq → subst C eq (f (subst B (sym x₁≡x₂) y))) $ sym-sym _ ⟩∎ subst C x₁≡x₂ (f (subst B (sym x₁≡x₂) y)) ∎ subst-→-domain : (B : A → Type b) {f : B x → C} (x≡y : x ≡ y) {u : B y} → subst (λ x → B x → C) x≡y f u ≡ f (subst B (sym x≡y) u) subst-→-domain {C = C} B x≡y {u = u} = elim₁ (λ {x} x≡y → (f : B x → C) → subst (λ x → B x → C) x≡y f u ≡ f (subst B (sym x≡y) u)) (λ f → subst (λ x → B x → C) (refl _) f u ≡⟨ cong (_$ u) $ subst-refl (λ x → B x → _) _ ⟩ f u ≡⟨ cong f $ sym $ subst-refl _ _ ⟩ f (subst B (refl _) u) ≡⟨ cong (λ p → f (subst B p u)) $ sym sym-refl ⟩∎ f (subst B (sym (refl _)) u) ∎) x≡y _ -- A "computation rule". subst-→-domain-refl : {B : A → Type b} {f : B x → C} {u : B x} → subst-→-domain B {f = f} (refl x) {u = u} ≡ trans (cong (_$ u) (subst-refl (λ x → B x → _) _)) (trans (cong f (sym (subst-refl _ _))) (cong (f ∘ flip (subst B) u) (sym sym-refl))) subst-→-domain-refl {C = C} {B = B} {u = u} = cong (_$ _) $ elim₁-refl (λ {x} x≡y → (f : B x → C) → subst (λ x → B x → C) x≡y f u ≡ f (subst B (sym x≡y) u)) _ -- The following lemma is Proposition 2 from "Generalizations of -- Hedberg's Theorem" by Kraus, Escardó, Coquand and Altenkirch. subst-in-terms-of-trans-and-cong : {x≡y : x ≡ y} {fx≡gx : f x ≡ g x} → subst (λ z → f z ≡ g z) x≡y fx≡gx ≡ trans (sym (cong f x≡y)) (trans fx≡gx (cong g x≡y)) subst-in-terms-of-trans-and-cong {f = f} {g = g} = elim (λ {x y} x≡y → (fx≡gx : f x ≡ g x) → subst (λ z → f z ≡ g z) x≡y fx≡gx ≡ trans (sym (cong f x≡y)) (trans fx≡gx (cong g x≡y))) (λ x fx≡gx → subst (λ z → f z ≡ g z) (refl x) fx≡gx ≡⟨ subst-refl _ _ ⟩ fx≡gx ≡⟨ sym $ trans-reflˡ _ ⟩ trans (refl (f x)) fx≡gx ≡⟨ sym $ cong₂ trans sym-refl (trans-reflʳ _) ⟩ trans (sym (refl (f x))) (trans fx≡gx (refl (g x))) ≡⟨ sym $ cong₂ (λ p q → trans (sym p) (trans _ q)) (cong-refl _) (cong-refl _) ⟩∎ trans (sym (cong f (refl x))) (trans fx≡gx (cong g (refl x))) ∎ ) _ _ -- A variant of subst-in-terms-of-trans-and-cong that works for -- dependent functions. subst-in-terms-of-trans-and-dcong : {f g : (x : A) → P x} {x≡y : x ≡ y} {fx≡gx : f x ≡ g x} → subst (λ z → f z ≡ g z) x≡y fx≡gx ≡ trans (sym (dcong f x≡y)) (trans (cong (subst P x≡y) fx≡gx) (dcong g x≡y)) subst-in-terms-of-trans-and-dcong {P = P} {f = f} {g = g} = elim (λ {x y} x≡y → (fx≡gx : f x ≡ g x) → subst (λ z → f z ≡ g z) x≡y fx≡gx ≡ trans (sym (dcong f x≡y)) (trans (cong (subst P x≡y) fx≡gx) (dcong g x≡y))) (λ x fx≡gx → subst (λ z → f z ≡ g z) (refl x) fx≡gx ≡⟨ subst-refl _ _ ⟩ fx≡gx ≡⟨ elim¹ (λ {gx} eq → eq ≡ trans (sym (subst-refl P (f x))) (trans (cong (subst P (refl x)) eq) (subst-refl P gx))) ( refl (f x) ≡⟨ sym $ trans-symˡ _ ⟩ trans (sym (subst-refl P (f x))) (subst-refl P (f x)) ≡⟨ cong (trans _) $ trans (sym $ trans-reflˡ _) $ cong (flip trans _) $ sym $ cong-refl _ ⟩∎ trans (sym (subst-refl P (f x))) (trans (cong (subst P (refl x)) (refl (f x))) (subst-refl P (f x))) ∎) fx≡gx ⟩ trans (sym (subst-refl P (f x))) (trans (cong (subst P (refl x)) fx≡gx) (subst-refl P (g x))) ≡⟨ sym $ cong₂ (λ p q → trans (sym p) (trans (cong (subst P (refl x)) fx≡gx) q)) (dcong-refl _) (dcong-refl _) ⟩∎ trans (sym (dcong f (refl x))) (trans (cong (subst P (refl x)) fx≡gx) (dcong g (refl x))) ∎) _ _ -- Sometimes cong can be "pushed" inside subst. The following -- lemma provides one example. cong-subst : {B : A → Type b} {C : A → Type c} {f : ∀ {x} → B x → C x} {g h : (x : A) → B x} (eq₁ : x ≡ y) (eq₂ : g x ≡ h x) → cong f (subst (λ x → g x ≡ h x) eq₁ eq₂) ≡ subst (λ x → f (g x) ≡ f (h x)) eq₁ (cong f eq₂) cong-subst {f = f} {g} {h} = elim₁ (λ eq₁ → ∀ eq₂ → cong f (subst (λ x → g x ≡ h x) eq₁ eq₂) ≡ subst (λ x → f (g x) ≡ f (h x)) eq₁ (cong f eq₂)) (λ eq₂ → cong f (subst (λ x → g x ≡ h x) (refl _) eq₂) ≡⟨ cong (cong f) $ subst-refl _ _ ⟩ cong f eq₂ ≡⟨ sym $ subst-refl _ _ ⟩∎ subst (λ x → f (g x) ≡ f (h x)) (refl _) (cong f eq₂) ∎) -- Some rearrangement lemmas for equalities between equalities. [trans≡]≡[≡trans-symʳ] : (p₁₂ : a₁ ≡ a₂) (p₁₃ : a₁ ≡ a₃) (p₂₃ : a₂ ≡ a₃) → (trans p₁₂ p₂₃ ≡ p₁₃) ≡ (p₁₂ ≡ trans p₁₃ (sym p₂₃)) [trans≡]≡[≡trans-symʳ] p₁₂ p₁₃ p₂₃ = elim (λ {a₂ a₃} p₂₃ → ∀ {a₁} (p₁₂ : a₁ ≡ a₂) (p₁₃ : a₁ ≡ a₃) → (trans p₁₂ p₂₃ ≡ p₁₃) ≡ (p₁₂ ≡ trans p₁₃ (sym p₂₃))) (λ a₂₃ p₁₂ p₁₃ → trans p₁₂ (refl a₂₃) ≡ p₁₃ ≡⟨ cong₂ _≡_ (trans-reflʳ _) (sym $ trans-reflʳ _) ⟩ p₁₂ ≡ trans p₁₃ (refl a₂₃) ≡⟨ cong ((_ ≡_) ∘ trans _) (sym sym-refl) ⟩∎ p₁₂ ≡ trans p₁₃ (sym (refl a₂₃)) ∎) p₂₃ p₁₂ p₁₃ [trans≡]≡[≡trans-symˡ] : (p₁₂ : a₁ ≡ a₂) (p₁₃ : a₁ ≡ a₃) (p₂₃ : a₂ ≡ a₃) → (trans p₁₂ p₂₃ ≡ p₁₃) ≡ (p₂₃ ≡ trans (sym p₁₂) p₁₃) [trans≡]≡[≡trans-symˡ] p₁₂ = elim (λ {a₁ a₂} p₁₂ → ∀ {a₃} (p₁₃ : a₁ ≡ a₃) (p₂₃ : a₂ ≡ a₃) → (trans p₁₂ p₂₃ ≡ p₁₃) ≡ (p₂₃ ≡ trans (sym p₁₂) p₁₃)) (λ a₁₂ p₁₃ p₂₃ → trans (refl a₁₂) p₂₃ ≡ p₁₃ ≡⟨ cong₂ _≡_ (trans-reflˡ _) (sym $ trans-reflˡ _) ⟩ p₂₃ ≡ trans (refl a₁₂) p₁₃ ≡⟨ cong ((_ ≡_) ∘ flip trans _) (sym sym-refl) ⟩∎ p₂₃ ≡ trans (sym (refl a₁₂)) p₁₃ ∎) p₁₂ -- The following lemma is basically Theorem 2.11.5 from the HoTT -- book (the book's lemma gives an equivalence between equality -- types, rather than an equality between equality types). [subst≡]≡[trans≡trans] : {p : x ≡ y} {q : x ≡ x} {r : y ≡ y} → (subst (λ z → z ≡ z) p q ≡ r) ≡ (trans q p ≡ trans p r) [subst≡]≡[trans≡trans] {p = p} {q} {r} = elim (λ {x y} p → {q : x ≡ x} {r : y ≡ y} → (subst (λ z → z ≡ z) p q ≡ r) ≡ (trans q p ≡ trans p r)) (λ x {q r} → subst (λ z → z ≡ z) (refl x) q ≡ r ≡⟨ cong (_≡ _) (subst-refl _ _) ⟩ q ≡ r ≡⟨ sym $ cong₂ _≡_ (trans-reflʳ _) (trans-reflˡ _) ⟩∎ trans q (refl x) ≡ trans (refl x) r ∎) p -- "Evaluation rule" for [subst≡]≡[trans≡trans]. [subst≡]≡[trans≡trans]-refl : {q r : x ≡ x} → [subst≡]≡[trans≡trans] {p = refl x} ≡ trans (cong (_≡ r) (subst-refl (λ z → z ≡ z) q)) (sym $ cong₂ _≡_ (trans-reflʳ q) (trans-reflˡ r)) [subst≡]≡[trans≡trans]-refl {q = q} {r = r} = cong (λ f → f {q = q} {r = r}) $ elim-refl (λ {x y} p → {q : x ≡ x} {r : y ≡ y} → _ ≡ (trans _ p ≡ _)) _ -- The proof trans is commutative when one of the arguments is f x for -- a function f : (x : A) → x ≡ x. trans-sometimes-commutative : {p : x ≡ x} (f : (x : A) → x ≡ x) → trans (f x) p ≡ trans p (f x) trans-sometimes-commutative {x = x} {p = p} f = let lemma = subst (λ z → z ≡ z) p (f x) ≡⟨ dcong f p ⟩∎ f x ∎ in trans (f x) p ≡⟨ subst id [subst≡]≡[trans≡trans] lemma ⟩∎ trans p (f x) ∎ -- Sometimes one can turn two ("modified") copies of a proof into -- one. trans-cong-cong : (f : A → A → B) (p : x ≡ y) → trans (cong (λ z → f z x) p) (cong (λ z → f y z) p) ≡ cong (λ z → f z z) p trans-cong-cong f = elim (λ {x y} p → trans (cong (λ z → f z x) p) (cong (λ z → f y z) p) ≡ cong (λ z → f z z) p) (λ x → trans (cong (λ z → f z x) (refl x)) (cong (λ z → f x z) (refl x)) ≡⟨ cong₂ trans (cong-refl _) (cong-refl _) ⟩ trans (refl (f x x)) (refl (f x x)) ≡⟨ trans-refl-refl ⟩ refl (f x x) ≡⟨ sym $ cong-refl _ ⟩∎ cong (λ z → f z z) (refl x) ∎) -- If f and g agree on a decidable subset of their common domain, then -- cong f eq is equal to (modulo some uses of transitivity) cong g eq -- for proofs eq between elements in this subset. cong-respects-relevant-equality : {f g : A → B} (p : A → Bool) (f≡g : ∀ x → T (p x) → f x ≡ g x) {px : T (p x)} {py : T (p y)} → trans (cong f x≡y) (f≡g y py) ≡ trans (f≡g x px) (cong g x≡y) cong-respects-relevant-equality {f = f} {g} p f≡g = elim (λ {x y} x≡y → {px : T (p x)} {py : T (p y)} → trans (cong f x≡y) (f≡g y py) ≡ trans (f≡g x px) (cong g x≡y)) (λ x {px px′} → trans (cong f (refl x)) (f≡g x px′) ≡⟨ cong (flip trans _) (cong-refl _) ⟩ trans (refl (f x)) (f≡g x px′) ≡⟨ trans-reflˡ _ ⟩ f≡g x px′ ≡⟨ cong (f≡g x) (T-irr (p x) px′ px) ⟩ f≡g x px ≡⟨ sym $ trans-reflʳ _ ⟩ trans (f≡g x px) (refl (g x)) ≡⟨ cong (trans _) (sym $ cong-refl _) ⟩∎ trans (f≡g x px) (cong g (refl x)) ∎) _ where T-irr : (b : Bool) → Is-proposition (T b) T-irr true _ _ = refl _ T-irr false () -- A special case of cong-respects-relevant-equality. -- -- The statement of this lemma is very similar to that of -- Lemma 2.4.3 from the HoTT book. naturality : {x≡y : x ≡ y} (f≡g : ∀ x → f x ≡ g x) → trans (cong f x≡y) (f≡g y) ≡ trans (f≡g x) (cong g x≡y) naturality f≡g = cong-respects-relevant-equality (λ _ → true) (λ x _ → f≡g x) -- If f z evaluates to z for a decidable set of values which -- includes x and y, do we have -- -- cong f x≡y ≡ x≡y -- -- for any x≡y : x ≡ y? The equation above is not well-typed if f -- is a variable, but the approximation below can be proved. cong-roughly-id : (f : A → A) (p : A → Bool) (x≡y : x ≡ y) (px : T (p x)) (py : T (p y)) (f≡id : ∀ z → T (p z) → f z ≡ z) → cong f x≡y ≡ trans (f≡id x px) (trans x≡y $ sym (f≡id y py)) cong-roughly-id {x = x} {y = y} f p x≡y px py f≡id = let lemma = trans (cong id x≡y) (sym (f≡id y py)) ≡⟨ cong-respects-relevant-equality p (λ x → sym ∘ f≡id x) ⟩∎ trans (sym (f≡id x px)) (cong f x≡y) ∎ in cong f x≡y ≡⟨ sym $ subst (λ eq → eq → trans (f≡id x px) (trans (cong id x≡y) (sym (f≡id y py))) ≡ cong f x≡y) ([trans≡]≡[≡trans-symˡ] _ _ _) id lemma ⟩ trans (f≡id x px) (trans (cong id x≡y) $ sym (f≡id y py)) ≡⟨ cong (λ eq → trans _ (trans eq _)) (sym $ cong-id _) ⟩∎ trans (f≡id x px) (trans x≡y $ sym (f≡id y py)) ∎
{ "alphanum_fraction": 0.4084751184, "avg_line_length": 42.2857766143, "ext": "agda", "hexsha": "8ab1a4008940c0a58c8a82c77997531e6a727f75", "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/Equality.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/Equality.agda", "max_line_length": 144, "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/Equality.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": 37616, "size": 96919 }
{-# OPTIONS -v tc.conv.irr:50 #-} -- {-# OPTIONS -v tc.lhs.unify:50 #-} module IndexInference where data Nat : Set where zero : Nat suc : Nat -> Nat data Vec (A : Set) : Nat -> Set where [] : Vec A zero _::_ : {n : Nat} -> A -> Vec A n -> Vec A (suc n) infixr 40 _::_ -- The length of the vector can be inferred from the pattern. foo : Vec Nat _ -> Nat foo (a :: b :: c :: []) = c -- Andreas, 2012-09-13 an example with irrelevant components in index pred : Nat → Nat pred (zero ) = zero pred (suc n) = n data ⊥ : Set where record ⊤ : Set where NonZero : Nat → Set NonZero zero = ⊥ NonZero (suc n) = ⊤ data Fin (n : Nat) : Set where zero : .(NonZero n) → Fin n suc : .(NonZero n) → Fin (pred n) → Fin n data SubVec (A : Set)(n : Nat) : Fin n → Set where [] : .{p : NonZero n} → SubVec A n (zero p) _::_ : .{p : NonZero n}{k : Fin (pred n)} → A → SubVec A (pred n) k → SubVec A n (suc p k) -- The length of the vector can be inferred from the pattern. bar : {A : Set} → SubVec A (suc (suc (suc zero))) _ → A bar (a :: []) = a
{ "alphanum_fraction": 0.5721017908, "avg_line_length": 24.6744186047, "ext": "agda", "hexsha": "8f73deee95dee0a162c59845fe34cea6750c0770", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/succeed/IndexInference.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/IndexInference.agda", "max_line_length": 92, "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/Succeed/IndexInference.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": 387, "size": 1061 }
{-# OPTIONS --safe #-} module Definition.Typed.Properties where open import Definition.Untyped open import Definition.Untyped.Properties open import Definition.Typed open import Definition.Typed.RedSteps import Definition.Typed.Weakening as Twk open import Tools.Empty using (⊥; ⊥-elim) open import Tools.Product open import Tools.Sum hiding (id ; sym) import Tools.PropositionalEquality as PE import Data.Fin as Fin import Data.Nat as Nat -- Escape context extraction wfTerm : ∀ {Γ A t r} → Γ ⊢ t ∷ A ^ r → ⊢ Γ wfTerm (univ <l ⊢Γ) = ⊢Γ wfTerm (ℕⱼ ⊢Γ) = ⊢Γ wfTerm (Emptyⱼ ⊢Γ) = ⊢Γ wfTerm (Πⱼ <l ▹ <l' ▹ F ▹ G) = wfTerm F wfTerm (∃ⱼ F ▹ G) = wfTerm F wfTerm (var ⊢Γ x₁) = ⊢Γ wfTerm (lamⱼ _ _ F t) with wfTerm t wfTerm (lamⱼ _ _ F t) | ⊢Γ ∙ F′ = ⊢Γ wfTerm (g ∘ⱼ a) = wfTerm a wfTerm (⦅ F , G , t , u ⦆ⱼ) = wfTerm t wfTerm (fstⱼ A B t) = wfTerm t wfTerm (sndⱼ A B t) = wfTerm t wfTerm (zeroⱼ ⊢Γ) = ⊢Γ wfTerm (sucⱼ n) = wfTerm n wfTerm (natrecⱼ F z s n) = wfTerm z wfTerm (Emptyrecⱼ A e) = wfTerm e wfTerm (Idⱼ A t u) = wfTerm t wfTerm (Idreflⱼ t) = wfTerm t wfTerm (transpⱼ A P t s u e) = wfTerm t wfTerm (castⱼ A B e t) = wfTerm t wfTerm (castreflⱼ A t) = wfTerm t wfTerm (conv t A≡B) = wfTerm t wf : ∀ {Γ A r} → Γ ⊢ A ^ r → ⊢ Γ wf (Uⱼ ⊢Γ) = ⊢Γ wf (univ A) = wfTerm A mutual wfEqTerm : ∀ {Γ A t u r} → Γ ⊢ t ≡ u ∷ A ^ r → ⊢ Γ wfEqTerm (refl t) = wfTerm t wfEqTerm (sym t≡u) = wfEqTerm t≡u wfEqTerm (trans t≡u u≡r) = wfEqTerm t≡u wfEqTerm (conv t≡u A≡B) = wfEqTerm t≡u wfEqTerm (Π-cong _ _ F F≡H G≡E) = wfEqTerm F≡H wfEqTerm (∃-cong F F≡H G≡E) = wfEqTerm F≡H wfEqTerm (app-cong f≡g a≡b) = wfEqTerm f≡g wfEqTerm (β-red _ _ F t a) = wfTerm a wfEqTerm (η-eq _ _ F f g f0≡g0) = wfTerm f wfEqTerm (suc-cong n) = wfEqTerm n wfEqTerm (natrec-cong F≡F′ z≡z′ s≡s′ n≡n′) = wfEqTerm z≡z′ wfEqTerm (natrec-zero F z s) = wfTerm z wfEqTerm (natrec-suc n F z s) = wfTerm n wfEqTerm (Emptyrec-cong A≡A' _ _) = wfEq A≡A' wfEqTerm (proof-irrelevance t u) = wfTerm t wfEqTerm (Id-cong A t u) = wfEqTerm u wfEqTerm (Id-Π _ _ A B t u) = wfTerm t wfEqTerm (Id-ℕ-00 ⊢Γ) = ⊢Γ wfEqTerm (Id-ℕ-SS m n) = wfTerm n wfEqTerm (Id-U-ΠΠ A B A' B') = wfTerm A wfEqTerm (Id-U-ℕℕ ⊢Γ) = ⊢Γ wfEqTerm (Id-SProp A B) = wfTerm A wfEqTerm (Id-ℕ-0S n) = wfTerm n wfEqTerm (Id-ℕ-S0 n) = wfTerm n wfEqTerm (Id-U-ℕΠ A B) = wfTerm A wfEqTerm (Id-U-Πℕ A B) = wfTerm A wfEqTerm (Id-U-ΠΠ!% eq A B A' B') = wfTerm A wfEqTerm (cast-cong A B t _ _) = wfEqTerm t wfEqTerm (cast-Π A B A' B' e f) = wfTerm f wfEqTerm (cast-ℕ-0 e) = wfTerm e wfEqTerm (cast-ℕ-S e n) = wfTerm n wfEq : ∀ {Γ A B r} → Γ ⊢ A ≡ B ^ r → ⊢ Γ wfEq (univ A≡B) = wfEqTerm A≡B wfEq (refl A) = wf A wfEq (sym A≡B) = wfEq A≡B wfEq (trans A≡B B≡C) = wfEq A≡B -- Reduction is a subset of conversion subsetTerm : ∀ {Γ A t u l} → Γ ⊢ t ⇒ u ∷ A ^ l → Γ ⊢ t ≡ u ∷ A ^ [ ! , l ] subset : ∀ {Γ A B r} → Γ ⊢ A ⇒ B ^ r → Γ ⊢ A ≡ B ^ r subsetTerm (natrec-subst F z s n⇒n′) = natrec-cong (refl F) (refl z) (refl s) (subsetTerm n⇒n′) subsetTerm (natrec-zero F z s) = natrec-zero F z s subsetTerm (natrec-suc n F z s) = natrec-suc n F z s subsetTerm (app-subst {rA = !} t⇒u a) = app-cong (subsetTerm t⇒u) (refl a) subsetTerm (app-subst {rA = %} t⇒u a) = app-cong (subsetTerm t⇒u) (proof-irrelevance a a) subsetTerm (β-red l< l<' A t a) = β-red l< l<' A t a subsetTerm (conv t⇒u A≡B) = conv (subsetTerm t⇒u) A≡B subsetTerm (Id-subst A t u) = Id-cong (subsetTerm A) (refl t) (refl u) subsetTerm (Id-ℕ-subst m n) = Id-cong (refl (ℕⱼ (wfTerm n))) (subsetTerm m) (refl n) subsetTerm (Id-ℕ-0-subst n) = let ⊢Γ = wfEqTerm (subsetTerm n) in Id-cong (refl (ℕⱼ ⊢Γ)) (refl (zeroⱼ ⊢Γ)) (subsetTerm n) subsetTerm (Id-ℕ-S-subst m n) = Id-cong (refl (ℕⱼ (wfTerm m))) (refl (sucⱼ m)) (subsetTerm n) subsetTerm (Id-U-subst A B) = Id-cong (refl (univ 0<1 (wfTerm B))) (subsetTerm A) (refl B) subsetTerm (Id-U-ℕ-subst B) = let ⊢Γ = wfEqTerm (subsetTerm B) in Id-cong (refl (univ 0<1 ⊢Γ)) (refl (ℕⱼ ⊢Γ)) (subsetTerm B) subsetTerm (Id-U-Π-subst A P B) = Id-cong (refl (univ 0<1 (wfTerm A))) (refl (Πⱼ (≡is≤ PE.refl) ▹ (≡is≤ PE.refl) ▹ A ▹ P)) (subsetTerm B) subsetTerm (Id-Π <l <l' A B t u) = Id-Π <l <l' A B t u subsetTerm (Id-ℕ-00 ⊢Γ) = Id-ℕ-00 ⊢Γ subsetTerm (Id-ℕ-SS m n) = Id-ℕ-SS m n subsetTerm (Id-U-ΠΠ A B A' B') = Id-U-ΠΠ A B A' B' subsetTerm (Id-U-ℕℕ ⊢Γ) = Id-U-ℕℕ ⊢Γ subsetTerm (Id-SProp A B) = Id-SProp A B subsetTerm (Id-ℕ-0S n) = Id-ℕ-0S n subsetTerm (Id-ℕ-S0 n) = Id-ℕ-S0 n subsetTerm (Id-U-ℕΠ A B) = Id-U-ℕΠ A B subsetTerm (Id-U-Πℕ A B) = Id-U-Πℕ A B subsetTerm (Id-U-ΠΠ!% eq A B A' B') = Id-U-ΠΠ!% eq A B A' B' subsetTerm (cast-subst A B e t) = let ⊢Γ = wfEqTerm (subsetTerm A) in cast-cong (subsetTerm A) (refl B) (refl t) e (conv e (univ (Id-cong (refl (univ 0<1 ⊢Γ)) (subsetTerm A) (refl B)))) subsetTerm (cast-ℕ-subst B e t) = let ⊢Γ = wfEqTerm (subsetTerm B) in cast-cong (refl (ℕⱼ (wfTerm t))) (subsetTerm B) (refl t) e (conv e (univ (Id-cong (refl (univ 0<1 ⊢Γ)) (refl (ℕⱼ ⊢Γ)) (subsetTerm B)))) subsetTerm (cast-Π-subst A P B e t) = let ⊢Γ = wfTerm A in cast-cong (refl (Πⱼ (≡is≤ PE.refl) ▹ (≡is≤ PE.refl) ▹ A ▹ P)) (subsetTerm B) (refl t) e (conv e (univ (Id-cong (refl (univ 0<1 ⊢Γ)) (refl (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ A ▹ P)) (subsetTerm B) ))) subsetTerm (cast-Π A B A' B' e f) = cast-Π A B A' B' e f subsetTerm (cast-ℕ-0 e) = cast-ℕ-0 e subsetTerm (cast-ℕ-S e n) = cast-ℕ-S e n subsetTerm (cast-ℕ-cong e n) = let ⊢Γ = wfTerm e ⊢ℕ = ℕⱼ ⊢Γ in cast-cong (refl ⊢ℕ) (refl ⊢ℕ) (subsetTerm n) e e subset (univ A⇒B) = univ (subsetTerm A⇒B) subset*Term : ∀ {Γ A t u l } → Γ ⊢ t ⇒* u ∷ A ^ l → Γ ⊢ t ≡ u ∷ A ^ [ ! , l ] subset*Term (id t) = refl t subset*Term (t⇒t′ ⇨ t⇒*u) = trans (subsetTerm t⇒t′) (subset*Term t⇒*u) subset* : ∀ {Γ A B r} → Γ ⊢ A ⇒* B ^ r → Γ ⊢ A ≡ B ^ r subset* (id A) = refl A subset* (A⇒A′ ⇨ A′⇒*B) = trans (subset A⇒A′) (subset* A′⇒*B) -- Transitivity of reduction transTerm⇒* : ∀ {Γ A t u v l } → Γ ⊢ t ⇒* u ∷ A ^ l → Γ ⊢ u ⇒* v ∷ A ^ l → Γ ⊢ t ⇒* v ∷ A ^ l transTerm⇒* (id x) y = y transTerm⇒* (x ⇨ x₁) y = x ⇨ transTerm⇒* x₁ y trans⇒* : ∀ {Γ A B C r} → Γ ⊢ A ⇒* B ^ r → Γ ⊢ B ⇒* C ^ r → Γ ⊢ A ⇒* C ^ r trans⇒* (id x) y = y trans⇒* (x ⇨ x₁) y = x ⇨ trans⇒* x₁ y transTerm:⇒:* : ∀ {Γ A t u v l } → Γ ⊢ t :⇒*: u ∷ A ^ l → Γ ⊢ u :⇒*: v ∷ A ^ l → Γ ⊢ t :⇒*: v ∷ A ^ l transTerm:⇒:* [[ ⊢t , ⊢u , d ]] [[ ⊢t₁ , ⊢u₁ , d₁ ]] = [[ ⊢t , ⊢u₁ , (transTerm⇒* d d₁) ]] conv⇒* : ∀ {Γ A B l t u} → Γ ⊢ t ⇒* u ∷ A ^ l → Γ ⊢ A ≡ B ^ [ ! , l ] → Γ ⊢ t ⇒* u ∷ B ^ l conv⇒* (id x) e = id (conv x e) conv⇒* (x ⇨ D) e = conv x e ⇨ conv⇒* D e conv:⇒*: : ∀ {Γ A B l t u} → Γ ⊢ t :⇒*: u ∷ A ^ l → Γ ⊢ A ≡ B ^ [ ! , l ] → Γ ⊢ t :⇒*: u ∷ B ^ l conv:⇒*: [[ ⊢t , ⊢u , d ]] e = [[ (conv ⊢t e) , (conv ⊢u e) , (conv⇒* d e) ]] -- Can extract left-part of a reduction redFirstTerm : ∀ {Γ t u A l } → Γ ⊢ t ⇒ u ∷ A ^ l → Γ ⊢ t ∷ A ^ [ ! , l ] redFirst : ∀ {Γ A B r} → Γ ⊢ A ⇒ B ^ r → Γ ⊢ A ^ r redFirstTerm (conv t⇒u A≡B) = conv (redFirstTerm t⇒u) A≡B redFirstTerm (app-subst t⇒u a) = (redFirstTerm t⇒u) ∘ⱼ a redFirstTerm (β-red {lA = lA} {lB = lB} lA< lB< ⊢A ⊢t ⊢a) = (lamⱼ lA< lB< ⊢A ⊢t) ∘ⱼ ⊢a redFirstTerm (natrec-subst F z s n⇒n′) = natrecⱼ F z s (redFirstTerm n⇒n′) redFirstTerm (natrec-zero F z s) = natrecⱼ F z s (zeroⱼ (wfTerm z)) redFirstTerm (natrec-suc n F z s) = natrecⱼ F z s (sucⱼ n) redFirstTerm (Id-subst A t u) = Idⱼ (redFirstTerm A) t u redFirstTerm (Id-ℕ-subst m n) = Idⱼ (ℕⱼ (wfTerm n)) (redFirstTerm m) n redFirstTerm (Id-ℕ-0-subst n) = Idⱼ (ℕⱼ (wfEqTerm (subsetTerm n))) (zeroⱼ (wfEqTerm (subsetTerm n))) (redFirstTerm n) redFirstTerm (Id-ℕ-S-subst m n) = Idⱼ (ℕⱼ (wfTerm m)) (sucⱼ m) (redFirstTerm n) redFirstTerm (Id-U-subst A B) = Idⱼ (univ 0<1 (wfTerm B)) (redFirstTerm A) B redFirstTerm (Id-U-ℕ-subst B) = let ⊢Γ = (wfEqTerm (subsetTerm B)) in Idⱼ (univ 0<1 ⊢Γ) (ℕⱼ ⊢Γ) (redFirstTerm B) redFirstTerm (Id-U-Π-subst A P B) = Idⱼ (univ 0<1 (wfTerm A)) (Πⱼ (≡is≤ PE.refl) ▹ (≡is≤ PE.refl) ▹ A ▹ P) (redFirstTerm B) redFirstTerm (Id-Π {rA = rA} <l <l' A B t u) = Idⱼ (Πⱼ <l ▹ <l' ▹ A ▹ B) t u redFirstTerm (Id-ℕ-00 ⊢Γ) = Idⱼ (ℕⱼ ⊢Γ) (zeroⱼ ⊢Γ) (zeroⱼ ⊢Γ) redFirstTerm (Id-ℕ-SS m n) = Idⱼ (ℕⱼ (wfTerm m)) (sucⱼ m) (sucⱼ n) redFirstTerm (Id-U-ΠΠ A B A' B') = Idⱼ (univ 0<1 (wfTerm A)) (Πⱼ (≡is≤ PE.refl) ▹ (≡is≤ PE.refl) ▹ A ▹ B) (Πⱼ (≡is≤ PE.refl) ▹ (≡is≤ PE.refl) ▹ A' ▹ B') redFirstTerm (Id-U-ℕℕ ⊢Γ) = Idⱼ (univ 0<1 ⊢Γ) (ℕⱼ ⊢Γ) (ℕⱼ ⊢Γ) redFirstTerm (Id-SProp A B) = Idⱼ (univ 0<1 (wfTerm A)) A B redFirstTerm (Id-ℕ-0S n) = Idⱼ (ℕⱼ (wfTerm n)) (zeroⱼ (wfTerm n)) (sucⱼ n) redFirstTerm (Id-ℕ-S0 n) = Idⱼ (ℕⱼ (wfTerm n)) (sucⱼ n) (zeroⱼ (wfTerm n)) redFirstTerm (Id-U-ℕΠ A B) = Idⱼ (univ 0<1 (wfTerm A)) (ℕⱼ (wfTerm A)) (Πⱼ (≡is≤ PE.refl) ▹ (≡is≤ PE.refl) ▹ A ▹ B) redFirstTerm (Id-U-Πℕ A B) = Idⱼ (univ 0<1 (wfTerm A)) (Πⱼ (≡is≤ PE.refl) ▹ (≡is≤ PE.refl) ▹ A ▹ B) (ℕⱼ (wfTerm A)) redFirstTerm (Id-U-ΠΠ!% eq A B A' B') = Idⱼ (univ 0<1 (wfTerm A)) (Πⱼ (≡is≤ PE.refl) ▹ (≡is≤ PE.refl) ▹ A ▹ B) (Πⱼ (≡is≤ PE.refl) ▹ (≡is≤ PE.refl) ▹ A' ▹ B') redFirstTerm (cast-subst A B e t) = castⱼ (redFirstTerm A) B e t redFirstTerm (cast-ℕ-subst B e t) = castⱼ (ℕⱼ (wfTerm t)) (redFirstTerm B) e t redFirstTerm (cast-Π-subst A P B e t) = castⱼ (Πⱼ (≡is≤ PE.refl) ▹ (≡is≤ PE.refl) ▹ A ▹ P) (redFirstTerm B) e t redFirstTerm (cast-Π A B A' B' e f) = castⱼ (Πⱼ (≡is≤ PE.refl) ▹ (≡is≤ PE.refl) ▹ A ▹ B) (Πⱼ (≡is≤ PE.refl) ▹ (≡is≤ PE.refl) ▹ A' ▹ B') e f redFirstTerm (cast-ℕ-0 e) = castⱼ (ℕⱼ (wfTerm e)) (ℕⱼ (wfTerm e)) e (zeroⱼ (wfTerm e)) redFirstTerm (cast-ℕ-S e n) = castⱼ (ℕⱼ (wfTerm e)) (ℕⱼ (wfTerm e)) e (sucⱼ n) redFirstTerm (cast-ℕ-cong e n) = castⱼ (ℕⱼ (wfTerm e)) (ℕⱼ (wfTerm e)) e (redFirstTerm n) redFirst (univ A⇒B) = univ (redFirstTerm A⇒B) redFirst*Term : ∀ {Γ t u A l} → Γ ⊢ t ⇒* u ∷ A ^ l → Γ ⊢ t ∷ A ^ [ ! , l ] redFirst*Term (id t) = t redFirst*Term (t⇒t′ ⇨ t′⇒*u) = redFirstTerm t⇒t′ redFirst* : ∀ {Γ A B r} → Γ ⊢ A ⇒* B ^ r → Γ ⊢ A ^ r redFirst* (id A) = A redFirst* (A⇒A′ ⇨ A′⇒*B) = redFirst A⇒A′ -- Neutral types are always small -- tyNe : ∀ {Γ t r} → Γ ⊢ t ^ r → Neutral t → Γ ⊢ t ∷ (Univ r) ^ ! -- tyNe (univ x) tn = x -- tyNe (Idⱼ A x y) tn = Idⱼ A x y -- Neutrals do not weak head reduce neRedTerm : ∀ {Γ t u l A} (d : Γ ⊢ t ⇒ u ∷ A ^ l) (n : Neutral t) → ⊥ neRed : ∀ {Γ t u r} (d : Γ ⊢ t ⇒ u ^ r) (n : Neutral t) → ⊥ whnfRedTerm : ∀ {Γ t u A l} (d : Γ ⊢ t ⇒ u ∷ A ^ l) (w : Whnf t) → ⊥ whnfRed : ∀ {Γ A B r} (d : Γ ⊢ A ⇒ B ^ r) (w : Whnf A) → ⊥ neRedTerm (conv d x) n = neRedTerm d n neRedTerm (app-subst d x) (∘ₙ n) = neRedTerm d n neRedTerm (β-red _ _ x x₁ x₂) (∘ₙ ()) neRedTerm (natrec-zero x x₁ x₂) (natrecₙ ()) neRedTerm (natrec-suc x x₁ x₂ x₃) (natrecₙ ()) neRedTerm (natrec-subst x x₁ x₂ tr) (natrecₙ tn) = neRedTerm tr tn neRedTerm (Id-subst tr x y) (Idₙ tn) = neRedTerm tr tn neRedTerm (Id-ℕ-subst tr x) (Idℕₙ tn) = neRedTerm tr tn neRedTerm (Id-ℕ-0-subst tr) (Idℕ0ₙ tn) = neRedTerm tr tn neRedTerm (Id-ℕ-S-subst x tr) (IdℕSₙ tn) = neRedTerm tr tn neRedTerm (Id-U-subst tr x) (IdUₙ tn) = neRedTerm tr tn neRedTerm (Id-U-ℕ-subst tr) (IdUℕₙ tn) = neRedTerm tr tn neRedTerm (Id-U-Π-subst A B tr) (IdUΠₙ tn) = neRedTerm tr tn neRedTerm (Id-subst tr x y) (Idℕₙ tn) = whnfRedTerm tr ℕₙ neRedTerm (Id-subst tr x y) (Idℕ0ₙ tn) = whnfRedTerm tr ℕₙ neRedTerm (Id-subst tr x y) (IdℕSₙ tn) = whnfRedTerm tr ℕₙ neRedTerm (Id-subst tr x y) (IdUₙ tn) = whnfRedTerm tr Uₙ neRedTerm (Id-subst tr x y) (IdUℕₙ tn) = whnfRedTerm tr Uₙ neRedTerm (Id-subst tr x y) (IdUΠₙ tn) = whnfRedTerm tr Uₙ neRedTerm (Id-ℕ-subst tr x) (Idℕ0ₙ tn) = whnfRedTerm tr zeroₙ neRedTerm (Id-ℕ-subst tr x) (IdℕSₙ tn) = whnfRedTerm tr sucₙ neRedTerm (Id-U-subst tr x) (IdUℕₙ tn) = whnfRedTerm tr ℕₙ neRedTerm (Id-U-subst tr x) (IdUΠₙ tn) = whnfRedTerm tr Πₙ neRedTerm (Id-Π _ _ A B t u) (Idₙ ()) neRedTerm (Id-ℕ-00 tr) (Idₙ ()) neRedTerm (Id-ℕ-00 tr) (Idℕₙ ()) neRedTerm (Id-ℕ-00 tr) (Idℕ0ₙ ()) neRedTerm (Id-ℕ-SS x tr) (Idₙ ()) neRedTerm (Id-ℕ-SS x tr) (Idℕₙ ()) neRedTerm (Id-U-ΠΠ A B A' B') (Idₙ ()) neRedTerm (Id-U-ΠΠ A B A' B') (IdUₙ ()) neRedTerm (Id-U-ΠΠ A B A' B') (IdUΠₙ ()) neRedTerm (Id-U-ℕℕ x) (Idₙ ()) neRedTerm (Id-U-ℕℕ x) (IdUₙ ()) neRedTerm (Id-U-ℕℕ x) (IdUℕₙ ()) neRedTerm (Id-SProp A B) (Idₙ ()) neRedTerm (Id-ℕ-0S x) (Idₙ ()) neRedTerm (Id-ℕ-S0 x) (Idₙ ()) neRedTerm (Id-U-ℕΠ A B) (Idₙ ()) neRedTerm (Id-U-Πℕ A B) (Idₙ ()) neRedTerm (Id-U-ΠΠ!% eq A B A' B') (Idₙ ()) neRedTerm (cast-subst tr B e x) (castₙ tn) = neRedTerm tr tn neRedTerm (cast-ℕ-subst tr e x) (castℕₙ tn) = neRedTerm tr tn neRedTerm (cast-Π-subst A B tr e x) (castΠₙ tn) = neRedTerm tr tn neRedTerm (cast-Π-subst A B tr e x) (castΠℕₙ) = whnfRedTerm tr ℕₙ neRedTerm (cast-subst tr x x₁ x₂) (castℕₙ tn) = whnfRedTerm tr ℕₙ neRedTerm (cast-subst tr x x₁ x₂) (castΠₙ tn) = whnfRedTerm tr Πₙ neRedTerm (cast-subst tr x x₁ x₂) (castℕℕₙ tn) = whnfRedTerm tr ℕₙ neRedTerm (cast-subst tr x x₁ x₂) (castℕΠₙ) = whnfRedTerm tr ℕₙ neRedTerm (cast-subst tr x x₁ x₂) (castΠℕₙ) = whnfRedTerm tr Πₙ neRedTerm (cast-ℕ-subst tr x x₁) (castℕℕₙ tn) = whnfRedTerm tr ℕₙ neRedTerm (cast-ℕ-subst tr x x₁) (castℕΠₙ) = whnfRedTerm tr Πₙ neRedTerm (cast-Π A B A' B' e f) (castₙ ()) neRedTerm (cast-Π A B A' B' e f) (castΠₙ ()) neRedTerm (cast-ℕ-0 x) (castₙ ()) neRedTerm (cast-ℕ-0 x) (castℕₙ ()) neRedTerm (cast-ℕ-0 x) (castℕℕₙ ()) neRedTerm (cast-ℕ-S x x₁) (castₙ ()) neRedTerm (cast-ℕ-S x x₁) (castℕₙ ()) neRedTerm (cast-ℕ-S x x₁) (castℕℕₙ ()) neRedTerm (cast-ℕ-cong x x₁) (castₙ ()) neRedTerm (cast-ℕ-cong x x₁) (castℕₙ ()) neRedTerm (cast-ℕ-cong x x₁) (castℕℕₙ t) = neRedTerm x₁ t neRedTerm (cast-subst d x x₁ x₂) castΠΠ%!ₙ = whnfRedTerm d Πₙ neRedTerm (cast-subst d x x₁ x₂) castΠΠ!%ₙ = whnfRedTerm d Πₙ neRedTerm (cast-Π-subst x x₁ d x₂ x₃) castΠΠ%!ₙ = whnfRedTerm d Πₙ neRedTerm (cast-Π-subst x x₁ d x₂ x₃) castΠΠ!%ₙ = whnfRedTerm d Πₙ neRed (univ x) N = neRedTerm x N whnfRedTerm (conv d x) w = whnfRedTerm d w whnfRedTerm (app-subst d x) (ne (∘ₙ x₁)) = neRedTerm d x₁ whnfRedTerm (β-red _ _ x x₁ x₂) (ne (∘ₙ ())) whnfRedTerm (natrec-subst x x₁ x₂ d) (ne (natrecₙ x₃)) = neRedTerm d x₃ whnfRedTerm (natrec-zero x x₁ x₂) (ne (natrecₙ ())) whnfRedTerm (natrec-suc x x₁ x₂ x₃) (ne (natrecₙ ())) whnfRedTerm (Id-subst d x x₁) (ne (Idₙ x₂)) = neRedTerm d x₂ whnfRedTerm (Id-subst d x x₁) (ne (Idℕₙ x₂)) = whnfRedTerm d ℕₙ whnfRedTerm (Id-subst d x x₁) (ne (Idℕ0ₙ x₂)) = whnfRedTerm d ℕₙ whnfRedTerm (Id-subst d x x₁) (ne (IdℕSₙ x₂)) = whnfRedTerm d ℕₙ whnfRedTerm (Id-subst d x x₁) (ne (IdUₙ x₂)) = whnfRedTerm d Uₙ whnfRedTerm (Id-subst d x x₁) (ne (IdUℕₙ x₂)) = whnfRedTerm d Uₙ whnfRedTerm (Id-subst d x x₁) (ne (IdUΠₙ x₂)) = whnfRedTerm d Uₙ whnfRedTerm (Id-ℕ-subst d x) (ne (Idℕₙ x₁)) = neRedTerm d x₁ whnfRedTerm (Id-ℕ-subst d x) (ne (Idℕ0ₙ x₁)) = whnfRedTerm d zeroₙ whnfRedTerm (Id-ℕ-subst d x) (ne (IdℕSₙ x₁)) = whnfRedTerm d sucₙ whnfRedTerm (Id-ℕ-0-subst d) (ne (Idℕ0ₙ x)) = neRedTerm d x whnfRedTerm (Id-ℕ-S-subst x d) (ne (IdℕSₙ x₁)) = neRedTerm d x₁ whnfRedTerm (Id-U-subst d x) (ne (IdUₙ x₁)) = neRedTerm d x₁ whnfRedTerm (Id-U-subst d x) (ne (IdUℕₙ x₁)) = whnfRedTerm d ℕₙ whnfRedTerm (Id-U-subst d x) (ne (IdUΠₙ x₁)) = whnfRedTerm d Πₙ whnfRedTerm (Id-U-ℕ-subst d) (ne (IdUℕₙ x)) = neRedTerm d x whnfRedTerm (Id-U-Π-subst x x₁ d) (ne (IdUΠₙ x₂)) = neRedTerm d x₂ whnfRedTerm (Id-Π _ _ x x₁ x₂ x₃) (ne (Idₙ ())) whnfRedTerm (Id-ℕ-00 x) (ne (Idₙ ())) whnfRedTerm (Id-ℕ-00 x) (ne (Idℕₙ ())) whnfRedTerm (Id-ℕ-00 x) (ne (Idℕ0ₙ ())) whnfRedTerm (Id-ℕ-SS x x₁) (ne (Idₙ ())) whnfRedTerm (Id-ℕ-SS x x₁) (ne (Idℕₙ ())) whnfRedTerm (Id-ℕ-SS x x₁) (ne (IdℕSₙ ())) whnfRedTerm (Id-U-ΠΠ x x₁ x₂ x₃) (ne (Idₙ ())) whnfRedTerm (Id-U-ΠΠ x x₁ x₂ x₃) (ne (IdUₙ ())) whnfRedTerm (Id-U-ΠΠ x x₁ x₂ x₃) (ne (IdUΠₙ ())) whnfRedTerm (Id-U-ℕℕ x) (ne (Idₙ ())) whnfRedTerm (Id-U-ℕℕ x) (ne (IdUₙ ())) whnfRedTerm (Id-U-ℕℕ x) (ne (IdUℕₙ ())) whnfRedTerm (Id-SProp x x₁) (ne (Idₙ ())) whnfRedTerm (Id-ℕ-0S x) (ne (Idₙ ())) whnfRedTerm (Id-ℕ-S0 x) (ne (Idₙ ())) whnfRedTerm (Id-U-ℕΠ A B) (ne (Idₙ ())) whnfRedTerm (Id-U-Πℕ A B) (ne (Idₙ ())) whnfRedTerm (Id-U-ΠΠ!% eq A B A' B') (ne (Idₙ ())) whnfRedTerm (cast-subst d x x₁ x₂) (ne (castₙ x₃)) = neRedTerm d x₃ whnfRedTerm (cast-subst d x x₁ x₂) (ne (castℕₙ x₃)) = whnfRedTerm d ℕₙ whnfRedTerm (cast-subst d x x₁ x₂) (ne (castΠₙ x₃)) = whnfRedTerm d Πₙ whnfRedTerm (cast-subst d x x₁ x₂) (ne (castℕℕₙ x₃)) = whnfRedTerm d ℕₙ whnfRedTerm (cast-subst d x x₁ x₂) (ne castℕΠₙ) = whnfRedTerm d ℕₙ whnfRedTerm (cast-subst d x x₁ x₂) (ne castΠℕₙ) = whnfRedTerm d Πₙ whnfRedTerm (cast-ℕ-subst d x x₁) (ne (castℕₙ x₂)) = neRedTerm d x₂ whnfRedTerm (cast-ℕ-subst d x x₁) (ne (castℕℕₙ x₂)) = whnfRedTerm d ℕₙ whnfRedTerm (cast-ℕ-subst d x x₁) (ne castℕΠₙ) = whnfRedTerm d Πₙ whnfRedTerm (cast-Π-subst x x₁ d x₂ x₃) (ne (castΠₙ x₄)) = neRedTerm d x₄ whnfRedTerm (cast-Π-subst x x₁ d x₂ x₃) (ne castΠℕₙ) = whnfRedTerm d ℕₙ whnfRedTerm (cast-Π x x₁ x₂ x₃ x₄ x₅) (ne (castₙ ())) whnfRedTerm (cast-Π x x₁ x₂ x₃ x₄ x₅) (ne (castΠₙ ())) whnfRedTerm (cast-ℕ-0 x) (ne (castₙ ())) whnfRedTerm (cast-ℕ-0 x) (ne (castℕₙ ())) whnfRedTerm (cast-ℕ-0 x) (ne (castℕℕₙ ())) whnfRedTerm (cast-ℕ-S x x₁) (ne (castₙ ())) whnfRedTerm (cast-ℕ-S x x₁) (ne (castℕₙ ())) whnfRedTerm (cast-ℕ-S x x₁) (ne (castℕℕₙ ())) whnfRedTerm (cast-ℕ-cong x x₁) (ne (castₙ ())) whnfRedTerm (cast-ℕ-cong x x₁) (ne (castℕₙ ())) whnfRedTerm (cast-ℕ-cong x x₁) (ne (castℕℕₙ t)) = neRedTerm x₁ t whnfRedTerm (cast-subst d x x₁ x₂) (ne castΠΠ%!ₙ) = whnfRedTerm d Πₙ whnfRedTerm (cast-subst d x x₁ x₂) (ne castΠΠ!%ₙ) = whnfRedTerm d Πₙ whnfRedTerm (cast-Π-subst x x₁ d x₂ x₃) (ne castΠΠ%!ₙ) = whnfRedTerm d Πₙ whnfRedTerm (cast-Π-subst x x₁ d x₂ x₃) (ne castΠΠ!%ₙ) = whnfRedTerm d Πₙ whnfRed (univ x) w = whnfRedTerm x w whnfRed*Term : ∀ {Γ t u A l} (d : Γ ⊢ t ⇒* u ∷ A ^ l) (w : Whnf t) → t PE.≡ u whnfRed*Term (id x) Uₙ = PE.refl whnfRed*Term (id x) Πₙ = PE.refl whnfRed*Term (id x) ∃ₙ = PE.refl whnfRed*Term (id x) ℕₙ = PE.refl whnfRed*Term (id x) Emptyₙ = PE.refl whnfRed*Term (id x) lamₙ = PE.refl whnfRed*Term (id x) zeroₙ = PE.refl whnfRed*Term (id x) sucₙ = PE.refl whnfRed*Term (id x) (ne x₁) = PE.refl whnfRed*Term (conv x x₁ ⇨ d) w = ⊥-elim (whnfRedTerm x w) whnfRed*Term (x ⇨ d) (ne x₁) = ⊥-elim (neRedTerm x x₁) whnfRed* : ∀ {Γ A B r} (d : Γ ⊢ A ⇒* B ^ r) (w : Whnf A) → A PE.≡ B whnfRed* (id x) w = PE.refl whnfRed* (x ⇨ d) w = ⊥-elim (whnfRed x w) -- Whr is deterministic -- somehow the cases (cast-Π, cast-Π) and (Id-U-ΠΠ, Id-U-ΠΠ) fail if -- we do not introduce a dummy relevance rA'. This is why we need the two -- auxiliary functions. whrDetTerm-aux1 : ∀{Γ t u F lF A A' rA lA lB rA' l B B' e f} → (d : t PE.≡ cast l (Π A ^ rA ° lA ▹ B ° lB ° l) (Π A' ^ rA' ° lA ▹ B' ° lB ° l) e f) → (d′ : Γ ⊢ t ⇒ u ∷ F ^ lF) → (lam A' ▹ (let a = cast l (wk1 A') (wk1 A) (Idsym (Univ rA l) (wk1 A) (wk1 A') (fst (wk1 e))) (var 0) in cast l (B [ a ]↑) B' ((snd (wk1 e)) ∘ (var 0) ^ ¹) ((wk1 f) ∘ a ^ l)) ^ l) PE.≡ u whrDetTerm-aux1 d (conv d' x) = whrDetTerm-aux1 d d' whrDetTerm-aux1 PE.refl (cast-subst d' x x₁ x₂) = ⊥-elim (whnfRedTerm d' Πₙ) whrDetTerm-aux1 PE.refl (cast-Π-subst x x₁ d' x₂ x₃) = ⊥-elim (whnfRedTerm d' Πₙ) whrDetTerm-aux1 PE.refl (cast-Π x x₁ x₂ x₃ x₄ x₅) = PE.refl whrDetTerm-aux2 : ∀{Γ t u F lF A rA B A' rA' B'} → (rA≡rA' : rA PE.≡ rA') → (d : t PE.≡ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) (Π A' ^ rA' ° ⁰ ▹ B' ° ⁰ ° ⁰)) → (d' : Γ ⊢ t ⇒ u ∷ F ^ lF) → (∃ (Id (Univ rA ⁰) A A') ▹ (Π (wk1 A') ^ rA ° ⁰ ▹ Id (U ⁰) ((wk (lift (step id)) B) [ cast ⁰ (wk1 (wk1 A')) (wk1 (wk1 A)) (Idsym (Univ rA ⁰) (wk1 (wk1 A)) (wk1 (wk1 A')) (var 1)) (var 0) ]↑) (wk (lift (step id)) B') ° ¹ ° ¹ ) ) PE.≡ u whrDetTerm-aux2 eq d (conv d' x) = whrDetTerm-aux2 eq d d' whrDetTerm-aux2 _ PE.refl (Id-subst d' x x₁) = ⊥-elim (whnfRedTerm d' Uₙ) whrDetTerm-aux2 _ PE.refl (Id-U-subst d' x) = ⊥-elim (whnfRedTerm d' Πₙ) whrDetTerm-aux2 _ PE.refl (Id-U-Π-subst x x₁ d') = ⊥-elim (whnfRedTerm d' Πₙ) whrDetTerm-aux2 _ PE.refl (Id-U-ΠΠ x x₁ x₂ x₃) = PE.refl whrDetTerm-aux2 PE.refl PE.refl (Id-U-ΠΠ!% eq A B A' B') = ⊥-elim (eq PE.refl) whrDetTerm : ∀{Γ t u A l u′ A′ l′} (d : Γ ⊢ t ⇒ u ∷ A ^ l) (d′ : Γ ⊢ t ⇒ u′ ∷ A′ ^ l′) → u PE.≡ u′ whrDet : ∀{Γ A B B′ r r'} (d : Γ ⊢ A ⇒ B ^ r) (d′ : Γ ⊢ A ⇒ B′ ^ r') → B PE.≡ B′ whrDetTerm (conv d x) d′ = whrDetTerm d d′ whrDetTerm (app-subst d x) (app-subst d′ x₁) rewrite whrDetTerm d d′ = PE.refl whrDetTerm (app-subst d x) (β-red _ _ x₁ x₂ x₃) = ⊥-elim (whnfRedTerm d lamₙ) whrDetTerm (β-red _ _ x x₁ x₂) (app-subst d' x₃) = ⊥-elim (whnfRedTerm d' lamₙ) whrDetTerm (β-red _ _ x x₁ x₂) (β-red _ _ x₃ x₄ x₅) = PE.refl whrDetTerm (natrec-subst x x₁ x₂ d) (natrec-subst x₃ x₄ x₅ d') rewrite whrDetTerm d d' = PE.refl whrDetTerm (natrec-subst x x₁ x₂ d) (natrec-zero x₃ x₄ x₅) = ⊥-elim (whnfRedTerm d zeroₙ) whrDetTerm (natrec-subst x x₁ x₂ d) (natrec-suc x₃ x₄ x₅ x₆) = ⊥-elim (whnfRedTerm d sucₙ) whrDetTerm (natrec-zero x x₁ x₂) (natrec-subst x₃ x₄ x₅ d') = ⊥-elim (whnfRedTerm d' zeroₙ) whrDetTerm (natrec-zero x x₁ x₂) (natrec-zero x₃ x₄ x₅) = PE.refl whrDetTerm (natrec-suc x x₁ x₂ x₃) (natrec-subst x₄ x₅ x₆ d') = ⊥-elim (whnfRedTerm d' sucₙ) whrDetTerm (natrec-suc x x₁ x₂ x₃) (natrec-suc x₄ x₅ x₆ x₇) = PE.refl whrDetTerm (Id-subst d x x₁) (Id-subst d' x₂ x₃) rewrite whrDetTerm d d' = PE.refl whrDetTerm (Id-subst d x x₁) (Id-ℕ-subst d' x₂) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (Id-subst d x x₁) (Id-ℕ-0-subst d') = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (Id-subst d x x₁) (Id-ℕ-S-subst x₂ d') = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (Id-subst d x x₁) (Id-U-subst d' x₂) = ⊥-elim (whnfRedTerm d Uₙ) whrDetTerm (Id-subst d x x₁) (Id-U-ℕ-subst d') = ⊥-elim (whnfRedTerm d Uₙ) whrDetTerm (Id-subst d x x₁) (Id-U-Π-subst x₂ x₃ d') = ⊥-elim (whnfRedTerm d Uₙ) whrDetTerm (Id-subst d x x₁) (Id-Π _ _ x₂ x₃ x₄ x₅) = ⊥-elim (whnfRedTerm d Πₙ) whrDetTerm (Id-subst d x x₁) (Id-ℕ-00 x₂) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (Id-subst d x x₁) (Id-ℕ-SS x₂ x₃) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (Id-subst d x x₁) (Id-U-ΠΠ x₂ x₃ x₄ x₅) = ⊥-elim (whnfRedTerm d Uₙ) whrDetTerm (Id-subst d x x₁) (Id-U-ℕℕ x₂) = ⊥-elim (whnfRedTerm d Uₙ) whrDetTerm (Id-subst d x x₁) (Id-SProp x₂ x₃) = ⊥-elim (whnfRedTerm d Uₙ) whrDetTerm (Id-subst d x x₁) (Id-ℕ-0S x₂) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (Id-subst d x x₁) (Id-ℕ-S0 x₂) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (Id-subst d x x₁) (Id-U-ℕΠ x₂ x₃) = ⊥-elim (whnfRedTerm d Uₙ) whrDetTerm (Id-subst d x x₁) (Id-U-Πℕ x₂ x₃) = ⊥-elim (whnfRedTerm d Uₙ) whrDetTerm (Id-subst d x x₁) (Id-U-ΠΠ!% x₂ x₃ x₄ x₅ x₆) = ⊥-elim (whnfRedTerm d Uₙ) whrDetTerm (Id-ℕ-subst d x) (Id-subst d' x₁ x₂) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (Id-ℕ-subst d x) (Id-ℕ-subst d' x₁) rewrite whrDetTerm d d' = PE.refl whrDetTerm (Id-ℕ-subst d x) (Id-ℕ-0-subst d') = ⊥-elim (whnfRedTerm d zeroₙ) whrDetTerm (Id-ℕ-subst d x) (Id-ℕ-S-subst x₁ d') = ⊥-elim (whnfRedTerm d sucₙ) whrDetTerm (Id-ℕ-subst d x) (Id-ℕ-00 x₁) = ⊥-elim (whnfRedTerm d zeroₙ) whrDetTerm (Id-ℕ-subst d x) (Id-ℕ-SS x₁ x₂) = ⊥-elim (whnfRedTerm d sucₙ) whrDetTerm (Id-ℕ-subst d x) (Id-ℕ-0S x₁) = ⊥-elim (whnfRedTerm d zeroₙ) whrDetTerm (Id-ℕ-subst d x) (Id-ℕ-S0 x₁) = ⊥-elim (whnfRedTerm d sucₙ) whrDetTerm (Id-ℕ-0-subst d) (Id-subst d' x x₁) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (Id-ℕ-0-subst d) (Id-ℕ-subst d' x) = ⊥-elim (whnfRedTerm d' zeroₙ) whrDetTerm (Id-ℕ-0-subst d) (Id-ℕ-0-subst d') rewrite whrDetTerm d d' = PE.refl whrDetTerm (Id-ℕ-0-subst d) (Id-ℕ-00 x) = ⊥-elim (whnfRedTerm d zeroₙ) whrDetTerm (Id-ℕ-0-subst d) (Id-ℕ-0S x) = ⊥-elim (whnfRedTerm d sucₙ) whrDetTerm (Id-ℕ-S-subst x d) (Id-subst d' x₁ x₂) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (Id-ℕ-S-subst x d) (Id-ℕ-subst d' x₁) = ⊥-elim (whnfRedTerm d' sucₙ) whrDetTerm (Id-ℕ-S-subst x d) (Id-ℕ-S-subst x₁ d') rewrite whrDetTerm d d' = PE.refl whrDetTerm (Id-ℕ-S-subst x d) (Id-ℕ-SS x₁ x₂) = ⊥-elim (whnfRedTerm d sucₙ) whrDetTerm (Id-ℕ-S-subst x d) (Id-ℕ-S0 x₁) = ⊥-elim (whnfRedTerm d zeroₙ) whrDetTerm (Id-U-subst d x) (Id-subst d' x₁ x₂) = ⊥-elim (whnfRedTerm d' Uₙ) whrDetTerm (Id-U-subst d x) (Id-U-subst d' x₁) rewrite whrDetTerm d d' = PE.refl whrDetTerm (Id-U-subst d x) (Id-U-ℕ-subst d') = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (Id-U-subst d x) (Id-U-Π-subst x₁ x₂ d') = ⊥-elim (whnfRedTerm d Πₙ) whrDetTerm (Id-U-subst d x) (Id-U-ΠΠ x₁ x₂ x₃ x₄) = ⊥-elim (whnfRedTerm d Πₙ) whrDetTerm (Id-U-subst d x) (Id-U-ℕℕ x₁) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (Id-U-subst d x) (Id-U-ℕΠ x₁ x₂) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (Id-U-subst d x) (Id-U-Πℕ x₁ x₂) = ⊥-elim (whnfRedTerm d Πₙ) whrDetTerm (Id-U-subst d x) (Id-U-ΠΠ!% x₁ x₂ x₃ x₄ x₅) = ⊥-elim (whnfRedTerm d Πₙ) whrDetTerm (Id-U-ℕ-subst d) (Id-subst d' x x₁) = ⊥-elim (whnfRedTerm d' Uₙ) whrDetTerm (Id-U-ℕ-subst d) (Id-U-subst d' x) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (Id-U-ℕ-subst d) (Id-U-ℕ-subst d') rewrite whrDetTerm d d' = PE.refl whrDetTerm (Id-U-ℕ-subst d) (Id-U-ℕℕ x) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (Id-U-ℕ-subst d) (Id-U-ℕΠ x x₁) = ⊥-elim (whnfRedTerm d Πₙ) whrDetTerm (Id-U-Π-subst x x₁ d) (Id-subst d' x₂ x₃) = ⊥-elim (whnfRedTerm d' Uₙ) whrDetTerm (Id-U-Π-subst x x₁ d) (Id-U-subst d' x₂) = ⊥-elim (whnfRedTerm d' Πₙ) whrDetTerm (Id-U-Π-subst x x₁ d) (Id-U-Π-subst x₂ x₃ d') rewrite whrDetTerm d d' = PE.refl whrDetTerm (Id-U-Π-subst x x₁ d) (Id-U-ΠΠ x₂ x₃ x₄ x₅) = ⊥-elim (whnfRedTerm d Πₙ) whrDetTerm (Id-U-Π-subst x x₁ d) (Id-U-Πℕ x₂ x₃) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (Id-U-Π-subst x x₁ d) (Id-U-ΠΠ!% x₂ x₃ x₄ x₅ x₆) = ⊥-elim (whnfRedTerm d Πₙ) whrDetTerm (Id-Π _ _ x x₁ x₂ x₃) (Id-subst d' x₄ x₅) = ⊥-elim (whnfRedTerm d' Πₙ) whrDetTerm (Id-Π _ _ x x₁ x₂ x₃) (Id-Π _ _ x₄ x₅ x₆ x₇) = PE.refl whrDetTerm (Id-ℕ-00 x) (Id-subst d' x₁ x₂) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (Id-ℕ-00 x) (Id-ℕ-subst d' x₁) = ⊥-elim (whnfRedTerm d' zeroₙ) whrDetTerm (Id-ℕ-00 x) (Id-ℕ-0-subst d') = ⊥-elim (whnfRedTerm d' zeroₙ) whrDetTerm (Id-ℕ-00 x) (Id-ℕ-00 x₁) = PE.refl whrDetTerm (Id-ℕ-SS x x₁) (Id-subst d' x₂ x₃) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (Id-ℕ-SS x x₁) (Id-ℕ-subst d' x₂) = ⊥-elim (whnfRedTerm d' sucₙ) whrDetTerm (Id-ℕ-SS x x₁) (Id-ℕ-S-subst x₂ d') = ⊥-elim (whnfRedTerm d' sucₙ) whrDetTerm (Id-ℕ-SS x x₁) (Id-ℕ-SS x₂ x₃) = PE.refl whrDetTerm (Id-U-ΠΠ x x₁ x₂ x₃) d' = whrDetTerm-aux2 PE.refl PE.refl d' whrDetTerm (Id-U-ℕℕ x) (Id-subst d' x₁ x₂) = ⊥-elim (whnfRedTerm d' Uₙ) whrDetTerm (Id-U-ℕℕ x) (Id-U-subst d' x₁) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (Id-U-ℕℕ x) (Id-U-ℕ-subst d') = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (Id-U-ℕℕ x) (Id-U-ℕℕ x₁) = PE.refl whrDetTerm (Id-SProp x x₁) (Id-subst d' x₂ x₃) = ⊥-elim (whnfRedTerm d' Uₙ) whrDetTerm (Id-SProp x x₁) (Id-SProp x₂ x₃) = PE.refl whrDetTerm (Id-ℕ-0S x) (Id-subst d' x₁ x₂) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (Id-ℕ-0S x) (Id-ℕ-subst d' x₁) = ⊥-elim (whnfRedTerm d' zeroₙ) whrDetTerm (Id-ℕ-0S x) (Id-ℕ-0-subst d') = ⊥-elim (whnfRedTerm d' sucₙ) whrDetTerm (Id-ℕ-0S x) (Id-ℕ-0S x₁) = PE.refl whrDetTerm (Id-ℕ-S0 x) (Id-subst d' x₁ x₂) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (Id-ℕ-S0 x) (Id-ℕ-subst d' x₁) = ⊥-elim (whnfRedTerm d' sucₙ) whrDetTerm (Id-ℕ-S0 x) (Id-ℕ-S-subst x₁ d') = ⊥-elim (whnfRedTerm d' zeroₙ) whrDetTerm (Id-ℕ-S0 x) (Id-ℕ-S0 x₁) = PE.refl whrDetTerm (Id-U-ℕΠ x x₁) (Id-subst d' x₂ x₃) = ⊥-elim (whnfRedTerm d' Uₙ) whrDetTerm (Id-U-ℕΠ x x₁) (Id-U-subst d' x₂) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (Id-U-ℕΠ x x₁) (Id-U-ℕ-subst d') = ⊥-elim (whnfRedTerm d' Πₙ) whrDetTerm (Id-U-ℕΠ x x₁) (Id-U-ℕΠ x₂ x₃) = PE.refl whrDetTerm (Id-U-Πℕ x x₁) (Id-subst d' x₂ x₃) = ⊥-elim (whnfRedTerm d' Uₙ) whrDetTerm (Id-U-Πℕ x x₁) (Id-U-subst d' x₂) = ⊥-elim (whnfRedTerm d' Πₙ) whrDetTerm (Id-U-Πℕ x x₁) (Id-U-Π-subst x₂ x₃ d') = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (Id-U-Πℕ x x₁) (Id-U-Πℕ x₂ x₃) = PE.refl whrDetTerm (Id-U-ΠΠ!% eq A B A' B') (Id-subst d' x x₁) = ⊥-elim (whnfRedTerm d' Uₙ) whrDetTerm (Id-U-ΠΠ!% eq A B A' B') (Id-U-subst d' x) = ⊥-elim (whnfRedTerm d' Πₙ) whrDetTerm (Id-U-ΠΠ!% eq A B A' B') (Id-U-Π-subst x x₁ d') = ⊥-elim (whnfRedTerm d' Πₙ) whrDetTerm (Id-U-ΠΠ!% eq A B A' B') (Id-U-ΠΠ x x₁ x₂ x₃) = ⊥-elim (eq PE.refl) whrDetTerm (Id-U-ΠΠ!% eq A B A' B') (Id-U-ΠΠ!% x x₁ x₂ x₃ x₄) = PE.refl whrDetTerm (cast-subst d x x₁ x₂) (cast-subst d' x₃ x₄ x₅) rewrite whrDetTerm d d' = PE.refl whrDetTerm (cast-subst d x x₁ x₂) (cast-ℕ-subst d' x₃ x₄) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (cast-subst d x x₁ x₂) (cast-Π-subst x₃ x₄ d' x₅ x₆) = ⊥-elim (whnfRedTerm d Πₙ) whrDetTerm (cast-subst d x x₁ x₂) (cast-Π x₃ x₄ x₅ x₆ x₇ x₈) = ⊥-elim (whnfRedTerm d Πₙ) whrDetTerm (cast-subst d x x₁ x₂) (cast-ℕ-0 x₃) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (cast-subst d x x₁ x₂) (cast-ℕ-S x₃ x₄) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (cast-ℕ-subst d x x₁) (cast-subst d' x₂ x₃ x₄) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (cast-ℕ-subst d x x₁) (cast-ℕ-subst d' x₂ x₃) rewrite whrDetTerm d d' = PE.refl whrDetTerm (cast-ℕ-subst d x x₁) (cast-ℕ-0 x₂) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (cast-ℕ-subst d x x₁) (cast-ℕ-S x₂ x₃) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (cast-Π-subst x x₁ d x₂ x₃) (cast-subst d' x₄ x₅ x₆) = ⊥-elim (whnfRedTerm d' Πₙ) whrDetTerm (cast-Π-subst x x₁ d x₂ x₃) (cast-Π-subst x₄ x₅ d' x₆ x₇) rewrite whrDetTerm d d' = PE.refl whrDetTerm (cast-Π-subst x x₁ d x₂ x₃) (cast-Π x₄ x₅ x₆ x₇ x₈ x₉) = ⊥-elim (whnfRedTerm d Πₙ) whrDetTerm (cast-Π x x₁ x₂ x₃ x₄ x₅) d' = whrDetTerm-aux1 (PE.refl) d' whrDetTerm (cast-ℕ-0 x) (cast-subst d' x₁ x₂ x₃) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (cast-ℕ-0 x) (cast-ℕ-subst d' x₁ x₂) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (cast-ℕ-0 x) (cast-ℕ-0 x₁) = PE.refl whrDetTerm (cast-ℕ-S x x₁) (cast-subst d' x₂ x₃ x₄) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (cast-ℕ-S x x₁) (cast-ℕ-subst d' x₂ x₃) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (cast-ℕ-S x x₁) (cast-ℕ-S x₂ x₃) = PE.refl whrDetTerm (cast-ℕ-cong x x₁) (cast-subst d' x₂ x₃ x₄) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (cast-ℕ-cong x x₁) (cast-ℕ-subst d' x₂ x₃) = ⊥-elim (whnfRedTerm d' ℕₙ) whrDetTerm (cast-ℕ-cong x x₁) (cast-ℕ-cong x₂ x₃) rewrite whrDetTerm x₁ x₃ = PE.refl -- whrDetTerm (cast-subst d x x₁ x₂) (cast-ℕ-cong x₃ d′) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (cast-ℕ-subst d x x₁) (cast-ℕ-cong x₂ d′) = ⊥-elim (whnfRedTerm d ℕₙ) whrDetTerm (cast-ℕ-0 x) (cast-ℕ-cong x₁ d′) = ⊥-elim (whnfRedTerm d′ zeroₙ) whrDetTerm (cast-ℕ-S x x₁) (cast-ℕ-cong x₂ d′) = ⊥-elim (whnfRedTerm d′ sucₙ) whrDetTerm (cast-ℕ-cong x d) (cast-ℕ-0 x₁) = ⊥-elim (whnfRedTerm d zeroₙ) whrDetTerm (cast-ℕ-cong x d) (cast-ℕ-S x₁ x₂) = ⊥-elim (whnfRedTerm d sucₙ) {-# CATCHALL #-} whrDetTerm d (conv d′ x₁) = whrDetTerm d d′ whrDet (univ x) (univ x₁) = whrDetTerm x x₁ whrDet↘Term : ∀{Γ t u A l u′} (d : Γ ⊢ t ↘ u ∷ A ^ l) (d′ : Γ ⊢ t ⇒* u′ ∷ A ^ l) → Γ ⊢ u′ ⇒* u ∷ A ^ l whrDet↘Term (proj₁ , proj₂) (id x) = proj₁ whrDet↘Term (id x , proj₂) (x₁ ⇨ d′) = ⊥-elim (whnfRedTerm x₁ proj₂) whrDet↘Term (x ⇨ proj₁ , proj₂) (x₁ ⇨ d′) = whrDet↘Term (PE.subst (λ x₂ → _ ⊢ x₂ ↘ _ ∷ _ ^ _) (whrDetTerm x x₁) (proj₁ , proj₂)) d′ whrDet*Term : ∀{Γ t u A A' l u′ } (d : Γ ⊢ t ↘ u ∷ A ^ l) (d′ : Γ ⊢ t ↘ u′ ∷ A' ^ l) → u PE.≡ u′ whrDet*Term (id x , proj₂) (id x₁ , proj₄) = PE.refl whrDet*Term (id x , proj₂) (x₁ ⇨ proj₃ , proj₄) = ⊥-elim (whnfRedTerm x₁ proj₂) whrDet*Term (x ⇨ proj₁ , proj₂) (id x₁ , proj₄) = ⊥-elim (whnfRedTerm x proj₄) whrDet*Term (x ⇨ proj₁ , proj₂) (x₁ ⇨ proj₃ , proj₄) = whrDet*Term (proj₁ , proj₂) (PE.subst (λ x₂ → _ ⊢ x₂ ↘ _ ∷ _ ^ _) (whrDetTerm x₁ x) (proj₃ , proj₄)) whrDet* : ∀{Γ A B B′ r r'} (d : Γ ⊢ A ↘ B ^ r) (d′ : Γ ⊢ A ↘ B′ ^ r') → B PE.≡ B′ whrDet* (id x , proj₂) (id x₁ , proj₄) = PE.refl whrDet* (id x , proj₂) (x₁ ⇨ proj₃ , proj₄) = ⊥-elim (whnfRed x₁ proj₂) whrDet* (x ⇨ proj₁ , proj₂) (id x₁ , proj₄) = ⊥-elim (whnfRed x proj₄) whrDet* (A⇒A′ ⇨ A′⇒*B , whnfB) (A⇒A″ ⇨ A″⇒*B′ , whnfB′) = whrDet* (A′⇒*B , whnfB) (PE.subst (λ x → _ ⊢ x ↘ _ ^ _ ) (whrDet A⇒A″ A⇒A′) (A″⇒*B′ , whnfB′)) -- Identity of syntactic reduction idRed:*: : ∀ {Γ A r} → Γ ⊢ A ^ r → Γ ⊢ A :⇒*: A ^ r idRed:*: A = [[ A , A , id A ]] idRedTerm:*: : ∀ {Γ A l t} → Γ ⊢ t ∷ A ^ [ ! , l ] → Γ ⊢ t :⇒*: t ∷ A ^ l idRedTerm:*: t = [[ t , t , id t ]] -- U cannot be a term UnotInA : ∀ {A Γ r r'} → Γ ⊢ (Univ r ¹) ∷ A ^ r' → ⊥ UnotInA (conv U∷U x) = UnotInA U∷U UnotInA[t] : ∀ {A B t a Γ r r' r'' r'''} → t [ a ] PE.≡ (Univ r ¹) → Γ ⊢ a ∷ A ^ r' → Γ ∙ A ^ r'' ⊢ t ∷ B ^ r''' → ⊥ UnotInA[t] () x₁ (univ 0<1 x₂) UnotInA[t] () x₁ (ℕⱼ x₂) UnotInA[t] () x₁ (Emptyⱼ x₂) UnotInA[t] () x₁ (Πⱼ _ ▹ _ ▹ x₂ ▹ x₃) UnotInA[t] x₁ x₂ (var x₃ here) rewrite x₁ = UnotInA x₂ UnotInA[t] () x₂ (var x₃ (there x₄)) UnotInA[t] () x₁ (lamⱼ _ _ x₂ x₃) UnotInA[t] () x₁ (x₂ ∘ⱼ x₃) UnotInA[t] () x₁ (zeroⱼ x₂) UnotInA[t] () x₁ (sucⱼ x₂) UnotInA[t] () x₁ (natrecⱼ x₂ x₃ x₄ x₅) UnotInA[t] () x₁ (Emptyrecⱼ x₂ x₃) UnotInA[t] x x₁ (conv x₂ x₃) = UnotInA[t] x x₁ x₂ redU*Term′ : ∀ {A B U′ l Γ r} → U′ PE.≡ (Univ r ¹) → Γ ⊢ A ⇒ U′ ∷ B ^ l → ⊥ redU*Term′ U′≡U (conv A⇒U x) = redU*Term′ U′≡U A⇒U redU*Term′ () (app-subst A⇒U x) redU*Term′ U′≡U (β-red _ _ x x₁ x₂) = UnotInA[t] U′≡U x₂ x₁ redU*Term′ () (natrec-subst x x₁ x₂ A⇒U) redU*Term′ U′≡U (natrec-zero x x₁ x₂) rewrite U′≡U = UnotInA x₁ redU*Term′ () (natrec-suc x x₁ x₂ x₃) redU*Term : ∀ {A B l Γ r} → Γ ⊢ A ⇒* (Univ r ¹) ∷ B ^ l → ⊥ redU*Term (id x) = UnotInA x redU*Term (x ⇨ A⇒*U) = redU*Term A⇒*U -- Nothing reduces to U redU : ∀ {A Γ r l } → Γ ⊢ A ⇒ (Univ r ¹) ^ [ ! , l ] → ⊥ redU (univ x) = redU*Term′ PE.refl x redU* : ∀ {A Γ r l } → Γ ⊢ A ⇒* (Univ r ¹) ^ [ ! , l ] → A PE.≡ (Univ r ¹) redU* (id x) = PE.refl redU* (x ⇨ A⇒*U) rewrite redU* A⇒*U = ⊥-elim (redU x) -- convertibility for irrelevant terms implies typing typeInversion : ∀ {t u A l Γ} → Γ ⊢ t ≡ u ∷ A ^ [ % , l ] → Γ ⊢ t ∷ A ^ [ % , l ] typeInversion (conv X x) = let d = typeInversion X in conv d x typeInversion (proof-irrelevance x x₁) = x -- general version of reflexivity, symmetry and transitivity genRefl : ∀ {A Γ t r l } → Γ ⊢ t ∷ A ^ [ r , l ] → Γ ⊢ t ≡ t ∷ A ^ [ r , l ] genRefl {r = !} d = refl d genRefl {r = %} d = proof-irrelevance d d -- Judgmental instance of the equality relation genSym : ∀ {k l A Γ r lA } → Γ ⊢ k ≡ l ∷ A ^ [ r , lA ] → Γ ⊢ l ≡ k ∷ A ^ [ r , lA ] genSym {r = !} = sym genSym {r = %} (proof-irrelevance x x₁) = proof-irrelevance x₁ x genSym {r = %} (conv x x₁) = conv (genSym x) x₁ genTrans : ∀ {k l m A r Γ lA } → Γ ⊢ k ≡ l ∷ A ^ [ r , lA ] → Γ ⊢ l ≡ m ∷ A ^ [ r , lA ] → Γ ⊢ k ≡ m ∷ A ^ [ r , lA ] genTrans {r = !} = trans genTrans {r = %} (conv X x) (conv Y x₁) = conv (genTrans X (conv Y (trans x₁ (sym x)))) x genTrans {r = %} (conv X x) (proof-irrelevance x₁ x₂) = proof-irrelevance (conv (typeInversion X) x) x₂ genTrans {r = %} (proof-irrelevance x x₁) (conv Y x₂) = proof-irrelevance x (conv (typeInversion (genSym Y)) x₂) genTrans {r = %} (proof-irrelevance x x₁) (proof-irrelevance x₂ x₃) = proof-irrelevance x x₃ genVar : ∀ {x A Γ r l } → Γ ⊢ var x ∷ A ^ [ r , l ] → Γ ⊢ var x ≡ var x ∷ A ^ [ r , l ] genVar {r = !} = refl genVar {r = %} d = proof-irrelevance d d toLevelInj : ∀ {l₁ l₁′ : TypeLevel} {l<₁ : l₁′ <∞ l₁} {l₂ l₂′ : TypeLevel} {l<₂ : l₂′ <∞ l₂} → toLevel l₁′ PE.≡ toLevel l₂′ → l₁′ PE.≡ l₂′ toLevelInj {.(ι ¹)} {.(ι ⁰)} {emb<} {.(ι ¹)} {.(ι ⁰)} {emb<} e = PE.refl toLevelInj {.∞} {.(ι ¹)} {∞<} {.(ι ¹)} {.(ι ⁰)} {emb<} () toLevelInj {.∞} {.(ι ¹)} {∞<} {.∞} {.(ι ¹)} {∞<} e = PE.refl redSProp′ : ∀ {Γ A B l} (D : Γ ⊢ A ⇒* B ∷ SProp l ^ next l ) → Γ ⊢ A ⇒* B ^ [ % , ι l ] redSProp′ (id x) = id (univ x) redSProp′ (x ⇨ D) = univ x ⇨ redSProp′ D redSProp : ∀ {Γ A B l} (D : Γ ⊢ A :⇒*: B ∷ SProp l ^ next l ) → Γ ⊢ A :⇒*: B ^ [ % , ι l ] redSProp [[ ⊢t , ⊢u , d ]] = [[ (univ ⊢t) , (univ ⊢u) , redSProp′ d ]] un-univ : ∀ {A r Γ l} → Γ ⊢ A ^ [ r , ι l ] → Γ ⊢ A ∷ Univ r l ^ [ ! , next l ] un-univ (univ x) = x un-univ≡ : ∀ {A B r Γ l} → Γ ⊢ A ≡ B ^ [ r , ι l ] → Γ ⊢ A ≡ B ∷ Univ r l ^ [ ! , next l ] un-univ≡ (univ x) = x un-univ≡ (refl x) = refl (un-univ x) un-univ≡ (sym X) = sym (un-univ≡ X) un-univ≡ (trans X Y) = trans (un-univ≡ X) (un-univ≡ Y) univ-gen : ∀ {r Γ l} → (⊢Γ : ⊢ Γ) → Γ ⊢ Univ r l ^ [ ! , next l ] univ-gen {l = ⁰} ⊢Γ = univ (univ 0<1 ⊢Γ ) univ-gen {l = ¹} ⊢Γ = Uⱼ ⊢Γ un-univ⇒ : ∀ {l Γ A B r} → Γ ⊢ A ⇒ B ^ [ r , ι l ] → Γ ⊢ A ⇒ B ∷ Univ r l ^ next l un-univ⇒ (univ x) = x univ⇒* : ∀ {l Γ A B r} → Γ ⊢ A ⇒* B ∷ Univ r l ^ next l → Γ ⊢ A ⇒* B ^ [ r , ι l ] univ⇒* (id x) = id (univ x) univ⇒* (x ⇨ D) = univ x ⇨ univ⇒* D un-univ⇒* : ∀ {l Γ A B r} → Γ ⊢ A ⇒* B ^ [ r , ι l ] → Γ ⊢ A ⇒* B ∷ Univ r l ^ next l un-univ⇒* (id x) = id (un-univ x) un-univ⇒* (x ⇨ D) = un-univ⇒ x ⇨ un-univ⇒* D univ:⇒*: : ∀ {l Γ A B r} → Γ ⊢ A :⇒*: B ∷ Univ r l ^ next l → Γ ⊢ A :⇒*: B ^ [ r , ι l ] univ:⇒*: [[ ⊢A , ⊢B , D ]] = [[ (univ ⊢A) , (univ ⊢B) , (univ⇒* D) ]] un-univ:⇒*: : ∀ {l Γ A B r} → Γ ⊢ A :⇒*: B ^ [ r , ι l ] → Γ ⊢ A :⇒*: B ∷ Univ r l ^ next l un-univ:⇒*: [[ ⊢A , ⊢B , D ]] = [[ (un-univ ⊢A) , (un-univ ⊢B) , (un-univ⇒* D) ]] IdRed*Term′ : ∀ {Γ A B t u l} (⊢t : Γ ⊢ t ∷ A ^ [ ! , ι l ]) (⊢u : Γ ⊢ u ∷ A ^ [ ! , ι l ]) (D : Γ ⊢ A ⇒* B ^ [ ! , ι l ]) → Γ ⊢ Id A t u ⇒* Id B t u ∷ SProp l ^ next l IdRed*Term′ ⊢t ⊢u (id (univ ⊢A)) = id (Idⱼ ⊢A ⊢t ⊢u) IdRed*Term′ ⊢t ⊢u (univ d ⇨ D) = Id-subst d ⊢t ⊢u ⇨ IdRed*Term′ (conv ⊢t (subset (univ d))) (conv ⊢u (subset (univ d))) D IdRed*Term : ∀ {Γ A B t u l} (⊢t : Γ ⊢ t ∷ A ^ [ ! , ι l ]) (⊢u : Γ ⊢ u ∷ A ^ [ ! , ι l ]) (D : Γ ⊢ A :⇒*: B ^ [ ! , ι l ]) → Γ ⊢ Id A t u :⇒*: Id B t u ∷ SProp l ^ next l IdRed*Term {Γ} {A} {B} ⊢t ⊢u [[ univ ⊢A , univ ⊢B , D ]] = [[ Idⱼ ⊢A ⊢t ⊢u , Idⱼ ⊢B (conv ⊢t (subset* D)) (conv ⊢u (subset* D)) , IdRed*Term′ ⊢t ⊢u D ]] IdRed* : ∀ {Γ A B t u l} (⊢t : Γ ⊢ t ∷ A ^ [ ! , ι l ]) (⊢u : Γ ⊢ u ∷ A ^ [ ! , ι l ]) (D : Γ ⊢ A ⇒* B ^ [ ! , ι l ]) → Γ ⊢ Id A t u ⇒* Id B t u ^ [ % , ι l ] IdRed* ⊢t ⊢u (id ⊢A) = id (univ (Idⱼ (un-univ ⊢A) ⊢t ⊢u)) IdRed* ⊢t ⊢u (d ⇨ D) = univ (Id-subst (un-univ⇒ d) ⊢t ⊢u) ⇨ IdRed* (conv ⊢t (subset d)) (conv ⊢u (subset d)) D CastRed*Term′ : ∀ {Γ A B X e t} (⊢X : Γ ⊢ X ^ [ ! , ι ⁰ ]) (⊢e : Γ ⊢ e ∷ Id (U ⁰) A X ^ [ % , next ⁰ ]) (⊢t : Γ ⊢ t ∷ A ^ [ ! , ι ⁰ ]) (D : Γ ⊢ A ⇒* B ^ [ ! , ι ⁰ ]) → Γ ⊢ cast ⁰ A X e t ⇒* cast ⁰ B X e t ∷ X ^ ι ⁰ CastRed*Term′ (univ ⊢X) ⊢e ⊢t (id (univ ⊢A)) = id (castⱼ ⊢A ⊢X ⊢e ⊢t) CastRed*Term′ (univ ⊢X) ⊢e ⊢t (univ d ⇨ D) = cast-subst d ⊢X ⊢e ⊢t ⇨ CastRed*Term′ (univ ⊢X) (conv ⊢e (univ (Id-cong (refl (univ 0<1 (wfTerm ⊢t))) (subsetTerm d) (refl ⊢X)) )) (conv ⊢t (subset (univ d))) D CastRed*Term : ∀ {Γ A B X t e} (⊢X : Γ ⊢ X ^ [ ! , ι ⁰ ]) (⊢e : Γ ⊢ e ∷ Id (U ⁰) A X ^ [ % , next ⁰ ]) (⊢t : Γ ⊢ t ∷ A ^ [ ! , ι ⁰ ]) (D : Γ ⊢ A :⇒*: B ∷ U ⁰ ^ next ⁰) → Γ ⊢ cast ⁰ A X e t :⇒*: cast ⁰ B X e t ∷ X ^ ι ⁰ CastRed*Term {Γ} {A} {B} (univ ⊢X) ⊢e ⊢t [[ ⊢A , ⊢B , D ]] = [[ castⱼ ⊢A ⊢X ⊢e ⊢t , castⱼ ⊢B ⊢X (conv ⊢e (univ (Id-cong (refl (univ 0<1 (wfTerm ⊢t))) (subset*Term D) (refl ⊢X)) )) (conv ⊢t (univ (subset*Term D))) , CastRed*Term′ (univ ⊢X) ⊢e ⊢t (univ* D) ]] CastRed*Termℕ′ : ∀ {Γ A B e t} (⊢e : Γ ⊢ e ∷ Id (U ⁰) ℕ A ^ [ % , next ⁰ ]) (⊢t : Γ ⊢ t ∷ ℕ ^ [ ! , ι ⁰ ]) (D : Γ ⊢ A ⇒* B ^ [ ! , ι ⁰ ]) → Γ ⊢ cast ⁰ ℕ A e t ⇒* cast ⁰ ℕ B e t ∷ A ^ ι ⁰ CastRed*Termℕ′ ⊢e ⊢t (id (univ ⊢A)) = id (castⱼ (ℕⱼ (wfTerm ⊢A)) ⊢A ⊢e ⊢t) CastRed*Termℕ′ ⊢e ⊢t (univ d ⇨ D) = cast-ℕ-subst d ⊢e ⊢t ⇨ conv* (CastRed*Termℕ′ (conv ⊢e (univ (Id-cong (refl (univ 0<1 (wfTerm ⊢e))) (refl (ℕⱼ (wfTerm ⊢e))) (subsetTerm d))) ) ⊢t D) (sym (subset (univ d))) CastRed*Termℕ : ∀ {Γ A B e t} (⊢e : Γ ⊢ e ∷ Id (U ⁰) ℕ A ^ [ % , next ⁰ ]) (⊢t : Γ ⊢ t ∷ ℕ ^ [ ! , ι ⁰ ]) (D : Γ ⊢ A :⇒*: B ^ [ ! , ι ⁰ ]) → Γ ⊢ cast ⁰ ℕ A e t :⇒*: cast ⁰ ℕ B e t ∷ A ^ ι ⁰ CastRed*Termℕ ⊢e ⊢t [[ ⊢A , ⊢B , D ]] = [[ castⱼ (ℕⱼ (wfTerm ⊢e)) (un-univ ⊢A) ⊢e ⊢t , conv (castⱼ (ℕⱼ (wfTerm ⊢e)) (un-univ ⊢B) (conv ⊢e (univ (Id-cong (refl (univ 0<1 (wfTerm ⊢e))) (refl (ℕⱼ (wfTerm ⊢e))) (subset*Term (un-univ⇒* D))))) ⊢t) (sym (subset* D)) , CastRed*Termℕ′ ⊢e ⊢t D ]] CastRed*Termℕℕ′ : ∀ {Γ e t u} (⊢e : Γ ⊢ e ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ]) (⊢t : Γ ⊢ t ⇒* u ∷ ℕ ^ ι ⁰ ) → Γ ⊢ cast ⁰ ℕ ℕ e t ⇒* cast ⁰ ℕ ℕ e u ∷ ℕ ^ ι ⁰ CastRed*Termℕℕ′ ⊢e (id ⊢t) = id (castⱼ (ℕⱼ (wfTerm ⊢e)) (ℕⱼ (wfTerm ⊢e)) ⊢e ⊢t) CastRed*Termℕℕ′ ⊢e (d ⇨ D) = cast-ℕ-cong ⊢e d ⇨ CastRed*Termℕℕ′ ⊢e D CastRed*Termℕℕ : ∀ {Γ e t u} (⊢e : Γ ⊢ e ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ]) (⊢t : Γ ⊢ t :⇒*: u ∷ ℕ ^ ι ⁰ ) → Γ ⊢ cast ⁰ ℕ ℕ e t :⇒*: cast ⁰ ℕ ℕ e u ∷ ℕ ^ ι ⁰ CastRed*Termℕℕ ⊢e [[ ⊢t , ⊢u , D ]] = [[ castⱼ (ℕⱼ (wfTerm ⊢e)) (ℕⱼ (wfTerm ⊢e)) ⊢e ⊢t , castⱼ (ℕⱼ (wfTerm ⊢e)) (ℕⱼ (wfTerm ⊢e)) ⊢e ⊢u , CastRed*Termℕℕ′ ⊢e D ]] CastRed*Termℕsuc : ∀ {Γ e n} (⊢e : Γ ⊢ e ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ]) (⊢n : Γ ⊢ n ∷ ℕ ^ [ ! , ι ⁰ ]) → Γ ⊢ cast ⁰ ℕ ℕ e (suc n) :⇒*: suc (cast ⁰ ℕ ℕ e n) ∷ ℕ ^ ι ⁰ CastRed*Termℕsuc ⊢e ⊢n = [[ castⱼ (ℕⱼ (wfTerm ⊢e)) (ℕⱼ (wfTerm ⊢e)) ⊢e (sucⱼ ⊢n) , sucⱼ (castⱼ (ℕⱼ (wfTerm ⊢e)) (ℕⱼ (wfTerm ⊢e)) ⊢e ⊢n) , cast-ℕ-S ⊢e ⊢n ⇨ id (sucⱼ (castⱼ (ℕⱼ (wfTerm ⊢e)) (ℕⱼ (wfTerm ⊢e)) ⊢e ⊢n)) ]] CastRed*Termℕzero : ∀ {Γ e} (⊢e : Γ ⊢ e ∷ Id (U ⁰) ℕ ℕ ^ [ % , next ⁰ ]) → Γ ⊢ cast ⁰ ℕ ℕ e zero :⇒*: zero ∷ ℕ ^ ι ⁰ CastRed*Termℕzero ⊢e = [[ castⱼ (ℕⱼ (wfTerm ⊢e)) (ℕⱼ (wfTerm ⊢e)) ⊢e (zeroⱼ (wfTerm ⊢e)) , zeroⱼ (wfTerm ⊢e) , cast-ℕ-0 ⊢e ⇨ id (zeroⱼ (wfTerm ⊢e)) ]] CastRed*TermΠ′ : ∀ {Γ F rF G A B e t} (⊢F : Γ ⊢ F ∷ (Univ rF ⁰) ^ [ ! , next ⁰ ]) (⊢G : Γ ∙ F ^ [ rF , ι ⁰ ] ⊢ G ∷ U ⁰ ^ [ ! , next ⁰ ]) (⊢e : Γ ⊢ e ∷ Id (U ⁰) (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) A ^ [ % , next ⁰ ]) (⊢t : Γ ⊢ t ∷ (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) ^ [ ! , ι ⁰ ]) (D : Γ ⊢ A ⇒* B ^ [ ! , ι ⁰ ]) → Γ ⊢ cast ⁰ (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) A e t ⇒* cast ⁰ (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) B e t ∷ A ^ ι ⁰ CastRed*TermΠ′ ⊢F ⊢G ⊢e ⊢t (id (univ ⊢A)) = id (castⱼ (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢F ▹ ⊢G) ⊢A ⊢e ⊢t) CastRed*TermΠ′ ⊢F ⊢G ⊢e ⊢t (univ d ⇨ D) = cast-Π-subst ⊢F ⊢G d ⊢e ⊢t ⇨ conv* (CastRed*TermΠ′ ⊢F ⊢G (conv ⊢e (univ (Id-cong (refl (univ 0<1 (wfTerm ⊢e))) (refl (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢F ▹ ⊢G)) (subsetTerm d))) ) ⊢t D) (sym (subset (univ d))) CastRed*TermΠ : ∀ {Γ F rF G A B e t} (⊢F : Γ ⊢ F ∷ (Univ rF ⁰) ^ [ ! , next ⁰ ]) (⊢G : Γ ∙ F ^ [ rF , ι ⁰ ] ⊢ G ∷ U ⁰ ^ [ ! , next ⁰ ]) (⊢e : Γ ⊢ e ∷ Id (U ⁰) (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) A ^ [ % , next ⁰ ]) (⊢t : Γ ⊢ t ∷ (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) ^ [ ! , ι ⁰ ]) (D : Γ ⊢ A :⇒*: B ^ [ ! , ι ⁰ ]) → Γ ⊢ cast ⁰ (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) A e t :⇒*: cast ⁰ (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) B e t ∷ A ^ ι ⁰ CastRed*TermΠ ⊢F ⊢G ⊢e ⊢t [[ ⊢A , ⊢B , D ]] = let [Π] = Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢F ▹ ⊢G in [[ castⱼ [Π] (un-univ ⊢A) ⊢e ⊢t , conv (castⱼ [Π] (un-univ ⊢B) (conv ⊢e (univ (Id-cong (refl (univ 0<1 (wfTerm ⊢e))) (refl [Π]) (subset*Term (un-univ⇒* D))))) ⊢t) (sym (subset* D)) , CastRed*TermΠ′ ⊢F ⊢G ⊢e ⊢t D ]] IdURed*Term′ : ∀ {Γ t t′ u} (⊢t : Γ ⊢ t ∷ U ⁰ ^ [ ! , ι ¹ ]) (⊢t′ : Γ ⊢ t′ ∷ U ⁰ ^ [ ! , ι ¹ ]) (d : Γ ⊢ t ⇒* t′ ∷ U ⁰ ^ ι ¹) (⊢u : Γ ⊢ u ∷ U ⁰ ^ [ ! , ι ¹ ]) → Γ ⊢ Id (U ⁰) t u ⇒* Id (U ⁰) t′ u ∷ SProp ¹ ^ ∞ IdURed*Term′ ⊢t ⊢t′ (id x) ⊢u = id (Idⱼ (univ 0<1 (wfTerm ⊢t)) ⊢t ⊢u) IdURed*Term′ ⊢t ⊢t′ (x ⇨ d) ⊢u = _⇨_ (Id-U-subst x ⊢u) (IdURed*Term′ (redFirst*Term d) ⊢t′ d ⊢u) IdURed*Term : ∀ {Γ t t′ u} (d : Γ ⊢ t :⇒*: t′ ∷ U ⁰ ^ ι ¹) (⊢u : Γ ⊢ u ∷ U ⁰ ^ [ ! , ι ¹ ]) → Γ ⊢ Id (U ⁰) t u :⇒*: Id (U ⁰) t′ u ∷ SProp ¹ ^ ∞ IdURed*Term [[ ⊢t , ⊢t′ , d ]] ⊢u = [[ Idⱼ (univ 0<1 (wfTerm ⊢u)) ⊢t ⊢u , Idⱼ (univ 0<1 (wfTerm ⊢u)) ⊢t′ ⊢u , IdURed*Term′ ⊢t ⊢t′ d ⊢u ]] IdUΠRed*Term′ : ∀ {Γ F rF G t t′} (⊢F : Γ ⊢ F ∷ Univ rF ⁰ ^ [ ! , ι ¹ ]) (⊢G : Γ ∙ F ^ [ rF , ι ⁰ ] ⊢ G ∷ U ⁰ ^ [ ! , ι ¹ ]) (⊢t : Γ ⊢ t ∷ U ⁰ ^ [ ! , ι ¹ ]) (⊢t′ : Γ ⊢ t′ ∷ U ⁰ ^ [ ! , ι ¹ ]) (d : Γ ⊢ t ⇒* t′ ∷ U ⁰ ^ ι ¹) → Γ ⊢ Id (U ⁰) (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) t ⇒* Id (U ⁰) (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) t′ ∷ SProp ¹ ^ ∞ IdUΠRed*Term′ ⊢F ⊢G ⊢t ⊢t′ (id x) = id (Idⱼ (univ 0<1 (wfTerm ⊢t)) (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢F ▹ ⊢G) ⊢t) IdUΠRed*Term′ ⊢F ⊢G ⊢t ⊢t′ (x ⇨ d) = _⇨_ (Id-U-Π-subst ⊢F ⊢G x) (IdUΠRed*Term′ ⊢F ⊢G (redFirst*Term d) ⊢t′ d) IdUΠRed*Term : ∀ {Γ F rF G t t′} (⊢F : Γ ⊢ F ∷ Univ rF ⁰ ^ [ ! , ι ¹ ]) (⊢G : Γ ∙ F ^ [ rF , ι ⁰ ] ⊢ G ∷ U ⁰ ^ [ ! , ι ¹ ]) (d : Γ ⊢ t :⇒*: t′ ∷ U ⁰ ^ ι ¹) → Γ ⊢ Id (U ⁰) (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) t :⇒*: Id (U ⁰) (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) t′ ∷ SProp ¹ ^ ∞ IdUΠRed*Term ⊢F ⊢G [[ ⊢t , ⊢t′ , d ]] = [[ Idⱼ (univ 0<1 (wfTerm ⊢t)) (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢F ▹ ⊢G) ⊢t , Idⱼ (univ 0<1 (wfTerm ⊢t)) (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ ⊢F ▹ ⊢G) ⊢t′ , IdUΠRed*Term′ ⊢F ⊢G ⊢t ⊢t′ d ]] IdℕRed*Term′ : ∀ {Γ t t′ u} (⊢t : Γ ⊢ t ∷ ℕ ^ [ ! , ι ⁰ ]) (⊢t′ : Γ ⊢ t′ ∷ ℕ ^ [ ! , ι ⁰ ]) (d : Γ ⊢ t ⇒* t′ ∷ ℕ ^ ι ⁰) (⊢u : Γ ⊢ u ∷ ℕ ^ [ ! , ι ⁰ ]) → Γ ⊢ Id ℕ t u ⇒* Id ℕ t′ u ∷ SProp ⁰ ^ next ⁰ IdℕRed*Term′ ⊢t ⊢t′ (id x) ⊢u = id (Idⱼ (ℕⱼ (wfTerm ⊢u)) ⊢t ⊢u) IdℕRed*Term′ ⊢t ⊢t′ (x ⇨ d) ⊢u = _⇨_ (Id-ℕ-subst x ⊢u) (IdℕRed*Term′ (redFirst*Term d) ⊢t′ d ⊢u) Idℕ0Red*Term′ : ∀ {Γ t t′} (⊢t : Γ ⊢ t ∷ ℕ ^ [ ! , ι ⁰ ]) (⊢t′ : Γ ⊢ t′ ∷ ℕ ^ [ ! , ι ⁰ ]) (d : Γ ⊢ t ⇒* t′ ∷ ℕ ^ ι ⁰) → Γ ⊢ Id ℕ zero t ⇒* Id ℕ zero t′ ∷ SProp ⁰ ^ next ⁰ Idℕ0Red*Term′ ⊢t ⊢t′ (id x) = id (Idⱼ (ℕⱼ (wfTerm ⊢t)) (zeroⱼ (wfTerm ⊢t)) ⊢t) Idℕ0Red*Term′ ⊢t ⊢t′ (x ⇨ d) = Id-ℕ-0-subst x ⇨ Idℕ0Red*Term′ (redFirst*Term d) ⊢t′ d IdℕSRed*Term′ : ∀ {Γ t u u′} (⊢t : Γ ⊢ t ∷ ℕ ^ [ ! , ι ⁰ ]) (⊢u : Γ ⊢ u ∷ ℕ ^ [ ! , ι ⁰ ]) (⊢u′ : Γ ⊢ u′ ∷ ℕ ^ [ ! , ι ⁰ ]) (d : Γ ⊢ u ⇒* u′ ∷ ℕ ^ ι ⁰) → Γ ⊢ Id ℕ (suc t) u ⇒* Id ℕ (suc t) u′ ∷ SProp ⁰ ^ next ⁰ IdℕSRed*Term′ ⊢t ⊢u ⊢u′ (id x) = id (Idⱼ (ℕⱼ (wfTerm ⊢t)) (sucⱼ ⊢t) ⊢u) IdℕSRed*Term′ ⊢t ⊢u ⊢u′ (x ⇨ d) = Id-ℕ-S-subst ⊢t x ⇨ IdℕSRed*Term′ ⊢t (redFirst*Term d) ⊢u′ d IdUℕRed*Term′ : ∀ {Γ t t′} (⊢t : Γ ⊢ t ∷ U ⁰ ^ [ ! , ι ¹ ]) (⊢t′ : Γ ⊢ t′ ∷ U ⁰ ^ [ ! , ι ¹ ]) (d : Γ ⊢ t ⇒* t′ ∷ U ⁰ ^ ι ¹) → Γ ⊢ Id (U ⁰) ℕ t ⇒* Id (U ⁰) ℕ t′ ∷ SProp ¹ ^ ∞ IdUℕRed*Term′ ⊢t ⊢t′ (id x) = id (Idⱼ (univ 0<1 (wfTerm ⊢t)) (ℕⱼ (wfTerm ⊢t) ) ⊢t) IdUℕRed*Term′ ⊢t ⊢t′ (x ⇨ d) = _⇨_ (Id-U-ℕ-subst x) (IdUℕRed*Term′ (redFirst*Term d) ⊢t′ d) IdUℕRed*Term : ∀ {Γ t t′} (d : Γ ⊢ t :⇒*: t′ ∷ U ⁰ ^ ι ¹) → Γ ⊢ Id (U ⁰) ℕ t :⇒*: Id (U ⁰) ℕ t′ ∷ SProp ¹ ^ ∞ IdUℕRed*Term [[ ⊢t , ⊢t′ , d ]] = [[ Idⱼ (univ 0<1 (wfTerm ⊢t)) (ℕⱼ (wfTerm ⊢t) ) ⊢t , Idⱼ (univ 0<1 (wfTerm ⊢t)) (ℕⱼ (wfTerm ⊢t) ) ⊢t′ , IdUℕRed*Term′ ⊢t ⊢t′ d ]] appRed* : ∀ {Γ a t u A B rA lA lB l} (⊢a : Γ ⊢ a ∷ A ^ [ rA , ι lA ]) (D : Γ ⊢ t ⇒* u ∷ (Π A ^ rA ° lA ▹ B ° lB ° l) ^ ι l) → Γ ⊢ t ∘ a ^ l ⇒* u ∘ a ^ l ∷ B [ a ] ^ ι lB appRed* ⊢a (id x) = id (x ∘ⱼ ⊢a) appRed* ⊢a (x ⇨ D) = app-subst x ⊢a ⇨ appRed* ⊢a D castΠRed* : ∀ {Γ F rF G A B e t} (⊢F : Γ ⊢ F ^ [ rF , ι ⁰ ]) (⊢G : Γ ∙ F ^ [ rF , ι ⁰ ] ⊢ G ^ [ ! , ι ⁰ ]) (⊢e : Γ ⊢ e ∷ Id (U ⁰) (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) A ^ [ % , next ⁰ ]) (⊢t : Γ ⊢ t ∷ Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]) (D : Γ ⊢ A ⇒* B ^ [ ! , ι ⁰ ]) → Γ ⊢ cast ⁰ (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) A e t ⇒* cast ⁰ (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) B e t ∷ A ^ ι ⁰ castΠRed* ⊢F ⊢G ⊢e ⊢t (id (univ ⊢A)) = id (castⱼ (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ un-univ ⊢F ▹ un-univ ⊢G) ⊢A ⊢e ⊢t) castΠRed* ⊢F ⊢G ⊢e ⊢t ((univ d) ⇨ D) = cast-Π-subst (un-univ ⊢F) (un-univ ⊢G) d ⊢e ⊢t ⇨ conv* (castΠRed* ⊢F ⊢G (conv ⊢e (univ (Id-cong (refl (univ 0<1 (wf ⊢F))) (refl (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ un-univ ⊢F ▹ un-univ ⊢G)) (subsetTerm d)))) ⊢t D) (sym (subset (univ d))) notredUterm* : ∀ {Γ r l l' A B} → Γ ⊢ Univ r l ⇒ A ∷ B ^ l' → ⊥ notredUterm* (conv D x) = notredUterm* D notredU* : ∀ {Γ r l l' A} → Γ ⊢ Univ r l ⇒ A ^ [ ! , l' ] → ⊥ notredU* (univ x) = notredUterm* x redU*gen : ∀ {Γ r l r' l' l''} → Γ ⊢ Univ r l ⇒* Univ r' l' ^ [ ! , l'' ] → Univ r l PE.≡ Univ r' l' redU*gen (id x) = PE.refl redU*gen (univ (conv x x₁) ⇨ D) = ⊥-elim (notredUterm* x) -- Typing of Idsym Idsymⱼ : ∀ {Γ A l x y e} → Γ ⊢ A ∷ U l ^ [ ! , next l ] → Γ ⊢ x ∷ A ^ [ ! , ι l ] → Γ ⊢ y ∷ A ^ [ ! , ι l ] → Γ ⊢ e ∷ Id A x y ^ [ % , ι l ] → Γ ⊢ Idsym A x y e ∷ Id A y x ^ [ % , ι l ] Idsymⱼ {Γ} {A} {l} {x} {y} {e} ⊢A ⊢x ⊢y ⊢e = let ⊢Γ = wfTerm ⊢A ⊢A = univ ⊢A ⊢P : Γ ∙ A ^ [ ! , ι l ] ⊢ Id (wk1 A) (var 0) (wk1 x) ^ [ % , ι l ] ⊢P = univ (Idⱼ (Twk.wkTerm (Twk.step Twk.id) (⊢Γ ∙ ⊢A) (un-univ ⊢A)) (var (⊢Γ ∙ ⊢A) here) (Twk.wkTerm (Twk.step Twk.id) (⊢Γ ∙ ⊢A) ⊢x)) ⊢refl : Γ ⊢ Idrefl A x ∷ Id (wk1 A) (var 0) (wk1 x) [ x ] ^ [ % , ι l ] ⊢refl = PE.subst₂ (λ X Y → Γ ⊢ Idrefl A x ∷ Id X x Y ^ [ % , ι l ]) (PE.sym (wk1-singleSubst A x)) (PE.sym (wk1-singleSubst x x)) (Idreflⱼ ⊢x) in PE.subst₂ (λ X Y → Γ ⊢ Idsym A x y e ∷ Id X y Y ^ [ % , ι l ]) (wk1-singleSubst A y) (wk1-singleSubst x y) (transpⱼ ⊢A ⊢P ⊢x ⊢refl ⊢y ⊢e) ▹▹ⱼ_▹_▹_▹_ : ∀ {Γ F rF lF G lG r l} → lF ≤ l → lG ≤ l → Γ ⊢ F ∷ (Univ rF lF) ^ [ ! , next lF ] → Γ ⊢ G ∷ (Univ r lG) ^ [ ! , next lG ] → Γ ⊢ F ^ rF ° lF ▹▹ G ° lG ° l ∷ (Univ r l) ^ [ ! , next l ] ▹▹ⱼ lF≤ ▹ lG≤ ▹ F ▹ G = Πⱼ lF≤ ▹ lG≤ ▹ F ▹ un-univ (Twk.wk (Twk.step Twk.id) ((wf (univ F)) ∙ (univ F)) (univ G)) ××ⱼ_▹_ : ∀ {Γ F G l} → Γ ⊢ F ∷ SProp l ^ [ ! , next l ] → Γ ⊢ G ∷ SProp l ^ [ ! , next l ] → Γ ⊢ F ×× G ∷ SProp l ^ [ ! , next l ] ××ⱼ F ▹ G = ∃ⱼ F ▹ un-univ (Twk.wk (Twk.step Twk.id) ((wf (univ F)) ∙ (univ F)) (univ G))
{ "alphanum_fraction": 0.5354363371, "avg_line_length": 51.9241025641, "ext": "agda", "hexsha": "eeb89c57be3ffa5a777055bfafcaea9f8a76daae", "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/Typed/Properties.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/Typed/Properties.agda", "max_line_length": 274, "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/Typed/Properties.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": 27829, "size": 50626 }
{-# OPTIONS --cubical --safe #-} module Data.Nat.Properties where open import Data.Nat.Base open import Agda.Builtin.Nat using () renaming (_<_ to _<ᴮ_; _==_ to _≡ᴮ_) public open import Prelude open import Cubical.Data.Nat using (caseNat; injSuc) public open import Data.Nat.DivMod mutual _-1⊔_ : ℕ → ℕ → ℕ zero -1⊔ n = n suc m -1⊔ n = n ⊔ m _⊔_ : ℕ → ℕ → ℕ zero ⊔ m = m suc n ⊔ m = suc (m -1⊔ n) znots : ∀ {n} → zero ≢ suc n znots z≡s = subst (caseNat ⊤ ⊥) z≡s tt snotz : ∀ {n} → suc n ≢ zero snotz s≡z = subst (caseNat ⊥ ⊤) s≡z tt pred : ℕ → ℕ pred (suc n) = n pred zero = zero sound-== : ∀ n m → T (n ≡ᴮ m) → n ≡ m sound-== zero zero p i = zero sound-== (suc n) (suc m) p i = suc (sound-== n m p i) complete-== : ∀ n → T (n ≡ᴮ n) complete-== zero = tt complete-== (suc n) = complete-== n open import Relation.Nullary.Discrete.FromBoolean discreteℕ : Discrete ℕ discreteℕ = from-bool-eq _≡ᴮ_ sound-== complete-== isSetℕ : isSet ℕ isSetℕ = Discrete→isSet discreteℕ +-suc : ∀ x y → x + suc y ≡ suc (x + y) +-suc zero y = refl +-suc (suc x) y = cong suc (+-suc x y) +-idʳ : ∀ x → x + 0 ≡ x +-idʳ zero = refl +-idʳ (suc x) = cong suc (+-idʳ x) +-comm : ∀ x y → x + y ≡ y + x +-comm x zero = +-idʳ x +-comm x (suc y) = +-suc x y ; cong suc (+-comm x y) infix 4 _<_ _<_ : ℕ → ℕ → Type n < m = T (n <ᴮ m) infix 4 _≤ᴮ_ _≤ᴮ_ : ℕ → ℕ → Bool n ≤ᴮ m = not (m <ᴮ n) infix 4 _≤_ _≤_ : ℕ → ℕ → Type n ≤ m = T (n ≤ᴮ m) infix 4 _≥ᴮ_ _≥ᴮ_ : ℕ → ℕ → Bool _≥ᴮ_ = flip _≤ᴮ_ +-assoc : ∀ x y z → (x + y) + z ≡ x + (y + z) +-assoc zero y z i = y + z +-assoc (suc x) y z i = suc (+-assoc x y z i) +-*-distrib : ∀ x y z → (x + y) * z ≡ x * z + y * z +-*-distrib zero y z = refl +-*-distrib (suc x) y z = cong (z +_) (+-*-distrib x y z) ; sym (+-assoc z (x * z) (y * z)) *-zeroʳ : ∀ x → x * zero ≡ zero *-zeroʳ zero = refl *-zeroʳ (suc x) = *-zeroʳ x *-suc : ∀ x y → x + x * y ≡ x * suc y *-suc zero y = refl *-suc (suc x) y = cong suc (sym (+-assoc x y (x * y)) ; cong (_+ x * y) (+-comm x y) ; +-assoc y x (x * y) ; cong (y +_) (*-suc x y)) *-comm : ∀ x y → x * y ≡ y * x *-comm zero y = sym (*-zeroʳ y) *-comm (suc x) y = cong (y +_) (*-comm x y) ; *-suc y x *-assoc : ∀ x y z → (x * y) * z ≡ x * (y * z) *-assoc zero y z = refl *-assoc (suc x) y z = +-*-distrib y (x * y) z ; cong (y * z +_) (*-assoc x y z) open import Data.Nat.DivMod open import Agda.Builtin.Nat using (div-helper) div-helper′ : (m n j : ℕ) → ℕ div-helper′ m zero j = zero div-helper′ m (suc n) zero = suc (div-helper′ m n m) div-helper′ m (suc n) (suc j) = div-helper′ m n j div-helper-lemma : ∀ k m n j → div-helper k m n j ≡ k + div-helper′ m n j div-helper-lemma k m zero j = sym (+-idʳ k) div-helper-lemma k m (suc n) zero = div-helper-lemma (suc k) m n m ; sym (+-suc k (div-helper′ m n m)) div-helper-lemma k m (suc n) (suc j) = div-helper-lemma k m n j Even : ℕ → Type Even n = T (even n) odd : ℕ → Bool odd n = not (rem n 2 ≡ᴮ 0) Odd : ℕ → Type Odd n = T (odd n) s≤s : ∀ n m → n ≤ m → suc n ≤ suc m s≤s zero m p = tt s≤s (suc n) m p = p n≤s : ∀ n m → n ≤ m → n ≤ suc m n≤s zero m p = tt n≤s (suc zero) m p = tt n≤s (suc (suc n)) zero p = p n≤s (suc (suc n₁)) (suc n) p = n≤s (suc n₁) n p div-≤ : ∀ n m → n ÷ suc m ≤ n div-≤ n m = subst (_≤ n) (sym (div-helper-lemma 0 m n m)) (go m n m) where go : ∀ m n j → div-helper′ m n j ≤ n go m zero j = tt go m (suc n) zero = s≤s (div-helper′ m n m) n (go m n m) go m (suc n) (suc j) = n≤s (div-helper′ m n j) n (go m n j) ≤-trans : ∀ x y z → x ≤ y → y ≤ z → x ≤ z ≤-trans zero y z p q = tt ≤-trans (suc n) zero zero p q = p ≤-trans (suc zero) zero (suc n) p q = tt ≤-trans (suc (suc n₁)) zero (suc n) p q = ≤-trans (suc n₁) zero n p tt ≤-trans (suc n) (suc zero) zero p q = q ≤-trans (suc zero) (suc zero) (suc n) p q = tt ≤-trans (suc (suc n₁)) (suc zero) (suc n) p q = ≤-trans (suc n₁) zero n p tt ≤-trans (suc n₁) (suc (suc n)) zero p q = q ≤-trans (suc zero) (suc (suc n₁)) (suc n) p q = tt ≤-trans (suc (suc n₁)) (suc (suc n₂)) (suc n) p q = ≤-trans (suc n₁) (suc n₂) n p q p≤n : ∀ n m → suc n ≤ m → n ≤ m p≤n zero m p = tt p≤n (suc n) zero p = p p≤n (suc zero) (suc n) p = tt p≤n (suc (suc n₁)) (suc n) p = p≤n (suc n₁) n p p≤p : ∀ n m → suc n ≤ suc m → n ≤ m p≤p zero m p = tt p≤p (suc n) m p = p ≤-refl : ∀ n → n ≤ n ≤-refl zero = tt ≤-refl (suc zero) = tt ≤-refl (suc (suc n)) = ≤-refl (suc n) linearise : ∀ n m → n ≡ m → n ≡ m linearise n m n≡m with discreteℕ n m ... | yes p = p ... | no ¬p = ⊥-elim (¬p n≡m)
{ "alphanum_fraction": 0.526362428, "avg_line_length": 26.7100591716, "ext": "agda", "hexsha": "ae0c435a0ee9203e7c736708cc2505b597b8c6b6", "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/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "oisdk/agda-playground", "max_issues_repo_path": "Data/Nat/Properties.agda", "max_line_length": 133, "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/Properties.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z", "max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z", "num_tokens": 2192, "size": 4514 }
------------------------------------------------------------------------ -- Paths and extensionality ------------------------------------------------------------------------ {-# OPTIONS --erased-cubical --safe #-} module Equality.Path where import Bijection open import Equality hiding (module Derived-definitions-and-properties) open import Equality.Instances-related import Equivalence import Equivalence.Contractible-preimages import Equivalence.Half-adjoint import Function-universe import H-level import H-level.Closure open import Logical-equivalence using (_⇔_) import Preimage open import Prelude import Univalence-axiom ------------------------------------------------------------------------ -- The interval open import Agda.Primitive.Cubical public using (I; Partial; PartialP) renaming (i0 to 0̲; i1 to 1̲; IsOne to Is-one; itIsOne to is-one; primINeg to -_; primIMin to min; primIMax to max; primComp to comp; primHComp to hcomp; primTransp to transport) open import Agda.Builtin.Cubical.Sub public renaming (Sub to _[_↦_]; inc to inˢ; primSubOut to outˢ) ------------------------------------------------------------------------ -- Some local generalisable variables private variable a b c p q ℓ : Level A : Type a B : A → Type b P : I → Type p u v w x y z : A f g h : (x : A) → B x i j : I n : ℕ ------------------------------------------------------------------------ -- Equality -- Homogeneous and heterogeneous equality. open import Agda.Builtin.Cubical.Path public using (_≡_) renaming (PathP to infix 4 [_]_≡_) ------------------------------------------------------------------------ -- Filling -- The code in this section is based on code in the cubical library -- written by Anders Mörtberg. -- Filling for homogenous composition. hfill : {φ : I} (u : I → Partial φ A) (u₀ : A [ φ ↦ u 0̲ ]) → outˢ u₀ ≡ hcomp u (outˢ u₀) hfill {φ = φ} u u₀ = λ i → hcomp (λ j → λ { (φ = 1̲) → u (min i j) is-one ; (i = 0̲) → outˢ u₀ }) (outˢ u₀) -- Filling for heterogeneous composition. -- -- Note that if p had been a constant level, then the final line of -- the type signature could have been replaced by -- [ P ] outˢ u₀ ≡ comp P u u₀. fill : {p : I → Level} (P : ∀ i → Type (p i)) {φ : I} (u : ∀ i → Partial φ (P i)) (u₀ : P 0̲ [ φ ↦ u 0̲ ]) → ∀ i → P i fill P {φ} u u₀ i = comp (λ j → P (min i j)) (λ j → λ { (φ = 1̲) → u (min i j) is-one ; (i = 0̲) → outˢ u₀ }) (outˢ u₀) -- Filling for transport. transport-fill : (A : Type ℓ) (φ : I) (P : (i : I) → Type ℓ [ φ ↦ (λ _ → A) ]) (u₀ : outˢ (P 0̲)) → [ (λ i → outˢ (P i)) ] u₀ ≡ transport (λ i → outˢ (P i)) φ u₀ transport-fill _ φ P u₀ i = transport (λ j → outˢ (P (min i j))) (max (- i) φ) u₀ ------------------------------------------------------------------------ -- Path equality satisfies the axioms of Equality-with-J -- Reflexivity. refl : {@0 A : Type a} {x : A} → x ≡ x refl {x = x} = λ _ → x -- A family of instantiations of Reflexive-relation. reflexive-relation : ∀ ℓ → Reflexive-relation ℓ Reflexive-relation._≡_ (reflexive-relation _) = _≡_ Reflexive-relation.refl (reflexive-relation _) = λ _ → refl -- Symmetry. hsym : [ P ] x ≡ y → [ (λ i → P (- i)) ] y ≡ x hsym x≡y = λ i → x≡y (- i) -- Transitivity. -- -- The proof htransʳ-reflʳ is based on code in Agda's reference manual -- written by Anders Mörtberg. -- -- The proof htrans is suggested in the HoTT book (first version, -- Exercise 6.1). htransʳ : [ P ] x ≡ y → y ≡ z → [ P ] x ≡ z htransʳ {x = x} x≡y y≡z = λ i → hcomp (λ { _ (i = 0̲) → x ; j (i = 1̲) → y≡z j }) (x≡y i) htransˡ : x ≡ y → [ P ] y ≡ z → [ P ] x ≡ z htransˡ x≡y y≡z = hsym (htransʳ (hsym y≡z) (hsym x≡y)) htransʳ-reflʳ : (x≡y : [ P ] x ≡ y) → htransʳ x≡y refl ≡ x≡y htransʳ-reflʳ {x = x} {y = y} x≡y = λ i j → hfill (λ { _ (j = 0̲) → x ; _ (j = 1̲) → y }) (inˢ (x≡y j)) (- i) htransˡ-reflˡ : (x≡y : [ P ] x ≡ y) → htransˡ refl x≡y ≡ x≡y htransˡ-reflˡ = htransʳ-reflʳ htrans : {x≡y : x ≡ y} {y≡z : y ≡ z} (P : A → Type p) {p : P x} {q : P y} {r : P z} → [ (λ i → P (x≡y i)) ] p ≡ q → [ (λ i → P (y≡z i)) ] q ≡ r → [ (λ i → P (htransˡ x≡y y≡z i)) ] p ≡ r htrans {z = z} {x≡y = x≡y} {y≡z = y≡z} P {r = r} p≡q q≡r = λ i → comp (λ j → P (eq j i)) (λ { j (i = 0̲) → p≡q (- j) ; j (i = 1̲) → r }) (q≡r i) where eq : [ (λ i → x≡y (- i) ≡ z) ] y≡z ≡ htransˡ x≡y y≡z eq = λ i j → hfill (λ { i (j = 0̲) → x≡y (- i) ; _ (j = 1̲) → z }) (inˢ (y≡z j)) i -- Some equational reasoning combinators. infix -1 finally finally-h infixr -2 step-≡ step-≡h step-≡hh _≡⟨⟩_ step-≡ : ∀ x → [ P ] y ≡ z → x ≡ y → [ P ] x ≡ z step-≡ _ = flip htransˡ syntax step-≡ x y≡z x≡y = x ≡⟨ x≡y ⟩ y≡z step-≡h : ∀ x → y ≡ z → [ P ] x ≡ y → [ P ] x ≡ z step-≡h _ = flip htransʳ syntax step-≡h x y≡z x≡y = x ≡⟨ x≡y ⟩h y≡z step-≡hh : {x≡y : x ≡ y} {y≡z : y ≡ z} (P : A → Type p) (p : P x) {q : P y} {r : P z} → [ (λ i → P (y≡z i)) ] q ≡ r → [ (λ i → P (x≡y i)) ] p ≡ q → [ (λ i → P (htransˡ x≡y y≡z i)) ] p ≡ r step-≡hh P _ = flip (htrans P) syntax step-≡hh P p q≡r p≡q = p ≡⟨ p≡q ⟩[ P ] q≡r _≡⟨⟩_ : ∀ x → [ P ] x ≡ y → [ P ] x ≡ y _ ≡⟨⟩ x≡y = x≡y finally : (x y : A) → x ≡ y → x ≡ y finally _ _ x≡y = x≡y syntax finally x y x≡y = x ≡⟨ x≡y ⟩∎ y ∎ finally-h : ∀ x y → [ P ] x ≡ y → [ P ] x ≡ y finally-h _ _ x≡y = x≡y syntax finally-h x y x≡y = x ≡⟨ x≡y ⟩∎h y ∎ -- The J rule. elim : (P : {x y : A} → x ≡ y → Type p) → (∀ x → P (refl {x = x})) → (x≡y : x ≡ y) → P x≡y elim {x = x} P p x≡y = transport (λ i → P (λ j → x≡y (min i j))) 0̲ (p x) -- Substitutivity. hsubst : ∀ (Q : ∀ {i} → P i → Type q) → [ P ] x ≡ y → Q x → Q y hsubst Q x≡y p = transport (λ i → Q (x≡y i)) 0̲ p subst : (P : A → Type p) → x ≡ y → P x → P y subst P = hsubst P -- Congruence. -- -- The heterogeneous variant is based on code in the cubical library -- written by Anders Mörtberg. hcong : (f : (x : A) → B x) (x≡y : x ≡ y) → [ (λ i → B (x≡y i)) ] f x ≡ f y hcong f x≡y = λ i → f (x≡y i) cong : {B : Type b} (f : A → B) → x ≡ y → f x ≡ f y cong f = hcong f dcong : (f : (x : A) → B x) (x≡y : x ≡ y) → subst B x≡y (f x) ≡ f y dcong {B = B} f x≡y = λ i → transport (λ j → B (x≡y (max i j))) i (f (x≡y i)) -- Transporting along reflexivity amounts to doing nothing. -- -- This definition is based on code in Agda's reference manual written -- by Anders Mörtberg. transport-refl : ∀ i → transport (λ i → refl {x = A} i) i ≡ id transport-refl {A = A} i = λ j → transport (λ _ → A) (max i j) -- A family of instantiations of Equivalence-relation⁺. -- -- Note that htransˡ is used to implement trans. The reason htransˡ is -- used, rather than htransʳ, is that htransˡ is also used to -- implement the commonly used equational reasoning combinator step-≡, -- and I'd like this combinator to match trans. equivalence-relation⁺ : ∀ ℓ → Equivalence-relation⁺ ℓ equivalence-relation⁺ _ = λ where .Equivalence-relation⁺.reflexive-relation → reflexive-relation _ .Equivalence-relation⁺.sym → hsym .Equivalence-relation⁺.sym-refl → refl .Equivalence-relation⁺.trans → htransˡ .Equivalence-relation⁺.trans-refl-refl → htransˡ-reflˡ _ -- A family of instantiations of Equality-with-J₀. equality-with-J₀ : Equality-with-J₀ a p reflexive-relation Equality-with-J₀.elim equality-with-J₀ = elim Equality-with-J₀.elim-refl equality-with-J₀ = λ _ r → cong (_$ r _) $ transport-refl 0̲ private module Temporarily-local where -- A family of instantiations of Equality-with-J. equality-with-J : Equality-with-J a p equivalence-relation⁺ equality-with-J = λ where .Equality-with-J.equality-with-J₀ → equality-with-J₀ .Equality-with-J.cong → cong .Equality-with-J.cong-refl → λ _ → refl .Equality-with-J.subst → subst .Equality-with-J.subst-refl → λ _ p → cong (_$ p) $ transport-refl 0̲ .Equality-with-J.dcong → dcong .Equality-with-J.dcong-refl → λ _ → refl -- Various derived definitions and properties. open Equality.Derived-definitions-and-properties Temporarily-local.equality-with-J public hiding (_≡_; refl; elim; subst; cong; dcong; step-≡; _≡⟨⟩_; finally; reflexive-relation; equality-with-J₀) ------------------------------------------------------------------------ -- An extended variant of Equality-with-J -- The following variant of Equality-with-J includes functions mapping -- equalities to and from paths. The purpose of this definition is to -- make it possible to instantiate these functions with identity -- functions when paths are used as equalities (see -- equality-with-paths below). record Equality-with-paths a b (e⁺ : ∀ ℓ → Equivalence-relation⁺ ℓ) : Type (lsuc (a ⊔ b)) where field equality-with-J : Equality-with-J a b e⁺ private module R = Reflexive-relation (Equivalence-relation⁺.reflexive-relation (e⁺ a)) field -- A bijection between equality at level a and paths. to-path : x R.≡ y → x ≡ y from-path : x ≡ y → x R.≡ y to-path∘from-path : (x≡y : x ≡ y) → to-path (from-path x≡y) R.≡ x≡y from-path∘to-path : (x≡y : x R.≡ y) → from-path (to-path x≡y) R.≡ x≡y -- The bijection maps reflexivity to reflexivity. to-path-refl : to-path (R.refl x) R.≡ refl from-path-refl : from-path refl R.≡ R.refl x -- A family of instantiations of Equality-with-paths. equality-with-paths : Equality-with-paths a p equivalence-relation⁺ equality-with-paths = λ where .E.equality-with-J → Temporarily-local.equality-with-J .E.to-path → id .E.from-path → id .E.to-path∘from-path → λ _ → refl .E.from-path∘to-path → λ _ → refl .E.to-path-refl → refl .E.from-path-refl → refl where module E = Equality-with-paths -- Equality-with-paths (for arbitrary universe levels) can be derived -- from Equality-with-J (for arbitrary universe levels). Equality-with-J⇒Equality-with-paths : ∀ {e⁺} → (∀ {a p} → Equality-with-J a p e⁺) → (∀ {a p} → Equality-with-paths a p e⁺) Equality-with-J⇒Equality-with-paths eq = λ where .E.equality-with-J → eq .E.to-path → B._↔_.to (proj₁ ≡↔≡′) .E.from-path → B._↔_.from (proj₁ ≡↔≡′) .E.to-path∘from-path → B._↔_.right-inverse-of (proj₁ ≡↔≡′) .E.from-path∘to-path → B._↔_.left-inverse-of (proj₁ ≡↔≡′) .E.to-path-refl → B._↔_.from (proj₁ ≡↔≡′) (proj₁ (proj₂ ≡↔≡′)) .E.from-path-refl → proj₂ (proj₂ ≡↔≡′) where module E = Equality-with-paths module B = Bijection eq ≡↔≡′ = all-equality-types-isomorphic eq Temporarily-local.equality-with-J -- Equality-with-paths (for arbitrary universe levels) can be derived -- from Equality-with-J₀ (for arbitrary universe levels). Equality-with-J₀⇒Equality-with-paths : ∀ {reflexive} → (eq : ∀ {a p} → Equality-with-J₀ a p reflexive) → ∀ {a p} → Equality-with-paths a p (λ _ → J₀⇒Equivalence-relation⁺ eq) Equality-with-J₀⇒Equality-with-paths eq = Equality-with-J⇒Equality-with-paths (J₀⇒J eq) module Derived-definitions-and-properties {e⁺} (equality-with-paths : ∀ {a p} → Equality-with-paths a p e⁺) where private module EP {a} {p} = Equality-with-paths (equality-with-paths {a = a} {p = p}) open EP public using (equality-with-J) private module E = Equality.Derived-definitions-and-properties equality-with-J open Bijection equality-with-J ≡↔≡ : {A : Type a} {x y : A} → x E.≡ y ↔ x ≡ y ≡↔≡ {a = a} = record { surjection = record { logical-equivalence = record { to = EP.to-path {p = a} ; from = EP.from-path } ; right-inverse-of = EP.to-path∘from-path } ; left-inverse-of = EP.from-path∘to-path } -- The isomorphism maps reflexivity to reflexivity. to-≡↔≡-refl : _↔_.to ≡↔≡ (E.refl x) E.≡ refl to-≡↔≡-refl = EP.to-path-refl from-≡↔≡-refl : _↔_.from ≡↔≡ refl E.≡ E.refl x from-≡↔≡-refl = EP.from-path-refl open E public open Temporarily-local public ------------------------------------------------------------------------ -- Extensionality open Equivalence equality-with-J using (Is-equivalence) open H-level.Closure equality-with-J using (ext⁻¹) -- Extensionality. ext : Extensionality a b apply-ext ext f≡g = λ i x → f≡g x i ⟨ext⟩ : Extensionality′ A B ⟨ext⟩ = apply-ext ext -- The function ⟨ext⟩ is an equivalence. ext-is-equivalence : Is-equivalence {A = ∀ x → f x ≡ g x} ⟨ext⟩ ext-is-equivalence = ext⁻¹ , (λ _ → refl) , (λ _ → refl) , (λ _ → refl) private -- Equality rearrangement lemmas for ⟨ext⟩. All of these lemmas hold -- definitionally. ext-refl : ⟨ext⟩ (λ x → refl {x = f x}) ≡ refl ext-refl = refl ext-const : (x≡y : x ≡ y) → ⟨ext⟩ (const {B = A} x≡y) ≡ cong const x≡y ext-const _ = refl cong-ext : (f≡g : ∀ x → f x ≡ g x) → cong (_$ x) (⟨ext⟩ f≡g) ≡ f≡g x cong-ext _ = refl subst-ext : ∀ {p} (f≡g : ∀ x → f x ≡ g x) → subst (λ f → B (f x)) (⟨ext⟩ f≡g) p ≡ subst B (f≡g x) p subst-ext _ = refl elim-ext : {f g : (x : A) → B x} (P : B x → B x → Type p) (p : (y : B x) → P y y) (f≡g : ∀ x → f x ≡ g x) → elim (λ {f g} _ → P (f x) (g x)) (p ∘ (_$ x)) (⟨ext⟩ f≡g) ≡ elim (λ {x y} _ → P x y) p (f≡g x) elim-ext _ _ _ = refl -- I based the statements of the following three lemmas on code in -- the Lean Homotopy Type Theory Library with Jakob von Raumer and -- Floris van Doorn listed as authors. The file was claimed to have -- been ported from the Coq HoTT library. (The third lemma has later -- been generalised.) ext-sym : (f≡g : ∀ x → f x ≡ g x) → ⟨ext⟩ (sym ∘ f≡g) ≡ sym (⟨ext⟩ f≡g) ext-sym _ = refl ext-trans : (f≡g : ∀ x → f x ≡ g x) (g≡h : ∀ x → g x ≡ h x) → ⟨ext⟩ (λ x → trans (f≡g x) (g≡h x)) ≡ trans (⟨ext⟩ f≡g) (⟨ext⟩ g≡h) ext-trans _ _ = refl cong-post-∘-ext : {B : A → Type b} {C : A → Type c} {f g : (x : A) → B x} {h : ∀ {x} → B x → C x} (f≡g : ∀ x → f x ≡ g x) → cong (h ∘_) (⟨ext⟩ f≡g) ≡ ⟨ext⟩ (cong h ∘ f≡g) cong-post-∘-ext _ = refl cong-pre-∘-ext : {B : Type b} {C : B → Type c} {f g : (x : B) → C x} {h : A → B} (f≡g : ∀ x → f x ≡ g x) → cong (_∘ h) (⟨ext⟩ f≡g) ≡ ⟨ext⟩ (f≡g ∘ h) cong-pre-∘-ext _ = refl ------------------------------------------------------------------------ -- Some properties open Bijection equality-with-J using (_↔_) open Function-universe equality-with-J hiding (id; _∘_) open H-level equality-with-J open Univalence-axiom equality-with-J -- There is a dependent path from reflexivity for x to any dependent -- path starting in x. refl≡ : (x≡y : [ P ] x ≡ y) → [ (λ i → [ (λ j → P (min i j)) ] x ≡ x≡y i) ] refl {x = x} ≡ x≡y refl≡ x≡y = λ i j → x≡y (min i j) -- Transporting in one direction and then back amounts to doing -- nothing. transport∘transport : ∀ {p : I → Level} (P : ∀ i → Type (p i)) {p} → transport (λ i → P (- i)) 0̲ (transport P 0̲ p) ≡ p transport∘transport P {p} = hsym λ i → comp (λ j → P (min i (- j))) (λ j → λ { (i = 0̲) → p ; (i = 1̲) → transport (λ k → P (- min j k)) (- j) (transport P 0̲ p) }) (transport (λ j → P (min i j)) (- i) p) -- One form of transporting can be expressed using trans and sym. transport-≡ : {p : x ≡ y} {q : u ≡ v} (r : x ≡ u) → transport (λ i → p i ≡ q i) 0̲ r ≡ trans (sym p) (trans r q) transport-≡ {x = x} {p = p} {q = q} r = elim¹ (λ p → transport (λ i → p i ≡ q i) 0̲ r ≡ trans (sym p) (trans r q)) (transport (λ i → x ≡ q i) 0̲ r ≡⟨⟩ subst (x ≡_) q r ≡⟨ sym trans-subst ⟩ trans r q ≡⟨ sym $ trans-reflˡ _ ⟩ trans refl (trans r q) ≡⟨⟩ trans (sym refl) (trans r q) ∎) p -- The function htrans {x≡y = x≡y} {y≡z = y≡z} (const A) is pointwise -- equal to trans. -- -- Andrea Vezzosi helped me with this proof. htrans-const : (x≡y : x ≡ y) (y≡z : y ≡ z) (p : u ≡ v) {q : v ≡ w} → htrans {x≡y = x≡y} {y≡z = y≡z} (const A) p q ≡ trans p q htrans-const {A = A} {w = w} _ _ p {q = q} = (λ i → comp (λ _ → A) (s i) (q i)) ≡⟨⟩ (λ i → hcomp (λ j x → transport (λ _ → A) j (s i j x)) (transport (λ _ → A) 0̲ (q i))) ≡⟨ (λ k i → hcomp (λ j x → cong (_$ s i j x) (transport-refl j) k) (cong (_$ q i) (transport-refl 0̲) k)) ⟩∎ (λ i → hcomp (s i) (q i)) ∎ where s : ∀ i j → Partial (max i (- i)) A s i = λ where j (i = 0̲) → p (- j) _ (i = 1̲) → w -- The following two lemmas are due to Anders Mörtberg. -- -- Previously Andrea Vezzosi and I had each proved the second lemma in -- much more convoluted ways (starting from a logical equivalence -- proved by Anders; I had also gotten some useful hints from Andrea -- for my proof). -- Heterogeneous equality can be expressed in terms of homogeneous -- equality. heterogeneous≡homogeneous : {P : I → Type p} {p : P 0̲} {q : P 1̲} → ([ P ] p ≡ q) ≡ (transport P 0̲ p ≡ q) heterogeneous≡homogeneous {P = P} {p = p} {q = q} = λ i → [ (λ j → P (max i j)) ] transport (λ j → P (min i j)) (- i) p ≡ q -- A variant of the previous lemma. heterogeneous↔homogeneous : (P : I → Type p) {p : P 0̲} {q : P 1̲} → ([ P ] p ≡ q) ↔ transport P 0̲ p ≡ q heterogeneous↔homogeneous P = subst ([ P ] _ ≡ _ ↔_) heterogeneous≡homogeneous (Bijection.id equality-with-J) -- The function dcong is pointwise equal to an expression involving -- hcong. dcong≡hcong : {B : A → Type b} {x≡y : x ≡ y} (f : (x : A) → B x) → dcong f x≡y ≡ _↔_.to (heterogeneous↔homogeneous (λ i → B (x≡y i))) (hcong f x≡y) dcong≡hcong {B = B} {x≡y = x≡y} f = elim (λ x≡y → dcong f x≡y ≡ _↔_.to (heterogeneous↔homogeneous (λ i → B (x≡y i))) (hcong f x≡y)) (λ x → dcong f (refl {x = x}) ≡⟨⟩ (λ i → transport (λ _ → B x) i (f x)) ≡⟨ (λ i → comp (λ j → transport (λ _ → B x) (- j) (f x) ≡ f x) (λ { j (i = 0̲) → (λ k → transport (λ _ → B x) (max k (- j)) (f x)) ; j (i = 1̲) → transport (λ k → transport (λ _ → B x) (- min k j) (f x) ≡ f x) 0̲ refl }) (transport (λ _ → f x ≡ f x) (- i) refl)) ⟩ transport (λ i → transport (λ _ → B x) (- i) (f x) ≡ f x) 0̲ refl ≡⟨ cong (transport (λ i → transport (λ _ → B x) (- i) (f x) ≡ f x) 0̲ ∘ (_$ refl)) $ sym $ transport-refl 0̲ ⟩ transport (λ i → transport (λ _ → B x) (- i) (f x) ≡ f x) 0̲ (transport (λ _ → f x ≡ f x) 0̲ refl) ≡⟨⟩ _↔_.to (heterogeneous↔homogeneous (λ i → B (refl {x = x} i))) (hcong f (refl {x = x})) ∎) x≡y -- A "computation" rule. from-heterogeneous↔homogeneous-const-refl : (B : A → Type b) {x : A} {y : B x} → _↔_.from (heterogeneous↔homogeneous λ _ → B x) refl ≡ sym (subst-refl B y) from-heterogeneous↔homogeneous-const-refl B {x = x} {y = y} = transport (λ _ → y ≡ transport (λ _ → B x) 0̲ y) 0̲ (transport (λ i → transport (λ _ → B x) i y ≡ transport (λ _ → B x) 0̲ y) 0̲ (λ _ → transport (λ _ → B x) 0̲ y)) ≡⟨ cong (_$ transport (λ i → transport (λ _ → B x) i y ≡ transport (λ _ → B x) 0̲ y) 0̲ (λ _ → transport (λ _ → B x) 0̲ y)) $ transport-refl 0̲ ⟩ transport (λ i → transport (λ _ → B x) i y ≡ transport (λ _ → B x) 0̲ y) 0̲ (λ _ → transport (λ _ → B x) 0̲ y) ≡⟨ transport-≡ (λ _ → transport (λ _ → B x) 0̲ y) ⟩ trans (λ i → transport (λ _ → B x) (- i) y) (trans (λ _ → transport (λ _ → B x) 0̲ y) (λ _ → transport (λ _ → B x) 0̲ y)) ≡⟨ cong (trans (λ i → transport (λ _ → B x) (- i) y)) $ trans-symʳ (λ _ → transport (λ _ → B x) 0̲ y) ⟩ trans (λ i → transport (λ _ → B x) (- i) y) refl ≡⟨ trans-reflʳ _ ⟩∎ (λ i → transport (λ _ → B x) (- i) y) ∎ -- A direct proof of something with the same type as Σ-≡,≡→≡. Σ-≡,≡→≡′ : {p₁ p₂ : Σ A B} → (p : proj₁ p₁ ≡ proj₁ p₂) → subst B p (proj₂ p₁) ≡ proj₂ p₂ → p₁ ≡ p₂ Σ-≡,≡→≡′ {B = B} {p₁ = _ , y₁} {p₂ = _ , y₂} p q i = p i , lemma i where lemma : [ (λ i → B (p i)) ] y₁ ≡ y₂ lemma = _↔_.from (heterogeneous↔homogeneous _) q -- Σ-≡,≡→≡ is pointwise equal to Σ-≡,≡→≡′. Σ-≡,≡→≡≡Σ-≡,≡→≡′ : {B : A → Type b} {p₁ p₂ : Σ A B} {p : proj₁ p₁ ≡ proj₁ p₂} {q : subst B p (proj₂ p₁) ≡ proj₂ p₂} → Σ-≡,≡→≡ {B = B} p q ≡ Σ-≡,≡→≡′ p q Σ-≡,≡→≡≡Σ-≡,≡→≡′ {B = B} {p₁ = p₁} {p₂ = p₂} {p = p} {q = q} = elim₁ (λ p → ∀ {p₁₂} (q : subst B p p₁₂ ≡ proj₂ p₂) → Σ-≡,≡→≡ p q ≡ Σ-≡,≡→≡′ p q) (λ q → Σ-≡,≡→≡ refl q ≡⟨ Σ-≡,≡→≡-reflˡ q ⟩ cong (_ ,_) (trans (sym $ subst-refl B _) q) ≡⟨ cong (cong (_ ,_)) $ elim¹ (λ q → trans (sym $ subst-refl B _) q ≡ _↔_.from (heterogeneous↔homogeneous _) q) ( trans (sym $ subst-refl B _) refl ≡⟨ trans-reflʳ _ ⟩ sym (subst-refl B _) ≡⟨ sym $ from-heterogeneous↔homogeneous-const-refl B ⟩∎ _↔_.from (heterogeneous↔homogeneous _) refl ∎) q ⟩ cong (_ ,_) (_↔_.from (heterogeneous↔homogeneous _) q) ≡⟨⟩ Σ-≡,≡→≡′ refl q ∎) p q -- All instances of an interval-indexed family are equal. index-irrelevant : (P : I → Type p) → P i ≡ P j index-irrelevant {i = i} {j = j} P = λ k → P (max (min i (- k)) (min j k)) -- Positive h-levels of P i can be expressed in terms of the h-levels -- of dependent paths over P. H-level-suc↔H-level[]≡ : {P : I → Type p} → H-level (suc n) (P i) ↔ (∀ x y → H-level n ([ P ] x ≡ y)) H-level-suc↔H-level[]≡ {n = n} {i = i} {P = P} = H-level (suc n) (P i) ↝⟨ H-level-cong ext _ (≡⇒≃ $ index-irrelevant P) ⟩ H-level (suc n) (P 1̲) ↝⟨ inverse $ ≡↔+ _ ext ⟩ ((x y : P 1̲) → H-level n (x ≡ y)) ↝⟨ (Π-cong ext (≡⇒≃ $ index-irrelevant P) λ x → ∀-cong ext λ _ → ≡⇒↝ _ $ cong (λ x → H-level _ (x ≡ _)) ( x ≡⟨ sym $ transport∘transport (λ i → P (- i)) ⟩ transport P 0̲ (transport (λ i → P (- i)) 0̲ x) ≡⟨ cong (λ f → transport P 0̲ (transport (λ i → P (- i)) 0̲ (f x))) $ sym $ transport-refl 0̲ ⟩∎ transport P 0̲ (transport (λ i → P (- i)) 0̲ (transport (λ _ → P 1̲) 0̲ x)) ∎)) ⟩ ((x : P 0̲) (y : P 1̲) → H-level n (transport P 0̲ x ≡ y)) ↝⟨ (∀-cong ext λ x → ∀-cong ext λ y → H-level-cong ext n $ inverse $ heterogeneous↔homogeneous P) ⟩□ ((x : P 0̲) (y : P 1̲) → H-level n ([ P ] x ≡ y)) □ private -- A simple lemma used below. H-level-suc→H-level[]≡ : ∀ n → H-level (1 + n) (P 0̲) → H-level n ([ P ] x ≡ y) H-level-suc→H-level[]≡ {P = P} {x = x} {y = y} n = H-level (1 + n) (P 0̲) ↔⟨ H-level-suc↔H-level[]≡ ⟩ (∀ x y → H-level n ([ P ] x ≡ y)) ↝⟨ (λ f → f _ _) ⟩□ H-level n ([ P ] x ≡ y) □ -- A form of proof irrelevance for paths that are propositional at one -- end-point. heterogeneous-irrelevance₀ : Is-proposition (P 0̲) → [ P ] x ≡ y heterogeneous-irrelevance₀ {P = P} {x = x} {y = y} = Is-proposition (P 0̲) ↝⟨ H-level-suc→H-level[]≡ _ ⟩ Contractible ([ P ] x ≡ y) ↝⟨ proj₁ ⟩□ [ P ] x ≡ y □ -- A form of UIP for squares that are sets on one corner. heterogeneous-UIP₀₀ : {P : I → I → Type p} {x : ∀ i → P i 0̲} {y : ∀ i → P i 1̲} {p : [ (λ j → P 0̲ j) ] x 0̲ ≡ y 0̲} {q : [ (λ j → P 1̲ j) ] x 1̲ ≡ y 1̲} → Is-set (P 0̲ 0̲) → [ (λ i → [ (λ j → P i j) ] x i ≡ y i) ] p ≡ q heterogeneous-UIP₀₀ {P = P} {x = x} {y = y} {p = p} {q = q} = Is-set (P 0̲ 0̲) ↝⟨ H-level-suc→H-level[]≡ 1 ⟩ Is-proposition ([ (λ j → P 0̲ j) ] x 0̲ ≡ y 0̲) ↝⟨ H-level-suc→H-level[]≡ _ ⟩ Contractible ([ (λ i → [ (λ j → P i j) ] x i ≡ y i) ] p ≡ q) ↝⟨ proj₁ ⟩□ [ (λ i → [ (λ j → P i j) ] x i ≡ y i) ] p ≡ q □ -- A variant of heterogeneous-UIP₀₀, "one level up". heterogeneous-UIP₃₀₀ : {P : I → I → I → Type p} {x : ∀ i j → P i j 0̲} {y : ∀ i j → P i j 1̲} {p : ∀ i → [ (λ k → P i 0̲ k) ] x i 0̲ ≡ y i 0̲} {q : ∀ i → [ (λ k → P i 1̲ k) ] x i 1̲ ≡ y i 1̲} {r : [ (λ j → [ (λ k → P 0̲ j k) ] x 0̲ j ≡ y 0̲ j) ] p 0̲ ≡ q 0̲} {s : [ (λ j → [ (λ k → P 1̲ j k) ] x 1̲ j ≡ y 1̲ j) ] p 1̲ ≡ q 1̲} → H-level 3 (P 0̲ 0̲ 0̲) → [ (λ i → [ (λ j → [ (λ k → P i j k) ] x i j ≡ y i j) ] p i ≡ q i) ] r ≡ s heterogeneous-UIP₃₀₀ {P = P} {x = x} {y = y} {p = p} {q = q} {r = r} {s = s} = H-level 3 (P 0̲ 0̲ 0̲) ↝⟨ H-level-suc→H-level[]≡ 2 ⟩ Is-set ([ (λ k → P 0̲ 0̲ k) ] x 0̲ 0̲ ≡ y 0̲ 0̲) ↝⟨ H-level-suc→H-level[]≡ 1 ⟩ Is-proposition ([ (λ j → [ (λ k → P 0̲ j k) ] x 0̲ j ≡ y 0̲ j) ] p 0̲ ≡ q 0̲) ↝⟨ H-level-suc→H-level[]≡ _ ⟩ Contractible ([ (λ i → [ (λ j → [ (λ k → P i j k) ] x i j ≡ y i j) ] p i ≡ q i) ] r ≡ s) ↝⟨ proj₁ ⟩□ [ (λ i → [ (λ j → [ (λ k → P i j k) ] x i j ≡ y i j) ] p i ≡ q i) ] r ≡ s □ -- The following three lemmas can be used to implement the truncation -- cases of (at least some) eliminators for (at least some) HITs. For -- some examples, see H-level.Truncation.Propositional, Quotient and -- Eilenberg-MacLane-space. -- A variant of heterogeneous-irrelevance₀. heterogeneous-irrelevance : {P : A → Type p} → (∀ x → Is-proposition (P x)) → {x≡y : x ≡ y} {p₁ : P x} {p₂ : P y} → [ (λ i → P (x≡y i)) ] p₁ ≡ p₂ heterogeneous-irrelevance {x = x} {P = P} P-prop {x≡y} {p₁} {p₂} = $⟨ P-prop ⟩ (∀ x → Is-proposition (P x)) ↝⟨ _$ _ ⟩ Is-proposition (P x) ↝⟨ heterogeneous-irrelevance₀ ⟩□ [ (λ i → P (x≡y i)) ] p₁ ≡ p₂ □ -- A variant of heterogeneous-UIP₀₀. -- -- The cubical library contains (or used to contain) a lemma with -- basically the same type, but with a seemingly rather different -- proof, implemented by Zesen Qian. heterogeneous-UIP : {P : A → Type p} → (∀ x → Is-set (P x)) → {eq₁ eq₂ : x ≡ y} (eq₃ : eq₁ ≡ eq₂) {p₁ : P x} {p₂ : P y} (eq₄ : [ (λ j → P (eq₁ j)) ] p₁ ≡ p₂) (eq₅ : [ (λ j → P (eq₂ j)) ] p₁ ≡ p₂) → [ (λ i → [ (λ j → P (eq₃ i j)) ] p₁ ≡ p₂) ] eq₄ ≡ eq₅ heterogeneous-UIP {x = x} {P = P} P-set eq₃ {p₁} {p₂} eq₄ eq₅ = $⟨ P-set ⟩ (∀ x → Is-set (P x)) ↝⟨ _$ _ ⟩ Is-set (P x) ↝⟨ heterogeneous-UIP₀₀ ⟩□ [ (λ i → [ (λ j → P (eq₃ i j)) ] p₁ ≡ p₂) ] eq₄ ≡ eq₅ □ -- A variant of heterogeneous-UIP, "one level up". heterogeneous-UIP₃ : {P : A → Type p} → (∀ x → H-level 3 (P x)) → {eq₁ eq₂ : x ≡ y} {eq₃ eq₄ : eq₁ ≡ eq₂} (eq₅ : eq₃ ≡ eq₄) {p₁ : P x} {p₂ : P y} {eq₆ : [ (λ k → P (eq₁ k)) ] p₁ ≡ p₂} {eq₇ : [ (λ k → P (eq₂ k)) ] p₁ ≡ p₂} (eq₈ : [ (λ j → [ (λ k → P (eq₃ j k)) ] p₁ ≡ p₂) ] eq₆ ≡ eq₇) (eq₉ : [ (λ j → [ (λ k → P (eq₄ j k)) ] p₁ ≡ p₂) ] eq₆ ≡ eq₇) → [ (λ i → [ (λ j → [ (λ k → P (eq₅ i j k)) ] p₁ ≡ p₂) ] eq₆ ≡ eq₇) ] eq₈ ≡ eq₉ heterogeneous-UIP₃ {x = x} {P = P} P-groupoid eq₅ {p₁ = p₁} {p₂ = p₂} {eq₆ = eq₆} {eq₇ = eq₇} eq₈ eq₉ = $⟨ P-groupoid ⟩ (∀ x → H-level 3 (P x)) ↝⟨ _$ _ ⟩ H-level 3 (P x) ↝⟨ heterogeneous-UIP₃₀₀ ⟩□ [ (λ i → [ (λ j → [ (λ k → P (eq₅ i j k)) ] p₁ ≡ p₂) ] eq₆ ≡ eq₇) ] eq₈ ≡ eq₉ □
{ "alphanum_fraction": 0.4574029486, "avg_line_length": 34.8094144661, "ext": "agda", "hexsha": "e9b9593f45ecbf1a4c263a665bee22940a4517b4", "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/Equality/Path.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/Equality/Path.agda", "max_line_length": 150, "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/Equality/Path.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": 11649, "size": 30319 }
-- Andreas, 2017-07-26 -- Better error message when constructor not fully applied. open import Agda.Builtin.Nat test : (Nat → Nat) → Nat test suc = suc zero -- WAS: Type mismatch -- NOW: Cannot pattern match on functions -- when checking that the pattern suc has type Nat → Nat
{ "alphanum_fraction": 0.7224199288, "avg_line_length": 23.4166666667, "ext": "agda", "hexsha": "2a0e06efbb6ea8fb3fd89a493d1eab774bf4a144", "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/MatchOnFunctions.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/MatchOnFunctions.agda", "max_line_length": 59, "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/MatchOnFunctions.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": 74, "size": 281 }
-- Andreas, 2018-10-17, re #2757 -- -- Don't project from erased matches. open import Agda.Builtin.List open import Common.Prelude data IsCons {A : Set} : List A → Set where isCons : ∀{@0 x : A} {@0 xs : List A} → IsCons (x ∷ xs) headOfErased : ∀{A} (@0 xs : List A) → IsCons xs → A headOfErased (x ∷ xs) isCons = x -- Should fail with error: -- -- Variable x is declared erased, so it cannot be used here main = printNat (headOfErased (1 ∷ 2 ∷ []) isCons) -- Otherwise, main segfaults.
{ "alphanum_fraction": 0.6464646465, "avg_line_length": 23.5714285714, "ext": "agda", "hexsha": "afa36e27f957b558ff7b2b2ac04f35c8d02d5dee", "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/Erasure-No-Project-Erased-Match.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/Erasure-No-Project-Erased-Match.agda", "max_line_length": 59, "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/Erasure-No-Project-Erased-Match.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 169, "size": 495 }
------------------------------------------------------------------------------ -- Well-founded induction on the lexicographic order on natural numbers ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Data.Nat.Induction.NonAcc.LexicographicI where open import FOTC.Base open import FOTC.Data.Nat.Inequalities open import FOTC.Data.Nat.Inequalities.EliminationPropertiesI open import FOTC.Data.Nat.Inequalities.PropertiesI open import FOTC.Data.Nat.Type ------------------------------------------------------------------------------ Lexi-wfind : (A : D → D → Set) → (∀ {m₁ n₁} → N m₁ → N n₁ → (∀ {m₂ n₂} → N m₂ → N n₂ → Lexi m₂ n₂ m₁ n₁ → A m₂ n₂) → A m₁ n₁) → ∀ {m n} → N m → N n → A m n Lexi-wfind A h Nm Nn = h Nm Nn (helper₂ Nm Nn) where helper₁ : ∀ {m n o} → N m → N n → N o → m < o → o < succ₁ n → m < n helper₁ {m} {n} {o} Nm Nn No m<o o<Sn = Sx≤y→x<y Nm Nn (≤-trans (nsucc Nm) No Nn (x<y→Sx≤y Nm No m<o) (Sx≤Sy→x≤y {o} {n} (x<y→Sx≤y No (nsucc Nn) o<Sn))) helper₂ : ∀ {m₁ n₁ m₂ n₂} → N m₁ → N n₁ → N m₂ → N n₂ → Lexi m₂ n₂ m₁ n₁ → A m₂ n₂ helper₂ Nm₁ Nn₂ nzero nzero 00<00 = h nzero nzero (λ Nm' Nn' m'n'<00 → ⊥-elim (xy<00→⊥ Nm' Nn' m'n'<00)) helper₂ nzero nzero (nsucc Nm₂) nzero Sm₂0<00 = ⊥-elim (Sxy<0y'→⊥ Sm₂0<00) helper₂ (nsucc Nm₁) nzero (nsucc Nm₂) nzero Sm₂0<Sm₁0 = h (nsucc Nm₂) nzero (λ Nm' Nn' m'n'<Sm₂0 → helper₂ Nm₁ nzero Nm' Nn' (inj₁ (helper₁ Nm' Nm₁ (nsucc Nm₂) (xy<x'0→x<x' Nn' m'n'<Sm₂0) (xy<x'0→x<x' nzero Sm₂0<Sm₁0)))) helper₂ nzero (nsucc Nn₁) (nsucc Nm₂) nzero Sm₂0<0Sn₁ = ⊥-elim (Sxy<0y'→⊥ Sm₂0<0Sn₁) helper₂ (nsucc Nm₁) (nsucc Nn₁) (nsucc Nm₂) nzero Sm₂0<Sm₁Sn₁ = h (nsucc Nm₂) nzero (λ Nm' Nn' m'n'<Sm₂0 → helper₂ (nsucc Nm₁) Nn₁ Nm' Nn' (inj₁ (case (λ Sm₂<Sm₁ → x<y→x<Sy Nm' Nm₁ (helper₁ Nm' Nm₁ (nsucc Nm₂) (xy<x'0→x<x' Nn' m'n'<Sm₂0) Sm₂<Sm₁)) (λ Sm₂≡Sm₁∧0<Sn₁ → x<y→y≡z→x<z (xy<x'0→x<x' Nn' m'n'<Sm₂0) (∧-proj₁ Sm₂≡Sm₁∧0<Sn₁)) Sm₂0<Sm₁Sn₁))) helper₂ nzero nzero nzero (nsucc Nn₂) 0Sn₂<00 = ⊥-elim (0Sx<00→⊥ 0Sn₂<00) helper₂ (nsucc {m₁} Nm₁) nzero nzero (nsucc Nn₂) 0Sn₂<Sm₁0 = h nzero (nsucc Nn₂) (λ Nm' Nn' m'n'<0Nn₂ → helper₂ Nm₁ (nsucc Nn₂) Nm' Nn' (case (λ m'<0 → ⊥-elim (x<0→⊥ Nm' m'<0)) (λ m'≡0∧n'<Sn₂ → case (λ 0<m₁ → inj₁ (x≡y→y<z→x<z (∧-proj₁ m'≡0∧n'<Sn₂) 0<m₁)) (λ 0≡m₁ → inj₂ ((trans (∧-proj₁ m'≡0∧n'<Sn₂) 0≡m₁) , (∧-proj₂ m'≡0∧n'<Sn₂))) (x<Sy→x<y∨x≡y nzero Nm₁ 0<Sm₁)) m'n'<0Nn₂)) where 0<Sm₁ : zero < succ₁ m₁ 0<Sm₁ = xy<x'0→x<x' (nsucc Nn₂) 0Sn₂<Sm₁0 helper₂ nzero (nsucc Nn₁) nzero (nsucc Nn₂) 0Sn₂<0Sn₁ = case (λ 0<0 → ⊥-elim (0<0→⊥ 0<0)) (λ 0≡0∧Sn₂<Sn₁ → h nzero (nsucc Nn₂) (λ Nm' Nn' m'n'<0Sn₂ → case (λ m'<0 → ⊥-elim (x<0→⊥ Nm' m'<0)) (λ m'≡0∧n'<Sn₂ → helper₂ nzero Nn₁ Nm' Nn' (inj₂ (∧-proj₁ m'≡0∧n'<Sn₂ , helper₁ Nn' Nn₁ (nsucc Nn₂) (∧-proj₂ m'≡0∧n'<Sn₂) (∧-proj₂ 0≡0∧Sn₂<Sn₁)))) m'n'<0Sn₂)) 0Sn₂<0Sn₁ helper₂ (nsucc Nm₁) (nsucc Nn₁) nzero (nsucc Nn₂) 0Sn₂<Sm₁Sn₁ = h nzero (nsucc Nn₂) (λ Nm' Nn' m'n'<0Sn₂ → helper₂ (nsucc Nm₁) Nn₁ Nm' Nn' (case (λ m'<0 → ⊥-elim (x<0→⊥ Nm' m'<0)) (λ m'≡0∧n'<Sn₂ → case (λ 0<Sm₁ → inj₁ (x≡y→y<z→x<z (∧-proj₁ m'≡0∧n'<Sn₂) 0<Sm₁)) (λ 0≡Sn₂∧Sn₂<Sn₁ → ⊥-elim (0≢S (∧-proj₁ 0≡Sn₂∧Sn₂<Sn₁))) 0Sn₂<Sm₁Sn₁) m'n'<0Sn₂)) helper₂ nzero nzero (nsucc Nm₂) (nsucc Nn₂) Sm₂Sn₂<00 = ⊥-elim (xy<00→⊥ (nsucc Nm₂) (nsucc Nn₂) Sm₂Sn₂<00) helper₂ (nsucc {m₁} Nm₁) nzero (nsucc {m₂} Nm₂) (nsucc Nn₂) Sm₂Sn₂<Sm₁0 = h (nsucc Nm₂) (nsucc Nn₂) (λ Nm' Nn' m'n'<Sm₂Sn₂ → helper₂ Nm₁ (nsucc Nn₂) Nm' Nn' (case (λ m'<Sm₂ → inj₁ (helper₁ Nm' Nm₁ (nsucc Nm₂) m'<Sm₂ Sm₂<Sm₁)) (λ m'≡Sm₂∧n'<Sn₂ → case (λ m'<m₁ → inj₁ m'<m₁) (λ m'≡m₁ → inj₂ (m'≡m₁ , ∧-proj₂ m'≡Sm₂∧n'<Sn₂)) (x<Sy→x<y∨x≡y Nm' Nm₁ (x≡y→y<z→x<z (∧-proj₁ m'≡Sm₂∧n'<Sn₂) Sm₂<Sm₁))) m'n'<Sm₂Sn₂)) where Sm₂<Sm₁ : succ₁ m₂ < succ₁ m₁ Sm₂<Sm₁ = xy<x'0→x<x' (nsucc Nn₂) Sm₂Sn₂<Sm₁0 helper₂ nzero (nsucc Nn₁) (nsucc Nm₂) (nsucc Nn₂) Sm₂Sn₂<0Sn₁ = ⊥-elim (Sxy<0y'→⊥ Sm₂Sn₂<0Sn₁) helper₂ (nsucc Nm₁) (nsucc Nn₁) (nsucc Nm₂) (nsucc Nn₂) Sm₂Sn₂<Sm₁Sn₁ = h (nsucc Nm₂) (nsucc Nn₂) (λ Nm' Nn' m'n'<Sm₂Sn₂ → helper₂ (nsucc Nm₁) Nn₁ Nm' Nn' (case (λ Sm₂<Sm₁ → case (λ m'<Sm₂ → inj₁ (x<y→x<Sy Nm' Nm₁ (helper₁ Nm' Nm₁ (nsucc Nm₂) m'<Sm₂ Sm₂<Sm₁))) (λ m'≡Sm₂∧n'<Sn₂ → inj₁ (x≡y→y<z→x<z (∧-proj₁ m'≡Sm₂∧n'<Sn₂) Sm₂<Sm₁)) m'n'<Sm₂Sn₂) (λ Sm₂≡Sm₁∧Sn₂<Sn₁ → case (λ m'<Sm₂ → inj₁ (x<y→y≡z→x<z m'<Sm₂ (∧-proj₁ Sm₂≡Sm₁∧Sn₂<Sn₁))) (λ m'≡Sm₂∧n'<Sn₂ → inj₂ (trans (∧-proj₁ m'≡Sm₂∧n'<Sn₂) (∧-proj₁ Sm₂≡Sm₁∧Sn₂<Sn₁) , helper₁ Nn' Nn₁ (nsucc Nn₂) (∧-proj₂ m'≡Sm₂∧n'<Sn₂) (∧-proj₂ Sm₂≡Sm₁∧Sn₂<Sn₁))) m'n'<Sm₂Sn₂) Sm₂Sn₂<Sm₁Sn₁))
{ "alphanum_fraction": 0.4442598438, "avg_line_length": 43.3021582734, "ext": "agda", "hexsha": "e9d27529b8ef205b75f53b1efab9e8351454a434", "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/Data/Nat/Induction/NonAcc/LexicographicI.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/Data/Nat/Induction/NonAcc/LexicographicI.agda", "max_line_length": 104, "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/Data/Nat/Induction/NonAcc/LexicographicI.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": 2667, "size": 6019 }
module Numeral.Natural.Oper.Divisibility where import Lvl open import Data open import Data.Boolean open import Numeral.Natural open import Numeral.Natural.Oper.Comparisons open import Numeral.Natural.Oper.Modulo -- Divisibility check _∣?_ : ℕ → ℕ → Bool 𝟎 ∣? _ = 𝐹 𝐒(y) ∣? x = zero?(x mod 𝐒(y)) -- Divisibility check _∣₀?_ : ℕ → ℕ → Bool 𝟎 ∣₀? 𝟎 = 𝑇 𝟎 ∣₀? 𝐒(_) = 𝐹 𝐒(y) ∣₀? x = zero?(x mod 𝐒(y)) {- open import Numeral.Natural.Oper open import Numeral.Natural.UnclosedOper open import Data.Option as Option using (Option) {-# TERMINATING #-} _∣?_ : ℕ → ℕ → Bool _ ∣? 𝟎 = 𝑇 𝟎 ∣? 𝐒(_) = 𝐹 𝐒(x) ∣? 𝐒(y) with (x −? y) ... | Option.Some(xy) = xy ∣? 𝐒(y) ... | Option.None = 𝐹 -}
{ "alphanum_fraction": 0.6221590909, "avg_line_length": 20.7058823529, "ext": "agda", "hexsha": "5455e184559b589382a73c2ec75af51a1b8438cf", "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/Divisibility.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/Divisibility.agda", "max_line_length": 48, "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/Divisibility.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": 305, "size": 704 }
record R (A : Set) : Set where field giveA : A open R ⦃ … ⦄ record WrapR (A : Set) : Set where field instance ⦃ wrappedR ⦄ : R A open WrapR ⦃ … ⦄ postulate instance R-instance : ∀ {X} → WrapR X data D : Set where works : D works = giveA ⦃ WrapR.wrappedR (R-instance {D}) ⦄ fails : D fails = giveA ⦃ {!!} ⦄ -- No instance of type R D was found in scope. -- open import Agda.Primitive -- {- -- record IsBottom₀ (⊥ : Set) : Set (lsuc lzero) where -- field -- ⊥₀-elim : ⊥ → {A : Set lzero} → A -- open IsBottom₀ ⦃ … ⦄ public -- record Bottom₀ : Set (lsuc lzero) where -- field -- ⊥₀ : Set -- ⦃ isBottom ⦄ : IsBottom₀ ⊥₀ -- open Bottom₀ ⦃ … ⦄ public -- test : ⦃ bottom : ∀ {l : Set} → Bottom₀ ⦄ {fake : ⊥₀ ⦃ bottom {Level} ⦄} {real : Set} → real -- test ⦃ bottom ⦄ {fake} {real} = ⊥₀-elim {⊥₀ ⦃ bottom ⦄} ⦃ Bottom₀.isBottom (bottom {Level}) ⦄ fake -- -} -- record IsBottom₀ (⊥ : Set) a : Set (lsuc a) where -- field -- ⊥₀-elim : ⊥ → {A : Set a} → A -- open IsBottom₀ ⦃ … ⦄ public -- record Bottom₀ a : Set (lsuc a) where -- field -- ⊥₀ : Set -- ⦃ isBottom ⦄ : IsBottom₀ ⊥₀ a -- open Bottom₀ ⦃ … ⦄ public -- postulate -- instance Bi : ∀ {a} → Bottom₀ a -- --test : ⦃ bottom : ∀ {a} → Bottom₀ a ⦄ {fake : ⊥₀ {lzero}} {real : Set} → real -- --test ⦃ bottom ⦄ {fake} {real} = let instance b = Bottom₀.isBottom (bottom {lzero}) in ⊥₀-elim {⊥₀ {lzero} ⦃ bottom ⦄} {lzero} ⦃ {!Bottom₀.isBottom bottom!} ⦄ fake -- test : {fake : ⊥₀ {lzero}} {real : Set} → real -- test {fake} {real} = ⊥₀-elim {⊥₀ {lzero} ⦃ Bi ⦄} {lzero} ⦃ Bottom₀.isBottom Bi ⦄ fake -- -- record Bottom₀ a : Set (lsuc a) where -- -- field -- -- ⊥₀ : Set -- -- ⊥₀-elim : ⊥₀ → {A : Set a} → A -- -- open Bottom₀ ⦃ … ⦄ public -- -- test : ⦃ bottom : ∀ {a} → Bottom₀ a ⦄ {fake : ⊥₀ {lzero}} {real : Set} → real -- -- test ⦃ bottom ⦄ {fake} {real} = ⊥₀-elim fake -- ⊥₀-elim {⊥₀ {lzero} ⦃ bottom ⦄} {lzero} ⦃ bottom ⦄ fake -- -- postulate -- -- B : Set -- -- record IsB (r : Set) a : Set (lsuc a) where -- -- field -- -- gotB : B -- -- xx : r -- -- open IsB ⦃ … ⦄ public -- -- record RB a : Set (lsuc a) where -- -- field -- -- r : Set -- -- ⦃ isB ⦄ : IsB r a -- -- open RB ⦃ … ⦄ public -- -- testB : ⦃ bottom : ∀ {a} → RB a ⦄ → B -- -- testB ⦃ bottom ⦄ = gotB ⦃ {!isB bottom {lzero}!} ⦄
{ "alphanum_fraction": 0.5209760274, "avg_line_length": 24.5894736842, "ext": "agda", "hexsha": "48c345049a8047835c14881570290ba13c43e806", "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/BottomUp2.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/BottomUp2.agda", "max_line_length": 167, "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/BottomUp2.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1024, "size": 2336 }
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Setoids.Setoids open import Functions.Definition open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import Numbers.Naturals.Naturals open import Numbers.Integers.Integers open import Groups.Definition open import Groups.Homomorphisms.Definition open import Groups.Homomorphisms.Lemmas open import Groups.Isomorphisms.Definition open import Groups.Abelian.Definition open import Groups.Subgroups.Definition open import Groups.Lemmas open import Groups.Groups open import Rings.Definition open import Rings.Lemmas open import Fields.Fields open import Sets.EquivalenceRelations module Groups.Examples.ExampleSheet1 where {- Question 1: e is the unique solution of x^2 = x -} question1 : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} → (G : Group S _+_) → (x : A) → Setoid._∼_ S (x + x) x → Setoid._∼_ S x (Group.0G G) question1 {S = S} {_+_ = _+_} G x x+x=x = transitive (symmetric identRight) (transitive (+WellDefined reflexive (symmetric invRight)) (transitive +Associative (transitive (+WellDefined x+x=x reflexive) invRight))) where open Group G open Setoid S open Equivalence eq question1' : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} → (G : Group S _+_) → Setoid._∼_ S ((Group.0G G) + (Group.0G G)) (Group.0G G) question1' G = Group.identRight G {- Question 3. We can't talk about ℝ yet, so we'll just work in an arbitrary integral domain. Show that the collection of linear functions over a ring forms a group; is it abelian? -} record LinearFunction {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} (F : Field R) : Set (a ⊔ b) where field xCoeff : A xCoeffNonzero : (Setoid._∼_ S xCoeff (Ring.0R R) → False) constant : A interpretLinearFunction : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} {F : Field R} (f : LinearFunction F) → A → A interpretLinearFunction {_+_ = _+_} {_*_ = _*_} record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant } a = (xCoeff * a) + constant composeLinearFunctions : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} {F : Field R} (f1 : LinearFunction F) (f2 : LinearFunction F) → LinearFunction F LinearFunction.xCoeff (composeLinearFunctions {_+_ = _+_} {_*_ = _*_} record { xCoeff = xCoeff1 ; xCoeffNonzero = xCoeffNonzero1 ; constant = constant1 } record { xCoeff = xCoeff2 ; xCoeffNonzero = xCoeffNonzero2 ; constant = constant2 }) = xCoeff1 * xCoeff2 LinearFunction.xCoeffNonzero (composeLinearFunctions {S = S} {R = R} {F = F} record { xCoeff = xCoeff1 ; xCoeffNonzero = xCoeffNonzero1 ; constant = constant1 } record { xCoeff = xCoeff2 ; xCoeffNonzero = xCoeffNonzero2 ; constant = constant2 }) pr = xCoeffNonzero2 bad where open Setoid S open Ring R open Equivalence eq bad : Setoid._∼_ S xCoeff2 0R bad with Field.allInvertible F xCoeff1 xCoeffNonzero1 ... | xinv , pr' = transitive (symmetric identIsIdent) (transitive (*WellDefined (symmetric pr') reflexive) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive pr) (Ring.timesZero R)))) LinearFunction.constant (composeLinearFunctions {_+_ = _+_} {_*_ = _*_} record { xCoeff = xCoeff1 ; xCoeffNonzero = xCoeffNonzero1 ; constant = constant1 } record { xCoeff = xCoeff2 ; xCoeffNonzero = xCoeffNonzero2 ; constant = constant2 }) = (xCoeff1 * constant2) + constant1 compositionIsCorrect : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} {F : Field R} (f1 : LinearFunction F) (f2 : LinearFunction F) → {r : A} → Setoid._∼_ S (interpretLinearFunction (composeLinearFunctions f1 f2) r) (((interpretLinearFunction f1) ∘ (interpretLinearFunction f2)) r) compositionIsCorrect {S = S} {_+_ = _+_} {_*_ = _*_} {R = R} record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant } record { xCoeff = xCoeff' ; xCoeffNonzero = xCoeffNonzero' ; constant = constant' } {r} = ans where open Setoid S open Ring R open Equivalence eq ans : (((xCoeff * xCoeff') * r) + ((xCoeff * constant') + constant)) ∼ (xCoeff * ((xCoeff' * r) + constant')) + constant ans = transitive (Group.+Associative additiveGroup) (Group.+WellDefined additiveGroup (transitive (Group.+WellDefined additiveGroup (symmetric (Ring.*Associative R)) reflexive) (symmetric (Ring.*DistributesOver+ R))) (reflexive {constant})) linearFunctionsSetoid : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} (I : Field R) → Setoid (LinearFunction I) Setoid._∼_ (linearFunctionsSetoid {S = S} I) f1 f2 = ((LinearFunction.xCoeff f1) ∼ (LinearFunction.xCoeff f2)) && ((LinearFunction.constant f1) ∼ (LinearFunction.constant f2)) where open Setoid S Equivalence.reflexive (Setoid.eq (linearFunctionsSetoid {S = S} I)) = Equivalence.reflexive (Setoid.eq S) ,, Equivalence.reflexive (Setoid.eq S) Equivalence.symmetric (Setoid.eq (linearFunctionsSetoid {S = S} I)) (fst ,, snd) = Equivalence.symmetric (Setoid.eq S) fst ,, Equivalence.symmetric (Setoid.eq S) snd Equivalence.transitive (Setoid.eq (linearFunctionsSetoid {S = S} I)) (fst1 ,, snd1) (fst2 ,, snd2) = Equivalence.transitive (Setoid.eq S) fst1 fst2 ,, Equivalence.transitive (Setoid.eq S) snd1 snd2 linearFunctionsGroup : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} (F : Field R) → Group (linearFunctionsSetoid F) (composeLinearFunctions) Group.+WellDefined (linearFunctionsGroup {R = R} F) {record { xCoeff = xCoeffM ; xCoeffNonzero = xCoeffNonzeroM ; constant = constantM }} {record { xCoeff = xCoeffN ; xCoeffNonzero = xCoeffNonzeroN ; constant = constantN }} {record { xCoeff = xCoeffX ; xCoeffNonzero = xCoeffNonzeroX ; constant = constantX }} {record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant }} (fst1 ,, snd1) (fst2 ,, snd2) = *WellDefined fst1 fst2 ,, Group.+WellDefined additiveGroup (*WellDefined fst1 snd2) snd1 where open Ring R Group.0G (linearFunctionsGroup {S = S} {R = R} F) = record { xCoeff = Ring.1R R ; constant = Ring.0R R ; xCoeffNonzero = λ p → Field.nontrivial F (Equivalence.symmetric (Setoid.eq S) p) } Group.inverse (linearFunctionsGroup {S = S} {_*_ = _*_} {R = R} F) record { xCoeff = xCoeff ; constant = c ; xCoeffNonzero = pr } with Field.allInvertible F xCoeff pr ... | (inv , pr') = record { xCoeff = inv ; constant = inv * (Group.inverse (Ring.additiveGroup R) c) ; xCoeffNonzero = λ p → Field.nontrivial F (transitive (symmetric (transitive (Ring.*WellDefined R p reflexive) (transitive (Ring.*Commutative R) (Ring.timesZero R)))) pr') } where open Setoid S open Equivalence eq Group.+Associative (linearFunctionsGroup {S = S} {_+_ = _+_} {_*_ = _*_} {R = R} F) {record { xCoeff = xA ; xCoeffNonzero = xANonzero ; constant = cA }} {record { xCoeff = xB ; xCoeffNonzero = xBNonzero ; constant = cB }} {record { xCoeff = xC ; xCoeffNonzero = xCNonzero ; constant = cC }} = Ring.*Associative R ,, transitive (Group.+WellDefined additiveGroup (transitive *DistributesOver+ (Group.+WellDefined additiveGroup *Associative reflexive)) reflexive) (symmetric (Group.+Associative additiveGroup)) where open Setoid S open Equivalence eq open Ring R Group.identRight (linearFunctionsGroup {S = S} {_+_ = _+_} {_*_ = _*_} {R = R} F) {record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant }} = transitive (Ring.*Commutative R) (Ring.identIsIdent R) ,, transitive (Group.+WellDefined additiveGroup (Ring.timesZero R) reflexive) (Group.identLeft additiveGroup) where open Ring R open Setoid S open Equivalence eq Group.identLeft (linearFunctionsGroup {S = S} {R = R} F) {record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant }} = identIsIdent ,, transitive (Group.identRight additiveGroup) identIsIdent where open Setoid S open Ring R open Equivalence eq Group.invLeft (linearFunctionsGroup F) {record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant }} with Field.allInvertible F xCoeff xCoeffNonzero Group.invLeft (linearFunctionsGroup {S = S} {R = R} F) {record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant }} | inv , prInv = prInv ,, transitive (symmetric *DistributesOver+) (transitive (*WellDefined reflexive (Group.invRight additiveGroup)) (Ring.timesZero R)) where open Setoid S open Ring R open Equivalence eq Group.invRight (linearFunctionsGroup {S = S} {R = R} F) {record { xCoeff = xCoeff ; xCoeffNonzero = xCoeffNonzero ; constant = constant }} with Field.allInvertible F xCoeff xCoeffNonzero ... | inv , pr = transitive *Commutative pr ,, transitive (Group.+WellDefined additiveGroup *Associative reflexive) (transitive (Group.+WellDefined additiveGroup (*WellDefined (transitive *Commutative pr) reflexive) reflexive) (transitive (Group.+WellDefined additiveGroup identIsIdent reflexive) (Group.invLeft additiveGroup))) where open Setoid S open Ring R open Equivalence eq {- Question 3, part 2: prove that linearFunctionsGroup is not abelian -} -- We'll assume the field doesn't have characteristic 2. linearFunctionsGroupNotAbelian : {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} {F : Field R} → (nonChar2 : Setoid._∼_ S ((Ring.1R R) + (Ring.1R R)) (Ring.0R R) → False) → AbelianGroup (linearFunctionsGroup F) → False linearFunctionsGroupNotAbelian {S = S} {_+_ = _+_} {_*_ = _*_} {R = R} {F = F} pr record { commutative = commutative } = ans where open Ring R open Group additiveGroup open Equivalence (Setoid.eq S) renaming (symmetric to symmetricS ; transitive to transitiveS ; reflexive to reflexiveS) f : LinearFunction F f = record { xCoeff = 1R ; xCoeffNonzero = λ p → Field.nontrivial F (symmetricS p) ; constant = 1R } g : LinearFunction F g = record { xCoeff = 1R + 1R ; xCoeffNonzero = pr ; constant = 0R } gf : LinearFunction F gf = record { xCoeff = 1R + 1R ; xCoeffNonzero = pr ; constant = 1R + 1R } fg : LinearFunction F fg = record { xCoeff = 1R + 1R ; xCoeffNonzero = pr ; constant = 1R } oneWay : Setoid._∼_ (linearFunctionsSetoid F) gf (composeLinearFunctions g f) oneWay = symmetricS (transitiveS *Commutative identIsIdent) ,, transitiveS (symmetricS (transitiveS *Commutative identIsIdent)) (symmetricS (Group.identRight additiveGroup)) otherWay : Setoid._∼_ (linearFunctionsSetoid F) fg (composeLinearFunctions f g) otherWay = symmetricS identIsIdent ,, transitiveS (symmetricS (Group.identLeft additiveGroup)) (Group.+WellDefined additiveGroup (symmetricS identIsIdent) (reflexiveS {1R})) open Equivalence (Setoid.eq (linearFunctionsSetoid F)) bad : Setoid._∼_ (linearFunctionsSetoid F) gf fg bad = transitive {gf} {composeLinearFunctions g f} {fg} oneWay (transitive {composeLinearFunctions g f} {composeLinearFunctions f g} {fg} (commutative {g} {f}) (symmetric {fg} {composeLinearFunctions f g} otherWay)) ans : False ans with bad ans | _ ,, contr = Field.nontrivial F (symmetricS (transitiveS {1R} {1R + (1R + Group.inverse additiveGroup 1R)} (transitiveS (symmetricS (Group.identRight additiveGroup)) (Group.+WellDefined additiveGroup reflexiveS (symmetricS (Group.invRight additiveGroup)))) (transitiveS (Group.+Associative additiveGroup) (transitiveS (Group.+WellDefined additiveGroup contr reflexiveS) (Group.invRight additiveGroup)))))
{ "alphanum_fraction": 0.6831558648, "avg_line_length": 77.4480519481, "ext": "agda", "hexsha": "d0c3c7276059d96ef7b60d7a2b98b32c02e1bc6b", "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/Examples/ExampleSheet1.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/Examples/ExampleSheet1.agda", "max_line_length": 515, "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/Examples/ExampleSheet1.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": 3761, "size": 11927 }
------------------------------------------------------------------------ -- The partiality monad's monad instance, defined via an adjunction ------------------------------------------------------------------------ {-# OPTIONS --cubical --safe #-} module Partiality-monad.Inductive.Monad.Adjunction where open import Equality.Propositional.Cubical open import Logical-equivalence using (_⇔_) open import Prelude hiding (T; ⊥) open import Adjunction equality-with-J open import Bijection equality-with-J using (_↔_) open import Category equality-with-J open import Function-universe equality-with-J hiding (id; _∘_) open import Functor equality-with-J open import H-level equality-with-J open import H-level.Closure equality-with-J open import Partiality-algebra as PA hiding (id; _∘_) open import Partiality-algebra.Category as PAC import Partiality-algebra.Properties as PAP open import Partiality-monad.Inductive as PI using (_⊥; partiality-algebra; initial) open import Partiality-monad.Inductive.Eliminators import Partiality-monad.Inductive.Monad as PM import Partiality-monad.Inductive.Omega-continuous as PO -- A forgetful functor from partiality algebras to sets. Forget : ∀ {a p q} {A : Type a} → PAC.precategory p q A ⇨ precategory-Set p ext functor Forget = (λ P → T P , T-is-set P) , Morphism.function , refl , refl where open Partiality-algebra -- The precategory of pointed ω-cpos. ω-CPPO : ∀ p q → Precategory (lsuc (p ⊔ q)) (p ⊔ q) ω-CPPO p q = PAC.precategory p q ⊥₀ -- Pointed ω-cpos. ω-cppo : ∀ p q → Type (lsuc (p ⊔ q)) ω-cppo p q = Partiality-algebra p q ⊥₀ -- If there is a function from B to the carrier of P, then P -- can be converted to a partiality algebra over B. convert : ∀ {a b p q} {A : Type a} {B : Type b} → (P : Partiality-algebra p q A) → (B → Partiality-algebra.T P) → Partiality-algebra p q B convert P f = record { T = T ; partiality-algebra-with = record { _⊑_ = _⊑_ ; never = never ; now = f ; ⨆ = ⨆ ; antisymmetry = antisymmetry ; T-is-set-unused = T-is-set-unused ; ⊑-refl = ⊑-refl ; ⊑-trans = ⊑-trans ; never⊑ = never⊑ ; upper-bound = upper-bound ; least-upper-bound = least-upper-bound ; ⊑-propositional = ⊑-propositional } } where open Partiality-algebra P -- A lemma that removes convert from certain types. drop-convert : ∀ {a p q p′ q′} {A : Type a} {X : ω-cppo p q} {Y : ω-cppo p′ q′} {f : A → _} {g : A → _} → Morphism (convert X f) (convert Y g) → Morphism X Y drop-convert m = record { function = function ; monotone = monotone ; strict = strict ; now-to-now = λ x → ⊥-elim x ; ω-continuous = ω-continuous } where open Morphism m -- Converts partiality algebras to ω-cppos. drop-now : ∀ {a p q} {A : Type a} → Partiality-algebra p q A → ω-cppo p q drop-now P = convert P ⊥-elim -- The function drop-now does not modify ω-cppos. drop-now-constant : ∀ {p q} {P : ω-cppo p q} → drop-now P ≡ P drop-now-constant = cong (λ now → record { partiality-algebra-with = record { now = now } }) (⟨ext⟩ λ x → ⊥-elim x) -- Converts types to ω-cppos. Partial⊚ : ∀ {ℓ} → Type ℓ → ω-cppo ℓ ℓ Partial⊚ = drop-now ∘ partiality-algebra private -- A lemma. Partial⊙′ : let open Partiality-algebra; open Morphism in ∀ {a b p q} {A : Type a} {B : Type b} (P : Partiality-algebra p q B) → (f : A → T P) → ∃ λ (m : Morphism (Partial⊚ A) (drop-now P)) → (∀ x → function m (PI.now x) ≡ now (convert P f) x) × (∀ m′ → (∀ x → function m′ (PI.now x) ≡ now (convert P f) x) → m ≡ m′) Partial⊙′ {A = A} P f = m′ , PI.⊥-rec-now _ , lemma where P′ : Partiality-algebra _ _ A P′ = convert P f m : Morphism (partiality-algebra A) P′ m = proj₁ (initial P′) m′ : Morphism (Partial⊚ A) (drop-now P) m′ = drop-convert m abstract lemma : ∀ m″ → (∀ x → Morphism.function m″ (PI.now x) ≡ Partiality-algebra.now P′ x) → m′ ≡ m″ lemma m″ hyp = _↔_.to equality-characterisation-Morphism ( function m′ ≡⟨⟩ function m ≡⟨ cong function (proj₂ (initial P′) record { function = function m″ ; monotone = monotone m″ ; strict = strict m″ ; now-to-now = hyp ; ω-continuous = ω-continuous m″ }) ⟩∎ function m″ ∎) where open Morphism -- Lifts functions between types to morphisms between the -- corresponding ω-cppos. Partial⊙ : ∀ {a b} {A : Type a} {B : Type b} → (A → B) → Morphism (Partial⊚ A) (Partial⊚ B) Partial⊙ f = proj₁ (Partial⊙′ (partiality-algebra _) (PI.now ∘ f)) -- Partial⊙ f is the unique morphism (of the given type) mapping -- PI.now x to PI.now (f x) (for all x). Partial⊙-now : ∀ {a b} {A : Type a} {B : Type b} {f : A → B} {x} → Morphism.function (Partial⊙ f) (PI.now x) ≡ PI.now (f x) Partial⊙-now = proj₁ (proj₂ (Partial⊙′ (partiality-algebra _) _)) _ Partial⊙-unique : ∀ {a b} {A : Type a} {B : Type b} {f : A → B} {m} → (∀ x → Morphism.function m (PI.now x) ≡ PI.now (f x)) → Partial⊙ f ≡ m Partial⊙-unique = proj₂ (proj₂ (Partial⊙′ (partiality-algebra _) _)) _ -- A functor that maps a set A to A ⊥. Partial : ∀ {ℓ} → precategory-Set ℓ ext ⇨ ω-CPPO ℓ ℓ _⇨_.functor (Partial {ℓ}) = Partial⊚ ∘ proj₁ , Partial⊙ , L.lemma₁ , L.lemma₂ where open Morphism module L where abstract lemma₁ : {A : Type ℓ} → Partial⊙ (id {A = A}) ≡ PA.id lemma₁ = Partial⊙-unique λ _ → refl lemma₂ : {A B C : Type ℓ} {f : A → B} {g : B → C} → Partial⊙ (g ∘ f) ≡ Partial⊙ g PA.∘ Partial⊙ f lemma₂ {f = f} {g} = Partial⊙-unique λ x → function (Partial⊙ g PA.∘ Partial⊙ f) (PI.now x) ≡⟨ cong (function (Partial⊙ g)) Partial⊙-now ⟩ function (Partial⊙ g) (PI.now (f x)) ≡⟨ Partial⊙-now ⟩∎ PI.now (g (f x)) ∎ -- Partial is a left adjoint of Forget. Partial⊣Forget : ∀ {ℓ} → Partial {ℓ = ℓ} ⊣ Forget Partial⊣Forget {ℓ} = η , ε , (λ {X} → let P = Partial⊚ (proj₁ X) in _↔_.to equality-characterisation-Morphism $ ⟨ext⟩ $ ⊥-rec-⊥ record { pe = fun P (function (Partial⊙ PI.now) PI.never) ≡⟨ cong (fun P) $ strict (Partial⊙ PI.now) ⟩ fun P PI.never ≡⟨ strict (m P) ⟩∎ PI.never ∎ ; po = λ x → fun P (function (Partial⊙ PI.now) (PI.now x)) ≡⟨ cong (fun P) Partial⊙-now ⟩ fun P (PI.now (PI.now x)) ≡⟨ fun-now P ⟩∎ PI.now x ∎ ; pl = λ s hyp → fun P (function (Partial⊙ PI.now) (PI.⨆ s)) ≡⟨ cong (fun P) $ ω-continuous (Partial⊙ PI.now) _ ⟩ fun P (PI.⨆ _) ≡⟨ ω-continuous (m P) _ ⟩ PI.⨆ _ ≡⟨ cong PI.⨆ $ _↔_.to PI.equality-characterisation-increasing hyp ⟩∎ PI.⨆ s ∎ ; pp = λ _ → PI.⊥-is-set }) , (λ {X} → ⟨ext⟩ λ x → fun X (PI.now x) ≡⟨ fun-now X ⟩∎ x ∎) where open Morphism {q₂ = ℓ} open PAP open Partiality-algebra η : id⇨ ⇾ Forget ∙⇨ Partial _⇾_.natural-transformation η = PI.now , (λ {X Y f} → ⟨ext⟩ λ x → function (Partial⊙ f) (PI.now x) ≡⟨ Partial⊙-now ⟩∎ PI.now (f x) ∎) m : (X : ω-cppo ℓ ℓ) → Morphism (Partial⊚ (T X)) X m X = $⟨ id ⟩ (T X → T X) ↝⟨ proj₁ ∘ Partial⊙′ X ⟩ Morphism (Partial⊚ (T X)) (drop-now X) ↝⟨ drop-convert ⟩□ Morphism (Partial⊚ (T X)) X □ fun : (X : ω-cppo ℓ ℓ) → T X ⊥ → T X fun X = function (m X) fun-now : ∀ (X : ω-cppo ℓ ℓ) {x} → fun X (PI.now x) ≡ x fun-now X = proj₁ (proj₂ (Partial⊙′ X _)) _ fun-unique : (X : ω-cppo ℓ ℓ) (m′ : Morphism (Partial⊚ (T X)) X) → (∀ x → function m′ (PI.now x) ≡ x) → fun X ≡ function m′ fun-unique X m′ hyp = cong function $ proj₂ (proj₂ (Partial⊙′ X _)) (drop-convert m′) hyp ε : Partial ∙⇨ Forget ⇾ id⇨ _⇾_.natural-transformation ε = (λ {X} → m X) , (λ {X Y f} → let m′ = (Partial ∙⇨ Forget) ⊙ f in _↔_.to equality-characterisation-Morphism $ ⟨ext⟩ $ ⊥-rec-⊥ record { pe = function f (fun X PI.never) ≡⟨ cong (function f) (strict (m X)) ⟩ function f (never X) ≡⟨ strict f ⟩ never Y ≡⟨ sym $ strict (m Y) ⟩ fun Y PI.never ≡⟨ cong (fun Y) $ sym $ strict m′ ⟩∎ fun Y (function m′ PI.never) ∎ ; po = λ x → function f (fun X (PI.now x)) ≡⟨ cong (function f) (fun-now X) ⟩ function f x ≡⟨ sym $ fun-now Y ⟩ fun Y (PI.now (function f x)) ≡⟨ cong (fun Y) $ sym Partial⊙-now ⟩∎ fun Y (function m′ (PI.now x)) ∎ ; pl = λ s hyp → function f (fun X (PI.⨆ s)) ≡⟨ cong (function f) (ω-continuous (m X) _) ⟩ function f (⨆ X _) ≡⟨ ω-continuous f _ ⟩ ⨆ Y _ ≡⟨ cong (⨆ Y) $ _↔_.to (equality-characterisation-increasing Y) hyp ⟩ ⨆ Y _ ≡⟨ sym $ ω-continuous (m Y) _ ⟩ fun Y (PI.⨆ _) ≡⟨ cong (fun Y) $ sym $ ω-continuous m′ _ ⟩∎ fun Y (function m′ (PI.⨆ s)) ∎ ; pp = λ _ → T-is-set Y }) -- Thus we get that the partiality monad is a monad. Partiality-monad : ∀ {ℓ} → Monad (precategory-Set ℓ ext) Partiality-monad = adjunction→monad (Partial , Forget , Partial⊣Forget) private -- The object part of the monad's functor really does correspond to -- the partiality monad. object-part-of-functor-correct : ∀ {a} {A : Set a} → proj₁ (proj₁ Partiality-monad ⊚ A) ≡ proj₁ A ⊥ object-part-of-functor-correct = refl -- The definition of "map" obtained here matches the explicit -- definition in Partiality-monad.Inductive.Monad. map-correct : ∀ {ℓ} {A B : Set ℓ} {f : proj₁ A → proj₁ B} → _⊙_ (proj₁ Partiality-monad) {X = A} {Y = B} f ≡ PO.[_⊥→_⊥].function (PM.map f) map-correct = refl -- The definition of "return" is the expected one. return-correct : ∀ {a} {A : Set a} → _⇾_.transformation (proj₁ (proj₂ Partiality-monad)) {X = A} ≡ PI.now return-correct = refl -- The definition of "join" obtained here matches the explicit -- definition in Partiality-monad.Inductive.Monad. join-correct : ∀ {a} {A : Set a} → _⇾_.transformation (proj₁ (proj₂ (proj₂ Partiality-monad))) {X = A} ≡ PM.join join-correct = refl
{ "alphanum_fraction": 0.5035889356, "avg_line_length": 34.2035928144, "ext": "agda", "hexsha": "4a9ed4420ae32b8fb1aabdba410c31bc3acafe0b", "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": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/partiality-monad", "max_forks_repo_path": "src/Partiality-monad/Inductive/Monad/Adjunction.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae", "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/partiality-monad", "max_issues_repo_path": "src/Partiality-monad/Inductive/Monad/Adjunction.agda", "max_line_length": 131, "max_stars_count": 2, "max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/partiality-monad", "max_stars_repo_path": "src/Partiality-monad/Inductive/Monad/Adjunction.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z", "num_tokens": 3892, "size": 11424 }
------------------------------------------------------------------------------ -- The group commutator ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module GroupTheory.Commutator where open import GroupTheory.Base ------------------------------------------------------------------------------ -- The group commutator -- -- There are two definitions for the group commutator: -- -- [a,b] = aba⁻¹b⁻¹ (Mac Lane and Garret 1999, p. 418), or -- -- [a,b] = a⁻¹b⁻¹ab (Kurosh 1960, p. 99). -- -- We use Kurosh's definition, because this is the definition used by -- the TPTP 6.4.0 problem GRP/GRP024-5.p. Actually the problem uses -- the definition -- -- [a,b] = a⁻¹(b⁻¹(ab)). [_,_] : G → G → G [ a , b ] = a ⁻¹ · b ⁻¹ · a · b {-# ATP definition [_,_] #-} commutatorAssoc : G → G → G → Set commutatorAssoc a b c = [ [ a , b ] , c ] ≡ [ a , [ b , c ] ] {-# ATP definition commutatorAssoc #-} ------------------------------------------------------------------------------ -- References -- -- Mac Lane, S. and Birkhof, G. (1999). Algebra. 3rd ed. AMS Chelsea -- Publishing. -- -- Kurosh, A. G. (1960). The Theory of Groups. 2nd -- ed. Vol. 1. Translated and edited by K. A. Hirsch. Chelsea -- Publising Company.
{ "alphanum_fraction": 0.4614295824, "avg_line_length": 30.7173913043, "ext": "agda", "hexsha": "19d5e57d3c5e578b065c7a953a72d8d2d6fce848", "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/Commutator.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/Commutator.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/Commutator.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": 379, "size": 1413 }
module Categories.Congruence where open import Level open import Relation.Binary hiding (_⇒_; Setoid) open import Categories.Support.PropositionalEquality open import Categories.Support.Equivalence open import Categories.Support.EqReasoning open import Categories.Category hiding (module Heterogeneous; _[_∼_]) record Congruence {o ℓ e} (C : Category o ℓ e) q : Set (o ⊔ ℓ ⊔ e ⊔ suc q) where open Category C field _≡₀_ : Rel Obj q equiv₀ : IsEquivalence _≡₀_ module Equiv₀ = IsEquivalence equiv₀ field coerce : ∀ {X₁ X₂ Y₁ Y₂} → X₁ ≡₀ X₂ → Y₁ ≡₀ Y₂ → X₁ ⇒ Y₁ → X₂ ⇒ Y₂ .coerce-resp-≡ : ∀ {X₁ X₂ Y₁ Y₂} (xpf : X₁ ≡₀ X₂) (ypf : Y₁ ≡₀ Y₂) → {f₁ f₂ : X₁ ⇒ Y₁} → f₁ ≡ f₂ → coerce xpf ypf f₁ ≡ coerce xpf ypf f₂ .coerce-refl : ∀ {X Y} (f : X ⇒ Y) → coerce Equiv₀.refl Equiv₀.refl f ≡ f .coerce-invariant : ∀ {X₁ X₂ Y₁ Y₂} (xpf₁ xpf₂ : X₁ ≡₀ X₂) (ypf₁ ypf₂ : Y₁ ≡₀ Y₂) → (f : X₁ ⇒ Y₁) → coerce xpf₁ ypf₁ f ≡ coerce xpf₂ ypf₂ f .coerce-trans : ∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃} (xpf₁ : X₁ ≡₀ X₂) (xpf₂ : X₂ ≡₀ X₃) (ypf₁ : Y₁ ≡₀ Y₂) (ypf₂ : Y₂ ≡₀ Y₃) → (f : X₁ ⇒ Y₁) → coerce (Equiv₀.trans xpf₁ xpf₂) (Equiv₀.trans ypf₁ ypf₂) f ≡ coerce xpf₂ ypf₂ (coerce xpf₁ ypf₁ f) .coerce-∘ : ∀ {X₁ X₂ Y₁ Y₂ Z₁ Z₂} → (pfX : X₁ ≡₀ X₂) (pfY : Y₁ ≡₀ Y₂) (pfZ : Z₁ ≡₀ Z₂) → (g : Y₁ ⇒ Z₁) (f : X₁ ⇒ Y₁) → coerce pfX pfZ (g ∘ f) ≡ coerce pfY pfZ g ∘ coerce pfX pfY f .coerce-local : ∀ {X Y} (xpf : X ≡₀ X) (ypf : Y ≡₀ Y) {f : X ⇒ Y} → coerce xpf ypf f ≡ f coerce-local xpf ypf {f} = begin coerce xpf ypf f ↓⟨ coerce-invariant xpf Equiv₀.refl ypf Equiv₀.refl f ⟩ coerce Equiv₀.refl Equiv₀.refl f ↓⟨ coerce-refl f ⟩ f ∎ where open HomReasoning .coerce-zigzag : ∀ {X₁ X₂ Y₁ Y₂} (pfX : X₁ ≡₀ X₂) (rfX : X₂ ≡₀ X₁) (pfY : Y₁ ≡₀ Y₂) (rfY : Y₂ ≡₀ Y₁) → {f : X₁ ⇒ Y₁} → coerce rfX rfY (coerce pfX pfY f) ≡ f coerce-zigzag pfX rfX pfY rfY {f} = begin coerce rfX rfY (coerce pfX pfY f) ↑⟨ coerce-trans _ _ _ _ _ ⟩ coerce (trans pfX rfX) (trans pfY rfY) f ↓⟨ coerce-local _ _ ⟩ f ∎ where open HomReasoning open Equiv₀ .coerce-uncong : ∀ {X₁ X₂ Y₁ Y₂} (pfX : X₁ ≡₀ X₂) (pfY : Y₁ ≡₀ Y₂) (f g : X₁ ⇒ Y₁) → coerce pfX pfY f ≡ coerce pfX pfY g → f ≡ g coerce-uncong xpf ypf f g fg-pf = begin f ↑⟨ coerce-zigzag _ _ _ _ ⟩ coerce (sym xpf) (sym ypf) (coerce xpf ypf f) ↓⟨ coerce-resp-≡ _ _ fg-pf ⟩ coerce (sym xpf) (sym ypf) (coerce xpf ypf g) ↓⟨ coerce-zigzag _ _ _ _ ⟩ g ∎ where open HomReasoning open Equiv₀ .coerce-slide⇒ : ∀ {X₁ X₂ Y₁ Y₂} (pfX : X₁ ≡₀ X₂) (rfX : X₂ ≡₀ X₁) (pfY : Y₁ ≡₀ Y₂) (rfY : Y₂ ≡₀ Y₁) → (f : X₁ ⇒ Y₁) (g : X₂ ⇒ Y₂) → coerce pfX pfY f ≡ g → f ≡ coerce rfX rfY g coerce-slide⇒ pfX rfX pfY rfY f g eq = begin f ↑⟨ coerce-zigzag _ _ _ _ ⟩ coerce rfX rfY (coerce pfX pfY f) ↓⟨ coerce-resp-≡ _ _ eq ⟩ coerce rfX rfY g ∎ where open HomReasoning .coerce-slide⇐ : ∀ {X₁ X₂ Y₁ Y₂} (pfX : X₁ ≡₀ X₂) (rfX : X₂ ≡₀ X₁) (pfY : Y₁ ≡₀ Y₂) (rfY : Y₂ ≡₀ Y₁) → (f : X₁ ⇒ Y₁) (g : X₂ ⇒ Y₂) → f ≡ coerce rfX rfY g → coerce pfX pfY f ≡ g coerce-slide⇐ pfX rfX pfY rfY f g eq = begin coerce pfX pfY f ↓⟨ coerce-resp-≡ _ _ eq ⟩ coerce pfX pfY (coerce rfX rfY g) ↓⟨ coerce-zigzag _ _ _ _ ⟩ g ∎ where open HomReasoning .coerce-id : ∀ {X Y} (pf₁ pf₂ : X ≡₀ Y) → coerce pf₁ pf₂ id ≡ id coerce-id pf₁ pf₂ = begin coerce pf₁ pf₂ id ↑⟨ identityˡ ⟩ id ∘ coerce pf₁ pf₂ id ↑⟨ ∘-resp-≡ˡ (coerce-local _ _) ⟩ coerce (trans (sym pf₂) pf₂) (trans (sym pf₂) pf₂) id ∘ coerce pf₁ pf₂ id ↓⟨ ∘-resp-≡ˡ (coerce-trans _ _ _ _ _) ⟩ coerce pf₂ pf₂ (coerce (sym pf₂) (sym pf₂) id) ∘ coerce pf₁ pf₂ id ↑⟨ coerce-∘ _ _ _ _ _ ⟩ coerce pf₁ pf₂ (coerce (sym pf₂) (sym pf₂) id ∘ id) ↓⟨ coerce-resp-≡ _ _ identityʳ ⟩ coerce pf₁ pf₂ (coerce (sym pf₂) (sym pf₂) id) ↑⟨ coerce-trans _ _ _ _ _ ⟩ coerce (trans (sym pf₂) pf₁) (trans (sym pf₂) pf₂) id ↓⟨ coerce-local _ _ ⟩ id ∎ where open HomReasoning open Equiv₀ module Heterogeneous {o ℓ e} {C : Category o ℓ e} {q} (Q : Congruence C q) where open Category C open Congruence Q open Equiv renaming (refl to refl′; sym to sym′; trans to trans′; reflexive to reflexive′) open Equiv₀ renaming (refl to refl₀; sym to sym₀; trans to trans₀; reflexive to reflexive₀) infix 4 _∼_ data _∼_ {A B} (f : A ⇒ B) {X Y} (g : X ⇒ Y) : Set (o ⊔ ℓ ⊔ e ⊔ q) where ≡⇒∼ : (ax : A ≡₀ X) (by : B ≡₀ Y) → .(coerce ax by f ≡ g) → f ∼ g refl : ∀ {A B} {f : A ⇒ B} → f ∼ f refl = ≡⇒∼ refl₀ refl₀ (coerce-refl _) sym : ∀ {A B} {f : A ⇒ B} {D E} {g : D ⇒ E} → f ∼ g → g ∼ f sym (≡⇒∼ A≡D B≡E f≡g) = ≡⇒∼ (sym₀ A≡D) (sym₀ B≡E) (coerce-slide⇐ _ _ _ _ _ _ (sym′ f≡g)) trans : ∀ {A B} {f : A ⇒ B} {D E} {g : D ⇒ E} {F G} {h : F ⇒ G} → f ∼ g → g ∼ h → f ∼ h trans (≡⇒∼ A≡D B≡E f≡g) (≡⇒∼ D≡F E≡G g≡h) = ≡⇒∼ (trans₀ A≡D D≡F) (trans₀ B≡E E≡G) (trans′ (trans′ (coerce-trans _ _ _ _ _) (coerce-resp-≡ _ _ f≡g)) g≡h) reflexive : ∀ {A B} {f g : A ⇒ B} → f ≣ g → f ∼ g reflexive f≣g = ≡⇒∼ refl₀ refl₀ (trans′ (coerce-refl _) (reflexive′ f≣g)) ∘-resp-∼ : ∀ {A B C A′ B′ C′} {f : B ⇒ C} {h : B′ ⇒ C′} {g : A ⇒ B} {i : A′ ⇒ B′} → f ∼ h → g ∼ i → (f ∘ g) ∼ (h ∘ i) ∘-resp-∼ {f = f} {h} {g} {i} (≡⇒∼ B≡B′₁ C≡C′ f≡h) (≡⇒∼ A≡A′ B≡B′₂ g≡i) = ≡⇒∼ A≡A′ C≡C′ (begin coerce A≡A′ C≡C′ (f ∘ g) ↓⟨ coerce-∘ _ _ _ _ _ ⟩ coerce B≡B′₁ C≡C′ f ∘ coerce A≡A′ B≡B′₁ g ↓⟨ ∘-resp-≡ʳ (coerce-invariant _ _ _ _ _) ⟩ coerce B≡B′₁ C≡C′ f ∘ coerce A≡A′ B≡B′₂ g ↓⟨ ∘-resp-≡ f≡h g≡i ⟩ h ∘ i ∎) where open HomReasoning ∘-resp-∼ˡ : ∀ {A B C C′} {f : B ⇒ C} {h : B ⇒ C′} {g : A ⇒ B} → f ∼ h → (f ∘ g) ∼ (h ∘ g) ∘-resp-∼ˡ {f = f} {h} {g} (≡⇒∼ B≡B C≡C′ f≡h) = ≡⇒∼ refl₀ C≡C′ (begin coerce refl₀ C≡C′ (f ∘ g) ↓⟨ coerce-∘ _ _ _ _ _ ⟩ coerce B≡B C≡C′ f ∘ coerce refl₀ B≡B g ↓⟨ ∘-resp-≡ʳ (coerce-local _ _) ⟩ coerce B≡B C≡C′ f ∘ g ↓⟨ ∘-resp-≡ˡ f≡h ⟩ h ∘ g ∎) where open HomReasoning ∘-resp-∼ʳ : ∀ {A A′ B C} {f : A ⇒ B} {h : A′ ⇒ B} {g : B ⇒ C} → f ∼ h → (g ∘ f) ∼ (g ∘ h) ∘-resp-∼ʳ {f = f} {h} {g} (≡⇒∼ A≡A′ B≡B f≡h) = ≡⇒∼ A≡A′ refl₀ (begin coerce A≡A′ refl₀ (g ∘ f) ↓⟨ coerce-∘ _ _ _ _ _ ⟩ coerce B≡B refl₀ g ∘ coerce A≡A′ B≡B f ↓⟨ ∘-resp-≡ˡ (coerce-local _ _) ⟩ g ∘ coerce A≡A′ B≡B f ↓⟨ ∘-resp-≡ʳ f≡h ⟩ g ∘ h ∎) where open HomReasoning .∼⇒≡ : ∀ {A B} {f g : A ⇒ B} → f ∼ g → f ≡ g ∼⇒≡ (≡⇒∼ A≡A B≡B f≡g) = trans′ (sym′ (coerce-local A≡A B≡B)) (irr f≡g) domain-≣ : ∀ {A A′ B B′} {f : A ⇒ B} {f′ : A′ ⇒ B′} → f ∼ f′ → A ≡₀ A′ domain-≣ (≡⇒∼ eq _ _) = eq codomain-≣ : ∀ {A A′ B B′} {f : A ⇒ B} {f′ : A′ ⇒ B′} → f ∼ f′ → B ≡₀ B′ codomain-≣ (≡⇒∼ _ eq _) = eq ∼-cong : ∀ {t : Level} {T : Set t} {dom cod : T → Obj} (f : (x : T) → dom x ⇒ cod x) → ∀ {i j} (eq : i ≣ j) → f i ∼ f j ∼-cong f ≣-refl = refl -- henry ford versions .∼⇒≡₂ : ∀ {A A′ B B′} {f : A ⇒ B} {f′ : A′ ⇒ B′} → f ∼ f′ → (A≡A′ : A ≡₀ A′) (B≡B′ : B ≡₀ B′) → coerce A≡A′ B≡B′ f ≡ f′ ∼⇒≡₂ (≡⇒∼ pfA pfB pff) A≡A′ B≡B′ = trans′ (coerce-invariant _ _ _ _ _) (irr pff) -- .∼⇒≡ˡ : ∀ {A B B′} {f : A ⇒ B} {f′ : A ⇒ B′} → f ∼ f′ → (B≣B′ : B ≣ B′) → floatˡ B≣B′ f ≡ f′ -- ∼⇒≡ˡ pf ≣-refl = ∼⇒≡ pf -- .∼⇒≡ʳ : ∀ {A A′ B} {f : A ⇒ B} {f′ : A′ ⇒ B} → f ∼ f′ → (A≣A′ : A ≣ A′) → floatʳ A≣A′ f ≡ f′ -- ∼⇒≡ʳ pf ≣-refl = ∼⇒≡ pf -- ≡⇒∼ʳ : ∀ {A A′ B} {f : A ⇒ B} {f′ : A′ ⇒ B} → (A≣A′ : A ≣ A′) → .(floatʳ A≣A′ f ≡ f′) → f ∼ f′ -- ≡⇒∼ʳ ≣-refl pf = ≡⇒∼ pf coerce-resp-∼ : ∀ {A A′ B B′} (A≡A′ : A ≡₀ A′) (B≡B′ : B ≡₀ B′) {f : C [ A , B ]} → f ∼ coerce A≡A′ B≡B′ f coerce-resp-∼ A≡A′ B≡B′ = ≡⇒∼ A≡A′ B≡B′ refl′ -- floatˡ-resp-∼ : ∀ {A B B′} (B≣B′ : B ≣ B′) {f : C [ A , B ]} → f ∼ floatˡ B≣B′ f -- floatˡ-resp-∼ ≣-refl = refl -- floatʳ-resp-∼ : ∀ {A A′ B} (A≣A′ : A ≣ A′) {f : C [ A , B ]} → f ∼ floatʳ A≣A′ f -- floatʳ-resp-∼ ≣-refl = refl infixr 4 ▹_ record -⇒- : Set (o ⊔ ℓ) where constructor ▹_ field {Dom} : Obj {Cod} : Obj morphism : Dom ⇒ Cod ∼-setoid : Setoid _ _ ∼-setoid = record { Carrier = -⇒-; _≈_ = λ x y → -⇒-.morphism x ∼ -⇒-.morphism y; isEquivalence = record { refl = refl; sym = sym; trans = trans } } module HetReasoning where open SetoidReasoning ∼-setoid public _[_∼_] : ∀ {o ℓ e} {C : Category o ℓ e} {q} (Q : Congruence C q) {A B} (f : C [ A , B ]) {X Y} (g : C [ X , Y ]) → Set (q ⊔ o ⊔ ℓ ⊔ e) Q [ f ∼ g ] = Heterogeneous._∼_ Q f g TrivialCongruence : ∀ {o ℓ e} (C : Category o ℓ e) → Congruence C _ TrivialCongruence C = record { _≡₀_ = _≣_ ; equiv₀ = ≣-isEquivalence ; coerce = ≣-subst₂ (_⇒_) ; coerce-resp-≡ = resp-≡ ; coerce-refl = λ f → refl ; coerce-invariant = invariant ; coerce-trans = tranz ; coerce-∘ = compose } where open Category C open Equiv -- XXX must this depend on proof irrelevance? .resp-≡ : ∀ {X₁ X₂ Y₁ Y₂} (xpf : X₁ ≣ X₂) (ypf : Y₁ ≣ Y₂) {f₁ f₂ : X₁ ⇒ Y₁} → f₁ ≡ f₂ → ≣-subst₂ _⇒_ xpf ypf f₁ ≡ ≣-subst₂ _⇒_ xpf ypf f₂ resp-≡ ≣-refl ≣-refl eq = eq .invariant : ∀ {X₁ X₂ Y₁ Y₂} (xpf₁ xpf₂ : X₁ ≣ X₂) (ypf₁ ypf₂ : Y₁ ≣ Y₂) → (f : X₁ ⇒ Y₁) → ≣-subst₂ _⇒_ xpf₁ ypf₁ f ≡ ≣-subst₂ _⇒_ xpf₂ ypf₂ f invariant ≣-refl ≣-refl ≣-refl ≣-refl f = refl .tranz : ∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃} (xpf₁ : X₁ ≣ X₂) (xpf₂ : X₂ ≣ X₃) (ypf₁ : Y₁ ≣ Y₂) (ypf₂ : Y₂ ≣ Y₃) → (f : X₁ ⇒ Y₁) → ≣-subst₂ _⇒_ (≣-trans xpf₁ xpf₂) (≣-trans ypf₁ ypf₂) f ≡ ≣-subst₂ _⇒_ xpf₂ ypf₂ (≣-subst₂ _⇒_ xpf₁ ypf₁ f) tranz ≣-refl xpf₂ ≣-refl ypf₂ f = refl .compose : ∀ {X₁ X₂ Y₁ Y₂ Z₁ Z₂} (pfX : X₁ ≣ X₂)(pfY : Y₁ ≣ Y₂)(pfZ : Z₁ ≣ Z₂) → (g : Y₁ ⇒ Z₁) (f : X₁ ⇒ Y₁) → ≣-subst₂ _⇒_ pfX pfZ (g ∘ f) ≡ ≣-subst₂ _⇒_ pfY pfZ g ∘ ≣-subst₂ _⇒_ pfX pfY f compose ≣-refl ≣-refl ≣-refl g f = refl
{ "alphanum_fraction": 0.469163829, "avg_line_length": 35.595959596, "ext": "agda", "hexsha": "3d57b776c09a02da45f49eff768a1924a9cd81e1", "lang": "Agda", "max_forks_count": 23, "max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z", "max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "p-pavel/categories", "max_forks_repo_path": "Categories/Congruence.agda", "max_issues_count": 19, "max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2", "max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z", "max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "p-pavel/categories", "max_issues_repo_path": "Categories/Congruence.agda", "max_line_length": 134, "max_stars_count": 98, "max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "copumpkin/categories", "max_stars_repo_path": "Categories/Congruence.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z", "max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z", "num_tokens": 5329, "size": 10572 }
-------------------------------------------------------------------------------- -- This is part of Agda Inference Systems {-# OPTIONS --sized-types --guardedness #-} open import Agda.Builtin.Equality open import Data.Product open import Data.Sum open import Codata.Thunk open import Size open import Level open import Relation.Unary using (_⊆_) module is-lib.InfSys.Equivalence {𝓁} where private variable U : Set 𝓁 open import is-lib.InfSys.Base {𝓁} open import is-lib.InfSys.Coinduction {𝓁} open import is-lib.InfSys.SCoinduction {𝓁} open IS {- Equivalence CoInd and SCoInd -} coind-size : ∀{𝓁c 𝓁p 𝓁n}{is : IS {𝓁c} {𝓁p} {𝓁n} U} → CoInd⟦ is ⟧ ⊆ λ u → ∀ {i} → SCoInd⟦ is ⟧ u i coind-size p-coind with CoInd⟦_⟧.unfold p-coind ... | rn , c , refl , pr = sfold (rn , c , refl , λ i → λ where .force → coind-size (pr i)) size-coind : ∀{𝓁c 𝓁p 𝓁n}{is : IS {𝓁c} {𝓁p} {𝓁n} U} → (λ u → ∀ {i} → SCoInd⟦ is ⟧ u i) ⊆ CoInd⟦ is ⟧ size-coind {is = is} p-scoind = coind[ is ] (λ u → ∀ {j} → SCoInd⟦ is ⟧ u j) scoind-postfix p-scoind
{ "alphanum_fraction": 0.5849056604, "avg_line_length": 33.125, "ext": "agda", "hexsha": "488b6a320e49f6a5b0e55c30118911c21b9bb644", "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/Equivalence.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/Equivalence.agda", "max_line_length": 102, "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/Equivalence.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": 407, "size": 1060 }
module Data.Bin.Minus where open import Data.Bin hiding (suc; fromℕ) open Data.Bin using (2+_) open import Data.Bin.Bijection using (fromℕ) open import Data.Fin hiding (_-_; _+_; toℕ; _<_; fromℕ) open import Data.List open import Data.Digit open import Relation.Binary.PropositionalEquality open import Data.Nat using (ℕ; _∸_; suc; zero) renaming (_+_ to _ℕ+_) infixl 6 _-?_ infixl 6 _-_ open import Function pred' : Bin → Bin pred' 0# = 0# pred' ([] 1#) = 0# pred' ((zero ∷ t) 1#) = case Data.Bin.pred t of λ { 0# → [] 1# ; (t' 1#) → (suc zero ∷ t') 1# } pred' ((suc zero ∷ t) 1#) = (zero ∷ t) 1# pred' ((suc (suc ()) ∷ _) 1#) open import Data.Sum open import Data.Unit import Data.Nat.Properties data Greater (a b : Bin) : Set where greater : ∀ (diff : Bin⁺) → b + diff 1# ≡ a → Greater a b open import Data.Empty using (⊥; ⊥-elim) import Data.Bin.Addition open import Data.Bin.Props greater-to-< : ∀ a b → Greater a b → b < a greater-to-< ._ b (greater diff refl) = let zz = Data.Nat.Properties.+-mono-≤ {1} {toℕ (diff 1#)} {toℕ b} {toℕ b} (case z<nz diff of λ { (Data.Bin.less p) → p }) Data.Nat.Properties.≤-refl in Data.Bin.less (Data.Nat.Properties.≤-trans zz ( Data.Nat.Properties.≤-reflexive ( trans (sym (Data.Nat.Properties.+-comm (toℕ b) _)) (sym (Data.Bin.Addition.+-is-addition b (diff 1#))) ))) open import Data.Product data Difference (a b : Bin) : Set where positive : Greater a b → Difference a b negative : Greater b a → Difference a b equal : a ≡ b → Difference a b open import Relation.Nullary open import Algebra.Structures import Data.Bin.Addition open IsCommutativeMonoid Data.Bin.Addition.is-commutativeMonoid using (identity; identityˡ) renaming (comm to +-comm; assoc to +-assoc) open import Data.Product identityʳ = proj₂ identity ∷-pred : Bit → Bin⁺ → Bin⁺ ∷-pred zero [] = [] ∷-pred zero (h ∷ t) = suc zero ∷ ∷-pred h t ∷-pred (suc zero) l = zero ∷ l ∷-pred (suc (suc ())) l open Relation.Binary.PropositionalEquality.≡-Reasoning open import Data.Bin.Multiplication using (∷1#-interpretation) open import Function using (_⟨_⟩_) seems-trivial : ∀ xs → (zero ∷ xs) 1# + [] 1# ≡ (suc zero ∷ xs) 1# seems-trivial xs = cong (λ q → q + [] 1#) (∷1#-interpretation zero xs ⟨ trans ⟩ (identityˡ (xs 1# *2))) ⟨ trans ⟩ +-comm (xs 1# *2) ([] 1#) ⟨ trans ⟩ sym (∷1#-interpretation (suc zero) xs) open import Data.Bin.Props carry : ∀ t → [] 1# + (suc zero ∷ t) 1# ≡ ([] 1# + t 1#) *2 carry t = begin [] 1# + (suc zero ∷ t) 1# ≡⟨ cong (_+_ ([] 1#)) (∷1#-interpretation (suc zero) t) ⟩ [] 1# + ([] 1# + t 1# *2) ≡⟨ sym (+-assoc ([] 1#) ([] 1#) (t 1# *2)) ⟩ [] 1# *2 + (t 1# *2) ≡⟨ sym (*2-distrib ([] 1#) (t 1#)) ⟩ ([] 1# + t 1#) *2 ∎ 1+∷-pred : ∀ h t → [] 1# + (∷-pred h t) 1# ≡ (h ∷ t) 1# 1+∷-pred zero [] = refl 1+∷-pred zero (x ∷ xs) = begin [] 1# + (suc zero ∷ ∷-pred x xs) 1# ≡⟨ carry (∷-pred x xs) ⟩ ([] 1# + (∷-pred x xs) 1#) *2 ≡⟨ cong _*2 (1+∷-pred x xs) ⟩ (x ∷ xs) 1# *2 ≡⟨ refl ⟩ (zero ∷ x ∷ xs) 1# ∎ 1+∷-pred (suc zero) t = +-comm ([] 1#) ((zero ∷ t) 1#) ⟨ trans ⟩ seems-trivial t 1+∷-pred (suc (suc ())) t data Comparison (A : Set) : Set where greater : A → Comparison A equal : Comparison A less : A → Comparison A map-cmp : {A B : Set} → (A → B) → Comparison A → Comparison B map-cmp f (greater a) = greater (f a) map-cmp f (less a) = less (f a) map-cmp f equal = equal _%f_ : ∀ {b} → Fin (suc b) → Fin (suc b) → Comparison (Fin b) zero %f zero = equal zero %f suc b = less b suc a %f zero = greater a _%f_ {suc base} (suc a) (suc b) = map-cmp inject₁ (a %f b) _%f_ {zero} (suc ()) (suc ()) _*2-1 : Bin⁺ → Bin⁺ [] *2-1 = [] (suc zero ∷ t) *2-1 = suc zero ∷ zero ∷ t (zero ∷ t) *2-1 = suc zero ∷ (t *2-1) (suc (suc ()) ∷ t) *2-1 _*2+1' : Bin⁺ → Bin⁺ l *2+1' = suc zero ∷ l addBit : Bin⁺ → Comparison (Fin 1) → Bin⁺ addBit gt (greater zero) = gt *2+1' addBit gt equal = zero ∷ gt addBit gt (less zero) = gt *2-1 addBit gt (less (suc ())) addBit gt (greater (suc ())) open import Data.Bin.Utils *2-1-lem : ∀ d → (d *2-1) 1# + [] 1# ≡ d 1# *2 *2-1-lem [] = refl *2-1-lem (zero ∷ xs) = begin (zero ∷ xs) *2-1 1# + [] 1# ≡⟨ refl ⟩ (suc zero ∷ (xs *2-1)) 1# + [] 1# ≡⟨ +-comm ((suc zero ∷ xs *2-1) 1#) ([] 1#) ⟩ [] 1# + (suc zero ∷ (xs *2-1)) 1# ≡⟨ carry (xs *2-1) ⟩ ([] 1# + (xs *2-1) 1#) *2 ≡⟨ cong _*2 (+-comm ([] 1#) ((xs *2-1) 1#)) ⟩ ((xs *2-1) 1# + [] 1#) *2 ≡⟨ cong _*2 (*2-1-lem xs) ⟩ (xs 1# *2) *2 ≡⟨ refl ⟩ (zero ∷ xs) 1# *2 ∎ *2-1-lem (suc zero ∷ xs) = begin (suc zero ∷ zero ∷ xs) 1# + [] 1# ≡⟨ cong (λ q → q + [] 1#) (∷1#-interpretation (suc zero) (zero ∷ xs)) ⟩ [] 1# + (zero ∷ xs) 1# *2 + [] 1# ≡⟨ refl ⟩ [] 1# + xs 1# *2 *2 + [] 1# ≡⟨ +-comm ([] 1# + xs 1# *2 *2) ([] 1#) ⟩ [] 1# + ([] 1# + xs 1# *2 *2) ≡⟨ sym (+-assoc ([] 1#) ([] 1#) (xs 1# *2 *2)) ⟩ [] 1# *2 + xs 1# *2 *2 ≡⟨ sym (*2-distrib ([] 1#) (xs 1# *2)) ⟩ ([] 1# + xs 1# *2) *2 ≡⟨ cong _*2 (sym (∷1#-interpretation (suc zero) xs)) ⟩ (suc zero ∷ xs) 1# *2 ≡⟨ refl ⟩ (zero ∷ suc zero ∷ xs) 1# ∎ *2-1-lem (suc (suc ()) ∷ xs) addBit-lem : ∀ x y d → addBit d (x %f y) 1# + bitToBin y ≡ d 1# *2 + bitToBin x addBit-lem zero zero d = refl addBit-lem (suc zero) zero d = refl addBit-lem zero (suc zero) d = *2-1-lem d ⟨ trans ⟩ sym (identityʳ (d 1# *2)) addBit-lem (suc zero) (suc zero) d = refl addBit-lem (suc (suc ())) _ d addBit-lem _ (suc (suc ())) d +-cong₁ : ∀ {z} {x y} → x ≡ y → x + z ≡ y + z +-cong₁ {z} = cong (λ q → q + z) +-cong₂ : ∀ {z} {x y} → x ≡ y → z + x ≡ z + y +-cong₂ {z} = cong (λ q → z + q) refineGt : ∀ xs ys (x y : Bit) → Greater (xs 1#) (ys 1#) → Greater ((x ∷ xs) 1#) ((y ∷ ys) 1#) refineGt xs ys x y (greater d ys+d=xs) = greater (addBit d (x %f y)) good where good : (y ∷ ys) 1# + addBit d (x %f y) 1# ≡ (x ∷ xs) 1# good = begin (y ∷ ys) 1# + addBit d (x %f y) 1# ≡⟨ +-cong₁ {addBit d (x %f y) 1#} (∷1#-interpretation y ys) ⟩ bitToBin y + (ys 1#) *2 + addBit d (x %f y) 1# ≡⟨ +-comm (bitToBin y + (ys 1#) *2) (addBit d (x %f y) 1#) ⟩ addBit d (x %f y) 1# + (bitToBin y + (ys 1#) *2) ≡⟨ sym (+-assoc (addBit d (x %f y) 1#) (bitToBin y) ((ys 1#) *2)) ⟩ (addBit d (x %f y) 1# + bitToBin y) + (ys 1#) *2 ≡⟨ +-cong₁ {(ys 1#) *2} (addBit-lem x y d) ⟩ (d 1# *2 + bitToBin x) + (ys 1#) *2 ≡⟨ +-cong₁ {(ys 1#) *2} (+-comm (d 1# *2) (bitToBin x)) ⟩ (bitToBin x + d 1# *2 ) + (ys 1#) *2 ≡⟨ +-assoc (bitToBin x) (d 1# *2) ((ys 1#) *2) ⟩ bitToBin x + (d 1# *2 + (ys 1#) *2) ≡⟨ +-cong₂ {bitToBin x} (+-comm (d 1# *2) ((ys 1#) *2)) ⟩ bitToBin x + ((ys 1#) *2 + d 1# *2) ≡⟨ +-cong₂ {bitToBin x} (sym (*2-distrib (ys 1#) (d 1#))) ⟩ bitToBin x + (ys 1# + d 1#) *2 ≡⟨ +-cong₂ {bitToBin x} (cong _*2 ys+d=xs) ⟩ bitToBin x + xs 1# *2 ≡⟨ sym (∷1#-interpretation x xs) ⟩ (x ∷ xs) 1# ∎ compare-bit : ∀ a b xs → Difference ((a ∷ xs) 1#) ((b ∷ xs) 1#) compare-bit 0b 0b xs = equal refl compare-bit 1b 0b xs = positive (greater [] (seems-trivial xs)) compare-bit 0b 1b xs = negative (greater [] (seems-trivial xs)) compare-bit 1b 1b xs = equal refl compare-bit (2+ ()) _ xs compare-bit _ (2+ ()) xs _-⁺_ : ∀ a b → Difference (a 1#) (b 1#) [] -⁺ [] = equal refl [] -⁺ (x ∷ xs) = negative (greater (∷-pred x xs) (1+∷-pred x xs)) (x ∷ xs) -⁺ [] = positive (greater (∷-pred x xs) (1+∷-pred x xs)) (x ∷ xs) -⁺ (y ∷ ys) = case xs -⁺ ys of λ { (positive gt) → positive (refineGt xs ys x y gt) ; (negative lt) → negative (refineGt ys xs y x lt) ; (equal refl) → compare-bit _ _ xs } _-?_ : ∀ a b → Difference a b 0# -? 0# = equal refl a 1# -? 0# = positive (greater a (identityˡ (a 1#))) 0# -? a 1# = negative (greater a (identityˡ (a 1#))) a 1# -? b 1# = a -⁺ b _%⁺_ : Bin⁺ → Bin⁺ → Comparison Bin⁺ [] %⁺ [] = equal (h ∷ t) %⁺ [] = greater (∷-pred h t) [] %⁺ (h ∷ t) = less (∷-pred h t) (x ∷ xs) %⁺ (y ∷ ys) with xs %⁺ ys ... | greater gt = greater (addBit gt (x %f y)) ... | less lt = less (addBit lt (y %f x)) ... | equal = map-cmp (λ _ → []) (x %f y) succ : Bin⁺ → Bin⁺ succ [] = zero ∷ [] succ (zero ∷ t) = suc zero ∷ t succ (suc zero ∷ t) = zero ∷ succ t succ (suc (suc ()) ∷ t) succpred-id : ∀ x xs → succ (∷-pred x xs) ≡ x ∷ xs succpred-id zero [] = refl succpred-id zero (x ∷ xs) = cong (λ z → zero ∷ z) (succpred-id x xs) succpred-id (suc zero) xs = refl succpred-id (suc (suc ())) xs -- CR: difference-to-∸ : ∀ {a b} → Difference a b → Bin -- difference-to-bin _-_ : Bin → Bin → Bin x - y with x -? y ... | positive (greater d _) = d 1# ... | equal _ = 0# ... | negative _ = 0# open import Data.Bin.Bijection using (fromℕ-bijection; toℕ-inj; fromToℕ-inverse; fromℕ-inj) open import Data.Bin.Addition using (+-is-addition) suc-inj : ∀ {x y : ℕ} → Data.Nat.suc x ≡ suc y → x ≡ y suc-inj {x} .{x} refl = refl ℕ-+-inj₂ : ∀ z {a b} → Data.Nat._+_ z a ≡ Data.Nat._+_ z b → a ≡ b ℕ-+-inj₂ zero refl = refl ℕ-+-inj₂ (suc n) eq = ℕ-+-inj₂ n (suc-inj eq) +-inj₂ : ∀ z {a b} → z + a ≡ z + b → a ≡ b +-inj₂ z {a} {b} z+a≡z+b = toℕ-inj ( ℕ-+-inj₂ (toℕ z) (sym (+-is-addition z a) ⟨ trans ⟩ cong toℕ z+a≡z+b ⟨ trans ⟩ +-is-addition z b) ) nat-+zz : ∀ a b → Data.Nat._+_ a b ≡ 0 → a ≡ 0 nat-+zz zero b _ = refl nat-+zz (suc _) b () +zz : ∀ a b → a + b ≡ 0# → a ≡ 0# +zz a b eq = toℕ-inj (nat-+zz (toℕ a) (toℕ b) (sym (+-is-addition a b) ⟨ trans ⟩ cong toℕ eq)) minus-elim : ∀ x z → z + x - z ≡ x minus-elim x z with (z + x -? z) ... | positive (greater d z+d=z+x) = +-inj₂ z z+d=z+x ... | equal z+x≡z = +-inj₂ z (identityʳ z ⟨ trans ⟩ sym z+x≡z) ... | negative (greater d z+x+d≡z) = sym (+zz x (d 1#) (+-inj₂ z ( sym (+-assoc z x (d 1#)) ⟨ trans ⟩ z+x+d≡z ⟨ trans ⟩ sym (identityʳ z)))) import Data.Bin.NatHelpers x≮z→x≡z+y : ∀ {x z} → ¬ x < z → ∃ λ y → x ≡ z + y x≮z→x≡z+y {x} {z} x≮z = case Data.Bin.NatHelpers.x≮z→x≡z+y (λ toℕ-leq → x≮z (less toℕ-leq)) of λ { (y , eq) → fromℕ y , toℕ-inj ( begin toℕ x ≡⟨ eq ⟩ toℕ z ℕ+ y ≡⟨ cong (λ q → toℕ z ℕ+ q) (fromℕ-inj (sym (fromToℕ-inverse (fromℕ y)))) ⟩ toℕ z ℕ+ toℕ (fromℕ y) ≡⟨ sym (+-is-addition z (fromℕ y)) ⟩ toℕ (z + fromℕ y) ∎) } -+-elim' : ∀ {x z} → ¬ x < z → x - z + z ≡ x -+-elim' {x} {z} x≮z = case x≮z→x≡z+y x≮z of λ { (y , refl) → begin z + y - z + z ≡⟨ cong (λ q → q + z) (minus-elim y z)⟩ y + z ≡⟨ +-comm y z ⟩ z + y ∎ }
{ "alphanum_fraction": 0.489693998, "avg_line_length": 31.7377521614, "ext": "agda", "hexsha": "36055be3b3f59fbbdf035d13cf8338fa3fae2427", "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": "09cc5104421e88da82f9fead5a43f0028f77810d", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "Rotsor/BinDivMod", "max_forks_repo_path": "Data/Bin/Minus.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "Rotsor/BinDivMod", "max_issues_repo_path": "Data/Bin/Minus.agda", "max_line_length": 190, "max_stars_count": 1, "max_stars_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "Rotsor/BinDivMod", "max_stars_repo_path": "Data/Bin/Minus.agda", "max_stars_repo_stars_event_max_datetime": "2019-11-18T13:58:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-11-18T13:58:14.000Z", "num_tokens": 5125, "size": 11013 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Homogeneously-indexed binary relations ------------------------------------------------------------------------ -- The contents of this module should be accessed via -- `Relation.Binary.Indexed.Homogeneous`. {-# OPTIONS --without-K --safe #-} module Relation.Binary.Indexed.Homogeneous.Bundles where open import Data.Product using (_,_) open import Function using (_⟨_⟩_) open import Level using (Level; _⊔_; suc) open import Relation.Binary as B using (_⇒_) open import Relation.Binary.PropositionalEquality as P using (_≡_) open import Relation.Nullary using (¬_) open import Relation.Binary.Indexed.Homogeneous.Core open import Relation.Binary.Indexed.Homogeneous.Structures -- Indexed structures are laid out in a similar manner as to those -- in Relation.Binary. The main difference is each structure also -- contains proofs for the lifted version of the relation. ------------------------------------------------------------------------ -- Equivalences 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 Carrier : Set _ Carrier = ∀ i → Carrierᵢ i _≈_ : B.Rel Carrier _ _≈_ = Lift Carrierᵢ _≈ᵢ_ _≉_ : B.Rel Carrier _ x ≉ y = ¬ (x ≈ y) setoid : B.Setoid _ _ setoid = record { isEquivalence = isEquivalence } record IndexedDecSetoid {i} (I : Set i) c ℓ : Set (suc (i ⊔ c ⊔ ℓ)) where infix 4 _≈ᵢ_ field Carrierᵢ : I → Set c _≈ᵢ_ : IRel Carrierᵢ ℓ isDecEquivalenceᵢ : IsIndexedDecEquivalence Carrierᵢ _≈ᵢ_ open IsIndexedDecEquivalence isDecEquivalenceᵢ public indexedSetoid : IndexedSetoid I c ℓ indexedSetoid = record { isEquivalenceᵢ = isEquivalenceᵢ } open IndexedSetoid indexedSetoid public using (Carrier; _≈_; _≉_; setoid) ------------------------------------------------------------------------ -- Preorders record IndexedPreorder {i} (I : Set i) c ℓ₁ ℓ₂ : Set (suc (i ⊔ c ⊔ ℓ₁ ⊔ ℓ₂)) where infix 4 _≈ᵢ_ _∼ᵢ_ _≈_ _∼_ field Carrierᵢ : I → Set c _≈ᵢ_ : IRel Carrierᵢ ℓ₁ _∼ᵢ_ : IRel Carrierᵢ ℓ₂ isPreorderᵢ : IsIndexedPreorder Carrierᵢ _≈ᵢ_ _∼ᵢ_ open IsIndexedPreorder isPreorderᵢ public Carrier : Set _ Carrier = ∀ i → Carrierᵢ i _≈_ : B.Rel Carrier _ x ≈ y = ∀ i → x i ≈ᵢ y i _∼_ : B.Rel Carrier _ x ∼ y = ∀ i → x i ∼ᵢ y i preorder : B.Preorder _ _ _ preorder = record { isPreorder = isPreorder } ------------------------------------------------------------------------ -- Partial orders record IndexedPoset {i} (I : Set i) c ℓ₁ ℓ₂ : Set (suc (i ⊔ c ⊔ ℓ₁ ⊔ ℓ₂)) where field Carrierᵢ : I → Set c _≈ᵢ_ : IRel Carrierᵢ ℓ₁ _≤ᵢ_ : IRel Carrierᵢ ℓ₂ isPartialOrderᵢ : IsIndexedPartialOrder Carrierᵢ _≈ᵢ_ _≤ᵢ_ open IsIndexedPartialOrder isPartialOrderᵢ public preorderᵢ : IndexedPreorder I c ℓ₁ ℓ₂ preorderᵢ = record { isPreorderᵢ = isPreorderᵢ } open IndexedPreorder preorderᵢ public using (Carrier; _≈_; preorder) renaming (_∼_ to _≤_) poset : B.Poset _ _ _ poset = record { isPartialOrder = isPartialOrder }
{ "alphanum_fraction": 0.5875509017, "avg_line_length": 27.2857142857, "ext": "agda", "hexsha": "a0fc42d2bc54ca32f3e7af4e39714eb9af7bf125", "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/Homogeneous/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/Homogeneous/Bundles.agda", "max_line_length": 73, "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/Homogeneous/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": 1126, "size": 3438 }
------------------------------------------------------------------------------ -- FOTC combinators for lists, colists, streams, etc. ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Base.List where open import FOTC.Base infixr 5 _∷_ ------------------------------------------------------------------------------ -- List constants. postulate [] cons head tail null : D -- FOTC partial lists. -- Definitions abstract _∷_ : D → D → D x ∷ xs = cons · x · xs -- {-# ATP definition _∷_ #-} head₁ : D → D head₁ xs = head · xs -- {-# ATP definition head₁ #-} tail₁ : D → D tail₁ xs = tail · xs -- {-# ATP definition tail₁ #-} null₁ : D → D null₁ xs = null · xs -- {-# ATP definition null₁ #-} ------------------------------------------------------------------------------ -- Conversion rules -- Conversion rules for null. -- null-[] : null · [] ≡ true -- null-∷ : ∀ x xs → null · (cons · x · xs) ≡ false postulate null-[] : null₁ [] ≡ true null-∷ : ∀ x xs → null₁ (x ∷ xs) ≡ false -- Conversion rule for head. -- head-∷ : ∀ x xs → head · (cons · x · xs) ≡ x postulate head-∷ : ∀ x xs → head₁ (x ∷ xs) ≡ x {-# ATP axiom head-∷ #-} -- Conversion rule for tail. -- tail-∷ : ∀ x xs → tail · (cons · x · xs) ≡ xs postulate tail-∷ : ∀ x xs → tail₁ (x ∷ xs) ≡ xs {-# ATP axiom tail-∷ #-} ------------------------------------------------------------------------------ -- Discrimination rules -- postulate []≢cons : ∀ {x xs} → [] ≢ cons · x · xs postulate []≢cons : ∀ {x xs} → [] ≢ x ∷ xs
{ "alphanum_fraction": 0.4062146893, "avg_line_length": 28.0952380952, "ext": "agda", "hexsha": "c19218438b07a0ebbec1fc1b2de8cfda098a4d6c", "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/List.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/List.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/FOTC/Base/List.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": 478, "size": 1770 }
{-# OPTIONS --no-syntactic-equality #-} open import Agda.Primitive variable a : Level postulate A : Set a
{ "alphanum_fraction": 0.6814159292, "avg_line_length": 11.3, "ext": "agda", "hexsha": "7426c716fac4fe45e8dd548cef85e29f4b67094a", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "test/Succeed/Issue4265.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "test/Succeed/Issue4265.agda", "max_line_length": 39, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cruhland/agda", "max_stars_repo_path": "test/Succeed/Issue4265.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": 34, "size": 113 }
module MultipleIdentifiersOneSignature where data Bool : Set where false true : Bool data Suit : Set where ♥ ♢ ♠ ♣ : Suit record R : Set₁ where field A B C : Set postulate A Char : Set B C : Set {-# BUILTIN CHAR Char #-} {-# BUILTIN BOOL Bool #-} {-# BUILTIN TRUE true #-} {-# BUILTIN FALSE false #-} primitive primIsDigit primIsSpace : Char → Bool
{ "alphanum_fraction": 0.6342105263, "avg_line_length": 15.8333333333, "ext": "agda", "hexsha": "d1a98d0061cbcc968300b5ab75e8acdce13d5c20", "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": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/agda-kanso", "max_forks_repo_path": "test/succeed/MultipleIdentifiersOneSignature.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "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": "asr/agda-kanso", "max_issues_repo_path": "test/succeed/MultipleIdentifiersOneSignature.agda", "max_line_length": 44, "max_stars_count": null, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/succeed/MultipleIdentifiersOneSignature.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 114, "size": 380 }
{-# OPTIONS --type-in-type #-} module Spire.DarkwingDuck.Primitive where ---------------------------------------------------------------------- infixr 4 _,_ infixr 5 _∷_ ---------------------------------------------------------------------- postulate String : Set {-# BUILTIN STRING String #-} ---------------------------------------------------------------------- data ⊥ : Set where elimBot : (P : ⊥ → Set) (v : ⊥) → P v elimBot P () ---------------------------------------------------------------------- data ⊤ : Set where tt : ⊤ elimUnit : (P : ⊤ → Set) (ptt : P tt) (u : ⊤) → P u elimUnit P ptt tt = ptt ---------------------------------------------------------------------- data Σ (A : Set) (B : A → Set) : Set where _,_ : (a : A) (b : B a) → Σ A B elimPair : (A : Set) (B : A → Set) (P : Σ A B → Set) (ppair : (a : A) (b : B a) → P (a , b)) (ab : Σ A B) → P ab elimPair A B P ppair (a , b) = ppair a b ---------------------------------------------------------------------- data _≡_ {A : Set} (x : A) : {B : Set} → B → Set where refl : x ≡ x elimEq : (A : Set) (x : A) (P : (y : A) → x ≡ y → Set) (prefl : P x refl) (y : A) (q : x ≡ y) → P y q elimEq A .x P prefl x refl = prefl ---------------------------------------------------------------------- data Enum : Set where [] : Enum _∷_ : (x : String) (xs : Enum) → Enum elimEnum : (P : Enum → Set) (pnil : P []) (pcons : (x : String) (xs : Enum) → P xs → P (x ∷ xs)) (xs : Enum) → P xs elimEnum P pnil pcons [] = pnil elimEnum P pnil pcons (x ∷ xs) = pcons x xs (elimEnum P pnil pcons xs) ---------------------------------------------------------------------- data Tag : Enum → Set where here : ∀{x xs} → Tag (x ∷ xs) there : ∀{x xs} → Tag xs → Tag (x ∷ xs) Branches : (E : Enum) (P : Tag E → Set) → Set Branches [] P = ⊤ Branches (l ∷ E) P = Σ (P here) (λ _ → Branches E (λ t → P (there t))) case : (E : Enum) (P : Tag E → Set) (cs : Branches E P) (t : Tag E) → P t case (ℓ ∷ E) P ccs here = elimPair (P here) (λ _ → Branches E (λ t → P (there t))) (λ _ → P here) (λ c cs → c) ccs case (ℓ ∷ E) P ccs (there t) = elimPair (P here) (λ _ → Branches E (λ t → P (there t))) (λ _ → P (there t)) (λ c cs → case E (λ t → P (there t)) cs t) ccs ---------------------------------------------------------------------- data Tel : Set₁ where Emp : Tel Ext : (A : Set) (B : A → Tel) → Tel elimTel : (P : Tel → Set) (pemp : P Emp) (pext : (A : Set) (B : A → Tel) (pb : (a : A) → P (B a)) → P (Ext A B)) (T : Tel) → P T elimTel P pemp pext Emp = pemp elimTel P pemp pext (Ext A B) = pext A B (λ a → elimTel P pemp pext (B a)) ---------------------------------------------------------------------- data Desc (I : Set) : Set₁ where End : (i : I) → Desc I Rec : (i : I) (D : Desc I) → Desc I Arg : (A : Set) (B : A → Desc I) → Desc I elimDesc : (I : Set) (P : Desc I → Set) (pend : (i : I) → P (End i)) (prec : (i : I) (D : Desc I) (pd : P D) → P (Rec i D)) (parg : (A : Set) (B : A → Desc I) (pb : (a : A) → P (B a)) → P (Arg A B)) (D : Desc I) → P D elimDesc I P pend prec parg (End i) = pend i elimDesc I P pend prec parg (Rec i D) = prec i D (elimDesc I P pend prec parg D) elimDesc I P pend prec parg (Arg A B) = parg A B (λ a → elimDesc I P pend prec parg (B a)) Func : (I : Set) (D : Desc I) → (I → Set) → I → Set Func I (End j) X i = j ≡ i Func I (Rec j D) X i = Σ (X j) (λ _ → Func I D X i) Func I (Arg A B) X i = Σ A (λ a → Func I (B a) X i) Hyps : (I : Set) (D : Desc I) (X : I → Set) (M : (i : I) → X i → Set) (i : I) (xs : Func I D X i) → Set Hyps I (End j) X M i q = ⊤ Hyps I (Rec j D) X M i = elimPair (X j) (λ _ → Func I D X i) (λ _ → Set) (λ x xs → Σ (M j x) (λ _ → Hyps I D X M i xs)) Hyps I (Arg A B) X M i = elimPair A (λ a → Func I (B a) X i) (λ _ → Set) (λ a xs → Hyps I (B a) X M i xs) ---------------------------------------------------------------------- data μ (ℓ : String) (P I : Set) (D : Desc I) (p : P) (i : I) : Set where init : Func I D (μ ℓ P I D p) i → μ ℓ P I D p i prove : (I : Set) (D : Desc I) (X : I → Set) (M : (i : I) → X i → Set) (m : (i : I) (x : X i) → M i x) (i : I) (xs : Func I D X i) → Hyps I D X M i xs prove I (End j) X M m i q = tt prove I (Rec j D) X M m i = elimPair (X j) (λ _ → Func I D X i) (λ xxs → Hyps I (Rec j D) X M i xxs) (λ x xs → m j x , prove I D X M m i xs) prove I (Arg A B) X M m i = elimPair A (λ a → Func I (B a) X i) (λ axs → Hyps I (Arg A B) X M i axs) (λ a xs → prove I (B a) X M m i xs) {-# NO_TERMINATION_CHECK #-} ind : (ℓ : String) (P I : Set) (D : Desc I) (p : P) (M : (i : I) → μ ℓ P I D p i → Set) (α : ∀ i (xs : Func I D (μ ℓ P I D p) i) (ihs : Hyps I D (μ ℓ P I D p) M i xs) → M i (init xs)) (i : I) (x : μ ℓ P I D p i) → M i x ind ℓ P I D p M α i (init xs) = α i xs (prove I D (μ ℓ P I D p) M (ind ℓ P I D p M α) i xs) ----------------------------------------------------------------------
{ "alphanum_fraction": 0.408171521, "avg_line_length": 32.96, "ext": "agda", "hexsha": "478ea94d4670b39bf0d9a7136597c6f852254bb2", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-08-17T21:00:07.000Z", "max_forks_repo_forks_event_min_datetime": "2015-08-17T21:00:07.000Z", "max_forks_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "spire/spire", "max_forks_repo_path": "formalization/agda/Spire/DarkwingDuck/Primitive.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "spire/spire", "max_issues_repo_path": "formalization/agda/Spire/DarkwingDuck/Primitive.agda", "max_line_length": 107, "max_stars_count": 43, "max_stars_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "spire/spire", "max_stars_repo_path": "formalization/agda/Spire/DarkwingDuck/Primitive.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-08T17:10:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-05-28T23:25:33.000Z", "num_tokens": 1883, "size": 4944 }
{-# OPTIONS --safe #-} module Cubical.Algebra.CommRing.Instances.Int where open import Cubical.Foundations.Prelude open import Cubical.Algebra.CommRing open import Cubical.Data.Int as Int renaming ( ℤ to ℤType ; _+_ to _+ℤ_; _·_ to _·ℤ_; -_ to -ℤ_) open CommRingStr ℤ : CommRing ℓ-zero fst ℤ = ℤType 0r (snd ℤ) = 0 1r (snd ℤ) = 1 _+_ (snd ℤ) = _+ℤ_ _·_ (snd ℤ) = _·ℤ_ - snd ℤ = -ℤ_ isCommRing (snd ℤ) = isCommRingℤ where abstract isCommRingℤ : IsCommRing 0 1 _+ℤ_ _·ℤ_ -ℤ_ isCommRingℤ = makeIsCommRing isSetℤ Int.+Assoc (λ _ → refl) -Cancel Int.+Comm Int.·Assoc Int.·Rid ·DistR+ Int.·Comm
{ "alphanum_fraction": 0.6172106825, "avg_line_length": 24.962962963, "ext": "agda", "hexsha": "2973970ade6dfc1cbc34ef4885b82121e01651be", "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/Algebra/CommRing/Instances/Int.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/Algebra/CommRing/Instances/Int.agda", "max_line_length": 63, "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/Algebra/CommRing/Instances/Int.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": 259, "size": 674 }
open import eq open import bool open import bool-relations using (transitive; total) open import maybe open import nat open import nat-thms using (≤-trans; ≤-total) open import product module z05-01-hc-sorted-list-test where open import bool-relations _≤_ hiding (transitive; total) import z05-01-hc-sorted-list as SL open SL nat _≤_ (λ {x} {y} {z} → ≤-trans {x} {y} {z}) (λ {x} {y} → ≤-total {x} {y}) empty : slist 10 10 empty = snil refl _ : slist 9 10 _ = slist-insert 9 empty refl --_ : slist-insert 9 empty refl ≡ scons 9 (snil {!!}) {!!} --_ = refl
{ "alphanum_fraction": 0.6434634975, "avg_line_length": 22.6538461538, "ext": "agda", "hexsha": "b822c724601a7dd798b4e17a784296c760a7d171", "lang": "Agda", "max_forks_count": 8, "max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z", "max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_forks_repo_path": "agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-hc-sorted-list-test.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_issues_repo_path": "agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-hc-sorted-list-test.agda", "max_line_length": 59, "max_stars_count": 36, "max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_stars_repo_path": "agda/book/2015-Verified_Functional_programming_in_Agda-Stump/ial/z05-01-hc-sorted-list-test.agda", "max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z", "num_tokens": 205, "size": 589 }
-- A variant of code reported by Andreas Abel. {-# OPTIONS --guardedness --sized-types #-} open import Agda.Builtin.Size data ⊥ : Set where mutual data D (i : Size) : Set where inn : D' i → D i record D' (i : Size) : Set where coinductive field ♭ : {j : Size< i} → D j open D' bla : ∀{i} → D' i ♭ bla = inn bla -- Should be rejected by termination checker iter : D ∞ → ⊥ iter (inn t) = iter (♭ t) false : ⊥ false = iter (♭ bla)
{ "alphanum_fraction": 0.5859030837, "avg_line_length": 16.8148148148, "ext": "agda", "hexsha": "5ddb50db23094a2a7f0fbd97a90e6c4eca023347", "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/Issue1209-2.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/Issue1209-2.agda", "max_line_length": 46, "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/Issue1209-2.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": 158, "size": 454 }
postulate H I : Set → Set → Set !_ : Set → Set X : Set infix 1 !_ infix 0 H syntax H X Y = X , Y syntax I X Y = Y , X -- This parsed when default fixity was 'unrelated', but with -- an actual default fixity (of any strength) in place it really -- should not. Foo : Set Foo = ! X , X
{ "alphanum_fraction": 0.6169491525, "avg_line_length": 17.3529411765, "ext": "agda", "hexsha": "2a39c08d461c15399b79af6b421985c761b5319a", "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/Issue1436-11.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/Issue1436-11.agda", "max_line_length": 64, "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/Issue1436-11.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": 103, "size": 295 }
open import Nat open import Prelude open import core open import contexts open import lemmas-consistency open import type-assignment-unicity open import lemmas-progress-checks -- taken together, the theorems in this file argue that for any expression -- d, at most one summand of the labeled sum that results from progress may -- be true at any time: that boxed values, indeterminates, and expressions -- that step are pairwise disjoint. -- -- note that as a consequence of currying and comutativity of products, -- this means that there are three theorems to prove. in addition to those, -- we also prove several convenince forms that combine theorems about -- indeterminate and boxed value forms into the same statement about final -- forms, which mirrors the mutual definition of indeterminate and final -- and saves some redundant argumentation. module progress-checks where -- boxed values are not indeterminates boxedval-not-indet : ∀{d} → d boxedval → d indet → ⊥ boxedval-not-indet (BVVal VConst) () boxedval-not-indet (BVVal VLam) () boxedval-not-indet (BVArrCast x bv) (ICastArr x₁ ind) = boxedval-not-indet bv ind boxedval-not-indet (BVHoleCast x bv) (ICastGroundHole x₁ ind) = boxedval-not-indet bv ind boxedval-not-indet (BVHoleCast x bv) (ICastHoleGround x₁ ind x₂) = boxedval-not-indet bv ind -- boxed values don't step boxedval-not-step : ∀{d} → d boxedval → (Σ[ d' ∈ ihexp ] (d ↦ d')) → ⊥ boxedval-not-step (BVVal VConst) (d' , Step FHOuter () x₃) boxedval-not-step (BVVal VLam) (d' , Step FHOuter () x₃) boxedval-not-step (BVArrCast x bv) (d0' , Step FHOuter (ITCastID) FHOuter) = x refl boxedval-not-step (BVArrCast x bv) (_ , Step (FHCast x₁) x₂ (FHCast x₃)) = boxedval-not-step bv (_ , Step x₁ x₂ x₃) boxedval-not-step (BVHoleCast () bv) (d' , Step FHOuter (ITCastID) FHOuter) boxedval-not-step (BVHoleCast x bv) (d' , Step FHOuter (ITCastSucceed ()) FHOuter) boxedval-not-step (BVHoleCast GHole bv) (_ , Step FHOuter (ITGround (MGArr x)) FHOuter) = x refl boxedval-not-step (BVHoleCast x bv) (_ , Step (FHCast x₁) x₂ (FHCast x₃)) = boxedval-not-step bv (_ , Step x₁ x₂ x₃) boxedval-not-step (BVHoleCast x x₁) (_ , Step FHOuter (ITExpand ()) FHOuter) boxedval-not-step (BVHoleCast x x₁) (_ , Step FHOuter (ITCastFail x₂ () x₄) FHOuter) mutual -- indeterminates don't step indet-not-step : ∀{d} → d indet → (Σ[ d' ∈ ihexp ] (d ↦ d')) → ⊥ indet-not-step IEHole (d' , Step FHOuter () FHOuter) indet-not-step (INEHole x) (d' , Step FHOuter () FHOuter) indet-not-step (INEHole x) (_ , Step (FHNEHole x₁) x₂ (FHNEHole x₃)) = final-sub-not-trans x x₁ x₂ indet-not-step (IAp x₁ () x₂) (_ , Step FHOuter (ITLam) FHOuter) indet-not-step (IAp x (ICastArr x₁ ind) x₂) (_ , Step FHOuter (ITApCast) FHOuter) = x _ _ _ _ _ refl indet-not-step (IAp x ind _) (_ , Step (FHAp1 x₂) x₃ (FHAp1 x₄)) = indet-not-step ind (_ , Step x₂ x₃ x₄) indet-not-step (IAp x ind f) (_ , Step (FHAp2 x₃) x₄ (FHAp2 x₆)) = final-not-step f (_ , Step x₃ x₄ x₆) indet-not-step (ICastArr x ind) (d0' , Step FHOuter (ITCastID) FHOuter) = x refl indet-not-step (ICastArr x ind) (_ , Step (FHCast x₁) x₂ (FHCast x₃)) = indet-not-step ind (_ , Step x₁ x₂ x₃) indet-not-step (ICastGroundHole () ind) (d' , Step FHOuter (ITCastID) FHOuter) indet-not-step (ICastGroundHole x ind) (d' , Step FHOuter (ITCastSucceed ()) FHOuter) indet-not-step (ICastGroundHole GHole ind) (_ , Step FHOuter (ITGround (MGArr x₁)) FHOuter) = x₁ refl indet-not-step (ICastGroundHole x ind) (_ , Step (FHCast x₁) x₂ (FHCast x₃)) = indet-not-step ind (_ , Step x₁ x₂ x₃) indet-not-step (ICastHoleGround x ind ()) (d' , Step FHOuter (ITCastID ) FHOuter) indet-not-step (ICastHoleGround x ind g) (d' , Step FHOuter (ITCastSucceed x₂) FHOuter) = x _ _ refl indet-not-step (ICastHoleGround x ind GHole) (_ , Step FHOuter (ITExpand (MGArr x₂)) FHOuter) = x₂ refl indet-not-step (ICastHoleGround x ind g) (_ , Step (FHCast x₁) x₂ (FHCast x₃)) = indet-not-step ind (_ , Step x₁ x₂ x₃) indet-not-step (ICastGroundHole x x₁) (_ , Step FHOuter (ITExpand ()) FHOuter) indet-not-step (ICastHoleGround x x₁ x₂) (_ , Step FHOuter (ITGround ()) FHOuter) indet-not-step (ICastGroundHole x x₁) (_ , Step FHOuter (ITCastFail x₂ () x₄) FHOuter) indet-not-step (ICastHoleGround x x₁ x₂) (_ , Step FHOuter (ITCastFail x₃ x₄ x₅) FHOuter) = x _ _ refl indet-not-step (IFailedCast x x₁ x₂ x₃) (d' , Step FHOuter () FHOuter) indet-not-step (IFailedCast x x₁ x₂ x₃) (_ , Step (FHFailedCast x₄) x₅ (FHFailedCast x₆)) = final-not-step x (_ , Step x₄ x₅ x₆) -- final expressions don't step final-not-step : ∀{d} → d final → Σ[ d' ∈ ihexp ] (d ↦ d') → ⊥ final-not-step (FBoxedVal x) stp = boxedval-not-step x stp final-not-step (FIndet x) stp = indet-not-step x stp
{ "alphanum_fraction": 0.6870874587, "avg_line_length": 66.4109589041, "ext": "agda", "hexsha": "ba44d0c6f79c5b37ee6df00b08a3904d32167d70", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z", "max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_forks_repo_path": "progress-checks.agda", "max_issues_count": 54, "max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z", "max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_issues_repo_path": "progress-checks.agda", "max_line_length": 132, "max_stars_count": 16, "max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda", "max_stars_repo_path": "progress-checks.agda", "max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z", "max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z", "num_tokens": 1705, "size": 4848 }
-- Haskell-like do-notation. module Syntax.Do where open import Functional import Lvl open import Syntax.Idiom open import Type private variable ℓ ℓ₁ ℓ₂ : Lvl.Level private variable A B : Type{ℓ} private variable F : Type{ℓ₁} → Type{ℓ₂} record DoNotation (F : Type{ℓ₁} → Type{ℓ₂}) : Type{Lvl.𝐒(ℓ₁) Lvl.⊔ ℓ₂} where constructor intro field return : A → F(A) _>>=_ : F(A) → (A → F(B)) → F(B) module HaskellNames where _=<<_ : ∀{A B} → (A → F(B)) → F(A) → F(B) _=<<_ = swap(_>>=_) _>>_ : ∀{A B} → F(A) → F(B) → F(B) f >> g = f >>= const g _>=>_ : ∀{A B C : Type} → (A → F(B)) → (B → F(C)) → (A → F(C)) (f >=> g)(A) = f(A) >>= g _<=<_ : ∀{A B C : Type} → (B → F(C)) → (A → F(B)) → (A → F(C)) _<=<_ = swap(_>=>_) idiomBrackets : IdiomBrackets(F) IdiomBrackets.pure idiomBrackets = return IdiomBrackets._<*>_ idiomBrackets Ff Fa = do f <- Ff a <- Fa return(f(a)) open DoNotation ⦃ … ⦄ using (return ; _>>=_) public
{ "alphanum_fraction": 0.5313765182, "avg_line_length": 24.7, "ext": "agda", "hexsha": "754c2ac7a4372add1698f1e20a7fa728ca7f8db6", "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": "Syntax/Do.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": "Syntax/Do.agda", "max_line_length": 76, "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": "Syntax/Do.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": 408, "size": 988 }
{-# OPTIONS --without-K #-} module Model.Terminal where open import Cats.Category open import Model.Type.Core open import Util.HoTT.HLevel open import Util.Prelude hiding (⊤) ⊤ : ∀ {Δ} → ⟦Type⟧ Δ ⊤ = record { ObjHSet = λ _ → HLevel-suc ⊤-HProp ; eqHProp = λ _ _ _ → ⊤-HProp } instance hasTerminal : ∀ {Δ} → HasTerminal (⟦Types⟧ Δ) hasTerminal = record { ⊤ = ⊤ ; isTerminal = λ T → record { arr = record {} ; unique = λ _ → ≈⁺ λ γ x → refl } } private open module HT {Δ} = HasTerminal (hasTerminal {Δ}) public using (! ; !-unique)
{ "alphanum_fraction": 0.5896551724, "avg_line_length": 18.7096774194, "ext": "agda", "hexsha": "87eaea839173b31a5f2e8e9dc6315306f8f0118a", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JLimperg/msc-thesis-code", "max_forks_repo_path": "src/Model/Terminal.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JLimperg/msc-thesis-code", "max_issues_repo_path": "src/Model/Terminal.agda", "max_line_length": 80, "max_stars_count": 5, "max_stars_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JLimperg/msc-thesis-code", "max_stars_repo_path": "src/Model/Terminal.agda", "max_stars_repo_stars_event_max_datetime": "2021-06-26T06:37:31.000Z", "max_stars_repo_stars_event_min_datetime": "2021-04-13T21:31:17.000Z", "num_tokens": 205, "size": 580 }
module tree-io-example where open import io open import list open import maybe open import string open import tree open import unit open import nat-to-string errmsg = "Run with a single (small) number as the command-line argument.\n" processArgs : 𝕃 string → IO ⊤ processArgs (s :: []) with string-to-ℕ s ... | nothing = putStr errmsg ... | just n = putStr (𝕋-to-string ℕ-to-string (perfect-binary-tree n n)) >> putStr "\n" processArgs _ = putStr errmsg main : IO ⊤ main = getArgs >>= processArgs
{ "alphanum_fraction": 0.7089108911, "avg_line_length": 22.9545454545, "ext": "agda", "hexsha": "5af4fb096777ac61eacd3e76b81a35f77d8e9ca1", "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": "tree-io-example.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": "tree-io-example.agda", "max_line_length": 88, "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": "tree-io-example.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": 140, "size": 505 }
module STLC.Syntax where open import Prelude public -------------------------------------------------------------------------------- -- Types infixr 7 _⇒_ data 𝒯 : Set where ⎵ : 𝒯 _⇒_ : (A B : 𝒯) → 𝒯 -------------------------------------------------------------------------------- -- Contexts data 𝒞 : Set where ∅ : 𝒞 _,_ : (Γ : 𝒞) (A : 𝒯) → 𝒞 length : 𝒞 → Nat length ∅ = zero length (Γ , x) = suc (length Γ) lookup : (Γ : 𝒞) (i : Nat) {{_ : True (length Γ >? i)}} → 𝒯 lookup ∅ i {{()}} lookup (Γ , A) zero {{yes}} = A lookup (Γ , B) (suc i) {{p}} = lookup Γ i -- Variables infix 4 _∋_ data _∋_ : 𝒞 → 𝒯 → Set where zero : ∀ {Γ A} → Γ , A ∋ A suc : ∀ {Γ A B} → (i : Γ ∋ A) → Γ , B ∋ A Nat→∋ : ∀ {Γ} → (i : Nat) {{_ : True (length Γ >? i)}} → Γ ∋ lookup Γ i Nat→∋ {Γ = ∅} i {{()}} Nat→∋ {Γ = Γ , A} zero {{yes}} = zero Nat→∋ {Γ = Γ , B} (suc i) {{p}} = suc (Nat→∋ i) instance num∋ : ∀ {Γ A} → Number (Γ ∋ A) num∋ {Γ} {A} = record { Constraint = λ i → Σ (True (length Γ >? i)) (λ p → lookup Γ i {{p}} ≡ A) ; fromNat = λ { i {{p , refl}} → Nat→∋ i } } -------------------------------------------------------------------------------- -- Terms infix 3 _⊢_ data _⊢_ : 𝒞 → 𝒯 → Set where 𝓋 : ∀ {Γ A} → (i : Γ ∋ A) → Γ ⊢ A ƛ : ∀ {Γ A B} → (M : Γ , A ⊢ B) → Γ ⊢ A ⇒ B _∙_ : ∀ {Γ A B} → (M : Γ ⊢ A ⇒ B) (N : Γ ⊢ A) → Γ ⊢ B instance num⊢ : ∀ {Γ A} → Number (Γ ⊢ A) num⊢ {Γ} {A} = record { Constraint = λ i → Σ (True (length Γ >? i)) (λ p → lookup Γ i {{p}} ≡ A) ; fromNat = λ { i {{p , refl}} → 𝓋 (Nat→∋ i) } } -------------------------------------------------------------------------------- -- Normal forms mutual infix 3 _⊢ⁿᶠ_ data _⊢ⁿᶠ_ : 𝒞 → 𝒯 → Set where ƛ : ∀ {Γ A B} → (M : Γ , A ⊢ⁿᶠ B) → Γ ⊢ⁿᶠ A ⇒ B ne : ∀ {Γ} → (M : Γ ⊢ⁿᵉ ⎵) → Γ ⊢ⁿᶠ ⎵ infix 3 _⊢ⁿᵉ_ data _⊢ⁿᵉ_ : 𝒞 → 𝒯 → Set where 𝓋 : ∀ {Γ A} → (i : Γ ∋ A) → Γ ⊢ⁿᵉ A _∙_ : ∀ {Γ A B} → (M : Γ ⊢ⁿᵉ A ⇒ B) (N : Γ ⊢ⁿᶠ A) → Γ ⊢ⁿᵉ B instance num⊢ⁿᵉ : ∀ {Γ A} → Number (Γ ⊢ⁿᵉ A) num⊢ⁿᵉ {Γ} {A} = record { Constraint = λ i → Σ (True (length Γ >? i)) (λ p → lookup Γ i {{p}} ≡ A) ; fromNat = λ { i {{p , refl}} → 𝓋 (Nat→∋ i) } } --------------------------------------------------------------------------------
{ "alphanum_fraction": 0.3009049774, "avg_line_length": 21.216, "ext": "agda", "hexsha": "22b04c7254bdebee8979ffeef71878248687866c", "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": "bd626509948fbf8503ec2e31c1852e1ac6edcc79", "max_forks_repo_licenses": [ "X11" ], "max_forks_repo_name": "mietek/coquand-kovacs", "max_forks_repo_path": "src/STLC/Syntax.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79", "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-kovacs", "max_issues_repo_path": "src/STLC/Syntax.agda", "max_line_length": 80, "max_stars_count": null, "max_stars_repo_head_hexsha": "bd626509948fbf8503ec2e31c1852e1ac6edcc79", "max_stars_repo_licenses": [ "X11" ], "max_stars_repo_name": "mietek/coquand-kovacs", "max_stars_repo_path": "src/STLC/Syntax.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1095, "size": 2652 }
open import Relation.Binary open import Relation.Binary.PropositionalEquality open import Data.Product open import Level module IndexedMap {Index : Set} {Key : Index → Set} {_≈_ _<_ : Rel (∃ Key) zero} (isOrderedKeySet : IsStrictTotalOrder _≈_ _<_) -- Equal keys must have equal indices. (indicesEqual : _≈_ =[ proj₁ ]⇒ _≡_) (Value : Index → Set) where
{ "alphanum_fraction": 0.6348039216, "avg_line_length": 31.3846153846, "ext": "agda", "hexsha": "2e93f26b4829e04d9ab459df5de4a694e1b58f86", "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": "benchmark/monad/IndexedMap.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": "benchmark/monad/IndexedMap.agda", "max_line_length": 71, "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": "benchmark/monad/IndexedMap.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": 112, "size": 408 }
-- 2012-03-08 Andreas module NoTerminationCheck1 where {-# NO_TERMINATION_CHECK #-} -- error: misplaced pragma
{ "alphanum_fraction": 0.7522123894, "avg_line_length": 16.1428571429, "ext": "agda", "hexsha": "72498ce93b22e000e786a162ff6c900dcdc08d0b", "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/NoTerminationCheck1.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/NoTerminationCheck1.agda", "max_line_length": 32, "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/NoTerminationCheck1.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": 30, "size": 113 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Convenient syntax for "equational reasoning" using a partial order ------------------------------------------------------------------------ open import Relation.Binary module Relation.Binary.PartialOrderReasoning {p₁ p₂ p₃} (P : Poset p₁ p₂ p₃) where open Poset P import Relation.Binary.PreorderReasoning as PreR open PreR preorder public renaming (_∼⟨_⟩_ to _≤⟨_⟩_)
{ "alphanum_fraction": 0.5277207392, "avg_line_length": 32.4666666667, "ext": "agda", "hexsha": "e337b0493a5a1a11deed55723751a2e2edd8e6f6", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "qwe2/try-agda", "max_forks_repo_path": "agda-stdlib-0.9/src/Relation/Binary/PartialOrderReasoning.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Apache-2.0" ], "max_issues_repo_name": "qwe2/try-agda", "max_issues_repo_path": "agda-stdlib-0.9/src/Relation/Binary/PartialOrderReasoning.agda", "max_line_length": 72, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Relation/Binary/PartialOrderReasoning.agda", "max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z", "max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z", "num_tokens": 104, "size": 487 }
open import Level module Ordinals where open import zf open import Data.Nat renaming ( zero to Zero ; suc to Suc ; ℕ to Nat ; _⊔_ to _n⊔_ ) open import Data.Empty open import Relation.Binary.PropositionalEquality open import logic open import nat open import Data.Unit using ( ⊤ ) open import Relation.Nullary open import Relation.Binary open import Relation.Binary.Core record Oprev {n : Level} (ord : Set n) (osuc : ord → ord ) (x : ord ) : Set (suc n) where field oprev : ord oprev=x : osuc oprev ≡ x record IsOrdinals {n : Level} (ord : Set n) (o∅ : ord ) (osuc : ord → ord ) (_o<_ : ord → ord → Set n) (next : ord → ord ) : Set (suc (suc n)) where field ordtrans : {x y z : ord } → x o< y → y o< z → x o< z trio< : Trichotomous {n} _≡_ _o<_ ¬x<0 : { x : ord } → ¬ ( x o< o∅ ) <-osuc : { x : ord } → x o< osuc x osuc-≡< : { a x : ord } → x o< osuc a → (x ≡ a ) ∨ (x o< a) Oprev-p : ( x : ord ) → Dec ( Oprev ord osuc x ) TransFinite : { ψ : ord → Set (suc n) } → ( (x : ord) → ( (y : ord ) → y o< x → ψ y ) → ψ x ) → ∀ (x : ord) → ψ x record IsNext {n : Level } (ord : Set n) (o∅ : ord ) (osuc : ord → ord ) (_o<_ : ord → ord → Set n) (next : ord → ord ) : Set (suc (suc n)) where field x<nx : { y : ord } → (y o< next y ) osuc<nx : { x y : ord } → x o< next y → osuc x o< next y ¬nx<nx : {x y : ord} → y o< x → x o< next y → ¬ ((z : ord) → ¬ (x ≡ osuc z)) record Ordinals {n : Level} : Set (suc (suc n)) where field Ordinal : Set n o∅ : Ordinal osuc : Ordinal → Ordinal _o<_ : Ordinal → Ordinal → Set n next : Ordinal → Ordinal isOrdinal : IsOrdinals Ordinal o∅ osuc _o<_ next isNext : IsNext Ordinal o∅ osuc _o<_ next module inOrdinal {n : Level} (O : Ordinals {n} ) where open Ordinals O open IsOrdinals isOrdinal open IsNext isNext TransFinite0 : { ψ : Ordinal → Set n } → ( (x : Ordinal) → ( (y : Ordinal ) → y o< x → ψ y ) → ψ x ) → ∀ (x : Ordinal) → ψ x TransFinite0 {ψ} ind x = lower (TransFinite {λ y → Lift (suc n) ( ψ y)} ind1 x) where ind1 : (z : Ordinal) → ((y : Ordinal) → y o< z → Lift (suc n) (ψ y)) → Lift (suc n) (ψ z) ind1 z prev = lift (ind z (λ y y<z → lower (prev y y<z ) ))
{ "alphanum_fraction": 0.5273738238, "avg_line_length": 37.1111111111, "ext": "agda", "hexsha": "2d313e8c50510cf3aae57ba54d15ff877944d0be", "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": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "shinji-kono/zf-in-agda", "max_forks_repo_path": "src/Ordinals.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "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/zf-in-agda", "max_issues_repo_path": "src/Ordinals.agda", "max_line_length": 150, "max_stars_count": 5, "max_stars_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "shinji-kono/zf-in-agda", "max_stars_repo_path": "src/Ordinals.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-10T13:27:48.000Z", "max_stars_repo_stars_event_min_datetime": "2019-10-02T13:46:23.000Z", "num_tokens": 923, "size": 2338 }
module Fin where data Nat : Set where zero : Nat succ : Nat -> Nat data Fin : Nat -> Set where fzero : {n : Nat} -> Fin (succ n) fsucc : {n : Nat} -> Fin n -> Fin (succ n)
{ "alphanum_fraction": 0.5483870968, "avg_line_length": 18.6, "ext": "agda", "hexsha": "2476f46c256bd8855039d89a21454c0d67805cd6", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andrejtokarcik/agda-semantics", "max_forks_repo_path": "tests/covered/Fin.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andrejtokarcik/agda-semantics", "max_issues_repo_path": "tests/covered/Fin.agda", "max_line_length": 46, "max_stars_count": 3, "max_stars_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "andrejtokarcik/agda-semantics", "max_stars_repo_path": "tests/covered/Fin.agda", "max_stars_repo_stars_event_max_datetime": "2018-12-06T17:24:25.000Z", "max_stars_repo_stars_event_min_datetime": "2015-08-10T15:33:56.000Z", "num_tokens": 63, "size": 186 }
module sets.nat.ordering.leq.alternative where open import equality.core open import equality.calculus open import function.isomorphism open import hott.equivalence.logical open import hott.level.core open import hott.level.sets open import sets.nat.core open import sets.nat.properties open import sets.nat.ordering.leq.core open import sets.nat.ordering.leq.level open import sum Less : ℕ → ℕ → Set _ Less n m = Σ ℕ λ d → n + d ≡ m Less-level : ∀ {n m} → h 1 (Less n m) Less-level {n}{m} = prop⇒h1 λ { (d₁ , p₁) (d₂ , p₂) → unapΣ ( +-left-cancel n (p₁ · sym p₂) , h1⇒prop (nat-set _ _) _ _) } leq-sum : ∀ {n m}(p : n ≤ m) → Less n m leq-sum {m = m} z≤n = m , refl leq-sum (s≤s p) with leq-sum p leq-sum (s≤s p) | d , q = d , ap suc q diff : ∀ {n m} → n ≤ m → ℕ diff p = proj₁ (leq-sum p) sum-leq : ∀ n d → n ≤ (n + d) sum-leq n 0 = ≡⇒≤ (sym (+-right-unit _)) sum-leq n (suc d) = trans≤ (sum-leq n d) (trans≤ suc≤ (≡⇒≤ ( ap suc (+-commutativity n d) · +-commutativity (suc d) n))) leq-sum-iso : ∀ {n m} → (n ≤ m) ≅ Less n m leq-sum-iso = ↔⇒≅ ≤-level Less-level ( leq-sum , (λ { (d , refl) → sum-leq _ d }))
{ "alphanum_fraction": 0.5786375105, "avg_line_length": 29, "ext": "agda", "hexsha": "638ed437dbebebbc0a75bc6b436d3251ebd1565a", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z", "max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z", "max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "pcapriotti/agda-base", "max_forks_repo_path": "src/sets/nat/ordering/leq/alternative.agda", "max_issues_count": 4, "max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z", "max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "pcapriotti/agda-base", "max_issues_repo_path": "src/sets/nat/ordering/leq/alternative.agda", "max_line_length": 68, "max_stars_count": 20, "max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "pcapriotti/agda-base", "max_stars_repo_path": "src/sets/nat/ordering/leq/alternative.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z", "max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z", "num_tokens": 458, "size": 1189 }
module Type.Properties.Empty.Proofs where import Data.Tuple open import Data open import Functional open import Logic.Propositional import Lvl open import Type.Properties.Inhabited open import Type.Properties.Empty open import Type private variable ℓ : Lvl.Level private variable A B T : Type{ℓ} -- A type is never inhabited and empty at the same time. notInhabitedAndEmpty : (◊ T) → IsEmpty(T) → ⊥ notInhabitedAndEmpty (intro ⦃ obj ⦄) (intro empty) with () ← empty{Empty} (obj) -- A type being empty is equivalent to the existence of a function from the type to the empty type of any universe level. empty-negation-eq : IsEmpty(T) ↔ (T → Empty{ℓ}) IsEmpty.empty (Data.Tuple.left empty-negation-eq nt) = empty ∘ nt Data.Tuple.right empty-negation-eq (intro e) t with () ← e {Empty} t empty-by-function : (f : A → B) → (IsEmpty{ℓ}(B) → IsEmpty{ℓ}(A)) empty-by-function f (intro empty-B) = intro(empty-B ∘ f)
{ "alphanum_fraction": 0.7234273319, "avg_line_length": 35.4615384615, "ext": "agda", "hexsha": "c0627d38c7412daec86c73528bef2732b1e56ef0", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Lolirofle/stuff-in-agda", "max_forks_repo_path": "Type/Properties/Empty/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": "Type/Properties/Empty/Proofs.agda", "max_line_length": 121, "max_stars_count": 6, "max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Lolirofle/stuff-in-agda", "max_stars_repo_path": "Type/Properties/Empty/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": 272, "size": 922 }
-- Andreas, 2011-05-30 -- {-# OPTIONS -v tc.lhs.unify:50 #-} module Issue292 where data Bool : Set where true false : Bool data Bool2 : Set where true2 false2 : Bool2 data ⊥ : Set where infix 3 ¬_ ¬_ : Set → Set ¬ P = P → ⊥ infix 4 _≅_ data _≅_ {A : Set} (x : A) : ∀ {B : Set} → B → Set where refl : x ≅ x record Σ (A : Set) (B : A → Set) : Set where constructor _,_ field proj₁ : A proj₂ : B proj₁ open Σ public P : Set -> Set P S = Σ S (\s → s ≅ true) pbool : P Bool pbool = true , refl -- the following should fail: ¬pbool2 : ¬ P Bool2 ¬pbool2 ( true2 , () ) ¬pbool2 ( false2 , () ) {- using subst, one could now prove distinctness of types, which we don't want tada : ¬ (Bool ≡ Bool2) tada eq = ¬pbool2 (subst (\ S → P S) eq pbool ) -}
{ "alphanum_fraction": 0.5851755527, "avg_line_length": 18.3095238095, "ext": "agda", "hexsha": "f27eb1343f1b5c9d9aaae9adb609888fb2530826", "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/fail/Issue292.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/Issue292.agda", "max_line_length": 78, "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/Issue292.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": 295, "size": 769 }
module Structure.Relator.Equivalence.Proofs where import Lvl open import Functional open import Structure.Relator.Equivalence open import Structure.Relator.Properties.Proofs open import Type private variable ℓ : Lvl.Level private variable T A B : Type{ℓ} private variable _▫_ : T → T → Type{ℓ} private variable f : A → B on₂-equivalence : ⦃ eq : Equivalence(_▫_) ⦄ → Equivalence((_▫_) on₂ f) Equivalence.reflexivity (on₂-equivalence {_▫_ = _▫_}) = on₂-reflexivity Equivalence.symmetry (on₂-equivalence {_▫_ = _▫_}) = on₂-symmetry Equivalence.transitivity (on₂-equivalence {_▫_ = _▫_}) = on₂-transitivity
{ "alphanum_fraction": 0.7439222042, "avg_line_length": 34.2777777778, "ext": "agda", "hexsha": "8d9c736ab3649358c23d2ecf5dbeb73374e807d1", "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/Relator/Equivalence/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": "Structure/Relator/Equivalence/Proofs.agda", "max_line_length": 73, "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/Relator/Equivalence/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": 196, "size": 617 }
{-# OPTIONS --universe-polymorphism #-} module Categories.Category.Construction.F-Algebras where open import Level open import Data.Product using (proj₁; proj₂) open import Categories.Category open import Categories.Functor hiding (id) open import Categories.Functor.Algebra open import Categories.Object.Initial import Categories.Morphism.Reasoning as MR import Categories.Morphism as Mor using (_≅_) private variable o ℓ e : Level 𝒞 : Category o ℓ e F-Algebras : {𝒞 : Category o ℓ e} → Endofunctor 𝒞 → Category (ℓ ⊔ o) (e ⊔ ℓ) e F-Algebras {𝒞 = 𝒞} F = record { Obj = F-Algebra F ; _⇒_ = F-Algebra-Morphism ; _≈_ = λ α₁ α₂ → f α₁ ≈ f α₂ ; _∘_ = λ α₁ α₂ → record { f = f α₁ ∘ f α₂ ; commutes = commut α₁ α₂ } ; id = record { f = id ; commutes = identityˡ ○ ⟺ identityʳ ○ ⟺ (∘-resp-≈ʳ identity) } ; assoc = assoc ; sym-assoc = sym-assoc ; identityˡ = identityˡ ; identityʳ = identityʳ ; identity² = identity² ; equiv = record { refl = refl ; sym = sym ; trans = trans } ; ∘-resp-≈ = ∘-resp-≈ } where open Category 𝒞 open Equiv open HomReasoning using (⟺; _○_; begin_; _≈⟨_⟩_; _∎) open Functor F open F-Algebra-Morphism open F-Algebra commut : {A B C : F-Algebra F} (α₁ : F-Algebra-Morphism B C) (α₂ : F-Algebra-Morphism A B) → (f α₁ ∘ f α₂) ∘ α A ≈ α C ∘ F₁ (f α₁ ∘ f α₂) commut {A} {B} {C} α₁ α₂ = begin (f α₁ ∘ f α₂) ∘ α A ≈⟨ assoc ○ ∘-resp-≈ʳ (commutes α₂) ⟩ f α₁ ∘ (α B ∘ F₁ (f α₂)) ≈⟨ ⟺ assoc ○ ∘-resp-≈ˡ (commutes α₁) ⟩ (α C ∘ F₁ (f α₁)) ∘ F₁ (f α₂) ≈⟨ assoc ○ ∘-resp-≈ʳ (⟺ homomorphism) ⟩ α C ∘ F₁ (f α₁ ∘ f α₂) ∎ module Lambek {𝒞 : Category o ℓ e} {F : Endofunctor 𝒞} (I : Initial (F-Algebras F)) where open Category 𝒞 open Functor F open F-Algebra using (α) open MR 𝒞 using (glue) open Mor 𝒞 open Initial I -- so ⊥ is an F-Algebra, which is initial -- While an expert might be able to decipher the proof at the nLab -- (https://ncatlab.org/nlab/show/initial+algebra+of+an+endofunctor) -- I (JC) have found that the notes at -- http://www.cs.ru.nl/~jrot/coalgebra/ak-algebras.pdf -- are easier to follow, and lead to the full proof below. private module ⊥ = F-Algebra ⊥ A = ⊥.A a : F₀ A ⇒ A a = ⊥.α -- The F-Algebra structure that will make things work F⊥ : F-Algebra F F⊥ = iterate ⊥ -- By initiality, we get the following morphism f : F-Algebra-Morphism ⊥ F⊥ f = ! module FAM = F-Algebra-Morphism f i : A ⇒ F₀ A i = FAM.f a∘f : F-Algebra-Morphism ⊥ ⊥ a∘f = record { f = a ∘ i ; commutes = glue triv FAM.commutes ○ ∘-resp-≈ʳ (⟺ homomorphism) } where open HomReasoning using (_○_; ⟺) triv : CommutativeSquare (α F⊥) (α F⊥) a a triv = Equiv.refl lambek : A ≅ F₀ A lambek = record { from = i ; to = a ; iso = record { isoˡ = ⊥-id a∘f ; isoʳ = begin i ∘ a ≈⟨ F-Algebra-Morphism.commutes f ⟩ F₁ a ∘ F₁ i ≈˘⟨ homomorphism ⟩ F₁ (a ∘ i) ≈⟨ F-resp-≈ (⊥-id a∘f) ⟩ F₁ id ≈⟨ identity ⟩ id ∎ } } where open HomReasoning
{ "alphanum_fraction": 0.5651771957, "avg_line_length": 28.7168141593, "ext": "agda", "hexsha": "2f3beba717ddf80935dac0bf41e1380191d37dad", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Taneb/agda-categories", "max_forks_repo_path": "Categories/Category/Construction/F-Algebras.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Taneb/agda-categories", "max_issues_repo_path": "Categories/Category/Construction/F-Algebras.agda", "max_line_length": 96, "max_stars_count": null, "max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Taneb/agda-categories", "max_stars_repo_path": "Categories/Category/Construction/F-Algebras.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1306, "size": 3245 }
-- ---------------------------------------------------------------------- -- The Agda Descriptor Library -- -- (Open) Descriptors -- ---------------------------------------------------------------------- module Data.Desc where open import Data.List using (List; []; _∷_) open import Data.List.Relation.Unary.All using (All; []; _∷_) open import Data.List.Relation.Unary.Any using (here; there) open import Data.List.Membership.Propositional using (_∈_) open import Data.Product using (Σ; _,_) open import Data.Var using (_-Scoped[_]; Var; get; zero; suc; tabulate) open import Data.Unit.Polymorphic using (⊤; tt) open import Level using (Level; 0ℓ; _⊔_) open import Relation.Unary using (IUniversal; _⇒_) private variable A : Set 1ℓ : Level 1ℓ = Level.suc 0ℓ -- ---------------------------------------------------------------------- -- Definition -- -- An open description is a open dependent type theory. -- Our theoretic model is described by: -- -- Metatheoretic terms: -- -- Agda sets A, B ∷= ... -- Agda values x, y ∷= ... -- -- Open object terms: -- -- kinds κ ∷= Set | Π A κ -- types T ∷= a | T x | Π A T | T ⟶ T -- -- A descriptor is a set of well-kinded constructor types. data Kind : Set₁ where `Set₀ : Kind `Π : (A : Set) → (A → Kind) → Kind private variable κ κ′ : Kind Γ : List Kind B : A → Kind infixr 6 _⟶_ data Type : Kind -Scoped[ 1ℓ ] where `_ : ∀[ Var κ ⇒ Type κ ] _·_ : Type (`Π A B) Γ → (a : A) → Type (B a) Γ `Π : (A : Set) → (A → Type `Set₀ Γ) → Type `Set₀ Γ _⟶_ : Type `Set₀ Γ → Type `Set₀ Γ → Type `Set₀ Γ mutual data Pos : Type κ Γ → Set where `_ : ∀ (x : Var κ Γ) -- ---------------- → Pos (` x) _·_ : ∀ {T : Type (`Π A B) Γ} → Pos T → (a : A) -- ------------------------ → Pos (T · a) `Π : (A : Set) {T : A → Type `Set₀ Γ} → ((a : A) → Pos (T a)) -- -------------------------------- → Pos (`Π A T) _⟶_ : ∀ {T T′ : Type `Set₀ Γ} → Neg T → Pos T′ -- -------------------------- → Pos (T ⟶ T′) data Neg : Type κ Γ → Set where _·_ : ∀ {T : Type (`Π A B) Γ} → Neg T → (a : A) -- ------------------------ → Neg (T · a) `Π : (A : Set) {T : A → Type `Set₀ Γ} → ((a : A) → Neg (T a)) -- -------------------------------- → Neg (`Π A T) _⟶_ : ∀ {T T′ : Type `Set₀ Γ} → Pos T → Neg T′ -- -------------------------- → Neg (T ⟶ T′) data StrictPos : Type κ Γ → Set where `_ : ∀ (x : Var κ Γ) -- ---------------- → StrictPos (` x) _·_ : ∀ {T : Type (`Π A B) Γ} → StrictPos T → (a : A) -- ------------------------ → StrictPos (T · a) `Π : (A : Set) {T : A → Type `Set₀ Γ} → ((a : A) → StrictPos (T a)) -- -------------------------------- → StrictPos (`Π A T) data Con : Type κ Γ → Set where `_ : ∀ (x : Var κ Γ) -- ---------------- → Con (` x) _·_ : ∀ {T : Type (`Π A B) Γ} → Con T → (a : A) -- ------------------------ → Con (T · a) `Π : (A : Set) {T : A → Type `Set₀ Γ} → ((a : A) → Con (T a)) -- -------------------------------- → Con (`Π A T) _⟶_ : ∀ {T T′ : Type `Set₀ Γ} → StrictPos T → Con T′ -- -------------------------- → Con (T ⟶ T′) data Constr : Kind -Scoped[ 1ℓ ] where ! : {T : Type κ Γ} → Con T → Constr κ Γ ++⇒C : ∀{T : Type κ Γ} → StrictPos T → Con T ++⇒C (` x) = ` x ++⇒C (P · a) = ++⇒C P · a ++⇒C (`Π A P) = `Π A (λ a → ++⇒C (P a)) Desc : List Kind → Set₁ Desc Γ = List (Constr `Set₀ Γ) -- ---------------------------------------------------------------------- -- Interpretation lift⟦_⟧ᴷ : Kind → (ℓ : Level) → Set (Level.suc ℓ) lift⟦ `Set₀ ⟧ᴷ ℓ = Set ℓ lift⟦ `Π A κ ⟧ᴷ ℓ = (a : A) → lift⟦ κ a ⟧ᴷ ℓ -- Lifting of lift⟦_⟧ᴷ to a context lift⟪_⟫ᴷ : List Kind → (ℓ : Level) → Set (Level.suc ℓ) lift⟪ Γ ⟫ᴷ ℓ = All (λ κ → lift⟦ κ ⟧ᴷ ℓ) Γ ⟦_⟧ᴷ : Kind → Set₁ ⟦ `Set₀ ⟧ᴷ = Set ⟦ `Π A κ ⟧ᴷ = (a : A) → ⟦ κ a ⟧ᴷ ⟪_⟫ᴷ : List Kind → Set₁ ⟪ Γ ⟫ᴷ = All ⟦_⟧ᴷ Γ -- ---------------------------------------------------------------------- -- Fixpoint -- -- To define the fixed point, we're looking for a fixpoint of the form: -- μ : Desc Γ → ⟪ Γ ⟫ᴷ -- -- To consider the interpretation of constructors and type formers, -- we first describe the terms formed by constructors and -- positive types: -- -- constructor terms c ∷= Constrᵢ | c · a | c · p private variable C : Constr `Set₀ Γ D : Desc Γ data Term : Constr `Set₀ Γ -Scoped[ 1ℓ ] where `Constr : ∀[ Var C ⇒ Term C ] _·_ : ∀ {A} {T : A → Type `Set₀ Γ} {C : (a : A) → Con (T a)} → Term (! (`Π A C)) D → (a : A) → Term (! (C a)) D _•_ : ∀ {T T′ : Type `Set₀ Γ} {P : StrictPos T} {C : Con T′} → Term (! (P ⟶ C)) D → Term (! (++⇒C P)) D → Term (! C) D μᵏ : Constr κ Γ → Desc Γ → lift⟦ κ ⟧ᴷ 1ℓ μᵏ {κ = `Set₀} C D = Term C D μᵏ {κ = `Π _ _} (! C) D = λ a → μᵏ (! (C · a)) D μᴰ : Desc Γ → lift⟪ Γ ⟫ᴷ 1ℓ μᴰ D = tabulate λ x → μᵏ (! (` x)) D -- ---------------------------------------------------------------------- -- Examples ℕᴰ : Desc (`Set₀ ∷ []) ℕᴰ = ! (` zero) ∷ ! ((` zero) ⟶ (` zero)) ∷ [] `ℕ : Set₁ `ℕ = get zero (μᴰ ℕᴰ) pattern `zero = `Constr zero pattern `suc n = `Constr (suc zero) • n _ : `ℕ _ = `suc (`suc `zero)
{ "alphanum_fraction": 0.4081860465, "avg_line_length": 23.0686695279, "ext": "agda", "hexsha": "c1b0faa225c32422f3fb3219e97859ee3f4bdbff", "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": "27fd49914d5ce1cc90d319089686861b33e8f19f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "johnyob/agda-desc", "max_forks_repo_path": "src/Data/Desc.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "27fd49914d5ce1cc90d319089686861b33e8f19f", "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": "johnyob/agda-desc", "max_issues_repo_path": "src/Data/Desc.agda", "max_line_length": 73, "max_stars_count": null, "max_stars_repo_head_hexsha": "27fd49914d5ce1cc90d319089686861b33e8f19f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "johnyob/agda-desc", "max_stars_repo_path": "src/Data/Desc.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1991, "size": 5375 }
module _ where module M where F : Set → Set F A = A open M infix 0 F syntax F A = [ A ] G : Set → Set G A = [ A ]
{ "alphanum_fraction": 0.5284552846, "avg_line_length": 8.2, "ext": "agda", "hexsha": "4186dd6c9b453ffc3754eee42442f86c426f9f4c", "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/Issue2893.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/Issue2893.agda", "max_line_length": 18, "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/Issue2893.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": 49, "size": 123 }
{-# OPTIONS --without-K --safe #-} -- Composition of pseudofunctors module Categories.Pseudofunctor.Composition where open import Data.Product using (_,_) open import Categories.Bicategory using (Bicategory) import Categories.Bicategory.Extras as BicategoryExt open import Categories.Category using (Category) open import Categories.Category.Instance.One using (shift) open import Categories.Category.Product using (_⁂_) open import Categories.Functor using (Functor; _∘F_) import Categories.Morphism.Reasoning as MorphismReasoning open import Categories.NaturalTransformation using (NaturalTransformation) open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism; _≃_; niHelper; _ⓘˡ_; _ⓘʳ_) open import Categories.Pseudofunctor using (Pseudofunctor) open Category using (module HomReasoning) open NaturalIsomorphism using (F⇒G; F⇐G) infixr 9 _∘P_ -- Composition of pseudofunctors _∘P_ : ∀ {o ℓ e t o′ ℓ′ e′ t′ o″ ℓ″ e″ t″} {C : Bicategory o ℓ e t} {D : Bicategory o′ ℓ′ e′ t′} {E : Bicategory o″ ℓ″ e″ t″} → Pseudofunctor D E → Pseudofunctor C D → Pseudofunctor C E _∘P_ {o″ = o″} {ℓ″ = ℓ″} {e″ = e″} {C = C} {D = D} {E = E} F G = record { P₀ = λ x → F₀ (G₀ x) ; P₁ = F₁ ∘F G₁ ; P-identity = P-identity ; P-homomorphism = P-homomorphism ; unitaryˡ = unitaryˡ ; unitaryʳ = unitaryʳ ; assoc = assoc } where module C = BicategoryExt C module D = BicategoryExt D module E = BicategoryExt E module F = Pseudofunctor F module G = Pseudofunctor G open E open F using () renaming (P₀ to F₀; P₁ to F₁) open G using () renaming (P₀ to G₀; P₁ to G₁) module F₁G₁ {x} {y} = Functor (F₁ {G₀ x} {G₀ y} ∘F G₁ {x} {y}) open NaturalIsomorphism F∘G-id = λ {x} → F₁ ⓘˡ G.P-identity {x} F-id = λ {x} → F.P-identity {G₀ x} P-identity : ∀ {x} → E.id ∘F shift o″ ℓ″ e″ ≃ (F₁ ∘F G₁) ∘F (C.id {x}) P-identity {x} = niHelper (record { η = λ _ → ⇒.η F∘G-id _ ∘ᵥ ⇒.η F-id _ ; η⁻¹ = λ _ → ⇐.η F-id _ ∘ᵥ ⇐.η F∘G-id _ ; commute = λ _ → glue (⇒.commute F∘G-id _) (⇒.commute F-id _) ; iso = λ _ → record { isoˡ = begin (⇐.η F-id _ ∘ᵥ ⇐.η F∘G-id _) ∘ᵥ ⇒.η F∘G-id _ ∘ᵥ ⇒.η F-id _ ≈⟨ cancelInner (iso.isoˡ F∘G-id _) ⟩ ⇐.η F-id _ ∘ᵥ ⇒.η F-id _ ≈⟨ iso.isoˡ F-id _ ⟩ id₂ ∎ ; isoʳ = begin (⇒.η F∘G-id _ ∘ᵥ ⇒.η F-id _) ∘ᵥ ⇐.η F-id _ ∘ᵥ ⇐.η F∘G-id _ ≈⟨ cancelInner (iso.isoʳ F-id _) ⟩ ⇒.η F∘G-id _ ∘ᵥ ⇐.η F∘G-id _ ≈⟨ iso.isoʳ F∘G-id _ ⟩ id₂ ∎ } }) where FGx = F₀ (G₀ x) open HomReasoning (hom FGx FGx) open MorphismReasoning (hom FGx FGx) F∘G-h = λ {x y z} → F₁ ⓘˡ G.P-homomorphism {x} {y} {z} F-h∘G = λ {x y z} → F.P-homomorphism {G₀ x} {G₀ y} {G₀ z} ⓘʳ (G₁ ⁂ G₁) P-homomorphism : ∀ {x y z} → E.⊚ ∘F (F₁ ∘F G₁ ⁂ F₁ ∘F G₁) ≃ (F₁ ∘F G₁) ∘F C.⊚ {x} {y} {z} P-homomorphism {x} {y} {z} = niHelper (record { η = λ f,g → ⇒.η F∘G-h f,g ∘ᵥ ⇒.η F-h∘G f,g ; η⁻¹ = λ f,g → ⇐.η F-h∘G f,g ∘ᵥ ⇐.η F∘G-h f,g ; commute = λ α,β → glue (⇒.commute F∘G-h α,β) (⇒.commute F-h∘G α,β) ; iso = λ f,g → record { isoˡ = cancelInner (iso.isoˡ F∘G-h f,g) ○ iso.isoˡ F-h∘G f,g ; isoʳ = cancelInner (iso.isoʳ F-h∘G f,g) ○ iso.isoʳ F∘G-h f,g } }) where FGx = F₀ (G₀ x) FGz = F₀ (G₀ z) open HomReasoning (hom FGx FGz) open MorphismReasoning (hom FGx FGz) Pid = λ {A} → NaturalTransformation.η (F⇒G (P-identity {A})) _ Phom = λ {x} {y} {z} f,g → NaturalTransformation.η (F⇒G (P-homomorphism {x} {y} {z})) f,g λ⇒ = unitorˡ.from ρ⇒ = unitorʳ.from α⇒ = associator.from unitaryˡ : ∀ {x y} {f : x C.⇒₁ y} → let open ComHom in [ id₁ ⊚₀ F₁G₁.₀ f ⇒ F₁G₁.₀ f ]⟨ Pid ⊚₁ id₂ ⇒⟨ F₁G₁.₀ C.id₁ ⊚₀ F₁G₁.₀ f ⟩ Phom (C.id₁ , f) ⇒⟨ F₁G₁.₀ (C.id₁ C.⊚₀ f) ⟩ F₁G₁.₁ C.unitorˡ.from ≈ E.unitorˡ.from ⟩ unitaryˡ {x} {y} {f} = begin F₁G₁.₁ C.unitorˡ.from ∘ᵥ Phom (C.id₁ , f) ∘ᵥ Pid ⊚₁ id₂ ≡⟨⟩ F₁.₁ (G₁.₁ C.unitorˡ.from) ∘ᵥ (⇒.η F∘G-h (C.id₁ , f) ∘ᵥ ⇒.η F-h∘G (C.id₁ , f)) ∘ᵥ (⇒.η F∘G-id _ ∘ᵥ ⇒.η F-id _) ⊚₁ id₂ ≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ E.∘ᵥ-distr-◁ ⟩ F₁.₁ (G₁.₁ C.unitorˡ.from) ∘ᵥ (⇒.η F∘G-h (C.id₁ , f) ∘ᵥ ⇒.η F-h∘G (C.id₁ , f)) ∘ᵥ ⇒.η F∘G-id _ ⊚₁ id₂ ∘ᵥ ⇒.η F-id _ ⊚₁ id₂ ≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ E.⊚.F-resp-≈ (hom.Equiv.refl , F₁.identity) ⟩∘⟨refl ⟩ F₁.₁ (G₁.₁ C.unitorˡ.from) ∘ᵥ (⇒.η F∘G-h (C.id₁ , f) ∘ᵥ ⇒.η F-h∘G (C.id₁ , f)) ∘ᵥ ⇒.η F∘G-id _ ⊚₁ F₁.₁ D.id₂ ∘ᵥ ⇒.η F-id _ ⊚₁ id₂ ≈⟨ refl⟩∘⟨ extend² (F.Hom.commute (G.unitˡ.η _ , D.id₂)) ⟩ F₁.₁ (G₁.₁ C.unitorˡ.from) ∘ᵥ (⇒.η F∘G-h (C.id₁ , f) ∘ᵥ F₁.₁ (G.unitˡ.η _ D.⊚₁ D.id₂)) ∘ᵥ F.Hom.η (D.id₁ , G₁.₀ f) ∘ᵥ ⇒.η F-id _ ⊚₁ id₂ ≈˘⟨ pushˡ (F₁.homomorphism ○ hom.∘-resp-≈ʳ F₁.homomorphism) ⟩ F₁.₁ (G₁.₁ C.unitorˡ.from D.∘ᵥ G.Hom.η (C.id₁ , f) D.∘ᵥ G.unitˡ.η _ D.⊚₁ D.id₂) ∘ᵥ F.Hom.η (D.id₁ , G₁.₀ f) ∘ᵥ ⇒.η F-id _ ⊚₁ id₂ ≈⟨ F₁.F-resp-≈ G.unitaryˡ ⟩∘⟨refl ⟩ F₁.₁ (D.unitorˡ.from) ∘ᵥ F.Hom.η (D.id₁ , G₁.₀ f) ∘ᵥ ⇒.η F-id _ ⊚₁ id₂ ≈⟨ F.unitaryˡ ⟩ E.unitorˡ.from ∎ where FGx = F₀ (G₀ x) FGy = F₀ (G₀ y) open HomReasoning (hom FGx FGy) open MorphismReasoning (hom FGx FGy) unitaryʳ : ∀ {x y} {f : x C.⇒₁ y} → let open ComHom in [ F₁G₁.₀ f ⊚₀ id₁ ⇒ F₁G₁.₀ f ]⟨ id₂ ⊚₁ Pid ⇒⟨ F₁G₁.₀ f ⊚₀ F₁G₁.₀ C.id₁ ⟩ Phom (f , C.id₁) ⇒⟨ F₁G₁.₀ (f C.⊚₀ C.id₁) ⟩ F₁G₁.₁ C.unitorʳ.from ≈ E.unitorʳ.from ⟩ unitaryʳ {x} {y} {f} = begin F₁G₁.₁ C.unitorʳ.from ∘ᵥ Phom (f , C.id₁) ∘ᵥ id₂ ⊚₁ Pid ≡⟨⟩ F₁.₁ (G₁.₁ C.unitorʳ.from) ∘ᵥ (⇒.η F∘G-h (f , C.id₁) ∘ᵥ ⇒.η F-h∘G (f , C.id₁)) ∘ᵥ id₂ ⊚₁ (⇒.η F∘G-id _ ∘ᵥ ⇒.η F-id _) ≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ E.∘ᵥ-distr-▷ ⟩ F₁.₁ (G₁.₁ C.unitorʳ.from) ∘ᵥ (⇒.η F∘G-h (f , C.id₁) ∘ᵥ ⇒.η F-h∘G (f , C.id₁)) ∘ᵥ id₂ ⊚₁ ⇒.η F∘G-id _ ∘ᵥ id₂ ⊚₁ ⇒.η F-id _ ≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ E.⊚.F-resp-≈ (F₁.identity , hom.Equiv.refl) ⟩∘⟨refl ⟩ F₁.₁ (G₁.₁ C.unitorʳ.from) ∘ᵥ (⇒.η F∘G-h (f , C.id₁) ∘ᵥ ⇒.η F-h∘G (f , C.id₁)) ∘ᵥ F₁.₁ D.id₂ ⊚₁ ⇒.η F∘G-id _ ∘ᵥ id₂ ⊚₁ ⇒.η F-id _ ≈⟨ refl⟩∘⟨ extend² (F.Hom.commute (D.id₂ , G.unitˡ.η _)) ⟩ F₁.₁ (G₁.₁ C.unitorʳ.from) ∘ᵥ (⇒.η F∘G-h (f , C.id₁) ∘ᵥ F₁.₁ (D.id₂ D.⊚₁ G.unitˡ.η _)) ∘ᵥ F.Hom.η (G₁.₀ f , D.id₁) ∘ᵥ id₂ ⊚₁ ⇒.η F-id _ ≈˘⟨ pushˡ (F₁.homomorphism ○ hom.∘-resp-≈ʳ F₁.homomorphism) ⟩ F₁.₁ (G₁.₁ C.unitorʳ.from D.∘ᵥ G.Hom.η (f , C.id₁) D.∘ᵥ D.id₂ D.⊚₁ G.unitˡ.η _) ∘ᵥ F.Hom.η (G₁.₀ f , D.id₁) ∘ᵥ id₂ ⊚₁ ⇒.η F-id _ ≈⟨ F₁.F-resp-≈ G.unitaryʳ ⟩∘⟨refl ⟩ F₁.₁ (D.unitorʳ.from) ∘ᵥ F.Hom.η (G₁.₀ f , D.id₁) ∘ᵥ id₂ ⊚₁ ⇒.η F-id _ ≈⟨ F.unitaryʳ ⟩ E.unitorʳ.from ∎ where FGx = F₀ (G₀ x) FGy = F₀ (G₀ y) open HomReasoning (hom FGx FGy) open MorphismReasoning (hom FGx FGy) assoc : ∀ {x y z w} {f : x C.⇒₁ y} {g : y C.⇒₁ z} {h : z C.⇒₁ w} → let open ComHom in [ (F₁G₁.₀ h ⊚₀ F₁G₁.₀ g) ⊚₀ F₁G₁.₀ f ⇒ F₁G₁.₀ (h C.⊚₀ (g C.⊚₀ f)) ]⟨ Phom (h , g) ⊚₁ id₂ ⇒⟨ F₁G₁.₀ (h C.⊚₀ g) ⊚₀ F₁G₁.₀ f ⟩ Phom (_ , f) ⇒⟨ F₁G₁.₀ ((h C.⊚₀ g) C.⊚₀ f) ⟩ F₁G₁.₁ C.associator.from ≈ E.associator.from ⇒⟨ F₁G₁.₀ h ⊚₀ (F₁G₁.₀ g ⊚₀ F₁G₁.₀ f) ⟩ id₂ ⊚₁ Phom (g , f) ⇒⟨ F₁G₁.₀ h ⊚₀ F₁G₁.₀ (g C.⊚₀ f) ⟩ Phom (h , _) ⟩ assoc {x} {_} {_} {w} {f} {g} {h} = begin F₁G₁.₁ C.associator.from ∘ᵥ Phom (_ , f) ∘ᵥ Phom (h , g) ⊚₁ id₂ ≡⟨⟩ F₁.₁ (G₁.₁ C.associator.from) ∘ᵥ (⇒.η F∘G-h (_ , f) ∘ᵥ ⇒.η F-h∘G (_ , f)) ∘ᵥ (⇒.η F∘G-h (h , g) ∘ᵥ ⇒.η F-h∘G (h , g)) ⊚₁ id₂ ≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ E.∘ᵥ-distr-◁ ⟩ F₁.₁ (G₁.₁ C.associator.from) ∘ᵥ (⇒.η F∘G-h (_ , f) ∘ᵥ ⇒.η F-h∘G (_ , f)) ∘ᵥ ⇒.η F∘G-h (h , g) ⊚₁ id₂ ∘ᵥ ⇒.η F-h∘G (h , g) ⊚₁ id₂ ≈˘⟨ refl⟩∘⟨ refl⟩∘⟨ E.⊚.F-resp-≈ (hom.Equiv.refl , F₁.identity) ⟩∘⟨refl ⟩ F₁.₁ (G₁.₁ C.associator.from) ∘ᵥ (⇒.η F∘G-h (_ , f) ∘ᵥ ⇒.η F-h∘G (_ , f)) ∘ᵥ ⇒.η F∘G-h (h , g) ⊚₁ F₁.₁ D.id₂ ∘ᵥ ⇒.η F-h∘G (h , g) ⊚₁ id₂ ≈⟨ refl⟩∘⟨ extend² (F.Hom.commute (G.Hom.η (h , g) , D.id₂)) ⟩ F₁.₁ (G₁.₁ C.associator.from) ∘ᵥ (⇒.η F∘G-h (_ , f) ∘ᵥ F₁.₁ (G.Hom.η (h , g) D.⊚₁ D.id₂)) ∘ᵥ F.Hom.η (_ , G₁.₀ f) ∘ᵥ ⇒.η F-h∘G (h , g) ⊚₁ id₂ ≈˘⟨ pushˡ (F₁.homomorphism ○ hom.∘-resp-≈ʳ F₁.homomorphism) ⟩ F₁.₁ (G₁.₁ C.associator.from D.∘ᵥ G.Hom.η (_ , f) D.∘ᵥ G.Hom.η (h , g) D.⊚₁ D.id₂) ∘ᵥ F.Hom.η (_ , G₁.₀ f) ∘ᵥ ⇒.η F-h∘G (h , g) ⊚₁ id₂ ≈⟨ F₁.F-resp-≈ G.assoc ⟩∘⟨refl ⟩ F₁.₁ (G.Hom.η (h , _) D.∘ᵥ D.id₂ D.⊚₁ G.Hom.η (g , f) D.∘ᵥ D.associator.from) ∘ᵥ F.Hom.η (_ , G₁.₀ f) ∘ᵥ ⇒.η F-h∘G (h , g) ⊚₁ id₂ ≈⟨ (F₁.homomorphism ○ pushʳ F₁.homomorphism) ⟩∘⟨refl ⟩ ((⇒.η F∘G-h (h , _) ∘ᵥ F₁.₁ (D.id₂ D.⊚₁ G.Hom.η (g , f))) ∘ᵥ F₁.₁ D.associator.from) ∘ᵥ F.Hom.η (_ , G₁.₀ f) ∘ᵥ ⇒.η F-h∘G (h , g) ⊚₁ id₂ ≈⟨ pullʳ F.assoc ⟩ (⇒.η F∘G-h (h , _) ∘ᵥ F₁.₁ (D.id₂ D.⊚₁ G.Hom.η (g , f))) ∘ᵥ F.Hom.η (G₁.₀ h , _) ∘ᵥ id₂ ⊚₁ ⇒.η F-h∘G (g , f) ∘ᵥ E.associator.from ≈˘⟨ extend² (F.Hom.commute (D.id₂ , G.Hom.η (g , f))) ⟩ (⇒.η F∘G-h (h , _) ∘ᵥ ⇒.η F-h∘G (h , _)) ∘ᵥ F₁.₁ D.id₂ ⊚₁ ⇒.η F∘G-h (g , f) ∘ᵥ id₂ ⊚₁ ⇒.η F-h∘G (g , f) ∘ᵥ E.associator.from ≈⟨ refl⟩∘⟨ pullˡ (E.⊚.F-resp-≈ (F₁.identity , hom.Equiv.refl) ⟩∘⟨refl) ⟩ (⇒.η F∘G-h (h , _) ∘ᵥ ⇒.η F-h∘G (h , _)) ∘ᵥ (id₂ ⊚₁ ⇒.η F∘G-h (g , f) ∘ᵥ id₂ ⊚₁ ⇒.η F-h∘G (g , f)) ∘ᵥ E.associator.from ≈⟨ refl⟩∘⟨ E.∘ᵥ-distr-▷ ⟩∘⟨refl ⟩ (⇒.η F∘G-h (h , _) ∘ᵥ ⇒.η F-h∘G (h , _)) ∘ᵥ id₂ ⊚₁ (⇒.η F∘G-h (g , f) ∘ᵥ ⇒.η F-h∘G (g , f)) ∘ᵥ E.associator.from ≡⟨⟩ Phom (h , _) ∘ᵥ id₂ ⊚₁ Phom (g , f) ∘ᵥ E.associator.from ∎ where FGx = F₀ (G₀ x) FGw = F₀ (G₀ w) open HomReasoning (hom FGx FGw) open MorphismReasoning (hom FGx FGw)
{ "alphanum_fraction": 0.4634146341, "avg_line_length": 41.3166023166, "ext": "agda", "hexsha": "ac42aa2812a4bb3f1ae9488bb0f29fe809df9bd8", "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/Pseudofunctor/Composition.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/Pseudofunctor/Composition.agda", "max_line_length": 80, "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/Pseudofunctor/Composition.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": 5710, "size": 10701 }
-- notes-01-monday.agda open import Data.Nat open import Data.Bool f : ℕ → ℕ f x = x + 2 {- f 3 = = (x + 2)[x:=3] = = 3 + 2 = = 5 -} n : ℕ n = 3 f' : ℕ → ℕ f' = λ x → x + 2 -- λ function (nameless function) {- f' 3 = = (λ x → x + 2) 3 = = (x + 2)[x := 3] = -- β-reduction = 3 + 2 = = 5 -} g : ℕ → ℕ → ℕ -- currying g = λ x → (λ y → x + y) k : (ℕ → ℕ) → ℕ k h = h 2 + h 3 {- k f = = f 2 + f 3 = = (2 + 2) + (3 + 2) = = 4 + 5 = = 9 -} variable A B C : Set -- polymorphic: Set actually means "type" id : A → A id x = x _∘_ : (B → C) → (A → B) → (A → C) f ∘ g = λ x → f (g x) {- A combinator is a high-order function that uses only function application and other combinators. -} K : A → B → A K x y = x S : (A → B → C) → (A → B) → A → C S f g x = f x (g x) -- in combinatory logic, every pure λ-term can be translated into S,K -- λ x → f x = f -- η-equality
{ "alphanum_fraction": 0.4516483516, "avg_line_length": 14, "ext": "agda", "hexsha": "c67c336023212bb4794fb6565d935393e3915b29", "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": "f328e596d98a7d052b34144447dd14de0f57e534", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "FoxySeta/mgs-2021", "max_forks_repo_path": "Type Theory/notes-01-monday.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "f328e596d98a7d052b34144447dd14de0f57e534", "max_issues_repo_issues_event_max_datetime": "2021-07-14T20:35:48.000Z", "max_issues_repo_issues_event_min_datetime": "2021-07-14T20:34:53.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "FoxySeta/mgs-2021", "max_issues_repo_path": "Type Theory/notes-01-monday.agda", "max_line_length": 79, "max_stars_count": null, "max_stars_repo_head_hexsha": "f328e596d98a7d052b34144447dd14de0f57e534", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "FoxySeta/mgs-2021", "max_stars_repo_path": "Type Theory/notes-01-monday.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 418, "size": 910 }
------------------------------------------------------------------------ -- Strict ω-continuous functions ------------------------------------------------------------------------ {-# OPTIONS --cubical --safe #-} module Partiality-monad.Inductive.Strict-omega-continuous where open import Equality.Propositional.Cubical open import Prelude hiding (⊥) open import Bijection equality-with-J using (_↔_) open import Function-universe equality-with-J hiding (_∘_) open import Monad equality-with-J import Partiality-algebra.Strict-omega-continuous as S open import Partiality-monad.Inductive open import Partiality-monad.Inductive.Eliminators open import Partiality-monad.Inductive.Monad open import Partiality-monad.Inductive.Monotone open import Partiality-monad.Inductive.Omega-continuous -- Definition of strict ω-continuous functions. [_⊥→_⊥]-strict : ∀ {a b} → Type a → Type b → Type (a ⊔ b) [ A ⊥→ B ⊥]-strict = S.[ partiality-algebra A ⟶ partiality-algebra B ]⊥ module [_⊥→_⊥]-strict {a b} {A : Type a} {B : Type b} (f : [ A ⊥→ B ⊥]-strict) = S.[_⟶_]⊥ f open [_⊥→_⊥]-strict -- Identity. id-strict : ∀ {a} {A : Type a} → [ A ⊥→ A ⊥]-strict id-strict = S.id⊥ -- Composition. infixr 40 _∘-strict_ _∘-strict_ : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} → [ B ⊥→ C ⊥]-strict → [ A ⊥→ B ⊥]-strict → [ A ⊥→ C ⊥]-strict _∘-strict_ = S._∘⊥_ -- Equality characterisation lemma for strict ω-continuous functions. equality-characterisation-strict : ∀ {a b} {A : Type a} {B : Type b} {f g : [ A ⊥→ B ⊥]-strict} → (∀ x → function f x ≡ function g x) ↔ f ≡ g equality-characterisation-strict = S.equality-characterisation-strict -- Composition is associative. ∘-strict-assoc : ∀ {a b c d} {A : Type a} {B : Type b} {C : Type c} {D : Type d} (f : [ C ⊥→ D ⊥]-strict) (g : [ B ⊥→ C ⊥]-strict) (h : [ A ⊥→ B ⊥]-strict) → f ∘-strict (g ∘-strict h) ≡ (f ∘-strict g) ∘-strict h ∘-strict-assoc = S.∘⊥-assoc -- Strict ω-continuous functions satisfy an extra monad law. >>=-∘-return : ∀ {a b} {A : Type a} {B : Type b} → (f : [ A ⊥→ B ⊥]-strict) → ∀ x → x >>=′ (function f ∘ return) ≡ function f x >>=-∘-return fs = ⊥-rec-⊥ (record { P = λ x → x >>=′ (f ∘ return) ≡ f x ; pe = never >>=′ f ∘ return ≡⟨ never->>= ⟩ never ≡⟨ sym (strict fs) ⟩∎ f never ∎ ; po = λ x → now x >>=′ f ∘ return ≡⟨ now->>= ⟩∎ f (now x) ∎ ; pl = λ s p → ⨆ s >>=′ (f ∘ return) ≡⟨ ⨆->>= ⟩ ⨆ ((f ∘ return) ∗-inc s) ≡⟨ cong ⨆ (_↔_.to equality-characterisation-increasing λ n → (f ∘ return) ∗-inc s [ n ] ≡⟨ p n ⟩∎ [ f⊑ $ s ]-inc [ n ] ∎) ⟩ ⨆ [ f⊑ $ s ]-inc ≡⟨ sym $ ω-continuous fs s ⟩∎ f (⨆ s) ∎ ; pp = λ _ → ⊥-is-set }) where f⊑ = monotone-function fs f = function fs -- Strict ω-continuous functions from A ⊥ to B ⊥ are isomorphic to -- functions from A to B ⊥. partial↔strict : ∀ {a b} {A : Type a} {B : Type b} → (A → B ⊥) ↔ [ A ⊥→ B ⊥]-strict partial↔strict {a} = record { surjection = record { logical-equivalence = record { to = λ f → record { ω-continuous-function = f ∗ ; strict = never >>=′ f ≡⟨ never->>= ⟩∎ never ∎ } ; from = λ f x → function f (return x) } ; right-inverse-of = λ f → _↔_.to equality-characterisation-strict λ x → x >>=′ (function f ∘ return) ≡⟨ >>=-∘-return f x ⟩∎ function f x ∎ } ; left-inverse-of = λ f → ⟨ext⟩ λ x → return x >>=′ f ≡⟨ Monad-laws.left-identity x f ⟩∎ f x ∎ }
{ "alphanum_fraction": 0.4920593595, "avg_line_length": 31.4836065574, "ext": "agda", "hexsha": "cb43cff4fb2a5980d0d5a65777bf5d39566a61d2", "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": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/partiality-monad", "max_forks_repo_path": "src/Partiality-monad/Inductive/Strict-omega-continuous.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae", "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/partiality-monad", "max_issues_repo_path": "src/Partiality-monad/Inductive/Strict-omega-continuous.agda", "max_line_length": 100, "max_stars_count": 2, "max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/partiality-monad", "max_stars_repo_path": "src/Partiality-monad/Inductive/Strict-omega-continuous.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z", "num_tokens": 1361, "size": 3841 }
-- The positivity checker should not be run twice for the same mutual -- block. (If we decide to turn Agda into a total program, then we may -- want to revise this decision.) {-# OPTIONS -vtc.pos.graph:5 #-} module Positivity-once where A : Set₁ module M where B : Set₁ B = A A = Set
{ "alphanum_fraction": 0.6870748299, "avg_line_length": 17.2941176471, "ext": "agda", "hexsha": "f63d5cd5429b7018cc0ee2f6b061e220d2c54ec5", "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/interaction/Positivity-once.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/Positivity-once.agda", "max_line_length": 70, "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/Positivity-once.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 82, "size": 294 }
-- This module introduces built-in types and primitive functions. module Introduction.Built-in where {- Agda supports four built-in types : - integers, - floating point numbers, - characters, and - strings. Note that strings are not defined as lists of characters (as is the case in Haskell). To use the built-in types they first have to be bound to Agda types. The reason for this is that there are no predefined names in Agda. -} -- To be able to use the built-in types we first introduce a new set for each -- built-in type. postulate Int : Set Float : Set Char : Set String : Set -- We can then bind the built-in types to these new sets using the BUILTIN -- pragma. {-# BUILTIN INTEGER Int #-} {-# BUILTIN FLOAT Float #-} {-# BUILTIN CHAR Char #-} {-# BUILTIN STRING String #-} pi : Float pi = 3.141593 forAll : Char forAll = '∀' hello : String hello = "Hello World!" -- There are no integer literals. Instead there are natural number literals. To -- use these you have to tell the type checker which type to use for natural -- numbers. data Nat : Set where zero : Nat suc : Nat -> Nat {-# BUILTIN NATURAL Nat #-} -- Now we can define fortyTwo : Nat fortyTwo = 42 -- To anything interesting with values of the built-in types we need functions -- to manipulate them. To this end Agda provides a set of primitive functions. -- To gain access to a primitive function one simply declares it. For instance, -- the function for floating point addition is called primFloatPlus. See below -- for a complete list of primitive functions. At the moment the name that you -- bring into scope is always the name of the primitive function. In the future -- we might allow a primitive function to be introduced with any name. module FloatPlus where -- We put it in a module to prevent it from clashing with -- the plus function in the complete list of primitive -- functions below. primitive primFloatPlus : Float -> Float -> Float twoPi = primFloatPlus pi pi -- Some primitive functions returns elements of non-primitive types. For -- instance, the integer comparison functions return booleans. To be able to -- use these functions we have to explain which type to use for booleans. data Bool : Set where false : Bool true : Bool {-# BUILTIN BOOL Bool #-} {-# BUILTIN TRUE true #-} {-# BUILTIN FALSE false #-} module FloatLess where primitive primFloatLess : Float -> Float -> Bool -- There are functions to convert a string to a list of characters, so we need -- to say which list type to use. data List (A : Set) : Set where nil : List A _::_ : A -> List A -> List A {-# BUILTIN LIST List #-} {-# BUILTIN NIL nil #-} {-# BUILTIN CONS _::_ #-} module StringToList where primitive primStringToList : String -> List Char -- Below is a partial version of the complete list of primitive -- functions. primitive -- Integer functions primIntegerPlus : Int -> Int -> Int primIntegerMinus : Int -> Int -> Int primIntegerTimes : Int -> Int -> Int primIntegerDiv : Int -> Int -> Int -- partial primIntegerMod : Int -> Int -> Int -- partial primIntegerEquality : Int -> Int -> Bool primIntegerLess : Int -> Int -> Bool primIntegerAbs : Int -> Nat primNatToInteger : Nat -> Int primShowInteger : Int -> String -- Floating point functions primIntegerToFloat : Int -> Float primFloatPlus : Float -> Float -> Float primFloatMinus : Float -> Float -> Float primFloatTimes : Float -> Float -> Float primFloatDiv : Float -> Float -> Float primFloatLess : Float -> Float -> Bool primRound : Float -> Int primFloor : Float -> Int primCeiling : Float -> Int primExp : Float -> Float primLog : Float -> Float -- partial primSin : Float -> Float primShowFloat : Float -> String -- Character functions primCharEquality : Char -> Char -> Bool primIsLower : Char -> Bool primIsDigit : Char -> Bool primIsAlpha : Char -> Bool primIsSpace : Char -> Bool primIsAscii : Char -> Bool primIsLatin1 : Char -> Bool primIsPrint : Char -> Bool primIsHexDigit : Char -> Bool primToUpper : Char -> Char primToLower : Char -> Char primCharToNat : Char -> Nat primNatToChar : Nat -> Char -- partial primShowChar : Char -> String -- String functions primStringToList : String -> List Char primStringFromList : List Char -> String primStringAppend : String -> String -> String primStringEquality : String -> String -> Bool primShowString : String -> String
{ "alphanum_fraction": 0.6552879581, "avg_line_length": 29.6583850932, "ext": "agda", "hexsha": "c695faf6118b3e76eb2912fb65d885fa78efd05a", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "examples/Introduction/Built-in.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/Introduction/Built-in.agda", "max_line_length": 81, "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": "examples/Introduction/Built-in.agda", "max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z", "max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z", "num_tokens": 1194, "size": 4775 }
{- Example by Andreas (2015-09-18) -} {-# OPTIONS --rewriting --local-confluence-check #-} open import Common.Prelude open import Common.Equality {-# BUILTIN REWRITE _≡_ #-} module _ (A : Set) where postulate plus0p : ∀{x} → (x + zero) ≡ x {-# REWRITE plus0p #-}
{ "alphanum_fraction": 0.6258992806, "avg_line_length": 17.375, "ext": "agda", "hexsha": "14c43ec6324f32324896b3dd088e9a0df53ff340", "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": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "shlevy/agda", "max_forks_repo_path": "test/Succeed/Issue1652-2.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "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": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue1652-2.agda", "max_line_length": 52, "max_stars_count": null, "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/Issue1652-2.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 89, "size": 278 }
module <-trans where open import Data.Nat using (ℕ) open import Relations using (_<_; z<s; s<s) <-trans : ∀ {m n p : ℕ} → m < n → n < p ----- → m < p <-trans z<s (s<s _) = z<s <-trans (s<s a) (s<s b) = s<s (<-trans a b)
{ "alphanum_fraction": 0.4894514768, "avg_line_length": 16.9285714286, "ext": "agda", "hexsha": "64289aa546915df19bb1bcfbf9adf0ed21fb2ffd", "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": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "akiomik/plfa-solutions", "max_forks_repo_path": "part1/relations/<-trans.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547", "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": "akiomik/plfa-solutions", "max_issues_repo_path": "part1/relations/<-trans.agda", "max_line_length": 43, "max_stars_count": 1, "max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "akiomik/plfa-solutions", "max_stars_repo_path": "part1/relations/<-trans.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z", "max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z", "num_tokens": 93, "size": 237 }
module BTree {A : Set} where open import Data.List data BTree : Set where leaf : BTree node : A → BTree → BTree → BTree flatten : BTree → List A flatten leaf = [] flatten (node x l r) = (flatten l) ++ (x ∷ flatten r)
{ "alphanum_fraction": 0.6271929825, "avg_line_length": 16.2857142857, "ext": "agda", "hexsha": "9aa398edc15b68eea2c29081300d3548dfbbf9c0", "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/BTree.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/BTree.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/BTree.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": 75, "size": 228 }
module FunctorCat where open import Categories open import Functors open import Naturals FunctorCat : ∀{a b c d} → Cat {a}{b} → Cat {c}{d} → Cat FunctorCat C D = record{ Obj = Fun C D; Hom = NatT; iden = idNat; comp = compNat; idl = idlNat; idr = idrNat; ass = λ{_}{_}{_}{_}{α}{β}{η} → assNat {α = α}{β}{η}}
{ "alphanum_fraction": 0.5957446809, "avg_line_length": 20.5625, "ext": "agda", "hexsha": "750a6da936b3774c151968248c956cdb7af5e85c", "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": "FunctorCat.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": "FunctorCat.agda", "max_line_length": 55, "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": "FunctorCat.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": 132, "size": 329 }
module agdaFunction where addOne : N -> N addOne Z = suc Z addOne (suc a) = suc (suc a)
{ "alphanum_fraction": 0.6555555556, "avg_line_length": 12.8571428571, "ext": "agda", "hexsha": "86cdbba0d93f2b4106e1fd8c0f15917ab7728a46", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-11-27T16:25:18.000Z", "max_forks_repo_forks_event_min_datetime": "2019-11-27T16:25:18.000Z", "max_forks_repo_head_hexsha": "a5f65e28cc9fdfefde49e7d8cf84486601b9e7b1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hjorthjort/IdrisToAgda", "max_forks_repo_path": "agdaFunction.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "a5f65e28cc9fdfefde49e7d8cf84486601b9e7b1", "max_issues_repo_issues_event_max_datetime": "2019-11-28T17:52:42.000Z", "max_issues_repo_issues_event_min_datetime": "2019-11-28T17:52:42.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "hjorthjort/IdrisToAgda", "max_issues_repo_path": "agdaFunction.agda", "max_line_length": 28, "max_stars_count": 2, "max_stars_repo_head_hexsha": "a5f65e28cc9fdfefde49e7d8cf84486601b9e7b1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hjorthjort/IdrisToAgda", "max_stars_repo_path": "agdaFunction.agda", "max_stars_repo_stars_event_max_datetime": "2020-06-29T20:42:43.000Z", "max_stars_repo_stars_event_min_datetime": "2020-02-16T23:22:50.000Z", "num_tokens": 34, "size": 90 }
{- modified from a bug report given to me by Ulf Norell, for a previous, incorrect version of bt-remove-min. -} module braun-tree-test where open import nat open import list open import product open import sum open import eq import braun-tree open braun-tree nat _<_ test : braun-tree 4 test = bt-node 2 (bt-node 3 (bt-node 6 bt-empty bt-empty (inj₁ refl)) bt-empty (inj₂ refl)) (bt-node 4 bt-empty bt-empty (inj₁ refl)) (inj₂ refl) {- to-list : ∀ {n} → braun-tree n → list nat to-list {zero} _ = [] to-list {suc _} t with bt-remove-min t to-list {suc _} t | x , t′ = x :: to-list t′ t : braun-tree 5 t = bt-insert 5 (bt-insert 3 (bt-insert 4 (bt-insert 2 (bt-insert 1 bt-empty)))) oops : to-list t ≡ (1 :: 2 :: 3 :: 4 :: 5 :: []) oops = refl -}
{ "alphanum_fraction": 0.609394314, "avg_line_length": 17.5869565217, "ext": "agda", "hexsha": "8259d1f7fcea0e24e0e7227c2fb3255d0d18e192", "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": "braun-tree-test.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": "braun-tree-test.agda", "max_line_length": 80, "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": "braun-tree-test.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": 269, "size": 809 }
{-# OPTIONS --allow-unsolved-metas #-} module Control.Monad.Free where open import Prelude data Free (F : Type a → Type a) (A : Type a) : Type (ℓsuc a) where lift : F A → Free F A return : A → Free F A _>>=_ : Free F B → (B → Free F A) → Free F A >>=-idˡ : isSet A → (f : B → Free F A) (x : B) → (return x >>= f) ≡ f x >>=-idʳ : isSet A → (x : Free F A) → (x >>= return) ≡ x >>=-assoc : isSet A → (xs : Free F C) (f : C → Free F B) (g : B → Free F A) → ((xs >>= f) >>= g) ≡ (xs >>= (λ x → f x >>= g)) trunc : isSet A → isSet (Free F A) data FreeF (F : Type a → Type a) (P : ∀ {T} → Free F T → Type b) (A : Type a) : Type (ℓsuc a ℓ⊔ b) where liftF : F A → FreeF F P A returnF : A → FreeF F P A bindF : (xs : Free F B) (P⟨xs⟩ : P xs) (k : B → Free F A) (P⟨∘k⟩ : ∀ x → P (k x)) → FreeF F P A private variable F : Type a → Type a G : Type b → Type b p : Level P : ∀ {T} → Free F T → Type p ⟪_⟫ : FreeF F P A → Free F A ⟪ liftF x ⟫ = lift x ⟪ returnF x ⟫ = return x ⟪ bindF xs P⟨xs⟩ k P⟨∘k⟩ ⟫ = xs >>= k Alg : (F : Type a → Type a) (P : ∀ {T} → Free F T → Type b) → Type _ Alg F P = ∀ {A} → (xs : FreeF F P A) → P ⟪ xs ⟫ record Coherent {a p} {F : Type a → Type a} {P : ∀ {T} → Free F T → Type p} (ψ : Alg F P) : Type (ℓsuc a ℓ⊔ p) where field c-set : ∀ {T} → isSet T → ∀ xs → isSet (P {T = T} xs) -- possibly needs to be isSet T → isSet (P {T = T} xs) c->>=idˡ : ∀ (isb : isSet B) (f : A → Free F B) Pf x → ψ (bindF (return x) (ψ (returnF x)) f Pf) ≡[ i ≔ P (>>=-idˡ isb f x i) ]≡ Pf x c->>=idʳ : ∀ (isa : isSet A) (x : Free F A) Px → ψ (bindF x Px return (λ y → ψ (returnF y))) ≡[ i ≔ P (>>=-idʳ isa x i) ]≡ Px c->>=assoc : ∀ (isa : isSet A) (xs : Free F C) Pxs (f : C → Free F B) Pf (g : B → Free F A) Pg → ψ (bindF (xs >>= f) (ψ (bindF xs Pxs f Pf)) g Pg) ≡[ i ≔ P (>>=-assoc isa xs f g i) ]≡ ψ (bindF xs Pxs (λ x → f x >>= g) λ x → ψ (bindF (f x) (Pf x) g Pg)) open Coherent public Ψ : (F : Type a → Type a) (P : ∀ {T} → Free F T → Type p) → Type _ Ψ F P = Σ (Alg F P) Coherent infixr 1 Ψ syntax Ψ F (λ v → e) = Ψ[ v ⦂ F * ] ⇒ e Φ : (Type a → Type a) → Type b → Type _ Φ A B = Ψ A (λ _ → B) ⟦_⟧ : Ψ F P → (xs : Free F A) → P xs ⟦ alg ⟧ (lift x) = alg .fst (liftF x) ⟦ alg ⟧ (return x) = alg .fst (returnF x) ⟦ alg ⟧ (xs >>= k) = alg .fst (bindF xs (⟦ alg ⟧ xs) k (⟦ alg ⟧ ∘ k)) ⟦ alg ⟧ (>>=-idˡ iss f k i) = alg .snd .c->>=idˡ iss f (⟦ alg ⟧ ∘ f) k i ⟦ alg ⟧ (>>=-idʳ iss xs i) = alg .snd .c->>=idʳ iss xs (⟦ alg ⟧ xs) i ⟦ alg ⟧ (>>=-assoc iss xs f g i) = alg .snd .c->>=assoc iss xs (⟦ alg ⟧ xs) f (⟦ alg ⟧ ∘ f) g (⟦ alg ⟧ ∘ g) i ⟦ alg ⟧ (trunc AIsSet xs ys p q i j) = isOfHLevel→isOfHLevelDep 2 (alg .snd .c-set AIsSet) (⟦ alg ⟧ xs) (⟦ alg ⟧ ys) (cong ⟦ alg ⟧ p) (cong ⟦ alg ⟧ q) (trunc AIsSet xs ys p q) i j prop-coh : {alg : Alg F P} → (∀ {T} → isSet T → ∀ xs → isProp (P {T} xs)) → Coherent alg prop-coh P-isProp .c-set TIsSet xs = isProp→isSet (P-isProp TIsSet xs) prop-coh {P = P} P-isProp .c->>=idˡ iss f Pf x = toPathP (P-isProp iss (f x) (transp (λ i → P (>>=-idˡ iss f x i)) i0 _) _) prop-coh {P = P} P-isProp .c->>=idʳ iss x Px = toPathP (P-isProp iss x (transp (λ i → P (>>=-idʳ iss x i)) i0 _) _) prop-coh {P = P} P-isProp .c->>=assoc iss xs Pxs f Pf g Pg = toPathP (P-isProp iss (xs >>= (λ x → f x >>= g)) (transp (λ i → P (>>=-assoc iss xs f g i)) i0 _) _) -- infix 4 _⊜_ -- record AnEquality (F : Type a → Type a) (A : Type a) : Type (ℓsuc a) where -- constructor _⊜_ -- field lhs rhs : Free F A -- open AnEquality public -- EqualityProof-Alg : (F : Type a → Type a) (P : ∀ {A} → Free F A → AnEquality G A) → Type _ -- EqualityProof-Alg F P = Alg F (λ xs → let Pxs = P xs in lhs Pxs ≡ rhs Pxs) -- eq-coh : {P : ∀ {A} → Free F A → AnEquality G A} {alg : EqualityProof-Alg F P} → Coherent alg -- eq-coh {P = P} = prop-coh λ xs → let Pxs = P xs in trunc (lhs Pxs) (rhs Pxs) open import Algebra module _ {F : Type a → Type a} where freeMonad : SetMonad a (ℓsuc a) freeMonad .SetMonad.𝐹 = Free F freeMonad .SetMonad.isSetMonad .IsSetMonad._>>=_ = _>>=_ freeMonad .SetMonad.isSetMonad .IsSetMonad.return = return freeMonad .SetMonad.isSetMonad .IsSetMonad.>>=-idˡ = >>=-idˡ freeMonad .SetMonad.isSetMonad .IsSetMonad.>>=-idʳ = >>=-idʳ freeMonad .SetMonad.isSetMonad .IsSetMonad.>>=-assoc = >>=-assoc freeMonad .SetMonad.isSetMonad .IsSetMonad.trunc = trunc module _ {ℓ} (mon : SetMonad ℓ ℓ) where module F = SetMonad mon open F using (𝐹) module _ {G : Type ℓ → Type ℓ} (h : ∀ {T} → G T → 𝐹 T) where ⟦_⟧′ : Free G A → 𝐹 A ⟦ lift x ⟧′ = h x ⟦ return x ⟧′ = F.return x ⟦ xs >>= k ⟧′ = ⟦ xs ⟧′ F.>>= λ x → ⟦ k x ⟧′ ⟦ >>=-idˡ iss f x i ⟧′ = F.>>=-idˡ iss (⟦_⟧′ ∘ f) x i ⟦ >>=-idʳ iss xs i ⟧′ = F.>>=-idʳ iss ⟦ xs ⟧′ i ⟦ >>=-assoc iss xs f g i ⟧′ = F.>>=-assoc iss ⟦ xs ⟧′ (⟦_⟧′ ∘ f) (⟦_⟧′ ∘ g) i ⟦ trunc iss xs ys p q i j ⟧′ = isOfHLevel→isOfHLevelDep 2 (λ xs → F.trunc iss) ⟦ xs ⟧′ ⟦ ys ⟧′ (cong ⟦_⟧′ p) (cong ⟦_⟧′ q) (trunc iss xs ys p q) i j module _ (hom : SetMonadHomomorphism freeMonad {F = G} ⟶ mon) where module Hom = SetMonadHomomorphism_⟶_ hom open Hom using (f) uniq-alg : (inv : ∀ {A : Type _} → (x : G A) → f (lift x) ≡ h x) → Ψ[ xs ⦂ G * ] ⇒ ⟦ xs ⟧′ ≡ f xs uniq-alg inv .snd = prop-coh λ iss xs → F.trunc iss _ _ uniq-alg inv .fst (liftF x) = sym (inv x) uniq-alg inv .fst (returnF x) = sym (Hom.return-homo x) uniq-alg inv .fst (bindF xs P⟨xs⟩ k P⟨∘k⟩) = cong₂ F._>>=_ P⟨xs⟩ (funExt P⟨∘k⟩) ; Hom.>>=-homo xs k uniq : (inv : ∀ {A : Type _} → (x : G A) → f (lift x) ≡ h x) → (xs : Free G A) → ⟦ xs ⟧′ ≡ f xs uniq inv = ⟦ uniq-alg inv ⟧ open import Cubical.Foundations.HLevels using (isSetΠ) module _ {ℓ} (fun : Functor ℓ ℓ) where open Functor fun using (map; 𝐹) module _ {B : Type ℓ} (BIsSet : isSet B) where cata-alg : (𝐹 B → B) → Ψ 𝐹 λ {T} _ → (T → B) → B cata-alg ϕ .fst (liftF x) h = ϕ (map h x) cata-alg ϕ .fst (returnF x) h = h x cata-alg ϕ .fst (bindF _ P⟨xs⟩ _ P⟨∘k⟩) h = P⟨xs⟩ (flip P⟨∘k⟩ h) cata-alg ϕ .snd .c-set _ _ = isSetΠ λ _ → BIsSet cata-alg ϕ .snd .c->>=idˡ isb f Pf x = refl cata-alg ϕ .snd .c->>=idʳ isa x Px = refl cata-alg ϕ .snd .c->>=assoc isa xs Pxs f Pf g Pg = refl cata : (A → B) → (𝐹 B → B) → Free 𝐹 A → B cata h ϕ xs = ⟦ cata-alg ϕ ⟧ xs h _>>_ : Free F A → Free F B → Free F B xs >> ys = xs >>= const ys
{ "alphanum_fraction": 0.5154070213, "avg_line_length": 39.2951807229, "ext": "agda", "hexsha": "0c1e676f60e7e10107cafcb51c5f9a1a35366321", "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": "Control/Monad/Free.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": "Control/Monad/Free.agda", "max_line_length": 137, "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": "Control/Monad/Free.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": 2948, "size": 6523 }
module 747Quantifiers where -- Library import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl) open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _≤_; z≤n; s≤s) -- added ≤ open import Relation.Nullary using (¬_) open import Data.Product using (_×_; proj₁; proj₂) renaming (_,_ to ⟨_,_⟩) -- added proj₂ open import Data.Sum using (_⊎_; inj₁; inj₂ ) -- added inj₁, inj₂ open import Function using (_∘_) -- added -- Copied from 747Isomorphism. postulate extensionality : ∀ {A B : Set} {f g : A → B} → (∀ (x : A) → f x ≡ g x) ----------------------- → f ≡ g infix 0 _≃_ record _≃_ (A B : Set) : Set where constructor mk-≃ field to : A → B from : B → A from∘to : ∀ (x : A) → from (to x) ≡ x to∘from : ∀ (y : B) → to (from y) ≡ y open _≃_ record _⇔_ (A B : Set) : Set where field to : A → B from : B → A open _⇔_ -- Logical forall is, not surpringly, ∀. -- Forall elimination is also function application. ∀-elim : ∀ {A : Set} {B : A → Set} → (L : ∀ (x : A) → B x) → (M : A) ----------------- → B M ∀-elim L M = L M -- In fact, A → B is nicer syntax for ∀ (_ : A) → B. -- 747/PLFA exercise: ForAllDistProd (1 point) -- Show that ∀ distributes over ×. -- (The special case of → distributes over × was shown in the Connectives chapter.) ∀-distrib-× : ∀ {A : Set} {B C : A → Set} → (∀ (x : A) → B x × C x) ≃ (∀ (x : A) → B x) × (∀ (x : A) → C x) ∀-distrib-× = {!!} -- 747/PLFA exercise: SumForAllImpForAllSum (1 point) -- Show that a disjunction of foralls implies a forall of disjunctions. ⊎∀-implies-∀⊎ : ∀ {A : Set} {B C : A → Set} → (∀ (x : A) → B x) ⊎ (∀ (x : A) → C x) → ∀ (x : A) → B x ⊎ C x ⊎∀-implies-∀⊎ ∀B⊎∀C = {!!} -- Existential quantification can be defined as a pair: -- a witness and a proof that the witness satisfies the property. data Σ (A : Set) (B : A → Set) : Set where ⟨_,_⟩ : (x : A) → B x → Σ A B -- Some convenient syntax. Σ-syntax = Σ infix 2 Σ-syntax syntax Σ-syntax A (λ x → B) = Σ[ x ∈ A ] B -- Unfortunately, we can use the RHS syntax in code, -- but the LHS will show up in displays of goal and context. -- This is equivalent to defining a dependent record type. record Σ′ (A : Set) (B : A → Set) : Set where field proj₁′ : A proj₂′ : B proj₁′ -- By convention, the library uses ∃ when the domain of the bound variable is implicit. ∃ : ∀ {A : Set} (B : A → Set) → Set ∃ {A} B = Σ A B -- More special syntax. ∃-syntax = ∃ syntax ∃-syntax (λ x → B) = ∃[ x ] B -- Above we saw two ways of constructing an existential. -- We eliminate an existential with a function that consumes the -- witness and proof and reaches a conclusion C. ∃-elim : ∀ {A : Set} {B : A → Set} {C : Set} → (∀ x → B x → C) → ∃[ x ] B x --------------- → C ∃-elim f ⟨ x , y ⟩ = f x y -- This is a generalization of currying (from Connectives). -- currying : ∀ {A B C : Set} → (A → B → C) ≃ (A × B → C) ∀∃-currying : ∀ {A : Set} {B : A → Set} {C : Set} → (∀ x → B x → C) ≃ (∃[ x ] B x → C) _≃_.to ∀∃-currying f ⟨ x , x₁ ⟩ = f x x₁ _≃_.from ∀∃-currying e x x₁ = e ⟨ x , x₁ ⟩ _≃_.from∘to ∀∃-currying f = refl _≃_.to∘from ∀∃-currying e = extensionality λ { ⟨ x , x₁ ⟩ → refl} -- 747/PLFA exercise: ExistsDistSum (2 points) -- Show that existentials distribute over disjunction. ∃-distrib-⊎ : ∀ {A : Set} {B C : A → Set} → ∃[ x ] (B x ⊎ C x) ≃ (∃[ x ] B x) ⊎ (∃[ x ] C x) ∃-distrib-⊎ = {!!} -- 747/PLFA exercise: ExistsProdImpProdExists (1 point) -- Show that existentials distribute over ×. ∃×-implies-×∃ : ∀ {A : Set} {B C : A → Set} → ∃[ x ] (B x × C x) → (∃[ x ] B x) × (∃[ x ] C x) ∃×-implies-×∃ = {!!} -- An existential example: revisiting even/odd. -- Recall the mutually-recursive definitions of even and odd. data even : ℕ → Set data odd : ℕ → Set data even where even-zero : even zero even-suc : ∀ {n : ℕ} → odd n ------------ → even (suc n) data odd where odd-suc : ∀ {n : ℕ} → even n ----------- → odd (suc n) -- An number is even iff it is double some other number. -- A number is odd iff is one plus double some other number. -- Proofs below. even-∃ : ∀ {n : ℕ} → even n → ∃[ m ] ( m * 2 ≡ n) odd-∃ : ∀ {n : ℕ} → odd n → ∃[ m ] (1 + m * 2 ≡ n) even-∃ even-zero = ⟨ zero , refl ⟩ even-∃ (even-suc x) with odd-∃ x even-∃ (even-suc x) | ⟨ x₁ , refl ⟩ = ⟨ suc x₁ , refl ⟩ odd-∃ (odd-suc x) with even-∃ x odd-∃ (odd-suc x) | ⟨ x₁ , refl ⟩ = ⟨ x₁ , refl ⟩ ∃-even : ∀ {n : ℕ} → ∃[ m ] ( m * 2 ≡ n) → even n ∃-odd : ∀ {n : ℕ} → ∃[ m ] (1 + m * 2 ≡ n) → odd n ∃-even ⟨ zero , refl ⟩ = even-zero ∃-even ⟨ suc x , refl ⟩ = even-suc (∃-odd ⟨ x , refl ⟩) ∃-odd ⟨ x , refl ⟩ = odd-suc (∃-even ⟨ x , refl ⟩) -- PLFA exercise: what if we write the arithmetic more "naturally"? -- (Proof gets harder but is still doable). -- 747/PLFA exercise: AltLE (3 points) -- An alternate definition of y ≤ z. -- (Optional exercise: Is this an isomorphism?) ∃-≤ : ∀ {y z : ℕ} → ( (y ≤ z) ⇔ ( ∃[ x ] (y + x ≡ z) ) ) ∃-≤ = {!!} -- The negation of an existential is isomorphic to a universal of a negation. ¬∃≃∀¬ : ∀ {A : Set} {B : A → Set} → (¬ ∃[ x ] B x) ≃ ∀ x → ¬ B x ¬∃≃∀¬ = {!!} -- 747/PLFA exercise: ExistsNegImpNegForAll (1 point) -- Existence of negation implies negation of universal. ∃¬-implies-¬∀ : ∀ {A : Set} {B : A → Set} → ∃[ x ] (¬ B x) -------------- → ¬ (∀ x → B x) ∃¬-implies-¬∀ ∃¬B = {!!} -- The converse cannot be proved in intuitionistic logic. -- PLFA exercise: isomorphism between naturals and existence of canonical binary. -- This is essentially what we did at the end of 747Isomorphism.
{ "alphanum_fraction": 0.5478865704, "avg_line_length": 27.6206896552, "ext": "agda", "hexsha": "0255c852a815c935e0ed3f3d9bb27eb10e0e08c2", "lang": "Agda", "max_forks_count": 8, "max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z", "max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z", "max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_forks_repo_licenses": [ "Unlicense" ], "max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_forks_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x08-747Quantifiers-completed.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "Unlicense" ], "max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_issues_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x08-747Quantifiers-completed.agda", "max_line_length": 89, "max_stars_count": 36, "max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225", "max_stars_repo_licenses": [ "Unlicense" ], "max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc", "max_stars_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x08-747Quantifiers-completed.agda", "max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z", "num_tokens": 2190, "size": 5607 }
-- Andreas, 2014-01-09, illegal double hiding info in typed bindings. postulate ok : ({A} : Set) → Set bad : {{A} : Set} → Set
{ "alphanum_fraction": 0.6090225564, "avg_line_length": 22.1666666667, "ext": "agda", "hexsha": "e7e88f892609da962c02d0e5a9581607d5540210", "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/Issue1391b.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/Issue1391b.agda", "max_line_length": 69, "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/Issue1391b.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": 47, "size": 133 }
{-# OPTIONS --without-K --safe #-} -- Definitions for the types of a polynomial stored in sparse horner -- normal form. -- -- These definitions ensure that the polynomial is actually in fully -- canonical form, with no trailing zeroes, etc. open import Polynomial.Parameters module Polynomial.NormalForm.Definition {a ℓ} (coeffs : RawCoeff a ℓ) where open import Polynomial.NormalForm.InjectionIndex open import Relation.Nullary using (¬_) open import Level using (_⊔_) open import Data.Empty using (⊥) open import Data.Unit using (⊤) open import Data.Nat using (ℕ; suc; zero) open import Data.Bool using (T) open import Data.List.Kleene public infixl 6 _Δ_ record PowInd {c} (C : Set c) : Set c where inductive constructor _Δ_ field coeff : C pow : ℕ open PowInd public open RawCoeff coeffs mutual -- A Polynomial is indexed by the number of variables it contains. infixl 6 _Π_ record Poly (n : ℕ) : Set a where inductive constructor _Π_ field {i} : ℕ flat : FlatPoly i i≤n : i ≤′ n data FlatPoly : ℕ → Set a where Κ : Carrier → FlatPoly zero Σ : ∀ {n} → (xs : Coeff n +) → .{xn : Norm xs} → FlatPoly (suc n) -- A list of coefficients, paired with the exponent *gap* from the -- preceding coefficient. In other words, to represent the -- polynomial: -- -- 3 + 2x² + 4x⁵ + 2x⁷ -- -- We write: -- -- [(3,0),(2,1),(4,2),(2,1)] -- -- Which can be thought of as a representation of the expression: -- -- x⁰ * (3 + x * x¹ * (2 + x * x² * (4 + x * x¹ * (2 + x * 0)))) -- -- This is sparse Horner normal form. Coeff : ℕ → Set a Coeff n = PowInd (NonZero n) -- We disallow zeroes in the coefficient list. This condition alone -- is enough to ensure a unique representation for any polynomial. infixl 6 _≠0 record NonZero (i : ℕ) : Set a where inductive constructor _≠0 field poly : Poly i .{poly≠0} : ¬ Zero poly -- This predicate is used (in its negation) to ensure that no -- coefficient is zero, preventing any trailing zeroes. Zero : ∀ {n} → Poly n → Set Zero (Κ x Π _) = T (Zero-C x) Zero (Σ _ Π _) = ⊥ -- This predicate is used to ensure that all polynomials are in -- normal form: if a particular level is constant, than it can -- be collapsed into the level below it. Norm : ∀ {i} → Coeff i + → Set Norm (_ Δ zero & []) = ⊥ Norm (_ Δ zero & ∹ _) = ⊤ Norm (_ Δ suc _ & _) = ⊤ open NonZero public open Poly public
{ "alphanum_fraction": 0.6253943218, "avg_line_length": 26.4166666667, "ext": "agda", "hexsha": "95dfdbf1394d6f4aeca74f3b9f8aff753615ec07", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2022-01-20T07:07:11.000Z", "max_forks_repo_forks_event_min_datetime": "2019-04-16T02:23:16.000Z", "max_forks_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "mckeankylej/agda-ring-solver", "max_forks_repo_path": "src/Polynomial/NormalForm/Definition.agda", "max_issues_count": 5, "max_issues_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500", "max_issues_repo_issues_event_max_datetime": "2022-03-12T01:55:42.000Z", "max_issues_repo_issues_event_min_datetime": "2019-04-17T20:48:48.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "mckeankylej/agda-ring-solver", "max_issues_repo_path": "src/Polynomial/NormalForm/Definition.agda", "max_line_length": 69, "max_stars_count": 36, "max_stars_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "mckeankylej/agda-ring-solver", "max_stars_repo_path": "src/Polynomial/NormalForm/Definition.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-15T00:57:55.000Z", "max_stars_repo_stars_event_min_datetime": "2019-01-25T16:40:52.000Z", "num_tokens": 796, "size": 2536 }
{-# OPTIONS --warning=error --safe --without-K --guardedness #-} open import Sets.EquivalenceRelations open import Functions.Definition open import Functions.Lemmas open import Sets.FinSet.Definition open import Sets.FinSet.Lemmas open import Sets.Cardinality.Finite.Definition open import LogicalFormulae open import Groups.Definition open import Groups.Groups open import Groups.FiniteGroups.Definition open import Groups.Abelian.Definition open import Setoids.Setoids open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order open import Numbers.Integers.Integers open import Numbers.Rationals.Definition open import Numbers.Reals.Definition open import Rings.Definition open import Fields.FieldOfFractions.Setoid open import Semirings.Definition open import Numbers.Modulo.Definition open import Numbers.Modulo.Group open import Fields.Fields open import Setoids.Subset open import Rings.IntegralDomains.Definition open import Fields.Lemmas open import Rings.Examples.Examples module LectureNotes.Groups.Lecture1 where -- Examples groupExample1 : Group (reflSetoid ℤ) (_+Z_) groupExample1 = ℤGroup groupExample2 : Group ℚSetoid (_+Q_) groupExample2 = Ring.additiveGroup ℚRing groupExample2' : Group ℝSetoid (_+R_) groupExample2' = Ring.additiveGroup ℝRing groupExample3 : Group (reflSetoid ℤ) (_-Z_) → False groupExample3 record { +Associative = multAssoc } with multAssoc {nonneg 3} {nonneg 2} {nonneg 1} groupExample3 record { +WellDefined = wellDefined } | () negSuccInjective : {a b : ℕ} → (negSucc a ≡ negSucc b) → a ≡ b negSuccInjective {a} {.a} refl = refl nonnegInjective : {a b : ℕ} → (nonneg a ≡ nonneg b) → a ≡ b nonnegInjective {a} {.a} refl = refl integersTimesNotGroup : Group (reflSetoid ℤ) (_*Z_) → False integersTimesNotGroup = multiplicationNotGroup ℤRing λ () rationalsTimesNotGroup : Group ℚSetoid (_*Q_) → False rationalsTimesNotGroup = multiplicationNotGroup ℚRing λ () QNonzeroGroup : Group _ _ QNonzeroGroup = fieldMultiplicativeGroup ℚField -- TODO: {1, -1} is a group with * ℤnIsGroup : (n : ℕ) → (0<n : 0 <N n) → _ ℤnIsGroup n pr = ℤnGroup n pr -- Groups example 8.9 from lecture 1 data Weird : Set where e : Weird a : Weird b : Weird c : Weird _+W_ : Weird → Weird → Weird e +W t = t a +W e = a a +W a = e a +W b = c a +W c = b b +W e = b b +W a = c b +W b = e b +W c = a c +W e = c c +W a = b c +W b = a c +W c = e +WAssoc : {x y z : Weird} → (x +W (y +W z)) ≡ (x +W y) +W z +WAssoc {e} {y} {z} = refl +WAssoc {a} {e} {z} = refl +WAssoc {a} {a} {e} = refl +WAssoc {a} {a} {a} = refl +WAssoc {a} {a} {b} = refl +WAssoc {a} {a} {c} = refl +WAssoc {a} {b} {e} = refl +WAssoc {a} {b} {a} = refl +WAssoc {a} {b} {b} = refl +WAssoc {a} {b} {c} = refl +WAssoc {a} {c} {e} = refl +WAssoc {a} {c} {a} = refl +WAssoc {a} {c} {b} = refl +WAssoc {a} {c} {c} = refl +WAssoc {b} {e} {z} = refl +WAssoc {b} {a} {e} = refl +WAssoc {b} {a} {a} = refl +WAssoc {b} {a} {b} = refl +WAssoc {b} {a} {c} = refl +WAssoc {b} {b} {e} = refl +WAssoc {b} {b} {a} = refl +WAssoc {b} {b} {b} = refl +WAssoc {b} {b} {c} = refl +WAssoc {b} {c} {e} = refl +WAssoc {b} {c} {a} = refl +WAssoc {b} {c} {b} = refl +WAssoc {b} {c} {c} = refl +WAssoc {c} {e} {z} = refl +WAssoc {c} {a} {e} = refl +WAssoc {c} {a} {a} = refl +WAssoc {c} {a} {b} = refl +WAssoc {c} {a} {c} = refl +WAssoc {c} {b} {e} = refl +WAssoc {c} {b} {a} = refl +WAssoc {c} {b} {b} = refl +WAssoc {c} {b} {c} = refl +WAssoc {c} {c} {e} = refl +WAssoc {c} {c} {a} = refl +WAssoc {c} {c} {b} = refl +WAssoc {c} {c} {c} = refl weirdGroup : Group (reflSetoid Weird) _+W_ Group.+WellDefined weirdGroup = reflGroupWellDefined Group.0G weirdGroup = e Group.inverse weirdGroup t = t Group.+Associative weirdGroup {r} {s} {t} = +WAssoc {r} {s} {t} Group.identRight weirdGroup {e} = refl Group.identRight weirdGroup {a} = refl Group.identRight weirdGroup {b} = refl Group.identRight weirdGroup {c} = refl Group.identLeft weirdGroup {e} = refl Group.identLeft weirdGroup {a} = refl Group.identLeft weirdGroup {b} = refl Group.identLeft weirdGroup {c} = refl Group.invLeft weirdGroup {e} = refl Group.invLeft weirdGroup {a} = refl Group.invLeft weirdGroup {b} = refl Group.invLeft weirdGroup {c} = refl Group.invRight weirdGroup {e} = refl Group.invRight weirdGroup {a} = refl Group.invRight weirdGroup {b} = refl Group.invRight weirdGroup {c} = refl weirdAb : AbelianGroup weirdGroup AbelianGroup.commutative weirdAb {e} {e} = refl AbelianGroup.commutative weirdAb {e} {a} = refl AbelianGroup.commutative weirdAb {e} {b} = refl AbelianGroup.commutative weirdAb {e} {c} = refl AbelianGroup.commutative weirdAb {a} {e} = refl AbelianGroup.commutative weirdAb {a} {a} = refl AbelianGroup.commutative weirdAb {a} {b} = refl AbelianGroup.commutative weirdAb {a} {c} = refl AbelianGroup.commutative weirdAb {b} {e} = refl AbelianGroup.commutative weirdAb {b} {a} = refl AbelianGroup.commutative weirdAb {b} {b} = refl AbelianGroup.commutative weirdAb {b} {c} = refl AbelianGroup.commutative weirdAb {c} {e} = refl AbelianGroup.commutative weirdAb {c} {a} = refl AbelianGroup.commutative weirdAb {c} {b} = refl AbelianGroup.commutative weirdAb {c} {c} = refl weirdProjection : Weird → FinSet 4 weirdProjection a = ofNat 0 (le 3 refl) weirdProjection b = ofNat 1 (le 2 refl) weirdProjection c = ofNat 2 (le 1 refl) weirdProjection e = ofNat 3 (le zero refl) weirdProjectionSurj : Surjection weirdProjection weirdProjectionSurj fzero = a , refl weirdProjectionSurj (fsucc fzero) = b , refl weirdProjectionSurj (fsucc (fsucc fzero)) = c , refl weirdProjectionSurj (fsucc (fsucc (fsucc fzero))) = e , refl weirdProjectionSurj (fsucc (fsucc (fsucc (fsucc ())))) weirdProjectionInj : (x y : Weird) → weirdProjection x ≡ weirdProjection y → Setoid._∼_ (reflSetoid Weird) x y weirdProjectionInj e e fx=fy = refl weirdProjectionInj e a () weirdProjectionInj e b () weirdProjectionInj e c () weirdProjectionInj a e () weirdProjectionInj a a fx=fy = refl weirdProjectionInj a b () weirdProjectionInj a c () weirdProjectionInj b e () weirdProjectionInj b a () weirdProjectionInj b b fx=fy = refl weirdProjectionInj b c () weirdProjectionInj c e () weirdProjectionInj c a () weirdProjectionInj c b () weirdProjectionInj c c fx=fy = refl weirdFinite : FiniteGroup weirdGroup (FinSet 4) SetoidToSet.project (FiniteGroup.toSet weirdFinite) = weirdProjection SetoidToSet.wellDefined (FiniteGroup.toSet weirdFinite) x y = applyEquality weirdProjection SetoidToSet.surj (FiniteGroup.toSet weirdFinite) = weirdProjectionSurj SetoidToSet.inj (FiniteGroup.toSet weirdFinite) = weirdProjectionInj FiniteSet.size (FiniteGroup.finite weirdFinite) = 4 FiniteSet.mapping (FiniteGroup.finite weirdFinite) = id FiniteSet.bij (FiniteGroup.finite weirdFinite) = idIsBijective weirdOrder : groupOrder weirdFinite ≡ 4 weirdOrder = refl
{ "alphanum_fraction": 0.7132136551, "avg_line_length": 31.7570093458, "ext": "agda", "hexsha": "8a660ddbf44ff24d8698f08ad60e7cfb434c9486", "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": "LectureNotes/Groups/Lecture1.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": "LectureNotes/Groups/Lecture1.agda", "max_line_length": 110, "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": "LectureNotes/Groups/Lecture1.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": 2389, "size": 6796 }
open import Function using (_∘_) open import Category.Functor open import Category.Monad open import Data.Fin as Fin using (Fin) renaming (suc to fs; zero to fz) import Data.Fin.Properties as FinProps open import Data.Maybe as Maybe using (Maybe; maybe; just; nothing) open import Data.Nat as Nat using (ℕ; suc; zero; _+_; _⊔_) open import Data.Product using (Σ; ∃; _,_; proj₁; proj₂) renaming (_×_ to _∧_) open import Data.Sum using (_⊎_; inj₁; inj₂; [_,_]) open import Data.Vec as Vec using (Vec; []; _∷_; head; tail) open import Data.Vec.Equality as VecEq open import Relation.Nullary using (Dec; yes; no; ¬_) open import Relation.Binary open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl; cong; inspect; [_]) module Unification (Name : ℕ → Set) (decEqName : ∀ {k} (x y : Name k) → Dec (x ≡ y)) where open RawFunctor {{...}} open RawMonad {{...}} hiding (_<$>_) open DecSetoid {{...}} using (_≟_) instance MaybeFunctor = Maybe.functor instance MaybeMonad = Maybe.monad private natDecSetoid = PropEq.decSetoid Nat._≟_ private finDecSetoid : ∀ {n} → DecSetoid _ _ finDecSetoid {n} = FinProps.decSetoid n private nameDecSetoid : ∀ {k} → DecSetoid _ _ nameDecSetoid {k} = PropEq.decSetoid (decEqName {k}) -- defining terms data Term (n : ℕ) : Set where var : Fin n → Term n con : ∀ {k} (s : Name k) → (ts : Vec (Term n) k) → Term n -- defining decidable equality on terms mutual decEqTerm : ∀ {n} → (t₁ t₂ : Term n) → Dec (t₁ ≡ t₂) decEqTerm (var x₁) (var x₂) with x₁ FinProps.≟ x₂ decEqTerm (var .x₂) (var x₂) | yes refl = yes refl decEqTerm (var x₁) (var x₂) | no x₁≢x₂ = no (x₁≢x₂ ∘ elim) where elim : ∀ {n} {x y : Fin n} → var x ≡ var y → x ≡ y elim {n} {x} {.x} refl = refl decEqTerm (var _) (con _ _) = no (λ ()) decEqTerm (con _ _) (var _) = no (λ ()) decEqTerm (con {k₁} s₁ ts₁) (con {k₂} s₂ ts₂) with k₁ Nat.≟ k₂ decEqTerm (con {k₁} s₁ ts₁) (con {k₂} s₂ ts₂) | no k₁≢k₂ = no (k₁≢k₂ ∘ elim) where elim : ∀ {n k₁ k₂ s₁ s₂} {ts₁ : Vec (Term n) k₁} {ts₂ : Vec (Term n) k₂} → con {n} {k₁} s₁ ts₁ ≡ con {n} {k₂} s₂ ts₂ → k₁ ≡ k₂ elim {n} {k} {.k} refl = refl decEqTerm (con {.k} s₁ ts₁) (con { k} s₂ ts₂) | yes refl with decEqName s₁ s₂ decEqTerm (con s₁ ts₁) (con s₂ ts₂) | yes refl | no s₁≢s₂ = no (s₁≢s₂ ∘ elim) where elim : ∀ {n k s₁ s₂} {ts₁ ts₂ : Vec (Term n) k} → con s₁ ts₁ ≡ con s₂ ts₂ → s₁ ≡ s₂ elim {n} {k} {s} {.s} refl = refl decEqTerm (con .s ts₁) (con s ts₂) | yes refl | yes refl with decEqVecTerm ts₁ ts₂ decEqTerm (con .s ts₁) (con s ts₂) | yes refl | yes refl | no ts₁≢ts₂ = no (ts₁≢ts₂ ∘ elim) where elim : ∀ {n k s} {ts₁ ts₂ : Vec (Term n) k} → con s ts₁ ≡ con s ts₂ → ts₁ ≡ ts₂ elim {n} {k} {s} {ts} {.ts} refl = refl decEqTerm (con .s .ts) (con s ts) | yes refl | yes refl | yes refl = yes refl decEqVecTerm : ∀ {n k} → (xs ys : Vec (Term n) k) → Dec (xs ≡ ys) decEqVecTerm [] [] = yes refl decEqVecTerm (x ∷ xs) ( y ∷ ys) with decEqTerm x y | decEqVecTerm xs ys decEqVecTerm (x ∷ xs) (.x ∷ .xs) | yes refl | yes refl = yes refl decEqVecTerm (x ∷ xs) ( y ∷ ys) | yes _ | no xs≢ys = no (xs≢ys ∘ cong tail) decEqVecTerm (x ∷ xs) ( y ∷ ys) | no x≢y | _ = no (x≢y ∘ cong head) termDecSetoid : ∀ {n} → DecSetoid _ _ termDecSetoid {n} = PropEq.decSetoid (decEqTerm {n}) -- defining replacement function (written _◂ in McBride, 2003) mutual replace : ∀ {n m} → (Fin n → Term m) → Term n → Term m replace f (var i) = f i replace f (con s ts) = con s (replaceChildren f ts) replaceChildren : ∀ {n m k} → (Fin n → Term m) → Vec (Term n) k → Vec (Term m) k replaceChildren f [] = [] replaceChildren f (x ∷ xs) = replace f x ∷ (replaceChildren f xs) -- defining replacement composition _◇_ : ∀ {m n l} (f : Fin m → Term n) (g : Fin l → Term m) → Fin l → Term n _◇_ f g = replace f ∘ g -- defining thick and thin thin : {n : ℕ} -> Fin (suc n) -> Fin n -> Fin (suc n) thin fz y = fs y thin (fs x) fz = fz thin (fs x) (fs y) = fs (thin x y) thick : {n : ℕ} -> (x y : Fin (suc n)) -> Maybe (Fin n) thick fz fz = nothing thick fz (fs y) = just y thick {Nat.zero} (fs ()) _ thick {Nat.suc n} (fs x) fz = just fz thick {Nat.suc n} (fs x) (fs y) = fs <$> (thick x y) -- | defining an occurs check (**check** in McBride, 2003) mutual check : ∀ {n} (x : Fin (suc n)) (t : Term (suc n)) → Maybe (Term n) check x₁ (var x₂) = var <$> thick x₁ x₂ check x₁ (con s ts) = con s <$> checkChildren x₁ ts checkChildren : ∀ {n k} (x : Fin (suc n)) (ts : Vec (Term (suc n)) k) → Maybe (Vec (Term n) k) checkChildren x₁ [] = just [] checkChildren x₁ (t ∷ ts) = check x₁ t >>= λ t' → checkChildren x₁ ts >>= λ ts' → return (t' ∷ ts') -- | datatype for substitutions (AList in McBride, 2003) data Subst : ℕ → ℕ → Set where nil : ∀ {n} → Subst n n snoc : ∀ {m n} → (s : Subst m n) → (t : Term m) → (x : Fin (suc m)) → Subst (suc m) n -- | substitutes t for x (**for** in McBride, 2003) _for_ : ∀ {n} (t : Term n) (x : Fin (suc n)) → Fin (suc n) → Term n _for_ t x y with thick x y _for_ t x y | just y' = var y' _for_ t x y | nothing = t -- | substitution application (**sub** in McBride, 2003) apply : ∀ {m n} → Subst m n → Fin m → Term n apply nil = var apply (snoc s t x) = (apply s) ◇ (t for x) -- | composes two substitutions _⊕_ : ∀ {l m n} → Subst m n → Subst l m → Subst l n s₁ ⊕ nil = s₁ s₁ ⊕ (snoc s₂ t x) = snoc (s₁ ⊕ s₂) t x flexRigid : ∀ {n} → Fin n → Term n → Maybe (∃ (Subst n)) flexRigid {zero} () t flexRigid {suc n} x t with check x t flexRigid {suc n} x t | nothing = nothing flexRigid {suc n} x t | just t' = just (n , snoc nil t' x) flexFlex : ∀ {n} → (x y : Fin n) → ∃ (Subst n) flexFlex {zero} () j flexFlex {suc n} x y with thick x y flexFlex {suc n} x y | nothing = (suc n , nil) flexFlex {suc n} x y | just z = (n , snoc nil (var z) x) mutual unifyAcc : ∀ {m} → (t₁ t₂ : Term m) → ∃ (Subst m) → Maybe (∃ (Subst m)) unifyAcc (con {k₁} s₁ ts₁) (con {k₂} s₂ ts₂) acc with k₁ Nat.≟ k₂ unifyAcc (con {k₁} s₁ ts₁) (con {k₂} s₂ ts₂) acc | no k₁≢k₂ = nothing unifyAcc (con { k} s₁ ts₁) (con {.k} s₂ ts₂) acc | yes refl with decEqName s₁ s₂ unifyAcc (con { k} s₁ ts₁) (con {.k} s₂ ts₂) acc | yes refl | no s₁≢s₂ = nothing unifyAcc (con { k} .s ts₁) (con {.k} s ts₂) acc | yes refl | yes refl = unifyAccChildren ts₁ ts₂ acc unifyAcc (var x₁) (var x₂) (n , nil) = just (flexFlex x₁ x₂) unifyAcc (var x₁) t₂ (n , nil) = flexRigid x₁ t₂ unifyAcc t₁ (var x₂) (n , nil) = flexRigid x₂ t₁ unifyAcc t₁ t₂ (n , snoc s t' x) = ( λ s → proj₁ s , snoc (proj₂ s) t' x ) <$> unifyAcc (replace (t' for x) t₁) (replace (t' for x) t₂) (n , s) unifyAccChildren : ∀ {n k} → (ts₁ ts₂ : Vec (Term n) k) → ∃ (Subst n) → Maybe (∃ (Subst n)) unifyAccChildren [] [] acc = just acc unifyAccChildren (t₁ ∷ ts₁) (t₂ ∷ ts₂) acc = unifyAcc t₁ t₂ acc >>= unifyAccChildren ts₁ ts₂ unify : ∀ {m} → (t₁ t₂ : Term m) → Maybe (∃ (Subst m)) unify {m} t₁ t₂ = unifyAcc t₁ t₂ (m , nil)
{ "alphanum_fraction": 0.5626099905, "avg_line_length": 40.8121546961, "ext": "agda", "hexsha": "7b24a90ee4dc42241093fcb07f292f6c9f0cbea7", "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": "5fc229e7eb6925dd3ea8e5d8e8bfbff4500c5614", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "wenkokke/FirstOrderUnificationInAgda", "max_forks_repo_path": "Unification.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "5fc229e7eb6925dd3ea8e5d8e8bfbff4500c5614", "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": "wenkokke/FirstOrderUnificationInAgda", "max_issues_repo_path": "Unification.agda", "max_line_length": 105, "max_stars_count": 3, "max_stars_repo_head_hexsha": "5fc229e7eb6925dd3ea8e5d8e8bfbff4500c5614", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "wenkokke/FirstOrderUnificationInAgda", "max_stars_repo_path": "Unification.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-06T21:58:31.000Z", "max_stars_repo_stars_event_min_datetime": "2017-07-27T22:15:32.000Z", "num_tokens": 2932, "size": 7387 }
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module SL where open import Data.Nat open import Data.Product open import Data.Sum open import Relation.Binary.PropositionalEquality -- Example from: Hofmann and Streicher. The groupoid model refutes -- uniqueness of identity proofs. thm₁ : ∀ n → n ≡ 0 ⊎ Σ ℕ (λ n' → n ≡ suc n') thm₁ zero = inj₁ refl thm₁ (suc n) = inj₂ (n , refl) postulate indℕ : (P : ℕ → Set) → P 0 → (∀ n → P n → P (suc n)) → ∀ n → P n thm₂ : ∀ n → n ≡ 0 ⊎ Σ ℕ λ n' → n ≡ suc n' thm₂ = indℕ P P0 is where P : ℕ → Set P m = m ≡ 0 ⊎ Σ ℕ λ m' → m ≡ suc m' P0 : P 0 P0 = inj₁ refl is : ∀ m → P m → P (suc m) is m _ = inj₂ (m , refl)
{ "alphanum_fraction": 0.5457920792, "avg_line_length": 25.25, "ext": "agda", "hexsha": "a46d9efb64def5bcb16f802904a485a6a2536168", "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/k-axiom/SL.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/k-axiom/SL.agda", "max_line_length": 74, "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/k-axiom/SL.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": 292, "size": 808 }
module Irrelevant where open import Common.IO open import Common.Nat open import Common.Unit A : Set A = Nat record R : Set where id : A → A id x = x postulate r : R id2 : .A → A → A id2 x y = y open R main : IO Unit main = printNat (id2 10 20) ,, printNat (id r 30) ,, return unit
{ "alphanum_fraction": 0.6363636364, "avg_line_length": 11.88, "ext": "agda", "hexsha": "7d3c5da7a7397749c7ae9bd80092f8b41179d0a7", "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/Compiler/simple/Irrelevant.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/Compiler/simple/Irrelevant.agda", "max_line_length": 30, "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/Compiler/simple/Irrelevant.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": 108, "size": 297 }