id
stringlengths
27
136
text
stringlengths
4
1.05M
algebraic-stack_agda0000_doc_56
------------------------------------------------------------------------ -- Values ------------------------------------------------------------------------ open import Atom module Values (atoms : χ-atoms) where open import Equality.Propositional open import Prelude hiding (const) open import Chi atoms open import Deterministic atoms open χ-atoms atoms -- Values. mutual infixr 5 _∷_ data Value : Exp → Type where lambda : ∀ x e → Value (lambda x e) const : ∀ c {es} → Values es → Value (const c es) data Values : List Exp → Type where [] : Values [] _∷_ : ∀ {e es} → Value e → Values es → Values (e ∷ es) -- Constructor applications. data Consts : Type where const : Const → List Consts → Consts mutual data Constructor-application : Exp → Type where const : ∀ c {es} → Constructor-applications es → Constructor-application (const c es) data Constructor-applications : List Exp → Type where [] : Constructor-applications [] _∷_ : ∀ {e es} → Constructor-application e → Constructor-applications es → Constructor-applications (e ∷ es) -- Constructor applications are values. mutual const→value : ∀ {e} → Constructor-application e → Value e const→value (const c cs) = const c (consts→values cs) consts→values : ∀ {es} → Constructor-applications es → Values es consts→values [] = [] consts→values (c ∷ cs) = const→value c ∷ consts→values cs -- The second argument of _⇓_ is always a Value. mutual ⇓-Value : ∀ {e v} → e ⇓ v → Value v ⇓-Value (apply _ _ p) = ⇓-Value p ⇓-Value (case _ _ _ p) = ⇓-Value p ⇓-Value (rec p) = ⇓-Value p ⇓-Value lambda = lambda _ _ ⇓-Value (const ps) = const _ (⇓⋆-Values ps) ⇓⋆-Values : ∀ {es vs} → es ⇓⋆ vs → Values vs ⇓⋆-Values [] = [] ⇓⋆-Values (p ∷ ps) = ⇓-Value p ∷ ⇓⋆-Values ps mutual values-compute-to-themselves : ∀ {v} → Value v → v ⇓ v values-compute-to-themselves (lambda _ _) = lambda values-compute-to-themselves (const _ ps) = const (values-compute-to-themselves⋆ ps) values-compute-to-themselves⋆ : ∀ {vs} → Values vs → vs ⇓⋆ vs values-compute-to-themselves⋆ [] = [] values-compute-to-themselves⋆ (p ∷ ps) = values-compute-to-themselves p ∷ values-compute-to-themselves⋆ ps values-only-compute-to-themselves : ∀ {v₁ v₂} → Value v₁ → v₁ ⇓ v₂ → v₁ ≡ v₂ values-only-compute-to-themselves p q = ⇓-deterministic (values-compute-to-themselves p) q values-only-compute-to-themselves⋆ : ∀ {vs₁ vs₂} → Values vs₁ → vs₁ ⇓⋆ vs₂ → vs₁ ≡ vs₂ values-only-compute-to-themselves⋆ ps qs = ⇓⋆-deterministic (values-compute-to-themselves⋆ ps) qs
algebraic-stack_agda0000_doc_57
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Semigroup.Properties where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Function using (_∘_; id) open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Logic using (_≡ₚ_) open import Cubical.Functions.Embedding open import Cubical.Data.Nat open import Cubical.Data.NatPlusOne open import Cubical.Algebra open import Cubical.Algebra.Properties open import Cubical.Algebra.Semigroup.Morphism open import Cubical.Algebra.Magma.Properties using (isPropIsMagma) open import Cubical.Relation.Binary open import Cubical.Relation.Binary.Reasoning.Equality open import Cubical.HITs.PropositionalTruncation open import Cubical.Algebra.Semigroup.MorphismProperties public using (SemigroupPath; uaSemigroup; carac-uaSemigroup; Semigroup≡; caracSemigroup≡) private variable ℓ ℓ′ : Level isPropIsSemigroup : ∀ {S : Type ℓ} {_•_} → isProp (IsSemigroup S _•_) isPropIsSemigroup {_} {_} {_•_} (issemigroup aMagma aAssoc) (issemigroup bMagma bAssoc) = cong₂ issemigroup (isPropIsMagma aMagma bMagma) (isPropAssociative (IsMagma.is-set aMagma) _•_ aAssoc bAssoc) module SemigroupLemmas (S : Semigroup ℓ) where open Semigroup S ^-suc : ∀ x n → x ^ suc₊₁ n ≡ x ^ n • x ^-suc x one = refl ^-suc x (2+ n) = x ^ suc₊₁ (2+ n) ≡⟨⟩ x ^ 1+ suc (suc n) ≡⟨⟩ x • (x • x ^ 1+ n) ≡⟨⟩ x • x ^ suc₊₁ (1+ n) ≡⟨ cong (x •_) (^-suc x (1+ n)) ⟩ x • (x ^ 1+ n • x) ≡˘⟨ assoc x (x ^ 1+ n) x ⟩ x • x ^ 1+ n • x ≡⟨⟩ x ^ 2+ n • x ∎ ^-plus : ∀ x → Homomorphic₂ (x ^_) _+₊₁_ _•_ ^-plus _ one _ = refl ^-plus x (2+ m) n = x ^ (1+ (suc m) +₊₁ n) ≡⟨⟩ x • (x ^ (1+ m +₊₁ n)) ≡⟨ cong (x •_) (^-plus x (1+ m) n) ⟩ x • (x ^ 1+ m • x ^ n) ≡˘⟨ assoc x (x ^ 1+ m) (x ^ n) ⟩ x • x ^ 1+ m • x ^ n ≡⟨⟩ x ^ 2+ m • x ^ n ∎ module Kernel {S : Semigroup ℓ} {T : Semigroup ℓ′} (hom : SemigroupHom S T) where private module S = Semigroup S module T = Semigroup T open SemigroupHom hom renaming (fun to f) Kernel′ : RawRel ⟨ S ⟩ ℓ′ Kernel′ x y = f x ≡ f y isPropKernel : isPropValued Kernel′ isPropKernel x y = T.is-set (f x) (f y) Kernel : Rel ⟨ S ⟩ ℓ′ Kernel = fromRaw Kernel′ isPropKernel ker-reflexive : Reflexive Kernel ker-reflexive = refl ker-fromEq : FromEq Kernel ker-fromEq = rec (isPropKernel _ _) (cong f) ker-symmetric : Symmetric Kernel ker-symmetric = sym ker-transitive : Transitive Kernel ker-transitive = _∙_ ker-isPreorder : IsPreorder Kernel ker-isPreorder = record { reflexive = ker-reflexive ; transitive = ker-transitive } ker-isPartialEquivalence : IsPartialEquivalence Kernel ker-isPartialEquivalence = record { symmetric = ker-symmetric ; transitive = ker-transitive } ker-isEquivalence : IsEquivalence Kernel ker-isEquivalence = record { isPartialEquivalence = ker-isPartialEquivalence ; reflexive = ker-reflexive } ker⇒id→emb : Kernel ⇒ _≡ₚ_ → isEmbedding f ker⇒id→emb ker⇒id = injEmbedding S.is-set T.is-set (λ p → rec (S.is-set _ _) id (ker⇒id p)) emb→ker⇒id : isEmbedding f → Kernel ⇒ _≡ₚ_ emb→ker⇒id isemb {x} {y} = ∣_∣ ∘ invIsEq (isemb x y)
algebraic-stack_agda0000_doc_58
{-# OPTIONS --prop #-} data _≡_ {A : Set} (a : A) : A → Set where refl : a ≡ a postulate funextP : {A : Prop} {B : A → Set} {f g : (a : A) → B a} (h : (x : A) → f x ≡ g x) → f ≡ g test : {A : Prop} {B : A → Set} {f g : (a : A) → B a} (h : (x : A) → f x ≡ g x) → f ≡ g test h = funextP h
algebraic-stack_agda0000_doc_59
------------------------------------------------------------------------------ -- Parametrized preorder reasoning ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module Common.Relation.Binary.PreorderReasoning {D : Set} (_∼_ : D → D → Set) (refl : ∀ {x} → x ∼ x) (trans : ∀ {x y z} → x ∼ y → y ∼ z → x ∼ z) where infix 3 _∎ infixr 2 _∼⟨_⟩_ ------------------------------------------------------------------------------ -- From (Mu, S.-C., Ko, H.-S. and Jansson, P. (2009)). -- -- N.B. Unlike Ulf's thesis (and the Agda standard library 0.8.1) this -- set of combinators do not use a wrapper data type. _∼⟨_⟩_ : ∀ x {y z} → x ∼ y → y ∼ z → x ∼ z _ ∼⟨ x∼y ⟩ y∼z = trans x∼y y∼z _∎ : ∀ x → x ∼ x _∎ _ = refl ------------------------------------------------------------------------------ -- References -- -- Mu, S.-C., Ko, H.-S. and Jansson, P. (2009). Algebra of programming -- in Agda: Dependent types for relational program derivation. Journal -- of Functional Programming 19.5, pp. 545–579.
algebraic-stack_agda0000_doc_60
{-# OPTIONS --without-K #-} module SubstLemmas where open import Level using (Level) open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; subst; cong₂) open import Data.Nat using (ℕ; _+_; _*_) ------------------------------------------------------------------------------ -- Lemmas about subst (and a couple about trans) subst-dist : {a b : Level} {A : Set a} {B : A → Set b} (f : {x : A} → B x → B x → B x) → {x₁ x₂ : A} → (x₂≡x₁ : x₂ ≡ x₁) → (v₁ v₂ : B x₂) → subst B x₂≡x₁ (f v₁ v₂) ≡ f (subst B x₂≡x₁ v₁) (subst B x₂≡x₁ v₂) subst-dist f refl v₁ v₂ = refl subst-trans : {a b : Level} {A : Set a} {B : A → Set b} {x₁ x₂ x₃ : A} → (x₂≡x₁ : x₂ ≡ x₁) → (x₃≡x₂ : x₃ ≡ x₂) → (v : B x₃) → subst B x₂≡x₁ (subst B x₃≡x₂ v) ≡ subst B (trans x₃≡x₂ x₂≡x₁) v subst-trans refl refl v = refl subst₂+ : {b : Level} {B : ℕ → Set b} {x₁ x₂ x₃ x₄ : ℕ} → (x₂≡x₁ : x₂ ≡ x₁) → (x₄≡x₃ : x₄ ≡ x₃) → (v₁ : B x₂) → (v₂ : B x₄) → (f : {x₁ x₂ : ℕ} → B x₁ → B x₂ → B (x₁ + x₂)) → subst B (cong₂ _+_ x₂≡x₁ x₄≡x₃) (f v₁ v₂) ≡ f (subst B x₂≡x₁ v₁) (subst B x₄≡x₃ v₂) subst₂+ refl refl v₁ v₂ f = refl subst₂* : {b : Level} {B : ℕ → Set b} {x₁ x₂ x₃ x₄ : ℕ} → (x₂≡x₁ : x₂ ≡ x₁) → (x₄≡x₃ : x₄ ≡ x₃) → (v₁ : B x₂) → (v₂ : B x₄) → (f : {x₁ x₂ : ℕ} → B x₁ → B x₂ → B (x₁ * x₂)) → subst B (cong₂ _*_ x₂≡x₁ x₄≡x₃) (f v₁ v₂) ≡ f (subst B x₂≡x₁ v₁) (subst B x₄≡x₃ v₂) subst₂* refl refl v₁ v₂ f = refl trans-syml : {A : Set} {x y : A} → (p : x ≡ y) → trans (sym p) p ≡ refl trans-syml refl = refl trans-symr : {A : Set} {x y : A} → (p : x ≡ y) → trans p (sym p) ≡ refl trans-symr refl = refl subst-subst : {a b : Level} {A : Set a} {B : A → Set b} {x y : A} → (eq : x ≡ y) → (eq' : y ≡ x) → (irr : sym eq ≡ eq') → (v : B y) → subst B eq (subst B eq' v) ≡ v subst-subst refl .refl refl v = refl
algebraic-stack_agda0000_doc_61
-- Andreas, 2015-12-29 -- with-clause stripping for record patterns -- {-# OPTIONS -v tc.with.strip:60 #-} record R : Set1 where field f : Set test : R → Set1 test record{ f = a } with a ... | x = R test1 : R → Set1 test1 record{ f = a } with a test1 record{ f = a } | _ = R test2 : R → Set1 test2 record{ f = a } with a test2 record{ f = _ } | _ = R -- Visible fields may be missing. test3 : R → Set1 test3 record{ f = a } with a test3 record{} | _ = R -- With-clauses may specify more fields than the parent test4 : R → Set1 test4 record{} with R test4 record{ f = _ } | _ = R -- all should pass
algebraic-stack_agda0000_doc_62
{-# OPTIONS --without-K --safe #-} module TypeTheory.HoTT.Data.Sum.Properties where -- agda-stdlib open import Level open import Data.Empty open import Data.Product open import Data.Sum open import Function.Base open import Relation.Binary.PropositionalEquality open import Relation.Nullary -- agda-misc open import TypeTheory.HoTT.Base private variable a b : Level A : Set a B : Set b isProp-⊎ : ¬ (A × B) → isProp A → isProp B → isProp (A ⊎ B) isProp-⊎ ¬[A×B] A-isP B-isP (inj₁ x₁) (inj₁ x₂) = cong inj₁ (A-isP x₁ x₂) isProp-⊎ ¬[A×B] A-isP B-isP (inj₁ x₁) (inj₂ y₂) = ⊥-elim $ ¬[A×B] (x₁ , y₂) isProp-⊎ ¬[A×B] A-isP B-isP (inj₂ y₁) (inj₁ x₂) = ⊥-elim $ ¬[A×B] (x₂ , y₁) isProp-⊎ ¬[A×B] A-isP B-isP (inj₂ y₁) (inj₂ y₂) = cong inj₂ (B-isP y₁ y₂)
algebraic-stack_agda0000_doc_63
module Proofs where open import Agda.Builtin.Equality open import Relation.Binary.PropositionalEquality.Core open import Data.Nat open ≡-Reasoning open import Classes data Vec : ℕ → Set → Set where Nil : ∀ {a} → Vec 0 a Cons : ∀ {n A} → (a : A) → Vec n A → Vec (suc n) A cons-cong : ∀ {n A} {a c : A} {b d : Vec n A} → a ≡ c → b ≡ d → Cons a b ≡ Cons c d cons-cong {_} {_} {a} {c} {b} {d} p q = begin Cons a b ≡⟨ cong (λ x → Cons a x) q ⟩ Cons a d ≡⟨ cong (λ x → Cons x d) p ⟩ Cons c d ∎ instance VecF : {n : ℕ} → Functor (Vec n) VecF = record { fmap = fmap' ; F-id = id' ; F-∘ = comp' } where fmap' : ∀ {n A B} → (A → B) → Vec n A → Vec n B fmap' f Nil = Nil fmap' f (Cons a v) = Cons (f a) (fmap' f v) id' : ∀ {n A} → (a : Vec n A) → fmap' id a ≡ a id' Nil = refl id' (Cons a v) = cong (λ w → Cons a w) (id' v) comp' : ∀ {n A B C} → (g : B → C) (f : A → B) (a : Vec n A) → fmap' (g ∘ f) a ≡ (fmap' g ∘ fmap' f) a comp' g f Nil = refl comp' g f (Cons a v) = cons-cong refl (comp' g f v) full : ∀ {A} → A → (n : ℕ) → Vec n A full x zero = Nil full x (suc n) = Cons x (full x n) zipWith : ∀ {n A B C} → (A → B → C) → Vec n A → Vec n B → Vec n C zipWith _ Nil Nil = Nil zipWith f (Cons a v) (Cons b w) = Cons (f a b) (zipWith f v w) instance VecA : {n : ℕ} → Applicative (Vec n) VecA {n} = record { pure = λ x → full x n ; _<*>_ = ap' ; A-id = id' ; A-∘ = comp' ; A-hom = hom' ; A-ic = ic' } where ap' : ∀ {n A B} (v : Vec n (A → B)) (w : Vec n A) → Vec n B ap' Nil Nil = Nil ap' (Cons a v) (Cons b w) = Cons (a b) (ap' v w) id' : ∀ {n A} (v : Vec n A) → ap' (full id n) v ≡ v id' Nil = refl id' (Cons a v) = cons-cong refl (id' v) comp' : ∀ {n A B C} → (u : Vec n (B → C)) (v : Vec n (A → B)) (w : Vec n A) → ap' (ap' (ap' (full _∘_ n) u) v) w ≡ ap' u (ap' v w) comp' Nil Nil Nil = refl comp' (Cons a u) (Cons b v) (Cons c w) = cons-cong refl (comp' u v w) hom' : ∀ {n A B} (f : A → B) (x : A) → ap' (full f n) (full x n) ≡ full (f x) n hom' {zero} f x = refl hom' {suc n} f x = cons-cong refl (hom' {n} f x) ic' : ∀ {n A B} (u : Vec n (A → B)) (y : A) → ap' u (full y n) ≡ ap' (full (_$ y) n) u ic' Nil y = refl ic' (Cons a u) y = cons-cong refl (ic' u y) tail : ∀ {n A} → Vec (suc n) A → Vec n A tail (Cons x v) = v diag : ∀ {n A} → Vec n (Vec n A) → Vec n A diag Nil = Nil diag (Cons (Cons a w) v) = Cons a (diag (fmap tail v)) fmap-pure : ∀ {A B F} {{aF : Applicative F}} (f : A → B) (x : A) → fmap f (Applicative.pure aF x) ≡ Applicative.pure aF (f x) fmap-pure f x = begin fmap f (pure x) ≡⟨ sym (appFun f (pure x)) ⟩ pure f <*> pure x ≡⟨ A-hom f x ⟩ pure (f x) ∎ diag-full : ∀ {A} (n : ℕ) (v : Vec n A) → diag (full v n) ≡ v diag-full _ Nil = refl diag-full (suc n) (Cons a v) = cons-cong refl (begin diag (fmap tail (full (Cons a v) n)) ≡⟨ cong diag (fmap-pure tail (Cons a v)) ⟩ diag (full v n) ≡⟨ diag-full n v ⟩ v ∎) instance VecM : {n : ℕ} → Monad (Vec n) VecM = record { _>>=_ = bind' ; left-1 = left' ; right-1 = {!!} ; assoc = {!!} } where bind' : ∀ {n A B} → Vec n A → (A → Vec n B) → Vec n B bind' v f = diag (fmap f v) left' : ∀ {n A B} (a : A) (k : A → Vec n B) → bind' (pure a) k ≡ k a left' {n} a k = begin diag (fmap k (full a n)) ≡⟨ cong diag (fmap-pure k a) ⟩ diag (full (k a) n) ≡⟨ diag-full n (k a) ⟩ k a ∎ right' : ∀ {n A} (m : Vec n A) → bind' m pure ≡ m right' Nil = refl right' (Cons a m) = begin bind' (Cons a m) pure ≡⟨ refl ⟩ diag (fmap pure (Cons a m)) ≡⟨ cons-cong refl {!!} ⟩ -- :( Cons a m ∎
algebraic-stack_agda0000_doc_5984
{-# OPTIONS --without-K #-} module WithoutK8 where data I : Set where i : I module M (x : I) where data D : Set where d : D data P : D → Set where postulate x : I open module M′ = M x Foo : P d → Set Foo ()
algebraic-stack_agda0000_doc_5985
module Human.List where open import Human.Nat infixr 5 _,_ data List {a} (A : Set a) : Set a where end : List A _,_ : (x : A) (xs : List A) → List A {-# BUILTIN LIST List #-} {-# COMPILE JS List = function(x,v) { if (x.length < 1) { return v["[]"](); } else { return v["_∷_"](x[0], x.slice(1)); } } #-} {-# COMPILE JS end = Array() #-} {-# COMPILE JS _,_ = function (x) { return function(y) { return Array(x).concat(y); }; } #-} foldr : ∀ {A : Set} {B : Set} → (A → B → B) → B → List A → B foldr c n end = n foldr c n (x , xs) = c x (foldr c n xs) length : ∀ {A : Set} → List A → Nat length = foldr (λ a n → suc n) zero -- TODO -- -- filter -- reduce -- Receives a function that transforms each element of A, a function A and a new list, B. map : ∀ {A : Set} {B : Set} → (f : A → B) → List A → List B map f end = end map f (x , xs) = (f x) , (map f xs) -- f transforms element x, return map to do a new transformation -- Sum all numbers in a list sum : List Nat → Nat sum end = zero sum (x , l) = x + (sum l) remove-last : ∀ {A : Set} → List A → List A remove-last end = end remove-last (x , l) = l
algebraic-stack_agda0000_doc_5986
{-# OPTIONS --safe #-} module Cubical.Data.Vec.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.HLevels open import Cubical.Foundations.Univalence import Cubical.Data.Empty as ⊥ open import Cubical.Data.Unit open import Cubical.Data.Nat open import Cubical.Data.Sigma open import Cubical.Data.Sum open import Cubical.Data.Vec.Base open import Cubical.Data.FinData open import Cubical.Relation.Nullary open Iso private variable ℓ : Level A : Type ℓ -- This is really cool! -- Compare with: https://github.com/agda/agda-stdlib/blob/master/src/Data/Vec/Properties/WithK.agda#L32 ++-assoc : ∀ {m n k} (xs : Vec A m) (ys : Vec A n) (zs : Vec A k) → PathP (λ i → Vec A (+-assoc m n k (~ i))) ((xs ++ ys) ++ zs) (xs ++ ys ++ zs) ++-assoc {m = zero} [] ys zs = refl ++-assoc {m = suc m} (x ∷ xs) ys zs i = x ∷ ++-assoc xs ys zs i -- Equivalence between Fin n → A and Vec A n FinVec→Vec : {n : ℕ} → FinVec A n → Vec A n FinVec→Vec {n = zero} xs = [] FinVec→Vec {n = suc _} xs = xs zero ∷ FinVec→Vec (λ x → xs (suc x)) Vec→FinVec : {n : ℕ} → Vec A n → FinVec A n Vec→FinVec xs f = lookup f xs FinVec→Vec→FinVec : {n : ℕ} (xs : FinVec A n) → Vec→FinVec (FinVec→Vec xs) ≡ xs FinVec→Vec→FinVec {n = zero} xs = funExt λ f → ⊥.rec (¬Fin0 f) FinVec→Vec→FinVec {n = suc n} xs = funExt goal where goal : (f : Fin (suc n)) → Vec→FinVec (xs zero ∷ FinVec→Vec (λ x → xs (suc x))) f ≡ xs f goal zero = refl goal (suc f) i = FinVec→Vec→FinVec (λ x → xs (suc x)) i f Vec→FinVec→Vec : {n : ℕ} (xs : Vec A n) → FinVec→Vec (Vec→FinVec xs) ≡ xs Vec→FinVec→Vec {n = zero} [] = refl Vec→FinVec→Vec {n = suc n} (x ∷ xs) i = x ∷ Vec→FinVec→Vec xs i FinVecIsoVec : (n : ℕ) → Iso (FinVec A n) (Vec A n) FinVecIsoVec n = iso FinVec→Vec Vec→FinVec Vec→FinVec→Vec FinVec→Vec→FinVec FinVec≃Vec : (n : ℕ) → FinVec A n ≃ Vec A n FinVec≃Vec n = isoToEquiv (FinVecIsoVec n) FinVec≡Vec : (n : ℕ) → FinVec A n ≡ Vec A n FinVec≡Vec n = ua (FinVec≃Vec n) isContrVec0 : isContr (Vec A 0) isContrVec0 = [] , λ { [] → refl } -- encode - decode Vec module VecPath {A : Type ℓ} where code : {n : ℕ} → (v v' : Vec A n) → Type ℓ code [] [] = Unit* code (a ∷ v) (a' ∷ v') = (a ≡ a') × (v ≡ v') -- encode reflEncode : {n : ℕ} → (v : Vec A n) → code v v reflEncode [] = tt* reflEncode (a ∷ v) = refl , refl encode : {n : ℕ} → (v v' : Vec A n) → (v ≡ v') → code v v' encode v v' p = J (λ v' _ → code v v') (reflEncode v) p encodeRefl : {n : ℕ} → (v : Vec A n) → encode v v refl ≡ reflEncode v encodeRefl v = JRefl (λ v' _ → code v v') (reflEncode v) -- decode decode : {n : ℕ} → (v v' : Vec A n) → (r : code v v') → (v ≡ v') decode [] [] _ = refl decode (a ∷ v) (a' ∷ v') (p , q) = cong₂ _∷_ p q decodeRefl : {n : ℕ} → (v : Vec A n) → decode v v (reflEncode v) ≡ refl decodeRefl [] = refl decodeRefl (a ∷ v) = refl -- equiv ≡Vec≃codeVec : {n : ℕ} → (v v' : Vec A n) → (v ≡ v') ≃ (code v v') ≡Vec≃codeVec v v' = isoToEquiv is where is : Iso (v ≡ v') (code v v') fun is = encode v v' inv is = decode v v' rightInv is = sect v v' where sect : {n : ℕ} → (v v' : Vec A n) → (r : code v v') → encode v v' (decode v v' r) ≡ r sect [] [] tt* = encodeRefl [] sect (a ∷ v) (a' ∷ v') (p , q) = J (λ a' p → encode (a ∷ v) (a' ∷ v') (decode (a ∷ v) (a' ∷ v') (p , q)) ≡ (p , q)) (J (λ v' q → encode (a ∷ v) (a ∷ v') (decode (a ∷ v) (a ∷ v') (refl , q)) ≡ (refl , q)) (encodeRefl (a ∷ v)) q) p leftInv is = retr v v' where retr : {n : ℕ} → (v v' : Vec A n) → (p : v ≡ v') → decode v v' (encode v v' p) ≡ p retr v v' p = J (λ v' p → decode v v' (encode v v' p) ≡ p) (cong (decode v v) (encodeRefl v) ∙ decodeRefl v) p isOfHLevelVec : (h : HLevel) (n : ℕ) → isOfHLevel (suc (suc h)) A → isOfHLevel (suc (suc h)) (Vec A n) isOfHLevelVec h zero ofLevelA [] [] = isOfHLevelRespectEquiv (suc h) (invEquiv (≡Vec≃codeVec [] [])) (isOfHLevelUnit* (suc h)) isOfHLevelVec h (suc n) ofLevelA (x ∷ v) (x' ∷ v') = isOfHLevelRespectEquiv (suc h) (invEquiv (≡Vec≃codeVec _ _)) (isOfHLevelΣ (suc h) (ofLevelA x x') (λ _ → isOfHLevelVec h n ofLevelA v v')) discreteA→discreteVecA : Discrete A → (n : ℕ) → Discrete (Vec A n) discreteA→discreteVecA DA zero [] [] = yes refl discreteA→discreteVecA DA (suc n) (a ∷ v) (a' ∷ v') with (DA a a') | (discreteA→discreteVecA DA n v v') ... | yes p | yes q = yes (invIsEq (snd (≡Vec≃codeVec (a ∷ v) (a' ∷ v'))) (p , q)) ... | yes p | no ¬q = no (λ r → ¬q (snd (funIsEq (snd (≡Vec≃codeVec (a ∷ v) (a' ∷ v'))) r))) ... | no ¬p | yes q = no (λ r → ¬p (fst (funIsEq (snd (≡Vec≃codeVec (a ∷ v) (a' ∷ v'))) r))) ... | no ¬p | no ¬q = no (λ r → ¬q (snd (funIsEq (snd (≡Vec≃codeVec (a ∷ v) (a' ∷ v'))) r))) ≢-∷ : {m : ℕ} → (Discrete A) → (a : A) → (v : Vec A m) → (a' : A) → (v' : Vec A m) → (a ∷ v ≡ a' ∷ v' → ⊥.⊥) → (a ≡ a' → ⊥.⊥) ⊎ (v ≡ v' → ⊥.⊥) ≢-∷ {m} discreteA a v a' v' ¬r with (discreteA a a') | (discreteA→discreteVecA discreteA m v v') ... | yes p | yes q = ⊥.rec (¬r (cong₂ _∷_ p q)) ... | yes p | no ¬q = inr ¬q ... | no ¬p | y = inl ¬p
algebraic-stack_agda0000_doc_5987
module Oscar.Data.AList where open import Oscar.Data.Equality open import Oscar.Data.Nat open import Oscar.Level module _ {a} (A : Nat → Set a) where data AList (n : Nat) : Nat → Set a where [] : AList n n _∷_ : ∀ {m} → A m → AList n m → AList n (suc m) open import Oscar.Category module Category' {a} {A : Nat → Set a} where _⊸_ = AList A infix 4 _≋_ _≋_ : ∀ {m n} → m ⊸ n → m ⊸ n → Set a _≋_ = _≡_ infixr 9 _∙_ _∙_ : ∀ {m n} → m ⊸ n → ∀ {l} → l ⊸ m → l ⊸ n [] ∙ ρ = ρ (x ∷ σ) ∙ ρ = x ∷ (σ ∙ ρ) ∙-associativity : ∀ {k l} (f : k ⊸ l) {m} (g : l ⊸ m) {n} (h : m ⊸ n) → (h ∙ g) ∙ f ≋ h ∙ g ∙ f ∙-associativity f g [] = refl ∙-associativity f g (x ∷ h) = cong (x ∷_) (∙-associativity f g h) ε : ∀ {n} → n ⊸ n ε = [] ∙-left-identity : ∀ {m n} (σ : m ⊸ n) → ε ∙ σ ≋ σ ∙-left-identity _ = refl ∙-right-identity : ∀ {m n} (σ : m ⊸ n) → σ ∙ ε ≋ σ ∙-right-identity [] = refl ∙-right-identity (x ∷ σ) = cong (x ∷_) (∙-right-identity σ) semigroupoidAList : Semigroupoid (AList A) (λ {x y} → ≡-setoid (AList A x y)) Semigroupoid._∙_ semigroupoidAList = _∙_ Semigroupoid.∙-extensionality semigroupoidAList refl refl = refl Semigroupoid.∙-associativity semigroupoidAList = ∙-associativity categoryAList : Category semigroupoidAList Category.ε categoryAList = ε Category.ε-left-identity categoryAList = ∙-left-identity _ Category.ε-right-identity categoryAList = ∙-right-identity _ -- ∙-associativity σ _ [] = refl -- ∙-associativity (τ asnoc t / x) ρ σ = cong (λ s → s asnoc t / x) (∙-associativity τ ρ σ) -- -- semigroupoid : ∀ {a} (A : Nat → Set a) → Semigroupoid a a ∅̂ -- -- Semigroupoid._∙_ = semigroupoid -- -- -- record Semigroupoid -- -- -- {𝔬} {𝔒 : -- -- -- -- module Oscar.Data.AList {𝔣} (FunctionName : Set 𝔣) where -- -- -- -- open import Oscar.Data.Fin -- -- -- -- open import Oscar.Data.Nat -- -- -- -- open import Oscar.Data.Product -- -- -- -- open import Oscar.Data.Term FunctionName -- -- -- -- open import Oscar.Data.IList -- -- -- -- pattern anil = [] -- -- -- -- pattern _asnoc_/_ σ t' x = (t' , x) ∷ σ -- -- -- -- AList : Nat → Nat → Set 𝔣 -- -- -- -- AList m n = IList (λ m → Term m × Fin (suc m)) n m -- -- -- -- -- data AList' (n : Nat) : Nat -> Set 𝔣 where -- -- -- -- -- anil : AList' n n -- -- -- -- -- _asnoc_/_ : ∀ {m} (σ : AList' n m) (t' : Term m) (x : Fin (suc m)) -- -- -- -- -- -> AList' n (suc m) -- -- -- -- -- open import Oscar.Function -- -- -- -- -- --AList = flip AList' -- -- -- -- -- -- data AList : Nat -> Nat -> Set 𝔣 where -- -- -- -- -- -- anil : ∀ {n} -> AList n n -- -- -- -- -- -- _asnoc_/_ : ∀ {m n} (σ : AList m n) (t' : Term m) (x : Fin (suc m)) -- -- -- -- -- -- -> AList (suc m) n -- -- -- -- -- -- -- open import Relation.Binary.PropositionalEquality renaming ([_] to [[_]]) -- -- -- -- -- -- -- open ≡-Reasoning -- -- -- -- -- -- -- step-prop : ∀ {m n} (s t : Term (suc m)) (σ : AList m n) r z -> -- -- -- -- -- -- -- (Unifies s t [-◇ sub (σ asnoc r / z) ]) ⇔ (Unifies ((r for z) ◃ s) ((r for z) ◃ t) [-◇ sub σ ]) -- -- -- -- -- -- -- step-prop s t σ r z f = to , from -- -- -- -- -- -- -- where -- -- -- -- -- -- -- lemma1 : ∀ t -> (f ◇ sub σ) ◃ ((r for z) ◃ t) ≡ (f ◇ (sub σ ◇ (r for z))) ◃ t -- -- -- -- -- -- -- lemma1 t = bind-assoc f (sub σ) (r for z) t -- -- -- -- -- -- -- to = λ a → begin -- -- -- -- -- -- -- (f ◇ sub σ) ◃ ((r for z) ◃ s) ≡⟨ lemma1 s ⟩ -- -- -- -- -- -- -- (f ◇ (sub σ ◇ (r for z))) ◃ s ≡⟨ a ⟩ -- -- -- -- -- -- -- (f ◇ (sub σ ◇ (r for z))) ◃ t ≡⟨ sym (lemma1 t) ⟩ -- -- -- -- -- -- -- (f ◇ sub σ) ◃ ((r for z) ◃ t) ∎ -- -- -- -- -- -- -- from = λ a → begin -- -- -- -- -- -- -- (f ◇ (sub σ ◇ (r for z))) ◃ s ≡⟨ sym (lemma1 s) ⟩ -- -- -- -- -- -- -- (f ◇ sub σ) ◃ ((r for z) ◃ s) ≡⟨ a ⟩ -- -- -- -- -- -- -- (f ◇ sub σ) ◃ ((r for z) ◃ t) ≡⟨ lemma1 t ⟩ -- -- -- -- -- -- -- (f ◇ (sub σ ◇ (r for z))) ◃ t ∎ -- -- -- -- -- -- -- record ⋆amgu (T : ℕ → Set) : Set where -- -- -- -- -- -- -- field amgu : ∀ {m} (s t : T m) (acc : ∃ (AList m)) -> Maybe (∃ (AList m)) -- -- -- -- -- -- -- open ⋆amgu ⦃ … ⦄ public -- -- -- -- -- -- -- open import Category.Monad using (RawMonad) -- -- -- -- -- -- -- import Level -- -- -- -- -- -- -- open RawMonad (Data.Maybe.monad {Level.zero}) -- -- -- -- -- -- -- open import Relation.Binary using (IsDecEquivalence) -- -- -- -- -- -- -- open import Relation.Nullary using (Dec; yes; no) -- -- -- -- -- -- -- open import Data.Nat using (ℕ; _≟_) -- -- -- -- -- -- -- open import Data.Product using () renaming (Σ to Σ₁) -- -- -- -- -- -- -- open Σ₁ renaming (proj₁ to π₁; proj₂ to π₂) -- -- -- -- -- -- -- open import Data.Product using (Σ) -- -- -- -- -- -- -- open Σ -- -- -- -- -- -- -- open import Data.Sum -- -- -- -- -- -- -- open import Function -- -- -- -- -- -- -- NothingForkLeft : ∀ {m l} (s1 t1 : Term m) (ρ : AList m l) (s2 t2 : Term m) → -- -- -- -- -- -- -- Nothing⋆ $ Unifies⋆ s1 t1 [-◇⋆ sub ρ ] → -- -- -- -- -- -- -- Nothing⋆ $ Unifies⋆ (s1 fork s2) (t1 fork t2) [-◇⋆ sub ρ ] -- -- -- -- -- -- -- NothingForkLeft s1 t1 ρ s2 t2 nounify = No[Q◇ρ]→No[P◇ρ] No[Q◇ρ] -- -- -- -- -- -- -- where -- -- -- -- -- -- -- P = Unifies⋆ (s1 fork s2) (t1 fork t2) -- -- -- -- -- -- -- Q = (Unifies⋆ s1 t1 ∧⋆ Unifies⋆ s2 t2) -- -- -- -- -- -- -- Q⇔P : Q ⇔⋆ P -- -- -- -- -- -- -- Q⇔P = switch⋆ P Q (Properties.fact1' {_} {s1} {s2} {t1} {t2}) -- -- -- -- -- -- -- No[Q◇ρ]→No[P◇ρ] : Nothing⋆ (Q [-◇⋆ sub ρ ]) -> Nothing⋆ (P [-◇⋆ sub ρ ]) -- -- -- -- -- -- -- No[Q◇ρ]→No[P◇ρ] = Properties.fact2⋆ (Q [-◇⋆ sub ρ ]) (P [-◇⋆ sub ρ ]) (Properties.fact5⋆ Q P (sub ρ) Q⇔P) -- -- -- -- -- -- -- No[Q◇ρ] : Nothing⋆ (Q [-◇⋆ sub ρ ]) -- -- -- -- -- -- -- No[Q◇ρ] = failure-propagation.first⋆ (sub ρ) (Unifies⋆ s1 t1) (Unifies⋆ s2 t2) nounify -- -- -- -- -- -- -- NothingForkRight : ∀ {m l n} (σ : AList l n) -- -- -- -- -- -- -- (s1 s2 : Term m) -- -- -- -- -- -- -- (t1 t2 : Term m) → -- -- -- -- -- -- -- (ρ : AList m l) → -- -- -- -- -- -- -- Max⋆ (Unifies⋆ s1 t1 [-◇⋆ sub ρ ]) $ sub σ → -- -- -- -- -- -- -- Nothing⋆ $ Unifies⋆ s2 t2 [-◇⋆ sub (σ ++ ρ) ] → -- -- -- -- -- -- -- Nothing⋆ $ Unifies⋆ (s1 fork s2) (t1 fork t2) [-◇⋆ sub ρ ] -- -- -- -- -- -- -- NothingForkRight σ s1 s2 t1 t2 ρ a nounify = No[Q◇ρ]→No[P◇ρ]⋆ No[Q◇ρ]⋆ -- -- -- -- -- -- -- where -- -- -- -- -- -- -- P⋆ = Unifies⋆ (s1 fork s2) (t1 fork t2) -- -- -- -- -- -- -- Q⋆ = (Unifies⋆ s1 t1 ∧⋆ Unifies⋆ s2 t2) -- -- -- -- -- -- -- Q⇔P⋆ : Q⋆ ⇔⋆ P⋆ -- -- -- -- -- -- -- Q⇔P⋆ = switch⋆ P⋆ Q⋆ (Properties.fact1'⋆ {_} {s1} {s2} {t1} {t2}) -- -- -- -- -- -- -- No[Q◇ρ]→No[P◇ρ]⋆ : Nothing⋆ (Q⋆ [-◇⋆ sub ρ ]) -> Nothing⋆ (P⋆ [-◇⋆ sub ρ ]) -- -- -- -- -- -- -- No[Q◇ρ]→No[P◇ρ]⋆ = Properties.fact2⋆ (Q⋆ [-◇⋆ sub ρ ]) (P⋆ [-◇⋆ sub ρ ]) (Properties.fact5⋆ Q⋆ P⋆ (sub ρ) Q⇔P⋆) -- -- -- -- -- -- -- No[Q◇ρ]⋆ : Nothing⋆ (Q⋆ [-◇⋆ sub ρ ]) -- -- -- -- -- -- -- No[Q◇ρ]⋆ = failure-propagation.second⋆ (sub ρ) (sub σ) (Unifies⋆ s1 t1) (Unifies s2 t2) a -- -- -- -- -- -- -- (λ f → nounify f ∘ π₂ (Unifies s2 t2) (cong (f ◃_) ∘ sym ∘ SubList.fact1 σ ρ)) -- -- -- -- -- -- -- MaxFork : ∀ {m l n n1} (s1 s2 t1 t2 : Term m) -- -- -- -- -- -- -- (ρ : AList m l) (σ : AList l n) → -- -- -- -- -- -- -- Max⋆ (Unifies⋆ s1 t1 [-◇⋆ sub ρ ]) $ sub σ → -- -- -- -- -- -- -- (σ1 : AList n n1) → -- -- -- -- -- -- -- Max⋆ (Unifies⋆ s2 t2 [-◇⋆ sub (σ ++ ρ) ]) $ sub σ1 → -- -- -- -- -- -- -- Max⋆ (Unifies⋆ (s1 fork s2) (t1 fork t2) [-◇⋆ sub ρ ]) $ sub (σ1 ++ σ) -- -- -- -- -- -- -- MaxFork s1 s2 t1 t2 ρ σ a σ1 b = Max[P∧Q◇ρ][σ1++σ] -- -- -- -- -- -- -- where -- -- -- -- -- -- -- P = Unifies s1 t1 -- -- -- -- -- -- -- Q = Unifies s2 t2 -- -- -- -- -- -- -- P∧Q = P ∧ Q -- -- -- -- -- -- -- C = Unifies (s1 fork s2) (t1 fork t2) -- -- -- -- -- -- -- Max[C◇ρ]⇔Max[P∧Q◇ρ] : Max (C [-◇ sub ρ ]) ⇔ Max (P∧Q [-◇ sub ρ ]) -- -- -- -- -- -- -- Max[C◇ρ]⇔Max[P∧Q◇ρ] = Max.fact (C [-◇ sub ρ ]) (P∧Q [-◇ sub ρ ]) (Properties.fact5 C P∧Q (sub ρ) -- -- -- -- -- -- -- (Properties.fact1' {_} {s1} {s2} {t1} {t2})) -- -- -- -- -- -- -- Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] : Max (Q [-◇ sub (σ ++ ρ)]) ⇔ Max (Q [-◇ sub σ ◇ sub ρ ]) -- -- -- -- -- -- -- Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] = Max.fact (Q [-◇ sub (σ ++ ρ)]) (Q [-◇ sub σ ◇ sub ρ ]) (Properties.fact6 Q (SubList.fact1 σ ρ)) -- -- -- -- -- -- -- Max[P∧Q◇ρ][σ1++σ] : π₁ (Max (C [-◇ sub ρ ])) (sub (σ1 ++ σ)) -- -- -- -- -- -- -- Max[P∧Q◇ρ][σ1++σ] = π₂ (Max (C [-◇ sub ρ ])) (≐-sym (SubList.fact1 σ1 σ)) -- -- -- -- -- -- -- (proj₂ (Max[C◇ρ]⇔Max[P∧Q◇ρ] (sub σ1 ◇ sub σ)) -- -- -- -- -- -- -- (optimist (sub ρ) (sub σ) (sub σ1) P Q (DClosed.fact1 s1 t1) a (proj₁ (Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] (sub σ1)) b))) -- -- -- -- -- -- -- NothingVecHead : ∀ {m l} (t₁ t₂ : Term m) (ρ : AList m l) {N} (ts₁ ts₂ : Vec (Term m) N) → -- -- -- -- -- -- -- Nothing⋆ $ Unifies⋆ t₁ t₂ [-◇⋆ sub ρ ] → -- -- -- -- -- -- -- Nothing⋆ $ Unifies⋆V (t₁ ∷ ts₁) (t₂ ∷ ts₂) [-◇⋆ sub ρ ] -- -- -- -- -- -- -- NothingVecHead t₁ t₂ ρ ts₁ ts₂ nounify = No[Q◇ρ]→No[P◇ρ] No[Q◇ρ] -- -- -- -- -- -- -- where -- -- -- -- -- -- -- P = Unifies⋆V (t₁ ∷ ts₁) (t₂ ∷ ts₂) -- -- -- -- -- -- -- Q = (Unifies⋆ t₁ t₂ ∧⋆ Unifies⋆V ts₁ ts₂) -- -- -- -- -- -- -- Q⇔P : Q ⇔⋆ P -- -- -- -- -- -- -- Q⇔P = switch⋆ P Q (Properties.fact1'V {_} {t₁} {t₂} {_} {ts₁} {ts₂}) -- -- -- -- -- -- -- No[Q◇ρ]→No[P◇ρ] : Nothing⋆ (Q [-◇⋆ sub ρ ]) -> Nothing⋆ (P [-◇⋆ sub ρ ]) -- -- -- -- -- -- -- No[Q◇ρ]→No[P◇ρ] = Properties.fact2⋆ (Q [-◇⋆ sub ρ ]) (P [-◇⋆ sub ρ ]) (Properties.fact5⋆ Q P (sub ρ) Q⇔P) -- -- -- -- -- -- -- No[Q◇ρ] : Nothing⋆ (Q [-◇⋆ sub ρ ]) -- -- -- -- -- -- -- No[Q◇ρ] = failure-propagation.first⋆ (sub ρ) (Unifies⋆ t₁ t₂) (Unifies⋆V ts₁ ts₂) nounify -- -- -- -- -- -- -- NothingVecTail : ∀ {m l n} (σ : AList l n) -- -- -- -- -- -- -- (t₁ t₂ : Term m) -- -- -- -- -- -- -- {N} -- -- -- -- -- -- -- (ts₁ ts₂ : Vec (Term m) N) → -- -- -- -- -- -- -- (ρ : AList m l) → -- -- -- -- -- -- -- Max⋆ (Unifies⋆ t₁ t₂ [-◇⋆ sub ρ ]) $ sub σ → -- -- -- -- -- -- -- Nothing⋆ $ Unifies⋆V ts₁ ts₂ [-◇⋆ sub (σ ++ ρ) ] → -- -- -- -- -- -- -- Nothing⋆ $ Unifies⋆V (t₁ ∷ ts₁) (t₂ ∷ ts₂) [-◇⋆ sub ρ ] -- -- -- -- -- -- -- NothingVecTail σ t₁ t₂ ts₁ ts₂ ρ a nounify = No[Q◇ρ]→No[P◇ρ]⋆ No[Q◇ρ]⋆ -- -- -- -- -- -- -- where -- -- -- -- -- -- -- P⋆ = Unifies⋆V (t₁ ∷ ts₁) (t₂ ∷ ts₂) -- -- -- -- -- -- -- Q⋆ = (Unifies⋆ t₁ t₂ ∧⋆ Unifies⋆V ts₁ ts₂) -- -- -- -- -- -- -- Q⇔P⋆ : Q⋆ ⇔⋆ P⋆ -- -- -- -- -- -- -- Q⇔P⋆ = switch⋆ P⋆ Q⋆ (Properties.fact1'V {_} {t₁} {t₂} {_} {ts₁} {ts₂}) -- -- -- -- -- -- -- -- Q⇔P⋆ = switch⋆ P⋆ Q⋆ (Properties.fact1'⋆ {_} {s1} {s2} {t1} {t2}) -- -- -- -- -- -- -- No[Q◇ρ]→No[P◇ρ]⋆ : Nothing⋆ (Q⋆ [-◇⋆ sub ρ ]) -> Nothing⋆ (P⋆ [-◇⋆ sub ρ ]) -- -- -- -- -- -- -- No[Q◇ρ]→No[P◇ρ]⋆ = Properties.fact2⋆ (Q⋆ [-◇⋆ sub ρ ]) (P⋆ [-◇⋆ sub ρ ]) (Properties.fact5⋆ Q⋆ P⋆ (sub ρ) Q⇔P⋆) -- -- -- -- -- -- -- No[Q◇ρ]⋆ : Nothing⋆ (Q⋆ [-◇⋆ sub ρ ]) -- -- -- -- -- -- -- No[Q◇ρ]⋆ = failure-propagation.second⋆ (sub ρ) (sub σ) (Unifies⋆ t₁ t₂) (UnifiesV ts₁ ts₂) a -- -- -- -- -- -- -- (λ f → nounify f ∘ π₂ (UnifiesV ts₁ ts₂) (cong (f ◃_) ∘ sym ∘ SubList.fact1 σ ρ)) -- -- -- -- -- -- -- MaxVec : ∀ {m l n n1} (t₁ t₂ : Term m) {N} (ts₁ ts₂ : Vec (Term m) N) -- -- -- -- -- -- -- (ρ : AList m l) (σ : AList l n) → -- -- -- -- -- -- -- Max⋆ (Unifies⋆ t₁ t₂ [-◇⋆ sub ρ ]) $ sub σ → -- -- -- -- -- -- -- (σ1 : AList n n1) → -- -- -- -- -- -- -- Max⋆ (Unifies⋆V ts₁ ts₂ [-◇⋆ sub (σ ++ ρ) ]) $ sub σ1 → -- -- -- -- -- -- -- Max⋆ (Unifies⋆V (t₁ ∷ ts₁) (t₂ ∷ ts₂) [-◇⋆ sub ρ ]) $ sub (σ1 ++ σ) -- -- -- -- -- -- -- MaxVec t₁ t₂ ts₁ ts₂ ρ σ a σ1 b = Max[P∧Q◇ρ][σ1++σ] -- -- -- -- -- -- -- where -- -- -- -- -- -- -- P = Unifies t₁ t₂ -- -- -- -- -- -- -- Q = UnifiesV ts₁ ts₂ -- -- -- -- -- -- -- P∧Q = P ∧ Q -- -- -- -- -- -- -- C = UnifiesV (t₁ ∷ ts₁) (t₂ ∷ ts₂) -- -- -- -- -- -- -- Max[C◇ρ]⇔Max[P∧Q◇ρ] : Max (C [-◇ sub ρ ]) ⇔ Max (P∧Q [-◇ sub ρ ]) -- -- -- -- -- -- -- Max[C◇ρ]⇔Max[P∧Q◇ρ] = Max.fact (C [-◇ sub ρ ]) (P∧Q [-◇ sub ρ ]) (Properties.fact5 C P∧Q (sub ρ) -- -- -- -- -- -- -- (Properties.fact1'V {_} {t₁} {t₂} {_} {ts₁} {ts₂})) -- -- -- -- -- -- -- Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] : Max (Q [-◇ sub (σ ++ ρ)]) ⇔ Max (Q [-◇ sub σ ◇ sub ρ ]) -- -- -- -- -- -- -- Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] = Max.fact (Q [-◇ sub (σ ++ ρ)]) (Q [-◇ sub σ ◇ sub ρ ]) (Properties.fact6 Q (SubList.fact1 σ ρ)) -- -- -- -- -- -- -- Max[P∧Q◇ρ][σ1++σ] : π₁ (Max (C [-◇ sub ρ ])) (sub (σ1 ++ σ)) -- -- -- -- -- -- -- Max[P∧Q◇ρ][σ1++σ] = π₂ (Max (C [-◇ sub ρ ])) (≐-sym (SubList.fact1 σ1 σ)) -- -- -- -- -- -- -- (proj₂ (Max[C◇ρ]⇔Max[P∧Q◇ρ] (sub σ1 ◇ sub σ)) -- -- -- -- -- -- -- (optimist (sub ρ) (sub σ) (sub σ1) P Q (DClosed.fact1 t₁ t₂) a (proj₁ (Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] (sub σ1)) b))) -- -- -- -- -- -- -- NothingFor→NothingComposition : ∀ {m l} (s t : Term (suc m)) (ρ : AList m l) -- -- -- -- -- -- -- (r : Term m) (z : Fin (suc m)) → -- -- -- -- -- -- -- Nothing⋆ (Unifies⋆ ((r for z) ◃ s) ((r for z) ◃ t) [-◇⋆ sub ρ ]) → -- -- -- -- -- -- -- Nothing⋆ (Unifies⋆ s t [-◇⋆ sub (ρ asnoc r / z) ]) -- -- -- -- -- -- -- NothingFor→NothingComposition s t ρ r z nounify = NoQ→NoP nounify -- -- -- -- -- -- -- where -- -- -- -- -- -- -- P = Unifies s t [-◇ sub (ρ asnoc r / z) ] -- -- -- -- -- -- -- Q = Unifies ((r for z) ◃ s) ((r for z) ◃ t) [-◇ sub ρ ] -- -- -- -- -- -- -- NoQ→NoP : Nothing Q → Nothing P -- -- -- -- -- -- -- NoQ→NoP = Properties.fact2 Q P (switch P Q (step-prop s t ρ r z)) -- -- -- -- -- -- -- MaxFor→MaxComposition : ∀ {m l n} (s t : Term (suc m)) (ρ : AList m l) -- -- -- -- -- -- -- (r : Term m) (z : Fin (suc m)) (σ : AList l n) → -- -- -- -- -- -- -- Max⋆ (Unifies⋆ ((r for z) ◃ s) ((r for z) ◃ t) [-◇⋆ sub ρ ]) $ sub σ → -- -- -- -- -- -- -- Max⋆ (Unifies⋆ s t [-◇⋆ sub (ρ asnoc r / z) ]) $ sub σ -- -- -- -- -- -- -- MaxFor→MaxComposition s t ρ r z σ a = proj₂ (MaxP⇔MaxQ (sub σ)) a -- -- -- -- -- -- -- where -- -- -- -- -- -- -- P = Unifies s t [-◇ sub (ρ asnoc r / z) ] -- -- -- -- -- -- -- Q = Unifies ((r for z) ◃ s) ((r for z) ◃ t) [-◇ sub ρ ] -- -- -- -- -- -- -- MaxP⇔MaxQ : Max P ⇔ Max Q -- -- -- -- -- -- -- MaxP⇔MaxQ = Max.fact P Q (step-prop s t ρ r z) -- -- -- -- -- -- -- module _ ⦃ isDecEquivalenceA : IsDecEquivalence (_≡_ {A = FunctionName}) ⦄ where -- -- -- -- -- -- -- open IsDecEquivalence isDecEquivalenceA using () renaming (_≟_ to _≟F_) -- -- -- -- -- -- -- mutual -- -- -- -- -- -- -- instance ⋆amguTerm : ⋆amgu Term -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguTerm leaf leaf acc = just acc -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguTerm leaf (function _ _) acc = nothing -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguTerm leaf (s' fork t') acc = nothing -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguTerm (s' fork t') leaf acc = nothing -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguTerm (s' fork t') (function _ _) acc = nothing -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguTerm (s1 fork s2) (t1 fork t2) acc = -- -- -- -- -- -- -- amgu s2 t2 =<< amgu s1 t1 acc -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguTerm (function fn₁ ts₁) leaf acc = nothing -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguTerm (function fn₁ {n₁} ts₁) (function fn₂ {n₂} ts₂) acc -- -- -- -- -- -- -- with fn₁ ≟F fn₂ -- -- -- -- -- -- -- … | no _ = nothing -- -- -- -- -- -- -- … | yes _ with n₁ ≟ n₂ -- -- -- -- -- -- -- … | no _ = nothing -- -- -- -- -- -- -- … | yes refl = amgu ts₁ ts₂ acc -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguTerm (function fn₁ ts₁) (_ fork _) acc = nothing -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguTerm (i x) (i y) (m , anil) = just (flexFlex x y) -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguTerm (i x) t (m , anil) = flexRigid x t -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguTerm t (i x) (m , anil) = flexRigid x t -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguTerm s t (n , σ asnoc r / z) = -- -- -- -- -- -- -- (λ σ -> σ ∃asnoc r / z) <$> -- -- -- -- -- -- -- amgu ((r for z) ◃ s) ((r for z) ◃ t) (n , σ) -- -- -- -- -- -- -- instance ⋆amguVecTerm : ∀ {N} → ⋆amgu (flip Vec N ∘ Term) -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguVecTerm [] [] acc = just acc -- -- -- -- -- -- -- ⋆amgu.amgu ⋆amguVecTerm (t₁ ∷ t₁s) (t₂ ∷ t₂s) acc = amgu t₁s t₂s =<< amgu t₁ t₂ acc -- -- -- -- -- -- -- mgu : ∀ {m} -> (s t : Term m) -> Maybe (∃ (AList m)) -- -- -- -- -- -- -- mgu {m} s t = amgu s t (m , anil) -- -- -- -- -- -- -- mutual -- -- -- -- -- -- -- -- We use a view so that we need to handle fewer cases in the main proof -- -- -- -- -- -- -- data AmguT : {m : ℕ} -> (s t : Term m) -> ∃ (AList m) -> Maybe (∃ (AList m)) -> Set where -- -- -- -- -- -- -- Flip : ∀ {m s t acc} -> amgu t s acc ≡ amgu s t acc -> -- -- -- -- -- -- -- AmguT {m} t s acc (amgu t s acc) -> AmguT s t acc (amgu s t acc) -- -- -- -- -- -- -- leaf-leaf : ∀ {m acc} -> AmguT {m} leaf leaf acc (just acc) -- -- -- -- -- -- -- fn-name : ∀ {m fn₁ fn₂ N₁ N₂ acc} {ts₁ : Vec (Term m) N₁} {ts₂ : Vec (Term m) N₂} → -- -- -- -- -- -- -- fn₁ ≢ fn₂ → -- -- -- -- -- -- -- AmguT {m} (function fn₁ ts₁) -- -- -- -- -- -- -- (function fn₂ ts₂) -- -- -- -- -- -- -- acc nothing -- -- -- -- -- -- -- fn-size : ∀ {m fn₁ fn₂ N₁ N₂ acc} {ts₁ : Vec (Term m) N₁} {ts₂ : Vec (Term m) N₂} → -- -- -- -- -- -- -- N₁ ≢ N₂ → -- -- -- -- -- -- -- AmguT {m} (function fn₁ ts₁) -- -- -- -- -- -- -- (function fn₂ ts₂) -- -- -- -- -- -- -- acc nothing -- -- -- -- -- -- -- fn-fn : ∀ {m fn N acc} {ts₁ ts₂ : Vec (Term m) N} → -- -- -- -- -- -- -- AmguT {m} (function fn ts₁) -- -- -- -- -- -- -- (function fn ts₂) -- -- -- -- -- -- -- acc (amgu ts₁ ts₂ acc) -- -- -- -- -- -- -- leaf-fork : ∀ {m s t acc} -> AmguT {m} leaf (s fork t) acc nothing -- -- -- -- -- -- -- leaf-fn : ∀ {m fn N} {ts : Vec (Term _) N} {acc} -> AmguT {m} leaf (function fn ts) acc nothing -- -- -- -- -- -- -- fork-fn : ∀ {m s t fn N} {ts : Vec (Term _) N} {acc} -> AmguT {m} (s fork t) (function fn ts) acc nothing -- -- -- -- -- -- -- fork-fork : ∀ {m s1 s2 t1 t2 acc} -> AmguT {m} (s1 fork s2) (t1 fork t2) acc (amgu s2 t2 =<< amgu s1 t1 acc) -- -- -- -- -- -- -- var-var : ∀ {m x y} -> AmguT (i x) (i y) (m , anil) (just (flexFlex x y)) -- -- -- -- -- -- -- var-t : ∀ {m x t} -> i x ≢ t -> AmguT (i x) t (m , anil) (flexRigid x t) -- -- -- -- -- -- -- s-t : ∀{m s t n σ r z} -> AmguT {suc m} s t (n , σ asnoc r / z) ((λ σ -> σ ∃asnoc r / z) <$> -- -- -- -- -- -- -- amgu ((r for z) ◃ s) ((r for z) ◃ t) (n , σ)) -- -- -- -- -- -- -- data AmguTV : {m : ℕ} -> ∀ {N} (ss ts : Vec (Term m) N) -> ∃ (AList m) -> Maybe (∃ (AList m)) -> Set where -- -- -- -- -- -- -- fn0-fn0 : ∀ {m acc} → -- -- -- -- -- -- -- AmguTV {m} ([]) -- -- -- -- -- -- -- ([]) -- -- -- -- -- -- -- acc (just acc) -- -- -- -- -- -- -- fns-fns : ∀ {m N acc} {t₁ t₂ : Term m} {ts₁ ts₂ : Vec (Term m) N} → -- -- -- -- -- -- -- AmguTV {m} ((t₁ ∷ ts₁)) -- -- -- -- -- -- -- ((t₂ ∷ ts₂)) -- -- -- -- -- -- -- acc (amgu ts₁ ts₂ =<< amgu t₁ t₂ acc) -- -- -- -- -- -- -- view : ∀ {m : ℕ} -> (s t : Term m) -> (acc : ∃ (AList m)) -> AmguT s t acc (amgu s t acc) -- -- -- -- -- -- -- view leaf leaf acc = leaf-leaf -- -- -- -- -- -- -- view leaf (s fork t) acc = leaf-fork -- -- -- -- -- -- -- view (s fork t) leaf acc = Flip refl leaf-fork -- -- -- -- -- -- -- view (s1 fork s2) (t1 fork t2) acc = fork-fork -- -- -- -- -- -- -- view (function fn₁ {n₁} ts₁) (function fn₂ {n₂} ts₂) acc with -- -- -- -- -- -- -- fn₁ ≟F fn₂ -- -- -- -- -- -- -- … | no neq = fn-name neq -- -- -- -- -- -- -- … | yes refl with n₁ ≟ n₂ -- -- -- -- -- -- -- … | yes refl = fn-fn -- -- -- -- -- -- -- … | no neq = fn-size neq -- -- -- -- -- -- -- view leaf (function fn ts) acc = leaf-fn -- -- -- -- -- -- -- view (function fn ts) leaf acc = Flip refl leaf-fn -- -- -- -- -- -- -- view (function fn ts) (_ fork _) acc = Flip refl fork-fn -- -- -- -- -- -- -- view (s fork t) (function fn ts) acc = fork-fn -- -- -- -- -- -- -- view (i x) (i y) (m , anil) = var-var -- -- -- -- -- -- -- view (i x) leaf (m , anil) = var-t (λ ()) -- -- -- -- -- -- -- view (i x) (s fork t) (m , anil) = var-t (λ ()) -- -- -- -- -- -- -- view (i x) (function fn ts) (m , anil) = var-t (λ ()) -- -- -- -- -- -- -- view leaf (i x) (m , anil) = Flip refl (var-t (λ ())) -- -- -- -- -- -- -- view (s fork t) (i x) (m , anil) = Flip refl (var-t (λ ())) -- -- -- -- -- -- -- view (function fn ts) (i x) (m , anil) = Flip refl (var-t (λ ())) -- -- -- -- -- -- -- view (i x) (i x') (n , σ asnoc r / z) = s-t -- -- -- -- -- -- -- view (i x) leaf (n , σ asnoc r / z) = s-t -- -- -- -- -- -- -- view (i x) (s fork t) (n , σ asnoc r / z) = s-t -- -- -- -- -- -- -- view leaf (i x) (n , σ asnoc r / z) = s-t -- -- -- -- -- -- -- view (s fork t) (i x) (n , σ asnoc r / z) = s-t -- -- -- -- -- -- -- view (function fn ts) (i x) (n , σ asnoc r / z) = s-t -- -- -- -- -- -- -- view (i x) (function fn ts) (n , σ asnoc r / z) = s-t -- -- -- -- -- -- -- viewV : ∀ {m : ℕ} {N} -> (ss ts : Vec (Term m) N) -> (acc : ∃ (AList m)) -> AmguTV ss ts acc (amgu ss ts acc) -- -- -- -- -- -- -- viewV [] [] acc = fn0-fn0 -- -- -- -- -- -- -- viewV (t ∷ ts₁) (t₂ ∷ ts₂) acc = fns-fns -- -- -- -- -- -- -- amgu-Correctness : {m : ℕ} -> (s t : Term m) -> ∃ (AList m) -> Set -- -- -- -- -- -- -- amgu-Correctness s t (l , ρ) = -- -- -- -- -- -- -- (∃ λ n → ∃ λ σ → π₁ (Max (Unifies s t [-◇ sub ρ ])) (sub σ) × amgu s t (l , ρ) ≡ just (n , σ ++ ρ )) -- -- -- -- -- -- -- ⊎ (Nothing ((Unifies s t) [-◇ sub ρ ]) × amgu s t (l , ρ) ≡ nothing) -- -- -- -- -- -- -- amgu-Correctness⋆ : {m : ℕ} -> (s t : Term m) -> ∃ (AList m) -> Set -- -- -- -- -- -- -- amgu-Correctness⋆ s t (l , ρ) = -- -- -- -- -- -- -- (∃ λ n → ∃ λ σ → π₁ (Max (Unifies s t [-◇ sub ρ ])) (sub σ) × amgu s t (l , ρ) ≡ just (n , σ ++ ρ )) -- -- -- -- -- -- -- ⊎ (Nothing ((Unifies s t) [-◇ sub ρ ]) × amgu s t (l , ρ) ≡ nothing) -- -- -- -- -- -- -- amgu-Ccomm : ∀ {m} s t acc -> amgu {m = m} s t acc ≡ amgu t s acc -> amgu-Correctness s t acc -> amgu-Correctness t s acc -- -- -- -- -- -- -- amgu-Ccomm s t (l , ρ) st≡ts = lemma -- -- -- -- -- -- -- where -- -- -- -- -- -- -- Unst = (Unifies s t) [-◇ sub ρ ] -- -- -- -- -- -- -- Unts = (Unifies t s) [-◇ sub ρ ] -- -- -- -- -- -- -- Unst⇔Unts : ((Unifies s t) [-◇ sub ρ ]) ⇔ ((Unifies t s) [-◇ sub ρ ]) -- -- -- -- -- -- -- Unst⇔Unts = Properties.fact5 (Unifies s t) (Unifies t s) (sub ρ) (Properties.fact1 {_} {s} {t}) -- -- -- -- -- -- -- lemma : amgu-Correctness s t (l , ρ) -> amgu-Correctness t s (l , ρ) -- -- -- -- -- -- -- lemma (inj₁ (n , σ , MaxUnst , amgu≡just)) = -- -- -- -- -- -- -- inj₁ (n , σ , proj₁ (Max.fact Unst Unts Unst⇔Unts (sub σ)) MaxUnst , trans (sym st≡ts) amgu≡just) -- -- -- -- -- -- -- lemma (inj₂ (NoUnst , amgu≡nothing)) = -- -- -- -- -- -- -- inj₂ ((λ {_} → Properties.fact2 Unst Unts Unst⇔Unts NoUnst) , trans (sym st≡ts) amgu≡nothing) -- -- -- -- -- -- -- amgu-Ccomm⋆ : ∀ {m} s t acc -> amgu {m = m} s t acc ≡ amgu t s acc -> amgu-Correctness⋆ s t acc -> amgu-Correctness⋆ t s acc -- -- -- -- -- -- -- amgu-Ccomm⋆ s t (l , ρ) st≡ts = lemma -- -- -- -- -- -- -- where -- -- -- -- -- -- -- Unst = (Unifies s t) [-◇ sub ρ ] -- -- -- -- -- -- -- Unts = (Unifies t s) [-◇ sub ρ ] -- -- -- -- -- -- -- Unst⇔Unts : ((Unifies s t) [-◇ sub ρ ]) ⇔ ((Unifies t s) [-◇ sub ρ ]) -- -- -- -- -- -- -- Unst⇔Unts = Properties.fact5 (Unifies s t) (Unifies t s) (sub ρ) (Properties.fact1 {_} {s} {t}) -- -- -- -- -- -- -- lemma : amgu-Correctness s t (l , ρ) -> amgu-Correctness t s (l , ρ) -- -- -- -- -- -- -- lemma (inj₁ (n , σ , MaxUnst , amgu≡just)) = -- -- -- -- -- -- -- inj₁ (n , σ , proj₁ (Max.fact Unst Unts Unst⇔Unts (sub σ)) MaxUnst , trans (sym st≡ts) amgu≡just) -- -- -- -- -- -- -- lemma (inj₂ (NoUnst , amgu≡nothing)) = -- -- -- -- -- -- -- inj₂ ((λ {_} → Properties.fact2 Unst Unts Unst⇔Unts NoUnst) , trans (sym st≡ts) amgu≡nothing) -- -- -- -- -- -- -- mutual -- -- -- -- -- -- -- amguV-c : ∀ {m N} {ss ts : Vec (Term m) N} {l ρ} -> AmguTV ss ts (l , ρ) (amgu ss ts (l , ρ)) -> -- -- -- -- -- -- -- (∃ λ n → ∃ λ σ → Max⋆ (Unifies⋆V ss ts [-◇⋆ sub ρ ]) (sub σ) × amgu {m = m} ss ts (l , ρ) ≡ just (n , σ ++ ρ )) -- -- -- -- -- -- -- ⊎ (Nothing⋆ (Unifies⋆V ss ts [-◇⋆ sub ρ ]) × amgu {m = m} ss ts (l , ρ) ≡ nothing) -- -- -- -- -- -- -- amguV-c {m} {N} {ss} {ts} {l} {ρ} amg with amgu ss ts (l , ρ) -- -- -- -- -- -- -- amguV-c {m} {0} {.[]} {.[]} {l} {ρ} fn0-fn0 | .(just (l , ρ)) = inj₁ (_ , anil , trivial-problemV {_} {_} {_} {[]} {sub ρ} , cong (just ∘ _,_ l) (sym (SubList.anil-id-l ρ))) -- -- -- -- -- -- -- amguV-c {m} {.(suc _)} {(t₁ ∷ ts₁)} {(t₂ ∷ ts₂)} {l} {ρ} fns-fns | _ with amgu t₁ t₂ (l , ρ) | amgu-c $ view t₁ t₂ (l , ρ) -- -- -- -- -- -- -- amguV-c {m} {.(suc _)} {(t₁ ∷ ts₁)} {(t₂ ∷ ts₂)} {l} {ρ} fns-fns | _ | am | inj₂ (nounify , refl) = inj₂ ((λ {_} → NothingVecHead t₁ t₂ ρ _ _ nounify) , refl) -- -- -- -- -- -- -- amguV-c {m} {.(suc _)} {(t₁ ∷ ts₁)} {(t₂ ∷ ts₂)} {l} {ρ} fns-fns | _ | am | inj₁ (n , σ , a , refl) -- -- -- -- -- -- -- with amgu ts₁ ts₂ (n , σ ++ ρ) | amguV-c (viewV (ts₁) (ts₂) (n , (σ ++ ρ))) -- -- -- -- -- -- -- … | _ | inj₂ (nounify , refl) = inj₂ ((λ {_} → NothingVecTail σ t₁ t₂ _ _ ρ a nounify) , refl) -- -- -- -- -- -- -- … | _ | inj₁ (n1 , σ1 , a1 , refl) = inj₁ (n1 , σ1 ++ σ , MaxVec t₁ t₂ _ _ ρ σ a σ1 a1 , cong (λ σ -> just (n1 , σ)) (++-assoc σ1 σ ρ)) -- -- -- -- -- -- -- amgu-c : ∀ {m s t l ρ} -> AmguT s t (l , ρ) (amgu s t (l , ρ)) -> -- -- -- -- -- -- -- (∃ λ n → ∃ λ σ → Max⋆ (Unifies⋆ s t [-◇⋆ sub ρ ]) (sub σ) × amgu {m = m} s t (l , ρ) ≡ just (n , σ ++ ρ )) -- -- -- -- -- -- -- ⊎ (Nothing⋆ (Unifies⋆ s t [-◇⋆ sub ρ ]) × amgu {m = m} s t (l , ρ) ≡ nothing) -- -- -- -- -- -- -- amgu-c {m} {s} {t} {l} {ρ} amg with amgu s t (l , ρ) -- -- -- -- -- -- -- amgu-c {l = l} {ρ} leaf-leaf | ._ -- -- -- -- -- -- -- = inj₁ (l , anil , trivial-problem {_} {_} {leaf} {sub ρ} , cong (λ x -> just (l , x)) (sym (SubList.anil-id-l ρ)) ) -- -- -- -- -- -- -- amgu-c (fn-name neq) | _ = inj₂ ((λ f x → neq (Term-function-inj-FunctionName x)) , refl) -- -- -- -- -- -- -- amgu-c (fn-size neq) | _ = inj₂ ((λ f x → neq (Term-function-inj-VecSize x)) , refl) -- -- -- -- -- -- -- amgu-c {s = function fn ts₁} {t = function .fn ts₂} {l = l} {ρ = ρ} fn-fn | _ with amgu ts₁ ts₂ | amguV-c (viewV ts₁ ts₂ (l , ρ)) -- -- -- -- -- -- -- … | _ | inj₂ (nounify , refl!) rewrite refl! = inj₂ ((λ {_} f feq → nounify f (Term-function-inj-Vector feq)) , refl) -- -- -- -- -- -- -- … | _ | inj₁ (n , σ , (b , c) , refl!) rewrite refl! = inj₁ (_ , _ , ((cong (function fn) b) , (λ {_} f' feq → c f' (Term-function-inj-Vector feq))) , refl ) -- -- -- -- -- -- -- amgu-c leaf-fork | .nothing = inj₂ ((λ _ () ) , refl) -- -- -- -- -- -- -- amgu-c leaf-fn | _ = inj₂ ((λ _ () ) , refl) -- -- -- -- -- -- -- amgu-c fork-fn | _ = inj₂ ((λ _ () ) , refl) -- -- -- -- -- -- -- amgu-c {m} {s1 fork s2} {t1 fork t2} {l} {ρ} fork-fork | ._ -- -- -- -- -- -- -- with amgu s1 t1 (l , ρ) | amgu-c $ view s1 t1 (l , ρ) -- -- -- -- -- -- -- … | .nothing | inj₂ (nounify , refl) = inj₂ ((λ {_} -> NothingForkLeft s1 t1 ρ s2 t2 nounify) , refl) -- -- -- -- -- -- -- … | .(just (n , σ ++ ρ)) | inj₁ (n , σ , a , refl) -- -- -- -- -- -- -- with amgu s2 t2 (n , σ ++ ρ) | amgu-c (view s2 t2 (n , (σ ++ ρ))) -- -- -- -- -- -- -- … | .nothing | inj₂ (nounify , refl) = inj₂ ( (λ {_} -> NothingForkRight σ s1 s2 t1 t2 ρ a nounify) , refl) -- -- -- -- -- -- -- … | .(just (n1 , σ1 ++ (σ ++ ρ))) | inj₁ (n1 , σ1 , b , refl) -- -- -- -- -- -- -- = inj₁ (n1 , σ1 ++ σ , MaxFork s1 s2 t1 t2 ρ σ a σ1 b , cong (λ σ -> just (n1 , σ)) (++-assoc σ1 σ ρ)) -- -- -- -- -- -- -- amgu-c {suc l} {i x} {i y} (var-var) | .(just (flexFlex x y)) -- -- -- -- -- -- -- with thick? x y | Thick.fact1 x y (thick? x y) refl -- -- -- -- -- -- -- … | .(just y') | inj₂ (y' , thinxy'≡y , refl ) -- -- -- -- -- -- -- = inj₁ (l , anil asnoc i y' / x , var-elim-i-≡ x (i y) (sym (cong i thinxy'≡y)) , refl ) -- -- -- -- -- -- -- … | .nothing | inj₁ ( x≡y , refl ) rewrite sym x≡y -- -- -- -- -- -- -- = inj₁ (suc l , anil , trivial-problem {_} {_} {i x} {sub anil} , refl) -- -- -- -- -- -- -- amgu-c {suc l} {i x} {t} (var-t ix≢t) | .(flexRigid x t) -- -- -- -- -- -- -- with check x t | check-prop x t -- -- -- -- -- -- -- … | .nothing | inj₂ ( ps , r , refl) = inj₂ ( (λ {_} -> NothingStep x t ix≢t ps r ) , refl) -- -- -- -- -- -- -- … | .(just t') | inj₁ (t' , r , refl) = inj₁ ( l , anil asnoc t' / x , var-elim-i-≡ x t r , refl ) -- -- -- -- -- -- -- amgu-c {suc m} {s} {t} {l} {ρ asnoc r / z} s-t -- -- -- -- -- -- -- | .((λ x' → x' ∃asnoc r / z) <$> -- -- -- -- -- -- -- (amgu ((r for z) ◃ s) ((r for z) ◃ t) (l , ρ))) -- -- -- -- -- -- -- with amgu-c (view ((r for z) ◃ s) ((r for z) ◃ t) (l , ρ)) -- -- -- -- -- -- -- … | inj₂ (nounify , ra) = inj₂ ( (λ {_} -> NothingFor→NothingComposition s t ρ r z nounify) , cong (_<$>_ (λ x' → x' ∃asnoc r / z)) ra ) -- -- -- -- -- -- -- … | inj₁ (n , σ , a , ra) = inj₁ (n , σ , MaxFor→MaxComposition s t ρ r z σ a , cong (_<$>_ (λ x' → x' ∃asnoc r / z)) ra) -- -- -- -- -- -- -- amgu-c {m} {s} {t} {l} {ρ} (Flip amguts≡amgust amguts) | ._ = amgu-Ccomm⋆ t s (l , ρ) amguts≡amgust (amgu-c amguts) -- -- -- -- -- -- -- amgu-c {zero} {i ()} _ | _ -- -- -- -- -- -- -- mgu-c : ∀ {m} (s t : Term m) -> -- -- -- -- -- -- -- (∃ λ n → ∃ λ σ → (Max⋆ (Unifies⋆ s t)) (sub σ) × mgu s t ≡ just (n , σ)) -- -- -- -- -- -- -- ⊎ (Nothing⋆ (Unifies⋆ s t) × mgu s t ≡ nothing) -- -- -- -- -- -- -- mgu-c {m} s t = amgu-c (view s t (m , anil)) -- -- -- -- -- -- -- unify : ∀ {m} (s t : Term m) -> -- -- -- -- -- -- -- (∃ λ n → ∃ λ (σ : AList m n) → Max⋆ (Unifies⋆ s t) $ sub σ) -- -- -- -- -- -- -- ⊎ Nothing⋆ (Unifies⋆ s t) -- -- -- -- -- -- -- unify {m} s t with amgu-c (view s t (m , anil)) -- -- -- -- -- -- -- unify {m} s₁ t | inj₁ (proj₃ , proj₄ , proj₅ , proj₆) = inj₁ (proj₃ , proj₄ , proj₅) -- -- -- -- -- -- -- unify {m} s t | inj₂ (proj₃ , _) = inj₂ proj₃ -- -- -- -- -- -- -- unifyV : ∀ {m N} (s t : Vec (Term m) N) -> -- -- -- -- -- -- -- (∃ λ n → ∃ λ (σ : AList m n) → Max⋆ (Unifies⋆V s t) $ sub σ) -- -- -- -- -- -- -- ⊎ Nothing⋆ (Unifies⋆V s t) -- -- -- -- -- -- -- unifyV {m} {N} s t with amguV-c (viewV s t (m , anil)) -- -- -- -- -- -- -- … | inj₁ (proj₃ , proj₄ , proj₅ , proj₆) = inj₁ (proj₃ , proj₄ , proj₅) -- -- -- -- -- -- -- … | inj₂ (proj₃ , _) = inj₂ proj₃ -- -- -- -- -- -- -- open import Oscar.Data.Permutation -- -- -- -- -- -- -- unifyWith : ∀ {m N} (p q : Term m) (X Y : Vec (Term m) N) → -- -- -- -- -- -- -- (∃ λ X* → X* ≡ordering' X × ∃ λ n → ∃ λ (σ : AList m n) → Max⋆ (Unifies⋆V (p ∷ X*) (q ∷ Y)) $ sub σ) -- -- -- -- -- -- -- ⊎ -- -- -- -- -- -- -- (∀ X* → X* ≡ordering' X → Nothing⋆ (Unifies⋆V (p ∷ X*) (q ∷ Y))) -- -- -- -- -- -- -- unifyWith p q X Y = {!!}
algebraic-stack_agda0000_doc_5988
module AKS.Primality where open import AKS.Primality.Base public open import AKS.Primality.Properties public
algebraic-stack_agda0000_doc_5989
{-# OPTIONS --without-K --safe #-} open import Categories.Category.Core using (Category) open import Categories.Comonad -- Verbatim dual of Categories.Adjoint.Construction.Kleisli module Categories.Adjoint.Construction.CoKleisli {o ℓ e} {C : Category o ℓ e} (M : Comonad C) where open import Categories.Category.Construction.CoKleisli open import Categories.Adjoint open import Categories.Functor open import Categories.Functor.Properties open import Categories.NaturalTransformation.Core open import Categories.NaturalTransformation.NaturalIsomorphism using (_≃_) open import Categories.Morphism.Reasoning C private module C = Category C module M = Comonad M open M.F open C open HomReasoning open Equiv Forgetful : Functor (CoKleisli M) C Forgetful = record { F₀ = λ X → F₀ X ; F₁ = λ f → F₁ f ∘ M.δ.η _ ; identity = Comonad.identityˡ M ; homomorphism = λ {X Y Z} {f g} → hom-proof {X} {Y} {Z} {f} {g} ; F-resp-≈ = λ eq → ∘-resp-≈ˡ (F-resp-≈ eq) } where trihom : {X Y Z W : Obj} {f : X ⇒ Y} {g : Y ⇒ Z} {h : Z ⇒ W} → F₁ (h ∘ g ∘ f) ≈ F₁ h ∘ F₁ g ∘ F₁ f trihom {X} {Y} {Z} {W} {f} {g} {h} = begin F₁ (h ∘ g ∘ f) ≈⟨ homomorphism ⟩ F₁ h ∘ F₁ (g ∘ f) ≈⟨ refl⟩∘⟨ homomorphism ⟩ F₁ h ∘ F₁ g ∘ F₁ f ∎ hom-proof : {X Y Z : Obj} {f : F₀ X ⇒ Y} {g : F₀ Y ⇒ Z} → (F₁ (g ∘ F₁ f ∘ M.δ.η X)) ∘ M.δ.η X ≈ (F₁ g ∘ M.δ.η Y) ∘ F₁ f ∘ M.δ.η X hom-proof {X} {Y} {Z} {f} {g} = begin (F₁ (g ∘ F₁ f ∘ M.δ.η X)) ∘ M.δ.η X ≈⟨ pushˡ trihom ⟩ F₁ g ∘ (F₁ (F₁ f) ∘ F₁ (M.δ.η X)) ∘ M.δ.η X ≈⟨ refl⟩∘⟨ (pullʳ (sym M.assoc)) ⟩ F₁ g ∘ F₁ (F₁ f) ∘ M.δ.η (F₀ X) ∘ M.δ.η X ≈⟨ refl⟩∘⟨ pullˡ (sym (M.δ.commute f)) ⟩ F₁ g ∘ (M.δ.η Y ∘ F₁ f) ∘ M.δ.η X ≈⟨ assoc²'' ⟩ (F₁ g ∘ M.δ.η Y) ∘ F₁ f ∘ M.δ.η X ∎ Cofree : Functor C (CoKleisli M) Cofree = record { F₀ = λ X → X ; F₁ = λ f → f ∘ M.ε.η _ ; identity = λ {A} → identityˡ ; homomorphism = λ {X Y Z} {f g} → hom-proof {X} {Y} {Z} {f} {g} ; F-resp-≈ = λ x → ∘-resp-≈ˡ x } where hom-proof : {X Y Z : Obj} {f : X ⇒ Y} {g : Y ⇒ Z} → (g ∘ f) ∘ M.ε.η X ≈ (g ∘ M.ε.η Y) ∘ (F₁ (f ∘ M.ε.η X) ∘ M.δ.η X) hom-proof {X} {Y} {Z} {f} {g} = begin (g ∘ f) ∘ M.ε.η X ≈⟨ pullʳ (sym (M.ε.commute f)) ⟩ g ∘ M.ε.η Y ∘ F₁ f ≈⟨ sym (pullʳ (refl⟩∘⟨ elimʳ (Comonad.identityˡ M))) ⟩ (g ∘ M.ε.η Y) ∘ (F₁ f ∘ F₁ (M.ε.η X) ∘ M.δ.η X) ≈⟨ refl⟩∘⟨ pullˡ (sym homomorphism) ⟩ (g ∘ M.ε.η Y) ∘ (F₁ (f ∘ M.ε.η X) ∘ M.δ.η X) ∎ FC≃M : Forgetful ∘F Cofree ≃ M.F FC≃M = record { F⇒G = ntHelper record { η = λ X → F₁ C.id ; commute = λ {X Y} f → to-commute {X} {Y} f } ; F⇐G = ntHelper record { η = λ X → F₁ C.id ; commute = λ {X Y} f → from-commute {X} {Y} f } ; iso = λ X → record { isoˡ = elimʳ identity ○ identity ; isoʳ = elimʳ identity ○ identity } } where to-commute : {X Y : Obj} → (f : X ⇒ Y) → F₁ C.id ∘ F₁ (f ∘ M.ε.η X) ∘ M.δ.η X ≈ F₁ f ∘ F₁ C.id to-commute {X} {Y} f = begin F₁ C.id ∘ F₁ (f ∘ M.ε.η X) ∘ M.δ.η X ≈⟨ elimˡ identity ⟩ F₁ (f ∘ M.ε.η X) ∘ M.δ.η X ≈⟨ pushˡ homomorphism ⟩ F₁ f ∘ F₁ (M.ε.η X) ∘ M.δ.η X ≈⟨ refl⟩∘⟨ Comonad.identityˡ M ⟩ F₁ f ∘ C.id ≈⟨ refl⟩∘⟨ sym identity ⟩ F₁ f ∘ F₁ C.id ∎ from-commute : {X Y : Obj} → (f : X ⇒ Y) → F₁ C.id ∘ F₁ f ≈ (F₁ (f ∘ M.ε.η X) ∘ M.δ.η X) ∘ F₁ C.id from-commute {X} {Y} f = begin F₁ C.id ∘ F₁ f ≈⟨ [ M.F ]-resp-square id-comm-sym ⟩ F₁ f ∘ F₁ C.id ≈⟨ introʳ (Comonad.identityˡ M) ⟩∘⟨refl ⟩ (F₁ f ∘ F₁ (M.ε.η X) ∘ M.δ.η X) ∘ F₁ C.id ≈⟨ pullˡ (sym homomorphism) ⟩∘⟨refl ⟩ (F₁ (f ∘ M.ε.η X) ∘ M.δ.η X) ∘ F₁ C.id ∎ -- useful lemma: FF1≈1 : {X : Obj} → F₁ (F₁ (C.id {X})) ≈ C.id FF1≈1 {X} = begin F₁ (F₁ (C.id {X})) ≈⟨ F-resp-≈ identity ⟩ F₁ (C.id) ≈⟨ identity ⟩ C.id ∎ Forgetful⊣Cofree : Forgetful ⊣ Cofree Forgetful⊣Cofree = record { unit = ntHelper record { η = λ X → F₁ C.id ; commute = λ {X Y} f → unit-commute {X} {Y} f } ; counit = ntHelper record { η = M.ε.η ; commute = λ {X Y} f → counit-commute {X} {Y} f } ; zig = λ {A} → zig-proof {A} ; zag = λ {B} → zag-proof {B} } where unit-commute : ∀ {X Y : Obj} → (f : F₀ X ⇒ Y) → F₁ C.id ∘ F₁ f ∘ M.δ.η X ≈ ((F₁ f ∘ M.δ.η X) ∘ M.ε.η (F₀ X)) ∘ F₁ (F₁ C.id) ∘ M.δ.η X unit-commute {X} {Y} f = begin F₁ C.id ∘ F₁ f ∘ M.δ.η X ≈⟨ elimˡ identity ⟩ F₁ f ∘ M.δ.η X ≈⟨ introʳ (Comonad.identityʳ M) ⟩ (F₁ f ∘ M.δ.η X) ∘ M.ε.η (F₀ X) ∘ M.δ.η X ≈⟨ sym assoc ⟩ ((F₁ f ∘ M.δ.η X) ∘ M.ε.η (F₀ X)) ∘ M.δ.η X ≈⟨ intro-center FF1≈1 ⟩ ((F₁ f ∘ M.δ.η X) ∘ M.ε.η (F₀ X)) ∘ F₁ (F₁ C.id) ∘ M.δ.η X ∎ counit-commute : ∀ {X Y : Obj} → (f : X ⇒ Y) → M.ε.η Y ∘ (F₁ (f ∘ M.ε.η X) ∘ M.δ.η X) ≈ f ∘ M.ε.η X counit-commute {X} {Y} f = begin M.ε.η Y ∘ F₁ (f ∘ M.ε.η X) ∘ M.δ.η X ≈⟨ refl⟩∘⟨ pushˡ homomorphism ⟩ M.ε.η Y ∘ (F₁ f ∘ F₁ (M.ε.η X) ∘ M.δ.η X) ≈⟨ refl⟩∘⟨ elimʳ (Comonad.identityˡ M) ⟩ M.ε.η Y ∘ F₁ f ≈⟨ M.ε.commute f ⟩ f ∘ M.ε.η X ∎ zig-proof : {A : Obj} → M.ε.η (F₀ A) ∘ F₁ (F₁ C.id) ∘ M.δ.η _ ≈ C.id zig-proof {A} = begin M.ε.η (F₀ A) ∘ F₁ (F₁ C.id) ∘ M.δ.η _ ≈⟨ elim-center FF1≈1 ⟩ M.ε.η (F₀ A) ∘ M.δ.η _ ≈⟨ Comonad.identityʳ M ⟩ C.id ∎ zag-proof : {B : Obj} → (M.ε.η B ∘ M.ε.η (F₀ B)) ∘ (F₁ (F₁ C.id) ∘ M.δ.η _) ≈ M.ε.η B zag-proof {B} = begin (M.ε.η B ∘ M.ε.η (F₀ B)) ∘ (F₁ (F₁ C.id) ∘ M.δ.η _) ≈⟨ assoc ⟩ M.ε.η B ∘ (M.ε.η (F₀ B) ∘ (F₁ (F₁ C.id) ∘ M.δ.η _)) ≈⟨ refl⟩∘⟨ elim-center FF1≈1 ⟩ M.ε.η B ∘ (M.ε.η (F₀ B) ∘ M.δ.η _) ≈⟨ elimʳ (Comonad.identityʳ M) ⟩ M.ε.η B ∎
algebraic-stack_agda0000_doc_5990
{-# OPTIONS --safe #-} {- This uses ideas from Floris van Doorn's phd thesis and the code in https://github.com/cmu-phil/Spectral/blob/master/spectrum/basic.hlean -} module Cubical.Homotopy.Spectrum where open import Cubical.Foundations.Prelude open import Cubical.Data.Unit.Pointed open import Cubical.Foundations.Equiv open import Cubical.Data.Int open import Cubical.Homotopy.Prespectrum private variable ℓ : Level record Spectrum (ℓ : Level) : Type (ℓ-suc ℓ) where open GenericPrespectrum field prespectrum : Prespectrum ℓ equiv : (k : ℤ) → isEquiv (fst (map prespectrum k)) open GenericPrespectrum prespectrum public
algebraic-stack_agda0000_doc_5991
{- This file contains: - the abelianization of groups as a HIT as proposed in https://arxiv.org/abs/2007.05833 The definition of the abelianization is not as a set-quotient, since the relation of abelianization is cumbersome to work with. -} {-# OPTIONS --safe #-} module Cubical.Algebra.Group.Abelianization.Base where open import Cubical.Data.Sigma open import Cubical.Algebra.Group.Base open import Cubical.Algebra.Group.Properties private variable ℓ : Level module _ (G : Group ℓ) where open GroupStr {{...}} open GroupTheory G private instance _ = snd G {- The definition of the abelianization of a group as a higher inductive type. The generality of the comm relation will be needed to define the group structure on the abelianization. -} data Abelianization : Type ℓ where η : (g : fst G) → Abelianization comm : (a b c : fst G) → η (a · (b · c)) ≡ η (a · (c · b)) isset : (x y : Abelianization) → (p q : x ≡ y) → p ≡ q
algebraic-stack_agda0000_doc_5992
{-# OPTIONS --without-K --safe #-} open import Categories.Category module Categories.Category.Construction.Properties.Presheaves.Complete {o ℓ e} (C : Category o ℓ e) where open import Data.Product open import Function.Equality using (Π) renaming (_∘_ to _∙_) open import Relation.Binary open import Relation.Binary.Construct.Closure.SymmetricTransitive as ST using (Plus⇔) open Plus⇔ open import Categories.Category.Complete open import Categories.Category.Cocomplete open import Categories.Category.Construction.Presheaves open import Categories.Category.Instance.Setoids open import Categories.Category.Instance.Properties.Setoids open import Categories.Diagram.Limit as Lim open import Categories.Diagram.Colimit open import Categories.Functor open import Categories.NaturalTransformation import Categories.Category.Construction.Cones as Co import Categories.Category.Construction.Cocones as Coc import Relation.Binary.Reasoning.Setoid as SetoidR private module C = Category C open C open Π using (_⟨$⟩_) module _ o′ where private P = Presheaves′ o′ o′ C module P = Category P module _ {J : Category o′ o′ o′} (F : Functor J P) where module J = Category J module F = Functor F open F module F₀ j = Functor (F₀ j) module F₁ {a b} (f : a J.⇒ b) = NaturalTransformation (F₁ f) open Setoid using () renaming (_≈_ to [_]_≈_) F[-,_] : Obj → Functor J (Setoids o′ o′) F[-, X ] = record { F₀ = λ j → F₀.₀ j X ; F₁ = λ f → F₁.η f X ; identity = identity ; homomorphism = homomorphism ; F-resp-≈ = λ eq → F-resp-≈ eq -- this application cannot be eta reduced } -- limit related definitions module LimFX X = Limit (Setoids-Complete _ _ _ o′ o′ F[-, X ]) module FCone (K : Co.Cone F) where open Co.Cone F K public module N = Functor N module ψ j = NaturalTransformation (ψ j) module FCone⇒ {K K′ : Co.Cone F} (K⇒K′ : Co.Cone⇒ F K K′) where open Co.Cone⇒ F K⇒K′ public module arr = NaturalTransformation arr FXcone : ∀ X → (K : Co.Cone F) → Co.Cone F[-, X ] FXcone X K = record { N = N.₀ X ; apex = record { ψ = λ j → ψ.η j X ; commute = λ f → commute f -- this application cannot be eta reduced } } where open FCone K ⊤ : Co.Cone F ⊤ = record { N = record { F₀ = λ X → LimFX.apex X ; F₁ = λ {A B} f → record { _⟨$⟩_ = λ { (S , eq) → (λ j → F₀.₁ j f ⟨$⟩ S j) , λ {X Y} g → let open SetoidR (F₀.₀ Y B) in begin F₁.η g B ⟨$⟩ (F₀.₁ X f ⟨$⟩ S X) ≈⟨ F₁.commute g f (Setoid.refl (F₀.₀ X A)) ⟩ F₀.₁ Y f ⟨$⟩ (F₁.η g A ⟨$⟩ S X) ≈⟨ Π.cong (F₀.₁ Y f) (eq g) ⟩ F₀.₁ Y f ⟨$⟩ S Y ∎ } ; cong = λ eq j → Π.cong (F₀.₁ j f) (eq j) } ; identity = λ eq j → F₀.identity j (eq j) ; homomorphism = λ eq j → F₀.homomorphism j (eq j) ; F-resp-≈ = λ eq eq′ j → F₀.F-resp-≈ j eq (eq′ j) } ; apex = record { ψ = λ j → ntHelper record { η = λ X → record { _⟨$⟩_ = λ { (S , eq) → S j } ; cong = λ eq → eq j } ; commute = λ f eq → Π.cong (F₀.₁ j f) (eq j) } ; commute = λ { {Y} {Z} f {W} {S₁ , eq₁} {S₂ , eq₂} eq → let open SetoidR (F₀.₀ Z W) in begin F₁.η f W ⟨$⟩ S₁ Y ≈⟨ eq₁ f ⟩ S₁ Z ≈⟨ eq Z ⟩ S₂ Z ∎ } } } K⇒⊤′ : ∀ X {K} → Co.Cones F [ K , ⊤ ] → Co.Cones F[-, X ] [ FXcone X K , LimFX.limit X ] K⇒⊤′ X {K} K⇒⊤ = record { arr = arr.η X ; commute = comm } where open FCone⇒ K⇒⊤ renaming (commute to comm) complete : Limit F complete = record { terminal = record { ⊤ = ⊤ ; ! = λ {K} → let module K = FCone K in record { arr = ntHelper record { η = λ X → LimFX.rep X (FXcone X K) ; commute = λ {X Y} f eq j → K.ψ.commute j f eq } ; commute = λ eq → Π.cong (K.ψ.η _ _) eq } ; !-unique = λ K⇒⊤ {X} → LimFX.terminal.!-unique X (K⇒⊤′ X K⇒⊤) } } -- colimit related definitions module ColimFX X = Colimit (Setoids-Cocomplete _ _ _ o′ o′ F[-, X ]) module FCocone (K : Coc.Cocone F) where open Coc.Cocone F K public module N = Functor N module ψ j = NaturalTransformation (ψ j) module FCocone⇒ {K K′ : Coc.Cocone F} (K⇒K′ : Coc.Cocone⇒ F K K′) where open Coc.Cocone⇒ F K⇒K′ public module arr = NaturalTransformation arr FXcocone : ∀ X → (K : Coc.Cocone F) → Coc.Cocone F[-, X ] FXcocone X K = record { N = N.₀ X ; coapex = record { ψ = λ j → ψ.η j X ; commute = λ f → commute f -- this application cannot be eta reduced } } where open FCocone K ⊥ : Coc.Cocone F ⊥ = record { N = record { F₀ = λ X → ColimFX.coapex X ; F₁ = λ {A B} f → record { _⟨$⟩_ = λ { (j , Sj) → j , F₀.₁ j f ⟨$⟩ Sj } ; cong = λ { {a , Sa} {b , Sb} → ST.map (λ { (j , Sj) → j , F₀.₁ j f ⟨$⟩ Sj }) (helper f) } } ; identity = λ { {A} {j , _} eq → forth⁺ (J.id , identity (F₀.identity j (Setoid.refl (F₀.₀ j A)))) eq } ; homomorphism = λ {X Y Z} {f g} → λ { {_} {j , Sj} eq → let open Setoid (F₀.₀ j Z) in ST.trans (coc o′ o′ F[-, Z ]) (ST.map (hom-map f g) (helper (f ∘ g)) eq) (forth (J.id , trans (identity refl) (F₀.homomorphism j (Setoid.refl (F₀.₀ j X))))) } ; F-resp-≈ = λ {A B} {f g} eq → λ { {j , Sj} eq′ → let open Setoid (F₀.₀ j B) in ST.trans (coc o′ o′ F[-, B ]) (forth (J.id , trans (identity refl) (F₀.F-resp-≈ j eq (Setoid.refl (F₀.₀ j A))))) (ST.map (λ { (j , Sj) → (j , F₀.₁ j g ⟨$⟩ Sj) }) (helper g) eq′) } } ; coapex = record { ψ = λ j → ntHelper record { η = λ X → record { _⟨$⟩_ = j ,_ ; cong = λ eq → forth (-, identity eq) } ; commute = λ {X Y} f eq → back (-, identity (Π.cong (F₀.₁ j f) (Setoid.sym (F₀.₀ j X) eq))) } ; commute = λ {a b} f {X} {x y} eq → let open ST.Plus⇔Reasoning (coc o′ o′ F[-, X ]) in back (f , Π.cong (F₁.η f X) (Setoid.sym (F₀.₀ a X) eq)) } } where helper : ∀ {A B} (f : B C.⇒ A) {a Sa b Sb} → Σ (a J.⇒ b) (λ g → [ F₀.₀ b A ] F₁.η g A ⟨$⟩ Sa ≈ Sb) → Σ (a J.⇒ b) λ h → [ F₀.₀ b B ] F₁.η h B ⟨$⟩ (F₀.₁ a f ⟨$⟩ Sa) ≈ F₀.₁ b f ⟨$⟩ Sb helper {A} {B} f {a} {Sa} {b} {Sb} (g , eq′) = let open SetoidR (F₀.₀ b B) in g , (begin F₁.η g B ⟨$⟩ (F₀.₁ a f ⟨$⟩ Sa) ≈⟨ F₁.commute g f (Setoid.refl (F₀.₀ a A)) ⟩ F₀.₁ b f ⟨$⟩ (F₁.η g A ⟨$⟩ Sa) ≈⟨ Π.cong (F₀.₁ b f) eq′ ⟩ F₀.₁ b f ⟨$⟩ Sb ∎) hom-map : ∀ {X Y Z} → Y C.⇒ X → Z C.⇒ Y → Σ J.Obj (λ j → Setoid.Carrier (F₀.₀ j X)) → Σ J.Obj (λ j → Setoid.Carrier (F₀.₀ j Z)) hom-map f g (j , Sj) = j , F₀.₁ j (f ∘ g) ⟨$⟩ Sj ⊥⇒K′ : ∀ X {K} → Coc.Cocones F [ ⊥ , K ] → Coc.Cocones F[-, X ] [ ColimFX.colimit X , FXcocone X K ] ⊥⇒K′ X {K} ⊥⇒K = record { arr = arr.η X ; commute = comm } where open FCocone⇒ ⊥⇒K renaming (commute to comm) ! : {K : Coc.Cocone F} → Coc.Cocone⇒ F ⊥ K ! {K} = record { arr = ntHelper record { η = λ X → ColimFX.rep X (FXcocone X K) ; commute = λ {X Y} f → λ { {a , Sa} {b , Sb} eq → let open SetoidR (K.N.F₀ Y) in begin K.ψ.η a Y ⟨$⟩ (F₀.₁ a f ⟨$⟩ Sa) ≈⟨ K.ψ.commute a f (Setoid.refl (F₀.₀ a X)) ⟩ K.N.F₁ f ⟨$⟩ (K.ψ.η a X ⟨$⟩ Sa) ≈⟨ Π.cong (K.N.F₁ f) (ST.minimal (coc o′ o′ F[-, X ]) (K.N.₀ X) (Kψ X) (helper X) eq) ⟩ K.N.F₁ f ⟨$⟩ (K.ψ.η b X ⟨$⟩ Sb) ∎ } } ; commute = λ eq → Π.cong (K.ψ.η _ _) eq } where module K = FCocone K Kψ : ∀ X → Σ J.Obj (λ j → Setoid.Carrier (F₀.₀ j X)) → Setoid.Carrier (K.N.F₀ X) Kψ X (j , S) = K.ψ.η j X ⟨$⟩ S helper : ∀ X → coc o′ o′ F[-, X ] =[ Kψ X ]⇒ [ K.N.₀ X ]_≈_ helper X {a , Sa} {b , Sb} (f , eq) = begin K.ψ.η a X ⟨$⟩ Sa ≈˘⟨ K.commute f (Setoid.refl (F₀.₀ a X)) ⟩ K.ψ.η b X ⟨$⟩ (F₁.η f X ⟨$⟩ Sa) ≈⟨ Π.cong (K.ψ.η b X) eq ⟩ K.ψ.η b X ⟨$⟩ Sb ∎ where open SetoidR (K.N.₀ X) cocomplete : Colimit F cocomplete = record { initial = record { ⊥ = ⊥ ; ! = ! ; !-unique = λ ⊥⇒K {X} → ColimFX.initial.!-unique X (⊥⇒K′ X ⊥⇒K) } } Presheaves-Complete : Complete o′ o′ o′ P Presheaves-Complete F = complete F Presheaves-Cocomplete : Cocomplete o′ o′ o′ P Presheaves-Cocomplete F = cocomplete F
algebraic-stack_agda0000_doc_5993
{-# OPTIONS --cubical-compatible #-} data ℕ : Set where zero : ℕ suc : ℕ → ℕ Test : Set Test = ℕ test : Test → ℕ test zero = zero test (suc n) = test n
algebraic-stack_agda0000_doc_5994
module Serializer where open import Data.List open import Data.Fin hiding (_+_) open import Data.Nat open import Data.Product open import Data.Bool open import Function using (_∘_ ; _$_ ; _∋_) open import Function.Injection hiding (_∘_) open import Function.Surjection hiding (_∘_) open import Function.Bijection hiding (_∘_) open import Relation.Binary.PropositionalEquality hiding ( [_] ) open import Reflection open import Helper.Fin open import Helper.CodeGeneration ----------------------------------- -- Generic ----------------------------------- -- Finite record Serializer (T : Set) : Set where constructor serializer field size : ℕ from : T -> Fin size to : Fin size -> T bijection : Bijection (setoid T) (setoid (Fin size))
algebraic-stack_agda0000_doc_5995
------------------------------------------------------------------------------ -- Test the consistency of FOTC.Data.List ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- In the module FOTC.Data.List we declare Agda postulates as FOL -- axioms. We test if it is possible to prove an unprovable theorem -- from these axioms. module FOTC.Data.List.Consistency.Axioms where open import FOTC.Base open import FOTC.Data.List ------------------------------------------------------------------------------ postulate impossible : ∀ d e → d ≡ e {-# ATP prove impossible #-}
algebraic-stack_agda0000_doc_5996
open import Data.Product using ( _×_ ; _,_ ) open import Data.Sum using ( inj₁ ; inj₂ ) open import Relation.Binary.PropositionalEquality using ( _≡_ ; refl ) open import Relation.Unary using ( _∈_ ; _⊆_ ) open import Web.Semantic.DL.ABox using ( ABox ; Assertions ; ⟨ABox⟩ ; ε ; _,_ ; _∼_ ; _∈₁_ ; _∈₂_ ) open import Web.Semantic.DL.ABox.Interp using ( Interp ; _,_ ; ⌊_⌋ ; ind ; _*_ ) open import Web.Semantic.DL.ABox.Interp.Morphism using ( _≲_ ; _,_ ; ≲⌊_⌋ ; ≲-resp-ind ; ≡³-impl-≲ ) open import Web.Semantic.DL.Signature using ( Signature ) open import Web.Semantic.DL.TBox.Interp using ( Δ ; _⊨_≈_ ; ≈-refl ; ≈-sym ; ≈-trans ; con ; rol ; con-≈ ; rol-≈ ) open import Web.Semantic.DL.TBox.Interp.Morphism using ( ≲-image ; ≲-resp-≈ ; ≲-resp-con ; ≲-resp-rol ; ≲-refl ) open import Web.Semantic.Util using ( True ; tt ; id ; _∘_ ; _⊕_⊕_ ; inode ; bnode ; enode ; →-dist-⊕ ) module Web.Semantic.DL.ABox.Model {Σ : Signature} where infix 2 _⊨a_ _⊨b_ infixr 5 _,_ _⟦_⟧₀ : ∀ {X} (I : Interp Σ X) → X → (Δ ⌊ I ⌋) I ⟦ x ⟧₀ = ind I x _⊨a_ : ∀ {X} → Interp Σ X → ABox Σ X → Set I ⊨a ε = True I ⊨a (A , B) = (I ⊨a A) × (I ⊨a B) I ⊨a x ∼ y = ⌊ I ⌋ ⊨ ind I x ≈ ind I y I ⊨a x ∈₁ c = ind I x ∈ con ⌊ I ⌋ c I ⊨a (x , y) ∈₂ r = (ind I x , ind I y) ∈ rol ⌊ I ⌋ r Assertions✓ : ∀ {X} (I : Interp Σ X) A {a} → (a ∈ Assertions A) → (I ⊨a A) → (I ⊨a a) Assertions✓ I ε () I⊨A Assertions✓ I (A , B) (inj₁ a∈A) (I⊨A , I⊨B) = Assertions✓ I A a∈A I⊨A Assertions✓ I (A , B) (inj₂ a∈B) (I⊨A , I⊨B) = Assertions✓ I B a∈B I⊨B Assertions✓ I (i ∼ j) refl I⊨A = I⊨A Assertions✓ I (i ∈₁ c) refl I⊨A = I⊨A Assertions✓ I (ij ∈₂ r) refl I⊨A = I⊨A ⊨a-resp-⊇ : ∀ {X} (I : Interp Σ X) A B → (Assertions A ⊆ Assertions B) → (I ⊨a B) → (I ⊨a A) ⊨a-resp-⊇ I ε B A⊆B I⊨B = tt ⊨a-resp-⊇ I (A₁ , A₂) B A⊆B I⊨B = ( ⊨a-resp-⊇ I A₁ B (A⊆B ∘ inj₁) I⊨B , ⊨a-resp-⊇ I A₂ B (A⊆B ∘ inj₂) I⊨B ) ⊨a-resp-⊇ I (x ∼ y) B A⊆B I⊨B = Assertions✓ I B (A⊆B refl) I⊨B ⊨a-resp-⊇ I (x ∈₁ c) B A⊆B I⊨B = Assertions✓ I B (A⊆B refl) I⊨B ⊨a-resp-⊇ I (xy ∈₂ r) B A⊆B I⊨B = Assertions✓ I B (A⊆B refl) I⊨B ⊨a-resp-≲ : ∀ {X} {I J : Interp Σ X} → (I ≲ J) → ∀ A → (I ⊨a A) → (J ⊨a A) ⊨a-resp-≲ {X} {I} {J} I≲J ε I⊨A = tt ⊨a-resp-≲ {X} {I} {J} I≲J (A , B) (I⊨A , I⊨B) = (⊨a-resp-≲ I≲J A I⊨A , ⊨a-resp-≲ I≲J B I⊨B) ⊨a-resp-≲ {X} {I} {J} I≲J (x ∼ y) I⊨x∼y = ≈-trans ⌊ J ⌋ (≈-sym ⌊ J ⌋ (≲-resp-ind I≲J x)) (≈-trans ⌊ J ⌋ (≲-resp-≈ ≲⌊ I≲J ⌋ I⊨x∼y) (≲-resp-ind I≲J y)) ⊨a-resp-≲ {X} {I} {J} I≲J (x ∈₁ c) I⊨x∈c = con-≈ ⌊ J ⌋ c (≲-resp-con ≲⌊ I≲J ⌋ I⊨x∈c) (≲-resp-ind I≲J x) ⊨a-resp-≲ {X} {I} {J} I≲J ((x , y) ∈₂ r) I⊨xy∈r = rol-≈ ⌊ J ⌋ r (≈-sym ⌊ J ⌋ (≲-resp-ind I≲J x)) (≲-resp-rol ≲⌊ I≲J ⌋ I⊨xy∈r) (≲-resp-ind I≲J y) ⊨a-resp-≡ : ∀ {X : Set} (I : Interp Σ X) j → (ind I ≡ j) → ∀ A → (I ⊨a A) → (⌊ I ⌋ , j ⊨a A) ⊨a-resp-≡ (I , i) .i refl A I⊨A = I⊨A ⊨a-resp-≡³ : ∀ {V X Y : Set} (I : Interp Σ (X ⊕ V ⊕ Y)) j → (→-dist-⊕ (ind I) ≡ →-dist-⊕ j) → ∀ A → (I ⊨a A) → (⌊ I ⌋ , j ⊨a A) ⊨a-resp-≡³ I j i≡j = ⊨a-resp-≲ (≡³-impl-≲ I j i≡j) ⟨ABox⟩-Assertions : ∀ {X Y a} (f : X → Y) (A : ABox Σ X) → (a ∈ Assertions A) → (⟨ABox⟩ f a ∈ Assertions (⟨ABox⟩ f A)) ⟨ABox⟩-Assertions f ε () ⟨ABox⟩-Assertions f (A , B) (inj₁ a∈A) = inj₁ (⟨ABox⟩-Assertions f A a∈A) ⟨ABox⟩-Assertions f (A , B) (inj₂ a∈B) = inj₂ (⟨ABox⟩-Assertions f B a∈B) ⟨ABox⟩-Assertions f (x ∼ y) refl = refl ⟨ABox⟩-Assertions f (x ∈₁ c) refl = refl ⟨ABox⟩-Assertions f ((x , y) ∈₂ r) refl = refl ⟨ABox⟩-resp-⊨ : ∀ {X Y} {I : Interp Σ X} {j : Y → Δ ⌊ I ⌋} (f : X → Y) → (∀ x → ⌊ I ⌋ ⊨ ind I x ≈ j (f x)) → ∀ A → (I ⊨a A) → (⌊ I ⌋ , j ⊨a ⟨ABox⟩ f A) ⟨ABox⟩-resp-⊨ {X} {Y} {I} f i≈j∘f ε I⊨ε = tt ⟨ABox⟩-resp-⊨ {X} {Y} {I} f i≈j∘f (A , B) (I⊨A , I⊨B) = (⟨ABox⟩-resp-⊨ f i≈j∘f A I⊨A , ⟨ABox⟩-resp-⊨ f i≈j∘f B I⊨B) ⟨ABox⟩-resp-⊨ {X} {Y} {I} f i≈j∘f (x ∼ y) x≈y = ≈-trans ⌊ I ⌋ (≈-sym ⌊ I ⌋ (i≈j∘f x)) (≈-trans ⌊ I ⌋ x≈y (i≈j∘f y)) ⟨ABox⟩-resp-⊨ {X} {Y} {I} f i≈j∘f (x ∈₁ c) x∈⟦c⟧ = con-≈ ⌊ I ⌋ c x∈⟦c⟧ (i≈j∘f x) ⟨ABox⟩-resp-⊨ {X} {Y} {I} f i≈j∘f ((x , y) ∈₂ r) xy∈⟦r⟧ = rol-≈ ⌊ I ⌋ r (≈-sym ⌊ I ⌋ (i≈j∘f x)) xy∈⟦r⟧ (i≈j∘f y) *-resp-⟨ABox⟩ : ∀ {X Y} (f : Y → X) I A → (I ⊨a ⟨ABox⟩ f A) → (f * I ⊨a A) *-resp-⟨ABox⟩ f (I , i) ε I⊨ε = tt *-resp-⟨ABox⟩ f (I , i) (A , B) (I⊨A , I⊨B) = (*-resp-⟨ABox⟩ f (I , i) A I⊨A , *-resp-⟨ABox⟩ f (I , i) B I⊨B ) *-resp-⟨ABox⟩ f (I , i) (x ∼ y) x≈y = x≈y *-resp-⟨ABox⟩ f (I , i) (x ∈₁ c) x∈⟦c⟧ = x∈⟦c⟧ *-resp-⟨ABox⟩ f (I , i) ((x , y) ∈₂ r) xy∈⟦c⟧ = xy∈⟦c⟧ -- bnodes I f is the same as I, except that f is used as the interpretation -- for bnodes. on-bnode : ∀ {V W X Y Z : Set} → (W → Z) → ((X ⊕ V ⊕ Y) → Z) → ((X ⊕ W ⊕ Y) → Z) on-bnode f g (inode x) = g (inode x) on-bnode f g (bnode w) = f w on-bnode f g (enode y) = g (enode y) bnodes : ∀ {V W X Y} → (I : Interp Σ (X ⊕ V ⊕ Y)) → (W → Δ ⌊ I ⌋) → Interp Σ (X ⊕ W ⊕ Y) bnodes I f = (⌊ I ⌋ , on-bnode f (ind I)) bnodes-resp-≲ : ∀ {V W X Y} (I J : Interp Σ (X ⊕ V ⊕ Y)) → (I≲J : I ≲ J) → (f : W → Δ ⌊ I ⌋) → (bnodes I f ≲ bnodes J (≲-image ≲⌊ I≲J ⌋ ∘ f)) bnodes-resp-≲ (I , i) (J , j) (I≲J , i≲j) f = (I≲J , lemma) where lemma : ∀ x → J ⊨ ≲-image I≲J (on-bnode f i x) ≈ on-bnode (≲-image I≲J ∘ f) j x lemma (inode x) = i≲j (inode x) lemma (bnode v) = ≈-refl J lemma (enode y) = i≲j (enode y) -- I ⊨b A whenever there exists an f such that bnodes I f ⊨a A data _⊨b_ {V W X Y} (I : Interp Σ (X ⊕ V ⊕ Y)) (A : ABox Σ (X ⊕ W ⊕ Y)) : Set where _,_ : ∀ f → (bnodes I f ⊨a A) → (I ⊨b A) inb : ∀ {V W X Y} {I : Interp Σ (X ⊕ V ⊕ Y)} {A : ABox Σ (X ⊕ W ⊕ Y)} → (I ⊨b A) → W → Δ ⌊ I ⌋ inb (f , I⊨A) = f ⊨b-impl-⊨a : ∀ {V W X Y} {I : Interp Σ (X ⊕ V ⊕ Y)} {A : ABox Σ (X ⊕ W ⊕ Y)} → (I⊨A : I ⊨b A) → (bnodes I (inb I⊨A) ⊨a A) ⊨b-impl-⊨a (f , I⊨A) = I⊨A ⊨a-impl-⊨b : ∀ {V X Y} (I : Interp Σ (X ⊕ V ⊕ Y)) A → (I ⊨a A) → (I ⊨b A) ⊨a-impl-⊨b I A I⊨A = (ind I ∘ bnode , ⊨a-resp-≲ (≲-refl ⌊ I ⌋ , lemma) A I⊨A) where lemma : ∀ x → ⌊ I ⌋ ⊨ ind I x ≈ on-bnode (ind I ∘ bnode) (ind I) x lemma (inode x) = ≈-refl ⌊ I ⌋ lemma (bnode v) = ≈-refl ⌊ I ⌋ lemma (enode y) = ≈-refl ⌊ I ⌋ ⊨b-resp-≲ : ∀ {V W X Y} {I J : Interp Σ (X ⊕ V ⊕ Y)} → (I ≲ J) → ∀ (A : ABox Σ (X ⊕ W ⊕ Y)) → (I ⊨b A) → (J ⊨b A) ⊨b-resp-≲ I≲J A (f , I⊨A) = ((≲-image ≲⌊ I≲J ⌋ ∘ f) , ⊨a-resp-≲ (bnodes-resp-≲ _ _ I≲J f) A I⊨A)
algebraic-stack_agda0000_doc_5997
{-# OPTIONS --allow-unsolved-metas --no-termination-check #-} module Bag where import Prelude import Equiv import Datoid import Eq import Nat import List import Pos open Prelude open Equiv open Datoid open Eq open Nat open List abstract ---------------------------------------------------------------------- -- Bag type private -- If this were Coq then the invariant should be a Prop. Similar -- remarks apply to some definitions below. Since I have to write -- the supporting library myself I can't be bothered to -- distinguish Set and Prop right now though. data BagType (a : Datoid) : Set where bt : (pairs : List (Pair Pos.Pos (El a))) → NoDuplicates a (map snd pairs) → BagType a list : {a : Datoid} → BagType a → List (Pair Pos.Pos (El a)) list (bt l _) = l contents : {a : Datoid} → BagType a → List (El a) contents b = map snd (list b) invariant : {a : Datoid} → (b : BagType a) → NoDuplicates a (contents b) invariant (bt _ i) = i private elemDatoid : Datoid → Datoid elemDatoid a = pairDatoid Pos.posDatoid a BagEq : (a : Datoid) → BagType a → BagType a → Set BagEq a b1 b2 = rel' (Permutation (elemDatoid a)) (list b1) (list b2) eqRefl : {a : Datoid} → (x : BagType a) → BagEq a x x eqRefl {a} x = refl (Permutation (elemDatoid a)) {list x} eqSym : {a : Datoid} → (x y : BagType a) → BagEq a x y → BagEq a y x eqSym {a} x y = sym (Permutation (elemDatoid a)) {list x} {list y} eqTrans : {a : Datoid} → (x y z : BagType a) → BagEq a x y → BagEq a y z → BagEq a x z eqTrans {a} x y z = trans (Permutation (elemDatoid a)) {list x} {list y} {list z} eqDec : {a : Datoid} → (x y : BagType a) → Either (BagEq a x y) _ eqDec {a} x y = decRel (Permutation (elemDatoid a)) (list x) (list y) BagEquiv : (a : Datoid) → DecidableEquiv (BagType a) BagEquiv a = decEquiv (equiv (BagEq a) eqRefl eqSym eqTrans) (dec eqDec) Bag : Datoid → Datoid Bag a = datoid (BagType a) (BagEquiv a) ---------------------------------------------------------------------- -- Bag primitives empty : {a : Datoid} → El (Bag a) empty = bt nil unit private data LookupResult (a : Datoid) (x : El a) (b : El (Bag a)) : Set where lr : Nat → (b' : El (Bag a)) → Not (member a x (contents b')) → ({y : El a} → Not (member a y (contents b)) → Not (member a y (contents b'))) → LookupResult a x b lookup1 : {a : Datoid} → (n : Pos.Pos) → (y : El a) → (b' : El (Bag a)) → (nyb' : Not (member a y (contents b'))) → (x : El a) → Either (datoidRel a x y) _ → LookupResult a x b' → LookupResult a x (bt (pair n y :: list b') (pair nyb' (invariant b'))) lookup1 n y b' nyb' x (left xy) _ = lr (Pos.toNat n) b' (contrapositive (memberPreservesEq xy (contents b')) nyb') (\{y'} ny'b → snd (notDistribIn ny'b)) lookup1 {a} n y b' nyb' x (right nxy) (lr n' (bt b'' ndb'') nxb'' nmPres) = lr n' (bt (pair n y :: b'') (pair (nmPres nyb') ndb'')) (notDistribOut {datoidRel a x y} nxy nxb'') (\{y'} ny'b → notDistribOut (fst (notDistribIn ny'b)) (nmPres (snd (notDistribIn ny'b)))) lookup2 : {a : Datoid} → (x : El a) → (b : El (Bag a)) → LookupResult a x b lookup2 x (bt nil nd) = lr zero (bt nil nd) (not id) (\{_} _ → not id) lookup2 {a} x (bt (pair n y :: b) (pair nyb ndb)) = lookup1 n y (bt b ndb) nyb x (decRel (datoidEq a) x y) (lookup2 x (bt b ndb)) lookup3 : {a : Datoid} → {x : El a} → {b : El (Bag a)} → LookupResult a x b → Pair Nat (El (Bag a)) lookup3 (lr n b _ _) = pair n b lookup : {a : Datoid} → El a → El (Bag a) → Pair Nat (El (Bag a)) lookup x b = lookup3 (lookup2 x b) private insert' : {a : Datoid} → (x : El a) → {b : El (Bag a)} → LookupResult a x b → El (Bag a) insert' x (lr n (bt b ndb) nxb _) = bt (pair (Pos.suc' n) x :: b) (pair nxb ndb) insert : {a : Datoid} → El a → El (Bag a) → El (Bag a) insert x b = insert' x (lookup2 x b) private postulate insertLemma1 : {a : Datoid} → (x : El a) → (b : El (Bag a)) → (nxb : Not (member a x (contents b))) → datoidRel (Bag a) (insert x b) (bt (pair Pos.one x :: list b) (pair nxb (invariant b))) insertLemma2 : {a : Datoid} → (n : Pos.Pos) → (x : El a) → (b : El (Bag a)) → (nxb : Not (member a x (contents b))) → datoidRel (Bag a) (insert x (bt (pair n x :: list b) (pair nxb (invariant b)))) (bt (pair (Pos.suc n) x :: list b) (pair nxb (invariant b))) ---------------------------------------------------------------------- -- Bag traversals data Traverse (a : Datoid) : Set where Empty : Traverse a Insert : (x : El a) → (b : El (Bag a)) → Traverse a run : {a : Datoid} → Traverse a → El (Bag a) run Empty = empty run (Insert x b) = insert x b abstract traverse : {a : Datoid} → El (Bag a) → Traverse a traverse (bt nil _) = Empty traverse {a} (bt (pair n x :: b) (pair nxb ndb)) = traverse' (Pos.pred n) where private traverse' : Maybe Pos.Pos → Traverse a traverse' Nothing = Insert x (bt b ndb) traverse' (Just n) = Insert x (bt (pair n x :: b) (pair nxb ndb)) traverseTraverses : {a : Datoid} → (b : El (Bag a)) → datoidRel (Bag a) (run (traverse b)) b traverseTraverses {a} (bt nil unit) = dRefl (Bag a) {empty} traverseTraverses {a} (bt (pair n x :: b) (pair nxb ndb)) = tT (Pos.pred n) (Pos.predOK n) where private postulate subst' : {a : Datoid} → (P : El a → Set) → (x y : El a) → datoidRel a x y → P x → P y tT : (predN : Maybe Pos.Pos) → Pos.Pred n predN → datoidRel (Bag a) (run (traverse (bt (pair n x :: b) (pair nxb ndb)))) (bt (pair n x :: b) (pair nxb ndb)) tT Nothing (Pos.ok eq) = {!!} -- subst' (\p → datoidRel (Bag a) -- (run (traverse (bt (pair p x :: b) (pair nxb ndb)))) -- (bt (pair p x :: b) (pair nxb ndb))) -- Pos.one n eq (insertLemma1 x (bt b ndb) nxb) -- eq : one == n -- data Pred (p : Pos) (mP : Maybe Pos) : Set where -- ok : datoidRel posDatoid (sucPred mP) p → Pred p mP -- insert x (bt b ndb) == bt (pair n x :: b) (pair nxb ndb) tT (Just n) (Pos.ok eq) = {!!} -- insertLemma2 n x (bt b ndb) nxb -- insert x (bt (pair n x :: b) (pair nxb btb) == -- bt (pair (suc n) x :: b) (pair nxb btb) bagElim : {a : Datoid} → (P : El (Bag a) → Set) → Respects (Bag a) P → P empty → ((x : El a) → (b : El (Bag a)) → P b → P (insert x b)) → (b : El (Bag a)) → P b bagElim {a} P Prespects e i b = bagElim' b (traverse b) (traverseTraverses b) where private bagElim' : (b : El (Bag a)) → (t : Traverse a) → datoidRel (Bag a) (run t) b → P b bagElim' b Empty eq = subst Prespects empty b eq e bagElim' b (Insert x b') eq = subst Prespects (insert x b') b eq (i x b' (bagElim' b' (traverse b') (traverseTraverses b'))) ---------------------------------------------------------------------- -- Respect and equality preservation lemmas postulate insertPreservesRespect : {a : Datoid} → (P : El (Bag a) → Set) → (x : El a) → Respects (Bag a) P → Respects (Bag a) (\b → P (insert x b)) lookupPreservesRespect : {a : Datoid} → (P : El (Bag a) → Set) → (x : El a) → Respects (Bag a) P → Respects (Bag a) (\b → P (snd $ lookup x b)) -- This doesn't type check without John Major equality or some -- ugly substitutions... -- bagElimPreservesEquality -- : {a : Datoid} -- → (P : El (Bag a) → Set) -- → (r : Respects (Bag a) P) -- → (e : P empty) -- → (i : (x : El a) → (b : El (Bag a)) → P b → P (insert x b)) -- → ( (x1 x2 : El a) → (b1 b2 : El (Bag a)) -- → (p1 : P b1) → (p2 : P b2) -- → (eqX : datoidRel a x1 x2) → (eqB : datoidRel (Bag a) b1 b2) -- → i x1 b1 p1 =^= i x2 b2 p2 -- ) -- → (b1 b2 : El (Bag a)) -- → datoidRel (Bag a) b1 b2 -- → bagElim P r e i b1 =^= bagElim P r e i b2
algebraic-stack_agda0000_doc_5998
{-# OPTIONS --without-K --safe #-} -- | Operations that ensure a cycle traverses a particular element -- at most once. module Dodo.Binary.Cycle where -- Stdlib import import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; _≢_; refl) open import Level using (Level; _⊔_) open import Function using (_∘_) open import Data.Product using (_×_; _,_; proj₁; proj₂) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Relation.Nullary using (yes; no) open import Relation.Binary using (Rel) open import Relation.Binary.Construct.Closure.Transitive using (TransClosure; [_]; _∷_; _∷ʳ_; _++_) -- Local imports open import Dodo.Unary.Dec open import Dodo.Binary.Transitive -- # Definitions -- | The given relation, with proofs that neither element equals `z`. ExcludeRel : {a ℓ : Level} {A : Set a} → (R : Rel A ℓ) → (z : A) → Rel A (a ⊔ ℓ) ExcludeRel R z x y = R x y × x ≢ z × y ≢ z -- | A cycle of R which passes through `z` /exactly once/. data PassCycle {a ℓ : Level} {A : Set a} (R : Rel A ℓ) (z : A) : Set (a ⊔ ℓ) where cycle₁ : R z z → PassCycle R z cycle₂ : {x : A} → x ≢ z → R z x → R x z → PassCycle R z cycleₙ : {x y : A} → R z x → TransClosure (ExcludeRel R z) x y → R y z → PassCycle R z -- # Functions -- | A cycle of a relation either /does not/ pass through an element `y`, or it -- can be made to pass through `y` /exactly once/. -- -- Note that if the original cycle passes `y` /more than once/, then only one -- cycle of the multi-cycle through `y` may be taken. divert-cycle : {a ℓ : Level} {A : Set a} → {R : Rel A ℓ} → {x : A} → TransClosure R x x → {y : A} → DecPred (_≡ y) → PassCycle R y ⊎ TransClosure (ExcludeRel R y) x x divert-cycle {x = x} [ Rxx ] eq-xm with eq-xm x ... | yes refl = inj₁ (cycle₁ Rxx) ... | no x≢y = inj₂ [ ( Rxx , x≢y , x≢y ) ] divert-cycle {A = A} {R = R} {x} ( Rxw ∷ R⁺wx ) {y} eq-dec = lemma Rxw R⁺wx where -- Chain that starts with `y`. -- -- `Ryx` and `R⁺xz` are acculumators. lemma-incl : {x z : A} → R y x → TransClosure (ExcludeRel R y) x z → TransClosure R z y → PassCycle R y lemma-incl Ryx R⁺xz [ Rzy ] = cycleₙ Ryx R⁺xz Rzy lemma-incl Ryx R⁺xz (_∷_ {_} {w} Rzw R⁺wy) with eq-dec w lemma-incl Ryx R⁺xz (_∷_ {_} {w} Rzw R⁺wy) | yes refl = cycleₙ Ryx R⁺xz Rzw lemma-incl Ryx R⁺xz (_∷_ {_} {w} Rzw R⁺wy) | no w≢y = let z≢y = ⁺-lift-predʳ (proj₂ ∘ proj₂) R⁺xz in lemma-incl Ryx (R⁺xz ∷ʳ (Rzw , z≢y , w≢y)) R⁺wy -- First step of a chain that starts with `y`. lemma-incl₀ : {x : A} → R y x → TransClosure R x y → PassCycle R y lemma-incl₀ {x} Ryx R⁺xy with eq-dec x lemma-incl₀ {x} Ryx R⁺xy | yes refl = cycle₁ Ryx lemma-incl₀ {x} Ryx [ Rxy ] | no x≢y = cycle₂ x≢y Ryx Rxy lemma-incl₀ {x} Ryx (_∷_ {_} {z} Rxz R⁺zy) | no x≢y with eq-dec z lemma-incl₀ {x} Ryx (_∷_ {x} {z} Rxz R⁺zy) | no x≢y | yes refl = cycle₂ x≢y Ryx Rxz lemma-incl₀ {x} Ryx (_∷_ {x} {z} Rxz R⁺zy) | no x≢y | no z≢y = lemma-incl Ryx [ Rxz , x≢y , z≢y ] R⁺zy -- Chain that does /not/ (yet) pass through `y`. lemma-excl : {z : A} → TransClosure (ExcludeRel R y) x z → TransClosure R z x → PassCycle R y ⊎ TransClosure (ExcludeRel R y) x x lemma-excl R⁺xz [ Rzx ] = let z≢y = ⁺-lift-predʳ (proj₂ ∘ proj₂) R⁺xz x≢y = ⁺-lift-predˡ (proj₁ ∘ proj₂) R⁺xz in inj₂ (R⁺xz ∷ʳ (Rzx , z≢y , x≢y)) lemma-excl R⁺xz (_∷_ {_} {w} Rzw R⁺wx) with eq-dec w lemma-excl R⁺xz (_∷_ {_} {_} Rzw [ Rwx ]) | yes refl = inj₁ (cycleₙ Rwx R⁺xz Rzw) lemma-excl R⁺xz (_∷_ {_} {_} Rzw (Rwq ∷ R⁺qx)) | yes refl = inj₁ (lemma-incl₀ Rwq (R⁺qx ++ (⁺-map _ proj₁ R⁺xz) ∷ʳ Rzw)) lemma-excl R⁺xz (_∷_ {_} {_} Rzw R⁺wx) | no w≢y = let z≢y = ⁺-lift-predʳ (proj₂ ∘ proj₂) R⁺xz in lemma-excl (R⁺xz ∷ʳ (Rzw , z≢y , w≢y)) R⁺wx lemma : {w : A} → R x w → TransClosure R w x → PassCycle R y ⊎ TransClosure (ExcludeRel R y) x x lemma {_} Rxw R⁺wx with eq-dec x lemma {_} Rxw R⁺wx | yes refl = inj₁ (lemma-incl₀ Rxw R⁺wx) lemma {w} Rxw R⁺wx | no x≢y with eq-dec w lemma {_} Rxw [ Rwx ] | no x≢y | yes refl = inj₁ (cycle₂ x≢y Rwx Rxw) lemma {_} Rxw ( Rwz ∷ R⁺zx ) | no x≢y | yes refl = inj₁ (lemma-incl₀ Rwz (R⁺zx ∷ʳ Rxw)) lemma {_} Rxw R⁺wx | no x≢y | no w≢y = lemma-excl [ Rxw , x≢y , w≢y ] R⁺wx
algebraic-stack_agda0000_doc_5999
{-# OPTIONS --without-K --safe #-} -- A "canonical" presentation of limits in Setoid. -- -- These limits are obviously isomorphic to those created by -- the Completeness proof, but are far less unweildy to work with. -- This isomorphism is witnessed by Categories.Diagram.Pullback.up-to-iso module Categories.Category.Instance.Properties.Setoids.Limits.Canonical where open import Level open import Data.Product using (_,_; _×_) open import Relation.Binary.Bundles using (Setoid) open import Function.Equality as SΠ renaming (id to ⟶-id) import Relation.Binary.Reasoning.Setoid as SR open import Categories.Diagram.Pullback open import Categories.Category.Instance.Setoids open Setoid renaming (_≈_ to [_][_≈_]) -------------------------------------------------------------------------------- -- Pullbacks record FiberProduct {o ℓ} {X Y Z : Setoid o ℓ} (f : X ⟶ Z) (g : Y ⟶ Z) : Set (o ⊔ ℓ) where field elem₁ : Carrier X elem₂ : Carrier Y commute : [ Z ][ f ⟨$⟩ elem₁ ≈ g ⟨$⟩ elem₂ ] open FiberProduct pullback : ∀ (o ℓ : Level) {X Y Z : Setoid (o ⊔ ℓ) ℓ} → (f : X ⟶ Z) → (g : Y ⟶ Z) → Pullback (Setoids (o ⊔ ℓ) ℓ) f g pullback _ _ {X = X} {Y = Y} {Z = Z} f g = record { P = record { Carrier = FiberProduct f g ; _≈_ = λ p q → [ X ][ elem₁ p ≈ elem₁ q ] × [ Y ][ elem₂ p ≈ elem₂ q ] ; isEquivalence = record { refl = (refl X) , (refl Y) ; sym = λ (eq₁ , eq₂) → sym X eq₁ , sym Y eq₂ ; trans = λ (eq₁ , eq₂) (eq₁′ , eq₂′) → (trans X eq₁ eq₁′) , (trans Y eq₂ eq₂′) } } ; p₁ = record { _⟨$⟩_ = elem₁ ; cong = λ (eq₁ , _) → eq₁ } ; p₂ = record { _⟨$⟩_ = elem₂ ; cong = λ (_ , eq₂) → eq₂ } ; isPullback = record { commute = λ {p} {q} (eq₁ , eq₂) → trans Z (cong f eq₁) (commute q) ; universal = λ {A} {h₁} {h₂} eq → record { _⟨$⟩_ = λ a → record { elem₁ = h₁ ⟨$⟩ a ; elem₂ = h₂ ⟨$⟩ a ; commute = eq (refl A) } ; cong = λ eq → cong h₁ eq , cong h₂ eq } ; unique = λ eq₁ eq₂ x≈y → eq₁ x≈y , eq₂ x≈y ; p₁∘universal≈h₁ = λ {_} {h₁} {_} eq → cong h₁ eq ; p₂∘universal≈h₂ = λ {_} {_} {h₂} eq → cong h₂ eq } }
algebraic-stack_agda0000_doc_5872
{-# OPTIONS --cubical --safe #-} module Data.Bag where open import Prelude open import Algebra open import Path.Reasoning infixr 5 _∷_ data ⟅_⟆ (A : Type a) : Type a where [] : ⟅ A ⟆ _∷_ : A → ⟅ A ⟆ → ⟅ A ⟆ com : ∀ x y xs → x ∷ y ∷ xs ≡ y ∷ x ∷ xs trunc : isSet ⟅ A ⟆ record Elim {a ℓ} (A : Type a) (P : ⟅ A ⟆ → Type ℓ) : Type (a ℓ⊔ ℓ) where constructor elim field ⟅_⟆-set : ∀ {xs} → isSet (P xs) ⟅_⟆[] : P [] ⟅_⟆_∷_⟨_⟩ : ∀ x xs → P xs → P (x ∷ xs) private z = ⟅_⟆[]; f = ⟅_⟆_∷_⟨_⟩ field ⟅_⟆-com : (∀ x y xs pxs → PathP (λ i → P (com x y xs i)) (f x (y ∷ xs) (f y xs pxs)) (f y (x ∷ xs) (f x xs pxs))) ⟅_⟆⇓ : (xs : ⟅ A ⟆) → P xs ⟅ [] ⟆⇓ = z ⟅ x ∷ xs ⟆⇓ = f x xs ⟅ xs ⟆⇓ ⟅ com x y xs i ⟆⇓ = ⟅_⟆-com x y xs ⟅ xs ⟆⇓ i ⟅ trunc xs ys x y i j ⟆⇓ = isOfHLevel→isOfHLevelDep 2 (λ xs → ⟅_⟆-set {xs}) ⟅ xs ⟆⇓ ⟅ ys ⟆⇓ (cong ⟅_⟆⇓ x) (cong ⟅_⟆⇓ y) (trunc xs ys x y) i j open Elim infixr 0 elim-syntax elim-syntax : ∀ {a ℓ} → (A : Type a) → (⟅ A ⟆ → Type ℓ) → Type (a ℓ⊔ ℓ) elim-syntax = Elim syntax elim-syntax A (λ xs → Pxs) = xs ⦂⟅ A ⟆→ Pxs record ElimProp {a ℓ} (A : Type a) (P : ⟅ A ⟆ → Type ℓ) : Type (a ℓ⊔ ℓ) where constructor elim-prop field ⟦_⟧-prop : ∀ {xs} → isProp (P xs) ⟦_⟧[] : P [] ⟦_⟧_∷_⟨_⟩ : ∀ x xs → P xs → P (x ∷ xs) private z = ⟦_⟧[]; f = ⟦_⟧_∷_⟨_⟩ ⟦_⟧⇑ = elim (isProp→isSet ⟦_⟧-prop) z f (λ x y xs pxs → toPathP (⟦_⟧-prop (transp (λ i → P (com x y xs i)) i0 (f x (y ∷ xs) (f y xs pxs))) (f y (x ∷ xs) (f x xs pxs)))) ⟦_⟧⇓ = ⟅ ⟦_⟧⇑ ⟆⇓ open ElimProp infixr 0 elim-prop-syntax elim-prop-syntax : ∀ {a ℓ} → (A : Type a) → (⟅ A ⟆ → Type ℓ) → Type (a ℓ⊔ ℓ) elim-prop-syntax = ElimProp syntax elim-prop-syntax A (λ xs → Pxs) = xs ⦂⟅ A ⟆→∥ Pxs ∥ record [⟅_⟆→_] {a b} (A : Type a) (B : Type b) : Type (a ℓ⊔ b) where constructor rec field [_]-set : isSet B [_]_∷_ : A → B → B [_][] : B private f = [_]_∷_; z = [_][] field [_]-com : ∀ x y xs → f x (f y xs) ≡ f y (f x xs) [_]⇑ = elim [_]-set z (λ x _ → f x) (λ x y _ → [_]-com x y) [_]↓ = ⟅ [_]⇑ ⟆⇓ open [⟅_⟆→_] infixr 5 _∪_ _∪_ : ⟅ A ⟆ → ⟅ A ⟆ → ⟅ A ⟆ _∪_ = λ xs ys → [ ys ∪′ ]↓ xs where _∪′ : ⟅ A ⟆ → [⟅ A ⟆→ ⟅ A ⟆ ] [ ys ∪′ ]-set = trunc [ ys ∪′ ] x ∷ xs = x ∷ xs [ ys ∪′ ][] = ys [ ys ∪′ ]-com = com ∪-assoc : (xs ys zs : ⟅ A ⟆) → (xs ∪ ys) ∪ zs ≡ xs ∪ (ys ∪ zs) ∪-assoc = λ xs ys zs → ⟦ ∪-assoc′ ys zs ⟧⇓ xs where ∪-assoc′ : ∀ ys zs → xs ⦂⟅ A ⟆→∥ (xs ∪ ys) ∪ zs ≡ xs ∪ (ys ∪ zs) ∥ ⟦ ∪-assoc′ ys zs ⟧-prop = trunc _ _ ⟦ ∪-assoc′ ys zs ⟧[] = refl ⟦ ∪-assoc′ ys zs ⟧ x ∷ xs ⟨ P ⟩ = cong (x ∷_) P ∪-cons : ∀ (x : A) xs ys → (x ∷ xs) ∪ ys ≡ xs ∪ (x ∷ ys) ∪-cons = λ x xs ys → ⟦ ∪-cons′ x ys ⟧⇓ xs where ∪-cons′ : ∀ x ys → xs ⦂⟅ A ⟆→∥ (x ∷ xs) ∪ ys ≡ xs ∪ (x ∷ ys) ∥ ⟦ ∪-cons′ x ys ⟧-prop = trunc _ _ ⟦ ∪-cons′ x ys ⟧[] = refl ⟦ ∪-cons′ x ys ⟧ y ∷ xs ⟨ P ⟩ = cong (_∪ ys) (com x y xs) ; cong (y ∷_) P ∪-idʳ : (xs : ⟅ A ⟆) → xs ∪ [] ≡ xs ∪-idʳ = ⟦ ∪-idʳ′ ⟧⇓ where ∪-idʳ′ : xs ⦂⟅ A ⟆→∥ xs ∪ [] ≡ xs ∥ ⟦ ∪-idʳ′ ⟧-prop = trunc _ _ ⟦ ∪-idʳ′ ⟧[] = refl ⟦ ∪-idʳ′ ⟧ x ∷ xs ⟨ P ⟩ = cong (x ∷_) P ∪-comm : (xs ys : ⟅ A ⟆) → xs ∪ ys ≡ ys ∪ xs ∪-comm {A = A} = λ xs ys → ⟦ ∪-comm′ ys ⟧⇓ xs where ∪-comm′ : (ys : ⟅ A ⟆) → xs ⦂⟅ A ⟆→∥ xs ∪ ys ≡ ys ∪ xs ∥ ⟦ ∪-comm′ ys ⟧-prop = trunc _ _ ⟦ ∪-comm′ ys ⟧[] = sym (∪-idʳ ys) ⟦ ∪-comm′ ys ⟧ x ∷ xs ⟨ P ⟩ = (x ∷ xs) ∪ ys ≡⟨ cong (x ∷_) P ⟩ (x ∷ ys) ∪ xs ≡⟨ ∪-cons x ys xs ⟩ ys ∪ x ∷ xs ∎ ⟅⟆-commutative-monoid : ∀ {a} (A : Type a) → CommutativeMonoid _ Monoid.𝑆 (CommutativeMonoid.monoid (⟅⟆-commutative-monoid A)) = ⟅ A ⟆ Monoid._∙_ (CommutativeMonoid.monoid (⟅⟆-commutative-monoid A)) = _∪_ Monoid.ε (CommutativeMonoid.monoid (⟅⟆-commutative-monoid A)) = [] Monoid.assoc (CommutativeMonoid.monoid (⟅⟆-commutative-monoid A)) = ∪-assoc Monoid.ε∙ (CommutativeMonoid.monoid (⟅⟆-commutative-monoid A)) _ = refl Monoid.∙ε (CommutativeMonoid.monoid (⟅⟆-commutative-monoid A)) = ∪-idʳ CommutativeMonoid.comm (⟅⟆-commutative-monoid A) = ∪-comm module _ {ℓ} (mon : CommutativeMonoid ℓ) (sIsSet : isSet (CommutativeMonoid.𝑆 mon)) where open CommutativeMonoid mon ⟦_⟧ : (A → 𝑆) → ⟅ A ⟆ → 𝑆 ⟦_⟧ = λ h → [ ⟦ h ⟧′ ]↓ where ⟦_⟧′ : (A → 𝑆) → [⟅ A ⟆→ 𝑆 ] [ ⟦ h ⟧′ ] x ∷ xs = h x ∙ xs [ ⟦ h ⟧′ ][] = ε [ ⟦ h ⟧′ ]-com x y xs = h x ∙ (h y ∙ xs) ≡˘⟨ assoc _ _ _ ⟩ (h x ∙ h y) ∙ xs ≡⟨ cong (_∙ xs) (comm _ _) ⟩ (h y ∙ h x) ∙ xs ≡⟨ assoc _ _ _ ⟩ h y ∙ (h x ∙ xs) ∎ [ ⟦ h ⟧′ ]-set = sIsSet record ⟦_≡_⟧ {a b} {A : Type a} {B : Type b} (h : ⟅ A ⟆ → B) (xf : [⟅ A ⟆→ B ]) : Type (a ℓ⊔ b) where constructor elim-univ field ⟦_≡⟧_∷_ : ∀ x xs → h (x ∷ xs) ≡ [ xf ] x ∷ h xs ⟦_≡⟧[] : h [] ≡ [ xf ][] ⟦_≡⟧⇓ : ∀ xs → h xs ≡ [ xf ]↓ xs ⟦_≡⟧⇓ = ⟦ ≡⇓′ ⟧⇓ where ≡⇓′ : xs ⦂⟅ A ⟆→∥ h xs ≡ [ xf ]↓ xs ∥ ⟦ ≡⇓′ ⟧-prop = [ xf ]-set _ _ ⟦ ≡⇓′ ⟧[] = ⟦_≡⟧[] ⟦ ≡⇓′ ⟧ x ∷ xs ⟨ P ⟩ = ⟦_≡⟧_∷_ x _ ; cong ([ xf ] x ∷_) P open ⟦_≡_⟧ record ⟦_⊚_≡_⟧ {a b c} {A : Type a} {B : Type b} {C : Type c} (h : B → C) (xf : [⟅ A ⟆→ B ]) (yf : [⟅ A ⟆→ C ]) : Type (a ℓ⊔ b ℓ⊔ c) where constructor elim-fuse field ⟦_∘≡⟧_∷_ : ∀ x xs → h ([ xf ] x ∷ xs) ≡ [ yf ] x ∷ h xs ⟦_∘≡⟧[] : h [ xf ][] ≡ [ yf ][] ⟦_∘≡⟧⇓ : ∀ xs → h ([ xf ]↓ xs) ≡ [ yf ]↓ xs ⟦_∘≡⟧⇓ = ⟦ ≡⇓′ ⟧⇓ where ≡⇓′ : xs ⦂⟅ A ⟆→∥ h ([ xf ]↓ xs) ≡ [ yf ]↓ xs ∥ ⟦ ≡⇓′ ⟧-prop = [ yf ]-set _ _ ⟦ ≡⇓′ ⟧[] = ⟦_∘≡⟧[] ⟦ ≡⇓′ ⟧ x ∷ xs ⟨ P ⟩ = ⟦_∘≡⟧_∷_ x _ ; cong ([ yf ] x ∷_) P open ⟦_⊚_≡_⟧ map-alg : (A → B) → [⟅ A ⟆→ ⟅ B ⟆ ] [ map-alg f ]-set = trunc [ map-alg f ][] = [] [ map-alg f ] x ∷ xs = f x ∷ xs [ map-alg f ]-com x y = com (f x) (f y) map : (A → B) → ⟅ A ⟆ → ⟅ B ⟆ map f = [ map-alg f ]↓ [_]∘_ : [⟅ B ⟆→ C ] → (A → B) → [⟅ A ⟆→ C ] [ [ g ]∘ f ]-set = [ g ]-set [ [ g ]∘ f ][] = [ g ][] [ [ g ]∘ f ] x ∷ xs = [ g ] f x ∷ xs [ [ g ]∘ f ]-com x y = [ g ]-com (f x) (f y) map-fuse : ∀ (g : [⟅ B ⟆→ C ]) (f : A → B) → [ g ]↓ ∘ map f ≡ [ [ g ]∘ f ]↓ map-fuse g f = funExt ⟦ map-fuse′ g f ∘≡⟧⇓ where map-fuse′ : (g : [⟅ B ⟆→ C ]) (f : A → B) → ⟦ [ g ]↓ ⊚ map-alg f ≡ [ g ]∘ f ⟧ ⟦ map-fuse′ g f ∘≡⟧ x ∷ xs = refl ⟦ map-fuse′ g f ∘≡⟧[] = refl bind : ⟅ A ⟆ → (A → ⟅ B ⟆) → ⟅ B ⟆ bind xs f = ⟦ ⟅⟆-commutative-monoid _ ⟧ trunc f xs
algebraic-stack_agda0000_doc_5873
record R (A : Set) : Set₁ where field P : A → Set p : (x : A) → P x module M (r : (A : Set) → R A) where open module R′ {A : Set} = R (r A) public postulate r : (A : Set) → R A A : Set open M r internal-error : (x : A) → P x internal-error x = p
algebraic-stack_agda0000_doc_5874
-- Andreas, 2017-08-23, issue #2714 -- Make sure we produce a warning about missing main function -- even though we import a module with --no-main. open import Issue2712
algebraic-stack_agda0000_doc_5875
module _ where open import Common.Prelude case_of_ : {A B : Set} → A → (A → B) → B case x of f = f x {-# INLINE case_of_ #-} patlam : Nat → Nat patlam zero = zero patlam (suc n) = case n of λ { zero → zero ; (suc m) → m + patlam n } static : {A : Set} → A → A static x = x {-# STATIC static #-} -- The static here will make the compiler get to the pattern lambda in the body of patlam -- before compiling patlam. If we're not careful this might make the pattern lambda not -- inline in the body of patlam. foo : Nat → Nat foo n = static (patlam (suc n)) main : IO Unit main = printNat (foo 5)
algebraic-stack_agda0000_doc_5876
import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; sym; cong; cong₂; cong-app) open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎) open import Function using (_∘_) open import Data.Nat using (ℕ; zero; suc) open import Data.Fin hiding (_+_; #_) open import DeBruijn postulate extensionality : ∀ {A B : Set} {f g : A → B} → (∀ (x : A) → f x ≡ g x) ----------------------- → f ≡ g ⟪_⟫ : ∀ {n m} → Subst n m → Term n → Term m ⟪ σ ⟫ = subst σ ids : ∀ {n} → Subst n n ids x = # x ↑ : ∀ {n} → Subst n (suc n) ↑ x = # (suc x) infix 6 _•_ _•_ : ∀ {n m} → Term m → Subst n m → Subst (suc n) m (M • σ) zero = M (M • σ) (suc x) = σ x infixr 5 _⨟_ _⨟_ : ∀ {n k m} → Subst n k → Subst k m → Subst n m σ ⨟ τ = ⟪ τ ⟫ ∘ σ ren : ∀ {n m} → Rename n m → Subst n m ren ρ = ids ∘ ρ sub-head : ∀ {n m} {M : Term m} {σ : Subst n m} → ⟪ M • σ ⟫ (# zero) ≡ M sub-head = refl sub-tail : ∀ {n m} {M : Term m} {σ : Subst n m} → (↑ ⨟ M • σ) ≡ σ sub-tail = extensionality λ x → refl sub-idL : ∀ {n m} {σ : Subst n m} → ids ⨟ σ ≡ σ sub-idL = extensionality λ x → refl sub-dist : ∀ {n m k} {σ : Subst n m} {τ : Subst m k} {M : Term m} → ((M • σ) ⨟ τ) ≡ ((subst τ M) • (σ ⨟ τ)) sub-dist {n}{m}{k}{σ}{τ}{M} = extensionality λ x → lemma {x = x} where lemma : ∀ {x : Fin (suc n)} → ((M • σ) ⨟ τ) x ≡ ((subst τ M) • (σ ⨟ τ)) x lemma {x = zero} = refl lemma {x = suc x} = refl cong-ext : ∀ {n m}{ρ ρ′ : Rename n m} → (ρ ≡ ρ′) --------------------------------- → ext ρ ≡ ext ρ′ cong-ext{n}{m}{ρ}{ρ′} rr = extensionality λ x → lemma {x} where lemma : ∀ {x : Fin (suc n)} → ext ρ x ≡ ext ρ′ x lemma {zero} = refl lemma {suc y} = cong suc (cong-app rr y) cong-rename : ∀ {n m}{ρ ρ′ : Rename n m}{M M′ : Term n} → ρ ≡ ρ′ → M ≡ M′ ------------------------ → rename ρ M ≡ rename ρ′ M cong-rename {M = # x} rr refl = cong #_ (cong-app rr x) cong-rename {ρ = ρ} {ρ′ = ρ′} {M = ƛ N} rr refl = cong ƛ_ (cong-rename {ρ = ext ρ}{ρ′ = ext ρ′}{M = N} (cong-ext rr) refl) cong-rename {M = L · M} rr refl = cong₂ _·_ (cong-rename rr refl) (cong-rename rr refl) cong-exts : ∀ {n m}{σ σ′ : Subst n m} → σ ≡ σ′ ---------------- → exts σ ≡ exts σ′ cong-exts{n}{m}{σ}{σ′} ss = extensionality λ x → lemma {x} where lemma : ∀ {x} → exts σ x ≡ exts σ′ x lemma {zero} = refl lemma {suc x} = cong (rename suc) (cong-app (ss) x) cong-sub : ∀ {n m}{σ σ′ : Subst n m}{M M′ : Term n} → σ ≡ σ′ → M ≡ M′ ----------------------- → subst σ M ≡ subst σ′ M′ cong-sub {n}{m}{σ}{σ′}{# x} ss refl = cong-app ss x cong-sub {n}{m}{σ}{σ′}{ƛ M} ss refl = cong ƛ_ (cong-sub {σ = exts σ}{σ′ = exts σ′} {M = M} (cong-exts ss) refl) cong-sub {n}{m}{σ}{σ′}{L · M} ss refl = cong₂ _·_ (cong-sub {M = L} ss refl) (cong-sub {M = M} ss refl) cong-sub-zero : ∀ {n} {M M′ : Term n} → M ≡ M′ ---------------------------- → subst-zero M ≡ subst-zero M′ cong-sub-zero {n}{M}{M′} mm′ = extensionality λ x → cong (λ z → subst-zero z x) mm′ cong-cons : ∀ {n m}{M N : Term m}{σ τ : Subst n m} → M ≡ N → σ ≡ τ ----------------- → (M • σ) ≡ (N • τ) cong-cons{n}{m}{M}{N}{σ}{τ} refl st = extensionality lemma where lemma : (x : Fin (suc n)) → (M • σ) x ≡ (M • τ) x lemma zero = refl lemma (suc x) = cong-app st x cong-seq : ∀ {n m k}{σ σ′ : Subst n m}{τ τ′ : Subst m k} → (σ ≡ σ′) → (τ ≡ τ′) → (σ ⨟ τ) ≡ (σ′ ⨟ τ′) cong-seq {n}{m}{k}{σ}{σ′}{τ}{τ′} ss′ tt′ = extensionality lemma where lemma : (x : Fin n) → (σ ⨟ τ) x ≡ (σ′ ⨟ τ′) x lemma x = begin (σ ⨟ τ) x ≡⟨⟩ subst τ (σ x) ≡⟨ cong (subst τ) (cong-app ss′ x) ⟩ subst τ (σ′ x) ≡⟨ cong-sub{M = σ′ x} tt′ refl ⟩ subst τ′ (σ′ x) ≡⟨⟩ (σ′ ⨟ τ′) x ∎ ren-ext : ∀ {n m} {ρ : Rename n m} → ren (ext ρ) ≡ exts (ren ρ) ren-ext {n}{m}{ρ} = extensionality λ x → lemma {x = x} where lemma : ∀ {x : Fin (suc n)} → (ren (ext ρ)) x ≡ exts (ren ρ) x lemma {x = zero} = refl lemma {x = suc x} = refl rename-subst-ren : ∀ {n m} {ρ : Rename n m} {M : Term n} → rename ρ M ≡ ⟪ ren ρ ⟫ M rename-subst-ren {M = # x} = refl rename-subst-ren {n}{ρ = ρ}{M = ƛ N} = begin rename ρ (ƛ N) ≡⟨⟩ ƛ rename (ext ρ) N ≡⟨ cong ƛ_ (rename-subst-ren {ρ = ext ρ}{M = N}) ⟩ ƛ ⟪ ren (ext ρ) ⟫ N ≡⟨ cong ƛ_ (cong-sub{M = N} ren-ext refl) ⟩ ƛ ⟪ exts (ren ρ) ⟫ N ≡⟨⟩ ⟪ ren ρ ⟫ (ƛ N) ∎ rename-subst-ren {M = L · M} = cong₂ _·_ rename-subst-ren rename-subst-ren exts-cons-shift : ∀ {n m} {σ : Subst n m} → exts σ ≡ (# zero • (σ ⨟ ↑)) exts-cons-shift = extensionality λ x → lemma{x = x} where lemma : ∀ {n m} {σ : Subst n m} {x : Fin (suc n)} → exts σ x ≡ (# zero • (σ ⨟ ↑)) x lemma {x = zero} = refl lemma {x = suc y} = rename-subst-ren subst-zero-cons-ids : ∀ {n}{M : Term n} → subst-zero M ≡ (M • ids) subst-zero-cons-ids = extensionality λ x → lemma {x = x} where lemma : ∀ {n}{M : Term n}{x : Fin (suc n)} → subst-zero M x ≡ (M • ids) x lemma {x = zero} = refl lemma {x = suc x} = refl exts-ids : ∀ {n} → exts ids ≡ ids {suc n} exts-ids {n} = extensionality lemma where lemma : (x : Fin (suc n)) → exts ids x ≡ ids x lemma zero = refl lemma (suc x) = refl sub-id : ∀ {n} {M : Term n} → ⟪ ids ⟫ M ≡ M sub-id {M = # x} = refl sub-id {M = ƛ N} = begin ⟪ ids ⟫ (ƛ N) ≡⟨⟩ ƛ ⟪ exts ids ⟫ N ≡⟨ cong ƛ_ (cong-sub{M = N} exts-ids refl) ⟩ ƛ ⟪ ids ⟫ N ≡⟨ cong ƛ_ sub-id ⟩ ƛ N ∎ sub-id {M = L · M} = cong₂ _·_ sub-id sub-id sub-idR : ∀ {n m} {σ : Subst n m} → (σ ⨟ ids) ≡ σ sub-idR {n}{σ = σ} = begin σ ⨟ ids ≡⟨⟩ ⟪ ids ⟫ ∘ σ ≡⟨ extensionality (λ x → sub-id) ⟩ σ ∎ compose-ext : ∀ {n m k}{ρ : Rename m k} {ρ′ : Rename n m} → ((ext ρ) ∘ (ext ρ′)) ≡ ext (ρ ∘ ρ′) compose-ext = extensionality λ x → lemma {x = x} where lemma : ∀ {n m k}{ρ : Rename m k} {ρ′ : Rename n m} {x : Fin (suc n)} → ((ext ρ) ∘ (ext ρ′)) x ≡ ext (ρ ∘ ρ′) x lemma {x = zero} = refl lemma {x = suc x} = refl compose-rename : ∀ {n m k}{M : Term n}{ρ : Rename m k}{ρ′ : Rename n m} → rename ρ (rename ρ′ M) ≡ rename (ρ ∘ ρ′) M compose-rename {M = # x} = refl compose-rename {n}{m}{k}{ƛ N}{ρ}{ρ′} = cong ƛ_ G where G : rename (ext ρ) (rename (ext ρ′) N) ≡ rename (ext (ρ ∘ ρ′)) N G = begin rename (ext ρ) (rename (ext ρ′) N) ≡⟨ compose-rename{ρ = ext ρ}{ρ′ = ext ρ′} ⟩ rename ((ext ρ) ∘ (ext ρ′)) N ≡⟨ cong-rename compose-ext refl ⟩ rename (ext (ρ ∘ ρ′)) N ∎ compose-rename {M = L · M} = cong₂ _·_ compose-rename compose-rename commute-subst-rename : ∀ {n m}{M : Term n}{σ : Subst n m} {ρ : ∀ {n} → Rename n (suc n)} → (∀ {x : Fin n} → exts σ (ρ x) ≡ rename ρ (σ x)) → subst (exts σ) (rename ρ M) ≡ rename ρ (subst σ M) commute-subst-rename {M = # x} r = r commute-subst-rename{n}{m}{ƛ N}{σ}{ρ} r = cong ƛ_ (commute-subst-rename{suc n}{suc m}{N} {exts σ}{ρ = ρ′} (λ {x} → H {x})) where ρ′ : ∀ {n} → Rename n (suc n) ρ′ {zero} = λ () ρ′ {suc n} = ext ρ H : {x : Fin (suc n)} → exts (exts σ) (ext ρ x) ≡ rename (ext ρ) (exts σ x) H {zero} = refl H {suc y} = begin exts (exts σ) (ext ρ (suc y)) ≡⟨⟩ rename suc (exts σ (ρ y)) ≡⟨ cong (rename suc) r ⟩ rename suc (rename ρ (σ y)) ≡⟨ compose-rename ⟩ rename (suc ∘ ρ) (σ y) ≡⟨ cong-rename refl refl ⟩ rename ((ext ρ) ∘ suc) (σ y) ≡⟨ sym compose-rename ⟩ rename (ext ρ) (rename suc (σ y)) ≡⟨⟩ rename (ext ρ) (exts σ (suc y)) ∎ commute-subst-rename {M = L · M}{ρ = ρ} r = cong₂ _·_ (commute-subst-rename{M = L}{ρ = ρ} r) (commute-subst-rename{M = M}{ρ = ρ} r) exts-seq : ∀ {n m m′} {σ₁ : Subst n m} {σ₂ : Subst m m′} → (exts σ₁ ⨟ exts σ₂) ≡ exts (σ₁ ⨟ σ₂) exts-seq = extensionality λ x → lemma {x = x} where lemma : ∀ {n m m′}{x : Fin (suc n)} {σ₁ : Subst n m}{σ₂ : Subst m m′} → (exts σ₁ ⨟ exts σ₂) x ≡ exts (σ₁ ⨟ σ₂) x lemma {x = zero} = refl lemma {x = suc x}{σ₁}{σ₂} = begin (exts σ₁ ⨟ exts σ₂) (suc x) ≡⟨⟩ ⟪ exts σ₂ ⟫ (rename suc (σ₁ x)) ≡⟨ commute-subst-rename{M = σ₁ x}{σ = σ₂}{ρ = suc} refl ⟩ rename suc (⟪ σ₂ ⟫ (σ₁ x)) ≡⟨⟩ rename suc ((σ₁ ⨟ σ₂) x) ∎ sub-sub : ∀ {n m k}{M : Term n} {σ₁ : Subst n m}{σ₂ : Subst m k} → ⟪ σ₂ ⟫ (⟪ σ₁ ⟫ M) ≡ ⟪ σ₁ ⨟ σ₂ ⟫ M sub-sub {M = # x} = refl sub-sub {n}{m}{k}{ƛ N}{σ₁}{σ₂} = begin ⟪ σ₂ ⟫ (⟪ σ₁ ⟫ (ƛ N)) ≡⟨⟩ ƛ ⟪ exts σ₂ ⟫ (⟪ exts σ₁ ⟫ N) ≡⟨ cong ƛ_ (sub-sub{M = N}{σ₁ = exts σ₁}{σ₂ = exts σ₂}) ⟩ ƛ ⟪ exts σ₁ ⨟ exts σ₂ ⟫ N ≡⟨ cong ƛ_ (cong-sub{M = N} exts-seq refl) ⟩ ƛ ⟪ exts ( σ₁ ⨟ σ₂) ⟫ N ∎ sub-sub {M = L · M} = cong₂ _·_ (sub-sub{M = L}) (sub-sub{M = M}) rename-subst : ∀ {n m m′}{M : Term n}{ρ : Rename n m}{σ : Subst m m′} → ⟪ σ ⟫ (rename ρ M) ≡ ⟪ σ ∘ ρ ⟫ M rename-subst {n}{m}{m′}{M}{ρ}{σ} = begin ⟪ σ ⟫ (rename ρ M) ≡⟨ cong ⟪ σ ⟫ (rename-subst-ren{M = M}) ⟩ ⟪ σ ⟫ (⟪ ren ρ ⟫ M) ≡⟨ sub-sub{M = M} ⟩ ⟪ ren ρ ⨟ σ ⟫ M ≡⟨⟩ ⟪ σ ∘ ρ ⟫ M ∎ sub-assoc : ∀ {n m k Ψ} {σ : Subst n m} {τ : Subst m k} {θ : Subst k Ψ} → (σ ⨟ τ) ⨟ θ ≡ (σ ⨟ τ ⨟ θ) sub-assoc {n}{m}{k}{Ψ}{σ}{τ}{θ} = extensionality λ x → lemma{x = x} where lemma : ∀ {x : Fin n} → ((σ ⨟ τ) ⨟ θ) x ≡ (σ ⨟ τ ⨟ θ) x lemma {x} = begin ((σ ⨟ τ) ⨟ θ) x ≡⟨⟩ ⟪ θ ⟫ (⟪ τ ⟫ (σ x)) ≡⟨ sub-sub{M = σ x} ⟩ ⟪ τ ⨟ θ ⟫ (σ x) ≡⟨⟩ (σ ⨟ τ ⨟ θ) x ∎ subst-zero-exts-cons : ∀ {n m}{σ : Subst n m}{M : Term m} → exts σ ⨟ subst-zero M ≡ (M • σ) subst-zero-exts-cons {n}{m}{σ}{M} = begin exts σ ⨟ subst-zero M ≡⟨ cong-seq exts-cons-shift subst-zero-cons-ids ⟩ (# zero • (σ ⨟ ↑)) ⨟ (M • ids) ≡⟨ sub-dist ⟩ (⟪ M • ids ⟫ (# zero)) • ((σ ⨟ ↑) ⨟ (M • ids)) ≡⟨ cong-cons (sub-head{σ = ids}) refl ⟩ M • ((σ ⨟ ↑) ⨟ (M • ids)) ≡⟨ cong-cons refl (sub-assoc{σ = σ}) ⟩ M • (σ ⨟ (↑ ⨟ (M • ids))) ≡⟨ cong-cons refl (cong-seq{σ = σ} refl (sub-tail{M = M}{σ = ids})) ⟩ M • (σ ⨟ ids) ≡⟨ cong-cons refl (sub-idR{σ = σ}) ⟩ M • σ ∎ subst-commute : ∀ {n m} {N : Term (suc n)} {M : Term n} {σ : Subst n m} → ⟪ exts σ ⟫ N [ ⟪ σ ⟫ M ] ≡ ⟪ σ ⟫ (N [ M ]) subst-commute {n}{m}{N}{M}{σ} = begin ⟪ exts σ ⟫ N [ ⟪ σ ⟫ M ] ≡⟨⟩ ⟪ subst-zero (⟪ σ ⟫ M) ⟫ (⟪ exts σ ⟫ N) ≡⟨ cong-sub {M = ⟪ exts σ ⟫ N} subst-zero-cons-ids refl ⟩ ⟪ ⟪ σ ⟫ M • ids ⟫ (⟪ exts σ ⟫ N) ≡⟨ sub-sub {M = N} ⟩ ⟪ (exts σ) ⨟ ((⟪ σ ⟫ M) • ids) ⟫ N ≡⟨ cong-sub {M = N} (cong-seq exts-cons-shift refl) refl ⟩ ⟪ (# zero • (σ ⨟ ↑)) ⨟ (⟪ σ ⟫ M • ids) ⟫ N ≡⟨ cong-sub {M = N} (sub-dist {M = # zero}) refl ⟩ ⟪ ⟪ ⟪ σ ⟫ M • ids ⟫ (# zero) • ((σ ⨟ ↑) ⨟ (⟪ σ ⟫ M • ids)) ⟫ N ≡⟨⟩ ⟪ ⟪ σ ⟫ M • ((σ ⨟ ↑) ⨟ (⟪ σ ⟫ M • ids)) ⟫ N ≡⟨ cong-sub {M = N} (cong-cons refl (sub-assoc {σ = σ})) refl ⟩ ⟪ ⟪ σ ⟫ M • (σ ⨟ ↑ ⨟ ⟪ σ ⟫ M • ids) ⟫ N ≡⟨ cong-sub {M = N} refl refl ⟩ ⟪ ⟪ σ ⟫ M • (σ ⨟ ids) ⟫ N ≡⟨ cong-sub {M = N} (cong-cons refl (sub-idR {σ = σ})) refl ⟩ ⟪ ⟪ σ ⟫ M • σ ⟫ N ≡⟨ cong-sub {M = N} (cong-cons refl (sub-idL {σ = σ})) refl ⟩ ⟪ ⟪ σ ⟫ M • (ids ⨟ σ) ⟫ N ≡⟨ cong-sub {M = N} (sym sub-dist) refl ⟩ ⟪ M • ids ⨟ σ ⟫ N ≡⟨ sym (sub-sub {M = N}) ⟩ ⟪ σ ⟫ (⟪ M • ids ⟫ N) ≡⟨ cong ⟪ σ ⟫ (sym (cong-sub {M = N} subst-zero-cons-ids refl)) ⟩ ⟪ σ ⟫ (N [ M ]) ∎ rename-subst-commute : ∀ {n m} {N : Term (suc n)} {M : Term n} {ρ : Rename n m } → (rename (ext ρ) N) [ rename ρ M ] ≡ rename ρ (N [ M ]) rename-subst-commute {n}{m}{N}{M}{ρ} = begin (rename (ext ρ) N) [ rename ρ M ] ≡⟨ cong-sub (cong-sub-zero (rename-subst-ren {M = M})) (rename-subst-ren {M = N}) ⟩ (⟪ ren (ext ρ) ⟫ N) [ ⟪ ren ρ ⟫ M ] ≡⟨ cong-sub refl (cong-sub {M = N} ren-ext refl) ⟩ (⟪ exts (ren ρ) ⟫ N) [ ⟪ ren ρ ⟫ M ] ≡⟨ subst-commute {N = N} ⟩ subst (ren ρ) (N [ M ]) ≡⟨ sym (rename-subst-ren) ⟩ rename ρ (N [ M ]) ∎ infix 8 _〔_〕 _〔_〕 : ∀ {n} → Term (suc (suc n)) → Term n → Term (suc n) _〔_〕 N M = subst (exts (subst-zero M)) N substitution-lemma : ∀ {n} {M : Term (suc (suc n))} {N : Term (suc n)} {L : Term n} → M [ N ] [ L ] ≡ (M 〔 L 〕) [ (N [ L ]) ] substitution-lemma {M = M}{N = N}{L = L} = sym (subst-commute {N = M}{M = N}{σ = subst-zero L})
algebraic-stack_agda0000_doc_5877
module Category.Functor.Either where open import Agda.Primitive using (_⊔_) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Category.Functor using (RawFunctor ; module RawFunctor ) open import Category.Applicative using (RawApplicative; module RawApplicative) open import Function using (_∘_) Either : ∀ {l₁ l₂} (A : Set l₁) (B : Set l₂) → Set (l₁ ⊔ l₂) Either = _⊎_ eitherFunctor : ∀ {l₁ l₂} {A : Set l₁} → RawFunctor (Either {l₁} {l₂} A) eitherFunctor = record { _<$>_ = λ f → λ { (inj₁ z) → inj₁ z ; (inj₂ a) → inj₂ (f a) } } eitherApplicative : ∀ {l₁} {A : Set l₁} → RawApplicative (Either {l₁} {l₁} A) eitherApplicative = record { pure = inj₂ ; _⊛_ = λ { (inj₁ a) → λ _ → inj₁ a ; (inj₂ f) → λ { (inj₁ a) → inj₁ a ; (inj₂ b) → inj₂ (f b) } } }
algebraic-stack_agda0000_doc_5878
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.FiniteMultiset.Base where open import Cubical.Foundations.Prelude open import Cubical.HITs.SetTruncation open import Cubical.Foundations.HLevels private variable A : Type₀ infixr 5 _∷_ data FMSet (A : Type₀) : Type₀ where [] : FMSet A _∷_ : (x : A) → (xs : FMSet A) → FMSet A comm : ∀ x y xs → x ∷ y ∷ xs ≡ y ∷ x ∷ xs trunc : isSet (FMSet A) pattern [_] x = x ∷ [] module FMSetElim {ℓ} {B : FMSet A → Type ℓ} ([]* : B []) (_∷*_ : (x : A) {xs : FMSet A} → B xs → B (x ∷ xs)) (comm* : (x y : A) {xs : FMSet A} (b : B xs) → PathP (λ i → B (comm x y xs i)) (x ∷* (y ∷* b)) (y ∷* (x ∷* b))) (trunc* : (xs : FMSet A) → isSet (B xs)) where f : (xs : FMSet A) → B xs f [] = []* f (x ∷ xs) = x ∷* f xs f (comm x y xs i) = comm* x y (f xs) i f (trunc xs zs p q i j) = isOfHLevel→isOfHLevelDep {n = 2} trunc* (f xs) (f zs) (cong f p) (cong f q) (trunc xs zs p q) i j module FMSetElimProp {ℓ} {B : FMSet A → Type ℓ} (BProp : {xs : FMSet A} → isProp (B xs)) ([]* : B []) (_∷*_ : (x : A) {xs : FMSet A} → B xs → B (x ∷ xs)) where f : (xs : FMSet A) → B xs f = FMSetElim.f []* _∷*_ (λ x y {xs} b → toPathP (BProp (transp (λ i → B (comm x y xs i)) i0 (x ∷* (y ∷* b))) (y ∷* (x ∷* b)))) (λ xs → isProp→isSet BProp) module FMSetRec {ℓ} {B : Type ℓ} (BType : isSet B) ([]* : B) (_∷*_ : A → B → B) (comm* : (x y : A) (b : B) → x ∷* (y ∷* b) ≡ y ∷* (x ∷* b)) where f : FMSet A → B f = FMSetElim.f []* (λ x b → x ∷* b) (λ x y b → comm* x y b) (λ _ → BType)
algebraic-stack_agda0000_doc_5879
-- Σ type (also used as existential) and -- cartesian product (also used as conjunction). {-# OPTIONS --without-K --safe #-} module Tools.Product where open import Agda.Primitive open import Agda.Builtin.Sigma public using (Σ; _,_) open import Agda.Builtin.Sigma using (fst; snd) infixr 2 _×_ -- Dependent pair type (aka dependent sum, Σ type). private variable ℓ₁ ℓ₂ ℓ₃ : Level proj₁ : ∀ {A : Set ℓ₁} {B : A → Set ℓ₂} → Σ A B → A proj₁ = fst proj₂ : ∀ {A : Set ℓ₁} {B : A → Set ℓ₂} → (S : Σ A B) → B (fst S) proj₂ = snd -- Existential quantification. ∃ : {A : Set ℓ₁} → (A → Set ℓ₂) → Set (ℓ₁ ⊔ ℓ₂) ∃ = Σ _ ∃₂ : {A : Set ℓ₁} {B : A → Set ℓ₂} (C : (x : A) → B x → Set ℓ₃) → Set (ℓ₁ ⊔ ℓ₂ ⊔ ℓ₃) ∃₂ C = ∃ λ a → ∃ λ b → C a b -- Cartesian product. _×_ : (A : Set ℓ₁) (B : Set ℓ₂) → Set (ℓ₁ ⊔ ℓ₂) A × B = Σ A (λ x → B)
algebraic-stack_agda0000_doc_5880
-- When defining types by recursion it is sometimes difficult to infer implicit -- arguments. This module illustrates the problem and shows how to get around -- it for the example of vectors of a given length. module DataByRecursion where data Nat : Set where zero : Nat suc : Nat -> Nat data Nil : Set where nil' : Nil data Cons (A As : Set) : Set where _::'_ : A -> As -> Cons A As mutual Vec' : Set -> Nat -> Set Vec' A zero = Nil Vec' A (suc n) = Cons A (Vec A n) data Vec (A : Set)(n : Nat) : Set where vec : Vec' A n -> Vec A n nil : {A : Set} -> Vec A zero nil = vec nil' _::_ : {A : Set}{n : Nat} -> A -> Vec A n -> Vec A (suc n) x :: xs = vec (x ::' xs) map : {n : Nat}{A B : Set} -> (A -> B) -> Vec A n -> Vec B n map {zero} f (vec nil') = nil map {suc n} f (vec (x ::' xs)) = f x :: map f xs
algebraic-stack_agda0000_doc_5881
module FSC where -- focused sequent calculus {- open import Relation.Binary.PropositionalEquality open import Data.Nat hiding (_>_) -} open import StdLibStuff open import Syntax data FSC-Ctx (n : ℕ) : Ctx n → Set where ε : FSC-Ctx n ε _∷_ : {Γ : Ctx n} → (t : Type n) → FSC-Ctx n Γ → FSC-Ctx n (t ∷ Γ) _∷h_ : {Γ : Ctx n} → Form Γ $o → FSC-Ctx n Γ → FSC-Ctx n Γ data HVar {n : ℕ} : {Γ-t : Ctx n} → FSC-Ctx n Γ-t → Set where zero : {Γ-t : Ctx n} {h : Form Γ-t $o} {Γ : FSC-Ctx n Γ-t} → HVar (h ∷h Γ) succ : {Γ-t : Ctx n} {h : Form Γ-t $o} {Γ : FSC-Ctx n Γ-t} → HVar Γ → HVar (h ∷h Γ) skip : {Γ-t : Ctx n} {t : Type n} {Γ : FSC-Ctx n Γ-t} → HVar Γ → HVar (t ∷ Γ) lookup-hyp : {n : ℕ} {Γ-t : Ctx n} (Γ : FSC-Ctx n Γ-t) → HVar Γ → Form Γ-t $o lookup-hyp .(h ∷h Γ) (zero {._} {h} {Γ}) = h lookup-hyp .(h ∷h Γ) (succ {._} {h} {Γ} x) = lookup-hyp Γ x lookup-hyp .(t ∷ Γ) (skip {Γ-t} {t} {Γ} x) = weak (lookup-hyp Γ x) mutual data _⊢_ {n : ℕ} {Γ-t : Ctx n} (Γ : FSC-Ctx n Γ-t) : Form Γ-t $o → Set where ||-I-l : {F G : Form Γ-t $o} → Γ ⊢ F → Γ ⊢ (F || G) ||-I-r : {F G : Form Γ-t $o} → Γ ⊢ G → Γ ⊢ (F || G) &-I : {F G : Form Γ-t $o} → Γ ⊢ F → Γ ⊢ G → Γ ⊢ (F & G) ?-I : {t : Type n} {F : Form (t ∷ Γ-t) $o} (G : Form Γ-t t) → Γ ⊢ sub G F → Γ ⊢ (?[ t ] F) ?'-I : {t : Type n} {F : Form Γ-t (t > $o)} (G : Form Γ-t t) → Γ ⊢ (F · G) → Γ ⊢ (?'[ t ] F) =>-I : {F G : Form Γ-t $o} → (F ∷h Γ) ⊢ G → Γ ⊢ (F => G) ~-I : {F : Form Γ-t $o} → (F ∷h Γ) ⊢ $false → Γ ⊢ (~ F) !-I : {t : Type n} {F : Form (t ∷ Γ-t) $o} → (t ∷ Γ) ⊢ F → Γ ⊢ (![ t ] F) !'-I : {t : Type n} {F : Form Γ-t (t > $o)} → (t ∷ Γ) ⊢ (weak F · ($ this {refl})) → Γ ⊢ (!'[ t ] F) $true-I : Γ ⊢ $true ==-I : {t : Type n} {F G : Form Γ-t t} → Γ ⊢ t ∋ F == G → Γ ⊢ (F == G) -- compute eq elim : {F : Form Γ-t $o} → (x : HVar Γ) → Γ , lookup-hyp Γ x ⊢ F → Γ ⊢ F ac : {t : Type n} {F : Form Γ-t $o} → Γ , (![ t > $o ] ((?[ t ] ($ (next this) {refl} · $ this {refl})) => ($ this {refl} · (ι t ($ (next this) {refl} · $ this {refl}))))) ⊢ F → Γ ⊢ F ac' : {t : Type n} {F : Form Γ-t $o} → Γ , (![ t > $o ] ((?'[ t ] ($ this {refl})) => ($ this {refl} · (ι' t ($ this {refl}))))) ⊢ F → Γ ⊢ F raa : {F : Form Γ-t $o} → Γ ⊢ (~ (~ F)) → Γ ⊢ F reduce : {t u : Type n} {F : Form Γ-t u → Form Γ-t $o} {G : Form (t ∷ Γ-t) u} {H : Form Γ-t t} → Γ ⊢ (F (sub H G)) → Γ ⊢ (F ((^[ t ] G) · H)) data _,_⊢_ {n : ℕ} {Γ-t : Ctx n} (Γ : FSC-Ctx n Γ-t) : Form Γ-t $o → Form Γ-t $o → Set where use : {F G : Form Γ-t $o} → Γ ⊢ $o ∋ G ↔ F → Γ , F ⊢ G $false-E : {H : Form Γ-t $o} → Γ , $false ⊢ H ~-E : {F H : Form Γ-t $o} → Γ ⊢ F → Γ , ~ F ⊢ H ||-E : {F G H : Form Γ-t $o} → Γ ⊢ (F => H) → Γ ⊢ (G => H) → Γ , F || G ⊢ H &-E-l : {F G H : Form Γ-t $o} → Γ , F ⊢ H → Γ , F & G ⊢ H &-E-r : {F G H : Form Γ-t $o} → Γ , G ⊢ H → Γ , F & G ⊢ H ?-E : {t : Type n} {F : Form (t ∷ Γ-t) $o} {H : Form Γ-t $o} → Γ , sub (ι t F) F ⊢ H → Γ , ?[ t ] F ⊢ H ?'-E : {t : Type n} {F : Form Γ-t (t > $o)} {H : Form Γ-t $o} → Γ , (F · ι' t F) ⊢ H → Γ , ?'[ t ] F ⊢ H =>-E : {F G H : Form Γ-t $o} → Γ ⊢ F → Γ , G ⊢ H → Γ , F => G ⊢ H !-E : {t : Type n} {F : Form (t ∷ Γ-t) $o} {H : Form Γ-t $o} (G : Form Γ-t t) → Γ , sub G F ⊢ H → Γ , ![ t ] F ⊢ H !'-E : {t : Type n} {F : Form Γ-t (t > $o)} {H : Form Γ-t $o} (G : Form Γ-t t) → Γ , (F · G) ⊢ H → Γ , !'[ t ] F ⊢ H r-bool-ext : {F G H : Form Γ-t $o} → Γ , ((F => G) & (G => F)) ⊢ H → Γ , F == G ⊢ H -- compute eq r-fun-ext : {t u : Type n} {F G : Form Γ-t (t > u)} {H : Form Γ-t $o} (I : Form Γ-t t) → Γ , (F · I) == (G · I) ⊢ H → Γ , F == G ⊢ H -- compute eq reduce : {t u : Type n} {F : Form Γ-t u → Form Γ-t $o} {G : Form (t ∷ Γ-t) u} {H : Form Γ-t t} {I : Form Γ-t $o} → Γ , (F (sub H G)) ⊢ I → Γ , (F ((^[ t ] G) · H)) ⊢ I data _⊢_∋_==_ {n : ℕ} {Γ-t : Ctx n} (Γ : FSC-Ctx n Γ-t) : (t : Type n) (F G : Form Γ-t t) → Set where simp : {t : Type n} {F G : Form Γ-t t} → Γ ⊢ t ∋ F ↔ G → Γ ⊢ t ∋ F == G step : {t : Type n} {F G : Form Γ-t t} (F' G' : Form Γ-t t) → (x : HVar Γ) → Γ , lookup-hyp Γ x ⊢ F' == G' → Γ ⊢ t ∋ F ↔ F' → Γ ⊢ t ∋ G' == G → Γ ⊢ t ∋ F == G bool-ext : {F G : Form Γ-t $o} → Γ ⊢ ((F => G) & (G => F)) → Γ ⊢ $o ∋ F == G fun-ext : {t u : Type n} {F G : Form Γ-t (t > u)} → (t ∷ Γ) ⊢ u ∋ ((weak F) · $ this {refl}) == ((weak G) · $ this {refl}) → Γ ⊢ (t > u) ∋ F == G data _⊢_∋_↔_ {n : ℕ} {Γ-t : Ctx n} (Γ : FSC-Ctx n Γ-t) : (t : Type n) → Form Γ-t t → Form Γ-t t → Set where head-var : (t : Type n) (x : Var Γ-t) (p : lookup-Var Γ-t x ≡ t) → Γ ⊢ t ∋ $ x {p} ↔ $ x {p} head-const : (t : Type n) (c : Form Γ-t t) → Γ ⊢ t ∋ c ↔ c head-app : (t₁ t₂ : Type n) (F₁ F₂ : Form Γ-t (t₁ > t₂)) (G₁ G₂ : Form Γ-t t₁) → Γ ⊢ (t₁ > t₂) ∋ F₁ == F₂ → Γ ⊢ t₁ ∋ G₁ == G₂ → Γ ⊢ t₂ ∋ (F₁ · G₁) ↔ (F₂ · G₂) head-lam : (t₁ t₂ : Type n) (F₁ F₂ : Form (t₁ ∷ Γ-t) t₂) → (t₁ ∷ Γ) ⊢ t₂ ∋ F₁ == F₂ → Γ ⊢ (t₁ > t₂) ∋ (lam t₁ F₁) ↔ (lam t₁ F₂) head-lam-eta-left : (t₁ t₂ : Type n) (F₁ : Form Γ-t (t₁ > t₂)) (F₂ : Form (t₁ ∷ Γ-t) t₂) → (t₁ ∷ Γ) ⊢ t₂ ∋ (weak F₁ · $ this {refl}) == F₂ → Γ ⊢ (t₁ > t₂) ∋ F₁ ↔ lam t₁ F₂ head-lam-eta-right : (t₁ t₂ : Type n) (F₁ : Form Γ-t (t₁ > t₂)) (F₂ : Form (t₁ ∷ Γ-t) t₂) → (t₁ ∷ Γ) ⊢ t₂ ∋ F₂ == (weak F₁ · $ this {refl}) → Γ ⊢ (t₁ > t₂) ∋ lam t₁ F₂ ↔ F₁ reduce-l : {t u v : Type n} {F₁ : Form Γ-t v → Form Γ-t t} {G : Form (u ∷ Γ-t) v} {H : Form Γ-t u} {F₂ : Form Γ-t t} → Γ ⊢ t ∋ (F₁ (sub H G)) ↔ F₂ → Γ ⊢ t ∋ (F₁ ((^[ u ] G) · H)) ↔ F₂ reduce-r : {t u v : Type n} {F₂ : Form Γ-t v → Form Γ-t t} {G : Form (u ∷ Γ-t) v} {H : Form Γ-t u} {F₁ : Form Γ-t t} → Γ ⊢ t ∋ F₁ ↔ (F₂ (sub H G)) → Γ ⊢ t ∋ F₁ ↔ (F₂ ((^[ u ] G) · H)) data _,_⊢_==_ {n : ℕ} {Γ-t : Ctx n} {t : Type n} (Γ : FSC-Ctx n Γ-t) : Form Γ-t $o → Form Γ-t t → Form Γ-t t → Set where use : {F G : Form Γ-t t} → Γ , F == G ⊢ F == G use' : {F G : Form Γ-t t} {H : Form Γ-t $o} → headNorm 2 (F == G) ≡ headNorm 2 H → Γ , H ⊢ F == G use-sym : {F G : Form Γ-t t} → Γ , F == G ⊢ G == F -- compute eq &-E-l : {F G : Form Γ-t $o} {H₁ H₂ : Form Γ-t t} → Γ , F ⊢ H₁ == H₂ → Γ , F & G ⊢ H₁ == H₂ &-E-r : {F G : Form Γ-t $o} {H₁ H₂ : Form Γ-t t} → Γ , G ⊢ H₁ == H₂ → Γ , F & G ⊢ H₁ == H₂ ?-E : {u : Type n} {F : Form (u ∷ Γ-t) $o} {H₁ H₂ : Form Γ-t t} → Γ , sub (ι u F) F ⊢ H₁ == H₂ → Γ , ?[ u ] F ⊢ H₁ == H₂ ?'-E : {u : Type n} {F : Form Γ-t (u > $o)} {H₁ H₂ : Form Γ-t t} → Γ , (F · ι' u F) ⊢ H₁ == H₂ → Γ , ?'[ u ] F ⊢ H₁ == H₂ =>-E : {F G : Form Γ-t $o} {H₁ H₂ : Form Γ-t t} → Γ ⊢ F → Γ , G ⊢ H₁ == H₂ → Γ , F => G ⊢ H₁ == H₂ !-E : {u : Type n} {F : Form (u ∷ Γ-t) $o} {H₁ H₂ : Form Γ-t t} (G : Form Γ-t u) → Γ , sub G F ⊢ H₁ == H₂ → Γ , ![ u ] F ⊢ H₁ == H₂ !'-E : {u : Type n} {F : Form Γ-t (u > $o)} {H₁ H₂ : Form Γ-t t} (G : Form Γ-t u) → Γ , (F · G) ⊢ H₁ == H₂ → Γ , !'[ u ] F ⊢ H₁ == H₂ r-bool-ext : {F G : Form Γ-t $o} {H I : Form Γ-t t} → Γ , ((F => G) & (G => F)) ⊢ H == I → Γ , F == G ⊢ H == I -- compute eq r-fun-ext : {u v : Type n} {F G : Form Γ-t (u > v)} {H I : Form Γ-t t} (J : Form Γ-t u) → Γ , (F · J) == (G · J) ⊢ H == I → Γ , F == G ⊢ H == I -- compute eq reduce : {u v : Type n} {F : Form Γ-t v → Form Γ-t $o} {G : Form (u ∷ Γ-t) v} {H : Form Γ-t u} {I₁ I₂ : Form Γ-t t} → Γ , (F (sub H G)) ⊢ I₁ == I₂ → Γ , (F ((^[ u ] G) · H)) ⊢ I₁ == I₂
algebraic-stack_agda0000_doc_5882
-- Andreas, 2016-09-20, issue #2197 reported by m0davis {-# OPTIONS --allow-unsolved-metas #-} -- {-# OPTIONS -v tc.pos:20 -v tc.meta.eta:20 #-} record R : Set where inductive field foo : R bar : R bar = {!!} -- This used to loop due to infinite eta-expansion. -- Should check now.
algebraic-stack_agda0000_doc_5883
module Common.Issue481ParametrizedModule (A : Set1) where id : A → A id x = x postulate Bla : Set
algebraic-stack_agda0000_doc_5884
test = forall _⦇_ → Set
algebraic-stack_agda0000_doc_5885
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics module lib.types.Sigma where -- pointed [Σ] ⊙Σ : ∀ {i j} (X : Ptd i) → (de⊙ X → Ptd j) → Ptd (lmax i j) ⊙Σ ⊙[ A , a₀ ] Y = ⊙[ Σ A (de⊙ ∘ Y) , (a₀ , pt (Y a₀)) ] -- Cartesian product _×_ : ∀ {i j} (A : Type i) (B : Type j) → Type (lmax i j) A × B = Σ A (λ _ → B) _⊙×_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j) X ⊙× Y = ⊙Σ X (λ _ → Y) infixr 80 _×_ _⊙×_ -- XXX Do we really need two versions of [⊙fst]? ⊙fstᵈ : ∀ {i j} {X : Ptd i} (Y : de⊙ X → Ptd j) → ⊙Σ X Y ⊙→ X ⊙fstᵈ Y = fst , idp ⊙fst : ∀ {i j} {X : Ptd i} {Y : Ptd j} → X ⊙× Y ⊙→ X ⊙fst = ⊙fstᵈ _ ⊙snd : ∀ {i j} {X : Ptd i} {Y : Ptd j} → X ⊙× Y ⊙→ Y ⊙snd = (snd , idp) fanout : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} → (A → B) → (A → C) → (A → B × C) fanout f g x = f x , g x ⊙fanout-pt : ∀ {i j} {A : Type i} {B : Type j} {a₀ a₁ : A} (p : a₀ == a₁) {b₀ b₁ : B} (q : b₀ == b₁) → (a₀ , b₀) == (a₁ , b₁) :> A × B ⊙fanout-pt = pair×= ⊙fanout : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} → X ⊙→ Y → X ⊙→ Z → X ⊙→ Y ⊙× Z ⊙fanout (f , fpt) (g , gpt) = fanout f g , ⊙fanout-pt fpt gpt diag : ∀ {i} {A : Type i} → (A → A × A) diag a = a , a ⊙diag : ∀ {i} {X : Ptd i} → X ⊙→ X ⊙× X ⊙diag = ((λ x → (x , x)) , idp) ⊙×-inl : ∀ {i j} (X : Ptd i) (Y : Ptd j) → X ⊙→ X ⊙× Y ⊙×-inl X Y = (λ x → x , pt Y) , idp ⊙×-inr : ∀ {i j} (X : Ptd i) (Y : Ptd j) → Y ⊙→ X ⊙× Y ⊙×-inr X Y = (λ y → pt X , y) , idp ⊙fst-fanout : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} (f : X ⊙→ Y) (g : X ⊙→ Z) → ⊙fst ⊙∘ ⊙fanout f g == f ⊙fst-fanout (f , idp) (g , idp) = idp ⊙snd-fanout : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} (f : X ⊙→ Y) (g : X ⊙→ Z) → ⊙snd ⊙∘ ⊙fanout f g == g ⊙snd-fanout (f , idp) (g , idp) = idp ⊙fanout-pre∘ : ∀ {i j k l} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {W : Ptd l} (f : Y ⊙→ Z) (g : Y ⊙→ W) (h : X ⊙→ Y) → ⊙fanout f g ⊙∘ h == ⊙fanout (f ⊙∘ h) (g ⊙∘ h) ⊙fanout-pre∘ (f , idp) (g , idp) (h , idp) = idp module _ {i j} {A : Type i} {B : A → Type j} where pair : (a : A) (b : B a) → Σ A B pair a b = (a , b) -- pair= has already been defined fst= : {ab a'b' : Σ A B} (p : ab == a'b') → (fst ab == fst a'b') fst= = ap fst snd= : {ab a'b' : Σ A B} (p : ab == a'b') → (snd ab == snd a'b' [ B ↓ fst= p ]) snd= {._} {_} idp = idp fst=-β : {a a' : A} (p : a == a') {b : B a} {b' : B a'} (q : b == b' [ B ↓ p ]) → fst= (pair= p q) == p fst=-β idp idp = idp snd=-β : {a a' : A} (p : a == a') {b : B a} {b' : B a'} (q : b == b' [ B ↓ p ]) → snd= (pair= p q) == q [ (λ v → b == b' [ B ↓ v ]) ↓ fst=-β p q ] snd=-β idp idp = idp pair=-η : {ab a'b' : Σ A B} (p : ab == a'b') → p == pair= (fst= p) (snd= p) pair=-η {._} {_} idp = idp pair== : {a a' : A} {p p' : a == a'} (α : p == p') {b : B a} {b' : B a'} {q : b == b' [ B ↓ p ]} {q' : b == b' [ B ↓ p' ]} (β : q == q' [ (λ u → b == b' [ B ↓ u ]) ↓ α ]) → pair= p q == pair= p' q' pair== idp idp = idp module _ {i j} {A : Type i} {B : Type j} where fst×= : {ab a'b' : A × B} (p : ab == a'b') → (fst ab == fst a'b') fst×= = ap fst snd×= : {ab a'b' : A × B} (p : ab == a'b') → (snd ab == snd a'b') snd×= = ap snd fst×=-β : {a a' : A} (p : a == a') {b b' : B} (q : b == b') → fst×= (pair×= p q) == p fst×=-β idp idp = idp snd×=-β : {a a' : A} (p : a == a') {b b' : B} (q : b == b') → snd×= (pair×= p q) == q snd×=-β idp idp = idp pair×=-η : {ab a'b' : A × B} (p : ab == a'b') → p == pair×= (fst×= p) (snd×= p) pair×=-η {._} {_} idp = idp module _ {i j} {A : Type i} {B : A → Type j} where =Σ : (x y : Σ A B) → Type (lmax i j) =Σ (a , b) (a' , b') = Σ (a == a') (λ p → b == b' [ B ↓ p ]) =Σ-econv : (x y : Σ A B) → (=Σ x y) ≃ (x == y) =Σ-econv x y = equiv (λ pq → pair= (fst pq) (snd pq)) (λ p → fst= p , snd= p) (λ p → ! (pair=-η p)) (λ pq → pair= (fst=-β (fst pq) (snd pq)) (snd=-β (fst pq) (snd pq))) =Σ-conv : (x y : Σ A B) → (=Σ x y) == (x == y) =Σ-conv x y = ua (=Σ-econv x y) Σ= : ∀ {i j} {A A' : Type i} (p : A == A') {B : A → Type j} {B' : A' → Type j} (q : B == B' [ (λ X → (X → Type j)) ↓ p ]) → Σ A B == Σ A' B' Σ= idp idp = idp instance Σ-level : ∀ {i j} {n : ℕ₋₂} {A : Type i} {P : A → Type j} → has-level n A → ((x : A) → has-level n (P x)) → has-level n (Σ A P) Σ-level {n = ⟨-2⟩} p q = has-level-in ((contr-center p , (contr-center (q (contr-center p)))) , lemma) where abstract lemma = λ y → pair= (contr-path p _) (from-transp! _ _ (contr-path (q _) _)) Σ-level {n = S n} p q = has-level-in lemma where abstract lemma = λ x y → equiv-preserves-level (=Σ-econv x y) {{Σ-level (has-level-apply p _ _) (λ _ → equiv-preserves-level ((to-transp-equiv _ _)⁻¹) {{has-level-apply (q _) _ _}})}} ×-level : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} → (has-level n A → has-level n B → has-level n (A × B)) ×-level pA pB = Σ-level pA (λ x → pB) -- Equivalences in a Σ-type Σ-fmap-l : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k) → (f : A → B) → (Σ A (P ∘ f) → Σ B P) Σ-fmap-l P f (a , r) = (f a , r) ×-fmap-l : ∀ {i₀ i₁ j} {A₀ : Type i₀} {A₁ : Type i₁} (B : Type j) → (f : A₀ → A₁) → (A₀ × B → A₁ × B) ×-fmap-l B = Σ-fmap-l (λ _ → B) Σ-isemap-l : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k) {h : A → B} → is-equiv h → is-equiv (Σ-fmap-l P h) Σ-isemap-l {A = A} {B = B} P {h} e = is-eq _ g f-g g-f where f = Σ-fmap-l P h g : Σ B P → Σ A (P ∘ h) g (b , s) = (is-equiv.g e b , transport P (! (is-equiv.f-g e b)) s) f-g : ∀ y → f (g y) == y f-g (b , s) = pair= (is-equiv.f-g e b) (transp-↓ P (is-equiv.f-g e b) s) g-f : ∀ x → g (f x) == x g-f (a , r) = pair= (is-equiv.g-f e a) (transport (λ q → transport P (! q) r == r [ P ∘ h ↓ is-equiv.g-f e a ]) (is-equiv.adj e a) (transp-ap-↓ P h (is-equiv.g-f e a) r)) ×-isemap-l : ∀ {i₀ i₁ j} {A₀ : Type i₀} {A₁ : Type i₁} (B : Type j) {h : A₀ → A₁} → is-equiv h → is-equiv (×-fmap-l B h) ×-isemap-l B = Σ-isemap-l (λ _ → B) Σ-emap-l : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k) → (e : A ≃ B) → (Σ A (P ∘ –> e) ≃ Σ B P) Σ-emap-l P (f , e) = _ , Σ-isemap-l P e ×-emap-l : ∀ {i₀ i₁ j} {A₀ : Type i₀} {A₁ : Type i₁} (B : Type j) → (e : A₀ ≃ A₁) → (A₀ × B ≃ A₁ × B) ×-emap-l B = Σ-emap-l (λ _ → B) Σ-fmap-r : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} → (∀ x → B x → C x) → (Σ A B → Σ A C) Σ-fmap-r h (a , b) = (a , h a b) ×-fmap-r : ∀ {i j₀ j₁} (A : Type i) {B₀ : Type j₀} {B₁ : Type j₁} → (h : B₀ → B₁) → (A × B₀ → A × B₁) ×-fmap-r A h = Σ-fmap-r (λ _ → h) Σ-isemap-r : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {h : ∀ x → B x → C x} → (∀ x → is-equiv (h x)) → is-equiv (Σ-fmap-r h) Σ-isemap-r {A = A} {B = B} {C = C} {h} k = is-eq _ g f-g g-f where f = Σ-fmap-r h g : Σ A C → Σ A B g (a , c) = (a , is-equiv.g (k a) c) f-g : ∀ p → f (g p) == p f-g (a , c) = pair= idp (is-equiv.f-g (k a) c) g-f : ∀ p → g (f p) == p g-f (a , b) = pair= idp (is-equiv.g-f (k a) b) ×-isemap-r : ∀ {i j₀ j₁} (A : Type i) {B₀ : Type j₀} {B₁ : Type j₁} → {h : B₀ → B₁} → is-equiv h → is-equiv (×-fmap-r A h) ×-isemap-r A e = Σ-isemap-r (λ _ → e) Σ-emap-r : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} → (∀ x → B x ≃ C x) → (Σ A B ≃ Σ A C) Σ-emap-r k = _ , Σ-isemap-r (λ x → snd (k x)) ×-emap-r : ∀ {i j₀ j₁} (A : Type i) {B₀ : Type j₀} {B₁ : Type j₁} → (e : B₀ ≃ B₁) → (A × B₀ ≃ A × B₁) ×-emap-r A e = Σ-emap-r (λ _ → e) hfiber-Σ-fmap-r : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} → (h : ∀ x → B x → C x) → {a : A} → (c : C a) → hfiber (Σ-fmap-r h) (a , c) ≃ hfiber (h a) c hfiber-Σ-fmap-r h {a} c = equiv to from to-from from-to where to : hfiber (Σ-fmap-r h) (a , c) → hfiber (h a) c to ((_ , b) , idp) = b , idp from : hfiber (h a) c → hfiber (Σ-fmap-r h) (a , c) from (b , idp) = (a , b) , idp abstract to-from : (x : hfiber (h a) c) → to (from x) == x to-from (b , idp) = idp from-to : (x : hfiber (Σ-fmap-r h) (a , c)) → from (to x) == x from-to ((_ , b) , idp) = idp {- -- 2016/08/20 favonia: no one is using the following two functions. -- Two ways of simultaneously applying equivalences in each component. module _ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : A₀ → Type j₀} {B₁ : A₁ → Type j₁} where Σ-emap : (u : A₀ ≃ A₁) (v : ∀ a → B₀ (<– u a) ≃ B₁ a) → Σ A₀ B₀ ≃ Σ A₁ B₁ Σ-emap u v = Σ A₀ B₀ ≃⟨ Σ-emap-l _ (u ⁻¹) ⁻¹ ⟩ Σ A₁ (B₀ ∘ <– u) ≃⟨ Σ-emap-r v ⟩ Σ A₁ B₁ ≃∎ Σ-emap' : (u : A₀ ≃ A₁) (v : ∀ a → B₀ a ≃ B₁ (–> u a)) → Σ A₀ B₀ ≃ Σ A₁ B₁ Σ-emap' u v = Σ A₀ B₀ ≃⟨ Σ-emap-r v ⟩ Σ A₀ (B₁ ∘ –> u) ≃⟨ Σ-emap-l _ u ⟩ Σ A₁ B₁ ≃∎ -} ×-fmap : ∀ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁} → (h : A₀ → A₁) (k : B₀ → B₁) → (A₀ × B₀ → A₁ × B₁) ×-fmap u v = ×-fmap-r _ v ∘ ×-fmap-l _ u ⊙×-fmap : ∀ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'} → X ⊙→ X' → Y ⊙→ Y' → X ⊙× Y ⊙→ X' ⊙× Y' ⊙×-fmap (f , fpt) (g , gpt) = ×-fmap f g , pair×= fpt gpt ×-isemap : ∀ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁} {h : A₀ → A₁} {k : B₀ → B₁} → is-equiv h → is-equiv k → is-equiv (×-fmap h k) ×-isemap eh ek = ×-isemap-r _ ek ∘ise ×-isemap-l _ eh ×-emap : ∀ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁} {B₀ : Type j₀} {B₁ : Type j₁} → (u : A₀ ≃ A₁) (v : B₀ ≃ B₁) → (A₀ × B₀ ≃ A₁ × B₁) ×-emap u v = ×-emap-r _ v ∘e ×-emap-l _ u ⊙×-emap : ∀ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'} → X ⊙≃ X' → Y ⊙≃ Y' → X ⊙× Y ⊙≃ X' ⊙× Y' ⊙×-emap (F , F-ise) (G , G-ise) = ⊙×-fmap F G , ×-isemap F-ise G-ise -- Implementation of [_∙'_] on Σ Σ-∙' : ∀ {i j} {A : Type i} {B : A → Type j} {x y z : A} {p : x == y} {p' : y == z} {u : B x} {v : B y} {w : B z} (q : u == v [ B ↓ p ]) (r : v == w [ B ↓ p' ]) → (pair= p q ∙' pair= p' r) == pair= (p ∙' p') (q ∙'ᵈ r) Σ-∙' {p = idp} {p' = idp} q idp = idp -- Implementation of [_∙_] on Σ Σ-∙ : ∀ {i j} {A : Type i} {B : A → Type j} {x y z : A} {p : x == y} {p' : y == z} {u : B x} {v : B y} {w : B z} (q : u == v [ B ↓ p ]) (r : v == w [ B ↓ p' ]) → (pair= p q ∙ pair= p' r) == pair= (p ∙ p') (q ∙ᵈ r) Σ-∙ {p = idp} {p' = idp} idp r = idp -- Implementation of [!] on Σ Σ-! : ∀ {i j} {A : Type i} {B : A → Type j} {x y : A} {p : x == y} {u : B x} {v : B y} (q : u == v [ B ↓ p ]) → ! (pair= p q) == pair= (! p) (!ᵈ q) Σ-! {p = idp} idp = idp -- Implementation of [_∙'_] on × ×-∙' : ∀ {i j} {A : Type i} {B : Type j} {x y z : A} (p : x == y) (p' : y == z) {u v w : B} (q : u == v) (q' : v == w) → (pair×= p q ∙' pair×= p' q') == pair×= (p ∙' p') (q ∙' q') ×-∙' idp idp q idp = idp -- Implementation of [_∙_] on × ×-∙ : ∀ {i j} {A : Type i} {B : Type j} {x y z : A} (p : x == y) (p' : y == z) {u v w : B} (q : u == v) (q' : v == w) → (pair×= p q ∙ pair×= p' q') == pair×= (p ∙ p') (q ∙ q') ×-∙ idp idp idp r = idp -- Implementation of [!] on × ×-! : ∀ {i j} {A : Type i} {B : Type j} {x y : A} (p : x == y) {u v : B} (q : u == v) → ! (pair×= p q) == pair×= (! p) (! q) ×-! idp idp = idp -- Special case of [ap-,] ap-cst,id : ∀ {i j} {A : Type i} (B : A → Type j) {a : A} {x y : B a} (p : x == y) → ap (λ x → _,_ {B = B} a x) p == pair= idp p ap-cst,id B idp = idp -- hfiber fst == B module _ {i j} {A : Type i} {B : A → Type j} where private to : ∀ a → hfiber (fst :> (Σ A B → A)) a → B a to a ((.a , b) , idp) = b from : ∀ (a : A) → B a → hfiber (fst :> (Σ A B → A)) a from a b = (a , b) , idp to-from : ∀ (a : A) (b : B a) → to a (from a b) == b to-from a b = idp from-to : ∀ a b′ → from a (to a b′) == b′ from-to a ((.a , b) , idp) = idp hfiber-fst : ∀ a → hfiber (fst :> (Σ A B → A)) a ≃ B a hfiber-fst a = to a , is-eq (to a) (from a) (to-from a) (from-to a) {- Dependent paths in a Σ-type -} module _ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k} where ↓-Σ-in : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : C x r} {s' : C x' r'} (q : r == r' [ B ↓ p ]) → s == s' [ uncurry C ↓ pair= p q ] → (r , s) == (r' , s') [ (λ x → Σ (B x) (C x)) ↓ p ] ↓-Σ-in {p = idp} idp t = pair= idp t ↓-Σ-fst : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : C x r} {s' : C x' r'} → (r , s) == (r' , s') [ (λ x → Σ (B x) (C x)) ↓ p ] → r == r' [ B ↓ p ] ↓-Σ-fst {p = idp} u = fst= u ↓-Σ-snd : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : C x r} {s' : C x' r'} → (u : (r , s) == (r' , s') [ (λ x → Σ (B x) (C x)) ↓ p ]) → s == s' [ uncurry C ↓ pair= p (↓-Σ-fst u) ] ↓-Σ-snd {p = idp} idp = idp ↓-Σ-β-fst : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : C x r} {s' : C x' r'} (q : r == r' [ B ↓ p ]) (t : s == s' [ uncurry C ↓ pair= p q ]) → ↓-Σ-fst (↓-Σ-in q t) == q ↓-Σ-β-fst {p = idp} idp idp = idp ↓-Σ-β-snd : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : C x r} {s' : C x' r'} (q : r == r' [ B ↓ p ]) (t : s == s' [ uncurry C ↓ pair= p q ]) → ↓-Σ-snd (↓-Σ-in q t) == t [ (λ q' → s == s' [ uncurry C ↓ pair= p q' ]) ↓ ↓-Σ-β-fst q t ] ↓-Σ-β-snd {p = idp} idp idp = idp ↓-Σ-η : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : C x r} {s' : C x' r'} (u : (r , s) == (r' , s') [ (λ x → Σ (B x) (C x)) ↓ p ]) → ↓-Σ-in (↓-Σ-fst u) (↓-Σ-snd u) == u ↓-Σ-η {p = idp} idp = idp {- Dependent paths in a ×-type -} module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} where ↓-×-in : {x x' : A} {p : x == x'} {r : B x} {r' : B x'} {s : C x} {s' : C x'} → r == r' [ B ↓ p ] → s == s' [ C ↓ p ] → (r , s) == (r' , s') [ (λ x → B x × C x) ↓ p ] ↓-×-in {p = idp} q t = pair×= q t {- Dependent paths over a ×-type -} module _ {i j k} {A : Type i} {B : Type j} (C : A → B → Type k) where ↓-over-×-in : {x x' : A} {p : x == x'} {y y' : B} {q : y == y'} {u : C x y} {v : C x' y} {w : C x' y'} → u == v [ (λ a → C a y) ↓ p ] → v == w [ (λ b → C x' b) ↓ q ] → u == w [ uncurry C ↓ pair×= p q ] ↓-over-×-in {p = idp} {q = idp} idp idp = idp ↓-over-×-in' : {x x' : A} {p : x == x'} {y y' : B} {q : y == y'} {u : C x y} {v : C x y'} {w : C x' y'} → u == v [ (λ b → C x b) ↓ q ] → v == w [ (λ a → C a y') ↓ p ] → u == w [ uncurry C ↓ pair×= p q ] ↓-over-×-in' {p = idp} {q = idp} idp idp = idp module _ where -- An orphan lemma. ↓-cst×app-in : ∀ {i j k} {A : Type i} {B : Type j} {C : A → B → Type k} {a₁ a₂ : A} (p : a₁ == a₂) {b₁ b₂ : B} (q : b₁ == b₂) {c₁ : C a₁ b₁}{c₂ : C a₂ b₂} → c₁ == c₂ [ uncurry C ↓ pair×= p q ] → (b₁ , c₁) == (b₂ , c₂) [ (λ x → Σ B (C x)) ↓ p ] ↓-cst×app-in idp idp idp = idp {- pair= and pair×= where one argument is reflexivity -} pair=-idp-l : ∀ {i j} {A : Type i} {B : A → Type j} (a : A) {b₁ b₂ : B a} (q : b₁ == b₂) → pair= {B = B} idp q == ap (λ y → (a , y)) q pair=-idp-l _ idp = idp pair×=-idp-l : ∀ {i j} {A : Type i} {B : Type j} (a : A) {b₁ b₂ : B} (q : b₁ == b₂) → pair×= idp q == ap (λ y → (a , y)) q pair×=-idp-l _ idp = idp pair×=-idp-r : ∀ {i j} {A : Type i} {B : Type j} {a₁ a₂ : A} (p : a₁ == a₂) (b : B) → pair×= p idp == ap (λ x → (x , b)) p pair×=-idp-r idp _ = idp pair×=-split-l : ∀ {i j} {A : Type i} {B : Type j} {a₁ a₂ : A} (p : a₁ == a₂) {b₁ b₂ : B} (q : b₁ == b₂) → pair×= p q == ap (λ a → (a , b₁)) p ∙ ap (λ b → (a₂ , b)) q pair×=-split-l idp idp = idp pair×=-split-r : ∀ {i j} {A : Type i} {B : Type j} {a₁ a₂ : A} (p : a₁ == a₂) {b₁ b₂ : B} (q : b₁ == b₂) → pair×= p q == ap (λ b → (a₁ , b)) q ∙ ap (λ a → (a , b₂)) p pair×=-split-r idp idp = idp -- Commutativity of products and derivatives. module _ {i j} {A : Type i} {B : Type j} where ×-comm : Σ A (λ _ → B) ≃ Σ B (λ _ → A) ×-comm = equiv (λ {(a , b) → (b , a)}) (λ {(b , a) → (a , b)}) (λ _ → idp) (λ _ → idp) module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} where Σ₂-×-comm : Σ (Σ A B) (λ ab → C (fst ab)) ≃ Σ (Σ A C) (λ ac → B (fst ac)) Σ₂-×-comm = Σ-assoc ⁻¹ ∘e Σ-emap-r (λ a → ×-comm) ∘e Σ-assoc module _ {i j k} {A : Type i} {B : Type j} {C : A → B → Type k} where Σ₁-×-comm : Σ A (λ a → Σ B (λ b → C a b)) ≃ Σ B (λ b → Σ A (λ a → C a b)) Σ₁-×-comm = Σ-assoc ∘e Σ-emap-l _ ×-comm ∘e Σ-assoc ⁻¹
algebraic-stack_agda0000_doc_5886
{-# OPTIONS --prop --without-K --rewriting #-} -- The basic CBPV metalanguage, extended with parallelism. open import Calf.CostMonoid module Calf.ParMetalanguage (parCostMonoid : ParCostMonoid) where open ParCostMonoid parCostMonoid open import Calf.Prelude open import Calf.Metalanguage open import Calf.Step costMonoid open import Calf.Types.Eq open import Calf.Types.Bounded costMonoid open import Data.Product open import Relation.Binary.PropositionalEquality postulate _&_ : {A₁ A₂ : tp pos} → cmp (F A₁) → cmp (F A₂) → cmp (F (Σ++ A₁ (λ _ → A₂))) &/join : ∀ {A₁ A₂} {v₁ v₂ p₁ p₂} → step (F A₁) p₁ (ret v₁) & step (F A₂) p₂ (ret v₂) ≡ step (F (Σ++ A₁ λ _ → A₂)) (p₁ ⊗ p₂) (ret (v₁ , v₂)) {-# REWRITE &/join #-} &/join/𝟘 : ∀ {A₁ A₂} {v₁ v₂} → ret v₁ & ret v₂ ≡ step (F (Σ++ A₁ λ _ → A₂)) (𝟘 ⊗ 𝟘) (ret (v₁ , v₂)) &/join/𝟘 = &/join {p₁ = 𝟘} {p₂ = 𝟘} {-# REWRITE &/join/𝟘 #-} bind/& : ∀ {A₁ A₂} {X} {v₁ v₂ f} (p₁ p₂ : ℂ) → bind {Σ++ A₁ λ _ → A₂} X (step (F A₁) p₁ (ret v₁) & step (F A₂) p₂ (ret v₂)) f ≡ step X (p₁ ⊗ p₂) (f (v₁ , v₂)) bind/& _ _ = refl bound/par : {A₁ A₂ : tp pos} {e₁ : cmp (F A₁)} {e₂ : cmp (F A₂)} {c₁ c₂ : ℂ} → IsBounded A₁ e₁ c₁ → IsBounded A₂ e₂ c₂ → IsBounded (Σ++ A₁ λ _ → A₂) (e₁ & e₂) (c₁ ⊗ c₂) bound/par (⇓ a₁ withCost p₁' [ h-bounded₁ , h-≡₁ ]) (⇓ a₂ withCost p₂' [ h-bounded₂ , h-≡₂ ]) with eq/ref h-≡₁ | eq/ref h-≡₂ ... | refl | refl = ⇓ (a₁ , a₂) withCost (p₁' ⊗ p₂') [ (λ u → ⊗-mono-≤ (h-bounded₁ u) (h-bounded₂ u)) , (ret (eq/intro refl)) ]
algebraic-stack_agda0000_doc_5887
{-# OPTIONS --warning=error --safe --without-K #-} open import LogicalFormulae open import Lists.Lists open import Numbers.BinaryNaturals.Definition open import Maybe open import Numbers.BinaryNaturals.SubtractionGo module Numbers.BinaryNaturals.SubtractionGoPreservesCanonicalRight where goPreservesCanonicalRightZero : (a b : BinNat) → mapMaybe canonical (go zero a b) ≡ mapMaybe canonical (go zero a (canonical b)) goPreservesCanonicalRightOne : (a b : BinNat) → mapMaybe canonical (go one a b) ≡ mapMaybe canonical (go one a (canonical b)) goPreservesCanonicalRightZero [] [] = refl goPreservesCanonicalRightZero [] (zero :: b) with inspect (go zero [] b) goPreservesCanonicalRightZero [] (zero :: b) | no with≡ pr with inspect (canonical b) goPreservesCanonicalRightZero [] (zero :: b) | no with≡ pr | [] with≡ pr2 rewrite pr | pr2 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr)) (transitivity (goPreservesCanonicalRightZero [] b) (transitivity (applyEquality (λ i → mapMaybe canonical (go zero [] i)) pr2) refl)))) goPreservesCanonicalRightZero [] (zero :: b) | no with≡ pr | (x :: y) with≡ pr2 with inspect (go zero [] (x :: y)) goPreservesCanonicalRightZero [] (zero :: b) | no with≡ pr | (x :: y) with≡ pr2 | no with≡ pr3 rewrite pr | pr2 | pr3 = refl goPreservesCanonicalRightZero [] (zero :: b) | no with≡ pr | (x :: y) with≡ pr2 | yes z with≡ pr3 rewrite pr | pr2 | pr3 | equalityCommutative pr2 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr)) (transitivity (goPreservesCanonicalRightZero [] b) (applyEquality (mapMaybe canonical) pr3)))) goPreservesCanonicalRightZero [] (zero :: b) | yes r with≡ pr with inspect (canonical b) goPreservesCanonicalRightZero [] (zero :: b) | yes r with≡ pr | [] with≡ pr2 rewrite pr | pr2 = applyEquality yes (goZeroEmpty' b pr) goPreservesCanonicalRightZero [] (zero :: b) | yes r with≡ pr | (x :: xs) with≡ pr2 with inspect (go zero [] (x :: xs)) goPreservesCanonicalRightZero [] (zero :: b) | yes r with≡ pr | (x :: xs) with≡ pr2 | no with≡ pr3 rewrite pr | pr2 | pr3 = exFalso (noNotYes (transitivity (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr3)) (transitivity (applyEquality (λ i → mapMaybe canonical (go zero [] i)) (equalityCommutative pr2)) (equalityCommutative (goPreservesCanonicalRightZero [] b)))) (applyEquality (mapMaybe canonical) pr))) goPreservesCanonicalRightZero [] (zero :: b) | yes r with≡ pr | (x :: xs) with≡ pr2 | yes x₁ with≡ pr3 rewrite pr | pr2 | pr3 = transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr)) (transitivity (transitivity (goPreservesCanonicalRightZero [] b) (applyEquality (λ i → mapMaybe canonical (go zero [] i)) pr2)) (applyEquality (mapMaybe canonical) pr3)) goPreservesCanonicalRightZero [] (one :: b) = refl goPreservesCanonicalRightZero (zero :: a) [] = refl goPreservesCanonicalRightZero (one :: a) [] = refl goPreservesCanonicalRightZero (zero :: a) (zero :: b) with inspect (canonical b) goPreservesCanonicalRightZero (zero :: a) (zero :: b) | [] with≡ pr1 with inspect (go zero a b) goPreservesCanonicalRightZero (zero :: a) (zero :: b) | [] with≡ pr1 | no with≡ pr2 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr2)) (transitivity (goPreservesCanonicalRightZero a b) (transitivity (applyEquality (λ i → mapMaybe canonical (go zero a i)) pr1) (applyEquality (mapMaybe canonical) (goEmpty a)))))) goPreservesCanonicalRightZero (zero :: a) (zero :: b) | [] with≡ pr1 | yes y with≡ pr2 rewrite pr1 | pr2 = applyEquality yes v where t : canonical y ≡ canonical a t = yesInjective (transitivity (applyEquality (mapMaybe canonical) (equalityCommutative pr2)) (transitivity (goPreservesCanonicalRightZero a b) (transitivity (applyEquality (λ i → mapMaybe canonical (go zero a i)) pr1) (applyEquality (mapMaybe canonical) (goEmpty a))))) v : canonical (zero :: y) ≡ canonical (zero :: a) v with inspect (canonical y) v | [] with≡ pr4 rewrite pr4 | (transitivity (equalityCommutative t) pr4) = refl v | (x :: r) with≡ pr4 rewrite pr4 | transitivity (equalityCommutative t) pr4 = refl goPreservesCanonicalRightZero (zero :: a) (zero :: b) | (r :: rs) with≡ pr1 with inspect (go zero a b) goPreservesCanonicalRightZero (zero :: a) (zero :: b) | (r :: rs) with≡ pr1 | no with≡ pr2 with inspect (go zero a (r :: rs)) goPreservesCanonicalRightZero (zero :: a) (zero :: b) | (r :: rs) with≡ pr1 | no with≡ pr2 | no with≡ pr3 rewrite pr1 | pr2 | pr3 = refl goPreservesCanonicalRightZero (zero :: a) (zero :: b) | (r :: rs) with≡ pr1 | no with≡ pr2 | yes z with≡ pr3 rewrite pr1 | pr2 | pr3 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr2)) (transitivity (transitivity (goPreservesCanonicalRightZero a b) (applyEquality (λ i → mapMaybe canonical (go zero a i)) pr1)) (applyEquality (mapMaybe canonical) pr3)))) goPreservesCanonicalRightZero (zero :: a) (zero :: b) | (r :: rs) with≡ pr1 | yes y with≡ pr2 with inspect (go zero a (r :: rs)) goPreservesCanonicalRightZero (zero :: a) (zero :: b) | (r :: rs) with≡ pr1 | yes y with≡ pr2 | no with≡ pr3 rewrite pr1 | pr2 | pr3 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr3)) (transitivity (transitivity (applyEquality (λ i → mapMaybe canonical (go zero a i)) (equalityCommutative pr1)) (equalityCommutative (goPreservesCanonicalRightZero a b))) (applyEquality (mapMaybe canonical) pr2)))) goPreservesCanonicalRightZero (zero :: a) (zero :: b) | (r :: rs) with≡ pr1 | yes y with≡ pr2 | yes z with≡ pr3 rewrite pr1 | pr2 | pr3 = applyEquality yes v where t : canonical y ≡ canonical z t = yesInjective (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr2)) (transitivity (goPreservesCanonicalRightZero a b) (transitivity (applyEquality (λ i → mapMaybe canonical (go zero a i)) pr1) (applyEquality (mapMaybe canonical) pr3)))) v : canonical (zero :: y) ≡ canonical (zero :: z) v with inspect (canonical y) v | [] with≡ pr4 rewrite pr4 | (transitivity (equalityCommutative t) pr4) = refl v | (x :: r) with≡ pr4 rewrite pr4 | transitivity (equalityCommutative t) pr4 = refl goPreservesCanonicalRightZero (zero :: a) (one :: b) with inspect (go one a b) goPreservesCanonicalRightZero (zero :: a) (one :: b) | no with≡ x with inspect (go one a (canonical b)) goPreservesCanonicalRightZero (zero :: a) (one :: b) | no with≡ pr | no with≡ pr2 rewrite pr | pr2 = refl goPreservesCanonicalRightZero (zero :: a) (one :: b) | no with≡ pr | yes x with≡ pr2 rewrite pr | pr2 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr)) (transitivity (goPreservesCanonicalRightOne a b) (applyEquality (mapMaybe canonical) pr2)))) goPreservesCanonicalRightZero (zero :: a) (one :: b) | yes r with≡ pr1 with inspect (go one a (canonical b)) goPreservesCanonicalRightZero (zero :: a) (one :: b) | yes r with≡ pr1 | no with≡ pr2 rewrite pr1 | pr2 = exFalso (noNotYes (transitivity (applyEquality (mapMaybe canonical) (equalityCommutative pr2)) (transitivity (equalityCommutative (goPreservesCanonicalRightOne a b)) (applyEquality (mapMaybe canonical) pr1)))) goPreservesCanonicalRightZero (zero :: a) (one :: b) | yes r with≡ pr1 | yes s with≡ pr2 rewrite pr1 | pr2 = applyEquality (λ i → yes (one :: i)) (yesInjective (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (goPreservesCanonicalRightOne a b) (applyEquality (mapMaybe canonical) pr2)))) goPreservesCanonicalRightZero (one :: a) (zero :: b) with inspect (go zero a b) goPreservesCanonicalRightZero (one :: a) (zero :: b) | no with≡ pr1 with inspect (canonical b) goPreservesCanonicalRightZero (one :: a) (zero :: b) | no with≡ pr1 | [] with≡ pr2 rewrite pr1 | pr2 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (goPreservesCanonicalRightZero a b) (transitivity (applyEquality (λ i → mapMaybe canonical (go zero a i)) pr2) (applyEquality (mapMaybe canonical) (goEmpty a)))))) goPreservesCanonicalRightZero (one :: a) (zero :: b) | no with≡ pr1 | (x :: y) with≡ pr2 with inspect (go zero a (x :: y)) goPreservesCanonicalRightZero (one :: a) (zero :: b) | no with≡ pr1 | (x :: y) with≡ pr2 | no with≡ pr3 rewrite pr1 | pr2 | pr3 = refl goPreservesCanonicalRightZero (one :: a) (zero :: b) | no with≡ pr1 | (x :: y) with≡ pr2 | yes z with≡ pr3 rewrite pr1 | pr2 | pr3 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (goPreservesCanonicalRightZero a b) (transitivity (applyEquality (λ i → mapMaybe canonical (go zero a i)) pr2) (applyEquality (mapMaybe canonical) pr3))))) goPreservesCanonicalRightZero (one :: a) (zero :: b) | yes x with≡ pr1 with inspect (canonical b) goPreservesCanonicalRightZero (one :: a) (zero :: b) | yes x with≡ pr1 | [] with≡ pr2 rewrite pr1 | pr2 = applyEquality (λ i → yes (one :: i)) (yesInjective (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (goPreservesCanonicalRightZero a b) (transitivity (applyEquality (λ i → mapMaybe canonical (go zero a i)) pr2) (applyEquality (mapMaybe canonical) (goEmpty a)))))) goPreservesCanonicalRightZero (one :: a) (zero :: b) | yes x with≡ pr1 | (r :: rs) with≡ pr2 with inspect (go zero a (r :: rs)) goPreservesCanonicalRightZero (one :: a) (zero :: b) | yes x with≡ pr1 | (r :: rs) with≡ pr2 | no with≡ pr3 rewrite pr1 | pr2 | pr3 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr3)) (transitivity (transitivity (applyEquality (λ i → mapMaybe canonical (go zero a i)) (equalityCommutative pr2)) (equalityCommutative (goPreservesCanonicalRightZero a b))) (applyEquality (mapMaybe canonical) pr1)))) goPreservesCanonicalRightZero (one :: a) (zero :: b) | yes x with≡ pr1 | (r :: rs) with≡ pr2 | yes y with≡ pr3 rewrite pr1 | pr2 | pr3 = applyEquality (λ i → yes (one :: i)) (yesInjective (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (transitivity (goPreservesCanonicalRightZero a b) (applyEquality (λ i → mapMaybe canonical (go zero a i)) pr2)) (applyEquality (mapMaybe canonical) pr3)))) goPreservesCanonicalRightZero (one :: a) (one :: b) with inspect (go zero a b) goPreservesCanonicalRightZero (one :: a) (one :: b) | no with≡ pr1 with inspect (go zero a (canonical b)) goPreservesCanonicalRightZero (one :: a) (one :: b) | no with≡ pr1 | no with≡ x rewrite pr1 | x = refl goPreservesCanonicalRightZero (one :: a) (one :: b) | no with≡ pr1 | yes x₁ with≡ x rewrite pr1 | x = exFalso (noNotYes (transitivity (applyEquality (mapMaybe canonical) (equalityCommutative pr1)) (transitivity (goPreservesCanonicalRightZero a b) (applyEquality (mapMaybe canonical) x)))) goPreservesCanonicalRightZero (one :: a) (one :: b) | yes x with≡ pr1 with inspect (go zero a (canonical b)) goPreservesCanonicalRightZero (one :: a) (one :: b) | yes x with≡ pr1 | no with≡ pr2 rewrite pr1 | pr2 = exFalso (noNotYes (transitivity (applyEquality (mapMaybe canonical) (equalityCommutative pr2)) (transitivity (equalityCommutative (goPreservesCanonicalRightZero a b)) (applyEquality (mapMaybe canonical) pr1)))) goPreservesCanonicalRightZero (one :: a) (one :: b) | yes x with≡ pr1 | yes y with≡ pr2 rewrite pr1 | pr2 = applyEquality yes v where t : canonical x ≡ canonical y t = yesInjective (transitivity (transitivity (applyEquality (mapMaybe canonical) (equalityCommutative pr1)) (goPreservesCanonicalRightZero a b)) (applyEquality (mapMaybe canonical) pr2)) v : canonical (zero :: x) ≡ canonical (zero :: y) v with inspect (canonical x) v | [] with≡ pr4 rewrite pr4 | (transitivity (equalityCommutative t) pr4) = refl v | (x :: r) with≡ pr4 rewrite pr4 | transitivity (equalityCommutative t) pr4 = refl goPreservesCanonicalRightOne a [] = refl goPreservesCanonicalRightOne [] (zero :: b) rewrite goOneEmpty' (canonical (zero :: b)) = refl goPreservesCanonicalRightOne (zero :: a) (zero :: b) with inspect (go one a b) goPreservesCanonicalRightOne (zero :: a) (zero :: b) | no with≡ pr1 with inspect (canonical b) goPreservesCanonicalRightOne (zero :: a) (zero :: b) | no with≡ pr1 | [] with≡ pr2 with inspect (go one a []) goPreservesCanonicalRightOne (zero :: a) (zero :: b) | no with≡ pr1 | [] with≡ pr2 | no with≡ pr3 rewrite pr1 | pr2 | pr3 = refl goPreservesCanonicalRightOne (zero :: a) (zero :: b) | no with≡ pr1 | [] with≡ pr2 | yes y with≡ pr3 rewrite pr1 | pr2 | pr3 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (transitivity (goPreservesCanonicalRightOne a b) (transitivity (applyEquality (λ i → mapMaybe canonical (go one a i)) pr2) refl)) (applyEquality (mapMaybe canonical) pr3)))) goPreservesCanonicalRightOne (zero :: a) (zero :: b) | no with≡ pr1 | (x :: y) with≡ pr2 with inspect (go one a (x :: y)) goPreservesCanonicalRightOne (zero :: a) (zero :: b) | no with≡ pr1 | (x :: y) with≡ pr2 | no with≡ pr3 rewrite pr1 | pr2 | pr3 = refl goPreservesCanonicalRightOne (zero :: a) (zero :: b) | no with≡ pr1 | (x :: y) with≡ pr2 | yes z with≡ pr3 rewrite pr1 | pr2 | pr3 = exFalso (noNotYes (transitivity (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (goPreservesCanonicalRightOne a b) (applyEquality (λ i → mapMaybe canonical (go one a i)) pr2))) (applyEquality (mapMaybe canonical) pr3))) goPreservesCanonicalRightOne (zero :: a) (zero :: b) | yes y with≡ pr1 with inspect (canonical b) goPreservesCanonicalRightOne (zero :: a) (zero :: b) | yes y with≡ pr1 | [] with≡ pr2 with inspect (go one a []) goPreservesCanonicalRightOne (zero :: a) (zero :: b) | yes y with≡ pr1 | [] with≡ pr2 | no with≡ pr3 rewrite pr1 | pr2 | pr3 = exFalso (noNotYes (transitivity (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr3)) (transitivity (applyEquality (λ i → mapMaybe canonical (go one a i)) (equalityCommutative pr2)) (equalityCommutative (goPreservesCanonicalRightOne a b)))) (applyEquality (mapMaybe canonical) pr1))) goPreservesCanonicalRightOne (zero :: a) (zero :: b) | yes y with≡ pr1 | [] with≡ pr2 | yes z with≡ pr3 rewrite pr1 | pr2 | pr3 = applyEquality (λ i → yes (one :: i)) (yesInjective (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (transitivity (goPreservesCanonicalRightOne a b) (applyEquality (λ i → mapMaybe canonical (go one a i)) pr2)) (applyEquality (mapMaybe canonical) pr3)))) goPreservesCanonicalRightOne (zero :: a) (zero :: b) | yes y with≡ pr1 | (r :: rs) with≡ pr2 with inspect (go one a (r :: rs)) goPreservesCanonicalRightOne (zero :: a) (zero :: b) | yes y with≡ pr1 | (r :: rs) with≡ pr2 | no with≡ pr3 rewrite pr1 | pr2 | pr3 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr3)) (transitivity (applyEquality (λ i → mapMaybe canonical (go one a i)) (equalityCommutative pr2)) (transitivity (equalityCommutative (goPreservesCanonicalRightOne a b)) (applyEquality (mapMaybe canonical) pr1))))) goPreservesCanonicalRightOne (zero :: a) (zero :: b) | yes y with≡ pr1 | (r :: rs) with≡ pr2 | yes z with≡ pr3 rewrite pr1 | pr2 | pr3 = applyEquality (λ i → yes (one :: i)) (yesInjective (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (transitivity (goPreservesCanonicalRightOne a b) (applyEquality (λ i → mapMaybe canonical (go one a i)) pr2)) (applyEquality (mapMaybe canonical) pr3)))) goPreservesCanonicalRightOne (one :: a) (zero :: b) with inspect (go zero a b) goPreservesCanonicalRightOne (one :: a) (zero :: b) | no with≡ pr1 with inspect (canonical b) goPreservesCanonicalRightOne (one :: a) (zero :: b) | no with≡ pr1 | [] with≡ pr2 rewrite pr1 | pr2 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (goPreservesCanonicalRightZero a b) (transitivity (applyEquality (λ i → mapMaybe canonical (go zero a i)) pr2) (applyEquality (mapMaybe canonical) (goEmpty a)))))) goPreservesCanonicalRightOne (one :: a) (zero :: b) | no with≡ pr1 | (r :: rs) with≡ pr2 with inspect (go zero a (r :: rs)) goPreservesCanonicalRightOne (one :: a) (zero :: b) | no with≡ pr1 | (r :: rs) with≡ pr2 | no with≡ pr3 rewrite pr1 | pr2 | pr3 = refl goPreservesCanonicalRightOne (one :: a) (zero :: b) | no with≡ pr1 | (r :: rs) with≡ pr2 | yes y with≡ pr3 rewrite pr1 | pr2 | pr3 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (transitivity (goPreservesCanonicalRightZero a b) (applyEquality (λ i → mapMaybe canonical (go zero a i)) pr2)) (applyEquality (mapMaybe canonical) pr3)))) goPreservesCanonicalRightOne (one :: a) (zero :: b) | yes y with≡ pr1 with inspect (canonical b) goPreservesCanonicalRightOne (one :: a) (zero :: b) | yes y with≡ pr1 | [] with≡ pr2 rewrite pr1 | pr2 = applyEquality yes v where t : canonical y ≡ canonical a t = yesInjective (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (goPreservesCanonicalRightZero a b) (transitivity (applyEquality (λ i → mapMaybe canonical (go zero a i)) pr2) (applyEquality (mapMaybe canonical) (goEmpty a))))) v : canonical (zero :: y) ≡ canonical (zero :: a) v with inspect (canonical y) v | [] with≡ pr4 rewrite pr4 | (transitivity (equalityCommutative t) pr4) = refl v | (x :: r) with≡ pr4 rewrite pr4 | transitivity (equalityCommutative t) pr4 = refl goPreservesCanonicalRightOne (one :: a) (zero :: b) | yes y with≡ pr1 | (r :: rs) with≡ pr2 with inspect (go zero a (r :: rs)) goPreservesCanonicalRightOne (one :: a) (zero :: b) | yes y with≡ pr1 | (r :: rs) with≡ pr2 | no with≡ pr3 rewrite pr1 | pr2 | pr3 = exFalso (noNotYes (transitivity (equalityCommutative (transitivity (transitivity (goPreservesCanonicalRightZero a b) (applyEquality (λ i → mapMaybe canonical (go zero a i)) pr2)) (applyEquality (mapMaybe canonical) pr3))) (applyEquality (mapMaybe canonical) pr1))) goPreservesCanonicalRightOne (one :: a) (zero :: b) | yes y with≡ pr1 | (r :: rs) with≡ pr2 | yes z with≡ pr3 rewrite pr1 | pr2 | pr3 = applyEquality yes v where t : canonical y ≡ canonical z t = yesInjective (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (goPreservesCanonicalRightZero a b) (transitivity (applyEquality (λ i → mapMaybe canonical (go zero a i)) pr2) (applyEquality (mapMaybe canonical) pr3)))) v : canonical (zero :: y) ≡ canonical (zero :: z) v with inspect (canonical y) v | [] with≡ pr4 rewrite pr4 | (transitivity (equalityCommutative t) pr4) = refl v | (x :: r) with≡ pr4 rewrite pr4 | transitivity (equalityCommutative t) pr4 = refl goPreservesCanonicalRightOne [] (one :: b) = refl goPreservesCanonicalRightOne (zero :: a) (one :: b) with inspect (go one a b) goPreservesCanonicalRightOne (zero :: a) (one :: b) | no with≡ pr1 with inspect (go one a (canonical b)) goPreservesCanonicalRightOne (zero :: a) (one :: b) | no with≡ pr1 | no with≡ pr2 rewrite pr1 | pr2 = refl goPreservesCanonicalRightOne (zero :: a) (one :: b) | no with≡ pr1 | yes y with≡ pr2 rewrite pr1 | pr2 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (goPreservesCanonicalRightOne a b) (applyEquality (mapMaybe canonical) pr2)))) goPreservesCanonicalRightOne (zero :: a) (one :: b) | yes y with≡ pr1 with inspect (go one a (canonical b)) goPreservesCanonicalRightOne (zero :: a) (one :: b) | yes y with≡ pr1 | no with≡ pr2 rewrite pr1 | pr2 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr2)) (transitivity (equalityCommutative (goPreservesCanonicalRightOne a b)) (applyEquality (mapMaybe canonical) pr1)))) goPreservesCanonicalRightOne (zero :: a) (one :: b) | yes y with≡ pr1 | yes z with≡ pr2 rewrite pr1 | pr2 = applyEquality yes v where t : canonical y ≡ canonical z t = yesInjective (transitivity (transitivity (applyEquality (mapMaybe canonical) (equalityCommutative pr1)) (goPreservesCanonicalRightOne a b)) (applyEquality (mapMaybe canonical) pr2)) v : canonical (zero :: y) ≡ canonical (zero :: z) v with inspect (canonical y) v | [] with≡ pr4 rewrite pr4 | (transitivity (equalityCommutative t) pr4) = refl v | (x :: r) with≡ pr4 rewrite pr4 | transitivity (equalityCommutative t) pr4 = refl goPreservesCanonicalRightOne (one :: a) (one :: b) with inspect (go one a b) goPreservesCanonicalRightOne (one :: a) (one :: b) | no with≡ pr1 with inspect (go one a (canonical b)) goPreservesCanonicalRightOne (one :: a) (one :: b) | no with≡ pr1 | no with≡ pr2 rewrite pr1 | pr2 = refl goPreservesCanonicalRightOne (one :: a) (one :: b) | no with≡ pr1 | yes y with≡ pr2 rewrite pr1 | pr2 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr1)) (transitivity (goPreservesCanonicalRightOne a b) (applyEquality (mapMaybe canonical) pr2)))) goPreservesCanonicalRightOne (one :: a) (one :: b) | yes y with≡ pr1 with inspect (go one a (canonical b)) goPreservesCanonicalRightOne (one :: a) (one :: b) | yes y with≡ pr1 | yes z with≡ pr2 rewrite pr1 | pr2 = applyEquality (λ i → yes (one :: i)) (yesInjective (transitivity (transitivity (applyEquality (mapMaybe canonical) (equalityCommutative pr1)) (goPreservesCanonicalRightOne a b) ) (applyEquality (mapMaybe canonical) pr2))) goPreservesCanonicalRightOne (one :: a) (one :: b) | yes y with≡ pr1 | no with≡ pr2 rewrite pr1 | pr2 = exFalso (noNotYes (transitivity (equalityCommutative (applyEquality (mapMaybe canonical) pr2)) (transitivity (equalityCommutative (goPreservesCanonicalRightOne a b)) (applyEquality (mapMaybe canonical) pr1)))) goPreservesCanonicalRight : (state : Bit) → (a b : BinNat) → mapMaybe canonical (go state a b) ≡ mapMaybe canonical (go state a (canonical b)) goPreservesCanonicalRight zero = goPreservesCanonicalRightZero goPreservesCanonicalRight one = goPreservesCanonicalRightOne
algebraic-stack_agda0000_doc_128
{-# OPTIONS --cubical --safe --postfix-projections #-} module Data.Bool.Properties where open import Prelude open import Data.Bool open import Data.Unit.Properties T? : ∀ x → Dec (T x) T? x .does = x T? false .why = ofⁿ id T? true .why = ofʸ tt isPropT : ∀ x → isProp (T x) isPropT false = isProp⊥ isPropT true = isProp⊤ discreteBool : Discrete Bool discreteBool false y .does = not y discreteBool true y .does = y discreteBool false false .why = ofʸ refl discreteBool false true .why = ofⁿ λ p → subst (bool ⊤ ⊥) p tt discreteBool true false .why = ofⁿ λ p → subst (bool ⊥ ⊤) p tt discreteBool true true .why = ofʸ refl
algebraic-stack_agda0000_doc_129
{-# OPTIONS --without-K #-} module P where open import Data.Empty open import Data.Unit open import Data.Sum open import Data.Product open import Relation.Binary.PropositionalEquality ------------------------------------------------------------------------------ -- For now, a groupoid is just a set Groupoid : Set₁ Groupoid = Set mutual -- types data B : Set where ZERO : B ONE : B _+_ : B → B → B _*_ : B → B → B _~_ : {b : B} → ⟦ b ⟧ → ⟦ b ⟧ → B -- values ⟦_⟧ : B → Groupoid ⟦ ZERO ⟧ = ⊥ ⟦ ONE ⟧ = ⊤ ⟦ b₁ + b₂ ⟧ = ⟦ b₁ ⟧ ⊎ ⟦ b₂ ⟧ ⟦ b₁ * b₂ ⟧ = ⟦ b₁ ⟧ × ⟦ b₂ ⟧ ⟦ v₁ ~ v₂ ⟧ = v₁ ≡ v₂ -- pointed types data PB : Set where POINTED : Σ B (λ b → ⟦ b ⟧) → PB RECIP : PB → PB -- lift B type constructors to pointed types _++_ : PB → PB → PB (POINTED (b₁ , v₁)) ++ (POINTED (b₂ , v₂)) = POINTED (b₁ + b₂ , inj₁ v₁) _ ++ _ = {!!} _**_ : PB → PB → PB (POINTED (b₁ , v₁)) ** (POINTED (b₂ , v₂)) = POINTED (b₁ * b₂ , (v₁ , v₂)) _ ** _ = {!!} -- All the pi combinators now work on pointed types data _⟷_ : PB → PB → Set₁ where swap⋆ : {pb₁ pb₂ : PB} → (pb₁ ** pb₂) ⟷ (pb₂ ** pb₁) eta : {pb : PB} → POINTED (ONE , tt) ⟷ RECIP pb -- induction principle to reason about identities; needed ??? ind : {b : B} → (C : (v₁ v₂ : ⟦ b ⟧) → (p : ⟦ _~_ {b} v₁ v₂ ⟧) → Set) → (c : (v : ⟦ b ⟧) → C v v refl) → (v₁ v₂ : ⟦ b ⟧) → (p : ⟦ _~_ {b} v₁ v₂ ⟧) → C v₁ v₂ p ind C c v .v refl = c v -- Examples Bool : B Bool = ONE + ONE false : ⟦ Bool ⟧ false = inj₁ tt true : ⟦ Bool ⟧ true = inj₂ tt pb1 : PB pb1 = POINTED (Bool , false) pb2 : PB pb2 = POINTED (Bool , true) FalseID : B FalseID = _~_ {Bool} false false pb3 : PB pb3 = POINTED (FalseID , refl) FalseID^2 : B FalseID^2 = _~_ {FalseID} refl refl pb4 : PB pb4 = POINTED (FalseID^2 , refl) ------------------------------------------------------------------------------
algebraic-stack_agda0000_doc_130
-- Basic intuitionistic logic of proofs, without ∨, ⊥, or +. -- Gentzen-style formalisation of syntax with context pairs. -- Normal forms and neutrals. module BasicILP.Syntax.DyadicGentzenNormalForm where open import BasicILP.Syntax.DyadicGentzen public -- Derivations. mutual -- Normal forms, or introductions. infix 3 _⊢ⁿᶠ_ data _⊢ⁿᶠ_ : Cx² Ty Box → Ty → Set where neⁿᶠ : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ⁿᵉ A → Γ ⁏ Δ ⊢ⁿᶠ A lamⁿᶠ : ∀ {A B Γ Δ} → Γ , A ⁏ Δ ⊢ⁿᶠ B → Γ ⁏ Δ ⊢ⁿᶠ A ▻ B boxⁿᶠ : ∀ {Ψ Ω A Γ Δ} → (x : Ψ ⁏ Ω ⊢ A) → Γ ⁏ Δ ⊢ⁿᶠ [ Ψ ⁏ Ω ⊢ x ] A pairⁿᶠ : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ⁿᶠ A → Γ ⁏ Δ ⊢ⁿᶠ B → Γ ⁏ Δ ⊢ⁿᶠ A ∧ B unitⁿᶠ : ∀ {Γ Δ} → Γ ⁏ Δ ⊢ⁿᶠ ⊤ -- Neutrals, or eliminations. infix 3 _⊢ⁿᵉ_ data _⊢ⁿᵉ_ : Cx² Ty Box → Ty → Set where varⁿᵉ : ∀ {A Γ Δ} → A ∈ Γ → Γ ⁏ Δ ⊢ⁿᵉ A appⁿᵉ : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ⁿᵉ A ▻ B → Γ ⁏ Δ ⊢ⁿᶠ A → Γ ⁏ Δ ⊢ⁿᵉ B mvarⁿᵉ : ∀ {Ψ Ω A x Γ Δ} → [ Ψ ⁏ Ω ⊢ x ] A ∈ Δ → {{_ : Γ ⁏ Δ ⊢⋆ⁿᶠ Ψ}} → {{_ : Γ ⁏ Δ ⊢⍟ⁿᶠ Ω}} → Γ ⁏ Δ ⊢ⁿᵉ A unboxⁿᵉ : ∀ {Ψ Ω A C x Γ Δ} → Γ ⁏ Δ ⊢ⁿᵉ [ Ψ ⁏ Ω ⊢ x ] A → Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A ⊢ⁿᶠ C → Γ ⁏ Δ ⊢ⁿᵉ C fstⁿᵉ : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ⁿᵉ A ∧ B → Γ ⁏ Δ ⊢ⁿᵉ A sndⁿᵉ : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ⁿᵉ A ∧ B → Γ ⁏ Δ ⊢ⁿᵉ B infix 3 _⊢⋆ⁿᶠ_ _⊢⋆ⁿᶠ_ : Cx² Ty Box → Cx Ty → Set Γ ⁏ Δ ⊢⋆ⁿᶠ ∅ = 𝟙 Γ ⁏ Δ ⊢⋆ⁿᶠ Ξ , A = Γ ⁏ Δ ⊢⋆ⁿᶠ Ξ × Γ ⁏ Δ ⊢ⁿᶠ A infix 3 _⊢⍟ⁿᶠ_ _⊢⍟ⁿᶠ_ : Cx² Ty Box → Cx Box → Set Γ ⁏ Δ ⊢⍟ⁿᶠ ∅ = 𝟙 Γ ⁏ Δ ⊢⍟ⁿᶠ Ξ , [ Ψ ⁏ Ω ⊢ x ] A = Γ ⁏ Δ ⊢⍟ⁿᶠ Ξ × Γ ⁏ Δ ⊢ⁿᶠ [ Ψ ⁏ Ω ⊢ x ] A infix 3 _⊢⋆ⁿᵉ_ _⊢⋆ⁿᵉ_ : Cx² Ty Box → Cx Ty → Set Γ ⁏ Δ ⊢⋆ⁿᵉ ∅ = 𝟙 Γ ⁏ Δ ⊢⋆ⁿᵉ Ξ , A = Γ ⁏ Δ ⊢⋆ⁿᵉ Ξ × Γ ⁏ Δ ⊢ⁿᵉ A infix 3 _⊢⍟ⁿᵉ_ _⊢⍟ⁿᵉ_ : Cx² Ty Box → Cx Box → Set Γ ⁏ Δ ⊢⍟ⁿᵉ ∅ = 𝟙 Γ ⁏ Δ ⊢⍟ⁿᵉ Ξ , [ Ψ ⁏ Ω ⊢ x ] A = Γ ⁏ Δ ⊢⍟ⁿᵉ Ξ × Γ ⁏ Δ ⊢ⁿᵉ [ Ψ ⁏ Ω ⊢ x ] A -- Translation to simple terms. mutual nf→tm : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ⁿᶠ A → Γ ⁏ Δ ⊢ A nf→tm (neⁿᶠ t) = ne→tm t nf→tm (lamⁿᶠ t) = lam (nf→tm t) nf→tm (boxⁿᶠ t) = box t nf→tm (pairⁿᶠ t u) = pair (nf→tm t) (nf→tm u) nf→tm unitⁿᶠ = unit ne→tm : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ⁿᵉ A → Γ ⁏ Δ ⊢ A ne→tm (varⁿᵉ i) = var i ne→tm (appⁿᵉ t u) = app (ne→tm t) (nf→tm u) ne→tm (mvarⁿᵉ i {{ts}} {{us}}) = mvar i {{nf→tm⋆ ts}} {{nf→tm⍟ us}} ne→tm (unboxⁿᵉ t u) = unbox (ne→tm t) (nf→tm u) ne→tm (fstⁿᵉ t) = fst (ne→tm t) ne→tm (sndⁿᵉ t) = snd (ne→tm t) nf→tm⋆ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊢⋆ⁿᶠ Ξ → Γ ⁏ Δ ⊢⋆ Ξ nf→tm⋆ {∅} ∙ = ∙ nf→tm⋆ {Ξ , A} (ts , t) = nf→tm⋆ ts , nf→tm t nf→tm⍟ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊢⍟ⁿᶠ Ξ → Γ ⁏ Δ ⊢⍟ Ξ nf→tm⍟ {∅} ∙ = ∙ nf→tm⍟ {Ξ , _} (ts , t) = nf→tm⍟ ts , nf→tm t ne→tm⋆ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊢⋆ⁿᵉ Ξ → Γ ⁏ Δ ⊢⋆ Ξ ne→tm⋆ {∅} ∙ = ∙ ne→tm⋆ {Ξ , A} (ts , t) = ne→tm⋆ ts , ne→tm t ne→tm⍟ : ∀ {Ξ Γ Δ} → Γ ⁏ Δ ⊢⍟ⁿᵉ Ξ → Γ ⁏ Δ ⊢⍟ Ξ ne→tm⍟ {∅} ∙ = ∙ ne→tm⍟ {Ξ , _} (ts , t) = ne→tm⍟ ts , ne→tm t -- Monotonicity with respect to context inclusion. mutual mono⊢ⁿᶠ : ∀ {A Γ Γ′ Δ} → Γ ⊆ Γ′ → Γ ⁏ Δ ⊢ⁿᶠ A → Γ′ ⁏ Δ ⊢ⁿᶠ A mono⊢ⁿᶠ η (neⁿᶠ t) = neⁿᶠ (mono⊢ⁿᵉ η t) mono⊢ⁿᶠ η (lamⁿᶠ t) = lamⁿᶠ (mono⊢ⁿᶠ (keep η) t) mono⊢ⁿᶠ η (boxⁿᶠ t) = boxⁿᶠ t mono⊢ⁿᶠ η (pairⁿᶠ t u) = pairⁿᶠ (mono⊢ⁿᶠ η t) (mono⊢ⁿᶠ η u) mono⊢ⁿᶠ η unitⁿᶠ = unitⁿᶠ mono⊢ⁿᵉ : ∀ {A Γ Γ′ Δ} → Γ ⊆ Γ′ → Γ ⁏ Δ ⊢ⁿᵉ A → Γ′ ⁏ Δ ⊢ⁿᵉ A mono⊢ⁿᵉ η (varⁿᵉ i) = varⁿᵉ (mono∈ η i) mono⊢ⁿᵉ η (appⁿᵉ t u) = appⁿᵉ (mono⊢ⁿᵉ η t) (mono⊢ⁿᶠ η u) mono⊢ⁿᵉ η (mvarⁿᵉ i {{ts}} {{us}}) = mvarⁿᵉ i {{mono⊢⋆ⁿᶠ η ts}} {{mono⊢⍟ⁿᶠ η us}} mono⊢ⁿᵉ η (unboxⁿᵉ t u) = unboxⁿᵉ (mono⊢ⁿᵉ η t) (mono⊢ⁿᶠ η u) mono⊢ⁿᵉ η (fstⁿᵉ t) = fstⁿᵉ (mono⊢ⁿᵉ η t) mono⊢ⁿᵉ η (sndⁿᵉ t) = sndⁿᵉ (mono⊢ⁿᵉ η t) mono⊢⋆ⁿᶠ : ∀ {Ξ Γ Γ′ Δ} → Γ ⊆ Γ′ → Γ ⁏ Δ ⊢⋆ⁿᶠ Ξ → Γ′ ⁏ Δ ⊢⋆ⁿᶠ Ξ mono⊢⋆ⁿᶠ {∅} η ∙ = ∙ mono⊢⋆ⁿᶠ {Ξ , A} η (ts , t) = mono⊢⋆ⁿᶠ η ts , mono⊢ⁿᶠ η t mono⊢⍟ⁿᶠ : ∀ {Ξ Γ Γ′ Δ} → Γ ⊆ Γ′ → Γ ⁏ Δ ⊢⍟ⁿᶠ Ξ → Γ′ ⁏ Δ ⊢⍟ⁿᶠ Ξ mono⊢⍟ⁿᶠ {∅} η ∙ = ∙ mono⊢⍟ⁿᶠ {Ξ , _} η (ts , t) = mono⊢⍟ⁿᶠ η ts , mono⊢ⁿᶠ η t mono⊢⋆ⁿᵉ : ∀ {Ξ Γ Γ′ Δ} → Γ ⊆ Γ′ → Γ ⁏ Δ ⊢⋆ⁿᵉ Ξ → Γ′ ⁏ Δ ⊢⋆ⁿᵉ Ξ mono⊢⋆ⁿᵉ {∅} η ∙ = ∙ mono⊢⋆ⁿᵉ {Ξ , A} η (ts , t) = mono⊢⋆ⁿᵉ η ts , mono⊢ⁿᵉ η t mono⊢⍟ⁿᵉ : ∀ {Ξ Γ Γ′ Δ} → Γ ⊆ Γ′ → Γ ⁏ Δ ⊢⍟ⁿᵉ Ξ → Γ′ ⁏ Δ ⊢⍟ⁿᵉ Ξ mono⊢⍟ⁿᵉ {∅} η ∙ = ∙ mono⊢⍟ⁿᵉ {Ξ , _} η (ts , t) = mono⊢⍟ⁿᵉ η ts , mono⊢ⁿᵉ η t -- Monotonicity with respect to modal context inclusion. mutual mmono⊢ⁿᶠ : ∀ {A Γ Δ Δ′} → Δ ⊆ Δ′ → Γ ⁏ Δ ⊢ⁿᶠ A → Γ ⁏ Δ′ ⊢ⁿᶠ A mmono⊢ⁿᶠ θ (neⁿᶠ t) = neⁿᶠ (mmono⊢ⁿᵉ θ t) mmono⊢ⁿᶠ θ (lamⁿᶠ t) = lamⁿᶠ (mmono⊢ⁿᶠ θ t) mmono⊢ⁿᶠ θ (boxⁿᶠ t) = boxⁿᶠ t mmono⊢ⁿᶠ θ (pairⁿᶠ t u) = pairⁿᶠ (mmono⊢ⁿᶠ θ t) (mmono⊢ⁿᶠ θ u) mmono⊢ⁿᶠ θ unitⁿᶠ = unitⁿᶠ mmono⊢ⁿᵉ : ∀ {A Γ Δ Δ′} → Δ ⊆ Δ′ → Γ ⁏ Δ ⊢ⁿᵉ A → Γ ⁏ Δ′ ⊢ⁿᵉ A mmono⊢ⁿᵉ θ (varⁿᵉ i) = varⁿᵉ i mmono⊢ⁿᵉ θ (appⁿᵉ t u) = appⁿᵉ (mmono⊢ⁿᵉ θ t) (mmono⊢ⁿᶠ θ u) mmono⊢ⁿᵉ θ (mvarⁿᵉ i {{ts}} {{us}}) = mvarⁿᵉ (mono∈ θ i) {{mmono⊢⋆ⁿᶠ θ ts}} {{mmono⊢⍟ⁿᶠ θ us}} mmono⊢ⁿᵉ θ (unboxⁿᵉ t u) = unboxⁿᵉ (mmono⊢ⁿᵉ θ t) (mmono⊢ⁿᶠ (keep θ) u) mmono⊢ⁿᵉ θ (fstⁿᵉ t) = fstⁿᵉ (mmono⊢ⁿᵉ θ t) mmono⊢ⁿᵉ θ (sndⁿᵉ t) = sndⁿᵉ (mmono⊢ⁿᵉ θ t) mmono⊢⋆ⁿᶠ : ∀ {Ξ Γ Δ Δ′} → Δ ⊆ Δ′ → Γ ⁏ Δ ⊢⋆ⁿᶠ Ξ → Γ ⁏ Δ′ ⊢⋆ⁿᶠ Ξ mmono⊢⋆ⁿᶠ {∅} θ ∙ = ∙ mmono⊢⋆ⁿᶠ {Ξ , A} θ (ts , t) = mmono⊢⋆ⁿᶠ θ ts , mmono⊢ⁿᶠ θ t mmono⊢⍟ⁿᶠ : ∀ {Ξ Γ Δ Δ′} → Δ ⊆ Δ′ → Γ ⁏ Δ ⊢⍟ⁿᶠ Ξ → Γ ⁏ Δ′ ⊢⍟ⁿᶠ Ξ mmono⊢⍟ⁿᶠ {∅} θ ∙ = ∙ mmono⊢⍟ⁿᶠ {Ξ , _} θ (ts , t) = mmono⊢⍟ⁿᶠ θ ts , mmono⊢ⁿᶠ θ t mmono⊢⋆ⁿᵉ : ∀ {Ξ Γ Δ Δ′} → Δ ⊆ Δ′ → Γ ⁏ Δ ⊢⋆ⁿᵉ Ξ → Γ ⁏ Δ′ ⊢⋆ⁿᵉ Ξ mmono⊢⋆ⁿᵉ {∅} θ ∙ = ∙ mmono⊢⋆ⁿᵉ {Ξ , A} θ (ts , t) = mmono⊢⋆ⁿᵉ θ ts , mmono⊢ⁿᵉ θ t mmono⊢⍟ⁿᵉ : ∀ {Ξ Γ Δ Δ′} → Δ ⊆ Δ′ → Γ ⁏ Δ ⊢⍟ⁿᵉ Ξ → Γ ⁏ Δ′ ⊢⍟ⁿᵉ Ξ mmono⊢⍟ⁿᵉ {∅} θ ∙ = ∙ mmono⊢⍟ⁿᵉ {Ξ , _} θ (ts , t) = mmono⊢⍟ⁿᵉ θ ts , mmono⊢ⁿᵉ θ t -- Monotonicity using context pairs. mono²⊢ⁿᶠ : ∀ {A Π Π′} → Π ⊆² Π′ → Π ⊢ⁿᶠ A → Π′ ⊢ⁿᶠ A mono²⊢ⁿᶠ (η , θ) = mono⊢ⁿᶠ η ∘ mmono⊢ⁿᶠ θ mono²⊢ⁿᵉ : ∀ {A Π Π′} → Π ⊆² Π′ → Π ⊢ⁿᵉ A → Π′ ⊢ⁿᵉ A mono²⊢ⁿᵉ (η , θ) = mono⊢ⁿᵉ η ∘ mmono⊢ⁿᵉ θ -- Generalised reflexivity. refl⊢⋆ⁿᵉ : ∀ {Γ Ψ Δ} → {{_ : Ψ ⊆ Γ}} → Γ ⁏ Δ ⊢⋆ⁿᵉ Ψ refl⊢⋆ⁿᵉ {∅} {{done}} = ∙ refl⊢⋆ⁿᵉ {Γ , A} {{skip η}} = mono⊢⋆ⁿᵉ weak⊆ (refl⊢⋆ⁿᵉ {{η}}) refl⊢⋆ⁿᵉ {Γ , A} {{keep η}} = mono⊢⋆ⁿᵉ weak⊆ (refl⊢⋆ⁿᵉ {{η}}) , varⁿᵉ top
algebraic-stack_agda0000_doc_131
module EquationalTheory where open import Library open import Syntax open import RenamingAndSubstitution -- Single collapsing substitution. sub1 : ∀{Γ σ τ} → Tm Γ σ → Tm (Γ , σ) τ → Tm Γ τ sub1 {Γ}{σ}{τ} u t = sub (subId , u) t -- Typed β-η-equality. data _≡βη_ {Γ : Cxt} : ∀{σ} → Tm Γ σ → Tm Γ σ → Set where -- Axioms. beta≡ : ∀{σ τ} {t : Tm (Γ , σ) τ} {u : Tm Γ σ} → -------------------------- app (abs t) u ≡βη sub1 u t eta≡ : ∀{σ τ} (t : Tm Γ (σ ⇒ τ)) → ------------------------------------- abs (app (weak _ t) (var zero)) ≡βη t -- Congruence rules. var≡ : ∀{σ} (x : Var Γ σ) → --------------- var x ≡βη var x abs≡ : ∀{σ τ}{t t' : Tm (Γ , σ) τ} → t ≡βη t' → ---------------- abs t ≡βη abs t' app≡ : ∀{σ τ}{t t' : Tm Γ (σ ⇒ τ)}{u u' : Tm Γ σ} → t ≡βη t' → u ≡βη u' → --------------------- app t u ≡βη app t' u' -- Equivalence rules. refl≡ : ∀{a} (t {t'} : Tm Γ a) → t ≡ t' → ------- t ≡βη t' sym≡ : ∀{a}{t t' : Tm Γ a} (t'≡t : t' ≡βη t) → ----------------- t ≡βη t' trans≡ : ∀{a}{t₁ t₂ t₃ : Tm Γ a} (t₁≡t₂ : t₁ ≡βη t₂) (t₂≡t₃ : t₂ ≡βη t₃) → ---------------------------------- t₁ ≡βη t₃ -- A calculation on renamings needed for renaming of eta≡. ren-eta≡ : ∀ {Γ Δ a b} (t : Tm Γ (a ⇒ b)) (ρ : Ren Δ Γ) → ren (wkr ρ , zero) (ren (wkr renId) t) ≡ ren (wkr {σ = a} renId) (ren ρ t) ren-eta≡ t ρ = begin ren (wkr ρ , zero) (ren (wkr renId) t) ≡⟨ sym (rencomp _ _ _) ⟩ ren (renComp (wkr ρ , zero) (wkr renId)) t ≡⟨ cong (λ ρ₁ → ren ρ₁ t) (lemrr _ _ _) ⟩ ren (renComp (wkr ρ) renId) t ≡⟨ cong (λ ρ₁ → ren ρ₁ t) (ridr _) ⟩ ren (wkr ρ) t ≡⟨ cong (λ ρ₁ → ren ρ₁ t) (cong wkr (sym (lidr _))) ⟩ ren (wkr (renComp renId ρ)) t ≡⟨ cong (λ ρ₁ → ren ρ₁ t) (sym (wkrcomp _ _)) ⟩ ren (renComp (wkr renId) ρ) t ≡⟨ rencomp _ _ _ ⟩ ren (wkr renId) (ren ρ t) ∎ where open ≡-Reasoning -- Definitional equality is closed under renaming. ren≡βη : ∀{Γ a} {t : Tm Γ a}{t' : Tm Γ a} → t ≡βη t' → ∀{Δ}(ρ : Ren Δ Γ) → ren ρ t ≡βη ren ρ t' ren≡βη (beta≡ {t = t}{u = u}) ρ = trans≡ beta≡ $ refl≡ _ $ trans (subren (subId , ren ρ u) (liftr ρ) t) (trans (cong (λ xs → sub xs t) (cong₂ Sub._,_ (trans (lemsr subId (ren ρ u) ρ) (trans (sidl (ren2sub ρ)) (sym $ sidr (ren2sub ρ)))) (ren2subren ρ u))) (sym $ rensub ρ (subId , u) t)) -- TODO: factor out reasoning about renamings and substitutions ren≡βη (eta≡ {a} t) ρ rewrite ren-eta≡ t ρ = eta≡ (ren ρ t) -- OLD: -- ren≡βη (eta≡ t) ρ = trans≡ -- (abs≡ (app≡ (refl≡ _ -- (trans (sym $ rencomp (liftr ρ) (wkr renId) t) -- (trans (cong (λ xs → ren xs t) -- (trans (lemrr (wkr ρ) zero renId) -- (trans (ridr (wkr ρ)) -- (trans (cong wkr (sym (lidr ρ))) -- (sym (wkrcomp renId ρ)))))) -- (rencomp (wkr renId) ρ t)))) -- (refl≡ _))) -- (eta≡ _) ren≡βη (var≡ x) ρ = var≡ (lookr ρ x) ren≡βη (abs≡ p) ρ = abs≡ (ren≡βη p (liftr ρ)) ren≡βη (app≡ p q) ρ = app≡ (ren≡βη p ρ) (ren≡βη q ρ) ren≡βη (refl≡ _ refl) ρ = refl≡ _ refl ren≡βη (sym≡ p) ρ = sym≡ (ren≡βη p ρ) ren≡βη (trans≡ p q) ρ = trans≡ (ren≡βη p ρ) (ren≡βη q ρ)
algebraic-stack_agda0000_doc_132
open import Relation.Binary.Core module InsertSort.Impl2.Correctness.Order {A : Set} (_≤_ : A → A → Set) (tot≤ : Total _≤_) where open import Data.List open import Function using (_∘_) open import InsertSort.Impl2 _≤_ tot≤ open import List.Sorted _≤_ open import OList _≤_ open import OList.Properties _≤_ theorem-insertSort-sorted : (xs : List A) → Sorted (forget (insertSort xs)) theorem-insertSort-sorted = lemma-olist-sorted ∘ insertSort
algebraic-stack_agda0000_doc_133
{-# OPTIONS --prop #-} open import Agda.Builtin.Nat data T : Nat → Prop where To : T zero Tn : ∀ n → T n ummm : ∀ n → T n → {! !} ummm n t = {! t !}
algebraic-stack_agda0000_doc_134
-- A variant of code reported by Andreas Abel. {-# OPTIONS --guardedness --sized-types #-} open import Common.Coinduction renaming (∞ to Delay) open import Common.Size open import Common.Product data ⊥ : Set where record Stream (A : Set) : Set where inductive constructor delay field force : Delay (A × Stream A) open Stream head : ∀{A} → Stream A → A head s = proj₁ (♭ (force s)) -- This type should be empty, as Stream A is isomorphic to ℕ → A. data D : (i : Size) → Set where lim : ∀ i → Stream (D i) → D (↑ i) -- Emptiness witness for D. empty : ∀ i → D i → ⊥ empty .(↑ i) (lim i s) = empty i (head s) -- BAD: But we can construct an inhabitant. inh : Stream (D ∞) inh = delay (♯ (lim ∞ inh , inh)) -- Should be rejected by termination checker. absurd : ⊥ absurd = empty ∞ (lim ∞ inh)
algebraic-stack_agda0000_doc_135
open import Oscar.Prelude open import Oscar.Class open import Oscar.Class.IsPrecategory open import Oscar.Class.IsCategory open import Oscar.Class.HasEquivalence open import Oscar.Class.Reflexivity open import Oscar.Class.Symmetry open import Oscar.Class.Transextensionality open import Oscar.Class.Transassociativity open import Oscar.Class.Transleftidentity open import Oscar.Class.Transrightidentity open import Oscar.Class.Transitivity open import Oscar.Class.Precategory open import Oscar.Class.Category open import Oscar.Property.Setoid.Proposequality open import Oscar.Property.Setoid.Proposextensequality open import Oscar.Data.Proposequality import Oscar.Class.Reflexivity.Function import Oscar.Class.Transextensionality.Proposequality module Oscar.Property.Category.Function where module _ {𝔬 : Ł} where instance TransitivityFunction : Transitivity.class Function⟦ 𝔬 ⟧ TransitivityFunction .⋆ f g = g ∘ f module _ {𝔬 : Ł} where instance HasEquivalenceFunction : ∀ {A B : Ø 𝔬} → HasEquivalence (Function⟦ 𝔬 ⟧ A B) 𝔬 HasEquivalenceFunction .⋆ = _≡̇_ HasEquivalenceFunction .Rℭlass.⋆⋆ = ! instance TransassociativityFunction : Transassociativity.class Function⟦ 𝔬 ⟧ _≡̇_ transitivity TransassociativityFunction .⋆ _ _ _ _ = ∅ instance 𝓣ransextensionalityFunctionProposextensequality : Transextensionality.class Function⟦ 𝔬 ⟧ Proposextensequality transitivity 𝓣ransextensionalityFunctionProposextensequality .⋆ {f₂ = f₂} f₁≡̇f₂ g₁≡̇g₂ x rewrite f₁≡̇f₂ x = g₁≡̇g₂ (f₂ x) instance IsPrecategoryFunction : IsPrecategory Function⟦ 𝔬 ⟧ _≡̇_ transitivity IsPrecategoryFunction = ∁ instance TransleftidentityFunction : Transleftidentity.class Function⟦ 𝔬 ⟧ _≡̇_ ε transitivity TransleftidentityFunction .⋆ _ = ∅ TransrightidentityFunction : Transrightidentity.class Function⟦ 𝔬 ⟧ _≡̇_ ε transitivity TransrightidentityFunction .⋆ _ = ∅ instance IsCategoryFunction : IsCategory Function⟦ 𝔬 ⟧ _≡̇_ ε transitivity IsCategoryFunction = ∁ PrecategoryFunction : Precategory _ _ _ PrecategoryFunction = ∁ Function⟦ 𝔬 ⟧ Proposextensequality transitivity CategoryFunction : Category _ _ _ CategoryFunction = ∁ Function⟦ 𝔬 ⟧ Proposextensequality ε transitivity
algebraic-stack_agda0000_doc_136
------------------------------------------------------------------------ -- The Agda standard library -- -- Floats ------------------------------------------------------------------------ module Data.Float where open import Data.Bool hiding (_≟_) open import Relation.Nullary.Decidable open import Relation.Nullary open import Relation.Binary.PropositionalEquality as PropEq using (_≡_) open import Relation.Binary.PropositionalEquality.TrustMe open import Data.String using (String) postulate Float : Set {-# BUILTIN FLOAT Float #-} primitive primFloatEquality : Float → Float → Bool primShowFloat : Float → String show : Float → String show = primShowFloat _≟_ : (x y : Float) → Dec (x ≡ y) x ≟ y with primFloatEquality x y ... | true = yes trustMe ... | false = no whatever where postulate whatever : _
algebraic-stack_agda0000_doc_137
module Issue2447.Type-error where import Issue2447.M Rejected : Set Rejected = Set
algebraic-stack_agda0000_doc_138
{-# OPTIONS --safe --warning=error --without-K #-} open import Groups.Homomorphisms.Definition open import Groups.Definition open import Setoids.Setoids open import Rings.Definition open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) module Rings.Homomorphisms.Definition where record RingHom {m n o p : _} {A : Set m} {B : Set n} {SA : Setoid {m} {o} A} {SB : Setoid {n} {p} B} {_+A_ : A → A → A} {_*A_ : A → A → A} (R : Ring SA _+A_ _*A_) {_+B_ : B → B → B} {_*B_ : B → B → B} (S : Ring SB _+B_ _*B_) (f : A → B) : Set (m ⊔ n ⊔ o ⊔ p) where open Ring S open Group additiveGroup open Setoid SB field preserves1 : f (Ring.1R R) ∼ 1R ringHom : {r s : A} → f (r *A s) ∼ (f r) *B (f s) groupHom : GroupHom (Ring.additiveGroup R) additiveGroup f
algebraic-stack_agda0000_doc_139
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Relation.Binary.Base where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.Fiberwise open import Cubical.Data.Sigma open import Cubical.HITs.SetQuotients.Base open import Cubical.HITs.PropositionalTruncation.Base private variable ℓA ℓ≅A ℓA' ℓ≅A' : Level Rel : ∀ {ℓ} (A B : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ')) Rel A B ℓ' = A → B → Type ℓ' PropRel : ∀ {ℓ} (A B : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ')) PropRel A B ℓ' = Σ[ R ∈ Rel A B ℓ' ] ∀ a b → isProp (R a b) idPropRel : ∀ {ℓ} (A : Type ℓ) → PropRel A A ℓ idPropRel A .fst a a' = ∥ a ≡ a' ∥ idPropRel A .snd _ _ = squash invPropRel : ∀ {ℓ ℓ'} {A B : Type ℓ} → PropRel A B ℓ' → PropRel B A ℓ' invPropRel R .fst b a = R .fst a b invPropRel R .snd b a = R .snd a b compPropRel : ∀ {ℓ ℓ' ℓ''} {A B C : Type ℓ} → PropRel A B ℓ' → PropRel B C ℓ'' → PropRel A C (ℓ-max ℓ (ℓ-max ℓ' ℓ'')) compPropRel R S .fst a c = ∥ Σ[ b ∈ _ ] (R .fst a b × S .fst b c) ∥ compPropRel R S .snd _ _ = squash graphRel : ∀ {ℓ} {A B : Type ℓ} → (A → B) → Rel A B ℓ graphRel f a b = f a ≡ b module BinaryRelation {ℓ ℓ' : Level} {A : Type ℓ} (R : Rel A A ℓ') where isRefl : Type (ℓ-max ℓ ℓ') isRefl = (a : A) → R a a isSym : Type (ℓ-max ℓ ℓ') isSym = (a b : A) → R a b → R b a isTrans : Type (ℓ-max ℓ ℓ') isTrans = (a b c : A) → R a b → R b c → R a c record isEquivRel : Type (ℓ-max ℓ ℓ') where constructor equivRel field reflexive : isRefl symmetric : isSym transitive : isTrans isPropValued : Type (ℓ-max ℓ ℓ') isPropValued = (a b : A) → isProp (R a b) isEffective : Type (ℓ-max ℓ ℓ') isEffective = (a b : A) → isEquiv (eq/ {R = R} a b) impliesIdentity : Type _ impliesIdentity = {a a' : A} → (R a a') → (a ≡ a') -- the total space corresponding to the binary relation w.r.t. a relSinglAt : (a : A) → Type (ℓ-max ℓ ℓ') relSinglAt a = Σ[ a' ∈ A ] (R a a') -- the statement that the total space is contractible at any a contrRelSingl : Type (ℓ-max ℓ ℓ') contrRelSingl = (a : A) → isContr (relSinglAt a) isUnivalent : Type (ℓ-max ℓ ℓ') isUnivalent = (a a' : A) → (R a a') ≃ (a ≡ a') contrRelSingl→isUnivalent : isRefl → contrRelSingl → isUnivalent contrRelSingl→isUnivalent ρ c a a' = isoToEquiv i where h : isProp (relSinglAt a) h = isContr→isProp (c a) aρa : relSinglAt a aρa = a , ρ a Q : (y : A) → a ≡ y → _ Q y _ = R a y i : Iso (R a a') (a ≡ a') Iso.fun i r = cong fst (h aρa (a' , r)) Iso.inv i = J Q (ρ a) Iso.rightInv i = J (λ y p → cong fst (h aρa (y , J Q (ρ a) p)) ≡ p) (J (λ q _ → cong fst (h aρa (a , q)) ≡ refl) (J (λ α _ → cong fst α ≡ refl) refl (isContr→isProp (isProp→isContrPath h aρa aρa) refl (h aρa aρa))) (sym (JRefl Q (ρ a)))) Iso.leftInv i r = J (λ w β → J Q (ρ a) (cong fst β) ≡ snd w) (JRefl Q (ρ a)) (h aρa (a' , r)) isUnivalent→contrRelSingl : isUnivalent → contrRelSingl isUnivalent→contrRelSingl u a = q where abstract f : (x : A) → a ≡ x → R a x f x p = invEq (u a x) p t : singl a → relSinglAt a t (x , p) = x , f x p q : isContr (relSinglAt a) q = isOfHLevelRespectEquiv 0 (t , totalEquiv _ _ f λ x → invEquiv (u a x) .snd) (isContrSingl a) EquivRel : ∀ {ℓ} (A : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ')) EquivRel A ℓ' = Σ[ R ∈ Rel A A ℓ' ] BinaryRelation.isEquivRel R EquivPropRel : ∀ {ℓ} (A : Type ℓ) (ℓ' : Level) → Type (ℓ-max ℓ (ℓ-suc ℓ')) EquivPropRel A ℓ' = Σ[ R ∈ PropRel A A ℓ' ] BinaryRelation.isEquivRel (R .fst) record RelIso {A : Type ℓA} (_≅_ : Rel A A ℓ≅A) {A' : Type ℓA'} (_≅'_ : Rel A' A' ℓ≅A') : Type (ℓ-max (ℓ-max ℓA ℓA') (ℓ-max ℓ≅A ℓ≅A')) where constructor reliso field fun : A → A' inv : A' → A rightInv : (a' : A') → fun (inv a') ≅' a' leftInv : (a : A) → inv (fun a) ≅ a open BinaryRelation RelIso→Iso : {A : Type ℓA} {A' : Type ℓA'} (_≅_ : Rel A A ℓ≅A) (_≅'_ : Rel A' A' ℓ≅A') (uni : impliesIdentity _≅_) (uni' : impliesIdentity _≅'_) (f : RelIso _≅_ _≅'_) → Iso A A' Iso.fun (RelIso→Iso _ _ _ _ f) = RelIso.fun f Iso.inv (RelIso→Iso _ _ _ _ f) = RelIso.inv f Iso.rightInv (RelIso→Iso _ _ uni uni' f) a' = uni' (RelIso.rightInv f a') Iso.leftInv (RelIso→Iso _ _ uni uni' f) a = uni (RelIso.leftInv f a)
algebraic-stack_agda0000_doc_140
module Thesis.SIRelBigStep.Types where open import Data.Empty open import Data.Product open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Relation.Binary hiding (_⇒_) data Type : Set where _⇒_ : (σ τ : Type) → Type pair : (σ τ : Type) → Type nat : Type infixr 20 _⇒_ open import Base.Syntax.Context Type public open import Base.Syntax.Vars Type public -- Decidable equivalence for types and contexts. Needed later for ⊕ on closures. ⇒-inj : ∀ {τ1 τ2 τ3 τ4 : Type} → _≡_ {A = Type} (τ1 ⇒ τ2) (τ3 ⇒ τ4) → τ1 ≡ τ3 × τ2 ≡ τ4 ⇒-inj refl = refl , refl pair-inj : ∀ {τ1 τ2 τ3 τ4 : Type} → _≡_ {A = Type} (pair τ1 τ2) (pair τ3 τ4) → τ1 ≡ τ3 × τ2 ≡ τ4 pair-inj refl = refl , refl _≟Type_ : (τ1 τ2 : Type) → Dec (τ1 ≡ τ2) (τ1 ⇒ τ2) ≟Type (τ3 ⇒ τ4) with τ1 ≟Type τ3 | τ2 ≟Type τ4 (τ1 ⇒ τ2) ≟Type (.τ1 ⇒ .τ2) | yes refl | yes refl = yes refl (τ1 ⇒ τ2) ≟Type (.τ1 ⇒ τ4) | yes refl | no ¬q = no (λ x → ¬q (proj₂ (⇒-inj x))) (τ1 ⇒ τ2) ≟Type (τ3 ⇒ τ4) | no ¬p | q = no (λ x → ¬p (proj₁ (⇒-inj x))) (τ1 ⇒ τ2) ≟Type pair τ3 τ4 = no (λ ()) (τ1 ⇒ τ2) ≟Type nat = no (λ ()) pair τ1 τ2 ≟Type (τ3 ⇒ τ4) = no (λ ()) pair τ1 τ2 ≟Type pair τ3 τ4 with τ1 ≟Type τ3 | τ2 ≟Type τ4 pair τ1 τ2 ≟Type pair .τ1 .τ2 | yes refl | yes refl = yes refl pair τ1 τ2 ≟Type pair τ3 τ4 | yes p | no ¬q = no (λ x → ¬q (proj₂ (pair-inj x))) pair τ1 τ2 ≟Type pair τ3 τ4 | no ¬p | q = no (λ x → ¬p (proj₁ (pair-inj x))) pair τ1 τ2 ≟Type nat = no (λ ()) nat ≟Type pair τ1 τ2 = no (λ ()) nat ≟Type (τ1 ⇒ τ2) = no (λ ()) nat ≟Type nat = yes refl •-inj : ∀ {τ1 τ2 : Type} {Γ1 Γ2 : Context} → _≡_ {A = Context} (τ1 • Γ1) (τ2 • Γ2) → τ1 ≡ τ2 × Γ1 ≡ Γ2 •-inj refl = refl , refl _≟Ctx_ : (Γ1 Γ2 : Context) → Dec (Γ1 ≡ Γ2) ∅ ≟Ctx ∅ = yes refl ∅ ≟Ctx (τ2 • Γ2) = no (λ ()) (τ1 • Γ1) ≟Ctx ∅ = no (λ ()) (τ1 • Γ1) ≟Ctx (τ2 • Γ2) with τ1 ≟Type τ2 | Γ1 ≟Ctx Γ2 (τ1 • Γ1) ≟Ctx (.τ1 • .Γ1) | yes refl | yes refl = yes refl (τ1 • Γ1) ≟Ctx (.τ1 • Γ2) | yes refl | no ¬q = no (λ x → ¬q (proj₂ (•-inj x))) (τ1 • Γ1) ≟Ctx (τ2 • Γ2) | no ¬p | q = no (λ x → ¬p (proj₁ (•-inj x))) ≟Ctx-refl : ∀ Γ → Γ ≟Ctx Γ ≡ yes refl ≟Ctx-refl Γ with Γ ≟Ctx Γ ≟Ctx-refl Γ | yes refl = refl ≟Ctx-refl Γ | no ¬p = ⊥-elim (¬p refl)
algebraic-stack_agda0000_doc_141
module MLib.Prelude where open import MLib.Prelude.FromStdlib public module Fin where open import MLib.Prelude.Fin public open Fin using (Fin; zero; suc) hiding (module Fin) public
algebraic-stack_agda0000_doc_142
open import Agda.Builtin.Nat data Vec (A : Set) : Nat → Set where [] : Vec A 0 _∷_ : ∀ {n} → A → Vec A n → Vec A (suc n) infixr 5 _∷_ _++_ _++_ : ∀ {A m n} → Vec A m → Vec A n → Vec A (m + n) [] ++ ys = ys (x ∷ xs) ++ ys = x ∷ xs ++ ys T : ∀ {A n} → Vec A n → Set T [] = Nat T (x ∷ xs) = Vec Nat 0 foo : ∀ {A} m n (xs : Vec A m) (ys : Vec A n) → T (xs ++ ys) foo m n xs ys with {m + n} | xs ++ ys ... | [] = 0 ... | z ∷ zs = []
algebraic-stack_agda0000_doc_143
module HelloWorld where open import Common.IO open import Common.Unit main : IO Unit main = putStr "Hello World"
algebraic-stack_agda0000_doc_17248
------------------------------------------------------------------------ -- The Agda standard library -- -- Examples of decision procedures and how to use them ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module README.Decidability where -- Reflects and Dec are defined in Relation.Nullary, and operations on them can -- be found in Relation.Nullary.Reflects and Relation.Nullary.Decidable. open import Relation.Nullary as Nullary open import Relation.Nullary.Reflects open import Relation.Nullary.Decidable open import Data.Bool open import Data.List open import Data.List.Properties using (∷-injective) open import Data.Nat open import Data.Nat.Properties using (suc-injective) open import Data.Product open import Data.Unit open import Function open import Relation.Binary.PropositionalEquality open import Relation.Nary open import Relation.Nullary.Product infix 4 _≟₀_ _≟₁_ _≟₂_ -- A proof of `Reflects P b` shows that a proposition `P` has the truth value of -- the boolean `b`. A proof of `Reflects P true` amounts to a proof of `P`, and -- a proof of `Reflects P false` amounts to a refutation of `P`. ex₀ : (n : ℕ) → Reflects (n ≡ n) true ex₀ n = ofʸ refl ex₁ : (n : ℕ) → Reflects (zero ≡ suc n) false ex₁ n = ofⁿ λ () ex₂ : (b : Bool) → Reflects (T b) b ex₂ false = ofⁿ id ex₂ true = ofʸ tt -- A proof of `Dec P` is a proof of `Reflects P b` for some `b`. -- `Dec P` is declared as a record, with fields: -- does : Bool -- proof : Reflects P does ex₃ : (b : Bool) → Dec (T b) does (ex₃ b) = b proof (ex₃ b) = ex₂ b -- We also have pattern synonyms `yes` and `no`, allowing both fields to be -- given at once. ex₄ : (n : ℕ) → Dec (zero ≡ suc n) ex₄ n = no λ () -- It is possible, but not ideal, to define recursive decision procedures using -- only the `yes` and `no` patterns. The following procedure decides whether two -- given natural numbers are equal. _≟₀_ : (m n : ℕ) → Dec (m ≡ n) zero ≟₀ zero = yes refl zero ≟₀ suc n = no λ () suc m ≟₀ zero = no λ () suc m ≟₀ suc n with m ≟₀ n ... | yes p = yes (cong suc p) ... | no ¬p = no (¬p ∘ suc-injective) -- In this case, we can see that `does (suc m ≟ suc n)` should be equal to -- `does (m ≟ n)`, because a `yes` from `m ≟ n` gives rise to a `yes` from the -- result, and similarly for `no`. However, in the above definition, this -- equality does not hold definitionally, because we always do a case split -- before returning a result. To avoid this, we can return the `does` part -- separately, before any pattern matching. _≟₁_ : (m n : ℕ) → Dec (m ≡ n) zero ≟₁ zero = yes refl zero ≟₁ suc n = no λ () suc m ≟₁ zero = no λ () does (suc m ≟₁ suc n) = does (m ≟₁ n) proof (suc m ≟₁ suc n) with m ≟₁ n ... | yes p = ofʸ (cong suc p) ... | no ¬p = ofⁿ (¬p ∘ suc-injective) -- We now get definitional equalities such as the following. _ : (m n : ℕ) → does (5 + m ≟₁ 3 + n) ≡ does (2 + m ≟₁ n) _ = λ m n → refl -- Even better, from a maintainability point of view, is to use `map` or `map′`, -- both of which capture the pattern of the `does` field remaining the same, but -- the `proof` field being updated. _≟₂_ : (m n : ℕ) → Dec (m ≡ n) zero ≟₂ zero = yes refl zero ≟₂ suc n = no λ () suc m ≟₂ zero = no λ () suc m ≟₂ suc n = map′ (cong suc) suc-injective (m ≟₂ n) _ : (m n : ℕ) → does (5 + m ≟₂ 3 + n) ≡ does (2 + m ≟₂ n) _ = λ m n → refl -- `map′` can be used in conjunction with combinators such as `_⊎-dec_` and -- `_×-dec_` to build complex (simply typed) decision procedures. module ListDecEq₀ {a} {A : Set a} (_≟ᴬ_ : (x y : A) → Dec (x ≡ y)) where _≟ᴸᴬ_ : (xs ys : List A) → Dec (xs ≡ ys) [] ≟ᴸᴬ [] = yes refl [] ≟ᴸᴬ (y ∷ ys) = no λ () (x ∷ xs) ≟ᴸᴬ [] = no λ () (x ∷ xs) ≟ᴸᴬ (y ∷ ys) = map′ (uncurry (cong₂ _∷_)) ∷-injective (x ≟ᴬ y ×-dec xs ≟ᴸᴬ ys) -- The final case says that `x ∷ xs ≡ y ∷ ys` exactly when `x ≡ y` *and* -- `xs ≡ ys`. The proofs are updated by the first two arguments to `map′`. -- In the case of ≡-equality tests, the pattern -- `map′ (congₙ c) c-injective (x₀ ≟ y₀ ×-dec ... ×-dec xₙ₋₁ ≟ yₙ₋₁)` -- is captured by `≟-mapₙ n c c-injective (x₀ ≟ y₀) ... (xₙ₋₁ ≟ yₙ₋₁)`. module ListDecEq₁ {a} {A : Set a} (_≟ᴬ_ : (x y : A) → Dec (x ≡ y)) where _≟ᴸᴬ_ : (xs ys : List A) → Dec (xs ≡ ys) [] ≟ᴸᴬ [] = yes refl [] ≟ᴸᴬ (y ∷ ys) = no λ () (x ∷ xs) ≟ᴸᴬ [] = no λ () (x ∷ xs) ≟ᴸᴬ (y ∷ ys) = ≟-mapₙ 2 _∷_ ∷-injective (x ≟ᴬ y) (xs ≟ᴸᴬ ys)
algebraic-stack_agda0000_doc_17249
{-# OPTIONS --cubical-compatible #-} module WithoutK2 where -- Equality defined with two indices. data _≡_ {A : Set} : A → A → Set where refl : ∀ x → x ≡ x K : {A : Set} (P : {x : A} → x ≡ x → Set) → (∀ x → P (refl x)) → ∀ {x} (x≡x : x ≡ x) → P x≡x K P p (refl x) = p x
algebraic-stack_agda0000_doc_17250
open import SOAS.Common open import SOAS.Families.Core open import Categories.Object.Initial open import SOAS.Coalgebraic.Strength import SOAS.Metatheory.MetaAlgebra -- Substitution structure by initiality module SOAS.Metatheory.Substitution {T : Set} (⅀F : Functor 𝔽amiliesₛ 𝔽amiliesₛ) (⅀:Str : Strength ⅀F) (𝔛 : Familyₛ) (open SOAS.Metatheory.MetaAlgebra ⅀F 𝔛) (𝕋:Init : Initial 𝕄etaAlgebras) where open import SOAS.Context open import SOAS.Variable open import SOAS.Abstract.Hom import SOAS.Abstract.Coalgebra as →□ ; open →□.Sorted import SOAS.Abstract.Box as □ ; open □.Sorted open import SOAS.Abstract.Monoid open import SOAS.Coalgebraic.Map open import SOAS.Coalgebraic.Monoid open import SOAS.Coalgebraic.Lift open import SOAS.Metatheory.Algebra ⅀F open import SOAS.Metatheory.Semantics ⅀F ⅀:Str 𝔛 𝕋:Init open import SOAS.Metatheory.Traversal ⅀F ⅀:Str 𝔛 𝕋:Init open import SOAS.Metatheory.Renaming ⅀F ⅀:Str 𝔛 𝕋:Init open import SOAS.Metatheory.Coalgebraic ⅀F ⅀:Str 𝔛 𝕋:Init open Strength ⅀:Str private variable Γ Δ : Ctx α β : T -- Substitution is a 𝕋-parametrised traversal into 𝕋 module Substitution = Traversal 𝕋ᴮ 𝕒𝕝𝕘 id 𝕞𝕧𝕒𝕣 𝕤𝕦𝕓 : 𝕋 ⇾̣ 〖 𝕋 , 𝕋 〗 𝕤𝕦𝕓 = Substitution.𝕥𝕣𝕒𝕧 -- The renaming and algebra structures on 𝕋 are compatible, so 𝕤𝕦𝕓 is coalgebraic 𝕤𝕦𝕓ᶜ : Coalgebraic 𝕋ᴮ 𝕋ᴮ 𝕋ᴮ 𝕤𝕦𝕓 𝕤𝕦𝕓ᶜ = Travᶜ.𝕥𝕣𝕒𝕧ᶜ 𝕋ᴮ 𝕒𝕝𝕘 id 𝕞𝕧𝕒𝕣 𝕋ᴮ idᴮ⇒ Renaming.𝕤𝕖𝕞ᵃ⇒ module 𝕤𝕦𝕓ᶜ = Coalgebraic 𝕤𝕦𝕓ᶜ -- Compatibility of renaming and substitution compat : {ρ : Γ ↝ Δ} (t : 𝕋 α Γ) → 𝕣𝕖𝕟 t ρ ≡ 𝕤𝕦𝕓 t (𝕧𝕒𝕣 ∘ ρ) compat {ρ = ρ} t = begin 𝕣𝕖𝕟 t ρ ≡˘⟨ 𝕥𝕣𝕒𝕧-η≈id 𝕋ᴮ id refl ⟩ 𝕤𝕦𝕓 (𝕣𝕖𝕟 t ρ) 𝕧𝕒𝕣 ≡⟨ 𝕤𝕦𝕓ᶜ.f∘r ⟩ 𝕤𝕦𝕓 t (𝕧𝕒𝕣 ∘ ρ) ∎ where open ≡-Reasoning -- Substitution associativity law 𝕤𝕦𝕓-comp : MapEq₂ 𝕋ᴮ 𝕋ᴮ 𝕒𝕝𝕘 (λ t σ ς → 𝕤𝕦𝕓 (𝕤𝕦𝕓 t σ) ς) (λ t σ ς → 𝕤𝕦𝕓 t (λ v → 𝕤𝕦𝕓 (σ v) ς)) 𝕤𝕦𝕓-comp = record { φ = id ; ϕ = 𝕤𝕦𝕓 ; χ = 𝕞𝕧𝕒𝕣 ; f⟨𝑣⟩ = 𝕥≈₁ 𝕥⟨𝕧⟩ ; f⟨𝑚⟩ = trans (𝕥≈₁ 𝕥⟨𝕞⟩) 𝕥⟨𝕞⟩ ; f⟨𝑎⟩ = λ{ {σ = σ}{ς}{t} → begin 𝕤𝕦𝕓 (𝕤𝕦𝕓 (𝕒𝕝𝕘 t) σ) ς ≡⟨ 𝕥≈₁ 𝕥⟨𝕒⟩ ⟩ 𝕤𝕦𝕓 (𝕒𝕝𝕘 (str 𝕋ᴮ 𝕋 (⅀₁ 𝕤𝕦𝕓 t) σ)) ς ≡⟨ 𝕥⟨𝕒⟩ ⟩ 𝕒𝕝𝕘 (str 𝕋ᴮ 𝕋 (⅀₁ 𝕤𝕦𝕓 (str 𝕋ᴮ 𝕋 (⅀₁ 𝕤𝕦𝕓 t) σ)) ς) ≡˘⟨ congr (str-nat₂ 𝕤𝕦𝕓 (⅀₁ 𝕤𝕦𝕓 t) σ) (λ - → 𝕒𝕝𝕘 (str 𝕋ᴮ 𝕋 - ς)) ⟩ 𝕒𝕝𝕘 (str 𝕋ᴮ 𝕋 (str 𝕋ᴮ 〖 𝕋 , 𝕋 〗 (⅀.F₁ (λ { h ς → 𝕤𝕦𝕓 (h ς) }) (⅀₁ 𝕤𝕦𝕓 t)) σ) ς) ≡˘⟨ congr ⅀.homomorphism (λ - → 𝕒𝕝𝕘 (str 𝕋ᴮ 𝕋 (str 𝕋ᴮ 〖 𝕋 , 𝕋 〗 - σ) ς)) ⟩ 𝕒𝕝𝕘 (str 𝕋ᴮ 𝕋 (str 𝕋ᴮ 〖 𝕋 , 𝕋 〗 (⅀₁ (λ{ t σ → 𝕤𝕦𝕓 (𝕤𝕦𝕓 t σ)}) t) σ) ς) ∎ } ; g⟨𝑣⟩ = 𝕥⟨𝕧⟩ ; g⟨𝑚⟩ = 𝕥⟨𝕞⟩ ; g⟨𝑎⟩ = λ{ {σ = σ}{ς}{t} → begin 𝕤𝕦𝕓 (𝕒𝕝𝕘 t) (λ v → 𝕤𝕦𝕓 (σ v) ς) ≡⟨ 𝕥⟨𝕒⟩ ⟩ 𝕒𝕝𝕘 (str 𝕋ᴮ 𝕋 (⅀₁ 𝕤𝕦𝕓 t) (λ v → 𝕤𝕦𝕓 (σ v) ς)) ≡⟨ cong 𝕒𝕝𝕘 (str-dist 𝕋 𝕤𝕦𝕓ᶜ (⅀₁ 𝕤𝕦𝕓 t) (λ {τ} z → σ z) ς) ⟩ 𝕒𝕝𝕘 (str 𝕋ᴮ 𝕋 (str 𝕋ᴮ 〖 𝕋 , 𝕋 〗 (⅀.F₁ (precomp 𝕋 𝕤𝕦𝕓) (⅀₁ 𝕤𝕦𝕓 t)) σ) ς) ≡˘⟨ congr ⅀.homomorphism (λ - → 𝕒𝕝𝕘 (str 𝕋ᴮ 𝕋 (str 𝕋ᴮ 〖 𝕋 , 𝕋 〗 - σ) ς)) ⟩ 𝕒𝕝𝕘 (str 𝕋ᴮ 𝕋 (str 𝕋ᴮ 〖 𝕋 , 𝕋 〗 (⅀₁ (λ{ t σ ς → 𝕤𝕦𝕓 t (λ v → 𝕤𝕦𝕓 (σ v) ς)}) t) σ) ς) ∎ } } where open ≡-Reasoning ; open Substitution -- Coalgebraic monoid structure on 𝕋 𝕋ᵐ : Mon 𝕋 𝕋ᵐ = record { η = 𝕧𝕒𝕣 ; μ = 𝕤𝕦𝕓 ; lunit = Substitution.𝕥⟨𝕧⟩ ; runit = λ{ {t = t} → trans (𝕥𝕣𝕒𝕧-η≈𝕤𝕖𝕞 𝕋ᴮ 𝕋ᵃ id refl) 𝕤𝕖𝕞-id } ; assoc = λ{ {t = t} → MapEq₂.≈ 𝕤𝕦𝕓-comp t } } open Mon 𝕋ᵐ using ([_/] ; [_,_/]₂ ; lunit ; runit ; assoc) public 𝕋ᴹ : CoalgMon 𝕋 𝕋ᴹ = record { ᴮ = 𝕋ᴮ ; ᵐ = 𝕋ᵐ ; η-compat = refl ; μ-compat = λ{ {t = t} → compat t } } -- Corollaries: renaming and simultaneous substitution commutes with -- single-variable substitution open import SOAS.ContextMaps.Combinators 𝕣𝕖𝕟[/] : (ρ : Γ ↝ Δ)(b : 𝕋 α (β ∙ Γ))(a : 𝕋 β Γ) → 𝕣𝕖𝕟 ([ a /] b) ρ ≡ [ (𝕣𝕖𝕟 a ρ) /] (𝕣𝕖𝕟 b (rlift _ ρ)) 𝕣𝕖𝕟[/] ρ b a = begin 𝕣𝕖𝕟 ([ a /] b) ρ ≡⟨ 𝕤𝕦𝕓ᶜ.r∘f ⟩ 𝕤𝕦𝕓 b (λ v → 𝕣𝕖𝕟 (add 𝕋 a 𝕧𝕒𝕣 v) ρ) ≡⟨ cong (𝕤𝕦𝕓 b) (dext (λ{ new → refl ; (old y) → Renaming.𝕥⟨𝕧⟩})) ⟩ 𝕤𝕦𝕓 b (λ v → add 𝕋 (𝕣𝕖𝕟 a ρ) 𝕧𝕒𝕣 (rlift _ ρ v)) ≡˘⟨ 𝕤𝕦𝕓ᶜ.f∘r ⟩ [ 𝕣𝕖𝕟 a ρ /] (𝕣𝕖𝕟 b (rlift _ ρ)) ∎ where open ≡-Reasoning 𝕤𝕦𝕓[/] : (σ : Γ ~[ 𝕋 ]↝ Δ)(b : 𝕋 α (β ∙ Γ))(a : 𝕋 β Γ) → 𝕤𝕦𝕓 ([ a /] b) σ ≡ [ 𝕤𝕦𝕓 a σ /] (𝕤𝕦𝕓 b (lift 𝕋ᴮ ⌈ β ⌋ σ)) 𝕤𝕦𝕓[/] {β = β} σ b a = begin 𝕤𝕦𝕓 ([ a /] b) σ ≡⟨ assoc ⟩ 𝕤𝕦𝕓 b (λ v → 𝕤𝕦𝕓 (add 𝕋 a 𝕧𝕒𝕣 v) σ) ≡⟨ cong (𝕤𝕦𝕓 b) (dext (λ{ new → sym lunit ; (old v) → sym (begin 𝕤𝕦𝕓 (𝕣𝕖𝕟 (σ v) old) (add 𝕋 (𝕤𝕦𝕓 a σ) 𝕧𝕒𝕣) ≡⟨ 𝕤𝕦𝕓ᶜ.f∘r ⟩ 𝕤𝕦𝕓 (σ v) (λ v → add 𝕋 (𝕤𝕦𝕓 a σ) 𝕧𝕒𝕣 (old v)) ≡⟨ cong (𝕤𝕦𝕓 (σ v)) (dext (λ{ new → refl ; (old v) → refl})) ⟩ 𝕤𝕦𝕓 (σ v) 𝕧𝕒𝕣 ≡⟨ runit ⟩ σ v ≡˘⟨ lunit ⟩ 𝕤𝕦𝕓 (𝕧𝕒𝕣 v) σ ∎)})) ⟩ 𝕤𝕦𝕓 b (λ v → 𝕤𝕦𝕓 (lift 𝕋ᴮ ⌈ β ⌋ σ v) (add 𝕋 (𝕤𝕦𝕓 a σ) 𝕧𝕒𝕣)) ≡˘⟨ assoc ⟩ [ 𝕤𝕦𝕓 a σ /] (𝕤𝕦𝕓 b (lift 𝕋ᴮ ⌈ β ⌋ σ)) ∎ where open ≡-Reasoning
algebraic-stack_agda0000_doc_17251
module BuiltinConstructorsNeededForLiterals where data Nat : Set where zero : Nat → Nat suc : Nat → Nat {-# BUILTIN NATURAL Nat #-} data ⊥ : Set where empty : Nat → ⊥ empty (zero n) = empty n empty (suc n) = empty n bad : ⊥ bad = empty 0
algebraic-stack_agda0000_doc_17252
{-# OPTIONS --without-K #-} open import HoTT open import homotopy.HSpace renaming (HSpaceStructure to HSS) open import homotopy.WedgeExtension module homotopy.Pi2HSusp where module Pi2HSusp {i} (A : Type i) (gA : has-level ⟨ 1 ⟩ A) (cA : is-connected ⟨0⟩ A) (A-H : HSS A) (μcoh : HSS.μe- A-H (HSS.e A-H) == HSS.μ-e A-H (HSS.e A-H)) where {- TODO this belongs somewhere else, but where? -} private Type=-ext : ∀ {i} {A B : Type i} (p q : A == B) → ((x : A) → coe p x == coe q x) → p == q Type=-ext p q α = ! (ua-η p) ∙ ap ua (pair= (λ= α) (prop-has-all-paths-↓ (is-equiv-is-prop (coe q)))) ∙ ua-η q open HSpaceStructure A-H open ConnectedHSpace A cA A-H P : Suspension A → Type i P x = Trunc ⟨ 1 ⟩ (north A == x) module Codes = SuspensionRec A A A (λ a → ua (μ-equiv a)) Codes : Suspension A → Type i Codes = Codes.f Codes-level : (x : Suspension A) → has-level ⟨ 1 ⟩ (Codes x) Codes-level = Suspension-elim A gA gA (λ _ → prop-has-all-paths-↓ has-level-is-prop) encode₀ : {x : Suspension A} → (north A == x) → Codes x encode₀ α = transport Codes α e encode : {x : Suspension A} → P x → Codes x encode {x} = Trunc-rec (Codes-level x) encode₀ decode' : A → P (north A) decode' a = [ (merid A a ∙ ! (merid A e)) ] abstract transport-Codes-mer : (a a' : A) → transport Codes (merid A a) a' == μ a a' transport-Codes-mer a a' = coe (ap Codes (merid A a)) a' =⟨ Codes.glue-β a |in-ctx (λ w → coe w a') ⟩ coe (ua (μ-equiv a)) a' =⟨ coe-β (μ-equiv a) a' ⟩ μ a a' ∎ transport-Codes-mer-e-! : (a : A) → transport Codes (! (merid A e)) a == a transport-Codes-mer-e-! a = coe (ap Codes (! (merid A e))) a =⟨ ap-! Codes (merid A e) |in-ctx (λ w → coe w a) ⟩ coe (! (ap Codes (merid A e))) a =⟨ Codes.glue-β e |in-ctx (λ w → coe (! w) a) ⟩ coe (! (ua (μ-equiv e))) a =⟨ Type=-ext (ua (μ-equiv e)) idp (λ x → coe-β _ x ∙ μe- x) |in-ctx (λ w → coe (! w) a) ⟩ coe (! idp) a ∎ abstract encode-decode' : (a : A) → encode (decode' a) == a encode-decode' a = transport Codes (merid A a ∙ ! (merid A e)) e =⟨ trans-∙ {B = Codes} (merid A a) (! (merid A e)) e ⟩ transport Codes (! (merid A e)) (transport Codes (merid A a) e) =⟨ transport-Codes-mer a e ∙ μ-e a |in-ctx (λ w → transport Codes (! (merid A e)) w) ⟩ transport Codes (! (merid A e)) a =⟨ transport-Codes-mer-e-! a ⟩ a ∎ abstract homomorphism : (a a' : A) → Path {A = Trunc ⟨ 1 ⟩ (north A == south A)} [ merid A (μ a a' ) ] [ merid A a' ∙ ! (merid A e) ∙ merid A a ] homomorphism = WedgeExt.ext args where args : WedgeExt.args {a₀ = e} {b₀ = e} args = record {m = ⟨-2⟩; n = ⟨-2⟩; cA = cA; cB = cA; P = λ a a' → (_ , Trunc-level {n = ⟨ 1 ⟩} _ _); f = λ a → ap [_] $ merid A (μ a e) =⟨ ap (merid A) (μ-e a) ⟩ merid A a =⟨ ap (λ w → w ∙ merid A a) (! (!-inv-r (merid A e))) ∙ ∙-assoc (merid A e) (! (merid A e)) (merid A a) ⟩ merid A e ∙ ! (merid A e) ∙ merid A a ∎; g = λ a' → ap [_] $ merid A (μ e a') =⟨ ap (merid A) (μe- a') ⟩ merid A a' =⟨ ! (∙-unit-r (merid A a')) ∙ ap (λ w → merid A a' ∙ w) (! (!-inv-l (merid A e))) ⟩ merid A a' ∙ ! (merid A e) ∙ merid A e ∎ ; p = ap (λ {(p₁ , p₂) → ap [_] $ merid A (μ e e) =⟨ p₁ ⟩ merid A e =⟨ p₂ ⟩ merid A e ∙ ! (merid A e) ∙ merid A e ∎}) (pair×= (ap (λ x → ap (merid A) x) (! μcoh)) (coh (merid A e)))} where coh : {B : Type i} {b b' : B} (p : b == b') → ap (λ w → w ∙ p) (! (!-inv-r p)) ∙ ∙-assoc p (! p) p == ! (∙-unit-r p) ∙ ap (λ w → p ∙ w) (! (!-inv-l p)) coh idp = idp decode : {x : Suspension A} → Codes x → P x decode {x} = Suspension-elim A {P = λ x → Codes x → P x} decode' (λ a → [ merid A a ]) (λ a → ↓-→-from-transp (λ= $ STS a)) x where abstract STS : (a a' : A) → transport P (merid A a) (decode' a') == [ merid A (transport Codes (merid A a) a') ] STS a a' = transport P (merid A a) [ merid A a' ∙ ! (merid A e) ] =⟨ transport-Trunc (λ x → north A == x) (merid A a) _ ⟩ [ transport (λ x → north A == x) (merid A a) (merid A a' ∙ ! (merid A e)) ] =⟨ ap [_] (trans-pathfrom {A = Suspension A} (merid A a) _) ⟩ [ (merid A a' ∙ ! (merid A e)) ∙ merid A a ] =⟨ ap [_] (∙-assoc (merid A a') (! (merid A e)) (merid A a)) ⟩ [ merid A a' ∙ ! (merid A e) ∙ merid A a ] =⟨ ! (homomorphism a a') ⟩ [ merid A (μ a a') ] =⟨ ap ([_] ∘ merid A) (! (transport-Codes-mer a a')) ⟩ [ merid A (transport Codes (merid A a) a') ] ∎ abstract decode-encode : {x : Suspension A} (tα : P x) → decode {x} (encode {x} tα) == tα decode-encode {x} = Trunc-elim {P = λ tα → decode {x} (encode {x} tα) == tα} (λ _ → =-preserves-level ⟨ 1 ⟩ Trunc-level) (J (λ y p → decode {y} (encode {y} [ p ]) == [ p ]) (ap [_] (!-inv-r (merid A e)))) main-lemma-eqv : Trunc ⟨ 1 ⟩ (north A == north A) ≃ A main-lemma-eqv = equiv encode decode' encode-decode' decode-encode ⊙main-lemma : ⊙Trunc ⟨ 1 ⟩ (⊙Ω (⊙Susp (A , e))) == (A , e) ⊙main-lemma = ⊙ua main-lemma-eqv idp abstract main-lemma-iso : (t1 : 1 ≠ 0) → Ω^-Group 1 t1 (⊙Trunc ⟨ 1 ⟩ (⊙Ω (⊙Susp (A , e)))) Trunc-level ≃ᴳ Ω^-Group 1 t1 (⊙Trunc ⟨ 1 ⟩ (A , e)) Trunc-level main-lemma-iso _ = (record {f = f; pres-comp = pres-comp} , ie) where h : fst (⊙Trunc ⟨ 1 ⟩ (⊙Ω (⊙Susp (A , e))) ⊙→ ⊙Trunc ⟨ 1 ⟩ (A , e)) h = (λ x → [ encode x ]) , idp f : Ω (⊙Trunc ⟨ 1 ⟩ (⊙Ω (⊙Susp (A , e)))) → Ω (⊙Trunc ⟨ 1 ⟩ (A , e)) f = fst (ap^ 1 h) pres-comp : (p q : Ω^ 1 (⊙Trunc ⟨ 1 ⟩ (⊙Ω (⊙Susp (A , e))))) → f (conc^ 1 (ℕ-S≠O _) p q) == conc^ 1 (ℕ-S≠O _) (f p) (f q) pres-comp = ap^-conc^ 1 (ℕ-S≠O _) h ie : is-equiv f ie = is-equiv-ap^ 1 h (snd $ ((unTrunc-equiv A gA)⁻¹ ∘e main-lemma-eqv)) abstract π₂-Suspension : (t1 : 1 ≠ 0) (t2 : 2 ≠ 0) → π 2 t2 (⊙Susp (A , e)) == π 1 t1 (A , e) π₂-Suspension t1 t2 = π 2 t2 (⊙Susp (A , e)) =⟨ π-inner-iso 1 t1 t2 (⊙Susp (A , e)) ⟩ π 1 t1 (⊙Ω (⊙Susp (A , e))) =⟨ ! (π-Trunc-shift-iso 1 t1 (⊙Ω (⊙Susp (A , e)))) ⟩ Ω^-Group 1 t1 (⊙Trunc ⟨ 1 ⟩ (⊙Ω (⊙Susp (A , e)))) Trunc-level =⟨ group-ua (main-lemma-iso t1) ⟩ Ω^-Group 1 t1 (⊙Trunc ⟨ 1 ⟩ (A , e)) Trunc-level =⟨ π-Trunc-shift-iso 1 t1 (A , e) ⟩ π 1 t1 (A , e) ∎
algebraic-stack_agda0000_doc_17253
open import Categories open import Monads open import Level import Monads.CatofAdj module Monads.CatofAdj.TermAdjHom {c d} {C : Cat {c}{d}} (M : Monad C) (A : Cat.Obj (Monads.CatofAdj.CatofAdj M {c ⊔ d}{c ⊔ d})) where open import Library open import Functors open import Adjunctions open import Monads.EM M open Monads.CatofAdj M open import Monads.CatofAdj.TermAdjObj M open Cat open Fun open Adj open Monad open ObjAdj K' : Fun (D A) (D EMObj) K' = record { OMap = λ X → record { acar = OMap (R (adj A)) X; astr = λ Z f → subst (λ Z → Hom C Z (OMap (R (adj A)) X)) (fcong Z (cong OMap (law A))) (HMap (R (adj A)) (right (adj A) f)); alaw1 = λ {Z} {f} → alaw1lem (TFun M) (L (adj A)) (R (adj A)) (law A) (η M) (right (adj A)) (left (adj A)) (ηlaw A) (natleft (adj A) (iden C) (right (adj A) f) (iden (D A))) (lawb (adj A) f); alaw2 = λ {Z} {W} {k} {f} → alaw2lem (TFun M) (L (adj A)) (R (adj A)) (law A) (right (adj A)) (bind M) (natright (adj A)) (bindlaw A {_}{_}{k})}; HMap = λ {X} {Y} f → record { amor = HMap (R (adj A)) f; ahom = λ {Z} {g} → ahomlem (TFun M) (L (adj A)) (R (adj A)) (law A) (right (adj A)) (natright (adj A))}; fid = AlgMorphEq (fid (R (adj A))); fcomp = AlgMorphEq (fcomp (R (adj A)))} Llaw' : K' ○ L (adj A) ≅ L (adj EMObj) Llaw' = FunctorEq _ _ (ext (λ X → AlgEq (fcong X (cong OMap (law A))) ((ext λ Z → dext (λ {f} {f'} p → Llawlem (TFun M) (L (adj A)) (R (adj A)) (law A) (right (adj A)) (bind M) (bindlaw A) p))))) (iext λ X → iext λ Y → ext λ f → AlgMorphEq' (AlgEq (fcong X (cong OMap (law A))) ((ext λ Z → dext (λ {f₁} {f'} p → Llawlem (TFun M) (L (adj A)) (R (adj A)) (law A) (right (adj A)) (bind M) (bindlaw A) p)))) (AlgEq (fcong Y (cong OMap (law A))) ((ext λ Z → dext (λ {f₁} {f'} p → Llawlem (TFun M) (L (adj A)) (R (adj A)) (law A) (right (adj A)) (bind M) (bindlaw A) p)))) (dcong (refl {x = f}) (ext (λ _ → cong₂ (Hom C) (fcong X (cong OMap (law A))) (fcong Y (cong OMap (law A))))) (dicong (refl {x = Y}) (ext (λ z → cong (λ F → Hom C X z → Hom C (F X) (F z)) (cong OMap (law A)))) (dicong (refl {x = X}) (ext (λ z → cong (λ F → ∀ {y} → Hom C z y → Hom C (F z) (F y)) (cong OMap (law A)))) (cong HMap (law A)))))) Rlaw' : R (adj A) ≅ R (adj EMObj) ○ K' Rlaw' = FunctorEq _ _ refl refl rightlaw' : {X : Obj C} {Y : Obj (D A)} {f : Hom C X (OMap (R (adj A)) Y)} → HMap K' (right (adj A) f) ≅ right (adj EMObj) {X} {OMap K' Y} (subst (Hom C X) (fcong Y (cong OMap Rlaw')) f) rightlaw' {X = X}{Y = Y}{f = f} = AlgMorphEq' (AlgEq (fcong X (cong OMap (law A))) (ext λ Z → dext (λ p → Llawlem (TFun M) (L (adj A)) (R (adj A)) (law A) (right (adj A)) (bind M) (bindlaw A) p ))) refl (trans (cong (λ (f₁ : Hom C X (OMap (R (adj A)) Y)) → HMap (R (adj A)) (right (adj A) f₁)) (sym (stripsubst (Hom C X) f (fcong Y (cong OMap Rlaw')))) ) (sym (stripsubst (λ Z → Hom C Z (OMap (R (adj A)) Y)) ( ((HMap (R (adj A)) (right (adj A) (subst (Hom C X) (fcong Y (cong (λ r → OMap r) Rlaw')) f))))) (fcong X (cong OMap (law A)))))) EMHom : Hom CatofAdj A EMObj EMHom = record { K = K'; Llaw = Llaw'; Rlaw = Rlaw'; rightlaw = rightlaw'}
algebraic-stack_agda0000_doc_17254
{-# OPTIONS --without-K --rewriting #-} open import lib.Base open import lib.PathFunctor open import lib.PathGroupoid open import lib.Equivalence {- Structural lemmas about paths over paths The lemmas here have the form [↓-something-in] : introduction rule for the something [↓-something-out] : elimination rule for the something [↓-something-β] : β-reduction rule for the something [↓-something-η] : η-reduction rule for the something The possible somethings are: [cst] : constant fibration [cst2] : fibration constant in the second argument [cst2×] : fibration constant and nondependent in the second argument [ap] : the path below is of the form [ap f p] [fst×] : the fibration is [fst] (nondependent product) [snd×] : the fibration is [snd] (nondependent product) The rule of prime: The above lemmas should choose between [_∙_] and [_∙'_] in a way that, if the underlying path is [idp], then the entire lemma reduces to an identity function. Otherwise, the lemma would have the suffix [in'] or [out'], meaning that all the choices of [_∙_] or [_∙'_] are exactly the opposite ones. You can also go back and forth between dependent paths and homogeneous paths with a transport on one side with the functions [to-transp], [from-transp], [to-transp-β] [to-transp!], [from-transp!], [to-transp!-β] More lemmas about paths over paths are present in the lib.types.* modules (depending on the type constructor of the fibration) -} module lib.PathOver where {- Dependent paths in a constant fibration -} module _ {i j} {A : Type i} {B : Type j} where ↓-cst-in : {x y : A} {p : x == y} {u v : B} → u == v → u == v [ (λ _ → B) ↓ p ] ↓-cst-in {p = idp} q = q ↓-cst-out : {x y : A} {p : x == y} {u v : B} → u == v [ (λ _ → B) ↓ p ] → u == v ↓-cst-out {p = idp} q = q ↓-cst-β : {x y : A} (p : x == y) {u v : B} (q : u == v) → (↓-cst-out (↓-cst-in {p = p} q) == q) ↓-cst-β idp q = idp {- Interaction of [↓-cst-in] with [_∙_] -} ↓-cst-in-∙ : {x y z : A} (p : x == y) (q : y == z) {u v w : B} (p' : u == v) (q' : v == w) → ↓-cst-in {p = p ∙ q} (p' ∙ q') == ↓-cst-in {p = p} p' ∙ᵈ ↓-cst-in {p = q} q' ↓-cst-in-∙ idp idp idp idp = idp {- Interaction of [↓-cst-in] with [_∙'_] -} ↓-cst-in-∙' : {x y z : A} (p : x == y) (q : y == z) {u v w : B} (p' : u == v) (q' : v == w) → ↓-cst-in {p = p ∙' q} (p' ∙' q') == ↓-cst-in {p = p} p' ∙'ᵈ ↓-cst-in {p = q} q' ↓-cst-in-∙' idp idp idp idp = idp {- Introduction of an equality between [↓-cst-in]s (used to deduce the recursor from the eliminator in HIT with 2-paths) -} ↓-cst-in2 : {a a' : A} {u v : B} {p₀ : a == a'} {p₁ : a == a'} {q₀ q₁ : u == v} {q : p₀ == p₁} → q₀ == q₁ → (↓-cst-in {p = p₀} q₀ == ↓-cst-in {p = p₁} q₁ [ (λ p → u == v [ (λ _ → B) ↓ p ]) ↓ q ]) ↓-cst-in2 {p₀ = idp} {p₁ = .idp} {q₀} {q₁} {idp} k = k -- Dependent paths in a fibration constant in the second argument module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} where ↓-cst2-in : {x y : A} (p : x == y) {b : C x} {c : C y} (q : b == c [ C ↓ p ]) {u : B x} {v : B y} → u == v [ B ↓ p ] → u == v [ (λ xy → B (fst xy)) ↓ (pair= p q) ] ↓-cst2-in idp idp r = r ↓-cst2-out : {x y : A} (p : x == y) {b : C x} {c : C y} (q : b == c [ C ↓ p ]) {u : B x} {v : B y} → u == v [ (λ xy → B (fst xy)) ↓ (pair= p q) ] → u == v [ B ↓ p ] ↓-cst2-out idp idp r = r -- Dependent paths in a fibration constant and non dependent in the -- second argument module _ {i j k} {A : Type i} {B : A → Type j} {C : Type k} where ↓-cst2×-in : {x y : A} (p : x == y) {b c : C} (q : b == c) {u : B x} {v : B y} → u == v [ B ↓ p ] → u == v [ (λ xy → B (fst xy)) ↓ (pair×= p q) ] ↓-cst2×-in idp idp r = r ↓-cst2×-out : {x y : A} (p : x == y) {b c : C} (q : b == c) {u : B x} {v : B y} → u == v [ (λ xy → B (fst xy)) ↓ (pair×= p q) ] → u == v [ B ↓ p ] ↓-cst2×-out idp idp r = r -- Dependent paths in the universal fibration over the universe ↓-idf-out : ∀ {i} {A B : Type i} (p : A == B) {u : A} {v : B} → u == v [ (λ x → x) ↓ p ] → coe p u == v ↓-idf-out idp = idf _ ↓-idf-in : ∀ {i} {A B : Type i} (p : A == B) {u : A} {v : B} → coe p u == v → u == v [ (λ x → x) ↓ p ] ↓-idf-in idp = idf _ -- Dependent paths over [ap f p] module _ {i j k} {A : Type i} {B : Type j} (C : B → Type k) (f : A → B) where ↓-ap-in : {x y : A} {p : x == y} {u : C (f x)} {v : C (f y)} → u == v [ C ∘ f ↓ p ] → u == v [ C ↓ ap f p ] ↓-ap-in {p = idp} idp = idp ↓-ap-out : {x y : A} (p : x == y) {u : C (f x)} {v : C (f y)} → u == v [ C ↓ ap f p ] → u == v [ C ∘ f ↓ p ] ↓-ap-out idp idp = idp -- Dependent paths over [ap2 f p q] module _ {i j k l} {A : Type i} {B : Type j} {C : Type k} (D : C → Type l) (f : A → B → C) where ↓-ap2-in : {x y : A} {p : x == y} {w z : B} {q : w == z} {u : D (f x w)} {v : D (f y z)} → u == v [ D ∘ uncurry f ↓ pair×= p q ] → u == v [ D ↓ ap2 f p q ] ↓-ap2-in {p = idp} {q = idp} α = α ↓-ap2-out : {x y : A} {p : x == y} {w z : B} {q : w == z} {u : D (f x w)} {v : D (f y z)} → u == v [ D ↓ ap2 f p q ] → u == v [ D ∘ uncurry f ↓ pair×= p q ] ↓-ap2-out {p = idp} {q = idp} α = α apd↓ : ∀ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k} (f : {a : A} (b : B a) → C a b) {x y : A} {p : x == y} {u : B x} {v : B y} (q : u == v [ B ↓ p ]) → f u == f v [ (λ xy → C (fst xy) (snd xy)) ↓ pair= p q ] apd↓ f {p = idp} idp = idp apd↓=apd : ∀ {i j} {A : Type i} {B : A → Type j} (f : (a : A) → B a) {x y : A} (p : x == y) → (apd f p == ↓-ap-out _ _ p (apd↓ {A = Unit} f {p = idp} p)) apd↓=apd f idp = idp -- Paths in the fibrations [fst] and [snd] module _ {i j} where ↓-fst×-out : {A A' : Type i} {B B' : Type j} (p : A == A') (q : B == B') {u : A} {v : A'} → u == v [ fst ↓ pair×= p q ] → u == v [ (λ X → X) ↓ p ] ↓-fst×-out idp idp h = h ↓-snd×-in : {A A' : Type i} {B B' : Type j} (p : A == A') (q : B == B') {u : B} {v : B'} → u == v [ (λ X → X) ↓ q ] → u == v [ snd ↓ pair×= p q ] ↓-snd×-in idp idp h = h -- Mediating dependent paths with the transport version module _ {i j} {A : Type i} where from-transp : (B : A → Type j) {a a' : A} (p : a == a') {u : B a} {v : B a'} → (transport B p u == v) → (u == v [ B ↓ p ]) from-transp B idp idp = idp to-transp : {B : A → Type j} {a a' : A} {p : a == a'} {u : B a} {v : B a'} → (u == v [ B ↓ p ]) → (transport B p u == v) to-transp {p = idp} idp = idp to-transp-β : (B : A → Type j) {a a' : A} (p : a == a') {u : B a} {v : B a'} (q : transport B p u == v) → to-transp (from-transp B p q) == q to-transp-β B idp idp = idp to-transp-η : {B : A → Type j} {a a' : A} {p : a == a'} {u : B a} {v : B a'} (q : u == v [ B ↓ p ]) → from-transp B p (to-transp q) == q to-transp-η {p = idp} idp = idp to-transp-equiv : (B : A → Type j) {a a' : A} (p : a == a') {u : B a} {v : B a'} → (u == v [ B ↓ p ]) ≃ (transport B p u == v) to-transp-equiv B p = equiv to-transp (from-transp B p) (to-transp-β B p) (to-transp-η) from-transp! : (B : A → Type j) {a a' : A} (p : a == a') {u : B a} {v : B a'} → (u == transport! B p v) → (u == v [ B ↓ p ]) from-transp! B idp idp = idp to-transp! : {B : A → Type j} {a a' : A} {p : a == a'} {u : B a} {v : B a'} → (u == v [ B ↓ p ]) → (u == transport! B p v) to-transp! {p = idp} idp = idp to-transp!-β : (B : A → Type j) {a a' : A} (p : a == a') {u : B a} {v : B a'} (q : u == transport! B p v) → to-transp! (from-transp! B p q) == q to-transp!-β B idp idp = idp to-transp!-η : {B : A → Type j} {a a' : A} {p : a == a'} {u : B a} {v : B a'} (q : u == v [ B ↓ p ]) → from-transp! B p (to-transp! q) == q to-transp!-η {p = idp} idp = idp to-transp!-equiv : (B : A → Type j) {a a' : A} (p : a == a') {u : B a} {v : B a'} → (u == v [ B ↓ p ]) ≃ (u == transport! B p v) to-transp!-equiv B p = equiv to-transp! (from-transp! B p) (to-transp!-β B p) (to-transp!-η) {- Various other lemmas -} {- Used for defining the recursor from the eliminator for 1-HIT -} apd=cst-in : ∀ {i j} {A : Type i} {B : Type j} {f : A → B} {a a' : A} {p : a == a'} {q : f a == f a'} → apd f p == ↓-cst-in q → ap f p == q apd=cst-in {p = idp} x = x ↓-apd-out : ∀ {i j k} {A : Type i} {B : A → Type j} (C : (a : A) → B a → Type k) {f : Π A B} {x y : A} {p : x == y} {q : f x == f y [ B ↓ p ]} (r : apd f p == q) {u : C x (f x)} {v : C y (f y)} → u == v [ uncurry C ↓ pair= p q ] → u == v [ (λ z → C z (f z)) ↓ p ] ↓-apd-out C {p = idp} idp idp = idp ↓-ap-out= : ∀ {i j k} {A : Type i} {B : Type j} (C : (b : B) → Type k) (f : A → B) {x y : A} (p : x == y) {q : f x == f y} (r : ap f p == q) {u : C (f x)} {v : C (f y)} → u == v [ C ↓ q ] → u == v [ (λ z → C (f z)) ↓ p ] ↓-ap-out= C f idp idp idp = idp -- No idea what that is to-transp-weird : ∀ {i j} {A : Type i} {B : A → Type j} {u v : A} {d : B u} {d' d'' : B v} {p : u == v} (q : d == d' [ B ↓ p ]) (r : transport B p d == d'') → (from-transp B p r ∙'ᵈ (! r ∙ to-transp q)) == q to-transp-weird {p = idp} idp idp = idp -- Something not really clear yet module _ {i j k} {A : Type i} {B : Type j} {C : Type k} (f : A → C) (g : B → C) where ↓-swap : {a a' : A} {p : a == a'} {b b' : B} {q : b == b'} (r : f a == g b') (s : f a' == g b) → (ap f p ∙' s == r [ (λ x → f a == g x) ↓ q ]) → (r == s ∙ ap g q [ (λ x → f x == g b') ↓ p ]) ↓-swap {p = idp} {q = idp} r s t = (! t) ∙ ∙'-unit-l s ∙ ! (∙-unit-r s) ↓-swap! : {a a' : A} {p : a == a'} {b b' : B} {q : b == b'} (r : f a == g b') (s : f a' == g b) → (r == s ∙ ap g q [ (λ x → f x == g b') ↓ p ]) → (ap f p ∙' s == r [ (λ x → f a == g x) ↓ q ]) ↓-swap! {p = idp} {q = idp} r s t = ∙'-unit-l s ∙ ! (∙-unit-r s) ∙ (! t) ↓-swap-β : {a a' : A} {p : a == a'} {b b' : B} {q : b == b'} (r : f a == g b') (s : f a' == g b) (t : ap f p ∙' s == r [ (λ x → f a == g x) ↓ q ]) → ↓-swap! r s (↓-swap r s t) == t ↓-swap-β {p = idp} {q = idp} r s t = coh (∙'-unit-l s) (∙-unit-r s) t where coh : ∀ {i} {X : Type i} {x y z t : X} (p : x == y) (q : z == y) (r : x == t) → p ∙ ! q ∙ ! (! r ∙ p ∙ ! q) == r coh idp idp idp = idp transp-↓ : ∀ {i j} {A : Type i} (P : A → Type j) {a₁ a₂ : A} (p : a₁ == a₂) (y : P a₂) → transport P (! p) y == y [ P ↓ p ] transp-↓ _ idp _ = idp transp-ap-↓ : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k) (h : A → B) {a₁ a₂ : A} (p : a₁ == a₂) (y : P (h a₂)) → transport P (! (ap h p)) y == y [ P ∘ h ↓ p ] transp-ap-↓ _ _ idp _ = idp
algebraic-stack_agda0000_doc_17255
------------------------------------------------------------------------ -- The Agda standard library -- -- The lifting of a strict order to incorporate a new supremum ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} -- This module is designed to be used with -- Relation.Nullary.Construct.Add.Supremum open import Relation.Binary module Relation.Binary.Construct.Add.Supremum.Strict {a r} {A : Set a} (_<_ : Rel A r) where open import Level using (_⊔_) open import Data.Product open import Function open import Relation.Nullary hiding (Irrelevant) import Relation.Nullary.Decidable as Dec open import Relation.Binary.PropositionalEquality as P using (_≡_; refl) open import Relation.Nullary.Construct.Add.Supremum import Relation.Binary.Construct.Add.Supremum.Equality as Equality import Relation.Binary.Construct.Add.Supremum.NonStrict as NonStrict ------------------------------------------------------------------------ -- Definition infix 4 _<⁺_ data _<⁺_ : Rel (A ⁺) (a ⊔ r) where [_] : {k l : A} → k < l → [ k ] <⁺ [ l ] [_]<⊤⁺ : (k : A) → [ k ] <⁺ ⊤⁺ ------------------------------------------------------------------------ -- Relational properties [<]-injective : ∀ {k l} → [ k ] <⁺ [ l ] → k < l [<]-injective [ p ] = p <⁺-asym : Asymmetric _<_ → Asymmetric _<⁺_ <⁺-asym <-asym [ p ] [ q ] = <-asym p q <⁺-trans : Transitive _<_ → Transitive _<⁺_ <⁺-trans <-trans [ p ] [ q ] = [ <-trans p q ] <⁺-trans <-trans [ p ] [ k ]<⊤⁺ = [ _ ]<⊤⁺ <⁺-dec : Decidable _<_ → Decidable _<⁺_ <⁺-dec _<?_ [ k ] [ l ] = Dec.map′ [_] [<]-injective (k <? l) <⁺-dec _<?_ [ k ] ⊤⁺ = yes [ k ]<⊤⁺ <⁺-dec _<?_ ⊤⁺ [ l ] = no (λ ()) <⁺-dec _<?_ ⊤⁺ ⊤⁺ = no (λ ()) <⁺-irrelevant : Irrelevant _<_ → Irrelevant _<⁺_ <⁺-irrelevant <-irr [ p ] [ q ] = P.cong _ (<-irr p q) <⁺-irrelevant <-irr [ k ]<⊤⁺ [ k ]<⊤⁺ = P.refl module _ {r} {_≤_ : Rel A r} where open NonStrict _≤_ <⁺-transʳ : Trans _≤_ _<_ _<_ → Trans _≤⁺_ _<⁺_ _<⁺_ <⁺-transʳ <-transʳ [ p ] [ q ] = [ <-transʳ p q ] <⁺-transʳ <-transʳ [ p ] [ k ]<⊤⁺ = [ _ ]<⊤⁺ <⁺-transˡ : Trans _<_ _≤_ _<_ → Trans _<⁺_ _≤⁺_ _<⁺_ <⁺-transˡ <-transˡ [ p ] [ q ] = [ <-transˡ p q ] <⁺-transˡ <-transˡ [ p ] ([ _ ] ≤⊤⁺) = [ _ ]<⊤⁺ <⁺-transˡ <-transˡ [ k ]<⊤⁺ (⊤⁺ ≤⊤⁺) = [ k ]<⊤⁺ ------------------------------------------------------------------------ -- Relational properties + propositional equality <⁺-cmp-≡ : Trichotomous _≡_ _<_ → Trichotomous _≡_ _<⁺_ <⁺-cmp-≡ <-cmp ⊤⁺ ⊤⁺ = tri≈ (λ ()) refl (λ ()) <⁺-cmp-≡ <-cmp ⊤⁺ [ l ] = tri> (λ ()) (λ ()) [ l ]<⊤⁺ <⁺-cmp-≡ <-cmp [ k ] ⊤⁺ = tri< [ k ]<⊤⁺ (λ ()) (λ ()) <⁺-cmp-≡ <-cmp [ k ] [ l ] with <-cmp k l ... | tri< a ¬b ¬c = tri< [ a ] (¬b ∘ []-injective) (¬c ∘ [<]-injective) ... | tri≈ ¬a refl ¬c = tri≈ (¬a ∘ [<]-injective) refl (¬c ∘ [<]-injective) ... | tri> ¬a ¬b c = tri> (¬a ∘ [<]-injective) (¬b ∘ []-injective) [ c ] <⁺-irrefl-≡ : Irreflexive _≡_ _<_ → Irreflexive _≡_ _<⁺_ <⁺-irrefl-≡ <-irrefl refl [ x ] = <-irrefl refl x <⁺-respˡ-≡ : _<⁺_ Respectsˡ _≡_ <⁺-respˡ-≡ = P.subst (_<⁺ _) <⁺-respʳ-≡ : _<⁺_ Respectsʳ _≡_ <⁺-respʳ-≡ = P.subst (_ <⁺_) <⁺-resp-≡ : _<⁺_ Respects₂ _≡_ <⁺-resp-≡ = <⁺-respʳ-≡ , <⁺-respˡ-≡ ------------------------------------------------------------------------ -- Relational properties + setoid equality module _ {e} {_≈_ : Rel A e} where open Equality _≈_ <⁺-cmp : Trichotomous _≈_ _<_ → Trichotomous _≈⁺_ _<⁺_ <⁺-cmp <-cmp ⊤⁺ ⊤⁺ = tri≈ (λ ()) ⊤⁺≈⊤⁺ (λ ()) <⁺-cmp <-cmp ⊤⁺ [ l ] = tri> (λ ()) (λ ()) [ l ]<⊤⁺ <⁺-cmp <-cmp [ k ] ⊤⁺ = tri< [ k ]<⊤⁺ (λ ()) (λ ()) <⁺-cmp <-cmp [ k ] [ l ] with <-cmp k l ... | tri< a ¬b ¬c = tri< [ a ] (¬b ∘ [≈]-injective) (¬c ∘ [<]-injective) ... | tri≈ ¬a b ¬c = tri≈ (¬a ∘ [<]-injective) [ b ] (¬c ∘ [<]-injective) ... | tri> ¬a ¬b c = tri> (¬a ∘ [<]-injective) (¬b ∘ [≈]-injective) [ c ] <⁺-irrefl : Irreflexive _≈_ _<_ → Irreflexive _≈⁺_ _<⁺_ <⁺-irrefl <-irrefl [ p ] [ q ] = <-irrefl p q <⁺-respˡ-≈⁺ : _<_ Respectsˡ _≈_ → _<⁺_ Respectsˡ _≈⁺_ <⁺-respˡ-≈⁺ <-respˡ-≈ [ p ] [ q ] = [ <-respˡ-≈ p q ] <⁺-respˡ-≈⁺ <-respˡ-≈ [ p ] ([ l ]<⊤⁺) = [ _ ]<⊤⁺ <⁺-respˡ-≈⁺ <-respˡ-≈ ⊤⁺≈⊤⁺ q = q <⁺-respʳ-≈⁺ : _<_ Respectsʳ _≈_ → _<⁺_ Respectsʳ _≈⁺_ <⁺-respʳ-≈⁺ <-respʳ-≈ [ p ] [ q ] = [ <-respʳ-≈ p q ] <⁺-respʳ-≈⁺ <-respʳ-≈ ⊤⁺≈⊤⁺ q = q <⁺-resp-≈⁺ : _<_ Respects₂ _≈_ → _<⁺_ Respects₂ _≈⁺_ <⁺-resp-≈⁺ = map <⁺-respʳ-≈⁺ <⁺-respˡ-≈⁺ ------------------------------------------------------------------------ -- Structures + propositional equality <⁺-isStrictPartialOrder-≡ : IsStrictPartialOrder _≡_ _<_ → IsStrictPartialOrder _≡_ _<⁺_ <⁺-isStrictPartialOrder-≡ strict = record { isEquivalence = P.isEquivalence ; irrefl = <⁺-irrefl-≡ irrefl ; trans = <⁺-trans trans ; <-resp-≈ = <⁺-resp-≡ } where open IsStrictPartialOrder strict <⁺-isDecStrictPartialOrder-≡ : IsDecStrictPartialOrder _≡_ _<_ → IsDecStrictPartialOrder _≡_ _<⁺_ <⁺-isDecStrictPartialOrder-≡ dectot = record { isStrictPartialOrder = <⁺-isStrictPartialOrder-≡ isStrictPartialOrder ; _≟_ = ≡-dec _≟_ ; _<?_ = <⁺-dec _<?_ } where open IsDecStrictPartialOrder dectot <⁺-isStrictTotalOrder-≡ : IsStrictTotalOrder _≡_ _<_ → IsStrictTotalOrder _≡_ _<⁺_ <⁺-isStrictTotalOrder-≡ strictot = record { isEquivalence = P.isEquivalence ; trans = <⁺-trans trans ; compare = <⁺-cmp-≡ compare } where open IsStrictTotalOrder strictot ------------------------------------------------------------------------ -- Structures + setoid equality module _ {e} {_≈_ : Rel A e} where open Equality _≈_ <⁺-isStrictPartialOrder : IsStrictPartialOrder _≈_ _<_ → IsStrictPartialOrder _≈⁺_ _<⁺_ <⁺-isStrictPartialOrder strict = record { isEquivalence = ≈⁺-isEquivalence isEquivalence ; irrefl = <⁺-irrefl irrefl ; trans = <⁺-trans trans ; <-resp-≈ = <⁺-resp-≈⁺ <-resp-≈ } where open IsStrictPartialOrder strict <⁺-isDecStrictPartialOrder : IsDecStrictPartialOrder _≈_ _<_ → IsDecStrictPartialOrder _≈⁺_ _<⁺_ <⁺-isDecStrictPartialOrder dectot = record { isStrictPartialOrder = <⁺-isStrictPartialOrder isStrictPartialOrder ; _≟_ = ≈⁺-dec _≟_ ; _<?_ = <⁺-dec _<?_ } where open IsDecStrictPartialOrder dectot <⁺-isStrictTotalOrder : IsStrictTotalOrder _≈_ _<_ → IsStrictTotalOrder _≈⁺_ _<⁺_ <⁺-isStrictTotalOrder strictot = record { isEquivalence = ≈⁺-isEquivalence isEquivalence ; trans = <⁺-trans trans ; compare = <⁺-cmp compare } where open IsStrictTotalOrder strictot
algebraic-stack_agda0000_doc_17256
module _ where module A where infix 2 _↑ infix 1 c data D : Set where ● : D _↑ : D → D c : {x y : D} → D syntax c {x = x} {y = y} = x ↓ y module B where infix 1 c data D : Set where c : {y x : D} → D syntax c {y = y} {x = x} = y ↓ x open A open B rejected : A.D rejected = ● ↑ ↓ ●
algebraic-stack_agda0000_doc_17257
{-# OPTIONS --cubical --safe #-} module Issue4949 where open import Agda.Builtin.Cubical.Path open import Agda.Primitive.Cubical renaming (primIMax to _∨_) open import Agda.Builtin.Unit open import Agda.Builtin.Sigma open import Agda.Builtin.Cubical.Glue renaming (prim^glue to glue) idIsEquiv : ∀ {ℓ} (A : Set ℓ) → isEquiv (\ (x : A) → x) equiv-proof (idIsEquiv A) y = ((y , \ _ → y) , λ z i → z .snd (primINeg i) , λ j → z .snd (primINeg i ∨ j)) idEquiv : ∀ {ℓ} (A : Set ℓ) → Σ _ (isEquiv {A = A} {B = A}) idEquiv A .fst = \ x → x idEquiv A .snd = idIsEquiv A Glue : ∀ {ℓ ℓ'} (A : Set ℓ) {φ : I} → (Te : Partial φ (Σ (Set ℓ') \ T → Σ _ (isEquiv {A = T} {B = A}))) → Set ℓ' Glue A Te = primGlue A (λ x → Te x .fst) (λ x → Te x .snd) ua : ∀ {ℓ} {A B : Set ℓ} → A ≃ B → A ≡ B ua {A = A} {B = B} e i = Glue B (λ { (i = i0) → (A , e) ; (i = i1) → (B , idEquiv B) }) ⊤₀ = ⊤ ⊤₁ = Σ ⊤ \ _ → ⊤ prf : isEquiv {A = ⊤₀} {B = ⊤₁} _ equiv-proof prf y = (_ , \ i → _) , (\ y → \ i → _ , (\ j → _)) u : ⊤₀ ≡ ⊤₁ u = ua ((λ _ → _) , prf) uniq : ∀ i j → u (i ∨ j) uniq i j = glue (λ { (i = i0) (j = i0) → tt ; (i = i1) → tt , tt ; (j = i1) → tt , tt }) _ -- comparing the partial element argument of `glue` should happen at the right type. -- if it does not we get problems with eta. test : ∀ j → uniq i0 j ≡ glue (λ { (i0 = i0) (j = i0) → tt ; (j = i1) → tt , tt }) (tt , tt) test j = \ k → uniq i0 j
algebraic-stack_agda0000_doc_17258
-- Problem 4: ``50 shades of continuity'' {- C(f) = ∀ c : X. Cat(f,c) Cat(f,c) = ∀ ε > 0. ∃ δ > 0. Q(f,c,ε,δ) Q(f,c,ε,δ) = ∀ x : X. abs(x - c) < δ ⇒ abs(f x - f c) < ε C'(f) = ∃ getδ : X -> RPos -> RPos. ∀ c : X. ∀ ε > 0. Q(f,c,ε,getδ c ε) 4a: Define UC(f): UC(f) = ∀ ε > 0. ∃ δ > 0. ∀ y : X. Q(f,y,ε,δ) 4b: Define UC'(f): UC'(f) = ∃ newδ : RPos -> RPos. ∀ ε > 0. ∀ y : X. Q(f,y,ε,newδ ε) The function |newδ| computes a suitable "global" |δ| from any |ε|, which shows |Q| for any |y|. 4c: Prove |∀ f : X -> ℝ. UC'(f) => C'(f)|. The proof is a function from a pair (newδ, puc) to a pair (getδ, pc). proof f (newδ, puc) = (getδ, pc) where getδ c ε = newδ ε pc c ε = puc ε c -- (1) The type of (1) is Q(f,c,ε,newδ ε) = Q(f,c,ε,getδ c ε) which is the type of |pc c ε|. ---------------- Below is a self-contained proof in Agda just to check the above. It is not part of the exam question. -} postulate R RPos : Set abs : R -> RPos _-_ : R -> R -> R _<_ : RPos -> RPos -> Set X = R -- to avoid trouble with lack of subtyping record Sigma (A : Set) (B : A -> Set) : Set where constructor _,_ field fst : A snd : B fst Q : (X -> R) -> X -> RPos -> RPos -> Set Q f c ε δ = (x : X) -> (abs( x - c) < δ) -> (abs(f x - f c) < ε) Cat : (X -> R) -> X -> Set Cat f c = (ε : RPos) -> Sigma RPos (\δ -> Q f c ε δ) C : (X -> R) -> Set C f = (c : X) -> Cat f c C' : (X -> R) -> Set C' f = Sigma (X -> RPos -> RPos) (\getδ -> (c : X) -> (ε : RPos) -> Q f c ε (getδ c ε)) UC : (X -> R) -> Set UC f = (ε : RPos) -> Sigma RPos (\δ -> (y : X) -> Q f y ε δ) UC' : (X -> R) -> Set UC' f = Sigma (RPos -> RPos) (\newδ -> (ε : RPos) -> (y : X) -> Q f y ε (newδ ε)) proof : (f : X -> R) -> UC' f -> C' f proof f (newδ , puc) = (getδ , pc) where getδ = \c -> newδ pc = \c ε -> puc ε c
algebraic-stack_agda0000_doc_17259
-- {-# OPTIONS --show-implicit --show-irrelevant #-} module Data.QuadTree.LensProofs.Valid-LensA where open import Haskell.Prelude renaming (zero to Z; suc to S) open import Data.Lens.Lens open import Data.Logic open import Data.QuadTree.InternalAgda open import Agda.Primitive open import Data.Lens.Proofs.LensLaws open import Data.Lens.Proofs.LensPostulates open import Data.Lens.Proofs.LensComposition open import Data.QuadTree.Implementation.QuadrantLenses open import Data.QuadTree.Implementation.Definition open import Data.QuadTree.Implementation.ValidTypes open import Data.QuadTree.Implementation.SafeFunctions open import Data.QuadTree.Implementation.PublicFunctions open import Data.QuadTree.Implementation.DataLenses --- Lens laws for lensA ValidLens-LensA-ViewSet : {t : Set} {{eqT : Eq t}} {dep : Nat} -> ViewSet (lensA {t} {dep}) ValidLens-LensA-ViewSet (CVQuadrant (Leaf x) {p1}) (CVQuadrant (Leaf v) {p2}) = begin view lensA (set lensA (CVQuadrant (Leaf x) {p1}) (CVQuadrant (Leaf v) {p2})) =⟨⟩ getConst (lensA CConst (ifc (x == v && v == v && v == v) then CVQuadrant (Leaf x) else CVQuadrant (Node (Leaf x) (Leaf v) (Leaf v) (Leaf v)))) =⟨ sym (propFnIfc (x == v && v == v && v == v) (λ x -> getConst (lensA CConst x))) ⟩ (ifc (x == v && v == v && v == v) then (CVQuadrant (Leaf x)) else (CVQuadrant (Leaf x))) =⟨ propIfcBranchesSame {c = (x == v && v == v && v == v)} (CVQuadrant (Leaf x)) ⟩ (CVQuadrant (Leaf x)) end ValidLens-LensA-ViewSet (CVQuadrant (Node a b c d)) (CVQuadrant (Leaf v)) = refl ValidLens-LensA-ViewSet (CVQuadrant (Leaf x) {p1}) (CVQuadrant (Node a b@(Leaf vb) c@(Leaf vc) d@(Leaf vd)) {p2}) = begin view lensA (set lensA (CVQuadrant (Leaf x) {p1}) (CVQuadrant (Node a b c d) {p2})) =⟨⟩ getConst (lensA CConst ( ifc (x == vb && vb == vc && vc == vd) then (CVQuadrant (Leaf x)) else (CVQuadrant (Node (Leaf x) (Leaf vb) (Leaf vc) (Leaf vd))) )) =⟨ sym (propFnIfc (x == vb && vb == vc && vc == vd) (λ x -> getConst (lensA CConst x))) ⟩ (ifc (x == vb && vb == vc && vc == vd) then (CVQuadrant (Leaf x)) else (CVQuadrant (Leaf x))) =⟨ propIfcBranchesSame {c = (x == vb && vb == vc && vc == vd)} (CVQuadrant (Leaf x)) ⟩ (CVQuadrant (Leaf x)) end ValidLens-LensA-ViewSet (CVQuadrant (Leaf x)) (CVQuadrant (Node a (Leaf x₁) (Leaf x₂) (Node d d₁ d₂ d₃))) = refl ValidLens-LensA-ViewSet (CVQuadrant (Leaf x)) (CVQuadrant (Node a (Leaf x₁) (Node c c₁ c₂ c₃) d)) = refl ValidLens-LensA-ViewSet (CVQuadrant (Leaf x)) (CVQuadrant (Node a (Node b b₁ b₂ b₃) c d)) = refl ValidLens-LensA-ViewSet (CVQuadrant (Node toa tob toc tod)) (CVQuadrant (Node a b c d)) = refl ValidLens-LensA-SetView : {t : Set} {{eqT : Eq t}} {dep : Nat} -> SetView (lensA {t} {dep}) ValidLens-LensA-SetView {t} {dep} qd@(CVQuadrant (Leaf x) {p}) = begin set lensA (view lensA qd) qd =⟨⟩ ((ifc (x == x && x == x && x == x) then (CVQuadrant (Leaf x)) else λ {{z}} -> (CVQuadrant (Node (Leaf x) (Leaf x) (Leaf x) (Leaf x))))) =⟨ ifcTrue (x == x && x == x && x == x) (andCombine (eqReflexivity x) (andCombine (eqReflexivity x) (eqReflexivity x))) ⟩ CVQuadrant (Leaf x) end ValidLens-LensA-SetView {t} {dep} cv@(CVQuadrant qd@(Node (Leaf a) (Leaf b) (Leaf c) (Leaf d)) {p}) = begin set lensA (view lensA cv) cv =⟨⟩ (ifc (a == b && b == c && c == d) then (CVQuadrant (Leaf a)) else (CVQuadrant (Node (Leaf a) (Leaf b) (Leaf c) (Leaf d)))) =⟨ ifcFalse (a == b && b == c && c == d) (notTrueToFalse (andSnd {depth qd <= S dep} {isCompressed qd} p)) ⟩ (CVQuadrant (Node (Leaf a) (Leaf b) (Leaf c) (Leaf d))) end ValidLens-LensA-SetView (CVQuadrant (Node (Leaf x) (Leaf x₁) (Leaf x₂) (Node qd₃ qd₄ qd₅ qd₆))) = refl ValidLens-LensA-SetView (CVQuadrant (Node (Leaf x) (Leaf x₁) (Node qd₂ qd₄ qd₅ qd₆) qd₃)) = refl ValidLens-LensA-SetView (CVQuadrant (Node (Leaf x) (Node qd₁ qd₄ qd₅ qd₆) qd₂ qd₃)) = refl ValidLens-LensA-SetView (CVQuadrant (Node (Node qd qd₄ qd₅ qd₆) qd₁ qd₂ qd₃)) = refl ValidLens-LensA-SetSet-Lemma : {t : Set} {{eqT : Eq t}} {dep : Nat} -> (x a b c d : VQuadrant t {dep}) -> set lensA x (combine a b c d) ≡ (combine x b c d) ValidLens-LensA-SetSet-Lemma {t} {dep} (CVQuadrant x@(Leaf xv)) (CVQuadrant a@(Leaf va)) (CVQuadrant b@(Leaf vb)) (CVQuadrant c@(Leaf vc)) (CVQuadrant d@(Leaf vd)) = begin (runIdentity (lensA (λ _ → CIdentity (CVQuadrant (Leaf xv))) (ifc va == vb && vb == vc && vc == vd then CVQuadrant (Leaf va) else CVQuadrant (Node (Leaf va) (Leaf vb) (Leaf vc) (Leaf vd))))) =⟨ sym $ propFnIfc (va == vb && vb == vc && vc == vd) (λ g -> (runIdentity (lensA (λ _ → CIdentity (CVQuadrant (Leaf xv) {andCombine (zeroLteAny dep) IsTrue.itsTrue})) g ) ) ) ⟩ (ifc va == vb && vb == vc && vc == vd then ifc xv == va && va == va && va == va then CVQuadrant (Leaf xv) else CVQuadrant (Node (Leaf xv) (Leaf va) (Leaf va) (Leaf va)) else ifc xv == vb && vb == vc && vc == vd then CVQuadrant (Leaf xv) else CVQuadrant (Node (Leaf xv) (Leaf vb) (Leaf vc) (Leaf vd))) =⟨ ifcTrueMap {c = va == vb && vb == vc && vc == vd} (λ p -> cong (λ q -> ifc xv == q && q == q && q == q then CVQuadrant (Leaf xv) {andCombine (zeroLteAny (S dep)) IsTrue.itsTrue} else (λ {{p}} -> CVQuadrant (Node (Leaf xv) (Leaf q) (Leaf q) (Leaf q)) {andCombine (zeroLteAny (dep)) (falseToNotTrue p)}) ) (eqToEquiv va vb (andFst {va == vb} p)) ) ⟩ (ifc va == vb && vb == vc && vc == vd then ifc xv == vb && vb == vb && vb == vb then CVQuadrant (Leaf xv) {andCombine (zeroLteAny (S dep)) IsTrue.itsTrue} else (λ {{p}} -> CVQuadrant (Node (Leaf xv) (Leaf vb) (Leaf vb) (Leaf vb)) {andCombine (zeroLteAny (dep)) (falseToNotTrue p)}) else ifc xv == vb && vb == vc && vc == vd then CVQuadrant (Leaf xv) else CVQuadrant (Node (Leaf xv) (Leaf vb) (Leaf vc) (Leaf vd))) =⟨ ifcTrueMap {c = va == vb && vb == vc && vc == vd} (λ p -> cong (λ q -> ifc xv == vb && vb == q && q == q then CVQuadrant (Leaf xv) {andCombine (zeroLteAny (S dep)) IsTrue.itsTrue} else (λ {{p}} -> CVQuadrant (Node (Leaf xv) (Leaf vb) (Leaf q) (Leaf q)) {andCombine (zeroLteAny (dep)) (falseToNotTrue p)}) ) (eqToEquiv vb vc (andFst $ andSnd {va == vb} p)) ) ⟩ (ifc va == vb && vb == vc && vc == vd then ifc xv == vb && vb == vc && vc == vc then CVQuadrant (Leaf xv) {andCombine (zeroLteAny (S dep)) IsTrue.itsTrue} else (λ {{p}} -> CVQuadrant (Node (Leaf xv) (Leaf vb) (Leaf vc) (Leaf vc)) {andCombine (zeroLteAny (dep)) (falseToNotTrue p)}) else ifc xv == vb && vb == vc && vc == vd then CVQuadrant (Leaf xv) else CVQuadrant (Node (Leaf xv) (Leaf vb) (Leaf vc) (Leaf vd))) =⟨ ifcTrueMap {c = va == vb && vb == vc && vc == vd} (λ p -> cong (λ q -> ifc xv == vb && vb == vc && vc == q then CVQuadrant (Leaf xv) {andCombine (zeroLteAny (S dep)) IsTrue.itsTrue} else (λ {{p}} -> CVQuadrant (Node (Leaf xv) (Leaf vb) (Leaf vc) (Leaf q)) {andCombine (zeroLteAny (dep)) (falseToNotTrue p)}) ) (eqToEquiv vc vd (andSnd $ andSnd {va == vb} p)) ) ⟩ (ifc va == vb && vb == vc && vc == vd then ifc xv == vb && vb == vc && vc == vd then CVQuadrant (Leaf xv) {andCombine (zeroLteAny (S dep)) IsTrue.itsTrue} else (λ {{p}} -> CVQuadrant (Node (Leaf xv) (Leaf vb) (Leaf vc) (Leaf vd)) {andCombine (zeroLteAny (dep)) (falseToNotTrue p)}) else ifc xv == vb && vb == vc && vc == vd then CVQuadrant (Leaf xv) else CVQuadrant (Node (Leaf xv) (Leaf vb) (Leaf vc) (Leaf vd))) =⟨ propIfcBranchesSame {c = va == vb && vb == vc && vc == vd} (ifc xv == vb && vb == vc && vc == vd then CVQuadrant (Leaf xv) else CVQuadrant (Node (Leaf xv) (Leaf vb) (Leaf vc) (Leaf vd))) ⟩ (ifc xv == vb && vb == vc && vc == vd then CVQuadrant (Leaf xv) else CVQuadrant (Node (Leaf xv) (Leaf vb) (Leaf vc) (Leaf vd))) end ValidLens-LensA-SetSet-Lemma {t} {dep} cvx@(CVQuadrant x@(Node x1 x2 x3 x4) {p}) cva@(CVQuadrant a@(Leaf va)) cvb@(CVQuadrant b@(Leaf vb)) cvc@(CVQuadrant c@(Leaf vc)) cvd@(CVQuadrant d@(Leaf vd)) = begin runIdentity (lensA (λ _ → CIdentity cvx) (ifc va == vb && vb == vc && vc == vd then CVQuadrant (Leaf va) else CVQuadrant (Node (Leaf va) (Leaf vb) (Leaf vc) (Leaf vd)))) =⟨ sym $ propFnIfc (va == vb && vb == vc && vc == vd) (λ g -> (runIdentity (lensA (λ _ → CIdentity cvx) g ) ) ) ⟩ (ifc va == vb && vb == vc && vc == vd then CVQuadrant (Node x (Leaf va) (Leaf va) (Leaf va)) else CVQuadrant (Node x (Leaf vb) (Leaf vc) (Leaf vd))) =⟨ ifcTrueMap {c = va == vb && vb == vc && vc == vd} (λ p -> cong (λ q -> combine cvx (cvq q) (cvq q) (cvq q)) (eqToEquiv va vb (andFst {va == vb} p))) ⟩ (ifc va == vb && vb == vc && vc == vd then CVQuadrant (Node x (Leaf vb) (Leaf vb) (Leaf vb)) else CVQuadrant (Node x (Leaf vb) (Leaf vc) (Leaf vd))) =⟨ ifcTrueMap {c = va == vb && vb == vc && vc == vd} (λ p -> cong (λ q -> combine cvx cvb (cvq q) (cvq q)) (eqToEquiv vb vc (andFst $ andSnd {va == vb} p))) ⟩ (ifc va == vb && vb == vc && vc == vd then CVQuadrant (Node x (Leaf vb) (Leaf vc) (Leaf vc)) else CVQuadrant (Node x (Leaf vb) (Leaf vc) (Leaf vd))) =⟨ ifcTrueMap {c = va == vb && vb == vc && vc == vd} (λ p -> cong (λ q -> combine cvx cvb cvc (cvq q)) (eqToEquiv vc vd (andSnd $ andSnd {va == vb} p))) ⟩ (ifc va == vb && vb == vc && vc == vd then CVQuadrant (Node x (Leaf vb) (Leaf vc) (Leaf vd)) else CVQuadrant (Node x (Leaf vb) (Leaf vc) (Leaf vd))) =⟨ propIfcBranchesSame {c = va == vb && vb == vc && vc == vd} (CVQuadrant (Node x (Leaf vb) (Leaf vc) (Leaf vd))) ⟩ CVQuadrant (Node x (Leaf vb) (Leaf vc) (Leaf vd)) end where -- Construct a valid leaf from a value cvq : t -> VQuadrant t {dep} cvq q = CVQuadrant (Leaf q) {andCombine (zeroLteAny dep) IsTrue.itsTrue} ValidLens-LensA-SetSet-Lemma (CVQuadrant _) (CVQuadrant (Leaf _)) (CVQuadrant (Leaf _)) (CVQuadrant (Leaf _)) (CVQuadrant (Node _ _ _ _)) = refl ValidLens-LensA-SetSet-Lemma (CVQuadrant _) (CVQuadrant (Leaf _)) (CVQuadrant (Leaf _)) (CVQuadrant (Node _ _ _ _)) (CVQuadrant _) = refl ValidLens-LensA-SetSet-Lemma (CVQuadrant _) (CVQuadrant (Leaf _)) (CVQuadrant (Node _ _ _ _)) (CVQuadrant _) (CVQuadrant _) = refl ValidLens-LensA-SetSet-Lemma (CVQuadrant _) (CVQuadrant (Node _ _ _ _)) (CVQuadrant _) (CVQuadrant _) (CVQuadrant _) = refl ValidLens-LensA-SetSet : {t : Set} {{eqT : Eq t}} {dep : Nat} -> SetSet (lensA {t} {dep}) ValidLens-LensA-SetSet a@(CVQuadrant qda) b@(CVQuadrant qdb) x@(CVQuadrant qdx@(Leaf xv)) = begin set lensA (CVQuadrant qdb) (combine (CVQuadrant qda) (CVQuadrant (Leaf xv)) (CVQuadrant (Leaf xv)) (CVQuadrant (Leaf xv))) =⟨ ValidLens-LensA-SetSet-Lemma (CVQuadrant qdb) (CVQuadrant qda) (CVQuadrant (Leaf xv)) (CVQuadrant (Leaf xv)) (CVQuadrant (Leaf xv)) ⟩ combine (CVQuadrant qdb) (CVQuadrant (Leaf xv)) (CVQuadrant (Leaf xv)) (CVQuadrant (Leaf xv)) end ValidLens-LensA-SetSet (CVQuadrant qda) (CVQuadrant qdb) (CVQuadrant qdx@(Node xa xb xc xd)) = begin set lensA (CVQuadrant qdb) (combine (CVQuadrant qda) (CVQuadrant xb) (CVQuadrant xc) (CVQuadrant xd)) =⟨ ValidLens-LensA-SetSet-Lemma (CVQuadrant qdb) (CVQuadrant qda) (CVQuadrant xb) (CVQuadrant xc) (CVQuadrant xd) ⟩ combine (CVQuadrant qdb) (CVQuadrant xb) (CVQuadrant xc) (CVQuadrant xd) end ValidLens-LensA : {t : Set} {{eqT : Eq t}} {dep : Nat} -> ValidLens (VQuadrant t {S dep}) (VQuadrant t {dep}) ValidLens-LensA = CValidLens lensA (ValidLens-LensA-ViewSet) (ValidLens-LensA-SetView) (ValidLens-LensA-SetSet)
algebraic-stack_agda0000_doc_17260
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Base.Types open import LibraBFT.Concrete.System open import LibraBFT.Concrete.System.Parameters import LibraBFT.Impl.Consensus.BlockStorage.BlockStore as BlockStore import LibraBFT.Impl.Consensus.BlockStorage.Properties.BlockStore as BSprops open import LibraBFT.Impl.Consensus.EpochManager as EpochManager open import LibraBFT.Impl.Consensus.EpochManagerTypes import LibraBFT.Impl.Consensus.MetricsSafetyRules as MetricsSafetyRules open import LibraBFT.Impl.Consensus.Properties.MetricsSafetyRules import LibraBFT.Impl.Consensus.RoundManager as RoundManager open import LibraBFT.Impl.Consensus.RoundManager.Properties import LibraBFT.Impl.Consensus.SafetyRules.SafetyRulesManager as SafetyRulesManager open import LibraBFT.Impl.OBM.Logging.Logging open import LibraBFT.Impl.Properties.Util open import LibraBFT.ImplShared.Base.Types open import LibraBFT.ImplShared.Consensus.Types open import LibraBFT.ImplShared.Consensus.Types.EpochDep open import LibraBFT.ImplShared.Interface.Output open import LibraBFT.ImplShared.Util.Dijkstra.All open import Optics.All open import Util.Hash open import Util.Lemmas open import Util.PKCS open import Util.Prelude open import Yasm.System ℓ-RoundManager ℓ-VSFP ConcSysParms open InitProofDefs open Invariants open EpochManagerInv open SafetyRulesInv open SafetyDataInv module LibraBFT.Impl.Consensus.EpochManager.Properties where module newSpec (nodeConfig : NodeConfig) (stateComp : StateComputer) (persistentLivenessStorage : PersistentLivenessStorage) (obmAuthor : Author) (obmSK : SK) where -- TODO-2: May require refinement (additional requirements and/or properties) Contract : EitherD-Post ErrLog EpochManager Contract (Left _) = ⊤ Contract (Right em) = ∀ {sr} → em ^∙ emSafetyRulesManager ∙ srmInternalSafetyRules ≡ SRWLocal sr → sr ^∙ srPersistentStorage ∙ pssSafetyData ∙ sdLastVote ≡ nothing postulate contract : Contract (EpochManager.new nodeConfig stateComp persistentLivenessStorage obmAuthor obmSK) module startRoundManager'Spec (self0 : EpochManager) (now : Instant) (recoveryData : RecoveryData) (epochState0 : EpochState) (obmNeedFetch : ObmNeedFetch) (obmProposalGenerator : ProposalGenerator) (obmVersion : Version) where open startRoundManager'-ed self0 now recoveryData epochState0 obmNeedFetch obmProposalGenerator obmVersion lastVote = recoveryData ^∙ rdLastVote proposalGenerator = obmProposalGenerator roundState = createRoundState-abs self0 now proposerElection = createProposerElection epochState0 srUpdate : SafetyRules → SafetyRules srUpdate = _& srPersistentStorage ∙ pssSafetyData ∙ sdEpoch ∙~ epochState0 ^∙ esEpoch initProcessor : SafetyRules → BlockStore → RoundManager initProcessor sr bs = RoundManager∙new obmNeedFetch epochState0 bs roundState proposerElection proposalGenerator (srUpdate sr) (self0 ^∙ emConfig ∙ ccSyncOnly) ecInfo = mkECinfo (epochState0 ^∙ esVerifier) (epochState0 ^∙ esEpoch) SRVoteEpoch≡ : SafetyRules → Epoch → Set SRVoteEpoch≡ sr epoch = ∀ {v} → sr ^∙ srPersistentStorage ∙ pssSafetyData ∙ sdLastVote ≡ just v → v ^∙ vEpoch ≡ epoch SRVoteRound≤ : SafetyRules → Set SRVoteRound≤ sr = let sd = sr ^∙ srPersistentStorage ∙ pssSafetyData in Meta.getLastVoteRound sd ≤ sd ^∙ sdLastVotedRound initRMInv : ∀ {sr bs} → ValidatorVerifier-correct (epochState0 ^∙ esVerifier) → SafetyDataInv (sr ^∙ srPersistentStorage ∙ pssSafetyData) → sr ^∙ srPersistentStorage ∙ pssSafetyData ∙ sdLastVote ≡ nothing → BlockStoreInv (bs , ecInfo) → RoundManagerInv (initProcessor sr bs) initRMInv {sr} vvCorr sdInv refl bsInv = mkRoundManagerInv vvCorr refl bsInv (mkSafetyRulesInv (mkSafetyDataInv refl z≤n)) contract-continue2 : ∀ {sr bs} → ValidatorVerifier-correct (epochState0 ^∙ esVerifier) → SafetyRulesInv sr → sr ^∙ srPersistentStorage ∙ pssSafetyData ∙ sdLastVote ≡ nothing → BlockStoreInv (bs , ecInfo) → EitherD-weakestPre (continue2-abs lastVote bs sr) (InitContract lastVote) contract-continue2 {sr} {bs} vvCorr srInv lvNothing bsInv rewrite continue2-abs-≡ with LBFT-contract (RoundManager.start-abs now lastVote) (Contract initRM initRMCorr) (initProcessor sr bs) (contract' initRM initRMCorr) where open startSpec now lastVote initRM = initProcessor sr bs initRMCorr = initRMInv {sr} {bs} vvCorr (sdInv srInv) lvNothing bsInv ...| inj₁ (_ , er≡j ) rewrite er≡j = tt ...| inj₂ (er≡n , ico) rewrite er≡n = LBFT-post (RoundManager.start-abs now lastVote) (initProcessor sr bs) , refl , ico contract-continue1 : ∀ {bs} → BlockStoreInv (bs , ecInfo) → ValidatorVerifier-correct (epochState0 ^∙ esVerifier) → EpochManagerInv self0 → EitherD-weakestPre (continue1-abs lastVote bs) (InitContract lastVote) contract-continue1 {bs} bsInv vvCorr emi rewrite continue1-abs-≡ with self0 ^∙ emSafetyRulesManager ∙ srmInternalSafetyRules | inspect (self0 ^∙_) (emSafetyRulesManager ∙ srmInternalSafetyRules) ...| SRWLocal safetyRules | [ R ] with emiSRI emi R ...| (sri , lvNothing) with performInitializeSpec.contract safetyRules (self0 ^∙ emStorage) sri lvNothing ...| piProp with MetricsSafetyRules.performInitialize-abs safetyRules (self0 ^∙ emStorage) ...| Left _ = tt ...| Right sr = contract-continue2 vvCorr (performInitializeSpec.ContractOk.srPres piProp sri) (performInitializeSpec.ContractOk.lvNothing piProp) bsInv contract' : ValidatorVerifier-correct (epochState0 ^∙ esVerifier) → EpochManagerInv self0 → EitherD-weakestPre (EpochManager.startRoundManager'-ed-abs self0 now recoveryData epochState0 obmNeedFetch obmProposalGenerator obmVersion) (InitContract lastVote) contract' vvCorr emi rewrite startRoundManager'-ed-abs-≡ with BSprops.new.contract (self0 ^∙ emStorage) recoveryData stateComputer (self0 ^∙ emConfig ∙ ccMaxPrunedBlocksInMem) ...| bsprop with BlockStore.new-e-abs (self0 ^∙ emStorage) recoveryData stateComputer (self0 ^∙ emConfig ∙ ccMaxPrunedBlocksInMem) ...| Left _ = tt ...| Right bs = contract-continue1 bsprop vvCorr emi
algebraic-stack_agda0000_doc_17261
{- https://lists.chalmers.se/pipermail/agda/2013/006033.html http://code.haskell.org/~Saizan/unification/ 18-Nov-2013 Andrea Vezzosi -} module UnifyProof2 where open import Data.Fin using (Fin; suc; zero) open import Data.Nat hiding (_≤_) open import Relation.Binary.PropositionalEquality open import Function open import Relation.Nullary open import Data.Product renaming (map to _***_) open import Data.Empty open import Data.Maybe using (maybe; nothing; just; monad; Maybe) open import Data.Sum open import Unify open import UnifyProof open Σ₁ open import Data.List renaming (_++_ to _++L_) open ≡-Reasoning open import Category.Functor open import Category.Monad import Level open RawMonad (Data.Maybe.monad {Level.zero}) -- We use a view so that we need to handle fewer cases in the main proof data Amgu : {m : ℕ} -> (s t : Term m) -> ∃ (AList m) -> Maybe (∃ (AList m)) -> Set where Flip : ∀ {m s t acc} -> amgu t s acc ≡ amgu s t acc -> Amgu {m} t s acc (amgu t s acc) -> Amgu s t acc (amgu s t acc) leaf-leaf : ∀ {m acc} -> Amgu {m} leaf leaf acc (just acc) leaf-fork : ∀ {m s t acc} -> Amgu {m} leaf (s fork t) acc nothing fork-fork : ∀ {m s1 s2 t1 t2 acc} -> Amgu {m} (s1 fork s2) (t1 fork t2) acc (amgu s2 t2 =<< amgu s1 t1 acc) var-var : ∀ {m x y} -> Amgu (i x) (i y) (m , anil) (just (flexFlex x y)) var-t : ∀ {m x t} -> i x ≢ t -> Amgu (i x) t (m , anil) (flexRigid x t) s-t : ∀{m s t n σ r z} -> Amgu {suc m} s t (n , σ asnoc r / z) ((λ σ -> σ ∃asnoc r / z) <$> amgu ((r for z) ◃ s) ((r for z) ◃ t) (n , σ)) view : ∀ {m : ℕ} -> (s t : Term m) -> (acc : ∃ (AList m)) -> Amgu s t acc (amgu s t acc) view leaf leaf acc = leaf-leaf view leaf (s fork t) acc = leaf-fork view (s fork t) leaf acc = Flip refl leaf-fork view (s1 fork s2) (t1 fork t2) acc = fork-fork view (i x) (i y) (m , anil) = var-var view (i x) leaf (m , anil) = var-t (λ ()) view (i x) (s fork t) (m , anil) = var-t (λ ()) view leaf (i x) (m , anil) = Flip refl (var-t (λ ())) view (s fork t) (i x) (m , anil) = Flip refl (var-t (λ ())) view (i x) (i x') (n , σ asnoc r / z) = s-t view (i x) leaf (n , σ asnoc r / z) = s-t view (i x) (s fork t) (n , σ asnoc r / z) = s-t view leaf (i x) (n , σ asnoc r / z) = s-t view (s fork t) (i x) (n , σ asnoc r / z) = s-t amgu-Correctness : {m : ℕ} -> (s t : Term m) -> ∃ (AList m) -> Set amgu-Correctness s t (l , ρ) = (∃ λ n → ∃ λ σ → π₁ (Max (Unifies s t [-◇ sub ρ ])) (sub σ) × amgu s t (l , ρ) ≡ just (n , σ ++ ρ )) ⊎ (Nothing ((Unifies s t) [-◇ sub ρ ]) × amgu s t (l , ρ) ≡ nothing) amgu-Ccomm : ∀ {m} s t acc -> amgu {m} s t acc ≡ amgu t s acc -> amgu-Correctness s t acc -> amgu-Correctness t s acc amgu-Ccomm s t (l , ρ) st≡ts = lemma where Unst = (Unifies s t) [-◇ sub ρ ] Unts = (Unifies t s) [-◇ sub ρ ] Unst⇔Unts : ((Unifies s t) [-◇ sub ρ ]) ⇔ ((Unifies t s) [-◇ sub ρ ]) Unst⇔Unts = Properties.fact5 (Unifies s t) (Unifies t s) (sub ρ) (Properties.fact1 {_} {s} {t}) lemma : amgu-Correctness s t (l , ρ) -> amgu-Correctness t s (l , ρ) lemma (inj₁ (n , σ , MaxUnst , amgu≡just)) = inj₁ (n , σ , proj₁ (Max.fact Unst Unts Unst⇔Unts (sub σ)) MaxUnst , trans (sym st≡ts) amgu≡just) lemma (inj₂ (NoUnst , amgu≡nothing)) = inj₂ ((λ {_} → Properties.fact2 Unst Unts Unst⇔Unts NoUnst) , trans (sym st≡ts) amgu≡nothing) amgu-c : ∀ {m s t l ρ} -> Amgu s t (l , ρ) (amgu s t (l , ρ)) -> (∃ λ n → ∃ λ σ → π₁ (Max ((Unifies s t) [-◇ sub ρ ])) (sub σ) × amgu {m} s t (l , ρ) ≡ just (n , σ ++ ρ )) ⊎ (Nothing ((Unifies s t) [-◇ sub ρ ]) × amgu {m} s t (l , ρ) ≡ nothing) amgu-c {m} {s} {t} {l} {ρ} amg with amgu s t (l , ρ) amgu-c {l = l} {ρ} leaf-leaf | ._ = inj₁ (l , anil , trivial-problem {_} {_} {leaf} {sub ρ} , cong (λ x -> just (l , x)) (sym (SubList.anil-id-l ρ)) ) amgu-c leaf-fork | .nothing = inj₂ ((λ _ () ) , refl) amgu-c {m} {s1 fork s2} {t1 fork t2} {l} {ρ} fork-fork | ._ with amgu s1 t1 (l , ρ) | amgu-c $ view s1 t1 (l , ρ) ... | .nothing | inj₂ (nounify , refl) = inj₂ ((λ {_} -> No[Q◇ρ]→No[P◇ρ] No[Q◇ρ]) , refl) where P = Unifies (s1 fork s2) (t1 fork t2) Q = (Unifies s1 t1 ∧ Unifies s2 t2) Q⇔P : Q ⇔ P Q⇔P = switch P Q (Properties.fact1' {_} {s1} {s2} {t1} {t2}) No[Q◇ρ]→No[P◇ρ] : Nothing (Q [-◇ sub ρ ]) -> Nothing (P [-◇ sub ρ ]) No[Q◇ρ]→No[P◇ρ] = Properties.fact2 (Q [-◇ sub ρ ]) (P [-◇ sub ρ ]) (Properties.fact5 Q P (sub ρ) Q⇔P) No[Q◇ρ] : Nothing (Q [-◇ sub ρ ]) No[Q◇ρ] = failure-propagation.first (sub ρ) (Unifies s1 t1) (Unifies s2 t2) nounify ... | .(just (n , σ ++ ρ)) | inj₁ (n , σ , a , refl) with amgu s2 t2 (n , σ ++ ρ) | amgu-c (view s2 t2 (n , (σ ++ ρ))) ... | .nothing | inj₂ (nounify , refl) = inj₂ ( (λ {_} -> No[Q◇ρ]→No[P◇ρ] No[Q◇ρ]) , refl) where P = Unifies (s1 fork s2) (t1 fork t2) Q = (Unifies s1 t1 ∧ Unifies s2 t2) Q⇔P : Q ⇔ P Q⇔P = switch P Q (Properties.fact1' {_} {s1} {s2} {t1} {t2}) No[Q◇ρ]→No[P◇ρ] : Nothing (Q [-◇ sub ρ ]) -> Nothing (P [-◇ sub ρ ]) No[Q◇ρ]→No[P◇ρ] = Properties.fact2 (Q [-◇ sub ρ ]) (P [-◇ sub ρ ]) (Properties.fact5 Q P (sub ρ) Q⇔P) No[Q◇ρ] : Nothing (Q [-◇ sub ρ ]) No[Q◇ρ] = failure-propagation.second (sub ρ) (sub σ) (Unifies s1 t1) (Unifies s2 t2) a (λ f Unifs2t2-f◇σ◇ρ → nounify f (π₂ (Unifies s2 t2) (λ t → cong (f ◃) (sym (SubList.fact1 σ ρ t))) Unifs2t2-f◇σ◇ρ)) ... | .(just (n1 , σ1 ++ (σ ++ ρ))) | inj₁ (n1 , σ1 , b , refl) = inj₁ (n1 , σ1 ++ σ , Max[P∧Q◇ρ][σ1++σ] , cong (λ σ -> just (n1 , σ)) (++-assoc σ1 σ ρ)) where P = Unifies s1 t1 Q = Unifies s2 t2 P∧Q = P ∧ Q C = Unifies (s1 fork s2) (t1 fork t2) Max[C◇ρ]⇔Max[P∧Q◇ρ] : Max (C [-◇ sub ρ ]) ⇔ Max (P∧Q [-◇ sub ρ ]) Max[C◇ρ]⇔Max[P∧Q◇ρ] = Max.fact (C [-◇ sub ρ ]) (P∧Q [-◇ sub ρ ]) (Properties.fact5 C P∧Q (sub ρ) (Properties.fact1' {_} {s1} {s2} {t1} {t2})) Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] : Max (Q [-◇ sub (σ ++ ρ)]) ⇔ Max (Q [-◇ sub σ ◇ sub ρ ]) Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] = Max.fact (Q [-◇ sub (σ ++ ρ)]) (Q [-◇ sub σ ◇ sub ρ ]) (Properties.fact6 Q (SubList.fact1 σ ρ)) Max[P∧Q◇ρ][σ1++σ] : π₁ (Max (C [-◇ sub ρ ])) (sub (σ1 ++ σ)) Max[P∧Q◇ρ][σ1++σ] = π₂ (Max (C [-◇ sub ρ ])) (≐-sym (SubList.fact1 σ1 σ)) (proj₂ (Max[C◇ρ]⇔Max[P∧Q◇ρ] (sub σ1 ◇ sub σ)) (optimist (sub ρ) (sub σ) (sub σ1) P Q (DClosed.fact1 s1 t1) a (proj₁ (Max[Q◇σ++ρ]⇔Max[Q◇σ◇ρ] (sub σ1)) b))) amgu-c {suc l} {i x} {i y} (var-var) | .(just (flexFlex x y)) with thick x y | Thick.fact1 x y (thick x y) refl ... | .(just y') | inj₂ (y' , thinxy'≡y , refl ) = inj₁ (l , anil asnoc i y' / x , var-elim-i-≡ x (i y) (sym (cong i thinxy'≡y)) , refl ) ... | .nothing | inj₁ ( x≡y , refl ) rewrite sym x≡y = inj₁ (suc l , anil , trivial-problem {_} {_} {i x} {sub anil} , refl) amgu-c {suc l} {i x} {t} (var-t ix≢t) | .(flexRigid x t) with check x t | check-prop x t ... | .nothing | inj₂ ( ps , r , refl) = inj₂ ( (λ {_} -> No-Unifier ) , refl) where No-Unifier : {n : ℕ} (f : Fin (suc l) → Term n) → f x ≡ f ◃ t → ⊥ No-Unifier f fx≡f◃t = ix≢t (sym (trans r (cong (λ ps -> ps ⊹ i x) ps≡[]))) where ps≡[] : ps ≡ [] ps≡[] = map-[] f ps (No-Cycle (f x) ((f ◃S) ps) (begin f x ≡⟨ fx≡f◃t ⟩ f ◃ t ≡⟨ cong (f ◃) r ⟩ f ◃ (ps ⊹ i x) ≡⟨ StepM.fact2 f (i x) ps ⟩ (f ◃S) ps ⊹ f x ∎)) ... | .(just t') | inj₁ (t' , r , refl) = inj₁ ( l , anil asnoc t' / x , var-elim-i-≡ x t r , refl ) amgu-c {suc m} {s} {t} {l} {ρ asnoc r / z} s-t | .((λ x' → x' ∃asnoc r / z) <$> (amgu ((r for z) ◃ s) ((r for z) ◃ t) (l , ρ))) with amgu-c (view ((r for z) ◃ s) ((r for z) ◃ t) (l , ρ)) ... | inj₂ (nounify , ra) = inj₂ ( (λ {_} -> NoQ→NoP nounify) , cong (_<$>_ (λ x' → x' ∃asnoc r / z)) ra ) where P = Unifies s t [-◇ sub (ρ asnoc r / z) ] Q = Unifies ((r for z) ◃ s) ((r for z) ◃ t) [-◇ sub ρ ] NoQ→NoP : Nothing Q → Nothing P NoQ→NoP = Properties.fact2 Q P (switch P Q (step-prop s t ρ r z)) ... | inj₁ (n , σ , a , ra) = inj₁ (n , σ , proj₂ (MaxP⇔MaxQ (sub σ)) a , cong (_<$>_ (λ x' → x' ∃asnoc r / z)) ra) where P = Unifies s t [-◇ sub (ρ asnoc r / z) ] Q = Unifies ((r for z) ◃ s) ((r for z) ◃ t) [-◇ sub ρ ] MaxP⇔MaxQ : Max P ⇔ Max Q MaxP⇔MaxQ = Max.fact P Q (step-prop s t ρ r z) amgu-c {m} {s} {t} {l} {ρ} (Flip amguts≡amgust amguts) | ._ = amgu-Ccomm t s (l , ρ) amguts≡amgust (amgu-c amguts) amgu-c {zero} {i ()} _ | _ mgu-c : ∀ {m} (s t : Term m) -> (∃ λ n → ∃ λ σ → π₁ (Max (Unifies s t)) (sub σ) × mgu s t ≡ just (n , σ)) ⊎ (Nothing (Unifies s t) × mgu s t ≡ nothing) mgu-c {m} s t = amgu-c (view s t (m , anil))
algebraic-stack_agda0000_doc_17262
{-# OPTIONS --without-K #-} module sets.fin.ordering where open import equality.core open import function.isomorphism open import sets.core open import sets.fin.core open import sets.fin.properties import sets.nat.ordering as N _<_ : ∀ {n} → Fin n → Fin n → Set i < j = toℕ i N.< toℕ j infixr 4 _<_ ord-from-ℕ : ∀ {n} {i j : Fin n} → Ordering N._<_ (toℕ i) (toℕ j) → Ordering _<_ i j ord-from-ℕ (lt p) = lt p ord-from-ℕ (eq p) = eq (toℕ-inj p) ord-from-ℕ (gt p) = gt p compare : ∀ {n} → (i j : Fin n) → Ordering _<_ i j compare i j = ord-from-ℕ (N.compare (toℕ i) (toℕ j))
algebraic-stack_agda0000_doc_17263
module ComplexIMPORT where {-# IMPORT Prelude as P #-}
algebraic-stack_agda0000_doc_16960
module Impure.STLCRef.Properties.Soundness where open import Data.Nat open import Data.Sum open import Data.Product as Pr open import Data.List open import Data.Vec hiding (_∷ʳ_) open import Data.Star open import Function open import Extensions.List open import Relation.Binary.PropositionalEquality as P open import Relation.Binary.Core using (REL; Reflexive) open import Relation.Binary.List.Pointwise as PRel hiding (refl) open import Impure.STLCRef.Syntax hiding (id) open import Impure.STLCRef.Welltyped open import Impure.STLCRef.Eval ref-value-lemma : ∀ {n A Γ Σ} {e : Exp n} → Γ , Σ ⊢ e ∶ Ref A → Val e → ∃ λ i → e ≡ (loc i) ref-value-lemma (var x) () ref-value-lemma (loc p) (loc i) = i , refl ref-value-lemma (p · p₁) () ref-value-lemma (ref p) () ref-value-lemma (! p) () progress : ∀ {Γ Σ A} {e : Exp 0} {μ} → Γ , Σ ⊢ μ → Γ , Σ ⊢ e ∶ A → -------------------------------------- Val e ⊎ ∃₂ λ e' μ' → (e , μ ≻ e' , μ') progress p unit = inj₁ unit progress p (var ()) progress p (loc {i = i} q) = inj₁ (loc i) progress p (ƛ wt) = inj₁ (ƛ _ _) progress p (f · e) with progress p f progress p (() · e) | inj₁ unit progress p (() · e) | inj₁ (loc i) progress p (ƛ f · e) | inj₁ (ƛ _ _) = inj₂ (_ , (_ , AppAbs)) progress p (f · e) | inj₂ (_ , _ , f≻f') = inj₂ (_ , (_ , (Appₗ f≻f'))) progress p (ref wt) with progress p wt progress p (ref wt) | inj₁ v = inj₂ (_ , (_ , (RefVal v))) progress p (ref wt) | inj₂ (_ , _ , wt≻wt') = inj₂ (_ , _ , Ref wt≻wt') progress p (! wt) with progress p wt progress p (! wt) | inj₁ v with ref-value-lemma wt v progress p (! loc q) | inj₁ (loc .i) | (i , refl) = inj₂ (_ , (_ , (DerefLoc (P.subst (_<_ _) (pointwise-length p) ([]=-length q))))) progress p (! wt) | inj₂ (_ , _ , wt≻wt') = inj₂ (_ , (_ , (Deref wt≻wt'))) progress p (wt ≔ x) with progress p wt | progress p x progress p (wt ≔ x) | _ | inj₂ (_ , _ , x≻x') = inj₂ (_ , (_ , (Assign₂ x≻x'))) progress p (wt ≔ x) | inj₂ (_ , _ , wt≻wt') | _ = inj₂ (_ , _ , Assign₁ wt≻wt') progress p (wt ≔ x) | inj₁ v | inj₁ w with ref-value-lemma wt v progress p (loc q ≔ x) | inj₁ (loc .i) | inj₁ w | (i , refl) = inj₂ (_ , (_ , Assign (P.subst (_<_ _) (pointwise-length p) ([]=-length q)) w)) postulate sub-preserves : ∀ {n Γ Σ A B x} {e : Exp (suc n)} → (B ∷ Γ) , Σ ⊢ e ∶ A → Γ , Σ ⊢ x ∶ B → Γ , Σ ⊢ (e / sub x) ∶ A !!-loc : ∀ {n Σ Σ' A μ i} {Γ : Ctx n} → Rel (λ A x → Γ , Σ ⊢ proj₁ x ∶ A) Σ' μ → Σ' ⊢loc i ∶ A → (l : i < length μ) → Γ , Σ ⊢ proj₁ (μ !! l) ∶ A !!-loc [] () !!-loc (x∼y ∷ p) here (s≤s z≤n) = x∼y !!-loc (x∼y ∷ p) (there q) (s≤s l) = !!-loc p q l -- extending the store preserves expression typings ⊒-preserves : ∀ {n Γ Σ Σ' A} {e : Exp n} → Σ' ⊒ Σ → Γ , Σ ⊢ e ∶ A → Γ , Σ' ⊢ e ∶ A ⊒-preserves ext unit = unit ⊒-preserves ext (var x) = var x ⊒-preserves ext (loc x) = loc (xs⊒ys[i] x ext) ⊒-preserves ext (ƛ p) = ƛ (⊒-preserves ext p) ⊒-preserves ext (p · q) = (⊒-preserves ext p) · ⊒-preserves ext q ⊒-preserves ext (ref p) = ref (⊒-preserves ext p) ⊒-preserves ext (! p) = ! (⊒-preserves ext p) ⊒-preserves ext (p ≔ q) = (⊒-preserves ext p) ≔ (⊒-preserves ext q) ≻-preserves : ∀ {n Γ Σ A} {e : Exp n} {e' μ' μ} → Γ , Σ ⊢ e ∶ A → Γ , Σ ⊢ μ → e , μ ≻ e' , μ' → --------------------------------- ∃ λ Σ' → Γ , Σ' ⊢ e' ∶ A × Σ' ⊒ Σ × Γ , Σ' ⊢ μ' ≻-preserves unit p () ≻-preserves (var x) p () ≻-preserves (loc p) p₁ () ≻-preserves (ƛ wt) p () ≻-preserves {Σ = Σ} (ƛ wt · wt₁) p AppAbs = Σ , sub-preserves wt wt₁ , ⊑-refl , p ≻-preserves {Σ = Σ} (ref {x = x} {A} wt) p (RefVal v) = let ext = ∷ʳ-⊒ A Σ in Σ ∷ʳ A , loc (P.subst (λ i → _ ⊢loc i ∶ _) (pointwise-length p) (∷ʳ[length] Σ A)) , ext , pointwise-∷ʳ (PRel.map (⊒-preserves ext) p) (⊒-preserves ext wt) ≻-preserves {Σ = Σ₁} (! loc x) p (DerefLoc l) = Σ₁ , !!-loc p x l , ⊑-refl , p ≻-preserves {Σ = Σ₁} (loc x ≔ y) p (Assign l v) = Σ₁ , unit , ⊑-refl , pointwise-[]≔ p x l y -- contextual closure ≻-preserves {Σ = Σ} (wt-f · wt-x) p (Appₗ r) = Pr.map id (λ{ (wt-f' , ext , q) → wt-f' · ⊒-preserves ext wt-x , ext , q}) (≻-preserves wt-f p r) ≻-preserves (f · x) p (Appᵣ r) = Pr.map id (λ{ (x' , ext , q) → ⊒-preserves ext f · x' , ext , q}) (≻-preserves x p r) ≻-preserves (ref wt) p (Ref r) = Pr.map id (λ{ (wt' , ext) → ref wt' , ext}) (≻-preserves wt p r) ≻-preserves (! wt) p (Deref r) = Pr.map id (λ{ (wt' , ext) → ! wt' , ext}) (≻-preserves wt p r) ≻-preserves (y ≔ x) p (Assign₁ r) = Pr.map id (λ{ (y' , ext , q) → y' ≔ ⊒-preserves ext x , ext , q}) (≻-preserves y p r) ≻-preserves (y ≔ x) p (Assign₂ r) = Pr.map id (λ{ (x' , ext , q) → ⊒-preserves ext y ≔ x' , ext , q}) (≻-preserves x p r) -- preservation for multistep reductions preservation : ∀ {n} {e : Exp n} {Γ Σ A μ μ' e'} → Γ , Σ ⊢ e ∶ A → Γ , Σ ⊢ μ → e , μ ≻* e' , μ' → ----------------------------------------------- ∃ λ Σ' → Γ , Σ' ⊢ e' ∶ A × Σ' ⊒ Σ × Γ , Σ' ⊢ μ' preservation wt ok ε = _ , wt , ⊑-refl , ok preservation wt ok (x ◅ r) with ≻-preserves wt ok x ... | Σ₂ , wt' , Σ₂⊒Σ , μ₂ok with preservation wt' μ₂ok r ... | Σ₃ , wt'' , Σ₃⊒Σ₂ , μ₃ = Σ₃ , wt'' , ⊑-trans Σ₂⊒Σ Σ₃⊒Σ₂ , μ₃ -- fueled evaluation open import Data.Maybe eval : ∀ {e : Exp zero} {Σ A μ} ℕ → [] , Σ ⊢ e ∶ A → [] , Σ ⊢ μ → --------------------------------------- Maybe (∃ λ Σ' → ∃ λ e' → ∃ λ μ' → (e , μ ≻* e' , μ') × Val e' × ([] , Σ' ⊢ e' ∶ A)) eval 0 _ _ = nothing eval (suc n) p q with progress q p eval (suc n) p q | inj₁ x = just (_ , _ , _ , ε , x , p) eval (suc n) p q | inj₂ (e' , μ' , step) with ≻-preserves p q step ... | (Σ₂ , wte' , ext , μ'-ok) with eval n wte' μ'-ok ... | nothing = nothing ... | just (Σ₃ , e'' , μ'' , steps , v , wte'') = just (Σ₃ , e'' , μ'' , step ◅ steps , v , wte'')
algebraic-stack_agda0000_doc_16961
{-# OPTIONS --without-K --safe #-} module Categories.Adjoint.Alternatives where open import Level open import Categories.Adjoint open import Categories.Category open import Categories.Functor renaming (id to idF) open import Categories.NaturalTransformation import Categories.Morphism.Reasoning as MR private variable o ℓ e : Level C D : Category o ℓ e module _ (L : Functor C D) (R : Functor D C) where private module C = Category C module D = Category D module L = Functor L module R = Functor R record FromUnit : Set (levelOfTerm L ⊔ levelOfTerm R) where field unit : NaturalTransformation idF (R ∘F L) module unit = NaturalTransformation unit field θ : ∀ {X Y} → C [ X , R.₀ Y ] → D [ L.₀ X , Y ] commute : ∀ {X Y} (g : C [ X , R.₀ Y ]) → g C.≈ R.₁ (θ g) C.∘ unit.η X unique : ∀ {X Y} {f : D [ L.₀ X , Y ]} {g : C [ X , R.₀ Y ]} → g C.≈ R.₁ f C.∘ unit.η X → θ g D.≈ f module _ where open C.HomReasoning open MR C θ-natural : ∀ {X Y Z} (f : D [ Y , Z ]) (g : C [ X , R.₀ Y ]) → θ (R.₁ f C.∘ g) D.≈ θ (R.₁ f) D.∘ L.₁ g θ-natural {X} {Y} f g = unique eq where eq : R.₁ f C.∘ g C.≈ R.₁ (θ (R.₁ f) D.∘ L.₁ g) C.∘ unit.η X eq = begin R.₁ f C.∘ g ≈⟨ commute (R.₁ f) ⟩∘⟨refl ⟩ (R.₁ (θ (R.₁ f)) C.∘ unit.η (R.F₀ Y)) C.∘ g ≈⟨ C.assoc ⟩ R.₁ (θ (R.₁ f)) C.∘ unit.η (R.₀ Y) C.∘ g ≈⟨ pushʳ (unit.commute g) ⟩ (R.₁ (θ (R.₁ f)) C.∘ R.₁ (L.₁ g)) C.∘ unit.η X ≈˘⟨ R.homomorphism ⟩∘⟨refl ⟩ R.₁ (θ (R.₁ f) D.∘ L.₁ g) C.∘ unit.η X ∎ θ-cong : ∀ {X Y} {f g : C [ X , R.₀ Y ]} → f C.≈ g → θ f D.≈ θ g θ-cong eq = unique (eq ○ commute _) θ-natural′ : ∀ {X Y} (g : C [ X , R.₀ Y ]) → θ g D.≈ θ C.id D.∘ L.₁ g θ-natural′ g = θ-cong (introˡ R.identity) ○ θ-natural D.id g ○ D.∘-resp-≈ˡ (θ-cong R.identity) where open D.HomReasoning open MR C counit : NaturalTransformation (L ∘F R) idF counit = ntHelper record { η = λ d → θ C.id ; commute = λ f → begin θ C.id D.∘ L.₁ (R.₁ f) ≈˘⟨ θ-natural′ (R.₁ f) ⟩ θ (R.₁ f) ≈⟨ unique (CH.⟺ (MR.cancelʳ C (CH.⟺ (commute C.id))) CH.○ CH.⟺ (C.∘-resp-≈ˡ R.homomorphism)) ⟩ f D.∘ θ C.id ∎ } where open D.HomReasoning module CH = C.HomReasoning unique′ : ∀ {X Y} {f g : D [ L.₀ X , Y ]} (h : C [ X , R.₀ Y ]) → h C.≈ R.₁ f C.∘ unit.η X → h C.≈ R.₁ g C.∘ unit.η X → f D.≈ g unique′ _ eq₁ eq₂ = ⟺ (unique eq₁) ○ unique eq₂ where open D.HomReasoning zig : ∀ {A} → θ C.id D.∘ L.F₁ (unit.η A) D.≈ D.id zig {A} = unique′ (unit.η A) (commute (unit.η A) ○ (C.∘-resp-≈ˡ (R.F-resp-≈ (θ-natural′ (unit.η A))))) (introˡ R.identity) where open C.HomReasoning open MR C L⊣R : L ⊣ R L⊣R = record { unit = unit ; counit = counit ; zig = zig ; zag = C.Equiv.sym (commute C.id) } record FromCounit : Set (levelOfTerm L ⊔ levelOfTerm R) where field counit : NaturalTransformation (L ∘F R) idF module counit = NaturalTransformation counit field θ : ∀ {X Y} → D [ L.₀ X , Y ] → C [ X , R.₀ Y ] commute : ∀ {X Y} (g : D [ L.₀ X , Y ]) → g D.≈ counit.η Y D.∘ L.₁ (θ g) unique : ∀ {X Y} {f : C [ X , R.₀ Y ]} {g : D [ L.₀ X , Y ]} → g D.≈ counit.η Y D.∘ L.₁ f → θ g C.≈ f module _ where open D.HomReasoning open MR D θ-natural : ∀ {X Y Z} (f : C [ X , Y ]) (g : D [ L.₀ Y , Z ]) → θ (g D.∘ L.₁ f) C.≈ R.₁ g C.∘ θ (L.₁ f) θ-natural {X} {Y} {Z} f g = unique eq where eq : g D.∘ L.₁ f D.≈ counit.η Z D.∘ L.₁ (R.₁ g C.∘ θ (L.₁ f)) eq = begin g D.∘ L.₁ f ≈⟨ pushʳ (commute (L.₁ f)) ⟩ (g D.∘ counit.η (L.F₀ Y)) D.∘ L.F₁ (θ (L.F₁ f)) ≈⟨ pushˡ (counit.sym-commute g) ⟩ counit.η Z D.∘ L.₁ (R.₁ g) D.∘ L.₁ (θ (L.₁ f)) ≈˘⟨ refl⟩∘⟨ L.homomorphism ⟩ counit.η Z D.∘ L.₁ (R.₁ g C.∘ θ (L.₁ f)) ∎ θ-cong : ∀ {X Y} {f g : D [ L.₀ X , Y ]} → f D.≈ g → θ f C.≈ θ g θ-cong eq = unique (eq ○ commute _) θ-natural′ : ∀ {X Y} (g : D [ L.₀ X , Y ]) → θ g C.≈ R.₁ g C.∘ θ D.id θ-natural′ g = θ-cong (introʳ L.identity) ○ θ-natural C.id g ○ C.∘-resp-≈ʳ (θ-cong L.identity) where open C.HomReasoning open MR D unit : NaturalTransformation idF (R ∘F L) unit = ntHelper record { η = λ _ → θ D.id ; commute = λ f → begin θ D.id C.∘ f ≈˘⟨ unique (DH.⟺ (cancelˡ (DH.⟺ (commute D.id))) DH.○ D.∘-resp-≈ʳ (DH.⟺ L.homomorphism)) ⟩ θ (L.₁ f) ≈⟨ θ-natural′ (L.₁ f) ⟩ R.₁ (L.₁ f) C.∘ θ D.id ∎ } where open C.HomReasoning module DH = D.HomReasoning open MR D unique′ : ∀ {X Y} {f g : C [ X , R.₀ Y ]} (h : D [ L.₀ X , Y ]) → h D.≈ counit.η Y D.∘ L.₁ f → h D.≈ counit.η Y D.∘ L.₁ g → f C.≈ g unique′ _ eq₁ eq₂ = ⟺ (unique eq₁) ○ unique eq₂ where open C.HomReasoning zag : ∀ {B} → R.F₁ (counit.η B) C.∘ θ D.id C.≈ C.id zag {B} = unique′ (counit.η B) (⟺ (cancelʳ (⟺ (commute D.id))) ○ pushˡ (counit.sym-commute (counit.η B)) ○ D.∘-resp-≈ʳ (⟺ L.homomorphism)) (introʳ L.identity) where open D.HomReasoning open MR D L⊣R : L ⊣ R L⊣R = record { unit = unit ; counit = counit ; zig = D.Equiv.sym (commute D.id) ; zag = zag } module _ {L : Functor C D} {R : Functor D C} where fromUnit : FromUnit L R → L ⊣ R fromUnit = FromUnit.L⊣R fromCounit : FromCounit L R → L ⊣ R fromCounit = FromCounit.L⊣R
algebraic-stack_agda0000_doc_16962
-- Trying to define ≤ as a datatype in Prop doesn't work very well: {-# OPTIONS --enable-prop #-} open import Agda.Builtin.Nat data _≤'_ : Nat → Nat → Prop where zero : (y : Nat) → zero ≤' y suc : (x y : Nat) → x ≤' y → suc x ≤' suc y ≤'-ind : (P : (m n : Nat) → Set) → (pzy : (y : Nat) → P zero y) → (pss : (x y : Nat) → P x y → P (suc x) (suc y)) → (m n : Nat) → m ≤' n → P m n ≤'-ind P pzy pss .0 y (zero .y) = ? ≤'-ind P pzy pss .(suc x) .(suc y) (suc x y pf) = ?
algebraic-stack_agda0000_doc_16963
module Lookup where data Bool : Set where false : Bool true : Bool data IsTrue : Bool -> Set where isTrue : IsTrue true data List (A : Set) : Set where [] : List A _::_ : A -> List A -> List A data _×_ (A B : Set) : Set where _,_ : A -> B -> A × B module Map (Key : Set) (_==_ : Key -> Key -> Bool) (Code : Set) (Val : Code -> Set) where infixr 40 _⟼_,_ infix 20 _∈_ data Map : List Code -> Set where ε : Map [] _⟼_,_ : forall {c cs} -> Key -> Val c -> Map cs -> Map (c :: cs) _∈_ : forall {cs} -> Key -> Map cs -> Bool k ∈ ε = false k ∈ (k' ⟼ _ , m) with k == k' ... | true = true ... | false = k ∈ m Lookup : forall {cs} -> (k : Key)(m : Map cs) -> IsTrue (k ∈ m) -> Set Lookup k ε () Lookup k (_⟼_,_ {c} k' _ m) p with k == k' ... | true = Val c ... | false = Lookup k m p lookup : {cs : List Code}(k : Key)(m : Map cs)(p : IsTrue (k ∈ m)) -> Lookup k m p lookup k ε () lookup k (k' ⟼ v , m) p with k == k' ... | true = v ... | false = lookup k m p
algebraic-stack_agda0000_doc_16964
-- Andreas, 2014-03-05, reported by xcycl.xoo, Mar 30, 2009 -- {-# OPTIONS -v tc.with:60 #-} open import Common.Prelude renaming (Nat to ℕ; module Nat to ℕ) data Nat : ℕ → Set where i : (k : ℕ) → Nat k toNat : (n : ℕ) → Nat n toNat n = i n fun : (n : ℕ) → ℕ fun n with toNat n fun .m | i m with toNat m fun .Set | i .l | i l = 0 -- 'Set' is ill-typed here and should trigger an error FORCE_FAIL_HERE_UNTIL_ISSUE_142_IS_REALLY_FIXED
algebraic-stack_agda0000_doc_16965
id : Set → Set id A = A
algebraic-stack_agda0000_doc_16966
------------------------------------------------------------------------ -- INCREMENTAL λ-CALCULUS -- -- Correctness of differentiation with the Nehemiah plugin. ------------------------------------------------------------------------ module Nehemiah.Change.Correctness where -- The denotational properties of the `derive` transformation -- for Calculus Nehemiah. In particular, the main theorem -- about it producing the correct incremental behavior. open import Nehemiah.Syntax.Type open import Nehemiah.Syntax.Term open import Nehemiah.Denotation.Value open import Nehemiah.Denotation.Evaluation open import Nehemiah.Change.Type open import Nehemiah.Change.Term open import Nehemiah.Change.Value open import Nehemiah.Change.Evaluation open import Nehemiah.Change.Validity open import Nehemiah.Change.Derive open import Nehemiah.Change.Implementation open import Base.Denotation.Notation open import Relation.Binary.PropositionalEquality open import Data.Integer open import Theorem.Groups-Nehemiah open import Postulate.Extensionality import Parametric.Change.Correctness Const ⟦_⟧Base ⟦_⟧Const ΔBase apply-base diff-base nil-base ⟦apply-base⟧ ⟦diff-base⟧ ⟦nil-base⟧ meaning-⊕-base meaning-⊝-base meaning-onil-base derive-const implementation-structure as Correctness open import Algebra.Structures private flatmap-funarg-equal : ∀ (f : ℤ → Bag) (Δf : Δ₍ int ⇒ bag ₎ f) Δf′ (Δf≈Δf′ : Δf ≈₍ int ⇒ bag ₎ Δf′) → (f ⊞₍ int ⇒ bag ₎ Δf) ≡ (f ⟦⊕₍ int ⇒ bag ₎⟧ Δf′) flatmap-funarg-equal f Δf Δf′ Δf≈Δf′ = ext lemma where lemma : ∀ v → f v ++ FunctionChange.apply Δf v (+ 0) ≡ f v ++ Δf′ v (+ 0) lemma v rewrite Δf≈Δf′ v (+ 0) (+ 0) refl = refl derive-const-correct : Correctness.Structure derive-const-correct (intlit-const n) = refl derive-const-correct add-const w Δw .Δw refl w₁ Δw₁ .Δw₁ refl rewrite mn·pq=mp·nq {w} {Δw} {w₁} {Δw₁} | associative-int (w + w₁) (Δw + Δw₁) (- (w + w₁)) = n+[m-n]=m {w + w₁} {Δw + Δw₁} derive-const-correct minus-const w Δw .Δw refl rewrite sym (-m·-n=-mn {w} {Δw}) | associative-int (- w) (- Δw) (- (- w)) = n+[m-n]=m { - w} { - Δw} derive-const-correct empty-const = refl derive-const-correct insert-const w Δw .Δw refl w₁ Δw₁ .Δw₁ refl = refl derive-const-correct union-const w Δw .Δw refl w₁ Δw₁ .Δw₁ refl rewrite ab·cd=ac·bd {w} {Δw} {w₁} {Δw₁} | associative-bag (w ++ w₁) (Δw ++ Δw₁) (negateBag (w ++ w₁)) = a++[b\\a]=b {w ++ w₁} {Δw ++ Δw₁} derive-const-correct negate-const w Δw .Δw refl rewrite sym (-a·-b=-ab {w} {Δw}) | associative-bag (negateBag w) (negateBag Δw) (negateBag (negateBag w)) = a++[b\\a]=b {negateBag w} {negateBag Δw} derive-const-correct flatmap-const w Δw Δw′ Δw≈Δw′ w₁ Δw₁ .Δw₁ refl rewrite flatmap-funarg-equal w Δw Δw′ Δw≈Δw′ = refl derive-const-correct sum-const w Δw .Δw refl rewrite homo-sum {w} {Δw} | associative-int (sumBag w) (sumBag Δw) (- sumBag w) = n+[m-n]=m {sumBag w} {sumBag Δw} open Correctness.Structure derive-const-correct public
algebraic-stack_agda0000_doc_16967
{-# OPTIONS --safe --warning=error --without-K #-} open import Groups.Definition open import Setoids.Setoids open import Sets.EquivalenceRelations open import Groups.Homomorphisms.Definition open import Groups.Homomorphisms.Lemmas open import Groups.Subgroups.Definition open import Groups.Lemmas open import Groups.Abelian.Definition open import Groups.Subgroups.Normal.Definition open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) module Groups.Subgroups.Normal.Lemmas where data GroupKernelElement {a} {b} {c} {d} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) : Set (a ⊔ b ⊔ c ⊔ d) where kerOfElt : (x : A) → (Setoid._∼_ T (f x) (Group.0G H)) → GroupKernelElement G hom groupKernel : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → Setoid (GroupKernelElement G hom) Setoid._∼_ (groupKernel {S = S} G {H} {f} fHom) (kerOfElt x fx=0) (kerOfElt y fy=0) = Setoid._∼_ S x y Equivalence.reflexive (Setoid.eq (groupKernel {S = S} G {H} {f} fHom)) {kerOfElt x x₁} = Equivalence.reflexive (Setoid.eq S) Equivalence.symmetric (Setoid.eq (groupKernel {S = S} G {H} {f} fHom)) {kerOfElt x prX} {kerOfElt y prY} = Equivalence.symmetric (Setoid.eq S) Equivalence.transitive (Setoid.eq (groupKernel {S = S} G {H} {f} fHom)) {kerOfElt x prX} {kerOfElt y prY} {kerOfElt z prZ} = Equivalence.transitive (Setoid.eq S) groupKernelGroupOp : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → (GroupKernelElement G hom) → (GroupKernelElement G hom) → (GroupKernelElement G hom) groupKernelGroupOp {T = T} {_·A_ = _+A_} G {H = H} hom (kerOfElt x prX) (kerOfElt y prY) = kerOfElt (x +A y) (transitive (GroupHom.groupHom hom) (transitive (Group.+WellDefined H prX prY) (Group.identLeft H))) where open Setoid T open Equivalence eq groupKernelGroup : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → Group (groupKernel G hom) (groupKernelGroupOp G hom) Group.+WellDefined (groupKernelGroup G fHom) {kerOfElt x prX} {kerOfElt y prY} {kerOfElt a prA} {kerOfElt b prB} = Group.+WellDefined G Group.0G (groupKernelGroup G fHom) = kerOfElt (Group.0G G) (imageOfIdentityIsIdentity fHom) Group.inverse (groupKernelGroup {T = T} G {H = H} fHom) (kerOfElt x prX) = kerOfElt (Group.inverse G x) (transitive (homRespectsInverse fHom) (transitive (inverseWellDefined H prX) (invIdent H))) where open Setoid T open Equivalence eq Group.+Associative (groupKernelGroup {S = S} {_·A_ = _·A_} G fHom) {kerOfElt x prX} {kerOfElt y prY} {kerOfElt z prZ} = Group.+Associative G Group.identRight (groupKernelGroup G fHom) {kerOfElt x prX} = Group.identRight G Group.identLeft (groupKernelGroup G fHom) {kerOfElt x prX} = Group.identLeft G Group.invLeft (groupKernelGroup G fHom) {kerOfElt x prX} = Group.invLeft G Group.invRight (groupKernelGroup G fHom) {kerOfElt x prX} = Group.invRight G injectionFromKernelToG : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → GroupKernelElement G hom → A injectionFromKernelToG G hom (kerOfElt x _) = x injectionFromKernelToGIsHom : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → GroupHom (groupKernelGroup G hom) G (injectionFromKernelToG G hom) GroupHom.groupHom (injectionFromKernelToGIsHom {S = S} G hom) {kerOfElt x prX} {kerOfElt y prY} = Equivalence.reflexive (Setoid.eq S) GroupHom.wellDefined (injectionFromKernelToGIsHom G hom) {kerOfElt x prX} {kerOfElt y prY} i = i groupKernelGroupPred : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → A → Set d groupKernelGroupPred {T = T} G {H = H} {f = f} hom a = Setoid._∼_ T (f a) (Group.0G H) groupKernelGroupPredWd : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → {x y : A} → (Setoid._∼_ S x y) → (groupKernelGroupPred G hom x → groupKernelGroupPred G hom y) groupKernelGroupPredWd {S = S} {T = T} G hom {x} {y} x=y fx=0 = Equivalence.transitive (Setoid.eq T) (GroupHom.wellDefined hom (Equivalence.symmetric (Setoid.eq S) x=y)) fx=0 groupKernelGroupIsSubgroup : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → Subgroup G (groupKernelGroupPred G hom) Subgroup.closedUnderPlus (groupKernelGroupIsSubgroup {S = S} {T = T} G {H = H} hom) g=0 h=0 = Equivalence.transitive (Setoid.eq T) (GroupHom.groupHom hom) (Equivalence.transitive (Setoid.eq T) (Group.+WellDefined H g=0 h=0) (Group.identLeft H)) Subgroup.containsIdentity (groupKernelGroupIsSubgroup G hom) = imageOfIdentityIsIdentity hom Subgroup.closedUnderInverse (groupKernelGroupIsSubgroup {S = S} {T = T} G {H = H} hom) g=0 = Equivalence.transitive (Setoid.eq T) (homRespectsInverse hom) (Equivalence.transitive (Setoid.eq T) (inverseWellDefined H g=0) (invIdent H)) Subgroup.isSubset (groupKernelGroupIsSubgroup G hom) = groupKernelGroupPredWd G hom groupKernelGroupIsNormalSubgroup : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → normalSubgroup G (groupKernelGroupIsSubgroup G hom) groupKernelGroupIsNormalSubgroup {T = T} G {H = H} hom k=0 = transitive groupHom (transitive (+WellDefined reflexive groupHom) (transitive (+WellDefined reflexive (transitive (+WellDefined k=0 reflexive) identLeft)) (transitive (symmetric groupHom) (transitive (wellDefined (Group.invRight G)) (imageOfIdentityIsIdentity hom))))) where open Setoid T open Group H open Equivalence eq open GroupHom hom abelianGroupSubgroupIsNormal : {a b c : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {G : Group S _+_} {pred : A → Set c} → (s : Subgroup G pred) → AbelianGroup G → normalSubgroup G s abelianGroupSubgroupIsNormal {S = S} {_+_ = _+_} {G = G} record { isSubset = predWd ; closedUnderPlus = respectsPlus ; containsIdentity = respectsId ; closedUnderInverse = respectsInv } abelian {k} {l} prK = predWd (transitive (transitive (transitive (symmetric identLeft) (+WellDefined (symmetric invRight) reflexive)) (symmetric +Associative)) (+WellDefined reflexive commutative)) prK where open Group G open AbelianGroup abelian open Setoid S open Equivalence eq
algebraic-stack_agda0000_doc_16968
{-# OPTIONS --without-K --rewriting #-} open import lib.Basics open import lib.types.Bool open import lib.types.Empty open import lib.types.Lift open import lib.types.Sigma open import lib.types.Pi module lib.types.Coproduct where module _ {i j} {A : Type i} {B : Type j} where Coprod-elim : ∀ {k} {C : A ⊔ B → Type k} → ((a : A) → C (inl a)) → ((b : B) → C (inr b)) → Π (A ⊔ B) C Coprod-elim f g (inl a) = f a Coprod-elim f g (inr b) = g b ⊔-elim = Coprod-elim Coprod-rec : ∀ {k} {C : Type k} → (A → C) → (B → C) → (A ⊔ B → C) Coprod-rec {C = C} = Coprod-elim {C = λ _ → C} ⊔-rec = Coprod-rec Coprod= : Coprod A B → Coprod A B → Type (lmax i j) Coprod= (inl a₁) (inl a₂) = Lift {j = (lmax i j)} $ a₁ == a₂ Coprod= (inl a₁) (inr b₂) = Lift Empty Coprod= (inr b₁) (inl a₂) = Lift Empty Coprod= (inr b₁) (inr b₂) = Lift {j = (lmax i j)} $ b₁ == b₂ Coprod=-in : {x y : Coprod A B} → (x == y) → Coprod= x y Coprod=-in {inl _} idp = lift idp Coprod=-in {inr _} idp = lift idp Coprod=-out : {x y : Coprod A B} → Coprod= x y → (x == y) Coprod=-out {inl _} {inl _} c = ap inl $ lower c Coprod=-out {inl _} {inr _} c = Empty-rec $ lower c Coprod=-out {inr _} {inl _} c = Empty-rec $ lower c Coprod=-out {inr _} {inr _} c = ap inr (lower c) Coprod=-in-equiv : (x y : Coprod A B) → (x == y) ≃ Coprod= x y Coprod=-in-equiv x y = equiv Coprod=-in Coprod=-out (f-g x y) (g-f x y) where f-g : ∀ x' y' → ∀ c → Coprod=-in (Coprod=-out {x'} {y'} c) == c f-g (inl a₁) (inl .a₁) (lift idp) = idp f-g (inl a₁) (inr b₂) b = Empty-rec $ lower b f-g (inr b₁) (inl a₂) b = Empty-rec $ lower b f-g (inr b₁) (inr .b₁) (lift idp) = idp g-f : ∀ x' y' → ∀ p → Coprod=-out (Coprod=-in {x'} {y'} p) == p g-f (inl _) .(inl _) idp = idp g-f (inr _) .(inr _) idp = idp inl=inl-equiv : (a₁ a₂ : A) → (inl a₁ == inl a₂) ≃ (a₁ == a₂) inl=inl-equiv a₁ a₂ = lower-equiv ∘e Coprod=-in-equiv (inl a₁) (inl a₂) inr=inr-equiv : (b₁ b₂ : B) → (inr b₁ == inr b₂) ≃ (b₁ == b₂) inr=inr-equiv b₁ b₂ = lower-equiv ∘e Coprod=-in-equiv (inr b₁) (inr b₂) inl≠inr : (a₁ : A) (b₂ : B) → (inl a₁ ≠ inr b₂) inl≠inr a₁ b₂ p = lower $ Coprod=-in p inr≠inl : (b₁ : B) (a₂ : A) → (inr b₁ ≠ inl a₂) inr≠inl a₁ b₂ p = lower $ Coprod=-in p instance ⊔-level : ∀ {n} → has-level (S (S n)) A → has-level (S (S n)) B → has-level (S (S n)) (Coprod A B) ⊔-level {n} pA pB = has-level-in (⊔-level-aux pA pB) where instance _ = pA; _ = pB ⊔-level-aux : has-level (S (S n)) A → has-level (S (S n)) B → has-level-aux (S (S n)) (Coprod A B) ⊔-level-aux _ _ (inl a₁) (inl a₂) = equiv-preserves-level (inl=inl-equiv a₁ a₂ ⁻¹) ⊔-level-aux _ _ (inl a₁) (inr b₂) = has-level-in (λ p → Empty-rec (inl≠inr a₁ b₂ p)) ⊔-level-aux _ _ (inr b₁) (inl a₂) = has-level-in (λ p → Empty-rec (inr≠inl b₁ a₂ p)) ⊔-level-aux _ _ (inr b₁) (inr b₂) = equiv-preserves-level ((inr=inr-equiv b₁ b₂)⁻¹) Coprod-level = ⊔-level module _ {i j} {A : Type i} {B : Type j} where Coprod-rec-post∘ : ∀ {k l} {C : Type k} {D : Type l} → (h : C → D) (f : A → C) (g : B → C) → h ∘ Coprod-rec f g ∼ Coprod-rec (h ∘ f) (h ∘ g) Coprod-rec-post∘ h f g (inl _) = idp Coprod-rec-post∘ h f g (inr _) = idp ⊔-rec-post∘ = Coprod-rec-post∘ module _ {i i' j j'} {A : Type i} {A' : Type i'} {B : Type j} {B' : Type j'} (f : A → A') (g : B → B') where ⊔-fmap : A ⊔ B → A' ⊔ B' ⊔-fmap (inl a) = inl (f a) ⊔-fmap (inr b) = inr (g b) infix 80 _⊙⊔_ _⊙⊔_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j) X ⊙⊔ Y = ⊙[ Coprod (de⊙ X) (de⊙ Y) , inl (pt X) ] _⊔⊙_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j) X ⊔⊙ Y = ⊙[ Coprod (de⊙ X) (de⊙ Y) , inr (pt Y) ] module _ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} (f : X ⊙→ Z) (g : Y ⊙→ Z) where ⊙⊔-rec : X ⊙⊔ Y ⊙→ Z ⊙⊔-rec = Coprod-rec (fst f) (fst g) , snd f ⊔⊙-rec : X ⊔⊙ Y ⊙→ Z ⊔⊙-rec = Coprod-rec (fst f) (fst g) , snd g module _ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'} (f : X ⊙→ X') (g : Y ⊙→ Y') where ⊙⊔-fmap : X ⊙⊔ Y ⊙→ X' ⊙⊔ Y' ⊙⊔-fmap = ⊔-fmap (fst f) (fst g) , ap inl (snd f) ⊔⊙-fmap : X ⊔⊙ Y ⊙→ X' ⊔⊙ Y' ⊔⊙-fmap = ⊔-fmap (fst f) (fst g) , ap inr (snd g) codiag : ∀ {i} {A : Type i} → A ⊔ A → A codiag = Coprod-rec (idf _) (idf _) ⊙codiag : ∀ {i} {X : Ptd i} → X ⊙⊔ X ⊙→ X ⊙codiag = (codiag , idp) -- A binary sigma is a coproduct ΣBool-equiv-⊔ : ∀ {i} (Pick : Bool → Type i) → Σ Bool Pick ≃ Pick true ⊔ Pick false ΣBool-equiv-⊔ Pick = equiv into out into-out out-into where into : Σ _ Pick → Pick true ⊔ Pick false into (true , a) = inl a into (false , b) = inr b out : (Pick true ⊔ Pick false) → Σ _ Pick out (inl a) = (true , a) out (inr b) = (false , b) abstract into-out : ∀ c → into (out c) == c into-out (inl a) = idp into-out (inr b) = idp out-into : ∀ s → out (into s) == s out-into (true , a) = idp out-into (false , b) = idp ⊔₁-Empty : ∀ {i} (A : Type i) → Empty ⊔ A ≃ A ⊔₁-Empty A = equiv (λ{(inl ()); (inr a) → a}) inr (λ _ → idp) (λ{(inl ()); (inr _) → idp}) module _ {i j k} {A : Type i} {B : Type j} (P : A ⊔ B → Type k) where Π₁-⊔-equiv-× : Π (A ⊔ B) P ≃ Π A (P ∘ inl) × Π B (P ∘ inr) Π₁-⊔-equiv-× = equiv to from to-from from-to where to : Π (A ⊔ B) P → Π A (P ∘ inl) × Π B (P ∘ inr) to f = (λ a → f (inl a)) , (λ b → f (inr b)) from : Π A (P ∘ inl) × Π B (P ∘ inr) → Π (A ⊔ B) P from (f , g) (inl a) = f a from (f , g) (inr b) = g b abstract to-from : ∀ fg → to (from fg) == fg to-from _ = idp from-to : ∀ fg → from (to fg) == fg from-to fg = λ= λ where (inl _) → idp (inr _) → idp
algebraic-stack_agda0000_doc_16969
module nat-to-string where open import bool open import char open import eq open import list open import maybe open import nat open import nat-division open import nat-thms open import product open import string open import termination ℕ-to-digitsh : (base : ℕ) → 1 < base ≡ tt → (x : ℕ) → ↓𝔹 _>_ x → 𝕃 ℕ ℕ-to-digitsh _ _ 0 _ = [] ℕ-to-digitsh base bp (suc x) (pf↓ fx) with (suc x) ÷ base ! (<=ℕff2 base bp) ... | q , r , p , _ = r :: (ℕ-to-digitsh base bp q (fx (÷<{base}{q}{r}{x} bp p))) ℕ-to-digits : ℕ → 𝕃 ℕ ℕ-to-digits x = reverse (ℕ-to-digitsh 10 refl x (↓-> x)) digit-to-string : ℕ → string digit-to-string 0 = "0" digit-to-string 1 = "1" digit-to-string 2 = "2" digit-to-string 3 = "3" digit-to-string 4 = "4" digit-to-string 5 = "5" digit-to-string 6 = "6" digit-to-string 7 = "7" digit-to-string 8 = "8" digit-to-string 9 = "9" digit-to-string _ = "unexpected-digit" digits-to-string : 𝕃 ℕ → string digits-to-string [] = "" digits-to-string (d :: ds) = (digit-to-string d) ^ (digits-to-string ds) ℕ-to-string : ℕ → string ℕ-to-string 0 = "0" ℕ-to-string (suc x) = digits-to-string (ℕ-to-digits (suc x)) string-to-digit : char → maybe ℕ string-to-digit '0' = just 0 string-to-digit '1' = just 1 string-to-digit '2' = just 2 string-to-digit '3' = just 3 string-to-digit '4' = just 4 string-to-digit '5' = just 5 string-to-digit '6' = just 6 string-to-digit '7' = just 7 string-to-digit '8' = just 8 string-to-digit '9' = just 9 string-to-digit _ = nothing -- the digits are in order from least to most significant digits-to-ℕh : ℕ → ℕ → 𝕃 ℕ → ℕ digits-to-ℕh multiplier sum [] = sum digits-to-ℕh multiplier sum (x :: xs) = digits-to-ℕh (10 * multiplier) (x * multiplier + sum) xs digits-to-ℕ : 𝕃 ℕ → ℕ digits-to-ℕ digits = digits-to-ℕh 1 0 digits string-to-ℕ : string → maybe ℕ string-to-ℕ s with 𝕃maybe-map string-to-digit (reverse (string-to-𝕃char s)) ... | nothing = nothing ... | just ds = just (digits-to-ℕ ds)
algebraic-stack_agda0000_doc_16970
{-# OPTIONS --type-in-type #-} module Compilation.Encode.Examples where open import Context open import Type.Core open import Compilation.Data open import Compilation.Encode.Core open import Function open import Data.Product open import Data.List.Base module ProdTreeTreeExample where open ProdTreeTree open prodTreeTree ProdTreeTree′ = ⟦ prodTreeTree ⟧ᵈ ProdTree′ : Set -> Set -> Set ProdTree′ with ProdTreeTree′ ... | ø ▶ PT′ ▶ T′ = PT′ Tree′ : Set -> Set Tree′ with ProdTreeTree′ ... | ø ▶ PT′ ▶ T′ = T′ mutual fromProdTree : ∀ {A B A′ B′} -> (A -> A′) -> (B -> B′) -> ProdTree A B -> ProdTree′ A′ B′ fromProdTree f g (Prod tree) = Wrap λ R h -> h $ fromTree (λ{ (x , y) _ k -> k (f x) (g y) }) tree fromTree : ∀ {A A′} -> (A -> A′) -> Tree A -> Tree′ A′ fromTree f (Leaf x) = Wrap λ R g h -> g $ f x fromTree f (Fork prod) = Wrap λ R g h -> h $ fromProdTree f f prod {-# TERMINATING #-} mutual toProdTree : ∀ {A B A′ B′} -> (A -> A′) -> (B -> B′) -> ProdTree′ A B -> ProdTree A′ B′ toProdTree f g (Wrap k) = k _ λ tree -> Prod $ toTree (λ k -> k _ λ x y -> f x , g y) tree toTree : ∀ {A A′} -> (A -> A′) -> Tree′ A -> Tree A′ toTree f (Wrap k) = k _ (Leaf ∘ f) (Fork ∘ toProdTree f f) module ListExample where list : Data⁺ (ε ▻ (ε ▻ ⋆)) list = PackData $ ø ▶ ( endᶜ ∷ Var vz ⇒ᶜ Var (vs vz) ∙ Var vz ⇒ᶜ endᶜ ∷ [] ) List′ : Set -> Set List′ with ⟦ list ⟧ᵈ ... | ø ▶ L′ = L′ fromList : ∀ {A} -> List A -> List′ A fromList [] = Wrap λ R z f -> z fromList (x ∷ xs) = Wrap λ R z f -> f x $ fromList xs {-# TERMINATING #-} toList : ∀ {A} -> List′ A -> List A toList (Wrap k) = k _ [] λ x xs -> x ∷ toList xs module InterListExample where data InterList (A B : Set) : Set where InterNil : InterList A B InterCons : A -> B -> InterList B A -> InterList A B interlist : Data⁺ (ε ▻ (ε ▻ ⋆ ▻ ⋆)) interlist = PackData $ ø ▶ ( endᶜ ∷ Var (vs vz) ⇒ᶜ Var vz ⇒ᶜ Var (vs vs vz) ∙ Var vz ∙ Var (vs vz) ⇒ᶜ endᶜ ∷ [] ) InterList′ : Set -> Set -> Set InterList′ with ⟦ interlist ⟧ᵈ ... | ø ▶ IL′ = IL′ fromInterList : ∀ {A B} -> InterList A B -> InterList′ A B fromInterList InterNil = Wrap λ R z f -> z fromInterList (InterCons x y yxs) = Wrap λ R z f -> f x y $ fromInterList yxs {-# TERMINATING #-} toInterList : ∀ {A B} -> InterList′ A B -> InterList A B toInterList (Wrap k) = k _ InterNil λ x y yxs -> InterCons x y $ toInterList yxs module TreeForestExample where mutual data Tree (A : Set) : Set where node : A -> Forest A -> Tree A data Forest (A : Set) : Set where nil : Forest A cons : Tree A -> Forest A -> Forest A treeForest : Data⁺ (ε ▻ (ε ▻ ⋆) ▻ (ε ▻ ⋆)) treeForest = PackData $ ø ▶ ( Var vz ⇒ᶜ Var (vs vz) ∙ Var vz ⇒ᶜ endᶜ ∷ [] ) ▶ ( endᶜ ∷ Var (vs vs vz) ∙ Var vz ⇒ᶜ Var (vs vz) ∙ Var vz ⇒ᶜ endᶜ ∷ [] ) TreeForest′ = ⟦ treeForest ⟧ᵈ Tree′ : Set -> Set Tree′ with TreeForest′ ... | ø ▶ T′ ▶ F′ = T′ Forest′ : Set -> Set Forest′ with TreeForest′ ... | ø ▶ T′ ▶ F′ = F′ mutual fromTree : ∀ {A} -> Tree A -> Tree′ A fromTree (node x forest) = Wrap λ R f -> f x $ fromForest forest fromForest : ∀ {A} -> Forest A -> Forest′ A fromForest nil = Wrap λ R z f -> z fromForest (cons tree forest) = Wrap λ R z f -> f (fromTree tree) (fromForest forest) {-# TERMINATING #-} mutual toTree : ∀ {A} -> Tree′ A -> Tree A toTree (Wrap k) = k _ λ x forest -> node x $ toForest forest toForest : ∀ {A} -> Forest′ A -> Forest A toForest (Wrap k) = k _ nil λ tree forest -> cons (toTree tree) (toForest forest) module MNExample where mutual data M (A : Set) : Set where p : A -> M A n : N -> M A data N : Set where m : M N -> N mn : Data⁺ (ε ▻ (ε ▻ ⋆) ▻ ε) mn = PackData $ ø ▶ ( Var vz ⇒ᶜ endᶜ ∷ Var (vs vz) ⇒ᶜ endᶜ ∷ [] ) ▶ ( Var (vs vz) ∙ Var vz ⇒ᶜ endᶜ ∷ [] ) MN′ = ⟦ mn ⟧ᵈ M′ : Set -> Set M′ with MN′ ... | ø ▶ M′ ▶ N′ = M′ N′ : Set N′ with MN′ ... | ø ▶ M′ ▶ N′ = N′ {-# TERMINATING #-} mutual fromM : ∀ {A B} -> (A -> B) -> M A -> M′ B fromM f (p x) = Wrap λ R g h -> g $ f x fromM f (n x) = Wrap λ R g h -> h $ fromN x fromN : N -> N′ fromN (m x) = Wrap λ R f -> f $ fromM fromN x {-# TERMINATING #-} mutual toM : ∀ {A B} -> (A -> B) -> M′ A -> M B toM f (Wrap k) = k _ (λ x -> p (f x)) (λ x -> n (toN x)) toN : N′ -> N toN (Wrap k) = k _ λ x -> m (toM toN x)
algebraic-stack_agda0000_doc_16971
module FFI.Data.Bool where {-# FOREIGN GHC import qualified Data.Bool #-} data Bool : Set where false : Bool true : Bool {-# COMPILE GHC Bool = data Data.Bool.Bool (Data.Bool.False|Data.Bool.True) #-}
algebraic-stack_agda0000_doc_16972
module test where
algebraic-stack_agda0000_doc_16973
module Data.Either.Equiv where import Lvl open import Data.Either as Either open import Structure.Function.Domain open import Structure.Function open import Structure.Operator open import Structure.Setoid open import Type private variable ℓ ℓₑ ℓₑ₁ ℓₑ₂ : Lvl.Level private variable A B : Type{ℓ} record Extensionality ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄ ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄ (equiv : Equiv{ℓₑ}(A ‖ B)) : Type{Lvl.of(A) Lvl.⊔ Lvl.of(B) Lvl.⊔ ℓₑ₁ Lvl.⊔ ℓₑ₂ Lvl.⊔ ℓₑ} where constructor intro private instance _ = equiv field ⦃ Left-function ⦄ : Function Left ⦃ Right-function ⦄ : Function Right ⦃ Left-injective ⦄ : Injective Left ⦃ Right-injective ⦄ : Injective Right Left-Right-inequality : ∀{x : A}{y : B} → (Left x ≢ Right y)
algebraic-stack_agda0000_doc_16974
{-# OPTIONS --without-K #-} open import HoTT open import homotopy.SuspProduct open import homotopy.SuspSmash open import homotopy.JoinSusp open import cohomology.Theory module cohomology.SphereProduct {i} (CT : CohomologyTheory i) where open CohomologyTheory CT open import cohomology.Wedge CT module _ (n : ℤ) (m : ℕ) (X : Ptd i) where private space-path : ⊙Susp (⊙Lift {j = i} (⊙Sphere m) ⊙× X) == ⊙Susp (⊙Lift (⊙Sphere m)) ⊙∨ (⊙Susp X ⊙∨ ⊙Susp^ (S m) X) space-path = SuspProduct.⊙path (⊙Lift (⊙Sphere m)) X ∙ ap (λ Z → ⊙Susp (⊙Lift (⊙Sphere m)) ⊙∨ (⊙Susp X ⊙∨ Z)) (SuspSmash.⊙path (⊙Lift (⊙Sphere m)) X ∙ ⊙*-⊙Lift-⊙Sphere m X) C-Sphere× : C n (⊙Lift {j = i} (⊙Sphere m) ⊙× X) == C n (⊙Lift (⊙Sphere m)) ×ᴳ (C n X ×ᴳ C n (⊙Susp^ m X)) C-Sphere× = ! (group-ua (C-Susp n (⊙Lift {j = i} (⊙Sphere m) ⊙× X))) ∙ ap (C (succ n)) space-path ∙ CWedge.path (succ n) (⊙Susp (⊙Lift (⊙Sphere m))) (⊙Susp X ⊙∨ ⊙Susp^ (S m) X) ∙ ap (λ H → C (succ n) (⊙Susp (⊙Lift (⊙Sphere m))) ×ᴳ H) (CWedge.path (succ n) (⊙Susp X) (⊙Susp^ (S m) X) ∙ ap2 _×ᴳ_ (group-ua (C-Susp n X)) (group-ua (C-Susp n (⊙Susp^ m X)))) ∙ ap (λ H → H ×ᴳ (C n X ×ᴳ C n (⊙Susp^ m X))) (group-ua (C-Susp n (⊙Lift (⊙Sphere m))))
algebraic-stack_agda0000_doc_16975
------------------------------------------------------------------------ -- A type soundness result ------------------------------------------------------------------------ module Lambda.Closure.Functional.Type-soundness where import Category.Monad.Partiality as Partiality open import Category.Monad.Partiality.All as All using (All; now; later) open import Codata.Musical.Notation open import Data.Fin using (Fin; zero; suc) open import Data.Maybe using (Maybe; just; nothing) open import Data.Maybe.Relation.Unary.Any as Maybe using (just) open import Data.Nat open import Data.Vec using (Vec; []; _∷_; lookup) open import Relation.Binary.PropositionalEquality using (_≡_) open import Relation.Nullary open All.Alternative private open module E {A : Set} = Partiality.Equality (_≡_ {A = A}) using (_≈_; now; laterˡ) open import Lambda.Closure.Functional open Lambda.Closure.Functional.PF using (fail) open Lambda.Closure.Functional.Workaround using (⟪_⟫P) open import Lambda.Syntax open Lambda.Syntax.Closure Tm -- WF-Value, WF-Env and WF-MV specify when a -- value/environment/potential value is well-formed with respect to a -- given context (and type). mutual data WF-Value : Ty → Value → Set where con : ∀ {i} → WF-Value nat (con i) ƛ : ∀ {n Γ σ τ} {t : Tm (1 + n)} {ρ} (t∈ : ♭ σ ∷ Γ ⊢ t ∈ ♭ τ) (ρ-wf : WF-Env Γ ρ) → WF-Value (σ ⇾ τ) (ƛ t ρ) infixr 5 _∷_ data WF-Env : ∀ {n} → Ctxt n → Env n → Set where [] : WF-Env [] [] _∷_ : ∀ {n} {Γ : Ctxt n} {ρ σ v} (v-wf : WF-Value σ v) (ρ-wf : WF-Env Γ ρ) → WF-Env (σ ∷ Γ) (v ∷ ρ) WF-MV : Ty → Maybe Value → Set WF-MV σ = Maybe.Any (WF-Value σ) -- Variables pointing into a well-formed environment refer to -- well-formed values. lookup-wf : ∀ {n Γ ρ} (x : Fin n) → WF-Env Γ ρ → WF-Value (lookup Γ x) (lookup ρ x) lookup-wf zero (v-wf ∷ ρ-wf) = v-wf lookup-wf (suc x) (v-wf ∷ ρ-wf) = lookup-wf x ρ-wf -- If we can prove All (WF-MV σ) x, then x does not "go wrong". does-not-go-wrong : ∀ {σ x} → All (WF-MV σ) x → ¬ x ≈ fail does-not-go-wrong (now (just _)) (now ()) does-not-go-wrong (later x-wf) (laterˡ x↯) = does-not-go-wrong (♭ x-wf) x↯ -- Well-typed programs do not "go wrong". mutual ⟦⟧-wf : ∀ {n Γ} (t : Tm n) {σ} → Γ ⊢ t ∈ σ → ∀ {ρ} → WF-Env Γ ρ → AllP (WF-MV σ) (⟦ t ⟧ ρ) ⟦⟧-wf (con i) con ρ-wf = now (just con) ⟦⟧-wf (var x) var ρ-wf = now (just (lookup-wf x ρ-wf)) ⟦⟧-wf (ƛ t) (ƛ t∈) ρ-wf = now (just (ƛ t∈ ρ-wf)) ⟦⟧-wf (t₁ · t₂) (t₁∈ · t₂∈) {ρ} ρ-wf = ⟦ t₁ · t₂ ⟧ ρ ≅⟨ ·-comp t₁ t₂ ⟩P ⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ⟨ (⟦⟧-wf t₁ t₁∈ ρ-wf >>=-congP λ { .{_} (just f-wf) → ⟦⟧-wf t₂ t₂∈ ρ-wf >>=-congP λ { .{_} (just v-wf) → ∙-wf f-wf v-wf }}) ⟩P ∙-wf : ∀ {σ τ f v} → WF-Value (σ ⇾ τ) f → WF-Value (♭ σ) v → AllP (WF-MV (♭ τ)) ⟪ f ∙ v ⟫P ∙-wf (ƛ t₁∈ ρ₁-wf) v₂-wf = later (♯ ⟦⟧-wf _ t₁∈ (v₂-wf ∷ ρ₁-wf)) type-soundness : ∀ {t : Tm 0} {σ} → [] ⊢ t ∈ σ → ¬ ⟦ t ⟧ [] ≈ fail type-soundness t∈ = does-not-go-wrong (All.Alternative.sound (⟦⟧-wf _ t∈ []))
algebraic-stack_agda0000_doc_5952
{-# OPTIONS --without-K --safe #-} module Categories.Category.Instance.Properties.Setoids where open import Level open import Data.Product using (Σ; proj₁; proj₂; _,_; Σ-syntax; _×_; -,_) open import Function.Equality using (Π) open import Relation.Binary using (Setoid; Preorder; Rel) open import Relation.Binary.PropositionalEquality as ≡ using (_≡_) open import Relation.Binary.Indexed.Heterogeneous using (_=[_]⇒_) open import Relation.Binary.Construct.Closure.SymmetricTransitive as ST using (Plus⇔; minimal) open Plus⇔ open import Categories.Category using (Category; _[_,_]) open import Categories.Functor open import Categories.Category.Instance.Setoids open import Categories.Category.Complete open import Categories.Category.Cocomplete import Categories.Category.Construction.Cocones as Coc import Categories.Category.Construction.Cones as Co import Relation.Binary.Reasoning.Setoid as RS open Π using (_⟨$⟩_) module _ {o ℓ e} c ℓ′ {J : Category o ℓ e} (F : Functor J (Setoids (o ⊔ c) (o ⊔ ℓ ⊔ c ⊔ ℓ′))) where private module J = Category J open Functor F module F₀ j = Setoid (F₀ j) open F₀ using () renaming (_≈_ to _[_≈_]) vertex-carrier : Set (o ⊔ c) vertex-carrier = Σ J.Obj F₀.Carrier coc : Rel vertex-carrier (o ⊔ ℓ ⊔ c ⊔ ℓ′) coc (X , x) (Y , y) = Σ[ f ∈ J [ X , Y ] ] Y [ (F₁ f ⟨$⟩ x) ≈ y ] coc-preorder : Preorder (o ⊔ c) (o ⊔ c) (o ⊔ ℓ ⊔ c ⊔ ℓ′) coc-preorder = record { Carrier = vertex-carrier ; _≈_ = _≡_ ; _∼_ = coc ; isPreorder = record { isEquivalence = ≡.isEquivalence ; reflexive = λ { {j , _} ≡.refl → J.id , (identity (F₀.refl j)) } ; trans = λ { {a , Sa} {b , Sb} {c , Sc} (f , eq₁) (g , eq₂) → let open RS (F₀ c) in g J.∘ f , (begin F₁ (g J.∘ f) ⟨$⟩ Sa ≈⟨ homomorphism (F₀.refl a) ⟩ F₁ g ⟨$⟩ (F₁ f ⟨$⟩ Sa) ≈⟨ Π.cong (F₁ g) eq₁ ⟩ F₁ g ⟨$⟩ Sb ≈⟨ eq₂ ⟩ Sc ∎) } } } Setoids-Cocomplete : (o ℓ e c ℓ′ : Level) → Cocomplete o ℓ e (Setoids (o ⊔ c) (o ⊔ ℓ ⊔ c ⊔ ℓ′)) Setoids-Cocomplete o ℓ e c ℓ′ {J} F = record { initial = record { ⊥ = record { N = ⇛-Setoid ; coapex = record { ψ = λ j → record { _⟨$⟩_ = j ,_ ; cong = λ i≈k → forth (-, identity i≈k) } ; commute = λ {X} X⇒Y x≈y → back (-, Π.cong (F₁ X⇒Y) (F₀.sym X x≈y)) } } ; ! = λ {K} → let module K = Cocone K in record { arr = record { _⟨$⟩_ = to-coapex K ; cong = minimal (coc c ℓ′ F) K.N (to-coapex K) (coapex-cong K) } ; commute = λ {X} x≈y → Π.cong (Coapex.ψ (Cocone.coapex K) X) x≈y } ; !-unique = λ { {K} f {a , Sa} {b , Sb} eq → let module K = Cocone K module f = Cocone⇒ f open RS K.N in begin K.ψ a ⟨$⟩ Sa ≈˘⟨ f.commute (F₀.refl a) ⟩ f.arr ⟨$⟩ (a , Sa) ≈⟨ Π.cong f.arr eq ⟩ f.arr ⟨$⟩ (b , Sb) ∎ } } } where open Functor F open Coc F module J = Category J module F₀ j = Setoid (F₀ j) open F₀ using () renaming (_≈_ to _[_≈_]) -- this is essentially a symmetric transitive closure of coc ⇛-Setoid : Setoid (o ⊔ c) (o ⊔ ℓ ⊔ c ⊔ ℓ′) ⇛-Setoid = ST.setoid (coc c ℓ′ F) (Preorder.refl (coc-preorder c ℓ′ F)) to-coapex : ∀ K → vertex-carrier c ℓ′ F → Setoid.Carrier (Cocone.N K) to-coapex K (j , Sj) = K.ψ j ⟨$⟩ Sj where module K = Cocone K coapex-cong : ∀ K → coc c ℓ′ F =[ to-coapex K ]⇒ (Setoid._≈_ (Cocone.N K)) coapex-cong K {X , x} {Y , y} (f , fx≈y) = begin K.ψ X ⟨$⟩ x ≈˘⟨ K.commute f (F₀.refl X) ⟩ K.ψ Y ⟨$⟩ (F₁ f ⟨$⟩ x) ≈⟨ Π.cong (K.ψ Y) fx≈y ⟩ K.ψ Y ⟨$⟩ y ∎ where module K = Cocone K open RS K.N Setoids-Complete : (o ℓ e c ℓ′ : Level) → Complete o ℓ e (Setoids (c ⊔ ℓ ⊔ o ⊔ ℓ′) (o ⊔ ℓ′)) Setoids-Complete o ℓ e c ℓ′ {J} F = record { terminal = record { ⊤ = record { N = record { Carrier = Σ (∀ j → F₀.Carrier j) (λ S → ∀ {X Y} (f : J [ X , Y ]) → [ F₀ Y ] F₁ f ⟨$⟩ S X ≈ S Y) ; _≈_ = λ { (S₁ , _) (S₂ , _) → ∀ j → [ F₀ j ] S₁ j ≈ S₂ j } ; isEquivalence = record { refl = λ j → F₀.refl j ; sym = λ a≈b j → F₀.sym j (a≈b j) ; trans = λ a≈b b≈c j → F₀.trans j (a≈b j) (b≈c j) } } ; apex = record { ψ = λ j → record { _⟨$⟩_ = λ { (S , _) → S j } ; cong = λ eq → eq j } ; commute = λ { {X} {Y} X⇒Y {_ , eq} {y} f≈g → F₀.trans Y (eq X⇒Y) (f≈g Y) } } } ; ! = λ {K} → let module K = Cone K in record { arr = record { _⟨$⟩_ = λ x → (λ j → K.ψ j ⟨$⟩ x) , λ f → K.commute f (Setoid.refl K.N) ; cong = λ a≈b j → Π.cong (K.ψ j) a≈b } ; commute = λ x≈y → Π.cong (K.ψ _) x≈y } ; !-unique = λ {K} f x≈y j → let module K = Cone K in F₀.sym j (Cone⇒.commute f (Setoid.sym K.N x≈y)) } } where open Functor F open Co F module J = Category J module F₀ j = Setoid (F₀ j) [_]_≈_ = Setoid._≈_
algebraic-stack_agda0000_doc_5953
open import Agda.Primitive variable ℓ : Level A : Set ℓ P : A → Set ℓ f : (x : A) → P x postulate R : (a : Level) → Set (lsuc a) r : (a : Level) → R a Id : (a : Level) (A : Set a) → A → A → Set a cong₂ : (a b c : Level) (A : Set a) (B : Set b) (C : Set c) (x y : A) (u v : B) (f : A → B → C) → Id c C (f x u) (f y v) foo : (x y u v : A) (g : A → A) → let a = _ in Id a (Id _ _ _ _) (cong₂ _ _ _ _ _ _ x y u v (λ x → f (g x))) (cong₂ _ _ _ _ _ _ (g x) (g y) u v f)
algebraic-stack_agda0000_doc_5954
open import Oscar.Prelude open import Oscar.Class open import Oscar.Class.Reflexivity module Oscar.Class.Reflexivity.Function where module _ {a} where instance 𝓡eflexivityFunction : Reflexivity.class Function⟦ a ⟧ 𝓡eflexivityFunction .⋆ = ¡
algebraic-stack_agda0000_doc_5955
-- https://github.com/idris-lang/Idris-dev/blob/4e704011fb805fcb861cc9a1bd68a2e727cefdde/libs/contrib/Data/Nat/Fib.idr {-# OPTIONS --without-K --safe #-} -- agda-stdlib open import Algebra module Math.NumberTheory.Fibonacci.Generic {c e} (CM : CommutativeMonoid c e) (v0 v1 : CommutativeMonoid.Carrier CM) where -- agda-stdlib open import Data.Nat open import Function import Relation.Binary.PropositionalEquality as ≡ import Relation.Binary.Reasoning.Setoid as SetoidReasoning open CommutativeMonoid CM renaming ( Carrier to A ) open SetoidReasoning setoid fibRec : ℕ → A fibRec 0 = v0 fibRec 1 = v1 fibRec (suc (suc n)) = fibRec (suc n) ∙ fibRec n fibAcc : ℕ → A → A → A fibAcc 0 a b = a fibAcc (suc n) a b = fibAcc n b (a ∙ b) fib : ℕ → A fib n = fibAcc n v0 v1 lemma : ∀ m n o p → (m ∙ n) ∙ (o ∙ p) ≈ (m ∙ o) ∙ (n ∙ p) lemma m n o p = begin (m ∙ n) ∙ (o ∙ p) ≈⟨ assoc m n (o ∙ p) ⟩ m ∙ (n ∙ (o ∙ p)) ≈⟨ sym $ ∙-congˡ $ assoc n o p ⟩ m ∙ ((n ∙ o) ∙ p) ≈⟨ ∙-congˡ $ ∙-congʳ $ comm n o ⟩ m ∙ ((o ∙ n) ∙ p) ≈⟨ ∙-congˡ $ assoc o n p ⟩ m ∙ (o ∙ (n ∙ p)) ≈⟨ sym $ assoc m o (n ∙ p) ⟩ (m ∙ o) ∙ (n ∙ p) ∎ fibAcc-cong : ∀ {m n o p q r} → m ≡.≡ n → o ≈ p → q ≈ r → fibAcc m o q ≈ fibAcc n p r fibAcc-cong {zero} {.0} {o} {p} {q} {r} ≡.refl o≈p q≈r = o≈p fibAcc-cong {suc m} {.(suc m)} {o} {p} {q} {r} ≡.refl o≈p q≈r = fibAcc-cong {m = m} ≡.refl q≈r (∙-cong o≈p q≈r) fibAdd : ∀ m n o p q → fibAcc m n o ∙ fibAcc m p q ≈ fibAcc m (n ∙ p) (o ∙ q) fibAdd 0 n o p q = refl fibAdd 1 n o p q = refl fibAdd (suc (suc m)) n o p q = begin fibAcc (2 + m) n o ∙ fibAcc (2 + m) p q ≡⟨⟩ fibAcc (1 + m) o (n ∙ o) ∙ fibAcc (1 + m) q (p ∙ q) ≡⟨⟩ fibAcc m (n ∙ o) (o ∙ (n ∙ o)) ∙ fibAcc m (p ∙ q) (q ∙ (p ∙ q)) ≈⟨ fibAdd m (n ∙ o) (o ∙ (n ∙ o)) (p ∙ q) (q ∙ (p ∙ q)) ⟩ fibAcc m ((n ∙ o) ∙ (p ∙ q)) ((o ∙ (n ∙ o)) ∙ (q ∙ (p ∙ q))) ≈⟨ fibAcc-cong {m = m} ≡.refl (lemma n o p q) (lemma o (n ∙ o) q (p ∙ q)) ⟩ fibAcc m ((n ∙ p) ∙ (o ∙ q)) ((o ∙ q) ∙ ((n ∙ o) ∙ (p ∙ q))) ≈⟨ fibAcc-cong {m = m} ≡.refl refl (∙-congˡ $ lemma n o p q) ⟩ fibAcc m ((n ∙ p) ∙ (o ∙ q)) ((o ∙ q) ∙ ((n ∙ p) ∙ (o ∙ q))) ≡⟨⟩ fibAcc (1 + m) (o ∙ q) ((n ∙ p) ∙ (o ∙ q)) ≡⟨⟩ fibAcc (2 + m) (n ∙ p) (o ∙ q) ∎ fibRec≈fib : ∀ n → fibRec n ≈ fib n fibRec≈fib 0 = refl fibRec≈fib 1 = refl fibRec≈fib (suc (suc n)) = begin fibRec (2 + n) ≡⟨⟩ fibRec (1 + n) ∙ fibRec n ≈⟨ ∙-cong (fibRec≈fib (suc n)) (fibRec≈fib n) ⟩ fib (1 + n) ∙ fib n ≡⟨⟩ fibAcc (1 + n) v0 v1 ∙ fibAcc n v0 v1 ≡⟨⟩ fibAcc n v1 (v0 ∙ v1) ∙ fibAcc n v0 v1 ≈⟨ fibAdd n v1 (v0 ∙ v1) v0 v1 ⟩ fibAcc n (v1 ∙ v0) ((v0 ∙ v1) ∙ v1) ≈⟨ fibAcc-cong {m = n} ≡.refl (comm v1 v0) (trans (∙-congʳ (comm v0 v1)) (assoc v1 v0 v1)) ⟩ fibAcc n (v0 ∙ v1) (v1 ∙ (v0 ∙ v1)) ≡⟨⟩ fib (2 + n) ∎ fib[2+n]≈fib[1+n]∙fib[n] : ∀ n → fib (suc (suc n)) ≈ fib (suc n) ∙ fib n fib[2+n]≈fib[1+n]∙fib[n] n = trans (sym $ fibRec≈fib (suc (suc n))) (∙-cong (fibRec≈fib (suc n)) (fibRec≈fib n)) fib[1+n]∙fib[n]≈fib[2+n] : ∀ n → fib (suc n) ∙ fib n ≈ fib (suc (suc n)) fib[1+n]∙fib[n]≈fib[2+n] n = sym $ fib[2+n]≈fib[1+n]∙fib[n] n fib[n]∙fib[1+n]≈fib[2+n] : ∀ n → fib n ∙ fib (suc n) ≈ fib (suc (suc n)) fib[n]∙fib[1+n]≈fib[2+n] n = trans (comm (fib n) (fib (suc n))) (fib[1+n]∙fib[n]≈fib[2+n] n)
algebraic-stack_agda0000_doc_5956
module Lib.Maybe where data Maybe (A : Set) : Set where nothing : Maybe A just : A -> Maybe A {-# COMPILE GHC Maybe = data Maybe (Nothing | Just) #-}
algebraic-stack_agda0000_doc_5957
module Subst where open import Prelude open import Lambda infix 100 _[_] _[_:=_] _↑ infixl 100 _↑_ _↑ˢ_ _↑ˣ_ _↓ˣ_ infixl 60 _-_ {- _-_ : {τ : Type}(Γ : Ctx) -> Var Γ τ -> Ctx ε - () Γ , τ - vz = Γ Γ , τ - vs x = (Γ - x) , τ wkˣ : {Γ : Ctx}{σ τ : Type} (x : Var Γ σ) -> Var (Γ - x) τ -> Var Γ τ wkˣ vz y = vs y wkˣ (vs x) vz = vz wkˣ (vs x) (vs y) = vs (wkˣ x y) wk : {Γ : Ctx}{σ τ : Type} (x : Var Γ σ) -> Term (Γ - x) τ -> Term Γ τ wk x (var y) = var (wkˣ x y) wk x (s • t) = wk x s • wk x t wk x (ƛ t) = ƛ wk (vs x) t _↑ : {Γ : Ctx}{σ τ : Type} -> Term Γ τ -> Term (Γ , σ) τ t ↑ = wk vz t _↑_ : {Γ : Ctx}{τ : Type} -> Term Γ τ -> (Δ : Ctx) -> Term (Γ ++ Δ) τ t ↑ ε = t t ↑ (Δ , σ) = (t ↑ Δ) ↑ data Cmpˣ {Γ : Ctx}{τ : Type}(x : Var Γ τ) : {σ : Type} -> Var Γ σ -> Set where same : Cmpˣ x x diff : {σ : Type}(y : Var (Γ - x) σ) -> Cmpˣ x (wkˣ x y) _≟_ : {Γ : Ctx}{σ τ : Type}(x : Var Γ σ)(y : Var Γ τ) -> Cmpˣ x y vz ≟ vz = same vz ≟ vs y = diff y vs x ≟ vz = diff vz vs x ≟ vs y with x ≟ y vs x ≟ vs .x | same = same vs x ≟ vs .(wkˣ x y) | diff y = diff (vs y) _[_:=_] : {Γ : Ctx}{σ τ : Type} -> Term Γ σ -> (x : Var Γ τ) -> Term (Γ - x) τ -> Term (Γ - x) σ var y [ x := u ] with x ≟ y var .x [ x := u ] | same = u var .(wkˣ x y) [ x := u ] | diff y = var y (s • t) [ x := u ] = s [ x := u ] • t [ x := u ] (ƛ t) [ x := u ] = ƛ t [ vs x := u ↑ ] -} infix 30 _─⟶_ infixl 90 _/_ _─⟶_ : Ctx -> Ctx -> Set Γ ─⟶ Δ = Terms Γ Δ idS : forall {Γ} -> Γ ─⟶ Γ idS = tabulate var infixr 80 _∘ˢ_ [_] : forall {Γ σ } -> Term Γ σ -> Γ ─⟶ Γ , σ [ t ] = idS ◄ t wkS : forall {Γ Δ τ} -> Γ ─⟶ Δ -> Γ , τ ─⟶ Δ wkS ∅ = ∅ wkS (θ ◄ t) = wkS θ ◄ wk t _↑ : forall {Γ Δ τ} -> (Γ ─⟶ Δ) -> Γ , τ ─⟶ Δ , τ θ ↑ = wkS θ ◄ vz _/_ : forall {Γ Δ τ} -> Term Δ τ -> Γ ─⟶ Δ -> Term Γ τ vz / (θ ◄ u) = u wk t / (θ ◄ u) = t / θ (s • t) / θ = s / θ • t / θ (ƛ t) / θ = ƛ t / θ ↑ _∘ˢ_ : forall {Γ Δ Θ} -> Δ ─⟶ Θ -> Γ ─⟶ Δ -> Γ ─⟶ Θ ∅ ∘ˢ θ = ∅ (δ ◄ t) ∘ˢ θ = δ ∘ˢ θ ◄ t / θ inj : forall {Γ Δ τ} Θ -> Term Γ τ -> Γ ─⟶ Δ ++ Θ -> Γ ─⟶ Δ , τ ++ Θ inj ε t θ = θ ◄ t inj (Θ , σ) t (θ ◄ u) = inj Θ t θ ◄ u [_⟵_] : forall {Γ τ} Δ -> Term (Γ ++ Δ) τ -> Γ ++ Δ ─⟶ Γ , τ ++ Δ [ Δ ⟵ t ] = inj Δ t idS _↑_ : forall {Γ σ} -> Term Γ σ -> (Δ : Ctx) -> Term (Γ ++ Δ) σ t ↑ ε = t t ↑ (Δ , τ) = wk (t ↑ Δ) _↑ˢ_ : forall {Γ Δ} -> Terms Γ Δ -> (Θ : Ctx) -> Terms (Γ ++ Θ) Δ ∅ ↑ˢ Θ = ∅ (ts ◄ t) ↑ˢ Θ = ts ↑ˢ Θ ◄ t ↑ Θ _↑ˣ_ : forall {Γ τ} -> Var Γ τ -> (Δ : Ctx) -> Var (Γ ++ Δ) τ x ↑ˣ ε = x x ↑ˣ (Δ , σ) = vsuc (x ↑ˣ Δ) lem-var-↑ˣ : forall {Γ τ}(x : Var Γ τ)(Δ : Ctx) -> var (x ↑ˣ Δ) ≡ var x ↑ Δ lem-var-↑ˣ x ε = refl lem-var-↑ˣ x (Δ , σ) = cong wk (lem-var-↑ˣ x Δ) {- Not true! lem-•-↑ : forall {Γ σ τ}(t : Term Γ (σ ⟶ τ))(u : Term Γ σ) Δ -> (t ↑ Δ) • (u ↑ Δ) ≡ (t • u) ↑ Δ lem-•-↑ t u ε = refl lem-•-↑ t u (Δ , δ) = {! !} lem-•ˢ-↑ : forall {Γ Θ τ}(t : Term Γ (Θ ⇒ τ))(ts : Terms Γ Θ) Δ -> (t ↑ Δ) •ˢ (ts ↑ˢ Δ) ≡ (t •ˢ ts) ↑ Δ lem-•ˢ-↑ t ∅ Δ = refl lem-•ˢ-↑ t (u ◄ us) Δ = {! !} -} {- _[_] : {Γ : Ctx}{σ τ : Type} -> Term (Γ , τ) σ -> Term Γ τ -> Term Γ σ t [ u ] = t / [ u ] -} {- vz [ u ] = u wk t [ u ] = {! !} (s • t) [ u ] = {! !} (ƛ_ {τ = ρ} t) [ u ] = ƛ {! !} -} {- _↓ˣ_ : {Γ : Ctx}{σ τ : Type} (y : Var Γ σ)(x : Var (Γ - y) τ) -> Var (Γ - wkˣ y x) σ vz ↓ˣ x = vz vs y ↓ˣ vz = y vs y ↓ˣ vs x = vs (y ↓ˣ x) lem-commute-minus : {Γ : Ctx}{σ τ : Type}(y : Var Γ σ)(x : Var (Γ - y) τ) -> Γ - y - x ≡ Γ - wkˣ y x - (y ↓ˣ x) lem-commute-minus vz x = refl lem-commute-minus (vs y) vz = refl lem-commute-minus (vs {Γ} y) (vs x) with Γ - y - x | lem-commute-minus y x ... | ._ | refl = refl Lem-wk-[] : {Γ : Ctx}{τ σ ρ : Type} (y : Var Γ τ) (x : Var (Γ - y) σ) (t : Term (Γ - wkˣ y x) ρ) (u : Term (Γ - y - x) τ) -> Set Lem-wk-[] {Γ}{τ}{σ}{ρ} y x t u = wk (wkˣ y x) t [ y := wk x u ] ≡ wk x t[u']' where u' : Term (Γ - wkˣ y x - y ↓ˣ x) τ u' = subst (\Δ -> Term Δ τ) (sym (lem-commute-minus y x)) u t[u']' : Term (Γ - y - x) ρ t[u']' = subst (\Δ -> Term Δ ρ) (lem-commute-minus y x) (t [ y ↓ˣ x := u' ]) postulate lem-wk-[] : {Γ : Ctx}{σ τ ρ : Type} (y : Var Γ τ)(x : Var (Γ - y) σ) (t : Term (Γ - wkˣ y x) ρ){u : Term (Γ - y - x) τ} -> Lem-wk-[] y x t u {- lem-wk-[] y x (var z) = {! !} lem-wk-[] y x (t • u) = {! !} lem-wk-[] y x (ƛ t) = {! !} -} lem-wk-[]' : {Γ : Ctx}{σ τ ρ : Type} (x : Var Γ σ)(t : Term (Γ - x , ρ) τ){u : Term (Γ - x) ρ} -> wk x (t [ vz := u ]) ≡ wk (vs x) t [ vz := wk x u ] lem-wk-[]' x t = sym (lem-wk-[] vz x t) -}
algebraic-stack_agda0000_doc_5958
{-# OPTIONS --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.Substitution.Introductions.IdUniv {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped open import Definition.Untyped.Properties open import Definition.Typed open import Definition.Typed.Properties import Definition.Typed.Weakening as Twk open import Definition.Typed.EqualityRelation open import Definition.Typed.RedSteps open import Definition.LogicalRelation open import Definition.LogicalRelation.ShapeView open import Definition.LogicalRelation.Irrelevance open import Definition.LogicalRelation.Properties open import Definition.LogicalRelation.Application open import Definition.LogicalRelation.Substitution import Definition.LogicalRelation.Weakening as Lwk open import Definition.LogicalRelation.Substitution.Properties import Definition.LogicalRelation.Substitution.Irrelevance as S open import Definition.LogicalRelation.Substitution.Reflexivity open import Definition.LogicalRelation.Substitution.Weakening -- open import Definition.LogicalRelation.Substitution.Introductions.Nat open import Definition.LogicalRelation.Substitution.Introductions.Empty open import Definition.LogicalRelation.Substitution.Introductions.Pi open import Definition.LogicalRelation.Substitution.Introductions.Idlemmas open import Definition.LogicalRelation.Substitution.MaybeEmbed -- open import Definition.LogicalRelation.Substitution.Introductions.SingleSubst open import Definition.LogicalRelation.Substitution.Introductions.Universe open import Tools.Product open import Tools.Empty import Tools.Unit as TU import Tools.PropositionalEquality as PE import Data.Nat as Nat [Id]SProp : ∀ {t u Γ} (⊢Γ : ⊢ Γ) ([t] : Γ ⊩⟨ ι ⁰ ⟩ t ^ [ % , ι ⁰ ]) ([u] : Γ ⊩⟨ ι ⁰ ⟩ u ^ [ % , ι ⁰ ]) → Γ ⊩⟨ ι ¹ ⟩ Id (SProp ⁰) t u ^ [ % , ι ¹ ] [Id]SProp {t} {u} {Γ} ⊢Γ [t] [u] = let ⊢t = escape [t] ⊢u = escape [u] ⊢wkt = Twk.wk (Twk.step Twk.id) (⊢Γ ∙ ⊢u) ⊢t ⊢wku = Twk.wk (Twk.step Twk.id) (⊢Γ ∙ ⊢t) ⊢u [wkt] = λ {ρ} {Δ} ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Lwk.wk [ρ] ⊢Δ [t] [wku] = λ {ρ} {Δ} ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Lwk.wk [ρ] ⊢Δ [u] [t▹u] : Γ ⊩⟨ ι ⁰ ⟩ t ^ % ° ⁰ ▹▹ u ° ⁰ ° ¹ ^ [ % , ι ¹ ] [t▹u] = Πᵣ′ % ⁰ ⁰ (<is≤ 0<1) (<is≤ 0<1) t (wk1 u) (idRed:*: (univ (Πⱼ <is≤ 0<1 ▹ <is≤ 0<1 ▹ un-univ ⊢t ▹ un-univ ⊢wku))) ⊢t ⊢wku (≅-univ (≅ₜ-Π-cong (<is≤ 0<1) (<is≤ 0<1) ⊢t (≅-un-univ (escapeEqRefl [t])) (≅-un-univ (≅-wk (Twk.step Twk.id) (⊢Γ ∙ ⊢t) (escapeEqRefl [u]))))) [wkt] ([nondep] [u] [wkt]) ([nondepext] [u] [wkt]) [u▹t] : Γ ⊩⟨ ι ⁰ ⟩ u ^ % ° ⁰ ▹▹ t ° ⁰ ° ¹ ^ [ % , ι ¹ ] [u▹t] = Πᵣ′ % ⁰ ⁰ (<is≤ 0<1) (<is≤ 0<1) u (wk1 t) (idRed:*: (univ (Πⱼ <is≤ 0<1 ▹ <is≤ 0<1 ▹ un-univ ⊢u ▹ un-univ ⊢wkt))) ⊢u ⊢wkt (≅-univ (≅ₜ-Π-cong (<is≤ 0<1) (<is≤ 0<1) ⊢u (≅-un-univ (escapeEqRefl [u])) (≅-un-univ (≅-wk (Twk.step Twk.id) (⊢Γ ∙ ⊢u) (escapeEqRefl [t]))))) [wku] ([nondep] [t] [wku]) ([nondepext] [t] [wku]) [wkt▹u] = λ {ρ} {Δ} ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Lwk.wk [ρ] ⊢Δ (emb emb< [t▹u]) ⊢t▹u = escape [t▹u] ⊢u▹t = Twk.wk (Twk.step Twk.id) (⊢Γ ∙ ⊢t▹u) (escape [u▹t]) ⊢Id = univ (Idⱼ (univ 0<1 ⊢Γ) (un-univ ⊢t) (un-univ ⊢u)) ⊢Eq = univ (∃ⱼ un-univ ⊢t▹u ▹ un-univ ⊢u▹t) in ∃ᵣ′ (t ^ % ° ⁰ ▹▹ u ° ⁰ ° ¹) (wk1 (u ^ % ° ⁰ ▹▹ t ° ⁰ ° ¹)) [[ ⊢Id , ⊢Eq , univ (Id-SProp (un-univ ⊢t) (un-univ ⊢u)) ⇨ id ⊢Eq ]] ⊢t▹u ⊢u▹t (≅-univ (≅ₜ-∃-cong ⊢t▹u (≅-un-univ (escapeEqRefl [t▹u])) (≅-un-univ (≅-wk (Twk.step Twk.id) (⊢Γ ∙ ⊢t▹u) (escapeEqRefl [u▹t]))))) [wkt▹u] ([nondep] (emb emb< [u▹t]) [wkt▹u]) ([nondepext] (emb emb< [u▹t]) [wkt▹u]) [IdExt]SProp : ∀ {t t′ u u′ Γ} (⊢Γ : ⊢ Γ) ([t] : Γ ⊩⟨ ι ⁰ ⟩ t ^ [ % , ι ⁰ ]) ([t′] : Γ ⊩⟨ ι ⁰ ⟩ t′ ^ [ % , ι ⁰ ]) ([t≡t′] : Γ ⊩⟨ ι ⁰ ⟩ t ≡ t′ ^ [ % , ι ⁰ ] / [t]) ([u] : Γ ⊩⟨ ι ⁰ ⟩ u ^ [ % , ι ⁰ ]) ([u′] : Γ ⊩⟨ ι ⁰ ⟩ u′ ^ [ % , ι ⁰ ]) ([u≡u′] : Γ ⊩⟨ ι ⁰ ⟩ u ≡ u′ ^ [ % , ι ⁰ ] / [u]) → Γ ⊩⟨ ι ¹ ⟩ Id (SProp ⁰) t u ≡ Id (SProp ⁰) t′ u′ ^ [ % , ι ¹ ] / [Id]SProp ⊢Γ [t] [u] [IdExt]SProp {t} {t′} {u} {u′} {Γ} ⊢Γ [t] [t′] [t≡t′] [u] [u′] [u≡u′] = let ⊢t = escape [t] ⊢t′ = escape [t′] ⊢u = escape [u] ⊢u′ = escape [u′] ⊢t≡t′ = ≅-un-univ (escapeEq [t] [t≡t′]) ⊢u≡u′ = ≅-un-univ (escapeEq [u] [u≡u′]) ⊢wkt = Twk.wk (Twk.step Twk.id) (⊢Γ ∙ ⊢u) ⊢t ⊢wku = Twk.wk (Twk.step Twk.id) (⊢Γ ∙ ⊢t) ⊢u [wkt] = λ {ρ} {Δ} ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Lwk.wk [ρ] ⊢Δ [t] [wku] = λ {ρ} {Δ} ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Lwk.wk [ρ] ⊢Δ [u] ⊢wkt′ = Twk.wk (Twk.step Twk.id) (⊢Γ ∙ ⊢u′) ⊢t′ ⊢wku′ = Twk.wk (Twk.step Twk.id) (⊢Γ ∙ ⊢t′) ⊢u′ [wkt′] = λ {ρ} {Δ} ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Lwk.wk [ρ] ⊢Δ [t′] [wku′] = λ {ρ} {Δ} ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Lwk.wk [ρ] ⊢Δ [u′] [t▹u] : Γ ⊩⟨ ι ⁰ ⟩ t ^ % ° ⁰ ▹▹ u ° ⁰ ° ¹ ^ [ % , ι ¹ ] [t▹u] = Πᵣ′ % ⁰ ⁰ (<is≤ 0<1) (<is≤ 0<1) t (wk1 u) (idRed:*: (univ (Πⱼ <is≤ 0<1 ▹ <is≤ 0<1 ▹ un-univ ⊢t ▹ un-univ ⊢wku))) ⊢t ⊢wku (≅-univ (≅ₜ-Π-cong (<is≤ 0<1) (<is≤ 0<1) ⊢t (≅-un-univ (escapeEqRefl [t])) (≅-un-univ (≅-wk (Twk.step Twk.id) (⊢Γ ∙ ⊢t) (escapeEqRefl [u]))))) [wkt] ([nondep] [u] [wkt]) ([nondepext] [u] [wkt]) [u▹t] : Γ ⊩⟨ ι ⁰ ⟩ u ^ % ° ⁰ ▹▹ t ° ⁰ ° ¹ ^ [ % , ι ¹ ] [u▹t] = Πᵣ′ % ⁰ ⁰ (<is≤ 0<1) (<is≤ 0<1) u (wk1 t) (idRed:*: (univ (Πⱼ <is≤ 0<1 ▹ <is≤ 0<1 ▹ un-univ ⊢u ▹ un-univ ⊢wkt))) ⊢u ⊢wkt (≅-univ (≅ₜ-Π-cong (<is≤ 0<1) (<is≤ 0<1) ⊢u (≅-un-univ (escapeEqRefl [u])) (≅-un-univ (≅-wk (Twk.step Twk.id) (⊢Γ ∙ ⊢u) (escapeEqRefl [t]))))) [wku] ([nondep] [t] [wku]) ([nondepext] [t] [wku]) [t▹u′] : Γ ⊩⟨ ι ⁰ ⟩ t′ ^ % ° ⁰ ▹▹ u′ ° ⁰ ° ¹ ^ [ % , ι ¹ ] [t▹u′] = Πᵣ′ % ⁰ ⁰ (<is≤ 0<1) (<is≤ 0<1) t′ (wk1 u′) (idRed:*: (univ (Πⱼ <is≤ 0<1 ▹ <is≤ 0<1 ▹ un-univ ⊢t′ ▹ un-univ ⊢wku′))) ⊢t′ ⊢wku′ (≅-univ (≅ₜ-Π-cong (<is≤ 0<1) (<is≤ 0<1) ⊢t′ (≅-un-univ (escapeEqRefl [t′])) (≅-un-univ (≅-wk (Twk.step Twk.id) (⊢Γ ∙ ⊢t′) (escapeEqRefl [u′]))))) [wkt′] ([nondep] [u′] [wkt′]) ([nondepext] [u′] [wkt′]) [u▹t′] : Γ ⊩⟨ ι ⁰ ⟩ u′ ^ % ° ⁰ ▹▹ t′ ° ⁰ ° ¹ ^ [ % , ι ¹ ] [u▹t′] = Πᵣ′ % ⁰ ⁰ (<is≤ 0<1) (<is≤ 0<1) u′ (wk1 t′) (idRed:*: (univ (Πⱼ <is≤ 0<1 ▹ <is≤ 0<1 ▹ un-univ ⊢u′ ▹ un-univ ⊢wkt′))) ⊢u′ ⊢wkt′ (≅-univ (≅ₜ-Π-cong (<is≤ 0<1) (<is≤ 0<1) ⊢u′ (≅-un-univ (escapeEqRefl [u′])) (≅-un-univ (≅-wk (Twk.step Twk.id) (⊢Γ ∙ ⊢u′) (escapeEqRefl [t′]))))) [wku′] ([nondep] [t′] [wku′]) ([nondepext] [t′] [wku′]) [t▹u≡t▹u′] : Γ ⊩⟨ ι ⁰ ⟩ t ^ % ° ⁰ ▹▹ u ° ⁰ ° ¹ ≡ t′ ^ % ° ⁰ ▹▹ u′ ° ⁰ ° ¹ ^ [ % , ι ¹ ] / [t▹u] [t▹u≡t▹u′] = Π₌ t′ (wk1 u′) (id (univ (Πⱼ <is≤ 0<1 ▹ <is≤ 0<1 ▹ un-univ ⊢t′ ▹ un-univ ⊢wku′))) (≅-univ (≅ₜ-Π-cong (<is≤ 0<1) (<is≤ 0<1) ⊢t ⊢t≡t′ (≅ₜ-wk (Twk.step Twk.id) (⊢Γ ∙ ⊢t) ⊢u≡u′))) (λ {ρ} {Δ} ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Lwk.wkEq [ρ] ⊢Δ (emb emb< [t]) [t≡t′]) ([nondepext'] [u] [u′] [u≡u′] [wkt] [wkt′]) [u▹t≡u▹t′] : Γ ⊩⟨ ι ⁰ ⟩ u ^ % ° ⁰ ▹▹ t ° ⁰ ° ¹ ≡ u′ ^ % ° ⁰ ▹▹ t′ ° ⁰ ° ¹ ^ [ % , ι ¹ ] / [u▹t] [u▹t≡u▹t′] = Π₌ u′ (wk1 t′) (id (univ (Πⱼ <is≤ 0<1 ▹ <is≤ 0<1 ▹ un-univ ⊢u′ ▹ un-univ ⊢wkt′))) (≅-univ (≅ₜ-Π-cong (<is≤ 0<1) (<is≤ 0<1) ⊢u ⊢u≡u′ (≅ₜ-wk (Twk.step Twk.id) (⊢Γ ∙ ⊢u) ⊢t≡t′))) (λ {ρ} {Δ} ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Lwk.wkEq [ρ] ⊢Δ (emb emb< [u]) [u≡u′]) ([nondepext'] [t] [t′] [t≡t′] [wku] [wku′]) ⊢t▹u = escape [t▹u] in ∃₌ {l′ = ¹} (t′ ^ % ° ⁰ ▹▹ u′ ° ⁰ ° ¹ ) (wk1 (u′ ^ % ° ⁰ ▹▹ t′ ° ⁰ ° ¹ )) (univ (Id-SProp (un-univ ⊢t′) (un-univ ⊢u′)) ⇨ id (univ (××ⱼ (▹▹ⱼ <is≤ 0<1 ▹ <is≤ 0<1 ▹ un-univ ⊢t′ ▹ un-univ ⊢u′) ▹ (▹▹ⱼ <is≤ 0<1 ▹ <is≤ 0<1 ▹ un-univ ⊢u′ ▹ un-univ ⊢t′)))) (≅-univ (≅ₜ-∃-cong ⊢t▹u (≅ₜ-Π-cong (<is≤ 0<1) (<is≤ 0<1) ⊢t ⊢t≡t′ (≅ₜ-wk (Twk.step Twk.id) (⊢Γ ∙ ⊢t) ⊢u≡u′)) (≅ₜ-Π-cong (<is≤ 0<1) (<is≤ 0<1) (Twk.wk (Twk.step Twk.id) (⊢Γ ∙ ⊢t▹u) ⊢u) (≅ₜ-wk (Twk.step Twk.id) (⊢Γ ∙ ⊢t▹u) ⊢u≡u′) (≅ₜ-wk (Twk.lift (Twk.step Twk.id)) ((⊢Γ ∙ ⊢t▹u) ∙ (Twk.wk (Twk.step Twk.id) (⊢Γ ∙ ⊢t▹u) ⊢u)) (≅ₜ-wk (Twk.step Twk.id) (⊢Γ ∙ ⊢u) ⊢t≡t′)) ))) (λ {ρ} {Δ} ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Lwk.wkEq [ρ] ⊢Δ [t▹u] [t▹u≡t▹u′]) ([nondepext'] (emb emb< [u▹t]) (emb emb< [u▹t′]) [u▹t≡u▹t′] (λ {ρ} {Δ} ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Lwk.wk [ρ] ⊢Δ (emb emb< [t▹u])) (λ {ρ} {Δ} ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Lwk.wk [ρ] ⊢Δ (emb emb< [t▹u′]))) [Id]U : ∀ {A B Γ} (⊢Γ : ⊢ Γ) ([A] : Γ ⊩⟨ ι ⁰ ⟩ A ^ [ ! , ι ⁰ ]) ([B] : Γ ⊩⟨ ι ⁰ ⟩ B ^ [ ! , ι ⁰ ]) → Γ ⊩⟨ ι ¹ ⟩ Id (U ⁰) A B ^ [ % , ι ¹ ] [IdExtShape]U : ∀ {A A′ B B′ Γ} (⊢Γ : ⊢ Γ) ([A] : Γ ⊩⟨ ι ⁰ ⟩ A ^ [ ! , ι ⁰ ]) ([A′] : Γ ⊩⟨ ι ⁰ ⟩ A′ ^ [ ! , ι ⁰ ]) (ShapeA : ShapeView Γ (ι ⁰) (ι ⁰) A A′ [ ! , ι ⁰ ] [ ! , ι ⁰ ] [A] [A′]) ([A≡A′] : Γ ⊩⟨ ι ⁰ ⟩ A ≡ A′ ^ [ ! , ι ⁰ ] / [A]) ([B] : Γ ⊩⟨ ι ⁰ ⟩ B ^ [ ! , ι ⁰ ]) ([B′] : Γ ⊩⟨ ι ⁰ ⟩ B′ ^ [ ! , ι ⁰ ]) (ShapeB : ShapeView Γ (ι ⁰) (ι ⁰) B B′ [ ! , ι ⁰ ] [ ! , ι ⁰ ] [B] [B′]) ([B≡B′] : Γ ⊩⟨ ι ⁰ ⟩ B ≡ B′ ^ [ ! , ι ⁰ ] / [B]) → Γ ⊩⟨ ι ¹ ⟩ Id (U ⁰) A B ≡ Id (U ⁰) A′ B′ ^ [ % , ι ¹ ] / [Id]U ⊢Γ [A] [B] [IdExt]U : ∀ {A A′ B B′ Γ} (⊢Γ : ⊢ Γ) ([A] : Γ ⊩⟨ ι ⁰ ⟩ A ^ [ ! , ι ⁰ ]) ([A′] : Γ ⊩⟨ ι ⁰ ⟩ A′ ^ [ ! , ι ⁰ ]) ([A≡A′] : Γ ⊩⟨ ι ⁰ ⟩ A ≡ A′ ^ [ ! , ι ⁰ ] / [A]) ([B] : Γ ⊩⟨ ι ⁰ ⟩ B ^ [ ! , ι ⁰ ]) ([B′] : Γ ⊩⟨ ι ⁰ ⟩ B′ ^ [ ! , ι ⁰ ]) ([B≡B′] : Γ ⊩⟨ ι ⁰ ⟩ B ≡ B′ ^ [ ! , ι ⁰ ] / [B]) → Γ ⊩⟨ ι ¹ ⟩ Id (U ⁰) A B ≡ Id (U ⁰) A′ B′ ^ [ % , ι ¹ ] / [Id]U ⊢Γ [A] [B] [Id]U {A} {B} ⊢Γ (ne′ K D neK K≡K) [B] = let ⊢B = escape [B] B≡B = escapeEqRefl [B] in ne (ne (Id (U ⁰) K B) (univ:⇒*: (IdURed*Term (un-univ:⇒*: D) (un-univ ⊢B))) (IdUₙ neK) (~-IdU ⊢Γ K≡K (≅-un-univ B≡B))) [Id]U ⊢Γ (ℕᵣ [[ ⊢A , ⊢K , D ]]) (ℕᵣ [[ ⊢B , ⊢L , D₁ ]]) = let ⊢tA = (subset* D) in proj₁ (redSubst* (trans⇒* (univ⇒* (IdURed*Term′ (un-univ ⊢A) (un-univ ⊢K) (un-univ⇒* D) (un-univ ⊢B))) (trans⇒* (univ⇒* (IdUℕRed*Term′ (un-univ ⊢B) (un-univ ⊢L) (un-univ⇒* D₁))) (univ (Id-U-ℕℕ ⊢Γ) ⇨ id (univ (Unitⱼ ⊢Γ))))) (UnitType ⊢Γ)) [Id]U ⊢Γ (ℕᵣ D) (ne′ K D₁ neK K≡K) = let [B] = ne′ K D₁ neK K≡K ⊢B = escape {l = ι ¹} [B] in ne′ (Id (U ⁰) ℕ K) (univ:⇒*: (transTerm:⇒:* (IdURed*Term (un-univ:⇒*: D) (un-univ ⊢B) ) (IdUℕRed*Term (un-univ:⇒*: D₁)))) (IdUℕₙ neK) (~-IdUℕ ⊢Γ K≡K) [Id]U ⊢Γ (ℕᵣ [[ ⊢A , ⊢ℕ , D ]]) (Πᵣ′ rF lF lG (≡is≤ PE.refl) (≡is≤ PE.refl) F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) = let [B] = Πᵣ′ rF lF lG (≡is≤ PE.refl) (≡is≤ PE.refl) F G D′ ⊢F ⊢G A≡A [F] [G] G-ext ⊢B = escape [B] in proj₁ (redSubst* (trans⇒* (univ⇒* (IdURed*Term′ (un-univ ⊢A) (un-univ ⊢ℕ) (un-univ⇒* D) (un-univ ⊢B))) (trans⇒* (univ⇒* (IdUℕRed*Term′ (un-univ ⊢B) (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ (un-univ ⊢F) ▹ (un-univ ⊢G)) (un-univ⇒* (red D′)))) (univ (Id-U-ℕΠ (un-univ ⊢F) (un-univ ⊢G)) ⇨ id (univ (Emptyⱼ ⊢Γ))))) (EmptyType ⊢Γ)) [Id]U ⊢Γ (Πᵣ′ rF lF lG (≡is≤ PE.refl) (≡is≤ PE.refl) F G [[ ⊢A , ⊢Π , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) (ℕᵣ [[ ⊢B , ⊢ℕ , D' ]]) = proj₁ (redSubst* (trans⇒* (univ⇒* (IdURed*Term′ (un-univ ⊢A) (un-univ ⊢Π) (un-univ⇒* D) (un-univ ⊢B))) (trans⇒* (univ⇒* (IdUΠRed*Term′ (un-univ ⊢F) (un-univ ⊢G) (un-univ ⊢B) (un-univ ⊢ℕ) (un-univ⇒* D'))) (univ (Id-U-Πℕ (un-univ ⊢F) (un-univ ⊢G)) ⇨ id (univ (Emptyⱼ ⊢Γ))))) (EmptyType ⊢Γ)) [Id]U ⊢Γ (Πᵣ′ rF lF lG (≡is≤ PE.refl) (≡is≤ PE.refl) F G D ⊢F ⊢G A≡A [F] [G] G-ext) (ne′ K D₁ neK K≡K) = let [B] = ne′ K D₁ neK K≡K ⊢B = escape {l = ι ¹} [B] -- [F]' = PE.subst (λ X → _ ⊩⟨ _ ⟩ X ^ [ _ , _ ]) (wk-id F) ([F] Twk.id ⊢Γ) -- ⊢F≅F = ≅-un-univ (escapeEqRefl [F]') -- [G]' = PE.subst (λ X → _ ⊩⟨ _ ⟩ X ^ [ _ , _ ]) (wkSingleSubstId G) ([G] {a = var 0} (Twk.step Twk.id) (⊢Γ ∙ ⊢F) {!!}) -- ⊢G≅G = ≅-un-univ (escapeEqRefl [G]') in ne′ (Id (U ⁰) (Π F ^ rF ° lF ▹ G ° lG ° ⁰) K) (univ:⇒*: (transTerm:⇒:* (IdURed*Term (un-univ:⇒*: D) (un-univ ⊢B) ) (IdUΠRed*Term (un-univ ⊢F) (un-univ ⊢G) (un-univ:⇒*: D₁)))) (IdUΠₙ neK) (~-IdUΠ (≅-un-univ A≡A) K≡K) [Id]U {A} {B} {Γ} ⊢Γ (Πᵣ′ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F G [[ ⊢A , ⊢ΠFG , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) (Πᵣ′ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₁ G₁ [[ ⊢B , ⊢ΠF₁G₁ , D₁ ]] ⊢F₁ ⊢G₁ B≡B [F₁] [G₁] G₁-ext) = ∃ᵣ′ (Id (U ⁰) F F₁) (IdGG₁ (step id) (var 0)) [[ (univ (Idⱼ (univ 0<1 ⊢Γ) (un-univ ⊢A) (un-univ ⊢B))) , ⊢∃ , D∃ ]] ⊢IdFF₁ ⊢IdGG₁ ∃≡∃ [IdFF₁] (λ {ρ} {Δ} {a} [ρ] ⊢Δ [a] → PE.subst (λ X → Δ ⊩⟨ ι ¹ ⟩ X ^ [ % , ι ¹ ]) (PE.sym (wksubst-IdTel ρ a)) ([IdGG₁] [ρ] ⊢Δ [a])) (λ {ρ} {Δ} {a} {b} [ρ] ⊢Δ [a] [b] [a≡b] → irrelevanceEq″ (PE.sym (wksubst-IdTel ρ a)) (PE.sym (wksubst-IdTel ρ b)) PE.refl PE.refl ([IdGG₁] [ρ] ⊢Δ [a]) (PE.subst (λ X → Δ ⊩⟨ ι ¹ ⟩ X ^ [ % , ι ¹ ]) (PE.sym (wksubst-IdTel ρ a)) ([IdGG₁] [ρ] ⊢Δ [a])) ([IdGG₁-ext] [ρ] ⊢Δ [a] [b] [a≡b])) where open IdTypeU-lemmas ⊢Γ ⊢A ⊢ΠFG D ⊢F ⊢G A≡A [F] [G] G-ext ⊢B ⊢ΠF₁G₁ D₁ ⊢F₁ ⊢G₁ B≡B [F₁] [G₁] G₁-ext (λ [ρ] ⊢Δ → [Id]U ⊢Δ ([F] [ρ] ⊢Δ) ([F₁] [ρ] ⊢Δ)) (λ [ρ] ⊢Δ [x] [y] → [Id]U ⊢Δ ([G] [ρ] ⊢Δ [x]) ([G₁] [ρ] ⊢Δ [y])) (λ [ρ] ⊢Δ [x] [x′] [x≡x′] [y] [y′] [y≡y′] → [IdExt]U ⊢Δ ([G] [ρ] ⊢Δ [x]) ([G] [ρ] ⊢Δ [x′]) (G-ext [ρ] ⊢Δ [x] [x′] [x≡x′]) ([G₁] [ρ] ⊢Δ [y]) ([G₁] [ρ] ⊢Δ [y′]) (G₁-ext [ρ] ⊢Δ [y] [y′] [y≡y′])) [Id]U {A} {B} {Γ} ⊢Γ (Πᵣ′ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F G [[ ⊢A , ⊢ΠFG , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) (Πᵣ′ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₁ G₁ [[ ⊢B , ⊢ΠF₁G₁ , D₁ ]] ⊢F₁ ⊢G₁ B≡B [F₁] [G₁] G₁-ext) = ∃ᵣ′ (Id (SProp ⁰) F F₁) (IdGG₁ (step id) (var 0)) [[ (univ (Idⱼ (univ 0<1 ⊢Γ) (un-univ ⊢A) (un-univ ⊢B))) , ⊢∃ , D∃ ]] ⊢IdFF₁ ⊢IdGG₁ ∃≡∃ [IdFF₁] (λ {ρ} {Δ} {a} [ρ] ⊢Δ [a] → PE.subst (λ X → Δ ⊩⟨ ι ¹ ⟩ X ^ [ % , ι ¹ ]) (PE.sym (wksubst-IdTel ρ a)) ([IdGG₁] [ρ] ⊢Δ [a])) (λ {ρ} {Δ} {a} {b} [ρ] ⊢Δ [a] [b] [a≡b] → irrelevanceEq″ (PE.sym (wksubst-IdTel ρ a)) (PE.sym (wksubst-IdTel ρ b)) PE.refl PE.refl ([IdGG₁] [ρ] ⊢Δ [a]) (PE.subst (λ X → Δ ⊩⟨ ι ¹ ⟩ X ^ [ % , ι ¹ ]) (PE.sym (wksubst-IdTel ρ a)) ([IdGG₁] [ρ] ⊢Δ [a])) ([IdGG₁-ext] [ρ] ⊢Δ [a] [b] [a≡b])) where open IdTypeU-lemmas ⊢Γ ⊢A ⊢ΠFG D ⊢F ⊢G A≡A [F] [G] G-ext ⊢B ⊢ΠF₁G₁ D₁ ⊢F₁ ⊢G₁ B≡B [F₁] [G₁] G₁-ext (λ [ρ] ⊢Δ → [Id]SProp ⊢Δ ([F] [ρ] ⊢Δ) ([F₁] [ρ] ⊢Δ)) (λ [ρ] ⊢Δ [x] [y] → [Id]U ⊢Δ ([G] [ρ] ⊢Δ [x]) ([G₁] [ρ] ⊢Δ [y])) (λ [ρ] ⊢Δ [x] [x′] [x≡x′] [y] [y′] [y≡y′] → [IdExt]U ⊢Δ ([G] [ρ] ⊢Δ [x]) ([G] [ρ] ⊢Δ [x′]) (G-ext [ρ] ⊢Δ [x] [x′] [x≡x′]) ([G₁] [ρ] ⊢Δ [y]) ([G₁] [ρ] ⊢Δ [y′]) (G₁-ext [ρ] ⊢Δ [y] [y′] [y≡y′])) [Id]U ⊢Γ (Πᵣ′ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F G [[ ⊢A , ⊢ΠFG , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) (Πᵣ′ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₁ G₁ [[ ⊢B , ⊢ΠF₁G₁ , D' ]] ⊢F₁ ⊢G₁ B≡B [F₁] [G₁] G₁-ext) = proj₁ (redSubst* (trans⇒* (univ⇒* (IdURed*Term′ (un-univ ⊢A) (un-univ ⊢ΠFG) (un-univ⇒* D) (un-univ ⊢B))) (trans⇒* (univ⇒* (IdUΠRed*Term′ (un-univ ⊢F) (un-univ ⊢G) (un-univ ⊢B) (un-univ ⊢ΠF₁G₁) (un-univ⇒* D'))) (univ (Id-U-ΠΠ!% !≢% (un-univ ⊢F) (un-univ ⊢G) (un-univ ⊢F₁) (un-univ ⊢G₁)) ⇨ id (univ (Emptyⱼ ⊢Γ))))) (EmptyType ⊢Γ)) [Id]U ⊢Γ (Πᵣ′ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F G [[ ⊢A , ⊢ΠFG , D ]] ⊢F ⊢G A≡A [F] [G] G-ext) (Πᵣ′ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₁ G₁ [[ ⊢B , ⊢ΠF₁G₁ , D' ]] ⊢F₁ ⊢G₁ B≡B [F₁] [G₁] G₁-ext) = proj₁ (redSubst* (trans⇒* (univ⇒* (IdURed*Term′ (un-univ ⊢A) (un-univ ⊢ΠFG) (un-univ⇒* D) (un-univ ⊢B))) (trans⇒* (univ⇒* (IdUΠRed*Term′ (un-univ ⊢F) (un-univ ⊢G) (un-univ ⊢B) (un-univ ⊢ΠF₁G₁) (un-univ⇒* D'))) (univ (Id-U-ΠΠ!% (λ e → !≢% (PE.sym e)) (un-univ ⊢F) (un-univ ⊢G) (un-univ ⊢F₁) (un-univ ⊢G₁)) ⇨ id (univ (Emptyⱼ ⊢Γ))))) (EmptyType ⊢Γ)) [IdExtShape]U ⊢Γ _ _ (ℕᵥ ℕA [[ ⊢A , ⊢K , D ]]) [A≡A′] _ _ (ℕᵥ NB [[ ⊢B , ⊢L , D₁ ]]) [B≡B′] = Π₌ (Empty _) (Empty _) (trans⇒* (univ⇒* (IdURed*Term′ (un-univ ⊢A) (un-univ ⊢K) (un-univ⇒* D) (un-univ ⊢B))) (trans⇒* (univ⇒* (IdUℕRed*Term′ (un-univ ⊢B) (un-univ ⊢L) (un-univ⇒* D₁))) (univ (Id-U-ℕℕ ⊢Γ) ⇨ id (univ (Unitⱼ ⊢Γ))))) (≅-univ (Unit≡Unit ⊢Γ)) (λ [ρ] ⊢Δ → id (univ (Emptyⱼ ⊢Δ))) λ [ρ] ⊢Δ [a] → id (univ (Emptyⱼ ⊢Δ)) [IdExtShape]U ⊢Γ _ _ (ℕᵥ ℕA D) [A≡A′] _ _ (ne neB neB') (ne₌ M D′ neM K≡M) = let [[ ⊢B , _ , _ ]] = D′ in ne₌ (Id (U ⁰) ℕ M) (univ:⇒*: (transTerm:⇒:* (IdURed*Term (un-univ:⇒*: D) (un-univ ⊢B) ) (IdUℕRed*Term (un-univ:⇒*: D′)))) (IdUℕₙ neM) (~-IdUℕ ⊢Γ K≡M) [IdExtShape]U ⊢Γ _ _ (ℕᵥ [[ ⊢A , ⊢ℕ , D ]] [[ ⊢A' , ⊢ℕ' , D' ]]) [A≡A′] _ _ (Πᵥ (Πᵣ rF lF lG (≡is≤ PE.refl) (≡is≤ PE.refl) F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) (Πᵣ rF' lF' lG' (≡is≤ PE.refl) (≡is≤ PE.refl) F' G' D′' ⊢F' ⊢G' A≡A' [F]' [G]' G-ext')) [B≡B′] = let [B]' = Πᵣ′ rF' lF' lG' (≡is≤ PE.refl) (≡is≤ PE.refl) F' G' D′' ⊢F' ⊢G' A≡A' [F]' [G]' G-ext' ⊢B' = escape [B]' in trans⇒* (univ⇒* (IdURed*Term′ (un-univ ⊢A') (un-univ ⊢ℕ') (un-univ⇒* D') (un-univ ⊢B'))) (trans⇒* (univ⇒* (IdUℕRed*Term′ (un-univ ⊢B') (Πⱼ ≡is≤ PE.refl ▹ ≡is≤ PE.refl ▹ (un-univ ⊢F') ▹ (un-univ ⊢G')) (un-univ⇒* (red D′')))) (univ (Id-U-ℕΠ (un-univ ⊢F') (un-univ ⊢G')) ⇨ id (univ (Emptyⱼ ⊢Γ)))) [IdExtShape]U {A} {A′} {B} {B′} ⊢Γ _ _ (ne neA neA') (ne₌ M D neM K≡M) [B] [B'] [ShapeB] [B≡B′] = let ⊢B' = escape [B'] B≡B' = escapeEq [B] [B≡B′] in ne₌ (Id (U ⁰) M B′) (univ:⇒*: (IdURed*Term (un-univ:⇒*: D) (un-univ ⊢B'))) (IdUₙ neM) (~-IdU ⊢Γ K≡M (≅-un-univ B≡B')) [IdExtShape]U ⊢Γ _ _ (Πᵥ (Πᵣ rF lF lG (≡is≤ PE.refl) (≡is≤ PE.refl) F G D′ ⊢F ⊢G A≡A [F] [G] G-ext) (Πᵣ rF' lF' lG' (≡is≤ PE.refl) (≡is≤ PE.refl) F' G' [[ ⊢A' , ⊢Π' , DΠ' ]] ⊢F' ⊢G' A≡A' [F]' [G]' G-ext')) [A≡A′] _ _ (ℕᵥ [[ ⊢A , ⊢ℕ , D ]] [[ ⊢B' , ⊢ℕ' , D' ]]) [B≡B′] = trans⇒* (univ⇒* (IdURed*Term′ (un-univ ⊢A') (un-univ ⊢Π') (un-univ⇒* DΠ') (un-univ ⊢B'))) (trans⇒* (univ⇒* (IdUΠRed*Term′ (un-univ ⊢F') (un-univ ⊢G') (un-univ ⊢B') (un-univ ⊢ℕ') (un-univ⇒* D'))) (univ (Id-U-Πℕ (un-univ ⊢F') (un-univ ⊢G')) ⇨ id (univ (Emptyⱼ ⊢Γ)))) [IdExtShape]U ⊢Γ _ _ (Πᵥ (Πᵣ rF' .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F' G' De' ⊢F' ⊢G' A≡A' [F]' [G]' G-ext') (Πᵣ rF .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F G D ⊢F ⊢G A≡A [F] [G] G-ext)) (Π₌ F′ G′ D′₁ A≡B [F≡F′] [G≡G′]) _ _ (ne neA neB) (ne₌ M D′ neM K≡M) = let [[ ⊢B , _ , _ ]] = D′ Π≡Π = whrDet* (red D , Whnf.Πₙ) (D′₁ , Whnf.Πₙ) F≡F' , rF≡rF' , _ , G≡G' , _ = Π-PE-injectivity Π≡Π in ne₌ (Id (U ⁰) (Π F ^ rF ° ⁰ ▹ G ° ⁰ ° ⁰) M) (univ:⇒*: (transTerm:⇒:* (IdURed*Term (un-univ:⇒*: D) (un-univ ⊢B) ) (IdUΠRed*Term (un-univ ⊢F) (un-univ ⊢G) (un-univ:⇒*: D′)))) (IdUΠₙ neM) (PE.subst (λ X → _ ⊢ Id (U ⁰) (Π F' ^ rF' ° ⁰ ▹ G' ° ⁰ ° ⁰) _ ~ Id (U ⁰) (Π F ^ X ° ⁰ ▹ G ° ⁰ ° ⁰) M ∷ SProp _ ^ _) (PE.sym rF≡rF') (~-IdUΠ (≅-un-univ (PE.subst (λ X → _ ⊢ Π F' ^ rF' ° ⁰ ▹ G' ° ⁰ ° ⁰ ≅ Π F ^ rF' ° ⁰ ▹ X ° ⁰ ° ⁰ ^ _ ) (PE.sym G≡G') (PE.subst (λ X → _ ⊢ Π F' ^ rF' ° ⁰ ▹ G' ° ⁰ ° ⁰ ≅ Π X ^ rF' ° ⁰ ▹ G′ ° ⁰ ° ⁰ ^ _ ) (PE.sym F≡F') A≡B))) K≡M)) [IdExtShape]U ⊢Γ _ _ (Πᵥ (Πᵣ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₁ G₁ [[ ⊢A₁ , ⊢ΠF₁G₁ , D₁ ]] ⊢F₁ ⊢G₁ A₁≡A₁ [F₁] [G₁] G₁-ext) (Πᵣ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₂ G₂ [[ ⊢A₂ , ⊢ΠF₂G₂ , D₂ ]] ⊢F₂ ⊢G₂ A₂≡A₂ [F₂] [G₂] G₂-ext)) (Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) _ _ (Πᵥ _ _) (Π₌ F′₁ G′₁ D′₁ A≡B₁ [F≡F′]₁ [G≡G′]₁) = let ΠFG′≡ΠFG′₁ = whrDet* (D₂ , Πₙ) (D′ , Πₙ) F′≡F′₁ , rF≡rF′ , _ , G′≡G′₁ , _ = Π-PE-injectivity ΠFG′≡ΠFG′₁ in ⊥-elim (!≢% rF≡rF′) [IdExtShape]U ⊢Γ _ _ (Πᵥ (Πᵣ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₁ G₁ [[ ⊢A₁ , ⊢ΠF₁G₁ , D₁ ]] ⊢F₁ ⊢G₁ A₁≡A₁ [F₁] [G₁] G₁-ext) (Πᵣ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₂ G₂ [[ ⊢A₂ , ⊢ΠF₂G₂ , D₂ ]] ⊢F₂ ⊢G₂ A₂≡A₂ [F₂] [G₂] G₂-ext)) (Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) _ _ (Πᵥ _ _) (Π₌ F′₁ G′₁ D′₁ A≡B₁ [F≡F′]₁ [G≡G′]₁) = let ΠFG′≡ΠFG′₁ = whrDet* (D₂ , Πₙ) (D′ , Πₙ) F′≡F′₁ , rF≡rF′ , _ , G′≡G′₁ , _ = Π-PE-injectivity ΠFG′≡ΠFG′₁ in ⊥-elim (!≢% (PE.sym rF≡rF′)) [IdExtShape]U ⊢Γ _ _ (Πᵥ _ _) (Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) _ _ (Πᵥ (Πᵣ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₁ G₁ [[ ⊢A₁ , ⊢ΠF₁G₁ , D₁ ]] ⊢F₁ ⊢G₁ A₁≡A₁ [F₁] [G₁] G₁-ext) (Πᵣ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₂ G₂ [[ ⊢A₂ , ⊢ΠF₂G₂ , D₂ ]] ⊢F₂ ⊢G₂ A₂≡A₂ [F₂] [G₂] G₂-ext)) (Π₌ F′₁ G′₁ D′₁ A≡B₁ [F≡F′]₁ [G≡G′]₁) = let ΠFG′≡ΠFG′₁ = whrDet* (D₂ , Πₙ) (D′₁ , Πₙ) F′≡F′₁ , rF≡rF′ , _ , G′≡G′₁ , _ = Π-PE-injectivity ΠFG′≡ΠFG′₁ in ⊥-elim (!≢% rF≡rF′) [IdExtShape]U ⊢Γ _ _ (Πᵥ _ _) (Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) _ _ (Πᵥ (Πᵣ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₁ G₁ [[ ⊢A₁ , ⊢ΠF₁G₁ , D₁ ]] ⊢F₁ ⊢G₁ A₁≡A₁ [F₁] [G₁] G₁-ext) (Πᵣ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₂ G₂ [[ ⊢A₂ , ⊢ΠF₂G₂ , D₂ ]] ⊢F₂ ⊢G₂ A₂≡A₂ [F₂] [G₂] G₂-ext)) (Π₌ F′₁ G′₁ D′₁ A≡B₁ [F≡F′]₁ [G≡G′]₁) = let ΠFG′≡ΠFG′₁ = whrDet* (D₂ , Πₙ) (D′₁ , Πₙ) F′≡F′₁ , rF≡rF′ , _ , G′≡G′₁ , _ = Π-PE-injectivity ΠFG′≡ΠFG′₁ in ⊥-elim (!≢% (PE.sym rF≡rF′)) [IdExtShape]U ⊢Γ _ _ (Πᵥ (Πᵣ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₁ G₁ [[ ⊢A₁ , ⊢ΠF₁G₁ , D₁ ]] ⊢F₁ ⊢G₁ A₁≡A₁ [F₁] [G₁] G₁-ext) (Πᵣ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₂ G₂ [[ ⊢A₂ , ⊢ΠF₂G₂ , D₂ ]] ⊢F₂ ⊢G₂ A₂≡A₂ [F₂] [G₂] G₂-ext)) (Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) _ _ (Πᵥ (Πᵣ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₃ G₃ [[ ⊢A₃ , ⊢ΠF₃G₃ , D₃ ]] ⊢F₃ ⊢G₃ A₃≡A₃ [F₃] [G₃] G₃-ext) (Πᵣ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₄ G₄ [[ ⊢A₄ , ⊢ΠF₄G₄ , D₄ ]] ⊢F₄ ⊢G₄ A₄≡A₄ [F₄] [G₄] G₄-ext)) (Π₌ F′₁ G′₁ D′₁ A≡B₁ [F≡F′]₁ [G≡G′]₁) = trans⇒* (univ⇒* (IdURed*Term′ (un-univ ⊢A₂) (un-univ ⊢ΠF₂G₂) (un-univ⇒* D₂) (un-univ ⊢A₄))) (trans⇒* (univ⇒* (IdUΠRed*Term′ (un-univ ⊢F₂) (un-univ ⊢G₂) (un-univ ⊢A₄) (un-univ ⊢ΠF₄G₄) (un-univ⇒* D₄))) (univ (Id-U-ΠΠ!% !≢% (un-univ ⊢F₂) (un-univ ⊢G₂) (un-univ ⊢F₄) (un-univ ⊢G₄)) ⇨ id (univ (Emptyⱼ ⊢Γ)))) [IdExtShape]U ⊢Γ _ _ (Πᵥ (Πᵣ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₁ G₁ [[ ⊢A₁ , ⊢ΠF₁G₁ , D₁ ]] ⊢F₁ ⊢G₁ A₁≡A₁ [F₁] [G₁] G₁-ext) (Πᵣ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₂ G₂ [[ ⊢A₂ , ⊢ΠF₂G₂ , D₂ ]] ⊢F₂ ⊢G₂ A₂≡A₂ [F₂] [G₂] G₂-ext)) (Π₌ F′ G′ D′ A≡B [F≡F′] [G≡G′]) _ _ (Πᵥ (Πᵣ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₃ G₃ [[ ⊢A₃ , ⊢ΠF₃G₃ , D₃ ]] ⊢F₃ ⊢G₃ A₃≡A₃ [F₃] [G₃] G₃-ext) (Πᵣ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₄ G₄ [[ ⊢A₄ , ⊢ΠF₄G₄ , D₄ ]] ⊢F₄ ⊢G₄ A₄≡A₄ [F₄] [G₄] G₄-ext)) (Π₌ F′₁ G′₁ D′₁ A≡B₁ [F≡F′]₁ [G≡G′]₁) = trans⇒* (univ⇒* (IdURed*Term′ (un-univ ⊢A₂) (un-univ ⊢ΠF₂G₂) (un-univ⇒* D₂) (un-univ ⊢A₄))) (trans⇒* (univ⇒* (IdUΠRed*Term′ (un-univ ⊢F₂) (un-univ ⊢G₂) (un-univ ⊢A₄) (un-univ ⊢ΠF₄G₄) (un-univ⇒* D₄))) (univ (Id-U-ΠΠ!% (λ e → !≢% (PE.sym e)) (un-univ ⊢F₂) (un-univ ⊢G₂) (un-univ ⊢F₄) (un-univ ⊢G₄)) ⇨ id (univ (Emptyⱼ ⊢Γ)))) [IdExtShape]U {A₁} {A₂} {A₃} {A₄} {Γ} ⊢Γ _ _ (Πᵥ (Πᵣ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₁ G₁ [[ ⊢A₁ , ⊢ΠF₁G₁ , D₁ ]] ⊢F₁ ⊢G₁ A₁≡A₁ [F₁] [G₁] G₁-ext) (Πᵣ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₂ G₂ [[ ⊢A₂ , ⊢ΠF₂G₂ , D₂ ]] ⊢F₂ ⊢G₂ A₂≡A₂ [F₂] [G₂] G₂-ext)) (Π₌ F₂′ G₂′ D₂′ A₁≡A₂′ [F₁≡F₂′] [G₁≡G₂′]) _ _ (Πᵥ (Πᵣ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₃ G₃ [[ ⊢A₃ , ⊢ΠF₃G₃ , D₃ ]] ⊢F₃ ⊢G₃ A₃≡A₃ [F₃] [G₃] G₃-ext) (Πᵣ ! .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₄ G₄ [[ ⊢A₄ , ⊢ΠF₄G₄ , D₄ ]] ⊢F₄ ⊢G₄ A₄≡A₄ [F₄] [G₄] G₄-ext)) (Π₌ F₄′ G₄′ D₄′ A₃≡A₄′ [F₃≡F₄′] [G₃≡G₄′]) = ∃₌ (Id (U ⁰) F₂ F₄) (E₂.IdGG₁ (step id) (var 0)) E₂.D∃ ∃₁≡∃₂ [IdFF₁≡IdFF₂] (λ {ρ} {Δ} {e} [ρ] ⊢Δ [e] → irrelevanceEq″ (PE.sym (E₁.wksubst-IdTel ρ e)) (PE.sym (E₂.wksubst-IdTel ρ e)) PE.refl PE.refl (E₁.[IdGG₁] [ρ] ⊢Δ [e]) (PE.subst (λ X → Δ ⊩⟨ ι ¹ ⟩ X ^ [ % , ι ¹ ]) (PE.sym (E₁.wksubst-IdTel ρ e)) (E₁.[IdGG₁] [ρ] ⊢Δ [e])) ([IdGG₁≡IdGG₂] [ρ] ⊢Δ [e])) where Π≡Π = whrDet* (D₂ , Whnf.Πₙ) (D₂′ , Whnf.Πₙ) F₂≡F₂′ = let x , _ , _ , _ , _ = Π-PE-injectivity Π≡Π in x G₂≡G₂′ = let _ , _ , _ , x , _ = Π-PE-injectivity Π≡Π in x Π≡Π′ = whrDet* (D₄ , Whnf.Πₙ) (D₄′ , Whnf.Πₙ) F₄≡F₄′ = let x , _ , _ , _ , _ = Π-PE-injectivity Π≡Π′ in x G₄≡G₄′ = let _ , _ , _ , x , _ = Π-PE-injectivity Π≡Π′ in x A₁≡A₂ = PE.subst₂ (λ X Y → Γ ⊢ Π F₁ ^ ! ° ⁰ ▹ G₁ ° ⁰ ° ⁰ ≅ Π X ^ ! ° ⁰ ▹ Y ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]) (PE.sym F₂≡F₂′) (PE.sym G₂≡G₂′) A₁≡A₂′ A₃≡A₄ = PE.subst₂ (λ X Y → Γ ⊢ Π F₃ ^ ! ° ⁰ ▹ G₃ ° ⁰ ° ⁰ ≅ Π X ^ ! ° ⁰ ▹ Y ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]) (PE.sym F₄≡F₄′) (PE.sym G₄≡G₄′) A₃≡A₄′ [F₁≡F₂] = PE.subst (λ X → ∀ {ρ Δ} → ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Δ ⊩⟨ ι ⁰ ⟩ wk ρ F₁ ≡ wk ρ X ^ [ ! , ι ⁰ ] / [F₁] [ρ] ⊢Δ) (PE.sym F₂≡F₂′) [F₁≡F₂′] [F₃≡F₄] = PE.subst (λ X → ∀ {ρ Δ} → ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Δ ⊩⟨ ι ⁰ ⟩ wk ρ F₃ ≡ wk ρ X ^ [ ! , ι ⁰ ] / [F₃] [ρ] ⊢Δ) (PE.sym F₄≡F₄′) [F₃≡F₄′] [G₁≡G₂] = PE.subst (λ X → ∀ {ρ Δ a} → ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → ([a] : Δ ⊩⟨ ι ⁰ ⟩ a ∷ wk ρ F₁ ^ [ ! , ι ⁰ ] / [F₁] [ρ] ⊢Δ) → Δ ⊩⟨ ι ⁰ ⟩ wk (lift ρ) G₁ [ a ] ≡ wk (lift ρ) X [ a ] ^ [ ! , ι ⁰ ] / [G₁] [ρ] ⊢Δ [a]) (PE.sym G₂≡G₂′) [G₁≡G₂′] [G₃≡G₄] = PE.subst (λ X → ∀ {ρ Δ a} → ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → ([a] : Δ ⊩⟨ ι ⁰ ⟩ a ∷ wk ρ F₃ ^ [ ! , ι ⁰ ] / [F₃] [ρ] ⊢Δ) → Δ ⊩⟨ ι ⁰ ⟩ wk (lift ρ) G₃ [ a ] ≡ wk (lift ρ) X [ a ] ^ [ ! , ι ⁰ ] / [G₃] [ρ] ⊢Δ [a]) (PE.sym G₄≡G₄′) [G₃≡G₄′] open IdTypeU-lemmas-2 ⊢Γ ⊢A₁ ⊢ΠF₁G₁ D₁ ⊢F₁ ⊢G₁ A₁≡A₁ [F₁] [G₁] G₁-ext ⊢A₂ ⊢ΠF₂G₂ D₂ ⊢F₂ ⊢G₂ A₂≡A₂ [F₂] [G₂] G₂-ext ⊢A₃ ⊢ΠF₃G₃ D₃ ⊢F₃ ⊢G₃ A₃≡A₃ [F₃] [G₃] G₃-ext ⊢A₄ ⊢ΠF₄G₄ D₄ ⊢F₄ ⊢G₄ A₄≡A₄ [F₄] [G₄] G₄-ext A₁≡A₂ A₃≡A₄ [F₁≡F₂] [F₃≡F₄] [G₁≡G₂] [G₃≡G₄] (λ [ρ] ⊢Δ → [Id]U ⊢Δ ([F₁] [ρ] ⊢Δ) ([F₃] [ρ] ⊢Δ)) (λ [ρ] ⊢Δ [x] [y] → [Id]U ⊢Δ ([G₁] [ρ] ⊢Δ [x]) ([G₃] [ρ] ⊢Δ [y])) (λ [ρ] ⊢Δ → [Id]U ⊢Δ ([F₂] [ρ] ⊢Δ) ([F₄] [ρ] ⊢Δ)) (λ [ρ] ⊢Δ [x] [y] → [Id]U ⊢Δ ([G₂] [ρ] ⊢Δ [x]) ([G₄] [ρ] ⊢Δ [y])) (λ [ρ] ⊢Δ [x] [x′] [x≡x′] [y] [y′] [y≡y′] → [IdExt]U ⊢Δ ([G₁] [ρ] ⊢Δ [x]) ([G₁] [ρ] ⊢Δ [x′]) (G₁-ext [ρ] ⊢Δ [x] [x′] [x≡x′]) ([G₃] [ρ] ⊢Δ [y]) ([G₃] [ρ] ⊢Δ [y′]) (G₃-ext [ρ] ⊢Δ [y] [y′] [y≡y′])) (λ [ρ] ⊢Δ [x] [x′] [x≡x′] [y] [y′] [y≡y′] → [IdExt]U ⊢Δ ([G₂] [ρ] ⊢Δ [x]) ([G₂] [ρ] ⊢Δ [x′]) (G₂-ext [ρ] ⊢Δ [x] [x′] [x≡x′]) ([G₄] [ρ] ⊢Δ [y]) ([G₄] [ρ] ⊢Δ [y′]) (G₄-ext [ρ] ⊢Δ [y] [y′] [y≡y′])) (λ [ρ] ⊢Δ → [IdExt]U ⊢Δ ([F₁] [ρ] ⊢Δ) ([F₂] [ρ] ⊢Δ) ([F₁≡F₂] [ρ] ⊢Δ) ([F₃] [ρ] ⊢Δ) ([F₄] [ρ] ⊢Δ) ([F₃≡F₄] [ρ] ⊢Δ)) (λ [ρ] ⊢Δ [x₁] [x₂] [G₁x₁≡G₂x₂] [x₃] [x₄] [G₃x₃≡G₄x₄] → [IdExt]U ⊢Δ ([G₁] [ρ] ⊢Δ [x₁]) ([G₂] [ρ] ⊢Δ [x₂]) [G₁x₁≡G₂x₂] ([G₃] [ρ] ⊢Δ [x₃]) ([G₄] [ρ] ⊢Δ [x₄]) [G₃x₃≡G₄x₄]) [IdExtShape]U {A₁} {A₂} {A₃} {A₄} {Γ} ⊢Γ _ _ (Πᵥ (Πᵣ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₁ G₁ [[ ⊢A₁ , ⊢ΠF₁G₁ , D₁ ]] ⊢F₁ ⊢G₁ A₁≡A₁ [F₁] [G₁] G₁-ext) (Πᵣ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₂ G₂ [[ ⊢A₂ , ⊢ΠF₂G₂ , D₂ ]] ⊢F₂ ⊢G₂ A₂≡A₂ [F₂] [G₂] G₂-ext)) (Π₌ F₂′ G₂′ D₂′ A₁≡A₂′ [F₁≡F₂′] [G₁≡G₂′]) _ _ (Πᵥ (Πᵣ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₃ G₃ [[ ⊢A₃ , ⊢ΠF₃G₃ , D₃ ]] ⊢F₃ ⊢G₃ A₃≡A₃ [F₃] [G₃] G₃-ext) (Πᵣ % .⁰ .⁰ (≡is≤ PE.refl) (≡is≤ PE.refl) F₄ G₄ [[ ⊢A₄ , ⊢ΠF₄G₄ , D₄ ]] ⊢F₄ ⊢G₄ A₄≡A₄ [F₄] [G₄] G₄-ext)) (Π₌ F₄′ G₄′ D₄′ A₃≡A₄′ [F₃≡F₄′] [G₃≡G₄′]) = ∃₌ (Id (SProp ⁰) F₂ F₄) (E₂.IdGG₁ (step id) (var 0)) E₂.D∃ ∃₁≡∃₂ [IdFF₁≡IdFF₂] (λ {ρ} {Δ} {e} [ρ] ⊢Δ [e] → irrelevanceEq″ (PE.sym (E₁.wksubst-IdTel ρ e)) (PE.sym (E₂.wksubst-IdTel ρ e)) PE.refl PE.refl (E₁.[IdGG₁] [ρ] ⊢Δ [e]) (PE.subst (λ X → Δ ⊩⟨ ι ¹ ⟩ X ^ [ % , ι ¹ ]) (PE.sym (E₁.wksubst-IdTel ρ e)) (E₁.[IdGG₁] [ρ] ⊢Δ [e])) ([IdGG₁≡IdGG₂] [ρ] ⊢Δ [e])) where Π≡Π = whrDet* (D₂ , Whnf.Πₙ) (D₂′ , Whnf.Πₙ) F₂≡F₂′ = let x , _ , _ , _ , _ = Π-PE-injectivity Π≡Π in x G₂≡G₂′ = let _ , _ , _ , x , _ = Π-PE-injectivity Π≡Π in x Π≡Π′ = whrDet* (D₄ , Whnf.Πₙ) (D₄′ , Whnf.Πₙ) F₄≡F₄′ = let x , _ , _ , _ , _ = Π-PE-injectivity Π≡Π′ in x G₄≡G₄′ = let _ , _ , _ , x , _ = Π-PE-injectivity Π≡Π′ in x A₁≡A₂ = PE.subst₂ (λ X Y → Γ ⊢ Π F₁ ^ % ° ⁰ ▹ G₁ ° ⁰ ° ⁰ ≅ Π X ^ % ° ⁰ ▹ Y ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]) (PE.sym F₂≡F₂′) (PE.sym G₂≡G₂′) A₁≡A₂′ A₃≡A₄ = PE.subst₂ (λ X Y → Γ ⊢ Π F₃ ^ % ° ⁰ ▹ G₃ ° ⁰ ° ⁰ ≅ Π X ^ % ° ⁰ ▹ Y ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]) (PE.sym F₄≡F₄′) (PE.sym G₄≡G₄′) A₃≡A₄′ [F₁≡F₂] = PE.subst (λ X → ∀ {ρ Δ} → ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Δ ⊩⟨ ι ⁰ ⟩ wk ρ F₁ ≡ wk ρ X ^ [ % , ι ⁰ ] / [F₁] [ρ] ⊢Δ) (PE.sym F₂≡F₂′) [F₁≡F₂′] [F₃≡F₄] = PE.subst (λ X → ∀ {ρ Δ} → ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → Δ ⊩⟨ ι ⁰ ⟩ wk ρ F₃ ≡ wk ρ X ^ [ % , ι ⁰ ] / [F₃] [ρ] ⊢Δ) (PE.sym F₄≡F₄′) [F₃≡F₄′] [G₁≡G₂] = PE.subst (λ X → ∀ {ρ Δ a} → ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → ([a] : Δ ⊩⟨ ι ⁰ ⟩ a ∷ wk ρ F₁ ^ [ % , ι ⁰ ] / [F₁] [ρ] ⊢Δ) → Δ ⊩⟨ ι ⁰ ⟩ wk (lift ρ) G₁ [ a ] ≡ wk (lift ρ) X [ a ] ^ [ ! , ι ⁰ ] / [G₁] [ρ] ⊢Δ [a]) (PE.sym G₂≡G₂′) [G₁≡G₂′] [G₃≡G₄] = PE.subst (λ X → ∀ {ρ Δ a} → ([ρ] : ρ Twk.∷ Δ ⊆ Γ) (⊢Δ : ⊢ Δ) → ([a] : Δ ⊩⟨ ι ⁰ ⟩ a ∷ wk ρ F₃ ^ [ % , ι ⁰ ] / [F₃] [ρ] ⊢Δ) → Δ ⊩⟨ ι ⁰ ⟩ wk (lift ρ) G₃ [ a ] ≡ wk (lift ρ) X [ a ] ^ [ ! , ι ⁰ ] / [G₃] [ρ] ⊢Δ [a]) (PE.sym G₄≡G₄′) [G₃≡G₄′] open IdTypeU-lemmas-2 ⊢Γ ⊢A₁ ⊢ΠF₁G₁ D₁ ⊢F₁ ⊢G₁ A₁≡A₁ [F₁] [G₁] G₁-ext ⊢A₂ ⊢ΠF₂G₂ D₂ ⊢F₂ ⊢G₂ A₂≡A₂ [F₂] [G₂] G₂-ext ⊢A₃ ⊢ΠF₃G₃ D₃ ⊢F₃ ⊢G₃ A₃≡A₃ [F₃] [G₃] G₃-ext ⊢A₄ ⊢ΠF₄G₄ D₄ ⊢F₄ ⊢G₄ A₄≡A₄ [F₄] [G₄] G₄-ext A₁≡A₂ A₃≡A₄ [F₁≡F₂] [F₃≡F₄] [G₁≡G₂] [G₃≡G₄] (λ [ρ] ⊢Δ → [Id]SProp ⊢Δ ([F₁] [ρ] ⊢Δ) ([F₃] [ρ] ⊢Δ)) (λ [ρ] ⊢Δ [x] [y] → [Id]U ⊢Δ ([G₁] [ρ] ⊢Δ [x]) ([G₃] [ρ] ⊢Δ [y])) (λ [ρ] ⊢Δ → [Id]SProp ⊢Δ ([F₂] [ρ] ⊢Δ) ([F₄] [ρ] ⊢Δ)) (λ [ρ] ⊢Δ [x] [y] → [Id]U ⊢Δ ([G₂] [ρ] ⊢Δ [x]) ([G₄] [ρ] ⊢Δ [y])) (λ [ρ] ⊢Δ [x] [x′] [x≡x′] [y] [y′] [y≡y′] → [IdExt]U ⊢Δ ([G₁] [ρ] ⊢Δ [x]) ([G₁] [ρ] ⊢Δ [x′]) (G₁-ext [ρ] ⊢Δ [x] [x′] [x≡x′]) ([G₃] [ρ] ⊢Δ [y]) ([G₃] [ρ] ⊢Δ [y′]) (G₃-ext [ρ] ⊢Δ [y] [y′] [y≡y′])) (λ [ρ] ⊢Δ [x] [x′] [x≡x′] [y] [y′] [y≡y′] → [IdExt]U ⊢Δ ([G₂] [ρ] ⊢Δ [x]) ([G₂] [ρ] ⊢Δ [x′]) (G₂-ext [ρ] ⊢Δ [x] [x′] [x≡x′]) ([G₄] [ρ] ⊢Δ [y]) ([G₄] [ρ] ⊢Δ [y′]) (G₄-ext [ρ] ⊢Δ [y] [y′] [y≡y′])) (λ [ρ] ⊢Δ → [IdExt]SProp ⊢Δ ([F₁] [ρ] ⊢Δ) ([F₂] [ρ] ⊢Δ) ([F₁≡F₂] [ρ] ⊢Δ) ([F₃] [ρ] ⊢Δ) ([F₄] [ρ] ⊢Δ) ([F₃≡F₄] [ρ] ⊢Δ)) (λ [ρ] ⊢Δ [x₁] [x₂] [G₁x₁≡G₂x₂] [x₃] [x₄] [G₃x₃≡G₄x₄] → [IdExt]U ⊢Δ ([G₁] [ρ] ⊢Δ [x₁]) ([G₂] [ρ] ⊢Δ [x₂]) [G₁x₁≡G₂x₂] ([G₃] [ρ] ⊢Δ [x₃]) ([G₄] [ρ] ⊢Δ [x₄]) [G₃x₃≡G₄x₄]) [IdExt]U ⊢Γ [A] [A′] [A≡A′] [B] [B′] [B≡B′] = [IdExtShape]U ⊢Γ [A] [A′] (goodCases [A] [A′] [A≡A′]) [A≡A′] [B] [B′] (goodCases [B] [B′] [B≡B′]) [B≡B′] Ugen' : ∀ {Γ rU l} → (⊢Γ : ⊢ Γ) → ((next l) LogRel.⊩¹U logRelRec (next l) ^ Γ) (Univ rU l) (next l) Ugen' {Γ} {rU} {⁰} ⊢Γ = Uᵣ rU ⁰ emb< PE.refl ((idRed:*: (Ugenⱼ ⊢Γ))) Ugen' {Γ} {rU} {¹} ⊢Γ = Uᵣ rU ¹ ∞< PE.refl (idRed:*: (Uⱼ ⊢Γ)) [Id]UGen : ∀ {A t u Γ l} (⊢Γ : ⊢ Γ) ([A] : (l LogRel.⊩¹U logRelRec l ^ Γ) A (ι ¹)) ([t] : Γ ⊩⟨ l ⟩ t ∷ A ^ [ ! , ι ¹ ] / Uᵣ [A]) ([u] : Γ ⊩⟨ l ⟩ u ∷ A ^ [ ! , ι ¹ ] / Uᵣ [A]) → Γ ⊩⟨ l ⟩ Id A t u ^ [ % , ι ¹ ] [Id]UGen {A} {t} {u} {Γ} {ι .¹} ⊢Γ (Uᵣ ! ⁰ emb< PE.refl [[ ⊢A , ⊢B , D ]]) (Uₜ K d typeK K≡K [t]) (Uₜ M d₁ typeM M≡M [u]) = let [t0] : Γ ⊩⟨ ι ⁰ ⟩ t ^ [ ! , ι ⁰ ] [t0] = PE.subst (λ X → Γ ⊩⟨ ι ⁰ ⟩ X ^ [ ! , ι ⁰ ]) (wk-id t) ([t] Twk.id ⊢Γ) [u0] = PE.subst (λ X → Γ ⊩⟨ ι ⁰ ⟩ X ^ [ ! , ι ⁰ ]) (wk-id u) ([u] Twk.id ⊢Γ) ⊢tA = conv (un-univ (escape [t0])) (sym (subset* D)) ⊢uA = conv (un-univ (escape [u0])) (sym (subset* D)) in proj₁ (redSubst* (IdRed* ⊢tA ⊢uA D) ([Id]U ⊢Γ [t0] [u0])) [Id]UGen {A} {t} {u} {Γ} {ι .¹} ⊢Γ (Uᵣ % ⁰ emb< PE.refl [[ ⊢A , ⊢B , D ]]) (Uₜ K d typeK K≡K [t]) (Uₜ M d₁ typeM M≡M [u]) = let [t0] : Γ ⊩⟨ ι ⁰ ⟩ t ^ [ % , ι ⁰ ] [t0] = PE.subst (λ X → Γ ⊩⟨ ι ⁰ ⟩ X ^ [ % , ι ⁰ ]) (wk-id t) ([t] Twk.id ⊢Γ) [u0] = PE.subst (λ X → Γ ⊩⟨ ι ⁰ ⟩ X ^ [ % , ι ⁰ ]) (wk-id u) ([u] Twk.id ⊢Γ) ⊢tA = conv (un-univ (escape [t0])) (sym (subset* D)) ⊢uA = conv (un-univ (escape [u0])) (sym (subset* D)) in proj₁ (redSubst* (IdRed* ⊢tA ⊢uA D) ([Id]SProp ⊢Γ [t0] [u0])) [IdExt]UGen : ∀ {A B t v u w Γ l l'} (⊢Γ : ⊢ Γ) ([A] : (l LogRel.⊩¹U logRelRec l ^ Γ) A (ι ¹)) ([B] : (l' LogRel.⊩¹U logRelRec l' ^ Γ) B (ι ¹)) ([A≡B] : Γ ⊩⟨ l ⟩ A ≡ B ^ [ ! , ι ¹ ] / Uᵣ [A]) ([t] : Γ ⊩⟨ l ⟩ t ∷ A ^ [ ! , ι ¹ ] / Uᵣ [A]) ([v] : Γ ⊩⟨ l' ⟩ v ∷ B ^ [ ! , ι ¹ ] / Uᵣ [B]) ([t≡v] : Γ ⊩⟨ l ⟩ t ≡ v ∷ A ^ [ ! , ι ¹ ] / Uᵣ [A]) ([u] : Γ ⊩⟨ l ⟩ u ∷ A ^ [ ! , ι ¹ ] / Uᵣ [A]) ([w] : Γ ⊩⟨ l' ⟩ w ∷ B ^ [ ! , ι ¹ ] / Uᵣ [B]) ([u≡w] : Γ ⊩⟨ l ⟩ u ≡ w ∷ A ^ [ ! , ι ¹ ] / Uᵣ [A]) → Γ ⊩⟨ l ⟩ Id A t u ≡ Id B v w ^ [ % , ι ¹ ] / [Id]UGen ⊢Γ [A] [t] [u] [IdExt]UGen {A} {B} {t} {v} {u} {w} {Γ} {.(ι ¹)} {.(ι ¹)} ⊢Γ (Uᵣ ! ⁰ emb< PE.refl d) (Uᵣ r₁ ⁰ emb< PE.refl d₁) [A≡B] [t] [v] [t≡v] [u] [w] [u≡w] = let U≡U = whrDet* (red d₁ , Uₙ) ([A≡B] , Uₙ) r≡r , _ = Univ-PE-injectivity U≡U [UA] = Uᵣ ! ⁰ emb< PE.refl d [UB] = Uᵣ r₁ ⁰ emb< PE.refl d₁ [U] = Ugen' ⊢Γ [U]' = Ugen' ⊢Γ [UA]' , [UAeq] = redSubst* (red d) (Uᵣ [U]) [UB]' , [UBeq] = redSubst* (PE.subst (λ X → Γ ⊢ _ ⇒* Univ X _ ^ _) r≡r (red d₁)) (Uᵣ [U]') [t]′ = convTerm₁ {t = t} [UA]' (Uᵣ [U]) [UAeq] (irrelevanceTerm (Uᵣ [UA]) [UA]' [t]) [t^] = univEq (Uᵣ [U]) [t]′ [v]′ = convTerm₁ {t = v} [UB]' (Uᵣ [U]) [UBeq] (irrelevanceTerm (Uᵣ [UB]) [UB]' [v]) [v^] = univEq (Uᵣ [U]) [v]′ [t≡v]′ = convEqTerm₁ {t = t} {u = v} [UA]' (Uᵣ [U]) [UAeq] (irrelevanceEqTerm (Uᵣ [UA]) [UA]' [t≡v]) [t≡v^] = univEqEq (Uᵣ [U]) [t^] [t≡v]′ [u]′ = convTerm₁ {t = u} [UA]' (Uᵣ [U]) [UAeq] (irrelevanceTerm (Uᵣ [UA]) [UA]' [u]) [u^] = univEq (Uᵣ [U]) [u]′ [w]′ = convTerm₁ {t = w} [UB]' (Uᵣ [U]) [UBeq] (irrelevanceTerm (Uᵣ [UB]) [UB]' [w]) [w^] = univEq (Uᵣ [U]) [w]′ [u≡w]′ = convEqTerm₁ {t = u} {u = w} [UA]' (Uᵣ [U]) [UAeq] (irrelevanceEqTerm (Uᵣ [UA]) [UA]' [u≡w]) [u≡w^] = univEqEq (Uᵣ [U]) [u^] [u≡w]′ X = irrelevanceEq {A = Id (U ⁰) t u} {B = Id (U ⁰) v w} ([Id]U ⊢Γ [t^] [u^]) ([Id]UGen ⊢Γ [U] [t]′ [u]′) ([IdExt]U ⊢Γ [t^] [v^] [t≡v^] [u^] [w^] [u≡w^]) [IdA] , [IdA≡U] = redSubst* (IdRed* (escapeTerm (Uᵣ [UA]) [t]) (escapeTerm (Uᵣ [UA]) [u]) (red d)) ([Id]UGen ⊢Γ [U] [t]′ [u]′) [IdB] , [IdB≡U] = redSubst* (IdRed* (escapeTerm (Uᵣ [UB]) [v]) (escapeTerm (Uᵣ [UB]) [w]) (PE.subst (λ X → Γ ⊢ _ ⇒* Univ X _ ^ _) r≡r (red d₁))) ([Id]UGen ⊢Γ [U] [v]′ [w]′) [IdA≡U]′ = irrelevanceEq {A = Id A t u} {B = Id (U ⁰) t u} [IdA] ([Id]UGen ⊢Γ [UA] [t] [u]) [IdA≡U] [IdB≡U]′ = irrelevanceEq {A = Id B v w} {B = Id (U ⁰) v w} [IdB] ([Id]UGen ⊢Γ [UB] [v] [w]) [IdB≡U] in transEq {A = Id A t u} {B = Id (U _) t u} {C = Id B v w} ([Id]UGen ⊢Γ [UA] [t] [u]) ([Id]UGen ⊢Γ [U] [t]′ [u]′) ([Id]UGen ⊢Γ [UB] [v] [w]) [IdA≡U]′ (transEq {A = Id (U _) t u} {B = Id (U _) v w} {C = Id B v w} ([Id]UGen ⊢Γ [U] [t]′ [u]′) ([Id]UGen ⊢Γ [U] [v]′ [w]′) ([Id]UGen ⊢Γ [UB] [v] [w]) X (symEq {A = Id B v w} {B = Id (U _) v w} ([Id]UGen ⊢Γ [UB] [v] [w]) ([Id]UGen ⊢Γ [U] [v]′ [w]′) [IdB≡U]′)) [IdExt]UGen {A} {B} {t} {v} {u} {w} {Γ} {.(ι ¹)} {.(ι ¹)} ⊢Γ (Uᵣ % ⁰ emb< PE.refl d) (Uᵣ r₁ ⁰ emb< PE.refl d₁) [A≡B] [t] [v] [t≡v] [u] [w] [u≡w] = let U≡U = whrDet* (red d₁ , Uₙ) ([A≡B] , Uₙ) r≡r , _ = Univ-PE-injectivity U≡U [UA] = Uᵣ % ⁰ emb< PE.refl d [UB] = Uᵣ r₁ ⁰ emb< PE.refl d₁ [U] = Ugen' ⊢Γ [U]' = Ugen' ⊢Γ [UA]' , [UAeq] = redSubst* (red d) (Uᵣ [U]) [UB]' , [UBeq] = redSubst* (PE.subst (λ X → Γ ⊢ _ ⇒* Univ X _ ^ _) r≡r (red d₁)) (Uᵣ [U]') [t]′ = convTerm₁ {t = t} [UA]' (Uᵣ [U]) [UAeq] (irrelevanceTerm (Uᵣ [UA]) [UA]' [t]) [t^] = univEq (Uᵣ [U]) [t]′ [v]′ = convTerm₁ {t = v} [UB]' (Uᵣ [U]) [UBeq] (irrelevanceTerm (Uᵣ [UB]) [UB]' [v]) [v^] = univEq (Uᵣ [U]) [v]′ [t≡v]′ = convEqTerm₁ {t = t} {u = v} [UA]' (Uᵣ [U]) [UAeq] (irrelevanceEqTerm (Uᵣ [UA]) [UA]' [t≡v]) [t≡v^] = univEqEq (Uᵣ [U]) [t^] [t≡v]′ [u]′ = convTerm₁ {t = u} [UA]' (Uᵣ [U]) [UAeq] (irrelevanceTerm (Uᵣ [UA]) [UA]' [u]) [u^] = univEq (Uᵣ [U]) [u]′ [w]′ = convTerm₁ {t = w} [UB]' (Uᵣ [U]) [UBeq] (irrelevanceTerm (Uᵣ [UB]) [UB]' [w]) [w^] = univEq (Uᵣ [U]) [w]′ [u≡w]′ = convEqTerm₁ {t = u} {u = w} [UA]' (Uᵣ [U]) [UAeq] (irrelevanceEqTerm (Uᵣ [UA]) [UA]' [u≡w]) [u≡w^] = univEqEq (Uᵣ [U]) [u^] [u≡w]′ X = irrelevanceEq {A = Id (SProp ⁰) t u} {B = Id (SProp ⁰) v w} ([Id]SProp ⊢Γ [t^] [u^]) ([Id]UGen ⊢Γ [U] [t]′ [u]′) ([IdExt]SProp ⊢Γ [t^] [v^] [t≡v^] [u^] [w^] [u≡w^]) [IdA] , [IdA≡U] = redSubst* (IdRed* (escapeTerm (Uᵣ [UA]) [t]) (escapeTerm (Uᵣ [UA]) [u]) (red d)) ([Id]UGen ⊢Γ [U] [t]′ [u]′) [IdB] , [IdB≡U] = redSubst* (IdRed* (escapeTerm (Uᵣ [UB]) [v]) (escapeTerm (Uᵣ [UB]) [w]) (PE.subst (λ X → Γ ⊢ _ ⇒* Univ X _ ^ _) r≡r (red d₁))) ([Id]UGen ⊢Γ [U] [v]′ [w]′) [IdA≡U]′ = irrelevanceEq {A = Id A t u} {B = Id (SProp ⁰) t u} [IdA] ([Id]UGen ⊢Γ [UA] [t] [u]) [IdA≡U] [IdB≡U]′ = irrelevanceEq {A = Id B v w} {B = Id (SProp ⁰) v w} [IdB] ([Id]UGen ⊢Γ [UB] [v] [w]) [IdB≡U] in transEq {A = Id A t u} {B = Id (SProp _) t u} {C = Id B v w} ([Id]UGen ⊢Γ [UA] [t] [u]) ([Id]UGen ⊢Γ [U] [t]′ [u]′) ([Id]UGen ⊢Γ [UB] [v] [w]) [IdA≡U]′ (transEq {A = Id (SProp _) t u} {B = Id (SProp _) v w} {C = Id B v w} ([Id]UGen ⊢Γ [U] [t]′ [u]′) ([Id]UGen ⊢Γ [U] [v]′ [w]′) ([Id]UGen ⊢Γ [UB] [v] [w]) X (symEq {A = Id B v w} {B = Id (SProp _) v w} ([Id]UGen ⊢Γ [UB] [v] [w]) ([Id]UGen ⊢Γ [U] [v]′ [w]′) [IdB≡U]′))
algebraic-stack_agda0000_doc_5959
{-# OPTIONS --cubical --safe --postfix-projections #-} module Cardinality.Finite.Structure where open import Prelude open import Data.Fin open import Data.Nat open import Data.Nat.Properties private variable n m : ℕ liftˡ : ∀ n m → Fin m → Fin (n + m) liftˡ zero m x = x liftˡ (suc n) m x = fs (liftˡ n m x) liftʳ : ∀ n m → Fin n → Fin (n + m) liftʳ (suc n) m f0 = f0 liftʳ (suc n) m (fs x) = fs (liftʳ n m x) mapl : (A → B) → A ⊎ C → B ⊎ C mapl f (inl x) = inl (f x) mapl f (inr x) = inr x fin-sum-to : ∀ n m → Fin n ⊎ Fin m → Fin (n + m) fin-sum-to n m = either (liftʳ n m) (liftˡ n m) fin-sum-from : ∀ n m → Fin (n + m) → Fin n ⊎ Fin m fin-sum-from zero m x = inr x fin-sum-from (suc n) m f0 = inl f0 fin-sum-from (suc n) m (fs x) = mapl fs (fin-sum-from n m x) mapl-distrib : ∀ {a b c d} {A : Type a} {B : Type b} {C : Type c} {D : Type d} (xs : A ⊎ B) (h : A → C) (f : C → D) (g : B → D) → either′ f g (mapl h xs) ≡ either′ (f ∘′ h) g xs mapl-distrib (inl x) h f g = refl mapl-distrib (inr x) h f g = refl either-distrib : ∀ {d} {D : Type d} (f : A → C) (g : B → C) (h : C → D) (xs : A ⊎ B) → either′ (h ∘ f) (h ∘ g) xs ≡ h (either′ f g xs) either-distrib f g h (inl x) = refl either-distrib f g h (inr x) = refl open import Path.Reasoning fin-sum-to-from : ∀ n m x → fin-sum-to n m (fin-sum-from n m x) ≡ x fin-sum-to-from zero m x = refl fin-sum-to-from (suc n) m f0 = refl fin-sum-to-from (suc n) m (fs x) = fin-sum-to (suc n) m (mapl fs (fin-sum-from n m x)) ≡⟨ mapl-distrib (fin-sum-from n m x) fs (liftʳ (suc n) m) (liftˡ (suc n) m) ⟩ either (liftʳ (suc n) m ∘ fs) (liftˡ (suc n) m) (fin-sum-from n m x) ≡⟨⟩ either (fs ∘ liftʳ n m) (fs ∘ liftˡ n m) (fin-sum-from n m x) ≡⟨ either-distrib (liftʳ n m) (liftˡ n m) fs (fin-sum-from n m x) ⟩ fs (either (liftʳ n m) (liftˡ n m) (fin-sum-from n m x)) ≡⟨ cong fs (fin-sum-to-from n m x) ⟩ fs x ∎ -- fin-sum-from-to : ∀ n m x → fin-sum-from n m (fin-sum-to n m x) ≡ x -- fin-sum-from-to n m (inl x) = {!!} -- fin-sum-from-to n m (inr x) = {!!} -- fin-sum : ∀ n m → Fin n ⊎ Fin m ⇔ Fin (n + m) -- fin-sum n m .fun = fin-sum-to n m -- fin-sum n m .inv = fin-sum-from n m -- fin-sum n m .rightInv = fin-sum-to-from n m -- fin-sum n m .leftInv = fin-sum-from-to n m
algebraic-stack_agda0000_doc_5960
module Data.Signed where open import Data.Bit using (Bit ; b0 ; b1 ; Bits-num ; Bits-neg ; Overflowing ; _overflow:_ ; result ; carry ; WithCarry ; _with-carry:_ ; toBool ; tryToFinₙ ; !ₙ ; _⊕_ ; _↔_ ) renaming ( _+_ to bit+ ; _-_ to bit- ; ! to bit! ; _&_ to bit& ; _~|_ to bit| ; _^_ to bit^ ; _>>_ to bit>> ; _<<_ to bit<< ) open import Data.Unit using (⊤) open import Data.Nat using (ℕ; suc; zero) renaming (_≤_ to ℕ≤) open import Data.Vec using (Vec; _∷_; []; head; tail; replicate) open import Data.Nat.Literal using (Number) open import Data.Int.Literal using (Negative) open import Data.Maybe using (just; nothing) open import Data.Empty using (⊥) infixl 8 _-_ _+_ infixl 7 _<<_ _>>_ infixl 6 _&_ infixl 5 _^_ infixl 4 _~|_ record Signed (n : ℕ) : Set where constructor mk-int field bits : Vec Bit n open Signed public instance Signed-num : {m : ℕ} → Number (Signed m) Signed-num {zero} .Number.Constraint = Number.Constraint (Bits-num {zero}) Signed-num {suc m} .Number.Constraint = Number.Constraint (Bits-num {m}) Signed-num {zero} .Number.fromNat zero ⦃ p ⦄ = mk-int [] where Signed-num {zero} .Number.fromNat (suc _) ⦃ ℕ≤.s≤s () ⦄ Signed-num {suc m} .Number.fromNat n ⦃ p ⦄ = mk-int (mk-bits p) where mk-bits : Number.Constraint (Bits-num {m}) n → Vec Bit (suc m) mk-bits p = b0 ∷ Number.fromNat Bits-num n ⦃ p ⦄ instance Signed-neg : {m : ℕ} → Negative (Signed (suc m)) Signed-neg {m} .Negative.Constraint = Negative.Constraint (Bits-neg {m}) Signed-neg {m} .Negative.fromNeg n ⦃ p ⦄ = mk-int bitVec where bitVec : Vec Bit (suc m) bitVec = Negative.fromNeg (Bits-neg {m}) n ⦃ p ⦄ _+_ : {n : ℕ} → Signed n → Signed n → Overflowing (Signed n) p + q = mk-int (result sum) overflow: toBool overflow where sum = bit+ (bits p) (bits q) last-carry : {n : ℕ} → Vec Bit n → Bit last-carry [] = b0 last-carry (b ∷ _) = b overflow = head (carry sum) ⊕ last-carry (tail (carry sum)) _-_ : {n : ℕ} → Signed n → Signed n → Overflowing (Signed n) p - q = mk-int (result sub) overflow: toBool overflow where sub = bit- (bits p) (bits q) last-carry : {n : ℕ} → Vec Bit n → Bit last-carry [] = b0 last-carry (b ∷ _) = b overflow = head (carry sub) ↔ last-carry (tail (carry sub)) rotr : {n : ℕ} → Signed n → Signed n → WithCarry (Signed n) (Signed n) rotr {n} (mk-int ps) (mk-int qs) = new-result with-carry: new-carry where shifted : WithCarry (Vec Bit n) (Vec Bit n) shifted with tryToFinₙ qs ... | just i = bit>> ps i ... | nothing = replicate b0 with-carry: ps new-result : Signed n new-result = mk-int (result shifted) new-carry : Signed n new-carry = mk-int (carry shifted) rotl : {n : ℕ} → Signed n → Signed n → WithCarry (Signed n) (Signed n) rotl {n} (mk-int ps) (mk-int qs) = new-result with-carry: new-carry where shifted : WithCarry (Vec Bit n) (Vec Bit n) shifted with tryToFinₙ qs ... | just i = bit<< ps i ... | nothing = replicate b0 with-carry: ps new-result : Signed n new-result = mk-int (result shifted) new-carry : Signed n new-carry = mk-int (carry shifted) _>>_ : {n : ℕ} → Signed n → Signed n → Signed n ps >> qs = result (rotr ps qs) _<<_ : {n : ℕ} → Signed n → Signed n → Signed n ps << qs = result (rotl ps qs) arotr : {n : ℕ} → Signed n → Signed n → WithCarry (Signed n) (Signed n) arotr {n} (mk-int []) _ = mk-int [] with-carry: mk-int [] arotr {suc n} (mk-int (p ∷ ps)) (mk-int qs) = new-result with-carry: new-carry where shifted : WithCarry (Vec Bit n) (Vec Bit n) shifted with tryToFinₙ qs ... | just i = bit>> ps i ... | nothing = replicate b0 with-carry: ps new-result : Signed (suc n) new-result = mk-int (p ∷ result shifted) new-carry : Signed (suc n) new-carry = mk-int (b0 ∷ carry shifted) arotl : {n : ℕ} → Signed n → Signed n → WithCarry (Signed n) (Signed n) arotl {n} (mk-int []) _ = mk-int [] with-carry: mk-int [] arotl {suc n} (mk-int (p ∷ ps)) (mk-int qs) = new-result with-carry: new-carry where shifted : WithCarry (Vec Bit n) (Vec Bit n) shifted with tryToFinₙ qs ... | just i = bit<< ps i ... | nothing = replicate b0 with-carry: ps new-result : Signed (suc n) new-result = mk-int (p ∷ result shifted) new-carry : Signed (suc n) new-carry = mk-int (b0 ∷ carry shifted) _a>>_ : {n : ℕ} → Signed n → Signed n → Signed n ps a>> qs = result (rotr ps qs) _a<<_ : {n : ℕ} → Signed n → Signed n → Signed n ps a<< qs = result (rotl ps qs) ! : {n : ℕ} → Signed n → Signed n ! (mk-int ps) = mk-int (!ₙ ps) _&_ : {n : ℕ} → Signed n → Signed n → Signed n (mk-int ps) & (mk-int qs) = mk-int (bit& ps qs) _~|_ : {n : ℕ} → Signed n → Signed n → Signed n (mk-int ps) ~| (mk-int qs) = mk-int (bit| ps qs) _^_ : {n : ℕ} → Signed n → Signed n → Signed n (mk-int ps) ^ (mk-int qs) = mk-int (bit^ ps qs)
algebraic-stack_agda0000_doc_5961
{-# OPTIONS --warning=error --safe --without-K #-} open import LogicalFormulae open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import Functions open import Setoids.Setoids open import Setoids.Subset open import Graphs.Definition open import Sets.FinSet.Definition open import Numbers.Naturals.Semiring open import Numbers.Naturals.Order open import Sets.EquivalenceRelations open import Graphs.CompleteGraph open import Graphs.Colouring module Graphs.RamseyTriangle where hasMonochromaticTriangle : {a : _} {n : ℕ} (G : Graph a (reflSetoid (FinSet n))) → Set (lsuc lzero) hasMonochromaticTriangle {n = n} G = Sg (FinSet n → Set) λ pred → (subset (reflSetoid (FinSet n)) pred) && {!!} ramseyForTriangle : (k : ℕ) → Sg ℕ (λ N → (n : ℕ) → (N <N n) → (c : Colouring k (Kn n)) → {!!}) ramseyForTriangle k = {!!}
algebraic-stack_agda0000_doc_5962
{-# OPTIONS --sized-types #-} module SizedTypesRigidVarClash where postulate Size : Set _^ : Size -> Size ∞ : Size {-# BUILTIN SIZE Size #-} {-# BUILTIN SIZESUC _^ #-} {-# BUILTIN SIZEINF ∞ #-} data Nat : {size : Size} -> Set where zero : {size : Size} -> Nat {size ^} suc : {size : Size} -> Nat {size} -> Nat {size ^} inc : {i j : Size} -> Nat {i} -> Nat {j ^} inc x = suc x
algebraic-stack_agda0000_doc_5963
-- Andreas, 2017-01-18, issue #2413 -- As-patterns of variable patterns data Bool : Set where true false : Bool test : Bool → Bool test x@y = {!x!} -- split on x test1 : Bool → Bool test1 x@_ = {!x!} -- split on x test2 : Bool → Bool test2 x@y = {!y!} -- split on y