id
stringlengths
27
136
text
stringlengths
4
1.05M
algebraic-stack_agda0000_doc_5964
module reverse_string where open import Data.String open import Data.List reverse_string : String → String reverse_string s = fromList (reverse (toList s))
algebraic-stack_agda0000_doc_5965
{-# OPTIONS --safe --without-K #-} open import Algebra.Bundles using (Monoid) module Categories.Category.Construction.MonoidAsCategory o {c ℓ} (M : Monoid c ℓ) where open import Data.Unit.Polymorphic open import Level open import Categories.Category.Core open Monoid M -- A monoid is a category with one object MonoidAsCategory : Category o c ℓ MonoidAsCategory = record { Obj = ⊤ ; assoc = assoc _ _ _ ; sym-assoc = sym (assoc _ _ _) ; identityˡ = identityˡ _ ; identityʳ = identityʳ _ ; identity² = identityˡ _ ; equiv = isEquivalence ; ∘-resp-≈ = ∙-cong }
algebraic-stack_agda0000_doc_5966
------------------------------------------------------------------------------ -- Non-terminating GCD ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOT.FOTC.Program.GCD.GCD-NT where open import Data.Nat open import Relation.Nullary ------------------------------------------------------------------------------ {-# TERMINATING #-} gcd : ℕ → ℕ → ℕ gcd 0 0 = 0 gcd (suc m) 0 = suc m gcd 0 (suc n) = suc n gcd (suc m) (suc n) with suc m ≤? suc n gcd (suc m) (suc n) | yes p = gcd (suc m) (suc n ∸ suc m) gcd (suc m) (suc n) | no ¬p = gcd (suc m ∸ suc n) (suc n)
algebraic-stack_agda0000_doc_5967
module Structure.Signature where open import Data.Tuple.Raise open import Data.Tuple.Raiseᵣ.Functions import Lvl open import Numeral.Natural open import Structure.Function open import Structure.Setoid open import Structure.Relator open import Type private variable ℓ ℓᵢ ℓᵢ₁ ℓᵢ₂ ℓᵢ₃ ℓd ℓd₁ ℓd₂ ℓᵣ ℓᵣ₁ ℓᵣ₂ ℓₑ ℓₑ₁ ℓₑ₂ : Lvl.Level private variable n : ℕ -- A signature consists of a countable family of sets of function and relation symbols. -- `functions(n)` and `relations(n)` should be interpreted as the indices for functions/relations of arity `n`. record Signature : Type{Lvl.𝐒(ℓᵢ₁ Lvl.⊔ ℓᵢ₂)} where field functions : ℕ → Type{ℓᵢ₁} relations : ℕ → Type{ℓᵢ₂} private variable s : Signature{ℓᵢ₁}{ℓᵢ₂} import Data.Tuple.Equiv as Tuple -- A structure with a signature `s` consists of a domain and interpretations of the function/relation symbols in `s`. record Structure (s : Signature{ℓᵢ₁}{ℓᵢ₂}) : Type{Lvl.𝐒(ℓₑ Lvl.⊔ ℓd Lvl.⊔ ℓᵣ) Lvl.⊔ ℓᵢ₁ Lvl.⊔ ℓᵢ₂} where open Signature(s) field domain : Type{ℓd} ⦃ equiv ⦄ : ∀{n} → Equiv{ℓₑ}(domain ^ n) ⦃ ext ⦄ : ∀{n} → Tuple.Extensionality(equiv{𝐒(𝐒 n)}) function : functions(n) → ((domain ^ n) → domain) ⦃ function-func ⦄ : ∀{fi} → Function(function{n} fi) relation : relations(n) → ((domain ^ n) → Type{ℓᵣ}) ⦃ relation-func ⦄ : ∀{ri} → UnaryRelator(relation{n} ri) open Structure public using() renaming (domain to dom ; function to fn ; relation to rel) open import Logic.Predicate module _ {s : Signature{ℓᵢ₁}{ℓᵢ₂}} where private variable A B C S : Structure{ℓd = ℓd}{ℓᵣ = ℓᵣ}(s) private variable fi : Signature.functions s n private variable ri : Signature.relations s n private variable xs : dom(S) ^ n record Homomorphism (A : Structure{ℓₑ = ℓₑ₁}{ℓd = ℓd₁}{ℓᵣ = ℓᵣ₁}(s)) (B : Structure{ℓₑ = ℓₑ₂}{ℓd = ℓd₂}{ℓᵣ = ℓᵣ₂}(s)) (f : dom(A) → dom(B)) : Type{ℓₑ₁ Lvl.⊔ ℓₑ₂ Lvl.⊔ ℓd₁ Lvl.⊔ ℓd₂ Lvl.⊔ ℓᵣ₁ Lvl.⊔ ℓᵣ₂ Lvl.⊔ Lvl.ofType(Type.of s)} where field ⦃ function ⦄ : Function(f) preserve-functions : ∀{xs : dom(A) ^ n} → (f(fn(A) fi xs) ≡ fn(B) fi (map f xs)) preserve-relations : ∀{xs : dom(A) ^ n} → (rel(A) ri xs) → (rel(B) ri (map f xs)) _→ₛₜᵣᵤ_ : Structure{ℓₑ = ℓₑ₁}{ℓd = ℓd₁}{ℓᵣ = ℓᵣ₁}(s) → Structure{ℓₑ = ℓₑ₂}{ℓd = ℓd₂}{ℓᵣ = ℓᵣ₂}(s) → Type A →ₛₜᵣᵤ B = ∃(Homomorphism A B) open import Data open import Data.Tuple as Tuple using (_,_) open import Data.Tuple.Raiseᵣ.Proofs open import Functional open import Function.Proofs open import Lang.Instance open import Structure.Operator open import Structure.Relator.Properties open import Syntax.Transitivity idₛₜᵣᵤ : A →ₛₜᵣᵤ A ∃.witness idₛₜᵣᵤ = id Homomorphism.preserve-functions (∃.proof (idₛₜᵣᵤ {A = A})) {n} {fi} {xs} = congruence₁(fn A fi) (symmetry(Equiv._≡_ (Structure.equiv A)) ⦃ Equiv.symmetry infer ⦄ map-id) Homomorphism.preserve-relations (∃.proof (idₛₜᵣᵤ {A = A})) {n} {ri} {xs} = substitute₁ₗ(rel A ri) map-id _∘ₛₜᵣᵤ_ : let _ = A , B , C in (B →ₛₜᵣᵤ C) → (A →ₛₜᵣᵤ B) → (A →ₛₜᵣᵤ C) ∃.witness (([∃]-intro f) ∘ₛₜᵣᵤ ([∃]-intro g)) = f ∘ g Homomorphism.function (∃.proof ([∃]-intro f ∘ₛₜᵣᵤ [∃]-intro g)) = [∘]-function {f = f}{g = g} Homomorphism.preserve-functions (∃.proof (_∘ₛₜᵣᵤ_ {A = A} {B = B} {C = C} ([∃]-intro f ⦃ hom-f ⦄) ([∃]-intro g ⦃ hom-g ⦄))) {fi = fi} = transitivity(_≡_) ⦃ Equiv.transitivity infer ⦄ (transitivity(_≡_) ⦃ Equiv.transitivity infer ⦄ (congruence₁(f) (Homomorphism.preserve-functions hom-g)) (Homomorphism.preserve-functions hom-f)) (congruence₁(fn C fi) (symmetry(Equiv._≡_ (Structure.equiv C)) ⦃ Equiv.symmetry infer ⦄ (map-[∘] {f = f}{g = g}))) Homomorphism.preserve-relations (∃.proof (_∘ₛₜᵣᵤ_ {A = A} {B = B} {C = C} ([∃]-intro f ⦃ hom-f ⦄) ([∃]-intro g ⦃ hom-g ⦄))) {ri = ri} = substitute₁ₗ (rel C ri) map-[∘] ∘ Homomorphism.preserve-relations hom-f ∘ Homomorphism.preserve-relations hom-g open import Function.Equals open import Function.Equals.Proofs open import Logic.Predicate.Equiv open import Structure.Category open import Structure.Categorical.Properties Structure-Homomorphism-category : Category(_→ₛₜᵣᵤ_ {ℓₑ}{ℓd}{ℓᵣ}) Category._∘_ Structure-Homomorphism-category = _∘ₛₜᵣᵤ_ Category.id Structure-Homomorphism-category = idₛₜᵣᵤ BinaryOperator.congruence (Category.binaryOperator Structure-Homomorphism-category) = [⊜][∘]-binaryOperator-raw _⊜_.proof (Morphism.Associativity.proof (Category.associativity Structure-Homomorphism-category) {_} {_} {_} {_} {[∃]-intro f} {[∃]-intro g} {[∃]-intro h}) {x} = reflexivity(_≡_) ⦃ Equiv.reflexivity infer ⦄ {f(g(h(x)))} _⊜_.proof (Morphism.Identityₗ.proof (Tuple.left (Category.identity Structure-Homomorphism-category)) {f = [∃]-intro f}) {x} = reflexivity(_≡_) ⦃ Equiv.reflexivity infer ⦄ {f(x)} _⊜_.proof (Morphism.Identityᵣ.proof (Tuple.right (Category.identity Structure-Homomorphism-category)) {f = [∃]-intro f}) {x} = reflexivity(_≡_) ⦃ Equiv.reflexivity infer ⦄ {f(x)} module _ (s : Signature{ℓᵢ₁}{ℓᵢ₂}) where data Term : Type{ℓᵢ₁} where var : ℕ → Term func : (Signature.functions s n) → (Term ^ n) → Term
algebraic-stack_agda0000_doc_272
module Issue59 where data Nat : Set where zero : Nat suc : Nat → Nat -- This no longer termination checks with the -- new rules for with. bad : Nat → Nat bad n with n ... | zero = zero ... | suc m = bad m -- This shouldn't termination check. bad₂ : Nat → Nat bad₂ n with bad₂ n ... | m = m
algebraic-stack_agda0000_doc_273
module Cats.Util.SetoidMorphism.Iso where open import Data.Product using (_,_ ; proj₁ ; proj₂) open import Level using (_⊔_) open import Relation.Binary using (Setoid ; IsEquivalence) open import Cats.Util.SetoidMorphism as Mor using ( _⇒_ ; arr ; resp ; _≈_ ; ≈-intro ; ≈-elim ; ≈-elim′ ; _∘_ ; ∘-resp ; id ; IsInjective ; IsSurjective) open import Cats.Util.SetoidReasoning private module S = Setoid record IsIso {l l≈} {A : Setoid l l≈} {l′ l≈′} {B : Setoid l′ l≈′} (f : A ⇒ B) : Set (l ⊔ l≈ ⊔ l′ ⊔ l≈′) where field back : B ⇒ A forth-back : f ∘ back ≈ id back-forth : back ∘ f ≈ id open IsIso record _≅_ {l l≈} (A : Setoid l l≈) {l′ l≈′} (B : Setoid l′ l≈′) : Set (l ⊔ l≈ ⊔ l′ ⊔ l≈′) where field forth : A ⇒ B back : B ⇒ A forth-back : forth ∘ back ≈ id back-forth : back ∘ forth ≈ id open _≅_ public IsIso→≅ : ∀ {l l≈} {A : Setoid l l≈} {l′ l≈′} {B : Setoid l′ l≈′} (f : A ⇒ B) → IsIso f → A ≅ B IsIso→≅ f i = record { forth = f ; back = back i ; forth-back = forth-back i ; back-forth = back-forth i } ≅→IsIso : ∀ {l l≈} {A : Setoid l l≈} {l′ l≈′} {B : Setoid l′ l≈′} → (i : A ≅ B) → IsIso (forth i) ≅→IsIso i = record { back = back i ; forth-back = forth-back i ; back-forth = back-forth i } IsIso-resp : ∀ {l l≈} {A : Setoid l l≈} {l′ l≈′} {B : Setoid l′ l≈′} → {f g : A ⇒ B} → f ≈ g → IsIso f → IsIso g IsIso-resp {A = A} {B = B} {f} {g} f≈g i = record { back = back i ; forth-back = ≈-intro λ {x} {y} x≈y → begin⟨ B ⟩ arr g (arr (back i) x) ≈⟨ B.sym (≈-elim f≈g (resp (back i) (B.sym x≈y))) ⟩ arr f (arr (back i) y) ≈⟨ ≈-elim′ (forth-back i) ⟩ y ∎ ; back-forth = ≈-intro λ {x} {y} x≈y → begin⟨ A ⟩ arr (back i) (arr g x) ≈⟨ resp (back i) (B.sym (≈-elim f≈g (A.sym x≈y))) ⟩ arr (back i) (arr f y) ≈⟨ ≈-elim′ (back-forth i) ⟩ y ∎ } where module A = Setoid A module B = Setoid B refl : ∀ {l l≈} {A : Setoid l l≈} → A ≅ A refl = record { forth = id ; back = id ; forth-back = ≈-intro λ eq → eq ; back-forth = ≈-intro λ eq → eq } sym : ∀ {l l≈} {A : Setoid l l≈} {l′ l≈′} {B : Setoid l′ l≈′} → A ≅ B → B ≅ A sym i = record { forth = back i ; back = forth i ; forth-back = back-forth i ; back-forth = forth-back i } trans : ∀ {l l≈} {A : Setoid l l≈} {l′ l≈′} {B : Setoid l′ l≈′} → ∀ {l″ l≈″} {C : Setoid l″ l≈″} → A ≅ B → B ≅ C → A ≅ C trans {A = A} {C = C} AB BC = record { forth = forth BC ∘ forth AB ; back = back AB ∘ back BC ; forth-back = ≈-intro λ x≈y → S.trans C (resp (forth BC) (≈-elim (forth-back AB) (resp (back BC) x≈y))) (≈-elim′ (forth-back BC)) ; back-forth = ≈-intro λ x≈y → S.trans A (resp (back AB) (≈-elim (back-forth BC) (resp (forth AB) x≈y))) (≈-elim′ (back-forth AB)) } module _ {l l≈} {A : Setoid l l≈} {l′ l≈′} {B : Setoid l′ l≈′} where Injective∧Surjective→Iso : {f : A ⇒ B} → IsInjective f → IsSurjective f → IsIso f Injective∧Surjective→Iso {f} inj surj = record { back = record { arr = λ b → proj₁ (surj b) ; resp = λ {b} {c} b≈c → inj (S.trans B (S.sym B (proj₂ (surj b))) (S.trans B b≈c (proj₂ (surj c)))) } ; forth-back = ≈-intro λ {x} {y} x≈y → S.trans B (S.sym B (proj₂ (surj x))) x≈y ; back-forth = ≈-intro λ {x} {y} x≈y → inj (S.trans B (S.sym B (proj₂ (surj _))) (resp f x≈y)) } Injective∧Surjective→≅ : {f : A ⇒ B} → IsInjective f → IsSurjective f → A ≅ B Injective∧Surjective→≅ {f} inj surj = IsIso→≅ f (Injective∧Surjective→Iso inj surj) Iso→Injective : {f : A ⇒ B} → IsIso f → IsInjective f Iso→Injective {f} i {a} {b} fa≈fb = begin⟨ A ⟩ a ≈⟨ S.sym A (≈-elim′ (back-forth i)) ⟩ arr (back i) (arr f a) ≈⟨ resp (back i) fa≈fb ⟩ arr (back i) (arr f b) ≈⟨ ≈-elim′ (back-forth i) ⟩ b ∎ ≅-Injective : (i : A ≅ B) → IsInjective (forth i) ≅-Injective i = Iso→Injective (≅→IsIso i) Iso→Surjective : {f : A ⇒ B} → IsIso f → IsSurjective f Iso→Surjective i b = arr (back i) b , S.sym B (≈-elim′ (forth-back i)) ≅-Surjective : (i : A ≅ B) → IsSurjective (forth i) ≅-Surjective i = Iso→Surjective (≅→IsIso i)
algebraic-stack_agda0000_doc_274
{- T R U N C A T I O N L E V E L S I N H O M O T O P Y T Y P E T H E O R Y ======= ELECTRONIC APPENDIX ======= NICOLAI KRAUS February 2015 -} {-# OPTIONS --without-K #-} module INDEX where -- Chapter 2 open import Preliminaries -- Parts of Chapter 2 are in a separate file: open import Pointed {- Chapter 3,4,5,6 are joint work with Martin Escardo, Thierry Coquand, Thorsten Altenkirch -} -- Chapter 3 open import Truncation_Level_Criteria -- Chapter 4 open import Anonymous_Existence_CollSplit open import Anonymous_Existence_Populatedness open import Anonymous_Existence_Comparison -- Chapter 5 open import Weakly_Constant_Functions -- Chapter 6 open import Judgmental_Computation {- Chapter 7 (joint work with Christian Sattler) has two parts. First, we construct homotopically complicated types; this development is distributed beween two files. Then, we discuss connectedness, which turns out to be very hard to formalise; we use in total five files to structure that discussion, see below. -} {- First, we have an auxiliary file which makes precise that the 'universe of n-types' behaves like an actual universe. We formalise operations for it; this is very useful as it allows a more 'principled' development. -} open import UniverseOfNTypes {- Now: Sections 1-4 of Chapter 7, where 1,2 are "hidden". They are special cases of the more general theorem that we prove in 7.4; the special cases are written out only for pedagogical reasons and are thus omitted in this formalisation. -} open import HHHUU-ComplicatedTypes {- Note that Chapter 7.5 is not formalised, even though it could have been; we omit it because it is only an alternative to the above formalisation, and actually leads to a weaker result than the one in 'HHHUU-ComplicatedTypes'. Chapter 7.6 is very hard to formalise (mostly done by Christian Sattler). Caveat: The order of the statements in the formalisation is different from the order in the thesis (it sometimes is more convenient to define multiple notions in the same module because they share argument to avoid replication of code, without them belonging together logically). First, we show (in a separate file) that the non-dependent universal property and the dependent universal property are equivalent. Contains: Definition 7.6.2, Lemma 7.6.6 -} open import Trunc.Universal -- Definition 7.6.4, Lemma 7.6.7, Corollary 7.6.8 open import Trunc.Basics -- Lemma 7.6.9, Lemma 7.6.10 -- (actually even a stronger version of Lemma 7.6.10) open import Trunc.TypeConstructors {- main part of connectedness: (link to 7.6.1,) Definition 7.6.13, Definition 7.6.11, Lemma 7.6.14, Lemma 7.6.12, Lemma 7.6.15 and Theorem 7.7.1 -} open import Trunc.Connection -- Remark 7.6.16 open import Trunc.ConnectednessAlt {- The main result of Chapter 8 is, unfortunately, meta-theoretical. It is plausible that in an implementation of a type theory with 'two levels' (one semi-internal 'strict' equality and the ordinary identity type), the complete Chapter 8 could be formalised; but at the moment, this is merely speculation. -} -- Chapter 9.2: Semi-Simplicial Types -- Proposition 9.2.1 (Δ₊ implemented with judgmental categorical laws) open import Deltaplus
algebraic-stack_agda0000_doc_275
{-# OPTIONS --verbose tc.constr.findInScope:20 #-} module InstanceArgumentsConstraints where data Bool : Set where true false : Bool postulate A1 A2 B C : Set a1 : A1 a2 : A2 someF : A1 → C record Class (R : Bool → Set) : Set where field f : (t : Bool) → R t open Class {{...}} class1 : Class (λ _ → A1) class1 = record { f = λ _ → a1 } class2 : Class (λ _ → A2) class2 = record { f = λ _ → a2 } test : C test = someF (f true)
algebraic-stack_agda0000_doc_276
{-# OPTIONS --cubical --safe #-} module Data.Bool where open import Level open import Agda.Builtin.Bool using (Bool; true; false) public open import Data.Unit open import Data.Empty bool : ∀ {ℓ} {P : Bool → Type ℓ} (f : P false) (t : P true) → (x : Bool) → P x bool f t false = f bool f t true = t not : Bool → Bool not false = true not true = false infixl 6 _or_ _or_ : Bool → Bool → Bool false or y = y true or y = true infixl 7 _and_ _and_ : Bool → Bool → Bool false and y = false true and y = y infixr 0 if_then_else_ if_then_else_ : ∀ {a} {A : Set a} → Bool → A → A → A if true then x else _ = x if false then _ else x = x T : Bool → Type₀ T true = ⊤ T false = ⊥
algebraic-stack_agda0000_doc_277
------------------------------------------------------------------------ -- Example: Left recursive expression grammar ------------------------------------------------------------------------ module TotalParserCombinators.Examples.Expression where open import Codata.Musical.Notation open import Data.Char as Char using (Char) open import Data.List open import Data.Nat open import Data.String as String using (String) open import Function open import Relation.Binary.PropositionalEquality as P using (_≡_) open import TotalParserCombinators.BreadthFirst open import TotalParserCombinators.Lib open import TotalParserCombinators.Parser open Token Char Char._≟_ ------------------------------------------------------------------------ -- An expression grammar -- t ∷= t '+' f ∣ f -- f ∷= f '*' a ∣ a -- a ∷= '(' t ')' ∣ n -- Applicative implementation of the grammar. module Applicative where mutual term = ♯ (return (λ e₁ _ e₂ → e₁ + e₂) ⊛ term) ⊛ tok '+' ⊛ factor ∣ factor factor = ♯ (return (λ e₁ _ e₂ → e₁ * e₂) ⊛ factor) ⊛ tok '*' ⊛ atom ∣ atom atom = return (λ _ e _ → e) ⊛ tok '(' ⊛ ♯ term ⊛ tok ')' ∣ number -- Monadic implementation of the grammar. module Monadic where mutual term = factor ∣ ♯ term >>= λ e₁ → tok '+' >>= λ _ → factor >>= λ e₂ → return (e₁ + e₂) factor = atom ∣ ♯ factor >>= λ e₁ → tok '*' >>= λ _ → atom >>= λ e₂ → return (e₁ * e₂) atom = number ∣ tok '(' >>= λ _ → ♯ term >>= λ e → tok ')' >>= λ _ → return e ------------------------------------------------------------------------ -- Unit tests module Tests where test : ∀ {R xs} → Parser Char R xs → String → List R test p = parse p ∘ String.toList -- Some examples have been commented out in order to reduce -- type-checking times. -- ex₁ : test Applicative.term "1*(2+3)" ≡ [ 5 ] -- ex₁ = P.refl -- ex₂ : test Applicative.term "1*(2+3" ≡ [] -- ex₂ = P.refl ex₃ : test Monadic.term "1+2+3" ≡ [ 6 ] ex₃ = P.refl ex₄ : test Monadic.term "+32" ≡ [] ex₄ = P.refl
algebraic-stack_agda0000_doc_278
module Tactic.Nat.Reflect where open import Prelude hiding (abs) open import Control.Monad.State open import Control.Monad.Transformer import Agda.Builtin.Nat as Builtin open import Builtin.Reflection open import Tactic.Reflection open import Tactic.Reflection.Quote open import Tactic.Reflection.Meta open import Tactic.Deriving.Quotable open import Tactic.Reflection.Equality open import Tactic.Nat.Exp R = StateT (Nat × List (Term × Nat)) TC fail : ∀ {A} → R A fail = lift (typeErrorS "reflection error") liftMaybe : ∀ {A} → Maybe A → R A liftMaybe = maybe fail pure runR : ∀ {A} → R A → TC (Maybe (A × List Term)) runR r = maybeA (second (reverse ∘ map fst ∘ snd) <$> runStateT r (0 , [])) pattern `Nat = def (quote Nat) [] infixr 1 _`->_ infix 4 _`≡_ pattern _`≡_ x y = def (quote _≡_) (_ ∷ hArg `Nat ∷ vArg x ∷ vArg y ∷ []) pattern _`->_ a b = pi (vArg a) (abs _ b) pattern _`+_ x y = def₂ (quote Builtin._+_) x y pattern _`*_ x y = def₂ (quote Builtin._*_) x y pattern `0 = con₀ (quote Nat.zero) pattern `suc n = con₁ (quote Nat.suc) n fresh : Term → R (Exp Var) fresh t = get >>= uncurry′ λ i Γ → var i <$ put (suc i , (t , i) ∷ Γ) ⟨suc⟩ : ∀ {X} → Exp X → Exp X ⟨suc⟩ (lit n) = lit (suc n) ⟨suc⟩ (lit n ⟨+⟩ e) = lit (suc n) ⟨+⟩ e ⟨suc⟩ e = lit 1 ⟨+⟩ e private forceInstance : Name → Term → R ⊤ forceInstance i v = lift $ unify v (def₀ i) forceSemiring = forceInstance (quote SemiringNat) forceNumber = forceInstance (quote NumberNat) termToExpR : Term → R (Exp Var) termToExpR (a `+ b) = ⦇ termToExpR a ⟨+⟩ termToExpR b ⦈ termToExpR (a `* b) = ⦇ termToExpR a ⟨*⟩ termToExpR b ⦈ termToExpR (def (quote Semiring._+_) (_ ∷ _ ∷ vArg i@(meta x _) ∷ vArg a ∷ vArg b ∷ [])) = do forceSemiring i ⦇ termToExpR a ⟨+⟩ termToExpR b ⦈ termToExpR (def (quote Semiring._*_) (_ ∷ _ ∷ vArg i@(meta x _) ∷ vArg a ∷ vArg b ∷ [])) = do lift $ unify i (def₀ (quote SemiringNat)) ⦇ termToExpR a ⟨*⟩ termToExpR b ⦈ termToExpR (def (quote Semiring.zro) (_ ∷ _ ∷ vArg i@(meta x _) ∷ [])) = do forceSemiring i pure (lit 0) termToExpR (def (quote Semiring.one) (_ ∷ _ ∷ vArg i@(meta x _) ∷ [])) = do forceSemiring i pure (lit 1) termToExpR (def (quote Number.fromNat) (_ ∷ _ ∷ vArg i@(meta x _) ∷ vArg a ∷ _ ∷ [])) = do forceNumber i termToExpR a termToExpR `0 = pure (lit 0) termToExpR (`suc a) = ⟨suc⟩ <$> termToExpR a termToExpR (lit (nat n)) = pure (lit n) termToExpR (meta x _) = lift (blockOnMeta x) termToExpR unknown = fail termToExpR t = do lift (ensureNoMetas t) just i ← gets (flip lookup t ∘ snd) where nothing → fresh t pure (var i) private lower : Nat → Term → R Term lower 0 = pure lower i = liftMaybe ∘ strengthen i termToEqR : Term → R (Exp Var × Exp Var) termToEqR (lhs `≡ rhs) = ⦇ termToExpR lhs , termToExpR rhs ⦈ termToEqR (def (quote _≡_) (_ ∷ hArg (meta x _) ∷ _)) = lift (blockOnMeta x) termToEqR (meta x _) = lift (blockOnMeta x) termToEqR _ = fail termToHypsR′ : Nat → Term → R (List (Exp Var × Exp Var)) termToHypsR′ i (hyp `-> a) = _∷_ <$> (termToEqR =<< lower i hyp) <*> termToHypsR′ (suc i) a termToHypsR′ _ (meta x _) = lift (blockOnMeta x) termToHypsR′ i a = [_] <$> (termToEqR =<< lower i a) termToHypsR : Term → R (List (Exp Var × Exp Var)) termToHypsR = termToHypsR′ 0 termToHyps : Term → TC (Maybe (List (Exp Var × Exp Var) × List Term)) termToHyps t = runR (termToHypsR t) termToEq : Term → TC (Maybe ((Exp Var × Exp Var) × List Term)) termToEq t = runR (termToEqR t) buildEnv : List Nat → Env Var buildEnv [] i = 0 buildEnv (x ∷ xs) zero = x buildEnv (x ∷ xs) (suc i) = buildEnv xs i defaultArg : Term → Arg Term defaultArg = arg (arg-info visible relevant) data ProofError {a} : Set a → Set (lsuc a) where bad-goal : ∀ g → ProofError g qProofError : Term → Term qProofError v = con (quote bad-goal) (defaultArg v ∷ []) implicitArg instanceArg : ∀ {A} → A → Arg A implicitArg = arg (arg-info hidden relevant) instanceArg = arg (arg-info instance′ relevant) unquoteDecl QuotableExp = deriveQuotable QuotableExp (quote Exp) stripImplicitArg : Arg Term → List (Arg Term) stripImplicitArgs : List (Arg Term) → List (Arg Term) stripImplicitAbsTerm : Abs Term → Abs Term stripImplicitArgTerm : Arg Term → Arg Term stripImplicit : Term → Term stripImplicit (var x args) = var x (stripImplicitArgs args) stripImplicit (con c args) = con c (stripImplicitArgs args) stripImplicit (def f args) = def f (stripImplicitArgs args) stripImplicit (meta x args) = meta x (stripImplicitArgs args) stripImplicit (lam v t) = lam v (stripImplicitAbsTerm t) stripImplicit (pi t₁ t₂) = pi (stripImplicitArgTerm t₁) (stripImplicitAbsTerm t₂) stripImplicit (agda-sort x) = agda-sort x stripImplicit (lit l) = lit l stripImplicit (pat-lam cs args) = pat-lam cs (stripImplicitArgs args) stripImplicit unknown = unknown stripImplicitAbsTerm (abs x v) = abs x (stripImplicit v) stripImplicitArgs [] = [] stripImplicitArgs (a ∷ as) = stripImplicitArg a ++ stripImplicitArgs as stripImplicitArgTerm (arg i x) = arg i (stripImplicit x) stripImplicitArg (arg (arg-info visible r) x) = arg (arg-info visible r) (stripImplicit x) ∷ [] stripImplicitArg (arg (arg-info hidden r) x) = [] stripImplicitArg (arg (arg-info instance′ r) x) = [] quotedEnv : List Term → Term quotedEnv ts = def (quote buildEnv) $ defaultArg (quoteList $ map stripImplicit ts) ∷ [] QED : ∀ {a} {A : Set a} {x : Maybe A} → Set QED {x = x} = IsJust x get-proof : ∀ {a} {A : Set a} (prf : Maybe A) → QED {x = prf} → A get-proof (just eq) _ = eq get-proof nothing () {-# STATIC get-proof #-} getProof : Name → Term → Term → Term getProof err t proof = def (quote get-proof) $ vArg proof ∷ vArg (def err $ vArg (stripImplicit t) ∷ []) ∷ [] failedProof : Name → Term → Term failedProof err t = def (quote get-proof) $ vArg (con (quote nothing) []) ∷ vArg (def err $ vArg (stripImplicit t) ∷ []) ∷ [] cantProve : Set → ⊤ cantProve _ = _ invalidGoal : Set → ⊤ invalidGoal _ = _
algebraic-stack_agda0000_doc_279
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Group.Algebra where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.HLevels open import Cubical.Foundations.Function using (_∘_) open import Cubical.Foundations.GroupoidLaws open import Cubical.Data.Sigma open import Cubical.Data.Unit open import Cubical.Algebra.Group.Base open import Cubical.Algebra.Group.Properties open import Cubical.Algebra.Group.Morphism open import Cubical.Algebra.Group.MorphismProperties open import Cubical.HITs.PropositionalTruncation hiding (map) -- open import Cubical.Data.Group.Base open Iso open Group open GroupHom private variable ℓ ℓ₁ ℓ₂ ℓ₃ : Level ------- elementary properties of morphisms -------- -- (- 0) = 0 -0≡0 : ∀ {ℓ} {G : Group {ℓ}} → (- G) (0g G) ≡ (0g G) -- - 0 ≡ 0 -0≡0 {G = G} = sym (IsGroup.lid (isGroup G) _) ∙ fst (IsGroup.inverse (isGroup G) _) -- ϕ(0) ≡ 0 morph0→0 : ∀ {ℓ ℓ'} (G : Group {ℓ}) (H : Group {ℓ'}) (f : GroupHom G H) → fun f (0g G) ≡ 0g H morph0→0 G H f = (fun f) (0g G) ≡⟨ sym (IsGroup.rid (isGroup H) _) ⟩ (f' (0g G) H.+ 0g H) ≡⟨ (λ i → f' (0g G) H.+ invr H (f' (0g G)) (~ i)) ⟩ (f' (0g G) H.+ (f' (0g G) H.+ (H.- f' (0g G)))) ≡⟨ (Group.assoc H (f' (0g G)) (f' (0g G)) (H.- (f' (0g G)))) ⟩ ((f' (0g G) H.+ f' (0g G)) H.+ (H.- f' (0g G))) ≡⟨ sym (cong (λ x → x H.+ (H.- f' (0g G))) (sym (cong f' (IsGroup.lid (isGroup G) _)) ∙ isHom f (0g G) (0g G))) ⟩ (f' (0g G)) H.+ (H.- (f' (0g G))) ≡⟨ invr H (f' (0g G)) ⟩ 0g H ∎ where module G = Group G module H = Group H f' = fun f -- ϕ(- x) = - ϕ(x) morphMinus : ∀ {ℓ ℓ'} (G : Group {ℓ}) (H : Group {ℓ'}) → (ϕ : GroupHom G H) → (g : ⟨ G ⟩) → fun ϕ ((- G) g) ≡ (- H) (fun ϕ g) morphMinus G H ϕ g = f (G.- g) ≡⟨ sym (IsGroup.rid (isGroup H) (f (G.- g))) ⟩ (f (G.- g) H.+ 0g H) ≡⟨ cong (f (G.- g) H.+_) (sym (invr H (f g))) ⟩ (f (G.- g) H.+ (f g H.+ (H.- f g))) ≡⟨ Group.assoc H (f (G.- g)) (f g) (H.- f g) ⟩ ((f (G.- g) H.+ f g) H.+ (H.- f g)) ≡⟨ cong (H._+ (H.- f g)) helper ⟩ (0g H H.+ (H.- f g)) ≡⟨ IsGroup.lid (isGroup H) (H.- (f g))⟩ H.- (f g) ∎ where module G = Group G module H = Group H f = fun ϕ helper : (f (G.- g) H.+ f g) ≡ 0g H helper = sym (isHom ϕ (G.- g) g) ∙∙ cong f (invl G g) ∙∙ morph0→0 G H ϕ -- ----------- Alternative notions of isomorphisms -------------- record GroupIso {ℓ ℓ'} (G : Group {ℓ}) (H : Group {ℓ'}) : Type (ℓ-max ℓ ℓ') where no-eta-equality constructor iso field map : GroupHom G H inv : ⟨ H ⟩ → ⟨ G ⟩ rightInv : section (GroupHom.fun map) inv leftInv : retract (GroupHom.fun map) inv record BijectionIso {ℓ ℓ'} (A : Group {ℓ}) (B : Group {ℓ'}) : Type (ℓ-max ℓ ℓ') where constructor bij-iso field map' : GroupHom A B inj : isInjective A B map' surj : isSurjective A B map' -- "Very" short exact sequences -- i.e. an exact sequence A → B → C → D where A and D are trivial record vSES {ℓ ℓ' ℓ'' ℓ'''} (A : Group {ℓ}) (B : Group {ℓ'}) (leftGr : Group {ℓ''}) (rightGr : Group {ℓ'''}) : Type (ℓ-suc (ℓ-max ℓ (ℓ-max ℓ' (ℓ-max ℓ'' ℓ''')))) where constructor ses field isTrivialLeft : isProp ⟨ leftGr ⟩ isTrivialRight : isProp ⟨ rightGr ⟩ left : GroupHom leftGr A right : GroupHom B rightGr ϕ : GroupHom A B Ker-ϕ⊂Im-left : (x : ⟨ A ⟩) → isInKer A B ϕ x → isInIm leftGr A left x Ker-right⊂Im-ϕ : (x : ⟨ B ⟩) → isInKer B rightGr right x → isInIm A B ϕ x open BijectionIso open GroupIso open vSES compGroupIso : {G : Group {ℓ}} {H : Group {ℓ₁}} {A : Group {ℓ₂}} → GroupIso G H → GroupIso H A → GroupIso G A map (compGroupIso iso1 iso2) = compGroupHom (map iso1) (map iso2) inv (compGroupIso iso1 iso2) = inv iso1 ∘ inv iso2 rightInv (compGroupIso iso1 iso2) a = cong (fun (map iso2)) (rightInv iso1 _) ∙ rightInv iso2 a leftInv (compGroupIso iso1 iso2) a = cong (inv iso1) (leftInv iso2 _) ∙ leftInv iso1 a isGroupHomInv' : {G : Group {ℓ}} {H : Group {ℓ₁}} (f : GroupIso G H) → isGroupHom H G (inv f) isGroupHomInv' {G = G} {H = H} f h h' = isInj-f _ _ ( f' (g (h ⋆² h')) ≡⟨ (rightInv f) _ ⟩ (h ⋆² h') ≡⟨ sym (cong₂ _⋆²_ (rightInv f h) (rightInv f h')) ⟩ (f' (g h) ⋆² f' (g h')) ≡⟨ sym (isHom (map f) _ _) ⟩ -- sym (isHom (hom f) _ _) ⟩ f' (g h ⋆¹ g h') ∎) where f' = fun (map f) _⋆¹_ = Group._+_ G _⋆²_ = Group._+_ H g = inv f -- invEq (eq f) isInj-f : (x y : ⟨ G ⟩) → f' x ≡ f' y → x ≡ y isInj-f x y p = sym (leftInv f _) ∙∙ cong g p ∙∙ leftInv f _ invGroupIso : {G : Group {ℓ}} {H : Group {ℓ₁}} → GroupIso G H → GroupIso H G fun (map (invGroupIso iso1)) = inv iso1 isHom (map (invGroupIso iso1)) = isGroupHomInv' iso1 inv (invGroupIso iso1) = fun (map iso1) rightInv (invGroupIso iso1) = leftInv iso1 leftInv (invGroupIso iso1) = rightInv iso1 dirProdGroupIso : {G : Group {ℓ}} {H : Group {ℓ₁}} {A : Group {ℓ₂}} {B : Group {ℓ₃}} → GroupIso G H → GroupIso A B → GroupIso (dirProd G A) (dirProd H B) fun (map (dirProdGroupIso iso1 iso2)) prod = fun (map iso1) (fst prod) , fun (map iso2) (snd prod) isHom (map (dirProdGroupIso iso1 iso2)) a b = ΣPathP (isHom (map iso1) (fst a) (fst b) , isHom (map iso2) (snd a) (snd b)) inv (dirProdGroupIso iso1 iso2) prod = (inv iso1) (fst prod) , (inv iso2) (snd prod) rightInv (dirProdGroupIso iso1 iso2) a = ΣPathP (rightInv iso1 (fst a) , (rightInv iso2 (snd a))) leftInv (dirProdGroupIso iso1 iso2) a = ΣPathP (leftInv iso1 (fst a) , (leftInv iso2 (snd a))) GrIsoToGrEquiv : {G : Group {ℓ}} {H : Group {ℓ₂}} → GroupIso G H → GroupEquiv G H GroupEquiv.eq (GrIsoToGrEquiv i) = isoToEquiv (iso (fun (map i)) (inv i) (rightInv i) (leftInv i)) GroupEquiv.isHom (GrIsoToGrEquiv i) = isHom (map i) --- Proofs that BijectionIso and vSES both induce isomorphisms --- BijectionIsoToGroupIso : {A : Group {ℓ}} {B : Group {ℓ₂}} → BijectionIso A B → GroupIso A B BijectionIsoToGroupIso {A = A} {B = B} i = grIso where module A = Group A module B = Group B f = fun (map' i) helper : (b : _) → isProp (Σ[ a ∈ ⟨ A ⟩ ] f a ≡ b) helper _ a b = Σ≡Prop (λ _ → isSetCarrier B _ _) (fst a ≡⟨ sym (IsGroup.rid (isGroup A) (fst a)) ⟩ ((fst a) A.+ 0g A) ≡⟨ cong ((fst a) A.+_) (sym (invl A (fst b))) ⟩ ((fst a) A.+ ((A.- fst b) A.+ fst b)) ≡⟨ Group.assoc A _ _ _ ⟩ (((fst a) A.+ (A.- fst b)) A.+ fst b) ≡⟨ cong (A._+ fst b) idHelper ⟩ (0g A A.+ fst b) ≡⟨ IsGroup.lid (isGroup A) (fst b) ⟩ fst b ∎) where idHelper : fst a A.+ (A.- fst b) ≡ 0g A idHelper = inj i _ (isHom (map' i) (fst a) (A.- (fst b)) ∙ (cong (f (fst a) B.+_) (morphMinus A B (map' i) (fst b)) ∙∙ cong (B._+ (B.- f (fst b))) (snd a ∙ sym (snd b)) ∙∙ invr B (f (fst b)))) grIso : GroupIso A B map grIso = map' i inv grIso b = (rec (helper b) (λ a → a) (surj i b)) .fst rightInv grIso b = (rec (helper b) (λ a → a) (surj i b)) .snd leftInv grIso b j = rec (helper (f b)) (λ a → a) (propTruncIsProp (surj i (f b)) ∣ b , refl ∣ j) .fst BijectionIsoToGroupEquiv : {A : Group {ℓ}} {B : Group {ℓ₂}} → BijectionIso A B → GroupEquiv A B BijectionIsoToGroupEquiv i = GrIsoToGrEquiv (BijectionIsoToGroupIso i) vSES→GroupIso : ∀ {ℓ ℓ' ℓ'' ℓ'''} {A : Group {ℓ}} {B : Group {ℓ'}} (leftGr : Group {ℓ''}) (rightGr : Group {ℓ'''}) → vSES A B leftGr rightGr → GroupIso A B vSES→GroupIso {A = A} lGr rGr vses = BijectionIsoToGroupIso theIso where theIso : BijectionIso _ _ map' theIso = vSES.ϕ vses inj theIso a inker = rec (isSetCarrier A _ _) (λ (a , p) → sym p ∙∙ cong (fun (left vses)) (isTrivialLeft vses a _) ∙∙ morph0→0 lGr A (left vses)) (Ker-ϕ⊂Im-left vses a inker) surj theIso a = Ker-right⊂Im-ϕ vses a (isTrivialRight vses _ _) vSES→GroupEquiv : {A : Group {ℓ}} {B : Group {ℓ₁}} (leftGr : Group {ℓ₂}) (rightGr : Group {ℓ₃}) → vSES A B leftGr rightGr → GroupEquiv A B vSES→GroupEquiv {A = A} lGr rGr vses = GrIsoToGrEquiv (vSES→GroupIso lGr rGr vses) -- The trivial group is a unit. lUnitGroupIso : ∀ {ℓ} {G : Group {ℓ}} → GroupEquiv (dirProd trivialGroup G) G lUnitGroupIso = GrIsoToGrEquiv (iso (grouphom snd (λ a b → refl)) (λ g → tt , g) (λ _ → refl) λ _ → refl) rUnitGroupIso : ∀ {ℓ} {G : Group {ℓ}} → GroupEquiv (dirProd G trivialGroup) G rUnitGroupIso = GrIsoToGrEquiv (iso (grouphom fst λ _ _ → refl) (λ g → g , tt) (λ _ → refl) λ _ → refl) contrGroup≅trivialGroup : {G : Group {ℓ}} → isContr ⟨ G ⟩ → GroupEquiv G trivialGroup GroupEquiv.eq (contrGroup≅trivialGroup contr) = isContr→≃Unit contr GroupEquiv.isHom (contrGroup≅trivialGroup contr) _ _ = refl
algebraic-stack_agda0000_doc_280
module Relations where -- Imports import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; cong) open import Data.Nat using (ℕ; zero; suc; _+_) open import Data.Nat.Properties using (+-comm) -- Defining relations data _≤_ : ℕ → ℕ → Set where z≤n : ∀ {n : ℕ} -------- → zero ≤ n s≤s : ∀ {m n : ℕ} → m ≤ n ------------- → suc m ≤ suc n _ : 2 ≤ 4 _ = s≤s (s≤s z≤n) -- Implicit arguments _ : 2 ≤ 4 _ = s≤s {1} {3} (s≤s {0} {2} (z≤n {2})) _ : 2 ≤ 4 _ = s≤s {m = 1} {n = 3} (s≤s {m = 0} {n = 2} (z≤n {n = 2})) _ : 2 ≤ 4 _ = s≤s {n = 3} (s≤s {n = 2} z≤n) -- Precedence infix 4 _≤_ -- Inversion inv-s≤s : ∀ {m n : ℕ} → suc m ≤ suc n ------------- → m ≤ n inv-s≤s (s≤s m≤n) = m≤n inv-z≤n : ∀ {m : ℕ} → m ≤ zero -------- → m ≡ zero inv-z≤n z≤n = refl -- Reflexivity (反射律) ≤-refl : ∀ {n : ℕ} ----- → n ≤ n ≤-refl {zero} = z≤n ≤-refl {suc n} = s≤s ≤-refl -- Transitivity (推移律) ≤-trans : ∀ {m n p : ℕ} → m ≤ n → n ≤ p ----- → m ≤ p ≤-trans z≤n _ = z≤n ≤-trans (s≤s m≤n) (s≤s n≤p) = s≤s (≤-trans m≤n n≤p) ≤-trans′ : ∀ (m n p : ℕ) → m ≤ n → n ≤ p ----- → m ≤ p ≤-trans′ zero _ _ z≤n _ = z≤n ≤-trans′ (suc m) (suc n) (suc p) (s≤s m≤n) (s≤s n≤p) = s≤s (≤-trans′ m n p m≤n n≤p) -- Anti-symmetry (非対称律) ≤-antisym : ∀ {m n : ℕ} → m ≤ n → n ≤ m ----- → m ≡ n ≤-antisym z≤n z≤n = refl ≤-antisym (s≤s m≤n) (s≤s n≤m) = cong suc (≤-antisym m≤n n≤m) -- Total (全順序) data Total (m n : ℕ) : Set where forward : m ≤ n --------- → Total m n flipped : n ≤ m --------- → Total m n data Total′ : ℕ → ℕ → Set where forward′ : ∀ {m n : ℕ} → m ≤ n ---------- → Total′ m n flipped′ : ∀ {m n : ℕ} → n ≤ m ---------- → Total′ m n ≤-total : ∀ (m n : ℕ) → Total m n ≤-total zero n = forward z≤n ≤-total (suc m) zero = flipped z≤n ≤-total (suc m) (suc n) with ≤-total m n ... | forward m≤n = forward (s≤s m≤n) ... | flipped n≤m = flipped (s≤s n≤m) ≤-total′ : ∀ (m n : ℕ) → Total m n ≤-total′ zero n = forward z≤n ≤-total′ (suc m) zero = flipped z≤n ≤-total′ (suc m) (suc n) = helper (≤-total′ m n) where helper : Total m n → Total (suc m) (suc n) helper (forward m≤n) = forward (s≤s m≤n) helper (flipped n≤m) = flipped (s≤s n≤m) ≤-total″ : ∀ (m n : ℕ) → Total m n ≤-total″ m zero = flipped z≤n ≤-total″ zero (suc n) = forward z≤n ≤-total″ (suc m) (suc n) with ≤-total″ m n ... | forward m≤n = forward (s≤s m≤n) ... | flipped n≤m = flipped (s≤s n≤m) -- Monotonicity (単調性) +-monoʳ-≤ : ∀ (n p q : ℕ) → p ≤ q ------------- → n + p ≤ n + q +-monoʳ-≤ zero p q p≤q = p≤q +-monoʳ-≤ (suc n) p q p≤q = s≤s (+-monoʳ-≤ n p q p≤q) +-monoˡ-≤ : ∀ (m n p : ℕ) → m ≤ n ------------- → m + p ≤ n + p +-monoˡ-≤ m n p m≤n rewrite +-comm m p | +-comm n p = +-monoʳ-≤ p m n m≤n +-mono-≤ : ∀ (m n p q : ℕ) → m ≤ n → p ≤ q ------------- → m + p ≤ n + q +-mono-≤ m n p q m≤n p≤q = ≤-trans (+-monoˡ-≤ m n p m≤n) (+-monoʳ-≤ n p q p≤q) -- Strict inequality infix 4 _<_ data _<_ : ℕ → ℕ → Set where z<s : ∀ {n : ℕ} ------------ → zero < suc n s<s : ∀ {m n : ℕ} → m < n ------------- → suc m < suc n -- Even and odd data even : ℕ → Set data odd : ℕ → Set data even where zero : --------- even zero suc : ∀ {n : ℕ} → odd n ------------ → even (suc n) data odd where suc : ∀ {n : ℕ} → even n ----------- → odd (suc n) e+e≡e : ∀ {m n : ℕ} → even m → even n ------------ → even (m + n) o+e≡o : ∀ {m n : ℕ} → odd m → even n ----------- → odd (m + n) e+e≡e zero en = en e+e≡e (suc om) en = suc (o+e≡o om en) o+e≡o (suc em) en = suc (e+e≡e em en)
algebraic-stack_agda0000_doc_281
module Data.Nat.Instance where open import Agda.Builtin.Nat open import Class.Equality open import Class.Monoid open import Class.Show open import Data.Char open import Data.List open import Data.Nat renaming (_≟_ to _≟ℕ_; _+_ to _+ℕ_) open import Data.String open import Function private postulate primShowNat : ℕ -> List Char {-# COMPILE GHC primShowNat = show #-} showNat : ℕ -> String showNat = fromList ∘ primShowNat instance Eq-ℕ : Eq ℕ Eq-ℕ = record { _≟_ = _≟ℕ_ } EqB-ℕ : EqB ℕ EqB-ℕ = record { _≣_ = Agda.Builtin.Nat._==_ } ℕ-Monoid : Monoid ℕ ℕ-Monoid = record { mzero = zero ; _+_ = _+ℕ_ } Show-ℕ : Show ℕ Show-ℕ = record { show = showNat }
algebraic-stack_agda0000_doc_282
open import Data.Product using ( _×_ ; _,_ ; swap ) open import Data.Sum using ( inj₁ ; inj₂ ) open import Relation.Nullary using ( ¬_ ; yes ; no ) open import Relation.Unary using ( _∈_ ) open import Web.Semantic.DL.ABox using ( ABox ; ε ; _,_ ; _∼_ ; _∈₁_ ; _∈₂_ ) open import Web.Semantic.DL.ABox.Interp using ( Interp ; ⌊_⌋ ; ind ; ind⁻¹ ; Surjective ; surj✓ ) open import Web.Semantic.DL.ABox.Interp.Morphism using ( _≲_ ; _≃_ ; _,_ ; ≲⌊_⌋ ; ≲-resp-ind ) open import Web.Semantic.DL.ABox.Interp.Meet using ( meet ; meet-lb ; meet-glb ; meet-uniq ; meet-surj ) open import Web.Semantic.DL.ABox.Model using ( _⊨a_ ) open import Web.Semantic.DL.Concept using ( Concept ; ⟨_⟩ ; ¬⟨_⟩ ; ⊤ ; ⊥ ; _⊔_ ; _⊓_ ; ∀[_]_ ; ∃⟨_⟩_ ; ≤1 ; >1 ; neg ) open import Web.Semantic.DL.Concept.Model using ( _⟦_⟧₁ ; neg-sound ; neg-complete ) open import Web.Semantic.DL.Integrity.Closed using ( Mediated₀ ; Initial₀ ; sur_⊨₀_ ; _,_ ) open import Web.Semantic.DL.Integrity.Closed.Alternate using ( _⊫_∼_ ; _⊫_∈₁_ ; _⊫_∈₂_ ; _⊫t_ ; _⊫a_ ; _⊫k_ ; eq ; rel ; rev ; +atom ; -atom ; top ; inj₁ ; inj₂ ; all ; ex ; uniq ; ¬uniq ; cn ; rl ; dis ; ref ; irr ; tra ; ε ; _,_ ) open import Web.Semantic.DL.KB using ( KB ; tbox ; abox ) open import Web.Semantic.DL.KB.Model using ( _⊨_ ; Interps ; ⊨-resp-≃ ) open import Web.Semantic.DL.Role using ( Role ; ⟨_⟩ ; ⟨_⟩⁻¹ ) open import Web.Semantic.DL.Role.Model using ( _⟦_⟧₂ ) open import Web.Semantic.DL.Signature using ( Signature ) open import Web.Semantic.DL.TBox using ( TBox ; ε ; _,_ ; _⊑₁_ ; _⊑₂_ ; Dis ; Ref ; Irr ; Tra ) open import Web.Semantic.DL.TBox.Interp using ( _⊨_≈_ ; ≈-sym ; ≈-trans ) open import Web.Semantic.DL.TBox.Interp.Morphism using ( ≲-resp-≈ ; iso ) open import Web.Semantic.DL.TBox.Model using ( _⊨t_ ) open import Web.Semantic.Util using ( ExclMiddle ; ExclMiddle₁ ; smaller-excl-middle ; is! ; is✓ ; tt ; elim ) module Web.Semantic.DL.Integrity.Closed.Properties (excl-middle₁ : ExclMiddle₁) {Σ : Signature} {X : Set} where -- The two definitions of closed-world integrity coincide for surjective interpretations. -- Note that this requires excluded middle, as the alternate definition assumes a classical logic, -- for example interpreting C ⊑ D as (¬ C ⊔ D) being a tautology. min : KB Σ X → Interp Σ X min K = meet excl-middle₁ (Interps K) excl-middle : ExclMiddle excl-middle = smaller-excl-middle excl-middle₁ sound∼ : ∀ K x y → (K ⊫ x ∼ y) → (⌊ min K ⌋ ⊨ x ≈ y) sound∼ K x y (eq K⊫x∼y) = is! K⊫x∼y complete∼ : ∀ K x y → (⌊ min K ⌋ ⊨ x ≈ y) → (K ⊫ x ∼ y) complete∼ K x y x≈y = eq (is✓ x≈y) sound₂ : ∀ K R xy → (K ⊫ xy ∈₂ R) → (xy ∈ ⌊ min K ⌋ ⟦ R ⟧₂) sound₂ K ⟨ r ⟩ (x , y) (rel K⊫xy∈r) = is! K⊫xy∈r sound₂ K ⟨ r ⟩⁻¹ (x , y) (rev K⊫yx∈r) = is! K⊫yx∈r complete₂ : ∀ K R xy → (xy ∈ ⌊ min K ⌋ ⟦ R ⟧₂) → (K ⊫ xy ∈₂ R) complete₂ K ⟨ r ⟩ (x , y) xy∈⟦r⟧ = rel (is✓ xy∈⟦r⟧) complete₂ K ⟨ r ⟩⁻¹ (x , y) yx∈⟦r⟧ = rev (is✓ yx∈⟦r⟧) sound₁ : ∀ K C x → (K ⊫ x ∈₁ C) → (x ∈ ⌊ min K ⌋ ⟦ C ⟧₁) sound₁ K ⟨ c ⟩ x (+atom K⊨x∈c) = is! K⊨x∈c sound₁ K ¬⟨ c ⟩ x (-atom K⊭x∈c) = λ x∈⟦c⟧ → K⊭x∈c (is✓ x∈⟦c⟧) sound₁ K ⊤ x top = tt sound₁ K ⊥ x () sound₁ K (C ⊓ D) x (K⊫x∈C , K⊫x∈D) = (sound₁ K C x K⊫x∈C , sound₁ K D x K⊫x∈D) sound₁ K (C ⊔ D) x (inj₁ K⊫x∈C) = inj₁ (sound₁ K C x K⊫x∈C) sound₁ K (C ⊔ D) x (inj₂ K⊫x∈D) = inj₂ (sound₁ K D x K⊫x∈D) sound₁ K (∀[ R ] C) x (all K⊫x∈∀RC) = λ y xy∈⟦R⟧ → sound₁ K C y (K⊫x∈∀RC y (complete₂ K R _ xy∈⟦R⟧)) sound₁ K (∃⟨ R ⟩ C) x (ex y K⊫xy∈R K⊫y∈C) = (y , sound₂ K R _ K⊫xy∈R , sound₁ K C y K⊫y∈C) sound₁ K (≤1 R) x (uniq K⊫x∈≤1R) = λ y z xy∈⟦R⟧ xz∈⟦R⟧ → sound∼ K y z (K⊫x∈≤1R y z (complete₂ K R _ xy∈⟦R⟧) (complete₂ K R _ xz∈⟦R⟧)) sound₁ K (>1 R) x (¬uniq y z K⊫xy∈R K⊫xz∈R K⊯y∼z) = ( y , z , sound₂ K R _ K⊫xy∈R , sound₂ K R _ K⊫xz∈R , λ y≈z → K⊯y∼z (complete∼ K y z y≈z) ) complete₁ : ∀ K C x → (x ∈ ⌊ min K ⌋ ⟦ C ⟧₁) → (K ⊫ x ∈₁ C) complete₁ K ⟨ c ⟩ x x∈⟦c⟧ = +atom (is✓ x∈⟦c⟧) complete₁ K ¬⟨ c ⟩ x x∉⟦c⟧ = -atom (λ K⊫x∈c → x∉⟦c⟧ (is! K⊫x∈c)) complete₁ K ⊤ x x∈⟦C⟧ = top complete₁ K ⊥ x () complete₁ K (C ⊓ D) x (x∈⟦C⟧ , x∈⟦D⟧) = (complete₁ K C x x∈⟦C⟧ , complete₁ K D x x∈⟦D⟧) complete₁ K (C ⊔ D) x (inj₁ x∈⟦C⟧) = inj₁ (complete₁ K C x x∈⟦C⟧) complete₁ K (C ⊔ D) x (inj₂ x∈⟦D⟧) = inj₂ (complete₁ K D x x∈⟦D⟧) complete₁ K (∀[ R ] C) x x∈⟦∀RC⟧ = all (λ y K⊫xy∈R → complete₁ K C y (x∈⟦∀RC⟧ y (sound₂ K R _ K⊫xy∈R))) complete₁ K (∃⟨ R ⟩ C) x (y , xy∈⟦R⟧ , y∈⟦C⟧) = ex y (complete₂ K R (x , y) xy∈⟦R⟧) (complete₁ K C y y∈⟦C⟧) complete₁ K (≤1 R) x x∈⟦≤1R⟧ = uniq (λ y z K⊫xy∈R K⊫xz∈R → complete∼ K y z (x∈⟦≤1R⟧ y z (sound₂ K R _ K⊫xy∈R) (sound₂ K R _ K⊫xz∈R))) complete₁ K (>1 R) x (y , z , xy∈⟦R⟧ , xz∈⟦R⟧ , y≉z) = ¬uniq y z (complete₂ K R _ xy∈⟦R⟧) (complete₂ K R _ xz∈⟦R⟧) (λ K⊫y∼z → y≉z (sound∼ K y z K⊫y∼z)) ⊫-impl-min⊨ : ∀ K L → (K ⊫k L) → (min K ⊨ L) ⊫-impl-min⊨ K L (K⊫T , K⊫A) = ( J⊨T K⊫T , J⊨A K⊫A ) where J : Interp Σ X J = min K J⊨T : ∀ {T} → (K ⊫t T) → (⌊ J ⌋ ⊨t T) J⊨T ε = tt J⊨T (K⊫T , K⊫U) = (J⊨T K⊫T , J⊨T K⊫U) J⊨T (rl Q R K⊫Q⊑R) = λ {xy} xy∈⟦Q⟧ → sound₂ K R xy (K⊫Q⊑R xy (complete₂ K Q xy xy∈⟦Q⟧)) J⊨T (cn C D K⊫C⊑D) = λ {x} → lemma x (K⊫C⊑D x) where lemma : ∀ x → (K ⊫ x ∈₁ (neg C ⊔ D)) → (x ∈ ⌊ J ⌋ ⟦ C ⟧₁) → (x ∈ ⌊ J ⌋ ⟦ D ⟧₁) lemma x (inj₁ K⊫x∈¬C) x∈⟦C⟧ = elim (neg-sound ⌊ J ⌋ {x} C (sound₁ K (neg C) x K⊫x∈¬C) x∈⟦C⟧) lemma x (inj₂ K⊫x∈D) x∈⟦C⟧ = sound₁ K D x K⊫x∈D J⊨T (dis Q R K⊫DisQR) = λ {xy} xy∈⟦Q⟧ xy∈⟦R⟧ → K⊫DisQR xy (complete₂ K Q xy xy∈⟦Q⟧) (complete₂ K R xy xy∈⟦R⟧) J⊨T (ref R K⊫RefR) = λ x → sound₂ K R (x , x) (K⊫RefR x) J⊨T (irr R K⊫IrrR) = λ x xx∈⟦R⟧ → K⊫IrrR x (complete₂ K R (x , x) xx∈⟦R⟧) J⊨T (tra R K⊫TraR) = λ {x} {y} {z} xy∈⟦R⟧ yz∈⟦R⟧ → sound₂ K R (x , z) (K⊫TraR x y z (complete₂ K R (x , y) xy∈⟦R⟧) (complete₂ K R (y , z) yz∈⟦R⟧)) J⊨A : ∀ {A} → (K ⊫a A) → (J ⊨a A) J⊨A ε = tt J⊨A (K⊫A , K⊫B) = (J⊨A K⊫A , J⊨A K⊫B) J⊨A (eq x y K⊫x∼y) = sound∼ K x y K⊫x∼y J⊨A (rl (x , y) r K⊫xy∈r) = sound₂ K ⟨ r ⟩ (x , y) K⊫xy∈r J⊨A (cn x c K⊫x∈c) = sound₁ K ⟨ c ⟩ x K⊫x∈c min⊨-impl-⊫ : ∀ K L → (min K ⊨ L) → (K ⊫k L) min⊨-impl-⊫ K L (J⊨T , J⊨A) = ( K⊫T (tbox L) J⊨T , K⊫A (abox L) J⊨A ) where J : Interp Σ X J = min K K⊫T : ∀ T → (⌊ J ⌋ ⊨t T) → (K ⊫t T) K⊫T ε J⊨ε = ε K⊫T (T , U) (J⊨T , J⊨U) = (K⊫T T J⊨T , K⊫T U J⊨U) K⊫T (Q ⊑₂ R) J⊨Q⊑R = rl Q R (λ xy K⊫xy∈Q → complete₂ K R xy (J⊨Q⊑R (sound₂ K Q xy K⊫xy∈Q))) K⊫T (C ⊑₁ D) J⊨C⊑D = cn C D lemma where lemma : ∀ x → (K ⊫ x ∈₁ neg C ⊔ D) lemma x with excl-middle (x ∈ ⌊ J ⌋ ⟦ C ⟧₁) lemma x | yes x∈⟦C⟧ = inj₂ (complete₁ K D x (J⊨C⊑D x∈⟦C⟧)) lemma x | no x∉⟦C⟧ = inj₁ (complete₁ K (neg C) x (neg-complete excl-middle ⌊ J ⌋ C x∉⟦C⟧)) K⊫T (Dis Q R) J⊨DisQR = dis Q R (λ xy K⊫xy∈Q K⊫xy∈R → J⊨DisQR (sound₂ K Q xy K⊫xy∈Q) (sound₂ K R xy K⊫xy∈R)) K⊫T (Ref R) J⊨RefR = ref R (λ x → complete₂ K R (x , x) (J⊨RefR x)) K⊫T (Irr R) J⊨IrrR = irr R (λ x K⊫xx∈R → J⊨IrrR x (sound₂ K R (x , x) K⊫xx∈R)) K⊫T (Tra R) J⊨TrR = tra R (λ x y z K⊫xy∈R K⊫yz∈R → complete₂ K R (x , z) (J⊨TrR (sound₂ K R (x , y) K⊫xy∈R) (sound₂ K R (y , z) K⊫yz∈R))) K⊫A : ∀ A → (J ⊨a A) → (K ⊫a A) K⊫A ε J⊨ε = ε K⊫A (A , B) (J⊨A , J⊨B) = (K⊫A A J⊨A , K⊫A B J⊨B) K⊫A (x ∼ y) x≈y = eq x y (complete∼ K x y x≈y) K⊫A (x ∈₁ c) x∈⟦c⟧ = cn x c (complete₁ K ⟨ c ⟩ x x∈⟦c⟧) K⊫A ((x , y) ∈₂ r) xy∈⟦r⟧ = rl (x , y) r (complete₂ K ⟨ r ⟩ (x , y) xy∈⟦r⟧) min-med : ∀ (K : KB Σ X) J → (J ⊨ K) → Mediated₀ (min K) J min-med K J J⊨K = (meet-lb excl-middle₁ (Interps K) J J⊨K , meet-uniq excl-middle₁ (Interps K) J J⊨K) min-init : ∀ (K : KB Σ X) → (K ⊫k K) → (min K ∈ Initial₀ K) min-init K K⊫K = ( ⊫-impl-min⊨ K K K⊫K , min-med K) min-uniq : ∀ (I : Interp Σ X) (K : KB Σ X) → (I ∈ Surjective) → (I ∈ Initial₀ K) → (I ≃ min K) min-uniq I K I∈Surj (I⊨K , I-med) = ( iso ≲⌊ meet-glb excl-middle₁ (Interps K) I I∈Surj lemma₁ ⌋ ≲⌊ meet-lb excl-middle₁ (Interps K) I I⊨K ⌋ (λ x → ≈-sym ⌊ I ⌋ (surj✓ I∈Surj x)) (λ x → is! (lemma₂ x)) , λ x → is! (lemma₂ x)) where lemma₁ : ∀ J J⊨K → I ≲ J lemma₁ J J⊨K with I-med J J⊨K lemma₁ J J⊨K | (I≲J , I≲J-uniq) = I≲J lemma₂ : ∀ x J J⊨K → ⌊ J ⌋ ⊨ ind J (ind⁻¹ I∈Surj (ind I x)) ≈ ind J x lemma₂ x J J⊨K = ≈-trans ⌊ J ⌋ (≈-sym ⌊ J ⌋ (≲-resp-ind (lemma₁ J J⊨K) (ind⁻¹ I∈Surj (ind I x)))) (≈-trans ⌊ J ⌋ (≲-resp-≈ ≲⌊ lemma₁ J J⊨K ⌋ (≈-sym ⌊ I ⌋ (surj✓ I∈Surj (ind I x)))) (≲-resp-ind (lemma₁ J J⊨K) x)) ⊫-impl-⊨₀ : ∀ (KB₁ KB₂ : KB Σ X) → (KB₁ ⊫k KB₁) → (KB₁ ⊫k KB₂) → (sur KB₁ ⊨₀ KB₂) ⊫-impl-⊨₀ KB₁ KB₂ KB₁⊫KB₁ KB₁⊫KB₂ = ( min KB₁ , meet-surj excl-middle₁ (Interps KB₁) , min-init KB₁ KB₁⊫KB₁ , ⊫-impl-min⊨ KB₁ KB₂ KB₁⊫KB₂ ) ⊨₀-impl-⊫₁ : ∀ (KB₁ KB₂ : KB Σ X) → (sur KB₁ ⊨₀ KB₂) → (KB₁ ⊫k KB₁) ⊨₀-impl-⊫₁ KB₁ KB₂ (I , I∈Surj , (I⊨KB₁ , I-med) , I⊨KB₂) = min⊨-impl-⊫ KB₁ KB₁ (⊨-resp-≃ (min-uniq I KB₁ I∈Surj (I⊨KB₁ , I-med)) KB₁ I⊨KB₁) ⊨₀-impl-⊫₂ : ∀ (KB₁ KB₂ : KB Σ X) → (sur KB₁ ⊨₀ KB₂) → (KB₁ ⊫k KB₂) ⊨₀-impl-⊫₂ KB₁ KB₂ (I , I∈Surj , I-init , I⊨KB₂) = min⊨-impl-⊫ KB₁ KB₂ (⊨-resp-≃ (min-uniq I KB₁ I∈Surj I-init) KB₂ I⊨KB₂)
algebraic-stack_agda0000_doc_283
{-# OPTIONS --without-K --safe #-} module Fragment.Examples.CSemigroup.Types where
algebraic-stack_agda0000_doc_284
-- This document shows how to encode GADTs using `IFix`. {-# OPTIONS --type-in-type #-} module ScottVec where -- The kind of church-encoded type-level natural numbers. Nat = (Set -> Set) -> Set -> Set zero : Nat zero = λ f z -> z suc : Nat -> Nat suc = λ n f z -> f (n f z) plus : Nat -> Nat -> Nat plus = λ n m f z -> n f (m f z) -- Our old friend. {-# NO_POSITIVITY_CHECK #-} record IFix {I : Set} (F : (I -> Set) -> I -> Set) (i : I) : Set where constructor wrap field unwrap : F (IFix F) i open IFix -- Scott-encoded vectors (a vector is a list with statically-known length). -- As usually the pattern vector of a Scott-encoded data type encodes pattern-matching. VecF : Set -> (Nat -> Set) -> Nat -> Set VecF = λ A Rec n -> (R : Nat -> Set) -- The type of the result depends on the vector's length. -> (∀ p -> A -> Rec p -> R (suc p)) -- The encoded `cons` constructor. -> R zero -- The encoded `nil` constructor. -> R n Vec : Set -> Nat -> Set Vec = λ (A : Set) -> IFix (VecF A) nil : ∀ A -> Vec A zero nil = λ A -> wrap λ R f z -> z cons : ∀ A n -> A -> Vec A n -> Vec A (suc n) cons = λ A n x xs -> wrap λ R f z -> f n x xs open import Data.Empty open import Data.Unit.Base open import Data.Nat.Base using (ℕ; _+_) -- Type-safe `head`. head : ∀ A n -> Vec A (suc n) -> A head A n xs = unwrap xs (λ p -> p (λ _ -> A) ⊤) -- `p (λ _ -> A) ⊤` returns `A` when `p` is `suc p'` for some `p'` -- and `⊤` when `p` is `zero` (λ p x xs' -> x) -- In the `cons` case `suc p (λ _ -> A) ⊤` reduces to `A`, -- hence we return the list element of type `A`. tt -- In the `nil` case `zero (λ _ -> A) ⊤` reduces to `⊤`, -- hence we return the only value of that type. {- Note [Type-safe `tail`] It's not obvious if type-safe `tail` can be implemented with this setup. This is because even though `Vec` is Scott-encoded, the type-level natural are Church-encoded (obviously we could have Scott-encoded type-level naturals in Agda just as well, but not in Zerepoch Core), which makes `pred` hard, which makes `tail` non-trivial. I did try using Scott-encoded naturals in Agda, that makes `tail` even more straightforward than `head`: tail : ∀ A n -> Vec A (suc n) -> Vec A n tail A n xs = unwrap xs (λ p -> ((B : ℕ -> Set) -> B (pred p) -> B n) -> Vec A n) (λ p x xs' coe -> coe (Vec A) xs') (λ coe -> coe (Vec A) (nil A)) (λ B x -> x) -} -- Here we pattern-match on `xs` and if it's non-empty, i.e. of type `Vec ℕ (suc p)` for some `p`, -- then we also get access to a coercion function that allows us to coerce the second list from -- `Vec ℕ n` to the same `Vec ℕ (suc p)` and call the type-safe `head` over it. -- Note that we don't even need to encode the `n ~ suc p` and `n ~ zero` equality constraints in -- the definition of `vecF` and can recover coercions along those constraints by adding the -- `Vec ℕ n -> Vec ℕ p` argument to the motive. sumHeadsOr0 : ∀ n -> Vec ℕ n -> Vec ℕ n -> ℕ sumHeadsOr0 n xs ys = unwrap xs (λ p -> (Vec ℕ n -> Vec ℕ p) -> ℕ) (λ p i _ coe -> i + head ℕ p (coe ys)) (λ _ -> 0) (λ x -> x)
algebraic-stack_agda0000_doc_285
module EqTest where import Common.Level open import Common.Maybe open import Common.Equality data ℕ : Set where zero : ℕ suc : ℕ -> ℕ _≟_ : (x y : ℕ) -> Maybe (x ≡ y) suc m ≟ suc n with m ≟ n suc .n ≟ suc n | just refl = just refl suc m ≟ suc n | nothing = nothing zero ≟ suc _ = nothing suc m ≟ zero = nothing zero ≟ zero = just refl
algebraic-stack_agda0000_doc_286
-- Andreas, 2012-09-26 disable projection-likeness for recursive functions -- {-# OPTIONS -v tc.proj.like:100 #-} module ProjectionLikeRecursive where open import Common.Prelude open import Common.Equality if_then_else_ : {A : Set} → Bool → A → A → A if true then t else e = t if false then t else e = e infixr 5 _∷_ _∷′_ data Vec (n : Nat) : Set where [] : {p : n ≡ 0} → Vec n _∷_ : {m : Nat}{p : n ≡ suc m} → Nat → Vec m → Vec n null : {n : Nat} → Vec n → Bool null [] = true null xs = false -- last is considered projection-like last : (n : Nat) → Vec n → Nat -- last 0 xs = zero --restoring this line removes proj.-likeness and passes the file last n [] = zero last n (x ∷ xs) = if (null xs) then x else last _ xs -- breaks if projection-like translation is not removing the _ in the rec. call []′ : Vec zero []′ = [] {p = refl} _∷′_ : {n : Nat} → Nat → Vec n → Vec (suc n) x ∷′ xs = _∷_ {p = refl} x xs three = last 3 (1 ∷′ 2 ∷′ 3 ∷′ []′) test : three ≡ 3 test = refl -- Error: Incomplete pattern matching -- when checking that the expression refl has type three ≡ 3
algebraic-stack_agda0000_doc_287
module HasNegation where record HasNegation (A : Set) : Set where field ~ : A → A open HasNegation ⦃ … ⦄ public {-# DISPLAY HasNegation.~ _ = ~ #-}
algebraic-stack_agda0000_doc_6112
module _ where open import Common.Prelude open import Common.Equality primitive primForce : ∀ {a b} {A : Set a} {B : A → Set b} (x : A) → (∀ x → B x) → B x primForceLemma : ∀ {a b} {A : Set a} {B : A → Set b} (x : A) (f : ∀ x → B x) → primForce x f ≡ f x force = primForce forceLemma = primForceLemma seq : ∀ {a b} {A : Set a} {B : Set b} → A → B → B seq x y = force x λ _ → y foo : (a b : Nat) → seq a b ≡ b foo zero _ = refl foo (suc n) _ = refl seqLit : (n : Nat) → seq "literal" n ≡ n seqLit n = refl seqType : (n : Nat) → seq Nat n ≡ n seqType n = refl seqPi : {A B : Set} {n : Nat} → seq (A → B) n ≡ n seqPi = refl seqLam : {n : Nat} → seq (λ (x : Nat) → x) n ≡ n seqLam = refl seqLemma : (a b : Nat) → seq a b ≡ b seqLemma a b = forceLemma a _ evalLemma : (n : Nat) → seqLemma (suc n) n ≡ refl evalLemma n = refl infixr 0 _$!_ _$!_ : ∀ {a b} {A : Set a} {B : A → Set b} → (∀ x → B x) → ∀ x → B x f $! x = force x f -- Without seq, this would be exponential -- pow2 : Nat → Nat → Nat pow2 zero acc = acc pow2 (suc n) acc = pow2 n $! acc + acc lem : pow2 32 1 ≡ 4294967296 lem = refl
algebraic-stack_agda0000_doc_6113
{-# OPTIONS --cubical --no-import-sorts --safe #-} open import Cubical.Core.Everything open import Cubical.Foundations.HLevels module Cubical.Algebra.Semigroup.Construct.Right {ℓ} (Aˢ : hSet ℓ) where open import Cubical.Foundations.Prelude open import Cubical.Algebra.Semigroup import Cubical.Algebra.Magma.Construct.Right Aˢ as RMagma open RMagma public hiding (Right-isMagma; RightMagma) private A = ⟨ Aˢ ⟩ isSetA = Aˢ .snd ▸-assoc : Associative _▸_ ▸-assoc _ _ _ = refl Right-isSemigroup : IsSemigroup A _▸_ Right-isSemigroup = record { isMagma = RMagma.Right-isMagma ; assoc = ▸-assoc } RightSemigroup : Semigroup ℓ RightSemigroup = record { isSemigroup = Right-isSemigroup }
algebraic-stack_agda0000_doc_6114
module _ where abstract data Nat : Set where Zero : Nat Succ : Nat → Nat countDown : Nat → Nat countDown x with x ... | Zero = Zero ... | Succ n = countDown n
algebraic-stack_agda0000_doc_6115
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics open import lib.types.Sigma open import lib.types.Group open import lib.types.CommutingSquare open import lib.groups.Homomorphism open import lib.groups.Isomorphism module lib.groups.CommutingSquare where -- A new type to keep the parameters. record CommSquareᴳ {i₀ i₁ j₀ j₁} {G₀ : Group i₀} {G₁ : Group i₁} {H₀ : Group j₀} {H₁ : Group j₁} (φ₀ : G₀ →ᴳ H₀) (φ₁ : G₁ →ᴳ H₁) (ξG : G₀ →ᴳ G₁) (ξH : H₀ →ᴳ H₁) : Type (lmax (lmax i₀ i₁) (lmax j₀ j₁)) where constructor comm-sqrᴳ field commutesᴳ : ∀ g₀ → GroupHom.f (ξH ∘ᴳ φ₀) g₀ == GroupHom.f (φ₁ ∘ᴳ ξG) g₀ infixr 0 _□$ᴳ_ _□$ᴳ_ = CommSquareᴳ.commutesᴳ is-csᴳ-equiv : ∀ {i₀ i₁ j₀ j₁} {G₀ : Group i₀} {G₁ : Group i₁} {H₀ : Group j₀} {H₁ : Group j₁} {φ₀ : G₀ →ᴳ H₀} {φ₁ : G₁ →ᴳ H₁} {ξG : G₀ →ᴳ G₁} {ξH : H₀ →ᴳ H₁} → CommSquareᴳ φ₀ φ₁ ξG ξH → Type (lmax (lmax i₀ i₁) (lmax j₀ j₁)) is-csᴳ-equiv {ξG = ξG} {ξH} _ = is-equiv (GroupHom.f ξG) × is-equiv (GroupHom.f ξH) CommSquareEquivᴳ : ∀ {i₀ i₁ j₀ j₁} {G₀ : Group i₀} {G₁ : Group i₁} {H₀ : Group j₀} {H₁ : Group j₁} (φ₀ : G₀ →ᴳ H₀) (φ₁ : G₁ →ᴳ H₁) (ξG : G₀ →ᴳ G₁) (ξH : H₀ →ᴳ H₁) → Type (lmax (lmax i₀ i₁) (lmax j₀ j₁)) CommSquareEquivᴳ φ₀ φ₁ ξG ξH = Σ (CommSquareᴳ φ₀ φ₁ ξG ξH) is-csᴳ-equiv abstract CommSquareᴳ-∘v : ∀ {i₀ i₁ i₂ j₀ j₁ j₂} {G₀ : Group i₀} {G₁ : Group i₁} {G₂ : Group i₂} {H₀ : Group j₀} {H₁ : Group j₁} {H₂ : Group j₂} {φ : G₀ →ᴳ H₀} {ψ : G₁ →ᴳ H₁} {χ : G₂ →ᴳ H₂} {ξG : G₀ →ᴳ G₁} {ξH : H₀ →ᴳ H₁} {μA : G₁ →ᴳ G₂} {μB : H₁ →ᴳ H₂} → CommSquareᴳ ψ χ μA μB → CommSquareᴳ φ ψ ξG ξH → CommSquareᴳ φ χ (μA ∘ᴳ ξG) (μB ∘ᴳ ξH) CommSquareᴳ-∘v {ξG = ξG} {μB = μB} (comm-sqrᴳ □₁₂) (comm-sqrᴳ □₀₁) = comm-sqrᴳ λ g₀ → ap (GroupHom.f μB) (□₀₁ g₀) ∙ □₁₂ (GroupHom.f ξG g₀) CommSquareEquivᴳ-inverse-v : ∀ {i₀ i₁ j₀ j₁} {G₀ : Group i₀} {G₁ : Group i₁} {H₀ : Group j₀} {H₁ : Group j₁} {φ₀ : G₀ →ᴳ H₀} {φ₁ : G₁ →ᴳ H₁} {ξG : G₀ →ᴳ G₁} {ξH : H₀ →ᴳ H₁} → (cse : CommSquareEquivᴳ φ₀ φ₁ ξG ξH) → CommSquareEquivᴳ φ₁ φ₀ (GroupIso.g-hom (ξG , fst (snd cse))) (GroupIso.g-hom (ξH , snd (snd cse))) CommSquareEquivᴳ-inverse-v (comm-sqrᴳ cs , ise) with CommSquareEquiv-inverse-v (comm-sqr cs , ise) ... | (comm-sqr cs' , ise') = cs'' , ise' where abstract cs'' = comm-sqrᴳ cs' CommSquareᴳ-inverse-v : ∀ {i₀ i₁ j₀ j₁} {G₀ : Group i₀} {G₁ : Group i₁} {H₀ : Group j₀} {H₁ : Group j₁} {φ₀ : G₀ →ᴳ H₀} {φ₁ : G₁ →ᴳ H₁} {ξG : G₀ →ᴳ G₁} {ξH : H₀ →ᴳ H₁} → CommSquareᴳ φ₀ φ₁ ξG ξH → (ξG-ise : is-equiv (GroupHom.f ξG)) (ξH-ise : is-equiv (GroupHom.f ξH)) → CommSquareᴳ φ₁ φ₀ (GroupIso.g-hom (ξG , ξG-ise)) (GroupIso.g-hom (ξH , ξH-ise)) CommSquareᴳ-inverse-v cs ξG-ise ξH-ise = fst (CommSquareEquivᴳ-inverse-v (cs , ξG-ise , ξH-ise)) -- basic facts nicely represented in commuting squares inv-hom-natural-comm-sqr : ∀ {i j} (G : AbGroup i) (H : AbGroup j) (φ : AbGroup.grp G →ᴳ AbGroup.grp H) → CommSquareᴳ φ φ (inv-hom G) (inv-hom H) inv-hom-natural-comm-sqr _ _ φ = comm-sqrᴳ λ g → ! (GroupHom.pres-inv φ g)
algebraic-stack_agda0000_doc_6116
-- this is effectively a CM make file. it just includes all the files that -- exist in the directory in the right order so that one can check that -- everything compiles cleanly and has no unfilled holes -- data structures open import List open import Nat open import Prelude -- basic stuff: core definitions, etc open import core open import checks open import judgemental-erase open import judgemental-inconsistency open import moveerase open import examples open import structural -- first wave theorems open import sensibility open import aasubsume-min open import determinism -- second wave theorems (checksums) open import reachability open import constructability
algebraic-stack_agda0000_doc_6117
module consoleExamples.passwordCheckSimple where open import ConsoleLib open import Data.Bool.Base open import Data.Bool open import Data.String renaming (_==_ to _==str_) open import SizedIO.Base main : ConsoleProg main = run (GetLine >>= λ s → if s ==str "passwd" then WriteString "Success" else WriteString "Error")
algebraic-stack_agda0000_doc_6118
{-# OPTIONS --cubical --safe #-} module Cubical.Data.Universe where open import Cubical.Data.Universe.Base public open import Cubical.Data.Universe.Properties public
algebraic-stack_agda0000_doc_6119
{-# OPTIONS --without-K --safe #-} open import Categories.Bicategory using (Bicategory) -- A Pseudofunctor is a homomorphism of Bicategories -- Follow Bénabou's definition, which is basically that of a Functor -- Note that what is in nLab is an "exploded" version of the simpler version below module Categories.Pseudofunctor where open import Level open import Data.Product using (_,_) import Categories.Category as Category open Category.Category using (Obj; module Commutation) open Category using (Category; _[_,_]) open import Categories.Functor using (Functor; _∘F_) renaming (id to idF) open import Categories.Category.Product using (_⁂_) open import Categories.NaturalTransformation using (NaturalTransformation) open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism; _≃_) open import Categories.Category.Instance.One using (shift) open NaturalIsomorphism using (F⇒G; F⇐G) record Pseudofunctor {o ℓ e t o′ ℓ′ e′ t′ : Level} (C : Bicategory o ℓ e t) (D : Bicategory o′ ℓ′ e′ t′) : Set (o ⊔ ℓ ⊔ e ⊔ t ⊔ o′ ⊔ ℓ′ ⊔ e′ ⊔ t′) where private module C = Bicategory C module D = Bicategory D field P₀ : C.Obj → D.Obj P₁ : {x y : C.Obj} → Functor (C.hom x y) (D.hom (P₀ x) (P₀ y)) -- For maximal generality, shift the levels of One. P preserves id P-identity : {A : C.Obj} → D.id {P₀ A} ∘F shift o′ ℓ′ e′ ≃ P₁ ∘F (C.id {A}) -- P preserves composition P-homomorphism : {x y z : C.Obj} → D.⊚ ∘F (P₁ ⁂ P₁) ≃ P₁ ∘F C.⊚ {x} {y} {z} -- P preserves ≃ module unitˡ {A} = NaturalTransformation (F⇒G (P-identity {A})) module unitʳ {A} = NaturalTransformation (F⇐G (P-identity {A})) module Hom {x} {y} {z} = NaturalTransformation (F⇒G (P-homomorphism {x} {y} {z})) -- For notational convenience, shorten some functor applications private F₀ = λ {x y} X → Functor.F₀ (P₁ {x} {y}) X field unitaryˡ : {x y : C.Obj} → let open Commutation (D.hom (P₀ x) (P₀ y)) in {f : Obj (C.hom x y)} → [ D.id₁ D.⊚₀ (F₀ f) ⇒ F₀ f ]⟨ unitˡ.η _ D.⊚₁ D.id₂ ⇒⟨ F₀ C.id₁ D.⊚₀ F₀ f ⟩ Hom.η ( C.id₁ , f) ⇒⟨ F₀ (C.id₁ C.⊚₀ f) ⟩ Functor.F₁ P₁ C.unitorˡ.from ≈ D.unitorˡ.from ⟩ unitaryʳ : {x y : C.Obj} → let open Commutation (D.hom (P₀ x) (P₀ y)) in {f : Obj (C.hom x y)} → [ (F₀ f) D.⊚₀ D.id₁ ⇒ F₀ f ]⟨ D.id₂ D.⊚₁ unitˡ.η _ ⇒⟨ F₀ f D.⊚₀ F₀ C.id₁ ⟩ Hom.η ( f , C.id₁ ) ⇒⟨ F₀ (f C.⊚₀ C.id₁) ⟩ Functor.F₁ P₁ (C.unitorʳ.from) ≈ D.unitorʳ.from ⟩ assoc : {x y z w : C.Obj} → let open Commutation (D.hom (P₀ x) (P₀ w)) in {f : Obj (C.hom x y)} {g : Obj (C.hom y z)} {h : Obj (C.hom z w)} → [ (F₀ h D.⊚₀ F₀ g) D.⊚₀ F₀ f ⇒ F₀ (h C.⊚₀ (g C.⊚₀ f)) ]⟨ Hom.η (h , g) D.⊚₁ D.id₂ ⇒⟨ F₀ (h C.⊚₀ g) D.⊚₀ F₀ f ⟩ Hom.η (_ , f) ⇒⟨ F₀ ((h C.⊚₀ g) C.⊚₀ f) ⟩ Functor.F₁ P₁ C.associator.from ≈ D.associator.from ⇒⟨ F₀ h D.⊚₀ (F₀ g D.⊚₀ F₀ f) ⟩ D.id₂ D.⊚₁ Hom.η (g , f) ⇒⟨ F₀ h D.⊚₀ F₀ (g C.⊚₀ f) ⟩ Hom.η (h , _) ⟩
algebraic-stack_agda0000_doc_6120
module Tactic.Reflection.Replace where open import Prelude open import Container.Traversable open import Tactic.Reflection open import Tactic.Reflection.Equality {-# TERMINATING #-} _r[_/_] : Term → Term → Term → Term p r[ r / l ] = ifYes p == l then r else case p of λ { (var x args) → var x $ args r₂[ r / l ] ; (con c args) → con c $ args r₂[ r / l ] ; (def f args) → def f $ args r₂[ r / l ] ; (lam v t) → lam v $ t r₁[ weaken 1 r / weaken 1 l ] -- lam v <$> t r₁[ weaken 1 r / weaken 1 l ] ; (pat-lam cs args) → let w = length args in pat-lam (replaceClause (weaken w l) (weaken w r) <$> cs) $ args r₂[ r / l ] ; (pi a b) → pi (a r₁[ r / l ]) (b r₁[ weaken 1 r / weaken 1 l ]) ; (agda-sort s) → agda-sort $ replaceSort l r s ; (lit l) → lit l ; (meta x args) → meta x $ args r₂[ r / l ] ; unknown → unknown } where replaceClause : Term → Term → Clause → Clause replaceClause l r (clause pats x) = clause pats $ x r[ r / l ] replaceClause l r (absurd-clause pats) = absurd-clause pats replaceSort : Term → Term → Sort → Sort replaceSort l r (set t) = set $ t r[ r / l ] replaceSort l r (lit n) = lit n replaceSort l r unknown = unknown _r₁[_/_] : {T₀ : Set → Set} {{_ : Traversable T₀}} → T₀ Term → Term → Term → T₀ Term p r₁[ r / l ] = _r[ r / l ] <$> p _r₂[_/_] : {T₀ T₁ : Set → Set} {{_ : Traversable T₀}} {{_ : Traversable T₁}} → T₁ (T₀ Term) → Term → Term → T₁ (T₀ Term) p r₂[ r / l ] = fmap _r[ r / l ] <$> p _R[_/_] : List (Arg Type) → Type → Type → List (Arg Type) Γ R[ L / R ] = go Γ (strengthen 1 L) (strengthen 1 R) where go : List (Arg Type) → Maybe Term → Maybe Term → List (Arg Type) go (γ ∷ Γ) (just L) (just R) = (caseF γ of _r[ L / R ]) ∷ go Γ (strengthen 1 L) (strengthen 1 R) go Γ _ _ = Γ
algebraic-stack_agda0000_doc_6121
module Numeral.Natural.Relation.Order.Decidable where open import Functional open import Logic.IntroInstances open import Logic.Propositional.Theorems open import Numeral.Natural open import Numeral.Natural.Oper.Comparisons open import Numeral.Natural.Oper.Proofs open import Numeral.Natural.Relation.Order open import Numeral.Natural.Relation.Order.Proofs open import Relator.Equals open import Relator.Equals.Proofs open import Structure.Function.Domain open import Type.Properties.Decidable instance [≡]-decider : Decider(2)(_≡_)(_≡?_) [≡]-decider {𝟎} {𝟎} = true [≡]-intro [≡]-decider {𝟎} {𝐒 y} = false \() [≡]-decider {𝐒 x}{𝟎} = false \() [≡]-decider {𝐒 x}{𝐒 y} = step{f = id} (true ∘ [≡]-with(𝐒)) (false ∘ contrapositiveᵣ (injective(𝐒))) ([≡]-decider {x}{y}) instance [≤]-decider : Decider(2)(_≤_)(_≤?_) [≤]-decider {𝟎} {𝟎} = true [≤]-minimum [≤]-decider {𝟎} {𝐒 y} = true [≤]-minimum [≤]-decider {𝐒 x} {𝟎} = false \() [≤]-decider {𝐒 x} {𝐒 y} = step{f = id} (true ∘ \p → [≤]-with-[𝐒] ⦃ p ⦄) (false ∘ contrapositiveᵣ [≤]-without-[𝐒]) ([≤]-decider {x}{y}) [<]-decider : Decider(2)(_<_)(_<?_) [<]-decider {𝟎} {𝟎} = false (λ ()) [<]-decider {𝟎} {𝐒 y} = true (succ min) [<]-decider {𝐒 x} {𝟎} = false (λ ()) [<]-decider {𝐒 x} {𝐒 y} = step{f = id} (true ∘ succ) (false ∘ contrapositiveᵣ [≤]-without-[𝐒]) ([<]-decider {x} {y})
algebraic-stack_agda0000_doc_6122
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order open import Numbers.Naturals.Order.WellFounded open import Numbers.Naturals.Order.Lemmas open import Numbers.Integers.Definition open import Numbers.Integers.Integers open import Numbers.Integers.Order open import Groups.Groups open import Groups.Definition open import Rings.Definition open import Rings.Orders.Partial.Definition open import Rings.Orders.Total.Definition open import Fields.Fields open import Numbers.Primes.PrimeNumbers open import Setoids.Setoids open import Functions.Definition open import Sets.EquivalenceRelations open import Numbers.Rationals.Definition open import Semirings.Definition open import Orders.Total.Definition open import Orders.WellFounded.Induction open import Setoids.Orders.Total.Definition module Numbers.Rationals.Lemmas where open import Semirings.Lemmas ℕSemiring open PartiallyOrderedRing ℤPOrderedRing open import Rings.Orders.Total.Lemmas ℤOrderedRing open import Rings.Orders.Total.AbsoluteValue ℤOrderedRing open SetoidTotalOrder (totalOrderToSetoidTotalOrder ℤOrder) evenOrOdd : (a : ℕ) → (Sg ℕ (λ i → i *N 2 ≡ a)) || (Sg ℕ (λ i → succ (i *N 2) ≡ a)) evenOrOdd zero = inl (zero , refl) evenOrOdd (succ zero) = inr (zero , refl) evenOrOdd (succ (succ a)) with evenOrOdd a evenOrOdd (succ (succ a)) | inl (a/2 , even) = inl (succ a/2 , applyEquality (λ i → succ (succ i)) even) evenOrOdd (succ (succ a)) | inr (a/2-1 , odd) = inr (succ a/2-1 , applyEquality (λ i → succ (succ i)) odd) parity : (a b : ℕ) → succ (2 *N a) ≡ 2 *N b → False parity zero (succ b) pr rewrite Semiring.commutative ℕSemiring b (succ (b +N 0)) = bad pr where bad : (1 ≡ succ (succ ((b +N 0) +N b))) → False bad () parity (succ a) (succ b) pr rewrite Semiring.commutative ℕSemiring b (succ (b +N 0)) | Semiring.commutative ℕSemiring a (succ (a +N 0)) | Semiring.commutative ℕSemiring (a +N 0) a | Semiring.commutative ℕSemiring (b +N 0) b = parity a b (succInjective (succInjective pr)) sqrt0 : (p : ℕ) → p *N p ≡ 0 → p ≡ 0 sqrt0 zero pr = refl sqrt0 (succ p) () -- So as to give us something easy to induct down, introduce a silly extra variable evil' : (k : ℕ) → ((a b : ℕ) → (0 <N a) → (pr : k ≡ a +N b) → a *N a ≡ (b *N b) *N 2 → False) evil' = rec <NWellfounded (λ z → (x x₁ : ℕ) (pr' : 0 <N x) (x₂ : z ≡ x +N x₁) (x₃ : x *N x ≡ (x₁ *N x₁) *N 2) → False) go where go : (k : ℕ) (indHyp : (k' : ℕ) (k'<k : k' <N k) (r s : ℕ) (0<r : 0 <N r) (r+s : k' ≡ r +N s) (x₇ : r *N r ≡ (s *N s) *N 2) → False) (a b : ℕ) (0<a : 0 <N a) (a+b : k ≡ a +N b) (pr : a *N a ≡ (b *N b) *N 2) → False go k indHyp a b 0<a a+b pr = contr where open import Semirings.Solver ℕSemiring multiplicationNIsCommutative aEven : Sg ℕ (λ i → i *N 2 ≡ a) aEven with evenOrOdd a aEven | inl x = x aEven | inr (a/2-1 , odd) rewrite equalityCommutative odd = -- Derive a pretty mechanical contradiction using the automatic solver. -- This line looks hellish, but it was almost completely mechanical. exFalso (parity (a/2-1 +N (a/2-1 *N succ (a/2-1 *N 2))) (b *N b) (transitivity ( -- truly mechanical bit starts here from (succ (plus (plus (const a/2-1) (times (const a/2-1) (succ (times (const a/2-1) (succ (succ zero)))))) (plus (plus (const a/2-1) (times (const a/2-1) (succ (times (const a/2-1) (succ (succ zero)))))) (times zero (plus (const a/2-1) (times (const a/2-1) (succ (times (const a/2-1) (succ (succ zero)))))))))) to succ (plus (times (const a/2-1) (succ (succ zero))) (times (times (const a/2-1) (succ (succ zero))) (succ (times (const a/2-1) (succ (succ zero)))))) -- truly mechanical bit ends here by applyEquality (λ i → succ (a/2-1 +N i)) ( -- Grinding out some manipulations transitivity (equalityCommutative (Semiring.+Associative ℕSemiring a/2-1 _ _)) (applyEquality (a/2-1 +N_) (transitivity (Semiring.commutative ℕSemiring (a/2-1 *N (a/2-1 +N a/2-1)) _) (transitivity (equalityCommutative (Semiring.+Associative ℕSemiring a/2-1 _ _)) (applyEquality (a/2-1 +N_) (transitivity (equalityCommutative (Semiring.+Associative ℕSemiring a/2-1 _ _)) (applyEquality (a/2-1 +N_) (transitivity (equalityCommutative (Semiring.+DistributesOver* ℕSemiring a/2-1 _ _)) (applyEquality (a/2-1 *N_) (equalityCommutative (Semiring.+Associative ℕSemiring a/2-1 _ _)))))))))) )) (transitivity pr (multiplicationNIsCommutative (b *N b) 2)))) next : (underlying aEven *N 2) *N (underlying aEven *N 2) ≡ (b *N b) *N 2 next with aEven ... | a/2 , even rewrite even = pr next2 : (underlying aEven *N 2) *N underlying aEven ≡ b *N b next2 = productCancelsRight 2 _ _ (le 1 refl) (transitivity (equalityCommutative (Semiring.*Associative ℕSemiring (underlying aEven *N 2) _ _)) next) next3 : b *N b ≡ (underlying aEven *N underlying aEven) *N 2 next3 = equalityCommutative (transitivity (transitivity (equalityCommutative (Semiring.*Associative ℕSemiring (underlying aEven) _ _)) (multiplicationNIsCommutative (underlying aEven) _)) next2) halveDecreased : underlying aEven <N a halveDecreased with aEven halveDecreased | zero , even rewrite equalityCommutative even = exFalso (TotalOrder.irreflexive ℕTotalOrder 0<a) halveDecreased | succ a/2 , even = le a/2 (transitivity (applyEquality succ (transitivity (Semiring.commutative ℕSemiring a/2 _) (applyEquality succ (transitivity (doubleIsAddTwo a/2) (multiplicationNIsCommutative 2 a/2))))) even) reduced : b +N underlying aEven <N k reduced with lessRespectsAddition b halveDecreased ... | bl rewrite a+b = identityOfIndiscernablesLeft _<N_ bl (Semiring.commutative ℕSemiring _ b) 0<b : 0 <N b 0<b with TotalOrder.totality ℕTotalOrder 0 b 0<b | inl (inl 0<b) = 0<b 0<b | inl (inr ()) 0<b | inr 0=b rewrite equalityCommutative 0=b = exFalso (TotalOrder.irreflexive ℕTotalOrder {0} (identityOfIndiscernablesRight _<N_ 0<a (sqrt0 a pr))) contr : False contr = indHyp (b +N underlying aEven) reduced b (underlying aEven) 0<b refl next3 evil : (a b : ℕ) → (0 <N a) → a *N a ≡ (b *N b) *N 2 → False evil a b 0<a = evil' (a +N b) a b 0<a refl absNonneg : (x : ℕ) → abs (nonneg x) ≡ nonneg x absNonneg x with totality (nonneg 0) (nonneg x) absNonneg x | inl (inl 0<x) = refl absNonneg x | inr 0=x = refl absNegsucc : (x : ℕ) → abs (negSucc x) ≡ nonneg (succ x) absNegsucc x with totality (nonneg 0) (negSucc x) absNegsucc x | inl (inr _) = refl toNats : (numerator denominator : ℤ) → .(denominator ≡ nonneg 0 → False) → (abs numerator) *Z (abs numerator) ≡ ((abs denominator) *Z (abs denominator)) *Z nonneg 2 → Sg (ℕ && ℕ) (λ nats → ((_&&_.fst nats *N _&&_.fst nats) ≡ (_&&_.snd nats *N _&&_.snd nats) *N 2) && (_&&_.snd nats ≡ 0 → False)) toNats (nonneg num) (nonneg 0) pr _ = exFalso (pr refl) toNats (nonneg num) (nonneg (succ denom)) _ pr = (num ,, (succ denom)) , (nonnegInjective (transitivity (transitivity (equalityCommutative (absNonneg (num *N num))) (absRespectsTimes (nonneg num) (nonneg num))) pr) ,, λ ()) toNats (nonneg num) (negSucc denom) _ pr = (num ,, succ denom) , (nonnegInjective (transitivity (transitivity (equalityCommutative (absNonneg (num *N num))) (absRespectsTimes (nonneg num) (nonneg num))) pr) ,, λ ()) toNats (negSucc num) (nonneg (succ denom)) _ pr = (succ num ,, succ denom) , (nonnegInjective pr ,, λ ()) toNats (negSucc num) (negSucc denom) _ pr = (succ num ,, succ denom) , (nonnegInjective pr ,, λ ()) sqrt2Irrational : (a : ℚ) → (a *Q a) =Q (injectionQ (nonneg 2)) → False sqrt2Irrational (record { num = numerator ; denom = denominator ; denomNonzero = denom!=0 }) pr = bad where -- We have in hand `pr`, which is the following (almost by definition): pr' : (numerator *Z numerator) ≡ (denominator *Z denominator) *Z nonneg 2 pr' = transitivity (equalityCommutative (transitivity (Ring.*Commutative ℤRing) (Ring.identIsIdent ℤRing))) pr -- Move into the naturals so that we can do nice divisibility things. lemma1 : abs ((denominator *Z denominator) *Z nonneg 2) ≡ (abs denominator *Z abs denominator) *Z nonneg 2 lemma1 = transitivity (absRespectsTimes (denominator *Z denominator) (nonneg 2)) (applyEquality (_*Z nonneg 2) (absRespectsTimes denominator denominator)) amenableToNaturals : (abs numerator) *Z (abs numerator) ≡ ((abs denominator) *Z (abs denominator)) *Z nonneg 2 amenableToNaturals = transitivity (equalityCommutative (absRespectsTimes numerator numerator)) (transitivity (applyEquality abs pr') lemma1) naturalsStatement : Sg (ℕ && ℕ) (λ nats → ((_&&_.fst nats *N _&&_.fst nats) ≡ (_&&_.snd nats *N _&&_.snd nats) *N 2) && (_&&_.snd nats ≡ 0 → False)) naturalsStatement = toNats numerator denominator denom!=0 amenableToNaturals bad : False bad with naturalsStatement bad | (num ,, 0) , (pr1 ,, pr2) = exFalso (pr2 refl) bad | (num ,, succ denom) , (pr1 ,, pr2) = evil num (succ denom) 0<num pr1 where 0<num : 0 <N num 0<num with TotalOrder.totality ℕTotalOrder 0 num 0<num | inl (inl 0<num) = 0<num 0<num | inr 0=num rewrite equalityCommutative 0=num = exFalso (naughtE pr1)
algebraic-stack_agda0000_doc_6123
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.DStructures.Equivalences.PeifferGraphS2G where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Function open import Cubical.Foundations.Structure open import Cubical.Functions.FunExtEquiv open import Cubical.Homotopy.Base open import Cubical.Data.Sigma open import Cubical.Data.Unit open import Cubical.Relation.Binary open import Cubical.Structures.Subtype open import Cubical.Algebra.Group open import Cubical.Structures.LeftAction open import Cubical.Algebra.Group.Semidirect open import Cubical.DStructures.Base open import Cubical.DStructures.Meta.Properties open import Cubical.DStructures.Meta.Isomorphism open import Cubical.DStructures.Structures.Constant open import Cubical.DStructures.Structures.Type open import Cubical.DStructures.Structures.Group open import Cubical.DStructures.Structures.Action open import Cubical.DStructures.Structures.XModule open import Cubical.DStructures.Structures.ReflGraph open import Cubical.DStructures.Structures.VertComp open import Cubical.DStructures.Structures.PeifferGraph open import Cubical.DStructures.Structures.Strict2Group open import Cubical.DStructures.Equivalences.GroupSplitEpiAction open import Cubical.DStructures.Equivalences.PreXModReflGraph private variable ℓ ℓ' ℓ'' ℓ₁ ℓ₁' ℓ₁'' ℓ₂ ℓA ℓA' ℓ≅A ℓ≅A' ℓB ℓB' ℓ≅B ℓC ℓ≅C ℓ≅ᴰ ℓ≅ᴰ' ℓ≅B' : Level open Kernel open GroupHom -- such .fun! open GroupLemmas open MorphismLemmas open ActionLemmas module _ (ℓ ℓ' : Level) where ℓℓ' = ℓ-max ℓ ℓ' 𝒮ᴰ-♭PIso-PeifferGraph-Strict2Group : 𝒮ᴰ-♭PIso (idfun (ReflGraph ℓ ℓℓ')) (𝒮ᴰ-ReflGraph\Peiffer ℓ ℓℓ') (𝒮ᴰ-Strict2Group ℓ ℓℓ') RelIso.fun (𝒮ᴰ-♭PIso-PeifferGraph-Strict2Group 𝒢) isPeifferGraph = 𝒱 where open ReflGraphNotation 𝒢 open ReflGraphLemmas 𝒢 open VertComp _⊙_ = λ (g f : ⟨ G₁ ⟩) → (g -₁ (𝒾s g)) +₁ f 𝒱 : VertComp 𝒢 vcomp 𝒱 g f _ = g ⊙ f σ-∘ 𝒱 g f c = r where isg = 𝒾s g abstract r = s ((g -₁ isg) +₁ f) ≡⟨ (σ .isHom (g -₁ isg) f) ⟩ s (g -₁ isg) +₀ s f ≡⟨ cong (_+₀ s f) (σ-g--isg g) ⟩ 0₀ +₀ s f ≡⟨ lId₀ (s f) ⟩ s f ∎ τ-∘ 𝒱 g f c = r where isg = 𝒾s g -isg = -₁ (𝒾s g) abstract r = t ((g -₁ isg) +₁ f) ≡⟨ τ .isHom (g -₁ isg) f ⟩ t (g -₁ isg) +₀ t f ≡⟨ cong (_+₀ t f) (τ .isHom g (-₁ isg)) ⟩ (t g +₀ t -isg) +₀ t f ≡⟨ cong ((t g +₀ t -isg) +₀_) (sym c) ⟩ (t g +₀ t -isg) +₀ s g ≡⟨ cong (λ z → (t g +₀ z) +₀ s g) (mapInv τ isg) ⟩ (t g -₀ (t isg)) +₀ s g ≡⟨ cong (λ z → (t g -₀ z) +₀ s g) (τι-≡-fun (s g)) ⟩ (t g -₀ (s g)) +₀ s g ≡⟨ (sym (assoc₀ (t g) (-₀ s g) (s g))) ∙ (cong (t g +₀_) (lCancel₀ (s g))) ⟩ t g +₀ 0₀ ≡⟨ rId₀ (t g) ⟩ t g ∎ isHom-∘ 𝒱 g f c-gf g' f' _ _ = r where isg = 𝒾s g -isg = -₁ (𝒾s g) isg' = 𝒾s g' -isg' = -₁ (𝒾s g') itf = 𝒾t f -itf = -₁ (𝒾t f) abstract r = (g +₁ g') ⊙ (f +₁ f') ≡⟨ assoc₁ ((g +₁ g') -₁ 𝒾s (g +₁ g')) f f' ⟩ (((g +₁ g') -₁ 𝒾s (g +₁ g')) +₁ f) +₁ f' ≡⟨ cong (λ z → (z +₁ f) +₁ f') (sym (assoc₁ g g' (-₁ (𝒾s (g +₁ g'))))) ⟩ ((g +₁ (g' -₁ (𝒾s (g +₁ g')))) +₁ f) +₁ f' ≡⟨ cong (_+₁ f') (sym (assoc₁ g (g' -₁ (𝒾s (g +₁ g'))) f)) ⟩ (g +₁ ((g' -₁ (𝒾s (g +₁ g'))) +₁ f)) +₁ f' ≡⟨ cong (λ z → (g +₁ z) +₁ f') ((g' -₁ (𝒾s (g +₁ g'))) +₁ f ≡⟨ cong (λ z → (g' -₁ z) +₁ f) (ι∘σ .isHom g g') ⟩ (g' -₁ (isg +₁ isg')) +₁ f ≡⟨ cong (λ z → (g' +₁ z) +₁ f) (invDistr G₁ isg isg') ⟩ (g' +₁ (-isg' +₁ -isg)) +₁ f ≡⟨ assoc-c--r- G₁ g' -isg' -isg f ⟩ g' +₁ (-isg' +₁ (-isg +₁ f)) ≡⟨ cong (λ z → g' +₁ (-isg' +₁ ((-₁ (𝒾 z)) +₁ f))) c-gf ⟩ g' +₁ (-isg' +₁ (-itf +₁ f)) ≡⟨ isPeifferGraph4 𝒢 isPeifferGraph f g' ⟩ -itf +₁ (f +₁ (g' +₁ -isg')) ≡⟨ cong (λ z → (-₁ (𝒾 z)) +₁ (f +₁ (g' +₁ -isg'))) (sym c-gf) ⟩ -isg +₁ (f +₁ (g' +₁ -isg')) ∎) ⟩ (g +₁ (-isg +₁ (f +₁ (g' +₁ -isg')))) +₁ f' ≡⟨ cong (_+₁ f') (assoc₁ g -isg (f +₁ (g' -₁ isg'))) ⟩ ((g +₁ -isg) +₁ (f +₁ (g' +₁ -isg'))) +₁ f' ≡⟨ cong (_+₁ f') (assoc₁ (g -₁ isg) f (g' -₁ isg')) ⟩ (((g -₁ isg) +₁ f) +₁ (g' -₁ isg')) +₁ f' ≡⟨ sym (assoc₁ ((g -₁ isg) +₁ f) (g' -₁ isg') f') ⟩ ((g -₁ isg) +₁ f) +₁ ((g' -₁ isg') +₁ f') ≡⟨ refl ⟩ (g ⊙ f) +₁ (g' ⊙ f') ∎ -- behold! use of symmetry is lurking around the corner -- (in stark contrast to composability proofs) assoc-∘ 𝒱 h g f _ _ _ _ = sym r where isg = 𝒾s g ish = 𝒾s h -ish = -₁ 𝒾s h abstract r = (h ⊙ g) ⊙ f ≡⟨ cong (λ z → (((h -₁ ish) +₁ g) -₁ z) +₁ f) (ι∘σ .isHom (h -₁ ish) g) ⟩ (((h -₁ ish) +₁ g) -₁ (𝒾s (h -₁ ish) +₁ 𝒾s g)) +₁ f ≡⟨ cong (λ z → (((h -₁ ish) +₁ g) -₁ (z +₁ 𝒾s g)) +₁ f) (ι∘σ .isHom h (-₁ ish)) ⟩ (((h -₁ ish) +₁ g) -₁ ((𝒾s h +₁ (𝒾s -ish)) +₁ 𝒾s g)) +₁ f ≡⟨ cong (λ z → (((h -₁ ish) +₁ g) -₁ ((𝒾s h +₁ z) +₁ 𝒾s g)) +₁ f) (ισ-ι (s h)) ⟩ (((h -₁ ish) +₁ g) -₁ ((ish -₁ ish) +₁ isg)) +₁ f ≡⟨ cong (λ z → (((h -₁ ish) +₁ g) -₁ z) +₁ f) (rCancel-lId G₁ ish isg) ⟩ (((h -₁ ish) +₁ g) -₁ isg) +₁ f ≡⟨ (cong (_+₁ f) (sym (assoc₁ (h -₁ ish) g (-₁ isg)))) ∙ (sym (assoc₁ (h -₁ ish) (g -₁ isg) f)) ⟩ h ⊙ (g ⊙ f) ∎ lid-∘ 𝒱 f _ = r where itf = 𝒾t f abstract r = itf ⊙ f ≡⟨ cong (λ z → (itf -₁ (𝒾 z)) +₁ f) (σι-≡-fun (t f)) ⟩ (itf -₁ itf) +₁ f ≡⟨ rCancel-lId G₁ itf f ⟩ f ∎ rid-∘ 𝒱 g _ = r where isg = 𝒾s g -isg = -₁ (𝒾s g) abstract r = g ⊙ isg ≡⟨ sym (assoc₁ g -isg isg) ⟩ g +₁ (-isg +₁ isg) ≡⟨ lCancel-rId G₁ g isg ⟩ g ∎ RelIso.inv (𝒮ᴰ-♭PIso-PeifferGraph-Strict2Group 𝒢) 𝒞 = isPf where open ReflGraphNotation 𝒢 open VertComp 𝒞 abstract isPf : isPeifferGraph 𝒢 isPf f g = ((isg +₁ (f -₁ itf)) +₁ (-isg +₁ g)) +₁ itf ≡⟨ cong (_+₁ itf) (sym (assoc₁ isg (f -₁ itf) (-isg +₁ g))) ⟩ (isg +₁ ((f -₁ itf) +₁ (-isg +₁ g))) +₁ itf ≡⟨ cong (λ z → (isg +₁ z) +₁ itf) (sym (assoc₁ f -itf (-isg +₁ g))) ⟩ (isg +₁ (f +₁ (-itf +₁ (-isg +₁ g)))) +₁ itf ≡⟨ cong (λ z → (isg +₁ (f +₁ z)) +₁ itf) (assoc₁ -itf -isg g) ⟩ (isg +₁ (f +₁ ((-itf -₁ isg) +₁ g))) +₁ itf ≡⟨ cong (λ z → (isg +₁ z) +₁ itf) (IC5 𝒞 g f) ⟩ (isg +₁ ((-isg +₁ g) +₁ (f -₁ itf))) +₁ itf ≡⟨ cong (_+₁ itf) (assoc₁ isg (-isg +₁ g) (f -₁ itf)) ⟩ ((isg +₁ (-isg +₁ g)) +₁ (f -₁ itf)) +₁ itf ≡⟨ cong (λ z → (z +₁ (f -₁ itf)) +₁ itf) (assoc₁ isg -isg g ∙ rCancel-lId G₁ isg g) ⟩ (g +₁ (f -₁ itf)) +₁ itf ≡⟨ sym (assoc₁ g (f -₁ itf) itf) ⟩ g +₁ ((f -₁ itf) +₁ itf) ≡⟨ cong (g +₁_) ((sym (assoc₁ _ _ _)) ∙ (lCancel-rId G₁ f itf)) ⟩ g +₁ f ∎ where isg = 𝒾s g -isg = -₁ (𝒾s g) itf = 𝒾t f -itf = -it f RelIso.leftInv (𝒮ᴰ-♭PIso-PeifferGraph-Strict2Group _) _ = tt RelIso.rightInv (𝒮ᴰ-♭PIso-PeifferGraph-Strict2Group _) _ = tt Iso-PeifferGraph-Strict2Group : Iso (PeifferGraph ℓ ℓℓ') (Strict2Group ℓ ℓℓ') Iso-PeifferGraph-Strict2Group = 𝒮ᴰ-♭PIso-Over→TotalIso idIso (𝒮ᴰ-ReflGraph\Peiffer ℓ ℓℓ') (𝒮ᴰ-Strict2Group ℓ ℓℓ') 𝒮ᴰ-♭PIso-PeifferGraph-Strict2Group open import Cubical.DStructures.Equivalences.XModPeifferGraph Iso-XModule-Strict2Group : Iso (XModule ℓ ℓℓ') (Strict2Group ℓ ℓℓ') Iso-XModule-Strict2Group = compIso (Iso-XModule-PeifferGraph ℓ ℓℓ') Iso-PeifferGraph-Strict2Group
algebraic-stack_agda0000_doc_6124
------------------------------------------------------------------------------ -- Arithmetic properties (added for the Collatz function example) ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Program.Collatz.Data.Nat.PropertiesATP where open import FOTC.Base open import FOTC.Data.Nat open import FOTC.Data.Nat.Inequalities open import FOTC.Data.Nat.Inequalities.PropertiesATP using ( x≤x ; 2*SSx≥2 ) open import FOTC.Data.Nat.PropertiesATP using ( *-N ; *-rightZero ; *-rightIdentity ; x∸x≡0 ; +-rightIdentity ; +-comm ; +-N ; xy≡0→x≡0∨y≡0 ; Sx≢x ; xy≡1→x≡1 ; 0∸x ; S∸S ) open import FOTC.Data.Nat.UnaryNumbers open import FOTC.Program.Collatz.Data.Nat ------------------------------------------------------------------------------ ^-N : ∀ {m n} → N m → N n → N (m ^ n) ^-N {m} Nm nzero = prf where postulate prf : N (m ^ zero) {-# ATP prove prf #-} ^-N {m} Nm (nsucc {n} Nn) = prf (^-N Nm Nn) where postulate prf : N (m ^ n) → N (m ^ succ₁ n) {-# ATP prove prf *-N #-} div-2x-2≡x : ∀ {n} → N n → div (2' * n) 2' ≡ n div-2x-2≡x nzero = prf where postulate prf : div (2' * zero) 2' ≡ zero {-# ATP prove prf *-rightZero #-} div-2x-2≡x (nsucc nzero) = prf where postulate prf : div (2' * (succ₁ zero)) 2' ≡ succ₁ zero {-# ATP prove prf *-rightIdentity x≤x x∸x≡0 #-} div-2x-2≡x (nsucc (nsucc {n} Nn)) = prf (div-2x-2≡x (nsucc Nn)) where postulate prf : div (2' * succ₁ n) 2' ≡ succ₁ n → div (2' * (succ₁ (succ₁ n))) 2' ≡ succ₁ (succ₁ n) {-# ATP prove prf 2*SSx≥2 +-rightIdentity +-comm +-N #-} postulate div-2^[x+1]-2≡2^x : ∀ {n} → N n → div (2' ^ succ₁ n) 2' ≡ 2' ^ n {-# ATP prove div-2^[x+1]-2≡2^x ^-N div-2x-2≡x #-} +∸2 : ∀ {n} → N n → n ≢ zero → n ≢ 1' → n ≡ succ₁ (succ₁ (n ∸ 2')) +∸2 nzero n≢0 n≢1 = ⊥-elim (n≢0 refl) +∸2 (nsucc nzero) n≢0 n≢1 = ⊥-elim (n≢1 refl) +∸2 (nsucc (nsucc {n} Nn)) n≢0 n≢1 = prf where -- TODO (06 December 2012). We do not use the ATPs because we do not -- how to erase a term. -- -- See the interactive proof. postulate prf : succ₁ (succ₁ n) ≡ succ₁ (succ₁ (succ₁ (succ₁ n) ∸ 2')) -- {-# ATP prove prf S∸S #-} 2^x≢0 : ∀ {n} → N n → 2' ^ n ≢ zero 2^x≢0 nzero h = ⊥-elim (0≢S (trans (sym h) (^-0 2'))) 2^x≢0 (nsucc {n} Nn) h = prf (2^x≢0 Nn) where postulate prf : 2' ^ n ≢ zero → ⊥ {-# ATP prove prf xy≡0→x≡0∨y≡0 ^-N #-} postulate 2^[x+1]≢1 : ∀ {n} → N n → 2' ^ succ₁ n ≢ 1' {-# ATP prove 2^[x+1]≢1 Sx≢x xy≡1→x≡1 ^-N #-} Sx-Even→x-Odd : ∀ {n} → N n → Even (succ₁ n) → Odd n Sx-Even→x-Odd nzero h = ⊥-elim prf where postulate prf : ⊥ {-# ATP prove prf #-} Sx-Even→x-Odd (nsucc {n} Nn) h = prf where postulate prf : odd (succ₁ n) ≡ true {-# ATP prove prf #-} Sx-Odd→x-Even : ∀ {n} → N n → Odd (succ₁ n) → Even n Sx-Odd→x-Even nzero _ = even-0 Sx-Odd→x-Even (nsucc {n} Nn) h = trans (sym (odd-S (succ₁ n))) h postulate 2-Even : Even 2' {-# ATP prove 2-Even #-} ∸-Even : ∀ {m n} → N m → N n → Even m → Even n → Even (m ∸ n) ∸-Odd : ∀ {m n} → N m → N n → Odd m → Odd n → Even (m ∸ n) ∸-Even {m} Nm nzero h₁ _ = subst Even (sym (∸-x0 m)) h₁ ∸-Even nzero (nsucc {n} Nn) h₁ _ = subst Even (sym (0∸x (nsucc Nn))) h₁ ∸-Even (nsucc {m} Nm) (nsucc {n} Nn) h₁ h₂ = prf where postulate prf : Even (succ₁ m ∸ succ₁ n) {-# ATP prove prf ∸-Odd Sx-Even→x-Odd S∸S #-} ∸-Odd nzero Nn h₁ _ = ⊥-elim (t≢f (trans (sym h₁) odd-0)) ∸-Odd (nsucc Nm) nzero _ h₂ = ⊥-elim (t≢f (trans (sym h₂) odd-0)) ∸-Odd (nsucc {m} Nm) (nsucc {n} Nn) h₁ h₂ = prf where postulate prf : Even (succ₁ m ∸ succ₁ n) {-# ATP prove prf ∸-Even Sx-Odd→x-Even S∸S #-} x-Even→SSx-Even : ∀ {n} → N n → Even n → Even (succ₁ (succ₁ n)) x-Even→SSx-Even nzero h = prf where postulate prf : Even (succ₁ (succ₁ zero)) {-# ATP prove prf #-} x-Even→SSx-Even (nsucc {n} Nn) h = prf where postulate prf : Even (succ₁ (succ₁ (succ₁ n))) {-# ATP prove prf #-} x+x-Even : ∀ {n} → N n → Even (n + n) x+x-Even nzero = prf where postulate prf : even (zero + zero) ≡ true {-# ATP prove prf #-} x+x-Even (nsucc {n} Nn) = prf (x+x-Even Nn) where postulate prf : Even (n + n) → Even (succ₁ n + succ₁ n) {-# ATP prove prf x-Even→SSx-Even +-N +-comm #-} 2x-Even : ∀ {n} → N n → Even (2' * n) 2x-Even nzero = prf where postulate prf : Even (2' * zero) {-# ATP prove prf #-} 2x-Even (nsucc {n} Nn) = prf where postulate prf : Even (2' * succ₁ n) {-# ATP prove prf x-Even→SSx-Even x+x-Even +-N +-comm +-rightIdentity #-} postulate 2^[x+1]-Even : ∀ {n} → N n → Even (2' ^ succ₁ n) {-# ATP prove 2^[x+1]-Even ^-N 2x-Even #-}
algebraic-stack_agda0000_doc_6125
module OlderBasicILP.Direct.Translation where open import Common.Context public -- import OlderBasicILP.Direct.Hilbert.Sequential as HS import OlderBasicILP.Direct.Hilbert.Nested as HN import OlderBasicILP.Direct.Gentzen as G -- open HS using () renaming (_⊢×_ to HS⟨_⊢×_⟩ ; _⊢_ to HS⟨_⊢_⟩) public open HN using () renaming (_⊢_ to HN⟨_⊢_⟩ ; _⊢⋆_ to HN⟨_⊢⋆_⟩) public open G using () renaming (_⊢_ to G⟨_⊢_⟩ ; _⊢⋆_ to G⟨_⊢⋆_⟩) public -- Translation from sequential Hilbert-style to nested. -- hs→hn : ∀ {A Γ} → HS⟨ Γ ⊢ A ⟩ → HN⟨ Γ ⊢ A ⟩ -- hs→hn = ? -- Translation from nested Hilbert-style to sequential. -- hn→hs : ∀ {A Γ} → HN⟨ Γ ⊢ A ⟩ → HS⟨ Γ ⊢ A ⟩ -- hn→hs = ? -- Deduction theorem for sequential Hilbert-style. -- hs-lam : ∀ {A B Γ} → HS⟨ Γ , A ⊢ B ⟩ → HS⟨ Γ ⊢ A ▻ B ⟩ -- hs-lam = hn→hs ∘ HN.lam ∘ hs→hn -- Translation from Hilbert-style to Gentzen-style. mutual hn→gᵇᵒˣ : HN.Box → G.Box hn→gᵇᵒˣ HN.[ t ] = {!G.[ hn→g t ]!} hn→gᵀ : HN.Ty → G.Ty hn→gᵀ (HN.α P) = G.α P hn→gᵀ (A HN.▻ B) = hn→gᵀ A G.▻ hn→gᵀ B hn→gᵀ (T HN.⦂ A) = hn→gᵇᵒˣ T G.⦂ hn→gᵀ A hn→gᵀ (A HN.∧ B) = hn→gᵀ A G.∧ hn→gᵀ B hn→gᵀ HN.⊤ = G.⊤ hn→gᵀ⋆ : Cx HN.Ty → Cx G.Ty hn→gᵀ⋆ ∅ = ∅ hn→gᵀ⋆ (Γ , A) = hn→gᵀ⋆ Γ , hn→gᵀ A hn→gⁱ : ∀ {A Γ} → A ∈ Γ → hn→gᵀ A ∈ hn→gᵀ⋆ Γ hn→gⁱ top = top hn→gⁱ (pop i) = pop (hn→gⁱ i) hn→g : ∀ {A Γ} → HN⟨ Γ ⊢ A ⟩ → G⟨ hn→gᵀ⋆ Γ ⊢ hn→gᵀ A ⟩ hn→g (HN.var i) = G.var (hn→gⁱ i) hn→g (HN.app t u) = G.app (hn→g t) (hn→g u) hn→g HN.ci = G.ci hn→g HN.ck = G.ck hn→g HN.cs = G.cs hn→g (HN.box t) = {!G.box (hn→g t)!} hn→g HN.cdist = {!G.cdist!} hn→g HN.cup = {!G.cup!} hn→g HN.cdown = G.cdown hn→g HN.cpair = G.cpair hn→g HN.cfst = G.cfst hn→g HN.csnd = G.csnd hn→g HN.unit = G.unit -- hs→g : ∀ {A Γ} → HS⟨ Γ ⊢ A ⟩ → G⟨ Γ ⊢ A ⟩ -- hs→g = hn→g ∘ hs→hn -- Translation from Gentzen-style to Hilbert-style. mutual g→hnᵇᵒˣ : G.Box → HN.Box g→hnᵇᵒˣ G.[ t ] = {!HN.[ g→hn t ]!} g→hnᵀ : G.Ty → HN.Ty g→hnᵀ (G.α P) = HN.α P g→hnᵀ (A G.▻ B) = g→hnᵀ A HN.▻ g→hnᵀ B g→hnᵀ (T G.⦂ A) = g→hnᵇᵒˣ T HN.⦂ g→hnᵀ A g→hnᵀ (A G.∧ B) = g→hnᵀ A HN.∧ g→hnᵀ B g→hnᵀ G.⊤ = HN.⊤ g→hnᵀ⋆ : Cx G.Ty → Cx HN.Ty g→hnᵀ⋆ ∅ = ∅ g→hnᵀ⋆ (Γ , A) = g→hnᵀ⋆ Γ , g→hnᵀ A g→hnⁱ : ∀ {A Γ} → A ∈ Γ → g→hnᵀ A ∈ g→hnᵀ⋆ Γ g→hnⁱ top = top g→hnⁱ (pop i) = pop (g→hnⁱ i) g→hn : ∀ {A Γ} → G⟨ Γ ⊢ A ⟩ → HN⟨ g→hnᵀ⋆ Γ ⊢ g→hnᵀ A ⟩ g→hn (G.var i) = HN.var (g→hnⁱ i) g→hn (G.lam t) = HN.lam (g→hn t) g→hn (G.app t u) = HN.app (g→hn t) (g→hn u) -- g→hn (G.multibox ts u) = {!HN.multibox (g→hn⋆ ts) (g→hn u)!} g→hn (G.down t) = HN.down (g→hn t) g→hn (G.pair t u) = HN.pair (g→hn t) (g→hn u) g→hn (G.fst t) = HN.fst (g→hn t) g→hn (G.snd t) = HN.snd (g→hn t) g→hn G.unit = HN.unit g→hn⋆ : ∀ {Ξ Γ} → G⟨ Γ ⊢⋆ Ξ ⟩ → HN⟨ g→hnᵀ⋆ Γ ⊢⋆ g→hnᵀ⋆ Ξ ⟩ g→hn⋆ {∅} ∙ = ∙ g→hn⋆ {Ξ , A} (ts , t) = g→hn⋆ ts , g→hn t -- g→hs : ∀ {A Γ} → G⟨ Γ ⊢ A ⟩ → HS⟨ Γ ⊢ A ⟩ -- g→hs = hn→hs ∘ g→hn
algebraic-stack_agda0000_doc_6126
module Oscar.Class.Semifunctor where open import Oscar.Class.Semigroup open import Oscar.Class.Extensionality open import Oscar.Class.Preservativity open import Oscar.Function open import Oscar.Level open import Oscar.Relation record Semifunctor {𝔞₁} {𝔄₁ : Set 𝔞₁} {𝔰₁} {_►₁_ : 𝔄₁ → 𝔄₁ → Set 𝔰₁} (_◅₁_ : ∀ {m n} → m ►₁ n → ∀ {l} → m ⟨ l ►₁_ ⟩→ n) {ℓ₁} (_≋₁_ : ∀ {m n} → m ►₁ n → m ►₁ n → Set ℓ₁) {𝔞₂} {𝔄₂ : Set 𝔞₂} {𝔰₂} {_►₂_ : 𝔄₂ → 𝔄₂ → Set 𝔰₂} (_◅₂_ : ∀ {m n} → m ►₂ n → ∀ {l} → m ⟨ l ►₂_ ⟩→ n) {ℓ₂} (_≋₂_ : ∀ {m n} → m ►₂ n → m ►₂ n → Set ℓ₂) (μ : 𝔄₁ → 𝔄₂) (□ : ∀ {m n} → m ►₁ n → μ m ►₂ μ n) : Set (𝔞₁ ⊔ 𝔰₁ ⊔ ℓ₁ ⊔ 𝔞₂ ⊔ 𝔰₂ ⊔ ℓ₂) where field ⦃ ′semigroup₁ ⦄ : Semigroup _◅₁_ _≋₁_ ⦃ ′semigroup₂ ⦄ : Semigroup _◅₂_ _≋₂_ ⦃ ′extensionality ⦄ : ∀ {m n} → Extensionality (_≋₁_ {m} {n}) (λ ⋆ → _≋₂_ {μ m} {μ n} ⋆) □ □ ⦃ ′preservativity ⦄ : ∀ {l m n} → Preservativity (λ ⋆ → _◅₁_ {m = m} {n = n} ⋆ {l = l}) (λ ⋆ → _◅₂_ ⋆) _≋₂_ □ □ □ instance Semifunctor⋆ : ∀ {𝔞₁} {𝔄₁ : Set 𝔞₁} {𝔰₁} {_►₁_ : 𝔄₁ → 𝔄₁ → Set 𝔰₁} {_◅₁_ : ∀ {m n} → m ►₁ n → ∀ {l} → m ⟨ l ►₁_ ⟩→ n} {ℓ₁} {_≋₁_ : ∀ {m n} → m ►₁ n → m ►₁ n → Set ℓ₁} {𝔞₂} {𝔄₂ : Set 𝔞₂} {𝔰₂} {_►₂_ : 𝔄₂ → 𝔄₂ → Set 𝔰₂} {_◅₂_ : ∀ {m n} → m ►₂ n → ∀ {l} → m ⟨ l ►₂_ ⟩→ n} {ℓ₂} {_≋₂_ : ∀ {m n} → m ►₂ n → m ►₂ n → Set ℓ₂} {μ : 𝔄₁ → 𝔄₂} {□ : ∀ {m n} → m ►₁ n → μ m ►₂ μ n} ⦃ _ : Semigroup _◅₁_ _≋₁_ ⦄ ⦃ _ : Semigroup _◅₂_ _≋₂_ ⦄ ⦃ _ : ∀ {m n} → Extensionality (_≋₁_ {m} {n}) (λ ⋆ → _≋₂_ {μ m} {μ n} ⋆) □ □ ⦄ ⦃ _ : ∀ {l m n} → Preservativity (λ ⋆ → _◅₁_ {m = m} {n = n} ⋆ {l = l}) (λ ⋆ → _◅₂_ ⋆) _≋₂_ □ □ □ ⦄ → Semifunctor _◅₁_ _≋₁_ _◅₂_ _≋₂_ μ □ Semifunctor.′semigroup₁ Semifunctor⋆ = it Semifunctor.′semigroup₂ Semifunctor⋆ = it Semifunctor.′extensionality Semifunctor⋆ = it Semifunctor.′preservativity Semifunctor⋆ = it -- record Semifunctor' -- {𝔞} {𝔄 : Set 𝔞} {𝔰} {_►_ : 𝔄 → 𝔄 → Set 𝔰} -- (_◅_ : ∀ {m n} → m ► n → ∀ {l} → m ⟨ l ►_ ⟩→ n) -- {ℓ₁} -- (_≋₁_ : ∀ {m n} → m ► n → m ► n → Set ℓ₁) -- {𝔱} {▸ : 𝔄 → Set 𝔱} -- (_◃_ : ∀ {m n} → m ► n → m ⟨ ▸ ⟩→ n) -- {ℓ₂} -- (_≋₂_ : ∀ {n} → ▸ n → ▸ n → Set ℓ₂) -- (□ : ∀ {m n} → m ► n → m ► n) -- : Set (𝔞 ⊔ 𝔰 ⊔ ℓ₁ ⊔ 𝔱 ⊔ ℓ₂) where -- field -- ⦃ ′semigroup₁ ⦄ : Semigroup _◅_ (λ ⋆ → _◅_ ⋆) _≋₁_ -- ⦃ ′semigroup₂ ⦄ : Semigroup _◅_ _◃_ _≋₂_ -- ⦃ ′extensionality ⦄ : ∀ {m} {t : ▸ m} {n} → Extensionality (_≋₁_ {m} {n}) (λ ⋆ → _≋₂_ {n} ⋆) (_◃ t) (_◃ t) -- ⦃ ′preservativity ⦄ : Preservativity _►₁_ _◃₁_ _►₂_ _◃₂_ _≋₂_ ◽ □ -- record Semifunctor -- {𝔞₁} {𝔄₁ : Set 𝔞₁} {𝔰₁} {_►₁_ : 𝔄₁ → 𝔄₁ → Set 𝔰₁} -- (_◅₁_ : ∀ {m n} → m ►₁ n → ∀ {l} → m ⟨ l ►₁_ ⟩→ n) -- {𝔱₁} {▸₁ : 𝔄₁ → Set 𝔱₁} -- (_◃₁_ : ∀ {m n} → m ►₁ n → m ⟨ ▸₁ ⟩→ n) -- {ℓ₁} -- (_≋₁_ : ∀ {n} → ▸₁ n → ▸₁ n → Set ℓ₁) -- {𝔞₂} {𝔄₂ : Set 𝔞₂} {𝔰₂} {_►₂_ : 𝔄₂ → 𝔄₂ → Set 𝔰₂} -- (_◅₂_ : ∀ {m n} → m ►₂ n → ∀ {l} → m ⟨ l ►₂_ ⟩→ n) -- {𝔱₂} {▸₂ : 𝔄₂ → Set 𝔱₂} -- (_◃₂_ : ∀ {m n} → m ►₂ n → m ⟨ ▸₂ ⟩→ n) -- {ℓ₂} -- (_≋₂_ : ∀ {n} → ▸₂ n → ▸₂ n → Set ℓ₂) -- (μ : 𝔄₁ → 𝔄₂) -- (◽ : ∀ {n} → ▸₁ n → ▸₂ (μ n)) -- (□ : ∀ {m n} → m ►₁ n → μ m ►₂ μ n) -- : Set (𝔞₁ ⊔ 𝔰₁ ⊔ 𝔱₁ ⊔ ℓ₁ ⊔ 𝔞₂ ⊔ 𝔰₂ ⊔ 𝔱₂ ⊔ ℓ₂) where -- field -- ⦃ ′semigroup₁ ⦄ : Semigroup _◅₁_ _◃₁_ _≋₁_ -- ⦃ ′semigroup₂ ⦄ : Semigroup _◅₂_ _◃₂_ _≋₂_ -- ⦃ ′extensionality ⦄ : ∀ {n} → Extensionality (_≋₁_ {n}) (λ ⋆ → _≋₂_ {μ n} ⋆) ◽ ◽ -- ⦃ ′preservativity ⦄ : Preservativity _►₁_ _◃₁_ _►₂_ _◃₂_ _≋₂_ ◽ □ -- open Semifunctor ⦃ … ⦄ public hiding (′semigroup₁; ′semigroup₂; ′extensionality; ′preservativity) -- instance -- Semifunctor⋆ : ∀ -- {𝔞₁} {𝔄₁ : Set 𝔞₁} {𝔰₁} {_►₁_ : 𝔄₁ → 𝔄₁ → Set 𝔰₁} -- {_◅₁_ : ∀ {m n} → m ►₁ n → ∀ {l} → m ⟨ l ►₁_ ⟩→ n} -- {𝔱₁} {▸₁ : 𝔄₁ → Set 𝔱₁} -- {_◃₁_ : ∀ {m n} → m ►₁ n → m ⟨ ▸₁ ⟩→ n} -- {ℓ₁} -- {_≋₁_ : ∀ {n} → ▸₁ n → ▸₁ n → Set ℓ₁} -- {𝔞₂} {𝔄₂ : Set 𝔞₂} {𝔰₂} {_►₂_ : 𝔄₂ → 𝔄₂ → Set 𝔰₂} -- {_◅₂_ : ∀ {m n} → m ►₂ n → ∀ {l} → m ⟨ l ►₂_ ⟩→ n} -- {𝔱₂} {▸₂ : 𝔄₂ → Set 𝔱₂} -- {_◃₂_ : ∀ {m n} → m ►₂ n → m ⟨ ▸₂ ⟩→ n} -- {ℓ₂} -- {_≋₂_ : ∀ {n} → ▸₂ n → ▸₂ n → Set ℓ₂} -- {μ : 𝔄₁ → 𝔄₂} -- {◽ : ∀ {n} → ▸₁ n → ▸₂ (μ n)} -- {□ : ∀ {m n} → m ►₁ n → μ m ►₂ μ n} -- ⦃ _ : Semigroup _◅₁_ _◃₁_ _≋₁_ ⦄ -- ⦃ _ : Semigroup _◅₂_ _◃₂_ _≋₂_ ⦄ -- ⦃ _ : ∀ {n} → Extensionality (_≋₁_ {n}) (λ ⋆ → _≋₂_ {μ n} ⋆) ◽ ◽ ⦄ -- ⦃ _ : Preservativity _►₁_ _◃₁_ _►₂_ _◃₂_ _≋₂_ ◽ □ ⦄ -- → Semifunctor _◅₁_ _◃₁_ _≋₁_ _◅₂_ _◃₂_ _≋₂_ μ ◽ □ -- Semifunctor.′semigroup₁ Semifunctor⋆ = it -- Semifunctor.′semigroup₂ Semifunctor⋆ = it -- Semifunctor.′extensionality Semifunctor⋆ = it -- Semifunctor.′preservativity Semifunctor⋆ = it
algebraic-stack_agda0000_doc_6127
module nform where open import Data.PropFormula (3) public open import Data.PropFormula.NormalForms 3 public open import Relation.Binary.PropositionalEquality using (_≡_; refl) p : PropFormula p = Var (# 0) q : PropFormula q = Var (# 1) r : PropFormula r = Var (# 2) φ : PropFormula φ = ¬ ((p ∧ (p ⊃ q)) ⊃ q) -- (p ∧ q) ∨ (¬ r) cnfφ : PropFormula cnfφ = ¬ q ∧ (p ∧ (¬ p ∨ q)) postulate p1 : ∅ ⊢ φ p2 : ∅ ⊢ cnfφ p2 = cnf-lem p1 -- thm-cnf p1 {- p3 : cnf φ ≡ cnfφ p3 = refl ψ : PropFormula ψ = (¬ r) ∨ (p ∧ q) cnfψ : PropFormula cnfψ = (¬ r ∨ p) ∧ (¬ r ∨ q) p5 : cnf ψ ≡ cnfψ p5 = refl -} to5 = (¬ p) ∨ ((¬ q) ∨ r) from5 = (¬ p) ∨ (r ∨ ((¬ q) ∧ p)) test : ⌊ eq (cnf from5) to5 ⌋ ≡ false test = refl
algebraic-stack_agda0000_doc_17152
open import Nat open import Prelude open import contexts open import core open import type-assignment-unicity module canonical-indeterminate-forms where -- this type gives somewhat nicer syntax for the output of the canonical -- forms lemma for indeterminates at base type data cif-base : (Δ : hctx) (d : ihexp) → Set where CIFBEHole : ∀ {Δ d} → Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ] ((d == ⦇-⦈⟨ u , σ ⟩) × ((u :: b [ Γ ]) ∈ Δ) × (Δ , ∅ ⊢ σ :s: Γ) ) → cif-base Δ d CIFBNEHole : ∀ {Δ d} → Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ] Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ] ((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) × (Δ , ∅ ⊢ d' :: τ') × (d' final) × ((u :: b [ Γ ]) ∈ Δ) × (Δ , ∅ ⊢ σ :s: Γ) ) → cif-base Δ d CIFBAp : ∀ {Δ d} → Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ] Σ[ τ2 ∈ htyp ] ((d == d1 ∘ d2) × (Δ , ∅ ⊢ d1 :: τ2 ==> b) × (Δ , ∅ ⊢ d2 :: τ2) × (d1 indet) × (d2 final) × ((τ3 τ4 τ3' τ4' : htyp) (d1' : ihexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩)) ) → cif-base Δ d CIFBCast : ∀ {Δ d} → Σ[ d' ∈ ihexp ] ((d == d' ⟨ ⦇-⦈ ⇒ b ⟩) × (Δ , ∅ ⊢ d' :: ⦇-⦈) × (d' indet) × ((d'' : ihexp) (τ' : htyp) → d' ≠ (d'' ⟨ τ' ⇒ ⦇-⦈ ⟩)) ) → cif-base Δ d CIFBFailedCast : ∀ {Δ d} → Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ] ((d == d' ⟨ τ' ⇒⦇-⦈⇏ b ⟩) × (Δ , ∅ ⊢ d' :: τ') × (τ' ground) × (τ' ≠ b) ) → cif-base Δ d canonical-indeterminate-forms-base : ∀{Δ d} → Δ , ∅ ⊢ d :: b → d indet → cif-base Δ d canonical-indeterminate-forms-base TAConst () canonical-indeterminate-forms-base (TAVar x₁) () canonical-indeterminate-forms-base (TAAp wt wt₁) (IAp x ind x₁) = CIFBAp (_ , _ , _ , refl , wt , wt₁ , ind , x₁ , x) canonical-indeterminate-forms-base (TAEHole x x₁) IEHole = CIFBEHole (_ , _ , _ , refl , x , x₁) canonical-indeterminate-forms-base (TANEHole x wt x₁) (INEHole x₂) = CIFBNEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁) canonical-indeterminate-forms-base (TACast wt x) (ICastHoleGround x₁ ind x₂) = CIFBCast (_ , refl , wt , ind , x₁) canonical-indeterminate-forms-base (TAFailedCast x x₁ x₂ x₃) (IFailedCast x₄ x₅ x₆ x₇) = CIFBFailedCast (_ , _ , refl , x , x₅ , x₇) -- this type gives somewhat nicer syntax for the output of the canonical -- forms lemma for indeterminates at arrow type data cif-arr : (Δ : hctx) (d : ihexp) (τ1 τ2 : htyp) → Set where CIFAEHole : ∀{d Δ τ1 τ2} → Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ] ((d == ⦇-⦈⟨ u , σ ⟩) × ((u :: (τ1 ==> τ2) [ Γ ]) ∈ Δ) × (Δ , ∅ ⊢ σ :s: Γ) ) → cif-arr Δ d τ1 τ2 CIFANEHole : ∀{d Δ τ1 τ2} → Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ] Σ[ Γ ∈ tctx ] ((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) × (Δ , ∅ ⊢ d' :: τ') × (d' final) × ((u :: (τ1 ==> τ2) [ Γ ]) ∈ Δ) × (Δ , ∅ ⊢ σ :s: Γ) ) → cif-arr Δ d τ1 τ2 CIFAAp : ∀{d Δ τ1 τ2} → Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ] Σ[ τ2' ∈ htyp ] Σ[ τ1 ∈ htyp ] Σ[ τ2 ∈ htyp ] ((d == d1 ∘ d2) × (Δ , ∅ ⊢ d1 :: τ2' ==> (τ1 ==> τ2)) × (Δ , ∅ ⊢ d2 :: τ2') × (d1 indet) × (d2 final) × ((τ3 τ4 τ3' τ4' : htyp) (d1' : ihexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩)) ) → cif-arr Δ d τ1 τ2 CIFACast : ∀{d Δ τ1 τ2} → Σ[ d' ∈ ihexp ] Σ[ τ1 ∈ htyp ] Σ[ τ2 ∈ htyp ] Σ[ τ1' ∈ htyp ] Σ[ τ2' ∈ htyp ] ((d == d' ⟨ (τ1' ==> τ2') ⇒ (τ1 ==> τ2) ⟩) × (Δ , ∅ ⊢ d' :: τ1' ==> τ2') × (d' indet) × ((τ1' ==> τ2') ≠ (τ1 ==> τ2)) ) → cif-arr Δ d τ1 τ2 CIFACastHole : ∀{d Δ τ1 τ2} → Σ[ d' ∈ ihexp ] ((d == (d' ⟨ ⦇-⦈ ⇒ ⦇-⦈ ==> ⦇-⦈ ⟩)) × (τ1 == ⦇-⦈) × (τ2 == ⦇-⦈) × (Δ , ∅ ⊢ d' :: ⦇-⦈) × (d' indet) × ((d'' : ihexp) (τ' : htyp) → d' ≠ (d'' ⟨ τ' ⇒ ⦇-⦈ ⟩)) ) → cif-arr Δ d τ1 τ2 CIFAFailedCast : ∀{d Δ τ1 τ2} → Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ] ((d == (d' ⟨ τ' ⇒⦇-⦈⇏ ⦇-⦈ ==> ⦇-⦈ ⟩) ) × (τ1 == ⦇-⦈) × (τ2 == ⦇-⦈) × (Δ , ∅ ⊢ d' :: τ') × (τ' ground) × (τ' ≠ (⦇-⦈ ==> ⦇-⦈)) ) → cif-arr Δ d τ1 τ2 canonical-indeterminate-forms-arr : ∀{Δ d τ1 τ2 } → Δ , ∅ ⊢ d :: (τ1 ==> τ2) → d indet → cif-arr Δ d τ1 τ2 canonical-indeterminate-forms-arr (TAVar x₁) () canonical-indeterminate-forms-arr (TALam _ wt) () canonical-indeterminate-forms-arr (TAAp wt wt₁) (IAp x ind x₁) = CIFAAp (_ , _ , _ , _ , _ , refl , wt , wt₁ , ind , x₁ , x) canonical-indeterminate-forms-arr (TAEHole x x₁) IEHole = CIFAEHole (_ , _ , _ , refl , x , x₁) canonical-indeterminate-forms-arr (TANEHole x wt x₁) (INEHole x₂) = CIFANEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁) canonical-indeterminate-forms-arr (TACast wt x) (ICastArr x₁ ind) = CIFACast (_ , _ , _ , _ , _ , refl , wt , ind , x₁) canonical-indeterminate-forms-arr (TACast wt TCHole2) (ICastHoleGround x₁ ind GHole) = CIFACastHole (_ , refl , refl , refl , wt , ind , x₁) canonical-indeterminate-forms-arr (TAFailedCast x x₁ GHole x₃) (IFailedCast x₄ x₅ GHole x₇) = CIFAFailedCast (_ , _ , refl , refl , refl , x , x₅ , x₇) -- this type gives somewhat nicer syntax for the output of the canonical -- forms lemma for indeterminates at hole type data cif-hole : (Δ : hctx) (d : ihexp) → Set where CIFHEHole : ∀ {Δ d} → Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ Γ ∈ tctx ] ((d == ⦇-⦈⟨ u , σ ⟩) × ((u :: ⦇-⦈ [ Γ ]) ∈ Δ) × (Δ , ∅ ⊢ σ :s: Γ) ) → cif-hole Δ d CIFHNEHole : ∀ {Δ d} → Σ[ u ∈ Nat ] Σ[ σ ∈ env ] Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ] Σ[ Γ ∈ tctx ] ((d == ⦇⌜ d' ⌟⦈⟨ u , σ ⟩) × (Δ , ∅ ⊢ d' :: τ') × (d' final) × ((u :: ⦇-⦈ [ Γ ]) ∈ Δ) × (Δ , ∅ ⊢ σ :s: Γ) ) → cif-hole Δ d CIFHAp : ∀ {Δ d} → Σ[ d1 ∈ ihexp ] Σ[ d2 ∈ ihexp ] Σ[ τ2 ∈ htyp ] ((d == d1 ∘ d2) × (Δ , ∅ ⊢ d1 :: (τ2 ==> ⦇-⦈)) × (Δ , ∅ ⊢ d2 :: τ2) × (d1 indet) × (d2 final) × ((τ3 τ4 τ3' τ4' : htyp) (d1' : ihexp) → d1 ≠ (d1' ⟨ τ3 ==> τ4 ⇒ τ3' ==> τ4' ⟩)) ) → cif-hole Δ d CIFHCast : ∀ {Δ d} → Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ] ((d == d' ⟨ τ' ⇒ ⦇-⦈ ⟩) × (Δ , ∅ ⊢ d' :: τ') × (τ' ground) × (d' indet) ) → cif-hole Δ d canonical-indeterminate-forms-hole : ∀{Δ d} → Δ , ∅ ⊢ d :: ⦇-⦈ → d indet → cif-hole Δ d canonical-indeterminate-forms-hole (TAVar x₁) () canonical-indeterminate-forms-hole (TAAp wt wt₁) (IAp x ind x₁) = CIFHAp (_ , _ , _ , refl , wt , wt₁ , ind , x₁ , x) canonical-indeterminate-forms-hole (TAEHole x x₁) IEHole = CIFHEHole (_ , _ , _ , refl , x , x₁) canonical-indeterminate-forms-hole (TANEHole x wt x₁) (INEHole x₂) = CIFHNEHole (_ , _ , _ , _ , _ , refl , wt , x₂ , x , x₁) canonical-indeterminate-forms-hole (TACast wt x) (ICastGroundHole x₁ ind) = CIFHCast (_ , _ , refl , wt , x₁ , ind) canonical-indeterminate-forms-hole (TACast wt x) (ICastHoleGround x₁ ind ()) canonical-indeterminate-forms-hole (TAFailedCast x x₁ () x₃) (IFailedCast x₄ x₅ x₆ x₇) canonical-indeterminate-forms-coverage : ∀{Δ d τ} → Δ , ∅ ⊢ d :: τ → d indet → τ ≠ b → ((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ==> τ2)) → τ ≠ ⦇-⦈ → ⊥ canonical-indeterminate-forms-coverage TAConst () nb na nh canonical-indeterminate-forms-coverage (TAVar x₁) () nb na nh canonical-indeterminate-forms-coverage (TALam _ wt) () nb na nh canonical-indeterminate-forms-coverage {τ = b} (TAAp wt wt₁) (IAp x ind x₁) nb na nh = nb refl canonical-indeterminate-forms-coverage {τ = ⦇-⦈} (TAAp wt wt₁) (IAp x ind x₁) nb na nh = nh refl canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TAAp wt wt₁) (IAp x ind x₁) nb na nh = na τ τ₁ refl canonical-indeterminate-forms-coverage {τ = b} (TAEHole x x₁) IEHole nb na nh = nb refl canonical-indeterminate-forms-coverage {τ = ⦇-⦈} (TAEHole x x₁) IEHole nb na nh = nh refl canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TAEHole x x₁) IEHole nb na nh = na τ τ₁ refl canonical-indeterminate-forms-coverage {τ = b} (TANEHole x wt x₁) (INEHole x₂) nb na nh = nb refl canonical-indeterminate-forms-coverage {τ = ⦇-⦈} (TANEHole x wt x₁) (INEHole x₂) nb na nh = nh refl canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TANEHole x wt x₁) (INEHole x₂) nb na nh = na τ τ₁ refl canonical-indeterminate-forms-coverage (TACast wt x) (ICastArr x₁ ind) nb na nh = na _ _ refl canonical-indeterminate-forms-coverage (TACast wt x) (ICastGroundHole x₁ ind) nb na nh = nh refl canonical-indeterminate-forms-coverage {τ = b} (TACast wt x) (ICastHoleGround x₁ ind x₂) nb na nh = nb refl canonical-indeterminate-forms-coverage {τ = ⦇-⦈} (TACast wt x) (ICastHoleGround x₁ ind x₂) nb na nh = nh refl canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TACast wt x) (ICastHoleGround x₁ ind x₂) nb na nh = na τ τ₁ refl canonical-indeterminate-forms-coverage {τ = b} (TAFailedCast x x₁ x₂ x₃) (IFailedCast x₄ x₅ x₆ x₇) = λ z _ _₁ → z refl canonical-indeterminate-forms-coverage {τ = ⦇-⦈} (TAFailedCast x x₁ x₂ x₃) (IFailedCast x₄ x₅ x₆ x₇) = λ _ _₁ z → z refl canonical-indeterminate-forms-coverage {τ = τ ==> τ₁} (TAFailedCast x x₁ x₂ x₃) (IFailedCast x₄ x₅ x₆ x₇) = λ _ z _₁ → z τ τ₁ refl
algebraic-stack_agda0000_doc_17153
module Cats.Util.SetoidReasoning where open import Relation.Binary.SetoidReasoning public open import Relation.Binary using (Setoid) open import Relation.Binary.EqReasoning as EqR using (_IsRelatedTo_) infixr 2 _≡⟨⟩_ _≡⟨⟩_ : ∀ {c l} {S : Setoid c l} → ∀ x {y} → _IsRelatedTo_ S x y → _IsRelatedTo_ S x y _≡⟨⟩_ {S = S} = EqR._≡⟨⟩_ S triangle : ∀ {l l′} (S : Setoid l l′) → let open Setoid S in ∀ m {x y} → x ≈ m → y ≈ m → x ≈ y triangle S m x≈m y≈m = trans x≈m (sym y≈m) where open Setoid S
algebraic-stack_agda0000_doc_17154
{-# OPTIONS --without-K --exact-split --safe #-} module Fragment.Extensions.CSemigroup.Base where open import Fragment.Equational.Theory.Bundles open import Fragment.Algebra.Signature open import Fragment.Algebra.Free Σ-magma hiding (_~_) open import Fragment.Algebra.Homomorphism Σ-magma open import Fragment.Algebra.Algebra Σ-magma using (Algebra; IsAlgebra; Interpretation; Congruence) open import Fragment.Equational.FreeExtension Θ-csemigroup using (FreeExtension; IsFreeExtension) open import Fragment.Equational.Model Θ-csemigroup open import Fragment.Extensions.CSemigroup.Monomial open import Fragment.Setoid.Morphism using (_↝_) open import Level using (Level; _⊔_) open import Data.Nat using (ℕ) open import Data.Fin using (#_) open import Data.Vec using (Vec; []; _∷_; map) open import Data.Vec.Relation.Binary.Pointwise.Inductive using ([]; _∷_) import Relation.Binary.Reasoning.Setoid as Reasoning open import Relation.Binary using (Setoid; IsEquivalence) open import Relation.Binary.PropositionalEquality as PE using (_≡_) private variable a ℓ : Level module _ (A : Model {a} {ℓ}) (n : ℕ) where private open module A = Setoid ∥ A ∥/≈ _·_ : ∥ A ∥ → ∥ A ∥ → ∥ A ∥ x · y = A ⟦ • ⟧ (x ∷ y ∷ []) ·-cong : ∀ {x y z w} → x ≈ y → z ≈ w → x · z ≈ y · w ·-cong x≈y z≈w = (A ⟦ • ⟧-cong) (x≈y ∷ z≈w ∷ []) ·-comm : ∀ (x y : ∥ A ∥) → x · y ≈ y · x ·-comm x y = ∥ A ∥ₐ-models comm (env {A = ∥ A ∥ₐ} (x ∷ y ∷ [])) ·-assoc : ∀ (x y z : ∥ A ∥) → (x · y) · z ≈ x · (y · z) ·-assoc x y z = ∥ A ∥ₐ-models assoc (env {A = ∥ A ∥ₐ} (x ∷ y ∷ z ∷ [])) data Blob : Set a where sta : ∥ A ∥ → Blob dyn : ∥ J' n ∥ → Blob blob : ∥ J' n ∥ → ∥ A ∥ → Blob infix 6 _≋_ data _≋_ : Blob → Blob → Set (a ⊔ ℓ) where sta : ∀ {x y} → x ≈ y → sta x ≋ sta y dyn : ∀ {xs ys} → xs ≡ ys → dyn xs ≋ dyn ys blob : ∀ {x y xs ys} → xs ≡ ys → x ≈ y → blob xs x ≋ blob ys y ≋-refl : ∀ {x} → x ≋ x ≋-refl {x = sta x} = sta A.refl ≋-refl {x = dyn xs} = dyn PE.refl ≋-refl {x = blob xs x} = blob PE.refl A.refl ≋-sym : ∀ {x y} → x ≋ y → y ≋ x ≋-sym (sta p) = sta (A.sym p) ≋-sym (dyn ps) = dyn (PE.sym ps) ≋-sym (blob ps p) = blob (PE.sym ps) (A.sym p) ≋-trans : ∀ {x y z} → x ≋ y → y ≋ z → x ≋ z ≋-trans (sta p) (sta q) = sta (A.trans p q) ≋-trans (dyn ps) (dyn qs) = dyn (PE.trans ps qs) ≋-trans (blob ps p) (blob qs q) = blob (PE.trans ps qs) (A.trans p q) ≋-isEquivalence : IsEquivalence _≋_ ≋-isEquivalence = record { refl = ≋-refl ; sym = ≋-sym ; trans = ≋-trans } Blob/≋ : Setoid _ _ Blob/≋ = record { Carrier = Blob ; _≈_ = _≋_ ; isEquivalence = ≋-isEquivalence } _++_ : Blob → Blob → Blob sta x ++ sta y = sta (x · y) dyn xs ++ dyn ys = dyn (xs ⊗ ys) sta x ++ dyn ys = blob ys x sta x ++ blob ys y = blob ys (x · y) dyn xs ++ sta y = blob xs y dyn xs ++ blob ys y = blob (xs ⊗ ys) y blob xs x ++ sta y = blob xs (x · y) blob xs x ++ dyn ys = blob (xs ⊗ ys) x blob xs x ++ blob ys y = blob (xs ⊗ ys) (x · y) ++-cong : ∀ {x y z w} → x ≋ y → z ≋ w → x ++ z ≋ y ++ w ++-cong (sta p) (sta q) = sta (·-cong p q) ++-cong (dyn ps) (dyn qs) = dyn (⊗-cong ps qs) ++-cong (sta p) (dyn qs) = blob qs p ++-cong (sta p) (blob qs q) = blob qs (·-cong p q) ++-cong (dyn ps) (sta q) = blob ps q ++-cong (dyn ps) (blob qs q) = blob (⊗-cong ps qs) q ++-cong (blob ps p) (sta q) = blob ps (·-cong p q) ++-cong (blob ps p) (dyn qs) = blob (⊗-cong ps qs) p ++-cong (blob ps p) (blob qs q) = blob (⊗-cong ps qs) (·-cong p q) ++-comm : ∀ x y → x ++ y ≋ y ++ x ++-comm (sta x) (sta y) = sta (·-comm x y) ++-comm (dyn xs) (dyn ys) = dyn (⊗-comm xs ys) ++-comm (sta x) (dyn ys) = ≋-refl ++-comm (sta x) (blob ys y) = blob PE.refl (·-comm x y) ++-comm (dyn xs) (sta y) = ≋-refl ++-comm (dyn xs) (blob ys y) = blob (⊗-comm xs ys) A.refl ++-comm (blob xs x) (sta y) = blob PE.refl (·-comm x y) ++-comm (blob xs x) (dyn ys) = blob (⊗-comm xs ys) A.refl ++-comm (blob xs x) (blob ys y) = blob (⊗-comm xs ys) (·-comm x y) ++-assoc : ∀ x y z → (x ++ y) ++ z ≋ x ++ (y ++ z) ++-assoc (sta x) (sta y) (sta z) = sta (·-assoc x y z) ++-assoc (dyn xs) (dyn ys) (dyn zs) = dyn (⊗-assoc xs ys zs) ++-assoc (sta x) (sta y) (dyn zs) = ≋-refl ++-assoc (sta x) (sta y) (blob zs z) = blob PE.refl (·-assoc x y z) ++-assoc (sta x) (dyn ys) (sta z) = ≋-refl ++-assoc (sta x) (dyn ys) (dyn zs) = ≋-refl ++-assoc (sta x) (dyn ys) (blob zs z) = ≋-refl ++-assoc (sta x) (blob ys y) (sta z) = blob PE.refl (·-assoc x y z) ++-assoc (sta x) (blob ys y) (dyn zs) = ≋-refl ++-assoc (sta x) (blob ys y) (blob zs z) = blob PE.refl (·-assoc x y z) ++-assoc (dyn xs) (sta y) (sta z) = ≋-refl ++-assoc (dyn xs) (sta y) (dyn zs) = ≋-refl ++-assoc (dyn xs) (sta y) (blob zs z) = ≋-refl ++-assoc (dyn xs) (dyn ys) (sta z) = ≋-refl ++-assoc (dyn xs) (dyn ys) (blob zs z) = blob (⊗-assoc xs ys zs) A.refl ++-assoc (dyn xs) (blob ys y) (sta z) = ≋-refl ++-assoc (dyn xs) (blob ys y) (dyn zs) = blob (⊗-assoc xs ys zs) A.refl ++-assoc (dyn xs) (blob ys y) (blob zs z) = blob (⊗-assoc xs ys zs) A.refl ++-assoc (blob xs x) (sta y) (sta z) = blob PE.refl (·-assoc x y z) ++-assoc (blob xs x) (sta y) (dyn zs) = ≋-refl ++-assoc (blob xs x) (sta y) (blob zs z) = blob PE.refl (·-assoc x y z) ++-assoc (blob xs x) (dyn ys) (sta z) = ≋-refl ++-assoc (blob xs x) (dyn ys) (dyn zs) = blob (⊗-assoc xs ys zs) A.refl ++-assoc (blob xs x) (dyn ys) (blob zs z) = blob (⊗-assoc xs ys zs) A.refl ++-assoc (blob xs x) (blob ys y) (sta z) = blob PE.refl (·-assoc x y z) ++-assoc (blob xs x) (blob ys y) (dyn zs) = blob (⊗-assoc xs ys zs) A.refl ++-assoc (blob xs x) (blob ys y) (blob zs z) = blob (⊗-assoc xs ys zs) (·-assoc x y z) Blob⟦_⟧ : Interpretation Blob/≋ Blob⟦ • ⟧ (x ∷ y ∷ []) = x ++ y Blob⟦_⟧-cong : Congruence Blob/≋ Blob⟦_⟧ Blob⟦ • ⟧-cong (p ∷ q ∷ []) = ++-cong p q Blob/≋-isAlgebra : IsAlgebra Blob/≋ Blob/≋-isAlgebra = record { ⟦_⟧ = Blob⟦_⟧ ; ⟦⟧-cong = Blob⟦_⟧-cong } Blob/≋-algebra : Algebra Blob/≋-algebra = record { ∥_∥/≈ = Blob/≋ ; ∥_∥/≈-isAlgebra = Blob/≋-isAlgebra } Blob/≋-models : Models Blob/≋-algebra Blob/≋-models comm θ = ++-comm (θ (# 0)) (θ (# 1)) Blob/≋-models assoc θ = ++-assoc (θ (# 0)) (θ (# 1)) (θ (# 2)) Blob/≋-isModel : IsModel Blob/≋ Blob/≋-isModel = record { isAlgebra = Blob/≋-isAlgebra ; models = Blob/≋-models } Frex : Model Frex = record { ∥_∥/≈ = Blob/≋ ; isModel = Blob/≋-isModel } ∣inl∣ : ∥ A ∥ → ∥ Frex ∥ ∣inl∣ = sta ∣inl∣-cong : Congruent _≈_ _≋_ ∣inl∣ ∣inl∣-cong = sta ∣inl∣⃗ : ∥ A ∥/≈ ↝ ∥ Frex ∥/≈ ∣inl∣⃗ = record { ∣_∣ = ∣inl∣ ; ∣_∣-cong = ∣inl∣-cong } ∣inl∣-hom : Homomorphic ∥ A ∥ₐ ∥ Frex ∥ₐ ∣inl∣ ∣inl∣-hom • (x ∷ y ∷ []) = ≋-refl inl : ∥ A ∥ₐ ⟿ ∥ Frex ∥ₐ inl = record { ∣_∣⃗ = ∣inl∣⃗ ; ∣_∣-hom = ∣inl∣-hom } ∣inr∣ : ∥ J n ∥ → ∥ Frex ∥ ∣inr∣ x = dyn (∣ norm ∣ x) ∣inr∣-cong : Congruent ≈[ J n ] _≋_ ∣inr∣ ∣inr∣-cong p = dyn (∣ norm ∣-cong p) ∣inr∣⃗ : ∥ J n ∥/≈ ↝ ∥ Frex ∥/≈ ∣inr∣⃗ = record { ∣_∣ = ∣inr∣ ; ∣_∣-cong = ∣inr∣-cong } ∣inr∣-hom : Homomorphic ∥ J n ∥ₐ ∥ Frex ∥ₐ ∣inr∣ ∣inr∣-hom • (x ∷ y ∷ []) = dyn (∣ norm ∣-hom • (x ∷ y ∷ [])) inr : ∥ J n ∥ₐ ⟿ ∥ Frex ∥ₐ inr = record { ∣_∣⃗ = ∣inr∣⃗ ; ∣_∣-hom = ∣inr∣-hom } module _ {b ℓ} (X : Model {b} {ℓ}) where private open module X = Setoid ∥ X ∥/≈ renaming (_≈_ to _~_) _⊕_ : ∥ X ∥ → ∥ X ∥ → ∥ X ∥ x ⊕ y = X ⟦ • ⟧ (x ∷ y ∷ []) ⊕-cong : ∀ {x y z w} → x ~ y → z ~ w → x ⊕ z ~ y ⊕ w ⊕-cong p q = (X ⟦ • ⟧-cong) (p ∷ q ∷ []) ⊕-comm : ∀ (x y : ∥ X ∥) → x ⊕ y ~ y ⊕ x ⊕-comm x y = ∥ X ∥ₐ-models comm (env {A = ∥ X ∥ₐ} (x ∷ y ∷ [])) ⊕-assoc : ∀ (x y z : ∥ X ∥) → (x ⊕ y) ⊕ z ~ x ⊕ (y ⊕ z) ⊕-assoc x y z = ∥ X ∥ₐ-models assoc (env {A = ∥ X ∥ₐ} (x ∷ y ∷ z ∷ [])) module _ (f : ∥ A ∥ₐ ⟿ ∥ X ∥ₐ) (g : ∥ J n ∥ₐ ⟿ ∥ X ∥ₐ) where ∣resid∣ : ∥ Frex ∥ → ∥ X ∥ ∣resid∣ (sta x) = ∣ f ∣ x ∣resid∣ (dyn xs) = ∣ g ∣ (∣ syn ∣ xs) ∣resid∣ (blob xs x) = ∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x ∣resid∣-cong : Congruent _≋_ _~_ ∣resid∣ ∣resid∣-cong (sta p) = ∣ f ∣-cong p ∣resid∣-cong (dyn ps) = ∣ g ∣-cong (∣ syn ∣-cong ps) ∣resid∣-cong (blob ps p) = ⊕-cong (∣ g ∣-cong (∣ syn ∣-cong ps)) (∣ f ∣-cong p) open Reasoning ∥ X ∥/≈ ∣resid∣-hom : Homomorphic ∥ Frex ∥ₐ ∥ X ∥ₐ ∣resid∣ ∣resid∣-hom • (sta x ∷ sta y ∷ []) = ∣ f ∣-hom • (x ∷ y ∷ []) ∣resid∣-hom • (sta x ∷ dyn ys ∷ []) = ⊕-comm (∣ f ∣ x) _ ∣resid∣-hom • (sta x ∷ blob ys y ∷ []) = begin ∣ f ∣ x ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ y) ≈⟨ ⊕-cong X.refl (⊕-comm _ (∣ f ∣ y)) ⟩ ∣ f ∣ x ⊕ (∣ f ∣ y ⊕ ∣ g ∣ (∣ syn ∣ ys)) ≈⟨ X.sym (⊕-assoc (∣ f ∣ x) (∣ f ∣ y) _) ⟩ (∣ f ∣ x ⊕ ∣ f ∣ y) ⊕ ∣ g ∣ (∣ syn ∣ ys) ≈⟨ ⊕-cong (∣ f ∣-hom • (x ∷ y ∷ [])) X.refl ⟩ ∣ f ∣ (x · y) ⊕ ∣ g ∣ (∣ syn ∣ ys) ≈⟨ ⊕-comm _ _ ⟩ ∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ (x · y) ∎ ∣resid∣-hom • (dyn xs ∷ sta y ∷ []) = X.refl ∣resid∣-hom • (dyn xs ∷ dyn ys ∷ []) = ∣ g ⊙ syn ∣-hom • (xs ∷ ys ∷ []) ∣resid∣-hom • (dyn xs ∷ blob ys y ∷ []) = begin ∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ y) ≈⟨ X.sym (⊕-assoc _ _ (∣ f ∣ y)) ⟩ (∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ g ∣ (∣ syn ∣ ys)) ⊕ ∣ f ∣ y ≈⟨ ⊕-cong (∣ g ⊙ syn ∣-hom • (xs ∷ ys ∷ [])) X.refl ⟩ ∣ g ∣ (∣ syn ∣ (xs ⊗ ys)) ⊕ ∣ f ∣ y ∎ ∣resid∣-hom • (blob xs x ∷ sta y ∷ []) = begin (∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x) ⊕ ∣ f ∣ y ≈⟨ ⊕-assoc _ (∣ f ∣ x) (∣ f ∣ y) ⟩ ∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ f ∣ x ⊕ ∣ f ∣ y) ≈⟨ ⊕-cong X.refl (∣ f ∣-hom • (x ∷ y ∷ [])) ⟩ ∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ (x · y) ∎ ∣resid∣-hom • (blob xs x ∷ dyn ys ∷ []) = begin (∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x) ⊕ ∣ g ∣ (∣ syn ∣ ys) ≈⟨ ⊕-assoc _ (∣ f ∣ x) _ ⟩ ∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ f ∣ x ⊕ ∣ g ∣ (∣ syn ∣ ys)) ≈⟨ ⊕-cong X.refl (⊕-comm (∣ f ∣ x) _) ⟩ ∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ x) ≈⟨ X.sym (⊕-assoc _ _ (∣ f ∣ x)) ⟩ (∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ g ∣ (∣ syn ∣ ys)) ⊕ ∣ f ∣ x ≈⟨ ⊕-cong (∣ g ⊙ syn ∣-hom • (xs ∷ ys ∷ [])) X.refl ⟩ ∣ g ∣ (∣ syn ∣ (xs ⊗ ys)) ⊕ ∣ f ∣ x ∎ ∣resid∣-hom • (blob xs x ∷ blob ys y ∷ []) = begin (∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x) ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ y) ≈⟨ ⊕-assoc _ (∣ f ∣ x) _ ⟩ ∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ f ∣ x ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ y)) ≈⟨ ⊕-cong X.refl (X.sym (⊕-assoc (∣ f ∣ x) _ _)) ⟩ ∣ g ∣ (∣ syn ∣ xs) ⊕ ((∣ f ∣ x ⊕ ∣ g ∣ (∣ syn ∣ ys)) ⊕ ∣ f ∣ y) ≈⟨ ⊕-cong X.refl (⊕-cong (⊕-comm (∣ f ∣ x) _) X.refl) ⟩ ∣ g ∣ (∣ syn ∣ xs) ⊕ ((∣ g ∣ (∣ syn ∣ ys) ⊕ ∣ f ∣ x) ⊕ ∣ f ∣ y) ≈⟨ ⊕-cong X.refl (⊕-assoc _ (∣ f ∣ x) _) ⟩ ∣ g ∣ (∣ syn ∣ xs) ⊕ (∣ g ∣ (∣ syn ∣ ys) ⊕ (∣ f ∣ x ⊕ ∣ f ∣ y)) ≈⟨ X.sym (⊕-assoc _ _ _) ⟩ (∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ g ∣ (∣ syn ∣ ys)) ⊕ (∣ f ∣ x ⊕ ∣ f ∣ y) ≈⟨ ⊕-cong (∣ g ⊙ syn ∣-hom • (xs ∷ ys ∷ [])) (∣ f ∣-hom • (x ∷ y ∷ [])) ⟩ ∣ g ∣ (∣ syn ∣ (xs ⊗ ys)) ⊕ ∣ f ∣ (x · y) ∎ ∣resid∣⃗ : ∥ Frex ∥/≈ ↝ ∥ X ∥/≈ ∣resid∣⃗ = record { ∣_∣ = ∣resid∣ ; ∣_∣-cong = ∣resid∣-cong } _[_,_] : ∥ Frex ∥ₐ ⟿ ∥ X ∥ₐ _[_,_] = record { ∣_∣⃗ = ∣resid∣⃗ ; ∣_∣-hom = ∣resid∣-hom } module _ {b ℓ} {X : Model {b} {ℓ}} where private open module X = Setoid ∥ X ∥/≈ renaming (_≈_ to _~_) _⊕_ : ∥ X ∥ → ∥ X ∥ → ∥ X ∥ x ⊕ y = X ⟦ • ⟧ (x ∷ y ∷ []) ⊕-cong : ∀ {x y z w} → x ~ y → z ~ w → x ⊕ z ~ y ⊕ w ⊕-cong p q = (X ⟦ • ⟧-cong) (p ∷ q ∷ []) ⊕-comm : ∀ (x y : ∥ X ∥) → x ⊕ y ~ y ⊕ x ⊕-comm x y = ∥ X ∥ₐ-models comm (env {A = ∥ X ∥ₐ} (x ∷ y ∷ [])) ⊕-assoc : ∀ (x y z : ∥ X ∥) → (x ⊕ y) ⊕ z ~ x ⊕ (y ⊕ z) ⊕-assoc x y z = ∥ X ∥ₐ-models assoc (env {A = ∥ X ∥ₐ} (x ∷ y ∷ z ∷ [])) module _ {f : ∥ A ∥ₐ ⟿ ∥ X ∥ₐ} {g : ∥ J n ∥ₐ ⟿ ∥ X ∥ₐ} where commute₁ : X [ f , g ] ⊙ inl ≗ f commute₁ = X.refl commute₂ : X [ f , g ] ⊙ inr ≗ g commute₂ {x} = ∣ g ∣-cong (syn⊙norm≗id {x = x}) module _ {h : ∥ Frex ∥ₐ ⟿ ∥ X ∥ₐ} (c₁ : h ⊙ inl ≗ f) (c₂ : h ⊙ inr ≗ g) where open Reasoning ∥ X ∥/≈ universal : X [ f , g ] ≗ h universal {sta x} = X.sym c₁ universal {dyn xs} = begin ∣ g ∣ (∣ syn ∣ xs) ≈⟨ X.sym c₂ ⟩ ∣ h ∣ (dyn (∣ norm ∣ (∣ syn ∣ xs))) ≈⟨ ∣ h ∣-cong (dyn norm⊙syn≗id) ⟩ ∣ h ∣ (dyn xs) ∎ universal {blob xs x} = begin ∣ g ∣ (∣ syn ∣ xs) ⊕ ∣ f ∣ x ≈⟨ ⊕-cong universal universal ⟩ ∣ h ∣ (dyn xs) ⊕ ∣ h ∣ (sta x) ≈⟨ ∣ h ∣-hom • (dyn xs ∷ sta x ∷ []) ⟩ ∣ h ∣ (blob xs x) ∎ CSemigroupFrex : FreeExtension CSemigroupFrex = record { _[_] = Frex ; _[_]-isFrex = isFrex } where isFrex : IsFreeExtension Frex isFrex A n = record { inl = inl A n ; inr = inr A n ; _[_,_] = _[_,_] A n ; commute₁ = λ {_ _ X f g} → commute₁ A n {X = X} {f} {g} ; commute₂ = λ {_ _ X f g} → commute₂ A n {X = X} {f} {g} ; universal = λ {_ _ X f g h} → universal A n {X = X} {f} {g} {h} }
algebraic-stack_agda0000_doc_17155
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-} open import Light.Library.Data.Natural as ℕ using (ℕ ; predecessor ; zero) open import Light.Package using (Package) module Light.Literals.Level ⦃ natural‐package : Package record { ℕ } ⦄ where open import Light.Literals.Definition.Natural using (FromNatural) open FromNatural using (convert) open import Light.Level using (Level ; 0ℓ ; ++_) open import Light.Library.Relation.Decidable using (if_then_else_) open import Light.Library.Relation.Binary.Equality using (_≈_) open import Light.Library.Relation.Binary.Equality.Decidable using (DecidableEquality) instance from‐natural : FromNatural Level convert from‐natural n = if n ≈ zero then 0ℓ else ++ convert from‐natural (predecessor n)
algebraic-stack_agda0000_doc_17156
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.types.Paths open import lib.types.Pi open import lib.types.Unit module lib.types.Circle where {- Idea : data S¹ : Type₀ where base : S¹ loop : base == base I’m using Dan Licata’s trick to have a higher inductive type with definitional reduction rule for [base] -} module _ where private data #S¹-aux : Type₀ where #base : #S¹-aux data #S¹ : Type₀ where #s¹ : #S¹-aux → (Unit → Unit) → #S¹ S¹ : Type₀ S¹ = #S¹ base : S¹ base = #s¹ #base _ postulate -- HIT loop : base == base module S¹Elim {i} {P : S¹ → Type i} (base* : P base) (loop* : base* == base* [ P ↓ loop ]) where f : Π S¹ P f = f-aux phantom where f-aux : Phantom loop* → Π S¹ P f-aux phantom (#s¹ #base _) = base* postulate -- HIT loop-β : apd f loop == loop* open S¹Elim public using () renaming (f to S¹-elim) module S¹Rec {i} {A : Type i} (base* : A) (loop* : base* == base*) where private module M = S¹Elim base* (↓-cst-in loop*) f : S¹ → A f = M.f loop-β : ap f loop == loop* loop-β = apd=cst-in {f = f} M.loop-β module S¹RecType {i} (A : Type i) (e : A ≃ A) where open S¹Rec A (ua e) public coe-loop-β : (a : A) → coe (ap f loop) a == –> e a coe-loop-β a = coe (ap f loop) a =⟨ loop-β |in-ctx (λ u → coe u a) ⟩ coe (ua e) a =⟨ coe-β e a ⟩ –> e a ∎ coe!-loop-β : (a : A) → coe! (ap f loop) a == <– e a coe!-loop-β a = coe! (ap f loop) a =⟨ loop-β |in-ctx (λ u → coe! u a) ⟩ coe! (ua e) a =⟨ coe!-β e a ⟩ <– e a ∎ ↓-loop-out : {a a' : A} → a == a' [ f ↓ loop ] → –> e a == a' ↓-loop-out {a} {a'} p = –> e a =⟨ ! (coe-loop-β a) ⟩ coe (ap f loop) a =⟨ to-transp p ⟩ a' ∎ import lib.types.Generic1HIT as Generic1HIT module S¹G = Generic1HIT Unit Unit (idf _) (idf _) module P = S¹G.RecType (cst A) (cst e) private generic-S¹ : Σ S¹ f == Σ S¹G.T P.f generic-S¹ = eqv-tot where module To = S¹Rec (S¹G.cc tt) (S¹G.pp tt) to = To.f module From = S¹G.Rec (cst base) (cst loop) from : S¹G.T → S¹ from = From.f abstract to-from : (x : S¹G.T) → to (from x) == x to-from = S¹G.elim (λ _ → idp) (λ _ → ↓-∘=idf-in to from (ap to (ap from (S¹G.pp tt)) =⟨ From.pp-β tt |in-ctx ap to ⟩ ap to loop =⟨ To.loop-β ⟩ S¹G.pp tt ∎)) from-to : (x : S¹) → from (to x) == x from-to = S¹-elim idp (↓-∘=idf-in from to (ap from (ap to loop) =⟨ To.loop-β |in-ctx ap from ⟩ ap from (S¹G.pp tt) =⟨ From.pp-β tt ⟩ loop ∎)) eqv : S¹ ≃ S¹G.T eqv = equiv to from to-from from-to eqv-fib : f == P.f [ (λ X → (X → Type _)) ↓ ua eqv ] eqv-fib = ↓-app→cst-in (λ {t} p → S¹-elim {P = λ t → f t == P.f (–> eqv t)} idp (↓-='-in (ap (P.f ∘ (–> eqv)) loop =⟨ ap-∘ P.f to loop ⟩ ap P.f (ap to loop) =⟨ To.loop-β |in-ctx ap P.f ⟩ ap P.f (S¹G.pp tt) =⟨ P.pp-β tt ⟩ ua e =⟨ ! loop-β ⟩ ap f loop ∎)) t ∙ ap P.f (↓-idf-ua-out eqv p)) eqv-tot : Σ S¹ f == Σ S¹G.T P.f eqv-tot = ap (uncurry Σ) (pair= (ua eqv) eqv-fib) import lib.types.Flattening as Flattening module FlatteningS¹ = Flattening Unit Unit (idf _) (idf _) (cst A) (cst e) open FlatteningS¹ public hiding (flattening-equiv; module P) flattening-S¹ : Σ S¹ f == Wt flattening-S¹ = generic-S¹ ∙ ua FlatteningS¹.flattening-equiv
algebraic-stack_agda0000_doc_17157
-- Andreas, 2015-06-24 {-# OPTIONS --copatterns #-} -- {-# OPTIONS -v tc.with.strip:20 #-} module _ where open import Common.Equality open import Common.Product module SynchronousIO (I O : Set) where F : Set → Set F S = I → O × S record SyncIO : Set₁ where field St : Set tr : St → F St module Eq (A₁ A₂ : SyncIO) where open SyncIO A₁ renaming (St to S₁; tr to tr₁) open SyncIO A₂ renaming (St to S₂; tr to tr₂) record BiSim (s₁ : S₁) (s₂ : S₂) : Set where coinductive field force : ∀ (i : I) → let (o₁ , t₁) = tr₁ s₁ i (o₂ , t₂) = tr₂ s₂ i in o₁ ≡ o₂ × BiSim t₁ t₂ module Trans (A₁ A₂ A₃ : SyncIO) where open SyncIO A₁ renaming (St to S₁; tr to tr₁) open SyncIO A₂ renaming (St to S₂; tr to tr₂) open SyncIO A₃ renaming (St to S₃; tr to tr₃) open Eq A₁ A₂ renaming (BiSim to _₁≅₂_; module BiSim to B₁₂) open Eq A₂ A₃ renaming (BiSim to _₂≅₃_; module BiSim to B₂₃) open Eq A₁ A₃ renaming (BiSim to _₁≅₃_; module BiSim to B₁₃) open B₁₂ renaming (force to force₁₂) open B₂₃ renaming (force to force₂₃) open B₁₃ renaming (force to force₁₃) transitivity : ∀{s₁ s₂ s₃} (p : s₁ ₁≅₂ s₂) (p' : s₂ ₂≅₃ s₃) → s₁ ₁≅₃ s₃ force₁₃ (transitivity p p') i with force₁₂ p i | force₂₃ p' i force₁₃ (transitivity p p') i | (q , r) | (q' , r') = trans q q' , transitivity r r' -- with-clause stripping failed for projections from module applications -- should work now
algebraic-stack_agda0000_doc_17158
-- MIT License -- Copyright (c) 2021 Luca Ciccone and Luca Padovani -- Permission is hereby granted, free of charge, to any person -- obtaining a copy of this software and associated documentation -- files (the "Software"), to deal in the Software without -- restriction, including without limitation the rights to use, -- copy, modify, merge, publish, distribute, sublicense, and/or sell -- copies of the Software, and to permit persons to whom the -- Software is furnished to do so, subject to the following -- conditions: -- The above copyright notice and this permission notice shall be -- included in all copies or substantial portions of the Software. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -- OTHER DEALINGS IN THE SOFTWARE. {-# OPTIONS --guardedness --sized-types #-} open import Data.Empty open import Data.Product open import Data.Sum open import Data.List using ([]; _∷_; _∷ʳ_; _++_) open import Data.List.Properties using (∷-injective) open import Relation.Nullary open import Relation.Nullary.Negation using (contraposition) open import Relation.Unary using (_∈_; _∉_; _⊆_) open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; subst; subst₂; cong) open import Relation.Binary.Construct.Closure.ReflexiveTransitive using (ε; _◅_) open import Function.Base using (case_of_) open import Common module Discriminator {ℙ : Set} (message : Message ℙ) where open import Trace message open import SessionType message open import HasTrace message open import TraceSet message open import Transitions message open import Subtyping message open import Divergence message open import Session message open import Semantics message make-diverge-backward : ∀{T S α} (tα : T HasTrace (α ∷ [])) (sα : S HasTrace (α ∷ [])) -> T ↑ S -> after tα ↑ after sα -> DivergeBackward tα sα make-diverge-backward tα sα divε divα none = divε make-diverge-backward tα sα divε divα (some none) = subst₂ (λ u v -> after u ↑ after v) (sym (⊑-has-trace-after tα)) (sym (⊑-has-trace-after sα)) divα has-trace-after-split : ∀{T φ ψ} -> (tφ : T HasTrace φ) (tφψ : T HasTrace (φ ++ ψ)) -> has-trace-after tφ (split-trace tφ tφψ) ≡ tφψ has-trace-after-split (_ , tdef , refl) tφψ = refl has-trace-after-split (_ , tdef , step inp tr) (_ , sdef , step inp sr) rewrite has-trace-after-split (_ , tdef , tr) (_ , sdef , sr) = refl has-trace-after-split (T , tdef , step (out fx) tr) (S , sdef , step (out gx) sr) rewrite has-trace-after-split (_ , tdef , tr) (_ , sdef , sr) = cong (S ,_) (cong (sdef ,_) (cong (λ z -> step z sr) (cong out (Defined-eq (transitions+defined->defined sr sdef) gx)))) disc-set-has-outputs : ∀{T S φ x} -> T <: S -> φ ∈ DiscSet T S -> T HasTrace (φ ∷ʳ O x) -> S HasTrace φ -> φ ∷ʳ O x ∈ DiscSet T S disc-set-has-outputs {_} {S} {φ} {x} sub (inc tφ sφ div←φ) tφx _ with S HasTrace? (φ ∷ʳ O x) ... | yes sφx = let tφ/x = split-trace tφ tφx in let sφ/x = split-trace sφ sφx in let divφ = subst₂ (λ u v -> after u ↑ after v) (⊑-has-trace-after tφ) (⊑-has-trace-after sφ) (div←φ (⊑-refl φ)) in let divx = _↑_.divergence divφ {[]} {x} none tφ/x sφ/x in let divφ←x = make-diverge-backward tφ/x sφ/x divφ divx in let div←φx = subst₂ DivergeBackward (has-trace-after-split tφ tφx) (has-trace-after-split sφ sφx) (append-diverge-backward tφ sφ tφ/x sφ/x div←φ divφ←x) in inc tφx sφx div←φx ... | no nsφx = exc refl tφ sφ tφx nsφx div←φ disc-set-has-outputs sub (exc eq tψ sψ tφ nsφ div←ψ) tφx sφ = ⊥-elim (nsφ sφ) defined-becomes-nil : ∀{T φ S} -> Defined T -> ¬ Defined S -> Transitions T φ S -> ∃[ ψ ] ∃[ x ] (φ ≡ ψ ∷ʳ I x × T HasTrace ψ × ¬ T HasTrace φ) defined-becomes-nil def ndef refl = ⊥-elim (ndef def) defined-becomes-nil def ndef (step (inp {_} {x}) refl) = [] , x , refl , (_ , inp , refl) , inp-has-no-trace λ { (_ , def , refl) → ⊥-elim (ndef def) } defined-becomes-nil def ndef (step inp tr@(step t _)) with defined-becomes-nil (transition->defined t) ndef tr ... | ψ , x , eq , tψ , ntφ = I _ ∷ ψ , x , cong (I _ ∷_) eq , inp-has-trace tψ , inp-has-no-trace ntφ defined-becomes-nil def ndef (step (out fx) tr) with defined-becomes-nil fx ndef tr ... | ψ , x , refl , tψ , ntφ = O _ ∷ ψ , x , refl , out-has-trace tψ , out-has-no-trace ntφ sub+diverge->defined : ∀{T S} -> T <: S -> T ↑ S -> Defined T × Defined S sub+diverge->defined nil<:any div with _↑_.with-trace div ... | _ , def , tr = ⊥-elim (contraposition (transitions+defined->defined tr) (λ ()) def) sub+diverge->defined (end<:def (inp _) def) _ = inp , def sub+diverge->defined (end<:def (out _) def) _ = out , def sub+diverge->defined (inp<:inp _ _) _ = inp , inp sub+diverge->defined (out<:out _ _ _) _ = out , out sub+diverge->has-empty-trace : ∀{T S} -> T <: S -> T ↑ S -> DiscSet T S [] sub+diverge->has-empty-trace nil<:any div with _↑_.with-trace div ... | tφ = ⊥-elim (nil-has-no-trace tφ) sub+diverge->has-empty-trace (end<:def e def) div with _↑_.with-trace div | _↑_.without-trace div ... | tφ | nsφ rewrite end-has-empty-trace e tφ = ⊥-elim (nsφ (defined->has-empty-trace def)) sub+diverge->has-empty-trace (inp<:inp _ _) div = inc (_ , inp , refl) (_ , inp , refl) λ { none → div } sub+diverge->has-empty-trace (out<:out _ _ _) div = inc (_ , out , refl) (_ , out , refl) λ { none → div } discriminator : SessionType -> SessionType -> SessionType discriminator T S = decode (co-semantics (disc-set->semantics T S)) .force discriminator-disc-set-sub : (T S : SessionType) -> CoSet ⟦ discriminator T S ⟧ ⊆ DiscSet T S discriminator-disc-set-sub T S rφ = co-inversion {DiscSet T S} (decode-sub (co-semantics (disc-set->semantics T S)) rφ) discriminator-disc-set-sup : (T S : SessionType) -> DiscSet T S ⊆ CoSet ⟦ discriminator T S ⟧ discriminator-disc-set-sup T S dφ = decode-sup (co-semantics (disc-set->semantics T S)) (co-definition {DiscSet T S} dφ) sub+diverge->discriminator-defined : ∀{T S} -> T <: S -> T ↑ S -> Defined (discriminator T S) sub+diverge->discriminator-defined {T} {S} sub div = has-trace->defined (co-set-right->left {DiscSet T S} {⟦ discriminator T S ⟧} (discriminator-disc-set-sup T S) (co-definition {DiscSet T S} {[]} (sub+diverge->has-empty-trace sub div))) input-does-not-win : ∀{T S φ x} (tφ : T HasTrace φ) -> Transitions T (φ ∷ʳ I x) S -> ¬ Win (after tφ) input-does-not-win (_ , _ , refl) (step inp _) () input-does-not-win (_ , def , step inp tr) (step inp sr) w = input-does-not-win (_ , def , tr) sr w input-does-not-win (_ , def , step (out _) tr) (step (out _) sr) w = input-does-not-win (_ , def , tr) sr w ends-with-output->has-trace : ∀{T S φ x} -> Transitions T (φ ∷ʳ O x) S -> T HasTrace (φ ∷ʳ O x) ends-with-output->has-trace tr = _ , output-transitions->defined tr , tr co-trace-swap : ∀{φ ψ} -> co-trace φ ≡ ψ -> φ ≡ co-trace ψ co-trace-swap {φ} eq rewrite sym eq rewrite co-trace-involution φ = refl co-trace-swap-⊑ : ∀{φ ψ} -> co-trace φ ⊑ ψ -> φ ⊑ co-trace ψ co-trace-swap-⊑ {[]} none = none co-trace-swap-⊑ {α ∷ _} (some le) rewrite co-action-involution α = some (co-trace-swap-⊑ le) co-maximal : ∀{X φ} -> φ ∈ Maximal X -> co-trace φ ∈ Maximal (CoSet X) co-maximal {X} (maximal xφ F) = maximal (co-definition {X} xφ) λ le xψ -> let le' = co-trace-swap-⊑ le in let eq = F le' xψ in co-trace-swap eq co-maximal-2 : ∀{X φ} -> co-trace φ ∈ Maximal (CoSet X) -> φ ∈ Maximal X co-maximal-2 {X} (maximal wit F) = maximal (co-inversion {X} wit) λ le xψ -> let le' = ⊑-co-trace le in let eq = F le' (co-definition {X} xψ) in co-trace-injective eq co-trace->co-set : ∀{X φ} -> co-trace φ ∈ Maximal X -> φ ∈ Maximal (CoSet X) co-trace->co-set {_} {φ} cxφ with co-maximal cxφ ... | res rewrite co-trace-involution φ = res discriminator-after-sync->defined : ∀{R T S T' φ} -> T <: S -> (rdef : Defined (discriminator T S)) (rr : Transitions (discriminator T S) (co-trace φ) R) (tr : Transitions T φ T') -> Defined R discriminator-after-sync->defined {R} {T} {S} sub rdef rr tr with Defined? R ... | yes rdef' = rdef' ... | no nrdef' with defined-becomes-nil rdef nrdef' rr ... | ψ , x , eq , rψ , nrφ rewrite eq with input-does-not-win rψ rr ... | nwin with contraposition (decode+maximal->win (co-semantics (disc-set->semantics T S)) rψ) nwin ... | ncψ with decode-sub (co-semantics (disc-set->semantics T S)) rψ ... | dsψ with contraposition (disc-set-maximal-1 dsψ) (contraposition co-trace->co-set ncψ) ... | nnsψ with has-trace-double-negation nnsψ ... | sψ with (let tr' = subst (λ z -> Transitions _ z _) (co-trace-swap eq) tr in let tr'' = subst (λ z -> Transitions _ z _) (co-trace-++ ψ (I x ∷ [])) tr' in ends-with-output->has-trace tr'') ... | tψ with disc-set-has-outputs sub dsψ tψ sψ ... | dsφ with decode-sup (co-semantics (disc-set->semantics T S)) (co-definition {DiscSet T S} dsφ) ... | rφ = let rφ' = subst (_ HasTrace_) (co-trace-++ (co-trace ψ) (O x ∷ [])) rφ in let rφ'' = subst (λ z -> _ HasTrace (z ++ _)) (co-trace-involution ψ) rφ' in ⊥-elim (nrφ rφ'') after-trace-defined : ∀{T T' φ} -> T HasTrace φ -> Transitions T φ T' -> Defined T' after-trace-defined (_ , def , refl) refl = def after-trace-defined (_ , def , step inp tr) (step inp sr) = after-trace-defined (_ , def , tr) sr after-trace-defined (_ , def , step (out _) tr) (step (out _) sr) = after-trace-defined (_ , def , tr) sr after-trace-defined-2 : ∀{T φ} (tφ : T HasTrace φ) -> Defined (after tφ) after-trace-defined-2 (_ , def , _) = def ⊑-after : ∀{φ ψ} -> φ ⊑ ψ -> Trace ⊑-after {_} {ψ} none = ψ ⊑-after (some le) = ⊑-after le ⊑-after-co-trace : ∀{φ ψ} (le : φ ⊑ ψ) -> ⊑-after (⊑-co-trace le) ≡ co-trace (⊑-after le) ⊑-after-co-trace none = refl ⊑-after-co-trace (some le) = ⊑-after-co-trace le extend-transitions : ∀{T S φ ψ} (le : φ ⊑ ψ) (tr : Transitions T φ S) (tψ : T HasTrace ψ) -> Transitions S (⊑-after le) (after tψ) extend-transitions none refl (_ , _ , sr) = sr extend-transitions (some le) (step inp tr) (_ , sdef , step inp sr) = extend-transitions le tr (_ , sdef , sr) extend-transitions (some le) (step (out _) tr) (_ , sdef , step (out _) sr) = extend-transitions le tr (_ , sdef , sr) discriminator-compliant : ∀{T S} -> T <: S -> T ↑ S -> FairComplianceS (discriminator T S # T) discriminator-compliant {T} {S} sub div {R' # T'} reds with unzip-red* reds ... | φ , rr , tr with sub+diverge->discriminator-defined sub div | sub+diverge->defined sub div ... | rdef | tdef , sdef with discriminator-after-sync->defined sub rdef rr tr ... | rdef' with decode-sub (co-semantics (disc-set->semantics T S)) (_ , rdef' , rr) ... | dsφ rewrite co-trace-involution φ = case completion sub dsφ of λ { (inj₁ (ψ , lt , cψ@(maximal dsψ _))) -> let rψ = decode-sup (co-semantics (disc-set->semantics T S)) (co-definition {DiscSet T S} dsψ) in let tψ = disc-set-subset dsψ in let rr' = subst (λ z -> Transitions _ z _) (⊑-after-co-trace (⊏->⊑ lt)) (extend-transitions (⊑-co-trace (⊏->⊑ lt)) rr rψ) in let tr' = extend-transitions (⊏->⊑ lt) tr tψ in let winr = decode+maximal->win (co-semantics (disc-set->semantics T S)) rψ (co-maximal cψ) in let reds' = zip-red* rr' tr' in _ , reds' , win#def winr (after-trace-defined-2 tψ) ; (inj₂ (cφ , nsφ)) -> let winr = decode+maximal->win (co-semantics (disc-set->semantics T S)) (_ , rdef' , rr) (co-maximal cφ) in _ , ε , win#def winr (after-trace-defined (disc-set-subset dsφ) tr) } discriminator-not-compliant : ∀{T S} -> T <: S -> T ↑ S -> ¬ FairComplianceS (discriminator T S # S) discriminator-not-compliant {T} {S} sub div comp with comp ε ... | _ , reds , win#def w def with unzip-red* reds ... | φ , rr , sr with decode+win->maximal (co-semantics (disc-set->semantics T S)) (_ , win->defined w , rr) w ... | cφ with co-maximal-2 {DiscSet T S} cφ ... | csφ with disc-set-maximal-2 sub csφ ... | nsφ = nsφ (_ , def , sr)
algebraic-stack_agda0000_doc_17159
------------------------------------------------------------------------ -- A type for values that should be erased at run-time ------------------------------------------------------------------------ -- Most of the definitions in this module are reexported, in one way -- or another, from Erased. -- This module imports Function-universe, but not Equivalence.Erased. {-# OPTIONS --without-K --safe #-} open import Equality module Erased.Level-1 {e⁺} (eq-J : ∀ {a p} → Equality-with-J a p e⁺) where open Derived-definitions-and-properties eq-J hiding (module Extensionality) open import Logical-equivalence using (_⇔_) open import Prelude hiding ([_,_]) open import Bijection eq-J as Bijection using (_↔_; Has-quasi-inverse) open import Embedding eq-J as Emb using (Embedding; Is-embedding) open import Equality.Decidable-UIP eq-J open import Equivalence eq-J as Eq using (_≃_; Is-equivalence) import Equivalence.Contractible-preimages eq-J as CP open import Equivalence.Erased.Basics eq-J as EEq using (_≃ᴱ_; Is-equivalenceᴱ) open import Equivalence-relation eq-J open import Function-universe eq-J as F hiding (id; _∘_) open import H-level eq-J as H-level open import H-level.Closure eq-J open import Injection eq-J using (_↣_; Injective) open import Monad eq-J hiding (map; map-id; map-∘) open import Preimage eq-J using (_⁻¹_) open import Surjection eq-J as Surjection using (_↠_; Split-surjective) open import Univalence-axiom eq-J as U using (≡⇒→; _²/≡) private variable a b c d ℓ ℓ₁ ℓ₂ q r : Level A B : Type a eq k k′ p x y : A P : A → Type p f g : A → B n : ℕ ------------------------------------------------------------------------ -- Some basic definitions open import Erased.Basics public ------------------------------------------------------------------------ -- Stability mutual -- A type A is stable if Erased A implies A. Stable : Type a → Type a Stable = Stable-[ implication ] -- A generalisation of Stable. Stable-[_] : Kind → Type a → Type a Stable-[ k ] A = Erased A ↝[ k ] A -- A variant of Stable-[ equivalence ]. Very-stable : Type a → Type a Very-stable A = Is-equivalence [ A ∣_]→ -- A variant of Stable-[ equivalenceᴱ ]. Very-stableᴱ : Type a → Type a Very-stableᴱ A = Is-equivalenceᴱ [ A ∣_]→ -- Variants of the definitions above for equality. Stable-≡ : Type a → Type a Stable-≡ = For-iterated-equality 1 Stable Stable-≡-[_] : Kind → Type a → Type a Stable-≡-[ k ] = For-iterated-equality 1 Stable-[ k ] Very-stable-≡ : Type a → Type a Very-stable-≡ = For-iterated-equality 1 Very-stable Very-stableᴱ-≡ : Type a → Type a Very-stableᴱ-≡ = For-iterated-equality 1 Very-stableᴱ ------------------------------------------------------------------------ -- Erased is a monad -- A universe-polymorphic variant of bind. infixl 5 _>>=′_ _>>=′_ : {@0 A : Type a} {@0 B : Type b} → Erased A → (A → Erased B) → Erased B x >>=′ f = [ erased (f (erased x)) ] instance -- Erased is a monad. raw-monad : Raw-monad (λ (A : Type a) → Erased A) Raw-monad.return raw-monad = [_]→ Raw-monad._>>=_ raw-monad = _>>=′_ monad : Monad (λ (A : Type a) → Erased A) Monad.raw-monad monad = raw-monad Monad.left-identity monad = λ _ _ → refl _ Monad.right-identity monad = λ _ → refl _ Monad.associativity monad = λ _ _ _ → refl _ ------------------------------------------------------------------------ -- Erased preserves some kinds of functions -- Erased is functorial for dependent functions. map-id : {@0 A : Type a} → map id ≡ id {A = Erased A} map-id = refl _ map-∘ : {@0 A : Type a} {@0 P : A → Type b} {@0 Q : {x : A} → P x → Type c} (@0 f : ∀ {x} (y : P x) → Q y) (@0 g : (x : A) → P x) → map (f ∘ g) ≡ map f ∘ map g map-∘ _ _ = refl _ -- Erased preserves logical equivalences. Erased-cong-⇔ : {@0 A : Type a} {@0 B : Type b} → @0 A ⇔ B → Erased A ⇔ Erased B Erased-cong-⇔ A⇔B = record { to = map (_⇔_.to A⇔B) ; from = map (_⇔_.from A⇔B) } -- Erased is functorial for logical equivalences. Erased-cong-⇔-id : {@0 A : Type a} → Erased-cong-⇔ F.id ≡ F.id {A = Erased A} Erased-cong-⇔-id = refl _ Erased-cong-⇔-∘ : {@0 A : Type a} {@0 B : Type b} {@0 C : Type c} (@0 f : B ⇔ C) (@0 g : A ⇔ B) → Erased-cong-⇔ (f F.∘ g) ≡ Erased-cong-⇔ f F.∘ Erased-cong-⇔ g Erased-cong-⇔-∘ _ _ = refl _ -- Erased preserves equivalences with erased proofs. Erased-cong-≃ᴱ : {@0 A : Type a} {@0 B : Type b} → @0 A ≃ᴱ B → Erased A ≃ᴱ Erased B Erased-cong-≃ᴱ A≃ᴱB = EEq.↔→≃ᴱ (map (_≃ᴱ_.to A≃ᴱB)) (map (_≃ᴱ_.from A≃ᴱB)) (cong [_]→ ∘ _≃ᴱ_.right-inverse-of A≃ᴱB ∘ erased) (cong [_]→ ∘ _≃ᴱ_.left-inverse-of A≃ᴱB ∘ erased) ------------------------------------------------------------------------ -- Some isomorphisms -- In an erased context Erased A is always isomorphic to A. Erased↔ : {@0 A : Type a} → Erased (Erased A ↔ A) Erased↔ = [ record { surjection = record { logical-equivalence = record { to = erased ; from = [_]→ } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → refl _ } ] -- The following result is based on a result in Mishra-Linger's PhD -- thesis (see Section 5.4.4). -- Erased (Erased A) is isomorphic to Erased A. Erased-Erased↔Erased : {@0 A : Type a} → Erased (Erased A) ↔ Erased A Erased-Erased↔Erased = record { surjection = record { logical-equivalence = record { to = λ x → [ erased (erased x) ] ; from = [_]→ } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → refl _ } -- Erased ⊤ is isomorphic to ⊤. Erased-⊤↔⊤ : Erased ⊤ ↔ ⊤ Erased-⊤↔⊤ = record { surjection = record { logical-equivalence = record { to = λ _ → tt ; from = [_]→ } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → refl _ } -- Erased ⊥ is isomorphic to ⊥. Erased-⊥↔⊥ : Erased (⊥ {ℓ = ℓ}) ↔ ⊥ {ℓ = ℓ} Erased-⊥↔⊥ = record { surjection = record { logical-equivalence = record { to = λ { [ () ] } ; from = [_]→ } ; right-inverse-of = λ () } ; left-inverse-of = λ { [ () ] } } -- Erased commutes with Π A. Erased-Π↔Π : {@0 P : A → Type p} → Erased ((x : A) → P x) ↔ ((x : A) → Erased (P x)) Erased-Π↔Π = record { surjection = record { logical-equivalence = record { to = λ { [ f ] x → [ f x ] } ; from = λ f → [ (λ x → erased (f x)) ] } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → refl _ } -- A variant of Erased-Π↔Π. Erased-Π≃ᴱΠ : {@0 A : Type a} {@0 P : A → Type p} → Erased ((x : A) → P x) ≃ᴱ ((x : A) → Erased (P x)) Erased-Π≃ᴱΠ = EEq.[≃]→≃ᴱ (EEq.[proofs] $ from-isomorphism Erased-Π↔Π) -- Erased commutes with Π. Erased-Π↔Π-Erased : {@0 A : Type a} {@0 P : A → Type p} → Erased ((x : A) → P x) ↔ ((x : Erased A) → Erased (P (erased x))) Erased-Π↔Π-Erased = record { surjection = record { logical-equivalence = record { to = λ ([ f ]) → map f ; from = λ f → [ (λ x → erased (f [ x ])) ] } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → refl _ } -- Erased commutes with Σ. Erased-Σ↔Σ : {@0 A : Type a} {@0 P : A → Type p} → Erased (Σ A P) ↔ Σ (Erased A) (λ x → Erased (P (erased x))) Erased-Σ↔Σ = record { surjection = record { logical-equivalence = record { to = λ { [ p ] → [ proj₁ p ] , [ proj₂ p ] } ; from = λ { ([ x ] , [ y ]) → [ x , y ] } } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → refl _ } -- Erased commutes with ↑ ℓ. Erased-↑↔↑ : {@0 A : Type a} → Erased (↑ ℓ A) ↔ ↑ ℓ (Erased A) Erased-↑↔↑ = record { surjection = record { logical-equivalence = record { to = λ { [ x ] → lift [ lower x ] } ; from = λ { (lift [ x ]) → [ lift x ] } } ; right-inverse-of = λ _ → refl _ } ; left-inverse-of = λ _ → refl _ } -- Erased commutes with ¬_ (assuming extensionality). Erased-¬↔¬ : {@0 A : Type a} → Erased (¬ A) ↝[ a ∣ lzero ] ¬ Erased A Erased-¬↔¬ {A = A} ext = Erased (A → ⊥) ↔⟨ Erased-Π↔Π-Erased ⟩ (Erased A → Erased ⊥) ↝⟨ (∀-cong ext λ _ → from-isomorphism Erased-⊥↔⊥) ⟩□ (Erased A → ⊥) □ -- Erased can be dropped under ¬_ (assuming extensionality). ¬-Erased↔¬ : {A : Type a} → ¬ Erased A ↝[ a ∣ lzero ] ¬ A ¬-Erased↔¬ {a = a} {A = A} = generalise-ext?-prop (record { to = λ ¬[a] a → ¬[a] [ a ] ; from = λ ¬a ([ a ]) → _↔_.to Erased-⊥↔⊥ [ ¬a a ] }) ¬-propositional ¬-propositional -- The following three results are inspired by a result in -- Mishra-Linger's PhD thesis (see Section 5.4.1). -- -- See also Π-Erased↔Π0[], Π-Erased≃Π0[], Π-Erased↔Π0 and Π-Erased≃Π0 -- in Erased.Cubical and Erased.With-K. -- There is a logical equivalence between -- (x : Erased A) → P (erased x) and (@0 x : A) → P x. Π-Erased⇔Π0 : {@0 A : Type a} {@0 P : A → Type p} → ((x : Erased A) → P (erased x)) ⇔ ((@0 x : A) → P x) Π-Erased⇔Π0 = record { to = λ f x → f [ x ] ; from = λ f ([ x ]) → f x } -- There is an equivalence with erased proofs between -- (x : Erased A) → P (erased x) and (@0 x : A) → P x. Π-Erased≃ᴱΠ0 : {@0 A : Type a} {@0 P : A → Type p} → ((x : Erased A) → P (erased x)) ≃ᴱ ((@0 x : A) → P x) Π-Erased≃ᴱΠ0 = EEq.↔→≃ᴱ (_⇔_.to Π-Erased⇔Π0) (_⇔_.from Π-Erased⇔Π0) refl refl -- There is an equivalence between (x : Erased A) → P (erased x) and -- (@0 x : A) → P x. Π-Erased≃Π0 : {@0 A : Type a} {P : @0 A → Type p} → ((x : Erased A) → P (erased x)) ≃ ((@0 x : A) → P x) Π-Erased≃Π0 {A = A} {P = P} = Eq.↔→≃ {B = (@0 x : A) → P x} (_⇔_.to Π-Erased⇔Π0) (_⇔_.from Π-Erased⇔Π0) (λ _ → refl {A = (@0 x : A) → P x} _) (λ _ → refl _) -- A variant of Π-Erased≃Π0. Π-Erased≃Π0[] : {@0 A : Type a} {P : Erased A → Type p} → ((x : Erased A) → P x) ≃ ((@0 x : A) → P [ x ]) Π-Erased≃Π0[] = Π-Erased≃Π0 -- Erased commutes with W up to logical equivalence. Erased-W⇔W : {@0 A : Type a} {@0 P : A → Type p} → Erased (W A P) ⇔ W (Erased A) (λ x → Erased (P (erased x))) Erased-W⇔W {A = A} {P = P} = record { to = to; from = from } where to : Erased (W A P) → W (Erased A) (λ x → Erased (P (erased x))) to [ sup x f ] = sup [ x ] (λ ([ y ]) → to [ f y ]) from : W (Erased A) (λ x → Erased (P (erased x))) → Erased (W A P) from (sup [ x ] f) = [ sup x (λ y → erased (from (f [ y ]))) ] ---------------------------------------------------------------------- -- Erased is a modality -- Erased is the modal operator of a uniquely eliminating modality -- with [_]→ as the modal unit. -- -- The terminology here roughly follows that of "Modalities in -- Homotopy Type Theory" by Rijke, Shulman and Spitters. uniquely-eliminating-modality : {@0 P : Erased A → Type p} → Is-equivalence (λ (f : (x : Erased A) → Erased (P x)) → f ∘ [ A ∣_]→) uniquely-eliminating-modality {A = A} {P = P} = _≃_.is-equivalence (((x : Erased A) → Erased (P x)) ↔⟨ inverse Erased-Π↔Π-Erased ⟩ Erased ((x : A) → (P [ x ])) ↔⟨ Erased-Π↔Π ⟩ ((x : A) → Erased (P [ x ])) □) -- Two results that are closely related to -- uniquely-eliminating-modality. -- -- These results are based on the Coq source code accompanying -- "Modalities in Homotopy Type Theory" by Rijke, Shulman and -- Spitters. -- Precomposition with [_]→ is injective for functions from Erased A -- to Erased B. ∘-[]-injective : {@0 B : Type b} → Injective (λ (f : Erased A → Erased B) → f ∘ [_]→) ∘-[]-injective = _≃_.injective Eq.⟨ _ , uniquely-eliminating-modality ⟩ -- A rearrangement lemma for ext⁻¹ and ∘-[]-injective. ext⁻¹-∘-[]-injective : {@0 B : Type b} {f g : Erased A → Erased B} {p : f ∘ [_]→ ≡ g ∘ [_]→} → ext⁻¹ (∘-[]-injective {x = f} {y = g} p) [ x ] ≡ ext⁻¹ p x ext⁻¹-∘-[]-injective {x = x} {f = f} {g = g} {p = p} = ext⁻¹ (∘-[]-injective p) [ x ] ≡⟨ elim₁ (λ p → ext⁻¹ p [ x ] ≡ ext⁻¹ (_≃_.from equiv p) x) ( ext⁻¹ (refl g) [ x ] ≡⟨ cong-refl (_$ [ x ]) ⟩ refl (g [ x ]) ≡⟨ sym $ cong-refl _ ⟩ ext⁻¹ (refl (g ∘ [_]→)) x ≡⟨ cong (λ p → ext⁻¹ p x) $ sym $ cong-refl _ ⟩∎ ext⁻¹ (_≃_.from equiv (refl g)) x ∎) (∘-[]-injective p) ⟩ ext⁻¹ (_≃_.from equiv (∘-[]-injective p)) x ≡⟨ cong (flip ext⁻¹ x) $ _≃_.left-inverse-of equiv _ ⟩∎ ext⁻¹ p x ∎ where equiv = Eq.≃-≡ Eq.⟨ _ , uniquely-eliminating-modality ⟩ ---------------------------------------------------------------------- -- Some lemmas related to functions with erased domains -- A variant of H-level.Π-closure for function spaces with erased -- explicit domains. Note the type of P. Πᴱ-closure : {@0 A : Type a} {P : @0 A → Type p} → Extensionality a p → ∀ n → ((@0 x : A) → H-level n (P x)) → H-level n ((@0 x : A) → P x) Πᴱ-closure {P = P} ext n = (∀ (@0 x) → H-level n (P x)) →⟨ Eq._≃₀_.from Π-Erased≃Π0 ⟩ (∀ x → H-level n (P (x .erased))) →⟨ Π-closure ext n ⟩ H-level n (∀ x → P (x .erased)) →⟨ H-level-cong {B = ∀ (@0 x) → P x} _ n Π-Erased≃Π0 ⟩□ H-level n (∀ (@0 x) → P x) □ -- A variant of H-level.Π-closure for function spaces with erased -- implicit domains. Note the type of P. implicit-Πᴱ-closure : {@0 A : Type a} {P : @0 A → Type p} → Extensionality a p → ∀ n → ((@0 x : A) → H-level n (P x)) → H-level n ({@0 x : A} → P x) implicit-Πᴱ-closure {A = A} {P = P} ext n = (∀ (@0 x) → H-level n (P x)) →⟨ Πᴱ-closure ext n ⟩ H-level n (∀ (@0 x) → P x) →⟨ H-level-cong {A = ∀ (@0 x) → P x} {B = ∀ {@0 x} → P x} _ n $ inverse {A = ∀ {@0 x} → P x} {B = ∀ (@0 x) → P x} Bijection.implicit-Πᴱ↔Πᴱ′ ⟩□ H-level n (∀ {@0 x} → P x) □ -- Extensionality implies extensionality for some functions with -- erased arguments (note the type of P). apply-extᴱ : {@0 A : Type a} {P : @0 A → Type p} {f g : (@0 x : A) → P x} → Extensionality a p → ((@0 x : A) → f x ≡ g x) → f ≡ g apply-extᴱ {A = A} {P = P} {f = f} {g = g} ext = ((@0 x : A) → f x ≡ g x) →⟨ Eq._≃₀_.from Π-Erased≃Π0 ⟩ ((x : Erased A) → f (x .erased) ≡ g (x .erased)) →⟨ apply-ext ext ⟩ (λ x → f (x .erased)) ≡ (λ x → g (x .erased)) →⟨ cong {B = (@0 x : A) → P x} (Eq._≃₀_.to Π-Erased≃Π0) ⟩□ f ≡ g □ -- Extensionality implies extensionality for some functions with -- implicit erased arguments (note the type of P). implicit-apply-extᴱ : {@0 A : Type a} {P : @0 A → Type p} {f g : {@0 x : A} → P x} → Extensionality a p → ((@0 x : A) → f {x = x} ≡ g {x = x}) → _≡_ {A = {@0 x : A} → P x} f g implicit-apply-extᴱ {A = A} {P = P} {f = f} {g = g} ext = ((@0 x : A) → f {x = x} ≡ g {x = x}) →⟨ apply-extᴱ ext ⟩ _≡_ {A = (@0 x : A) → P x} (λ x → f {x = x}) (λ x → g {x = x}) →⟨ cong {A = (@0 x : A) → P x} {B = {@0 x : A} → P x} (λ f {x = x} → f x) ⟩□ _≡_ {A = {@0 x : A} → P x} f g □ ------------------------------------------------------------------------ -- A variant of Dec ∘ Erased -- Dec-Erased A means that either we have A (erased), or we have ¬ A -- (also erased). Dec-Erased : @0 Type ℓ → Type ℓ Dec-Erased A = Erased A ⊎ Erased (¬ A) -- Dec A implies Dec-Erased A. Dec→Dec-Erased : {@0 A : Type a} → Dec A → Dec-Erased A Dec→Dec-Erased (yes a) = yes [ a ] Dec→Dec-Erased (no ¬a) = no [ ¬a ] -- In erased contexts Dec-Erased A is equivalent to Dec A. @0 Dec-Erased≃Dec : {@0 A : Type a} → Dec-Erased A ≃ Dec A Dec-Erased≃Dec {A = A} = Eq.with-other-inverse (Erased A ⊎ Erased (¬ A) ↔⟨ erased Erased↔ ⊎-cong erased Erased↔ ⟩□ A ⊎ ¬ A □) Dec→Dec-Erased Prelude.[ (λ _ → refl _) , (λ _ → refl _) ] -- Dec-Erased A is isomorphic to Dec (Erased A) (assuming -- extensionality). Dec-Erased↔Dec-Erased : {@0 A : Type a} → Dec-Erased A ↝[ a ∣ lzero ] Dec (Erased A) Dec-Erased↔Dec-Erased {A = A} ext = Erased A ⊎ Erased (¬ A) ↝⟨ F.id ⊎-cong Erased-¬↔¬ ext ⟩□ Erased A ⊎ ¬ Erased A □ -- A map function for Dec-Erased. Dec-Erased-map : {@0 A : Type a} {@0 B : Type b} → @0 A ⇔ B → Dec-Erased A → Dec-Erased B Dec-Erased-map A⇔B = ⊎-map (map (_⇔_.to A⇔B)) (map (_∘ _⇔_.from A⇔B)) -- Dec-Erased preserves logical equivalences. Dec-Erased-cong-⇔ : {@0 A : Type a} {@0 B : Type b} → @0 A ⇔ B → Dec-Erased A ⇔ Dec-Erased B Dec-Erased-cong-⇔ A⇔B = record { to = Dec-Erased-map A⇔B ; from = Dec-Erased-map (inverse A⇔B) } -- If A and B are decided (with erased proofs), then A × B is. Dec-Erased-× : {@0 A : Type a} {@0 B : Type b} → Dec-Erased A → Dec-Erased B → Dec-Erased (A × B) Dec-Erased-× (no [ ¬a ]) _ = no [ ¬a ∘ proj₁ ] Dec-Erased-× _ (no [ ¬b ]) = no [ ¬b ∘ proj₂ ] Dec-Erased-× (yes [ a ]) (yes [ b ]) = yes [ a , b ] -- If A and B are decided (with erased proofs), then A ⊎ B is. Dec-Erased-⊎ : {@0 A : Type a} {@0 B : Type b} → Dec-Erased A → Dec-Erased B → Dec-Erased (A ⊎ B) Dec-Erased-⊎ (yes [ a ]) _ = yes [ inj₁ a ] Dec-Erased-⊎ (no [ ¬a ]) (yes [ b ]) = yes [ inj₂ b ] Dec-Erased-⊎ (no [ ¬a ]) (no [ ¬b ]) = no [ Prelude.[ ¬a , ¬b ] ] -- A variant of Equality.Decision-procedures.×.dec⇒dec⇒dec. dec-erased⇒dec-erased⇒×-dec-erased : {@0 A : Type a} {@0 B : Type b} {@0 x₁ x₂ : A} {@0 y₁ y₂ : B} → Dec-Erased (x₁ ≡ x₂) → Dec-Erased (y₁ ≡ y₂) → Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂)) dec-erased⇒dec-erased⇒×-dec-erased = λ where (no [ x₁≢x₂ ]) _ → no [ x₁≢x₂ ∘ cong proj₁ ] _ (no [ y₁≢y₂ ]) → no [ y₁≢y₂ ∘ cong proj₂ ] (yes [ x₁≡x₂ ]) (yes [ y₁≡y₂ ]) → yes [ cong₂ _,_ x₁≡x₂ y₁≡y₂ ] -- A variant of Equality.Decision-procedures.Σ.set⇒dec⇒dec⇒dec. -- -- See also set⇒dec-erased⇒dec-erased⇒Σ-dec-erased below. set⇒dec⇒dec-erased⇒Σ-dec-erased : {@0 A : Type a} {@0 P : A → Type p} {@0 x₁ x₂ : A} {@0 y₁ : P x₁} {@0 y₂ : P x₂} → @0 Is-set A → Dec (x₁ ≡ x₂) → (∀ eq → Dec-Erased (subst P eq y₁ ≡ y₂)) → Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂)) set⇒dec⇒dec-erased⇒Σ-dec-erased _ (no x₁≢x₂) _ = no [ x₁≢x₂ ∘ cong proj₁ ] set⇒dec⇒dec-erased⇒Σ-dec-erased {P = P} {y₁ = y₁} {y₂ = y₂} set₁ (yes x₁≡x₂) dec₂ = ⊎-map (map (Σ-≡,≡→≡ x₁≡x₂)) (map λ cast-y₁≢y₂ eq → $⟨ proj₂ (Σ-≡,≡←≡ eq) ⟩ subst P (proj₁ (Σ-≡,≡←≡ eq)) y₁ ≡ y₂ ↝⟨ subst (λ p → subst _ p _ ≡ _) (set₁ _ _) ⟩ subst P x₁≡x₂ y₁ ≡ y₂ ↝⟨ cast-y₁≢y₂ ⟩□ ⊥ □) (dec₂ x₁≡x₂) -- A variant of Equality.Decision-procedures.Σ.decidable⇒dec⇒dec. -- -- See also decidable-erased⇒dec-erased⇒Σ-dec-erased below. decidable⇒dec-erased⇒Σ-dec-erased : {@0 A : Type a} {@0 P : A → Type p} {x₁ x₂ : A} {@0 y₁ : P x₁} {@0 y₂ : P x₂} → Decidable-equality A → (∀ eq → Dec-Erased (subst P eq y₁ ≡ y₂)) → Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂)) decidable⇒dec-erased⇒Σ-dec-erased dec = set⇒dec⇒dec-erased⇒Σ-dec-erased (decidable⇒set dec) (dec _ _) ------------------------------------------------------------------------ -- Decidable erased equality -- A variant of Decidable-equality that is defined using Dec-Erased. Decidable-erased-equality : Type ℓ → Type ℓ Decidable-erased-equality A = (x y : A) → Dec-Erased (x ≡ y) -- Decidable equality implies decidable erased equality. Decidable-equality→Decidable-erased-equality : {@0 A : Type a} → Decidable-equality A → Decidable-erased-equality A Decidable-equality→Decidable-erased-equality dec x y = Dec→Dec-Erased (dec x y) -- In erased contexts Decidable-erased-equality A is equivalent to -- Decidable-equality A (assuming extensionality). @0 Decidable-erased-equality≃Decidable-equality : {A : Type a} → Decidable-erased-equality A ↝[ a ∣ a ] Decidable-equality A Decidable-erased-equality≃Decidable-equality {A = A} ext = ((x y : A) → Dec-Erased (x ≡ y)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → from-equivalence Dec-Erased≃Dec) ⟩□ ((x y : A) → Dec (x ≡ y)) □ -- A map function for Decidable-erased-equality. Decidable-erased-equality-map : A ↠ B → Decidable-erased-equality A → Decidable-erased-equality B Decidable-erased-equality-map A↠B _≟_ x y = $⟨ _↠_.from A↠B x ≟ _↠_.from A↠B y ⟩ Dec-Erased (_↠_.from A↠B x ≡ _↠_.from A↠B y) ↝⟨ Dec-Erased-map (_↠_.logical-equivalence $ Surjection.↠-≡ A↠B) ⟩□ Dec-Erased (x ≡ y) □ -- A variant of Equality.Decision-procedures.×.Dec._≟_. decidable-erased⇒decidable-erased⇒×-decidable-erased : {@0 A : Type a} {@0 B : Type b} → Decidable-erased-equality A → Decidable-erased-equality B → Decidable-erased-equality (A × B) decidable-erased⇒decidable-erased⇒×-decidable-erased decA decB _ _ = dec-erased⇒dec-erased⇒×-dec-erased (decA _ _) (decB _ _) -- A variant of Equality.Decision-procedures.Σ.Dec._≟_. -- -- See also decidable-erased⇒decidable-erased⇒Σ-decidable-erased -- below. decidable⇒decidable-erased⇒Σ-decidable-erased : Decidable-equality A → ({x : A} → Decidable-erased-equality (P x)) → Decidable-erased-equality (Σ A P) decidable⇒decidable-erased⇒Σ-decidable-erased {P = P} decA decP (_ , x₂) (_ , y₂) = decidable⇒dec-erased⇒Σ-dec-erased decA (λ eq → decP (subst P eq x₂) y₂) ------------------------------------------------------------------------ -- Erased binary relations -- Lifts binary relations from A to Erased A. Erasedᴾ : {@0 A : Type a} {@0 B : Type b} → @0 (A → B → Type r) → (Erased A → Erased B → Type r) Erasedᴾ R [ x ] [ y ] = Erased (R x y) -- Erasedᴾ preserves Is-equivalence-relation. Erasedᴾ-preserves-Is-equivalence-relation : {@0 A : Type a} {@0 R : A → A → Type r} → @0 Is-equivalence-relation R → Is-equivalence-relation (Erasedᴾ R) Erasedᴾ-preserves-Is-equivalence-relation equiv = λ where .Is-equivalence-relation.reflexive → [ equiv .Is-equivalence-relation.reflexive ] .Is-equivalence-relation.symmetric → map (equiv .Is-equivalence-relation.symmetric) .Is-equivalence-relation.transitive → zip (equiv .Is-equivalence-relation.transitive) ------------------------------------------------------------------------ -- Some results that hold in erased contexts -- In an erased context there is an equivalence between equality of -- "boxed" values and equality of values. @0 []≡[]≃≡ : ([ x ] ≡ [ y ]) ≃ (x ≡ y) []≡[]≃≡ = Eq.↔⇒≃ (record { surjection = record { logical-equivalence = record { to = cong erased ; from = cong [_]→ } ; right-inverse-of = λ eq → cong erased (cong [_]→ eq) ≡⟨ cong-∘ _ _ _ ⟩ cong id eq ≡⟨ sym $ cong-id _ ⟩∎ eq ∎ } ; left-inverse-of = λ eq → cong [_]→ (cong erased eq) ≡⟨ cong-∘ _ _ _ ⟩ cong id eq ≡⟨ sym $ cong-id _ ⟩∎ eq ∎ }) -- In an erased context [_]→ is always an embedding. Erased-Is-embedding-[] : {@0 A : Type a} → Erased (Is-embedding [ A ∣_]→) Erased-Is-embedding-[] = [ (λ x y → _≃_.is-equivalence ( x ≡ y ↝⟨ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ $ inverse $ erased Erased↔ ⟩□ [ x ] ≡ [ y ] □)) ] -- In an erased context [_]→ is always split surjective. Erased-Split-surjective-[] : {@0 A : Type a} → Erased (Split-surjective [ A ∣_]→) Erased-Split-surjective-[] = [ (λ ([ x ]) → x , refl _) ] ------------------------------------------------------------------------ -- []-cong-axiomatisation -- An axiomatisation for []-cong. -- -- In addition to the results in this section, see -- []-cong-axiomatisation-propositional below. record []-cong-axiomatisation a : Type (lsuc a) where field []-cong : {@0 A : Type a} {@0 x y : A} → Erased (x ≡ y) → [ x ] ≡ [ y ] []-cong-equivalence : {@0 A : Type a} {@0 x y : A} → Is-equivalence ([]-cong {x = x} {y = y}) []-cong-[refl] : {@0 A : Type a} {@0 x : A} → []-cong [ refl x ] ≡ refl [ x ] -- The []-cong axioms can be instantiated in erased contexts. @0 erased-instance-of-[]-cong-axiomatisation : []-cong-axiomatisation a erased-instance-of-[]-cong-axiomatisation .[]-cong-axiomatisation.[]-cong = cong [_]→ ∘ erased erased-instance-of-[]-cong-axiomatisation .[]-cong-axiomatisation.[]-cong-equivalence {x = x} {y = y} = _≃_.is-equivalence (Erased (x ≡ y) ↔⟨ erased Erased↔ ⟩ x ≡ y ↝⟨ inverse []≡[]≃≡ ⟩□ [ x ] ≡ [ y ] □) erased-instance-of-[]-cong-axiomatisation .[]-cong-axiomatisation.[]-cong-[refl] {x = x} = cong [_]→ (erased [ refl x ]) ≡⟨⟩ cong [_]→ (refl x) ≡⟨ cong-refl _ ⟩∎ refl [ x ] ∎ -- If the []-cong axioms can be implemented for a certain universe -- level, then they can also be implemented for all smaller universe -- levels. lower-[]-cong-axiomatisation : ∀ a′ → []-cong-axiomatisation (a ⊔ a′) → []-cong-axiomatisation a lower-[]-cong-axiomatisation {a = a} a′ ax = λ where .[]-cong-axiomatisation.[]-cong → []-cong′ .[]-cong-axiomatisation.[]-cong-equivalence → []-cong′-equivalence .[]-cong-axiomatisation.[]-cong-[refl] → []-cong′-[refl] where open []-cong-axiomatisation ax lemma : {@0 A : Type a} {@0 x y : A} → Erased (lift {ℓ = a′} x ≡ lift y) ≃ ([ x ] ≡ [ y ]) lemma {x = x} {y = y} = Erased (lift {ℓ = a′} x ≡ lift y) ↝⟨ Eq.⟨ _ , []-cong-equivalence ⟩ ⟩ [ lift x ] ≡ [ lift y ] ↝⟨ inverse $ Eq.≃-≡ (Eq.↔→≃ (map lower) (map lift) refl refl) ⟩□ [ x ] ≡ [ y ] □ []-cong′ : {@0 A : Type a} {@0 x y : A} → Erased (x ≡ y) → [ x ] ≡ [ y ] []-cong′ {x = x} {y = y} = Erased (x ≡ y) ↝⟨ map (cong lift) ⟩ Erased (lift {ℓ = a′} x ≡ lift y) ↔⟨ lemma ⟩□ [ x ] ≡ [ y ] □ []-cong′-equivalence : {@0 A : Type a} {@0 x y : A} → Is-equivalence ([]-cong′ {x = x} {y = y}) []-cong′-equivalence {x = x} {y = y} = _≃_.is-equivalence (Erased (x ≡ y) ↝⟨ Eq.↔→≃ (map (cong lift)) (map (cong lower)) (λ ([ eq ]) → [ cong lift (cong lower eq) ] ≡⟨ []-cong [ cong-∘ _ _ _ ] ⟩ [ cong id eq ] ≡⟨ []-cong [ sym $ cong-id _ ] ⟩∎ [ eq ] ∎) (λ ([ eq ]) → [ cong lower (cong lift eq) ] ≡⟨ []-cong′ [ cong-∘ _ _ _ ] ⟩ [ cong id eq ] ≡⟨ []-cong′ [ sym $ cong-id _ ] ⟩∎ [ eq ] ∎) ⟩ Erased (lift {ℓ = a′} x ≡ lift y) ↝⟨ lemma ⟩□ [ x ] ≡ [ y ] □) []-cong′-[refl] : {@0 A : Type a} {@0 x : A} → []-cong′ [ refl x ] ≡ refl [ x ] []-cong′-[refl] {x = x} = cong (map lower) ([]-cong [ cong lift (refl x) ]) ≡⟨ cong (cong (map lower) ∘ []-cong) $ []-cong [ cong-refl _ ] ⟩ cong (map lower) ([]-cong [ refl (lift x) ]) ≡⟨ cong (cong (map lower)) []-cong-[refl] ⟩ cong (map lower) (refl [ lift x ]) ≡⟨ cong-refl _ ⟩∎ refl [ x ] ∎ ------------------------------------------------------------------------ -- An alternative to []-cong-axiomatisation -- Stable-≡-Erased-axiomatisation a is the property that equality is -- stable for Erased A, for every erased type A : Type a, along with a -- "computation" rule. Stable-≡-Erased-axiomatisation : (a : Level) → Type (lsuc a) Stable-≡-Erased-axiomatisation a = ∃ λ (Stable-≡-Erased : {@0 A : Type a} → Stable-≡ (Erased A)) → {@0 A : Type a} {x : Erased A} → Stable-≡-Erased x x [ refl x ] ≡ refl x -- Some lemmas used to implement Extensionality→[]-cong as well as -- Erased.Stability.[]-cong-axiomatisation≃Stable-≡-Erased-axiomatisation. module Stable-≡-Erased-axiomatisation→[]-cong-axiomatisation ((Stable-≡-Erased , Stable-≡-Erased-[refl]) : Stable-≡-Erased-axiomatisation a) where -- An implementation of []-cong. []-cong : {@0 A : Type a} {@0 x y : A} → Erased (x ≡ y) → [ x ] ≡ [ y ] []-cong {x = x} {y = y} = Erased (x ≡ y) ↝⟨ map (cong [_]→) ⟩ Erased ([ x ] ≡ [ y ]) ↝⟨ Stable-≡-Erased _ _ ⟩□ [ x ] ≡ [ y ] □ -- A "computation rule" for []-cong. []-cong-[refl] : {@0 A : Type a} {@0 x : A} → []-cong [ refl x ] ≡ refl [ x ] []-cong-[refl] {x = x} = []-cong [ refl x ] ≡⟨⟩ Stable-≡-Erased _ _ [ cong [_]→ (refl x) ] ≡⟨ cong (Stable-≡-Erased _ _) ([]-cong [ cong-refl _ ]) ⟩ Stable-≡-Erased _ _ [ refl [ x ] ] ≡⟨ Stable-≡-Erased-[refl] ⟩∎ refl [ x ] ∎ -- Equality is very stable for Erased A. Very-stable-≡-Erased : {@0 A : Type a} → Very-stable-≡ (Erased A) Very-stable-≡-Erased x y = _≃_.is-equivalence (Eq.↔⇒≃ (record { surjection = record { logical-equivalence = record { from = Stable-≡-Erased x y } ; right-inverse-of = λ ([ eq ]) → []-cong [ lemma eq ] } ; left-inverse-of = lemma })) where lemma = elim¹ (λ eq → Stable-≡-Erased _ _ [ eq ] ≡ eq) Stable-≡-Erased-[refl] -- The following implementations of functions from Erased-cong -- (below) are restricted to types in Type a (where a is the -- universe level for which extensionality is assumed to hold). module _ {@0 A B : Type a} where Erased-cong-↠ : @0 A ↠ B → Erased A ↠ Erased B Erased-cong-↠ A↠B = record { logical-equivalence = Erased-cong-⇔ (_↠_.logical-equivalence A↠B) ; right-inverse-of = λ { [ x ] → []-cong [ _↠_.right-inverse-of A↠B x ] } } Erased-cong-↔ : @0 A ↔ B → Erased A ↔ Erased B Erased-cong-↔ A↔B = record { surjection = Erased-cong-↠ (_↔_.surjection A↔B) ; left-inverse-of = λ { [ x ] → []-cong [ _↔_.left-inverse-of A↔B x ] } } Erased-cong-≃ : @0 A ≃ B → Erased A ≃ Erased B Erased-cong-≃ A≃B = from-isomorphism (Erased-cong-↔ (from-isomorphism A≃B)) -- []-cong is an equivalence. []-cong-equivalence : {@0 A : Type a} {@0 x y : A} → Is-equivalence ([]-cong {x = x} {y = y}) []-cong-equivalence {x = x} {y = y} = _≃_.is-equivalence ( Erased (x ≡ y) ↝⟨ inverse $ Erased-cong-≃ []≡[]≃≡ ⟩ Erased ([ x ] ≡ [ y ]) ↝⟨ inverse Eq.⟨ _ , Very-stable-≡-Erased _ _ ⟩ ⟩□ [ x ] ≡ [ y ] □) -- The []-cong axioms can be instantiated. instance-of-[]-cong-axiomatisation : []-cong-axiomatisation a instance-of-[]-cong-axiomatisation = record { []-cong = []-cong ; []-cong-equivalence = []-cong-equivalence ; []-cong-[refl] = []-cong-[refl] } ------------------------------------------------------------------------ -- In the presence of function extensionality the []-cong axioms can -- be instantiated -- Some lemmas used to implement -- Extensionality→[]-cong-axiomatisation. module Extensionality→[]-cong-axiomatisation (ext′ : Extensionality a a) where private ext = Eq.good-ext ext′ -- Equality is stable for Erased A. -- -- The proof is based on the proof of Lemma 1.25 in "Modalities in -- Homotopy Type Theory" by Rijke, Shulman and Spitters, and the -- corresponding Coq source code. Stable-≡-Erased : {@0 A : Type a} → Stable-≡ (Erased A) Stable-≡-Erased x y eq = x ≡⟨ flip ext⁻¹ eq ( (λ (_ : Erased (x ≡ y)) → x) ≡⟨ ∘-[]-injective ( (λ (_ : x ≡ y) → x) ≡⟨ apply-ext ext (λ (eq : x ≡ y) → x ≡⟨ eq ⟩∎ y ∎) ⟩∎ (λ (_ : x ≡ y) → y) ∎) ⟩∎ (λ (_ : Erased (x ≡ y)) → y) ∎) ⟩∎ y ∎ -- A "computation rule" for Stable-≡-Erased. Stable-≡-Erased-[refl] : {@0 A : Type a} {x : Erased A} → Stable-≡-Erased x x [ refl x ] ≡ refl x Stable-≡-Erased-[refl] {x = [ x ]} = Stable-≡-Erased [ x ] [ x ] [ refl [ x ] ] ≡⟨⟩ ext⁻¹ (∘-[]-injective (apply-ext ext id)) [ refl [ x ] ] ≡⟨ ext⁻¹-∘-[]-injective ⟩ ext⁻¹ (apply-ext ext id) (refl [ x ]) ≡⟨ cong (_$ refl _) $ _≃_.left-inverse-of (Eq.extensionality-isomorphism ext′) _ ⟩∎ refl [ x ] ∎ open Stable-≡-Erased-axiomatisation→[]-cong-axiomatisation (Stable-≡-Erased , Stable-≡-Erased-[refl]) public -- If we have extensionality, then []-cong can be implemented. -- -- The idea for this result comes from "Modalities in Homotopy Type -- Theory" in which Rijke, Shulman and Spitters state that []-cong can -- be implemented for every modality, and that it is an equivalence -- for lex modalities (Theorem 3.1 (ix)). Extensionality→[]-cong-axiomatisation : Extensionality a a → []-cong-axiomatisation a Extensionality→[]-cong-axiomatisation ext = instance-of-[]-cong-axiomatisation where open Extensionality→[]-cong-axiomatisation ext ------------------------------------------------------------------------ -- A variant of []-cong-axiomatisation -- A variant of []-cong-axiomatisation where some erased arguments -- have been replaced with non-erased ones. record []-cong-axiomatisation′ a : Type (lsuc a) where field []-cong : {A : Type a} {x y : A} → Erased (x ≡ y) → [ x ] ≡ [ y ] []-cong-equivalence : Is-equivalence ([]-cong {x = x} {y = y}) []-cong-[refl] : []-cong [ refl x ] ≡ refl [ x ] -- When implementing the []-cong axioms it suffices to prove "weaker" -- variants with fewer erased arguments. -- -- See also -- Erased.Stability.[]-cong-axiomatisation≃[]-cong-axiomatisation′. []-cong-axiomatisation′→[]-cong-axiomatisation : []-cong-axiomatisation′ a → []-cong-axiomatisation a []-cong-axiomatisation′→[]-cong-axiomatisation {a = a} ax = record { []-cong = []-cong₀ ; []-cong-equivalence = []-cong₀-equivalence ; []-cong-[refl] = []-cong₀-[refl] } where open []-cong-axiomatisation′ ax []-cong₀ : {@0 A : Type a} {@0 x y : A} → Erased (x ≡ y) → [ x ] ≡ [ y ] []-cong₀ {A = A} {x = x} {y = y} = Erased (x ≡ y) →⟨ map (cong [_]→) ⟩ Erased ([ x ] ≡ [ y ]) →⟨ []-cong ⟩ [ [ x ] ] ≡ [ [ y ] ] →⟨ cong (map erased) ⟩□ [ x ] ≡ [ y ] □ []-cong₀-[refl] : {@0 A : Type a} {@0 x : A} → []-cong₀ [ refl x ] ≡ refl [ x ] []-cong₀-[refl] {x = x} = cong (map erased) ([]-cong (map (cong [_]→) [ refl x ])) ≡⟨⟩ cong (map erased) ([]-cong [ cong [_]→ (refl x) ]) ≡⟨ cong (cong (map erased) ∘ []-cong) $ []-cong₀ [ cong-refl _ ] ⟩ cong (map erased) ([]-cong [ refl [ x ] ]) ≡⟨ cong (cong (map erased)) []-cong-[refl] ⟩ cong (map erased) (refl [ [ x ] ]) ≡⟨ cong-refl _ ⟩∎ refl [ x ] ∎ []-cong₀-equivalence : {@0 A : Type a} {@0 x y : A} → Is-equivalence ([]-cong₀ {x = x} {y = y}) []-cong₀-equivalence = _≃_.is-equivalence $ Eq.↔→≃ _ (λ [x]≡[y] → [ cong erased [x]≡[y] ]) (λ [x]≡[y] → cong (map erased) ([]-cong (map (cong [_]→) [ cong erased [x]≡[y] ])) ≡⟨⟩ cong (map erased) ([]-cong [ cong [_]→ (cong erased [x]≡[y]) ]) ≡⟨ cong (cong (map erased) ∘ []-cong) $ []-cong₀ [ trans (cong-∘ _ _ _) $ sym $ cong-id _ ] ⟩ cong (map erased) ([]-cong [ [x]≡[y] ]) ≡⟨ elim (λ x≡y → cong (map erased) ([]-cong [ x≡y ]) ≡ x≡y) (λ x → cong (map erased) ([]-cong [ refl x ]) ≡⟨ cong (cong (map erased)) []-cong-[refl] ⟩ cong (map erased) (refl [ x ]) ≡⟨ cong-refl _ ⟩∎ refl x ∎) _ ⟩ [x]≡[y] ∎) (λ ([ x≡y ]) → [ cong erased (cong (map erased) ([]-cong (map (cong [_]→) [ x≡y ]))) ] ≡⟨⟩ [ cong erased (cong (map erased) ([]-cong [ cong [_]→ x≡y ])) ] ≡⟨ []-cong₀ [ elim (λ x≡y → cong erased (cong (map erased) ([]-cong [ cong [_]→ x≡y ])) ≡ x≡y) (λ x → cong erased (cong (map erased) ([]-cong [ cong [_]→ (refl x) ])) ≡⟨ cong (cong erased ∘ cong (map erased) ∘ []-cong) $ []-cong₀ [ cong-refl _ ] ⟩ cong erased (cong (map erased) ([]-cong [ refl [ x ] ])) ≡⟨ cong (cong erased ∘ cong (map erased)) []-cong-[refl] ⟩ cong erased (cong (map erased) (refl [ [ x ] ])) ≡⟨ trans (cong (cong erased) $ cong-refl _) $ cong-refl _ ⟩∎ refl x ∎) _ ] ⟩∎ [ x≡y ] ∎) ------------------------------------------------------------------------ -- Erased preserves some kinds of functions -- The following definitions are parametrised by two implementations -- of the []-cong axioms. module Erased-cong (ax₁ : []-cong-axiomatisation ℓ₁) (ax₂ : []-cong-axiomatisation ℓ₂) {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} where private module BC₁ = []-cong-axiomatisation ax₁ module BC₂ = []-cong-axiomatisation ax₂ -- Erased preserves split surjections. Erased-cong-↠ : @0 A ↠ B → Erased A ↠ Erased B Erased-cong-↠ A↠B = record { logical-equivalence = Erased-cong-⇔ (_↠_.logical-equivalence A↠B) ; right-inverse-of = λ { [ x ] → BC₂.[]-cong [ _↠_.right-inverse-of A↠B x ] } } -- Erased preserves bijections. Erased-cong-↔ : @0 A ↔ B → Erased A ↔ Erased B Erased-cong-↔ A↔B = record { surjection = Erased-cong-↠ (_↔_.surjection A↔B) ; left-inverse-of = λ { [ x ] → BC₁.[]-cong [ _↔_.left-inverse-of A↔B x ] } } -- Erased preserves equivalences. Erased-cong-≃ : @0 A ≃ B → Erased A ≃ Erased B Erased-cong-≃ A≃B = from-isomorphism (Erased-cong-↔ (from-isomorphism A≃B)) -- A variant of Erased-cong (which is defined in Erased.Level-2). Erased-cong? : @0 A ↝[ c ∣ d ] B → Erased A ↝[ c ∣ d ]ᴱ Erased B Erased-cong? hyp = generalise-erased-ext? (Erased-cong-⇔ (hyp _)) (λ ext → Erased-cong-↔ (hyp ext)) ------------------------------------------------------------------------ -- Some results that follow if the []-cong axioms hold for a single -- universe level module []-cong₁ (ax : []-cong-axiomatisation ℓ) where open []-cong-axiomatisation ax public open Erased-cong ax ax ---------------------------------------------------------------------- -- Some definitions directly related to []-cong -- There is an equivalence between erased equality proofs and -- equalities between erased values. Erased-≡≃[]≡[] : {@0 A : Type ℓ} {@0 x y : A} → Erased (x ≡ y) ≃ ([ x ] ≡ [ y ]) Erased-≡≃[]≡[] = Eq.⟨ _ , []-cong-equivalence ⟩ -- There is a bijection between erased equality proofs and -- equalities between erased values. Erased-≡↔[]≡[] : {@0 A : Type ℓ} {@0 x y : A} → Erased (x ≡ y) ↔ [ x ] ≡ [ y ] Erased-≡↔[]≡[] = _≃_.bijection Erased-≡≃[]≡[] -- The inverse of []-cong. []-cong⁻¹ : {@0 A : Type ℓ} {@0 x y : A} → [ x ] ≡ [ y ] → Erased (x ≡ y) []-cong⁻¹ = _≃_.from Erased-≡≃[]≡[] -- Rearrangement lemmas for []-cong and []-cong⁻¹. []-cong-[]≡cong-[] : {A : Type ℓ} {x y : A} {x≡y : x ≡ y} → []-cong [ x≡y ] ≡ cong [_]→ x≡y []-cong-[]≡cong-[] {x = x} {x≡y = x≡y} = elim¹ (λ x≡y → []-cong [ x≡y ] ≡ cong [_]→ x≡y) ([]-cong [ refl x ] ≡⟨ []-cong-[refl] ⟩ refl [ x ] ≡⟨ sym $ cong-refl _ ⟩∎ cong [_]→ (refl x) ∎) x≡y []-cong⁻¹≡[cong-erased] : {@0 A : Type ℓ} {@0 x y : A} {@0 x≡y : [ x ] ≡ [ y ]} → []-cong⁻¹ x≡y ≡ [ cong erased x≡y ] []-cong⁻¹≡[cong-erased] {x≡y = x≡y} = []-cong [ erased ([]-cong⁻¹ x≡y) ≡⟨ cong erased (_↔_.from (from≡↔≡to Erased-≡≃[]≡[]) lemma) ⟩ erased [ cong erased x≡y ] ≡⟨⟩ cong erased x≡y ∎ ] where @0 lemma : _ lemma = x≡y ≡⟨ cong-id _ ⟩ cong id x≡y ≡⟨⟩ cong ([_]→ ∘ erased) x≡y ≡⟨ sym $ cong-∘ _ _ _ ⟩ cong [_]→ (cong erased x≡y) ≡⟨ sym []-cong-[]≡cong-[] ⟩∎ []-cong [ cong erased x≡y ] ∎ -- A "computation rule" for []-cong⁻¹. []-cong⁻¹-refl : {@0 A : Type ℓ} {@0 x : A} → []-cong⁻¹ (refl [ x ]) ≡ [ refl x ] []-cong⁻¹-refl {x = x} = []-cong⁻¹ (refl [ x ]) ≡⟨ []-cong⁻¹≡[cong-erased] ⟩ [ cong erased (refl [ x ]) ] ≡⟨ []-cong [ cong-refl _ ] ⟩∎ [ refl x ] ∎ -- []-cong and []-cong⁻¹ commute (kind of) with sym. []-cong⁻¹-sym : {@0 A : Type ℓ} {@0 x y : A} {x≡y : [ x ] ≡ [ y ]} → []-cong⁻¹ (sym x≡y) ≡ map sym ([]-cong⁻¹ x≡y) []-cong⁻¹-sym = elim¹ (λ x≡y → []-cong⁻¹ (sym x≡y) ≡ map sym ([]-cong⁻¹ x≡y)) ([]-cong⁻¹ (sym (refl _)) ≡⟨ cong []-cong⁻¹ sym-refl ⟩ []-cong⁻¹ (refl _) ≡⟨ []-cong⁻¹-refl ⟩ [ refl _ ] ≡⟨ []-cong [ sym sym-refl ] ⟩ [ sym (refl _) ] ≡⟨⟩ map sym [ refl _ ] ≡⟨ cong (map sym) $ sym []-cong⁻¹-refl ⟩∎ map sym ([]-cong⁻¹ (refl _)) ∎) _ []-cong-[sym] : {@0 A : Type ℓ} {@0 x y : A} {@0 x≡y : x ≡ y} → []-cong [ sym x≡y ] ≡ sym ([]-cong [ x≡y ]) []-cong-[sym] {x≡y = x≡y} = sym $ _↔_.to (from≡↔≡to $ Eq.↔⇒≃ Erased-≡↔[]≡[]) ( []-cong⁻¹ (sym ([]-cong [ x≡y ])) ≡⟨ []-cong⁻¹-sym ⟩ map sym ([]-cong⁻¹ ([]-cong [ x≡y ])) ≡⟨ cong (map sym) $ _↔_.left-inverse-of Erased-≡↔[]≡[] _ ⟩∎ map sym [ x≡y ] ∎) -- []-cong and []-cong⁻¹ commute (kind of) with trans. []-cong⁻¹-trans : {@0 A : Type ℓ} {@0 x y z : A} {x≡y : [ x ] ≡ [ y ]} {y≡z : [ y ] ≡ [ z ]} → []-cong⁻¹ (trans x≡y y≡z) ≡ [ trans (erased ([]-cong⁻¹ x≡y)) (erased ([]-cong⁻¹ y≡z)) ] []-cong⁻¹-trans {y≡z = y≡z} = elim₁ (λ x≡y → []-cong⁻¹ (trans x≡y y≡z) ≡ [ trans (erased ([]-cong⁻¹ x≡y)) (erased ([]-cong⁻¹ y≡z)) ]) ([]-cong⁻¹ (trans (refl _) y≡z) ≡⟨ cong []-cong⁻¹ $ trans-reflˡ _ ⟩ []-cong⁻¹ y≡z ≡⟨⟩ [ erased ([]-cong⁻¹ y≡z) ] ≡⟨ []-cong [ sym $ trans-reflˡ _ ] ⟩ [ trans (refl _) (erased ([]-cong⁻¹ y≡z)) ] ≡⟨⟩ [ trans (erased [ refl _ ]) (erased ([]-cong⁻¹ y≡z)) ] ≡⟨ []-cong [ cong (flip trans _) $ cong erased $ sym []-cong⁻¹-refl ] ⟩∎ [ trans (erased ([]-cong⁻¹ (refl _))) (erased ([]-cong⁻¹ y≡z)) ] ∎) _ []-cong-[trans] : {@0 A : Type ℓ} {@0 x y z : A} {@0 x≡y : x ≡ y} {@0 y≡z : y ≡ z} → []-cong [ trans x≡y y≡z ] ≡ trans ([]-cong [ x≡y ]) ([]-cong [ y≡z ]) []-cong-[trans] {x≡y = x≡y} {y≡z = y≡z} = sym $ _↔_.to (from≡↔≡to $ Eq.↔⇒≃ Erased-≡↔[]≡[]) ( []-cong⁻¹ (trans ([]-cong [ x≡y ]) ([]-cong [ y≡z ])) ≡⟨ []-cong⁻¹-trans ⟩ [ trans (erased ([]-cong⁻¹ ([]-cong [ x≡y ]))) (erased ([]-cong⁻¹ ([]-cong [ y≡z ]))) ] ≡⟨ []-cong [ cong₂ (λ p q → trans (erased p) (erased q)) (_↔_.left-inverse-of Erased-≡↔[]≡[] _) (_↔_.left-inverse-of Erased-≡↔[]≡[] _) ] ⟩∎ [ trans x≡y y≡z ] ∎) -- In an erased context there is an equivalence between equality of -- values and equality of "boxed" values. @0 ≡≃[]≡[] : {A : Type ℓ} {x y : A} → (x ≡ y) ≃ ([ x ] ≡ [ y ]) ≡≃[]≡[] = Eq.↔⇒≃ (record { surjection = record { logical-equivalence = record { to = []-cong ∘ [_]→ ; from = cong erased } ; right-inverse-of = λ eq → []-cong [ cong erased eq ] ≡⟨ []-cong-[]≡cong-[] ⟩ cong [_]→ (cong erased eq) ≡⟨ cong-∘ _ _ _ ⟩ cong id eq ≡⟨ sym $ cong-id _ ⟩∎ eq ∎ } ; left-inverse-of = λ eq → cong erased ([]-cong [ eq ]) ≡⟨ cong (cong erased) []-cong-[]≡cong-[] ⟩ cong erased (cong [_]→ eq) ≡⟨ cong-∘ _ _ _ ⟩ cong id eq ≡⟨ sym $ cong-id _ ⟩∎ eq ∎ }) -- The left-to-right and right-to-left directions of the equivalence -- are definitionally equal to certain functions. _ : _≃_.to (≡≃[]≡[] {x = x} {y = y}) ≡ []-cong ∘ [_]→ _ = refl _ @0 _ : _≃_.from (≡≃[]≡[] {x = x} {y = y}) ≡ cong erased _ = refl _ ---------------------------------------------------------------------- -- Variants of subst, cong and the J rule that take erased equality -- proofs -- A variant of subst that takes an erased equality proof. substᴱ : {@0 A : Type ℓ} {@0 x y : A} (P : @0 A → Type p) → @0 x ≡ y → P x → P y substᴱ P eq = subst (λ ([ x ]) → P x) ([]-cong [ eq ]) -- A variant of elim₁ that takes an erased equality proof. elim₁ᴱ : {@0 A : Type ℓ} {@0 x y : A} (P : {@0 x : A} → @0 x ≡ y → Type p) → P (refl y) → (@0 x≡y : x ≡ y) → P x≡y elim₁ᴱ {x = x} {y = y} P p x≡y = substᴱ (λ p → P (proj₂ p)) (proj₂ (singleton-contractible y) (x , x≡y)) p -- A variant of elim¹ that takes an erased equality proof. elim¹ᴱ : {@0 A : Type ℓ} {@0 x y : A} (P : {@0 y : A} → @0 x ≡ y → Type p) → P (refl x) → (@0 x≡y : x ≡ y) → P x≡y elim¹ᴱ {x = x} {y = y} P p x≡y = substᴱ (λ p → P (proj₂ p)) (proj₂ (other-singleton-contractible x) (y , x≡y)) p -- A variant of elim that takes an erased equality proof. elimᴱ : {@0 A : Type ℓ} {@0 x y : A} (P : {@0 x y : A} → @0 x ≡ y → Type p) → ((@0 x : A) → P (refl x)) → (@0 x≡y : x ≡ y) → P x≡y elimᴱ {y = y} P p = elim₁ᴱ P (p y) -- A variant of cong that takes an erased equality proof. congᴱ : {@0 A : Type ℓ} {@0 x y : A} (f : @0 A → B) → @0 x ≡ y → f x ≡ f y congᴱ f = elimᴱ (λ {x y} _ → f x ≡ f y) (λ x → refl (f x)) -- A "computation rule" for substᴱ. substᴱ-refl : {@0 A : Type ℓ} {@0 x : A} {P : @0 A → Type p} {p : P x} → substᴱ P (refl x) p ≡ p substᴱ-refl {P = P} {p = p} = subst (λ ([ x ]) → P x) ([]-cong [ refl _ ]) p ≡⟨ cong (flip (subst _) _) []-cong-[refl] ⟩ subst (λ ([ x ]) → P x) (refl [ _ ]) p ≡⟨ subst-refl _ _ ⟩∎ p ∎ -- If all arguments are non-erased, then one can replace substᴱ with -- subst (if the first explicit argument is η-expanded). substᴱ≡subst : {P : @0 A → Type p} {p : P x} → substᴱ P eq p ≡ subst (λ x → P x) eq p substᴱ≡subst {eq = eq} {P = P} {p = p} = elim¹ (λ eq → substᴱ P eq p ≡ subst (λ x → P x) eq p) (substᴱ P (refl _) p ≡⟨ substᴱ-refl ⟩ p ≡⟨ sym $ subst-refl _ _ ⟩∎ subst (λ x → P x) (refl _) p ∎) eq -- A computation rule for elim₁ᴱ. elim₁ᴱ-refl : ∀ {@0 A : Type ℓ} {@0 y} {P : {@0 x : A} → @0 x ≡ y → Type p} {p : P (refl y)} → elim₁ᴱ P p (refl y) ≡ p elim₁ᴱ-refl {y = y} {P = P} {p = p} = substᴱ (λ p → P (proj₂ p)) (proj₂ (singleton-contractible y) (y , refl y)) p ≡⟨ congᴱ (λ q → substᴱ (λ p → P (proj₂ p)) q _) (singleton-contractible-refl _) ⟩ substᴱ (λ p → P (proj₂ p)) (refl (y , refl y)) p ≡⟨ substᴱ-refl ⟩∎ p ∎ -- If all arguments are non-erased, then one can replace elim₁ᴱ with -- elim₁ (if the first explicit argument is η-expanded). elim₁ᴱ≡elim₁ : {P : {@0 x : A} → @0 x ≡ y → Type p} {r : P (refl y)} → elim₁ᴱ P r eq ≡ elim₁ (λ x → P x) r eq elim₁ᴱ≡elim₁ {eq = eq} {P = P} {r = r} = elim₁ (λ eq → elim₁ᴱ P r eq ≡ elim₁ (λ x → P x) r eq) (elim₁ᴱ P r (refl _) ≡⟨ elim₁ᴱ-refl ⟩ r ≡⟨ sym $ elim₁-refl _ _ ⟩∎ elim₁ (λ x → P x) r (refl _) ∎) eq -- A computation rule for elim¹ᴱ. elim¹ᴱ-refl : ∀ {@0 A : Type ℓ} {@0 x} {P : {@0 y : A} → @0 x ≡ y → Type p} {p : P (refl x)} → elim¹ᴱ P p (refl x) ≡ p elim¹ᴱ-refl {x = x} {P = P} {p = p} = substᴱ (λ p → P (proj₂ p)) (proj₂ (other-singleton-contractible x) (x , refl x)) p ≡⟨ congᴱ (λ q → substᴱ (λ p → P (proj₂ p)) q _) (other-singleton-contractible-refl _) ⟩ substᴱ (λ p → P (proj₂ p)) (refl (x , refl x)) p ≡⟨ substᴱ-refl ⟩∎ p ∎ -- If all arguments are non-erased, then one can replace elim¹ᴱ with -- elim¹ (if the first explicit argument is η-expanded). elim¹ᴱ≡elim¹ : {P : {@0 y : A} → @0 x ≡ y → Type p} {r : P (refl x)} → elim¹ᴱ P r eq ≡ elim¹ (λ x → P x) r eq elim¹ᴱ≡elim¹ {eq = eq} {P = P} {r = r} = elim¹ (λ eq → elim¹ᴱ P r eq ≡ elim¹ (λ x → P x) r eq) (elim¹ᴱ P r (refl _) ≡⟨ elim¹ᴱ-refl ⟩ r ≡⟨ sym $ elim¹-refl _ _ ⟩∎ elim¹ (λ x → P x) r (refl _) ∎) eq -- A computation rule for elimᴱ. elimᴱ-refl : {@0 A : Type ℓ} {@0 x : A} {P : {@0 x y : A} → @0 x ≡ y → Type p} (r : (@0 x : A) → P (refl x)) → elimᴱ P r (refl x) ≡ r x elimᴱ-refl _ = elim₁ᴱ-refl -- If all arguments are non-erased, then one can replace elimᴱ with -- elim (if the first two explicit arguments are η-expanded). elimᴱ≡elim : {P : {@0 x y : A} → @0 x ≡ y → Type p} {r : ∀ (@0 x) → P (refl x)} → elimᴱ P r eq ≡ elim (λ x → P x) (λ x → r x) eq elimᴱ≡elim {eq = eq} {P = P} {r = r} = elim (λ eq → elimᴱ P r eq ≡ elim (λ x → P x) (λ x → r x) eq) (λ x → elimᴱ P r (refl _) ≡⟨ elimᴱ-refl r ⟩ r x ≡⟨ sym $ elim-refl _ _ ⟩∎ elim (λ x → P x) (λ x → r x) (refl _) ∎) eq -- A "computation rule" for congᴱ. congᴱ-refl : {@0 A : Type ℓ} {@0 x : A} {f : @0 A → B} → congᴱ f (refl x) ≡ refl (f x) congᴱ-refl {x = x} {f = f} = elimᴱ (λ {x y} _ → f x ≡ f y) (λ x → refl (f x)) (refl x) ≡⟨ elimᴱ-refl (λ x → refl (f x)) ⟩∎ refl (f x) ∎ -- If all arguments are non-erased, then one can replace congᴱ with -- cong (if the first explicit argument is η-expanded). congᴱ≡cong : {f : @0 A → B} → congᴱ f eq ≡ cong (λ x → f x) eq congᴱ≡cong {eq = eq} {f = f} = elim¹ (λ eq → congᴱ f eq ≡ cong (λ x → f x) eq) (congᴱ f (refl _) ≡⟨ congᴱ-refl ⟩ refl _ ≡⟨ sym $ cong-refl _ ⟩∎ cong (λ x → f x) (refl _) ∎) eq ---------------------------------------------------------------------- -- Some equalities -- [_] can be "pushed" through subst. push-subst-[] : {@0 P : A → Type ℓ} {@0 p : P x} {x≡y : x ≡ y} → subst (λ x → Erased (P x)) x≡y [ p ] ≡ [ subst P x≡y p ] push-subst-[] {P = P} {p = p} = elim¹ (λ x≡y → subst (λ x → Erased (P x)) x≡y [ p ] ≡ [ subst P x≡y p ]) (subst (λ x → Erased (P x)) (refl _) [ p ] ≡⟨ subst-refl _ _ ⟩ [ p ] ≡⟨ []-cong [ sym $ subst-refl _ _ ] ⟩∎ [ subst P (refl _) p ] ∎) _ -- []-cong kind of commutes with trans. []-cong-trans : {@0 A : Type ℓ} {@0 x y z : A} {@0 p : x ≡ y} {@0 q : y ≡ z} → []-cong [ trans p q ] ≡ trans ([]-cong [ p ]) ([]-cong [ q ]) []-cong-trans = elim¹ᴱ (λ p → ∀ (@0 q) → []-cong [ trans p q ] ≡ trans ([]-cong [ p ]) ([]-cong [ q ])) (λ q → []-cong [ trans (refl _) q ] ≡⟨ cong []-cong $ []-cong [ trans-reflˡ _ ] ⟩ []-cong [ q ] ≡⟨ sym $ trans-reflˡ _ ⟩ trans (refl [ _ ]) ([]-cong [ q ]) ≡⟨ cong (flip trans _) $ sym []-cong-[refl] ⟩∎ trans ([]-cong [ refl _ ]) ([]-cong [ q ]) ∎) _ _ ---------------------------------------------------------------------- -- All h-levels are closed under Erased -- Erased commutes with H-level′ n (assuming extensionality). Erased-H-level′↔H-level′ : {@0 A : Type ℓ} → ∀ n → Erased (H-level′ n A) ↝[ ℓ ∣ ℓ ] H-level′ n (Erased A) Erased-H-level′↔H-level′ {A = A} zero ext = Erased (H-level′ zero A) ↔⟨⟩ Erased (∃ λ (x : A) → (y : A) → x ≡ y) ↔⟨ Erased-Σ↔Σ ⟩ (∃ λ (x : Erased A) → Erased ((y : A) → erased x ≡ y)) ↔⟨ (∃-cong λ _ → Erased-Π↔Π-Erased) ⟩ (∃ λ (x : Erased A) → (y : Erased A) → Erased (erased x ≡ erased y)) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → from-isomorphism Erased-≡↔[]≡[]) ⟩ (∃ λ (x : Erased A) → (y : Erased A) → x ≡ y) ↔⟨⟩ H-level′ zero (Erased A) □ Erased-H-level′↔H-level′ {A = A} (suc n) ext = Erased (H-level′ (suc n) A) ↔⟨⟩ Erased ((x y : A) → H-level′ n (x ≡ y)) ↔⟨ Erased-Π↔Π-Erased ⟩ ((x : Erased A) → Erased ((y : A) → H-level′ n (erased x ≡ y))) ↝⟨ (∀-cong ext λ _ → from-isomorphism Erased-Π↔Π-Erased) ⟩ ((x y : Erased A) → Erased (H-level′ n (erased x ≡ erased y))) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → Erased-H-level′↔H-level′ n ext) ⟩ ((x y : Erased A) → H-level′ n (Erased (erased x ≡ erased y))) ↝⟨ (∀-cong ext λ _ → ∀-cong ext λ _ → H-level′-cong ext n Erased-≡↔[]≡[]) ⟩ ((x y : Erased A) → H-level′ n (x ≡ y)) ↔⟨⟩ H-level′ (suc n) (Erased A) □ -- Erased commutes with H-level n (assuming extensionality). Erased-H-level↔H-level : {@0 A : Type ℓ} → ∀ n → Erased (H-level n A) ↝[ ℓ ∣ ℓ ] H-level n (Erased A) Erased-H-level↔H-level {A = A} n ext = Erased (H-level n A) ↝⟨ Erased-cong? H-level↔H-level′ ext ⟩ Erased (H-level′ n A) ↝⟨ Erased-H-level′↔H-level′ n ext ⟩ H-level′ n (Erased A) ↝⟨ inverse-ext? H-level↔H-level′ ext ⟩□ H-level n (Erased A) □ -- H-level n is closed under Erased. H-level-Erased : {@0 A : Type ℓ} → ∀ n → @0 H-level n A → H-level n (Erased A) H-level-Erased n h = Erased-H-level↔H-level n _ [ h ] ---------------------------------------------------------------------- -- Some closure properties related to Is-proposition -- If A is a proposition, then Dec-Erased A is a proposition -- (assuming extensionality). Is-proposition-Dec-Erased : {@0 A : Type ℓ} → Extensionality ℓ lzero → @0 Is-proposition A → Is-proposition (Dec-Erased A) Is-proposition-Dec-Erased {A = A} ext p = $⟨ Dec-closure-propositional ext (H-level-Erased 1 p) ⟩ Is-proposition (Dec (Erased A)) ↝⟨ H-level-cong _ 1 (inverse $ Dec-Erased↔Dec-Erased {k = equivalence} ext) ⦂ (_ → _) ⟩□ Is-proposition (Dec-Erased A) □ -- If A is a set, then Decidable-erased-equality A is a proposition -- (assuming extensionality). Is-proposition-Decidable-erased-equality : {A : Type ℓ} → Extensionality ℓ ℓ → @0 Is-set A → Is-proposition (Decidable-erased-equality A) Is-proposition-Decidable-erased-equality ext s = Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Is-proposition-Dec-Erased (lower-extensionality lzero _ ext) s -- Erasedᴾ preserves Is-proposition. Is-proposition-Erasedᴾ : {@0 A : Type a} {@0 B : Type b} {@0 R : A → B → Type ℓ} → @0 (∀ {x y} → Is-proposition (R x y)) → ∀ {x y} → Is-proposition (Erasedᴾ R x y) Is-proposition-Erasedᴾ prop = H-level-Erased 1 prop ---------------------------------------------------------------------- -- A property related to "Modalities in Homotopy Type Theory" by -- Rijke, Shulman and Spitters -- Erased is a lex modality (see Theorem 3.1, case (i) in -- "Modalities in Homotopy Type Theory" for the definition used -- here). lex-modality : {@0 A : Type ℓ} {@0 x y : A} → Contractible (Erased A) → Contractible (Erased (x ≡ y)) lex-modality {A = A} {x = x} {y = y} = Contractible (Erased A) ↝⟨ _⇔_.from (Erased-H-level↔H-level 0 _) ⟩ Erased (Contractible A) ↝⟨ map (⇒≡ 0) ⟩ Erased (Contractible (x ≡ y)) ↝⟨ Erased-H-level↔H-level 0 _ ⟩□ Contractible (Erased (x ≡ y)) □ ---------------------------------------------------------------------- -- Erased "commutes" with various things -- Erased "commutes" with _⁻¹_. Erased-⁻¹ : {@0 A : Type a} {@0 B : Type ℓ} {@0 f : A → B} {@0 y : B} → Erased (f ⁻¹ y) ↔ map f ⁻¹ [ y ] Erased-⁻¹ {f = f} {y = y} = Erased (∃ λ x → f x ≡ y) ↝⟨ Erased-Σ↔Σ ⟩ (∃ λ x → Erased (f (erased x) ≡ y)) ↝⟨ (∃-cong λ _ → Erased-≡↔[]≡[]) ⟩□ (∃ λ x → map f x ≡ [ y ]) □ -- Erased "commutes" with Split-surjective. Erased-Split-surjective↔Split-surjective : {@0 A : Type a} {@0 B : Type ℓ} {@0 f : A → B} → Erased (Split-surjective f) ↝[ ℓ ∣ a ⊔ ℓ ] Split-surjective (map f) Erased-Split-surjective↔Split-surjective {f = f} ext = Erased (∀ y → ∃ λ x → f x ≡ y) ↔⟨ Erased-Π↔Π-Erased ⟩ (∀ y → Erased (∃ λ x → f x ≡ erased y)) ↝⟨ (∀-cong ext λ _ → from-isomorphism Erased-Σ↔Σ) ⟩ (∀ y → ∃ λ x → Erased (f (erased x) ≡ erased y)) ↝⟨ (∀-cong ext λ _ → ∃-cong λ _ → from-isomorphism Erased-≡↔[]≡[]) ⟩ (∀ y → ∃ λ x → [ f (erased x) ] ≡ y) ↔⟨⟩ (∀ y → ∃ λ x → map f x ≡ y) □ ---------------------------------------------------------------------- -- Some lemmas related to whether [_]→ is injective or an embedding -- In erased contexts [_]→ is injective. -- -- See also Erased.With-K.Injective-[]. @0 Injective-[] : {A : Type ℓ} → Injective {A = A} [_]→ Injective-[] = erased ∘ []-cong⁻¹ -- If A is a proposition, then [_]→ {A = A} is an embedding. -- -- See also Erased-Is-embedding-[] and Erased-Split-surjective-[] -- above as well as Very-stable→Is-embedding-[] and -- Very-stable→Split-surjective-[] in Erased.Stability and -- Injective-[] and Is-embedding-[] in Erased.With-K. Is-proposition→Is-embedding-[] : {A : Type ℓ} → Is-proposition A → Is-embedding [ A ∣_]→ Is-proposition→Is-embedding-[] prop = _⇔_.to (Emb.Injective⇔Is-embedding set (H-level-Erased 2 set) [_]→) (λ _ → prop _ _) where set = mono₁ 1 prop ---------------------------------------------------------------------- -- Variants of some functions from Equality.Decision-procedures -- A variant of Equality.Decision-procedures.Σ.set⇒dec⇒dec⇒dec. set⇒dec-erased⇒dec-erased⇒Σ-dec-erased : {@0 A : Type ℓ} {@0 P : A → Type p} {@0 x₁ x₂ : A} {@0 y₁ : P x₁} {@0 y₂ : P x₂} → @0 Is-set A → Dec-Erased (x₁ ≡ x₂) → (∀ (@0 eq) → Dec-Erased (substᴱ (λ x → P x) eq y₁ ≡ y₂)) → Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂)) set⇒dec-erased⇒dec-erased⇒Σ-dec-erased _ (no [ x₁≢x₂ ]) _ = no [ x₁≢x₂ ∘ cong proj₁ ] set⇒dec-erased⇒dec-erased⇒Σ-dec-erased {P = P} {y₁ = y₁} {y₂ = y₂} set₁ (yes [ x₁≡x₂ ]) dec₂ = ⊎-map (map λ cast-y₁≡y₂ → Σ-≡,≡→≡ x₁≡x₂ (subst (λ x → P x) x₁≡x₂ y₁ ≡⟨ sym substᴱ≡subst ⟩ substᴱ (λ x → P x) x₁≡x₂ y₁ ≡⟨ cast-y₁≡y₂ ⟩∎ y₂ ∎)) (map λ cast-y₁≢y₂ eq → $⟨ proj₂ (Σ-≡,≡←≡ eq) ⟩ subst (λ x → P x) (proj₁ (Σ-≡,≡←≡ eq)) y₁ ≡ y₂ ↝⟨ ≡⇒↝ _ $ cong (_≡ _) $ sym substᴱ≡subst ⟩ substᴱ (λ x → P x) (proj₁ (Σ-≡,≡←≡ eq)) y₁ ≡ y₂ ↝⟨ subst (λ p → substᴱ _ p _ ≡ _) (set₁ _ _) ⟩ substᴱ (λ x → P x) x₁≡x₂ y₁ ≡ y₂ ↝⟨ cast-y₁≢y₂ ⟩□ ⊥ □) (dec₂ x₁≡x₂) -- A variant of Equality.Decision-procedures.Σ.decidable⇒dec⇒dec. decidable-erased⇒dec-erased⇒Σ-dec-erased : {@0 A : Type ℓ} {@0 P : A → Type p} {x₁ x₂ : A} {@0 y₁ : P x₁} {@0 y₂ : P x₂} → Decidable-erased-equality A → (∀ (@0 eq) → Dec-Erased (substᴱ (λ x → P x) eq y₁ ≡ y₂)) → Dec-Erased ((x₁ , y₁) ≡ (x₂ , y₂)) decidable-erased⇒dec-erased⇒Σ-dec-erased dec = set⇒dec-erased⇒dec-erased⇒Σ-dec-erased (decidable⇒set (Decidable-erased-equality≃Decidable-equality _ dec)) (dec _ _) -- A variant of Equality.Decision-procedures.Σ.Dec._≟_. decidable-erased⇒decidable-erased⇒Σ-decidable-erased : {@0 A : Type ℓ} {P : @0 A → Type p} → Decidable-erased-equality A → ({x : A} → Decidable-erased-equality (P x)) → Decidable-erased-equality (Σ A λ x → P x) decidable-erased⇒decidable-erased⇒Σ-decidable-erased {P = P} decA decP (_ , x₂) (_ , y₂) = decidable-erased⇒dec-erased⇒Σ-dec-erased decA (λ eq → decP (substᴱ P eq x₂) y₂) ------------------------------------------------------------------------ -- Erased commutes with W -- Erased commutes with W (assuming extensionality and an -- implementation of the []-cong axioms). -- -- See also Erased-W↔W′ and Erased-W↔W below. Erased-W↔W-[]-cong : {@0 A : Type a} {@0 P : A → Type p} → []-cong-axiomatisation (a ⊔ p) → Erased (W A P) ↝[ p ∣ a ⊔ p ] W (Erased A) (λ x → Erased (P (erased x))) Erased-W↔W-[]-cong {a = a} {p = p} {A = A} {P = P} ax = generalise-ext? Erased-W⇔W (λ ext → to∘from ext , from∘to ext) where open []-cong-axiomatisation ax open _⇔_ Erased-W⇔W to∘from : Extensionality p (a ⊔ p) → (x : W (Erased A) (λ x → Erased (P (erased x)))) → to (from x) ≡ x to∘from ext (sup [ x ] f) = cong (sup [ x ]) $ apply-ext ext λ ([ y ]) → to∘from ext (f [ y ]) from∘to : Extensionality p (a ⊔ p) → (x : Erased (W A P)) → from (to x) ≡ x from∘to ext [ sup x f ] = []-cong [ (cong (sup x) $ apply-ext ext λ y → cong erased (from∘to ext [ f y ])) ] -- Erased commutes with W (assuming extensionality). -- -- See also Erased-W↔W below: That property is defined assuming that -- the []-cong axioms can be instantiated, but is stated using -- _↝[ p ∣ a ⊔ p ]_ instead of _↝[ a ⊔ p ∣ a ⊔ p ]_. Erased-W↔W′ : {@0 A : Type a} {@0 P : A → Type p} → Erased (W A P) ↝[ a ⊔ p ∣ a ⊔ p ] W (Erased A) (λ x → Erased (P (erased x))) Erased-W↔W′ {a = a} = generalise-ext? Erased-W⇔W (λ ext → let bij = Erased-W↔W-[]-cong (Extensionality→[]-cong-axiomatisation ext) (lower-extensionality a lzero ext) in _↔_.right-inverse-of bij , _↔_.left-inverse-of bij) ------------------------------------------------------------------------ -- Some results that follow if the []-cong axioms hold for two -- universe levels module []-cong₂ (ax₁ : []-cong-axiomatisation ℓ₁) (ax₂ : []-cong-axiomatisation ℓ₂) where private module BC₁ = []-cong₁ ax₁ module BC₂ = []-cong₁ ax₂ ---------------------------------------------------------------------- -- Some equalities -- The function map (cong f) can be expressed in terms of -- cong (map f) (up to pointwise equality). map-cong≡cong-map : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 x y : A} {@0 f : A → B} {x≡y : Erased (x ≡ y)} → map (cong f) x≡y ≡ BC₂.[]-cong⁻¹ (cong (map f) (BC₁.[]-cong x≡y)) map-cong≡cong-map {f = f} {x≡y = [ x≡y ]} = [ cong f x≡y ] ≡⟨⟩ [ cong (erased ∘ map f ∘ [_]→) x≡y ] ≡⟨ BC₂.[]-cong [ sym $ cong-∘ _ _ _ ] ⟩ [ cong (erased ∘ map f) (cong [_]→ x≡y) ] ≡⟨ BC₂.[]-cong [ cong (cong _) $ sym BC₁.[]-cong-[]≡cong-[] ] ⟩ [ cong (erased ∘ map f) (BC₁.[]-cong [ x≡y ]) ] ≡⟨ BC₂.[]-cong [ sym $ cong-∘ _ _ _ ] ⟩ [ cong erased (cong (map f) (BC₁.[]-cong [ x≡y ])) ] ≡⟨ sym BC₂.[]-cong⁻¹≡[cong-erased] ⟩∎ BC₂.[]-cong⁻¹ (cong (map f) (BC₁.[]-cong [ x≡y ])) ∎ -- []-cong kind of commutes with cong. []-cong-cong : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 f : A → B} {@0 x y : A} {@0 p : x ≡ y} → BC₂.[]-cong [ cong f p ] ≡ cong (map f) (BC₁.[]-cong [ p ]) []-cong-cong {f = f} = BC₁.elim¹ᴱ (λ p → BC₂.[]-cong [ cong f p ] ≡ cong (map f) (BC₁.[]-cong [ p ])) (BC₂.[]-cong [ cong f (refl _) ] ≡⟨ cong BC₂.[]-cong (BC₂.[]-cong [ cong-refl _ ]) ⟩ BC₂.[]-cong [ refl _ ] ≡⟨ BC₂.[]-cong-[refl] ⟩ refl _ ≡⟨ sym $ cong-refl _ ⟩ cong (map f) (refl _) ≡⟨ sym $ cong (cong (map f)) BC₁.[]-cong-[refl] ⟩∎ cong (map f) (BC₁.[]-cong [ refl _ ]) ∎) _ ---------------------------------------------------------------------- -- Erased "commutes" with one thing -- Erased "commutes" with Has-quasi-inverse. Erased-Has-quasi-inverse↔Has-quasi-inverse : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 f : A → B} → Erased (Has-quasi-inverse f) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ] Has-quasi-inverse (map f) Erased-Has-quasi-inverse↔Has-quasi-inverse {A = A} {B = B} {f = f} {k = k} ext = Erased (∃ λ g → (∀ x → f (g x) ≡ x) × (∀ x → g (f x) ≡ x)) ↔⟨ Erased-Σ↔Σ ⟩ (∃ λ g → Erased ((∀ x → f (erased g x) ≡ x) × (∀ x → erased g (f x) ≡ x))) ↝⟨ (∃-cong λ _ → from-isomorphism Erased-Σ↔Σ) ⟩ (∃ λ g → Erased (∀ x → f (erased g x) ≡ x) × Erased (∀ x → erased g (f x) ≡ x)) ↝⟨ Σ-cong Erased-Π↔Π-Erased (λ g → lemma₁ (erased g) ×-cong lemma₂ (erased g)) ⟩□ (∃ λ g → (∀ x → map f (g x) ≡ x) × (∀ x → g (map f x) ≡ x)) □ where lemma₁ : (@0 g : B → A) → _ ↝[ k ] _ lemma₁ g = Erased (∀ x → f (g x) ≡ x) ↔⟨ Erased-Π↔Π-Erased ⟩ (∀ x → Erased (f (g (erased x)) ≡ erased x)) ↝⟨ (∀-cong (lower-extensionality? k ℓ₁ ℓ₁ ext) λ _ → from-isomorphism BC₂.Erased-≡↔[]≡[]) ⟩ (∀ x → [ f (g (erased x)) ] ≡ x) ↔⟨⟩ (∀ x → map (f ∘ g) x ≡ x) □ lemma₂ : (@0 g : B → A) → _ ↝[ k ] _ lemma₂ g = Erased (∀ x → g (f x) ≡ x) ↔⟨ Erased-Π↔Π-Erased ⟩ (∀ x → Erased (g (f (erased x)) ≡ erased x)) ↝⟨ (∀-cong (lower-extensionality? k ℓ₂ ℓ₂ ext) λ _ → from-isomorphism BC₁.Erased-≡↔[]≡[]) ⟩ (∀ x → [ g (f (erased x)) ] ≡ x) ↔⟨⟩ (∀ x → map (g ∘ f) x ≡ x) □ ------------------------------------------------------------------------ -- Some results that follow if the []-cong axioms hold for the maximum -- of two universe levels (as well as for the two universe levels) -- It is possible to instantiate the first two arguments using the -- third and lower-[]-cong-axiomatisation, but this is not what is -- done in the module []-cong below. module []-cong₂-⊔ (ax₁ : []-cong-axiomatisation ℓ₁) (ax₂ : []-cong-axiomatisation ℓ₂) (ax : []-cong-axiomatisation (ℓ₁ ⊔ ℓ₂)) where private module EC = Erased-cong ax ax module BC₁ = []-cong₁ ax₁ module BC₂ = []-cong₁ ax₂ module BC = []-cong₁ ax ---------------------------------------------------------------------- -- A property related to "Modalities in Homotopy Type Theory" by -- Rijke, Shulman and Spitters -- A function f is Erased-connected in the sense of Rijke et al. -- exactly when there is an erased proof showing that f is an -- equivalence (assuming extensionality). -- -- See also Erased-Is-equivalence↔Is-equivalence below. Erased-connected↔Erased-Is-equivalence : {@0 A : Type ℓ₁} {B : Type ℓ₂} {@0 f : A → B} → (∀ y → Contractible (Erased (f ⁻¹ y))) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ] Erased (Is-equivalence f) Erased-connected↔Erased-Is-equivalence {f = f} {k = k} ext = (∀ y → Contractible (Erased (f ⁻¹ y))) ↝⟨ (∀-cong (lower-extensionality? k ℓ₁ lzero ext) λ _ → inverse-ext? (BC.Erased-H-level↔H-level 0) ext) ⟩ (∀ y → Erased (Contractible (f ⁻¹ y))) ↔⟨ inverse Erased-Π↔Π ⟩ Erased (∀ y → Contractible (f ⁻¹ y)) ↔⟨⟩ Erased (CP.Is-equivalence f) ↝⟨ inverse-ext? (λ ext → EC.Erased-cong? Is-equivalence≃Is-equivalence-CP ext) ext ⟩□ Erased (Is-equivalence f) □ ---------------------------------------------------------------------- -- Erased "commutes" with various things -- Erased "commutes" with Is-equivalence. Erased-Is-equivalence↔Is-equivalence : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 f : A → B} → Erased (Is-equivalence f) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ] Is-equivalence (map f) Erased-Is-equivalence↔Is-equivalence {f = f} {k = k} ext = Erased (Is-equivalence f) ↝⟨ EC.Erased-cong? Is-equivalence≃Is-equivalence-CP ext ⟩ Erased (∀ x → Contractible (f ⁻¹ x)) ↔⟨ Erased-Π↔Π-Erased ⟩ (∀ x → Erased (Contractible (f ⁻¹ erased x))) ↝⟨ (∀-cong ext′ λ _ → BC.Erased-H-level↔H-level 0 ext) ⟩ (∀ x → Contractible (Erased (f ⁻¹ erased x))) ↝⟨ (∀-cong ext′ λ _ → H-level-cong ext 0 BC₂.Erased-⁻¹) ⟩ (∀ x → Contractible (map f ⁻¹ x)) ↝⟨ inverse-ext? Is-equivalence≃Is-equivalence-CP ext ⟩□ Is-equivalence (map f) □ where ext′ = lower-extensionality? k ℓ₁ lzero ext -- Erased "commutes" with Injective. Erased-Injective↔Injective : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 f : A → B} → Erased (Injective f) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ] Injective (map f) Erased-Injective↔Injective {f = f} {k = k} ext = Erased (∀ {x y} → f x ≡ f y → x ≡ y) ↔⟨ EC.Erased-cong-↔ Bijection.implicit-Π↔Π ⟩ Erased (∀ x {y} → f x ≡ f y → x ≡ y) ↝⟨ EC.Erased-cong? (λ {k} ext → ∀-cong (lower-extensionality? k ℓ₂ lzero ext) λ _ → from-isomorphism Bijection.implicit-Π↔Π) ext ⟩ Erased (∀ x y → f x ≡ f y → x ≡ y) ↔⟨ Erased-Π↔Π-Erased ⟩ (∀ x → Erased (∀ y → f (erased x) ≡ f y → erased x ≡ y)) ↝⟨ (∀-cong ext′ λ _ → from-isomorphism Erased-Π↔Π-Erased) ⟩ (∀ x y → Erased (f (erased x) ≡ f (erased y) → erased x ≡ erased y)) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ → from-isomorphism Erased-Π↔Π-Erased) ⟩ (∀ x y → Erased (f (erased x) ≡ f (erased y)) → Erased (erased x ≡ erased y)) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ → generalise-ext?-sym (λ {k} ext → →-cong (lower-extensionality? ⌊ k ⌋-sym ℓ₁ ℓ₂ ext) (from-isomorphism BC₂.Erased-≡↔[]≡[]) (from-isomorphism BC₁.Erased-≡↔[]≡[])) ext) ⟩ (∀ x y → [ f (erased x) ] ≡ [ f (erased y) ] → x ≡ y) ↝⟨ (∀-cong ext′ λ _ → from-isomorphism $ inverse Bijection.implicit-Π↔Π) ⟩ (∀ x {y} → [ f (erased x) ] ≡ [ f (erased y) ] → x ≡ y) ↔⟨ inverse Bijection.implicit-Π↔Π ⟩□ (∀ {x y} → [ f (erased x) ] ≡ [ f (erased y) ] → x ≡ y) □ where ext′ = lower-extensionality? k ℓ₂ lzero ext -- Erased "commutes" with Is-embedding. Erased-Is-embedding↔Is-embedding : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} {@0 f : A → B} → Erased (Is-embedding f) ↝[ ℓ₁ ⊔ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ] Is-embedding (map f) Erased-Is-embedding↔Is-embedding {f = f} {k = k} ext = Erased (∀ x y → Is-equivalence (cong f)) ↔⟨ Erased-Π↔Π-Erased ⟩ (∀ x → Erased (∀ y → Is-equivalence (cong f))) ↝⟨ (∀-cong ext′ λ _ → from-isomorphism Erased-Π↔Π-Erased) ⟩ (∀ x y → Erased (Is-equivalence (cong f))) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ → Erased-Is-equivalence↔Is-equivalence ext) ⟩ (∀ x y → Is-equivalence (map (cong f))) ↝⟨ (∀-cong ext′ λ x → ∀-cong ext′ λ y → Is-equivalence-cong ext λ _ → []-cong₂.map-cong≡cong-map ax₁ ax₂) ⟩ (∀ x y → Is-equivalence (BC₂.[]-cong⁻¹ ∘ cong (map f) ∘ BC₁.[]-cong)) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ → inverse-ext? (Is-equivalence≃Is-equivalence-∘ʳ BC₁.[]-cong-equivalence) ext) ⟩ (∀ x y → Is-equivalence (BC₂.[]-cong⁻¹ ∘ cong (map f))) ↝⟨ (∀-cong ext′ λ _ → ∀-cong ext′ λ _ → inverse-ext? (Is-equivalence≃Is-equivalence-∘ˡ (_≃_.is-equivalence $ from-isomorphism $ inverse BC₂.Erased-≡↔[]≡[])) ext) ⟩□ (∀ x y → Is-equivalence (cong (map f))) □ where ext′ = lower-extensionality? k ℓ₂ lzero ext ---------------------------------------------------------------------- -- Erased commutes with various type formers -- Erased commutes with W (assuming extensionality). Erased-W↔W : {@0 A : Type ℓ₁} {@0 P : A → Type ℓ₂} → Erased (W A P) ↝[ ℓ₂ ∣ ℓ₁ ⊔ ℓ₂ ] W (Erased A) (λ x → Erased (P (erased x))) Erased-W↔W = Erased-W↔W-[]-cong ax -- Erased commutes with _⇔_. Erased-⇔↔⇔ : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} → Erased (A ⇔ B) ↔ (Erased A ⇔ Erased B) Erased-⇔↔⇔ {A = A} {B = B} = Erased (A ⇔ B) ↝⟨ EC.Erased-cong-↔ ⇔↔→×→ ⟩ Erased ((A → B) × (B → A)) ↝⟨ Erased-Σ↔Σ ⟩ Erased (A → B) × Erased (B → A) ↝⟨ Erased-Π↔Π-Erased ×-cong Erased-Π↔Π-Erased ⟩ (Erased A → Erased B) × (Erased B → Erased A) ↝⟨ inverse ⇔↔→×→ ⟩□ (Erased A ⇔ Erased B) □ -- Erased commutes with _↣_. Erased-cong-↣ : {@0 A : Type ℓ₁} {@0 B : Type ℓ₂} → @0 A ↣ B → Erased A ↣ Erased B Erased-cong-↣ A↣B = record { to = map (_↣_.to A↣B) ; injective = Erased-Injective↔Injective _ [ _↣_.injective A↣B ] } ------------------------------------------------------------------------ -- Some results that follow if the []-cong axioms hold for all -- universe levels module []-cong (ax : ∀ {ℓ} → []-cong-axiomatisation ℓ) where private open module EC {ℓ₁ ℓ₂} = Erased-cong (ax {ℓ = ℓ₁}) (ax {ℓ = ℓ₂}) public open module BC₁ {ℓ} = []-cong₁ (ax {ℓ = ℓ}) public open module BC₂ {ℓ₁ ℓ₂} = []-cong₂ (ax {ℓ = ℓ₁}) (ax {ℓ = ℓ₂}) public open module BC₂-⊔ {ℓ₁ ℓ₂} = []-cong₂-⊔ (ax {ℓ = ℓ₁}) (ax {ℓ = ℓ₂}) (ax {ℓ = ℓ₁ ⊔ ℓ₂}) public ------------------------------------------------------------------------ -- Some results that were proved assuming extensionality and also that -- one or more instances of the []-cong axioms can be implemented, -- reproved without the latter assumptions module Extensionality where -- Erased commutes with H-level′ n (assuming extensionality). Erased-H-level′≃H-level′ : {@0 A : Type a} → Extensionality a a → ∀ n → Erased (H-level′ n A) ≃ H-level′ n (Erased A) Erased-H-level′≃H-level′ ext n = []-cong₁.Erased-H-level′↔H-level′ (Extensionality→[]-cong-axiomatisation ext) n ext -- Erased commutes with H-level n (assuming extensionality). Erased-H-level≃H-level : {@0 A : Type a} → Extensionality a a → ∀ n → Erased (H-level n A) ≃ H-level n (Erased A) Erased-H-level≃H-level ext n = []-cong₁.Erased-H-level↔H-level (Extensionality→[]-cong-axiomatisation ext) n ext -- If A is a set, then Decidable-erased-equality A is a proposition -- (assuming extensionality). Is-proposition-Decidable-erased-equality′ : {A : Type a} → Extensionality a a → @0 Is-set A → Is-proposition (Decidable-erased-equality A) Is-proposition-Decidable-erased-equality′ ext = []-cong₁.Is-proposition-Decidable-erased-equality (Extensionality→[]-cong-axiomatisation ext) ext -- Erased "commutes" with Split-surjective. Erased-Split-surjective≃Split-surjective : {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} → Extensionality b (a ⊔ b) → Erased (Split-surjective f) ≃ Split-surjective (map f) Erased-Split-surjective≃Split-surjective {a = a} ext = []-cong₁.Erased-Split-surjective↔Split-surjective (Extensionality→[]-cong-axiomatisation (lower-extensionality lzero a ext)) ext -- A function f is Erased-connected in the sense of Rijke et al. -- exactly when there is an erased proof showing that f is an -- equivalence (assuming extensionality). Erased-connected≃Erased-Is-equivalence : {@0 A : Type a} {B : Type b} {@0 f : A → B} → Extensionality (a ⊔ b) (a ⊔ b) → (∀ y → Contractible (Erased (f ⁻¹ y))) ≃ Erased (Is-equivalence f) Erased-connected≃Erased-Is-equivalence {a = a} {b = b} ext = []-cong₂-⊔.Erased-connected↔Erased-Is-equivalence (Extensionality→[]-cong-axiomatisation (lower-extensionality b b ext)) (Extensionality→[]-cong-axiomatisation (lower-extensionality a a ext)) (Extensionality→[]-cong-axiomatisation ext) ext -- Erased "commutes" with Is-equivalence (assuming extensionality). Erased-Is-equivalence≃Is-equivalence : {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} → Extensionality (a ⊔ b) (a ⊔ b) → Erased (Is-equivalence f) ≃ Is-equivalence (map f) Erased-Is-equivalence≃Is-equivalence {a = a} {b = b} ext = []-cong₂-⊔.Erased-Is-equivalence↔Is-equivalence (Extensionality→[]-cong-axiomatisation (lower-extensionality b b ext)) (Extensionality→[]-cong-axiomatisation (lower-extensionality a a ext)) (Extensionality→[]-cong-axiomatisation ext) ext -- Erased "commutes" with Has-quasi-inverse (assuming -- extensionality). Erased-Has-quasi-inverse≃Has-quasi-inverse : {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} → Extensionality (a ⊔ b) (a ⊔ b) → Erased (Has-quasi-inverse f) ≃ Has-quasi-inverse (map f) Erased-Has-quasi-inverse≃Has-quasi-inverse {a = a} {b = b} ext = []-cong₂.Erased-Has-quasi-inverse↔Has-quasi-inverse (Extensionality→[]-cong-axiomatisation (lower-extensionality b b ext)) (Extensionality→[]-cong-axiomatisation (lower-extensionality a a ext)) ext -- Erased "commutes" with Injective (assuming extensionality). Erased-Injective≃Injective : {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} → Extensionality (a ⊔ b) (a ⊔ b) → Erased (Injective f) ≃ Injective (map f) Erased-Injective≃Injective {a = a} {b = b} ext = []-cong₂-⊔.Erased-Injective↔Injective (Extensionality→[]-cong-axiomatisation (lower-extensionality b b ext)) (Extensionality→[]-cong-axiomatisation (lower-extensionality a a ext)) (Extensionality→[]-cong-axiomatisation ext) ext -- Erased "commutes" with Is-embedding (assuming extensionality). Erased-Is-embedding≃Is-embedding : {@0 A : Type a} {@0 B : Type b} {@0 f : A → B} → Extensionality (a ⊔ b) (a ⊔ b) → Erased (Is-embedding f) ≃ Is-embedding (map f) Erased-Is-embedding≃Is-embedding {a = a} {b = b} ext = []-cong₂-⊔.Erased-Is-embedding↔Is-embedding (Extensionality→[]-cong-axiomatisation (lower-extensionality b b ext)) (Extensionality→[]-cong-axiomatisation (lower-extensionality a a ext)) (Extensionality→[]-cong-axiomatisation ext) ext ------------------------------------------------------------------------ -- Some lemmas related to []-cong-axiomatisation -- Any two implementations of []-cong are pointwise equal. []-cong-unique : {@0 A : Type a} {@0 x y : A} {x≡y : Erased (x ≡ y)} (ax₁ ax₂ : []-cong-axiomatisation a) → []-cong-axiomatisation.[]-cong ax₁ x≡y ≡ []-cong-axiomatisation.[]-cong ax₂ x≡y []-cong-unique {x = x} ax₁ ax₂ = BC₁.elim¹ᴱ (λ x≡y → BC₁.[]-cong [ x≡y ] ≡ BC₂.[]-cong [ x≡y ]) (BC₁.[]-cong [ refl x ] ≡⟨ BC₁.[]-cong-[refl] ⟩ refl [ x ] ≡⟨ sym BC₂.[]-cong-[refl] ⟩∎ BC₂.[]-cong [ refl x ] ∎) _ where module BC₁ = []-cong₁ ax₁ module BC₂ = []-cong₁ ax₂ -- The type []-cong-axiomatisation a is propositional (assuming -- extensionality). -- -- The proof is based on a proof due to Nicolai Kraus that shows that -- "J + its computation rule" is contractible, see -- Equality.Instances-related.Equality-with-J-contractible. []-cong-axiomatisation-propositional : Extensionality (lsuc a) a → Is-proposition ([]-cong-axiomatisation a) []-cong-axiomatisation-propositional {a = a} ext = [inhabited⇒contractible]⇒propositional λ ax → let module BC = []-cong₁ ax module EC = Erased-cong ax ax in _⇔_.from contractible⇔↔⊤ ([]-cong-axiomatisation a ↔⟨ Eq.↔→≃ (λ (record { []-cong = c ; []-cong-equivalence = e ; []-cong-[refl] = r }) _ → (λ ([ _ , _ , x≡y ]) → c [ x≡y ]) , (λ _ → r) , (λ _ _ → e)) (λ f → record { []-cong = λ ([ x≡y ]) → f _ .proj₁ [ _ , _ , x≡y ] ; []-cong-equivalence = f _ .proj₂ .proj₂ _ _ ; []-cong-[refl] = f _ .proj₂ .proj₁ _ }) refl refl ⟩ ((([ A ]) : Erased (Type a)) → ∃ λ (c : ((([ x , y , _ ]) : Erased (A ²/≡)) → [ x ] ≡ [ y ])) → ((([ x ]) : Erased A) → c [ x , x , refl x ] ≡ refl [ x ]) × ((([ x ]) ([ y ]) : Erased A) → Is-equivalence {A = Erased (x ≡ y)} {B = [ x ] ≡ [ y ]} (λ ([ x≡y ]) → c [ x , y , x≡y ]))) ↝⟨ (∀-cong ext λ _ → Σ-cong (inverse $ Π-cong ext′ (EC.Erased-cong-↔ (inverse U.-²/≡↔-)) λ _ → Bijection.id) λ c → ∃-cong λ r → ∀-cong ext′ λ ([ x ]) → ∀-cong ext′ λ ([ y ]) → Is-equivalence-cong ext′ λ ([ x≡y ]) → c [ x , y , x≡y ] ≡⟨ BC.elim¹ᴱ (λ x≡y → c [ _ , _ , x≡y ] ≡ BC.[]-cong [ x≡y ]) ( c [ x , x , refl x ] ≡⟨ r [ x ] ⟩ refl [ x ] ≡⟨ sym BC.[]-cong-[refl] ⟩∎ BC.[]-cong [ refl x ] ∎) _ ⟩∎ BC.[]-cong [ x≡y ] ∎) ⟩ ((([ A ]) : Erased (Type a)) → ∃ λ (c : ((x : Erased A) → x ≡ x)) → ((x : Erased A) → c x ≡ refl x) × ((([ x ]) ([ y ]) : Erased A) → Is-equivalence {A = Erased (x ≡ y)} {B = [ x ] ≡ [ y ]} (λ ([ x≡y ]) → BC.[]-cong [ x≡y ]))) ↝⟨ (∀-cong ext λ _ → ∃-cong λ _ → drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (Π-closure ext′ 1 λ _ → Π-closure ext′ 1 λ _ → Eq.propositional ext′ _) (λ _ _ → BC.[]-cong-equivalence)) ⟩ ((([ A ]) : Erased (Type a)) → ∃ λ (c : ((x : Erased A) → x ≡ x)) → ((x : Erased A) → c x ≡ refl x)) ↝⟨ (∀-cong ext λ _ → inverse ΠΣ-comm) ⟩ ((([ A ]) : Erased (Type a)) (x : Erased A) → ∃ λ (c : x ≡ x) → c ≡ refl x) ↔⟨⟩ ((([ A ]) : Erased (Type a)) (x : Erased A) → Singleton (refl x)) ↝⟨ _⇔_.to contractible⇔↔⊤ $ (Π-closure ext 0 λ _ → Π-closure ext′ 0 λ _ → singleton-contractible _) ⟩□ ⊤ □) where ext′ : Extensionality a a ext′ = lower-extensionality _ lzero ext -- The type []-cong-axiomatisation a is contractible (assuming -- extensionality). []-cong-axiomatisation-contractible : Extensionality (lsuc a) a → Contractible ([]-cong-axiomatisation a) []-cong-axiomatisation-contractible {a = a} ext = propositional⇒inhabited⇒contractible ([]-cong-axiomatisation-propositional ext) (Extensionality→[]-cong-axiomatisation (lower-extensionality _ lzero ext)) ------------------------------------------------------------------------ -- An alternative to []-cong-axiomatisation -- An axiomatisation of substᴱ, restricted to a fixed universe, along -- with its computation rule. Substᴱ-axiomatisation : (ℓ : Level) → Type (lsuc ℓ) Substᴱ-axiomatisation ℓ = ∃ λ (substᴱ : {@0 A : Type ℓ} {@0 x y : A} (P : @0 A → Type ℓ) → @0 x ≡ y → P x → P y) → {@0 A : Type ℓ} {@0 x : A} {P : @0 A → Type ℓ} {p : P x} → substᴱ P (refl x) p ≡ p private -- The type []-cong-axiomatisation ℓ is logically equivalent to -- Substᴱ-axiomatisation ℓ. []-cong-axiomatisation⇔Substᴱ-axiomatisation : []-cong-axiomatisation ℓ ⇔ Substᴱ-axiomatisation ℓ []-cong-axiomatisation⇔Substᴱ-axiomatisation {ℓ = ℓ} = record { to = to; from = from } where to : []-cong-axiomatisation ℓ → Substᴱ-axiomatisation ℓ to ax = []-cong₁.substᴱ ax , []-cong₁.substᴱ-refl ax from : Substᴱ-axiomatisation ℓ → []-cong-axiomatisation ℓ from (substᴱ , substᴱ-refl) = λ where .[]-cong-axiomatisation.[]-cong → []-cong .[]-cong-axiomatisation.[]-cong-[refl] → substᴱ-refl .[]-cong-axiomatisation.[]-cong-equivalence {x = x} → _≃_.is-equivalence $ Eq.↔→≃ _ (λ [x]≡[y] → [ cong erased [x]≡[y] ]) (elim¹ (λ [x]≡[y] → substᴱ (λ y → [ x ] ≡ [ y ]) (cong erased [x]≡[y]) (refl [ x ]) ≡ [x]≡[y]) (substᴱ (λ y → [ x ] ≡ [ y ]) (cong erased (refl [ x ])) (refl [ x ]) ≡⟨ substᴱ (λ eq → substᴱ (λ y → [ x ] ≡ [ y ]) eq (refl [ x ]) ≡ substᴱ (λ y → [ x ] ≡ [ y ]) (refl x) (refl [ x ])) (sym $ cong-refl _) (refl _) ⟩ substᴱ (λ y → [ x ] ≡ [ y ]) (refl x) (refl [ x ]) ≡⟨ substᴱ-refl ⟩∎ refl [ x ] ∎)) (λ ([ x≡y ]) → []-cong [ elim¹ (λ x≡y → cong erased ([]-cong [ x≡y ]) ≡ x≡y) (cong erased ([]-cong [ refl _ ]) ≡⟨ cong (cong erased) substᴱ-refl ⟩ cong erased (refl [ _ ]) ≡⟨ cong-refl _ ⟩∎ refl _ ∎) x≡y ]) where []-cong : {@0 A : Type ℓ} {@0 x y : A} → Erased (x ≡ y) → [ x ] ≡ [ y ] []-cong {x = x} ([ x≡y ]) = substᴱ (λ y → [ x ] ≡ [ y ]) x≡y (refl [ x ]) -- The type Substᴱ-axiomatisation ℓ is propositional (assuming -- extensionality). -- -- The proof is based on a proof due to Nicolai Kraus that shows that -- "J + its computation rule" is contractible, see -- Equality.Instances-related.Equality-with-J-contractible. Substᴱ-axiomatisation-propositional : Extensionality (lsuc ℓ) (lsuc ℓ) → Is-proposition (Substᴱ-axiomatisation ℓ) Substᴱ-axiomatisation-propositional {ℓ = ℓ} ext = [inhabited⇒contractible]⇒propositional λ ax → let ax′ = _⇔_.from []-cong-axiomatisation⇔Substᴱ-axiomatisation ax module EC = Erased-cong ax′ ax′ in _⇔_.from contractible⇔↔⊤ (Substᴱ-axiomatisation ℓ ↔⟨ Eq.↔→≃ (λ (substᴱ , substᴱ-refl) _ P → (λ ([ _ , _ , x≡y ]) → substᴱ (λ A → P [ A ]) x≡y) , (λ _ _ → substᴱ-refl)) (λ hyp → (λ P x≡y p → hyp _ (λ ([ A ]) → P A) .proj₁ [ _ , _ , x≡y ] p) , hyp _ _ .proj₂ _ _) refl refl ⟩ ((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ) → ∃ λ (s : ((([ x , y , _ ]) : Erased (A ²/≡)) → P [ x ] → P [ y ])) → ((([ x ]) : Erased A) (p : P [ x ]) → s [ x , x , refl x ] p ≡ p)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext′ λ _ → Σ-cong (inverse $ Π-cong ext″ (EC.Erased-cong-↔ (inverse U.-²/≡↔-)) λ _ → Bijection.id) (λ _ → Bijection.id)) ⟩ ((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ) → ∃ λ (s : ((([ x ]) : Erased A) → P [ x ] → P [ x ])) → ((([ x ]) : Erased A) (p : P [ x ]) → s [ x ] p ≡ p)) ↝⟨ (∀-cong ext λ _ → ∀-cong ext′ λ _ → inverse $ ΠΣ-comm F.∘ (∀-cong ext″ λ _ → ΠΣ-comm)) ⟩ ((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ) (x : Erased A) (p : P x) → ∃ λ (p′ : P x) → p′ ≡ p) ↔⟨⟩ ((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ) (x : Erased A) (p : P x) → Singleton p) ↝⟨ (_⇔_.to contractible⇔↔⊤ $ Π-closure ext 0 λ _ → Π-closure ext′ 0 λ _ → Π-closure ext″ 0 λ _ → Π-closure ext″ 0 λ _ → singleton-contractible _) ⟩□ ⊤ □) where ext′ : Extensionality (lsuc ℓ) ℓ ext′ = lower-extensionality lzero _ ext ext″ : Extensionality ℓ ℓ ext″ = lower-extensionality _ _ ext -- The type []-cong-axiomatisation ℓ is equivalent to -- Substᴱ-axiomatisation ℓ (assuming extensionality). []-cong-axiomatisation≃Substᴱ-axiomatisation : []-cong-axiomatisation ℓ ↝[ lsuc ℓ ∣ lsuc ℓ ] Substᴱ-axiomatisation ℓ []-cong-axiomatisation≃Substᴱ-axiomatisation {ℓ = ℓ} = generalise-ext?-prop []-cong-axiomatisation⇔Substᴱ-axiomatisation ([]-cong-axiomatisation-propositional ∘ lower-extensionality lzero _) Substᴱ-axiomatisation-propositional ------------------------------------------------------------------------ -- Another alternative to []-cong-axiomatisation -- An axiomatisation of elim¹ᴱ, restricted to a fixed universe, along -- with its computation rule. Elimᴱ-axiomatisation : (ℓ : Level) → Type (lsuc ℓ) Elimᴱ-axiomatisation ℓ = ∃ λ (elimᴱ : {@0 A : Type ℓ} {@0 x y : A} (P : {@0 x y : A} → @0 x ≡ y → Type ℓ) → ((@0 x : A) → P (refl x)) → (@0 x≡y : x ≡ y) → P x≡y) → {@0 A : Type ℓ} {@0 x : A} {P : {@0 x y : A} → @0 x ≡ y → Type ℓ} (r : (@0 x : A) → P (refl x)) → elimᴱ P r (refl x) ≡ r x private -- The type Substᴱ-axiomatisation ℓ is logically equivalent to -- Elimᴱ-axiomatisation ℓ. Substᴱ-axiomatisation⇔Elimᴱ-axiomatisation : Substᴱ-axiomatisation ℓ ⇔ Elimᴱ-axiomatisation ℓ Substᴱ-axiomatisation⇔Elimᴱ-axiomatisation {ℓ = ℓ} = record { to = to; from = from } where to : Substᴱ-axiomatisation ℓ → Elimᴱ-axiomatisation ℓ to ax = elimᴱ , elimᴱ-refl where open []-cong₁ (_⇔_.from []-cong-axiomatisation⇔Substᴱ-axiomatisation ax) from : Elimᴱ-axiomatisation ℓ → Substᴱ-axiomatisation ℓ from (elimᴱ , elimᴱ-refl) = (λ P x≡y p → elimᴱ (λ {x = x} {y = y} _ → P x → P y) (λ _ → id) x≡y p) , (λ {_ _ _ p} → cong (_$ p) $ elimᴱ-refl _) -- The type Elimᴱ-axiomatisation ℓ is propositional (assuming -- extensionality). -- -- The proof is based on a proof due to Nicolai Kraus that shows that -- "J + its computation rule" is contractible, see -- Equality.Instances-related.Equality-with-J-contractible. Elimᴱ-axiomatisation-propositional : Extensionality (lsuc ℓ) (lsuc ℓ) → Is-proposition (Elimᴱ-axiomatisation ℓ) Elimᴱ-axiomatisation-propositional {ℓ = ℓ} ext = [inhabited⇒contractible]⇒propositional λ ax → let ax′ = _⇔_.from []-cong-axiomatisation⇔Substᴱ-axiomatisation $ _⇔_.from Substᴱ-axiomatisation⇔Elimᴱ-axiomatisation ax module EC = Erased-cong ax′ ax′ in _⇔_.from contractible⇔↔⊤ (Elimᴱ-axiomatisation ℓ ↔⟨ Eq.↔→≃ (λ (elimᴱ , elimᴱ-refl) _ P r → (λ ([ _ , _ , x≡y ]) → elimᴱ (λ x≡y → P [ _ , _ , x≡y ]) (λ x → r [ x ]) x≡y) , (λ _ → elimᴱ-refl _)) (λ hyp → (λ P r x≡y → hyp _ (λ ([ _ , _ , x≡y ]) → P x≡y) (λ ([ x ]) → r x) .proj₁ [ _ , _ , x≡y ]) , (λ _ → hyp _ _ _ .proj₂ _)) refl refl ⟩ ((([ A ]) : Erased (Type ℓ)) (P : Erased (A ²/≡) → Type ℓ) (r : (([ x ]) : Erased A) → P [ x , x , refl x ]) → ∃ λ (e : (x : Erased (A ²/≡)) → P x) → ((([ x ]) : Erased A) → e [ x , x , refl x ] ≡ r [ x ])) ↝⟨ (∀-cong ext λ _ → Π-cong {k₁ = bijection} ext′ (→-cong₁ ext″ (EC.Erased-cong-↔ U.-²/≡↔-)) λ _ → ∀-cong ext‴ λ _ → Σ-cong (inverse $ Π-cong ext‴ (EC.Erased-cong-↔ (inverse U.-²/≡↔-)) λ _ → Bijection.id) (λ _ → Bijection.id)) ⟩ ((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ) (r : (x : Erased A) → P x) → ∃ λ (e : (x : Erased A) → P x) → (x : Erased A) → e x ≡ r x) ↝⟨ (∀-cong ext λ _ → ∀-cong ext′ λ _ → ∀-cong ext‴ λ _ → inverse ΠΣ-comm) ⟩ ((([ A ]) : Erased (Type ℓ)) (P : Erased A → Type ℓ) (r : (x : Erased A) → P x) (x : Erased A) → ∃ λ (p : P x) → p ≡ r x) ↝⟨ (_⇔_.to contractible⇔↔⊤ $ Π-closure ext 0 λ _ → Π-closure ext′ 0 λ _ → Π-closure ext‴ 0 λ _ → Π-closure ext‴ 0 λ _ → singleton-contractible _) ⟩□ ⊤ □) where ext′ : Extensionality (lsuc ℓ) ℓ ext′ = lower-extensionality lzero _ ext ext″ : Extensionality ℓ (lsuc ℓ) ext″ = lower-extensionality _ lzero ext ext‴ : Extensionality ℓ ℓ ext‴ = lower-extensionality _ _ ext -- The type Substᴱ-axiomatisation ℓ is equivalent to -- Elimᴱ-axiomatisation ℓ (assuming extensionality). Substᴱ-axiomatisation≃Elimᴱ-axiomatisation : Substᴱ-axiomatisation ℓ ↝[ lsuc ℓ ∣ lsuc ℓ ] Elimᴱ-axiomatisation ℓ Substᴱ-axiomatisation≃Elimᴱ-axiomatisation = generalise-ext?-prop Substᴱ-axiomatisation⇔Elimᴱ-axiomatisation Substᴱ-axiomatisation-propositional Elimᴱ-axiomatisation-propositional -- The type []-cong-axiomatisation ℓ is equivalent to -- Elimᴱ-axiomatisation ℓ (assuming extensionality). []-cong-axiomatisation≃Elimᴱ-axiomatisation : []-cong-axiomatisation ℓ ↝[ lsuc ℓ ∣ lsuc ℓ ] Elimᴱ-axiomatisation ℓ []-cong-axiomatisation≃Elimᴱ-axiomatisation {ℓ = ℓ} ext = []-cong-axiomatisation ℓ ↝⟨ []-cong-axiomatisation≃Substᴱ-axiomatisation ext ⟩ Substᴱ-axiomatisation ℓ ↝⟨ Substᴱ-axiomatisation≃Elimᴱ-axiomatisation ext ⟩□ Elimᴱ-axiomatisation ℓ □
algebraic-stack_agda0000_doc_17160
{-# OPTIONS --safe #-} module Cubical.Categories.Instances.FunctorAlgebras where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism renaming (Iso to _≅_) open import Cubical.Foundations.Univalence open import Cubical.Categories.Category open import Cubical.Categories.Functor open import Cubical.Categories.NaturalTransformation.Base open _≅_ private variable ℓC ℓC' : Level module _ {C : Category ℓC ℓC'} (F : Functor C C) where open Category open Functor IsAlgebra : ob C → Type ℓC' IsAlgebra x = C [ F-ob F x , x ] record Algebra : Type (ℓ-max ℓC ℓC') where constructor algebra field carrier : ob C str : IsAlgebra carrier open Algebra IsAlgebraHom : (algA algB : Algebra) → C [ carrier algA , carrier algB ] → Type ℓC' IsAlgebraHom algA algB f = (f ∘⟨ C ⟩ str algA) ≡ (str algB ∘⟨ C ⟩ F-hom F f) record AlgebraHom (algA algB : Algebra) : Type ℓC' where constructor algebraHom field carrierHom : C [ carrier algA , carrier algB ] strHom : IsAlgebraHom algA algB carrierHom open AlgebraHom RepAlgebraHom : (algA algB : Algebra) → Type ℓC' RepAlgebraHom algA algB = Σ[ f ∈ C [ carrier algA , carrier algB ] ] IsAlgebraHom algA algB f isoRepAlgebraHom : (algA algB : Algebra) → AlgebraHom algA algB ≅ RepAlgebraHom algA algB fun (isoRepAlgebraHom algA algB) (algebraHom f isalgF) = f , isalgF inv (isoRepAlgebraHom algA algB) (f , isalgF) = algebraHom f isalgF rightInv (isoRepAlgebraHom algA algB) (f , isalgF) = refl leftInv (isoRepAlgebraHom algA algB) (algebraHom f isalgF)= refl pathRepAlgebraHom : (algA algB : Algebra) → AlgebraHom algA algB ≡ RepAlgebraHom algA algB pathRepAlgebraHom algA algB = ua (isoToEquiv (isoRepAlgebraHom algA algB)) AlgebraHom≡ : {algA algB : Algebra} {algF algG : AlgebraHom algA algB} → (carrierHom algF ≡ carrierHom algG) → algF ≡ algG carrierHom (AlgebraHom≡ {algA} {algB} {algF} {algG} p i) = p i strHom (AlgebraHom≡ {algA} {algB} {algF} {algG} p i) = idfun (PathP (λ j → (p j ∘⟨ C ⟩ str algA) ≡ (str algB ∘⟨ C ⟩ F-hom F (p j))) (strHom algF) (strHom algG) ) (fst (idfun (isContr _) (isOfHLevelPathP' 0 (isOfHLevelPath' 1 (isSetHom C) _ _) (strHom algF) (strHom algG)))) i idAlgebraHom : {algA : Algebra} → AlgebraHom algA algA carrierHom (idAlgebraHom {algA}) = id C strHom (idAlgebraHom {algA}) = ⋆IdR C (str algA) ∙∙ sym (⋆IdL C (str algA)) ∙∙ cong (λ φ → φ ⋆⟨ C ⟩ str algA) (sym (F-id F)) seqAlgebraHom : {algA algB algC : Algebra} (algF : AlgebraHom algA algB) (algG : AlgebraHom algB algC) → AlgebraHom algA algC carrierHom (seqAlgebraHom {algA} {algB} {algC} algF algG) = carrierHom algF ⋆⟨ C ⟩ carrierHom algG strHom (seqAlgebraHom {algA} {algB} {algC} algF algG) = str algA ⋆⟨ C ⟩ (carrierHom algF ⋆⟨ C ⟩ carrierHom algG) ≡⟨ sym (⋆Assoc C (str algA) (carrierHom algF) (carrierHom algG)) ⟩ (str algA ⋆⟨ C ⟩ carrierHom algF) ⋆⟨ C ⟩ carrierHom algG ≡⟨ cong (λ φ → φ ⋆⟨ C ⟩ carrierHom algG) (strHom algF) ⟩ (F-hom F (carrierHom algF) ⋆⟨ C ⟩ str algB) ⋆⟨ C ⟩ carrierHom algG ≡⟨ ⋆Assoc C (F-hom F (carrierHom algF)) (str algB) (carrierHom algG) ⟩ F-hom F (carrierHom algF) ⋆⟨ C ⟩ (str algB ⋆⟨ C ⟩ carrierHom algG) ≡⟨ cong (λ φ → F-hom F (carrierHom algF) ⋆⟨ C ⟩ φ) (strHom algG) ⟩ F-hom F (carrierHom algF) ⋆⟨ C ⟩ (F-hom F (carrierHom algG) ⋆⟨ C ⟩ str algC) ≡⟨ sym (⋆Assoc C (F-hom F (carrierHom algF)) (F-hom F (carrierHom algG)) (str algC)) ⟩ (F-hom F (carrierHom algF) ⋆⟨ C ⟩ F-hom F (carrierHom algG)) ⋆⟨ C ⟩ str algC ≡⟨ cong (λ φ → φ ⋆⟨ C ⟩ str algC) (sym (F-seq F (carrierHom algF) (carrierHom algG))) ⟩ F-hom F (carrierHom algF ⋆⟨ C ⟩ carrierHom algG) ⋆⟨ C ⟩ str algC ∎ AlgebrasCategory : Category (ℓ-max ℓC ℓC') ℓC' ob AlgebrasCategory = Algebra Hom[_,_] AlgebrasCategory = AlgebraHom id AlgebrasCategory = idAlgebraHom _⋆_ AlgebrasCategory = seqAlgebraHom ⋆IdL AlgebrasCategory algF = AlgebraHom≡ (⋆IdL C (carrierHom algF)) ⋆IdR AlgebrasCategory algF = AlgebraHom≡ (⋆IdR C (carrierHom algF)) ⋆Assoc AlgebrasCategory algF algG algH = AlgebraHom≡ (⋆Assoc C (carrierHom algF) (carrierHom algG) (carrierHom algH)) isSetHom AlgebrasCategory = subst isSet (sym (pathRepAlgebraHom _ _)) (isSetΣ (isSetHom C) (λ f → isProp→isSet (isSetHom C _ _))) ForgetAlgebra : Functor AlgebrasCategory C F-ob ForgetAlgebra = carrier F-hom ForgetAlgebra = carrierHom F-id ForgetAlgebra = refl F-seq ForgetAlgebra algF algG = refl module _ {C : Category ℓC ℓC'} {F G : Functor C C} (τ : NatTrans F G) where private module C = Category C open Functor open NatTrans open AlgebraHom AlgebrasFunctor : Functor (AlgebrasCategory G) (AlgebrasCategory F) F-ob AlgebrasFunctor (algebra a α) = algebra a (α C.∘ N-ob τ a) carrierHom (F-hom AlgebrasFunctor (algebraHom f isalgF)) = f strHom (F-hom AlgebrasFunctor {algebra a α} {algebra b β} (algebraHom f isalgF)) = (N-ob τ a C.⋆ α) C.⋆ f ≡⟨ C.⋆Assoc (N-ob τ a) α f ⟩ N-ob τ a C.⋆ (α C.⋆ f) ≡⟨ cong (N-ob τ a C.⋆_) isalgF ⟩ N-ob τ a C.⋆ (F-hom G f C.⋆ β) ≡⟨ sym (C.⋆Assoc _ _ _) ⟩ (N-ob τ a C.⋆ F-hom G f) C.⋆ β ≡⟨ cong (C._⋆ β) (sym (N-hom τ f)) ⟩ (F-hom F f C.⋆ N-ob τ b) C.⋆ β ≡⟨ C.⋆Assoc _ _ _ ⟩ F-hom F f C.⋆ (N-ob τ b C.⋆ β) ∎ F-id AlgebrasFunctor = AlgebraHom≡ F refl F-seq AlgebrasFunctor algΦ algΨ = AlgebraHom≡ F refl
algebraic-stack_agda0000_doc_17161
module Prelude where -------------------------------------------------------------------------------- open import Agda.Primitive public using (Level ; _⊔_) renaming (lzero to ℓ₀) id : ∀ {ℓ} → {X : Set ℓ} → X → X id x = x _◎_ : ∀ {ℓ ℓ′ ℓ″} → {X : Set ℓ} {P : X → Set ℓ′} {Q : ∀ {x} → P x → Set ℓ″} → (g : ∀ {x} → (y : P x) → Q y) (f : (x : X) → P x) (x : X) → Q (f x) (g ◎ f) x = g (f x) const : ∀ {ℓ ℓ′} → {X : Set ℓ} {Y : Set ℓ′} → X → Y → X const x y = x flip : ∀ {ℓ ℓ′ ℓ″} → {X : Set ℓ} {Y : Set ℓ′} {Z : X → Y → Set ℓ″} → (f : (x : X) (y : Y) → Z x y) (y : Y) (x : X) → Z x y flip f y x = f x y _∘_ : ∀ {ℓ ℓ′ ℓ″} → {X : Set ℓ} {Y : Set ℓ′} {Z : Set ℓ″} → (g : Y → Z) (f : X → Y) → X → Z g ∘ f = g ◎ f _⨾_ : ∀ {ℓ ℓ′ ℓ″} → {X : Set ℓ} {Y : Set ℓ′} {Z : Set ℓ″} → (f : X → Y) (g : Y → Z) → X → Z _⨾_ = flip _∘_ -------------------------------------------------------------------------------- open import Agda.Builtin.Equality public using (_≡_ ; refl) _⁻¹≡ : ∀ {ℓ} → {X : Set ℓ} {x₁ x₂ : X} → x₁ ≡ x₂ → x₂ ≡ x₁ refl ⁻¹≡ = refl _⦙≡_ : ∀ {ℓ} → {X : Set ℓ} {x₁ x₂ x₃ : X} → x₁ ≡ x₂ → x₂ ≡ x₃ → x₁ ≡ x₃ refl ⦙≡ refl = refl record PER {ℓ} (X : Set ℓ) (_≈_ : X → X → Set ℓ) : Set ℓ where infix 9 _⁻¹ infixr 4 _⦙_ field _⁻¹ : ∀ {x₁ x₂} → x₁ ≈ x₂ → x₂ ≈ x₁ _⦙_ : ∀ {x₁ x₂ x₃} → x₁ ≈ x₂ → x₂ ≈ x₃ → x₁ ≈ x₃ open PER {{…}} public instance per≡ : ∀ {ℓ} {X : Set ℓ} → PER X _≡_ per≡ = record { _⁻¹ = _⁻¹≡ ; _⦙_ = _⦙≡_ } infixl 9 _&_ _&_ : ∀ {ℓ ℓ′} → {X : Set ℓ} {Y : Set ℓ′} {x₁ x₂ : X} → (f : X → Y) → x₁ ≡ x₂ → f x₁ ≡ f x₂ f & refl = refl infixl 8 _⊗_ _⊗_ : ∀ {ℓ ℓ′} → {X : Set ℓ} {Y : Set ℓ′} {f₁ f₂ : X → Y} {x₁ x₂ : X} → f₁ ≡ f₂ → x₁ ≡ x₂ → f₁ x₁ ≡ f₂ x₂ refl ⊗ refl = refl case_of_ : ∀ {ℓ ℓ′} → {X : Set ℓ} {Y : Set ℓ′} → X → (X → Y) → Y case x of f = f x coe : ∀ {ℓ} → {X Y : Set ℓ} → X ≡ Y → X → Y coe refl x = x postulate fext! : ∀ {ℓ ℓ′} → {X : Set ℓ} {P : X → Set ℓ′} {f₁ f₂ : (x : X) → P x} → ((x : X) → f₁ x ≡ f₂ x) → f₁ ≡ f₂ fext¡ : ∀ {ℓ ℓ′} → {X : Set ℓ} {P : X → Set ℓ′} {f₁ f₂ : {x : X} → P x} → ({x : X} → f₁ {x} ≡ f₂ {x}) → (λ {x} → f₁ {x}) ≡ (λ {x} → f₂ {x}) -------------------------------------------------------------------------------- open import Agda.Builtin.Unit public using (⊤ ; tt) data ⊥ : Set where elim⊥ : ∀ {ℓ} → {X : Set ℓ} → ⊥ → X elim⊥ () ¬_ : ∀ {ℓ} → Set ℓ → Set ℓ ¬ X = X → ⊥ Π : ∀ {ℓ ℓ′} → Set ℓ → Set ℓ′ → Set (ℓ ⊔ ℓ′) Π X Y = X → Y infixl 6 _,_ record Σ {ℓ ℓ′} (X : Set ℓ) (P : X → Set ℓ′) : Set (ℓ ⊔ ℓ′) where instance constructor _,_ field proj₁ : X proj₂ : P proj₁ open Σ public infixl 5 _⁏_ pattern _⁏_ x y = x , y infixl 2 _×_ _×_ : ∀ {ℓ ℓ′} → Set ℓ → Set ℓ′ → Set (ℓ ⊔ ℓ′) X × Y = Σ X (λ x → Y) mapΣ : ∀ {ℓ ℓ′ ℓ″ ℓ‴} → {X : Set ℓ} {Y : Set ℓ′} {P : X → Set ℓ″} {Q : Y → Set ℓ‴} → (f : X → Y) (g : ∀ {x} → P x → Q (f x)) → Σ X P → Σ Y Q mapΣ f g (x , y) = f x , g y caseΣ : ∀ {ℓ ℓ′ ℓ″ ℓ‴} → {X : Set ℓ} {Y : Set ℓ′} {P : X → Set ℓ″} {Q : Y → Set ℓ‴} → Σ X P → (f : X → Y) (g : ∀ {x} → P x → Q (f x)) → Σ Y Q caseΣ p f g = mapΣ f g p infixl 1 _⊎_ data _⊎_ {ℓ ℓ′} (X : Set ℓ) (Y : Set ℓ′) : Set (ℓ ⊔ ℓ′) where inj₁ : (x : X) → X ⊎ Y inj₂ : (y : Y) → X ⊎ Y elim⊎ : ∀ {ℓ ℓ′ ℓ″} → {X : Set ℓ} {Y : Set ℓ′} {Z : Set ℓ″} → X ⊎ Y → (X → Z) → (Y → Z) → Z elim⊎ (inj₁ x) f g = f x elim⊎ (inj₂ y) f g = g y map⊎ : ∀ {ℓ ℓ′ ℓ″ ℓ‴} → {X : Set ℓ} {Y : Set ℓ′} {Z₁ : Set ℓ″} {Z₂ : Set ℓ‴} → (X → Z₁) → (Y → Z₂) → X ⊎ Y → Z₁ ⊎ Z₂ map⊎ f g s = elim⊎ s (inj₁ ∘ f) (inj₂ ∘ g) case⊎ : ∀ {ℓ ℓ′ ℓ″ ℓ‴} → {X : Set ℓ} {Y : Set ℓ′} {Z₁ : Set ℓ″} {Z₂ : Set ℓ‴} → X ⊎ Y → (X → Z₁) → (Y → Z₂) → Z₁ ⊎ Z₂ case⊎ s f g = map⊎ f g s -------------------------------------------------------------------------------- open import Agda.Builtin.Bool public using (Bool ; false ; true) if_then_else_ : ∀ {ℓ} → {X : Set ℓ} → Bool → X → X → X if_then_else_ true t f = t if_then_else_ false t f = f not : Bool → Bool not true = false not false = true and : Bool → Bool → Bool and true b = b and false b = false or : Bool → Bool → Bool or true b = true or false b = b xor : Bool → Bool → Bool xor true b = not b xor false b = b data True : Bool → Set where instance yes : True true -------------------------------------------------------------------------------- open import Agda.Builtin.Nat public using (Nat ; zero ; suc) open import Agda.Builtin.FromNat public using (Number ; fromNat) instance numNat : Number Nat numNat = record { Constraint = λ n → ⊤ ; fromNat = λ n → n } _>?_ : Nat → Nat → Bool zero >? k = false suc n >? zero = true suc n >? suc k = n >? k -------------------------------------------------------------------------------- data Fin : Nat → Set where zero : ∀ {n} → Fin (suc n) suc : ∀ {n} → Fin n → Fin (suc n) Nat→Fin : ∀ {n} → (k : Nat) {{_ : True (n >? k)}} → Fin n Nat→Fin {n = zero} k {{()}} Nat→Fin {n = suc n} zero {{is-true}} = zero Nat→Fin {n = suc n} (suc k) {{p}} = suc (Nat→Fin k {{p}}) instance numFin : ∀ {n} → Number (Fin n) numFin {n} = record { Constraint = λ k → True (n >? k) ; fromNat = Nat→Fin } --------------------------------------------------------------------------------
algebraic-stack_agda0000_doc_17162
-- Andreas, 2013-11-23 -- checking that postulates are allowed in new-style mutual blocks open import Common.Prelude -- new style mutual block even : Nat → Bool postulate odd : Nat → Bool even zero = true even (suc n) = odd n -- No error
algebraic-stack_agda0000_doc_17163
module Data.Num.Bijective where open import Data.Nat open import Data.Fin as Fin using (Fin; #_; fromℕ≤) open import Data.Fin.Extra open import Data.Fin.Properties using (bounded) open ≤-Reasoning renaming (begin_ to start_; _∎ to _□; _≡⟨_⟩_ to _≈⟨_⟩_) open import Level using () renaming (suc to lsuc) open import Function open import Relation.Nullary.Negation open import Relation.Nullary.Decidable open import Relation.Nullary open import Relation.Binary.PropositionalEquality as PropEq infixr 5 _∷_ -- For a system to be bijective wrt ℕ: -- * base ≥ 1 -- * digits = {1 .. base} data Bij : ℕ → Set where -- from the terminal object, which represents 0 ∙ : ∀ {b} -- base → Bij (suc b) -- base ≥ 1 -- successors _∷_ : ∀ {b} → Fin b -- digit = {1 .. b} → Bij b → Bij b infixr 9 _/_ -- syntax sugar for chaining digits with ℕ _/_ : ∀ {b} → (n : ℕ) → {lower-bound : True (suc zero ≤? n)} -- digit ≥ 1 → {upper-bound : True (n ≤? b)} -- digit ≤ base → Bij b → Bij b _/_ {b} zero {()} {ub} ns _/_ {b} (suc n) {lb} {ub} ns = (# n) {b} {ub} ∷ ns module _/_-Examples where 零 : Bij 2 零 = ∙ 一 : Bij 2 一 = 1 / ∙ 八 : Bij 3 八 = 2 / 2 / ∙ 八 : Bij 3 八 = 2 / 2 / ∙ open import Data.Nat.DM open import Data.Nat.Properties using (≰⇒>) open import Relation.Binary -- a digit at its largest full : ∀ {b} (x : Fin (suc b)) → Dec (Fin.toℕ {suc b} x ≡ b) full {b} x = Fin.toℕ x ≟ b -- a digit at its largest (for ℕ) full-ℕ : ∀ b n → Dec (n ≡ b) full-ℕ b n = n ≟ b ------------------------------------------------------------------------ -- Digit ------------------------------------------------------------------------ digit-toℕ : ∀ {b} → Fin b → ℕ digit-toℕ x = suc (Fin.toℕ x) digit+1-lemma : ∀ a b → a < suc b → a ≢ b → a < b digit+1-lemma zero zero a<1+b a≢b = contradiction refl a≢b digit+1-lemma zero (suc b) a<1+b a≢b = s≤s z≤n digit+1-lemma (suc a) zero (s≤s ()) a≢b digit+1-lemma (suc a) (suc b) (s≤s a<1+b) a≢b = s≤s (digit+1-lemma a b a<1+b (λ z → a≢b (cong suc z))) digit+1 : ∀ {b} → (x : Fin (suc b)) → Fin.toℕ x ≢ b → Fin (suc b) digit+1 {b} x ¬p = fromℕ≤ {digit-toℕ x} (s≤s (digit+1-lemma (Fin.toℕ x) b (bounded x) ¬p)) ------------------------------------------------------------------------ -- Bij ------------------------------------------------------------------------ 1+ : ∀ {b} → Bij (suc b) → Bij (suc b) 1+ ∙ = Fin.zero ∷ ∙ 1+ {b} (x ∷ xs) with full x 1+ {b} (x ∷ xs) | yes p = Fin.zero ∷ 1+ xs 1+ {b} (x ∷ xs) | no ¬p = digit+1 x ¬p ∷ xs n+ : ∀ {b} → ℕ → Bij (suc b) → Bij (suc b) n+ zero xs = xs n+ (suc n) xs = 1+ (n+ n xs) ------------------------------------------------------------------------ -- From and to ℕ ------------------------------------------------------------------------ toℕ : ∀ {b} → Bij b → ℕ toℕ ∙ = zero toℕ {b} (x ∷ xs) = digit-toℕ x + (toℕ xs * b) fromℕ : ∀ {b} → ℕ → Bij (suc b) fromℕ zero = ∙ fromℕ (suc n) = 1+ (fromℕ n) ------------------------------------------------------------------------ -- Functions on Bij ------------------------------------------------------------------------ -- infixl 6 _⊹_ -- -- _⊹_ : ∀ {b} → Bij b → Bij b → Bij b -- _⊹_ ∙ ys = ys -- _⊹_ xs ∙ = xs -- _⊹_ {zero} (() ∷ xs) (y ∷ ys) -- _⊹_ {suc b} (x ∷ xs) (y ∷ ys) with (suc (Fin.toℕ x + Fin.toℕ y)) divMod (suc b) -- _⊹_ {suc b} (x ∷ xs) (y ∷ ys) | result quotient remainder property div-eq mod-eq = -- remainder ∷ n+ quotient (xs ⊹ ys) -- old base = suc b -- new base = suc (suc b) increase-base : ∀ {b} → Bij (suc b) → Bij (suc (suc b)) increase-base {b} ∙ = ∙ increase-base {b} (x ∷ xs) with fromℕ {suc b} (toℕ (increase-base xs) * suc b) | inspect (λ ws → fromℕ {suc b} (toℕ ws * suc b)) (increase-base xs) increase-base {b} (x ∷ xs) | ∙ | [ eq ] = Fin.inject₁ x ∷ ∙ increase-base {b} (x ∷ xs) | y ∷ ys | [ eq ] with suc (Fin.toℕ x + Fin.toℕ y) divMod (suc (suc b)) increase-base {b} (x ∷ xs) | y ∷ ys | [ eq ] | result quotient remainder property div-eq mod-eq = remainder ∷ n+ quotient ys -- old base = suc (suc b) -- new base = suc b decrease-base : ∀ {b} → Bij (suc (suc b)) → Bij (suc b) decrease-base {b} ∙ = ∙ decrease-base {b} (x ∷ xs) with fromℕ {b} (toℕ (decrease-base xs) * suc (suc b)) | inspect (λ ws → fromℕ {b} (toℕ ws * suc (suc b))) (decrease-base xs) decrease-base {b} (x ∷ xs) | ∙ | [ eq ] with full x decrease-base {b} (x ∷ xs) | ∙ | [ eq ] | yes p = Fin.zero ∷ Fin.zero ∷ ∙ decrease-base {b} (x ∷ xs) | ∙ | [ eq ] | no ¬p = inject-1 x ¬p ∷ ∙ decrease-base {b} (x ∷ xs) | y ∷ ys | [ eq ] with (suc (Fin.toℕ x + Fin.toℕ y)) divMod (suc b) decrease-base (x ∷ xs) | y ∷ ys | [ eq ] | result quotient remainder property div-eq mod-eq = remainder ∷ n+ quotient ys
algebraic-stack_agda0000_doc_17164
module z-06 where open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _<?_; _<_; ≤-pred) open import Relation.Binary.PropositionalEquality using (_≡_; refl) import Relation.Binary.PropositionalEquality.Core as PE {- ------------------------------------------------------------------------------ -- 267 p 6.2.2 Shortcuts. C-c C-l typecheck and highlight the current file C-c C-, get information about the hole under the cursor C-c C-. show inferred type for proposed term for a hole C-c C-space give a solution C-c C-c case analysis on a variable C-c C-r refine the hole C-c C-a automatic fill C-c C-n which normalizes a term (useful to test computations) middle click definition of the term SYMBOLS ∧ \and ⊤ \top → \to ∀ \all Π \Pi λ \Gl ∨ \or ⊥ \bot ¬ \neg ∃ \ex Σ \Sigma ≡ \equiv ℕ \bN × \times ≤ \le ∈ \in ⊎ \uplus ∷ \:: ∎ \qed x₁ \_1 x¹ \^1 ------------------------------------------------------------------------------ -- p 268 6.2.3 The standard library. default path /usr/share/agda-stdlib Data.Empty empty type (⊥) Data.Unit unit type (⊤) Data.Bool booleans Data.Nat natural numbers (ℕ) Data.List lists Data.Vec vectors (lists of given length) Data.Fin types with finite number of elements Data.Integer integers Data.Float floating point numbers Data.Bin binary natural numbers Data.Rational rational numbers Data.String strings Data.Maybe option types Data.AVL balanced binary search trees Data.Sum sum types (⊎, ∨) Data.Product product types (×, ∧, ∃, Σ) Relation.Nullary negation (¬) Relation.Binary.PropositionalEquality equality (≡) ------------------------------------------------------------------------------ -- p 277 6.3.4 Postulates. for axioms (no proof) avoide as much as possible e.g, to work in classical logic, assume law of excluded middle with postulate lem : (A : Set) → ¬ A ⊎ A postulates do not compute: - applying 'lem' to type A, will not reduce to ¬ A or A (as expected for a coproduct) see section 6.5.6 ------------------------------------------------------------------------------ -- p 277 6.3.5 Records. -} -- implementation of pairs using records record Pair (A B : Set) : Set where constructor mkPair field fst : A snd : B make-pair : {A B : Set} → A → B → Pair A B make-pair a b = record { fst = a ; snd = b } make-pair' : {A B : Set} → A → B → Pair A B make-pair' a b = mkPair a b proj1 : {A B : Set} → Pair A B → A proj1 p = Pair.fst p ------------------------------------------------------------------------------ -- p 278 6.4 Inductive types: data -- p 278 6.4.1 Natural numbers {- data ℕ : Set where zero : ℕ -- base case suc : ℕ → ℕ -- inductive case -} pred : ℕ → ℕ pred zero = zero pred (suc n) = n _+'_ : ℕ → ℕ → ℕ zero +' n = n (suc m) +' n = suc (m +' n) infixl 6 _+'_ _∸'_ : ℕ → ℕ → ℕ zero ∸' n = zero suc m ∸' zero = suc m suc m ∸' suc n = m ∸' n _*'_ : ℕ → ℕ → ℕ zero *' n = zero suc m *' n = (m *' n) + n {- _mod'_ : ℕ → ℕ → ℕ m mod' n with m <? n m mod' n | yes _ = m m mod' n | no _ = (m ∸' n) mod' n -} -- TODO : what is going on here? -- mod' : ℕ → ℕ → ℕ -- mod' m n with m <? n -- ... | x = {!!} {- ------------------------------------------------------------------------------ -- p 280 Empty pattern matching. there is no case to pattern match on elements of this type use on types with no elements, e.g., -} data ⊥' : Set where -- given an element of type ⊥ then "produce" anything -- uses pattern : () -- means that no such pattern can happen ⊥'-elim : {A : Set} → ⊥' → A ⊥'-elim () {- since A is arbitrary, no way, in proof, to exhibit one. Do not have to. '()' states no cases to handle, so done Useful in negation and other less obvious ways of constructing empty inductive types. E.g., the type zero ≡ suc zero of equalities between 0 and 1 is also an empty inductive type. -} {- ------------------------------------------------------------------------------ -- p 281 Anonymous pattern matching. -} -- curly brackets before args, cases separated by semicolons: -- e.g., pred' : ℕ → ℕ pred' = λ { zero → zero ; (suc n) → n } {- ------------------------------------------------------------------------------ -- p 281 6.4.3 The induction principle. pattern matching corresponds to the presence of a recurrence or induction principle e.g., f : → A f zero = t f (suc n) = u' -- u' might be 'n' or result of recursive call f n recurrence principle expresses this as -} rec : {A : Set} → A → (ℕ → A → A) → ℕ → A rec t u zero = t rec t u (suc n) = u n (rec t u n) -- same with differenct var names recℕ : {A : Set} → A → (ℕ → A → A) → ℕ → A recℕ a n→a→a zero = a recℕ a n→a→a (suc n) = n→a→a n (recℕ a n→a→a n) {- Same as "recursor" for including nats to simply typed λ-calculus in section 4.3.6. Any function of type ℕ → A defined using pattern matching can be redefined using this function. This recurrence function encapsulates the expressive power of pattern matching. e.g., -} pred'' : ℕ → ℕ pred'' = rec zero (λ n _ → n) _ : pred'' 2 ≡ rec zero (λ n _ → n) 2 _ = refl _ : rec zero (λ n _ → n) 2 ≡ 1 _ = refl _ : pred'' 2 ≡ 1 _ = refl {- logical : recurrence principle corresponds to elimination rule, so aka "eliminator" Pattern matching in Agda is more powerful - can be used to define functions whose return type depends on argument means must consider functions of the form f : (n : ℕ) -> P n -- P : ℕ → Set f zero = t -- : P zero f (suc n) = u n (f n) -- : P (suc n) corresponding dependent variant of the recurrence principle is called the induction principle: -} rec' : (P : ℕ → Set) → P zero → ((n : ℕ) → P n → P (suc n)) → (n : ℕ) → P n rec' P Pz Ps zero = Pz rec' P Pz Ps (suc n) = Ps n (rec' P Pz Ps n) {- reading type as a logical formula, it says the recurrence principle over natural numbers: P (0) ⇒ (∀n ∈ ℕ.P (n) ⇒ P (n + 1)) ⇒ ∀n ∈ ℕ.P (n) -} -- proof using recursion +-zero' : (n : ℕ) → n + zero ≡ n +-zero' zero = refl +-zero' (suc n) = PE.cong suc (+-zero' n) -- proof using dependent induction principle +-zero'' : (n : ℕ) → n + zero ≡ n +-zero'' = rec' (λ n → n + zero ≡ n) refl (λ n p → PE.cong suc p) _ : +-zero'' 2 ≡ refl _ = refl _ : rec' (λ n → n + zero ≡ n) refl (λ n p → PE.cong suc p) ≡ λ n → rec' (λ z → z + zero ≡ z) refl (λ n → PE.cong (λ z → suc z)) n _ = refl ------------------------------------------------------------------------------ -- p 282 Booleans data Bool : Set where false : Bool true : Bool -- induction principle for booleans Bool-rec : (P : Bool → Set) → P false → P true → (b : Bool) → P b Bool-rec P Pf Pt false = Pf Bool-rec P Pf Pt true = Pt ------------------------------------------------------------------------------ -- p 283 Lists Data.List data List (A : Set) : Set where [] : List A _∷_ : A → List A → List A length : {A : Set} → List A → ℕ length [] = 0 length (_ ∷ xs) = 1 + length xs _++_ : {A : Set} → List A → List A → List A [] ++ l = l (x ∷ xs) ++ l = x ∷ (xs ++ l) List-rec : {A : Set} → (P : List A → Set) → P [] → ((x : A) → (xs : List A) → P xs → P (x ∷ xs)) → (xs : List A) → P xs List-rec P Pe Pc [] = Pe List-rec P Pe Pc (x ∷ xs) = Pc x xs (List-rec P Pe Pc xs) ------------------------------------------------------------------------------ -- p 284 6.4.7 Vectors. data Vec (A : Set) : ℕ → Set where [] : Vec A zero _∷_ : {n : ℕ} → A → Vec A n → Vec A (suc n) {- ------------------------------------------------------------------------------ -- p 284 Dependent types. type Vec A n depends on term n : a defining feature of dependent types. -} -- also, functions whose result type depends on argument, e.g., replicate : {A : Set} → A → (n : ℕ) → Vec A n replicate x zero = [] replicate x (suc n) = x ∷ replicate x n ------------------------------------------------------------------------------ -- p 285 Dependent pattern matching. -- since input is type Vec A (suc n), infers never applied to empty head : {n : ℕ} {A : Set} → Vec A (suc n) → A head (x ∷ xs) = x ------------------------------------------------------------------------------ -- p 285 Convertibility. -- Agda is able to compare types up to β-reduction on terms (zero + n reduces to n): -- - never distinguishes between two β-convertible terms _++'_ : {m n : ℕ} {A : Set} → Vec A m → Vec A n → Vec A (m + n) [] ++' l = l -- Vec A (zero + n) ≡ Vec A n (x ∷ xs) ++' l = x ∷ (xs ++' l) ------------------------------------------------------------------------------ -- p 285 Induction principle for Vec-rec -- induction principle for vectors Vec-rec : {A : Set} → (P : {n : ℕ} → Vec A n → Set) → P [] → ({n : ℕ} → (x : A) → (xs : Vec A n) → P xs → P (x ∷ xs)) → {n : ℕ} → (xs : Vec A n) → P xs Vec-rec P Pe Pc [] = Pe Vec-rec P Pe Pc (x ∷ xs) = Pc x xs (Vec-rec P Pe Pc xs) ------------------------------------------------------------------------------ -- p 285 Indices instead of parameters. -- general : can always encode a parameter as an index -- recommended using parameters whenever possible (Agda handles them more efficiently) -- use an index for type A (instead of a parameter) data VecI : Set → ℕ → Set where [] : {A : Set} → VecI A zero _∷_ : {A : Set} {n : ℕ} (x : A) (xs : VecI A n) → VecI A (suc n) -- induction principle for index VecI VecI-rec : (P : {A : Set} {n : ℕ} → VecI A n → Set) → ({A : Set} → P {A} []) → ({A : Set} {n : ℕ} (x : A) (xs : VecI A n) → P xs → P (x ∷ xs)) → {A : Set} → {n : ℕ} → (xs : VecI A n) → P xs VecI-rec P Pe Pc [] = Pe VecI-rec P Pe Pc (x ∷ xs) = Pc x xs (VecI-rec P Pe Pc xs) ------------------------------------------------------------------------------ -- p 286 6.4.8 Finite sets. -- has n elements data Fin' : ℕ → Set where fzero' : {n : ℕ} → Fin' (suc n) fsuc' : {n : ℕ} → Fin' n → Fin' (suc n) {- Fin n is collection of ℕ restricted to Fin n = {0,...,n − 1} above type corresponds to inductive set-theoretic definition: Fin 0 = ∅ Fin (n + 1) = {0} ∪ {i + 1 | i ∈ Fin n} -} finToℕ : {n : ℕ} → Fin' n → ℕ finToℕ fzero' = zero finToℕ (fsuc' i) = suc (finToℕ i) ------------------------------------------------------------------------------ -- p 286 Vector lookup using Fin -- Fin n typically used to index -- type ensures index in bounds lookup : {n : ℕ} {A : Set} → Fin' n → Vec A n → A lookup fzero' (x ∷ xs) = x lookup (fsuc' i) (x ∷ xs) = lookup i xs -- where index can be out of bounds open import Data.Maybe lookup' : ℕ → {A : Set} {n : ℕ} → Vec A n → Maybe A lookup' zero [] = nothing lookup' zero (x ∷ l) = just x lookup' (suc i) [] = nothing lookup' (suc i) (x ∷ l) = lookup' i l -- another option : add proof of i < n lookupP : {i n : ℕ} {A : Set} → i < n → Vec A n → A lookupP {i} {.0} () [] lookupP {zero} {.(suc _)} i<n (x ∷ l) = x lookupP {suc i} {.(suc _)} i<n (x ∷ l) = lookupP (≤-pred i<n) l {- ------------------------------------------------------------------------------ -- p 287 6.5 Inductive types: logic Use inductive types to implement types used as logical formulas, though the Curry-Howard correspondence. What follows is a dictionary between the two. ------------------------------------------------------------------------------ -- 6.5.1 Implication : corresponds to arrow (→) in types -} -- constant function -- classical formula A ⇒ B ⇒ A proved by K : {A B : Set} → A → B → A K x y = x -- composition -- classical formula (A ⇒ B ⇒ C) ⇒ (A ⇒ B) ⇒ A ⇒ C proved by S : {A B C : Set} → (A → B → C) → (A → B) → A → C S g f x = g x (f x) {- ------------------------------------------------------------------------------ -- 6.5.2 Product : corresponds to conjunction defined in Data.Product -} data _×_ (A B : Set) : Set where _,_ : A → B → A × B -- aka fst proj₁ : {A B : Set} → A × B → A proj₁ (a , b) = a -- aka snd proj₂ : {A B : Set} → A × B → B proj₂ (a , b) = b -- proof of A ∧ B ⇒ B ∧ A (commutativity of conjunction) ×-comm : {A B : Set} → A × B → B × A ×-comm (a , b) = (b , a) -- proof of curryfication ×-→ : {A B C : Set} → (A × B → C) → (A → B → C) ×-→ f x y = f (x , y) -- and →-× : {A B C : Set} → (A → B → C) → (A × B → C) →-× f (x , y) = f x y {- introduction rule for conjunction: Γ ⊢ A Γ ⊢ B -------------- (∧I) Γ ⊢ A ∧ B general : when logical connectives are defined with inductive types, - CONSTRUCTORS CORRESPOND TO INTRODUCTION RULES ------------------------------------------------------------------------------ Induction principle : ELIMINATION RULE CORRESPONDS TO THE ASSOCIATED INDUCTION PRINCIPLE -} -- for case where P does not depend on its arg ×-rec : {A B : Set} → (P : Set) → (A → B → P) → A × B → P ×-rec P Pp (x , y) = Pp x y {- corresponds to elimination rule for conjunction: Γ, A,B ⊢ P Γ ⊢ A ∧ B ------------------------- (∧E) Γ ⊢ P if the premises are true then the conclusion is also true -} -- dependent induction principle -- corresponds to the elimination rule in dependent types -- see 8.3.3 ×-ind : {A B : Set} → (P : A × B → Set) → ((x : A) → (y : B) → P (x , y)) → (p : A × B) → P p ×-ind P Pp (x , y) = Pp x y {- ------------------------------------------------------------------------------ -- p 289 6.5.3 Unit type : corresponds to truth Data.Unit -} data ⊤ : Set where tt : ⊤ -- constructor is introduction rule {- ----- (⊤I) Γ ⊢ ⊤ -} -- induction principle ⊤-rec : (P : ⊤ → Set) → P tt → (t : ⊤) → P t ⊤-rec P Ptt tt = Ptt {- know from logic there is no elimination rule associated with truth but can write rule that corresponds to induction principle: Γ ⊢ P Γ ⊢ ⊤ --------------- (⊤E) Γ ⊢ P not interesting from a logical point of view: if P holds and ⊤ holds then can deduce that P holds, which was already known ------------------------------------------------------------------------------ -- 6.5.4 Empty type : corresponds to falsity Data.Empty -} data ⊥ : Set where -- no constructor, so no introduction rule -- dependent induction principle ⊥-d-elim : (P : ⊥ → Set) → (x : ⊥) → P x ⊥-d-elim P () -- non-dependent variant of this principle ⊥-elim : (P : Set) → ⊥ → P ⊥-elim P () -- () is the empty pattern in Agda -- indicates there are no cases to handle when matching on a value of type {- corresponds to explosion principle, which is the associated elimination rule Γ ⊢ ⊥ ---- (⊥E) Γ ⊢ P ------------------------------------------------------------------------------ 6.5.5 Negation Relation.Nullary -} ¬ : Set → Set ¬ A = A → ⊥ -- e.g., A ⇒ ¬¬A proved: nni : {A : Set} → A → ¬ (¬ A) nni A ¬A = ¬A A {- ------------------------------------------------------------------------------ p 290 6.5.6 Coproduct : corresponds to disjunction Data.Sum -} data _⊎_ (A : Set) (B : Set) : Set where inj₁ : A → A ⊎ B -- called injection of A into A ⊎ B inj₂ : B → A ⊎ B -- ditto B {- The two constructors correspond to the two introduction rules Γ ⊢ A --------- (∨ᴸI) Γ ⊢ A ∨ B Γ ⊢ B --------- (∨ᴿI) Γ ⊢ A ∨ B -} -- commutativity of disjunction ⊎-comm : (A B : Set) → A ⊎ B → B ⊎ A ⊎-comm A B (inj₁ x) = inj₂ x ⊎-comm A B (inj₂ y) = inj₁ y {- -- proof of (A ∨ ¬A) ⇒ ¬¬A ⇒ A lem-raa : {A : Set} → A ⊎ ¬ A → ¬ (¬ A) → A lem-raa (inj₁ a) _ = a lem-raa (inj₂ ¬a) k = ⊥-elim (k ¬a) -- ⊥ !=< Set -} -- induction principle ⊎-rec : {A B : Set} → (P : A ⊎ B → Set) → ((x : A) → P (inj₁ x)) → ((y : B) → P (inj₂ y)) → (u : A ⊎ B) → P u ⊎-rec P P₁ P₂ (inj₁ x) = P₁ x ⊎-rec P P₁ P₂ (inj₂ y) = P₂ y {- non-dependent induction principle corresponds to the elimination rule Γ, A ⊢ P Γ, B ⊢ P Γ ⊢ A ∨ B ----------------------------- (∨E) Γ ⊢ P ------------------------------------------------------------------------------ Decidable types : A type A is decidable when it is known whether it is inhabited or not i.e. a proof of A ∨ ¬A could define predicate: Dec A is a proof that A is decidable -} Dec' : Set → Set Dec' A = A ⊎ ¬ A -- by definition of the disjunction {- Agda convention write yes/no instead of inj₁/inj₂ because it answers the question: is A provable? defined in Relation.Nullary as -- p 291 A type A is decidable when -} data Dec (A : Set) : Set where yes : A → Dec A no : ¬ A → Dec A {- logic of Agda is intuitionistic therefore A ∨ ¬A not provable for any type A, and not every type is decidable it can be proved that no type is not decidable (see 2.3.5 and 6.6.8) -} nndec : (A : Set) → ¬ (¬ (Dec A)) nndec A n = n (no (λ a → n (yes a))) {- ------------------------------------------------------------------------------ -- p 291 6.5.7 Π-types : corresponds to universal quantification dependent types : types that depend on terms some connectives support dependent generalizations e.g., generalization of function types A → B to dependent function types (x : A) → B where x might occur in B. the type B of the returned value depends on arg x e.g., replicate : {A : Set} → A → (n : ℕ) → Vec A n Dependent function types are also called Π-types often written Π(x : A).B can be define as (note: there is builtin notation in Agda) -} data Π {A : Set} (A : Set) (B : A → Set) : Set where Λ : ((a : A) → B a) → Π A B {- an element of Π A B is a dependent function (x : A) → B x bound universal quantification bounded (the type A over which the variable ranges) corresponds to ∀x ∈ A.B(x) proof of that formula corresponds to a function which - to every x in A - associates a proof of B(x) why Agda allows the notation ∀ x → B x for the above type (leaves A implicit) Exercise 6.5.7.1. Show that the type Π Bool (λ { false → A ; true → B }) is isomorphic to A × B ------------------------------------------------------------------------------ -- p 292 6.5.8 Σ-types : corresponds to bounded existential quantification Data.Product -} -- dependent variant of product types : a : A , b : B a data Σ (A : Set) (B : A → Set) : Set where _,_ : (a : A) → B a → Σ A B -- actual Agda def is done using a record dproj₁ : {A : Set} {B : A → Set} → Σ A B → A dproj₁ (a , b) = a dproj₂ : {A : Set} {B : A → Set} → (s : Σ A B) → B (dproj₁ s) dproj₂ (a , b) = b {- Logical interpretation type Σ A B is bounded existential quantification ∃x ∈ A.B(x) set theoretic interpretation corresponds to constructing sets by comprehension {x ∈ A | B(x)} the set of elements x of A such that B(x) is satisfied e.g., in set theory - given a function f : A → B - its image Im(f) is the subset of B consisting of elements in the image of f. formally defined Im(f) = {y ∈ B | ∃x ∈ A.f (x) = y} translated to with two Σ types - one for the comprehension - one for the universal quantification -} Im : {A B : Set} (f : A → B) → Set Im {A} {B} f = Σ B (λ y → Σ A (λ x → f x ≡ y)) -- e.g., can show that every function f : A → B has a right inverse (or section) -- g : Im(f) → A sec : {A B : Set} (f : A → B) → Im f → A sec f (y , (x , p)) = x {- ------------------------------------------------------------------------------ -- p 293 : the axiom of choice for every relation R ⊆ A × B satisfying ∀x ∈ A.∃y ∈ B.(x, y) ∈ R there is a function f : A → B such that ∀x ∈ A.(x, f (x)) ∈ R section 6.5.9 defined type Rel A B corresponding to relations between types A and B using Rel, can prov axiom of choice -} -- AC : {A B : Set} (R : Rel A B) -- TODO -- → ((x : A) → Σ B (λ y → R x y)) -- → Σ (A → B) (λ f → ∀ x → R x (f x)) -- AC R f = (λ x → proj₁ (f x)) , (λ x → proj₂ (f x)) {- the arg that corresponds to the proof of (6.1), is constructive a function which to every element x of type A associates a pair of an element y of B and a proof that (x, y) belongs to the relation. By projecting it on the first component, necessary function f is obtained (associates an element of B to each element of A) use the second component to prove that it satisfies the required property the "classical" variant of the axiom of choice does not have access to the proof of (6.1) -- it only knows its existence. another description is thus where the double negation has killed the contents of the proof, see section 2.5.9 postulate CAC : {A B : Set} (R : Rel A B) → ¬ ¬ ((x : A) → Σ B (λ y → R x y)) → ¬ ¬ Σ (A → B) (λ f → ∀ x → R x (f x)) see 9.3.4. ------------------------------------------------------------------------------ -- p 293 : 6.5.9 Predicates In classical logic, the set Bool of booleans is the set of truth values: - a predicate on a set A can either be false or true - modeled as a function A → Bool In Agda/intuitionistic logic - not so much interested in truth value of predicate - but rather in its proofs - so the role of truth values is now played by Set predicate P on a type A is term of type A → Set which to every element x of A associates the type of proofs of P x ------------------------------------------------------------------------------ -- p 294 Relations Relation.Binary In classical mathematics, a relation R on a set A is a subset of A × A (see A.1) x of A is in relation with an element y when (x, y) ∈ R relation on A can also be encoded as a function : A × A → 𝔹 or, curryfication, : A → A → 𝔹 in this representation, x is in relation with y when R(x, y) = 1 In Agda/intuitionistic - relations between types A and B as type Rel A - obtained by replacing the set 𝔹 of truth values with Set in the above description: -} Rel : Set → Set₁ Rel A = A → A → Set -- e.g. -- _≤_ : type Rel ℕ -- _≡_ : type Rel A {- ------------------------------------------------------------------------------ Inductive predicates (predicates defined by induction) -} data isEven : ℕ → Set where even-z : isEven zero -- 0 is even even-s : {n : ℕ} → isEven n → isEven (suc (suc n)) -- if n is even then n + 2 is even {- corresponds to def of set E ⊆ N of even numbers as the smallest set of numbers such that 0 ∈ E and n ∈ E ⇒ n+2 ∈ E -} data _≤_ : ℕ → ℕ → Set where z≤n : {n : ℕ} → zero ≤ n s≤s : {m n : ℕ} (m≤n : m ≤ n) → suc m ≤ suc n {- smallest relation on ℕ such that 0 ≤ 0 and m ≤ n implies m+1 ≤ n+1 inductive predicate definitions enable reasoning by induction over those predicates/relations -} ≤-refl : {n : ℕ} → (n ≤ n) ≤-refl {zero} = z≤n ≤-refl {suc n} = s≤s ≤-refl -- p 295 ≤-trans : {m n p : ℕ} → (m ≤ n) → (n ≤ p) → (m ≤ p) ≤-trans z≤n n≤p = z≤n ≤-trans (s≤s m≤n) (s≤s n≤p) = s≤s (≤-trans m≤n n≤p) {- inductive defs good because of Agda's support for reasoning by induction (and dependent pattern matching) leading to simpler proofs other defs possible -- base on classical equivalence, for m, n ∈ N, m ≤ n ⇔ ∃m' ∈ N.m + m' = n _≤'_ : ℕ → ℕ → Set m ≤' n = Σ (λ m' → m + m' ≡eq n) another: -} le : ℕ → ℕ → Bool le zero n = true le (suc m) zero = false le (suc m) (suc n) = le m n _≤'_ : ℕ → ℕ → Set m ≤' n = le m n ≡ true {- EXERCISE : show reflexivity and transitivity with the alternate formalizations involved example implicational fragment of intuitionistic natural deduction is formalized in section 7.2 the relation Γ ⊢ A between a context Γ and a type A which is true when the sequent is provable is defined inductively ------------------------------------------------------------------------------ -- p 295 6.6 Equality Relation.Binary.PropositionalEquality -- typed equality : compare elements of same type data _≡_ {A : Set} (x : A) : A → Set where refl : x ≡ x -- only way to be equal is to be the same ------------------------------------------------------------------------------ 6.6.1 Equality and pattern matching example proof with equality : successor function on natural numbers is injective - for every natural numbers m and n - m + 1 = n + 1 ⇒ m = n -} -- p 296 suc-injective : {m n : ℕ} → suc m ≡ suc n → m ≡ n -- suc-injective {m} {n} p -- Goal: m ≡ n; p : suc m ≡ suc n -- case split on p : it can ONLY be refl -- therefore m is equal to n -- so agda provide .m - not really an arg - something equal to m suc-injective {m} {.m} refl -- m ≡ m = refl {- ------------------------------------------------------------------------------ -- p 296 6.6.2 Main properties of equality: reflexive, congruence, symmetric, transitive -} sym : {A : Set} {x y : A} → x ≡ y → y ≡ x sym refl = refl trans : {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z trans refl refl = refl cong : ∀ {A B : Set} (f : A → B) {x y : A} → x ≡ y → f x ≡ f y cong f refl = refl -- substitutivity : enables transporting the elements of a type along an equality {- subst : {A : Set} (P : A → Set) → {x y : A} → x ≡ y → P x → P y subst P refl p = p -} -- https://stackoverflow.com/a/27789403 subst : ∀ {a p} {A : Set a} (P : A → Set p) {x y : A} → x ≡ y → P x → P y subst P refl p = p -- coercion : enables converting an element of type to another equal type coe : {A B : Set} → A ≡ B → A → B coe p x = subst (λ A → A) p x -- see 9.1 {- ------------------------------------------------------------------------------ -- p 296 6.6.3 Half of even numbers : example every even number has a half using proof strategy from 2.3 traditional notation : show ∀n ∈ N. isEven(n) ⇒ ∃m ∈ ℕ.m + m = n -} +-suc : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n) +-suc zero n = refl +-suc (suc m) n = cong suc (+-suc m n) -- even-half : {n : ℕ} -- → isEven n -- → Σ (λ m → m + m ≡ n) -- TODO (m : ℕ) → Set !=< Set -- even-half even-z = zero , refl -- even-half (even-s e) with even-half e -- even-half (even-s e) | m , p = -- suc m , cong suc (trans (+-suc m m) (cong suc p)) {- second case : by induction have m such that m + m = n need to construct a half for n + 2: m + 1 show that it is a half via (m + 1) + (m + 1) = (m + (m + 1)) + 1 by definition of addition = ((m + m) + 1) + 1 by +-suc = (n + 1) + 1 since m + m = n implemented using transitivity of equality and fact that it is a congruence (m + 1 = n + 1 from m = n) also use auxiliary lemma m + (n + 1) = (m + n) + 1 -} {- ------------------------------------------------------------------------------ -- p 297 6.6.4 Reasoning -} --import Relation.Binary.PropositionalEquality as Eq --open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎) infix 3 _∎ infixr 2 _≡⟨⟩_ _≡⟨_⟩_ infix 1 begin_ begin_ : ∀ {ℓ} {A : Set ℓ} {x y : A} → x ≡ y → x ≡ y begin_ x≡y = x≡y _≡⟨⟩_ : ∀ {ℓ} {A : Set ℓ} (x {y} : A) → x ≡ y → x ≡ y _ ≡⟨⟩ x≡y = x≡y _≡⟨_⟩_ : {A : Set} (x {y z} : A) → x ≡ y → y ≡ z → x ≡ z _ ≡⟨ x≡y ⟩ y≡z = trans x≡y y≡z _∎ : ∀ {ℓ} {A : Set ℓ} (x : A) → x ≡ x _∎ _ = refl +-zero : ∀ (n : ℕ) → n + zero ≡ n +-zero zero = refl +-zero (suc n) rewrite +-zero n = refl +-comm : (m n : ℕ) → m + n ≡ n + m +-comm m zero = +-zero m +-comm m (suc n) = begin (m + suc n) ≡⟨ +-suc m n ⟩ -- m + (n + 1) = (m + n) + 1 -- by +-suc suc (m + n) ≡⟨ cong suc (+-comm m n) ⟩ -- = (n + m) + 1 -- by induction hypothesis suc (n + m) ∎ -- p 297 -- another proof using properties of equality +-comm' : (m n : ℕ) → m + n ≡ n + m +-comm' m zero = +-zero m +-comm' m (suc n) = trans (+-suc m n) (cong suc (+-comm m n)) {- ------------------------------------------------------------------------------ -- p 298 6.6.5 Definitional equality two terms which are convertible (i.e. re duce to a common term) are considered to be EQUAL. not ≡, but equality internal to Agda, referred to as definitional equality - cannot distinguish between two definitionally equal terms - e.g., zero + n is definitionally equal to n (because addition defined that way) - definitional equality implies equality by refl: -} +-zero''' : (n : ℕ) → zero + n ≡ n +-zero''' n = refl -- n + zero and n are not definitionally equal (because def of addition) -- but can be proved +-0 : (n : ℕ) → n + zero ≡ n +-0 zero = refl +-0 (suc n) = cong suc (+-zero n) -- implies structure of definitions is important (and an art form) ------------------------------------------------------------------------------ -- p 298 6.6.6 More properties with equality -- zero is NOT the successor of any NAT zero-suc : {n : ℕ} → zero ≡ suc n → ⊥ zero-suc () +-assoc : (m n o : ℕ) → (m + n) + o ≡ m + (n + o) +-assoc zero n o = refl +-assoc (suc m) n o = cong suc (+-assoc m n o) -- p 299 *-+-dist-r : (m n o : ℕ) → (m + n) * o ≡ m * o + n * o *-+-dist-r zero n o = refl *-+-dist-r (suc m) n o rewrite +-comm n o | *-+-dist-r m n o | +-assoc o (m * o) (n * o) = refl *-assoc : (m n o : ℕ) → (m * n) * o ≡ m * (n * o) *-assoc zero n o = refl *-assoc (suc m) n o rewrite *-+-dist-r n (m * n) o | *-assoc m n o = refl ------------------------------------------------------------------------------ -- p 299 Lists ++-empty' : {A : Set} → (l : List A) → [] ++ l ≡ l ++-empty' l = refl empty-++ : {A : Set} → (l : List A) → l ++ [] ≡ l empty-++ [] = refl empty-++ (x ∷ l) = cong (x ∷_) (empty-++ l) ++-assoc : {A : Set} → (l1 l2 l3 : List A) → ((l1 ++ l2) ++ l3) ≡ (l1 ++ (l2 ++ l3)) ++-assoc [] l2 l3 = refl ++-assoc (x ∷ l1) l2 l3 = cong (x ∷_) (++-assoc l1 l2 l3) -- TODO DOES NOT COMPILE: Set₁ != Set -- ++-not-comm : ¬ ({A : Set} → (l1 l2 : List A) -- → (l1 ++ l2) ≡ (l2 ++ l1)) -- ++-not-comm f with f (1 ∷ []) (2 ∷ []) -- ... | () ++-length : {A : Set} → (l1 l2 : List A) → length (l1 ++ l2) ≡ length l1 + length l2 ++-length [] l2 = refl ++-length (x ∷ l1) l2 = cong (1 +_) (++-length l1 l2) -- p 300 -- adds element to end of list snoc : {A : Set} → List A → A → List A snoc [] x = x ∷ [] snoc (y ∷ l) x = y ∷ (snoc l x) -- reverse a list rev : {A : Set} → List A → List A rev [] = [] rev (x ∷ l) = snoc (rev l) x -- reversing a list with x as the last element will prodice a list with x as the first element rev-snoc : {A : Set} → (l : List A) → (x : A) → rev (snoc l x) ≡ x ∷ (rev l) rev-snoc [] x = refl rev-snoc (y ∷ l) x = cong (λ l → snoc l y) (rev-snoc l x) -- reverse twice rev-rev : {A : Set} → (l : List A) → rev (rev l) ≡ l rev-rev [] = refl rev-rev (x ∷ l) = trans (rev-snoc (rev l) x) (cong (x ∷_) (rev-rev l)) -------------------------------------------------- -- p 300 6.6.7 The J rule. -- equality data _≡'_ {A : Set} : A → A → Set where refl' : {x : A} → x ≡' x -- has associated induction principle : J rule: -- to prove P depending on equality proof p, -- - prove it when this proof is refl J : {A : Set} {x y : A} (p : x ≡' y) (P : (x y : A) → x ≡' y → Set) (r : (x : A) → P x x refl') → P x y p J {A} {x} {.x} refl' P r = r x {- section 6.6 shows that definition usually taken in Agda is different (it uses a parameter instead of an index for the first argument of type A), so that the resulting induction principle is a variant: -} J' : {A : Set} (x : A) (P : (y : A) → x ≡' y → Set) (r : P x refl') (y : A) (p : x ≡' y) → P y p J' x P r .x refl' = r {- -------------------------------------------------- p 301 6.6.8 Decidable equality. A type A is decidable when either A or ¬A is provable. Write Dec A for the type of proofs of decidability of A - yes p, where p is a proof of A, or - no q, where q is a proof of ¬A A relation on a type A is decidable when - the type R x y is decidable - for every elements x and y of type A. -} -- in Relation.Binary -- term of type Decidable R is proof that relation R is decidable Decidable : {A : Set} (R : A → A → Set) → Set Decidable {A} R = (x y : A) → Dec (R x y) {- A type A has decidable equality when equality relation _≡_ on A is decidable. - means there is a function/algorithm able to determine, given two elements of A, whether they are equal or not - return a PROOF (not a boolean) -} _≟_ : Decidable {A = Bool} _≡_ false ≟ false = yes refl true ≟ true = yes refl false ≟ true = no (λ ()) true ≟ false = no (λ ()) _≟ℕ_ : Decidable {A = ℕ} _≡_ zero ≟ℕ zero = yes refl zero ≟ℕ suc n = no(λ()) suc m ≟ℕ zero = no(λ()) suc m ≟ℕ suc n with m ≟ℕ n ... | yes refl = yes refl ... | no ¬p = no (λ p → ¬p (suc-injective p)) {- -------------------------------------------------- p 301 6.6.9 Heterogeneous equality : enables comparing (seemingly) distinct types due to McBride [McB00] p 302 e.g., show concatenation of vectors is associative (l1 ++ l2) ++ l3 ≡ l1 ++ (l2 ++ l3) , where lengths are m, n and o equality ≡ only used on terms of same type - but types above are - left Vec A ((m + n) + o) - right Vec A (m + (n + o)) the two types are propositionally equal, can prove Vec A ((m + n) + o) ≡ Vec A (m + (n + o)) by cong (Vec A) (+-assoc m n o) but the two types are not definitionally equal (required to compare terms with ≡) PROOF WITH STANDARD EQUALITY. To compare vecs, use above propositional equality and'coe' to cast one of the members to the same type as other. term coe (cong (Vec A) (+-assoc m n o)) has type Vec A ((m + n) + o) → Vec A (m + (n + o)) -} -- lemma : if l and l’ are propositional equal vectors, -- up to propositional equality of their types as above, -- then x : l and x : l’ are also propositionally equal: ∷-cong : {A : Set} → {m n : ℕ} {l1 : Vec A m} {l2 : Vec A n} → (x : A) → (p : m ≡ n) → coe (PE.cong (Vec A) p) l1 ≡ l2 → coe (PE.cong (Vec A) (PE.cong suc p)) (x ∷ l1) ≡ x ∷ l2 ∷-cong x refl refl = refl -- TODO this needs Vec ++ (only List ++ in scope) -- ++-assoc' : {A : Set} {m n o : ℕ} -- → (l1 : Vec A m) -- → (l2 : Vec A n) -- → (l3 : Vec A o) -- → coe (PE.cong (Vec A) (+-assoc m n o)) -- ((l1 ++ l2) ++ l3) ≡ l1 ++ (l2 ++ l3) -- ++-assoc' [] l2 l3 = refl -- ++-assoc' {_} {suc m} {n} {o} (x ∷ l1) l2 l3 = ∷-cong x (+-assoc m n o) (++-assoc' l1 l2 l3) {- p 303 Proof with heterogeneous equality - TODO ------------------------------------------------------------------------------ p 303 6.7 Proving programs in practice correctness means it agrees with a specification correctness properties - absence of errors : uses funs with args in correct domain (e.g., no divide by zero) - invariants : properties always satisfied during execution - functional properties : computes expected output on any given input p 304 6.7.1 Extrinsic vs intrinsic proofs extrinsic : first write program then prove properties about it (from "outside") e.g., sort : List ℕ → List ℕ intrinsic : incorporate properties in types e.g., sort : List ℕ → SortList ℕ example: length of concat of two lists is sum of their lengths -} -- extrinsic proof ++-length' : {A : Set} → (l1 l2 : List A) → length (l1 ++ l2) ≡ length l1 + length l2 ++-length' [] l2 = refl ++-length' (x ∷ l1) l2 = PE.cong suc (++-length' l1 l2) -- intrinsic _V++_ : {m n : ℕ} {A : Set} → Vec A m → Vec A n → Vec A (m + n) [] V++ l = l (x ∷ l) V++ l' = x ∷ (l V++ l') ------------------------------------------------------------------------------ -- p 305 6.7.2 Insertion sort
algebraic-stack_agda0000_doc_17165
module TrustMe where open import Data.String open import Data.String.Unsafe open import Data.Unit.Polymorphic using (⊤) open import IO import IO.Primitive as Prim open import Relation.Binary.PropositionalEquality open import Relation.Nullary -- Check that trustMe works. testTrustMe : IO ⊤ testTrustMe with "apa" ≟ "apa" ... | yes refl = putStrLn "Yes!" ... | no _ = putStrLn "No." main : Prim.IO ⊤ main = run testTrustMe
algebraic-stack_agda0000_doc_17166
-- Mapping of Haskell types to Agda Types module Foreign.Haskell.Types where open import Prelude open import Builtin.Float {-# FOREIGN GHC import qualified GHC.Float #-} {-# FOREIGN GHC import qualified Data.Text #-} HSUnit = ⊤ HSBool = Bool HSInteger = Int HSList = List HSChar = Char HSString = HSList HSChar HSText = String postulate HSFloat : Set HSFloat=>Float : HSFloat → Float lossyFloat=>HSFloat : Float → HSFloat HSInt : Set HSInt=>Int : HSInt → Int lossyInt=>HSInt : Int → HSInt {-# COMPILE GHC HSFloat = type Float #-} {-# COMPILE GHC HSFloat=>Float = GHC.Float.float2Double #-} {-# COMPILE GHC lossyFloat=>HSFloat = GHC.Float.double2Float #-} {-# COMPILE GHC HSInt = type Int #-} {-# COMPILE GHC HSInt=>Int = toInteger #-} {-# COMPILE GHC lossyInt=>HSInt = fromInteger #-} {-# FOREIGN GHC type AgdaTuple a b c d = (c, d) #-} data HSTuple {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where _,_ : A → B → HSTuple A B {-# COMPILE GHC HSTuple = data MAlonzo.Code.Foreign.Haskell.Types.AgdaTuple ((,)) #-}
algebraic-stack_agda0000_doc_17167
open import Prelude module Implicits.Resolution.Termination.Lemmas where open import Induction.WellFounded open import Induction.Nat open import Data.Fin.Substitution open import Implicits.Syntax open import Implicits.Syntax.Type.Unification open import Implicits.Substitutions open import Implicits.Substitutions.Lemmas open import Data.Nat hiding (_<_) open import Data.Nat.Properties open import Relation.Binary using (module DecTotalOrder) open DecTotalOrder decTotalOrder using () renaming (refl to ≤-refl) open import Extensions.Nat open import Implicits.Resolution.Termination.Lemmas.SizeMeasures public -- open import Implicits.Resolution.Termination.Lemmas.Stack public
algebraic-stack_agda0000_doc_4080
------------------------------------------------------------------------ -- The Agda standard library -- -- The Maybe type ------------------------------------------------------------------------ -- The definitions in this file are reexported by Data.Maybe. module Data.Maybe.Core where open import Level data Maybe {a} (A : Set a) : Set a where just : (x : A) → Maybe A nothing : Maybe A {-# IMPORT Data.FFI #-} {-# COMPILED_DATA Maybe Data.FFI.AgdaMaybe Just Nothing #-}
algebraic-stack_agda0000_doc_4081
module Type.Identity.Proofs where import Lvl open import Structure.Function open import Structure.Relator.Properties open import Structure.Relator open import Structure.Type.Identity open import Type.Identity open import Type private variable ℓ ℓ₁ ℓ₂ ℓₑ ℓₑ₁ ℓₑ₂ ℓₚ : Lvl.Level private variable T A B : Type{ℓ} private variable P : T → Type{ℓ} private variable _▫_ : A → B → Type{ℓ} instance Id-reflexivity : Reflexivity(Id{T = T}) Reflexivity.proof Id-reflexivity = intro instance Id-identityEliminator : IdentityEliminator{ℓₚ = ℓₚ}(Id{T = T}) IdentityEliminator.elim Id-identityEliminator = elim instance Id-identityEliminationOfIntro : IdentityEliminationOfIntro{ℓₘ = ℓ}(Id{T = T})(Id) IdentityEliminationOfIntro.proof Id-identityEliminationOfIntro P p = intro instance Id-identityType : IdentityType(Id) Id-identityType = intro {- open import Logic.Propositional open import Logic.Propositional.Equiv open import Relator.Equals.Proofs open import Structure.Setoid te : ⦃ equiv-A : Equiv{ℓₑ}(A)⦄ → ∀{f : A → Type{ℓ}} → Function ⦃ equiv-A ⦄ ⦃ [↔]-equiv ⦄ (f) test : ⦃ equiv-A : Equiv{ℓₑ}(A)⦄ → ∀{P : A → Type{ℓ}} → UnaryRelator ⦃ equiv-A ⦄ (P) UnaryRelator.substitution test eq p = [↔]-to-[→] (Function.congruence te eq) p -}
algebraic-stack_agda0000_doc_4082
-- Abstract constructors module Issue476c where module M where data D : Set abstract data D where c : D x : M.D x = M.c
algebraic-stack_agda0000_doc_4083
module Array.APL where open import Array.Base open import Array.Properties open import Data.Nat open import Data.Nat.DivMod hiding (_/_) open import Data.Nat.Properties open import Data.Fin using (Fin; zero; suc; raise; toℕ; fromℕ≤) open import Data.Fin.Properties using (toℕ<n) open import Data.Vec open import Data.Vec.Properties open import Data.Product open import Agda.Builtin.Float open import Function open import Relation.Binary.PropositionalEquality hiding (Extensionality) open import Relation.Nullary open import Relation.Nullary.Decidable open import Relation.Nullary.Negation --open import Relation.Binary -- Now we start to introduce APL operators trying -- to maintain syntactic rules and semantics. -- We won't be able to mimic explicit concatenations -- like 2 3 4 is a vector [2, 3, 4], as we would have -- to overload the " " somehow. -- This relation describes promotion of the scalar element in -- dyadic operations. data dy-args : ∀ n m k → (Vec ℕ n) → (Vec ℕ m) → (Vec ℕ k) → Set where instance n-n : ∀ {n}{s} → dy-args n n n s s s n-0 : ∀ {n}{s}{s₁} → dy-args n 0 n s s₁ s 0-n : ∀ {n}{s}{s₁} → dy-args 0 n n s s₁ s₁ dyadic-type : ∀ a → Set a → Set a dyadic-type a X = ∀ {n m k}{s s₁ s₂}{{c : dy-args n m k s s₁ s₂}} → Ar X n s → Ar X m s₁ → Ar X k s₂ lift-binary-op : ∀ {a}{X : Set a} → ∀ (op : X → X → X) → dyadic-type a X lift-binary-op op ⦃ c = n-n ⦄ (imap f) (imap g) = imap λ iv → op (f iv) (g iv) lift-binary-op op {s₁ = []} ⦃ c = n-0 ⦄ (imap f) (imap g) = imap λ iv → op (f iv) (g []) lift-binary-op op {s = [] } ⦃ c = 0-n ⦄ (imap f) (imap g) = imap λ iv → op (f []) (g iv) lift-unary-op : ∀ {a}{X : Set a} → ∀ (op : X → X) → ∀ {n s} → Ar X n s → Ar X n s lift-unary-op f (imap g) = imap (λ iv → f (g iv)) dyadic-type-c : ∀ a → Set a → Set a dyadic-type-c a X = ∀ {n m k}{s s₁ s₂} → Ar X n s → dy-args n m k s s₁ s₂ → Ar X m s₁ → Ar X k s₂ -- Nat operations infixr 20 _+ₙ_ infixr 20 _×ₙ_ _+ₙ_ = lift-binary-op _+_ _×ₙ_ = lift-binary-op _*_ _-safe-_ : (a : ℕ) → (b : ℕ) .{≥ : a ≥ b} → ℕ a -safe- b = a ∸ b -- FIXME As _-ₙ_ requires a proof, we won't consider yet -- full dyadic types for _-ₙ_, as it would require us -- to define dyadic types for ≥a. infixr 20 _-ₙ_ _-ₙ_ : ∀ {n}{s} → (a : Ar ℕ n s) → (b : Ar ℕ n s) → .{≥ : a ≥a b} → Ar ℕ n s (imap f -ₙ imap g) {≥} = imap λ iv → (f iv -safe- g iv) {≥ = ≥ iv} --≢-sym : ∀ {X : Set}{a b : X} → a ≢ b → b ≢ a --≢-sym pf = pf ∘ sym infixr 20 _÷ₙ_ _÷ₙ_ : ∀ {n}{s} → (a : Ar ℕ n s) → (b : Ar ℕ n s) → {≥0 : cst 0 <a b} → Ar ℕ n s _÷ₙ_ (imap f) (imap g) {≥0} = imap λ iv → (f iv div g iv) {≢0 = fromWitnessFalse (≢-sym $ <⇒≢ $ ≥0 iv) } infixr 20 _+⟨_⟩ₙ_ infixr 20 _×⟨_⟩ₙ_ _+⟨_⟩ₙ_ : dyadic-type-c _ _ a +⟨ c ⟩ₙ b = _+ₙ_ {{c = c}} a b _×⟨_⟩ₙ_ : dyadic-type-c _ _ a ×⟨ c ⟩ₙ b = _×ₙ_ {{c = c}} a b -- Float operations infixr 20 _+ᵣ_ _+ᵣ_ = lift-binary-op primFloatPlus infixr 20 _-ᵣ_ _-ᵣ_ = lift-binary-op primFloatMinus infixr 20 _×ᵣ_ _×ᵣ_ = lift-binary-op primFloatTimes -- XXX we can request the proof that the right argument is not zero. -- However, the current primFloatDiv has the type Float → Float → Float, so... infixr 20 _÷ᵣ_ _÷ᵣ_ = lift-binary-op primFloatDiv infixr 20 _×⟨_⟩ᵣ_ _×⟨_⟩ᵣ_ : dyadic-type-c _ _ a ×⟨ c ⟩ᵣ b = _×ᵣ_ {{c = c}} a b infixr 20 _+⟨_⟩ᵣ_ _+⟨_⟩ᵣ_ : dyadic-type-c _ _ a +⟨ c ⟩ᵣ b = _+ᵣ_ {{c = c}} a b infixr 20 _-⟨_⟩ᵣ_ _-⟨_⟩ᵣ_ : dyadic-type-c _ _ a -⟨ c ⟩ᵣ b = _-ᵣ_ {{c = c}} a b infixr 20 _÷⟨_⟩ᵣ_ _÷⟨_⟩ᵣ_ : dyadic-type-c _ _ a ÷⟨ c ⟩ᵣ b = _÷ᵣ_ {{c = c}} a b infixr 20 *ᵣ_ *ᵣ_ = lift-unary-op primFloatExp module xx where a : Ar ℕ 2 (3 ∷ 3 ∷ []) a = cst 1 s : Ar ℕ 0 [] s = cst 2 test₁ = a +ₙ a test₂ = a +ₙ s test₃ = s +ₙ a --test = (s +ₙ s) test₄ = s +⟨ n-n ⟩ₙ s test₅ : ∀ {n s} → Ar ℕ n s → Ar ℕ 0 [] → Ar ℕ n s test₅ = _+ₙ_ infixr 20 ρ_ ρ_ : ∀ {ℓ}{X : Set ℓ}{d s} → Ar X d s → Ar ℕ 1 (d ∷ []) ρ_ {s = s} _ = s→a s infixr 20 ,_ ,_ : ∀ {a}{X : Set a}{n s} → Ar X n s → Ar X 1 (prod s ∷ []) ,_ {s = s} (p) = imap λ iv → unimap p (off→idx s iv) -- Reshape infixr 20 _ρ_ _ρ_ : ∀ {a}{X : Set a}{n}{sa} → (s : Ar ℕ 1 (n ∷ [])) → (a : Ar X n sa) -- if the `sh` is non-empty, `s` must be non-empty as well. → {s≢0⇒ρa≢0 : prod (a→s s) ≢ 0 → prod sa ≢ 0} → Ar X n (a→s s) _ρ_ {sa = sa} s a {s≢0⇒ρa≢0} with prod sa ≟ 0 | prod (a→s s) ≟ 0 _ρ_ {sa = sa} s a {s≢0⇒ρa≢0} | _ | yes s≡0 = mkempty (a→s s) s≡0 _ρ_ {sa = sa} s a {s≢0⇒ρa≢0} | yes ρa≡0 | no s≢0 = contradiction ρa≡0 (s≢0⇒ρa≢0 s≢0) _ρ_ {sa = sa} s a {s≢0⇒ρa≢0} | no ρa≢0 | _ = imap from-flat where from-flat : _ from-flat iv = let off = idx→off (a→s s) iv --{!!} -- (ix-lookup iv zero) flat = unimap $ , a ix = (toℕ (ix-lookup off zero) mod prod sa) {≢0 = fromWitnessFalse ρa≢0} in flat (ix ∷ []) reduce-1d : ∀ {a}{X : Set a}{n} → Ar X 1 (n ∷ []) → (X → X → X) → X → X reduce-1d {n = zero} (imap p) op neut = neut reduce-1d {n = suc n} (imap p) op neut = op (p $ zero ∷ []) (reduce-1d (imap (λ iv → p (suc (ix-lookup iv zero) ∷ []))) op neut) {- This goes right to left if we want to reduce-1d (imap λ iv → p ((raise 1 $ ix-lookup iv zero) ∷ [])) op (op neut (p $ zero ∷ [])) -} Scal : ∀ {a} → Set a → Set a Scal X = Ar X 0 [] scal : ∀ {a}{X : Set a} → X → Scal X scal = cst unscal : ∀ {a}{X : Set a} → Scal X → X unscal (imap f) = f [] module true-reduction where thm : ∀ {a}{X : Set a}{n m} → (s : Vec X (n + m)) → s ≡ take n s ++ drop n s thm {n = n} s with splitAt n s thm {n = n} .(xs ++ ys) | xs , ys , refl = refl thm2 : ∀ {a}{X : Set a} → (v : Vec X 1) → v ≡ head v ∷ [] thm2 (x ∷ []) = refl -- This is a variant with take _/⟨_⟩_ : ∀ {a}{X : Set a}{n}{s : Vec ℕ (n + 1)} → (X → X → X) → X → Ar X (n + 1) s → Ar X n (take n s) _/⟨_⟩_ {n = n} {s} f neut a = let x = nest {s = take n s} {s₁ = drop n s} $ subst (λ x → Ar _ _ x) (thm {n = n} s) a in imap λ iv → reduce-1d (subst (λ x → Ar _ _ x) (thm2 (drop n s)) $ unimap x iv) f neut _/₁⟨_⟩_ : ∀ {a}{X : Set a}{n}{s : Vec ℕ n}{m} → (X → X → X) → X → Ar X (n + 1) (s ++ (m ∷ [])) → Ar X n s _/₁⟨_⟩_ {n = n} {s} f neut a = let x = nest {s = s} a in imap λ iv → reduce-1d (unimap x iv) f neut module test-reduce where a : Ar ℕ 2 (4 ∷ 4 ∷ []) a = cst 1 b : Ar ℕ 1 (5 ∷ []) b = cst 2 test₁ = _/⟨_⟩_ {n = 0} _+_ 0 (, a) test₂ = _/⟨_⟩_ {n = 0} _+_ 0 b -- FIXME! This reduction does not implement semantics of APL, -- as it assumes that we always reduce to scalars! -- Instead, in APL / reduce on the last axis only, -- i.e. ⍴ +/3 4 5 ⍴ ⍳1 = 3 4 -- This is mimicing APL's f/ syntax, but with extra neutral -- element. We can later introduce the variant where certain -- operations come with pre-defined neutral elements. _/⟨_⟩_ : ∀ {a}{X : Set a}{n s} → (Scal X → Scal X → Scal X) → Scal X → Ar X n s → Scal X f /⟨ neut ⟩ a = let op x y = unscal $ f (scal x) (scal y) a-1d = , a neut = unscal neut in scal $ reduce-1d a-1d op neut -- XXX I somehow don't understand how to make X to be an arbitrary Set a... data reduce-neut : {X : Set} → (Scal X → Scal X → Scal X) → Scal X → Set where instance plus-nat : reduce-neut _+⟨ n-n ⟩ₙ_ (cst 0) mult-nat : reduce-neut _×⟨ n-n ⟩ₙ_ (cst 1) plus-flo : reduce-neut (_+ᵣ_ {{c = n-n}}) (cst 0.0) mult-flo : reduce-neut (_×ᵣ_ {{c = n-n}}) (cst 1.0) infixr 20 _/_ _/_ : ∀ {X : Set}{n s neut} → (op : Scal X → Scal X → Scal X) → {{c : reduce-neut op neut}} → Ar X n s → Scal X _/_ {neut = neut} f a = f /⟨ neut ⟩ a module test-reduce where a = s→a $ 1 ∷ 2 ∷ 3 ∷ 4 ∷ [] test₁ : reduce-1d a _+_ 0 ≡ 10 test₁ = refl test₂ : _+⟨ n-n ⟩ₙ_ /⟨ scal 0 ⟩ a ≡ scal 10 test₂ = refl test₃ : _+ₙ_ / a ≡ scal 10 test₃ = refl -- This is somewhat semi-useful dot-product expressed -- pretty close to what you'd write in APL. dotp : ∀ {n s} → Ar ℕ n s → Ar ℕ n s → Scal ℕ dotp a b = _+ₙ_ / a ×ₙ b test₄ : dotp a a ≡ scal (1 + 4 + 9 + 16) test₄ = refl -- The size of the leading axis. infixr 20 ≢_ ≢_ : ∀ {a}{X : Set a}{n s} → Ar X n s → Scal ℕ ≢_ {n = zero} a = scal 1 ≢_ {n = suc n} {s} a = scal $ head s data iota-type : (d : ℕ) → (n : ℕ) → (Vec ℕ d) → Set where instance iota-scal : iota-type 0 1 [] iota-vec : ∀ {n} → iota-type 1 n (n ∷ []) iota-res-t : ∀ {d n s} → iota-type d n s → (sh : Ar ℕ d s) → Set iota-res-t {n = n} iota-scal sh = Ar (Σ ℕ λ x → x < unscal sh) 1 (unscal sh ∷ []) iota-res-t {n = n} iota-vec sh = Ar (Σ (Ar ℕ 1 (n ∷ [])) λ v → v <a sh) n (a→s sh) 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 infixr 20 ι_ ι_ : ∀ {d n s}{{c : iota-type d n s}} → (sh : Ar ℕ d s) → iota-res-t c sh ι_ ⦃ c = iota-scal ⦄ s = (imap λ iv → (toℕ $ ix-lookup iv zero) , toℕ<n (ix-lookup iv zero)) ι_ {n = n} {s = s ∷ []} ⦃ c = iota-vec ⦄ (imap sh) = imap cast-ix→a where cast-ix→a : _ cast-ix→a iv = let ix , pf = ix→a iv in ix , λ jv → a<b⇒b≡c⇒a<c (pf jv) (s→a∘a→s (imap sh) jv) -- Zilde and comma ⍬ : ∀ {a}{X : Set a} → Ar X 1 (0 ∷ []) ⍬ = imap λ iv → magic-fin $ ix-lookup iv zero -- XXX We are going to use _·_ instead of _,_ as the -- latter is a constructor of dependent sum. Renaming -- all the occurrences to something else would take -- a bit of work which we should do later. infixr 30 _·_ _·_ : ∀ {a}{X : Set a}{n} → X → Ar X 1 (n ∷ []) → Ar X 1 (suc n ∷ []) x · (imap p) = imap λ iv → case ix-lookup iv zero of λ where zero → x (suc j) → p (j ∷ []) -- Note that two dots in an upper register combined with -- the underscore form the _̈ symbol. When the symbol is -- used on its own, it looks like ̈ which is the correct -- "spelling". infixr 20 _̈_ _̈_ : ∀ {a}{X Y : Set a}{n s} → (X → Y) → Ar X n s → Ar Y n s f ̈ imap p = imap λ iv → f $ p iv -- Take and Drop ax+sh<s : ∀ {n} → (ax sh s : Ar ℕ 1 (n ∷ [])) → (s≥sh : s ≥a sh) → (ax <a (s -ₙ sh) {≥ = s≥sh}) → (ax +ₙ sh) <a s ax+sh<s (imap ax) (imap sh) (imap s) s≥sh ax<s-sh iv = let ax+sh<s-sh+sh = +-monoˡ-< (sh iv) (ax<s-sh iv) s-sh+sh≡s = m∸n+n≡m (s≥sh iv) in a<b⇒b≡c⇒a<c ax+sh<s-sh+sh s-sh+sh≡s _↑_ : ∀ {a}{X : Set a}{n s} → (sh : Ar ℕ 1 (n ∷ [])) → (a : Ar X n s) → {pf : s→a s ≥a sh} → Ar X n $ a→s sh _↑_ {s = s} sh (imap f) {pf} with (prod $ a→s sh) ≟ 0 _↑_ {s = s} sh (imap f) {pf} | yes Πsh≡0 = mkempty _ Πsh≡0 _↑_ {s = s} (imap q) (imap f) {pf} | no Πsh≢0 = imap mtake where mtake : _ mtake iv = let ai , ai< = ix→a iv ix<q jv = a<b⇒b≡c⇒a<c (ai< jv) (s→a∘a→s (imap q) jv) ix = a→ix ai (s→a s) λ jv → ≤-trans (ix<q jv) (pf jv) in f (subst-ix (a→s∘s→a s) ix) _↓_ : ∀ {a}{X : Set a}{n s} → (sh : Ar ℕ 1 (n ∷ [])) → (a : Ar X n s) → {pf : (s→a s) ≥a sh} → Ar X n $ a→s $ (s→a s -ₙ sh) {≥ = pf} _↓_ {s = s} sh (imap x) {pf} with let p = prod $ a→s $ (s→a s -ₙ sh) {≥ = pf} in p ≟ 0 _↓_ {s = s} sh (imap f) {pf} | yes Π≡0 = mkempty _ Π≡0 _↓_ {s = s} (imap q) (imap f) {pf} | no Π≢0 = imap mkdrop where mkdrop : _ mkdrop iv = let ai , ai< = ix→a iv ax = ai +ₙ (imap q) thmx = ax+sh<s ai (imap q) (s→a s) pf λ jv → a<b⇒b≡c⇒a<c (ai< jv) (s→a∘a→s ((s→a s -ₙ (imap q)) {≥ = pf}) jv) ix = a→ix ax (s→a s) thmx in f (subst-ix (a→s∘s→a s) ix) _̈⟨_⟩_ : ∀ {a}{X Y Z : Set a}{n s} → Ar X n s → (X → Y → Z) → Ar Y n s → Ar Z n s --(imap p) ̈⟨ f ⟩ (imap p₁) = imap λ iv → f (p iv) (p₁ iv) p ̈⟨ f ⟩ p₁ = imap λ iv → f (unimap p iv) (unimap p₁ iv)
algebraic-stack_agda0000_doc_4084
module Numeral.Natural.Coprime.Proofs where open import Functional open import Logic open import Logic.Classical open import Logic.Propositional open import Logic.Propositional.Theorems import Lvl open import Numeral.Finite open import Numeral.Natural open import Numeral.Natural.Coprime open import Numeral.Natural.Decidable open import Numeral.Natural.Function.GreatestCommonDivisor open import Numeral.Natural.Relation.Divisibility.Proofs open import Numeral.Natural.Oper open import Numeral.Natural.Prime open import Numeral.Natural.Prime.Proofs open import Numeral.Natural.Relation.Divisibility open import Numeral.Natural.Relation.Order open import Numeral.Natural.Relation.Order.Proofs open import Relator.Equals open import Structure.Relator.Properties open import Type.Properties.Decidable.Proofs open import Type private variable n x y d p : ℕ -- 1 is the only number coprime to itself because it does not have any divisors except for itself. Coprime-reflexivity-condition : Coprime(n)(n) ↔ (n ≡ 1) Coprime-reflexivity-condition {n} = [↔]-intro l (r{n}) where l : Coprime(n)(n) ← (n ≡ 1) Coprime.proof(l [≡]-intro) {a} a1 _ = [1]-only-divides-[1] (a1) r : ∀{n} → Coprime(n)(n) → (n ≡ 1) r {𝟎} (intro z1) = z1 Div𝟎 Div𝟎 r {𝐒(𝟎)} _ = [≡]-intro r {𝐒(𝐒(n))} (intro ssn1) = ssn1 {𝐒(𝐒(n))} divides-reflexivity divides-reflexivity instance Coprime-symmetry : Symmetry(Coprime) Coprime.proof(Symmetry.proof Coprime-symmetry (intro proof)) {n} nx ny = proof {n} ny nx -- The only number coprime to 0 is 1 because while all numbers divide 0, only 1 divides 1. Coprime-of-0-condition : ∀{x} → Coprime(0)(x) → (x ≡ 1) Coprime-of-0-condition {0} (intro n1) = n1 Div𝟎 Div𝟎 Coprime-of-0-condition {1} (intro n1) = [≡]-intro Coprime-of-0-condition {𝐒(𝐒(x))} (intro n1) = n1 Div𝟎 divides-reflexivity -- 1 is coprime to all numbers because only 1 divides 1. Coprime-of-1 : Coprime(1)(x) Coprime.proof (Coprime-of-1 {x}) {n} n1 nx = [1]-only-divides-[1] n1 Coprime-of-[+] : Coprime(x)(y) → Coprime(x)(x + y) Coprime.proof (Coprime-of-[+] {x}{y} (intro proof)) {n} nx nxy = proof {n} nx ([↔]-to-[→] (divides-without-[+] nxy) nx) -- Coprimality is obviously equivalent to the greatest common divisor being 1 by definition. Coprime-gcd : Coprime(x)(y) ↔ (gcd(x)(y) ≡ 1) Coprime-gcd = [↔]-transitivity ([↔]-intro l r) Gcd-gcd-value where l : Coprime(x)(y) ← Gcd(x)(y) 1 Coprime.proof (l p) nx ny = [1]-only-divides-[1] (Gcd.maximum₂ p nx ny) r : Coprime(x)(y) → Gcd(x)(y) 1 Gcd.divisor(r (intro coprim)) 𝟎 = [1]-divides Gcd.divisor(r (intro coprim)) (𝐒 𝟎) = [1]-divides Gcd.maximum(r (intro coprim)) dv with [≡]-intro ← coprim (dv 𝟎) (dv(𝐒 𝟎)) = [1]-divides -- A smaller number and a greater prime number is coprime. -- If the greater number is prime, then no smaller number will divide it except for 1, and greater numbers never divide smaller ones. -- Examples (y = 7): -- The prime factors of 7 is only itself (because it is prime). -- Then the only alternatives for x are: -- x ∈ {1,2,3,4,5,6} -- None of them is able to have 7 as a prime factor because it is greater: -- 1=1, 2=2, 3=3, 4=2⋅2, 5=5, 6=2⋅3 Coprime-of-Prime : (𝐒(x) < y) → Prime(y) → Coprime(𝐒(x))(y) Coprime.proof (Coprime-of-Prime (succ(succ lt)) prim) nx ny with prime-only-divisors prim ny Coprime.proof (Coprime-of-Prime (succ(succ lt)) prim) nx ny | [∨]-introₗ n1 = n1 Coprime.proof (Coprime-of-Prime (succ(succ lt)) prim) nx ny | [∨]-introᵣ [≡]-intro with () ← [≤]-to-[≯] lt ([≤]-without-[𝐒] (divides-upper-limit nx)) -- A prime number either divides a number or forms a coprime pair. -- If a prime number does not divide a number, then it cannot share any divisors because by definition, a prime only has 1 as a divisor. Prime-to-div-or-coprime : Prime(x) → ((x ∣ y) ∨ Coprime(x)(y)) Prime-to-div-or-coprime {y = y} (intro {x} prim) = [¬→]-disjunctive-formᵣ ⦃ decider-to-classical ⦄ (intro ∘ coprim) where coprim : (𝐒(𝐒(x)) ∤ y) → ∀{n} → (n ∣ 𝐒(𝐒(x))) → (n ∣ y) → (n ≡ 1) coprim nxy {𝟎} nx ny with () ← [0]-divides-not nx coprim nxy {𝐒 n} nx ny with prim nx ... | [∨]-introₗ [≡]-intro = [≡]-intro ... | [∨]-introᵣ [≡]-intro with () ← nxy ny divides-to-converse-coprime : ∀{x y z} → (x ∣ y) → Coprime(y)(z) → Coprime(x)(z) divides-to-converse-coprime xy (intro yz) = intro(nx ↦ nz ↦ yz (transitivity(_∣_) nx xy) nz)
algebraic-stack_agda0000_doc_4085
{-# OPTIONS --universe-polymorphism #-} -- {-# OPTIONS --verbose tc.records.ifs:15 #-} -- {-# OPTIONS --verbose tc.constr.findInScope:15 #-} -- {-# OPTIONS --verbose tc.term.args.ifs:15 #-} -- {-# OPTIONS --verbose cta.record.ifs:15 #-} -- {-# OPTIONS --verbose tc.section.apply:25 #-} -- {-# OPTIONS --verbose tc.mod.apply:100 #-} -- {-# OPTIONS --verbose scope.rec:15 #-} -- {-# OPTIONS --verbose tc.rec.def:15 #-} module 04-equality where record ⊤ : Set where constructor tt data Bool : Set where true : Bool false : Bool or : Bool → Bool → Bool or true _ = true or _ true = true or false false = false and : Bool → Bool → Bool and false _ = false and _ false = false and true true = false not : Bool → Bool not true = false not false = true id : {A : Set} → A → A id v = v primEqBool : Bool → Bool → Bool primEqBool true = id primEqBool false = not record Eq (A : Set) : Set where field eq : A → A → Bool eqBool : Eq Bool eqBool = record { eq = primEqBool } open Eq {{...}} neq : {t : Set} → {{eqT : Eq t}} → t → t → Bool neq a b = not (eq a b) test = eq false false -- Instance arguments will also resolve to candidate instances which -- still require hidden arguments. This allows us to define a -- reasonable instance for Fin types data ℕ : Set where zero : ℕ suc : ℕ → ℕ {-# BUILTIN NATURAL ℕ #-} data Fin : ℕ → Set where zero : {n : ℕ} → Fin (suc n) suc : {n : ℕ} → Fin n → Fin (suc n) primEqFin : {n : ℕ} → Fin n → Fin n → Bool primEqFin zero zero = true primEqFin zero (suc y) = false primEqFin (suc y) zero = false primEqFin (suc x) (suc y) = primEqFin x y eqFin : {n : ℕ} → Eq (Fin n) eqFin = record { eq = primEqFin } -- eqFin′ : Eq (Fin 3) -- eqFin′ = record { eq = primEqFin } -- eqFinSpecial : {n : ℕ} → Prime n → Eq (Fin n) -- eqFinSpecial fin1 : Fin 3 fin1 = zero fin2 : Fin 3 fin2 = suc (suc zero) testFin : Bool testFin = eq fin1 fin2
algebraic-stack_agda0000_doc_4086
------------------------------------------------------------------------ -- The Agda standard library -- -- The Stream type and some operations ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe --sized-types #-} module Codata.Stream where open import Size open import Codata.Thunk as Thunk using (Thunk; force) open import Data.Nat.Base open import Data.List.Base using (List; []; _∷_) open import Data.List.NonEmpty using (List⁺; _∷_) open import Data.Vec using (Vec; []; _∷_) open import Data.Product as P hiding (map) open import Function ------------------------------------------------------------------------ -- Definition data Stream {ℓ} (A : Set ℓ) (i : Size) : Set ℓ where _∷_ : A → Thunk (Stream A) i → Stream A i module _ {ℓ} {A : Set ℓ} where repeat : ∀ {i} → A → Stream A i repeat a = a ∷ λ where .force → repeat a head : ∀ {i} → Stream A i → A head (x ∷ xs) = x tail : Stream A ∞ → Stream A ∞ tail (x ∷ xs) = xs .force lookup : ℕ → Stream A ∞ → A lookup zero xs = head xs lookup (suc k) xs = lookup k (tail xs) splitAt : (n : ℕ) → Stream A ∞ → Vec A n × Stream A ∞ splitAt zero xs = [] , xs splitAt (suc n) (x ∷ xs) = P.map₁ (x ∷_) (splitAt n (xs .force)) take : (n : ℕ) → Stream A ∞ → Vec A n take n xs = proj₁ (splitAt n xs) drop : ℕ → Stream A ∞ → Stream A ∞ drop n xs = proj₂ (splitAt n xs) infixr 5 _++_ _⁺++_ _++_ : ∀ {i} → List A → Stream A i → Stream A i [] ++ ys = ys (x ∷ xs) ++ ys = x ∷ λ where .force → xs ++ ys _⁺++_ : ∀ {i} → List⁺ A → Thunk (Stream A) i → Stream A i (x ∷ xs) ⁺++ ys = x ∷ λ where .force → xs ++ ys .force cycle : ∀ {i} → List⁺ A → Stream A i cycle xs = xs ⁺++ λ where .force → cycle xs concat : ∀ {i} → Stream (List⁺ A) i → Stream A i concat (xs ∷ xss) = xs ⁺++ λ where .force → concat (xss .force) interleave : ∀ {i} → Stream A i → Thunk (Stream A) i → Stream A i interleave (x ∷ xs) ys = x ∷ λ where .force → interleave (ys .force) xs chunksOf : (n : ℕ) → Stream A ∞ → Stream (Vec A n) ∞ chunksOf n = chunksOfAcc n id module ChunksOf where chunksOfAcc : ∀ {i} k (acc : Vec A k → Vec A n) → Stream A ∞ → Stream (Vec A n) i chunksOfAcc zero acc xs = acc [] ∷ λ where .force → chunksOfAcc n id xs chunksOfAcc (suc k) acc (x ∷ xs) = chunksOfAcc k (acc ∘ (x ∷_)) (xs .force) module _ {ℓ ℓ′} {A : Set ℓ} {B : Set ℓ′} where map : ∀ {i} → (A → B) → Stream A i → Stream B i map f (x ∷ xs) = f x ∷ λ where .force → map f (xs .force) ap : ∀ {i} → Stream (A → B) i → Stream A i → Stream B i ap (f ∷ fs) (x ∷ xs) = f x ∷ λ where .force → ap (fs .force) (xs .force) unfold : ∀ {i} → (A → A × B) → A → Stream B i unfold next seed = let (seed′ , b) = next seed in b ∷ λ where .force → unfold next seed′ scanl : ∀ {i} → (B → A → B) → B → Stream A i → Stream B i scanl c n (x ∷ xs) = n ∷ λ where .force → scanl c (c n x) (xs .force) module _ {ℓ ℓ₁ ℓ₂} {A : Set ℓ} {B : Set ℓ₁} {C : Set ℓ₂} where zipWith : ∀ {i} → (A → B → C) → Stream A i → Stream B i → Stream C i zipWith f (a ∷ as) (b ∷ bs) = f a b ∷ λ where .force → zipWith f (as .force) (bs .force) module _ {a} {A : Set a} where iterate : (A → A) → A → Stream A ∞ iterate f = unfold < f , id >
algebraic-stack_agda0000_doc_4087
------------------------------------------------------------------------------ -- ABP auxiliary lemma ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOT.FOTC.Program.ABP.StrongerInductionPrinciple.LemmaATP where open import Common.FOL.Relation.Binary.EqReasoning open import FOTC.Base open import FOTC.Base.PropertiesI open import FOTC.Base.List open import FOTC.Base.List.PropertiesATP open import FOTC.Base.Loop open import FOTC.Data.Bool open import FOTC.Data.Bool.PropertiesATP open import FOTC.Data.List open import FOTC.Data.List.PropertiesATP open import FOTC.Program.ABP.ABP open import FOTC.Program.ABP.Fair.Type open import FOTC.Program.ABP.Fair.PropertiesATP open import FOTC.Program.ABP.PropertiesI open import FOTC.Program.ABP.Terms ------------------------------------------------------------------------------ -- Helper function for the auxiliary lemma module Helper where -- 30 November 2013. If we don't have the following definitions -- outside the where clause, the ATPs cannot prove the theorems. as^ : ∀ b i' is' ds → D as^ b i' is' ds = await b i' is' ds {-# ATP definition as^ #-} bs^ : D → D → D → D → D → D bs^ b i' is' ds os₁^ = corrupt os₁^ · (as^ b i' is' ds) {-# ATP definition bs^ #-} cs^ : D → D → D → D → D → D cs^ b i' is' ds os₁^ = ack b · (bs^ b i' is' ds os₁^) {-# ATP definition cs^ #-} ds^ : D → D → D → D → D → D → D ds^ b i' is' ds os₁^ os₂^ = corrupt os₂^ · cs^ b i' is' ds os₁^ {-# ATP definition ds^ #-} os₁^ : D → D → D os₁^ os₁' ft₁^ = ft₁^ ++ os₁' {-# ATP definition os₁^ #-} os₂^ : D → D os₂^ os₂ = tail₁ os₂ {-# ATP definition os₂^ #-} helper : ∀ {b i' is' os₁ os₂ as bs cs ds js} → Bit b → Fair os₂ → S b (i' ∷ is') os₁ os₂ as bs cs ds js → ∀ ft₁ os₁' → F*T ft₁ → Fair os₁' → os₁ ≡ ft₁ ++ os₁' → ∃[ js' ] js ≡ i' ∷ js' helper {b} {i'} {is'} {os₁} {os₂} {as} {bs} {cs} {ds} {js} Bb Fos₂ (asS , bsS , csS , dsS , jsS) .(T ∷ []) os₁' f*tnil Fos₁' os₁-eq = prf where postulate prf : ∃[ js' ] js ≡ i' ∷ js' {-# ATP prove prf #-} helper {b} {i'} {is'} {os₁} {os₂} {as} {bs} {cs} {ds} {js} Bb Fos₂ (asS , bsS , csS , dsS , jsS) .(F ∷ ft₁^) os₁' (f*tcons {ft₁^} FTft₁^) Fos₁' os₁-eq = helper Bb (tail-Fair Fos₂) ihS ft₁^ os₁' FTft₁^ Fos₁' refl where postulate os₁-eq-helper : os₁ ≡ F ∷ os₁^ os₁' ft₁^ {-# ATP prove os₁-eq-helper #-} postulate as-eq : as ≡ < i' , b > ∷ (as^ b i' is' ds) {-# ATP prove as-eq #-} postulate bs-eq : bs ≡ error ∷ (bs^ b i' is' ds (os₁^ os₁' ft₁^)) {-# ATP prove bs-eq os₁-eq-helper as-eq #-} postulate cs-eq : cs ≡ not b ∷ cs^ b i' is' ds (os₁^ os₁' ft₁^) {-# ATP prove cs-eq bs-eq #-} postulate ds-eq-helper₁ : os₂ ≡ T ∷ tail₁ os₂ → ds ≡ ok (not b) ∷ ds^ b i' is' ds (os₁^ os₁' ft₁^) (os₂^ os₂) {-# ATP prove ds-eq-helper₁ cs-eq #-} postulate ds-eq-helper₂ : os₂ ≡ F ∷ tail₁ os₂ → ds ≡ error ∷ ds^ b i' is' ds (os₁^ os₁' ft₁^) (os₂^ os₂) {-# ATP prove ds-eq-helper₂ cs-eq #-} ds-eq : ds ≡ ok (not b) ∷ ds^ b i' is' ds (os₁^ os₁' ft₁^) (os₂^ os₂) ∨ ds ≡ error ∷ ds^ b i' is' ds (os₁^ os₁' ft₁^) (os₂^ os₂) ds-eq = case (λ h → inj₁ (ds-eq-helper₁ h)) (λ h → inj₂ (ds-eq-helper₂ h)) (head-tail-Fair Fos₂) postulate as^-eq-helper₁ : ds ≡ ok (not b) ∷ ds^ b i' is' ds (os₁^ os₁' ft₁^) (os₂^ os₂) → as^ b i' is' ds ≡ send b · (i' ∷ is') · ds^ b i' is' ds (os₁^ os₁' ft₁^) (os₂^ os₂) {-# ATP prove as^-eq-helper₁ x≢not-x #-} postulate as^-eq-helper₂ : ds ≡ error ∷ ds^ b i' is' ds (os₁^ os₁' ft₁^) (os₂^ os₂) → as^ b i' is' ds ≡ send b · (i' ∷ is') · ds^ b i' is' ds (os₁^ os₁' ft₁^) (os₂^ os₂) {-# ATP prove as^-eq-helper₂ #-} as^-eq : as^ b i' is' ds ≡ send b · (i' ∷ is') · ds^ b i' is' ds (os₁^ os₁' ft₁^) (os₂^ os₂) as^-eq = case as^-eq-helper₁ as^-eq-helper₂ ds-eq postulate js-eq : js ≡ out b · bs^ b i' is' ds (os₁^ os₁' ft₁^) {-# ATP prove js-eq bs-eq #-} ihS : S b (i' ∷ is') (os₁^ os₁' ft₁^) (os₂^ os₂) (as^ b i' is' ds) (bs^ b i' is' ds (os₁^ os₁' ft₁^)) (cs^ b i' is' ds (os₁^ os₁' ft₁^)) (ds^ b i' is' ds (os₁^ os₁' ft₁^) (os₂^ os₂)) js ihS = as^-eq , refl , refl , refl , js-eq ------------------------------------------------------------------------------ -- From Dybjer and Sander's paper: From the assumption that os₁ ∈ Fair -- and hence by unfolding Fair, we conclude that there are ft₁ :  F*T -- and os₁' : Fair, such that os₁ = ft₁ ++ os₁'. -- -- We proceed by induction on ft₁ : F*T using helper. open Helper lemma : ∀ {b i' is' os₁ os₂ as bs cs ds js} → Bit b → Fair os₁ → Fair os₂ → S b (i' ∷ is') os₁ os₂ as bs cs ds js → ∃[ js' ] js ≡ i' ∷ js' lemma Bb Fos₁ Fos₂ s with Fair-out Fos₁ ... | ft , os₁' , FTft , prf , Fos₁' = helper Bb Fos₂ s ft os₁' FTft Fos₁' prf
algebraic-stack_agda0000_doc_4088
-- Andreas, 2019-02-24, issue #3457 -- Error messages for illegal as-clause import Agda.Builtin.Nat Fresh-name as _ -- Previously, this complained about a duplicate module definition -- with unspeakable name. -- Expected error: -- Not in scope: Fresh-name
algebraic-stack_agda0000_doc_4089
module Classes where open import Agda.Primitive open import Agda.Builtin.Equality open import Relation.Binary.PropositionalEquality.Core open ≡-Reasoning id : ∀ {ℓ} {A : Set ℓ} → A → A id x = x _$_ : ∀ {ℓ} {A B : Set ℓ} → (A → B) → A → B _$_ = id _∘_ : ∀ {ℓ} {A B C : Set ℓ} → (B → C) → (A → B) → A → C f ∘ g = λ x → f (g x) record Functor {ℓ} (F : Set ℓ → Set ℓ) : Set (lsuc ℓ) where field fmap : ∀ {A B} → (A → B) → F A → F B F-id : ∀ {A} → (a : F A) → fmap id a ≡ a F-∘ : ∀ {A B C} → (g : B → C) (f : A → B) (a : F A) → fmap (g ∘ f) a ≡ (fmap g ∘ fmap f) a _<$>_ : ∀ {A B} → (A → B) → F A → F B _<$>_ = fmap infixl 20 _<$>_ open Functor {{...}} public record Applicative (F : Set → Set) : Set₁ where field {{funF}} : Functor F pure : {A : Set} → A → F A _<*>_ : {A B : Set} → F (A → B) → F A → F B A-id : ∀ {A} → (v : F A) → pure id <*> v ≡ v A-∘ : ∀ {A B C} → (u : F (B → C)) (v : F (A → B)) (w : F A) → pure _∘_ <*> u <*> v <*> w ≡ u <*> (v <*> w) A-hom : ∀ {A B} → (f : A → B) (x : A) → pure f <*> pure x ≡ pure (f x) A-ic : ∀ {A B} → (u : F (A → B)) (y : A) → u <*> pure y ≡ pure (_$ y) <*> u infixl 20 _<*>_ open Applicative {{...}} public postulate -- this is from parametricity: fmap is universal w.r.t. the functor laws appFun : ∀ {A B F} {{aF : Applicative F}} → (f : A → B) (x : F A) → pure f <*> x ≡ fmap f x record Monad (F : Set → Set) : Set₁ where field {{appF}} : Applicative F _>>=_ : ∀ {A B} → F A → (A → F B) → F B return : ∀ {A} → A → F A return = pure _>=>_ : {A B C : Set} → (A → F B) → (B → F C) → A → F C f >=> g = λ a → f a >>= g infixl 10 _>>=_ infixr 10 _>=>_ field left-1 : ∀ {A B} → (a : A) (k : A → F B) → return a >>= k ≡ k a right-1 : ∀ {A} → (m : F A) → m >>= return ≡ m assoc : ∀ {A B C D} → (f : A → F B) (g : B → F C) (h : C → F D) (a : A) → (f >=> (g >=> h)) a ≡ ((f >=> g) >=> h) a open Monad {{...}} public
algebraic-stack_agda0000_doc_4090
data Bool : Set where true false : Bool record Top : Set where foo : Top foo with true ... | true = _ ... | false = top where top = record{ } -- the only purpose of this was to force -- evaluation of the with function clauses -- which were in an __IMPOSSIBLE__ state
algebraic-stack_agda0000_doc_4091
open import Prelude open import Nat open import dynamics-core open import contexts module lemmas-disjointness where -- disjointness is commutative ##-comm : {A : Set} {Δ1 Δ2 : A ctx} → Δ1 ## Δ2 → Δ2 ## Δ1 ##-comm (π1 , π2) = π2 , π1 -- the empty context is disjoint from any context empty-disj : {A : Set} (Γ : A ctx) → ∅ ## Γ empty-disj Γ = ed1 , ed2 where ed1 : {A : Set} (n : Nat) → dom {A} ∅ n → n # Γ ed1 n (π1 , ()) ed2 : {A : Set} (n : Nat) → dom Γ n → _#_ {A} n ∅ ed2 _ _ = refl -- two singleton contexts with different indices are disjoint disjoint-singles : {A : Set} {x y : A} {u1 u2 : Nat} → u1 ≠ u2 → (■ (u1 , x)) ## (■ (u2 , y)) disjoint-singles {_} {x} {y} {u1} {u2} neq = ds1 , ds2 where ds1 : (n : Nat) → dom (■ (u1 , x)) n → n # (■ (u2 , y)) ds1 n d with lem-dom-eq d ds1 .u1 d | refl with natEQ u2 u1 ds1 .u1 d | refl | Inl xx = abort (neq (! xx)) ds1 .u1 d | refl | Inr x₁ = refl ds2 : (n : Nat) → dom (■ (u2 , y)) n → n # (■ (u1 , x)) ds2 n d with lem-dom-eq d ds2 .u2 d | refl with natEQ u1 u2 ds2 .u2 d | refl | Inl x₁ = abort (neq x₁) ds2 .u2 d | refl | Inr x₁ = refl apart-noteq : {A : Set} (p r : Nat) (q : A) → p # (■ (r , q)) → p ≠ r apart-noteq p r q apt with natEQ r p apart-noteq p .p q apt | Inl refl = abort (somenotnone apt) apart-noteq p r q apt | Inr x₁ = flip x₁ -- if singleton contexts are disjoint, their indices must be disequal singles-notequal : {A : Set} {x y : A} {u1 u2 : Nat} → (■ (u1 , x)) ## (■ (u2 , y)) → u1 ≠ u2 singles-notequal {A} {x} {y} {u1} {u2} (d1 , d2) = apart-noteq u1 u2 y (d1 u1 (lem-domsingle u1 x)) -- dual of lem2 above; if two indices are disequal, then either is apart -- from the singleton formed with the other apart-singleton : {A : Set} → ∀{x y} → {τ : A} → x ≠ y → x # (■ (y , τ)) apart-singleton {A} {x} {y} {τ} neq with natEQ y x apart-singleton neq | Inl x₁ = abort ((flip neq) x₁) apart-singleton neq | Inr x₁ = refl -- if an index is apart from two contexts, it's apart from their union as -- well. used below and in other files, so it's outside the local scope. apart-parts : {A : Set} (Γ1 Γ2 : A ctx) (n : Nat) → n # Γ1 → n # Γ2 → n # (Γ1 ∪ Γ2) apart-parts Γ1 Γ2 n apt1 apt2 with Γ1 n apart-parts _ _ n refl apt2 | .None = apt2 -- this is just for convenience; it shows up a lot. apart-extend1 : {A : Set} → ∀{x y τ} → (Γ : A ctx) → x ≠ y → x # Γ → x # (Γ ,, (y , τ)) apart-extend1 {A} {x} {y} {τ} Γ neq apt with natEQ y x ... | Inl refl = abort (neq refl) ... | Inr y≠x = apt -- if an index is in the domain of a union, it's in the domain of one or -- the other unand dom-split : {A : Set} → (Γ1 Γ2 : A ctx) (n : Nat) → dom (Γ1 ∪ Γ2) n → dom Γ1 n + dom Γ2 n dom-split Γ4 Γ5 n (π1 , π2) with Γ4 n dom-split Γ4 Γ5 n (π1 , π2) | Some x = Inl (x , refl) dom-split Γ4 Γ5 n (π1 , π2) | None = Inr (π1 , π2) -- if both parts of a union are disjoint with a target, so is the union disjoint-parts : {A : Set} {Γ1 Γ2 Γ3 : A ctx} → Γ1 ## Γ3 → Γ2 ## Γ3 → (Γ1 ∪ Γ2) ## Γ3 disjoint-parts {_} {Γ1} {Γ2} {Γ3} D13 D23 = d31 , d32 where d31 : (n : Nat) → dom (Γ1 ∪ Γ2) n → n # Γ3 d31 n D with dom-split Γ1 Γ2 n D d31 n D | Inl x = π1 D13 n x d31 n D | Inr x = π1 D23 n x d32 : (n : Nat) → dom Γ3 n → n # (Γ1 ∪ Γ2) d32 n D = apart-parts Γ1 Γ2 n (π2 D13 n D) (π2 D23 n D) apart-union1 : {A : Set} (Γ1 Γ2 : A ctx) (n : Nat) → n # (Γ1 ∪ Γ2) → n # Γ1 apart-union1 Γ1 Γ2 n aprt with Γ1 n apart-union1 Γ1 Γ2 n () | Some x apart-union1 Γ1 Γ2 n aprt | None = refl apart-union2 : {A : Set} (Γ1 Γ2 : A ctx) (n : Nat) → n # (Γ1 ∪ Γ2) → n # Γ2 apart-union2 Γ1 Γ2 n aprt with Γ1 n apart-union2 Γ3 Γ4 n () | Some x apart-union2 Γ3 Γ4 n aprt | None = aprt -- if a union is disjoint with a target, so is the left unand disjoint-union1 : {A : Set} {Γ1 Γ2 Δ : A ctx} → (Γ1 ∪ Γ2) ## Δ → Γ1 ## Δ disjoint-union1 {Γ1 = Γ1} {Γ2 = Γ2} {Δ = Δ} (ud1 , ud2) = du11 , du12 where dom-union1 : {A : Set} (Γ1 Γ2 : A ctx) (n : Nat) → dom Γ1 n → dom (Γ1 ∪ Γ2) n dom-union1 Γ1 Γ2 n (π1 , π2) with Γ1 n dom-union1 Γ1 Γ2 n (π1 , π2) | Some x = x , refl dom-union1 Γ1 Γ2 n (π1 , ()) | None du11 : (n : Nat) → dom Γ1 n → n # Δ du11 n dom = ud1 n (dom-union1 Γ1 Γ2 n dom) du12 : (n : Nat) → dom Δ n → n # Γ1 du12 n dom = apart-union1 Γ1 Γ2 n (ud2 n dom) -- if a union is disjoint with a target, so is the right unand disjoint-union2 : {A : Set} {Γ1 Γ2 Δ : A ctx} → (Γ1 ∪ Γ2) ## Δ → Γ2 ## Δ disjoint-union2 {Γ1 = Γ1} {Γ2 = Γ2} {Δ = Δ} (ud1 , ud2) = du21 , du22 where dom-union2 : {A : Set} (Γ1 Γ2 : A ctx) (n : Nat) → dom Γ2 n → dom (Γ1 ∪ Γ2) n dom-union2 Γ1 Γ2 n (π1 , π2) with Γ1 n dom-union2 Γ3 Γ4 n (π1 , π2) | Some x = x , refl dom-union2 Γ3 Γ4 n (π1 , π2) | None = π1 , π2 du21 : (n : Nat) → dom Γ2 n → n # Δ du21 n dom = ud1 n (dom-union2 Γ1 Γ2 n dom) du22 : (n : Nat) → dom Δ n → n # Γ2 du22 n dom = apart-union2 Γ1 Γ2 n (ud2 n dom) -- if x isn't in a context and y is then they can't be equal lem-dom-apt : {A : Set} {G : A ctx} {x y : Nat} → x # G → dom G y → x ≠ y lem-dom-apt {x = x} {y = y} apt dom with natEQ x y lem-dom-apt apt dom | Inl refl = abort (somenotnone (! (π2 dom) · apt)) lem-dom-apt apt dom | Inr x₁ = x₁
algebraic-stack_agda0000_doc_4092
{-# OPTIONS --safe #-} module Cubical.Algebra.Group.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Structure open import Cubical.Foundations.GroupoidLaws hiding (assoc) open import Cubical.Data.Sigma open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid.Base open import Cubical.Algebra.Group.Base private variable ℓ : Level G : Type ℓ isPropIsGroup : (1g : G) (_·_ : G → G → G) (inv : G → G) → isProp (IsGroup 1g _·_ inv) isPropIsGroup 1g _·_ inv = isOfHLevelRetractFromIso 1 IsGroupIsoΣ (isPropΣ (isPropIsMonoid 1g _·_) λ mono → isProp× (isPropΠ λ _ → mono .is-set _ _) (isPropΠ λ _ → mono .is-set _ _)) where open IsMonoid module GroupTheory (G : Group ℓ) where open GroupStr (snd G) abstract ·CancelL : (a : ⟨ G ⟩) {b c : ⟨ G ⟩} → a · b ≡ a · c → b ≡ c ·CancelL a {b} {c} p = b ≡⟨ sym (·IdL b) ∙ cong (_· b) (sym (·InvL a)) ∙ sym (·Assoc _ _ _) ⟩ inv a · (a · b) ≡⟨ cong (inv a ·_) p ⟩ inv a · (a · c) ≡⟨ ·Assoc _ _ _ ∙ cong (_· c) (·InvL a) ∙ ·IdL c ⟩ c ∎ ·CancelR : {a b : ⟨ G ⟩} (c : ⟨ G ⟩) → a · c ≡ b · c → a ≡ b ·CancelR {a} {b} c p = a ≡⟨ sym (·IdR a) ∙ cong (a ·_) (sym (·InvR c)) ∙ ·Assoc _ _ _ ⟩ (a · c) · inv c ≡⟨ cong (_· inv c) p ⟩ (b · c) · inv c ≡⟨ sym (·Assoc _ _ _) ∙ cong (b ·_) (·InvR c) ∙ ·IdR b ⟩ b ∎ invInv : (a : ⟨ G ⟩) → inv (inv a) ≡ a invInv a = ·CancelL (inv a) (·InvR (inv a) ∙ sym (·InvL a)) inv1g : inv 1g ≡ 1g inv1g = ·CancelL 1g (·InvR 1g ∙ sym (·IdL 1g)) 1gUniqueL : {e : ⟨ G ⟩} (x : ⟨ G ⟩) → e · x ≡ x → e ≡ 1g 1gUniqueL {e} x p = ·CancelR x (p ∙ sym (·IdL _)) 1gUniqueR : (x : ⟨ G ⟩) {e : ⟨ G ⟩} → x · e ≡ x → e ≡ 1g 1gUniqueR x {e} p = ·CancelL x (p ∙ sym (·IdR _)) invUniqueL : {g h : ⟨ G ⟩} → g · h ≡ 1g → g ≡ inv h invUniqueL {g} {h} p = ·CancelR h (p ∙ sym (·InvL h)) invUniqueR : {g h : ⟨ G ⟩} → g · h ≡ 1g → h ≡ inv g invUniqueR {g} {h} p = ·CancelL g (p ∙ sym (·InvR g)) invDistr : (a b : ⟨ G ⟩) → inv (a · b) ≡ inv b · inv a invDistr a b = sym (invUniqueR γ) where γ : (a · b) · (inv b · inv a) ≡ 1g γ = (a · b) · (inv b · inv a) ≡⟨ sym (·Assoc _ _ _) ⟩ a · b · (inv b) · (inv a) ≡⟨ cong (a ·_) (·Assoc _ _ _ ∙ cong (_· (inv a)) (·InvR b)) ⟩ a · (1g · inv a) ≡⟨ cong (a ·_) (·IdL (inv a)) ∙ ·InvR a ⟩ 1g ∎ congIdLeft≡congIdRight : (_·G_ : G → G → G) (-G_ : G → G) (0G : G) (rUnitG : (x : G) → x ·G 0G ≡ x) (lUnitG : (x : G) → 0G ·G x ≡ x) → (r≡l : rUnitG 0G ≡ lUnitG 0G) → (p : 0G ≡ 0G) → cong (0G ·G_) p ≡ cong (_·G 0G) p congIdLeft≡congIdRight _·G_ -G_ 0G rUnitG lUnitG r≡l p = rUnit (cong (0G ·G_) p) ∙∙ ((λ i → (λ j → lUnitG 0G (i ∧ j)) ∙∙ cong (λ x → lUnitG x i) p ∙∙ λ j → lUnitG 0G (i ∧ ~ j)) ∙∙ cong₂ (λ x y → x ∙∙ p ∙∙ y) (sym r≡l) (cong sym (sym r≡l)) ∙∙ λ i → (λ j → rUnitG 0G (~ i ∧ j)) ∙∙ cong (λ x → rUnitG x (~ i)) p ∙∙ λ j → rUnitG 0G (~ i ∧ ~ j)) ∙∙ sym (rUnit (cong (_·G 0G) p))
algebraic-stack_agda0000_doc_4093
{-# OPTIONS --safe #-} module Cubical.HITs.Cost where open import Cubical.HITs.Cost.Base
algebraic-stack_agda0000_doc_4094
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import Level using (0ℓ) open import Util.Prelude -- This module incldes various Agda lemmas that are independent of the project's domain module Util.Lemmas where cong₃ : ∀{a b c d}{A : Set a}{B : Set b}{C : Set c}{D : Set d} → (f : A → B → C → D) → ∀{x y u v m n} → x ≡ y → u ≡ v → m ≡ n → f x u m ≡ f y v n cong₃ f refl refl refl = refl ≡-pi : ∀{a}{A : Set a}{x y : A}(p q : x ≡ y) → p ≡ q ≡-pi refl refl = refl Unit-pi : {u1 u2 : Unit} → u1 ≡ u2 Unit-pi {unit} {unit} = refl ++-inj : ∀{a}{A : Set a}{m n o p : List A} → length m ≡ length n → m ++ o ≡ n ++ p → m ≡ n × o ≡ p ++-inj {m = []} {x ∷ n} () hip ++-inj {m = x ∷ m} {[]} () hip ++-inj {m = []} {[]} lhip hip = refl , hip ++-inj {m = m ∷ ms} {n ∷ ns} lhip hip with ++-inj {m = ms} {ns} (suc-injective lhip) (proj₂ (∷-injective hip)) ...| (mn , op) rewrite proj₁ (∷-injective hip) = cong (n ∷_) mn , op ++-abs : ∀{a}{A : Set a}{n : List A}(m : List A) → 1 ≤ length m → [] ≡ m ++ n → ⊥ ++-abs [] () ++-abs (x ∷ m) imp () filter-++-[] : ∀ {a p} {A : Set a} {P : (a : A) → Set p} → ∀ xs ys (p : (a : A) → Dec (P a)) → List-filter p xs ≡ [] → List-filter p ys ≡ [] → List-filter p (xs ++ ys) ≡ [] filter-++-[] xs ys p pf₁ pf₂ rewrite List-filter-++ p xs ys | pf₁ | pf₂ = refl filter-∪?-[]₁ : ∀ {a p} {A : Set a} {P Q : (a : A) → Set p} → ∀ xs (p : (a : A) → Dec (P a)) (q : (a : A) → Dec (Q a)) → List-filter (p ∪? q) xs ≡ [] → List-filter p xs ≡ [] filter-∪?-[]₁ [] p q pf = refl filter-∪?-[]₁ (x ∷ xs) p q pf with p x ...| no proof₁ with q x ...| no proof₂ = filter-∪?-[]₁ xs p q pf filter-∪?-[]₁ (x ∷ xs) p q () | no proof₁ | yes proof₂ filter-∪?-[]₁ (x ∷ xs) p q () | yes proof filter-∪?-[]₂ : ∀ {a p} {A : Set a} {P Q : (a : A) → Set p} → ∀ xs (p : (a : A) → Dec (P a)) (q : (a : A) → Dec (Q a)) → List-filter (p ∪? q) xs ≡ [] → List-filter q xs ≡ [] filter-∪?-[]₂ [] p q pf = refl filter-∪?-[]₂ (x ∷ xs) p q pf with p x ...| no proof₁ with q x ...| no proof₂ = filter-∪?-[]₂ xs p q pf filter-∪?-[]₂ (x ∷ xs) p q () | no proof₁ | yes proof₂ filter-∪?-[]₂ (x ∷ xs) p q () | yes proof noneOfKind⇒¬Any : ∀ {a p} {A : Set a} {P : A → Set p} xs (p : (a : A) → Dec (P a)) → NoneOfKind xs p → ¬ Any P xs noneOfKind⇒¬Any (x ∷ xs) p none ∈xs with p x noneOfKind⇒¬Any (x ∷ xs) p none (here px) | no ¬px = ¬px px noneOfKind⇒¬Any (x ∷ xs) p none (there ∈xs) | no ¬px = noneOfKind⇒¬Any xs p none ∈xs noneOfKind⇒All¬ : ∀ {a p} {A : Set a} {P : A → Set p} xs (p : (a : A) → Dec (P a)) → NoneOfKind xs p → All (¬_ ∘ P) xs noneOfKind⇒All¬ xs p none = ¬Any⇒All¬ xs (noneOfKind⇒¬Any xs p none) ++-NoneOfKind : ∀ {ℓA} {A : Set ℓA} {ℓ} {P : A → Set ℓ} xs ys (p : (a : A) → Dec (P a)) → NoneOfKind xs p → NoneOfKind ys p → NoneOfKind (xs ++ ys) p ++-NoneOfKind xs ys p nok₁ nok₂ = filter-++-[] xs ys p nok₁ nok₂ data All-vec {ℓ} {A : Set ℓ} (P : A → Set ℓ) : ∀ {n} → Vec {ℓ} A n → Set (Level.suc ℓ) where [] : All-vec P [] _∷_ : ∀ {x n} {xs : Vec A n} (px : P x) (pxs : All-vec P xs) → All-vec P (x ∷ xs) ≤-unstep : ∀{m n} → suc m ≤ n → m ≤ n ≤-unstep (s≤s ss) = ≤-step ss ≡⇒≤ : ∀{m n} → m ≡ n → m ≤ n ≡⇒≤ refl = ≤-refl ∈-cong : ∀{a b}{A : Set a}{B : Set b}{x : A}{l : List A} → (f : A → B) → x ∈ l → f x ∈ List-map f l ∈-cong f (here px) = here (cong f px) ∈-cong f (there hyp) = there (∈-cong f hyp) All-self : ∀{a}{A : Set a}{xs : List A} → All (_∈ xs) xs All-self = All-tabulate (λ x → x) All-reduce⁺ : ∀{a b}{A : Set a}{B : Set b}{Q : A → Set}{P : B → Set} → { xs : List A } → (f : ∀{x} → Q x → B) → (∀{x} → (prf : Q x) → P (f prf)) → (all : All Q xs) → All P (All-reduce f all) All-reduce⁺ f hyp [] = [] All-reduce⁺ f hyp (ax ∷ axs) = (hyp ax) ∷ All-reduce⁺ f hyp axs All-reduce⁻ : ∀{a b}{A : Set a}{B : Set b} {Q : A → Set} → { xs : List A } → ∀ {vdq} → (f : ∀{x} → Q x → B) → (all : All Q xs) → vdq ∈ All-reduce f all → ∃[ v ] ∃[ v∈xs ] (vdq ≡ f {v} v∈xs) All-reduce⁻ {Q = Q} {(h ∷ _)} {vdq} f (px ∷ pxs) (here refl) = h , px , refl All-reduce⁻ {Q = Q} {(_ ∷ t)} {vdq} f (px ∷ pxs) (there vdq∈) = All-reduce⁻ {xs = t} f pxs vdq∈ List-index : ∀ {A : Set} → (_≟A_ : (a₁ a₂ : A) → Dec (a₁ ≡ a₂)) → A → (l : List A) → Maybe (Fin (length l)) List-index _≟A_ x l with break (_≟A x) l ...| not≡ , _ with length not≡ <? length l ...| no _ = nothing ...| yes found = just ( fromℕ< {length not≡} {length l} found) nats : ℕ → List ℕ nats 0 = [] nats (suc n) = (nats n) ++ (n ∷ []) _ : nats 4 ≡ 0 ∷ 1 ∷ 2 ∷ 3 ∷ [] _ = refl _ : Maybe-map toℕ (List-index _≟_ 2 (nats 4)) ≡ just 2 _ = refl _ : Maybe-map toℕ (List-index _≟_ 4 (nats 4)) ≡ nothing _ = refl allDistinct : ∀ {A : Set} → List A → Set allDistinct l = ∀ (i j : Fin (length l)) → i ≡ j ⊎ List-lookup l i ≢ List-lookup l j postulate -- TODO-1: currently unused; prove it, if needed allDistinct? : ∀ {A : Set} → {≟A : (a₁ a₂ : A) → Dec (a₁ ≡ a₂)} → (l : List A) → Dec (allDistinct l) -- Extends an arbitrary relation to work on the head of -- the supplied list, if any. data OnHead {A : Set}(P : A → A → Set) (x : A) : List A → Set where [] : OnHead P x [] on-∷ : ∀{y ys} → P x y → OnHead P x (y ∷ ys) -- Establishes that a list is sorted according to the supplied -- relation. data IsSorted {A : Set}(_<_ : A → A → Set) : List A → Set where [] : IsSorted _<_ [] _∷_ : ∀{x xs} → OnHead _<_ x xs → IsSorted _<_ xs → IsSorted _<_ (x ∷ xs) OnHead-prop : ∀{A}(P : A → A → Set)(x : A)(l : List A) → Irrelevant P → isPropositional (OnHead P x l) OnHead-prop P x [] hyp [] [] = refl OnHead-prop P x (x₁ ∷ l) hyp (on-∷ x₂) (on-∷ x₃) = cong on-∷ (hyp x₂ x₃) IsSorted-prop : ∀{A}(_<_ : A → A → Set)(l : List A) → Irrelevant _<_ → isPropositional (IsSorted _<_ l) IsSorted-prop _<_ [] hyp [] [] = refl IsSorted-prop _<_ (x ∷ l) hyp (x₁ ∷ a) (x₂ ∷ b) = cong₂ _∷_ (OnHead-prop _<_ x l hyp x₁ x₂) (IsSorted-prop _<_ l hyp a b) IsSorted-map⁻ : {A : Set}{_≤_ : A → A → Set} → {B : Set}(f : B → A)(l : List B) → IsSorted (λ x y → f x ≤ f y) l → IsSorted _≤_ (List-map f l) IsSorted-map⁻ f .[] [] = [] IsSorted-map⁻ f .(_ ∷ []) (x ∷ []) = [] ∷ [] IsSorted-map⁻ f .(_ ∷ _ ∷ _) (on-∷ x ∷ (x₁ ∷ is)) = (on-∷ x) ∷ IsSorted-map⁻ f _ (x₁ ∷ is) transOnHead : ∀ {A} {l : List A} {y x : A} {_<_ : A → A → Set} → Transitive _<_ → OnHead _<_ y l → x < y → OnHead _<_ x l transOnHead _ [] _ = [] transOnHead trans (on-∷ y<f) x<y = on-∷ (trans x<y y<f) ++-OnHead : ∀ {A} {xs ys : List A} {y : A} {_<_ : A → A → Set} → OnHead _<_ y xs → OnHead _<_ y ys → OnHead _<_ y (xs ++ ys) ++-OnHead [] y<y₁ = y<y₁ ++-OnHead (on-∷ y<x) _ = on-∷ y<x h∉t : ∀ {A} {t : List A} {h : A} {_<_ : A → A → Set} → Irreflexive _<_ _≡_ → Transitive _<_ → IsSorted _<_ (h ∷ t) → h ∉ t h∉t irfl trans (on-∷ h< ∷ sxs) (here refl) = ⊥-elim (irfl h< refl) h∉t irfl trans (on-∷ h< ∷ (x₁< ∷ sxs)) (there h∈t) = h∉t irfl trans ((transOnHead trans x₁< h<) ∷ sxs) h∈t ≤-head : ∀ {A} {l : List A} {x y : A} {_<_ : A → A → Set} {_≤_ : A → A → Set} → Reflexive _≤_ → Trans _<_ _≤_ _≤_ → y ∈ (x ∷ l) → IsSorted _<_ (x ∷ l) → _≤_ x y ≤-head ref≤ trans (here refl) _ = ref≤ ≤-head ref≤ trans (there y∈) (on-∷ x<x₁ ∷ sl) = trans x<x₁ (≤-head ref≤ trans y∈ sl) -- TODO-1 : Better name and/or replace with library property Any-sym : ∀ {a b}{A : Set a}{B : Set b}{tgt : B}{l : List A}{f : A → B} → Any (λ x → tgt ≡ f x) l → Any (λ x → f x ≡ tgt) l Any-sym (here x) = here (sym x) Any-sym (there x) = there (Any-sym x) Any-lookup-correct : ∀ {a b}{A : Set a}{B : Set b}{tgt : B}{l : List A}{f : A → B} → (p : Any (λ x → f x ≡ tgt) l) → Any-lookup p ∈ l Any-lookup-correct (here px) = here refl Any-lookup-correct (there p) = there (Any-lookup-correct p) Any-lookup-correctP : ∀ {a}{A : Set a}{l : List A}{P : A → Set} → (p : Any P l) → Any-lookup p ∈ l Any-lookup-correctP (here px) = here refl Any-lookup-correctP (there p) = there (Any-lookup-correctP p) Any-witness : ∀ {a b} {A : Set a} {l : List A} {P : A → Set b} → (p : Any P l) → P (Any-lookup p) Any-witness (here px) = px Any-witness (there x) = Any-witness x -- TODO-1: there is probably a library property for this. ∈⇒Any : ∀ {A : Set}{x : A} → {xs : List A} → x ∈ xs → Any (_≡ x) xs ∈⇒Any {x = x} (here refl) = here refl ∈⇒Any {x = x} {h ∷ t} (there xxxx) = there (∈⇒Any {xs = t} xxxx) false≢true : false ≢ true false≢true () witness : {A : Set}{P : A → Set}{x : A}{xs : List A} → x ∈ xs → All P xs → P x witness x y = All-lookup y x maybe-⊥ : ∀{a}{A : Set a}{x : A}{y : Maybe A} → y ≡ just x → y ≡ nothing → ⊥ maybe-⊥ () refl Maybe-map-cool : ∀ {S S₁ : Set} {f : S → S₁} {x : Maybe S} {z} → Maybe-map f x ≡ just z → x ≢ nothing Maybe-map-cool {x = nothing} () Maybe-map-cool {x = just y} prf = λ x → ⊥-elim (maybe-⊥ (sym x) refl) Maybe-map-cool-1 : ∀ {S S₁ : Set} {f : S → S₁} {x : Maybe S} {z} → Maybe-map f x ≡ just z → Σ S (λ x' → f x' ≡ z) Maybe-map-cool-1 {x = nothing} () Maybe-map-cool-1 {x = just y} {z = z} refl = y , refl Maybe-map-cool-2 : ∀ {S S₁ : Set} {f : S → S₁} {x : S} {z} → f x ≡ z → Maybe-map f (just x) ≡ just z Maybe-map-cool-2 {S}{S₁}{f}{x}{z} prf rewrite prf = refl T⇒true : ∀ {a : Bool} → T a → a ≡ true T⇒true {true} _ = refl isJust : ∀ {A : Set}{aMB : Maybe A}{a : A} → aMB ≡ just a → Is-just aMB isJust refl = just tt to-witness-isJust-≡ : ∀ {A : Set}{aMB : Maybe A}{a prf} → to-witness (isJust {aMB = aMB} {a} prf) ≡ a to-witness-isJust-≡ {aMB = just a'} {a} {prf} with to-witness-lemma (isJust {aMB = just a'} {a} prf) refl ...| xxx = just-injective (trans (sym xxx) prf) deMorgan : ∀ {A B : Set} → (¬ A) ⊎ (¬ B) → ¬ (A × B) deMorgan (inj₁ ¬a) = λ a×b → ¬a (proj₁ a×b) deMorgan (inj₂ ¬b) = λ a×b → ¬b (proj₂ a×b) ¬subst : ∀ {ℓ₁ ℓ₂} {A : Set ℓ₁} {P : A → Set ℓ₂} → {x y : A} → ¬ (P x) → y ≡ x → ¬ (P y) ¬subst px refl = px ∸-suc-≤ : ∀ (x w : ℕ) → suc x ∸ w ≤ suc (x ∸ w) ∸-suc-≤ x zero = ≤-refl ∸-suc-≤ zero (suc w) rewrite 0∸n≡0 w = z≤n ∸-suc-≤ (suc x) (suc w) = ∸-suc-≤ x w m∸n≤o⇒m∸o≤n : ∀ (x z w : ℕ) → x ∸ z ≤ w → x ∸ w ≤ z m∸n≤o⇒m∸o≤n x zero w p≤ rewrite m≤n⇒m∸n≡0 p≤ = z≤n m∸n≤o⇒m∸o≤n zero (suc z) w p≤ rewrite 0∸n≡0 w = z≤n m∸n≤o⇒m∸o≤n (suc x) (suc z) w p≤ = ≤-trans (∸-suc-≤ x w) (s≤s (m∸n≤o⇒m∸o≤n x z w p≤)) tail-⊆ : ∀ {A : Set} {x} {xs ys : List A} → (x ∷ xs) ⊆List ys → xs ⊆List ys tail-⊆ xxs⊆ys x∈xs = xxs⊆ys (there x∈xs) allDistinctTail : ∀ {A : Set} {x} {xs : List A} → allDistinct (x ∷ xs) → allDistinct xs allDistinctTail allDist i j with allDist (suc i) (suc j) ...| inj₁ refl = inj₁ refl ...| inj₂ lookup≢ = inj₂ lookup≢ ∈-Any-Index-elim : ∀ {A : Set} {x y} {ys : List A} (x∈ys : x ∈ ys) → x ≢ y → y ∈ ys → y ∈ ys ─ Any-index x∈ys ∈-Any-Index-elim (here refl) x≢y (here refl) = ⊥-elim (x≢y refl) ∈-Any-Index-elim (here refl) _ (there y∈ys) = y∈ys ∈-Any-Index-elim (there _) _ (here refl) = here refl ∈-Any-Index-elim (there x∈ys) x≢y (there y∈ys) = there (∈-Any-Index-elim x∈ys x≢y y∈ys) ∉∧⊆List⇒∉ : ∀ {A : Set} {x} {xs ys : List A} → x ∉ xs → ys ⊆List xs → x ∉ ys ∉∧⊆List⇒∉ x∉xs ys∈xs x∈ys = ⊥-elim (x∉xs (ys∈xs x∈ys)) allDistinctʳʳ : ∀ {A : Set} {x x₁ : A} {xs : List A} → allDistinct (x ∷ x₁ ∷ xs) → allDistinct (x ∷ xs) allDistinctʳʳ _ zero zero = inj₁ refl allDistinctʳʳ allDist zero (suc j) with allDist zero (suc (suc j)) ...| inj₂ x≢lookup = inj₂ λ x≡lkpxs → ⊥-elim (x≢lookup x≡lkpxs) allDistinctʳʳ allDist (suc i) zero with allDist (suc (suc i)) zero ...| inj₂ x≢lookup = inj₂ λ x≡lkpxs → ⊥-elim (x≢lookup x≡lkpxs) allDistinctʳʳ allDist (suc i) (suc j) with allDist (suc (suc i)) (suc (suc j)) ...| inj₁ refl = inj₁ refl ...| inj₂ lookup≡ = inj₂ lookup≡ allDistinct⇒∉ : ∀ {A : Set} {x} {xs : List A} → allDistinct (x ∷ xs) → x ∉ xs allDistinct⇒∉ allDist (here x≡x₁) with allDist zero (suc zero) ... | inj₂ x≢x₁ = ⊥-elim (x≢x₁ x≡x₁) allDistinct⇒∉ allDist (there x∈xs) = allDistinct⇒∉ (allDistinctʳʳ allDist) x∈xs sumListMap : ∀ {A : Set} {x} {xs : List A} (f : A → ℕ) → (x∈xs : x ∈ xs) → f-sum f xs ≡ f x + f-sum f (xs ─ Any-index x∈xs) sumListMap _ (here refl) = refl sumListMap {_} {x} {x₁ ∷ xs} f (there x∈xs) rewrite sumListMap f x∈xs | sym (+-assoc (f x) (f x₁) (f-sum f (xs ─ Any-index x∈xs))) | +-comm (f x) (f x₁) | +-assoc (f x₁) (f x) (f-sum f (xs ─ Any-index x∈xs)) = refl lookup⇒Any : ∀ {A : Set} {xs : List A} {P : A → Set} (i : Fin (length xs)) → P (List-lookup xs i) → Any P xs lookup⇒Any {_} {_ ∷ _} zero px = here px lookup⇒Any {_} {_ ∷ _} (suc i) px = there (lookup⇒Any i px) x∉→AllDistinct : ∀ {A : Set} {x} {xs : List A} → allDistinct xs → x ∉ xs → allDistinct (x ∷ xs) x∉→AllDistinct _ _ zero zero = inj₁ refl x∉→AllDistinct _ x∉xs zero (suc j) = inj₂ λ x≡lkp → x∉xs (lookup⇒Any j x≡lkp) x∉→AllDistinct _ x∉xs (suc i) (zero) = inj₂ λ x≡lkp → x∉xs (lookup⇒Any i (sym x≡lkp)) x∉→AllDistinct allDist x∉xs (suc i) (suc j) with allDist i j ...| inj₁ refl = inj₁ refl ...| inj₂ lkup≢ = inj₂ lkup≢ cast-injective : ∀ {n m} {i j : Fin n} {eq : n ≡ m} → cast eq i ≡ cast eq j → i ≡ j cast-injective {_} {_} {zero} {zero} {refl} _ = refl cast-injective {_} {_} {suc i} {suc j} {refl} ci≡cj = cong suc (cast-injective {eq = refl} (Fin-suc-injective ci≡cj)) List-lookup-map : ∀ {A B : Set} (xs : List A) (f : A → B) (α : Fin (length xs)) → let cα = cast (sym (List-length-map f xs)) α in f (List-lookup xs α) ≡ List-lookup (List-map f xs) cα List-lookup-map (x ∷ xs) f zero = refl List-lookup-map (x ∷ xs) f (suc α) = List-lookup-map xs f α allDistinct-Map : ∀ {A B : Set} {xs : List A} {α₁ α₂ : Fin (length xs)} (f : A → B) → allDistinct (List-map f xs) → α₁ ≢ α₂ → f (List-lookup xs α₁) ≢ f (List-lookup xs α₂) allDistinct-Map {_} {_} {xs} {α₁} {α₂} f all≢ α₁≢α₂ flkp≡ with all≢ (cast (sym (List-length-map f xs)) α₁) (cast (sym (List-length-map f xs)) α₂) ...| inj₁ cα₁≡cα₂ = ⊥-elim (α₁≢α₂ (cast-injective {eq = sym (List-length-map f xs)} cα₁≡cα₂)) ...| inj₂ lkpα₁α₂≢ = ⊥-elim (lkpα₁α₂≢ (trans (sym (List-lookup-map xs f α₁)) (trans flkp≡ (List-lookup-map xs f α₂)))) filter⊆ : ∀ {A : Set} {P : A → Set} {P? : (a : A) → Dec (P a)} {xs : List A} → List-filter P? xs ⊆List xs filter⊆ {P? = P?} x∈fxs = Any-filter⁻ P? x∈fxs ⊆⇒filter⊆ : ∀ {A : Set} {P : A → Set} {P? : (a : A) → Dec (P a)} {xs ys : List A} → xs ⊆List ys → List-filter P? xs ⊆List List-filter P? ys ⊆⇒filter⊆ {P? = P?} {xs = xs} {ys = ys} xs∈ys x∈fxs with List-∈-filter⁻ P? {xs = xs} x∈fxs ...| x∈xs , px = List-∈-filter⁺ P? (xs∈ys x∈xs) px map∘filter : ∀ {A B : Set} (xs : List A) (ys : List B) (f : A → B) {P : B → Set} (P? : (b : B) → Dec (P b)) → List-map f xs ≡ ys → List-map f (List-filter (P? ∘ f) xs) ≡ List-filter P? ys map∘filter [] [] _ _ _ = refl map∘filter (x ∷ xs) (.(f x) ∷ .(List-map f xs)) f P? refl with P? (f x) ...| yes prf = cong (f x ∷_) (map∘filter xs (List-map f xs) f P? refl) ...| no imp = map∘filter xs (List-map f xs) f P? refl allDistinct-Filter : ∀ {A : Set} {P : A → Set} {P? : (a : A) → Dec (P a)} {xs : List A} → allDistinct xs → allDistinct (List-filter P? xs) allDistinct-Filter {P? = P?} {xs = x ∷ xs} all≢ i j with P? x ...| no imp = allDistinct-Filter {P? = P?} {xs = xs} (allDistinctTail all≢) i j ...| yes prf = let all≢Tail = allDistinct-Filter {P? = P?} {xs = xs} (allDistinctTail all≢) x∉Tail = allDistinct⇒∉ all≢ in x∉→AllDistinct all≢Tail (∉∧⊆List⇒∉ x∉Tail filter⊆) i j sum-f∘g : ∀ {A B : Set} (xs : List A) (g : B → ℕ) (f : A → B) → f-sum (g ∘ f) xs ≡ f-sum g (List-map f xs) sum-f∘g xs g f = cong sum (List-map-compose xs) map-lookup-allFin : ∀ {A : Set} (xs : List A) → List-map (List-lookup xs) (allFin (length xs)) ≡ xs map-lookup-allFin xs = trans (map-tabulate id (List-lookup xs)) (tabulate-lookup xs) list-index : ∀ {A B : Set} {P : A → B → Set} (_∼_ : Decidable P) (xs : List A) → B → Maybe (Fin (length xs)) list-index _∼_ [] x = nothing list-index _∼_ (x ∷ xs) y with x ∼ y ...| yes x≡y = just zero ...| no x≢y with list-index _∼_ xs y ...| nothing = nothing ...| just i = just (suc i) module DecLemmas {A : Set} (_≟D_ : Decidable {A = A} (_≡_)) where _∈?_ : ∀ (x : A) → (xs : List A) → Dec (Any (x ≡_) xs) x ∈? xs = Any-any (x ≟D_) xs y∉xs⇒Allxs≢y : ∀ {xs : List A} {x y} → y ∉ (x ∷ xs) → x ≢ y × y ∉ xs y∉xs⇒Allxs≢y {xs} {x} {y} y∉ with y ∈? xs ...| yes y∈xs = ⊥-elim (y∉ (there y∈xs)) ...| no y∉xs with x ≟D y ...| yes x≡y = ⊥-elim (y∉ (here (sym x≡y))) ...| no x≢y = x≢y , y∉xs ⊆List-Elim : ∀ {x} {xs ys : List A} (x∈ys : x ∈ ys) → x ∉ xs → xs ⊆List ys → xs ⊆List ys ─ Any-index x∈ys ⊆List-Elim (here refl) x∉xs xs∈ys x₂∈xs with xs∈ys x₂∈xs ...| here refl = ⊥-elim (x∉xs x₂∈xs) ...| there x∈xs = x∈xs ⊆List-Elim (there x∈ys) x∉xs xs∈ys x₂∈xxs with x₂∈xxs ...| there x₂∈xs = ⊆List-Elim (there x∈ys) (proj₂ (y∉xs⇒Allxs≢y x∉xs)) (tail-⊆ xs∈ys) x₂∈xs ...| here refl with xs∈ys x₂∈xxs ...| here refl = here refl ...| there x₂∈ys = there (∈-Any-Index-elim x∈ys (≢-sym (proj₁ (y∉xs⇒Allxs≢y x∉xs))) x₂∈ys) sum-⊆-≤ : ∀ {ys} (xs : List A) (f : A → ℕ) → allDistinct xs → xs ⊆List ys → f-sum f xs ≤ f-sum f ys sum-⊆-≤ [] _ _ _ = z≤n sum-⊆-≤ (x ∷ xs) f dxs xs⊆ys rewrite sumListMap f (xs⊆ys (here refl)) = let x∉xs = allDistinct⇒∉ dxs xs⊆ysT = tail-⊆ xs⊆ys xs⊆ys-x = ⊆List-Elim (xs⊆ys (here refl)) x∉xs xs⊆ysT disTail = allDistinctTail dxs in +-monoʳ-≤ (f x) (sum-⊆-≤ xs f disTail xs⊆ys-x) ⊆-allFin : ∀ {n} {xs : List (Fin n)} → xs ⊆List allFin n ⊆-allFin {x = x} _ = Any-tabulate⁺ x refl intersect : List A → List A → List A intersect xs [] = [] intersect xs (y ∷ ys) with y ∈? xs ...| yes _ = y ∷ intersect xs ys ...| no _ = intersect xs ys union : List A → List A → List A union xs [] = xs union xs (y ∷ ys) with y ∈? xs ...| yes _ = union xs ys ...| no _ = y ∷ union xs ys ∈-intersect : ∀ (xs ys : List A) {α} → α ∈ intersect xs ys → α ∈ xs × α ∈ ys ∈-intersect xs (y ∷ ys) α∈int with y ∈? xs | α∈int ...| no y∉xs | α∈ = ×-map₂ there (∈-intersect xs ys α∈) ...| yes y∈xs | here refl = y∈xs , here refl ...| yes y∈xs | there α∈ = ×-map₂ there (∈-intersect xs ys α∈) x∉⇒x∉intersect : ∀ {x} {xs ys : List A} → x ∉ xs ⊎ x ∉ ys → x ∉ intersect xs ys x∉⇒x∉intersect {x} {xs} {ys} x∉ x∈int = contraposition (∈-intersect xs ys) (deMorgan x∉) x∈int intersectDistinct : ∀ (xs ys : List A) → allDistinct xs → allDistinct ys → allDistinct (intersect xs ys) intersectDistinct xs (y ∷ ys) dxs dys with y ∈? xs ...| yes y∈xs = let distTail = allDistinctTail dys intDTail = intersectDistinct xs ys dxs distTail y∉intTail = x∉⇒x∉intersect (inj₂ (allDistinct⇒∉ dys)) in x∉→AllDistinct intDTail y∉intTail ...| no y∉xs = intersectDistinct xs ys dxs (allDistinctTail dys) x∉⇒x∉union : ∀ {x} {xs ys : List A} → x ∉ xs × x ∉ ys → x ∉ union xs ys x∉⇒x∉union {_} {_} {[]} (x∉xs , _) x∈∪ = ⊥-elim (x∉xs x∈∪) x∉⇒x∉union {x} {xs} {y ∷ ys} (x∉xs , x∉ys) x∈union with y ∈? xs | x∈union ...| yes y∈xs | x∈∪ = ⊥-elim (x∉⇒x∉union (x∉xs , (proj₂ (y∉xs⇒Allxs≢y x∉ys))) x∈∪) ...| no y∉xs | here refl = ⊥-elim (proj₁ (y∉xs⇒Allxs≢y x∉ys) refl) ...| no y∉xs | there x∈∪ = ⊥-elim (x∉⇒x∉union (x∉xs , (proj₂ (y∉xs⇒Allxs≢y x∉ys))) x∈∪) unionDistinct : ∀ (xs ys : List A) → allDistinct xs → allDistinct ys → allDistinct (union xs ys) unionDistinct xs [] dxs dys = dxs unionDistinct xs (y ∷ ys) dxs dys with y ∈? xs ...| yes y∈xs = unionDistinct xs ys dxs (allDistinctTail dys) ...| no y∉xs = let distTail = allDistinctTail dys uniDTail = unionDistinct xs ys dxs distTail y∉intTail = x∉⇒x∉union (y∉xs , allDistinct⇒∉ dys) in x∉→AllDistinct uniDTail y∉intTail sumIntersect≤ : ∀ (xs ys : List A) (f : A → ℕ) → f-sum f (intersect xs ys) ≤ f-sum f (xs ++ ys) sumIntersect≤ _ [] _ = z≤n sumIntersect≤ xs (y ∷ ys) f with y ∈? xs ...| yes y∈xs rewrite map-++-commute f xs (y ∷ ys) | sum-++-commute (List-map f xs) (List-map f (y ∷ ys)) | sym (+-assoc (f-sum f xs) (f y) (f-sum f ys)) | +-comm (f-sum f xs) (f y) | +-assoc (f y) (f-sum f xs) (f-sum f ys) | sym (sum-++-commute (List-map f xs) (List-map f ys)) | sym (map-++-commute f xs ys) = +-monoʳ-≤ (f y) (sumIntersect≤ xs ys f) ...| no y∉xs rewrite map-++-commute f xs (y ∷ ys) | sum-++-commute (List-map f xs) (List-map f (y ∷ ys)) | +-comm (f y) (f-sum f ys) | sym (+-assoc (f-sum f xs) (f-sum f ys) (f y)) | sym (sum-++-commute (List-map f xs) (List-map f ys)) | sym (map-++-commute f xs ys) = ≤-stepsʳ (f y) (sumIntersect≤ xs ys f) index∘lookup-id : ∀ {B : Set} (xs : List B) (f : B → A) → allDistinct (List-map f xs) → {α : Fin (length xs)} → list-index (_≟D_ ∘ f) xs ((f ∘ List-lookup xs) α) ≡ just α index∘lookup-id (x ∷ xs) f all≢ {zero} with f x ≟D f x ...| yes fx≡fx = refl ...| no fx≢fx = ⊥-elim (fx≢fx refl) index∘lookup-id (x ∷ xs) f all≢ {suc α} with f x ≟D f (List-lookup xs α) ...| yes fx≡lkp = ⊥-elim (allDistinct⇒∉ all≢ (Any-map⁺ (lookup⇒Any α fx≡lkp))) ...| no fx≢lkp with list-index (_≟D_ ∘ f) xs (f (List-lookup xs α)) | index∘lookup-id xs f (allDistinctTail all≢) {α} ...| just .α | refl = refl lookup∘index-id : ∀ {B : Set} (xs : List B) (f : B → A) → allDistinct (List-map f xs) → {α : Fin (length xs)} {x : A} → list-index (_≟D_ ∘ f) xs x ≡ just α → (f ∘ List-lookup xs) α ≡ x lookup∘index-id (x₁ ∷ xs) f all≢ {α} {x} lkp≡α with f x₁ ≟D x ...| yes fx≡nId rewrite sym (just-injective lkp≡α) = fx≡nId ...| no fx≢nId with list-index (_≟D_ ∘ f) xs x | inspect (list-index (_≟D_ ∘ f) xs) x ...| just _ | [ eq ] rewrite sym (just-injective lkp≡α) = lookup∘index-id xs f (allDistinctTail all≢) eq
algebraic-stack_agda0000_doc_4095
module Cats.Category.Setoids.Facts where open import Cats.Category open import Cats.Category.Setoids using (Setoids) open import Cats.Category.Setoids.Facts.Exponentials using (hasExponentials) open import Cats.Category.Setoids.Facts.Initial using (hasInitial) open import Cats.Category.Setoids.Facts.Products using (hasProducts ; hasBinaryProducts) open import Cats.Category.Setoids.Facts.Terminal using (hasTerminal) instance isCCC : ∀ l → IsCCC (Setoids l l) isCCC l = record { hasFiniteProducts = record {} } -- [1] -- [1] For no discernible reason, `record {}` doesn't work.
algebraic-stack_agda0000_doc_3696
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import Util.Prelude -- This module defines types used in the specification of a SystemModel. module Yasm.Types where -- Actions that can be performed by peers. -- -- For now, the SystemModel supports only one kind of action: to send a -- message. Later it might include things like logging, crashes, assertion -- failures, etc. For example, if an assertion fires, this -- could "kill the process" and make it not send any messages in the future. -- We could also then prove that the handlers do not crash, certain -- messages are logged under certain circumstances, etc. -- -- Alternatively, certain actions can be kept outside the system model by -- defining an application-specific PeerState type (see `Yasm.Base`). -- For example: -- -- > libraHandle : Msg → Status × Log × LState → Status × LState × List Action -- > libraHandle _ (Crashed , l , s) = Crashed , s , [] -- i.e., crashed peers never send messages -- > -- > handle = filter isSend ∘ libraHandle data Action (Msg : Set) : Set where send : (m : Msg) → Action Msg -- Injectivity of `send`. action-send-injective : ∀ {Msg}{m m' : Msg} → send m ≡ send m' → m ≡ m' action-send-injective refl = refl
algebraic-stack_agda0000_doc_3697
{-# OPTIONS --without-K --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.Substitution.Properties {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped open import Definition.Untyped.Properties open import Definition.Typed open import Definition.Typed.Weakening open import Definition.LogicalRelation open import Definition.LogicalRelation.Substitution open import Definition.LogicalRelation.Substitution.Irrelevance using (irrelevanceSubst′) open import Definition.LogicalRelation.Irrelevance open import Definition.LogicalRelation.Properties import Definition.LogicalRelation.Weakening as LR open import Tools.Unit open import Tools.Product import Tools.PropositionalEquality as PE -- Valid substitutions are well-formed wellformedSubst : ∀ {Γ Δ σ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) → Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ → Δ ⊢ˢ σ ∷ Γ wellformedSubst ε′ ⊢Δ [σ] = id wellformedSubst ([Γ] ∙′ [A]) ⊢Δ ([tailσ] , [headσ]) = wellformedSubst [Γ] ⊢Δ [tailσ] , escapeTerm (proj₁ ([A] ⊢Δ [tailσ])) [headσ] -- Valid substitution equality is well-formed wellformedSubstEq : ∀ {Γ Δ σ σ′} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) → Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ] → Δ ⊢ˢ σ ≡ σ′ ∷ Γ wellformedSubstEq ε′ ⊢Δ [σ] [σ≡σ′] = id wellformedSubstEq ([Γ] ∙′ [A]) ⊢Δ ([tailσ] , [headσ]) ([tailσ≡σ′] , [headσ≡σ′]) = wellformedSubstEq [Γ] ⊢Δ [tailσ] [tailσ≡σ′] , ≅ₜ-eq (escapeTermEq (proj₁ ([A] ⊢Δ [tailσ])) [headσ≡σ′]) -- Extend a valid substitution with a term consSubstS : ∀ {l σ t A Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) ([t] : Δ ⊩⟨ l ⟩ t ∷ subst σ A / proj₁ ([A] ⊢Δ [σ])) → Δ ⊩ˢ consSubst σ t ∷ Γ ∙ A / [Γ] ∙″ [A] / ⊢Δ consSubstS [Γ] ⊢Δ [σ] [A] [t] = [σ] , [t] -- Extend a valid substitution equality with a term consSubstSEq : ∀ {l σ σ′ t A Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) ([σ≡σ′] : Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ]) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) ([t] : Δ ⊩⟨ l ⟩ t ∷ subst σ A / proj₁ ([A] ⊢Δ [σ])) → Δ ⊩ˢ consSubst σ t ≡ consSubst σ′ t ∷ Γ ∙ A / [Γ] ∙″ [A] / ⊢Δ / consSubstS {t = t} {A = A} [Γ] ⊢Δ [σ] [A] [t] consSubstSEq [Γ] ⊢Δ [σ] [σ≡σ′] [A] [t] = [σ≡σ′] , reflEqTerm (proj₁ ([A] ⊢Δ [σ])) [t] -- Weakening of valid substitutions wkSubstS : ∀ {ρ σ Γ Δ Δ′} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) (⊢Δ′ : ⊢ Δ′) ([ρ] : ρ ∷ Δ′ ⊆ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) → Δ′ ⊩ˢ ρ •ₛ σ ∷ Γ / [Γ] / ⊢Δ′ wkSubstS ε′ ⊢Δ ⊢Δ′ ρ [σ] = tt wkSubstS {σ = σ} {Γ = Γ ∙ A} ([Γ] ∙′ x) ⊢Δ ⊢Δ′ ρ [σ] = let [tailσ] = wkSubstS [Γ] ⊢Δ ⊢Δ′ ρ (proj₁ [σ]) in [tailσ] , irrelevanceTerm′ (wk-subst A) (LR.wk ρ ⊢Δ′ (proj₁ (x ⊢Δ (proj₁ [σ])))) (proj₁ (x ⊢Δ′ [tailσ])) (LR.wkTerm ρ ⊢Δ′ (proj₁ (x ⊢Δ (proj₁ [σ]))) (proj₂ [σ])) -- Weakening of valid substitution equality wkSubstSEq : ∀ {ρ σ σ′ Γ Δ Δ′} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) (⊢Δ′ : ⊢ Δ′) ([ρ] : ρ ∷ Δ′ ⊆ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) ([σ≡σ′] : Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ]) → Δ′ ⊩ˢ ρ •ₛ σ ≡ ρ •ₛ σ′ ∷ Γ / [Γ] / ⊢Δ′ / wkSubstS [Γ] ⊢Δ ⊢Δ′ [ρ] [σ] wkSubstSEq ε′ ⊢Δ ⊢Δ′ ρ [σ] [σ≡σ′] = tt wkSubstSEq {Γ = Γ ∙ A} ([Γ] ∙′ x) ⊢Δ ⊢Δ′ ρ [σ] [σ≡σ′] = wkSubstSEq [Γ] ⊢Δ ⊢Δ′ ρ (proj₁ [σ]) (proj₁ [σ≡σ′]) , irrelevanceEqTerm′ (wk-subst A) (LR.wk ρ ⊢Δ′ (proj₁ (x ⊢Δ (proj₁ [σ])))) (proj₁ (x ⊢Δ′ (wkSubstS [Γ] ⊢Δ ⊢Δ′ ρ (proj₁ [σ])))) (LR.wkEqTerm ρ ⊢Δ′ (proj₁ (x ⊢Δ (proj₁ [σ]))) (proj₂ [σ≡σ′])) -- Weaken a valid substitution by one type wk1SubstS : ∀ {F σ Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) (⊢F : Δ ⊢ F) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) → (Δ ∙ F) ⊩ˢ wk1Subst σ ∷ Γ / [Γ] / (⊢Δ ∙ ⊢F) wk1SubstS {F} {σ} {Γ} {Δ} [Γ] ⊢Δ ⊢F [σ] = wkSubstS [Γ] ⊢Δ (⊢Δ ∙ ⊢F) (step id) [σ] -- Weaken a valid substitution equality by one type wk1SubstSEq : ∀ {F σ σ′ Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) (⊢F : Δ ⊢ F) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) ([σ≡σ′] : Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ]) → (Δ ∙ F) ⊩ˢ wk1Subst σ ≡ wk1Subst σ′ ∷ Γ / [Γ] / (⊢Δ ∙ ⊢F) / wk1SubstS [Γ] ⊢Δ ⊢F [σ] wk1SubstSEq {l} {F} {σ} {Γ} {Δ} [Γ] ⊢Δ ⊢F [σ] [σ≡σ′] = wkSubstSEq [Γ] ⊢Δ (⊢Δ ∙ ⊢F) (step id) [σ] [σ≡σ′] -- Lift a valid substitution liftSubstS : ∀ {l F σ Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) ([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ]) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) → (Δ ∙ subst σ F) ⊩ˢ liftSubst σ ∷ Γ ∙ F / [Γ] ∙″ [F] / (⊢Δ ∙ escape (proj₁ ([F] ⊢Δ [σ]))) liftSubstS {F = F} {σ = σ} {Δ = Δ} [Γ] ⊢Δ [F] [σ] = let ⊢F = escape (proj₁ ([F] ⊢Δ [σ])) [tailσ] = wk1SubstS {F = subst σ F} [Γ] ⊢Δ (escape (proj₁ ([F] ⊢Δ [σ]))) [σ] var0 = var (⊢Δ ∙ ⊢F) (PE.subst (λ x → 0 ∷ x ∈ (Δ ∙ subst σ F)) (wk-subst F) here) in [tailσ] , neuTerm (proj₁ ([F] (⊢Δ ∙ ⊢F) [tailσ])) (var 0) var0 (~-var var0) -- Lift a valid substitution equality liftSubstSEq : ∀ {l F σ σ′ Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) ([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ]) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) ([σ≡σ′] : Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ]) → (Δ ∙ subst σ F) ⊩ˢ liftSubst σ ≡ liftSubst σ′ ∷ Γ ∙ F / [Γ] ∙″ [F] / (⊢Δ ∙ escape (proj₁ ([F] ⊢Δ [σ]))) / liftSubstS {F = F} [Γ] ⊢Δ [F] [σ] liftSubstSEq {F = F} {σ = σ} {σ′ = σ′} {Δ = Δ} [Γ] ⊢Δ [F] [σ] [σ≡σ′] = let ⊢F = escape (proj₁ ([F] ⊢Δ [σ])) [tailσ] = wk1SubstS {F = subst σ F} [Γ] ⊢Δ (escape (proj₁ ([F] ⊢Δ [σ]))) [σ] [tailσ≡σ′] = wk1SubstSEq [Γ] ⊢Δ (escape (proj₁ ([F] ⊢Δ [σ]))) [σ] [σ≡σ′] var0 = var (⊢Δ ∙ ⊢F) (PE.subst (λ x → 0 ∷ x ∈ (Δ ∙ subst σ F)) (wk-subst F) here) in [tailσ≡σ′] , neuEqTerm (proj₁ ([F] (⊢Δ ∙ ⊢F) [tailσ])) (var 0) (var 0) var0 var0 (~-var var0) mutual -- Valid contexts are well-formed soundContext : ∀ {Γ} → ⊩ᵛ Γ → ⊢ Γ soundContext ε′ = ε soundContext (x ∙′ x₁) = soundContext x ∙ escape (irrelevance′ (subst-id _) (proj₁ (x₁ (soundContext x) (idSubstS x)))) -- From a valid context we can constuct a valid identity substitution idSubstS : ∀ {Γ} ([Γ] : ⊩ᵛ Γ) → Γ ⊩ˢ idSubst ∷ Γ / [Γ] / soundContext [Γ] idSubstS ε′ = tt idSubstS {Γ = Γ ∙ A} ([Γ] ∙′ [A]) = let ⊢Γ = soundContext [Γ] ⊢Γ∙A = soundContext ([Γ] ∙″ [A]) ⊢Γ∙A′ = ⊢Γ ∙ escape (proj₁ ([A] ⊢Γ (idSubstS [Γ]))) [A]′ = wk1SubstS {F = subst idSubst A} [Γ] ⊢Γ (escape (proj₁ ([A] (soundContext [Γ]) (idSubstS [Γ])))) (idSubstS [Γ]) [tailσ] = irrelevanceSubst′ (PE.cong (_∙_ Γ) (subst-id A)) [Γ] [Γ] ⊢Γ∙A′ ⊢Γ∙A [A]′ var0 = var ⊢Γ∙A (PE.subst (λ x → 0 ∷ x ∈ (Γ ∙ A)) (wk-subst A) (PE.subst (λ x → 0 ∷ wk1 (subst idSubst A) ∈ (Γ ∙ x)) (subst-id A) here)) in [tailσ] , neuTerm (proj₁ ([A] ⊢Γ∙A [tailσ])) (var 0) var0 (~-var var0) -- Reflexivity valid substitutions reflSubst : ∀ {σ Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) → Δ ⊩ˢ σ ≡ σ ∷ Γ / [Γ] / ⊢Δ / [σ] reflSubst ε′ ⊢Δ [σ] = tt reflSubst ([Γ] ∙′ x) ⊢Δ [σ] = reflSubst [Γ] ⊢Δ (proj₁ [σ]) , reflEqTerm (proj₁ (x ⊢Δ (proj₁ [σ]))) (proj₂ [σ]) -- Reflexivity of valid identity substitution reflIdSubst : ∀ {Γ} ([Γ] : ⊩ᵛ Γ) → Γ ⊩ˢ idSubst ≡ idSubst ∷ Γ / [Γ] / soundContext [Γ] / idSubstS [Γ] reflIdSubst [Γ] = reflSubst [Γ] (soundContext [Γ]) (idSubstS [Γ]) -- Symmetry of valid substitution symS : ∀ {σ σ′ Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) ([σ′] : Δ ⊩ˢ σ′ ∷ Γ / [Γ] / ⊢Δ) → Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ] → Δ ⊩ˢ σ′ ≡ σ ∷ Γ / [Γ] / ⊢Δ / [σ′] symS ε′ ⊢Δ [σ] [σ′] [σ≡σ′] = tt symS ([Γ] ∙′ x) ⊢Δ [σ] [σ′] [σ≡σ′] = symS [Γ] ⊢Δ (proj₁ [σ]) (proj₁ [σ′]) (proj₁ [σ≡σ′]) , let [σA] = proj₁ (x ⊢Δ (proj₁ [σ])) [σ′A] = proj₁ (x ⊢Δ (proj₁ [σ′])) [σA≡σ′A] = (proj₂ (x ⊢Δ (proj₁ [σ]))) (proj₁ [σ′]) (proj₁ [σ≡σ′]) [headσ′≡headσ] = symEqTerm [σA] (proj₂ [σ≡σ′]) in convEqTerm₁ [σA] [σ′A] [σA≡σ′A] [headσ′≡headσ] -- Transitivity of valid substitution transS : ∀ {σ σ′ σ″ Γ Δ} ([Γ] : ⊩ᵛ Γ) (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ) ([σ′] : Δ ⊩ˢ σ′ ∷ Γ / [Γ] / ⊢Δ) ([σ″] : Δ ⊩ˢ σ″ ∷ Γ / [Γ] / ⊢Δ) → Δ ⊩ˢ σ ≡ σ′ ∷ Γ / [Γ] / ⊢Δ / [σ] → Δ ⊩ˢ σ′ ≡ σ″ ∷ Γ / [Γ] / ⊢Δ / [σ′] → Δ ⊩ˢ σ ≡ σ″ ∷ Γ / [Γ] / ⊢Δ / [σ] transS ε′ ⊢Δ [σ] [σ′] [σ″] [σ≡σ′] [σ′≡σ″] = tt transS ([Γ] ∙′ x) ⊢Δ [σ] [σ′] [σ″] [σ≡σ′] [σ′≡σ″] = transS [Γ] ⊢Δ (proj₁ [σ]) (proj₁ [σ′]) (proj₁ [σ″]) (proj₁ [σ≡σ′]) (proj₁ [σ′≡σ″]) , let [σA] = proj₁ (x ⊢Δ (proj₁ [σ])) [σ′A] = proj₁ (x ⊢Δ (proj₁ [σ′])) [σ″A] = proj₁ (x ⊢Δ (proj₁ [σ″])) [σ′≡σ″]′ = convEqTerm₂ [σA] [σ′A] ((proj₂ (x ⊢Δ (proj₁ [σ]))) (proj₁ [σ′]) (proj₁ [σ≡σ′])) (proj₂ [σ′≡σ″]) in transEqTerm [σA] (proj₂ [σ≡σ′]) [σ′≡σ″]′
algebraic-stack_agda0000_doc_3698
module Self where import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; cong; sym) data B : Set where T : B F : B _&&_ : B -> B -> B infixl 20 _&&_ T && T = T T && F = F F && _ = F _||_ : B -> B -> B infixl 15 _||_ T || _ = T F || T = T F || F = F p||p≡p : ∀ (p : B) -> p || p ≡ p p||p≡p T = refl p||p≡p F = refl p&&p≡p : ∀ (p : B) -> p && p ≡ p p&&p≡p T = refl p&&p≡p F = refl -- 交换律 a&&b≡b&&a : ∀ (a b : B) -> a && b ≡ b && a a&&b≡b&&a T T = refl a&&b≡b&&a T F = refl a&&b≡b&&a F T = refl a&&b≡b&&a F F = refl a||b≡b||a : ∀ (a b : B) -> a || b ≡ b || a a||b≡b||a T T = refl a||b≡b||a T F = refl a||b≡b||a F T = refl a||b≡b||a F F = refl abc||abc : ∀ (a b c : B) -> (a || b) || c ≡ a || (b || c) abc||abc T b c = refl abc||abc F T c = refl abc||abc F F T = refl abc||abc F F F = refl abc&&abc : ∀ (a b c : B) -> a && b && c ≡ a && (b && c) abc&&abc T T T = refl abc&&abc T T F = refl abc&&abc T F c = refl abc&&abc F b c = refl -- 分配律 a&&b||c≡a&&b||a&&c : ∀ (a b c : B) -> a && (b || c) ≡ a && b || a && c a&&b||c≡a&&b||a&&c T T c = refl a&&b||c≡a&&b||a&&c T F T = refl a&&b||c≡a&&b||a&&c T F F = refl a&&b||c≡a&&b||a&&c F T c = refl a&&b||c≡a&&b||a&&c F F c = refl a||b&&c≡a||b&&a||c : ∀ (a b c : B) -> a || b && c ≡ (a || b) && (a || c) a||b&&c≡a||b&&a||c T b c = refl a||b&&c≡a||b&&a||c F T T = refl a||b&&c≡a||b&&a||c F T F = refl a||b&&c≡a||b&&a||c F F c = refl T&&p≡p : ∀ (p : B) -> T && p ≡ p T&&p≡p T = refl T&&p≡p F = refl F||p≡p : ∀ (p : B) -> F || p ≡ p F||p≡p T = refl F||p≡p F = refl ¬_ : B -> B infix 25 ¬_ ¬ F = T ¬ T = F -- 负负得正 ¬¬p≡p : ∀ (p : B) -> ¬ (¬ p) ≡ p ¬¬p≡p T = refl ¬¬p≡p F = refl -- 德·摩根律 ¬a&&b≡¬a||¬b : ∀ (a b : B) -> ¬ (a && b) ≡ ¬ a || ¬ b ¬a&&b≡¬a||¬b T T = refl ¬a&&b≡¬a||¬b T F = refl ¬a&&b≡¬a||¬b F T = refl ¬a&&b≡¬a||¬b F F = refl ¬a||b≡¬a&&¬b : ∀ (a b : B) -> ¬ (a || b) ≡ ¬ a && ¬ b ¬a||b≡¬a&&¬b T T = refl ¬a||b≡¬a&&¬b T F = refl ¬a||b≡¬a&&¬b F T = refl ¬a||b≡¬a&&¬b F F = refl -- 自反律 p&&¬p≡F : ∀ (p : B) -> p && ¬ p ≡ F p&&¬p≡F T = refl p&&¬p≡F F = refl -- 排中律 ¬p||p≡T : ∀ (p : B) -> ¬ p || p ≡ T ¬p||p≡T T = refl ¬p||p≡T F = refl -- 蕴含 如果 .. 就 _to_ : B -> B -> B infixl 10 _to_ T to F = F T to T = T F to _ = T -- 蕴含等值推演 ptoq≡¬p||q : ∀ (p q : B) -> p to q ≡ ¬ p || q ptoq≡¬p||q T T = refl ptoq≡¬p||q T F = refl ptoq≡¬p||q F q = refl Ttop≡p : ∀ (p : B) -> T to p ≡ p Ttop≡p T = refl Ttop≡p F = refl Ftop≡T : ∀ (p : B) -> F to p ≡ T Ftop≡T p = refl -- 等价 _<>_ : B -> B -> B infixl 10 _eq_ T <> T = T F <> T = F T <> F = F F <> F = T -- 等价等值式 p<>q≡ptoq&&qtop : ∀ (p q : B) -> p <> q ≡ (p to q) && (q to p) p<>q≡ptoq&&qtop T T = refl p<>q≡ptoq&&qtop T F = refl p<>q≡ptoq&&qtop F T = refl p<>q≡ptoq&&qtop F F = refl -- lemma 01 p||q&&¬q≡p : ∀ (p q : B) -> p || q && ¬ q ≡ p p||q&&¬q≡p T T = refl p||q&&¬q≡p T F = refl p||q&&¬q≡p F q rewrite p&&¬p≡F q = refl -- proof 01 p&&q||p&&¬q≡p : ∀ (p q : B) -> p && q || p && ¬ q ≡ p p&&q||p&&¬q≡p T T = refl p&&q||p&&¬q≡p T F = refl p&&q||p&&¬q≡p F q = refl -- proof 02 atob≡¬bto¬a : ∀ (a b : B) -> a to b ≡ ¬ b to ¬ a atob≡¬bto¬a a b rewrite ptoq≡¬p||q a b | ptoq≡¬p||q (¬ b) (¬ a) | a||b≡b||a (¬ a) b | ¬¬p≡p b = refl implies₁ : ∀ (p q r s : B) -> ((p to (q to r)) && (¬ s || p) && q) to (s to r) ≡ T implies₁ T T T T = refl implies₁ T T T F = refl implies₁ T T F s = refl implies₁ T F T T = refl implies₁ T F T F = refl implies₁ T F F T = refl implies₁ T F F F = refl implies₁ F T T T = refl implies₁ F T T F = refl implies₁ F T F T = refl implies₁ F T F F = refl implies₁ F F r T = refl implies₁ F F r F = refl
algebraic-stack_agda0000_doc_3699
module my-vector where open import nat open import bool open import eq data 𝕍 {ℓ}(A : Set ℓ) : ℕ → Set ℓ where [] : 𝕍 A 0 _::_ : {n : ℕ} (x : A) (xs : 𝕍 A n) → 𝕍 A (suc n) infixr 6 _::_ _++𝕍_ _++𝕍_ : ∀ {ℓ} {A : Set ℓ}{n m : ℕ} → 𝕍 A n → 𝕍 A m → 𝕍 A (n + m) [] ++𝕍 ys = ys (x :: xs) ++𝕍 ys = x :: (xs ++𝕍 ys) test-vector : 𝕍 𝔹 4 test-vector = ff :: tt :: ff :: ff :: [] test-vector-append : 𝕍 𝔹 8 test-vector-append = test-vector ++𝕍 test-vector head𝕍 : ∀{ℓ}{A : Set ℓ}{n : ℕ} → 𝕍 A (suc n) → A head𝕍 (x :: _) = x tail𝕍 : ∀{ℓ}{A : Set ℓ}{n : ℕ} → 𝕍 A n → 𝕍 A (pred n) tail𝕍 [] = [] tail𝕍 (_ :: xs) = xs map𝕍 : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'}{n : ℕ} → (A → B) → 𝕍 A n → 𝕍 B n map𝕍 f [] = [] map𝕍 f (x :: xs) = f x :: map𝕍 f xs concat𝕍 : ∀{ℓ}{A : Set ℓ}{n m : ℕ} → 𝕍 (𝕍 A n) m → 𝕍 A (m * n) concat𝕍 [] = [] concat𝕍 (xs :: xs₁) = xs ++𝕍 (concat𝕍 xs₁) nth𝕍 : ∀{ℓ}{A : Set ℓ}{m : ℕ} → (n : ℕ) → n < m ≡ tt → 𝕍 A m → A nth𝕍 zero () [] nth𝕍 zero _ (x :: _) = x nth𝕍 (suc _) () [] nth𝕍 (suc n₁) p (_ :: xs) = nth𝕍 n₁ p xs repeat𝕍 : ∀{ℓ}{A : Set ℓ} → (a : A)(n : ℕ) → 𝕍 A n repeat𝕍 a zero = [] repeat𝕍 a (suc n) = a :: (repeat𝕍 a n)
algebraic-stack_agda0000_doc_3700
-- 2016-01-05, Jesper: In some cases, the new unifier is still too restrictive -- when --cubical-compatible is enabled because it doesn't do generalization of datatype -- indices. This should be fixed in the future. -- 2016-06-23, Jesper: Now fixed. {-# OPTIONS --cubical-compatible #-} data _≡_ {a} {A : Set a} (x : A) : A → Set a where refl : x ≡ x data Bar : Set₁ where bar : Bar baz : (A : Set) → Bar data Foo : Bar → Set₁ where foo : Foo bar test : foo ≡ foo → Set₁ test refl = Set
algebraic-stack_agda0000_doc_3701
module _ where module M (A : Set) where record R : Set where postulate B : Set postulate A : Set r : M.R A module M' = M A open import Agda.Builtin.Reflection open import Agda.Builtin.List postulate any : {A : Set} → A macro m : Term → TC _ m goal = bindTC (inferType goal) λ goal-type → bindTC (normalise goal-type) λ goal-type → bindTC (inferType goal-type) λ _ → unify goal (def (quote any) []) g : M'.R.B r g = m
algebraic-stack_agda0000_doc_3702
{-# OPTIONS --no-positivity-check #-} module Clowns where import Equality import Isomorphism import Derivative import ChainRule open import Sets open import Functor open import Zipper open import Dissect open Functor.Recursive open Functor.Semantics -- Natural numbers NatF : U NatF = K [1] + Id Nat : Set Nat = μ NatF zero : Nat zero = inn (inl <>) suc : Nat -> Nat suc n = inn (inr n) plus : Nat -> Nat -> Nat plus n m = fold NatF φ n where φ : ⟦ NatF ⟧ Nat -> Nat φ (inl <>) = m φ (inr z) = suc z -- Lists ListF : (A : Set) -> U ListF A = K [1] + K A × Id List' : (A : Set) -> Set List' A = μ (ListF A) nil : {A : Set} -> List' A nil = inn (inl <>) cons : {A : Set} -> A -> List' A -> List' A cons x xs = inn (inr < x , xs >) sum : List' Nat -> Nat sum = fold (ListF Nat) φ where φ : ⟦ ListF Nat ⟧ Nat -> Nat φ (inl <>) = zero φ (inr < n , m >) = plus n m TreeF : U TreeF = K [1] + Id × Id Tree : Set Tree = μ TreeF leaf : Tree leaf = inn (inl <>) node : Tree -> Tree -> Tree node l r = inn (inr < l , r >)
algebraic-stack_agda0000_doc_3703
module Numeric.Nat.GCD.Properties where open import Prelude open import Numeric.Nat.Properties open import Numeric.Nat.Divide open import Numeric.Nat.Divide.Properties open import Numeric.Nat.GCD open import Numeric.Nat.GCD.Extended open import Tactic.Nat open import Tactic.Cong gcd-is-gcd : ∀ d a b → gcd! a b ≡ d → IsGCD d a b gcd-is-gcd d a b refl with gcd a b ... | gcd-res _ isgcd = isgcd gcd-divides-l : ∀ a b → gcd! a b Divides a gcd-divides-l a b with gcd a b ... | gcd-res _ i = IsGCD.d|a i gcd-divides-r : ∀ a b → gcd! a b Divides b gcd-divides-r a b with gcd a b ... | gcd-res _ i = IsGCD.d|b i is-gcd-unique : ∀ {a b} d₁ d₂ (g₁ : IsGCD d₁ a b) (g₂ : IsGCD d₂ a b) → d₁ ≡ d₂ is-gcd-unique d d′ (is-gcd d|a d|b gd) (is-gcd d′|a d′|b gd′) = divides-antisym (gd′ d d|a d|b) (gd d′ d′|a d′|b) gcd-unique : ∀ a b d → IsGCD d a b → gcd! a b ≡ d gcd-unique a b d pd with gcd a b ... | gcd-res d′ pd′ = is-gcd-unique d′ d pd′ pd is-gcd-commute : ∀ {d a b} → IsGCD d a b → IsGCD d b a is-gcd-commute (is-gcd d|a d|b g) = is-gcd d|b d|a (flip ∘ g) gcd-commute : ∀ a b → gcd! a b ≡ gcd! b a gcd-commute a b with gcd b a gcd-commute a b | gcd-res d p = gcd-unique a b d (is-gcd-commute p) gcd-factor-l : ∀ {a b} → a Divides b → gcd! a b ≡ a gcd-factor-l {a} (factor! b) = gcd-unique a (b * a) a (is-gcd divides-refl (divides-mul-r b divides-refl) λ _ k|a _ → k|a) gcd-factor-r : ∀ {a b} → b Divides a → gcd! a b ≡ b gcd-factor-r {a} {b} b|a = gcd-commute a b ⟨≡⟩ gcd-factor-l b|a gcd-idem : ∀ a → gcd! a a ≡ a gcd-idem a = gcd-factor-l divides-refl gcd-zero-l : ∀ n → gcd! 0 n ≡ n gcd-zero-l n = gcd-unique 0 n n (is-gcd (factor! 0) divides-refl λ _ _ k|n → k|n) gcd-zero-r : ∀ n → gcd! n 0 ≡ n gcd-zero-r n = gcd-commute n 0 ⟨≡⟩ gcd-zero-l n zero-is-gcd-l : ∀ {a b} → IsGCD 0 a b → a ≡ 0 zero-is-gcd-l (is-gcd 0|a _ _) = divides-zero 0|a zero-is-gcd-r : ∀ {a b} → IsGCD 0 a b → b ≡ 0 zero-is-gcd-r (is-gcd _ 0|b _) = divides-zero 0|b zero-gcd-l : ∀ a b → gcd! a b ≡ 0 → a ≡ 0 zero-gcd-l a b eq with gcd a b zero-gcd-l a b refl | gcd-res .0 p = zero-is-gcd-l p zero-gcd-r : ∀ a b → gcd! a b ≡ 0 → b ≡ 0 zero-gcd-r a b eq with gcd a b zero-gcd-r a b refl | gcd-res .0 p = zero-is-gcd-r p nonzero-is-gcd-l : ∀ {a b d} {{_ : NonZero a}} → IsGCD d a b → NonZero d nonzero-is-gcd-l {0} {{}} _ nonzero-is-gcd-l {a@(suc _)} {d = suc _} _ = _ nonzero-is-gcd-l {a@(suc _)} {d = 0} (is-gcd (factor q eq) _ _) = refute eq nonzero-is-gcd-r : ∀ {a b d} {{_ : NonZero b}} → IsGCD d a b → NonZero d nonzero-is-gcd-r isgcd = nonzero-is-gcd-l (is-gcd-commute isgcd) nonzero-gcd-l : ∀ a b {{_ : NonZero a}} → NonZero (gcd! a b) nonzero-gcd-l a b = nonzero-is-gcd-l (GCD.isGCD (gcd a b)) nonzero-gcd-r : ∀ a b {{_ : NonZero b}} → NonZero (gcd! a b) nonzero-gcd-r a b = nonzero-is-gcd-r (GCD.isGCD (gcd a b)) private _|>_ = divides-trans gcd-assoc : ∀ a b c → gcd! a (gcd! b c) ≡ gcd! (gcd! a b) c gcd-assoc a b c with gcd a b | gcd b c ... | gcd-res ab (is-gcd ab|a ab|b gab) | gcd-res bc (is-gcd bc|b bc|c gbc) with gcd ab c ... | gcd-res ab-c (is-gcd abc|ab abc|c gabc) = gcd-unique a bc ab-c (is-gcd (abc|ab |> ab|a) (gbc ab-c (abc|ab |> ab|b) abc|c) λ k k|a k|bc → gabc k (gab k k|a (k|bc |> bc|b)) (k|bc |> bc|c)) -- Coprimality properties coprime-sym : ∀ a b → Coprime a b → Coprime b a coprime-sym a b p = gcd-commute b a ⟨≡⟩ p coprimeByDivide : ∀ a b → (∀ k → k Divides a → k Divides b → k Divides 1) → Coprime a b coprimeByDivide a b g = gcd-unique a b 1 (is-gcd one-divides one-divides g) divide-coprime : ∀ d a b → Coprime a b → d Divides a → d Divides b → d Divides 1 divide-coprime d a b p d|a d|b with gcd a b divide-coprime d a b refl d|a d|b | gcd-res _ (is-gcd _ _ g) = g d d|a d|b mul-coprime-l : ∀ a b c → Coprime a (b * c) → Coprime a b mul-coprime-l a b c a⊥bc = coprimeByDivide a b λ k k|a k|b → divide-coprime k a (b * c) a⊥bc k|a (divides-mul-l c k|b) mul-coprime-r : ∀ a b c → Coprime a (b * c) → Coprime a c mul-coprime-r a b c a⊥bc = mul-coprime-l a c b (transport (Coprime a) auto a⊥bc) is-gcd-factors-coprime : ∀ {a b d} (p : IsGCD d a b) {{_ : NonZero d}} → Coprime (is-gcd-factor₁ p) (is-gcd-factor₂ p) is-gcd-factors-coprime {a} {b} {0} _ {{}} is-gcd-factors-coprime {a} {b} {d@(suc _)} p@(is-gcd (factor qa refl) (factor qb refl) g) with gcd qa qb ... | gcd-res j (is-gcd j|qa j|qb gj) = lem₃ j lem₂ where lem : IsGCD (j * d) a b lem = is-gcd (divides-mul-cong-r d j|qa) (divides-mul-cong-r d j|qb) λ k k|a k|b → divides-mul-r j (g k k|a k|b) lem₂ : d ≡ j * d lem₂ = is-gcd-unique d (j * d) p lem lem₃ : ∀ j → d ≡ j * d → j ≡ 1 lem₃ 0 () lem₃ 1 _ = refl lem₃ (suc (suc n)) eq = refute eq private mul-gcd-distr-l' : ∀ a b c ⦃ a>0 : NonZero a ⦄ ⦃ b>0 : NonZero b ⦄ → gcd! (a * b) (a * c) ≡ a * gcd! b c mul-gcd-distr-l' a b c with gcd b c | gcd (a * b) (a * c) ... | gcd-res d gcd-bc@(is-gcd (factor! b′) (factor! c′) _) | gcd-res δ gcd-abac@(is-gcd (factor u uδ=ab) (factor v vδ=ac) g) = let instance _ = nonzero-is-gcd-l gcd-bc _ : NonZero (d * a) _ = mul-nonzero d a in case g (d * a) (factor b′ auto) (factor c′ auto) of λ where (factor w wda=δ) → let dab′=dauw = d * a * b′ ≡⟨ by uδ=ab ⟩ u * δ ≡⟨ u *_ $≡ wda=δ ⟩ʳ u * (w * (d * a)) ≡⟨ auto ⟩ d * a * (u * w) ∎ dac′=davw = d * a * c′ ≡⟨ by vδ=ac ⟩ v * δ ≡⟨ v *_ $≡ wda=δ ⟩ʳ v * (w * (d * a)) ≡⟨ auto ⟩ d * a * (v * w) ∎ uw=b′ : u * w ≡ b′ uw=b′ = sym (mul-inj₂ (d * a) b′ (u * w) dab′=dauw) vw=c′ : v * w ≡ c′ vw=c′ = sym (mul-inj₂ (d * a) c′ (v * w) dac′=davw) w=1 : w ≡ 1 w=1 = divides-one (divide-coprime w b′ c′ (is-gcd-factors-coprime gcd-bc) (factor u uw=b′) (factor v vw=c′)) in case w=1 of λ where refl → by wda=δ mul-gcd-distr-l : ∀ a b c → gcd! (a * b) (a * c) ≡ a * gcd! b c mul-gcd-distr-l zero b c = refl mul-gcd-distr-l a zero c = (λ z → gcd! z (a * c)) $≡ mul-zero-r a mul-gcd-distr-l a@(suc _) b@(suc _) c = mul-gcd-distr-l' a b c mul-gcd-distr-r : ∀ a b c → gcd! (a * c) (b * c) ≡ gcd! a b * c mul-gcd-distr-r a b c = gcd! (a * c) (b * c) ≡⟨ gcd! $≡ mul-commute a c *≡ mul-commute b c ⟩ gcd! (c * a) (c * b) ≡⟨ mul-gcd-distr-l c a b ⟩ c * gcd! a b ≡⟨ auto ⟩ gcd! a b * c ∎ -- Divide two numbers by their gcd and return the result, the gcd, and some useful properties. -- Continuation-passing for efficiency reasons. gcdReduce' : ∀ {a} {A : Set a} (a b : Nat) ⦃ _ : NonZero b ⦄ → ((a′ b′ d : Nat) → (⦃ _ : NonZero a ⦄ → NonZero a′) → ⦃ nzb : NonZero b′ ⦄ → ⦃ nzd : NonZero d ⦄ → a′ * d ≡ a → b′ * d ≡ b → Coprime a′ b′ → A) → A gcdReduce' a b ret with gcd a b gcdReduce' a b ret | gcd-res d isgcd@(is-gcd d|a@(factor a′ eqa) d|b@(factor b′ eqb) g)= let instance _ = nonzero-is-gcd-r isgcd in ret a′ b′ d (nonzero-factor d|a) ⦃ nonzero-factor d|b ⦄ eqa eqb (is-gcd-factors-coprime isgcd) -- Both arguments are non-zero. gcdReduce : ∀ {a} {A : Set a} (a b : Nat) ⦃ _ : NonZero a ⦄ ⦃ _ : NonZero b ⦄ → ((a′ b′ d : Nat) ⦃ a′>0 : NonZero a′ ⦄ ⦃ b′>0 : NonZero b′ ⦄ ⦃ nzd : NonZero d ⦄ → a′ * d ≡ a → b′ * d ≡ b → Coprime a′ b′ → A) → A gcdReduce a b k = gcdReduce' a b λ a′ b′ d a′>0 eq₁ eq₂ a′⊥b′ → let instance _ = a′>0 in k a′ b′ d eq₁ eq₂ a′⊥b′ -- Only the right argument is guaranteed to be non-zero. gcdReduce-r : ∀ {a} {A : Set a} (a b : Nat) ⦃ _ : NonZero b ⦄ → ((a′ b′ d : Nat) ⦃ nzb : NonZero b′ ⦄ ⦃ nzd : NonZero d ⦄ → a′ * d ≡ a → b′ * d ≡ b → Coprime a′ b′ → A) → A gcdReduce-r a b k = gcdReduce' a b λ a′ b′ d _ eq₁ eq₂ a′⊥b′ → k a′ b′ d eq₁ eq₂ a′⊥b′ --- Properties --- coprime-divide-mul-l : ∀ a b c → Coprime a b → a Divides (b * c) → a Divides c coprime-divide-mul-l a b c p a|bc with extendedGCD a b coprime-divide-mul-l a b c p a|bc | gcd-res d i e with gcd-unique _ _ _ i ʳ⟨≡⟩ p coprime-divide-mul-l a b c p (factor q qa=bc) | gcd-res d i (bézoutL x y ax=1+by) | refl = factor (x * c - y * q) $ (x * c - y * q) * a ≡⟨ auto ⟩ a * x * c - y * (q * a) ≡⟨ by-cong ax=1+by ⟩ suc (b * y) * c - y * (q * a) ≡⟨ by-cong qa=bc ⟩ suc (b * y) * c - y * (b * c) ≡⟨ auto ⟩ c ∎ coprime-divide-mul-l a b c p (factor q qa=bc) | gcd-res d i (bézoutR x y by=1+ax) | refl = factor (y * q - x * c) $ (y * q - x * c) * a ≡⟨ auto ⟩ y * (q * a) - a * x * c ≡⟨ by-cong qa=bc ⟩ y * (b * c) - a * x * c ≡⟨ auto ⟩ (b * y) * c - a * x * c ≡⟨ by-cong by=1+ax ⟩ suc (a * x) * c - a * x * c ≡⟨ auto ⟩ c ∎ coprime-divide-mul-r : ∀ a b c → Coprime a c → a Divides (b * c) → a Divides b coprime-divide-mul-r a b c p a|bc = coprime-divide-mul-l a c b p (transport (a Divides_) auto a|bc) is-gcd-by-coprime-factors : ∀ d a b (d|a : d Divides a) (d|b : d Divides b) ⦃ nzd : NonZero d ⦄ → Coprime (get-factor d|a) (get-factor d|b) → IsGCD d a b is-gcd-by-coprime-factors d a b d|a@(factor! q) d|b@(factor! r) q⊥r = is-gcd d|a d|b λ k k|a k|b → let lem : ∀ j → j Divides q → j Divides r → j ≡ 1 lem j j|q j|r = divides-one (divide-coprime j q r q⊥r j|q j|r) in case gcd k d of λ where (gcd-res g isgcd@(is-gcd (factor k′ k′g=k@refl) (factor d′ d′g=d@refl) sup)) → let instance g>0 = nonzero-is-gcd-r isgcd k′⊥d′ : Coprime k′ d′ k′⊥d′ = is-gcd-factors-coprime isgcd k′|qd′ : k′ Divides (q * d′) k′|qd′ = cancel-mul-divides-r k′ (q * d′) g (transport ((k′ * g) Divides_) {x = q * (d′ * g)} {q * d′ * g} auto k|a) k′|rd′ : k′ Divides (r * d′) k′|rd′ = cancel-mul-divides-r k′ (r * d′) g (transport ((k′ * g) Divides_) {x = r * (d′ * g)} {r * d′ * g} auto k|b) k′|q : k′ Divides q k′|q = coprime-divide-mul-r k′ q d′ k′⊥d′ k′|qd′ k′|r : k′ Divides r k′|r = coprime-divide-mul-r k′ r d′ k′⊥d′ k′|rd′ k′=1 = lem k′ k′|q k′|r k=g : k ≡ g k=g = case k′=1 of λ where refl → auto in factor d′ (d′ *_ $≡ k=g ⟨≡⟩ d′g=d)
algebraic-stack_agda0000_doc_3704
{-# OPTIONS --safe #-} module Cubical.Algebra.CommAlgebra.QuotientAlgebra where open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Powerset using (_∈_) open import Cubical.HITs.SetQuotients hiding (_/_) open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommRing.QuotientRing renaming (_/_ to _/Ring_) hiding ([_]/) open import Cubical.Algebra.CommRing.Ideal hiding (IdealsIn) open import Cubical.Algebra.CommAlgebra open import Cubical.Algebra.CommAlgebra.Ideal open import Cubical.Algebra.Ring open import Cubical.Algebra.Ring.Ideal using (isIdeal) private variable ℓ : Level module _ {R : CommRing ℓ} (A : CommAlgebra R ℓ) where open CommRingStr {{...}} hiding (_-_; -_; dist; ·Lid; ·Rdist+) renaming (_·_ to _·R_; _+_ to _+R_) open CommAlgebraStr {{...}} open RingTheory (CommRing→Ring (CommAlgebra→CommRing A)) using (-DistR·) instance _ : CommRingStr _ _ = snd R _ : CommAlgebraStr _ _ _ = snd A _/_ : (I : IdealsIn A) → CommAlgebra R ℓ _/_ I = commAlgebraFromCommRing ((CommAlgebra→CommRing A) /Ring I) (λ r → elim (λ _ → squash/) (λ x → [ r ⋆ x ]) (eq r)) (λ r s → elimProp (λ _ → squash/ _ _) λ x i → [ ((r ·R s) ⋆ x ≡⟨ ⋆-assoc r s x ⟩ r ⋆ (s ⋆ x) ∎) i ]) (λ r s → elimProp (λ _ → squash/ _ _) λ x i → [ ((r +R s) ⋆ x ≡⟨ ⋆-ldist r s x ⟩ r ⋆ x + s ⋆ x ∎) i ]) (λ r → elimProp2 (λ _ _ → squash/ _ _) λ x y i → [ (r ⋆ (x + y) ≡⟨ ⋆-rdist r x y ⟩ r ⋆ x + r ⋆ y ∎) i ]) (elimProp (λ _ → squash/ _ _) (λ x i → [ (1r ⋆ x ≡⟨ ⋆-lid x ⟩ x ∎) i ])) λ r → elimProp2 (λ _ _ → squash/ _ _) λ x y i → [ ((r ⋆ x) · y ≡⟨ ⋆-lassoc r x y ⟩ r ⋆ (x · y) ∎) i ] where open CommIdeal using (isCommIdeal) eq : (r : fst R) (x y : fst A) → x - y ∈ (fst I) → [ r ⋆ x ] ≡ [ r ⋆ y ] eq r x y x-y∈I = eq/ _ _ (subst (λ u → u ∈ fst I) ((r ⋆ 1a) · (x - y) ≡⟨ ·Rdist+ (r ⋆ 1a) x (- y) ⟩ (r ⋆ 1a) · x + (r ⋆ 1a) · (- y) ≡[ i ]⟨ (r ⋆ 1a) · x + -DistR· (r ⋆ 1a) y i ⟩ (r ⋆ 1a) · x - (r ⋆ 1a) · y ≡[ i ]⟨ ⋆-lassoc r 1a x i - ⋆-lassoc r 1a y i ⟩ r ⋆ (1a · x) - r ⋆ (1a · y) ≡[ i ]⟨ r ⋆ (·Lid x i) - r ⋆ (·Lid y i) ⟩ r ⋆ x - r ⋆ y ∎ ) (isCommIdeal.·Closed (snd I) _ x-y∈I)) [_]/ : {R : CommRing ℓ} {A : CommAlgebra R ℓ} {I : IdealsIn A} → (a : fst A) → fst (A / I) [ a ]/ = [ a ]
algebraic-stack_agda0000_doc_3705
-- Example by Ian Orton {-# OPTIONS --rewriting #-} open import Agda.Builtin.Bool open import Agda.Builtin.Equality _∧_ : Bool → Bool → Bool true ∧ y = y false ∧ y = false data ⊥ : Set where ⊥-elim : ∀ {a} {A : Set a} → ⊥ → A ⊥-elim () ¬_ : ∀ {a} → Set a → Set a ¬ A = A → ⊥ contradiction : ∀ {a b} {A : Set a} {B : Set b} → A → ¬ A → B contradiction a f = ⊥-elim (f a) _≢_ : ∀ {a} {A : Set a} (x y : A) → Set a x ≢ y = ¬ (x ≡ y) postulate obvious : (b b' : Bool) (p : b ≢ b') → (b ∧ b') ≡ false {-# BUILTIN REWRITE _≡_ #-} {-# REWRITE obvious #-} oops : (b : Bool) → b ∧ b ≡ false oops b = refl true≢false : true ≡ false → ⊥ true≢false () bot : ⊥ bot = true≢false (oops true)
algebraic-stack_agda0000_doc_3706
{-# OPTIONS --without-K #-} open import Base open import Homotopy.Pushout open import Homotopy.VanKampen.Guide {- This module provides the function code⇒path for the homotopy equivalence for van Kampen theorem. -} module Homotopy.VanKampen.CodeToPath {i} (d : pushout-diag i) (l : legend i (pushout-diag.C d)) where open pushout-diag d open legend l open import Homotopy.Truncation open import Homotopy.PathTruncation open import Homotopy.VanKampen.Code d l private pgl : ∀ n → _≡₀_ {A = P} (left (f $ loc n)) (right (g $ loc n)) pgl n = proj (glue $ loc n) p!gl : ∀ n → _≡₀_ {A = P} (right (g $ loc n)) (left (f $ loc n)) p!gl n = proj (! (glue $ loc n)) ap₀l : ∀ {a₁ a₂} → a₁ ≡₀ a₂ → _≡₀_ {A = P} (left a₁) (left a₂) ap₀l p = ap₀ left p ap₀r : ∀ {b₁ b₂} → b₁ ≡₀ b₂ → _≡₀_ {A = P} (right b₁) (right b₂) ap₀r p = ap₀ right p module _ {a₁ : A} where private ap⇒path-split : (∀ {a₂} → a-code-a a₁ a₂ → _≡₀_ {A = P} (left a₁) (left a₂)) × (∀ {b₂} → a-code-b a₁ b₂ → _≡₀_ {A = P} (left a₁) (right b₂)) ap⇒path-split = a-code-rec-nondep a₁ (λ a₂ → left a₁ ≡₀ left a₂) ⦃ λ a₂ → π₀-is-set _ ⦄ (λ b₂ → left a₁ ≡₀ right b₂) ⦃ λ b₂ → π₀-is-set _ ⦄ (λ p → ap₀l p) (λ n pco p → (pco ∘₀ p!gl n) ∘₀ ap₀l p) (λ n pco p → (pco ∘₀ pgl n) ∘₀ ap₀r p) (λ n {co} pco → (((pco ∘₀ pgl n) ∘₀ refl₀) ∘₀ p!gl n) ∘₀ refl₀ ≡⟨ refl₀-right-unit _ ⟩ ((pco ∘₀ pgl n) ∘₀ refl₀) ∘₀ p!gl n ≡⟨ ap (λ x → x ∘₀ p!gl n) $ refl₀-right-unit $ pco ∘₀ pgl n ⟩ (pco ∘₀ pgl n) ∘₀ p!gl n ≡⟨ concat₀-assoc pco (pgl n) (p!gl n) ⟩ pco ∘₀ (pgl n ∘₀ p!gl n) ≡⟨ ap (λ x → pco ∘₀ proj x) $ opposite-right-inverse $ glue $ loc n ⟩ pco ∘₀ refl₀ ≡⟨ refl₀-right-unit pco ⟩∎ pco ∎) (λ n {co} pco → (((pco ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n) ∘₀ refl₀ ≡⟨ refl₀-right-unit _ ⟩ ((pco ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n ≡⟨ ap (λ x → x ∘₀ pgl n) $ refl₀-right-unit $ pco ∘₀ p!gl n ⟩ (pco ∘₀ p!gl n) ∘₀ pgl n ≡⟨ concat₀-assoc pco (p!gl n) (pgl n) ⟩ pco ∘₀ (p!gl n ∘₀ pgl n) ≡⟨ ap (λ x → pco ∘₀ proj x) $ opposite-left-inverse $ glue $ loc n ⟩ pco ∘₀ refl₀ ≡⟨ refl₀-right-unit pco ⟩∎ pco ∎) (λ n₁ {co} pco n₂ r → (((pco ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r)) ∘₀ p!gl n₂) ∘₀ refl₀ ≡⟨ refl₀-right-unit _ ⟩ ((pco ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r)) ∘₀ p!gl n₂ ≡⟨ concat₀-assoc (pco ∘₀ pgl n₁) (ap₀r (ap₀ g r)) (p!gl n₂) ⟩ (pco ∘₀ pgl n₁) ∘₀ (ap₀r (ap₀ g r) ∘₀ p!gl n₂) ≡⟨ ap (λ x → (pco ∘₀ pgl n₁) ∘₀ (x ∘₀ p!gl n₂)) $ ! $ ap₀-compose right g r ⟩ (pco ∘₀ pgl n₁) ∘₀ (ap₀ (right ◯ g) r ∘₀ p!gl n₂) ≡⟨ ap (λ x → (pco ∘₀ pgl n₁) ∘₀ x) $ homotopy₀-naturality (right ◯ g) (left ◯ f) (proj ◯ (! ◯ glue)) r ⟩ (pco ∘₀ pgl n₁) ∘₀ (p!gl n₁ ∘₀ ap₀ (left ◯ f) r) ≡⟨ ! $ concat₀-assoc (pco ∘₀ pgl n₁) (p!gl n₁) (ap₀ (left ◯ f) r) ⟩ ((pco ∘₀ pgl n₁) ∘₀ p!gl n₁) ∘₀ ap₀ (left ◯ f) r ≡⟨ ap (λ x → ((pco ∘₀ pgl n₁) ∘₀ p!gl n₁) ∘₀ x) $ ap₀-compose left f r ⟩ ((pco ∘₀ pgl n₁) ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r) ≡⟨ ap (λ x → (x ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r)) $ ! $ refl₀-right-unit $ pco ∘₀ pgl n₁ ⟩∎ (((pco ∘₀ pgl n₁) ∘₀ refl₀) ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r) ∎) aa⇒path : ∀ {a₂} → a-code-a a₁ a₂ → _≡₀_ {A = P} (left a₁) (left a₂) aa⇒path = π₁ ap⇒path-split ab⇒path : ∀ {b₂} → a-code-b a₁ b₂ → _≡₀_ {A = P} (left a₁) (right b₂) ab⇒path = π₂ ap⇒path-split ap⇒path : ∀ {p₂ : P} → a-code a₁ p₂ → left a₁ ≡₀ p₂ ap⇒path {p₂} = pushout-rec (λ p → a-code a₁ p → left a₁ ≡₀ p) (λ a → aa⇒path {a}) (λ b → ab⇒path {b}) (loc-fiber-rec l (λ c → transport (λ p → a-code a₁ p → left a₁ ≡₀ p) (glue c) aa⇒path ≡ ab⇒path) ⦃ λ c → →-is-set (π₀-is-set (left a₁ ≡ right (g c))) _ _ ⦄ (λ n → funext λ co → transport (λ p → a-code a₁ p → left a₁ ≡₀ p) (glue $ loc n) aa⇒path co ≡⟨ trans-→ (a-code a₁) (λ x → left a₁ ≡₀ x) (glue $ loc n) aa⇒path co ⟩ transport (λ p → left a₁ ≡₀ p) (glue $ loc n) (aa⇒path $ transport (a-code a₁) (! (glue $ loc n)) co) ≡⟨ ap (transport (λ p → left a₁ ≡₀ p) (glue $ loc n) ◯ aa⇒path) $ trans-a-code-!glue-loc n co ⟩ transport (λ p → left a₁ ≡₀ p) (glue $ loc n) (aa⇒path $ ab⇒aa n co) ≡⟨ trans-cst≡₀id (glue $ loc n) (aa⇒path $ ab⇒aa n co) ⟩ (aa⇒path $ ab⇒aa n co) ∘₀ pgl n ≡⟨ refl ⟩ ((ab⇒path co ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n ≡⟨ ap (λ x → x ∘₀ pgl n) $ refl₀-right-unit $ ab⇒path co ∘₀ p!gl n ⟩ (ab⇒path co ∘₀ p!gl n) ∘₀ pgl n ≡⟨ concat₀-assoc (ab⇒path co) (p!gl n) (pgl n) ⟩ ab⇒path co ∘₀ (p!gl n ∘₀ pgl n) ≡⟨ ap (λ x → ab⇒path co ∘₀ proj x) $ opposite-left-inverse $ glue $ loc n ⟩ ab⇒path co ∘₀ refl₀ ≡⟨ refl₀-right-unit $ ab⇒path co ⟩∎ ab⇒path co ∎)) p₂ -- FIXME -- There is tension between reducing duplicate code and -- maintaining definitional equality. I could not make -- the neccessary type conversion definitional, so -- I just copied and pasted the previous module. module _ {b₁ : B} where private bp⇒path-split : (∀ {b₂} → b-code-b b₁ b₂ → _≡₀_ {A = P} (right b₁) (right b₂)) × (∀ {a₂} → b-code-a b₁ a₂ → _≡₀_ {A = P} (right b₁) (left a₂)) bp⇒path-split = b-code-rec-nondep b₁ (λ b₂ → right b₁ ≡₀ right b₂) ⦃ λ b₂ → π₀-is-set _ ⦄ (λ a₂ → right b₁ ≡₀ left a₂) ⦃ λ a₂ → π₀-is-set _ ⦄ (λ p → ap₀r p) (λ n pco p → (pco ∘₀ pgl n) ∘₀ ap₀r p) (λ n pco p → (pco ∘₀ p!gl n) ∘₀ ap₀l p) (λ n {co} pco → (((pco ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n) ∘₀ refl₀ ≡⟨ refl₀-right-unit _ ⟩ ((pco ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n ≡⟨ ap (λ x → x ∘₀ pgl n) $ refl₀-right-unit $ pco ∘₀ p!gl n ⟩ (pco ∘₀ p!gl n) ∘₀ pgl n ≡⟨ concat₀-assoc pco (p!gl n) (pgl n) ⟩ pco ∘₀ (p!gl n ∘₀ pgl n) ≡⟨ ap (λ x → pco ∘₀ proj x) $ opposite-left-inverse $ glue $ loc n ⟩ pco ∘₀ refl₀ ≡⟨ refl₀-right-unit pco ⟩∎ pco ∎) (λ n {co} pco → (((pco ∘₀ pgl n) ∘₀ refl₀) ∘₀ p!gl n) ∘₀ refl₀ ≡⟨ refl₀-right-unit _ ⟩ ((pco ∘₀ pgl n) ∘₀ refl₀) ∘₀ p!gl n ≡⟨ ap (λ x → x ∘₀ p!gl n) $ refl₀-right-unit $ pco ∘₀ pgl n ⟩ (pco ∘₀ pgl n) ∘₀ p!gl n ≡⟨ concat₀-assoc pco (pgl n) (p!gl n) ⟩ pco ∘₀ (pgl n ∘₀ p!gl n) ≡⟨ ap (λ x → pco ∘₀ proj x) $ opposite-right-inverse $ glue $ loc n ⟩ pco ∘₀ refl₀ ≡⟨ refl₀-right-unit pco ⟩∎ pco ∎) (λ n₁ {co} pco n₂ r → (((pco ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r)) ∘₀ pgl n₂) ∘₀ refl₀ ≡⟨ refl₀-right-unit _ ⟩ ((pco ∘₀ p!gl n₁) ∘₀ ap₀l (ap₀ f r)) ∘₀ pgl n₂ ≡⟨ concat₀-assoc (pco ∘₀ p!gl n₁) (ap₀l (ap₀ f r)) (pgl n₂) ⟩ (pco ∘₀ p!gl n₁) ∘₀ (ap₀l (ap₀ f r) ∘₀ pgl n₂) ≡⟨ ap (λ x → (pco ∘₀ p!gl n₁) ∘₀ (x ∘₀ pgl n₂)) $ ! $ ap₀-compose left f r ⟩ (pco ∘₀ p!gl n₁) ∘₀ (ap₀ (left ◯ f) r ∘₀ pgl n₂) ≡⟨ ap (λ x → (pco ∘₀ p!gl n₁) ∘₀ x) $ homotopy₀-naturality (left ◯ f) (right ◯ g) (proj ◯ glue) r ⟩ (pco ∘₀ p!gl n₁) ∘₀ (pgl n₁ ∘₀ ap₀ (right ◯ g) r) ≡⟨ ! $ concat₀-assoc (pco ∘₀ p!gl n₁) (pgl n₁) (ap₀ (right ◯ g) r) ⟩ ((pco ∘₀ p!gl n₁) ∘₀ pgl n₁) ∘₀ ap₀ (right ◯ g) r ≡⟨ ap (λ x → ((pco ∘₀ p!gl n₁) ∘₀ pgl n₁) ∘₀ x) $ ap₀-compose right g r ⟩ ((pco ∘₀ p!gl n₁) ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r) ≡⟨ ap (λ x → (x ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r)) $ ! $ refl₀-right-unit $ pco ∘₀ p!gl n₁ ⟩∎ (((pco ∘₀ p!gl n₁) ∘₀ refl₀) ∘₀ pgl n₁) ∘₀ ap₀r (ap₀ g r) ∎) bb⇒path : ∀ {b₂} → b-code-b b₁ b₂ → _≡₀_ {A = P} (right b₁) (right b₂) bb⇒path = π₁ bp⇒path-split ba⇒path : ∀ {a₂} → b-code-a b₁ a₂ → _≡₀_ {A = P} (right b₁) (left a₂) ba⇒path = π₂ bp⇒path-split bp⇒path : ∀ {p₂ : P} → b-code b₁ p₂ → right b₁ ≡₀ p₂ bp⇒path {p₂} = pushout-rec (λ p → b-code b₁ p → right b₁ ≡₀ p) (λ a → ba⇒path {a}) (λ b → bb⇒path {b}) (λ c → loc-fiber-rec l (λ c → transport (λ p → b-code b₁ p → right b₁ ≡₀ p) (glue c) ba⇒path ≡ bb⇒path) ⦃ λ c → →-is-set (π₀-is-set (right b₁ ≡ right (g c))) _ _ ⦄ (λ n → funext λ co → transport (λ p → b-code b₁ p → right b₁ ≡₀ p) (glue $ loc n) ba⇒path co ≡⟨ trans-→ (b-code b₁) (λ x → right b₁ ≡₀ x) (glue $ loc n) ba⇒path co ⟩ transport (λ p → right b₁ ≡₀ p) (glue $ loc n) (ba⇒path $ transport (b-code b₁) (! (glue $ loc n)) co) ≡⟨ ap (transport (λ p → right b₁ ≡₀ p) (glue $ loc n) ◯ ba⇒path) $ trans-b-code-!glue-loc n co ⟩ transport (λ p → right b₁ ≡₀ p) (glue $ loc n) (ba⇒path $ bb⇒ba n co) ≡⟨ trans-cst≡₀id (glue $ loc n) (ba⇒path $ bb⇒ba n co) ⟩ (ba⇒path $ bb⇒ba n co) ∘₀ pgl n ≡⟨ refl ⟩ ((bb⇒path co ∘₀ p!gl n) ∘₀ refl₀) ∘₀ pgl n ≡⟨ ap (λ x → x ∘₀ pgl n) $ refl₀-right-unit $ bb⇒path co ∘₀ p!gl n ⟩ (bb⇒path co ∘₀ p!gl n) ∘₀ pgl n ≡⟨ concat₀-assoc (bb⇒path co) (p!gl n) (pgl n) ⟩ bb⇒path co ∘₀ (p!gl n ∘₀ pgl n) ≡⟨ ap (λ x → bb⇒path co ∘₀ proj x) $ opposite-left-inverse $ glue $ loc n ⟩ bb⇒path co ∘₀ refl₀ ≡⟨ refl₀-right-unit $ bb⇒path co ⟩∎ bb⇒path co ∎) c) p₂ module _ where private Lbaaa : ∀ n {a₂} → b-code-a (g $ loc n) a₂ → Set i Lbaaa n co = aa⇒path {f $ loc n} (ba⇒aa n co) ≡ pgl n ∘₀ ba⇒path co Lbbab : ∀ n {b₂} → b-code-b (g $ loc n) b₂ → Set i Lbbab n co = ab⇒path {f $ loc n} (bb⇒ab n co) ≡ pgl n ∘₀ bb⇒path co private bp⇒ap⇒path-split : ∀ n → (∀ {a₂} co → Lbbab n {a₂} co) × (∀ {b₂} co → Lbaaa n {b₂} co) abstract bp⇒ap⇒path-split n = b-code-rec (g $ loc n) (λ co → ab⇒path {f $ loc n} (bb⇒ab n co) ≡ pgl n ∘₀ bb⇒path co) ⦃ λ _ → ≡-is-set $ π₀-is-set _ ⦄ (λ co → aa⇒path {f $ loc n} (ba⇒aa n co) ≡ pgl n ∘₀ ba⇒path co) ⦃ λ _ → ≡-is-set $ π₀-is-set _ ⦄ (λ p → ab⇒path (bb⇒ab n (⟧b p)) ≡⟨ refl ⟩ (refl₀ ∘₀ pgl n) ∘₀ ap₀r p ≡⟨ ap (λ x → x ∘₀ ap₀r p) $ refl₀-left-unit $ pgl n ⟩ pgl n ∘₀ ap₀r p ≡⟨ refl ⟩∎ pgl n ∘₀ bb⇒path (⟧b p) ∎) (λ n₁ {co} eq p₁ → (aa⇒path (ba⇒aa n co) ∘₀ pgl n₁) ∘₀ ap₀r p₁ ≡⟨ ap (λ x → (x ∘₀ pgl n₁) ∘₀ ap₀r p₁) eq ⟩ ((pgl n ∘₀ ba⇒path co) ∘₀ pgl n₁) ∘₀ ap₀r p₁ ≡⟨ ap (λ x → x ∘₀ ap₀r p₁) $ concat₀-assoc (pgl n) (ba⇒path co) (pgl n₁) ⟩ (pgl n ∘₀ (ba⇒path co ∘₀ pgl n₁)) ∘₀ ap₀r p₁ ≡⟨ concat₀-assoc (pgl n) (ba⇒path co ∘₀ pgl n₁) (ap₀r p₁) ⟩∎ pgl n ∘₀ ((ba⇒path co ∘₀ pgl n₁) ∘₀ ap₀r p₁) ∎) (λ n₁ {co} eq p₁ → (ab⇒path (bb⇒ab n co) ∘₀ p!gl n₁) ∘₀ ap₀l p₁ ≡⟨ ap (λ x → (x ∘₀ p!gl n₁) ∘₀ ap₀l p₁) eq ⟩ ((pgl n ∘₀ bb⇒path co) ∘₀ p!gl n₁) ∘₀ ap₀l p₁ ≡⟨ ap (λ x → x ∘₀ ap₀l p₁) $ concat₀-assoc (pgl n) (bb⇒path co) (p!gl n₁) ⟩ (pgl n ∘₀ (bb⇒path co ∘₀ p!gl n₁)) ∘₀ ap₀l p₁ ≡⟨ concat₀-assoc (pgl n) (bb⇒path co ∘₀ p!gl n₁) (ap₀l p₁) ⟩∎ pgl n ∘₀ ((bb⇒path co ∘₀ p!gl n₁) ∘₀ ap₀l p₁) ∎) (λ _ co → prop-has-all-paths (π₀-is-set _ _ _) _ co) (λ _ co → prop-has-all-paths (π₀-is-set _ _ _) _ co) (λ _ _ _ _ → prop-has-all-paths (π₀-is-set _ _ _) _ _) ba⇒aa⇒path : ∀ n {a₂} co → Lbaaa n {a₂} co ba⇒aa⇒path n = π₂ $ bp⇒ap⇒path-split n bb⇒ab⇒path : ∀ n {b₂} co → Lbbab n {b₂} co bb⇒ab⇒path n = π₁ $ bp⇒ap⇒path-split n private bp⇒ap⇒path : ∀ n {p₂} (co : b-code (g $ loc n) p₂) → ap⇒path {f $ loc n} {p₂} (bp⇒ap n {p₂} co) ≡ pgl n ∘₀ bp⇒path {g $ loc n} {p₂} co abstract bp⇒ap⇒path n {p₂} = pushout-rec (λ x → ∀ (co : b-code (g $ loc n) x) → ap⇒path {f $ loc n} {x} (bp⇒ap n {x} co) ≡ pgl n ∘₀ bp⇒path {g $ loc n} {x} co) (λ a₂ → ba⇒aa⇒path n {a₂}) (λ b₂ → bb⇒ab⇒path n {b₂}) (λ _ → funext λ _ → prop-has-all-paths (π₀-is-set _ _ _) _ _) p₂ code⇒path : ∀ {p₁ p₂} → code p₁ p₂ → p₁ ≡₀ p₂ code⇒path {p₁} {p₂} = pushout-rec (λ p₁ → code p₁ p₂ → p₁ ≡₀ p₂) (λ a → ap⇒path {a} {p₂}) (λ b → bp⇒path {b} {p₂}) (loc-fiber-rec l (λ c → transport (λ x → code x p₂ → x ≡₀ p₂) (glue c) (ap⇒path {f c} {p₂}) ≡ bp⇒path {g c} {p₂}) ⦃ λ c → →-is-set (π₀-is-set (right (g c) ≡ p₂)) _ _ ⦄ (λ n → funext λ (co : code (right $ g $ loc n) p₂) → transport (λ x → code x p₂ → x ≡₀ p₂) (glue $ loc n) (ap⇒path {f $ loc n} {p₂}) co ≡⟨ trans-→ (λ x → code x p₂) (λ x → x ≡₀ p₂) (glue $ loc n) (ap⇒path {f $ loc n} {p₂}) co ⟩ transport (λ x → x ≡₀ p₂) (glue $ loc n) (ap⇒path {f $ loc n} {p₂} $ transport (λ x → code x p₂) (! (glue $ loc n)) co) ≡⟨ ap (transport (λ x → x ≡₀ p₂) (glue $ loc n) ◯ ap⇒path {f $ loc n} {p₂}) $ trans-!glue-code-loc n {p₂} co ⟩ transport (λ x → x ≡₀ p₂) (glue $ loc n) (ap⇒path {f $ loc n} {p₂} $ bp⇒ap n {p₂} co) ≡⟨ ap (transport (λ x → x ≡₀ p₂) (glue $ loc n)) $ bp⇒ap⇒path n {p₂} co ⟩ transport (λ x → x ≡₀ p₂) (glue $ loc n) (pgl n ∘₀ bp⇒path {g $ loc n} {p₂} co) ≡⟨ trans-id≡₀cst (glue $ loc n) (pgl n ∘₀ bp⇒path {g $ loc n} {p₂} co) ⟩ p!gl n ∘₀ (pgl n ∘₀ bp⇒path {g $ loc n} {p₂} co) ≡⟨ ! $ concat₀-assoc (p!gl n) (pgl n) (bp⇒path {g $ loc n} {p₂} co) ⟩ (p!gl n ∘₀ pgl n) ∘₀ bp⇒path {g $ loc n} {p₂} co ≡⟨ ap (λ x → proj x ∘₀ bp⇒path {g $ loc n} {p₂} co) $ opposite-left-inverse (glue $ loc n) ⟩ refl₀ ∘₀ bp⇒path {g $ loc n} {p₂} co ≡⟨ refl₀-left-unit (bp⇒path {g $ loc n} {p₂} co) ⟩∎ bp⇒path {g $ loc n} {p₂} co ∎)) p₁
algebraic-stack_agda0000_doc_3707
module Example.Test where open import Data.Maybe using (Is-just) open import Prelude.Init open import Prelude.DecEq open import Prelude.Decidable _ : (¬ ¬ ((true , true) ≡ (true , true))) × (8 ≡ 18 ∸ 10) _ = auto
algebraic-stack_agda0000_doc_3708
-- Export only the experiments that are expected to compile (without -- any holes) {-# OPTIONS --cubical --no-import-sorts #-} module Cubical.Experiments.Everything where open import Cubical.Experiments.Brunerie public open import Cubical.Experiments.EscardoSIP public open import Cubical.Experiments.Generic public open import Cubical.Experiments.NatMinusTwo open import Cubical.Experiments.Problem open import Cubical.Experiments.FunExtFromUA public open import Cubical.Experiments.HoTT-UF open import Cubical.Experiments.Rng
algebraic-stack_agda0000_doc_3709
module Web.URI.Port where open import Web.URI.Port.Primitive public using ( Port? ; :80 ; ε )
algebraic-stack_agda0000_doc_3710
{-# OPTIONS --experimental-irrelevance #-} -- {-# OPTIONS -v tc:10 #-} module ExplicitLambdaExperimentalIrrelevance where postulate A : Set T : ..(x : A) -> Set -- shape irrelevant type test : .(a : A) -> T a -> Set test a = λ (x : T a) -> A -- this should type check and not complain about irrelevance of a module M .(a : A) where -- should also work with module parameter test1 : T a -> Set test1 = λ (x : T a) -> A
algebraic-stack_agda0000_doc_3711
module Numeral.Integer where open import Data.Tuple open import Logic import Lvl open import Numeral.Natural open import Numeral.Natural.Oper open import Relator.Equals open import Type open import Type.Quotient -- Equivalence relation of difference equality. -- Essentially (if one would already work in the integers): -- (a₁ , a₂) diff-≡_ (b₁ , b₂) -- ⇔ a₁ + b₂ ≡ a₂ + b₁ -- ⇔ a₁ − a₂ ≡ b₁ − b₂ _diff-≡_ : (ℕ ⨯ ℕ) → (ℕ ⨯ ℕ) → Stmt{Lvl.𝟎} (a₁ , a₂) diff-≡ (b₁ , b₂) = (a₁ + b₂ ≡ a₂ + b₁) ℤ : Type{Lvl.𝟎} ℤ = (ℕ ⨯ ℕ) / (_diff-≡_)
algebraic-stack_agda0000_doc_12480
------------------------------------------------------------------------ -- A definitional interpreter ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} module Lambda.Delay-monad.Interpreter where open import Equality.Propositional open import Prelude open import Prelude.Size open import Maybe equality-with-J open import Monad equality-with-J open import Vec.Function equality-with-J open import Delay-monad open import Delay-monad.Bisimilarity open import Delay-monad.Monad open import Lambda.Syntax hiding ([_]) open Closure Tm ------------------------------------------------------------------------ -- An interpreter monad -- The interpreter monad. M : ∀ {ℓ} → Size → Type ℓ → Type ℓ M i = MaybeT (λ A → Delay A i) -- A variant of the interpreter monad. M′ : ∀ {ℓ} → Size → Type ℓ → Type ℓ M′ i = MaybeT (λ A → Delay′ A i) -- A lifted variant of later. laterM : ∀ {i a} {A : Type a} → M′ i A → M i A run (laterM x) = later (run x) -- A lifted variant of weak bisimilarity. infix 4 _≈M_ _≈M_ : ∀ {a} {A : Type a} → M ∞ A → M ∞ A → Type a x ≈M y = run x ≈ run y ------------------------------------------------------------------------ -- The interpreter infix 10 _∙_ mutual ⟦_⟧ : ∀ {i n} → Tm n → Env n → M i Value ⟦ con i ⟧ ρ = return (con i) ⟦ var x ⟧ ρ = return (ρ x) ⟦ ƛ t ⟧ ρ = return (ƛ t ρ) ⟦ t₁ · t₂ ⟧ ρ = ⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦ t₂ ⟧ ρ >>= λ v₂ → v₁ ∙ v₂ _∙_ : ∀ {i} → Value → Value → M i Value con i ∙ v₂ = fail ƛ t₁ ρ ∙ v₂ = laterM (⟦ t₁ ⟧′ (cons v₂ ρ)) ⟦_⟧′ : ∀ {i n} → Tm n → Env n → M′ i Value force (run (⟦ t ⟧′ ρ)) = run (⟦ t ⟧ ρ) ------------------------------------------------------------------------ -- An example -- The semantics of Ω is the non-terminating computation never. Ω-loops : ∀ {i} → [ i ] run (⟦ Ω ⟧ nil) ∼ never Ω-loops = later λ { .force → Ω-loops }
algebraic-stack_agda0000_doc_12481
{- This file contains: Properties of FreeGroupoid: - Induction principle for the FreeGroupoid on hProps - ∥freeGroupoid∥₂ is a Group - FreeGroup A ≡ ∥ FreeGroupoid A ∥₂ -} {-# OPTIONS --safe #-} module Cubical.HITs.FreeGroupoid.Properties where open import Cubical.HITs.FreeGroupoid.Base open import Cubical.HITs.FreeGroup renaming (elimProp to freeGroupElimProp) open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.BiInvertible open import Cubical.Foundations.Univalence using (ua) open import Cubical.HITs.SetTruncation renaming (rec to recTrunc) open import Cubical.Algebra.Group open import Cubical.Algebra.Group.Morphisms open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Algebra.Monoid.Base open import Cubical.Algebra.Semigroup.Base private variable ℓ ℓ' : Level A : Type ℓ -- The induction principle for the FreeGroupoid for hProps elimProp : ∀ {B : FreeGroupoid A → Type ℓ'} → ((x : FreeGroupoid A) → isProp (B x)) → ((a : A) → B (η a)) → ((g1 g2 : FreeGroupoid A) → B g1 → B g2 → B (g1 · g2)) → (B ε) → ((g : FreeGroupoid A) → B g → B (inv g)) → (x : FreeGroupoid A) → B x elimProp {B = B} Bprop η-ind ·-ind ε-ind inv-ind = induction where induction : ∀ g → B g induction (η a) = η-ind a induction (g1 · g2) = ·-ind g1 g2 (induction g1) (induction g2) induction ε = ε-ind induction (inv g) = inv-ind g (induction g) induction (assoc g1 g2 g3 i) = path i where p1 : B g1 p1 = induction g1 p2 : B g2 p2 = induction g2 p3 : B g3 p3 = induction g3 path : PathP (λ i → B (assoc g1 g2 g3 i)) (·-ind g1 (g2 · g3) p1 (·-ind g2 g3 p2 p3)) (·-ind (g1 · g2) g3 (·-ind g1 g2 p1 p2) p3) path = isProp→PathP (λ i → Bprop (assoc g1 g2 g3 i)) (·-ind g1 (g2 · g3) p1 (·-ind g2 g3 p2 p3)) (·-ind (g1 · g2) g3 (·-ind g1 g2 p1 p2) p3) induction (idr g i) = path i where p : B g p = induction g pε : B ε pε = induction ε path : PathP (λ i → B (idr g i)) p (·-ind g ε p pε) path = isProp→PathP (λ i → Bprop (idr g i)) p (·-ind g ε p pε) induction (idl g i) = path i where p : B g p = induction g pε : B ε pε = induction ε path : PathP (λ i → B (idl g i)) p (·-ind ε g pε p) path = isProp→PathP (λ i → Bprop (idl g i)) p (·-ind ε g pε p) induction (invr g i) = path i where p : B g p = induction g pinv : B (inv g) pinv = inv-ind g p pε : B ε pε = induction ε path : PathP (λ i → B (invr g i)) (·-ind g (inv g) p pinv) pε path = isProp→PathP (λ i → Bprop (invr g i)) (·-ind g (inv g) p pinv) pε induction (invl g i) = path i where p : B g p = induction g pinv : B (inv g) pinv = inv-ind g p pε : B ε pε = induction ε path : PathP (λ i → B (invl g i)) (·-ind (inv g) g pinv p) pε path = isProp→PathP (λ i → Bprop (invl g i)) (·-ind (inv g) g pinv p) pε -- The truncation of the FreeGroupoid is a group and is equal to FreeGroup ∥freeGroupoid∥₂IsSet : isSet ∥ FreeGroupoid A ∥₂ ∥freeGroupoid∥₂IsSet = squash₂ _∣·∣₂_ : ∥ FreeGroupoid A ∥₂ → ∥ FreeGroupoid A ∥₂ → ∥ FreeGroupoid A ∥₂ _∣·∣₂_ = rec2 ∥freeGroupoid∥₂IsSet (λ g1 g2 → ∣ g1 · g2 ∣₂) ∥freeGroupoid∥₂IsSemiGroup : ∀ {ℓ}{A : Type ℓ} → IsSemigroup _∣·∣₂_ ∥freeGroupoid∥₂IsSemiGroup {A = A} = issemigroup ∥freeGroupoid∥₂IsSet |assoc∣₂ where inuctionBase : ∀ g1 g2 g3 → ∣ g1 ∣₂ ∣·∣₂ (∣ g2 ∣₂ ∣·∣₂ ∣ g3 ∣₂) ≡ (∣ g1 ∣₂ ∣·∣₂ ∣ g2 ∣₂) ∣·∣₂ ∣ g3 ∣₂ inuctionBase g1 g2 g3 = cong (λ x → ∣ x ∣₂) (assoc g1 g2 g3) Bset : ∀ x y z → isSet (x ∣·∣₂ (y ∣·∣₂ z) ≡ (x ∣·∣₂ y) ∣·∣₂ z) Bset x y z = isProp→isSet (squash₂ (x ∣·∣₂ (y ∣·∣₂ z)) ((x ∣·∣₂ y) ∣·∣₂ z)) |assoc∣₂ : (x y z : ∥ FreeGroupoid A ∥₂) → x ∣·∣₂ (y ∣·∣₂ z) ≡ (x ∣·∣₂ y) ∣·∣₂ z |assoc∣₂ = elim3 Bset inuctionBase ∣ε∣₂ : ∥ FreeGroupoid A ∥₂ ∣ε∣₂ = ∣ ε ∣₂ ∥freeGroupoid∥₂IsMonoid : IsMonoid {A = ∥ FreeGroupoid A ∥₂} ∣ε∣₂ _∣·∣₂_ ∥freeGroupoid∥₂IsMonoid = ismonoid ∥freeGroupoid∥₂IsSemiGroup (λ x → elim (λ g → isProp→isSet (squash₂ (g ∣·∣₂ ∣ε∣₂) g)) (λ g → cong (λ g' → ∣ g' ∣₂) (sym (idr g))) x) (λ x → elim (λ g → isProp→isSet (squash₂ (∣ε∣₂ ∣·∣₂ g) g)) (λ g → cong (λ g' → ∣ g' ∣₂) (sym (idl g))) x) ∣inv∣₂ : ∥ FreeGroupoid A ∥₂ → ∥ FreeGroupoid A ∥₂ ∣inv∣₂ = map inv ∥freeGroupoid∥₂IsGroup : IsGroup {G = ∥ FreeGroupoid A ∥₂} ∣ε∣₂ _∣·∣₂_ ∣inv∣₂ ∥freeGroupoid∥₂IsGroup = isgroup ∥freeGroupoid∥₂IsMonoid (λ x → elim (λ g → isProp→isSet (squash₂ (g ∣·∣₂ (∣inv∣₂ g)) ∣ε∣₂)) (λ g → cong (λ g' → ∣ g' ∣₂) (invr g)) x) (λ x → elim (λ g → isProp→isSet (squash₂ ((∣inv∣₂ g) ∣·∣₂ g) ∣ε∣₂)) (λ g → cong (λ g' → ∣ g' ∣₂) (invl g)) x) ∥freeGroupoid∥₂GroupStr : GroupStr ∥ FreeGroupoid A ∥₂ ∥freeGroupoid∥₂GroupStr = groupstr ∣ε∣₂ _∣·∣₂_ ∣inv∣₂ ∥freeGroupoid∥₂IsGroup ∥freeGroupoid∥₂Group : Type ℓ → Group ℓ ∥freeGroupoid∥₂Group A = ∥ FreeGroupoid A ∥₂ , ∥freeGroupoid∥₂GroupStr forgetfulHom : GroupHom (freeGroupGroup A) (∥freeGroupoid∥₂Group A) forgetfulHom = rec (λ a → ∣ η a ∣₂) forgetfulHom⁻¹ : GroupHom (∥freeGroupoid∥₂Group A) (freeGroupGroup A) forgetfulHom⁻¹ = invf , isHom where invf : ∥ FreeGroupoid A ∥₂ → FreeGroup A invf = recTrunc freeGroupIsSet aux where aux : FreeGroupoid A → FreeGroup A aux (η a) = η a aux (g1 · g2) = (aux g1) · (aux g2) aux ε = ε aux (inv g) = inv (aux g) aux (assoc g1 g2 g3 i) = assoc (aux g1) (aux g2) (aux g3) i aux (idr g i) = idr (aux g) i aux (idl g i) = idl (aux g) i aux (invr g i) = invr (aux g) i aux (invl g i) = invl (aux g) i isHom : IsGroupHom {A = ∥ FreeGroupoid A ∥₂} {B = FreeGroup A} ∥freeGroupoid∥₂GroupStr invf freeGroupGroupStr IsGroupHom.pres· isHom x y = elim2 (λ x y → isProp→isSet (freeGroupIsSet (invf (x ∣·∣₂ y)) ((invf x) · (invf y)))) ind x y where ind : ∀ g1 g2 → invf (∣ g1 ∣₂ ∣·∣₂ ∣ g2 ∣₂) ≡ (invf ∣ g1 ∣₂) · (invf ∣ g2 ∣₂) ind g1 g2 = refl IsGroupHom.pres1 isHom = refl IsGroupHom.presinv isHom x = elim (λ x → isProp→isSet (freeGroupIsSet (invf (∣inv∣₂ x)) (inv (invf x)))) ind x where ind : ∀ g → invf (∣inv∣₂ ∣ g ∣₂) ≡ inv (invf ∣ g ∣₂) ind g = refl freeGroupTruncIdempotentBiInvEquiv : BiInvEquiv (FreeGroup A) ∥ FreeGroupoid A ∥₂ freeGroupTruncIdempotentBiInvEquiv = biInvEquiv f invf rightInv invf leftInv where f : FreeGroup A → ∥ FreeGroupoid A ∥₂ f = fst forgetfulHom invf : ∥ FreeGroupoid A ∥₂ → FreeGroup A invf = fst forgetfulHom⁻¹ rightInv : ∀ (x : ∥ FreeGroupoid A ∥₂) → f (invf x) ≡ x rightInv x = elim (λ x → isProp→isSet (squash₂ (f (invf x)) x)) ind x where ind : ∀ (g : FreeGroupoid A) → f (invf ∣ g ∣₂) ≡ ∣ g ∣₂ ind g = elimProp Bprop η-ind ·-ind ε-ind inv-ind g where Bprop : ∀ g → isProp (f (invf ∣ g ∣₂) ≡ ∣ g ∣₂) Bprop g = squash₂ (f (invf ∣ g ∣₂)) ∣ g ∣₂ η-ind : ∀ a → f (invf ∣ η a ∣₂) ≡ ∣ η a ∣₂ η-ind a = refl ·-ind : ∀ g1 g2 → f (invf ∣ g1 ∣₂) ≡ ∣ g1 ∣₂ → f (invf ∣ g2 ∣₂) ≡ ∣ g2 ∣₂ → f (invf ∣ g1 · g2 ∣₂) ≡ ∣ g1 · g2 ∣₂ ·-ind g1 g2 ind1 ind2 = f (invf ∣ g1 · g2 ∣₂) ≡⟨ cong f (IsGroupHom.pres· (snd forgetfulHom⁻¹) ∣ g1 ∣₂ ∣ g2 ∣₂) ⟩ f ((invf ∣ g1 ∣₂) · (invf ∣ g2 ∣₂)) ≡⟨ IsGroupHom.pres· (snd forgetfulHom) (invf ∣ g1 ∣₂) (invf ∣ g2 ∣₂) ⟩ (f (invf ∣ g1 ∣₂)) ∣·∣₂ (f (invf ∣ g2 ∣₂)) ≡⟨ cong (λ x → x ∣·∣₂ (f (invf ∣ g2 ∣₂))) ind1 ⟩ ∣ g1 ∣₂ ∣·∣₂ (f (invf ∣ g2 ∣₂)) ≡⟨ cong (λ x → ∣ g1 ∣₂ ∣·∣₂ x) ind2 ⟩ ∣ g1 · g2 ∣₂ ∎ ε-ind : f (invf ∣ ε ∣₂) ≡ ∣ ε ∣₂ ε-ind = refl inv-ind : ∀ g → f (invf ∣ g ∣₂) ≡ ∣ g ∣₂ → f (invf ∣ inv g ∣₂) ≡ ∣ inv g ∣₂ inv-ind g ind = f (invf ∣ inv g ∣₂) ≡⟨ refl ⟩ f (invf (∣inv∣₂ ∣ g ∣₂)) ≡⟨ cong f (IsGroupHom.presinv (snd forgetfulHom⁻¹) ∣ g ∣₂) ⟩ f (inv (invf ∣ g ∣₂)) ≡⟨ IsGroupHom.presinv (snd forgetfulHom) (invf ∣ g ∣₂) ⟩ ∣inv∣₂ (f (invf ∣ g ∣₂)) ≡⟨ cong ∣inv∣₂ ind ⟩ ∣inv∣₂ ∣ g ∣₂ ≡⟨ refl ⟩ ∣ inv g ∣₂ ∎ leftInv : ∀ (g : FreeGroup A) → invf (f g) ≡ g leftInv g = freeGroupElimProp Bprop η-ind ·-ind ε-ind inv-ind g where Bprop : ∀ g → isProp (invf (f g) ≡ g) Bprop g = freeGroupIsSet (invf (f g)) g η-ind : ∀ a → invf (f (η a)) ≡ (η a) η-ind a = refl ·-ind : ∀ g1 g2 → invf (f g1) ≡ g1 → invf (f g2) ≡ g2 → invf (f (g1 · g2)) ≡ g1 · g2 ·-ind g1 g2 ind1 ind2 = invf (f (g1 · g2)) ≡⟨ cong invf (IsGroupHom.pres· (snd forgetfulHom) g1 g2) ⟩ invf ((f g1) ∣·∣₂ (f g2)) ≡⟨ IsGroupHom.pres· (snd forgetfulHom⁻¹) (f g1) (f g2) ⟩ (invf (f g1)) · (invf (f g2)) ≡⟨ cong (λ x → x · (invf (f g2))) ind1 ⟩ g1 · (invf (f g2)) ≡⟨ cong (λ x → g1 · x) ind2 ⟩ g1 · g2 ∎ ε-ind : invf (f ε) ≡ ε ε-ind = refl inv-ind : ∀ g → invf (f g) ≡ g → invf (f (inv g)) ≡ inv g inv-ind g ind = invf (f (inv g)) ≡⟨ cong invf (IsGroupHom.presinv (snd forgetfulHom) g) ⟩ invf (∣inv∣₂ (f g)) ≡⟨ IsGroupHom.presinv (snd forgetfulHom⁻¹) (f g) ⟩ inv (invf (f g)) ≡⟨ cong inv ind ⟩ inv g ∎ freeGroupTruncIdempotent≃ : FreeGroup A ≃ ∥ FreeGroupoid A ∥₂ freeGroupTruncIdempotent≃ = biInvEquiv→Equiv-right freeGroupTruncIdempotentBiInvEquiv freeGroupTruncIdempotent : FreeGroup A ≡ ∥ FreeGroupoid A ∥₂ freeGroupTruncIdempotent = ua freeGroupTruncIdempotent≃
algebraic-stack_agda0000_doc_12482
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} -- This is a selection of useful functions and definitions -- from the standard library that we tend to use a lot. module Util.Prelude where open import Haskell.Prelude public open import Dijkstra.All public open import Level renaming (suc to ℓ+1; zero to ℓ0; _⊔_ to _ℓ⊔_) public 1ℓ : Level 1ℓ = ℓ+1 0ℓ open import Agda.Builtin.Unit public open import Function using (_∘_; _∘′_; case_of_; _on_; _∋_) public identity = Function.id open import Data.Unit.NonEta public open import Data.Empty public -- NOTE: This function is defined to give extra documentation when discharging -- absurd cases where Agda can tell by pattern matching that `A` is not -- inhabited. For example: -- > absurd (just v ≡ nothing) case impossibleProof of λ () infix 0 absurd_case_of_ absurd_case_of_ : ∀ {ℓ₁ ℓ₂} (A : Set ℓ₁) {B : Set ℓ₂} → A → (A → ⊥) → B absurd A case x of f = ⊥-elim (f x) open import Data.Nat renaming (_≟_ to _≟ℕ_; _≤?_ to _≤?ℕ_; _≥?_ to _≥?ℕ_; compare to compareℕ; Ordering to Orderingℕ) public max = _⊔_ min = _⊓_ open import Data.Nat.Properties hiding (≡-irrelevant ; _≟_) public open import Data.List renaming (map to List-map ; filter to List-filter ; lookup to List-lookup; tabulate to List-tabulate; foldl to List-foldl) hiding (fromMaybe; [_]) public open import Data.List.Properties renaming (≡-dec to List-≡-dec; length-map to List-length-map; map-compose to List-map-compose; filter-++ to List-filter-++; length-filter to List-length-filter) using (∷-injective; length-++; map-++-commute; sum-++-commute; map-tabulate; tabulate-lookup; ++-identityʳ; ++-identityˡ) public open import Data.List.Relation.Binary.Subset.Propositional renaming (_⊆_ to _⊆List_) public open import Data.List.Relation.Unary.Any using (Any; here; there) renaming (lookup to Any-lookup; map to Any-map; satisfied to Any-satisfied ;index to Any-index; any to Any-any) public open import Data.List.Relation.Unary.Any.Properties using (¬Any[]) renaming ( map⁺ to Any-map⁺ ; map⁻ to Any-map⁻ ; concat⁺ to Any-concat⁺ ; concat⁻ to Any-concat⁻ ; ++⁻ to Any-++⁻ ; ++⁺ʳ to Any-++ʳ ; ++⁺ˡ to Any-++ˡ ; singleton⁻ to Any-singleton⁻ ; tabulate⁺ to Any-tabulate⁺ ; filter⁻ to Any-filter⁻ ) public open import Data.List.Relation.Unary.All using (All; []; _∷_) renaming (head to All-head; tail to All-tail; lookup to All-lookup; tabulate to All-tabulate; reduce to All-reduce; map to All-map) public open import Data.List.Relation.Unary.All.Properties hiding (All-map) renaming ( tabulate⁻ to All-tabulate⁻ ; tabulate⁺ to All-tabulate⁺ ; map⁺ to All-map⁺ ; map⁻ to All-map⁻ ; ++⁺ to All-++ ) public open import Data.List.Membership.Propositional using (_∈_; _∉_) public open import Data.List.Membership.Propositional.Properties renaming (∈-filter⁺ to List-∈-filter⁺; ∈-filter⁻ to List-∈-filter⁻) public open import Data.Vec using (Vec; []; _∷_) renaming (replicate to Vec-replicate; lookup to Vec-lookup ;map to Vec-map; head to Vec-head; tail to Vec-tail ;updateAt to Vec-updateAt; tabulate to Vec-tabulate ;allFin to Vec-allFin; toList to Vec-toList; fromList to Vec-fromList ;_++_ to _Vec-++_) public open import Data.Vec.Relation.Unary.All using ([]; _∷_) renaming (All to Vec-All; lookup to Vec-All-lookup) public open import Data.Vec.Properties using () renaming (updateAt-minimal to Vec-updateAt-minimal ;[]=⇒lookup to Vec-[]=⇒lookup ;lookup⇒[]= to Vec-lookup⇒[]= ;lookup∘tabulate to Vec-lookup∘tabulate ;≡-dec to Vec-≡-dec) public open import Data.List.Relation.Binary.Pointwise using (decidable-≡) public open import Data.Bool renaming (_≟_ to _≟Bool_) hiding (_≤?_; _<_; _<?_; _≤_; not) public open import Data.Maybe renaming (map to Maybe-map; maybe to Maybe-maybe; zip to Maybe-zip ; _>>=_ to _Maybe->>=_) hiding (align; alignWith; zipWith) public -- a non-dependent eliminator -- note the traditional argument order is "switched", hence the 'S' maybeS : ∀ {a b} {A : Set a} {B : Set b} → (x : Maybe A) → B → ((x : A) → B) → B maybeS {B = B} x f t = Maybe-maybe {B = const B} t f x -- A Dijkstra version of maybeS, implemented using the version in -- Dijkstra.Syntax which has traditional argument order maybeSD : ∀ {ℓ₁ ℓ₂} {M : Set ℓ₁ → Set ℓ₂} ⦃ mmd : MonadMaybeD M ⦄ → ∀ {A B : Set ℓ₁} → Maybe A → M B → (A → M B) → M B maybeSD ⦃ mmd ⦄ x y z = maybeD y z x module _ {Ev Wr St A B : Set} where maybeSMP-RWS : RWS Ev Wr St (Maybe A) → B → (A → RWS Ev Wr St B) → RWS Ev Wr St B maybeSMP-RWS x y z = maybeMP-RWS y z x open import Data.Maybe.Relation.Unary.Any renaming (Any to Maybe-Any; dec to Maybe-Any-dec) hiding (map; zip; zipWith; unzip ; unzipWith) public maybe-any-⊥ : ∀{a}{A : Set a} → Maybe-Any {A = A} (λ _ → ⊤) nothing → ⊥ maybe-any-⊥ () headMay : ∀ {A : Set} → List A → Maybe A headMay [] = nothing headMay (x ∷ _) = just x lastMay : ∀ {A : Set} → List A → Maybe A lastMay [] = nothing lastMay (x ∷ []) = just x lastMay (_ ∷ x ∷ xs) = lastMay (x ∷ xs) open import Data.Maybe.Properties using (just-injective) renaming (≡-dec to Maybe-≡-dec) public open import Data.Fin using (Fin; suc; zero; fromℕ; fromℕ< ; toℕ ; cast) renaming (_≟_ to _≟Fin_; _≤?_ to _≤?Fin_; _≤_ to _≤Fin_ ; _<_ to _<Fin_; inject₁ to Fin-inject₁; inject+ to Fin-inject+; inject≤ to Fin-inject≤) public fins : (n : ℕ) → List (Fin n) fins n = Vec-toList (Vec-allFin n) open import Data.Fin.Properties using (toℕ-injective; toℕ<n) renaming (<-cmp to Fin-<-cmp; <⇒≢ to <⇒≢Fin; suc-injective to Fin-suc-injective) public open import Relation.Binary.PropositionalEquality hiding (decSetoid) public open import Relation.Binary.HeterogeneousEquality using (_≅_) renaming (cong to ≅-cong; cong₂ to ≅-cong₂) public open import Relation.Binary public ≡-irrelevant : ∀{a}{A : Set a} → Irrelevant {a} {A} _≡_ ≡-irrelevant refl refl = refl to-witness-lemma : ∀{ℓ}{A : Set ℓ}{a : A}{f : Maybe A}(x : Is-just f) → to-witness x ≡ a → f ≡ just a to-witness-lemma (just x) refl = refl open import Relation.Nullary hiding (Irrelevant; proof) public open import Relation.Nullary.Decidable hiding (map) public open import Data.Sum renaming (map to ⊎-map; map₁ to ⊎-map₁; map₂ to ⊎-map₂) public open import Data.Sum.Properties using (inj₁-injective ; inj₂-injective) public ⊎-elimˡ : ∀ {ℓ₀ ℓ₁}{A₀ : Set ℓ₀}{A₁ : Set ℓ₁} → ¬ A₀ → A₀ ⊎ A₁ → A₁ ⊎-elimˡ ¬a = either (⊥-elim ∘ ¬a) id ⊎-elimʳ : ∀ {ℓ₀ ℓ₁}{A₀ : Set ℓ₀}{A₁ : Set ℓ₁} → ¬ A₁ → A₀ ⊎ A₁ → A₀ ⊎-elimʳ ¬a = either id (⊥-elim ∘ ¬a) open import Data.Product renaming (map to ×-map; map₂ to ×-map₂; map₁ to ×-map₁; <_,_> to split; swap to ×-swap) hiding (zip) public open import Data.Product.Properties public module _ {ℓA} {A : Set ℓA} where NoneOfKind : ∀ {ℓ} {P : A → Set ℓ} → List A → (p : (a : A) → Dec (P a)) → Set ℓA NoneOfKind xs p = List-filter p xs ≡ [] postulate -- TODO-1: Replace with or prove using library properties? Move to Lemmas? NoneOfKind⇒ : ∀ {ℓ} {P : A → Set ℓ} {Q : A → Set ℓ} {xs : List A} → (p : (a : A) → Dec (P a)) → {q : (a : A) → Dec (Q a)} → (∀ {a} → P a → Q a) -- TODO-1: Use proper notation (Relation.Unary?) → NoneOfKind xs q → NoneOfKind xs p infix 4 _<?ℕ_ _<?ℕ_ : Decidable _<_ m <?ℕ n = suc m ≤?ℕ n infix 0 if-yes_then_else_ infix 0 if-dec_then_else_ if-yes_then_else_ : ∀ {ℓA ℓB} {A : Set ℓA} {B : Set ℓB} → Dec A → (A → B) → (¬ A → B) → B if-yes (yes prf) then f else _ = f prf if-yes (no prf) then _ else g = g prf if-dec_then_else_ : ∀ {ℓA ℓB} {A : Set ℓA} {B : Set ℓB} → Dec A → B → B → B if-dec x then f else g = if-yes x then const f else const g open import Relation.Nullary.Negation using (contradiction; contraposition) public open import Relation.Binary using (Setoid; IsPreorder) public open import Relation.Unary using (_∪_) public open import Relation.Unary.Properties using (_∪?_) public -- Injectivity for a function of two potentially different types (A and B) via functions to a -- common type (C). Injective' : ∀ {b c d e}{B : Set b}{C : Set c}{D : Set d} → (hB : B → D) → (hC : C → D) → (_≈_ : B → C → Set e) → Set _ Injective' {C = C} hB hC _≈_ = ∀ {b c} → hB b ≡ hC c → b ≈ c Injective : ∀ {c d e}{C : Set c}{D : Set d} → (h : C → D) → (_≈_ : Rel C e) → Set _ Injective h _≈_ = Injective' h h _≈_ Injective-≡ : ∀ {c d}{C : Set c}{D : Set d} → (h : C → D) → Set _ Injective-≡ h = Injective h _≡_ Injective-int : ∀{a b c d e}{A : Set a}{B : Set b}{C : Set c}{D : Set d} → (_≈_ : A → B → Set e) → (h : C → D) → (f₁ : A → C) → (f₂ : B → C) → Set (a ℓ⊔ b ℓ⊔ d ℓ⊔ e) Injective-int _≈_ h f₁ f₂ = ∀ {a₁} {b₁} → h (f₁ a₁) ≡ h (f₂ b₁) → a₁ ≈ b₁ NonInjective : ∀{a b c}{A : Set a}{B : Set b} → (_≈_ : Rel A c) → (A → B) → Set (a ℓ⊔ b ℓ⊔ c) NonInjective {A = A} _≈_ f = Σ (A × A) (λ { (x₁ , x₂) → ¬ (x₁ ≈ x₂) × f x₁ ≡ f x₂ }) NonInjective-≡ : ∀{a b}{A : Set a}{B : Set b} → (A → B) → Set (a ℓ⊔ b) NonInjective-≡ = NonInjective _≡_ NonInjective-≡-preds : ∀{a b}{A : Set a}{B : Set b}{ℓ₁ ℓ₂ : Level} → (A → Set ℓ₁) → (A → Set ℓ₂) → (A → B) → Set (a ℓ⊔ b ℓ⊔ ℓ₁ ℓ⊔ ℓ₂) NonInjective-≡-preds Pred1 Pred2 f = Σ (NonInjective _≡_ f) λ { ((a₀ , a₁) , _ , _) → Pred1 a₀ × Pred2 a₁ } NonInjective-≡-pred : ∀{a b}{A : Set a}{B : Set b}{ℓ : Level} → (P : A → Set ℓ) → (A → B) → Set (a ℓ⊔ b ℓ⊔ ℓ) NonInjective-≡-pred Pred = NonInjective-≡-preds Pred Pred NonInjective-∘ : ∀{a b c}{A : Set a}{B : Set b}{C : Set c} → {f : A → B}(g : B → C) → NonInjective-≡ f → NonInjective-≡ (g ∘ f) NonInjective-∘ g ((x0 , x1) , (x0≢x1 , fx0≡fx1)) = ((x0 , x1) , x0≢x1 , (cong g fx0≡fx1)) -------------------------------------------- -- Handy fmap and bind for specific types -- _<M$>_ : ∀{a b}{A : Set a}{B : Set b} → (f : A → B) → Maybe A → Maybe B _<M$>_ = Maybe-map <M$>-univ : ∀{a b}{A : Set a}{B : Set b} → (f : A → B)(x : Maybe A) → {y : B} → f <M$> x ≡ just y → ∃[ x' ] (x ≡ just x' × f x' ≡ y) <M$>-univ f (just x) refl = x , (refl , refl) maybe-lift : {A : Set} → {mx : Maybe A}{x : A} → (P : A → Set) → P x → mx ≡ just x → Maybe-maybe {B = const Set} P ⊥ mx maybe-lift {mx = just .x} {x} P px refl = px <M$>-nothing : ∀ {a b}{A : Set a}{B : Set b}(f : A → B) → f <M$> nothing ≡ nothing <M$>-nothing _ = refl _<⊎$>_ : ∀{a b c}{A : Set a}{B : Set b}{C : Set c} → (A → B) → C ⊎ A → C ⊎ B f <⊎$> (inj₁ hb) = inj₁ hb f <⊎$> (inj₂ x) = inj₂ (f x) _⊎⟫=_ : ∀{a b c}{A : Set a}{B : Set b}{C : Set c} → C ⊎ A → (A → C ⊎ B) → C ⊎ B (inj₁ x) ⊎⟫= _ = inj₁ x (inj₂ a) ⊎⟫= f = f a -- a non-dependent eliminator -- note the traditional argument order is "switched", hence the 'S' eitherS : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} (x : Either A B) → ((x : A) → C) → ((x : B) → C) → C eitherS eab fa fb = case eab of λ where (Left a) → fa a (Right b) → fb b -- A Dijkstra version of eitherS, implemented using the version in -- Dijkstra.Syntax which has traditional argument order eitherSD : ∀ {ℓ₁ ℓ₂ ℓ₃} {M : Set ℓ₁ → Set ℓ₂} ⦃ med : MonadEitherD M ⦄ → ∀ {EL : Set ℓ₁ → Set ℓ₁ → Set ℓ₃} ⦃ _ : EitherLike EL ⦄ → ∀ {E A B : Set ℓ₁} → EL E A → (E → M B) → (A → M B) → M B eitherSD ⦃ med ⦄ ⦃ el ⦄ x y z = eitherD y z x open import Data.String as String hiding (_==_ ; _≟_ ; concat) check : Bool → List String → Either String Unit check b t = if b then inj₂ unit else inj₁ (String.intersperse "; " t) toWitnessT : ∀{ℓ}{P : Set ℓ}{d : Dec P} → ⌊ d ⌋ ≡ true → P toWitnessT {d = yes proof} _ = proof toWitnessF : ∀{ℓ}{P : Set ℓ}{d : Dec P} → ⌊ d ⌋ ≡ false → ¬ P toWitnessF{d = no proof} _ = proof Any-satisfied-∈ : ∀{a ℓ}{A : Set a}{P : A → Set ℓ}{xs : List A} → Any P xs → Σ A (λ x → P x × x ∈ xs) Any-satisfied-∈ (here px) = _ , (px , here refl) Any-satisfied-∈ (there p) = let (a , px , prf) = Any-satisfied-∈ p in (a , px , there prf) f-sum : ∀{a}{A : Set a} → (A → ℕ) → List A → ℕ f-sum f = sum ∘ List-map f maybeSMP : ∀ {ℓ} {A B : Set} {m : Set → Set ℓ} ⦃ _ : Monad m ⦄ → m (Maybe A) → B → (A → m B) → m B maybeSMP ma b f = do x ← ma case x of λ where nothing → pure b (just j) → f j open import LibraBFT.Base.Util public -- Like a Haskell list-comprehension for ℕ : [ n | n <- [from .. to] ] fromToList : ℕ → ℕ → List ℕ fromToList from to with from ≤′? to ... | no ¬pr = [] ... | yes pr = fromToList-le from to pr [] where fromToList-le : ∀ (from to : ℕ) (klel : from ≤′ to) (acc : List ℕ) → List ℕ fromToList-le from ._ ≤′-refl acc = from ∷ acc fromToList-le from (suc to) (≤′-step klel) acc = fromToList-le from to klel (suc to ∷ acc) _ : fromToList 1 1 ≡ 1 ∷ [] _ = refl _ : fromToList 1 2 ≡ 1 ∷ 2 ∷ [] _ = refl _ : fromToList 2 1 ≡ [] _ = refl
algebraic-stack_agda0000_doc_12483
module Data.List.Primitive where -- In Agda 2.2.10 and below, there's no FFI binding for the stdlib -- List type, so we have to roll our own. This will change. data #List (X : Set) : Set where [] : #List X _∷_ : X → #List X → #List X {-# COMPILED_DATA #List [] [] (:) #-}
algebraic-stack_agda0000_doc_12484
{-# OPTIONS --safe --experimental-lossy-unification #-} -- This file could be proven using the file Sn -- However the proofs are easier than in Sn -- And so kept for pedagologic reasons module Cubical.ZCohomology.CohomologyRings.S1 where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Transport open import Cubical.Foundations.HLevels open import Cubical.Data.Unit open import Cubical.Data.Nat renaming (_+_ to _+n_ ; _·_ to _·n_ ; snotz to nsnotz) open import Cubical.Data.Int open import Cubical.Data.Vec open import Cubical.Data.FinData open import Cubical.Algebra.Group open import Cubical.Algebra.Group.Morphisms open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Algebra.Group.Instances.Int renaming (ℤGroup to ℤG) open import Cubical.Algebra.DirectSum.Base open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommRing.FGIdeal open import Cubical.Algebra.CommRing.QuotientRing open import Cubical.Algebra.Polynomials.Multivariate.Base renaming (base to baseP) open import Cubical.Algebra.CommRing.Instances.Int renaming (ℤCommRing to ℤCR) open import Cubical.Algebra.CommRing.Instances.MultivariatePoly open import Cubical.Algebra.CommRing.Instances.MultivariatePoly-Quotient open import Cubical.Algebra.CommRing.Instances.MultivariatePoly-notationZ open import Cubical.HITs.Truncation open import Cubical.HITs.SetQuotients as SQ renaming (_/_ to _/sq_) open import Cubical.HITs.PropositionalTruncation as PT open import Cubical.HITs.Sn open import Cubical.ZCohomology.Base open import Cubical.ZCohomology.GroupStructure open import Cubical.ZCohomology.RingStructure.CupProduct open import Cubical.ZCohomology.RingStructure.CohomologyRing open import Cubical.ZCohomology.Groups.Sn open Iso module Equiv-S1-Properties where ----------------------------------------------------------------------------- -- Definitions open CommRingStr (snd ℤCR) using () renaming ( 0r to 0ℤ ; 1r to 1ℤ ; _+_ to _+ℤ_ ; -_ to -ℤ_ ; _·_ to _·ℤ_ ; +Assoc to +ℤAssoc ; +Identity to +ℤIdentity ; +Lid to +ℤLid ; +Rid to +ℤRid ; +Inv to +ℤInv ; +Linv to +ℤLinv ; +Rinv to +ℤRinv ; +Comm to +ℤComm ; ·Assoc to ·ℤAssoc ; ·Identity to ·ℤIdentity ; ·Lid to ·ℤLid ; ·Rid to ·ℤRid ; ·Rdist+ to ·ℤRdist+ ; ·Ldist+ to ·ℤLdist+ ; is-set to isSetℤ ) open RingStr (snd (H*R (S₊ 1))) using () renaming ( 0r to 0H* ; 1r to 1H* ; _+_ to _+H*_ ; -_ to -H*_ ; _·_ to _cup_ ; +Assoc to +H*Assoc ; +Identity to +H*Identity ; +Lid to +H*Lid ; +Rid to +H*Rid ; +Inv to +H*Inv ; +Linv to +H*Linv ; +Rinv to +H*Rinv ; +Comm to +H*Comm ; ·Assoc to ·H*Assoc ; ·Identity to ·H*Identity ; ·Lid to ·H*Lid ; ·Rid to ·H*Rid ; ·Rdist+ to ·H*Rdist+ ; ·Ldist+ to ·H*Ldist+ ; is-set to isSetH* ) open CommRingStr (snd ℤ[X]) using () renaming ( 0r to 0Pℤ ; 1r to 1Pℤ ; _+_ to _+Pℤ_ ; -_ to -Pℤ_ ; _·_ to _·Pℤ_ ; +Assoc to +PℤAssoc ; +Identity to +PℤIdentity ; +Lid to +PℤLid ; +Rid to +PℤRid ; +Inv to +PℤInv ; +Linv to +PℤLinv ; +Rinv to +PℤRinv ; +Comm to +PℤComm ; ·Assoc to ·PℤAssoc ; ·Identity to ·PℤIdentity ; ·Lid to ·PℤLid ; ·Rid to ·PℤRid ; ·Comm to ·PℤComm ; ·Rdist+ to ·PℤRdist+ ; ·Ldist+ to ·PℤLdist+ ; is-set to isSetPℤ ) open CommRingStr (snd ℤ[X]/X²) using () renaming ( 0r to 0PℤI ; 1r to 1PℤI ; _+_ to _+PℤI_ ; -_ to -PℤI_ ; _·_ to _·PℤI_ ; +Assoc to +PℤIAssoc ; +Identity to +PℤIIdentity ; +Lid to +PℤILid ; +Rid to +PℤIRid ; +Inv to +PℤIInv ; +Linv to +PℤILinv ; +Rinv to +PℤIRinv ; +Comm to +PℤIComm ; ·Assoc to ·PℤIAssoc ; ·Identity to ·PℤIIdentity ; ·Lid to ·PℤILid ; ·Rid to ·PℤIRid ; ·Rdist+ to ·PℤIRdist+ ; ·Ldist+ to ·PℤILdist+ ; is-set to isSetPℤI ) ----------------------------------------------------------------------------- -- Direct Sens on ℤ[x] ℤ[x]→H*-S¹ : ℤ[x] → H* (S₊ 1) ℤ[x]→H*-S¹ = Poly-Rec-Set.f _ _ _ isSetH* 0H* base-trad _+H*_ +H*Assoc +H*Rid +H*Comm base-neutral-eq base-add-eq where e : _ e = Hᵐ-Sⁿ base-trad : _ base-trad (zero ∷ []) a = base 0 (inv (fst (Hᵐ-Sⁿ 0 1)) a) base-trad (one ∷ []) a = base 1 (inv (fst (Hᵐ-Sⁿ 1 1)) a) base-trad (suc (suc n) ∷ []) a = 0H* base-neutral-eq : _ base-neutral-eq (zero ∷ []) = cong (base 0) (IsGroupHom.pres1 (snd (invGroupIso (Hᵐ-Sⁿ 0 1)))) ∙ base-neutral _ base-neutral-eq (one ∷ []) = cong (base 1) (IsGroupHom.pres1 (snd (invGroupIso (Hᵐ-Sⁿ 1 1)))) ∙ base-neutral _ base-neutral-eq (suc (suc n) ∷ []) = refl base-add-eq : _ base-add-eq (zero ∷ []) a b = (base-add _ _ _) ∙ (cong (base 0) (sym (IsGroupHom.pres· (snd (invGroupIso (Hᵐ-Sⁿ 0 1))) a b))) base-add-eq (one ∷ []) a b = (base-add _ _ _) ∙ (cong (base 1) (sym (IsGroupHom.pres· (snd (invGroupIso (Hᵐ-Sⁿ 1 1))) a b))) base-add-eq (suc (suc n) ∷ []) a b = +H*Rid _ ----------------------------------------------------------------------------- -- Morphism on ℤ[x] ℤ[x]→H*-S¹-pres1Pℤ : ℤ[x]→H*-S¹ (1Pℤ) ≡ 1H* ℤ[x]→H*-S¹-pres1Pℤ = refl ℤ[x]→H*-S¹-pres+ : (x y : ℤ[x]) → ℤ[x]→H*-S¹ (x +Pℤ y) ≡ ℤ[x]→H*-S¹ x +H* ℤ[x]→H*-S¹ y ℤ[x]→H*-S¹-pres+ x y = refl -- cup product on H⁰ → H⁰ → H⁰ T0 : (z : ℤ) → coHom 0 (S₊ 1) T0 = λ z → inv (fst (Hᵐ-Sⁿ 0 1)) z T0g : IsGroupHom (ℤG .snd) (fst (invGroupIso (Hᵐ-Sⁿ 0 1)) .fun) (coHomGr 0 (S₊ (suc 0)) .snd) T0g = snd (invGroupIso (Hᵐ-Sⁿ 0 1)) -- idea : control of the unfolding + simplification of T0 on the left pres·-base-case-00 : (a : ℤ) → (b : ℤ) → T0 (a ·ℤ b) ≡ (T0 a) ⌣ (T0 b) pres·-base-case-00 (pos zero) b = (IsGroupHom.pres1 T0g) pres·-base-case-00 (pos (suc n)) b = ((IsGroupHom.pres· T0g b (pos n ·ℤ b))) ∙ (cong (λ X → (T0 b) +ₕ X) (pres·-base-case-00 (pos n) b)) pres·-base-case-00 (negsuc zero) b = IsGroupHom.presinv T0g b pres·-base-case-00 (negsuc (suc n)) b = cong T0 (+ℤComm (-ℤ b) (negsuc n ·ℤ b)) -- ·ℤ and ·₀ are defined asymetrically ! ∙ IsGroupHom.pres· T0g (negsuc n ·ℤ b) (-ℤ b) ∙ cong₂ _+ₕ_ (pres·-base-case-00 (negsuc n) b) (IsGroupHom.presinv T0g b) -- cup product on H⁰ → H¹ → H¹ T1 : (z : ℤ) → coHom 1 (S₊ 1) T1 = λ z → inv (fst (Hᵐ-Sⁿ 1 1)) z -- idea : control of the unfolding + simplification of T0 on the left T1g : IsGroupHom (ℤG .snd) (fst (invGroupIso (Hᵐ-Sⁿ 1 1)) .fun) (coHomGr 1 (S₊ 1) .snd) T1g = snd (invGroupIso (Hᵐ-Sⁿ 1 1)) pres·-base-case-01 : (a : ℤ) → (b : ℤ) → T1 (a ·ℤ b) ≡ (T0 a) ⌣ (T1 b) pres·-base-case-01 (pos zero) b = (IsGroupHom.pres1 T1g) pres·-base-case-01 (pos (suc n)) b = ((IsGroupHom.pres· T1g b (pos n ·ℤ b))) ∙ (cong (λ X → (T1 b) +ₕ X) (pres·-base-case-01 (pos n) b)) pres·-base-case-01 (negsuc zero) b = IsGroupHom.presinv T1g b pres·-base-case-01 (negsuc (suc n)) b = cong T1 (+ℤComm (-ℤ b) (negsuc n ·ℤ b)) -- ·ℤ and ·₀ are defined asymetrically ! ∙ IsGroupHom.pres· T1g (negsuc n ·ℤ b) (-ℤ b) ∙ cong₂ _+ₕ_ (pres·-base-case-01 (negsuc n) b) (IsGroupHom.presinv T1g b) -- Nice packaging of the proof pres·-base-case-int : (n : ℕ) → (a : ℤ) → (m : ℕ) → (b : ℤ) → ℤ[x]→H*-S¹ (baseP (n ∷ []) a ·Pℤ baseP (m ∷ []) b) ≡ ℤ[x]→H*-S¹ (baseP (n ∷ []) a) cup ℤ[x]→H*-S¹ (baseP (m ∷ []) b) pres·-base-case-int zero a zero b = cong (base 0) (pres·-base-case-00 a b) pres·-base-case-int zero a one b = cong (base 1) (pres·-base-case-01 a b) pres·-base-case-int zero a (suc (suc m)) b = refl pres·-base-case-int one a zero b = cong ℤ[x]→H*-S¹ (·PℤComm (baseP (1 ∷ []) a) (baseP (zero ∷ []) b)) ∙ pres·-base-case-int 0 b 1 a ∙ gradCommRing (S₊ 1) 0 1 (inv (fst (Hᵐ-Sⁿ 0 1)) b) (inv (fst (Hᵐ-Sⁿ 1 1)) a) pres·-base-case-int one a one b = sym (base-neutral 2) ∙ cong (base 2) (isOfHLevelRetractFromIso 1 (fst (Hⁿ-Sᵐ≅0 1 0 nsnotz)) isPropUnit _ _) pres·-base-case-int one a (suc (suc m)) b = refl pres·-base-case-int (suc (suc n)) a m b = refl pres·-base-case-vec : (v : Vec ℕ 1) → (a : ℤ) → (v' : Vec ℕ 1) → (b : ℤ) → ℤ[x]→H*-S¹ (baseP v a ·Pℤ baseP v' b) ≡ ℤ[x]→H*-S¹ (baseP v a) cup ℤ[x]→H*-S¹ (baseP v' b) pres·-base-case-vec (n ∷ []) a (m ∷ []) b = pres·-base-case-int n a m b -- proof of the morphism ℤ[x]→H*-S¹-pres· : (x y : ℤ[x]) → ℤ[x]→H*-S¹ (x ·Pℤ y) ≡ ℤ[x]→H*-S¹ x cup ℤ[x]→H*-S¹ y ℤ[x]→H*-S¹-pres· = Poly-Ind-Prop.f _ _ _ (λ x p q i y j → isSetH* _ _ (p y) (q y) i j) (λ y → refl) base-case λ {U V} ind-U ind-V y → cong₂ _+H*_ (ind-U y) (ind-V y) where base-case : _ base-case (n ∷ []) a = Poly-Ind-Prop.f _ _ _ (λ _ → isSetH* _ _) (sym (RingTheory.0RightAnnihilates (H*R (S₊ 1)) _)) (λ v' b → pres·-base-case-vec (n ∷ []) a v' b) λ {U V} ind-U ind-V → (cong₂ _+H*_ ind-U ind-V) ∙ sym (·H*Rdist+ _ _ _) ----------------------------------------------------------------------------- -- Function on ℤ[x]/x + morphism ℤ[x]→H*-S¹-cancelX : (k : Fin 1) → ℤ[x]→H*-S¹ (<X²> k) ≡ 0H* ℤ[x]→H*-S¹-cancelX zero = refl ℤ[X]→H*-S¹ : RingHom (CommRing→Ring ℤ[X]) (H*R (S₊ 1)) fst ℤ[X]→H*-S¹ = ℤ[x]→H*-S¹ snd ℤ[X]→H*-S¹ = makeIsRingHom ℤ[x]→H*-S¹-pres1Pℤ ℤ[x]→H*-S¹-pres+ ℤ[x]→H*-S¹-pres· ℤ[X]/X²→H*R-S¹ : RingHom (CommRing→Ring ℤ[X]/X²) (H*R (S₊ 1)) ℤ[X]/X²→H*R-S¹ = Quotient-FGideal-CommRing-Ring.f ℤ[X] (H*R (S₊ 1)) ℤ[X]→H*-S¹ <X²> ℤ[x]→H*-S¹-cancelX ℤ[x]/x²→H*-S¹ : ℤ[x]/x² → H* (S₊ 1) ℤ[x]/x²→H*-S¹ = fst ℤ[X]/X²→H*R-S¹ ----------------------------------------------------------------------------- -- Converse Sens on ℤ[X] + ℤ[x]/x H*-S¹→ℤ[x] : H* (S₊ 1) → ℤ[x] H*-S¹→ℤ[x] = DS-Rec-Set.f _ _ _ _ isSetPℤ 0Pℤ base-trad _+Pℤ_ +PℤAssoc +PℤRid +PℤComm base-neutral-eq base-add-eq where base-trad : _ base-trad zero a = baseP (0 ∷ []) (fun (fst (Hᵐ-Sⁿ 0 1)) a) base-trad one a = baseP (1 ∷ []) (fun (fst (Hᵐ-Sⁿ 1 1)) a) base-trad (suc (suc n)) a = 0Pℤ base-neutral-eq : _ base-neutral-eq zero = cong (baseP (0 ∷ [])) (IsGroupHom.pres1 (snd (Hᵐ-Sⁿ 0 1))) ∙ base-0P _ base-neutral-eq one = cong (baseP (1 ∷ [])) (IsGroupHom.pres1 (snd (Hᵐ-Sⁿ 1 1))) ∙ base-0P _ base-neutral-eq (suc (suc n)) = refl base-add-eq : _ base-add-eq zero a b = (base-poly+ _ _ _) ∙ (cong (baseP (0 ∷ [])) (sym (IsGroupHom.pres· (snd (Hᵐ-Sⁿ 0 1)) a b))) base-add-eq one a b = (base-poly+ _ _ _) ∙ (cong (baseP (1 ∷ [])) (sym (IsGroupHom.pres· (snd (Hᵐ-Sⁿ 1 1)) a b))) base-add-eq (suc (suc n)) a b = +PℤRid _ H*-S¹→ℤ[x]-pres+ : (x y : H* (S₊ 1)) → H*-S¹→ℤ[x] ( x +H* y) ≡ H*-S¹→ℤ[x] x +Pℤ H*-S¹→ℤ[x] y H*-S¹→ℤ[x]-pres+ x y = refl H*-S¹→ℤ[x]/x² : H* (S₊ 1) → ℤ[x]/x² H*-S¹→ℤ[x]/x² = [_] ∘ H*-S¹→ℤ[x] H*-S¹→ℤ[x]/x²-pres+ : (x y : H* (S₊ 1)) → H*-S¹→ℤ[x]/x² (x +H* y) ≡ (H*-S¹→ℤ[x]/x² x) +PℤI (H*-S¹→ℤ[x]/x² y) H*-S¹→ℤ[x]/x²-pres+ x y = refl ----------------------------------------------------------------------------- -- Section e-sect : (x : H* (S₊ 1)) → ℤ[x]/x²→H*-S¹ (H*-S¹→ℤ[x]/x² x) ≡ x e-sect = DS-Ind-Prop.f _ _ _ _ (λ _ → isSetH* _ _) refl base-case λ {U V} ind-U ind-V → cong₂ _+H*_ ind-U ind-V where base-case : _ base-case zero a = cong (base 0) (leftInv (fst (Hᵐ-Sⁿ 0 1)) a) base-case one a = cong (base 1) (leftInv (fst (Hᵐ-Sⁿ 1 1)) a) base-case (suc (suc n)) a = (sym (base-neutral (suc (suc n)))) ∙ cong (base (suc (suc n))) (isOfHLevelRetractFromIso 1 (fst (Hⁿ-Sᵐ≅0 (suc n) 0 nsnotz)) isPropUnit _ _) ----------------------------------------------------------------------------- -- Retraction e-retr : (x : ℤ[x]/x²) → H*-S¹→ℤ[x]/x² (ℤ[x]/x²→H*-S¹ x) ≡ x e-retr = SQ.elimProp (λ _ → isSetPℤI _ _) (Poly-Ind-Prop.f _ _ _ (λ _ → isSetPℤI _ _) refl base-case λ {U V} ind-U ind-V → cong₂ _+PℤI_ ind-U ind-V) where base-case : _ base-case (zero ∷ []) a = cong [_] (cong (baseP (0 ∷ [])) (rightInv (fst (Hᵐ-Sⁿ 0 1)) a)) base-case (one ∷ []) a = cong [_] (cong (baseP (1 ∷ [])) (rightInv (fst (Hᵐ-Sⁿ 1 1)) a)) base-case (suc (suc n) ∷ []) a = eq/ 0Pℤ (baseP (suc (suc n) ∷ []) a) ∣ ((λ x → baseP (n ∷ []) (-ℤ a)) , helper) ∣₁ where helper : _ helper = (+PℤLid _) ∙ cong₂ baseP (cong (λ X → X ∷ []) (sym (+-comm n 2))) (sym (·ℤRid _)) ∙ (sym (+PℤRid _)) ----------------------------------------------------------------------------- -- Computation of the Cohomology Ring module _ where open Equiv-S1-Properties S¹-CohomologyRing : RingEquiv (CommRing→Ring ℤ[X]/X²) (H*R (S₊ 1)) fst S¹-CohomologyRing = isoToEquiv is where is : Iso ℤ[x]/x² (H* (S₊ 1)) fun is = ℤ[x]/x²→H*-S¹ inv is = H*-S¹→ℤ[x]/x² rightInv is = e-sect leftInv is = e-retr snd S¹-CohomologyRing = snd ℤ[X]/X²→H*R-S¹ CohomologyRing-S¹ : RingEquiv (H*R (S₊ 1)) (CommRing→Ring ℤ[X]/X²) CohomologyRing-S¹ = RingEquivs.invEquivRing S¹-CohomologyRing
algebraic-stack_agda0000_doc_12485
{-# OPTIONS --type-in-type --no-termination-check --no-positivity-check #-} module IMDesc where --******************************************** -- Prelude --******************************************** -- Some preliminary stuffs, to avoid relying on the stdlib --**************** -- Sigma and friends --**************** data Sigma (A : Set)(B : A -> Set) : Set where _,_ : (x : A)(y : B x) -> Sigma A B _*_ : (A B : Set) -> Set A * B = Sigma A \_ -> B fst : {A : Set}{B : A -> Set} -> Sigma A B -> A fst (a , _) = a snd : {A : Set}{B : A -> Set} (p : Sigma A B) -> B (fst p) snd (a , b) = b data Zero : Set where record One : Set where --**************** -- Sum and friends --**************** data _+_ (A B : Set) : Set where l : A -> A + B r : B -> A + B --**************** -- Prop --**************** data EProp : Set where Trivial : EProp Prf : EProp -> Set Prf _ = {! !} --**************** -- Enum --**************** data EnumU : Set where data EnumT (E : EnumU) : Set where Branches : (E : EnumU) -> (P : EnumT E -> Set) -> Set Branches _ _ = {! !} switch : (E : EnumU) -> (e : EnumT E) -> (P : EnumT E -> Set) -> Branches E P -> P e switch = {! !} --******************************************** -- IMDesc --******************************************** --**************** -- Code --**************** data IDesc (I : Set) : Set where iat : (i : I) -> IDesc I ipi : (S : Set)(T : S -> IDesc I) -> IDesc I isigma : (S : Set)(T : S -> IDesc I) -> IDesc I iprf : (Q : EProp) -> IDesc I iprod : (D : IDesc I)(D : IDesc I) -> IDesc I ifsigma : (E : EnumU)(f : Branches E (\ _ -> IDesc I)) -> IDesc I --**************** -- Interpretation --**************** desc : (I : Set)(D : IDesc I)(P : I -> Set) -> Set desc I (iat i) P = P i desc I (ipi S T) P = (s : S) -> desc I (T s) P desc I (isigma S T) P = Sigma S (\ s -> desc I (T s) P) desc I (iprf q) P = Prf q desc I (iprod D D') P = Sigma (desc I D P) (\ _ -> desc I D' P) desc I (ifsigma E B) P = Sigma (EnumT E) (\ e -> desc I (switch E e (\ _ -> IDesc I) B) P) --**************** -- Curried and uncurried interpretations --**************** curryD : (I : Set)(D : IDesc I)(P : I -> Set)(R : desc I D P -> Set) -> Set curryD I (iat i) P R = (x : P i) -> R x curryD I (ipi S T) P R = (f : (s : S) -> desc I (T s) P) -> R f curryD I (isigma S T) P R = (s : S) -> curryD I (T s) P (\ d -> R (s , d)) curryD I (iprf Q) P R = (x : Prf Q) -> R x curryD I (iprod D D') P R = curryD I D P (\ d -> curryD I D' P (\ d' -> R (d , d'))) curryD I (ifsigma E B) P R = Branches E (\e -> curryD I (switch E e (\_ -> IDesc I) B) P (\d -> R (e , d))) uncurryD : (I : Set)(D : IDesc I)(P : I -> Set)(R : desc I D P -> Set) -> curryD I D P R -> (xs : desc I D P) -> R xs uncurryD I (iat i) P R f xs = f xs uncurryD I (ipi S T) P R F f = F f uncurryD I (isigma S T) P R f (s , d) = uncurryD I (T s) P (\d -> R (s , d)) (f s) d uncurryD I (iprf Q) P R f q = f q uncurryD I (iprod D D') P R f (d , d') = uncurryD I D' P ((\ d' → R (d , d'))) (uncurryD I D P ((\ x → curryD I D' P (\ d0 → R (x , d0)))) f d) d' uncurryD I (ifsigma E B) P R br (e , d) = uncurryD I (switch E e (\ _ -> IDesc I) B) P (\ d -> R ( e , d )) (switch E e ( \ e -> R ( e , d)) br) d --**************** -- Everywhere --**************** box : (I : Set)(D : IDesc I)(P : I -> Set) -> desc I D P -> IDesc (Sigma I P) box I (iat i) P x = iat (i , x) box I (ipi S T) P f = ipi S (\ s -> box I (T s) P (f s)) box I (isigma S T) P (s , d) = box I (T s) P d box I (iprf Q) P q = iprf Trivial box I (iprod D D') P (d , d') = iprod (box I D P d) (box I D' P d') box I (ifsigma E B) P (e , d) = box I (switch E e (\ _ -> IDesc I) B) P d mapbox : (I : Set)(D : IDesc I)(Z : I -> Set)(P : Sigma I Z -> Set) -> ((x : Sigma I Z) -> P x) -> ( d : desc I D Z) -> desc (Sigma I Z) (box I D Z d) P mapbox = {!!} --**************** -- Fix-point --**************** data IMu (I : Set)(D : I -> IDesc I)(i : I) : Set where Con : desc I (D i) (\ j -> IMu I D j) -> IMu I D i --**************** -- Induction, curried --**************** inductionC : (I : Set)(D : I -> IDesc I)(i : I)(v : IMu I D i) (P : Sigma I (IMu I D) -> Set) (m : (i : I) -> curryD I (D i) (IMu I D) (\xs -> curryD (Sigma I (IMu I D)) (box I (D i) (IMu I D) xs) P (\ _ -> P (i , Con xs)))) -> P ( i , v ) inductionC I D i (Con x) P m = let t = uncurryD I (D i) (IMu I D) (\xs -> curryD (Sigma I (IMu I D)) (box I (D i) (IMu I D) xs) P (\ _ -> P (i , Con xs))) (m i) x in uncurryD (Sigma I (IMu I D)) ( box I (D i) (IMu I D) x) P (\ _ -> P ( i , Con x)) t (mapbox I ( D i) ( IMu I D) P ind x) where ind : (x' : Sigma I (IMu I D)) -> P x' ind ( i , x) = inductionC I D i x P m
algebraic-stack_agda0000_doc_12486
module Lib.Fin where open import Lib.Nat open import Lib.Bool open import Lib.Id data Fin : Nat -> Set where zero : {n : Nat} -> Fin (suc n) suc : {n : Nat} -> Fin n -> Fin (suc n) fromNat : (n : Nat) -> Fin (suc n) fromNat zero = zero fromNat (suc n) = suc (fromNat n) toNat : {n : Nat} -> Fin n -> Nat toNat zero = zero toNat (suc n) = suc (toNat n) weaken : {n : Nat} -> Fin n -> Fin (suc n) weaken zero = zero weaken (suc n) = suc (weaken n) lem-toNat-weaken : forall {n} (i : Fin n) -> toNat i ≡ toNat (weaken i) lem-toNat-weaken zero = refl lem-toNat-weaken (suc i) with toNat i | lem-toNat-weaken i ... | .(toNat (weaken i)) | refl = refl lem-toNat-fromNat : (n : Nat) -> toNat (fromNat n) ≡ n lem-toNat-fromNat zero = refl lem-toNat-fromNat (suc n) with toNat (fromNat n) | lem-toNat-fromNat n ... | .n | refl = refl finEq : {n : Nat} -> Fin n -> Fin n -> Bool finEq zero zero = true finEq zero (suc _) = false finEq (suc _) zero = false finEq (suc i) (suc j) = finEq i j -- A view telling you if a given element is the maximal one. data MaxView {n : Nat} : Fin (suc n) -> Set where theMax : MaxView (fromNat n) notMax : (i : Fin n) -> MaxView (weaken i) maxView : {n : Nat}(i : Fin (suc n)) -> MaxView i maxView {zero} zero = theMax maxView {zero} (suc ()) maxView {suc n} zero = notMax zero maxView {suc n} (suc i) with maxView i maxView {suc n} (suc .(fromNat n)) | theMax = theMax maxView {suc n} (suc .(weaken i)) | notMax i = notMax (suc i) -- The non zero view data NonEmptyView : {n : Nat} -> Fin n -> Set where ne : {n : Nat}{i : Fin (suc n)} -> NonEmptyView i nonEmpty : {n : Nat}(i : Fin n) -> NonEmptyView i nonEmpty zero = ne nonEmpty (suc _) = ne -- The thinning view thin : {n : Nat} -> Fin (suc n) -> Fin n -> Fin (suc n) thin zero j = suc j thin (suc i) zero = zero thin (suc i) (suc j) = suc (thin i j) data EqView : {n : Nat} -> Fin n -> Fin n -> Set where equal : {n : Nat}{i : Fin n} -> EqView i i notequal : {n : Nat}{i : Fin (suc n)}(j : Fin n) -> EqView i (thin i j) compare : {n : Nat}(i j : Fin n) -> EqView i j compare zero zero = equal compare zero (suc j) = notequal j compare (suc i) zero with nonEmpty i ... | ne = notequal zero compare (suc i) (suc j) with compare i j compare (suc i) (suc .i) | equal = equal compare (suc i) (suc .(thin i j)) | notequal j = notequal (suc j)
algebraic-stack_agda0000_doc_12487
------------------------------------------------------------------------ -- Integer division ------------------------------------------------------------------------ module Data.Nat.DivMod where open import Data.Nat open import Data.Nat.Properties open SemiringSolver open import Data.Fin as Fin using (Fin; zero; suc; toℕ; fromℕ) import Data.Fin.Props as Fin open import Induction.Nat open import Relation.Nullary.Decidable open import Relation.Binary.PropositionalEquality open ≡-Reasoning open import Data.Function ------------------------------------------------------------------------ -- Some boring lemmas private lem₁ : ∀ m k → _ lem₁ m k = cong suc $ begin m ≡⟨ Fin.inject+-lemma m k ⟩ toℕ (Fin.inject+ k (fromℕ m)) ≡⟨ solve 1 (λ x → x := x :+ con 0) refl _ ⟩ toℕ (Fin.inject+ k (fromℕ m)) + 0 ∎ lem₂ : ∀ n → _ lem₂ = solve 1 (λ n → con 1 :+ n := con 1 :+ (n :+ con 0)) refl lem₃ : ∀ n k q r eq → _ lem₃ n k q r eq = begin suc n + k ≡⟨ solve 2 (λ n k → con 1 :+ n :+ k := n :+ (con 1 :+ k)) refl n k ⟩ n + suc k ≡⟨ cong (_+_ n) eq ⟩ n + (toℕ r + q * n) ≡⟨ solve 3 (λ n r q → n :+ (r :+ q :* n) := r :+ (con 1 :+ q) :* n) refl n (toℕ r) q ⟩ toℕ r + suc q * n ∎ ------------------------------------------------------------------------ -- Division -- A specification of integer division. data DivMod : ℕ → ℕ → Set where result : {divisor : ℕ} (q : ℕ) (r : Fin divisor) → DivMod (toℕ r + q * divisor) divisor -- Sometimes the following type is more usable; functions in indices -- can be inconvenient. data DivMod' (dividend divisor : ℕ) : Set where result : (q : ℕ) (r : Fin divisor) (eq : dividend ≡ toℕ r + q * divisor) → DivMod' dividend divisor -- Integer division with remainder. -- Note that Induction.Nat.<-rec is used to ensure termination of -- division. The run-time complexity of this implementation of integer -- division should be linear in the size of the dividend, assuming -- that well-founded recursion and the equality type are optimised -- properly (see "Inductive Families Need Not Store Their Indices" -- (Brady, McBride, McKinna, TYPES 2003)). _divMod'_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → DivMod' dividend divisor _divMod'_ m n {≢0} = <-rec Pred dm m n {≢0} where Pred : ℕ → Set Pred dividend = (divisor : ℕ) {≢0 : False (divisor ≟ 0)} → DivMod' dividend divisor 1+_ : ∀ {k n} → DivMod' (suc k) n → DivMod' (suc n + k) n 1+_ {k} {n} (result q r eq) = result (1 + q) r (lem₃ n k q r eq) dm : (dividend : ℕ) → <-Rec Pred dividend → Pred dividend dm m rec zero {≢0 = ()} dm zero rec (suc n) = result 0 zero refl dm (suc m) rec (suc n) with compare m n dm (suc m) rec (suc .(suc m + k)) | less .m k = result 0 r (lem₁ m k) where r = suc (Fin.inject+ k (fromℕ m)) dm (suc m) rec (suc .m) | equal .m = result 1 zero (lem₂ m) dm (suc .(suc n + k)) rec (suc n) | greater .n k = 1+ rec (suc k) le (suc n) where le = s≤′s (s≤′s (n≤′m+n n k)) -- A variant. _divMod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → DivMod dividend divisor _divMod_ m n {≢0} with _divMod'_ m n {≢0} .(toℕ r + q * n) divMod n | result q r refl = result q r -- Integer division. _div_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → ℕ _div_ m n {≢0} with _divMod_ m n {≢0} .(toℕ r + q * n) div n | result q r = q -- The remainder after integer division. _mod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → Fin divisor _mod_ m n {≢0} with _divMod_ m n {≢0} .(toℕ r + q * n) mod n | result q r = r
algebraic-stack_agda0000_doc_12488
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} -- {-# OPTIONS --without-K #-} -- [1] Hofmann, Martin and Thomas Streicher (1998). “The groupoid -- interpretation on type theory”. In: Twenty-five Years of -- Constructive Type Theory. Ed. by Giovanni Sambin and Jan -- M. Smith. Oxford University Press. Chap. 6. module UIP where data Id (A : Set)(x : A) : A → Set where refl : Id A x x K : (A : Set)(x : A)(P : Id A x x → Set) → P refl → (p : Id A x x ) → P p K A x P pr refl = pr -- From [1, p. 88]. UIP : (A : Set)(a a' : A)(p p' : Id A a a') → Id (Id A a a') p p' UIP A a .a refl refl = refl
algebraic-stack_agda0000_doc_12489
-- Jesper, 2019-05-20: When checking confluence of two rewrite rules, -- we disable all reductions during unification of the left-hand -- sides. However, we should not disable reductions at the type-level, -- as shown by this (non-confluent) example. {-# OPTIONS --rewriting --confluence-check #-} open import Agda.Builtin.Unit open import Agda.Builtin.Bool open import Agda.Builtin.Equality open import Agda.Builtin.Equality.Rewrite data Unit : Set where unit : Unit A : Unit → Set A unit = ⊤ postulate a b : (u : Unit) → A u f : (u : Unit) → A u → Bool f-a : (u : Unit) → f u (a u) ≡ true f-b : (u : Unit) → f u (b u) ≡ false {-# REWRITE f-a #-} {-# REWRITE f-b #-} cong-f : (u : Unit) (x y : A u) → x ≡ y → f u x ≡ f u y cong-f u x y refl = refl boom : true ≡ false boom = cong-f unit (a unit) (b unit) refl
algebraic-stack_agda0000_doc_12490
module UniDB.Morph.Weaken where open import UniDB.Spec -------------------------------------------------------------------------------- data Weaken : MOR where weaken : {γ : Dom} (δ : Dom) → Weaken γ (γ ∪ δ) instance iLkWeaken : {T : STX} {{vrT : Vr T}} → Lk T Weaken lk {{iLkWeaken}} (weaken δ) i = vr (wk δ i) iWkmWeaken : Wkm Weaken wkm {{iWkmWeaken}} = weaken iIdmWeaken : Idm Weaken idm {{iIdmWeaken}} γ = weaken 0 iWkWeaken : {γ₁ : Dom} → Wk (Weaken γ₁) wk₁ {{iWkWeaken}} (weaken δ) = weaken (suc δ) wk {{iWkWeaken}} zero x = x wk {{iWkWeaken}} (suc δ) x = wk₁ (wk δ x) wk-zero {{iWkWeaken}} x = refl wk-suc {{iWkWeaken}} δ x = refl iLkWkmWeaken : {T : STX} {{vrT : Vr T}} → LkWkm T Weaken lk-wkm {{iLkWkmWeaken}} δ i = refl iCompWeaken : Comp Weaken _⊙_ {{iCompWeaken}} ξ (weaken δ) = wk δ ξ wk₁-comp : {γ₁ γ₂ γ₃ : Dom} (ξ₁ : Weaken γ₁ γ₂) (ξ₂ : Weaken γ₂ γ₃) → wk₁ (ξ₁ ⊙ ξ₂) ≡ ξ₁ ⊙ wk₁ ξ₂ wk₁-comp ξ₁ (weaken δ) = refl wk-comp : {γ₁ γ₂ γ₃ : Dom} (ξ₁ : Weaken γ₁ γ₂) (ξ₂ : Weaken γ₂ γ₃) (δ : Dom) → wk δ (ξ₁ ⊙ ξ₂) ≡ ξ₁ ⊙ wk δ ξ₂ wk-comp ξ₁ ξ₂ zero = refl wk-comp ξ₁ ξ₂ (suc δ) = trans (cong wk₁ (wk-comp ξ₁ ξ₂ δ)) (wk₁-comp ξ₁ (wk δ ξ₂)) module _ (T : STX) {{vrT : Vr T}} where lk-wk₁-weaken : {{wkT : Wk T}} {{wkVrT : WkVr T}} {γ₁ γ₂ : Dom} (ξ : Weaken γ₁ γ₂) (i : Ix γ₁) → lk {T} {Weaken} (wk₁ ξ) i ≡ wk₁ (lk {T} {Weaken} ξ i) lk-wk₁-weaken (weaken δ) i = sym (wk₁-vr {T} (wk δ i)) lk-wk-weaken : {{wkT : Wk T}} {{wkVrT : WkVr T}} {γ₁ γ₂ : Dom} (δ : Dom) (ξ : Weaken γ₁ γ₂) (i : Ix γ₁) → lk {T} {Weaken} (wk δ ξ) i ≡ wk δ (lk {T} {Weaken} ξ i) lk-wk-weaken zero ξ i = sym (wk-zero (lk {T} {Weaken} ξ i)) lk-wk-weaken (suc δ) ξ i = trans (lk-wk₁-weaken (wk δ ξ) i) (trans (cong wk₁ (lk-wk-weaken δ ξ i)) (sym (wk-suc {T} δ (lk {T} {Weaken} ξ i))) ) instance iLkRenWeaken : {T : STX} {{vrT : Vr T}} → LkRen T Weaken lk-ren {{iLkRenWeaken}} (weaken δ) i = refl iLkRenCompWeaken : {T : STX} {{vrT : Vr T}} {{wkT : Wk T}} {{wkVrT : WkVr T}} → LkRenComp T Weaken lk-ren-comp {{iLkRenCompWeaken {T}}} ξ₁ (weaken δ) i = begin lk {T} {Weaken} (wk δ ξ₁) i ≡⟨ lk-wk-weaken T δ ξ₁ i ⟩ wk δ (lk {T} {Weaken} ξ₁ i) ≡⟨ cong (wk δ) (lk-ren {T} {Weaken} ξ₁ i) ⟩ wk δ (vr {T} (lk {Ix} {Weaken} ξ₁ i)) ≡⟨ wk-vr {T} δ (lk {Ix} {Weaken} ξ₁ i) ⟩ vr {T} (wk δ (lk {Ix} {Weaken} ξ₁ i)) ∎ iCompIdmWeaken : CompIdm Weaken ⊙-idm {{iCompIdmWeaken}} ξ = refl idm-⊙ {{iCompIdmWeaken}} (weaken zero) = refl idm-⊙ {{iCompIdmWeaken}} (weaken (suc δ)) = cong wk₁ (idm-⊙ {Weaken} (weaken δ)) iCompAssocWeaken : CompAssoc Weaken ⊙-assoc {{iCompAssocWeaken}} ξ₁ ξ₂ (weaken δ) = sym (wk-comp ξ₁ ξ₂ δ) --------------------------------------------------------------------------------
algebraic-stack_agda0000_doc_12491
-- Jesper, 2017-01-23: when instantiating a variable during unification, -- we should check that the type of the variable is equal to the type -- of the equation (and not just a subtype of it). See Issue 2407. open import Agda.Builtin.Equality open import Agda.Builtin.Size data D : Size → Set where J= : ∀ {ℓ} {s : Size} (x₀ : D s) → (P : (x : D s) → _≡_ {A = D s} x₀ x → Set ℓ) → P x₀ refl → (x : D s) (e : _≡_ {A = D s} x₀ x) → P x e J= _ P p _ refl = p J< : ∀ {ℓ} {s : Size} {s' : Size< s} (x₀ : D s) → (P : (x : D s) → _≡_ {A = D s} x₀ x → Set ℓ) → P x₀ refl → (x : D s') (e : _≡_ {A = D s} x₀ x) → P x e J< _ P p _ refl = p J> : ∀ {ℓ} {s : Size} {s' : Size< s} (x₀ : D s') → (P : (x : D s) → _≡_ {A = D s} x₀ x → Set ℓ) → P x₀ refl → (x : D s) (e : _≡_ {A = D s} x₀ x) → P x e J> _ P p _ refl = p J~ : ∀ {ℓ} {s : Size} {s' s'' : Size< s} (x₀ : D s') → (P : (x : D s) → _≡_ {A = D s} x₀ x → Set ℓ) → P x₀ refl → (x : D s'') (e : _≡_ {A = D s} x₀ x) → P x e J~ _ P p _ refl = p
algebraic-stack_agda0000_doc_12492
-- WARNING: This file was generated automatically by Vehicle -- and should not be modified manually! -- Metadata -- - Agda version: 2.6.2 -- - AISEC version: 0.1.0.1 -- - Time generated: ??? open import AISEC.Utils open import Data.Real as ℝ using (ℝ) open import Data.List module MyTestModule where f : Tensor ℝ (1 ∷ []) → Tensor ℝ (1 ∷ []) f = evaluate record { databasePath = DATABASE_PATH ; networkUUID = NETWORK_UUID } monotonic : ∀ (x1 : Tensor ℝ (1 ∷ [])) → ∀ (x2 : Tensor ℝ (1 ∷ [])) → let y1 = f (x1) y2 = f (x2) in x1 0 ℝ.≤ x2 0 → y1 0 ℝ.≤ y2 0 monotonic = checkProperty record { databasePath = DATABASE_PATH ; propertyUUID = ???? }
algebraic-stack_agda0000_doc_12493
module Numeral.Natural.Oper.Proofs.Structure where open import Logic.Predicate open import Numeral.Natural open import Numeral.Natural.Oper.Proofs open import Numeral.Natural.Oper open import Relator.Equals open import Relator.Equals.Proofs open import Structure.Operator.Monoid instance [+]-monoid : Monoid(_+_) Monoid.identity-existence [+]-monoid = [∃]-intro(𝟎) instance [⋅]-monoid : Monoid(_⋅_) Monoid.identity-existence [⋅]-monoid = [∃]-intro(𝐒(𝟎))
algebraic-stack_agda0000_doc_12494
{-# OPTIONS --without-K #-} module Computability.Function where open import Computability.Prelude import Function variable l₀ l₁ : Level Injective : {A : Set l₀}{B : Set l₁} → (A → B) → Set _ Injective = Function.Injective _≡_ _≡_ Surjective : {A : Set l₀}{B : Set l₁} → (A → B) → Set _ Surjective {A = A} {B = B} = Function.Surjective {A = A} {B = B} _≡_ _≡_ Bijective : {A : Set l₀}{B : Set l₁} → (A → B) → Set _ Bijective = Function.Bijective _≡_ _≡_
algebraic-stack_agda0000_doc_12495
{-# OPTIONS --safe #-} module Cubical.HITs.FreeGroup where open import Cubical.HITs.FreeGroup.Base public open import Cubical.HITs.FreeGroup.Properties public