id
stringlengths
27
136
text
stringlengths
4
1.05M
algebraic-stack_agda0000_doc_12512
------------------------------------------------------------------------ -- A large class of algebraic structures satisfies the property that -- isomorphic instances of a structure are equal (assuming univalence) ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} -- This code has been superseded by more recent developments. See -- README.agda. -- This module has been developed in collaboration with Thierry -- Coquand. open import Equality module Univalence-axiom.Isomorphism-implies-equality {reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where open import Bijection eq open Derived-definitions-and-properties eq open import Equivalence eq as Eq open import H-level eq open import H-level.Closure eq open import Logical-equivalence open import Prelude open import Univalence-axiom eq ------------------------------------------------------------------------ -- N-ary functions -- N-ary functions. _^_⟶_ : Type → ℕ → Type → Type A ^ zero ⟶ B = B A ^ suc n ⟶ B = A → A ^ n ⟶ B -- N-ary function morphisms. Is-_-ary-morphism : (n : ℕ) {A B : Type} → A ^ n ⟶ A → B ^ n ⟶ B → (A → B) → Type Is- zero -ary-morphism f₁ f₂ m = m f₁ ≡ f₂ Is- suc n -ary-morphism f₁ f₂ m = ∀ x → Is- n -ary-morphism (f₁ x) (f₂ (m x)) m abstract -- If _↔_.to m is a morphism, then _↔_.from m is also a morphism. from-also-_-ary-morphism : (n : ℕ) {A B : Type} (f₁ : A ^ n ⟶ A) (f₂ : B ^ n ⟶ B) (m : A ↔ B) → Is- n -ary-morphism f₁ f₂ (_↔_.to m) → Is- n -ary-morphism f₂ f₁ (_↔_.from m) from-also- zero -ary-morphism f₁ f₂ m is = _↔_.to-from m is from-also- suc n -ary-morphism f₁ f₂ m is = λ x → from-also- n -ary-morphism (f₁ (from x)) (f₂ x) m (subst (λ y → Is- n -ary-morphism (f₁ (from x)) (f₂ y) to) (right-inverse-of x) (is (from x))) where open _↔_ m -- Changes the type of an n-ary function. cast : {A₁ A₂ : Type} → A₁ ≃ A₂ → ∀ n → A₁ ^ n ⟶ A₁ → A₂ ^ n ⟶ A₂ cast A₁≃A₂ zero = _≃_.to A₁≃A₂ cast A₁≃A₂ (suc n) = λ f x → cast A₁≃A₂ n (f (_≃_.from A₁≃A₂ x)) abstract -- Cast simplification lemma. cast-id : {A : Type} → (∀ n → Extensionality′ A (λ _ → A ^ n ⟶ A)) → ∀ n (f : A ^ n ⟶ A) → cast Eq.id n f ≡ f cast-id ext zero f = refl f cast-id ext (suc n) f = ext n $ λ x → cast-id ext n (f x) -- We can express cast as an instance of subst (assuming -- extensionality and univalence). cast-is-subst : (∀ {A : Type} n → Extensionality′ A (λ _ → A ^ n ⟶ A)) → {A₁ A₂ : Type} (univ : Univalence′ A₁ A₂) (A₁≃A₂ : A₁ ≃ A₂) (n : ℕ) (f : A₁ ^ n ⟶ A₁) → cast A₁≃A₂ n f ≡ subst (λ C → C ^ n ⟶ C) (≃⇒≡ univ A₁≃A₂) f cast-is-subst ext univ A₁≃A₂ n = transport-theorem (λ A → A ^ n ⟶ A) (λ A≃B f → cast A≃B n f) (cast-id ext n) univ A₁≃A₂ -- If there is an isomorphism from f₁ to f₂, then the corresponding -- instance of cast maps f₁ to f₂ (assuming extensionality). cast-isomorphism : {A₁ A₂ : Type} → (∀ n → Extensionality′ A₂ (λ _ → A₂ ^ n ⟶ A₂)) → (A₁≃A₂ : A₁ ≃ A₂) (n : ℕ) (f₁ : A₁ ^ n ⟶ A₁) (f₂ : A₂ ^ n ⟶ A₂) → Is- n -ary-morphism f₁ f₂ (_≃_.to A₁≃A₂) → cast A₁≃A₂ n f₁ ≡ f₂ cast-isomorphism ext A₁≃A₂ zero f₁ f₂ is = is cast-isomorphism ext A₁≃A₂ (suc n) f₁ f₂ is = ext n $ λ x → cast A₁≃A₂ n (f₁ (from x)) ≡⟨ cast-isomorphism ext A₁≃A₂ n _ _ (is (from x)) ⟩ f₂ (to (from x)) ≡⟨ cong f₂ (right-inverse-of x) ⟩∎ f₂ x ∎ where open _≃_ A₁≃A₂ -- Combining the results above we get the following: if there is an -- isomorphism from f₁ to f₂, then the corresponding instance of -- subst maps f₁ to f₂ (assuming extensionality and univalence). subst-isomorphism : (∀ {A : Type} n → Extensionality′ A (λ _ → A ^ n ⟶ A)) → {A₁ A₂ : Type} (univ : Univalence′ A₁ A₂) (A₁≃A₂ : A₁ ≃ A₂) (n : ℕ) (f₁ : A₁ ^ n ⟶ A₁) (f₂ : A₂ ^ n ⟶ A₂) → Is- n -ary-morphism f₁ f₂ (_≃_.to A₁≃A₂) → subst (λ A → A ^ n ⟶ A) (≃⇒≡ univ A₁≃A₂) f₁ ≡ f₂ subst-isomorphism ext univ A₁≃A₂ n f₁ f₂ is = subst (λ A → A ^ n ⟶ A) (≃⇒≡ univ A₁≃A₂) f₁ ≡⟨ sym $ cast-is-subst ext univ A₁≃A₂ n f₁ ⟩ cast A₁≃A₂ n f₁ ≡⟨ cast-isomorphism ext A₁≃A₂ n f₁ f₂ is ⟩∎ f₂ ∎ ------------------------------------------------------------------------ -- A class of algebraic structures -- An algebraic structure universe. mutual -- Codes for structures. infixl 5 _+operator_ _+axiom_ data Structure : Type₁ where empty : Structure -- N-ary functions. _+operator_ : Structure → (n : ℕ) → Structure -- Arbitrary /propositional/ axioms. _+axiom_ : (s : Structure) (P : ∃ λ (P : (A : Type) → ⟦ s ⟧ A → Type) → ∀ A s → Is-proposition (P A s)) → Structure -- Interpretation of the codes. ⟦_⟧ : Structure → Type → Type₁ ⟦ empty ⟧ A = ↑ _ ⊤ ⟦ s +operator n ⟧ A = ⟦ s ⟧ A × (A ^ n ⟶ A) ⟦ s +axiom (P , P-prop) ⟧ A = Σ (⟦ s ⟧ A) (P A) -- Top-level interpretation. ⟪_⟫ : Structure → Type₁ ⟪ s ⟫ = ∃ ⟦ s ⟧ -- Morphisms. Is-structure-morphism : (s : Structure) → {A B : Type} → ⟦ s ⟧ A → ⟦ s ⟧ B → (A → B) → Type Is-structure-morphism empty _ _ m = ⊤ Is-structure-morphism (s +axiom _) (s₁ , _) (s₂ , _) m = Is-structure-morphism s s₁ s₂ m Is-structure-morphism (s +operator n) (s₁ , op₁) (s₂ , op₂) m = Is-structure-morphism s s₁ s₂ m × Is- n -ary-morphism op₁ op₂ m -- Isomorphisms. Isomorphism : (s : Structure) → ⟪ s ⟫ → ⟪ s ⟫ → Type Isomorphism s (A₁ , s₁) (A₂ , s₂) = ∃ λ (m : A₁ ↔ A₂) → Is-structure-morphism s s₁ s₂ (_↔_.to m) abstract -- If _↔_.to m is a morphism, then _↔_.from m is also a morphism. from-also-structure-morphism : (s : Structure) → {A B : Type} {s₁ : ⟦ s ⟧ A} {s₂ : ⟦ s ⟧ B} → (m : A ↔ B) → Is-structure-morphism s s₁ s₂ (_↔_.to m) → Is-structure-morphism s s₂ s₁ (_↔_.from m) from-also-structure-morphism empty m = _ from-also-structure-morphism (s +axiom _) m = from-also-structure-morphism s m from-also-structure-morphism (s +operator n) m = Σ-map (from-also-structure-morphism s m) (from-also- n -ary-morphism _ _ m) -- Isomorphic structures are equal (assuming univalence). isomorphic-equal : Univalence′ (Type ²/≡) Type → Univalence lzero → (s : Structure) (s₁ s₂ : ⟪ s ⟫) → Isomorphism s s₁ s₂ → s₁ ≡ s₂ isomorphic-equal univ₁ univ₂ s (A₁ , s₁) (A₂ , s₂) (m , is) = (A₁ , s₁) ≡⟨ Σ-≡,≡→≡ A₁≡A₂ (lemma s s₁ s₂ is) ⟩∎ (A₂ , s₂) ∎ where open _↔_ m -- Extensionality follows from univalence. ext : {A : Type} {B : A → Type} → Extensionality′ A B ext = dependent-extensionality′ univ₁ (λ _ → univ₂) -- The presence of the bijection implies that the structure's -- underlying types are equal (due to univalence). A₁≡A₂ : A₁ ≡ A₂ A₁≡A₂ = _≃_.from (≡≃≃ univ₂) $ ↔⇒≃ m -- We can lift subst-isomorphism to structures by recursion on -- structure codes. lemma : (s : Structure) (s₁ : ⟦ s ⟧ A₁) (s₂ : ⟦ s ⟧ A₂) → Is-structure-morphism s s₁ s₂ to → subst ⟦ s ⟧ A₁≡A₂ s₁ ≡ s₂ lemma empty _ _ _ = refl _ lemma (s +axiom (P , P-prop)) (s₁ , ax₁) (s₂ , ax₂) is = subst (λ A → Σ (⟦ s ⟧ A) (P A)) A₁≡A₂ (s₁ , ax₁) ≡⟨ push-subst-pair′ ⟦ s ⟧ (uncurry P) (lemma s s₁ s₂ is) ⟩ (s₂ , _) ≡⟨ cong (_,_ s₂) $ P-prop _ _ _ _ ⟩∎ (s₂ , ax₂) ∎ lemma (s +operator n) (s₁ , op₁) (s₂ , op₂) (is-s , is-o) = subst (λ A → ⟦ s ⟧ A × (A ^ n ⟶ A)) A₁≡A₂ (s₁ , op₁) ≡⟨ push-subst-pair′ ⟦ s ⟧ (λ { (A , _) → A ^ n ⟶ A }) (lemma s s₁ s₂ is-s) ⟩ (s₂ , subst₂ (λ { (A , _) → A ^ n ⟶ A }) A₁≡A₂ (lemma s s₁ s₂ is-s) op₁) ≡⟨ cong (_,_ s₂) $ subst₂-proj₁ (λ A → A ^ n ⟶ A) ⟩ (s₂ , subst (λ A → A ^ n ⟶ A) A₁≡A₂ op₁) ≡⟨ cong (_,_ s₂) $ subst-isomorphism (λ _ → ext) univ₂ (↔⇒≃ m) n op₁ op₂ is-o ⟩∎ (s₂ , op₂) ∎ ------------------------------------------------------------------------ -- Some example structures -- Example: magmas. magma : Structure magma = empty +operator 2 Magma : Type₁ Magma = ⟪ magma ⟫ private -- An unfolding of Magma. Magma-unfolded : Magma ≡ ∃ λ (A : Type) → ↑ _ ⊤ × (A → A → A) Magma-unfolded = refl _ -- Example: semigroups. The definition uses extensionality to prove -- that the axioms are propositional. Note that one axiom states that -- the underlying type is a set. This assumption is used to prove that -- the other axiom is propositional. semigroup : Extensionality lzero lzero → Structure semigroup ext = empty +axiom ( (λ A _ → Is-set A) , is-set-prop ) +operator 2 +axiom ( (λ { _ (_ , _∙_) → ∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z) }) , assoc-prop ) where is-set-prop = λ _ _ → H-level-propositional ext 2 assoc-prop = λ { _ ((_ , A-set) , _) → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → A-set } Semigroup : Extensionality lzero lzero → Type₁ Semigroup ext = ⟪ semigroup ext ⟫ private -- An unfolding of Semigroup. Semigroup-unfolded : (ext : Extensionality lzero lzero) → Semigroup ext ≡ Σ Type λ A → Σ (Σ (Σ (↑ _ ⊤) λ _ → Is-set A ) λ _ → A → A → A ) λ { (_ , _∙_) → ∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z) } Semigroup-unfolded _ = refl _ -- Example: abelian groups. abelian-group : Extensionality lzero lzero → Structure abelian-group ext = empty -- The underlying type is a set. +axiom ( (λ A _ → Is-set A) , is-set-prop ) -- The binary group operation. +operator 2 -- Commutativity. +axiom ( (λ { _ (_ , _∙_) → ∀ x y → (x ∙ y) ≡ (y ∙ x) }) , comm-prop ) -- Associativity. +axiom ( (λ { _ ((_ , _∙_) , _) → ∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z) }) , assoc-prop ) -- Identity. +operator 0 -- Left identity. +axiom ( (λ { _ ((((_ , _∙_) , _) , _) , e) → ∀ x → (e ∙ x) ≡ x }) , left-identity-prop ) -- Right identity. +axiom ( (λ { _ (((((_ , _∙_) , _) , _) , e) , _) → ∀ x → (x ∙ e) ≡ x }) , right-identity-prop ) -- Inverse. +operator 1 -- Left inverse. +axiom ( (λ { _ (((((((_ , _∙_) , _) , _) , e) , _) , _) , _⁻¹) → ∀ x → ((x ⁻¹) ∙ x) ≡ e }) , left-inverse-prop ) -- Right inverse. +axiom ( (λ { _ ((((((((_ , _∙_) , _) , _) , e) , _) , _) , _⁻¹) , _) → ∀ x → (x ∙ (x ⁻¹)) ≡ e }) , right-inverse-prop ) where is-set-prop = λ _ _ → H-level-propositional ext 2 comm-prop = λ { _ ((_ , A-set) , _) → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → A-set } assoc-prop = λ { _ (((_ , A-set) , _) , _) → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → A-set } left-identity-prop = λ { _ (((((_ , A-set) , _) , _) , _) , _) → Π-closure ext 1 λ _ → A-set } right-identity-prop = λ { _ ((((((_ , A-set) , _) , _) , _) , _) , _) → Π-closure ext 1 λ _ → A-set } left-inverse-prop = λ { _ ((((((((_ , A-set) , _) , _) , _) , _) , _) , _) , _) → Π-closure ext 1 λ _ → A-set } right-inverse-prop = λ { _ (((((((((_ , A-set) , _) , _) , _) , _) , _) , _) , _) , _) → Π-closure ext 1 λ _ → A-set } Abelian-group : Extensionality lzero lzero → Type₁ Abelian-group ext = ⟪ abelian-group ext ⟫ private -- An unfolding of Abelian-group. Note that the inner structure is -- left-nested. Abelian-group-unfolded : (ext : Extensionality lzero lzero) → Abelian-group ext ≡ Σ Type λ A → Σ (Σ (Σ (Σ (Σ (Σ (Σ (Σ (Σ (Σ (↑ _ ⊤) λ _ → Is-set A ) λ _ → A → A → A ) λ { (_ , _∙_) → ∀ x y → (x ∙ y) ≡ (y ∙ x) }) λ { ((_ , _∙_) , _) → ∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z) }) λ _ → A ) λ { ((((_ , _∙_) , _) , _) , e) → ∀ x → (e ∙ x) ≡ x }) λ { (((((_ , _∙_) , _) , _) , e) , _) → ∀ x → (x ∙ e) ≡ x }) λ _ → A → A ) λ { (((((((_ , _∙_) , _) , _) , e) , _) , _) , _⁻¹) → ∀ x → ((x ⁻¹) ∙ x) ≡ e }) λ { ((((((((_ , _∙_) , _) , _) , e) , _) , _) , _⁻¹) , _) → ∀ x → (x ∙ (x ⁻¹)) ≡ e } Abelian-group-unfolded _ = refl _ ------------------------------------------------------------------------ -- Right-nested structures -- Right-nested structures are arguably easier to define (see the -- example below). However, the following class of right-nested -- structures is in some sense different from the class above. Take -- "operator 0 f : Structureʳ Bool", for instance. The /shape/ of f op -- can vary depending on whether the operator op is true or false. -- -- One could perhaps avoid this issue by only considering values of -- type ∀ A → Structureʳ A. However, it is not obvious how to convert -- elements of this type to elements of type Structure in a -- meaning-preserving way. Furthermore it seems to be awkward to -- define things like Is-structure-isomorphism when using values of -- type ∀ A → Structureʳ A (see the definition of -- Is-structure-isomorphismʳ below). -- Codes. (Note that these structures are defined for a single -- underlying type.) data Structureʳ (A : Type) : Type₁ where empty : Structureʳ A -- N-ary functions. operator : (n : ℕ) (s : A ^ n ⟶ A → Structureʳ A) → Structureʳ A -- Arbitrary /propositional/ axioms. axiom : (P : Type) (P-prop : Is-proposition P) (s : P → Structureʳ A) → Structureʳ A -- Interpretation of the codes. ⟦_⟧ʳ : {A : Type} → Structureʳ A → Type₁ ⟦ empty ⟧ʳ = ↑ _ ⊤ ⟦ operator n s ⟧ʳ = ∃ λ op → ⟦ s op ⟧ʳ ⟦ axiom P P-prop s ⟧ʳ = ∃ λ p → ⟦ s p ⟧ʳ -- Top-level interpretation. ⟪_⟫ʳ : (∀ A → Structureʳ A) → Type₁ ⟪ s ⟫ʳ = ∃ λ A → ⟦ s A ⟧ʳ -- The property of being an isomorphism. Is-structure-isomorphismʳ : (s : ∀ A → Structureʳ A) → {A B : Type} → ⟦ s A ⟧ʳ → ⟦ s B ⟧ʳ → A ↔ B → Type Is-structure-isomorphismʳ s {A} {B} S₁ S₂ m = helper (s A) (s B) S₁ S₂ where helper : (s₁ : Structureʳ A) (s₂ : Structureʳ B) → ⟦ s₁ ⟧ʳ → ⟦ s₂ ⟧ʳ → Type helper empty empty _ _ = ⊤ helper (operator n₁ s₁) (operator n₂ s₂) (op₁ , S₁) (op₂ , S₂) = (∃ λ (eq : n₁ ≡ n₂) → Is- n₁ -ary-morphism op₁ (subst (λ n → B ^ n ⟶ B) (sym eq) op₂) (_↔_.to m)) × helper (s₁ op₁) (s₂ op₂) S₁ S₂ helper (axiom P₁ _ s₁) (axiom P₂ _ s₂) (p₁ , S₁) (p₂ , S₂) = helper (s₁ p₁) (s₂ p₂) S₁ S₂ helper empty (operator n s₂) _ _ = ⊥ helper empty (axiom P P-prop s₂) _ _ = ⊥ helper (operator n s₁) empty _ _ = ⊥ helper (operator n s₁) (axiom P P-prop s₂) _ _ = ⊥ helper (axiom P P-prop s₁) empty _ _ = ⊥ helper (axiom P P-prop s₁) (operator n s₂) _ _ = ⊥ -- Example: semigroups. semigroupʳ : Extensionality lzero lzero → ∀ A → Structureʳ A semigroupʳ ext A = axiom (Is-set A) (H-level-propositional ext 2) λ A-set → operator 2 λ _∙_ → axiom (∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z)) (Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → Π-closure ext 1 λ _ → A-set) λ _ → empty Semigroupʳ : Extensionality lzero lzero → Type₁ Semigroupʳ ext = ⟪ semigroupʳ ext ⟫ʳ private -- An unfolding of Semigroupʳ. Semigroupʳ-unfolded : (ext : Extensionality lzero lzero) → Semigroupʳ ext ≡ ∃ λ (A : Type) → ∃ λ (_ : Is-set A) → ∃ λ (_∙_ : A → A → A) → ∃ λ (_ : ∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z)) → ↑ _ ⊤ Semigroupʳ-unfolded _ = refl _
algebraic-stack_agda0000_doc_12513
{-# OPTIONS --without-K --safe #-} module Categories.Category.Construction.Properties.Kleisli where open import Level import Relation.Binary.PropositionalEquality as ≡ open import Categories.Adjoint open import Categories.Adjoint.Properties open import Categories.Category open import Categories.Functor using (Functor; _∘F_) open import Categories.Functor.Equivalence open import Categories.Monad import Categories.Morphism.Reasoning as MR open import Categories.Adjoint.Construction.Kleisli open import Categories.Category.Construction.Kleisli private variable o ℓ e : Level 𝒞 𝒟 : Category o ℓ e module _ {F : Functor 𝒞 𝒟} {G : Functor 𝒟 𝒞} (F⊣G : Adjoint F G) where private T : Monad 𝒞 T = adjoint⇒monad F⊣G 𝒞ₜ : Category _ _ _ 𝒞ₜ = Kleisli T module 𝒞 = Category 𝒞 module 𝒟 = Category 𝒟 module 𝒞ₜ = Category 𝒞ₜ module T = Monad T module F = Functor F module G = Functor G open Adjoint F⊣G -- Maclane's Comparison Functor ComparisonF : Functor 𝒞ₜ 𝒟 ComparisonF = record { F₀ = λ X → F.F₀ X ; F₁ = λ {A} {B} f → 𝒟 [ counit.η (F.F₀ B) ∘ F.F₁ f ] ; identity = zig ; homomorphism = λ {X} {Y} {Z} {f} {g} → begin 𝒟 [ counit.η (F.F₀ Z) ∘ F.F₁ (𝒞 [ 𝒞 [ G.F₁ (counit.η (F.F₀ Z)) ∘ G.F₁ (F.F₁ g)] ∘ f ])] ≈⟨ refl⟩∘⟨ F.homomorphism ⟩ 𝒟 [ counit.η (F.F₀ Z) ∘ 𝒟 [ F.F₁ (𝒞 [ G.F₁ (counit.η (F.F₀ Z)) ∘ G.F₁ (F.F₁ g) ]) ∘ F.F₁ f ] ] ≈⟨ refl⟩∘⟨ F.homomorphism ⟩∘⟨refl ⟩ 𝒟 [ counit.η (F.F₀ Z) ∘ 𝒟 [ 𝒟 [ F.F₁ (G.F₁ (counit.η (F.F₀ Z))) ∘ F.F₁ (G.F₁ (F.F₁ g)) ] ∘ F.F₁ f ] ] ≈⟨ center⁻¹ refl refl ⟩ 𝒟 [ 𝒟 [ counit.η (F.F₀ Z) ∘ F.F₁ (G.F₁ (counit.η (F.F₀ Z))) ] ∘ 𝒟 [ F.F₁ (G.F₁ (F.F₁ g)) ∘ F.F₁ f ] ] ≈⟨ counit.commute (counit.η (F.F₀ Z)) ⟩∘⟨refl ⟩ 𝒟 [ 𝒟 [ counit.η (F.F₀ Z) ∘ (counit.η (F.F₀ (G.F₀ (F.F₀ Z)))) ] ∘ 𝒟 [ F.F₁ (G.F₁ (F.F₁ g)) ∘ F.F₁ f ] ] ≈⟨ extend² (counit.commute (F.F₁ g)) ⟩ 𝒟 [ 𝒟 [ counit.η (F.F₀ Z) ∘ F.F₁ g ] ∘ 𝒟 [ counit.η (F.F₀ Y) ∘ F.F₁ f ] ] ∎ ; F-resp-≈ = λ eq → 𝒟.∘-resp-≈ʳ (F.F-resp-≈ eq) } where open 𝒟.HomReasoning open MR 𝒟 private L = ComparisonF module L = Functor L module Gₜ = Functor (Forgetful T) module Fₜ = Functor (Free T) G∘L≡Forgetful : (G ∘F L) ≡F Forgetful T G∘L≡Forgetful = record { eq₀ = λ X → ≡.refl ; eq₁ = λ {A} {B} f → begin 𝒞 [ 𝒞.id ∘ G.F₁ (𝒟 [ counit.η (F.F₀ B) ∘ F.F₁ f ]) ] ≈⟨ 𝒞.identityˡ ⟩ G.F₁ (𝒟 [ counit.η (F.F₀ B) ∘ F.F₁ f ]) ≈⟨ G.homomorphism ⟩ 𝒞 [ G.F₁ (counit.η (F.F₀ B)) ∘ G.F₁ (F.F₁ f) ] ≈˘⟨ 𝒞.identityʳ ⟩ 𝒞 [ 𝒞 [ G.F₁ (counit.η (F.F₀ B)) ∘ G.F₁ (F.F₁ f) ] ∘ 𝒞.id ] ∎ } where open 𝒞.HomReasoning L∘Free≡F : (L ∘F Free T) ≡F F L∘Free≡F = record { eq₀ = λ X → ≡.refl ; eq₁ = λ {A} {B} f → begin 𝒟 [ 𝒟.id ∘ 𝒟 [ counit.η (F.F₀ B) ∘ F.F₁ (𝒞 [ unit.η B ∘ f ]) ] ] ≈⟨ 𝒟.identityˡ ⟩ 𝒟 [ counit.η (F.F₀ B) ∘ F.F₁ (𝒞 [ unit.η B ∘ f ]) ] ≈⟨ pushʳ F.homomorphism ⟩ 𝒟 [ 𝒟 [ counit.η (F.F₀ B) ∘ F.F₁ (unit.η B) ] ∘ F.F₁ f ] ≈⟨ elimˡ zig ⟩ F.F₁ f ≈˘⟨ 𝒟.identityʳ ⟩ 𝒟 [ F.F₁ f ∘ 𝒟.id ] ∎ } where open 𝒟.HomReasoning open MR 𝒟
algebraic-stack_agda0000_doc_12514
module Issue599 where data Bool : Set where true false : Bool -- standard lambda here foo : Bool → Bool foo = ? -- pattern matching lambda here bar : Bool → Bool bar = ?
algebraic-stack_agda0000_doc_12515
------------------------------------------------------------------------ -- The halting problem ------------------------------------------------------------------------ module Halting-problem where open import Equality.Propositional.Cubical open import Logical-equivalence using (_⇔_) open import Prelude hiding (const; Decidable) open import Tactic.By.Propositional open import Univalence-axiom open import Equality.Decision-procedures equality-with-J open import Function-universe equality-with-J hiding (id; _∘_) open import H-level equality-with-J open import H-level.Closure equality-with-J open import H-level.Truncation.Propositional equality-with-paths as Trunc hiding (rec) -- To simplify the development, let's work with actual natural numbers -- as variables and constants (see -- Atom.one-can-restrict-attention-to-χ-ℕ-atoms). open import Atom open import Cancellation χ-ℕ-atoms open import Chi χ-ℕ-atoms open import Coding χ-ℕ-atoms open import Compatibility χ-ℕ-atoms open import Computability χ-ℕ-atoms hiding (_∘_) open import Constants χ-ℕ-atoms open import Deterministic χ-ℕ-atoms open import Free-variables χ-ℕ-atoms open import Propositional χ-ℕ-atoms open import Reasoning χ-ℕ-atoms open import Termination χ-ℕ-atoms open import Values χ-ℕ-atoms open χ-atoms χ-ℕ-atoms import Coding.Instances.Nat open import Combinators as χ hiding (id; if_then_else_) open import Internal-coding ------------------------------------------------------------------------ -- The extensional halting problem -- The extensional halting problem is undecidable. extensional-halting-problem : ¬ ∃ λ halts → Closed halts × ∀ p → Closed p → (Terminates p → apply halts (lambda v-underscore p) ⇓ ⌜ true ⦂ Bool ⌝) × (¬ Terminates p → apply halts (lambda v-underscore p) ⇓ ⌜ false ⦂ Bool ⌝) extensional-halting-problem (halts , cl , hyp) = contradiction where terminv : Exp → Exp terminv p = χ.if apply halts (lambda v-underscore p) then loop else ⌜ zero ⌝ terminv-lemma : ∀ {p} → Closed p → Terminates (terminv p) ⇔ ¬ Terminates p terminv-lemma {p} cl-p = record { to = to; from = from } where to : Terminates (terminv p) → ¬ Terminates p to (_ , case _ (there _ (there _ ())) _ _) p⇓ to (_ , case halts⇓false (there _ here) [] _) p⇓ = C.distinct-codes→distinct-names (λ ()) $ proj₁ $ cancel-const $ ⇓-deterministic (proj₁ (hyp p cl-p) p⇓) halts⇓false to (_ , case _ here [] loop⇓) p⇓ = ¬loop⇓ (_ , loop⇓) from : ¬ Terminates p → Terminates (terminv p) from ¬p⇓ = _ , case (proj₂ (hyp p cl-p) ¬p⇓) (there lemma here) [] (const []) where lemma = C.distinct-codes→distinct-names (λ ()) strange : Exp strange = rec v-p (terminv (var v-p)) strange-closed : Closed strange strange-closed = Closed′-closed-under-rec $ if-then-else-closed (Closed′-closed-under-apply (Closed→Closed′ cl) (Closed′-closed-under-lambda (Closed′-closed-under-var (inj₂ (inj₁ refl))))) (Closed→Closed′ loop-closed) (Closed→Closed′ $ rep-closed zero) subst-lemma : terminv (var v-p) [ v-p ← strange ] ≡ terminv strange subst-lemma = terminv (var v-p) [ v-p ← strange ] ≡⟨⟩ χ.if apply ⟨ halts [ v-p ← strange ] ⟩ (lambda v-underscore strange) then loop else ⌜ zero ⌝ ≡⟨ ⟨by⟩ (subst-closed _ _ cl) ⟩ χ.if apply halts (lambda v-underscore strange) then loop else ⌜ zero ⌝ ≡⟨⟩ terminv strange ∎ strange-lemma : Terminates strange ⇔ ¬ Terminates strange strange-lemma = Terminates strange ↝⟨ record { to = λ { (_ , rec p) → _ , p } ; from = Σ-map _ rec } ⟩ Terminates (terminv (var v-p) [ v-p ← strange ]) ↔⟨ ≡⇒↝ bijection (by subst-lemma) ⟩ Terminates (terminv strange) ↝⟨ terminv-lemma strange-closed ⟩ ¬ Terminates strange □ contradiction : ⊥ contradiction = ¬[⇔¬] strange-lemma -- A variant of the statement above. extensional-halting-problem′ : ¬ ∃ λ halts → Closed halts × ∀ p → Closed p → ∃ λ (b : Bool) → apply halts (lambda v-underscore p) ⇓ ⌜ b ⌝ × if b then Terminates p else (¬ Terminates p) extensional-halting-problem′ (halts , cl , hyp) = extensional-halting-problem ( halts , cl , λ _ cl-p → ⇓→⇓true cl-p , ¬⇓→⇓false cl-p ) where ⇓→⇓true : ∀ {p} → Closed p → Terminates p → apply halts (lambda v-underscore p) ⇓ ⌜ true ⦂ Bool ⌝ ⇓→⇓true {p} cl p⇓ with hyp p cl ... | true , halts⇓true , _ = halts⇓true ... | false , _ , ¬p⇓ = ⊥-elim (¬p⇓ p⇓) ¬⇓→⇓false : ∀ {p} → Closed p → ¬ Terminates p → apply halts (lambda v-underscore p) ⇓ ⌜ false ⦂ Bool ⌝ ¬⇓→⇓false {p} cl ¬p⇓ with hyp p cl ... | false , halts⇓false , _ = halts⇓false ... | true , _ , p⇓ = ⊥-elim (¬p⇓ p⇓) -- And another variant. extensional-halting-problem″ : ¬ ∃ λ halts → Closed halts × ∀ p → Closed p → ∥ (∃ λ (b : Bool) → apply halts (lambda v-underscore p) ⇓ ⌜ b ⌝ × if b then Terminates p else (¬ Terminates p)) ∥ extensional-halting-problem″ (halts , cl , hyp) = extensional-halting-problem ( halts , cl , λ _ cl-p → ⇓→⇓true cl-p , ¬⇓→⇓false cl-p ) where ⇓→⇓true : ∀ {p} → Closed p → Terminates p → apply halts (lambda v-underscore p) ⇓ ⌜ true ⦂ Bool ⌝ ⇓→⇓true cl p⇓ = flip (Trunc.rec ⇓-propositional) (hyp _ cl) λ where (false , _ , ¬p⇓) → ⊥-elim (¬p⇓ p⇓) (true , halts⇓true , _) → halts⇓true ¬⇓→⇓false : ∀ {p} → Closed p → ¬ Terminates p → apply halts (lambda v-underscore p) ⇓ ⌜ false ⦂ Bool ⌝ ¬⇓→⇓false cl ¬p⇓ = flip (Trunc.rec ⇓-propositional) (hyp _ cl) λ where (true , _ , p⇓) → ⊥-elim (¬p⇓ p⇓) (false , halts⇓false , _) → halts⇓false ------------------------------------------------------------------------ -- The intensional halting problem with arbitrary or non-standard -- coding relations -- A "termination inversion" function, parametrised by a solution to -- the (generalised) intensional halting problem of self application. terminv : Exp → Exp terminv halts = lambda v-x (χ.if apply halts (var v-x) then loop else ⌜ zero ⌝) -- A generalised variant of the intensional halting problem of -- self-application is not decidable. This variant replaces the coding -- function for expressions with an arbitrary relation, restricted so -- that codes have to be values. Furthermore the statement is changed -- to include the assumption that there is a code for a certain -- "strange" program. generalised-intensional-halting-problem-of-self-application : (Code : Exp → ∃ Value → Type) → ¬ ∃ λ halts → Closed halts × ∃ (Code (terminv halts)) × ∀ p c → Closed p → Code p c → let c′ = proj₁ c in (Terminates (apply p c′) → apply halts c′ ⇓ ⌜ true ⦂ Bool ⌝) × (¬ Terminates (apply p c′) → apply halts c′ ⇓ ⌜ false ⦂ Bool ⌝) generalised-intensional-halting-problem-of-self-application Code (halts , cl , (code-strange , cd) , hyp) = contradiction where terminv-lemma : ∀ p c → Closed p → Code p c → Terminates (apply (terminv halts) (proj₁ c)) ⇔ ¬ Terminates (apply p (proj₁ c)) terminv-lemma p (c , c-vl) cl-p cd-p = record { to = to; from = from } where to : Terminates (apply (terminv halts) c) → ¬ Terminates (apply p c) to (_ , apply lambda _ (case _ here [] loop⇓)) p⇓ = ¬loop⇓ (_ , loop⇓) to (_ , apply lambda _ (case _ (there _ (there _ ())) _ _)) p⇓ to (_ , apply lambda rep-p⇓ (case halts⇓false′ (there _ here) [] _)) p⇓ = C.distinct-codes→distinct-names (λ ()) $ proj₁ $ cancel-const $ ⇓-deterministic (proj₁ (hyp p (c , c-vl) cl-p cd-p) p⇓) halts⇓false where halts⇓false : apply halts c ⇓ ⌜ false ⦂ Bool ⌝ halts⇓false rewrite sym $ values-only-compute-to-themselves c-vl rep-p⇓ = subst (λ e → apply e _ ⇓ _) (subst-closed _ _ cl) halts⇓false′ from : ¬ Terminates (apply p c) → Terminates (apply (terminv halts) c) from ¬p⇓ = _ , apply lambda (values-compute-to-themselves c-vl) (case halts⇓false (there (C.distinct-codes→distinct-names (λ ())) here) [] (const [])) where halts⇓false : apply (halts [ v-x ← c ]) c ⇓ ⌜ false ⦂ Bool ⌝ halts⇓false = subst (λ e → apply e _ ⇓ _) (sym $ subst-closed _ _ cl) (proj₂ (hyp p (c , c-vl) cl-p cd-p) ¬p⇓) strange : Exp strange = apply (terminv halts) (proj₁ code-strange) terminv-closed : Closed (terminv halts) terminv-closed = Closed′-closed-under-lambda $ if-then-else-closed (Closed′-closed-under-apply (Closed→Closed′ cl) (Closed′-closed-under-var (inj₁ refl))) (Closed→Closed′ loop-closed) (Closed→Closed′ $ rep-closed zero) strange-lemma : Terminates strange ⇔ ¬ Terminates strange strange-lemma = terminv-lemma (terminv halts) code-strange terminv-closed cd contradiction : ⊥ contradiction = ¬[⇔¬] strange-lemma -- A coding relation: An expression e that terminates is encoded by -- the representation of true, and an expression e that does not -- terminate is encoded by the representation of false. ⇓-coding : Exp → ∃ Value → Type ⇓-coding e (c , _) = Terminates e × c ≡ ⌜ true ⦂ Bool ⌝ ⊎ ¬ Terminates e × c ≡ ⌜ false ⦂ Bool ⌝ -- When this coding relation is used the intensional halting problem -- with zero arguments is decidable. intensional-halting-problem₀-with-⇓-coding : ∃ λ halts → Closed halts × ∀ p (c@(c′ , _) : ∃ Value) → Closed p → ⇓-coding p c → (Terminates p → apply halts c′ ⇓ ⌜ true ⦂ Bool ⌝) × (¬ Terminates p → apply halts c′ ⇓ ⌜ false ⦂ Bool ⌝) intensional-halting-problem₀-with-⇓-coding = halts , halts-closed , halts-correct where halts : Exp halts = lambda v-p (case (var v-p) (branch c-true [] ⌜ true ⦂ Bool ⌝ ∷ branch c-false [] ⌜ false ⦂ Bool ⌝ ∷ [])) halts-closed : Closed halts halts-closed = from-⊎ (closed? halts) halts-correct : ∀ p (c@(c′ , _) : ∃ Value) → Closed p → ⇓-coding p c → (Terminates p → apply halts c′ ⇓ ⌜ true ⦂ Bool ⌝) × (¬ Terminates p → apply halts c′ ⇓ ⌜ false ⦂ Bool ⌝) halts-correct _ (.(⌜ true ⌝) , _) _ (inj₁ (p⇓ , refl)) = (λ _ → apply lambda (rep⇓rep (true ⦂ Bool)) (case (rep⇓rep (true ⦂ Bool)) here [] (rep⇓rep (true ⦂ Bool)))) , (λ ¬p⇓ → ⊥-elim (¬p⇓ p⇓)) halts-correct _ (.(⌜ false ⌝) , _) _ (inj₂ (¬p⇓ , refl)) = (λ p⇓ → ⊥-elim (¬p⇓ p⇓)) , (λ _ → apply lambda (rep⇓rep (false ⦂ Bool)) (case (rep⇓rep (false ⦂ Bool)) (there (λ ()) here) [] (rep⇓rep (false ⦂ Bool)))) ------------------------------------------------------------------------ -- The intensional halting problem -- The intensional halting problem of self-application. (This -- definition is not used below.) Intensional-halting-problem-of-self-application : Closed-exp →Bool Intensional-halting-problem-of-self-application = as-function-to-Bool₁ (λ { (e , _) → Terminates (apply e ⌜ e ⌝) }) -- The intensional halting problem of self-application is not -- decidable. intensional-halting-problem-of-self-application : ¬ ∃ λ halts → Closed halts × ∀ p → Closed p → (Terminates (apply p ⌜ p ⌝) → apply halts ⌜ p ⌝ ⇓ ⌜ true ⦂ Bool ⌝) × (¬ Terminates (apply p ⌜ p ⌝) → apply halts ⌜ p ⌝ ⇓ ⌜ false ⦂ Bool ⌝) intensional-halting-problem-of-self-application (halts , cl , hyp) = generalised-intensional-halting-problem-of-self-application ⌜⌝-Code ( halts , cl , ( ( ⌜ terminv halts ⌝ , const→value (rep-const (terminv halts)) ) , refl ) , λ { p _ cl-p refl → hyp p cl-p } ) where ⌜⌝-Code : Exp → ∃ Value → Type ⌜⌝-Code e (c , _) = ⌜ e ⌝ ≡ c -- The intensional halting problem with one argument is not decidable. intensional-halting-problem₁ : ¬ ∃ λ halts → Closed halts × ∀ p x → Closed p → Closed x → (Terminates (apply p ⌜ x ⌝) → apply halts ⌜ p , x ⌝ ⇓ ⌜ true ⦂ Bool ⌝) × (¬ Terminates (apply p ⌜ x ⌝) → apply halts ⌜ p , x ⌝ ⇓ ⌜ false ⦂ Bool ⌝) intensional-halting-problem₁ (halts , cl , hyp) = intensional-halting-problem-of-self-application ( halts′ , cl′ , λ p cl-p → Σ-map (lemma p true ∘_) (lemma p false ∘_) (hyp p p cl-p cl-p) ) where arg = const c-pair (var v-p ∷ var v-p ∷ []) halts′ = lambda v-p (apply halts arg) cl′ : Closed halts′ cl′ = Closed′-closed-under-lambda $ Closed′-closed-under-apply (Closed→Closed′ cl) (from-⊎ (closed′? arg (v-p ∷ []))) lemma : (p : Exp) (b : Bool) → apply halts ⌜ p , p ⌝ ⇓ ⌜ b ⌝ → apply halts′ ⌜ p ⌝ ⇓ ⌜ b ⌝ lemma p b halts⇓ = apply halts′ ⌜ p ⌝ ⟶⟨ apply lambda (rep⇓rep p) ⟩ apply ⟨ halts [ v-p ← ⌜ p ⌝ ] ⟩ ⌜ p , p ⌝ ≡⟨ ⟨by⟩ (subst-closed _ _ cl) ⟩⟶ apply halts ⌜ p , p ⌝ ⇓⟨ halts⇓ ⟩■ ⌜ b ⌝ -- The intensional halting problem with zero arguments is not -- decidable. intensional-halting-problem₀ : ¬ ∃ λ halts → Closed halts × ∀ p → Closed p → (Terminates p → apply halts ⌜ p ⌝ ⇓ ⌜ true ⦂ Bool ⌝) × (¬ Terminates p → apply halts ⌜ p ⌝ ⇓ ⌜ false ⦂ Bool ⌝) intensional-halting-problem₀ (halts , cl , hyp) = intensional-halting-problem-of-self-application ( halts′ , cl′ , λ p cl-p → Σ-map (lemma p true ∘_) (lemma p false ∘_) (hyp (apply p ⌜ p ⌝) (Closed′-closed-under-apply (Closed→Closed′ cl-p) (Closed→Closed′ (rep-closed p)))) ) where halts′ = lambda v-p (apply halts ( const c-apply (var v-p ∷ apply internal-code (var v-p) ∷ []))) cl′ : Closed halts′ cl′ = Closed′-closed-under-lambda $ Closed′-closed-under-apply (Closed→Closed′ cl) (Closed′-closed-under-const (λ { _ (inj₁ refl) → Closed′-closed-under-var (inj₁ refl) ; _ (inj₂ (inj₁ refl)) → Closed′-closed-under-apply (Closed→Closed′ internal-code-closed) (Closed′-closed-under-var (inj₁ refl)) ; _ (inj₂ (inj₂ ())) })) abstract lemma : (p : Exp) (b : Bool) → apply halts ⌜ Exp.apply p ⌜ p ⌝ ⌝ ⇓ ⌜ b ⌝ → apply halts′ ⌜ p ⌝ ⇓ ⌜ b ⌝ lemma p b halts⇓ = apply halts′ ⌜ p ⌝ ⟶⟨ apply lambda (rep⇓rep p) ⟩ apply ⟨ halts [ v-p ← ⌜ p ⌝ ] ⟩ (const c-apply ( ⌜ p ⌝ ∷ apply (internal-code [ v-p ← ⌜ p ⌝ ]) ⌜ p ⌝ ∷ [])) ≡⟨ ⟨by⟩ (subst-closed _ _ cl) ⟩⟶ apply halts (const c-apply ( ⌜ p ⌝ ∷ apply ⟨ internal-code [ v-p ← ⌜ p ⌝ ] ⟩ ⌜ p ⌝ ∷ [])) ≡⟨ ⟨by⟩ (subst-closed v-p ⌜ p ⌝ internal-code-closed) ⟩⟶ apply halts (const c-apply ( ⌜ p ⌝ ∷ apply internal-code ⌜ p ⌝ ∷ [])) ⟶⟨ []⇓ (apply→ ∙) (const (rep⇓rep p ∷ internal-code-correct p ∷ [])) ⟩ apply halts (const c-apply (⌜ p ⌝ ∷ ⌜ ⌜ p ⌝ ⦂ Exp ⌝ ∷ [])) ⟶⟨⟩ apply halts ⌜ Exp.apply p ⌜ p ⌝ ⌝ ⇓⟨ halts⇓ ⟩■ ⌜ b ⌝ -- Two statements of the intensional halting problem with zero -- arguments. Intensional-halting-problem₀₁ : Closed-exp →Bool Intensional-halting-problem₀₁ = as-function-to-Bool₁ (Terminates ∘ proj₁) Intensional-halting-problem₀₂ : Closed-exp →Bool Intensional-halting-problem₀₂ = as-function-to-Bool₂ (Terminates ∘ proj₁) Terminates-propositional -- The first variant is not decidable. intensional-halting-problem₀₁ : ¬ Decidable Intensional-halting-problem₀₁ intensional-halting-problem₀₁ (halts , cl , hyp , _) = intensional-halting-problem₀ ( halts , cl , λ p cl-p → (λ p⇓ → apply halts ⌜ p ⌝ ⇓⟨ hyp (p , cl-p) true ((λ _ → refl) , λ ¬p⇓ → ⊥-elim (¬p⇓ p⇓)) ⟩■ ⌜ true ⦂ Bool ⌝) , λ ¬p⇓ → apply halts ⌜ p ⌝ ⇓⟨ hyp (p , cl-p) false ((λ p⇓ → ⊥-elim (¬p⇓ p⇓)) , λ _ → refl) ⟩■ ⌜ false ⦂ Bool ⌝ ) -- The second variant is not decidable. intensional-halting-problem₀₂ : ¬ Decidable Intensional-halting-problem₀₂ intensional-halting-problem₀₂ (halts , cl , hyp , _) = intensional-halting-problem₀ ( halts , cl , λ p cl-p → (λ p⇓ → apply halts ⌜ p ⌝ ⇓⟨ hyp (p , cl-p) true (inj₁ (p⇓ , refl)) ⟩■ ⌜ true ⦂ Bool ⌝) , (λ ¬p⇓ → apply halts ⌜ p ⌝ ⇓⟨ hyp (p , cl-p) false (inj₂ (¬p⇓ , refl)) ⟩■ ⌜ false ⦂ Bool ⌝) ) -- Under the assumption of excluded middle one can prove that -- Intensional-halting-problem₀₁ and Intensional-halting-problem₀₂ are -- pointwise equal. Intensional-halting-problem₀₂→Intensional-halting-problem₀₁ : ∀ {e b} → proj₁ Intensional-halting-problem₀₂ [ e ]= b → proj₁ Intensional-halting-problem₀₁ [ e ]= b Intensional-halting-problem₀₂→Intensional-halting-problem₀₁ (inj₁ (e⇓ , refl)) = (λ _ → refl) , (⊥-elim ∘ (_$ e⇓)) Intensional-halting-problem₀₂→Intensional-halting-problem₀₁ (inj₂ (¬e⇓ , refl)) = (⊥-elim ∘ ¬e⇓) , λ _ → refl Intensional-halting-problem₀₁→Intensional-halting-problem₀₂ : (excluded-middle : (P : Type) → Is-proposition P → Dec P) → ∀ {e} b → proj₁ Intensional-halting-problem₀₁ [ e ]= b → proj₁ Intensional-halting-problem₀₂ [ e ]= b Intensional-halting-problem₀₁→Intensional-halting-problem₀₂ em = λ where true (_ , ¬¬e⇓) → inj₁ ( double-negation-elimination Terminates-propositional (Bool.true≢false ∘ ¬¬e⇓) , refl ) false (¬e⇓ , _) → inj₂ ( Bool.true≢false ∘ sym ∘ ¬e⇓ , refl ) where double-negation-elimination : {P : Type} → Is-proposition P → ¬ ¬ P → P double-negation-elimination P-prop ¬¬p = case em _ P-prop of λ where (inj₁ p) → p (inj₂ ¬p) → ⊥-elim (¬¬p ¬p) ------------------------------------------------------------------------ -- "Half of the halting problem" -- If a (correct) self-interpreter can be implemented, then "half of -- the halting problem" is computable. half-of-the-halting-problem : (eval : Exp) → Closed eval → (∀ p v → Closed p → p ⇓ v → apply eval ⌜ p ⌝ ⇓ ⌜ v ⌝) → (∀ p → Closed p → ¬ Terminates p → ¬ Terminates (apply eval ⌜ p ⌝)) → ∃ λ halts → Closed halts × ∀ p → Closed p → (Terminates p → apply halts ⌜ p ⌝ ⇓ ⌜ true ⦂ Bool ⌝) × (¬ Terminates p → ¬ Terminates (apply halts ⌜ p ⌝)) half-of-the-halting-problem eval cl eval⇓ eval¬⇓ = halts , cl′ , λ p cl-p → lemma₁ p cl-p , lemma₂ p cl-p module Half-of-the-halting-problem where halts = lambda v-p (apply (lambda v-underscore ⌜ true ⦂ Bool ⌝) (apply eval (var v-p))) cl′ : Closed halts cl′ = Closed′-closed-under-lambda $ Closed′-closed-under-apply (from-⊎ (closed′? (lambda v-underscore ⌜ true ⦂ Bool ⌝) _)) (Closed′-closed-under-apply (Closed→Closed′ cl) (Closed′-closed-under-var (inj₁ refl))) lemma₁ : ∀ p → Closed p → Terminates p → apply halts ⌜ p ⌝ ⇓ ⌜ true ⦂ Bool ⌝ lemma₁ p cl-p (v , p⇓v) = apply halts ⌜ p ⌝ ⟶⟨ apply lambda (rep⇓rep p) ⟩ apply (lambda v-underscore ⌜ true ⦂ Bool ⌝) (apply ⟨ eval [ v-p ← ⌜ p ⌝ ] ⟩ ⌜ p ⌝) ≡⟨ ⟨by⟩ (subst-closed _ _ cl) ⟩⟶ apply (lambda v-underscore ⌜ true ⦂ Bool ⌝) (apply eval ⌜ p ⌝) ⇓⟨ apply lambda (eval⇓ p v cl-p p⇓v) (rep⇓rep (true ⦂ Bool)) ⟩■ ⌜ true ⦂ Bool ⌝ halts-eval-inversion : ∀ e → Terminates (apply halts e) → Terminates (apply eval e) halts-eval-inversion e (_ , apply {v₂ = v} lambda e⇓ (apply {v₂ = v₂} _ eval⇓ _)) = _ , (apply eval e ⟶⟨ []⇓ (apply→ ∙) e⇓ ⟩ apply eval v ≡⟨ by (subst-closed _ _ cl) ⟩⟶ apply (eval [ v-p ← v ]) v ⇓⟨ eval⇓ ⟩■ v₂) lemma₂ : ∀ p → Closed p → ¬ Terminates p → ¬ Terminates (apply halts ⌜ p ⌝) lemma₂ p cl-p ¬p⇓ = Terminates (apply halts ⌜ p ⌝) ↝⟨ halts-eval-inversion ⌜ p ⌝ ⟩ Terminates (apply eval ⌜ p ⌝) ↝⟨ eval¬⇓ p cl-p ¬p⇓ ⟩□ ⊥ □ -- Two statements of "half of the halting problem". Half-of-the-halting-problem₁ : Closed-exp ⇀ Bool Half-of-the-halting-problem₁ = as-partial-function-to-Bool₁ (Terminates ∘ proj₁) Half-of-the-halting-problem₂ : Closed-exp ⇀ Bool Half-of-the-halting-problem₂ = as-partial-function-to-Bool₂ (Terminates ∘ proj₁) Terminates-propositional -- If a (correct) self-interpreter can be implemented, then -- Half-of-the-halting-problem₂ is computable. half-of-the-halting-problem₂ : (eval : Exp) → Closed eval → (∀ p v → Closed p → p ⇓ v → apply eval ⌜ p ⌝ ⇓ ⌜ v ⌝) → (∀ p v → Closed p → apply eval ⌜ p ⌝ ⇓ v → ∃ λ v′ → p ⇓ v′ × v ≡ ⌜ v′ ⌝) → Computable Half-of-the-halting-problem₂ half-of-the-halting-problem₂ eval cl eval₁ eval₂ = H.halts , H.cl′ , (λ { (p , cl-p) .true (p⇓ , refl) → H.lemma₁ p cl-p p⇓ }) , (λ { (p , cl-p) v halts⌜p⌝⇓v → true , Σ-map (_, refl) id (lemma₂ p v cl-p halts⌜p⌝⇓v) }) where eval-inversion : ∀ p → Closed p → Terminates (apply eval ⌜ p ⌝) → Terminates p eval-inversion p cl-p = Σ-map id proj₁ ∘ eval₂ p _ cl-p ∘ proj₂ module H = Half-of-the-halting-problem eval cl eval₁ (λ { p cl-p ¬p⇓ → Terminates (apply eval ⌜ p ⌝) ↝⟨ eval-inversion p cl-p ⟩ Terminates p ↝⟨ ¬p⇓ ⟩□ ⊥ □ }) lemma₂ : ∀ p v → Closed p → apply H.halts ⌜ p ⌝ ⇓ v → Terminates p × v ≡ ⌜ true ⦂ Bool ⌝ lemma₂ p v cl-p q@(apply lambda _ (apply lambda _ (const []))) = ( $⟨ _ , q ⟩ Terminates (apply H.halts ⌜ p ⌝) ↝⟨ H.halts-eval-inversion ⌜ p ⌝ ⟩ Terminates (apply eval ⌜ p ⌝) ↝⟨ eval-inversion p cl-p ⟩□ Terminates p □) , refl ------------------------------------------------------------------------ -- Halting with zero -- If the expression terminates with ⌜ zero ⌝ as the result, then this -- (total partial) function returns true. If the expression does not -- terminate with ⌜ zero ⌝ as the result, then the function returns -- false. Halts-with-zero : Closed-exp →Bool Halts-with-zero = as-function-to-Bool₁ (λ { (e , _) → e ⇓ ⌜ zero ⌝ }) -- Halts-with-zero is not decidable. halts-with-zero : ¬ Decidable Halts-with-zero halts-with-zero = Reduction→¬Computable→¬Computable (proj₁ Intensional-halting-problem₀₁) (proj₁ Halts-with-zero) red intensional-halting-problem₀₁ where red : Reduction (proj₁ Intensional-halting-problem₀₁) (proj₁ Halts-with-zero) red (halts-with-zero , cl , hyp₁ , hyp₂) = halts , cl-halts , hyp₁′ , hyp₂′ where argument : Closed-exp → Closed-exp argument (p , cl-p) = apply (lambda v-x (const c-zero [])) p , (Closed′-closed-under-apply (from-⊎ (closed′? (lambda v-x (const c-zero [])) [])) (Closed→Closed′ cl-p)) coded-argument : Exp → Exp coded-argument p = const c-apply ( ⌜ Exp.lambda v-x (const c-zero []) ⌝ ∷ p ∷ []) halts : Exp halts = lambda v-p (apply halts-with-zero (coded-argument (var v-p))) cl-halts : Closed halts cl-halts = Closed′-closed-under-lambda $ Closed′-closed-under-apply (Closed→Closed′ cl) (Closed′-closed-under-const λ where _ (inj₁ refl) → Closed→Closed′ $ rep-closed (Exp.lambda v-x (const c-zero [])) _ (inj₂ (inj₁ refl)) → Closed′-closed-under-var (inj₁ refl) _ (inj₂ (inj₂ ()))) lemma₁ : ∀ p b → proj₁ Intensional-halting-problem₀₁ [ p ]= b → proj₁ Halts-with-zero [ argument p ]= b lemma₁ p true (_ , ¬¬p⇓) = (λ _ → refl) , λ ¬arg-p⇓zero → ¬¬p⇓ λ p⇓ → ¬arg-p⇓zero (proj₁ (argument p) ⇓⟨ apply lambda (proj₂ p⇓) (const []) ⟩■ const c-zero []) lemma₁ p false (¬p⇓ , _) = (λ { (apply _ p⇓ _) → ¬p⇓ (_ , p⇓) }) , λ _ → refl hyp₁′ : ∀ p b → proj₁ Intensional-halting-problem₀₁ [ p ]= b → apply halts ⌜ p ⌝ ⇓ ⌜ b ⌝ hyp₁′ p b halts[p]=b = apply halts ⌜ p ⌝ ⟶⟨ apply lambda (rep⇓rep p) ⟩ apply ⟨ halts-with-zero [ v-p ← ⌜ p ⌝ ] ⟩ (coded-argument ⌜ p ⌝) ≡⟨ ⟨by⟩ (subst-closed _ _ cl) ⟩⟶ apply halts-with-zero (coded-argument ⌜ p ⌝) ⟶⟨⟩ apply halts-with-zero ⌜ argument p ⌝ ⇓⟨ hyp₁ (argument p) b (lemma₁ p _ halts[p]=b) ⟩■ ⌜ b ⌝ pattern coded-argument-⇓ p = const (const (const (const (const (const [] ∷ []) ∷ []) ∷ []) ∷ const (const [] ∷ const [] ∷ []) ∷ []) ∷ p ∷ []) lemma₂ : ∀ p v → apply halts ⌜ p ⌝ ⇓ v → apply halts-with-zero ⌜ argument p ⌝ ⇓ v lemma₂ p v (apply {v₂ = v₂} lambda q r) = apply ⟨ halts-with-zero ⟩ ⌜ argument p ⌝ ≡⟨ ⟨by⟩ (subst-closed _ _ cl) ⟩⟶ apply (halts-with-zero [ v-p ← v₂ ]) (coded-argument ⌜ p ⌝) ⟶⟨ []⇓ (apply→ ∙) (coded-argument-⇓ q) ⟩ apply (halts-with-zero [ v-p ← v₂ ]) (coded-argument v₂) ⇓⟨ r ⟩■ v hyp₂′ : ∀ p v → apply halts ⌜ p ⌝ ⇓ v → ∃ λ v′ → proj₁ Intensional-halting-problem₀₁ [ p ]= v′ × v ≡ ⌜ v′ ⌝ hyp₂′ p v q = Σ-map id (Σ-map (Σ-map (_∘ λ p⇓ → apply lambda (proj₂ p⇓) (const [])) (_∘ λ ¬p⇓ → λ { (apply lambda p⇓ (const [])) → ¬p⇓ (_ , p⇓) })) id) $ hyp₂ (argument p) v (lemma₂ p v q)
algebraic-stack_agda0000_doc_12516
module IrrelevantLambda where postulate A : Set P : .A -> Set f : ._ -> Set f = λ .x -> P x f' = λ .(x : _) -> P x f'' = λ .{x y z : _} -> P x g : ((.A -> Set) -> Set) -> Set g k = k f
algebraic-stack_agda0000_doc_12517
module Golden.InsertionSort where open import Agda.Builtin.Nat open import Agda.Builtin.List open import Agda.Builtin.Bool insert : Nat -> List Nat -> List Nat insert a [] = a ∷ [] insert x (a ∷ b) with x < a ... | true = x ∷ a ∷ b ... | false = a ∷ (insert x b) foldr : ∀ {a b : Set} → (a → b → b) → b → List a -> b foldr f ini [] = ini foldr f ini (x ∷ l) = f x (foldr f ini l) insertSort : List Nat -> List Nat insertSort = foldr insert [] atDef : ∀ {a : Set} → a → List a -> Nat -> a atDef def (x ∷ l) zero = x atDef def (x ∷ l) (suc ix) = atDef def l ix atDef def _ _ = def lst : List Nat lst = 4 ∷ 2 ∷ 7 ∷ [] slst : List Nat slst = insertSort lst l0 : Nat l0 = atDef 0 slst 0 l1 : Nat l1 = atDef 0 slst 1 l2 : Nat l2 = atDef 0 slst 2
algebraic-stack_agda0000_doc_12518
------------------------------------------------------------------------ -- The Agda standard library -- -- Universe levels ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Level where -- Levels. open import Agda.Primitive as Prim public using (Level; _⊔_) renaming (lzero to zero; lsuc to suc) -- Lifting. record Lift {a} ℓ (A : Set a) : Set (a ⊔ ℓ) where constructor lift field lower : A open Lift public -- Synonyms 0ℓ : Level 0ℓ = zero
algebraic-stack_agda0000_doc_12519
{-# OPTIONS --safe #-} module Cubical.Algebra.MonoidSolver.Solver where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Structure open import Cubical.Data.FinData using (Fin) open import Cubical.Data.Nat using (ℕ) open import Cubical.Data.List open import Cubical.Data.Vec using (Vec; lookup) open import Cubical.Algebra.Monoid open import Cubical.Algebra.MonoidSolver.MonoidExpression private variable ℓ : Level module Eval (M : Monoid ℓ) where open MonoidStr (snd M) Env : ℕ → Type ℓ Env n = Vec ⟨ M ⟩ n -- evaluation of an expression (without normalization) ⟦_⟧ : ∀{n} → Expr ⟨ M ⟩ n → Env n → ⟨ M ⟩ ⟦ ε⊗ ⟧ v = ε ⟦ ∣ i ⟧ v = lookup i v ⟦ e₁ ⊗ e₂ ⟧ v = ⟦ e₁ ⟧ v · ⟦ e₂ ⟧ v NormalForm : ℕ → Type _ NormalForm n = List (Fin n) -- normalization of an expression normalize : ∀{n} → Expr ⟨ M ⟩ n → NormalForm n normalize (∣ i) = i ∷ [] normalize ε⊗ = [] normalize (e₁ ⊗ e₂) = (normalize e₁) ++ (normalize e₂) -- evaluation of normalform eval : ∀ {n} → NormalForm n → Env n → ⟨ M ⟩ eval [] v = ε eval (x ∷ xs) v = (lookup x v) · (eval xs v) -- some calculation evalIsHom : ∀ {n} (x y : NormalForm n) (v : Env n) → eval (x ++ y) v ≡ eval x v · eval y v evalIsHom [] y v = sym (·IdL _) evalIsHom (x ∷ xs) y v = cong (λ m → (lookup x v) · m) (evalIsHom xs y v) ∙ ·Assoc _ _ _ module EqualityToNormalform (M : Monoid ℓ) where open Eval M open MonoidStr (snd M) -- proof that evaluation of an expression is invariant under normalization isEqualToNormalform : (n : ℕ) → (e : Expr ⟨ M ⟩ n) → (v : Env n) → eval (normalize e) v ≡ ⟦ e ⟧ v isEqualToNormalform n (∣ i) v = ·IdR _ isEqualToNormalform n ε⊗ v = refl isEqualToNormalform n (e₁ ⊗ e₂) v = eval ((normalize e₁) ++ (normalize e₂)) v ≡⟨ evalIsHom (normalize e₁) (normalize e₂) v ⟩ (eval (normalize e₁) v) · (eval (normalize e₂) v) ≡⟨ cong₂ _·_ (isEqualToNormalform n e₁ v) (isEqualToNormalform n e₂ v) ⟩ ⟦ e₁ ⟧ v · ⟦ e₂ ⟧ v ∎ solve : {n : ℕ} → (e₁ e₂ : Expr ⟨ M ⟩ n) → (v : Env n) → (p : eval (normalize e₁) v ≡ eval (normalize e₂) v) → ⟦ e₁ ⟧ v ≡ ⟦ e₂ ⟧ v solve e₁ e₂ v p = ⟦ e₁ ⟧ v ≡⟨ sym (isEqualToNormalform _ e₁ v) ⟩ eval (normalize e₁) v ≡⟨ p ⟩ eval (normalize e₂) v ≡⟨ isEqualToNormalform _ e₂ v ⟩ ⟦ e₂ ⟧ v ∎ solve : (M : Monoid ℓ) {n : ℕ} (e₁ e₂ : Expr ⟨ M ⟩ n) (v : Eval.Env M n) (p : Eval.eval M (Eval.normalize M e₁) v ≡ Eval.eval M (Eval.normalize M e₂) v) → _ solve M = EqualityToNormalform.solve M
algebraic-stack_agda0000_doc_12520
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Homotopy.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv.Properties private variable ℓ ℓ' : Level _∼_ : {X : Type ℓ} {Y : X → Type ℓ'} → (f g : (x : X) → Y x) → Type (ℓ-max ℓ ℓ') _∼_ {X = X} f g = (x : X) → f x ≡ g x funExt∼ : {X : Type ℓ} {Y : X → Type ℓ'} {f g : (x : X) → Y x} (H : f ∼ g) → f ≡ g funExt∼ = funExt ∼-refl : {X : Type ℓ} {Y : X → Type ℓ'} {f : (x : X) → Y x} → f ∼ f ∼-refl {f = f} = λ x → refl {x = f x}
algebraic-stack_agda0000_doc_12521
{-# OPTIONS --cubical --safe --postfix-projections #-} module Categories.Exercises where open import Prelude open import Categories open Category ⦃ ... ⦄ open import Categories.Product open Product public open HasProducts ⦃ ... ⦄ public -- module _ {ℓ₁} {ℓ₂} ⦃ c : Category ℓ₁ ℓ₂ ⦄ ⦃ hp : HasProducts c ⦄ where -- ex17 : (t : Terminal) (x : Ob) → Product.obj (product (fst t) x) ≅ x -- ex17 t x .fst = proj₂ (product (fst t) x) -- ex17 t x .snd .fst = ump (product (fst t) x) (t .snd .fst) Id .fst -- ex17 t x .snd .snd .fst = let p = ump (product (fst t) x) (t .snd .fst) Id .snd .snd ({!!} , {!!}) in {!!} -- ex17 t x .snd .snd .snd = {!!}
algebraic-stack_agda0000_doc_12522
{-# OPTIONS --safe --warning=error --without-K #-} open import LogicalFormulae open import Numbers.Naturals.Semiring open import Numbers.Naturals.Multiplication open import Semirings.Definition open import Rings.Definition open import Setoids.Setoids module Numbers.Integers.RingStructure.Ring where open import Numbers.Integers.Definition public open import Numbers.Integers.Addition public open import Numbers.Integers.Multiplication public *ZCommutative : (a b : ℤ) → a *Z b ≡ b *Z a *ZCommutative (nonneg x) (nonneg y) = applyEquality nonneg (multiplicationNIsCommutative x y) *ZCommutative (nonneg zero) (negSucc y) = refl *ZCommutative (nonneg (succ x)) (negSucc y) = refl *ZCommutative (negSucc x) (nonneg zero) = refl *ZCommutative (negSucc x) (nonneg (succ y)) = refl *ZCommutative (negSucc x) (negSucc y) = applyEquality nonneg (multiplicationNIsCommutative (succ x) (succ y)) *ZleftIdent : (a : ℤ) → (nonneg 1) *Z a ≡ a *ZleftIdent (nonneg x) = applyEquality nonneg (Semiring.commutative ℕSemiring x 0) *ZleftIdent (negSucc x) = applyEquality negSucc (transitivity (Semiring.commutative ℕSemiring (x +N 0) 0) (Semiring.commutative ℕSemiring x 0)) *ZrightIdent : (a : ℤ) → a *Z (nonneg 1) ≡ a *ZrightIdent (nonneg x) = applyEquality nonneg (Semiring.productOneRight ℕSemiring x) *ZrightIdent (negSucc x) = applyEquality negSucc (transitivity (Semiring.commutative ℕSemiring (x +N 0) 0) (Semiring.commutative ℕSemiring x 0)) *ZZeroLeft : (a : ℤ) → nonneg 0 *Z a ≡ nonneg 0 *ZZeroLeft (nonneg x) = refl *ZZeroLeft (negSucc x) = refl *ZZeroRight : (a : ℤ) → a *Z nonneg 0 ≡ nonneg 0 *ZZeroRight (nonneg x) = applyEquality nonneg (Semiring.productZeroRight ℕSemiring x) *ZZeroRight (negSucc x) = refl *ZAssociative : (a b c : ℤ) → a *Z (b *Z c) ≡ (a *Z b) *Z c *ZAssociative (nonneg zero) b c = transitivity (*ZZeroLeft (b *Z c)) (transitivity (equalityCommutative (*ZZeroLeft c)) (applyEquality (_*Z c) (equalityCommutative (*ZZeroLeft b)))) *ZAssociative (nonneg (succ a)) (nonneg zero) c rewrite Semiring.productZeroRight ℕSemiring a | *ZZeroLeft c | Semiring.productZeroRight ℕSemiring a = refl *ZAssociative (nonneg (succ a)) (nonneg (succ b)) (nonneg zero) rewrite Semiring.productZeroRight ℕSemiring b | Semiring.productZeroRight ℕSemiring (b +N a *N succ b) | Semiring.productZeroRight ℕSemiring a = refl *ZAssociative (nonneg (succ a)) (nonneg (succ b)) (nonneg (succ c)) = applyEquality nonneg (Semiring.*Associative ℕSemiring (succ a) (succ b) (succ c)) *ZAssociative (nonneg (succ a)) (nonneg (succ b)) (negSucc x) rewrite productDistributes' b (a *N succ b) x | Semiring.+Associative ℕSemiring x (b *N x) ((a *N succ b) *N x) | equalityCommutative (Semiring.+Associative ℕSemiring ((x +N b *N x) +N b) (a *N ((x +N b *N x) +N b)) a) | equalityCommutative (Semiring.+Associative ℕSemiring (x +N b *N x) ((a *N succ b) *N x) (b +N a *N succ b)) | equalityCommutative (Semiring.+Associative ℕSemiring (x +N b *N x) b (a *N ((x +N b *N x) +N b) +N a)) = applyEquality (λ i → negSucc ((x +N b *N x) +N i)) ans where ans3 : (succ b +N (succ b *N x)) *N a ≡ succ x *N (a *N succ b) ans3 rewrite multiplicationNIsCommutative (succ b) x = transitivity (equalityCommutative (Semiring.*Associative ℕSemiring (succ x) (succ b) a)) (applyEquality (succ x *N_) (multiplicationNIsCommutative (succ b) a)) ans2 : a *N ((x +N b *N x) +N b) +N a ≡ (a *N succ b) +N (a *N succ b) *N x ans2 rewrite multiplicationNIsCommutative (a *N succ b) x | Semiring.commutative ℕSemiring (succ b *N x) b | multiplicationNIsCommutative a (b +N (succ b *N x)) | Semiring.commutative ℕSemiring ((b +N (succ b *N x)) *N a) a = ans3 ans : b +N (a *N ((x +N b *N x) +N b) +N a) ≡ (a *N succ b) *N x +N (b +N a *N succ b) ans rewrite Semiring.commutative ℕSemiring ((a *N succ b) *N x) (b +N a *N succ b) | equalityCommutative (Semiring.+Associative ℕSemiring b (a *N succ b) ((a *N succ b) *N x)) = applyEquality (b +N_) ans2 *ZAssociative (nonneg (succ a)) (negSucc b) (nonneg zero) = applyEquality nonneg (Semiring.productZeroRight ℕSemiring a) *ZAssociative (nonneg (succ a)) (negSucc b) (nonneg (succ c)) = applyEquality negSucc ans where ans4 : (b +N b *N c) +N (a *N b +N (a *N b) *N c) ≡ (b +N a *N b) +N (b *N c +N (a *N b) *N c) ans4 rewrite Semiring.+Associative ℕSemiring (b +N b *N c) (a *N b) ((a *N b) *N c) | Semiring.+Associative ℕSemiring (b +N a *N b) (b *N c) ((a *N b) *N c) = applyEquality (_+N (a *N b) *N c) (transitivity (transitivity (applyEquality (_+N a *N b) (Semiring.commutative ℕSemiring b (b *N c))) (equalityCommutative (Semiring.+Associative ℕSemiring (b *N c) b (a *N b)))) (Semiring.commutative ℕSemiring (b *N c) (b +N a *N b))) ans3 : ((b +N b *N c) +N (a *N b +N (a *N b) *N c)) +N ((c +N a *N c) +N a) ≡ ((b +N a *N b) +N (b *N c +N (a *N b) *N c)) +N ((a +N a *N c) +N c) ans3 rewrite Semiring.commutative ℕSemiring (c +N a *N c) a | Semiring.commutative ℕSemiring c (a *N c) | Semiring.+Associative ℕSemiring a (a *N c) c = applyEquality (λ i → i +N ((a +N a *N c) +N c)) {(b +N b *N c) +N (a *N b +N (a *N b) *N c)} {(b +N a *N b) +N (b *N c +N (a *N b) *N c)} ans4 ans2 : (((b +N c *N b) +N (a *N b +N a *N (c *N b))) +N (c +N a *N c)) +N a ≡ (((b +N a *N b) +N (c *N b +N c *N (a *N b))) +N (a +N c *N a)) +N c ans2 rewrite multiplicationNIsCommutative c b | multiplicationNIsCommutative c (a *N b) | Semiring.*Associative ℕSemiring a b c | multiplicationNIsCommutative c a = transitivity (equalityCommutative (Semiring.+Associative ℕSemiring ((b +N b *N c) +N (a *N b +N (a *N b) *N c)) (c +N a *N c) a)) (transitivity ans3 (Semiring.+Associative ℕSemiring ((b +N a *N b) +N (b *N c +N (a *N b) *N c)) (a +N a *N c) c)) ans : succ a *N ((succ c *N b) +N c) +N a ≡ succ c *N ((succ a *N b) +N a) +N c ans = transitivity (applyEquality (_+N a) (productDistributes (succ a) (succ c *N b) c)) (transitivity (transitivity (applyEquality (λ i → ((((b +N c *N b) +N i) +N (c +N a *N c)) +N a)) (productDistributes a b (c *N b))) (transitivity ans2 (applyEquality (λ i → (((b +N a *N b) +N i) +N (a +N c *N a)) +N c) (equalityCommutative (productDistributes c b (a *N b)))))) (applyEquality (_+N c) (equalityCommutative (productDistributes (succ c) (succ a *N b) a)))) *ZAssociative (nonneg (succ a)) (negSucc b) (negSucc x) = applyEquality nonneg ans where ans : succ a *N (succ b *N succ x) ≡ succ ((succ a *N b) +N a) *N succ x ans rewrite Semiring.commutative ℕSemiring (succ a *N b) a | multiplicationNIsCommutative (succ a) b = transitivity (Semiring.*Associative ℕSemiring (succ a) (succ b) (succ x)) (applyEquality (_*N succ x) {succ a *N succ b} {succ b *N succ a} (multiplicationNIsCommutative (succ a) (succ b))) *ZAssociative (negSucc a) (nonneg zero) c rewrite *ZZeroLeft c = refl *ZAssociative (negSucc a) (nonneg (succ b)) (nonneg zero) rewrite multiplicationNIsCommutative b 0 = refl *ZAssociative (negSucc a) (nonneg (succ b)) (nonneg (succ c)) = applyEquality negSucc ans where ans2 : (d : ℕ) → ((succ b *N d) *N a) +N b *N d ≡ d *N ((succ b *N a) +N b) ans2 d = transitivity (transitivity (applyEquality (((d +N b *N d) *N a) +N_) (multiplicationNIsCommutative b d)) (applyEquality (_+N d *N b) (transitivity (applyEquality (_*N a) {d +N b *N d} {d *N succ b} (multiplicationNIsCommutative (succ b) d)) (equalityCommutative (Semiring.*Associative ℕSemiring d (succ b) a))))) (equalityCommutative (Semiring.+DistributesOver* ℕSemiring d (succ b *N a) b)) ans : (succ (c +N b *N succ c) *N a) +N (c +N b *N succ c) ≡ (succ c *N ((succ b *N a) +N b)) +N c ans rewrite Semiring.commutative ℕSemiring c (b *N succ c) | Semiring.+Associative ℕSemiring (succ (b *N succ c +N c) *N a) (b *N succ c) c | Semiring.commutative ℕSemiring (b *N succ c) c = applyEquality (_+N c) (ans2 (succ c)) *ZAssociative (negSucc a) (nonneg (succ b)) (negSucc c) = applyEquality nonneg ans where ans : succ a *N ((succ ((succ b) *N c)) +N b) ≡ (succ (succ b *N a) +N b) *N succ c ans rewrite Semiring.commutative ℕSemiring (succ b *N a) b | multiplicationNIsCommutative (succ b) a = transitivity (applyEquality (succ a *N_) (applyEquality succ (transitivity (equalityCommutative (Semiring.+Associative ℕSemiring c (b *N c) b)) (applyEquality (c +N_) (transitivity (transitivity (Semiring.commutative ℕSemiring (b *N c) b) (applyEquality (b +N_) (multiplicationNIsCommutative b c))) (multiplicationNIsCommutative (succ c) b)))))) (Semiring.*Associative ℕSemiring (succ a) (succ b) (succ c)) *ZAssociative (negSucc a) (negSucc b) (nonneg zero) rewrite Semiring.productZeroRight ℕSemiring (b +N a *N succ b) = refl *ZAssociative (negSucc a) (negSucc b) (nonneg (succ x)) = applyEquality nonneg (transitivity (applyEquality (succ a *N_) ans) (Semiring.*Associative ℕSemiring (succ a) (succ b) (succ x))) where ans : succ ((succ x *N b) +N x) ≡ (succ b *N succ x) ans rewrite Semiring.commutative ℕSemiring (succ x *N b) x | multiplicationNIsCommutative (succ x) b = refl *ZAssociative (negSucc a) (negSucc b) (negSucc x) = applyEquality negSucc t where l1 : (a b c d e f g : ℕ) → (a +N b) +N d ≡ e +N (f +N g) → (a +N b) +N (c +N d) ≡ (c +N e) +N (f +N g) l1 a b c d e f g pr rewrite Semiring.commutative ℕSemiring c d | Semiring.+Associative ℕSemiring (a +N b) d c | pr | Semiring.commutative ℕSemiring (e +N (f +N g)) c | Semiring.+Associative ℕSemiring c e (f +N g) = refl v : (((succ b) *N succ x) *N a) ≡ (succ x) *N (a *N succ b) v = transitivity (applyEquality (_*N a) (multiplicationNIsCommutative (succ b) (succ x))) (transitivity (equalityCommutative (Semiring.*Associative ℕSemiring (succ x) (succ b) a)) (applyEquality (succ x *N_) (multiplicationNIsCommutative (succ b) a))) u : (a +N (x +N b *N succ x) *N a) +N b *N succ x ≡ (b +N a *N succ b) *N x +N (b +N a *N succ b) u = transitivity (transitivity (transitivity (Semiring.commutative ℕSemiring (a +N (x +N b *N succ x) *N a) (b *N succ x)) (transitivity (applyEquality (_+N (a +N (x +N b *N succ x) *N a)) (multiplicationNIsCommutative b (succ x))) (transitivity (applyEquality ((b +N x *N b) +N_) v) (equalityCommutative (productDistributes (succ x) b (a *N succ b)))))) (applyEquality ((b +N a *N succ b) +N_) (multiplicationNIsCommutative x (b +N a *N succ b)))) (Semiring.commutative ℕSemiring (b +N a *N succ b) ((b +N a *N succ b) *N x)) t : (a +N (x +N b *N succ x) *N a) +N (x +N b *N succ x) ≡ (x +N (b +N a *N succ b) *N x) +N (b +N a *N succ b) t = l1 a ((x +N b *N succ x) *N a) x (b *N succ x) ((b +N (a *N succ b)) *N x) b (a *N succ b) u multLemma : (a b : ℕ) → a *N succ b ≡ a *N b +N a multLemma a b rewrite multiplicationNIsCommutative a (succ b) | Semiring.commutative ℕSemiring a (b *N a) | multiplicationNIsCommutative a b = refl negSucc+Nonneg : (a b : ℕ) → negSucc a ≡ negSucc (a +N b) +Z nonneg b negSucc+Nonneg zero zero = refl negSucc+Nonneg zero (succ b) = negSucc+Nonneg zero b negSucc+Nonneg (succ a) zero rewrite Semiring.commutative ℕSemiring a 0 = refl negSucc+Nonneg (succ a) (succ b) rewrite Semiring.commutative ℕSemiring a (succ b) | Semiring.commutative ℕSemiring b a = negSucc+Nonneg (succ a) b distLemma : (a b : ℕ) → negSucc a *Z nonneg b ≡ negSucc ((a +N b *N a) +N b) +Z nonneg (succ a) distLemma a b rewrite Semiring.commutative ℕSemiring (a +N b *N a) b | Semiring.commutative ℕSemiring a (b *N a) | Semiring.+Associative ℕSemiring b (b *N a) a = transitivity u (transitivity (equalityCommutative (+ZAssociative (negSucc ((b +N b *N a) +N a)) (nonneg a) (nonneg 1))) (applyEquality ((negSucc ((b +N b *N a) +N a)) +Z_) {nonneg a +Z nonneg 1} {nonneg (succ a)} (+ZCommutative (nonneg a) (nonneg 1)))) where v : (a b : ℕ) → negSucc a *Z nonneg b ≡ (negSucc (b +N b *N a)) +Z nonneg 1 v zero zero = refl v zero (succ b) rewrite Semiring.productZeroRight ℕSemiring b = applyEquality negSucc (equalityCommutative (Semiring.sumZeroRight ℕSemiring b)) v (succ a) zero = refl v (succ a) (succ b) = applyEquality negSucc (Semiring.commutative ℕSemiring (succ (a +N b *N succ a)) b) u : negSucc a *Z nonneg b ≡ (negSucc ((b +N b *N a) +N a) +Z nonneg a) +Z nonneg 1 u = transitivity (v a b) (applyEquality (_+Z nonneg 1) (negSucc+Nonneg (b +N b *N a) a)) *ZDistributesOver+Z : (a b c : ℤ) → a *Z (b +Z c) ≡ (a *Z b) +Z (a *Z c) *ZDistributesOver+Z (nonneg zero) b c rewrite *ZZeroLeft (b +Z c) | *ZZeroLeft b | *ZZeroLeft c = refl *ZDistributesOver+Z (nonneg (succ a)) (nonneg zero) (nonneg c) rewrite Semiring.productZeroRight ℕSemiring a = refl *ZDistributesOver+Z (nonneg (succ a)) (nonneg (succ b)) (nonneg c) = applyEquality nonneg (productDistributes (succ a) (succ b) c) *ZDistributesOver+Z (nonneg (succ a)) (nonneg zero) (negSucc c) rewrite Semiring.productZeroRight ℕSemiring a = refl *ZDistributesOver+Z (nonneg (succ a)) (nonneg (succ b)) (negSucc zero) rewrite Semiring.productZeroRight ℕSemiring a = t a where t : (a : ℕ) → nonneg (succ a *N b) ≡ nonneg (succ a *N succ b) +Z negSucc a t zero = refl t (succ a) = transitivity (+Zinherits b (b +N a *N b)) (transitivity (applyEquality (nonneg b +Z_) (t a)) (transitivity (+ZAssociative (nonneg b) (nonneg (succ (b +N a *N succ b))) (negSucc a)) (applyEquality (_+Z negSucc a) {nonneg b +Z nonneg (succ (b +N a *N succ b))} {nonneg (b +N succ (b +N a *N succ b))} (equalityCommutative (+Zinherits b _))))) *ZDistributesOver+Z (nonneg (succ a)) (nonneg (succ x)) (negSucc (succ b)) = transitivity (applyEquality ((nonneg (succ a)) *Z_) (+ZCommutative (nonneg x) (negSucc b))) (transitivity (transitivity (*ZDistributesOver+Z (nonneg (succ a)) (negSucc b) (nonneg x)) t) (+ZCommutative (negSucc ((b +N a *N succ b) +N a)) (nonneg (x +N a *N succ x)))) where t : negSucc ((b +N a *N b) +N a) +Z nonneg (x +N a *N x) ≡ negSucc ((b +N a *N succ b) +N a) +Z nonneg (x +N a *N succ x) t rewrite multLemma a x | multLemma a b | Semiring.+Associative ℕSemiring x (a *N x) a | Semiring.+Associative ℕSemiring b (a *N b) a | Semiring.commutative ℕSemiring (x +N a *N x) a | +Zinherits a (x +N a *N x) | +ZAssociative (negSucc (((b +N a *N b) +N a) +N a)) (nonneg a) (nonneg (x +N a *N x)) = applyEquality (_+Z nonneg (x +N a *N x)) {negSucc ((b +N a *N b) +N a)} {negSucc (((b +N a *N b) +N a) +N a) +Z nonneg a} (negSucc+Nonneg ((b +N a *N b) +N a) a) *ZDistributesOver+Z (nonneg (succ a)) (negSucc b) (nonneg zero) rewrite Semiring.productZeroRight ℕSemiring a = refl *ZDistributesOver+Z (nonneg (succ a)) (negSucc zero) (nonneg (succ x)) rewrite Semiring.productZeroRight ℕSemiring a = t a x where t : (a x : ℕ) → nonneg (succ a *N x) ≡ negSucc a +Z nonneg (succ a *N succ x) t zero x = refl t (succ a) x with t a x ... | bl rewrite +Zinherits x (a *N x) | +Zinherits x (x +N a *N x) = transitivity (transitivity (applyEquality (nonneg x +Z_) (+Zinherits x (a *N x))) (+ZCommutative (nonneg x) (nonneg x +Z nonneg (a *N x)))) (transitivity (applyEquality (_+Z nonneg x) bl) (transitivity (equalityCommutative (+ZAssociative (negSucc a) (nonneg (succ x +N a *N succ x)) (nonneg x))) (applyEquality (λ i → negSucc a +Z nonneg i) {succ (x +N a *N succ x) +N x} {x +N succ (x +N a *N succ x)} (Semiring.commutative ℕSemiring (succ (x +N a *N succ x)) x)))) *ZDistributesOver+Z (nonneg (succ a)) (negSucc (succ b)) (nonneg (succ x)) = transitivity (*ZDistributesOver+Z (nonneg (succ a)) (negSucc b) (nonneg x)) t where t : negSucc ((b +N a *N b) +N a) +Z nonneg (x +N a *N x) ≡ negSucc ((b +N a *N succ b) +N a) +Z nonneg (x +N a *N succ x) t rewrite multLemma a x | multLemma a b | Semiring.+Associative ℕSemiring x (a *N x) a | Semiring.+Associative ℕSemiring b (a *N b) a | Semiring.commutative ℕSemiring (x +N a *N x) a | +Zinherits a (x +N a *N x) | +ZAssociative (negSucc (((b +N a *N b) +N a) +N a)) (nonneg a) (nonneg (x +N a *N x)) = applyEquality (_+Z nonneg (x +N a *N x)) {negSucc ((b +N a *N b) +N a)} {negSucc (((b +N a *N b) +N a) +N a) +Z nonneg a} (negSucc+Nonneg ((b +N a *N b) +N a) a) *ZDistributesOver+Z (nonneg (succ a)) (negSucc b) (negSucc x) = applyEquality negSucc (transitivity (applyEquality (_+N a) (transitivity (productDistributes (succ a) (succ b) x) (applyEquality (_+N (x +N a *N x)) {succ b +N a *N succ b} {succ (b +N a *N b) +N a} (applyEquality succ u)))) (equalityCommutative (Semiring.+Associative ℕSemiring (succ ((b +N a *N b) +N a)) (succ a *N x) a))) where u : b +N a *N succ b ≡ (succ a *N b) +N a u rewrite multiplicationNIsCommutative a (succ b) | Semiring.commutative ℕSemiring a (b *N a) | multiplicationNIsCommutative b a = Semiring.+Associative ℕSemiring b (a *N b) a *ZDistributesOver+Z (negSucc a) (nonneg zero) (nonneg x) = refl *ZDistributesOver+Z (negSucc a) (nonneg zero) (negSucc x) = refl *ZDistributesOver+Z (negSucc a) (nonneg (succ b)) (nonneg zero) rewrite Semiring.commutative ℕSemiring b 0 = refl *ZDistributesOver+Z (negSucc a) (nonneg (succ b)) (nonneg (succ c)) = applyEquality negSucc t where v : a *N b +N a *N succ c ≡ c *N a +N (a +N b *N a) v rewrite multiplicationNIsCommutative b a | Semiring.+Associative ℕSemiring (c *N a) a (a *N b) | Semiring.commutative ℕSemiring (c *N a +N a) (a *N b) | Semiring.commutative ℕSemiring (c *N a) a = applyEquality (λ i → a *N b +N i) (transitivity (multLemma a c) (transitivity (Semiring.commutative ℕSemiring (a *N c) a) (applyEquality (a +N_) (multiplicationNIsCommutative a c)))) u : (a +N (b +N succ c) *N a) +N b ≡ (a +N c *N a) +N ((a +N b *N a) +N b) u rewrite Semiring.+Associative ℕSemiring (a +N c *N a) (a +N b *N a) b | (equalityCommutative (Semiring.+Associative ℕSemiring a (c *N a) (a +N b *N a))) = applyEquality (λ i → (a +N i) +N b) (transitivity (multiplicationNIsCommutative (b +N succ c) a) (transitivity (productDistributes a b (succ c)) v)) t : (a +N (b +N succ c) *N a) +N (b +N succ c) ≡ succ (((a +N b *N a) +N b) +N ((a +N c *N a) +N c)) t rewrite Semiring.+Associative ℕSemiring ((a +N (b +N succ c) *N a)) b (succ c) | Semiring.commutative ℕSemiring ((a +N b *N a) +N b) ((a +N c *N a) +N c) | Semiring.commutative ℕSemiring (a +N c *N a) c | equalityCommutative (Semiring.+Associative ℕSemiring (succ c) (a +N c *N a) ((a +N b *N a) +N b)) | Semiring.commutative ℕSemiring (succ c) ((a +N c *N a) +N ((a +N b *N a) +N b)) = applyEquality (_+N succ c) u *ZDistributesOver+Z (negSucc a) (nonneg (succ b)) (negSucc zero) rewrite Semiring.productOneRight ℕSemiring a = distLemma a b *ZDistributesOver+Z (negSucc a) (nonneg (succ b)) (negSucc (succ c)) = transitivity (*ZDistributesOver+Z (negSucc a) (nonneg b) (negSucc c)) (transitivity (applyEquality (_+Z nonneg (succ (c +N a *N succ c))) (distLemma a b)) (transitivity (equalityCommutative (+ZAssociative (negSucc ((a +N b *N a) +N b)) (nonneg (succ a)) (nonneg (succ (c +N a *N succ c))))) (applyEquality (negSucc ((a +N b *N a) +N b) +Z_) {nonneg (succ (a +N succ (c +N a *N succ c)))} {nonneg (succ (succ (c +N a *N succ (succ c))))} (applyEquality nonneg (t (succ a) (succ c)))))) where t : (x y : ℕ) → x +N x *N y ≡ x *N succ y t x y = transitivity (Semiring.commutative ℕSemiring x (x *N y)) (equalityCommutative (multLemma x y)) *ZDistributesOver+Z (negSucc a) (negSucc b) (nonneg zero) rewrite Semiring.commutative ℕSemiring (b +N a *N succ b) 0 = refl *ZDistributesOver+Z (negSucc a) (negSucc zero) (nonneg (succ b)) = transitivity (distLemma a b) (transitivity (+ZCommutative (negSucc ((a +N b *N a) +N b)) (nonneg (succ a))) (applyEquality (λ i → nonneg (succ i) +Z negSucc ((a +N b *N a) +N b)) (equalityCommutative (Semiring.productOneRight ℕSemiring a)))) *ZDistributesOver+Z (negSucc a) (negSucc (succ c)) (nonneg (succ b)) = transitivity (applyEquality (negSucc a *Z_) (+ZCommutative (negSucc c) (nonneg b))) (transitivity (transitivity (*ZDistributesOver+Z (negSucc a) (nonneg b) (negSucc c)) (transitivity (applyEquality (_+Z nonneg (succ (c +N a *N succ c))) (distLemma a b)) (transitivity (equalityCommutative (+ZAssociative (negSucc ((a +N b *N a) +N b)) (nonneg (succ a)) (nonneg (succ (c +N a *N succ c))))) (applyEquality (negSucc ((a +N b *N a) +N b) +Z_) {nonneg (succ (a +N succ (c +N a *N succ c)))} {nonneg (succ (succ (c +N a *N succ (succ c))))} (applyEquality nonneg (t (succ a) (succ c))))))) (+ZCommutative (negSucc ((a +N b *N a) +N b)) (nonneg (succ (succ (c +N a *N succ (succ c))))))) where t : (x y : ℕ) → x +N x *N y ≡ x *N succ y t x y = transitivity (Semiring.commutative ℕSemiring x (x *N y)) (equalityCommutative (multLemma x y)) *ZDistributesOver+Z (negSucc a) (negSucc b) (negSucc c) = applyEquality nonneg (transitivity (applyEquality (λ i → succ a *N (succ i)) (transitivity (applyEquality succ (Semiring.commutative ℕSemiring b c)) (Semiring.commutative ℕSemiring (succ c) b))) (productDistributes (succ a) (succ b) (succ c))) ℤRing : Ring (reflSetoid ℤ) _+Z_ _*Z_ Ring.additiveGroup ℤRing = ℤGroup Ring.*WellDefined ℤRing refl refl = refl Ring.1R ℤRing = nonneg 1 Ring.groupIsAbelian ℤRing {a} {b} = +ZCommutative a b Ring.*Associative ℤRing {a} {b} {c} = *ZAssociative a b c Ring.*Commutative ℤRing {a} {b} = *ZCommutative a b Ring.*DistributesOver+ ℤRing {a} {b} {c} = *ZDistributesOver+Z a b c Ring.identIsIdent ℤRing {a} = *ZleftIdent a
algebraic-stack_agda0000_doc_12523
module Oscar.Data.Term.Injectivity {𝔣} (FunctionName : Set 𝔣) where open import Oscar.Data.Term FunctionName open import Data.Fin open import Data.Nat open import Data.Vec open import Relation.Binary.PropositionalEquality Term-i-inj : ∀ {m} {𝑥₁ 𝑥₂ : Fin m} → i 𝑥₁ ≡ i 𝑥₂ → 𝑥₁ ≡ 𝑥₂ Term-i-inj refl = refl Term-functionName-inj : ∀ {fn₁ fn₂} {n N₁ N₂} {ts₁ : Vec (Term n) N₁} {ts₂ : Vec (Term n) N₂} → Term.function fn₁ ts₁ ≡ Term.function fn₂ ts₂ → fn₁ ≡ fn₂ Term-functionName-inj refl = refl Term-functionArity-inj : ∀ {fn₁ fn₂} {n N₁ N₂} {ts₁ : Vec (Term n) N₁} {ts₂ : Vec (Term n) N₂} → Term.function fn₁ ts₁ ≡ Term.function fn₂ ts₂ → N₁ ≡ N₂ Term-functionArity-inj refl = refl Term-functionTerms-inj : ∀ {fn₁ fn₂} {n N} {ts₁ : Vec (Term n) N} {ts₂ : Vec (Term n) N} → Term.function fn₁ ts₁ ≡ Term.function fn₂ ts₂ → ts₁ ≡ ts₂ Term-functionTerms-inj refl = refl Term-forkLeft-inj : ∀ {n} {l₁ r₁ l₂ r₂ : Term n} → l₁ fork r₁ ≡ l₂ fork r₂ → l₁ ≡ l₂ Term-forkLeft-inj refl = refl Term-forkRight-inj : ∀ {n} {l₁ r₁ l₂ r₂ : Term n} → l₁ fork r₁ ≡ l₂ fork r₂ → r₁ ≡ r₂ Term-forkRight-inj refl = refl
algebraic-stack_agda0000_doc_12524
{-# OPTIONS --without-K --exact-split --rewriting --overlapping-instances #-} open import lib.Basics open import lib.NConnected open import lib.NType2 open import lib.types.Truncation open import lib.types.Sigma open import lib.Equivalence open import lib.types.Fin open import lib.types.Coproduct open import Graphs.Definition open import Graphs.Properties open import Coequalizers.Definition open import Coequalizers.Misc open import Groups.Definition open import Coequalizers.PullbackStability open import Coequalizers.PreserveEquivalence open import Coequalizers.EdgeCoproduct open import Graphs.SpanningTreeFinite open import Graphs.SubTrees open import Util.Misc open import Util.DecEq module NielsenSchreier {i : ULevel} where {- We build towards the proof of the finite index Nielsen-Schreier theorem in several steps. -} {- We will first show that subgroups of free higher groups are free higher groupoids. That is, we will show that for any family of types X over ⊤ / A, the total space Σ (⊤ / A) X is equivalent to the coequalizer of a graph. Moveover, we can give an explicit description of the graph. -} module SubgroupsOfFreeHigherGroups (A : Type i) (X : (⊤ / A) → Type i) where instance {- Whenever we need a pair of maps (A × X fhg-base) ⇉ (X fhg-base) we will use the definition below. This applies in this module and wherever it is imported. -} higher-subgp-gph : Graph (A × X fhg-base) (X fhg-base) higher-subgp-gph = record { π₀ = snd ; π₁ = λ {(a , x) → transport X (quot a) x} } to-free-higher-gpd : Σ (⊤ / A) X ≃ (X fhg-base) / (A × X fhg-base) to-free-higher-gpd = Σ (⊤ / A) X ≃⟨ pb-equiv ⁻¹ ⟩ -- coequalizers are stable under pullback (Σ ⊤ (X ∘ c[_])) / (Σ A (X ∘ c[_] ∘ π₀)) ≃⟨ Coeq-emap Σ₁-Unit (ide _) (λ _ → idp) (λ _ → idp) ⟩ (X fhg-base) / (A × X fhg-base) ≃∎ where open PullbackStability A ⊤ X -- contains definition of (Σ ⊤ (X ∘ c[_])) / (Σ A (X ∘ c[_] ∘ π₀)) {- We now show that subgroups of free groups are free groupoids. This is a 1-truncated version of the result above. -} module SubGroupsOfFreeGroups (A : Type i) (X : ∥ ⊤ / A ∥₁ → Type i) ⦃ Xset : {z : ∥ ⊤ / A ∥₁} → is-set (X z) ⦄ where -- we now need to assume X is 0-truncated. open SubgroupsOfFreeHigherGroups A (X ∘ [_]) public -- also defines instance for (X fhg-base) / (A × X fhg-base) to-free-gpd : Σ ∥ ⊤ / A ∥₁ X ≃ ∥ X base / (A × X base) ∥₁ to-free-gpd = Σ ∥ ⊤ / A ∥₁ X ≃⟨ Σ-emap-r (Trunc-elim λ z → ide _) ⟩ Σ ∥ ⊤ / A ∥₁ X' ≃⟨ TruncRecType.flattening-Trunc _ ⟩ ∥ Σ (⊤ / A) (X ∘ [_]) ∥₁ ≃⟨ Trunc-emap to-free-higher-gpd ⟩ ∥ X base / (A × X base) ∥₁ ≃∎ where X'-set : ∥ ⊤ / A ∥₁ → hSet i X'-set = Trunc-rec (λ z → ((X [ z ]) , Xset)) X' = fst ∘ X'-set instance X-≃-gpd : {z : ∥ ⊤ / A ∥₁} → is-gpd (X z ≃ X' z) X-≃-gpd {z} = raise-level 0 (≃-level Xset (snd (X'-set z))) {- A free groupoid with vertex set a definitionally finite set is merely equivalent to a free group. -} strict-fin-free-gpd-is-free-gp : (n : ℕ) → (E : Type i) → (Edec : has-dec-eq E) → ⦃ gph : Graph E (Fin (S n)) ⦄ ⦃ conn : gph-is-connected gph ⦄ → ∥ Σ (Type i) (λ B → ∥ Coeq gph ∥₁ ≃ FreeGroup B) ∥ strict-fin-free-gpd-is-free-gp n E Edec = Trunc-fmap from-spanning-tree-fin (spanning-tree E Edec n) where from-spanning-tree-fin : SpanningTree E (Fin (S n)) (Fin n) (Fin (S n)) → Σ (Type i) (λ B → ∥ Fin (S n) / E ∥₁ ≃ FreeGroup B) from-spanning-tree-fin st = ¬E' , Trunc-emap eq where open SpanningTree st open ExtendSpanningTree E (Fin (S n)) (Fin n) (Fin (S n)) st open CoeqCoprodEquiv (Fin (S n)) (Fin n) ¬E' eq : Fin (S n) / E ≃ ⊤ / ¬E' eq = Fin (S n) / E ≃⟨ spantree-equiv ⟩ Fin (S n) / ((Fin n) ⊔ ¬E') ≃⟨ edge-coproduct-expand ⟩ (Fin (S n) / (Fin n)) / ¬E' ≃⟨ Coeq-emap (contr-equiv-Unit ⟨⟩) (ide _) (λ _ → idp) (λ _ → idp) ⟩ ⊤ / ¬E' ≃∎ {- We generalise the above so that the vertex set only needs to be equivalent to a definitionally finite set. -} fin-free-gpd-is-free-gp : (n : ℕ) → (E : Type i) → (Edec : has-dec-eq E) → (V : Type i) → (Vfin : V ≃ Fin (S n)) → ⦃ gph : Graph E V ⦄ ⦃ conn : gph-is-connected gph ⦄ → ∥ Σ (Type i) (λ B → ∥ Coeq gph ∥₁ ≃ FreeGroup B) ∥ fin-free-gpd-is-free-gp n E Edec V Vfin = Trunc-fmap (λ {(B , e) → B , (e ∘e Trunc-emap coeq-equiv)}) (strict-fin-free-gpd-is-free-gp n E Edec) where instance gph' : Graph E (Fin (S n)) gph' = record { π₀ = (–> Vfin) ∘ π₀ ; π₁ = (–> Vfin) ∘ π₁ } coeq-equiv : (V / E) ≃ (Fin (S n) / E) coeq-equiv = Coeq-emap Vfin (ide E) (λ _ → idp) λ _ → idp instance conn' : gph-is-connected gph' conn' = equiv-preserves-level (Trunc-emap coeq-equiv ) {- We can now prove the finite index version of the Nielsen-Schreier theorem. -} nielsen-schreier-finite-index : (A : Type i) (Adec : has-dec-eq A) -- we are given a type A with decidable equality (X : (FreeGroup A) → Type i) -- together with a covering space over the free group on A, that is a family of types X ... ⦃ conn : is-connected 0 (Σ (FreeGroup A) X) ⦄ -- such that the total space is connected (n : ℕ) (Xfin : X (base) ≃ Fin (S n)) → -- here we do the finite index case ∥ Σ (Type i) (λ B → Σ (FreeGroup A) X ≃ FreeGroup B) ∥ -- then the total space is a free group nielsen-schreier-finite-index A Adec X n Xfin = Trunc-fmap (λ {(B , e) → B , e ∘e to-free-gpd}) -- we compose the two equivalences from earlier (fin-free-gpd-is-free-gp n (A × X base) (×-has-dec-eq Adec (equiv-preserves-dec-eq Xfin Fin-has-dec-eq)) (X base) Xfin) -- earlier we showed that free groupoids with finite vertex set are merely equivalent to free groups where open SubGroupsOfFreeGroups A X -- contains our proof that the subgroup is a free groupoid instance -- we use that X is a set and the free groupoid is connected Xset : {z : (FreeGroup A)} → is-set (X z) Xset {z} = Trunc-elim {P = λ z → is-set (X z)} (Coeq-elim (λ z → is-set (X [ z ])) (λ {unit → equiv-preserves-level (Xfin ⁻¹) ⦃ Fin-is-set ⦄}) λ _ → prop-has-all-paths-↓) z conn2 : is-connected 0 (X base / (A × X base)) conn2 = equiv-preserves-level e where e : ∥ Σ (FreeGroup A) X ∥₀ ≃ ∥ X base / (A × X base) ∥₀ e = ∥ Σ (FreeGroup A) X ∥₀ ≃⟨ Trunc-emap (to-free-gpd ) ⟩ ∥ ∥ X base / (A × X base) ∥₁ ∥₀ ≃⟨ Trunc-fuse _ 0 1 ⟩ ∥ X base / (A × X base) ∥₀ ≃∎
algebraic-stack_agda0000_doc_12525
{-# OPTIONS --without-K #-} module TypeEquivalences where open import Data.Empty open import Data.Unit open import Data.Unit.Core open import Data.Nat renaming (_⊔_ to _⊔ℕ_) open import Data.Sum renaming (map to _⊎→_) open import Data.Product renaming (map to _×→_) open import Function renaming (_∘_ to _○_) -- explicit using to show how little of HoTT is needed open import SimpleHoTT using (refl; ap; ap2) open import Equivalences ------------------------------------------------------------------------------ -- Type Equivalences -- for each type combinator, define two functions that are inverses, and -- establish an equivalence. These are all in the 'semantic space' with -- respect to Pi combinators. -- swap₊ swap₊ : {A B : Set} → A ⊎ B → B ⊎ A swap₊ (inj₁ a) = inj₂ a swap₊ (inj₂ b) = inj₁ b swapswap₊ : {A B : Set} → swap₊ ○ swap₊ {A} {B} ∼ id swapswap₊ (inj₁ a) = refl (inj₁ a) swapswap₊ (inj₂ b) = refl (inj₂ b) swap₊equiv : {A B : Set} → (A ⊎ B) ≃ (B ⊎ A) swap₊equiv = (swap₊ , equiv₁ (mkqinv swap₊ swapswap₊ swapswap₊)) -- unite₊ and uniti₊ unite₊ : {A : Set} → ⊥ ⊎ A → A unite₊ (inj₁ ()) unite₊ (inj₂ y) = y uniti₊ : {A : Set} → A → ⊥ ⊎ A uniti₊ a = inj₂ a uniti₊∘unite₊ : {A : Set} → uniti₊ ○ unite₊ ∼ id {A = ⊥ ⊎ A} uniti₊∘unite₊ (inj₁ ()) uniti₊∘unite₊ (inj₂ y) = refl (inj₂ y) -- this is so easy, Agda can figure it out by itself (see below) unite₊∙uniti₊ : {A : Set} → unite₊ ○ uniti₊ ∼ id {A = A} unite₊∙uniti₊ = refl unite₊equiv : {A : Set} → (⊥ ⊎ A) ≃ A unite₊equiv = (unite₊ , mkisequiv uniti₊ refl uniti₊ uniti₊∘unite₊) uniti₊equiv : {A : Set} → A ≃ (⊥ ⊎ A) uniti₊equiv = uniti₊ , mkisequiv unite₊ uniti₊∘unite₊ unite₊ unite₊∙uniti₊ -- unite⋆ and uniti⋆ unite⋆ : {A : Set} → ⊤ × A → A unite⋆ (tt , x) = x uniti⋆ : {A : Set} → A → ⊤ × A uniti⋆ x = tt , x uniti⋆∘unite⋆ : {A : Set} → uniti⋆ ○ unite⋆ ∼ id {A = ⊤ × A} uniti⋆∘unite⋆ (tt , x) = refl (tt , x) unite⋆equiv : {A : Set} → (⊤ × A) ≃ A unite⋆equiv = unite⋆ , mkisequiv uniti⋆ refl uniti⋆ uniti⋆∘unite⋆ uniti⋆equiv : {A : Set} → A ≃ (⊤ × A) uniti⋆equiv = uniti⋆ , mkisequiv unite⋆ uniti⋆∘unite⋆ unite⋆ refl -- swap⋆ swap⋆ : {A B : Set} → A × B → B × A swap⋆ (a , b) = (b , a) swapswap⋆ : {A B : Set} → swap⋆ ○ swap⋆ ∼ id {A = A × B} swapswap⋆ (a , b) = refl (a , b) swap⋆equiv : {A B : Set} → (A × B) ≃ (B × A) swap⋆equiv = swap⋆ , mkisequiv swap⋆ swapswap⋆ swap⋆ swapswap⋆ -- assocl₊ and assocr₊ assocl₊ : {A B C : Set} → (A ⊎ (B ⊎ C)) → ((A ⊎ B) ⊎ C) assocl₊ (inj₁ a) = inj₁ (inj₁ a) assocl₊ (inj₂ (inj₁ b)) = inj₁ (inj₂ b) assocl₊ (inj₂ (inj₂ c)) = inj₂ c assocr₊ : {A B C : Set} → ((A ⊎ B) ⊎ C) → (A ⊎ (B ⊎ C)) assocr₊ (inj₁ (inj₁ a)) = inj₁ a assocr₊ (inj₁ (inj₂ b)) = inj₂ (inj₁ b) assocr₊ (inj₂ c) = inj₂ (inj₂ c) assocl₊∘assocr₊ : {A B C : Set} → assocl₊ ○ assocr₊ ∼ id {A = ((A ⊎ B) ⊎ C)} assocl₊∘assocr₊ (inj₁ (inj₁ a)) = refl (inj₁ (inj₁ a)) assocl₊∘assocr₊ (inj₁ (inj₂ b)) = refl (inj₁ (inj₂ b)) assocl₊∘assocr₊ (inj₂ c) = refl (inj₂ c) assocr₊∘assocl₊ : {A B C : Set} → assocr₊ ○ assocl₊ ∼ id {A = (A ⊎ (B ⊎ C))} assocr₊∘assocl₊ (inj₁ a) = refl (inj₁ a) assocr₊∘assocl₊ (inj₂ (inj₁ b)) = refl (inj₂ (inj₁ b)) assocr₊∘assocl₊ (inj₂ (inj₂ c)) = refl (inj₂ (inj₂ c)) assocl₊equiv : {A B C : Set} → (A ⊎ (B ⊎ C)) ≃ ((A ⊎ B) ⊎ C) assocl₊equiv = assocl₊ , mkisequiv assocr₊ assocl₊∘assocr₊ assocr₊ assocr₊∘assocl₊ assocr₊equiv : {A B C : Set} → ((A ⊎ B) ⊎ C) ≃ (A ⊎ (B ⊎ C)) assocr₊equiv = assocr₊ , mkisequiv assocl₊ assocr₊∘assocl₊ assocl₊ assocl₊∘assocr₊ -- assocl⋆ and assocr⋆ assocl⋆ : {A B C : Set} → (A × (B × C)) → ((A × B) × C) assocl⋆ (a , (b , c)) = ((a , b) , c) assocr⋆ : {A B C : Set} → ((A × B) × C) → (A × (B × C)) assocr⋆ ((a , b) , c) = (a , (b , c)) assocl⋆∘assocr⋆ : {A B C : Set} → assocl⋆ ○ assocr⋆ ∼ id {A = ((A × B) × C)} assocl⋆∘assocr⋆ x = refl x assocr⋆∘assocl⋆ : {A B C : Set} → assocr⋆ ○ assocl⋆ ∼ id {A = (A × (B × C))} assocr⋆∘assocl⋆ x = refl x assocl⋆equiv : {A B C : Set} → (A × (B × C)) ≃ ((A × B) × C) assocl⋆equiv = assocl⋆ , mkisequiv assocr⋆ assocl⋆∘assocr⋆ assocr⋆ assocr⋆∘assocl⋆ assocr⋆equiv : {A B C : Set} → ((A × B) × C) ≃ (A × (B × C)) assocr⋆equiv = assocr⋆ , mkisequiv assocl⋆ assocr⋆∘assocl⋆ assocl⋆ assocl⋆∘assocr⋆ -- distz and factorz distz : { A : Set} → (⊥ × A) → ⊥ distz (() , _) factorz : {A : Set} → ⊥ → (⊥ × A) factorz () distz∘factorz : {A : Set} → distz ○ factorz {A} ∼ id distz∘factorz () factorz∘distz : {A : Set} → factorz {A} ○ distz ∼ id factorz∘distz (() , proj₂) distzequiv : {A : Set} → (⊥ × A) ≃ ⊥ distzequiv {A} = distz , mkisequiv factorz (distz∘factorz {A}) factorz factorz∘distz factorzequiv : {A : Set} → ⊥ ≃ (⊥ × A) factorzequiv {A} = factorz , mkisequiv distz factorz∘distz distz (distz∘factorz {A}) -- dist and factor dist : {A B C : Set} → ((A ⊎ B) × C) → (A × C) ⊎ (B × C) dist (inj₁ x , c) = inj₁ (x , c) dist (inj₂ y , c) = inj₂ (y , c) factor : {A B C : Set} → (A × C) ⊎ (B × C) → ((A ⊎ B) × C) factor (inj₁ (a , c)) = inj₁ a , c factor (inj₂ (b , c)) = inj₂ b , c dist∘factor : {A B C : Set} → dist {A} {B} {C} ○ factor ∼ id dist∘factor (inj₁ x) = refl (inj₁ x) dist∘factor (inj₂ y) = refl (inj₂ y) factor∘dist : {A B C : Set} → factor {A} {B} {C} ○ dist ∼ id factor∘dist (inj₁ x , c) = refl (inj₁ x , c) factor∘dist (inj₂ y , c) = refl (inj₂ y , c) distequiv : {A B C : Set} → ((A ⊎ B) × C) ≃ ((A × C) ⊎ (B × C)) distequiv = dist , mkisequiv factor dist∘factor factor factor∘dist factorequiv : {A B C : Set} → ((A × C) ⊎ (B × C)) ≃ ((A ⊎ B) × C) factorequiv = factor , (mkisequiv dist factor∘dist dist dist∘factor) -- ⊕ _⊎∼_ : {A B C D : Set} {f : A → C} {finv : C → A} {g : B → D} {ginv : D → B} → (α : f ○ finv ∼ id) → (β : g ○ ginv ∼ id) → (f ⊎→ g) ○ (finv ⊎→ ginv) ∼ id {A = C ⊎ D} _⊎∼_ α β (inj₁ x) = ap inj₁ (α x) _⊎∼_ α β (inj₂ y) = ap inj₂ (β y) path⊎ : {A B C D : Set} → A ≃ C → B ≃ D → (A ⊎ B) ≃ (C ⊎ D) path⊎ (fp , eqp) (fq , eqq) = Data.Sum.map fp fq , mkisequiv (P.g ⊎→ Q.g) (P.α ⊎∼ Q.α) (P.h ⊎→ Q.h) (P.β ⊎∼ Q.β) where module P = isequiv eqp module Q = isequiv eqq -- ⊗ _×∼_ : {A B C D : Set} {f : A → C} {finv : C → A} {g : B → D} {ginv : D → B} → (α : f ○ finv ∼ id) → (β : g ○ ginv ∼ id) → (f ×→ g) ○ (finv ×→ ginv) ∼ id {A = C × D} _×∼_ α β (x , y) = ap2 _,_ (α x) (β y) path× : {A B C D : Set} → A ≃ C → B ≃ D → (A × B) ≃ (C × D) path× {A} {B} {C} {D} (fp , eqp) (fq , eqq) = Data.Product.map fp fq , mkisequiv (P.g ×→ Q.g) (_×∼_ {A} {B} {C} {D} {fp} {P.g} {fq} {Q.g} P.α Q.α) (P.h ×→ Q.h) (_×∼_ {C} {D} {A} {B} {P.h} {fp} {Q.h} {fq} P.β Q.β) where module P = isequiv eqp module Q = isequiv eqq idequiv : {A : Set} → A ≃ A idequiv = id≃
algebraic-stack_agda0000_doc_12526
{-# OPTIONS --cubical #-} module HyperPositive where open import Prelude infixr 4 _↬_ {-# NO_POSITIVITY_CHECK #-} record _↬_ (A : Type a) (B : Type b) : Type (a ℓ⊔ b) where inductive; constructor hyp field invoke : ((A ↬ B) → A) → B open _↬_ open import Data.List using (List; _∷_; []; foldr) module _ {a b} {A : Type a} {B : Type b} where XT = List (A × B) ↬ (A → List (A × B)) → List (A × B) YT = List (A × B) ↬ (A → List (A × B)) yfld : List B → YT yfld = foldr f n where f : B → YT → YT f y yk .invoke xk x = (x , y) ∷ xk yk n : YT n .invoke _ _ = [] xfld : List A → XT xfld = foldr f n where f : A → XT → XT f x xk yk = yk .invoke xk x n : XT n _ = [] zip : List A → List B → List (A × B) zip xs ys = xfld xs (yfld ys) open import Data.List using (_⋯_) open import Data.List.Syntax _ : zip (1 ⋯ 5) (11 ⋯ 15) ≡ [ 5 ][ (1 , 11) , (2 , 12) , (3 , 13) , (4 , 14) , (5 , 15) ] _ = refl
algebraic-stack_agda0000_doc_12527
open import Relation.Binary.Indexed module Relation.Binary.Indexed.EqReasoning {𝒾} {I : Set 𝒾} {𝒸 ℓ} (S : Setoid I 𝒸 ℓ) where open Setoid S import Relation.Binary.Indexed.PreorderReasoning as PreR open import Relation.Binary.Indexed.Extra using (Setoid⇒Preorder) open PreR (Setoid⇒Preorder S) public renaming ( _∼⟨_⟩_ to _≈⟨_⟩_ ; _≈⟨_⟩_ to _≡⟨_⟩_ ; _≈⟨⟩_ to _≡⟨⟩_ )
algebraic-stack_agda0000_doc_4656
module Categories.Ran where open import Level open import Categories.Category open import Categories.Functor hiding (_≡_) open import Categories.NaturalTransformation record Ran {o₀ ℓ₀ e₀} {o₁ ℓ₁ e₁} {o₂ ℓ₂ e₂} {A : Category o₀ ℓ₀ e₀} {B : Category o₁ ℓ₁ e₁} {C : Category o₂ ℓ₂ e₂} (F : Functor A B) (X : Functor A C) : Set (o₀ ⊔ ℓ₀ ⊔ e₀ ⊔ o₁ ⊔ ℓ₁ ⊔ e₁ ⊔ o₂ ⊔ ℓ₂ ⊔ e₂) where field R : Functor B C η : NaturalTransformation (R ∘ F) X δ : (M : Functor B C) → (α : NaturalTransformation (M ∘ F) X) → NaturalTransformation M R .δ-unique : {M : Functor B C} → {α : NaturalTransformation (M ∘ F) X} → (δ′ : NaturalTransformation M R) → α ≡ η ∘₁ (δ′ ∘ʳ F) → δ′ ≡ δ M α .commutes : (M : Functor B C) → (α : NaturalTransformation (M ∘ F) X) → α ≡ η ∘₁ (δ M α ∘ʳ F)
algebraic-stack_agda0000_doc_4657
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020 Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Prelude open import LibraBFT.Lemmas open import LibraBFT.Hash open import LibraBFT.Base.PKCS open import LibraBFT.Base.Encode -- This module brings in the base types used through libra -- and those necessary for the abstract model. module LibraBFT.Abstract.Types where open import LibraBFT.Base.Types public -- Simple way to flag meta-information without having it getting -- in the way. Meta : ∀{ℓ} → Set ℓ → Set ℓ Meta x = x -- An epoch-configuration carries only simple data about the epoch; the complicated -- parts will be provided by the System, defined below. -- -- The reason for the separation is that we should be able to provide -- an EpochConfig from a single peer state. record EpochConfig : Set₁ where constructor mkEpochConfig field -- TODO-2 : This should really be a UID as Hash should not show up in the Abstract -- namespace. This will require some refactoring of modules and reordering of -- module parameters. genesisUID : Hash epochId : EpochId authorsN : ℕ -- The set of members of this epoch. Member : Set Member = Fin authorsN -- There is a partial isomorphism between NodeIds and the -- authors participating in this epoch. field toNodeId : Member → NodeId isMember? : NodeId → Maybe Member nodeid-author-id : ∀{α} → isMember? (toNodeId α) ≡ just α author-nodeid-id : ∀{nid α} → isMember? nid ≡ just α → toNodeId α ≡ nid getPubKey : Member → PK PK-inj : ∀ {m1 m2} → getPubKey m1 ≡ getPubKey m2 → m1 ≡ m2 IsQuorum : List Member → Set bft-assumption : ∀ {xs ys} → IsQuorum xs → IsQuorum ys → ∃[ α ] (α ∈ xs × α ∈ ys × Meta-Honest-PK (getPubKey α)) open EpochConfig toNodeId-inj : ∀{𝓔}{x y : Member 𝓔} → toNodeId 𝓔 x ≡ toNodeId 𝓔 y → x ≡ y toNodeId-inj {𝓔} hyp = just-injective (trans (sym (nodeid-author-id 𝓔)) (trans (cong (isMember? 𝓔) hyp) (nodeid-author-id 𝓔))) record EpochConfigFor (eid : ℕ) : Set₁ where field epochConfig : EpochConfig forEpochId : epochId epochConfig ≡ eid MemberSubst : ∀ {𝓔} {𝓔'} → 𝓔' ≡ 𝓔 → EpochConfig.Member 𝓔 → EpochConfig.Member 𝓔' MemberSubst refl = id -- A member of an epoch is considered "honest" iff its public key is honest. Meta-Honest-Member : (𝓔 : EpochConfig) → Member 𝓔 → Set Meta-Honest-Member 𝓔 α = Meta-Honest-PK (getPubKey 𝓔 α) -- Naturally, if two witnesses that two authors belong -- in the epoch are the same, then the authors are also the same. -- -- This proof is very Galois-like, because of the way we structured -- our partial isos. It's actually pretty nice! :) member≡⇒author≡ : ∀{α β}{𝓔 : EpochConfig} → (authorα : Is-just (isMember? 𝓔 α)) → (authorβ : Is-just (isMember? 𝓔 β)) → to-witness authorα ≡ to-witness authorβ → α ≡ β member≡⇒author≡ {α} {β} {𝓔} a b prf with isMember? 𝓔 α | inspect (isMember? 𝓔) α ...| nothing | [ _ ] = ⊥-elim (maybe-any-⊥ a) member≡⇒author≡ {α} {β} {𝓔} (just _) b prf | just ra | [ RA ] with isMember? 𝓔 β | inspect (isMember? 𝓔) β ...| nothing | [ _ ] = ⊥-elim (maybe-any-⊥ b) member≡⇒author≡ {α} {β} {𝓔} (just _) (just _) prf | just ra | [ RA ] | just rb | [ RB ] = trans (sym (author-nodeid-id 𝓔 RA)) (trans (cong (toNodeId 𝓔) prf) (author-nodeid-id 𝓔 RB)) -- The abstract model is connected to the implementaton by means of -- 'VoteEvidence'. The record module will be parameterized by a -- v of type 'VoteEvidence 𝓔 UID'; this v will provide evidence -- that a given author voted for a given block (identified by the UID) -- on the specified round. -- -- When it comes time to instantiate the v above concretely, it will -- be something that states that we have a signature from the specified -- author voting for the specified block. record AbsVoteData (𝓔 : EpochConfig)(UID : Set) : Set where constructor mkAbsVoteData field abs-vRound : Round abs-vMember : EpochConfig.Member 𝓔 abs-vBlockUID : UID open AbsVoteData public AbsVoteData-η : ∀ {𝓔} {UID : Set} {r1 r2 : Round} {m1 m2 : EpochConfig.Member 𝓔} {b1 b2 : UID} → r1 ≡ r2 → m1 ≡ m2 → b1 ≡ b2 → mkAbsVoteData {𝓔} {UID} r1 m1 b1 ≡ mkAbsVoteData r2 m2 b2 AbsVoteData-η refl refl refl = refl VoteEvidence : EpochConfig → Set → Set₁ VoteEvidence 𝓔 UID = AbsVoteData 𝓔 UID → Set
algebraic-stack_agda0000_doc_4658
module Thesis.Syntax where open import Thesis.Types public open import Thesis.Contexts public data Const : (τ : Type) → Set where unit : Const unit lit : ℤ → Const int plus : Const (int ⇒ int ⇒ int) minus : Const (int ⇒ int ⇒ int) cons : ∀ {t1 t2} → Const (t1 ⇒ t2 ⇒ pair t1 t2) fst : ∀ {t1 t2} → Const (pair t1 t2 ⇒ t1) snd : ∀ {t1 t2} → Const (pair t1 t2 ⇒ t2) linj : ∀ {t1 t2} → Const (t1 ⇒ sum t1 t2) rinj : ∀ {t1 t2} → Const (t2 ⇒ sum t1 t2) match : ∀ {t1 t2 t3} → Const (sum t1 t2 ⇒ (t1 ⇒ t3) ⇒ (t2 ⇒ t3) ⇒ t3) data Term (Γ : Context) : (τ : Type) → Set where -- constants aka. primitives const : ∀ {τ} → (c : Const τ) → Term Γ τ var : ∀ {τ} → (x : Var Γ τ) → Term Γ τ app : ∀ {σ τ} (s : Term Γ (σ ⇒ τ)) → (t : Term Γ σ) → Term Γ τ -- we use de Bruijn indices, so we don't need binding occurrences. abs : ∀ {σ τ} (t : Term (σ • Γ) τ) → Term Γ (σ ⇒ τ) -- Weakening weaken : ∀ {Γ₁ Γ₂ τ} → (Γ₁≼Γ₂ : Γ₁ ≼ Γ₂) → Term Γ₁ τ → Term Γ₂ τ weaken Γ₁≼Γ₂ (const c) = const c weaken Γ₁≼Γ₂ (var x) = var (weaken-var Γ₁≼Γ₂ x) weaken Γ₁≼Γ₂ (app s t) = app (weaken Γ₁≼Γ₂ s) (weaken Γ₁≼Γ₂ t) weaken Γ₁≼Γ₂ (abs {σ} t) = abs (weaken (keep σ • Γ₁≼Γ₂) t) -- Shorthands for nested applications app₂ : ∀ {Γ α β γ} → Term Γ (α ⇒ β ⇒ γ) → Term Γ α → Term Γ β → Term Γ γ app₂ f x = app (app f x) app₃ : ∀ {Γ α β γ δ} → Term Γ (α ⇒ β ⇒ γ ⇒ δ) → Term Γ α → Term Γ β → Term Γ γ → Term Γ δ app₃ f x = app₂ (app f x) app₄ : ∀ {Γ α β γ δ ε} → Term Γ (α ⇒ β ⇒ γ ⇒ δ ⇒ ε) → Term Γ α → Term Γ β → Term Γ γ → Term Γ δ → Term Γ ε app₄ f x = app₃ (app f x) app₅ : ∀ {Γ α β γ δ ε ζ} → Term Γ (α ⇒ β ⇒ γ ⇒ δ ⇒ ε ⇒ ζ) → Term Γ α → Term Γ β → Term Γ γ → Term Γ δ → Term Γ ε → Term Γ ζ app₅ f x = app₄ (app f x) app₆ : ∀ {Γ α β γ δ ε ζ η} → Term Γ (α ⇒ β ⇒ γ ⇒ δ ⇒ ε ⇒ ζ ⇒ η) → Term Γ α → Term Γ β → Term Γ γ → Term Γ δ → Term Γ ε → Term Γ ζ → Term Γ η app₆ f x = app₅ (app f x)
algebraic-stack_agda0000_doc_4659
open import Common.Reflection macro round-trip : Term → Tactic round-trip v hole = unify v hole module M (A : Set) where data D : Set where test : Set test = round-trip D
algebraic-stack_agda0000_doc_4660
module MissingWithClauses where data D : Set where c : D f : D -> D f c with c
algebraic-stack_agda0000_doc_4661
module PiInSet where Rel : Set -> Set1 Rel A = A -> A -> Set Reflexive : {A : Set} -> Rel A -> Set Reflexive {A} _R_ = forall x -> x R x Symmetric : {A : Set} -> Rel A -> Set Symmetric {A} _R_ = forall x y -> x R y -> y R x data True : Set where tt : True data False : Set where data Nat : Set where zero : Nat suc : Nat -> Nat _==_ : Rel Nat zero == zero = True zero == suc _ = False suc _ == zero = False suc n == suc m = n == m refl== : Reflexive _==_ refl== zero = tt refl== (suc n) = refl== n sym== : Symmetric _==_ sym== zero zero tt = tt sym== zero (suc _) () sym== (suc _) zero () sym== (suc n) (suc m) n==m = sym== n m n==m
algebraic-stack_agda0000_doc_4662
{-# OPTIONS --without-K --allow-unsolved-metas --exact-split #-} module 21-pushouts where import 20-pullbacks open 20-pullbacks public -- Section 14.1 {- We define the type of cocones with vertex X on a span. Since we will use it later on, we will also characterize the identity type of the type of cocones with a given vertex X. -} cocone : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) → UU l4 → UU _ cocone {A = A} {B = B} f g X = Σ (A → X) (λ i → Σ (B → X) (λ j → (i ∘ f) ~ (j ∘ g))) {- We characterize the identity type of the type of cocones with vertex C. -} coherence-htpy-cocone : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c c' : cocone f g X) → (K : (pr1 c) ~ (pr1 c')) (L : (pr1 (pr2 c)) ~ (pr1 (pr2 c'))) → UU (l1 ⊔ l4) coherence-htpy-cocone f g c c' K L = ((pr2 (pr2 c)) ∙h (L ·r g)) ~ ((K ·r f) ∙h (pr2 (pr2 c'))) htpy-cocone : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} → cocone f g X → cocone f g X → UU (l1 ⊔ (l2 ⊔ (l3 ⊔ l4))) htpy-cocone f g c c' = Σ ((pr1 c) ~ (pr1 c')) ( λ K → Σ ((pr1 (pr2 c)) ~ (pr1 (pr2 c'))) ( coherence-htpy-cocone f g c c' K)) reflexive-htpy-cocone : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) → htpy-cocone f g c c reflexive-htpy-cocone f g (pair i (pair j H)) = pair refl-htpy (pair refl-htpy htpy-right-unit) htpy-cocone-eq : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c c' : cocone f g X) → Id c c' → htpy-cocone f g c c' htpy-cocone-eq f g c .c refl = reflexive-htpy-cocone f g c is-contr-total-htpy-cocone : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) → is-contr (Σ (cocone f g X) (htpy-cocone f g c)) is-contr-total-htpy-cocone f g c = is-contr-total-Eq-structure ( λ i' jH' K → Σ ((pr1 (pr2 c)) ~ (pr1 jH')) ( coherence-htpy-cocone f g c (pair i' jH') K)) ( is-contr-total-htpy (pr1 c)) ( pair (pr1 c) refl-htpy) ( is-contr-total-Eq-structure ( λ j' H' → coherence-htpy-cocone f g c ( pair (pr1 c) (pair j' H')) ( refl-htpy)) ( is-contr-total-htpy (pr1 (pr2 c))) ( pair (pr1 (pr2 c)) refl-htpy) ( is-contr-is-equiv' ( Σ (((pr1 c) ∘ f) ~ ((pr1 (pr2 c)) ∘ g)) (λ H' → (pr2 (pr2 c)) ~ H')) ( tot (λ H' M → htpy-right-unit ∙h M)) ( is-equiv-tot-is-fiberwise-equiv (λ H' → is-equiv-htpy-concat _ _)) ( is-contr-total-htpy (pr2 (pr2 c))))) is-equiv-htpy-cocone-eq : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c c' : cocone f g X) → is-equiv (htpy-cocone-eq f g c c') is-equiv-htpy-cocone-eq f g c = fundamental-theorem-id c ( reflexive-htpy-cocone f g c) ( is-contr-total-htpy-cocone f g c) ( htpy-cocone-eq f g c) eq-htpy-cocone : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c c' : cocone f g X) → htpy-cocone f g c c' → Id c c' eq-htpy-cocone f g c c' = inv-is-equiv (is-equiv-htpy-cocone-eq f g c c') {- Given a cocone c on a span S with vertex X, and a type Y, the function cocone-map sends a function X → Y to a new cocone with vertex Y. -} cocone-map : {l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} {Y : UU l5} → cocone f g X → (X → Y) → cocone f g Y cocone-map f g (pair i (pair j H)) h = pair (h ∘ i) (pair (h ∘ j) (h ·l H)) cocone-map-id : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) → Id (cocone-map f g c id) c cocone-map-id f g (pair i (pair j H)) = eq-pair refl (eq-pair refl (eq-htpy (λ s → ap-id (H s)))) cocone-map-comp : {l1 l2 l3 l4 l5 l6 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) {Y : UU l5} (h : X → Y) {Z : UU l6} (k : Y → Z) → Id (cocone-map f g c (k ∘ h)) (cocone-map f g (cocone-map f g c h) k) cocone-map-comp f g (pair i (pair j H)) h k = eq-pair refl (eq-pair refl (eq-htpy (λ s → ap-comp k h (H s)))) {- A cocone c on a span S is said to satisfy the universal property of the pushout of S if the function cocone-map is an equivalence for every type Y. -} universal-property-pushout : {l1 l2 l3 l4 : Level} (l : Level) {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} → cocone f g X → UU _ universal-property-pushout l f g c = (Y : UU l) → is-equiv (cocone-map f g {Y = Y} c) map-universal-property-pushout : {l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) → ( up-c : {l : Level} → universal-property-pushout l f g c) {Y : UU l5} → cocone f g Y → (X → Y) map-universal-property-pushout f g c up-c {Y} = inv-is-equiv (up-c Y) htpy-cocone-map-universal-property-pushout : { l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3} ( f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) → ( up-c : {l : Level} → universal-property-pushout l f g c) { Y : UU l5} (d : cocone f g Y) → htpy-cocone f g ( cocone-map f g c ( map-universal-property-pushout f g c up-c d)) ( d) htpy-cocone-map-universal-property-pushout f g c up-c {Y} d = htpy-cocone-eq f g ( cocone-map f g c (map-universal-property-pushout f g c up-c d)) ( d) ( issec-inv-is-equiv (up-c Y) d) uniqueness-map-universal-property-pushout : { l1 l2 l3 l4 l5 : Level} {S : UU l1} {A : UU l2} {B : UU l3} ( f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) → ( up-c : {l : Level} → universal-property-pushout l f g c) → { Y : UU l5} (d : cocone f g Y) → is-contr ( Σ (X → Y) (λ h → htpy-cocone f g (cocone-map f g c h) d)) uniqueness-map-universal-property-pushout f g c up-c {Y} d = is-contr-is-equiv' ( fib (cocone-map f g c) d) ( tot (λ h → htpy-cocone-eq f g (cocone-map f g c h) d)) ( is-equiv-tot-is-fiberwise-equiv ( λ h → is-equiv-htpy-cocone-eq f g (cocone-map f g c h) d)) ( is-contr-map-is-equiv (up-c Y) d) {- We derive a 3-for-2 property of pushouts, analogous to the 3-for-2 property of pullbacks. -} triangle-cocone-cocone : { l1 l2 l3 l4 l5 l6 : Level} { S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4} {Y : UU l5} { f : S → A} {g : S → B} (c : cocone f g X) (d : cocone f g Y) ( h : X → Y) (KLM : htpy-cocone f g (cocone-map f g c h) d) ( Z : UU l6) → ( cocone-map f g d) ~ ((cocone-map f g c) ∘ (λ (k : Y → Z) → k ∘ h)) triangle-cocone-cocone {Y = Y} {f = f} {g = g} c d h KLM Z k = inv ( ( cocone-map-comp f g c h k) ∙ ( ap ( λ t → cocone-map f g t k) ( eq-htpy-cocone f g (cocone-map f g c h) d KLM))) is-equiv-up-pushout-up-pushout : { l1 l2 l3 l4 l5 : Level} { S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4} {Y : UU l5} ( f : S → A) (g : S → B) (c : cocone f g X) (d : cocone f g Y) → ( h : X → Y) (KLM : htpy-cocone f g (cocone-map f g c h) d) → ( up-c : {l : Level} → universal-property-pushout l f g c) → ( up-d : {l : Level} → universal-property-pushout l f g d) → is-equiv h is-equiv-up-pushout-up-pushout f g c d h KLM up-c up-d = is-equiv-is-equiv-precomp h ( λ l Z → is-equiv-right-factor ( cocone-map f g d) ( cocone-map f g c) ( precomp h Z) ( triangle-cocone-cocone c d h KLM Z) ( up-c Z) ( up-d Z)) up-pushout-up-pushout-is-equiv : { l1 l2 l3 l4 l5 : Level} { S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4} {Y : UU l5} ( f : S → A) (g : S → B) (c : cocone f g X) (d : cocone f g Y) → ( h : X → Y) (KLM : htpy-cocone f g (cocone-map f g c h) d) → is-equiv h → ( up-c : {l : Level} → universal-property-pushout l f g c) → {l : Level} → universal-property-pushout l f g d up-pushout-up-pushout-is-equiv f g c d h KLM is-equiv-h up-c Z = is-equiv-comp ( cocone-map f g d) ( cocone-map f g c) ( precomp h Z) ( triangle-cocone-cocone c d h KLM Z) ( is-equiv-precomp-is-equiv h is-equiv-h Z) ( up-c Z) up-pushout-is-equiv-up-pushout : { l1 l2 l3 l4 l5 : Level} { S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4} {Y : UU l5} ( f : S → A) (g : S → B) (c : cocone f g X) (d : cocone f g Y) → ( h : X → Y) (KLM : htpy-cocone f g (cocone-map f g c h) d) → ( up-d : {l : Level} → universal-property-pushout l f g d) → is-equiv h → {l : Level} → universal-property-pushout l f g c up-pushout-is-equiv-up-pushout f g c d h KLM up-d is-equiv-h Z = is-equiv-left-factor ( cocone-map f g d) ( cocone-map f g c) ( precomp h Z) ( triangle-cocone-cocone c d h KLM Z) ( up-d Z) ( is-equiv-precomp-is-equiv h is-equiv-h Z) uniquely-unique-pushout : { l1 l2 l3 l4 l5 : Level} { S : UU l1} {A : UU l2} {B : UU l3} {X : UU l4} {Y : UU l5} ( f : S → A) (g : S → B) (c : cocone f g X) (d : cocone f g Y) → ( up-c : {l : Level} → universal-property-pushout l f g c) → ( up-d : {l : Level} → universal-property-pushout l f g d) → is-contr ( Σ (X ≃ Y) (λ e → htpy-cocone f g (cocone-map f g c (map-equiv e)) d)) uniquely-unique-pushout f g c d up-c up-d = is-contr-total-Eq-substructure ( uniqueness-map-universal-property-pushout f g c up-c d) ( is-subtype-is-equiv) ( map-universal-property-pushout f g c up-c d) ( htpy-cocone-map-universal-property-pushout f g c up-c d) ( is-equiv-up-pushout-up-pushout f g c d ( map-universal-property-pushout f g c up-c d) ( htpy-cocone-map-universal-property-pushout f g c up-c d) ( up-c) ( up-d)) {- We will assume that every span has a pushout. Moreover, we will introduce some further terminology to facilitate working with these pushouts. -} postulate pushout : {l1 l2 l3 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) → UU (l1 ⊔ l2 ⊔ l3) postulate inl-pushout : {l1 l2 l3 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) → A → pushout f g postulate inr-pushout : {l1 l2 l3 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) → B → pushout f g postulate glue-pushout : {l1 l2 l3 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) → ((inl-pushout f g) ∘ f) ~ ((inr-pushout f g) ∘ g) cocone-pushout : {l1 l2 l3 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) → cocone f g (pushout f g) cocone-pushout f g = pair ( inl-pushout f g) ( pair ( inr-pushout f g) ( glue-pushout f g)) postulate up-pushout : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) → universal-property-pushout l4 f g (cocone-pushout f g) cogap : { l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} ( f : S → A) (g : S → B) → { X : UU l4} (c : cocone f g X) → pushout f g → X cogap f g = map-universal-property-pushout f g ( cocone-pushout f g) ( up-pushout f g) is-pushout : { l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} ( f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) → UU (l1 ⊔ l2 ⊔ l3 ⊔ l4) is-pushout f g c = is-equiv (cogap f g c) -- Section 14.2 Suspensions suspension-structure : {l1 l2 : Level} (X : UU l1) (Y : UU l2) → UU (l1 ⊔ l2) suspension-structure X Y = Σ Y (λ N → Σ Y (λ S → (x : X) → Id N S)) suspension-cocone' : {l1 l2 : Level} (X : UU l1) (Y : UU l2) → UU (l1 ⊔ l2) suspension-cocone' X Y = cocone (const X unit star) (const X unit star) Y cocone-suspension-structure : {l1 l2 : Level} (X : UU l1) (Y : UU l2) → suspension-structure X Y → suspension-cocone' X Y cocone-suspension-structure X Y (pair N (pair S merid)) = pair ( const unit Y N) ( pair ( const unit Y S) ( merid)) universal-property-suspension' : (l : Level) {l1 l2 : Level} (X : UU l1) (Y : UU l2) (susp-str : suspension-structure X Y) → UU (lsuc l ⊔ l1 ⊔ l2) universal-property-suspension' l X Y susp-str-Y = universal-property-pushout l ( const X unit star) ( const X unit star) ( cocone-suspension-structure X Y susp-str-Y) is-suspension : (l : Level) {l1 l2 : Level} (X : UU l1) (Y : UU l2) → UU (lsuc l ⊔ l1 ⊔ l2) is-suspension l X Y = Σ (suspension-structure X Y) (universal-property-suspension' l X Y) suspension : {l : Level} → UU l → UU l suspension X = pushout (const X unit star) (const X unit star) N-susp : {l : Level} {X : UU l} → suspension X N-susp {X = X} = inl-pushout (const X unit star) (const X unit star) star S-susp : {l : Level} {X : UU l} → suspension X S-susp {X = X} = inr-pushout (const X unit star) (const X unit star) star merid-susp : {l : Level} {X : UU l} → X → Id (N-susp {X = X}) (S-susp {X = X}) merid-susp {X = X} = glue-pushout (const X unit star) (const X unit star) sphere : ℕ → UU lzero sphere zero-ℕ = bool sphere (succ-ℕ n) = suspension (sphere n) N-sphere : (n : ℕ) → sphere n N-sphere zero-ℕ = true N-sphere (succ-ℕ n) = N-susp S-sphere : (n : ℕ) → sphere n S-sphere zero-ℕ = false S-sphere (succ-ℕ n) = S-susp {- We now work towards Lemma 17.2.2. -} suspension-cocone : {l1 l2 : Level} (X : UU l1) (Z : UU l2) → UU _ suspension-cocone X Z = Σ Z (λ z1 → Σ Z (λ z2 → (x : X) → Id z1 z2)) ev-suspension : {l1 l2 l3 : Level} {X : UU l1} {Y : UU l2} → (susp-str-Y : suspension-structure X Y) → (Z : UU l3) → (Y → Z) → suspension-cocone X Z ev-suspension (pair N (pair S merid)) Z h = pair (h N) (pair (h S) (h ·l merid)) universal-property-suspension : (l : Level) {l1 l2 : Level} (X : UU l1) (Y : UU l2) → suspension-structure X Y → UU (lsuc l ⊔ l1 ⊔ l2) universal-property-suspension l X Y susp-str-Y = (Z : UU l) → is-equiv (ev-suspension susp-str-Y Z) comparison-suspension-cocone : {l1 l2 : Level} (X : UU l1) (Z : UU l2) → suspension-cocone' X Z ≃ suspension-cocone X Z comparison-suspension-cocone X Z = equiv-toto ( λ z1 → Σ Z (λ z2 → (x : X) → Id z1 z2)) ( equiv-ev-star' Z) ( λ z1 → equiv-toto ( λ z2 → (x : X) → Id (z1 star) z2) ( equiv-ev-star' Z) ( λ z2 → equiv-id ((x : X) → Id (z1 star) (z2 star)))) map-comparison-suspension-cocone : {l1 l2 : Level} (X : UU l1) (Z : UU l2) → suspension-cocone' X Z → suspension-cocone X Z map-comparison-suspension-cocone X Z = map-equiv (comparison-suspension-cocone X Z) is-equiv-map-comparison-suspension-cocone : {l1 l2 : Level} (X : UU l1) (Z : UU l2) → is-equiv (map-comparison-suspension-cocone X Z) is-equiv-map-comparison-suspension-cocone X Z = is-equiv-map-equiv (comparison-suspension-cocone X Z) triangle-ev-suspension : {l1 l2 l3 : Level} {X : UU l1} {Y : UU l2} → (susp-str-Y : suspension-structure X Y) → (Z : UU l3) → ( ( map-comparison-suspension-cocone X Z) ∘ ( cocone-map ( const X unit star) ( const X unit star) ( cocone-suspension-structure X Y susp-str-Y))) ~ ( ev-suspension susp-str-Y Z) triangle-ev-suspension (pair N (pair S merid)) Z h = refl is-equiv-ev-suspension : { l1 l2 l3 : Level} {X : UU l1} {Y : UU l2} → ( susp-str-Y : suspension-structure X Y) → ( up-Y : universal-property-suspension' l3 X Y susp-str-Y) → ( Z : UU l3) → is-equiv (ev-suspension susp-str-Y Z) is-equiv-ev-suspension {X = X} susp-str-Y up-Y Z = is-equiv-comp ( ev-suspension susp-str-Y Z) ( map-comparison-suspension-cocone X Z) ( cocone-map ( const X unit star) ( const X unit star) ( cocone-suspension-structure X _ susp-str-Y)) ( htpy-inv (triangle-ev-suspension susp-str-Y Z)) ( up-Y Z) ( is-equiv-map-comparison-suspension-cocone X Z) {- Pointed maps and pointed homotopies. -} pointed-fam : {l1 : Level} (l : Level) (X : UU-pt l1) → UU (lsuc l ⊔ l1) pointed-fam l (pair X x) = Σ (X → UU l) (λ P → P x) pointed-Π : {l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) → UU (l1 ⊔ l2) pointed-Π (pair X x) (pair P p) = Σ ((x' : X) → P x') (λ f → Id (f x) p) pointed-htpy : {l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) → (f g : pointed-Π X P) → UU (l1 ⊔ l2) pointed-htpy (pair X x) (pair P p) (pair f α) g = pointed-Π (pair X x) (pair (λ x' → Id (f x') (pr1 g x')) (α ∙ (inv (pr2 g)))) pointed-refl-htpy : {l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) → (f : pointed-Π X P) → pointed-htpy X P f f pointed-refl-htpy (pair X x) (pair P p) (pair f α) = pair refl-htpy (inv (right-inv α)) pointed-htpy-eq : {l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) → (f g : pointed-Π X P) → Id f g → pointed-htpy X P f g pointed-htpy-eq X P f .f refl = pointed-refl-htpy X P f is-contr-total-pointed-htpy : {l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) (f : pointed-Π X P) → is-contr (Σ (pointed-Π X P) (pointed-htpy X P f)) is-contr-total-pointed-htpy (pair X x) (pair P p) (pair f α) = is-contr-total-Eq-structure ( λ g β (H : f ~ g) → Id (H x) (α ∙ (inv β))) ( is-contr-total-htpy f) ( pair f refl-htpy) ( is-contr-equiv' ( Σ (Id (f x) p) (λ β → Id β α)) ( equiv-tot (λ β → equiv-con-inv refl β α)) ( is-contr-total-path' α)) is-equiv-pointed-htpy-eq : {l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) → (f g : pointed-Π X P) → is-equiv (pointed-htpy-eq X P f g) is-equiv-pointed-htpy-eq X P f = fundamental-theorem-id f ( pointed-refl-htpy X P f) ( is-contr-total-pointed-htpy X P f) ( pointed-htpy-eq X P f) eq-pointed-htpy : {l1 l2 : Level} (X : UU-pt l1) (P : pointed-fam l2 X) → (f g : pointed-Π X P) → (pointed-htpy X P f g) → Id f g eq-pointed-htpy X P f g = inv-is-equiv (is-equiv-pointed-htpy-eq X P f g) -- Section 14.3 Duality of pushouts and pullbacks {- The universal property of the pushout of a span S can also be stated as a pullback-property: a cocone c = (pair i (pair j H)) with vertex X satisfies the universal property of the pushout of S if and only if the square Y^X -----> Y^B | | | | V V Y^A -----> Y^S is a pullback square for every type Y. Below, we first define the cone of this commuting square, and then we introduce the type pullback-property-pushout, which states that the above square is a pullback. -} htpy-precomp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} {f g : A → B} (H : f ~ g) (C : UU l3) → (precomp f C) ~ (precomp g C) htpy-precomp H C h = eq-htpy (h ·l H) compute-htpy-precomp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2} (f : A → B) (C : UU l3) → (htpy-precomp (refl-htpy' f) C) ~ refl-htpy compute-htpy-precomp f C h = eq-htpy-refl-htpy (h ∘ f) cone-pullback-property-pushout : {l1 l2 l3 l4 l : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) (Y : UU l) → cone (λ (h : A → Y) → h ∘ f) (λ (h : B → Y) → h ∘ g) (X → Y) cone-pullback-property-pushout f g {X} c Y = pair ( precomp (pr1 c) Y) ( pair ( precomp (pr1 (pr2 c)) Y) ( htpy-precomp (pr2 (pr2 c)) Y)) pullback-property-pushout : {l1 l2 l3 l4 : Level} (l : Level) {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) → UU (l1 ⊔ (l2 ⊔ (l3 ⊔ (l4 ⊔ lsuc l)))) pullback-property-pushout l {S} {A} {B} f g {X} c = (Y : UU l) → is-pullback ( precomp f Y) ( precomp g Y) ( cone-pullback-property-pushout f g c Y) {- In order to show that the universal property of pushouts is equivalent to the pullback property, we show that the maps cocone-map and the gap map fit in a commuting triangle, where the third map is an equivalence. The claim then follows from the 3-for-2 property of equivalences. -} triangle-pullback-property-pushout-universal-property-pushout : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) → {l : Level} (Y : UU l) → ( cocone-map f g c) ~ ( ( tot (λ i' → tot (λ j' p → htpy-eq p))) ∘ ( gap (λ h → h ∘ f) (λ h → h ∘ g) (cone-pullback-property-pushout f g c Y))) triangle-pullback-property-pushout-universal-property-pushout {S = S} {A = A} {B = B} f g (pair i (pair j H)) Y h = eq-pair refl (eq-pair refl (inv (issec-eq-htpy (h ·l H)))) pullback-property-pushout-universal-property-pushout : {l1 l2 l3 l4 : Level} (l : Level) {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) → universal-property-pushout l f g c → pullback-property-pushout l f g c pullback-property-pushout-universal-property-pushout l f g (pair i (pair j H)) up-c Y = let c = (pair i (pair j H)) in is-equiv-right-factor ( cocone-map f g c) ( tot (λ i' → tot (λ j' p → htpy-eq p))) ( gap (λ h → h ∘ f) (λ h → h ∘ g) (cone-pullback-property-pushout f g c Y)) ( triangle-pullback-property-pushout-universal-property-pushout f g c Y) ( is-equiv-tot-is-fiberwise-equiv ( λ i' → is-equiv-tot-is-fiberwise-equiv ( λ j' → funext (i' ∘ f) (j' ∘ g)))) ( up-c Y) universal-property-pushout-pullback-property-pushout : {l1 l2 l3 l4 : Level} (l : Level) {S : UU l1} {A : UU l2} {B : UU l3} (f : S → A) (g : S → B) {X : UU l4} (c : cocone f g X) → pullback-property-pushout l f g c → universal-property-pushout l f g c universal-property-pushout-pullback-property-pushout l f g (pair i (pair j H)) pb-c Y = let c = (pair i (pair j H)) in is-equiv-comp ( cocone-map f g c) ( tot (λ i' → tot (λ j' p → htpy-eq p))) ( gap (λ h → h ∘ f) (λ h → h ∘ g) (cone-pullback-property-pushout f g c Y)) ( triangle-pullback-property-pushout-universal-property-pushout f g c Y) ( pb-c Y) ( is-equiv-tot-is-fiberwise-equiv ( λ i' → is-equiv-tot-is-fiberwise-equiv ( λ j' → funext (i' ∘ f) (j' ∘ g)))) cocone-compose-horizontal : { l1 l2 l3 l4 l5 l6 : Level} { A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6} ( f : A → X) (i : A → B) (k : B → C) → ( c : cocone f i Y) (d : cocone (pr1 (pr2 c)) k Z) → cocone f (k ∘ i) Z cocone-compose-horizontal f i k (pair j (pair g H)) (pair l (pair h K)) = pair ( l ∘ j) ( pair ( h) ( (l ·l H) ∙h (K ·r i))) {- is-pushout-rectangle-is-pushout-right-square : ( l : Level) { l1 l2 l3 l4 l5 l6 : Level} { A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6} ( f : A → X) (i : A → B) (k : B → C) → ( c : cocone f i Y) (d : cocone (pr1 (pr2 c)) k Z) → universal-property-pushout l f i c → universal-property-pushout l (pr1 (pr2 c)) k d → universal-property-pushout l f (k ∘ i) (cocone-compose-horizontal f i k c d) is-pushout-rectangle-is-pushout-right-square l f i k c d up-Y up-Z = universal-property-pushout-pullback-property-pushout l f (k ∘ i) ( cocone-compose-horizontal f i k c d) ( λ T → is-pullback-htpy {!!} {!!} {!!} {!!} {!!} {!!} {!!}) -} -- Examples of pushouts {- The cofiber of a map. -} cofiber : {l1 l2 : Level} {A : UU l1} {B : UU l2} → (A → B) → UU (l1 ⊔ l2) cofiber {A = A} f = pushout f (const A unit star) cocone-cofiber : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → cocone f (const A unit star) (cofiber f) cocone-cofiber {A = A} f = cocone-pushout f (const A unit star) inl-cofiber : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → B → cofiber f inl-cofiber {A = A} f = pr1 (cocone-cofiber f) inr-cofiber : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → unit → cofiber f inr-cofiber f = pr1 (pr2 (cocone-cofiber f)) pt-cofiber : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → cofiber f pt-cofiber {A = A} f = inr-cofiber f star cofiber-ptd : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → UU-pt (l1 ⊔ l2) cofiber-ptd f = pair (cofiber f) (pt-cofiber f) up-cofiber : { l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → ( {l : Level} → universal-property-pushout l f (const A unit star) (cocone-cofiber f)) up-cofiber {A = A} f = up-pushout f (const A unit star) _*_ : {l1 l2 : Level} (A : UU l1) (B : UU l2) → UU (l1 ⊔ l2) A * B = pushout (pr1 {A = A} {B = λ x → B}) pr2 cocone-join : {l1 l2 : Level} (A : UU l1) (B : UU l2) → cocone (pr1 {A = A} {B = λ x → B}) pr2 (A * B) cocone-join A B = cocone-pushout pr1 pr2 up-join : {l1 l2 : Level} (A : UU l1) (B : UU l2) → ( {l : Level} → universal-property-pushout l ( pr1 {A = A} {B = λ x → B}) pr2 (cocone-join A B)) up-join A B = up-pushout pr1 pr2 inl-join : {l1 l2 : Level} (A : UU l1) (B : UU l2) → A → A * B inl-join A B = pr1 (cocone-join A B) inr-join : {l1 l2 : Level} (A : UU l1) (B : UU l2) → B → A * B inr-join A B = pr1 (pr2 (cocone-join A B)) glue-join : {l1 l2 : Level} (A : UU l1) (B : UU l2) (t : A × B) → Id (inl-join A B (pr1 t)) (inr-join A B (pr2 t)) glue-join A B = pr2 (pr2 (cocone-join A B)) _∨_ : {l1 l2 : Level} (A : UU-pt l1) (B : UU-pt l2) → UU-pt (l1 ⊔ l2) A ∨ B = pair ( pushout ( const unit (pr1 A) (pr2 A)) ( const unit (pr1 B) (pr2 B))) ( inl-pushout ( const unit (pr1 A) (pr2 A)) ( const unit (pr1 B) (pr2 B)) ( pr2 A)) indexed-wedge : {l1 l2 : Level} (I : UU l1) (A : I → UU-pt l2) → UU-pt (l1 ⊔ l2) indexed-wedge I A = pair ( cofiber (λ i → pair i (pr2 (A i)))) ( pt-cofiber (λ i → pair i (pr2 (A i)))) wedge-inclusion : {l1 l2 : Level} (A : UU-pt l1) (B : UU-pt l2) → pr1 (A ∨ B) → (pr1 A) × (pr1 B) wedge-inclusion {l1} {l2} (pair A a) (pair B b) = inv-is-equiv ( up-pushout ( const unit A a) ( const unit B b) ( A × B)) ( pair ( λ x → pair x b) ( pair ( λ y → pair a y) ( refl-htpy))) -- Exercises -- Exercise 13.1 -- Exercise 13.2 is-equiv-universal-property-pushout : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {C : UU l4} (f : S → A) (g : S → B) (c : cocone f g C) → is-equiv f → ({l : Level} → universal-property-pushout l f g c) → is-equiv (pr1 (pr2 c)) is-equiv-universal-property-pushout {A = A} {B} f g (pair i (pair j H)) is-equiv-f up-c = is-equiv-is-equiv-precomp j ( λ l T → is-equiv-is-pullback' ( λ (h : A → T) → h ∘ f) ( λ (h : B → T) → h ∘ g) ( cone-pullback-property-pushout f g (pair i (pair j H)) T) ( is-equiv-precomp-is-equiv f is-equiv-f T) ( pullback-property-pushout-universal-property-pushout l f g (pair i (pair j H)) up-c T)) equiv-universal-property-pushout : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {C : UU l4} (e : S ≃ A) (g : S → B) (c : cocone (map-equiv e) g C) → ({l : Level} → universal-property-pushout l (map-equiv e) g c) → B ≃ C equiv-universal-property-pushout e g c up-c = pair ( pr1 (pr2 c)) ( is-equiv-universal-property-pushout ( map-equiv e) ( g) ( c) ( is-equiv-map-equiv e) ( up-c)) is-equiv-universal-property-pushout' : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {C : UU l4} (f : S → A) (g : S → B) (c : cocone f g C) → is-equiv g → ({l : Level} → universal-property-pushout l f g c) → is-equiv (pr1 c) is-equiv-universal-property-pushout' f g (pair i (pair j H)) is-equiv-g up-c = is-equiv-is-equiv-precomp i ( λ l T → is-equiv-is-pullback ( precomp f T) ( precomp g T) ( cone-pullback-property-pushout f g (pair i (pair j H)) T) ( is-equiv-precomp-is-equiv g is-equiv-g T) ( pullback-property-pushout-universal-property-pushout l f g (pair i (pair j H)) up-c T)) equiv-universal-property-pushout' : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {C : UU l4} (f : S → A) (e : S ≃ B) (c : cocone f (map-equiv e) C) → ({l : Level} → universal-property-pushout l f (map-equiv e) c) → A ≃ C equiv-universal-property-pushout' f e c up-c = pair ( pr1 c) ( is-equiv-universal-property-pushout' ( f) ( map-equiv e) ( c) ( is-equiv-map-equiv e) ( up-c)) universal-property-pushout-is-equiv : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {C : UU l4} (f : S → A) (g : S → B) (c : cocone f g C) → is-equiv f → is-equiv (pr1 (pr2 c)) → ({l : Level} → universal-property-pushout l f g c) universal-property-pushout-is-equiv f g (pair i (pair j H)) is-equiv-f is-equiv-j {l} = let c = (pair i (pair j H)) in universal-property-pushout-pullback-property-pushout l f g c ( λ T → is-pullback-is-equiv' ( λ h → h ∘ f) ( λ h → h ∘ g) ( cone-pullback-property-pushout f g c T) ( is-equiv-precomp-is-equiv f is-equiv-f T) ( is-equiv-precomp-is-equiv j is-equiv-j T)) universal-property-pushout-is-equiv' : {l1 l2 l3 l4 : Level} {S : UU l1} {A : UU l2} {B : UU l3} {C : UU l4} (f : S → A) (g : S → B) (c : cocone f g C) → is-equiv g → is-equiv (pr1 c) → ({l : Level} → universal-property-pushout l f g c) universal-property-pushout-is-equiv' f g (pair i (pair j H)) is-equiv-g is-equiv-i {l} = let c = (pair i (pair j H)) in universal-property-pushout-pullback-property-pushout l f g c ( λ T → is-pullback-is-equiv ( precomp f T) ( precomp g T) ( cone-pullback-property-pushout f g c T) ( is-equiv-precomp-is-equiv g is-equiv-g T) ( is-equiv-precomp-is-equiv i is-equiv-i T)) is-contr-suspension-is-contr : {l : Level} {X : UU l} → is-contr X → is-contr (suspension X) is-contr-suspension-is-contr {l} {X} is-contr-X = is-contr-is-equiv' ( unit) ( pr1 (pr2 (cocone-pushout (const X unit star) (const X unit star)))) ( is-equiv-universal-property-pushout ( const X unit star) ( const X unit star) ( cocone-pushout ( const X unit star) ( const X unit star)) ( is-equiv-is-contr (const X unit star) is-contr-X is-contr-unit) ( up-pushout (const X unit star) (const X unit star))) ( is-contr-unit) is-contr-cofiber-is-equiv : {l1 l2 : Level} {A : UU l1} {B : UU l2} (f : A → B) → is-equiv f → is-contr (cofiber f) is-contr-cofiber-is-equiv {A = A} {B} f is-equiv-f = is-contr-is-equiv' ( unit) ( pr1 (pr2 (cocone-cofiber f))) ( is-equiv-universal-property-pushout ( f) ( const A unit star) ( cocone-cofiber f) ( is-equiv-f) ( up-cofiber f)) ( is-contr-unit) is-equiv-cofiber-point : {l : Level} {B : UU l} (b : B) → is-equiv (pr1 (cocone-pushout (const unit B b) (const unit unit star))) is-equiv-cofiber-point {l} {B} b = is-equiv-universal-property-pushout' ( const unit B b) ( const unit unit star) ( cocone-pushout (const unit B b) (const unit unit star)) ( is-equiv-is-contr (const unit unit star) is-contr-unit is-contr-unit) ( up-pushout (const unit B b) (const unit unit star)) is-equiv-inr-join-empty : {l : Level} (X : UU l) → is-equiv (inr-join empty X) is-equiv-inr-join-empty X = is-equiv-universal-property-pushout ( pr1 {A = empty} {B = λ t → X}) ( pr2) ( cocone-join empty X) ( is-equiv-pr1-prod-empty X) ( up-join empty X) left-unit-law-join : {l : Level} (X : UU l) → X ≃ (empty * X) left-unit-law-join X = pair (inr-join empty X) (is-equiv-inr-join-empty X) is-equiv-inl-join-empty : {l : Level} (X : UU l) → is-equiv (inl-join X empty) is-equiv-inl-join-empty X = is-equiv-universal-property-pushout' ( pr1) ( pr2) ( cocone-join X empty) ( is-equiv-pr2-prod-empty X) ( up-join X empty) right-unit-law-join : {l : Level} (X : UU l) → X ≃ (X * empty) right-unit-law-join X = pair (inl-join X empty) (is-equiv-inl-join-empty X) inv-map-left-unit-law-prod : {l : Level} (X : UU l) → X → (unit × X) inv-map-left-unit-law-prod X = pair star issec-inv-map-left-unit-law-prod : {l : Level} (X : UU l) → (pr2 ∘ (inv-map-left-unit-law-prod X)) ~ id issec-inv-map-left-unit-law-prod X x = refl isretr-inv-map-left-unit-law-prod : {l : Level} (X : UU l) → ((inv-map-left-unit-law-prod X) ∘ pr2) ~ id isretr-inv-map-left-unit-law-prod X (pair star x) = refl is-equiv-left-unit-law-prod : {l : Level} (X : UU l) → is-equiv (pr2 {A = unit} {B = λ t → X}) is-equiv-left-unit-law-prod X = is-equiv-has-inverse ( inv-map-left-unit-law-prod X) ( issec-inv-map-left-unit-law-prod X) ( isretr-inv-map-left-unit-law-prod X) left-unit-law-prod : {l : Level} (X : UU l) → (unit × X) ≃ X left-unit-law-prod X = pair pr2 (is-equiv-left-unit-law-prod X) is-equiv-inl-join-unit : {l : Level} (X : UU l) → is-equiv (inl-join unit X) is-equiv-inl-join-unit X = is-equiv-universal-property-pushout' ( pr1) ( pr2) ( cocone-join unit X) ( is-equiv-left-unit-law-prod X) ( up-join unit X) left-zero-law-join : {l : Level} (X : UU l) → is-contr (unit * X) left-zero-law-join X = is-contr-equiv' ( unit) ( pair (inl-join unit X) (is-equiv-inl-join-unit X)) ( is-contr-unit) inv-map-right-unit-law-prod : {l : Level} (X : UU l) → X → X × unit inv-map-right-unit-law-prod X x = pair x star issec-inv-map-right-unit-law-prod : {l : Level} (X : UU l) → (pr1 ∘ (inv-map-right-unit-law-prod X)) ~ id issec-inv-map-right-unit-law-prod X x = refl isretr-inv-map-right-unit-law-prod : {l : Level} (X : UU l) → ((inv-map-right-unit-law-prod X) ∘ pr1) ~ id isretr-inv-map-right-unit-law-prod X (pair x star) = refl is-equiv-right-unit-law-prod : {l : Level} (X : UU l) → is-equiv (pr1 {A = X} {B = λ t → unit}) is-equiv-right-unit-law-prod X = is-equiv-has-inverse ( inv-map-right-unit-law-prod X) ( issec-inv-map-right-unit-law-prod X) ( isretr-inv-map-right-unit-law-prod X) right-unit-law-prod : {l : Level} (X : UU l) → (X × unit) ≃ X right-unit-law-prod X = pair pr1 (is-equiv-right-unit-law-prod X) is-equiv-inr-join-unit : {l : Level} (X : UU l) → is-equiv (inr-join X unit) is-equiv-inr-join-unit X = is-equiv-universal-property-pushout ( pr1) ( pr2) ( cocone-join X unit) ( is-equiv-right-unit-law-prod X) ( up-join X unit) right-zero-law-join : {l : Level} (X : UU l) → is-contr (X * unit) right-zero-law-join X = is-contr-equiv' ( unit) ( pair (inr-join X unit) (is-equiv-inr-join-unit X)) ( is-contr-unit) unit-pt : UU-pt lzero unit-pt = pair unit star is-contr-pt : {l : Level} → UU-pt l → UU l is-contr-pt A = is-contr (pr1 A) -- Exercise 16.2 -- ev-disjunction : -- {l1 l2 l3 : Level} (P : UU-Prop l1) (Q : UU-Prop l2) (R : UU-Prop l3) → -- ((type-Prop P) * (type-Prop Q) → (type-Prop R)) → -- (type-Prop P → type-Prop R) × (type-Prop Q → type-Prop R) -- ev-disjunction P Q R f = -- pair -- ( f ∘ (inl-join (type-Prop P) (type-Prop Q))) -- ( f ∘ (inr-join (type-Prop P) (type-Prop Q))) -- comparison-ev-disjunction : -- {l1 l2 l3 : Level} (P : UU-Prop l1) (Q : UU-Prop l2) (R : UU-Prop l3) → -- cocone-join (type-Prop P) (type-Prop Q) (type-Prop R) -- universal-property-disjunction-join-prop : -- {l1 l2 l3 : Level} (P : UU-Prop l1) (Q : UU-Prop l2) (R : UU-Prop l3) → -- is-equiv (ev-disjunction P Q R)
algebraic-stack_agda0000_doc_4663
{-# OPTIONS --without-K --safe #-} open import Categories.Category open import Categories.Category.Monoidal -- the definition used here is not very similar to what one usually sees in nLab or -- any textbook. the difference is that usually closed monoidal category is defined -- through a right adjoint of -⊗X, which is [X,-]. then there is an induced bifunctor -- [-,-]. -- -- but in proof relevant context, the induced bifunctor [-,-] does not have to be -- exactly the intended bifunctor! in fact, one can probably only show that the -- intended bifunctor is only naturally isomorphic to the induced one, which is -- significantly weaker. -- -- the approach taken here as an alternative is to BEGIN with a bifunctor -- already. however, is it required to have mates between any given two adjoints. this -- definition can be shown equivalent to the previous one but just works better. module Categories.Category.Monoidal.Closed {o ℓ e} {C : Category o ℓ e} (M : Monoidal C) where private module C = Category C open Category C variable X Y A B : Obj open import Level open import Data.Product using (_,_) open import Categories.Adjoint open import Categories.Adjoint.Mate open import Categories.Functor renaming (id to idF) open import Categories.Functor.Bifunctor open import Categories.Functor.Hom open import Categories.Category.Instance.Setoids open import Categories.NaturalTransformation hiding (id) open import Categories.NaturalTransformation.Properties open import Categories.NaturalTransformation.NaturalIsomorphism as NI record Closed : Set (levelOfTerm M) where open Monoidal M public field [-,-] : Bifunctor C.op C C adjoint : (-⊗ X) ⊣ appˡ [-,-] X mate : (f : X ⇒ Y) → Mate (adjoint {X}) (adjoint {Y}) (appʳ-nat ⊗ f) (appˡ-nat [-,-] f) module [-,-] = Functor [-,-] module adjoint {X} = Adjoint (adjoint {X}) module mate {X Y} f = Mate (mate {X} {Y} f) [_,-] : Obj → Functor C C [_,-] = appˡ [-,-] [-,_] : Obj → Functor C.op C [-,_] = appʳ [-,-] [_,_]₀ : Obj → Obj → Obj [ X , Y ]₀ = [-,-].F₀ (X , Y) [_,_]₁ : A ⇒ B → X ⇒ Y → [ B , X ]₀ ⇒ [ A , Y ]₀ [ f , g ]₁ = [-,-].F₁ (f , g) Hom[-⊗_,-] : ∀ X → Bifunctor C.op C (Setoids ℓ e) Hom[-⊗ X ,-] = adjoint.Hom[L-,-] {X} Hom[-,[_,-]] : ∀ X → Bifunctor C.op C (Setoids ℓ e) Hom[-,[ X ,-]] = adjoint.Hom[-,R-] {X} Hom-NI : ∀ {X : Obj} → NaturalIsomorphism Hom[-⊗ X ,-] Hom[-,[ X ,-]] Hom-NI = Hom-NI′ adjoint
algebraic-stack_agda0000_doc_4664
{-# OPTIONS --universe-polymorphism #-} module Categories.Bifunctor where open import Level open import Data.Product using (_,_; swap) open import Categories.Category open import Categories.Functor public open import Categories.Product Bifunctor : ∀ {o ℓ e} {o′ ℓ′ e′} {o′′ ℓ′′ e′′} → Category o ℓ e → Category o′ ℓ′ e′ → Category o′′ ℓ′′ e′′ → Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′ ⊔ o′′ ⊔ ℓ′′ ⊔ e′′) Bifunctor C D E = Functor (Product C D) E overlap-× : ∀ {o ℓ e} {o′₁ ℓ′₁ e′₁} {o′₂ ℓ′₂ e′₂} {C : Category o ℓ e} {D₁ : Category o′₁ ℓ′₁ e′₁} {D₂ : Category o′₂ ℓ′₂ e′₂} (H : Bifunctor D₁ D₂ C) {o″ ℓ″ e″} {E : Category o″ ℓ″ e″} (F : Functor E D₁) (G : Functor E D₂) → Functor E C overlap-× H F G = H ∘ (F ※ G) reduce-× : ∀ {o ℓ e} {o′₁ ℓ′₁ e′₁} {o′₂ ℓ′₂ e′₂} {C : Category o ℓ e} {D₁ : Category o′₁ ℓ′₁ e′₁} {D₂ : Category o′₂ ℓ′₂ e′₂} (H : Bifunctor D₁ D₂ C) {o″₁ ℓ″₁ e″₁} {E₁ : Category o″₁ ℓ″₁ e″₁} (F : Functor E₁ D₁) {o″₂ ℓ″₂ e″₂} {E₂ : Category o″₂ ℓ″₂ e″₂} (G : Functor E₂ D₂) → Bifunctor E₁ E₂ C reduce-× H F G = H ∘ (F ⁂ G) flip-bifunctor : ∀ {o ℓ e} {o′ ℓ′ e′} {o′′ ℓ′′ e′′} {C : Category o ℓ e} → {D : Category o′ ℓ′ e′} → {E : Category o′′ ℓ′′ e′′} → Bifunctor C D E → Bifunctor D C E flip-bifunctor {C = C} {D = D} {E = E} b = _∘_ b (Swap {C = C} {D = D})
algebraic-stack_agda0000_doc_4665
module Cats.Functor.Op where open import Cats.Category.Base open import Cats.Category.Op using (_ᵒᵖ) open import Cats.Functor using (Functor) open Functor Op : ∀ {lo la l≈ lo′ la′ l≈′} → {C : Category lo la l≈} {D : Category lo′ la′ l≈′} → Functor C D → Functor (C ᵒᵖ) (D ᵒᵖ) Op F = record { fobj = fobj F ; fmap = fmap F ; fmap-resp = fmap-resp F ; fmap-id = fmap-id F ; fmap-∘ = fmap-∘ F }
algebraic-stack_agda0000_doc_4666
module Tactic.Deriving.Quotable where open import Prelude open import Container.Traversable open import Tactic.Reflection open import Tactic.Reflection.Quote.Class open import Tactic.Deriving private -- Bootstrapping qVis : Visibility → Term qVis visible = con (quote visible) [] qVis hidden = con (quote hidden) [] qVis instance′ = con (quote instance′) [] qRel : Relevance → Term qRel relevant = con (quote relevant) [] qRel irrelevant = con (quote irrelevant) [] qArgInfo : ArgInfo → Term qArgInfo (arg-info v r) = con₂ (quote arg-info) (qVis v) (qRel r) qArg : Arg Term → Term qArg (arg i x) = con₂ (quote arg) (qArgInfo i) x qList : List Term → Term qList = foldr (λ x xs → con₂ (quote List._∷_) x xs) (con₀ (quote List.[])) -- Could compute this from the type of the dictionary constructor quoteType : Name → TC Type quoteType d = caseM instanceTelescope d (quote Quotable) of λ { (tel , vs) → pure $ telPi tel $ def d vs `→ def (quote Term) [] } dictConstructor : TC Name dictConstructor = caseM getConstructors (quote Quotable) of λ { (c ∷ []) → pure c ; _ → typeErrorS "impossible" } patArgs : Telescope → List (Arg Pattern) patArgs tel = map (var "x" <$_) tel quoteArgs′ : Nat → Telescope → List Term quoteArgs′ 0 _ = [] quoteArgs′ _ [] = [] quoteArgs′ (suc n) (a ∷ tel) = qArg (def₁ (quote `) (var n []) <$ a) ∷ quoteArgs′ n tel quoteArgs : Nat → Telescope → Term quoteArgs pars tel = qList $ replicate pars (qArg $ hArg (con₀ (quote Term.unknown))) ++ quoteArgs′ (length tel) tel constructorClause : Nat → Name → TC Clause constructorClause pars c = do tel ← drop pars ∘ fst ∘ telView <$> getType c pure (clause (vArg (con c (patArgs tel)) ∷ []) (con₂ (quote Term.con) (lit (name c)) (quoteArgs pars tel))) quoteClauses : Name → TC (List Clause) quoteClauses d = do n ← getParameters d caseM getConstructors d of λ where [] → pure [ absurd-clause (vArg absurd ∷ []) ] cs → mapM (constructorClause n) cs declareQuotableInstance : Name → Name → TC ⊤ declareQuotableInstance iname d = declareDef (iArg iname) =<< instanceType d (quote Quotable) defineQuotableInstance : Name → Name → TC ⊤ defineQuotableInstance iname d = do fname ← freshName ("quote[" & show d & "]") declareDef (vArg fname) =<< quoteType d dictCon ← dictConstructor defineFun iname (clause [] (con₁ dictCon (def₀ fname)) ∷ []) defineFun fname =<< quoteClauses d return _ deriveQuotable : Name → Name → TC ⊤ deriveQuotable iname d = declareQuotableInstance iname d >> defineQuotableInstance iname d
algebraic-stack_agda0000_doc_4667
open import Data.Product using ( _×_ ) open import FRP.LTL.ISet.Core using ( ISet ; ⌈_⌉ ; M⟦_⟧ ) open import FRP.LTL.Time using ( Time ) open import FRP.LTL.Time.Bound using ( fin ; _≺_ ) open import FRP.LTL.Time.Interval using ( [_⟩ ; sing ) module FRP.LTL.ISet.Until where data _Until_ (A B : ISet) (t : Time) : Set where now : M⟦ B ⟧ (sing t) → (A Until B) t later : ∀ {u} → .(t≺u : fin t ≺ fin u) → M⟦ A ⟧ [ t≺u ⟩ → M⟦ B ⟧ (sing u) → (A Until B) t _U_ : ISet → ISet → ISet A U B = ⌈ A Until B ⌉
algebraic-stack_agda0000_doc_4668
module Sets.ExtensionalPredicateSet where import Lvl open import Data open import Data.Boolean open import Data.Either as Either using (_‖_) open import Data.Tuple as Tuple using (_⨯_ ; _,_) open import Functional open import Function.Equals open import Function.Equals.Proofs open import Function.Inverse open import Function.Proofs open import Logic open import Logic.Propositional open import Logic.Propositional.Theorems open import Logic.Predicate open import Structure.Setoid renaming (_≡_ to _≡ₑ_) open import Structure.Function.Domain open import Structure.Function.Domain.Proofs open import Structure.Function open import Structure.Relator.Equivalence import Structure.Relator.Names as Names open import Structure.Relator.Properties open import Structure.Relator.Proofs open import Structure.Relator open import Syntax.Transitivity open import Type open import Type.Size private variable ℓ ℓₒ ℓₑ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓ₁ ℓ₂ ℓ₃ : Lvl.Level private variable T A A₁ A₂ B : Type{ℓ} -- A set of objects of a certain type where equality is based on setoids. -- This is defined by the containment predicate (_∋_) and a proof that it respects the setoid structure. -- (A ∋ a) is read "The set A contains the element a". -- Note: This is only a "set" within a certain type, so a collection of type PredSet(T) is actually a subcollection of T. record PredSet {ℓ ℓₒ ℓₑ} (T : Type{ℓₒ}) ⦃ equiv : Equiv{ℓₑ}(T) ⦄ : Type{Lvl.𝐒(ℓ) Lvl.⊔ ℓₒ Lvl.⊔ ℓₑ} where constructor intro field _∋_ : T → Stmt{ℓ} ⦃ preserve-equiv ⦄ : UnaryRelator(_∋_) open PredSet using (_∋_) public open PredSet using (preserve-equiv) -- Element-set relations. module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where -- The membership relation. -- (a ∈ A) is read "The element a is included in the set A". _∈_ : T → PredSet{ℓ}(T) → Stmt _∈_ = swap(_∋_) _∉_ : T → PredSet{ℓ}(T) → Stmt _∉_ = (¬_) ∘₂ (_∈_) _∌_ : PredSet{ℓ}(T) → T → Stmt _∌_ = (¬_) ∘₂ (_∋_) NonEmpty : PredSet{ℓ}(T) → Stmt NonEmpty(S) = ∃(_∈ S) -- Set-bounded quantifiers. module _ {T : Type{ℓₒ}} ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where ∀ₛ : PredSet{ℓ}(T) → (T → Stmt{ℓ₁}) → Stmt{ℓ Lvl.⊔ ℓ₁ Lvl.⊔ ℓₒ} ∀ₛ(S) P = ∀{elem : T} → (elem ∈ S) → P(elem) ∃ₛ : PredSet{ℓ}(T) → (T → Stmt{ℓ₁}) → Stmt{ℓ Lvl.⊔ ℓ₁ Lvl.⊔ ℓₒ} ∃ₛ(S) P = ∃(elem ↦ (elem ∈ S) ∧ P(elem)) -- Sets and set operations. module _ {T : Type{ℓₒ}} ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where -- An empty set. -- Contains nothing. ∅ : PredSet{ℓ}(T) ∅ ∋ x = Empty UnaryRelator.substitution (preserve-equiv ∅) = const id -- An universal set. -- Contains everything. -- Note: Everything as in every object of type T. 𝐔 : PredSet{ℓ}(T) 𝐔 ∋ x = Unit UnaryRelator.substitution (preserve-equiv 𝐔) = const id -- A singleton set (a set containing only one element). •_ : T → PredSet(T) (• a) ∋ x = x ≡ₑ a UnaryRelator.substitution (preserve-equiv (• a)) xy xa = symmetry(_≡ₑ_) xy 🝖 xa -- An union of two sets. -- Contains the elements that any of the both sets contain. _∪_ : PredSet{ℓ₁}(T) → PredSet{ℓ₂}(T) → PredSet(T) (A ∪ B) ∋ x = (A ∋ x) ∨ (B ∋ x) UnaryRelator.substitution (preserve-equiv (A ∪ B)) xy = Either.map (substitute₁(A ∋_) xy) (substitute₁(B ∋_) xy) infixr 1000 _∪_ -- An intersection of two sets. -- Contains the elements that both of the both sets contain. _∩_ : PredSet{ℓ₁}(T) → PredSet{ℓ₂}(T) → PredSet(T) (A ∩ B) ∋ x = (A ∋ x) ∧ (B ∋ x) UnaryRelator.substitution (preserve-equiv (A ∩ B)) xy = Tuple.map (substitute₁(A ∋_) xy) (substitute₁(B ∋_) xy) infixr 1001 _∩_ -- A complement of a set. -- Contains the elements that the set does not contain. ∁_ : PredSet{ℓ}(T) → PredSet(T) (∁ A) ∋ x = A ∌ x UnaryRelator.substitution (preserve-equiv (∁ A)) xy = contrapositiveᵣ (substitute₁(A ∋_) (symmetry(_≡ₑ_) xy)) infixr 1002 ∁_ -- A relative complement of a set. -- Contains the elements that the left set contains without the elements included in the right set.. _∖_ : PredSet{ℓ₁}(T) → PredSet{ℓ₂}(T) → PredSet(T) A ∖ B = (A ∩ (∁ B)) infixr 1001 _∖_ filter : (P : T → Stmt{ℓ₁}) ⦃ _ : UnaryRelator(P) ⦄ → PredSet{ℓ₂}(T) → PredSet(T) filter P(A) ∋ x = (x ∈ A) ∧ P(x) _⨯_.left (UnaryRelator.substitution (preserve-equiv (filter P A)) xy ([∧]-intro xA Px)) = substitute₁(A ∋_) xy xA _⨯_.right (UnaryRelator.substitution (preserve-equiv (filter P A)) xy ([∧]-intro xA Px)) = substitute₁(P) xy Px unapply : ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄ ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄ → (f : A → B) ⦃ func-f : Function(f) ⦄ → B → PredSet(A) unapply f(y) ∋ x = f(x) ≡ₑ y preserve-equiv (unapply f(y)) = [∘]-unaryRelator ⦃ rel = binary-unaryRelatorᵣ ⦃ rel-P = [≡]-binaryRelator ⦄ ⦄ ⊶ : ⦃ _ : Equiv{ℓₑ₂}(B) ⦄ → (f : A → B) → PredSet(B) ⊶ f ∋ y = ∃(x ↦ f(x) ≡ₑ y) preserve-equiv (⊶ f) = [∃]-unaryRelator ⦃ rel-P = binary-unaryRelatorₗ ⦃ rel-P = [≡]-binaryRelator ⦄ ⦄ unmap : ⦃ _ : Equiv{ℓₑ₁}(A) ⦄ ⦃ _ : Equiv{ℓₑ₂}(B) ⦄ → (f : A → B) ⦃ _ : Function(f) ⦄ → PredSet{ℓ}(B) → PredSet(A) (unmap f(Y)) ∋ x = f(x) ∈ Y preserve-equiv (unmap f x) = [∘]-unaryRelator map : ⦃ _ : Equiv{ℓₑ₁}(A) ⦄ ⦃ _ : Equiv{ℓₑ₂}(B) ⦄ → (f : A → B) → PredSet{ℓ}(A) → PredSet(B) map f(S) ∋ y = ∃(x ↦ (x ∈ S) ∧ (f(x) ≡ₑ y)) preserve-equiv (map f S) = [∃]-unaryRelator ⦃ rel-P = [∧]-unaryRelator ⦃ rel-Q = binary-unaryRelatorₗ ⦃ rel-P = [≡]-binaryRelator ⦄ ⦄ ⦄ map₂ : ⦃ _ : Equiv{ℓₑ₁}(A₁) ⦄ ⦃ _ : Equiv{ℓₑ₂}(A₂) ⦄ ⦃ _ : Equiv{ℓₑ₃}(B) ⦄ → (_▫_ : A₁ → A₂ → B) → PredSet{ℓ₁}(A₁) → PredSet{ℓ₂}(A₂) → PredSet(B) map₂(_▫_) S₁ S₂ ∋ y = ∃{Obj = _ ⨯ _}(\{(x₁ , x₂) → (x₁ ∈ S₁) ∧ (x₂ ∈ S₂) ∧ ((x₁ ▫ x₂) ≡ₑ y)}) preserve-equiv (map₂ (_▫_) S₁ S₂) = [∃]-unaryRelator ⦃ rel-P = [∧]-unaryRelator ⦃ rel-P = [∧]-unaryRelator ⦄ ⦃ rel-Q = binary-unaryRelatorₗ ⦃ rel-P = [≡]-binaryRelator ⦄ ⦄ ⦄ -- Set-set relations. module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where record _⊆_ (A : PredSet{ℓ₁}(T)) (B : PredSet{ℓ₂}(T)) : Stmt{Lvl.of(T) Lvl.⊔ ℓ₁ Lvl.⊔ ℓ₂} where constructor intro field proof : ∀{x} → (x ∈ A) → (x ∈ B) record _⊇_ (A : PredSet{ℓ₁}(T)) (B : PredSet{ℓ₂}(T)) : Stmt{Lvl.of(T) Lvl.⊔ ℓ₁ Lvl.⊔ ℓ₂} where constructor intro field proof : ∀{x} → (x ∈ A) ← (x ∈ B) record _≡_ (A : PredSet{ℓ₁}(T)) (B : PredSet{ℓ₂}(T)) : Stmt{Lvl.of(T) Lvl.⊔ ℓ₁ Lvl.⊔ ℓ₂} where constructor intro field proof : ∀{x} → (x ∈ A) ↔ (x ∈ B) instance [≡]-reflexivity : Reflexivity(_≡_ {ℓ}) Reflexivity.proof [≡]-reflexivity = intro [↔]-reflexivity instance [≡]-symmetry : Symmetry(_≡_ {ℓ}) Symmetry.proof [≡]-symmetry (intro xy) = intro([↔]-symmetry xy) [≡]-transitivity-raw : ∀{A : PredSet{ℓ₁}(T)}{B : PredSet{ℓ₂}(T)}{C : PredSet{ℓ₃}(T)} → (A ≡ B) → (B ≡ C) → (A ≡ C) [≡]-transitivity-raw (intro xy) (intro yz) = intro([↔]-transitivity xy yz) instance [≡]-transitivity : Transitivity(_≡_ {ℓ}) Transitivity.proof [≡]-transitivity (intro xy) (intro yz) = intro([↔]-transitivity xy yz) instance [≡]-equivalence : Equivalence(_≡_ {ℓ}) [≡]-equivalence = intro instance [≡]-equiv : Equiv(PredSet{ℓ}(T)) Equiv._≡_ ([≡]-equiv {ℓ}) x y = x ≡ y Equiv.equivalence [≡]-equiv = [≡]-equivalence module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where instance -- Note: The purpose of this module is to satisfy this property for arbitrary equivalences. [∋]-binaryRelator : BinaryRelator(_∋_ {ℓ}{T = T}) BinaryRelator.substitution [∋]-binaryRelator (intro pₛ) pₑ p = [↔]-to-[→] pₛ(substitute₁(_) pₑ p) instance [∋]-unaryRelatorₗ : ∀{a : T} → UnaryRelator(A ↦ _∋_ {ℓ} A a) [∋]-unaryRelatorₗ = BinaryRelator.left [∋]-binaryRelator -- TODO: There are level problems here that I am not sure how to solve. The big union of a set of sets are not of the same type as the inner sets. So, for example it would be useful if (⋃ As : PredSet{ℓₒ Lvl.⊔ Lvl.𝐒(ℓ₁)}(T)) and (A : PredSet{ℓ₁}(T)) for (A ∈ As) had the same type/levels when (As : PredSet{Lvl.𝐒(ℓ₁)}(PredSet{ℓ₁}(T))) so that they become comparable. But here, the result of big union is a level greater. module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where -- ⋃_ : PredSet{Lvl.𝐒(ℓ₁)}(PredSet{ℓ₁}(T)) → PredSet{ℓₒ Lvl.⊔ Lvl.𝐒(ℓ₁)}(T) ⋃ : PredSet{ℓ₁}(PredSet{ℓ₂}(T)) → PredSet(T) (⋃ As) ∋ x = ∃(A ↦ (A ∈ As) ∧ (x ∈ A)) UnaryRelator.substitution (preserve-equiv (⋃ As)) xy = [∃]-map-proof (Tuple.mapRight (substitute₁(_) xy)) ⋂ : PredSet{ℓ₁}(PredSet{ℓ₂}(T)) → PredSet(T) (⋂ As) ∋ x = ∀{A} → (A ∈ As) → (x ∈ A) UnaryRelator.substitution (preserve-equiv (⋂ As)) xy = substitute₁(_) xy ∘_ -- Indexed set operations. module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where ⋃ᵢ : ∀{I : Type{ℓ₁}} → (I → PredSet{ℓ₂}(T)) → PredSet{ℓ₁ Lvl.⊔ ℓ₂}(T) (⋃ᵢ Ai) ∋ x = ∃(i ↦ x ∈ Ai(i)) UnaryRelator.substitution (preserve-equiv (⋃ᵢ Ai)) xy = [∃]-map-proof (\{i} → substitute₁(_) ⦃ preserve-equiv(Ai(i)) ⦄ xy) ⋂ᵢ : ∀{I : Type{ℓ₁}} → (I → PredSet{ℓ₂}(T)) → PredSet{ℓ₁ Lvl.⊔ ℓ₂}(T) (⋂ᵢ Ai) ∋ x = ∀ₗ(i ↦ x ∈ Ai(i)) UnaryRelator.substitution (preserve-equiv (⋂ᵢ Ai)) xy p {i} = substitute₁(_) ⦃ preserve-equiv(Ai(i)) ⦄ xy p -- When the indexed union is indexed by a boolean, it is the same as the small union. ⋃ᵢ-of-boolean : ∀{A B : PredSet{ℓ}(T)} → ((⋃ᵢ{I = Bool}(if_then B else A)) ≡ (A ∪ B)) ∃.witness (_⨯_.left (_≡_.proof ⋃ᵢ-of-boolean) ([∨]-introₗ p)) = 𝐹 ∃.proof (_⨯_.left (_≡_.proof ⋃ᵢ-of-boolean) ([∨]-introₗ p)) = p ∃.witness (_⨯_.left (_≡_.proof ⋃ᵢ-of-boolean) ([∨]-introᵣ p)) = 𝑇 ∃.proof (_⨯_.left (_≡_.proof ⋃ᵢ-of-boolean) ([∨]-introᵣ p)) = p _⨯_.right (_≡_.proof ⋃ᵢ-of-boolean) ([∃]-intro 𝐹 ⦃ p ⦄) = [∨]-introₗ p _⨯_.right (_≡_.proof ⋃ᵢ-of-boolean) ([∃]-intro 𝑇 ⦃ p ⦄) = [∨]-introᵣ p -- When the indexed intersection is indexed by a boolean, it is the same as the small intersection. ⋂ᵢ-of-boolean : ∀{A B : PredSet{ℓ}(T)} → ((⋂ᵢ{I = Bool}(if_then B else A)) ≡ (A ∩ B)) _⨯_.left (_≡_.proof ⋂ᵢ-of-boolean) p {𝐹} = [∧]-elimₗ p _⨯_.left (_≡_.proof ⋂ᵢ-of-boolean) p {𝑇} = [∧]-elimᵣ p _⨯_.left (_⨯_.right (_≡_.proof ⋂ᵢ-of-boolean) p) = p{𝐹} _⨯_.right (_⨯_.right (_≡_.proof ⋂ᵢ-of-boolean) p) = p{𝑇} module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄ ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄ where ⋃ᵢ-of-bijection : ∀{f : B → PredSet{ℓ}(T)} ⦃ func-f : Function(f)⦄ → (([∃]-intro g) : A ≍ B) → (⋃ᵢ{I = A}(f ∘ g) ≡ ⋃ᵢ{I = B}(f)) ∃.witness (_⨯_.left (_≡_.proof (⋃ᵢ-of-bijection {f = f} ([∃]-intro g ⦃ bij-g ⦄))) ([∃]-intro b ⦃ p ⦄)) = inv g ⦃ bijective-to-invertible ⦄ (b) ∃.proof (_⨯_.left (_≡_.proof (⋃ᵢ-of-bijection {f = f} ([∃]-intro g ⦃ bij-g ⦄))) ([∃]-intro b ⦃ p ⦄)) = substitute₂(_∋_) (symmetry(_≡_) (congruence₁(f) (inverse-right(g)(inv g ⦃ bijective-to-invertible ⦄) ⦃ [∧]-elimᵣ([∃]-proof bijective-to-invertible) ⦄))) (reflexivity(_≡ₑ_)) p ∃.witness (_⨯_.right (_≡_.proof (⋃ᵢ-of-bijection {f = f} ([∃]-intro g ⦃ bij-g ⦄))) ([∃]-intro a ⦃ p ⦄)) = g(a) ∃.proof (_⨯_.right (_≡_.proof (⋃ᵢ-of-bijection {f = f} ([∃]-intro g ⦃ bij-g ⦄))) ([∃]-intro b ⦃ p ⦄)) = p ⋂ᵢ-of-bijection : ∀{f : B → PredSet{ℓ}(T)} ⦃ func-f : Function(f)⦄ → (([∃]-intro g) : A ≍ B) → (⋂ᵢ{I = A}(f ∘ g) ≡ ⋂ᵢ{I = B}(f)) _⨯_.left (_≡_.proof (⋂ᵢ-of-bijection {f = f} ([∃]-intro g ⦃ bij-g ⦄)) {x}) p {b} = p{g(b)} _⨯_.right (_≡_.proof (⋂ᵢ-of-bijection {f = f} ([∃]-intro g ⦃ bij-g ⦄)) {x}) p {b} = substitute₂(_∋_) (congruence₁(f) (inverse-right(g)(inv g ⦃ bijective-to-invertible ⦄) ⦃ [∧]-elimᵣ([∃]-proof bijective-to-invertible) ⦄)) (reflexivity(_≡ₑ_)) (p{inv g ⦃ bijective-to-invertible ⦄ (b)}) module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where instance singleton-function : ∀{A : Type{ℓ}} ⦃ _ : Equiv{ℓₑ}(A) ⦄ → Function{A = A}(•_) _≡_.proof (Function.congruence singleton-function {x} {y} xy) {a} = [↔]-intro (_🝖 symmetry(_≡ₑ_) xy) (_🝖 xy)
algebraic-stack_agda0000_doc_4669
open import MLib.Prelude open import MLib.Algebra.PropertyCode open import MLib.Algebra.PropertyCode.Structures module MLib.Matrix.Plus {c ℓ} (struct : Struct bimonoidCode c ℓ) {m n : ℕ} where open import MLib.Matrix.Core open import MLib.Matrix.Equality struct open FunctionProperties -- Pointwise addition -- infixl 6 _⊕_ _⊕_ : Matrix S m n → Matrix S m n → Matrix S m n (A ⊕ B) i j = A i j ⟨ + ⟩ B i j ⊕-cong : Congruent₂ _⊕_ ⊕-cong p q = λ i j → S.cong + (p i j) (q i j) ⊕-assoc : ⦃ props : Has₁ (associative on +) ⦄ → Associative _⊕_ ⊕-assoc ⦃ props ⦄ A B C i j = from props (associative on +) (A i j) (B i j) (C i j) 0● : Matrix S m n 0● _ _ = ⟦ 0# ⟧ ⊕-identityˡ : ⦃ props : Has₁ (0# is leftIdentity for +) ⦄ → LeftIdentity 0● _⊕_ ⊕-identityˡ ⦃ props ⦄ A i j = from props (0# is leftIdentity for +) (A i j) ⊕-identityʳ : ⦃ props : Has₁ (0# is rightIdentity for +) ⦄ → RightIdentity 0● _⊕_ ⊕-identityʳ ⦃ props ⦄ A i j = from props (0# is rightIdentity for +) (A i j) ⊕-comm : ⦃ props : Has₁ (commutative on +) ⦄ → Commutative _⊕_ ⊕-comm ⦃ props ⦄ A B i j = from props (commutative on +) (A i j) (B i j)
algebraic-stack_agda0000_doc_4670
{- Practical Relational Algebra Toon Nolten based on The Power Of Pi -} module relational-algebra where open import Data.Empty open import Data.Unit hiding (_≤_) open import Data.Bool open import Data.Nat open import Data.Integer hiding (show) open import Data.List open import Data.Char hiding (_==_) renaming (show to charToString) open import Data.Vec hiding (_++_; lookup; map; foldr; _>>=_) open import Data.String using (String; toVec; _==_; strictTotalOrder) renaming (_++_ to _∥_) open import Data.Product using (_×_; _,_; proj₁) open import Coinduction open import IO open import Relation.Binary open StrictTotalOrder Data.String.strictTotalOrder renaming (compare to str_cmp) data Order : Set where LT EQ GT : Order module InsertionSort where insert : {A : Set} → (A → A → Order) → A → List A → List A insert _ e [] = e ∷ [] insert cmp e (l ∷ ls) with cmp e l ... | GT = l ∷ insert cmp e ls ... | _ = e ∷ l ∷ ls sort : {A : Set} → (A → A → Order) → List A → List A sort cmp = foldr (insert cmp) [] open InsertionSort using (insert; sort) -- Universe U exists of type U and el : U → Set data U : Set where CHAR NAT BOOL : U VEC : U → ℕ → U el : U → Set el CHAR = Char el NAT = ℕ el (VEC u n) = Vec (el u) n el BOOL = Bool parens : String → String parens str = "(" ∥ str ∥ ")" show : {u : U} → el u → String show {CHAR } c = charToString c show {NAT } zero = "Zero" show {NAT } (suc k) = "Succ " ∥ parens (show k) show {VEC u zero } Nil = "Nil" show {VEC u (suc k)} (x ∷ xs) = parens (show x) ∥ " ∷ " ∥ parens (show xs) show {BOOL } true = "True" show {BOOL } false = "False" _=ᴺ_ : ℕ → ℕ → Bool zero =ᴺ zero = true suc m =ᴺ suc n = (m =ᴺ n) _ =ᴺ _ = false _≤ᴺ_ : ℕ → ℕ → Order zero ≤ᴺ zero = EQ zero ≤ᴺ _ = LT _ ≤ᴺ zero = GT suc a ≤ᴺ suc b = a ≤ᴺ b _=ᵁ_ : U → U → Bool CHAR =ᵁ CHAR = true NAT =ᵁ NAT = true BOOL =ᵁ BOOL = true VEC u x =ᵁ VEC u' x' = (u =ᵁ u') ∧ (x =ᴺ x') _ =ᵁ _ = false _≤ᵁ_ : U → U → Order CHAR ≤ᵁ CHAR = EQ CHAR ≤ᵁ _ = LT _ ≤ᵁ CHAR = GT NAT ≤ᵁ NAT = EQ NAT ≤ᵁ _ = LT _ ≤ᵁ NAT = GT BOOL ≤ᵁ BOOL = EQ BOOL ≤ᵁ _ = LT _ ≤ᵁ BOOL = GT VEC a x ≤ᵁ VEC b y with a ≤ᵁ b ... | LT = LT ... | EQ = x ≤ᴺ y ... | GT = GT So : Bool → Set So true = ⊤ So false = ⊥ data SqlValue : Set where SqlString : String → SqlValue SqlChar : Char → SqlValue SqlBool : Bool → SqlValue SqlInteger : ℤ → SqlValue --{-# COMPILED_DATA SqlValue SqlValue SqlString SqlChar SqlBool SqlInteger #-} module OrderedSchema where SchemaDescription = List (List SqlValue) Attribute : Set Attribute = String × U -- Compare on type if names are equal. -- SQL DB's probably don't allow columns with the same name -- but nothing prevents us from writing a Schema that does, -- this is necessary to make our sort return a unique answer. attr_cmp : Attribute → Attribute → Order attr_cmp (nm₁ , U₁) (nm₂ , U₂) with str_cmp nm₁ nm₂ | U₁ ≤ᵁ U₂ ... | tri< _ _ _ | _ = LT ... | tri≈ _ _ _ | U₁≤U₂ = U₁≤U₂ ... | tri> _ _ _ | _ = GT data Schema : Set where sorted : List Attribute → Schema mkSchema : List Attribute → Schema mkSchema xs = sorted (sort attr_cmp xs) expandSchema : Attribute → Schema → Schema expandSchema x (sorted xs) = sorted (insert attr_cmp x xs) schemify : SchemaDescription → Schema schemify sdesc = {!!} disjoint : Schema → Schema → Bool disjoint (sorted [] ) (_ ) = true disjoint (_ ) (sorted [] ) = true disjoint (sorted (x ∷ xs)) (sorted (y ∷ ys)) with attr_cmp x y ... | LT = disjoint (sorted xs ) (sorted (y ∷ ys)) ... | EQ = false ... | GT = disjoint (sorted (x ∷ xs)) (sorted ys ) sub : Schema → Schema → Bool sub (sorted [] ) (_ ) = true sub (sorted (x ∷ _) ) (sorted [] ) = false sub (sorted (x ∷ xs)) (sorted (X ∷ Xs)) with attr_cmp x X ... | LT = false ... | EQ = sub (sorted xs ) (sorted Xs) ... | GT = sub (sorted (x ∷ xs)) (sorted Xs) same' : List Attribute → List Attribute → Bool same' ([] ) ([] ) = true same' ((nm₁ , ty₁) ∷ xs) ((nm₂ , ty₂) ∷ ys) = (nm₁ == nm₂) ∧ (ty₁ =ᵁ ty₂) ∧ same' xs ys same' (_ ) (_ ) = false same : Schema → Schema → Bool same (sorted xs) (sorted ys) = same' xs ys occurs : String → Schema → Bool occurs nm (sorted s) = any (_==_ nm) (map (proj₁) s) lookup' : (nm : String) → (s : List Attribute) → So (occurs nm (sorted s)) → U lookup' _ [] () lookup' nm ((name , type) ∷ s') p with nm == name ... | true = type ... | false = lookup' nm s' p lookup : (nm : String) → (s : Schema) → So (occurs nm s) → U lookup nm (sorted s) = lookup' nm s append : (s s' : Schema) → Schema append (sorted s) (sorted s') = mkSchema (s ++ s') open OrderedSchema using (Schema; mkSchema; expandSchema; schemify; disjoint; sub; same; occurs; lookup; append) data Row : Schema → Set where EmptyRow : Row (mkSchema []) ConsRow : ∀ {name u s} → el u → Row s → Row (expandSchema (name , u) s) Table : Schema → Set Table s = List (Row s) DatabasePath = String TableName = String postulate Connection : Set connectSqlite3 : DatabasePath → IO Connection describe_table : TableName → Connection → IO (List (List SqlValue)) -- {-# COMPILED_TYPE Connection Connection #-} -- {-# COMPILED connectSqlite3 connectSqlite3 #-} -- {-# COMPILED describe_table describe_table #-} data Handle : Schema → Set where conn : Connection → (s : Schema) → Handle s -- Connect currently ignores differences between -- the expected schema and the actual schema. -- According to tpop this should result in -- "a *runtime exception* in the *IO* monad." -- Agda does not have exceptions(?) -- -> postulate error with a compiled pragma? connect : DatabasePath → TableName → (s : Schema) → IO (Handle s) connect DB table schema_expect = ♯ (connectSqlite3 DB) >>= (λ sqlite_conn → ♯ (♯ (describe_table table sqlite_conn) >>= (λ description → ♯ (♯ (return (schemify description)) >>= (λ schema_actual → ♯ (♯ (return (same schema_expect schema_actual)) >>= (λ { true → ♯ (return (conn sqlite_conn schema_expect)); false → ♯ (return (conn sqlite_conn schema_expect)) }))))))) data Expr : Schema → U → Set where equal : ∀ {u s} → Expr s u → Expr s u → Expr s BOOL lessThan : ∀ {u s} → Expr s u → Expr s u → Expr s BOOL _!_ : (s : Schema) → (nm : String) → {p : So (occurs nm s)} → Expr s (lookup nm s p) data RA : Schema → Set where Read : ∀ {s} → Handle s → RA s Union : ∀ {s} → RA s → RA s → RA s Diff : ∀ {s} → RA s → RA s → RA s Product : ∀ {s s'} → {_ : So (disjoint s s')} → RA s → RA s' → RA (append s s') Project : ∀ {s} → (s' : Schema) → {_ : So (sub s' s)} → RA s → RA s' Select : ∀ {s} → Expr s BOOL → RA s → RA s -- ... {- As we mentioned previously, we have taken a very minimal set of relational algebra operators. It should be fairly straightforward to add operators for the many other operators in relational algebra, such as the natural join, θ-join, equijoin, renaming, or division, using the same techniques. Alternatively, you can define many of these operations in terms of the operations we have implemented in the RA data type. -} -- We could: postulate toSQL : ∀ {s} → RA s → String -- We can do much better: postulate query : {s : Schema} → RA s → IO (List (Row s)) {- The *query* function uses *toSQL* to produce a query, and passes this to the database server. When the server replies, however, we know exactly how to parse the response: we know the schema of the table resulting from our query, and can use this to parse the database server's response in a type-safe manner. The type checker can then statically check that the program uses the returned list in a way consistent with its type. -} Cars : Schema Cars = mkSchema (("Model" , VEC CHAR 20) ∷ ("Time" , VEC CHAR 6) ∷ ("Wet" , BOOL) ∷ []) zonda : Row Cars zonda = ConsRow (toVec "Pagani Zonda C12 F ") (ConsRow (toVec "1:18.4") (ConsRow false EmptyRow)) Models : Schema Models = mkSchema (("Model" , VEC CHAR 20) ∷ []) models : Handle Cars → RA Models models h = Project Models (Read h) wet : Handle Cars → RA Models wet h = Project Models (Select (Cars ! "Wet") (Read h)) {- Discussion ========== There are many, many aspects of this proposal that can be improved. Some attributes of a schema contain *NULL*-values; we should close our universe under *Maybe* accordingly. Some database servers silently truncate strings longer than 255 characters. We would do well to ensure statically that this never happens. Our goal, however, was not to provide a complete model of all of SQL's quirks and idiosyncrasies: we want to show how a language with dependent types can schine where Haskell struggles. Our choice of *Schema* data type suffers from the usual disadvantages of using a list to represent a set: our *Schema* data type may contain duplicates and the order of the elements matters. The first problem is easy to solve. Using an implicit proof argument in the *Cons* case, we can define a data type for lists that do not contain duplicates. The type of *Cons* then becomes: Cons : (nm : String) → (u : U) → (s : Schema) → {_ : So (not (elem nm s))} → Schema The second point is a bit trickier. The real solution would involve quotient types to make the order of the elements unobservable. As Agda does not support quotient types, however, the best we can do is parameterise our constructors by an additional proof argument, when necessary. For example, the *Union* constructor could be defined as follows: Union : ∀ {s s'} → {_ : So (permute s s')} → RA s → RA s' → RA s Instead of requiring that both arguments of *Union* are indexed by the same schema, we should only require that the two schemas are equal up to a permutation of the elements. Alternatively, we could represent the *Schema* using a data structure that fixes the order in which its constituent elements occur, such as a trie or sorted list. Finally, we would like to return to our example table. We chose to model the lap time as a fixed-length string ─ clearly, a triple of integers would be a better representation. Unfortunately, most database servers only support a handful of built-in types, such as strings, numbers, bits. There is no way to extend these primitive types. This problem is sometimes referred to as the *object-relational impedance mismatch*. We believe the generic programming techniques and views from the previous sections can be used to marshall data between a low-level representation in the database and the high-level representation in our programming language. -}
algebraic-stack_agda0000_doc_4671
{-# OPTIONS --without-K --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped as U open import Definition.Typed open import Definition.Typed.Weakening open import Agda.Primitive open import Tools.Product open import Tools.Embedding import Tools.PropositionalEquality as PE -- The different cases of the logical relation are spread out through out -- this file. This is due to them having different dependencies. -- We will refer to expressions that satisfies the logical relation as reducible. -- Reducibility of Neutrals: -- Neutral type record _⊩ne_ (Γ : Con Term) (A : Term) : Set where constructor ne field K : Term D : Γ ⊢ A :⇒*: K neK : Neutral K K≡K : Γ ⊢ K ~ K ∷ U -- Neutral type equality record _⊩ne_≡_/_ (Γ : Con Term) (A B : Term) ([A] : Γ ⊩ne A) : Set where constructor ne₌ open _⊩ne_ [A] field M : Term D′ : Γ ⊢ B :⇒*: M neM : Neutral M K≡M : Γ ⊢ K ~ M ∷ U -- Neutral term in WHNF record _⊩neNf_∷_ (Γ : Con Term) (k A : Term) : Set where inductive constructor neNfₜ field neK : Neutral k ⊢k : Γ ⊢ k ∷ A k≡k : Γ ⊢ k ~ k ∷ A -- Neutral term record _⊩ne_∷_/_ (Γ : Con Term) (t A : Term) ([A] : Γ ⊩ne A) : Set where inductive constructor neₜ open _⊩ne_ [A] field k : Term d : Γ ⊢ t :⇒*: k ∷ K nf : Γ ⊩neNf k ∷ K -- Neutral term equality in WHNF record _⊩neNf_≡_∷_ (Γ : Con Term) (k m A : Term) : Set where inductive constructor neNfₜ₌ field neK : Neutral k neM : Neutral m k≡m : Γ ⊢ k ~ m ∷ A -- Neutral term equality record _⊩ne_≡_∷_/_ (Γ : Con Term) (t u A : Term) ([A] : Γ ⊩ne A) : Set where constructor neₜ₌ open _⊩ne_ [A] field k m : Term d : Γ ⊢ t :⇒*: k ∷ K d′ : Γ ⊢ u :⇒*: m ∷ K nf : Γ ⊩neNf k ≡ m ∷ K -- Reducibility of natural numbers: -- Natural number type _⊩ℕ_ : (Γ : Con Term) (A : Term) → Set Γ ⊩ℕ A = Γ ⊢ A :⇒*: ℕ -- Natural number type equality data _⊩ℕ_≡_ (Γ : Con Term) (A B : Term) : Set where ℕ₌ : Γ ⊢ B ⇒* ℕ → Γ ⊩ℕ A ≡ B mutual -- Natural number term data _⊩ℕ_∷ℕ (Γ : Con Term) (t : Term) : Set where ℕₜ : (n : Term) (d : Γ ⊢ t :⇒*: n ∷ ℕ) (n≡n : Γ ⊢ n ≅ n ∷ ℕ) (prop : Natural-prop Γ n) → Γ ⊩ℕ t ∷ℕ -- WHNF property of natural number terms data Natural-prop (Γ : Con Term) : (n : Term) → Set where sucᵣ : ∀ {n} → Γ ⊩ℕ n ∷ℕ → Natural-prop Γ (suc n) zeroᵣ : Natural-prop Γ zero ne : ∀ {n} → Γ ⊩neNf n ∷ ℕ → Natural-prop Γ n mutual -- Natural number term equality data _⊩ℕ_≡_∷ℕ (Γ : Con Term) (t u : Term) : Set where ℕₜ₌ : (k k′ : Term) (d : Γ ⊢ t :⇒*: k ∷ ℕ) (d′ : Γ ⊢ u :⇒*: k′ ∷ ℕ) (k≡k′ : Γ ⊢ k ≅ k′ ∷ ℕ) (prop : [Natural]-prop Γ k k′) → Γ ⊩ℕ t ≡ u ∷ℕ -- WHNF property of Natural number term equality data [Natural]-prop (Γ : Con Term) : (n n′ : Term) → Set where sucᵣ : ∀ {n n′} → Γ ⊩ℕ n ≡ n′ ∷ℕ → [Natural]-prop Γ (suc n) (suc n′) zeroᵣ : [Natural]-prop Γ zero zero ne : ∀ {n n′} → Γ ⊩neNf n ≡ n′ ∷ ℕ → [Natural]-prop Γ n n′ -- Natural extraction from term WHNF property natural : ∀ {Γ n} → Natural-prop Γ n → Natural n natural (sucᵣ x) = sucₙ natural zeroᵣ = zeroₙ natural (ne (neNfₜ neK ⊢k k≡k)) = ne neK -- Natural extraction from term equality WHNF property split : ∀ {Γ a b} → [Natural]-prop Γ a b → Natural a × Natural b split (sucᵣ x) = sucₙ , sucₙ split zeroᵣ = zeroₙ , zeroₙ split (ne (neNfₜ₌ neK neM k≡m)) = ne neK , ne neM -- Type levels data TypeLevel : Set where ⁰ : TypeLevel ¹ : TypeLevel data _<_ : (i j : TypeLevel) → Set where 0<1 : ⁰ < ¹ toLevel : TypeLevel → Level toLevel ⁰ = lzero toLevel ¹ = lsuc lzero -- Logical relation record LogRelKit (ℓ : Level) : Set (lsuc (lsuc ℓ)) where constructor Kit field _⊩U : (Γ : Con Term) → Set (lsuc ℓ) _⊩Π_ : (Γ : Con Term) → Term → Set (lsuc ℓ) _⊩_ : (Γ : Con Term) → Term → Set (lsuc ℓ) _⊩_≡_/_ : (Γ : Con Term) (A B : Term) → Γ ⊩ A → Set ℓ _⊩_∷_/_ : (Γ : Con Term) (t A : Term) → Γ ⊩ A → Set ℓ _⊩_≡_∷_/_ : (Γ : Con Term) (t u A : Term) → Γ ⊩ A → Set ℓ module LogRel (l : TypeLevel) (rec : ∀ {l′} → l′ < l → LogRelKit (toLevel l)) where record _⊩¹U (Γ : Con Term) : Set (lsuc (lsuc (toLevel l))) where constructor Uᵣ field l′ : TypeLevel l< : l′ < l ⊢Γ : ⊢ Γ -- Universe type equality record _⊩¹U≡_ (Γ : Con Term) (B : Term) : Set (lsuc (toLevel l)) where constructor U₌ field B≡U : B PE.≡ U -- Universe term record _⊩¹U_∷U/_ {l′} (Γ : Con Term) (t : Term) (l< : l′ < l) : Set (lsuc (toLevel l)) where constructor Uₜ open LogRelKit (rec l<) field A : Term d : Γ ⊢ t :⇒*: A ∷ U typeA : Type A A≡A : Γ ⊢ A ≅ A ∷ U [t] : Γ ⊩ t -- Universe term equality record _⊩¹U_≡_∷U/_ {l′} (Γ : Con Term) (t u : Term) (l< : l′ < l) : Set (lsuc (toLevel l)) where constructor Uₜ₌ open LogRelKit (rec l<) field A B : Term d : Γ ⊢ t :⇒*: A ∷ U d′ : Γ ⊢ u :⇒*: B ∷ U typeA : Type A typeB : Type B A≡B : Γ ⊢ A ≅ B ∷ U [t] : Γ ⊩ t [u] : Γ ⊩ u [t≡u] : Γ ⊩ t ≡ u / [t] RedRel : Set (lsuc (lsuc (lsuc (toLevel l)))) RedRel = Con Term → Term → (Term → Set (lsuc (toLevel l))) → (Term → Set (lsuc (toLevel l))) → (Term → Term → Set (lsuc (toLevel l))) → Set (lsuc (lsuc (toLevel l))) record _⊩⁰_/_ (Γ : Con Term) (A : Term) (_⊩_▸_▸_▸_ : RedRel) : Set (lsuc (lsuc (toLevel l))) where inductive eta-equality constructor LRPack field ⊩Eq : Term → Set (lsuc (toLevel l)) ⊩Term : Term → Set (lsuc (toLevel l)) ⊩EqTerm : Term → Term → Set (lsuc (toLevel l)) ⊩LR : Γ ⊩ A ▸ ⊩Eq ▸ ⊩Term ▸ ⊩EqTerm _⊩⁰_≡_/_ : {R : RedRel} (Γ : Con Term) (A B : Term) → Γ ⊩⁰ A / R → Set (lsuc (toLevel l)) Γ ⊩⁰ A ≡ B / LRPack ⊩Eq ⊩Term ⊩EqTerm ⊩Red = ⊩Eq B _⊩⁰_∷_/_ : {R : RedRel} (Γ : Con Term) (t A : Term) → Γ ⊩⁰ A / R → Set (lsuc (toLevel l)) Γ ⊩⁰ t ∷ A / LRPack ⊩Eq ⊩Term ⊩EqTerm ⊩Red = ⊩Term t _⊩⁰_≡_∷_/_ : {R : RedRel} (Γ : Con Term) (t u A : Term) → Γ ⊩⁰ A / R → Set (lsuc (toLevel l)) Γ ⊩⁰ t ≡ u ∷ A / LRPack ⊩Eq ⊩Term ⊩EqTerm ⊩Red = ⊩EqTerm t u record _⊩¹Π_/_ (Γ : Con Term) (A : Term) (R : RedRel) : Set (lsuc (lsuc (toLevel l))) where inductive eta-equality constructor Πᵣ field F : Term G : Term D : Γ ⊢ A :⇒*: Π F ▹ G ⊢F : Γ ⊢ F ⊢G : Γ ∙ F ⊢ G A≡A : Γ ⊢ Π F ▹ G ≅ Π F ▹ G [F] : ∀ {ρ Δ} → ρ ∷ Δ ⊆ Γ → (⊢Δ : ⊢ Δ) → Δ ⊩⁰ U.wk ρ F / R [G] : ∀ {ρ Δ a} → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ → Δ ⊩⁰ U.wk (lift ρ) G [ a ] / R G-ext : ∀ {ρ Δ a b} → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → ([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ) → ([b] : Δ ⊩⁰ b ∷ U.wk ρ F / [F] [ρ] ⊢Δ) → Δ ⊩⁰ a ≡ b ∷ U.wk ρ F / [F] [ρ] ⊢Δ → Δ ⊩⁰ U.wk (lift ρ) G [ a ] ≡ U.wk (lift ρ) G [ b ] / [G] [ρ] ⊢Δ [a] record _⊩¹Π_≡_/_ {R : RedRel} (Γ : Con Term) (A B : Term) ([A] : Γ ⊩¹Π A / R) : Set (lsuc (toLevel l)) where inductive eta-equality constructor Π₌ open _⊩¹Π_/_ [A] field F′ : Term G′ : Term D′ : Γ ⊢ B ⇒* Π F′ ▹ G′ A≡B : Γ ⊢ Π F ▹ G ≅ Π F′ ▹ G′ [F≡F′] : ∀ {ρ Δ} → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Δ ⊩⁰ U.wk ρ F ≡ U.wk ρ F′ / [F] [ρ] ⊢Δ [G≡G′] : ∀ {ρ Δ a} → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → ([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ) → Δ ⊩⁰ U.wk (lift ρ) G [ a ] ≡ U.wk (lift ρ) G′ [ a ] / [G] [ρ] ⊢Δ [a] -- Term of Π-type _⊩¹Π_∷_/_ : {R : RedRel} (Γ : Con Term) (t A : Term) ([A] : Γ ⊩¹Π A / R) → Set (lsuc (toLevel l)) Γ ⊩¹Π t ∷ A / Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext = ∃ λ f → Γ ⊢ t :⇒*: f ∷ Π F ▹ G × Function f × Γ ⊢ f ≅ f ∷ Π F ▹ G × (∀ {ρ Δ a b} → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) ([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ) ([b] : Δ ⊩⁰ b ∷ U.wk ρ F / [F] [ρ] ⊢Δ) ([a≡b] : Δ ⊩⁰ a ≡ b ∷ U.wk ρ F / [F] [ρ] ⊢Δ) → Δ ⊩⁰ U.wk ρ f ∘ a ≡ U.wk ρ f ∘ b ∷ U.wk (lift ρ) G [ a ] / [G] [ρ] ⊢Δ [a]) × (∀ {ρ Δ a} → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → ([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ) → Δ ⊩⁰ U.wk ρ f ∘ a ∷ U.wk (lift ρ) G [ a ] / [G] [ρ] ⊢Δ [a]) -- Issue: Agda complains about record use not being strictly positive. -- Therefore we have to use × -- Term equality of Π-type _⊩¹Π_≡_∷_/_ : {R : RedRel} (Γ : Con Term) (t u A : Term) ([A] : Γ ⊩¹Π A / R) → Set (lsuc (toLevel l)) Γ ⊩¹Π t ≡ u ∷ A / Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext = let [A] = Πᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext in ∃₂ λ f g → Γ ⊢ t :⇒*: f ∷ Π F ▹ G × Γ ⊢ u :⇒*: g ∷ Π F ▹ G × Function f × Function g × Γ ⊢ f ≅ g ∷ Π F ▹ G × Γ ⊩¹Π t ∷ A / [A] × Γ ⊩¹Π u ∷ A / [A] × (∀ {ρ Δ a} → ([ρ] : ρ ∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → ([a] : Δ ⊩⁰ a ∷ U.wk ρ F / [F] [ρ] ⊢Δ) → Δ ⊩⁰ U.wk ρ f ∘ a ≡ U.wk ρ g ∘ a ∷ U.wk (lift ρ) G [ a ] / [G] [ρ] ⊢Δ [a]) -- Issue: Same as above. -- Logical relation definition data _⊩LR_▸_▸_▸_ : RedRel where LRU : ∀ {Γ} (⊢Γ : ⊢ Γ) → (l' : TypeLevel) → (l< : l' < l) → Γ ⊩LR U ▸ (λ B → Γ ⊩¹U≡ B) ▸ (λ t → Γ ⊩¹U t ∷U/ l<) ▸ (λ t u → Γ ⊩¹U t ≡ u ∷U/ l<) LRℕ : ∀ {Γ A} → Γ ⊩ℕ A → Γ ⊩LR A ▸ (λ B → ι′ (Γ ⊩ℕ A ≡ B)) ▸ (λ t → ι′ (Γ ⊩ℕ t ∷ℕ)) ▸ (λ t u → ι′ (Γ ⊩ℕ t ≡ u ∷ℕ)) LRne : ∀ {Γ A} → (neA : Γ ⊩ne A) → Γ ⊩LR A ▸ (λ B → ι′ (Γ ⊩ne A ≡ B / neA)) ▸ (λ t → ι′ (Γ ⊩ne t ∷ A / neA)) ▸ (λ t u → ι′ (Γ ⊩ne t ≡ u ∷ A / neA)) LRΠ : ∀ {Γ A} → (ΠA : Γ ⊩¹Π A / _⊩LR_▸_▸_▸_) → Γ ⊩LR A ▸ (λ B → Γ ⊩¹Π A ≡ B / ΠA) ▸ (λ t → Γ ⊩¹Π t ∷ A / ΠA) ▸ (λ t u → Γ ⊩¹Π t ≡ u ∷ A / ΠA) LRemb : ∀ {Γ A l′} (l< : l′ < l) (let open LogRelKit (rec l<)) ([A] : Γ ⊩ A) → Γ ⊩LR A ▸ (λ B → ι (Γ ⊩ A ≡ B / [A])) ▸ (λ t → ι (Γ ⊩ t ∷ A / [A])) ▸ (λ t u → ι (Γ ⊩ t ≡ u ∷ A / [A])) _⊩¹_ : (Γ : Con Term) → (A : Term) → Set (lsuc (lsuc (toLevel l))) Γ ⊩¹ A = Γ ⊩⁰ A / _⊩LR_▸_▸_▸_ _⊩¹_≡_/_ : (Γ : Con Term) (A B : Term) → Γ ⊩¹ A → Set (lsuc (toLevel l)) Γ ⊩¹ A ≡ B / [A] = Γ ⊩⁰ A ≡ B / [A] _⊩¹_∷_/_ : (Γ : Con Term) (t A : Term) → Γ ⊩¹ A → Set (lsuc (toLevel l)) Γ ⊩¹ t ∷ A / [A] = Γ ⊩⁰ t ∷ A / [A] _⊩¹_≡_∷_/_ : (Γ : Con Term) (t u A : Term) → Γ ⊩¹ A → Set (lsuc (toLevel l)) Γ ⊩¹ t ≡ u ∷ A / [A] = Γ ⊩⁰ t ≡ u ∷ A / [A] open LogRel public using (Uᵣ; Πᵣ; Π₌; U₌ ; Uₜ; Uₜ₌ ; LRU ; LRℕ ; LRne ; LRΠ ; LRemb ; LRPack) pattern Πₜ f d funcF f≡f [f] [f]₁ = f , d , funcF , f≡f , [f] , [f]₁ pattern Πₜ₌ f g d d′ funcF funcG f≡g [f] [g] [f≡g] = f , g , d , d′ , funcF , funcG , f≡g , [f] , [g] , [f≡g] pattern ℕᵣ a = LRPack _ _ _ (LRℕ a) pattern emb′ a b = LRPack _ _ _ (LRemb a b) pattern Uᵣ′ a b c = LRPack _ _ _ (LRU c a b) pattern ne′ a b c d = LRPack _ _ _ (LRne (ne a b c d)) pattern Πᵣ′ a b c d e f g h i = LRPack _ _ _ (LRΠ (Πᵣ a b c d e f g h i)) kit₀ : LogRelKit (lsuc (lzero)) kit₀ = Kit _⊩¹U (λ Γ A → Γ ⊩¹Π A / _⊩LR_▸_▸_▸_) _⊩¹_ _⊩¹_≡_/_ _⊩¹_∷_/_ _⊩¹_≡_∷_/_ where open LogRel ⁰ (λ ()) logRelRec : ∀ l {l′} → l′ < l → LogRelKit (toLevel l) logRelRec ⁰ = λ () logRelRec ¹ 0<1 = kit₀ kit : ∀ (l : TypeLevel) → LogRelKit (lsuc (toLevel l)) kit l = Kit _⊩¹U (λ Γ A → Γ ⊩¹Π A / _⊩LR_▸_▸_▸_) _⊩¹_ _⊩¹_≡_/_ _⊩¹_∷_/_ _⊩¹_≡_∷_/_ where open LogRel l (logRelRec l) -- a bit of repetition in "kit ¹" definition, would work better with Fin 2 for -- TypeLevel because you could recurse. record _⊩′⟨_⟩U (Γ : Con Term) (l : TypeLevel) : Set where constructor Uᵣ field l′ : TypeLevel l< : l′ < l ⊢Γ : ⊢ Γ _⊩′⟨_⟩Π_ : (Γ : Con Term) (l : TypeLevel) → Term → Set (lsuc (lsuc (toLevel l))) Γ ⊩′⟨ l ⟩Π A = Γ ⊩Π A where open LogRelKit (kit l) _⊩⟨_⟩_ : (Γ : Con Term) (l : TypeLevel) → Term → Set (lsuc (lsuc (toLevel l))) Γ ⊩⟨ l ⟩ A = Γ ⊩ A where open LogRelKit (kit l) _⊩⟨_⟩_≡_/_ : (Γ : Con Term) (l : TypeLevel) (A B : Term) → Γ ⊩⟨ l ⟩ A → Set (lsuc (toLevel l)) Γ ⊩⟨ l ⟩ A ≡ B / [A] = Γ ⊩ A ≡ B / [A] where open LogRelKit (kit l) _⊩⟨_⟩_∷_/_ : (Γ : Con Term) (l : TypeLevel) (t A : Term) → Γ ⊩⟨ l ⟩ A → Set (lsuc (toLevel l)) Γ ⊩⟨ l ⟩ t ∷ A / [A] = Γ ⊩ t ∷ A / [A] where open LogRelKit (kit l) _⊩⟨_⟩_≡_∷_/_ : (Γ : Con Term) (l : TypeLevel) (t u A : Term) → Γ ⊩⟨ l ⟩ A → Set (lsuc (toLevel l)) Γ ⊩⟨ l ⟩ t ≡ u ∷ A / [A] = Γ ⊩ t ≡ u ∷ A / [A] where open LogRelKit (kit l)
algebraic-stack_agda0000_doc_13024
{-# OPTIONS --safe --postfix-projections #-} module Cubical.Algebra.OrderedCommMonoid.PropCompletion where {- The completion of an ordered monoid, viewed as monoidal prop-enriched category. This is used in the construction of the upper naturals, which is an idea of David Jaz Myers presented here https://felix-cherubini.de/myers-slides-II.pdf It should be straight forward, but tedious, to generalize this to enriched monoidal categories. -} open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Equiv open import Cubical.Foundations.Function open import Cubical.Foundations.Structure open import Cubical.Foundations.HLevels open import Cubical.Functions.Logic open import Cubical.Functions.Embedding open import Cubical.Data.Sigma open import Cubical.HITs.PropositionalTruncation renaming (rec to propTruncRec; rec2 to propTruncRec2) open import Cubical.Algebra.CommMonoid.Base open import Cubical.Algebra.OrderedCommMonoid open import Cubical.Relation.Binary.Poset private variable ℓ : Level module PropCompletion (ℓ : Level) (M : OrderedCommMonoid ℓ ℓ) where open OrderedCommMonoidStr (snd M) _≤p_ : fst M → fst M → hProp ℓ n ≤p m = (n ≤ m) , (is-prop-valued _ _) isUpwardClosed : (s : fst M → hProp ℓ) → Type _ isUpwardClosed s = (n m : fst M) → n ≤ m → fst (s n) → fst (s m) isPropUpwardClosed : (N : fst M → hProp ℓ) → isProp (isUpwardClosed N) isPropUpwardClosed N = isPropΠ4 (λ _ m _ _ → snd (N m)) isSetM→Prop : isSet (fst M → hProp ℓ) isSetM→Prop = isOfHLevelΠ 2 λ _ → isSetHProp M↑ : Type _ M↑ = Σ[ s ∈ (fst M → hProp ℓ)] isUpwardClosed s isSetM↑ : isSet M↑ isSetM↑ = isOfHLevelΣ 2 isSetM→Prop λ s → isOfHLevelSuc 1 (isPropUpwardClosed s) _isUpperBoundOf_ : fst M → M↑ → Type ℓ n isUpperBoundOf s = fst (fst s n) isBounded : (s : M↑) → Type _ isBounded s = ∃[ m ∈ (fst M) ] (m isUpperBoundOf s) isPropIsBounded : (s : M↑) → isProp (isBounded s) isPropIsBounded s = isPropPropTrunc _^↑ : fst M → M↑ n ^↑ = n ≤p_ , isUpwardClosed≤ where isUpwardClosed≤ : {m : fst M} → isUpwardClosed (m ≤p_) isUpwardClosed≤ = λ {_ _ n≤k m≤n → is-trans _ _ _ m≤n n≤k} isBounded^ : (m : fst M) → isBounded (m ^↑) isBounded^ m = ∣ (m , (is-refl m)) ∣₁ 1↑ : M↑ 1↑ = ε ^↑ _·↑_ : M↑ → M↑ → M↑ s ·↑ l = seq , seqIsUpwardClosed where seq : fst M → hProp ℓ seq n = (∃[ (a , b) ∈ (fst M) × (fst M) ] fst ((fst s a) ⊓ (fst l b) ⊓ ((a · b) ≤p n) )) , isPropPropTrunc seqIsUpwardClosed : isUpwardClosed seq seqIsUpwardClosed n m n≤m = propTruncRec isPropPropTrunc λ {((a , b) , wa , (wb , a·b≤n)) → ∣ (a , b) , wa , (wb , is-trans _ _ _ a·b≤n n≤m) ∣₁} ·presBounded : (s l : M↑) (bs : isBounded s) (bl : isBounded l) → isBounded (s ·↑ l) ·presBounded s l = propTruncRec2 isPropPropTrunc λ {(m , s≤m) (k , l≤k) → ∣ (m · k) , ∣ (m , k) , (s≤m , (l≤k , (is-refl (m · k)))) ∣₁ ∣₁ } {- convenience functions for the proof that ·↑ is the multiplication of a monoid -} typeAt : fst M → M↑ → Type _ typeAt n s = fst (fst s n) M↑Path : {s l : M↑} → ((n : fst M) → typeAt n s ≡ typeAt n l) → s ≡ l M↑Path {s = s} {l = l} pwPath = path where seqPath : fst s ≡ fst l seqPath i n = subtypePathReflection (λ A → isProp A , isPropIsProp) (fst s n) (fst l n) (pwPath n) i path : s ≡ l path = subtypePathReflection (λ s → isUpwardClosed s , isPropUpwardClosed s) s l seqPath pathFromImplications : (s l : M↑) → ((n : fst M) → typeAt n s → typeAt n l) → ((n : fst M) → typeAt n l → typeAt n s) → s ≡ l pathFromImplications s l s→l l→s = M↑Path λ n → cong fst (propPath n) where propPath : (n : fst M) → fst s n ≡ fst l n propPath n = ⇒∶ s→l n ⇐∶ l→s n ^↑Pres· : (x y : fst M) → (x · y) ^↑ ≡ (x ^↑) ·↑ (y ^↑) ^↑Pres· x y = pathFromImplications ((x · y) ^↑) ((x ^↑) ·↑ (y ^↑)) (⇐) ⇒ where ⇐ : (n : fst M) → typeAt n ((x · y) ^↑) → typeAt n ((x ^↑) ·↑ (y ^↑)) ⇐ n x·y≤n = ∣ (x , y) , ((is-refl _) , ((is-refl _) , x·y≤n)) ∣₁ ⇒ : (n : fst M) → typeAt n ((x ^↑) ·↑ (y ^↑)) → typeAt n ((x · y) ^↑) ⇒ n = propTruncRec (snd (fst ((x · y) ^↑) n)) λ {((m , l) , x≤m , (y≤l , m·l≤n)) → is-trans _ _ _ (is-trans _ _ _ (MonotoneR x≤m) (MonotoneL y≤l)) m·l≤n } ·↑Comm : (s l : M↑) → s ·↑ l ≡ l ·↑ s ·↑Comm s l = M↑Path λ n → cong fst (propPath n) where implication : (s l : M↑) (n : fst M) → fst (fst (s ·↑ l) n) → fst (fst (l ·↑ s) n) implication s l n = propTruncRec isPropPropTrunc (λ {((a , b) , wa , (wb , a·b≤n)) → ∣ (b , a) , wb , (wa , subst (λ k → fst (k ≤p n)) (·Comm a b) a·b≤n) ∣₁ }) propPath : (n : fst M) → fst (s ·↑ l) n ≡ fst (l ·↑ s) n propPath n = ⇒∶ implication s l n ⇐∶ implication l s n ·↑Rid : (s : M↑) → s ·↑ 1↑ ≡ s ·↑Rid s = pathFromImplications (s ·↑ 1↑) s (⇒) ⇐ where ⇒ : (n : fst M) → typeAt n (s ·↑ 1↑) → typeAt n s ⇒ n = propTruncRec (snd (fst s n)) (λ {((a , b) , sa , (1b , a·b≤n)) → (snd s) a n ( subst (_≤ n) (·IdR a) (is-trans _ _ _ (MonotoneL 1b) a·b≤n)) sa }) ⇐ : (n : fst M) → typeAt n s → typeAt n (s ·↑ 1↑) ⇐ n = λ sn → ∣ (n , ε) , (sn , (is-refl _ , subst (_≤ n) (sym (·IdR n)) (is-refl _))) ∣₁ ·↑Assoc : (s l k : M↑) → s ·↑ (l ·↑ k) ≡ (s ·↑ l) ·↑ k ·↑Assoc s l k = pathFromImplications (s ·↑ (l ·↑ k)) ((s ·↑ l) ·↑ k) (⇒) ⇐ where ⇒ : (n : fst M) → typeAt n (s ·↑ (l ·↑ k)) → typeAt n ((s ·↑ l) ·↑ k) ⇒ n = propTruncRec isPropPropTrunc λ {((a , b) , sa , (l·kb , a·b≤n)) → propTruncRec isPropPropTrunc (λ {((a' , b') , la' , (kb' , a'·b'≤b)) → ∣ ((a · a') , b') , ∣ (a , a') , (sa , (la' , is-refl _)) ∣₁ , kb' , (let a·⟨a'·b'⟩≤n = (is-trans _ _ _ (MonotoneL a'·b'≤b) a·b≤n) in subst (_≤ n) (·Assoc a a' b') a·⟨a'·b'⟩≤n) ∣₁ }) l·kb } ⇐ : _ ⇐ n = propTruncRec isPropPropTrunc λ {((a , b) , s·l≤a , (k≤b , a·b≤n)) → propTruncRec isPropPropTrunc (λ {((a' , b') , s≤a' , (l≤b' , a'·b'≤a)) → ∣ (a' , b' · b) , s≤a' , ( ∣ (b' , b) , l≤b' , (k≤b , is-refl _) ∣₁ , (let ⟨a'·b'⟩·b≤n = (is-trans _ _ _ (MonotoneR a'·b'≤a) a·b≤n) in subst (_≤ n) (sym (·Assoc a' b' b)) ⟨a'·b'⟩·b≤n) ) ∣₁ }) s·l≤a } asCommMonoid : CommMonoid (ℓ-suc ℓ) asCommMonoid = makeCommMonoid 1↑ _·↑_ isSetM↑ ·↑Assoc ·↑Rid ·↑Comm {- Poset structure on M↑ -} _≤↑_ : (s l : M↑) → Type _ s ≤↑ l = (m : fst M) → fst ((fst l) m) → fst ((fst s) m) isBounded→≤↑ : (s : M↑) → isBounded s → ∃[ m ∈ fst M ] (s ≤↑ (m ^↑)) isBounded→≤↑ s = propTruncRec isPropPropTrunc λ {(m , mIsBound) → ∣ m , (λ n m≤n → snd s m n m≤n mIsBound) ∣₁ } ≤↑IsProp : (s l : M↑) → isProp (s ≤↑ l) ≤↑IsProp s l = isPropΠ2 (λ x p → snd (fst s x)) ≤↑IsRefl : (s : M↑) → s ≤↑ s ≤↑IsRefl s = λ m x → x ≤↑IsTrans : (s l t : M↑) → s ≤↑ l → l ≤↑ t → s ≤↑ t ≤↑IsTrans s l t p q x = (p x) ∘ (q x) ≤↑IsAntisym : (s l : M↑) → s ≤↑ l → l ≤↑ s → s ≡ l ≤↑IsAntisym s l p q = pathFromImplications _ _ q p {- Compatability with the monoid structure -} ·↑IsRMonotone : (l t s : M↑) → l ≤↑ t → (l ·↑ s) ≤↑ (t ·↑ s) ·↑IsRMonotone l t s p x = propTruncRec isPropPropTrunc λ { ((a , b) , l≤a , (s≤b , a·b≤x)) → ∣ (a , b) , p a l≤a , s≤b , a·b≤x ∣₁} ·↑IsLMonotone : (l t s : M↑) → l ≤↑ t → (s ·↑ l) ≤↑ (s ·↑ t) ·↑IsLMonotone l t s p x = propTruncRec isPropPropTrunc λ {((a , b) , s≤a , (l≤b , a·b≤x)) → ∣ (a , b) , s≤a , p b l≤b , a·b≤x ∣₁} asOrderedCommMonoid : OrderedCommMonoid (ℓ-suc ℓ) ℓ asOrderedCommMonoid .fst = _ asOrderedCommMonoid .snd .OrderedCommMonoidStr._≤_ = _≤↑_ asOrderedCommMonoid .snd .OrderedCommMonoidStr._·_ = _·↑_ asOrderedCommMonoid .snd .OrderedCommMonoidStr.ε = 1↑ asOrderedCommMonoid .snd .OrderedCommMonoidStr.isOrderedCommMonoid = IsOrderedCommMonoidFromIsCommMonoid (CommMonoidStr.isCommMonoid (snd asCommMonoid)) ≤↑IsProp ≤↑IsRefl ≤↑IsTrans ≤↑IsAntisym ·↑IsRMonotone ·↑IsLMonotone boundedSubstructure : OrderedCommMonoid (ℓ-suc ℓ) ℓ boundedSubstructure = makeOrderedSubmonoid asOrderedCommMonoid (λ s → (isBounded s , isPropIsBounded s)) ·presBounded (isBounded^ ε) PropCompletion : OrderedCommMonoid ℓ ℓ → OrderedCommMonoid (ℓ-suc ℓ) ℓ PropCompletion M = PropCompletion.asOrderedCommMonoid _ M BoundedPropCompletion : OrderedCommMonoid ℓ ℓ → OrderedCommMonoid (ℓ-suc ℓ) ℓ BoundedPropCompletion M = PropCompletion.boundedSubstructure _ M isSetBoundedPropCompletion : (M : OrderedCommMonoid ℓ ℓ) → isSet (⟨ BoundedPropCompletion M ⟩) isSetBoundedPropCompletion M = isSetΣSndProp (isSetOrderedCommMonoid (PropCompletion M)) λ x → PropCompletion.isPropIsBounded _ M x
algebraic-stack_agda0000_doc_13025
-- Andreas, 2018-10-18, re issue #2757 -- -- Extracted this snippet from the standard library -- as it caused problems during work in #2757 -- (runtime erasue using 0-quantity). -- {-# OPTIONS -v tc.lhs.unify:65 -v tc.irr:50 #-} open import Agda.Builtin.Size data ⊥ : Set where mutual data Conat (i : Size) : Set where zero : Conat i suc : ∞Conat i → Conat i record ∞Conat (i : Size) : Set where coinductive field force : ∀{j : Size< i} → Conat j open ∞Conat infinity : ∀ {i} → Conat i infinity = suc λ where .force → infinity data Finite : Conat ∞ → Set where zero : Finite zero suc : ∀ {n} → Finite (n .force) → Finite (suc n) ¬Finite∞ : Finite infinity → ⊥ ¬Finite∞ (suc p) = ¬Finite∞ p -- The problem was that the usableMod check in the -- unifier (LHS.Unify) refuted this pattern match -- because a runtime-erased argument ∞ (via meta-variable) -- the the extended lambda.
algebraic-stack_agda0000_doc_13026
open import MJ.Types open import MJ.Classtable import MJ.Syntax as Syntax import MJ.Semantics.Values as Values -- -- Substitution-free interpretation of welltyped MJ -- module MJ.Semantics.Functional {c} (Σ : CT c) (ℂ : Syntax.Impl Σ) where open import Prelude open import Data.Vec hiding (init) open import Data.Vec.All.Properties.Extra as Vec∀++ open import Data.Sum open import Data.List as List open import Data.List.All as List∀ hiding (lookup) open import Data.List.All.Properties.Extra open import Data.List.Any open import Data.List.Prefix open import Data.List.Properties.Extra as List+ open import Data.Maybe as Maybe using (Maybe; just; nothing) open import Relation.Binary.PropositionalEquality open import Data.Star.Indexed import Data.Vec.All as Vec∀ open Membership-≡ open Values Σ open CT Σ open Syntax Σ -- open import MJ.Semantics.Objects.Hierarchical Σ ℂ using (encoding) open import MJ.Semantics.Objects.Flat Σ ℂ using (encoding) open ObjEncoding encoding open Heap encoding ⊒-res : ∀ {a}{I : World c → Set a}{W W'} → W' ⊒ W → Res I W' → Res I W ⊒-res {W = W} p (W' , ext' , μ' , v) = W' , ⊑-trans p ext' , μ' , v mutual -- -- object initialization -- init : ∀ {W} cid → Cont (fromList (Class.constr (clookup cid))) (λ W → Obj W cid) W init cid E μ with Impl.bodies ℂ cid init cid E μ | impl super-args defs with evalₙ (defs FLD) E μ ... | W₁ , ext₁ , μ₁ , vs with clookup cid | inspect clookup cid -- case *without* super initialization init cid E μ | impl nothing defs | (W₁ , ext₁ , μ₁ , vs) | (class nothing constr decls) | [ eq ] = W₁ , ext₁ , μ₁ , vs -- case *with* super initialization init cid E μ | impl (just sc) defs | (W₁ , ext₁ , μ₁ , vs) | (class (just x) constr decls) | [ eq ] with evalₑ-all sc (Vec∀.map (coerce ext₁) E) μ₁ ... | W₂ , ext₂ , μ₂ , svs with init x (all-fromList svs) μ₂ ... | W₃ , ext₃ , μ₃ , inherited = W₃ , ⊑-trans (⊑-trans ext₁ ext₂) ext₃ , μ₃ , (List∀.map (coerce (⊑-trans ext₂ ext₃)) vs ++-all inherited) {-} init cid E μ with Impl.bodies ℂ cid init cid E μ | impl super-args defs with evalₙ (defs FLD) E μ ... | W₁ , ext₁ , μ₁ , vs with clookup cid | inspect clookup cid -- case *without* super initialization init cid E μ | impl nothing defs | (W₁ , ext₁ , μ₁ , vs) | (class nothing constr decls) | [ eq ] = , ext₁ , μ₁ , record { own = λ{ MTH → List∀.tabulate (λ _ → tt) ; FLD → subst (λ C → All _ (Class.decls C FLD)) (sym eq) vs }; inherited = subst (λ C → Maybe.All _ (Class.parent C)) (sym eq) nothing } -- case *with* super initialization init cid E μ | impl (just sc) defs | (W₁ , ext₁ , μ₁ , vs) | (class (just x) constr decls) | [ eq ] with evalₑ-all sc (Vec∀.map (coerce ext₁) E) μ₁ ... | W₂ , ext₂ , μ₂ , svs with init x (all-fromList svs) μ₂ ... | W₃ , ext₃ , μ₃ , sO = , ⊑-trans (⊑-trans ext₁ ext₂) ext₃ , μ₃ , record { own = λ{ MTH → List∀.tabulate (λ _ → tt) ; FLD → subst (λ C → All _ (Class.decls C FLD)) (sym eq) (List∀.map (coerce (⊑-trans ext₂ ext₃)) vs) }; inherited = subst (λ C → Maybe.All _ (Class.parent C)) (sym eq) (just sO) } -} evalₑ-all : ∀ {n}{Γ : Ctx c n}{as} → All (Expr Γ) as → ∀ {W} → Cont Γ (λ W' → All (Val W') as) W evalₑ-all [] E μ = , ⊑-refl , μ , [] evalₑ-all (px ∷ exps) E μ with evalₑ px E μ ... | W' , ext' , μ' , v with evalₑ-all exps (Vec∀.map (coerce ext') E) μ' ... | W'' , ext'' , μ'' , vs = W'' , ⊑-trans ext' ext'' , μ'' , coerce ext'' v ∷ vs -- -- evaluation of expressions -- {-# TERMINATING #-} evalₑ : ∀ {n}{Γ : Ctx c n}{a} → Expr Γ a → ∀ {W} → Cont Γ (flip Val a) W evalₑ (upcast sub e) E μ with evalₑ e E μ ... | W' , ext' , μ' , (ref r s) = W' , ext' , μ' , ref r (<:-trans s sub) -- primitive values evalₑ unit = pure (const unit) evalₑ (num n) = pure (const (num n)) -- variable lookup evalₑ (var i) = pure (λ E → Vec∀.lookup i E) -- object allocation evalₑ (new C args) {W} E μ with evalₑ-all args E μ -- create the object, typed under the current heap shape ... | W₁ , ext₁ , μ₁ , vs with init C (all-fromList vs) μ₁ ... | W₂ , ext₂ , μ₂ , O = let -- extension fact for the heap extended with the new object allocation ext = ∷ʳ-⊒ (obj C) W₂ in , ⊑-trans (⊑-trans ext₁ ext₂) ext , all-∷ʳ (List∀.map (coerce ext) μ₂) (coerce ext (obj C O)) , ref (∈-∷ʳ W₂ (obj C)) refl -- value typed under the extended heap -- binary interger operations evalₑ (iop f l r) E μ with evalₑ l E μ ... | W₁ , ext₁ , μ₁ , (num i) with evalₑ r (Vec∀.map (coerce ext₁) E) μ₁ ... | W₂ , ext₂ , μ₂ , (num j) = W₂ , ⊑-trans ext₁ ext₂ , μ₂ , num (f i j) -- method calls evalₑ (call {C} e mtd args) E μ with evalₑ e E μ -- eval obj expression ... | W₁ , ext₁ , μ₁ , r@(ref o sub) with ∈-all o μ₁ -- lookup obj on the heap ... | val () ... | obj cid O with evalₑ-all args (Vec∀.map (coerce ext₁) E) μ₁ -- eval arguments ... | W₂ , ext₂ , μ₂ , vs = -- and finally eval the body of the method under the environment -- generated from the call arguments and the object's "this" ⊒-res (⊑-trans ext₁ ext₂) (eval-body cmd (ref (∈-⊒ o ext₂) <:-fact Vec∀.∷ all-fromList vs) μ₂) where -- get the method definition cmd = getDef C mtd ℂ -- get a subtyping fact <:-fact = <:-trans sub (proj₁ (proj₂ mtd)) -- field lookup in the heap evalₑ (get e fld) E μ with evalₑ e E μ ... | W' , ext' , μ' , ref o C<:C₁ with ∈-all o μ' ... | (val ()) -- apply the runtime subtyping fact to weaken the member fact ... | obj cid O = W' , ext' , μ' , getter O (mem-inherit Σ C<:C₁ fld) -- -- command evaluation -- evalc : ∀ {n m}{I : Ctx c n}{O : Ctx c m}{W : World c}{a} → -- we use a sum for abrupt returns Cmd I a O → Cont I (λ W → (Val W a) ⊎ (Env O W)) W -- new locals variable evalc (loc x e) E μ with evalₑ e E μ ... | W₁ , ext₁ , μ₁ , v = W₁ , ext₁ , μ₁ , inj₂ (v Vec∀.∷ (Vec∀.map (coerce ext₁) E)) -- assigning to a local evalc (asgn i x) E μ with evalₑ x E μ ... | W₁ , ext₁ , μ₁ , v = W₁ , ext₁ , μ₁ , inj₂ (Vec∀.map (coerce ext₁) E Vec∀++.[ i ]≔ v) -- setting a field -- start by lookuping up the referenced object on the heap & eval the expression to assign it evalc (set rf fld e) E μ with evalₑ rf E μ ... | W₁ , ext₁ , μ₁ , ref p s with List∀.lookup μ₁ p | evalₑ e (Vec∀.map (coerce ext₁) E) μ₁ ... | (val ()) | _ ... | (obj cid O) | (W₂ , ext₂ , μ₂ , v) = let ext = ⊑-trans ext₁ ext₂ in , ext , (μ₂ All[ ∈-⊒ p ext₂ ]≔' -- update the store at the reference location -- update the object at the member location obj cid ( setter (coerce ext₂ O) (mem-inherit Σ s fld) v ) ) , (inj₂ $ Vec∀.map (coerce ext) E) -- side-effectful expressions evalc (do x) E μ with evalₑ x E μ ... | W₁ , ext₁ , μ₁ , _ = W₁ , ext₁ , μ₁ , inj₂ (Vec∀.map (coerce ext₁) E) -- early returns evalc (ret x) E μ with evalₑ x E μ ... | W₁ , ext₁ , μ₁ , v = W₁ , ext₁ , μ₁ , inj₁ v eval-body : ∀ {n}{I : Ctx c n}{W : World c}{a} → Body I a → Cont I (λ W → Val W a) W eval-body (body ε re) E μ = evalₑ re E μ eval-body (body (x ◅ xs) re) E μ with evalc x E μ ... | W₁ , ext₁ , μ₁ , inj₂ E₁ = ⊒-res ext₁ (eval-body (body xs re) E₁ μ₁) ... | W₁ , ext₁ , μ₁ , inj₁ v = _ , ext₁ , μ₁ , v evalₙ : ∀ {n}{I : Ctx c n}{W : World c}{as} → All (Body I) as → Cont I (λ W → All (Val W) as) W evalₙ [] E μ = , ⊑-refl , μ , [] evalₙ (px ∷ bs) E μ with eval-body px E μ ... | W₁ , ext₁ , μ₁ , v with evalₙ bs (Vec∀.map (coerce ext₁) E) μ₁ ... | W₂ , ext₂ , μ₂ , vs = W₂ , ⊑-trans ext₁ ext₂ , μ₂ , coerce ext₂ v ∷ vs eval : ∀ {a} → Prog a → ∃ λ W → Store W × Val W a eval (lib , main) with eval-body main Vec∀.[] [] ... | W , ext , μ , v = W , μ , v
algebraic-stack_agda0000_doc_13027
{-# OPTIONS --allow-unsolved-metas #-} module LiteralFormula where open import OscarPrelude open import IsLiteralFormula open import HasNegation open import Formula record LiteralFormula : Set where constructor ⟨_⟩ field {formula} : Formula isLiteralFormula : IsLiteralFormula formula open LiteralFormula public instance EqLiteralFormula : Eq LiteralFormula Eq._==_ EqLiteralFormula (⟨_⟩ {φ₁} lf₁) (⟨_⟩ {φ₂} lf₂) with φ₁ ≟ φ₂ … | no φ₁≢φ₂ = no (λ {refl → φ₁≢φ₂ refl}) Eq._==_ EqLiteralFormula (⟨_⟩ {φ₁} lf₁) (⟨_⟩ {φ₂} lf₂) | yes refl = case (eqIsLiteralFormula lf₁ lf₂) of λ {refl → yes refl} instance HasNegationLiteralFormula : HasNegation LiteralFormula HasNegation.~ HasNegationLiteralFormula ⟨ atomic 𝑃 τs ⟩ = ⟨ logical 𝑃 τs ⟩ HasNegation.~ HasNegationLiteralFormula ⟨ logical 𝑃 τs ⟩ = ⟨ atomic 𝑃 τs ⟩ open import Interpretation open import Vector open import Term open import Elements open import TruthValue module _ where open import HasSatisfaction instance HasSatisfactionLiteralFormula : HasSatisfaction LiteralFormula HasSatisfaction._⊨_ HasSatisfactionLiteralFormula I ⟨ atomic 𝑃 τs ⟩ = 𝑃⟦ I ⟧ 𝑃 ⟨ ⟨ τ⟦ I ⟧ <$> vector (terms τs) ⟩ ⟩ ≡ ⟨ true ⟩ HasSatisfaction._⊨_ HasSatisfactionLiteralFormula I ⟨ logical 𝑃 τs ⟩ = 𝑃⟦ I ⟧ 𝑃 ⟨ ⟨ τ⟦ I ⟧ <$> vector (terms τs) ⟩ ⟩ ≡ ⟨ false ⟩ instance HasDecidableSatisfactionLiteralFormula : HasDecidableSatisfaction LiteralFormula HasDecidableSatisfaction._⊨?_ HasDecidableSatisfactionLiteralFormula I ⟨ atomic 𝑃 τs ⟩ with 𝑃⟦ I ⟧ 𝑃 ⟨ ⟨ τ⟦ I ⟧ <$> vector (terms τs) ⟩ ⟩ … | ⟨ true ⟩ = yes refl … | ⟨ false ⟩ = no λ () HasDecidableSatisfaction._⊨?_ HasDecidableSatisfactionLiteralFormula I ⟨ logical 𝑃 τs ⟩ with 𝑃⟦ I ⟧ 𝑃 ⟨ ⟨ τ⟦ I ⟧ <$> vector (terms τs) ⟩ ⟩ … | ⟨ true ⟩ = no λ () … | ⟨ false ⟩ = yes refl instance HasDecidableValidationLiteralFormula : HasDecidableValidation LiteralFormula HasDecidableValidation.⊨? HasDecidableValidationLiteralFormula = {!!} module _ where open import HasSubstantiveDischarge postulate instance cs' : CanonicalSubstitution LiteralFormula instance hpu' : HasPairUnification LiteralFormula (CanonicalSubstitution.S cs') instance HasSubstantiveDischargeLiteralFormula : HasSubstantiveDischarge LiteralFormula --HasSubstantiveDischarge._o≽o_ HasSubstantiveDischargeLiteralFormula φ₁ φ₂ = φ₁ ≡ φ₂ HasSubstantiveDischarge.hasNegation HasSubstantiveDischargeLiteralFormula = it HasSubstantiveDischarge.≽-reflexive HasSubstantiveDischargeLiteralFormula = {!!} HasSubstantiveDischarge.≽-consistent HasSubstantiveDischargeLiteralFormula = {!!} HasSubstantiveDischarge.≽-contrapositive HasSubstantiveDischargeLiteralFormula = {!!} instance HasDecidableSubstantiveDischargeLiteralFormula : HasDecidableSubstantiveDischarge LiteralFormula HasDecidableSubstantiveDischarge.hasSubstantiveDischarge HasDecidableSubstantiveDischargeLiteralFormula = it HasDecidableSubstantiveDischarge._≽?_ HasDecidableSubstantiveDischargeLiteralFormula φ+ φ- = {!!} -- φ+ ≟ φ-
algebraic-stack_agda0000_doc_13028
{-# OPTIONS --cubical --safe #-} module Cubical.Foundations.Bundle where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Univalence open import Cubical.Foundations.Fibration open import Cubical.Foundations.Structure open import Cubical.Structures.TypeEqvTo open import Cubical.Data.Sigma.Properties open import Cubical.HITs.PropositionalTruncation module _ {ℓb ℓf} {B : Type ℓb} {F : Type ℓf} {ℓ} where {- A fiber bundle with base space B and fibers F is a map `p⁻¹ : B → TypeEqvTo F` taking points in the base space to their respective fibers. e.g. a double cover is a map `B → TypeEqvTo Bool` -} Total : (p⁻¹ : B → TypeEqvTo ℓ F) → Type (ℓ-max ℓb ℓ) Total p⁻¹ = Σ[ x ∈ B ] p⁻¹ x .fst pr : (p⁻¹ : B → TypeEqvTo ℓ F) → Total p⁻¹ → B pr p⁻¹ = fst inc : (p⁻¹ : B → TypeEqvTo ℓ F) (x : B) → p⁻¹ x .fst → Total p⁻¹ inc p⁻¹ x = (x ,_) fibPrEquiv : (p⁻¹ : B → TypeEqvTo ℓ F) (x : B) → fiber (pr p⁻¹) x ≃ p⁻¹ x .fst fibPrEquiv p⁻¹ x = fiberEquiv (λ x → typ (p⁻¹ x)) x module _ {ℓb ℓf} (B : Type ℓb) (ℓ : Level) (F : Type ℓf) where private ℓ' = ℓ-max ℓb ℓ {- Equivalently, a fiber bundle with base space B and fibers F is a type E and a map `p : E → B` with fibers merely equivalent to F. -} bundleEquiv : (B → TypeEqvTo ℓ' F) ≃ (Σ[ E ∈ Type ℓ' ] Σ[ p ∈ (E → B) ] ∀ x → ∥ fiber p x ≃ F ∥) bundleEquiv = compEquiv (compEquiv PiΣ (pathToEquiv p)) assocΣ where e = fibrationEquiv B ℓ p : (Σ[ p⁻¹ ∈ (B → Type ℓ') ] ∀ x → ∥ p⁻¹ x ≃ F ∥) ≡ (Σ[ p ∈ (Σ[ E ∈ Type ℓ' ] (E → B)) ] ∀ x → ∥ fiber (snd p) x ≃ F ∥ ) p i = Σ[ q ∈ ua e (~ i) ] ∀ x → ∥ ua-unglue e (~ i) q x ≃ F ∥
algebraic-stack_agda0000_doc_13029
module Generic.Property.Reify where open import Generic.Core data ExplView : Visibility -> Set where yes-expl : ExplView expl no-expl : ∀ {v} -> ExplView v explView : ∀ v -> ExplView v explView expl = yes-expl explView v = no-expl ExplMaybe : ∀ {α} -> Visibility -> Set α -> Set α ExplMaybe v A with explView v ... | yes-expl = A ... | no-expl = ⊤ caseExplMaybe : ∀ {α π} {A : Set α} (P : Visibility -> Set π) -> (A -> P expl) -> (∀ {v} -> P v) -> ∀ v -> ExplMaybe v A -> P v caseExplMaybe P f y v x with explView v ... | yes-expl = f x ... | no-expl = y Prod : ∀ {α} β -> Visibility -> Set α -> Set (α ⊔ β) -> Set (α ⊔ β) Prod β v A B with explView v ... | yes-expl = A × B ... | no-expl = B uncurryProd : ∀ {α β γ} {A : Set α} {B : Set (α ⊔ β)} {C : Set γ} v -> Prod β v A B -> (ExplMaybe v A -> B -> C) -> C uncurryProd v p g with explView v | p ... | yes-expl | (x , y) = g x y ... | no-expl | y = g tt y SemReify : ∀ {i β} {I : Set i} -> Desc I β -> Set SemReify (var i) = ⊤ SemReify (π i q C) = ⊥ SemReify (D ⊛ E) = SemReify D × SemReify E mutual ExtendReify : ∀ {i β} {I : Set i} -> Desc I β -> Set β ExtendReify (var i) = ⊤ ExtendReify (π i q C) = ExtendReifyᵇ i C q ExtendReify (D ⊛ E) = SemReify D × ExtendReify E ExtendReifyᵇ : ∀ {ι α β γ q} {I : Set ι} i -> Binder α β γ i q I -> α ≤ℓ β -> Set β ExtendReifyᵇ {β = β} i (coerce (A , D)) q = Coerce′ q $ Prod β (visibility i) (Reify A) (∀ {x} -> ExtendReify (D x)) -- Can't reify an irrelevant thing into its relevant representation. postulate reifyᵢ : ∀ {α} {A : Set α} {{aReify : Reify A}} -> .A -> Term instance {-# TERMINATING #-} DataReify : ∀ {i β} {I : Set i} {D : Data (Desc I β)} {j} {{reD : All ExtendReify (consTypes D)}} -> Reify (μ D j) DataReify {ι} {β} {I} {D₀} = record { reify = reifyMu } where mutual reifySem : ∀ D {{reD : SemReify D}} -> ⟦ D ⟧ (μ D₀) -> Term reifySem (var i) d = reifyMu d reifySem (π i q C) {{()}} reifySem (D ⊛ E) {{reD , reE}} (x , y) = sate _,_ (reifySem D {{reD}} x) (reifySem E {{reE}} y) reifyExtend : ∀ {j} D {{reD : ExtendReify D}} -> Extend D (μ D₀) j -> List Term reifyExtend (var i) lrefl = [] reifyExtend (π i q C) p = reifyExtendᵇ i C q p reifyExtend (D ⊛ E) {{reD , reE}} (x , e) = reifySem D {{reD}} x ∷ reifyExtend E {{reE}} e reifyExtendᵇ : ∀ {α γ q j} i (C : Binder α β γ i q I) q′ {{reC : ExtendReifyᵇ i C q′}} -> Extendᵇ i C q′ (μ D₀) j -> List Term reifyExtendᵇ i (coerce (A , D)) q {{reC}} p = uncurryProd (visibility i) (uncoerce′ q reC) λ mreA reD -> split q p λ x e -> let es = reifyExtend (D x) {{reD}} e in caseExplMaybe _ (λ reA -> elimRelValue _ (reify {{reA}}) (reifyᵢ {{reA}}) x ∷ es) es (visibility i) mreA reifyDesc : ∀ {j} D {{reD : ExtendReify D}} -> Name -> Extend D (μ D₀) j -> Term reifyDesc D n e = vis appCon n (reifyExtend D e) reifyAny : ∀ {j} (Ds : List (Desc I β)) {{reD : All ExtendReify Ds}} -> ∀ d a b ns -> Node D₀ (packData d a b Ds ns) j -> Term reifyAny [] d a b tt () reifyAny (D ∷ []) {{reD , _}} d a b (n , ns) e = reifyDesc D {{reD}} n e reifyAny (D ∷ E ∷ Ds) {{reD , reDs}} d a b (n , ns) (inj₁ e) = reifyDesc D {{reD}} n e reifyAny (D ∷ E ∷ Ds) {{reD , reDs}} d a b (n , ns) (inj₂ r) = reifyAny (E ∷ Ds) {{reDs}} d a b ns r reifyMu : ∀ {j} -> μ D₀ j -> Term reifyMu (node e) = reifyAny (consTypes D₀) (dataName D₀) (parsTele D₀) (indsTele D₀) (consNames D₀) e
algebraic-stack_agda0000_doc_13030
module Issue1760g where data ⊥ : Set where {-# NO_POSITIVITY_CHECK #-} {-# NON_TERMINATING #-} mutual record U : Set where constructor roll field ap : U → U lemma : U → ⊥ lemma (roll u) = lemma (u (roll u)) bottom : ⊥ bottom = lemma (roll λ x → x)
algebraic-stack_agda0000_doc_13031
{-# OPTIONS --without-K --safe #-} open import Algebra.Structures.Bundles.Field module Algebra.Linear.Morphism.VectorSpace {k ℓᵏ} (K : Field k ℓᵏ) where open import Level open import Algebra.FunctionProperties as FP import Algebra.Linear.Morphism.Definitions as LinearMorphismDefinitions import Algebra.Morphism as Morphism open import Relation.Binary using (Rel; Setoid) open import Relation.Binary.Morphism.Structures open import Algebra.Morphism open import Algebra.Linear.Core open import Algebra.Linear.Structures.VectorSpace K open import Algebra.Linear.Structures.Bundles module LinearDefinitions {a₁ a₂ ℓ₂} (A : Set a₁) (B : Set a₂) (_≈_ : Rel B ℓ₂) where open Morphism.Definitions A B _≈_ public open LinearMorphismDefinitions K A B _≈_ public module _ {a₁ ℓ₁} (From : VectorSpace K a₁ ℓ₁) {a₂ ℓ₂} (To : VectorSpace K a₂ ℓ₂) where private module F = VectorSpace From module T = VectorSpace To K' : Set k K' = Field.Carrier K open F using () renaming (Carrier to A; _≈_ to _≈₁_; _+_ to _+₁_; _∙_ to _∙₁_) open T using () renaming (Carrier to B; _≈_ to _≈₂_; _+_ to _+₂_; _∙_ to _∙₂_) open import Function open LinearDefinitions (VectorSpace.Carrier From) (VectorSpace.Carrier To) _≈₂_ record IsLinearMap (⟦_⟧ : Morphism) : Set (k ⊔ a₁ ⊔ a₂ ⊔ ℓ₁ ⊔ ℓ₂) where field isAbelianGroupMorphism : IsAbelianGroupMorphism F.abelianGroup T.abelianGroup ⟦_⟧ ∙-homo : ScalarHomomorphism ⟦_⟧ _∙₁_ _∙₂_ open IsAbelianGroupMorphism isAbelianGroupMorphism public renaming (∙-homo to +-homo; ε-homo to 0#-homo) distrib-linear : ∀ (a b : K') (u v : A) -> ⟦ a ∙₁ u +₁ b ∙₁ v ⟧ ≈₂ a ∙₂ ⟦ u ⟧ +₂ b ∙₂ ⟦ v ⟧ distrib-linear a b u v = T.trans (+-homo (a ∙₁ u) (b ∙₁ v)) (T.+-cong (∙-homo a u) (∙-homo b v)) record IsLinearMonomorphism (⟦_⟧ : Morphism) : Set (k ⊔ a₁ ⊔ a₂ ⊔ ℓ₁ ⊔ ℓ₂) where field isLinearMap : IsLinearMap ⟦_⟧ injective : Injective _≈₁_ _≈₂_ ⟦_⟧ open IsLinearMap isLinearMap public record IsLinearIsomorphism (⟦_⟧ : Morphism) : Set (k ⊔ a₁ ⊔ a₂ ⊔ ℓ₁ ⊔ ℓ₂) where field isLinearMonomorphism : IsLinearMonomorphism ⟦_⟧ surjective : Surjective _≈₁_ _≈₂_ ⟦_⟧ open IsLinearMonomorphism isLinearMonomorphism public module _ {a ℓ} (V : VectorSpace K a ℓ) where open VectorSpace V open LinearDefinitions Carrier Carrier _≈_ IsLinearEndomorphism : Morphism -> Set (k ⊔ a ⊔ ℓ) IsLinearEndomorphism ⟦_⟧ = IsLinearMap V V ⟦_⟧ IsLinearAutomorphism : Morphism -> Set (k ⊔ a ⊔ ℓ) IsLinearAutomorphism ⟦_⟧ = IsLinearIsomorphism V V ⟦_⟧
algebraic-stack_agda0000_doc_13032
module helloworld where open import IO main = run (putStrLn "Hello World")
algebraic-stack_agda0000_doc_13033
{-# OPTIONS --without-K #-} module hott.types where open import hott.types.nat public open import hott.types.coproduct public
algebraic-stack_agda0000_doc_13034
module README where ---------------------------------------------------------------------- -- The Agda smallib library, version 0.1 ---------------------------------------------------------------------- -- -- This library implements a type theory which is described in the -- Appendix of the HoTT book. It also contains some properties derived -- from the rules of this theory. ---------------------------------------------------------------------- -- -- This project is meant to be a practice for the author but as a -- secondary goal it would be nice to create a small library which is -- less intimidating than the standard one. -- -- This version was tested using Agda 2.6.1. ---------------------------------------------------------------------- ---------------------------------------------------------------------- -- High-level overview of contents ---------------------------------------------------------------------- -- -- The top-level module L is not implemented (yet), it's sole purpose -- is to prepend all of the module names with something to avoid -- possible name clashes with the standard library. -- -- The structure of the library is the following: -- -- • Base -- The derivation rules of the implemented type theory and some -- useful properties which can be derived from these. To make a -- clear distinction between these every type has a Core and a -- Properties submodule. In some cases the latter might be empty. -- -- • Data -- ◦ Bool -- A specialized form of the Coproduct type. It implements if as -- an elimination rule. The following operations are defined on -- them: not, ∧, ∨, xor. ---------------------------------------------------------------------- ---------------------------------------------------------------------- -- Some useful modules ---------------------------------------------------------------------- -- -- • To use several things at once import L.Base -- Type theory with it's properties. import L.Base.Core -- Derivation rules. -- -- • To use only one base type import L.Base.Sigma -- Products (universe polymorphic). import L.Base.Coproduct -- Disjoint sums (universe polymorphic). import L.Base.Empty -- Empty type. import L.Base.Unit -- Unit type. import L.Base.Nat -- Natural numbers. import L.Base.Id -- Propositional equality (universe poly.). -- -- • To use the properties of the above import L.Base.Sigma.Properties import L.Base.Coproduct.Properties import L.Base.Empty.Properties import L.Base.Unit.Properties import L.Base.Nat.Properties import L.Base.Id.Properties -- -- • Some datatypes import L.Data.Bool -- Booleans. ---------------------------------------------------------------------- ---------------------------------------------------------------------- -- Notes ---------------------------------------------------------------------- -- -- • L.Base exports L.Coproduct.Core._+_ as _⊎_ to avoid multiple -- definitions of _+_, as L.Base.Nat declares it as well. ----------------------------------------------------------------------
algebraic-stack_agda0000_doc_13035
{-# OPTIONS --without-K #-} open import HoTT open import cohomology.SuspAdjointLoopIso open import cohomology.WithCoefficients open import cohomology.Theory open import cohomology.Exactness open import cohomology.Choice {- A spectrum (family (Eₙ | n : ℤ) such that ΩEₙ₊₁ = Eₙ) - gives rise to a cohomology theory C with Cⁿ(S⁰) = π₁(Eₙ₊₁). -} module cohomology.SpectrumModel {i} (E : ℤ → Ptd i) (spectrum : (n : ℤ) → ⊙Ω (E (succ n)) == E n) where module SpectrumModel where {- Definition of cohomology group C -} module _ (n : ℤ) (X : Ptd i) where C : Group i C = →Ω-group X (E (succ n)) {- convenient abbreviations -} CEl = Group.El C ⊙CEl = Group.⊙El C Cid = Group.ident C {- before truncation -} uCEl = fst (X ⊙→ ⊙Ω (E (succ n))) {- Cⁿ(X) is an abelian group -} C-abelian : (n : ℤ) (X : Ptd i) → is-abelian (C n X) C-abelian n X = transport (is-abelian ∘ →Ω-group X) (spectrum (succ n)) $ Trunc-group-abelian (→Ω-group-structure _ _) $ λ {(f , fpt) (g , gpt) → ⊙λ= (λ x → conc^2-comm (f x) (g x)) (pt-lemma fpt gpt)} where pt-lemma : ∀ {i} {A : Type i} {x : A} {p q : idp {a = x} == idp {a = x}} (α : p == idp) (β : q == idp) → ap (uncurry _∙_) (ap2 _,_ α β) ∙ idp == conc^2-comm p q ∙ ap (uncurry _∙_) (ap2 _,_ β α) ∙ idp pt-lemma idp idp = idp {- CF, the functorial action of C: - contravariant functor from pointed spaces to abelian groups -} module _ (n : ℤ) {X Y : Ptd i} where CF-hom : fst (X ⊙→ Y) → (C n Y →ᴳ C n X) CF-hom f = →Ω-group-dom-act f (E (succ n)) CF : fst (X ⊙→ Y) → fst (⊙CEl n Y ⊙→ ⊙CEl n X) CF F = GroupHom.⊙f (CF-hom F) {- CF-hom is a functor from pointed spaces to abelian groups -} module _ (n : ℤ) {X : Ptd i} where CF-ident : CF-hom n {X} {X} (⊙idf X) == idhom (C n X) CF-ident = →Ω-group-dom-idf (E (succ n)) CF-comp : {Y Z : Ptd i} (g : fst (Y ⊙→ Z)) (f : fst (X ⊙→ Y)) → CF-hom n (g ⊙∘ f) == CF-hom n f ∘ᴳ CF-hom n g CF-comp g f = →Ω-group-dom-∘ g f (E (succ n)) -- Eilenberg-Steenrod Axioms {- Suspension Axiom -} private C-Susp' : {E₁ E₀ : Ptd i} (p : ⊙Ω E₁ == E₀) (X : Ptd i) → →Ω-group (⊙Susp X) E₁ ≃ᴳ →Ω-group X E₀ C-Susp' {E₁ = E₁} idp X = SuspAdjointLoopIso.iso X E₁ C-SuspF' : {E₁ E₀ : Ptd i} (p : ⊙Ω E₁ == E₀) {X Y : Ptd i} (f : fst (X ⊙→ Y)) → fst (C-Susp' p X) ∘ᴳ →Ω-group-dom-act (⊙susp-fmap f) E₁ == →Ω-group-dom-act f E₀ ∘ᴳ fst (C-Susp' p Y) C-SuspF' {E₁ = E₁} idp f = SuspAdjointLoopIso.nat-dom f E₁ C-Susp : (n : ℤ) (X : Ptd i) → C (succ n) (⊙Susp X) ≃ᴳ C n X C-Susp n X = C-Susp' (spectrum (succ n)) X C-SuspF : (n : ℤ) {X Y : Ptd i} (f : fst (X ⊙→ Y)) → fst (C-Susp n X) ∘ᴳ CF-hom (succ n) (⊙susp-fmap f) == CF-hom n f ∘ᴳ fst (C-Susp n Y) C-SuspF n f = C-SuspF' (spectrum (succ n)) f {- Non-truncated Exactness Axiom -} module _ (n : ℤ) {X Y : Ptd i} where {- precomposing [⊙cfcod' f] and then [f] gives [0] -} exact-itok-lemma : (f : fst (X ⊙→ Y)) (g : uCEl n (⊙Cof f)) → (g ⊙∘ ⊙cfcod' f) ⊙∘ f == ⊙cst exact-itok-lemma (f , fpt) (g , gpt) = ⊙λ= (λ x → ap g (! (cfglue' f x)) ∙ gpt) (ap (g ∘ cfcod) fpt ∙ ap g (ap cfcod (! fpt) ∙ ! (cfglue (snd X))) ∙ gpt =⟨ lemma cfcod g fpt (! (cfglue (snd X))) gpt ⟩ ap g (! (cfglue (snd X))) ∙ gpt =⟨ ! (∙-unit-r _) ⟩ (ap g (! (cfglue (snd X))) ∙ gpt) ∙ idp ∎) where lemma : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} {a₁ a₂ : A} {b : B} {c : C} (f : A → B) (g : B → C) (p : a₁ == a₂) (q : f a₁ == b) (r : g b == c) → ap (g ∘ f) p ∙ ap g (ap f (! p) ∙ q) ∙ r == ap g q ∙ r lemma f g idp idp idp = idp {- if g ⊙∘ f is constant then g factors as h ⊙∘ ⊙cfcod' f -} exact-ktoi-lemma : (f : fst (X ⊙→ Y)) (g : uCEl n Y) → g ⊙∘ f == ⊙cst → Σ (uCEl n (⊙Cof f)) (λ h → h ⊙∘ ⊙cfcod' f == g) exact-ktoi-lemma (f , fpt) (h , hpt) p = ((g , ! q ∙ hpt) , pair= idp (! (∙-assoc q (! q) hpt) ∙ ap (_∙ hpt) (!-inv-r q))) where g : Cofiber f → Ω (E (succ n)) g = CofiberRec.f idp h (! ∘ app= (ap fst p)) q : h (snd Y) == g (cfbase' f) q = ap g (snd (⊙cfcod' (f , fpt))) {- Truncated Exactness Axiom -} module _ (n : ℤ) {X Y : Ptd i} where {- in image of (CF n (⊙cfcod' f)) ⇒ in kernel of (CF n f) -} abstract C-exact-itok : (f : fst (X ⊙→ Y)) → is-exact-itok (CF-hom n (⊙cfcod' f)) (CF-hom n f) C-exact-itok f = itok-alt-in (CF-hom n (⊙cfcod' f)) (CF-hom n f) $ Trunc-elim (λ _ → =-preserves-level _ (Trunc-level {n = 0})) (ap [_] ∘ exact-itok-lemma n f) {- in kernel of (CF n f) ⇒ in image of (CF n (⊙cfcod' f)) -} abstract C-exact-ktoi : (f : fst (X ⊙→ Y)) → is-exact-ktoi (CF-hom n (⊙cfcod' f)) (CF-hom n f) C-exact-ktoi f = Trunc-elim (λ _ → Π-level (λ _ → raise-level _ Trunc-level)) (λ h tp → Trunc-rec Trunc-level (lemma h) (–> (Trunc=-equiv _ _) tp)) where lemma : (h : uCEl n Y) → h ⊙∘ f == ⊙cst → Trunc -1 (Σ (CEl n (⊙Cof f)) (λ tk → fst (CF n (⊙cfcod' f)) tk == [ h ])) lemma h p = [ [ fst wit ] , ap [_] (snd wit) ] where wit : Σ (uCEl n (⊙Cof f)) (λ k → k ⊙∘ ⊙cfcod' f == h) wit = exact-ktoi-lemma n f h p C-exact : (f : fst (X ⊙→ Y)) → is-exact (CF-hom n (⊙cfcod' f)) (CF-hom n f) C-exact f = record {itok = C-exact-itok f; ktoi = C-exact-ktoi f} {- Additivity Axiom -} module _ (n : ℤ) {A : Type i} (X : A → Ptd i) (ac : (W : A → Type i) → has-choice 0 A W) where into : CEl n (⊙BigWedge X) → Trunc 0 (Π A (uCEl n ∘ X)) into = Trunc-rec Trunc-level (λ H → [ (λ a → H ⊙∘ ⊙bwin a) ]) module Out' (K : Π A (uCEl n ∘ X)) = BigWedgeRec idp (fst ∘ K) (! ∘ snd ∘ K) out : Trunc 0 (Π A (uCEl n ∘ X)) → CEl n (⊙BigWedge X) out = Trunc-rec Trunc-level (λ K → [ Out'.f K , idp ]) into-out : ∀ y → into (out y) == y into-out = Trunc-elim (λ _ → =-preserves-level _ Trunc-level) (λ K → ap [_] (λ= (λ a → pair= idp $ ap (Out'.f K) (! (bwglue a)) ∙ idp =⟨ ∙-unit-r _ ⟩ ap (Out'.f K) (! (bwglue a)) =⟨ ap-! (Out'.f K) (bwglue a) ⟩ ! (ap (Out'.f K) (bwglue a)) =⟨ ap ! (Out'.glue-β K a) ⟩ ! (! (snd (K a))) =⟨ !-! (snd (K a)) ⟩ snd (K a) ∎))) out-into : ∀ x → out (into x) == x out-into = Trunc-elim {P = λ tH → out (into tH) == tH} (λ _ → =-preserves-level _ Trunc-level) (λ {(h , hpt) → ap [_] $ pair= (λ= (out-into-fst (h , hpt))) (↓-app=cst-in $ ! $ ap (λ w → w ∙ hpt) (app=-β (out-into-fst (h , hpt)) bwbase) ∙ !-inv-l hpt)}) where lemma : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) {a₁ a₂ : A} {b : B} (p : a₁ == a₂) (q : f a₁ == b) → ! q ∙ ap f p == ! (ap f (! p) ∙ q) lemma f idp idp = idp out-into-fst : (H : fst (⊙BigWedge X ⊙→ ⊙Ω (E (succ n)))) → ∀ w → Out'.f (λ a → H ⊙∘ ⊙bwin a) w == fst H w out-into-fst (h , hpt) = BigWedge-elim (! hpt) (λ _ _ → idp) (λ a → ↓-='-in $ ! hpt ∙ ap h (bwglue a) =⟨ lemma h (bwglue a) hpt ⟩ ! (ap h (! (bwglue a)) ∙ hpt) =⟨ ! (Out'.glue-β (λ a → (h , hpt) ⊙∘ ⊙bwin a) a) ⟩ ap (Out'.f (λ a → (h , hpt) ⊙∘ ⊙bwin a)) (bwglue a) ∎) abstract C-additive : is-equiv (GroupHom.f (Πᴳ-hom-in (CF-hom n ∘ ⊙bwin {X = X}))) C-additive = transport is-equiv (λ= $ Trunc-elim (λ _ → =-preserves-level _ $ Π-level $ λ _ → Trunc-level) (λ _ → idp)) ((ac (uCEl n ∘ X)) ∘ise (is-eq into out into-out out-into)) open SpectrumModel spectrum-cohomology : CohomologyTheory i spectrum-cohomology = record { C = C; CF-hom = CF-hom; CF-ident = CF-ident; CF-comp = CF-comp; C-abelian = C-abelian; C-Susp = C-Susp; C-SuspF = C-SuspF; C-exact = C-exact; C-additive = C-additive} spectrum-C-S⁰ : (n : ℤ) → C n (⊙Lift ⊙S⁰) == πS 0 (E (succ n)) spectrum-C-S⁰ n = Bool⊙→Ω-is-π₁ (E (succ n))
algebraic-stack_agda0000_doc_13036
{-# OPTIONS --warning=error --safe --without-K #-} open import LogicalFormulae open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import Functions.Definition open import Setoids.Setoids open import Setoids.Subset module Graphs.Definition where record Graph {a b : _} (c : _) {V' : Set a} (V : Setoid {a} {b} V') : Set (a ⊔ b ⊔ lsuc c) where field _<->_ : Rel {a} {c} V' noSelfRelation : (x : V') → x <-> x → False symmetric : {x y : V'} → x <-> y → y <-> x wellDefined : {x y r s : V'} → Setoid._∼_ V x y → Setoid._∼_ V r s → x <-> r → y <-> s record GraphIso {a b c d e m : _} {V1' : Set a} {V2' : Set b} {V1 : Setoid {a} {c} V1'} {V2 : Setoid {b} {d} V2'} (G : Graph e V1) (H : Graph m V2) (f : V1' → V2') : Set (a ⊔ b ⊔ c ⊔ d ⊔ e ⊔ m) where field bij : SetoidBijection V1 V2 f respects : (x y : V1') → Graph._<->_ G x y → Graph._<->_ H (f x) (f y) respects' : (x y : V1') → Graph._<->_ H (f x) (f y) → Graph._<->_ G x y record Subgraph {a b c d e : _} {V' : Set a} {V : Setoid {a} {b} V'} (G : Graph c V) {pred : V' → Set d} (sub : subset V pred) (_<->'_ : Rel {_} {e} (Sg V' pred)) : Set (a ⊔ b ⊔ c ⊔ d ⊔ e) where field inherits : {x y : Sg V' pred} → (x <->' y) → (Graph._<->_ G (underlying x) (underlying y)) symmetric : {x y : Sg V' pred} → (x <->' y) → (y <->' x) wellDefined : {x y r s : Sg V' pred} → Setoid._∼_ (subsetSetoid V sub) x y → Setoid._∼_ (subsetSetoid V sub) r s → x <->' r → y <->' s subgraphIsGraph : {a b c d e : _} {V' : Set a} {V : Setoid {a} {b} V'} {G : Graph c V} {pred : V' → Set d} {sub : subset V pred} {rel : Rel {_} {e} (Sg V' pred)} (H : Subgraph G sub rel) → Graph e (subsetSetoid V sub) Graph._<->_ (subgraphIsGraph {rel = rel} H) = rel Graph.noSelfRelation (subgraphIsGraph {G = G} H) (v , isSub) v=v = Graph.noSelfRelation G v (Subgraph.inherits H v=v) Graph.symmetric (subgraphIsGraph H) v1=v2 = Subgraph.symmetric H v1=v2 Graph.wellDefined (subgraphIsGraph H) = Subgraph.wellDefined H
algebraic-stack_agda0000_doc_13037
{- A defintion of the real projective spaces following: [BR17] U. Buchholtz, E. Rijke, The real projective spaces in homotopy type theory. (2017) https://arxiv.org/abs/1704.05770 -} {-# OPTIONS --cubical --safe #-} module Cubical.HITs.RPn.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.Properties open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.HLevels open import Cubical.Foundations.Bundle open import Cubical.Foundations.SIP open import Cubical.Structures.Pointed open import Cubical.Structures.TypeEqvTo open import Cubical.Data.Bool open import Cubical.Data.Nat hiding (elim) open import Cubical.Data.NatMinusOne open import Cubical.Data.Sigma open import Cubical.Data.Unit open import Cubical.Data.Empty as ⊥ hiding (elim) open import Cubical.Data.Sum as ⊎ hiding (elim) open import Cubical.Data.Prod renaming (_×_ to _×'_; _×Σ_ to _×_; swapΣEquiv to swapEquiv) hiding (swapEquiv) open import Cubical.HITs.PropositionalTruncation as PropTrunc hiding (elim) open import Cubical.HITs.Sn open import Cubical.HITs.Susp open import Cubical.HITs.Join open import Cubical.HITs.Pushout open import Cubical.HITs.Pushout.Flattening private variable ℓ ℓ' ℓ'' : Level -- Definition II.1 in [BR17], see also Cubical.Foundations.Bundle 2-EltType₀ = TypeEqvTo ℓ-zero Bool -- Σ[ X ∈ Type₀ ] ∥ X ≃ Bool ∥ 2-EltPointed₀ = PointedEqvTo ℓ-zero Bool -- Σ[ X ∈ Type₀ ] X × ∥ X ≃ Bool ∥ Bool* : 2-EltType₀ Bool* = Bool , ∣ idEquiv _ ∣ -- Our first goal is to 'lift' `_⊕_ : Bool → Bool ≃ Bool` to a function `_⊕_ : A → A ≃ Bool` -- for any 2-element type (A, ∣e∣). -- `isContr-BoolPointedIso` and `isContr-2-EltPointed-iso` are contained in the proof -- of Lemma II.2 in [BR17], though we prove `isContr-BoolPointedIso` more directly -- with ⊕ -- [BR17] proves it for just the x = false case and uses notEquiv to get -- the x = true case. -- (λ y → x ⊕ y) is the unqiue pointed isomorphism (Bool , false) ≃ (Bool , x) isContr-BoolPointedIso : ∀ x → isContr ((Bool , false) ≃[ pointed-iso ] (Bool , x)) fst (isContr-BoolPointedIso x) = ((λ y → x ⊕ y) , isEquiv-⊕ x) , ⊕-comm x false snd (isContr-BoolPointedIso x) (e , p) = ΣProp≡ (λ e → isSetBool (equivFun e false) x) (ΣProp≡ isPropIsEquiv (funExt λ { false → ⊕-comm x false ∙ sym p ; true → ⊕-comm x true ∙ sym q })) where q : e .fst true ≡ not x q with dichotomyBool (invEq e (not x)) ... | inl q = invEq≡→equivFun≡ e q ... | inr q = ⊥.rec (not≢const x (sym (invEq≡→equivFun≡ e q) ∙ p)) -- Since isContr is a mere proposition, we can eliminate a witness ∣e∣ : ∥ X ≃ Bool ∥ to get -- that there is therefore a unique pointed isomorphism (Bool , false) ≃ (X , x) for any -- 2-element pointed type (X , x, ∣e∣). isContr-2-EltPointed-iso : (X∙ : 2-EltPointed₀) → isContr ((Bool , false , ∣ idEquiv Bool ∣) ≃[ PointedEqvTo-iso Bool ] X∙) isContr-2-EltPointed-iso (X , x , ∣e∣) = PropTrunc.rec isPropIsContr (λ e → J (λ X∙ _ → isContr ((Bool , false) ≃[ pointed-iso ] X∙)) (isContr-BoolPointedIso (e .fst x)) (sym (pointed-sip _ _ (e , refl)))) ∣e∣ -- This unique isomorphism must be _⊕_ 'lifted' to X. This idea is alluded to at the end of the -- proof of Theorem III.4 in [BR17], where the authors reference needing ⊕-comm. module ⊕* (X : 2-EltType₀) where _⊕*_ : typ X → typ X → Bool y ⊕* z = invEquiv (fst (fst (isContr-2-EltPointed-iso (fst X , y , snd X)))) .fst z -- we've already shown that this map is an equivalence on the right isEquivʳ : (y : typ X) → isEquiv (y ⊕*_) isEquivʳ y = invEquiv (fst (fst (isContr-2-EltPointed-iso (fst X , y , snd X)))) .snd Equivʳ : typ X → typ X ≃ Bool Equivʳ y = (y ⊕*_) , isEquivʳ y -- any mere proposition that holds for (Bool, _⊕_) holds for (typ X, _⊕*_) -- this amounts to just carefully unfolding the PropTrunc.elim and J in isContr-2-EltPointed-iso elim : ∀ {ℓ'} (P : (A : Type₀) (_⊕'_ : A → A → Bool) → Type ℓ') (propP : ∀ A _⊕'_ → isProp (P A _⊕'_)) → P Bool _⊕_ → P (typ X) _⊕*_ elim {ℓ'} P propP r = PropTrunc.elim {P = λ ∣e∣ → P (typ X) (R₁ ∣e∣)} (λ _ → propP _ _) (λ e → EquivJ (λ A e → P A (R₂ A e)) r e) (snd X) where R₁ : ∥ fst X ≃ Bool ∥ → typ X → typ X → Bool R₁ ∣e∣ y = invEq (fst (fst (isContr-2-EltPointed-iso (fst X , y , ∣e∣)))) R₂ : (B : Type₀) → B ≃ Bool → B → B → Bool R₂ A e y = invEq (fst (fst (J (λ A∙ _ → isContr ((Bool , false) ≃[ pointed-iso ] A∙)) (isContr-BoolPointedIso (e .fst y)) (sym (pointed-sip (A , y) (Bool , e .fst y) (e , refl)))))) -- as a consequence, we get that ⊕* is commutative, and is therefore also an equivalence on the left comm : (y z : typ X) → y ⊕* z ≡ z ⊕* y comm = elim (λ A _⊕'_ → (x y : A) → x ⊕' y ≡ y ⊕' x) (λ _ _ → isPropPi (λ _ → isPropPi (λ _ → isSetBool _ _))) ⊕-comm isEquivˡ : (y : typ X) → isEquiv (_⊕* y) isEquivˡ y = subst isEquiv (funExt (λ z → comm y z)) (isEquivʳ y) Equivˡ : typ X → typ X ≃ Bool Equivˡ y = (_⊕* y) , isEquivˡ y -- Lemma II.2 in [BR17], though we do not use it here -- Note: Lemma II.3 is `pointed-sip`, used in `PointedEqvTo-sip` isContr-2-EltPointed : isContr (2-EltPointed₀) fst isContr-2-EltPointed = (Bool , false , ∣ idEquiv Bool ∣) snd isContr-2-EltPointed A∙ = PointedEqvTo-sip Bool _ A∙ (fst (isContr-2-EltPointed-iso A∙)) -------------------------------------------------------------------------------- -- Now we mutually define RP n and its double cover (Definition III.1 in [BR17]), -- and show that the total space of this double cover is S n (Theorem III.4). RP : ℕ₋₁ → Type₀ cov⁻¹ : (n : ℕ₋₁) → RP n → 2-EltType₀ -- (see Cubical.Foundations.Bundle) RP neg1 = ⊥ RP (ℕ→ℕ₋₁ n) = Pushout (pr (cov⁻¹ (-1+ n))) (λ _ → tt) {- tt Total (cov⁻¹ (n-1)) — — — > Unit | ∙ pr | ∙ inr | ∙ V V RP (n-1) ∙ ∙ ∙ ∙ ∙ ∙ > RP n := Pushout pr (const tt) inl -} cov⁻¹ neg1 x = Bool* cov⁻¹ (ℕ→ℕ₋₁ n) (inl x) = cov⁻¹ (-1+ n) x cov⁻¹ (ℕ→ℕ₋₁ n) (inr _) = Bool* cov⁻¹ (ℕ→ℕ₋₁ n) (push (x , y) i) = ua ((λ z → y ⊕* z) , ⊕*.isEquivʳ (cov⁻¹ (-1+ n) x) y) i , ∣p∣ i where open ⊕* (cov⁻¹ (-1+ n) x) ∣p∣ = isProp→PathP (λ i → squash {A = ua (⊕*.Equivʳ (cov⁻¹ (-1+ n) x) y) i ≃ Bool}) (str (cov⁻¹ (-1+ n) x)) (∣ idEquiv _ ∣) {- tt Total (cov⁻¹ (n-1)) — — — > Unit | | pr | // ua α // | Bool | | V V RP (n-1) - - - - - - > Type cov⁻¹ (n-1) where α : ∀ (x : Total (cov⁻¹ (n-1))) → cov⁻¹ (n-1) (pr x) ≃ Bool α (x , y) = (λ z → y ⊕* z) , ⊕*.isEquivʳ y -} TotalCov≃Sn : ∀ n → Total (cov⁻¹ n) ≃ S n TotalCov≃Sn neg1 = isoToEquiv (iso (λ { () }) (λ { () }) (λ { () }) (λ { () })) TotalCov≃Sn (ℕ→ℕ₋₁ n) = Total (cov⁻¹ (ℕ→ℕ₋₁ n)) ≃⟨ i ⟩ Pushout Σf Σg ≃⟨ ii ⟩ join (Total (cov⁻¹ (-1+ n))) Bool ≃⟨ iii ⟩ S (ℕ→ℕ₋₁ n) ■ where {- (i) First we want to show that `Total (cov⁻¹ (ℕ→ℕ₋₁ n))` is equivalent to a pushout. We do this using the flattening lemma, which states: Given f,g,F,G,e such that the following square commutes: g A — — — — > C Define: E : Pushout f g → Type | | E (inl b) = F b f | ua e | G E (inr c) = G c V V E (push a i) = ua (e a) i B — — — — > Type F Then, the total space `Σ (Pushout f g) E` is the following pushout: Σg := (g , e a) Σ[ a ∈ A ] F (f a) — — — — — — — — > Σ[ c ∈ C ] G c | ∙ Σf := (f , id) | ∙ V V Σ[ b ∈ B ] F b ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ ∙ > Σ (Pushout f g) E In our case, setting `f = pr (cov⁻¹ (n-1))`, `g = λ _ → tt`, `F = cov⁻¹ (n-1)`, `G = λ _ → Bool`, and `e = λ (x , y) → ⊕*.Equivʳ (cov⁻¹ (n-1) x) y` makes E equal (up to funExt) to `cov⁻¹ n`. Thus the flattening lemma gives us that `Total (cov⁻¹ n) ≃ Pushout Σf Σg`. -} open FlatteningLemma {- f = -} (λ x → pr (cov⁻¹ (-1+ n)) x) {- g = -} (λ _ → tt) {- F = -} (λ x → typ (cov⁻¹ (-1+ n) x)) {- G = -} (λ _ → Bool) {- e = -} (λ { (x , y) → ⊕*.Equivʳ (cov⁻¹ (-1+ n) x) y }) hiding (Σf ; Σg) cov⁻¹≃E : ∀ x → typ (cov⁻¹ (ℕ→ℕ₋₁ n) x) ≃ E x cov⁻¹≃E (inl x) = idEquiv _ cov⁻¹≃E (inr x) = idEquiv _ cov⁻¹≃E (push a i) = idEquiv _ -- for easier reference, we copy these definitons here Σf : Σ[ x ∈ Total (cov⁻¹ (-1+ n)) ] typ (cov⁻¹ (-1+ n) (fst x)) → Total (cov⁻¹ (-1+ n)) Σg : Σ[ x ∈ Total (cov⁻¹ (-1+ n)) ] typ (cov⁻¹ (-1+ n) (fst x)) → Unit × Bool Σf ((x , y) , z) = (x , z) -- ≡ (f a , x) Σg ((x , y) , z) = (tt , y ⊕* z) -- ≡ (g a , (e a) .fst x) where open ⊕* (cov⁻¹ (-1+ n) x) i : Total (cov⁻¹ (ℕ→ℕ₋₁ n)) ≃ Pushout Σf Σg i = (Σ[ x ∈ RP (ℕ→ℕ₋₁ n) ] typ (cov⁻¹ (ℕ→ℕ₋₁ n) x)) ≃⟨ congΣEquiv cov⁻¹≃E ⟩ (Σ[ x ∈ RP (ℕ→ℕ₋₁ n) ] E x) ≃⟨ flatten ⟩ Pushout Σf Σg ■ {- (ii) Next we want to show that `Pushout Σf Σg` is equivalent to `join (Total (cov⁻¹ (n-1))) Bool`. Since both are pushouts, this can be done by defining a diagram equivalence: Σf Σg Total (cov⁻¹ (n-1)) < — — Σ[ x ∈ Total (cov⁻¹ (n-1)) ] cov⁻¹ (n-1) (pr x) — — > Unit × Bool | ∙ | id |≃ u ∙≃ snd |≃ V V V Total (cov⁻¹ (n-1)) < — — — — — — — Total (cov⁻¹ (n-1)) × Bool — — — — — — — — — > Bool proj₁ proj₂ where the equivalence u above must therefore satisfy: `u .fst x ≡ (Σf x , snd (Σg x))` Unfolding this, we get: `u .fst ((x , y) , z) ≡ ((x , z) , (y ⊕* z))` It suffices to show that the map y ↦ y ⊕* z is an equivalence, since we can then express u as the following composition of equivalences: ((x , y) , z) ↦ (x , (y , z)) ↦ (x , (z , y)) ↦ (x , (z , y ⊕* z)) ↦ ((x , z) , y ⊕* z) This was proved above by ⊕*.isEquivˡ. -} u : ∀ {n} → (Σ[ x ∈ Total (cov⁻¹ n) ] typ (cov⁻¹ n (fst x))) ≃ (Total (cov⁻¹ n) ×' Bool) u {n} = Σ[ x ∈ Total (cov⁻¹ n) ] typ (cov⁻¹ n (fst x)) ≃⟨ assocΣ ⟩ Σ[ x ∈ RP n ] (typ (cov⁻¹ n x)) × (typ (cov⁻¹ n x)) ≃⟨ congΣEquiv (λ x → swapEquiv _ _) ⟩ Σ[ x ∈ RP n ] (typ (cov⁻¹ n x)) × (typ (cov⁻¹ n x)) ≃⟨ congΣEquiv (λ x → congΣEquiv (λ y → ⊕*.Equivˡ (cov⁻¹ n x) y)) ⟩ Σ[ x ∈ RP n ] (typ (cov⁻¹ n x)) × Bool ≃⟨ invEquiv assocΣ ⟩ Total (cov⁻¹ n) × Bool ≃⟨ invEquiv A×B≃A×ΣB ⟩ Total (cov⁻¹ n) ×' Bool ■ H : ∀ x → u .fst x ≡ (Σf x , snd (Σg x)) H x = refl nat : 3-span-equiv (3span Σf Σg) (3span {A2 = Total (cov⁻¹ (-1+ n)) ×' Bool} proj₁ proj₂) nat = record { e0 = idEquiv _ ; e2 = u ; e4 = ΣUnit _ ; H1 = λ x → cong proj₁ (H x) ; H3 = λ x → cong proj₂ (H x) } ii : Pushout Σf Σg ≃ join (Total (cov⁻¹ (-1+ n))) Bool ii = compEquiv (pathToEquiv (spanEquivToPushoutPath nat)) (joinPushout≃join _ _) {- (iii) Finally, it's trivial to show that `join (Total (cov⁻¹ (n-1))) Bool` is equivalent to `Susp (Total (cov⁻¹ (n-1)))`. Induction then gives us that `Susp (Total (cov⁻¹ (n-1)))` is equivalent to `S n`, which completes the proof. -} iii : join (Total (cov⁻¹ (-1+ n))) Bool ≃ S (ℕ→ℕ₋₁ n) iii = join (Total (cov⁻¹ (-1+ n))) Bool ≃⟨ invEquiv Susp≃joinBool ⟩ Susp (Total (cov⁻¹ (-1+ n))) ≃⟨ congSuspEquiv (TotalCov≃Sn (-1+ n)) ⟩ S (ℕ→ℕ₋₁ n) ■ -- the usual covering map S n → RP n, with fibers exactly cov⁻¹ cov : (n : ℕ₋₁) → S n → RP n cov n = pr (cov⁻¹ n) ∘ invEq (TotalCov≃Sn n) fibcov≡cov⁻¹ : ∀ n (x : RP n) → fiber (cov n) x ≡ cov⁻¹ n x .fst fibcov≡cov⁻¹ n x = fiber (cov n) x ≡[ i ]⟨ fiber {A = ua e i} (pr (cov⁻¹ n) ∘ ua-unglue e i) x ⟩ fiber (pr (cov⁻¹ n)) x ≡⟨ ua (fibPrEquiv (cov⁻¹ n) x) ⟩ cov⁻¹ n x .fst ∎ where e = invEquiv (TotalCov≃Sn n) -------------------------------------------------------------------------------- -- Finally, we state the trivial equivalences for RP 0 and RP 1 (Example III.3 in [BR17]) RP0≃Unit : RP 0 ≃ Unit RP0≃Unit = isoToEquiv (iso (λ _ → tt) (λ _ → inr tt) (λ _ → refl) (λ { (inr tt) → refl })) RP1≡S1 : RP 1 ≡ S 1 RP1≡S1 = Pushout {A = Total (cov⁻¹ 0)} {B = RP 0} (pr (cov⁻¹ 0)) (λ _ → tt) ≡⟨ i ⟩ Pushout {A = Total (cov⁻¹ 0)} {B = Unit} (λ _ → tt) (λ _ → tt) ≡⟨ ii ⟩ Pushout {A = S 0} {B = Unit} (λ _ → tt) (λ _ → tt) ≡⟨ PushoutSusp≡Susp ⟩ S 1 ∎ where i = λ i → Pushout {A = Total (cov⁻¹ 0)} {B = ua RP0≃Unit i} (λ x → ua-gluePt RP0≃Unit i (pr (cov⁻¹ 0) x)) (λ _ → tt) ii = λ j → Pushout {A = ua (TotalCov≃Sn 0) j} (λ _ → tt) (λ _ → tt)
algebraic-stack_agda0000_doc_13038
{-# OPTIONS --allow-unsolved-metas #-} open import Agda.Builtin.Bool postulate A : Set F : Bool → Set F true = A F false = A data D {b : Bool} (x : F b) : Set where variable b : Bool x : F b postulate f : D x → (P : F b → Set) → P x
algebraic-stack_agda0000_doc_13039
-- {-# OPTIONS -v scope.clash:20 #-} -- Andreas, 2012-10-19 test case for Issue 719 module ShadowModule2 where open import Common.Size as YesDuplicate import Common.Size as NotDuplicate private open module YesDuplicate = NotDuplicate -- should report: -- Duplicate definition of module YesDuplicate. -- NOT: Duplicate definition of module NotDuplicate.
algebraic-stack_agda0000_doc_4832
module CS410-Monoid where open import CS410-Prelude record Monoid (M : Set) : Set where field -- OPERATIONS ---------------------------------------- e : M op : M -> M -> M -- LAWS ---------------------------------------------- lunit : forall m -> op e m == m runit : forall m -> op m e == m assoc : forall m m' m'' -> op m (op m' m'') == op (op m m') m''
algebraic-stack_agda0000_doc_4833
------------------------------------------------------------------------ -- A combinator for running two computations in parallel ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} module Delay-monad.Parallel where import Equality.Propositional as Eq open import Prelude open import Prelude.Size open import Conat Eq.equality-with-J as Conat using (zero; suc; force; max) open import Delay-monad open import Delay-monad.Bisimilarity open import Delay-monad.Bisimilarity.Kind open import Delay-monad.Monad import Delay-monad.Sequential as S private variable a b : Level A B : Type a i : Size k : Kind f f₁ f₂ g : Delay (A → B) ∞ x x₁ x₂ y y₁ y₂ : Delay A ∞ f′ : Delay′ (A → B) ∞ x′ : Delay′ A ∞ h : A → B z : A ------------------------------------------------------------------------ -- The _⊛_ operator -- Parallel composition of computations. infixl 6 _⊛_ _⊛_ : Delay (A → B) i → Delay A i → Delay B i now f ⊛ now x = now (f x) now f ⊛ later x = later λ { .force → now f ⊛ x .force } later f ⊛ now x = later λ { .force → f .force ⊛ now x } later f ⊛ later x = later λ { .force → f .force ⊛ x .force } -- The number of later constructors in f ⊛ x is bisimilar to the -- maximum of the number of later constructors in f and the number of -- later constructors in x. steps-⊛∼max-steps-steps : Conat.[ i ] steps (f ⊛ x) ∼ max (steps f) (steps x) steps-⊛∼max-steps-steps {f = now _} {x = now _} = zero steps-⊛∼max-steps-steps {f = now _} {x = later _} = suc λ { .force → steps-⊛∼max-steps-steps } steps-⊛∼max-steps-steps {f = later _} {x = now _} = suc λ { .force → steps-⊛∼max-steps-steps } steps-⊛∼max-steps-steps {f = later _} {x = later _} = suc λ { .force → steps-⊛∼max-steps-steps } -- Rearrangement lemmas for _⊛_. later-⊛ : later f′ ⊛ x ∼ later (record { force = f′ .force ⊛ drop-later x }) later-⊛ {x = now _} = later λ { .force → _ ∎ } later-⊛ {x = later _} = later λ { .force → _ ∎ } ⊛-later : f ⊛ later x′ ∼ later (record { force = drop-later f ⊛ x′ .force }) ⊛-later {f = now _} = later λ { .force → _ ∎ } ⊛-later {f = later _} = later λ { .force → _ ∎ } -- The _⊛_ operator preserves strong and weak bisimilarity and -- expansion. infixl 6 _⊛-cong_ _⊛-cong_ : [ i ] f₁ ⟨ k ⟩ f₂ → [ i ] x₁ ⟨ k ⟩ x₂ → [ i ] f₁ ⊛ x₁ ⟨ k ⟩ f₂ ⊛ x₂ now ⊛-cong now = now now ⊛-cong later q = later λ { .force → now ⊛-cong q .force } now ⊛-cong laterˡ q = laterˡ (now ⊛-cong q) now ⊛-cong laterʳ q = laterʳ (now ⊛-cong q) later p ⊛-cong now = later λ { .force → p .force ⊛-cong now } laterˡ p ⊛-cong now = laterˡ (p ⊛-cong now) laterʳ p ⊛-cong now = laterʳ (p ⊛-cong now) later p ⊛-cong later q = later λ { .force → p .force ⊛-cong q .force } laterʳ p ⊛-cong laterʳ q = laterʳ (p ⊛-cong q) laterˡ p ⊛-cong laterˡ q = laterˡ (p ⊛-cong q) later {x = f₁} {y = f₂} p ⊛-cong laterˡ {x = x₁} {y = x₂} q = later f₁ ⊛ later x₁ ∼⟨ (later λ { .force → _ ∎ }) ⟩ later (record { force = f₁ .force ⊛ x₁ .force }) ?⟨ (later λ { .force → p .force ⊛-cong drop-laterʳ q }) ⟩∼ later (record { force = f₂ .force ⊛ drop-later x₂ }) ∼⟨ symmetric later-⊛ ⟩ later f₂ ⊛ x₂ ∎ later {x = f₁} {y = f₂} p ⊛-cong laterʳ {x = x₁} {y = x₂} q = later f₁ ⊛ x₁ ∼⟨ later-⊛ ⟩ later (record { force = f₁ .force ⊛ drop-later x₁ }) ≈⟨ (later λ { .force → p .force ⊛-cong drop-laterˡ q }) ⟩∼ later (record { force = f₂ .force ⊛ x₂ .force }) ∼⟨ (later λ { .force → _ ∎ }) ⟩ later f₂ ⊛ later x₂ ∎ laterˡ {x = f₁} {y = f₂} p ⊛-cong later {x = x₁} {y = x₂} q = later f₁ ⊛ later x₁ ∼⟨ (later λ { .force → _ ∎ }) ⟩ later (record { force = f₁ .force ⊛ x₁ .force }) ?⟨ (later λ { .force → drop-laterʳ p ⊛-cong q .force }) ⟩∼ later (record { force = drop-later f₂ ⊛ x₂ .force }) ∼⟨ symmetric ⊛-later ⟩ f₂ ⊛ later x₂ ∎ laterʳ {x = f₁} {y = f₂} p ⊛-cong later {x = x₁} {y = x₂} q = f₁ ⊛ later x₁ ∼⟨ ⊛-later ⟩ later (record { force = drop-later f₁ ⊛ x₁ .force }) ≈⟨ (later λ { .force → drop-laterˡ p ⊛-cong q .force }) ⟩∼ later (record { force = f₂ .force ⊛ x₂ .force }) ∼⟨ (later λ { .force → _ ∎ }) ⟩ later f₂ ⊛ later x₂ ∎ laterˡ {x = f₁} {y = f₂} p ⊛-cong laterʳ {x = x₁} {y = x₂} q = later f₁ ⊛ x₁ ∼⟨ later-⊛ ⟩ later (record { force = f₁ .force ⊛ drop-later x₁ }) ≈⟨ (later λ { .force → drop-laterʳ p ⊛-cong drop-laterˡ q }) ⟩∼ later (record { force = drop-later f₂ ⊛ x₂ .force }) ∼⟨ symmetric ⊛-later ⟩ f₂ ⊛ later x₂ ∎ laterʳ {x = f₁} {y = f₂} p ⊛-cong laterˡ {x = x₁} {y = x₂} q = f₁ ⊛ later x₁ ∼⟨ ⊛-later ⟩ later (record { force = drop-later f₁ ⊛ x₁ .force }) ≈⟨ (later λ { .force → drop-laterˡ p ⊛-cong drop-laterʳ q }) ⟩∼ later (record { force = f₂ .force ⊛ drop-later x₂ }) ∼⟨ symmetric later-⊛ ⟩ later f₂ ⊛ x₂ ∎ -- The _⊛_ operator is (kind of) commutative. ⊛-comm : [ i ] f ⊛ x ∼ map′ (flip _$_) x ⊛ f ⊛-comm {f = now f} {x = now x} = reflexive _ ⊛-comm {f = now f} {x = later x} = later λ { .force → ⊛-comm } ⊛-comm {f = later f} {x = now x} = later λ { .force → ⊛-comm } ⊛-comm {f = later f} {x = later x} = later λ { .force → ⊛-comm } -- The function map′ can be expressed using _⊛_. map∼now-⊛ : [ i ] map′ h x ∼ now h ⊛ x map∼now-⊛ {x = now x} = now map∼now-⊛ {x = later x} = later λ { .force → map∼now-⊛ } -- The applicative functor laws hold up to strong bisimilarity. now-id-⊛ : [ i ] now id ⊛ x ∼ x now-id-⊛ {x = now x} = now now-id-⊛ {x = later x} = later λ { .force → now-id-⊛ } now-∘-⊛-⊛-⊛ : [ i ] now (λ f → f ∘_) ⊛ f ⊛ g ⊛ x ∼ f ⊛ (g ⊛ x) now-∘-⊛-⊛-⊛ {f = now _} {g = now _} {x = now _} = now now-∘-⊛-⊛-⊛ {f = now _} {g = now _} {x = later _} = later λ { .force → now-∘-⊛-⊛-⊛ } now-∘-⊛-⊛-⊛ {f = now _} {g = later _} {x = now _} = later λ { .force → now-∘-⊛-⊛-⊛ } now-∘-⊛-⊛-⊛ {f = now _} {g = later _} {x = later _} = later λ { .force → now-∘-⊛-⊛-⊛ } now-∘-⊛-⊛-⊛ {f = later _} {g = now _} {x = now _} = later λ { .force → now-∘-⊛-⊛-⊛ } now-∘-⊛-⊛-⊛ {f = later _} {g = now _} {x = later _} = later λ { .force → now-∘-⊛-⊛-⊛ } now-∘-⊛-⊛-⊛ {f = later _} {g = later _} {x = now _} = later λ { .force → now-∘-⊛-⊛-⊛ } now-∘-⊛-⊛-⊛ {f = later _} {g = later _} {x = later _} = later λ { .force → now-∘-⊛-⊛-⊛ } now-⊛-now : [ i ] now h ⊛ now z ∼ now (h z) now-⊛-now = now ⊛-now : [ i ] f ⊛ now z ∼ now (λ f → f z) ⊛ f ⊛-now {f = now f} = now ⊛-now {f = later f} = later λ { .force → ⊛-now } -- Sequential composition is an expansion of parallel composition. ⊛≳⊛ : [ i ] f S.⊛ x ≳ f ⊛ x ⊛≳⊛ {f = now f} {x = now x} = now (f x) ∎ ⊛≳⊛ {f = now f} {x = later x} = later λ { .force → now f S.⊛ x .force ≳⟨ ⊛≳⊛ ⟩∎ now f ⊛ x .force ∎ } ⊛≳⊛ {f = later f} {x = now x} = later λ { .force → f .force S.⊛ now x ≳⟨ ⊛≳⊛ ⟩∎ f .force ⊛ now x ∎ } ⊛≳⊛ {f = later f} {x = later x} = later λ { .force → f .force S.⊛ later x ≳⟨ ((f .force ∎) >>=-cong λ _ → laterˡ (_ ∎)) ⟩ f .force S.⊛ x .force ≳⟨ ⊛≳⊛ ⟩∎ f .force ⊛ x .force ∎ } ------------------------------------------------------------------------ -- The _∣_ operator -- Parallel composition of computations. infix 10 _∣_ _∣_ : Delay A i → Delay B i → Delay (A × B) i x ∣ y = map′ _,_ x ⊛ y -- The number of later constructors in x ∣ y is bisimilar to the -- maximum of the number of later constructors in x and the number of -- later constructors in y. steps-∣∼max-steps-steps : Conat.[ i ] steps (x ∣ y) ∼ max (steps x) (steps y) steps-∣∼max-steps-steps {x = x} {y = y} = steps (x ∣ y) Conat.∼⟨ Conat.reflexive-∼ _ ⟩ steps (map′ _,_ x ⊛ y) Conat.∼⟨ steps-⊛∼max-steps-steps ⟩ max (steps (map′ _,_ x)) (steps y) Conat.∼⟨ Conat.max-cong (steps-map′ x) (Conat.reflexive-∼ _) ⟩∎ max (steps x) (steps y) ∎∼ -- The _∣_ operator preserves strong and weak bisimilarity and -- expansion. infix 10 _∣-cong_ _∣-cong_ : [ i ] x₁ ⟨ k ⟩ x₂ → [ i ] y₁ ⟨ k ⟩ y₂ → [ i ] x₁ ∣ y₁ ⟨ k ⟩ x₂ ∣ y₂ p ∣-cong q = map-cong _,_ p ⊛-cong q -- The _∣_ operator is commutative (up to swapping of results). ∣-comm : [ i ] x ∣ y ∼ map′ swap (y ∣ x) ∣-comm {x = x} {y = y} = x ∣ y ∼⟨⟩ map′ _,_ x ⊛ y ∼⟨ ⊛-comm ⟩ map′ (flip _$_) y ⊛ map′ _,_ x ∼⟨ map∼now-⊛ ⊛-cong map∼now-⊛ ⟩ now (flip _$_) ⊛ y ⊛ (now _,_ ⊛ x) ∼⟨ symmetric now-∘-⊛-⊛-⊛ ⟩ now (λ f → f ∘_) ⊛ (now (flip _$_) ⊛ y) ⊛ now _,_ ⊛ x ∼⟨ symmetric now-∘-⊛-⊛-⊛ ⊛-cong (_ ∎) ⊛-cong (_ ∎) ⟩ now _∘_ ⊛ now (λ f → f ∘_) ⊛ now (flip _$_) ⊛ y ⊛ now _,_ ⊛ x ∼⟨⟩ now (λ x f y → f y x) ⊛ y ⊛ now _,_ ⊛ x ∼⟨ ⊛-now ⊛-cong (_ ∎) ⟩ now (_$ _,_) ⊛ (now (λ x f y → f y x) ⊛ y) ⊛ x ∼⟨ symmetric now-∘-⊛-⊛-⊛ ⊛-cong (_ ∎) ⟩ now _∘_ ⊛ now (_$ _,_) ⊛ now (λ x f y → f y x) ⊛ y ⊛ x ∼⟨⟩ now (curry swap) ⊛ y ⊛ x ∼⟨⟩ now _∘_ ⊛ now (swap ∘_) ⊛ now _,_ ⊛ y ⊛ x ∼⟨ now-∘-⊛-⊛-⊛ ⊛-cong (_ ∎) ⟩ now (swap ∘_) ⊛ (now _,_ ⊛ y) ⊛ x ∼⟨ (_ ∎) ⊛-cong symmetric map∼now-⊛ ⊛-cong (_ ∎) ⟩ now (swap ∘_) ⊛ map′ _,_ y ⊛ x ∼⟨⟩ now _∘_ ⊛ now swap ⊛ map′ _,_ y ⊛ x ∼⟨ now-∘-⊛-⊛-⊛ ⟩ now swap ⊛ (map′ _,_ y ⊛ x) ∼⟨ symmetric map∼now-⊛ ⟩ map′ swap (map′ _,_ y ⊛ x) ∼⟨⟩ map′ swap (y ∣ x) ∎ -- Sequential composition is an expansion of parallel composition. ∣≳∣ : [ i ] x S.∣ y ≳ x ∣ y ∣≳∣ {x = x} {y = y} = x S.∣ y ∼⟨⟩ map′ _,_ x S.⊛ y ≳⟨ ⊛≳⊛ ⟩ map′ _,_ x ⊛ y ∼⟨⟩ x ∣ y ∎
algebraic-stack_agda0000_doc_4834
{-# OPTIONS --allow-exec #-} open import Agda.Builtin.FromNat open import Data.Bool.Base using (T; Bool; if_then_else_) open import Data.String using (String; _++_; lines) open import Data.Nat.Base using (ℕ) open import Data.Fin using (Fin) import Data.Fin.Literals as Fin import Data.Nat.Literals as Nat open import Data.Vec.Base using (Vec) open import Data.Float.Base using (Float; _≤ᵇ_) open import Data.List.Base using (List; []; _∷_) open import Data.Unit.Base using (⊤; tt) open import Relation.Nullary using (does) open import Relation.Binary.Core using (Rel) open import Reflection.Argument open import Reflection.Term open import Reflection.External open import Reflection.TypeChecking.Monad open import Reflection.TypeChecking.Monad.Syntax open import Reflection.Show using (showTerm) open import Vehicle.Utils module Vehicle where ------------------------------------------------------------------------ -- Metadata ------------------------------------------------------------------------ VEHICLE_COMMAND : String VEHICLE_COMMAND = "vehicle" ------------------------------------------------------------------------ -- Checking ------------------------------------------------------------------------ record CheckArgs : Set where field proofCache : String checkCmd : CheckArgs → CmdSpec checkCmd checkArgs = cmdSpec VEHICLE_COMMAND ( "check" ∷ ("--proofCache=" ++ proofCache) ∷ []) "" where open CheckArgs checkArgs checkSuccessful : String → Bool checkSuccessful output = "verified" ⊆ output postulate valid : ∀ {a} {A : Set a} → A `valid : Term `valid = def (quote valid) (hArg unknown ∷ []) checkSpecificationMacro : CheckArgs → Term → TC ⊤ checkSpecificationMacro args hole = do goal ← inferType hole -- (showTerm goal) output ← runCmdTC (checkCmd args) if checkSuccessful output then unify hole `valid else typeError (strErr ("Error: " ++ output) ∷ []) macro checkSpecification : CheckArgs → Term → TC ⊤ checkSpecification = checkSpecificationMacro ------------------------------------------------------------------------ -- Other ------------------------------------------------------------------------ instance finNumber : ∀ {n} -> Number (Fin n) finNumber {n} = Fin.number n natNumber : Number ℕ natNumber = Nat.number
algebraic-stack_agda0000_doc_4835
module Theory where open import Data.List using (List; []; _∷_; _++_) open import Data.Fin using () renaming (zero to fzero; suc to fsuc) open import Relation.Binary using (Rel) open import Level using (suc; _⊔_) open import Syntax record Theory ℓ₁ ℓ₂ ℓ₃ : Set (suc (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃)) where field Sg : Signature ℓ₁ ℓ₂ open Signature Sg open Term Sg field Ax : forall Γ A -> Rel (Γ ⊢ A) ℓ₃ infix 3 _⊢_≡_ infix 3 _⊨_≡_ data _⊢_≡_ : forall Γ {A} -> Γ ⊢ A -> Γ ⊢ A -> Set (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃) data _⊨_≡_ : forall Γ {Γ′} -> Γ ⊨ Γ′ -> Γ ⊨ Γ′ -> Set (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃) -- Theorems data _⊢_≡_ where ax : forall {Γ A e₁ e₂} -> Ax Γ A e₁ e₂ -> Γ ⊢ e₁ ≡ e₂ refl : forall {Γ} {A} {e : Γ ⊢ A} -> Γ ⊢ e ≡ e sym : forall {Γ} {A} {e₁ : Γ ⊢ A} {e₂} -> Γ ⊢ e₁ ≡ e₂ -> Γ ⊢ e₂ ≡ e₁ trans : forall {Γ} {A} {e₁ : Γ ⊢ A} {e₂ e₃} -> Γ ⊢ e₁ ≡ e₂ -> Γ ⊢ e₂ ≡ e₃ -> Γ ⊢ e₁ ≡ e₃ sub/id : forall {Γ} {A} {e : Γ ⊢ A} -> Γ ⊢ e [ id ] ≡ e sub/∙ : forall {Γ} {A} {Γ′ Γ′′} {e : Γ′′ ⊢ A} {γ : Γ′ ⊨ Γ′′} {δ} -> Γ ⊢ e [ γ ∙ δ ] ≡ e [ γ ] [ δ ] eta/Unit : forall {Γ} (e : Γ ⊢ Unit) -> Γ ⊢ unit ≡ e beta/*₁ : forall {Γ} {A B} (e₁ : Γ ⊢ A) (e₂ : Γ ⊢ B) -> Γ ⊢ fst (pair e₁ e₂) ≡ e₁ beta/*₂ : forall {Γ} {A B} (e₁ : Γ ⊢ A) (e₂ : Γ ⊢ B) -> Γ ⊢ snd (pair e₁ e₂) ≡ e₂ eta/* : forall {Γ} {A B} (e : Γ ⊢ A * B) -> Γ ⊢ pair (fst e) (snd e) ≡ e beta/=> : forall {Γ} {A B} (e : A ∷ Γ ⊢ B) (e′ : Γ ⊢ A) -> Γ ⊢ app (abs e) e′ ≡ e [ ext id e′ ] eta/=> : forall {Γ} {A B} (e : Γ ⊢ A => B) -> Γ ⊢ abs (app (e [ weaken ]) var) ≡ e -- cong cong/func : forall {Γ} {f : Func} {e e′ : Γ ⊢ dom f} -> Γ ⊢ e ≡ e′ -> Γ ⊢ func f e ≡ func f e′ cong/sub : forall {Γ Γ′} {γ γ′ : Γ ⊨ Γ′} {A} {e e′ : Γ′ ⊢ A} -> Γ ⊨ γ ≡ γ′ -> Γ′ ⊢ e ≡ e′ -> Γ ⊢ e [ γ ] ≡ e′ [ γ′ ] cong/pair : forall {Γ} {A B} {e₁ e₁′ : Γ ⊢ A} {e₂ e₂′ : Γ ⊢ B} -> Γ ⊢ e₁ ≡ e₁′ -> Γ ⊢ e₂ ≡ e₂′ -> Γ ⊢ pair e₁ e₂ ≡ pair e₁′ e₂′ cong/fst : forall {Γ} {A B} {e e′ : Γ ⊢ A * B} -> Γ ⊢ e ≡ e′ -> Γ ⊢ fst e ≡ fst e′ cong/snd : forall {Γ} {A B} {e e′ : Γ ⊢ A * B} -> Γ ⊢ e ≡ e′ -> Γ ⊢ snd e ≡ snd e′ cong/abs : forall {Γ} {A B} {e e′ : A ∷ Γ ⊢ B} -> A ∷ Γ ⊢ e ≡ e′ -> Γ ⊢ abs e ≡ abs e′ cong/app : forall {Γ} {A B} {e₁ e₁′ : Γ ⊢ A => B} {e₂ e₂′ : Γ ⊢ A} -> Γ ⊢ e₁ ≡ e₁′ -> Γ ⊢ e₂ ≡ e₂′ -> Γ ⊢ app e₁ e₂ ≡ app e₁′ e₂′ -- subst commutes with term formers comm/func : forall Γ Γ′ (γ : Γ ⊨ Γ′) f e -> Γ ⊢ func f e [ γ ] ≡ func f (e [ γ ]) comm/unit : forall Γ Γ′ (γ : Γ ⊨ Γ′) -> Γ ⊢ unit [ γ ] ≡ unit comm/pair : forall {Γ Γ′} {γ : Γ ⊨ Γ′} {A B} {e₁ : Γ′ ⊢ A} {e₂ : Γ′ ⊢ B} -> Γ ⊢ pair e₁ e₂ [ γ ] ≡ pair (e₁ [ γ ]) (e₂ [ γ ]) comm/fst : forall {Γ Γ′} {γ : Γ ⊨ Γ′} {A B} {e : Γ′ ⊢ A * B} -> Γ ⊢ fst e [ γ ] ≡ fst (e [ γ ]) comm/snd : forall {Γ Γ′} {γ : Γ ⊨ Γ′} {A B} {e : Γ′ ⊢ A * B} -> Γ ⊢ snd e [ γ ] ≡ snd (e [ γ ]) comm/abs : forall {Γ Γ′} {γ : Γ ⊨ Γ′} {A B} {e : A ∷ Γ′ ⊢ B} -> Γ ⊢ (abs e) [ γ ] ≡ abs (e [ ext (γ ∙ weaken) var ]) comm/app : forall {Γ Γ′} {γ : Γ ⊨ Γ′} {A B} {e₁ : Γ′ ⊢ A => B} {e₂} -> Γ ⊢ app e₁ e₂ [ γ ] ≡ app (e₁ [ γ ]) (e₂ [ γ ]) var/ext : forall {Γ Γ′} (γ : Γ ⊨ Γ′) {A} (e : Γ ⊢ A) -> Γ ⊢ var [ ext γ e ] ≡ e data _⊨_≡_ where refl : forall {Γ Γ′} {γ : Γ ⊨ Γ′} -> Γ ⊨ γ ≡ γ sym : forall {Γ Γ′} {γ γ′ : Γ ⊨ Γ′} -> Γ ⊨ γ ≡ γ′ -> Γ ⊨ γ′ ≡ γ trans : forall {Γ Γ′} {γ₁ γ₂ γ₃ : Γ ⊨ Γ′} -> Γ ⊨ γ₁ ≡ γ₂ -> Γ ⊨ γ₂ ≡ γ₃ -> Γ ⊨ γ₁ ≡ γ₃ id∙ˡ : forall {Γ Γ′} {γ : Γ ⊨ Γ′} -> Γ ⊨ id ∙ γ ≡ γ id∙ʳ : forall {Γ Γ′} {γ : Γ ⊨ Γ′} -> Γ ⊨ γ ∙ id ≡ γ assoc∙ : forall {Γ Γ′ Γ′′ Γ′′′} {γ₁ : Γ′′ ⊨ Γ′′′} {γ₂ : Γ′ ⊨ Γ′′} {γ₃ : Γ ⊨ Γ′} -> Γ ⊨ (γ₁ ∙ γ₂) ∙ γ₃ ≡ γ₁ ∙ (γ₂ ∙ γ₃) !-unique : forall {Γ} {γ : Γ ⊨ []} -> Γ ⊨ ! ≡ γ η-pair : forall {Γ : Context} {A : Type} -> A ∷ Γ ⊨ ext weaken var ≡ id ext∙ : forall {Γ Γ′ Γ′′} {γ : Γ′ ⊨ Γ′′} {γ′ : Γ ⊨ Γ′} {A} {e : Γ′ ⊢ A} -> Γ ⊨ ext γ e ∙ γ′ ≡ ext (γ ∙ γ′) (e [ γ′ ]) weaken/ext : forall {Γ Γ′} {γ : Γ ⊨ Γ′} {A} {e : Γ ⊢ A} -> Γ ⊨ weaken ∙ ext γ e ≡ γ cong/ext : forall {Γ Γ′} {γ γ′ : Γ ⊨ Γ′} {A} {e e′ : Γ ⊢ A} -> Γ ⊨ γ ≡ γ′ -> Γ ⊢ e ≡ e′ -> Γ ⊨ ext γ e ≡ ext γ′ e′ cong/∙ : forall {Γ Γ′ Γ′′} {γ γ′ : Γ′ ⊨ Γ′′} {δ δ′ : Γ ⊨ Γ′} -> Γ′ ⊨ γ ≡ γ′ -> Γ ⊨ δ ≡ δ′ -> Γ ⊨ γ ∙ δ ≡ γ′ ∙ δ′ ×id′-∙ : forall {Γ Γ′ Γ′′} {γ′ : Γ ⊨ Γ′} {γ : Γ′ ⊨ Γ′′} {A} -> A ∷ Γ ⊨ γ ×id′ ∙ γ′ ×id′ ≡ (γ ∙ γ′) ×id′ ×id′-∙ = trans ext∙ (cong/ext (trans assoc∙ (trans (cong/∙ refl weaken/ext) (sym assoc∙))) (var/ext _ _)) ×id′-ext : forall {Γ Γ′ Γ′′} {γ′ : Γ ⊨ Γ′} {γ : Γ′ ⊨ Γ′′} {A} {e : Γ ⊢ A} -> Γ ⊨ γ ×id′ ∙ ext γ′ e ≡ ext (γ ∙ γ′) e ×id′-ext = trans ext∙ (cong/ext (trans assoc∙ (cong/∙ refl weaken/ext)) (var/ext _ _)) open import Relation.Binary.Bundles TermSetoid : forall {Γ : Context} {A : Type} -> Setoid (ℓ₁ ⊔ ℓ₂) (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃) TermSetoid {Γ} {A} = record { Carrier = Γ ⊢ A ; _≈_ = λ e₁ e₂ → Γ ⊢ e₁ ≡ e₂ ;isEquivalence = record { refl = refl ; sym = sym ; trans = trans } } SubstSetoid : forall {Γ : Context} {Γ′ : Context} -> Setoid (ℓ₁ ⊔ ℓ₂) (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃) SubstSetoid {Γ} {Γ′} = record { Carrier = Γ ⊨ Γ′ ; _≈_ = λ γ₁ γ₂ → Γ ⊨ γ₁ ≡ γ₂ ;isEquivalence = record { refl = refl ; sym = sym ; trans = trans } } open import Categories.Category open import Categories.Category.CartesianClosed module _ {o ℓ e} (𝒞 : Category o ℓ e) (CC : CartesianClosed 𝒞) {ℓ₁ ℓ₂ ℓ₃} (Th : Theory ℓ₁ ℓ₂ ℓ₃) where open Category 𝒞 open import Data.Product using (Σ-syntax) open Theory Th open import Semantics 𝒞 CC Sg Model : Set (o ⊔ ℓ ⊔ e ⊔ ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃) Model = Σ[ M ∈ Structure ] forall {Γ A e₁ e₂} -> Ax Γ A e₁ e₂ -> ⟦ e₁ ⟧ M ≈ ⟦ e₂ ⟧ M
algebraic-stack_agda0000_doc_4836
module Prelude.Unit where data Unit : Set where unit : Unit
algebraic-stack_agda0000_doc_4837
------------------------------------------------------------------------ -- The Agda standard library -- -- Bounded vectors (inefficient implementation) ------------------------------------------------------------------------ -- Vectors of a specified maximum length. module Data.Star.BoundedVec where open import Data.Star open import Data.Star.Nat open import Data.Star.Decoration open import Data.Star.Pointer open import Data.Star.List using (List) open import Data.Unit open import Function import Data.Maybe as Maybe open import Relation.Binary open import Relation.Binary.Consequences ------------------------------------------------------------------------ -- The type -- Finite sets decorated with elements (note the use of suc). BoundedVec : Set → ℕ → Set BoundedVec a n = Any (λ _ → a) (λ _ → ⊤) (suc n) [] : ∀ {a n} → BoundedVec a n [] = this tt infixr 5 _∷_ _∷_ : ∀ {a n} → a → BoundedVec a n → BoundedVec a (suc n) _∷_ = that ------------------------------------------------------------------------ -- Increasing the bound -- Note that this operation is linear in the length of the list. ↑ : ∀ {a n} → BoundedVec a n → BoundedVec a (suc n) ↑ {a} = gmap inc lift where inc = Maybe.map (map-NonEmpty suc) lift : Pointer (λ _ → a) (λ _ → ⊤) =[ inc ]⇒ Pointer (λ _ → a) (λ _ → ⊤) lift (step x) = step x lift (done _) = done _ ------------------------------------------------------------------------ -- Conversions fromList : ∀ {a} → (xs : List a) → BoundedVec a (length xs) fromList ε = [] fromList (x ◅ xs) = x ∷ fromList xs toList : ∀ {a n} → BoundedVec a n → List a toList xs = gmap (const tt) decoration (init xs)
algebraic-stack_agda0000_doc_4838
{-# OPTIONS --without-K --rewriting #-} open import HoTT module homotopy.SmashFmapConn where module _ {i} {j} {A : Type i} (B : A → Type j) where custom-assoc : {a₀ a₁ a₂ a₃ : A} {b₀ : B a₀} {b₁ b₁' b₁'' : B a₁} {b₂ : B a₂} {b₃ : B a₃} {p : a₀ == a₁} (p' : b₀ == b₁ [ B ↓ p ]) (q' : b₁ == b₁') (r' : b₁' == b₁'') {s : a₁ == a₂} (s' : b₁'' == b₂ [ B ↓ s ]) {t : a₂ == a₃} (t' : b₂ == b₃ [ B ↓ t ]) → p' ∙ᵈ (((q' ∙ r') ◃ s') ∙ᵈ t') == ((p' ▹ q') ▹ r') ∙ᵈ s' ∙ᵈ t' custom-assoc {p = idp} p'@idp q'@idp r'@idp {s = idp} s'@idp {t = idp} t' = idp transp-over : {a₀ a₁ : A} (p : a₀ == a₁) (b₀ : B a₀) → b₀ == transport B p b₀ [ B ↓ p ] transp-over p b₀ = from-transp B p (idp {a = transport B p b₀}) transp-over-naturality : ∀ {a₀ a₁ : A} (p : a₀ == a₁) {b₀ b₀' : B a₀} (q : b₀ == b₀') → q ◃ transp-over p b₀' == transp-over p b₀ ▹ ap (transport B p) q transp-over-naturality p@idp q@idp = idp to-transp-over : {a₀ a₁ : A} {p : a₀ == a₁} {b₀ : B a₀} {b₁ : B a₁} (q : b₀ == b₁ [ B ↓ p ]) → q ▹ ! (to-transp q) == transp-over p b₀ to-transp-over {p = idp} q@idp = idp module _ {i} {j} {S* : Type i} (P* : S* → Type j) where -- cpa = custom path algebra cpa₁ : {s₁ s₂ t : S*} (p* : P* s₂) (p₁ : s₁ == t) (p₂ : s₂ == t) → transport P* (! (p₁ ∙ ! p₂)) p* == transport P* p₂ p* [ P* ↓ p₁ ] cpa₁ p* p₁@idp p₂@idp = idp -- cpac = custom path algebra coherence cpac₁ : ∀ {k} {C : Type k} (f : C → S*) {c₁ c₂ : C} (q : c₁ == c₂) (d : Π C (P* ∘ f)) {t : S*} (p₁ : f c₁ == t) (p₂ : f c₂ == t) (r : ap f q == p₁ ∙' ! p₂) {u : P* (f c₂)} (v : u == transport P* (! (p₂ ∙ ! p₂)) (d c₂)) {u' : P* (f c₁)} (v' : u' == transport P* (! (p₁ ∙ ! p₂)) (d c₂)) → (v' ∙ ap (λ pp → transport P* pp (d c₂)) (ap ! (! (r ∙ ∙'=∙ p₁ (! p₂))) ∙ !-ap f q) ∙ to-transp {B = P*} {p = ap f (! q)} (↓-ap-in P* f (apd d (! q)))) ◃ apd d q == ↓-ap-out= P* f q (r ∙ ∙'=∙ p₁ (! p₂)) ((v' ◃ cpa₁ (d c₂) p₁ p₂) ∙ᵈ !ᵈ (v ◃ cpa₁ (d c₂) p₂ p₂)) ▹ (v ∙ ap (λ pp → transport P* (! pp) (d c₂)) (!-inv-r p₂)) cpac₁ f q@idp d p₁@.idp p₂@idp r@idp v@idp v'@idp = idp cpa₂ : ∀ {k} {C : Type k} (f : C → S*) {c₁ c₂ : C} (q : c₁ == c₂) (d : Π C (P* ∘ f)) {s t : S*} (p : f c₁ == s) (r : s == t) (u : f c₂ == t) (h : ap f q == p ∙' (r ∙ ! u)) → transport P* p (d c₁) == transport P* u (d c₂) [ P* ↓ r ] cpa₂ f q@idp d [email protected] r@idp u@idp h@idp = idp cpac₂ : ∀ {k} {C : Type k} (f : C → S*) {c₁ c₂ c₃ : C} (q : c₁ == c₂) (q' : c₃ == c₂) (d : Π C (P* ∘ f)) {s t : S*} (p : f c₁ == s) (p' : f c₃ == f c₂) (r : s == t) (u : f c₂ == t) (h : ap f q == p ∙' (r ∙ ! u)) (h' : ap f q' == p' ∙' u ∙ ! u) {x : P* (f c₂)} (x' : x == transport P* p' (d c₃)) {y : P* (f c₁)} (y' : y == d c₁) → ↓-ap-out= P* f q (h ∙ ∙'=∙ p (r ∙ ! u)) ((y' ◃ transp-over P* p (d c₁)) ∙ᵈ cpa₂ f q d p r u h ∙ᵈ !ᵈ (x' ◃ cpa₂ f q' d p' u u h')) ▹ (x' ∙ ap (λ pp → transport P* pp (d c₃)) (! (∙-unit-r p') ∙ ap (p' ∙_) (! (!-inv-r u)) ∙ ! (h' ∙ ∙'=∙ p' (u ∙ ! u))) ∙ to-transp (↓-ap-in P* f (apd d q'))) == y' ◃ apd d q cpac₂ f q@idp q'@idp d [email protected] p'@.idp r@idp u@idp h@idp h'@idp x'@idp y'@idp = idp module _ {i} {j} {k} {A : Ptd i} {A' : Ptd j} (f : A ⊙→ A') (B : Ptd k) {m n : ℕ₋₂} (f-is-m-conn : has-conn-fibers m (fst f)) (B-is-Sn-conn : is-connected (S n) (de⊙ B)) where private a₀ = pt A a₀' = pt A' b₀ = pt B module ConnIn (P : A' ∧ B → (n +2+ m) -Type (lmax i (lmax j k))) (d : ∀ (ab : A ∧ B) → fst (P (∧-fmap f (⊙idf B) ab))) where h : ∀ (b : de⊙ B) → (∀ (a' : de⊙ A') → fst (P (smin a' b))) → (∀ (a : de⊙ A) → fst (P (smin (fst f a) b))) h b s = s ∘ fst f Q : de⊙ B → n -Type (lmax i (lmax j k)) Q b = Q' , Q'-level where Q' : Type (lmax i (lmax j k)) Q' = hfiber (h b) (λ a → d (smin a b)) Q'-level : has-level n Q' Q'-level = conn-extend-general {n = m} {k = n} f-is-m-conn (λ a → P (smin a b)) (λ a → d (smin a b)) s₀ : ∀ (a' : de⊙ A') → fst (P (smin a' b₀)) s₀ a' = transport (fst ∘ P) (! (∧-norm-l a')) (d smbasel) ∧-fmap-smgluel-β-∙' : ∀ (a : de⊙ A) → ap (∧-fmap f (⊙idf B)) (smgluel a) == smgluel (fst f a) ∙' ! (smgluel a₀') ∧-fmap-smgluel-β-∙' a = ∧-fmap-smgluel-β' f (⊙idf B) a ∙ ∙=∙' (smgluel (fst f a)) (! (smgluel a₀')) ∧-fmap-smgluel-β-∙ : ∀ (a : de⊙ A) → ap (∧-fmap f (⊙idf B)) (smgluel a) == smgluel (fst f a) ∙ ! (smgluel a₀') ∧-fmap-smgluel-β-∙ a = ∧-fmap-smgluel-β-∙' a ∙ ∙'=∙ (smgluel (fst f a)) (! (smgluel a₀')) ∧-fmap-smgluer-β-∙' : ∀ (b : de⊙ B) → ap (∧-fmap f (⊙idf B)) (smgluer b) == ap (λ a' → smin a' b) (snd f) ∙' ∧-norm-r b ∧-fmap-smgluer-β-∙' b = ∧-fmap-smgluer-β' f (⊙idf B) b ∙ ∙=∙' (ap (λ a' → smin a' b) (snd f)) (∧-norm-r b) ∧-fmap-smgluer-β-∙ : ∀ (b : de⊙ B) → ap (∧-fmap f (⊙idf B)) (smgluer b) == ap (λ a' → smin a' b) (snd f) ∙ ∧-norm-r b ∧-fmap-smgluer-β-∙ b = ∧-fmap-smgluer-β-∙' b ∙ ∙'=∙ (ap (λ a' → smin a' b) (snd f)) (∧-norm-r b) s₀-f : ∀ (a : de⊙ A) → s₀ (fst f a) == d (smin a b₀) s₀-f a = ap (λ p → transport (λ a'b → fst (P a'b)) p (d smbasel)) q ∙ to-transp {B = fst ∘ P} {p = ap (∧-fmap f (⊙idf B)) (! (smgluel a))} (↓-ap-in (fst ∘ P) (∧-fmap f (⊙idf B)) (apd d (! (smgluel a)))) where q : ! (∧-norm-l (fst f a)) == ap (∧-fmap f (⊙idf B)) (! (smgluel a)) q = ap ! (! (∧-fmap-smgluel-β-∙ a)) ∙ !-ap (∧-fmap f (⊙idf B)) (smgluel a) q₀ : fst (Q b₀) q₀ = s₀ , s₀-lies-over-pt where s₀-lies-over-pt : h b₀ s₀ == (λ a → d (smin a b₀)) s₀-lies-over-pt = λ= s₀-f q : ∀ (b : de⊙ B) → fst (Q b) q = conn-extend {n = n} {h = cst b₀} (pointed-conn-out (de⊙ B) b₀ {{B-is-Sn-conn}}) Q (λ _ → q₀) q-f : q b₀ == q₀ q-f = conn-extend-β {n = n} {h = cst b₀} (pointed-conn-out (de⊙ B) b₀ {{B-is-Sn-conn}}) Q (λ _ → q₀) unit s : ∀ (a' : de⊙ A') (b : de⊙ B) → fst (P (smin a' b)) s a' b = fst (q b) a' s-b₀ : ∀ (a' : de⊙ A') → s a' b₀ == s₀ a' s-b₀ a' = ap (λ u → fst u a') q-f s-f : ∀ (a : de⊙ A) (b : de⊙ B) → s (fst f a) b == d (smin a b) s-f a b = app= (snd (q b)) a s-f-b₀ : ∀ (a : de⊙ A) → s-f a b₀ == s-b₀ (fst f a) ∙ s₀-f a s-f-b₀ a = app= (snd (q b₀)) a =⟨ ↓-app=cst-out' (apd (λ u → app= (snd u) a) q-f) ⟩ s-b₀ (fst f a) ∙' app= (snd q₀) a =⟨ ap (s-b₀ (fst f a) ∙'_) (app=-β s₀-f a) ⟩ s-b₀ (fst f a) ∙' s₀-f a =⟨ ∙'=∙ (s-b₀ (fst f a)) (s₀-f a) ⟩ s-b₀ (fst f a) ∙ s₀-f a =∎ s-a₀' : ∀ (b : de⊙ B) → s a₀' b == transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (d (smin a₀ b)) s-a₀' b = ↯ $ s a₀' b =⟪ ! (to-transp (↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f)))) ⟫ transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (s (fst f a₀) b) =⟪ ap (transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f))) (s-f a₀ b) ⟫ transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (d (smin a₀ b)) ∎∎ section-smbasel : fst (P smbasel) section-smbasel = transport (fst ∘ P) (smgluel a₀') (d smbasel) section-smbaser : fst (P smbaser) section-smbaser = transport (fst ∘ P) (smgluer b₀) (d smbaser) section-smgluel' : ∀ (a' : de⊙ A') → s₀ a' == section-smbasel [ fst ∘ P ↓ smgluel a' ] section-smgluel' a' = cpa₁ (fst ∘ P) (d smbasel) (smgluel a') (smgluel a₀') section-smgluel : ∀ (a' : de⊙ A') → s a' b₀ == section-smbasel [ fst ∘ P ↓ smgluel a' ] section-smgluel a' = s-b₀ a' ◃ section-smgluel' a' section-smgluer' : ∀ (b : de⊙ B) → transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (d (smin a₀ b)) == section-smbaser [ fst ∘ P ↓ smgluer b ] section-smgluer' b = cpa₂ (fst ∘ P) (∧-fmap f (⊙idf B)) (smgluer b) d (ap (λ a' → smin a' b) (snd f)) (smgluer b) (smgluer b₀) (∧-fmap-smgluer-β-∙' b) section-smgluer : ∀ (b : de⊙ B) → s a₀' b == section-smbaser [ fst ∘ P ↓ smgluer b ] section-smgluer b = s-a₀' b ◃ section-smgluer' b module Section = SmashElim {P = fst ∘ P} s section-smbasel section-smbaser section-smgluel section-smgluer section : Π (A' ∧ B) (fst ∘ P) section = Section.f is-section-smbasel : s a₀' b₀ == d smbasel is-section-smbasel = ↯ $ s a₀' b₀ =⟪ s-b₀ a₀' ⟫ s₀ a₀' =⟪idp⟫ transport (fst ∘ P) (! (∧-norm-l a₀')) (d smbasel) =⟪ ap (λ p → transport (fst ∘ P) (! p) (d smbasel)) (!-inv-r (smgluel a₀')) ⟫ d smbasel ∎∎ is-section-smgluel : ∀ (a : de⊙ A) → s-f a b₀ ◃ apd d (smgluel a) == apd (section ∘ ∧-fmap f (⊙idf B)) (smgluel a) ▹ is-section-smbasel is-section-smgluel a = s-f a b₀ ◃ apd d (smgluel a) =⟨ ap (_◃ apd d (smgluel a)) (s-f-b₀ a) ⟩ (s-b₀ (fst f a) ∙ s₀-f a) ◃ apd d (smgluel a) =⟨ cpac₁ (fst ∘ P) (∧-fmap f (⊙idf B)) (smgluel a) d (smgluel (fst f a)) (smgluel a₀') (∧-fmap-smgluel-β-∙' a) (s-b₀ a₀') (s-b₀ (fst f a)) ⟩ ↓-ap-out= (fst ∘ P) (∧-fmap f (⊙idf B)) (smgluel a) (∧-fmap-smgluel-β-∙ a) (section-smgluel (fst f a) ∙ᵈ !ᵈ (section-smgluel a₀')) ▹ is-section-smbasel =⟨ ! $ ap (_▹ is-section-smbasel) $ ap (↓-ap-out= (fst ∘ P) (∧-fmap f (⊙idf B)) (smgluel a) (∧-fmap-smgluel-β-∙ a)) $ apd-section-norm-l (fst f a) ⟩ ↓-ap-out= (fst ∘ P) (∧-fmap f (⊙idf B)) (smgluel a) (∧-fmap-smgluel-β-∙ a) (apd section (∧-norm-l (fst f a))) ▹ is-section-smbasel =⟨ ! $ ap (_▹ is-section-smbasel) $ apd-∘'' section (∧-fmap f (⊙idf B)) (smgluel a) (∧-fmap-smgluel-β-∙ a) ⟩ apd (section ∘ ∧-fmap f (⊙idf B)) (smgluel a) ▹ is-section-smbasel =∎ where apd-section-norm-l : ∀ (a' : de⊙ A') → apd section (∧-norm-l a') == section-smgluel a' ∙ᵈ !ᵈ (section-smgluel a₀') apd-section-norm-l a' = apd section (∧-norm-l a') =⟨ apd-∙ section (smgluel a') (! (smgluel a₀')) ⟩ apd section (smgluel a') ∙ᵈ apd section (! (smgluel a₀')) =⟨ ap2 _∙ᵈ_ (Section.smgluel-β a') (apd-! section (smgluel a₀') ∙ ap !ᵈ (Section.smgluel-β a₀')) ⟩ section-smgluel a' ∙ᵈ !ᵈ (section-smgluel a₀') =∎ is-section-smbaser : s a₀' b₀ == d smbaser is-section-smbaser = ↯ $ s a₀' b₀ =⟪ s-a₀' b₀ ⟫ transport (fst ∘ P) (ap (λ a' → smin a' b₀) (snd f)) (d (smin a₀ b₀)) =⟪ ap (λ p → transport (fst ∘ P) p (d (smin a₀ b₀))) (↯ r) ⟫ transport (fst ∘ P) (ap (∧-fmap f (⊙idf B)) (smgluer b₀)) (d (smin a₀ b₀)) =⟪ to-transp (↓-ap-in (fst ∘ P) (∧-fmap f (⊙idf B)) (apd d (smgluer b₀))) ⟫ d smbaser ∎∎ where r : ap (λ a' → smin a' b₀) (snd f) =-= ap (∧-fmap f (⊙idf B)) (smgluer b₀) r = ap (λ a' → smin a' b₀) (snd f) =⟪ ! (∙-unit-r _) ⟫ ap (λ a' → smin a' b₀) (snd f) ∙ idp =⟪ ap (ap (λ a' → smin a' b₀) (snd f) ∙_) (! (!-inv-r (smgluer b₀))) ⟫ ap (λ a' → smin a' b₀) (snd f) ∙ ∧-norm-r b₀ =⟪ ! (∧-fmap-smgluer-β-∙ b₀) ⟫ ap (∧-fmap f (⊙idf B)) (smgluer b₀) ∎∎ is-section-smgluer : ∀ (b : de⊙ B) → s-f a₀ b ◃ apd d (smgluer b) == apd (section ∘ ∧-fmap f (⊙idf B)) (smgluer b) ▹ is-section-smbaser is-section-smgluer b = ! $ apd (section ∘ ∧-fmap f (⊙idf B)) (smgluer b) ▹ is-section-smbaser =⟨ ap (_▹ is-section-smbaser) $ apd-∘'' section (∧-fmap f (⊙idf B)) (smgluer b) (∧-fmap-smgluer-β-∙ b) ⟩ ↓-ap-out= (fst ∘ P) (∧-fmap f (⊙idf B)) (smgluer b) (∧-fmap-smgluer-β-∙ b) (apd section (ap (λ a' → smin a' b) (snd f) ∙ ∧-norm-r b)) ▹ is-section-smbaser =⟨ ap (_▹ is-section-smbaser) $ ap (↓-ap-out= (fst ∘ P) (∧-fmap f (⊙idf B)) (smgluer b) (∧-fmap-smgluer-β-∙ b)) $ apd-section-helper ⟩ ↓-ap-out= (fst ∘ P) (∧-fmap f (⊙idf B)) (smgluer b) (∧-fmap-smgluer-β-∙ b) ((s-f a₀ b ◃ transp-over (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (d (smin a₀ b))) ∙ᵈ section-smgluer' b ∙ᵈ !ᵈ (section-smgluer b₀)) ▹ is-section-smbaser =⟨ cpac₂ (fst ∘ P) (∧-fmap f (⊙idf B)) (smgluer b) (smgluer b₀) d (ap (λ a' → smin a' b) (snd f)) (ap (λ a' → smin a' b₀) (snd f)) (smgluer b) (smgluer b₀) (∧-fmap-smgluer-β-∙' b) (∧-fmap-smgluer-β-∙' b₀) (s-a₀' b₀) (s-f a₀ b) ⟩ s-f a₀ b ◃ apd d (smgluer b) =∎ where apd-section-helper : apd section (ap (λ a' → smin a' b) (snd f) ∙ ∧-norm-r b) == (s-f a₀ b ◃ transp-over (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (d (smin a₀ b))) ∙ᵈ section-smgluer' b ∙ᵈ !ᵈ (section-smgluer b₀) apd-section-helper = apd section (ap (λ a' → smin a' b) (snd f) ∙ ∧-norm-r b) =⟨ apd-∙ section (ap (λ a' → smin a' b) (snd f)) (∧-norm-r b) ⟩ apd section (ap (λ a' → smin a' b) (snd f)) ∙ᵈ apd section (∧-norm-r b) =⟨ ap2 _∙ᵈ_ (apd-∘''' section (λ a' → smin a' b) (snd f)) (apd-∙ section (smgluer b) (! (smgluer b₀))) ⟩ ↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f)) ∙ᵈ apd section (smgluer b) ∙ᵈ apd section (! (smgluer b₀)) =⟨ ap (↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f)) ∙ᵈ_) $ ap2 _∙ᵈ_ (Section.smgluer-β b) (apd-! section (smgluer b₀) ∙ ap !ᵈ (Section.smgluer-β b₀)) ⟩ ↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f)) ∙ᵈ section-smgluer b ∙ᵈ !ᵈ (section-smgluer b₀) =⟨ custom-assoc (fst ∘ P) (↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f))) (! (to-transp (↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f))))) (ap (transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f))) (s-f a₀ b)) (section-smgluer' b) (!ᵈ (section-smgluer b₀)) ⟩ ((↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f)) ▹ ! (to-transp (↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f))))) ▹ ap (transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f))) (s-f a₀ b)) ∙ᵈ section-smgluer' b ∙ᵈ !ᵈ (section-smgluer b₀) =⟨ ap (λ u → (u ▹ ap (transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f))) (s-f a₀ b)) ∙ᵈ section-smgluer' b ∙ᵈ !ᵈ (section-smgluer b₀)) $ to-transp-over (fst ∘ P) $ ↓-ap-in (fst ∘ P) (λ a' → smin a' b) (apd (λ a' → s a' b) (snd f)) ⟩ (transp-over (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (s (fst f a₀) b) ▹ ap (transport (fst ∘ P) (ap (λ a' → smin a' b) (snd f))) (s-f a₀ b)) ∙ᵈ section-smgluer' b ∙ᵈ !ᵈ (section-smgluer b₀) =⟨ ! $ ap (_∙ᵈ section-smgluer' b ∙ᵈ !ᵈ (section-smgluer b₀)) $ transp-over-naturality (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (s-f a₀ b) ⟩ (s-f a₀ b ◃ transp-over (fst ∘ P) (ap (λ a' → smin a' b) (snd f)) (d (smin a₀ b))) ∙ᵈ section-smgluer' b ∙ᵈ !ᵈ (section-smgluer b₀) =∎ is-section : section ∘ ∧-fmap f (⊙idf B) ∼ d is-section = Smash-PathOver-elim {P = λ ab → fst (P (∧-fmap f (⊙idf B) ab))} (section ∘ ∧-fmap f (⊙idf B)) d s-f is-section-smbasel is-section-smbaser is-section-smgluel is-section-smgluer {- Proposition 4.3.2 in Guillaume Brunerie's thesis -} ∧-fmap-conn-l : has-conn-fibers (n +2+ m) (∧-fmap f (⊙idf B)) ∧-fmap-conn-l = conn-in (λ P → ConnIn.section P , ConnIn.is-section P) private ∧-swap-conn : ∀ {i} {j} (X : Ptd i) (Y : Ptd j) (n : ℕ₋₂) → has-conn-fibers n (∧-swap X Y) ∧-swap-conn X Y n yx = Trunc-preserves-level {n = -2} n $ equiv-is-contr-map (∧-swap-is-equiv X Y) yx ∧-fmap-conn-r : ∀ {i} {j} {k} (A : Ptd i) {B : Ptd j} {B' : Ptd k} (g : B ⊙→ B') {k l : ℕ₋₂} → is-connected (S k) (de⊙ A) → has-conn-fibers l (fst g) → has-conn-fibers (k +2+ l) (∧-fmap (⊙idf A) g) ∧-fmap-conn-r A {B} {B'} g {k} {l} A-is-Sk-conn g-is-l-conn = transport (has-conn-fibers (k +2+ l)) (λ= (∧-swap-fmap (⊙idf A) g)) $ ∘-conn (∧-swap A B) (∧-swap B' A ∘ ∧-fmap g (⊙idf A)) (∧-swap-conn A B _) $ ∘-conn (∧-fmap g (⊙idf A)) (∧-swap B' A) (∧-fmap-conn-l g A g-is-l-conn A-is-Sk-conn) (∧-swap-conn B' A _) private ∘-conn' : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} {n m : ℕ₋₂} (g : B → C) (f : A → B) → has-conn-fibers m g → has-conn-fibers n f → has-conn-fibers (minT n m) (g ∘ f) ∘-conn' {n = n} {m = m} g f g-conn f-conn = ∘-conn f g (λ b → connected-≤T (minT≤l n m) {{f-conn b}}) (λ c → connected-≤T (minT≤r n m) {{g-conn c}}) {- Proposition 4.3.5 in Guillaume Brunerie's thesis -} ∧-fmap-conn : ∀ {i i' j j'} {A : Ptd i} {A' : Ptd i'} (f : A ⊙→ A') {B : Ptd j} {B' : Ptd j'} (g : B ⊙→ B') {m n k l : ℕ₋₂} → is-connected (S k) (de⊙ A') → is-connected (S n) (de⊙ B) → has-conn-fibers m (fst f) → has-conn-fibers l (fst g) → has-conn-fibers (minT (n +2+ m) (k +2+ l)) (∧-fmap f g) ∧-fmap-conn {A = A} {A'} f {B} {B'} g {m} {n} {k} {l} A'-is-Sk-conn B-is-Sn-conn f-is-m-conn g-is-l-conn = transport (has-conn-fibers (minT (n +2+ m) (k +2+ l))) p $ ∘-conn' (∧-fmap (⊙idf A') g) (∧-fmap f (⊙idf B)) (∧-fmap-conn-r A' g A'-is-Sk-conn g-is-l-conn) (∧-fmap-conn-l f B f-is-m-conn B-is-Sn-conn) where p : ∧-fmap (⊙idf A') g ∘ ∧-fmap f (⊙idf B) == ∧-fmap f g p = ∧-fmap (⊙idf A') g ∘ ∧-fmap f (⊙idf B) =⟨ ! (λ= (∧-fmap-comp f (⊙idf A') (⊙idf B) g)) ⟩ ∧-fmap (⊙idf A' ⊙∘ f) (g ⊙∘ ⊙idf B) =⟨ ap (λ h → ∧-fmap h g) (⊙λ= (⊙∘-unit-l f)) ⟩ ∧-fmap f g =∎
algebraic-stack_agda0000_doc_4839
{-# OPTIONS --allow-unsolved-metas #-} ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- CS410 2017/18 Exercise 1 VECTORS AND FRIENDS (worth 25%) ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- NOTE (19/9/17) This file is currently incomplete: more will arrive on -- GitHub. -- MARK SCHEME (transcribed from paper): the (m) numbers add up to slightly -- more than 25, so should be taken as the maximum number of marks losable on -- the exercise. In fact, I did mark it negatively, but mostly because it was -- done so well (with Agda's help) that it was easier to find the errors. ------------------------------------------------------------------------------ -- Dependencies ------------------------------------------------------------------------------ open import CS410-Prelude ------------------------------------------------------------------------------ -- Vectors ------------------------------------------------------------------------------ data Vec (X : Set) : Nat -> Set where -- like lists, but length-indexed [] : Vec X zero _,-_ : {n : Nat} -> X -> Vec X n -> Vec X (suc n) infixr 4 _,-_ -- the "cons" operator associates to the right -- I like to use the asymmetric ,- to remind myself that the element is to -- the left and the rest of the list is to the right. -- Vectors are useful when there are important length-related safety -- properties. ------------------------------------------------------------------------------ -- Heads and Tails ------------------------------------------------------------------------------ -- We can rule out nasty head and tail errors by insisting on nonemptiness! --??--1.1-(2)----------------------------------------------------------------- vHead : {X : Set}{n : Nat} -> Vec X (suc n) -> X vHead xs = {!!} vTail : {X : Set}{n : Nat} -> Vec X (suc n) -> Vec X n vTail xs = {!!} vHeadTailFact : {X : Set}{n : Nat}(xs : Vec X (suc n)) -> (vHead xs ,- vTail xs) == xs vHeadTailFact xs = {!!} --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Concatenation and its Inverse ------------------------------------------------------------------------------ --??--1.2-(2)----------------------------------------------------------------- _+V_ : {X : Set}{m n : Nat} -> Vec X m -> Vec X n -> Vec X (m +N n) xs +V ys = {!!} infixr 4 _+V_ vChop : {X : Set}(m : Nat){n : Nat} -> Vec X (m +N n) -> Vec X m * Vec X n vChop m xs = {!!} vChopAppendFact : {X : Set}{m n : Nat}(xs : Vec X m)(ys : Vec X n) -> vChop m (xs +V ys) == (xs , ys) vChopAppendFact xs ys = {!!} --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Map, take I ------------------------------------------------------------------------------ -- Implement the higher-order function that takes an operation on -- elements and does it to each element of a vector. Use recursion -- on the vector. -- Note that the type tells you the size remains the same. -- Show that if the elementwise function "does nothing", neither does -- its vMap. "map of identity is identity" -- Show that two vMaps in a row can be collapsed to just one, or -- "composition of maps is map of compositions" --??--1.3-(2)----------------------------------------------------------------- vMap : {X Y : Set} -> (X -> Y) -> {n : Nat} -> Vec X n -> Vec Y n vMap f xs = {!!} vMapIdFact : {X : Set}{f : X -> X}(feq : (x : X) -> f x == x) -> {n : Nat}(xs : Vec X n) -> vMap f xs == xs vMapIdFact feq xs = {!!} vMapCpFact : {X Y Z : Set}{f : Y -> Z}{g : X -> Y}{h : X -> Z} (heq : (x : X) -> f (g x) == h x) -> {n : Nat}(xs : Vec X n) -> vMap f (vMap g xs) == vMap h xs vMapCpFact heq xs = {!!} --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- vMap and +V ------------------------------------------------------------------------------ -- Show that if you've got two vectors of Xs and a function from X to Y, -- and you want to concatenate and map, it doesn't matter which you do -- first. --??--1.4-(1)----------------------------------------------------------------- vMap+VFact : {X Y : Set}(f : X -> Y) -> {m n : Nat}(xs : Vec X m)(xs' : Vec X n) -> vMap f (xs +V xs') == (vMap f xs +V vMap f xs') vMap+VFact f xs xs' = {!!} --??-------------------------------------------------------------------------- -- Think about what you could prove, relating vMap with vHead, vTail, vChop... -- Now google "Philip Wadler" "Theorems for Free" ------------------------------------------------------------------------------ -- Applicative Structure (giving mapping and zipping cheaply) ------------------------------------------------------------------------------ --??--1.5-(2)----------------------------------------------------------------- -- HINT: you will need to override the default invisibility of n to do this. vPure : {X : Set} -> X -> {n : Nat} -> Vec X n vPure x {n} = {!!} _$V_ : {X Y : Set}{n : Nat} -> Vec (X -> Y) n -> Vec X n -> Vec Y n fs $V xs = {!!} infixl 3 _$V_ -- "Application associates to the left, -- rather as we all did in the sixties." (Roger Hindley) -- Pattern matching and recursion are forbidden for the next two tasks. -- implement vMap again, but as a one-liner vec : {X Y : Set} -> (X -> Y) -> {n : Nat} -> Vec X n -> Vec Y n vec f xs = {!!} -- implement the operation which pairs up corresponding elements vZip : {X Y : Set}{n : Nat} -> Vec X n -> Vec Y n -> Vec (X * Y) n vZip xs ys = {!!} --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Applicative Laws ------------------------------------------------------------------------------ -- According to "Applicative programming with effects" by -- Conor McBride and Ross Paterson -- some laws should hold for applicative functors. -- Check that this is the case. --??--1.6-(2)----------------------------------------------------------------- vIdentity : {X : Set}{f : X -> X}(feq : (x : X) -> f x == x) -> {n : Nat}(xs : Vec X n) -> (vPure f $V xs) == xs vIdentity feq xs = {!!} vHomomorphism : {X Y : Set}(f : X -> Y)(x : X) -> {n : Nat} -> (vPure f $V vPure x) == vPure (f x) {n} vHomomorphism f x {n} = {!!} vInterchange : {X Y : Set}{n : Nat}(fs : Vec (X -> Y) n)(x : X) -> (fs $V vPure x) == (vPure (_$ x) $V fs) vInterchange fs x = {!!} vComposition : {X Y Z : Set}{n : Nat} (fs : Vec (Y -> Z) n)(gs : Vec (X -> Y) n)(xs : Vec X n) -> (vPure _<<_ $V fs $V gs $V xs) == (fs $V (gs $V xs)) vComposition fs gs xs = {!!} --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Order-Preserving Embeddings (also known in the business as "thinnings") ------------------------------------------------------------------------------ -- What have these to do with Pascal's Triangle? data _<=_ : Nat -> Nat -> Set where oz : zero <= zero os : {n m : Nat} -> n <= m -> suc n <= suc m o' : {n m : Nat} -> n <= m -> n <= suc m -- Find all the values in each of the following <= types. -- This is a good opportunity to learn to use C-c C-a with the -l option -- (a.k.a. "google the type" without "I feel lucky") -- The -s n option also helps. --??--1.7-(1)----------------------------------------------------------------- all0<=4 : Vec (0 <= 4) {!!} all0<=4 = {!!} all1<=4 : Vec (1 <= 4) {!!} all1<=4 = {!!} all2<=4 : Vec (2 <= 4) {!!} all2<=4 = {!!} all3<=4 : Vec (3 <= 4) {!!} all3<=4 = {!!} all4<=4 : Vec (4 <= 4) {!!} all4<=4 = {!!} -- Prove the following. A massive case analysis "rant" is fine. no5<=4 : 5 <= 4 -> Zero no5<=4 th = {!!} --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Order-Preserving Embeddings Select From Vectors ------------------------------------------------------------------------------ -- Use n <= m to encode the choice of n elements from an m-Vector. -- The os constructor tells you to take the next element of the vector; -- the o' constructor tells you to omit the next element of the vector. --??--1.8-(2)----------------------------------------------------------------- _<?=_ : {X : Set}{n m : Nat} -> n <= m -> Vec X m -> Vec X n th <?= xs = {!!} -- it shouldn't matter whether you map then select or select then map vMap<?=Fact : {X Y : Set}(f : X -> Y) {n m : Nat}(th : n <= m)(xs : Vec X m) -> vMap f (th <?= xs) == (th <?= vMap f xs) vMap<?=Fact f th xs = {!!} --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Our Favourite Thinnings ------------------------------------------------------------------------------ -- Construct the identity thinning and the empty thinning. --??--1.9-(1)----------------------------------------------------------------- oi : {n : Nat} -> n <= n oi {n} = {!!} oe : {n : Nat} -> 0 <= n oe {n} = {!!} --??-------------------------------------------------------------------------- -- Show that all empty thinnings are equal to yours. --??--1.10-(1)---------------------------------------------------------------- oeUnique : {n : Nat}(th : 0 <= n) -> th == oe oeUnique i = {!!} --??-------------------------------------------------------------------------- -- Show that there are no thinnings of form big <= small (TRICKY) -- Then show that all the identity thinnings are equal to yours. -- Note that you can try the second even if you haven't finished the first. -- HINT: you WILL need to expose the invisible numbers. -- HINT: check CS410-Prelude for a reminder of >= --??--1.11-(3)---------------------------------------------------------------- oTooBig : {n m : Nat} -> n >= m -> suc n <= m -> Zero oTooBig {n} {m} n>=m th = {!!} oiUnique : {n : Nat}(th : n <= n) -> th == oi oiUnique th = {!!} --??-------------------------------------------------------------------------- -- Show that the identity thinning selects the whole vector --??--1.12-(1)---------------------------------------------------------------- id-<?= : {X : Set}{n : Nat}(xs : Vec X n) -> (oi <?= xs) == xs id-<?= xs = {!!} --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Composition of Thinnings ------------------------------------------------------------------------------ -- Define the composition of thinnings and show that selecting by a -- composite thinning is like selecting then selecting again. -- A small bonus applies to minimizing the length of the proof. -- To collect the bonus, you will need to think carefully about -- how to make the composition as *lazy* as possible. --??--1.13-(3)---------------------------------------------------------------- _o>>_ : {p n m : Nat} -> p <= n -> n <= m -> p <= m th o>> th' = {!!} cp-<?= : {p n m : Nat}(th : p <= n)(th' : n <= m) -> {X : Set}(xs : Vec X m) -> ((th o>> th') <?= xs) == (th <?= (th' <?= xs)) cp-<?= th th' xs = {!!} --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Thinning Dominoes ------------------------------------------------------------------------------ --??--1.14-(3)---------------------------------------------------------------- idThen-o>> : {n m : Nat}(th : n <= m) -> (oi o>> th) == th idThen-o>> th = {!!} idAfter-o>> : {n m : Nat}(th : n <= m) -> (th o>> oi) == th idAfter-o>> th = {!!} assoc-o>> : {q p n m : Nat}(th0 : q <= p)(th1 : p <= n)(th2 : n <= m) -> ((th0 o>> th1) o>> th2) == (th0 o>> (th1 o>> th2)) assoc-o>> th0 th1 th2 = {!!} --??-------------------------------------------------------------------------- ------------------------------------------------------------------------------ -- Vectors as Arrays ------------------------------------------------------------------------------ -- We can use 1 <= n as the type of bounded indices into a vector and do -- a kind of "array projection". First we select a 1-element vector from -- the n-element vector, then we take its head to get the element out. vProject : {n : Nat}{X : Set} -> Vec X n -> 1 <= n -> X vProject xs i = vHead (i <?= xs) -- Your (TRICKY) mission is to reverse the process, tabulating a function -- from indices as a vector. Then show that these operations are inverses. --??--1.15-(3)---------------------------------------------------------------- -- HINT: composition of functions vTabulate : {n : Nat}{X : Set} -> (1 <= n -> X) -> Vec X n vTabulate {n} f = {!!} -- This should be easy if vTabulate is correct. vTabulateProjections : {n : Nat}{X : Set}(xs : Vec X n) -> vTabulate (vProject xs) == xs vTabulateProjections xs = {!!} -- HINT: oeUnique vProjectFromTable : {n : Nat}{X : Set}(f : 1 <= n -> X)(i : 1 <= n) -> vProject (vTabulate f) i == f i vProjectFromTable f i = {!!} --??--------------------------------------------------------------------------
algebraic-stack_agda0000_doc_4840
------------------------------------------------------------------------ -- The Agda standard library -- -- A categorical view of Vec ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.Vec.Categorical {a n} where open import Category.Applicative using (RawApplicative) open import Category.Applicative.Indexed using (Morphism) open import Category.Functor as Fun using (RawFunctor) import Function.Identity.Categorical as Id open import Category.Monad using (RawMonad) open import Data.Fin using (Fin) open import Data.Vec as Vec hiding (_⊛_) open import Data.Vec.Properties open import Function ------------------------------------------------------------------------ -- Functor and applicative functor : RawFunctor (λ (A : Set a) → Vec A n) functor = record { _<$>_ = map } applicative : RawApplicative (λ (A : Set a) → Vec A n) applicative = record { pure = replicate ; _⊛_ = Vec._⊛_ } ------------------------------------------------------------------------ -- Get access to other monadic functions module _ {f F} (App : RawApplicative {f} F) where open RawApplicative App sequenceA : ∀ {A n} → Vec (F A) n → F (Vec A n) sequenceA [] = pure [] sequenceA (x ∷ xs) = _∷_ <$> x ⊛ sequenceA xs mapA : ∀ {a} {A : Set a} {B n} → (A → F B) → Vec A n → F (Vec B n) mapA f = sequenceA ∘ map f forA : ∀ {a} {A : Set a} {B n} → Vec A n → (A → F B) → F (Vec B n) forA = flip mapA module _ {m M} (Mon : RawMonad {m} M) where private App = RawMonad.rawIApplicative Mon sequenceM : ∀ {A n} → Vec (M A) n → M (Vec A n) sequenceM = sequenceA App mapM : ∀ {a} {A : Set a} {B n} → (A → M B) → Vec A n → M (Vec B n) mapM = mapA App forM : ∀ {a} {A : Set a} {B n} → Vec A n → (A → M B) → M (Vec B n) forM = forA App ------------------------------------------------------------------------ -- Other -- lookup is a functor morphism from Vec to Identity. lookup-functor-morphism : (i : Fin n) → Fun.Morphism functor Id.functor lookup-functor-morphism i = record { op = flip lookup i ; op-<$> = lookup-map i } -- lookup is an applicative functor morphism. lookup-morphism : (i : Fin n) → Morphism applicative Id.applicative lookup-morphism i = record { op = flip lookup i ; op-pure = lookup-replicate i ; op-⊛ = lookup-⊛ i }
algebraic-stack_agda0000_doc_4841
-- A placeholder module so that we can write a main. Agda compilation -- does not work without a main so batch compilation is bound to give -- errors. For travis builds, we want batch compilation and this is -- module can be imported to serve that purpose. There is nothing -- useful that can be achieved from this module though. module io.placeholder where open import hott.core.universe postulate Unit : Type₀ IO : Type₀ → Type₀ dummyMain : IO Unit {-# COMPILED_TYPE Unit () #-} {-# COMPILED_TYPE IO IO #-} {-# COMPILED dummyMain (return ()) #-} {-# BUILTIN IO IO #-}
algebraic-stack_agda0000_doc_4842
open import Mockingbird.Forest using (Forest) import Mockingbird.Forest.Birds as Birds -- The Master Forest module Mockingbird.Problems.Chapter18 {b ℓ} (forest : Forest {b} {ℓ}) ⦃ _ : Birds.HasStarling forest ⦄ ⦃ _ : Birds.HasKestrel forest ⦄ where open import Data.Maybe using (Maybe; nothing; just) open import Data.Product using (_×_; _,_; proj₁; ∃-syntax) open import Data.Vec using (Vec; []; _∷_; _++_) open import Data.Vec.Relation.Unary.Any.Properties using (++⁺ʳ) open import Function using (_$_) open import Level using (_⊔_) open import Mockingbird.Forest.Combination.Vec forest using (⟨_⟩; here; there; [_]; _⟨∙⟩_∣_; _⟨∙⟩_; [#_]) open import Mockingbird.Forest.Combination.Vec.Properties forest using (subst′; weaken-++ˡ; weaken-++ʳ; ++-comm) open import Relation.Unary using (_∈_) open Forest forest open import Mockingbird.Forest.Birds forest problem₁ : HasIdentity problem₁ = record { I = S ∙ K ∙ K ; isIdentity = λ x → begin S ∙ K ∙ K ∙ x ≈⟨ isStarling K K x ⟩ K ∙ x ∙ (K ∙ x) ≈⟨ isKestrel x (K ∙ x) ⟩ x ∎ } private instance hasIdentity = problem₁ problem₂ : HasMockingbird problem₂ = record { M = S ∙ I ∙ I ; isMockingbird = λ x → begin S ∙ I ∙ I ∙ x ≈⟨ isStarling I I x ⟩ I ∙ x ∙ (I ∙ x) ≈⟨ congʳ $ isIdentity x ⟩ x ∙ (I ∙ x) ≈⟨ congˡ $ isIdentity x ⟩ x ∙ x ∎ } private instance hasMockingbird = problem₂ problem₃ : HasThrush problem₃ = record { T = S ∙ (K ∙ (S ∙ I)) ∙ K ; isThrush = λ x y → begin S ∙ (K ∙ (S ∙ I)) ∙ K ∙ x ∙ y ≈⟨ congʳ $ isStarling (K ∙ (S ∙ I)) K x ⟩ K ∙ (S ∙ I) ∙ x ∙ (K ∙ x) ∙ y ≈⟨ (congʳ $ congʳ $ isKestrel (S ∙ I) x) ⟩ S ∙ I ∙ (K ∙ x) ∙ y ≈⟨ isStarling I (K ∙ x) y ⟩ I ∙ y ∙ (K ∙ x ∙ y) ≈⟨ congʳ $ isIdentity y ⟩ y ∙ (K ∙ x ∙ y) ≈⟨ congˡ $ isKestrel x y ⟩ y ∙ x ∎ } -- TODO: Problem 4. I∈⟨S,K⟩ : I ∈ ⟨ S ∷ K ∷ [] ⟩ I∈⟨S,K⟩ = subst′ refl $ [# 0 ] ⟨∙⟩ [# 1 ] ⟨∙⟩ [# 1 ] -- Try to strengthen a proof of X ∈ ⟨ y ∷ xs ⟩ to X ∈ ⟨ xs ⟩, which can be done -- if y does not occur in X. strengthen : ∀ {n X y} {xs : Vec Bird n} → X ∈ ⟨ y ∷ xs ⟩ → Maybe (X ∈ ⟨ xs ⟩) -- NOTE: it could be the case that y ∈ xs, but checking that requires decidable -- equality. strengthen [ here X≈y ] = nothing strengthen [ there X∈xs ] = just [ X∈xs ] strengthen (Y∈⟨y,xs⟩ ⟨∙⟩ Z∈⟨y,xs⟩ ∣ YZ≈X) = do Y∈⟨xs⟩ ← strengthen Y∈⟨y,xs⟩ Z∈⟨xs⟩ ← strengthen Z∈⟨y,xs⟩ just $ Y∈⟨xs⟩ ⟨∙⟩ Z∈⟨xs⟩ ∣ YZ≈X where open import Data.Maybe.Categorical using (monad) open import Category.Monad using (RawMonad) open RawMonad (monad {b ⊔ ℓ}) eliminate : ∀ {n X y} {xs : Vec Bird n} → X ∈ ⟨ y ∷ xs ⟩ → ∃[ X′ ] (X′ ∈ ⟨ S ∷ K ∷ xs ⟩ × X′ ∙ y ≈ X) eliminate {X = X} {y} [ here X≈y ] = (I , weaken-++ˡ I∈⟨S,K⟩ , trans (isIdentity y) (sym X≈y)) eliminate {X = X} {y} [ there X∈xs ] = (K ∙ X , [# 1 ] ⟨∙⟩ [ ++⁺ʳ (S ∷ K ∷ []) X∈xs ] , isKestrel X y) eliminate {X = X} {y} (_⟨∙⟩_∣_ {Y} {Z} Y∈⟨y,xs⟩ [ here Z≈y ] YZ≈X) with strengthen Y∈⟨y,xs⟩ ... | just Y∈⟨xs⟩ = (Y , weaken-++ʳ (S ∷ K ∷ []) Y∈⟨xs⟩ , trans (congˡ (sym Z≈y)) YZ≈X) ... | nothing = let (Y′ , Y′∈⟨S,K,xs⟩ , Y′y≈Y) = eliminate Y∈⟨y,xs⟩ SY′Iy≈X : S ∙ Y′ ∙ I ∙ y ≈ X SY′Iy≈X = begin S ∙ Y′ ∙ I ∙ y ≈⟨ isStarling Y′ I y ⟩ Y′ ∙ y ∙ (I ∙ y) ≈⟨ congʳ $ Y′y≈Y ⟩ Y ∙ (I ∙ y) ≈⟨ congˡ $ isIdentity y ⟩ Y ∙ y ≈˘⟨ congˡ Z≈y ⟩ Y ∙ Z ≈⟨ YZ≈X ⟩ X ∎ in (S ∙ Y′ ∙ I , [# 0 ] ⟨∙⟩ Y′∈⟨S,K,xs⟩ ⟨∙⟩ weaken-++ˡ I∈⟨S,K⟩ , SY′Iy≈X) eliminate {X = X} {y} (_⟨∙⟩_∣_ {Y} {Z} Y∈⟨y,xs⟩ Z∈⟨y,xs⟩ YZ≈X) = let (Y′ , Y′∈⟨S,K,xs⟩ , Y′y≈Y) = eliminate Y∈⟨y,xs⟩ (Z′ , Z′∈⟨S,K,xs⟩ , Z′y≈Z) = eliminate Z∈⟨y,xs⟩ SY′Z′y≈X : S ∙ Y′ ∙ Z′ ∙ y ≈ X SY′Z′y≈X = begin S ∙ Y′ ∙ Z′ ∙ y ≈⟨ isStarling Y′ Z′ y ⟩ Y′ ∙ y ∙ (Z′ ∙ y) ≈⟨ congʳ Y′y≈Y ⟩ Y ∙ (Z′ ∙ y) ≈⟨ congˡ Z′y≈Z ⟩ Y ∙ Z ≈⟨ YZ≈X ⟩ X ∎ in (S ∙ Y′ ∙ Z′ , [# 0 ] ⟨∙⟩ Y′∈⟨S,K,xs⟩ ⟨∙⟩ Z′∈⟨S,K,xs⟩ , SY′Z′y≈X) module _ (x y : Bird) where -- Example: y-eliminating the expression y should give I. _ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 0 ]) ≈ I _ = refl -- Example: y-eliminating the expression x should give Kx. _ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 1 ]) ≈ K ∙ x _ = refl -- Example: y-eliminating the expression xy should give x (Principle 3). _ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 1 ] ⟨∙⟩ [# 0 ]) ≈ x _ = refl -- Example: y-eliminating the expression yx should give SI(Kx). _ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 0 ] ⟨∙⟩ [# 1 ]) ≈ S ∙ I ∙ (K ∙ x) _ = refl -- Example: y-eliminating the expression yy should give SII. _ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 0 ] ⟨∙⟩ [# 0 ]) ≈ S ∙ I ∙ I _ = refl strengthen-SK : ∀ {n X y} {xs : Vec Bird n} → X ∈ ⟨ S ∷ K ∷ y ∷ xs ⟩ → Maybe (X ∈ ⟨ S ∷ K ∷ xs ⟩) strengthen-SK {y = y} {xs} X∈⟨S,K,y,xs⟩ = do let X∈⟨y,xs,S,K⟩ = ++-comm (S ∷ K ∷ []) (y ∷ xs) X∈⟨S,K,y,xs⟩ X∈⟨xs,S,K⟩ ← strengthen X∈⟨y,xs,S,K⟩ let X∈⟨S,K,xs⟩ = ++-comm xs (S ∷ K ∷ []) X∈⟨xs,S,K⟩ just X∈⟨S,K,xs⟩ where open import Data.Maybe.Categorical using (monad) open import Category.Monad using (RawMonad) open RawMonad (monad {b ⊔ ℓ}) -- TODO: formulate eliminate or eliminate-SK in terms of the other. eliminate-SK : ∀ {n X y} {xs : Vec Bird n} → X ∈ ⟨ S ∷ K ∷ y ∷ xs ⟩ → ∃[ X′ ] (X′ ∈ ⟨ S ∷ K ∷ xs ⟩ × X′ ∙ y ≈ X) eliminate-SK {X = X} {y} [ here X≈S ] = (K ∙ S , [# 1 ] ⟨∙⟩ [# 0 ] , trans (isKestrel S y) (sym X≈S)) eliminate-SK {X = X} {y} [ there (here X≈K) ] = (K ∙ K , [# 1 ] ⟨∙⟩ [# 1 ] , trans (isKestrel K y) (sym X≈K)) eliminate-SK {X = X} {y} [ there (there (here X≈y)) ] = (I , weaken-++ˡ I∈⟨S,K⟩ , trans (isIdentity y) (sym X≈y)) eliminate-SK {X = X} {y} [ there (there (there X∈xs)) ] = (K ∙ X , ([# 1 ] ⟨∙⟩ [ (++⁺ʳ (S ∷ K ∷ []) X∈xs) ]) , isKestrel X y) eliminate-SK {X = X} {y} (_⟨∙⟩_∣_ {Y} {Z} Y∈⟨S,K,y,xs⟩ [ there (there (here Z≈y)) ] YZ≈X) with strengthen-SK Y∈⟨S,K,y,xs⟩ ... | just Y∈⟨S,K,xs⟩ = (Y , Y∈⟨S,K,xs⟩ , trans (congˡ (sym Z≈y)) YZ≈X) ... | nothing = let (Y′ , Y′∈⟨S,K,xs⟩ , Y′y≈Y) = eliminate-SK Y∈⟨S,K,y,xs⟩ SY′Iy≈X : S ∙ Y′ ∙ I ∙ y ≈ X SY′Iy≈X = begin S ∙ Y′ ∙ I ∙ y ≈⟨ isStarling Y′ I y ⟩ Y′ ∙ y ∙ (I ∙ y) ≈⟨ congʳ $ Y′y≈Y ⟩ Y ∙ (I ∙ y) ≈⟨ congˡ $ isIdentity y ⟩ Y ∙ y ≈˘⟨ congˡ Z≈y ⟩ Y ∙ Z ≈⟨ YZ≈X ⟩ X ∎ in (S ∙ Y′ ∙ I , [# 0 ] ⟨∙⟩ Y′∈⟨S,K,xs⟩ ⟨∙⟩ weaken-++ˡ I∈⟨S,K⟩ , SY′Iy≈X) eliminate-SK {X = X} {y} (_⟨∙⟩_∣_ {Y} {Z} Y∈⟨S,K,y,xs⟩ Z∈⟨S,K,y,xs⟩ YZ≈X) = let (Y′ , Y′∈⟨S,K,xs⟩ , Y′y≈Y) = eliminate-SK Y∈⟨S,K,y,xs⟩ (Z′ , Z′∈⟨S,K,xs⟩ , Z′y≈Z) = eliminate-SK Z∈⟨S,K,y,xs⟩ SY′Z′y≈X : S ∙ Y′ ∙ Z′ ∙ y ≈ X SY′Z′y≈X = begin S ∙ Y′ ∙ Z′ ∙ y ≈⟨ isStarling Y′ Z′ y ⟩ Y′ ∙ y ∙ (Z′ ∙ y) ≈⟨ congʳ Y′y≈Y ⟩ Y ∙ (Z′ ∙ y) ≈⟨ congˡ Z′y≈Z ⟩ Y ∙ Z ≈⟨ YZ≈X ⟩ X ∎ in (S ∙ Y′ ∙ Z′ , [# 0 ] ⟨∙⟩ Y′∈⟨S,K,xs⟩ ⟨∙⟩ Z′∈⟨S,K,xs⟩ , SY′Z′y≈X) module _ (x y : Bird) where -- Example: y-eliminating the expression y should give I. _ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 2 ]) ≈ I _ = refl -- Example: y-eliminating the expression x should give Kx. _ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 3 ]) ≈ K ∙ x _ = refl -- Example: y-eliminating the expression xy should give x (Principle 3). _ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 3 ] ⟨∙⟩ [# 2 ]) ≈ x _ = refl -- Example: y-eliminating the expression yx should give SI(Kx). _ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 2 ] ⟨∙⟩ [# 3 ]) ≈ S ∙ I ∙ (K ∙ x) _ = refl -- Example: y-eliminating the expression yy should give SII. _ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 2 ] ⟨∙⟩ [# 2 ]) ≈ S ∙ I ∙ I _ = refl infixl 6 _∙ⁿ_ _∙ⁿ_ : ∀ {n} → (A : Bird) (xs : Vec Bird n) → Bird A ∙ⁿ [] = A A ∙ⁿ (x ∷ xs) = A ∙ⁿ xs ∙ x eliminateAll′ : ∀ {n X} {xs : Vec Bird n} → X ∈ ⟨ S ∷ K ∷ xs ⟩ → ∃[ X′ ] (X′ ∈ ⟨ S ∷ K ∷ [] ⟩ × X′ ∙ⁿ xs ≈ X) eliminateAll′ {X = X} {[]} X∈⟨S,K⟩ = (X , X∈⟨S,K⟩ , refl) eliminateAll′ {X = X} {x ∷ xs} X∈⟨S,K,x,xs⟩ = let (X′ , X′∈⟨S,K,xs⟩ , X′x≈X) = eliminate-SK X∈⟨S,K,x,xs⟩ (X″ , X″∈⟨S,K⟩ , X″xs≈X′) = eliminateAll′ X′∈⟨S,K,xs⟩ X″∙ⁿxs∙x≈X : X″ ∙ⁿ xs ∙ x ≈ X X″∙ⁿxs∙x≈X = begin X″ ∙ⁿ xs ∙ x ≈⟨ congʳ X″xs≈X′ ⟩ X′ ∙ x ≈⟨ X′x≈X ⟩ X ∎ in (X″ , X″∈⟨S,K⟩ , X″∙ⁿxs∙x≈X) -- TOOD: can we do this in some way without depending on xs : Vec Bird n? eliminateAll : ∀ {n X} {xs : Vec Bird n} → X ∈ ⟨ xs ⟩ → ∃[ X′ ] (X′ ∈ ⟨ S ∷ K ∷ [] ⟩ × X′ ∙ⁿ xs ≈ X) eliminateAll X∈⟨xs⟩ = eliminateAll′ $ weaken-++ʳ (S ∷ K ∷ []) X∈⟨xs⟩
algebraic-stack_agda0000_doc_4843
-- Andreas, 2017-01-12, re #2386 -- Correct error message for wrong BUILTIN UNIT data Bool : Set where true false : Bool {-# BUILTIN UNIT Bool #-} -- Error WAS: -- The builtin UNIT must be a datatype with 1 constructors -- when checking the pragma BUILTIN UNIT Bool -- Expected error: -- Builtin UNIT must be a singleton record type -- when checking the pragma BUILTIN UNIT Bool
algebraic-stack_agda0000_doc_4844
open import FRP.JS.Bool using ( not ) open import FRP.JS.Nat using ( ) renaming ( _≟_ to _≟n_ ) open import FRP.JS.String using ( _≟_ ; _≤_ ; _<_ ; length ) open import FRP.JS.QUnit using ( TestSuite ; ok ; test ; _,_ ) module FRP.JS.Test.String where tests : TestSuite tests = ( test "≟" ( ok "abc ≟ abc" ("abc" ≟ "abc") , ok "ε ≟ abc" (not ("" ≟ "abc")) , ok "a ≟ abc" (not ("a" ≟ "abc")) , ok "abc ≟ ABC" (not ("abc" ≟ "ABC")) ) , test "length" ( ok "length ε" (length "" ≟n 0) , ok "length a" (length "a" ≟n 1) , ok "length ab" (length "ab" ≟n 2) , ok "length abc" (length "abc" ≟n 3) , ok "length \"\\\"" (length "\"\\\"" ≟n 3) , ok "length åäö⊢ξ∀" (length "åäö⊢ξ∀" ≟n 6) , ok "length ⟨line-terminators⟩" (length "\r\n\x2028\x2029" ≟n 4) ) , test "≤" ( ok "abc ≤ abc" ("abc" ≤ "abc") , ok "abc ≤ ε" (not ("abc" ≤ "")) , ok "abc ≤ a" (not ("abc" ≤ "a")) , ok "abc ≤ ab" (not ("abc" ≤ "a")) , ok "abc ≤ ABC" (not ("abc" ≤ "ABC")) , ok "ε ≤ abc" ("" ≤ "abc") , ok "a ≤ abc" ("a" ≤ "abc") , ok "ab ≤ abc" ("a" ≤ "abc") , ok "ABC ≤ abc" ("ABC" ≤ "abc") ) , test "<" ( ok "abc < abc" (not ("abc" < "abc")) , ok "abc < ε" (not ("abc" < "")) , ok "abc < a" (not ("abc" < "a")) , ok "abc < ab" (not ("abc" < "a")) , ok "abc < ABC" (not ("abc" < "ABC")) , ok "ε < abc" ("" < "abc") , ok "a < abc" ("a" < "abc") , ok "ab < abc" ("a" < "abc") , ok "ABC < abc" ("ABC" < "abc") ) )
algebraic-stack_agda0000_doc_4845
-- Andreas, 2017-11-06, issue #2840 reported by wenkokke Id : (F : Set → Set) → Set → Set Id F = F data D (A : Set) : Set where c : Id _ A -- WAS: internal error in positivity checker -- EXPECTED: success, or -- The target of a constructor must be the datatype applied to its -- parameters, _F_2 A isn't -- when checking the constructor c in the declaration of D
algebraic-stack_agda0000_doc_4846
------------------------------------------------------------------------ -- This module proves that the context-sensitive language aⁿbⁿcⁿ can -- be recognised ------------------------------------------------------------------------ -- This is obvious given the proof in -- TotalRecognisers.LeftRecursion.ExpressiveStrength but the code -- below provides a non-trivial example of the use of the parser -- combinators. module TotalRecognisers.LeftRecursion.NotOnlyContextFree where open import Algebra open import Codata.Musical.Notation open import Data.Bool using (Bool; true; false; _∨_) open import Function open import Data.List as List using (List; []; _∷_; _++_; [_]) import Data.List.Properties private module ListMonoid {A : Set} = Monoid (Data.List.Properties.++-monoid A) open import Data.Nat as Nat using (ℕ; zero; suc; _+_) import Data.Nat.Properties as NatProp private module NatCS = CommutativeSemiring NatProp.+-*-commutativeSemiring import Data.Nat.Solver open Data.Nat.Solver.+-*-Solver open import Data.Product open import Relation.Binary open import Relation.Binary.PropositionalEquality open import Relation.Nullary open ≡-Reasoning import TotalRecognisers.LeftRecursion import TotalRecognisers.LeftRecursion.Lib as Lib ------------------------------------------------------------------------ -- The alphabet data Tok : Set where a b c : Tok _≟_ : Decidable (_≡_ {A = Tok}) a ≟ a = yes refl a ≟ b = no λ() a ≟ c = no λ() b ≟ a = no λ() b ≟ b = yes refl b ≟ c = no λ() c ≟ a = no λ() c ≟ b = no λ() c ≟ c = yes refl open TotalRecognisers.LeftRecursion Tok open Lib Tok private open module TokTok = Lib.Tok Tok _≟_ using (tok) ------------------------------------------------------------------------ -- An auxiliary definition and a boring lemma infixr 8 _^^_ _^^_ : Tok → ℕ → List Tok _^^_ = flip List.replicate private shallow-comm : ∀ i n → i + suc n ≡ suc (i + n) shallow-comm i n = solve 2 (λ i n → i :+ (con 1 :+ n) := con 1 :+ i :+ n) refl i n ------------------------------------------------------------------------ -- Some lemmas relating _^^_, _^_ and tok tok-^-complete : ∀ t i → t ^^ i ∈ tok t ^ i tok-^-complete t zero = empty tok-^-complete t (suc i) = add-♭♯ ⟨ false ^ i ⟩-nullable TokTok.complete · tok-^-complete t i tok-^-sound : ∀ t i {s} → s ∈ tok t ^ i → s ≡ t ^^ i tok-^-sound t zero empty = refl tok-^-sound t (suc i) (t∈ · s∈) with TokTok.sound (drop-♭♯ ⟨ false ^ i ⟩-nullable t∈) ... | refl = cong (_∷_ t) (tok-^-sound t i s∈) ------------------------------------------------------------------------ -- aⁿbⁿcⁿ -- The context-sensitive language { aⁿbⁿcⁿ | n ∈ ℕ } can be recognised -- using the parser combinators defined in this development. private -- The two functions below are not actually mutually recursive, but -- are placed in a mutual block to ensure that the constraints -- generated by the second function can be used to instantiate the -- underscore in the body of the first. mutual aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-index : ℕ → Bool aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-index _ = _ aⁿbⁱ⁺ⁿcⁱ⁺ⁿ : (i : ℕ) → P (aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-index i) aⁿbⁱ⁺ⁿcⁱ⁺ⁿ i = cast lem (♯? (tok a) · ♯ aⁿbⁱ⁺ⁿcⁱ⁺ⁿ (suc i)) ∣ tok b ^ i ⊙ tok c ^ i where lem = left-zero (aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-index (suc i)) aⁿbⁿcⁿ : P true aⁿbⁿcⁿ = aⁿbⁱ⁺ⁿcⁱ⁺ⁿ 0 -- Let us prove that aⁿbⁿcⁿ is correctly defined. aⁿbⁿcⁿ-string : ℕ → List Tok aⁿbⁿcⁿ-string n = a ^^ n ++ b ^^ n ++ c ^^ n private aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-string : ℕ → ℕ → List Tok aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-string n i = a ^^ n ++ b ^^ (i + n) ++ c ^^ (i + n) aⁿbⁿcⁿ-complete : ∀ n → aⁿbⁿcⁿ-string n ∈ aⁿbⁿcⁿ aⁿbⁿcⁿ-complete n = aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-complete n 0 where aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-complete : ∀ n i → aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-string n i ∈ aⁿbⁱ⁺ⁿcⁱ⁺ⁿ i aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-complete zero i with i + 0 | proj₂ NatCS.+-identity i ... | .i | refl = ∣-right {n₁ = false} (helper b · helper c) where helper = λ (t : Tok) → add-♭♯ ⟨ false ^ i ⟩-nullable (tok-^-complete t i) aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-complete (suc n) i with i + suc n | shallow-comm i n ... | .(suc i + n) | refl = ∣-left $ cast {eq = lem} ( add-♭♯ (aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-index (suc i)) TokTok.complete · aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-complete n (suc i)) where lem = left-zero (aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-index (suc i)) aⁿbⁿcⁿ-sound : ∀ {s} → s ∈ aⁿbⁿcⁿ → ∃ λ n → s ≡ aⁿbⁿcⁿ-string n aⁿbⁿcⁿ-sound = aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-sound 0 where aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-sound : ∀ {s} i → s ∈ aⁿbⁱ⁺ⁿcⁱ⁺ⁿ i → ∃ λ n → s ≡ aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-string n i aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-sound i (∣-left (cast (t∈ · s∈))) with TokTok.sound (drop-♭♯ (aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-index (suc i)) t∈) ... | refl with aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-sound (suc i) s∈ ... | (n , refl) = suc n , (begin a ^^ suc n ++ b ^^ (suc i + n) ++ c ^^ (suc i + n) ≡⟨ cong (λ i → a ^^ suc n ++ b ^^ i ++ c ^^ i) (sym (shallow-comm i n)) ⟩ a ^^ suc n ++ b ^^ (i + suc n) ++ c ^^ (i + suc n) ∎) aⁿbⁱ⁺ⁿcⁱ⁺ⁿ-sound i (∣-right (_·_ {s₁} {s₂} s₁∈ s₂∈)) = 0 , (begin s₁ ++ s₂ ≡⟨ cong₂ _++_ (tok-^-sound b i (drop-♭♯ ⟨ false ^ i ⟩-nullable s₁∈)) (tok-^-sound c i (drop-♭♯ ⟨ false ^ i ⟩-nullable s₂∈)) ⟩ b ^^ i ++ c ^^ i ≡⟨ cong (λ i → b ^^ i ++ c ^^ i) (sym (proj₂ NatCS.+-identity i)) ⟩ b ^^ (i + 0) ++ c ^^ (i + 0) ∎)
algebraic-stack_agda0000_doc_4847
postulate Nat : Set Fin : Nat → Set Finnat : Nat → Set fortytwo : Nat finnatic : Finnat fortytwo _==_ : Finnat fortytwo → Finnat fortytwo → Set record Fixer : Set where field fix : ∀ {x} → Finnat x → Finnat fortytwo open Fixer {{...}} postulate Fixidentity : {{_ : Fixer}} → Set instance fixidentity : {{fx : Fixer}} {{fxi : Fixidentity}} {f : Finnat fortytwo} → fix f == f InstanceWrapper : Set iwrap : InstanceWrapper instance IrrFixerInstance : .InstanceWrapper → Fixer instance FixerInstance : Fixer FixerInstance = IrrFixerInstance iwrap instance postulate FixidentityInstance : Fixidentity it : ∀ {a} {A : Set a} {{x : A}} → A it {{x}} = x fails : Fixer.fix FixerInstance finnatic == finnatic fails = fixidentity works : Fixer.fix FixerInstance finnatic == finnatic works = fixidentity {{fx = it}} works₂ : Fixer.fix FixerInstance finnatic == finnatic works₂ = fixidentity {{fxi = it}}
algebraic-stack_agda0000_doc_13248
module Categories.Setoids where open import Library open import Categories record Setoid {a b} : Set (lsuc (a ⊔ b)) where field set : Set a eq : set → set → Set b ref : {s : set} → eq s s sym' : {s s' : set} → eq s s' → eq s' s trn : {s s' s'' : set} → eq s s' → eq s' s'' → eq s s'' open Setoid record SetoidFun (S S' : Setoid) : Set where constructor setoidfun field fun : set S → set S' feq : {s s' : set S} → eq S s s' → eq S' (fun s) (fun s') open SetoidFun SetoidFunEq : {S S' : Setoid}{f g : SetoidFun S S'} → fun f ≅ fun g → (λ{s}{s'}(p : eq S s s') → feq f p) ≅ (λ{s}{s'}(p : eq S s s') → feq g p) → f ≅ g SetoidFunEq {f = setoidfun fun feq} {setoidfun .fun .feq} refl refl = refl idFun : {S : Setoid} → SetoidFun S S idFun = record {fun = id; feq = id} compFun : {S S' S'' : Setoid} → SetoidFun S' S'' → SetoidFun S S' → SetoidFun S S'' compFun f g = record {fun = fun f ∘ fun g; feq = feq f ∘ feq g} idl : {X Y : Setoid} {f : SetoidFun X Y} → compFun idFun f ≅ f idl {f = setoidfun _ _} = refl idr : {X Y : Setoid} {f : SetoidFun X Y} → compFun f idFun ≅ f idr {f = setoidfun _ _} = refl Setoids : Cat Setoids = record{ Obj = Setoid; Hom = SetoidFun; iden = idFun; comp = compFun; idl = idl; idr = idr; ass = refl} -- -}
algebraic-stack_agda0000_doc_13249
------------------------------------------------------------------------ -- Divisibility and coprimality ------------------------------------------------------------------------ module Data.Integer.Divisibility where open import Data.Function open import Data.Integer open import Data.Integer.Properties import Data.Nat.Divisibility as ℕ import Data.Nat.Coprimality as ℕ open import Relation.Binary open import Relation.Binary.PropositionalEquality -- Divisibility. infix 4 _∣_ _∣_ : Rel ℤ _∣_ = ℕ._∣_ on₁ ∣_∣ -- Coprimality. Coprime : Rel ℤ Coprime = ℕ.Coprime on₁ ∣_∣ -- If i divides jk and is coprime to j, then it divides k. coprime-divisor : ∀ i j k → Coprime i j → i ∣ j * k → i ∣ k coprime-divisor i j k c eq = ℕ.coprime-divisor c (subst (ℕ._∣_ ∣ i ∣) (abs-*-commute j k) eq)
algebraic-stack_agda0000_doc_13250
module Issue18 where postulate D : Set data ∃ (A : D → Set) : Set where _,_ : (witness : D) → A witness → ∃ A
algebraic-stack_agda0000_doc_13251
{-# OPTIONS --cubical #-} module Cubical.README where ------------------------------------------------------------------------ -- An experimental library for Cubical Agda ----------------------------------------------------------------------- -- The library comes with a .agda-lib file, for use with the library -- management system. ------------------------------------------------------------------------ -- Module hierarchy ------------------------------------------------------------------------ -- The core library for Cubical Agda. -- It contains basic primitives, equivalences, glue types. import Cubical.Core.Everything -- The foundations for Cubical Agda. -- The Prelude module is self-explanatory. import Cubical.Foundations.Prelude import Cubical.Foundations.Everything -- Data types and properties import Cubical.Data.Everything -- Properties and proofs about relations import Cubical.Relation.Everything -- Higher-inductive types import Cubical.HITs.Everything -- Coinductive data types and properties import Cubical.Codata.Everything -- Various experiments using Cubical Agda import Cubical.Experiments.Everything
algebraic-stack_agda0000_doc_13252
module Lang.Function where import Lvl open import Data.Boolean open import Data.List as List using (List) open import Data.List.Functions.Positional as List open import Data.Option open import Data open import Lang.Reflection open import Syntax.Do open import Type -- A default value tactic for implicit arguments. -- This implements a "default arguments" language feature. -- It works by always unifying the hole with the specified value. -- Essentially a constant function for holes. -- Example: -- test : ∀{@(tactic default 𝑇) x : Bool} → Bool -- test{x} = x -- Now, `test = 𝑇`, `test{𝑇} = 𝑇`, `test{𝐹} = 𝐹`. default : ∀{ℓ}{T : Type{ℓ}} → T → Term → TC(Unit{Lvl.𝟎}) default x hole = quoteTC x >>= unify hole -- A no inferrance tactic for implicit arguments. -- This makes implicit arguments work like explicit arguments by throwing an error when the hole does not match perfectly while still maintaining its implicit visibility status. -- It works by always selecting the last argument in the hole, and the last argument is the one closest to the value, which is the argument one expects it to choose. -- Examples: -- idᵢwith : ∀{T : TYPE} → {@(tactic no-infer) x : T} → T -- idᵢwith {x = x} = x -- -- idᵢwithout : ∀{T : TYPE} → {x : T} → T -- idᵢwithout {x = x} = x -- -- postulate test : ({_ : Bool} → Bool) → Bool -- -- test1 : Bool -- test1 = test idᵢwith -- -- test2 : (Bool → Bool) → Bool -- test2 _ = test idᵢwith -- -- test3 : ∀{T : TYPE} → {_ : T} → T -- test3 = idᵢwith -- -- It is useful in these kinds of scenarios because idᵢwithout would require writing the implicit argument explicitly, while idᵢwith always uses the given argument in order like how explicit arguments work. no-infer : Term → TC(Unit{Lvl.𝟎}) no-infer hole@(meta _ args) with List.last(args) ... | None = typeError (List.singleton (strErr "Expected a parameter with \"hidden\" visibility when using \"no-infer\", found none.")) ... | Some (arg (arg-info hidden _) term) = unify hole term {-# CATCHALL #-} ... | Some (arg (arg-info _ _) term) = typeError (List.singleton (strErr "Wrong visibility of argument. Expected \"hidden\" when using \"no-infer\".")) {-# CATCHALL #-} no-infer _ = typeError (List.singleton (strErr "TODO: In what situations is this error occurring?")) -- TODO: Implement idᵢwith, rename it to idᵢ, and put it in Functional. Also, try to refactor Data.Boolean, Data.List and Data.Option so that they only contain the type definition and its constructors. This minimizes the amount of dependencies this module requires (which should help in case of circular dependencies when importing this module).
algebraic-stack_agda0000_doc_13253
postulate T C D : Set instance I : {{_ : C}} → D d : {{_ : D}} → T t : T t = d
algebraic-stack_agda0000_doc_13254
{-# OPTIONS --without-K --safe #-} module Categories.Diagram.Cone.Properties where open import Level open import Categories.Category open import Categories.Functor open import Categories.Functor.Properties open import Categories.NaturalTransformation import Categories.Diagram.Cone as Con import Categories.Morphism.Reasoning as MR private variable o ℓ e : Level C D J J′ : Category o ℓ e module _ {F : Functor J C} (G : Functor C D) where private module C = Category C module D = Category D module F = Functor F module G = Functor G module CF = Con F GF = G ∘F F module CGF = Con GF F-map-Coneˡ : CF.Cone → CGF.Cone F-map-Coneˡ K = record { apex = record { ψ = λ X → G.F₁ (ψ X) ; commute = λ f → [ G ]-resp-∘ (commute f) } } where open CF.Cone K F-map-Cone⇒ˡ : ∀ {K K′} (f : CF.Cone⇒ K K′) → CGF.Cone⇒ (F-map-Coneˡ K) (F-map-Coneˡ K′) F-map-Cone⇒ˡ f = record { arr = G.F₁ arr ; commute = [ G ]-resp-∘ commute } where open CF.Cone⇒ f module _ {F : Functor J C} (G : Functor J′ J) where private module C = Category C module J′ = Category J′ module F = Functor F module G = Functor G module CF = Con F FG = F ∘F G module CFG = Con FG F-map-Coneʳ : CF.Cone → CFG.Cone F-map-Coneʳ K = record { apex = record { ψ = λ j → ψ (G.F₀ j) ; commute = λ f → commute (G.F₁ f) } } where open CF.Cone K F-map-Cone⇒ʳ : ∀ {K K′} (f : CF.Cone⇒ K K′) → CFG.Cone⇒ (F-map-Coneʳ K) (F-map-Coneʳ K′) F-map-Cone⇒ʳ f = record { arr = arr ; commute = commute } where open CF.Cone⇒ f module _ {F G : Functor J C} (α : NaturalTransformation F G) where private module C = Category C module J = Category J module F = Functor F module G = Functor G module α = NaturalTransformation α module CF = Con F module CG = Con G open C open HomReasoning open MR C nat-map-Cone : CF.Cone → CG.Cone nat-map-Cone K = record { apex = record { ψ = λ j → α.η j C.∘ ψ j ; commute = λ {X Y} f → begin G.F₁ f ∘ α.η X ∘ ψ X ≈˘⟨ pushˡ (α.commute f) ⟩ (α.η Y ∘ F.F₁ f) ∘ ψ X ≈⟨ pullʳ (commute f) ⟩ α.η Y ∘ ψ Y ∎ } } where open CF.Cone K nat-map-Cone⇒ : ∀ {K K′} (f : CF.Cone⇒ K K′) → CG.Cone⇒ (nat-map-Cone K) (nat-map-Cone K′) nat-map-Cone⇒ {K} {K′} f = record { arr = arr ; commute = pullʳ commute } where open CF.Cone⇒ f
algebraic-stack_agda0000_doc_13255
{-# OPTIONS --safe #-} module Definition.Conversion.HelperDecidable where open import Definition.Untyped open import Definition.Untyped.Properties open import Definition.Typed open import Definition.Typed.Properties open import Definition.Conversion open import Definition.Conversion.Whnf open import Definition.Conversion.Soundness open import Definition.Conversion.Symmetry open import Definition.Conversion.Stability open import Definition.Conversion.Conversion open import Definition.Conversion.Lift open import Definition.Typed.Consequences.Syntactic open import Definition.Typed.Consequences.Substitution open import Definition.Typed.Consequences.Injectivity open import Definition.Typed.Consequences.Reduction open import Definition.Typed.Consequences.Equality open import Definition.Typed.Consequences.Inequality as IE open import Definition.Typed.Consequences.NeTypeEq open import Definition.Typed.Consequences.SucCong open import Tools.Nat open import Tools.Product open import Tools.Empty open import Tools.Nullary import Tools.PropositionalEquality as PE dec-relevance : ∀ (r r′ : Relevance) → Dec (r PE.≡ r′) dec-relevance ! ! = yes PE.refl dec-relevance ! % = no (λ ()) dec-relevance % ! = no (λ ()) dec-relevance % % = yes PE.refl dec-level : ∀ (l l′ : Level) → Dec (l PE.≡ l′) dec-level ⁰ ⁰ = yes PE.refl dec-level ⁰ ¹ = no (λ ()) dec-level ¹ ⁰ = no (λ ()) dec-level ¹ ¹ = yes PE.refl -- Algorithmic equality of variables infers propositional equality. strongVarEq : ∀ {m n A Γ l} → Γ ⊢ var n ~ var m ↑! A ^ l → n PE.≡ m strongVarEq (var-refl x x≡y) = x≡y -- Helper function for decidability of applications. dec~↑!-app : ∀ {k k₁ l l₁ F F₁ G G₁ rF B Γ Δ lF lG lΠ lK} → ⊢ Γ ≡ Δ → Γ ⊢ k ∷ Π F ^ rF ° lF ▹ G ° lG ° lΠ ^ [ ! , ι lΠ ] → Δ ⊢ k₁ ∷ Π F₁ ^ rF ° lF ▹ G₁ ° lG ° lΠ ^ [ ! , ι lΠ ] → Γ ⊢ k ~ k₁ ↓! B ^ lK → Dec (Γ ⊢ l [genconv↑] l₁ ∷ F ^ [ rF , ι lF ]) → Dec (∃ λ A → ∃ λ lA → Γ ⊢ k ∘ l ^ lΠ ~ k₁ ∘ l₁ ^ lΠ ↑! A ^ lA) dec~↑!-app Γ≡Δ k k₁ k~k₁ (yes p) = let whnfA , neK , neL = ne~↓! k~k₁ ⊢A , ⊢k , ⊢l = syntacticEqTerm (soundness~↓! k~k₁) l≡l , ΠFG₁≡A = neTypeEq neK k ⊢k H , E , A≡ΠHE = Π≡A ΠFG₁≡A whnfA F≡H , rF≡rH , lF≡lH , lG≡lE , G₁≡E = injectivity (PE.subst (λ x → _ ⊢ _ ≡ x ^ _) A≡ΠHE ΠFG₁≡A) in yes (E [ _ ] , _ , app-cong (PE.subst₂ (λ x y → _ ⊢ _ ~ _ ↓! x ^ y) A≡ΠHE (PE.sym l≡l) k~k₁) (convConvTerm%! p F≡H)) dec~↑!-app Γ≡Δ k k₁ k~k₁ (no ¬p) = no (λ { (_ , _ , app-cong k~k₁′ p) → let whnfA , neK , neL = ne~↓! k~k₁′ ⊢A , ⊢k , ⊢l = syntacticEqTerm (soundness~↓! k~k₁′) l≡l , Π≡Π = neTypeEq neK k ⊢k F≡F , rF≡rF , lF≡lF , lG≡lG , G≡G = injectivity Π≡Π in ¬p (convConvTerm%! (PE.subst₂ (λ x y → _ ⊢ _ [genconv↑] _ ∷ _ ^ [ x , ι y ]) (PE.sym rF≡rF) (PE.sym lF≡lF) p) (sym F≡F)) }) nonNeutralℕ : Neutral ℕ → ⊥ nonNeutralℕ () nonNeutralU : ∀ {r l} → Neutral (Univ r l) → ⊥ nonNeutralU () Idℕ-elim : ∀ {Γ l A B t u t' u'} → Neutral A → Γ ⊢ Id A t u ~ Id ℕ t' u' ↑! B ^ l → ⊥ Idℕ-elim neA (Id-cong x x₁ x₂) = let _ , _ , neℕ = ne~↓! x in ⊥-elim (nonNeutralℕ neℕ) Idℕ-elim neA (Id-ℕ x x₁) = ⊥-elim (nonNeutralℕ neA) Idℕ-elim neA (Id-ℕ0 x) = ⊥-elim (nonNeutralℕ neA) Idℕ-elim neA (Id-ℕS x x₁) = ⊥-elim (nonNeutralℕ neA) Idℕ-elim' : ∀ {Γ l A B t u t' u'} → Neutral A → Γ ⊢ Id ℕ t u ~ Id A t' u' ↑! B ^ l → ⊥ Idℕ-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in Idℕ-elim neA e' conv↑-inversion : ∀ {Γ l A t u} → Whnf A → Whnf t → Whnf u → Γ ⊢ t [conv↑] u ∷ A ^ l → Γ ⊢ t [conv↓] u ∷ A ^ l conv↑-inversion whnfA whnft whnfu ([↑]ₜ B t′ u′ D d d′ whnfB whnft′ whnfu′ t<>u) = let et = whnfRed*Term d whnft eu = whnfRed*Term d′ whnfu eA = whnfRed* D whnfA in PE.subst₃ (λ A X Y → _ ⊢ X [conv↓] Y ∷ A ^ _) (PE.sym eA) (PE.sym et) (PE.sym eu) t<>u Idℕ0-elim- : ∀ {Γ l t} → Neutral t → Γ ⊢ t [conv↓] zero ∷ ℕ ^ l → ⊥ Idℕ0-elim- net (ℕ-ins ()) Idℕ0-elim- net (ne-ins x x₁ x₂ ()) Idℕ0-elim- () (zero-refl x) Idℕ0-elim : ∀ {Γ l A t u u'} → Neutral t → Γ ⊢ Id ℕ t u ~ Id ℕ zero u' ↑! A ^ l → ⊥ Idℕ0-elim net (Id-cong x y x₂) = let e = conv↑-inversion ℕₙ (ne net) zeroₙ y in Idℕ0-elim- net e Idℕ0-elim net (Id-ℕ () x₁) Idℕ0-elim () (Id-ℕ0 x) Idℕ0-elim' : ∀ {Γ l A t u u'} → Neutral t → Γ ⊢ Id ℕ zero u ~ Id ℕ t u' ↑! A ^ l → ⊥ Idℕ0-elim' net e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in Idℕ0-elim net e' IdℕS-elim- : ∀ {Γ l t n} → Neutral t → Γ ⊢ t [conv↓] suc n ∷ ℕ ^ l → ⊥ IdℕS-elim- net (ℕ-ins ()) IdℕS-elim- net (ne-ins x x₁ x₂ ()) IdℕS-elim- () (suc-cong x) IdℕS-elim : ∀ {Γ l A t u n u'} → Neutral t → Γ ⊢ Id ℕ t u ~ Id ℕ (suc n) u' ↑! A ^ l → ⊥ IdℕS-elim net (Id-cong x y x₂) = let e = conv↑-inversion ℕₙ (ne net) sucₙ y in IdℕS-elim- net e IdℕS-elim net (Id-ℕ () x₁) IdℕS-elim () (Id-ℕS x _) IdℕS-elim' : ∀ {Γ l A t u n u'} → Neutral t → Γ ⊢ Id ℕ (suc n) u ~ Id ℕ t u' ↑! A ^ l → ⊥ IdℕS-elim' net e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in IdℕS-elim net e' Idℕ0S-elim- : ∀ {Γ l n} → Γ ⊢ zero [conv↓] suc n ∷ ℕ ^ l → ⊥ Idℕ0S-elim- (ℕ-ins ()) Idℕ0S-elim- (ne-ins x x₁ x₂ ()) Idℕ0S-elim : ∀ {Γ l A u u' n} → Γ ⊢ Id ℕ zero u ~ Id ℕ (suc n) u' ↑! A ^ l → ⊥ Idℕ0S-elim (Id-cong x y x₂) = let e = conv↑-inversion ℕₙ zeroₙ sucₙ y in Idℕ0S-elim- e Idℕ0S-elim (Id-ℕ () _) Idℕ0S-elim' : ∀ {Γ l A u u' n} → Γ ⊢ Id ℕ (suc n) u ~ Id ℕ zero u' ↑! A ^ l → ⊥ Idℕ0S-elim' e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in Idℕ0S-elim e' IdU-elim : ∀ {Γ l A B t u t' u' rU lU} → Neutral A → Γ ⊢ Id A t u ~ Id (Univ rU lU) t' u' ↑! B ^ l → ⊥ IdU-elim neA (Id-cong x x₁ x₂) = let _ , _ , neU = ne~↓! x in ⊥-elim (nonNeutralU neU) IdU-elim neA (Id-U x x₁) = ⊥-elim (nonNeutralU neA) IdU-elim neA (Id-Uℕ x) = ⊥-elim (nonNeutralU neA) IdU-elim neA (Id-UΠ x x₁) = ⊥-elim (nonNeutralU neA) IdU-elim' : ∀ {Γ l A B t u t' u' rU lU} → Neutral A → Γ ⊢ Id (Univ rU lU) t u ~ Id A t' u' ↑! B ^ l → ⊥ IdU-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in IdU-elim neA e' IdUℕ-elim : ∀ {Γ l A t u t' u' rU lU} → Γ ⊢ Id (Univ rU lU) t u ~ Id ℕ t' u' ↑! A ^ l → ⊥ IdUℕ-elim (Id-cong () x₁ x₂) IdℕU-elim : ∀ {Γ l A t u t' u' rU lU} → Γ ⊢ Id ℕ t u ~ Id (Univ rU lU) t' u' ↑! A ^ l → ⊥ IdℕU-elim (Id-cong () x₁ x₂) IdUUℕ-elim : ∀ {Γ l A t u u'} → Neutral t → Γ ⊢ Id (U ⁰) t u ~ Id (U ⁰) ℕ u' ↑! A ^ l → ⊥ IdUUℕ-elim () (Id-Uℕ x) IdUUℕ-elim' : ∀ {Γ l A t u u'} → Neutral t → Γ ⊢ Id (U ⁰) ℕ u ~ Id (U ⁰) t u' ↑! A ^ l → ⊥ IdUUℕ-elim' () (Id-Uℕ x) IdUUΠ-elim- : ∀ {Γ l A rA B X t} → Neutral t → Γ ⊢ t [conv↓] Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰ ∷ X ^ l → ⊥ IdUUΠ-elim- net (η-eq x x₁ x₂ x₃ x₄ x₅ (ne ()) x₇) IdUUΠ-elim : ∀ {Γ l A rA B X t u u'} → Neutral t → Γ ⊢ Id (U ⁰) t u ~ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) u' ↑! X ^ l → ⊥ IdUUΠ-elim net (Id-cong x y x₂) = let e = conv↑-inversion Uₙ (ne net) Πₙ y in IdUUΠ-elim- net e IdUUΠ-elim net (Id-U () x₁) IdUUΠ-elim () (Id-UΠ x x₁) IdUUΠ-elim' : ∀ {Γ l A rA B X t u u'} → Neutral t → Γ ⊢ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) u ~ Id (U ⁰) t u' ↑! X ^ l → ⊥ IdUUΠ-elim' net e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in IdUUΠ-elim net e' IdUUΠℕ-elim- : ∀ {Γ l A rA B X} → Γ ⊢ Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰ [conv↓] ℕ ∷ X ^ l → ⊥ IdUUΠℕ-elim- (η-eq x x₁ x₂ x₃ x₄ x₅ (ne ()) x₇) IdUUΠℕ-elim : ∀ {Γ l A rA B X u u'} → Γ ⊢ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) u ~ Id (U ⁰) ℕ u' ↑! X ^ l → ⊥ IdUUΠℕ-elim (Id-cong x y x₂) = let e = conv↑-inversion Uₙ Πₙ ℕₙ y in IdUUΠℕ-elim- e IdUUΠℕ-elim (Id-U () x₁) IdUUΠℕ-elim' : ∀ {Γ l A rA B X u u'} → Γ ⊢ Id (U ⁰) ℕ u ~ Id (U ⁰) (Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰) u' ↑! X ^ l → ⊥ IdUUΠℕ-elim' e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in IdUUΠℕ-elim e' castℕ-elim : ∀ {Γ l A B B' X t e t' e'} → Neutral A → Γ ⊢ cast ⁰ A B e t ~ cast ⁰ ℕ B' e' t' ↑! X ^ l → ⊥ castℕ-elim neA (cast-cong () x₁ x₂ x₃ x₄) castℕ-elim () (cast-ℕ x x₁ x₂ x₃) castℕ-elim () (cast-ℕℕ x x₁ x₂) castℕ-elim () (cast-ℕΠ x x₁ x₂ x₃) castℕ-elim' : ∀ {Γ l A B B' X t e t' e'} → Neutral A → Γ ⊢ cast ⁰ ℕ B e t ~ cast ⁰ A B' e' t' ↑! X ^ l → ⊥ castℕ-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castℕ-elim neA e' castΠ-elim : ∀ {Γ l A B B' X t e t' e' r P Q} → Neutral A → Γ ⊢ cast ⁰ A B e t ~ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) B' e' t' ↑! X ^ l → ⊥ castΠ-elim neA (cast-cong () x₁ x₂ x₃ x₄) castΠ-elim () (cast-Π x x₁ x₂ x₃ x₄) castΠ-elim () (cast-Πℕ x x₁ x₂ x₃) castΠ-elim () (cast-ΠΠ%! x x₁ x₂ x₃ x₄) castΠ-elim () (cast-ΠΠ!% x x₁ x₂ x₃ x₄) castΠ-elim' : ∀ {Γ l A B B' X t e t' e' r P Q} → Neutral A → Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) B e t ~ cast ⁰ A B' e' t' ↑! X ^ l → ⊥ castΠ-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castΠ-elim neA e' castℕℕ-elim : ∀ {Γ l A X t e t' e'} → Neutral A → Γ ⊢ cast ⁰ ℕ A e t ~ cast ⁰ ℕ ℕ e' t' ↑! X ^ l → ⊥ castℕℕ-elim neA (cast-cong () x₁ x₂ x₃ x₄) castℕℕ-elim (var n) (cast-ℕ () x₁ x₂ x₃) castℕℕ-elim () (cast-ℕℕ x x₁ x₂) castℕℕ-elim' : ∀ {Γ l A X t e t' e'} → Neutral A → Γ ⊢ cast ⁰ ℕ ℕ e t ~ cast ⁰ ℕ A e' t' ↑! X ^ l → ⊥ castℕℕ-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castℕℕ-elim neA e' castℕΠ-elim : ∀ {Γ l A A' X t e t' e' r P Q} → Γ ⊢ cast ⁰ ℕ A e t ~ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) A' e' t' ↑! X ^ l → ⊥ castℕΠ-elim (cast-cong () x₁ x₂ x₃ x₄) castℕΠ-elim' : ∀ {Γ l A A' X t e t' e' r P Q} → Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) A e t ~ cast ⁰ ℕ A' e' t' ↑! X ^ l → ⊥ castℕΠ-elim' (cast-cong () x₁ x₂ x₃ x₄) castℕneΠ-elim : ∀ {Γ l A X t e t' e' r P Q} → Neutral A → Γ ⊢ cast ⁰ ℕ A e t ~ cast ⁰ ℕ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) e' t' ↑! X ^ l → ⊥ castℕneΠ-elim neA (cast-cong () x₁ x₂ x₃ x₄) castℕneΠ-elim neA (cast-ℕ () x₁ x₂ x₃) castℕneΠ-elim () (cast-ℕΠ x x₁ x₂ x₃) castℕneΠ-elim' : ∀ {Γ l A X t e t' e' r P Q} → Neutral A → Γ ⊢ cast ⁰ ℕ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) e t ~ cast ⁰ ℕ A e' t' ↑! X ^ l → ⊥ castℕneΠ-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castℕneΠ-elim neA e' castℕℕΠ-elim : ∀ {Γ l X t e t' e' r P Q} → Γ ⊢ cast ⁰ ℕ ℕ e t ~ cast ⁰ ℕ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) e' t' ↑! X ^ l → ⊥ castℕℕΠ-elim (cast-cong () x₁ x₂ x₃ x₄) castℕℕΠ-elim (cast-ℕ () x₁ x₂ x₃) castℕℕΠ-elim' : ∀ {Γ l X t e t' e' r P Q} → Γ ⊢ cast ⁰ ℕ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) e t ~ cast ⁰ ℕ ℕ e' t' ↑! X ^ l → ⊥ castℕℕΠ-elim' e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castℕℕΠ-elim e' castΠneℕ-elim : ∀ {Γ l A X t e t' e' r P Q r' P' Q'} → Neutral A → Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) A e t ~ cast ⁰ (Π P' ^ r' ° ⁰ ▹ Q' ° ⁰ ° ⁰) ℕ e' t' ↑! X ^ l → ⊥ castΠneℕ-elim neA (cast-cong () x₁ x₂ x₃ x₄) castΠneℕ-elim neA (cast-Π x () x₂ x₃ x₄) castΠneℕ-elim () (cast-Πℕ x x₁ x₂ x₃) castΠneℕ-elim' : ∀ {Γ l A X t e t' e' r P Q r' P' Q'} → Neutral A → Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) ℕ e t ~ cast ⁰ (Π P' ^ r' ° ⁰ ▹ Q' ° ⁰ ° ⁰) A e' t' ↑! X ^ l → ⊥ castΠneℕ-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castΠneℕ-elim neA e' castΠneΠ-elim : ∀ {Γ l A X t e t' e' r P Q r' P' Q' r'' P'' Q''} → Neutral A → Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) A e t ~ cast ⁰ (Π P' ^ r' ° ⁰ ▹ Q' ° ⁰ ° ⁰) (Π P'' ^ r'' ° ⁰ ▹ Q'' ° ⁰ ° ⁰) e' t' ↑! X ^ l → ⊥ castΠneΠ-elim neA (cast-cong () x₁ x₂ x₃ x₄) castΠneΠ-elim neA (cast-Π x () x₂ x₃ x₄) castΠneΠ-elim () (cast-ΠΠ%! x x₁ x₂ x₃ x₄) castΠneΠ-elim () (cast-ΠΠ!% x x₁ x₂ x₃ x₄) castΠneΠ-elim' : ∀ {Γ l A X t e t' e' r P Q r' P' Q' r'' P'' Q''} → Neutral A → Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) (Π P'' ^ r'' ° ⁰ ▹ Q'' ° ⁰ ° ⁰) e t ~ cast ⁰ (Π P' ^ r' ° ⁰ ▹ Q' ° ⁰ ° ⁰) A e' t' ↑! X ^ l → ⊥ castΠneΠ-elim' neA e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castΠneΠ-elim neA e' castΠΠℕ-elim : ∀ {Γ l X t e t' e' r P Q r' P' Q' r'' P'' Q''} → Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) ℕ e t ~ cast ⁰ (Π P' ^ r' ° ⁰ ▹ Q' ° ⁰ ° ⁰) (Π P'' ^ r'' ° ⁰ ▹ Q'' ° ⁰ ° ⁰) e' t' ↑! X ^ l → ⊥ castΠΠℕ-elim (cast-cong () x₁ x₂ x₃ x₄) castΠΠℕ-elim (cast-Π x () x₂ x₃ x₄) castΠΠℕ-elim' : ∀ {Γ l X t e t' e' r P Q r' P' Q' r'' P'' Q''} → Γ ⊢ cast ⁰ (Π P ^ r ° ⁰ ▹ Q ° ⁰ ° ⁰) (Π P'' ^ r'' ° ⁰ ▹ Q'' ° ⁰ ° ⁰) e t ~ cast ⁰ (Π P' ^ r' ° ⁰ ▹ Q' ° ⁰ ° ⁰) ℕ e' t' ↑! X ^ l → ⊥ castΠΠℕ-elim' e = let _ , _ , e' = sym~↑! (reflConEq (wfEqTerm (soundness~↑! e))) e in castΠΠℕ-elim e' castΠΠ!%-elim : ∀ {Γ l A A' X t e t' e' P Q P' Q'} → Γ ⊢ cast ⁰ (Π P ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰) A e t ~ cast ⁰ (Π P' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰) A' e' t' ↑! X ^ l → ⊥ castΠΠ!%-elim (cast-cong () x₁ x₂ x₃ x₄) castΠΠ%!-elim : ∀ {Γ l A A' X t e t' e' P Q P' Q'} → Γ ⊢ cast ⁰ (Π P ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰) A e t ~ cast ⁰ (Π P' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰) A' e' t' ↑! X ^ l → ⊥ castΠΠ%!-elim (cast-cong () x₁ x₂ x₃ x₄) -- Helper functions for decidability for neutrals decConv↓Term-ℕ-ins : ∀ {t u Γ l} → Γ ⊢ t [conv↓] u ∷ ℕ ^ l → Γ ⊢ t ~ t ↓! ℕ ^ l → Γ ⊢ t ~ u ↓! ℕ ^ l decConv↓Term-ℕ-ins (ℕ-ins x) t~t = x decConv↓Term-ℕ-ins (ne-ins x x₁ () x₃) t~t decConv↓Term-ℕ-ins (zero-refl x) ([~] A D whnfB ()) decConv↓Term-ℕ-ins (suc-cong x) ([~] A D whnfB ()) decConv↓Term-U-ins : ∀ {t u Γ r lU l} → Γ ⊢ t [conv↓] u ∷ Univ r lU ^ l → Γ ⊢ t ~ t ↓! Univ r lU ^ l → Γ ⊢ t ~ u ↓! Univ r lU ^ l decConv↓Term-U-ins (ne x) t~r = x decConv↓Term-ne-ins : ∀ {t u A Γ l} → Neutral A → Γ ⊢ t [conv↓] u ∷ A ^ l → ∃ λ B → ∃ λ lB → Γ ⊢ t ~ u ↓! B ^ lB decConv↓Term-ne-ins neA (ne-ins x x₁ x₂ x₃) = _ , _ , x₃ -- Helper function for decidability for impossibility of terms not being equal -- as neutrals when they are equal as terms and the first is a neutral. decConv↓Term-ℕ : ∀ {t u Γ l} → Γ ⊢ t [conv↓] u ∷ ℕ ^ l → Γ ⊢ t ~ t ↓! ℕ ^ l → ¬ (Γ ⊢ t ~ u ↓! ℕ ^ l) → ⊥ decConv↓Term-ℕ (ℕ-ins x) t~t ¬u~u = ¬u~u x decConv↓Term-ℕ (ne-ins x x₁ () x₃) t~t ¬u~u decConv↓Term-ℕ (zero-refl x) ([~] A D whnfB ()) ¬u~u decConv↓Term-ℕ (suc-cong x) ([~] A D whnfB ()) ¬u~u decConv↓Term-U : ∀ {t u Γ r lU l} → Γ ⊢ t [conv↓] u ∷ Univ r lU ^ l → Γ ⊢ t ~ t ↓! Univ r lU ^ l → ¬ (Γ ⊢ t ~ u ↓! Univ r lU ^ l) → ⊥ decConv↓Term-U (ne x) t~t ¬u~u = ¬u~u x
algebraic-stack_agda0000_doc_13256
record R (X : Set) : Set₁ where field P : X → Set f : ∀ {x : X} → P x → P x open R {{…}} test : ∀ {X} {{r : R X}} {x : X} → P x → P x test p = f p -- WAS: instance search fails with several candidates left -- SHOULD: succeed
algebraic-stack_agda0000_doc_13257
------------------------------------------------------------------------ -- The Agda standard library -- -- Heterogeneous equality ------------------------------------------------------------------------ {-# OPTIONS --with-K --safe #-} module Relation.Binary.HeterogeneousEquality where import Axiom.Extensionality.Heterogeneous as Ext open import Data.Product open import Data.Unit.NonEta open import Function open import Function.Inverse using (Inverse) open import Level open import Relation.Nullary open import Relation.Binary open import Relation.Binary.Consequences open import Relation.Binary.Indexed.Heterogeneous using (IndexedSetoid) open import Relation.Binary.Indexed.Heterogeneous.Construct.At using (_atₛ_) open import Relation.Binary.PropositionalEquality as P using (_≡_; refl) import Relation.Binary.HeterogeneousEquality.Core as Core ------------------------------------------------------------------------ -- Heterogeneous equality infix 4 _≇_ open Core public using (_≅_; refl) -- Nonequality. _≇_ : ∀ {ℓ} {A : Set ℓ} → A → {B : Set ℓ} → B → Set ℓ x ≇ y = ¬ x ≅ y ------------------------------------------------------------------------ -- Conversion open Core public using (≅-to-≡; ≡-to-≅) ≅-to-type-≡ : ∀ {a} {A B : Set a} {x : A} {y : B} → x ≅ y → A ≡ B ≅-to-type-≡ refl = refl ≅-to-subst-≡ : ∀ {a} {A B : Set a} {x : A} {y : B} → (p : x ≅ y) → P.subst (λ x → x) (≅-to-type-≡ p) x ≡ y ≅-to-subst-≡ refl = refl ------------------------------------------------------------------------ -- Some properties reflexive : ∀ {a} {A : Set a} → _⇒_ {A = A} _≡_ (λ x y → x ≅ y) reflexive refl = refl sym : ∀ {ℓ} {A B : Set ℓ} {x : A} {y : B} → x ≅ y → y ≅ x sym refl = refl trans : ∀ {ℓ} {A B C : Set ℓ} {x : A} {y : B} {z : C} → x ≅ y → y ≅ z → x ≅ z trans refl eq = eq subst : ∀ {a} {A : Set a} {p} → Substitutive {A = A} (λ x y → x ≅ y) p subst P refl p = p subst₂ : ∀ {a b p} {A : Set a} {B : Set b} (P : A → B → Set p) → ∀ {x₁ x₂ y₁ y₂} → x₁ ≅ x₂ → y₁ ≅ y₂ → P x₁ y₁ → P x₂ y₂ subst₂ P refl refl p = p subst-removable : ∀ {a p} {A : Set a} (P : A → Set p) {x y} (eq : x ≅ y) z → subst P eq z ≅ z subst-removable P refl z = refl ≡-subst-removable : ∀ {a p} {A : Set a} (P : A → Set p) {x y} (eq : x ≡ y) z → P.subst P eq z ≅ z ≡-subst-removable P refl z = refl cong : ∀ {a b} {A : Set a} {B : A → Set b} {x y} (f : (x : A) → B x) → x ≅ y → f x ≅ f y cong f refl = refl cong-app : ∀ {a b} {A : Set a} {B : A → Set b} {f g : (x : A) → B x} → f ≅ g → (x : A) → f x ≅ g x cong-app refl x = refl cong₂ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : ∀ x → B x → Set c} {x y u v} (f : (x : A) (y : B x) → C x y) → x ≅ y → u ≅ v → f x u ≅ f y v cong₂ f refl refl = refl resp₂ : ∀ {a ℓ} {A : Set a} (∼ : Rel A ℓ) → ∼ Respects₂ (λ x y → x ≅ y) resp₂ _∼_ = subst⟶resp₂ _∼_ subst icong : ∀ {a b ℓ} {I : Set ℓ} (A : I → Set a) {B : {k : I} → A k → Set b} {i j : I} {x : A i} {y : A j} → i ≡ j → (f : {k : I} → (z : A k) → B z) → x ≅ y → f x ≅ f y icong _ refl _ refl = refl icong₂ : ∀ {a b c ℓ} {I : Set ℓ} (A : I → Set a) {B : {k : I} → A k → Set b} {C : {k : I} → (a : A k) → B a → Set c} {i j : I} {x : A i} {y : A j} {u : B x} {v : B y} → i ≡ j → (f : {k : I} → (z : A k) → (w : B z) → C z w) → x ≅ y → u ≅ v → f x u ≅ f y v icong₂ _ refl _ refl refl = refl icong-subst-removable : ∀ {a b ℓ} {I : Set ℓ} (A : I → Set a) {B : {k : I} → A k → Set b} {i j : I} (eq : i ≅ j) (f : {k : I} → (z : A k) → B z) (x : A i) → f (subst A eq x) ≅ f x icong-subst-removable _ refl _ _ = refl icong-≡-subst-removable : ∀ {a b ℓ} {I : Set ℓ} (A : I → Set a) {B : {k : I} → A k → Set b} {i j : I} (eq : i ≡ j) (f : {k : I} → (z : A k) → B z) (x : A i) → f (P.subst A eq x) ≅ f x icong-≡-subst-removable _ refl _ _ = refl ------------------------------------------------------------------------ --Proof irrelevance ≅-irrelevant : ∀ {ℓ} {A B : Set ℓ} → Irrelevant ((A → B → Set ℓ) ∋ λ a → a ≅_) ≅-irrelevant refl refl = refl module _ {ℓ} {A₁ A₂ A₃ A₄ : Set ℓ} {a₁ : A₁} {a₂ : A₂} {a₃ : A₃} {a₄ : A₄} where ≅-heterogeneous-irrelevant : (p : a₁ ≅ a₂) (q : a₃ ≅ a₄) → a₂ ≅ a₃ → p ≅ q ≅-heterogeneous-irrelevant refl refl refl = refl ≅-heterogeneous-irrelevantˡ : (p : a₁ ≅ a₂) (q : a₃ ≅ a₄) → a₁ ≅ a₃ → p ≅ q ≅-heterogeneous-irrelevantˡ refl refl refl = refl ≅-heterogeneous-irrelevantʳ : (p : a₁ ≅ a₂) (q : a₃ ≅ a₄) → a₂ ≅ a₄ → p ≅ q ≅-heterogeneous-irrelevantʳ refl refl refl = refl ------------------------------------------------------------------------ -- Structures isEquivalence : ∀ {a} {A : Set a} → IsEquivalence {A = A} (λ x y → x ≅ y) isEquivalence = record { refl = refl ; sym = sym ; trans = trans } setoid : ∀ {a} → Set a → Setoid _ _ setoid A = record { Carrier = A ; _≈_ = λ x y → x ≅ y ; isEquivalence = isEquivalence } indexedSetoid : ∀ {a b} {A : Set a} → (A → Set b) → IndexedSetoid A _ _ indexedSetoid B = record { Carrier = B ; _≈_ = λ x y → x ≅ y ; isEquivalence = record { refl = refl ; sym = sym ; trans = trans } } ≡↔≅ : ∀ {a b} {A : Set a} (B : A → Set b) {x : A} → Inverse (P.setoid (B x)) ((indexedSetoid B) atₛ x) ≡↔≅ B = record { to = record { _⟨$⟩_ = id; cong = ≡-to-≅ } ; from = record { _⟨$⟩_ = id; cong = ≅-to-≡ } ; inverse-of = record { left-inverse-of = λ _ → refl ; right-inverse-of = λ _ → refl } } decSetoid : ∀ {a} {A : Set a} → Decidable {A = A} {B = A} (λ x y → x ≅ y) → DecSetoid _ _ decSetoid dec = record { _≈_ = λ x y → x ≅ y ; isDecEquivalence = record { isEquivalence = isEquivalence ; _≟_ = dec } } isPreorder : ∀ {a} {A : Set a} → IsPreorder {A = A} (λ x y → x ≅ y) (λ x y → x ≅ y) isPreorder = record { isEquivalence = isEquivalence ; reflexive = id ; trans = trans } isPreorder-≡ : ∀ {a} {A : Set a} → IsPreorder {A = A} _≡_ (λ x y → x ≅ y) isPreorder-≡ = record { isEquivalence = P.isEquivalence ; reflexive = reflexive ; trans = trans } preorder : ∀ {a} → Set a → Preorder _ _ _ preorder A = record { Carrier = A ; _≈_ = _≡_ ; _∼_ = λ x y → x ≅ y ; isPreorder = isPreorder-≡ } ------------------------------------------------------------------------ -- Convenient syntax for equational reasoning module ≅-Reasoning where -- The code in `Relation.Binary.Reasoning.Setoid` cannot handle -- heterogeneous equalities, hence the code duplication here. infix 4 _IsRelatedTo_ infix 3 _∎ infixr 2 _≅⟨_⟩_ _≅˘⟨_⟩_ _≡⟨_⟩_ _≡˘⟨_⟩_ _≡⟨⟩_ infix 1 begin_ data _IsRelatedTo_ {ℓ} {A : Set ℓ} (x : A) {B : Set ℓ} (y : B) : Set ℓ where relTo : (x≅y : x ≅ y) → x IsRelatedTo y begin_ : ∀ {ℓ} {A : Set ℓ} {x : A} {B} {y : B} → x IsRelatedTo y → x ≅ y begin relTo x≅y = x≅y _≅⟨_⟩_ : ∀ {ℓ} {A : Set ℓ} (x : A) {B} {y : B} {C} {z : C} → x ≅ y → y IsRelatedTo z → x IsRelatedTo z _ ≅⟨ x≅y ⟩ relTo y≅z = relTo (trans x≅y y≅z) _≅˘⟨_⟩_ : ∀ {ℓ} {A : Set ℓ} (x : A) {B} {y : B} {C} {z : C} → y ≅ x → y IsRelatedTo z → x IsRelatedTo z _ ≅˘⟨ y≅x ⟩ relTo y≅z = relTo (trans (sym y≅x) y≅z) _≡⟨_⟩_ : ∀ {ℓ} {A : Set ℓ} (x : A) {y C} {z : C} → x ≡ y → y IsRelatedTo z → x IsRelatedTo z _ ≡⟨ x≡y ⟩ relTo y≅z = relTo (trans (reflexive x≡y) y≅z) _≡˘⟨_⟩_ : ∀ {ℓ} {A : Set ℓ} (x : A) {y C} {z : C} → y ≡ x → y IsRelatedTo z → x IsRelatedTo z _ ≡˘⟨ y≡x ⟩ relTo y≅z = relTo (trans (sym (reflexive y≡x)) y≅z) _≡⟨⟩_ : ∀ {ℓ} {A : Set ℓ} (x : A) {B} {y : B} → x IsRelatedTo y → x IsRelatedTo y _ ≡⟨⟩ x≅y = x≅y _∎ : ∀ {a} {A : Set a} (x : A) → x IsRelatedTo x _∎ _ = relTo refl ------------------------------------------------------------------------ -- Inspect -- Inspect can be used when you want to pattern match on the result r -- of some expression e, and you also need to "remember" that r ≡ e. record Reveal_·_is_ {a b} {A : Set a} {B : A → Set b} (f : (x : A) → B x) (x : A) (y : B x) : Set (a ⊔ b) where constructor [_] field eq : f x ≅ y inspect : ∀ {a b} {A : Set a} {B : A → Set b} (f : (x : A) → B x) (x : A) → Reveal f · x is f x inspect f x = [ refl ] -- Example usage: -- f x y with g x | inspect g x -- f x y | c z | [ eq ] = ... ------------------------------------------------------------------------ -- DEPRECATED NAMES ------------------------------------------------------------------------ -- Please use the new names as continuing support for the old names is -- not guaranteed. -- Version 0.15 proof-irrelevance = ≅-irrelevant {-# WARNING_ON_USAGE proof-irrelevance "Warning: proof-irrelevance was deprecated in v0.15. Please use ≅-irrelevant instead." #-} -- Version 1.0 ≅-irrelevance = ≅-irrelevant {-# WARNING_ON_USAGE ≅-irrelevance "Warning: ≅-irrelevance was deprecated in v1.0. Please use ≅-irrelevant instead." #-} ≅-heterogeneous-irrelevance = ≅-heterogeneous-irrelevant {-# WARNING_ON_USAGE ≅-heterogeneous-irrelevance "Warning: ≅-heterogeneous-irrelevance was deprecated in v1.0. Please use ≅-heterogeneous-irrelevant instead." #-} ≅-heterogeneous-irrelevanceˡ = ≅-heterogeneous-irrelevantˡ {-# WARNING_ON_USAGE ≅-heterogeneous-irrelevanceˡ "Warning: ≅-heterogeneous-irrelevanceˡ was deprecated in v1.0. Please use ≅-heterogeneous-irrelevantˡ instead." #-} ≅-heterogeneous-irrelevanceʳ = ≅-heterogeneous-irrelevantʳ {-# WARNING_ON_USAGE ≅-heterogeneous-irrelevanceʳ "Warning: ≅-heterogeneous-irrelevanceʳ was deprecated in v1.0. Please use ≅-heterogeneous-irrelevantʳ instead." #-} Extensionality = Ext.Extensionality {-# WARNING_ON_USAGE Extensionality "Warning: Extensionality was deprecated in v1.0. Please use Extensionality from `Axiom.Extensionality.Heterogeneous` instead." #-} ≡-ext-to-≅-ext = Ext.≡-ext⇒≅-ext {-# WARNING_ON_USAGE ≡-ext-to-≅-ext "Warning: ≡-ext-to-≅-ext was deprecated in v1.0. Please use ≡-ext⇒≅-ext from `Axiom.Extensionality.Heterogeneous` instead." #-}
algebraic-stack_agda0000_doc_13258
{-# OPTIONS --without-K #-} module Data.Word8.Primitive where open import Agda.Builtin.Bool using (Bool) open import Agda.Builtin.Nat using (Nat) {-# FOREIGN GHC import qualified Data.Word #-} {-# FOREIGN GHC import qualified Data.Bits #-} postulate Word8 : Set _==_ : Word8 → Word8 → Bool _/=_ : Word8 → Word8 → Bool _xor_ : Word8 → Word8 → Word8 _and_ : Word8 → Word8 → Word8 _or_ : Word8 → Word8 → Word8 {-# COMPILE GHC Word8 = type Data.Word.Word8 #-} {-# COMPILE GHC _==_ = (Prelude.==) #-} {-# COMPILE GHC _/=_ = (Prelude./=) #-} {-# COMPILE GHC _xor_ = (Data.Bits.xor) #-} {-# COMPILE GHC _and_ = (Data.Bits..&.) #-} {-# COMPILE GHC _or_ = (Data.Bits..|.) #-} postulate primWord8fromNat : Nat → Word8 primWord8toNat : Word8 → Nat {-# COMPILE GHC primWord8fromNat = (\n -> Prelude.fromIntegral n) #-} {-# COMPILE GHC primWord8toNat = (\w -> Prelude.fromIntegral w) #-}
algebraic-stack_agda0000_doc_13259
------------------------------------------------------------------------------ -- Testing the --schematic-propositional-symbols option ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- Fails because requires the above option. module RequiredOption.SchematicPropositionalSymbols where postulate D : Set postulate id : (P : Set) → P → P {-# ATP prove id #-}
algebraic-stack_agda0000_doc_13260
module Formalization.ClassicalPropositionalLogic.NaturalDeduction.Consistency where import Lvl open import Formalization.ClassicalPropositionalLogic.NaturalDeduction open import Formalization.ClassicalPropositionalLogic.NaturalDeduction.Proofs open import Formalization.ClassicalPropositionalLogic.Syntax open import Functional open import Logic.Propositional as Logic using (_←_) open import Logic.Propositional.Theorems as Logic using () open import Relator.Equals.Proofs.Equiv open import Sets.PredicateSet using (PredSet ; _∈_ ; _∉_ ; _∪_ ; _∪•_ ; _∖_ ; _⊆_ ; _⊇_ ; ∅ ; [≡]-to-[⊆] ; [≡]-to-[⊇]) renaming (•_ to singleton ; _≡_ to _≡ₛ_) open import Type private variable ℓₚ ℓ ℓ₁ ℓ₂ : Lvl.Level private variable P : Type{ℓₚ} private variable Γ Γ₁ Γ₂ : Formulas(P){ℓ} private variable φ ψ : Formula(P) Inconsistent : Formulas(P){ℓ} → Type Inconsistent(Γ) = Γ ⊢ ⊥ Consistent : Formulas(P){ℓ} → Type Consistent(Γ) = Γ ⊬ ⊥ consistency-of-[∪]ₗ : Consistent(Γ₁ ∪ Γ₂) → Consistent(Γ₁) consistency-of-[∪]ₗ con z = con (weaken-union z) [⊢]-derivability-inconsistency : (Γ ⊢ φ) Logic.↔ Inconsistent(Γ ∪ singleton(¬ φ)) [⊢]-derivability-inconsistency = Logic.[↔]-intro [¬]-elim ([¬]-intro-converse ∘ [¬¬]-intro) [⊢]-derivability-consistencyᵣ : Consistent(Γ) → ((Γ ⊢ φ) → Consistent(Γ ∪ singleton(φ))) [⊢]-derivability-consistencyᵣ con Γφ Γφ⊥ = con([⊥]-intro Γφ ([¬]-intro Γφ⊥)) [⊢]-explosion-inconsistency : (∀{φ} → (Γ ⊢ φ)) Logic.↔ Inconsistent(Γ) [⊢]-explosion-inconsistency {Γ} = Logic.[↔]-intro (λ z → [⊥]-elim z) (λ z → z) [⊢]-compose-inconsistency : (Γ ⊢ φ) → Inconsistent(Γ ∪ singleton(φ)) → Inconsistent(Γ) [⊢]-compose-inconsistency Γφ Γφ⊥ = [⊥]-intro Γφ ([¬]-intro Γφ⊥) [⊢]-compose-consistency : (Γ ⊢ φ) → Consistent(Γ) → Consistent(Γ ∪ singleton(φ)) [⊢]-compose-consistency Γφ = Logic.contrapositiveᵣ ([⊢]-compose-inconsistency Γφ) [⊢]-subset-consistency : (Γ₁ ⊆ Γ₂) → (Consistent(Γ₂) → Consistent(Γ₁)) [⊢]-subset-consistency sub con = con ∘ weaken sub [⊢]-subset-inconsistency : (Γ₁ ⊆ Γ₂) → (Inconsistent(Γ₁) → Inconsistent(Γ₂)) [⊢]-subset-inconsistency sub = weaken sub [⊬]-negation-consistency : (Γ ⊬ (¬ φ)) → Consistent(Γ ∪ singleton(φ)) [⊬]-negation-consistency = _∘ [¬]-intro [⊢]-consistent-noncontradicting-membership : Consistent(Γ) → ((¬ φ) ∈ Γ) → (φ ∈ Γ) → Logic.⊥ [⊢]-consistent-noncontradicting-membership con Γ¬φ Γφ = con([⊥]-intro (direct Γφ) (direct Γ¬φ))
algebraic-stack_agda0000_doc_13261
open import Structure.Operator.Field open import Structure.Setoid open import Type -- Operators for matrices over a field. module Numeral.Matrix.OverField {ℓ ℓₑ}{T : Type{ℓ}} ⦃ equiv : Equiv{ℓₑ}(T) ⦄ {_+ₛ_ _⋅ₛ_ : T → T → T} ⦃ field-structure : Field(_+ₛ_)(_⋅ₛ_) ⦄ where open Field(field-structure) renaming (_−_ to _−ₛ_ ; −_ to −ₛ_ ; 𝟎 to 𝟎ₛ ; 𝟏 to 𝟏ₛ) open import Data.Tuple as Tuple using (_,_) open import Logic.Predicate open import Numeral.Matrix open import Numeral.Matrix.Proofs open import Structure.Operator.Properties 𝟎 : ∀{s} → Matrix(s)(T) 𝟎 = fill(𝟎ₛ) 𝟏 : ∀{n} → Matrix(n , n)(T) 𝟏 = SquareMatrix.scalarMat(𝟎ₛ)(𝟏ₛ) _+_ : ∀{s} → Matrix(s)(T) → Matrix(s)(T) → Matrix(s)(T) _+_ = map₂(_+ₛ_) infixr 1000 _+_ _−_ : ∀{s} → Matrix(s)(T) → Matrix(s)(T) → Matrix(s)(T) _−_ = map₂(_−ₛ_) infixr 1000 _−_ −_ : ∀{s} → Matrix(s)(T) → Matrix(s)(T) −_ = map(−ₛ_) infixr 1000 −_ _⨯_ : ∀{x y z} → Matrix(y , z)(T) → Matrix(x , y)(T) → Matrix(x , z)(T) _⨯_ = multPattern(_+ₛ_)(_⋅ₛ_)(𝟎ₛ) infixr 1000 _⨯_ _⁻¹ : ∀{n} → (M : Matrix(n , n)(T)) ⦃ inver : InvertibleElement(_⨯_) ⦃ [∃]-intro 𝟏 ⦃ {!matrix-multPattern-identity!} ⦄ ⦄ (M) ⦄ → Matrix(n , n)(T) _⁻¹ _ ⦃ inver ⦄ = [∃]-witness inver
algebraic-stack_agda0000_doc_13262
module Five where open import Relation.Binary.PropositionalEquality open ≡-Reasoning import Data.Nat as ℕ import Data.Nat.Properties as ℕₚ import Data.List as List import Data.List.Properties as Listₚ import Data.Product as Product open List using (List; []; _∷_; _++_) open ℕ using (ℕ; zero; suc; _+_) open Product using (Σ; _,_) -- Our language consists of constants and addition data Expr : Set where const : ℕ → Expr plus : Expr → Expr → Expr -- Straightforward semantics eval-expr : Expr → ℕ eval-expr (const n) = n eval-expr (plus e1 e2) = eval-expr e1 + eval-expr e2 data Instr : Set where push : ℕ → Instr add : Instr Prog = List Instr Stack = List ℕ run : Prog → Stack → Stack run [] s = s run (push n ∷ p) s = run p (n ∷ s) run (add ∷ p) (a1 ∷ a2 ∷ s) = run p (a1 + a2 ∷ s) run (add ∷ p) s = run p s compile : Expr → Prog compile (const n) = push n ∷ [] compile (plus e1 e2) = compile e1 ++ compile e2 ++ add ∷ [] -- Task 2. Prove that you get the expected result when you compile and run the program. compile-correct-split : ∀ p q s → run (p ++ q) s ≡ run q (run p s) compile-correct-split = {!!} compile-correct-exist : ∀ e s → Σ ℕ (λ m → run (compile e) s ≡ m ∷ s) compile-correct-exist = {!!} compile-correct-gen : ∀ e s → run (compile e) s ≡ run (compile e) [] ++ s compile-correct-gen = {!!} compile-correct : ∀ e → run (compile e) [] ≡ eval-expr e ∷ [] compile-correct = {!!}
algebraic-stack_agda0000_doc_13263
open import Prelude renaming (lift to finlift) hiding (id; subst) module Implicits.Substitutions.Lemmas.LNMetaType where open import Implicits.Syntax.LNMetaType open import Implicits.Substitutions.LNMetaType open import Data.Fin.Substitution open import Data.Fin.Substitution.Lemmas open import Data.Vec.Properties open import Data.Star using (Star; ε; _◅_) open import Data.Nat.Properties open import Data.Nat as Nat open import Extensions.Substitution open import Relation.Binary using (module DecTotalOrder) open DecTotalOrder decTotalOrder using () renaming (refl to ≤-refl; trans to ≤-trans) open import Relation.Binary.HeterogeneousEquality as H using () module HR = H.≅-Reasoning typeLemmas : TermLemmas MetaType typeLemmas = record { termSubst = typeSubst; app-var = refl ; /✶-↑✶ = Lemma./✶-↑✶ } where module Lemma {T₁ T₂} {lift₁ : Lift T₁ MetaType} {lift₂ : Lift T₂ MetaType} where open Lifted lift₁ using () renaming (_↑✶_ to _↑✶₁_; _/✶_ to _/✶₁_) open Lifted lift₂ using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂_) /✶-↑✶ : ∀ {m n} (σs₁ : Subs T₁ m n) (σs₂ : Subs T₂ m n) → (∀ k x → (simpl (mvar x)) /✶₁ σs₁ ↑✶₁ k ≡ (simpl (mvar x)) /✶₂ σs₂ ↑✶₂ k) → ∀ k t → t /✶₁ σs₁ ↑✶₁ k ≡ t /✶₂ σs₂ ↑✶₂ k /✶-↑✶ ρs₁ ρs₂ hyp k (simpl (mvar x)) = hyp k x /✶-↑✶ ρs₁ ρs₂ hyp k (simpl (tvar x)) = begin simpl (tvar x) /✶₁ ρs₁ ↑✶₁ k ≡⟨ MetaTypeApp.tvar-/✶-↑✶ _ k ρs₁ ⟩ simpl (tvar x) ≡⟨ sym $ MetaTypeApp.tvar-/✶-↑✶ _ k ρs₂ ⟩ simpl (tvar x) /✶₂ ρs₂ ↑✶₂ k ∎ /✶-↑✶ ρs₁ ρs₂ hyp k (simpl (tc c)) = begin (simpl (tc c)) /✶₁ ρs₁ ↑✶₁ k ≡⟨ MetaTypeApp.tc-/✶-↑✶ _ k ρs₁ ⟩ (simpl (tc c)) ≡⟨ sym $ MetaTypeApp.tc-/✶-↑✶ _ k ρs₂ ⟩ (simpl (tc c)) /✶₂ ρs₂ ↑✶₂ k ∎ /✶-↑✶ ρs₁ ρs₂ hyp k (simpl (a →' b)) = begin (simpl (a →' b)) /✶₁ ρs₁ ↑✶₁ k ≡⟨ MetaTypeApp.→'-/✶-↑✶ _ k ρs₁ ⟩ simpl ((a /✶₁ ρs₁ ↑✶₁ k) →' (b /✶₁ ρs₁ ↑✶₁ k)) ≡⟨ cong₂ (λ a b → simpl (a →' b)) (/✶-↑✶ ρs₁ ρs₂ hyp k a) (/✶-↑✶ ρs₁ ρs₂ hyp k b) ⟩ simpl ((a /✶₂ ρs₂ ↑✶₂ k) →' (b /✶₂ ρs₂ ↑✶₂ k)) ≡⟨ sym (MetaTypeApp.→'-/✶-↑✶ _ k ρs₂) ⟩ (simpl (a →' b)) /✶₂ ρs₂ ↑✶₂ k ∎ /✶-↑✶ ρs₁ ρs₂ hyp k (a ⇒ b) = begin (a ⇒ b) /✶₁ ρs₁ ↑✶₁ k ≡⟨ MetaTypeApp.⇒-/✶-↑✶ _ k ρs₁ ⟩ -- (a /✶₁ ρs₁ ↑✶₁ k) ⇒ (b /✶₁ ρs₁ ↑✶₁ k) ≡⟨ cong₂ _⇒_ (/✶-↑✶ ρs₁ ρs₂ hyp k a) (/✶-↑✶ ρs₁ ρs₂ hyp k b) ⟩ (a /✶₂ ρs₂ ↑✶₂ k) ⇒ (b /✶₂ ρs₂ ↑✶₂ k) ≡⟨ sym (MetaTypeApp.⇒-/✶-↑✶ _ k ρs₂) ⟩ (a ⇒ b) /✶₂ ρs₂ ↑✶₂ k ∎ /✶-↑✶ ρs₁ ρs₂ hyp k (∀' a) = begin (∀' a) /✶₁ ρs₁ ↑✶₁ k ≡⟨ MetaTypeApp.∀'-/✶-↑✶ _ k ρs₁ ⟩ ∀' (a /✶₁ ρs₁ ↑✶₁ k) ≡⟨ cong ∀' (/✶-↑✶ ρs₁ ρs₂ hyp k a) ⟩ ∀' (a /✶₂ ρs₂ ↑✶₂ k) ≡⟨ sym (MetaTypeApp.∀'-/✶-↑✶ _ k ρs₂) ⟩ (∀' a) /✶₂ ρs₂ ↑✶₂ k ∎ open TermLemmas typeLemmas public hiding (var; id; _/_; _↑⋆_; wk; weaken; sub) open AdditionalLemmas typeLemmas public -- The above lemma /✶-↑✶ specialized to single substitutions /-↑⋆ : ∀ {T₁ T₂} {lift₁ : Lift T₁ MetaType} {lift₂ : Lift T₂ MetaType} → let open Lifted lift₁ using () renaming (_↑⋆_ to _↑⋆₁_; _/_ to _/₁_) open Lifted lift₂ using () renaming (_↑⋆_ to _↑⋆₂_; _/_ to _/₂_) in ∀ {n k} (ρ₁ : Sub T₁ n k) (ρ₂ : Sub T₂ n k) → (∀ i x → (simpl (mvar x)) /₁ ρ₁ ↑⋆₁ i ≡ (simpl (mvar x)) /₂ ρ₂ ↑⋆₂ i) → ∀ i a → a /₁ ρ₁ ↑⋆₁ i ≡ a /₂ ρ₂ ↑⋆₂ i /-↑⋆ ρ₁ ρ₂ hyp i a = /✶-↑✶ (ρ₁ ◅ ε) (ρ₂ ◅ ε) hyp i a -- weakening a simple type gives a simple type simpl-wk : ∀ {ν} k (τ : MetaSType (k N+ ν)) → ∃ λ τ' → (simpl τ) / wk ↑⋆ k ≡ simpl τ' simpl-wk k (tc x) = , refl simpl-wk k (mvar n) = , var-/-wk-↑⋆ k n simpl-wk k (tvar n) = , refl simpl-wk k (x →' x₁) = , refl tclosed-wk : ∀ {ν m} {a : MetaType m} → TClosed ν a → TClosed (suc ν) a tclosed-wk (a ⇒ b) = tclosed-wk a ⇒ tclosed-wk b tclosed-wk (∀' x) = ∀' (tclosed-wk x) tclosed-wk (simpl x) = simpl $ tclosed-wks x where tclosed-wks : ∀ {ν m} {τ : MetaSType m} → TClosedS ν τ → TClosedS (suc ν) τ tclosed-wks (tvar p) = tvar (≤-steps 1 p) tclosed-wks mvar = mvar tclosed-wks (a →' b) = (tclosed-wk a) →' (tclosed-wk b) tclosed-wks tc = tc -- proper substitution doesn't affect the number of tvars tclosed-/ : ∀ {m m' n} (a : MetaType m) {σ : Sub MetaType m m'} → TClosed n a → (∀ i → TClosed n (lookup i σ)) → TClosed n (a / σ) tclosed-/ (a ⇒ b) (ca ⇒ cb) f = tclosed-/ a ca f ⇒ tclosed-/ b cb f tclosed-/ (∀' a) (∀' x) f = ∀' (tclosed-/ a x (λ p → tclosed-wk (f p))) tclosed-/ (simpl x) (simpl y) f = tclosed-/s x y f where tclosed-/s : ∀ {m m' n} (a : MetaSType m) {σ : Sub MetaType m m'} → TClosedS n a → (∀ i → TClosed n (lookup i σ)) → TClosed n (a simple/ σ) tclosed-/s (tvar _) (tvar p) f = simpl (tvar p) tclosed-/s (mvar i) _ f = f i tclosed-/s (a →' b) (ca →' cb) f = simpl (tclosed-/ a ca f →' tclosed-/ b cb f) tclosed-/s (tc c) _ _ = simpl tc -- opening any free tvar will reduce the number of free tvars tclosed-open : ∀ {m ν} {a : MetaType m} k → k N< (suc ν) → TClosed (suc ν) a → TClosed ν (open-meta k a) tclosed-open k k<ν (a ⇒ b) = (tclosed-open k k<ν a) ⇒ (tclosed-open k k<ν b) tclosed-open k k<ν (∀' a) = ∀' (tclosed-open (suc k) (s≤s k<ν) a) tclosed-open k k<ν (simpl (tvar {x = x} p)) with Nat.compare x k tclosed-open .(suc (k' N+ k)) (s≤s k<ν) (simpl (tvar p)) | less k' k = simpl (tvar (≤-trans (m≤m+n (suc k') k) k<ν)) tclosed-open x k<ν (simpl (tvar x₁)) | equal .x = simpl mvar tclosed-open m k<ν (simpl (tvar (s≤s p))) | greater .m k = simpl (tvar p) tclosed-open k k<ν (simpl mvar) = simpl mvar tclosed-open k k<ν (simpl (x →' x₁)) = simpl (tclosed-open k k<ν x →' tclosed-open k k<ν x₁) tclosed-open k k<ν (simpl tc) = simpl tc open-meta-◁m₁ : ∀ {m k} (a : MetaType m) → (open-meta k a) ◁m₁ ≡ a ◁m₁ open-meta-◁m₁ (a ⇒ b) = open-meta-◁m₁ b open-meta-◁m₁ (∀' a) = cong suc (open-meta-◁m₁ a) open-meta-◁m₁ (simpl x) = refl lem : ∀ {m} n k (a : MetaType m) → open-meta n (open-meta (n N+ suc k) a) H.≅ open-meta (n N+ k) (open-meta n a) lem n k (a ⇒ b) = H.cong₂ _⇒_ (lem n k a) (lem n k b) lem n k (∀' a) = H.cong ∀' (lem _ _ a) lem n k (simpl (tvar x)) with Nat.compare x (n N+ (suc k)) lem n k (simpl (tvar x)) | z = {!z!} lem n k (simpl (mvar x)) = H.refl lem n k (simpl (a →' b)) = H.cong₂ (λ u v → simpl (u →' v)) (lem n k a) (lem n k b) lem n k (simpl (tc x)) = H.refl open-meta-◁m : ∀ {m} k (a : MetaType m) → ((open-meta k a) ◁m) H.≅ open-meta k (a ◁m) open-meta-◁m k (a ⇒ b) = open-meta-◁m k b open-meta-◁m k (∀' a) = HR.begin open-meta zero ((open-meta (suc k)) a ◁m) HR.≅⟨ {!!} ⟩ open-meta zero (open-meta (suc k) (a ◁m)) HR.≅⟨ lem zero k (a ◁m) ⟩ open-meta k (open-meta zero (a ◁m)) HR.∎ open-meta-◁m k (simpl x) = H.refl open import Implicits.Syntax.Type open import Implicits.Substitutions.Type as TS using () lem₁ : ∀ {ν} k (a : Type (k N+ suc ν)) (b : Type ν) → (to-meta (a TS./ (TS.sub b) TS.↑⋆ k)) ≡ (open-meta k (to-meta a) / sub (to-meta b)) lem₁ k (simpl (tc x)) b = refl lem₁ k (simpl (tvar n)) b with Nat.compare (toℕ n) k lem₁ k (simpl (tvar n)) b | z = {!!} lem₁ k (simpl (a →' b)) c = cong₂ (λ u v → simpl (u →' v)) (lem₁ k a c) (lem₁ k b c) lem₁ k (a ⇒ b) c = cong₂ _⇒_ (lem₁ k a c) (lem₁ k b c) lem₁ k (∀' a) b = cong ∀' (lem₁ (suc k) a b)
algebraic-stack_agda0000_doc_14048
{-# OPTIONS --universe-polymorphism #-} module Categories.Enriched where open import Categories.Category open import Categories.Monoidal -- moar
algebraic-stack_agda0000_doc_14049
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics open import lib.cubical.Square open import lib.types.Bool open import lib.types.Coproduct open import lib.types.FunctionSeq open import lib.types.Paths open import lib.types.Pointed open import lib.types.Span open import lib.types.Pushout open import lib.types.Sigma module lib.types.Smash where module _ {i j} (X : Ptd i) (Y : Ptd j) where ⊙∧-span : ⊙Span ⊙∧-span = ⊙span (X ⊙× Y) ⊙Bool (X ⊙⊔ Y) (⊔-rec (_, pt Y) (pt X ,_) , idp) (⊙⊔-fmap {Y = Y} ⊙cst ⊙cst) ∧-span : Span ∧-span = ⊙Span-to-Span ⊙∧-span abstract _∧_ : Type (lmax i j) _∧_ = Pushout ∧-span Smash = _∧_ module _ {i j} {X : Ptd i} {Y : Ptd j} where abstract smin : de⊙ X → de⊙ Y → Smash X Y smin x y = left (x , y) module _ {i j} (X : Ptd i) (Y : Ptd j) where _⊙∧_ = ptd (X ∧ Y) (smin (pt X) (pt Y)) ⊙Smash = _⊙∧_ module _ {i j} {X : Ptd i} {Y : Ptd j} where abstract smbasel : Smash X Y smbasel = right true smbaser : Smash X Y smbaser = right false smgluel : (x : de⊙ X) → smin x (pt Y) == smbasel smgluel x = glue (inl x) smgluer : (y : de⊙ Y) → smin (pt X) y == smbaser smgluer y = glue (inr y) ∧-norm-l-seq : (x : de⊙ X) → smin x (pt Y) =-= smin (pt X) (pt Y) ∧-norm-l-seq x = smgluel x ◃∙ ! (smgluel (pt X)) ◃∎ ∧-norm-l : (x : de⊙ X) → smin x (pt Y) == smin (pt X) (pt Y) ∧-norm-l x = ↯ (∧-norm-l-seq x) ∧-norm-r-seq : (y : de⊙ Y) → smin (pt X) y =-= smin (pt X) (pt Y) ∧-norm-r-seq y = smgluer y ◃∙ ! (smgluer (pt Y)) ◃∎ ∧-norm-r : (y : de⊙ Y) → smin (pt X) y == smin (pt X) (pt Y) ∧-norm-r y = ↯ (∧-norm-r-seq y) ∧-⊙inl : de⊙ Y → X ⊙→ ⊙Smash X Y ∧-⊙inl y = (λ x → smin x y) , smgluer y ∙ ! (smgluer (pt Y)) ∧-⊙inr : de⊙ X → Y ⊙→ ⊙Smash X Y ∧-⊙inr x = (λ y → smin x y) , smgluel x ∙ ! (smgluel (pt X)) ∧-glue-lr : smbasel == smbaser ∧-glue-lr = ! (smgluel (pt X)) ∙ smgluer (pt Y) ap-smin-l : {a b : de⊙ X} (p : a == b) → ap (λ x → smin x (pt Y)) p == smgluel a ∙ ! (smgluel b) ap-smin-l = ap-null-homotopic (λ x → smin x (pt Y)) smgluel ap-smin-r : {a b : de⊙ Y} (p : a == b) → ap (smin (pt X)) p == smgluer a ∙ ! (smgluer b) ap-smin-r = ap-null-homotopic (λ y → smin (pt X) y) smgluer module _ {i j} {X : Ptd i} {Y : Ptd j} where module SmashElim {k} {P : Smash X Y → Type k} (smin* : (x : de⊙ X) (y : de⊙ Y) → P (smin x y)) (smbasel* : P smbasel) (smbaser* : P smbaser) (smgluel* : (x : de⊙ X) → smin* x (pt Y) == smbasel* [ P ↓ smgluel x ]) (smgluer* : (y : de⊙ Y) → smin* (pt X) y == smbaser* [ P ↓ smgluer y ]) where -- It would be better to encapsulate the repetition in the following definitions in a -- private module as follows. Unfortunately, this is not possible when the smash -- datatype is declared abstract. {-private module M = PushoutElim (uncurry smin*) (Coprod-elim (λ _ → smbasel*) (λ _ → smbaser*)) (Coprod-elim smgluel* smgluer*)-} abstract f : (s : X ∧ Y) → P s f = PushoutElim.f (uncurry smin*) (Coprod-elim (λ _ → smbasel*) (λ _ → smbaser*)) (Coprod-elim smgluel* smgluer*) smin-β : ∀ x y → f (smin x y) ↦ smin* x y smin-β x y = PushoutElim.left-β (uncurry smin*) (Coprod-elim (λ _ → smbasel*) (λ _ → smbaser*)) (Coprod-elim smgluel* smgluer*) (x , y) {-# REWRITE smin-β #-} smbasel-β : f smbasel ↦ smbasel* smbasel-β = PushoutElim.right-β (uncurry smin*) (Coprod-elim (λ _ → smbasel*) (λ _ → smbaser*)) (Coprod-elim smgluel* smgluer*) true {-# REWRITE smbasel-β #-} smbaser-β : f smbaser ↦ smbaser* smbaser-β = PushoutElim.right-β (uncurry smin*) (Coprod-elim (λ _ → smbasel*) (λ _ → smbaser*)) (Coprod-elim smgluel* smgluer*) false {-# REWRITE smbaser-β #-} smgluel-β : ∀ (x : de⊙ X) → apd f (smgluel x) == smgluel* x smgluel-β = PushoutElim.glue-β (uncurry smin*) (Coprod-elim (λ _ → smbasel*) (λ _ → smbaser*)) (Coprod-elim smgluel* smgluer*) ∘ inl smgluer-β : ∀ (y : de⊙ Y) → apd f (smgluer y) == smgluer* y smgluer-β = PushoutElim.glue-β (uncurry smin*) (Coprod-elim (λ _ → smbasel*) (λ _ → smbaser*)) (Coprod-elim smgluel* smgluer*) ∘ inr Smash-elim = SmashElim.f module SmashRec {k} {C : Type k} (smin* : (x : de⊙ X) (y : de⊙ Y) → C) (smbasel* smbaser* : C) (smgluel* : (x : de⊙ X) → smin* x (pt Y) == smbasel*) (smgluer* : (y : de⊙ Y) → smin* (pt X) y == smbaser*) where -- It would be better to encapsulate the repetition in the following definitions in a -- private module as follows. Unfortunately, this is not possible when the smash -- datatype is declared abstract. {-private module M = PushoutRec {d = ∧-span X Y} (uncurry smin*) (Coprod-rec (λ _ → smbasel*) (λ _ → smbaser*)) (Coprod-elim smgluel* smgluer*)-} abstract f : X ∧ Y → C f = PushoutRec.f (uncurry smin*) (Coprod-elim (λ _ → smbasel*) (λ _ → smbaser*)) (Coprod-elim smgluel* smgluer*) smin-β : ∀ x y → f (smin x y) ↦ smin* x y smin-β x y = PushoutRec.left-β {d = ∧-span X Y} (uncurry smin*) (Coprod-rec (λ _ → smbasel*) (λ _ → smbaser*)) (Coprod-elim smgluel* smgluer*) (x , y) {-# REWRITE smin-β #-} smbasel-β : f smbasel ↦ smbasel* smbasel-β = PushoutRec.right-β {d = ∧-span X Y} (uncurry smin*) (Coprod-rec (λ _ → smbasel*) (λ _ → smbaser*)) (Coprod-elim smgluel* smgluer*) true {-# REWRITE smbasel-β #-} smbaser-β : f smbaser ↦ smbaser* smbaser-β = PushoutRec.right-β {d = ∧-span X Y} (uncurry smin*) (Coprod-rec (λ _ → smbasel*) (λ _ → smbaser*)) (Coprod-elim smgluel* smgluer*) false {-# REWRITE smbaser-β #-} smgluel-β : ∀ (x : de⊙ X) → ap f (smgluel x) == smgluel* x smgluel-β = PushoutRec.glue-β (uncurry smin*) (Coprod-rec (λ _ → smbasel*) (λ _ → smbaser*)) (Coprod-elim smgluel* smgluer*) ∘ inl smgluer-β : ∀ (y : de⊙ Y) → ap f (smgluer y) == smgluer* y smgluer-β = PushoutRec.glue-β (uncurry smin*) (Coprod-rec (λ _ → smbasel*) (λ _ → smbaser*)) (Coprod-elim smgluel* smgluer*) ∘ inr ∧-norm-l-β : ∀ (x : de⊙ X) → ap f (∧-norm-l x) == smgluel* x ∙ ! (smgluel* (pt X)) ∧-norm-l-β x = ap f (∧-norm-l x) =⟨ ap-∙ f (smgluel x) (! (smgluel (pt X))) ⟩ ap f (smgluel x) ∙ ap f (! (smgluel (pt X))) =⟨ ap2 _∙_ (smgluel-β x) (ap-! f (smgluel (pt X)) ∙ ap ! (smgluel-β (pt X))) ⟩ smgluel* x ∙ ! (smgluel* (pt X)) =∎ ∧-norm-r-β : ∀ (y : de⊙ Y) → ap f (∧-norm-r y) == smgluer* y ∙ ! (smgluer* (pt Y)) ∧-norm-r-β y = ap f (∧-norm-r y) =⟨ ap-∙ f (smgluer y) (! (smgluer (pt Y))) ⟩ ap f (smgluer y) ∙ ap f (! (smgluer (pt Y))) =⟨ ap2 _∙_ (smgluer-β y) (ap-! f (smgluer (pt Y)) ∙ ap ! (smgluer-β (pt Y))) ⟩ smgluer* y ∙ ! (smgluer* (pt Y)) =∎ Smash-rec = SmashRec.f module SmashPathOverElim {k} {P : Smash X Y → Type k} (g₁ g₂ : (xy : Smash X Y) → P xy) (smin* : (x : de⊙ X) (y : de⊙ Y) → g₁ (smin x y) == g₂ (smin x y)) (smbasel* : g₁ smbasel == g₂ smbasel) (smbaser* : g₁ smbaser == g₂ smbaser) (smgluel* : (x : de⊙ X) → smin* x (pt Y) ◃ apd g₂ (smgluel x) == apd g₁ (smgluel x) ▹ smbasel*) (smgluer* : (y : de⊙ Y) → smin* (pt X) y ◃ apd g₂ (smgluer y) == apd g₁ (smgluer y) ▹ smbaser*) where f : g₁ ∼ g₂ f = Smash-elim {P = λ xy → g₁ xy == g₂ xy} smin* smbasel* smbaser* (λ x → ↓-=-in (smgluel* x)) (λ y → ↓-=-in (smgluer* y)) Smash-PathOver-elim = SmashPathOverElim.f module SmashPathElim {k} {C : Type k} (g₁ g₂ : Smash X Y → C) (smin* : (x : de⊙ X) (y : de⊙ Y) → g₁ (smin x y) == g₂ (smin x y)) (smbasel* : g₁ smbasel == g₂ smbasel) (smbaser* : g₁ smbaser == g₂ smbaser) (smgluel* : (x : de⊙ X) → Square (smin* x (pt Y)) (ap g₁ (smgluel x)) (ap g₂ (smgluel x)) smbasel*) (smgluer* : (y : de⊙ Y) → Square (smin* (pt X) y) (ap g₁ (smgluer y)) (ap g₂ (smgluer y)) smbaser*) where f : g₁ ∼ g₂ f = Smash-elim {P = λ xy → g₁ xy == g₂ xy} smin* smbasel* smbaser* (λ x → ↓-='-from-square (smgluel* x)) (λ y → ↓-='-from-square (smgluer* y)) Smash-Path-elim = SmashPathElim.f module _ {i j k l} {X : Ptd i} {Y : Ptd j} {X' : Ptd k} {Y' : Ptd l} (f : X ⊙→ X') (g : Y ⊙→ Y') where private module M = SmashRec {C = X' ∧ Y'} (λ x y → smin (fst f x) (fst g y)) (smin (pt X') (pt Y')) (smin (pt X') (pt Y')) (λ x → ap (λ y' → smin (fst f x) y') (snd g) ∙ ∧-norm-l (fst f x)) (λ y → ap (λ x' → smin x' (fst g y)) (snd f) ∙ ∧-norm-r (fst g y)) abstract ∧-fmap : X ∧ Y → X' ∧ Y' ∧-fmap = M.f ∧-fmap-smin-β : ∀ x y → ∧-fmap (smin x y) ↦ smin (fst f x) (fst g y) ∧-fmap-smin-β = M.smin-β {-# REWRITE ∧-fmap-smin-β #-} ∧-fmap-smbasel-β : ∧-fmap smbasel ↦ smin (pt X') (pt Y') ∧-fmap-smbasel-β = M.smbasel-β {-# REWRITE ∧-fmap-smbasel-β #-} ∧-fmap-smbaser-β : ∧-fmap smbaser ↦ smin (pt X') (pt Y') ∧-fmap-smbaser-β = M.smbaser-β {-# REWRITE ∧-fmap-smbaser-β #-} ∧-fmap-smgluel-β' : ∀ x → ap ∧-fmap (smgluel x) == ap (λ y' → smin (fst f x) y') (snd g) ∙ ∧-norm-l (fst f x) ∧-fmap-smgluel-β' x = M.smgluel-β x ∧-fmap-smgluer-β' : ∀ y → ap ∧-fmap (smgluer y) == ap (λ x' → smin x' (fst g y)) (snd f) ∙ ∧-norm-r (fst g y) ∧-fmap-smgluer-β' = M.smgluer-β ∧-fmap-smgluel-β : ∀ x → ap ∧-fmap (smgluel x) ◃∎ =ₛ ap (λ y' → smin (fst f x) y') (snd g) ◃∙ ∧-norm-l (fst f x) ◃∎ ∧-fmap-smgluel-β x = =ₛ-in (∧-fmap-smgluel-β' x) ∧-fmap-smgluer-β : ∀ y → ap ∧-fmap (smgluer y) ◃∎ =ₛ ap (λ x' → smin x' (fst g y)) (snd f) ◃∙ ∧-norm-r (fst g y) ◃∎ ∧-fmap-smgluer-β y = =ₛ-in (∧-fmap-smgluer-β' y) ⊙∧-fmap : X ⊙∧ Y ⊙→ X' ⊙∧ Y' ⊙∧-fmap = ∧-fmap , ap2 smin (snd f) (snd g) ∧-fmap-norm-l : ∀ x → ap ∧-fmap (∧-norm-l x) ◃∎ =ₛ ap (λ y' → smin (fst f x) y') (snd g) ◃∙ smgluel (fst f x) ◃∙ ! (smgluel (fst f (pt X))) ◃∙ ! (ap (smin (fst f (pt X))) (snd g)) ◃∎ ∧-fmap-norm-l x = ap ∧-fmap (∧-norm-l x) ◃∎ =ₛ⟨ ap-seq-∙ ∧-fmap (∧-norm-l-seq x) ⟩ ap ∧-fmap (smgluel x) ◃∙ ap ∧-fmap (! (smgluel (pt X))) ◃∎ =ₛ₁⟨ 1 & 1 & ap-! ∧-fmap (smgluel (pt X)) ⟩ ap ∧-fmap (smgluel x) ◃∙ ! (ap ∧-fmap (smgluel (pt X))) ◃∎ =ₛ⟨ 0 & 1 & ∧-fmap-smgluel-β x ⟩ ap (smin (fst f x)) (snd g) ◃∙ ∧-norm-l (fst f x) ◃∙ ! (ap ∧-fmap (smgluel (pt X))) ◃∎ =ₛ⟨ 2 & 1 & !-=ₛ (∧-fmap-smgluel-β (pt X)) ⟩ ap (smin (fst f x)) (snd g) ◃∙ ∧-norm-l (fst f x) ◃∙ ! (∧-norm-l (fst f (pt X))) ◃∙ ! (ap (smin (fst f (pt X))) (snd g)) ◃∎ =ₛ⟨ 2 & 1 & !-=ₛ (expand (∧-norm-l-seq (fst f (pt X)))) ⟩ ap (smin (fst f x)) (snd g) ◃∙ ∧-norm-l (fst f x) ◃∙ ! (! (smgluel (pt X'))) ◃∙ ! (smgluel (fst f (pt X))) ◃∙ ! (ap (smin (fst f (pt X))) (snd g)) ◃∎ =ₛ⟨ 1 & 1 & expand (∧-norm-l-seq (fst f x)) ⟩ ap (smin (fst f x)) (snd g) ◃∙ smgluel (fst f x) ◃∙ ! (smgluel (pt X')) ◃∙ ! (! (smgluel (pt X'))) ◃∙ ! (smgluel (fst f (pt X))) ◃∙ ! (ap (smin (fst f (pt X))) (snd g)) ◃∎ =ₛ⟨ 2 & 2 & seq-!-inv-r (! (smgluel (pt X')) ◃∎) ⟩ ap (smin (fst f x)) (snd g) ◃∙ smgluel (fst f x) ◃∙ ! (smgluel (fst f (pt X))) ◃∙ ! (ap (smin (fst f (pt X))) (snd g)) ◃∎ ∎ₛ ∧-fmap-norm-r : ∀ y → ap ∧-fmap (∧-norm-r y) ◃∎ =ₛ ap (λ x' → smin x' (fst g y)) (snd f) ◃∙ smgluer (fst g y) ◃∙ ! (smgluer (fst g (pt Y))) ◃∙ ! (ap (λ x' → smin x' (fst g (pt Y))) (snd f)) ◃∎ ∧-fmap-norm-r y = ap ∧-fmap (∧-norm-r y) ◃∎ =ₛ⟨ ap-seq-∙ ∧-fmap (∧-norm-r-seq y) ⟩ ap ∧-fmap (smgluer y) ◃∙ ap ∧-fmap (! (smgluer (pt Y))) ◃∎ =ₛ₁⟨ 1 & 1 & ap-! ∧-fmap (smgluer (pt Y)) ⟩ ap ∧-fmap (smgluer y) ◃∙ ! (ap ∧-fmap (smgluer (pt Y))) ◃∎ =ₛ⟨ 0 & 1 & ∧-fmap-smgluer-β y ⟩ ap (λ x' → smin x' (fst g y)) (snd f) ◃∙ ∧-norm-r (fst g y) ◃∙ ! (ap ∧-fmap (smgluer (pt Y))) ◃∎ =ₛ⟨ 2 & 1 & !-=ₛ (∧-fmap-smgluer-β (pt Y)) ⟩ ap (λ x' → smin x' (fst g y)) (snd f) ◃∙ ∧-norm-r (fst g y) ◃∙ ! (∧-norm-r (fst g (pt Y))) ◃∙ ! (ap (λ x' → smin x' (fst g (pt Y))) (snd f)) ◃∎ =ₛ⟨ 2 & 1 & !-=ₛ (expand (∧-norm-r-seq (fst g (pt Y)))) ⟩ ap (λ x' → smin x' (fst g y)) (snd f) ◃∙ ∧-norm-r (fst g y) ◃∙ ! (! (smgluer (pt Y'))) ◃∙ ! (smgluer (fst g (pt Y))) ◃∙ ! (ap (λ x' → smin x' (fst g (pt Y))) (snd f)) ◃∎ =ₛ⟨ 1 & 1 & expand (∧-norm-r-seq (fst g y)) ⟩ ap (λ x' → smin x' (fst g y)) (snd f) ◃∙ smgluer (fst g y) ◃∙ ! (smgluer (pt Y')) ◃∙ ! (! (smgluer (pt Y'))) ◃∙ ! (smgluer (fst g (pt Y))) ◃∙ ! (ap (λ x → smin x (fst g (pt Y))) (snd f)) ◃∎ =ₛ⟨ 2 & 2 & seq-!-inv-r (! (smgluer (pt Y')) ◃∎) ⟩ ap (λ x' → smin x' (fst g y)) (snd f) ◃∙ smgluer (fst g y) ◃∙ ! (smgluer (fst g (pt Y))) ◃∙ ! (ap (λ x' → smin x' (fst g (pt Y))) (snd f)) ◃∎ ∎ₛ module _ {i i' i'' j j' j''} {X : Ptd i} {X' : Ptd i'} {X'' : Ptd i''} (f : X ⊙→ X') (f' : X' ⊙→ X'') {Y : Ptd j} {Y' : Ptd j'} {Y'' : Ptd j''} (g : Y ⊙→ Y') (g' : Y' ⊙→ Y'') where ∧-fmap-comp : ∀ xy → ∧-fmap (f' ⊙∘ f) (g' ⊙∘ g) xy == ∧-fmap f' g' (∧-fmap f g xy) ∧-fmap-comp = Smash-elim {X = X} {Y = Y} {P = λ xy → ∧-fmap (f' ⊙∘ f) (g' ⊙∘ g) xy == ∧-fmap f' g' (∧-fmap f g xy)} (λ x y → idp) (! (ap2 smin (snd f') (snd g'))) (! (ap2 smin (snd f') (snd g'))) (λ x → ↓-='-in-=ₛ $ idp ◃∙ ap (∧-fmap f' g' ∘ ∧-fmap f g) (smgluel x) ◃∎ =ₛ⟨ 0 & 1 & expand [] ⟩ ap (∧-fmap f' g' ∘ ∧-fmap f g) (smgluel x) ◃∎ =ₛ₁⟨ ap-∘ (∧-fmap f' g') (∧-fmap f g) (smgluel x) ⟩ ap (∧-fmap f' g') (ap (∧-fmap f g) (smgluel x)) ◃∎ =ₛ⟨ ap-seq-=ₛ (∧-fmap f' g') (∧-fmap-smgluel-β f g x) ⟩ ap (∧-fmap f' g') (ap (smin (fst f x)) (snd g)) ◃∙ ap (∧-fmap f' g') (∧-norm-l (fst f x)) ◃∎ =ₛ₁⟨ 0 & 1 & ∘-ap (∧-fmap f' g') (smin (fst f x)) (snd g) ⟩ ap (smin (fst (f' ⊙∘ f) x) ∘ fst g') (snd g) ◃∙ ap (∧-fmap f' g') (∧-norm-l (fst f x)) ◃∎ =ₛ⟨ 1 & 1 & ∧-fmap-norm-l f' g' (fst f x) ⟩ ap (smin (fst (f' ⊙∘ f) x) ∘ fst g') (snd g) ◃∙ ap (smin (fst (f' ⊙∘ f) x)) (snd g') ◃∙ smgluel (fst (f' ⊙∘ f) x) ◃∙ ! (smgluel (fst f' (pt X'))) ◃∙ ! (ap (smin (fst f' (pt X'))) (snd g')) ◃∎ =ₛ₁⟨ 0 & 1 & ap-∘ (smin (fst (f' ⊙∘ f) x)) (fst g') (snd g) ⟩ ap (smin (fst (f' ⊙∘ f) x)) (ap (fst g') (snd g)) ◃∙ ap (smin (fst (f' ⊙∘ f) x)) (snd g') ◃∙ smgluel (fst (f' ⊙∘ f) x) ◃∙ ! (smgluel (fst f' (pt X'))) ◃∙ ! (ap (smin (fst f' (pt X'))) (snd g')) ◃∎ =ₛ⟨ 0 & 2 & ∙-ap-seq (smin (fst (f' ⊙∘ f) x)) (ap (fst g') (snd g) ◃∙ snd g' ◃∎) ⟩ ap (smin (fst f' (fst f x))) (snd (g' ⊙∘ g)) ◃∙ smgluel (fst (f' ⊙∘ f) x) ◃∙ ! (smgluel (fst f' (pt X'))) ◃∙ ! (ap (smin (fst f' (pt X'))) (snd g')) ◃∎ =ₛ⟨ 3 & 0 & !ₛ (seq-!-inv-r (ap (λ x'' → smin x'' (pt Y'')) (snd f') ◃∎)) ⟩ ap (smin (fst f' (fst f x))) (snd (g' ⊙∘ g)) ◃∙ smgluel (fst (f' ⊙∘ f) x) ◃∙ ! (smgluel (fst f' (pt X'))) ◃∙ ap (λ x'' → smin x'' (pt Y'')) (snd f') ◃∙ ! (ap (λ x'' → smin x'' (pt Y'')) (snd f')) ◃∙ ! (ap (smin (fst f' (pt X'))) (snd g')) ◃∎ =ₛ⟨ 4 & 2 & !ₛ $ !-=ₛ $ ap2-out' smin (snd f') (snd g') ⟩ ap (smin (fst f' (fst f x))) (snd (g' ⊙∘ g)) ◃∙ smgluel (fst (f' ⊙∘ f) x) ◃∙ ! (smgluel (fst f' (pt X'))) ◃∙ ap (λ x'' → smin x'' (pt Y'')) (snd f') ◃∙ ! (ap2 smin (snd f') (snd g')) ◃∎ =ₛ⟨ 3 & 1 & =ₛ-in {t = smgluel (fst f' (pt X')) ◃∙ ! (smgluel (pt X'')) ◃∎} $ ap-null-homotopic (λ x'' → smin x'' (pt Y'')) smgluel (snd f') ⟩ ap (smin (fst f' (fst f x))) (snd (g' ⊙∘ g)) ◃∙ smgluel (fst (f' ⊙∘ f) x) ◃∙ ! (smgluel (fst f' (pt X'))) ◃∙ smgluel (fst f' (pt X')) ◃∙ ! (smgluel (pt X'')) ◃∙ ! (ap2 smin (snd f') (snd g')) ◃∎ =ₛ⟨ 2 & 2 & seq-!-inv-l (smgluel (fst f' (pt X')) ◃∎) ⟩ ap (smin (fst f' (fst f x))) (snd (g' ⊙∘ g)) ◃∙ smgluel (fst (f' ⊙∘ f) x) ◃∙ ! (smgluel (pt X'')) ◃∙ ! (ap2 smin (snd f') (snd g')) ◃∎ =ₛ⟨ 1 & 2 & contract ⟩ ap (smin (fst f' (fst f x))) (snd (g' ⊙∘ g)) ◃∙ ∧-norm-l (fst (f' ⊙∘ f) x) ◃∙ ! (ap2 smin (snd f') (snd g')) ◃∎ =ₛ⟨ 0 & 2 & !ₛ (∧-fmap-smgluel-β (f' ⊙∘ f) (g' ⊙∘ g) x) ⟩ ap (∧-fmap (f' ⊙∘ f) (g' ⊙∘ g)) (smgluel x) ◃∙ ! (ap2 smin (snd f') (snd g')) ◃∎ ∎ₛ) (λ y → ↓-='-in-=ₛ $ idp ◃∙ ap (∧-fmap f' g' ∘ ∧-fmap f g) (smgluer y) ◃∎ =ₛ⟨ 0 & 1 & expand [] ⟩ ap (∧-fmap f' g' ∘ ∧-fmap f g) (smgluer y) ◃∎ =ₛ₁⟨ ap-∘ (∧-fmap f' g') (∧-fmap f g) (smgluer y) ⟩ ap (∧-fmap f' g') (ap (∧-fmap f g) (smgluer y)) ◃∎ =ₛ⟨ ap-seq-=ₛ (∧-fmap f' g') (∧-fmap-smgluer-β f g y) ⟩ ap (∧-fmap f' g') (ap (λ x' → smin x' (fst g y)) (snd f)) ◃∙ ap (∧-fmap f' g') (∧-norm-r (fst g y)) ◃∎ =ₛ₁⟨ 0 & 1 & ∘-ap (∧-fmap f' g') (λ x' → smin x' (fst g y)) (snd f) ⟩ ap (λ x' → smin (fst f' x') (fst (g' ⊙∘ g) y)) (snd f) ◃∙ ap (∧-fmap f' g') (∧-norm-r (fst g y)) ◃∎ =ₛ⟨ 1 & 1 & ∧-fmap-norm-r f' g' (fst g y) ⟩ ap (λ x' → smin (fst f' x') (fst (g' ⊙∘ g) y)) (snd f) ◃∙ ap (λ x'' → smin x'' (fst (g' ⊙∘ g) y)) (snd f') ◃∙ smgluer (fst (g' ⊙∘ g) y) ◃∙ ! (smgluer (fst g' (pt Y'))) ◃∙ ! (ap (λ x' → smin x' (fst g' (pt Y'))) (snd f')) ◃∎ =ₛ₁⟨ 0 & 1 & ap-∘ (λ x'' → smin x'' (fst (g' ⊙∘ g) y)) (fst f') (snd f) ⟩ ap (λ x'' → smin x'' (fst (g' ⊙∘ g) y)) (ap (fst f') (snd f)) ◃∙ ap (λ x'' → smin x'' (fst (g' ⊙∘ g) y)) (snd f') ◃∙ smgluer (fst (g' ⊙∘ g) y) ◃∙ ! (smgluer (fst g' (pt Y'))) ◃∙ ! (ap (λ x' → smin x' (fst g' (pt Y'))) (snd f')) ◃∎ =ₛ⟨ 0 & 2 & ∙-ap-seq (λ x'' → smin x'' (fst (g' ⊙∘ g) y)) (ap (fst f') (snd f) ◃∙ snd f' ◃∎) ⟩ ap (λ x'' → smin x'' (fst (g' ⊙∘ g) y)) (snd (f' ⊙∘ f)) ◃∙ smgluer (fst (g' ⊙∘ g) y) ◃∙ ! (smgluer (fst g' (pt Y'))) ◃∙ ! (ap (λ x' → smin x' (fst g' (pt Y'))) (snd f')) ◃∎ =ₛ⟨ 3 & 0 & !ₛ (seq-!-inv-r (ap (smin (pt X'')) (snd g') ◃∎)) ⟩ ap (λ x'' → smin x'' (fst (g' ⊙∘ g) y)) (snd (f' ⊙∘ f)) ◃∙ smgluer (fst (g' ⊙∘ g) y) ◃∙ ! (smgluer (fst g' (pt Y'))) ◃∙ ap (smin (pt X'')) (snd g') ◃∙ ! (ap (smin (pt X'')) (snd g')) ◃∙ ! (ap (λ x' → smin x' (fst g' (pt Y'))) (snd f')) ◃∎ =ₛ⟨ 4 & 2 & !ₛ $ !-=ₛ $ ap2-out smin (snd f') (snd g') ⟩ ap (λ x'' → smin x'' (fst (g' ⊙∘ g) y)) (snd (f' ⊙∘ f)) ◃∙ smgluer (fst (g' ⊙∘ g) y) ◃∙ ! (smgluer (fst g' (pt Y'))) ◃∙ ap (smin (pt X'')) (snd g') ◃∙ ! (ap2 smin (snd f') (snd g')) ◃∎ =ₛ⟨ 3 & 1 & =ₛ-in {t = smgluer (fst g' (pt Y')) ◃∙ ! (smgluer (pt Y'')) ◃∎} $ ap-null-homotopic (smin (pt X'')) smgluer (snd g') ⟩ ap (λ x'' → smin x'' (fst (g' ⊙∘ g) y)) (snd (f' ⊙∘ f)) ◃∙ smgluer (fst (g' ⊙∘ g) y) ◃∙ ! (smgluer (fst g' (pt Y'))) ◃∙ smgluer (fst g' (pt Y')) ◃∙ ! (smgluer (pt Y'')) ◃∙ ! (ap2 smin (snd f') (snd g')) ◃∎ =ₛ⟨ 2 & 2 & seq-!-inv-l (smgluer (fst g' (pt Y')) ◃∎) ⟩ ap (λ x'' → smin x'' (fst (g' ⊙∘ g) y)) (snd (f' ⊙∘ f)) ◃∙ smgluer (fst (g' ⊙∘ g) y) ◃∙ ! (smgluer (pt Y'')) ◃∙ ! (ap2 smin (snd f') (snd g')) ◃∎ =ₛ⟨ 1 & 2 & contract ⟩ ap (λ x'' → smin x'' (fst (g' ⊙∘ g) y)) (snd (f' ⊙∘ f)) ◃∙ ∧-norm-r (fst (g' ⊙∘ g) y) ◃∙ ! (ap2 smin (snd f') (snd g')) ◃∎ =ₛ⟨ 0 & 2 & !ₛ (∧-fmap-smgluer-β (f' ⊙∘ f) (g' ⊙∘ g) y) ⟩ ap (∧-fmap (f' ⊙∘ f) (g' ⊙∘ g)) (smgluer y) ◃∙ ! (ap2 smin (snd f') (snd g')) ◃∎ ∎ₛ) module _ {i j} {X : Ptd i} {Y : Ptd j} where ×-to-∧ : de⊙ X × de⊙ Y → X ∧ Y ×-to-∧ (x , y) = smin x y ×-⊙to-∧ : X ⊙× Y ⊙→ X ⊙∧ Y ×-⊙to-∧ = ×-to-∧ , idp module _ {i j} (X : Ptd i) (Y : Ptd j) where module SmashSwap = SmashRec {X = X} {Y = Y} {C = Y ∧ X} (λ x y → smin y x) (smin (pt Y) (pt X)) (smin (pt Y) (pt X)) ∧-norm-r ∧-norm-l ∧-swap : X ∧ Y → Y ∧ X ∧-swap = SmashSwap.f ⊙∧-swap : X ⊙∧ Y ⊙→ Y ⊙∧ X ⊙∧-swap = ∧-swap , idp ∧-swap-norm-l-β : ∀ x → ap ∧-swap (∧-norm-l x) == ∧-norm-r x ∧-swap-norm-l-β x = ap ∧-swap (∧-norm-l x) =⟨ SmashSwap.∧-norm-l-β x ⟩ ∧-norm-r x ∙ ! (∧-norm-r (pt X)) =⟨ ap (λ u → ∧-norm-r x ∙ ! u) (!-inv-r (smgluer (pt X))) ⟩ ∧-norm-r x ∙ idp =⟨ ∙-unit-r (∧-norm-r x) ⟩ ∧-norm-r x =∎ ∧-swap-norm-r-β : ∀ y → ap ∧-swap (∧-norm-r y) == ∧-norm-l y ∧-swap-norm-r-β y = ap ∧-swap (∧-norm-r y) =⟨ SmashSwap.∧-norm-r-β y ⟩ ∧-norm-l y ∙ ! (∧-norm-l (pt Y)) =⟨ ap (λ u → ∧-norm-l y ∙ ! u) (!-inv-r (smgluel (pt Y))) ⟩ ∧-norm-l y ∙ idp =⟨ ∙-unit-r (∧-norm-l y) ⟩ ∧-norm-l y =∎ ×-to-∧-swap : ∧-swap ∘ ×-to-∧ ∼ ×-to-∧ ∘ ×-swap ×-to-∧-swap (x , y) = idp ×-⊙to-∧-swap : ⊙∧-swap ◃⊙∘ ×-⊙to-∧ ◃⊙idf =⊙∘ ×-⊙to-∧ ◃⊙∘ ⊙×-swap ◃⊙idf ×-⊙to-∧-swap = =⊙∘-in $ ⊙λ=' ×-to-∧-swap idp module _ {i j} (X : Ptd i) (Y : Ptd j) where module SmashSwapInvolutive = SmashElim {X = X} {Y = Y} {P = λ xy → ∧-swap Y X (∧-swap X Y xy) == xy} (λ x y → idp) (smgluel (pt X)) (smgluer (pt Y)) (λ x → ↓-app=idf-in $ ! $ ap (∧-swap Y X ∘ ∧-swap X Y) (smgluel x) ∙ smgluel (pt X) =⟨ ap (_∙ smgluel (pt X)) $ ap-∘ (∧-swap Y X) (∧-swap X Y) (smgluel x) ⟩ ap (∧-swap Y X) (ap (∧-swap X Y) (smgluel x)) ∙ smgluel (pt X) =⟨ ap (λ p → ap (∧-swap Y X) p ∙ smgluel (pt X)) $ SmashSwap.smgluel-β X Y x ⟩ ap (∧-swap Y X) (∧-norm-r x) ∙ smgluel (pt X) =⟨ ap (_∙ smgluel (pt X)) (∧-swap-norm-r-β Y X x) ⟩ ∧-norm-l x ∙ smgluel (pt X) =⟨ ∙-assoc (smgluel x) (! (smgluel (pt X))) (smgluel (pt X))⟩ smgluel x ∙ ! (smgluel (pt X)) ∙ smgluel (pt X) =⟨ ap (smgluel x ∙_) (!-inv-l (smgluel (pt X))) ⟩ smgluel x ∙ idp =⟨ ∙-unit-r (smgluel x) ⟩ smgluel x =⟨ ! (∙'-unit-l (smgluel x)) ⟩ idp ∙' smgluel x =∎) (λ y → ↓-app=idf-in $ ! $ ap (∧-swap Y X ∘ ∧-swap X Y) (smgluer y) ∙ smgluer (pt Y) =⟨ ap (_∙ smgluer (pt Y)) $ ap-∘ (∧-swap Y X) (∧-swap X Y) (smgluer y) ⟩ ap (∧-swap Y X) (ap (∧-swap X Y) (smgluer y)) ∙ smgluer (pt Y) =⟨ ap (λ p → ap (∧-swap Y X) p ∙ smgluer (pt Y)) $ SmashSwap.smgluer-β X Y y ⟩ ap (∧-swap Y X) (∧-norm-l y) ∙ smgluer (pt Y) =⟨ ap (_∙ smgluer (pt Y)) (∧-swap-norm-l-β Y X y) ⟩ ∧-norm-r y ∙ smgluer (pt Y) =⟨ ∙-assoc (smgluer y) (! (smgluer (pt Y))) (smgluer (pt Y)) ⟩ smgluer y ∙ ! (smgluer (pt Y)) ∙ smgluer (pt Y) =⟨ ap (smgluer y ∙_) (!-inv-l (smgluer (pt Y))) ⟩ smgluer y ∙ idp =⟨ ∙-unit-r (smgluer y) ⟩ smgluer y =⟨ ! (∙'-unit-l (smgluer y)) ⟩ idp ∙' smgluer y =∎) ∧-swap-inv : ∀ xy → ∧-swap Y X (∧-swap X Y xy) == xy ∧-swap-inv = SmashSwapInvolutive.f ⊙∧-swap-inv : ⊙∧-swap Y X ◃⊙∘ ⊙∧-swap X Y ◃⊙idf =⊙∘ ⊙idf-seq ⊙∧-swap-inv = =⊙∘-in (⊙λ=' ∧-swap-inv idp) module _ {i j} (X : Ptd i) (Y : Ptd j) where ∧-swap-is-equiv : is-equiv (∧-swap X Y) ∧-swap-is-equiv = is-eq _ (∧-swap Y X) (∧-swap-inv Y X) (∧-swap-inv X Y) ∧-swap-equiv : (X ∧ Y) ≃ (Y ∧ X) ∧-swap-equiv = ∧-swap X Y , ∧-swap-is-equiv module _ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'} (f : X ⊙→ X') (g : Y ⊙→ Y') where ∧-swap-naturality : ∀ xy → ∧-fmap g f (∧-swap X Y xy) == ∧-swap X' Y' (∧-fmap f g xy) ∧-swap-naturality = Smash-elim {X = X} {Y = Y} {P = λ xy → ∧-fmap g f (∧-swap X Y xy) == ∧-swap X' Y' (∧-fmap f g xy)} (λ x y → idp) (ap2 smin (snd g) (snd f)) (ap2 smin (snd g) (snd f)) (λ x → ↓-='-in-=ₛ $ idp ◃∙ ap (∧-swap X' Y' ∘ ∧-fmap f g) (smgluel x) ◃∎ =ₛ⟨ 0 & 1 & expand [] ⟩ ap (∧-swap X' Y' ∘ ∧-fmap f g) (smgluel x) ◃∎ =ₛ₁⟨ ap-∘ (∧-swap X' Y') (∧-fmap f g) (smgluel x) ⟩ ap (∧-swap X' Y') (ap (∧-fmap f g) (smgluel x)) ◃∎ =ₛ⟨ ap-seq-=ₛ (∧-swap X' Y') (∧-fmap-smgluel-β f g x) ⟩ ap (∧-swap X' Y') (ap (smin (fst f x)) (snd g)) ◃∙ ap (∧-swap X' Y') (∧-norm-l (fst f x)) ◃∎ =ₛ₁⟨ 0 & 1 & ∘-ap (∧-swap X' Y') (smin (fst f x)) (snd g) ⟩ ap (λ y' → smin y' (fst f x)) (snd g) ◃∙ ap (∧-swap X' Y') (∧-norm-l (fst f x)) ◃∎ =ₛ₁⟨ 1 & 1 & ∧-swap-norm-l-β X' Y' (fst f x) ⟩ ap (λ y' → smin y' (fst f x)) (snd g) ◃∙ ∧-norm-r (fst f x) ◃∎ =ₛ⟨ 1 & 1 & expand (∧-norm-r-seq (fst f x)) ⟩ ap (λ y' → smin y' (fst f x)) (snd g) ◃∙ smgluer (fst f x) ◃∙ ! (smgluer (pt X')) ◃∎ =ₛ⟨ 2 & 0 & !ₛ (seq-!-inv-l (smgluer (fst f (pt X)) ◃∎)) ⟩ ap (λ y' → smin y' (fst f x)) (snd g) ◃∙ smgluer (fst f x) ◃∙ ! (smgluer (fst f (pt X))) ◃∙ smgluer (fst f (pt X)) ◃∙ ! (smgluer (pt X')) ◃∎ =ₛ₁⟨ 3 & 2 & ! (ap-null-homotopic (smin (pt Y')) smgluer (snd f)) ⟩ ap (λ y' → smin y' (fst f x)) (snd g) ◃∙ smgluer (fst f x) ◃∙ ! (smgluer (fst f (pt X))) ◃∙ ap (smin (pt Y')) (snd f) ◃∎ =ₛ⟨ 3 & 0 & !ₛ (seq-!-inv-l (ap (λ y' → smin y' (fst f (pt X))) (snd g) ◃∎)) ⟩ ap (λ y' → smin y' (fst f x)) (snd g) ◃∙ smgluer (fst f x) ◃∙ ! (smgluer (fst f (pt X))) ◃∙ ! (ap (λ y' → smin y' (fst f (pt X))) (snd g)) ◃∙ ap (λ y' → smin y' (fst f (pt X))) (snd g) ◃∙ ap (smin (pt Y')) (snd f) ◃∎ =ₛ⟨ 4 & 2 & !ₛ (ap2-out smin (snd g) (snd f)) ⟩ ap (λ y' → smin y' (fst f x)) (snd g) ◃∙ smgluer (fst f x) ◃∙ ! (smgluer (fst f (pt X))) ◃∙ ! (ap (λ y' → smin y' (fst f (pt X))) (snd g)) ◃∙ ap2 smin (snd g) (snd f) ◃∎ =ₛ⟨ 0 & 4 & !ₛ (∧-fmap-norm-r g f x) ⟩ ap (∧-fmap g f) (∧-norm-r x) ◃∙ ap2 smin (snd g) (snd f) ◃∎ =ₛ₁⟨ 0 & 1 & ! (ap (ap (∧-fmap g f)) (SmashSwap.smgluel-β X Y x)) ⟩ ap (∧-fmap g f) (ap (∧-swap X Y) (smgluel x)) ◃∙ ap2 smin (snd g) (snd f) ◃∎ =ₛ₁⟨ 0 & 1 & ∘-ap (∧-fmap g f) (∧-swap X Y) (smgluel x) ⟩ ap (∧-fmap g f ∘ ∧-swap X Y) (smgluel x) ◃∙ ap2 smin (snd g) (snd f) ◃∎ ∎ₛ) (λ y → ↓-='-in-=ₛ $ idp ◃∙ ap (∧-swap X' Y' ∘ ∧-fmap f g) (smgluer y) ◃∎ =ₛ⟨ 0 & 1 & expand [] ⟩ ap (∧-swap X' Y' ∘ ∧-fmap f g) (smgluer y) ◃∎ =ₛ₁⟨ ap-∘ (∧-swap X' Y') (∧-fmap f g) (smgluer y) ⟩ ap (∧-swap X' Y') (ap (∧-fmap f g) (smgluer y)) ◃∎ =ₛ⟨ ap-seq-=ₛ (∧-swap X' Y') (∧-fmap-smgluer-β f g y) ⟩ ap (∧-swap X' Y') (ap (λ x' → smin x' (fst g y)) (snd f)) ◃∙ ap (∧-swap X' Y') (∧-norm-r (fst g y)) ◃∎ =ₛ₁⟨ 0 & 1 & ∘-ap (∧-swap X' Y') (λ x' → smin x' (fst g y)) (snd f) ⟩ ap (smin (fst g y)) (snd f) ◃∙ ap (∧-swap X' Y') (∧-norm-r (fst g y)) ◃∎ =ₛ₁⟨ 1 & 1 & ∧-swap-norm-r-β X' Y' (fst g y) ⟩ ap (smin (fst g y)) (snd f) ◃∙ ∧-norm-l (fst g y) ◃∎ =ₛ⟨ 1 & 1 & expand (∧-norm-l-seq (fst g y)) ⟩ ap (smin (fst g y)) (snd f) ◃∙ smgluel (fst g y) ◃∙ ! (smgluel (pt Y')) ◃∎ =ₛ⟨ 2 & 0 & !ₛ (seq-!-inv-l (smgluel (fst g (pt Y)) ◃∎)) ⟩ ap (smin (fst g y)) (snd f) ◃∙ smgluel (fst g y) ◃∙ ! (smgluel (fst g (pt Y))) ◃∙ smgluel (fst g (pt Y)) ◃∙ ! (smgluel (pt Y')) ◃∎ =ₛ₁⟨ 3 & 2 & ! (ap-null-homotopic (λ y' → smin y' (pt X')) smgluel (snd g)) ⟩ ap (smin (fst g y)) (snd f) ◃∙ smgluel (fst g y) ◃∙ ! (smgluel (fst g (pt Y))) ◃∙ ap (λ y' → smin y' (pt X')) (snd g) ◃∎ =ₛ⟨ 3 & 0 & !ₛ (seq-!-inv-l (ap (smin (fst g (pt Y))) (snd f) ◃∎)) ⟩ ap (smin (fst g y)) (snd f) ◃∙ smgluel (fst g y) ◃∙ ! (smgluel (fst g (pt Y))) ◃∙ ! (ap (smin (fst g (pt Y))) (snd f)) ◃∙ ap (smin (fst g (pt Y))) (snd f) ◃∙ ap (λ y' → smin y' (pt X')) (snd g) ◃∎ =ₛ⟨ 4 & 2 & !ₛ (ap2-out' smin (snd g) (snd f)) ⟩ ap (smin (fst g y)) (snd f) ◃∙ smgluel (fst g y) ◃∙ ! (smgluel (fst g (pt Y))) ◃∙ ! (ap (smin (fst g (pt Y))) (snd f)) ◃∙ ap2 smin (snd g) (snd f) ◃∎ =ₛ⟨ 0 & 4 & !ₛ (∧-fmap-norm-l g f y) ⟩ ap (∧-fmap g f) (∧-norm-l y) ◃∙ ap2 smin (snd g) (snd f) ◃∎ =ₛ₁⟨ 0 & 1 & ! (ap (ap (∧-fmap g f)) (SmashSwap.smgluer-β X Y y)) ⟩ ap (∧-fmap g f) (ap (∧-swap X Y) (smgluer y)) ◃∙ ap2 smin (snd g) (snd f) ◃∎ =ₛ₁⟨ 0 & 1 & ∘-ap (∧-fmap g f) (∧-swap X Y) (smgluer y) ⟩ ap (∧-fmap g f ∘ ∧-swap X Y) (smgluer y) ◃∙ ap2 smin (snd g) (snd f) ◃∎ ∎ₛ) ⊙∧-swap-naturality : ⊙∧-fmap g f ⊙∘ ⊙∧-swap X Y == ⊙∧-swap X' Y' ⊙∘ ⊙∧-fmap f g ⊙∧-swap-naturality = ⊙λ=' ∧-swap-naturality $ =ₛ-out $ ap2 smin (snd g) (snd f) ◃∎ =ₛ⟨ ap2-out smin (snd g) (snd f) ⟩ ap (λ u → smin u (fst f (pt X))) (snd g) ◃∙ ap (smin (pt Y')) (snd f) ◃∎ =ₛ⟨ !ₛ $ ap2-out' (λ x y → smin y x) (snd f) (snd g) ⟩ ap2 (λ x y → smin y x) (snd f) (snd g) ◃∎ =ₛ₁⟨ ! $ ap-ap2 (∧-swap X' Y') smin (snd f) (snd g) ⟩ ap (∧-swap X' Y') (ap2 smin (snd f) (snd g)) ◃∎ =ₛ⟨ 1 & 0 & contract ⟩ ap (∧-swap X' Y') (ap2 smin (snd f) (snd g)) ◃∙ idp ◃∎ ∎ₛ ∧-swap-fmap : ∀ xy → ∧-swap Y' X' (∧-fmap g f (∧-swap X Y xy)) == ∧-fmap f g xy ∧-swap-fmap xy = ∧-swap Y' X' (∧-fmap g f (∧-swap X Y xy)) =⟨ ap (∧-swap Y' X') (∧-swap-naturality xy) ⟩ ∧-swap Y' X' (∧-swap X' Y' (∧-fmap f g xy)) =⟨ ∧-swap-inv X' Y' (∧-fmap f g xy) ⟩ ∧-fmap f g xy =∎
algebraic-stack_agda0000_doc_14050
-- Testing parameterised records in parameterised modules module Exist (X : Set) where data [_] (a : Set) : Set where [] : [ a ] _∷_ : a -> [ a ] -> [ a ] map : forall {a b} -> (a -> b) -> [ a ] -> [ b ] map f [] = [] map f (x ∷ xs) = f x ∷ map f xs record ∃ (a : Set) (P : a -> Set) : Set where field witness : a proof : P witness ListP : (a : Set) -> (a -> Set) -> Set ListP a P = [ ∃ a P ] mapP : forall {a b P Q} -> (f : a -> b) -> (forall {x} -> P x -> Q (f x)) -> ListP a P -> ListP b Q mapP {a} {b} {P} {Q} f pres xs = map helper xs where helper : ∃ a P -> ∃ b Q helper r = record { witness = f (∃.witness r) ; proof = pres (∃.proof r) }
algebraic-stack_agda0000_doc_14051
{-# OPTIONS --without-K --safe #-} open import Relation.Binary using (Rel; Setoid; IsEquivalence) module Structures {a ℓ} {A : Set a} -- The underlying set (_≈_ : Rel A ℓ) -- The underlying equality relation where open import Algebra.Core open import Level using (_⊔_) open import Data.Product using (_,_; proj₁; proj₂) open import Algebra.Definitions _≈_ open import Algebra.Structures _≈_ open import Definitions _≈_ ------------------------------------------------------------------------ -- Structures with 1 binary operation ------------------------------------------------------------------------ record IsLatinQuasigroup (∙ : Op₂ A ) : Set (a ⊔ ℓ) where field isMagma : IsMagma ∙ latinSquare : LatinSquare ∙ open IsMagma isMagma public latinSquare₁ : LatinSquare₁ ∙ latinSquare₁ = proj₁ latinSquare latinSquare₂ : LatinSquare₂ ∙ latinSquare₂ = proj₂ latinSquare record IsIdempotentMagma (∙ : Op₂ A) : Set (a ⊔ ℓ) where field isMagma : IsMagma ∙ idem : Idempotent ∙ open IsMagma isMagma public record IsAlternateMagma (∙ : Op₂ A) : Set (a ⊔ ℓ) where field isMagma : IsMagma ∙ alter : Alternative ∙ open IsMagma isMagma public record IsFlexibleMagma (∙ : Op₂ A) : Set (a ⊔ ℓ) where field isMagma : IsMagma ∙ flex : Flexible ∙ open IsMagma isMagma public record IsMedialMagma (∙ : Op₂ A) : Set (a ⊔ ℓ) where field isMagma : IsMagma ∙ medial : Medial ∙ open IsMagma isMagma public record IsSemimedialMagma (∙ : Op₂ A) : Set (a ⊔ ℓ) where field isMagma : IsMagma ∙ semiMedial : Semimedial ∙ open IsMagma isMagma public record IsInverseSemigroup (∙ : Op₂ A) : Set (a ⊔ ℓ) where field isSemigroup : IsSemigroup ∙ pseudoInverse : PseudoInverse ∙ open IsSemigroup isSemigroup public ------------------------------------------------------------------------ -- Structures with 1 binary operation and 1 element ------------------------------------------------------------------------ record IsLeftUnitalMagma (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where field isMagma : IsMagma ∙ identity : LeftIdentity ε ∙ open IsMagma isMagma public record IsRightUnitalMagma (∙ : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where field isMagma : IsMagma ∙ identity : RightIdentity ε ∙ open IsMagma isMagma public ------------------------------------------------------------------------ -- Structures with 2 binary operations, 1 unary operation & 1 element ------------------------------------------------------------------------ record IsNonAssociativeRing (+ * : Op₂ A) (-_ : Op₁ A) (0# 1# : A) : Set (a ⊔ ℓ) where field +-isAbelianGroup : IsAbelianGroup + 0# -_ *-cong : Congruent₂ * identity : Identity 1# * distrib : * DistributesOver + zero : Zero 0# * open IsAbelianGroup +-isAbelianGroup public renaming ( assoc to +-assoc ; ∙-cong to +-cong ; ∙-congˡ to +-congˡ ; ∙-congʳ to +-congʳ ; identity to +-identity ; identityˡ to +-identityˡ ; identityʳ to +-identityʳ ; inverse to -‿inverse ; inverseˡ to -‿inverseˡ ; inverseʳ to -‿inverseʳ ; ⁻¹-cong to -‿cong ; comm to +-comm ; isMagma to +-isMagma ; isSemigroup to +-isSemigroup ; isMonoid to +-isMonoid ; isUnitalMagma to +-isUnitalMagma ; isCommutativeMagma to +-isCommutativeMagma ; isCommutativeMonoid to +-isCommutativeMonoid ; isCommutativeSemigroup to +-isCommutativeSemigroup ; isInvertibleMagma to +-isInvertibleMagma ; isInvertibleUnitalMagma to +-isInvertibleUnitalMagma ; isGroup to +-isGroup ) *-isMagma : IsMagma * *-isMagma = record { isEquivalence = isEquivalence ; ∙-cong = *-cong } *-identityˡ : LeftIdentity 1# * *-identityˡ = proj₁ identity *-identityʳ : RightIdentity 1# * *-identityʳ = proj₂ identity ------------------------------------------------------------------------ -- Structures with 3 binary operation and 1 element ------------------------------------------------------------------------ record IsLeftBolLoop (∙ \\ // : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where field isLoop : IsLoop ∙ \\ // ε leftBol : LeftBol ∙ open IsLoop isLoop public record IsRightBolLoop (∙ \\ // : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where field isLoop : IsLoop ∙ \\ // ε rightBol : RightBol ∙ open IsLoop isLoop public record IsMoufangLoop (∙ \\ // : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where field isLoop : IsLoop ∙ \\ // ε moufangIdentity : MoufangIdentity₁ ∙ moufangIdentity₂ : MoufangIdentity₂ ∙ moufangIdentity₃ : MoufangIdentity₃ ∙ moufangIdentity₄ : MoufangIdentity₄ ∙ open IsLoop isLoop public record IsPique (∙ \\ // : Op₂ A) (ε : A) : Set (a ⊔ ℓ) where field isQuasigroup : IsQuasigroup ∙ \\ // idem : Idempotent ∙ open IsQuasigroup isQuasigroup public
algebraic-stack_agda0000_doc_14052
-- Andreas, 2016-10-04, issue #2236 -- Result splitting should not insert hidden arguments visibly -- {-# OPTIONS -v interaction.case:100 #-} -- {-# OPTIONS -v tc.cover:100 #-} -- {-# OPTIONS -v reify.clause:100 #-} -- {-# OPTIONS -v reify.implicit:100 #-} splitMe : (A : Set) {B : Set} → Set splitMe = {!!} -- C-c C-c RET inserts hidden {B} splitMe' : (A : Set) {B : Set} (C : Set) {D : Set} → Set splitMe' = {!!} -- C-c C-c RET inserts hidden {B} and {D} splitMe'' : {B : Set} (C : Set) {D : Set} → Set splitMe'' = {!!} -- C-c C-c RET inserts hidden {D} postulate N : Set P : N → Set test : (A : Set) → ∀ {n} → P n → Set test = {!!} -- C-c C-c RET inserts hidden {n} -- Correct is: -- No hidden arguments inserted on lhs.
algebraic-stack_agda0000_doc_14053
{-# OPTIONS --without-K --exact-split --safe #-} open import Fragment.Algebra.Signature module Fragment.Algebra.Free.Base (Σ : Signature) where open import Fragment.Algebra.Algebra Σ open import Fragment.Algebra.Free.Atoms public open import Level using (Level; _⊔_) open import Function using (_∘_) open import Data.Empty using (⊥) open import Data.Nat using (ℕ) open import Data.Fin using (Fin) open import Data.Vec using (Vec; []; _∷_) open import Data.Vec.Relation.Binary.Pointwise.Inductive using (Pointwise; []; _∷_) open import Relation.Binary using (Setoid; IsEquivalence) open import Relation.Binary.PropositionalEquality as PE using (_≡_) private variable a ℓ : Level module _ (A : Set a) where data Term : Set a where atom : A → Term term : ∀ {arity} → (f : ops Σ arity) → Vec Term arity → Term module _ (S : Setoid a ℓ) where open Setoid S renaming (Carrier to A) data _~_ : Term A → Term A → Set (a ⊔ ℓ) where atom : ∀ {x y} → x ≈ y → atom x ~ atom y term : ∀ {arity xs ys} {f : ops Σ arity} → Pointwise _~_ xs ys → term f xs ~ term f ys private mutual map-~-refl : ∀ {n} {xs : Vec _ n} → Pointwise _~_ xs xs map-~-refl {xs = []} = [] map-~-refl {xs = x ∷ xs} = ~-refl ∷ map-~-refl ~-refl : ∀ {x} → x ~ x ~-refl {atom _} = atom refl ~-refl {term _ _} = term map-~-refl mutual map-~-sym : ∀ {n} {xs ys : Vec _ n} → Pointwise _~_ xs ys → Pointwise _~_ ys xs map-~-sym [] = [] map-~-sym (x≈y ∷ xs≈ys) = ~-sym x≈y ∷ map-~-sym xs≈ys ~-sym : ∀ {x y} → x ~ y → y ~ x ~-sym (atom x≈y) = atom (sym x≈y) ~-sym (term xs≈ys) = term (map-~-sym xs≈ys) mutual map-~-trans : ∀ {n} {xs ys zs : Vec _ n} → Pointwise _~_ xs ys → Pointwise _~_ ys zs → Pointwise _~_ xs zs map-~-trans [] [] = [] map-~-trans (x≈y ∷ xs≈ys) (y≈z ∷ ys≈zs) = ~-trans x≈y y≈z ∷ map-~-trans xs≈ys ys≈zs ~-trans : ∀ {x y z} → x ~ y → y ~ z → x ~ z ~-trans (atom x≈y) (atom y≈z) = atom (trans x≈y y≈z) ~-trans (term xs≈ys) (term ys≈zs) = term (map-~-trans xs≈ys ys≈zs) ~-isEquivalence : IsEquivalence _~_ ~-isEquivalence = record { refl = ~-refl ; sym = ~-sym ; trans = ~-trans } Herbrand : Setoid _ _ Herbrand = record { Carrier = Term A ; _≈_ = _~_ ; isEquivalence = ~-isEquivalence } Free : Algebra Free = record { ∥_∥/≈ = Herbrand ; ∥_∥/≈-isAlgebra = Free-isAlgebra } where term-cong : Congruence Herbrand term term-cong f p = term p Free-isAlgebra : IsAlgebra Herbrand Free-isAlgebra = record { ⟦_⟧ = term ; ⟦⟧-cong = term-cong } F : ℕ → Algebra F = Free ∘ Atoms (PE.setoid ⊥)
algebraic-stack_agda0000_doc_14054
-- 2011-09-14 posted by Nisse -- Andreas: this failed since SubstHH for Telescopes was wrong. -- {-# OPTIONS --show-implicit -v tc.lhs.unify:15 #-} module Issue292-14 where data D : Set where d : D postulate T : D → D → Set data T′ (x y : D) : Set where c : T x y → T′ x y F : D → D → Set F x d = T′ x d -- blocking unfolding of F x y record [F] : Set where field x y : D f : F x y -- T′ x y works data _≡_ (x : [F]) : [F] → Set where refl : x ≡ x Foo : ∀ {x} {t₁ t₂ : T x d} → record { f = c t₁ } ≡ record { f = c t₂ } → Set₁ Foo refl = Set
algebraic-stack_agda0000_doc_14055
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-} {-# OPTIONS --type-in-type #-} -- Note: Using this module is discouraged unless absolutely necessary. -- Use `Data.Product` or `Data.Both` instead. module Light.Indexed where open import Light.Level using (Level) postulate ℓ : Level record Indexed {aℓ} (𝕒 : Set aℓ) {aℓf : 𝕒 → Level} (𝕓 : ∀ a → Set (aℓf a)) : Set ℓ where constructor indexed field index : 𝕒 field thing : 𝕓 index open Indexed public
algebraic-stack_agda0000_doc_14056
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Group.Action 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.Structure open import Cubical.Algebra.Group.Base open import Cubical.Algebra.Group.Morphism open import Cubical.Algebra.Group.Properties open import Cubical.Algebra.Group.Notation open import Cubical.Algebra.Group.MorphismProperties open import Cubical.Structures.LeftAction open import Cubical.Structures.Axioms open import Cubical.Structures.Macro open import Cubical.Structures.Auto open import Cubical.Data.Sigma private variable ℓ ℓ' : Level record IsGroupAction (G : Group {ℓ = ℓ}) (H : Group {ℓ = ℓ'}) (_α_ : LeftActionStructure ⟨ G ⟩ ⟨ H ⟩) : Type (ℓ-max ℓ ℓ') where constructor isgroupaction open GroupNotationG G field isHom : (g : ⟨ G ⟩) → isGroupHom H H (g α_) identity : (h : ⟨ H ⟩) → 0ᴳ α h ≡ h assoc : (g g' : ⟨ G ⟩) → (h : ⟨ H ⟩) → (g +ᴳ g') α h ≡ g α (g' α h) record GroupAction (G : Group {ℓ}) (H : Group {ℓ'}): Type (ℓ-suc (ℓ-max ℓ ℓ')) where constructor groupaction field _α_ : LeftActionStructure ⟨ G ⟩ ⟨ H ⟩ isGroupAction : IsGroupAction G H _α_ module ActionΣTheory {ℓ ℓ' : Level} where module _ (G : Group {ℓ}) (H : Group {ℓ'}) (_α_ : LeftActionStructure ⟨ G ⟩ ⟨ H ⟩) where open GroupNotationG G IsGroupActionΣ : Type (ℓ-max ℓ ℓ') IsGroupActionΣ = ((g : ⟨ G ⟩) → isGroupHom H H (g α_)) × ((h : ⟨ H ⟩) → 0ᴳ α h ≡ h) × ((g g' : ⟨ G ⟩) → (h : ⟨ H ⟩) → (g +ᴳ g') α h ≡ g α (g' α h)) isPropIsGroupActionΣ : isProp IsGroupActionΣ isPropIsGroupActionΣ = isPropΣ isPropIsHom λ _ → isPropΣ isPropIdentity λ _ → isPropAssoc where isPropIsHom = isPropΠ (λ g → isPropIsGroupHom H H) isPropIdentity = isPropΠ (λ h → GroupStr.is-set (snd H) (0ᴳ α h) h) isPropAssoc = isPropΠ3 (λ g g' h → GroupStr.is-set (snd H) ((g +ᴳ g') α h) (g α (g' α h))) IsGroupAction→IsGroupActionΣ : IsGroupAction G H _α_ → IsGroupActionΣ IsGroupAction→IsGroupActionΣ (isgroupaction isHom identity assoc) = isHom , identity , assoc IsGroupActionΣ→IsGroupAction : IsGroupActionΣ → IsGroupAction G H _α_ IsGroupActionΣ→IsGroupAction (isHom , identity , assoc) = isgroupaction isHom identity assoc IsGroupActionΣIso : Iso (IsGroupAction G H _α_) IsGroupActionΣ Iso.fun IsGroupActionΣIso = IsGroupAction→IsGroupActionΣ Iso.inv IsGroupActionΣIso = IsGroupActionΣ→IsGroupAction Iso.rightInv IsGroupActionΣIso = λ _ → refl Iso.leftInv IsGroupActionΣIso = λ _ → refl open ActionΣTheory isPropIsGroupAction : {ℓ ℓ' : Level } (G : Group {ℓ}) (H : Group {ℓ'}) (_α_ : LeftActionStructure ⟨ G ⟩ ⟨ H ⟩) → isProp (IsGroupAction G H _α_) isPropIsGroupAction G H _α_ = isOfHLevelRespectEquiv 1 (invEquiv (isoToEquiv (IsGroupActionΣIso G H _α_))) (isPropIsGroupActionΣ G H _α_) module ActionNotationα {N : Group {ℓ}} {H : Group {ℓ'}} (Act : GroupAction H N) where _α_ = GroupAction._α_ Act private isGroupAction = GroupAction.isGroupAction Act α-id = IsGroupAction.identity isGroupAction α-hom = IsGroupAction.isHom isGroupAction α-assoc = IsGroupAction.assoc isGroupAction module ActionLemmas {G : Group {ℓ}} {H : Group {ℓ'}} (Act : GroupAction G H) where open ActionNotationα {N = H} {H = G} Act open GroupNotationᴴ H open GroupNotationG G open MorphismLemmas {G = H} {H = H} open GroupLemmas abstract actOnUnit : (g : ⟨ G ⟩) → g α 0ᴴ ≡ 0ᴴ actOnUnit g = mapId (grouphom (g α_) (α-hom g)) actOn-Unit : (g : ⟨ G ⟩) → g α (-ᴴ 0ᴴ) ≡ 0ᴴ actOn-Unit g = (cong (g α_) (invId H)) ∙ actOnUnit g actOn- : (g : ⟨ G ⟩) (h : ⟨ H ⟩) → g α (-ᴴ h) ≡ -ᴴ (g α h) actOn- g h = mapInv (grouphom (g α_) (α-hom g)) h -idAct : (h : ⟨ H ⟩) → (-ᴳ 0ᴳ) α h ≡ h -idAct h = (cong (_α h) (invId G)) ∙ (α-id h) -- Examples -- left adjoint action of a group on a normal subgroup
algebraic-stack_agda0000_doc_14057
{- This file contains: - Properties of set truncations -} {-# OPTIONS --cubical --safe #-} module Cubical.HITs.SetTruncation.Properties where open import Cubical.HITs.SetTruncation.Base open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels private variable ℓ : Level A : Type ℓ -- lemma 6.9.1 in HoTT book elim : {B : ∥ A ∥₀ → Type ℓ} → (Bset : (x : ∥ A ∥₀) → isSet (B x)) → (g : (a : A) → B (∣ a ∣₀)) → (x : ∥ A ∥₀) → B x elim Bset g ∣ a ∣₀ = g a elim {A = A} {B = B} Bset g (squash₀ x y p q i j) = isOfHLevel→isOfHLevelDep 2 Bset _ _ (cong (elim Bset g) p) (cong (elim Bset g) q) (squash₀ x y p q) i j setTruncUniversal : {B : Type ℓ} → (isSet B) → (∥ A ∥₀ → B) ≃ (A → B) setTruncUniversal Bset = isoToEquiv (iso intro out leftInv rightInv) where intro = (λ h a → h ∣ a ∣₀) out = elim (λ x → Bset) leftInv : ∀ g → intro (out g) ≡ g leftInv g = refl rightInv : ∀ h → out (intro h) ≡ h rightInv h i x = elim (λ x → isProp→isSet (Bset (out (intro h) x) (h x))) (λ a → refl) x i elim2 : {B : ∥ A ∥₀ → ∥ A ∥₀ → Type ℓ} (Bset : ((x y : ∥ A ∥₀) → isSet (B x y))) (g : (a b : A) → B ∣ a ∣₀ ∣ b ∣₀) (x y : ∥ A ∥₀) → B x y elim2 Bset g = elim (λ _ → isOfHLevelPi 2 (λ _ → Bset _ _)) (λ a → elim (λ _ → Bset _ _) (λ b → g a b)) elim3 : {B : (x y z : ∥ A ∥₀) → Type ℓ} (Bset : ((x y z : ∥ A ∥₀) → isSet (B x y z))) (g : (a b c : A) → B ∣ a ∣₀ ∣ b ∣₀ ∣ c ∣₀) (x y z : ∥ A ∥₀) → B x y z elim3 Bset g = elim2 (λ _ _ → isOfHLevelPi 2 λ _ → Bset _ _ _) (λ a b → elim (λ _ → Bset _ _ _) (λ c → g a b c)) setTruncIsSet : isSet ∥ A ∥₀ setTruncIsSet a b p q = squash₀ a b p q setId : isSet A → ∥ A ∥₀ ≡ A setId {A = A} isset = isoToPath (iso (elim {A = A} (λ _ → isset) (λ x → x)) (λ x → ∣ x ∣₀) (λ b → refl) (λ b → idLemma b)) where idLemma : ∀ (b : ∥ A ∥₀) → ∣ elim (λ x → isset) (λ x → x) b ∣₀ ≡ b idLemma b = elim {B = (λ x → ∣ elim (λ _ → isset) (λ x → x) x ∣₀ ≡ x)} (λ x → isOfHLevelSuc 2 (setTruncIsSet {A = A}) ∣ elim (λ _ → isset) (λ x₁ → x₁) x ∣₀ x) (λ _ → refl) b
algebraic-stack_agda0000_doc_14058
{-# OPTIONS --without-K #-} open import Base open import Homotopy.TruncatedHIT open import Spaces.Spheres open import Integers module Sets.Quotient {i j} (A : Set i) ⦃ p : is-set A ⦄ (R : A → A → Set j) ⦃ q : (x y : A) → is-prop (R x y) ⦄ where private data _#/_ : Set (max i j) where #proj : A → _#/_ #top : (f : hSⁿ ⟨0⟩ → _#/_) → _#/_ _/_ : Set (max i j) _/_ = _#/_ proj : A → _/_ proj = #proj postulate -- HIT eq : (x y : A) (p : R x y) → proj x ≡ proj y top : (f : hSⁿ ⟨0⟩ → _/_) → _/_ top = #top postulate -- HIT rays : (f : hSⁿ ⟨0⟩ → _/_) (x : hSⁿ ⟨0⟩) → top f ≡ f x #/-rec : ∀ {k} (P : _/_ → Set k) (proj* : (x : A) → P (proj x)) (eq* : (x y : A) (p : R x y) → transport P (eq x y p) (proj* x) ≡ proj* y) (top* : (f : hSⁿ ⟨0⟩ → _/_) (p : (x : hSⁿ ⟨0⟩) → P (f x)) → P (top f)) (rays* : (f : hSⁿ ⟨0⟩ → _/_) (p : (x : hSⁿ ⟨0⟩) → P (f x)) (x : hSⁿ ⟨0⟩) → transport P (rays f x) (top* f p) ≡ p x) → ((t : _/_) → P t) #/-rec P proj* eq* top* rays* (#proj x) = proj* x #/-rec P proj* eq* top* rays* (#top f) = top* f (λ x → #/-rec P proj* eq* top* rays* (f x)) #/-rec-nondep : ∀ {k} (B : Set k) (proj* : A → B) (eq* : (x y : A) (p : R x y) → proj* x ≡ proj* y) (top* : (f : hSⁿ ⟨0⟩ → _/_) (p : hSⁿ ⟨0⟩ → B) → B) (rays* : (f : hSⁿ ⟨0⟩ → _/_) (p : hSⁿ ⟨0⟩ → B) (x : hSⁿ ⟨0⟩) → top* f p ≡ p x) → (_/_ → B) #/-rec-nondep B proj* eq* top* rays* (#proj x) = proj* x #/-rec-nondep B proj* eq* top* rays* (#top f) = top* f (λ x → #/-rec-nondep B proj* eq* top* rays* (f x)) /-rec : ∀ {k} (P : _/_ → Set k) (proj* : (x : A) → P (proj x)) (eq* : (x y : A) (p : R x y) → transport P (eq x y p) (proj* x) ≡ proj* y) (trunc : (x : _/_) → is-set (P x)) → ((t : _/_) → P t) /-rec P proj* eq* trunc = #/-rec P proj* eq* (λ f p₁ → π₁ (u f p₁)) (λ f p₁ → π₂ (u f p₁)) where u : _ u = truncated-has-filling-dep _/_ P ⟨0⟩ (λ ()) (λ f → (top f , rays f)) /-rec-nondep : ∀ {k} (B : Set k) (proj* : A → B) (eq* : (x y : A) (p : R x y) → proj* x ≡ proj* y) (trunc : is-set B) → (_/_ → B) /-rec-nondep B proj* eq* trunc = #/-rec-nondep B proj* eq* (λ _ p → π₁ (u p)) (λ _ p → π₂ (u p)) where u : _ u = truncated-has-spheres-filled ⟨0⟩ _ trunc -- Reduction rules for paths are not needed
algebraic-stack_agda0000_doc_14059
{-# OPTIONS --allow-unsolved-metas #-} -- When instantiating metas, we can't ignore variables occurring in -- irrelevant terms. If we do the irrelevant terms will become illformed -- (and we get __IMPOSSIBLE__s) -- For instance -- _42 := DontCare (Just (Var 0 [])) -- is a bad thing to do. In the example below we hit the __IMPOSSIBLE__ in -- the rename function in TypeChecking.MetaVars.assign. module DontIgnoreIrrelevantVars where import Common.Level import Common.Irrelevance record Category : Set₁ where field .Arr : Set postulate C : Category _∙_ : ∀ {A : Set} {B : A → Set} {C : Set} → (∀ {x} → B x → C) → (g : ∀ x → B x) → A → C f ∙ g = λ x → f (g x) Exp : (I : Set) → Category Exp I = record { Arr = I → Category.Arr C } postulate Functor : Category → Set postulate flattenP : ∀ D → Functor D → Functor D flattenHʳ : ∀ J → Functor (Exp J) → Functor (Exp J) flattenH : ∀ I → Functor (Exp I) → Functor (Exp I) flattenH I = flattenHʳ _ ∙ flattenP _
algebraic-stack_agda0000_doc_14060
module Categories.Support.Experimental where open import Relation.Binary.PropositionalEquality.TrustMe open import Categories.Support.PropositionalEquality ≣-relevant : ∀ {l} {A : Set l} {X Y : A} -> .(X ≣ Y) -> X ≣ Y ≣-relevant _ = trustMe private ≣-coe : ∀ {a} {A B : Set a} → (A ≣ B) -> A -> B ≣-coe ≣-refl a = a ≣-subst′ : ∀ {a p} {A : Set a} → (P : A -> Set p) -> {x y : A} -> .(x ≣ y) -> P x -> P y ≣-subst′ P eq Px = ≣-coe (≣-relevant (≣-cong P eq)) Px
algebraic-stack_agda0000_doc_14061
{-# OPTIONS --without-K --safe #-} open import Polynomial.Parameters module Polynomial.NormalForm.Construction {a ℓ} (coeffs : RawCoeff a ℓ) where open import Relation.Nullary using (Dec; yes; no) open import Level using (lift; lower; _⊔_) open import Data.Unit using (tt) open import Data.List using (_∷_; []; List; foldr) open import Data.Nat as ℕ using (ℕ; suc; zero) open import Data.Nat.Properties using (z≤′n) open import Data.Product using (_×_; _,_; map₁; curry; uncurry) open import Data.Maybe using (just; nothing) open import Data.Bool using (if_then_else_; true; false) open import Function open import Polynomial.NormalForm.InjectionIndex open import Polynomial.NormalForm.Definition coeffs open RawCoeff coeffs ---------------------------------------------------------------------- -- Construction -- -- Because the polynomial is stored in a canonical form, we use a -- normalising cons operator to construct the coefficient lists. ---------------------------------------------------------------------- -- Decision procedure for Zero zero? : ∀ {n} → (p : Poly n) → Dec (Zero p) zero? (Σ _ Π _) = no (λ z → z) zero? (Κ x Π _) with Zero-C x ... | true = yes tt ... | false = no (λ z → z) {-# INLINE zero? #-} -- Exponentiate the first variable of a polynomial infixr 8 _⍓*_ _⍓+_ _⍓*_ : ∀ {n} → Coeff n * → ℕ → Coeff n * _⍓+_ : ∀ {n} → Coeff n + → ℕ → Coeff n + [] ⍓* _ = [] (∹ xs) ⍓* i = ∹ xs ⍓+ i coeff (head (xs ⍓+ i)) = coeff (head xs) pow (head (xs ⍓+ i)) = pow (head xs) ℕ.+ i tail (xs ⍓+ i) = tail xs infixr 5 _∷↓_ _∷↓_ : ∀ {n} → PowInd (Poly n) → Coeff n * → Coeff n * x Δ i ∷↓ xs = case zero? x of λ { (yes p) → xs ⍓* suc i ; (no ¬p) → ∹ _≠0 x {¬p} Δ i & xs } {-# INLINE _∷↓_ #-} -- Inject a polynomial into a larger polynomoial with more variables _Π↑_ : ∀ {n m} → Poly n → (suc n ≤′ m) → Poly m (xs Π i≤n) Π↑ n≤m = xs Π (≤′-step i≤n ⟨ ≤′-trans ⟩ n≤m) {-# INLINE _Π↑_ #-} infixr 4 _Π↓_ _Π↓_ : ∀ {i n} → Coeff i * → suc i ≤′ n → Poly n [] Π↓ i≤n = Κ 0# Π z≤′n (∹ x ≠0 Δ zero & [] ) Π↓ i≤n = x Π↑ i≤n (∹ x Δ zero & ∹ xs) Π↓ i≤n = Σ (x Δ zero & ∹ xs) Π i≤n (∹ x Δ suc j & xs ) Π↓ i≤n = Σ (x Δ suc j & xs) Π i≤n {-# INLINE _Π↓_ #-} -------------------------------------------------------------------------------- -- These folds allow us to abstract over the proofs later: we try to avoid -- using ∷↓ and Π↓ directly anywhere except here, so if we prove that this fold -- acts the same on a normalised or non-normalised polynomial, we can prove th -- same about any operation which uses it. PolyF : ℕ → Set a PolyF i = Poly i × Coeff i * Fold : ℕ → Set a Fold i = PolyF i → PolyF i para : ∀ {i} → Fold i → Coeff i + → Coeff i * para f (x ≠0 Δ i & []) = case f (x , []) of λ { (y , ys) → y Δ i ∷↓ ys } para f (x ≠0 Δ i & ∹ xs) = case f (x , para f xs) of λ { (y , ys) → y Δ i ∷↓ ys } poly-map : ∀ {i} → (Poly i → Poly i) → Coeff i + → Coeff i * poly-map f = para (λ { (x , y) → (f x , y)}) {-# INLINE poly-map #-}
algebraic-stack_agda0000_doc_14062
-- Andreas, 2011-04-14 module UnificationUndecidedForNonStronglyRigidOccurrence where data Nat : Set where zero : Nat suc : Nat -> Nat data _≡_ {A : Set}(a : A) : A -> Set where refl : a ≡ a i : (f : Nat -> Nat)(n : Nat) -> n ≡ f n -> Nat i f n () -- this should fail, since n ≡ f n is not always empty, only in case of f=suc -- thus, an occurrence does not always mean no match, only strict occurrences -- mean that.
algebraic-stack_agda0000_doc_14063
{-# OPTIONS --safe #-} module JVM.Compiler where open import JVM.Types open import JVM.Syntax.Instructions module _ 𝑭 where open import JVM.Compiler.Monad StackTy ⟨ 𝑭 ∣_↝_⟩ noop using (Compiler) public module _ {𝑭} where open import JVM.Compiler.Monad StackTy ⟨ 𝑭 ∣_↝_⟩ noop hiding (Compiler) public
algebraic-stack_agda0000_doc_13648
-- The purpose of this universe construction is to get some definitional -- equalities in the model. Specifically, if we define ⟦σ⟧ : ⟦Δ⟧ → ⟦Ω⟧ -- (a functor) for the "canonical" notion of subsitution, then we have -- ⟦Wk⟧ (δ , m) ≡ δ propositionally, but *not* definitionally. This then -- complicates proofs involving ⟦Wk⟧, and similar for the other substitutions. {-# OPTIONS --without-K --safe #-} module Source.Size.Substitution.Universe where open import Relation.Binary using (IsEquivalence ; Setoid) open import Source.Size open import Source.Size.Substitution.Canonical as Can using (Sub⊢) open import Util.Prelude import Relation.Binary.Reasoning.Setoid as SetoidReasoning infix 4 _≈_ infixl 5 _>>_ data Sub : (Δ Ω : Ctx) → Set where Id : Sub Δ Δ _>>_ : (σ : Sub Δ Δ′) (τ : Sub Δ′ Ω) → Sub Δ Ω Wk : Sub (Δ ∙ n) Δ Lift : (σ : Sub Δ Ω) → Sub (Δ ∙ m) (Ω ∙ n) Sing : (n : Size Δ) → Sub Δ (Δ ∙ m) Skip : Sub (Δ ∙ n ∙ v0) (Δ ∙ n) ⟨_⟩ : Sub Δ Ω → Can.Sub Δ Ω ⟨ Id ⟩ = Can.Id ⟨ σ >> τ ⟩ = ⟨ σ ⟩ Can.>> ⟨ τ ⟩ ⟨ Wk ⟩ = Can.Wk ⟨ Lift σ ⟩ = Can.Lift ⟨ σ ⟩ ⟨ Sing n ⟩ = Can.Sing n ⟨ Skip ⟩ = Can.Skip subV : (σ : Sub Δ Ω) (x : Var Ω) → Size Δ subV σ = Can.subV ⟨ σ ⟩ sub : (σ : Sub Δ Ω) (n : Size Ω) → Size Δ sub σ = Can.sub ⟨ σ ⟩ pattern Lift′ σ ⊢n = Lift σ ⊢n refl variable σ τ ι : Sub Δ Ω data Sub⊢ᵤ : ∀ Δ Ω → Sub Δ Ω → Set where Id : Sub⊢ᵤ Δ Δ Id comp : (⊢σ : Sub⊢ᵤ Δ Δ′ σ) (⊢τ : Sub⊢ᵤ Δ′ Δ″ τ) → Sub⊢ᵤ Δ Δ″ (σ >> τ) Wk : Sub⊢ᵤ (Δ ∙ n) Δ Wk Lift : (⊢σ : Sub⊢ᵤ Δ Ω σ) (m≡n[σ] : m ≡ sub σ n) → Sub⊢ᵤ (Δ ∙ m) (Ω ∙ n) (Lift σ) Sing : (n<m : n < m) → Sub⊢ᵤ Δ (Δ ∙ m) (Sing n) Skip : Sub⊢ᵤ (Δ ∙ n ∙ v0) (Δ ∙ n) Skip syntax Sub⊢ᵤ Δ Ω σ = σ ∶ Δ ⇒ᵤ Ω ⟨⟩-resp-⊢ : σ ∶ Δ ⇒ᵤ Ω → ⟨ σ ⟩ ∶ Δ ⇒ Ω ⟨⟩-resp-⊢ Id = Can.Id⊢ ⟨⟩-resp-⊢ (comp ⊢σ ⊢τ) = Can.>>⊢ (⟨⟩-resp-⊢ ⊢σ) (⟨⟩-resp-⊢ ⊢τ) ⟨⟩-resp-⊢ Wk = Can.Wk⊢ ⟨⟩-resp-⊢ (Lift ⊢σ m≡n[σ]) = Can.Lift⊢ (⟨⟩-resp-⊢ ⊢σ) m≡n[σ] ⟨⟩-resp-⊢ (Sing n<m) = Can.Sing⊢ n<m ⟨⟩-resp-⊢ Skip = Can.Skip⊢ record _≈_ (σ τ : Sub Δ Ω) : Set where constructor ≈⁺ field ≈⁻ : ⟨ σ ⟩ ≡ ⟨ τ ⟩ open _≈_ public ≈-refl : σ ≈ σ ≈-refl = ≈⁺ refl ≈-sym : σ ≈ τ → τ ≈ σ ≈-sym (≈⁺ p) = ≈⁺ (sym p) ≈-trans : σ ≈ τ → τ ≈ ι → σ ≈ ι ≈-trans (≈⁺ p) (≈⁺ q) = ≈⁺ (trans p q) ≈-isEquivalence : IsEquivalence (_≈_ {Δ} {Ω}) ≈-isEquivalence = record { refl = ≈-refl ; sym = ≈-sym ; trans = ≈-trans } Sub-setoid : (Δ Ω : Ctx) → Setoid 0ℓ 0ℓ Sub-setoid Δ Ω = record { Carrier = Sub Δ Ω ; _≈_ = _≈_ ; isEquivalence = ≈-isEquivalence } module ≈-Reasoning {Δ} {Ω} = SetoidReasoning (Sub-setoid Δ Ω) abstract >>-resp-≈ : {σ σ′ : Sub Δ Δ′} {τ τ′ : Sub Δ′ Δ″} → σ ≈ σ′ → τ ≈ τ′ → σ >> τ ≈ σ′ >> τ′ >>-resp-≈ (≈⁺ p) (≈⁺ q) = ≈⁺ (cong₂ Can._>>_ p q) Lift-resp-≈ : σ ≈ τ → Lift {m = m} {n} σ ≈ Lift τ Lift-resp-≈ (≈⁺ p) = ≈⁺ (cong Can.Lift p) sub-resp-< : σ ∶ Δ ⇒ᵤ Ω → n < m → sub σ n < sub σ m sub-resp-< ⊢σ = Can.sub-resp-< (⟨⟩-resp-⊢ ⊢σ) mutual subV′ : Sub Δ Ω → Var Ω → Size Δ subV′ Id x = var x subV′ (σ >> τ) x = sub′ σ (subV′ τ x) subV′ Wk x = var (suc x) subV′ (Lift σ) zero = var zero subV′ (Lift σ) (suc x) = wk (subV′ σ x) subV′ (Sing n) zero = n subV′ (Sing n) (suc x) = var x subV′ Skip zero = var zero subV′ Skip (suc x) = var (suc (suc x)) sub′ : Sub Δ Ω → Size Ω → Size Δ sub′ σ (var x) = subV′ σ x sub′ σ ∞ = ∞ sub′ σ zero = zero sub′ σ (suc n) = suc (sub′ σ n) abstract subV′≡subV : ∀ (σ : Sub Δ Ω) x → subV′ σ x ≡ subV σ x subV′≡subV Id x = sym (Can.subV-Id x) subV′≡subV (σ >> τ) x = trans (sub′≡sub σ (subV′ τ x)) (trans (cong (sub σ) (subV′≡subV τ x)) (sym (Can.subV->> ⟨ σ ⟩ ⟨ τ ⟩ x))) subV′≡subV Wk x = sym (Can.sub-Wk (var x)) subV′≡subV (Lift σ) zero = refl subV′≡subV (Lift σ) (suc x) = trans (cong wk (subV′≡subV σ x)) (sym (Can.subV-Weaken ⟨ σ ⟩ x)) subV′≡subV (Sing n) zero = refl subV′≡subV (Sing n) (suc x) = sym (Can.subV-Id x) subV′≡subV Skip zero = refl subV′≡subV Skip (suc x) = sym (trans (Can.subV-Weaken (Can.Weaken Can.Id) x) (cong wk (Can.sub-Wk (var x)))) sub′≡sub : ∀ (σ : Sub Δ Ω) n → sub′ σ n ≡ sub σ n sub′≡sub σ (var x) = subV′≡subV σ x sub′≡sub σ ∞ = refl sub′≡sub σ zero = refl sub′≡sub σ (suc n) = cong suc (sub′≡sub σ n)
algebraic-stack_agda0000_doc_13649
{-# OPTIONS --safe #-} module Cubical.Algebra.DirectSum.DirectSumHIT.Properties where open import Cubical.Foundations.Prelude open import Cubical.Data.Empty as ⊥ open import Cubical.Data.Sigma open import Cubical.Relation.Nullary open import Cubical.Algebra.Group open import Cubical.Algebra.AbGroup open import Cubical.Algebra.DirectSum.DirectSumHIT.Base private variable ℓ ℓ' : Level module AbGroupProperties (Idx : Type ℓ) (P : Idx → Type ℓ') (AGP : (r : Idx) → AbGroupStr (P r)) where inv : ⊕HIT Idx P AGP → ⊕HIT Idx P AGP inv = DS-Rec-Set.f Idx P AGP (⊕HIT Idx P AGP) trunc -- elements neutral (λ r a → base r (AbGroupStr.-_ (AGP r) a)) (λ xs ys → xs add ys) -- eq group (λ xs ys zs → addAssoc xs ys zs) (λ xs → addRid xs) (λ xs ys → addComm xs ys) -- eq base (λ r → let open AbGroupStr (AGP r) in let open GroupTheory (P r , AbGroupStr→GroupStr (AGP r)) in (cong (base r) inv1g) ∙ (base-neutral r)) (λ r a b → let open AbGroupStr (AGP r) in let open GroupTheory (P r , AbGroupStr→GroupStr (AGP r)) in ((base r (- a) add base r (- b)) ≡⟨ (base-add r (- a) (- b)) ⟩ base r ((- a) + (- b)) ≡⟨ (cong (base r) (sym (invDistr b a))) ⟩ base r (- (b + a)) ≡⟨ cong (base r) (cong (-_) (+Comm b a)) ⟩ base r (- (a + b)) ∎)) rinv : (z : ⊕HIT Idx P AGP) → z add (inv z) ≡ neutral rinv = DS-Ind-Prop.f Idx P AGP (λ z → z add (inv z) ≡ neutral) (λ _ → trunc _ _) -- elements (addRid neutral) (λ r a → let open AbGroupStr (AGP r) in ((base r a add base r (- a)) ≡⟨ base-add r a (- a) ⟩ base r (a + - a) ≡⟨ cong (base r) (+InvR a) ⟩ base r 0g ≡⟨ base-neutral r ⟩ neutral ∎)) (λ {x} {y} p q → (((x add y) add ((inv x) add (inv y))) ≡⟨ cong (λ X → X add ((inv x) add (inv y))) (addComm x y) ⟩ ((y add x) add (inv x add inv y)) ≡⟨ sym (addAssoc y x (inv x add inv y)) ⟩ (y add (x add (inv x add inv y))) ≡⟨ cong (λ X → y add X) (addAssoc x (inv x) (inv y)) ⟩ (y add ((x add inv x) add inv y)) ≡⟨ cong (λ X → y add (X add (inv y))) (p) ⟩ (y add (neutral add inv y)) ≡⟨ cong (λ X → y add X) (addComm neutral (inv y)) ⟩ (y add (inv y add neutral)) ≡⟨ cong (λ X → y add X) (addRid (inv y)) ⟩ (y add inv y) ≡⟨ q ⟩ neutral ∎)) module SubstLemma (Idx : Type ℓ) (G : Idx → Type ℓ') (Gstr : (r : Idx) → AbGroupStr (G r)) where open AbGroupStr subst0g : {l k : Idx} → (p : l ≡ k) → subst G p (0g (Gstr l)) ≡ 0g (Gstr k) subst0g {l} {k} p = J (λ k p → subst G p (0g (Gstr l)) ≡ 0g (Gstr k)) (transportRefl _) p subst+ : {l : Idx} → (a b : G l) → {k : Idx} → (p : l ≡ k) → Gstr k ._+_ (subst G p a) (subst G p b) ≡ subst G p (Gstr l ._+_ a b) subst+ {l} a b {k} p = J (λ k p → Gstr k ._+_ (subst G p a) (subst G p b) ≡ subst G p (Gstr l ._+_ a b)) (cong₂ (Gstr l ._+_) (transportRefl _) (transportRefl _) ∙ sym (transportRefl _)) p module DecIndec-BaseProperties (Idx : Type ℓ) (decIdx : Discrete Idx) (G : Idx → Type ℓ') (Gstr : (r : Idx) → AbGroupStr (G r)) where open AbGroupStr open SubstLemma Idx G Gstr πₖ : (k : Idx) → ⊕HIT Idx G Gstr → G k πₖ k = DS-Rec-Set.f _ _ _ _ (is-set (Gstr k)) (0g (Gstr k)) base-trad (_+_ (Gstr k)) (+Assoc (Gstr k)) (+IdR (Gstr k)) (+Comm (Gstr k)) base-neutral-eq base-add-eq where base-trad : (l : Idx) → (a : G l) → G k base-trad l a with decIdx l k ... | yes p = subst G p a ... | no ¬p = 0g (Gstr k) base-neutral-eq : _ base-neutral-eq l with decIdx l k ... | yes p = subst0g p ... | no ¬p = refl base-add-eq : _ base-add-eq l a b with decIdx l k ... | yes p = subst+ a b p ... | no ¬p = +IdR (Gstr k) _ πₖ-id : {k : Idx} → (a : G k) → πₖ k (base k a) ≡ a πₖ-id {k} a with decIdx k k ... | yes p = cong (λ X → subst G X a) (Discrete→isSet decIdx _ _ _ _) ∙ transportRefl _ ... | no ¬p = rec (¬p refl) πₖ-0g : {k l : Idx} → (a : G l) → (p : k ≡ l → ⊥) → πₖ k (base l a) ≡ 0g (Gstr k) πₖ-0g {k} {l} a ¬q with decIdx l k ... | yes p = rec (¬q (sym p)) ... | no ¬p = refl base-inj : {k : Idx} → {a b : G k} → base {AGP = Gstr} k a ≡ base k b → a ≡ b base-inj {k} {a} {b} p = sym (πₖ-id a) ∙ cong (πₖ k) p ∙ πₖ-id b base-≢ : {k : Idx} → {a : G k} → {l : Idx} → {b : G l} → (p : k ≡ l → ⊥) → base {AGP = Gstr} k a ≡ base {AGP = Gstr} l b → (a ≡ 0g (Gstr k)) × (b ≡ 0g (Gstr l)) base-≢ {k} {a} {l} {b} ¬p q = helper1 , helper2 where helper1 : a ≡ 0g (Gstr k) helper1 = sym (πₖ-id a) ∙ cong (πₖ k) q ∙ πₖ-0g b ¬p helper2 : b ≡ 0g (Gstr l) helper2 = sym (πₖ-id b) ∙ cong (πₖ l) (sym q) ∙ πₖ-0g a (λ x → ¬p (sym x))
algebraic-stack_agda0000_doc_13650
-- Check that unquoted functions are termination checked. module _ where open import Common.Prelude hiding (_>>=_) open import Common.Reflection `⊥ : Type `⊥ = def (quote ⊥) [] {- Generate aux : ⊥ aux = aux loop : ⊥ loop = aux -} makeLoop : QName → TC ⊤ makeLoop loop = freshName "aux" >>= λ aux → declareDef (vArg aux) `⊥ >>= λ _ → defineFun aux (clause [] (def aux []) ∷ []) >>= λ _ → declareDef (vArg loop) `⊥ >>= λ _ → defineFun loop (clause [] (def aux []) ∷ []) unquoteDecl loop = makeLoop loop
algebraic-stack_agda0000_doc_13651
------------------------------------------------------------------------ -- The Agda standard library -- -- Definitions for types of functions that only require an equality -- relation over the domain. ------------------------------------------------------------------------ -- The contents of this file should usually be accessed from `Function`. {-# OPTIONS --without-K --safe #-} open import Relation.Binary module Function.Definitions.Core1 {a ℓ₁} {A : Set a} (_≈₁_ : Rel A ℓ₁) where open import Level using (_⊔_) ------------------------------------------------------------------------ -- Definitions -- (Note the name `RightInverse` is used for the bundle) Inverseʳ : ∀ {b} {B : Set b} → (A → B) → (B → A) → Set (a ⊔ ℓ₁) Inverseʳ f g = ∀ x → g (f x) ≈₁ x