hexsha
stringlengths
40
40
size
int64
3
1.05M
ext
stringclasses
163 values
lang
stringclasses
53 values
max_stars_repo_path
stringlengths
3
945
max_stars_repo_name
stringlengths
4
112
max_stars_repo_head_hexsha
stringlengths
40
78
max_stars_repo_licenses
listlengths
1
10
max_stars_count
float64
1
191k
max_stars_repo_stars_event_min_datetime
stringlengths
24
24
max_stars_repo_stars_event_max_datetime
stringlengths
24
24
max_issues_repo_path
stringlengths
3
945
max_issues_repo_name
stringlengths
4
113
max_issues_repo_head_hexsha
stringlengths
40
78
max_issues_repo_licenses
listlengths
1
10
max_issues_count
float64
1
116k
max_issues_repo_issues_event_min_datetime
stringlengths
24
24
max_issues_repo_issues_event_max_datetime
stringlengths
24
24
max_forks_repo_path
stringlengths
3
945
max_forks_repo_name
stringlengths
4
113
max_forks_repo_head_hexsha
stringlengths
40
78
max_forks_repo_licenses
listlengths
1
10
max_forks_count
float64
1
105k
max_forks_repo_forks_event_min_datetime
stringlengths
24
24
max_forks_repo_forks_event_max_datetime
stringlengths
24
24
content
stringlengths
3
1.05M
avg_line_length
float64
1
966k
max_line_length
int64
1
977k
alphanum_fraction
float64
0
1
2136d8dd0e32c7114cdd4a6e382c6af60e8a9dfe
706
agda
Agda
test/Compiler/simple/VecReverse.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
null
null
null
test/Compiler/simple/VecReverse.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
null
null
null
test/Compiler/simple/VecReverse.agda
pthariensflame/agda
222c4c64b2ccf8e0fc2498492731c15e8fef32d4
[ "BSD-3-Clause" ]
null
null
null
module _ where open import Common.Prelude open import Lib.Vec _∘_ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : ∀ x → B x → Set c} (f : ∀ {x} (y : B x) → C x y) (g : ∀ x → B x) → ∀ x → C x (g x) (f ∘ g) x = f (g x) sum : ∀ {n} → Vec Nat n → Nat sum (x ∷ xs) = x + sum xs sum [] = 0 foldl : ∀ {A}{B : Nat → Set} → (∀ {n} → B n → A → B (suc n)) → B 0 → ∀ {n} → Vec A n → B n foldl {B = B} f z (x ∷ xs) = foldl {B = λ n → B (suc n)} f (f z x) xs foldl f z [] = z reverse : ∀ {A n} → Vec A n → Vec A n reverse = foldl {B = Vec _} (λ xs x → x ∷ xs) [] downFrom : ∀ n → Vec Nat n downFrom zero = [] downFrom (suc n) = n ∷ downFrom n main : IO Unit main = printNat (sum (reverse (downFrom 6000)))
25.214286
90
0.475921
35fb1513cf030fa25dfbb636404244b7125c5d6c
2,863
agda
Agda
src/Implicits/Syntax/Type/Unification/Lemmas.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
4
2019-04-05T17:57:11.000Z
2021-05-07T04:08:41.000Z
src/Implicits/Syntax/Type/Unification/Lemmas.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
src/Implicits/Syntax/Type/Unification/Lemmas.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
module Implicits.Syntax.Type.Unification.Lemmas where open import Prelude open import Data.Nat.Properties.Simple open import Data.Maybe as Maybe open import Data.Vec open import Extensions.Vec open import Implicits.Syntax open import Implicits.Syntax.Type.Unification hiding (open-meta) open import Implicits.Substitutions open import Implicits.Substitutions.Lemmas.MetaType open MetaTypeMetaSubst open MetaTypeMetaLemmas open import Relation.Binary.HeterogeneousEquality as H using () -- the following properties of mgu are assumed to hold here but have been proven by -- Conor McBride (and verified using the LEGO dependently typed language) postulate sound : ∀ {m ν} (a : MetaType m ν) (b : SimpleType ν) → Maybe.All (Unifier a b) (mgu a b) postulate complete : ∀ {m ν} (a : MetaType m ν) (b : SimpleType ν) u → Unifier a b u → Is-just (mgu a b) to-meta-zero-vanishes : ∀ {ν} {a : Type ν} → from-meta (to-meta a) ≡ a to-meta-zero-vanishes {a = simpl (tc x)} = refl to-meta-zero-vanishes {a = simpl (tvar n)} = refl to-meta-zero-vanishes {a = simpl (a →' b)} = cong₂ (λ u v → simpl (u →' v)) to-meta-zero-vanishes to-meta-zero-vanishes to-meta-zero-vanishes {a = a ⇒ b} = cong₂ _⇒_ to-meta-zero-vanishes to-meta-zero-vanishes to-meta-zero-vanishes {a = ∀' a} = cong ∀' to-meta-zero-vanishes mutual from-to-smeta : ∀ {ν} (a : SimpleType ν) → from-smeta (to-smeta a) ≡ a from-to-smeta (tc x) = refl from-to-smeta (tvar n) = refl from-to-smeta (a →' b) = cong₂ _→'_ (from-to-meta a) (from-to-meta b) from-to-meta : ∀ {ν} (a : Type ν) → from-meta (to-meta a) ≡ a from-to-meta (simpl x) = cong simpl (from-to-smeta x) from-to-meta (a ⇒ b) = cong₂ _⇒_ (from-to-meta a) (from-to-meta b) from-to-meta (∀' a) = cong ∀' (from-to-meta a) from-to-meta-/-vanishes : ∀ {ν} {a : Type ν} {s} → from-meta (to-meta {zero} a MetaTypeMetaSubst./ s) ≡ a from-to-meta-/-vanishes {a = a} {s = []} = begin from-meta (MetaTypeMetaSubst._/_ (to-meta {zero} a) []) ≡⟨ cong (λ q → from-meta q) (MetaTypeMetaLemmas.id-vanishes (to-meta {zero} a)) ⟩ from-meta (to-meta {zero} a) ≡⟨ to-meta-zero-vanishes ⟩ a ∎ mgu-id : ∀ {ν} → (a : SimpleType ν) → Unifiable {m = zero} (simpl (to-smeta a)) a mgu-id a = [] , (begin from-meta (MetaTypeMetaSubst._/_ (simpl (to-smeta a)) []) ≡⟨ from-to-meta-/-vanishes ⟩ simpl a ∎) mvar-unifiable : ∀ {ν m} (n : Fin m) (τ : SimpleType ν) → Unifiable (simpl (mvar n)) τ mvar-unifiable n τ = u , p where u = replicate (simpl (tc zero)) [ n ]≔ simpl (to-smeta τ) p : from-meta (lookup n u) ≡ simpl τ p = begin from-meta (lookup n u) ≡⟨ cong from-meta (lookup-≔ (replicate (simpl (tc zero))) n _) ⟩ simpl (from-smeta (to-smeta τ)) ≡⟨ cong simpl (from-to-smeta τ) ⟩ simpl τ ∎
38.173333
89
0.629759
0458e151f8f676e3f2d01891973bac63c4878a20
9,200
agda
Agda
Cubical/Data/Nat/Order.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/Data/Nat/Order.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/Data/Nat/Order.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-} module Cubical.Data.Nat.Order where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Data.Empty as ⊥ open import Cubical.Data.Sigma open import Cubical.Data.Sum as ⊎ open import Cubical.Data.Nat.Base open import Cubical.Data.Nat.Properties open import Cubical.Induction.WellFounded open import Cubical.Relation.Nullary private variable ℓ : Level infix 4 _≤_ _<_ _≤_ : ℕ → ℕ → Type₀ m ≤ n = Σ[ k ∈ ℕ ] k + m ≡ n _<_ : ℕ → ℕ → Type₀ m < n = suc m ≤ n data Trichotomy (m n : ℕ) : Type₀ where lt : m < n → Trichotomy m n eq : m ≡ n → Trichotomy m n gt : n < m → Trichotomy m n private variable k l m n : ℕ private witness-prop : ∀ j → isProp (j + m ≡ n) witness-prop {m} {n} j = isSetℕ (j + m) n m≤n-isProp : isProp (m ≤ n) m≤n-isProp {m} {n} (k , p) (l , q) = Σ≡Prop witness-prop lemma where lemma : k ≡ l lemma = inj-+m (p ∙ (sym q)) zero-≤ : 0 ≤ n zero-≤ {n} = n , +-zero n suc-≤-suc : m ≤ n → suc m ≤ suc n suc-≤-suc (k , p) = k , (+-suc k _) ∙ (cong suc p) ≤-+k : m ≤ n → m + k ≤ n + k ≤-+k {m} {k = k} (i , p) = i , +-assoc i m k ∙ cong (_+ k) p ≤-k+ : m ≤ n → k + m ≤ k + n ≤-k+ {m} {n} {k} = subst (_≤ k + n) (+-comm m k) ∘ subst (m + k ≤_) (+-comm n k) ∘ ≤-+k pred-≤-pred : suc m ≤ suc n → m ≤ n pred-≤-pred (k , p) = k , injSuc ((sym (+-suc k _)) ∙ p) ≤-refl : m ≤ m ≤-refl = 0 , refl ≤-suc : m ≤ n → m ≤ suc n ≤-suc (k , p) = suc k , cong suc p ≤-predℕ : predℕ n ≤ n ≤-predℕ {zero} = ≤-refl ≤-predℕ {suc n} = ≤-suc ≤-refl ≤-trans : k ≤ m → m ≤ n → k ≤ n ≤-trans {k} {m} {n} (i , p) (j , q) = i + j , l2 ∙ (l1 ∙ q) where l1 : j + i + k ≡ j + m l1 = (sym (+-assoc j i k)) ∙ (cong (j +_) p) l2 : i + j + k ≡ j + i + k l2 = cong (_+ k) (+-comm i j) ≤-antisym : m ≤ n → n ≤ m → m ≡ n ≤-antisym {m} (i , p) (j , q) = (cong (_+ m) l3) ∙ p where l1 : j + i + m ≡ m l1 = (sym (+-assoc j i m)) ∙ ((cong (j +_) p) ∙ q) l2 : j + i ≡ 0 l2 = m+n≡n→m≡0 l1 l3 : 0 ≡ i l3 = sym (snd (m+n≡0→m≡0×n≡0 l2)) ≤-k+-cancel : k + m ≤ k + n → m ≤ n ≤-k+-cancel {k} {m} (l , p) = l , inj-m+ (sub k m ∙ p) where sub : ∀ k m → k + (l + m) ≡ l + (k + m) sub k m = +-assoc k l m ∙ cong (_+ m) (+-comm k l) ∙ sym (+-assoc l k m) ≤-+k-cancel : m + k ≤ n + k → m ≤ n ≤-+k-cancel {m} {k} {n} (l , p) = l , cancelled where cancelled : l + m ≡ n cancelled = inj-+m (sym (+-assoc l m k) ∙ p) ≤-·k : m ≤ n → m · k ≤ n · k ≤-·k {m} {n} {k} (d , r) = d · k , reason where reason : d · k + m · k ≡ n · k reason = d · k + m · k ≡⟨ ·-distribʳ d m k ⟩ (d + m) · k ≡⟨ cong (_· k) r ⟩ n · k ∎ <-k+-cancel : k + m < k + n → m < n <-k+-cancel {k} {m} {n} = ≤-k+-cancel ∘ subst (_≤ k + n) (sym (+-suc k m)) ¬-<-zero : ¬ m < 0 ¬-<-zero (k , p) = snotz ((sym (+-suc k _)) ∙ p) ¬m<m : ¬ m < m ¬m<m {m} = ¬-<-zero ∘ ≤-+k-cancel {k = m} ≤0→≡0 : n ≤ 0 → n ≡ 0 ≤0→≡0 {zero} ineq = refl ≤0→≡0 {suc n} ineq = ⊥.rec (¬-<-zero ineq) predℕ-≤-predℕ : m ≤ n → (predℕ m) ≤ (predℕ n) predℕ-≤-predℕ {zero} {zero} ineq = ≤-refl predℕ-≤-predℕ {zero} {suc n} ineq = zero-≤ predℕ-≤-predℕ {suc m} {zero} ineq = ⊥.rec (¬-<-zero ineq) predℕ-≤-predℕ {suc m} {suc n} ineq = pred-≤-pred ineq ¬m+n<m : ¬ m + n < m ¬m+n<m {m} {n} = ¬-<-zero ∘ <-k+-cancel ∘ subst (m + n <_) (sym (+-zero m)) <-weaken : m < n → m ≤ n <-weaken (k , p) = suc k , sym (+-suc k _) ∙ p ≤<-trans : l ≤ m → m < n → l < n ≤<-trans p = ≤-trans (suc-≤-suc p) <≤-trans : l < m → m ≤ n → l < n <≤-trans = ≤-trans <-trans : l < m → m < n → l < n <-trans p = ≤<-trans (<-weaken p) <-asym : m < n → ¬ n ≤ m <-asym m<n = ¬m<m ∘ <≤-trans m<n <-+k : m < n → m + k < n + k <-+k p = ≤-+k p <-k+ : m < n → k + m < k + n <-k+ {m} {n} {k} p = subst (λ km → km ≤ k + n) (+-suc k m) (≤-k+ p) <-·sk : m < n → m · suc k < n · suc k <-·sk {m} {n} {k} (d , r) = (d · suc k + k) , reason where reason : (d · suc k + k) + suc (m · suc k) ≡ n · suc k reason = (d · suc k + k) + suc (m · suc k) ≡⟨ sym (+-assoc (d · suc k) k _) ⟩ d · suc k + (k + suc (m · suc k)) ≡[ i ]⟨ d · suc k + +-suc k (m · suc k) i ⟩ d · suc k + suc m · suc k ≡⟨ ·-distribʳ d (suc m) (suc k) ⟩ (d + suc m) · suc k ≡⟨ cong (_· suc k) r ⟩ n · suc k ∎ Trichotomy-suc : Trichotomy m n → Trichotomy (suc m) (suc n) Trichotomy-suc (lt m<n) = lt (suc-≤-suc m<n) Trichotomy-suc (eq m=n) = eq (cong suc m=n) Trichotomy-suc (gt n<m) = gt (suc-≤-suc n<m) _≟_ : ∀ m n → Trichotomy m n zero ≟ zero = eq refl zero ≟ suc n = lt (n , +-comm n 1) suc m ≟ zero = gt (m , +-comm m 1) suc m ≟ suc n = Trichotomy-suc (m ≟ n) <-split : m < suc n → (m < n) ⊎ (m ≡ n) <-split {n = zero} = inr ∘ snd ∘ m+n≡0→m≡0×n≡0 ∘ snd ∘ pred-≤-pred <-split {zero} {suc n} = λ _ → inl (suc-≤-suc zero-≤) <-split {suc m} {suc n} = ⊎.map suc-≤-suc (cong suc) ∘ <-split ∘ pred-≤-pred private acc-suc : Acc _<_ n → Acc _<_ (suc n) acc-suc a = acc λ y y<sn → case <-split y<sn of λ { (inl y<n) → access a y y<n ; (inr y≡n) → subst _ (sym y≡n) a } <-wellfounded : WellFounded _<_ <-wellfounded zero = acc λ _ → ⊥.rec ∘ ¬-<-zero <-wellfounded (suc n) = acc-suc (<-wellfounded n) <→≢ : n < m → ¬ n ≡ m <→≢ {n} {m} p q = ¬m<m (subst (_< m) q p) module _ (b₀ : ℕ) (P : ℕ → Type₀) (base : ∀ n → n < suc b₀ → P n) (step : ∀ n → P n → P (suc b₀ + n)) where open WFI (<-wellfounded) private dichotomy : ∀ b n → (n < b) ⊎ (Σ[ m ∈ ℕ ] n ≡ b + m) dichotomy b n = case n ≟ b return (λ _ → (n < b) ⊎ (Σ[ m ∈ ℕ ] n ≡ b + m)) of λ { (lt o) → inl o ; (eq p) → inr (0 , p ∙ sym (+-zero b)) ; (gt (m , p)) → inr (suc m , sym p ∙ +-suc m b ∙ +-comm (suc m) b) } dichotomy<≡ : ∀ b n → (n<b : n < b) → dichotomy b n ≡ inl n<b dichotomy<≡ b n n<b = case dichotomy b n return (λ d → d ≡ inl n<b) of λ { (inl x) → cong inl (m≤n-isProp x n<b) ; (inr (m , p)) → ⊥.rec (<-asym n<b (m , sym (p ∙ +-comm b m))) } dichotomy+≡ : ∀ b m n → (p : n ≡ b + m) → dichotomy b n ≡ inr (m , p) dichotomy+≡ b m n p = case dichotomy b n return (λ d → d ≡ inr (m , p)) of λ { (inl n<b) → ⊥.rec (<-asym n<b (m , +-comm m b ∙ sym p)) ; (inr (m' , q)) → cong inr (Σ≡Prop (λ x → isSetℕ n (b + x)) (inj-m+ {m = b} (sym q ∙ p))) } b = suc b₀ lemma₁ : ∀{x y z} → x ≡ suc z + y → y < x lemma₁ {y = y} {z} p = z , +-suc z y ∙ sym p subStep : (n : ℕ) → (∀ m → m < n → P m) → (n < b) ⊎ (Σ[ m ∈ ℕ ] n ≡ b + m) → P n subStep n _ (inl l) = base n l subStep n rec (inr (m , p)) = transport (cong P (sym p)) (step m (rec m (lemma₁ p))) wfStep : (n : ℕ) → (∀ m → m < n → P m) → P n wfStep n rec = subStep n rec (dichotomy b n) wfStepLemma₀ : ∀ n (n<b : n < b) rec → wfStep n rec ≡ base n n<b wfStepLemma₀ n n<b rec = cong (subStep n rec) (dichotomy<≡ b n n<b) wfStepLemma₁ : ∀ n rec → wfStep (b + n) rec ≡ step n (rec n (lemma₁ refl)) wfStepLemma₁ n rec = cong (subStep (b + n) rec) (dichotomy+≡ b n (b + n) refl) ∙ transportRefl _ +induction : ∀ n → P n +induction = induction wfStep +inductionBase : ∀ n → (l : n < b) → +induction n ≡ base n l +inductionBase n l = induction-compute wfStep n ∙ wfStepLemma₀ n l _ +inductionStep : ∀ n → +induction (b + n) ≡ step n (+induction n) +inductionStep n = induction-compute wfStep (b + n) ∙ wfStepLemma₁ n _ module <-Reasoning where -- TODO: would it be better to mirror the way it is done in the agda-stdlib? infixr 2 _<⟨_⟩_ _≤<⟨_⟩_ _≤⟨_⟩_ _<≤⟨_⟩_ _≡<⟨_⟩_ _≡≤⟨_⟩_ _<≡⟨_⟩_ _≤≡⟨_⟩_ _<⟨_⟩_ : ∀ k → k < n → n < m → k < m _ <⟨ p ⟩ q = <-trans p q _≤<⟨_⟩_ : ∀ k → k ≤ n → n < m → k < m _ ≤<⟨ p ⟩ q = ≤<-trans p q _≤⟨_⟩_ : ∀ k → k ≤ n → n ≤ m → k ≤ m _ ≤⟨ p ⟩ q = ≤-trans p q _<≤⟨_⟩_ : ∀ k → k < n → n ≤ m → k < m _ <≤⟨ p ⟩ q = <≤-trans p q _≡≤⟨_⟩_ : ∀ k → k ≡ l → l ≤ m → k ≤ m _ ≡≤⟨ p ⟩ q = subst (λ k → k ≤ _) (sym p) q _≡<⟨_⟩_ : ∀ k → k ≡ l → l < m → k < m _ ≡<⟨ p ⟩ q = _ ≡≤⟨ cong suc p ⟩ q _≤≡⟨_⟩_ : ∀ k → k ≤ l → l ≡ m → k ≤ m _ ≤≡⟨ p ⟩ q = subst (λ l → _ ≤ l) q p _<≡⟨_⟩_ : ∀ k → k < l → l ≡ m → k < m _ <≡⟨ p ⟩ q = _ ≤≡⟨ p ⟩ q module LowerBoundedInduction where -- given k, if X holds for every r + k, -- then X holds for all k ≥ r +Type→≤Type : (k : ℕ) → (X : ℕ → Type ℓ) → ((r : ℕ) → X (r + k)) → (n : ℕ) → k ≤ n → X n +Type→≤Type k X Xk+ n p = subst (λ n → X n) (snd p) (Xk+ (fst p)) -- same as above, but with arity 2 +Type→≤Type2 : (k k' : ℕ) → (X : ℕ → ℕ → Type ℓ) → ((r r' : ℕ) → X (r + k) (r' + k')) → (n n' : ℕ) → k ≤ n → k' ≤ n' → X n n' +Type→≤Type2 k k' X Xk'+ n n' p p' = +Type→≤Type k (λ n → X n n') (λ r → +Type→≤Type k' (λ n' → X (r + k) n') (λ r' → Xk'+ r r') n' p') n p
29.581994
88
0.44663
fd386cbd4891687b16a73c85b3c063ee3dc826df
2,018
agda
Agda
src/Categories/Category/Instance/Properties/Setoids/Complete.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
279
2019-06-01T14:36:40.000Z
2022-03-22T00:40:14.000Z
src/Categories/Category/Instance/Properties/Setoids/Complete.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
236
2019-06-01T14:53:54.000Z
2022-03-28T14:31:43.000Z
src/Categories/Category/Instance/Properties/Setoids/Complete.agda
seanpm2001/agda-categories
d9e4f578b126313058d105c61707d8c8ae987fa8
[ "MIT" ]
64
2019-06-02T16:58:15.000Z
2022-03-14T02:00:59.000Z
{-# OPTIONS --without-K --safe #-} module Categories.Category.Instance.Properties.Setoids.Complete where open import Level open import Data.Product using (Σ; proj₁; proj₂; _,_; Σ-syntax; _×_; -,_) open import Function.Equality using (Π) open import Relation.Binary using (Setoid; Rel) open import Categories.Category using (Category; _[_,_]) open import Categories.Functor open import Categories.Category.Instance.Setoids open import Categories.Category.Complete import Categories.Category.Construction.Cones as Co open Π using (_⟨$⟩_) 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) } } } ; ⊤-is-terminal = record { ! = λ {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._≈_
32.031746
92
0.482656
fdb6e3785adaa066d401e484a45302ef8cc1bf18
1,404
agda
Agda
theorems/homotopy/IterSuspensionStable.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
theorems/homotopy/IterSuspensionStable.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
theorems/homotopy/IterSuspensionStable.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
1
2018-12-26T21:31:57.000Z
2018-12-26T21:31:57.000Z
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import homotopy.Freudenthal module homotopy.IterSuspensionStable where {- π (S k) (Ptd-Susp^ (S n) X) == π k (Ptd-Susp^ n X), where k = S k' Susp^Stable below assumes k ≠ O instead of taking k' as the argument -} module Susp^StableSucc {i} (X : Ptd i) (cX : is-connected 0 (de⊙ X)) (k n : ℕ) (Skle : S k ≤ n *2) where {- some numeric computations -} private Skle' : ⟨ S k ⟩ ≤T ⟨ n ⟩₋₁ +2+ ⟨ n ⟩₋₁ Skle' = ≤T-trans (⟨⟩-monotone-≤ Skle) (inl (lemma n)) where lemma : (n : ℕ) → ⟨ n *2 ⟩ == ⟨ n ⟩₋₁ +2+ ⟨ n ⟩₋₁ lemma O = idp lemma (S n') = ap S (ap S (lemma n') ∙ ! (+2+-βr ⟨ S n' ⟩₋₂ ⟨ S n' ⟩₋₂)) private module F = FreudenthalIso ⟨ n ⟩₋₂ k Skle' (⊙Susp^ n X) (transport (λ t → is-connected t (de⊙ (⊙Susp^ n X))) (+2+0 ⟨ n ⟩₋₂) (⊙Susp^-conn n cX)) stable : πS (S k) (⊙Susp^ (S n) X) ≃ᴳ πS k (⊙Susp^ n X) stable = πS (S k) (⊙Susp^ (S n) X) ≃ᴳ⟨ πS-Ω-split-iso k (⊙Susp^ (S n) X) ⟩ πS k (⊙Ω (⊙Susp^ (S n) X)) ≃ᴳ⟨ Ω^S-group-Trunc-fuse-diag-iso k (⊙Ω (⊙Susp^ (S n) X)) ⁻¹ᴳ ⟩ Ω^S-group k (⊙Trunc ⟨ S k ⟩ (⊙Ω (⊙Susp^ (S n) X))) Trunc-level ≃ᴳ⟨ F.iso ⁻¹ᴳ ⟩ Ω^S-group k (⊙Trunc ⟨ S k ⟩ (⊙Susp^ n X)) Trunc-level ≃ᴳ⟨ Ω^S-group-Trunc-fuse-diag-iso k (⊙Susp^ n X) ⟩ πS k (⊙Susp^ n X) ≃ᴳ∎
36
74
0.490028
5254b9a589ecc9e898d7a376a66ed20a4ca73ab0
3,968
agda
Agda
test/Succeed/SizedCoinductiveRecords.agda
redfish64/autonomic-agda
c0ae7d20728b15d7da4efff6ffadae6fe4590016
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/SizedCoinductiveRecords.agda
redfish64/autonomic-agda
c0ae7d20728b15d7da4efff6ffadae6fe4590016
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/SizedCoinductiveRecords.agda
redfish64/autonomic-agda
c0ae7d20728b15d7da4efff6ffadae6fe4590016
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --copatterns --sized-types --experimental-irrelevance #-} -- {-# OPTIONS --show-implicit --show-irrelevant #-} -- {-# OPTIONS -v tc.polarity:10 -v tc.pos:15 -v tc.size.solve:100 #-} module SizedCoinductiveRecords where open import Common.Size {- THIS WOULD BE A BETTER TYPING FOR sizeSuc, but it requires builtin Size< sizeSuc : (i : Size) → Size< (↑ (↑ i)) sizeSuc i = ↑ i -} -- -- Subtyping for Size< -- Andreas, 2015-03-15: Functions returning sizes are now illegal: -- emb< : {i : Size} → Size< i → Size -- emb< {i} j = j -- Use Size< hypotheses data Empty : {i : Size} → Set where empty : {i : Size} → Empty {i} → Empty {↑ i} subEmpty : {i : Size}{j : Size< i} → Empty {j} → Empty {i} subEmpty x = x -- SHOULD FAIL: -- fail : {i : Size}{j : Size< i} → Empty {i} → Empty {j} -- fail x = x -- -- Covariance for Size< -- Andreas, 2015-03-15: Functions returning sizes are now illegal: -- co : {i : Size}{j : Size< i} → Size< j → Size< i -- co k = k -- Contravariance for bounded quantification Bounded : Size → Set Bounded i = (j : Size< i) → Empty {j} contra : {i : Size}{j : Size< i} → Bounded i → Bounded j contra k = k -- sized naturals data Nat {i : Size} : Set where zero : Nat suc : {j : Size< i} → Nat {j} → Nat -- polarity of successor data Bool : Set where true false : Bool -- a natural number one : Nat one = suc {i = ∞} zero mySuc : {i : Size} → Nat {i} → Nat {↑ i} mySuc x = suc x pred : {i : Size} → Nat {↑ i} → Nat {i} pred zero = zero pred (suc n) = n shift : {i : Size} → (Nat → Nat {↑ i}) → Nat → Nat {i} shift f n = pred (f (suc n)) {- Does not type check loop : {i : Size} → Nat {i} → (Nat → Nat {i}) → Set loop (suc n) f = loop n (shift f) loop zero = Nat -} data ⊥ : Set where record ⊤ : Set where mono : {i : Size}{j : Size< i} → Nat {j} → Nat {i} mono n = n id : {i : Size} → Nat {i} → Nat {i} id (zero) = zero id (suc n) = suc (id n) monus : {i : Size} → Nat {i} → Nat → Nat {i} monus x zero = x monus zero y = zero monus (suc x) (suc y) = monus x y div : {i : Size} → Nat {i} → Nat → Nat {i} div zero y = zero div (suc x) y = suc (div (monus x y) y) -- postulate _∪_ : {i : Size} → Size< i → Size< i → Size< i {- max : {i : Size} → Nat {i} → Nat {i} → Nat {i} max zero n = n max m zero = m max {i} (suc {j = j} m) (suc {j = k} n) = suc {j = j ∪ k} (max {j ∪ k} m n) -} -- omega inst {- DOES NOT MAKE SENSE: omegaBad' : (F : Size → Set) (i : Size) (j : Size< i) (f : (k : Size< (↑ j)) → F k) → F j omegaBad' F i j f = f j -} -- fix A : Size → Set A i = Nat {i} → Nat {-# TERMINATING #-} fix : (f : (i : Size) → ((j : Size< i) → A j) → A i) → (i : Size) → A i fix f i zero = zero fix f i (suc {j} n) = f i (λ j → fix f j) (suc n) -- forever : {i : Size} → ({j : Size< i} → Nat {i} → Nat {j}) → Nat {i} → ⊥ -- forever {i} f n = forever f (f {{!!}} n) -- sized streams module STREAM where record Stream (A : Set) {i : Size} : Set where coinductive constructor _∷_ field head : A tail : {j : Size< i} → Stream A {j} open Stream map : {A B : Set}(f : A → B){i : Size} → Stream A {i} → Stream B {i} head (map f s) = f (head s) tail (map f s) = map f (tail s) -- stream antitone anti : {A : Set}{i : Size}{j : Size< i} → Stream A {i} → Stream A {j} anti s = s anti' : {A : Set}{i : Size}{j : Size< i} → (Stream A {j} → A) → (Stream A {i} → A) anti' f = f -- Spanning tree data List (A : Set) {i : Size} : Set where [] : List A _∷_ : {j : Size< i}(x : A)(xs : List A {j}) → List A map : {A B : Set}(f : A → B){i : Size} → List A {i} → List B {i} map f [] = [] map f (x ∷ xs) = f x ∷ map f xs module Graph (I : Set)(adj : I → List I) where record Span {i : Size} : Set where coinductive constructor span field root : I nodes : {j : Size< i} → List (Span {j}) open Span tree : {i : Size} → I → Span {i} root (tree root) = root nodes (tree root) = map (tree) (adj root)
23.069767
84
0.533266
fdfb6a349b51b2748c3c201ce125d813673775f9
2,016
agda
Agda
src/Tactic/Nat/Less/Lemmas.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
null
null
null
src/Tactic/Nat/Less/Lemmas.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
null
null
null
src/Tactic/Nat/Less/Lemmas.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
null
null
null
module Tactic.Nat.Less.Lemmas where open import Prelude open import Tactic.Nat.Exp open import Tactic.Nat.NF open import Tactic.Nat.Subtract.Exp open import Tactic.Nat.Auto.Lemmas open import Tactic.Nat.Simpl.Lemmas open import Tactic.Nat.Subtract.Lemmas liftNFSubLess : ∀ e₁ e₂ ρ → ⟦ normSub e₁ ⟧sn ρ < ⟦ normSub e₂ ⟧sn ρ → ⟦ e₁ ⟧se ρ < ⟦ e₂ ⟧se ρ liftNFSubLess e₁ e₂ ρ (diff k eq) = diff k (eraseEquality $ sound-sub e₂ ρ ⟨≡⟩ eq ⟨≡⟩ʳ (suc k +_) $≡ sound-sub e₁ ρ) SubExpLess : SubExp → SubExp → Env Var → Set SubExpLess e₁ e₂ ρ = ⟦ e₁ ⟧se ρ < ⟦ e₂ ⟧se ρ NFLessS : SubNF × SubNF → Env SubAtom → Set NFLessS (nf₁ , nf₂) ρ = ⟦ nf₁ ⟧ns ρ < ⟦ nf₂ ⟧ns ρ CancelSubLess : SubExp → SubExp → Env Var → Set CancelSubLess e₁ e₂ ρ = NFLessS (cancel (normSub e₁) (normSub e₂)) (atomEnvS ρ) c⟦_⟧eqn : Eqn → Env Var → Set c⟦ a :≡ b ⟧eqn = CancelSubEq a b c⟦ a :< b ⟧eqn = CancelSubLess a b simplifySubLess : ∀ e₁ e₂ (ρ : Env Var) → CancelSubLess e₁ e₂ ρ → SubExpLess e₁ e₂ ρ simplifySubLess e₁ e₂ ρ H with cancel (normSub e₁) (normSub e₂) | λ a b → cancel-sound′ a b (normSub e₁) (normSub e₂) (atomEnvS ρ) simplifySubLess e₁ e₂ ρ (diff k H) | v₁ , v₂ | sound = liftNFSubLess e₁ e₂ ρ $ diff k $ lem-eval-sn-nS (normSub e₂) ρ ⟨≡⟩ sound (suc k) 0 ((suc k +_) $≡ ns-sound v₁ (atomEnvS ρ) ʳ⟨≡⟩ H ʳ⟨≡⟩ ns-sound v₂ (atomEnvS ρ)) ʳ⟨≡⟩ʳ (suc k +_) $≡ lem-eval-sn-nS (normSub e₁) ρ complicateSubLess : ∀ e₁ e₂ ρ → SubExpLess e₁ e₂ ρ → CancelSubLess e₁ e₂ ρ complicateSubLess e₁ e₂ ρ H with cancel (normSub e₁) (normSub e₂) | λ a b → cancel-complete′ a b (normSub e₁) (normSub e₂) (atomEnvS ρ) complicateSubLess e₁ e₂ ρ (diff k H) | v₁ , v₂ | complete = diff k (eraseEquality $ ns-sound v₂ (atomEnvS ρ) ⟨≡⟩ complete (suc k) 0 ((suc k +_) $≡ lem-eval-sn-nS (normSub e₁) ρ ʳ⟨≡⟩ (suc k +_) $≡ sound-sub e₁ ρ ʳ⟨≡⟩ H ʳ⟨≡⟩ sound-sub e₂ ρ ⟨≡⟩ lem-eval-sn-nS (normSub e₂) ρ) ʳ⟨≡⟩ʳ (suc k +_) $≡ ns-sound v₁ (atomEnvS ρ))
38.769231
104
0.622024
226a9c8a8579c9ddab26adf4cff388bc0a4ee083
10,609
agda
Agda
agda/Number/Structures.agda
mchristianl/synthetic-reals
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
[ "MIT" ]
3
2020-07-31T18:15:26.000Z
2022-02-19T12:15:21.000Z
agda/Number/Structures.agda
mchristianl/synthetic-reals
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
[ "MIT" ]
null
null
null
agda/Number/Structures.agda
mchristianl/synthetic-reals
10206b5c3eaef99ece5d18bf703c9e8b2371bde4
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts #-} open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero) module Number.Structures where private variable ℓ ℓ' : Level open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc) open import Cubical.Relation.Nullary.Base -- ¬_ open import Cubical.Relation.Binary.Base -- Rel -- open import Data.Nat.Base using (ℕ) renaming (_≤_ to _≤ₙ_) open import Cubical.Data.Nat using (ℕ; zero; suc) renaming (_+_ to _+ₙ_) open import Cubical.Data.Nat.Order renaming (zero-≤ to z≤n; suc-≤-suc to s≤s; _≤_ to _≤ₙ_; _<_ to _<ₙ_) open import Cubical.Data.Unit.Base -- Unit open import Cubical.Data.Empty -- ⊥ open import Cubical.Data.Sum.Base renaming (_⊎_ to infixr 4 _⊎_) open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_) open import Cubical.Data.Empty renaming (elim to ⊥-elim) -- `⊥` and `elim` open import Cubical.Data.Maybe.Base import MoreAlgebra open MoreAlgebra.Definitions import Algebra.Structures -- ℕ ℤ ℚ ℝ ℂ and ℚ₀⁺ ℝ₀⁺ ... -- ring without additive inverse -- see Algebra.Structures.IsCommutativeSemiring record IsRCommSemiring {F : Type ℓ} (_#_ : Rel F F ℓ') (0f 1f : F) (_+_ _·_ : F → F → F) : Type (ℓ-max ℓ ℓ') where field isApartnessRel : IsApartnessRel _#_ -- TODO: properties open IsApartnessRel isApartnessRel public renaming ( isIrrefl to #-irrefl ; isSym to #-sym ; isCotrans to #-cotrans ) -- ℤ ℚ ℝ ℂ -- see Algebra.Structures.IsCommutativeRing record IsRCommRing {F : Type ℓ} (_#_ : Rel F F ℓ') (0f 1f : F) (_+_ _·_ : F → F → F) (-_ : F → F) : Type (ℓ-max ℓ ℓ') where field isRCommSemiring : IsRCommSemiring _#_ 0f 1f _+_ _·_ open IsRCommSemiring isRCommSemiring public -- ℚ ℝ ℂ record IsRField {F : Type ℓ} (_#_ : Rel F F ℓ') (0f 1f : F) (_+_ _·_ : F → F → F) (-_ : F → F) (_⁻¹ : (x : F) → {{ x # 0f }} → F) : Type (ℓ-max ℓ ℓ') where field isRCommRing : IsRCommRing _#_ 0f 1f _+_ _·_ -_ +-assoc : ∀ x y z → (x + y) + z ≡ x + (y + z) +-comm : ∀ x y → x + y ≡ y + x distrib : ∀ x y z → (x + y) · z ≡ (x · z) + (y · z) ⁻¹-preserves-#0 : ∀ x → (p : x # 0f) → _⁻¹ x {{p}} # 0f -preserves-# : ∀ x y → x # y → (- x) # (- y) -preserves-#0 : ∀ x → x # 0f → (- x) # 0f ·-#0-#0-implies-#0 : ∀ a b → a # 0f → b # 0f → (a · b) # 0f 1#0 : 1f # 0f -- TODO: properties open IsRCommRing isRCommRing public -- Finₖ ℕ ℤ ℚ ℝ and ℚ₀⁺ ℚ⁺ ℝ₀⁺ ℝ⁺ ... record IsRLattice {F : Type ℓ} (_<_ _≤_ _#_ : Rel F F ℓ') (min max : F → F → F) : Type (ℓ-max ℓ ℓ') where field isPartialOrder : IsPartialOrder _≤_ glb : ∀ x y z → z ≤ min x y → z ≤ x × z ≤ y glb-back : ∀ x y z → z ≤ x × z ≤ y → z ≤ min x y lub : ∀ x y z → max x y ≤ z → x ≤ z × y ≤ z lub-back : ∀ x y z → x ≤ z × y ≤ z → max x y ≤ z -- TODO: derived properties <-implies-# : ∀ x y → x < y → x # y ≤-#-implies-< : ∀ x y → x ≤ y → x # y → x < y #-sym : ∀ x y → x # y → y # x max-sym : ∀ x y → max x y ≡ max y x max-id : ∀ x → max x x ≡ x open IsPartialOrder isPartialOrder public -- ℕ ℤ ℚ ℝ and ℚ₀⁺ ℚ⁺ ℝ₀⁺ ℝ⁺ ... -- ring without additive inverse record IsROrderedCommSemiring {F : Type ℓ} (_<_ _≤_ _#_ : Rel F F ℓ') (min max : F → F → F) (0f 1f : F) (_+_ _·_ : F → F → F) : Type (ℓ-max ℓ ℓ') where field isRLattice : IsRLattice _<_ _≤_ _#_ min max isRCommSemiring : IsRCommSemiring _#_ 0f 1f _+_ _·_ -- TODO: properties -- TODO: the following can be derived 0<1 : 0f < 1f +-0<-0<-implies-0< : ∀ a b → 0f < a → 0f < b → 0f < (a + b) +-0<-0≤-implies-0< : ∀ a b → 0f < a → 0f ≤ b → 0f < (a + b) +-0≤-0<-implies-0< : ∀ a b → 0f ≤ a → 0f < b → 0f < (a + b) +-0≤-0≤-implies-0≤ : ∀ a b → 0f ≤ a → 0f ≤ b → 0f ≤ (a + b) +-<0-<0-implies-<0 : ∀ a b → a < 0f → b < 0f → (a + b) < 0f +-<0-≤0-implies-<0 : ∀ a b → a < 0f → b ≤ 0f → (a + b) < 0f +-≤0-<0-implies-<0 : ∀ a b → a ≤ 0f → b < 0f → (a + b) < 0f +-≤0-≤0-implies-≤0 : ∀ a b → a ≤ 0f → b ≤ 0f → (a + b) ≤ 0f ·-#0-#0-implies-#0 : ∀ a b → a # 0f → b # 0f → (a · b) # 0f ·-#0-0<-implies-#0 : ∀ a b → a # 0f → 0f < b → (a · b) # 0f ·-#0-<0-implies-#0 : ∀ a b → a # 0f → b < 0f → (a · b) # 0f ·-0≤-0≤-implies-0≤ : ∀ a b → 0f ≤ a → 0f ≤ b → 0f ≤ (a · b) ·-0≤-0<-implies-0≤ : ∀ a b → 0f ≤ a → 0f < b → 0f ≤ (a · b) ·-0≤-<0-implies-≤0 : ∀ a b → 0f ≤ a → b < 0f → (a · b) ≤ 0f ·-0≤-≤0-implies-≤0 : ∀ a b → 0f ≤ a → b ≤ 0f → (a · b) ≤ 0f ·-0<-#0-implies-#0 : ∀ a b → 0f < a → b # 0f → (a · b) # 0f ·-0<-0≤-implies-0≤ : ∀ a b → 0f < a → 0f ≤ b → 0f ≤ (a · b) ·-0<-0<-implies-0< : ∀ a b → 0f < a → 0f < b → 0f < (a · b) ·-0<-<0-implies-<0 : ∀ a b → 0f < a → b < 0f → (a · b) < 0f ·-0<-≤0-implies-≤0 : ∀ a b → 0f < a → b ≤ 0f → (a · b) ≤ 0f ·-<0-#0-implies-#0 : ∀ a b → a < 0f → b # 0f → (a · b) # 0f ·-<0-0≤-implies-≤0 : ∀ a b → a < 0f → 0f ≤ b → (a · b) ≤ 0f ·-<0-0<-implies-<0 : ∀ a b → a < 0f → 0f < b → (a · b) < 0f ·-<0-<0-implies-0< : ∀ a b → a < 0f → b < 0f → 0f < (a · b) ·-<0-≤0-implies-0≤ : ∀ a b → a < 0f → b ≤ 0f → 0f ≤ (a · b) ·-≤0-0≤-implies-≤0 : ∀ a b → a ≤ 0f → 0f ≤ b → (a · b) ≤ 0f ·-≤0-0<-implies-≤0 : ∀ a b → a ≤ 0f → 0f < b → (a · b) ≤ 0f ·-≤0-<0-implies-0≤ : ∀ a b → a ≤ 0f → b < 0f → 0f ≤ (a · b) ·-≤0-≤0-implies-0≤ : ∀ a b → a ≤ 0f → b ≤ 0f → 0f ≤ (a · b) 0≤-#0-implies-0< : ∀ x → 0f ≤ x → x # 0f → 0f < x {- ·-#0-#0-implies-#0 : ∀ a b → a # 0f → b # 0f → (a · b) # 0f ·-#0-0<-implies-#0 : ∀ a b → a # 0f → 0f < b → (a · b) # 0f ·-0≤-0≤-implies-0≤ : ∀ a b → 0f ≤ a → 0f ≤ b → 0f ≤ (a · b) ·-0≤-0<-implies-0≤ : ∀ a b → 0f ≤ a → 0f < b → 0f ≤ (a · b) ·-0≤-≤0-implies-≤0 : ∀ a b → 0f ≤ a → b ≤ 0f → (a · b) ≤ 0f ·-0<-#0-implies-#0 : ∀ a b → 0f < a → b # 0f → (a · b) # 0f ·-0<-0≤-implies-0≤ : ∀ a b → 0f < a → 0f ≤ b → 0f ≤ (a · b) ·-0<-0<-implies-0< : ∀ a b → 0f < a → 0f < b → 0f < (a · b) ·-0<-≤0-implies-≤0 : ∀ a b → 0f < a → b ≤ 0f → (a · b) ≤ 0f ·-≤0-0≤-implies-≤0 : ∀ a b → a ≤ 0f → 0f ≤ b → (a · b) ≤ 0f ·-≤0-0<-implies-≤0 : ∀ a b → a ≤ 0f → 0f < b → (a · b) ≤ 0f ·-≤0-≤0-implies-0≤ : ∀ a b → a ≤ 0f → b ≤ 0f → 0f ≤ (a · b) -} open IsRLattice isRLattice public -- ℤ ℚ ℝ record IsROrderedCommRing {F : Type ℓ} (_<_ _≤_ _#_ : Rel F F ℓ') (min max : F → F → F) (0f 1f : F) (_+_ _·_ : F → F → F) (-_ : F → F) : Type (ℓ-max ℓ ℓ') where field isROrderedCommSemiring : IsROrderedCommSemiring _<_ _≤_ _#_ min max 0f 1f _+_ _·_ isRCommRing : IsRCommRing _#_ 0f 1f _+_ _·_ -_ 0≡-0 : 0f ≡ - 0f -flips-< : ∀ x y → x < y → (- y) < (- x) -flips-<0 : ∀ x → x < 0f → 0f < (- x) -flips-0< : ∀ x → 0f < x → (- x) < 0f -flips-≤ : ∀ x y → x ≤ y → (- y) ≤ (- x) -flips-≤0 : ∀ x → x ≤ 0f → 0f ≤ (- x) -flips-0≤ : ∀ x → 0f ≤ x → (- x) ≤ 0f -preserves-# : ∀ x y → x # y → (- x) # (- y) -preserves-#0 : ∀ x → x # 0f → (- x) # 0f -- TODO: properties open IsROrderedCommSemiring isROrderedCommSemiring public -- Remark 6.7.7. As we define absolute values by | x | = max(x, -x), as is common in constructive analysis, -- if x has a locator, then so does | x |, and we use this fact in the proof of the above theorem. -- Remark 4.1.9. -- -- 1. From the fact that (A, ≤, min, max) is a lattice, it does not follow that -- for every x and y, -- -- max(x, y) = x ∨ max(x, y) = y, -- -- which would hold in a linear order. -- However, in Lemma 6.7.1 we characterize max as -- -- z < max(x, y) ⇔ z < x ∨ z < y, -- -- and similarly for min. {- from: https://isabelle.in.tum.de/doc/tutorial.pdf "8.4.5 The Numeric Type Classes" Absolute Value. The absolute value function `abs` is available for all ordered rings, including types int, rat and real. It satisfies many properties, such as the following: | x * y | ≡ | x | * | y | (abs_mult) | a | ≤ b ⇔ (a ≤ b) ∧ (- a) ≤ b (abs_le_iff) | a + b | ≤ | a | + | b | (abs_triangle_ineq) -} -- also see https://en.wikipedia.org/wiki/Ordered_ring#Basic_properties record IsAbsOrderedCommRing {F : Type ℓ} (_<_ _≤_ _#_ : Rel F F ℓ') (min max : F → F → F) (0f 1f : F) (_+_ _·_ : F → F → F) (-_ : F → F) (abs : F → F) : Type (ℓ-max ℓ ℓ') where field abs0≡0 : abs 0f ≡ 0f abs-preserves-· : ∀ x y → abs (x · y) ≡ abs x · abs y triangle-ineq : ∀ x y → abs (x + y) ≤ (abs x + abs y) -- -trichotomy : ∀ x → (x ≡ 0f) ⊎ (0f < x) ⊎ (0f < (- x)) abs-≤ : ∀ x y → abs x ≤ y → (x ≤ y) × ((- x) ≤ y) abs-≤-back : ∀ x y → (x ≤ y) × ((- x) ≤ y) → abs x ≤ y 0≤abs : ∀ x → 0f ≤ abs x -- ℚ ℝ record IsROrderedField {F : Type ℓ} (_<_ _≤_ _#_ : Rel F F ℓ') (min max : F → F → F) (0f 1f : F) (_+_ _·_ : F → F → F) (-_ : F → F) (_⁻¹ : (x : F) → {{ x # 0f }} → F) : Type (ℓ-max ℓ ℓ') where field isROrderedCommRing : IsROrderedCommRing _<_ _≤_ _#_ min max 0f 1f _+_ _·_ -_ isRField : IsRField _#_ 0f 1f _+_ _·_ -_ _⁻¹ -- TODO: properties open IsROrderedCommRing isROrderedCommRing hiding ( -preserves-# ; -preserves-#0 ) public open IsRField isRField hiding ( ·-#0-#0-implies-#0 ) public field ⁻¹-preserves-<0 : ∀ x → (x < 0f) → (p : x # 0f) → _⁻¹ x {{p}} < 0f ⁻¹-preserves-0< : ∀ x → (0f < x) → (p : x # 0f) → 0f < _⁻¹ x {{p}} -- ℚ₀⁺ ℚ₀⁻ ℝ₀⁺ ℝ₀⁻ {- record IsROrderedSemifield {F : Type ℓ} (_<_ _≤_ _#_ : Rel F F ℓ') (min max : F → F → F) (0f 1f : F) (_+_ _·_ : F → F → F) (_⁻¹ : (x : F) → {{ x < 0f }} → F) : Type (ℓ-max ℓ ℓ') where field isROrderedCommSemiring : IsROrderedCommSemiring _<_ _≤_ _#_ min max 0f 1f _+_ _·_ -- TODO: properties #0-implies-0< : ∀ x → 0f # x → 0f < x positivity : ∀ x → 0f ≤ x open IsROrderedCommSemiring isROrderedCommSemiring public -} -- ℚ⁺ ℚ⁻ ℝ⁺ ℝ⁻ {- record IsROrderedSemifieldWithoutZero {F : Type ℓ} (_<_ _≤_ _#_ : Rel F F ℓ') (min max : F → F → F) (0f 1f : F) (_+_ _·_ : F → F → F) (_⁻¹ : (x : F) → F) : Type (ℓ-max ℓ ℓ') where field isRLattice : IsRLattice _<_ _≤_ _#_ min max -- isGroup : IsGroup 1f _·_ _⁻¹ +-assoc : ∀ x y z → (x + y) + z ≡ x + (y + z) +-comm : ∀ x y → x + y ≡ y + x distrib : ∀ x y z → (x + y) · z ≡ (x · z) + (y · z) -- TODO: properties open IsRLattice isRLattice public -}
42.266932
192
0.478273
9a174ec33f5122919f13f19a20dbc1fb28b72659
2,620
agda
Agda
Peano.agda
cantsin/agda-experiments
382fcfae193079783621fc5cf54b6588e22ef759
[ "Apache-2.0" ]
null
null
null
Peano.agda
cantsin/agda-experiments
382fcfae193079783621fc5cf54b6588e22ef759
[ "Apache-2.0" ]
null
null
null
Peano.agda
cantsin/agda-experiments
382fcfae193079783621fc5cf54b6588e22ef759
[ "Apache-2.0" ]
null
null
null
open import Agda.Primitive open import Empty open import Logic open import Boolean module Peano where data ℕ : Set where zero : ℕ succ : ℕ → ℕ {-# BUILTIN NATURAL ℕ #-} pred : ℕ → ℕ pred zero = zero pred (succ x) = x _+_ : ℕ → ℕ → ℕ zero + m = m (succ n) + m = succ (n + m) {-# BUILTIN NATPLUS _+_ #-} _∘_ : ℕ → ℕ → ℕ zero ∘ _ = zero (succ n) ∘ m = (n ∘ m) + m {-# BUILTIN NATTIMES _∘_ #-} data _≡_ (x : ℕ) : ℕ → Set where refl : x ≡ x data _≢_ : ℕ → ℕ → Set where z≢s : ∀ {n} → zero ≢ succ n s≢z : ∀ {n} → succ n ≢ zero s≢s : ∀ {m n} → m ≢ n → succ m ≢ succ n data Equal? (m n : ℕ) : Set where yes : m ≡ n → Equal? m n no : m ≢ n → Equal? m n _≟_ : (m n : ℕ) → Equal? m n _≟_ zero zero = yes refl _≟_ zero (succ _) = no z≢s _≟_ (succ _) zero = no s≢z _≟_ (succ m) (succ n) with m ≟ n _≟_ (succ m) (succ .m) | yes refl = yes refl _≟_ (succ m) (succ n) | no p = no (s≢s p) equality-disjoint : (m n : ℕ) → m ≡ n → m ≢ n → ⊥ equality-disjoint zero zero refl () equality-disjoint zero (succ _) () z≢s equality-disjoint (succ _) zero () s≢z equality-disjoint (succ m) (succ .m) refl (s≢s e) = equality-disjoint m m refl e private -- to make the last `equality-disjoint` match clearer, verify that s≢s can be nested test-s≢s : (succ (succ (succ zero))) ≢ (succ (succ zero)) test-s≢s = s≢s (s≢s s≢z) data Ordering : Rel ℕ where less : ∀ m k → Ordering m (succ (m + k)) equal : ∀ m → Ordering m m greater : ∀ m k → Ordering (succ (m + k)) m compare : ∀ m n → Ordering m n compare zero zero = equal zero compare (succ m) zero = greater zero m compare zero (succ n) = less zero n compare (succ m) (succ n) with compare m n compare (succ .m) (succ .(succ m + k)) | less m k = less (succ m) k compare (succ .m) (succ .m) | equal m = equal (succ m) compare (succ .(succ m + k)) (succ .m) | greater m k = greater (succ m) k infix 4 _≤_ _<_ _≥_ _>_ _≰_ _≮_ _≱_ _≯_ data _≤_ : Rel ℕ where z≤n : ∀ {n} → zero ≤ n s≤s : ∀ {m n} (m≤n : m ≤ n) → succ m ≤ succ n _<_ : Rel ℕ m < n = succ m ≤ n _≥_ : Rel ℕ m ≥ n = n ≤ m _>_ : Rel ℕ m > n = n < m _≰_ : Rel ℕ a ≰ b = ¬ (a ≤ b) _≮_ : Rel ℕ a ≮ b = ¬ (a < b) _≱_ : Rel ℕ a ≱ b = ¬ (a ≥ b) _≯_ : Rel ℕ a ≯ b = ¬ (a > b) data _even : ℕ → Set where ZERO : zero even STEP : ∀ {x} → x even → succ (succ x) even private proof₁ : succ(succ(succ(succ(zero)))) even proof₁ = STEP (STEP ZERO) proof₂ : (A : Set) → A → A proof₂ _ ν = ν proof'₂ : ℕ → ℕ proof'₂ = proof₂ ℕ
23.392857
88
0.520992
35ce7b9ccbb5e13a181de7e966b4f2958aa428b8
600
agda
Agda
test/Succeed/Issue2650.agda
asr/eagda
7220bebfe9f64297880ecec40314c0090018fdd0
[ "BSD-3-Clause" ]
1
2016-03-17T01:45:59.000Z
2016-03-17T01:45:59.000Z
test/Succeed/Issue2650.agda
asr/eagda
7220bebfe9f64297880ecec40314c0090018fdd0
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/Issue2650.agda
asr/eagda
7220bebfe9f64297880ecec40314c0090018fdd0
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
{-# OPTIONS --cubical #-} module _ where module _ where import Agda.Primitive open import Agda.Primitive.Cubical public postulate Path' : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ PathP : ∀ {ℓ} (A : I → Set ℓ) → A i0 → A i1 → Set ℓ {-# BUILTIN PATH Path' #-} {-# BUILTIN PATHP PathP #-} infix 4 _≡_ _≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ _≡_ {A = A} = PathP (λ _ → A) Path = _≡_ refl : ∀ {a} {A : Set a} {x : A} → x ≡ x refl {x = x} = \ _ → x testPath : ∀ {A : Set} {b a : A} (let H : Path b b; H = _) → ∀ i → H i ≡ b testPath i = refl
22.222222
74
0.463333
436b8fa94678150f64818c4d72f7e13e1fb1bce0
1,578
agda
Agda
src/Dijkstra/EitherD/Syntax.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/Dijkstra/EitherD/Syntax.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
src/Dijkstra/EitherD/Syntax.agda
LaudateCorpus1/bft-consensus-agda
a4674fc473f2457fd3fe5123af48253cfb2404ef
[ "UPL-1.0" ]
null
null
null
{- 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 -} module Dijkstra.EitherD.Syntax where open import Dijkstra.EitherD open import Dijkstra.EitherLike open import Dijkstra.Syntax open import Haskell.Prelude private variable E : Set A B C : Set -- From this instance declaration, we get _<$>_, pure, and _<*>_ also. instance Monad-EitherD : ∀ {E : Set} → Monad (EitherD E) Monad.return Monad-EitherD = EitherD-return Monad._>>=_ Monad-EitherD = EitherD-bind -- These instance declarations give us variant conditional operations that we -- can define to play nice with `EitherD-weakestPre` instance EitherD-MonadIfD : MonadIfD{ℓ₃ = ℓ0} (EitherD E) MonadIfD.monad EitherD-MonadIfD = Monad-EitherD MonadIfD.ifD‖ EitherD-MonadIfD = EitherD-if EitherD-MonadMaybeD : MonadMaybeD (EitherD E) MonadMaybeD.monad EitherD-MonadMaybeD = Monad-EitherD MonadMaybeD.maybeD EitherD-MonadMaybeD = EitherD-maybe EitherD-MonadEitherD : MonadEitherD (EitherD E) MonadEitherD.monad EitherD-MonadEitherD = Monad-EitherD MonadEitherD.eitherD EitherD-MonadEitherD = EitherD-either -- `EitherD` is Either-like instance EitherD-EitherLike : EitherLike EitherD EitherLike.fromEither EitherD-EitherLike (Left a) = EitherD-bail a EitherLike.fromEither EitherD-EitherLike (Right b) = EitherD-return b EitherLike.toEither EitherD-EitherLike = EitherD-run
32.875
111
0.76109
7c33fbee060fbda5ceb30515b63a8cdd81323b4e
825
agda
Agda
Lvl/MultiFunctions/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Lvl/MultiFunctions/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Lvl/MultiFunctions/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Lvl.MultiFunctions.Proofs where open import Data open import Lvl hiding (𝐒) open import Lvl.MultiFunctions open import Data.Tuple.Raise open import Data.Tuple.Raiseᵣ.Functions open import Lvl.MultiFunctions open import Numeral.Natural open import Relator.Equals open import Syntax.Number max-repeat : ∀{n}{ℓ} → ((ℓ ⊔ (⨆(repeat n ℓ))) ≡ ℓ) max-repeat {n = 0} = [≡]-intro max-repeat {n = 1} = [≡]-intro max-repeat {n = 𝐒(𝐒(n))} = max-repeat {n = 𝐒(n)} {- TODO: Is this possible? open import Relator.Equals.Proofs test2 : ∀{a b} → (eq : a ≡ b) → ([≡]-substitutionᵣ eq {\n → Set(n)} (Set(a)) ≡ Set(b)) test2 : ∀{a b} → (a ≡ b) → (Set(a) ≡ Set(b)) postulate ℓ : Level postulate n : ℕ postulate s : Set(ℓ ⊔ (⨆{n} (repeat n ℓ))) postulate p : Set(ℓ) → Set want : Set want rewrite max-repeat{n}{ℓ} = p s -}
25
86
0.638788
52c952d486c17a5f20bd88e3c71761ef34315293
971
agda
Agda
Cubical/Codata/Everything.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Codata/Everything.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Codata/Everything.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --guardedness #-} module Cubical.Codata.Everything where open import Cubical.Codata.EverythingSafe public --- Modules making assumptions that might be incompatible with other -- flags or make use of potentially unsafe features. -- Assumes --guardedness open import Cubical.Codata.Stream public open import Cubical.Codata.Conat public open import Cubical.Codata.Conat.Bounded open import Cubical.Codata.M public -- Also uses {-# TERMINATING #-}. open import Cubical.Codata.M.Bisimilarity public {- -- Alternative M type implemetation, based on -- https://arxiv.org/pdf/1504.02949.pdf -- "Non-wellfounded trees in Homotopy Type Theory" -- Benedikt Ahrens, Paolo Capriotti, Régis Spadotti -} open import Cubical.Codata.M.AsLimit.M open import Cubical.Codata.M.AsLimit.Coalg open import Cubical.Codata.M.AsLimit.helper open import Cubical.Codata.M.AsLimit.Container open import Cubical.Codata.M.AsLimit.itree open import Cubical.Codata.M.AsLimit.stream
28.558824
68
0.789907
fd21d0201024be91bb6cc1314f9def8fbf40d94a
871
agda
Agda
test/Succeed/Issue4944.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue4944.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue4944.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2020-09-26, issue #4944. -- Size solver got stuck on projected variables which are left over -- in some size constraints by the generalization feature. {-# OPTIONS --sized-types #-} -- {-# OPTIONS --show-implicit #-} -- {-# OPTIONS -v tc.conv.size:60 -v tc.size:30 -v tc.meta.assign:10 #-} open import Agda.Builtin.Size variable i : Size postulate A : Set data ListA (i : Size) : Set where nil : ListA i cons : (j : Size< i) (t : A) (as : ListA j) → ListA i postulate node : A → ListA ∞ → A R : (i : Size) (as as′ : ListA i) → Set test : -- {i : Size} -- made error vanish (t u : A) (as : ListA i) → R (↑ (↑ i)) (cons (↑ i) t (cons i u as)) (cons _ (node t (cons _ u nil)) as) variable t u : A as : ListA i postulate tst2 : R _ (cons _ t (cons _ u as)) (cons _ (node t (cons _ u nil)) as) -- Should pass.
23.540541
85
0.577497
3537e93c19b1a259ba19b3d428b4bd311f936d0f
21,362
agda
Agda
Cubical/ZCohomology/Groups/KleinBottle.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/ZCohomology/Groups/KleinBottle.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/ZCohomology/Groups/KleinBottle.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
{-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.ZCohomology.Groups.KleinBottle where open import Cubical.ZCohomology.Base open import Cubical.ZCohomology.GroupStructure open import Cubical.ZCohomology.Properties open import Cubical.Foundations.HLevels open import Cubical.Foundations.Prelude open import Cubical.Foundations.Pointed open import Cubical.Foundations.Function open import Cubical.Foundations.GroupoidLaws open import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to pRec2 ; elim to sElim ; elim2 to sElim2 ; map to sMap) open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; ∣_∣ to ∣_∣₁) open import Cubical.HITs.Truncation renaming (elim to trElim ; rec to trRec ; elim2 to trElim2) open import Cubical.Data.Nat hiding (+-assoc) open import Cubical.Algebra.Group renaming (Int to IntGroup ; Bool to BoolGroup ; Unit to UnitGroup) open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.Transport open import Cubical.ZCohomology.Groups.Unit open import Cubical.ZCohomology.Groups.Sn open import Cubical.Data.Sigma open import Cubical.Foundations.Isomorphism open import Cubical.HITs.S1 open import Cubical.HITs.Sn open import Cubical.Foundations.Equiv open import Cubical.Homotopy.Connected open import Cubical.Data.Empty renaming (rec to ⊥-rec) open import Cubical.Data.Bool open import Cubical.Data.Int renaming (+-comm to +-commℤ ; _+_ to _+ℤ_) open import Cubical.HITs.KleinBottle open import Cubical.Data.Empty open import Cubical.Foundations.Path open import Cubical.Homotopy.Loopspace open IsGroupHom open Iso characFunSpace𝕂² : ∀ {ℓ} (A : Type ℓ) → Iso (KleinBottle → A) (Σ[ x ∈ A ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) fun (characFunSpace𝕂² A) f = (f point) , ((cong f line1) , (cong f line2 , fst (Square≃doubleComp (cong f line2) (cong f line2) (sym (cong f line1)) (cong f line1)) (λ i j → f (square i j)))) inv (characFunSpace𝕂² A) (x , p , q , sq) point = x inv (characFunSpace𝕂² A) (x , p , q , sq) (line1 i) = p i inv (characFunSpace𝕂² A) (x , p , q , sq) (line2 i) = q i inv (characFunSpace𝕂² A) (x , p , q , sq) (square i j) = invEq (Square≃doubleComp q q (sym p) p) sq i j rightInv (characFunSpace𝕂² A) (x , (p , (q , sq))) = ΣPathP (refl , (ΣPathP (refl , (ΣPathP (refl , retEq (Square≃doubleComp q q (sym p) p) sq))))) leftInv (characFunSpace𝕂² A) f _ point = f point leftInv (characFunSpace𝕂² A) f _ (line1 i) = f (line1 i) leftInv (characFunSpace𝕂² A) f _ (line2 i) = f (line2 i) leftInv (characFunSpace𝕂² A) f z (square i j) = secEq (Square≃doubleComp (cong f line2) (cong f line2) (sym (cong f line1)) (cong f line1)) (λ i j → f (square i j)) z i j private movePathLem : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x) → isComm∙ (A , x) → (p ∙∙ q ∙∙ p ≡ q) ≡ ((p ∙ p) ∙ q ≡ q) movePathLem p q comm = cong (_≡ q) (doubleCompPath-elim' p q p ∙∙ cong (p ∙_) (comm q p) ∙∙ assoc _ _ _) movePathLem2 : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x) → (((p ∙ p) ∙ q) ∙ sym q ≡ q ∙ sym q) ≡ (p ∙ p ≡ refl) movePathLem2 p q = cong₂ _≡_ (sym (assoc (p ∙ p) q (sym q)) ∙∙ cong ((p ∙ p) ∙_) (rCancel q) ∙∙ sym (rUnit (p ∙ p))) (rCancel q) movePathIso : ∀ {ℓ} {A : Type ℓ} {x : A} (p q : x ≡ x) → isComm∙ (A , x) → Iso (p ∙∙ q ∙∙ p ≡ q) (p ∙ p ≡ refl) movePathIso {x = x} p q comm = compIso (pathToIso (movePathLem p q comm)) (compIso (helper (p ∙ p)) (pathToIso (movePathLem2 p q))) where helper : (p : x ≡ x) → Iso (p ∙ q ≡ q) ((p ∙ q) ∙ sym q ≡ q ∙ sym q) helper p = congIso (equivToIso (_ , compPathr-isEquiv (sym q))) ------ H¹(𝕂²) ≅ 0 -------------- H⁰-𝕂² : GroupIso (coHomGr 0 KleinBottle) IntGroup fun (fst H⁰-𝕂²) = sRec isSetInt λ f → f point inv (fst H⁰-𝕂²) x = ∣ (λ _ → x) ∣₂ rightInv (fst H⁰-𝕂²) _ = refl leftInv (fst H⁰-𝕂²) = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ f → cong ∣_∣₂ (funExt (λ {point → refl ; (line1 i) j → isSetInt (f point) (f point) refl (cong f line1) j i ; (line2 i) j → isSetInt (f point) (f point) refl (cong f line2) j i ; (square i j) z → helper f i j z})) where helper : (f : KleinBottle → Int) → Cube (λ j z → isSetInt (f point) (f point) refl (cong f line2) z j) (λ j z → isSetInt (f point) (f point) refl (cong f line2) z j) (λ i z → isSetInt (f point) (f point) refl (cong f line1) z (~ i)) (λ i z → isSetInt (f point) (f point) refl (cong f line1) z i) refl λ i j → f (square i j) helper f = isGroupoid→isGroupoid' (isOfHLevelSuc 2 isSetInt) _ _ _ _ _ _ snd H⁰-𝕂² = makeIsGroupHom (sElim2 (λ _ _ → isOfHLevelPath 2 isSetInt _ _) λ _ _ → refl) ------ H¹(𝕂¹) ≅ ℤ ------------ {- Step one : H¹(𝕂²) := ∥ 𝕂² → K₁ ∥₂ ≡ ∥ Σ[ x ∈ K₁ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] (p ∙∙ q ∙∙ p ≡ q) ∥₂ (characFunSpace𝕂²) ≡ ∥ Σ[ x ∈ K₁ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (movePathIso, using commutativity of ΩK₂) ≡ ∥ Σ[ x ∈ K₁ ] (x ≡ x) ∥₂ (p ∙ p ≡ refl forces p ≡ refl. Also, p ∙ p ≡ refl is an hProp) -} nilpotent→≡0 : (x : Int) → x +ℤ x ≡ 0 → x ≡ 0 nilpotent→≡0 (pos zero) p = refl nilpotent→≡0 (pos (suc n)) p = ⊥-rec (negsucNotpos _ _ (sym (cong (_- 1) (cong sucInt (sym (helper2 n)) ∙ p)))) where helper2 : (n : ℕ) → pos (suc n) +pos n ≡ pos (suc (n + n)) helper2 zero = refl helper2 (suc n) = cong sucInt (sym (sucInt+pos n (pos (suc n)))) ∙∙ cong (sucInt ∘ sucInt) (helper2 n) ∙∙ cong (pos ∘ suc ∘ suc) (sym (+-suc n n)) nilpotent→≡0 (negsuc n) p = ⊥-rec (negsucNotpos _ _ (helper2 n p)) where helper2 : (n : ℕ) → (negsuc n +negsuc n) ≡ pos 0 → negsuc n ≡ pos (suc n) helper2 n p = cong (negsuc n +ℤ_) (sym (helper3 n)) ∙ +-assoc (negsuc n) (negsuc n) (pos (suc n)) ∙∙ cong (_+ℤ (pos (suc n))) p ∙∙ cong sucInt (+-commℤ (pos 0) (pos n)) where helper3 : (n : ℕ) → negsuc n +pos (suc n) ≡ 0 helper3 zero = refl helper3 (suc n) = cong sucInt (sucInt+pos n (negsuc (suc n))) ∙ helper3 n nilpotent→≡refl : (x : coHomK 1) (p : x ≡ x) → p ∙ p ≡ refl → p ≡ refl nilpotent→≡refl = trElim (λ _ → isGroupoidΠ2 λ _ _ → isOfHLevelPlus {n = 1} 2 (isOfHLevelTrunc 3 _ _ _ _)) (toPropElim (λ _ → isPropΠ2 λ _ _ → isOfHLevelTrunc 3 _ _ _ _) λ p pId → sym (rightInv (Iso-Kn-ΩKn+1 0) p) ∙∙ cong (Kn→ΩKn+1 0) (nilpotent→≡0 (ΩKn+1→Kn 0 p) (sym (ΩKn+1→Kn-hom 0 p p) ∙ cong (ΩKn+1→Kn 0) pId)) ∙∙ Kn→ΩKn+10ₖ 0) Iso-H¹-𝕂²₁ : Iso (Σ[ x ∈ coHomK 1 ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl) (Σ[ x ∈ coHomK 1 ] x ≡ x) fun Iso-H¹-𝕂²₁ (x , (_ , (q , _))) = x , q inv Iso-H¹-𝕂²₁ (x , q) = x , (refl , (q , (sym (rUnit refl)))) rightInv Iso-H¹-𝕂²₁ _ = refl leftInv Iso-H¹-𝕂²₁ (x , (p , (q , P))) = ΣPathP (refl , (ΣPathP (sym (nilpotent→≡refl x p P) , toPathP (Σ≡Prop (λ _ → isOfHLevelTrunc 3 _ _ _ _) (transportRefl q))))) {- But this is precisely the type (minus set-truncation) of H¹(S¹) -} Iso-H¹-𝕂²₂ : Iso (Σ[ x ∈ coHomK 1 ] x ≡ x) (S¹ → coHomK 1) Iso-H¹-𝕂²₂ = invIso IsoFunSpaceS¹ H¹-𝕂²≅ℤ : GroupIso (coHomGr 1 KleinBottle) IntGroup H¹-𝕂²≅ℤ = compGroupIso theGroupIso (Hⁿ-Sⁿ≅ℤ 0) where theIso : Iso (coHom 1 KleinBottle) (coHom 1 S¹) theIso = setTruncIso ( compIso (characFunSpace𝕂² (coHomK 1)) (compIso (Σ-cong-iso-snd (λ x → Σ-cong-iso-snd λ p → Σ-cong-iso-snd λ q → movePathIso p q (isCommΩK-based 1 x))) (compIso Iso-H¹-𝕂²₁ Iso-H¹-𝕂²₂))) is-hom : IsGroupHom (coHomGr 1 KleinBottle .snd) (fun theIso) (coHomGr 1 S¹ .snd) is-hom = makeIsGroupHom (sElim2 (λ _ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ f g → cong ∣_∣₂ (funExt λ {base → refl ; (loop i) → refl})) theGroupIso : GroupIso (coHomGr 1 KleinBottle) (coHomGr 1 S¹) theGroupIso = (theIso , is-hom) ------ H²(𝕂²) ≅ ℤ/2ℤ (represented here by BoolGroup) ------- -- It suffices to show that H²(Klein) is equivalent to Bool as types {- Step one : H²(𝕂²) := ∥ 𝕂² → K₂ ∥₂ ≡ ∥ Σ[ x ∈ K₂ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] (p ∙∙ q ∙∙ p ≡ q) ∥₂ (characFunSpace𝕂²) ≡ ∥ Σ[ x ∈ K₂ ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (movePathIso, using commutativity of ΩK₂) ≡ ∥ Σ[ p ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ (connectedness of K₂) -} Iso-H²-𝕂²₁ : Iso ∥ Σ[ x ∈ coHomK 2 ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ ∥ Σ[ p ∈ 0ₖ 2 ≡ 0ₖ 2 ] p ∙ p ≡ refl ∥₂ fun Iso-H²-𝕂²₁ = sRec setTruncIsSet (uncurry (trElim (λ _ → is2GroupoidΠ λ _ → isOfHLevelPlus {n = 2} 2 setTruncIsSet) (sphereElim _ (λ _ → isSetΠ λ _ → setTruncIsSet) λ y → ∣ fst y , snd (snd y) ∣₂))) inv Iso-H²-𝕂²₁ = sMap λ p → (0ₖ 2) , ((fst p) , (refl , (snd p))) rightInv Iso-H²-𝕂²₁ = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ p → refl leftInv Iso-H²-𝕂²₁ = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) (uncurry (trElim (λ _ → is2GroupoidΠ λ _ → isOfHLevelPlus {n = 1} 3 (setTruncIsSet _ _)) (sphereToPropElim _ (λ _ → isPropΠ λ _ → setTruncIsSet _ _) λ {(p , (q , sq)) → trRec (setTruncIsSet _ _) (λ qid → cong ∣_∣₂ (ΣPathP (refl , (ΣPathP (refl , (ΣPathP (sym qid , refl))))))) (fun (PathIdTruncIso _) (isContr→isProp (isConnectedPathKn 1 (0ₖ 2) (0ₖ 2)) ∣ q ∣ ∣ refl ∣))}))) {- Step two : ∥ Σ[ p ∈ x ≡ x ] p ∙ p ≡ refl ∥₂ ≡ ∥ Σ[ x ∈ K₁ ] x + x ≡ 0 ∥₂ -} Iso-H²-𝕂²₂ : Iso ∥ (Σ[ p ∈ 0ₖ 2 ≡ 0ₖ 2 ] p ∙ p ≡ refl) ∥₂ ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ Iso-H²-𝕂²₂ = setTruncIso (Σ-cong-iso {B' = λ x → x +ₖ x ≡ 0ₖ 1} (invIso (Iso-Kn-ΩKn+1 1)) λ p → compIso (congIso (invIso (Iso-Kn-ΩKn+1 1))) (pathToIso λ i → ΩKn+1→Kn-hom 1 p p i ≡ 0ₖ 1)) {- Step three : ∥ Σ[ x ∈ K₁ ] x + x ≡ 0 ∥₂ ≡ Bool We begin by defining the a map Σ[ x ∈ K₁ ] x + x ≡ 0 → Bool. For a point (0 , p) we map it to true if winding(p) is even and false if winding(p) is odd. We also have to show that this map respects the loop -} ΣKₙNilpot→Bool : Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 → Bool ΣKₙNilpot→Bool = uncurry (trElim (λ _ → isGroupoidΠ λ _ → isOfHLevelSuc 2 isSetBool) λ {base p → isEven (ΩKn+1→Kn 0 p) ; (loop i) p → hcomp (λ k → λ { (i = i0) → respectsLoop p k ; (i = i1) → isEven (ΩKn+1→Kn 0 p)}) (isEven (ΩKn+1→Kn 0 (transp (λ j → ∣ (loop ∙ loop) (i ∨ j) ∣ ≡ 0ₖ 1) i p)))}) where isEven-2 : (x : Int) → isEven (-2 +ℤ x) ≡ isEven x isEven-2 (pos zero) = refl isEven-2 (pos (suc zero)) = refl isEven-2 (pos (suc (suc n))) = cong isEven (cong sucInt (sucInt+pos _ _) ∙∙ sucInt+pos _ _ ∙∙ +-commℤ 0 (pos n)) ∙ lossy n where lossy : (n : ℕ) → isEven (pos n) ≡ isEven (pos n) lossy n = refl isEven-2 (negsuc zero) = refl isEven-2 (negsuc (suc n)) = cong isEven (predInt+negsuc n _ ∙ +-commℤ -3 (negsuc n)) ∙ lossy2 n where lossy2 : (n : ℕ) → isEven (negsuc (suc (suc (suc n)))) ≡ isEven (pos n) lossy2 n = refl respectsLoop : (p : 0ₖ 1 ≡ 0ₖ 1) → isEven (ΩKn+1→Kn 0 (transport (λ i → ∣ (loop ∙ loop) i ∣ ≡ 0ₖ 1) p)) ≡ isEven (ΩKn+1→Kn 0 p) respectsLoop p = cong isEven (cong (ΩKn+1→Kn 0) (cong (transport (λ i → ∣ (loop ∙ loop) i ∣ ≡ 0ₖ 1)) (lUnit p))) ∙∙ cong isEven (cong (ΩKn+1→Kn 0) λ j → transp (λ i → ∣ (loop ∙ loop) (i ∨ j) ∣ ≡ 0ₖ 1) j ((λ i → ∣ (loop ∙ loop) (~ i ∧ j) ∣) ∙ p)) ∙∙ cong isEven (ΩKn+1→Kn-hom 0 (sym (cong ∣_∣ (loop ∙ loop))) p) ∙ isEven-2 (ΩKn+1→Kn 0 p) {- We show that for any x : Int we have ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ≡ ∣ (0ₖ 1 , refl) ∣₂ when x is even and ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ≡ ∣ (0ₖ 1 , cong ∣_∣ loop) ∣₂ when x is odd This is done by induction on x. For the inductive step we define a multiplication _*_ on ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ which is just ∣ (0 , p) ∣₂ * ∣ (0 , q) ∣₂ ≡ ∣ (0 , p ∙ q) ∣₂ when x is 0 -} private _*_ : ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ _*_ = sRec (isSetΠ (λ _ → setTruncIsSet)) λ a → sRec setTruncIsSet λ b → *' (fst a) (fst b) (snd a) (snd b) where *' : (x y : coHomK 1) (p : x +ₖ x ≡ 0ₖ 1) (q : y +ₖ y ≡ 0ₖ 1) → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ *' = trElim2 (λ _ _ → isGroupoidΠ2 λ _ _ → isOfHLevelSuc 2 setTruncIsSet) (wedgeconFun _ _ (λ _ _ → isSetΠ2 λ _ _ → setTruncIsSet) (λ x p q → ∣ ∣ x ∣ , cong₂ _+ₖ_ p q ∣₂) (λ y p q → ∣ ∣ y ∣ , sym (rUnitₖ 1 (∣ y ∣ +ₖ ∣ y ∣)) ∙ cong₂ _+ₖ_ p q ∣₂) (funExt λ p → funExt λ q → cong ∣_∣₂ (ΣPathP (refl , (sym (lUnit _)))))) *=∙ : (p q : 0ₖ 1 ≡ 0ₖ 1) → ∣ 0ₖ 1 , p ∣₂ * ∣ 0ₖ 1 , q ∣₂ ≡ ∣ 0ₖ 1 , p ∙ q ∣₂ *=∙ p q = cong ∣_∣₂ (ΣPathP (refl , sym (∙≡+₁ p q))) isEvenNegsuc : (n : ℕ) → isEven (pos (suc n)) ≡ true → isEven (negsuc n) ≡ true isEvenNegsuc zero p = ⊥-rec (true≢false (sym p)) isEvenNegsuc (suc n) p = p ¬isEvenNegSuc : (n : ℕ) → isEven (pos (suc n)) ≡ false → isEven (negsuc n) ≡ false ¬isEvenNegSuc zero p = refl ¬isEvenNegSuc (suc n) p = p evenCharac : (x : Int) → isEven x ≡ true → Path ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ∣ (0ₖ 1 , refl) ∣₂ evenCharac (pos zero) isisEven i = ∣ (0ₖ 1) , (rUnit refl (~ i)) ∣₂ evenCharac (pos (suc zero)) isisEven = ⊥-rec (true≢false (sym isisEven)) evenCharac (pos (suc (suc zero))) isisEven = cong ∣_∣₂ ((λ i → 0ₖ 1 , rUnit (cong ∣_∣ ((lUnit loop (~ i)) ∙ loop)) (~ i)) ∙ (ΣPathP (cong ∣_∣ loop , λ i j → ∣ (loop ∙ loop) (i ∨ j) ∣))) evenCharac (pos (suc (suc (suc n)))) isisEven = (λ i → ∣ 0ₖ 1 , Kn→ΩKn+1-hom 0 (pos (suc n)) 2 i ∣₂) ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (pos (suc n))) (Kn→ΩKn+1 0 (pos 2))) ∙∙ (cong₂ _*_ (evenCharac (pos (suc n)) isisEven) (evenCharac 2 refl)) evenCharac (negsuc zero) isisEven = ⊥-rec (true≢false (sym isisEven)) evenCharac (negsuc (suc zero)) isisEven = cong ∣_∣₂ ((λ i → 0ₖ 1 , λ i₁ → hfill (doubleComp-faces (λ i₂ → ∣ base ∣) (λ _ → ∣ base ∣) i₁) (inS ∣ compPath≡compPath' (sym loop) (sym loop) i i₁ ∣) (~ i)) ∙ ΣPathP ((cong ∣_∣ (sym loop)) , λ i j → ∣ (sym loop ∙' sym loop) (i ∨ j) ∣)) evenCharac (negsuc (suc (suc n))) isisEven = cong ∣_∣₂ (λ i → 0ₖ 1 , Kn→ΩKn+1-hom 0 (negsuc n) -2 i) ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (negsuc n)) (Kn→ΩKn+1 0 -2)) ∙∙ cong₂ _*_ (evenCharac (negsuc n) (isEvenNegsuc n isisEven)) (evenCharac -2 refl) oddCharac : (x : Int) → isEven x ≡ false → Path ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ ∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂ ∣ (0ₖ 1 , cong ∣_∣ loop) ∣₂ oddCharac (pos zero) isOdd = ⊥-rec (true≢false isOdd) oddCharac (pos (suc zero)) isOdd i = ∣ (0ₖ 1 , λ j → hfill (doubleComp-faces (λ i₂ → ∣ base ∣) (λ _ → ∣ base ∣) j) (inS ∣ lUnit loop (~ i) j ∣) (~ i)) ∣₂ oddCharac (pos (suc (suc n))) isOdd = (λ i → ∣ 0ₖ 1 , Kn→ΩKn+1-hom 0 (pos n) 2 i ∣₂) ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (pos n)) (Kn→ΩKn+1 0 2)) ∙∙ cong₂ _*_ (oddCharac (pos n) isOdd) (evenCharac 2 refl) oddCharac (negsuc zero) isOdd = cong ∣_∣₂ ((λ i → 0ₖ 1 , rUnit (sym (cong ∣_∣ loop)) (~ i)) ∙ ΣPathP (cong ∣_∣ (sym loop) , λ i j → ∣ hcomp (λ k → λ { (i = i0) → loop (~ j ∧ k) ; (i = i1) → loop j ; (j = i1) → base}) (loop (j ∨ ~ i)) ∣)) oddCharac (negsuc (suc zero)) isOdd = ⊥-rec (true≢false isOdd) oddCharac (negsuc (suc (suc n))) isOdd = cong ∣_∣₂ (λ i → 0ₖ 1 , Kn→ΩKn+1-hom 0 (negsuc n) -2 i) ∙∙ sym (*=∙ (Kn→ΩKn+1 0 (negsuc n)) (Kn→ΩKn+1 0 -2)) ∙∙ cong₂ _*_ (oddCharac (negsuc n) (¬isEvenNegSuc n isOdd)) (evenCharac (negsuc 1) refl) {- We now have all we need to establish the Iso -} Bool→ΣKₙNilpot : Bool → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ Bool→ΣKₙNilpot false = ∣ 0ₖ 1 , cong ∣_∣ loop ∣₂ Bool→ΣKₙNilpot true = ∣ 0ₖ 1 , refl ∣₂ testIso : Iso ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ Bool fun testIso = sRec isSetBool ΣKₙNilpot→Bool inv testIso = Bool→ΣKₙNilpot rightInv testIso false = refl rightInv testIso true = refl leftInv testIso = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) (uncurry (trElim (λ _ → isGroupoidΠ λ _ → isOfHLevelPlus {n = 1} 2 (setTruncIsSet _ _)) (toPropElim (λ _ → isPropΠ (λ _ → setTruncIsSet _ _)) (λ p → path p (isEven (ΩKn+1→Kn 0 p)) refl)))) where path : (p : 0ₖ 1 ≡ 0ₖ 1) (b : Bool) → (isEven (ΩKn+1→Kn 0 p) ≡ b) → Bool→ΣKₙNilpot (ΣKₙNilpot→Bool (∣ base ∣ , p)) ≡ ∣ ∣ base ∣ , p ∣₂ path p false q = (cong Bool→ΣKₙNilpot q) ∙∙ sym (oddCharac (ΩKn+1→Kn 0 p) q) ∙∙ cong ∣_∣₂ λ i → 0ₖ 1 , rightInv (Iso-Kn-ΩKn+1 0) p i path p true q = cong Bool→ΣKₙNilpot q ∙∙ sym (evenCharac (ΩKn+1→Kn 0 p) q) ∙∙ cong ∣_∣₂ λ i → 0ₖ 1 , rightInv (Iso-Kn-ΩKn+1 0) p i H²-𝕂²≅Bool : GroupIso (coHomGr 2 KleinBottle) BoolGroup H²-𝕂²≅Bool = invGroupIso (≅Bool theIso) where theIso : Iso _ _ theIso = compIso (setTruncIso (compIso (characFunSpace𝕂² (coHomK 2)) (Σ-cong-iso-snd λ x → Σ-cong-iso-snd λ p → Σ-cong-iso-snd λ q → (movePathIso p q (isCommΩK-based 2 x))))) (compIso Iso-H²-𝕂²₁ (compIso Iso-H²-𝕂²₂ testIso)) ------ Hⁿ(𝕂²) ≅ 0 , n ≥ 3 ------ isContrHⁿ-𝕂² : (n : ℕ) → isContr (coHom (3 + n) KleinBottle) isContrHⁿ-𝕂² n = isOfHLevelRetractFromIso 0 (setTruncIso (characFunSpace𝕂² (coHomK _))) isContrΣ-help where helper : (x : coHomK (3 + n))(p : x ≡ x) → (refl ≡ p) → (q : x ≡ x) → (refl ≡ q) → (P : p ∙∙ q ∙∙ p ≡ q) → Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂ ∣ x , p , q , P ∣₂ ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂ helper = trElim (λ _ → isProp→isOfHLevelSuc (4 + n) (isPropΠ4 λ _ _ _ _ → isPropΠ λ _ → setTruncIsSet _ _)) (sphereToPropElim _ (λ _ → isPropΠ4 λ _ _ _ _ → isPropΠ λ _ → setTruncIsSet _ _) λ p → J (λ p _ → (q : 0ₖ _ ≡ 0ₖ _) → (refl ≡ q) → (P : p ∙∙ q ∙∙ p ≡ q) → Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂ ∣ 0ₖ _ , p , q , P ∣₂ ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂) λ q → J (λ q _ → (P : refl ∙∙ q ∙∙ refl ≡ q) → Path ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂ ∣ 0ₖ _ , refl , q , P ∣₂ ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂) λ P → trRec (isProp→isOfHLevelSuc n (setTruncIsSet _ _)) (λ P≡rUnitrefl i → ∣ 0ₖ (3 + n) , refl , refl , P≡rUnitrefl i ∣₂) (fun (PathIdTruncIso _) (isContr→isProp (isConnectedPath _ (isConnectedPathKn (2 + n) _ _) (refl ∙∙ refl ∙∙ refl) refl) ∣ P ∣ ∣ sym (rUnit refl) ∣))) isContrΣ-help : isContr ∥ (Σ[ x ∈ coHomK (3 + n) ] Σ[ p ∈ x ≡ x ] Σ[ q ∈ x ≡ x ] p ∙∙ q ∙∙ p ≡ q) ∥₂ fst isContrΣ-help = ∣ 0ₖ _ , refl , refl , sym (rUnit refl) ∣₂ snd isContrΣ-help = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ {(x , p , q , P) → trRec (isProp→isOfHLevelSuc (suc n) (setTruncIsSet _ _)) (λ pId → trRec (isProp→isOfHLevelSuc (suc n) (setTruncIsSet _ _)) (λ qId → sym (helper x p pId q qId P)) (fun (PathIdTruncIso (2 + n)) (isContr→isProp (isConnectedPathKn (2 + n) _ _) ∣ refl ∣ ∣ q ∣))) (fun (PathIdTruncIso (2 + n)) (isContr→isProp (isConnectedPathKn (2 + n) _ _) ∣ refl ∣ ∣ p ∣))} Hⁿ⁺³-𝕂²≅0 : (n : ℕ) → GroupIso (coHomGr (3 + n) KleinBottle) UnitGroup Hⁿ⁺³-𝕂²≅0 n = contrGroupIsoUnit (isContrHⁿ-𝕂² n)
46.949451
141
0.50529
21a3fb9ca3ceec4852c9c84f0a3fad4441ee1bd4
938
agda
Agda
src/Control/WellFounded.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
111
2015-01-05T11:28:15.000Z
2022-02-12T23:29:26.000Z
src/Control/WellFounded.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
59
2016-02-09T05:36:44.000Z
2022-01-14T07:32:36.000Z
src/Control/WellFounded.agda
t-more/agda-prelude
da4fca7744d317b8843f2bc80a923972f65548d3
[ "MIT" ]
24
2015-03-12T18:03:45.000Z
2021-04-22T06:10:41.000Z
module Control.WellFounded where open import Prelude open import Prelude.Nat.Properties using (suc-inj) data Acc {a b} {A : Set a} (_<_ : A → A → Set b) (x : A) : Set (a ⊔ b) where acc : (∀ y → y < x → Acc _<_ y) → Acc _<_ x -- LessNat is well-founded -- private wfNatSlow : (n : Nat) → Acc _<_ n wfNatSlow′ : (n j y : Nat) → n ≡ suc (j + y) → Acc _<_ y wfNatSlow′ (suc n) zero .n refl = wfNatSlow n wfNatSlow′ (suc n) (suc j) y eq = wfNatSlow′ n j y (suc-inj eq) wfNatSlow′ zero zero y () wfNatSlow′ zero (suc j) y () wfNatSlow n = acc λ { y (diff j eq) → wfNatSlow′ n j y eq } -- Need to match on n to avoid unfolding on neutral argument! wfNatFast : {k : Nat} → (n : Nat) → Acc _<_ n wfNatFast {zero} n = wfNatSlow n wfNatFast {suc k} zero = wfNatSlow zero wfNatFast {suc k} (suc n) = acc λ m _ → wfNatFast {k} m wfNat : (n : Nat) → Acc _<_ n wfNat n = wfNatFast {1000000000} n
31.266667
76
0.591684
1b85f19a4da045bd7fa0949cf4dd114973be94b3
741
agda
Agda
test/Fail/Issue2650.agda
asr/eagda
7220bebfe9f64297880ecec40314c0090018fdd0
[ "BSD-3-Clause" ]
1
2016-03-17T01:45:59.000Z
2016-03-17T01:45:59.000Z
test/Fail/Issue2650.agda
asr/eagda
7220bebfe9f64297880ecec40314c0090018fdd0
[ "BSD-3-Clause" ]
null
null
null
test/Fail/Issue2650.agda
asr/eagda
7220bebfe9f64297880ecec40314c0090018fdd0
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
{-# OPTIONS --cubical #-} module _ where module _ where open import Agda.Primitive.Cubical public postulate Path' : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ PathP : ∀ {ℓ} (A : I → Set ℓ) → A i0 → A i1 → Set ℓ {-# BUILTIN PATH Path' #-} {-# BUILTIN PATHP PathP #-} infix 4 _≡_ _≡_ : ∀ {ℓ} {A : Set ℓ} → A → A → Set ℓ _≡_ {A = A} = PathP (λ _ → A) Path = _≡_ refl : ∀ {a} {A : Set a} {x : A} → x ≡ x refl {x = x} = \ _ → x -- Here there's no solution for H, pattern unification will try -- H := \ i -> b, but the equality constraints from -- H : Path b a should rule out that assignment. testPath : ∀ {A : Set} {b a : A} (let H : Path b a; H = _) → ∀ i → H i ≡ b testPath i = refl
25.551724
74
0.504723
06711c2c19428d1a213c0e0a220c8029f022c10f
1,723
agda
Agda
src/paper.agda
wenkokke/msla2014
b880cf25ed8e81b9a965ea9aad18377008d68a9f
[ "MIT" ]
5
2018-11-17T23:04:39.000Z
2020-10-29T09:07:45.000Z
src/paper.agda
wenkokke/msla2014
b880cf25ed8e81b9a965ea9aad18377008d68a9f
[ "MIT" ]
null
null
null
src/paper.agda
wenkokke/msla2014
b880cf25ed8e81b9a965ea9aad18377008d68a9f
[ "MIT" ]
null
null
null
module paper where open import Data.Bool using (Bool; not; _∨_; _∧_) open import Data.Nat using (ℕ) open import Data.Fin using (Fin; suc; zero) open import Data.List using (List; _++_) renaming (_∷_ to _,_; [] to ∅) open import Data.Product using (_×_; _,_) open import Relation.Binary.PropositionalEquality using (_≡_; refl) postulate Entity : Set _⊃_ : Bool → Bool → Bool FORALL : (Entity → Bool) → Bool EXISTS : (Entity → Bool) → Bool PERSON : Entity → Bool FIND : Entity → Entity → Bool UNICORN : Entity → Bool data U : Set where S N NP : U ⟦_⟧ᵁ : U → Set ⟦ S ⟧ᵁ = Bool ⟦ N ⟧ᵁ = Entity → Bool ⟦ NP ⟧ᵁ = Entity import IntuitionisticLogic U ⟦_⟧ᵁ as IL import LinearLogic U S ⟦_⟧ᵁ as LP import LambekGrishinCalculus U S ⟦_⟧ᵁ as LG open LG open IL.Explicit using (Ctxt; _,_; ∅) open IL.Explicit.Reify TypeReify everyone : ⟦ (el NP + ⇐ el N +) ⊗ el N + ⟧ everyone = ( (λ{ (A , B) → FORALL (λ x → B x ⊃ A x) }) , PERSON ) finds : ⟦ (el NP + ⇒ el S -) ⇐ el NP + ⟧ finds = λ{ ((x , k) , y) → k (FIND y x) } some : ⟦ el NP + ⇐ el N + ⟧ some = λ{ (A , B) → EXISTS (λ x → A x ∧ B x) } unicorn : ⟦ el N + ⟧ unicorn = UNICORN sent : · (el NP + ⇐ el N +) ⊗ el N + -- everyone · ⊗ (· (el NP + ⇒ el S -) ⇐ el NP + -- finds · ⊗ (· el NP + ⇐ el N + -- some · ⊗ · el N + · -- unicorn )) ⊢[ el S - ] sent = μ (res₃ (⊗L (res₃ (μ̃* (⇐L ( μ̃ (res₄ (res₁ (res₁ (res₃ (μ̃* (⇐L ( μ̃ (res₂ (res₃ (μ̃* (⇐L (⇒L var covar) var))))) var))))))) var))))) test : ([ sent ] (everyone , finds , some , unicorn , ∅)) ≡ (λ k → FORALL (λ x₁ → PERSON x₁ ⊃ EXISTS (λ x₂ → k (FIND x₂ x₁) ∧ UNICORN x₂))) test = refl
29.706897
86
0.526988
fdd1b3fa6d18d8a2efb8b3b4bbad813d867c9d96
1,434
agda
Agda
Cubical/Relation/Nullary/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Relation/Nullary/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Relation/Nullary/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --safe #-} module Cubical.Relation.Nullary.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Functions.Fixpoint open import Cubical.Data.Empty as ⊥ open import Cubical.HITs.PropositionalTruncation.Base private variable ℓ : Level A : Type ℓ -- Negation infix 3 ¬_ ¬_ : Type ℓ → Type ℓ ¬ A = A → ⊥ -- Decidable types (inspired by standard library) data Dec (P : Type ℓ) : Type ℓ where yes : ( p : P) → Dec P no : (¬p : ¬ P) → Dec P NonEmpty : Type ℓ → Type ℓ NonEmpty A = ¬ ¬ A Stable : Type ℓ → Type ℓ Stable A = NonEmpty A → A -- reexport propositional truncation for uniformity open Cubical.HITs.PropositionalTruncation.Base using (∥_∥) public SplitSupport : Type ℓ → Type ℓ SplitSupport A = ∥ A ∥ → A Collapsible : Type ℓ → Type ℓ Collapsible A = Σ[ f ∈ (A → A) ] 2-Constant f Populated ⟪_⟫ : Type ℓ → Type ℓ Populated A = (f : Collapsible A) → Fixpoint (f .fst) ⟪_⟫ = Populated PStable : Type ℓ → Type ℓ PStable A = ⟪ A ⟫ → A onAllPaths : (Type ℓ → Type ℓ) → Type ℓ → Type ℓ onAllPaths S A = (x y : A) → S (x ≡ y) Separated : Type ℓ → Type ℓ Separated = onAllPaths Stable HSeparated : Type ℓ → Type ℓ HSeparated = onAllPaths SplitSupport Collapsible≡ : Type ℓ → Type ℓ Collapsible≡ = onAllPaths Collapsible PStable≡ : Type ℓ → Type ℓ PStable≡ = onAllPaths PStable Discrete : Type ℓ → Type ℓ Discrete = onAllPaths Dec
21.402985
53
0.679916
a09f28bf24274dc3a3e3360e37746058d97fee64
654
agda
Agda
Cubical/Data/DiffInt/Base.agda
mchristianl/cubical
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
[ "MIT" ]
null
null
null
Cubical/Data/DiffInt/Base.agda
mchristianl/cubical
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
[ "MIT" ]
null
null
null
Cubical/Data/DiffInt/Base.agda
mchristianl/cubical
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Data.DiffInt.Base where open import Cubical.Foundations.Prelude open import Cubical.HITs.SetQuotients.Base open import Cubical.Data.Sigma open import Cubical.Data.Nat rel : (ℕ × ℕ) → (ℕ × ℕ) → Type₀ rel (a₀ , b₀) (a₁ , b₁) = x ≡ y where x = a₀ + b₁ y = a₁ + b₀ ℤ = (ℕ × ℕ) / rel open import Cubical.Data.Nat.Literals public instance fromNatDiffInt : HasFromNat ℤ fromNatDiffInt = record { Constraint = λ _ → Unit ; fromNat = λ n → [ n , 0 ] } instance fromNegDiffInt : HasFromNeg ℤ fromNegDiffInt = record { Constraint = λ _ → Unit ; fromNeg = λ n → [ 0 , n ] }
23.357143
81
0.657492
430a8b1e1ba17530fd658d47bb058d9e5e96723f
12,879
agda
Agda
agda/calculus/properties.agda
florence/esterel-calculus
4340bef3f8df42ab8167735d35a4cf56243a45cd
[ "MIT" ]
3
2020-04-16T10:58:53.000Z
2020-07-01T03:59:31.000Z
agda/calculus/properties.agda
florence/esterel-calculus
4340bef3f8df42ab8167735d35a4cf56243a45cd
[ "MIT" ]
null
null
null
agda/calculus/properties.agda
florence/esterel-calculus
4340bef3f8df42ab8167735d35a4cf56243a45cd
[ "MIT" ]
1
2020-04-15T20:02:49.000Z
2020-04-15T20:02:49.000Z
module calculus.properties where open import utility open import Esterel.Lang open import Esterel.Lang.Binding open import Esterel.Lang.Properties open import Esterel.Lang.CanFunction using (Canθₛ ; Canθₛₕ ; [S]-env) open import Esterel.Environment as Env using (Env ; Θ ; _←_ ; sig ; []env ; module SigMap ; module ShrMap ; module VarMap) open import Esterel.Context using (EvaluationContext ; EvaluationContext1 ; _⟦_⟧e ; _≐_⟦_⟧e ; Context ; Context1 ; _⟦_⟧c ; _≐_⟦_⟧c ; dchole) open import Esterel.Variable.Signal as Signal using (Signal) open import Esterel.Variable.Shared as SharedVar using (SharedVar) open import Esterel.Variable.Sequential as SeqVar using (SeqVar) open import Esterel.Context.Properties open import Relation.Nullary using (¬_) open import Relation.Binary.PropositionalEquality using (_≡_ ; refl) open import Data.Empty using (⊥ ; ⊥-elim) import Data.FiniteMap open import Data.List using (List ; _∷_ ; [] ; _++_) open import Data.List.All as All using (All ; _∷_ ; []) open import Data.Nat using (ℕ ; zero ; suc ; _+_) open import Data.Product using (Σ-syntax ; Σ ; _,_ ; proj₁ ; proj₂ ; _×_ ; _,′_ ; ∃) open import Data.Sum using (_⊎_ ; inj₁ ; inj₂) open import Relation.Binary.PropositionalEquality open import sn-calculus open import calculus open import par-swap open import par-swap.union-properties using (∥R∪sn≡ₑ-consistent) open import binding-preserve using (CB-preservation*) ⟶*-concat : ∀ {p q r} -> p ⟶* q -> q ⟶* r -> p ⟶* r ⟶*-concat [refl] q⟶*r = q⟶*r ⟶*-concat ([step] p⟶q p⟶*q) q⟶*r = [step] p⟶q (⟶*-concat p⟶*q q⟶*r) ⟶*->∥R*∪sn⟶* : ∀ {p q} -> p ⟶* q -> p ∥R*∪sn⟶* q ⟶*->∥R*∪sn⟶* = thm where thm : ∀ {p q} -> p ⟶* q -> p ∥R*∪sn⟶* q thm [refl] = ∪refl thm ([step] ([context] C dc p⟶₁p') p'⟶*q) with thm p'⟶*q thm ([step] ([context] C dc [par-swap]) p'⟶*q) | R = ∪∥R* (∥Rn (∥Rstep{C} dc) ∥R0) R thm ([step] ([context] C dc ([par-nothing] doneq)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rpar-done-right hnothin doneq)) rrefl) R thm ([step] ([context] C dc ([par-1exit] n pausedq)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rpar-done-right (hexit n) (dpaused pausedq))) rrefl) R thm ([step] ([context] C dc ([par-2exit] n m)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rpar-done-right (hexit n) (dhalted (hexit m)))) rrefl) R thm ([step] ([context] C dc ([is-present] S S∈ θ[S]≡present de)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (ris-present{S = S} S∈ θ[S]≡present de)) rrefl) R thm ([step] ([context] C dc ([is-absent] S S∈ θ[S]≡absent de)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (ris-absent{S = S} S∈ θ[S]≡absent de)) rrefl) R thm ([step] ([context] C dc ([emit] S∈ ¬S≡a de)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (remit S∈ ¬S≡a de)) rrefl) R thm ([step] ([context] C dc [loop-unroll]) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc rloop-unroll) rrefl) R thm ([step] ([context] C dc [seq-done]) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc rseq-done) rrefl) R thm ([step] ([context] C dc [seq-exit]) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc rseq-exit) rrefl) R thm ([step] ([context] C dc [loopˢ-exit]) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc rloopˢ-exit) rrefl) R thm ([step] ([context] C dc ([suspend-done] haltedp)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rsuspend-done haltedp)) rrefl) R thm ([step] ([context] C dc ([trap-done] haltedp)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rtrap-done haltedp)) rrefl) R thm ([step] ([context] C dc [raise-signal]) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc rraise-signal) rrefl) R thm ([step] ([context] C dc ([raise-shared] all-readyeθ de)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rraise-shared all-readyeθ de)) rrefl) R thm ([step] ([context] C dc ([set-shared-value-old] e' s∈ θ[s]≡old de)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rset-shared-value-old e' s∈ θ[s]≡old de)) rrefl) R thm ([step] ([context] C dc ([set-shared-value-new] e' s∈ θ[s]≡n de)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rset-shared-value-new e' s∈ θ[s]≡n de)) rrefl) R thm ([step] ([context] C dc ([raise-var] all-readyeθ de)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rraise-var all-readyeθ de)) rrefl) R thm ([step] ([context] C dc ([set-var] x∈ all-readyeθ de)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rset-var x∈ all-readyeθ de)) rrefl) R thm ([step] ([context] C dc ([if-false] x∈ θ[x]≡z de)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rif-false x∈ θ[x]≡z de)) rrefl) R thm ([step] ([context] C dc ([if-true] x∈ θ[x]≡s de)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rif-true x∈ θ[x]≡s de)) rrefl) R thm ([step] ([context] C dc ([absence] S S∈ θ[S]≡unknown S∉Canθₛ)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rabsence{S = S} S∈ θ[S]≡unknown S∉Canθₛ)) rrefl) R thm ([step] ([context] C dc ([readyness] s s∈ θ[s]≡old⊎θ[s]≡new s∉Canθₛₕ)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rreadyness{s = s} s∈ θ[s]≡old⊎θ[s]≡new s∉Canθₛₕ)) rrefl) R thm ([step] ([context] C dc ([merge] de)) p'⟶*q) | R = ∪sn⟶* (rstep (rcontext C dc (rmerge de)) rrefl) R ∥R*∪sn⟶*->⟶* : ∀ {p q} -> p ∥R*∪sn⟶* q -> p ⟶* q ∥R*∪sn⟶*->⟶* = thm where p∥R*q->p⟶*q : ∀ {p q} -> p ∥R* q -> p ⟶* q p∥R*q->p⟶*q ∥R0 = [refl] p∥R*q->p⟶*q (∥Rn (∥Rstep d≐C⟦p∥q⟧c) p∥R*q) = [step] ([context] _ d≐C⟦p∥q⟧c [par-swap]) (p∥R*q->p⟶*q p∥R*q) sn* : ∀ {p q} -> p sn⟶* q -> p ⟶* q sn* rrefl = [refl] sn* (rstep (rcontext C dc step) more) with sn* more sn* (rstep (rcontext C dc (rpar-done-right hnothin q')) _) | R = [step] ([context] C dc ([par-nothing] q')) R sn* (rstep (rcontext C dc (rpar-done-right (hexit n) (dhalted hnothin))) _) | R = [step] ([context] C dc [par-swap]) ([step] ([context] C Crefl ([par-nothing] (dhalted (hexit n)))) R) sn* (rstep (rcontext C dc (rpar-done-right (hexit n) (dhalted (hexit m)))) _) | R = [step] ([context] C dc ([par-2exit] n m)) R sn* (rstep (rcontext C dc (rpar-done-right (hexit n) (dpaused p/paused))) _) | R = [step] ([context] C dc ([par-1exit] n p/paused)) R sn* (rstep (rcontext C dc (rpar-done-left (dhalted hnothin) q')) more) | R = [step] ([context] C dc ([par-nothing] (dhalted q'))) R sn* (rstep (rcontext C dc (rpar-done-left (dhalted (hexit n)) hnothin)) more) | R = [step] ([context] C dc [par-swap]) ([step] ([context] C Crefl ([par-nothing] (dhalted (hexit n)))) R) sn* (rstep (rcontext C dc (rpar-done-left (dhalted (hexit n)) (hexit m))) more) | R = [step] ([context] C dc ([par-2exit] n m)) R sn* (rstep (rcontext C dc (rpar-done-left (dpaused p/paused) hnothin)) more) | R = [step] ([context] C dc [par-swap]) ([step] ([context] C Crefl ([par-nothing] (dpaused p/paused))) R) sn* (rstep (rcontext C dc (rpar-done-left (dpaused p/paused) (hexit n))) more) | R = [step] ([context] C dc [par-swap]) ([step] ([context] C Crefl ([par-1exit] n p/paused)) R) sn* (rstep (rcontext C dc (ris-present{S = S} S∈ x x₁)) _) | R = [step] ([context] C dc ([is-present] S S∈ x x₁)) R sn* (rstep (rcontext C dc (ris-absent{S = S} S∈ x x₁)) _) | R = [step] ([context] C dc ([is-absent] S S∈ x x₁)) R sn* (rstep (rcontext C dc (remit S∈ ¬S≡a x)) _) | R = [step] ([context] C dc ([emit] S∈ ¬S≡a x)) R sn* (rstep (rcontext C dc rloop-unroll) _) | R = [step] ([context] C dc [loop-unroll]) R sn* (rstep (rcontext C dc rseq-done) _) | R = [step] ([context] C dc [seq-done]) R sn* (rstep (rcontext C dc rseq-exit) _) | R = [step] ([context] C dc [seq-exit]) R sn* (rstep (rcontext C dc rloopˢ-exit) _) | R = [step] ([context] C dc [loopˢ-exit]) R sn* (rstep (rcontext C dc (rsuspend-done x)) _) | R = [step] ([context] C dc ([suspend-done] x)) R sn* (rstep (rcontext C dc (rtrap-done p')) _) | R = [step] ([context] C dc ([trap-done] p')) R sn* (rstep (rcontext C dc rraise-signal) _) | R = [step] ([context] C dc [raise-signal]) R sn* (rstep (rcontext C dc (rraise-shared e' x)) _) | R = [step] ([context] C dc ([raise-shared] e' x)) R sn* (rstep (rcontext C dc (rset-shared-value-old e' s∈ x x₁)) _) | R = [step] ([context] C dc ([set-shared-value-old] e' s∈ x x₁)) R sn* (rstep (rcontext C dc (rset-shared-value-new e' s∈ x x₁)) _) | R = [step] ([context] C dc ([set-shared-value-new] e' s∈ x x₁)) R sn* (rstep (rcontext C dc (rraise-var e' x₁)) _) | R = [step] ([context] C dc ([raise-var] e' x₁)) R sn* (rstep (rcontext C dc (rset-var x∈ e' x₁)) _) | R = [step] ([context] C dc ([set-var] x∈ e' x₁)) R sn* (rstep (rcontext C dc (rif-false x∈ x₁ x₂)) _) | R = [step] ([context] C dc ([if-false] x∈ x₁ x₂)) R sn* (rstep (rcontext C dc (rif-true x∈ x₁ x₂)) _) | R = [step] ([context] C dc ([if-true] x∈ x₁ x₂)) R sn* (rstep (rcontext C dc (rabsence{S = S} S∈ x x₁)) _) | R = [step] ([context] C dc ([absence] S S∈ x x₁)) R sn* (rstep (rcontext C dc (rreadyness{s = s} s∈ x x₁)) _) | R = [step] ([context] C dc ([readyness] s s∈ x x₁)) R sn* (rstep (rcontext C dc (rmerge x)) _) | R = [step] ([context] C dc ([merge] x)) R thm : ∀ {p q} -> p ∥R*∪sn⟶* q -> p ⟶* q thm (∪∥R* p∥R*q p∥R*∪sn⟶*q) = ⟶*-concat (p∥R*q->p⟶*q p∥R*q) (thm p∥R*∪sn⟶*q) thm (∪sn⟶* psn⟶*q p∥R*∪sn⟶*q) = ⟶*-concat (sn* psn⟶*q) (thm p∥R*∪sn⟶*q) thm ∪refl = [refl] ≡ₑ-to-∥R∪sn≡ₑ : ∀ {p q} -> p ≡ₑ q # [] -> p ∥R∪sn≡ₑ q ≡ₑ-to-∥R∪sn≡ₑ = λ p≡ₑq#[] → thm Crefl Crefl p≡ₑq#[] where lift-∥R* : ∀ {p q} -> p ∥R* q -> p ∥R∪sn≡ₑ q lift-∥R* ∥R0 = ∪ref lift-∥R* (∥Rn p∥Rr r⟶q) = ∪trn (∪stp∥ p∥Rr) (lift-∥R* r⟶q) lift-sn⟶* : ∀ {p q} -> p sn⟶* q -> p ∥R∪sn≡ₑ q lift-sn⟶* rrefl = ∪ref lift-sn⟶* (rstep psn⟶r r⟶q) = ∪trn (∪stpsn psn⟶r) (lift-sn⟶* r⟶q) lift-∪ : ∀ {p q} -> p ∥R*∪sn⟶* q -> p ∥R∪sn≡ₑ q lift-∪ (∪∥R* p∥R*r r⟶*q) = ∪trn (lift-∥R* p∥R*r) (lift-∪ r⟶*q) lift-∪ (∪sn⟶* psn⟶*r r⟶*q) = ∪trn (lift-sn⟶* psn⟶*r) (lift-∪ r⟶*q) lift-∪ ∪refl = ∪ref thm : ∀ {p′ p q′ q C} -> (p′C : p′ ≐ C ⟦ p ⟧c) -> (q′C : q′ ≐ C ⟦ q ⟧c) -> p ≡ₑ q # C -> p′ ∥R∪sn≡ₑ q′ thm p′C q′C ≡ₑrefl rewrite sym (unplugc p′C) | sym (unplugc q′C) = ∪ref thm p′C q′C (≡ₑtran p≡ₑr r≡ₑq) with thm p′C Crefl p≡ₑr ... | p′∪≡r′ with thm Crefl q′C r≡ₑq ... | r′∪≡q′ = ∪trn p′∪≡r′ r′∪≡q′ thm p′C q′C (≡ₑsymm CBq p≡ₑq) with thm q′C p′C p≡ₑq ... | q∪≡p rewrite sym (unplugc q′C) = ∪sym q∪≡p CBq thm p′C q′C (≡ₑctxt pC′ qC′ C′⟦p₂⟧≡ₑC′⟦q₂⟧) = thm (C++ p′C pC′) (C++ q′C qC′) C′⟦p₂⟧≡ₑC′⟦q₂⟧ thm p′C q′C (≡ₑstep p⟶₁q) with ⟶*->∥R*∪sn⟶* ([step] ([context] _ p′C p⟶₁q) [refl]) ... | p′∥R*∪sn⟶*q′ rewrite sym (unplugc q′C) = lift-∪ p′∥R*∪sn⟶*q′ ∥R∪sn≡-to-≡ₑ : ∀ {p q} -> p ∥R∪sn≡ₑ q -> p ≡ₑ q # [] ∥R∪sn≡-to-≡ₑ = thm where lift⟶* : ∀ {p q} -> p ⟶* q -> p ≡ₑ q # [] lift⟶* [refl] = ≡ₑrefl lift⟶* ([step] ([context] C dc p⟶₁p') r⟶*q) = ≡ₑtran (≡ₑctxt dc Crefl (≡ₑstep p⟶₁p')) (lift⟶* r⟶*q) thm : ∀ {p q} -> p ∥R∪sn≡ₑ q -> p ≡ₑ q # [] thm (∪stpsn psn⟶q) = lift⟶* (∥R*∪sn⟶*->⟶* (∪sn⟶* (rstep psn⟶q rrefl) ∪refl)) thm (∪stp∥ (∥Rstep d≐C⟦p∥q⟧c)) = ≡ₑctxt d≐C⟦p∥q⟧c Crefl (≡ₑstep [par-swap]) thm (∪sym q∪≡p CBq) with thm q∪≡p ... | q≡ₑp = ≡ₑsymm CBq q≡ₑp thm ∪ref = ≡ₑrefl thm (∪trn p∪≡r r∪≡q) with thm p∪≡r ... | p≡ₑr with thm r∪≡q ... | r≡ₑq = ≡ₑtran p≡ₑr r≡ₑq ≡ₑ-consistent : ∀{p q BV FV} → CorrectBinding p BV FV → p ≡ₑ q # [] → Σ[ r ∈ Term ] p ⟶* r × q ⟶* r ≡ₑ-consistent CB eq with ∥R∪sn≡ₑ-consistent CB (≡ₑ-to-∥R∪sn≡ₑ eq) ≡ₑ-consistent CB₁ eq | r , p∥⟶*r , q∥⟶*r = r , (∥R*∪sn⟶*->⟶* p∥⟶*r) , (∥R*∪sn⟶*->⟶* q∥⟶*r) ∥R*-preserve-CB : ∀ p q → (⊢C⟦p⟧ : CB p) → (p∥R*q : p ∥R* q) → CB q ∥R*-preserve-CB p .p ⊢C⟦p⟧ ∥R0 = ⊢C⟦p⟧ ∥R*-preserve-CB p q₁ ⊢C⟦p⟧ (∥Rn (∥Rstep d≐C⟦p∥q⟧c) p∥R*q) with binding-extractc' ⊢C⟦p⟧ d≐C⟦p∥q⟧c ... | (FV' , BV') , CB2 with CB2 ... | (CBpar{BVp = BVp}{FVp = FVp} y y₁ BVp≠BVq FVp≠BVq BVp≠FVq Xp≠Xq) with n where n = binding-substc' ⊢C⟦p⟧ d≐C⟦p∥q⟧c CB2 (∪-comm-⊆-left BVp ⊆-refl) ((∪-comm-⊆-left FVp ⊆-refl)) ((CBpar y₁ y (distinct-sym BVp≠BVq) (distinct-sym BVp≠FVq) (distinct-sym FVp≠BVq) (distinct'-sym Xp≠Xq))) ... | (_ , _ , cb) with BVFVcorrect _ _ _ cb ... | refl , refl = ∥R*-preserve-CB _ _ cb p∥R*q ∥R*∪sn⟶*-preserve-CB : ∀ p q → (⊢C⟦p⟧ : CB p) → (p∥R*∪sn⟶*q : p ∥R*∪sn⟶* q) → CB q ∥R*∪sn⟶*-preserve-CB p q ⊢C⟦p⟧ (∪∥R* p∥R*q p∥R*∪sn⟶*q) = ∥R*∪sn⟶*-preserve-CB _ _ (∥R*-preserve-CB _ _ ⊢C⟦p⟧ p∥R*q) p∥R*∪sn⟶*q ∥R*∪sn⟶*-preserve-CB p q ⊢C⟦p⟧ (∪sn⟶* psn⟶*q p∥R*∪sn⟶*q) = ∥R*∪sn⟶*-preserve-CB _ _ next p∥R*∪sn⟶*q where next = CB-preservation* p _ ⊢C⟦p⟧ psn⟶*q ∥R*∪sn⟶*-preserve-CB p .p ⊢C⟦p⟧ ∪refl = ⊢C⟦p⟧ ⟶₁-preserve-CB : ∀ p q C → (⊢C⟦p⟧ : CB (C ⟦ p ⟧c)) → (p⟶₁q : p ⟶₁ q) → CB (C ⟦ q ⟧c) ⟶₁-preserve-CB p q C ⊢C⟦p⟧ p⟶₁q with (⟶*->∥R*∪sn⟶* ([step] ([context] C Crefl p⟶₁q) [refl])) ... | p∥R*∪sn⟶*q = ∥R*∪sn⟶*-preserve-CB (C ⟦ p ⟧c) (C ⟦ q ⟧c) ⊢C⟦p⟧ p∥R*∪sn⟶*q
40.246875
206
0.544219
19d9264eecd664ee8e74999f5e7eb27255877e24
4,901
agda
Agda
Cubical/Relation/Binary/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Relation/Binary/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Relation/Binary/Base.agda
barrettj12/cubical
7b41b9171f90473efc98487cb2ea7a4d02320cb2
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --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 isAntisym : Type (ℓ-max ℓ ℓ') isAntisym = (a b : A) → R a b → R b a → a ≡ b 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) isSetValued : Type (ℓ-max ℓ ℓ') isSetValued = (a b : A) → isSet (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)
32.892617
106
0.548868
5ec13c943f419a79d3dd052d5565cb1da8b5e4e6
40,834
agda
Agda
Formalization/ClassicalPropositionalLogic.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Formalization/ClassicalPropositionalLogic.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Formalization/ClassicalPropositionalLogic.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
open import Type open import Logic.Classical as Logic using (Classical) open import Logic.Predicate as Logic using () module Formalization.ClassicalPropositionalLogic ⦃ classical : ∀{ℓ} → Logic.∀ₗ(Classical{ℓ}) ⦄ where import Lvl open import Data open import Data.Boolean import Data.Boolean.Operators open import Data.Boolean.Stmt open import Data.Either as Either using (_‖_ ; Left ; Right) open import Data.Tuple as Tuple using () private module BoolOp = Data.Boolean.Operators.Logic open import Functional open import Function.Names using (_⊜_) open import Logic open import Logic.Propositional as Logic using (_←_) open import Logic.Propositional.Theorems as Logic using () open import Logic.Predicate.Theorems as Logic using () open import Relator.Equals open import Relator.Equals.Proofs open import Relator.Equals.Proofs.Equiv open import Sets.PredicateSet using (PredSet ; _∈_ ; _∉_ ; _∪_ ; _∪•_ ; _∖_ ; _⊆_ ; _⊇_ ; ∅ ; [≡]-to-[⊆] ; [≡]-to-[⊇]) renaming (•_ to singleton ; _≡_ to _≡ₛ_) open Sets.PredicateSet.BoundedQuantifiers open import Structure.Relator.Properties open import Syntax.Function open import Type.Properties.Decidable.Proofs open import Type.Properties.Decidable open import Type.Size.Countable private variable ℓₚ ℓ ℓ₁ ℓ₂ : Lvl.Level open import Formalization.ClassicalPropositionalLogic.NaturalDeduction open import Formalization.ClassicalPropositionalLogic.NaturalDeduction.Proofs open import Formalization.ClassicalPropositionalLogic.Syntax open import Formalization.ClassicalPropositionalLogic.Syntax.Proofs open import Formalization.ClassicalPropositionalLogic.Semantics open import Formalization.ClassicalPropositionalLogic.Semantics.Proofs import Formalization.ClassicalPropositionalLogic.TruthTable as TruthTable instance _ = classical-to-decidable instance _ = classical-to-decider module NaturalDeduction where private variable P : Type{ℓₚ} private variable Γ Γ₁ Γ₂ : Formulas(P){ℓ} private variable φ ψ : Formula(P) [⊢]-functionₗ : (Γ₁ ≡ₛ Γ₂) → ((Γ₁ ⊢_) ≡ₛ (Γ₂ ⊢_)) [⊢]-functionₗ Γ₁Γ₂ = Logic.[↔]-intro (weaken (Logic.[↔]-to-[←] Γ₁Γ₂)) (weaken (Logic.[↔]-to-[→] Γ₁Γ₂)) [⊢]-compose : (Γ ⊢ φ) → ((Γ ∪ singleton(φ)) ⊢ ψ) → (Γ ⊢ ψ) [⊢]-compose Γφ Γφψ = [∨]-elim Γφψ Γφψ ([∨]-introₗ Γφ) -- TODO: Is this provable? Does one need to include it in the definition of (_⊢_)? Is it even possible to include it? -- [⊢]-hypothesis : ((Γ ⊢ φ) → (Γ ⊢ ψ)) → ((Γ ∪ singleton(φ)) ⊢ ψ) -- [⊢]-hypothesis hyp = {!!} [⊢][→]-intro-from-[∨] : (Γ ⊢ ¬ φ) Logic.∨ (Γ ⊢ ψ) → (Γ ⊢ (φ ⟶ ψ)) [⊢][→]-intro-from-[∨] {Γ = Γ}{φ}{ψ} (Left x) = [⟶]-intro ([⊥]-elim ([⊥]-intro (direct (Right [≡]-intro)) (weaken-union {Γ₂ = singleton φ} x))) [⊢][→]-intro-from-[∨] (Right x) = [⟶]-intro (weaken-union x) -- A smallest finite set of assumptions that is able to derive a formula. finiteAssumptions : ∀{φ : Formula(P)} → (Γ ⊢ φ) → Formulas(P){Lvl.of(P)} finiteAssumptions {φ = φ} (direct _) = singleton(φ) finiteAssumptions {φ = .⊤} [⊤]-intro = ∅ finiteAssumptions {φ = .⊥} ([⊥]-intro p q) = finiteAssumptions p ∪ finiteAssumptions q finiteAssumptions {φ = φ} ([⊥]-elim p) = finiteAssumptions p finiteAssumptions {φ = ¬ φ} ([¬]-intro{φ = φ} p) = finiteAssumptions p ∖ singleton(φ) finiteAssumptions {φ = φ} ([¬]-elim {φ = φ} p) = finiteAssumptions p ∖ singleton(¬ φ) finiteAssumptions {φ = .(_ ∧ _)} ([∧]-intro p q) = finiteAssumptions p ∪ finiteAssumptions q finiteAssumptions {φ = φ} ([∧]-elimₗ p) = finiteAssumptions p finiteAssumptions {φ = φ} ([∧]-elimᵣ p) = finiteAssumptions p finiteAssumptions {φ = .(_ ∨ _)} ([∨]-introₗ p) = finiteAssumptions p finiteAssumptions {φ = .(_ ∨ _)} ([∨]-introᵣ p) = finiteAssumptions p finiteAssumptions {φ = _} ([∨]-elim {φ = φ}{ψ} p q r) = ((finiteAssumptions p ∖ singleton(φ)) ∪ (finiteAssumptions q ∖ singleton(ψ))) ∪ finiteAssumptions r finiteAssumptions {φ = .(_ ⟶ _)} ([⟶]-intro{φ = φ} p) = finiteAssumptions p ∖ singleton(φ) finiteAssumptions {φ = φ} ([⟶]-elim p q) = finiteAssumptions p ∪ finiteAssumptions q finiteAssumptions {φ = .(_ ⟷ _)} ([⟷]-intro{φ = φ}{ψ} p q) = (finiteAssumptions p ∖ singleton(ψ)) ∪ (finiteAssumptions q ∖ singleton(φ)) finiteAssumptions {φ = φ} ([⟷]-elimₗ p q) = finiteAssumptions p ∪ finiteAssumptions q finiteAssumptions {φ = φ} ([⟷]-elimᵣ p q) = finiteAssumptions p ∪ finiteAssumptions q finiteAssumptions-correctness : (p : (Γ ⊢ φ)) → (finiteAssumptions p ⊢ φ) finiteAssumptions-correctness (direct x) = direct [≡]-intro finiteAssumptions-correctness [⊤]-intro = [⊤]-intro finiteAssumptions-correctness ([⊥]-intro p q) = [⊥]-intro (weaken Left (finiteAssumptions-correctness p)) (weaken Right (finiteAssumptions-correctness q)) finiteAssumptions-correctness ([⊥]-elim p) = [⊥]-elim (finiteAssumptions-correctness p) finiteAssumptions-correctness ([¬]-intro p) = [¬]-intro (weaken (Logic.[↔]-to-[←] ([∖][∪]-is-[∪] {A = finiteAssumptions p}{B = singleton _}) ∘ Logic.[∨]-introₗ) (finiteAssumptions-correctness p)) finiteAssumptions-correctness ([¬]-elim p) = [¬]-elim (weaken (Logic.[↔]-to-[←] ([∖][∪]-is-[∪] {A = finiteAssumptions p}{B = singleton _}) ∘ Logic.[∨]-introₗ) (finiteAssumptions-correctness p)) finiteAssumptions-correctness ([∧]-intro p q) = [∧]-intro (weaken Left (finiteAssumptions-correctness p)) (weaken Right (finiteAssumptions-correctness q)) finiteAssumptions-correctness ([∧]-elimₗ p) = [∧]-elimₗ (finiteAssumptions-correctness p) finiteAssumptions-correctness ([∧]-elimᵣ p) = [∧]-elimᵣ (finiteAssumptions-correctness p) finiteAssumptions-correctness ([∨]-introₗ p) = [∨]-introₗ (finiteAssumptions-correctness p) finiteAssumptions-correctness ([∨]-introᵣ p) = [∨]-introᵣ (finiteAssumptions-correctness p) finiteAssumptions-correctness ([∨]-elim{φ = φ}{ψ} p q r) = [∨]-elim (weaken (sl ∘ Left) (finiteAssumptions-correctness p)) (weaken (sr ∘ Left) (finiteAssumptions-correctness q)) (weaken Right (finiteAssumptions-correctness r)) where postulate sl : (finiteAssumptions p ∪ singleton(φ)) ⊆ ((((finiteAssumptions p ∖ singleton(φ)) ∪ (finiteAssumptions q ∖ singleton(ψ))) ∪ finiteAssumptions r) ∪ singleton(φ)) postulate sr : (finiteAssumptions q ∪ singleton(ψ)) ⊆ ((((finiteAssumptions p ∖ singleton(φ)) ∪ (finiteAssumptions q ∖ singleton(ψ))) ∪ finiteAssumptions r) ∪ singleton(ψ)) finiteAssumptions-correctness ([⟶]-intro p) = [⟶]-intro (weaken (Logic.[↔]-to-[←] ([∖][∪]-is-[∪] {A = finiteAssumptions p}{B = singleton _}) ∘ Logic.[∨]-introₗ) (finiteAssumptions-correctness p)) finiteAssumptions-correctness ([⟶]-elim p q) = [⟶]-elim (weaken Left (finiteAssumptions-correctness p)) (weaken Right (finiteAssumptions-correctness q)) finiteAssumptions-correctness ([⟷]-intro p q) = [⟷]-intro (weaken (sl ∘ Left) (finiteAssumptions-correctness p)) (weaken (sr ∘ Left) (finiteAssumptions-correctness q)) where postulate sl : (finiteAssumptions p ∪ singleton(φ)) ⊆ (((finiteAssumptions p ∖ singleton(φ)) ∪ (finiteAssumptions q ∖ singleton(ψ))) ∪ singleton(φ)) postulate sr : (finiteAssumptions q ∪ singleton(ψ)) ⊆ (((finiteAssumptions p ∖ singleton(φ)) ∪ (finiteAssumptions q ∖ singleton(ψ))) ∪ singleton(ψ)) finiteAssumptions-correctness ([⟷]-elimₗ p q) = [⟷]-elimₗ (weaken Left (finiteAssumptions-correctness p)) (weaken Right (finiteAssumptions-correctness q)) finiteAssumptions-correctness ([⟷]-elimᵣ p q) = [⟷]-elimᵣ (weaken Left (finiteAssumptions-correctness p)) (weaken Right (finiteAssumptions-correctness q)) finiteAssumptions-subset : (p : (Γ ⊢ φ)) → (finiteAssumptions p ⊆ Γ) finiteAssumptions-subset (direct x) = \{[≡]-intro → x} finiteAssumptions-subset [⊤]-intro = empty finiteAssumptions-subset ([⊥]-intro p q) = [∪]-subset (\{x} → finiteAssumptions-subset p {x}) (\{x} → finiteAssumptions-subset q {x}) finiteAssumptions-subset ([⊥]-elim p) = finiteAssumptions-subset p finiteAssumptions-subset ([¬]-intro p) = [∪][∖]-invertᵣ-[⊆] {A = finiteAssumptions p} (finiteAssumptions-subset p) finiteAssumptions-subset ([¬]-elim p) = [∪][∖]-invertᵣ-[⊆] {A = finiteAssumptions p} (finiteAssumptions-subset p) finiteAssumptions-subset ([∧]-intro p q) = [∪]-subset (\{x} → finiteAssumptions-subset p {x}) (\{x} → finiteAssumptions-subset q {x}) finiteAssumptions-subset ([∧]-elimₗ p) = finiteAssumptions-subset p finiteAssumptions-subset ([∧]-elimᵣ p) = finiteAssumptions-subset p finiteAssumptions-subset ([∨]-introₗ p) = finiteAssumptions-subset p finiteAssumptions-subset ([∨]-introᵣ p) = finiteAssumptions-subset p finiteAssumptions-subset{Γ = Γ} ([∨]-elim p q r) = [∪]-subset (\{x} → [∪]-subset{C = Γ} ([∪][∖]-invertᵣ-[⊆] {B = Γ} (finiteAssumptions-subset p)) ([∪][∖]-invertᵣ-[⊆] {B = Γ} (finiteAssumptions-subset q)) {x}) (finiteAssumptions-subset r) finiteAssumptions-subset ([⟶]-intro p) = \{(Logic.[∧]-intro fpx φx) → Logic.[∨]-elim id (Logic.[⊥]-elim ∘ φx) (finiteAssumptions-subset p fpx)} finiteAssumptions-subset ([⟶]-elim p q) = [∪]-subset (\{x} → finiteAssumptions-subset p {x}) (\{x} → finiteAssumptions-subset q {x}) finiteAssumptions-subset ([⟷]-intro p q) = Logic.[∨]-elim ([∪][∖]-invertᵣ-[⊆] {A = finiteAssumptions p} (finiteAssumptions-subset p)) ([∪][∖]-invertᵣ-[⊆] {A = finiteAssumptions q} (finiteAssumptions-subset q)) finiteAssumptions-subset ([⟷]-elimₗ p q) = [∪]-subset (\{x} → finiteAssumptions-subset p {x}) (\{x} → finiteAssumptions-subset q {x}) finiteAssumptions-subset ([⟷]-elimᵣ p q) = [∪]-subset (\{x} → finiteAssumptions-subset p {x}) (\{x} → finiteAssumptions-subset q {x}) {- module _ where open import Numeral.Natural finiteAssumptions-index : (p : (Γ ⊢ φ)) → ∀{x} → (x ∈ finiteAssumptions p) → ℕ finiteAssumptions-index (direct x) [≡]-intro = {!!} finiteAssumptions-index [⊤]-intro () finiteAssumptions-index ([⊥]-intro p q) (Left x) = {!!} finiteAssumptions-index ([⊥]-intro p q) (Right x) = {!!} finiteAssumptions-index ([⊥]-elim p) = {!!} finiteAssumptions-index ([¬]-intro p) = {!!} finiteAssumptions-index ([¬]-elim p) = {!!} finiteAssumptions-index ([∧]-intro p p₁) = {!!} finiteAssumptions-index ([∧]-elimₗ p) = {!!} finiteAssumptions-index ([∧]-elimᵣ p) = {!!} finiteAssumptions-index ([∨]-introₗ p) = {!!} finiteAssumptions-index ([∨]-introᵣ p) = {!!} finiteAssumptions-index ([∨]-elim p p₁ p₂) = {!!} finiteAssumptions-index ([⟶]-intro p) = {!!} finiteAssumptions-index ([⟶]-elim p p₁) = {!!} finiteAssumptions-index ([⟷]-intro p p₁) = {!!} finiteAssumptions-index ([⟷]-elimₗ p p₁) = {!!} finiteAssumptions-index ([⟷]-elimᵣ p p₁) = {!!} -} module _ (Γ : Formulas(P){ℓ}) where ConsistentSubsetMaximality = ∀{Δ : Formulas(P){Lvl.of(P) Lvl.⊔ ℓ}} → Consistent(Δ) → (Γ ⊆ Δ) → (Δ ⊆ Γ) ConsistentElementMaximality = ∀{φ} → Consistent(Γ ∪ singleton(φ)) → (φ ∈ Γ) CompleteDerivability = ∀{φ} → (Γ ⊢ φ) Logic.∨ (Γ ⊢ (¬ φ)) CompleteMembership = ∀{φ} → (φ ∈ Γ) Logic.∨ ((¬ φ) ∈ Γ) -- Equivalences when `Γ` is consistent. Used in the definition of `MaximallyConsistent`. data ConsistentlyComplete : Stmt{Lvl.𝐒(Lvl.of(P) Lvl.⊔ ℓ)} where subset-intro : ConsistentSubsetMaximality → ConsistentlyComplete element-intro : ConsistentElementMaximality → ConsistentlyComplete complete-deriv-intro : CompleteDerivability → ConsistentlyComplete complete-member-intro : CompleteMembership → ConsistentlyComplete module CompleteMembership(p : CompleteMembership) where consistentSubsetMaximality : ConsistentSubsetMaximality consistentSubsetMaximality conΔ ΓΔ {φ} φΔ = Logic.[∨]-not-right (p{φ}) (¬φΓ ↦ conΔ([⊥]-intro (direct φΔ) (direct(ΓΔ ¬φΓ)))) module ConsistentElementMaximality(element-maximal : ConsistentElementMaximality) where consistentSubsetMaximality : ConsistentSubsetMaximality consistentSubsetMaximality conΔ ΓΔ {φ} φΔ = element-maximal ([⊢]-subset-consistency (Logic.[∨]-elim ΓΔ (\{([≡]-intro) → φΔ})) conΔ) element-maximal-contra : (φ ∉ Γ) → Inconsistent(Γ ∪ singleton(φ)) element-maximal-contra = Logic.[↔]-to-[←] Logic.contrapositive-variant2 element-maximal [⊢]-derivability-consistencyₗ : ((Γ ⊢ φ) ← Consistent(Γ ∪ singleton(φ))) [⊢]-derivability-consistencyₗ = direct ∘ element-maximal module Consistent(consistent : Consistent(Γ)) where [⊢]-to-[∈] : (Γ ⊢ φ) → (φ ∈ Γ) [⊢]-to-[∈] = Logic.[→]-from-contrary (\Γφ φ∉Γ → consistent ([⊢]-compose-inconsistency Γφ (element-maximal-contra φ∉Γ))) [⊢][∈]-equivalence : (Γ ⊢ φ) Logic.↔ (φ ∈ Γ) [⊢][∈]-equivalence = Logic.[↔]-intro direct [⊢]-to-[∈] -- [•]-maximal-membership : ((• p) ∈ Γ) Logic.↔ ? -- [•]-maximal-membership = [⊤]-maximal-membership : (⊤ ∈ Γ) Logic.↔ Logic.⊤ [⊤]-maximal-membership = Logic.[↔]-intro l r where l = const (element-maximal (Γ⊤-incons ↦ consistent([⊢]-compose-inconsistency [⊤]-intro Γ⊤-incons))) r = const Logic.[⊤]-intro [⊥]-maximal-membership : (⊥ ∈ Γ) Logic.↔ Logic.⊥ [⊥]-maximal-membership = Logic.[↔]-intro l r where l = Logic.[⊥]-elim r = consistent ∘ direct [¬]-maximal-membership : ((¬ φ) ∈ Γ) Logic.↔ (φ ∉ Γ) [¬]-maximal-membership = Logic.[↔]-intro l r where l = [⊢]-to-[∈] ∘ [¬]-intro ∘ element-maximal-contra r = [⊢]-consistent-noncontradicting-membership consistent [∧]-maximal-membership : ((φ ∧ ψ) ∈ Γ) Logic.↔ ((φ ∈ Γ) Logic.∧ (ψ ∈ Γ)) [∧]-maximal-membership = Logic.[↔]-intro l r where l = \{(Logic.[∧]-intro φΓ ψΓ) → [⊢]-to-[∈] ([∧]-intro (direct φΓ) (direct ψΓ))} r = φψΓ ↦ Logic.[∧]-intro ([⊢]-to-[∈] ([∧]-elimₗ(direct φψΓ))) ([⊢]-to-[∈] ([∧]-elimᵣ(direct φψΓ))) [∨]-maximal-membership : ((φ ∨ ψ) ∈ Γ) Logic.↔ ((φ ∈ Γ) Logic.∨ (ψ ∈ Γ)) [∨]-maximal-membership = Logic.[↔]-intro l r where l = Logic.[∨]-elim ([⊢]-to-[∈] ∘ [∨]-introₗ ∘ direct) ([⊢]-to-[∈] ∘ [∨]-introᵣ ∘ direct) r = Logic.contrapositiveₗ ⦃ classical ⦄ ((\{(Logic.[∧]-intro ¬φΓ ¬ψΓ) → φψΓ ↦ consistent([∨]-elim (element-maximal-contra ¬φΓ) (element-maximal-contra ¬ψΓ) (direct φψΓ))}) ∘ Logic.[↔]-to-[→] Logic.[¬]-preserves-[∨][∧]) [⟶]-maximal-membership : ((φ ⟶ ψ) ∈ Γ) Logic.↔ ((φ ∉ Γ) Logic.∨ (ψ ∈ Γ)) [⟶]-maximal-membership = Logic.[↔]-symmetry [⊢][∈]-equivalence ⦗ Logic.[↔]-transitivity ⦘ₗ [→]-disjunctive-form ⦗ Logic.[↔]-transitivity ⦘ₗ [⊢][∈]-equivalence ⦗ Logic.[↔]-transitivity ⦘ₗ [∨]-maximal-membership ⦗ Logic.[↔]-transitivity ⦘ₗ Logic.[↔]-intro (Either.mapLeft (Logic.[↔]-to-[←] [¬]-maximal-membership)) (Either.mapLeft ((Logic.[↔]-to-[→] [¬]-maximal-membership))) [⟷]-maximal-membership : ((φ ⟷ ψ) ∈ Γ) Logic.↔ (((φ ∈ Γ) Logic.∧ (ψ ∈ Γ)) Logic.∨ ((φ ∉ Γ) Logic.∧ (ψ ∉ Γ))) [⟷]-maximal-membership = Logic.[↔]-symmetry [⊢][∈]-equivalence ⦗ Logic.[↔]-transitivity ⦘ₗ [⟷]-conjunction-disjunction-negation ⦗ Logic.[↔]-transitivity ⦘ₗ [⊢][∈]-equivalence ⦗ Logic.[↔]-transitivity ⦘ₗ [∨]-maximal-membership ⦗ Logic.[↔]-transitivity ⦘ₗ Logic.[↔]-intro (Either.map (Logic.[↔]-to-[←] [∧]-maximal-membership) (Logic.[↔]-to-[←] [∧]-maximal-membership)) (Either.map (Logic.[↔]-to-[→] [∧]-maximal-membership) (Logic.[↔]-to-[→] [∧]-maximal-membership)) ⦗ Logic.[↔]-transitivity ⦘ₗ Logic.[↔]-intro (Either.mapRight (Tuple.map (Logic.[↔]-to-[←] [¬]-maximal-membership) (Logic.[↔]-to-[←] [¬]-maximal-membership))) (Either.mapRight (Tuple.map (Logic.[↔]-to-[→] [¬]-maximal-membership) (Logic.[↔]-to-[→] [¬]-maximal-membership))) complete-membership : CompleteMembership complete-membership = Logic.[¬→]-disjunctive-formᵣ (Logic.[↔]-to-[←] [¬]-maximal-membership) equal-model-existence : Logic.∃(𝔐 ↦ (Γ ≡ₛ (𝔐 ⊧_))) equal-model-existence = Logic.[∃]-intro witness ⦃ Logic.[↔]-intro l r ⦄ where witness = (p ↦ decide(0)((• p) ∈ Γ)) l : (witness ⊧ φ) → (φ ∈ Γ) r : witness ⊧₊ Γ r {• x} = Logic.[↔]-to-[→] decider-true r {⊤} = Logic.[↔]-to-[→] [⊤]-maximal-membership r {⊥} = Logic.[↔]-to-[→] [⊥]-maximal-membership r {¬ φ} = Logic.contrapositiveᵣ l ∘ Logic.[↔]-to-[→] [¬]-maximal-membership r {φ ∧ ψ} = Tuple.map r r ∘ Logic.[↔]-to-[→] [∧]-maximal-membership r {φ ∨ ψ} = Either.map r r ∘ Logic.[↔]-to-[→] [∨]-maximal-membership r {φ ⟶ ψ} = Either.map (Logic.contrapositiveᵣ l) r ∘ Logic.[↔]-to-[→] [⟶]-maximal-membership r {φ ⟷ ψ} = Either.map (Tuple.map r r) (Tuple.map (Logic.contrapositiveᵣ l) (Logic.contrapositiveᵣ l)) ∘ Logic.[↔]-to-[→] [⟷]-maximal-membership l {• x} = Logic.[↔]-to-[←] decider-true l {⊤} = Logic.[↔]-to-[←] [⊤]-maximal-membership l {¬ φ} = Logic.[↔]-to-[←] [¬]-maximal-membership ∘ Logic.contrapositiveᵣ r l {φ ∧ ψ} = Logic.[↔]-to-[←] [∧]-maximal-membership ∘ Tuple.map l l l {φ ∨ ψ} = Logic.[↔]-to-[←] [∨]-maximal-membership ∘ Either.map l l l {φ ⟶ ψ} = Logic.[↔]-to-[←] [⟶]-maximal-membership ∘ Either.map (Logic.contrapositiveᵣ r) l l {φ ⟷ ψ} = Logic.[↔]-to-[←] [⟷]-maximal-membership ∘ Either.map (Tuple.map l l) (Tuple.map (Logic.contrapositiveᵣ r) (Logic.contrapositiveᵣ r)) satisfiable : Satisfiable(Γ) satisfiable = Logic.[∃]-map-proof (\eq {φ} → Logic.[↔]-to-[→] (eq{φ})) equal-model-existence module ConsistentSubsetMaximality(p : ConsistentSubsetMaximality) where consistentElementMaximality : ConsistentElementMaximality consistentElementMaximality con = p con Left (Right [≡]-intro) module CompleteDerivability(p : CompleteDerivability) where module Consistent(consistent : Consistent(Γ)) where [⊢]-to-[∈]' : (Γ ⊢ φ) → (φ ∈ Γ) [⊢]-to-[∈]' {φ = φ} = Logic.[→]-disjunctive-formₗ {!!} consistentSubsetMaximality : ConsistentSubsetMaximality consistentSubsetMaximality {Δ} conΔ ΓΔ {φ} φΔ = {!Logic.[¬→]-disjunctive-formₗ (Either.map (weaken ΓΔ) (weaken ΓΔ) (p{φ}))!} {-with p{φ} | Logic.excluded-middle((¬ φ) ∈ Δ) ... | Left q | Left r = {!!} ... | Left q | Right r with () ← Logic.contrapositiveᵣ(weaken ΓΔ) {!!} {!!} ... | Right q | _ with () ← conΔ([⊥]-intro (direct φΔ) (weaken ΓΔ q))-} -- conΔ([⊥]-intro (direct φΔ) (direct(ΓΔ ¬φΓ))) -- Logic.[∨]-not-right (p{φ}) (¬φΓ ↦ ?) consistentElementMaximality : ConsistentElementMaximality consistentElementMaximality {φ} conΓφ with p{φ} | Logic.excluded-middle((¬ φ) ∈ Γ) ... | Left q | Left r with () ← consistent([⊥]-intro q (direct r)) ... | Left q | Right r = Logic.[¬¬]-elim (¬Γφ ↦ {![⊢]-consistent-noncontradicting-membership consistent !}) ... | Right q | _ with () ← conΓφ([¬]-intro-converse q) -- ConsistentSubsetMaximality.consistentElementMaximality {!!} -- [⊢]-derivability-consistencyᵣ consistent q -- [¬]-intro(Logic.[↔]-to-[→] [⊢]-derivability-inconsistency q) -- Logic.contrapositiveᵣ direct conΓφ -- (¬φΓ ↦ Logic.contrapositiveᵣ direct (conΓφ ∘ [¬]-intro-converse) {!r ∘ direct!}) -- [⊢]-consistent-noncontradicting-membership consistent -- (r ∘ direct) completeMembership : CompleteMembership completeMembership = Either.map [⊢]-to-[∈] [⊢]-to-[∈] p where [⊢]-to-[∈] = (ConsistentElementMaximality.Consistent.[⊢]-to-[∈] consistentElementMaximality consistent) record MaximallyConsistent (Γ : Formulas(P){ℓ}) : Stmt{Lvl.𝐒(Lvl.of(P) Lvl.⊔ ℓ)} where field consistent : Consistent(Γ) maximal : ConsistentlyComplete(Γ) subset-maximal : ConsistentSubsetMaximality(Γ) element-maximal : ConsistentElementMaximality(Γ) element-maximal with maximal ... | subset-intro p = ConsistentSubsetMaximality.consistentElementMaximality Γ p ... | element-intro p = p ... | complete-deriv-intro p = ConsistentSubsetMaximality.consistentElementMaximality Γ subset-maximal where ... | complete-member-intro p = ConsistentSubsetMaximality.consistentElementMaximality Γ (CompleteMembership.consistentSubsetMaximality Γ p) open ConsistentElementMaximality Γ element-maximal using ( element-maximal-contra ; [⊢]-derivability-consistencyₗ ) public open ConsistentElementMaximality.Consistent Γ element-maximal consistent using ( [⊢]-to-[∈] ; equal-model-existence ) public subset-maximal with maximal ... | subset-intro p = p ... | element-intro p = ConsistentElementMaximality.consistentSubsetMaximality Γ p ... | complete-deriv-intro p = CompleteMembership.consistentSubsetMaximality Γ (Either.map [⊢]-to-[∈] [⊢]-to-[∈] p) ... | complete-member-intro p = CompleteMembership.consistentSubsetMaximality Γ p {-r : (term-model(max Γ con) ⊧ φ) → (φ ∈ max Γ con) r {• x} modelsφ Γφ-incons = Logic.[↔]-to-[←] Logic.decide-is-true modelsφ Γφ-incons r {⊤} modelsφ Γφ-incons = con([⊢]-compose-inconsistency [⊤]-intro Γφ-incons)-} open MaximallyConsistent ⦃ … ⦄ using ( [⊢]-derivability-consistencyₗ ; [⊤]-maximal-membership ; [⊥]-maximal-membership ; [¬]-maximal-membership ; [∧]-maximal-membership ; [∨]-maximal-membership ; [⟶]-maximal-membership ; [⟷]-maximal-membership ) public module _ ⦃ countable-P : CountablyInfinite P ⦄ where -- Also called: Lindenbaums' lemma open import Numeral.Natural private variable n : ℕ {- data maxi (Γ : Formulas(P){ℓ}) : ℕ → Formulas(P){Lvl.of(P) Lvl.⊔ ℓ} where base : Γ ⊆ maxi Γ 𝟎 step : maxi Γ n ⊆ maxi Γ (𝐒(n)) form : let ψ = Logic.[∃]-witness (Formula-is-countably-infinite {P = P}) n in maxi Γ (𝐒(n)) (if Logic.decide(maxi Γ n ⊢ ψ) then ψ else (¬ ψ)) maxi-zero : (Γ ≡ₛ maxi Γ 𝟎) maxi-zero = Logic.[↔]-intro (\{(base p) → p}) base maxi-succ : let ψ = Logic.[∃]-witness (Formula-is-countably-infinite {P = P}) n in (((maxi Γ n) ∪ singleton(if Logic.decide(maxi Γ n ⊢ ψ) then ψ else (¬ ψ))) ≡ₛ maxi Γ (𝐒(n))) maxi-succ {n = n}{Γ = Γ} = Logic.[↔]-intro l r where p = Logic.[∃]-witness (Formula-is-countably-infinite {P = P}) n l : ((maxi Γ n) ∪ singleton(if Logic.decide(maxi Γ n ⊢ p) then p else (¬ p))) ⊇ maxi Γ (𝐒(n)) l (step x) = Left x l form = Right [≡]-intro r : ((maxi Γ n) ∪ singleton(if Logic.decide(maxi Γ n ⊢ p) then p else (¬ p))) ⊆ maxi Γ (𝐒(n)) r (Left x) = step x r (Right [≡]-intro) = form maxi-superset : Consistent(Γ) → (∀{n} → (Γ ⊆ maxi Γ n)) maxi-superset {Γ = Γ} con {𝟎} = Logic.[↔]-to-[→] maxi-zero maxi-superset {Γ = Γ} con {𝐒 n} {φ} Γφ = {!!} instance maxi-consistent : Consistent(Γ) → (∀{n} → Consistent(maxi Γ n)) maxi-consistent con {n = 𝟎} = [⊢]-subset-consistency (Logic.[↔]-to-[←] maxi-zero) con maxi-consistent {Γ = Γ} con {n = 𝐒 n} = [⊢]-subset-consistency (Logic.[↔]-to-[←] maxi-succ) con-eq where p = Logic.[∃]-witness (Formula-is-countably-infinite {P = P}) n con-eq : Consistent((maxi Γ n) ∪ singleton(if Logic.decide(maxi Γ n ⊢ p) then p else (¬ p))) con-eq with Logic.excluded-middle(maxi Γ n ⊢ p) | Logic.decide(maxi Γ n ⊢ p) ... | Left derp | _ = [⊢]-compose-consistency derp (maxi-consistent con {n = n}) ... | Right dernp | _ = [⊬]-negation-consistency(dernp ∘ [¬¬]-elim) -} maxi2 : Formulas(P){ℓ} → ℕ → Formulas(P){Lvl.of(P) Lvl.⊔ ℓ} maxi2 Γ 𝟎 = Lvl.Up{Lvl.of(P)} ∘ Γ maxi2 Γ (𝐒(n)) = let ψ = CountablyInfinite.index(Formula P) n in (maxi2 Γ n) ∪ singleton(if decide(0)(maxi2 Γ n ⊢ ψ) then ψ else (¬ ψ)) maxi2-succ : let ψ = CountablyInfinite.index(Formula P) n in (((maxi2 Γ n) ∪ singleton(if decide(0)(maxi2 Γ n ⊢ ψ) then ψ else (¬ ψ))) ≡ₛ maxi2 Γ (𝐒(n))) -- maxi2-succ {n = n}{Γ = Γ} = Logic.[↔]-intro {!!} {!!} maxi2-zero : (Γ ≡ₛ maxi2 Γ 𝟎) maxi2-zero {Γ = Γ} = Logic.[↔]-symmetry (Sets.PredicateSet.LvlUp-set-equality {S = Γ}) maxi2-superset : ∀{n} → (Γ ⊆ maxi2 Γ n) maxi2-superset {Γ = Γ} {𝟎} = Logic.[↔]-to-[→] (maxi2-zero {Γ = Γ}) maxi2-superset {Γ = Γ} {𝐒 n} = Left ∘ maxi2-superset {Γ = Γ} {n} instance maxi2-consistent : Consistent(Γ) → (∀{n} → Consistent(maxi2 Γ n)) maxi2-consistent {Γ = Γ} con {n = 𝟎} = [⊢]-subset-consistency (Logic.[↔]-to-[←] (maxi2-zero {Γ = Γ})) con maxi2-consistent {Γ = Γ} con {n = 𝐒 n} = [⊢]-subset-consistency (Logic.[↔]-to-[←] (maxi2-succ {Γ = Γ})) con-eq where p = CountablyInfinite.index(Formula P) n con-eq : Consistent((maxi2 Γ n) ∪ singleton(if decide(0)(maxi2 Γ n ⊢ p) then p else (¬ p))) con-eq with Logic.excluded-middle(maxi2 Γ n ⊢ p) | decide(0)(maxi2 Γ n ⊢ p) ... | Left derp | _ = [⊢]-compose-consistency derp (maxi2-consistent con {n = n}) ... | Right dernp | _ = [⊬]-negation-consistency(dernp ∘ [¬¬]-elim) max : (Γ : Formulas(P){ℓ}) → Formulas(P){Lvl.of(P) Lvl.⊔ ℓ} max(Γ) φ = Logic.∃(n ↦ φ ∈ maxi2 Γ n) maxi2-subset-max : (maxi2 Γ n ⊆ max Γ) maxi2-subset-max {Γ = Γ} {n} p = Logic.[∃]-intro n ⦃ p ⦄ open import Lang.Inspect max-maximal : (φ ∈ max Γ) Logic.∨ ((¬ φ) ∈ max Γ) max-maximal {φ = φ}{Γ = Γ} with n ← CountablyInfinite.indexing(Formula P) φ with Logic.excluded-middle(maxi2 Γ n ⊢ CountablyInfinite.index(Formula P) n) | inspect(maxi2 Γ) (𝐒 n) ... | Left p | intro q with r ← [≡]-with(_$ CountablyInfinite.index(Formula P) n) q = Left (Logic.[∃]-intro (𝐒(n)) ⦃ Right {!!} ⦄) ... | Right p | intro q = Right (Logic.[∃]-intro (𝐒(n)) ⦃ Right {!q!} ⦄) instance max-consistent : Consistent(Γ) → Consistent(max Γ) max-consistent {Γ = Γ} con = [⊢]-subset-consistency (Logic.[∃]-proof test5) (maxi2-consistent con {Logic.[∃]-witness test5}) where open import Numeral.Natural.Relation.Order open import Type.Properties.Inhabited test2 : (φ ∈ max Γ) → Logic.∃(n ↦ (φ ∈ maxi2 Γ n)) test2 p = p test3a : ∀{φ} → Logic.∃(n ↦ ((φ ∈ max Γ) → (φ ∈ maxi2 Γ n))) test3a = Logic.[∃]-unrelatedᵣ-[→]ₗ ⦃ pos = intro ⦃ 𝟎 ⦄ ⦄ test2 test3b : Logic.∃{Obj = Formula(P) → ℕ}(n ↦ (max Γ) ⊆ (φ ↦ φ ∈ maxi2 Γ (n(φ)))) test3b = Logic.[∀][∃]-to-function-existence test3a test4 : ∀{a b} → (a ≤ b) → ∀{Γ : Formulas(P){ℓ}} → ((maxi2 Γ a) ⊆ (maxi2 Γ b)) test4 {a = 𝟎} {𝟎} [≤]-minimum p = p test4 {a = 𝟎} {𝐒 b} [≤]-minimum {Γ} p = Left(test4 {a = 𝟎}{b} [≤]-minimum {Γ} p) test4 {a = 𝐒 a} {𝐒 b} ([≤]-with-[𝐒] ⦃ ab ⦄) {Γ} (Left p) = Left (test4 {a = a}{b} ab p) test4 {a = 𝐒 a} {𝐒 b} ([≤]-with-[𝐒] ⦃ ab ⦄) {Γ}{φ} (Right p) = {!test4 {a = a}{b = b} ab {Γ ∪ singleton(if Logic.decide(maxi2 Γ b ⊢ β) then β else (¬ β))}{φ} ? !} where β = CountablyInfinite.index(Formula P) b {-with Logic.excluded-middle(maxi2 Γ a ⊢ Logic.[∃]-witness Formula-is-countably-infinite a) | p ... | Left x | [≡]-intro = {!!} ... | Right x | q = test4 {a} {𝐒 b} {!!} {!!}-} -- TODO: Because test3 and test4 test5 : Logic.∃(n ↦ (max Γ) ⊆ (maxi2 Γ n)) -- with [∃]-intro n ⦃ pn ⦄ ← max Γ = {!!} -- [⊢]-subset-consistency (\{φ} → {!maxi2-consistent con {n = 𝟎}!}) {!con!} instance max-maximally-consistent : Consistent(Γ) → MaximallyConsistent(max Γ) MaximallyConsistent.consistent (max-maximally-consistent con) = max-consistent con MaximallyConsistent.maximal (max-maximally-consistent {Γ = Γ} con) = {!!} -- {φ} conm with n ← CountablyInfinite.indexing(Formula P) φ = {!!} max-superset : Γ ⊆ max Γ max-superset {Γ = Γ} Γφ = Logic.[∃]-intro 𝟎 ⦃ maxi2-superset {Γ = Γ}{n = 𝟎} Γφ ⦄ {- {- max : (Γ : Formulas(P){ℓ}) → Consistent(Γ) → Formulas(P){Lvl.𝐒(Lvl.of(P) Lvl.⊔ ℓ)} max Γ con φ = Consistent(Γ ∪ singleton(φ)) -- TODO: Probably not like this. The problem with this definition is that (Consistent(Γ ∪ singleton(φ)) → (Γ ⊢ φ)) is impossible to prove, and it is neccessary for proving that (max Γ con) for any Γ is a consistent set of formulas. This is related to the issue that if both (Γ ∪ singleton(φ)) and (Γ ∪ singleton(¬ φ)) is consistent, then both of them will be included. But this would lead to (max Γ cons) not necccesarily consistent. -- if decide(Consistent(Γ ∪ singleton(φ))) then (Γ ∪ singleton(φ)) else (Γ ∪ singleton(¬ φ)) {-data max2 (Γ : Formulas(P){ℓ}) (con : Consistent(Γ)) : Formulas(P){Lvl.𝐒(Lvl.of(P) Lvl.⊔ ℓ)} where Positive : Consistent (Γ ∪ singleton(φ)) → Inconsistent(Γ ∪ singleton(¬ φ)) → max2 Γ con φ Negative : Inconsistent(Γ ∪ singleton(φ)) → Consistent (Γ ∪ singleton(¬ φ)) → max2 Γ con φ -} max2 : (Γ : Formulas(P){ℓ}) → Consistent(Γ) → Formulas(P){Lvl.𝐒(Lvl.of(P) Lvl.⊔ ℓ)} max2 Γ con φ = Consistent(Γ ∪ singleton(φ)) Logic.∧ Inconsistent(Γ ∪ singleton(¬ φ)) max-maximal : ∀{con : Consistent(Γ)} → (φ ∈ max Γ con) Logic.∨ ((¬ φ) ∈ max Γ con) max-maximal {Γ = Γ}{φ = φ}{con = con} with Logic.excluded-middle(Inconsistent(Γ ∪ singleton(φ))) ⦃ classical ⦄ ... | Logic.[∨]-introₗ Γφ⊥ = Logic.[∨]-introᵣ (Γ¬φ⊥ ↦ Logic.[⊥]-elim(con ([⊥]-intro ([¬]-elim Γ¬φ⊥) ([¬]-intro Γφ⊥)))) ... | Logic.[∨]-introᵣ ¬Γφ⊥ = Logic.[∨]-introₗ ¬Γφ⊥ max-no-bottom : ∀{con : Consistent(Γ)} → (⊥ ∉ max Γ con) max-no-bottom = apply(direct(Right [≡]-intro)) max-consistent-containment : ∀{con : Consistent(Γ)} → (φ ∈ max Γ con) → ((¬ φ) ∈ max Γ con) → Logic.⊥ max-consistent-containment {Γ = Γ}{φ = φ}{con = con} ¬Γφ⊥ ¬Γ¬φ⊥ = ¬Γφ⊥ ([⊥]-intro (direct (Right [≡]-intro)) {!!}) max-consistency-membership : ∀{con} → Consistent(Γ ∪ singleton(φ)) Logic.↔ (φ ∈ max Γ con) max-consistency-membership = Logic.[↔]-intro id id max-inconsistency-membership2 : ∀{con} → Inconsistent(Γ ∪ singleton(φ)) Logic.↔ (φ ∉ max Γ con) max-inconsistency-membership2 = Logic.[↔]-intro Logic.[¬¬]-elim apply test : ∀{con} → (φ ∉ max Γ con) → ((¬ φ) ∈ max Γ con) test {con = con} p = [⊢]-compose-consistency ([¬]-intro(Logic.[¬¬]-elim p)) con max-consistent : ∀{con : Consistent(Γ)} → Consistent(max Γ con) max-consistent {Γ = Γ} {con = con} = Logic.contrapositiveᵣ {!!} con {-max-consistent {Γ = Γ} {con = con} (direct x) = max-no-bottom{con = con} x max-consistent {Γ = Γ} {con = con} ([⊥]-intro p q) = {!max-consistent q!} max-consistent {Γ = Γ} {con = con} ([⊥]-elim p) = max-consistent{con = con} p max-consistent {Γ = Γ} {con = con} ([¬]-elim p) = {!!} max-consistent {Γ = Γ} {con = con} ([∧]-elimₗ p) = {!max-consistent !} max-consistent {Γ = Γ} {con = con} ([∧]-elimᵣ p) = {!!} max-consistent {Γ = Γ} {con = con} ([∨]-elim p q r) = {!!} max-consistent {Γ = Γ} {con = con} ([⟶]-elim p q) = {!!} max-consistent {Γ = Γ} {con = con} ([⟷]-elimₗ p q) = {!!} max-consistent {Γ = Γ} {con = con} ([⟷]-elimᵣ p q) = {!!}-} {- test2 : ∀{con} → ((¬ φ) ∈ max Γ con) → (φ ∉ max Γ con) test2 {con = con} p q = {!!} test3 : ∀{con} → (max Γ con ⊢ φ) → (Γ ⊢ φ) test3 {Γ = Γ} {φ} {con = con} (direct x) = {!!} test3 {Γ = Γ} {.⊤} {con = con} [⊤]-intro = {!!} test3 {Γ = Γ} {.⊥} {con = con} ([⊥]-intro p p₁) = {!!} test3 {Γ = Γ} {φ} {con = con} ([⊥]-elim p) = {!!} test3 {Γ = Γ} {.(¬ _)} {con = con} ([¬]-intro p) = {!!} test3 {Γ = Γ} {φ} {con = con} ([¬]-elim p) = {!!} test3 {Γ = Γ} {.(_ ∧ _)} {con = con} ([∧]-intro p p₁) = {!!} test3 {Γ = Γ} {φ} {con = con} ([∧]-elimₗ p) = {!!} test3 {Γ = Γ} {φ} {con = con} ([∧]-elimᵣ p) = {!!} test3 {Γ = Γ} {.(_ ∨ _)} {con = con} ([∨]-introₗ p) = {!!} test3 {Γ = Γ} {.(_ ∨ _)} {con = con} ([∨]-introᵣ p) = {!!} test3 {Γ = Γ} {φ} {con = con} ([∨]-elim p p₁ p₂) = {!!} test3 {Γ = Γ} {.(_ ⟶ _)} {con = con} ([⟶]-intro p) = {!!} test3 {Γ = Γ} {φ} {con = con} ([⟶]-elim p p₁) = {!!} test3 {Γ = Γ} {.(_ ⟷ _)} {con = con} ([⟷]-intro p p₁) = {!!} test3 {Γ = Γ} {φ} {con = con} ([⟷]-elimₗ p p₁) = {!!} test3 {Γ = Γ} {φ} {con = con} ([⟷]-elimᵣ p p₁) = {!!} -} max-inconsistency-membership : ∀{con} → Inconsistent(Γ ∪ singleton(φ)) Logic.↔ ((¬ φ) ∈ max Γ con) max-inconsistency-membership {Γ = Γ}{φ = φ}{con = con} = Logic.double-negation ⦗ Logic.[↔]-transitivity ⦘ₗ Logic.[¬]-unaryOperator max-consistency-membership ⦗ Logic.[↔]-transitivity ⦘ₗ Logic.[↔]-intro ll (Γ¬φ-incons ↦ Γφ-incons ↦ con([⊥]-intro ([¬]-elim Γφ-incons) ([¬]-intro (Logic.[¬¬]-elim Γ¬φ-incons)))) where ll : Logic.¬((Γ ∪ singleton(¬ φ)) ⊢ ⊥) → Logic.¬((Γ ∪ singleton(φ)) ⊢ ⊥) → Empty ll ¬φin φin = {!!} -- () ← ¬φin([⊥]-intro {!!} (direct (Right [≡]-intro))) -- con([⊥]-intro {!!} {!!}) -- -- {![⊥]-intro (direct φin) (direct ¬φin)!}) -- Logic.contrapositiveₗ ⦃ classical ⦄ (Γ¬φ-incons ↦ Γφ-incons ↦ con([⊥]-intro ([¬]-elim (Logic.[¬¬]-elim Γ¬φ-incons)) ([¬]-intro Γφ-incons))) max-superset : ∀{con : Consistent(Γ)} → (Γ ⊆ max Γ con) max-superset {con = con} {x = φ} φΓ Γφ⊥ = con ([⊥]-intro (direct φΓ) ([¬]-intro Γφ⊥)) -- TODO: Are there any easy ways to prove this? instance max-maximally-consistent : ∀{con : Consistent(Γ)} → MaximallyConsistent(max Γ con) MaximallyConsistent.consistent (max-maximally-consistent {con = con}) = max-consistent{con = con} MaximallyConsistent.element-maximal max-maximally-consistent p = {!!} -- max-consistency-membership {!Logic.contrapositive-variant2ₗ weaken-union-singleton!} -- max-consistency-membership {!p!} -- max-[⊢]-subset : ∀{con : Consistent(Γ)} → ((max Γ con ⊢_) ⊆ (Γ ⊢_)) -- max-[⊢]-subset {con = con} p = {!!} -} -} module _ where open NaturalDeduction private variable P : Type{ℓₚ} private variable φ ψ : Formula(P) module _ where private variable Γ Γ₁ Γ₂ : Formulas(P){ℓₚ} soundness : (Γ ⊢ φ) → (Γ ⊨ φ) soundness (direct Γφ) 𝔐Γ = 𝔐Γ(Γφ) soundness [⊤]-intro = const(Logic.[⊤]-intro) soundness ([⊥]-intro Γφ Γ¬φ) 𝔐Γ = (soundness Γ¬φ 𝔐Γ) (soundness Γφ 𝔐Γ) soundness ([⊥]-elim Γ⊥) 𝔐Γ = Logic.[⊥]-elim(soundness Γ⊥ 𝔐Γ) soundness {Γ = Γ}{φ = φ} ([¬]-intro Γφ⊥) 𝔐Γ 𝔐φ = soundness Γφ⊥ ([⊧₊]-strengthen {Γ₁ = Γ}{Γ₂ = singleton _} (𝔐Γ) (Logic.[↔]-to-[→] [⊧]-to-[⊧₊] 𝔐φ)) soundness {Γ = Γ}{φ = φ} ([¬]-elim Γ¬φ⊥) {𝔐} 𝔐Γ = Logic.[¬¬]-elim {P = (𝔐 ⊧ φ)} (¬𝔐φ ↦ soundness Γ¬φ⊥ ([⊧₊]-strengthen {Γ₁ = Γ}{Γ₂ = singleton _} 𝔐Γ (Logic.[↔]-to-[→] [⊧]-to-[⊧₊] ¬𝔐φ))) soundness ([∧]-intro Γφ Γψ) 𝔐Γ = (Logic.[∧]-intro (soundness Γφ 𝔐Γ) (soundness Γψ 𝔐Γ)) soundness ([∧]-elimₗ Γφψ) = Logic.[∧]-elimₗ ∘ (soundness Γφψ) soundness ([∧]-elimᵣ Γφψ) = Logic.[∧]-elimᵣ ∘ (soundness Γφψ) soundness ([∨]-introₗ Γφ) = Logic.[∨]-introₗ ∘ (soundness Γφ) soundness ([∨]-introᵣ Γψ) = Logic.[∨]-introᵣ ∘ (soundness Γψ) soundness {Γ = Γ}{φ = φ} ([∨]-elim {φ = ψ₁} {ψ₂} Γψ₁φ Γψ₂φ Γψ₁ψ₂) {𝔐} 𝔐Γ = (Logic.[∨]-elim (𝔐ψ₁ ↦ soundness Γψ₁φ ([⊧₊]-strengthen {Γ₁ = Γ}{Γ₂ = singleton _} (𝔐Γ) (Logic.[↔]-to-[→] [⊧]-to-[⊧₊] 𝔐ψ₁))) (𝔐ψ₂ ↦ soundness Γψ₂φ ([⊧₊]-strengthen {Γ₁ = Γ}{Γ₂ = singleton _} (𝔐Γ) (Logic.[↔]-to-[→] [⊧]-to-[⊧₊] 𝔐ψ₂))) (soundness Γψ₁ψ₂ 𝔐Γ) ) soundness {Γ = Γ} ([⟶]-intro Γφψ) 𝔐Γ = Logic.[→]-disjunctive-formᵣ (𝔐φ ↦ soundness Γφψ ([⊧₊]-strengthen {Γ₁ = Γ}{Γ₂ = singleton _} (𝔐Γ) (Logic.[↔]-to-[→] [⊧]-to-[⊧₊] 𝔐φ))) soundness ([⟶]-elim Γφ Γφψ) 𝔐Γ = Logic.[→]-disjunctive-formₗ((soundness Γφψ) 𝔐Γ) (soundness Γφ 𝔐Γ) soundness {Γ = Γ} ([⟷]-intro {φ = φ} {ψ = ψ} Γψφ Γφψ) {𝔐} 𝔐Γ with Logic.excluded-middle(𝔐 ⊧ φ) | Logic.excluded-middle(𝔐 ⊧ ψ) ... | Logic.[∨]-introₗ 𝔐φ | Logic.[∨]-introₗ 𝔐ψ = Logic.[∨]-introₗ (Logic.[∧]-intro 𝔐φ 𝔐ψ) ... | Logic.[∨]-introₗ 𝔐φ | Logic.[∨]-introᵣ ¬𝔐ψ = (Logic.[⊥]-elim ∘ ¬𝔐ψ ∘ soundness Γφψ) (Logic.[∨]-elim 𝔐Γ \{[≡]-intro → 𝔐φ}) ... | Logic.[∨]-introᵣ ¬𝔐φ | Logic.[∨]-introₗ 𝔐ψ = (Logic.[⊥]-elim ∘ ¬𝔐φ ∘ soundness Γψφ) (Logic.[∨]-elim 𝔐Γ \{[≡]-intro → 𝔐ψ}) ... | Logic.[∨]-introᵣ ¬𝔐φ | Logic.[∨]-introᵣ ¬𝔐ψ = Logic.[∨]-introᵣ (Logic.[∧]-intro ¬𝔐φ ¬𝔐ψ) soundness {Γ = Γ} ([⟷]-elimₗ {φ = φ} {ψ = ψ} Γψ Γφψ) 𝔐Γ with soundness Γφψ 𝔐Γ ... | Logic.[∨]-introₗ(Logic.[∧]-intro 𝔐φ 𝔐ψ ) = 𝔐φ ... | Logic.[∨]-introᵣ(Logic.[∧]-intro ¬𝔐φ ¬𝔐ψ) = Logic.[⊥]-elim(¬𝔐ψ(soundness Γψ 𝔐Γ)) soundness {Γ = Γ} ([⟷]-elimᵣ {φ = φ} {ψ = ψ} Γφ Γφψ) 𝔐Γ with soundness Γφψ 𝔐Γ ... | Logic.[∨]-introₗ(Logic.[∧]-intro 𝔐φ 𝔐ψ ) = 𝔐ψ ... | Logic.[∨]-introᵣ(Logic.[∧]-intro ¬𝔐φ ¬𝔐ψ) = Logic.[⊥]-elim(¬𝔐φ(soundness Γφ 𝔐Γ)) satisfiable-consistent : Satisfiable(Γ) → Consistent(Γ) satisfiable-consistent sat = Logic.contrapositiveᵣ soundness (\p → Logic.[↔]-to-[→] [⊨]-unsatisfiability p sat) consistency-of-∅ : Consistent{P = P}{ℓ = ℓ}(∅) consistency-of-∅ = satisfiable-consistent [∅]-satisfiable module _ where open import Data.Boolean.Stmt.Proofs open import Lang.Inspect modelSet : Model(P) → Formulas(P) modelSet(𝔐) = 𝔐 ⊧_ module _ {𝔐 : Model(P)} where modelSet-satisfiable : Satisfiable(modelSet(𝔐)) modelSet-satisfiable = Logic.[∃]-intro 𝔐 ⦃ id ⦄ modelSet-maximally-consistent : MaximallyConsistent(modelSet(𝔐)) MaximallyConsistent.consistent modelSet-maximally-consistent = satisfiable-consistent modelSet-satisfiable MaximallyConsistent.maximal modelSet-maximally-consistent = element-intro p where p : ConsistentElementMaximality(modelSet(𝔐)) p {φ} cons with TruthTable.eval 𝔐 φ | inspect (TruthTable.eval 𝔐) φ ... | 𝑇 | intro eval-𝑇 = TruthTable.eval-to-models {φ = φ} (Logic.[↔]-to-[←] IsTrue.is-𝑇 eval-𝑇) ... | 𝐹 | intro eval-𝐹 = Logic.[⊥]-elim (cons ([⊥]-intro (direct (Right [≡]-intro)) (weaken Left (direct (TruthTable.eval-to-models {φ = ¬ φ} (Logic.[↔]-to-[←] IsTrue.is-𝑇 ([≡]-with(BoolOp.¬) eval-𝐹))))))) {-maximally-consistent-is-modelSet : MaximallyConsistent(Γ) → (Γ ≡ₛ modelSet(𝔐)) maximally-consistent-is-modelSet maxCon {• x} = Logic.[↔]-intro {!Logic.[↔]-to-[←] Logic.decide-is-true!} {!Logic.[↔]-to-[→] Logic.decide-is-true!} maximally-consistent-is-modelSet maxCon {⊤} = [⊤]-maximal-membership ⦃ maxCon ⦄ maximally-consistent-is-modelSet maxCon {⊥} = [⊥]-maximal-membership ⦃ maxCon ⦄ maximally-consistent-is-modelSet maxCon {¬ φ} = Logic.[↔]-transitivity ([¬]-maximal-membership ⦃ maxCon ⦄) (Logic.[¬]-unaryOperator (maximally-consistent-is-modelSet maxCon)) maximally-consistent-is-modelSet maxCon {φ ∧ ψ} = Logic.[↔]-transitivity ([∧]-maximal-membership ⦃ maxCon ⦄) (Logic.[∧]-binaryOperator (maximally-consistent-is-modelSet maxCon) (maximally-consistent-is-modelSet maxCon)) maximally-consistent-is-modelSet maxCon {φ ∨ ψ} = Logic.[↔]-transitivity ([∨]-maximal-membership ⦃ maxCon ⦄) (Logic.[∨]-binaryOperator (maximally-consistent-is-modelSet maxCon) (maximally-consistent-is-modelSet maxCon)) maximally-consistent-is-modelSet maxCon {φ ⟶ ψ} = {!!} maximally-consistent-is-modelSet maxCon {φ ⟷ ψ} = {!!}-} term-model : Formulas(P){ℓ} → Model(P) term-model(Γ) p = decide(0)((• p) ∈ Γ) module _ ⦃ countable-P : CountablyInfinite(P) ⦄ where private variable Γ Γ₁ Γ₂ : Formulas(P){ℓₚ} term-model-of-max-proof : (con : Consistent(Γ)) → (max Γ ≡ₛ (term-model(max Γ) ⊧_)) term-model-of-max-proof {Γ = Γ} con = Logic.[∃]-proof(MaximallyConsistent.equal-model-existence (max-maximally-consistent con)) consistent-satisfiable : Consistent(Γ) → Satisfiable(Γ) Logic.∃.witness (consistent-satisfiable {Γ = Γ} con) = term-model(max Γ) Logic.∃.proof (consistent-satisfiable {Γ = Γ} con) {γ} = (Logic.[↔]-to-[→] (term-model-of-max-proof {Γ = Γ} con {γ})) ∘ max-superset completeness : (Γ ⊨ φ) → (Γ ⊢ φ) completeness {Γ = Γ}{φ = φ} = (Logic.[↔]-to-[←] [⊢]-derivability-inconsistency) ∘ (Logic.[↔]-to-[←] Logic.contrapositive-variant2 consistent-satisfiable) ∘ (Logic.[↔]-to-[→] [⊨]-entailment-unsatisfiability)
61.776097
478
0.587966
0340d5fa639aea8142c22b58c731f9292b40d667
388
agda
Agda
src/ProcessSyntax.agda
peterthiemann/definitional-session
c2213909c8a308fb1c1c1e4e789d65ba36f6042c
[ "BSD-3-Clause" ]
9
2019-01-19T16:33:27.000Z
2021-01-18T08:10:14.000Z
src/ProcessSyntax.agda
peterthiemann/definitional-session
c2213909c8a308fb1c1c1e4e789d65ba36f6042c
[ "BSD-3-Clause" ]
null
null
null
src/ProcessSyntax.agda
peterthiemann/definitional-session
c2213909c8a308fb1c1c1e4e789d65ba36f6042c
[ "BSD-3-Clause" ]
null
null
null
module ProcessSyntax where open import Data.List open import Typing open import Syntax -- processes data Proc (Φ : TCtx) : Set where exp : (e : Expr Φ TUnit) → Proc Φ par : ∀ {Φ₁ Φ₂} → (sp : Split Φ Φ₁ Φ₂) → (P₁ : Proc Φ₁) → (P₂ : Proc Φ₂) → Proc Φ res : (s : SType) → (P : Proc (TChan (SType.force s) ∷ TChan (SType.force (dual s)) ∷ Φ)) → Proc Φ
16.869565
75
0.564433
300e38dd809ed000f50b672102eaca9121d8bf0e
541
agda
Agda
test/Fail/Issue2081.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue2081.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue2081.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2016-07-08, issue reported by Nisse module Issue2081 where module M where private Private : Set₁ Private = Set -- The local module should be private as well! module Public where -- The definitions inside this module should not be private -- unless declared so explicitly! Public : Set₁ Public = Set private Bla = Public -- should work! -- This `where` should not give a 'useless private' error: where open Public module Pu = M.Public -- should fail!
21.64
67
0.643253
04f6ec7a637899e01a3a2632636e4d633005f1e5
374
agda
Agda
Cubical/Data/NatMinusOne/Properties.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Data/NatMinusOne/Properties.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Data/NatMinusOne/Properties.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --no-exact-split --safe #-} module Cubical.Data.NatMinusOne.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Univalence open import Cubical.Data.Nat open import Cubical.Data.NatMinusOne.Base open import Cubical.Reflection.StrictEquiv -1+Path : ℕ ≡ ℕ₋₁ -1+Path = ua e where unquoteDecl e = declStrictEquiv e -1+_ 1+_
26.714286
48
0.775401
4125c49da63c8908022c669761f5932b188b379b
408
agda
Agda
test/fail/Issue291b.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T04:41:05.000Z
2019-11-27T04:41:05.000Z
test/fail/Issue291b.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
test/fail/Issue291b.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
-- Andreas, 2011-04-14 -- {-# OPTIONS -v tc.cover:20 -v tc.lhs.unify:20 #-} module Issue291b where open import Imports.Coinduction data _≡_ {A : Set}(a : A) : A -> Set where refl : a ≡ a data RUnit : Set where runit : ∞ RUnit -> RUnit j : (u : RUnit) -> u ≡ runit (♯ u) -> Set j u () -- needs to fail because of a non strongly rigid occurrence -- ♯ does not count as a constructor, and that is good!
24
59
0.629902
35f48f4557aabc17d6c1733ac10e28896c65c889
6,092
agda
Agda
Cubical/HITs/Pushout/KrausVonRaumer.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
1
2022-02-05T01:25:26.000Z
2022-02-05T01:25:26.000Z
Cubical/HITs/Pushout/KrausVonRaumer.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
Cubical/HITs/Pushout/KrausVonRaumer.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
{- An induction principle for paths in a pushout, described in Kraus and von Raumer, "Path Spaces of Higher Inductive Types in Homotopy Type Theory" https://arxiv.org/abs/1901.06022 -} {-# OPTIONS --safe #-} module Cubical.HITs.Pushout.KrausVonRaumer where open import Cubical.Foundations.Everything open import Cubical.Functions.Embedding open import Cubical.Data.Sigma open import Cubical.Data.Nat open import Cubical.Data.Sum as ⊎ open import Cubical.HITs.PropositionalTruncation as Trunc open import Cubical.HITs.Pushout.Base as ⊔ open import Cubical.HITs.Pushout.Properties private variable ℓ ℓ' ℓ'' ℓ''' : Level A : Type ℓ B : Type ℓ' C : Type ℓ'' private interpolate : {x y z : A} (q : y ≡ z) → PathP (λ i → x ≡ q i → x ≡ z) (_∙ q) (idfun _) interpolate q i p j = hcomp (λ k → λ { (j = i0) → p i0 ; (j = i1) → q (i ∨ k) ; (i = i1) → p j }) (p j) interpolateCompPath : {x y : A} (p : x ≡ y) {z : A} (q : y ≡ z) → (λ i → interpolate q i (λ j → compPath-filler p q i j)) ≡ refl interpolateCompPath p = J (λ z q → (λ i → interpolate q i (λ j → compPath-filler p q i j)) ≡ refl) (homotopySymInv (λ p i j → compPath-filler p refl (~ i) j) p) module ElimL {f : A → B} {g : A → C} {b₀ : B} (P : ∀ b → Path (Pushout f g) (inl b₀) (inl b) → Type ℓ''') (Q : ∀ c → Path (Pushout f g) (inl b₀) (inr c) → Type ℓ''') (r : P b₀ refl) (e : (a : A) (q : inl b₀ ≡ inl (f a)) → P (f a) q ≃ Q (g a) (q ∙ push a)) where Codes : (d : Pushout f g) (q : inl b₀ ≡ d) → Type ℓ''' Codes (inl b) q = P b q Codes (inr c) q = Q c q Codes (push a i) q = Glue (Q (g a) (interpolate (push a) i q)) (λ { (i = i0) → _ , e a q ; (i = i1) → _ , idEquiv (Q (g a) q) }) elimL : ∀ b q → P b q elimL _ = J Codes r elimR : ∀ c q → Q c q elimR _ = J Codes r refl-β : elimL b₀ refl ≡ r refl-β = transportRefl _ push-β : (a : A) (q : inl b₀ ≡ inl (f a)) → elimR (g a) (q ∙ push a) ≡ e a q .fst (elimL (f a) q) push-β a q = J-∙ Codes r q (push a) ∙ fromPathP (subst (λ α → PathP (λ i → Q (g a) (α i)) (e a q .fst (elimL (f a) q)) (e a q .fst (elimL (f a) q))) (interpolateCompPath q (push a) ⁻¹) refl) module ElimR {f : A → B} {g : A → C} {c₀ : C} (P : ∀ b → Path (Pushout f g) (inr c₀) (inl b) → Type ℓ''') (Q : ∀ c → Path (Pushout f g) (inr c₀) (inr c) → Type ℓ''') (r : Q c₀ refl) (e : (a : A) (q : inr c₀ ≡ inl (f a)) → P (f a) q ≃ Q (g a) (q ∙ push a)) where Codes : (d : Pushout f g) (q : inr c₀ ≡ d) → Type ℓ''' Codes (inl b) q = P b q Codes (inr c) q = Q c q Codes (push a i) q = Glue (Q (g a) (interpolate (push a) i q)) (λ { (i = i0) → _ , e a q ; (i = i1) → _ , idEquiv (Q (g a) q) }) elimL : ∀ b q → P b q elimL _ = J Codes r elimR : ∀ c q → Q c q elimR _ = J Codes r refl-β : elimR c₀ refl ≡ r refl-β = transportRefl _ push-β : (a : A) (q : inr c₀ ≡ inl (f a)) → elimR (g a) (q ∙ push a) ≡ e a q .fst (elimL (f a) q) push-β a q = J-∙ Codes r q (push a) ∙ fromPathP (subst (λ α → PathP (λ i → Q (g a) (α i)) (e a q .fst (elimL (f a) q)) (e a q .fst (elimL (f a) q))) (interpolateCompPath q (push a) ⁻¹) refl) -- Example application: pushouts preserve embeddings isEmbeddingInr : (f : A → B) (g : A → C) → isEmbedding f → isEmbedding (⊔.inr {f = f} {g = g}) isEmbeddingInr f g fEmb c₀ c₁ = isoToIsEquiv (iso _ (fst ∘ bwd c₁) (snd ∘ bwd c₁) bwdCong) where Q : ∀ c → ⊔.inr c₀ ≡ ⊔.inr c → Type _ Q _ q = fiber (cong ⊔.inr) q P : ∀ b → ⊔.inr c₀ ≡ ⊔.inl b → Type _ P b p = Σ[ u ∈ fiber f b ] Q _ (p ∙ cong ⊔.inl (u .snd ⁻¹) ∙ push (u .fst)) module Bwd = ElimR P Q (refl , refl) (λ a p → subst (P (f a) p ≃_) (cong (λ w → fiber (cong ⊔.inr) (p ∙ w)) (lUnit (push a) ⁻¹)) (Σ-contractFst (inhProp→isContr (a , refl) (isEmbedding→hasPropFibers fEmb (f a))))) bwd : ∀ c → (t : ⊔.inr c₀ ≡ ⊔.inr c) → fiber (cong ⊔.inr) t bwd = Bwd.elimR bwdCong : ∀ {c} → (r : c₀ ≡ c) → bwd c (cong ⊔.inr r) .fst ≡ r bwdCong = J (λ c r → bwd c (cong ⊔.inr r) .fst ≡ r) (cong fst Bwd.refl-β) -- Further Application: Pushouts of emedding-spans of n-Types are n-Types, for n≥0 module _ (f : A → B) (g : A → C) where inlrJointlySurjective : (z : Pushout f g) → ∥ Σ[ x ∈ (B ⊎ C) ] (⊎.rec inl inr x) ≡ z ∥ inlrJointlySurjective = elimProp _ (λ _ → isPropPropTrunc) (λ b → ∣ ⊎.inl b , refl ∣) (λ c → ∣ ⊎.inr c , refl ∣) preserveHLevelEmbedding : {n : HLevel} → isEmbedding f → isEmbedding g → isOfHLevel (2 + n) B → isOfHLevel (2 + n) C → isOfHLevel (2 + n) (Pushout f g) preserveHLevelEmbedding {n = n} fEmb gEmb isOfHLB isOfHLC = isOfHLevelΩ→isOfHLevel n ΩHLevelPushout where isEmbInr = isEmbeddingInr f g fEmb isEmbInrSwitched = isEmbeddingInr g f gEmb equivΩC : {x : Pushout f g} (c : C) (p : inr c ≡ x) → (c ≡ c) ≃ (x ≡ x) equivΩC c p = compEquiv (_ , isEmbInr c c) (conjugatePathEquiv p) equivΩB : {x : Pushout f g} (b : B) (p : inl b ≡ x) → (b ≡ b) ≃ (x ≡ x) equivΩB b p = compEquiv (compEquiv (_ , isEmbInrSwitched b b) (congEquiv pushoutSwitchEquiv)) (conjugatePathEquiv p) ΩHLevelPushout : (x : Pushout f g) → isOfHLevel (suc n) (x ≡ x) ΩHLevelPushout x = Trunc.elim (λ _ → isPropIsOfHLevel {A = (x ≡ x)} (suc n)) (λ {(⊎.inl b , p) → isOfHLevelRespectEquiv (suc n) (equivΩB b p) (isOfHLB b b); (⊎.inr c , p) → isOfHLevelRespectEquiv (suc n) (equivΩC c p) (isOfHLC c c)}) (inlrJointlySurjective x)
30.613065
100
0.498194
049caf244712ec7e7bd077974882b9b0985d97af
498
agda
Agda
test/Succeed/Issue2727-2.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2727-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2727-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Agda.Builtin.Equality using (_≡_; refl) record ⊤ : Set where no-eta-equality constructor tt data Box (A : Set) : Set where [_] : A → Box A Unit : Set Unit = Box ⊤ F : Unit → Set → Set F [ _ ] x = x G : {P : Unit → Set} → ((x : ⊤) → P [ x ]) → ((x : Unit) → P x) G f [ x ] = f x record R : Set₁ where no-eta-equality field f : (x : Unit) → Box (F x ⊤) data ⊥ : Set where r : R r = record { f = G [_] } open R r H : ⊥ → Set₁ H _ with refl {x = tt} ... | _ = Set
14.647059
63
0.512048
34e78c8d62f48f3ecfa433cfae100e4bd92e618a
11,086
agda
Agda
benchmark/cwf/Setoid.agda
asr/agda-kanso
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
[ "MIT" ]
1
2019-11-27T07:26:06.000Z
2019-11-27T07:26:06.000Z
benchmark/cwf/Setoid.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
benchmark/cwf/Setoid.agda
np/agda-git-experiment
20596e9dd9867166a64470dd24ea68925ff380ce
[ "MIT" ]
null
null
null
{-# OPTIONS --no-positivity-check --no-termination-check #-} -- A universe setoids module Setoid where import Chain record True : Set where data False : Set where Rel : Set -> Set1 Rel A = A -> A -> Set Pred : Set -> Set1 Pred A = A -> Set Resp : {A : Set} -> Rel A -> {B : Set} -> Rel B -> Pred (A -> B) Resp _R_ _S_ f = forall x y -> x R y -> f x S f y mutual infix 40 _=El=_ _=S=_ _=Fam=_ infix 60 _!_ data Setoid : Set where nat : Setoid Π : (A : Setoid)(F : Fam A) -> Setoid Σ : (A : Setoid)(F : Fam A) -> Setoid data Fam (A : Setoid) : Set where fam : (F : El A -> Setoid) -> Resp _=El=_ _=S=_ F -> Fam A data El : Setoid -> Set where zero : El nat suc : El nat -> El nat ƛ : {A : Setoid}{F : Fam A} (f : (x : El A) -> El (F ! x)) -> ((x y : El A) -> x =El= y -> f x =El= f y) -> El (Π A F) _,_ : {A : Setoid}{F : Fam A}(x : El A) -> El (F ! x) -> El (Σ A F) data _=S=_ : (A B : Setoid) -> Set where eqNat : nat =S= nat eqΠ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂} -> A₂ =S= A₁ -> F₁ =Fam= F₂ -> Π A₁ F₁ =S= Π A₂ F₂ eqΣ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂} -> A₁ =S= A₂ -> F₁ =Fam= F₂ -> Σ A₁ F₁ =S= Σ A₂ F₂ data _=El=_ : {A B : Setoid} -> El A -> El B -> Set where eqInNat : {n : El nat} -> n =El= n eqInΠ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂} {f₁ : (x : El A₁) -> El (F₁ ! x)} {pf₁ : (x y : El A₁) -> x =El= y -> f₁ x =El= f₁ y} {f₂ : (x : El A₂) -> El (F₂ ! x)} -> {pf₂ : (x y : El A₂) -> x =El= y -> f₂ x =El= f₂ y} -> A₂ =S= A₁ -> ((x : El A₁)(y : El A₂) -> x =El= y -> f₁ x =El= f₂ y) -> ƛ f₁ pf₁ =El= ƛ f₂ pf₂ eqInΣ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂} {x₁ : El A₁}{y₁ : El (F₁ ! x₁)} {x₂ : El A₂}{y₂ : El (F₂ ! x₂)} -> F₁ =Fam= F₂ -> x₁ =El= x₂ -> y₁ =El= y₂ -> (x₁ , y₁) =El= (x₂ , y₂) data _=Fam=_ {A B : Setoid}(F : Fam A)(G : Fam B) : Set where eqFam : B =S= A -> (forall x y -> x =El= y -> F ! x =S= G ! y) -> F =Fam= G _!_ : {A : Setoid} -> Fam A -> El A -> Setoid fam F _ ! x = F x -- Inversions famEqDom : {A B : Setoid}{F : Fam A}{G : Fam B} -> F =Fam= G -> B =S= A famEqDom (eqFam p _) = p famEqCodom : {A B : Setoid}{F : Fam A}{G : Fam B} -> F =Fam= G -> (x : El A)(y : El B) -> x =El= y -> F ! x =S= G ! y famEqCodom (eqFam _ p) = p eqΠ-inv₁ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂} -> Π A₁ F₁ =S= Π A₂ F₂ -> A₂ =S= A₁ eqΠ-inv₁ (eqΠ p _) = p eqΠ-inv₂ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂} -> Π A₁ F₁ =S= Π A₂ F₂ -> F₁ =Fam= F₂ eqΠ-inv₂ (eqΠ _ p) = p eqΣ-inv₁ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂} -> Σ A₁ F₁ =S= Σ A₂ F₂ -> A₁ =S= A₂ eqΣ-inv₁ (eqΣ p _) = p eqΣ-inv₂ : {A₁ A₂ : Setoid}{F₁ : Fam A₁}{F₂ : Fam A₂} -> Σ A₁ F₁ =S= Σ A₂ F₂ -> F₁ =Fam= F₂ eqΣ-inv₂ (eqΣ _ p) = p -- Equivalence proofs and casts mutual -- _=Fam=_ is an equivalence =Fam=-refl : {A : Setoid}{F : Fam A} -> F =Fam= F =Fam=-refl {F = fam _ p} = eqFam =S=-refl p =Fam=-sym : {A B : Setoid}{F : Fam A}{G : Fam B} -> F =Fam= G -> G =Fam= F =Fam=-sym (eqFam B=A F=G) = eqFam (=S=-sym B=A) \x y x=y -> =S=-sym (F=G _ _ (=El=-sym x=y)) =Fam=-trans : {A B C : Setoid}{F : Fam A}{G : Fam B}{H : Fam C} -> F =Fam= G -> G =Fam= H -> F =Fam= H =Fam=-trans (eqFam B=A F=G) (eqFam C=B G=H) = eqFam (=S=-trans C=B B=A) \x y x=y -> =S=-trans (F=G x (B=A << x) (cast-id _)) (G=H _ y (=El=-trans (=El=-sym (cast-id _)) x=y)) -- _=S=_ is an equivalence =S=-refl : {A : Setoid} -> A =S= A =S=-refl {nat} = eqNat =S=-refl {Π A F} = eqΠ =S=-refl =Fam=-refl =S=-refl {Σ A F} = eqΣ =S=-refl =Fam=-refl =S=-sym : {A B : Setoid} -> A =S= B -> B =S= A =S=-sym eqNat = eqNat =S=-sym (eqΠ pA pF) = eqΠ (=S=-sym pA) (=Fam=-sym pF) =S=-sym (eqΣ pA pF) = eqΣ (=S=-sym pA) (=Fam=-sym pF) =S=-trans : {A B C : Setoid} -> A =S= B -> B =S= C -> A =S= C =S=-trans eqNat eqNat = eqNat =S=-trans (eqΠ B=A F=G) (eqΠ C=B G=H) = eqΠ (=S=-trans C=B B=A) (=Fam=-trans F=G G=H) =S=-trans (eqΣ A=B F=G) (eqΣ B=C G=H) = eqΣ (=S=-trans A=B B=C) (=Fam=-trans F=G G=H) -- _=El=_ is an equivalence =El=-refl : {A : Setoid}{x : El A} -> x =El= x =El=-refl {nat} = eqInNat =El=-refl {Π A F}{ƛ f pf} = eqInΠ =S=-refl pf =El=-refl {Σ A F}{x , y} = eqInΣ =Fam=-refl =El=-refl =El=-refl =El=-sym : {A B : Setoid}{x : El A}{y : El B} -> x =El= y -> y =El= x =El=-sym eqInNat = eqInNat =El=-sym (eqInΠ B=A p) = eqInΠ (=S=-sym B=A) \x y x=y -> =El=-sym (p y x (=El=-sym x=y)) =El=-sym (eqInΣ pF px py) = eqInΣ (=Fam=-sym pF) (=El=-sym px) (=El=-sym py) =El=-trans : {A B C : Setoid}{x : El A}{y : El B}{z : El C} -> x =El= y -> y =El= z -> x =El= z =El=-trans eqInNat eqInNat = eqInNat =El=-trans (eqInΠ B=A f=g) (eqInΠ C=B g=h) = eqInΠ (=S=-trans C=B B=A) \x y x=y -> =El=-trans (f=g x (B=A << x) (cast-id _)) (g=h _ y (=El=-trans (=El=-sym (cast-id _)) x=y)) =El=-trans (eqInΣ F₁=F₂ x₁=x₂ y₁=y₂) (eqInΣ F₂=F₃ x₂=x₃ y₂=y₃) = eqInΣ (=Fam=-trans F₁=F₂ F₂=F₃) (=El=-trans x₁=x₂ x₂=x₃) (=El=-trans y₁=y₂ y₂=y₃) -- Casting. Important: don't look at the proof! infix 50 _<<_ _>>_ _<<_ : {A B : Setoid} -> A =S= B -> El B -> El A _<<_ {nat}{Π _ _} () _ _<<_ {nat}{Σ _ _} () _ _<<_ {Π _ _}{nat} () _ _<<_ {Π _ _}{Σ _ _} () _ _<<_ {Σ _ _}{nat} () _ _<<_ {Σ _ _}{Π _ _} () _ _<<_ {nat}{nat} p x = x _<<_ {Π A₁ F₁}{Π A₂ F₂} p (ƛ f pf) = ƛ g pg where g : (x : El A₁) -> El (F₁ ! x) g x = let A₂=A₁ = eqΠ-inv₁ p F₁=F₂ = famEqCodom (eqΠ-inv₂ p) x _ (cast-id _) in F₁=F₂ << f (A₂=A₁ << x) pg : (x y : El A₁) -> x =El= y -> g x =El= g y pg x y x=y = cast-irr _ _ (pf _ _ (cast-irr _ _ x=y)) _<<_ {Σ A₁ F₁}{Σ A₂ F₂} p (x , y) = eqΣ-inv₁ p << x , F₁=F₂ << y where F₁=F₂ : F₁ ! (eqΣ-inv₁ p << x) =S= F₂ ! x F₁=F₂ = famEqCodom (eqΣ-inv₂ p) _ _ (=El=-sym (cast-id _)) _>>_ : {A B : Setoid} -> Fam A -> A =S= B -> Fam B fam F pF >> A=B = fam G pG where G : El _ -> Setoid G y = F (A=B << y) pG : forall x y -> x =El= y -> G x =S= G y pG x y x=y = pF _ _ (cast-irr _ _ x=y) cast-id : {A B : Setoid}{x : El A}(p : B =S= A) -> x =El= p << x cast-id eqNat = eqInNat cast-id {x = x , y } (eqΣ A=B F=G) = eqInΣ (=Fam=-sym F=G) (cast-id _) (cast-id _) cast-id {x = ƛ f pf} (eqΠ B=A F=G) = eqInΠ (=S=-sym B=A) \x y x=y -> proof f x ≡ f (_ << y) by pf _ _ (=El=-trans x=y (cast-id _)) ≡ _ << f (_ << y) by cast-id _ qed where open Chain El _=El=_ (\x -> =El=-refl) (\x y z -> =El=-trans) cast-irr : {A₁ A₂ B₁ B₂ : Setoid}{x : El A₁}{y : El A₂} (p₁ : B₁ =S= A₁)(p₂ : B₂ =S= A₂) -> x =El= y -> p₁ << x =El= p₂ << y cast-irr {x = x}{y = y} p q x=y = proof p << x ≡ x by =El=-sym (cast-id _) ≡ y by x=y ≡ q << y by cast-id _ qed where open Chain El _=El=_ (\x -> =El=-refl) (\x y z -> =El=-trans) -- Let's do some overloading data EqFam : Set -> Set where el : EqFam Setoid setoid : EqFam True fam : EqFam Setoid [_] : {I : Set} -> EqFam I -> I -> Set [ el ] A = El A [ setoid ] _ = Setoid [ fam ] A = Fam A _==_ : {I : Set}{eqf : EqFam I}{i j : I} -> [ eqf ] i -> [ eqf ] j -> Set _==_ {eqf = el } x y = x =El= y _==_ {eqf = setoid} A B = A =S= B _==_ {eqf = fam } F G = F =Fam= G refl : {I : Set}{eqf : EqFam I}{i : I}{x : [ eqf ] i} -> x == x refl {eqf = el} = =El=-refl refl {eqf = setoid} = =S=-refl refl {eqf = fam} = =Fam=-refl sym : {I : Set}{eqf : EqFam I}{i j : I}{x : [ eqf ] i}{y : [ eqf ] j} -> x == y -> y == x sym {eqf = el} = =El=-sym sym {eqf = setoid} = =S=-sym sym {eqf = fam} = =Fam=-sym trans : {I : Set}{eqf : EqFam I}{i j k : I}{x : [ eqf ] i}{y : [ eqf ] j}{z : [ eqf ] k} -> x == y -> y == z -> x == z trans {eqf = el} = =El=-trans trans {eqf = setoid} = =S=-trans trans {eqf = fam} = =Fam=-trans open module EqChain {I : Set}{eqf : EqFam I} = Chain ([ eqf ]) _==_ (\x -> refl) (\x y z -> trans) homo : {A B : Setoid}{x : El A}{y : El B} -> x == y -> A == B homo eqInNat = eqNat homo (eqInΠ B=A p) = eqΠ B=A (eqFam B=A \x y x=y -> homo (p x y x=y)) homo (eqInΣ F=G p q) = eqΣ (homo p) F=G cast-id' : {A B C : Setoid}{x : El A}{y : El B}(p : C == B) -> x == y -> x == p << y cast-id' C=B x=y = trans x=y (cast-id _) -- Some helper stuff K : {A : Setoid} -> Setoid -> Fam A K B = fam (\_ -> B) (\_ _ _ -> refl) infixr 20 _==>_ infixl 70 _·_ _∘_ _○_ infixl 90 _#_ !-cong : {A B : Setoid}(F : Fam A)(G : Fam B){x : El A}{y : El B} -> F == G -> x == y -> F ! x == G ! y !-cong F G (eqFam B=A F=G) x=y = F=G _ _ x=y !-cong-R : {A : Setoid}(F : Fam A){x y : El A} -> x == y -> F ! x == F ! y !-cong-R F x=y = !-cong F F refl x=y _==>_ : Setoid -> Setoid -> Setoid A ==> B = Π A (K B) _#_ : {A : Setoid}{F : Fam A} -> El (Π A F) -> (x : El A) -> El (F ! x) ƛ f _ # x = f x #-cong : {A B : Setoid}{F : Fam A}{G : Fam B} (f : El (Π A F))(g : El (Π B G)){x : El A}{y : El B} -> f == g -> x == y -> f # x == g # y #-cong ._ ._ (eqInΠ _ f=g) x=y = f=g _ _ x=y #-cong-R : {A : Setoid}{F : Fam A}(f : El (Π A F)){x y : El A} -> x == y -> f # x == f # y #-cong-R f p = #-cong f f refl p id : {A : Setoid} -> El (A ==> A) id = ƛ (\x -> x) (\_ _ p -> p) -- Family composition _○_ : {A B : Setoid} -> Fam A -> El (B ==> A) -> Fam B F ○ f = fam (\x -> F ! (f # x)) (\x y x=y -> !-cong-R F (#-cong-R f x=y)) lem-○-id : {A : Setoid}{F : Fam A} -> F ○ id == F lem-○-id {F = F} = eqFam refl \x y x=y -> !-cong-R F x=y _∘_ : {A B : Setoid}{F : Fam B} -> El (Π B F) -> (g : El (A ==> B)) -> El (Π A (F ○ g)) f ∘ g = ƛ (\x -> f # (g # x)) \x y x=y -> #-cong-R f (#-cong-R g x=y) lem-∘-id : {A : Setoid}{F : Fam A}(f : El (Π A F)) -> f ∘ id == f lem-∘-id (ƛ f pf) = eqInΠ refl pf lem-id-∘ : {A B : Setoid}(f : El (A ==> B)) -> id ∘ f == f lem-id-∘ (ƛ f pf) = eqInΠ refl pf -- Simply type composition (not quite a special case of ∘ because of proof relevance) _·_ : {A B C : Setoid} -> El (B ==> C) -> El (A ==> B) -> El (A ==> C) f · g = eqΠ refl (eqFam refl \_ _ _ -> refl) << f ∘ g fst : {A : Setoid}{F : Fam A} -> El (Σ A F) -> El A fst (x , y) = x snd : {A : Setoid}{F : Fam A}(p : El (Σ A F)) -> El (F ! fst p) snd (x , y) = y fst-eq : {A B : Setoid}{F : Fam A}{G : Fam B} {x : El (Σ A F)}{y : El (Σ B G)} -> x == y -> fst x == fst y fst-eq (eqInΣ _ x₁=x₂ _) = x₁=x₂ snd-eq : {A B : Setoid}{F : Fam A}{G : Fam B} {x : El (Σ A F)}{y : El (Σ B G)} -> x == y -> snd x == snd y snd-eq (eqInΣ _ _ y₁=y₂) = y₁=y₂ η : {A : Setoid}{F : Fam A}(f : El (Π A F)){pf : (x y : El A) -> x == y -> f # x == f # y} -> f == ƛ {F = F} (_#_ f) pf η (ƛ f pf) = eqInΠ refl pf
34.321981
94
0.448043
34739e6ab74a6b511e55b6d89ccaf420bad73a4b
16,755
agda
Agda
Cubical/Structures/Record.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Structures/Record.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
Cubical/Structures/Record.agda
kiana-S/univalent-foundations
8bdb0766260489f9c89a14f4c0f2ad26e5190dec
[ "MIT" ]
null
null
null
{- Automatically generating proofs of UnivalentStr for records -} {-# OPTIONS --cubical --no-exact-split --safe #-} module Cubical.Structures.Record where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.SIP open import Cubical.Foundations.Structure open import Cubical.Foundations.Univalence open import Cubical.Data.Sigma open import Cubical.Data.Nat open import Cubical.Data.List as List open import Cubical.Data.Vec as Vec open import Cubical.Data.Bool open import Cubical.Data.Maybe open import Cubical.Data.Sum open import Cubical.Structures.Auto import Cubical.Structures.Macro as M import Agda.Builtin.Reflection as R open import Cubical.Reflection.Base -- Magic number private FUEL = 10000 -- Types for specifying inputs to the tactics data AutoFieldSpec : Typeω where autoFieldSpec : ∀ {ℓ ℓ₁ ℓ₂} (R : Type ℓ → Type ℓ₁) {S : Type ℓ → Type ℓ₂} → ({X : Type ℓ} → R X → S X) → AutoFieldSpec module _ {ℓ ℓ₁ ℓ₁'} where mutual data AutoFields (R : Type ℓ → Type ℓ₁) (ι : StrEquiv R ℓ₁') : Typeω where fields: : AutoFields R ι _data[_∣_] : (fs : AutoFields R ι) → ∀ {ℓ₂ ℓ₂'} {S : Type ℓ → Type ℓ₂} {ι' : StrEquiv S ℓ₂'} → (f : {X : Type ℓ} → R X → S X) → ({A B : TypeWithStr ℓ R} {e : typ A ≃ typ B} → ι A B e → ι' (map-snd f A) (map-snd f B) e) → AutoFields R ι _prop[_∣_] : (fs : AutoFields R ι) → ∀ {ℓ₂} {P : (X : Type ℓ) → GatherFields fs X → Type ℓ₂} → ({X : Type ℓ} (r : R X) → P X (projectFields fs r)) → isPropProperty R ι fs P → AutoFields R ι GatherFieldsLevel : {R : Type ℓ → Type ℓ₁} {ι : StrEquiv R ℓ₁'} → AutoFields R ι → Level GatherFieldsLevel fields: = ℓ-zero GatherFieldsLevel (_data[_∣_] fs {ℓ₂ = ℓ₂} _ _) = ℓ-max (GatherFieldsLevel fs) ℓ₂ GatherFieldsLevel (_prop[_∣_] fs {ℓ₂ = ℓ₂} _ _) = ℓ-max (GatherFieldsLevel fs) ℓ₂ GatherFields : {R : Type ℓ → Type ℓ₁} {ι : StrEquiv R ℓ₁'} (dat : AutoFields R ι) → Type ℓ → Type (GatherFieldsLevel dat) GatherFields fields: X = ⊤ GatherFields (_data[_∣_] fs {S = S} _ _) X = GatherFields fs X × S X GatherFields (_prop[_∣_] fs {P = P} _ _) X = Σ[ s ∈ GatherFields fs X ] (P X s) projectFields : {R : Type ℓ → Type ℓ₁} {ι : StrEquiv R ℓ₁'} (fs : AutoFields R ι) → {X : Type ℓ} → R X → GatherFields fs X projectFields fields: = _ projectFields (fs data[ f ∣ _ ]) r = projectFields fs r , f r projectFields (fs prop[ f ∣ _ ]) r = projectFields fs r , f r isPropProperty : ∀ {ℓ₂} (R : Type ℓ → Type ℓ₁) (ι : StrEquiv R ℓ₁') (fs : AutoFields R ι) (P : (X : Type ℓ) → GatherFields fs X → Type ℓ₂) → Type (ℓ-max (ℓ-suc ℓ) (ℓ-max ℓ₁ ℓ₂)) isPropProperty R ι fs P = {X : Type ℓ} (r : R X) → isProp (P X (projectFields fs r)) data AutoRecordSpec : Typeω where autoRecordSpec : (R : Type ℓ → Type ℓ₁) (ι : StrEquiv R ℓ₁') → AutoFields R ι → AutoRecordSpec -- Some reflection utilities private tApply : R.Term → List (R.Arg R.Term) → R.Term tApply t l = R.def (quote idfun) (R.unknown v∷ t v∷ l) tStrMap : R.Term → R.Term → R.Term tStrMap A f = R.def (quote map-snd) (f v∷ A v∷ []) tStrProj : R.Term → R.Name → R.Term tStrProj A sfield = tStrMap A (R.def sfield []) Fun : ∀ {ℓ ℓ'} → Type ℓ → Type ℓ' → Type (ℓ-max ℓ ℓ') Fun A B = A → B -- Helper functions used in the generated univalence proof private pathMap : ∀ {ℓ ℓ'} {S : I → Type ℓ} {T : I → Type ℓ'} (f : {i : I} → S i → T i) {x : S i0} {y : S i1} → PathP S x y → PathP T (f x) (f y) pathMap f p i = f (p i) -- Property field helper functions module _ {ℓ ℓ₁ ℓ₁' ℓ₂} (R : Type ℓ → Type ℓ₁) -- Structure record (ι : StrEquiv R ℓ₁') -- Equivalence record (fs : AutoFields R ι) -- Prior fields (P : (X : Type ℓ) → GatherFields fs X → Type ℓ₂) -- Property type (f : {X : Type ℓ} (r : R X) → P X (projectFields fs r)) -- Property projection where prev = projectFields fs Prev = GatherFields fs PropHelperCenterType : Type _ PropHelperCenterType = (A B : TypeWithStr ℓ R) (e : A .fst ≃ B .fst) (p : PathP (λ i → Prev (ua e i)) (prev (A .snd)) (prev (B .snd))) → PathP (λ i → P (ua e i) (p i)) (f (A .snd)) (f (B .snd)) PropHelperContractType : PropHelperCenterType → Type _ PropHelperContractType c = (A B : TypeWithStr ℓ R) (e : A .fst ≃ B .fst) {p₀ : PathP (λ i → Prev (ua e i)) (prev (A .snd)) (prev (B .snd))} (q : PathP (λ i → R (ua e i)) (A .snd) (B .snd)) (p : p₀ ≡ (λ i → prev (q i))) → PathP (λ k → PathP (λ i → P (ua e i) (p k i)) (f (A .snd)) (f (B .snd))) (c A B e p₀) (λ i → f (q i)) PropHelperType : Type _ PropHelperType = Σ PropHelperCenterType PropHelperContractType derivePropHelper : isPropProperty R ι fs P → PropHelperType derivePropHelper propP .fst A B e p = isOfHLevelPathP' 0 (propP _) (f (A .snd)) (f (B .snd)) .fst derivePropHelper propP .snd A B e q p = isOfHLevelPathP' 0 (isOfHLevelPathP 1 (propP _) _ _) _ _ .fst -- Build proof of univalence from an isomorphism module _ {ℓ ℓ₁ ℓ₁'} (S : Type ℓ → Type ℓ₁) (ι : StrEquiv S ℓ₁') where fwdShape : Type _ fwdShape = (A B : TypeWithStr ℓ S) (e : typ A ≃ typ B) → ι A B e → PathP (λ i → S (ua e i)) (str A) (str B) bwdShape : Type _ bwdShape = (A B : TypeWithStr ℓ S) (e : typ A ≃ typ B) → PathP (λ i → S (ua e i)) (str A) (str B) → ι A B e fwdBwdShape : fwdShape → bwdShape → Type _ fwdBwdShape fwd bwd = (A B : TypeWithStr ℓ S) (e : typ A ≃ typ B) → ∀ p → fwd A B e (bwd A B e p) ≡ p bwdFwdShape : fwdShape → bwdShape → Type _ bwdFwdShape fwd bwd = (A B : TypeWithStr ℓ S) (e : typ A ≃ typ B) → ∀ r → bwd A B e (fwd A B e r) ≡ r -- The implicit arguments A,B in UnivalentStr make some things annoying so let's avoid them ExplicitUnivalentStr : Type _ ExplicitUnivalentStr = (A B : TypeWithStr _ S) (e : typ A ≃ typ B) → ι A B e ≃ PathP (λ i → S (ua e i)) (str A) (str B) explicitUnivalentStr : (fwd : fwdShape) (bwd : bwdShape) → fwdBwdShape fwd bwd → bwdFwdShape fwd bwd → ExplicitUnivalentStr explicitUnivalentStr fwd bwd fwdBwd bwdFwd A B e = isoToEquiv isom where open Iso isom : Iso _ _ isom .fun = fwd A B e isom .inv = bwd A B e isom .rightInv = fwdBwd A B e isom .leftInv = bwdFwd A B e ExplicitUnivalentDesc : ∀ ℓ {ℓ₁ ℓ₁'} → (d : M.Desc ℓ ℓ₁ ℓ₁') → Type _ ExplicitUnivalentDesc _ d = ExplicitUnivalentStr (M.MacroStructure d) (M.MacroEquivStr d) explicitUnivalentDesc : ∀ ℓ {ℓ₁ ℓ₁'} → (d : M.Desc ℓ ℓ₁ ℓ₁') → ExplicitUnivalentDesc ℓ d explicitUnivalentDesc _ d A B e = M.MacroUnivalentStr d e -- Internal record specification type private record TypedTerm : Type where field type : R.Term term : R.Term record InternalDatumField : Type where field sfield : R.Name -- name of structure field efield : R.Name -- name of equivalence field record InternalPropField : Type where field sfield : R.Name -- name of structure field InternalField : Type InternalField = InternalDatumField ⊎ InternalPropField record InternalSpec (A : Type) : Type where field srec : R.Term -- structure record type erec : R.Term -- equivalence record type fields : List (InternalField × A) -- in reverse order open TypedTerm open InternalDatumField open InternalPropField -- Parse a field and record specifications private findName : R.Term → R.TC R.Name findName (R.def name _) = R.returnTC name findName (R.lam R.hidden (R.abs _ t)) = findName t findName t = R.typeError (R.strErr "Not a name + spine: " ∷ R.termErr t ∷ []) parseFieldSpec : R.Term → R.TC (R.Term × R.Term × R.Term × R.Term) parseFieldSpec (R.con (quote autoFieldSpec) (ℓ h∷ ℓ₁ h∷ ℓ₂ h∷ R v∷ S h∷ f v∷ [])) = R.reduce ℓ >>= λ ℓ → R.returnTC (ℓ , ℓ₂ , S , f) parseFieldSpec t = R.typeError (R.strErr "Malformed field specification: " ∷ R.termErr t ∷ []) parseSpec : R.Term → R.TC (InternalSpec TypedTerm) parseSpec (R.con (quote autoRecordSpec) (ℓ h∷ ℓ₁ h∷ ℓ₁' h∷ srecTerm v∷ erecTerm v∷ fs v∷ [])) = parseFields fs >>= λ fs' → R.returnTC λ { .srec → srecTerm ; .erec → erecTerm ; .fields → fs'} where open InternalSpec parseFields : R.Term → R.TC (List (InternalField × TypedTerm)) parseFields (R.con (quote fields:) _) = R.returnTC [] parseFields (R.con (quote _data[_∣_]) (ℓ h∷ ℓ₁ h∷ ℓ₁' h∷ R h∷ ι h∷ fs v∷ ℓ₂ h∷ ℓ₂' h∷ S h∷ ι' h∷ sfieldTerm v∷ efieldTerm v∷ [])) = R.reduce ℓ >>= λ ℓ → findName sfieldTerm >>= λ sfieldName → findName efieldTerm >>= λ efieldName → buildDesc FUEL ℓ ℓ₂ S >>= λ d → let f : InternalField × TypedTerm f = λ { .fst → inl λ { .sfield → sfieldName ; .efield → efieldName } ; .snd .type → R.def (quote ExplicitUnivalentDesc) (ℓ v∷ d v∷ []) ; .snd .term → R.def (quote explicitUnivalentDesc) (ℓ v∷ d v∷ []) } in liftTC (f ∷_) (parseFields fs) parseFields (R.con (quote _prop[_∣_]) (ℓ h∷ ℓ₁ h∷ ℓ₁' h∷ R h∷ ι h∷ fs v∷ ℓ₂ h∷ P h∷ fieldTerm v∷ prop v∷ [])) = findName fieldTerm >>= λ fieldName → let p : InternalField × TypedTerm p = λ { .fst → inr λ { .sfield → fieldName } ; .snd .type → R.def (quote PropHelperType) (srecTerm v∷ erecTerm v∷ fs v∷ P v∷ fieldTerm v∷ []) ; .snd .term → R.def (quote derivePropHelper) (srecTerm v∷ erecTerm v∷ fs v∷ P v∷ fieldTerm v∷ prop v∷ []) } in liftTC (p ∷_) (parseFields fs) parseFields t = R.typeError (R.strErr "Malformed autoRecord specification (1): " ∷ R.termErr t ∷ []) parseSpec t = R.typeError (R.strErr "Malformed autoRecord specification (2): " ∷ R.termErr t ∷ []) -- Build a proof of univalence from an InternalSpec module _ (spec : InternalSpec ℕ) where open InternalSpec spec private fwdDatum : Vec R.Term 4 → R.Term → InternalDatumField × ℕ → R.Term fwdDatum (A ∷ B ∷ e ∷ streq ∷ _) i (dat , n) = R.def (quote equivFun) (tApply (v n) (tStrProj A (dat .sfield) v∷ tStrProj B (dat .sfield) v∷ e v∷ []) v∷ R.def (dat .efield) (streq v∷ []) v∷ i v∷ []) fwdProperty : Vec R.Term 4 → R.Term → R.Term → InternalPropField × ℕ → R.Term fwdProperty (A ∷ B ∷ e ∷ streq ∷ _) i prevPath prop = R.def (quote fst) (v (prop .snd) v∷ A v∷ B v∷ e v∷ prevPath v∷ i v∷ []) bwdClause : Vec R.Term 4 → InternalDatumField × ℕ → R.Clause bwdClause (A ∷ B ∷ e ∷ q ∷ _) (dat , n) = R.clause [] (R.proj (dat .efield) v∷ []) (R.def (quote invEq) (tApply (v n) (tStrProj A (dat .sfield) v∷ tStrProj B (dat .sfield) v∷ e v∷ []) v∷ R.def (quote pathMap) (R.def (dat .sfield) [] v∷ q v∷ []) v∷ [])) fwdBwdDatum : Vec R.Term 4 → R.Term → R.Term → InternalDatumField × ℕ → R.Term fwdBwdDatum (A ∷ B ∷ e ∷ q ∷ _) j i (dat , n) = R.def (quote retEq) (tApply (v n) (tStrProj A (dat .sfield) v∷ tStrProj B (dat .sfield) v∷ e v∷ []) v∷ R.def (quote pathMap) (R.def (dat .sfield) [] v∷ q v∷ []) v∷ j v∷ i v∷ []) fwdBwdProperty : Vec R.Term 4 → (j i prevPath : R.Term) → InternalPropField × ℕ → R.Term fwdBwdProperty (A ∷ B ∷ e ∷ q ∷ _) j i prevPath prop = R.def (quote snd) (v (prop .snd) v∷ A v∷ B v∷ e v∷ q v∷ prevPath v∷ j v∷ i v∷ []) bwdFwdClause : Vec R.Term 4 → R.Term → InternalDatumField × ℕ → R.Clause bwdFwdClause (A ∷ B ∷ e ∷ streq ∷ _) j (dat , n) = R.clause [] (R.proj (dat .efield) v∷ []) (R.def (quote secEq) (tApply (v n) (tStrProj A (dat .sfield) v∷ tStrProj B (dat .sfield) v∷ e v∷ []) v∷ R.def (dat .efield) (streq v∷ []) v∷ j v∷ [])) makeVarsFrom : {n : ℕ} → ℕ → Vec R.Term n makeVarsFrom {zero} k = [] makeVarsFrom {suc n} k = v (n + k) ∷ (makeVarsFrom k) fwd : R.Term fwd = vlam "A" (vlam "B" (vlam "e" (vlam "streq" (vlam "i" (R.pat-lam body []))))) where -- input list is in reverse order fwdClauses : ℕ → List (InternalField × ℕ) → List (R.Name × R.Term) fwdClauses k [] = [] fwdClauses k ((inl f , n) ∷ fs) = fwdClauses k fs ∷ʳ (f .sfield , fwdDatum (makeVarsFrom k) (v 0) (map-snd (4 + k +_) (f , n))) fwdClauses k ((inr p , n) ∷ fs) = fwdClauses k fs ∷ʳ (p .sfield , fwdProperty (makeVarsFrom k) (v 0) prevPath (map-snd (4 + k +_) (p , n))) where prevPath = vlam "i" (List.foldl (λ t (_ , t') → R.con (quote _,_) (t v∷ t' v∷ [])) (R.con (quote tt) []) (fwdClauses (suc k) fs)) body = List.map (λ (n , t) → R.clause [] [ varg (R.proj n) ] t) (fwdClauses 1 fields) bwd : R.Term bwd = vlam "A" (vlam "B" (vlam "e" (vlam "q" (R.pat-lam (bwdClauses fields) [])))) where -- input is in reverse order bwdClauses : List (InternalField × ℕ) → List R.Clause bwdClauses [] = [] bwdClauses ((inl f , n) ∷ fs) = bwdClauses fs ∷ʳ bwdClause (makeVarsFrom 0) (map-snd (4 +_) (f , n)) bwdClauses ((inr p , n) ∷ fs) = bwdClauses fs fwdBwd : R.Term fwdBwd = vlam "A" (vlam "B" (vlam "e" (vlam "q" (vlam "j" (vlam "i" (R.pat-lam body [])))))) where -- input is in reverse order fwdBwdClauses : ℕ → List (InternalField × ℕ) → List (R.Name × R.Term) fwdBwdClauses k [] = [] fwdBwdClauses k ((inl f , n) ∷ fs) = fwdBwdClauses k fs ∷ʳ (f .sfield , fwdBwdDatum (makeVarsFrom k) (v 1) (v 0) (map-snd (4 + k +_) (f , n))) fwdBwdClauses k ((inr p , n) ∷ fs) = fwdBwdClauses k fs ∷ʳ ((p .sfield , fwdBwdProperty (makeVarsFrom k) (v 1) (v 0) prevPath (map-snd (4 + k +_) (p , n)))) where prevPath = vlam "j" (vlam "i" (List.foldl (λ t (_ , t') → R.con (quote _,_) (t v∷ t' v∷ [])) (R.con (quote tt) []) (fwdBwdClauses (2 + k) fs))) body = List.map (λ (n , t) → R.clause [] [ varg (R.proj n) ] t) (fwdBwdClauses 2 fields) bwdFwd : R.Term bwdFwd = vlam "A" (vlam "B" (vlam "e" (vlam "streq" (vlam "j" (R.pat-lam (bwdFwdClauses fields) []))))) where bwdFwdClauses : List (InternalField × ℕ) → List R.Clause bwdFwdClauses [] = [] bwdFwdClauses ((inl f , n) ∷ fs) = bwdFwdClauses fs ∷ʳ bwdFwdClause (makeVarsFrom 1) (v 0) (map-snd (5 +_) (f , n)) bwdFwdClauses ((inr _ , n) ∷ fs) = bwdFwdClauses fs univalentRecord : R.Term univalentRecord = R.def (quote explicitUnivalentStr) (R.unknown v∷ R.unknown v∷ fwd v∷ bwd v∷ fwdBwd v∷ bwdFwd v∷ []) macro autoFieldEquiv : R.Term → R.Term → R.Term → R.Term → R.TC ⊤ autoFieldEquiv spec A B hole = (R.reduce spec >>= parseFieldSpec) >>= λ (ℓ , ℓ₂ , S , f) → buildDesc FUEL ℓ ℓ₂ S >>= λ d → R.unify hole (R.def (quote M.MacroEquivStr) (d v∷ tStrMap A f v∷ tStrMap B f v∷ [])) autoUnivalentRecord : R.Term → R.Term → R.TC ⊤ autoUnivalentRecord t hole = (R.reduce t >>= parseSpec) >>= λ spec → -- R.typeError (R.strErr "WOW: " ∷ R.termErr (main spec) ∷ []) R.unify (main spec) hole where module _ (spec : InternalSpec TypedTerm) where open InternalSpec spec mapUp : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → (ℕ → A → B) → ℕ → List A → List B mapUp f _ [] = [] mapUp f n (x ∷ xs) = f n x ∷ mapUp f (suc n) xs closureSpec : InternalSpec ℕ closureSpec .InternalSpec.srec = srec closureSpec .InternalSpec.erec = erec closureSpec .InternalSpec.fields = mapUp (λ n → map-snd (λ _ → n)) 0 fields closure : R.Term closure = iter (List.length fields) (vlam "") (univalentRecord closureSpec) env : List (R.Arg R.Term) env = List.map (varg ∘ term ∘ snd) (List.rev fields) closureTy : R.Term closureTy = List.foldr (λ ty cod → R.def (quote Fun) (ty v∷ cod v∷ [])) (R.def (quote ExplicitUnivalentStr) (srec v∷ erec v∷ [])) (List.map (type ∘ snd) (List.rev fields)) main : R.Term main = R.def (quote idfun) (closureTy v∷ closure v∷ env)
36.905286
108
0.56801
1b39ec7af391d0011b0a119a5f4178b926a2459e
5,668
agda
Agda
src/Util/HoTT/HLevel/Core.agda
JLimperg/msc-thesis-code
104cddc6b65386c7e121c13db417aebfd4b7a863
[ "MIT" ]
5
2021-04-13T21:31:17.000Z
2021-06-26T06:37:31.000Z
src/Util/HoTT/HLevel/Core.agda
JLimperg/msc-thesis-code
104cddc6b65386c7e121c13db417aebfd4b7a863
[ "MIT" ]
null
null
null
src/Util/HoTT/HLevel/Core.agda
JLimperg/msc-thesis-code
104cddc6b65386c7e121c13db417aebfd4b7a863
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --safe #-} module Util.HoTT.HLevel.Core where open import Data.Nat using (_+_) open import Level using (Lift ; lift ; lower) open import Util.Prelude open import Util.Relation.Binary.LogicalEquivalence using (_↔_ ; forth ; back) open import Util.Relation.Binary.PropositionalEquality using ( Σ-≡⁺ ; Σ-≡⁻ ; Σ-≡⁺∘Σ-≡⁻ ; trans-injectiveˡ ) private variable α β γ : Level A B C : Set α IsContr : Set α → Set α IsContr A = Σ[ x ∈ A ] (∀ y → x ≡ y) IsProp : Set α → Set α IsProp A = (x y : A) → x ≡ y IsProp′ : Set α → Set α IsProp′ A = (x y : A) → IsContr (x ≡ y) IsProp→IsProp′ : IsProp A → IsProp′ A IsProp→IsProp′ {A = A} A-prop x y = (A-prop x y) , canon where go : (p : x ≡ y) → trans p (A-prop y y) ≡ A-prop x y go refl = refl canon : (p : x ≡ y) → A-prop x y ≡ p canon refl = trans-injectiveˡ (A-prop y y) (go (A-prop y y)) IsProp′→IsProp : IsProp′ A → IsProp A IsProp′→IsProp A-prop x y = proj₁ (A-prop x y) IsProp↔IsProp′ : IsProp A ↔ IsProp′ A IsProp↔IsProp′ .forth = IsProp→IsProp′ IsProp↔IsProp′ .back = IsProp′→IsProp IsSet : Set α → Set α IsSet A = {x y : A} → IsProp (x ≡ y) IsOfHLevel : ℕ → Set α → Set α IsOfHLevel 0 A = IsContr A IsOfHLevel 1 A = IsProp A IsOfHLevel (suc (suc n)) A = {x y : A} → IsOfHLevel (suc n) (x ≡ y) IsOfHLevel′ : ℕ → Set α → Set α IsOfHLevel′ zero A = IsContr A IsOfHLevel′ (suc n) A = ∀ {x y : A} → IsOfHLevel′ n (x ≡ y) IsOfHLevel′→IsOfHLevel : ∀ n → IsOfHLevel′ n A → IsOfHLevel n A IsOfHLevel′→IsOfHLevel zero A-contr = A-contr IsOfHLevel′→IsOfHLevel (suc zero) A-prop = IsProp′→IsProp λ _ _ → A-prop IsOfHLevel′→IsOfHLevel (suc (suc n)) A-level = IsOfHLevel′→IsOfHLevel (suc n) A-level IsOfHLevel→IsOfHLevel′ : ∀ n → IsOfHLevel n A → IsOfHLevel′ n A IsOfHLevel→IsOfHLevel′ zero A-contr = A-contr IsOfHLevel→IsOfHLevel′ (suc zero) A-prop = IsProp→IsProp′ A-prop _ _ IsOfHLevel→IsOfHLevel′ (suc (suc n)) A-level = IsOfHLevel→IsOfHLevel′ (suc n) A-level IsOfHLevel↔IsOfHLevel′ : ∀ n → IsOfHLevel n A ↔ IsOfHLevel′ n A IsOfHLevel↔IsOfHLevel′ n .forth = IsOfHLevel→IsOfHLevel′ n IsOfHLevel↔IsOfHLevel′ n .back = IsOfHLevel′→IsOfHLevel n IsContr→IsProp : IsContr A → IsProp A IsContr→IsProp (c , c-canon) x y = trans (sym (c-canon x)) (c-canon y) IsOfHLevel-suc : ∀ n → IsOfHLevel n A → IsOfHLevel (suc n) A IsOfHLevel-suc 0 A-contr = IsContr→IsProp A-contr IsOfHLevel-suc 1 A-prop = IsOfHLevel-suc 0 (IsProp→IsProp′ A-prop _ _) IsOfHLevel-suc (suc (suc n)) A-level-n = IsOfHLevel-suc (suc n) A-level-n IsOfHLevel-suc-n : ∀ n m → IsOfHLevel n A → IsOfHLevel (m + n) A IsOfHLevel-suc-n {A = A} n zero A-level = A-level IsOfHLevel-suc-n n (suc m) A-level = IsOfHLevel-suc (m + n) (IsOfHLevel-suc-n n m A-level) IsProp→IsSet : IsProp A → IsSet A IsProp→IsSet = IsOfHLevel-suc 1 IsContr→IsSet : IsContr A → IsSet A IsContr→IsSet = IsOfHLevel-suc-n 0 2 record HLevel α n : Set (lsuc α) where constructor HLevel⁺ field type : Set α level : IsOfHLevel n type open HLevel public HContr : ∀ α → Set (lsuc α) HContr α = HLevel α 0 HProp : ∀ α → Set (lsuc α) HProp α = HLevel α 1 HSet : ∀ α → Set (lsuc α) HSet α = HLevel α 2 HLevel-suc : ∀ {α n} → HLevel α n → HLevel α (suc n) HLevel-suc (HLevel⁺ A A-level) = HLevel⁺ A (IsOfHLevel-suc _ A-level) ⊤-IsContr : IsContr ⊤ ⊤-IsContr = _ , λ _ → refl ⊤-IsProp : IsProp ⊤ ⊤-IsProp = IsOfHLevel-suc 0 ⊤-IsContr ⊥-IsProp : IsProp ⊥ ⊥-IsProp () ×-IsProp : IsProp A → IsProp B → IsProp (A × B) ×-IsProp A-prop B-prop (x , y) (x′ , y′) = cong₂ _,_ (A-prop _ _) (B-prop _ _) Lift-IsProp : IsProp A → IsProp (Lift α A) Lift-IsProp A-prop (lift x) (lift y) = cong lift (A-prop _ _) ⊤-HProp : HProp 0ℓ ⊤-HProp = HLevel⁺ ⊤ ⊤-IsProp ⊥-HProp : HProp 0ℓ ⊥-HProp = HLevel⁺ ⊥ ⊥-IsProp _×-HProp_ : HProp α → HProp β → HProp (α ⊔ℓ β) A ×-HProp B = HLevel⁺ (A .type × B .type) (×-IsProp (A .level) (B .level)) Lift-HProp : ∀ α → HProp β → HProp (α ⊔ℓ β) Lift-HProp α (HLevel⁺ A A-prop) = HLevel⁺ (Lift α A) (Lift-IsProp A-prop) ⊤-IsSet : IsSet ⊤ ⊤-IsSet = IsOfHLevel-suc 1 ⊤-IsProp ⊥-IsSet : IsSet ⊥ ⊥-IsSet = IsOfHLevel-suc 1 ⊥-IsProp Σ-IsSet : {A : Set α} {B : A → Set β} → IsSet A → (∀ a → IsSet (B a)) → IsSet (Σ A B) Σ-IsSet A-set B-set p q = trans (sym (Σ-≡⁺∘Σ-≡⁻ p)) (sym (trans (sym (Σ-≡⁺∘Σ-≡⁻ q)) (cong Σ-≡⁺ (Σ-≡⁺ (A-set _ _ , B-set _ _ _))))) ×-IsSet : IsSet A → IsSet B → IsSet (A × B) ×-IsSet A-set B-set = Σ-IsSet A-set (λ _ → B-set) Lift-IsSet : IsSet A → IsSet (Lift α A) Lift-IsSet A-set p q = trans (sym (Lift-≡⁺∘Lift-≡⁻ p)) (sym (trans (sym (Lift-≡⁺∘Lift-≡⁻ q)) (cong Lift-≡⁺ (A-set _ _)))) where Lift-≡⁻ : {x y : Lift α A} → x ≡ y → lower x ≡ lower y Lift-≡⁻ refl = refl Lift-≡⁺ : {x y : Lift α A} → lower x ≡ lower y → x ≡ y Lift-≡⁺ refl = refl Lift-≡⁻∘Lift-≡⁺ : {x y : Lift α A} (p : lower x ≡ lower y) → Lift-≡⁻ {α = α} (Lift-≡⁺ p) ≡ p Lift-≡⁻∘Lift-≡⁺ refl = refl Lift-≡⁺∘Lift-≡⁻ : {x y : Lift α A} (p : x ≡ y) → Lift-≡⁺ {α = α} (Lift-≡⁻ p) ≡ p Lift-≡⁺∘Lift-≡⁻ refl = refl ⊤-HSet : HSet 0ℓ ⊤-HSet = HLevel⁺ ⊤ ⊤-IsSet ⊥-HSet : HSet 0ℓ ⊥-HSet = HLevel⁺ ⊥ ⊥-IsSet Σ-HSet : (A : HSet α) (B : A .type → HSet β) → HSet (α ⊔ℓ β) Σ-HSet A B = HLevel⁺ (Σ (A .type) λ a → B a .type) (Σ-IsSet (A .level) (λ a → B a .level)) _×-HSet_ : HSet α → HSet β → HSet (α ⊔ℓ β) A ×-HSet B = HLevel⁺ (A .type × B .type) (×-IsSet (A .level) (B .level)) Lift-HSet : ∀ α → HSet β → HSet (α ⊔ℓ β) Lift-HSet α (HLevel⁺ B B-set) = HLevel⁺ (Lift α B) (Lift-IsSet B-set) IsProp∧Pointed→IsContr : IsProp A → (a : A) → IsContr A IsProp∧Pointed→IsContr A-prop a = a , λ b → A-prop a b
24.222222
81
0.599859
04a189d03ac976ea874b840cf1f20d0434c78293
1,621
agda
Agda
Cubical/Structures/Parameterized.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Structures/Parameterized.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Structures/Parameterized.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{- A parameterized family of structures S can be combined into a single structure: X ↦ (a : A) → S a X This is more general than Structures.Function in that S can vary in A. -} {-# OPTIONS --safe #-} module Cubical.Structures.Parameterized where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Functions.FunExtEquiv open import Cubical.Foundations.SIP open import Cubical.Foundations.Univalence private variable ℓ ℓ₁ ℓ₁' : Level module _ {ℓ₀} (A : Type ℓ₀) where ParamStructure : (S : A → Type ℓ → Type ℓ₁) → Type ℓ → Type (ℓ-max ℓ₀ ℓ₁) ParamStructure S X = (a : A) → S a X ParamEquivStr : {S : A → Type ℓ → Type ℓ₁} → (∀ a → StrEquiv (S a) ℓ₁') → StrEquiv (ParamStructure S) (ℓ-max ℓ₀ ℓ₁') ParamEquivStr ι (X , l) (Y , m) e = ∀ a → ι a (X , l a) (Y , m a) e paramUnivalentStr : {S : A → Type ℓ → Type ℓ₁} (ι : ∀ a → StrEquiv (S a) ℓ₁') (θ : ∀ a → UnivalentStr (S a) (ι a)) → UnivalentStr (ParamStructure S) (ParamEquivStr ι) paramUnivalentStr ι θ e = compEquiv (equivΠCod λ a → θ a e) funExtEquiv paramEquivAction : {S : A → Type ℓ → Type ℓ₁} → (∀ a → EquivAction (S a)) → EquivAction (ParamStructure S) paramEquivAction α e = equivΠCod (λ a → α a e) paramTransportStr : {S : A → Type ℓ → Type ℓ₁} (α : ∀ a → EquivAction (S a)) (τ : ∀ a → TransportStr (α a)) → TransportStr (paramEquivAction α) paramTransportStr {S = S} α τ e f = funExt λ a → τ a e (f a) ∙ cong (λ fib → transport (λ i → S (fib .snd (~ i)) (ua e i)) (f (fib .snd i1))) (isContrSingl a .snd (_ , sym (transportRefl a)))
33.081633
84
0.630475
7c41f0bb54350b0e35707f73b2383ef367014faf
3,245
agda
Agda
Numeral/Finite/Oper/Comparisons/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Numeral/Finite/Oper/Comparisons/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Numeral/Finite/Oper/Comparisons/Proofs.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Numeral.Finite.Oper.Comparisons.Proofs where import Lvl open import Data open import Data.Boolean import Data.Boolean.Operators open Data.Boolean.Operators.Programming open import Logic.Propositional open import Logic.Predicate open import Numeral.Finite open import Numeral.Finite.Oper.Comparisons open import Numeral.Sign open import Numeral.Sign.Oper0 open import Relator.Equals open import Relator.Equals.Proofs.Equivalence import Structure.Operator.Names as Names open import Structure.Operator.Properties open import Syntax.Number ⋚-of-𝟎-not-+ : ∀{an bn}{b : 𝕟(bn)} → ⦃ _ : 𝟎 {an} ⋚? b ≡ ➕ ⦄ → ⊥ ⋚-of-𝟎-not-+ {b = 𝟎} ⦃ ⦄ ⋚-of-𝟎-not-+ {b = 𝐒(_)} ⦃ ⦄ ⋚-of-𝟎-not-− : ∀{an bn}{a : 𝕟(an)} → ⦃ _ : a ⋚? 𝟎 {bn} ≡ ➖ ⦄ → ⊥ ⋚-of-𝟎-not-− {a = 𝟎} ⦃ ⦄ ⋚-of-𝟎-not-− {a = 𝐒(_)} ⦃ ⦄ ⋚-of-𝐒𝟎-not-𝟎 : ∀{an bn}{a : 𝕟(an)} → ⦃ _ : 𝐒(a) ⋚? 𝟎 {bn} ≡ 𝟎 ⦄ → ⊥ ⋚-of-𝐒𝟎-not-𝟎 {a = 𝟎} ⦃ ⦄ ⋚-of-𝐒𝟎-not-𝟎 {a = 𝐒(_)} ⦃ ⦄ ⋚-of-𝟎𝐒-not-𝟎 : ∀{an bn}{b : 𝕟(bn)} → ⦃ _ : 𝟎 {an} ⋚? 𝐒(b) ≡ 𝟎 ⦄ → ⊥ ⋚-of-𝟎𝐒-not-𝟎 {b = 𝟎} ⦃ ⦄ ⋚-of-𝟎𝐒-not-𝟎 {b = 𝐒(_)} ⦃ ⦄ ⋚-surjective : ∀{an bn}{a : 𝕟(an)}{b : 𝕟(bn)} → ∃{Obj = (−|0|+)} (a ⋚? b ≡_) ⋚-surjective {a = 𝟎} {𝟎} = [∃]-intro 𝟎 ⋚-surjective {a = 𝟎} {𝐒 b} = [∃]-intro ➖ ⋚-surjective {a = 𝐒 a} {𝟎} = [∃]-intro ➕ ⋚-surjective {a = 𝐒 a} {𝐒 b} = ⋚-surjective {a = a} {b} ⋚-to-< : ∀{an bn}{a : 𝕟(an)}{b : 𝕟(bn)} → ⦃ _ : a ⋚? b ≡ ➕ ⦄ → (a >? b ≡ 𝑇) ⋚-to-< {a = 𝐒 a} {𝟎} = [≡]-intro ⋚-to-< {a = 𝐒 a} {𝐒 b} = ⋚-to-< {a = a} {b} ⋚-to-> : ∀{an bn}{a : 𝕟(an)}{b : 𝕟(bn)} → ⦃ _ : a ⋚? b ≡ ➖ ⦄ → (a <? b ≡ 𝑇) ⋚-to-> {a = 𝟎} {𝐒 b} = [≡]-intro ⋚-to-> {a = 𝐒 a} {𝐒 b} = ⋚-to-> {a = a} {b} ⋚-to-≡ : ∀{an bn}{a : 𝕟(an)}{b : 𝕟(bn)} → ⦃ _ : a ⋚? b ≡ 𝟎 ⦄ → (a ≡? b ≡ 𝑇) ⋚-to-≡ {a = 𝟎} {𝟎} = [≡]-intro ⋚-to-≡ {a = 𝐒 a} {𝐒 b} = ⋚-to-≡ {a = a} {b} instance [≡?]-commutativity : ∀{n} → Commutativity{T₁ = 𝕟(n)} ⦃ [≡]-equiv ⦄ (_≡?_) [≡?]-commutativity{n} = intro(\{x y} → p{n}{x}{y}) where p : ∀{n} → Names.Commutativity{T₁ = 𝕟(n)} ⦃ [≡]-equiv ⦄ (_≡?_) p{_}{𝟎} {𝟎} = [≡]-intro p{_}{𝟎} {𝐒 y} = [≡]-intro p{_}{𝐒 x}{𝟎} = [≡]-intro p{_}{𝐒 x}{𝐒 y} = p{_}{x}{y} ⋚-anticommutativity : ∀{xn yn}{x : 𝕟(xn)}{y : 𝕟(yn)} → (−(x ⋚? y) ≡ y ⋚? x) ⋚-anticommutativity {x = 𝟎} {y = 𝟎} = [≡]-intro ⋚-anticommutativity {x = 𝟎} {y = 𝐒 y} = [≡]-intro ⋚-anticommutativity {x = 𝐒 x}{y = 𝟎} = [≡]-intro ⋚-anticommutativity {x = 𝐒 x}{y = 𝐒 y} = ⋚-anticommutativity {x = x}{y = y} ⋚-elim₃-negation-flip : ∀{xn yn}{x : 𝕟(xn)}{y : 𝕟(yn)}{b₁ b₂ b₃} → (elim₃{P = \_ → Bool} b₁ b₂ b₃ (−(x ⋚? y)) ≡ elim₃ b₃ b₂ b₁ (x ⋚? y)) ⋚-elim₃-negation-flip {x = 𝟎} {y = 𝟎} = [≡]-intro ⋚-elim₃-negation-flip {x = 𝟎} {y = 𝐒 y} = [≡]-intro ⋚-elim₃-negation-flip {x = 𝐒 x}{y = 𝟎} = [≡]-intro ⋚-elim₃-negation-flip {x = 𝐒 x}{y = 𝐒 y} = ⋚-elim₃-negation-flip {x = x}{y = y} ⋚-elim₃-negation-distribution : ∀{xn yn}{x : 𝕟(xn)}{y : 𝕟(yn)}{b₁ b₂ b₃ : Bool} → (!(elim₃ b₁ b₂ b₃ (x ⋚? y)) ≡ elim₃ (! b₁) (! b₂) (! b₃) (x ⋚? y)) ⋚-elim₃-negation-distribution {x = 𝟎} {y = 𝟎} = [≡]-intro ⋚-elim₃-negation-distribution {x = 𝟎} {y = 𝐒 y} = [≡]-intro ⋚-elim₃-negation-distribution {x = 𝐒 x}{y = 𝟎} = [≡]-intro ⋚-elim₃-negation-distribution {x = 𝐒 x}{y = 𝐒 y} = ⋚-elim₃-negation-distribution {x = x}{y = y}
40.5625
148
0.493374
576644a77a022d5664ddfa2517dffbebff8be471
2,472
agda
Agda
agda-stdlib/src/Data/List/Relation/Binary/Sublist/Propositional/Disjoint.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/List/Relation/Binary/Sublist/Propositional/Disjoint.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/List/Relation/Binary/Sublist/Propositional/Disjoint.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Sublist-related properties ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Binary.Sublist.Propositional.Disjoint {a} {A : Set a} where open import Data.List.Base using (List) open import Data.List.Relation.Binary.Sublist.Propositional open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong) ------------------------------------------------------------------------ -- A Union where the triangles commute is a -- Cospan in the slice category (_ ⊆ zs). record IsCospan {xs ys zs : List A} {τ₁ : xs ⊆ zs} {τ₂ : ys ⊆ zs} (u : UpperBound τ₁ τ₂) : Set a where field tri₁ : ⊆-trans (UpperBound.inj₁ u) (UpperBound.sub u) ≡ τ₁ tri₂ : ⊆-trans (UpperBound.inj₂ u) (UpperBound.sub u) ≡ τ₂ record Cospan {xs ys zs : List A} (τ₁ : xs ⊆ zs) (τ₂ : ys ⊆ zs) : Set a where field upperBound : UpperBound τ₁ τ₂ isCospan : IsCospan upperBound open UpperBound upperBound public open IsCospan isCospan public open IsCospan open Cospan module _ {x : A} {xs ys zs : List A} {τ₁ : xs ⊆ zs} {τ₂ : ys ⊆ zs} (d : Disjoint τ₁ τ₂) (c : IsCospan (⊆-disjoint-union d)) where ∷ₙ-cospan : IsCospan (⊆-disjoint-union (x ∷ₙ d)) ∷ₙ-cospan = record { tri₁ = cong (x ∷ʳ_) (c .tri₁) ; tri₂ = cong (x ∷ʳ_) (c .tri₂) } ∷ₗ-cospan : IsCospan (⊆-disjoint-union (refl {x = x} ∷ₗ d)) ∷ₗ-cospan = record { tri₁ = cong (refl ∷_) (c .tri₁) ; tri₂ = cong (x ∷ʳ_) (c .tri₂) } ∷ᵣ-cospan : IsCospan (⊆-disjoint-union (refl {x = x} ∷ᵣ d)) ∷ᵣ-cospan = record { tri₁ = cong (x ∷ʳ_) (c .tri₁) ; tri₂ = cong (refl ∷_) (c .tri₂) } ⊆-disjoint-union-is-cospan : ∀ {xs ys zs : List A} {τ₁ : xs ⊆ zs} {τ₂ : ys ⊆ zs} → (d : Disjoint τ₁ τ₂) → IsCospan (⊆-disjoint-union d) ⊆-disjoint-union-is-cospan [] = record { tri₁ = refl ; tri₂ = refl } ⊆-disjoint-union-is-cospan (x ∷ₙ d) = ∷ₙ-cospan d (⊆-disjoint-union-is-cospan d) ⊆-disjoint-union-is-cospan (refl ∷ₗ d) = ∷ₗ-cospan d (⊆-disjoint-union-is-cospan d) ⊆-disjoint-union-is-cospan (refl ∷ᵣ d) = ∷ᵣ-cospan d (⊆-disjoint-union-is-cospan d) ⊆-disjoint-union-cospan : ∀ {xs ys zs : List A} {τ₁ : xs ⊆ zs} {τ₂ : ys ⊆ zs} → Disjoint τ₁ τ₂ → Cospan τ₁ τ₂ ⊆-disjoint-union-cospan d = record { upperBound = ⊆-disjoint-union d ; isCospan = ⊆-disjoint-union-is-cospan d }
34.816901
102
0.569175
fd59ca1e8e8fd37e1ee0c998863e04aa91a08403
29,614
agda
Agda
theorems/cohomology/CupProduct/OnEM/InLowDegrees.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
294
2015-01-09T16:23:23.000Z
2022-03-20T13:54:45.000Z
theorems/cohomology/CupProduct/OnEM/InLowDegrees.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
31
2015-03-05T20:09:00.000Z
2021-10-03T19:15:25.000Z
theorems/cohomology/CupProduct/OnEM/InLowDegrees.agda
AntoineAllioux/HoTT-Agda
1037d82edcf29b620677a311dcfd4fc2ade2faa6
[ "MIT" ]
50
2015-01-10T01:48:08.000Z
2022-02-14T03:03:25.000Z
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import homotopy.EilenbergMacLane open import homotopy.EilenbergMacLane1 open import homotopy.EilenbergMacLaneFunctor open import homotopy.EM1HSpaceAssoc open import lib.types.TwoSemiCategory open import lib.two-semi-categories.FunCategory open import lib.two-semi-categories.FundamentalCategory module cohomology.CupProduct.OnEM.InLowDegrees {i} {j} (G : AbGroup i) (H : AbGroup j) where private module G = AbGroup G module H = AbGroup H module G⊗H = TensorProduct G H open G⊗H using (_⊗_) open EMExplicit ⊙×-cp₀₀' : G.⊙El ⊙× H.⊙El ⊙→ G⊗H.⊙El ⊙×-cp₀₀' = uncurry G⊗H._⊗_ , G⊗H.⊗-unit-l H.ident ⊙×-cp₀₀-seq : (⊙EM G 0 ⊙× ⊙EM H 0) ⊙–→ ⊙EM G⊗H.abgroup 0 ⊙×-cp₀₀-seq = ⊙–> (⊙emloop-equiv G⊗H.grp) ◃⊙∘ ⊙×-cp₀₀' ◃⊙∘ ⊙×-fmap (⊙<– (⊙emloop-equiv G.grp)) (⊙<– (⊙emloop-equiv H.grp)) ◃⊙idf ⊙×-cp₀₀ : ⊙EM G 0 ⊙× ⊙EM H 0 ⊙→ ⊙EM G⊗H.abgroup 0 ⊙×-cp₀₀ = ⊙compose ⊙×-cp₀₀-seq ×-cp₀₀ : EM G 0 × EM H 0 → EM G⊗H.abgroup 0 ×-cp₀₀ = fst ⊙×-cp₀₀ open EM₁HSpaceAssoc G⊗H.abgroup hiding (comp-functor) renaming (mult to EM₁-mult) public cp₀₁ : G.El → EM₁ H.grp → EM₁ G⊗H.grp cp₀₁ g = EM₁-fmap (G⊗H.ins-r-hom g) abstract cp₀₁-emloop-β : ∀ g h → ap (cp₀₁ g) (emloop h) == emloop (g ⊗ h) cp₀₁-emloop-β g = EM₁-fmap-emloop-β (G⊗H.ins-r-hom g) cp₀₁-distr-l : (g₁ g₂ : G.El) (y : EM₁ H.grp) → cp₀₁ (G.comp g₁ g₂) y == EM₁-mult (cp₀₁ g₁ y) (cp₀₁ g₂ y) cp₀₁-distr-l g₁ g₂ = EM₁-set-elim {P = λ x → f x == g x} {{λ x → has-level-apply (EM₁-level₁ G⊗H.grp) _ _}} idp loop' where f : EM₁ H.grp → EM₁ G⊗H.grp f x = cp₀₁ (G.comp g₁ g₂) x g : EM₁ H.grp → EM₁ G⊗H.grp g x = EM₁-mult (cp₀₁ g₁ x) (cp₀₁ g₂ x) abstract loop' : (h : H.El) → idp == idp [ (λ x → f x == g x) ↓ emloop h ] loop' h = ↓-='-in {f = f} {g = g} {p = emloop h} {u = idp} {v = idp} $ idp ∙' ap g (emloop h) =⟨ ∙'-unit-l (ap g (emloop h)) ⟩ ap g (emloop h) =⟨ ! (ap2-diag (λ x y → EM₁-mult (cp₀₁ g₁ x) (cp₀₁ g₂ y)) (emloop h)) ⟩ ap2 (λ x y → EM₁-mult (cp₀₁ g₁ x) (cp₀₁ g₂ y)) (emloop h) (emloop h) =⟨ =ₛ-out $ ap2-out (λ x y → EM₁-mult (cp₀₁ g₁ x) (cp₀₁ g₂ y)) (emloop h) (emloop h) ⟩ ap (λ x → EM₁-mult (cp₀₁ g₁ x) embase) (emloop h) ∙ ap (cp₀₁ g₂) (emloop h) =⟨ ap2 _∙_ part (cp₀₁-emloop-β g₂ h) ⟩ emloop (g₁ ⊗ h) ∙ emloop (g₂ ⊗ h) =⟨ ! (emloop-comp (g₁ ⊗ h) (g₂ ⊗ h)) ⟩ emloop (G⊗H.comp (g₁ ⊗ h) (g₂ ⊗ h)) =⟨ ap emloop (! (G⊗H.⊗-lin-l g₁ g₂ h)) ⟩ emloop (G.comp g₁ g₂ ⊗ h) =⟨ ! (cp₀₁-emloop-β (G.comp g₁ g₂) h) ⟩ ap f (emloop h) =⟨ ! (∙-unit-r (ap f (emloop h))) ⟩ ap f (emloop h) ∙ idp =∎ where part : ap (λ x → EM₁-mult (cp₀₁ g₁ x) embase) (emloop h) == emloop (g₁ ⊗ h) part = ap (λ x → EM₁-mult (cp₀₁ g₁ x) embase) (emloop h) =⟨ ap-∘ (λ u → EM₁-mult u embase) (cp₀₁ g₁) (emloop h) ⟩ ap (λ u → EM₁-mult u embase) (ap (cp₀₁ g₁) (emloop h)) =⟨ ap (ap (λ u → EM₁-mult u embase)) (cp₀₁-emloop-β g₁ h) ⟩ ap (λ u → EM₁-mult u embase) (emloop (g₁ ⊗ h)) =⟨ mult-emloop-β (g₁ ⊗ h) embase ⟩ emloop (g₁ ⊗ h) =∎ module _ (g₁ g₂ g₃ : G.El) (y : EM₁ H.grp) where cp₀₁-distr-l₁ : cp₀₁ (G.comp (G.comp g₁ g₂) g₃) y =-= EM₁-mult (cp₀₁ g₁ y) (EM₁-mult (cp₀₁ g₂ y) (cp₀₁ g₃ y)) cp₀₁-distr-l₁ = cp₀₁ (G.comp (G.comp g₁ g₂) g₃) y =⟪ cp₀₁-distr-l (G.comp g₁ g₂) g₃ y ⟫ EM₁-mult (cp₀₁ (G.comp g₁ g₂) y) (cp₀₁ g₃ y) =⟪ ap (λ s → EM₁-mult s (cp₀₁ g₃ y)) (cp₀₁-distr-l g₁ g₂ y) ⟫ EM₁-mult (EM₁-mult (cp₀₁ g₁ y) (cp₀₁ g₂ y)) (cp₀₁ g₃ y) =⟪ H-⊙EM₁-assoc (cp₀₁ g₁ y) (cp₀₁ g₂ y) (cp₀₁ g₃ y) ⟫ EM₁-mult (cp₀₁ g₁ y) (EM₁-mult (cp₀₁ g₂ y) (cp₀₁ g₃ y)) ∎∎ cp₀₁-distr-l₂ : cp₀₁ (G.comp (G.comp g₁ g₂) g₃) y =-= EM₁-mult (cp₀₁ g₁ y) (EM₁-mult (cp₀₁ g₂ y) (cp₀₁ g₃ y)) cp₀₁-distr-l₂ = cp₀₁ (G.comp (G.comp g₁ g₂) g₃) y =⟪ ap (λ s → cp₀₁ s y) (G.assoc g₁ g₂ g₃) ⟫ cp₀₁ (G.comp g₁ (G.comp g₂ g₃)) y =⟪ cp₀₁-distr-l g₁ (G.comp g₂ g₃) y ⟫ EM₁-mult (cp₀₁ g₁ y) (cp₀₁ (G.comp g₂ g₃) y) =⟪ ap (EM₁-mult (cp₀₁ g₁ y)) (cp₀₁-distr-l g₂ g₃ y) ⟫ EM₁-mult (cp₀₁ g₁ y) (EM₁-mult (cp₀₁ g₂ y) (cp₀₁ g₃ y)) ∎∎ abstract cp₀₁-distr-l-coh : (g₁ g₂ g₃ : G.El) (y : EM₁ H.grp) → cp₀₁-distr-l₁ g₁ g₂ g₃ y =ₛ cp₀₁-distr-l₂ g₁ g₂ g₃ y cp₀₁-distr-l-coh g₁ g₂ g₃ = EM₁-prop-elim {P = λ y → cp₀₁-distr-l₁ g₁ g₂ g₃ y =ₛ cp₀₁-distr-l₂ g₁ g₂ g₃ y} {{λ y → =ₛ-level (EM₁-level₁ G⊗H.grp)}} $ idp ◃∙ idp ◃∙ idp ◃∎ =ₛ₁⟨ 0 & 1 & ! (ap-cst embase (G.assoc g₁ g₂ g₃)) ⟩ ap (cst embase) (G.assoc g₁ g₂ g₃) ◃∙ idp ◃∙ idp ◃∎ ∎ₛ cp₀₁-functor : TwoSemiFunctor (group-to-cat G.grp) (fun-cat (EM₁ H.grp) EM₁-2-semi-category) cp₀₁-functor = record { F₀ = λ _ _ → unit ; F₁ = λ g x → cp₀₁ g x ; pres-comp = λ g₁ g₂ → λ= (cp₀₁-distr-l g₁ g₂) ; pres-comp-coh = λ g₁ g₂ g₃ → pres-comp-coh g₁ g₂ g₃ -- TODO: for some reason, this last field takes a really long time to check -- it is recommended to comment it out } where abstract pres-comp-coh : ∀ g₁ g₂ g₃ → λ= (cp₀₁-distr-l (G.comp g₁ g₂) g₃) ◃∙ ap (λ s y → EM₁-mult (s y) (cp₀₁ g₃ y)) (λ= (cp₀₁-distr-l g₁ g₂)) ◃∙ λ= (λ y → H-⊙EM₁-assoc (cp₀₁ g₁ y) (cp₀₁ g₂ y) (cp₀₁ g₃ y)) ◃∎ =ₛ ap (λ s → cp₀₁ s) (G.assoc g₁ g₂ g₃) ◃∙ λ= (cp₀₁-distr-l g₁ (G.comp g₂ g₃)) ◃∙ ap (λ s y → EM₁-mult (cp₀₁ g₁ y) (s y)) (λ= (cp₀₁-distr-l g₂ g₃)) ◃∎ pres-comp-coh g₁ g₂ g₃ = λ= (cp₀₁-distr-l (G.comp g₁ g₂) g₃) ◃∙ ap (λ s y → EM₁-mult (s y) (cp₀₁ g₃ y)) (λ= (cp₀₁-distr-l g₁ g₂)) ◃∙ λ= (λ y → H-⊙EM₁-assoc (cp₀₁ g₁ y) (cp₀₁ g₂ y) (cp₀₁ g₃ y)) ◃∎ =ₛ₁⟨ 1 & 1 & λ=-ap (λ y s → EM₁-mult s (cp₀₁ g₃ y)) (cp₀₁-distr-l g₁ g₂) ⟩ λ= (cp₀₁-distr-l (G.comp g₁ g₂) g₃) ◃∙ λ= (λ y → ap (λ s → EM₁-mult s (cp₀₁ g₃ y)) (cp₀₁-distr-l g₁ g₂ y)) ◃∙ λ= (λ y → H-⊙EM₁-assoc (cp₀₁ g₁ y) (cp₀₁ g₂ y) (cp₀₁ g₃ y)) ◃∎ =ₛ⟨ ∙∙-λ= (cp₀₁-distr-l (G.comp g₁ g₂) g₃) (λ y → ap (λ s → EM₁-mult s (cp₀₁ g₃ y)) (cp₀₁-distr-l g₁ g₂ y)) (λ y → H-⊙EM₁-assoc (cp₀₁ g₁ y) (cp₀₁ g₂ y) (cp₀₁ g₃ y)) ⟩ λ= (λ y → ↯ (cp₀₁-distr-l₁ g₁ g₂ g₃ y)) ◃∎ =ₛ₁⟨ ap λ= (λ= (λ y → =ₛ-out (cp₀₁-distr-l-coh g₁ g₂ g₃ y))) ⟩ λ= (λ y → ↯ (cp₀₁-distr-l₂ g₁ g₂ g₃ y)) ◃∎ =ₛ⟨ λ=-∙∙ (λ y → ap (λ s → cp₀₁ s y) (G.assoc g₁ g₂ g₃)) (cp₀₁-distr-l g₁ (G.comp g₂ g₃)) (λ y → ap (EM₁-mult (cp₀₁ g₁ y)) (cp₀₁-distr-l g₂ g₃ y)) ⟩ λ= (λ y → ap (λ s → cp₀₁ s y) (G.assoc g₁ g₂ g₃)) ◃∙ λ= (cp₀₁-distr-l g₁ (G.comp g₂ g₃)) ◃∙ λ= (λ y → ap (EM₁-mult (cp₀₁ g₁ y)) (cp₀₁-distr-l g₂ g₃ y)) ◃∎ =ₛ₁⟨ 0 & 1 & ap λ= (λ= (λ y → ap-∘ (λ f → f y) cp₀₁ (G.assoc g₁ g₂ g₃))) ⟩ λ= (app= (ap (λ s → cp₀₁ s) (G.assoc g₁ g₂ g₃))) ◃∙ λ= (cp₀₁-distr-l g₁ (G.comp g₂ g₃)) ◃∙ λ= (λ y → ap (EM₁-mult (cp₀₁ g₁ y)) (cp₀₁-distr-l g₂ g₃ y)) ◃∎ =ₛ₁⟨ 0 & 1 & ! (λ=-η (ap (λ s → cp₀₁ s) (G.assoc g₁ g₂ g₃))) ⟩ ap (λ s → cp₀₁ s) (G.assoc g₁ g₂ g₃) ◃∙ λ= (cp₀₁-distr-l g₁ (G.comp g₂ g₃)) ◃∙ λ= (λ y → ap (EM₁-mult (cp₀₁ g₁ y)) (cp₀₁-distr-l g₂ g₃ y)) ◃∎ =ₛ₁⟨ 2 & 1 & ! (λ=-ap (λ y s → EM₁-mult (cp₀₁ g₁ y) s) (cp₀₁-distr-l g₂ g₃)) ⟩ ap (λ s → cp₀₁ s) (G.assoc g₁ g₂ g₃) ◃∙ λ= (cp₀₁-distr-l g₁ (G.comp g₂ g₃)) ◃∙ ap (λ s y → EM₁-mult (cp₀₁ g₁ y) (s y)) (λ= (cp₀₁-distr-l g₂ g₃)) ◃∎ ∎ₛ comp-functor : TwoSemiFunctor EM₁-2-semi-category (=ₜ-fundamental-cat (Susp (EM₁ G⊗H.grp))) comp-functor = record { F₀ = λ _ → [ north ] ; F₁ = λ x → [ η x ] ; pres-comp = comp ; pres-comp-coh = comp-coh } -- this is *exactly* the same as -- `EM₁HSpaceAssoc.comp-functor G⊗H.abgroup` -- inlined but Agda chokes on this shorter definition module _ where private T : TwoSemiCategory (lmax i j) (lmax i j) T = fun-cat (EM₁ H.grp) (=ₜ-fundamental-cat (Susp (EM₁ G⊗H.grp))) module T = TwoSemiCategory T cst-north : T.El cst-north = λ _ → [ north ] T-comp' = T.comp {x = cst-north} {y = cst-north} {z = cst-north} T-assoc' = T.assoc {x = cst-north} {y = cst-north} {z = cst-north} {w = cst-north} group-to-EM₁→EM₂ : TwoSemiFunctor (group-to-cat G.grp) T group-to-EM₁→EM₂ = cp₀₁-functor –F→ fun-functor-map (EM₁ H.grp) comp-functor abstract app=-group-to-EM₁→EM₂-pres-comp-embase : ∀ g₁ g₂ → app= (TwoSemiFunctor.pres-comp group-to-EM₁→EM₂ g₁ g₂) embase == comp embase embase app=-group-to-EM₁→EM₂-pres-comp-embase g₁ g₂ = =ₛ-out $ app= (TwoSemiFunctor.pres-comp group-to-EM₁→EM₂ g₁ g₂) embase ◃∎ =ₛ⟨ ap-seq-=ₛ (λ f → f embase) (comp-functors-pres-comp-β cp₀₁-functor G₁₂ g₁ g₂) ⟩ app= (ap (TwoSemiFunctor.F₁ G₁₂) (TwoSemiFunctor.pres-comp cp₀₁-functor g₁ g₂)) embase ◃∙ app= (TwoSemiFunctor.pres-comp G₁₂ (cp₀₁ g₁) (cp₀₁ g₂)) embase ◃∎ =ₛ⟨ 0 & 1 & =ₛ-in {t = []} $ app= (ap (λ f x → [ η (f x) ]) (λ= (cp₀₁-distr-l g₁ g₂))) embase =⟨ ap (λ w → app= w embase) (λ=-ap (λ _ y → [ η y ]) (cp₀₁-distr-l g₁ g₂)) ⟩ app= (λ= (λ a → ap (λ y → [ η y ]) (cp₀₁-distr-l g₁ g₂ a))) embase =⟨ app=-β (λ a → ap (λ y → [ η y ]) (cp₀₁-distr-l g₁ g₂ a)) embase ⟩ idp =∎ ⟩ app= (TwoSemiFunctor.pres-comp G₁₂ (cp₀₁ g₁) (cp₀₁ g₂)) embase ◃∎ =ₛ₁⟨ app=-β (λ y → comp (cp₀₁ g₁ y) (cp₀₁ g₂ y)) embase ⟩ comp embase embase ◃∎ ∎ₛ where G₁₂ = fun-functor-map (EM₁ H.grp) comp-functor module CP₁₁ where private C : Type (lmax i j) C = EM₁ H.grp → EM G⊗H.abgroup 2 C-level : has-level 2 C C-level = Π-level (λ _ → EM-level G⊗H.abgroup 2) D₀ : TwoSemiCategory lzero i D₀ = group-to-cat G.grp D₁' : TwoSemiCategory (lmax i j) (lmax i j) D₁' = =ₜ-fundamental-cat (Susp (EM₁ G⊗H.grp)) D₁ : TwoSemiCategory (lmax i j) (lmax i j) D₁ = fun-cat (EM₁ H.grp) D₁' D₂' : TwoSemiCategory (lmax i j) (lmax i j) D₂' = 2-type-fundamental-cat (EM G⊗H.abgroup 2) D₂ : TwoSemiCategory (lmax i j) (lmax i j) D₂ = fun-cat (EM₁ H.grp) D₂' D₃ : TwoSemiCategory (lmax i j) (lmax i j) D₃ = 2-type-fundamental-cat (EM₁ H.grp → EM G⊗H.abgroup 2) {{C-level}} F₀₁ : TwoSemiFunctor D₀ D₁ F₀₁ = group-to-EM₁→EM₂ F₁₂' : TwoSemiFunctor D₁' D₂' F₁₂' = =ₜ-to-2-type-fundamental-cat (Susp (EM₁ G⊗H.grp)) F₁₂ : TwoSemiFunctor D₁ D₂ F₁₂ = fun-functor-map (EM₁ H.grp) F₁₂' F₀₂ : TwoSemiFunctor D₀ D₂ F₀₂ = F₀₁ –F→ F₁₂ module F₂₃-Funext = FunextFunctors (EM₁ H.grp) (EM G⊗H.abgroup 2) {{⟨⟩}} F₂₃ : TwoSemiFunctor D₂ D₃ F₂₃ = F₂₃-Funext.λ=-functor module F₀₂ = TwoSemiFunctor F₀₂ module F₂₃ = TwoSemiFunctor F₂₃ private module F₀₃-Comp = FunctorComposition F₀₂ F₂₃ F₀₃ : TwoSemiFunctor D₀ D₃ F₀₃ = F₀₃-Comp.composition module F₀₁ = TwoSemiFunctor F₀₁ module F₁₂ = TwoSemiFunctor F₁₂ module F₁₂' = TwoSemiFunctor F₁₂' module F₀₃ = TwoSemiFunctor F₀₃ module CP₁₁-Rec = EM₁Rec {G = G.grp} {C = C} {{C-level}} F₀₃ abstract cp₁₁ : EM₁ G.grp → EM₁ H.grp → EM G⊗H.abgroup 2 cp₁₁ = CP₁₁-Rec.f cp₁₁-embase-β : cp₁₁ embase ↦ (λ _ → [ north ]) cp₁₁-embase-β = CP₁₁-Rec.embase-β {-# REWRITE cp₁₁-embase-β #-} cp₁₁-emloop-β : ∀ g → ap cp₁₁ (emloop g) == λ= (λ y → ap [_] (η (cp₀₁ g y))) cp₁₁-emloop-β g = CP₁₁-Rec.emloop-β g app=-F₀₂-pres-comp-embase-β : ∀ g₁ g₂ → app= (F₀₂.pres-comp g₁ g₂) embase ◃∎ =ₛ ap (ap [_]) (comp-l embase) ◃∙ ap-∙ [_] (η embase) (η embase) ◃∎ app=-F₀₂-pres-comp-embase-β g₁ g₂ = app= (F₀₂.pres-comp g₁ g₂) embase ◃∎ =ₛ⟨ ap-seq-=ₛ (λ f → f embase) (comp-functors-pres-comp-β F₀₁ F₁₂ g₁ g₂) ⟩ app= (ap (λ α y → <– (=ₜ-equiv [ north ] [ north ]) (α y)) (F₀₁.pres-comp g₁ g₂)) embase ◃∙ app= (F₁₂.pres-comp {x = λ _ → [ north ]} {y = λ _ → [ north ]} {z = λ _ → [ north ]} (λ y → [ η (cp₀₁ g₁ y) ]₁) (λ y → [ η (cp₀₁ g₂ y) ]₁)) embase ◃∎ =ₛ₁⟨ 0 & 1 & step₂ ⟩ ap (ap [_]) (comp-l embase) ◃∙ app= (F₁₂.pres-comp {x = λ _ → [ north ]} {y = λ _ → [ north ]} {z = λ _ → [ north ]} (λ y → [ η (cp₀₁ g₁ y) ]₁) (λ y → [ η (cp₀₁ g₂ y) ]₁)) embase ◃∎ =ₛ₁⟨ 1 & 1 & step₃ ⟩ ap (ap [_]) (comp-l embase) ◃∙ ap-∙ [_] (η embase) (η embase) ◃∎ ∎ₛ where step₂ : app= (ap (λ α y → <– (=ₜ-equiv [ north ] [ north ]) (α y)) (F₀₁.pres-comp g₁ g₂)) embase == ap (ap [_]) (comp-l embase) step₂ = app= (ap (λ α y → <– (=ₜ-equiv [ north ] [ north ]) (α y)) (F₀₁.pres-comp g₁ g₂)) embase =⟨ ∘-ap (λ f → f embase) (λ α y → <– (=ₜ-equiv [ north ] [ north ]) (α y)) (F₀₁.pres-comp g₁ g₂) ⟩ ap (λ α → <– (=ₜ-equiv [ north ] [ north ]) (α embase)) (F₀₁.pres-comp g₁ g₂) =⟨ ap-∘ (<– (=ₜ-equiv [ north ] [ north ])) (λ f → f embase) (F₀₁.pres-comp g₁ g₂) ⟩ ap (<– (=ₜ-equiv [ north ] [ north ])) (app= (F₀₁.pres-comp g₁ g₂) embase) =⟨ ap (ap (<– (=ₜ-equiv [ north ] [ north ]))) (app=-group-to-EM₁→EM₂-pres-comp-embase g₁ g₂) ⟩ ap (<– (=ₜ-equiv [ north ] [ north ])) (comp embase embase) =⟨ ap (ap (<– (=ₜ-equiv [ north ] [ north ]))) (comp-unit-l embase) ⟩ ap (<– (=ₜ-equiv [ north ] [ north ])) (comp-l₁ embase) =⟨ ∘-ap (<– (=ₜ-equiv [ north ] [ north ])) [_]₁ (comp-l embase) ⟩ ap (ap [_]) (comp-l embase) =∎ step₃ : app= (F₁₂.pres-comp {x = λ _ → [ north ]₂} {y = λ _ → [ north ]₂} {z = λ _ → [ north ]₂} (λ y → [ η (cp₀₁ g₁ y) ]₁) (λ y → [ η (cp₀₁ g₂ y) ]₁)) embase == ap-∙ [_] (η embase) (η embase) step₃ = app= (F₁₂.pres-comp {x = λ _ → [ north ]} {y = λ _ → [ north ]} {z = λ _ → [ north ]} (λ y → [ η (cp₀₁ g₁ y) ]₁) (λ y → [ η (cp₀₁ g₂ y) ]₁)) embase =⟨ app=-β (λ y → F₁₂'.pres-comp {x = [ north ]} {y = [ north ]} {z = [ north ]} [ η (cp₀₁ g₁ y) ]₁ [ η (cp₀₁ g₂ y) ]₁) embase ⟩ F₁₂'.pres-comp {x = [ north ]} {y = [ north ]} {z = [ north ]} [ η embase ]₁ [ η embase ]₁ =⟨ =ₜ-to-2-type-fundamental-cat-pres-comp-β (Susp (EM₁ G⊗H.grp)) (η embase) (η embase) ⟩ ap-∙ [_] (η embase) (η embase) =∎ app=-F₀₂-pres-comp-embase-coh : ∀ g₁ g₂ → app= (F₀₂.pres-comp g₁ g₂) embase ◃∙ ap2 _∙_ (ap (ap [_]) (!-inv-r (merid embase))) (ap (ap [_]) (!-inv-r (merid embase))) ◃∎ =ₛ ap (ap [_]) (!-inv-r (merid embase)) ◃∎ app=-F₀₂-pres-comp-embase-coh g₁ g₂ = app= (F₀₂.pres-comp g₁ g₂) embase ◃∙ ap2 _∙_ (ap (ap [_]) (!-inv-r (merid embase))) (ap (ap [_]) (!-inv-r (merid embase))) ◃∎ =ₛ⟨ 0 & 1 & app=-F₀₂-pres-comp-embase-β g₁ g₂ ⟩ ap (ap [_]) (comp-l embase) ◃∙ ap-∙ [_] (η embase) (η embase) ◃∙ ap2 _∙_ (ap (ap [_]) (!-inv-r (merid embase))) (ap (ap [_]) (!-inv-r (merid embase))) ◃∎ =ₛ₁⟨ 2 & 1 & ap2-ap-lr _∙_ (ap [_]) (ap [_]) (!-inv-r (merid embase)) (!-inv-r (merid embase)) ⟩ ap (ap [_]) (comp-l embase) ◃∙ ap-∙ [_] (η embase) (η embase) ◃∙ ap2 (λ s t → ap [_] s ∙ ap [_] t) (!-inv-r (merid embase)) (!-inv-r (merid embase)) ◃∎ =ₛ⟨ 1 & 2 & !ₛ $ homotopy-naturality2 (λ s t → ap [_] (s ∙ t)) (λ s t → ap [_] s ∙ ap [_] t) (ap-∙ [_]) (!-inv-r (merid embase)) (!-inv-r (merid embase)) ⟩ ap (ap [_]) (comp-l embase) ◃∙ ap2 (λ s t → ap [_] (s ∙ t)) (!-inv-r (merid embase)) (!-inv-r (merid embase)) ◃∙ idp ◃∎ =ₛ⟨ 2 & 1 & expand [] ⟩ ap (ap [_]) (comp-l embase) ◃∙ ap2 (λ s t → ap [_] (s ∙ t)) (!-inv-r (merid embase)) (!-inv-r (merid embase)) ◃∎ =ₛ₁⟨ 1 & 1 & ! (ap-ap2 (ap [_]) _∙_ (!-inv-r (merid embase)) (!-inv-r (merid embase))) ⟩ ap (ap [_]) (comp-l embase) ◃∙ ap (ap [_]) (ap2 _∙_ (!-inv-r (merid embase)) (!-inv-r (merid embase))) ◃∎ =ₛ⟨ ap-seq-=ₛ (ap [_]) step₇' ⟩ ap (ap [_]) (!-inv-r (merid embase)) ◃∎ ∎ₛ where helper : ∀ {i} {A : Type i} {a₀ a₁ : A} (p : a₀ == a₁) → add-path-inverse-l (p ∙ ! p) p ◃∙ ap2 _∙_ (!-inv-r p) (!-inv-r p) ◃∎ =ₛ !-inv-r p ◃∎ helper idp = =ₛ-in idp step₇' : comp-l embase ◃∙ ap2 _∙_ (!-inv-r (merid embase)) (!-inv-r (merid embase)) ◃∎ =ₛ !-inv-r (merid embase) ◃∎ step₇' = helper (merid embase) app=-ap-cp₁₁-seq : ∀ g y → app= (ap cp₁₁ (emloop g)) y =-= ap [_] (η (cp₀₁ g y)) app=-ap-cp₁₁-seq g y = app= (ap cp₁₁ (emloop g)) y =⟪ ap (λ p → app= p y) (cp₁₁-emloop-β g) ⟫ app= (λ= (λ x → ap [_] (η (cp₀₁ g x)))) y =⟪ app=-β (λ x → ap [_] (η (cp₀₁ g x))) y ⟫ ap [_] (η (cp₀₁ g y)) ∎∎ app=-ap-cp₁₁ : ∀ g y → app= (ap cp₁₁ (emloop g)) y == ap [_] (η (cp₀₁ g y)) app=-ap-cp₁₁ g y = ↯ (app=-ap-cp₁₁-seq g y) app=-ap-cp₁₁-coh-seq₁ : ∀ g₁ g₂ y → app= (ap cp₁₁ (emloop (G.comp g₁ g₂))) y =-= ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y)) app=-ap-cp₁₁-coh-seq₁ g₁ g₂ y = app= (ap cp₁₁ (emloop (G.comp g₁ g₂))) y =⟪ ap (λ u → app= (ap cp₁₁ u) y) (emloop-comp g₁ g₂) ⟫ app= (ap cp₁₁ (emloop g₁ ∙ emloop g₂)) y =⟪ ap (λ u → app= u y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ⟫ app= (ap cp₁₁ (emloop g₁) ∙ ap cp₁₁ (emloop g₂)) y =⟪ ap-∙ (λ f → f y) (ap cp₁₁ (emloop g₁)) (ap cp₁₁ (emloop g₂)) ⟫ app= (ap cp₁₁ (emloop g₁)) y ∙ app= (ap cp₁₁ (emloop g₂)) y =⟪ ap2 _∙_ (app=-ap-cp₁₁ g₁ y) (app=-ap-cp₁₁ g₂ y) ⟫ ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y)) ∎∎ app=-ap-cp₁₁-coh-seq₂ : ∀ g₁ g₂ y → app= (ap cp₁₁ (emloop (G.comp g₁ g₂))) y =-= ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y)) app=-ap-cp₁₁-coh-seq₂ g₁ g₂ y = app= (ap cp₁₁ (emloop (G.comp g₁ g₂))) y =⟪ app=-ap-cp₁₁ (G.comp g₁ g₂) y ⟫ ap [_] (η (cp₀₁ (G.comp g₁ g₂) y)) =⟪ app= (F₀₂.pres-comp g₁ g₂) y ⟫ ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y)) ∎∎ abstract app=-ap-cp₁₁-coh : ∀ g₁ g₂ y → app=-ap-cp₁₁-coh-seq₁ g₁ g₂ y =ₛ app=-ap-cp₁₁-coh-seq₂ g₁ g₂ y app=-ap-cp₁₁-coh g₁ g₂ y = ap (λ u → app= (ap cp₁₁ u) y) (emloop-comp g₁ g₂) ◃∙ ap (λ u → app= u y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙ ap-∙ (λ f → f y) (ap cp₁₁ (emloop g₁)) (ap cp₁₁ (emloop g₂)) ◃∙ ap2 _∙_ (app=-ap-cp₁₁ g₁ y) (app=-ap-cp₁₁ g₂ y) ◃∎ =ₛ⟨ 3 & 2 & ap2-seq-∙ _∙_ (app=-ap-cp₁₁-seq g₁ y) (app=-ap-cp₁₁-seq g₂ y) ⟩ ap (λ u → app= (ap cp₁₁ u) y) (emloop-comp g₁ g₂) ◃∙ ap (λ u → app= u y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙ ap-∙ (λ f → f y) (ap cp₁₁ (emloop g₁)) (ap cp₁₁ (emloop g₂)) ◃∙ ap2 _∙_ (ap (λ z → app= z y) (cp₁₁-emloop-β g₁)) (ap (λ z → app= z y) (cp₁₁-emloop-β g₂)) ◃∙ ap2 _∙_ (app=-β (λ x → ap [_] (η (cp₀₁ g₁ x))) y) (app=-β (λ x → ap [_] (η (cp₀₁ g₂ x))) y) ◃∎ =ₛ₁⟨ 3 & 1 & ap2-ap-lr _∙_ (λ z → app= z y) (λ z → app= z y) (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂) ⟩ ap (λ u → app= (ap cp₁₁ u) y) (emloop-comp g₁ g₂) ◃∙ ap (λ u → app= u y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙ ap-∙ (λ f → f y) (ap cp₁₁ (emloop g₁)) (ap cp₁₁ (emloop g₂)) ◃∙ ap2 (λ a b → app= a y ∙ app= b y) (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂) ◃∙ ap2 _∙_ (app=-β (λ x → ap [_] (η (cp₀₁ g₁ x))) y) (app=-β (λ x → ap [_] (η (cp₀₁ g₂ x))) y) ◃∎ =ₛ⟨ 2 & 2 & !ₛ $ homotopy-naturality2 (λ a b → app= (a ∙ b) y) (λ a b → app= a y ∙ app= b y) (ap-∙ (λ f → f y)) (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂) ⟩ ap (λ u → app= (ap cp₁₁ u) y) (emloop-comp g₁ g₂) ◃∙ ap (λ u → app= u y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙ ap2 (λ a b → app= (a ∙ b) y) (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂) ◃∙ ap-∙ (λ f → f y) (λ= (λ y' → ap [_] (η (cp₀₁ g₁ y')))) (λ= (λ y' → ap [_] (η (cp₀₁ g₂ y')))) ◃∙ ap2 _∙_ (app=-β (λ x → ap [_] (η (cp₀₁ g₁ x))) y) (app=-β (λ x → ap [_] (η (cp₀₁ g₂ x))) y) ◃∎ =ₛ⟨ 3 & 2 & app=-β-coh (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))) y ⟩ ap (λ x → app= (ap cp₁₁ x) y) (emloop-comp g₁ g₂) ◃∙ ap (λ p → app= p y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙ ap2 (λ a b → app= (a ∙ b) y) (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂) ◃∙ ap (λ p → app= p y) (=ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))))) ◃∙ app=-β (λ x → ap [_] (η (cp₀₁ g₁ x)) ∙ ap [_] (η (cp₀₁ g₂ x))) y ◃∎ =ₛ₁⟨ 0 & 1 & ap-∘ (λ p → app= p y) (ap cp₁₁) (emloop-comp g₁ g₂) ⟩ ap (λ p → app= p y) (ap (ap cp₁₁) (emloop-comp g₁ g₂)) ◃∙ ap (λ p → app= p y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙ ap2 (λ a b → app= (a ∙ b) y) (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂) ◃∙ ap (λ p → app= p y) (=ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))))) ◃∙ app=-β (λ x → ap [_] (η (cp₀₁ g₁ x)) ∙ ap [_] (η (cp₀₁ g₂ x))) y ◃∎ =ₛ₁⟨ 2 & 1 & ! (ap-ap2 (λ p → app= p y) _∙_ (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂)) ⟩ ap (λ p → app= p y) (ap (ap cp₁₁) (emloop-comp g₁ g₂)) ◃∙ ap (λ p → app= p y) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙ ap (λ p → app= p y) (ap2 _∙_ (cp₁₁-emloop-β g₁) (cp₁₁-emloop-β g₂)) ◃∙ ap (λ p → app= p y) (=ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))))) ◃∙ app=-β (λ x → ap [_] (η (cp₀₁ g₁ x)) ∙ ap [_] (η (cp₀₁ g₂ x))) y ◃∎ =ₛ⟨ 0 & 3 & ap-seq-=ₛ (λ p → app= p y) (CP₁₁-Rec.emloop-comp-path g₁ g₂) ⟩ ap (λ p → app= p y) (cp₁₁-emloop-β (G.comp g₁ g₂)) ◃∙ ap (λ p → app= p y) (F₀₃.pres-comp g₁ g₂) ◃∙ ap (λ p → app= p y) (=ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))))) ◃∙ app=-β (λ x → ap [_] (η (cp₀₁ g₁ x)) ∙ ap [_] (η (cp₀₁ g₂ x))) y ◃∎ =ₛ⟨ 1 & 2 & step₈ ⟩ ap (λ p → app= p y) (cp₁₁-emloop-β (G.comp g₁ g₂)) ◃∙ ap (λ p → app= p y) (ap λ= (F₀₂.pres-comp g₁ g₂)) ◃∙ app=-β (λ x → ap [_] (η (cp₀₁ g₁ x)) ∙ ap [_] (η (cp₀₁ g₂ x))) y ◃∎ =ₛ₁⟨ 1 & 1 & ∘-ap (λ p → app= p y) λ= (F₀₂.pres-comp g₁ g₂) ⟩ ap (λ p → app= p y) (cp₁₁-emloop-β (G.comp g₁ g₂)) ◃∙ ap (λ γ → app= (λ= γ) y) (F₀₂.pres-comp g₁ g₂) ◃∙ app=-β (λ x → ap [_] (η (cp₀₁ g₁ x)) ∙ ap [_] (η (cp₀₁ g₂ x))) y ◃∎ =ₛ⟨ 1 & 2 & homotopy-naturality (λ γ → app= (λ= γ) y) (λ γ → γ y) (λ γ → app=-β γ y) (F₀₂.pres-comp g₁ g₂) ⟩ ap (λ p → app= p y) (cp₁₁-emloop-β (G.comp g₁ g₂)) ◃∙ app=-β (λ x → ap [_] (η (cp₀₁ (G.comp g₁ g₂) x))) y ◃∙ app= (F₀₂.pres-comp g₁ g₂) y ◃∎ =ₛ⟨ 0 & 2 & contract ⟩ app=-ap-cp₁₁ (G.comp g₁ g₂) y ◃∙ app= (F₀₂.pres-comp g₁ g₂) y ◃∎ ∎ₛ where step₈ : ap (λ p → app= p y) (F₀₃.pres-comp g₁ g₂) ◃∙ ap (λ p → app= p y) (=ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))))) ◃∎ =ₛ ap (λ p → app= p y) (ap λ= (F₀₂.pres-comp g₁ g₂)) ◃∎ step₈ = ap-seq-=ₛ (λ p → app= p y) $ F₀₃.pres-comp g₁ g₂ ◃∙ =ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x)))) ◃∎ =ₛ⟨ 0 & 1 & F₀₃-Comp.pres-comp-β g₁ g₂ ⟩ ap λ= (F₀₂.pres-comp g₁ g₂) ◃∙ F₂₃.pres-comp (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))) ◃∙ =ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x)))) ◃∎ =ₛ₁⟨ 1 & 1 & F₂₃-Funext.λ=-functor-pres-comp=λ=-∙ (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x))) ⟩ ap λ= (F₀₂.pres-comp g₁ g₂) ◃∙ =ₛ-out (λ=-∙ (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x)))) ◃∙ =ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x)))) ◃∎ =ₛ⟨ 1 & 2 & seq-!-inv-l (=ₛ-out (∙-λ= (λ x → ap [_] (η (cp₀₁ g₁ x))) (λ x → ap [_] (η (cp₀₁ g₂ x)))) ◃∎) ⟩ ap λ= (F₀₂.pres-comp g₁ g₂) ◃∎ ∎ₛ ap-cp₁₁-seq : ∀ g y → ap (λ x → cp₁₁ x y) (emloop g) =-= ap [_] (η (cp₀₁ g y)) ap-cp₁₁-seq g y = ap (λ x → cp₁₁ x y) (emloop g) =⟪ ap-∘ (λ f → f y) cp₁₁ (emloop g) ⟫ ap (λ f → f y) (ap cp₁₁ (emloop g)) =⟪ app=-ap-cp₁₁ g y ⟫ ap [_] (η (cp₀₁ g y)) ∎∎ ap-cp₁₁ : ∀ g y → ap (λ x → cp₁₁ x y) (emloop g) == ap [_] (η (cp₀₁ g y)) ap-cp₁₁ g y = ↯ (ap-cp₁₁-seq g y) ap-cp₁₁-coh-seq₁ : ∀ g₁ g₂ y → ap (λ x → cp₁₁ x y) (emloop (G.comp g₁ g₂)) =-= ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y)) ap-cp₁₁-coh-seq₁ g₁ g₂ y = ap (λ x → cp₁₁ x y) (emloop (G.comp g₁ g₂)) =⟪ ap (ap (λ x → cp₁₁ x y)) (emloop-comp g₁ g₂) ⟫ ap (λ x → cp₁₁ x y) (emloop g₁ ∙ emloop g₂) =⟪ ap-∙ (λ x → cp₁₁ x y) (emloop g₁) (emloop g₂) ⟫ ap (λ x → cp₁₁ x y) (emloop g₁) ∙ ap (λ x → cp₁₁ x y) (emloop g₂) =⟪ ap2 _∙_ (ap-cp₁₁ g₁ y) (ap-cp₁₁ g₂ y) ⟫ ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y)) ∎∎ ap-cp₁₁-coh-seq₂ : ∀ g₁ g₂ y → ap (λ x → cp₁₁ x y) (emloop (G.comp g₁ g₂)) =-= ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y)) ap-cp₁₁-coh-seq₂ g₁ g₂ y = ap (λ x → cp₁₁ x y) (emloop (G.comp g₁ g₂)) =⟪ ap-cp₁₁ (G.comp g₁ g₂) y ⟫ ap [_] (η (cp₀₁ (G.comp g₁ g₂) y)) =⟪ app= (F₀₂.pres-comp g₁ g₂) y ⟫ ap [_] (η (cp₀₁ g₁ y)) ∙ ap [_] (η (cp₀₁ g₂ y)) ∎∎ abstract ap-cp₁₁-coh : ∀ g₁ g₂ y → ap-cp₁₁-coh-seq₁ g₁ g₂ y =ₛ ap-cp₁₁-coh-seq₂ g₁ g₂ y ap-cp₁₁-coh g₁ g₂ y = ap (ap (λ x → cp₁₁ x y)) (emloop-comp g₁ g₂) ◃∙ ap-∙ (λ x → cp₁₁ x y) (emloop g₁) (emloop g₂) ◃∙ ap2 _∙_ (ap-cp₁₁ g₁ y) (ap-cp₁₁ g₂ y) ◃∎ =ₛ⟨ 2 & 1 & ap2-seq-∙ _∙_ (ap-cp₁₁-seq g₁ y) (ap-cp₁₁-seq g₂ y) ⟩ ap (ap (λ x → cp₁₁ x y)) (emloop-comp g₁ g₂) ◃∙ ap-∙ (λ x → cp₁₁ x y) (emloop g₁) (emloop g₂) ◃∙ ap2 _∙_ (ap-∘ (λ f → f y) cp₁₁ (emloop g₁)) (ap-∘ (λ f → f y) cp₁₁ (emloop g₂)) ◃∙ ap2 _∙_ (app=-ap-cp₁₁ g₁ y) (app=-ap-cp₁₁ g₂ y) ◃∎ =ₛ⟨ 1 & 2 & ap-∘-∙-coh (λ f → f y) cp₁₁ (emloop g₁) (emloop g₂) ⟩ ap (ap (λ x → cp₁₁ x y)) (emloop-comp g₁ g₂) ◃∙ ap-∘ (λ f → f y) cp₁₁ (emloop g₁ ∙ emloop g₂) ◃∙ ap (ap (λ f → f y)) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙ ap-∙ (λ f → f y) (ap cp₁₁ (emloop g₁)) (ap cp₁₁ (emloop g₂)) ◃∙ ap2 _∙_ (app=-ap-cp₁₁ g₁ y) (app=-ap-cp₁₁ g₂ y) ◃∎ =ₛ⟨ 0 & 2 & homotopy-naturality {A = embase' G.grp == embase} {B = cp₁₁ embase y == cp₁₁ embase y} (ap (λ x → cp₁₁ x y)) (λ p → app= (ap cp₁₁ p) y) (ap-∘ (λ f → f y) cp₁₁) (emloop-comp g₁ g₂) ⟩ ap-∘ (λ f → f y) cp₁₁ (emloop (G.comp g₁ g₂)) ◃∙ ap (λ p → app= (ap cp₁₁ p) y) (emloop-comp g₁ g₂) ◃∙ ap (ap (λ f → f y)) (ap-∙ cp₁₁ (emloop g₁) (emloop g₂)) ◃∙ ap-∙ (λ f → f y) (ap cp₁₁ (emloop g₁)) (ap cp₁₁ (emloop g₂)) ◃∙ ap2 _∙_ (app=-ap-cp₁₁ g₁ y) (app=-ap-cp₁₁ g₂ y) ◃∎ =ₛ⟨ 1 & 4 & app=-ap-cp₁₁-coh g₁ g₂ y ⟩ ap-∘ (λ f → f y) cp₁₁ (emloop (G.comp g₁ g₂)) ◃∙ app=-ap-cp₁₁ (G.comp g₁ g₂) y ◃∙ app= (F₀₂.pres-comp g₁ g₂) y ◃∎ =ₛ₁⟨ 0 & 2 & idp ⟩ ap-cp₁₁ (G.comp g₁ g₂) y ◃∙ app= (F₀₂.pres-comp g₁ g₂) y ◃∎ ∎ₛ ap-cp₁₁-embase-seq : ∀ g → ap (λ x → cp₁₁ x embase) (emloop g) =-= idp ap-cp₁₁-embase-seq g = ap (λ x → cp₁₁ x embase) (emloop g) =⟪ ap-cp₁₁ g embase ⟫ ap [_] (η (cp₀₁ g embase)) =⟪idp⟫ ap [_] (η embase) =⟪ ap (ap [_]) (!-inv-r (merid embase)) ⟫ ap [_] (idp {a = north}) =⟪idp⟫ idp ∎∎ ap-cp₁₁-embase : ∀ g → ap (λ x → cp₁₁ x embase) (emloop g) == idp ap-cp₁₁-embase g = ↯ (ap-cp₁₁-embase-seq g) ap-cp₁₁-embase-coh-seq : ∀ g₁ g₂ → ap (λ x → cp₁₁ x embase) (emloop (G.comp g₁ g₂)) =-= idp ap-cp₁₁-embase-coh-seq g₁ g₂ = ap (λ x → cp₁₁ x embase) (emloop (G.comp g₁ g₂)) =⟪ ap (ap (λ x → cp₁₁ x embase)) (emloop-comp g₁ g₂) ⟫ ap (λ x → cp₁₁ x embase) (emloop g₁ ∙ emloop g₂) =⟪ ap-∙ (λ x → cp₁₁ x embase) (emloop g₁) (emloop g₂) ⟫ ap (λ x → cp₁₁ x embase) (emloop g₁) ∙ ap (λ x → cp₁₁ x embase) (emloop g₂) =⟪ ap2 _∙_ (ap-cp₁₁-embase g₁) (ap-cp₁₁-embase g₂) ⟫ idp ∎∎ ap-cp₁₁-embase-coh : ∀ g₁ g₂ → ap-cp₁₁-embase (G.comp g₁ g₂) ◃∎ =ₛ ap-cp₁₁-embase-coh-seq g₁ g₂ ap-cp₁₁-embase-coh g₁ g₂ = ap-cp₁₁-embase (G.comp g₁ g₂) ◃∎ =ₛ⟨ expand (ap-cp₁₁-embase-seq (G.comp g₁ g₂)) ⟩ ap-cp₁₁ (G.comp g₁ g₂) embase ◃∙ ap (ap [_]) (!-inv-r (merid embase)) ◃∎ =ₛ⟨ 1 & 1 & !ₛ (app=-F₀₂-pres-comp-embase-coh g₁ g₂) ⟩ ap-cp₁₁ (G.comp g₁ g₂) embase ◃∙ app= (F₀₂.pres-comp g₁ g₂) embase ◃∙ ap2 _∙_ (ap (ap [_]) (!-inv-r (merid embase))) (ap (ap [_]) (!-inv-r (merid embase))) ◃∎ =ₛ⟨ 0 & 2 & !ₛ (ap-cp₁₁-coh g₁ g₂ embase) ⟩ ap (ap (λ x → cp₁₁ x embase)) (emloop-comp g₁ g₂) ◃∙ ap-∙ (λ x → cp₁₁ x embase) (emloop g₁) (emloop g₂) ◃∙ ap2 _∙_ (ap-cp₁₁ g₁ embase) (ap-cp₁₁ g₂ embase) ◃∙ ap2 _∙_ (ap (ap [_]) (!-inv-r (merid embase))) (ap (ap [_]) (!-inv-r (merid embase))) ◃∎ =ₛ⟨ 2 & 2 & ∙-ap2-seq _∙_ (ap-cp₁₁-embase-seq g₁) (ap-cp₁₁-embase-seq g₂) ⟩ ap (ap (λ x → cp₁₁ x embase)) (emloop-comp g₁ g₂) ◃∙ ap-∙ (λ x → cp₁₁ x embase) (emloop g₁) (emloop g₂) ◃∙ ap2 _∙_ (ap-cp₁₁-embase g₁) (ap-cp₁₁-embase g₂) ◃∎ ∎ₛ open CP₁₁ public
45.842105
123
0.485176
ade0111838217c2b8a230260a0181355bb4b6716
5,320
agda
Agda
Cubical/Modalities/Modality.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Modalities/Modality.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
Cubical/Modalities/Modality.agda
limemloh/cubical
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.Modalities.Modality where {- translated from https://github.com/HoTT/HoTT-Agda/blob/master/core/lib/types/Modality.agda -} open import Cubical.Foundations.Everything record Modality ℓ : Type (ℓ-suc ℓ) where field isModal : Type ℓ → Type ℓ isModalIsProp : {A : Type ℓ} → isProp (isModal A) ◯ : Type ℓ → Type ℓ -- \ciO ◯-isModal : {A : Type ℓ} → isModal (◯ A) η : {A : Type ℓ} → A → ◯ A ◯-elim : {A : Type ℓ} {B : ◯ A → Type ℓ} (B-modal : (x : ◯ A) → isModal (B x)) → ((x : A) → (B (η x))) → ((x : ◯ A) → B x) ◯-elim-β : {A : Type ℓ} {B : ◯ A → Type ℓ} (B-modal : (x : ◯ A) → isModal (B x)) (f : (x : A) → (B (η x))) → (a : A) → ◯-elim B-modal f (η a) ≡ f a ◯-=-isModal : {A : Type ℓ} (x y : ◯ A) → isModal (x ≡ y) ◯-Types : Type (ℓ-suc ℓ) ◯-Types = Σ[ A ∈ Type ℓ ] isModal A {- elimination rules -} module ◯Elim {A : Type ℓ} {B : ◯ A → Type ℓ} (B-modal : (x : ◯ A) → isModal (B x)) (η* : (x : A) → (B (η x))) where f : (x : ◯ A) → B x f = ◯-elim B-modal η* η-β : (a : A) → ◯-elim B-modal η* (η a) ≡ η* a η-β = ◯-elim-β B-modal η* module ◯Rec {A : Type ℓ} {B : Type ℓ} (B-modal : isModal B) (η* : A → B) = ◯Elim (λ _ → B-modal) η* ◯-rec = ◯Rec.f ◯-rec-β = ◯Rec.η-β {- functoriality -} module ◯Fmap {A B : Type ℓ} (f : A → B) = ◯Rec ◯-isModal (η ∘ f) ◯-map = ◯Fmap.f ◯-map-β = ◯Fmap.η-β ◯-preservesEquiv : {A B : Type ℓ} (f : A → B) → isEquiv f → isEquiv (◯-map f) ◯-preservesEquiv f f-ise = isoToIsEquiv (iso _ (◯-map inv) to-from from-to) where open Iso (equivToIso (f , f-ise)) abstract to-from : ∀ ◯b → ◯-map f (◯-map inv ◯b) ≡ ◯b to-from = ◯-elim (λ ◯b → ◯-=-isModal (◯-map f (◯-map inv ◯b)) ◯b) (λ b → cong (◯-map f) (◯-map-β inv b) ∙ ◯-map-β f (inv b) ∙ cong η (rightInv b)) from-to : ∀ ◯a → ◯-map inv (◯-map f ◯a) ≡ ◯a from-to = ◯-elim (λ ◯a → ◯-=-isModal (◯-map inv (◯-map f ◯a)) ◯a) (λ a → cong (◯-map inv) (◯-map-β f a) ∙ ◯-map-β inv (f a) ∙ cong η (leftInv a)) ◯-equiv : {A B : Type ℓ} → A ≃ B → ◯ A ≃ ◯ B ◯-equiv (f , f-ise) = ◯-map f , ◯-preservesEquiv f f-ise {- equivalences preserve being modal -} equivPreservesIsModal : {A B : Type ℓ} → A ≃ B → isModal A → isModal B equivPreservesIsModal eq = fst (pathToEquiv (cong isModal (ua eq))) {- modal types and [η] being an equivalence -} isModalToIsEquiv : {A : Type ℓ} → isModal A → isEquiv (η {A}) isModalToIsEquiv {A} w = isoToIsEquiv (iso (η {A}) η-inv inv-l inv-r) where η-inv : ◯ A → A η-inv = ◯-rec w (idfun A) abstract inv-r : (a : A) → η-inv (η a) ≡ a inv-r = ◯-rec-β w (idfun A) inv-l : (a : ◯ A) → η (η-inv a) ≡ a inv-l = ◯-elim (λ a₀ → ◯-=-isModal _ _) (λ a₀ → cong η (inv-r a₀)) abstract isEquivToIsModal : {A : Type ℓ} → isEquiv (η {A}) → isModal A isEquivToIsModal {A} eq = equivPreservesIsModal (invEquiv (η , eq)) ◯-isModal retractIsModal : {A B : Type ℓ} (w : isModal A) (f : A → B) (g : B → A) (r : (b : B) → f (g b) ≡ b) → isModal B retractIsModal {A} {B} w f g r = isEquivToIsModal (isoToIsEquiv (iso η η-inv inv-l inv-r)) where η-inv : ◯ B → B η-inv = f ∘ (◯-rec w g) inv-r : (b : B) → η-inv (η b) ≡ b inv-r b = cong f (◯-rec-β w g b) ∙ r b inv-l : (b : ◯ B) → η (η-inv b) ≡ b inv-l = ◯-elim (λ b → ◯-=-isModal _ _) (λ b → cong η (inv-r b)) {- function types with modal codomain are modal -} abstract Π-isModal : {A : Type ℓ} {B : A → Type ℓ} (w : (a : A) → isModal (B a)) → isModal ((x : A) → B x) Π-isModal {A} {B} w = retractIsModal {◯ _} {(x : A) → B x} ◯-isModal η-inv η r where η-inv : ◯ ((x : A) → B x) → (x : A) → B x η-inv φ' a = ◯-rec (w a) (λ φ → φ a) φ' r : (φ : (x : A) → B x) → η-inv (η φ) ≡ φ r φ = funExt (λ a → ◯-rec-β (w a) (λ φ₀ → φ₀ a) φ) →-isModal : {A B : Type ℓ} → isModal B → isModal (A → B) →-isModal w = Π-isModal (λ _ → w) {- sigma types of a modal dependent type with modal base are modal -} abstract Σ-isModal : {A : Type ℓ} (B : A → Type ℓ) → isModal A → ((a : A) → isModal (B a)) → isModal (Σ A B) Σ-isModal {A} B A-modal B-modal = retractIsModal {◯ (Σ A B)} {Σ A B} ◯-isModal η-inv η r where h : ◯ (Σ A B) → A h = ◯-rec A-modal fst h-β : (x : Σ A B) → h (η x) ≡ fst x h-β = ◯-rec-β A-modal fst f : (j : I) → (x : Σ A B) → B (h-β x j) f j x = transp (λ i → B (h-β x ((~ i) ∨ j))) j (snd x) k : (y : ◯ (Σ A B)) → B (h y) k = ◯-elim (B-modal ∘ h) (f i0) η-inv : ◯ (Σ A B) → Σ A B η-inv y = h y , k y p : (x : Σ A B) → k (η x) ≡ f i0 x p = ◯-elim-β (B-modal ∘ h) (f i0) almost : (x : Σ A B) → (h (η x) , f i0 x) ≡ x almost x i = h-β x i , f i x r : (x : Σ A B) → η-inv (η x) ≡ x r x = (λ i → h (η x) , p x i) ∙ (almost x)
32.242424
89
0.444737
a013278ea8ae21ec9d86a97fb77bad12b505053c
1,774
agda
Agda
Cubical/Categories/Constructions/Product.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
1
2022-03-05T00:29:41.000Z
2022-03-05T00:29:41.000Z
Cubical/Categories/Constructions/Product.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
Cubical/Categories/Constructions/Product.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
-- Product of two categories {-# OPTIONS --safe #-} module Cubical.Categories.Constructions.Product where open import Cubical.Categories.Category.Base open import Cubical.Categories.Functor.Base open import Cubical.Data.Sigma renaming (_×_ to _×'_) open import Cubical.Foundations.HLevels open import Cubical.Foundations.Prelude private variable ℓC ℓC' ℓD ℓD' ℓE ℓE' : Level open Category _×_ : (C : Category ℓC ℓC') → (D : Category ℓD ℓD') → Category (ℓ-max ℓC ℓD) (ℓ-max ℓC' ℓD') (C × D) .ob = (ob C) ×' (ob D) (C × D) .Hom[_,_] (c , d) (c' , d') = (C [ c , c' ]) ×' (D [ d , d' ]) (C × D) .id = (id C , id D) (C × D) ._⋆_ _ _ = (_ ⋆⟨ C ⟩ _ , _ ⋆⟨ D ⟩ _) (C × D) .⋆IdL _ = ≡-× (⋆IdL C _) (⋆IdL D _) (C × D) .⋆IdR _ = ≡-× (⋆IdR C _) (⋆IdR D _) (C × D) .⋆Assoc _ _ _ = ≡-× (⋆Assoc C _ _ _) (⋆Assoc D _ _ _) (C × D) .isSetHom = isSet× (isSetHom C) (isSetHom D) infixr 5 _×_ -- Some useful functors module _ (C : Category ℓC ℓC') (D : Category ℓD ℓD') where open Functor module _ (E : Category ℓE ℓE') where -- Associativity of product ×C-assoc : Functor (C × (D × E)) ((C × D) × E) ×C-assoc .F-ob (c , (d , e)) = ((c , d), e) ×C-assoc .F-hom (f , (g , h)) = ((f , g), h) ×C-assoc .F-id = refl ×C-assoc .F-seq _ _ = refl -- Left/right injections into product linj : (d : ob D) → Functor C (C × D) linj d .F-ob c = (c , d) linj d .F-hom f = (f , id D) linj d .F-id = refl linj d .F-seq f g = ≡-× refl (sym (⋆IdL D _)) rinj : (c : ob C) → Functor D (C × D) rinj c .F-ob d = (c , d) rinj c .F-hom f = (id C , f) rinj c .F-id = refl rinj c .F-seq f g = ≡-× (sym (⋆IdL C _)) refl {- TODO: - define inverse to `assoc`, prove isomorphism - prove product is commutative up to isomorphism -}
27.292308
70
0.549042
21d8f1c7619cec7c75932961656cca0a3fb40e87
713
agda
Agda
theorems/cw/cohomology/HigherCoboundary.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
theorems/cw/cohomology/HigherCoboundary.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
null
null
null
theorems/cw/cohomology/HigherCoboundary.agda
mikeshulman/HoTT-Agda
e7d663b63d89f380ab772ecb8d51c38c26952dbb
[ "MIT" ]
1
2018-12-26T21:31:57.000Z
2018-12-26T21:31:57.000Z
{-# OPTIONS --without-K --rewriting #-} open import HoTT open import groups.Cokernel open import cohomology.Theory open import cw.CW module cw.cohomology.HigherCoboundary {i} (OT : OrdinaryTheory i) {n} (⊙skel : ⊙Skeleton {i} (S (S n))) where open OrdinaryTheory OT open import cw.cohomology.WedgeOfCells OT open import cw.cohomology.GridLongExactSequence cohomology-theory (ℕ-to-ℤ (S n)) (⊙cw-incl-last (⊙cw-init ⊙skel)) (⊙cw-incl-last ⊙skel) cw-co∂-last : CXₙ/Xₙ₋₁ (⊙cw-init ⊙skel) (ℕ-to-ℤ (S n)) →ᴳ CXₙ/Xₙ₋₁ ⊙skel (ℕ-to-ℤ (S (S n))) cw-co∂-last = grid-co∂ module CokerCo∂ where grp = Coker cw-co∂-last (CXₙ/Xₙ₋₁-is-abelian ⊙skel (ℕ-to-ℤ (S (S n)))) open Group grp public CokerCo∂ = CokerCo∂.grp
28.52
91
0.684432
35238ab26e40f8c0daf597005a42d356076cbb06
990
agda
Agda
Orders/Total/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
4
2019-08-08T12:44:19.000Z
2022-01-28T06:04:15.000Z
Orders/Total/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
14
2019-01-06T21:11:59.000Z
2020-04-11T11:03:39.000Z
Orders/Total/Definition.agda
Smaug123/agdaproofs
0f4230011039092f58f673abcad8fb0652e6b562
[ "MIT" ]
1
2021-11-29T13:23:07.000Z
2021-11-29T13:23:07.000Z
{-# OPTIONS --safe --warning=error --without-K #-} open import Agda.Primitive using (Level; lzero; lsuc; _⊔_) open import LogicalFormulae open import Functions.Definition module Orders.Total.Definition {a : _} (carrier : Set a) where open import Orders.Partial.Definition carrier record TotalOrder {b : _} : Set (a ⊔ lsuc b) where field order : PartialOrder {b} _<_ : Rel carrier _<_ = PartialOrder._<_ order _≤_ : Rel carrier _≤_ a b = (a < b) || (a ≡ b) field totality : (a b : carrier) → ((a < b) || (b < a)) || (a ≡ b) min : carrier → carrier → carrier min a b with totality a b min a b | inl (inl a<b) = a min a b | inl (inr b<a) = b min a b | inr a=b = a max : carrier → carrier → carrier max a b with totality a b max a b | inl (inl a<b) = b max a b | inl (inr b<a) = a max a b | inr a=b = b irreflexive = PartialOrder.irreflexive order <Transitive = PartialOrder.<Transitive order <WellDefined = PartialOrder.<WellDefined order
26.756757
64
0.635354
d150261beb9346de59555b4368514fda9a50b4f9
175
agda
Agda
Cubical/Algebra/CommAlgebra.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
1
2022-03-05T00:29:41.000Z
2022-03-05T00:29:41.000Z
Cubical/Algebra/CommAlgebra.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
Cubical/Algebra/CommAlgebra.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Algebra.CommAlgebra where open import Cubical.Algebra.CommAlgebra.Base public open import Cubical.Algebra.CommAlgebra.Properties public
29.166667
57
0.817143
5884475702481141cea623e2f067d560501f2be1
3,524
agda
Agda
benchmark/categories/Language3.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
benchmark/categories/Language3.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
benchmark/categories/Language3.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
------------------------------------------------------------------------ -- A small definition of a dependently typed language, using the -- technique from McBride's "Outrageous but Meaningful Coincidences" ------------------------------------------------------------------------ ------------------------------------------------------------------------ -- Prelude record ⊤ : Set₁ where record Σ (A : Set₁) (B : A → Set₁) : Set₁ where constructor _,_ field proj₁ : A proj₂ : B proj₁ open Σ uncurry : ∀ {A : Set₁} {B : A → Set₁} {C : Σ A B → Set₁} → ((x : A) (y : B x) → C (x , y)) → ((p : Σ A B) → C p) uncurry f (x , y) = f x y record ↑ (A : Set) : Set₁ where constructor lift field lower : A ------------------------------------------------------------------------ -- Contexts -- The definition of contexts is parametrised by a universe. module Context (U : Set₁) (El : U → Set₁) where mutual -- Contexts. data Ctxt : Set₁ where ε : Ctxt _▻_ : (Γ : Ctxt) → Ty Γ → Ctxt -- Types. Ty : Ctxt → Set₁ Ty Γ = Env Γ → U -- Environments. Env : Ctxt → Set₁ Env ε = ⊤ Env (Γ ▻ σ) = Σ (Env Γ) λ γ → El (σ γ) -- Variables (de Bruijn indices). infix 4 _∋_ data _∋_ : (Γ : Ctxt) → Ty Γ → Set₁ where zero : ∀ {Γ σ} → Γ ▻ σ ∋ λ γ → σ (proj₁ γ) suc : ∀ {Γ σ τ} (x : Γ ∋ τ) → Γ ▻ σ ∋ λ γ → τ (proj₁ γ) -- A lookup function. lookup : ∀ {Γ σ} → Γ ∋ σ → (γ : Env Γ) → El (σ γ) lookup zero (γ , v) = v lookup (suc x) (γ , v) = lookup x γ ------------------------------------------------------------------------ -- A universe mutual data U : Set₁ where set : U el : Set → U σ π : (a : U) → (El a → U) → U El : U → Set₁ El set = Set El (el A) = ↑ A El (σ a b) = Σ (El a) λ x → El (b x) El (π a b) = (x : El a) → El (b x) open Context U El -- Abbreviations. infixr 20 _⊗_ infixr 10 _⇾_ _⇾_ : U → U → U a ⇾ b = π a λ _ → b _⊗_ : U → U → U a ⊗ b = σ a λ _ → b -- Example. raw-somethingU : U raw-somethingU = σ set λ obj → σ (el obj ⇾ el obj ⇾ set) λ hom → (π (el obj) λ x → el (hom x x)) ⊗ (π (el obj) λ x → el (hom x x)) ------------------------------------------------------------------------ -- A language mutual infixl 30 _·_ infix 4 _⊢_ -- Syntax for types. data Type (Γ : Ctxt) : Ty Γ → Set₁ where set : Type Γ (λ _ → set) el : (x : Γ ⊢ λ _ → set) → Type Γ (λ γ → el (⟦ x ⟧ γ)) σ : ∀ {a b} → Type Γ a → Type (Γ ▻ a) b → Type Γ (λ γ → σ (a γ) (λ v → b (γ , v))) π : ∀ {a b} → Type Γ a → Type (Γ ▻ a) b → Type Γ (λ γ → π (a γ) (λ v → b (γ , v))) -- Terms. data _⊢_ (Γ : Ctxt) : Ty Γ → Set₁ where var : ∀ {a} → Γ ∋ a → Γ ⊢ a ƛ : ∀ {a b} → Γ ▻ a ⊢ uncurry b → Γ ⊢ (λ γ → π (a γ) (λ v → b γ v)) _·_ : ∀ {a} {b : (γ : Env Γ) → El (a γ) → U} → Γ ⊢ (λ γ → π (a γ) (λ v → b γ v)) → (t₂ : Γ ⊢ a) → Γ ⊢ (λ γ → b γ (⟦ t₂ ⟧ γ)) -- The semantics of a term. ⟦_⟧ : ∀ {Γ a} → Γ ⊢ a → (γ : Env Γ) → El (a γ) ⟦ var x ⟧ γ = lookup x γ ⟦ ƛ t ⟧ γ = λ v → ⟦ t ⟧ (γ , v) ⟦ t₁ · t₂ ⟧ γ = (⟦ t₁ ⟧ γ) (⟦ t₂ ⟧ γ) -- Example. raw-something : Type ε (λ _ → raw-somethingU) raw-something = σ set (σ (π (el (var zero)) (π (el (var (suc zero))) set)) (σ (π (el (var (suc zero))) (el (var (suc zero) · var zero · var zero))) (π (el (var (suc (suc zero)))) (el (var (suc (suc zero)) · var zero · var zero)) )))
22.883117
72
0.39983
52ae6865f280d4e4433fa501f4b04c0c35d2b4f6
3,093
agda
Agda
test/Compiler/simple/Floats.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
7
2018-11-05T22:13:36.000Z
2018-11-06T16:38:43.000Z
test/Compiler/simple/Floats.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
16
2018-10-08T00:32:04.000Z
2019-09-08T13:47:04.000Z
test/Compiler/simple/Floats.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2015-09-15T14:36:15.000Z
2015-09-15T14:36:15.000Z
module _ where open import Common.Prelude print : Float → IO Unit print x = putStrLn (primShowFloat x) printB : Bool → IO Unit printB true = putStrLn "true" printB false = putStrLn "false" _/_ = primFloatDiv _==_ = primFloatEquality _=N=_ = primFloatNumericalEquality _<N_ = primFloatNumericalLess _<_ = primFloatLess NaN : Float NaN = 0.0 / 0.0 -NaN : Float -NaN = primFloatNegate NaN Inf : Float Inf = 1.0 / 0.0 -Inf : Float -Inf = -1.0 / 0.0 sin = primSin cos = primCos tan = primTan asin = primASin acos = primACos atan = primATan atan2 = primATan2 isZero : Float → String isZero 0.0 = "pos" isZero -0.0 = "neg" isZero _ = "nonzero" main : IO Unit main = putStr "123.4 = " ,, print 123.4 ,, putStr "-42.9 = " ,, print -42.9 ,, -- Disabled because Issue #2359. -- putStr "1.0 = " ,, print 1.0 ,, -- putStr "-0.0 = " ,, print -0.0 ,, putStr "NaN = " ,, print NaN ,, putStr "Inf = " ,, print Inf ,, putStr "-Inf = " ,, print -Inf ,, putStr "Inf == Inf = " ,, printB (Inf == Inf) ,, -- Issues #2155 and #2194. putStr "NaN == NaN = " ,, printB (NaN == NaN) ,, -- Issue #2194. putStr "NaN == -NaN = " ,, printB (NaN == (primFloatNegate NaN)) ,, -- Issue #2169. putStr "0.0 == -0.0 = " ,, printB (0.0 == -0.0) ,, -- Issue #2216 putStr "isZero 0.0 = " ,, putStrLn (isZero 0.0) ,, putStr "isZero -0.0 = " ,, putStrLn (isZero -0.0) ,, putStr "isZero 1.0 = " ,, putStrLn (isZero 1.0) ,, -- numerical equality putStr "NaN =N= NaN = " ,, printB (NaN =N= NaN) ,, putStr "0.0 =N= -0.0 = " ,, printB (0.0 =N= -0.0) ,, putStr "0.0 =N= 12.0 = " ,, printB (0.0 =N= 12.0) ,, putStr "NaN < -Inf = " ,, printB (NaN < -Inf) ,, putStr "-Inf < NaN = " ,, printB (-Inf < NaN) ,, putStr "0.0 < -0.0 = " ,, printB (0.0 < -0.0) ,, putStr "-0.0 < 0.0 = " ,, printB (-0.0 < 0.0) ,, -- Issue #2208. putStr "NaN < NaN = " ,, printB (NaN < NaN) ,, putStr "-NaN < -NaN = " ,, printB (-NaN < -NaN) ,, putStr "NaN < -NaN = " ,, printB (NaN < -NaN) ,, putStr "-NaN < NaN = " ,, printB (-NaN < NaN) ,, putStr "NaN < -5.0 = " ,, printB (NaN < -5.0) ,, putStr "-5.0 < NaN = " ,, printB (-5.0 < NaN) ,, putStr "NaN <N -Inf = " ,, printB (NaN <N -Inf) ,, putStr "-Inf <N NaN = " ,, printB (-Inf <N NaN) ,, putStr "0.0 <N -0.0 = " ,, printB (0.0 <N -0.0) ,, putStr "-0.0 <N 0.0 = " ,, printB (-0.0 <N 0.0) ,, -- Issue #2208. putStr "NaN <N NaN = " ,, printB (NaN <N NaN) ,, putStr "-NaN <N -NaN = " ,, printB (-NaN <N -NaN) ,, putStr "NaN <N -NaN = " ,, printB (NaN <N -NaN) ,, putStr "-NaN <N NaN = " ,, printB (-NaN <N NaN) ,, putStr "NaN <N -5.0 = " ,, printB (NaN <N -5.0) ,, putStr "-5.0 <N NaN = " ,, printB (-5.0 <N NaN) ,, putStr "e = " ,, print (primExp 1.0) ,, putStr "sin (asin 0.6) = " ,, print (sin (asin 0.6)) ,, putStr "cos (acos 0.6) = " ,, print (cos (acos 0.6)) ,, putStr "tan (atan 0.4) = " ,, print (tan (atan 0.4)) ,, putStr "tan (atan2 0.4 1.0) = " ,, print (tan (atan2 0.4 1.0)) ,, return unit
28.376147
69
0.511478
383f4eb718416562569bdb889e7a44c9ce0c1dc6
4,759
agda
Agda
Globular-TT/Rules.agda
thibautbenjamin/catt-formalization
3a02010a869697f4833c9bc6047d66ca27b87cf2
[ "MIT" ]
null
null
null
Globular-TT/Rules.agda
thibautbenjamin/catt-formalization
3a02010a869697f4833c9bc6047d66ca27b87cf2
[ "MIT" ]
null
null
null
Globular-TT/Rules.agda
thibautbenjamin/catt-formalization
3a02010a869697f4833c9bc6047d66ca27b87cf2
[ "MIT" ]
null
null
null
{-# OPTIONS --rewriting --without-K #-} open import Agda.Primitive open import Prelude import GSeTT.Syntax import GSeTT.Rules open import GSeTT.Typed-Syntax import Globular-TT.Syntax module Globular-TT.Rules {l} (index : Set l) (rule : index → GSeTT.Typed-Syntax.Ctx × (Globular-TT.Syntax.Pre-Ty index)) where open import Globular-TT.Syntax index {- Notational shortcuts : the context corresponding to an index -} Ci : index → Pre-Ctx Ci i = GPre-Ctx (fst (fst (rule i))) Ti : index → Pre-Ty Ti i = snd (rule i) data _⊢C : Pre-Ctx → Set (lsuc l) data _⊢T_ : Pre-Ctx → Pre-Ty → Set (lsuc l) data _⊢t_#_ : Pre-Ctx → Pre-Tm → Pre-Ty → Set (lsuc l) data _⊢S_>_ : Pre-Ctx → Pre-Sub → Pre-Ctx → Set (lsuc l) data _⊢C where ec : ⊘ ⊢C cc : ∀ {Γ A x} → Γ ⊢C → Γ ⊢T A → x == C-length Γ → (Γ ∙ x # A) ⊢C data _⊢T_ where ob : ∀ {Γ} → Γ ⊢C → Γ ⊢T ∗ ar : ∀ {Γ A t u} → Γ ⊢T A → Γ ⊢t t # A → Γ ⊢t u # A → Γ ⊢T ⇒ A t u data _⊢t_#_ where var : ∀ {Γ x A} → Γ ⊢C → x # A ∈ Γ → Γ ⊢t (Var x) # A tm : ∀ {Δ γ A i} → Ci i ⊢T Ti i → Δ ⊢S γ > Ci i → (A == (Ti i [ γ ]Pre-Ty)) → Δ ⊢t Tm-constructor i γ # A data _⊢S_>_ where es : ∀ {Δ} → Δ ⊢C → Δ ⊢S <> > ⊘ sc : ∀ {Δ Γ γ x y A t} → Δ ⊢S γ > Γ → (Γ ∙ x # A) ⊢C → (Δ ⊢t t # (A [ γ ]Pre-Ty)) → x == y → Δ ⊢S < γ , y ↦ t > > (Γ ∙ x # A) {- Derivability is preserved by the translation from GSeTT to our TT -} x∈GCtx : ∀ {x A Γ} → x GSeTT.Syntax.# A ∈ Γ → x # GPre-Ty A ∈ GPre-Ctx Γ x∈GCtx {Γ = Γ :: a} (inl x∈Γ) = inl (x∈GCtx x∈Γ) x∈GCtx {Γ = Γ :: (x,A)} (inr (idp , idp)) = inr (idp , idp) G-length : ∀ Γ → length Γ == C-length (GPre-Ctx Γ) G-length nil = idp G-length (Γ :: _) = S= (G-length Γ) GCtx : ∀ (Γ : GSeTT.Syntax.Pre-Ctx) → Γ GSeTT.Rules.⊢C → (GPre-Ctx Γ) ⊢C GTy : ∀ (Γ : GSeTT.Syntax.Pre-Ctx) (A : GSeTT.Syntax.Pre-Ty) → Γ GSeTT.Rules.⊢T A → (GPre-Ctx Γ) ⊢T (GPre-Ty A) GTm : ∀ (Γ : GSeTT.Syntax.Pre-Ctx) (A : GSeTT.Syntax.Pre-Ty) (t : GSeTT.Syntax.Pre-Tm) → Γ GSeTT.Rules.⊢t t # A → (GPre-Ctx Γ) ⊢t (GPre-Tm t) # (GPre-Ty A) GCtx .nil GSeTT.Rules.ec = ec GCtx (Γ :: (.(length Γ) , A)) (GSeTT.Rules.cc Γ⊢ Γ⊢A idp) = coe (ap (λ n → (GPre-Ctx (Γ :: (n , A)) ⊢C)) (G-length Γ) ^) (cc (GCtx Γ Γ⊢) (GTy Γ A Γ⊢A) idp) GTy Γ .GSeTT.Syntax.∗ (GSeTT.Rules.ob Γ⊢) = ob (GCtx Γ Γ⊢) GTy Γ (GSeTT.Syntax.⇒ A t u) (GSeTT.Rules.ar Γ⊢t:A Γ⊢u:A) = ar (GTy Γ A (GSeTT.Rules.Γ⊢t:A→Γ⊢A Γ⊢t:A)) (GTm Γ A t Γ⊢t:A) (GTm Γ A u Γ⊢u:A) GTm Γ A (GSeTT.Syntax.Var x) (GSeTT.Rules.var Γ⊢ x∈Γ) = var (GCtx Γ Γ⊢) (x∈GCtx x∈Γ) {- Properties of the type theory -} {- weakening admissibility -} wkT : ∀ {Γ A y B} → Γ ⊢T A → (Γ ∙ y # B) ⊢C → (Γ ∙ y # B) ⊢T A wkt : ∀ {Γ A t y B} → Γ ⊢t t # A → (Γ ∙ y # B) ⊢C → (Γ ∙ y # B) ⊢t t # A wkS : ∀ {Δ Γ γ y B} → Δ ⊢S γ > Γ → (Δ ∙ y # B) ⊢C → (Δ ∙ y # B) ⊢S γ > Γ wkT (ob _) Γ,y:B⊢ = ob Γ,y:B⊢ wkT (ar Γ⊢A Γ⊢t:A Γ⊢u:A) Γ,y:B⊢ = ar (wkT Γ⊢A Γ,y:B⊢) (wkt Γ⊢t:A Γ,y:B⊢) (wkt Γ⊢u:A Γ,y:B⊢) wkt (var Γ⊢C x∈Γ) Γ,y:B⊢ = var Γ,y:B⊢ (inl x∈Γ) wkt (tm Ci⊢Ti Γ⊢γ:Δ idp) Γ,y:B⊢ = tm Ci⊢Ti (wkS Γ⊢γ:Δ Γ,y:B⊢) idp wkS (es _) Δ,y:B⊢ = es Δ,y:B⊢ wkS (sc Δ⊢γ:Γ Γ,x:A⊢ Δ⊢t:A[γ] idp) Δ,y:B⊢ = sc (wkS Δ⊢γ:Γ Δ,y:B⊢) Γ,x:A⊢ (wkt Δ⊢t:A[γ] Δ,y:B⊢) idp {- Consistency : all objects appearing in derivable judgments are derivable -} Γ⊢A→Γ⊢ : ∀ {Γ A} → Γ ⊢T A → Γ ⊢C Γ⊢t:A→Γ⊢ : ∀ {Γ A t} → Γ ⊢t t # A → Γ ⊢C Δ⊢γ:Γ→Δ⊢ : ∀ {Δ Γ γ} → Δ ⊢S γ > Γ → Δ ⊢C Γ⊢A→Γ⊢ (ob Γ⊢) = Γ⊢ Γ⊢A→Γ⊢ (ar Γ⊢A Γ⊢t:A Γ⊢u:A) = Γ⊢t:A→Γ⊢ Γ⊢t:A Γ⊢t:A→Γ⊢ (var Γ⊢ _) = Γ⊢ Γ⊢t:A→Γ⊢ (tm _ Γ⊢γ:Δ idp) = Δ⊢γ:Γ→Δ⊢ Γ⊢γ:Δ Δ⊢γ:Γ→Δ⊢ (es Δ⊢) = Δ⊢ Δ⊢γ:Γ→Δ⊢ (sc Δ⊢γ:Γ Γ,x:A⊢ Δ⊢t:A[γ] idp) = Δ⊢γ:Γ→Δ⊢ Δ⊢γ:Γ Δ⊢γ:Γ→Γ⊢ : ∀ {Δ Γ γ} → Δ ⊢S γ > Γ → Γ ⊢C Δ⊢γ:Γ→Γ⊢ (es Δ⊢) = ec Δ⊢γ:Γ→Γ⊢ (sc Δ⊢γ:Γ Γ,x:A⊢ Δ⊢t:A[γ] idp) = Γ,x:A⊢ Γ,x:A⊢→Γ,x:A⊢A : ∀ {Γ x A} → (Γ ∙ x # A) ⊢C → (Γ ∙ x # A) ⊢T A Γ,x:A⊢→Γ,x:A⊢A Γ,x:A⊢@(cc Γ⊢ Γ⊢A idp) = wkT Γ⊢A Γ,x:A⊢ Γ,x:A⊢→Γ,x:A⊢x:A : ∀ {Γ x A} → (Γ ∙ x # A) ⊢C → (Γ ∙ x # A) ⊢t (Var x) # A Γ,x:A⊢→Γ,x:A⊢x:A Γ,x:A⊢ = var Γ,x:A⊢ (inr (idp , idp)) Γ⊢src : ∀ {Γ A t u} → Γ ⊢T ⇒ A t u → Γ ⊢t t # A Γ⊢src (ar Γ⊢ Γ⊢t Γ⊢u) = Γ⊢t Γ⊢tgt : ∀ {Γ A t u} → Γ ⊢T ⇒ A t u → Γ ⊢t u # A Γ⊢tgt (ar Γ⊢ Γ⊢t Γ⊢u) = Γ⊢u -- The proposition Γ⊢t:A→Γ⊢A is slightly harder and is moved in CwF-Struture since it depends on lemmas there -- Type epressing that the rules are well-founded (useful to show that judgments are decidable) well-founded : Set (lsuc l) well-founded = ∀ (i : index) → Ci i ⊢T Ti i → dimC (Ci i) ≤ dim (Ti i) -- Derivation of a term constructed by a term constructor Γ⊢tm→Ci⊢Ti : ∀ {i Γ γ A} → Γ ⊢t (Tm-constructor i γ) # A → Ci i ⊢T Ti i Γ⊢tm→Ci⊢Ti (tm Ci⊢Ti _ idp) = Ci⊢Ti Γ⊢tm→Γ⊢γ : ∀ {i Γ γ A} → Γ ⊢t (Tm-constructor i γ) # A → Γ ⊢S γ > Ci i Γ⊢tm→Γ⊢γ (tm _ Γ⊢γ idp) = Γ⊢γ
41.025862
158
0.507249
7cd0aae676206d3cde94273c46092926aeb98f4f
953
agda
Agda
src/fot/PA/Inductive/PropertiesByInductionI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
src/fot/PA/Inductive/PropertiesByInductionI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
src/fot/PA/Inductive/PropertiesByInductionI.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
------------------------------------------------------------------------------ -- Inductive PA properties using the induction principle ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module PA.Inductive.PropertiesByInductionI where open import PA.Inductive.Base open import PA.Inductive.PropertiesByInduction open import PA.Inductive.Relation.Binary.EqReasoning ------------------------------------------------------------------------------ +-comm : ∀ m n → m + n ≡ n + m +-comm m n = ℕ-ind A A0 is m where A : ℕ → Set A i = i + n ≡ n + i A0 : A zero A0 = sym (+-rightIdentity n) is : ∀ i → A i → A (succ i) is i ih = succ (i + n) ≡⟨ succCong ih ⟩ succ (n + i) ≡⟨ sym (x+Sy≡S[x+y] n i) ⟩ n + succ i ∎
29.78125
78
0.427072
fd588e1c4cc01998066a8ac715f50465eaf3fa5c
576
agda
Agda
test/Succeed/SizeSucMonotone.agda
cagix/agda
cc026a6a97a3e517bb94bafa9d49233b067c7559
[ "BSD-2-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/SizeSucMonotone.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/SizeSucMonotone.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2012-09-24 Ensure that size successor is monotone -- Andreas, 2015-03-16 SizeUniv is still imperfect, so we need type-in-type -- here to work around the conflation of sLub and the PTS rule. {-# OPTIONS --type-in-type #-} {-# OPTIONS --sized-types #-} module SizeSucMonotone where open import Common.Size data Bool : Set where true false : Bool -- T should be monotone in its second arg T : Bool → Size → Set T true i = (Size< i → Bool) → Bool T false i = (Size< (↑ i) → Bool) → Bool test : {x : Bool}{i : Size}{j : Size< i} → T x j → T x i test h = h
26.181818
75
0.652778
35599a9aee5e2ed4536317c5e08ddae5d4db930e
289
agda
Agda
agda/Data/Binary/Literals.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
4
2021-01-05T14:07:44.000Z
2021-01-05T15:32:14.000Z
agda/Data/Binary/Literals.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
null
null
null
agda/Data/Binary/Literals.agda
oisdk/combinatorics-paper
3c176d4690566d81611080e9378f5a178b39b851
[ "MIT" ]
1
2021-01-05T14:05:30.000Z
2021-01-05T14:05:30.000Z
{-# OPTIONS --cubical --safe #-} module Data.Binary.Literals where open import Data.Binary.Base open import Literals.Number open import Data.Unit open import Data.Nat.Literals instance number𝔹 : Number 𝔹 Number.Constraint number𝔹 = λ _ → ⊤ Number.fromNat number𝔹 = λ n → ⟦ n ⇑⟧
18.0625
39
0.719723
a046c360236665c65ed61735e1d71121e7750e08
305
agda
Agda
test/Succeed/ImportWarningsB.agda
bennn/agda
f77b563d328513138d6c88bf0a3e350a9b91f8ed
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/ImportWarningsB.agda
bennn/agda
f77b563d328513138d6c88bf0a3e350a9b91f8ed
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/ImportWarningsB.agda
bennn/agda
f77b563d328513138d6c88bf0a3e350a9b91f8ed
[ "BSD-3-Clause" ]
null
null
null
module ImportWarningsB where -- all of the following files have warnings, which should be displayed -- when loading this file import Issue1988 import Issue2243 import Issue708quote import OldCompilerPragmas import RewritingEmptyPragma import Unreachable -- this warning will be ignored {-# REWRITE #-}
20.333333
70
0.813115
436b80843a498e06dc4e42fcdef5bbb9337b423a
5,762
agda
Agda
examples/outdated-and-incorrect/iird/Proof.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
examples/outdated-and-incorrect/iird/Proof.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
examples/outdated-and-incorrect/iird/Proof.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- IIRDg is expressible in IIRDr + Identity module Proof where open import LF open import IIRD open import IIRDr open import DefinitionalEquality open import Identity open import Proof.Setup import Logic.ChainReasoning as Chain -- We can then define general IIRDs using the ε function from Proof.Setup. Ug : {I : Set}{D : I -> Set1} -> OPg I D -> I -> Set Ug γ = Ur (ε γ) Tg : {I : Set}{D : I -> Set1}(γ : OPg I D)(i : I) -> Ug γ i -> D i Tg γ = Tr (ε γ) introg : {I : Set}{D : I -> Set1}(γ : OPg I D)(a : Gu γ (Ug γ) (Tg γ)) -> Ug γ (Gi γ (Ug γ) (Tg γ) a) introg γ a = intror (G→H γ (Ug γ) (Tg γ) a) -- To prove the reduction behviour of Tg we first have to prove that the -- top-level reduction of the encoding behaves as it should. At bit simplified -- that Ht (ε γ) (Gi a) ≡ Gt γ a Tg-eq : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (a : Gu γ U T) -> Ht (ε γ) U T (Gi γ U T a) (G→H γ U T a) ≡₁ Gt γ U T a Tg-eq {I}{D} (ι < i | e >') U T ★ = refl-≡₁ Tg-eq (σ A γ) U T < a | b > = Tg-eq (γ a) U T b Tg-eq (δ A i γ) U T < g | b > = Tg-eq (γ (T « i × g »)) U T b -- The statement we're interested in is a special case of the more general -- lemma above. Tg-equality : {I : Set}{D : I -> Set1}(γ : OPg I D)(a : Gu γ (Ug γ) (Tg γ)) -> Tg γ (Gi γ (Ug γ) (Tg γ) a) (introg γ a) ≡₁ Gt γ (Ug γ) (Tg γ) a Tg-equality γ a = Tg-eq γ (Ug γ) (Tg γ) a -- The elimination rule for generalised IIRDs. -- It's basically the elimination of the encoding followed by the elimination -- of the proof the the index is the right one. Rg : {I : Set}{D : I -> Set1}(γ : OPg I D)(F : (i : I) -> Ug γ i -> Set1) (h : (a : Gu γ (Ug γ) (Tg γ)) -> KIH γ (Ug γ) (Tg γ) F a -> F (Gi γ (Ug γ) (Tg γ) a) (introg γ a)) (i : I)(u : Ug γ i) -> F i u Rg {I}{D} γ F h = Rr (ε γ) F \i a ih -> G→H∘H→G-subst γ U T (\i a -> F i (intror a)) i a (lem1 i a ih) where U = Ug γ T = Tg γ lem1 : (i : I)(a : Hu (ε γ) U T i) -> KIH (ε γ i) U T F a -> F (Gi γ U T (H→G γ U T i a)) (intror (G→H γ U T (H→G γ U T i a))) lem1 i a ih = h (H→G γ U T i a) (\v -> εIArg-subst γ U T F i a v (ih (εIArg γ U T i a v))) open module Chain-≡ = Chain.Poly.Heterogenous1 _≡₁_ (\x -> refl-≡₁) trans-≡₁ open module Chain-≡₀ = Chain.Poly.Heterogenous _≡_ (\x -> refl-≡) trans-≡ renaming (chain>_ to chain>₀_; _===_ to _===₀_; _by_ to _by₀_) -- Again we have to generalise Rg-eq : {I : Set}{D : I -> Set1}(γ : OPg I D)(U : I -> Set)(T : (i : I) -> U i -> D i) (F : (i : I) -> U i -> Set1)(intro : (a : Gu γ U T) -> U (Gi γ U T a)) (g : (i : I)(u : U i) -> F i u) (h : (a : Gu γ U T) -> KIH γ U T F a -> F (Gi γ U T a) (intro a)) (a : Gu γ U T) -> let i = Gi γ U T a a' = G→H γ U T a in h (H→G γ U T i a') (\v -> εIArg-subst γ U T F i a' v (Kmap (ε γ i) U T F g a' (εIArg γ U T i a' v))) ≡₁ h a (Kmap γ U T F g a) Rg-eq {I}{D} γ U T F intro g h a = app-≡₁ (cong-≡₁⁰ h (H→G∘G→H-identity γ U T a)) (η-≡₁⁰ \x y p -> chain> εIArg-subst γ U T F i a' x (Kmap (ε γ i) U T F g a' (εIArg γ U T i a' x)) === Kmap (ε γ i) U T F g a' (εIArg γ U T i a' x) by εIArg-identity γ U T F a x (Kmap (ε γ i) U T F g a' (εIArg γ U T i a' x)) === Kmap γ U T F g a y by app-≡₁⁰ (cong-≡₁⁰ g (chain>₀ KIArg→I (ε γ i) U T a' (εIArg γ U T i a' x) ===₀ KIArg→I γ U T (H→G γ U T i a') x by₀ εIArg→I-identity γ U T i a' x ===₀ KIArg→I γ U T a y by₀ app-≡₀ (cong-≡' (KIArg→I γ U T) (H→G∘G→H-identity γ U T a) ) p ) ) (chain>₀ KIArg→U (ε γ i) U T a' (εIArg γ U T i a' x) ===₀ KIArg→U γ U T (H→G γ U T i a') x by₀ εIArg→U-identity γ U T i a' x ===₀ KIArg→U γ U T a y by₀ app-≡₀ (cong-≡' (KIArg→U γ U T) (H→G∘G→H-identity γ U T a) ) p ) ) where i = Gi γ U T a a' = G→H γ U T a Rg-equality : {I : Set}{D : I -> Set1}(γ : OPg I D)(F : (i : I) -> Ug γ i -> Set1) (h : (a : Gu γ (Ug γ) (Tg γ)) -> KIH γ (Ug γ) (Tg γ) F a -> F (Gi γ (Ug γ) (Tg γ) a) (introg γ a)) (a : Gu γ (Ug γ) (Tg γ)) -> Rg γ F h (Gi γ (Ug γ) (Tg γ) a) (introg γ a) ≡₁ h a (Kmap γ (Ug γ) (Tg γ) F (Rg γ F h) a) Rg-equality {I}{D} γ F h a = chain> Rg γ F h (Gi γ U T a) (introg γ a) === h'' i a' ih by refl-≡₁ === G→H∘H→G-subst γ U T F' i a' (h' i a' ih) by refl-≡₁ === h' i a' ih by G→H∘H→G-identity γ U T F' a (h' i a' ih) === h (H→G γ U T i a') (\v -> εIArg-subst γ U T F i a' v (ih (εIArg γ U T i a' v))) by refl-≡₁ === h a (Kmap γ U T F (Rg γ F h) a) by Rg-eq γ U T F (introg γ) (Rg γ F h) h a where U = Ug γ T = Tg γ F' = \i a -> F i (intror a) i = Gi γ U T a a' = G→H γ U T a h' : (i : I)(a : Hu (ε γ) U T i) -> KIH (ε γ i) U T F a -> F _ _ h' = \i a ih -> h (H→G γ U T i a) \v -> εIArg-subst γ U T F i a v (ih (εIArg γ U T i a v)) h'' = \i a ih -> G→H∘H→G-subst γ U T F' i a (h' i a ih) ih = Kmap (ε γ i) U T F (Rg γ F h) a'
43.984733
112
0.423811
3841c6848ceee83f70c07201ef3c09d7675f00a6
16,767
agda
Agda
Mockingbird/Problems/Chapter12.agda
splintah/combinatory-logic
df8bf877e60b3059532c54a247a36a3d83cd55b0
[ "MIT" ]
1
2022-02-28T23:44:42.000Z
2022-02-28T23:44:42.000Z
Mockingbird/Problems/Chapter12.agda
splintah/combinatory-logic
df8bf877e60b3059532c54a247a36a3d83cd55b0
[ "MIT" ]
null
null
null
Mockingbird/Problems/Chapter12.agda
splintah/combinatory-logic
df8bf877e60b3059532c54a247a36a3d83cd55b0
[ "MIT" ]
null
null
null
open import Mockingbird.Forest using (Forest) -- Mockingbirds, Warblers, and Starlings module Mockingbird.Problems.Chapter12 {b ℓ} (forest : Forest {b} {ℓ}) where open import Data.Product using (_×_; _,_; proj₁; ∃-syntax) open import Function using (_$_) open import Mockingbird.Forest.Birds forest import Mockingbird.Problems.Chapter11 forest as Chapter₁₁ open Forest forest problem₁ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasMockingbird ⦄ → HasDoubleMockingbird problem₁ = record { M₂ = B ∙ M ; isDoubleMockingbird = λ x y → begin B ∙ M ∙ x ∙ y ≈⟨ isBluebird M x y ⟩ M ∙ (x ∙ y) ≈⟨ isMockingbird (x ∙ y) ⟩ x ∙ y ∙ (x ∙ y) ∎ } problem₂-BCM : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasThrush ⦄ ⦃ _ : HasMockingbird ⦄ → HasLark problem₂-BCM = record { L = C ∙ B ∙ M ; isLark = λ x y → begin C ∙ B ∙ M ∙ x ∙ y ≈⟨ congʳ $ isCardinal B M x ⟩ B ∙ x ∙ M ∙ y ≈⟨ isBluebird x M y ⟩ x ∙ (M ∙ y) ≈⟨ congˡ $ isMockingbird y ⟩ x ∙ (y ∙ y) ∎ } where instance hasCardinal = Chapter₁₁.problem₂₁′ problem₂-BRM : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasThrush ⦄ ⦃ _ : HasMockingbird ⦄ → HasLark problem₂-BRM = record { L = R ∙ M ∙ B ; isLark = λ x y → begin R ∙ M ∙ B ∙ x ∙ y ≈⟨ congʳ $ isRobin M B x ⟩ B ∙ x ∙ M ∙ y ≈⟨ isBluebird x M y ⟩ x ∙ (M ∙ y) ≈⟨ congˡ $ isMockingbird y ⟩ x ∙ (y ∙ y) ∎ } where instance hasRobin = Chapter₁₁.problem₂₀ problem₃ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasWarbler ⦄ → HasLark problem₃ = record { L = B ∙ W ∙ B ; isLark = λ x y → begin B ∙ W ∙ B ∙ x ∙ y ≈⟨ congʳ $ isBluebird W B x ⟩ W ∙ (B ∙ x) ∙ y ≈⟨ isWarbler (B ∙ x) y ⟩ B ∙ x ∙ y ∙ y ≈⟨ isBluebird x y y ⟩ x ∙ (y ∙ y) ∎ } problem₄ : ⦃ _ : HasMockingbird ⦄ ⦃ _ : HasQueerBird ⦄ → HasLark problem₄ = record { L = Q ∙ M ; isLark = λ x y → begin Q ∙ M ∙ x ∙ y ≈⟨ isQueerBird M x y ⟩ x ∙ (M ∙ y) ≈⟨ congˡ $ isMockingbird y ⟩ x ∙ (y ∙ y) ∎ } problem₅ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasRobin ⦄ ⦃ _ : HasMockingbird ⦄ → HasConverseWarbler problem₅ = record { W′ = M₂ ∙ R ; isConverseWarbler = λ x y → begin M₂ ∙ R ∙ x ∙ y ≈⟨ congʳ $ isDoubleMockingbird R x ⟩ R ∙ x ∙ (R ∙ x) ∙ y ≈⟨ isRobin x (R ∙ x) y ⟩ R ∙ x ∙ y ∙ x ≈⟨ isRobin x y x ⟩ y ∙ x ∙ x ∎ } where instance hasDoubleMockingbird = problem₁ problem₆′ : ⦃ _ : HasCardinal ⦄ ⦃ _ : HasConverseWarbler ⦄ → HasWarbler problem₆′ = record { W = C ∙ W′ ; isWarbler = λ x y → begin C ∙ W′ ∙ x ∙ y ≈⟨ isCardinal W′ x y ⟩ W′ ∙ y ∙ x ≈⟨ isConverseWarbler y x ⟩ x ∙ y ∙ y ∎ } problem₆ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasRobin ⦄ ⦃ _ : HasCardinal ⦄ ⦃ _ : HasMockingbird ⦄ → HasWarbler problem₆ = record { W = C ∙ (B ∙ M ∙ R) ; isWarbler = λ x y → begin C ∙ (B ∙ M ∙ R) ∙ x ∙ y ≈⟨⟩ C ∙ (M₂ ∙ R) ∙ x ∙ y ≈⟨⟩ C ∙ W′ ∙ x ∙ y ≈⟨⟩ W ∙ x ∙ y ≈⟨ isWarbler x y ⟩ x ∙ y ∙ y ∎ } where instance hasDoubleMockingbird = problem₁ hasConverseWarbler = problem₅ hasWarbler = problem₆′ problem₇ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasThrush ⦄ ⦃ _ : HasMockingbird ⦄ → HasWarbler problem₇ = record { W = B ∙ (T ∙ (B ∙ M ∙ (B ∙ B ∙ T))) ∙ (B ∙ B ∙ T) ; isWarbler = λ x y → begin B ∙ (T ∙ (B ∙ M ∙ (B ∙ B ∙ T))) ∙ (B ∙ B ∙ T) ∙ x ∙ y ≈˘⟨ congʳ $ congʳ $ isWarbler′ ⟩ W ∙ x ∙ y ≈⟨ isWarbler x y ⟩ x ∙ y ∙ y ∎ } where instance hasRobin = Chapter₁₁.problem₂₀ hasCardinal = Chapter₁₁.problem₂₁-bonus hasWarbler = problem₆ isWarbler′ : W ≈ B ∙ (T ∙ (B ∙ M ∙ (B ∙ B ∙ T))) ∙ (B ∙ B ∙ T) isWarbler′ = begin W ≈⟨⟩ C ∙ (B ∙ M ∙ R) ≈⟨⟩ C ∙ (B ∙ M ∙ (B ∙ B ∙ T)) ≈⟨⟩ B ∙ (T ∙ (B ∙ B ∙ T)) ∙ (B ∙ B ∙ T) ∙ (B ∙ M ∙ (B ∙ B ∙ T)) ≈⟨ isBluebird (T ∙ (B ∙ B ∙ T)) (B ∙ B ∙ T) (B ∙ M ∙ (B ∙ B ∙ T)) ⟩ T ∙ (B ∙ B ∙ T) ∙ (B ∙ B ∙ T ∙ (B ∙ M ∙ (B ∙ B ∙ T))) ≈⟨ isThrush (B ∙ B ∙ T) (B ∙ B ∙ T ∙ (B ∙ M ∙ (B ∙ B ∙ T))) ⟩ B ∙ B ∙ T ∙ (B ∙ M ∙ (B ∙ B ∙ T)) ∙ (B ∙ B ∙ T) ≈⟨ congʳ $ isBluebird B T (B ∙ M ∙ (B ∙ B ∙ T)) ⟩ B ∙ (T ∙ (B ∙ M ∙ (B ∙ B ∙ T))) ∙ (B ∙ B ∙ T) ∎ -- TODO: other expression in problem 7. -- NOTE: the bluebird B is not necessary. problem₈ : ⦃ _ : HasThrush ⦄ ⦃ _ : HasWarbler ⦄ → HasMockingbird problem₈ = record { M = W ∙ T ; isMockingbird = λ x → begin W ∙ T ∙ x ≈⟨ isWarbler T x ⟩ T ∙ x ∙ x ≈⟨ isThrush x x ⟩ x ∙ x ∎ } problem₉-W* : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasThrush ⦄ ⦃ _ : HasMockingbird ⦄ → HasWarblerOnceRemoved problem₉-W* = record { W* = B ∙ W ; isWarblerOnceRemoved = λ x y z → begin B ∙ W ∙ x ∙ y ∙ z ≈⟨ congʳ $ isBluebird W x y ⟩ W ∙ (x ∙ y) ∙ z ≈⟨ isWarbler (x ∙ y) z ⟩ x ∙ y ∙ z ∙ z ∎ } where instance hasWarbler = problem₇ problem₉-W** : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasThrush ⦄ ⦃ _ : HasMockingbird ⦄ → HasWarblerTwiceRemoved problem₉-W** = record { W** = B ∙ W* ; isWarblerTwiceRemoved = λ x y z w → begin B ∙ W* ∙ x ∙ y ∙ z ∙ w ≈⟨ congʳ $ congʳ $ isBluebird W* x y ⟩ W* ∙ (x ∙ y) ∙ z ∙ w ≈⟨ isWarblerOnceRemoved (x ∙ y) z w ⟩ x ∙ y ∙ z ∙ w ∙ w ∎ } where instance hasWarbler = problem₇ hasWarblerOnceRemoved = problem₉-W* problem₁₀ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasCardinal ⦄ ⦃ _ : HasWarbler ⦄ → HasHummingbird problem₁₀ = record { H = B ∙ W ∙ (B ∙ C) ; isHummingbird = λ x y z → begin B ∙ W ∙ (B ∙ C) ∙ x ∙ y ∙ z ≈⟨ congʳ $ congʳ $ isBluebird W (B ∙ C) x ⟩ W ∙ (B ∙ C ∙ x) ∙ y ∙ z ≈⟨ congʳ $ isWarbler (B ∙ C ∙ x) y ⟩ B ∙ C ∙ x ∙ y ∙ y ∙ z ≈⟨ congʳ $ congʳ $ isBluebird C x y ⟩ C ∙ (x ∙ y) ∙ y ∙ z ≈⟨ isCardinal (x ∙ y) y z ⟩ x ∙ y ∙ z ∙ y ∎ } problem₁₁ : ⦃ _ : HasRobin ⦄ ⦃ _ : HasHummingbird ⦄ → HasWarbler problem₁₁ = problem₆′ where instance hasCardinal = Chapter₁₁.problem₂₁ hasConverseWarbler : HasConverseWarbler hasConverseWarbler = record { W′ = H ∙ R ; isConverseWarbler = λ x y → begin H ∙ R ∙ x ∙ y ≈⟨ isHummingbird R x y ⟩ R ∙ x ∙ y ∙ x ≈⟨ isRobin x y x ⟩ y ∙ x ∙ x ∎ } problem₁₂ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasThrush ⦄ ⦃ _ : HasMockingbird ⦄ → HasStarling problem₁₂ = record { S = W** ∙ G ; isStarling = λ x y z → begin W** ∙ G ∙ x ∙ y ∙ z ≈⟨ isWarblerTwiceRemoved G x y z ⟩ G ∙ x ∙ y ∙ z ∙ z ≈⟨ isGoldfinch x y z z ⟩ x ∙ z ∙ (y ∙ z) ∎ } where instance hasWarblerTwiceRemoved = problem₉-W** hasGoldfinch = Chapter₁₁.problem₄₇ problem₁₃ : ⦃ _ : HasStarling ⦄ ⦃ _ : HasRobin ⦄ → HasHummingbird problem₁₃ = record { H = S ∙ R ; isHummingbird = λ x y z → begin S ∙ R ∙ x ∙ y ∙ z ≈⟨ congʳ $ isStarling R x y ⟩ R ∙ y ∙ (x ∙ y) ∙ z ≈⟨ isRobin y (x ∙ y) z ⟩ x ∙ y ∙ z ∙ y ∎ } problem₁₄-SR : ⦃ _ : HasStarling ⦄ ⦃ _ : HasRobin ⦄ → HasWarbler problem₁₄-SR = record { W = R ∙ (S ∙ R ∙ R) ∙ R ; isWarbler = λ x y → begin R ∙ (S ∙ R ∙ R) ∙ R ∙ x ∙ y ≈˘⟨ congʳ $ congʳ $ isRobin R R (S ∙ R ∙ R) ⟩ R ∙ R ∙ R ∙ (S ∙ R ∙ R) ∙ x ∙ y ≈⟨⟩ C ∙ (S ∙ R ∙ R) ∙ x ∙ y ≈⟨⟩ C ∙ (H ∙ R) ∙ x ∙ y ≈⟨⟩ W ∙ x ∙ y ≈⟨ isWarbler x y ⟩ x ∙ y ∙ y ∎ } where instance hasCardinal = Chapter₁₁.problem₂₁ hasHummingbird = problem₁₃ hasWarbler = problem₁₁ problem₁₄-SC : ⦃ _ : HasStarling ⦄ ⦃ _ : HasCardinal ⦄ → HasWarbler problem₁₄-SC = record { W = C ∙ (S ∙ (C ∙ C) ∙ (C ∙ C)) ; isWarbler = λ x y → begin C ∙ (S ∙ (C ∙ C) ∙ (C ∙ C)) ∙ x ∙ y ≈⟨⟩ C ∙ (S ∙ R ∙ R) ∙ x ∙ y ≈⟨ isCardinal (S ∙ R ∙ R) x y ⟩ S ∙ R ∙ R ∙ y ∙ x ≈⟨ congʳ $ isStarling R R y ⟩ R ∙ y ∙ (R ∙ y) ∙ x ≈⟨ isRobin y (R ∙ y) x ⟩ R ∙ y ∙ x ∙ y ≈⟨ isRobin y x y ⟩ x ∙ y ∙ y ∎ } where instance hasRobin = Chapter₁₁.problem₂₃ problem₁₅ : ⦃ _ : HasThrush ⦄ ⦃ _ : HasStarling ⦄ → HasWarbler problem₁₅ = record { W = S ∙ T ; isWarbler = λ x y → begin S ∙ T ∙ x ∙ y ≈⟨ isStarling T x y ⟩ T ∙ y ∙ (x ∙ y) ≈⟨ isThrush y (x ∙ y) ⟩ x ∙ y ∙ y ∎ } problem₁₆ : ⦃ _ : HasThrush ⦄ ⦃ _ : HasStarling ⦄ → HasMockingbird problem₁₆ = record { M = S ∙ T ∙ T ; isMockingbird = λ x → begin S ∙ T ∙ T ∙ x ≈⟨ isStarling T T x ⟩ T ∙ x ∙ (T ∙ x) ≈⟨ isThrush x (T ∙ x) ⟩ T ∙ x ∙ x ≈⟨ isThrush x x ⟩ x ∙ x ∎ } module Exercises where exercise₁-a : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasThrush ⦄ → ∃[ G₁ ] (∀ x y z w v → G₁ ∙ x ∙ y ∙ z ∙ w ∙ v ≈ x ∙ y ∙ v ∙ (z ∙ w)) exercise₁-a = ( D₁ ∙ C* , λ x y z w v → begin D₁ ∙ C* ∙ x ∙ y ∙ z ∙ w ∙ v ≈⟨ congʳ $ isDickcissel C* x y z w ⟩ C* ∙ x ∙ y ∙ (z ∙ w) ∙ v ≈⟨ isCardinalOnceRemoved x y (z ∙ w) v ⟩ x ∙ y ∙ v ∙ (z ∙ w) ∎ ) where instance hasCardinal = Chapter₁₁.problem₂₁′ hasCardinalOnceRemoved = Chapter₁₁.problem₃₁ hasDickcissel = Chapter₁₁.problem₉ -- Note: in the solutions, the bluebird is used, but the exercise does not -- state that the bluebird may be used. exercise₁-b : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasMockingbird ⦄ → ∃[ G₁ ] (∀ x y z w v → G₁ ∙ x ∙ y ∙ z ∙ w ∙ v ≈ x ∙ y ∙ v ∙ (z ∙ w)) → ∃[ G₂ ] (∀ x y z w → G₂ ∙ x ∙ y ∙ z ∙ w ≈ x ∙ w ∙ (x ∙ w) ∙ (y ∙ z)) exercise₁-b (G₁ , isG₁) = ( G₁ ∙ (B ∙ M) , λ x y z w → begin G₁ ∙ (B ∙ M) ∙ x ∙ y ∙ z ∙ w ≈⟨ isG₁ (B ∙ M) x y z w ⟩ B ∙ M ∙ x ∙ w ∙ (y ∙ z) ≈⟨ congʳ $ isBluebird M x w ⟩ M ∙ (x ∙ w) ∙ (y ∙ z) ≈⟨ congʳ $ isMockingbird (x ∙ w) ⟩ x ∙ w ∙ (x ∙ w) ∙ (y ∙ z) ∎ ) exercise₁-c : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasThrush ⦄ ⦃ _ : HasIdentity ⦄ → ∃[ I₂ ] (∀ x → I₂ ∙ x ≈ x ∙ I ∙ I) exercise₁-c = ( B ∙ (T ∙ I) ∙ (T ∙ I) , λ x → begin B ∙ (T ∙ I) ∙ (T ∙ I) ∙ x ≈⟨ isBluebird (T ∙ I) (T ∙ I) x ⟩ T ∙ I ∙ (T ∙ I ∙ x) ≈⟨ isThrush I (T ∙ I ∙ x) ⟩ T ∙ I ∙ x ∙ I ≈⟨ congʳ $ isThrush I x ⟩ x ∙ I ∙ I ∎ ) exercise₁-d : ⦃ _ : HasIdentity ⦄ ⦃ _ : HasFinch ⦄ → (hasI₂ : ∃[ I₂ ] (∀ x → I₂ ∙ x ≈ x ∙ I ∙ I)) → ∀ x → proj₁ hasI₂ ∙ (F ∙ x) ≈ x exercise₁-d (I₂ , isI₂) x = begin I₂ ∙ (F ∙ x) ≈⟨ isI₂ (F ∙ x) ⟩ F ∙ x ∙ I ∙ I ≈⟨ isFinch x I I ⟩ I ∙ I ∙ x ≈⟨ congʳ $ isIdentity I ⟩ I ∙ x ≈⟨ isIdentity x ⟩ x ∎ exercise₁-e : ⦃ _ : HasFinch ⦄ ⦃ _ : HasQueerBird ⦄ ⦃ _ : HasIdentity ⦄ → (hasG₂ : ∃[ G₂ ] (∀ x y z w → G₂ ∙ x ∙ y ∙ z ∙ w ≈ x ∙ w ∙ (x ∙ w) ∙ (y ∙ z))) → (hasI₂ : ∃[ I₂ ] (∀ x → I₂ ∙ x ≈ x ∙ I ∙ I)) → IsWarbler (proj₁ hasG₂ ∙ F ∙ (Q ∙ proj₁ hasI₂)) exercise₁-e (G₂ , isG₂) (I₂ , isI₂) x y = begin G₂ ∙ F ∙ (Q ∙ I₂) ∙ x ∙ y ≈⟨ isG₂ F (Q ∙ I₂) x y ⟩ F ∙ y ∙ (F ∙ y) ∙ (Q ∙ I₂ ∙ x) ≈⟨ isFinch y (F ∙ y) (Q ∙ I₂ ∙ x) ⟩ Q ∙ I₂ ∙ x ∙ (F ∙ y) ∙ y ≈⟨ congʳ $ isQueerBird I₂ x (F ∙ y) ⟩ x ∙ (I₂ ∙ (F ∙ y)) ∙ y ≈⟨ congʳ $ congˡ $ exercise₁-d (I₂ , isI₂) y ⟩ x ∙ y ∙ y ∎ exercise₂ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasCardinal ⦄ ⦃ _ : HasWarbler ⦄ → IsStarling (B ∙ (B ∙ (B ∙ W) ∙ C) ∙ (B ∙ B)) exercise₂ x y z = begin B ∙ (B ∙ (B ∙ W) ∙ C) ∙ (B ∙ B) ∙ x ∙ y ∙ z ≈⟨ congʳ $ congʳ $ isBluebird (B ∙ (B ∙ W) ∙ C) (B ∙ B) x ⟩ B ∙ (B ∙ W) ∙ C ∙ (B ∙ B ∙ x) ∙ y ∙ z ≈⟨ congʳ $ congʳ $ isBluebird (B ∙ W) C (B ∙ B ∙ x) ⟩ B ∙ W ∙ (C ∙ (B ∙ B ∙ x)) ∙ y ∙ z ≈⟨ congʳ $ isBluebird W (C ∙ (B ∙ B ∙ x)) y ⟩ W ∙ (C ∙ (B ∙ B ∙ x) ∙ y) ∙ z ≈⟨ isWarbler (C ∙ (B ∙ B ∙ x) ∙ y) z ⟩ C ∙ (B ∙ B ∙ x) ∙ y ∙ z ∙ z ≈⟨ congʳ $ isCardinal (B ∙ B ∙ x) y z ⟩ B ∙ B ∙ x ∙ z ∙ y ∙ z ≈⟨ congʳ $ congʳ $ isBluebird B x z ⟩ B ∙ (x ∙ z) ∙ y ∙ z ≈⟨ isBluebird (x ∙ z) y z ⟩ x ∙ z ∙ (y ∙ z) ∎ exercise₃ : ⦃ _ : HasStarling ⦄ ⦃ _ : HasBluebird ⦄ → HasPhoenix exercise₃ = record { Φ = B ∙ (B ∙ S) ∙ B ; isPhoenix = λ x y z w → begin B ∙ (B ∙ S) ∙ B ∙ x ∙ y ∙ z ∙ w ≈⟨ congʳ $ congʳ $ congʳ $ isBluebird (B ∙ S) B x ⟩ B ∙ S ∙ (B ∙ x) ∙ y ∙ z ∙ w ≈⟨ congʳ $ congʳ $ isBluebird S (B ∙ x) y ⟩ S ∙ (B ∙ x ∙ y) ∙ z ∙ w ≈⟨ isStarling (B ∙ x ∙ y) z w ⟩ B ∙ x ∙ y ∙ w ∙ (z ∙ w) ≈⟨ congʳ $ isBluebird x y w ⟩ x ∙ (y ∙ w) ∙ (z ∙ w) ∎ } exercise₄ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasCardinal ⦄ ⦃ _ : HasWarbler ⦄ → HasPsiBird exercise₄ = record { Ψ = H* ∙ D₂ ; isPsiBird = λ x y z w → begin H* ∙ D₂ ∙ x ∙ y ∙ z ∙ w ≈⟨⟩ B ∙ H ∙ D₂ ∙ x ∙ y ∙ z ∙ w ≈⟨ congʳ $ congʳ $ congʳ $ isBluebird H D₂ x ⟩ H ∙ (D₂ ∙ x) ∙ y ∙ z ∙ w ≈⟨ congʳ $ isHummingbird (D₂ ∙ x) y z ⟩ D₂ ∙ x ∙ y ∙ z ∙ y ∙ w ≈⟨ isDovekie x y z y w ⟩ x ∙ (y ∙ z) ∙ (y ∙ w) ∎ } where instance hasHummingbird = problem₁₀ hasDovekie = Chapter₁₁.problem₁₁ H* = B ∙ H -- NOTE: my copy of the book contains a mistake (looking at the given -- solutions): it says Γxyzwv = y(zw)(xywv) instead of Γxyzwv = y(zw)(xyzwv). exercise₅-a : ⦃ _ : HasPhoenix ⦄ ⦃ _ : HasBluebird ⦄ → ∃[ Γ ] (∀ x y z w v → Γ ∙ x ∙ y ∙ z ∙ w ∙ v ≈ y ∙ (z ∙ w) ∙ (x ∙ y ∙ z ∙ w ∙ v)) exercise₅-a = ( Φ ∙ (Φ ∙ (Φ ∙ B)) ∙ B , λ x y z w v → begin Φ ∙ (Φ ∙ (Φ ∙ B)) ∙ B ∙ x ∙ y ∙ z ∙ w ∙ v ≈⟨ congʳ $ congʳ $ congʳ $ isPhoenix (Φ ∙ (Φ ∙ B)) B x y ⟩ Φ ∙ (Φ ∙ B) ∙ (B ∙ y) ∙ (x ∙ y) ∙ z ∙ w ∙ v ≈⟨ congʳ $ congʳ $ isPhoenix (Φ ∙ B) (B ∙ y) (x ∙ y) z ⟩ Φ ∙ B ∙ (B ∙ y ∙ z) ∙ (x ∙ y ∙ z) ∙ w ∙ v ≈⟨ congʳ $ isPhoenix B (B ∙ y ∙ z) (x ∙ y ∙ z) w ⟩ B ∙ (B ∙ y ∙ z ∙ w) ∙ (x ∙ y ∙ z ∙ w) ∙ v ≈⟨ isBluebird (B ∙ y ∙ z ∙ w) (x ∙ y ∙ z ∙ w) v ⟩ B ∙ y ∙ z ∙ w ∙ (x ∙ y ∙ z ∙ w ∙ v) ≈⟨ congʳ $ isBluebird y z w ⟩ y ∙ (z ∙ w) ∙ (x ∙ y ∙ z ∙ w ∙ v) ∎ ) exercise₅-b : ⦃ _ : HasKestrel ⦄ → ∃[ Γ ] (∀ x y z w v → Γ ∙ x ∙ y ∙ z ∙ w ∙ v ≈ y ∙ (z ∙ w) ∙ (x ∙ y ∙ z ∙ w ∙ v)) → HasPsiBird exercise₅-b (Γ , isΓ) = record { Ψ = Γ ∙ (K ∙ K) ; isPsiBird = λ x y z w → begin Γ ∙ (K ∙ K) ∙ x ∙ y ∙ z ∙ w ≈⟨ isΓ (K ∙ K) x y z w ⟩ x ∙ (y ∙ z) ∙ (K ∙ K ∙ x ∙ y ∙ z ∙ w) ≈⟨ congˡ $ congʳ $ congʳ $ congʳ $ isKestrel K x ⟩ x ∙ (y ∙ z) ∙ (K ∙ y ∙ z ∙ w) ≈⟨ congˡ $ congʳ $ isKestrel y z ⟩ x ∙ (y ∙ z) ∙ (y ∙ w) ∎ } exercise₅ : ⦃ _ : HasPhoenix ⦄ ⦃ _ : HasBluebird ⦄ ⦃ _ : HasKestrel ⦄ → HasPsiBird exercise₅ = exercise₅-b exercise₅-a exercise₆-a : ⦃ _ : HasStarling ⦄ ⦃ _ : HasBluebird ⦄ ⦃ _ : HasThrush ⦄ → ∃[ S′ ] (∀ x y z → S′ ∙ x ∙ y ∙ z ≈ y ∙ z ∙ (x ∙ z)) exercise₆-a = ( C ∙ S , λ x y z → begin C ∙ S ∙ x ∙ y ∙ z ≈⟨ congʳ $ isCardinal S x y ⟩ S ∙ y ∙ x ∙ z ≈⟨ isStarling y x z ⟩ y ∙ z ∙ (x ∙ z) ∎ ) where instance hasCardinal = Chapter₁₁.problem₂₁′ exercise₆-b : ⦃ _ : HasIdentity ⦄ → ∃[ S′ ] (∀ x y z → S′ ∙ x ∙ y ∙ z ≈ y ∙ z ∙ (x ∙ z)) → HasWarbler exercise₆-b (S′ , isS′) = record { W = S′ ∙ I ; isWarbler = λ x y → begin S′ ∙ I ∙ x ∙ y ≈⟨ isS′ I x y ⟩ x ∙ y ∙ (I ∙ y) ≈⟨ congˡ $ isIdentity y ⟩ x ∙ y ∙ y ∎ } exercise₇ : ⦃ _ : HasQueerBird ⦄ ⦃ _ : HasCardinal ⦄ ⦃ _ : HasWarbler ⦄ → ∃[ Q̂ ] IsStarling (C ∙ Q̂ ∙ W) exercise₇ = let Q̂ = Q ∙ (Q ∙ Q ∙ (Q ∙ Q)) ∙ Q in ( Q̂ , λ x y z → begin C ∙ Q̂ ∙ W ∙ x ∙ y ∙ z ≈⟨ congʳ $ congʳ $ isCardinal Q̂ W x ⟩ Q̂ ∙ x ∙ W ∙ y ∙ z ≈⟨⟩ Q ∙ (Q ∙ Q ∙ (Q ∙ Q)) ∙ Q ∙ x ∙ W ∙ y ∙ z ≈⟨ congʳ $ congʳ $ congʳ $ isQueerBird (Q ∙ Q ∙ (Q ∙ Q)) Q x ⟩ Q ∙ (Q ∙ Q ∙ (Q ∙ Q) ∙ x) ∙ W ∙ y ∙ z ≈⟨ congʳ $ isQueerBird (Q ∙ Q ∙ (Q ∙ Q) ∙ x) W y ⟩ W ∙ (Q ∙ Q ∙ (Q ∙ Q) ∙ x ∙ y) ∙ z ≈⟨ isWarbler (Q ∙ Q ∙ (Q ∙ Q) ∙ x ∙ y) z ⟩ Q ∙ Q ∙ (Q ∙ Q) ∙ x ∙ y ∙ z ∙ z ≈⟨ congʳ $ congʳ $ congʳ $ isQueerBird Q (Q ∙ Q) x ⟩ Q ∙ Q ∙ (Q ∙ x) ∙ y ∙ z ∙ z ≈⟨ congʳ $ congʳ $ isQueerBird Q (Q ∙ x) y ⟩ Q ∙ x ∙ (Q ∙ y) ∙ z ∙ z ≈⟨ congʳ $ isQueerBird x (Q ∙ y) z ⟩ Q ∙ y ∙ (x ∙ z) ∙ z ≈⟨ isQueerBird y (x ∙ z) z ⟩ x ∙ z ∙ (y ∙ z) ∎ )
40.5
132
0.424107
7c8e34eb45aebfb87445e8ec2df53161b236e637
301
agda
Agda
test/fail/Issue551a.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
null
null
null
test/fail/Issue551a.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
null
null
null
test/fail/Issue551a.agda
larrytheliquid/agda
477c8c37f948e6038b773409358fd8f38395f827
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
-- Andreas, 2012-01-11 module Issue551a where data Box (A : Set) : Set where [_] : A → Box A implicit : {A : Set}{{a : A}} -> A implicit {{a}} = a postulate A : Set .a : A -- this irrelevant definition needs to be ignored by instance search a' : Box A a' = [ implicit ] -- this should fail
17.705882
78
0.611296
38c92d9b004f4b8a015845ffc681fe7da92d73e7
46,510
agda
Agda
src/H-level/Truncation/Church.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
3
2020-05-21T22:58:50.000Z
2021-09-02T17:18:15.000Z
src/H-level/Truncation/Church.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
src/H-level/Truncation/Church.agda
nad/equality
402b20615cfe9ca944662380d7b2d69b0f175200
[ "MIT" ]
null
null
null
------------------------------------------------------------------------ -- Truncation, defined using a kind of Church encoding ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} -- Partly following the HoTT book. open import Equality module H-level.Truncation.Church {reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where open import Prelude open import Logical-equivalence using (_⇔_) open import Bijection eq as Bijection using (_↔_) open Derived-definitions-and-properties eq open import Embedding eq hiding (_∘_) open import Equality.Decidable-UIP eq import Equality.Groupoid eq as EG open import Equivalence eq as Eq using (_≃_; Is-equivalence) import Equivalence.Half-adjoint eq as HA open import Function-universe eq as F hiding (_∘_) open import Groupoid eq open import H-level eq as H-level open import H-level.Closure eq open import Nat eq open import Preimage eq as Preimage using (_⁻¹_) open import Surjection eq using (_↠_; Split-surjective) -- Truncation. ∥_∥ : ∀ {a} → Type a → ℕ → (ℓ : Level) → Type (a ⊔ lsuc ℓ) ∥ A ∥ n ℓ = (P : Type ℓ) → H-level n P → (A → P) → P -- If A is inhabited, then ∥ A ∥ n ℓ is also inhabited. ∣_∣ : ∀ {n ℓ a} {A : Type a} → A → ∥ A ∥ n ℓ ∣ x ∣ = λ _ _ f → f x -- A special case of ∣_∣. ∣_∣₁ : ∀ {ℓ a} {A : Type a} → A → ∥ A ∥ 1 ℓ ∣ x ∣₁ = ∣_∣ {n = 1} x -- The truncation produces types of the right h-level (assuming -- extensionality). truncation-has-correct-h-level : ∀ n {ℓ a} {A : Type a} → Extensionality (a ⊔ lsuc ℓ) (a ⊔ ℓ) → H-level n (∥ A ∥ n ℓ) truncation-has-correct-h-level n {ℓ} {a} ext = Π-closure (lower-extensionality a lzero ext) n λ _ → Π-closure (lower-extensionality (a ⊔ lsuc ℓ) lzero ext) n λ h → Π-closure (lower-extensionality (lsuc ℓ) a ext) n λ _ → h -- Primitive "recursion" for truncated types. rec : ∀ n {a b} {A : Type a} {B : Type b} → H-level n B → (A → B) → ∥ A ∥ n b → B rec _ h f x = x _ h f private -- The function rec computes in the right way. rec-∣∣ : ∀ {n a b} {A : Type a} {B : Type b} (h : H-level n B) (f : A → B) (x : A) → rec _ h f ∣ x ∣ ≡ f x rec-∣∣ _ _ _ = refl _ -- Map function. ∥∥-map : ∀ n {a b ℓ} {A : Type a} {B : Type b} → (A → B) → ∥ A ∥ n ℓ → ∥ B ∥ n ℓ ∥∥-map _ f x = λ P h g → x P h (g ∘ f) -- The truncation operator preserves logical equivalences. ∥∥-cong-⇔ : ∀ {n a b ℓ} {A : Type a} {B : Type b} → A ⇔ B → ∥ A ∥ n ℓ ⇔ ∥ B ∥ n ℓ ∥∥-cong-⇔ A⇔B = record { to = ∥∥-map _ (_⇔_.to A⇔B) ; from = ∥∥-map _ (_⇔_.from A⇔B) } -- The truncation operator preserves bijections (assuming -- extensionality). ∥∥-cong : ∀ {k n a b ℓ} {A : Type a} {B : Type b} → Extensionality (a ⊔ b ⊔ lsuc ℓ) (a ⊔ b ⊔ ℓ) → A ↔[ k ] B → ∥ A ∥ n ℓ ↔[ k ] ∥ B ∥ n ℓ ∥∥-cong {k} {n} {a} {b} {ℓ} ext A↝B = from-bijection (record { surjection = record { logical-equivalence = record { to = ∥∥-map _ (_↔_.to A↔B) ; from = ∥∥-map _ (_↔_.from A↔B) } ; right-inverse-of = lemma (lower-extensionality a a ext) A↔B } ; left-inverse-of = lemma (lower-extensionality b b ext) (inverse A↔B) }) where A↔B = from-isomorphism A↝B lemma : ∀ {c d} {C : Type c} {D : Type d} → Extensionality (d ⊔ lsuc ℓ) (d ⊔ ℓ) → (C↔D : C ↔ D) (∥d∥ : ∥ D ∥ n ℓ) → ∥∥-map _ (_↔_.to C↔D) (∥∥-map _ (_↔_.from C↔D) ∥d∥) ≡ ∥d∥ lemma {d = d} ext C↔D ∥d∥ = apply-ext (lower-extensionality d lzero ext) λ P → apply-ext (lower-extensionality _ lzero ext) λ h → apply-ext (lower-extensionality (lsuc ℓ) d ext) λ g → ∥d∥ P h (g ∘ _↔_.to C↔D ∘ _↔_.from C↔D) ≡⟨ cong (λ f → ∥d∥ P h (g ∘ f)) $ apply-ext (lower-extensionality (lsuc ℓ) ℓ ext) (_↔_.right-inverse-of C↔D) ⟩∎ ∥d∥ P h g ∎ -- The universe level can be decreased (unless it is zero). with-lower-level : ∀ ℓ₁ {ℓ₂ a} n {A : Type a} → ∥ A ∥ n (ℓ₁ ⊔ ℓ₂) → ∥ A ∥ n ℓ₂ with-lower-level ℓ₁ _ x = λ P h f → lower (x (↑ ℓ₁ P) (↑-closure _ h) (lift ∘ f)) private -- The function with-lower-level computes in the right way. with-lower-level-∣∣ : ∀ {ℓ₁ ℓ₂ a n} {A : Type a} (x : A) → with-lower-level ℓ₁ {ℓ₂ = ℓ₂} n ∣ x ∣ ≡ ∣ x ∣ with-lower-level-∣∣ _ = refl _ -- ∥_∥ is downwards closed in the h-level. downwards-closed : ∀ {m n a ℓ} {A : Type a} → n ≤ m → ∥ A ∥ m ℓ → ∥ A ∥ n ℓ downwards-closed n≤m x = λ P h f → x P (H-level.mono n≤m h) f private -- The function downwards-closed computes in the right way. downwards-closed-∣∣ : ∀ {m n a ℓ} {A : Type a} (n≤m : n ≤ m) (x : A) → downwards-closed {ℓ = ℓ} n≤m ∣ x ∣ ≡ ∣ x ∣ downwards-closed-∣∣ _ _ = refl _ -- The function rec can be used to define a kind of dependently typed -- eliminator for the propositional truncation (assuming -- extensionality). prop-elim : ∀ {ℓ a p} {A : Type a} → Extensionality (lsuc ℓ ⊔ a) (ℓ ⊔ a ⊔ p) → (P : ∥ A ∥ 1 ℓ → Type p) → (∀ x → Is-proposition (P x)) → ((x : A) → P ∣ x ∣₁) → ∥ A ∥ 1 (lsuc ℓ ⊔ a ⊔ p) → (x : ∥ A ∥ 1 ℓ) → P x prop-elim {ℓ} {a} {p} ext P P-prop f = rec 1 (Π-closure (lower-extensionality lzero (ℓ ⊔ a) ext) 1 P-prop) (λ x _ → subst P (truncation-has-correct-h-level 1 (lower-extensionality lzero p ext) _ _) (f x)) abstract -- The eliminator gives the right result, up to propositional -- equality, when applied to ∣ x ∣ and ∣ x ∣. prop-elim-∣∣ : ∀ {ℓ a p} {A : Type a} (ext : Extensionality (lsuc ℓ ⊔ a) (ℓ ⊔ a ⊔ p)) (P : ∥ A ∥ 1 ℓ → Type p) (P-prop : ∀ x → Is-proposition (P x)) (f : (x : A) → P ∣ x ∣₁) (x : A) → prop-elim ext P P-prop f ∣ x ∣₁ ∣ x ∣₁ ≡ f x prop-elim-∣∣ _ _ P-prop _ _ = P-prop _ _ _ -- Nested truncations can sometimes be flattened. flatten↠ : ∀ {m n a ℓ} {A : Type a} → Extensionality (a ⊔ lsuc ℓ) (a ⊔ ℓ) → m ≤ n → ∥ ∥ A ∥ m ℓ ∥ n (a ⊔ lsuc ℓ) ↠ ∥ A ∥ m ℓ flatten↠ ext m≤n = record { logical-equivalence = record { to = rec _ (H-level.mono m≤n (truncation-has-correct-h-level _ ext)) F.id ; from = ∣_∣ } ; right-inverse-of = refl } flatten↔ : ∀ {a ℓ} {A : Type a} → Extensionality (lsuc (a ⊔ lsuc ℓ)) (lsuc (a ⊔ lsuc ℓ)) → (∥ ∥ A ∥ 1 ℓ ∥ 1 (a ⊔ lsuc ℓ) → ∥ ∥ A ∥ 1 ℓ ∥ 1 (lsuc (a ⊔ lsuc ℓ))) → ∥ ∥ A ∥ 1 ℓ ∥ 1 (a ⊔ lsuc ℓ) ↔ ∥ A ∥ 1 ℓ flatten↔ ext resize = record { surjection = flatten↠ {m = 1} ext′ ≤-refl ; left-inverse-of = λ x → prop-elim ext (λ x → ∣ rec 1 (H-level.mono (≤-refl {n = 1}) (truncation-has-correct-h-level 1 ext′)) F.id x ∣₁ ≡ x) (λ _ → ⇒≡ 1 $ truncation-has-correct-h-level 1 (lower-extensionality lzero _ ext)) (λ _ → refl _) (resize x) x } where ext′ = lower-extensionality _ _ ext -- Surjectivity. -- -- I'm not quite sure what the universe level of the truncation should -- be, so I've included it as a parameter. Surjective : ∀ {a b} ℓ {A : Type a} {B : Type b} → (A → B) → Type (a ⊔ b ⊔ lsuc ℓ) Surjective ℓ f = ∀ b → ∥ f ⁻¹ b ∥ 1 ℓ -- The property Surjective ℓ f is a proposition (assuming -- extensionality). Surjective-propositional : ∀ {ℓ a b} {A : Type a} {B : Type b} {f : A → B} → Extensionality (a ⊔ b ⊔ lsuc ℓ) (a ⊔ b ⊔ lsuc ℓ) → Is-proposition (Surjective ℓ f) Surjective-propositional {ℓ} {a} ext = Π-closure (lower-extensionality (a ⊔ lsuc ℓ) lzero ext) 1 λ _ → truncation-has-correct-h-level 1 (lower-extensionality lzero (lsuc ℓ) ext) -- Split surjective functions are surjective. Split-surjective→Surjective : ∀ {a b ℓ} {A : Type a} {B : Type b} {f : A → B} → Split-surjective f → Surjective ℓ f Split-surjective→Surjective s = λ b → ∣ s b ∣₁ -- Being both surjective and an embedding is equivalent to being an -- equivalence. -- -- This is Corollary 4.6.4 from the first edition of the HoTT book -- (the proof is perhaps not quite identical). surjective×embedding≃equivalence : ∀ {a b} ℓ {A : Type a} {B : Type b} {f : A → B} → Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (lsuc (a ⊔ b ⊔ ℓ)) → (Surjective (a ⊔ b ⊔ ℓ) f × Is-embedding f) ≃ Is-equivalence f surjective×embedding≃equivalence {a} {b} ℓ {f = f} ext = Eq.⇔→≃ (×-closure 1 (Surjective-propositional ext) (Is-embedding-propositional (lower-extensionality _ _ ext))) (Eq.propositional (lower-extensionality _ _ ext) _) (λ (is-surj , is-emb) → _⇔_.from HA.Is-equivalence⇔Is-equivalence-CP $ λ y → $⟨ is-surj y ⟩ ∥ f ⁻¹ y ∥ 1 (a ⊔ b ⊔ ℓ) ↝⟨ with-lower-level ℓ 1 ⟩ ∥ f ⁻¹ y ∥ 1 (a ⊔ b) ↝⟨ rec 1 (Contractible-propositional (lower-extensionality _ _ ext)) (f ⁻¹ y ↝⟨ propositional⇒inhabited⇒contractible (embedding→⁻¹-propositional is-emb y) ⟩□ Contractible (f ⁻¹ y) □) ⟩□ Contractible (f ⁻¹ y) □) (λ is-eq → (λ y → $⟨ HA.inverse is-eq y , HA.right-inverse-of is-eq y ⟩ f ⁻¹ y ↝⟨ ∣_∣₁ ⟩□ ∥ f ⁻¹ y ∥ 1 (a ⊔ b ⊔ ℓ) □) , ($⟨ is-eq ⟩ Is-equivalence f ↝⟨ Embedding.is-embedding ∘ from-equivalence ∘ Eq.⟨ _ ,_⟩ ⟩□ Is-embedding f □)) -- If the underlying type has a certain h-level, then there is a split -- surjection from corresponding truncations (if they are "big" -- enough) to the type itself. ∥∥↠ : ∀ ℓ {a} {A : Type a} n → H-level n A → ∥ A ∥ n (a ⊔ ℓ) ↠ A ∥∥↠ ℓ _ h = record { logical-equivalence = record { to = rec _ h F.id ∘ with-lower-level ℓ _ ; from = ∣_∣ } ; right-inverse-of = refl } -- If the underlying type is a proposition, then propositional -- truncations of the type are isomorphic to the type itself (if they -- are "big" enough, and assuming extensionality). ∥∥↔ : ∀ ℓ {a} {A : Type a} → Extensionality (lsuc (a ⊔ ℓ)) (a ⊔ ℓ) → Is-proposition A → ∥ A ∥ 1 (a ⊔ ℓ) ↔ A ∥∥↔ ℓ ext A-prop = record { surjection = ∥∥↠ ℓ 1 A-prop ; left-inverse-of = λ _ → truncation-has-correct-h-level 1 ext _ _ } -- A simple isomorphism involving propositional truncation. ∥∥×↔ : ∀ {ℓ a} {A : Type a} → Extensionality (lsuc ℓ ⊔ a) (ℓ ⊔ a) → ∥ A ∥ 1 ℓ × A ↔ A ∥∥×↔ {ℓ} {A = A} ext = ∥ A ∥ 1 ℓ × A ↝⟨ ×-comm ⟩ A × ∥ A ∥ 1 ℓ ↝⟨ (drop-⊤-right λ a → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (truncation-has-correct-h-level 1 ext) ∣ a ∣₁) ⟩□ A □ -- A variant of ∥∥×↔, introduced to ensure that the right-inverse-of -- proof is, by definition, simple (see right-inverse-of-∥∥×≃ below). ∥∥×≃ : ∀ {ℓ a} {A : Type a} → Extensionality (lsuc ℓ ⊔ a) (ℓ ⊔ a) → (∥ A ∥ 1 ℓ × A) ≃ A ∥∥×≃ ext = Eq.↔→≃ proj₂ (λ x → ∣ x ∣₁ , x) refl (λ _ → cong (_, _) (truncation-has-correct-h-level 1 ext _ _)) private right-inverse-of-∥∥×≃ : ∀ {ℓ a} {A : Type a} (ext : Extensionality (lsuc ℓ ⊔ a) (ℓ ⊔ a)) (x : A) → _≃_.right-inverse-of (∥∥×≃ {ℓ = ℓ} ext) x ≡ refl x right-inverse-of-∥∥×≃ _ x = refl (refl x) -- ∥_∥ commutes with _×_ (assuming extensionality and a resizing -- function for the propositional truncation). ∥∥×∥∥↔∥×∥ : ∀ {a b} ℓ {A : Type a} {B : Type b} → Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (a ⊔ b ⊔ ℓ) → (∀ {x} {X : Type x} → ∥ X ∥ 1 (a ⊔ b ⊔ ℓ) → ∥ X ∥ 1 (lsuc (a ⊔ b ⊔ ℓ))) → let ℓ′ = a ⊔ b ⊔ ℓ in (∥ A ∥ 1 ℓ′ × ∥ B ∥ 1 ℓ′) ↔ ∥ A × B ∥ 1 ℓ′ ∥∥×∥∥↔∥×∥ _ ext resize = record { surjection = record { logical-equivalence = record { from = λ p → ∥∥-map 1 proj₁ p , ∥∥-map 1 proj₂ p ; to = λ { (x , y) → rec 1 (truncation-has-correct-h-level 1 ext) (λ x → rec 1 (truncation-has-correct-h-level 1 ext) (λ y → ∣ x , y ∣₁) (resize y)) (resize x) } } ; right-inverse-of = λ _ → truncation-has-correct-h-level 1 ext _ _ } ; left-inverse-of = λ _ → ×-closure 1 (truncation-has-correct-h-level 1 ext) (truncation-has-correct-h-level 1 ext) _ _ } -- If A is merely inhabited (at a certain level), then the -- propositional truncation of A (at the same level) is isomorphic to -- the unit type (assuming extensionality). inhabited⇒∥∥↔⊤ : ∀ {ℓ a} {A : Type a} → Extensionality (lsuc ℓ ⊔ a) (ℓ ⊔ a) → ∥ A ∥ 1 ℓ → ∥ A ∥ 1 ℓ ↔ ⊤ inhabited⇒∥∥↔⊤ ext ∥a∥ = _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (truncation-has-correct-h-level 1 ext) ∥a∥ -- If A is not inhabited, then the propositional truncation of A is -- isomorphic to the empty type. not-inhabited⇒∥∥↔⊥ : ∀ {ℓ₁ ℓ₂ a} {A : Type a} → ¬ A → ∥ A ∥ 1 ℓ₁ ↔ ⊥ {ℓ = ℓ₂} not-inhabited⇒∥∥↔⊥ {A = A} = ¬ A ↝⟨ (λ ¬a ∥a∥ → rec 1 ⊥-propositional ¬a (with-lower-level _ 1 ∥a∥)) ⟩ ¬ ∥ A ∥ 1 _ ↝⟨ inverse ∘ Bijection.⊥↔uninhabited ⟩□ ∥ A ∥ 1 _ ↔ ⊥ □ -- The following two results come from "Generalizations of Hedberg's -- Theorem" by Kraus, Escardó, Coquand and Altenkirch. -- Types with constant endofunctions are "h-stable" (meaning that -- "mere inhabitance" implies inhabitance). constant-endofunction⇒h-stable : ∀ {a} {A : Type a} {f : A → A} → Constant f → ∥ A ∥ 1 a → A constant-endofunction⇒h-stable {a} {A} {f} c = ∥ A ∥ 1 a ↝⟨ rec 1 (fixpoint-lemma f c) (λ x → f x , c (f x) x) ⟩ (∃ λ (x : A) → f x ≡ x) ↝⟨ proj₁ ⟩□ A □ -- Having a constant endofunction is logically equivalent to being -- h-stable (assuming extensionality). constant-endofunction⇔h-stable : ∀ {a} {A : Type a} → Extensionality (lsuc a) a → (∃ λ (f : A → A) → Constant f) ⇔ (∥ A ∥ 1 a → A) constant-endofunction⇔h-stable ext = record { to = λ { (_ , c) → constant-endofunction⇒h-stable c } ; from = λ f → f ∘ ∣_∣₁ , λ x y → f ∣ x ∣₁ ≡⟨ cong f $ truncation-has-correct-h-level 1 ext _ _ ⟩∎ f ∣ y ∣₁ ∎ } -- The following three lemmas were communicated to me by Nicolai -- Kraus. (In slightly different form.) They are closely related to -- Lemma 2.1 in his paper "The General Universal Property of the -- Propositional Truncation". -- A variant of ∥∥×≃. drop-∥∥ : ∀ ℓ {a b} {A : Type a} {B : A → Type b} → Extensionality (lsuc (a ⊔ ℓ)) (a ⊔ b ⊔ ℓ) → (∥ A ∥ 1 (a ⊔ ℓ) → ∀ x → B x) ↔ (∀ x → B x) drop-∥∥ ℓ {a} {b} {A} {B} ext = (∥ A ∥ 1 _ → ∀ x → B x) ↝⟨ inverse currying ⟩ ((p : ∥ A ∥ 1 _ × A) → B (proj₂ p)) ↝⟨ Π-cong (lower-extensionality lzero (a ⊔ ℓ) ext) (∥∥×≃ (lower-extensionality lzero b ext)) (λ _ → F.id) ⟩□ (∀ x → B x) □ -- Another variant of ∥∥×≃. push-∥∥ : ∀ ℓ {a b c} {A : Type a} {B : A → Type b} {C : (∀ x → B x) → Type c} → Extensionality (lsuc (a ⊔ ℓ)) (a ⊔ b ⊔ c ⊔ ℓ) → (∥ A ∥ 1 (a ⊔ ℓ) → ∃ λ (f : ∀ x → B x) → C f) ↔ (∃ λ (f : ∀ x → B x) → ∥ A ∥ 1 (a ⊔ ℓ) → C f) push-∥∥ ℓ {a} {b} {c} {A} {B} {C} ext = (∥ A ∥ 1 _ → ∃ λ (f : ∀ x → B x) → C f) ↝⟨ ΠΣ-comm ⟩ (∃ λ (f : ∥ A ∥ 1 _ → ∀ x → B x) → ∀ ∥x∥ → C (f ∥x∥)) ↝⟨ Σ-cong (drop-∥∥ ℓ (lower-extensionality lzero c ext)) (λ f → ∀-cong (lower-extensionality lzero (a ⊔ b ⊔ ℓ) ext) λ ∥x∥ → ≡⇒↝ _ $ cong C $ apply-ext (lower-extensionality _ (a ⊔ c ⊔ ℓ) ext) λ x → f ∥x∥ x ≡⟨ cong (λ ∥x∥ → f ∥x∥ x) $ truncation-has-correct-h-level 1 (lower-extensionality lzero (b ⊔ c) ext) _ _ ⟩ f ∣ x ∣₁ x ≡⟨ sym $ subst-refl _ _ ⟩∎ subst B (refl x) (f ∣ x ∣₁ x) ∎) ⟩□ (∃ λ (f : ∀ x → B x) → ∥ A ∥ 1 _ → C (λ x → f x)) □ -- This is an instance of a variant of Lemma 2.1 from "The General -- Universal Property of the Propositional Truncation" by Kraus. drop-∥∥₃ : ∀ ℓ {a b c d} {A : Type a} {B : A → Type b} {C : A → (∀ x → B x) → Type c} {D : A → (f : ∀ x → B x) → (∀ x → C x f) → Type d} → Extensionality (lsuc (a ⊔ ℓ)) (a ⊔ b ⊔ c ⊔ d ⊔ ℓ) → (∥ A ∥ 1 (a ⊔ ℓ) → ∃ λ (f : ∀ x → B x) → ∃ λ (g : ∀ x → C x f) → ∀ x → D x f g) ↔ (∃ λ (f : ∀ x → B x) → ∃ λ (g : ∀ x → C x f) → ∀ x → D x f g) drop-∥∥₃ ℓ {b = b} {c} {A = A} {B} {C} {D} ext = (∥ A ∥ 1 _ → ∃ λ (f : ∀ x → B x) → ∃ λ (g : ∀ x → C x f) → ∀ x → D x f g) ↝⟨ push-∥∥ ℓ ext ⟩ (∃ λ (f : ∀ x → B x) → ∥ A ∥ 1 _ → ∃ λ (g : ∀ x → C x f) → ∀ x → D x f g) ↝⟨ (∃-cong λ _ → push-∥∥ ℓ (lower-extensionality lzero b ext)) ⟩ (∃ λ (f : ∀ x → B x) → ∃ λ (g : ∀ x → C x f) → ∥ A ∥ 1 _ → ∀ x → D x f g) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → drop-∥∥ ℓ (lower-extensionality lzero (b ⊔ c) ext)) ⟩□ (∃ λ (f : ∀ x → B x) → ∃ λ (g : ∀ x → C x f) → ∀ x → D x f g) □ -- Having a coherently constant function into a groupoid is equivalent -- to having a function from a propositionally truncated type into the -- groupoid (assuming extensionality). This result is Proposition 2.3 -- in "The General Universal Property of the Propositional Truncation" -- by Kraus. Coherently-constant : ∀ {a b} {A : Type a} {B : Type b} → (A → B) → Type (a ⊔ b) Coherently-constant f = ∃ λ (c : Constant f) → ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃ coherently-constant-function≃∥inhabited∥⇒inhabited : ∀ {a b} ℓ {A : Type a} {B : Type b} → Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (a ⊔ b ⊔ ℓ) → H-level 3 B → (∃ λ (f : A → B) → Coherently-constant f) ≃ (∥ A ∥ 1 (a ⊔ b ⊔ ℓ) → B) coherently-constant-function≃∥inhabited∥⇒inhabited {a} {b} ℓ {A} {B} ext B-groupoid = (∃ λ (f : A → B) → Coherently-constant f) ↔⟨ inverse $ drop-∥∥₃ (b ⊔ ℓ) ext ⟩ (∥ A ∥ 1 ℓ′ → ∃ λ (f : A → B) → Coherently-constant f) ↝⟨ ∀-cong (lower-extensionality lzero ℓ ext) (inverse ∘ equivalence₂) ⟩□ (∥ A ∥ 1 ℓ′ → B) □ where ℓ′ = a ⊔ b ⊔ ℓ rearrangement-lemma = λ a₀ → (∃ λ (f₁ : B) → ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (c : Constant f) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ ∃-comm ⟩ (∃ λ (f : A → B) → ∃ λ (f₁ : B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (c : Constant f) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (f : A → B) → ∃ λ (f₁ : B) → ∃ λ (c : Constant f) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-comm) ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (f₁ : B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (f₁ : B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) → (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (f₁ : B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) → (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (f₁ : B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) → (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (f₁ : B) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) → (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (f₁ : B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) → (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (f₁ : B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) → (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) → (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ×-comm) ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (d₂ : (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) → trans (c a₀ a₀) (c₁ a₀) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩□ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (d₂ : (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → trans (c a₀ a₀) (c₁ a₀) ≡ c₂) □ equivalence₁ : A → (B ≃ ∃ λ (f : A → B) → Coherently-constant f) equivalence₁ a₀ = Eq.↔⇒≃ ( B ↝⟨ (inverse $ drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 0 λ _ → singleton-contractible _) ⟩ (∃ λ (f₁ : B) → (a : A) → ∃ λ (b : B) → b ≡ f₁) ↝⟨ (∃-cong λ _ → ΠΣ-comm) ⟩ (∃ λ (f₁ : B) → ∃ λ (f : A → B) → (a : A) → f a ≡ f₁) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → inverse $ drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ Π-closure (lower-extensionality _ ℓ ext) 0 λ _ → Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 0 λ _ → singleton-contractible _) ⟩ (∃ λ (f₁ : B) → ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∀ a₁ a₂ → ∃ λ (c : f a₁ ≡ f a₂) → c ≡ trans (c₁ a₁) (sym (c₁ a₂))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong (lower-extensionality _ ℓ ext) λ _ → ∀-cong (lower-extensionality _ (a ⊔ ℓ) ext) λ _ → ∃-cong λ _ → ≡⇒↝ _ $ sym $ [trans≡]≡[≡trans-symʳ] _ _ _) ⟩ (∃ λ (f₁ : B) → ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∀ a₁ a₂ → ∃ λ (c : f a₁ ≡ f a₂) → trans c (c₁ a₂) ≡ c₁ a₁) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong (lower-extensionality _ ℓ ext) λ _ → ΠΣ-comm) ⟩ (∃ λ (f₁ : B) → ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∀ a₁ → ∃ λ (c : ∀ a₂ → f a₁ ≡ f a₂) → ∀ a₂ → trans (c a₂) (c₁ a₂) ≡ c₁ a₁) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ΠΣ-comm) ⟩ (∃ λ (f₁ : B) → ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (c : Constant f) → ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → inverse $ drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ other-singleton-contractible _) ⟩ (∃ λ (f₁ : B) → ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (c : Constant f) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (c₂ : f a₀ ≡ f₁) → trans (c a₀ a₀) (c₁ a₀) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ c₁ → ∃-cong λ c → ∃-cong λ d₁ → ∃-cong λ _ → inverse $ drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (Π-closure (lower-extensionality _ ℓ ext) 1 λ _ → Π-closure (lower-extensionality _ ℓ ext) 1 λ _ → Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 1 λ _ → B-groupoid) (λ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡⟨ cong₂ trans (≡⇒↝ implication ([trans≡]≡[≡trans-symʳ] _ _ _) (d₁ _ _)) (≡⇒↝ implication ([trans≡]≡[≡trans-symʳ] _ _ _) (d₁ _ _)) ⟩ trans (trans (c₁ a₁) (sym (c₁ a₂))) (trans (c₁ a₂) (sym (c₁ a₃))) ≡⟨ sym $ trans-assoc _ _ _ ⟩ trans (trans (trans (c₁ a₁) (sym (c₁ a₂))) (c₁ a₂)) (sym (c₁ a₃)) ≡⟨ cong (flip trans _) $ trans-[trans-sym]- _ _ ⟩ trans (c₁ a₁) (sym (c₁ a₃)) ≡⟨ sym $ ≡⇒↝ implication ([trans≡]≡[≡trans-symʳ] _ _ _) (d₁ _ _) ⟩∎ c a₁ a₃ ∎)) ⟩ (∃ λ (f₁ : B) → ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (c : Constant f) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) → ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ c₁ → ∃-cong λ c → ∃-cong λ d₁ → ∃-cong λ c₂ → ∃-cong λ d₃ → inverse $ drop-⊤-right λ d → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 1 λ _ → B-groupoid) (λ a → trans (c a₀ a) (c₁ a) ≡⟨ cong (λ x → trans x _) $ sym $ d _ _ _ ⟩ trans (trans (c a₀ a₀) (c a₀ a)) (c₁ a) ≡⟨ trans-assoc _ _ _ ⟩ trans (c a₀ a₀) (trans (c a₀ a) (c₁ a)) ≡⟨ cong (trans _) $ d₁ _ _ ⟩ trans (c a₀ a₀) (c₁ a₀) ≡⟨ d₃ ⟩∎ c₂ ∎)) ⟩ (∃ λ (f₁ : B) → ∃ λ (f : A → B) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (c : Constant f) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (d₃ : trans (c a₀ a₀) (c₁ a₀) ≡ c₂) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ rearrangement-lemma a₀ ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (d₂ : (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) → ∃ λ (d₁ : ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) → trans (c a₀ a₀) (c₁ a₀) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ d₂ → drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (B-groupoid) (d₂ _)) ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → ∃ λ (d₂ : (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) → ∀ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡ c₁ a₁) ↝⟨ (∃-cong λ _ → ∃-cong λ c → ∃-cong λ d → ∃-cong λ _ → ∃-cong λ c₂ → ∃-cong λ c₁ → drop-⊤-right λ d₂ → _⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible (Π-closure (lower-extensionality _ ℓ ext) 1 λ _ → Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 1 λ _ → B-groupoid) (λ a₁ a₂ → trans (c a₁ a₂) (c₁ a₂) ≡⟨ cong₂ trans (sym $ d _ _ _) (≡⇒↝ implication ([trans≡]≡[≡trans-symˡ] _ _ _) (d₂ _)) ⟩ trans (trans (c a₁ a₀) (c a₀ a₂)) (trans (sym (c a₀ a₂)) c₂) ≡⟨ sym $ trans-assoc _ _ _ ⟩ trans (trans (trans (c a₁ a₀) (c a₀ a₂)) (sym (c a₀ a₂))) c₂ ≡⟨ cong (flip trans _) $ trans-[trans]-sym _ _ ⟩ trans (c a₁ a₀) c₂ ≡⟨ cong (trans _) $ sym $ d₂ _ ⟩ trans (c a₁ a₀) (trans (c a₀ a₁) (c₁ a₁)) ≡⟨ sym $ trans-assoc _ _ _ ⟩ trans (trans (c a₁ a₀) (c a₀ a₁)) (c₁ a₁) ≡⟨ cong (flip trans _) $ d _ _ _ ⟩ trans (c a₁ a₁) (c₁ a₁) ≡⟨ cong (flip trans _) $ Groupoid.idempotent⇒≡id (EG.groupoid _) (d _ _ _) ⟩ trans (refl _) (c₁ a₁) ≡⟨ trans-reflˡ _ ⟩∎ c₁ a₁ ∎)) ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) → ∃ λ (c₁ : (a : A) → f a ≡ f₁) → (a : A) → trans (c a₀ a) (c₁ a) ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → inverse ΠΣ-comm) ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) → (a : A) → ∃ λ (c₁ : f a ≡ f₁) → trans (c a₀ a) c₁ ≡ c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong (lower-extensionality _ (a ⊔ ℓ) ext) λ _ → ∃-cong λ _ → ≡⇒↝ _ $ [trans≡]≡[≡trans-symˡ] _ _ _) ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (f₁ : B) → ∃ λ (c₂ : f a₀ ≡ f₁) → (a : A) → ∃ λ (c₁ : f a ≡ f₁) → c₁ ≡ trans (sym (c a₀ a)) c₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 0 λ _ → singleton-contractible _) ⟩ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∃ λ (d : ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) → ∃ λ (f₁ : B) → f a₀ ≡ f₁) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ other-singleton-contractible _) ⟩□ (∃ λ (f : A → B) → ∃ λ (c : Constant f) → ∀ a₁ a₂ a₃ → trans (c a₁ a₂) (c a₂ a₃) ≡ c a₁ a₃) □) -- An alternative implementation of the forward component of the -- equivalence above (with shorter proofs). to : B → ∃ λ (f : A → B) → Coherently-constant f to b = (λ _ → b) , (λ _ _ → refl b) , (λ _ _ _ → trans-refl-refl) to-is-an-equivalence : A → Is-equivalence to to-is-an-equivalence a₀ = Eq.respects-extensional-equality (λ b → Σ-≡,≡→≡ (refl _) $ Σ-≡,≡→≡ (proj₁ (subst Coherently-constant (refl _) (proj₂ (_≃_.to (equivalence₁ a₀) b))) ≡⟨ cong proj₁ $ subst-refl Coherently-constant _ ⟩ (λ _ _ → trans (refl b) (sym (refl b))) ≡⟨ (apply-ext (lower-extensionality _ ℓ ext) λ _ → apply-ext (lower-extensionality _ (a ⊔ ℓ) ext) λ _ → trans-symʳ _) ⟩∎ (λ _ _ → refl b) ∎) ((Π-closure (lower-extensionality _ ℓ ext) 1 λ _ → Π-closure (lower-extensionality _ ℓ ext) 1 λ _ → Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 1 λ _ → B-groupoid) _ _)) (_≃_.is-equivalence (equivalence₁ a₀)) -- The forward component of the equivalence above does not depend on -- the value a₀ of type A, so it suffices to assume that A is merely -- inhabited. equivalence₂ : ∥ A ∥ 1 ℓ′ → (B ≃ ∃ λ (f : A → B) → Coherently-constant f) equivalence₂ ∥a∥ = Eq.⟨ to , rec 1 (Eq.propositional (lower-extensionality _ ℓ ext) _) to-is-an-equivalence (with-lower-level ℓ 1 ∥a∥) ⟩ -- Having a constant function into a set is equivalent to having a -- function from a propositionally truncated type into the set -- (assuming extensionality). The statement of this result is that of -- Proposition 2.2 in "The General Universal Property of the -- Propositional Truncation" by Kraus, but it uses a different proof: -- as observed by Kraus this result follows from Proposition 2.3. constant-function≃∥inhabited∥⇒inhabited : ∀ {a b} ℓ {A : Type a} {B : Type b} → Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (a ⊔ b ⊔ ℓ) → Is-set B → (∃ λ (f : A → B) → Constant f) ≃ (∥ A ∥ 1 (a ⊔ b ⊔ ℓ) → B) constant-function≃∥inhabited∥⇒inhabited {a} {b} ℓ {A} {B} ext B-set = (∃ λ (f : A → B) → Constant f) ↔⟨ (∃-cong λ f → inverse $ drop-⊤-right λ c → _⇔_.to contractible⇔↔⊤ $ Π-closure (lower-extensionality _ ℓ ext) 0 λ _ → Π-closure (lower-extensionality _ ℓ ext) 0 λ _ → Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 0 λ _ → +⇒≡ B-set) ⟩ (∃ λ (f : A → B) → Coherently-constant f) ↝⟨ coherently-constant-function≃∥inhabited∥⇒inhabited ℓ ext (mono₁ 2 B-set) ⟩□ (∥ A ∥ 1 (a ⊔ b ⊔ ℓ) → B) □ private -- One direction of the proposition above computes in the right way. to-constant-function≃∥inhabited∥⇒inhabited : ∀ {a b} ℓ {A : Type a} {B : Type b} (ext : Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (a ⊔ b ⊔ ℓ)) (B-set : Is-set B) (f : ∃ λ (f : A → B) → Constant f) (x : A) → _≃_.to (constant-function≃∥inhabited∥⇒inhabited ℓ ext B-set) f ∣ x ∣₁ ≡ proj₁ f x to-constant-function≃∥inhabited∥⇒inhabited _ _ _ _ _ = refl _ -- The propositional truncation's universal property (defined using -- extensionality). -- -- As observed by Kraus this result follows from Proposition 2.2 in -- his "The General Universal Property of the Propositional -- Truncation". universal-property : ∀ {a b} ℓ {A : Type a} {B : Type b} → Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (a ⊔ b ⊔ ℓ) → Is-proposition B → (∥ A ∥ 1 (a ⊔ b ⊔ ℓ) → B) ≃ (A → B) universal-property {a = a} {b} ℓ {A} {B} ext B-prop = Eq.with-other-function ((∥ A ∥ 1 (a ⊔ b ⊔ ℓ) → B) ↝⟨ inverse $ constant-function≃∥inhabited∥⇒inhabited ℓ ext (mono₁ 1 B-prop) ⟩ (∃ λ (f : A → B) → Constant f) ↔⟨ (drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $ Π-closure (lower-extensionality _ ℓ ext) 0 λ _ → Π-closure (lower-extensionality _ (a ⊔ ℓ) ext) 0 λ _ → +⇒≡ B-prop) ⟩□ (A → B) □) (_∘ ∣_∣₁) (λ f → apply-ext (lower-extensionality _ (a ⊔ ℓ) ext) λ x → subst (const B) (refl x) (f ∣ x ∣₁) ≡⟨ subst-refl _ _ ⟩∎ f ∣ x ∣₁ ∎) private -- The universal property computes in the right way. to-universal-property : ∀ {a b} ℓ {A : Type a} {B : Type b} (ext : Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (a ⊔ b ⊔ ℓ)) (B-prop : Is-proposition B) (f : ∥ A ∥ 1 (a ⊔ b ⊔ ℓ) → B) → _≃_.to (universal-property ℓ ext B-prop) f ≡ f ∘ ∣_∣₁ to-universal-property _ _ _ _ = refl _ from-universal-property : ∀ {a b} ℓ {A : Type a} {B : Type b} (ext : Extensionality (lsuc (a ⊔ b ⊔ ℓ)) (a ⊔ b ⊔ ℓ)) (B-prop : Is-proposition B) (f : A → B) (x : A) → _≃_.from (universal-property ℓ ext B-prop) f ∣ x ∣₁ ≡ f x from-universal-property _ _ _ _ _ = refl _ -- Some properties of an imagined "real" /propositional/ truncation. module Real-propositional-truncation (∥_∥ʳ : ∀ {a} → Type a → Type a) (∣_∣ʳ : ∀ {a} {A : Type a} → A → ∥ A ∥ʳ) (truncation-is-proposition : ∀ {a} {A : Type a} → Is-proposition ∥ A ∥ʳ) (recʳ : ∀ {a b} {A : Type a} {B : Type b} → Is-proposition B → (A → B) → ∥ A ∥ʳ → B) where -- The function recʳ can be used to define a dependently typed -- eliminator (assuming extensionality). elimʳ : ∀ {a p} {A : Type a} → Extensionality a p → (P : ∥ A ∥ʳ → Type p) → (∀ x → Is-proposition (P x)) → ((x : A) → P ∣ x ∣ʳ) → (x : ∥ A ∥ʳ) → P x elimʳ {A = A} ext P P-prop f x = recʳ {A = A} {B = ∀ x → P x} (Π-closure ext 1 P-prop) (λ x _ → subst P (truncation-is-proposition _ _) (f x)) x x -- The eliminator gives the right result, up to propositional -- equality, when applied to ∣ x ∣ʳ. elimʳ-∣∣ʳ : ∀ {a p} {A : Type a} (ext : Extensionality a p) (P : ∥ A ∥ʳ → Type p) (P-prop : ∀ x → Is-proposition (P x)) (f : (x : A) → P ∣ x ∣ʳ) (x : A) → elimʳ ext P P-prop f ∣ x ∣ʳ ≡ f x elimʳ-∣∣ʳ ext P P-prop f x = P-prop _ _ _ -- The "real" propositional truncation is isomorphic to the one -- defined above (assuming extensionality). isomorphic : ∀ {ℓ a} {A : Type a} → Extensionality (lsuc (a ⊔ ℓ)) (a ⊔ ℓ) → ∥ A ∥ʳ ↔ ∥ A ∥ 1 (a ⊔ ℓ) isomorphic {ℓ} ext = record { surjection = record { logical-equivalence = record { to = recʳ (truncation-has-correct-h-level 1 ext) ∣_∣₁ ; from = lower {ℓ = ℓ} ∘ rec 1 (↑-closure 1 truncation-is-proposition) (lift ∘ ∣_∣ʳ) } ; right-inverse-of = λ _ → truncation-has-correct-h-level 1 ext _ _ } ; left-inverse-of = λ _ → truncation-is-proposition _ _ } -- The axiom of choice, in one of the alternative forms given in the -- HoTT book (§3.8). -- -- The HoTT book uses a "real" propositional truncation, rather than -- the defined one used here. Note that I don't know if the universe -- levels used below (b ⊔ ℓ and a ⊔ b ⊔ ℓ) make sense. However, in the -- presence of a "real" propositional truncation (and extensionality) -- they can be dropped (see Real-propositional-truncation.isomorphic). Axiom-of-choice : (a b ℓ : Level) → Type (lsuc (a ⊔ b ⊔ ℓ)) Axiom-of-choice a b ℓ = {A : Type a} {B : A → Type b} → Is-set A → (∀ x → ∥ B x ∥ 1 (b ⊔ ℓ)) → ∥ (∀ x → B x) ∥ 1 (a ⊔ b ⊔ ℓ)
45.111542
146
0.402666
43a9e65b8a2f23c6723aa009aa932c250d4d9904
178
agda
Agda
Data/Empty/Base.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Data/Empty/Base.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Data/Empty/Base.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --without-K --safe #-} module Data.Empty.Base where open import Level data ⊥ : Type where infix 4.5 ¬_ ¬_ : Type a → Type a ¬ A = A → ⊥ ⊥-elim : ⊥ → A ⊥-elim ()
11.866667
34
0.567416
34f3cd1ff1b2773e762dab67b34728f6b2c50638
109
agda
Agda
test/interaction/Issue3020.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue3020.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue3020.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
record R : Set₁ where field A : Set B : Set B = A field C : Set D : Set D = A → B → C
8.384615
21
0.440367
1318a22e35c8361d3cd7861d511c87a754d84957
18,448
agda
Agda
Cubical/Algebra/CommAlgebra/FreeCommAlgebra/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Algebra/CommAlgebra/FreeCommAlgebra/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Algebra/CommAlgebra/FreeCommAlgebra/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --safe #-} module Cubical.Algebra.CommAlgebra.FreeCommAlgebra.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.Structure open import Cubical.Foundations.Function hiding (const) open import Cubical.Foundations.Isomorphism open import Cubical.Data.Sigma.Properties using (Σ≡Prop) open import Cubical.HITs.SetTruncation open import Cubical.Algebra.CommRing open import Cubical.Algebra.CommAlgebra.FreeCommAlgebra.Base open import Cubical.Algebra.Ring using () open import Cubical.Algebra.CommAlgebra open import Cubical.Algebra.CommAlgebra.Instances.Initial open import Cubical.Algebra.Algebra open import Cubical.Data.Empty open import Cubical.Data.Sigma private variable ℓ ℓ' ℓ'' : Level module Theory {R : CommRing ℓ} {I : Type ℓ'} where open CommRingStr (snd R) using (0r; 1r) renaming (_·_ to _·r_; _+_ to _+r_; ·Comm to ·r-comm; ·Rid to ·r-rid) module _ (A : CommAlgebra R ℓ'') (φ : I → ⟨ A ⟩) where open CommAlgebraStr (A .snd) open AlgebraTheory (CommRing→Ring R) (CommAlgebra→Algebra A) open Construction using (var; const) renaming (_+_ to _+c_; -_ to -c_; _·_ to _·c_) imageOf0Works : 0r ⋆ 1a ≡ 0a imageOf0Works = 0-actsNullifying 1a imageOf1Works : 1r ⋆ 1a ≡ 1a imageOf1Works = ⋆-lid 1a inducedMap : ⟨ R [ I ] ⟩ → ⟨ A ⟩ inducedMap (var x) = φ x inducedMap (const r) = r ⋆ 1a inducedMap (P +c Q) = (inducedMap P) + (inducedMap Q) inducedMap (-c P) = - inducedMap P inducedMap (Construction.+-assoc P Q S i) = +-assoc (inducedMap P) (inducedMap Q) (inducedMap S) i inducedMap (Construction.+-rid P i) = let eq : (inducedMap P) + (inducedMap (const 0r)) ≡ (inducedMap P) eq = (inducedMap P) + (inducedMap (const 0r)) ≡⟨ refl ⟩ (inducedMap P) + (0r ⋆ 1a) ≡⟨ cong (λ u → (inducedMap P) + u) (imageOf0Works) ⟩ (inducedMap P) + 0a ≡⟨ +-rid _ ⟩ (inducedMap P) ∎ in eq i inducedMap (Construction.+-rinv P i) = let eq : (inducedMap P - inducedMap P) ≡ (inducedMap (const 0r)) eq = (inducedMap P - inducedMap P) ≡⟨ +-rinv _ ⟩ 0a ≡⟨ sym imageOf0Works ⟩ (inducedMap (const 0r))∎ in eq i inducedMap (Construction.+-comm P Q i) = +-comm (inducedMap P) (inducedMap Q) i inducedMap (P ·c Q) = inducedMap P · inducedMap Q inducedMap (Construction.·-assoc P Q S i) = ·Assoc (inducedMap P) (inducedMap Q) (inducedMap S) i inducedMap (Construction.·-lid P i) = let eq = inducedMap (const 1r) · inducedMap P ≡⟨ cong (λ u → u · inducedMap P) imageOf1Works ⟩ 1a · inducedMap P ≡⟨ ·Lid (inducedMap P) ⟩ inducedMap P ∎ in eq i inducedMap (Construction.·-comm P Q i) = ·-comm (inducedMap P) (inducedMap Q) i inducedMap (Construction.ldist P Q S i) = ·Ldist+ (inducedMap P) (inducedMap Q) (inducedMap S) i inducedMap (Construction.+HomConst s t i) = ⋆-ldist s t 1a i inducedMap (Construction.·HomConst s t i) = let eq = (s ·r t) ⋆ 1a ≡⟨ cong (λ u → u ⋆ 1a) (·r-comm _ _) ⟩ (t ·r s) ⋆ 1a ≡⟨ ⋆-assoc t s 1a ⟩ t ⋆ (s ⋆ 1a) ≡⟨ cong (λ u → t ⋆ u) (sym (·Rid _)) ⟩ t ⋆ ((s ⋆ 1a) · 1a) ≡⟨ ⋆-rassoc t (s ⋆ 1a) 1a ⟩ (s ⋆ 1a) · (t ⋆ 1a) ∎ in eq i inducedMap (Construction.0-trunc P Q p q i j) = isSetAlgebra (CommAlgebra→Algebra A) (inducedMap P) (inducedMap Q) (cong _ p) (cong _ q) i j module _ where open IsAlgebraHom inducedHom : CommAlgebraHom (R [ I ]) A inducedHom .fst = inducedMap inducedHom .snd .pres0 = 0-actsNullifying _ inducedHom .snd .pres1 = imageOf1Works inducedHom .snd .pres+ x y = refl inducedHom .snd .pres· x y = refl inducedHom .snd .pres- x = refl inducedHom .snd .pres⋆ r x = (r ⋆ 1a) · inducedMap x ≡⟨ ⋆-lassoc r 1a (inducedMap x) ⟩ r ⋆ (1a · inducedMap x) ≡⟨ cong (λ u → r ⋆ u) (·Lid (inducedMap x)) ⟩ r ⋆ inducedMap x ∎ module _ (A : CommAlgebra R ℓ'') where open CommAlgebraStr (A .snd) open AlgebraTheory (CommRing→Ring R) (CommAlgebra→Algebra A) open Construction using (var; const) renaming (_+_ to _+c_; -_ to -c_; _·_ to _·c_) Hom = CommAlgebraHom (R [ I ]) A open IsAlgebraHom evaluateAt : Hom → I → ⟨ A ⟩ evaluateAt φ x = φ .fst (var x) mapRetrievable : ∀ (φ : I → ⟨ A ⟩) → evaluateAt (inducedHom A φ) ≡ φ mapRetrievable φ = refl proveEq : ∀ {X : Type ℓ''} (isSetX : isSet X) (f g : ⟨ R [ I ] ⟩ → X) → (var-eq : (x : I) → f (var x) ≡ g (var x)) → (const-eq : (r : ⟨ R ⟩) → f (const r) ≡ g (const r)) → (+-eq : (x y : ⟨ R [ I ] ⟩) → (eq-x : f x ≡ g x) → (eq-y : f y ≡ g y) → f (x +c y) ≡ g (x +c y)) → (·-eq : (x y : ⟨ R [ I ] ⟩) → (eq-x : f x ≡ g x) → (eq-y : f y ≡ g y) → f (x ·c y) ≡ g (x ·c y)) → (-eq : (x : ⟨ R [ I ] ⟩) → (eq-x : f x ≡ g x) → f (-c x) ≡ g (-c x)) → f ≡ g proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (var x) = var-eq x i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (const x) = const-eq x i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (x +c y) = +-eq x y (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x) (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i y) i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (-c x) = -eq x ((λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x)) i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (x ·c y) = ·-eq x y (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x) (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i y) i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+-assoc x y z j) = let rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x) a₀₋ : f (x +c (y +c z)) ≡ g (x +c (y +c z)) a₀₋ = +-eq _ _ (rec x) (+-eq _ _ (rec y) (rec z)) a₁₋ : f ((x +c y) +c z) ≡ g ((x +c y) +c z) a₁₋ = +-eq _ _ (+-eq _ _ (rec x) (rec y)) (rec z) a₋₀ : f (x +c (y +c z)) ≡ f ((x +c y) +c z) a₋₀ = cong f (Construction.+-assoc x y z) a₋₁ : g (x +c (y +c z)) ≡ g ((x +c y) +c z) a₋₁ = cong g (Construction.+-assoc x y z) in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+-rid x j) = let rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x) a₀₋ : f (x +c (const 0r)) ≡ g (x +c (const 0r)) a₀₋ = +-eq _ _ (rec x) (const-eq 0r) a₁₋ : f x ≡ g x a₁₋ = rec x a₋₀ : f (x +c (const 0r)) ≡ f x a₋₀ = cong f (Construction.+-rid x) a₋₁ : g (x +c (const 0r)) ≡ g x a₋₁ = cong g (Construction.+-rid x) in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+-rinv x j) = let rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x) a₀₋ : f (x +c (-c x)) ≡ g (x +c (-c x)) a₀₋ = +-eq x (-c x) (rec x) (-eq x (rec x)) a₁₋ : f (const 0r) ≡ g (const 0r) a₁₋ = const-eq 0r a₋₀ : f (x +c (-c x)) ≡ f (const 0r) a₋₀ = cong f (Construction.+-rinv x) a₋₁ : g (x +c (-c x)) ≡ g (const 0r) a₋₁ = cong g (Construction.+-rinv x) in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+-comm x y j) = let rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x) a₀₋ : f (x +c y) ≡ g (x +c y) a₀₋ = +-eq x y (rec x) (rec y) a₁₋ : f (y +c x) ≡ g (y +c x) a₁₋ = +-eq y x (rec y) (rec x) a₋₀ : f (x +c y) ≡ f (y +c x) a₋₀ = cong f (Construction.+-comm x y) a₋₁ : g (x +c y) ≡ g (y +c x) a₋₁ = cong g (Construction.+-comm x y) in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.·-assoc x y z j) = let rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x) a₀₋ : f (x ·c (y ·c z)) ≡ g (x ·c (y ·c z)) a₀₋ = ·-eq _ _ (rec x) (·-eq _ _ (rec y) (rec z)) a₁₋ : f ((x ·c y) ·c z) ≡ g ((x ·c y) ·c z) a₁₋ = ·-eq _ _ (·-eq _ _ (rec x) (rec y)) (rec z) a₋₀ : f (x ·c (y ·c z)) ≡ f ((x ·c y) ·c z) a₋₀ = cong f (Construction.·-assoc x y z) a₋₁ : g (x ·c (y ·c z)) ≡ g ((x ·c y) ·c z) a₋₁ = cong g (Construction.·-assoc x y z) in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.·-lid x j) = let rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x) a₀₋ : f ((const 1r) ·c x) ≡ g ((const 1r) ·c x) a₀₋ = ·-eq _ _ (const-eq 1r) (rec x) a₁₋ : f x ≡ g x a₁₋ = rec x a₋₀ : f ((const 1r) ·c x) ≡ f x a₋₀ = cong f (Construction.·-lid x) a₋₁ : g ((const 1r) ·c x) ≡ g x a₋₁ = cong g (Construction.·-lid x) in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.·-comm x y j) = let rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x) a₀₋ : f (x ·c y) ≡ g (x ·c y) a₀₋ = ·-eq _ _ (rec x) (rec y) a₁₋ : f (y ·c x) ≡ g (y ·c x) a₁₋ = ·-eq _ _ (rec y) (rec x) a₋₀ : f (x ·c y) ≡ f (y ·c x) a₋₀ = cong f (Construction.·-comm x y) a₋₁ : g (x ·c y) ≡ g (y ·c x) a₋₁ = cong g (Construction.·-comm x y) in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.ldist x y z j) = let rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x) a₀₋ : f ((x +c y) ·c z) ≡ g ((x +c y) ·c z) a₀₋ = ·-eq (x +c y) z (+-eq _ _ (rec x) (rec y)) (rec z) a₁₋ : f ((x ·c z) +c (y ·c z)) ≡ g ((x ·c z) +c (y ·c z)) a₁₋ = +-eq _ _ (·-eq _ _ (rec x) (rec z)) (·-eq _ _ (rec y) (rec z)) a₋₀ : f ((x +c y) ·c z) ≡ f ((x ·c z) +c (y ·c z)) a₋₀ = cong f (Construction.ldist x y z) a₋₁ : g ((x +c y) ·c z) ≡ g ((x ·c z) +c (y ·c z)) a₋₁ = cong g (Construction.ldist x y z) in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.+HomConst s t j) = let rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x) a₀₋ : f (const (s +r t)) ≡ g (const (s +r t)) a₀₋ = const-eq (s +r t) a₁₋ : f (const s +c const t) ≡ g (const s +c const t) a₁₋ = +-eq _ _ (const-eq s) (const-eq t) a₋₀ : f (const (s +r t)) ≡ f (const s +c const t) a₋₀ = cong f (Construction.+HomConst s t) a₋₁ : g (const (s +r t)) ≡ g (const s +c const t) a₋₁ = cong g (Construction.+HomConst s t) in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.·HomConst s t j) = let rec : (x : ⟨ R [ I ] ⟩) → f x ≡ g x rec x = (λ i → proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x) a₀₋ : f (const (s ·r t)) ≡ g (const (s ·r t)) a₀₋ = const-eq (s ·r t) a₁₋ : f (const s ·c const t) ≡ g (const s ·c const t) a₁₋ = ·-eq _ _ (const-eq s) (const-eq t) a₋₀ : f (const (s ·r t)) ≡ f (const s ·c const t) a₋₀ = cong f (Construction.·HomConst s t) a₋₁ : g (const (s ·r t)) ≡ g (const s ·c const t) a₋₁ = cong g (Construction.·HomConst s t) in isSet→isSet' isSetX a₀₋ a₁₋ a₋₀ a₋₁ j i proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i (Construction.0-trunc x y p q j k) = let P : (x : ⟨ R [ I ] ⟩) → f x ≡ g x P x i = proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x Q : (x : ⟨ R [ I ] ⟩) → f x ≡ g x Q x i = proveEq isSetX f g var-eq const-eq +-eq ·-eq -eq i x in isOfHLevel→isOfHLevelDep 2 (λ z → isProp→isSet (isSetX (f z) (g z))) _ _ (cong P p) (cong Q q) (Construction.0-trunc x y p q) j k i homRetrievable : ∀ (f : Hom) → inducedMap A (evaluateAt f) ≡ fst f homRetrievable f = proveEq (isSetAlgebra (CommAlgebra→Algebra A)) (inducedMap A (evaluateAt f)) (λ x → f $a x) (λ x → refl) (λ r → r ⋆ 1a ≡⟨ cong (λ u → r ⋆ u) (sym f.pres1) ⟩ r ⋆ (f $a (const 1r)) ≡⟨ sym (f.pres⋆ r _) ⟩ f $a (const r ·c const 1r) ≡⟨ cong (λ u → f $a u) (sym (Construction.·HomConst r 1r)) ⟩ f $a (const (r ·r 1r)) ≡⟨ cong (λ u → f $a (const u)) (·r-rid r) ⟩ f $a (const r) ∎) (λ x y eq-x eq-y → ι (x +c y) ≡⟨ refl ⟩ (ι x + ι y) ≡⟨ cong (λ u → u + ι y) eq-x ⟩ ((f $a x) + ι y) ≡⟨ cong (λ u → (f $a x) + u) eq-y ⟩ ((f $a x) + (f $a y)) ≡⟨ sym (f.pres+ _ _) ⟩ (f $a (x +c y)) ∎) (λ x y eq-x eq-y → ι (x ·c y) ≡⟨ refl ⟩ ι x · ι y ≡⟨ cong (λ u → u · ι y) eq-x ⟩ (f $a x) · (ι y) ≡⟨ cong (λ u → (f $a x) · u) eq-y ⟩ (f $a x) · (f $a y) ≡⟨ sym (f.pres· _ _) ⟩ f $a (x ·c y) ∎) (λ x eq-x → ι (-c x) ≡⟨ refl ⟩ - ι x ≡⟨ cong (λ u → - u) eq-x ⟩ - (f $a x) ≡⟨ sym (f.pres- x) ⟩ f $a (-c x) ∎) where ι = inducedMap A (evaluateAt f) module f = IsAlgebraHom (f .snd) evaluateAt : {R : CommRing ℓ} {I : Type ℓ'} (A : CommAlgebra R ℓ'') (f : CommAlgebraHom (R [ I ]) A) → (I → fst A) evaluateAt A f x = f $a (Construction.var x) inducedHom : {R : CommRing ℓ} {I : Type ℓ'} (A : CommAlgebra R ℓ'') (φ : I → fst A ) → CommAlgebraHom (R [ I ]) A inducedHom A φ = Theory.inducedHom A φ homMapIso : {R : CommRing ℓ} {I : Type ℓ''} (A : CommAlgebra R ℓ') → Iso (CommAlgebraHom (R [ I ]) A) (I → (fst A)) Iso.fun (homMapIso A) = evaluateAt A Iso.inv (homMapIso A) = inducedHom A Iso.rightInv (homMapIso A) = λ ϕ → Theory.mapRetrievable A ϕ Iso.leftInv (homMapIso {R = R} {I = I} A) = λ f → Σ≡Prop (λ f → isPropIsCommAlgebraHom {M = R [ I ]} {N = A} f) (Theory.homRetrievable A f) homMapPath : {R : CommRing ℓ} {I : Type ℓ} (A : CommAlgebra R ℓ') → CommAlgebraHom (R [ I ]) A ≡ (I → fst A) homMapPath A = isoToPath (homMapIso A) -- The homomorphism induced by the variables is the identity. inducedHomVar : (R : CommRing ℓ) (I : Type ℓ') → inducedHom (R [ I ]) Construction.var ≡ idCAlgHom (R [ I ]) inducedHomVar R I = isoFunInjective (homMapIso (R [ I ])) _ _ refl module _ {R : CommRing ℓ} {A B : CommAlgebra R ℓ''} where open AlgebraHoms A′ = CommAlgebra→Algebra A B′ = CommAlgebra→Algebra B R′ = (CommRing→Ring R) ν : AlgebraHom A′ B′ → (⟨ A ⟩ → ⟨ B ⟩) ν φ = φ .fst {- Hom(R[I],A) → (I → A) ↓ ↓ψ Hom(R[I],B) → (I → B) -} naturalEvR : {I : Type ℓ'} (ψ : CommAlgebraHom A B) (f : CommAlgebraHom (R [ I ]) A) → (fst ψ) ∘ evaluateAt A f ≡ evaluateAt B (ψ ∘a f) naturalEvR ψ f = refl {- Hom(R[I],A) ← (I → A) ↓ ↓ψ Hom(R[I],B) ← (I → B) -} natIndHomR : {I : Type ℓ'} (ψ : CommAlgebraHom A B) (ϕ : I → ⟨ A ⟩) → ψ ∘a inducedHom A ϕ ≡ inducedHom B (fst ψ ∘ ϕ) natIndHomR ψ ϕ = isoFunInjective (homMapIso B) _ _ (evaluateAt B (ψ ∘a (inducedHom A ϕ)) ≡⟨ refl ⟩ fst ψ ∘ evaluateAt A (inducedHom A ϕ) ≡⟨ refl ⟩ fst ψ ∘ ϕ ≡⟨ Iso.rightInv (homMapIso B) _ ⟩ evaluateAt B (inducedHom B (fst ψ ∘ ϕ)) ∎) {- Hom(R[I],A) → (I → A) ↓ ↓ Hom(R[J],A) → (J → A) -} naturalEvL : {I J : Type ℓ'} (φ : J → I) (f : CommAlgebraHom (R [ I ]) A) → (evaluateAt A f) ∘ φ ≡ evaluateAt A (f ∘a (inducedHom (R [ I ]) (λ x → Construction.var (φ x)))) naturalEvL φ f = refl module _ {R : CommRing ℓ} where {- Prove that the FreeCommAlgebra over R on zero generators is isomorphic to the initial R-Algebra - R itsself. -} freeOn⊥ : CommAlgebraEquiv (R [ ⊥ ]) (initialCAlg R) freeOn⊥ = equivByInitiality R (R [ ⊥ ]) {- Show that R[⊥] has the universal property of the initial R-Algbera and conclude that those are isomorphic -} λ B → let to : CommAlgebraHom (R [ ⊥ ]) B → (⊥ → fst B) to = evaluateAt B from : (⊥ → fst B) → CommAlgebraHom (R [ ⊥ ]) B from = inducedHom B from-to : (x : _) → from (to x) ≡ x from-to x = Σ≡Prop (λ f → isPropIsCommAlgebraHom {M = R [ ⊥ ]} {N = B} f) (Theory.homRetrievable B x) equiv : CommAlgebraHom (R [ ⊥ ]) B ≃ (⊥ → fst B) equiv = isoToEquiv (iso to from (λ x → isContr→isOfHLevel 1 isContr⊥→A _ _) from-to) in isOfHLevelRespectEquiv 0 (invEquiv equiv) isContr⊥→A
42.506912
102
0.47848
1b3a8d9a27498a8a517962395a5591fa12763bd7
253
agda
Agda
demo/agda/FRP/JS/Demo/Calculator.agda
agda/agda-frp-js
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
[ "MIT", "BSD-3-Clause" ]
63
2015-04-20T21:47:00.000Z
2022-02-28T09:46:14.000Z
demo/agda/FRP/JS/Demo/Calculator.agda
agda/agda-frp-js
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
[ "MIT", "BSD-3-Clause" ]
null
null
null
demo/agda/FRP/JS/Demo/Calculator.agda
agda/agda-frp-js
c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72
[ "MIT", "BSD-3-Clause" ]
7
2016-11-07T21:50:58.000Z
2022-03-12T11:39:38.000Z
open import FRP.JS.Behaviour using ( Beh ) open import FRP.JS.DOM using ( DOM ) open import FRP.JS.RSet using ( ⟦_⟧ ) open import FRP.JS.Demo.Calculator.View using ( view ) module FRP.JS.Demo.Calculator where main : ∀ {w} → ⟦ Beh (DOM w) ⟧ main = view
28.111111
54
0.6917
cb78cc9b80937bf367afa031b1592581194fc852
12,798
agda
Agda
src/data/lib/prim/Agda/Builtin/Reflection.agda
xekoukou/agda
75d3f20f94280881ec0a35ed0ae2ab4f1042c8fe
[ "BSD-3-Clause" ]
null
null
null
src/data/lib/prim/Agda/Builtin/Reflection.agda
xekoukou/agda
75d3f20f94280881ec0a35ed0ae2ab4f1042c8fe
[ "BSD-3-Clause" ]
1
2020-01-26T18:22:08.000Z
2020-01-26T18:22:08.000Z
src/data/lib/prim/Agda/Builtin/Reflection.agda
xekoukou/agda
75d3f20f94280881ec0a35ed0ae2ab4f1042c8fe
[ "BSD-3-Clause" ]
null
null
null
{-# OPTIONS --without-K --safe --no-sized-types --no-guardedness #-} module Agda.Builtin.Reflection where open import Agda.Builtin.Unit open import Agda.Builtin.Bool open import Agda.Builtin.Nat open import Agda.Builtin.Word open import Agda.Builtin.List open import Agda.Builtin.String open import Agda.Builtin.Char open import Agda.Builtin.Float open import Agda.Builtin.Int open import Agda.Builtin.Sigma -- Names -- postulate Name : Set {-# BUILTIN QNAME Name #-} primitive primQNameEquality : Name → Name → Bool primQNameLess : Name → Name → Bool primShowQName : Name → String -- Fixity -- data Associativity : Set where left-assoc : Associativity right-assoc : Associativity non-assoc : Associativity data Precedence : Set where related : Float → Precedence unrelated : Precedence data Fixity : Set where fixity : Associativity → Precedence → Fixity {-# BUILTIN ASSOC Associativity #-} {-# BUILTIN ASSOCLEFT left-assoc #-} {-# BUILTIN ASSOCRIGHT right-assoc #-} {-# BUILTIN ASSOCNON non-assoc #-} {-# BUILTIN PRECEDENCE Precedence #-} {-# BUILTIN PRECRELATED related #-} {-# BUILTIN PRECUNRELATED unrelated #-} {-# BUILTIN FIXITY Fixity #-} {-# BUILTIN FIXITYFIXITY fixity #-} {-# COMPILE GHC Associativity = data MAlonzo.RTE.Assoc (MAlonzo.RTE.LeftAssoc | MAlonzo.RTE.RightAssoc | MAlonzo.RTE.NonAssoc) #-} {-# COMPILE GHC Precedence = data MAlonzo.RTE.Precedence (MAlonzo.RTE.Related | MAlonzo.RTE.Unrelated) #-} {-# COMPILE GHC Fixity = data MAlonzo.RTE.Fixity (MAlonzo.RTE.Fixity) #-} {-# COMPILE JS Associativity = function (x,v) { return v[x](); } #-} {-# COMPILE JS left-assoc = "left-assoc" #-} {-# COMPILE JS right-assoc = "right-assoc" #-} {-# COMPILE JS non-assoc = "non-assoc" #-} {-# COMPILE JS Precedence = function (x,v) { if (x === "unrelated") { return v[x](); } else { return v["related"](x); }} #-} {-# COMPILE JS related = function(x) { return x; } #-} {-# COMPILE JS unrelated = "unrelated" #-} {-# COMPILE JS Fixity = function (x,v) { return v["fixity"](x["assoc"], x["prec"]); } #-} {-# COMPILE JS fixity = function (x) { return function (y) { return { "assoc": x, "prec": y}; }; } #-} primitive primQNameFixity : Name → Fixity primQNameToWord64s : Name → Σ Word64 (λ _ → Word64) -- Metavariables -- postulate Meta : Set {-# BUILTIN AGDAMETA Meta #-} primitive primMetaEquality : Meta → Meta → Bool primMetaLess : Meta → Meta → Bool primShowMeta : Meta → String primMetaToNat : Meta → Nat -- Arguments -- -- Arguments can be (visible), {hidden}, or {{instance}}. data Visibility : Set where visible hidden instance′ : Visibility {-# BUILTIN HIDING Visibility #-} {-# BUILTIN VISIBLE visible #-} {-# BUILTIN HIDDEN hidden #-} {-# BUILTIN INSTANCE instance′ #-} -- Arguments can be relevant or irrelevant. data Relevance : Set where relevant irrelevant : Relevance {-# BUILTIN RELEVANCE Relevance #-} {-# BUILTIN RELEVANT relevant #-} {-# BUILTIN IRRELEVANT irrelevant #-} data ArgInfo : Set where arg-info : (v : Visibility) (r : Relevance) → ArgInfo data Arg {a} (A : Set a) : Set a where arg : (i : ArgInfo) (x : A) → Arg A {-# BUILTIN ARGINFO ArgInfo #-} {-# BUILTIN ARGARGINFO arg-info #-} {-# BUILTIN ARG Arg #-} {-# BUILTIN ARGARG arg #-} -- Name abstraction -- data Abs {a} (A : Set a) : Set a where abs : (s : String) (x : A) → Abs A {-# BUILTIN ABS Abs #-} {-# BUILTIN ABSABS abs #-} -- Literals -- data Literal : Set where nat : (n : Nat) → Literal word64 : (n : Word64) → Literal float : (x : Float) → Literal char : (c : Char) → Literal string : (s : String) → Literal name : (x : Name) → Literal meta : (x : Meta) → Literal {-# BUILTIN AGDALITERAL Literal #-} {-# BUILTIN AGDALITNAT nat #-} {-# BUILTIN AGDALITWORD64 word64 #-} {-# BUILTIN AGDALITFLOAT float #-} {-# BUILTIN AGDALITCHAR char #-} {-# BUILTIN AGDALITSTRING string #-} {-# BUILTIN AGDALITQNAME name #-} {-# BUILTIN AGDALITMETA meta #-} -- Patterns -- data Pattern : Set where con : (c : Name) (ps : List (Arg Pattern)) → Pattern dot : Pattern var : (s : String) → Pattern lit : (l : Literal) → Pattern proj : (f : Name) → Pattern absurd : Pattern {-# BUILTIN AGDAPATTERN Pattern #-} {-# BUILTIN AGDAPATCON con #-} {-# BUILTIN AGDAPATDOT dot #-} {-# BUILTIN AGDAPATVAR var #-} {-# BUILTIN AGDAPATLIT lit #-} {-# BUILTIN AGDAPATPROJ proj #-} {-# BUILTIN AGDAPATABSURD absurd #-} -- Terms -- data Sort : Set data Clause : Set data Term : Set Type = Term data Term where var : (x : Nat) (args : List (Arg Term)) → Term con : (c : Name) (args : List (Arg Term)) → Term def : (f : Name) (args : List (Arg Term)) → Term lam : (v : Visibility) (t : Abs Term) → Term pat-lam : (cs : List Clause) (args : List (Arg Term)) → Term pi : (a : Arg Type) (b : Abs Type) → Term agda-sort : (s : Sort) → Term lit : (l : Literal) → Term meta : (x : Meta) → List (Arg Term) → Term unknown : Term data Sort where set : (t : Term) → Sort lit : (n : Nat) → Sort unknown : Sort data Clause where clause : (ps : List (Arg Pattern)) (t : Term) → Clause absurd-clause : (ps : List (Arg Pattern)) → Clause {-# BUILTIN AGDASORT Sort #-} {-# BUILTIN AGDATERM Term #-} {-# BUILTIN AGDACLAUSE Clause #-} {-# BUILTIN AGDATERMVAR var #-} {-# BUILTIN AGDATERMCON con #-} {-# BUILTIN AGDATERMDEF def #-} {-# BUILTIN AGDATERMMETA meta #-} {-# BUILTIN AGDATERMLAM lam #-} {-# BUILTIN AGDATERMEXTLAM pat-lam #-} {-# BUILTIN AGDATERMPI pi #-} {-# BUILTIN AGDATERMSORT agda-sort #-} {-# BUILTIN AGDATERMLIT lit #-} {-# BUILTIN AGDATERMUNSUPPORTED unknown #-} {-# BUILTIN AGDASORTSET set #-} {-# BUILTIN AGDASORTLIT lit #-} {-# BUILTIN AGDASORTUNSUPPORTED unknown #-} {-# BUILTIN AGDACLAUSECLAUSE clause #-} {-# BUILTIN AGDACLAUSEABSURD absurd-clause #-} -- Definitions -- data Definition : Set where function : (cs : List Clause) → Definition data-type : (pars : Nat) (cs : List Name) → Definition record-type : (c : Name) (fs : List (Arg Name)) → Definition data-cons : (d : Name) → Definition axiom : Definition prim-fun : Definition {-# BUILTIN AGDADEFINITION Definition #-} {-# BUILTIN AGDADEFINITIONFUNDEF function #-} {-# BUILTIN AGDADEFINITIONDATADEF data-type #-} {-# BUILTIN AGDADEFINITIONRECORDDEF record-type #-} {-# BUILTIN AGDADEFINITIONDATACONSTRUCTOR data-cons #-} {-# BUILTIN AGDADEFINITIONPOSTULATE axiom #-} {-# BUILTIN AGDADEFINITIONPRIMITIVE prim-fun #-} -- Errors -- data ErrorPart : Set where strErr : String → ErrorPart termErr : Term → ErrorPart nameErr : Name → ErrorPart {-# BUILTIN AGDAERRORPART ErrorPart #-} {-# BUILTIN AGDAERRORPARTSTRING strErr #-} {-# BUILTIN AGDAERRORPARTTERM termErr #-} {-# BUILTIN AGDAERRORPARTNAME nameErr #-} -- Constraints -- data Comparison : Set where cmpEq : Comparison cmpLEq : Comparison {-# BUILTIN AGDACOMPARISON Comparison #-} {-# BUILTIN AGDACMPEQ cmpEq #-} {-# BUILTIN AGDACMPLEQ cmpLEq #-} data CompareAs : Set where asTermsOf : Term → CompareAs asTypes : CompareAs asSizes : CompareAs {-# BUILTIN AGDACOMPAREAS CompareAs #-} {-# BUILTIN AGDAASTERMSOF asTermsOf #-} {-# BUILTIN AGDAASTYPES asTypes #-} {-# BUILTIN AGDAASSIZES asSizes #-} data Constraint : Set where valueCmp : Comparison → CompareAs → Term → Term → Constraint unsupported : Constraint {-# BUILTIN AGDACONSTRAINT Constraint #-} {-# BUILTIN AGDACONSTRAINTVALUECMP valueCmp #-} {-# BUILTIN AGDACONSTRAINTUNSUPPORTED unsupported #-} data Closure {a} (A : Set a) : Set a where closure : List (Arg Type) → A → Closure A {-# BUILTIN AGDACLOSURE Closure #-} {-# BUILTIN AGDACLOSURECLOSURE closure #-} -- TC monad -- postulate TC : ∀ {a} → Set a → Set a returnTC : ∀ {a} {A : Set a} → A → TC A bindTC : ∀ {a b} {A : Set a} {B : Set b} → TC A → (A → TC B) → TC B unify : Term → Term → TC ⊤ typeError : ∀ {a} {A : Set a} → List ErrorPart → TC A inferType : Term → TC Type checkType : Term → Type → TC Term normalise : Term → TC Term reduce : Term → TC Term catchTC : ∀ {a} {A : Set a} → TC A → TC A → TC A quoteTC : ∀ {a} {A : Set a} → A → TC Term unquoteTC : ∀ {a} {A : Set a} → Term → TC A getContext : TC (List (Arg Type)) extendContext : ∀ {a} {A : Set a} → Arg Type → TC A → TC A inContext : ∀ {a} {A : Set a} → List (Arg Type) → TC A → TC A freshName : String → TC Name declareDef : Arg Name → Type → TC ⊤ declarePostulate : Arg Name → Type → TC ⊤ defineFun : Name → List Clause → TC ⊤ getType : Name → TC Type getDefinition : Name → TC Definition blockOnMeta : ∀ {a} {A : Set a} → Meta → TC A commitTC : TC ⊤ isMacro : Name → TC Bool -- If the argument is 'true' makes the following primitives also normalise -- their results: inferType, checkType, quoteTC, getType, and getContext withNormalisation : ∀ {a} {A : Set a} → Bool → TC A → TC A -- Prints the third argument if the corresponding verbosity level is turned -- on (with the -v flag to Agda). debugPrint : String → Nat → List ErrorPart → TC ⊤ -- Fail if the given computation gives rise to new, unsolved -- "blocking" constraints. noConstraints : ∀ {a} {A : Set a} → TC A → TC A -- Gets all the constraints that mention the given meta-variables. getConstraintsMentioning : List Meta → TC (List (Closure Constraint)) -- Run the given TC action and return the first component. Resets to -- the old TC state if the second component is 'false', or keep the -- new TC state if it is 'true'. runSpeculative : ∀ {a} {A : Set a} → TC (Σ A λ _ → Bool) → TC A -- Delay the execution of a macro till the Declaration it is -- used in, has been typechecked. delayMacro : TC ⊤ {-# BUILTIN AGDATCM TC #-} {-# BUILTIN AGDATCMRETURN returnTC #-} {-# BUILTIN AGDATCMBIND bindTC #-} {-# BUILTIN AGDATCMUNIFY unify #-} {-# BUILTIN AGDATCMTYPEERROR typeError #-} {-# BUILTIN AGDATCMINFERTYPE inferType #-} {-# BUILTIN AGDATCMCHECKTYPE checkType #-} {-# BUILTIN AGDATCMNORMALISE normalise #-} {-# BUILTIN AGDATCMREDUCE reduce #-} {-# BUILTIN AGDATCMCATCHERROR catchTC #-} {-# BUILTIN AGDATCMQUOTETERM quoteTC #-} {-# BUILTIN AGDATCMUNQUOTETERM unquoteTC #-} {-# BUILTIN AGDATCMGETCONTEXT getContext #-} {-# BUILTIN AGDATCMEXTENDCONTEXT extendContext #-} {-# BUILTIN AGDATCMINCONTEXT inContext #-} {-# BUILTIN AGDATCMFRESHNAME freshName #-} {-# BUILTIN AGDATCMDECLAREDEF declareDef #-} {-# BUILTIN AGDATCMDECLAREPOSTULATE declarePostulate #-} {-# BUILTIN AGDATCMDEFINEFUN defineFun #-} {-# BUILTIN AGDATCMGETTYPE getType #-} {-# BUILTIN AGDATCMGETDEFINITION getDefinition #-} {-# BUILTIN AGDATCMBLOCKONMETA blockOnMeta #-} {-# BUILTIN AGDATCMCOMMIT commitTC #-} {-# BUILTIN AGDATCMISMACRO isMacro #-} {-# BUILTIN AGDATCMWITHNORMALISATION withNormalisation #-} {-# BUILTIN AGDATCMDEBUGPRINT debugPrint #-} {-# BUILTIN AGDATCMNOCONSTRAINTS noConstraints #-} {-# BUILTIN AGDATCMGETCONSTRAINTSMENTIONING getConstraintsMentioning #-} {-# BUILTIN AGDATCMRUNSPECULATIVE runSpeculative #-} {-# BUILTIN AGDATCMDELAYMACRO delayMacro #-}
35.848739
130
0.571027
34769eed04a39441463969ece45ae775f8313740
801
agda
Agda
test/Fail/JasonReedPruning.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/JasonReedPruning.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/JasonReedPruning.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2012-05-04 Example from Jason Reed, LFMTP 2009 -- Andreas, 2013-02-18 occurs check does not longer give error, hence -- we only get unsolved metas. {- {-# OPTIONS --allow-unsolved-metas #-} -- The option is supplied to force a real error to pass the regression test. -} module JasonReedPruning where open import Common.Equality open import Common.Product data o : Set where f : o -> o test : let U : o → o U = _ V : o → o V = _ W : o → o W = _ in (x y : o) → U x ≡ f (V (W y)) × V x ≡ U (W y) test x y = refl , refl {- Considering U (W y) = V x, we can prune x from V V x = V' After instantiation U x = f V' (solved) V' = U (W y) (not solved) U = \ x → f V' V' = f V' occurs check fails -}
19.536585
76
0.554307
8bc6364a079d41acb5755a2a6348591674471eca
5,056
agda
Agda
test/interaction/Issue1365.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue1365.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue1365.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Giving /lift \phi/ the the first hole TWICE (the first time you get an type error), causes the following internal error: -- An internal error has occurred. Please report this as a bug. -- Location of the error: -- src/full/Agda/TypeChecking/Reduce/Monad.hs:118 ------------------------------------------------------------------------ -- Library infixr 9 _∘_ _∘_ : ∀ {a b c} {A : Set a} {B : A → Set b} {C : {x : A} → B x → Set c} → (∀ {x} (y : B x) → C y) → (g : (x : A) → B x) → ((x : A) → C (g x)) f ∘ g = λ x → f (g x) data ⊥ : Set where data _⊎_ (A : Set) (B : Set) : Set where inj₁ : (x : A) → A ⊎ B inj₂ : (y : B) → A ⊎ B [_,_] : ∀ {A : Set} {B : Set} {C : A ⊎ B → Set} → ((x : A) → C (inj₁ x)) → ((x : B) → C (inj₂ x)) → ((x : A ⊎ B) → C x) [ f , g ] (inj₁ x) = f x [ f , g ] (inj₂ y) = g y [_,_]₁ : ∀ {A : Set} {B : Set} {C : A ⊎ B → Set₁} → ((x : A) → C (inj₁ x)) → ((x : B) → C (inj₂ x)) → ((x : A ⊎ B) → C x) [ f , g ]₁ (inj₁ x) = f x [ f , g ]₁ (inj₂ y) = g y record Σ (X : Set) (Y : X → Set) : Set where constructor _,_ field proj₁ : X proj₂ : Y proj₁ open Σ public _×_ : Set → Set → Set X × Y = Σ X λ _ → Y data _≡_ {X : Set} (x : X) : X → Set where refl : x ≡ x subst : ∀ {A} (P : A → Set) {x y} → x ≡ y → P x → P y subst P refl p = p Pow : Set → Set₁ Pow X = X → Set _∈_ : ∀ {X} → X → Pow X → Set x ∈ P = P x infix 4 _⊆_ _⊆_ : ∀ {X} → Pow X → Pow X → Set P ⊆ Q = ∀ {x} → x ∈ P → x ∈ Q _∪_ : ∀ {X} → Pow X → Pow X → Pow X P ∪ Q = λ x → P x ⊎ Q x _⇒_ : ∀ {X} → Pow X → Pow X → Pow X P ⇒ Q = λ x → x ∈ P → x ∈ Q record _▷_ (I O : Set) : Set₁ where constructor _◃_/_ field Parameter : (o : O) → Set Arity : ∀ {o} (p : Parameter o) → Set input : ∀ {o} (p : Parameter o) (a : Arity p) → I open _▷_ public Sig = λ I → I ▷ I ⟦_⟧ : ∀ {I O} → I ▷ O → (Pow I → Pow O) ⟦ P ◃ A / s ⟧ X o = Σ (P o) λ p → ((a : A p) → X (s p a)) data μ {I} (Ω : Sig I) : Pow I where sup : ⟦ Ω ⟧ (μ Ω) ⊆ μ Ω const^C : ∀ {I O} → Pow O → I ▷ O const^C X = X ◃ (λ _ → ⊥) / λ x () _⊎^C_ : ∀ {I O} → I ▷ O → I ▷ O → I ▷ O (P₁ ◃ A₁ / s₁) ⊎^C (P₂ ◃ A₂ / s₂) = (P₁ ∪ P₂) ◃ [ A₁ , A₂ ]₁ / [ s₁ , s₂ ] _⊙^C_ : ∀ {I J} → I ▷ I → J ▷ J → (I × J) ▷ (I × J) (P₁ ◃ A₁ / s₁) ⊙^C (P₂ ◃ A₂ / s₂) = (λ { (i , j) → P₁ i ⊎ P₂ j }) ◃ [ A₁ , A₂ ]₁ / (λ { {_ , j} (inj₁ p₁) a₁ → s₁ p₁ a₁ , j ; {i , _} (inj₂ p₂) a₂ → i , s₂ p₂ a₂ }) _⋆^C_ : ∀ {O} → O ▷ O → Pow O → O ▷ O Σ ⋆^C X = const^C X ⊎^C Σ _⋆_ : ∀ {O} → O ▷ O → Pow O → Pow O Σ ⋆ X = μ (Σ ⋆^C X) Alg : ∀ {I} → Sig I → Pow I → Set Alg Ω X = ⟦ Ω ⟧ X ⊆ X act : ∀ {O} {Σ : O ▷ O} {X} → Alg Σ (Σ ⋆ X) act (p , k) = sup (inj₂ p , k) Hom : ∀ {I J} → Sig (I × J) → Pow (I × J) → Pow I → Sig J → Pow J → Set Hom Ω U V Ψ W = Alg (const^C U ⊎^C Ω) ((V ∘ proj₁) ⇒ ((Ψ ⋆ W) ∘ proj₂)) _⋊_ : ∀ {I O} (C : I ▷ O) Z → (I × Z) ▷ (O × Z) (P ◃ A / s) ⋊ Z = (P ∘ proj₁) ◃ A / λ {oz} p a → s p a , proj₂ oz record ContainerMorphism {I₁ I₂ O₁ O₂} (C₁ : I₁ ▷ O₁) (C₂ : I₂ ▷ O₂) (f : I₁ → I₂) (g : O₁ → O₂) (_∼_ : I₂ → I₂ → Set) (_≈_ : Set → Set → Set) (_·_ : ∀ {A B} → A ≈ B → A → B) : Set where field parameter : Parameter C₁ ⊆ Parameter C₂ ∘ g arity : ∀ {o} {p₁ : Parameter C₁ o} → Arity C₂ (parameter p₁) ≈ Arity C₁ p₁ coherent : ∀ {o} {p₁ : Parameter C₁ o} {a₂ : Arity C₂ (parameter p₁)} → f (input C₁ p₁ (arity · a₂)) ∼ input C₂ (parameter p₁) a₂ open ContainerMorphism public _⇛[_/_]_ : ∀ {I₁ I₂ O₁ O₂} → I₁ ▷ O₁ → (I₁ → I₂) → (O₁ → O₂) → I₂ ▷ O₂ → Set C₁ ⇛[ f / g ] C₂ = ContainerMorphism C₁ C₂ f g _≡_ (λ R₂ R₁ → R₂ → R₁) (λ f x → f x) _⇛[_]_ : ∀ {I J} → I ▷ I → (I → J) → J ▷ J → Set C₁ ⇛[ f ] C₂ = C₁ ⇛[ f / f ] C₂ ⟪_⟫ : ∀ {I J} {C₁ : I ▷ I} {C₂ : J ▷ J} {f : I → J} → C₁ ⇛[ f ] C₂ → (X : Pow J) → ⟦ C₁ ⟧ (X ∘ f) ⊆ ⟦ C₂ ⟧ X ∘ f ⟪ m ⟫ X (c , k) = parameter m c , λ a₂ → subst X (coherent m) (k (arity m a₂)) ------------------------------------------------------------------------ weaken : ∀ {I J} {Ω : Sig I} {Ψ : Sig J} {X : Pow J} {f : I → J} → Alg Ψ X → Ω ⇛[ f ] Ψ → Alg Ω (X ∘ f) weaken {X = X} φ m (p , k) = φ (⟪ m ⟫ X (p , k)) lift : ∀ {I J} {Ω : Sig I} {U : Pow (I × J)} {V : Pow I} {Ψ : Sig J} {W : Pow J} → Hom (Ω ⋊ J) U V Ψ W → Hom (Ω ⊙^C Ψ) U V Ψ W lift φ (inj₁ u , _) = φ (inj₁ u , λ ()) lift φ (inj₂ (inj₁ p) , k) = φ (inj₂ p , k) lift φ (inj₂ (inj₂ p) , k) = λ v → act (p , λ a → k a v) handle : ∀ {I J K} {Ω : Sig I} {Ω′ : Sig J} {Ω″ : Sig K} {U : Pow (J × K)} {V : Pow J} {W : Pow K} {f : I → J × K} → Hom (Ω′ ⋊ K) U V Ω″ W → Ω ⇛[ f ] (Ω′ ⊙^C Ω″) → ∀ {i} → i ∈ (Ω ⋆ (U ∘ f)) → let (j , k) = f i in j ∈ V → k ∈ (Ω″ ⋆ W) handle φ m (sup (inj₁ u , _)) v = φ (inj₁ u , λ ()) v handle φ m (sup (inj₂ p , k)) v = weaken {!lift φ!} {!!} {!!} -- Expected outcome: -- giving "lift φ" twice should give the same error twice.
29.91716
123
0.39735
fde107762b92cfae61371d422af9993783447285
4,951
agda
Agda
Cubical/Algebra/DistLattice/BigOps.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Algebra/DistLattice/BigOps.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Algebra/DistLattice/BigOps.agda
hyleIndex/cubical
ce5c2820ecb2e0fd8dce74fb0247856cdbf034c4
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
-- define ⋁ and ⋀ as the bigOps of a Ring when interpreted -- as an additive/multiplicative monoid {-# OPTIONS --safe #-} module Cubical.Algebra.DistLattice.BigOps where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport open import Cubical.Foundations.SIP open import Cubical.Data.Sigma open import Cubical.Data.Nat using (ℕ ; zero ; suc) open import Cubical.Data.FinData open import Cubical.Data.Bool open import Cubical.Structures.Axioms open import Cubical.Structures.Auto open import Cubical.Structures.Macro open import Cubical.Algebra.Semigroup open import Cubical.Algebra.Monoid open import Cubical.Algebra.Monoid.BigOp open import Cubical.Algebra.CommMonoid open import Cubical.Algebra.Semilattice open import Cubical.Algebra.Lattice open import Cubical.Algebra.DistLattice private variable ℓ : Level module KroneckerDelta (L' : DistLattice ℓ) where private L = fst L' open DistLatticeStr (snd L') δ : {n : ℕ} (i j : Fin n) → L δ i j = if i == j then 1l else 0l module Join (L' : DistLattice ℓ) where private L = fst L' open DistLatticeStr (snd L') open MonoidBigOp (Semilattice→Monoid (Lattice→JoinSemilattice (DistLattice→Lattice L'))) -- extra DistLattice→JoinMonoid? open LatticeTheory (DistLattice→Lattice L') open KroneckerDelta L' ⋁ = bigOp ⋁Ext = bigOpExt ⋁0l = bigOpε ⋁Last = bigOpLast ⋁Split : ∀ {n} → (V W : FinVec L n) → ⋁ (λ i → V i ∨l W i) ≡ ⋁ V ∨l ⋁ W ⋁Split = bigOpSplit ∨lComm ⋁Meetrdist : ∀ {n} → (x : L) → (V : FinVec L n) → x ∧l ⋁ V ≡ ⋁ λ i → x ∧l V i ⋁Meetrdist {n = zero} x _ = 0lRightAnnihilates∧l x ⋁Meetrdist {n = suc n} x V = x ∧l (V zero ∨l ⋁ (V ∘ suc)) ≡⟨ ∧lLdist∨l _ _ _ ⟩ --Ldist and Rdist wrong way around? (x ∧l V zero) ∨l (x ∧l ⋁ (V ∘ suc)) ≡⟨ (λ i → (x ∧l V zero) ∨l ⋁Meetrdist x (V ∘ suc) i) ⟩ (x ∧l V zero) ∨l ⋁ (λ i → x ∧l V (suc i)) ∎ ⋁Meetldist : ∀ {n} → (x : L) → (V : FinVec L n) → (⋁ V) ∧l x ≡ ⋁ λ i → V i ∧l x ⋁Meetldist {n = zero} x _ = 0lLeftAnnihilates∧l x ⋁Meetldist {n = suc n} x V = (V zero ∨l ⋁ (V ∘ suc)) ∧l x ≡⟨ ∧lRdist∨l _ _ _ ⟩ (V zero ∧l x) ∨l ((⋁ (V ∘ suc)) ∧l x) ≡⟨ (λ i → (V zero ∧l x) ∨l ⋁Meetldist x (V ∘ suc) i) ⟩ (V zero ∧l x) ∨l ⋁ (λ i → V (suc i) ∧l x) ∎ ⋁Meetr0 : ∀ {n} → (V : FinVec L n) → ⋁ (λ i → V i ∧l 0l) ≡ 0l ⋁Meetr0 V = sym (⋁Meetldist 0l V) ∙ 0lRightAnnihilates∧l _ ⋁Meet0r : ∀ {n} → (V : FinVec L n) → ⋁ (λ i → 0l ∧l V i) ≡ 0l ⋁Meet0r V = sym (⋁Meetrdist 0l V) ∙ 0lLeftAnnihilates∧l _ ⋁Meetr1 : (n : ℕ) (V : FinVec L n) → (j : Fin n) → ⋁ (λ i → V i ∧l δ i j) ≡ V j ⋁Meetr1 (suc n) V zero = (λ k → ∧lRid (V zero) k ∨l ⋁Meetr0 (V ∘ suc) k) ∙ ∨lRid (V zero) ⋁Meetr1 (suc n) V (suc j) = (λ i → 0lRightAnnihilates∧l (V zero) i ∨l ⋁ (λ x → V (suc x) ∧l δ x j)) ∙∙ ∨lLid _ ∙∙ ⋁Meetr1 n (V ∘ suc) j ⋁Meet1r : (n : ℕ) (V : FinVec L n) → (j : Fin n) → ⋁ (λ i → (δ j i) ∧l V i) ≡ V j ⋁Meet1r (suc n) V zero = (λ k → ∧lLid (V zero) k ∨l ⋁Meet0r (V ∘ suc) k) ∙ ∨lRid (V zero) ⋁Meet1r (suc n) V (suc j) = (λ i → 0lLeftAnnihilates∧l (V zero) i ∨l ⋁ (λ i → (δ j i) ∧l V (suc i))) ∙∙ ∨lLid _ ∙∙ ⋁Meet1r n (V ∘ suc) j module Meet (L' : DistLattice ℓ) where private L = fst L' open DistLatticeStr (snd L') open MonoidBigOp (Semilattice→Monoid (Lattice→MeetSemilattice (DistLattice→Lattice L'))) -- extra DistLattice→MeetMonoid? open LatticeTheory (DistLattice→Lattice L') open KroneckerDelta L' ⋀ = bigOp ⋀Ext = bigOpExt ⋀1l = bigOpε ⋀Last = bigOpLast ⋀Split : ∀ {n} → (V W : FinVec L n) → ⋀ (λ i → V i ∧l W i) ≡ ⋀ V ∧l ⋀ W ⋀Split = bigOpSplit ∧lComm ⋀Joinrdist : ∀ {n} → (x : L) → (V : FinVec L n) → x ∨l ⋀ V ≡ ⋀ λ i → x ∨l V i ⋀Joinrdist {n = zero} x _ = 1lRightAnnihilates∨l x ⋀Joinrdist {n = suc n} x V = x ∨l (V zero ∧l ⋀ (V ∘ suc)) ≡⟨ ∨lLdist∧l _ _ _ ⟩ --Ldist and Rdist wrong way around? (x ∨l V zero) ∧l (x ∨l ⋀ (V ∘ suc)) ≡⟨ (λ i → (x ∨l V zero) ∧l ⋀Joinrdist x (V ∘ suc) i) ⟩ (x ∨l V zero) ∧l ⋀ (λ i → x ∨l V (suc i)) ∎ ⋀Joinldist : ∀ {n} → (x : L) → (V : FinVec L n) → (⋀ V) ∨l x ≡ ⋀ λ i → V i ∨l x ⋀Joinldist {n = zero} x _ = 1lLeftAnnihilates∨l x ⋀Joinldist {n = suc n} x V = (V zero ∧l ⋀ (V ∘ suc)) ∨l x ≡⟨ ∨lRdist∧l _ _ _ ⟩ (V zero ∨l x) ∧l ((⋀ (V ∘ suc)) ∨l x) ≡⟨ (λ i → (V zero ∨l x) ∧l ⋀Joinldist x (V ∘ suc) i) ⟩ (V zero ∨l x) ∧l ⋀ (λ i → V (suc i) ∨l x) ∎ ⋀Joinr1 : ∀ {n} → (V : FinVec L n) → ⋀ (λ i → V i ∨l 1l) ≡ 1l ⋀Joinr1 V = sym (⋀Joinldist 1l V) ∙ 1lRightAnnihilates∨l _ ⋀Join1r : ∀ {n} → (V : FinVec L n) → ⋀ (λ i → 1l ∨l V i) ≡ 1l ⋀Join1r V = sym (⋀Joinrdist 1l V) ∙ 1lLeftAnnihilates∨l _
36.138686
101
0.581499
1be3c1a9a3465def6ae50338d4424d3781087b23
1,888
agda
Agda
Agda/Ag12.agda
Brethland/LEARNING-STUFF
eb2cef0556efb9a4ce11783f8516789ea48cc344
[ "MIT" ]
2
2020-02-03T05:05:52.000Z
2020-03-11T10:35:42.000Z
Agda/Ag12.agda
Brethland/LEARNING-STUFF
eb2cef0556efb9a4ce11783f8516789ea48cc344
[ "MIT" ]
null
null
null
Agda/Ag12.agda
Brethland/LEARNING-STUFF
eb2cef0556efb9a4ce11783f8516789ea48cc344
[ "MIT" ]
1
2019-12-13T04:50:46.000Z
2019-12-13T04:50:46.000Z
module Ag12 where import Relation.Binary.PropositionalEquality as Eq open Eq open import Data.Nat using (ℕ; zero; suc; _+_; _*_) open import Relation.Nullary using (¬_) open import Data.Product using (_×_; proj₁; proj₂) renaming (_,_ to ⟨_,_⟩) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Function open import Ag09 hiding (_∘_) -- open import Data.Product using (Σ; _,_; ∃; Σ-syntax; ∃-syntax) open import Level using (Level; _⊔_) renaming (zero to lzero; suc to lsuc) open ≡-Reasoning open ≃-Reasoning postulate funExt : ∀ {m n : Level} {A : Set m} {B : Set n} {f g : A → B} → (∀ (x : A) → f x ≡ g x) → f ≡ g lemma₀ : ∀ {A B : Set} → (a : A × B) → ⟨ proj₁ a , proj₂ a ⟩ ≡ a lemma₀ ⟨ fst , snd ⟩ = refl lemma₁ : ∀ {A : Set} {B C : A → Set} → (f : (x : A) → B x × C x) → (λ a → ⟨ proj₁ (f a) , proj₂ (f a) ⟩) ≡ f lemma₁ f = refl ∀-distrib-× : ∀ {A : Set} {B C : A → Set} → (∀ (x : A) → B x × C x) ≃ (∀ (x : A) → B x) × (∀ (x : A) → C x) ∀-distrib-× {A} {B} {C} = record { to = λ bc → ⟨ proj₁ ∘ bc , proj₂ ∘ bc ⟩ ; from = λ bc a → ⟨ proj₁ bc a , proj₂ bc a ⟩ ; from∘to = λ f → refl ; to∘from = λ f → refl } ⊎∀-implies-∀⊎ : ∀ {A : Set} {B C : A → Set} → (∀ (x : A) → B x) ⊎ (∀ (x : A) → C x) → ∀ (x : A) → B x ⊎ C x ⊎∀-implies-∀⊎ (_⊎_.inj₁ x₁) x = _⊎_.inj₁ (x₁ x) ⊎∀-implies-∀⊎ (_⊎_.inj₂ y) x = _⊎_.inj₂ (y x) data Σ (A : Set) (B : A → Set) : Set where ⟨_,_⟩ : (x : A) → B x → Σ A B Σ-syntax = Σ infix 2 Σ-syntax syntax Σ-syntax A (λ x → B) = Σ[ x ∈ A ] B ∃ : ∀ {A : Set} (B : A → Set) → Set ∃ {A} B = Σ A B ∃-syntax = ∃ syntax ∃-syntax (λ x → B) = ∃[ x ] B ∃-distrib-⊎ : ∀ {A : Set} {B C : A → Set} → ∃[ x ] (B x ⊎ C x) ≃ (∃[ x ] B x) ⊎ (∃[ x ] C x) ∃-distrib-⊎ = record { to = λ x → {!!} ; from = λ{ (inj₁ x) → ⟨ {!!} , {!!} ⟩ ; (inj₂ x) → {!!} } ; from∘to = {!!} ; to∘from = {!!} }
29.046154
74
0.473517
523439b07e66a12e155a135f62098687713d9a18
130
agda
Agda
test/Succeed/NoUniverseCheckPragma.agda
alex-mckenna/agda
78b62cd24bbd570271a7153e44ad280e52ef3e29
[ "BSD-3-Clause" ]
1
2021-07-07T10:49:57.000Z
2021-07-07T10:49:57.000Z
test/Succeed/NoUniverseCheckPragma.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
test/Succeed/NoUniverseCheckPragma.agda
andersk/agda
56928ff709dcb931cb9a48c4790e5ed3739e3032
[ "BSD-3-Clause" ]
null
null
null
{-# NO_UNIVERSE_CHECK #-} data U : Set T : U → Set data U where pi : (A : Set)(b : A → U) → U T (pi A b) = (x : A) → T (b x)
13
31
0.461538
041d11f12c2cdea17a80f75976e55ac7795dffbd
2,074
agda
Agda
test/Succeed/DotPatternTermination.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2015-03-28T14:51:03.000Z
2015-12-07T20:14:00.000Z
test/Succeed/DotPatternTermination.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
3
2018-11-14T15:31:44.000Z
2019-04-01T19:39:26.000Z
test/Succeed/DotPatternTermination.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1
2019-03-05T20:02:38.000Z
2019-03-05T20:02:38.000Z
{-# OPTIONS --show-implicit #-} -- {-# OPTIONS -v tc.cover.strategy:20 -v tc.cover.precomputed:10 #-} -- {-# OPTIONS -v term.check.clause:25 #-} -- {-# OPTIONS -v term.matrices:40 #-} module DotPatternTermination where data Nat : Set where zero : Nat suc : Nat -> Nat -- A simple example. module Test1 where data D : Nat -> Set where cz : D zero c1 : forall n -> D n -> D (suc n) c2 : forall n -> D n -> D n -- To see that this is terminating the termination checker has to look at the -- natural number index, which is in a dot pattern. f : forall n -> D n -> Nat f .zero cz = zero f .(suc n) (c1 n d) = f n (c2 n d) f n (c2 .n d) = f n d -- There was a bug with dot patterns having the wrong context which manifested -- itself in the following example. module Test2 where data P : Nat -> Nat -> Set where c : forall {d r} -> P d r -> P (suc d) r c' : forall {d r} -> P d r -> P d r g : forall {d r} -> P d r -> Nat g .{suc d} {r} (c {d} .{r} x) = g (c' x) g (c' _) = zero -- Another bug where the dot patterns weren't substituted properly. module Test3 where data Parser : Nat -> Set where alt : (d : Nat) -> Nat -> Parser d -> Parser (suc d) ! : (d : Nat) -> Parser (suc d) pp : (d : Nat) -> Parser d parse₀ : (d : Nat) -> Parser d -> Nat parse₀ .(suc d) (alt d zero p) = parse₀ d p parse₀ .(suc d) (alt d _ p) = parse₀ d p parse₀ ._ (! d) = parse₀ d (pp d) parse₀ ._ (pp d) = zero module Test4 where -- Andreas, 2016-10-01 see issue #2231 -- abstract f sees through abstract suc, so dot pattern termination -- succeeds. abstract data N : Set where suc' : N → N sucN = suc' data D : N → Set where c1 : ∀ n → D n → D (sucN n) c2 : ∀ n → D n → D n abstract -- To see that this is terminating the termination checker has to look at the -- natural number index, which is in a dot pattern. f : ∀ n → D n → Set f .(sucN n) (c1 n d) = f n (c2 n (c2 n d)) f n (c2 .n d) = f n d
28.805556
79
0.557859
13d39f625c0363b77aff940dcc8bcc8ef6a468f0
19,450
agda
Agda
agda-stdlib/src/Algebra/Bundles.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Algebra/Bundles.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Algebra/Bundles.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Definitions of algebraic structures like monoids and rings -- (packed in records together with sets, operations, etc.) ------------------------------------------------------------------------ -- The contents of this module should be accessed via `Algebra`. {-# OPTIONS --without-K --safe #-} module Algebra.Bundles where open import Algebra.Core open import Algebra.Structures open import Relation.Binary open import Function.Base open import Level ------------------------------------------------------------------------ -- Bundles with 1 binary operation ------------------------------------------------------------------------ record RawMagma c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _∙_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier record Magma c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _∙_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier isMagma : IsMagma _≈_ _∙_ open IsMagma isMagma public rawMagma : RawMagma _ _ rawMagma = record { _≈_ = _≈_; _∙_ = _∙_ } record Semigroup c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _∙_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier isSemigroup : IsSemigroup _≈_ _∙_ open IsSemigroup isSemigroup public magma : Magma c ℓ magma = record { isMagma = isMagma } open Magma magma public using (rawMagma) record Band c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _∙_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier isBand : IsBand _≈_ _∙_ open IsBand isBand public semigroup : Semigroup c ℓ semigroup = record { isSemigroup = isSemigroup } open Semigroup semigroup public using (magma; rawMagma) record CommutativeSemigroup c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _∙_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier isCommutativeSemigroup : IsCommutativeSemigroup _≈_ _∙_ open IsCommutativeSemigroup isCommutativeSemigroup public semigroup : Semigroup c ℓ semigroup = record { isSemigroup = isSemigroup } open Semigroup semigroup public using (magma; rawMagma) record Semilattice c ℓ : Set (suc (c ⊔ ℓ)) where infixr 7 _∧_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∧_ : Op₂ Carrier isSemilattice : IsSemilattice _≈_ _∧_ open IsSemilattice isSemilattice public band : Band c ℓ band = record { isBand = isBand } open Band band public using (rawMagma; magma; semigroup) record SelectiveMagma c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _∙_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier isSelectiveMagma : IsSelectiveMagma _≈_ _∙_ open IsSelectiveMagma isSelectiveMagma public magma : Magma c ℓ magma = record { isMagma = isMagma } open Magma magma public using (rawMagma) ------------------------------------------------------------------------ -- Bundles with 1 binary operation & 1 element ------------------------------------------------------------------------ -- A raw monoid is a monoid without any laws. record RawMonoid c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _∙_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier ε : Carrier rawMagma : RawMagma c ℓ rawMagma = record { _≈_ = _≈_ ; _∙_ = _∙_ } record Monoid c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _∙_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier ε : Carrier isMonoid : IsMonoid _≈_ _∙_ ε open IsMonoid isMonoid public semigroup : Semigroup _ _ semigroup = record { isSemigroup = isSemigroup } rawMonoid : RawMonoid _ _ rawMonoid = record { _≈_ = _≈_; _∙_ = _∙_; ε = ε} open Semigroup semigroup public using (rawMagma; magma) record CommutativeMonoid c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _∙_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier ε : Carrier isCommutativeMonoid : IsCommutativeMonoid _≈_ _∙_ ε open IsCommutativeMonoid isCommutativeMonoid public monoid : Monoid _ _ monoid = record { isMonoid = isMonoid } commutativeSemigroup : CommutativeSemigroup _ _ commutativeSemigroup = record { isCommutativeSemigroup = isCommutativeSemigroup } open Monoid monoid public using (rawMagma; magma; semigroup; rawMonoid) record IdempotentCommutativeMonoid c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _∙_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier ε : Carrier isIdempotentCommutativeMonoid : IsIdempotentCommutativeMonoid _≈_ _∙_ ε open IsIdempotentCommutativeMonoid isIdempotentCommutativeMonoid public commutativeMonoid : CommutativeMonoid _ _ commutativeMonoid = record { isCommutativeMonoid = isCommutativeMonoid } open CommutativeMonoid commutativeMonoid public using (rawMagma; magma; semigroup; rawMonoid; monoid) -- Idempotent commutative monoids are also known as bounded lattices. -- Note that the BoundedLattice necessarily uses the notation inherited -- from monoids rather than lattices. BoundedLattice = IdempotentCommutativeMonoid module BoundedLattice {c ℓ} (idemCommMonoid : IdempotentCommutativeMonoid c ℓ) = IdempotentCommutativeMonoid idemCommMonoid ------------------------------------------------------------------------ -- Bundles with 1 binary operation, 1 unary operation & 1 element ------------------------------------------------------------------------ record RawGroup c ℓ : Set (suc (c ⊔ ℓ)) where infix 8 _⁻¹ infixl 7 _∙_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier ε : Carrier _⁻¹ : Op₁ Carrier rawMonoid : RawMonoid c ℓ rawMonoid = record { _≈_ = _≈_ ; _∙_ = _∙_ ; ε = ε } open RawMonoid rawMonoid public using (rawMagma) record Group c ℓ : Set (suc (c ⊔ ℓ)) where infix 8 _⁻¹ infixl 7 _∙_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier ε : Carrier _⁻¹ : Op₁ Carrier isGroup : IsGroup _≈_ _∙_ ε _⁻¹ open IsGroup isGroup public rawGroup : RawGroup _ _ rawGroup = record { _≈_ = _≈_; _∙_ = _∙_; ε = ε; _⁻¹ = _⁻¹} monoid : Monoid _ _ monoid = record { isMonoid = isMonoid } open Monoid monoid public using (rawMagma; magma; semigroup; rawMonoid) record AbelianGroup c ℓ : Set (suc (c ⊔ ℓ)) where infix 8 _⁻¹ infixl 7 _∙_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∙_ : Op₂ Carrier ε : Carrier _⁻¹ : Op₁ Carrier isAbelianGroup : IsAbelianGroup _≈_ _∙_ ε _⁻¹ open IsAbelianGroup isAbelianGroup public group : Group _ _ group = record { isGroup = isGroup } open Group group public using (rawMagma; magma; semigroup; monoid; rawMonoid; rawGroup) commutativeMonoid : CommutativeMonoid _ _ commutativeMonoid = record { isCommutativeMonoid = isCommutativeMonoid } ------------------------------------------------------------------------ -- Bundles with 2 binary operations ------------------------------------------------------------------------ record Lattice c ℓ : Set (suc (c ⊔ ℓ)) where infixr 7 _∧_ infixr 6 _∨_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∨_ : Op₂ Carrier _∧_ : Op₂ Carrier isLattice : IsLattice _≈_ _∨_ _∧_ open IsLattice isLattice public setoid : Setoid _ _ setoid = record { isEquivalence = isEquivalence } record DistributiveLattice c ℓ : Set (suc (c ⊔ ℓ)) where infixr 7 _∧_ infixr 6 _∨_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∨_ : Op₂ Carrier _∧_ : Op₂ Carrier isDistributiveLattice : IsDistributiveLattice _≈_ _∨_ _∧_ open IsDistributiveLattice isDistributiveLattice public lattice : Lattice _ _ lattice = record { isLattice = isLattice } open Lattice lattice public using (setoid) ------------------------------------------------------------------------ -- Bundles with 2 binary operations & 1 element ------------------------------------------------------------------------ record NearSemiring c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _*_ infixl 6 _+_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _+_ : Op₂ Carrier _*_ : Op₂ Carrier 0# : Carrier isNearSemiring : IsNearSemiring _≈_ _+_ _*_ 0# open IsNearSemiring isNearSemiring public +-monoid : Monoid _ _ +-monoid = record { isMonoid = +-isMonoid } open Monoid +-monoid public using () renaming ( rawMagma to +-rawMagma ; magma to +-magma ; semigroup to +-semigroup ; rawMonoid to +-rawMonoid ) *-semigroup : Semigroup _ _ *-semigroup = record { isSemigroup = *-isSemigroup } open Semigroup *-semigroup public using () renaming ( rawMagma to *-rawMagma ; magma to *-magma ) record SemiringWithoutOne c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _*_ infixl 6 _+_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _+_ : Op₂ Carrier _*_ : Op₂ Carrier 0# : Carrier isSemiringWithoutOne : IsSemiringWithoutOne _≈_ _+_ _*_ 0# open IsSemiringWithoutOne isSemiringWithoutOne public nearSemiring : NearSemiring _ _ nearSemiring = record { isNearSemiring = isNearSemiring } open NearSemiring nearSemiring public using ( +-rawMagma; +-magma; +-semigroup; +-rawMonoid; +-monoid ; *-rawMagma; *-magma; *-semigroup ) +-commutativeMonoid : CommutativeMonoid _ _ +-commutativeMonoid = record { isCommutativeMonoid = +-isCommutativeMonoid } record CommutativeSemiringWithoutOne c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _*_ infixl 6 _+_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _+_ : Op₂ Carrier _*_ : Op₂ Carrier 0# : Carrier isCommutativeSemiringWithoutOne : IsCommutativeSemiringWithoutOne _≈_ _+_ _*_ 0# open IsCommutativeSemiringWithoutOne isCommutativeSemiringWithoutOne public semiringWithoutOne : SemiringWithoutOne _ _ semiringWithoutOne = record { isSemiringWithoutOne = isSemiringWithoutOne } open SemiringWithoutOne semiringWithoutOne public using ( +-rawMagma; +-magma; +-semigroup ; *-rawMagma; *-magma; *-semigroup ; +-rawMonoid; +-monoid; +-commutativeMonoid ; nearSemiring ) ------------------------------------------------------------------------ -- Bundles with 2 binary operations & 2 elements ------------------------------------------------------------------------ record RawSemiring c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _*_ infixl 6 _+_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _+_ : Op₂ Carrier _*_ : Op₂ Carrier 0# : Carrier 1# : Carrier record SemiringWithoutAnnihilatingZero c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _*_ infixl 6 _+_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _+_ : Op₂ Carrier _*_ : Op₂ Carrier 0# : Carrier 1# : Carrier isSemiringWithoutAnnihilatingZero : IsSemiringWithoutAnnihilatingZero _≈_ _+_ _*_ 0# 1# open IsSemiringWithoutAnnihilatingZero isSemiringWithoutAnnihilatingZero public +-commutativeMonoid : CommutativeMonoid _ _ +-commutativeMonoid = record { isCommutativeMonoid = +-isCommutativeMonoid } open CommutativeMonoid +-commutativeMonoid public using () renaming ( rawMagma to +-rawMagma ; magma to +-magma ; semigroup to +-semigroup ; rawMonoid to +-rawMonoid ; monoid to +-monoid ) *-monoid : Monoid _ _ *-monoid = record { isMonoid = *-isMonoid } open Monoid *-monoid public using () renaming ( rawMagma to *-rawMagma ; magma to *-magma ; semigroup to *-semigroup ; rawMonoid to *-rawMonoid ) record Semiring c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _*_ infixl 6 _+_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _+_ : Op₂ Carrier _*_ : Op₂ Carrier 0# : Carrier 1# : Carrier isSemiring : IsSemiring _≈_ _+_ _*_ 0# 1# open IsSemiring isSemiring public rawSemiring : RawSemiring _ _ rawSemiring = record { _≈_ = _≈_ ; _+_ = _+_ ; _*_ = _*_ ; 0# = 0# ; 1# = 1# } semiringWithoutAnnihilatingZero : SemiringWithoutAnnihilatingZero _ _ semiringWithoutAnnihilatingZero = record { isSemiringWithoutAnnihilatingZero = isSemiringWithoutAnnihilatingZero } open SemiringWithoutAnnihilatingZero semiringWithoutAnnihilatingZero public using ( +-rawMagma; +-magma; +-semigroup ; *-rawMagma; *-magma; *-semigroup ; +-rawMonoid; +-monoid; +-commutativeMonoid ; *-rawMonoid; *-monoid ) semiringWithoutOne : SemiringWithoutOne _ _ semiringWithoutOne = record { isSemiringWithoutOne = isSemiringWithoutOne } open SemiringWithoutOne semiringWithoutOne public using (nearSemiring) record CommutativeSemiring c ℓ : Set (suc (c ⊔ ℓ)) where infixl 7 _*_ infixl 6 _+_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _+_ : Op₂ Carrier _*_ : Op₂ Carrier 0# : Carrier 1# : Carrier isCommutativeSemiring : IsCommutativeSemiring _≈_ _+_ _*_ 0# 1# open IsCommutativeSemiring isCommutativeSemiring public semiring : Semiring _ _ semiring = record { isSemiring = isSemiring } open Semiring semiring public using ( +-rawMagma; +-magma; +-semigroup ; *-rawMagma; *-magma; *-semigroup ; +-rawMonoid; +-monoid; +-commutativeMonoid ; *-rawMonoid; *-monoid ; nearSemiring; semiringWithoutOne ; semiringWithoutAnnihilatingZero ; rawSemiring ) *-commutativeSemigroup : CommutativeSemigroup _ _ *-commutativeSemigroup = record { isCommutativeSemigroup = *-isCommutativeSemigroup } *-commutativeMonoid : CommutativeMonoid _ _ *-commutativeMonoid = record { isCommutativeMonoid = *-isCommutativeMonoid } commutativeSemiringWithoutOne : CommutativeSemiringWithoutOne _ _ commutativeSemiringWithoutOne = record { isCommutativeSemiringWithoutOne = isCommutativeSemiringWithoutOne } ------------------------------------------------------------------------ -- Bundles with 2 binary operations, 1 unary operation & 2 elements ------------------------------------------------------------------------ -- A raw ring is a ring without any laws. record RawRing c ℓ : Set (suc (c ⊔ ℓ)) where infix 8 -_ infixl 7 _*_ infixl 6 _+_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _+_ : Op₂ Carrier _*_ : Op₂ Carrier -_ : Op₁ Carrier 0# : Carrier 1# : Carrier +-rawGroup : RawGroup c ℓ +-rawGroup = record { _≈_ = _≈_ ; _∙_ = _+_ ; ε = 0# ; _⁻¹ = -_ } *-rawMonoid : RawMonoid c ℓ *-rawMonoid = record { _≈_ = _≈_ ; _∙_ = _*_ ; ε = 1# } record Ring c ℓ : Set (suc (c ⊔ ℓ)) where infix 8 -_ infixl 7 _*_ infixl 6 _+_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _+_ : Op₂ Carrier _*_ : Op₂ Carrier -_ : Op₁ Carrier 0# : Carrier 1# : Carrier isRing : IsRing _≈_ _+_ _*_ -_ 0# 1# open IsRing isRing public +-abelianGroup : AbelianGroup _ _ +-abelianGroup = record { isAbelianGroup = +-isAbelianGroup } semiring : Semiring _ _ semiring = record { isSemiring = isSemiring } open Semiring semiring public using ( +-rawMagma; +-magma; +-semigroup ; *-rawMagma; *-magma; *-semigroup ; +-rawMonoid; +-monoid ; +-commutativeMonoid ; *-rawMonoid; *-monoid ; nearSemiring; semiringWithoutOne ; semiringWithoutAnnihilatingZero ) open AbelianGroup +-abelianGroup public using () renaming (group to +-group) rawRing : RawRing _ _ rawRing = record { _≈_ = _≈_ ; _+_ = _+_ ; _*_ = _*_ ; -_ = -_ ; 0# = 0# ; 1# = 1# } record CommutativeRing c ℓ : Set (suc (c ⊔ ℓ)) where infix 8 -_ infixl 7 _*_ infixl 6 _+_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _+_ : Op₂ Carrier _*_ : Op₂ Carrier -_ : Op₁ Carrier 0# : Carrier 1# : Carrier isCommutativeRing : IsCommutativeRing _≈_ _+_ _*_ -_ 0# 1# open IsCommutativeRing isCommutativeRing public ring : Ring _ _ ring = record { isRing = isRing } commutativeSemiring : CommutativeSemiring _ _ commutativeSemiring = record { isCommutativeSemiring = isCommutativeSemiring } open Ring ring public using (rawRing; +-group; +-abelianGroup) open CommutativeSemiring commutativeSemiring public using ( +-rawMagma; +-magma; +-semigroup ; *-rawMagma; *-magma; *-semigroup ; +-rawMonoid; +-monoid; +-commutativeMonoid ; *-rawMonoid; *-monoid; *-commutativeMonoid ; nearSemiring; semiringWithoutOne ; semiringWithoutAnnihilatingZero; semiring ; commutativeSemiringWithoutOne ) record BooleanAlgebra c ℓ : Set (suc (c ⊔ ℓ)) where infix 8 ¬_ infixr 7 _∧_ infixr 6 _∨_ infix 4 _≈_ field Carrier : Set c _≈_ : Rel Carrier ℓ _∨_ : Op₂ Carrier _∧_ : Op₂ Carrier ¬_ : Op₁ Carrier ⊤ : Carrier ⊥ : Carrier isBooleanAlgebra : IsBooleanAlgebra _≈_ _∨_ _∧_ ¬_ ⊤ ⊥ open IsBooleanAlgebra isBooleanAlgebra public distributiveLattice : DistributiveLattice _ _ distributiveLattice = record { isDistributiveLattice = isDistributiveLattice } open DistributiveLattice distributiveLattice public using (setoid; lattice) ------------------------------------------------------------------------ -- DEPRECATED NAMES ------------------------------------------------------------------------ -- Please use the new names as continuing support for the old names is -- not guaranteed. -- Version 1.0 RawSemigroup = RawMagma {-# WARNING_ON_USAGE RawSemigroup "Warning: RawSemigroup was deprecated in v1.0. Please use RawMagma instead." #-}
26.142473
83
0.56874
30f65f55003b8f656df0c4591c86619f191491a8
8,821
agda
Agda
Quicksort.agda
NAMEhzj/Divide-and-Conquer-in-Agda
99bd3a5e772563153d78f61c1bbca48d7809ff48
[ "MIT" ]
null
null
null
Quicksort.agda
NAMEhzj/Divide-and-Conquer-in-Agda
99bd3a5e772563153d78f61c1bbca48d7809ff48
[ "MIT" ]
null
null
null
Quicksort.agda
NAMEhzj/Divide-and-Conquer-in-Agda
99bd3a5e772563153d78f61c1bbca48d7809ff48
[ "MIT" ]
null
null
null
{-# OPTIONS --no-universe-polymorphism #-} open import Data.Product hiding (map) open import Relation.Binary.Core hiding (Total) open import Relation.Nullary open import Data.Nat import Level as L using (zero) open import Data.List open import Data.Unit using (⊤) open import Data.Empty open import DivideEtImpera open import Equivalence open import BagEquality open import Lists module Quicksort where splitWith : {A : Set} {P Q : A → Set} → (∀ x → P x ⊕ Q x) → List A → List A × List A splitWith _ [] = ([] , []) splitWith decPQ (x ∷ xs) with (decPQ x) splitWith decPQ (x ∷ xs) | (inj₁ _) = (x ∷ (proj₁ res), proj₂ res) where res = splitWith decPQ xs splitWith decPQ (x ∷ xs) | (inj₂ _) = (proj₁ res , x ∷ (proj₂ res)) where res = splitWith decPQ xs splitWithProp1 : {A : Set} {P Q : A → Set} → (decPQ : ∀ x → P x ⊕ Q x) → (xs : List A) → (z : A) → z ∈ proj₁ (splitWith decPQ xs) → P z splitWithProp1 decPQ [] z zIn1 = ⊥-elim zIn1 splitWithProp1 decPQ (x ∷ xs) z zIn with (decPQ x) splitWithProp1 decPQ (x ∷ xs) .x (inj₁ refl) | (inj₁ pfP) = pfP splitWithProp1 decPQ (x ∷ xs) z (inj₂ zIn) | (inj₁ _ ) = splitWithProp1 decPQ xs z zIn splitWithProp1 decPQ (x ∷ xs) z zIn | (inj₂ _ ) = splitWithProp1 decPQ xs z zIn splitWithProp2 : {A : Set} {P Q : A → Set} → (decPQ : ∀ x → P x ⊕ Q x) → (xs : List A) → (z : A) → z ∈ proj₂ (splitWith decPQ xs) → Q z splitWithProp2 decPQ [] z zIn1 = ⊥-elim zIn1 splitWithProp2 decPQ (x ∷ xs) z zIn with (decPQ x) splitWithProp2 decPQ (x ∷ xs) .x (inj₁ refl) | (inj₂ pfQ) = pfQ splitWithProp2 decPQ (x ∷ xs) z (inj₂ zIn) | (inj₂ _ ) = splitWithProp2 decPQ xs z zIn splitWithProp2 decPQ (x ∷ xs) z zIn | (inj₁ _ ) = splitWithProp2 decPQ xs z zIn ×-join : {A B C : Set} → (pair : A × B) → (op : A → B → C) → C ×-join (a , b) op = op a b splitWith-cong : {A : Set} {P Q : A → Set} → (decPQ : ∀ x → P x ⊕ Q x) → (xs : List A) → (proj₁ (splitWith decPQ xs)) ++ (proj₂ (splitWith decPQ xs)) ≈ xs splitWith-cong _ [] z = ⊥ □↔ splitWith-cong decPQ (x ∷ xs) z with (decPQ x) splitWith-cong decPQ (x ∷ xs) z | (inj₁ _) = let (res1 , res2) = splitWith decPQ xs in (z ≡ x) ⊕ Any (z ≡_) (res1 ++ res2) ↔⟨ ⊕-cong ((z ≡ x) □↔) (splitWith-cong decPQ xs z) ⟩ (z ≡ x) ⊕ Any (z ≡_) xs □↔ splitWith-cong decPQ (x ∷ xs) z | (inj₂ _) = let (res1 , res2) = splitWith decPQ xs in Any (z ≡_) (res1 ++ x ∷ res2) ↔⟨ ++-comm res1 (x ∷ res2) z ⟩ (z ≡ x) ⊕ Any (z ≡_) (res2 ++ res1) ↔⟨ ⊕-cong ((z ≡ x) □↔) (++-comm res2 res1 z) ⟩ (z ≡ x) ⊕ Any (z ≡_) (res1 ++ res2) ↔⟨ ⊕-cong ((z ≡ x) □↔) (splitWith-cong decPQ xs z) ⟩ (z ≡ x) ⊕ Any (z ≡_) xs □↔ ≤′-suc : {n m : ℕ} → n ≤′ m → suc n ≤′ suc m ≤′-suc ≤′-refl = ≤′-refl ≤′-suc (≤′-step pf) = ≤′-step (≤′-suc pf) splitWith-length1 : {A : Set} {P Q : A → Set} → (decPQ : ∀ x → P x ⊕ Q x) → (xs : List A) → length (proj₁ (splitWith decPQ xs)) ≤′ length xs splitWith-length1 _ [] = ≤′-refl splitWith-length1 decPQ (x ∷ xs) with (decPQ x) splitWith-length1 decPQ (x ∷ xs) | (inj₁ _) = ≤′-suc (splitWith-length1 decPQ xs) splitWith-length1 decPQ (x ∷ xs) | (inj₂ _) = ≤′-step (splitWith-length1 decPQ xs) splitWith-length2 : {A : Set} {P Q : A → Set} → (decPQ : ∀ x → P x ⊕ Q x) → (xs : List A) → length (proj₂ (splitWith decPQ xs)) ≤′ length xs splitWith-length2 _ [] = ≤′-refl splitWith-length2 decPQ (x ∷ xs) with (decPQ x) splitWith-length2 decPQ (x ∷ xs) | (inj₁ _) = ≤′-step (splitWith-length2 decPQ xs) splitWith-length2 decPQ (x ∷ xs) | (inj₂ _) = ≤′-suc (splitWith-length2 decPQ xs) qs-DecompCond : {A : Set} → Rel A L.zero → List A → (A × List A × List A) → Set qs-DecompCond LEQ xs (piv , ys , zs) = (piv ∷ (ys ++ zs) ≈ xs) × (∀ y → y ∈ ys → LEQ y piv) × (∀ z → z ∈ zs → LEQ piv z) qs-InputCond : {A : Set} → List A → Set qs-InputCond x = ⊤ qs-OutputCond : {A : Set} → Rel A L.zero → List A → List A → Set qs-OutputCond LEQ xs ys = ys ≈ xs × Ordered LEQ ys qs-G-InputCond : {A : Set} → A → Set qs-G-InputCond x = ⊤ qs-G-OutputCond : {A : Set} → A → A → Set qs-G-OutputCond x y = x ≡ y qs-CompCond : {A : Set} → (A × List A × List A) → List A → Set qs-CompCond (piv , xs , ys) zs = xs ++ piv ∷ ys ≡ zs qs-InductionLemma : {A : Set} → (LEQ : Rel A L.zero) → ∀{x₀ x₁ x₂ x₃ z₀ z₁ z₂ z₃} → qs-DecompCond LEQ x₀ (x₁ , x₂ , x₃ ) → qs-G-OutputCond x₁ z₁ → qs-OutputCond LEQ x₂ z₂ → qs-OutputCond LEQ x₃ z₃ → qs-CompCond (z₁ , z₂ , z₃) z₀ → qs-OutputCond LEQ x₀ z₀ qs-InductionLemma LEQ {xs} {piv} {ys₁} {ys₂} {ws} {.piv} {zs₁} {zs₂} (piv∷ys₁++ys₂≈xs , ltPiv , gtPiv) refl (zs₁≈ys₁ , ord₁) (zs₂≈ys₂ , ord₂) refl = (λ x → x ∈ (zs₁ ++ piv ∷ zs₂) ↔⟨ ++-comm zs₁ (piv ∷ zs₂) x ⟩ (x ∈ ((piv ∷ zs₂) ++ zs₁)) ↔⟨ Any-++ (λ z → x ≡ z) (piv ∷ zs₂) zs₁ ⟩ ((x ≡ piv) ⊕ x ∈ zs₂) ⊕ x ∈ zs₁ ↔⟨ ↔sym ⊕-assoc ⟩ (x ≡ piv) ⊕ (x ∈ zs₂ ⊕ x ∈ zs₁) ↔⟨ ⊕-cong ((x ≡ piv) □↔) (⊕-cong (zs₂≈ys₂ x) (zs₁≈ys₁ x)) ⟩ (x ≡ piv) ⊕ (x ∈ ys₂ ⊕ x ∈ ys₁) ↔⟨ ⊕-cong ((x ≡ piv) □↔) ⊕-comm ⟩ (x ≡ piv) ⊕ (x ∈ ys₁ ⊕ x ∈ ys₂) ↔⟨ ⊕-cong ((x ≡ piv) □↔) (↔sym (Any-++ (λ z → x ≡ z) ys₁ ys₂)) ⟩ x ∈ (piv ∷ (ys₁ ++ ys₂)) ↔⟨ piv∷ys₁++ys₂≈xs x ⟩ x ∈ xs □↔) , ++-Order-cong (λ x x∈zs₁ → ltPiv x (_↔_.to (zs₁≈ys₁ x) x∈zs₁)) ord₁ (cons-Order-cong (λ x x∈zs₂ → gtPiv x (_↔_.to (zs₂≈ys₂ x) x∈zs₂)) ord₂) qs-Decomp : {A : Set} → {LEQ : Rel A L.zero} → Total LEQ → (xs : List A) → ⊤ → ¬ ListPrimitive xs → Σ (A × List A × List A) λ y → qs-G-InputCond (proj₁ y) × (qs-InputCond (proj₁ (proj₂ y))) × (qs-InputCond (proj₂ (proj₂ y))) × ((proj₁ (proj₂ y)) <l xs) × ((proj₂ (proj₂ y)) <l xs) × (qs-DecompCond LEQ xs y) qs-Decomp total [] _ notPrim = ⊥-elim (notPrim (NilIsPrim)) qs-Decomp total (x ∷ xs) _ _ = ( x , splitWith (λ y → total y x) xs) , (⊤.tt , ⊤.tt , ⊤.tt , ≤′-suc (splitWith-length1 (λ y → total y x) xs) , ≤′-suc (splitWith-length2 (λ y → total y x) xs) , ((λ z → (z ≡ x) ⊕ z ∈ (proj₁ (splitWith (λ y → total y x) xs) ++ proj₂ (splitWith (λ y → total y x) xs)) ↔⟨ ⊕-cong ((z ≡ x) □↔) (splitWith-cong (λ y → total y x) xs z) ⟩ (z ≡ x) ⊕ z ∈ xs □↔) , splitWithProp1 (λ y → total y x) xs , splitWithProp2 (λ y → total y x) xs)) qs-G : {A : Set} → (x : A) → ⊤ → Σ A (qs-G-OutputCond x) qs-G x _ = (x , refl) qs-Comp : {A : Set} → (y : A × (List A × List A)) → Σ (List A) (qs-CompCond y) qs-Comp (piv , xs , ys) = (xs ++ piv ∷ ys , refl) qs-DirSolve : {A : Set} → (LEQ : Rel A L.zero) → (xs : List A) → ⊤ → ListPrimitive xs → Σ (List A) (qs-OutputCond LEQ xs) qs-DirSolve _ [] _ _ = ([] , (λ z → z ∈ [] □↔) , NilIsOrd) qs-DirSolve _ (_ ∷ _) _ prim = ⊥-elim (consIsNotPrim prim) quicksort : {A : Set} → {LEQ : Rel A L.zero} → Total LEQ → (xs : List A) → Σ (List A) (λ ys → ys ≈ xs × Ordered LEQ ys) quicksort {LEQ = LEQ} total xs = makeD&C2 <l-wellFounded primDec (qs-Decomp total) qs-Comp qs-G (qs-DirSolve LEQ) (qs-InductionLemma LEQ) xs ⊤.tt _≤_-total : Total _≤_ _≤_-total zero n = inj₁ z≤n _≤_-total n zero = inj₂ z≤n _≤_-total (suc n) (suc m) with (_≤_-total n m) _≤_-total (suc n) (suc m) | (inj₁ n≤m) = inj₁ (s≤s n≤m) _≤_-total (suc n) (suc m) | (inj₂ m≤n) = inj₂ (s≤s m≤n) nat-quicksort = quicksort _≤_-total
54.78882
193
0.451876
196c50a0c92252037d743d7b8c031a7399ad4499
366
agda
Agda
test/Succeed/Issue3108.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue3108.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue3108.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Agda.Builtin.Nat variable {n} : Nat data Vec (A : Set) : Nat → Set where [] : Vec A 0 _∷_ : A → Vec A n → Vec A (suc n) cons : ∀ {m A} → A → Vec A m → Vec A (suc m) cons = _∷_ module _ (A : Set) where data Vec' : Nat → Set where [] : Vec' 0 _∷_ : A → Vec' n → Vec' (suc n) cons' : ∀ {m A} → A → Vec' A m → Vec' A (suc m) cons' = _∷_
19.263158
47
0.5
4388d929f5c58409e0a730d0b9e663378bd763ce
2,798
agda
Agda
Cubical/Algebra/Semigroup/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Algebra/Semigroup/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Algebra/Semigroup/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --safe #-} module Cubical.Algebra.Semigroup.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Equiv.HalfAdjoint open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Transport open import Cubical.Foundations.SIP open import Cubical.Data.Sigma open import Cubical.Reflection.RecordEquiv open import Cubical.Reflection.StrictEquiv open import Cubical.Displayed.Base open import Cubical.Displayed.Auto open import Cubical.Displayed.Record open import Cubical.Displayed.Universe open Iso private variable ℓ : Level -- Semigroups as a record, inspired by the Agda standard library: -- -- https://github.com/agda/agda-stdlib/blob/master/src/Algebra/Bundles.agda#L48 -- https://github.com/agda/agda-stdlib/blob/master/src/Algebra/Structures.agda#L50 -- -- Note that as we are using Path for all equations the IsMagma record -- would only contain isSet A if we had it. record IsSemigroup {A : Type ℓ} (_·_ : A → A → A) : Type ℓ where no-eta-equality constructor issemigroup field is-set : isSet A assoc : (x y z : A) → x · (y · z) ≡ (x · y) · z unquoteDecl IsSemigroupIsoΣ = declareRecordIsoΣ IsSemigroupIsoΣ (quote IsSemigroup) record SemigroupStr (A : Type ℓ) : Type ℓ where constructor semigroupstr field _·_ : A → A → A isSemigroup : IsSemigroup _·_ infixl 7 _·_ open IsSemigroup isSemigroup public Semigroup : ∀ ℓ → Type (ℓ-suc ℓ) Semigroup ℓ = TypeWithStr ℓ SemigroupStr semigroup : (A : Type ℓ) (_·_ : A → A → A) (h : IsSemigroup _·_) → Semigroup ℓ semigroup A _·_ h = A , semigroupstr _·_ h record IsSemigroupEquiv {A : Type ℓ} {B : Type ℓ} (M : SemigroupStr A) (e : A ≃ B) (N : SemigroupStr B) : Type ℓ where -- Shorter qualified names private module M = SemigroupStr M module N = SemigroupStr N field isHom : (x y : A) → equivFun e (x M.· y) ≡ equivFun e x N.· equivFun e y open SemigroupStr open IsSemigroup open IsSemigroupEquiv SemigroupEquiv : (M N : Semigroup ℓ) → Type ℓ SemigroupEquiv M N = Σ[ e ∈ ⟨ M ⟩ ≃ ⟨ N ⟩ ] IsSemigroupEquiv (M .snd) e (N .snd) isPropIsSemigroup : {A : Type ℓ} (_·_ : A → A → A) → isProp (IsSemigroup _·_) isPropIsSemigroup _·_ = isOfHLevelRetractFromIso 1 IsSemigroupIsoΣ (isPropΣ isPropIsSet (λ isSetA → isPropΠ3 λ _ _ _ → isSetA _ _)) 𝒮ᴰ-Semigroup : DUARel (𝒮-Univ ℓ) SemigroupStr ℓ 𝒮ᴰ-Semigroup = 𝒮ᴰ-Record (𝒮-Univ _) IsSemigroupEquiv (fields: data[ _·_ ∣ autoDUARel _ _ ∣ isHom ] prop[ isSemigroup ∣ (λ _ _ → isPropIsSemigroup _) ]) SemigroupPath : (M N : Semigroup ℓ) → SemigroupEquiv M N ≃ (M ≡ N) SemigroupPath = ∫ 𝒮ᴰ-Semigroup .UARel.ua
27.70297
83
0.707648
a07b2d8116ba62a54896135bdd218b3205306331
9,603
agda
Agda
Cubical/Codata/M/AsLimit/M/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
301
2018-10-17T18:00:24.000Z
2022-03-24T02:10:47.000Z
Cubical/Codata/M/AsLimit/M/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
584
2018-10-15T09:49:02.000Z
2022-03-30T12:09:17.000Z
Cubical/Codata/M/AsLimit/M/Base.agda
FernandoLarrain/cubical
9acdecfa6437ec455568be4e5ff04849cc2bc13b
[ "MIT" ]
134
2018-11-16T06:11:03.000Z
2022-03-23T16:22:13.000Z
{-# OPTIONS --guardedness --safe #-} -- Construction of M-types from -- https://arxiv.org/pdf/1504.02949.pdf -- "Non-wellfounded trees in Homotopy Type Theory" -- Benedikt Ahrens, Paolo Capriotti, Régis Spadotti module Cubical.Codata.M.AsLimit.M.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv using (_≃_) open import Cubical.Foundations.Function using (_∘_) open import Cubical.Data.Unit open import Cubical.Data.Prod open import Cubical.Data.Nat as ℕ using (ℕ ; suc ; _+_ ) open import Cubical.Data.Sigma hiding (_×_) open import Cubical.Data.Nat.Algebra open import Cubical.Foundations.Transport open import Cubical.Foundations.Univalence open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Function open import Cubical.Foundations.Path open import Cubical.Foundations.HLevels open import Cubical.Foundations.GroupoidLaws open import Cubical.Data.Sum open import Cubical.Codata.M.AsLimit.helper open import Cubical.Codata.M.AsLimit.Container open import Cubical.Codata.M.AsLimit.Coalg.Base open Iso private limit-collapse : ∀ {ℓ} {S : Container ℓ} (X : ℕ → Type ℓ) (l : (n : ℕ) → X n → X (suc n)) → (x₀ : X 0) → ∀ (n : ℕ) → X n limit-collapse X l x₀ 0 = x₀ limit-collapse {S = S} X l x₀ (suc n) = l n (limit-collapse {S = S} X l x₀ n) lemma11-Iso : ∀ {ℓ} {S : Container ℓ} (X : ℕ → Type ℓ) (l : (n : ℕ) → X n → X (suc n)) → Iso (Σ[ x ∈ ((n : ℕ) → X n)] ((n : ℕ) → x (suc n) ≡ l n (x n))) (X 0) fun (lemma11-Iso X l) (x , y) = x 0 inv (lemma11-Iso {S = S} X l) x₀ = limit-collapse {S = S} X l x₀ , (λ n → refl {x = limit-collapse {S = S} X l x₀ (suc n)}) rightInv (lemma11-Iso X l) _ = refl leftInv (lemma11-Iso {ℓ = ℓ} {S = S} X l) (x , y) i = let temp = χ-prop (x 0) (fst (inv (lemma11-Iso {S = S} X l) (fun (lemma11-Iso {S = S} X l) (x , y))) , refl , (λ n → refl {x = limit-collapse {S = S} X l (x 0) (suc n)})) (x , refl , y) in temp i .fst , proj₂ (temp i .snd) where open AlgebraPropositionality open NatSection X-fiber-over-ℕ : (x₀ : X 0) -> NatFiber NatAlgebraℕ ℓ X-fiber-over-ℕ x₀ = record { Fiber = X ; fib-zero = x₀ ; fib-suc = λ {n : ℕ} xₙ → l n xₙ } X-section : (x₀ : X 0) → (z : Σ[ x ∈ ((n : ℕ) → X n)] (x 0 ≡ x₀) × (∀ n → (x (suc n)) ≡ l n (x n))) -> NatSection (X-fiber-over-ℕ x₀) X-section = λ x₀ z → record { section = fst z ; sec-comm-zero = proj₁ (snd z) ; sec-comm-suc = proj₂ (snd z) } Z-is-Section : (x₀ : X 0) → Iso (Σ[ x ∈ ((n : ℕ) → X n)] (x 0 ≡ x₀) × (∀ n → (x (suc n)) ≡ l n (x n))) (NatSection (X-fiber-over-ℕ x₀)) fun (Z-is-Section x₀) (x , (z , y)) = record { section = x ; sec-comm-zero = z ; sec-comm-suc = y } inv (Z-is-Section x₀) x = NatSection.section x , (sec-comm-zero x , sec-comm-suc x) rightInv (Z-is-Section x₀) _ = refl leftInv (Z-is-Section x₀) (x , (z , y)) = refl -- S≡T χ-prop' : (x₀ : X 0) → isProp (NatSection (X-fiber-over-ℕ x₀)) χ-prop' x₀ a b = SectionProp.S≡T isNatInductiveℕ (X-section x₀ (inv (Z-is-Section x₀) a)) (X-section x₀ (inv (Z-is-Section x₀) b)) χ-prop : (x₀ : X 0) → isProp (Σ[ x ∈ ((n : ℕ) → X n) ] (x 0 ≡ x₀) × (∀ n → (x (suc n)) ≡ l n (x n))) χ-prop x₀ = subst isProp (sym (isoToPath (Z-is-Section x₀))) (χ-prop' x₀) ----------------------------------------------------- -- Shifting the limit of a chain is an equivalence -- ----------------------------------------------------- -- Shift is equivalence (12) and (13) in the proof of Theorem 7 -- https://arxiv.org/pdf/1504.02949.pdf -- "Non-wellfounded trees in Homotopy Type Theory" -- Benedikt Ahrens, Paolo Capriotti, Régis Spadotti -- TODO: This definition is inefficient, it should be updated to use some cubical features! shift-iso : ∀ {ℓ} (S : Container ℓ) -> Iso (P₀ S (M S)) (M S) shift-iso S@(A , B) = P₀ S (M S) Iso⟨ Σ-cong-iso-snd (λ x → iso (λ f → (λ n z → f z .fst n) , λ n i a → f a .snd n i) (λ (u , q) z → (λ n → u n z) , λ n i → q n i z) (λ _ → refl) (λ _ → refl)) ⟩ (Σ[ a ∈ A ] (Σ[ u ∈ ((n : ℕ) → B a → X (sequence S) n) ] ((n : ℕ) → π (sequence S) ∘ (u (suc n)) ≡ u n))) Iso⟨ invIso α-iso-step-5-Iso ⟩ (Σ[ a ∈ (Σ[ a ∈ ((n : ℕ) → A) ] ((n : ℕ) → a (suc n) ≡ a n)) ] Σ[ u ∈ ((n : ℕ) → B (a .fst n) → X (sequence S) n) ] ((n : ℕ) → PathP (λ x → B (a .snd n x) → X (sequence S) n) (π (sequence S) ∘ u (suc n)) (u n))) Iso⟨ α-iso-step-1-4-Iso-lem-12 ⟩ M S ∎Iso where α-iso-step-5-Iso-helper0 : ∀ (a : (ℕ -> A)) → (p : (n : ℕ) → a (suc n) ≡ a n) → (n : ℕ) → a n ≡ a 0 α-iso-step-5-Iso-helper0 a p 0 = refl α-iso-step-5-Iso-helper0 a p (suc n) = p n ∙ α-iso-step-5-Iso-helper0 a p n α-iso-step-5-Iso-helper1-Iso : ∀ (a : ℕ -> A) → (p : (n : ℕ) → a (suc n) ≡ a n) → (u : (n : ℕ) → B (a n) → Wₙ S n) → (n : ℕ) → (PathP (λ x → B (p n x) → Wₙ S n) (πₙ S ∘ u (suc n)) (u n)) ≡ (πₙ S ∘ (subst (\k -> B k → Wₙ S (suc n)) (α-iso-step-5-Iso-helper0 a p (suc n))) (u (suc n)) ≡ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p n) (u n)) α-iso-step-5-Iso-helper1-Iso a p u n = PathP (λ x → B (p n x) → Wₙ S n) (πₙ S ∘ u (suc n)) (u n) ≡⟨ PathP≡Path (λ x → B (p n x) → Wₙ S n) (πₙ S ∘ u (suc n)) (u n) ⟩ subst (λ k → B k → Wₙ S n) (p n) (πₙ S ∘ u (suc n)) ≡ (u n) ≡⟨ (λ i → transp (λ j → B (α-iso-step-5-Iso-helper0 a p n (i ∧ j)) → Wₙ S n) (~ i) (subst (λ k → B k → Wₙ S n) (p n) (πₙ S ∘ u (suc n))) ≡ transp (λ j → B (α-iso-step-5-Iso-helper0 a p n (i ∧ j)) → Wₙ S n) (~ i) (u n)) ⟩ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p n) (subst (λ k → B k → Wₙ S n) (p n) (πₙ S ∘ u (suc n))) ≡ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p n) (u n) ≡⟨ (λ i → sym (substComposite (λ k → B k → Wₙ S n) (p n) (α-iso-step-5-Iso-helper0 a p n) (πₙ S ∘ u (suc n))) i ≡ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p n) (u n)) ⟩ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p (suc n)) (πₙ S ∘ u (suc n)) ≡ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p n) (u n) ≡⟨ (λ i → substCommSlice (λ k → B k → Wₙ S (suc n)) (λ k → B k → Wₙ S n) (λ a x x₁ → (πₙ S) (x x₁)) (α-iso-step-5-Iso-helper0 a p (suc n)) (u (suc n)) i ≡ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p n) (u n)) ⟩ πₙ S ∘ subst (λ k → B k → Wₙ S (suc n)) (α-iso-step-5-Iso-helper0 a p (suc n)) (u (suc n)) ≡ subst (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 a p n) (u n) ∎ α-iso-step-5-Iso : Iso (Σ[ a ∈ (Σ[ a ∈ ((n : ℕ) → A) ] ((n : ℕ) → a (suc n) ≡ a n)) ] Σ[ u ∈ ((n : ℕ) → B (a .fst n) → X (sequence S) n) ] ((n : ℕ) → PathP (λ x → B (a .snd n x) → X (sequence S) n) (π (sequence S) ∘ u (suc n)) (u n))) (Σ[ a ∈ A ] (Σ[ u ∈ ((n : ℕ) → B a → X (sequence S) n) ] ((n : ℕ) → π (sequence S) ∘ (u (suc n)) ≡ u n))) α-iso-step-5-Iso = Σ-cong-iso (lemma11-Iso {S = S} (λ _ → A) (λ _ x → x)) (λ a,p → Σ-cong-iso (pathToIso (cong (λ k → (n : ℕ) → k n) (funExt λ n → cong (λ k → B k → Wₙ S n) (α-iso-step-5-Iso-helper0 (a,p .fst) (a,p .snd) n)))) λ u → pathToIso (cong (λ k → (n : ℕ) → k n) (funExt λ n → α-iso-step-5-Iso-helper1-Iso (a,p .fst) (a,p .snd) u n))) α-iso-step-1-4-Iso-lem-12 : Iso (Σ[ a ∈ (Σ[ a ∈ ((n : ℕ) → A)] ((n : ℕ) → a (suc n) ≡ a n)) ] (Σ[ u ∈ ((n : ℕ) → B (a .fst n) → X (sequence S) n) ] ((n : ℕ) → PathP (λ x → B (a .snd n x) → X (sequence S) n) (π (sequence S) ∘ u (suc n)) (u n)))) (limit-of-chain (sequence S)) fun α-iso-step-1-4-Iso-lem-12 (a , b) = (λ { 0 → lift tt ; (suc n) → (a .fst n) , (b .fst n)}) , λ { 0 → refl {x = lift tt} ; (suc m) i → a .snd m i , b .snd m i } inv α-iso-step-1-4-Iso-lem-12 x = ((λ n → (x .fst) (suc n) .fst) , λ n i → (x .snd) (suc n) i .fst) , (λ n → (x .fst) (suc n) .snd) , λ n i → (x .snd) (suc n) i .snd fst (rightInv α-iso-step-1-4-Iso-lem-12 (b , c) i) 0 = lift tt fst (rightInv α-iso-step-1-4-Iso-lem-12 (b , c) i) (suc n) = refl i snd (rightInv α-iso-step-1-4-Iso-lem-12 (b , c) i) 0 = refl snd (rightInv α-iso-step-1-4-Iso-lem-12 (b , c) i) (suc n) = c (suc n) leftInv α-iso-step-1-4-Iso-lem-12 (a , b) = refl shift : ∀ {ℓ} (S : Container ℓ) -> P₀ S (M S) ≡ M S shift S = isoToPath (shift-iso S) -- lemma 13 & lemma 12 -- Transporting along shift in-fun : ∀ {ℓ} {S : Container ℓ} -> P₀ S (M S) -> M S in-fun {S = S} = fun (shift-iso S) out-fun : ∀ {ℓ} {S : Container ℓ} -> M S -> P₀ S (M S) out-fun {S = S} = inv (shift-iso S) -- Property of functions into M-types lift-to-M : ∀ {ℓ} {A : Type ℓ} {S : Container ℓ} → (x : (n : ℕ) -> A → X (sequence S) n) → ((n : ℕ) → (a : A) → π (sequence S) (x (suc n) a) ≡ x n a) --------------- → (A → M S) lift-to-M x p a = (λ n → x n a) , λ n i → p n a i lift-direct-M : ∀ {ℓ} {S : Container ℓ} → (x : (n : ℕ) → X (sequence S) n) → ((n : ℕ) → π (sequence S) (x (suc n)) ≡ x n) --------------- → M S lift-direct-M x p = x , p
49.246154
187
0.483391
34b56baaef5ce138bd972500b039348ed916f7a1
14,642
agda
Agda
theorems/groups/ReducedWord.agda
timjb/HoTT-Agda
66f800adef943afdf08c17b8ecfba67340fead5e
[ "MIT" ]
null
null
null
theorems/groups/ReducedWord.agda
timjb/HoTT-Agda
66f800adef943afdf08c17b8ecfba67340fead5e
[ "MIT" ]
null
null
null
theorems/groups/ReducedWord.agda
timjb/HoTT-Agda
66f800adef943afdf08c17b8ecfba67340fead5e
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K --rewriting #-} open import HoTT module groups.ReducedWord {i} {A : Type i} (dec : has-dec-eq A) where is-reduced : Word A → Type i is-reduced nil = Lift ⊤ is-reduced (_ :: nil) = Lift ⊤ is-reduced (inl x :: inl y :: w) = is-reduced (inl y :: w) is-reduced (inl x :: inr y :: w) = (x ≠ y) × is-reduced (inr y :: w) is-reduced (inr x :: inl y :: w) = (x ≠ y) × is-reduced (inl y :: w) is-reduced (inr x :: inr y :: w) = is-reduced (inr y :: w) -- Everything is a set. A-is-set : is-set A A-is-set = dec-eq-is-set dec PlusMinus-has-dec-eq : has-dec-eq (PlusMinus A) PlusMinus-has-dec-eq (inl x) (inl y) with dec x y PlusMinus-has-dec-eq (inl x) (inl y) | inl p = inl $ ap inl p PlusMinus-has-dec-eq (inl x) (inl y) | inr ¬p = inr $ ¬p ∘ lower ∘ Coprod=-in PlusMinus-has-dec-eq (inl x) (inr y) = inr $ lower ∘ Coprod=-in PlusMinus-has-dec-eq (inr x) (inl y) = inr $ lower ∘ Coprod=-in PlusMinus-has-dec-eq (inr x) (inr y) with dec x y PlusMinus-has-dec-eq (inr x) (inr y) | inl p = inl $ ap inr p PlusMinus-has-dec-eq (inr x) (inr y) | inr ¬p = inr $ ¬p ∘ lower ∘ Coprod=-in Word-has-dec-eq : has-dec-eq (Word A) Word-has-dec-eq nil nil = inl idp Word-has-dec-eq nil (_ :: w) = inr $ lower ∘ List=-in Word-has-dec-eq (_ :: v) nil = inr $ lower ∘ List=-in Word-has-dec-eq (x :: v) (y :: w) with PlusMinus-has-dec-eq x y Word-has-dec-eq (x :: v) (y :: w) | inl x=y with Word-has-dec-eq v w Word-has-dec-eq (x :: v) (y :: w) | inl x=y | inl v=w = inl $ List=-out (x=y , v=w) Word-has-dec-eq (x :: v) (y :: w) | inl x=y | inr v≠w = inr $ v≠w ∘ snd ∘ List=-in Word-has-dec-eq (x :: v) (y :: w) | inr x≠y = inr $ x≠y ∘ fst ∘ List=-in instance Word-is-set : is-set (Word A) Word-is-set = dec-eq-is-set Word-has-dec-eq is-reduced-is-prop : {w : Word A} → is-prop (is-reduced w) is-reduced-is-prop {nil} = ⟨⟩ is-reduced-is-prop {x :: nil} = ⟨⟩ is-reduced-is-prop {inl x :: inl y :: l} = is-reduced-is-prop {inl y :: l} is-reduced-is-prop {inl x :: inr y :: l} = ⟨⟩ where instance _ = is-reduced-is-prop {inr y :: l} is-reduced-is-prop {inr x :: inl y :: l} = ⟨⟩ where instance _ = is-reduced-is-prop {inl y :: l} is-reduced-is-prop {inr x :: inr y :: l} = is-reduced-is-prop {inr y :: l} is-reduced-prop : SubtypeProp (Word A) i is-reduced-prop = is-reduced , λ w → is-reduced-is-prop {w} -- The subtype ReducedWord : Type i ReducedWord = Subtype is-reduced-prop instance ReducedWord-is-set : is-set ReducedWord ReducedWord-is-set = Subtype-level is-reduced-prop where instance _ = is-reduced-is-prop -- Identifications in [ReducedWord]. ReducedWord= : ReducedWord → ReducedWord → Type i ReducedWord= = Subtype= is-reduced-prop ReducedWord=-out : {x y : ReducedWord} → ReducedWord= x y → x == y ReducedWord=-out = Subtype=-out is-reduced-prop -- The group structure of reduced words private rw-unit : ReducedWord rw-unit = nil , lift tt abstract tail-is-reduced : ∀ x w → is-reduced (x :: w) → is-reduced w tail-is-reduced x nil red = lift tt tail-is-reduced (inl x) (inl y :: w) red = red tail-is-reduced (inl x) (inr y :: w) red = snd red tail-is-reduced (inr x) (inl y :: w) red = snd red tail-is-reduced (inr x) (inr y :: w) red = red rw-cons : PlusMinus A → ReducedWord → ReducedWord rw-cons x (nil , _) = (x :: nil) , lift tt rw-cons (inl x) ((inl y :: l) , red) = (inl x :: inl y :: l) , red rw-cons (inl x) ((inr y :: l) , red) with dec x y rw-cons (inl x) ((inr y :: l) , red) | inl p = l , tail-is-reduced (inr y) l red rw-cons (inl x) ((inr y :: l) , red) | inr ¬p = (inl x :: inr y :: l) , (¬p , red) rw-cons (inr x) ((inl y :: l) , red) with dec x y rw-cons (inr x) ((inl y :: l) , red) | inl p = l , tail-is-reduced (inl y) l red rw-cons (inr x) ((inl y :: l) , red) | inr ¬p = (inr x :: inl y :: l) , (¬p , red) rw-cons (inr x) ((inr y :: l) , red) = (inr x :: inr y :: l) , red rw-++' : Word A → ReducedWord → ReducedWord rw-++' w₁ rw₂ = foldr rw-cons rw₂ w₁ reduce : Word A → ReducedWord reduce w = rw-++' w rw-unit rw-++ : ReducedWord → ReducedWord → ReducedWord rw-++ rw₁ rw₂ = rw-++' (fst rw₁) rw₂ abstract -- assoc rw-cons-reduced : ∀ x w → (red : is-reduced w) → (red' : is-reduced (x :: w)) → rw-cons x (w , red) == (x :: w) , red' rw-cons-reduced x nil _ _ = ReducedWord=-out idp rw-cons-reduced (inl x) (inl y :: w) _ red' = ReducedWord=-out idp rw-cons-reduced (inl x) (inr y :: w) _ red' with dec x y rw-cons-reduced (inl x) (inr y :: w) _ red' | inl p = ⊥-rec $ fst red' $ p rw-cons-reduced (inl x) (inr y :: w) _ red' | inr ¬p = ReducedWord=-out idp rw-cons-reduced (inr x) (inl y :: w) _ red' with dec x y rw-cons-reduced (inr x) (inl y :: w) _ red' | inl p = ⊥-rec $ fst red' $ p rw-cons-reduced (inr x) (inl y :: w) _ red' | inr ¬p = ReducedWord=-out idp rw-cons-reduced (inr x) (inr y :: w) _ red' = ReducedWord=-out idp rw-cons-flip : ∀ x w red red' → rw-cons x ((flip x :: w) , red) == w , red' rw-cons-flip (inl x) w _ _ with dec x x rw-cons-flip (inl x) w _ _ | inl x=x = ReducedWord=-out idp rw-cons-flip (inl x) w _ _ | inr x≠x = ⊥-rec (x≠x idp) rw-cons-flip (inr x) w _ _ with dec x x rw-cons-flip (inr x) w _ _ | inl x=x = ReducedWord=-out idp rw-cons-flip (inr x) w _ _ | inr x≠x = ⊥-rec (x≠x idp) rw-cons-cons-flip : ∀ x rw → rw-cons x (rw-cons (flip x) rw) == rw rw-cons-cons-flip x (nil , red) = rw-cons-flip x nil _ red rw-cons-cons-flip (inl x) ((inl y :: w) , red) with dec x y rw-cons-cons-flip (inl x) ((inl y :: w) , red) | inl x=y = rw-cons-reduced (inl x) w _ (transport! (λ z → is-reduced (inl z :: w)) x=y red) ∙ ReducedWord=-out (ap (λ z → inl z :: w) x=y) rw-cons-cons-flip (inl x) ((inl y :: w) , red) | inr x≠y = rw-cons-flip (inl x) (inl y :: w) (x≠y , red) red rw-cons-cons-flip (inl x) ((inr y :: w) , red) = rw-cons-flip (inl x) (inr y :: w) red red rw-cons-cons-flip (inr x) ((inl y :: w) , red) = rw-cons-flip (inr x) (inl y :: w) red red rw-cons-cons-flip (inr x) ((inr y :: w) , red) with dec x y rw-cons-cons-flip (inr x) ((inr y :: w) , red) | inl x=y = rw-cons-reduced (inr x) w _ (transport! (λ z → is-reduced (inr z :: w)) x=y red) ∙ ReducedWord=-out (ap (λ z → inr z :: w) x=y) rw-cons-cons-flip (inr x) ((inr y :: w) , red) | inr x≠y = rw-cons-flip (inr x) (inr y :: w) (x≠y , red) red rw-++-cons : ∀ x rw₁ rw₂ → rw-++ (rw-cons x rw₁) rw₂ == rw-cons x (rw-++ rw₁ rw₂) rw-++-cons x (nil , _) rw₂ = idp rw-++-cons (inl x) ((inl y :: w₁) , _) rw₂ = idp rw-++-cons (inl x) ((inr y :: w₁) , _) rw₂ with dec x y rw-++-cons (inl x) ((inr y :: w₁) , _) rw₂ | inl p rewrite p = ! (rw-cons-cons-flip (inl y) (rw-++' w₁ rw₂)) rw-++-cons (inl x) ((inr y :: w₁) , _) rw₂ | inr ¬p = idp rw-++-cons (inr x) ((inl y :: w₁) , _) rw₂ with dec x y rw-++-cons (inr x) ((inl y :: w₁) , _) rw₂ | inl p rewrite p = ! (rw-cons-cons-flip (inr y) (rw-++' w₁ rw₂)) rw-++-cons (inr x) ((inl y :: w₁) , _) rw₂ | inr ¬p = idp rw-++-cons (inr x) ((inr y :: w₁) , _) rw₂ = idp rw-++-assoc' : ∀ w₁ rw₂ rw₃ → rw-++ (rw-++' w₁ rw₂) rw₃ == rw-++' w₁ (rw-++' (fst rw₂) rw₃) rw-++-assoc' nil rw₂ rw = idp rw-++-assoc' (x :: w₁) rw₂ rw₃ = rw-++-cons x (rw-++' w₁ rw₂) rw₃ ∙ ap (rw-cons x) (rw-++-assoc' w₁ rw₂ rw₃) -- inv abstract head2-is-reduced : ∀ x y w → is-reduced (x :: y :: w) → is-reduced (x :: y :: nil) head2-is-reduced (inl x) (inl y) w red = lift tt head2-is-reduced (inl x) (inr y) w red = fst red , lift tt head2-is-reduced (inr x) (inl y) w red = fst red , lift tt head2-is-reduced (inr x) (inr y) w red = lift tt cons-is-reduced : ∀ x y w → is-reduced (x :: y :: nil) → is-reduced (y :: w) → is-reduced (x :: y :: w) cons-is-reduced (inl x) (inl y) _ _ red₂ = red₂ cons-is-reduced (inl x) (inr y) _ red₁ red₂ = fst red₁ , red₂ cons-is-reduced (inr x) (inl y) _ red₁ red₂ = fst red₁ , red₂ cons-is-reduced (inr x) (inr y) _ _ red₂ = red₂ ++-is-reduced : ∀ w₁ x w₂ → is-reduced (w₁ ++ (x :: nil)) → is-reduced (x :: w₂) → is-reduced ((w₁ ++ (x :: nil)) ++ w₂) ++-is-reduced nil _ _ _ red₂ = red₂ ++-is-reduced (x :: nil) y w₂ red₁ red₂ = cons-is-reduced x y w₂ red₁ red₂ ++-is-reduced (x :: y :: w₁) z w₂ red₁ red₂ = cons-is-reduced x y ((w₁ ++ (z :: nil)) ++ w₂) (head2-is-reduced x y (w₁ ++ (z :: nil)) red₁) (++-is-reduced (y :: w₁) z w₂ (tail-is-reduced x (y :: w₁ ++ (z :: nil)) red₁) red₂) swap2-is-reduced : ∀ x y → is-reduced (x :: y :: nil) → is-reduced (y :: x :: nil) swap2-is-reduced (inl x) (inl y) red = lift tt swap2-is-reduced (inl x) (inr y) red = fst red ∘ ! , lift tt swap2-is-reduced (inr x) (inl y) red = fst red ∘ ! , lift tt swap2-is-reduced (inr x) (inr y) red = lift tt reverse-is-reduced : ∀ w → is-reduced w → is-reduced (reverse w) reverse-is-reduced nil red = red reverse-is-reduced (x :: nil) red = red reverse-is-reduced (x :: y :: w) red = ++-is-reduced (reverse w) y (x :: nil) (reverse-is-reduced (y :: w) (tail-is-reduced x (y :: w) red)) (swap2-is-reduced x y (head2-is-reduced x y w red)) flip2-is-reduced : ∀ x y → is-reduced (x :: y :: nil) → is-reduced (flip x :: flip y :: nil) flip2-is-reduced (inl x) (inl y) red = red flip2-is-reduced (inl x) (inr y) red = red flip2-is-reduced (inr x) (inl y) red = red flip2-is-reduced (inr x) (inr y) red = red Word-flip-is-reduced : ∀ w → is-reduced w → is-reduced (Word-flip w) Word-flip-is-reduced nil red = red Word-flip-is-reduced (x :: nil) red = red Word-flip-is-reduced (x :: y :: w) red = cons-is-reduced (flip x) (flip y) (Word-flip w) (flip2-is-reduced x y (head2-is-reduced x y w red)) (Word-flip-is-reduced (y :: w) (tail-is-reduced x (y :: w) red)) rw-inv : ReducedWord → ReducedWord rw-inv (w , red) = reverse (Word-flip w) , reverse-is-reduced (Word-flip w) (Word-flip-is-reduced w red) abstract rw-inv-l-lemma : ∀ w₁ x w₂ (red₂ : is-reduced (x :: w₂)) (red₂' : is-reduced w₂) → rw-++' (w₁ ++ (flip x :: nil)) ((x :: w₂) , red₂) == rw-++' w₁ (w₂ , red₂') rw-inv-l-lemma nil (inl x) w₂ _ _ with dec x x rw-inv-l-lemma nil (inl x) w₂ _ _ | inl p = ReducedWord=-out idp rw-inv-l-lemma nil (inl x) w₂ _ _ | inr ¬p = ⊥-rec (¬p idp) rw-inv-l-lemma nil (inr x) w₂ _ _ with dec x x rw-inv-l-lemma nil (inr x) w₂ _ _ | inl p = ReducedWord=-out idp rw-inv-l-lemma nil (inr x) w₂ _ _ | inr ¬p = ⊥-rec (¬p idp) rw-inv-l-lemma (x :: w₁) y w₂ red₂ red₂' = ap (rw-cons x) (rw-inv-l-lemma w₁ y w₂ red₂ red₂') rw-inv-l' : ∀ w (red : is-reduced w) → rw-++' (reverse (Word-flip w)) (w , red) == nil , lift tt rw-inv-l' nil _ = idp rw-inv-l' (x :: w) red = rw-inv-l-lemma (reverse (Word-flip w)) x w red (tail-is-reduced x w red) ∙ rw-inv-l' w (tail-is-reduced x w red) suffix-is-reduced : ∀ w₁ w₂ → is-reduced (w₁ ++ w₂) → is-reduced w₂ suffix-is-reduced nil w₂ red = red suffix-is-reduced (x :: w₁) w₂ red = suffix-is-reduced w₁ w₂ $ tail-is-reduced x (w₁ ++ w₂) red ReducedWord-group-struct : GroupStructure ReducedWord ReducedWord-group-struct = record { ident = nil , lift tt ; inv = rw-inv ; comp = rw-++ ; unit-l = λ _ → idp ; assoc = λ rw → rw-++-assoc' (fst rw) ; inv-l = uncurry rw-inv-l' } ReducedWord-group : Group i ReducedWord-group = group _ ReducedWord-group-struct private abstract QuotWordRel-cons : ∀ x w₂ (red₂ : is-reduced w₂) → QuotWordRel (x :: w₂) (fst (rw-cons x (w₂ , red₂))) QuotWordRel-cons x nil _ = qwr-refl idp QuotWordRel-cons (inl x) (inl y :: w) _ = qwr-refl idp QuotWordRel-cons (inl x) (inr y :: w) _ with dec x y QuotWordRel-cons (inl x) (inr y :: w) _ | inl x=y rewrite x=y = qwr-flip (inl y) w QuotWordRel-cons (inl x) (inr y :: w) _ | inr x≠y = qwr-refl idp QuotWordRel-cons (inr x) (inl y :: w) _ with dec x y QuotWordRel-cons (inr x) (inl y :: w) _ | inl x=y rewrite x=y = qwr-flip (inr y) w QuotWordRel-cons (inr x) (inl y :: w) _ | inr x≠y = qwr-refl idp QuotWordRel-cons (inr x) (inr y :: w) _ = qwr-refl idp QuotWordRel-++ : ∀ w₁ rw₂ → QuotWordRel (w₁ ++ fst rw₂) (fst (rw-++' w₁ rw₂)) QuotWordRel-++ nil _ = qwr-refl idp QuotWordRel-++ (x :: w₁) rw₂ = qwr-trans (qwr-cons x (QuotWordRel-++ w₁ rw₂)) $ uncurry (QuotWordRel-cons x) (rw-++' w₁ rw₂) -- freeness ReducedWord-to-FreeGroup : ReducedWord-group →ᴳ FreeGroup A ReducedWord-to-FreeGroup = group-hom (λ rw → qw[ fst rw ]) (λ rw₁ rw₂ → ! $ quot-rel $ QuotWordRel-++ (fst rw₁) rw₂) private abstract reduce-emap : ∀ {w₁ w₂} → QuotWordRel w₁ w₂ → reduce w₁ == reduce w₂ reduce-emap (qwr-refl p) = ap reduce p reduce-emap (qwr-trans qwr₁ qwr₂) = reduce-emap qwr₁ ∙ reduce-emap qwr₂ reduce-emap (qwr-sym qwr) = ! (reduce-emap qwr) reduce-emap (qwr-cons x qwr) = ap (rw-cons x) (reduce-emap qwr) reduce-emap (qwr-flip x w) = rw-cons-cons-flip x (reduce w) to = GroupHom.f ReducedWord-to-FreeGroup from : QuotWord A → ReducedWord from = QuotWord-rec reduce reduce-emap abstract QuotWordRel-reduce : ∀ w → QuotWordRel w (fst (reduce w)) QuotWordRel-reduce nil = qwr-refl idp QuotWordRel-reduce (x :: w) = qwr-trans (qwr-cons x (QuotWordRel-reduce w)) $ uncurry (QuotWordRel-cons x) (reduce w) to-from : ∀ qw → to (from qw) == qw to-from = QuotWord-elim (λ w → ! $ quot-rel $ QuotWordRel-reduce w) (λ _ → prop-has-all-paths-↓) from-to : ∀ rw → from (to rw) == rw from-to = Group.unit-r ReducedWord-group ReducedWord-iso-FreeGroup : ReducedWord-group ≃ᴳ FreeGroup A ReducedWord-iso-FreeGroup = ReducedWord-to-FreeGroup , is-eq to from to-from from-to
45.331269
108
0.545008
34c0754d6361ae622518d530e63cb8a2e0eff41a
5,994
agda
Agda
src/Categories/Functor/Properties.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
src/Categories/Functor/Properties.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
null
null
null
src/Categories/Functor/Properties.agda
turion/agda-categories
ad0f94b6cf18d8a448b844b021aeda58e833d152
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
{-# OPTIONS --without-K --safe #-} module Categories.Functor.Properties where -- Properties valid of all Functors open import Level open import Data.Product using (proj₁; proj₂; _,_; _×_; Σ) open import Function.Surjection using (Surjective) open import Function.Equivalence using (Equivalence) open import Function.Equality using (Π; _⟶_; _⟨$⟩_; cong) open import Relation.Binary using (_Preserves_⟶_) open import Relation.Nullary open import Categories.Category open import Categories.Functor import Categories.Morphism as Morphism import Categories.Morphism.Reasoning as Reas open import Categories.Morphism.IsoEquiv as IsoEquiv open import Categories.Morphism.Isomorphism private variable o ℓ e o′ ℓ′ e′ : Level C D : Category o ℓ e Contravariant : ∀ (C : Category o ℓ e) (D : Category o′ ℓ′ e′) → Set _ Contravariant C D = Functor (Category.op C) D Faithful : Functor C D → Set _ Faithful {C = C} {D = D} F = ∀ {X Y} → (f g : C [ X , Y ]) → D [ F₁ f ≈ F₁ g ] → C [ f ≈ g ] where open Functor F Full : Functor C D → Set _ Full {C = C} {D = D} F = ∀ {X Y} → Surjective {To = D.hom-setoid {F₀ X} {F₀ Y}} G where module C = Category C module D = Category D open Functor F G : ∀ {X Y} → (C.hom-setoid {X} {Y}) ⟶ D.hom-setoid {F₀ X} {F₀ Y} G = record { _⟨$⟩_ = F₁ ; cong = F-resp-≈ } FullyFaithful : Functor C D → Set _ FullyFaithful F = Full F × Faithful F -- Note that this is a constructive version of Essentially Surjective, which is -- quite a strong assumption. EssentiallySurjective : Functor C D → Set _ EssentiallySurjective {C = C} {D = D} F = (d : Category.Obj D) → Σ C.Obj (λ c → Functor.F₀ F c ≅ d) where open Morphism D module C = Category C -- a series of [ Functor ]-respects-Thing combinators (with respects -> resp) module _ (F : Functor C D) where private module C = Category C using (Obj; _∘_; _⇒_; id; module HomReasoning) module D = Category D module IsoC = IsoEquiv C module IsoD = IsoEquiv D open C hiding (_∘_) open Functor F open Morphism private variable A B E : Obj f g h i : A ⇒ B [_]-resp-∘ : C [ C [ f ∘ g ] ≈ h ] → D [ D [ F₁ f ∘ F₁ g ] ≈ F₁ h ] [_]-resp-∘ {f = f} {g = g} {h = h} eq = begin F₁ f D.∘ F₁ g ≈˘⟨ homomorphism ⟩ F₁ (C [ f ∘ g ]) ≈⟨ F-resp-≈ eq ⟩ F₁ h ∎ where open D.HomReasoning [_]-resp-square : Definitions.CommutativeSquare C f g h i → Definitions.CommutativeSquare D (F₁ f) (F₁ g) (F₁ h) (F₁ i) [_]-resp-square {f = f} {g = g} {h = h} {i = i} sq = begin D [ F₁ h ∘ F₁ f ] ≈˘⟨ homomorphism ⟩ F₁ (C [ h ∘ f ]) ≈⟨ F-resp-≈ sq ⟩ F₁ (C [ i ∘ g ]) ≈⟨ homomorphism ⟩ D [ F₁ i ∘ F₁ g ] ∎ where open D.HomReasoning [_]-resp-Iso : Iso C f g → Iso D (F₁ f) (F₁ g) [_]-resp-Iso {f = f} {g = g} iso = record { isoˡ = begin F₁ g D.∘ F₁ f ≈⟨ [ isoˡ ]-resp-∘ ⟩ F₁ C.id ≈⟨ identity ⟩ D.id ∎ ; isoʳ = begin F₁ f D.∘ F₁ g ≈⟨ [ isoʳ ]-resp-∘ ⟩ F₁ C.id ≈⟨ identity ⟩ D.id ∎ } where open Iso iso open D.HomReasoning [_]-resp-≅ : F₀ Preserves _≅_ C ⟶ _≅_ D [_]-resp-≅ i≅j = record { from = F₁ from ; to = F₁ to ; iso = [ iso ]-resp-Iso } where open _≅_ i≅j [_]-resp-≃ : ∀ {f g : _≅_ C A B} → f IsoC.≃ g → [ f ]-resp-≅ IsoD.≃ [ g ]-resp-≅ [_]-resp-≃ ⌞ eq ⌟ = ⌞ F-resp-≈ eq ⌟ homomorphismᵢ : ∀ {f : _≅_ C B E} {g : _≅_ C A B} → [ _∘ᵢ_ C f g ]-resp-≅ IsoD.≃ (_∘ᵢ_ D [ f ]-resp-≅ [ g ]-resp-≅ ) homomorphismᵢ = ⌞ homomorphism ⌟ -- Uses a strong version of Essential Surjectivity. EssSurj×Full×Faithful⇒Invertible : EssentiallySurjective F → Full F → Faithful F → Functor D C EssSurj×Full×Faithful⇒Invertible surj full faith = record { F₀ = λ d → proj₁ (surj d) ; F₁ = λ {A} {B} f → let (a , sa) = surj A in let (b , sb) = surj B in let module S = Surjective (full {a} {b}) in S.from ⟨$⟩ (_≅_.to sb) ∘ f ∘ (_≅_.from sa) ; identity = λ {A} → let ff = from full (a , sa) = surj A in begin ff ⟨$⟩ _≅_.to sa ∘ D.id ∘ _≅_.from sa ≈⟨ cong ff (E.refl⟩∘⟨ D.identityˡ) ⟩ ff ⟨$⟩ _≅_.to sa ∘ _≅_.from sa ≈⟨ cong ff (_≅_.isoˡ sa) ⟩ ff ⟨$⟩ D.id ≈˘⟨ cong ff identity ⟩ ff ⟨$⟩ F₁ C.id ≈⟨ faith _ _ (right-inverse-of full (F₁ C.id)) ⟩ C.id ∎ ; homomorphism = λ {X} {Y} {Z} {f} {g} → let (x , sx) = surj X (y , sy) = surj Y (z , sz) = surj Z fsx = from sx tsz = to sz ff {T₁} {T₂} = from (full {T₁} {T₂}) in faith _ _ (E.begin F₁ (ff ⟨$⟩ tsz ∘ (g ∘ f) ∘ fsx) E.≈⟨ right-inverse-of full _ ⟩ (tsz ∘ (g ∘ f) ∘ fsx) E.≈⟨ pullˡ (E.refl⟩∘⟨ (E.refl⟩∘⟨ introˡ (isoʳ sy))) ⟩ (tsz ∘ g ∘ ((from sy ∘ to sy) ∘ f)) ∘ fsx E.≈⟨ pushʳ (E.refl⟩∘⟨ D.assoc) E.⟩∘⟨refl ⟩ ((tsz ∘ g) ∘ (from sy ∘ (to sy ∘ f))) ∘ fsx E.≈⟨ D.sym-assoc E.⟩∘⟨refl ⟩ (((tsz ∘ g) ∘ from sy) ∘ (to sy ∘ f)) ∘ fsx E.≈⟨ D.assoc ⟩ ((tsz ∘ g) ∘ from sy) ∘ ((to sy ∘ f) ∘ fsx) E.≈⟨ D.assoc E.⟩∘⟨ D.assoc ⟩ (tsz ∘ g ∘ from sy) ∘ (to sy ∘ f ∘ fsx) E.≈˘⟨ right-inverse-of full _ E.⟩∘⟨ right-inverse-of full _ ⟩ F₁ (ff ⟨$⟩ tsz ∘ g ∘ from sy) ∘ F₁ (ff ⟨$⟩ to sy ∘ f ∘ fsx) E.≈˘⟨ homomorphism ⟩ F₁ ((ff ⟨$⟩ tsz ∘ g ∘ from sy) C.∘ (ff ⟨$⟩ to sy ∘ f ∘ fsx)) E.∎) ; F-resp-≈ = λ f≈g → cong (from full) (D.∘-resp-≈ʳ (D.∘-resp-≈ˡ f≈g)) } where open Morphism._≅_ open Morphism D open Reas D open Category D open Surjective open C.HomReasoning module E = D.HomReasoning -- Functor Composition is Associative and the unit laws are found in -- NaturalTransformation.NaturalIsomorphism, reified as associator, unitorˡ and unitorʳ.
37.229814
126
0.526026
1bffdc32a71585cf2996bcfeafa834485a64669d
9,258
agda
Agda
Relator/Equals/Category.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
6
2020-04-07T17:58:13.000Z
2022-02-05T06:53:22.000Z
Relator/Equals/Category.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
Relator/Equals/Category.agda
Lolirofle/stuff-in-agda
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
[ "MIT" ]
null
null
null
module Relator.Equals.Category where import Data.Tuple as Tuple open import Functional as Fn using (_$_) open import Functional.Dependent using () renaming (_∘_ to _∘ᶠ_) open import Logic.Predicate import Lvl open import Relator.Equals open import Relator.Equals.Proofs open import Structure.Categorical.Properties import Structure.Category.Functor as Category open import Structure.Category.Monad open import Structure.Category.NaturalTransformation open import Structure.Category open import Structure.Function open import Structure.Groupoid import Structure.Groupoid.Functor as Groupoid open import Structure.Operator open import Structure.Relator.Properties open import Structure.Relator open import Syntax.Transitivity open import Type.Category.IntensionalFunctionsCategory open import Type.Identity open import Type private variable ℓ : Lvl.Level private variable T A B Obj : Type{ℓ} private variable f g : A → B private variable P : T → Type{ℓ} private variable x y z : T private variable p : Id x y private variable _⟶_ : Obj → Obj → Type{ℓ} -- The inhabitants of a type together with the the inhabitants of the identity type forms a groupoid. -- An object is an inhabitant of a certain type, and a morphism is a proof of identity between two objects. identityTypeGroupoid : Groupoid{Obj = T} (Id) Groupoid._∘_ identityTypeGroupoid = Fn.swap(transitivity(Id)) Groupoid.id identityTypeGroupoid = reflexivity(Id) Groupoid.inv identityTypeGroupoid = symmetry(Id) Morphism.Associativity.proof (Groupoid.associativity identityTypeGroupoid) {x = _} {x = intro} {y = intro} {z = intro} = intro Morphism.Identityₗ.proof (Tuple.left (Groupoid.identity identityTypeGroupoid)) {f = intro} = intro Morphism.Identityᵣ.proof (Tuple.right (Groupoid.identity identityTypeGroupoid)) {f = intro} = intro Polymorphism.Inverterₗ.proof (Tuple.left (Groupoid.inverter identityTypeGroupoid)) {f = intro} = intro Polymorphism.Inverterᵣ.proof (Tuple.right (Groupoid.inverter identityTypeGroupoid)) {f = intro} = intro identityTypeCategory : Category{Obj = T} (Id) identityTypeCategory = Groupoid.category identityTypeGroupoid -- TODO: Generalize and move this to Structure.Categorical.Proofs inverse-of-identity : ∀{grp : Groupoid(_⟶_)}{x} → (Groupoid.inv grp (Groupoid.id grp {x}) ≡ Groupoid.id grp) inverse-of-identity {grp = grp} = inv(id) 🝖[ Id ]-[ Morphism.identityᵣ(_∘_)(id) ]-sym inv(id) ∘ id 🝖[ Id ]-[ Morphism.inverseₗ(_∘_)(id)(id)(inv id) ] id 🝖[ Id ]-end where open Structure.Groupoid.Groupoid(grp) idTransportFunctor : ∀{grp : Groupoid(_⟶_)} → Groupoid.Functor(identityTypeGroupoid)(grp) Fn.id Groupoid.Functor.map (idTransportFunctor{_⟶_ = _⟶_}{grp = grp}) = sub₂(Id)(_⟶_) where instance _ = Groupoid.morphism-reflexivity grp Groupoid.Functor.op-preserving (idTransportFunctor{grp = grp}) {f = intro} {g = intro} = symmetry(Id) (Morphism.Identityₗ.proof (Tuple.left (Groupoid.identity grp))) Groupoid.Functor.inv-preserving (idTransportFunctor{_⟶_ = _⟶_}{grp = grp}) {f = intro} = sub₂(Id)(_⟶_) (symmetry(Id) (reflexivity(Id))) 🝖[ Id ]-[] sub₂(Id)(_⟶_) (reflexivity(Id)) 🝖[ Id ]-[] id 🝖[ Id ]-[ inverse-of-identity{grp = grp} ]-sym inv(id) 🝖[ Id ]-[] inv(sub₂(Id)(_⟶_) (reflexivity(Id))) 🝖-end where instance _ = Groupoid.morphism-reflexivity grp open Structure.Groupoid.Groupoid(grp) Groupoid.Functor.id-preserving idTransportFunctor = intro -- A functor in the identity type groupoid is a function and a proof of it being a function (compatibility with the identity relation, or in other words, respecting the congruence property). -- Note: It does not neccessarily have to be an endofunctor because different objects (types) can be chosen for the respective groupoids. functionFunctor : Groupoid.Functor(identityTypeGroupoid)(identityTypeGroupoid) f Groupoid.Functor.map (functionFunctor {f = f}) = congruence₁(f) Groupoid.Functor.op-preserving functionFunctor {f = intro} {g = intro} = intro Groupoid.Functor.inv-preserving functionFunctor {f = intro} = intro Groupoid.Functor.id-preserving functionFunctor = intro -- A functor to the category of types is a predicate and a proof of it being a relation (having the substitution property). predicateFunctor : Category.Functor(identityTypeCategory)(typeIntensionalFnCategory) P -- TODO: Is it possible to generalize so that the target (now `typeIntensionalFnCategory`) is more general? `idTransportFunctor` seems to be similar. Maybe on the on₂-category to the right? Category.Functor.map (predicateFunctor{P = P}) = substitute₁(P) Category.Functor.op-preserving predicateFunctor {x} {.x} {.x} {intro} {intro} = intro Category.Functor.id-preserving predicateFunctor = intro -- A natural transformation in the identity type groupoid between two functions (functors of the identity type groupoid) is a proof of them being extensionally identical. extensionalFnNaturalTransformation : (p : ∀(x) → (f(x) ≡ g(x))) → NaturalTransformation([∃]-intro f ⦃ Groupoid.Functor.categoryFunctor functionFunctor ⦄) ([∃]-intro g ⦃ Groupoid.Functor.categoryFunctor functionFunctor ⦄) p NaturalTransformation.natural (extensionalFnNaturalTransformation {f = f} {g = g} p) {x} {.x} {intro} = congruence₁(f) intro 🝖 p(x) 🝖-[ Morphism.Identityᵣ.proof (Tuple.right (Category.identity identityTypeCategory)) ] p(x) 🝖-[ Morphism.Identityₗ.proof (Tuple.left (Category.identity identityTypeCategory)) ]-sym p(x) 🝖 congruence₁(g) intro 🝖-end open import Function.Equals open import Function.Proofs open import Structure.Function.Domain open import Structure.Function.Multi open import Structure.Setoid using (Equiv) -- A monad in the identity type groupoid is an identity function and a proof of it being that and it being idempotent. -- The proof that it behaves the same extensionally as an identity function should also preserve congruence. -- TODO: Instead of (∀{x} → (p(f(x))) ≡ congruence₁(f) (p(x))) , use something like ⦃ preserv : Preserving₁(p)(f)(congruence₁(f)) ⦄ , but it does not work at the moment. Maybe something is dependent here? identityFunctionMonad : ∀{T : Type{ℓ}}{f : T → T} → (p : ∀(x) → (x ≡ f(x))) → (∀{x} → (p(f(x))) ≡ congruence₁(f) (p(x))) → Monad(f) ⦃ Groupoid.Functor.categoryFunctor functionFunctor ⦄ ∃.witness (Monad.Η (identityFunctionMonad p _)) = p NaturalTransformation.natural (∃.proof (Monad.Η (identityFunctionMonad {f = f} p _))) {x}{.x}{intro} = Fn.id intro 🝖 p(x) 🝖[ Id ]-[] intro 🝖 p(x) 🝖[ Id ]-[] p(x) 🝖[ Id ]-[ Morphism.Identityₗ.proof (Tuple.left (Category.identity identityTypeCategory)) ]-sym p(x) 🝖 intro 🝖[ Id ]-[] p(x) 🝖 congruence₁(f) intro 🝖-end ∃.witness (Monad.Μ (identityFunctionMonad {f = f} p _)) x = symmetry(Id) (congruence₁(f) (p(x))) NaturalTransformation.natural (∃.proof (Monad.Μ (identityFunctionMonad {f = f} p _))) {x}{.x}{intro} = (congruence₁(f) Fn.∘ congruence₁(f)) intro 🝖 symmetry(Id) (congruence₁(f) (p(x))) 🝖[ Id ]-[] congruence₁(f) (congruence₁(f) intro) 🝖 symmetry(Id) (congruence₁(f) (p(x))) 🝖[ Id ]-[] congruence₁(f) intro 🝖 symmetry(Id) (congruence₁(f) (p(x))) 🝖[ Id ]-[] intro 🝖 symmetry(Id) (congruence₁(f) (p(x))) 🝖[ Id ]-[] symmetry(Id) (congruence₁(f) (p(x))) 🝖[ Id ]-[ Morphism.Identityₗ.proof (Tuple.left (Category.identity identityTypeCategory)) ]-sym symmetry(Id) (congruence₁(f) (p(x))) 🝖 intro 🝖[ Id ]-[] symmetry(Id) (congruence₁(f) (p(x))) 🝖 congruence₁(f) intro 🝖-end _⊜_.proof (Monad.μ-functor-[∘]-commutativity (identityFunctionMonad {f = f} p preserv)) {x} = congruence₂ₗ(_🝖_)(symmetry(Id) (congruence₁(f) (p(x)))) $ congruence₁(f) (symmetry(Id) (congruence₁(f) (p(x)))) 🝖[ Id ]-[ Groupoid.Functor.inv-preserving (functionFunctor{f = f}) {f = congruence₁(f) (p x)} ] symmetry(Id) (congruence₁(f) (congruence₁(f) (p(x)))) 🝖[ Id ]-[ congruence₁(symmetry(Id)) (congruence₁(congruence₁(f)) preserv) ]-sym symmetry(Id) (congruence₁(f) (p(f(x)))) 🝖-end _⊜_.proof (Monad.μ-functor-[∘]-identityₗ (identityFunctionMonad {f = f} p preserv)) {x} = congruence₁(f) (p(x)) 🝖 symmetry(Id) (congruence₁(f) (p(x))) 🝖[ Id ]-[ congruence₂(Groupoid._∘_ identityTypeGroupoid) (congruence₁(symmetry(Id)) preserv) preserv ]-sym p(f(x)) 🝖 symmetry(Id) (p(f(x))) 🝖[ Id ]-[ Morphism.Inverseₗ.proof (Tuple.left(Groupoid.inverse identityTypeGroupoid {f = p(f x)})) ] intro{x = f(x)} 🝖-end _⊜_.proof (Monad.μ-functor-[∘]-identityᵣ (identityFunctionMonad {f = f} p preserv)) {x} = p(f(x)) 🝖 symmetry(Id) (congruence₁(f) (p(x))) 🝖[ Id ]-[ congruence₂ᵣ(_🝖_)(p(f(x))) (congruence₁(symmetry(Id)) preserv) ]-sym p(f(x)) 🝖 symmetry(Id) (p(f(x))) 🝖[ Id ]-[ Morphism.Inverseₗ.proof (Tuple.left(Groupoid.inverse identityTypeGroupoid {f = p(f x)})) ] intro{x = f(x)} 🝖-end
71.215385
276
0.67682
52d9c36f3612005abb9081d14d88b654bd473ebb
6,323
agda
Agda
Cubical/Foundations/Isomorphism.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
Cubical/Foundations/Isomorphism.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
Cubical/Foundations/Isomorphism.agda
howsiyu/cubical
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
[ "MIT" ]
null
null
null
{- Theory about isomorphisms - Definitions of [section] and [retract] - Definition of isomorphisms ([Iso]) - Any isomorphism is an equivalence ([isoToEquiv]) -} {-# OPTIONS --safe #-} module Cubical.Foundations.Isomorphism where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv.Base private variable ℓ ℓ' : Level A B C : Type ℓ -- Section and retract module _ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} where section : (f : A → B) → (g : B → A) → Type ℓ' section f g = ∀ b → f (g b) ≡ b -- NB: `g` is the retraction! retract : (f : A → B) → (g : B → A) → Type ℓ retract f g = ∀ a → g (f a) ≡ a record Iso {ℓ ℓ'} (A : Type ℓ) (B : Type ℓ') : Type (ℓ-max ℓ ℓ') where no-eta-equality constructor iso field fun : A → B inv : B → A rightInv : section fun inv leftInv : retract fun inv isIso : (A → B) → Type _ isIso {A = A} {B = B} f = Σ[ g ∈ (B → A) ] Σ[ _ ∈ section f g ] retract f g isoFunInjective : (f : Iso A B) → (x y : A) → Iso.fun f x ≡ Iso.fun f y → x ≡ y isoFunInjective f x y h = sym (Iso.leftInv f x) ∙∙ cong (Iso.inv f) h ∙∙ Iso.leftInv f y isoInvInjective : (f : Iso A B) → (x y : B) → Iso.inv f x ≡ Iso.inv f y → x ≡ y isoInvInjective f x y h = sym (Iso.rightInv f x) ∙∙ cong (Iso.fun f) h ∙∙ Iso.rightInv f y -- Any iso is an equivalence module _ (i : Iso A B) where open Iso i renaming ( fun to f ; inv to g ; rightInv to s ; leftInv to t) private module _ (y : B) (x0 x1 : A) (p0 : f x0 ≡ y) (p1 : f x1 ≡ y) where fill0 : I → I → A fill0 i = hfill (λ k → λ { (i = i1) → t x0 k ; (i = i0) → g y }) (inS (g (p0 (~ i)))) fill1 : I → I → A fill1 i = hfill (λ k → λ { (i = i1) → t x1 k ; (i = i0) → g y }) (inS (g (p1 (~ i)))) fill2 : I → I → A fill2 i = hfill (λ k → λ { (i = i1) → fill1 k i1 ; (i = i0) → fill0 k i1 }) (inS (g y)) p : x0 ≡ x1 p i = fill2 i i1 sq : I → I → A sq i j = hcomp (λ k → λ { (i = i1) → fill1 j (~ k) ; (i = i0) → fill0 j (~ k) ; (j = i1) → t (fill2 i i1) (~ k) ; (j = i0) → g y }) (fill2 i j) sq1 : I → I → B sq1 i j = hcomp (λ k → λ { (i = i1) → s (p1 (~ j)) k ; (i = i0) → s (p0 (~ j)) k ; (j = i1) → s (f (p i)) k ; (j = i0) → s y k }) (f (sq i j)) lemIso : (x0 , p0) ≡ (x1 , p1) lemIso i .fst = p i lemIso i .snd = λ j → sq1 i (~ j) isoToIsEquiv : isEquiv f isoToIsEquiv .equiv-proof y .fst .fst = g y isoToIsEquiv .equiv-proof y .fst .snd = s y isoToIsEquiv .equiv-proof y .snd z = lemIso y (g y) (fst z) (s y) (snd z) isoToEquiv : Iso A B → A ≃ B isoToEquiv i .fst = i .Iso.fun isoToEquiv i .snd = isoToIsEquiv i isoToPath : Iso A B → A ≡ B isoToPath {A = A} {B = B} f i = Glue B (λ { (i = i0) → (A , isoToEquiv f) ; (i = i1) → (B , idEquiv B) }) open Iso invIso : Iso A B → Iso B A fun (invIso f) = inv f inv (invIso f) = fun f rightInv (invIso f) = leftInv f leftInv (invIso f) = rightInv f compIso : Iso A B → Iso B C → Iso A C fun (compIso i j) = fun j ∘ fun i inv (compIso i j) = inv i ∘ inv j rightInv (compIso i j) b = cong (fun j) (rightInv i (inv j b)) ∙ rightInv j b leftInv (compIso i j) a = cong (inv i) (leftInv j (fun i a)) ∙ leftInv i a composesToId→Iso : (G : Iso A B) (g : B → A) → G .fun ∘ g ≡ idfun B → Iso B A fun (composesToId→Iso _ g _) = g inv (composesToId→Iso j _ _) = fun j rightInv (composesToId→Iso i g path) b = sym (leftInv i (g (fun i b))) ∙∙ cong (λ g → inv i (g (fun i b))) path ∙∙ leftInv i b leftInv (composesToId→Iso _ _ path) b i = path i b idIso : Iso A A fun idIso = idfun _ inv idIso = idfun _ rightInv idIso _ = refl leftInv idIso _ = refl LiftIso : Iso A (Lift {i = ℓ} {j = ℓ'} A) fun LiftIso = lift inv LiftIso = lower rightInv LiftIso _ = refl leftInv LiftIso _ = refl isContr→Iso : isContr A → isContr B → Iso A B fun (isContr→Iso _ Bctr) _ = Bctr .fst inv (isContr→Iso Actr _) _ = Actr .fst rightInv (isContr→Iso _ Bctr) = Bctr .snd leftInv (isContr→Iso Actr _) = Actr .snd isProp→Iso : (Aprop : isProp A) (Bprop : isProp B) (f : A → B) (g : B → A) → Iso A B fun (isProp→Iso _ _ f _) = f inv (isProp→Iso _ _ _ g) = g rightInv (isProp→Iso _ Bprop f g) b = Bprop (f (g b)) b leftInv (isProp→Iso Aprop _ f g) a = Aprop (g (f a)) a domIso : ∀ {ℓ} {C : Type ℓ} → Iso A B → Iso (A → C) (B → C) fun (domIso e) f b = f (inv e b) inv (domIso e) f a = f (fun e a) rightInv (domIso e) f i x = f (rightInv e x i) leftInv (domIso e) f i x = f (leftInv e x i) -- Helpful notation _Iso⟨_⟩_ : ∀ {ℓ ℓ' ℓ''} {B : Type ℓ'} {C : Type ℓ''} (X : Type ℓ) → Iso X B → Iso B C → Iso X C _ Iso⟨ f ⟩ g = compIso f g _∎Iso : ∀ {ℓ} (A : Type ℓ) → Iso A A A ∎Iso = idIso {A = A} infixr 0 _Iso⟨_⟩_ infix 1 _∎Iso codomainIsoDep : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : A → Type ℓ'} {C : A → Type ℓ''} → ((a : A) → Iso (B a) (C a)) → Iso ((a : A) → B a) ((a : A) → C a) fun (codomainIsoDep is) f a = fun (is a) (f a) inv (codomainIsoDep is) f a = inv (is a) (f a) rightInv (codomainIsoDep is) f = funExt λ a → rightInv (is a) (f a) leftInv (codomainIsoDep is) f = funExt λ a → leftInv (is a) (f a) codomainIso : ∀ {ℓ ℓ' ℓ''} {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} → Iso B C → Iso (A → B) (A → C) codomainIso z = codomainIsoDep λ _ → z Iso≡Set : isSet A → isSet B → (f g : Iso A B) → ((x : A) → f .fun x ≡ g .fun x) → ((x : B) → f .inv x ≡ g .inv x) → f ≡ g fun (Iso≡Set hA hB f g hfun hinv i) x = hfun x i inv (Iso≡Set hA hB f g hfun hinv i) x = hinv x i rightInv (Iso≡Set hA hB f g hfun hinv i) x j = isSet→isSet' hB (rightInv f x) (rightInv g x) (λ i → hfun (hinv x i) i) refl i j leftInv (Iso≡Set hA hB f g hfun hinv i) x j = isSet→isSet' hA (leftInv f x) (leftInv g x) (λ i → hinv (hfun x i) i) refl i j
32.260204
95
0.509094
9aaea8f15805e55be40709cf35b5e41f73c5a402
1,739
agda
Agda
data/github.com/liamoc/learn-you-an-agda/118c5d99819c6b3c3a5e1dedfc0078c4fa8c2ece/Printf.agda
ajnavarro/language-dataset
34e2980af98ff2ded500619edce3e0907a6e9050
[ "MIT" ]
9
2018-08-07T11:54:33.000Z
2022-03-11T09:48:45.000Z
Printf.agda
siddhartha-gadgil/learn-you-an-agda
f22242e8d7eebcbb5f481ba62eb2b1cafc9657a2
[ "BSD-3-Clause" ]
91
2019-11-11T15:41:26.000Z
2022-03-21T04:17:18.000Z
Printf.agda
siddhartha-gadgil/learn-you-an-agda
f22242e8d7eebcbb5f481ba62eb2b1cafc9657a2
[ "BSD-3-Clause" ]
3
2019-11-13T12:44:41.000Z
2022-01-06T19:34:26.000Z
module Printf where open import Data.List hiding(_++_) open import Data.String open import Data.Unit open import Data.Empty open import Data.Char open import Data.Product open import Data.Nat.Show renaming (show to showNat) open import Data.Nat open import Function using (_∘_) data ValidFormat : Set₁ where argument : (A : Set) → (A → String) → ValidFormat literal : Char → ValidFormat data Format : Set₁ where valid : List ValidFormat → Format invalid : Format parse : String → Format parse s = parse′ [] (toList s) where parse′ : List ValidFormat → List Char → Format parse′ l ('%' ∷ 's' ∷ fmt) = parse′ (argument String (λ x → x) ∷ l) fmt parse′ l ('%' ∷ 'c' ∷ fmt) = parse′ (argument Char (λ x → fromList [ x ]) ∷ l) fmt parse′ l ('%' ∷ 'd' ∷ fmt) = parse′ (argument ℕ showNat ∷ l) fmt parse′ l ('%' ∷ '%' ∷ fmt) = parse′ (literal '%' ∷ l) fmt parse′ l ('%' ∷ c ∷ fmt) = invalid parse′ l (c ∷ fmt) = parse′ (literal c ∷ l) fmt parse′ l [] = valid (reverse l) Args : Format → Set Args invalid = ⊥ → String Args (valid (argument t _ ∷ r)) = t → (Args (valid r)) Args (valid (literal _ ∷ r)) = Args (valid r) Args (valid []) = String FormatArgs : String → Set FormatArgs f = Args (parse f) sprintf : (f : String) → FormatArgs f sprintf = sprintf′ "" ∘ parse where sprintf′ : String → (f : Format) → Args f sprintf′ accum invalid = λ t → "" sprintf′ accum (valid []) = accum sprintf′ accum (valid (argument _ s ∷ l)) = λ t → (sprintf′ (accum ++ s t) (valid l)) sprintf′ accum (valid (literal c ∷ l)) = sprintf′ (accum ++ fromList [ c ]) (valid l)
33.442308
92
0.572743
8b43eba04cbad30261357ffd41b04d83bf5cf7cc
788
agda
Agda
agda/BBHeap/Height.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
6
2015-05-21T12:50:35.000Z
2021-08-24T22:11:15.000Z
agda/BBHeap/Height.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
agda/BBHeap/Height.agda
bgbianchi/sorting
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
[ "MIT" ]
null
null
null
{-# OPTIONS --sized-types #-} module BBHeap.Height {A : Set}(_≤_ : A → A → Set) where open import BBHeap _≤_ hiding (#) open import Bound.Lower A open import Bound.Lower.Order _≤_ open import SNat # : {b : Bound} → BBHeap b → SNat # leaf = zero # (left {l = l} {r = r} _ _) = succ (# l + # r) # (right {l = l} {r = r} _ _) = succ (# l + # r) height : {b : Bound} → BBHeap b → SNat height leaf = zero height (left {l = l} _ _) = succ (height l) height (right {l = l} _ _) = succ (height l) #' : {b : Bound} → BBHeap b → SNat #' leaf = zero #' (left {r = r} _ _) = succ (#' r + #' r) #' (right {r = r} _ _) = succ (#' r + #' r) height' : {b : Bound} → BBHeap b → SNat height' leaf = zero height' (left {r = r} _ _) = succ (height' r) height' (right {r = r} _ _) = succ (height' r)
26.266667
55
0.53934
4bb5f79aaf064e3746f58d0cf6dadb9cd7a15611
652
agda
Agda
agda-stdlib/src/Data/List/Relation/Unary/Unique/Propositional.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/List/Relation/Unary/Unique/Propositional.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/List/Relation/Unary/Unique/Propositional.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- Lists made up entirely of unique elements (propositional equality) ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Unary.Unique.Propositional {a} {A : Set a} where open import Relation.Binary.PropositionalEquality using (setoid) open import Data.List.Relation.Unary.Unique.Setoid as SetoidUnique ------------------------------------------------------------------------ -- Re-export the contents of setoid uniqueness open SetoidUnique (setoid A) public
34.315789
74
0.510736
03246eff2cd02913b65b7fa10694c765173f1f79
2,381
agda
Agda
src/Examples/Unification.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
4
2019-04-05T17:57:11.000Z
2021-05-07T04:08:41.000Z
src/Examples/Unification.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
src/Examples/Unification.agda
metaborg/ts.agda
7fe638b87de26df47b6437f5ab0a8b955384958d
[ "MIT" ]
null
null
null
open import Prelude hiding (id; Bool) module Examples.Unification where data TC : Set where tc-int : TC tc-bool : TC _tc≟_ : (a b : TC) → Dec (a ≡ b) tc-int tc≟ tc-int = yes refl tc-int tc≟ tc-bool = no (λ ()) tc-bool tc≟ tc-int = no (λ ()) tc-bool tc≟ tc-bool = yes refl open import Implicits.Oliveira.Types TC _tc≟_ open import Implicits.Oliveira.Terms TC _tc≟_ open import Implicits.Oliveira.Contexts TC _tc≟_ open import Implicits.Oliveira.WellTyped TC _tc≟_ open import Implicits.Oliveira.Substitutions TC _tc≟_ open import Implicits.Oliveira.Types.Unification TC _tc≟_ open import Implicits.Oliveira.Types.Unification.McBride TC _tc≟_ as McBride using () open import Data.Star as S open import Data.Maybe open import Level using () renaming (zero to level₀) open import Data.Maybe using (monad; functor) open import Category.Functor open RawFunctor {level₀} functor module M = MetaTypeMetaSubst module T = MetaTypeTypeSubst Bool : ∀ {n} → Type n Bool = simpl (tc tc-bool) Int : ∀ {n} → Type n Int = simpl (tc tc-int) module ex₂ where -- mgu test for simple 2 variable substitution a : MetaType (suc (suc zero)) (suc zero) a = open-meta $ open-meta $ to-meta $ (simpl ((simpl (tvar zero)) →' (simpl (simpl (tvar (suc zero)) →' simpl (tvar (suc (suc zero))))))) b : SimpleType (suc zero) b = Int →' (simpl (Int →' simpl (tvar zero))) s = mgu a b u = asub (proj₁ $ from-just s) unifies : a M./ u ≡ (simpl (to-smeta b)) unifies = refl module ex₃ where -- mgu test for simple 1 variable substitution -- (limited α) a : MetaType (suc zero) (suc zero) a = open-meta (to-meta (∀' (simpl ((simpl (tvar zero)) →' simpl (tvar (suc zero)))))) b : SimpleType (suc zero) b = Int →' Int s : mgu a b ≡ nothing s = refl module ex₄ where -- with ∀' in there somewhere a : MetaType (suc zero) (suc zero) a = simpl ((∀' (s-mvar zero)) →' (s-tc tc-int)) -- won't unify with a because we'd need to instantiate s-mvar zero with -- a s-tvar that's not yet introduced b : SimpleType (suc zero) b = (∀' (simpl (tvar zero))) →' Int s : mgu a b ≡ nothing s = refl module ex₅ where -- renaming example a : MetaType (suc (suc zero)) (suc zero) a = (s-mvar zero) ⇒ (s-mvar (suc zero)) b : Type (suc zero) b = (simpl (tvar (zero))) ⇒ (simpl (tvar zero)) s : is-just (McBride.mgu a b) ≡ true s = refl open ex₅
25.063158
139
0.656447
370daef6aabc4f9b245a0d06e7da0bbcedd6dbbd
646
agda
Agda
test/Fail/Issue1258-2.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Fail/Issue1258-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Fail/Issue1258-2.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue1258-2 where data Nat : Set where zero : Nat suc : Nat -> Nat data _==_ {A : Set}(x : A) : A -> Set where refl : x == x data Bool : Set where true false : Bool data Σ (A : Set) (B : A → Set) : Set where _,_ : (x : A) → B x → Σ A B _×_ : Set → Set → Set A × B = Σ A (λ _ → B) postulate f : (A : Set) -> A -> Bool record Wrap (A : Set) : Set where constructor wrap field wrapped : A data ⊥ : Set where Foo : Bool -> Set Foo true = ⊥ Foo false = ⊥ Alpha : Bool Stuck = Foo Alpha Beta : Stuck test : f (Bool × Wrap Nat) (true , wrap zero) == f (Stuck × Stuck) (Beta , Beta) Alpha = _ Beta = _ test = refl
16.564103
80
0.557276
213d7a17935b9738f5b40f60185da71f6024e0b5
226
agda
Agda
test/Succeed/Issue3062.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue3062.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue3062.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
open import Agda.Builtin.List open import Agda.Builtin.Char open import Agda.Builtin.Equality postulate A B : Set b : B f : List A → Char → B f _ 'a' = b f [] _ = b f _ _ = b test : ∀ xs → f xs 'a' ≡ b test _ = refl
14.125
33
0.606195
38bc22caa15419d21060b8c2d87b8d27d0d4ab04
301
agda
Agda
test/Succeed/Issue2953.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2953.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2953.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module _ where open import Agda.Builtin.IO open import Agda.Builtin.String open import Agda.Builtin.Unit data D (A : Set) : Set where L : A → D A R : A → D A data T : Set where Var : (s : D String) → T test : T → String test (Var (L "abc")) = "" test (Var (L s)) = "" test (Var (R s)) = ""
15.842105
31
0.58804
13ab5dca1cabc513a7e04a4497d72ba4351965c2
127
agda
Agda
test/interaction/Issue1839.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue1839.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue1839.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module _ where open import Issue1839.A open import Issue1839.B X : DontPrintThis -- should display as PrintThis X = {!!}
14.111111
51
0.716535
8b238b157e7c07108a7226dc0153e16f893fed2a
15,509
agda
Agda
agda-stdlib-0.9/src/Relation/Binary/Product/Pointwise.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
1
2016-10-20T15:52:05.000Z
2016-10-20T15:52:05.000Z
agda-stdlib-0.9/src/Relation/Binary/Product/Pointwise.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
agda-stdlib-0.9/src/Relation/Binary/Product/Pointwise.agda
qwe2/try-agda
9d4c43b1609d3f085636376fdca73093481ab882
[ "Apache-2.0" ]
null
null
null
------------------------------------------------------------------------ -- The Agda standard library -- -- Pointwise products of binary relations ------------------------------------------------------------------------ module Relation.Binary.Product.Pointwise where open import Data.Product as Prod open import Data.Sum open import Data.Unit using (⊤) open import Function open import Function.Equality as F using (_⟶_; _⟨$⟩_) open import Function.Equivalence as Eq using (Equivalence; _⇔_; module Equivalence) open import Function.Injection as Inj using (Injection; _↣_; module Injection) open import Function.Inverse as Inv using (Inverse; _↔_; module Inverse) open import Function.LeftInverse as LeftInv using (LeftInverse; _↞_; _LeftInverseOf_; module LeftInverse) open import Function.Related open import Function.Surjection as Surj using (Surjection; _↠_; module Surjection) open import Level import Relation.Nullary.Decidable as Dec open import Relation.Nullary.Product open import Relation.Binary open import Relation.Binary.PropositionalEquality as P using (_≡_) module _ {a₁ a₂ ℓ₁ ℓ₂} {A₁ : Set a₁} {A₂ : Set a₂} where infixr 2 _×-Rel_ _×-Rel_ : Rel A₁ ℓ₁ → Rel A₂ ℓ₂ → Rel (A₁ × A₂) _ _∼₁_ ×-Rel _∼₂_ = (_∼₁_ on proj₁) -×- (_∼₂_ on proj₂) -- Some properties which are preserved by ×-Rel (under certain -- assumptions). _×-reflexive_ : ∀ {_≈₁_ _∼₁_ _≈₂_ _∼₂_} → _≈₁_ ⇒ _∼₁_ → _≈₂_ ⇒ _∼₂_ → (_≈₁_ ×-Rel _≈₂_) ⇒ (_∼₁_ ×-Rel _∼₂_) refl₁ ×-reflexive refl₂ = λ x≈y → (refl₁ (proj₁ x≈y) , refl₂ (proj₂ x≈y)) _×-refl_ : ∀ {_∼₁_ _∼₂_} → Reflexive _∼₁_ → Reflexive _∼₂_ → Reflexive (_∼₁_ ×-Rel _∼₂_) refl₁ ×-refl refl₂ = (refl₁ , refl₂) ×-irreflexive₁ : ∀ {_≈₁_ _<₁_ _≈₂_ _<₂_} → Irreflexive _≈₁_ _<₁_ → Irreflexive (_≈₁_ ×-Rel _≈₂_) (_<₁_ ×-Rel _<₂_) ×-irreflexive₁ ir = λ x≈y x<y → ir (proj₁ x≈y) (proj₁ x<y) ×-irreflexive₂ : ∀ {_≈₁_ _<₁_ _≈₂_ _<₂_} → Irreflexive _≈₂_ _<₂_ → Irreflexive (_≈₁_ ×-Rel _≈₂_) (_<₁_ ×-Rel _<₂_) ×-irreflexive₂ ir = λ x≈y x<y → ir (proj₂ x≈y) (proj₂ x<y) _×-symmetric_ : ∀ {_∼₁_ _∼₂_} → Symmetric _∼₁_ → Symmetric _∼₂_ → Symmetric (_∼₁_ ×-Rel _∼₂_) sym₁ ×-symmetric sym₂ = λ x∼y → sym₁ (proj₁ x∼y) , sym₂ (proj₂ x∼y) _×-transitive_ : ∀ {_∼₁_ _∼₂_} → Transitive _∼₁_ → Transitive _∼₂_ → Transitive (_∼₁_ ×-Rel _∼₂_) trans₁ ×-transitive trans₂ = λ x∼y y∼z → trans₁ (proj₁ x∼y) (proj₁ y∼z) , trans₂ (proj₂ x∼y) (proj₂ y∼z) _×-antisymmetric_ : ∀ {_≈₁_ _≤₁_ _≈₂_ _≤₂_} → Antisymmetric _≈₁_ _≤₁_ → Antisymmetric _≈₂_ _≤₂_ → Antisymmetric (_≈₁_ ×-Rel _≈₂_) (_≤₁_ ×-Rel _≤₂_) antisym₁ ×-antisymmetric antisym₂ = λ x≤y y≤x → ( antisym₁ (proj₁ x≤y) (proj₁ y≤x) , antisym₂ (proj₂ x≤y) (proj₂ y≤x) ) ×-asymmetric₁ : ∀ {_<₁_ _∼₂_} → Asymmetric _<₁_ → Asymmetric (_<₁_ ×-Rel _∼₂_) ×-asymmetric₁ asym₁ = λ x<y y<x → asym₁ (proj₁ x<y) (proj₁ y<x) ×-asymmetric₂ : ∀ {_∼₁_ _<₂_} → Asymmetric _<₂_ → Asymmetric (_∼₁_ ×-Rel _<₂_) ×-asymmetric₂ asym₂ = λ x<y y<x → asym₂ (proj₂ x<y) (proj₂ y<x) _×-≈-respects₂_ : ∀ {_≈₁_ _∼₁_ _≈₂_ _∼₂_} → _∼₁_ Respects₂ _≈₁_ → _∼₂_ Respects₂ _≈₂_ → (_∼₁_ ×-Rel _∼₂_) Respects₂ (_≈₁_ ×-Rel _≈₂_) _×-≈-respects₂_ {_≈₁_ = _≈₁_} {_∼₁_ = _∼₁_} {_≈₂_ = _≈₂_} {_∼₂_ = _∼₂_} resp₁ resp₂ = (λ {x y z} → resp¹ {x} {y} {z}) , (λ {x y z} → resp² {x} {y} {z}) where _∼_ = _∼₁_ ×-Rel _∼₂_ resp¹ : ∀ {x} → (_∼_ x) Respects (_≈₁_ ×-Rel _≈₂_) resp¹ y≈y' x∼y = proj₁ resp₁ (proj₁ y≈y') (proj₁ x∼y) , proj₁ resp₂ (proj₂ y≈y') (proj₂ x∼y) resp² : ∀ {y} → (flip _∼_ y) Respects (_≈₁_ ×-Rel _≈₂_) resp² x≈x' x∼y = proj₂ resp₁ (proj₁ x≈x') (proj₁ x∼y) , proj₂ resp₂ (proj₂ x≈x') (proj₂ x∼y) ×-total : ∀ {_∼₁_ _∼₂_} → Symmetric _∼₁_ → Total _∼₁_ → Total _∼₂_ → Total (_∼₁_ ×-Rel _∼₂_) ×-total {_∼₁_ = _∼₁_} {_∼₂_ = _∼₂_} sym₁ total₁ total₂ = total where total : Total (_∼₁_ ×-Rel _∼₂_) total x y with total₁ (proj₁ x) (proj₁ y) | total₂ (proj₂ x) (proj₂ y) ... | inj₁ x₁∼y₁ | inj₁ x₂∼y₂ = inj₁ ( x₁∼y₁ , x₂∼y₂) ... | inj₁ x₁∼y₁ | inj₂ y₂∼x₂ = inj₂ (sym₁ x₁∼y₁ , y₂∼x₂) ... | inj₂ y₁∼x₁ | inj₂ y₂∼x₂ = inj₂ ( y₁∼x₁ , y₂∼x₂) ... | inj₂ y₁∼x₁ | inj₁ x₂∼y₂ = inj₁ (sym₁ y₁∼x₁ , x₂∼y₂) _×-decidable_ : ∀ {_∼₁_ _∼₂_} → Decidable _∼₁_ → Decidable _∼₂_ → Decidable (_∼₁_ ×-Rel _∼₂_) dec₁ ×-decidable dec₂ = λ x y → dec₁ (proj₁ x) (proj₁ y) ×-dec dec₂ (proj₂ x) (proj₂ y) -- Some collections of properties which are preserved by ×-Rel. _×-isEquivalence_ : ∀ {_≈₁_ _≈₂_} → IsEquivalence _≈₁_ → IsEquivalence _≈₂_ → IsEquivalence (_≈₁_ ×-Rel _≈₂_) _×-isEquivalence_ {_≈₁_ = _≈₁_} {_≈₂_ = _≈₂_} eq₁ eq₂ = record { refl = λ {x} → _×-refl_ {_∼₁_ = _≈₁_} {_∼₂_ = _≈₂_} (refl eq₁) (refl eq₂) {x} ; sym = λ {x y} → _×-symmetric_ {_∼₁_ = _≈₁_} {_∼₂_ = _≈₂_} (sym eq₁) (sym eq₂) {x} {y} ; trans = λ {x y z} → _×-transitive_ {_∼₁_ = _≈₁_} {_∼₂_ = _≈₂_} (trans eq₁) (trans eq₂) {x} {y} {z} } where open IsEquivalence _×-isPreorder_ : ∀ {_≈₁_ _∼₁_ _≈₂_ _∼₂_} → IsPreorder _≈₁_ _∼₁_ → IsPreorder _≈₂_ _∼₂_ → IsPreorder (_≈₁_ ×-Rel _≈₂_) (_∼₁_ ×-Rel _∼₂_) _×-isPreorder_ {_∼₁_ = _∼₁_} {_∼₂_ = _∼₂_} pre₁ pre₂ = record { isEquivalence = isEquivalence pre₁ ×-isEquivalence isEquivalence pre₂ ; reflexive = λ {x y} → _×-reflexive_ {_∼₁_ = _∼₁_} {_∼₂_ = _∼₂_} (reflexive pre₁) (reflexive pre₂) {x} {y} ; trans = λ {x y z} → _×-transitive_ {_∼₁_ = _∼₁_} {_∼₂_ = _∼₂_} (trans pre₁) (trans pre₂) {x} {y} {z} } where open IsPreorder _×-isDecEquivalence_ : ∀ {_≈₁_ _≈₂_} → IsDecEquivalence _≈₁_ → IsDecEquivalence _≈₂_ → IsDecEquivalence (_≈₁_ ×-Rel _≈₂_) eq₁ ×-isDecEquivalence eq₂ = record { isEquivalence = isEquivalence eq₁ ×-isEquivalence isEquivalence eq₂ ; _≟_ = _≟_ eq₁ ×-decidable _≟_ eq₂ } where open IsDecEquivalence _×-isPartialOrder_ : ∀ {_≈₁_ _≤₁_ _≈₂_ _≤₂_} → IsPartialOrder _≈₁_ _≤₁_ → IsPartialOrder _≈₂_ _≤₂_ → IsPartialOrder (_≈₁_ ×-Rel _≈₂_) (_≤₁_ ×-Rel _≤₂_) _×-isPartialOrder_ {_≤₁_ = _≤₁_} {_≤₂_ = _≤₂_} po₁ po₂ = record { isPreorder = isPreorder po₁ ×-isPreorder isPreorder po₂ ; antisym = λ {x y} → _×-antisymmetric_ {_≤₁_ = _≤₁_} {_≤₂_ = _≤₂_} (antisym po₁) (antisym po₂) {x} {y} } where open IsPartialOrder _×-isStrictPartialOrder_ : ∀ {_≈₁_ _<₁_ _≈₂_ _<₂_} → IsStrictPartialOrder _≈₁_ _<₁_ → IsStrictPartialOrder _≈₂_ _<₂_ → IsStrictPartialOrder (_≈₁_ ×-Rel _≈₂_) (_<₁_ ×-Rel _<₂_) _×-isStrictPartialOrder_ {_<₁_ = _<₁_} {_≈₂_ = _≈₂_} {_<₂_ = _<₂_} spo₁ spo₂ = record { isEquivalence = isEquivalence spo₁ ×-isEquivalence isEquivalence spo₂ ; irrefl = λ {x y} → ×-irreflexive₁ {_<₁_ = _<₁_} {_≈₂_ = _≈₂_} {_<₂_ = _<₂_} (irrefl spo₁) {x} {y} ; trans = λ {x y z} → _×-transitive_ {_∼₁_ = _<₁_} {_∼₂_ = _<₂_} (trans spo₁) (trans spo₂) {x} {y} {z} ; <-resp-≈ = <-resp-≈ spo₁ ×-≈-respects₂ <-resp-≈ spo₂ } where open IsStrictPartialOrder -- "Packages" (e.g. setoids) can also be combined. _×-preorder_ : ∀ {p₁ p₂ p₃ p₄} → Preorder p₁ p₂ _ → Preorder p₃ p₄ _ → Preorder _ _ _ p₁ ×-preorder p₂ = record { isPreorder = isPreorder p₁ ×-isPreorder isPreorder p₂ } where open Preorder _×-setoid_ : ∀ {s₁ s₂ s₃ s₄} → Setoid s₁ s₂ → Setoid s₃ s₄ → Setoid _ _ s₁ ×-setoid s₂ = record { isEquivalence = isEquivalence s₁ ×-isEquivalence isEquivalence s₂ } where open Setoid _×-decSetoid_ : ∀ {d₁ d₂ d₃ d₄} → DecSetoid d₁ d₂ → DecSetoid d₃ d₄ → DecSetoid _ _ s₁ ×-decSetoid s₂ = record { isDecEquivalence = isDecEquivalence s₁ ×-isDecEquivalence isDecEquivalence s₂ } where open DecSetoid _×-poset_ : ∀ {p₁ p₂ p₃ p₄} → Poset p₁ p₂ _ → Poset p₃ p₄ _ → Poset _ _ _ s₁ ×-poset s₂ = record { isPartialOrder = isPartialOrder s₁ ×-isPartialOrder isPartialOrder s₂ } where open Poset _×-strictPartialOrder_ : ∀ {s₁ s₂ s₃ s₄} → StrictPartialOrder s₁ s₂ _ → StrictPartialOrder s₃ s₄ _ → StrictPartialOrder _ _ _ s₁ ×-strictPartialOrder s₂ = record { isStrictPartialOrder = isStrictPartialOrder s₁ ×-isStrictPartialOrder isStrictPartialOrder s₂ } where open StrictPartialOrder ------------------------------------------------------------------------ -- Some properties related to "relatedness" private to-cong : ∀ {a b} {A : Set a} {B : Set b} → (_≡_ ×-Rel _≡_) ⇒ _≡_ {A = A × B} to-cong {i = (x , y)} {j = (.x , .y)} (P.refl , P.refl) = P.refl from-cong : ∀ {a b} {A : Set a} {B : Set b} → _≡_ {A = A × B} ⇒ (_≡_ ×-Rel _≡_) from-cong P.refl = (P.refl , P.refl) ×-Rel↔≡ : ∀ {a b} {A : Set a} {B : Set b} → Inverse (P.setoid A ×-setoid P.setoid B) (P.setoid (A × B)) ×-Rel↔≡ = record { to = record { _⟨$⟩_ = id; cong = to-cong } ; from = record { _⟨$⟩_ = id; cong = from-cong } ; inverse-of = record { left-inverse-of = λ _ → (P.refl , P.refl) ; right-inverse-of = λ _ → P.refl } } _×-≟_ : ∀ {a b} {A : Set a} {B : Set b} → Decidable {A = A} _≡_ → Decidable {A = B} _≡_ → Decidable {A = A × B} _≡_ (dec₁ ×-≟ dec₂) p₁ p₂ = Dec.map′ to-cong from-cong (p₁ ≟ p₂) where open DecSetoid (P.decSetoid dec₁ ×-decSetoid P.decSetoid dec₂) _×-⟶_ : ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈} {A : Setoid s₁ s₂} {B : Setoid s₃ s₄} {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} → A ⟶ B → C ⟶ D → (A ×-setoid C) ⟶ (B ×-setoid D) _×-⟶_ {A = A} {B} {C} {D} f g = record { _⟨$⟩_ = fg ; cong = fg-cong } where open Setoid (A ×-setoid C) using () renaming (_≈_ to _≈AC_) open Setoid (B ×-setoid D) using () renaming (_≈_ to _≈BD_) fg = Prod.map (_⟨$⟩_ f) (_⟨$⟩_ g) fg-cong : _≈AC_ =[ fg ]⇒ _≈BD_ fg-cong (_∼₁_ , _∼₂_) = (F.cong f _∼₁_ , F.cong g _∼₂_) _×-equivalence_ : ∀ {a₁ a₂ b₁ b₂ c₁ c₂ d₁ d₂} {A : Setoid a₁ a₂} {B : Setoid b₁ b₂} {C : Setoid c₁ c₂} {D : Setoid d₁ d₂} → Equivalence A B → Equivalence C D → Equivalence (A ×-setoid C) (B ×-setoid D) _×-equivalence_ {A = A} {B} {C} {D} A⇔B C⇔D = record { to = to A⇔B ×-⟶ to C⇔D ; from = from A⇔B ×-⟶ from C⇔D } where open Equivalence _×-⇔_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → A ⇔ B → C ⇔ D → (A × C) ⇔ (B × D) _×-⇔_ {A = A} {B} {C} {D} A⇔B C⇔D = Inverse.equivalence (×-Rel↔≡ {A = B} {B = D}) ⟨∘⟩ A⇔B ×-equivalence C⇔D ⟨∘⟩ Eq.sym (Inverse.equivalence (×-Rel↔≡ {A = A} {B = C})) where open Eq using () renaming (_∘_ to _⟨∘⟩_) _×-injection_ : ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈} {A : Setoid s₁ s₂} {B : Setoid s₃ s₄} {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} → Injection A B → Injection C D → Injection (A ×-setoid C) (B ×-setoid D) A↣B ×-injection C↣D = record { to = to A↣B ×-⟶ to C↣D ; injective = Prod.map (injective A↣B) (injective C↣D) } where open Injection _×-↣_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → A ↣ B → C ↣ D → (A × C) ↣ (B × D) _×-↣_ {A = A} {B} {C} {D} A↣B C↣D = Inverse.injection (×-Rel↔≡ {A = B} {B = D}) ⟨∘⟩ A↣B ×-injection C↣D ⟨∘⟩ Inverse.injection (Inv.sym (×-Rel↔≡ {A = A} {B = C})) where open Inj using () renaming (_∘_ to _⟨∘⟩_) _×-left-inverse_ : ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈} {A : Setoid s₁ s₂} {B : Setoid s₃ s₄} {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} → LeftInverse A B → LeftInverse C D → LeftInverse (A ×-setoid C) (B ×-setoid D) A↞B ×-left-inverse C↞D = record { to = Equivalence.to eq ; from = Equivalence.from eq ; left-inverse-of = left } where open LeftInverse eq = LeftInverse.equivalence A↞B ×-equivalence LeftInverse.equivalence C↞D left : Equivalence.from eq LeftInverseOf Equivalence.to eq left (x , y) = ( left-inverse-of A↞B x , left-inverse-of C↞D y ) _×-↞_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → A ↞ B → C ↞ D → (A × C) ↞ (B × D) _×-↞_ {A = A} {B} {C} {D} A↞B C↞D = Inverse.left-inverse (×-Rel↔≡ {A = B} {B = D}) ⟨∘⟩ A↞B ×-left-inverse C↞D ⟨∘⟩ Inverse.left-inverse (Inv.sym (×-Rel↔≡ {A = A} {B = C})) where open LeftInv using () renaming (_∘_ to _⟨∘⟩_) _×-surjection_ : ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈} {A : Setoid s₁ s₂} {B : Setoid s₃ s₄} {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} → Surjection A B → Surjection C D → Surjection (A ×-setoid C) (B ×-setoid D) A↠B ×-surjection C↠D = record { to = LeftInverse.from inv ; surjective = record { from = LeftInverse.to inv ; right-inverse-of = LeftInverse.left-inverse-of inv } } where open Surjection inv = right-inverse A↠B ×-left-inverse right-inverse C↠D _×-↠_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → A ↠ B → C ↠ D → (A × C) ↠ (B × D) _×-↠_ {A = A} {B} {C} {D} A↠B C↠D = Inverse.surjection (×-Rel↔≡ {A = B} {B = D}) ⟨∘⟩ A↠B ×-surjection C↠D ⟨∘⟩ Inverse.surjection (Inv.sym (×-Rel↔≡ {A = A} {B = C})) where open Surj using () renaming (_∘_ to _⟨∘⟩_) _×-inverse_ : ∀ {s₁ s₂ s₃ s₄ s₅ s₆ s₇ s₈} {A : Setoid s₁ s₂} {B : Setoid s₃ s₄} {C : Setoid s₅ s₆} {D : Setoid s₇ s₈} → Inverse A B → Inverse C D → Inverse (A ×-setoid C) (B ×-setoid D) A↔B ×-inverse C↔D = record { to = Surjection.to surj ; from = Surjection.from surj ; inverse-of = record { left-inverse-of = LeftInverse.left-inverse-of inv ; right-inverse-of = Surjection.right-inverse-of surj } } where open Inverse surj = Inverse.surjection A↔B ×-surjection Inverse.surjection C↔D inv = Inverse.left-inverse A↔B ×-left-inverse Inverse.left-inverse C↔D _×-↔_ : ∀ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → A ↔ B → C ↔ D → (A × C) ↔ (B × D) _×-↔_ {A = A} {B} {C} {D} A↔B C↔D = ×-Rel↔≡ {A = B} {B = D} ⟨∘⟩ A↔B ×-inverse C↔D ⟨∘⟩ Inv.sym (×-Rel↔≡ {A = A} {B = C}) where open Inv using () renaming (_∘_ to _⟨∘⟩_) _×-cong_ : ∀ {k a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} → A ∼[ k ] B → C ∼[ k ] D → (A × C) ∼[ k ] (B × D) _×-cong_ {implication} = λ f g → Prod.map f g _×-cong_ {reverse-implication} = λ f g → lam (Prod.map (app-← f) (app-← g)) _×-cong_ {equivalence} = _×-⇔_ _×-cong_ {injection} = _×-↣_ _×-cong_ {reverse-injection} = λ f g → lam (app-↢ f ×-↣ app-↢ g) _×-cong_ {left-inverse} = _×-↞_ _×-cong_ {surjection} = _×-↠_ _×-cong_ {bijection} = _×-↔_
36.067442
75
0.52073
9af8479d80397e31cb4f79b27fb73b3e22eee1a0
5,119
agda
Agda
slides/ClosedTheory3.agda
larrytheliquid/generic-elim
832383d7adf37aa2364213fb0aeb67e9f61a248f
[ "MIT" ]
11
2015-06-02T14:05:20.000Z
2021-09-09T08:46:42.000Z
slides/ClosedTheory3.agda
larrytheliquid/generic-elim
832383d7adf37aa2364213fb0aeb67e9f61a248f
[ "MIT" ]
null
null
null
slides/ClosedTheory3.agda
larrytheliquid/generic-elim
832383d7adf37aa2364213fb0aeb67e9f61a248f
[ "MIT" ]
2
2016-05-02T08:56:15.000Z
2022-03-12T11:31:22.000Z
{-# OPTIONS --type-in-type #-} open import Data.Empty open import Data.Unit open import Data.Bool hiding ( T ) open import Data.Product hiding ( curry ; uncurry ) open import Data.Nat open import Data.String open import Relation.Binary.PropositionalEquality using ( refl ; _≢_ ; _≡_ ) open import Function module ClosedTheory3 where ---------------------------------------------------------------------- data Tel : Set₁ where Emp : Tel Ext : (A : Set) (B : A → Tel) → Tel Scope : Tel → Set Scope Emp = ⊤ Scope (Ext A B) = Σ A λ a → Scope (B a) ---------------------------------------------------------------------- UncurriedScope : (T : Tel) (X : Scope T → Set) → Set UncurriedScope T X = (xs : Scope T) → X xs CurriedScope : (T : Tel) (X : Scope T → Set) → Set CurriedScope Emp X = X tt CurriedScope (Ext A B) X = (a : A) → CurriedScope (B a) (λ b → X (a , b)) curryScope : (T : Tel) (X : Scope T → Set) → UncurriedScope T X → CurriedScope T X curryScope Emp X f = f tt curryScope (Ext A B) X f a = curryScope (B a) (λ b → X (a , b)) (λ b → f (a , b)) ICurriedScope : (T : Tel) (X : Scope T → Set) → Set ICurriedScope Emp X = X tt ICurriedScope (Ext A B) X = {a : A} → ICurriedScope (B a) (λ b → X (a , b)) icurryScope : (T : Tel) (X : Scope T → Set) → UncurriedScope T X → ICurriedScope T X icurryScope Emp X f = f tt icurryScope (Ext A B) X f = λ {a} → icurryScope (B a) (λ b → X (a , b)) (λ b → f (a , b)) ---------------------------------------------------------------------- data Desc (I : Set) : Set₁ where End : (i : I) → Desc I Rec : (i : I) (D : Desc I) → Desc I Arg : (A : Set) (B : A → Desc I) → Desc I ISet : Set → Set₁ ISet I = I → Set El : {I : Set} (D : Desc I) → ISet I → ISet I El (End j) X i = j ≡ i El (Rec j D) X i = X j × El D X i El (Arg A B) X i = Σ A (λ a → El (B a) X i) data μ {I : Set} (D : Desc I) (i : I) : Set where init : El D (μ D) i → μ D i ---------------------------------------------------------------------- UncurriedEl : {I : Set} (D : Desc I) (X : ISet I) → Set UncurriedEl D X = ∀{i} → El D X i → X i CurriedEl : {I : Set} (D : Desc I) (X : ISet I) → Set CurriedEl (End i) X = X i CurriedEl (Rec i D) X = (x : X i) → CurriedEl D X CurriedEl (Arg A B) X = (a : A) → CurriedEl (B a) X curryEl : {I : Set} (D : Desc I) (X : ISet I) → UncurriedEl D X → CurriedEl D X curryEl (End i) X cn = cn refl curryEl (Rec i D) X cn = λ x → curryEl D X (λ xs → cn (x , xs)) curryEl (Arg A B) X cn = λ a → curryEl (B a) X (λ xs → cn (a , xs)) ---------------------------------------------------------------------- record Data : Set₁ where field E : Set P : Tel I : Scope P → Tel C : (p : Scope P) (t : E) → Desc (Scope (I p)) ---------------------------------------------------------------------- UncurriedFormer : Set UncurriedFormer = UncurriedScope P λ p → UncurriedScope (I p) λ i → Set FormUncurried : UncurriedFormer FormUncurried p = μ (Arg E (C p)) Former : Set Former = CurriedScope P λ p → CurriedScope (I p) λ i → Set Form : Former Form = curryScope P (λ p → CurriedScope (I p) λ i → Set) λ p → curryScope (I p) (λ i → Set) λ i → FormUncurried p i ---------------------------------------------------------------------- InjUncurried : E → Set InjUncurried t = UncurriedScope P λ p → CurriedEl (C p t ) (FormUncurried p) injUncurried : (t : E) → InjUncurried t injUncurried t p = curryEl (C p t) (FormUncurried p) (λ xs → init (t , xs)) Inj : E → Set Inj t = ICurriedScope P λ p → CurriedEl (C p t) (FormUncurried p) inj : (t : E) → Inj t inj t = icurryScope P (λ p → CurriedEl (C p t) (FormUncurried p)) (injUncurried t) ---------------------------------------------------------------------- open Data using ( Former ; Form ; Inj ; inj ) ---------------------------------------------------------------------- data VecT : Set where nilT consT : VecT VecR : Data VecR = record { E = VecT ; P = Ext Set λ _ → Emp ; I = λ _ → Ext ℕ λ _ → Emp ; C = λ { (A , tt) → λ { nilT → End (zero , tt) ; consT → Arg ℕ λ n → Arg A λ _ → Rec (n , tt) $ End (suc n , tt) } } } Vec : (A : Set) → ℕ → Set Vec = Form VecR nil : {A : Set} → Vec A zero nil = inj VecR nilT cons : {A : Set} (n : ℕ) (x : A) (xs : Vec A n) → Vec A (suc n) cons = inj VecR consT ---------------------------------------------------------------------- data TreeT : Set where leaf₁T leaf₂T branchT : TreeT TreeR : Data TreeR = record { E = TreeT ; P = Ext Set λ _ → Ext Set λ _ → Emp ; I = λ _ → Ext ℕ λ _ → Ext ℕ λ _ → Emp ; C = λ { (A , B , tt) → λ { leaf₁T → Arg A λ _ → End (suc zero , zero , tt) ; leaf₂T → Arg B λ _ → End (zero , suc zero , tt) ; branchT → Arg ℕ λ m → Arg ℕ λ n → Arg ℕ λ x → Arg ℕ λ y → Rec (m , n , tt) $ Rec (x , y , tt) $ End (m + x , n + y , tt) } } } Tree : (A B : Set) (m n : ℕ) → Set Tree = Form TreeR leaf₁ : {A B : Set} → A → Tree A B (suc zero) zero leaf₁ = inj TreeR leaf₁T ----------------------------------------------------------------------
27.972678
89
0.469818
8b826f6a30254f9b2f850215d7f1a5c93a3a03ab
1,296
agda
Agda
src/Dipsy/Struct.agda
wenkokke/Dipsy
06eec3f3325c71c81809ff19dfaf4fd43ba958ed
[ "MIT" ]
1
2020-09-10T13:43:29.000Z
2020-09-10T13:43:29.000Z
src/Dipsy/Struct.agda
wenkokke/dipsy
06eec3f3325c71c81809ff19dfaf4fd43ba958ed
[ "MIT" ]
null
null
null
src/Dipsy/Struct.agda
wenkokke/dipsy
06eec3f3325c71c81809ff19dfaf4fd43ba958ed
[ "MIT" ]
null
null
null
open import Data.Fin using (Fin; suc; zero) open import Data.Nat using (ℕ) open import Data.Vec using (Vec; []; _∷_; map) open import Dipsy.Polarity renaming (pos to +; neg to -) module Dipsy.Struct (FOp : {n : ℕ} (as : Vec Polarity n) (b : Polarity) → Set) (SOp : {n : ℕ} (as : Vec Polarity n) (b : Polarity) → Set) where open import Dipsy.Form FOp mutual data Struct : (b : Polarity) → Set where ·_· : {b : Polarity} → Form → Struct b op : {n : ℕ} {as : Vec Polarity n} {b : Polarity} → SOp as b → Structs as → Struct b data Structs : {n : ℕ} (as : Vec Polarity n) → Set where [] : Structs [] _∷_ : {n : ℕ} {a : Polarity} {as : Vec Polarity n} → Struct a → Structs as → Structs (a ∷ as) mutual data Context : (b c : Polarity) → Set where [] : {b : Polarity} → Context b b op : {n : ℕ} {as : Vec Polarity n} {b c : Polarity} → SOp as c → (i : Fin n) → Contexts as b i → Context b c data Contexts : {n : ℕ} (as : Vec Polarity n) (b : Polarity) (i : Fin n) → Set where _<∷_ : {n : ℕ} {b c : Polarity} {as : Vec Polarity n} → Context b c → Structs as → Contexts (c ∷ as) b zero _∷>_ : {n : ℕ} {a b : Polarity} {as : Vec Polarity n} {i : Fin n} → Struct a → Contexts as b i → Contexts (a ∷ as) b (suc i)
37.028571
86
0.55787
3585f90dcb924c86988d03e1e556a90256e2f891
464
agda
Agda
test/interaction/Issue231.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue231.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue231.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
module Issue231 where postulate A : Set data List : Set where _∷_ : A → List → List data Any : List → Set where there : ∀ {x xs} → Any xs → Any (x ∷ xs) postulate id : (A : Set) → A → A lemma : (xs : List) → Set → (p : Any xs) → Set lemma (x ∷ xs) A (there p) with id (Any xs) p lemma (x ∷ xs) A (there p) | p′ = {!p′!} -- Before case-split: -- lemma (x ∷ xs) A (there p) | p′ = {!p′!} -- After case-split: -- lemma (A ∷ _) _ (there p) | there y = ?
20.173913
46
0.532328
0375b2e0eb5d382a3d8f5598afd8da468a1f4bad
8,910
agda
Agda
Mockingbird/Problems/Chapter18.agda
splintah/combinatory-logic
df8bf877e60b3059532c54a247a36a3d83cd55b0
[ "MIT" ]
1
2022-02-28T23:44:42.000Z
2022-02-28T23:44:42.000Z
Mockingbird/Problems/Chapter18.agda
splintah/combinatory-logic
df8bf877e60b3059532c54a247a36a3d83cd55b0
[ "MIT" ]
null
null
null
Mockingbird/Problems/Chapter18.agda
splintah/combinatory-logic
df8bf877e60b3059532c54a247a36a3d83cd55b0
[ "MIT" ]
null
null
null
open import Mockingbird.Forest using (Forest) import Mockingbird.Forest.Birds as Birds -- The Master Forest module Mockingbird.Problems.Chapter18 {b ℓ} (forest : Forest {b} {ℓ}) ⦃ _ : Birds.HasStarling forest ⦄ ⦃ _ : Birds.HasKestrel forest ⦄ where open import Data.Maybe using (Maybe; nothing; just) open import Data.Product using (_×_; _,_; proj₁; ∃-syntax) open import Data.Vec using (Vec; []; _∷_; _++_) open import Data.Vec.Relation.Unary.Any.Properties using (++⁺ʳ) open import Function using (_$_) open import Level using (_⊔_) open import Mockingbird.Forest.Combination.Vec forest using (⟨_⟩; here; there; [_]; _⟨∙⟩_∣_; _⟨∙⟩_; [#_]) open import Mockingbird.Forest.Combination.Vec.Properties forest using (subst′; weaken-++ˡ; weaken-++ʳ; ++-comm) open import Relation.Unary using (_∈_) open Forest forest open import Mockingbird.Forest.Birds forest problem₁ : HasIdentity problem₁ = record { I = S ∙ K ∙ K ; isIdentity = λ x → begin S ∙ K ∙ K ∙ x ≈⟨ isStarling K K x ⟩ K ∙ x ∙ (K ∙ x) ≈⟨ isKestrel x (K ∙ x) ⟩ x ∎ } private instance hasIdentity = problem₁ problem₂ : HasMockingbird problem₂ = record { M = S ∙ I ∙ I ; isMockingbird = λ x → begin S ∙ I ∙ I ∙ x ≈⟨ isStarling I I x ⟩ I ∙ x ∙ (I ∙ x) ≈⟨ congʳ $ isIdentity x ⟩ x ∙ (I ∙ x) ≈⟨ congˡ $ isIdentity x ⟩ x ∙ x ∎ } private instance hasMockingbird = problem₂ problem₃ : HasThrush problem₃ = record { T = S ∙ (K ∙ (S ∙ I)) ∙ K ; isThrush = λ x y → begin S ∙ (K ∙ (S ∙ I)) ∙ K ∙ x ∙ y ≈⟨ congʳ $ isStarling (K ∙ (S ∙ I)) K x ⟩ K ∙ (S ∙ I) ∙ x ∙ (K ∙ x) ∙ y ≈⟨ (congʳ $ congʳ $ isKestrel (S ∙ I) x) ⟩ S ∙ I ∙ (K ∙ x) ∙ y ≈⟨ isStarling I (K ∙ x) y ⟩ I ∙ y ∙ (K ∙ x ∙ y) ≈⟨ congʳ $ isIdentity y ⟩ y ∙ (K ∙ x ∙ y) ≈⟨ congˡ $ isKestrel x y ⟩ y ∙ x ∎ } -- TODO: Problem 4. I∈⟨S,K⟩ : I ∈ ⟨ S ∷ K ∷ [] ⟩ I∈⟨S,K⟩ = subst′ refl $ [# 0 ] ⟨∙⟩ [# 1 ] ⟨∙⟩ [# 1 ] -- Try to strengthen a proof of X ∈ ⟨ y ∷ xs ⟩ to X ∈ ⟨ xs ⟩, which can be done -- if y does not occur in X. strengthen : ∀ {n X y} {xs : Vec Bird n} → X ∈ ⟨ y ∷ xs ⟩ → Maybe (X ∈ ⟨ xs ⟩) -- NOTE: it could be the case that y ∈ xs, but checking that requires decidable -- equality. strengthen [ here X≈y ] = nothing strengthen [ there X∈xs ] = just [ X∈xs ] strengthen (Y∈⟨y,xs⟩ ⟨∙⟩ Z∈⟨y,xs⟩ ∣ YZ≈X) = do Y∈⟨xs⟩ ← strengthen Y∈⟨y,xs⟩ Z∈⟨xs⟩ ← strengthen Z∈⟨y,xs⟩ just $ Y∈⟨xs⟩ ⟨∙⟩ Z∈⟨xs⟩ ∣ YZ≈X where open import Data.Maybe.Categorical using (monad) open import Category.Monad using (RawMonad) open RawMonad (monad {b ⊔ ℓ}) eliminate : ∀ {n X y} {xs : Vec Bird n} → X ∈ ⟨ y ∷ xs ⟩ → ∃[ X′ ] (X′ ∈ ⟨ S ∷ K ∷ xs ⟩ × X′ ∙ y ≈ X) eliminate {X = X} {y} [ here X≈y ] = (I , weaken-++ˡ I∈⟨S,K⟩ , trans (isIdentity y) (sym X≈y)) eliminate {X = X} {y} [ there X∈xs ] = (K ∙ X , [# 1 ] ⟨∙⟩ [ ++⁺ʳ (S ∷ K ∷ []) X∈xs ] , isKestrel X y) eliminate {X = X} {y} (_⟨∙⟩_∣_ {Y} {Z} Y∈⟨y,xs⟩ [ here Z≈y ] YZ≈X) with strengthen Y∈⟨y,xs⟩ ... | just Y∈⟨xs⟩ = (Y , weaken-++ʳ (S ∷ K ∷ []) Y∈⟨xs⟩ , trans (congˡ (sym Z≈y)) YZ≈X) ... | nothing = let (Y′ , Y′∈⟨S,K,xs⟩ , Y′y≈Y) = eliminate Y∈⟨y,xs⟩ SY′Iy≈X : S ∙ Y′ ∙ I ∙ y ≈ X SY′Iy≈X = begin S ∙ Y′ ∙ I ∙ y ≈⟨ isStarling Y′ I y ⟩ Y′ ∙ y ∙ (I ∙ y) ≈⟨ congʳ $ Y′y≈Y ⟩ Y ∙ (I ∙ y) ≈⟨ congˡ $ isIdentity y ⟩ Y ∙ y ≈˘⟨ congˡ Z≈y ⟩ Y ∙ Z ≈⟨ YZ≈X ⟩ X ∎ in (S ∙ Y′ ∙ I , [# 0 ] ⟨∙⟩ Y′∈⟨S,K,xs⟩ ⟨∙⟩ weaken-++ˡ I∈⟨S,K⟩ , SY′Iy≈X) eliminate {X = X} {y} (_⟨∙⟩_∣_ {Y} {Z} Y∈⟨y,xs⟩ Z∈⟨y,xs⟩ YZ≈X) = let (Y′ , Y′∈⟨S,K,xs⟩ , Y′y≈Y) = eliminate Y∈⟨y,xs⟩ (Z′ , Z′∈⟨S,K,xs⟩ , Z′y≈Z) = eliminate Z∈⟨y,xs⟩ SY′Z′y≈X : S ∙ Y′ ∙ Z′ ∙ y ≈ X SY′Z′y≈X = begin S ∙ Y′ ∙ Z′ ∙ y ≈⟨ isStarling Y′ Z′ y ⟩ Y′ ∙ y ∙ (Z′ ∙ y) ≈⟨ congʳ Y′y≈Y ⟩ Y ∙ (Z′ ∙ y) ≈⟨ congˡ Z′y≈Z ⟩ Y ∙ Z ≈⟨ YZ≈X ⟩ X ∎ in (S ∙ Y′ ∙ Z′ , [# 0 ] ⟨∙⟩ Y′∈⟨S,K,xs⟩ ⟨∙⟩ Z′∈⟨S,K,xs⟩ , SY′Z′y≈X) module _ (x y : Bird) where -- Example: y-eliminating the expression y should give I. _ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 0 ]) ≈ I _ = refl -- Example: y-eliminating the expression x should give Kx. _ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 1 ]) ≈ K ∙ x _ = refl -- Example: y-eliminating the expression xy should give x (Principle 3). _ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 1 ] ⟨∙⟩ [# 0 ]) ≈ x _ = refl -- Example: y-eliminating the expression yx should give SI(Kx). _ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 0 ] ⟨∙⟩ [# 1 ]) ≈ S ∙ I ∙ (K ∙ x) _ = refl -- Example: y-eliminating the expression yy should give SII. _ : proj₁ (eliminate {y = y} {xs = x ∷ []} $ [# 0 ] ⟨∙⟩ [# 0 ]) ≈ S ∙ I ∙ I _ = refl strengthen-SK : ∀ {n X y} {xs : Vec Bird n} → X ∈ ⟨ S ∷ K ∷ y ∷ xs ⟩ → Maybe (X ∈ ⟨ S ∷ K ∷ xs ⟩) strengthen-SK {y = y} {xs} X∈⟨S,K,y,xs⟩ = do let X∈⟨y,xs,S,K⟩ = ++-comm (S ∷ K ∷ []) (y ∷ xs) X∈⟨S,K,y,xs⟩ X∈⟨xs,S,K⟩ ← strengthen X∈⟨y,xs,S,K⟩ let X∈⟨S,K,xs⟩ = ++-comm xs (S ∷ K ∷ []) X∈⟨xs,S,K⟩ just X∈⟨S,K,xs⟩ where open import Data.Maybe.Categorical using (monad) open import Category.Monad using (RawMonad) open RawMonad (monad {b ⊔ ℓ}) -- TODO: formulate eliminate or eliminate-SK in terms of the other. eliminate-SK : ∀ {n X y} {xs : Vec Bird n} → X ∈ ⟨ S ∷ K ∷ y ∷ xs ⟩ → ∃[ X′ ] (X′ ∈ ⟨ S ∷ K ∷ xs ⟩ × X′ ∙ y ≈ X) eliminate-SK {X = X} {y} [ here X≈S ] = (K ∙ S , [# 1 ] ⟨∙⟩ [# 0 ] , trans (isKestrel S y) (sym X≈S)) eliminate-SK {X = X} {y} [ there (here X≈K) ] = (K ∙ K , [# 1 ] ⟨∙⟩ [# 1 ] , trans (isKestrel K y) (sym X≈K)) eliminate-SK {X = X} {y} [ there (there (here X≈y)) ] = (I , weaken-++ˡ I∈⟨S,K⟩ , trans (isIdentity y) (sym X≈y)) eliminate-SK {X = X} {y} [ there (there (there X∈xs)) ] = (K ∙ X , ([# 1 ] ⟨∙⟩ [ (++⁺ʳ (S ∷ K ∷ []) X∈xs) ]) , isKestrel X y) eliminate-SK {X = X} {y} (_⟨∙⟩_∣_ {Y} {Z} Y∈⟨S,K,y,xs⟩ [ there (there (here Z≈y)) ] YZ≈X) with strengthen-SK Y∈⟨S,K,y,xs⟩ ... | just Y∈⟨S,K,xs⟩ = (Y , Y∈⟨S,K,xs⟩ , trans (congˡ (sym Z≈y)) YZ≈X) ... | nothing = let (Y′ , Y′∈⟨S,K,xs⟩ , Y′y≈Y) = eliminate-SK Y∈⟨S,K,y,xs⟩ SY′Iy≈X : S ∙ Y′ ∙ I ∙ y ≈ X SY′Iy≈X = begin S ∙ Y′ ∙ I ∙ y ≈⟨ isStarling Y′ I y ⟩ Y′ ∙ y ∙ (I ∙ y) ≈⟨ congʳ $ Y′y≈Y ⟩ Y ∙ (I ∙ y) ≈⟨ congˡ $ isIdentity y ⟩ Y ∙ y ≈˘⟨ congˡ Z≈y ⟩ Y ∙ Z ≈⟨ YZ≈X ⟩ X ∎ in (S ∙ Y′ ∙ I , [# 0 ] ⟨∙⟩ Y′∈⟨S,K,xs⟩ ⟨∙⟩ weaken-++ˡ I∈⟨S,K⟩ , SY′Iy≈X) eliminate-SK {X = X} {y} (_⟨∙⟩_∣_ {Y} {Z} Y∈⟨S,K,y,xs⟩ Z∈⟨S,K,y,xs⟩ YZ≈X) = let (Y′ , Y′∈⟨S,K,xs⟩ , Y′y≈Y) = eliminate-SK Y∈⟨S,K,y,xs⟩ (Z′ , Z′∈⟨S,K,xs⟩ , Z′y≈Z) = eliminate-SK Z∈⟨S,K,y,xs⟩ SY′Z′y≈X : S ∙ Y′ ∙ Z′ ∙ y ≈ X SY′Z′y≈X = begin S ∙ Y′ ∙ Z′ ∙ y ≈⟨ isStarling Y′ Z′ y ⟩ Y′ ∙ y ∙ (Z′ ∙ y) ≈⟨ congʳ Y′y≈Y ⟩ Y ∙ (Z′ ∙ y) ≈⟨ congˡ Z′y≈Z ⟩ Y ∙ Z ≈⟨ YZ≈X ⟩ X ∎ in (S ∙ Y′ ∙ Z′ , [# 0 ] ⟨∙⟩ Y′∈⟨S,K,xs⟩ ⟨∙⟩ Z′∈⟨S,K,xs⟩ , SY′Z′y≈X) module _ (x y : Bird) where -- Example: y-eliminating the expression y should give I. _ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 2 ]) ≈ I _ = refl -- Example: y-eliminating the expression x should give Kx. _ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 3 ]) ≈ K ∙ x _ = refl -- Example: y-eliminating the expression xy should give x (Principle 3). _ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 3 ] ⟨∙⟩ [# 2 ]) ≈ x _ = refl -- Example: y-eliminating the expression yx should give SI(Kx). _ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 2 ] ⟨∙⟩ [# 3 ]) ≈ S ∙ I ∙ (K ∙ x) _ = refl -- Example: y-eliminating the expression yy should give SII. _ : proj₁ (eliminate-SK {y = y} {xs = x ∷ []} $ [# 2 ] ⟨∙⟩ [# 2 ]) ≈ S ∙ I ∙ I _ = refl infixl 6 _∙ⁿ_ _∙ⁿ_ : ∀ {n} → (A : Bird) (xs : Vec Bird n) → Bird A ∙ⁿ [] = A A ∙ⁿ (x ∷ xs) = A ∙ⁿ xs ∙ x eliminateAll′ : ∀ {n X} {xs : Vec Bird n} → X ∈ ⟨ S ∷ K ∷ xs ⟩ → ∃[ X′ ] (X′ ∈ ⟨ S ∷ K ∷ [] ⟩ × X′ ∙ⁿ xs ≈ X) eliminateAll′ {X = X} {[]} X∈⟨S,K⟩ = (X , X∈⟨S,K⟩ , refl) eliminateAll′ {X = X} {x ∷ xs} X∈⟨S,K,x,xs⟩ = let (X′ , X′∈⟨S,K,xs⟩ , X′x≈X) = eliminate-SK X∈⟨S,K,x,xs⟩ (X″ , X″∈⟨S,K⟩ , X″xs≈X′) = eliminateAll′ X′∈⟨S,K,xs⟩ X″∙ⁿxs∙x≈X : X″ ∙ⁿ xs ∙ x ≈ X X″∙ⁿxs∙x≈X = begin X″ ∙ⁿ xs ∙ x ≈⟨ congʳ X″xs≈X′ ⟩ X′ ∙ x ≈⟨ X′x≈X ⟩ X ∎ in (X″ , X″∈⟨S,K⟩ , X″∙ⁿxs∙x≈X) -- TOOD: can we do this in some way without depending on xs : Vec Bird n? eliminateAll : ∀ {n X} {xs : Vec Bird n} → X ∈ ⟨ xs ⟩ → ∃[ X′ ] (X′ ∈ ⟨ S ∷ K ∷ [] ⟩ × X′ ∙ⁿ xs ≈ X) eliminateAll X∈⟨xs⟩ = eliminateAll′ $ weaken-++ʳ (S ∷ K ∷ []) X∈⟨xs⟩
41.44186
125
0.465881
037aaa3c8f8587edd22bbbd10299cade8bcc7d4c
16,545
agda
Agda
Cubical/Talks/DURG.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/Talks/DURG.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
Cubical/Talks/DURG.agda
Schippmunk/cubical
c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Talks.DURG where open import Cubical.Algebra.Group open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.Equiv open import Cubical.Functions.FunExtEquiv open import Cubical.Data.Sigma open import Cubical.Data.Empty open import Cubical.Data.Unit open import Cubical.Data.Nat open import Cubical.Relation.Binary open import Cubical.DStructures.Base open import Cubical.DStructures.Meta.Properties open import Cubical.DStructures.Meta.Isomorphism open import Cubical.DStructures.Structures.XModule private variable ℓ ℓ' ℓ'' ℓ₁ ℓ₁' ℓ₁'' ℓ₂ ℓA ℓ≅A ℓA' ℓ≅A' ℓB ℓB' ℓ≅B' ℓ≅B ℓC ℓ≅C ℓ≅ᴰ ℓP : Level {- Goals of the project: - define strict 2-groups - define crossed modules - prove their equivalence - do something with the classifying space perspective on groups Problems: - performance - the maps going back and forth were fine, but the identity types stating that these maps are inverse to each other were too complex How did we solve this? - Copatterns - Ulrik's idea: displayed univalent reflexive graphs - Provide a fiberwise characterization of the identity types of a type family to obtain a characterization of the identity types of the total space - Avoid equality on objects in proofs - Modular and abstract -} -- DEFINITION -- - URG structure -- - alternative constructors record URGStr' (A : Type ℓA) (ℓ≅A : Level) : Type (ℓ-max ℓA (ℓ-suc ℓ≅A)) where no-eta-equality constructor urgstr' field _≅_ : Rel A A ℓ≅A ρ : isRefl _≅_ uni : isUnivalent _≅_ ρ -- substituted version record URGStr'' (A : Type ℓA) (ℓ≅A : Level) : Type (ℓ-max ℓA (ℓ-suc ℓ≅A)) where field -- a binary relation _≅_ : A → A → Type ℓ≅A -- a witness of reflexivity ρ : (a : A) → a ≅ a -- these two fields induce a map that turns -- a path into a proof the endpoints are related ≡→≅ : {a a' : A} → a ≡ a' → a ≅ a' ≡→≅ {a} {a'} p = subst (λ z → a ≅ z) p (ρ a) field -- that natural map is a fiberwise equivalence uni : (a a' : A) → isEquiv (≡→≅ {a} {a'}) -- alternatively, we could ask for any fiberwise equivalence uni' = (a a' : A) → (a ≡ a') ≃ (a ≅ a') -- another alternative: all ≅-singletons should be contractible contrRelSingl' = (a : A) → isContr (Σ[ a' ∈ A ] (a ≅ a')) -- We can prove that these are equivalent: -- uni ↔ uni' ↔ contrRelSingl' -- This gives rise to alternative constructors for URGs: make-𝒮' : {A : Type ℓA} {_≅_ : Rel A A ℓ≅A} (ρ : isRefl _≅_) (contrTotal : contrRelSingl _≅_) → URGStr A ℓ≅A make-𝒮' {_≅_ = _≅_} ρ contrTotal = urgstr _≅_ ρ (contrRelSingl→isUnivalent _≅_ ρ contrTotal) -- EXAMPLES -- - groups -- - univalent categories -- - observational equality on ℕ -- - universe -- - identity types -- The SIP for groups produces a URG structure on the type of groups 𝒮-group' : (ℓ : Level) → URGStr (Group {ℓ}) ℓ 𝒮-group' ℓ .URGStr._≅_ = GroupEquiv 𝒮-group' ℓ .URGStr.ρ = idGroupEquiv 𝒮-group' ℓ .URGStr.uni = isUnivalent'→isUnivalent GroupEquiv idGroupEquiv λ G H → invEquiv (GroupPath G H) -- Every univalent Category induces a URG on its type of objects open import Cubical.Categories.Category renaming (isUnivalent to isUnivalentCat) Cat→𝒮 : (𝒞 : Precategory ℓ ℓ') → (uni : isUnivalentCat 𝒞) → URGStr (𝒞 .ob) ℓ' Cat→𝒮 𝒞 uni = urgstr (CatIso {𝒞 = 𝒞}) idCatIso λ x y → isUnivalentCat.univ uni x y -- observational equality on ℕ ℕ-≅ : ℕ → ℕ → Type ℓ-zero ℕ-≅ 0 0 = Unit ℕ-≅ 0 (suc _) = ⊥ ℕ-≅ (suc _) 0 = ⊥ ℕ-≅ (suc n) (suc m) = ℕ-≅ n m -- observational equality on ℕ is a URG 𝒮-Nat' : URGStr ℕ ℓ-zero 𝒮-Nat' = {!!} where import Cubical.DStructures.Structures.Nat using (𝒮-Nat) -- equivalences determine a URG on any universe 𝒮-universe : URGStr (Type ℓ) ℓ 𝒮-universe = make-𝒮 {_≅_ = _≃_} idEquiv λ A → isContrRespectEquiv (Σ-cong-equiv-snd (λ A' → isoToEquiv (equivInv A' A))) (equivContr' A) where module _ (A : Type ℓ) where equivInv : (A' : Type ℓ) → Iso (A ≃ A') (A' ≃ A) Iso.fun (equivInv A') = invEquiv Iso.inv (equivInv A') = invEquiv Iso.leftInv (equivInv A') = λ e → equivEq (invEquiv (invEquiv e)) e (funExt (λ x → refl)) Iso.rightInv (equivInv A') = λ e → equivEq (invEquiv (invEquiv e)) e (funExt (λ x → refl)) equivContr' : isContr (Σ[ A' ∈ Type ℓ ] A' ≃ A) equivContr' = EquivContr A -- trivially, a type is a URGStr with the relation given by its identity types 𝒮-type : (A : Type ℓ) → URGStr A ℓ 𝒮-type A = make-𝒮 {_≅_ = _≡_} (λ _ → refl) isContrSingl -- THEOREM: -- uniqueness of small URGs 𝒮-uniqueness' : (A : Type ℓA) → isContr (URGStr A ℓA) 𝒮-uniqueness' = {!!} where import Cubical.DStructures.Structures.Type using (𝒮-uniqueness) -- DEFINITION -- - displayed URG record URGStrᴰ' {A : Type ℓA} (𝒮-A : URGStr A ℓ≅A) (B : A → Type ℓB) (ℓ≅ᴰ : Level) : Type (ℓ-max (ℓ-max (ℓ-max ℓA ℓB) ℓ≅A) (ℓ-suc ℓ≅ᴰ)) where no-eta-equality constructor urgstrᴰ' open URGStr 𝒮-A field _≅ᴰ⟨_⟩_ : {a a' : A} → B a → a ≅ a' → B a' → Type ℓ≅ᴰ ρᴰ : {a : A} → isRefl _≅ᴰ⟨ ρ a ⟩_ uniᴰ : {a : A} → isUnivalent _≅ᴰ⟨ ρ a ⟩_ ρᴰ -- Of course, this also has the alternative constructor make-𝒮ᴰ -- using that the uniᴰ field follows from uniᴰ' = {a : A} → (b : B a) → isContr (Σ[ b' ∈ B a ] b ≅ᴰ⟨ ρ a ⟩ b') -- EXAMPLE -- - pointedness displayed over the universe 𝒮ᴰ-pointed : {ℓ : Level} → URGStrᴰ (𝒮-universe {ℓ}) (λ A → A) ℓ 𝒮ᴰ-pointed {ℓ} = make-𝒮ᴰ (λ a e b → equivFun e a ≡ b) (λ _ → refl) p where p : (A : Type ℓ) (a : A) → isContr (Σ[ b ∈ A ] a ≡ b) p _ a = isContrSingl a -- THEOREM -- Every DURG on a type family B induces -- a URG on the total space Σ[ a ∈ A ] B a ∫⟨_⟩'_ : {A : Type ℓA} (𝒮-A : URGStr A ℓ≅A) {B : A → Type ℓB} (𝒮ᴰ-B : URGStrᴰ 𝒮-A B ℓ≅B) → URGStr (Σ A B) (ℓ-max ℓ≅A ℓ≅B) ∫⟨_⟩'_ = {!!} {- B ∫ | ↦ A × B A -} -- EXAMPLE -- A characterization of the identity types of pointed types 𝒮-pointed : {ℓ : Level} → URGStr (Σ[ A ∈ Type ℓ ] A) ℓ 𝒮-pointed = ∫⟨ 𝒮-universe ⟩ 𝒮ᴰ-pointed -- EXAMPLE -- - constant DURG -- - URG product -- - URG structure on pairs of groups 𝒮ᴰ-const : {A : Type ℓA} (𝒮-A : URGStr A ℓ≅A) {B : Type ℓB} (𝒮-B : URGStr B ℓ≅B) → URGStrᴰ 𝒮-A (λ _ → B) ℓ≅B 𝒮ᴰ-const {A = A} 𝒮-A {B} 𝒮-B = urgstrᴰ (λ b _ b' → b ≅ b') ρ uni where open URGStr 𝒮-B _×𝒮_ : {A : Type ℓA} (𝒮-A : URGStr A ℓ≅A) {B : Type ℓB} (𝒮-B : URGStr B ℓ≅B) → URGStr (A × B) (ℓ-max ℓ≅A ℓ≅B) _×𝒮_ 𝒮-A 𝒮-B = ∫⟨ 𝒮-A ⟩ (𝒮ᴰ-const 𝒮-A 𝒮-B) {- const B ∫ A, B ↦ | ↦ A × B A -} -- EXAMPLE -- Group Homomorphisms displayed over pairs of groups 𝒮ᴰ-G²\F' : URGStrᴰ (𝒮-group' ℓ ×𝒮 𝒮-group' ℓ') (λ (G , H) → GroupHom G H) (ℓ-max ℓ ℓ') 𝒮ᴰ-G²\F' = make-𝒮ᴰ (λ {(G , H)} {(G' , H')} f (eG , eH) f' → (g : ⟨ G ⟩) → GroupEquiv.eq eH .fst ((f .fun) g) ≡ (f' .fun) (GroupEquiv.eq eG .fst g)) (λ _ _ → refl) λ (G , H) f → isContrRespectEquiv (Σ-cong-equiv-snd (λ f' → isoToEquiv (invIso (GroupMorphismExtIso f f')))) (isContrSingl f) where open GroupHom {- The displayed relation is defined as f ≅⟨ eG , eH ⟩ f = commutativity of f G --------> H | | eG | | eH | | G'--------> H' f' Reflexivity is trivial Univalence follows from contractibility of Σ[ (f' , _) ∈ GroupHom G H ] (f ∼ f') for all (f , _) ∈ GroupHom G H -} {- Overview of Crossed Modules and Strict 2-Groups Definition: Crossed module - group action α of G₀ on H - homomorphism φ : H → G₀ - equivariance condition (g : G₀) → (h : H) → φ (g α h) ≡ g + (φ h) - g - peiffer condition (h h' : ⟨ H ⟩) → (φ h) α h' ≡ h + h' - h Definition: Strict 2-Group - internal category in the category of groups This means - split mono ι with two retractions ι : G₀ ↔ G : σ τ₁ - vertical composition operation which satisfies the interchange law _∘⟨_⟩_ : (g f : G₁) → isComposable g f → G₁ - equivalent to type of vertical compositions on internal reflexive graph: PFG (a b : G₁) → ι(σ b) + a - ι(τ a) - ι(σ b) + b + ι(τ a) ≡ b + a Produce this tree of displayed structures: PFXM PFG VertComp | | / | | / isEquivar isSecRet | | | | B B | | | | isAction isSecRet | | | | LAS F B F×B \ | | / \ | | / \ | / / \ | / / Grp | | Grp use the next result to display propositions like isAction, isEquivariant and isSecRet -} -- THEOREM -- Subtypes have a simple DURG structure given by 𝟙 -- This makes it easy to impose axioms on a structure Subtype→Sub-𝒮ᴰ : {A : Type ℓA} → (P : A → hProp ℓP) → (𝒮-A : URGStr A ℓ≅A) → URGStrᴰ 𝒮-A (λ a → P a .fst) ℓ-zero Subtype→Sub-𝒮ᴰ P 𝒮-A = make-𝒮ᴰ (λ _ _ _ → Unit) (λ _ → tt) (λ a p → isContrRespectEquiv (invEquiv (Σ-contractSnd (λ _ → isContrUnit))) (inhProp→isContr p (P a .snd))) -- EXAMPLE -- isAction axioms on pairs of groups together with a left action structure module _ (ℓ ℓ' : Level) where ℓℓ' = ℓ-max ℓ ℓ' open import Cubical.DStructures.Structures.Action 𝒮ᴰ-G²Las\Action' : URGStrᴰ (𝒮-G²Las ℓ ℓ') (λ ((G , H) , _α_) → IsGroupAction G H _α_) ℓ-zero 𝒮ᴰ-G²Las\Action' = Subtype→Sub-𝒮ᴰ (λ ((G , H) , _α_) → IsGroupAction G H _α_ , isPropIsGroupAction G H _α_) (𝒮-G²Las ℓ ℓ') 𝒮-G²LasAction' : URGStr (Action ℓ ℓ') (ℓ-max ℓ ℓ') 𝒮-G²LasAction' = ∫⟨ 𝒮-G²Las ℓ ℓ' ⟩ 𝒮ᴰ-G²Las\Action' {- -- THEOREM -- DURGs can be lifted to be displayed over the total space of -- another DURG on the same base URG B | B C Lift C \ / ↦ | A A -} VerticalLift-𝒮ᴰ' : {A : Type ℓA} (𝒮-A : URGStr A ℓ≅A) {B : A → Type ℓB} (𝒮ᴰ-B : URGStrᴰ 𝒮-A B ℓ≅B) {C : A → Type ℓC} (𝒮ᴰ-C : URGStrᴰ 𝒮-A C ℓ≅C) → URGStrᴰ (∫⟨ 𝒮-A ⟩ 𝒮ᴰ-C) (λ (a , _) → B a) ℓ≅B VerticalLift-𝒮ᴰ' {ℓ≅B = ℓ≅B} 𝒮-A {B = B} 𝒮ᴰ-B 𝒮ᴰ-C = urgstrᴰ (λ b (pA , _) b' → b ≅ᴰ⟨ pA ⟩ b') ρᴰ uniᴰ where open URGStrᴰ 𝒮ᴰ-B {- -- THEOREM -- A tower of two DURGs can be reassociated C | B split B × C | ↦ | A A (but C depends on B) -} splitTotal-𝒮ᴰ' : {A : Type ℓA} (𝒮-A : URGStr A ℓ≅A) {B : A → Type ℓB} (𝒮ᴰ-B : URGStrᴰ 𝒮-A B ℓ≅B) {C : Σ A B → Type ℓC} (𝒮ᴰ-C : URGStrᴰ (∫⟨ 𝒮-A ⟩ 𝒮ᴰ-B) C ℓ≅C) → URGStrᴰ 𝒮-A (λ a → Σ[ b ∈ B a ] C (a , b)) (ℓ-max ℓ≅B ℓ≅C) splitTotal-𝒮ᴰ' {A = A} 𝒮-A {B} 𝒮ᴰ-B {C} 𝒮ᴰ-C = make-𝒮ᴰ (λ (b , c) eA (b' , c') → Σ[ eB ∈ b B≅ᴰ⟨ eA ⟩ b' ] c ≅ᴰ⟨ eA , eB ⟩ c') (λ (b , c) → Bρᴰ b , ρᴰ c) {!!} where open URGStrᴰ 𝒮ᴰ-C open URGStr 𝒮-A _B≅ᴰ⟨_⟩_ = URGStrᴰ._≅ᴰ⟨_⟩_ 𝒮ᴰ-B Bρᴰ = URGStrᴰ.ρᴰ 𝒮ᴰ-B Buniᴰ = URGStrᴰ.uniᴰ 𝒮ᴰ-B {- -- THEOREM -- two DURGs over the same URGs can be combined B | B C Lift C split B × C \ / ↦ | ↦ | A A A -} combine-𝒮ᴰ' : {A : Type ℓA} {𝒮-A : URGStr A ℓ≅A} {B : A → Type ℓB} {C : A → Type ℓC} (𝒮ᴰ-B : URGStrᴰ 𝒮-A B ℓ≅B) (𝒮ᴰ-C : URGStrᴰ 𝒮-A C ℓ≅C) → URGStrᴰ 𝒮-A (λ a → B a × C a) (ℓ-max ℓ≅B ℓ≅C) combine-𝒮ᴰ' {𝒮-A = 𝒮-A} 𝒮ᴰ-B 𝒮ᴰ-C = splitTotal-𝒮ᴰ 𝒮-A 𝒮ᴰ-B (VerticalLift-𝒮ᴰ 𝒮-A 𝒮ᴰ-C 𝒮ᴰ-B) -- REMARK: DURG is equivalent to URG + morphism of URG via fibrant replacement module _ (C : Type ℓ) where dispTypeIso : Iso (C → Type ℓ) (Σ[ X ∈ Type ℓ ] (X → C)) Iso.fun dispTypeIso D = (Σ[ c ∈ C ] D c) , fst Iso.inv dispTypeIso (X , F) c = Σ[ x ∈ X ] F x ≡ c Iso.leftInv dispTypeIso = {!!} Iso.rightInv dispTypeIso = {!!} -- → combine is pullback in the (∞,1)-topos of DURGs {- With these operations we can construct the entire tree, but how to get equivalences? PFXM PFG VertComp | | / | | / isEquivar isSecRet | | | | B B | | | | isAction isSecRet | | | | LAS F B F×B \ | | / \ | | / \ | / / \ | / / Grp | | Grp -- For URGs: relational isomorphisms -} 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 RelIso→Iso' : {A : Type ℓA} {A' : Type ℓA'} (_≅_ : Rel A A ℓ≅A) (_≅'_ : Rel A' A' ℓ≅A') {ρ : isRefl _≅_} {ρ' : isRefl _≅'_} (uni : isUnivalent _≅_ ρ) (uni' : isUnivalent _≅'_ ρ') (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' f) a' = invEquiv (≡→R _≅'_ ρ' , uni' (RelIso.fun f (RelIso.inv f a')) a') .fst (RelIso.rightInv f a') Iso.leftInv (RelIso→Iso' _≅_ _ {ρ = ρ} uni _ f) a = invEquiv (≡→R _≅_ ρ , uni (RelIso.inv f (RelIso.fun f a)) a) .fst (RelIso.leftInv f a) {- For DURGs: pull back one of the DURGs along an equivalence and show that there is a fiberwise relational isomorphism between B and f*B' B f*B' B' | / | | / | A ≃ A' f -} 𝒮ᴰ-*-Iso-Over→TotalIso : {A : Type ℓA} {𝒮-A : URGStr A ℓ≅A} {A' : Type ℓA'} {𝒮-A' : URGStr A' ℓ≅A'} (ℱ : Iso A A') {B : A → Type ℓB} (𝒮ᴰ-B : URGStrᴰ 𝒮-A B ℓ≅B) {B' : A' → Type ℓB'} (𝒮ᴰ-B' : URGStrᴰ 𝒮-A' B' ℓ≅B') (𝒢 : 𝒮ᴰ-♭PIso (Iso.fun ℱ) 𝒮ᴰ-B 𝒮ᴰ-B') → Iso (Σ A B) (Σ A' B') 𝒮ᴰ-*-Iso-Over→TotalIso ℱ 𝒮ᴰ-B 𝒮ᴰ-B' 𝒢 = RelFiberIsoOver→Iso ℱ (𝒮ᴰ→relFamily 𝒮ᴰ-B) (𝒮ᴰ-B .uniᴰ) (𝒮ᴰ→relFamily 𝒮ᴰ-B') (𝒮ᴰ-B' .uniᴰ) 𝒢 where open URGStrᴰ {- Let's apply this machinery to our tower of DURGs. -} import Cubical.DStructures.Equivalences.GroupSplitEpiAction import Cubical.DStructures.Equivalences.PreXModReflGraph import Cubical.DStructures.Equivalences.XModPeifferGraph import Cubical.DStructures.Equivalences.PeifferGraphS2G {- DISCUSSION - alternate definition of URGs - how to layer the cake - uniformity, abstraction, no equality on objects, results transferrable across proof assistants and type theories - unlike displayed categories not limited to 1-truncated types and type families - easy to set up - associates the other way compared to SNS - every SNS gives DURG on the URG of the universe (not implemented) OTHER THINGS WE DID - Define (n,k)-groups - Display homomorphisms of (n,k)-groups over pairs of such groups - prove the equivalence of (0,1)-groups and axiomatic groups via EM-spaces FUTURE WORK - construct more operations - use reflection to automate steps - construct URG on the type of URG or even DURG structures - meta-theory - model of type theory - more higher group theory ... -}
28.476764
120
0.528256
7cb5cbf23b422e98deadd44ad5eecec7582d3d25
8,465
agda
Agda
Cubical/Data/Nat/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
1
2021-10-31T17:32:49.000Z
2021-10-31T17:32:49.000Z
Cubical/Data/Nat/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
Cubical/Data/Nat/Properties.agda
guilhermehas/cubical
ce3120d3f8d692847b2744162bcd7a01f0b687eb
[ "MIT" ]
null
null
null
{-# OPTIONS --no-exact-split --safe #-} module Cubical.Data.Nat.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.Transport open import Cubical.Data.Nat.Base open import Cubical.Data.Empty as ⊥ open import Cubical.Data.Sigma open import Cubical.Data.Sum.Base open import Cubical.Relation.Nullary open import Cubical.Relation.Nullary.DecidableEq private variable l m n : ℕ min : ℕ → ℕ → ℕ min zero m = zero min (suc n) zero = zero min (suc n) (suc m) = suc (min n m) minComm : (n m : ℕ) → min n m ≡ min m n minComm zero zero = refl minComm zero (suc m) = refl minComm (suc n) zero = refl minComm (suc n) (suc m) = cong suc (minComm n m) max : ℕ → ℕ → ℕ max zero m = m max (suc n) zero = suc n max (suc n) (suc m) = suc (max n m) maxComm : (n m : ℕ) → max n m ≡ max m n maxComm zero zero = refl maxComm zero (suc m) = refl maxComm (suc n) zero = refl maxComm (suc n) (suc m) = cong suc (maxComm n m) znots : ¬ (0 ≡ suc n) znots eq = subst (caseNat ℕ ⊥) eq 0 snotz : ¬ (suc n ≡ 0) snotz eq = subst (caseNat ⊥ ℕ) eq 0 injSuc : suc m ≡ suc n → m ≡ n injSuc p = cong predℕ p -- encode decode caracterisation of equality codeℕ : (n m : ℕ) → Type ℓ-zero codeℕ zero zero = Unit codeℕ zero (suc m) = ⊥ codeℕ (suc n) zero = ⊥ codeℕ (suc n) (suc m) = codeℕ n m encodeℕ : (n m : ℕ) → (n ≡ m) → codeℕ n m encodeℕ n m p = subst (λ m → codeℕ n m) p (reflCode n) where reflCode : (n : ℕ) → codeℕ n n reflCode zero = tt reflCode (suc n) = reflCode n compute-eqℕ : (n m : ℕ) → (n ≡ m ) → codeℕ n m compute-eqℕ zero zero p = tt compute-eqℕ zero (suc m) p = znots p compute-eqℕ (suc n) zero p = snotz p compute-eqℕ (suc n) (suc m) p = compute-eqℕ n m (injSuc p) decodeℕ : (n m : ℕ) → codeℕ n m → (n ≡ m) decodeℕ zero zero = λ _ → refl decodeℕ zero (suc m) = ⊥.rec decodeℕ (suc n) zero = ⊥.rec decodeℕ (suc n) (suc m) = λ r → cong suc (decodeℕ n m r) ≡ℕ≃Codeℕ : (n m : ℕ) → (n ≡ m) ≃ codeℕ n m ≡ℕ≃Codeℕ n m = isoToEquiv is where is : Iso (n ≡ m) (codeℕ n m) Iso.fun is = encodeℕ n m Iso.inv is = decodeℕ n m Iso.rightInv is = sect n m where sect : (n m : ℕ) → (r : codeℕ n m) → (encodeℕ n m (decodeℕ n m r) ≡ r) sect zero zero tt = refl sect zero (suc m) r = ⊥.rec r sect (suc n) zero r = ⊥.rec r sect (suc n) (suc m) r = sect n m r Iso.leftInv is = retr n m where reflRetr : (n : ℕ) → decodeℕ n n (encodeℕ n n refl) ≡ refl reflRetr zero = refl reflRetr (suc n) i = cong suc (reflRetr n i) retr : (n m : ℕ) → (p : n ≡ m) → (decodeℕ n m (encodeℕ n m p) ≡ p) retr n m p = J (λ m p → decodeℕ n m (encodeℕ n m p) ≡ p) (reflRetr n) p ≡ℕ≃Codeℕ' : (n m : ℕ) → (n ≡ m) ≃ codeℕ n m ≡ℕ≃Codeℕ' n m = isoToEquiv is where is : Iso (n ≡ m) (codeℕ n m) Iso.fun is = compute-eqℕ n m Iso.inv is = decodeℕ n m Iso.rightInv is = sect n m where sect : (n m : ℕ) → (r : codeℕ n m) → compute-eqℕ n m (decodeℕ n m r) ≡ r sect zero zero tt = refl sect (suc n) (suc m) r = sect n m r Iso.leftInv is = retr n m where reflRetr : (n : ℕ) → decodeℕ n n (compute-eqℕ n n refl) ≡ refl reflRetr zero = refl reflRetr (suc n) i = cong suc (reflRetr n i) retr : (n m : ℕ) → (p : n ≡ m) → decodeℕ n m (compute-eqℕ n m p) ≡ p retr n m p = J (λ m p → decodeℕ n m (compute-eqℕ n m p) ≡ p) (reflRetr n) p discreteℕ : Discrete ℕ discreteℕ zero zero = yes refl discreteℕ zero (suc n) = no znots discreteℕ (suc m) zero = no snotz discreteℕ (suc m) (suc n) with discreteℕ m n ... | yes p = yes (cong suc p) ... | no p = no (λ x → p (injSuc x)) isSetℕ : isSet ℕ isSetℕ = Discrete→isSet discreteℕ -- Arithmetic facts about predℕ suc-predℕ : ∀ n → ¬ n ≡ 0 → n ≡ suc (predℕ n) suc-predℕ zero p = ⊥.rec (p refl) suc-predℕ (suc n) p = refl -- Arithmetic facts about + +-zero : ∀ m → m + 0 ≡ m +-zero zero = refl +-zero (suc m) = cong suc (+-zero m) +-suc : ∀ m n → m + suc n ≡ suc (m + n) +-suc zero n = refl +-suc (suc m) n = cong suc (+-suc m n) +-comm : ∀ m n → m + n ≡ n + m +-comm m zero = +-zero m +-comm m (suc n) = (+-suc m n) ∙ (cong suc (+-comm m n)) -- Addition is associative +-assoc : ∀ m n o → m + (n + o) ≡ (m + n) + o +-assoc zero _ _ = refl +-assoc (suc m) n o = cong suc (+-assoc m n o) inj-m+ : m + l ≡ m + n → l ≡ n inj-m+ {zero} p = p inj-m+ {suc m} p = inj-m+ (injSuc p) inj-+m : l + m ≡ n + m → l ≡ n inj-+m {l} {m} {n} p = inj-m+ ((+-comm m l) ∙ (p ∙ (+-comm n m))) m+n≡n→m≡0 : m + n ≡ n → m ≡ 0 m+n≡n→m≡0 {n = zero} = λ p → (sym (+-zero _)) ∙ p m+n≡n→m≡0 {n = suc n} p = m+n≡n→m≡0 (injSuc ((sym (+-suc _ n)) ∙ p)) m+n≡0→m≡0×n≡0 : m + n ≡ 0 → (m ≡ 0) × (n ≡ 0) m+n≡0→m≡0×n≡0 {zero} = refl ,_ m+n≡0→m≡0×n≡0 {suc m} p = ⊥.rec (snotz p) -- Arithmetic facts about · 0≡m·0 : ∀ m → 0 ≡ m · 0 0≡m·0 zero = refl 0≡m·0 (suc m) = 0≡m·0 m ·-suc : ∀ m n → m · suc n ≡ m + m · n ·-suc zero n = refl ·-suc (suc m) n = cong suc ( n + m · suc n ≡⟨ cong (n +_) (·-suc m n) ⟩ n + (m + m · n) ≡⟨ +-assoc n m (m · n) ⟩ (n + m) + m · n ≡⟨ cong (_+ m · n) (+-comm n m) ⟩ (m + n) + m · n ≡⟨ sym (+-assoc m n (m · n)) ⟩ m + (n + m · n) ∎ ) ·-comm : ∀ m n → m · n ≡ n · m ·-comm zero n = 0≡m·0 n ·-comm (suc m) n = cong (n +_) (·-comm m n) ∙ sym (·-suc n m) ·-distribʳ : ∀ m n o → (m · o) + (n · o) ≡ (m + n) · o ·-distribʳ zero _ _ = refl ·-distribʳ (suc m) n o = sym (+-assoc o (m · o) (n · o)) ∙ cong (o +_) (·-distribʳ m n o) ·-distribˡ : ∀ o m n → (o · m) + (o · n) ≡ o · (m + n) ·-distribˡ o m n = (λ i → ·-comm o m i + ·-comm o n i) ∙ ·-distribʳ m n o ∙ ·-comm (m + n) o ·-assoc : ∀ m n o → m · (n · o) ≡ (m · n) · o ·-assoc zero _ _ = refl ·-assoc (suc m) n o = cong (n · o +_) (·-assoc m n o) ∙ ·-distribʳ n (m · n) o ·-identityˡ : ∀ m → 1 · m ≡ m ·-identityˡ m = +-zero m ·-identityʳ : ∀ m → m · 1 ≡ m ·-identityʳ zero = refl ·-identityʳ (suc m) = cong suc (·-identityʳ m) 0≡n·sm→0≡n : 0 ≡ n · suc m → 0 ≡ n 0≡n·sm→0≡n {n = zero} p = refl 0≡n·sm→0≡n {n = suc n} p = ⊥.rec (znots p) inj-·sm : l · suc m ≡ n · suc m → l ≡ n inj-·sm {zero} {m} {n} p = 0≡n·sm→0≡n p inj-·sm {l} {m} {zero} p = sym (0≡n·sm→0≡n (sym p)) inj-·sm {suc l} {m} {suc n} p = cong suc (inj-·sm (inj-m+ {m = suc m} p)) inj-sm· : suc m · l ≡ suc m · n → l ≡ n inj-sm· {m} {l} {n} p = inj-·sm (·-comm l (suc m) ∙ p ∙ ·-comm (suc m) n) integral-domain-· : {k l : ℕ} → (k ≡ 0 → ⊥) → (l ≡ 0 → ⊥) → (k · l ≡ 0 → ⊥) integral-domain-· {zero} {l} ¬p ¬q r = ¬p refl integral-domain-· {suc k} {zero} ¬p ¬q r = ¬q refl integral-domain-· {suc k} {suc l} ¬p ¬q r = snotz r -- Arithmetic facts about ∸ zero∸ : ∀ n → zero ∸ n ≡ zero zero∸ zero = refl zero∸ (suc _) = refl n∸n : (n : ℕ) → n ∸ n ≡ 0 n∸n zero = refl n∸n (suc n) = n∸n n ∸-cancelˡ : ∀ k m n → (k + m) ∸ (k + n) ≡ m ∸ n ∸-cancelˡ zero = λ _ _ → refl ∸-cancelˡ (suc k) = ∸-cancelˡ k +∸ : ∀ k n → (k + n) ∸ n ≡ k +∸ zero n = n∸n n +∸ (suc k) zero = cong suc (+-comm k zero) +∸ (suc k) (suc n) = cong (_∸ n) (+-suc k n) ∙ +∸ (suc k) n ∸-cancelʳ : ∀ m n k → (m + k) ∸ (n + k) ≡ m ∸ n ∸-cancelʳ m n k = (λ i → +-comm m k i ∸ +-comm n k i) ∙ ∸-cancelˡ k m n ∸-distribʳ : ∀ m n k → (m ∸ n) · k ≡ m · k ∸ n · k ∸-distribʳ m zero k = refl ∸-distribʳ zero (suc n) k = sym (zero∸ (k + n · k)) ∸-distribʳ (suc m) (suc n) k = ∸-distribʳ m n k ∙ sym (∸-cancelˡ k (m · k) (n · k)) -- factorial: _! : ℕ → ℕ zero ! = 1 suc n ! = (suc n) · (n !) --binomial coefficient: _choose_ : ℕ → ℕ → ℕ n choose zero = 1 zero choose suc k = 0 suc n choose suc k = n choose (suc k) + n choose k evenOrOdd : (n : ℕ) → isEvenT n ⊎ isOddT n evenOrOdd zero = inl tt evenOrOdd (suc zero) = inr tt evenOrOdd (suc (suc n)) = evenOrOdd n ¬evenAndOdd : (n : ℕ) → ¬ isEvenT n × isOddT n ¬evenAndOdd zero (p , ()) ¬evenAndOdd (suc zero) () ¬evenAndOdd (suc (suc n)) = ¬evenAndOdd n isPropIsEvenT : (n : ℕ) → isProp (isEvenT n) isPropIsEvenT zero x y = refl isPropIsEvenT (suc zero) = isProp⊥ isPropIsEvenT (suc (suc n)) = isPropIsEvenT n isPropIsOddT : (n : ℕ) → isProp (isOddT n) isPropIsOddT n = isPropIsEvenT (suc n) isPropEvenOrOdd : (n : ℕ) → isProp (isEvenT n ⊎ isOddT n) isPropEvenOrOdd n (inl x) (inl x₁) = cong inl (isPropIsEvenT n x x₁) isPropEvenOrOdd n (inl x) (inr x₁) = ⊥.rec (¬evenAndOdd n (x , x₁)) isPropEvenOrOdd n (inr x) (inl x₁) = ⊥.rec (¬evenAndOdd (suc n) (x , x₁)) isPropEvenOrOdd n (inr x) (inr x₁) = cong inr (isPropIsEvenT (suc n) x x₁)
28.792517
92
0.550975
34131a0157ba9f9bf0d40e573e4724171a89f11b
499
agda
Agda
Function/Surjective/Base.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Function/Surjective/Base.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Function/Surjective/Base.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --cubical --safe #-} module Function.Surjective.Base where open import Path open import Function.Fiber open import Level open import HITs.PropositionalTruncation open import Data.Sigma Surjective : (A → B) → Type _ Surjective f = ∀ y → ∥ fiber f y ∥ SplitSurjective : (A → B) → Type _ SplitSurjective f = ∀ y → fiber f y infixr 0 _↠!_ _↠_ _↠!_ : Type a → Type b → Type (a ℓ⊔ b) A ↠! B = Σ (A → B) SplitSurjective _↠_ : Type a → Type b → Type (a ℓ⊔ b) A ↠ B = Σ (A → B) Surjective
20.791667
40
0.651303
1b12436b6a243356a7c3df052e83668bb7599ee6
5,610
agda
Agda
nicolai/anonymousExistence/library/NType2.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
1
2021-06-30T00:17:55.000Z
2021-06-30T00:17:55.000Z
nicolai/anonymousExistence/library/NType2.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
null
null
null
nicolai/anonymousExistence/library/NType2.agda
nicolaikraus/HoTT-Agda
939a2d83e090fcc924f69f7dfa5b65b3b79fe633
[ "MIT" ]
null
null
null
{-# OPTIONS --without-K #-} open import library.Basics open import library.Equivalences2 open import library.types.Paths open import library.types.Pi open import library.types.Sigma open import library.types.TLevel module library.NType2 where module _ {i j} {A : Type i} {B : A → Type j} where abstract =-[-↓-]-level : {a b : A} {p : a == b} {u : B a} {v : B b} {n : ℕ₋₂} → ((x : A) → has-level (S n) (B x)) → has-level n (u == v [ B ↓ p ]) =-[-↓-]-level {p = idp} k = k _ _ _ ↓-preserves-level : {a b : A} {p : a == b} {u : B a} {v : B b} (n : ℕ₋₂) → ((x : A) → has-level n (B x)) → has-level n (u == v [ B ↓ p ]) ↓-preserves-level {p = idp} n k = =-preserves-level n (k _) prop-has-all-paths-↓ : {x y : A} {p : x == y} {u : B x} {v : B y} → (is-prop (B y) → u == v [ B ↓ p ]) prop-has-all-paths-↓ {p = idp} k = prop-has-all-paths k _ _ set-↓-has-all-paths-↓ : ∀ {k} {C : Type k} {x y : C → A} {p : (t : C) → x t == y t} {u : (t : C) → B (x t)} {v : (t : C) → B (y t)} {a b : C} {q : a == b} {α : u a == v a [ B ↓ p a ]} {β : u b == v b [ B ↓ p b ]} → (is-set (B (y a)) → α == β [ (λ t → u t == v t [ B ↓ p t ]) ↓ q ]) set-↓-has-all-paths-↓ {q = idp} = lemma _ where lemma : {x y : A} (p : x == y) {u : B x} {v : B y} {α β : u == v [ B ↓ p ]} → is-set (B y) → α == β lemma idp k = fst (k _ _ _ _) abstract -- Every map between contractible types is an equivalence contr-to-contr-is-equiv : ∀ {i j} {A : Type i} {B : Type j} (f : A → B) → (is-contr A → is-contr B → is-equiv f) contr-to-contr-is-equiv f cA cB = is-eq f (λ _ → fst cA) (λ b → ! (snd cB _) ∙ snd cB b) (snd cA) is-contr-is-prop : ∀ {i} {A : Type i} → is-prop (is-contr A) is-contr-is-prop {A = A} = all-paths-is-prop (λ x y → pair= (snd x (fst y)) (↓-cst→app-in (λ a → ↓-idf=cst-in (lemma x (fst y) a (snd y a))))) where lemma : (x : is-contr A) (b a : A) (p : b == a) → snd x a == snd x b ∙' p lemma x b ._ idp = idp has-level-is-prop : ∀ {i} {n : ℕ₋₂} {A : Type i} → is-prop (has-level n A) has-level-is-prop {n = ⟨-2⟩} = is-contr-is-prop has-level-is-prop {n = S n} = Π-level (λ x → Π-level (λ y → has-level-is-prop)) is-prop-is-prop : ∀ {i} {A : Type i} → is-prop (is-prop A) is-prop-is-prop = has-level-is-prop is-set-is-prop : ∀ {i} {A : Type i} → is-prop (is-set A) is-set-is-prop = has-level-is-prop subtype-level : ∀ {i j} {n : ℕ₋₂} {A : Type i} {P : A → Type j} → (has-level (S n) A → ((x : A) → is-prop (P x)) → has-level (S n) (Σ A P)) subtype-level p q = Σ-level p (λ x → prop-has-level-S (q x)) -- Type of all n-truncated types _-Type_ : (n : ℕ₋₂) (i : ULevel) → Type (lsucc i) n -Type i = Σ (Type i) (has-level n) hProp : (i : ULevel) → Type (lsucc i) hProp i = ⟨-1⟩ -Type i hSet : (i : ULevel) → Type (lsucc i) hSet i = ⟨0⟩ -Type i _-Type₀ : (n : ℕ₋₂) → Type₁ n -Type₀ = n -Type lzero hProp₀ = hProp lzero hSet₀ = hSet lzero -- [n -Type] is an (n+1)-type abstract ≃-level : ∀ {i j} {n : ℕ₋₂} {A : Type i} {B : Type j} → (has-level n A → has-level n B → has-level n (A ≃ B)) ≃-level {n = ⟨-2⟩} pA pB = ((cst (fst pB) , contr-to-contr-is-equiv _ pA pB) , (λ e → pair= (λ= (λ _ → snd pB _)) (from-transp is-equiv _ (fst (is-equiv-is-prop _ _ _))))) ≃-level {n = S n} pA pB = Σ-level (→-level pB) (λ _ → prop-has-level-S (is-equiv-is-prop _)) ≃-is-set : ∀ {i j} {A : Type i} {B : Type j} → is-set A → is-set B → is-set (A ≃ B) ≃-is-set = ≃-level universe-=-level : ∀ {i} {n : ℕ₋₂} {A B : Type i} → (has-level n A → has-level n B → has-level n (A == B)) universe-=-level pA pB = equiv-preserves-level ua-equiv (≃-level pA pB) universe-=-is-set : ∀ {i} {A B : Type i} → (is-set A → is-set B → is-set (A == B)) universe-=-is-set = universe-=-level nType= : ∀ {i} {n : ℕ₋₂} (A B : n -Type i) → Type (lsucc i) nType= (A , _) (B , _) = A == B nType=-in : ∀ {i} {n : ℕ₋₂} {A B : n -Type i} → fst A == fst B → A == B nType=-in idp = pair= idp (fst (has-level-is-prop _ _)) nType=-β : ∀ {i} {n : ℕ₋₂} {A B : n -Type i} (p : fst A == fst B) → fst= (nType=-in {A = A} {B = B} p) == p nType=-β idp = fst=-β idp _ nType=-η : ∀ {i} {n : ℕ₋₂} {A B : n -Type i} (p : A == B) → nType=-in (fst= p) == p nType=-η {A = A} {B = .A} idp = ap (pair= idp) (ap fst {x = has-level-is-prop _ _} {y = (idp , (λ p → fst (prop-is-set has-level-is-prop _ _ _ _)))} (fst (is-contr-is-prop _ _))) nType=-equiv : ∀ {i} {n : ℕ₋₂} (A B : n -Type i) → (nType= A B) ≃ (A == B) nType=-equiv A B = equiv nType=-in fst= nType=-η nType=-β _-Type-level_ : (n : ℕ₋₂) (i : ULevel) → has-level (S n) (n -Type i) (n -Type-level i) A B = equiv-preserves-level (nType=-equiv A B) (universe-=-level (snd A) (snd B)) hProp-is-set : (i : ULevel) → is-set (hProp i) hProp-is-set i = ⟨-1⟩ -Type-level i hSet-level : (i : ULevel) → has-level ⟨1⟩ (hSet i) hSet-level i = ⟨0⟩ -Type-level i {- The following two lemmas are in NType2 instead of NType because of cyclic dependencies -} module _ {i} {A : Type i} where abstract raise-level-<T : {m n : ℕ₋₂} → (m <T n) → has-level m A → has-level n A raise-level-<T ltS = raise-level _ raise-level-<T (ltSR lt) = raise-level _ ∘ raise-level-<T lt raise-level-≤T : {m n : ℕ₋₂} → (m ≤T n) → has-level m A → has-level n A raise-level-≤T (inl p) = transport (λ t → has-level t A) p raise-level-≤T (inr lt) = raise-level-<T lt
36.193548
94
0.500535
7c4c7e6c9eee6d7cd429a79ebc75d38bbb785715
1,222
agda
Agda
test/Succeed/Bush.agda
redfish64/autonomic-agda
c0ae7d20728b15d7da4efff6ffadae6fe4590016
[ "BSD-3-Clause" ]
1
2018-10-10T17:08:44.000Z
2018-10-10T17:08:44.000Z
test/succeed/Bush.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
null
null
null
test/succeed/Bush.agda
masondesu/agda
70c8a575c46f6a568c7518150a1a64fcd03aa437
[ "MIT" ]
1
2022-03-12T11:35:18.000Z
2022-03-12T11:35:18.000Z
module Bush where data Nat : Set where zero : Nat suc : Nat -> Nat {-# BUILTIN NATURAL Nat #-} _+_ : Nat -> Nat -> Nat zero + m = m suc n + m = suc (n + m) _^_ : (Set -> Set) -> Nat -> Set -> Set (F ^ zero) A = A (F ^ suc n) A = F ((F ^ n) A) data Bush (A : Set) : Set where leaf : Bush A node : A -> (Bush ^ 3) A -> Bush A elim : (P : (A : Set) -> Bush A -> Set) -> ((A : Set) -> P A leaf) -> ((A : Set)(x : A)(b : (Bush ^ 3) A) -> P ((Bush ^ 2) A) b -> P A (node x b)) -> (A : Set)(b : Bush A) -> P A b elim P l n A leaf = l A elim P l n A (node x b) = n A x b (elim P l n ((Bush ^ 2) A) b) iter : (P : (A : Set) -> Set) -> ((A : Set) -> P A) -> ((A : Set) -> A -> P ((Bush ^ 2) A) -> P A) -> (A : Set) -> Bush A -> P A iter P l n A leaf = l A iter P l n A (node x b) = n A x (iter P l n ((Bush ^ 2) A) b) data List (A : Set) : Set where [] : List A _::_ : A -> List A -> List A _++_ : {A : Set} -> List A -> List A -> List A [] ++ ys = ys (x :: xs) ++ ys = x :: (xs ++ ys) flatten : {A : Set}(n : Nat) -> (Bush ^ n) A -> List A flatten zero x = x :: [] flatten (suc n) leaf = [] flatten (suc n) (node x b) = flatten n x ++ flatten (3 + n) b
23.960784
63
0.437807
3080b7912925d0a54685396f7e5c32eac3e603b9
3,420
agda
Agda
test/Succeed/Issue2644.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/Succeed/Issue2644.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/Succeed/Issue2644.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
-- Andreas, 2017-07-29, issue #2644 reported by Christian Sattler -- -- Silly mistake in expandRecordVar: -- Substitution applied to ListTel instead of Telescope. -- (Messed up the de Bruijn indices, garbage.) -- This file should pass with lots of yellow. {-# OPTIONS --allow-unsolved-metas #-} -- {-# OPTIONS -v tc.meta.assign.proj:45 #-} -- OLD: -- {-# OPTIONS -v tc.cc:20 #-} -- {-# OPTIONS -v tc.lhs:10 #-} -- {-# OPTIONS -v tc.decl:10 #-} -- {-# OPTIONS -v tc.ip:20 #-} -- {-# OPTIONS -v tc.check.internal:20 #-} -- {-# OPTIONS -v tc.meta.check:30 #-} -- {-# OPTIONS -v tc:20 #-} -- {-# OPTIONS -v tc.meta:50 #-} -- {-# OPTIONS -v tc:45 #-} -- {-# OPTIONS -v tc.term.exlam:100 -v tc:90 #-} record Σ (A¹ : Set) (B¹ : A¹ → Set) : Set where constructor pair field fst : A¹ snd : B¹ fst open Σ postulate Path : (A² : Set) → A² → A² → Set path : (A³ : Set) → Path _ _ _ record S : Set₁ where constructor mkS field Aₛ : Set Bₛ : (aₛ¹ : Aₛ) → Set zₛ : (aₛ² : Aₛ) → Bₛ aₛ² record T : Set₁ where constructor mkT field A : Set B : (a¹ : A) → Set z : (a² : A) → B a² s : (a³ : A) → B a³ → B a³ p : (a⁴ : A) (f : B a⁴) → Path _ f (s _ (z _)) -- passes without the matching f₀ : S → T f₀ X = record { A = Σ _ _ ; B = λ b → Σ _ _ -- λ { (b₁ , b₂) → Σ _ _ } ; z = λ z₁ → pair (S.zₛ X _) _ ; s = λ s₁ s₂ → _ ; p = λ p₁ p₂ → path _ } -- This was my final variant module Final where mutual TA : S → Set TA Z = Σ _ _ aux : (Y : S) → TA Y → Set aux Y (pair b¹ b²) = Σ _ _ -- fails fₐ : S → T fₐ X = record { A = TA X ; B = aux X ; z = λ (z¹ : TA X) → pair (S.zₛ X _) _ ; s = λ (s¹ : TA X) (s² : aux X s¹) → _ ; p = λ (p¹ : TA X) (p² : aux X p¹) → path _ } -- Intermediate fₐᵤ : S → T fₐᵤ X = record { A = TA ; B = aux ; z = λ (z₁ : TA) → pair (S.zₛ X _) _ ; s = λ (s₁ : TA) (s₂ : aux s₁) → _ ; p = λ (p₁ : TA) (p₂ : aux p₁) → path _ } where TA = Σ _ _ aux : TA → Set -- (passes without the matching) -- aux b = let b₁ = fst b; b₂ = snd b in {! Σ _ _ !} -- worked aux (pair b₁ b₂) = Σ _ _ -- failed -- Close to original f : S → T f X = record { A = Σ _ _ ; B = λ { (pair b₁ b₂) → Σ _ _ } ; z = λ z₁ → pair (S.zₛ X _) _ ; s = λ s₁ s₂ → _ ; p = λ p₁ p₂ → path _ } {- Hunted down the crash cause: context before projection expansion (X : S) (p¹ : TA X) (p² : aux X p¹) meta args: [X, p¹, pair (S.zₛ X (_aₛ²_34 X p¹)) (?1 X p¹)] trying to expand projected variable X eta-expanding var X in terms ([X, p¹, pair (S.zₛ X (_aₛ²_34 X p¹)) (?1 X p¹)],_8 (?2 X p¹ p²)) meta args: [mkS Aₛ(X) Bₛ(X) zₛ(X), p¹, pair (zₛ(X) (_aₛ²_34 (mkS Aₛ(X) Bₛ(X) zₛ(X)) p¹)) (?1 (mkS Aₛ(X) Bₛ(X) zₛ(X)) p¹)] context before projection expansion (X : S) S (p¹ : TA X) TA 0 (p² : aux X p¹) aux 1 0 context after projection expansion (Aₛ(X) : Set) (Bₛ(X) : Aₛ(X) → Set) (zₛ(X) : (aₛ² : Aₛ(X)) → Bₛ(X) aₛ²) (p¹ : TA (mkS Aₛ(X) Bₛ(X) zₛ(X))) -- This type is fine (p² : aux Aₛ(X) (mkS Bₛ(X) zₛ(X) p¹)) -- This type is messed up! -} -- -} -- -} -- -} -- -} -- -}
25.333333
90
0.469006
5e1a1ac3f29b9b5db674bddadcd8f4e41ef3f41d
172
agda
Agda
test/interaction/Issue3072.agda
mdimjasevic/agda
8fb548356b275c7a1e79b768b64511ae937c738b
[ "BSD-3-Clause" ]
1,989
2015-01-09T23:51:16.000Z
2022-03-30T18:20:48.000Z
test/interaction/Issue3072.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
4,066
2015-01-10T11:24:51.000Z
2022-03-31T21:14:49.000Z
test/interaction/Issue3072.agda
Seanpm2001-languages/agda
9911f73061e21a87fad76c662463257afe02c861
[ "BSD-2-Clause" ]
371
2015-01-03T14:04:08.000Z
2022-03-30T19:00:30.000Z
postulate S : Set id : S comp : S → S → S module C where _∘_ = comp postulate R : (S → S) → Set T : R (C._∘ id) → R (id C.∘_) → Set t : Set t = T {!!} {!!}
10.75
37
0.44186
2134515e985218329e90de5fc7acff0c5da980ec
18,436
agda
Agda
examples/GUIgeneric/GUI.agda
stephanadls/state-dependent-gui
2bc84cb14a568b560acb546c440cbe0ddcbb2a01
[ "MIT" ]
2
2020-07-31T15:37:39.000Z
2020-07-31T17:20:59.000Z
examples/GUIgeneric/GUI.agda
stephanadls/state-dependent-gui
2bc84cb14a568b560acb546c440cbe0ddcbb2a01
[ "MIT" ]
null
null
null
examples/GUIgeneric/GUI.agda
stephanadls/state-dependent-gui
2bc84cb14a568b560acb546c440cbe0ddcbb2a01
[ "MIT" ]
null
null
null
module GUIgeneric.GUI where open import GUIgeneric.Prelude open import GUIgeneric.GUIDefinitions Frame : Set Frame = ComponentEls frame logOn : Bool logOn = true log : {A : Set} → String → (f : Unit → IO GuiLev1Interface ∞ A) → IO GuiLev1Interface ∞ A log s f = if logOn then (do (putStrLn s) λ x → f x) else f unit module _ where FFIcomponents : {c : Component}(e : ComponentEls c) → Set FFIcomponents {c} (add i e e' _) = FFIcomponents e × FFIcomponents e' FFIcomponents {frame} (createC tt) = FFIFrame FFIcomponents {atomicComp} (createC (button x)) = FFIButton FFIcomponents {atomicComp} (createC (txtbox y)) = FFITextCtrl ffiComponentsToFrame : (e : ComponentEls frame)(ffi : FFIcomponents e) → FFIFrame ffiComponentsToFrame (createC x) ffi = ffi ffiComponentsToFrame (add c'c e e₁ _) (ffie , ffie₁) = ffiComponentsToFrame e₁ ffie₁ FFIcomponentsReduce : {c c' : Component}(e : ComponentEls c)(e' : ComponentEls c') (ee' : e <c e') (ff1 : FFIcomponents e') → FFIcomponents e FFIcomponentsReduce e (add i .e e'' _) (addsub i' .e .e'' _) ffi1 = proj₁ ffi1 FFIcomponentsReduce e (add i e' .e _) (addlift i' .e' .e _) ffi1 = proj₂ ffi1 FFIcomponentsReduce+ : {c c' : Component}(e : ComponentEls c)(e' : ComponentEls c') (ee' : e <=c+ e') (ffi : FFIcomponents e') → FFIcomponents e FFIcomponentsReduce+ e .e (in0= .e) ffi1 = ffi1 FFIcomponentsReduce+ e e' (in2= .e e'₁ .e' x ee') ffi1 = FFIcomponentsReduce e e'₁ x (FFIcomponentsReduce+ e'₁ e' ee' ffi1) data SemiDec (A : Frame → Set) : Set where isEmpty : ((f : Frame) → A f → ⊥) → SemiDec A posNonEmpty : SemiDec A data MethodsStruct : Set where fficom : MethodsStruct ⊥^ : MethodsStruct _⊎^_ : (m m' : MethodsStruct) → MethodsStruct _⊎^unoptimized_ : (m m' : MethodsStruct) → MethodsStruct mutual methodsStruct2Method : (g : Frame)(m : MethodsStruct) → Set methodsStruct2Method g fficom = FFIcomponents g methodsStruct2Method g ⊥^ = ⊥ methodsStruct2Method g (m ⊎^ m₁) = methodsStruct2Methodaux g m m₁ (methodsUnivIsEmpty m) (methodsUnivIsEmpty m₁) methodsStruct2Method g (m ⊎^unoptimized m₁) = methodsStruct2Method g m ⊎ methodsStruct2Method g m₁ methodsStruct2Methodaux : (g : Frame) (m m' : MethodsStruct) (s : SemiDec (λ g → methodsStruct2Method g m)) (s' : SemiDec (λ g → methodsStruct2Method g m')) → Set methodsStruct2Methodaux g m m' s (isEmpty s') = methodsStruct2Method g m methodsStruct2Methodaux g m m' (isEmpty x) posNonEmpty = methodsStruct2Method g m' methodsStruct2Methodaux g m m' posNonEmpty posNonEmpty = methodsStruct2Method g m ⊎ methodsStruct2Method g m' methodsUnivIsEmpty : (m : MethodsStruct) → SemiDec (λ g → methodsStruct2Method g m) methodsUnivIsEmpty fficom = posNonEmpty methodsUnivIsEmpty ⊥^ = isEmpty (λ g → λ ()) methodsUnivIsEmpty (m ⊎^ m₁) = methodsUnivIsEmptyaux m m₁ (methodsUnivIsEmpty m) (methodsUnivIsEmpty m₁) methodsUnivIsEmpty (m ⊎^unoptimized m₁) = posNonEmpty methodsUnivIsEmptyaux : (m m' : MethodsStruct) (s : SemiDec (λ g → methodsStruct2Method g m )) (s' : SemiDec (λ g → methodsStruct2Method g m' )) → SemiDec (λ g → methodsStruct2Methodaux g m m' s s') methodsUnivIsEmptyaux m m' s (isEmpty s') = s methodsUnivIsEmptyaux m m' (isEmpty x) posNonEmpty = posNonEmpty methodsUnivIsEmptyaux m m' posNonEmpty posNonEmpty = posNonEmpty inj₁MUaux : (g : Frame) (m m' : MethodsStruct) (s : SemiDec (λ g → methodsStruct2Method g m )) (s' : SemiDec (λ g → methodsStruct2Method g m' )) (u : methodsStruct2Method g m) → methodsStruct2Methodaux g m m' s s' inj₁MUaux g m m' s (isEmpty x) u = u inj₁MUaux g m m' (isEmpty x) posNonEmpty u = ⊥-elim (x g u) inj₁MUaux g m m' posNonEmpty posNonEmpty u = inj₁ u inj₁MUoptimized : (g : Frame) (m m' : MethodsStruct)(u : methodsStruct2Method g m )-- (isOpt : Bool) → methodsStruct2Method g (m ⊎^ m') --isOpt inj₁MUoptimized g m m' u = inj₁MUaux g m m' (methodsUnivIsEmpty m) (methodsUnivIsEmpty m') u inj₁MUUnoptimized : (g : Frame) (m m' : MethodsStruct)(u : methodsStruct2Method g m )-- (isOpt : Bool) → methodsStruct2Method g (m ⊎^unoptimized m') --isOpt inj₁MUUnoptimized g m m' u = inj₁ u inj₂MUaux : (g : Frame) (m m' : MethodsStruct) (s : SemiDec (λ g → methodsStruct2Method g m)) (s' : SemiDec (λ g → methodsStruct2Method g m' )) (u : methodsStruct2Method g m') → methodsStruct2Methodaux g m m' s s' inj₂MUaux g m m' s (isEmpty x) u = ⊥-elim (x g u) inj₂MUaux g m m' (isEmpty x) posNonEmpty u = u inj₂MUaux g m m' posNonEmpty posNonEmpty u = inj₂ u inj₂MUoptimized : (g : Frame) (m m' : MethodsStruct)(u : methodsStruct2Method g m' ) → methodsStruct2Method g (m ⊎^ m') --isOpt inj₂MUoptimized g m m' u = inj₂MUaux g m m' (methodsUnivIsEmpty m) (methodsUnivIsEmpty m') u inj₂MUUnoptimized : (g : Frame) (m m' : MethodsStruct)(u : methodsStruct2Method g m' ) → methodsStruct2Method g (m ⊎^unoptimized m') --isOpt inj₂MUUnoptimized g m m' u = inj₂ u methodStruct : {c : Component}(e : ComponentEls c) → MethodsStruct methodStruct (add c'c x x₁ optimized) = methodStruct x ⊎^ methodStruct x₁ methodStruct (add c'c x x₁ notOptimized) = methodStruct x ⊎^unoptimized methodStruct x₁ methodStruct {atomicComp} (createC (button s)) = fficom methodStruct {atomicComp} (createC (txtbox s)) = ⊥^ methodStruct _ = ⊥^ methods : {c : Component}(e : ComponentEls c)(g : Frame) → Set methods e g = methodsStruct2Method g (methodStruct e) methodsG : (g : Frame) → Set methodsG g = methods g g methodLift : {c c'' : Component}(e : ComponentEls c)(e'₁ : ComponentEls c'') (g : Frame) (x : e <c e'₁) (m : methods e g ) → methods e'₁ g methodLift e .(add i e e₁ optimized) g (addsub i .e e₁ optimized) m = inj₁MUoptimized g (methodStruct e) (methodStruct e₁) m methodLift e .(add i e e₁ notOptimzed) g (addsub i .e e₁ notOptimzed) m = inj₁MUUnoptimized g (methodStruct e) (methodStruct e₁) m methodLift e .(add i e'₂ e optimized) g (addlift i e'₂ .e optimized) m = inj₂MUoptimized g (methodStruct e'₂) (methodStruct e) m methodLift e .(add i e'₂ e notOptimzed) g (addlift i e'₂ .e notOptimzed) m = inj₂MUUnoptimized g (methodStruct e'₂) (methodStruct e) m methodLift+ : {c c' : Component}(e : ComponentEls c)(e' : ComponentEls c') (g : Frame)(ee' : e <=c+ e') (m : methods e g) → methods e' g methodLift+ e .e g (in0= .e) m = m methodLift+ e e' g (in2= .e e'₁ .e' x ee'') m = methodLift+ e'₁ e' g ee'' (methodLift e e'₁ g x m) data returnType (f : Frame) : Set where noChange : returnType f changedAttributes : properties f → returnType f changedGUI : (fNew : Frame) → (properties fNew) → returnType f nextStateFrame : (f : Frame)(r : returnType f) → Frame nextStateFrame f noChange = f nextStateFrame f (changedAttributes x) = f nextStateFrame f (changedGUI fNew x) = fNew handlerInterface : Interfaceˢ handlerInterface .Stateˢ = Frame handlerInterface .Methodˢ f = methodsG f handlerInterface .Resultˢ f m = returnType f handlerInterface .nextˢ f m r = nextStateFrame f r HandlerObject : ∀ i → Frame → Set HandlerObject i g = IOObjectˢ GuiLev1Interface handlerInterface i g StateAndGuiObj : Set StateAndGuiObj = Σ[ g ∈ Frame ] (properties g) × (HandlerObject ∞ g) StateAndFFIComp : Set StateAndFFIComp = Σ[ g ∈ Frame ] FFIcomponents g -- -- Step 3 : create object of type HandlerObject -- SingleMVar : {A : Set} → (mvar : MVar A) → VarList SingleMVar {A} mvar = addVar mvar [] initHandlerMVar : (l : VarList) (g : Frame) (a : properties g) (f : HandlerObject ∞ g) → IOˢ GuiLev2Interface ∞ (λ s → Σ[ mvar ∈ MVar StateAndGuiObj ] s ≡ addVar mvar l ) l initHandlerMVar l g a f = doˢ (createVar {_}{StateAndGuiObj} (g , a , f)) λ mvar → returnˢ (mvar , refl) initFFIMVar : (g : Frame) → (comp : (FFIcomponents g)) → IOˢ GuiLev2Interface ∞ (λ s → Σ[ mvar ∈ MVar StateAndFFIComp ] s ≡ SingleMVar mvar ) [] initFFIMVar g comp = doˢ (createVar {_}{StateAndFFIComp} (g , comp)) λ mvar → returnˢ (mvar , refl) module _ where frameToEnclosing : (e : ComponentEls frame)(ffi : FFIcomponents e) → FFIFrame frameToEnclosing (createC x) ffi = ffi frameToEnclosing (add i e e₁ _) (proj₃ , proj₄) = frameToEnclosing e₁ proj₄ componentToEnclosingIndex : (c : Component) → Set componentToEnclosingIndex frame = ⊥ componentToEnclosingIndex atomicComp = ⊤ componentToEnclosings : (c : Component)(i : componentToEnclosingIndex c) → Set componentToEnclosings frame () componentToEnclosings atomicComp tt = FFIFrame createComp : {c : Component}{s : GuiLev2State}(e : ComponentEls c) (enclosings : (i : componentToEnclosingIndex c) → componentToEnclosings c i) → (existingFrame : Maybe FFIFrame) → IOₚˢ GuiLev2Interface ∞ (FFIcomponents e) s s createComp {frame} (createC fr) enc (just ffiFrame) = returnˢ (refl , ffiFrame) createComp {frame} (createC fr) enc nothing = doˢ (level1C createWxFrame) λ frFFI → returnˢ (refl , frFFI) createComp {frame} (add buttonFrame e frameEl _) enc maybeFr = createComp frameEl enc maybeFr >>=ₚˢ λ frameComp → createComp e (λ x → frameToEnclosing frameEl frameComp) maybeFr >>=ₚˢ λ buttonComp → returnˢ (refl , buttonComp , frameComp) createComp {atomicComp} (createC (button x)) enc maybeFr = doˢ (level1C (createButton (enc tt) x)) λ bt → returnˢ (refl , bt) createComp {atomicComp} (createC (txtbox x)) enc maybeFr = doˢ (level1C (createTextCtrl (enc tt) x)) λ txt → returnˢ (refl , txt) createComp {atomicComp} (add () e e₁ _) x y createFrame : (g : Frame) → IOₚˢ GuiLev2Interface ∞ (FFIcomponents g) [] [] createFrame g = createComp {frame} g (λ x → ⊥-elim x) nothing reCreateFrame : {s : GuiLev2State}(g : Frame)(f : FFIFrame) → IOₚˢ GuiLev2Interface ∞ (FFIcomponents g) s s reCreateFrame g fr = createComp {frame} g (λ x → ⊥-elim x) (just fr) module _ where ButtonComp : Set ButtonComp = ComponentEls atomicComp button2Frame : (bt : ButtonComp)(g : Frame)(ffi : FFIcomponents g) (rel : bt <=c+ g) → FFIFrame button2Frame bt g ffi (in2= {c' = frame} .bt .(add c'c bt e _) .g (addsub c'c .bt e _) rel) = ffiComponentsToFrame e (FFIcomponentsReduce+ e g aux ffi) where aux : e <=c+ g aux = in2= e (add c'c bt e _) g (addlift c'c bt e _) rel button2Frame bt g ffi (in2= {c' = atomicComp} .bt .(add _ bt e _) .g (addsub () .bt e _) rel) button2Frame bt g ffi (in2= .bt .(add _ e'₁ bt _) .g (addlift {frame} () e'₁ .bt _) (in2= .(add _ e'₁ bt _) e' .g x rel)) button2Frame bt g ffi (in2= .bt .(add _ e'₁ bt _) .g (addlift {atomicComp} () e'₁ .bt _) (in2= .(add _ e'₁ bt _) e' .g x rel)) buttonHandleraux2 : ∀{i} → (bt : ButtonComp) (g : Frame) (ffi : FFIcomponents g) (rel : bt <=c+ g) (m : methods bt g) (a : properties g) (obj : HandlerObject ∞ g) (r : returnType g) (obj' : IOObjectˢ GuiLev1Interface handlerInterface ∞ (nextStateFrame g r)) → IO GuiLev1Interface i StateAndGuiObj buttonHandleraux2 bt g ffi rel m a obj noChange obj' = return (g , a , obj') buttonHandleraux2 bt g ffi rel m a obj (changedAttributes a') obj' = log "Changing Attributes Directly" λ _ → return (g , a' , obj') buttonHandleraux2 (createC x) g ffi rel m a obj (changedGUI gNew a') obj' = log "Firing GUI change ----> SEND FIRE" λ _ → do (fireCustomEvent (button2Frame (createC x) g ffi rel)) λ _ → return (gNew , a' , obj') buttonHandleraux2 (add () bt bt₁ _) g ffi rel m a obj (changedGUI gNew a') obj' buttonHandleraux : ∀{i} → (bt : ButtonComp) (g : Frame) (ffi : FFIcomponents g) (rel : bt <=c+ g) (m : methods bt g) (gNew : Frame) (a : properties gNew) (obj : HandlerObject ∞ gNew) (dec : Dec (g ≡ gNew)) → IO GuiLev1Interface i StateAndGuiObj buttonHandleraux bt g ffi rel m .g a obj (Dec.yes refl) = method obj (methodLift+ bt g g rel m) >>= λ { (r , obj') → buttonHandleraux2 bt g ffi rel m a obj r obj'} buttonHandleraux bt g ffi rel m gNew a obj (Dec.no ¬p) = log "ERROR: button handler is called for wrong GUI !!" λ _ → return (gNew , a , obj) buttonHandler : ∀{i} → (bt : ButtonComp) (g : Frame) (ffi : FFIcomponents g) (rel : bt <=c+ g) (m : methods bt g) (obj : StateAndGuiObj) → IO GuiLev1Interface i StateAndGuiObj buttonHandler {i} bt g ffi rel m (gNew , a , obj) = buttonHandleraux {i} bt g ffi rel m gNew a obj (g ≟Comp gNew) setHandler : ∀{i} → (c : Component) (cels : ComponentEls c) (g : Frame) (ffiComp : FFIcomponents g) (rel : cels <=c+ g) (mvar : MVar StateAndGuiObj) (restList : VarList) → IOˢ GuiLev2Interface i (λ s' → s' ≡ addVar mvar restList × Unit) (addVar mvar restList) setHandler .frame (add buttonFrame cels cels₁ _) g ffi rel mvar restList = setHandler frame cels₁ g ffi (in2= cels₁ (add buttonFrame cels cels₁ _) g (addlift buttonFrame cels cels₁ _) rel) mvar restList >>=ₚˢ λ r → setHandler atomicComp cels g ffi (in2= cels (add buttonFrame cels cels₁ _) g (addsub buttonFrame cels cels₁ _) rel) mvar restList >>=ₚˢ λ r → returnˢ (refl , _) setHandler frame (createC tt) g ffi rel mvar restList = returnˢ (refl , _) setHandler atomicComp (createC (button x)) g ffi (in2= .(createC (button x)) e' .g x₁ rel) mvar restList = doˢ (setButtonHandler (FFIcomponentsReduce (createC (button x)) e' x₁ (FFIcomponentsReduce+ e' g rel ffi) ) [ (λ obj → buttonHandler (createC (button x)) g ffi (in2= (createC (button x)) e' g x₁ rel) ffi (varListProj₁ restList obj) >>= (λ { (g' , obj') → return (varListUpdateProj₁ restList ( g' , obj') obj)}))]) λ _ → returnˢ (refl , _) setHandler atomicComp (createC (txtbox x)) g ffi (in2= .(createC (txtbox x)) e' .g x₁ rel) mvar restList = returnˢ (refl , _) setHandlerG : ∀{i} → (g : Frame) (ffiComp : FFIcomponents g) (mvar : MVar StateAndGuiObj) (restList : VarList) → IOˢ GuiLev2Interface i (λ s → s ≡ addVar mvar restList × Unit) (addVar mvar restList) setHandlerG g ffi mvar restList = setHandler frame g g ffi (in0= g) mvar restList deleteComp : {c : Component}{s : GuiLev2State}(e : ComponentEls c)(ffi : FFIcomponents e) → IOₚˢ GuiLev2Interface ∞ Unit s s deleteComp {frame} (createC fr) _ = returnˢ (refl , _) deleteComp {frame} (add x be frameEl _) (ffi , ffis) = deleteComp be ffi >>=ₚˢ λ _ → deleteComp frameEl ffis >>=ₚˢ λ r → returnˢ (refl , _) deleteComp {atomicComp} (createC (button x)) ffiButton = doˢ (level1C (deleteButton ffiButton)) λ _ → returnˢ (refl , _) deleteComp {atomicComp} (createC (txtbox y)) ffiTextCtrl = doˢ (level1C (deleteTextCtrl ffiTextCtrl)) λ _ → returnˢ (refl , _) deleteComp {atomicComp} (add () a b _) y setAttributes : {c : Component}(i : Size)(e : ComponentEls c)(a : properties e) (ffi : FFIcomponents e) → IO GuiLev1Interface i ⊤ setAttributes {frame} i (createC fr) (a , b , c , d) x = log " setting properties for Frame " λ _ → do (setChildredLayout x a b c d) λ _ → return tt setAttributes {frame} i (add x be frameEl _) (a , as) (ffi , ffis) = setAttributes i be a ffi >>= λ _ → setAttributes i frameEl as ffis >>= λ r → return tt setAttributes {atomicComp} i (createC (button x)) propColor ffiButton = do (setAttribButton ffiButton propColor) λ _ → return tt setAttributes {atomicComp} i (createC (txtbox y)) propColor ffiTextCtrl = do (setAttribTextCtrl ffiTextCtrl propColor) λ _ → return tt setAttributes {atomicComp} i (add () a b _) y z getFrameGen : (g : Frame)(cp : FFIcomponents g) → FFIFrame getFrameGen (createC x) cp = cp getFrameGen (add buttonFrame g g₁ _) (compg , compg₁) = getFrameGen g₁ compg₁
38.328482
153
0.572033
21e863804f4797781a5a19d6356810e36385f728
10,945
agda
Agda
Cubical/Algebra/CommRing/Localisation/Base.agda
ByteBucket123/cubical
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/Localisation/Base.agda
ByteBucket123/cubical
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
[ "MIT" ]
null
null
null
Cubical/Algebra/CommRing/Localisation/Base.agda
ByteBucket123/cubical
aeaa15fb846a3e8bda73635dc7462ae3813b4b1b
[ "MIT" ]
1
2021-03-12T20:08:45.000Z
2021-03-12T20:08:45.000Z
-- We define the localisation of a commutative ring -- at a multiplicatively closed subset and show that it -- has a commutative ring structure. {-# OPTIONS --safe --experimental-lossy-unification #-} module Cubical.Algebra.CommRing.Localisation.Base where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Equiv open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Univalence open import Cubical.Foundations.HLevels open import Cubical.Foundations.Powerset open import Cubical.Foundations.Transport open import Cubical.Functions.FunExtEquiv import Cubical.Data.Empty as ⊥ open import Cubical.Data.Bool open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_ ; +-comm to +ℕ-comm ; +-assoc to +ℕ-assoc ; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm) open import Cubical.Data.Vec open import Cubical.Data.Sigma.Base open import Cubical.Data.Sigma.Properties open import Cubical.Data.FinData open import Cubical.Relation.Nullary open import Cubical.Relation.Binary open import Cubical.Algebra.Ring open import Cubical.Algebra.CommRing open import Cubical.Algebra.RingSolver.ReflectionSolving open import Cubical.HITs.SetQuotients as SQ open import Cubical.HITs.PropositionalTruncation as PT open Iso private variable ℓ ℓ' : Level A : Type ℓ -- A multiplicatively closed subset is assumed to contain 1 record isMultClosedSubset (R' : CommRing ℓ) (S' : ℙ (fst R')) : Type ℓ where constructor multclosedsubset field containsOne : (R' .snd .CommRingStr.1r) ∈ S' multClosed : ∀ {s t} → s ∈ S' → t ∈ S' → ((snd R') .CommRingStr._·_ s t) ∈ S' module Loc (R' : CommRing ℓ) (S' : ℙ (fst R')) (SMultClosedSubset : isMultClosedSubset R' S') where open isMultClosedSubset private R = fst R' open CommRingStr (snd R') open RingTheory (CommRing→Ring R') open CommRingTheory R' S = Σ[ s ∈ R ] (s ∈ S') -- We define the localisation of R by S by quotienting by the following relation: _≈_ : R × S → R × S → Type ℓ (r₁ , s₁) ≈ (r₂ , s₂) = Σ[ s ∈ S ] (fst s · r₁ · fst s₂ ≡ fst s · r₂ · fst s₁) S⁻¹R = (R × S) / _≈_ -- now define addition for S⁻¹R open BinaryRelation locRefl : isRefl _≈_ locRefl _ = (1r , SMultClosedSubset .containsOne) , refl locSym : isSym _≈_ locSym (r , s , s∈S') (r' , s' , s'∈S') (u , p) = u , sym p locTrans : isTrans _≈_ locTrans (r , s , s∈S') (r' , s' , s'∈S') (r'' , s'' , s''∈S') ((u , u∈S') , p) ((v , v∈S') , q) = ((u · v · s') , SMultClosedSubset .multClosed (SMultClosedSubset .multClosed u∈S' v∈S') s'∈S') , path where eq1 : (r s r' s' r'' s'' u v : R) → u · v · s' · r · s'' ≡ u · r · s' · v · s'' eq1 = solve R' eq2 : (r s r' s' r'' s'' u v : R) → u · r' · s · v · s'' ≡ u · s · (v · r' · s'') eq2 = solve R' eq3 : (r s r' s' r'' s'' u v : R) → u · s · (v · r'' · s') ≡ u · v · s' · r'' · s eq3 = solve R' path : u · v · s' · r · s'' ≡ u · v · s' · r'' · s path = u · v · s' · r · s'' ≡⟨ eq1 r s r' s' r'' s'' u v ⟩ -- not just ≡⟨ solve R' ⟩ u · r · s' · v · s'' ≡⟨ cong (λ x → x · v · s'') p ⟩ u · r' · s · v · s'' ≡⟨ eq2 r s r' s' r'' s'' u v ⟩ u · s · (v · r' · s'') ≡⟨ cong (u · s ·_) q ⟩ u · s · (v · r'' · s') ≡⟨ eq3 r s r' s' r'' s'' u v ⟩ u · v · s' · r'' · s ∎ locIsEquivRel : isEquivRel _≈_ isEquivRel.reflexive locIsEquivRel = locRefl isEquivRel.symmetric locIsEquivRel = locSym isEquivRel.transitive locIsEquivRel = locTrans _+ₗ_ : S⁻¹R → S⁻¹R → S⁻¹R _+ₗ_ = setQuotSymmBinOp locRefl locTrans _+ₚ_ +ₚ-symm θ where _+ₚ_ : R × S → R × S → R × S (r₁ , s₁ , s₁∈S) +ₚ (r₂ , s₂ , s₂∈S) = (r₁ · s₂ + r₂ · s₁) , (s₁ · s₂) , SMultClosedSubset .multClosed s₁∈S s₂∈S +ₚ-symm : (a b : R × S) → (a +ₚ b) ≡ (b +ₚ a) +ₚ-symm (r₁ , s₁ , s₁∈S) (r₂ , s₂ , s₂∈S) = ΣPathP (+Comm _ _ , Σ≡Prop (λ x → S' x .snd) (·-comm _ _)) θ : (a a' b : R × S) → a ≈ a' → (a +ₚ b) ≈ (a' +ₚ b) θ (r₁ , s₁ , s₁∈S) (r'₁ , s'₁ , s'₁∈S) (r₂ , s₂ , s₂∈S) ((s , s∈S) , p) = (s , s∈S) , path where eq1 : (r₁ s₁ r'₁ s'₁ s'₁ r₂ s₂ s : R) → s · (r₁ · s₂ + r₂ · s₁) · (s'₁ · s₂) ≡ s · r₁ · s'₁ · s₂ · s₂ + s · r₂ · s₁ · s'₁ · s₂ eq1 = solve R' eq2 : (r₁ s₁ r'₁ s'₁ s'₁ r₂ s₂ s : R) → s · r'₁ · s₁ · s₂ · s₂ + s · r₂ · s₁ · s'₁ · s₂ ≡ s · (r'₁ · s₂ + r₂ · s'₁) · (s₁ · s₂) eq2 = solve R' path : s · (r₁ · s₂ + r₂ · s₁) · (s'₁ · s₂) ≡ s · (r'₁ · s₂ + r₂ · s'₁) · (s₁ · s₂) path = s · (r₁ · s₂ + r₂ · s₁) · (s'₁ · s₂) ≡⟨ eq1 r₁ s₁ r'₁ s'₁ s'₁ r₂ s₂ s ⟩ s · r₁ · s'₁ · s₂ · s₂ + s · r₂ · s₁ · s'₁ · s₂ ≡⟨ cong (λ x → x · s₂ · s₂ + s · r₂ · s₁ · s'₁ · s₂) p ⟩ s · r'₁ · s₁ · s₂ · s₂ + s · r₂ · s₁ · s'₁ · s₂ ≡⟨ eq2 r₁ s₁ r'₁ s'₁ s'₁ r₂ s₂ s ⟩ s · (r'₁ · s₂ + r₂ · s'₁) · (s₁ · s₂) ∎ -- check group-laws for addition +ₗ-assoc : (x y z : S⁻¹R) → x +ₗ (y +ₗ z) ≡ (x +ₗ y) +ₗ z +ₗ-assoc = SQ.elimProp3 (λ _ _ _ → squash/ _ _) +ₗ-assoc[] where +ₗ-assoc[] : (a b c : R × S) → [ a ] +ₗ ([ b ] +ₗ [ c ]) ≡ ([ a ] +ₗ [ b ]) +ₗ [ c ] +ₗ-assoc[] (r , s , s∈S) (r' , s' , s'∈S) (r'' , s'' , s''∈S) = cong [_] (ΣPathP ((path r s r' s' r'' s'') , Σ≡Prop (λ x → ∈-isProp S' x) (·Assoc _ _ _))) where path : (r s r' s' r'' s'' : R) → r · (s' · s'') + (r' · s'' + r'' · s') · s ≡ (r · s' + r' · s) · s'' + r'' · (s · s') path = solve R' 0ₗ : S⁻¹R 0ₗ = [ 0r , 1r , SMultClosedSubset .containsOne ] +ₗ-rid : (x : S⁻¹R) → x +ₗ 0ₗ ≡ x +ₗ-rid = SQ.elimProp (λ _ → squash/ _ _) +ₗ-rid[] where +ₗ-rid[] : (a : R × S) → [ a ] +ₗ 0ₗ ≡ [ a ] +ₗ-rid[] (r , s , s∈S) = path where -- possible to automate with improved ring solver? eq1 : r · 1r + 0r · s ≡ r eq1 = cong (r · 1r +_) (0LeftAnnihilates _) ∙∙ +Rid _ ∙∙ ·Rid _ path : [ r · 1r + 0r · s , s · 1r , SMultClosedSubset .multClosed s∈S (SMultClosedSubset .containsOne) ] ≡ [ r , s , s∈S ] path = cong [_] (ΣPathP (eq1 , Σ≡Prop (λ x → ∈-isProp S' x) (·Rid _))) -ₗ_ : S⁻¹R → S⁻¹R -ₗ_ = SQ.rec squash/ -ₗ[] -ₗWellDef where -ₗ[] : R × S → S⁻¹R -ₗ[] (r , s) = [ - r , s ] -ₗWellDef : (a b : R × S) → a ≈ b → -ₗ[] a ≡ -ₗ[] b -ₗWellDef (r , s , _) (r' , s' , _) ((u , u∈S) , p) = eq/ _ _ ((u , u∈S) , path) where eq1 : (u r s' : R) → u · - r · s' ≡ - (u · r · s') eq1 = solve R' eq2 : (u r' s : R) → - (u · r' · s) ≡ u · - r' · s eq2 = solve R' path : u · - r · s' ≡ u · - r' · s path = eq1 u r s' ∙∙ cong -_ p ∙∙ eq2 u r' s +ₗ-rinv : (x : S⁻¹R) → x +ₗ (-ₗ x) ≡ 0ₗ +ₗ-rinv = SQ.elimProp (λ _ → squash/ _ _) +ₗ-rinv[] where +ₗ-rinv[] : (a : R × S) → ([ a ] +ₗ (-ₗ [ a ])) ≡ 0ₗ +ₗ-rinv[] (r , s , s∈S) = eq/ _ _ ((1r , SMultClosedSubset .containsOne) , path) where -- not yet possible with ring solver path : 1r · (r · s + - r · s) · 1r ≡ 1r · 0r · (s · s) path = 1r · (r · s + - r · s) · 1r ≡⟨ cong (λ x → 1r · (r · s + x) · 1r) (-DistL· _ _) ⟩ 1r · (r · s + - (r · s)) · 1r ≡⟨ cong (λ x → 1r · x · 1r) (+Rinv _) ⟩ 1r · 0r · 1r ≡⟨ ·Rid _ ⟩ 1r · 0r ≡⟨ ·Lid _ ⟩ 0r ≡⟨ sym (0LeftAnnihilates _) ⟩ 0r · (s · s) ≡⟨ cong (_· (s · s)) (sym (·Lid _)) ⟩ 1r · 0r · (s · s) ∎ +ₗ-comm : (x y : S⁻¹R) → x +ₗ y ≡ y +ₗ x +ₗ-comm = SQ.elimProp2 (λ _ _ → squash/ _ _) +ₗ-comm[] where +ₗ-comm[] : (a b : R × S) → ([ a ] +ₗ [ b ]) ≡ ([ b ] +ₗ [ a ]) +ₗ-comm[] (r , s , s∈S) (r' , s' , s'∈S) = cong [_] (ΣPathP ((+Comm _ _) , Σ≡Prop (λ x → ∈-isProp S' x) (·-comm _ _))) -- Now for multiplication _·ₗ_ : S⁻¹R → S⁻¹R → S⁻¹R _·ₗ_ = setQuotSymmBinOp locRefl locTrans _·ₚ_ ·ₚ-symm θ where _·ₚ_ : R × S → R × S → R × S (r₁ , s₁ , s₁∈S) ·ₚ (r₂ , s₂ , s₂∈S) = (r₁ · r₂) , ((s₁ · s₂) , SMultClosedSubset .multClosed s₁∈S s₂∈S) ·ₚ-symm : (a b : R × S) → (a ·ₚ b) ≡ (b ·ₚ a) ·ₚ-symm (r₁ , s₁ , s₁∈S) (r₂ , s₂ , s₂∈S) = ΣPathP (·-comm _ _ , Σ≡Prop (λ x → S' x .snd) (·-comm _ _)) θ : (a a' b : R × S) → a ≈ a' → (a ·ₚ b) ≈ (a' ·ₚ b) θ (r₁ , s₁ , s₁∈S) (r'₁ , s'₁ , s'₁∈S) (r₂ , s₂ , s₂∈S) ((s , s∈S) , p) = (s , s∈S) , path where eq1 : (r₁ s₁ r'₁ s'₁ r₂ s₂ s : R) → s · (r₁ · r₂) · (s'₁ · s₂) ≡ s · r₁ · s'₁ · r₂ · s₂ eq1 = solve R' eq2 : (r₁ s₁ r'₁ s'₁ r₂ s₂ s : R) → s · r'₁ · s₁ · r₂ · s₂ ≡ s · (r'₁ · r₂) · (s₁ · s₂) eq2 = solve R' path : s · (r₁ · r₂) · (s'₁ · s₂) ≡ s · (r'₁ · r₂) · (s₁ · s₂) path = eq1 r₁ s₁ r'₁ s'₁ r₂ s₂ s ∙∙ cong (λ x → x · r₂ · s₂) p ∙∙ eq2 r₁ s₁ r'₁ s'₁ r₂ s₂ s -- checking laws for multiplication 1ₗ : S⁻¹R 1ₗ = [ 1r , 1r , SMultClosedSubset .containsOne ] ·ₗ-assoc : (x y z : S⁻¹R) → x ·ₗ (y ·ₗ z) ≡ (x ·ₗ y) ·ₗ z ·ₗ-assoc = SQ.elimProp3 (λ _ _ _ → squash/ _ _) ·ₗ-assoc[] where ·ₗ-assoc[] : (a b c : R × S) → [ a ] ·ₗ ([ b ] ·ₗ [ c ]) ≡ ([ a ] ·ₗ [ b ]) ·ₗ [ c ] ·ₗ-assoc[] (r , s , s∈S) (r' , s' , s'∈S) (r'' , s'' , s''∈S) = cong [_] (ΣPathP ((·Assoc _ _ _) , Σ≡Prop (λ x → ∈-isProp S' x) (·Assoc _ _ _))) ·ₗ-rid : (x : S⁻¹R) → x ·ₗ 1ₗ ≡ x ·ₗ-rid = SQ.elimProp (λ _ → squash/ _ _) ·ₗ-rid[] where ·ₗ-rid[] : (a : R × S) → ([ a ] ·ₗ 1ₗ) ≡ [ a ] ·ₗ-rid[] (r , s , s∈S) = cong [_] (ΣPathP ((·Rid _) , Σ≡Prop (λ x → ∈-isProp S' x) (·Rid _))) ·ₗ-rdist-+ₗ : (x y z : S⁻¹R) → x ·ₗ (y +ₗ z) ≡ (x ·ₗ y) +ₗ (x ·ₗ z) ·ₗ-rdist-+ₗ = SQ.elimProp3 (λ _ _ _ → squash/ _ _) ·ₗ-rdist-+ₗ[] where ·ₗ-rdist-+ₗ[] : (a b c : R × S) → [ a ] ·ₗ ([ b ] +ₗ [ c ]) ≡ ([ a ] ·ₗ [ b ]) +ₗ ([ a ] ·ₗ [ c ]) ·ₗ-rdist-+ₗ[] (r , s , s∈S) (r' , s' , s'∈S) (r'' , s'' , s''∈S) = eq/ _ _ ((1r , (SMultClosedSubset .containsOne)) , path r s r' s' r'' s'') where -- could be shortened even further path : (r s r' s' r'' s'' : R) → 1r · (r · (r' · s'' + r'' · s')) · (s · s' · (s · s'')) ≡ 1r · (r · r' · (s · s'') + r · r'' · (s · s')) · (s · (s' · s'')) path = solve R' ·ₗ-comm : (x y : S⁻¹R) → x ·ₗ y ≡ y ·ₗ x ·ₗ-comm = SQ.elimProp2 (λ _ _ → squash/ _ _) ·ₗ-comm[] where ·ₗ-comm[] : (a b : R × S) → [ a ] ·ₗ [ b ] ≡ [ b ] ·ₗ [ a ] ·ₗ-comm[] (r , s , s∈S) (r' , s' , s'∈S) = cong [_] (ΣPathP ((·-comm _ _) , Σ≡Prop (λ x → ∈-isProp S' x) (·-comm _ _))) -- Commutative ring structure on S⁻¹R S⁻¹RAsCommRing : CommRing ℓ S⁻¹RAsCommRing = S⁻¹R , S⁻¹RCommRingStr where open CommRingStr S⁻¹RCommRingStr : CommRingStr S⁻¹R 0r S⁻¹RCommRingStr = 0ₗ 1r S⁻¹RCommRingStr = 1ₗ _+_ S⁻¹RCommRingStr = _+ₗ_ _·_ S⁻¹RCommRingStr = _·ₗ_ - S⁻¹RCommRingStr = -ₗ_ isCommRing S⁻¹RCommRingStr = makeIsCommRing squash/ +ₗ-assoc +ₗ-rid +ₗ-rinv +ₗ-comm ·ₗ-assoc ·ₗ-rid ·ₗ-rdist-+ₗ ·ₗ-comm
37.101695
101
0.471448
7c1f9ed4bf1ee29126f97c0215b073851f7f8edf
1,089
agda
Agda
notes/FOT/Common/FOL/Existential/Syntax.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
11
2015-09-03T20:53:42.000Z
2021-09-12T16:09:54.000Z
notes/FOT/Common/FOL/Existential/Syntax.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
2
2016-10-12T17:28:16.000Z
2017-01-01T14:34:26.000Z
notes/FOT/Common/FOL/Existential/Syntax.agda
asr/fotc
2fc9f2b81052a2e0822669f02036c5750371b72d
[ "MIT" ]
3
2016-09-19T14:18:30.000Z
2018-03-14T08:50:00.000Z
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOT.Common.FOL.Existential.Syntax where -- We add 3 to the fixities of the Agda standard library 0.8.1 (see -- Relation.Binary.Core). infix 7 _≡_ postulate D : Set _≡_ : D → D → Set refl : ∀ {d} → d ≡ d d : D module ∃₁ where -- We add 3 to the fixities of the Agda standard library 0.8.1 (see -- Data/Product.agda, Data/Sum.agda and Relation/Nullary/Core.agda). infixr 7 _,_ infix 5 ∃ data ∃ (P : D → Set) : Set where _,_ : (x : D) → P x → ∃ P syntax ∃ (λ x → e) = ∃[ x ] e t₁ : ∃ λ x → x ≡ x t₁ = d , refl t₂ : ∃[ x ] x ≡ x t₂ = d , refl t₃ : ∃ λ x → ∃ λ y → x ≡ y t₃ = d , d , refl t₄ : ∃[ x ] ∃[ y ] x ≡ y t₄ = d , d , refl module ∃₂ where infixr 7 _,_,_ data ∃₂ (P : D → D → Set) : Set where _,_,_ : (x y : D) → P x y → ∃₂ P -- Agda issue: 536 -- syntax ∃₂ (λ x y → e) = ∃₂[ x , y ] e t₁ : ∃₂ λ x y → x ≡ y t₁ = d , d , refl
20.54717
70
0.493113
2eb123e4483d2eb4dec29ec61f70e05f608a0885
589
agda
Agda
agda-stdlib/src/Data/List/Relation/Subset/Propositional.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
5
2020-10-07T12:07:53.000Z
2020-10-10T21:41:32.000Z
agda-stdlib/src/Data/List/Relation/Subset/Propositional.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
null
null
null
agda-stdlib/src/Data/List/Relation/Subset/Propositional.agda
DreamLinuxer/popl21-artifact
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
[ "MIT" ]
1
2021-11-04T06:54:45.000Z
2021-11-04T06:54:45.000Z
------------------------------------------------------------------------ -- The Agda standard library -- -- This module is DEPRECATED. Please use -- Data.List.Relation.Binary.Subset.Propositional directly. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.List.Relation.Subset.Propositional where open import Data.List.Relation.Binary.Subset.Propositional public {-# WARNING_ON_IMPORT "Data.List.Relation.Subset.Propositional was deprecated in v1.0. Use Data.List.Relation.Binary.Subset.Propositional instead." #-}
32.722222
72
0.585739
599d0b8f97b8d26d29522fd22eef6ea806d49b01
16,754
agda
Agda
Cubical/Structures/Record.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/Structures/Record.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
Cubical/Structures/Record.agda
maxdore/cubical
ef62b84397396d48135d73ba7400b71c721ddc94
[ "MIT" ]
null
null
null
{- Automatically generating proofs of UnivalentStr for records -} {-# OPTIONS --no-exact-split --safe #-} module Cubical.Structures.Record where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.Function open import Cubical.Foundations.HLevels open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.SIP open import Cubical.Foundations.Structure open import Cubical.Foundations.Univalence open import Cubical.Data.Sigma open import Cubical.Data.Nat open import Cubical.Data.List as List open import Cubical.Data.Vec as Vec open import Cubical.Data.Bool open import Cubical.Data.Maybe open import Cubical.Data.Sum open import Cubical.Structures.Auto import Cubical.Structures.Macro as M import Agda.Builtin.Reflection as R open import Cubical.Reflection.Base -- Magic number private FUEL = 10000 -- Types for specifying inputs to the tactics data AutoFieldSpec : Typeω where autoFieldSpec : ∀ {ℓ ℓ₁ ℓ₂} (R : Type ℓ → Type ℓ₁) {S : Type ℓ → Type ℓ₂} → ({X : Type ℓ} → R X → S X) → AutoFieldSpec module _ {ℓ ℓ₁ ℓ₁'} where mutual data AutoFields (R : Type ℓ → Type ℓ₁) (ι : StrEquiv R ℓ₁') : Typeω where fields: : AutoFields R ι _data[_∣_] : (fs : AutoFields R ι) → ∀ {ℓ₂ ℓ₂'} {S : Type ℓ → Type ℓ₂} {ι' : StrEquiv S ℓ₂'} → (f : {X : Type ℓ} → R X → S X) → ({A B : TypeWithStr ℓ R} {e : typ A ≃ typ B} → ι A B e → ι' (map-snd f A) (map-snd f B) e) → AutoFields R ι _prop[_∣_] : (fs : AutoFields R ι) → ∀ {ℓ₂} {P : (X : Type ℓ) → GatherFields fs X → Type ℓ₂} → ({X : Type ℓ} (r : R X) → P X (projectFields fs r)) → isPropProperty R ι fs P → AutoFields R ι GatherFieldsLevel : {R : Type ℓ → Type ℓ₁} {ι : StrEquiv R ℓ₁'} → AutoFields R ι → Level GatherFieldsLevel fields: = ℓ-zero GatherFieldsLevel (_data[_∣_] fs {ℓ₂ = ℓ₂} _ _) = ℓ-max (GatherFieldsLevel fs) ℓ₂ GatherFieldsLevel (_prop[_∣_] fs {ℓ₂ = ℓ₂} _ _) = ℓ-max (GatherFieldsLevel fs) ℓ₂ GatherFields : {R : Type ℓ → Type ℓ₁} {ι : StrEquiv R ℓ₁'} (dat : AutoFields R ι) → Type ℓ → Type (GatherFieldsLevel dat) GatherFields fields: X = Unit GatherFields (_data[_∣_] fs {S = S} _ _) X = GatherFields fs X × S X GatherFields (_prop[_∣_] fs {P = P} _ _) X = Σ[ s ∈ GatherFields fs X ] (P X s) projectFields : {R : Type ℓ → Type ℓ₁} {ι : StrEquiv R ℓ₁'} (fs : AutoFields R ι) → {X : Type ℓ} → R X → GatherFields fs X projectFields fields: = _ projectFields (fs data[ f ∣ _ ]) r = projectFields fs r , f r projectFields (fs prop[ f ∣ _ ]) r = projectFields fs r , f r isPropProperty : ∀ {ℓ₂} (R : Type ℓ → Type ℓ₁) (ι : StrEquiv R ℓ₁') (fs : AutoFields R ι) (P : (X : Type ℓ) → GatherFields fs X → Type ℓ₂) → Type (ℓ-max (ℓ-suc ℓ) (ℓ-max ℓ₁ ℓ₂)) isPropProperty R ι fs P = {X : Type ℓ} (r : R X) → isProp (P X (projectFields fs r)) data AutoRecordSpec : Typeω where autoRecordSpec : (R : Type ℓ → Type ℓ₁) (ι : StrEquiv R ℓ₁') → AutoFields R ι → AutoRecordSpec -- Some reflection utilities private tApply : R.Term → List (R.Arg R.Term) → R.Term tApply t l = R.def (quote idfun) (R.unknown v∷ t v∷ l) tStrMap : R.Term → R.Term → R.Term tStrMap A f = R.def (quote map-snd) (f v∷ A v∷ []) tStrProj : R.Term → R.Name → R.Term tStrProj A sfield = tStrMap A (R.def sfield []) Fun : ∀ {ℓ ℓ'} → Type ℓ → Type ℓ' → Type (ℓ-max ℓ ℓ') Fun A B = A → B -- Helper functions used in the generated univalence proof private pathMap : ∀ {ℓ ℓ'} {S : I → Type ℓ} {T : I → Type ℓ'} (f : {i : I} → S i → T i) {x : S i0} {y : S i1} → PathP S x y → PathP T (f x) (f y) pathMap f p i = f (p i) -- Property field helper functions module _ {ℓ ℓ₁ ℓ₁' ℓ₂} (R : Type ℓ → Type ℓ₁) -- Structure record (ι : StrEquiv R ℓ₁') -- Equivalence record (fs : AutoFields R ι) -- Prior fields (P : (X : Type ℓ) → GatherFields fs X → Type ℓ₂) -- Property type (f : {X : Type ℓ} (r : R X) → P X (projectFields fs r)) -- Property projection where prev = projectFields fs Prev = GatherFields fs PropHelperCenterType : Type _ PropHelperCenterType = (A B : TypeWithStr ℓ R) (e : A .fst ≃ B .fst) (p : PathP (λ i → Prev (ua e i)) (prev (A .snd)) (prev (B .snd))) → PathP (λ i → P (ua e i) (p i)) (f (A .snd)) (f (B .snd)) PropHelperContractType : PropHelperCenterType → Type _ PropHelperContractType c = (A B : TypeWithStr ℓ R) (e : A .fst ≃ B .fst) {p₀ : PathP (λ i → Prev (ua e i)) (prev (A .snd)) (prev (B .snd))} (q : PathP (λ i → R (ua e i)) (A .snd) (B .snd)) (p : p₀ ≡ (λ i → prev (q i))) → PathP (λ k → PathP (λ i → P (ua e i) (p k i)) (f (A .snd)) (f (B .snd))) (c A B e p₀) (λ i → f (q i)) PropHelperType : Type _ PropHelperType = Σ PropHelperCenterType PropHelperContractType derivePropHelper : isPropProperty R ι fs P → PropHelperType derivePropHelper propP .fst A B e p = isOfHLevelPathP' 0 (propP _) (f (A .snd)) (f (B .snd)) .fst derivePropHelper propP .snd A B e q p = isOfHLevelPathP' 0 (isOfHLevelPathP 1 (propP _) _ _) _ _ .fst -- Build proof of univalence from an isomorphism module _ {ℓ ℓ₁ ℓ₁'} (S : Type ℓ → Type ℓ₁) (ι : StrEquiv S ℓ₁') where fwdShape : Type _ fwdShape = (A B : TypeWithStr ℓ S) (e : typ A ≃ typ B) → ι A B e → PathP (λ i → S (ua e i)) (str A) (str B) bwdShape : Type _ bwdShape = (A B : TypeWithStr ℓ S) (e : typ A ≃ typ B) → PathP (λ i → S (ua e i)) (str A) (str B) → ι A B e fwdBwdShape : fwdShape → bwdShape → Type _ fwdBwdShape fwd bwd = (A B : TypeWithStr ℓ S) (e : typ A ≃ typ B) → ∀ p → fwd A B e (bwd A B e p) ≡ p bwdFwdShape : fwdShape → bwdShape → Type _ bwdFwdShape fwd bwd = (A B : TypeWithStr ℓ S) (e : typ A ≃ typ B) → ∀ r → bwd A B e (fwd A B e r) ≡ r -- The implicit arguments A,B in UnivalentStr make some things annoying so let's avoid them ExplicitUnivalentStr : Type _ ExplicitUnivalentStr = (A B : TypeWithStr _ S) (e : typ A ≃ typ B) → ι A B e ≃ PathP (λ i → S (ua e i)) (str A) (str B) explicitUnivalentStr : (fwd : fwdShape) (bwd : bwdShape) → fwdBwdShape fwd bwd → bwdFwdShape fwd bwd → ExplicitUnivalentStr explicitUnivalentStr fwd bwd fwdBwd bwdFwd A B e = isoToEquiv isom where open Iso isom : Iso _ _ isom .fun = fwd A B e isom .inv = bwd A B e isom .rightInv = fwdBwd A B e isom .leftInv = bwdFwd A B e ExplicitUnivalentDesc : ∀ ℓ {ℓ₁ ℓ₁'} → (d : M.Desc ℓ ℓ₁ ℓ₁') → Type _ ExplicitUnivalentDesc _ d = ExplicitUnivalentStr (M.MacroStructure d) (M.MacroEquivStr d) explicitUnivalentDesc : ∀ ℓ {ℓ₁ ℓ₁'} → (d : M.Desc ℓ ℓ₁ ℓ₁') → ExplicitUnivalentDesc ℓ d explicitUnivalentDesc _ d A B e = M.MacroUnivalentStr d e -- Internal record specification type private record TypedTerm : Type where field type : R.Term term : R.Term record InternalDatumField : Type where field sfield : R.Name -- name of structure field efield : R.Name -- name of equivalence field record InternalPropField : Type where field sfield : R.Name -- name of structure field InternalField : Type InternalField = InternalDatumField ⊎ InternalPropField record InternalSpec (A : Type) : Type where field srec : R.Term -- structure record type erec : R.Term -- equivalence record type fields : List (InternalField × A) -- in reverse order open TypedTerm open InternalDatumField open InternalPropField -- Parse a field and record specifications private findName : R.Term → R.TC R.Name findName (R.def name _) = R.returnTC name findName (R.lam R.hidden (R.abs _ t)) = findName t findName t = R.typeError (R.strErr "Not a name + spine: " ∷ R.termErr t ∷ []) parseFieldSpec : R.Term → R.TC (R.Term × R.Term × R.Term × R.Term) parseFieldSpec (R.con (quote autoFieldSpec) (ℓ h∷ ℓ₁ h∷ ℓ₂ h∷ R v∷ S h∷ f v∷ [])) = R.reduce ℓ >>= λ ℓ → R.returnTC (ℓ , ℓ₂ , S , f) parseFieldSpec t = R.typeError (R.strErr "Malformed field specification: " ∷ R.termErr t ∷ []) parseSpec : R.Term → R.TC (InternalSpec TypedTerm) parseSpec (R.con (quote autoRecordSpec) (ℓ h∷ ℓ₁ h∷ ℓ₁' h∷ srecTerm v∷ erecTerm v∷ fs v∷ [])) = parseFields fs >>= λ fs' → R.returnTC λ { .srec → srecTerm ; .erec → erecTerm ; .fields → fs'} where open InternalSpec parseFields : R.Term → R.TC (List (InternalField × TypedTerm)) parseFields (R.con (quote fields:) _) = R.returnTC [] parseFields (R.con (quote _data[_∣_]) (ℓ h∷ ℓ₁ h∷ ℓ₁' h∷ R h∷ ι h∷ fs v∷ ℓ₂ h∷ ℓ₂' h∷ S h∷ ι' h∷ sfieldTerm v∷ efieldTerm v∷ [])) = R.reduce ℓ >>= λ ℓ → findName sfieldTerm >>= λ sfieldName → findName efieldTerm >>= λ efieldName → buildDesc FUEL ℓ ℓ₂ S >>= λ d → let f : InternalField × TypedTerm f = λ { .fst → inl λ { .sfield → sfieldName ; .efield → efieldName } ; .snd .type → R.def (quote ExplicitUnivalentDesc) (ℓ v∷ d v∷ []) ; .snd .term → R.def (quote explicitUnivalentDesc) (ℓ v∷ d v∷ []) } in liftTC (f ∷_) (parseFields fs) parseFields (R.con (quote _prop[_∣_]) (ℓ h∷ ℓ₁ h∷ ℓ₁' h∷ R h∷ ι h∷ fs v∷ ℓ₂ h∷ P h∷ fieldTerm v∷ prop v∷ [])) = findName fieldTerm >>= λ fieldName → let p : InternalField × TypedTerm p = λ { .fst → inr λ { .sfield → fieldName } ; .snd .type → R.def (quote PropHelperType) (srecTerm v∷ erecTerm v∷ fs v∷ P v∷ fieldTerm v∷ []) ; .snd .term → R.def (quote derivePropHelper) (srecTerm v∷ erecTerm v∷ fs v∷ P v∷ fieldTerm v∷ prop v∷ []) } in liftTC (p ∷_) (parseFields fs) parseFields t = R.typeError (R.strErr "Malformed autoRecord specification (1): " ∷ R.termErr t ∷ []) parseSpec t = R.typeError (R.strErr "Malformed autoRecord specification (2): " ∷ R.termErr t ∷ []) -- Build a proof of univalence from an InternalSpec module _ (spec : InternalSpec ℕ) where open InternalSpec spec private fwdDatum : Vec R.Term 4 → R.Term → InternalDatumField × ℕ → R.Term fwdDatum (A ∷ B ∷ e ∷ streq ∷ _) i (dat , n) = R.def (quote equivFun) (tApply (v n) (tStrProj A (dat .sfield) v∷ tStrProj B (dat .sfield) v∷ e v∷ []) v∷ R.def (dat .efield) (streq v∷ []) v∷ i v∷ []) fwdProperty : Vec R.Term 4 → R.Term → R.Term → InternalPropField × ℕ → R.Term fwdProperty (A ∷ B ∷ e ∷ streq ∷ _) i prevPath prop = R.def (quote fst) (v (prop .snd) v∷ A v∷ B v∷ e v∷ prevPath v∷ i v∷ []) bwdClause : Vec R.Term 4 → InternalDatumField × ℕ → R.Clause bwdClause (A ∷ B ∷ e ∷ q ∷ _) (dat , n) = R.clause [] (R.proj (dat .efield) v∷ []) (R.def (quote invEq) (tApply (v n) (tStrProj A (dat .sfield) v∷ tStrProj B (dat .sfield) v∷ e v∷ []) v∷ R.def (quote pathMap) (R.def (dat .sfield) [] v∷ q v∷ []) v∷ [])) fwdBwdDatum : Vec R.Term 4 → R.Term → R.Term → InternalDatumField × ℕ → R.Term fwdBwdDatum (A ∷ B ∷ e ∷ q ∷ _) j i (dat , n) = R.def (quote retEq) (tApply (v n) (tStrProj A (dat .sfield) v∷ tStrProj B (dat .sfield) v∷ e v∷ []) v∷ R.def (quote pathMap) (R.def (dat .sfield) [] v∷ q v∷ []) v∷ j v∷ i v∷ []) fwdBwdProperty : Vec R.Term 4 → (j i prevPath : R.Term) → InternalPropField × ℕ → R.Term fwdBwdProperty (A ∷ B ∷ e ∷ q ∷ _) j i prevPath prop = R.def (quote snd) (v (prop .snd) v∷ A v∷ B v∷ e v∷ q v∷ prevPath v∷ j v∷ i v∷ []) bwdFwdClause : Vec R.Term 4 → R.Term → InternalDatumField × ℕ → R.Clause bwdFwdClause (A ∷ B ∷ e ∷ streq ∷ _) j (dat , n) = R.clause [] (R.proj (dat .efield) v∷ []) (R.def (quote secEq) (tApply (v n) (tStrProj A (dat .sfield) v∷ tStrProj B (dat .sfield) v∷ e v∷ []) v∷ R.def (dat .efield) (streq v∷ []) v∷ j v∷ [])) makeVarsFrom : {n : ℕ} → ℕ → Vec R.Term n makeVarsFrom {zero} k = [] makeVarsFrom {suc n} k = v (n + k) ∷ (makeVarsFrom k) fwd : R.Term fwd = vlam "A" (vlam "B" (vlam "e" (vlam "streq" (vlam "i" (R.pat-lam body []))))) where -- input list is in reverse order fwdClauses : ℕ → List (InternalField × ℕ) → List (R.Name × R.Term) fwdClauses k [] = [] fwdClauses k ((inl f , n) ∷ fs) = fwdClauses k fs ∷ʳ (f .sfield , fwdDatum (makeVarsFrom k) (v 0) (map-snd (4 + k +_) (f , n))) fwdClauses k ((inr p , n) ∷ fs) = fwdClauses k fs ∷ʳ (p .sfield , fwdProperty (makeVarsFrom k) (v 0) prevPath (map-snd (4 + k +_) (p , n))) where prevPath = vlam "i" (List.foldl (λ t (_ , t') → R.con (quote _,_) (t v∷ t' v∷ [])) (R.con (quote tt) []) (fwdClauses (suc k) fs)) body = List.map (λ (n , t) → R.clause [] [ varg (R.proj n) ] t) (fwdClauses 1 fields) bwd : R.Term bwd = vlam "A" (vlam "B" (vlam "e" (vlam "q" (R.pat-lam (bwdClauses fields) [])))) where -- input is in reverse order bwdClauses : List (InternalField × ℕ) → List R.Clause bwdClauses [] = [] bwdClauses ((inl f , n) ∷ fs) = bwdClauses fs ∷ʳ bwdClause (makeVarsFrom 0) (map-snd (4 +_) (f , n)) bwdClauses ((inr p , n) ∷ fs) = bwdClauses fs fwdBwd : R.Term fwdBwd = vlam "A" (vlam "B" (vlam "e" (vlam "q" (vlam "j" (vlam "i" (R.pat-lam body [])))))) where -- input is in reverse order fwdBwdClauses : ℕ → List (InternalField × ℕ) → List (R.Name × R.Term) fwdBwdClauses k [] = [] fwdBwdClauses k ((inl f , n) ∷ fs) = fwdBwdClauses k fs ∷ʳ (f .sfield , fwdBwdDatum (makeVarsFrom k) (v 1) (v 0) (map-snd (4 + k +_) (f , n))) fwdBwdClauses k ((inr p , n) ∷ fs) = fwdBwdClauses k fs ∷ʳ ((p .sfield , fwdBwdProperty (makeVarsFrom k) (v 1) (v 0) prevPath (map-snd (4 + k +_) (p , n)))) where prevPath = vlam "j" (vlam "i" (List.foldl (λ t (_ , t') → R.con (quote _,_) (t v∷ t' v∷ [])) (R.con (quote tt) []) (fwdBwdClauses (2 + k) fs))) body = List.map (λ (n , t) → R.clause [] [ varg (R.proj n) ] t) (fwdBwdClauses 2 fields) bwdFwd : R.Term bwdFwd = vlam "A" (vlam "B" (vlam "e" (vlam "streq" (vlam "j" (R.pat-lam (bwdFwdClauses fields) []))))) where bwdFwdClauses : List (InternalField × ℕ) → List R.Clause bwdFwdClauses [] = [] bwdFwdClauses ((inl f , n) ∷ fs) = bwdFwdClauses fs ∷ʳ bwdFwdClause (makeVarsFrom 1) (v 0) (map-snd (5 +_) (f , n)) bwdFwdClauses ((inr _ , n) ∷ fs) = bwdFwdClauses fs univalentRecord : R.Term univalentRecord = R.def (quote explicitUnivalentStr) (R.unknown v∷ R.unknown v∷ fwd v∷ bwd v∷ fwdBwd v∷ bwdFwd v∷ []) macro autoFieldEquiv : R.Term → R.Term → R.Term → R.Term → R.TC Unit autoFieldEquiv spec A B hole = (R.reduce spec >>= parseFieldSpec) >>= λ (ℓ , ℓ₂ , S , f) → buildDesc FUEL ℓ ℓ₂ S >>= λ d → R.unify hole (R.def (quote M.MacroEquivStr) (d v∷ tStrMap A f v∷ tStrMap B f v∷ [])) autoUnivalentRecord : R.Term → R.Term → R.TC Unit autoUnivalentRecord t hole = (R.reduce t >>= parseSpec) >>= λ spec → -- R.typeError (R.strErr "WOW: " ∷ R.termErr (main spec) ∷ []) R.unify (main spec) hole where module _ (spec : InternalSpec TypedTerm) where open InternalSpec spec mapUp : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → (ℕ → A → B) → ℕ → List A → List B mapUp f _ [] = [] mapUp f n (x ∷ xs) = f n x ∷ mapUp f (suc n) xs closureSpec : InternalSpec ℕ closureSpec .InternalSpec.srec = srec closureSpec .InternalSpec.erec = erec closureSpec .InternalSpec.fields = mapUp (λ n → map-snd (λ _ → n)) 0 fields closure : R.Term closure = iter (List.length fields) (vlam "") (univalentRecord closureSpec) env : List (R.Arg R.Term) env = List.map (varg ∘ term ∘ snd) (List.rev fields) closureTy : R.Term closureTy = List.foldr (λ ty cod → R.def (quote Fun) (ty v∷ cod v∷ [])) (R.def (quote ExplicitUnivalentStr) (srec v∷ erec v∷ [])) (List.map (type ∘ snd) (List.rev fields)) main : R.Term main = R.def (quote idfun) (closureTy v∷ closure v∷ env)
36.903084
108
0.568342
197c665b78d92958f376910ce487ceb084b80c51
113
agda
Agda
Cubical/Data/FinData.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
1
2020-03-23T23:52:11.000Z
2020-03-23T23:52:11.000Z
Cubical/Data/FinData.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
null
null
null
Cubical/Data/FinData.agda
ryanorendorff/cubical
c67854d2e11aafa5677e25a09087e176fafd3e43
[ "MIT" ]
null
null
null
{-# OPTIONS --cubical --safe #-} module Cubical.Data.FinData where open import Cubical.Data.FinData.Base public
22.6
44
0.752212
1bc753a262148715f188b88c27ae4fceb16508d5
1,001
agda
Agda
Data/Array/Skew.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
6
2020-09-11T17:45:41.000Z
2021-11-16T08:11:34.000Z
Data/Array/Skew.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
null
null
null
Data/Array/Skew.agda
oisdk/agda-playground
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
[ "MIT" ]
1
2021-11-11T12:30:21.000Z
2021-11-11T12:30:21.000Z
{-# OPTIONS --cubical --safe #-} module Data.Array.Skew where open import Prelude open import Data.Binary.Skew open import Data.List open import Data.Nat using (_+_) private variable p : Level P : ℕ → Type p n : ℕ ns : 𝔹 infixl 6 _∔_ _∔_ : ℕ → ℕ → ℕ zero ∔ m = m suc n ∔ m = n ∔ suc m infixl 4 _⊕_ _⊕_ : (ℕ → Type p) → ℕ → ℕ → Type p _⊕_ P n m = P (n ∔ m) data Spine⁺ {p} (P : ℕ → Type p) : 𝔹 → Type p where nil : Spine⁺ P [] conss : ∀ n → P n → Spine⁺ (P ⊕ suc n) ns → Spine⁺ P (n ∷ ns) data Spine {p} (P : ℕ → Type p) : 𝔹 → Type p where nil : Spine P [] conss : ∀ n → P n → Spine⁺ (P ⊕ n) ns → Spine P (n ∷ ns) -- cons : (∀ {m} → P m → P m → P (suc m)) → P zero → Spine P ns → Spine P (inc ns) -- cons _*_ x nil = conss zero x nil -- cons _*_ x (conss n x₁ nil) = conss zero x (conss n x₁ nil) -- cons _*_ x (conss n x₁ (conss zero x₂ xs)) = conss (suc n) (x₁ * x₁) xs -- cons _*_ x (conss n x₁ (conss (suc m) x₂ xs)) = conss zero x (conss n x₁ (conss m x₂ {!!}))
25.666667
94
0.545455
fd05f0e802c6e2e936f46642d38d911abdabaaeb
2,342
agda
Agda
data/github.com/effectfully/STLC/3826d7555f37d032d07cf414c7f6770fc32918f1/src/STLC/Lib/MaybeElim.agda
ajnavarro/language-dataset
34e2980af98ff2ded500619edce3e0907a6e9050
[ "MIT" ]
9
2018-08-07T11:54:33.000Z
2022-03-11T09:48:45.000Z
data/github.com/effectfully/STLC/3826d7555f37d032d07cf414c7f6770fc32918f1/src/STLC/Lib/MaybeElim.agda
ajnavarro/language-dataset
34e2980af98ff2ded500619edce3e0907a6e9050
[ "MIT" ]
91
2019-11-11T15:41:26.000Z
2022-03-21T04:17:18.000Z
data/github.com/effectfully/STLC/3826d7555f37d032d07cf414c7f6770fc32918f1/src/STLC/Lib/MaybeElim.agda
ajnavarro/language-dataset
34e2980af98ff2ded500619edce3e0907a6e9050
[ "MIT" ]
3
2019-11-13T12:44:41.000Z
2022-01-06T19:34:26.000Z
module STLC.Lib.MaybeElim where open import Level open import Function open import Relation.Binary.PropositionalEquality open import Data.Unit.Base open import Data.Bool.Base open import Data.Maybe.Base infixl 1 _>>=ᵀ_ _>>=ᵗ_ _>>=⊤_ infixl 4 _<$>ᵗ_ infixr 1 _>=>ᵗ_ infixr 10 _<∘>ᵗ_ data _>>=ᵀ_ {α β} {A : Set α} : (mx : Maybe A) -> (∀ x -> mx ≡ just x -> Set β) -> Set β where nothingᵗ : ∀ {B} -> nothing >>=ᵀ B justᵗ : ∀ {x B} -> B x refl -> just x >>=ᵀ B -- We could write (Set (maybe (const β) zero mx)), -- but I don't want to introduce dependency at the type level. FromJustᵗ : ∀ {α β} {A : Set α} {mx : Maybe A} {B : ∀ x -> mx ≡ just x -> Set β} -> mx >>=ᵀ B -> Set β FromJustᵗ nothingᵗ = Lift ⊤ FromJustᵗ (justᵗ {x} {B} y) = B x refl fromJustᵗ : ∀ {α β} {A : Set α} {mx : Maybe A} {B : ∀ x -> mx ≡ just x -> Set β} -> (yᵗ : mx >>=ᵀ B) -> FromJustᵗ yᵗ fromJustᵗ nothingᵗ = _ fromJustᵗ (justᵗ y) = y _>>=ᵗ_ : ∀ {α β} {A : Set α} {B : A -> Set β} -> (mx : Maybe A) -> (∀ x -> B x) -> mx >>=ᵀ λ x _ -> B x nothing >>=ᵗ f = nothingᵗ just x >>=ᵗ f = justᵗ (f x) _>>=⊤_ : ∀ {α β} {A : Set α} {B : A -> Set β} -> (mx : Maybe A) -> (g : ∀ x -> B x) -> FromJustᵗ (mx >>=ᵗ g) mx >>=⊤ g = fromJustᵗ $ mx >>=ᵗ g runᵗ : ∀ {α β} {A : Set α} {mx : Maybe A} {B : ∀ x -> mx ≡ just x -> Set β} {x} -> mx >>=ᵀ B -> (p : mx ≡ just x) -> B x p runᵗ (justᵗ y) refl = y _<$>ᵗ_ : ∀ {α β γ} {A : Set α} {mx : Maybe A} {B : ∀ x -> mx ≡ just x -> Set β} {C : ∀ {x} {p : mx ≡ just x} -> B x p -> Set γ} -> (∀ {x} {p : mx ≡ just x} -> (y : B x p) -> C y) -> (yᵗ : mx >>=ᵀ B) -> mx >>=ᵀ λ _ -> C ∘ runᵗ yᵗ g <$>ᵗ nothingᵗ = nothingᵗ g <$>ᵗ justᵗ y = justᵗ (g y) _>=>ᵗ_ : ∀ {α β γ} {A : Set α} {B : A -> Set β} {C : ∀ {x} -> B x -> Set γ} -> (f : ∀ x -> Maybe (B x)) -> (∀ {x} -> (y : B x) -> C y) -> ∀ x -> f x >>=ᵀ λ y _ -> C y (f >=>ᵗ g) x = f x >>=ᵗ g _<∘>ᵗ_ : ∀ {α β γ δ} {A : Set α} {B : A -> Set β} {f : ∀ x -> Maybe (B x)} {C : ∀ x y -> f x ≡ just y -> Set γ} {D : ∀ {x y} {p : f x ≡ just y} -> C x y p -> Set δ} -> (∀ {x y} {p : f x ≡ just y} -> (z : C x y p) -> D z) -> (g : ∀ x -> f x >>=ᵀ C x) -> ∀ x -> f x >>=ᵀ λ _ -> D ∘ runᵗ (g x) (h <∘>ᵗ g) x = h <$>ᵗ g x
35.484848
94
0.434244