Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.Equivalences2
open import lib.types.Paths
open import lib.types.Pi
open import lib.types.Sigma
open import lib.types.TLevel
module lib.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))
subtype= : ∀ {i j} {A : Type i} {P : A → Type j}
→ (x y : Σ A P) → Type i
subtype= (a₁ , _) (a₂ , _) = a₁ == a₂
subtype=-in : ∀ {i j} {A : Type i} {P : A → Type j}
→ (p : (x : A) → is-prop (P x)) → {x y : Σ A P}
→ subtype= x y → x == y
subtype=-in p idp = pair= idp (fst (p _ _ _))
-- Groupoids
is-gpd : {i : ULevel} → Type i → Type i
is-gpd = has-level 1
-- 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= = subtype=
nType=-in : ∀ {i} {n : ℕ₋₂} {A B : n -Type i} → fst A == fst B → A == B
nType=-in = subtype=-in (λ _ → 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
| {
"alphanum_fraction": 0.4993227227,
"avg_line_length": 34.9467455621,
"ext": "agda",
"hexsha": "d358dc939378e5420f7215b20994a0e7fa2e13a0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmknapp/HoTT-Agda",
"max_forks_repo_path": "core/lib/NType2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cmknapp/HoTT-Agda",
"max_issues_repo_path": "core/lib/NType2.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmknapp/HoTT-Agda",
"max_stars_repo_path": "core/lib/NType2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2448,
"size": 5906
} |
-- Record expressions are translated to copattern matches.
module _ where
record _×_ (A B : Set) : Set where
constructor _,_
field
fst : A
snd : B
open _×_
dup : ∀ {A} → A → A × A
dup x = record {fst = x; snd = x}
-- dup is translated internally to
-- dup x .fst = x
-- dup x .snd = x
-- so dup should not normalise to λ x → x , x
dup' : ∀ {A} → A → A × A
dup' x = x , x
-- But dup' is not translated, so dup' does reduce.
| {
"alphanum_fraction": 0.5807174888,
"avg_line_length": 17.84,
"ext": "agda",
"hexsha": "62b8aaf9a6a6a0cacca737335694f4c2a7b5f7d7",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/CopatternTranslation.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/CopatternTranslation.agda",
"max_line_length": 58,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/CopatternTranslation.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 151,
"size": 446
} |
{-# OPTIONS --without-K #-}
module hott.level.closure.core where
open import level
open import decidable
open import equality
open import function.isomorphism.core
-- open import function.isomorphism.properties
open import sum
open import hott.level.core
open import hott.equivalence.core
open import hott.univalence
open import sets.nat.core
-- open import sets.nat.ordering.leq.core
-- open import sets.nat.ordering.leq.decide
open import sets.empty
open import sets.unit
Σ-contr : ∀ {i j}{X : Set i}{Y : X → Set j}
→ contr X → ((x : X) → contr (Y x))
→ contr (Σ X Y)
Σ-contr {X = X}{Y = Y} (x₀ , cx) hY
= (x₀ , proj₁ (hY x₀)) , λ { (x , y) → c x y }
where
c : (x : X)(y : Y x) → (x₀ , proj₁ (hY x₀)) ≡ (x , y)
c x y = ap (λ x → (x , proj₁ (hY x))) (cx x)
· ap (_,_ x) (proj₂ (hY x) y)
×-contr : ∀ {i j}{X : Set i}{Y : Set j}
→ contr X → contr Y
→ contr (X × Y)
×-contr hX hY = Σ-contr hX (λ _ → hY)
unique-contr : ∀ {i}{A B : Set i}
→ contr A
→ contr B
→ A ≡ B
unique-contr {i}{A}{B} hA hB = ≈⇒≡ (f , f-we)
where
f : A → B
f _ = proj₁ hB
f-we : weak-equiv f
f-we b = ×-contr hA (h↑ hB _ _)
-- h-≤ : ∀ {i n m}{X : Set i}
-- → n ≤ m → h n X → h m X
-- h-≤ {m = 0} z≤n hX = hX
-- h-≤ {m = suc m} z≤n hX = λ x y
-- → h-≤ {m = m} z≤n (h↑ hX x y)
-- h-≤ (s≤s p) hX = λ x y
-- → h-≤ p (hX x y)
--
-- h! : ∀ {i n m}{X : Set i}
-- → {p : True (n ≤? m)}
-- → h n X → h m X
-- h! {p = p} = h-≤ (witness p)
abstract
-- retractions preserve levels
retract-level : ∀ {i j n} {X : Set i}{Y : Set j}
→ (f : X → Y)(g : Y → X)
→ ((y : Y) → f (g y) ≡ y)
→ h n X → h n Y
retract-level {n = 0}{X}{Y} f g r (x , c) = (f x , c')
where
c' : (y : Y) → f x ≡ y
c' y = ap f (c (g y)) · r y
retract-level {n = suc n}{X}{Y} f g r hX = λ y y'
→ retract-level f' g' r' (hX (g y) (g y'))
where
f' : {y y' : Y} → g y ≡ g y' → y ≡ y'
f' {y}{y'} p = sym (r y) · ap f p · r y'
g' : {y y' : Y} → y ≡ y' → g y ≡ g y'
g' = ap g
r' : {y y' : Y}(p : y ≡ y') → f' (g' p) ≡ p
r' {y}{.y} refl = ap (λ α → α · r y) (left-unit (sym (r y)))
· right-inverse (r y)
iso-level : ∀ {i j n}{X : Set i}{Y : Set j}
→ X ≅ Y → h n X → h n Y
iso-level (iso f g H K) = retract-level f g K
| {
"alphanum_fraction": 0.4492813142,
"avg_line_length": 28.6470588235,
"ext": "agda",
"hexsha": "693c40d24ec296db40d4f8ae61fa0ac253335ead",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "hott/level/closure/core.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "hott/level/closure/core.agda",
"max_line_length": 66,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "hott/level/closure/core.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 1016,
"size": 2435
} |
{-# OPTIONS --safe #-}
-- This is a file for dealing with Monuses: these are monoids that are like the
-- positive half of a group. Much of my info on them comes from these papers:
--
-- * Wehrung, Friedrich. ‘Injective Positively Ordered Monoids I’. Journal of
-- Pure and Applied Algebra 83, no. 1 (11 November 1992): 43–82.
-- https://doi.org/10.1016/0022-4049(92)90104-N.
-- * Wehrung, Friedrich. ‘Embedding Simple Commutative Monoids into Simple
-- Refinement Monoids’. Semigroup Forum 56, no. 1 (January 1998): 104–29.
-- https://doi.org/10.1007/s00233-002-7008-0.
-- * Amer, K. ‘Equationally Complete Classes of Commutative Monoids with Monus’.
-- Algebra Universalis 18, no. 1 (1 February 1984): 129–31.
-- https://doi.org/10.1007/BF01182254.
-- * Wehrung, Friedrich. ‘Metric Properties of Positively Ordered Monoids’.
-- Forum Mathematicum 5, no. 5 (1993).
-- https://doi.org/10.1515/form.1993.5.183.
-- * Wehrung, Friedrich. ‘Restricted Injectivity, Transfer Property and
-- Decompositions of Separative Positively Ordered Monoids.’ Communications in
-- Algebra 22, no. 5 (1 January 1994): 1747–81.
-- https://doi.org/10.1080/00927879408824934.
--
-- These monoids have a preorder defined on them, the algebraic preorder:
--
-- x ≤ y = ∃ z × (y ≡ x ∙ z)
--
-- The _∸_ operator extracts the z from above, if it exists.
module Algebra.Monus where
open import Prelude
open import Algebra
open import Relation.Binary
open import Path.Reasoning
open import Function.Reasoning
-- Positively ordered monoids.
--
-- These are monoids which have a preorder that respects the monoid operation
-- in a straightforward way.
record POM ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field commutativeMonoid : CommutativeMonoid ℓ₁
open CommutativeMonoid commutativeMonoid public
field preorder : Preorder 𝑆 ℓ₂
open Preorder preorder public renaming (refl to ≤-refl)
field
positive : ∀ x → ε ≤ x
≤-cong : ∀ x {y z} → y ≤ z → x ∙ y ≤ x ∙ z
x≤x∙y : ∀ {x y} → x ≤ x ∙ y
x≤x∙y {x} {y} = subst (_≤ x ∙ y) (∙ε x) (≤-cong x (positive y))
≤-congʳ : ∀ x {y z} → y ≤ z → y ∙ x ≤ z ∙ x
≤-congʳ x {y} {z} p = subst₂ _≤_ (comm x y) (comm x z) (≤-cong x p)
alg-≤-trans : ∀ {x y z k₁ k₂} → y ≡ x ∙ k₁ → z ≡ y ∙ k₂ → z ≡ x ∙ (k₁ ∙ k₂)
alg-≤-trans {x} {y} {z} {k₁} {k₂} y≡x∙k₁ z≡y∙k₂ =
z ≡⟨ z≡y∙k₂ ⟩
y ∙ k₂ ≡⟨ cong (_∙ k₂) y≡x∙k₁ ⟩
(x ∙ k₁) ∙ k₂ ≡⟨ assoc x k₁ k₂ ⟩
x ∙ (k₁ ∙ k₂) ∎
infix 4 _≺_
_≺_ : 𝑆 → 𝑆 → Type _
x ≺ y = ∃ k × (y ≡ x ∙ k) × (k ≢ ε)
-- Total Antisymmetric POM
record TAPOM ℓ₁ ℓ₂ : Type (ℓsuc (ℓ₁ ℓ⊔ ℓ₂)) where
field pom : POM ℓ₁ ℓ₂
open POM pom public using (preorder; _≤_; ≤-cong; ≤-congʳ; x≤x∙y; commutativeMonoid; positive)
open CommutativeMonoid commutativeMonoid public
field
_≤|≥_ : Total _≤_
antisym : Antisymmetric _≤_
totalOrder : TotalOrder 𝑆 ℓ₂ ℓ₂
totalOrder = fromPartialOrder (record { preorder = preorder ; antisym = antisym }) _≤|≥_
open TotalOrder totalOrder public hiding (_≤|≥_; antisym) renaming (refl to ≤-refl)
-- Every commutative monoid generates a positively ordered monoid
-- called the "algebraic" or "minimal" pom
module AlgebraicPOM {ℓ} (mon : CommutativeMonoid ℓ) where
commutativeMonoid = mon
open CommutativeMonoid mon
infix 4 _≤_
_≤_ : 𝑆 → 𝑆 → Type _
x ≤ y = ∃ z × (y ≡ x ∙ z)
-- The snd here is the same proof as alg-≤-trans, so could be refactored out.
≤-trans : Transitive _≤_
≤-trans (k₁ , _) (k₂ , _) .fst = k₁ ∙ k₂
≤-trans {x} {y} {z} (k₁ , y≡x∙k₁) (k₂ , z≡y∙k₂) .snd =
z ≡⟨ z≡y∙k₂ ⟩
y ∙ k₂ ≡⟨ cong (_∙ k₂) y≡x∙k₁ ⟩
(x ∙ k₁) ∙ k₂ ≡⟨ assoc x k₁ k₂ ⟩
x ∙ (k₁ ∙ k₂) ∎
preorder : Preorder 𝑆 ℓ
Preorder._≤_ preorder = _≤_
Preorder.refl preorder = ε , sym (∙ε _)
Preorder.trans preorder = ≤-trans
positive : ∀ x → ε ≤ x
positive x = x , sym (ε∙ x)
≤-cong : ∀ x {y z} → y ≤ z → x ∙ y ≤ x ∙ z
≤-cong x (k , z≡y∙k) = k , cong (x ∙_) z≡y∙k ; sym (assoc x _ k)
algebraic-pom : ∀ {ℓ} → CommutativeMonoid ℓ → POM ℓ ℓ
algebraic-pom mon = record { AlgebraicPOM mon }
-- Total Minimal POM
record TMPOM ℓ : Type (ℓsuc ℓ) where
field commutativeMonoid : CommutativeMonoid ℓ
pom : POM _ _
pom = algebraic-pom commutativeMonoid
open POM pom public
infix 4 _≤|≥_
field _≤|≥_ : Total _≤_
<⇒≺ : ∀ x y → y ≰ x → x ≺ y
<⇒≺ x y x<y with x ≤|≥ y
... | inr y≤x = ⊥-elim (x<y y≤x)
... | inl (k , y≡x∙k) = λ
where
.fst → k
.snd .fst → y≡x∙k
.snd .snd k≡ε → x<y (ε , sym (∙ε y ; y≡x∙k ; cong (x ∙_) k≡ε ; ∙ε x))
infixl 6 _∸_
_∸_ : 𝑆 → 𝑆 → 𝑆
x ∸ y = either′ (const ε) fst (x ≤|≥ y)
x∸y≤x : ∀ x y → x ∸ y ≤ x
x∸y≤x x y with x ≤|≥ y
... | inl (k , p) = positive x
... | inr (k , x≡y∙k) = y , x≡y∙k ; comm y k
-- Total Minimal Antisymmetric POM
record TMAPOM ℓ : Type (ℓsuc ℓ) where
field tmpom : TMPOM ℓ
open TMPOM tmpom public using (_≤_; _≤|≥_; positive; alg-≤-trans; _≺_; <⇒≺; _∸_; x∸y≤x)
field antisym : Antisymmetric _≤_
tapom : TAPOM _ _
TAPOM.pom tapom = TMPOM.pom tmpom
TAPOM._≤|≥_ tapom = _≤|≥_
TAPOM.antisym tapom = antisym
open TAPOM tapom public hiding (antisym; _≤|≥_; _≤_; positive)
zeroSumFree : ∀ x y → x ∙ y ≡ ε → x ≡ ε
zeroSumFree x y x∙y≡ε = antisym (y , sym x∙y≡ε) (positive x)
≤‿∸‿cancel : ∀ x y → x ≤ y → (y ∸ x) ∙ x ≡ y
≤‿∸‿cancel x y x≤y with y ≤|≥ x
... | inl y≤x = ε∙ x ; antisym x≤y y≤x
... | inr (k , y≡x∙k) = comm k x ; sym y≡x∙k
∸‿comm : ∀ x y → x ∙ (y ∸ x) ≡ y ∙ (x ∸ y)
∸‿comm x y with y ≤|≥ x | x ≤|≥ y
... | inl y≤x | inl x≤y = cong (_∙ ε) (antisym x≤y y≤x)
... | inr (k , y≡x∙k) | inl x≤y = sym y≡x∙k ; sym (∙ε y)
... | inl y≤x | inr (k , x≥y) = ∙ε x ; x≥y
... | inr (k₁ , y≡x∙k₁) | inr (k₂ , x≡y∙k₂) =
x ∙ k₁ ≡˘⟨ y≡x∙k₁ ⟩
y ≡⟨ antisym (k₂ , x≡y∙k₂) (k₁ , y≡x∙k₁) ⟩
x ≡⟨ x≡y∙k₂ ⟩
y ∙ k₂ ∎
∸‿≺ : ∀ x y → x ≢ ε → y ≢ ε → x ∸ y ≺ x
∸‿≺ x y x≢ε y≢ε with x ≤|≥ y
... | inl _ = x , sym (ε∙ x) , x≢ε
... | inr (k , x≡y∙k) = y , x≡y∙k ; comm y k , y≢ε
-- Commutative Monoids with Monus
record CMM ℓ : Type (ℓsuc ℓ) where
field commutativeMonoid : CommutativeMonoid ℓ
pom : POM _ _
pom = algebraic-pom commutativeMonoid
open POM pom public
field _∸_ : 𝑆 → 𝑆 → 𝑆
infixl 6 _∸_
field
∸‿comm : ∀ x y → x ∙ (y ∸ x) ≡ y ∙ (x ∸ y)
∸‿assoc : ∀ x y z → (x ∸ y) ∸ z ≡ x ∸ (y ∙ z)
∸‿inv : ∀ x → x ∸ x ≡ ε
ε∸ : ∀ x → ε ∸ x ≡ ε
∸ε : ∀ x → x ∸ ε ≡ x
∸ε x =
x ∸ ε ≡˘⟨ ε∙ (x ∸ ε) ⟩
ε ∙ (x ∸ ε) ≡⟨ ∸‿comm ε x ⟩
x ∙ (ε ∸ x) ≡⟨ cong (x ∙_) (ε∸ x) ⟩
x ∙ ε ≡⟨ ∙ε x ⟩
x ∎
∸≤ : ∀ x y → x ≤ y → x ∸ y ≡ ε
∸≤ x y (k , y≡x∙k) =
x ∸ y ≡⟨ cong (x ∸_) y≡x∙k ⟩
x ∸ (x ∙ k) ≡˘⟨ ∸‿assoc x x k ⟩
(x ∸ x) ∸ k ≡⟨ cong (_∸ k) (∸‿inv x) ⟩
ε ∸ k ≡⟨ ε∸ k ⟩
ε ∎
∣_-_∣ : 𝑆 → 𝑆 → 𝑆
∣ x - y ∣ = (x ∸ y) ∙ (y ∸ x)
_⊔₂_ : 𝑆 → 𝑆 → 𝑆
x ⊔₂ y = x ∙ y ∙ ∣ x - y ∣
_⊓₂_ : 𝑆 → 𝑆 → 𝑆
x ⊓₂ y = (x ∙ y) ∸ ∣ x - y ∣
-- Cancellative Commutative Monoids with Monus
record CCMM ℓ : Type (ℓsuc ℓ) where
field cmm : CMM ℓ
open CMM cmm public
field ∸‿cancel : ∀ x y → (x ∙ y) ∸ x ≡ y
cancelˡ : Cancellativeˡ _∙_
cancelˡ x y z x∙y≡x∙z =
y ≡˘⟨ ∸‿cancel x y ⟩
(x ∙ y) ∸ x ≡⟨ cong (_∸ x) x∙y≡x∙z ⟩
(x ∙ z) ∸ x ≡⟨ ∸‿cancel x z ⟩
z ∎
cancelʳ : Cancellativeʳ _∙_
cancelʳ x y z y∙x≡z∙x =
y ≡˘⟨ ∸‿cancel x y ⟩
(x ∙ y) ∸ x ≡⟨ cong (_∸ x) (comm x y) ⟩
(y ∙ x) ∸ x ≡⟨ cong (_∸ x) y∙x≡z∙x ⟩
(z ∙ x) ∸ x ≡⟨ cong (_∸ x) (comm z x) ⟩
(x ∙ z) ∸ x ≡⟨ ∸‿cancel x z ⟩
z ∎
zeroSumFree : ∀ x y → x ∙ y ≡ ε → x ≡ ε
zeroSumFree x y x∙y≡ε =
x ≡˘⟨ ∸‿cancel y x ⟩
(y ∙ x) ∸ y ≡⟨ cong (_∸ y) (comm y x) ⟩
(x ∙ y) ∸ y ≡⟨ cong (_∸ y) x∙y≡ε ⟩
ε ∸ y ≡⟨ ε∸ y ⟩
ε ∎
antisym : Antisymmetric _≤_
antisym {x} {y} (k₁ , y≡x∙k₁) (k₂ , x≡y∙k₂) =
x ≡⟨ x≡y∙k₂ ⟩
y ∙ k₂ ≡⟨ [ lemma ]⇒ y ∙ ε ≡ y ∙ (k₂ ∙ k₁)
⟨ cancelˡ y ε (k₂ ∙ k₁) ⟩⇒ ε ≡ k₂ ∙ k₁
⟨ sym ⟩⇒ k₂ ∙ k₁ ≡ ε
⟨ zeroSumFree k₂ k₁ ⟩⇒ k₂ ≡ ε
⟨ cong (y ∙_) ⟩⇒ y ∙ k₂ ≡ y ∙ ε ⇒∎ ⟩
y ∙ ε ≡⟨ ∙ε y ⟩
y ∎
where
lemma = ∙ε y ; alg-≤-trans x≡y∙k₂ y≡x∙k₁
partialOrder : PartialOrder _ _
PartialOrder.preorder partialOrder = preorder
PartialOrder.antisym partialOrder = antisym
≺⇒< : ∀ x y → x ≺ y → y ≰ x
≺⇒< x y (k₁ , y≡x∙k₁ , k₁≢ε) (k₂ , x≡y∙k₂) =
[ x ∙ ε ≡⟨ ∙ε x ⟩
x ≡⟨ x≡y∙k₂ ⟩
y ∙ k₂ ≡⟨ cong (_∙ k₂) y≡x∙k₁ ⟩
(x ∙ k₁) ∙ k₂ ≡⟨ assoc x k₁ k₂ ⟩
x ∙ (k₁ ∙ k₂) ∎ ]⇒ x ∙ ε ≡ x ∙ (k₁ ∙ k₂)
⟨ cancelˡ x ε (k₁ ∙ k₂) ⟩⇒ ε ≡ k₁ ∙ k₂
⟨ sym ⟩⇒ k₁ ∙ k₂ ≡ ε
⟨ zeroSumFree k₁ k₂ ⟩⇒ k₁ ≡ ε
⟨ k₁≢ε ⟩⇒ ⊥ ⇒∎
≤⇒<⇒≢ε : ∀ x y → (x≤y : x ≤ y) → y ≰ x → fst x≤y ≢ ε
≤⇒<⇒≢ε x y (k₁ , y≡x∙k₁) y≰x k₁≡ε = y≰x λ
where
.fst → ε
.snd → x ≡˘⟨ ∙ε x ⟩
x ∙ ε ≡˘⟨ cong (x ∙_) k₁≡ε ⟩
x ∙ k₁ ≡˘⟨ y≡x∙k₁ ⟩
y ≡˘⟨ ∙ε y ⟩
y ∙ ε ∎
≤-cancelʳ : ∀ x y z → y ∙ x ≤ z ∙ x → y ≤ z
≤-cancelʳ x y z (k , z∙x≡y∙x∙k) .fst = k
≤-cancelʳ x y z (k , z∙x≡y∙x∙k) .snd = cancelʳ x z (y ∙ k) $
z ∙ x ≡⟨ z∙x≡y∙x∙k ⟩
(y ∙ x) ∙ k ≡⟨ assoc y x k ⟩
y ∙ (x ∙ k) ≡⟨ cong (y ∙_) (comm x k) ⟩
y ∙ (k ∙ x) ≡˘⟨ assoc y k x ⟩
(y ∙ k) ∙ x ∎
≤-cancelˡ : ∀ x y z → x ∙ y ≤ x ∙ z → y ≤ z
≤-cancelˡ x y z (k , x∙z≡x∙y∙k) .fst = k
≤-cancelˡ x y z (k , x∙z≡x∙y∙k) .snd =
cancelˡ x z (y ∙ k) (x∙z≡x∙y∙k ; assoc x y k)
≺-irrefl : Irreflexive _≺_
≺-irrefl {x} (k , x≡x∙k , k≢ε) = k≢ε (sym (cancelˡ x ε k (∙ε x ; x≡x∙k)))
≤∸ : ∀ x y → (x≤y : x ≤ y) → y ∸ x ≡ fst x≤y
≤∸ x y (k , y≡x∙k) =
y ∸ x ≡⟨ cong (_∸ x) y≡x∙k ⟩
(x ∙ k) ∸ x ≡⟨ ∸‿cancel x k ⟩
k ∎
≤‿∸‿cancel : ∀ x y → x ≤ y → (y ∸ x) ∙ x ≡ y
≤‿∸‿cancel x y (k , y≡x∙k) =
(y ∸ x) ∙ x ≡⟨ cong (λ y → (y ∸ x) ∙ x) y≡x∙k ⟩
((x ∙ k) ∸ x) ∙ x ≡⟨ cong (_∙ x) (∸‿cancel x k) ⟩
k ∙ x ≡⟨ comm k x ⟩
x ∙ k ≡˘⟨ y≡x∙k ⟩
y ∎
-- Cancellative total minimal antisymmetric pom (has monus)
record CTMAPOM ℓ : Type (ℓsuc ℓ) where
field tmapom : TMAPOM ℓ
open TMAPOM tmapom public
field cancel : Cancellativeˡ _∙_
module cmm where
∸≤ : ∀ x y → x ≤ y → x ∸ y ≡ ε
∸≤ x y x≤y with x ≤|≥ y
∸≤ x y x≤y | inl _ = refl
∸≤ x y (k₁ , y≡x∙k₁) | inr (k₂ , x≡y∙k₂) =
[ lemma ]⇒ y ∙ ε ≡ y ∙ (k₂ ∙ k₁)
⟨ cancel y ε (k₂ ∙ k₁) ⟩⇒ ε ≡ k₂ ∙ k₁
⟨ sym ⟩⇒ k₂ ∙ k₁ ≡ ε
⟨ zeroSumFree k₂ k₁ ⟩⇒ k₂ ≡ ε ⇒∎
where
lemma = ∙ε y ; alg-≤-trans x≡y∙k₂ y≡x∙k₁
∸‿inv : ∀ x → x ∸ x ≡ ε
∸‿inv x = ∸≤ x x ≤-refl
ε∸ : ∀ x → ε ∸ x ≡ ε
ε∸ x = ∸≤ ε x (positive x)
∸‿assoc : ∀ x y z → (x ∸ y) ∸ z ≡ x ∸ (y ∙ z)
∸‿assoc x y z with x ≤|≥ y
∸‿assoc x y z | inl x≤y = ε∸ z ; sym (∸≤ x (y ∙ z) (≤-trans x≤y x≤x∙y))
∸‿assoc x y z | inr x≥y with x ≤|≥ y ∙ z
∸‿assoc x y z | inr (k₁ , x≡y∙k₁) | inl (k₂ , y∙z≡x∙k₂) = ∸≤ k₁ z (k₂ , lemma)
where
lemma : z ≡ k₁ ∙ k₂
lemma = cancel y z (k₁ ∙ k₂) (alg-≤-trans x≡y∙k₁ y∙z≡x∙k₂)
∸‿assoc x y z | inr (k , x≡y∙k) | inr x≥y∙z with k ≤|≥ z
∸‿assoc x y z | inr (k₁ , x≡y∙k₁) | inr (k₂ , x≡y∙z∙k₂) | inl (k₃ , z≡k₁∙k₃) =
[ lemma₁ ]⇒ ε ≡ k₂ ∙ k₃
⟨ sym ⟩⇒ k₂ ∙ k₃ ≡ ε
⟨ zeroSumFree k₂ k₃ ⟩⇒ k₂ ≡ ε
⟨ sym ⟩⇒ ε ≡ k₂ ⇒∎
where
lemma₃ =
y ∙ k₁ ≡˘⟨ x≡y∙k₁ ⟩
x ≡⟨ x≡y∙z∙k₂ ⟩
(y ∙ z) ∙ k₂ ≡⟨ assoc y z k₂ ⟩
y ∙ (z ∙ k₂) ∎
lemma₂ =
k₁ ∙ ε ≡⟨ ∙ε k₁ ⟩
k₁ ≡⟨ alg-≤-trans z≡k₁∙k₃ (cancel y k₁ (z ∙ k₂) lemma₃) ⟩
k₁ ∙ (k₃ ∙ k₂) ∎
lemma₁ =
ε ≡⟨ cancel k₁ ε (k₃ ∙ k₂) lemma₂ ⟩
k₃ ∙ k₂ ≡⟨ comm k₃ k₂ ⟩
k₂ ∙ k₃ ∎
∸‿assoc x y z | inr (k₁ , x≡y∙k₁) | inr (k₂ , x≡y∙z∙k₂) | inr (k₃ , k₁≡z∙k₃) =
cancel z k₃ k₂ lemma₂
where
lemma₁ =
y ∙ k₁ ≡˘⟨ x≡y∙k₁ ⟩
x ≡⟨ x≡y∙z∙k₂ ⟩
(y ∙ z) ∙ k₂ ≡⟨ assoc y z k₂ ⟩
y ∙ (z ∙ k₂) ∎
lemma₂ =
z ∙ k₃ ≡˘⟨ k₁≡z∙k₃ ⟩
k₁ ≡⟨ cancel y k₁ (z ∙ k₂) lemma₁ ⟩
z ∙ k₂ ∎
open cmm public
∸‿cancel : ∀ x y → (x ∙ y) ∸ x ≡ y
∸‿cancel x y with (x ∙ y) ≤|≥ x
... | inl x∙y≤x = sym (cancel x y ε (antisym x∙y≤x x≤x∙y ; sym (∙ε x)))
... | inr (k , x∙y≡x∙k) = sym (cancel x y k x∙y≡x∙k)
ccmm : CCMM _
ccmm = record { ∸‿cancel = ∸‿cancel
; cmm = record { cmm
; ∸‿comm = ∸‿comm
; commutativeMonoid = commutativeMonoid } }
open CCMM ccmm public
using (cancelʳ; cancelˡ; ∸ε; ≺⇒<; ≤⇒<⇒≢ε; _⊔₂_; _⊓₂_; ≺-irrefl; ≤∸)
∸‿< : ∀ x y → x ≢ ε → y ≢ ε → x ∸ y < x
∸‿< x y x≢ε y≢ε = ≺⇒< (x ∸ y) x (∸‿≺ x y x≢ε y≢ε)
∸‿<-< : ∀ x y → x < y → x ≢ ε → y ∸ x < y
∸‿<-< x y x<y x≢ε = ∸‿< y x (λ y≡ε → x<y (x , sym (cong (_∙ x) y≡ε ; ε∙ x))) x≢ε
2× : 𝑆 → 𝑆
2× x = x ∙ x
open import Relation.Binary.Lattice totalOrder
double-max : ∀ x y → 2× (x ⊔ y) ≡ x ⊔₂ y
double-max x y with x ≤|≥ y | y ≤|≥ x
double-max x y | inl x≤y | inl y≤x =
x ∙ x ≡⟨ cong (x ∙_) (antisym x≤y y≤x) ⟩
x ∙ y ≡˘⟨ ∙ε (x ∙ y) ⟩
(x ∙ y) ∙ ε ≡˘⟨ cong ((x ∙ y) ∙_) (ε∙ ε) ⟩
(x ∙ y) ∙ (ε ∙ ε) ∎
double-max x y | inl x≤y | inr (k , y≡x∙k) =
y ∙ y ≡⟨ cong (y ∙_) y≡x∙k ⟩
y ∙ (x ∙ k) ≡˘⟨ assoc y x k ⟩
(y ∙ x) ∙ k ≡⟨ cong (_∙ k) (comm y x) ⟩
(x ∙ y) ∙ k ≡˘⟨ cong ((x ∙ y) ∙_) (ε∙ k) ⟩
(x ∙ y) ∙ (ε ∙ k) ∎
double-max x y | inr (k , x≡y∙k) | inl y≤x =
x ∙ x ≡⟨ cong (x ∙_) x≡y∙k ⟩
x ∙ (y ∙ k) ≡˘⟨ assoc x y k ⟩
(x ∙ y) ∙ k ≡˘⟨ cong ((x ∙ y) ∙_) (∙ε k) ⟩
(x ∙ y) ∙ (k ∙ ε) ∎
double-max x y | inr (k₁ , x≡y∙k₁) | inr (k₂ , y≡x∙k₂) =
x ∙ x ≡⟨ cong (x ∙_) (antisym (k₂ , y≡x∙k₂) (k₁ , x≡y∙k₁)) ⟩
x ∙ y ≡⟨ cong₂ _∙_ x≡y∙k₁ y≡x∙k₂ ⟩
(y ∙ k₁) ∙ (x ∙ k₂) ≡˘⟨ assoc (y ∙ k₁) x k₂ ⟩
((y ∙ k₁) ∙ x) ∙ k₂ ≡⟨ cong (_∙ k₂) (comm (y ∙ k₁) x) ⟩
(x ∙ (y ∙ k₁)) ∙ k₂ ≡˘⟨ cong (_∙ k₂) (assoc x y k₁) ⟩
((x ∙ y) ∙ k₁) ∙ k₂ ≡⟨ assoc (x ∙ y) k₁ k₂ ⟩
(x ∙ y) ∙ (k₁ ∙ k₂) ∎
open import Data.Sigma.Properties
≤-prop : ∀ x y → isProp (x ≤ y)
≤-prop x y (k₁ , y≡x∙k₁) (k₂ , y≡x∙k₂) = Σ≡Prop (λ _ → total⇒isSet _ _) (cancelˡ x k₁ k₂ (sym y≡x∙k₁ ; y≡x∙k₂))
open import Cubical.Foundations.HLevels using (isProp×)
open import Data.Empty.Properties using (isProp¬)
≺-prop : ∀ x y → isProp (x ≺ y)
≺-prop x y (k₁ , y≡x∙k₁ , k₁≢ε) (k₂ , y≡x∙k₂ , k₂≢ε) = Σ≡Prop (λ k → isProp× (total⇒isSet _ _) (isProp¬ _)) (cancelˡ x k₁ k₂ (sym y≡x∙k₁ ; y≡x∙k₂))
-- We can construct the viterbi semiring by adjoining a top element to
-- a tapom
module Viterbi {ℓ₁} {ℓ₂} (tapom : TAPOM ℓ₁ ℓ₂) where
open TAPOM tapom
open import Relation.Binary.Construct.UpperBound totalOrder
open import Relation.Binary.Lattice totalOrder
⟨⊓⟩∙ : _∙_ Distributesˡ _⊓_
⟨⊓⟩∙ x y z with x <? y | (x ∙ z) <? (y ∙ z)
... | yes x<y | yes xz<yz = refl
... | no x≮y | no xz≮yz = refl
... | no x≮y | yes xz<yz = ⊥-elim (<⇒≱ xz<yz (≤-congʳ z (≮⇒≥ x≮y)))
... | yes x<y | no xz≮yz = antisym (≤-congʳ z (<⇒≤ x<y)) (≮⇒≥ xz≮yz)
∙⟨⊓⟩ : _∙_ Distributesʳ _⊓_
∙⟨⊓⟩ x y z = comm x (y ⊓ z) ; ⟨⊓⟩∙ y z x ; cong₂ _⊓_ (comm y x) (comm z x)
open UBSugar
module NS where
𝑅 = ⌈∙⌉
0# 1# : 𝑅
_*_ _+_ : 𝑅 → 𝑅 → 𝑅
1# = ⌈ ε ⌉
⌈⊤⌉ * y = ⌈⊤⌉
⌈ x ⌉ * ⌈⊤⌉ = ⌈⊤⌉
⌈ x ⌉ * ⌈ y ⌉ = ⌈ x ∙ y ⌉
0# = ⌈⊤⌉
⌈⊤⌉ + y = y
⌈ x ⌉ + ⌈⊤⌉ = ⌈ x ⌉
⌈ x ⌉ + ⌈ y ⌉ = ⌈ x ⊓ y ⌉
*-assoc : Associative _*_
*-assoc ⌈⊤⌉ _ _ = refl
*-assoc ⌈ _ ⌉ ⌈⊤⌉ _ = refl
*-assoc ⌈ _ ⌉ ⌈ _ ⌉ ⌈⊤⌉ = refl
*-assoc ⌈ x ⌉ ⌈ y ⌉ ⌈ z ⌉ = cong ⌈_⌉ (assoc x y z)
*-com : Commutative _*_
*-com ⌈⊤⌉ ⌈⊤⌉ = refl
*-com ⌈⊤⌉ ⌈ _ ⌉ = refl
*-com ⌈ _ ⌉ ⌈⊤⌉ = refl
*-com ⌈ x ⌉ ⌈ y ⌉ = cong ⌈_⌉ (comm x y)
⟨+⟩* : _*_ Distributesˡ _+_
⟨+⟩* ⌈⊤⌉ _ _ = refl
⟨+⟩* ⌈ _ ⌉ ⌈⊤⌉ ⌈⊤⌉ = refl
⟨+⟩* ⌈ _ ⌉ ⌈⊤⌉ ⌈ _ ⌉ = refl
⟨+⟩* ⌈ x ⌉ ⌈ y ⌉ ⌈⊤⌉ = refl
⟨+⟩* ⌈ x ⌉ ⌈ y ⌉ ⌈ z ⌉ = cong ⌈_⌉ (⟨⊓⟩∙ x y z)
+-assoc : Associative _+_
+-assoc ⌈⊤⌉ _ _ = refl
+-assoc ⌈ x ⌉ ⌈⊤⌉ _ = refl
+-assoc ⌈ x ⌉ ⌈ _ ⌉ ⌈⊤⌉ = refl
+-assoc ⌈ x ⌉ ⌈ y ⌉ ⌈ z ⌉ = cong ⌈_⌉ (⊓-assoc x y z)
0+ : ∀ x → 0# + x ≡ x
0+ ⌈⊤⌉ = refl
0+ ⌈ _ ⌉ = refl
+0 : ∀ x → x + 0# ≡ x
+0 ⌈ _ ⌉ = refl
+0 ⌈⊤⌉ = refl
1* : ∀ x → 1# * x ≡ x
1* ⌈⊤⌉ = refl
1* ⌈ x ⌉ = cong ⌈_⌉ (ε∙ x)
*1 : ∀ x → x * 1# ≡ x
*1 ⌈⊤⌉ = refl
*1 ⌈ x ⌉ = cong ⌈_⌉ (∙ε x)
0* : ∀ x → 0# * x ≡ 0#
0* _ = refl
open NS
nearSemiring : NearSemiring _
nearSemiring = record { NS }
+-comm : Commutative _+_
+-comm ⌈⊤⌉ ⌈⊤⌉ = refl
+-comm ⌈⊤⌉ ⌈ _ ⌉ = refl
+-comm ⌈ _ ⌉ ⌈⊤⌉ = refl
+-comm ⌈ x ⌉ ⌈ y ⌉ = cong ⌈_⌉ (⊓-comm x y)
*0 : ∀ x → x * ⌈⊤⌉ ≡ ⌈⊤⌉
*0 ⌈ _ ⌉ = refl
*0 ⌈⊤⌉ = refl
*⟨+⟩ : _*_ Distributesʳ _+_
*⟨+⟩ x y z = *-com x (y + z) ; ⟨+⟩* y z x ; cong₂ _+_ (*-com y x) (*-com z x)
viterbi : ∀ {ℓ₁ ℓ₂} → TAPOM ℓ₁ ℓ₂ → Semiring ℓ₁
viterbi tapom = record { Viterbi tapom }
| {
"alphanum_fraction": 0.4520532099,
"avg_line_length": 30.875,
"ext": "agda",
"hexsha": "dcc1e1fd5be07a2e1c1c96840e0eb5f632fd81ce",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Algebra/Monus.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Algebra/Monus.agda",
"max_line_length": 149,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Algebra/Monus.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 9746,
"size": 17290
} |
------------------------------------------------------------------------
-- Fixpoint combinators
------------------------------------------------------------------------
{-# OPTIONS --cubical --safe #-}
module Partiality-monad.Inductive.Fixpoints where
open import Equality.Propositional.Cubical
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (⊥)
open import Bijection equality-with-J using (_↔_)
import Equivalence equality-with-J as Eq
open import Function-universe equality-with-J hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import Monad equality-with-J hiding (sequence)
open import Univalence-axiom equality-with-J
open import Partiality-algebra using (Partiality-algebra)
import Partiality-algebra.Fixpoints as PAF
open import Partiality-algebra.Monotone
open import Partiality-algebra.Omega-continuous
open import Partiality-algebra.Pi as Pi hiding (at)
open import Partiality-monad.Inductive
open import Partiality-monad.Inductive.Monad
open import Partiality-monad.Inductive.Monotone using ([_⊥→_⊥]⊑)
open import Partiality-monad.Inductive.Omega-continuous
------------------------------------------------------------------------
-- The fixpoint combinator machinery instantiated with the partiality
-- monad
module _ {a} {A : Type a} where
open PAF.Fix {P = partiality-algebra A} public
open [_⊥→_⊥]
-- A variant of fix.
fix′ : (A → A ⊥) → A ⊥
fix′ f = fix (monotone-function (f ∗))
-- This variant also produces a kind of least fixpoint.
fix′-is-fixpoint-combinator :
(f : A → A ⊥) →
fix′ f ≡ fix′ f >>= f
fix′-is-fixpoint-combinator f =
fix′ f ≡⟨⟩
fix (monotone-function (f ∗)) ≡⟨ fix-is-fixpoint-combinator (f ∗) ⟩∎
fix (monotone-function (f ∗)) >>= f ∎
fix′-is-least :
(f : A → A ⊥) →
(x : A ⊥) → x >>= f ⊑ x → fix′ f ⊑ x
fix′-is-least f = fix-is-least (monotone-function (f ∗))
-- Taking steps that are "twice as large" does not affect the end
-- result.
fix′-∘ : (f : A → A ⊥) → fix′ (λ x → f x >>= f) ≡ fix′ f
fix′-∘ f =
fix′ (λ x → f x >>= f) ≡⟨⟩
fix (monotone-function ((λ x → f x >>= f) ∗)) ≡⟨ cong fix (_↔_.to equality-characterisation-monotone λ (x : A ⊥) →
(x >>= λ y → f y >>= f) ≡⟨ associativity x f f ⟩∎
x >>= f >>= f ∎) ⟩
fix (monotone-function (f ∗) ∘⊑ monotone-function (f ∗)) ≡⟨ fix-∘ (monotone-function (f ∗)) ⟩∎
fix′ f ∎
-- Unary Scott induction for fix′.
fix′-induction₁ :
∀ {p}
(P : A ⊥ → Type p)
(P⊥ : P never)
(P⨆ : ∀ s → (∀ n → P (s [ n ])) → P (⨆ s))
(f : A → A ⊥) →
(∀ x → P x → P (x >>= f)) →
P (fix′ f)
fix′-induction₁ P P⊥ P⨆ f =
fix-induction₁ P P⊥ P⨆ ([_⊥→_⊥].monotone-function (f ∗))
-- N-ary Scott induction.
module _ {a p} n
(As : Fin n → Type a)
(P : (∀ i → As i ⊥) → Type p)
(P⊥ : P (λ _ → never))
(P⨆ : ∀ ss → (∀ n → P (λ i → ss i [ n ])) → P (⨆ ∘ ss))
where
open PAF.N-ary n As (λ i → partiality-algebra (As i)) P P⊥ P⨆ public
fix′-induction :
(fs : ∀ i → As i → As i ⊥) →
(∀ xs → P xs → P (λ i → xs i >>= fs i)) →
P (fix′ ∘ fs)
fix′-induction fs =
fix-induction (λ i → [_⊥→_⊥].monotone-function (fs i ∗))
------------------------------------------------------------------------
-- The fixpoint combinator machinery instantiated with dependent
-- functions to the partiality monad
module _ {a b} (A : Type a) (B : A → Type b) where
-- Partial function transformers.
Trans : Type (a ⊔ b)
Trans = ((x : A) → B x ⊥) → ((x : A) → B x ⊥)
-- A partiality algebra.
Pi : Partiality-algebra (a ⊔ b) (a ⊔ b) ((x : A) → B x)
Pi = Π A (partiality-algebra ∘ B)
-- Monotone partial function transformers.
Trans-⊑ : Type (a ⊔ b)
Trans-⊑ = [ Pi ⟶ Pi ]⊑
private
sanity-check : Trans-⊑ → Trans
sanity-check = [_⟶_]⊑.function
-- Partial function transformers that are ω-continuous.
Trans-ω : Type (a ⊔ b)
Trans-ω = [ Pi ⟶ Pi ]
module _ {a b} {A : Type a} {B : A → Type b} where
module Trans-⊑ = [_⟶_]⊑ {P₁ = Pi A B} {P₂ = Pi A B}
module Trans-ω = [_⟶_] {P₁ = Pi A B} {P₂ = Pi A B}
private
module F = PAF.Fix {P = Pi A B}
-- Applies an increasing sequence of functions to a value.
at :
(∃ λ (f : ℕ → (x : A) → B x ⊥) → ∀ n x → f n x ⊑ f (suc n) x) →
(x : A) → ∃ λ (f : ℕ → B x ⊥) → ∀ n → f n ⊑ f (suc n)
at = Pi.at (partiality-algebra ∘ B)
-- Repeated application of a monotone partial function transformer
-- to the least element.
app→ : Trans-⊑ A B → ℕ → ((x : A) → B x ⊥)
app→ = F.app
-- The increasing sequence fix→-sequence f consists of the elements
-- const never, Trans-⊑.function f (const never), and so on. This
-- sequence is used in the implementation of fix→.
fix→-sequence : Trans-⊑ A B →
Partiality-algebra.Increasing-sequence (Pi A B)
fix→-sequence = F.fix-sequence
-- A fixpoint combinator.
fix→ : Trans-⊑ A B → ((x : A) → B x ⊥)
fix→ = F.fix
-- The fixpoint combinator produces fixpoints for ω-continuous
-- arguments.
fix→-is-fixpoint-combinator :
(f : Trans-ω A B) →
fix→ (Trans-ω.monotone-function f) ≡
Trans-ω.function f (fix→ (Trans-ω.monotone-function f))
fix→-is-fixpoint-combinator = F.fix-is-fixpoint-combinator
-- The result of the fixpoint combinator is pointwise smaller than
-- or equal to every "pointwise post-fixpoint".
fix→-is-least :
(f : Trans-⊑ A B) →
∀ g → (∀ x → Trans-⊑.function f g x ⊑ g x) →
∀ x → fix→ f x ⊑ g x
fix→-is-least = F.fix-is-least
-- Taking steps that are "twice as large" does not affect the end
-- result.
fix→-∘ : (f : Trans-⊑ A B) → fix→ (f ∘⊑ f) ≡ fix→ f
fix→-∘ = F.fix-∘
-- N-ary Scott induction.
module _
{a b p} n
(As : Fin n → Type a)
(Bs : (i : Fin n) → As i → Type b)
(P : (∀ i → (x : As i) → Bs i x ⊥) → Type p)
(P⊥ : P (λ _ _ → never))
(P⨆ : (ss : ∀ i (x : As i) → Increasing-sequence (Bs i x)) →
(∀ n → P (λ i xs → ss i xs [ n ])) →
P (λ i xs → ⨆ (ss i xs)))
(fs : ∀ i → Trans-⊑ (As i) (Bs i)) where
private
module N = PAF.N-ary n
(λ i → (x : As i) → Bs i x)
(λ i → Π (As i) (partiality-algebra ∘ Bs i))
P
P⊥
(λ _ → P⨆ _)
fs
-- Generalised.
fix→-induction′ :
(∀ n → P (λ i → app→ (fs i) n) →
P (λ i → app→ (fs i) (suc n))) →
P (λ i → fix→ (fs i))
fix→-induction′ = N.fix-induction′
-- Basic.
fix→-induction :
((gs : ∀ i (x : As i) → Bs i x ⊥) →
P gs → P (λ i → Trans-⊑.function (fs i) (gs i))) →
P (λ i → fix→ (fs i))
fix→-induction = N.fix-induction
-- Unary Scott induction.
fix→-induction₁ :
∀ {a b p} {A : Type a} {B : A → Type b}
(P : ((x : A) → B x ⊥) → Type p) →
P (λ _ → never) →
((s : (x : A) → Increasing-sequence (B x)) →
(∀ n → P (λ x → s x [ n ])) →
P (λ x → ⨆ (s x))) →
(f : Trans-⊑ A B) →
(∀ g → P g → P (Trans-⊑.function f g)) →
P (fix→ f)
fix→-induction₁ P P⊥ P⨆ = PAF.fix-induction₁ P P⊥ (λ _ → P⨆ _)
------------------------------------------------------------------------
-- Some combinators that can be used to construct ω-continuous partial
-- function transformers, for use with fix→
-- A type used by these combinators.
record Partial
{a b c}
(A : Type a) (B : A → Type b) (C : Type c) :
Type (a ⊔ b ⊔ lsuc c) where
field
-- A function that is allowed to make "recursive calls" of type
-- (x : A) → B x ⊥.
function : ((x : A) → B x ⊥) → C ⊥
-- The function must be monotone.
monotone : ∀ {rec₁ rec₂} →
(∀ x → rec₁ x ⊑ rec₂ x) →
function rec₁ ⊑ function rec₂
-- The function can be turned into an increasing sequence.
sequence : ((x : A) → Increasing-sequence (B x)) →
Increasing-sequence C
sequence recs =
(λ n → function (λ x → recs x [ n ]))
, (λ n → monotone (λ x → increasing (recs x) n))
field
-- The function must be ω-continuous in the following sense.
ω-continuous : (recs : (x : A) → Increasing-sequence (B x)) →
function (⨆ ∘ recs) ≡ ⨆ (sequence recs)
-- The first two arguments of Partial specify the domain and codomain
-- of "recursive calls".
rec : ∀ {a b} {A : Type a} {B : A → Type b} →
(x : A) → Partial A B (B x)
rec x = record
{ function = _$ x
; monotone = _$ x
; ω-continuous = λ _ → refl
}
-- Turns certain Partial-valued functions into monotone partial
-- function transformers.
transformer : ∀ {a b} {A : Type a} {B : A → Type b} →
((x : A) → Partial A B (B x)) → Trans-⊑ A B
transformer f = record
{ function = λ g x → function (f x) g
; monotone = λ g₁⊑g₂ x → monotone (f x) g₁⊑g₂
}
where
open Partial
-- Turns certain Partial-valued functions into ω-continuous partial
-- function transformers.
transformer-ω : ∀ {a b} {A : Type a} {B : A → Type b} →
((x : A) → Partial A B (B x)) → Trans-ω A B
transformer-ω f = record
{ monotone-function = transformer f
; ω-continuous = λ _ → ⟨ext⟩ λ x → ω-continuous (f x) _
}
where
open Partial
-- A fixpoint combinator.
fixP : ∀ {a b} {A : Type a} {B : A → Type b} →
((x : A) → Partial A B (B x)) → ((x : A) → B x ⊥)
fixP {A = A} {B} =
((x : A) → Partial A B (B x)) ↝⟨ transformer ⟩
Trans-⊑ A B ↝⟨ fix→ ⟩□
((x : A) → B x ⊥) □
-- The fixpoint combinator produces fixpoints.
fixP-is-fixpoint-combinator :
∀ {a b} {A : Type a} {B : A → Type b} →
(f : (x : A) → Partial A B (B x)) →
fixP f ≡ flip (Partial.function ∘ f) (fixP f)
fixP-is-fixpoint-combinator =
fix→-is-fixpoint-combinator ∘ transformer-ω
-- The result of the fixpoint combinator is pointwise smaller than
-- or equal to every "pointwise post-fixpoint".
fixP-is-least :
∀ {a b} {A : Type a} {B : A → Type b}
(f : (x : A) → Partial A B (B x)) →
∀ g → (∀ x → Partial.function (f x) g ⊑ g x) →
∀ x → fixP f x ⊑ g x
fixP-is-least = fix→-is-least ∘ transformer
-- Composition of certain Partial-valued functions.
infixr 40 _∘P_
_∘P_ :
∀ {a b} {A : Type a} {B : A → Type b} →
((x : A) → Partial A B (B x)) →
((x : A) → Partial A B (B x)) →
((x : A) → Partial A B (B x))
Partial.function ((f ∘P g) x) = λ h →
Partial.function (f x) λ y →
Partial.function (g y) h
Partial.monotone ((f ∘P g) x) = λ hyp →
Partial.monotone (f x) λ y →
Partial.monotone (g y) hyp
Partial.ω-continuous ((f ∘P g) x) = λ recs →
function (f x) (λ y → function (g y) (⨆ ∘ recs)) ≡⟨ cong (function (f x)) (⟨ext⟩ λ y → ω-continuous (g y) recs) ⟩
function (f x) (λ y → ⨆ (sequence (g y) recs)) ≡⟨ ω-continuous (f x) (λ y → sequence (g y) recs) ⟩∎
⨆ (sequence (f x) λ y → sequence (g y) recs) ∎
where
open Partial
-- Taking steps that are "twice as large" does not affect the end
-- result.
fixP-∘ : ∀ {a b} {A : Type a} {B : A → Type b}
(f : (x : A) → Partial A B (B x)) →
fixP (f ∘P f) ≡ fixP f
fixP-∘ f =
fix→ (transformer (f ∘P f)) ≡⟨⟩
fix→ (transformer f ∘⊑ transformer f) ≡⟨ fix→-∘ (transformer f) ⟩∎
fix→ (transformer f) ∎
-- N-ary Scott induction.
module _
{a b p} n
(As : Fin n → Type a)
(Bs : (i : Fin n) → As i → Type b)
(P : (∀ i (x : As i) → Bs i x ⊥) → Type p)
(P⊥ : P (λ _ _ → never))
(P⨆ : (ss : ∀ i (x : As i) → Increasing-sequence (Bs i x)) →
(∀ n → P (λ i xs → ss i xs [ n ])) →
P (λ i xs → ⨆ (ss i xs)))
(fs : ∀ i (x : As i) → Partial (As i) (Bs i) (Bs i x)) where
-- Generalised.
fixP-induction′ :
(∀ n → P (λ i → app→ (transformer (fs i)) n) →
P (λ i → app→ (transformer (fs i)) (suc n))) →
P (λ i → fixP (fs i))
fixP-induction′ =
fix→-induction′ n As Bs P P⊥ P⨆ (transformer ∘ fs)
-- Basic.
fixP-induction :
((gs : ∀ i (x : As i) → Bs i x ⊥) →
P gs → P (λ i xs → Partial.function (fs i xs) (gs i))) →
P (λ i → fixP (fs i))
fixP-induction =
fix→-induction n As Bs P P⊥ P⨆ (transformer ∘ fs)
-- Unary Scott induction.
fixP-induction₁ :
∀ {a b p} {A : Type a} {B : A → Type b}
(P : ((x : A) → B x ⊥) → Type p) →
P (λ _ → never) →
((s : (x : A) → Increasing-sequence (B x)) →
(∀ n → P (λ x → s x [ n ])) →
P (λ x → ⨆ (s x))) →
(f : (x : A) → Partial A B (B x)) →
(∀ g → P g → P (λ x → Partial.function (f x) g)) →
P (fixP f)
fixP-induction₁ P P⊥ P⨆ f =
fix→-induction₁ P P⊥ P⨆ (transformer f)
-- Equality characterisation lemma for Partial.
equality-characterisation-Partial :
∀ {a b c} {A : Type a} {B : A → Type b} {C : Type c}
{f g : Partial A B C} →
(∀ rec → Partial.function f rec ≡ Partial.function g rec) ↔
f ≡ g
equality-characterisation-Partial {f = f} {g} =
(∀ rec → function f rec ≡ function g rec) ↔⟨ Eq.extensionality-isomorphism bad-ext ⟩
function f ≡ function g ↝⟨ ignore-propositional-component
(Σ-closure 1
(implicit-Π-closure ext 1 λ _ →
implicit-Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
⊑-propositional) λ _ →
Π-closure ext 1 λ _ →
⊥-is-set) ⟩
(function f , _) ≡ (function g , _) ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ lemma) ⟩□
f ≡ g □
where
open Partial
lemma :
Partial _ _ _
↔
∃ λ f →
∃ λ (_ : ∀ {rec₁ rec₂} → (∀ x → rec₁ x ⊑ _) → f rec₁ ⊑ _) → _
lemma = record
{ surjection = record
{ logical-equivalence = record
{ to = λ x → function x , monotone x , ω-continuous x
; from = λ { (f , m , ω) → record
{ function = f
; monotone = λ {rec₁ rec₂} → m {rec₁ = rec₁} {rec₂ = rec₂}
; ω-continuous = ω
} }
}
; right-inverse-of = λ _ → refl
}
; left-inverse-of = λ _ → refl
}
-- "Non-recursive" computations can be converted into possibly
-- recursive ones.
non-recursive :
∀ {a b c} {A : Type a} {B : A → Type b} {C : Type c} →
C ⊥ → Partial A B C
non-recursive x = record
{ function = const x
; monotone = const (x ■)
; ω-continuous = λ _ →
x ≡⟨ sym ⨆-const ⟩∎
⨆ (constˢ x) ∎
}
instance
-- Partial A B is a monad.
partial-raw-monad : ∀ {a b c} {A : Type a} {B : A → Type b} →
Raw-monad (Partial {c = c} A B)
Raw-monad.return partial-raw-monad x = non-recursive (return x)
Raw-monad._>>=_ partial-raw-monad x f = record
{ function = λ rec →
function x rec >>=′ λ y →
function (f y) rec
; monotone = λ rec⊑rec →
monotone x rec⊑rec >>=-mono λ y →
monotone (f y) rec⊑rec
; ω-continuous = λ recs →
(function x (⨆ ∘ recs) >>=′ λ y → function (f y) (⨆ ∘ recs)) ≡⟨ cong₂ _>>=′_ (ω-continuous x recs)
(⟨ext⟩ λ y → ω-continuous (f y) recs) ⟩
(⨆ (sequence x recs) >>=′ λ y → ⨆ (sequence (f y) recs)) ≡⟨ ⨆->>= ⟩
⨆ ( (λ n →
function x (λ z → recs z [ n ]) >>=′ λ y →
⨆ (sequence (f y) recs))
, _
) ≡⟨ ⨆>>=⨆≡⨆>>= (sequence x recs)
(λ y → sequence (f y) recs) ⟩∎
⨆ ( (λ n → function x (λ z → recs z [ n ]) >>=′ λ y →
function (f y) (λ z → recs z [ n ]))
, _
) ∎
}
where
open Partial
partial-monad : ∀ {a b c} {A : Type a} {B : A → Type b} →
Monad (Partial {c = c} A B)
Monad.raw-monad partial-monad = partial-raw-monad
Monad.left-identity partial-monad _ f =
_↔_.to equality-characterisation-Partial
(λ h → left-identity _ (λ y → Partial.function (f y) h))
Monad.right-identity partial-monad _ =
_↔_.to equality-characterisation-Partial
(λ _ → right-identity _)
Monad.associativity partial-monad x _ _ =
_↔_.to equality-characterisation-Partial
(λ h → associativity (Partial.function x h) _ _)
| {
"alphanum_fraction": 0.4875220718,
"avg_line_length": 32.0566037736,
"ext": "agda",
"hexsha": "a47665782f9224ca0cb16c17e9d80b69a11380c4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Partiality-monad/Inductive/Fixpoints.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/partiality-monad",
"max_issues_repo_path": "src/Partiality-monad/Inductive/Fixpoints.agda",
"max_line_length": 130,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Partiality-monad/Inductive/Fixpoints.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 5946,
"size": 16990
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cw.CW
open import cw.FinCW
open import cw.FinBoundary
open import cohomology.ChainComplex
open import cohomology.Theory
module cw.cohomology.AxiomaticIsoCellular (OT : OrdinaryTheory lzero) where
open OrdinaryTheory OT
open import cw.cohomology.cellular.ChainComplex
import cw.cohomology.reconstructed.cochain.Complex OT as RCC
open import cw.cohomology.ReconstructedCohomologyGroups OT
open import cw.cohomology.ReconstructedCochainsEquivCellularCochains OT
axiomatic-iso-cellular : ∀ m {n} (⊙fin-skel : ⊙FinSkeleton n)
→ C m ⊙⟦ ⊙⦉ ⊙fin-skel ⦊ ⟧
≃ᴳ cohomology-group
(cochain-complex ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊
(FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel))
(FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel))
(C2-abgroup 0))
m
axiomatic-iso-cellular m ⊙fin-skel =
C m ⊙⟦ ⊙⦉ ⊙fin-skel ⦊ ⟧
≃ᴳ⟨ reconstructed-cohomology-group m ⊙⦉ ⊙fin-skel ⦊
(⊙FinSkeleton-has-cells-with-choice 0 ⊙fin-skel lzero) ⟩
cohomology-group (RCC.cochain-complex ⊙⦉ ⊙fin-skel ⦊) m
≃ᴳ⟨ frc-iso-fcc ⊙fin-skel m ⟩
cohomology-group
(cochain-complex ⦉ ⊙FinSkeleton.skel ⊙fin-skel ⦊
(FinSkeleton-has-cells-with-dec-eq (⊙FinSkeleton.skel ⊙fin-skel))
(FinSkeleton-has-degrees-with-finite-support (⊙FinSkeleton.skel ⊙fin-skel))
(C2-abgroup 0))
m
≃ᴳ∎
| {
"alphanum_fraction": 0.6752988048,
"avg_line_length": 38.6153846154,
"ext": "agda",
"hexsha": "19d964a3e3e98438856158bc2cbe7d1ea0f22278",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/cohomology/AxiomaticIsoCellular.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/cohomology/AxiomaticIsoCellular.agda",
"max_line_length": 85,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/cohomology/AxiomaticIsoCellular.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 546,
"size": 1506
} |
open import System.IO using ( _>>_ ; putStr ; commit )
module System.IO.Examples.HelloWorld where
main = putStr "Hello, World\n" >> commit
| {
"alphanum_fraction": 0.7163120567,
"avg_line_length": 23.5,
"ext": "agda",
"hexsha": "08eb5614a0685c416a4b978b49af7d68efe7107b",
"lang": "Agda",
"max_forks_count": 3909,
"max_forks_repo_forks_event_max_datetime": "2019-03-31T18:39:08.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-10-03T15:07:19.000Z",
"max_forks_repo_head_hexsha": "def0f44737e02fb40063cd347e93e456658e2532",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "PushpneetSingh/Hello-world",
"max_forks_repo_path": "Agda/Hello-world.agda",
"max_issues_count": 1162,
"max_issues_repo_head_hexsha": "def0f44737e02fb40063cd347e93e456658e2532",
"max_issues_repo_issues_event_max_datetime": "2018-10-18T14:17:52.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-03T15:05:49.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "PushpneetSingh/Hello-world",
"max_issues_repo_path": "Agda/Hello-world.agda",
"max_line_length": 54,
"max_stars_count": 1428,
"max_stars_repo_head_hexsha": "def0f44737e02fb40063cd347e93e456658e2532",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "PushpneetSingh/Hello-world",
"max_stars_repo_path": "Agda/Hello-world.agda",
"max_stars_repo_stars_event_max_datetime": "2019-03-31T18:38:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-03T15:15:17.000Z",
"num_tokens": 38,
"size": 141
} |
------------------------------------------------------------------------
-- Grammars defined as functions from non-terminals to productions
------------------------------------------------------------------------
{-# OPTIONS --safe #-}
module Grammar.Non-terminal where
open import Algebra
open import Category.Monad
open import Data.Bool
open import Data.Bool.Properties
open import Data.Char
open import Data.Empty
open import Data.List hiding (unfold)
open import Data.List.Properties
open import Data.Maybe hiding (_>>=_)
open import Data.Maybe.Categorical as MaybeC
open import Data.Nat
open import Data.Product as Product
open import Data.Unit
open import Function
open import Level using (Lift; lift)
open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_)
open import Relation.Nullary
open import Tactic.MonoidSolver
private
module LM {A : Set} = Monoid (++-monoid A)
open module MM {f} = RawMonadPlus (MaybeC.monadPlus {f = f})
using ()
renaming (_<$>_ to _<$>M_; _⊛_ to _⊛M_;
_>>=_ to _>>=M_; _∣_ to _∣M_)
open import Utilities
------------------------------------------------------------------------
-- Grammars
-- Productions. (Note that productions can contain choices.)
infix 30 _⋆
infixl 20 _⊛_ _<⊛_
infixl 15 _>>=_
infixl 10 _∣_
data Prod (NT : Set → Set₁) : Set → Set₁ where
! : ∀ {A} → NT A → Prod NT A
fail : ∀ {A} → Prod NT A
return : ∀ {A} → A → Prod NT A
token : Prod NT Char
tok : Char → Prod NT Char
_⊛_ : ∀ {A B} → Prod NT (A → B) → Prod NT A → Prod NT B
_<⊛_ : ∀ {A B} → Prod NT A → Prod NT B → Prod NT A
_>>=_ : ∀ {A B} → Prod NT A → (A → Prod NT B) → Prod NT B
_∣_ : ∀ {A} → Prod NT A → Prod NT A → Prod NT A
_⋆ : ∀ {A} → Prod NT A → Prod NT (List A)
-- Grammars.
Grammar : (Set → Set₁) → Set₁
Grammar NT = ∀ A → NT A → Prod NT A
-- An empty non-terminal type.
Empty-NT : Set → Set₁
Empty-NT _ = Lift _ ⊥
-- A corresponding grammar.
empty-grammar : Grammar Empty-NT
empty-grammar _ (lift ())
------------------------------------------------------------------------
-- Production combinators
-- Map.
infixl 20 _<$>_ _<$_
_<$>_ : ∀ {NT A B} → (A → B) → Prod NT A → Prod NT B
f <$> p = return f ⊛ p
_<$_ : ∀ {NT A B} → A → Prod NT B → Prod NT A
x <$ p = return x <⊛ p
-- Various sequencing operators.
infixl 20 _⊛>_
infixl 15 _>>_
_>>_ : ∀ {NT A B} → Prod NT A → Prod NT B → Prod NT B
p₁ >> p₂ = (λ _ x → x) <$> p₁ ⊛ p₂
_⊛>_ : ∀ {NT A B} → Prod NT A → Prod NT B → Prod NT B
_⊛>_ = _>>_
-- Kleene plus.
infix 30 _+
_+ : ∀ {NT A} → Prod NT A → Prod NT (List A)
p + = _∷_ <$> p ⊛ p ⋆
-- Elements separated by something.
infixl 18 _sep-by_
_sep-by_ : ∀ {NT A B} → Prod NT A → Prod NT B → Prod NT (List A)
g sep-by sep = _∷_ <$> g ⊛ (sep >> g) ⋆
-- A production for tokens satisfying a given predicate.
if-true : ∀ {NT} (b : Bool) → Prod NT (T b)
if-true true = return tt
if-true false = fail
sat : ∀ {NT} (p : Char → Bool) → Prod NT (∃ λ t → T (p t))
sat p = token >>= λ t → _,_ t <$> if-true (p t)
-- A production for whitespace.
whitespace : ∀ {NT} → Prod NT Char
whitespace = tok ' ' ∣ tok '\n'
-- A production for a given string.
string : ∀ {NT} → List Char → Prod NT (List Char)
string [] = return []
string (t ∷ s) = _∷_ <$> tok t ⊛ string s
-- A production for the given string, possibly followed by some
-- whitespace.
symbol : ∀ {NT} → List Char → Prod NT (List Char)
symbol s = string s <⊛ whitespace ⋆
------------------------------------------------------------------------
-- Semantics
infix 4 [_]_∈_·_
data [_]_∈_·_ {NT : Set → Set₁} (g : Grammar NT) :
∀ {A} → A → Prod NT A → List Char → Set₁ where
!-sem : ∀ {A} {nt : NT A} {x s} →
[ g ] x ∈ g A nt · s → [ g ] x ∈ ! nt · s
return-sem : ∀ {A} {x : A} → [ g ] x ∈ return x · []
token-sem : ∀ {t} → [ g ] t ∈ token · [ t ]
tok-sem : ∀ {t} → [ g ] t ∈ tok t · [ t ]
⊛-sem : ∀ {A B} {p₁ : Prod NT (A → B)} {p₂ : Prod NT A}
{f x s₁ s₂} →
[ g ] f ∈ p₁ · s₁ → [ g ] x ∈ p₂ · s₂ →
[ g ] f x ∈ p₁ ⊛ p₂ · s₁ ++ s₂
<⊛-sem : ∀ {A B} {p₁ : Prod NT A} {p₂ : Prod NT B} {x y s₁ s₂} →
[ g ] x ∈ p₁ · s₁ → [ g ] y ∈ p₂ · s₂ →
[ g ] x ∈ p₁ <⊛ p₂ · s₁ ++ s₂
>>=-sem : ∀ {A B} {p₁ : Prod NT A} {p₂ : A → Prod NT B}
{x y s₁ s₂} →
[ g ] x ∈ p₁ · s₁ → [ g ] y ∈ p₂ x · s₂ →
[ g ] y ∈ p₁ >>= p₂ · s₁ ++ s₂
left-sem : ∀ {A} {p₁ p₂ : Prod NT A} {x s} →
[ g ] x ∈ p₁ · s → [ g ] x ∈ p₁ ∣ p₂ · s
right-sem : ∀ {A} {p₁ p₂ : Prod NT A} {x s} →
[ g ] x ∈ p₂ · s → [ g ] x ∈ p₁ ∣ p₂ · s
⋆-[]-sem : ∀ {A} {p : Prod NT A} →
[ g ] [] ∈ p ⋆ · []
⋆-+-sem : ∀ {A} {p : Prod NT A} {xs s} →
[ g ] xs ∈ p + · s → [ g ] xs ∈ p ⋆ · s
-- Cast lemma.
cast : ∀ {NT g A} {p : Prod NT A} {x s₁ s₂} →
s₁ ≡ s₂ → [ g ] x ∈ p · s₁ → [ g ] x ∈ p · s₂
cast P.refl = id
------------------------------------------------------------------------
-- Semantics combinators
<$>-sem : ∀ {NT} {g : Grammar NT} {A B} {f : A → B} {x p s} →
[ g ] x ∈ p · s → [ g ] f x ∈ f <$> p · s
<$>-sem x∈ = ⊛-sem return-sem x∈
<$-sem : ∀ {NT g A B} {p : Prod NT B} {x : A} {y s} →
[ g ] y ∈ p · s → [ g ] x ∈ x <$ p · s
<$-sem y∈ = <⊛-sem return-sem y∈
>>-sem : ∀ {NT g A B} {p₁ : Prod NT A} {p₂ : Prod NT B} {x y s₁ s₂} →
[ g ] x ∈ p₁ · s₁ → [ g ] y ∈ p₂ · s₂ →
[ g ] y ∈ p₁ >> p₂ · s₁ ++ s₂
>>-sem x∈ y∈ = ⊛-sem (⊛-sem return-sem x∈) y∈
⊛>-sem : ∀ {NT g A B} {p₁ : Prod NT A} {p₂ : Prod NT B} {x y s₁ s₂} →
[ g ] x ∈ p₁ · s₁ → [ g ] y ∈ p₂ · s₂ →
[ g ] y ∈ p₁ ⊛> p₂ · s₁ ++ s₂
⊛>-sem = >>-sem
+-sem : ∀ {NT g A} {p : Prod NT A} {x xs s₁ s₂} →
[ g ] x ∈ p · s₁ → [ g ] xs ∈ p ⋆ · s₂ →
[ g ] x ∷ xs ∈ p + · s₁ ++ s₂
+-sem x∈ xs∈ = ⊛-sem (⊛-sem return-sem x∈) xs∈
⋆-∷-sem : ∀ {NT g A} {p : Prod NT A} {x xs s₁ s₂} →
[ g ] x ∈ p · s₁ → [ g ] xs ∈ p ⋆ · s₂ →
[ g ] x ∷ xs ∈ p ⋆ · s₁ ++ s₂
⋆-∷-sem x∈ xs∈ = ⋆-+-sem (+-sem x∈ xs∈)
⋆-⋆-sem : ∀ {NT g A} {p : Prod NT A} {xs₁ xs₂ s₁ s₂} →
[ g ] xs₁ ∈ p ⋆ · s₁ → [ g ] xs₂ ∈ p ⋆ · s₂ →
[ g ] xs₁ ++ xs₂ ∈ p ⋆ · s₁ ++ s₂
⋆-⋆-sem ⋆-[]-sem xs₂∈ = xs₂∈
⋆-⋆-sem (⋆-+-sem (⊛-sem (⊛-sem {s₂ = s₁} return-sem x∈) xs₁∈)) xs₂∈ =
cast (P.sym $ LM.assoc s₁ _ _)
(⋆-∷-sem x∈ (⋆-⋆-sem xs₁∈ xs₂∈))
+-∷-sem : ∀ {NT g A} {p : Prod NT A} {x xs s₁ s₂} →
[ g ] x ∈ p · s₁ → [ g ] xs ∈ p + · s₂ →
[ g ] x ∷ xs ∈ p + · s₁ ++ s₂
+-∷-sem x∈ xs∈ = +-sem x∈ (⋆-+-sem xs∈)
+-⋆-sem : ∀ {NT g A} {p : Prod NT A} {xs₁ xs₂ s₁ s₂} →
[ g ] xs₁ ∈ p + · s₁ → [ g ] xs₂ ∈ p ⋆ · s₂ →
[ g ] xs₁ ++ xs₂ ∈ p + · s₁ ++ s₂
+-⋆-sem (⊛-sem (⊛-sem {s₂ = s₁} return-sem x∈) xs₁∈) xs₂∈ =
cast (P.sym $ LM.assoc s₁ _ _)
(+-sem x∈ (⋆-⋆-sem xs₁∈ xs₂∈))
sep-by-sem-singleton :
∀ {NT g A B} {p : Prod NT A} {sep : Prod NT B} {x s} →
[ g ] x ∈ p · s → [ g ] [ x ] ∈ p sep-by sep · s
sep-by-sem-singleton x∈ =
cast (proj₂ LM.identity _) (⊛-sem (<$>-sem x∈) ⋆-[]-sem)
sep-by-sem-∷ :
∀ {NT g A B} {p : Prod NT A} {sep : Prod NT B} {x y xs s₁ s₂ s₃} →
[ g ] x ∈ p · s₁ → [ g ] y ∈ sep · s₂ → [ g ] xs ∈ p sep-by sep · s₃ →
[ g ] x ∷ xs ∈ p sep-by sep · s₁ ++ s₂ ++ s₃
sep-by-sem-∷ {s₂ = s₂} x∈ y∈ (⊛-sem (⊛-sem return-sem x′∈) xs∈) =
⊛-sem (<$>-sem x∈)
(cast (LM.assoc s₂ _ _) (⋆-∷-sem (>>-sem y∈ x′∈) xs∈))
if-true-sem : ∀ {NT} {g : Grammar NT} {b}
(t : T b) → [ g ] t ∈ if-true b · []
if-true-sem {b = true} _ = return-sem
if-true-sem {b = false} ()
sat-sem : ∀ {NT} {g : Grammar NT} {p t}
(pt : T (p t)) → [ g ] (t , pt) ∈ sat p · [ t ]
sat-sem pt = >>=-sem token-sem (<$>-sem (if-true-sem pt))
whitespace-sem-space : ∀ {NT} {g : Grammar NT} →
[ g ] ' ' ∈ whitespace · [ ' ' ]
whitespace-sem-space = left-sem tok-sem
whitespace-sem-newline : ∀ {NT} {g : Grammar NT} →
[ g ] '\n' ∈ whitespace · [ '\n' ]
whitespace-sem-newline = right-sem tok-sem
string-sem : ∀ {NT} {g : Grammar NT} {s} →
[ g ] s ∈ string s · s
string-sem {s = []} = return-sem
string-sem {s = t ∷ s} = ⊛-sem (<$>-sem tok-sem) string-sem
symbol-sem : ∀ {NT} {g : Grammar NT} {s s′ s″} →
[ g ] s″ ∈ whitespace ⋆ · s′ → [ g ] s ∈ symbol s · s ++ s′
symbol-sem s″∈ = <⊛-sem string-sem s″∈
------------------------------------------------------------------------
-- Some production transformers
-- Replaces all non-terminals with non-terminal-free productions.
replace : ∀ {NT A} → (∀ {A} → NT A → Prod Empty-NT A) →
Prod NT A → Prod Empty-NT A
replace f (! nt) = f nt
replace f fail = fail
replace f (return x) = return x
replace f token = token
replace f (tok x) = tok x
replace f (p₁ ⊛ p₂) = replace f p₁ ⊛ replace f p₂
replace f (p₁ <⊛ p₂) = replace f p₁ <⊛ replace f p₂
replace f (p₁ >>= p₂) = replace f p₁ >>= λ x → replace f (p₂ x)
replace f (p₁ ∣ p₂) = replace f p₁ ∣ replace f p₂
replace f (p ⋆) = replace f p ⋆
-- A lemma relating the resulting production with the original one in
-- case every non-terminal is replaced by fail.
replace-fail :
∀ {NT A g} (p : Prod NT A) {x s} →
[ empty-grammar ] x ∈ replace (λ _ → fail) p · s →
[ g ] x ∈ p · s
replace-fail (! nt) ()
replace-fail fail ()
replace-fail (return x) return-sem = return-sem
replace-fail token token-sem = token-sem
replace-fail (tok t) tok-sem = tok-sem
replace-fail (p₁ ⊛ p₂) (⊛-sem f∈ x∈) = ⊛-sem (replace-fail p₁ f∈) (replace-fail p₂ x∈)
replace-fail (p₁ <⊛ p₂) (<⊛-sem x∈ y∈) = <⊛-sem (replace-fail p₁ x∈) (replace-fail p₂ y∈)
replace-fail (p₁ >>= p₂) (>>=-sem x∈ y∈) = >>=-sem (replace-fail p₁ x∈) (replace-fail (p₂ _) y∈)
replace-fail (p₁ ∣ p₂) (left-sem x∈) = left-sem (replace-fail p₁ x∈)
replace-fail (p₁ ∣ p₂) (right-sem x∈) = right-sem (replace-fail p₂ x∈)
replace-fail (p ⋆) ⋆-[]-sem = ⋆-[]-sem
replace-fail (p ⋆) (⋆-+-sem xs∈) = ⋆-+-sem (replace-fail (p +) xs∈)
-- Unfolds every non-terminal. At most n /nested/ unfoldings are
-- performed.
unfold : ∀ {NT A} → (n : ℕ) → Grammar NT → Prod NT A → Prod NT A
unfold zero g p = p
unfold (suc n) g (! nt) = unfold n g (g _ nt)
unfold n g fail = fail
unfold n g (return x) = return x
unfold n g token = token
unfold n g (tok x) = tok x
unfold n g (p₁ ⊛ p₂) = unfold n g p₁ ⊛ unfold n g p₂
unfold n g (p₁ <⊛ p₂) = unfold n g p₁ <⊛ unfold n g p₂
unfold n g (p₁ >>= p₂) = unfold n g p₁ >>= λ x → unfold n g (p₂ x)
unfold n g (p₁ ∣ p₂) = unfold n g p₁ ∣ unfold n g p₂
unfold n g (p ⋆) = unfold n g p ⋆
-- Unfold is semantics-preserving.
unfold-to : ∀ {NT A} {g : Grammar NT} {x s} n (p : Prod NT A) →
[ g ] x ∈ p · s → [ g ] x ∈ unfold n g p · s
unfold-to zero p x∈ = x∈
unfold-to (suc n) (! nt) (!-sem x∈) = unfold-to n _ x∈
unfold-to (suc n) fail x∈ = x∈
unfold-to (suc n) (return x) x∈ = x∈
unfold-to (suc n) token x∈ = x∈
unfold-to (suc n) (tok x) x∈ = x∈
unfold-to (suc n) (p₁ ⊛ p₂) (⊛-sem f∈ x∈) = ⊛-sem (unfold-to (suc n) p₁ f∈)
(unfold-to (suc n) p₂ x∈)
unfold-to (suc n) (p₁ <⊛ p₂) (<⊛-sem x∈ y∈) = <⊛-sem (unfold-to (suc n) p₁ x∈)
(unfold-to (suc n) p₂ y∈)
unfold-to (suc n) (p₁ >>= p₂) (>>=-sem x∈ y∈) = >>=-sem (unfold-to (suc n) p₁ x∈)
(unfold-to (suc n) (p₂ _) y∈)
unfold-to (suc n) (p₁ ∣ p₂) (left-sem x∈) = left-sem (unfold-to (suc n) p₁ x∈)
unfold-to (suc n) (p₁ ∣ p₂) (right-sem x∈) = right-sem (unfold-to (suc n) p₂ x∈)
unfold-to (suc n) (p ⋆) ⋆-[]-sem = ⋆-[]-sem
unfold-to (suc n) (p ⋆) (⋆-+-sem xs∈) = ⋆-+-sem (unfold-to (suc n) (p +) xs∈)
unfold-from : ∀ {NT A} {g : Grammar NT} {x s} n (p : Prod NT A) →
[ g ] x ∈ unfold n g p · s → [ g ] x ∈ p · s
unfold-from zero p x∈ = x∈
unfold-from (suc n) (! nt) x∈ = !-sem (unfold-from n _ x∈)
unfold-from (suc n) fail x∈ = x∈
unfold-from (suc n) (return x) x∈ = x∈
unfold-from (suc n) token x∈ = x∈
unfold-from (suc n) (tok x) x∈ = x∈
unfold-from (suc n) (p₁ ⊛ p₂) (⊛-sem f∈ x∈) = ⊛-sem (unfold-from (suc n) p₁ f∈)
(unfold-from (suc n) p₂ x∈)
unfold-from (suc n) (p₁ <⊛ p₂) (<⊛-sem x∈ y∈) = <⊛-sem (unfold-from (suc n) p₁ x∈)
(unfold-from (suc n) p₂ y∈)
unfold-from (suc n) (p₁ >>= p₂) (>>=-sem x∈ y∈) = >>=-sem (unfold-from (suc n) p₁ x∈)
(unfold-from (suc n) (p₂ _) y∈)
unfold-from (suc n) (p₁ ∣ p₂) (left-sem x∈) = left-sem (unfold-from (suc n) p₁ x∈)
unfold-from (suc n) (p₁ ∣ p₂) (right-sem x∈) = right-sem (unfold-from (suc n) p₂ x∈)
unfold-from (suc n) (p ⋆) ⋆-[]-sem = ⋆-[]-sem
unfold-from (suc n) (p ⋆) (⋆-+-sem xs∈) = ⋆-+-sem (unfold-from (suc n) (p +) xs∈)
------------------------------------------------------------------------
-- Nullability
-- A production is nullable (with respect to a given grammar) if the
-- empty string is a member of the language defined by the production.
Nullable : ∀ {NT A} → Grammar NT → Prod NT A → Set₁
Nullable g p = ∃ λ x → [ g ] x ∈ p · []
-- Nullability is not decidable, not even for productions without
-- non-terminals. If nullability were decidable, then we could decide
-- if a given function of type ℕ → Bool always returns false.
nullability-not-decidable :
(∀ {A} (p : Prod Empty-NT A) → Dec (Nullable empty-grammar p)) →
(f : ℕ → Bool) → Dec (∀ n → f n ≡ false)
nullability-not-decidable dec f = goal
where
p : Prod Empty-NT ℕ
p = return tt ⋆ >>= λ tts →
let n = length tts in
if f n then return n else fail
true-lemma : ∀ {n s} → [ empty-grammar ] n ∈ p · s → f n ≡ true
true-lemma (>>=-sem {x = tts} _ _)
with f (length tts) | P.inspect f (length tts)
true-lemma (>>=-sem _ return-sem) | true | P.[ fn≡true ] = fn≡true
true-lemma (>>=-sem _ ()) | false | _
no-lemma : ∀ {n} → f n ≡ true → ¬ (∀ n → f n ≡ false)
no-lemma {n} ≡true ≡false with begin
true ≡⟨ P.sym ≡true ⟩
f n ≡⟨ ≡false n ⟩
false ∎
where open P.≡-Reasoning
... | ()
to-tts : ℕ → List ⊤
to-tts n = replicate n tt
n∈₁ : ∀ n → [ empty-grammar ] to-tts n ∈ return tt ⋆ · []
n∈₁ zero = ⋆-[]-sem
n∈₁ (suc n) = ⋆-∷-sem return-sem (n∈₁ n)
n∈₂ : ∀ n → f n ≡ true →
let n′ = length (replicate n tt) in
[ empty-grammar ] n ∈ if f n′ then return n′ else fail · []
n∈₂ n fn≡true rewrite length-replicate n {x = tt} | fn≡true =
return-sem
yes-lemma : ∀ n → ¬ ([ empty-grammar ] n ∈ p · []) → f n ≢ true
yes-lemma n n∉ fn≡true = n∉ (>>=-sem (n∈₁ n) (n∈₂ n fn≡true))
goal : Dec (∀ n → f n ≡ false)
goal with dec p
... | yes (_ , n∈) = no (no-lemma (true-lemma n∈))
... | no ¬[]∈ = yes λ n → ¬-not (yes-lemma n (¬[]∈ ∘ -,_))
-- However, we can implement a procedure that either proves that a
-- production is nullable, or returns "don't know" as the answer.
--
-- Note that, in the case of bind, the second argument is only applied
-- to one input—the first argument could give rise to infinitely many
-- results (as in the example above).
--
-- Note also that no attempt is made to memoise non-terminals—the
-- grammar could consist of an infinite number of non-terminals.
-- Instead the grammar is unfolded a certain number of times (n).
-- Memoisation still seems like a useful heuristic, but requires that
-- equality of non-terminals is decidable.
nullable? : ∀ {NT A} (n : ℕ) (g : Grammar NT) (p : Prod NT A) →
Maybe (Nullable g p)
nullable? {NT} n g p =
Product.map id (unfold-from n _) <$>M null? (unfold n g p)
where
null? : ∀ {A} (p : Prod NT A) → Maybe (Nullable g p)
null? (! nt) = nothing
null? fail = nothing
null? token = nothing
null? (tok t) = nothing
null? (return x) = just (x , return-sem)
null? (p ⋆) = just ([] , ⋆-[]-sem)
null? (p₁ ⊛ p₂) = Product.zip _$_ ⊛-sem <$>M null? p₁ ⊛M null? p₂
null? (p₁ <⊛ p₂) = Product.zip const <⊛-sem <$>M null? p₁ ⊛M null? p₂
null? (p₁ >>= p₂) = null? p₁ >>=M λ { (x , x∈) →
null? (p₂ x) >>=M λ { (y , y∈) →
just (y , >>=-sem x∈ y∈) }}
null? (p₁ ∣ p₂) = (Product.map id left-sem <$>M null? p₁)
∣M
(Product.map id right-sem <$>M null? p₂)
------------------------------------------------------------------------
-- Detecting the whitespace combinator
-- A predicate for the whitespace combinator.
data Is-whitespace {NT} : ∀ {A} → Prod NT A → Set₁ where
is-whitespace : Is-whitespace whitespace
-- Detects the whitespace combinator.
is-whitespace? : ∀ {NT A} (p : Prod NT A) → Maybe (Is-whitespace p)
is-whitespace? {NT} (tok ' ' ∣ p) = helper p P.refl
where
helper : ∀ {A} (p : Prod NT A) (eq : A ≡ Char) →
Maybe (Is-whitespace (tok ' ' ∣ P.subst (Prod NT) eq p))
helper (tok '\n') P.refl = just is-whitespace
helper _ _ = nothing
is-whitespace? _ = nothing
------------------------------------------------------------------------
-- Trailing whitespace
-- A predicate for productions that can "swallow" extra trailing
-- whitespace.
Trailing-whitespace : ∀ {NT A} → Grammar NT → Prod NT A → Set₁
Trailing-whitespace g p =
∀ {x s} → [ g ] x ∈ p <⊛ whitespace ⋆ · s → [ g ] x ∈ p · s
-- A heuristic procedure that either proves that a production can
-- swallow trailing whitespace, or returns "don't know" as the answer.
trailing-whitespace :
∀ {NT A} (n : ℕ) (g : Grammar NT) (p : Prod NT A) →
Maybe (Trailing-whitespace g p)
trailing-whitespace {NT} n g p =
convert ∘ unfold-lemma <$>M trailing? (unfold n g p)
where
-- An alternative formulation of Trailing-whitespace.
Trailing-whitespace′ : ∀ {NT A} → Grammar NT → Prod NT A → Set₁
Trailing-whitespace′ g p =
∀ {x s₁ s₂ s} →
[ g ] x ∈ p · s₁ → [ g ] s ∈ whitespace ⋆ · s₂ →
[ g ] x ∈ p · s₁ ++ s₂
convert : ∀ {NT A} {g : Grammar NT} {p : Prod NT A} →
Trailing-whitespace′ g p → Trailing-whitespace g p
convert t (<⊛-sem x∈ w) = t x∈ w
++-lemma : ∀ s₁ {s₂} → (s₁ ++ s₂) ++ [] ≡ (s₁ ++ []) ++ s₂
++-lemma _ = solve (++-monoid Char)
unfold-lemma : Trailing-whitespace′ g (unfold n g p) →
Trailing-whitespace′ g p
unfold-lemma t x∈ white = unfold-from n _ (t (unfold-to n _ x∈) white)
⊛-return-lemma :
∀ {A B} {p : Prod NT (A → B)} {x} →
Trailing-whitespace′ g p →
Trailing-whitespace′ g (p ⊛ return x)
⊛-return-lemma t (⊛-sem {s₁ = s₁} f∈ return-sem) white =
cast (++-lemma s₁) (⊛-sem (t f∈ white) return-sem)
+-lemma :
∀ {A} {p : Prod NT A} →
Trailing-whitespace′ g p →
Trailing-whitespace′ g (p +)
+-lemma t (⊛-sem (⊛-sem {s₂ = s₁} return-sem x∈) ⋆-[]-sem) white =
cast (++-lemma s₁) (+-sem (t x∈ white) ⋆-[]-sem)
+-lemma t (⊛-sem (⊛-sem {s₂ = s₁} return-sem x∈) (⋆-+-sem xs∈))
white =
cast (P.sym $ LM.assoc s₁ _ _)
(+-∷-sem x∈ (+-lemma t xs∈ white))
⊛-⋆-lemma :
∀ {A B} {p₁ : Prod NT (List A → B)} {p₂ : Prod NT A} →
Trailing-whitespace′ g p₁ →
Trailing-whitespace′ g p₂ →
Trailing-whitespace′ g (p₁ ⊛ p₂ ⋆)
⊛-⋆-lemma t₁ t₂ (⊛-sem {s₁ = s₁} f∈ ⋆-[]-sem) white =
cast (++-lemma s₁) (⊛-sem (t₁ f∈ white) ⋆-[]-sem)
⊛-⋆-lemma t₁ t₂ (⊛-sem {s₁ = s₁} f∈ (⋆-+-sem xs∈)) white =
cast (P.sym $ LM.assoc s₁ _ _)
(⊛-sem f∈ (⋆-+-sem (+-lemma t₂ xs∈ white)))
⊛-∣-lemma : ∀ {A B} {p₁ : Prod NT (A → B)} {p₂ p₃ : Prod NT A} →
Trailing-whitespace′ g (p₁ ⊛ p₂) →
Trailing-whitespace′ g (p₁ ⊛ p₃) →
Trailing-whitespace′ g (p₁ ⊛ (p₂ ∣ p₃))
⊛-∣-lemma t₁₂ t₁₃ {s₂ = s₃}
(⊛-sem {f = f} {x = x} {s₁ = s₁} {s₂ = s₂} f∈ (left-sem x∈))
white
with f x | (s₁ ++ s₂) ++ s₃ | t₁₂ (⊛-sem f∈ x∈) white
... | ._ | ._ | ⊛-sem f∈′ x∈′ = ⊛-sem f∈′ (left-sem x∈′)
⊛-∣-lemma t₁₂ t₁₃ {s₂ = s₃}
(⊛-sem {f = f} {x = x} {s₁ = s₁} {s₂ = s₂} f∈ (right-sem x∈))
white
with f x | (s₁ ++ s₂) ++ s₃ | t₁₃ (⊛-sem f∈ x∈) white
... | ._ | ._ | ⊛-sem f∈′ x∈′ = ⊛-sem f∈′ (right-sem x∈′)
⊛-lemma : ∀ {A B} {p₁ : Prod NT (A → B)} {p₂ : Prod NT A} →
Trailing-whitespace′ g p₂ →
Trailing-whitespace′ g (p₁ ⊛ p₂)
⊛-lemma t₂ (⊛-sem {s₁ = s₁} f∈ x∈) white =
cast (P.sym $ LM.assoc s₁ _ _)
(⊛-sem f∈ (t₂ x∈ white))
<⊛-return-lemma :
∀ {A B} {p : Prod NT A} {x : B} →
Trailing-whitespace′ g p →
Trailing-whitespace′ g (p <⊛ return x)
<⊛-return-lemma t (<⊛-sem {s₁ = s₁} f∈ return-sem) white =
cast (++-lemma s₁) (<⊛-sem (t f∈ white) return-sem)
<⊛-⋆-lemma :
∀ {A B} {p₁ : Prod NT A} {p₂ : Prod NT B} →
Is-whitespace p₂ →
Trailing-whitespace′ g (p₁ <⊛ p₂ ⋆)
<⊛-⋆-lemma is-whitespace (<⊛-sem {s₁ = s₁} x∈ white₁) white₂ =
cast (P.sym $ LM.assoc s₁ _ _)
(<⊛-sem x∈ (⋆-⋆-sem white₁ white₂))
<⊛-lemma : ∀ {A B} {p₁ : Prod NT A} {p₂ : Prod NT B} →
Trailing-whitespace′ g p₂ →
Trailing-whitespace′ g (p₁ <⊛ p₂)
<⊛-lemma t₂ (<⊛-sem {s₁ = s₁} f∈ x∈) white =
cast (P.sym $ LM.assoc s₁ _ _)
(<⊛-sem f∈ (t₂ x∈ white))
fail->>=-lemma : ∀ {A B} {p : A → Prod NT B} →
Trailing-whitespace′ g (fail >>= p)
fail->>=-lemma (>>=-sem () _)
return->>=-lemma : ∀ {A B} {p : A → Prod NT B} {x} →
Trailing-whitespace′ g (p x) →
Trailing-whitespace′ g (return x >>= p)
return->>=-lemma t (>>=-sem return-sem y∈) white =
>>=-sem return-sem (t y∈ white)
tok->>=-lemma : ∀ {A} {p : Char → Prod NT A} {t} →
Trailing-whitespace′ g (p t) →
Trailing-whitespace′ g (tok t >>= p)
tok->>=-lemma t (>>=-sem tok-sem y∈) white =
>>=-sem tok-sem (t y∈ white)
∣-lemma : ∀ {A} {p₁ p₂ : Prod NT A} →
Trailing-whitespace′ g p₁ →
Trailing-whitespace′ g p₂ →
Trailing-whitespace′ g (p₁ ∣ p₂)
∣-lemma t₁ t₂ (left-sem x∈) white = left-sem (t₁ x∈ white)
∣-lemma t₁ t₂ (right-sem x∈) white = right-sem (t₂ x∈ white)
trailing? : ∀ {A} (p : Prod NT A) →
Maybe (Trailing-whitespace′ g p)
trailing? fail = just (λ ())
trailing? (p ⊛ return x) = ⊛-return-lemma <$>M trailing? p
trailing? (p₁ ⊛ p₂ ⋆) = ⊛-⋆-lemma <$>M trailing? p₁ ⊛M trailing? p₂
trailing? (p₁ ⊛ (p₂ ∣ p₃)) = ⊛-∣-lemma <$>M trailing? (p₁ ⊛ p₂)
⊛M trailing? (p₁ ⊛ p₃)
trailing? (p₁ ⊛ p₂) = ⊛-lemma <$>M trailing? p₂
trailing? (p <⊛ return x) = <⊛-return-lemma <$>M trailing? p
trailing? (p₁ <⊛ p₂ ⋆) = <⊛-⋆-lemma <$>M is-whitespace? p₂
trailing? (p₁ <⊛ p₂) = <⊛-lemma <$>M trailing? p₂
trailing? (fail >>= p) = just fail->>=-lemma
trailing? (return x >>= p) = return->>=-lemma <$>M trailing? (p x)
trailing? (tok t >>= p) = tok->>=-lemma <$>M trailing? (p t)
trailing? (p₁ ∣ p₂) = ∣-lemma <$>M trailing? p₁ ⊛M trailing? p₂
trailing? _ = nothing
private
-- A unit test.
test : T (is-just (trailing-whitespace
0 empty-grammar (tt <$ whitespace ⋆)))
test = _
| {
"alphanum_fraction": 0.4795025334,
"avg_line_length": 37.8462757528,
"ext": "agda",
"hexsha": "8be867f0aeda6f13f29504777990684139a9f7ad",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/pretty",
"max_forks_repo_path": "Grammar/Non-terminal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/pretty",
"max_issues_repo_path": "Grammar/Non-terminal.agda",
"max_line_length": 96,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b956803ba90b6c5f57bbbaab01bb18485d948492",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/pretty",
"max_stars_repo_path": "Grammar/Non-terminal.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 9372,
"size": 23881
} |
{-# OPTIONS --without-K #-}
module hott.truncation.const where
open import sum
open import equality
open import function.overloading
open import hott.truncation.core
open import hott.level
const-factorisation : ∀ {i j}{A : Set i}{B : Set j}
→ h 2 B
→ (f : A → B)
→ ((x y : A) → f x ≡ f y)
→ (Trunc 1 A → B)
const-factorisation {A = A}{B} hB f c = f'
where
E : Set _
E = Σ B λ b → (a : A) → f a ≡ b
p : E → B
p (b , _) = b
lem : (a₀ : A)(b : B)(u : (a : A) → f a ≡ b)
→ (_≡_ {A = E} (f a₀ , λ a → c a a₀) (b , u))
lem a₀ b u = unapΣ (u a₀ , h1⇒prop (Π-level (λ a → hB (f a) b)) _ u)
hE : A → contr E
hE a₀ = (f a₀ , λ a → c a a₀) , λ { (b , u) → lem a₀ b u }
u : Trunc 1 A → contr E
u = Trunc-elim 1 _ _ (contr-h1 E) hE
s : Trunc 1 A → E
s a = proj₁ (u a)
f' : Trunc 1 A → B
f' a = p (s a)
| {
"alphanum_fraction": 0.4470338983,
"avg_line_length": 24.2051282051,
"ext": "agda",
"hexsha": "07f78435a61f9842e9262c7247ce9436945fffdc",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/hott/truncation/const.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/hott/truncation/const.agda",
"max_line_length": 72,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/hott/truncation/const.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 380,
"size": 944
} |
{-# OPTIONS --without-K #-}
module algebra where
open import algebra.semigroup public
open import algebra.monoid public
open import algebra.group public
| {
"alphanum_fraction": 0.7870967742,
"avg_line_length": 22.1428571429,
"ext": "agda",
"hexsha": "b10932d3bb385e1369fedbc07dda10c6ffb8a4b6",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/algebra.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/algebra.agda",
"max_line_length": 36,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/algebra.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 31,
"size": 155
} |
{-# OPTIONS --safe #-}
module Cubical.HITs.SequentialColimit where
open import Cubical.HITs.SequentialColimit.Base public
open import Cubical.HITs.SequentialColimit.Properties public
| {
"alphanum_fraction": 0.8260869565,
"avg_line_length": 30.6666666667,
"ext": "agda",
"hexsha": "41c17bad87ababa75a9ce56d69e140ed9e2f6656",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/HITs/SequentialColimit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/HITs/SequentialColimit.agda",
"max_line_length": 60,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/HITs/SequentialColimit.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 42,
"size": 184
} |
open import Prelude
open import Nat
open import core
open import contexts
open import disjointness
-- this module contains lemmas and properties about the holes-disjoint
-- judgement that double check that it acts as we would expect
module holes-disjoint-checks where
-- these lemmas are all structurally recursive and quite
-- mechanical. morally, they establish the properties about reduction
-- that would be obvious / baked into Agda if holes-disjoint was defined
-- as a function rather than a judgement (datatype), or if we had defined
-- all the O(n^2) cases rather than relying on a little indirection to
-- only have O(n) cases. that work has to go somewhwere, and we prefer
-- that it goes here.
ds-lem-asc : ∀{e1 e2 τ} → holes-disjoint e2 e1 → holes-disjoint e2 (e1 ·: τ)
ds-lem-asc HDConst = HDConst
ds-lem-asc (HDAsc hd) = HDAsc (ds-lem-asc hd)
ds-lem-asc HDVar = HDVar
ds-lem-asc (HDLam1 hd) = HDLam1 (ds-lem-asc hd)
ds-lem-asc (HDLam2 hd) = HDLam2 (ds-lem-asc hd)
ds-lem-asc (HDHole x) = HDHole (HNAsc x)
ds-lem-asc (HDNEHole x hd) = HDNEHole (HNAsc x) (ds-lem-asc hd)
ds-lem-asc (HDAp hd hd₁) = HDAp (ds-lem-asc hd) (ds-lem-asc hd₁)
ds-lem-lam1 : ∀{e1 e2 x} → holes-disjoint e2 e1 → holes-disjoint e2 (·λ x e1)
ds-lem-lam1 HDConst = HDConst
ds-lem-lam1 (HDAsc hd) = HDAsc (ds-lem-lam1 hd)
ds-lem-lam1 HDVar = HDVar
ds-lem-lam1 (HDLam1 hd) = HDLam1 (ds-lem-lam1 hd)
ds-lem-lam1 (HDLam2 hd) = HDLam2 (ds-lem-lam1 hd)
ds-lem-lam1 (HDHole x₁) = HDHole (HNLam1 x₁)
ds-lem-lam1 (HDNEHole x₁ hd) = HDNEHole (HNLam1 x₁) (ds-lem-lam1 hd)
ds-lem-lam1 (HDAp hd hd₁) = HDAp (ds-lem-lam1 hd) (ds-lem-lam1 hd₁)
ds-lem-lam2 : ∀{e1 e2 x τ} → holes-disjoint e2 e1 → holes-disjoint e2 (·λ x [ τ ] e1)
ds-lem-lam2 HDConst = HDConst
ds-lem-lam2 (HDAsc hd) = HDAsc (ds-lem-lam2 hd)
ds-lem-lam2 HDVar = HDVar
ds-lem-lam2 (HDLam1 hd) = HDLam1 (ds-lem-lam2 hd)
ds-lem-lam2 (HDLam2 hd) = HDLam2 (ds-lem-lam2 hd)
ds-lem-lam2 (HDHole x₁) = HDHole (HNLam2 x₁)
ds-lem-lam2 (HDNEHole x₁ hd) = HDNEHole (HNLam2 x₁) (ds-lem-lam2 hd)
ds-lem-lam2 (HDAp hd hd₁) = HDAp (ds-lem-lam2 hd) (ds-lem-lam2 hd₁)
ds-lem-nehole : ∀{e e1 u} → holes-disjoint e e1 → hole-name-new e u → holes-disjoint e ⦇⌜ e1 ⌟⦈[ u ]
ds-lem-nehole HDConst ν = HDConst
ds-lem-nehole (HDAsc hd) (HNAsc ν) = HDAsc (ds-lem-nehole hd ν)
ds-lem-nehole HDVar ν = HDVar
ds-lem-nehole (HDLam1 hd) (HNLam1 ν) = HDLam1 (ds-lem-nehole hd ν)
ds-lem-nehole (HDLam2 hd) (HNLam2 ν) = HDLam2 (ds-lem-nehole hd ν)
ds-lem-nehole (HDHole x) (HNHole x₁) = HDHole (HNNEHole (flip x₁) x)
ds-lem-nehole (HDNEHole x hd) (HNNEHole x₁ ν) = HDNEHole (HNNEHole (flip x₁) x) (ds-lem-nehole hd ν)
ds-lem-nehole (HDAp hd hd₁) (HNAp ν ν₁) = HDAp (ds-lem-nehole hd ν) (ds-lem-nehole hd₁ ν₁)
ds-lem-ap : ∀{e1 e2 e3} → holes-disjoint e3 e1 → holes-disjoint e3 e2 → holes-disjoint e3 (e1 ∘ e2)
ds-lem-ap HDConst hd2 = HDConst
ds-lem-ap (HDAsc hd1) (HDAsc hd2) = HDAsc (ds-lem-ap hd1 hd2)
ds-lem-ap HDVar hd2 = HDVar
ds-lem-ap (HDLam1 hd1) (HDLam1 hd2) = HDLam1 (ds-lem-ap hd1 hd2)
ds-lem-ap (HDLam2 hd1) (HDLam2 hd2) = HDLam2 (ds-lem-ap hd1 hd2)
ds-lem-ap (HDHole x) (HDHole x₁) = HDHole (HNAp x x₁)
ds-lem-ap (HDNEHole x hd1) (HDNEHole x₁ hd2) = HDNEHole (HNAp x x₁) (ds-lem-ap hd1 hd2)
ds-lem-ap (HDAp hd1 hd2) (HDAp hd3 hd4) = HDAp (ds-lem-ap hd1 hd3) (ds-lem-ap hd2 hd4)
-- holes-disjoint is symmetric
disjoint-sym : (e1 e2 : hexp) → holes-disjoint e1 e2 → holes-disjoint e2 e1
disjoint-sym .c c HDConst = HDConst
disjoint-sym .c (e2 ·: x) HDConst = HDAsc (disjoint-sym _ _ HDConst)
disjoint-sym .c (X x) HDConst = HDVar
disjoint-sym .c (·λ x e2) HDConst = HDLam1 (disjoint-sym c e2 HDConst)
disjoint-sym .c (·λ x [ x₁ ] e2) HDConst = HDLam2 (disjoint-sym c e2 HDConst)
disjoint-sym .c ⦇-⦈[ x ] HDConst = HDHole HNConst
disjoint-sym .c ⦇⌜ e2 ⌟⦈[ x ] HDConst = HDNEHole HNConst (disjoint-sym c e2 HDConst)
disjoint-sym .c (e2 ∘ e3) HDConst = HDAp (disjoint-sym c e2 HDConst) (disjoint-sym c e3 HDConst)
disjoint-sym _ c (HDAsc hd) = HDConst
disjoint-sym _ (e2 ·: x) (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ·: x) (HDAsc hd) | HDAsc ih = HDAsc (ds-lem-asc ih)
disjoint-sym _ (X x) (HDAsc hd) = HDVar
disjoint-sym _ (·λ x e2) (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x e2) (HDAsc hd) | HDLam1 ih = HDLam1 (ds-lem-asc ih)
disjoint-sym _ (·λ x [ x₁ ] e2) (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x [ x₁ ] e2) (HDAsc hd) | HDLam2 ih = HDLam2 (ds-lem-asc ih)
disjoint-sym _ ⦇-⦈[ x ] (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇-⦈[ x ] (HDAsc hd) | HDHole x₁ = HDHole (HNAsc x₁)
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x ] (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x ] (HDAsc hd) | HDNEHole x₁ ih = HDNEHole (HNAsc x₁) (ds-lem-asc ih)
disjoint-sym _ (e2 ∘ e3) (HDAsc hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ∘ e3) (HDAsc hd) | HDAp ih ih₁ = HDAp (ds-lem-asc ih) (ds-lem-asc ih₁)
disjoint-sym _ c HDVar = HDConst
disjoint-sym _ (e2 ·: x₁) HDVar = HDAsc (disjoint-sym _ e2 HDVar)
disjoint-sym _ (X x₁) HDVar = HDVar
disjoint-sym _ (·λ x₁ e2) HDVar = HDLam1 (disjoint-sym _ e2 HDVar)
disjoint-sym _ (·λ x₁ [ x₂ ] e2) HDVar = HDLam2 (disjoint-sym _ e2 HDVar)
disjoint-sym _ ⦇-⦈[ x₁ ] HDVar = HDHole HNVar
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x₁ ] HDVar = HDNEHole HNVar (disjoint-sym _ e2 HDVar)
disjoint-sym _ (e2 ∘ e3) HDVar = HDAp (disjoint-sym _ e2 HDVar) (disjoint-sym _ e3 HDVar)
disjoint-sym _ c (HDLam1 hd) = HDConst
disjoint-sym _ (e2 ·: x₁) (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ·: x₁) (HDLam1 hd) | HDAsc ih = HDAsc (ds-lem-lam1 ih)
disjoint-sym _ (X x₁) (HDLam1 hd) = HDVar
disjoint-sym _ (·λ x₁ e2) (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x₁ e2) (HDLam1 hd) | HDLam1 ih = HDLam1 (ds-lem-lam1 ih)
disjoint-sym _ (·λ x₁ [ x₂ ] e2) (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x₁ [ x₂ ] e2) (HDLam1 hd) | HDLam2 ih = HDLam2 (ds-lem-lam1 ih)
disjoint-sym _ ⦇-⦈[ x₁ ] (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇-⦈[ x₁ ] (HDLam1 hd) | HDHole x = HDHole (HNLam1 x)
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x₁ ] (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x₁ ] (HDLam1 hd) | HDNEHole x ih = HDNEHole (HNLam1 x) (ds-lem-lam1 ih)
disjoint-sym _ (e2 ∘ e3) (HDLam1 hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ∘ e3) (HDLam1 hd) | HDAp ih ih₁ = HDAp (ds-lem-lam1 ih) (ds-lem-lam1 ih₁)
disjoint-sym _ c (HDLam2 hd) = HDConst
disjoint-sym _ (e2 ·: x₁) (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ·: x₁) (HDLam2 hd) | HDAsc ih = HDAsc (ds-lem-lam2 ih)
disjoint-sym _ (X x₁) (HDLam2 hd) = HDVar
disjoint-sym _ (·λ x₁ e2) (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x₁ e2) (HDLam2 hd) | HDLam1 ih = HDLam1 (ds-lem-lam2 ih)
disjoint-sym _ (·λ x₁ [ x₂ ] e2) (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x₁ [ x₂ ] e2) (HDLam2 hd) | HDLam2 ih = HDLam2 (ds-lem-lam2 ih)
disjoint-sym _ ⦇-⦈[ x₁ ] (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇-⦈[ x₁ ] (HDLam2 hd) | HDHole x = HDHole (HNLam2 x)
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x₁ ] (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x₁ ] (HDLam2 hd) | HDNEHole x ih = HDNEHole (HNLam2 x) (ds-lem-lam2 ih)
disjoint-sym _ (e2 ∘ e3) (HDLam2 hd) with disjoint-sym _ _ hd
disjoint-sym _ (e2 ∘ e3) (HDLam2 hd) | HDAp ih ih₁ = HDAp (ds-lem-lam2 ih) (ds-lem-lam2 ih₁)
disjoint-sym _ c (HDHole x) = HDConst
disjoint-sym _ (e2 ·: x) (HDHole (HNAsc x₁)) = HDAsc (disjoint-sym ⦇-⦈[ _ ] e2 (HDHole x₁))
disjoint-sym _ (X x) (HDHole x₁) = HDVar
disjoint-sym _ (·λ x e2) (HDHole (HNLam1 x₁)) = HDLam1 (disjoint-sym ⦇-⦈[ _ ] e2 (HDHole x₁))
disjoint-sym _ (·λ x [ x₁ ] e2) (HDHole (HNLam2 x₂)) = HDLam2 (disjoint-sym ⦇-⦈[ _ ] e2 (HDHole x₂))
disjoint-sym _ ⦇-⦈[ x ] (HDHole (HNHole x₁)) = HDHole (HNHole (flip x₁))
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ u' ] (HDHole (HNNEHole x x₁)) = HDNEHole (HNHole (flip x)) (disjoint-sym ⦇-⦈[ _ ] e2 (HDHole x₁))
disjoint-sym _ (e2 ∘ e3) (HDHole (HNAp x x₁)) = HDAp (disjoint-sym ⦇-⦈[ _ ] e2 (HDHole x))
(disjoint-sym ⦇-⦈[ _ ] e3 (HDHole x₁))
disjoint-sym _ c (HDNEHole x hd) = HDConst
disjoint-sym _ (e2 ·: x) (HDNEHole x₁ hd) with disjoint-sym _ _ hd
disjoint-sym _ (e ·: x) (HDNEHole (HNAsc x₁) hd) | HDAsc ih = HDAsc (ds-lem-nehole ih x₁)
disjoint-sym _ (X x) (HDNEHole x₁ hd) = HDVar
disjoint-sym _ (·λ x e2) (HDNEHole x₁ hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x e2) (HDNEHole (HNLam1 x₁) hd) | HDLam1 ih = HDLam1 (ds-lem-nehole ih x₁)
disjoint-sym _ (·λ x [ x₁ ] e2) (HDNEHole x₂ hd) with disjoint-sym _ _ hd
disjoint-sym _ (·λ x [ x₁ ] e2) (HDNEHole (HNLam2 x₂) hd) | HDLam2 ih = HDLam2 (ds-lem-nehole ih x₂)
disjoint-sym _ ⦇-⦈[ x ] (HDNEHole x₁ hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇-⦈[ x ] (HDNEHole (HNHole x₂) hd) | HDHole x₁ = HDHole (HNNEHole (flip x₂) x₁)
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x ] (HDNEHole x₁ hd) with disjoint-sym _ _ hd
disjoint-sym _ ⦇⌜ e2 ⌟⦈[ x ] (HDNEHole (HNNEHole x₂ x₃) hd) | HDNEHole x₁ ih = HDNEHole (HNNEHole (flip x₂) x₁) (ds-lem-nehole ih x₃)
disjoint-sym _ (e2 ∘ e3) (HDNEHole x hd) with disjoint-sym _ _ hd
disjoint-sym _ (e1 ∘ e3) (HDNEHole (HNAp x x₁) hd) | HDAp ih ih₁ = HDAp (ds-lem-nehole ih x) (ds-lem-nehole ih₁ x₁)
disjoint-sym _ c (HDAp hd hd₁) = HDConst
disjoint-sym _ (e3 ·: x) (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (e3 ·: x) (HDAp hd hd₁) | HDAsc ih | HDAsc ih1 = HDAsc (ds-lem-ap ih ih1)
disjoint-sym _ (X x) (HDAp hd hd₁) = HDVar
disjoint-sym _ (·λ x e3) (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (·λ x e3) (HDAp hd hd₁) | HDLam1 ih | HDLam1 ih1 = HDLam1 (ds-lem-ap ih ih1)
disjoint-sym _ (·λ x [ x₁ ] e3) (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (·λ x [ x₁ ] e3) (HDAp hd hd₁) | HDLam2 ih | HDLam2 ih1 = HDLam2 (ds-lem-ap ih ih1)
disjoint-sym _ ⦇-⦈[ x ] (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ ⦇-⦈[ x ] (HDAp hd hd₁) | HDHole x₁ | HDHole x₂ = HDHole (HNAp x₁ x₂)
disjoint-sym _ ⦇⌜ e3 ⌟⦈[ x ] (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ ⦇⌜ e3 ⌟⦈[ x ] (HDAp hd hd₁) | HDNEHole x₁ ih | HDNEHole x₂ ih1 = HDNEHole (HNAp x₁ x₂) (ds-lem-ap ih ih1)
disjoint-sym _ (e3 ∘ e4) (HDAp hd hd₁) with disjoint-sym _ _ hd | disjoint-sym _ _ hd₁
disjoint-sym _ (e3 ∘ e4) (HDAp hd hd₁) | HDAp ih ih₁ | HDAp ih1 ih2 = HDAp (ds-lem-ap ih ih1) (ds-lem-ap ih₁ ih2)
-- note that this is false, so holes-disjoint isn't transitive
-- disjoint-new : ∀{e1 e2 u} → holes-disjoint e1 e2 → hole-name-new e1 u → hole-name-new e2 u
-- it's also not reflexive, because ⦇-⦈[ u ] isn't hole-disjoint with
-- itself since refl : u == u; it's also not anti-reflexive, because the
-- expression c *is* hole-disjoint with itself (albeit vacuously)
| {
"alphanum_fraction": 0.6473731884,
"avg_line_length": 60.9944751381,
"ext": "agda",
"hexsha": "ca811d3e7677e2896aa1f74de6d61365432a0575",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_forks_repo_path": "holes-disjoint-checks.agda",
"max_issues_count": 54,
"max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_issues_repo_path": "holes-disjoint-checks.agda",
"max_line_length": 135,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_stars_repo_path": "holes-disjoint-checks.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z",
"num_tokens": 5089,
"size": 11040
} |
{-# OPTIONS --without-K --safe #-}
module Dodo.Binary.Disjoint where
-- Stdlib imports
open import Level using (Level; _⊔_) renaming (suc to ℓsuc)
open import Data.Empty using (⊥)
open import Data.Product using (_,_)
open import Relation.Unary using (Pred)
open import Relation.Binary using (REL)
open import Data.List using (List; _∷_; []; all; map)
open import Data.List.Relation.Unary.Any using (Any; here; there)
open import Relation.Nullary using (¬_)
-- Local imports
open import Dodo.Binary.Empty
open import Dodo.Binary.Equality
open import Dodo.Binary.Intersection
-- # Definitions
-- | Predicate stating two binary relations are never inhabited for the same elements.
Disjoint₂ : ∀ {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b}
→ REL A B ℓ₁ → REL A B ℓ₂ → Set _
Disjoint₂ P Q = Empty₂ (P ∩₂ Q)
-- | Given a predicate `P`, `Any₂ P xs` states that /at least two/ elements in
-- `xs` satisfy `P`.
data Any₂ {a ℓ : Level} {A : Set a} (P : Pred A ℓ) : Pred (List A) (a ⊔ ℓ) where
here : ∀ {x xs} (px : P x) → Any P xs → Any₂ P (x ∷ xs)
there : ∀ {x xs} (pxs : Any₂ P xs) → Any₂ P (x ∷ xs)
-- | A predicate stating any two predicates in the list cannot be inhabitated for the same elements.
PairwiseDisjoint₁ : {a ℓ : Level} {A : Set a} → List (Pred A ℓ) → Set (a ⊔ ℓsuc ℓ)
PairwiseDisjoint₁ Ps = ∀ {x} → Any₂ (λ{P → P x}) Ps → ⊥
-- | A predicate stating any two binary relations in the list cannot be inhabitated for the same elements.
PairwiseDisjoint₂ : {a b ℓ : Level} {A : Set a} {B : Set b} → List (REL A B ℓ) → Set (a ⊔ b ⊔ ℓsuc ℓ)
PairwiseDisjoint₂ Rs = ∀ {x y} → Any₂ (λ{R → R x y}) Rs → ⊥
-- # Properties
module _ {a b ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} where
-- | If P is disjoint with Q, then Q is surely also disjoint with P.
disjoint₂-sym : Disjoint₂ P Q → Disjoint₂ Q P
disjoint₂-sym disjointPQ x y [Q∩P]xy =
let [P∩Q]xy = ⇔₂-apply-⊆₂ (∩₂-comm {P = Q} {Q = P}) [Q∩P]xy
in disjointPQ x y [P∩Q]xy
module _ {a b ℓ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ} where
-- | Every relation is disjoint with its negation.
disjoint₂-neg : Disjoint₂ P (¬₂ P)
disjoint₂-neg x y (Pxy , ¬Pxy) = ¬Pxy Pxy
module _ {a b ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL A B ℓ₃} where
-- | If two relations P and Q are disjoint, then any subset R of P is also disjoint with Q.
disjoint₂-⊆ˡ : R ⊆₂ P → Disjoint₂ P Q → Disjoint₂ R Q
disjoint₂-⊆ˡ R⊆P disjointPQ x y [R∩Q]xy = disjointPQ x y (⊆₂-apply (∩₂-substˡ-⊆₂ {R = Q} R⊆P) [R∩Q]xy)
-- | If two relations P and Q are disjoint, then any subset R of Q is also disjoint with P.
disjoint₂-⊆ʳ : R ⊆₂ Q → Disjoint₂ P Q → Disjoint₂ P R
disjoint₂-⊆ʳ R⊆Q disjointPQ x y [P∩R]xy = disjointPQ x y (⊆₂-apply (∩₂-substʳ-⊆₂ {R = P} R⊆Q) [P∩R]xy)
| {
"alphanum_fraction": 0.6359119943,
"avg_line_length": 40.8405797101,
"ext": "agda",
"hexsha": "3b7d002837fa4a411055d6f058efba8d58e87976",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "sourcedennis/agda-dodo",
"max_forks_repo_path": "src/Dodo/Binary/Disjoint.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "sourcedennis/agda-dodo",
"max_issues_repo_path": "src/Dodo/Binary/Disjoint.agda",
"max_line_length": 112,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "sourcedennis/agda-dodo",
"max_stars_repo_path": "src/Dodo/Binary/Disjoint.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1097,
"size": 2818
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommAlgebra.Instances.Pointwise where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Algebra.CommRing.Base
open import Cubical.Algebra.CommRing.Instances.Pointwise
open import Cubical.Algebra.CommAlgebra.Base
private
variable
ℓ : Level
pointwiseAlgebra : {R : CommRing ℓ} (X : Type ℓ) (A : CommAlgebra R ℓ) → CommAlgebra R ℓ
pointwiseAlgebra {R = R} X A =
let open CommAlgebraStr (snd A)
isSetX→A = isOfHLevelΠ 2 (λ (x : X) → isSetCommRing (CommAlgebra→CommRing A))
in commAlgebraFromCommRing
(pointwiseRing X (CommAlgebra→CommRing A))
(λ r f → (λ x → r ⋆ (f x)))
(λ r s f i x → ⋆Assoc r s (f x) i)
(λ r f g i x → ⋆DistR+ r (f x) (g x) i)
(λ r s f i x → ⋆DistL+ r s (f x) i)
(λ f i x → ⋆IdL (f x) i)
λ r f g i x → ⋆AssocL r (f x) (g x) i
| {
"alphanum_fraction": 0.6438809261,
"avg_line_length": 33.5925925926,
"ext": "agda",
"hexsha": "2c5f417f327e2e4fe66d9e11a81c523ba1ae8827",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommAlgebra/Instances/Pointwise.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommAlgebra/Instances/Pointwise.agda",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommAlgebra/Instances/Pointwise.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 336,
"size": 907
} |
{-# OPTIONS --safe #-}
module Cubical.Experiments.Brunerie where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Univalence
open import Cubical.Data.Bool
open import Cubical.Data.Nat
open import Cubical.Data.Int
open import Cubical.HITs.S1 hiding (encode)
open import Cubical.HITs.S2
open import Cubical.HITs.S3
open import Cubical.HITs.Join
open import Cubical.HITs.SetTruncation as SetTrunc
open import Cubical.HITs.GroupoidTruncation as GroupoidTrunc
open import Cubical.HITs.2GroupoidTruncation as 2GroupoidTrunc
open import Cubical.HITs.Truncation as Trunc
open import Cubical.HITs.Susp renaming (toSusp to σ)
open import Cubical.Homotopy.Loopspace
open import Cubical.Homotopy.Hopf
open S¹Hopf
-- This code is adapted from examples/brunerie3.ctt on the pi4s3_nobug branch of cubicaltt
Bool∙ S¹∙ S³∙ : Pointed₀
Bool∙ = (Bool , true)
S¹∙ = (S¹ , base)
S³∙ = (S³ , base)
∥_∥₃∙ ∥_∥₄∙ : Pointed₀ → Pointed₀
∥ A , a ∥₃∙ = ∥ A ∥₃ , ∣ a ∣₃
∥ A , a ∥₄∙ = ∥ A ∥₄ , ∣ a ∣₄
join∙ : Pointed₀ → Type₀ → Pointed₀
join∙ (A , a) B = join A B , inl a
Ω² Ω³ : Pointed₀ → Pointed₀
Ω² = Ω^ 2
Ω³ = Ω^ 3
mapΩrefl : {A : Pointed₀} {B : Type₀} (f : A .fst → B) → Ω A .fst → Ω (B , f (pt A)) .fst
mapΩrefl f p i = f (p i)
mapΩ²refl : {A : Pointed₀} {B : Type₀} (f : A .fst → B) → Ω² A .fst → Ω² (B , f (pt A)) .fst
mapΩ²refl f p i j = f (p i j)
mapΩ³refl : {A : Pointed₀} {B : Type₀} (f : A .fst → B) → Ω³ A .fst → Ω³ (B , f (pt A)) .fst
mapΩ³refl f p i j k = f (p i j k)
meridS² : S¹ → Path S² base base
meridS² base _ = base
meridS² (loop i) j = surf i j
alpha : join S¹ S¹ → S²
alpha (inl x) = base
alpha (inr y) = base
alpha (push x y i) = (meridS² y ∙ meridS² x) i
connectionBoth : {A : Type₀} {a : A} (p : Path A a a) → PathP (λ i → Path A (p i) (p i)) p p
connectionBoth {a = a} p i j =
hcomp
(λ k → λ
{ (i = i0) → p (j ∨ ~ k)
; (i = i1) → p (j ∧ k)
; (j = i0) → p (i ∨ ~ k)
; (j = i1) → p (i ∧ k)
})
a
data PostTotalHopf : Type₀ where
base : S¹ → PostTotalHopf
loop : (x : S¹) → PathP (λ i → Path PostTotalHopf (base x) (base (rotLoop x (~ i)))) refl refl
tee12 : (x : S²) → HopfS² x → PostTotalHopf
tee12 base y = base y
tee12 (surf i j) y =
hcomp
(λ k → λ
{ (i = i0) → base y
; (i = i1) → base y
; (j = i0) → base y
; (j = i1) → base (rotLoopInv y (~ i) k)
})
(loop (unglue (i ∨ ~ i ∨ j ∨ ~ j) y) i j)
tee34 : PostTotalHopf → join S¹ S¹
tee34 (base x) = inl x
tee34 (loop x i j) =
hcomp
(λ k → λ
{ (i = i0) → push x x (j ∧ ~ k)
; (i = i1) → push x x (j ∧ ~ k)
; (j = i0) → inl x
; (j = i1) → push (rotLoop x (~ i)) x (~ k)
})
(push x x j)
tee : (x : S²) → HopfS² x → join S¹ S¹
tee x y = tee34 (tee12 x y)
fibΩ : {B : Pointed₀} (P : B .fst → Type₀) → P (pt B) → Ω B .fst → Type₀
fibΩ P f p = PathP (λ i → P (p i)) f f
fibΩ² : {B : Pointed₀} (P : B .fst → Type₀) → P (pt B) → Ω² B .fst → Type₀
fibΩ² P f = fibΩ (fibΩ P f) refl
fibΩ³ : {B : Pointed₀} (P : B .fst → Type₀) → P (pt B) → Ω³ B .fst → Type₀
fibΩ³ P f = fibΩ² (fibΩ P f) refl
Ω³Hopf : Ω³ S²∙ .fst → Type₀
Ω³Hopf = fibΩ³ HopfS² base
fibContrΩ³Hopf : ∀ p → Ω³Hopf p
fibContrΩ³Hopf p i j k =
hcomp
(λ m → λ
{ (i = i0) → base
; (i = i1) → base
; (j = i0) → base
; (j = i1) → base
; (k = i0) → base
; (k = i1) →
isSetΩS¹ refl refl
(λ i j → transp (λ n → HopfS² (p i j n)) (i ∨ ~ i ∨ j ∨ ~ j) base)
(λ _ _ → base)
m i j
})
(transp (λ n → HopfS² (p i j (k ∧ n))) (i ∨ ~ i ∨ j ∨ ~ j ∨ ~ k) base)
h : Ω³ S²∙ .fst → Ω³ (join∙ S¹∙ S¹) .fst
h p i j k = tee (p i j k) (fibContrΩ³Hopf p i j k)
multTwoAux : (x : S²) → Path (Path ∥ S² ∥₄ ∣ x ∣₄ ∣ x ∣₄) refl refl
multTwoAux base i j = ∣ surf i j ∣₄
multTwoAux (surf k l) i j =
hcomp
(λ m → λ
{ (i = i0) → ∣ surf k l ∣₄
; (i = i1) → ∣ surf k l ∣₄
; (j = i0) → ∣ surf k l ∣₄
; (j = i1) → ∣ surf k l ∣₄
; (k = i0) → ∣ surf i j ∣₄
; (k = i1) → ∣ surf i j ∣₄
; (l = i0) → ∣ surf i j ∣₄
; (l = i1) → squash₄ _ _ _ _ _ _ (λ k i j → step₁ k i j) refl m k i j
})
(step₁ k i j)
where
step₁ : I → I → I → ∥ S² ∥₄
step₁ k i j =
hcomp {A = ∥ S² ∥₄}
(λ m → λ
{ (i = i0) → ∣ surf k (l ∧ m) ∣₄
; (i = i1) → ∣ surf k (l ∧ m) ∣₄
; (j = i0) → ∣ surf k (l ∧ m) ∣₄
; (j = i1) → ∣ surf k (l ∧ m) ∣₄
; (k = i0) → ∣ surf i j ∣₄
; (k = i1) → ∣ surf i j ∣₄
; (l = i0) → ∣ surf i j ∣₄
})
∣ surf i j ∣₄
multTwoTildeAux : (t : ∥ S² ∥₄) → Path (Path ∥ S² ∥₄ t t) refl refl
multTwoTildeAux ∣ x ∣₄ = multTwoAux x
multTwoTildeAux (squash₄ _ _ _ _ _ _ t u k l m n) i j =
squash₄ _ _ _ _ _ _
(λ k l m → multTwoTildeAux (t k l m) i j)
(λ k l m → multTwoTildeAux (u k l m) i j)
k l m n
multTwoEquivAux : Path (Path (∥ S² ∥₄ ≃ ∥ S² ∥₄) (idEquiv _) (idEquiv _)) refl refl
multTwoEquivAux i j =
( f i j
, hcomp
(λ l → λ
{ (i = i0) → isPropIsEquiv _ (idIsEquiv _) (idIsEquiv _) l
; (i = i1) → isPropIsEquiv _ (idIsEquiv _) (idIsEquiv _) l
; (j = i0) → isPropIsEquiv _ (idIsEquiv _) (idIsEquiv _) l
; (j = i1) →
isPropIsEquiv _
(transp (λ k → isEquiv (f i k)) (i ∨ ~ i) (idIsEquiv _))
(idIsEquiv _)
l
})
(transp (λ k → isEquiv (f i (j ∧ k))) (i ∨ ~ i ∨ ~ j) (idIsEquiv _))
)
where
f : I → I → ∥ S² ∥₄ → ∥ S² ∥₄
f i j t = multTwoTildeAux t i j
tHopf³ : S³ → Type₀
tHopf³ base = ∥ S² ∥₄
tHopf³ (surf i j k) =
Glue ∥ S² ∥₄
(λ { (i = i0) → (∥ S² ∥₄ , idEquiv _)
; (i = i1) → (∥ S² ∥₄ , idEquiv _)
; (j = i0) → (∥ S² ∥₄ , idEquiv _)
; (j = i1) → (∥ S² ∥₄ , idEquiv _)
; (k = i0) → (∥ S² ∥₄ , multTwoEquivAux i j)
; (k = i1) → (∥ S² ∥₄ , idEquiv _)
})
π₃S³ : Ω³ S³∙ .fst → Ω² ∥ S²∙ ∥₄∙ .fst
π₃S³ p i j = transp (λ k → tHopf³ (p j k i)) i0 ∣ base ∣₄
codeS² : S² → hGroupoid _
codeS² s = ∥ HopfS² s ∥₃ , squash₃
codeTruncS² : ∥ S² ∥₄ → hGroupoid _
codeTruncS² = 2GroupoidTrunc.rec (isOfHLevelTypeOfHLevel 3) codeS²
encodeTruncS² : Ω ∥ S²∙ ∥₄∙ .fst → ∥ S¹ ∥₃
encodeTruncS² p = transp (λ i → codeTruncS² (p i) .fst) i0 ∣ base ∣₃
codeS¹ : S¹ → hSet _
codeS¹ s = ∥ helix s ∥₂ , squash₂
codeTruncS¹ : ∥ S¹ ∥₃ → hSet _
codeTruncS¹ = GroupoidTrunc.rec (isOfHLevelTypeOfHLevel 2) codeS¹
encodeTruncS¹ : Ω ∥ S¹∙ ∥₃∙ .fst → ∥ ℤ ∥₂
encodeTruncS¹ p = transp (λ i → codeTruncS¹ (p i) .fst) i0 ∣ pos zero ∣₂
-- THE BIG GAME
f3 : Ω³ S³∙ .fst → Ω³ (join∙ S¹∙ S¹) .fst
f3 = mapΩ³refl S³→joinS¹S¹
f4 : Ω³ (join∙ S¹∙ S¹) .fst → Ω³ S²∙ .fst
f4 = mapΩ³refl alpha
f5 : Ω³ S²∙ .fst → Ω³ (join∙ S¹∙ S¹) .fst
f5 = h
f6 : Ω³ (join∙ S¹∙ S¹) .fst → Ω³ S³∙ .fst
f6 = mapΩ³refl joinS¹S¹→S³
f7 : Ω³ S³∙ .fst → Ω² ∥ S²∙ ∥₄∙ .fst
f7 = π₃S³
g8 : Ω² ∥ S²∙ ∥₄∙ .fst → Ω ∥ S¹∙ ∥₃∙ .fst
g8 = mapΩrefl encodeTruncS²
g9 : Ω ∥ S¹∙ ∥₃∙ .fst → ∥ ℤ ∥₂
g9 = encodeTruncS¹
g10 : ∥ ℤ ∥₂ → ℤ
g10 = SetTrunc.rec isSetℤ (idfun ℤ)
-- don't run me
brunerie : ℤ
brunerie = g10 (g9 (g8 (f7 (f6 (f5 (f4 (f3 (λ i j k → surf i j k))))))))
-- simpler tests
test63 : ℕ → ℤ
test63 n = g10 (g9 (g8 (f7 (63n n))))
where
63n : ℕ → Ω³ S³∙ .fst
63n zero i j k = surf i j k
63n (suc n) = f6 (f3 (63n n))
foo : Ω³ S²∙ .fst
foo i j k =
hcomp
(λ l → λ
{ (i = i0) → surf l l
; (i = i1) → surf l l
; (j = i0) → surf l l
; (j = i1) → surf l l
; (k = i0) → surf l l
; (k = i1) → surf l l
})
base
sorghum : Ω³ S²∙ .fst
sorghum i j k =
hcomp
(λ l → λ
{ (i = i0) → surf j l
; (i = i1) → surf k (~ l)
; (j = i0) → surf k (i ∧ ~ l)
; (j = i1) → surf k (i ∧ ~ l)
; (k = i0) → surf j (i ∨ l)
; (k = i1) → surf j (i ∨ l)
})
(hcomp
(λ l → λ
{ (i = i0) → base
; (i = i1) → surf j l
; (j = i0) → surf k i
; (j = i1) → surf k i
; (k = i0) → surf j (i ∧ l)
; (k = i1) → surf j (i ∧ l)
})
(surf k i))
goo : Ω³ S²∙ .fst → ℤ
goo x = g10 (g9 (g8 (f7 (f6 (f5 x)))))
{- Computation of an alternative definition of the Brunerie number
based on https://github.com/agda/cubical/pull/741. One should note
that this computation by no means is comparable to the one of the term
"brunerie" defined above. This computation starts in π₃S³ rather than
π₃S². -}
-- The brunerie element can be shown to correspond to the following map
η₃ : (join S¹ S¹ , inl base) →∙ (Susp S² , north)
fst η₃ (inl x) = north
fst η₃ (inr x) = north
fst η₃ (push a b i) =
(σ (S² , base) (S¹×S¹→S² a b) ∙ σ (S² , base) (S¹×S¹→S² a b)) i
where
S¹×S¹→S² : S¹ → S¹ → S²
S¹×S¹→S² base y = base
S¹×S¹→S² (loop i) base = base
S¹×S¹→S² (loop i) (loop j) = surf i j
snd η₃ = refl
K₂ = ∥ S² ∥₄
-- We will need a map Ω (Susp S²) → K₂. It turns out that the
-- following map is fast. It need a bit of work, however. It's
-- esentially the same map as you find in ZCohomology from ΩKₙ₊₁ to
-- Kₙ. This gives another definition of f7 which appears to work better.
module f7stuff where
_+₂_ : K₂ → K₂ → K₂
_+₂_ = 2GroupoidTrunc.elim (λ _ → isOfHLevelΠ 4 λ _ → squash₄)
λ { base x → x
; (surf i j) x → surfc x i j}
where
surfc : (x : K₂) → typ ((Ω^ 2) (K₂ , x))
surfc =
2GroupoidTrunc.elim
(λ _ → isOfHLevelPath 4 (isOfHLevelPath 4 squash₄ _ _) _ _)
(S²ToSetElim (λ _ → squash₄ _ _ _ _) λ i j → ∣ surf i j ∣₄)
K₂≃K₂ : (x : S²) → K₂ ≃ K₂
fst (K₂≃K₂ x) y = ∣ x ∣₄ +₂ y
snd (K₂≃K₂ x) = help x
where
help : (x : _) → isEquiv (λ y → ∣ x ∣₄ +₂ y)
help = S²ToSetElim (λ _ → isProp→isSet (isPropIsEquiv _))
(idEquiv _ .snd)
Code : Susp S² → Type ℓ-zero
Code north = K₂
Code south = K₂
Code (merid a i) = ua (K₂≃K₂ a) i
encode : (x : Susp S²) → north ≡ x → Code x
encode x = J (λ x p → Code x) ∣ base ∣₄
-- We now get an alternative definition of f7
f7' : typ (Ω (Susp∙ S²)) → K₂
f7' = f7stuff.encode north
-- We can define the Brunerie number by
brunerie' : ℤ
brunerie' = g10 (g9 (g8 λ i j → f7' λ k → η₃ .fst (push (loop i) (loop j) k)))
-- Computing it takes ~1s
brunerie'≡-2 : brunerie' ≡ -2
brunerie'≡-2 = refl
| {
"alphanum_fraction": 0.5338852522,
"avg_line_length": 27.7754010695,
"ext": "agda",
"hexsha": "18f32581411200f6cec8e488ce637b4a0ec2dda2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b6fbca9e83e553c5c2e4a16a2df7f9e9039034dc",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "xekoukou/cubical",
"max_forks_repo_path": "Cubical/Experiments/Brunerie.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b6fbca9e83e553c5c2e4a16a2df7f9e9039034dc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "xekoukou/cubical",
"max_issues_repo_path": "Cubical/Experiments/Brunerie.agda",
"max_line_length": 96,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b6fbca9e83e553c5c2e4a16a2df7f9e9039034dc",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "xekoukou/cubical",
"max_stars_repo_path": "Cubical/Experiments/Brunerie.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4940,
"size": 10388
} |
module StalinSort where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open import Data.Nat using (ℕ; _≤_; _≤?_)
open import Data.List using (List; _∷_; [])
open import Relation.Nullary using (Dec; yes; no)
-- Implementation of Stalin Sort
stalinSort : List ℕ → List ℕ
stalinSort [] = []
stalinSort (x ∷ []) = x ∷ []
stalinSort (x ∷ y ∷ zs) with x ≤? y
...| yes m≤n = x ∷ stalinSort (y ∷ zs)
...| no m≰n = stalinSort (x ∷ zs)
-- Example Test
_ : stalinSort (2 ∷ 3 ∷ 5 ∷ 4 ∷ 6 ∷ []) ≡ (2 ∷ 3 ∷ 5 ∷ 6 ∷ [])
_ = refl
-------------------- Correctness of Stalin Sort -------------------------
{-
This section is only interesting for Logic and Formal Verification
enthusiasts. Although I tried to sketch the formal proof that
Stalin Sort always returns a Sorted List, there is a point in the proof
that I couldn't solve yet. I declared it as a postulate, so somebody can
try improving it by giving an lemma that remove the postulate and
finish the proof =D
-}
-- A proof that x is less than all values in xs (thanks to Twan van Laarhoven)
data _≤*_ (x : ℕ) : List ℕ → Set where
[] : x ≤* []
_∷_ : ∀ {y ys} → (x ≤ y) → y ≤* ys → x ≤* (y ∷ ys)
-- Proof that a list is sorted (thanks to Twan van Laarhoven)
data SortedList : List ℕ → Set where
[] : SortedList []
_∷_ : ∀ {x xs} → x ≤* xs → SortedList xs → SortedList (x ∷ xs)
-- This is necessary to prove the correctness, I can't find a way yet ...
postulate
less-stalin : ∀ (x y : ℕ) (zs : List ℕ) → x ≤ y → x ≤* stalinSort (y ∷ zs)
-- Proof that Stalin Sort returns a sorted list
stalinSort-correctness : ∀ (xs : List ℕ) → SortedList (stalinSort xs)
stalinSort-correctness [] = []
stalinSort-correctness (x ∷ []) = [] ∷ []
stalinSort-correctness (x ∷ y ∷ zs) with x ≤? y
...| yes m≤n = less-stalin x y zs m≤n ∷ (stalinSort-correctness (y ∷ zs))
...| no m≰n = stalinSort-correctness (x ∷ zs)
| {
"alphanum_fraction": 0.5987933635,
"avg_line_length": 38.25,
"ext": "agda",
"hexsha": "f094536808f0584a228af71a650d5ee661372fcc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6098af3dbebdcbb8d23491a0be51775bddaee4a4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bluoxy/stalin-sort",
"max_forks_repo_path": "agda/StalinSort.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6098af3dbebdcbb8d23491a0be51775bddaee4a4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bluoxy/stalin-sort",
"max_issues_repo_path": "agda/StalinSort.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6098af3dbebdcbb8d23491a0be51775bddaee4a4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bluoxy/stalin-sort",
"max_stars_repo_path": "agda/StalinSort.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 672,
"size": 1989
} |
module Data.Bin.Utils where
open import Data.Digit
open import Data.Bin hiding (suc)
open import Data.Fin
open import Data.List
_%2 : Bin → Bin
0# %2 = 0#
([] 1#) %2 = [] 1#
((zero ∷ _) 1#) %2 = 0#
((suc zero ∷ _) 1#) %2 = [] 1#
((suc (suc ()) ∷ _) 1#) %2
bitToBin : Bit → Bin
bitToBin zero = 0#
bitToBin (suc zero) = [] 1#
bitToBin (suc (suc ()))
| {
"alphanum_fraction": 0.5329815303,
"avg_line_length": 19.9473684211,
"ext": "agda",
"hexsha": "1f2c4ff45ae8b3f2924e519da59673200dda6ae1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "Rotsor/BinDivMod",
"max_forks_repo_path": "Data/Bin/Utils.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "Rotsor/BinDivMod",
"max_issues_repo_path": "Data/Bin/Utils.agda",
"max_line_length": 35,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "Rotsor/BinDivMod",
"max_stars_repo_path": "Data/Bin/Utils.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-18T13:58:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-18T13:58:14.000Z",
"num_tokens": 167,
"size": 379
} |
module Properties where
open import Data.Bool
open import Data.Empty
open import Data.Maybe hiding (Any ; All)
open import Data.Nat
open import Data.List
open import Data.List.All
open import Data.List.Any
open import Data.Product
open import Data.Sum
open import Data.Unit
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Typing
open import Syntax
open import Global
open import Channel
open import Values
open import Session
open import Schedule
open import ProcessSyntax
open import ProcessRun
-- adequacy
open import Properties.Base
import Properties.StepBeta
import Properties.StepPair
import Properties.StepFork
import Properties.StepNew
import Properties.StepCloseWait
| {
"alphanum_fraction": 0.8360881543,
"avg_line_length": 19.1052631579,
"ext": "agda",
"hexsha": "6c86054487b9d069d1ee6ce146f4174610589fc8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "peterthiemann/definitional-session",
"max_forks_repo_path": "src/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "peterthiemann/definitional-session",
"max_issues_repo_path": "src/Properties.agda",
"max_line_length": 49,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "peterthiemann/definitional-session",
"max_stars_repo_path": "src/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-18T08:10:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-19T16:33:27.000Z",
"num_tokens": 152,
"size": 726
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
-- obtain free properties from duality
module Categories.Diagram.Pushout.Properties {o ℓ e} (C : Category o ℓ e) where
open Category C
open import Data.Product using (∃; _,_)
open import Categories.Category.Cocartesian C
open import Categories.Morphism C
open import Categories.Morphism.Properties C
open import Categories.Morphism.Duality C
open import Categories.Object.Initial C
open import Categories.Object.Terminal op
open import Categories.Object.Coproduct C
open import Categories.Object.Duality C
open import Categories.Diagram.Coequalizer C
open import Categories.Diagram.Pushout C
open import Categories.Diagram.Duality C
open import Categories.Diagram.Pullback op as P′ using (Pullback)
open import Categories.Diagram.Pullback.Properties op
private
variable
A B X Y : Obj
f g h i : A ⇒ B
module _ (p : Pushout f g) where
open Pushout p
private
pullback : Pullback f g
pullback = Pushout⇒coPullback p
open Pullback pullback
using (unique′; id-unique; unique-diagram)
public
swap : Pushout g f
swap = coPullback⇒Pushout (P′.swap pullback)
glue : Pushout h i₁ → Pushout (h ∘ f) g
glue p = coPullback⇒Pushout (P′.glue pullback (Pushout⇒coPullback p))
unglue : Pushout (h ∘ f) g → Pushout h i₁
unglue p = coPullback⇒Pushout (P′.unglue pullback (Pushout⇒coPullback p))
Pushout-resp-Epi : Epi g → Epi i₁
Pushout-resp-Epi epi = P′.Pullback-resp-Mono pullback epi
Pushout-resp-Iso : Iso g h → ∃ λ j → Iso i₁ j
Pushout-resp-Iso iso with P′.Pullback-resp-Iso pullback (Iso⇒op-Iso (Iso-swap iso))
... | j , record { isoˡ = isoˡ ; isoʳ = isoʳ } = j , record { isoˡ = isoʳ ; isoʳ = isoˡ }
Coproduct×Coequalizer⇒Pushout : (cp : Coproduct A B) →
Coequalizer (Coproduct.i₁ cp ∘ f) (Coproduct.i₂ cp ∘ g) →
Pushout f g
Coproduct×Coequalizer⇒Pushout cp coe =
coPullback⇒Pushout (P′.Product×Equalizer⇒Pullback (coproduct→product cp)
(Coequalizer⇒coEqualizer coe))
Coproduct×Pushout⇒Coequalizer : (cp : Coproduct A B) →
Pushout f g →
Coequalizer (Coproduct.i₁ cp ∘ f) (Coproduct.i₂ cp ∘ g)
Coproduct×Pushout⇒Coequalizer cp p =
coEqualizer⇒Coequalizer (P′.Product×Pullback⇒Equalizer (coproduct→product cp)
(Pushout⇒coPullback p))
module _ (i : Initial) where
open Initial i
private
t : Terminal
t = ⊥⇒op⊤ i
pushout-⊥⇒coproduct : Pushout (! {X}) (! {Y}) → Coproduct X Y
pushout-⊥⇒coproduct p = product→coproduct (pullback-⊤⇒product t (Pushout⇒coPullback p))
coproduct⇒pushout-⊥ : Coproduct X Y → Pushout (! {X}) (! {Y})
coproduct⇒pushout-⊥ c = coPullback⇒Pushout (product⇒pullback-⊤ t (coproduct→product c))
pushout-resp-≈ : Pushout f g → f ≈ h → g ≈ i → Pushout h i
pushout-resp-≈ p eq eq′ = coPullback⇒Pushout (pullback-resp-≈ (Pushout⇒coPullback p) eq eq′)
module _ (pushouts : ∀ {X Y Z} (f : X ⇒ Y) (g : X ⇒ Z) → Pushout f g)
(cocartesian : Cocartesian) where
open Cocartesian cocartesian
open Dual
pushout×cocartesian⇒coequalizer : Coequalizer f g
pushout×cocartesian⇒coequalizer = coEqualizer⇒Coequalizer
(pullback×cartesian⇒equalizer (λ f g → Pushout⇒coPullback (pushouts f g)) op-cartesian)
| {
"alphanum_fraction": 0.6641332944,
"avg_line_length": 36.0105263158,
"ext": "agda",
"hexsha": "f6ce54f7c34a4dd9a29abc58890943f6c3c9e541",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Diagram/Pushout/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Diagram/Pushout/Properties.agda",
"max_line_length": 92,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Diagram/Pushout/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1178,
"size": 3421
} |
module Categories.Monad.Algebras where
| {
"alphanum_fraction": 0.8717948718,
"avg_line_length": 19.5,
"ext": "agda",
"hexsha": "f9151d5e1fa1cdeadcbd2b8adb7ea3466bdd865c",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Monad/Algebras.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Monad/Algebras.agda",
"max_line_length": 38,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Monad/Algebras.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 8,
"size": 39
} |
module x02induction where
-- prove properties of inductive naturals and operations on them via induction
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_; _^_)
{-
------------------------------------------------------------------------------
## Properties of operators : identity, associativity, commutativity, distributivity
* _Identity_. left/right/both; sometimes called _unit_
* _Associativity_. e.g., `(m + n) + p ≡ m + (n + p)`
* _Commutativity_. e.g., `m + n ≡ n + m`
* _Distributivity_. e.g., from the left `(m + n) * p ≡ (m * p) + (n * p)`
from the right `m * (p + q) ≡ (m * p) + (m * q)`
#### Exercise `operators` (practice) {name=operators} TODO : ops with different properties - no proofs
pair of operators
- have an identity
- are associative, commutative, and distribute over one another
(do not prove)
operator
- has identity
- is associative
- not commutative
(do not prove)
-}
{-
HC not associative; right identity
-}
_ =
begin
(3 ∸ 1) ∸ 1 ∸ 0 ≡⟨⟩
2 ∸ 1 ∸ 0 ≡⟨⟩
1 ∸ 0 ≡⟨⟩
1 ∸ 0
∎
{-
------------------------------------------------------------------------------
## ASSOCIATIVITY of ADDITION : (m + n) + p ≡ m + (n + p)
-}
_ : (3 + 4) + 5 ≡ 3 + (4 + 5)
_ =
begin
(3 + 4) + 5 ≡⟨⟩
7 + 5 ≡⟨⟩
12 ≡⟨⟩
3 + 9 ≡⟨⟩
3 + (4 + 5)
∎
{-
useful to read chains like above
- from top down until reaching simplest term (i.e., `12`)
- from bottom up until reaching the same term
Why should `7 + 5` be the same as `3 + 9`?
Perhaps gather more evidence, testing the proposition by choosing other numbers.
But infinite naturals so testing can never be complete.
## PROOF BY INDUCTION
natural definition has
- base case
- inductive case
inductive proof follows structure of definition: prove two cases
- _base case_ : show property holds for `zero`
- _inductive case_ :
- assume property holds for an arbitrary natural `m` (the _inductive hypothesis_)
- then show that the property holds for `suc m`
------
P zero
P m
---------
P (suc m)
- initially, no properties are known.
- base case : `P zero` holds : add it to set of known properties
-- On the first day, one property is known.
P zero
- inductive case tells us that if `P m` holds
-- On the second day, two properties are known.
P zero
P (suc zero)
then `P (suc m)` also holds
-- On the third day, three properties are known.
P zero
P (suc zero)
P (suc (suc zero))
-- On the fourth day, four properties are known.
P zero
P (suc zero)
P (suc (suc zero))
P (suc (suc (suc zero)))
the process continues: property `P n` first appears on day _n+1_
------------------------------------------------------------------------------
## PROVE ASSOCIATIVITY of ADDITION
take `P m` to be the property:
(m + n) + p ≡ m + (n + p)
`n` and `p` are arbitrary natural numbers
show the equation holds for all `m` it will also hold for all `n` and `p`
-------------------------------
(zero + n) + p ≡ zero + (n + p)
(m + n) + p ≡ m + (n + p)
---------------------------------
(suc m + n) + p ≡ suc m + (n + p)
demonstrate both of above, then associativity of addition follows by induction
-}
-- signature says providing evidence for proposition
+-assoc : ∀ (m n p : ℕ)
→ (m + n) + p
≡ m + (n + p)
-- Evidence is a function that
-- - takes three natural numbers, binds them to `m`, `n`, and `p`
-- - returns evidence for the corresponding instance of the equation
-- base case : show: (zero + n) + p
-- ≡ zero + (n + p)
+-assoc zero n p =
begin
(zero + n) + p ≡⟨⟩ -- _+_ base case
n + p ≡⟨⟩
zero + (n + p)
∎
-- inductive case : show: (suc m + n) + p
-- ≡ suc m + (n + p)
+-assoc (suc m) n p =
begin
(suc m + n) + p ≡⟨⟩ -- _+_ inductive case (left to right)
suc (m + n) + p ≡⟨⟩
suc ((m + n) + p) ≡⟨ cong suc (+-assoc m n p) ⟩
-- simplifying both sides : suc ((m + n) + p) ≡ suc (m + (n + p))
-- follows by prefacing `suc` to both sides of the induction hypothesis:
-- (m + n) + p ≡ m + (n + p)
suc (m + (n + p)) ≡⟨⟩ -- _+_ inductive case (right to left)
suc m + (n + p)
∎
-- HC minimal version
+-assoc' : ∀ (m n p : ℕ)
→ (m + n) + p
≡ m + (n + p)
+-assoc' zero n p = refl
+-assoc' (suc m) n p = cong suc (+-assoc m n p)
{-
identifiers can have any characters NOT including spaces or the characters @.(){};_
the "middle" equation, does not follow from applying _+_ (i.e., "simplification") alone
- `_≡⟨_⟩_` : called "chain reasoning"
- justification for equation given in angle brackets:
- empty means "simplification", or
- something more, e.g.,:
⟨ cong suc (+-assoc m n p) ⟩
recursive invocation `+-assoc m n p`
- has type of the induction hypothesis
- `cong suc` prefaces `suc` to each side of inductive hypothesis
A relation is a CONGRUENCE for a given function
if the relation is preserved by applying the function.
if `e` is evidence that `x ≡ y`, then `cong f e` is evidence `f x ≡ f y`, for any `f`
here the inductive hypothesis is not assumed
instead, proved by recursive invocation of the function being defined, `+-assoc m n p`
WELL FOUNDED : associativity of larger numbers is proved in of associativity of smaller numbers.
e.g., `assoc (suc m) n p` is proved using `assoc m n p`.
------------------------------------------------------------------------------
## Induction as recursion
Concrete example of how induction corresponds to recursion : instantiate `m` to `2`
-}
+-assoc-2 : ∀ (n p : ℕ)
→ (2 + n) + p
≡ 2 + (n + p)
+-assoc-2 n p =
begin
(2 + n) + p ≡⟨⟩
suc (1 + n) + p ≡⟨⟩
suc ((1 + n) + p) ≡⟨ cong suc (+-assoc-1 n p) ⟩
suc (1 + (n + p)) ≡⟨⟩
2 + (n + p)
∎
where
+-assoc-1 : ∀ (n p : ℕ) → (1 + n) + p ≡ 1 + (n + p)
+-assoc-1 n p =
begin
(1 + n) + p ≡⟨⟩
suc (0 + n) + p ≡⟨⟩
suc ((0 + n) + p) ≡⟨ cong suc (+-assoc-0 n p) ⟩
suc (0 + (n + p)) ≡⟨⟩
1 + (n + p)
∎
where
+-assoc-0 : ∀ (n p : ℕ) → (0 + n) + p ≡ 0 + (n + p)
+-assoc-0 n p =
begin
(0 + n) + p ≡⟨⟩
n + p ≡⟨⟩
0 + (n + p)
∎
{-
------------------------------------------------------------------------------
## Terminology and notation
Evidence for a universal quantifier is a function. The notations
+-assoc : ∀ (m n p : ℕ)
→ (m + n) + p
≡ m + (n + p)
and
+-assoc : ∀ (m : ℕ)
→ ∀ (n : ℕ)
→ ∀ (p : ℕ)
→ (m + n) + p
≡ m + (n + p)
are equivalent.
differ from function type such as `ℕ → ℕ → ℕ`
- variables are associated with each argument type
- the result type may mention (or depend upon) these variables
- hence called _DEPENDENT functions_
------------------------------------------------------------------------------
## COMMUTATIVITY of ADDITION : m + n ≡ n + m
two lemmas used in proof
### first lemma
The base case of the definition of addition states that zero is a left-identity:
zero + n ≡ n
First lemma states that zero is also a right-identity:
-}
-- proof by induction on `m`
+-identityʳ : ∀ (m : ℕ)
→ m + zero
≡ m
-- base case : show:
-- zero + zero
-- ≡ zero
+-identityʳ zero =
begin
zero + zero ≡⟨⟩ -- _+_ base
zero
∎
-- inductive case : show:
-- (suc m) + zero
-- = suc m
+-identityʳ (suc m) =
begin
suc m + zero ≡⟨⟩ -- _+_ inductive
suc (m + zero) ≡⟨ cong suc (+-identityʳ m) ⟩
-- recursive invocation `+-identityʳ m`
-- has type of induction hypothesis
-- m + zero ≡ m
-- `cong suc` prefaces `suc` to each side of that type, yielding
-- suc (m + zero) ≡ suc m
suc m
∎
{-
### second lemma
inductive case of _+_ pushes `suc` on 1st arg to the outside:
suc m + n ≡ suc (m + n)
second lemma does same for `suc` on 2nd arg:
m + suc n ≡ suc (m + n)
-}
-- signature states defining `+-suc` which provides evidence for the proposition/type
+-suc : ∀ (m n : ℕ)
→ m + suc n
≡ suc (m + n)
-- evidence is fun that takes two nats, binds to `m` and `n`
-- returns evidence for the corresponding instance of the equation
-- proof is by induction on `m`
-- base case
+-suc zero n =
begin
zero + suc n ≡⟨⟩ -- _+_ base
suc n ≡⟨⟩ -- _+_ base
suc (zero + n)
∎
-- inductive case : show: suc m + suc n
-- ≡ suc (suc m + n)
+-suc (suc m) n =
begin
suc m + suc n ≡⟨⟩ -- _+_ inductive
suc (m + suc n) ≡⟨ cong suc (+-suc m n) ⟩ -- induction
suc (suc (m + n)) ≡⟨⟩ -- _+_ inductive
suc (suc m + n)
∎
-------------------------
+-comm : ∀ (m n : ℕ)
→ m + n
≡ n + m
+-comm m zero =
begin
m + zero ≡⟨ +-identityʳ m ⟩
m ≡⟨⟩
zero + m
∎
+-comm m (suc n) =
begin
m + suc n ≡⟨ +-suc m n ⟩
suc (m + n) ≡⟨ cong suc (+-comm m n) ⟩ -- congruence and induction hypothesis
suc (n + m) ≡⟨⟩ -- _+_ inductive
suc n + m
∎
{-
definition required BEFORE using them
------------------------------------------------------------------------------
## COROLLARY: REARRANGING : apply associativity to rearrange parentheses (SYM; sections)
-}
+-rearrange : ∀ (m n p q : ℕ)
→ (m + n) + (p + q)
≡ m + (n + p) + q
+-rearrange m n p q =
begin
(m + n) + (p + q) ≡⟨ +-assoc m n (p + q) ⟩
m + (n + (p + q)) ≡⟨ cong (m +_) (sym (+-assoc n p q)) ⟩
m + ((n + p) + q) ≡⟨ sym (+-assoc m (n + p) q) ⟩
(m + (n + p)) + q ≡⟨⟩
m + (n + p) + q
∎
{-
no induction is required
NOTE:
addition is left associative : m + (n + p) + q
= (m + (n + p)) + q
SYM : interchange sides of an equation, e.g.,
- `+-assoc n p q` shifts parens right to left:
(n + p) + q ≡ n + (p + q)
`sym (+-assoc n p q)`: to shift them left-to-right
n + (p + q) ≡ (n + p) + q
general
- if `e` provides evidence for `x ≡ y`
- then `sym e` provides evidence for `y ≡ x`
SECTION NOTATION (introduced by Richard Bird) : `(x +_)` `(_+ x)`
------------------------------------------------------------------------------
## Creation, one last time
base case : `(zero + n) + p ≡ zero + (n + p)`
inductive case :
- if `(m + n) + p ≡ m + (n + p)` then
`(suc m + n) + p ≡ suc m + (n + p)`
using base case, associativity of zero on left:
(0 + 0) + 0 ≡ 0 + (0 + 0) ... (0 + 4) + 5 ≡ 0 + (4 + 5) ...
using inductive case
(1 + 0) + 0 ≡ 1 + (0 + 0) ... (1 + 4) + 5 ≡ 1 + (4 + 5) ...
(2 + 0) + 0 ≡ 2 + (0 + 0) ... (2 + 4) + 5 ≡ 2 + (4 + 5) ...
(3 + 0) + 0 ≡ 3 + (0 + 0) ... (3 + 4) + 5 ≡ 3 + (4 + 5) ...
...
there is a finite approach to generating the same equations (following exercise)
------------------------------------------------------------------------------
#### Exercise `finite-|-assoc` (stretch) {name=finite-plus-assoc} TODO - first four days of creation - description, not proof
Write out what is known about associativity of addition on each of the
first four days using a finite story of creation, as
[earlier](/Naturals/#finite-creation).
------------------------------------------------------------------------------
## proof of ASSOCIATIVITY using `rewrite` (rather than chains of equations)
avoids chains of equations and the need to invoke `cong`
-}
+-assoc′ : ∀ (m n p : ℕ)
→ (m + n) + p
≡ m + (n + p)
-- base
-- show: (zero + n) + p ≡ zero + (n + p)
-- _+_ base applied "invisibly", then terms equal/refl
+-assoc′ zero n p = refl
-- inductive
-- show: (suc m + n) + p ≡ suc m + (n + p)
-- _+_ inductive applied "invisibly" giving: suc ((m + n) + p) ≡ suc (m + (n + p))
-- rewrite with the inductive hypothesis
-- then terms are equal/refl
+-assoc′ (suc m) n p rewrite +-assoc′ m n p = refl
{-
rewriting by a given equation
- indicated by keyword `rewrite`
- followed by a proof of that equation
------------------------------------------------------------------------------
## COMMUTATIVITY with rewrite
-}
+-suc′ : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n)
+-suc′ zero n = refl
+-suc′ (suc m) n rewrite +-suc′ m n = refl
+-comm′ : ∀ (m n : ℕ) → m + n ≡ n + m
+-comm′ m zero rewrite +-identityʳ m = refl
-- rewriting with two equations indicated by separating the two proofs
-- of the relevant equations by a vertical bar
-- left rewrite performed before right
+-comm′ m (suc n) -- m + suc n ≡ suc n + m
-- m + suc n ≡ suc (n + m) -- def/eq
rewrite
+-suc′ m n -- suc (m + n) ≡ suc (n + m)
| +-comm′ m n -- suc (n + m) ≡ suc (n + m)
= refl
+-comm′′ : ∀ (m n : ℕ) → m + n ≡ n + m
+-comm′′ m zero rewrite +-identityʳ m = refl
+-comm′′ m (suc n) =
begin
m + suc n ≡⟨ +-suc′ m n ⟩
suc (m + n) ≡⟨ cong suc (+-comm′′ m n) ⟩
suc (n + m) ≡⟨⟩ -- def/eq
suc n + m
∎
{-
------------------------------------------------------------------------------
HC
-}
*0 : ∀ (m : ℕ) → m * 0 ≡ 0
*0 zero = refl
*0 (suc m) = *0 m
0* : ∀ (m : ℕ) → 0 * m ≡ 0
0* m = refl
*1 : ∀ (n : ℕ) → n * 1 ≡ n
*1 zero = refl
*1 (suc n) rewrite *1 n = refl
1* : ∀ (n : ℕ) → 1 * n ≡ n
1* zero = refl
1* (suc n) rewrite 1* n = refl
{-
------------------------------------------------------------------------------
## Building proofs interactively
+-assoc′ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc′ m n p = ?
C-c C-l
+-assoc′ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc′ m n p = { }0
new window at the bottom:
?0 : ((m + n) + p) ≡ (m + (n + p))
indicates hole 0 needs to be filled with a proof of the stated judgment
to prove the proposition by induction on `m`
move cursor into hole
C-c C-c
prompt: pattern variables to case (empty for split on result):
type `m` to case split on that variable
+-assoc′ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc′ zero n p = { }0
+-assoc′ (suc m) n p = { }1
There are now two holes, and the window at the bottom tells you what
each is required to prove:
?0 : ((zero + n) + p) ≡ (zero + (n + p))
?1 : ((suc m + n) + p) ≡ (suc m + (n + p))
goto hole 0
C-c C-,
Goal: (n + p) ≡ (n + p)
————————————————————————————————————————————————————————————
p : ℕ
n : ℕ
indicates that after simplification the goal for hole 0 is as stated,
and that variables `p` and `n` of the stated types are available to use in the proof.
the proof of the given goal is simple
goto goal
C-c C-r
fills in with refl
C-c C-l renumbers remaining hole to 0:
+-assoc′ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc′ zero n p = refl
+-assoc′ (suc m) n p = { }0
goto hole 0
C-c C-,
Goal: suc ((m + n) + p) ≡ suc (m + (n + p))
————————————————————————————————————————————————————————————
p : ℕ
n : ℕ
m : ℕ
gives simplified goal and available variables
need to rewrite by the induction hypothesis
+-assoc′ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc′ zero n p = refl
+-assoc′ (suc m) n p rewrite +-assoc′ m n p = { }0
goto hole
C-c C-,
Goal: suc (m + (n + p)) ≡ suc (m + (n + p))
————————————————————————————————————————————————————————————
p : ℕ
n : ℕ
m : ℕ
goto goal
C-c C-r
fills in, completing proof
+-assoc′ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
+-assoc′ zero n p = refl
+-assoc′ (suc m) n p rewrite +-assoc′ m n p = refl
------------------------------------------------------------------------------
#### Exercise `+-swap` (recommended) {name=plus-swap}
Show
m + (n + p) ≡ n + (m + p)
for all naturals `m`, `n`, and `p`
- no induction
- use associativity and commutativity of addtion
-}
+-swap : ∀ (m n p : ℕ)
→ m + (n + p)
≡ n + (m + p)
+-swap m n p =
begin
m + (n + p) ≡⟨ sym (+-assoc m n p) ⟩
(m + n) + p ≡⟨ cong (_+ p) (sym (+-comm n m)) ⟩
(n + m) + p ≡⟨ +-assoc n m p ⟩
n + (m + p)
∎
{-
------------------------------------------------------------------------------
#### Exercise `*-distrib-+` (recommended) {name=times-distrib-plus} (m + n) * p ≡ m * p + n * p
-}
*-distrib-+r : ∀ (m n p : ℕ)
→ (m + n) * p
≡ m * p + n * p
*-distrib-+r zero y z = refl
*-distrib-+r (suc x) y z -- (suc x + y) * z ≡ suc x * z + y * z
-- z + (x + y) * z ≡ z + x * z + y * z
rewrite
*-distrib-+r x y z -- z + (x * z + y * z) ≡ z + x * z + y * z
| sym (+-assoc z (x * z) (y * z)) -- z + x * z + y * z ≡ z + x * z + y * z
= refl
{- TODO: agda loops on this : *-distrib-+r done with chain reasoning
*-distrib-+r' : ∀ (m n p : ℕ)
→ (m + n) * p
≡ m * p + n * p
*-distrib-+r' zero y z = refl
*-distrib-+r' (suc x) y z
begin
(suc x + y) * z ≡⟨⟩
z + (x + y) * z ≡⟨ *-distrib-+r' x y z ⟩
z + (x * z + y * z) ≡⟨ sym (+-assoc z (x * z) (y * z)) ⟩
z + x * z + y * z ≡⟨⟩
suc x * z + y * z
∎
-}
{-
------------------------------------------------------------------------------
#### Exercise `*-assoc` (recommended) {name=times-assoc} (m * n) * p ≡ m * (n * p)
-}
*-assoc : ∀ (m n p : ℕ)
→ (m * n) * p
≡ m * (n * p)
-- base case : show: (zero * n) * p
-- ≡ zero * (n * p)
*-assoc zero n p = refl -- zero * n * p ≡ zero * (n * p)
-- zero ≡ zero -- def/eq
-- inductive case : show: (suc m * n) * p
-- ≡ suc m * (n * p)
*-assoc (suc m) n p -- suc m * n * p ≡ suc m * (n * p)
-- (n + m * n) * p ≡ n * p + m * (n * p)
rewrite
*-distrib-+r n (m * n) p -- n * p + m * n * p ≡ n * p + m * (n * p)
| *-assoc m n p -- n * p + m * (n * p) ≡ n * p + m * (n * p)
= refl
{-
------------------------------------------------------------------------------
#### Exercise `*-comm` (practice) {name=times-comm} MULTIPLICATION is COMMUTATIVE : m * n ≡ n * m
-}
*-suc : ∀ (x y : ℕ) → x * (suc y) ≡ x + (x * y)
*-suc zero y = refl
*-suc (suc x) y -- suc x * suc y ≡ suc x + suc x * y
-- suc (y + x * suc y) ≡ suc (x + (y + x * y))
rewrite
+-comm y (x * suc y) -- suc (x * suc y + y) ≡ suc (x + (y + x * y))
| *-suc x y -- suc (x + x * y + y) ≡ suc (x + (y + x * y))
| +-comm y (x * y) -- suc (x + x * y + y) ≡ suc (x + (x * y + y))
| sym (+-assoc x (x * y) y) -- suc (x + x * y + y) ≡ suc (x + x * y + y)
= refl
*-comm : ∀ (m n : ℕ) → m * n ≡ n * m
*-comm m zero rewrite *0 m = refl
*-comm m (suc n) -- m * suc n ≡ suc n * m
-- m * suc n ≡ m + n * m
rewrite
*-suc m n -- m + m * n ≡ m + n * m
| *-comm m n -- m + n * m ≡ m + n * m
= refl
{-
------------------------------------------------------------------------------
#### Exercise `0∸n≡0` (practice) {name=zero-monus} : Show zero ∸ n ≡ zero
for all naturals `n`. Did your proof require induction?
-}
0∸n≡0 : ∀ (n : ℕ) → 0 ∸ n ≡ 0
0∸n≡0 zero = refl
0∸n≡0 (suc n) = refl
{-
------------------------------------------------------------------------------
#### Exercise `∸-|-assoc` (practice) {name=monus-plus-assoc} : m ∸ n ∸ p ≡ m ∸ (n + p)
show that monus associates with addition
-}
∸-|-assoc : ∀ (m n p : ℕ) → m ∸ n ∸ p ≡ m ∸ (n + p)
∸-|-assoc m n zero -- m ∸ n ∸ zero ≡ m ∸ (n + zero)
-- m ∸ n ≡ m ∸ (n + zero)
rewrite +-identityʳ n = refl -- m ∸ n ≡ m ∸ n
∸-|-assoc m zero (suc p) -- m ∸ zero ∸ suc p ≡ m ∸ (zero + suc p)
= refl -- m ∸ suc p ≡ m ∸ suc p
∸-|-assoc zero (suc n) (suc p) -- zero ∸ suc n ∸ suc p ≡ zero ∸ (suc n + suc p)
= refl -- zero ≡ zero
∸-|-assoc (suc m) (suc n) (suc p) -- suc m ∸ suc n ∸ suc p ≡ suc m ∸ (suc n + suc p)
-- m ∸ n ∸ suc p ≡ m ∸ (n + suc p)
rewrite
∸-|-assoc m n (suc p) -- m ∸ (n + suc p) ≡ m ∸ (n + suc p)
= refl
{-
------------------------------------------------------------------------------
#### Exercise `+*^` (stretch)
m ^ (n + p) ≡ (m ^ n) * (m ^ p) (^-distribˡ-|-*)
(m * n) ^ p ≡ (m ^ p) * (n ^ p) (^-distribʳ-*)
(m ^ n) ^ p ≡ m ^ (n * p) (^-*-assoc)
-}
-------------------------
-- this can be shortened
^-distribˡ-|-* : ∀ (m n p : ℕ)
→ m ^ (n + p)
≡ (m ^ n) * (m ^ p)
^-distribˡ-|-* m n zero -- (m ^ (n + zero)) ≡ (m ^ n) * (m ^ zero)
-- (m ^ (n + zero)) ≡ (m ^ n) * 1
rewrite
+-identityʳ n -- (m ^ n) ≡ (m ^ n) * 1
| *1 (m ^ n) -- (m ^ n) ≡ (m ^ n)
= refl
^-distribˡ-|-* m n (suc p) -- (m ^ (n + suc p)) ≡ (m ^ n) * (m ^ suc p)
-- (m ^ (n + suc p)) ≡ (m ^ n) * (m * (m ^ p))
rewrite
*-comm m (m ^ p) -- (m ^ (n + suc p)) ≡ (m ^ n) * ((m ^ p) * m)
| sym (*-assoc (m ^ n) (m ^ p) m) -- (m ^ (n + suc p)) ≡ (m ^ n) * (m ^ p) * m
| +-comm n (suc p) -- (m ^ suc (p + n)) ≡ (m ^ n) * (m ^ p) * m
-- m * (m ^ (p + n)) ≡ (m ^ n) * (m ^ p) * m
| *-comm ((m ^ n) * (m ^ p)) m -- m * (m ^ (p + n)) ≡ m * ((m ^ n) * (m ^ p))
| sym (*-assoc m (m ^ n) (m ^ p)) -- m * (m ^ (p + n)) ≡ m * (m ^ n) * (m ^ p)
| ^-distribˡ-|-* m p n -- m * ((m ^ p) * (m ^ n)) ≡ m * (m ^ n) * (m ^ p)
| sym (*-comm (m ^ n) (m ^ p)) -- m * ((m ^ n) * (m ^ p)) ≡ m * (m ^ n) * (m ^ p)
| *-assoc m (m ^ n) (m ^ p) -- m * ((m ^ n) * (m ^ p)) ≡ m * ((m ^ n) * (m ^ p))
= refl
-------------------------
^-distribʳ-* : ∀ (m n p : ℕ)
→ (m * n) ^ p
≡ (m ^ p) * (n ^ p)
^-distribʳ-* m n zero = refl
^-distribʳ-* m n (suc p) -- ((m * n) ^ suc p) ≡(m ^ suc p) * (n ^ suc p)
-- m * n * ((m * n) ^ p) ≡ m * (m ^ p) * (n * (n ^ p))
rewrite
^-distribʳ-* m n p -- m * n * ((m ^ p) * (n ^ p)) ≡ m * (m ^ p) * (n * (n ^ p))
| *-comm (m * (m ^ p)) (n * (n ^ p))
-- m * n * ((m ^ p) * (n ^ p)) ≡ n * (n ^ p) * (m * (m ^ p))
| *-assoc m n ((m ^ p) * (n ^ p)) -- m *(n * ((m ^ p) * (n ^ p)))≡ n * (n ^ p) * (m * (m ^ p))
| *-comm m (n * ((m ^ p) * (n ^ p)))
-- n *((m ^ p) * (n ^ p))* m ≡ n * (n ^ p) * (m * (m ^ p))
| *-comm (m ^ p) (n ^ p) -- n *((n ^ p) * (m ^ p))* m ≡ n * (n ^ p) * (m * (m ^ p))
| sym (*-assoc n (n ^ p) (m ^ p)) -- n * (n ^ p) * (m ^ p) * m ≡ n * (n ^ p) * (m * (m ^ p))
| *-assoc n (n ^ p) (m * (m ^ p)) -- n * (n ^ p) * (m ^ p) * m ≡ n *((n ^ p) * (m * (m ^ p)))
| *-comm m (m ^ p) -- n * (n ^ p) * (m ^ p) * m ≡ n *((n ^ p) * ((m ^ p) * m))
| *-assoc n (n ^ p) (m ^ p) -- n *((n ^ p) * (m ^ p))* m ≡ n *((n ^ p) * ((m ^ p) * m))
| *-assoc n ((n ^ p) * (m ^ p)) m -- n *((n ^ p) * (m ^ p) * m) ≡ n *((n ^ p) * ((m ^ p) * m))
| *-assoc (n ^ p) (m ^ p) m -- n *((n ^ p) *((m ^ p) * m))≡ n *((n ^ p) * ((m ^ p) * m))
= refl
-------------------------
^-*-assoc : ∀ (m n p : ℕ)
→ (m ^ n) ^ p
≡ m ^ (n * p)
^-*-assoc m n zero -- ((m ^ n) ^ zero) ≡ (m ^ (n * zero))
-- 1 ≡ (m ^ (n * zero))
rewrite *0 n -- 1 ≡ (m ^ 0)
-- 1 ≡ 1
= refl
^-*-assoc m n (suc p) -- ((m ^ n) ^ suc p) ≡ (m ^ (n * suc p))
-- (m ^ n) * ((m ^ n) ^ p) ≡ (m ^ (n * suc p))
rewrite
*-suc n p -- (m ^ n) * ((m ^ n) ^ p) ≡ (m ^ (n + n * p))
| ^-distribˡ-|-* m n (n * p) -- (m ^ n) * ((m ^ n) ^ p) ≡ (m ^ n) * (m ^ (n * p))
| sym (^-*-assoc m n p) -- (m ^ n) * ((m ^ n) ^ p) ≡ (m ^ n) * ((m ^ n) ^ p)
= refl
{-
------------------------------------------------------------------------------
#### Exercise `Bin-laws` (stretch) {name=Bin-laws}
Recall that
Exercise [Bin](/Naturals/#Bin)
defines a datatype `Bin` of bitstrings representing natural numbers,
and asks you to define functions
-}
-- begin duplicated from x01 (can't import because of "duplicate" pragma)
data Bin : Set where
⟨⟩ : Bin
_O : Bin → Bin
_I : Bin → Bin
inc : Bin → Bin
inc ⟨⟩ = ⟨⟩ I
inc (b O) = b I
inc (b I) = (inc b) O
_ : inc (⟨⟩ I O I I) ≡ ⟨⟩ I I O O
_ = refl
-- end duplicated
dbl : ℕ → ℕ
dbl zero = zero
dbl (suc m) = suc (suc (dbl m))
to : ℕ → Bin
to zero = ⟨⟩ O
to (suc m) = inc (to m)
-- THIS IS THE CRITICAL STEP : defining in terms of 'dbl'
-- Got hint from : https://cs.uwaterloo.ca/~plragde/842/
from : Bin → ℕ
from ⟨⟩ = 0
from (b O) = dbl (from b)
from (b I) = suc (dbl (from b))
_ : to 6 ≡ ⟨⟩ I I O
_ = refl
_ : from (⟨⟩ I I O) ≡ 6
_ = refl
{-
Consider the following laws, where `n` ranges over naturals and `b`
over bitstrings:
from (inc b) ≡ suc (from b)
to (from b) ≡ b
from (to n) ≡ n
For each law: if it holds, prove; if not, give a counterexample.
-}
-------------------------
-- fromInc≡sucFrom
+1 : ∀ (x : ℕ) → x + 1 ≡ suc x
+1 zero = refl
+1 (suc n) rewrite +1 n = refl
fromInc≡sucFrom : ∀ (b : Bin)
→ from (inc b) ≡ suc (from b)
fromInc≡sucFrom ⟨⟩ -- from (inc ⟨⟩) ≡ suc (from ⟨⟩)
-- 1 ≡ 1
= refl
fromInc≡sucFrom (⟨⟩ I) -- from (inc (⟨⟩ I)) ≡ suc (from (⟨⟩ I))
-- 2 ≡ 2
= refl
fromInc≡sucFrom (b O) -- from (inc (b O)) ≡ suc (from (b O))
-- dbl (from b) + 1 ≡ suc (dbl (from b))
rewrite
+1 (dbl (from b)) -- suc (dbl (from b)) ≡ suc (dbl (from b))
= refl
fromInc≡sucFrom (b I) -- from (inc (b I)) ≡ suc (from (b I))
-- dbl (from (inc b)) ≡ suc (dbl (from b) + 1)
rewrite
+1 (dbl (from b)) -- dbl (from (inc b)) ≡ suc (suc (dbl (from b)))
| fromInc≡sucFrom b -- dbl (suc (from b)) ≡ suc (suc (dbl (from b)))
-- suc (suc (dbl (from b))) ≡ suc (suc (dbl (from b)))
= refl
-------------------------
-- to-from≡b -- cannot be proved because there are TWO representations of ZERO
-- NOT USED
xx : ∀ (b : Bin)
→ (dbl (from b)) ≡ from (b O)
xx ⟨⟩ -- dbl (from ⟨⟩) ≡ from (⟨⟩ O)
-- zero ≡ zero
= refl
xx (b O) -- dbl (from (b O)) ≡ from ((b O) O)
-- dbl (dbl (from b)) ≡ dbl (dbl (from b))
= refl
xx (b I) -- dbl (from (b I)) ≡ from ((b I) O)
-- suc (suc (dbl (dbl (from b)))) ≡ suc (suc (dbl (dbl (from b))))
= refl
-- CANNOT BE PROVED BECAUSE TWO REPRESENTATIONS OF ZERO : (⟨⟩) and (⟨⟩ O)
yy : ∀ (b : Bin)
→ to (dbl (from b)) ≡ (b O)
yy ⟨⟩ -- to (dbl (from ⟨⟩)) ≡ (⟨⟩ O)
-- (⟨⟩ O) ≡ (⟨⟩ O)
= refl
yy (b O) -- to (dbl (from (b O))) ≡ ((b O) O)
-- to (dbl (dbl (from b))) ≡ ((b O) O)
rewrite
yy b
= {!!}
yy (b I) -- to (dbl (from (b I))) ≡ ((b I) O)
-- inc (inc (to (dbl (dbl (from b))))) ≡ ((b I) O)
= {!!}
to-from : ∀ (b : Bin)
→ to (from b) ≡ b
to-from ⟨⟩ -- to (from ⟨⟩) ≡ ⟨⟩
-- (⟨⟩ O) ≡ ⟨⟩ -- *****
= {!!}
to-from (⟨⟩ I) -- to (from (⟨⟩ I)) ≡ (⟨⟩ I)
-- (⟨⟩ I) ≡ (⟨⟩ I)
= refl
to-from (b O) -- to (from (b O)) ≡ (b O)
-- to (dbl (from b)) ≡ (b O)
rewrite
yy b -- (b O) ≡ (b O)
= refl
to-from (b I) -- to (from (b I)) ≡ (b I)
-- inc (to (dbl (from b))) ≡ (b I)
rewrite
yy b -- (b I) ≡ (b I)
= refl
-------------------------
-- https://github.com/billyang98/plfa/blob/master/plfa/Induction.agda
from-inc≡suc-from : ∀ x → from (inc x) ≡ suc (from x)
from-inc≡suc-from ⟨⟩ = refl
from-inc≡suc-from (x O) = refl
from-inc≡suc-from (x I) -- from (inc (x I)) ≡ suc (from (x I))
-- dbl (from (inc x)) ≡ suc (suc (dbl (from x)))
rewrite
from-inc≡suc-from x -- suc (suc (dbl (from x))) ≡ suc (suc (dbl (from x)))
= refl
from-to : ∀ n → from (to n) ≡ n
from-to zero = refl
from-to (suc n) -- from (to (suc n)) ≡ suc n
-- from (inc (to n)) ≡ suc n
rewrite
from-inc≡suc-from (to n) -- suc (from (to n)) ≡ suc n
| cong suc (from-to n) -- suc n ≡ suc n
= refl
{-
------------------------------------------------------------------------------
## Standard library
Definitions similar to those in this chapter can be found in the standard library:
```
import Data.Nat.Properties using (+-assoc; +-identityʳ; +-suc; +-comm)
```
------------------------------------------------------------------------------
## Unicode
This chapter uses the following unicode:
∀ U+2200 FOR ALL (\forall, \all)
ʳ U+02B3 MODIFIER LETTER SMALL R (\^r)
′ U+2032 PRIME (\')
″ U+2033 DOUBLE PRIME (\')
‴ U+2034 TRIPLE PRIME (\')
⁗ U+2057 QUADRUPLE PRIME (\')
Similar to `\r`, the command `\^r` gives access to a variety of
superscript rightward arrows, and also a superscript letter `r`.
The command `\'` gives access to a range of primes (`′ ″ ‴ ⁗`).
-}
-- ============================================================================
-- this is here to ensure the Bin/in/from/to does not get broken if changed above
_ : inc (⟨⟩ I O I I) ≡ ⟨⟩ I I O O
_ = refl
_ : inc (⟨⟩ O) ≡ ⟨⟩ I
_ = refl
_ : inc (⟨⟩ I) ≡ ⟨⟩ I O
_ = refl
_ : inc (⟨⟩ I O) ≡ ⟨⟩ I I
_ = refl
_ : inc (⟨⟩ I I) ≡ ⟨⟩ I O O
_ = refl
_ : inc (⟨⟩ I O O) ≡ ⟨⟩ I O I
_ = refl
_ : from (⟨⟩ O) ≡ 0
_ = refl
_ : from (⟨⟩ I) ≡ 1
_ = refl
_ : from (⟨⟩ I O) ≡ 2
_ = refl
_ : from (⟨⟩ I I) ≡ 3
_ = refl
_ : from (⟨⟩ I O O) ≡ 4
_ = refl
_ : to 0 ≡ (⟨⟩ O)
_ = refl
_ : to 1 ≡ (⟨⟩ I)
_ = refl
_ : to 2 ≡ (⟨⟩ I O)
_ = refl
_ : to 3 ≡ (⟨⟩ I I)
_ = refl
_ : to 4 ≡ (⟨⟩ I O O)
_ = refl
_ : from (to 12) ≡ 12
_ = refl
_ : to (from (⟨⟩ I I O O)) ≡ ⟨⟩ I I O O
_ = refl
| {
"alphanum_fraction": 0.4053140402,
"avg_line_length": 30.6408518877,
"ext": "agda",
"hexsha": "41e8c42d615dfce97b5718c02f9d84dd18c20261",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x02induction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x02induction.agda",
"max_line_length": 125,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x02induction.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 11345,
"size": 31652
} |
-- Helper operations to construct and build signatures
module SOAS.Syntax.Build (T : Set) where
open import SOAS.Common
open import SOAS.Families.Build {T}
open import SOAS.Context {T}
open import Data.List.Base
open import SOAS.Syntax.Signature T
-- Syntactic sugar to construct arity - sort mappings
⟼₀_ : T → List (Ctx × T) × T
⟼₀_ τ = [] , τ
_⟼₁_ : (Ctx × T) → T → List (Ctx × T) × T
a ⟼₁ τ = [ a ] , τ
_,_⟼₂_ : (a₁ a₂ : Ctx × T) → T → List (Ctx × T) × T
a₁ , a₂ ⟼₂ τ = (a₁ ∷ [ a₂ ]) , τ
_,_,_⟼₃_ : (a₁ a₂ a₃ : Ctx × T) → T → List (Ctx × T) × T
a₁ , a₂ , a₃ ⟼₃ τ = (a₁ ∷ a₂ ∷ [ a₃ ]) , τ
_,_,_,_⟼₄_ : (a₁ a₂ a₃ a₄ : Ctx × T) → T → List (Ctx × T) × T
a₁ , a₂ , a₃ , a₄ ⟼₄ τ = (a₁ ∷ a₂ ∷ a₃ ∷ [ a₄ ]) , τ
_⟼ₙ_ : List (Ctx × T) → T → List (Ctx × T) × T
_⟼ₙ_ = _,_
-- Syntactic sugar to costruct arguments
⊢₀_ : T → Ctx × T
⊢₀ α = ∅ , α
_⊢₁_ : T → T → Ctx × T
τ ⊢₁ α = ⌊ τ ⌋ , α
_,_⊢₂_ : (τ₁ τ₂ : T) → T → Ctx × T
τ₁ , τ₂ ⊢₂ α = ⌊ τ₁ ∙ τ₂ ⌋ , α
_,_,_⊢₃_ : (τ₁ τ₂ τ₃ : T) → T → Ctx × T
τ₁ , τ₂ , τ₃ ⊢₃ α = ⌊ τ₁ ∙ τ₂ ∙ τ₃ ⌋ , α
_⊢ₙ_ : Ctx → T → Ctx × T
Π ⊢ₙ τ = Π , τ
infix 2 ⟼₀_
infix 2 _⟼₁_
infix 2 _,_⟼₂_
infix 2 _,_,_⟼₃_
infix 2 _⟼ₙ_
infix 10 ⊢₀_
infix 10 _⊢₁_
infix 10 _,_⊢₂_
infix 10 _⊢ₙ_
-- Sum of two signatures
_+ˢ_ : {O₁ O₂ : Set} → Signature O₁ → Signature O₂ → Signature (+₂ O₁ O₂)
S1 +ˢ S2 = sig (₂| ∣ S1 ∣ ∣ S2 ∣)
where open Signature
-- Sums of signatures
Σ₂ : {O₁ O₂ : Set} → Signature O₁ → Signature O₂ → Signature (+₂ O₁ O₂)
Σ₂ S₁ S₂ = sig (₂| (∣ S₁ ∣) (∣ S₂ ∣))
where open Signature
Σ₃ : {O₁ O₂ O₃ : Set} → Signature O₁ → Signature O₂ → Signature O₃ → Signature (+₃ O₁ O₂ O₃)
Σ₃ S₁ S₂ S₃ = sig (₃| (∣ S₁ ∣) (∣ S₂ ∣) (∣ S₃ ∣))
where open Signature
Σ₄ : {O₁ O₂ O₃ O₄ : Set} → Signature O₁ → Signature O₂ → Signature O₃ → Signature O₄ → Signature (+₄ O₁ O₂ O₃ O₄)
Σ₄ S₁ S₂ S₃ S₄ = sig (₄| (∣ S₁ ∣) (∣ S₂ ∣) (∣ S₃ ∣) (∣ S₄ ∣))
where open Signature
| {
"alphanum_fraction": 0.5494447382,
"avg_line_length": 24.5584415584,
"ext": "agda",
"hexsha": "c71e5b83fb422c69336ef8cf697fde74f7a1f7c9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "SOAS/Syntax/Build.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "SOAS/Syntax/Build.agda",
"max_line_length": 113,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "SOAS/Syntax/Build.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 994,
"size": 1891
} |
module ANF where
open import Data.Nat
open import Data.Vec
open import Data.Fin
open import Data.String
open import Data.Rational
open import Data.Sum
open import Data.Unit
open import Binders.Var
record DataConApp (universe a : Set) : Set where
constructor _#_◂_
-- theres probably room for a better notation :)))
field
-- universe : Set
arity : ℕ
schema : Vec universe arity
app : Vec a arity
mutual
data term (a : Set ) : Set where
v : a -> term a -- variables return only appears in "tail" position
app : ∀ (n : ℕ ) -> Callish a n -> term a
letCall : ∀ (n : ℕ ) -> Callish a n -> term (Var (Fin n) a) -> term a
letAlloc : Allocish a 1 -> term (Var (Fin 1) a) -> term a
-- for now we only model direct allocations have having a single return value ...
data Allocish (a : Set) : ℕ -> Set where
lam : ∀ (n : ℕ ) -> term (Var (Fin n) (term a)) -> Allocish a 1
delay : term a -> Allocish a 1
dataConstr : DataConApp ⊤ {- for now using unit as the universe -} a -> Allocish a 1
data Callish (a : Set) : ℕ -> Set where
force : a -> Callish a 0
call : ∀ {n } -> a -> Vec a n -> Callish a n
primCall : ∀ {n } -> String -> Vec a n -> Callish a n
| {
"alphanum_fraction": 0.5534266765,
"avg_line_length": 30.8409090909,
"ext": "agda",
"hexsha": "14dfe55275700ad807abe740aae17215a608d828",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "e0de23b3c78313a7f6856c3d48c3d6a2ce3962dd",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "hopper-lang/hopper-v0",
"max_forks_repo_path": "models/agda/ANF.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "e0de23b3c78313a7f6856c3d48c3d6a2ce3962dd",
"max_issues_repo_issues_event_max_datetime": "2020-02-19T01:08:47.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-02-19T01:08:47.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "hopper-lang/hopper-v0",
"max_issues_repo_path": "models/agda/ANF.agda",
"max_line_length": 91,
"max_stars_count": 17,
"max_stars_repo_head_hexsha": "e0de23b3c78313a7f6856c3d48c3d6a2ce3962dd",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "hopper-lang/hopper-v0",
"max_stars_repo_path": "models/agda/ANF.agda",
"max_stars_repo_stars_event_max_datetime": "2019-03-18T03:02:06.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-09-23T16:03:03.000Z",
"num_tokens": 403,
"size": 1357
} |
{-# OPTIONS --postfix-projections #-}
module StateSized.cellStateDependent where
open import Data.Product
open import Data.String.Base
{-
open import SizedIO.Object
open import SizedIO.ConsoleObject
-}
open import SizedIO.Console hiding (main)
open import SizedIO.Base
open import NativeIO
open import StateSizedIO.Object
open import StateSizedIO.IOObject
open import Size
open import StateSizedIO.cellStateDependent
{- I moved most into src/StateSizedIO/cellStateDependent.agda
now the code doesn't work
-}
-- Program is another program
program : IOConsole ∞ Unit
program =
let c₀ = cellPempty ∞ in
exec getLine λ str →
method c₀ (put str) >>= λ{ (_ , c₁) → -- empty
method c₁ get >>= λ{ (str₁ , c₂) → -- full
exec (putStrLn ("we got " ++ str₁)) λ _ →
exec (putStrLn ("Second Round")) λ _ →
exec getLine λ str₂ →
method c₂ (put str₂) >>= λ{ (_ , c₃) →
method c₃ get >>= λ{ (str₃ , c₄) →
exec (putStrLn ("we got " ++ str₃) ) λ _ →
return unit
}}}}
main : NativeIO Unit
main = translateIOConsole program
-- cellP is constructor for the consoleObject for interface (cellI String)
{-
cellPˢ : ∀{i} → CellCˢ i
force (method cellPˢ (put x)) = {!!}
-}
{-
cellP : ∀{i} (s : String) → CellC i
force (method (cellP s) get) =
exec' (putStrLn ("getting (" ++ s ++ ")")) λ _ →
return (s , cellP s)
force (method (cellP s) (put x)) =
exec' (putStrLn ("putting (" ++ x ++ ")")) λ _ →
return (_ , (cellP x))
-}
{-
-- cellI is the interface of the object of a simple cell
cellI : (A : Set) → Interfaceˢ
Method (cellI A) = CellMethodˢ A
Result (cellI A) m = CellResultˢ m
-- cellC is the type of consoleObjects with interface (cellI String)
CellC : (i : Size) → Set
CellC i = ConsoleObject i (cellI String)
-}
{-
-- cellO is a program for a simple cell which
-- when get is called writes "getting s" for the string s of the object
-- and when putting s writes "putting s" for the string
-- cellP is constructor for the consoleObject for interface (cellI String)
cellP : ∀{i} (s : String) → CellC i
force (method (cellP s) get) =
exec' (putStrLn ("getting (" ++ s ++ ")")) λ _ →
return (s , cellP s)
force (method (cellP s) (put x)) =
exec' (putStrLn ("putting (" ++ x ++ ")")) λ _ →
return (_ , (cellP x))
-- Program is another program
program : String → IOConsole ∞ Unit
program arg =
let c₀ = cellP "Start" in
method c₀ get >>= λ{ (s , c₁) →
exec1 (putStrLn s) >>
method c₁ (put arg) >>= λ{ (_ , c₂) →
method c₂ get >>= λ{ (s' , c₃) →
exec1 (putStrLn s') }}}
main : NativeIO Unit
main = translateIOConsole (program "hello")
-}
| {
"alphanum_fraction": 0.6242559524,
"avg_line_length": 25.1214953271,
"ext": "agda",
"hexsha": "a0eb8b07edb7c64f95a0fac655a867857d79a1d9",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "examples/StateSized/cellStateDependent.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/ooAgda",
"max_issues_repo_path": "examples/StateSized/cellStateDependent.agda",
"max_line_length": 74,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "examples/StateSized/cellStateDependent.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 868,
"size": 2688
} |
module Logic.Propositional.Xor where
open import Logic.Propositional
open import Logic
import Lvl
-- TODO: Is it possible write a general construction for arbitrary number of xors? Probably by using rotate₃Fn₃Op₂?
data _⊕₃_⊕₃_ {ℓ₁ ℓ₂ ℓ₃} (P : Stmt{ℓ₁}) (Q : Stmt{ℓ₂}) (R : Stmt{ℓ₃}) : Stmt{ℓ₁ Lvl.⊔ ℓ₂ Lvl.⊔ ℓ₃} where
[⊕₃]-intro₁ : P → (¬ Q) → (¬ R) → (P ⊕₃ Q ⊕₃ R)
[⊕₃]-intro₂ : (¬ P) → Q → (¬ R) → (P ⊕₃ Q ⊕₃ R)
[⊕₃]-intro₃ : (¬ P) → (¬ Q) → R → (P ⊕₃ Q ⊕₃ R)
| {
"alphanum_fraction": 0.5728952772,
"avg_line_length": 40.5833333333,
"ext": "agda",
"hexsha": "1307a9e10566c953807a335516ad9adb4e259668",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Logic/Propositional/Xor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Logic/Propositional/Xor.agda",
"max_line_length": 115,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Logic/Propositional/Xor.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 248,
"size": 487
} |
module _ where
open import Agda.Builtin.Bool
postulate Eq : Set → Set
it : {A : Set} → ⦃ A ⦄ → A
it ⦃ x ⦄ = x
module M1 (A : Set) ⦃ eqA : Eq A ⦄ where
postulate B : Set
variable n : B
postulate P : B → Set
module M2 (A : Set) ⦃ eqA : Eq A ⦄ where
open M1 A
postulate
p₁ : P n
p₂ : P ⦃ it ⦄ n
p₃ : P ⦃ eqA ⦄ n
p₄ : M1.P A n
| {
"alphanum_fraction": 0.5308988764,
"avg_line_length": 15.4782608696,
"ext": "agda",
"hexsha": "ae84e44ba086acc2560e9a05015bd42e1cfdcd45",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Succeed/Issue5093.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Succeed/Issue5093.agda",
"max_line_length": 40,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Succeed/Issue5093.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 173,
"size": 356
} |
record R : Set₁ where
field
A : Set
module _ (r : R) where
open R r
data D : Set where
c : A → D
data P : D → Set where
d : (x : A) → P (c x)
postulate
f : D → A
g : (x : D) → P x → D
g x (d y) with Set
g x (d y) | _ = x
| {
"alphanum_fraction": 0.4461538462,
"avg_line_length": 11.8181818182,
"ext": "agda",
"hexsha": "03ae2bf644e537c8157405977077995eac6567b9",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue2297.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue2297.agda",
"max_line_length": 25,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2297.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 114,
"size": 260
} |
postulate
A : Set
f : A → A → A → A → A → A → A → A → A → A → A
test : A
test = {!f!}
| {
"alphanum_fraction": 0.3846153846,
"avg_line_length": 13,
"ext": "agda",
"hexsha": "a53f26b0954697f241006f669f20579d21e0f4e7",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/interaction/Issue3532.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue3532.agda",
"max_line_length": 47,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue3532.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 43,
"size": 91
} |
{-# OPTIONS --without-K --safe #-}
open import Level
open import Categories.Category using (Category; _[_,_])
-- Various conclusions that can be drawn from Yoneda
-- over a particular Category C
module Categories.Yoneda.Properties {o ℓ e : Level} (C : Category o ℓ e) where
open import Function using (_$_; Inverse) -- else there's a conflict with the import below
open import Function.Equality using (Π; _⟨$⟩_; cong)
open import Relation.Binary using (module Setoid)
import Relation.Binary.Reasoning.Setoid as SetoidR
open import Data.Product using (_,_; Σ)
open import Categories.Category.Product
open import Categories.Category.Construction.Presheaves
open import Categories.Category.Construction.Functors
open import Categories.Category.Instance.Setoids
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Hom using (module Hom; Hom[_][-,_]; Hom[_][-,-])
open import Categories.Functor.Bifunctor
open import Categories.Functor.Presheaf
open import Categories.Functor.Construction.LiftSetoids
open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper) renaming (id to idN)
open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism)
open import Categories.Yoneda
import Categories.Morphism as Mor
import Categories.Morphism.Reasoning as MR
import Categories.NaturalTransformation.Hom as NT-Hom
open Category C
open HomReasoning
open NaturalTransformation
open Yoneda C
private
module CE = Category.Equiv C
module C = Category C
YoFull : Full embed
YoFull {X} {Y} = record
{ from = record { _⟨$⟩_ = λ ε → η ε X ⟨$⟩ id ; cong = λ i≈j → i≈j CE.refl }
; right-inverse-of = λ ε {x} {z} {y} z≈y →
begin
(η ε X ⟨$⟩ id) ∘ z ≈˘⟨ identityˡ ⟩
id ∘ (η ε X ⟨$⟩ id) ∘ z ≈˘⟨ commute ε z CE.refl ⟩
η ε x ⟨$⟩ id ∘ id ∘ z ≈⟨ cong (η ε x) (identityˡ ○ identityˡ ○ z≈y) ⟩
η ε x ⟨$⟩ y ∎
}
YoFaithful : Faithful embed
YoFaithful _ _ pres-≈ = ⟺ identityʳ ○ pres-≈ {_} {id} CE.refl ○ identityʳ
YoFullyFaithful : FullyFaithful embed
YoFullyFaithful = YoFull , YoFaithful
open Mor C
yoneda-iso : ∀ {A B : Obj} → NaturalIsomorphism Hom[ C ][-, A ] Hom[ C ][-, B ] → A ≅ B
yoneda-iso {A} {B} niso = record
{ from = ⇒.η A ⟨$⟩ id
; to = ⇐.η B ⟨$⟩ id
; iso = record
{ isoˡ = begin
(⇐.η B ⟨$⟩ id) ∘ (⇒.η A ⟨$⟩ id) ≈˘⟨ identityˡ ⟩
id ∘ (⇐.η B ⟨$⟩ id) ∘ (⇒.η A ⟨$⟩ id) ≈⟨ B⇒A.inverseʳ F⇐G refl ⟩
⇐.η A ⟨$⟩ (⇒.η A ⟨$⟩ id) ≈⟨ isoX.isoˡ refl ⟩
id ∎
; isoʳ = begin
(⇒.η A ⟨$⟩ id) ∘ (⇐.η B ⟨$⟩ id) ≈˘⟨ identityˡ ⟩
id ∘ (⇒.η A ⟨$⟩ id) ∘ (⇐.η B ⟨$⟩ id) ≈⟨ A⇒B.inverseʳ F⇒G refl ⟩
⇒.η B ⟨$⟩ (⇐.η B ⟨$⟩ id) ≈⟨ isoX.isoʳ refl ⟩
id ∎
}
}
where open NaturalIsomorphism niso
A⇒B = yoneda-inverse A (Functor.F₀ embed B)
B⇒A = yoneda-inverse B (Functor.F₀ embed A)
module A⇒B = Inverse A⇒B
module B⇒A = Inverse B⇒A
module isoX {X} = Mor.Iso (iso X)
module _ {o′ ℓ′ e′} {D : Category o′ ℓ′ e′} where
private
module D = Category D
module _ {F G : Functor D C} where
private
module F = Functor F
module G = Functor G
Hom[-,F-] : Bifunctor C.op D (Setoids ℓ e)
Hom[-,F-] = Hom[ C ][-,-] ∘F (idF ⁂ F)
Hom[-,G-] : Bifunctor C.op D (Setoids ℓ e)
Hom[-,G-] = Hom[ C ][-,-] ∘F (idF ⁂ G)
nat-appʳ : ∀ X → NaturalTransformation Hom[-,F-] Hom[-,G-] →
NaturalTransformation Hom[ C ][-, F.F₀ X ] Hom[ C ][-, G.F₀ X ]
nat-appʳ X α = ntHelper record
{ η = λ Y → η α (Y , X)
; commute = λ {_ Y} f eq → cong (η α (Y , X)) (∘-resp-≈ˡ (⟺ F.identity)) ○ commute α (f , D.id) eq ○ ∘-resp-≈ˡ G.identity
}
transform : NaturalTransformation Hom[-,F-] Hom[-,G-] → NaturalTransformation F G
transform α = ntHelper record
{ η = λ X → η α (F.F₀ X , X) ⟨$⟩ id
; commute = λ {X Y} f → begin
(η α (F.F₀ Y , Y) ⟨$⟩ id) ∘ F.F₁ f ≈˘⟨ identityˡ ⟩
id ∘ (η α (F.F₀ Y , Y) ⟨$⟩ id) ∘ F.F₁ f ≈˘⟨ lower (yoneda.⇒.commute {Y = Hom[ C ][-, G.F₀ Y ] , _} (idN , F.F₁ f) {nat-appʳ Y α} {nat-appʳ Y α} (cong (η α _))) ⟩
η α (F.F₀ X , Y) ⟨$⟩ F.F₁ f ∘ id ≈⟨ cong (η α (F.F₀ X , Y)) (∘-resp-≈ʳ (⟺ identityˡ)) ⟩
η α (F.F₀ X , Y) ⟨$⟩ F.F₁ f ∘ id ∘ id ≈⟨ commute α (id , f) refl ⟩
G.F₁ f ∘ (η α (F.F₀ X , X) ⟨$⟩ id) ∘ id ≈⟨ refl⟩∘⟨ identityʳ ⟩
G.F₁ f ∘ (η α (F.F₀ X , X) ⟨$⟩ id) ∎
}
module _ (F G : Functor D C) where
private
module F = Functor F
module G = Functor G
Hom[-,F-] : Bifunctor C.op D (Setoids ℓ e)
Hom[-,F-] = Hom[ C ][-,-] ∘F (idF ⁂ F)
Hom[-,G-] : Bifunctor C.op D (Setoids ℓ e)
Hom[-,G-] = Hom[ C ][-,-] ∘F (idF ⁂ G)
yoneda-NI : NaturalIsomorphism Hom[-,F-] Hom[-,G-] → NaturalIsomorphism F G
yoneda-NI ni = record
{ F⇒G = transform F⇒G
; F⇐G = transform F⇐G
; iso = λ X → record
{ isoˡ = begin
(⇐.η (G.F₀ X , X) ⟨$⟩ id) ∘ (⇒.η (F.F₀ X , X) ⟨$⟩ id) ≈˘⟨ identityˡ ⟩
id ∘ (⇐.η (G.F₀ X , X) ⟨$⟩ id) ∘ (⇒.η (F.F₀ X , X) ⟨$⟩ id) ≈˘⟨ lower (yoneda.⇒.commute {Y = Hom[ C ][-, F.F₀ X ] , _} (idN , (⇒.η (F.F₀ X , X) ⟨$⟩ C.id))
{nat-appʳ X F⇐G} {nat-appʳ X F⇐G} (cong (⇐.η _))) ⟩
⇐.η (F.F₀ X , X) ⟨$⟩ (⇒.η (F.F₀ X , X) ⟨$⟩ id) ∘ id ≈⟨ cong (⇐.η _) identityʳ ⟩
⇐.η (F.F₀ X , X) ⟨$⟩ (⇒.η (F.F₀ X , X) ⟨$⟩ id) ≈⟨ iso.isoˡ _ refl ⟩
id ∎
; isoʳ = begin
(⇒.η (F.F₀ X , X) ⟨$⟩ id) ∘ (⇐.η (G.F₀ X , X) ⟨$⟩ id) ≈˘⟨ identityˡ ⟩
id ∘ (⇒.η (F.F₀ X , X) ⟨$⟩ id) ∘ (⇐.η (G.F₀ X , X) ⟨$⟩ id) ≈˘⟨ lower (yoneda.⇒.commute {Y = Hom[ C ][-, G.F₀ X ] , _} (idN , (⇐.η (G.F₀ X , X) ⟨$⟩ C.id))
{nat-appʳ X F⇒G} {nat-appʳ X F⇒G} (cong (⇒.η _))) ⟩
⇒.η (G.F₀ X , X) ⟨$⟩ (⇐.η (G.F₀ X , X) ⟨$⟩ id) ∘ id ≈⟨ cong (⇒.η _) identityʳ ⟩
⇒.η (G.F₀ X , X) ⟨$⟩ (⇐.η (G.F₀ X , X) ⟨$⟩ id) ≈⟨ iso.isoʳ _ refl ⟩
id ∎
}
}
where open NaturalIsomorphism ni
| {
"alphanum_fraction": 0.4943286327,
"avg_line_length": 43.7852348993,
"ext": "agda",
"hexsha": "e1ee0345682f688ddee2c4e76e68b0b53631171d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Yoneda/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Yoneda/Properties.agda",
"max_line_length": 171,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Yoneda/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2623,
"size": 6524
} |
------------------------------------------------------------------------
-- A virtual machine
------------------------------------------------------------------------
open import Prelude
import Lambda.Virtual-machine.Instructions
module Lambda.Virtual-machine
{Name : Type}
(open Lambda.Virtual-machine.Instructions Name)
(def : Name → Code 1)
where
open import Equality.Propositional
open import Colist equality-with-J as Colist using (Colist)
open import List equality-with-J using (_++_; length)
open import Monad equality-with-J
open import Vec.Data equality-with-J
open import Lambda.Delay-crash using (Delay-crash)
open import Lambda.Delay-crash-trace
open import Lambda.Syntax Name
open Closure Code
-- A single step of the computation.
step : State → Result
step ⟨ var x ∷ c , s , ρ ⟩ = continue ⟨ c , val (index ρ x) ∷ s , ρ ⟩
step ⟨ clo c′ ∷ c , s , ρ ⟩ = continue ⟨ c , val (lam c′ ρ) ∷ s , ρ ⟩
step ⟨ app ∷ c , val v ∷ val (lam c′ ρ′) ∷ s , ρ ⟩ = continue ⟨ c′ , ret c ρ ∷ s , v ∷ ρ′ ⟩
step ⟨ ret ∷ c , val v ∷ ret c′ ρ′ ∷ s , ρ ⟩ = continue ⟨ c′ , val v ∷ s , ρ′ ⟩
step ⟨ cal f ∷ c , val v ∷ s , ρ ⟩ = continue ⟨ def f , ret c ρ ∷ s , v ∷ [] ⟩
step ⟨ tcl f ∷ c , val v ∷ s , ρ ⟩ = continue ⟨ def f , s , v ∷ [] ⟩
step ⟨ con b ∷ c , s , ρ ⟩ = continue ⟨ c , val (con b) ∷ s , ρ ⟩
step ⟨ bra c₁ c₂ ∷ c , val (con true) ∷ s , ρ ⟩ = continue ⟨ c₁ ++ c , s , ρ ⟩
step ⟨ bra c₁ c₂ ∷ c , val (con false) ∷ s , ρ ⟩ = continue ⟨ c₂ ++ c , s , ρ ⟩
step ⟨ [] , val v ∷ [] , [] ⟩ = done v
step _ = crash
-- A functional semantics for the VM. The result includes a trace of
-- all the encountered states.
mutual
exec⁺ : ∀ {i} → State → Delay-crash-trace State Value i
exec⁺ s = later s λ { .force → exec⁺′ (step s) }
exec⁺′ : ∀ {i} → Result → Delay-crash-trace State Value i
exec⁺′ (continue s) = exec⁺ s
exec⁺′ (done v) = now v
exec⁺′ crash = crash
-- The semantics without the trace of states.
exec : ∀ {i} → State → Delay-crash Value i
exec = delay-crash ∘ exec⁺
-- The stack sizes of all the encountered states.
stack-sizes : ∀ {i} → State → Colist ℕ i
stack-sizes =
Colist.map (λ { ⟨ _ , s , _ ⟩ → length s }) ∘ trace ∘ exec⁺
| {
"alphanum_fraction": 0.4718581342,
"avg_line_length": 39.303030303,
"ext": "agda",
"hexsha": "68fd48d7161c3a23d5967959c486599590a31a2f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/definitional-interpreters",
"max_forks_repo_path": "src/Lambda/Virtual-machine.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/definitional-interpreters",
"max_issues_repo_path": "src/Lambda/Virtual-machine.agda",
"max_line_length": 112,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/definitional-interpreters",
"max_stars_repo_path": "src/Lambda/Virtual-machine.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 804,
"size": 2594
} |
module Rewrite where
open import Common.Equality
data _≈_ {A : Set}(x : A) : A → Set where
refl : ∀ {y} → x ≈ y
lem : ∀ {A} (x y : A) → x ≈ y
lem x y = refl
thm : {A : Set}(P : A → Set)(x y : A) → P x → P y
thm P x y px rewrite lem x y = {!!}
| {
"alphanum_fraction": 0.508,
"avg_line_length": 17.8571428571,
"ext": "agda",
"hexsha": "f89c800a21dd8f26713f20ca6dc971f507a751f2",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Rewrite.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Rewrite.agda",
"max_line_length": 49,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Rewrite.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 107,
"size": 250
} |
module Issue3818.M where
| {
"alphanum_fraction": 0.84,
"avg_line_length": 12.5,
"ext": "agda",
"hexsha": "15a5a726ec4702bbe3011e22bcb65a8dc8d7e812",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue3818/M.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue3818/M.agda",
"max_line_length": 24,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue3818/M.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 7,
"size": 25
} |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.Polynomials.Multivariate.EquivCarac.An[Am[X]]-Anm[X] where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Nat renaming (_+_ to _+n_; _·_ to _·n_)
open import Cubical.Data.Vec
open import Cubical.Data.Vec.OperationsNat
open import Cubical.Data.Sigma
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Polynomials.Univariate.Base
open import Cubical.Algebra.Polynomials.Multivariate.Base
open import Cubical.Algebra.Polynomials.Multivariate.Properties
open import Cubical.Algebra.CommRing.Instances.MultivariatePoly
private variable
ℓ ℓ' : Level
module Comp-Poly-nm (A' : CommRing ℓ) (n m : ℕ) where
private
A = fst A'
open CommRingStr (snd A')
module Mr = Nth-Poly-structure A' m
module N+Mr = Nth-Poly-structure A' (n +n m)
module N∘Mr = Nth-Poly-structure (PolyCommRing A' m) n
-----------------------------------------------------------------------------
-- direct sens
N∘M→N+M-b : (v : Vec ℕ n) → Poly A' m → Poly A' (n +n m)
N∘M→N+M-b v = Poly-Rec-Set.f A' m (Poly A' (n +n m)) trunc
0P
(λ v' a → base (v ++ v') a)
_poly+_
poly+Assoc
poly+IdR
poly+Comm
(λ v' → base-0P (v ++ v'))
(λ v' a b → base-poly+ (v ++ v') a b)
N∘M→N+M : Poly (PolyCommRing A' m) n → Poly A' (n +n m)
N∘M→N+M = Poly-Rec-Set.f (PolyCommRing A' m) n (Poly A' (n +n m)) trunc
0P
N∘M→N+M-b
_poly+_
poly+Assoc
poly+IdR
poly+Comm
(λ _ → refl)
(λ v a b → refl)
-- -----------------------------------------------------------------------------
-- -- Converse sens
N+M→N∘M : Poly A' (n +n m) → Poly (PolyCommRing A' m) n
N+M→N∘M = Poly-Rec-Set.f A' (n +n m) (Poly (PolyCommRing A' m) n) trunc
0P
(λ v a → let v , v' = sep-vec n m v in
base v (base v' a))
_poly+_
poly+Assoc
poly+IdR
poly+Comm
(λ v → (cong (base (fst (sep-vec n m v))) (base-0P (snd (sep-vec n m v)))) ∙ (base-0P (fst (sep-vec n m v))))
λ v a b → base-poly+ (fst (sep-vec n m v)) (base (snd (sep-vec n m v)) a) (base (snd (sep-vec n m v)) b)
∙ cong (base (fst (sep-vec n m v))) (base-poly+ (snd (sep-vec n m v)) a b)
-----------------------------------------------------------------------------
-- Section
e-sect : (P : Poly A' (n +n m)) → N∘M→N+M (N+M→N∘M P) ≡ P
e-sect = Poly-Ind-Prop.f A' (n +n m)
(λ P → N∘M→N+M (N+M→N∘M P) ≡ P)
(λ _ → trunc _ _)
refl
(λ v a → cong (λ X → base X a) (sep-vec-id n m v))
(λ {U V} ind-U ind-V → cong₂ _poly+_ ind-U ind-V)
-----------------------------------------------------------------------------
-- Retraction
e-retr : (P : Poly (PolyCommRing A' m) n) → N+M→N∘M (N∘M→N+M P) ≡ P
e-retr = Poly-Ind-Prop.f (PolyCommRing A' m) n
(λ P → N+M→N∘M (N∘M→N+M P) ≡ P)
(λ _ → trunc _ _)
refl
(λ v → Poly-Ind-Prop.f A' m
(λ P → N+M→N∘M (N∘M→N+M (base v P)) ≡ base v P)
(λ _ → trunc _ _)
(sym (base-0P v))
(λ v' a → cong₂ base (sep-vec-fst n m v v') (cong (λ X → base X a) (sep-vec-snd n m v v')))
(λ {U V} ind-U ind-V → (cong₂ _poly+_ ind-U ind-V) ∙ (base-poly+ v U V)))
(λ {U V} ind-U ind-V → cong₂ _poly+_ ind-U ind-V )
-----------------------------------------------------------------------------
-- Morphism of ring
map-0P : N∘M→N+M (0P) ≡ 0P
map-0P = refl
N∘M→N+M-gmorph : (P Q : Poly (PolyCommRing A' m) n) → N∘M→N+M ( P poly+ Q) ≡ N∘M→N+M P poly+ N∘M→N+M Q
N∘M→N+M-gmorph = λ P Q → refl
map-1P : N∘M→N+M (N∘Mr.1P) ≡ N+Mr.1P
map-1P = cong (λ X → base X 1r) (rep-concat n m 0 )
N∘M→N+M-rmorph : (P Q : Poly (PolyCommRing A' m) n) → N∘M→N+M ( P N∘Mr.poly* Q) ≡ N∘M→N+M P N+Mr.poly* N∘M→N+M Q
N∘M→N+M-rmorph =
-- Ind P
Poly-Ind-Prop.f (PolyCommRing A' m) n
(λ P → (Q : Poly (PolyCommRing A' m) n) → N∘M→N+M (P N∘Mr.poly* Q) ≡ (N∘M→N+M P N+Mr.poly* N∘M→N+M Q))
(λ P p q i Q j → trunc _ _ (p Q) (q Q) i j)
(λ Q → refl)
(λ v → -- Ind Base P
Poly-Ind-Prop.f A' m
(λ P → (Q : Poly (PolyCommRing A' m) n) → N∘M→N+M (base v P N∘Mr.poly* Q) ≡ (N∘M→N+M (base v P) N+Mr.poly* N∘M→N+M Q))
(λ P p q i Q j → trunc _ _ (p Q) (q Q) i j)
(λ Q → cong (λ X → N∘M→N+M (X N∘Mr.poly* Q)) (base-0P v))
(λ v' a → -- Ind Q
Poly-Ind-Prop.f (PolyCommRing A' m) n
(λ Q → N∘M→N+M (base v (base v' a) N∘Mr.poly* Q) ≡ (N∘M→N+M (base v (base v' a)) N+Mr.poly* N∘M→N+M Q))
(λ _ → trunc _ _)
(sym (N+Mr.poly*AnnihilR (N∘M→N+M (base v (base v' a)))))
(λ w → -- Ind base Q
Poly-Ind-Prop.f A' m
_
(λ _ → trunc _ _)
(sym (N+Mr.poly*AnnihilR (N∘M→N+M (base v (base v' a)))))
(λ w' b → cong (λ X → base X (a · b)) (+n-vec-concat n m v w v' w'))
λ {U V} ind-U ind-V → cong (λ X → N∘M→N+M (base v (base v' a) N∘Mr.poly* X)) (sym (base-poly+ w U V))
∙ cong₂ (_poly+_ ) ind-U ind-V
∙ sym (cong (λ X → N∘M→N+M (base v (base v' a)) N+Mr.poly* N∘M→N+M X) (base-poly+ w U V)) )
-- End Ind base Q
λ {U V} ind-U ind-V → cong₂ _poly+_ ind-U ind-V)
-- End Ind Q
λ {U V} ind-U ind-V Q → cong (λ X → N∘M→N+M (X N∘Mr.poly* Q)) (sym (base-poly+ v U V))
∙ cong₂ _poly+_ (ind-U Q) (ind-V Q)
∙ sym (cong (λ X → (N∘M→N+M X) N+Mr.poly* (N∘M→N+M Q)) (sym (base-poly+ v U V)) ))
-- End Ind base P
λ {U V} ind-U ind-V Q → cong₂ _poly+_ (ind-U Q) (ind-V Q)
-- End Ind P
-----------------------------------------------------------------------------
-- Ring Equivalence
module _ (A' : CommRing ℓ) (n m : ℕ) where
open Comp-Poly-nm A' n m
CRE-PolyN∘M-PolyN+M : CommRingEquiv (PolyCommRing (PolyCommRing A' m) n) (PolyCommRing A' (n +n m))
fst CRE-PolyN∘M-PolyN+M = isoToEquiv is
where
is : Iso _ _
Iso.fun is = N∘M→N+M
Iso.inv is = N+M→N∘M
Iso.rightInv is = e-sect
Iso.leftInv is = e-retr
snd CRE-PolyN∘M-PolyN+M = makeIsRingHom map-1P N∘M→N+M-gmorph N∘M→N+M-rmorph
| {
"alphanum_fraction": 0.4439279489,
"avg_line_length": 40.023255814,
"ext": "agda",
"hexsha": "21a990f92ab6e4eb0d67cb629545c26d8e0b7baf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guilhermehas/cubical",
"max_forks_repo_path": "Cubical/Algebra/Polynomials/Multivariate/EquivCarac/An[Am[X]]-Anm[X].agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "guilhermehas/cubical",
"max_issues_repo_path": "Cubical/Algebra/Polynomials/Multivariate/EquivCarac/An[Am[X]]-Anm[X].agda",
"max_line_length": 144,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guilhermehas/cubical",
"max_stars_repo_path": "Cubical/Algebra/Polynomials/Multivariate/EquivCarac/An[Am[X]]-Anm[X].agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 2526,
"size": 6884
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some defined operations (multiplication by natural number and
-- exponentiation)
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Algebra
module Algebra.Operations.Semiring {s₁ s₂} (S : Semiring s₁ s₂) where
import Algebra.Operations.CommutativeMonoid as MonoidOperations
open import Data.Nat.Base
using (zero; suc; ℕ) renaming (_+_ to _ℕ+_; _*_ to _ℕ*_)
open import Data.Product using (module Σ)
open import Function using (_$_)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open Semiring S renaming (zero to *-zero)
open import Relation.Binary.Reasoning.Setoid setoid
------------------------------------------------------------------------
-- Operations
-- Re-export all monoid operations and proofs
open MonoidOperations +-commutativeMonoid public
-- Exponentiation.
infixr 9 _^_
_^_ : Carrier → ℕ → Carrier
x ^ zero = 1#
x ^ suc n = x * x ^ n
------------------------------------------------------------------------
-- Properties of _×_
-- _× 1# is homomorphic with respect to _ℕ*_/_*_.
×1-homo-* : ∀ m n → (m ℕ* n) × 1# ≈ (m × 1#) * (n × 1#)
×1-homo-* 0 n = begin
0# ≈⟨ sym (Σ.proj₁ *-zero (n × 1#)) ⟩
0# * (n × 1#) ∎
×1-homo-* (suc m) n = begin
(n ℕ+ m ℕ* n) × 1# ≈⟨ ×-homo-+ 1# n (m ℕ* n) ⟩
n × 1# + (m ℕ* n) × 1# ≈⟨ +-cong refl (×1-homo-* m n) ⟩
n × 1# + (m × 1#) * (n × 1#) ≈⟨ sym (+-cong (*-identityˡ _) refl) ⟩
1# * (n × 1#) + (m × 1#) * (n × 1#) ≈⟨ sym (distribʳ (n × 1#) 1# (m × 1#)) ⟩
(1# + m × 1#) * (n × 1#) ∎
------------------------------------------------------------------------
-- Properties of _×′_
-- _×′ 1# is homomorphic with respect to _ℕ*_/_*_.
×′1-homo-* : ∀ m n → (m ℕ* n) ×′ 1# ≈ (m ×′ 1#) * (n ×′ 1#)
×′1-homo-* m n = begin
(m ℕ* n) ×′ 1# ≈⟨ sym $ ×≈×′ (m ℕ* n) 1# ⟩
(m ℕ* n) × 1# ≈⟨ ×1-homo-* m n ⟩
(m × 1#) * (n × 1#) ≈⟨ *-cong (×≈×′ m 1#) (×≈×′ n 1#) ⟩
(m ×′ 1#) * (n ×′ 1#) ∎
------------------------------------------------------------------------
-- Properties of _^_
-- _^_ preserves equality.
^-congˡ : ∀ n → (_^ n) Preserves _≈_ ⟶ _≈_
^-congˡ zero x≈y = refl
^-congˡ (suc n) x≈y = *-cong x≈y (^-congˡ n x≈y)
^-cong : _^_ Preserves₂ _≈_ ⟶ _≡_ ⟶ _≈_
^-cong {v = n} x≈y P.refl = ^-congˡ n x≈y
| {
"alphanum_fraction": 0.4401606426,
"avg_line_length": 32.7631578947,
"ext": "agda",
"hexsha": "bb7c67a604818ed5adff185713b11b515e9e5e7e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Operations/Semiring.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Operations/Semiring.agda",
"max_line_length": 79,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Algebra/Operations/Semiring.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 937,
"size": 2490
} |
{-# OPTIONS --cubical --safe --postfix-projections #-}
open import Prelude
open import Relation.Binary
module Data.AVLTree.Internal {k} {K : Type k} {r₁ r₂} (totalOrder : TotalOrder K r₁ r₂) where
open import Relation.Binary.Construct.Bounded totalOrder
open import Data.Nat using (_+_)
open TotalOrder totalOrder using (_<?_; compare)
open TotalOrder b-ord using (<-trans) renaming (refl to <-refl)
import Data.Empty.UniversePolymorphic as Poly
private
variable
n m l : ℕ
data Bal : ℕ → ℕ → ℕ → Type where
ll : Bal (suc n) n (suc n)
ee : Bal n n n
rr : Bal n (suc n) (suc n)
balr : Bal n m l → Bal l n l
balr ll = ee
balr ee = ee
balr rr = ll
ball : Bal n m l → Bal m l l
ball ll = rr
ball ee = ee
ball rr = ee
private
variable
v : Level
Val : K → Type v
data Tree {v} (Val : K → Type v) (lb ub : [∙]) : ℕ → Type (k ℓ⊔ r₁ ℓ⊔ v) where
leaf : (lb<ub : lb [<] ub) →
Tree Val lb ub zero
node : (key : K)
(val : Val key)
(bal : Bal n m l)
(lchild : Tree Val lb [ key ] n)
(rchild : Tree Val [ key ] ub m) →
Tree Val lb ub (suc l)
private
variable
lb ub : [∙]
data Inc {t} (T : ℕ → Type t) (n : ℕ) : Type t where
stay : T n → Inc T n
high : T (suc n) → Inc T n
private
variable
t : Level
N : ℕ → Type t
rotʳ : (x : K) →
(xv : Val x) →
(ls : Tree Val lb [ x ] (2 + n)) →
(rs : Tree Val [ x ] ub n) →
Inc (Tree Val lb ub) (2 + n)
rotʳ y yv (node x xv ll xl xr) zs = stay (node x xv ee xl (node y yv ee xr zs))
rotʳ y yv (node x xv ee xl xr) zs = high (node x xv rr xl (node y yv ll xr zs))
rotʳ z zv (node x xv rr xl (node y yv bl yl yr)) zr = stay (node y yv ee (node x xv (balr bl) xl yl) (node z zv (ball bl) yr zr))
rotˡ : (x : K) → (xv : Val x) →
(ls : Tree Val lb [ x ] n) →
(rs : Tree Val [ x ] ub (2 + n)) →
Inc (Tree Val lb ub) (2 + n)
rotˡ x xv xl (node y yv ee yl yr) = high (node y yv ll (node x xv rr xl yl) yr)
rotˡ x xv xl (node y yv rr yl yr) = stay (node y yv ee (node x xv ee xl yl) yr)
rotˡ x xv xl (node z zv ll (node y yv bl yl yr) zr) = stay (node y yv ee (node x xv (balr bl) xl yl) (node z zv (ball bl) yr zr))
insertWith : (x : K) → Val x →
((new : Val x) → (old : Val x) → Val x) →
(lb [<] [ x ]) →
([ x ] [<] ub) →
(tr : Tree Val lb ub n) →
Inc (Tree Val lb ub) n
insertWith x xv xf lb<x x<ub (leaf lb<ub) =
high (node x xv ee (leaf lb<x) (leaf x<ub))
insertWith x xv xf lb<x x<ub (node y yv bal ls rs) with compare x y
... | lt x<y with insertWith x xv xf lb<x x<y ls
... | stay ls′ = stay (node y yv bal ls′ rs)
... | high ls′ with bal
... | ll = rotʳ y yv ls′ rs
... | ee = high (node y yv ll ls′ rs)
... | rr = stay (node y yv ee ls′ rs)
insertWith x xv xf lb<x x<ub (node y yv bal ls rs)
| gt y<x with insertWith x xv xf y<x x<ub rs
... | stay rs′ = stay (node y yv bal ls rs′)
... | high rs′ with bal
... | ll = stay (node y yv ee ls rs′)
... | ee = high (node y yv rr ls rs′)
... | rr = rotˡ y yv ls rs′
insertWith x xv xf lb<x x<ub (node y yv bal ls rs)
| eq x≡y = stay (node y (subst _ x≡y (xf xv (subst _ (sym x≡y) yv))) bal ls rs)
lookup : (x : K) → Tree Val lb ub n → Maybe (Val x)
lookup x (leaf lb<ub) = nothing
lookup x (node y val bal lhs rhs) with compare y x
... | lt x<y = lookup x lhs
... | eq x≡y = just (subst _ x≡y val)
... | gt x>y = lookup x rhs
record Cons (Val : K → Type v) (lb ub : [∙]) (h : ℕ) : Type (k ℓ⊔ v ℓ⊔ r₁) where
constructor cons
field
head : K
val : Val head
bounds : lb [<] [ head ]
tail : Inc (Tree Val [ head ] ub) h
open Cons public
map-tail : ∀ {ub₁ ub₂} →
Cons Val lb ub₁ n →
(∀ {lb} → Inc (Tree Val lb ub₁) n → Inc (Tree Val lb ub₂) m) →
Cons Val lb ub₂ m
map-tail (cons h v b t) f = cons h v b (f t)
uncons : (x : K) →
Val x →
Bal n m l →
Tree Val lb [ x ] n →
Tree Val [ x ] ub m →
Cons Val lb ub l
uncons x xv bl (leaf lb<ub) rhs .head = x
uncons x xv bl (leaf lb<ub) rhs .val = xv
uncons x xv bl (leaf lb<ub) rhs .bounds = lb<ub
uncons x xv ee (leaf lb<ub) rhs .tail = stay rhs
uncons x xv rr (leaf lb<ub) rhs .tail = stay rhs
uncons x xv bl (node y yv yb ls yrs) rs =
map-tail (uncons y yv yb ls yrs)
λ { (high ys) → high (node x xv bl ys rs)
; (stay ys) → case bl of
λ { ll → stay (node x xv ee ys rs)
; ee → high (node x xv rr ys rs)
; rr → rotˡ x xv ys rs
}
}
ext : ∀ {ub′} → ub [<] ub′ → Tree Val lb ub n → Tree Val lb ub′ n
ext {lb = lb} ub<ub′ (leaf lb<ub) = leaf (<-trans {x = lb} lb<ub ub<ub′)
ext ub<ub′ (node x xv bal lhs rhs) = node x xv bal lhs (ext ub<ub′ rhs)
join : ∀ {x} →
Tree Val lb [ x ] m →
Bal m n l →
Tree Val [ x ] ub n →
Inc (Tree Val lb ub) l
join lhs ll (leaf lb<ub) = stay (ext lb<ub lhs)
join {lb = lb} (leaf lb<ub₁) ee (leaf lb<ub) = stay (leaf (<-trans {x = lb} lb<ub₁ lb<ub))
join lhs bl (node x xv xb xl xr) with uncons x xv xb xl xr
... | cons k′ v′ l<u (high tr′) = high (node k′ v′ bl (ext l<u lhs) tr′)
... | cons k′ v′ l<u (stay tr′) with bl
... | ll = rotʳ k′ v′ (ext l<u lhs) tr′
... | ee = high (node k′ v′ ll (ext l<u lhs) tr′)
... | rr = stay (node k′ v′ ee (ext l<u lhs) tr′)
data Decr {t} (T : ℕ → Type t) : ℕ → Type t where
same : T n → Decr T n
decr : T n → Decr T (suc n)
inc→dec : Inc N n → Decr N (suc n)
inc→dec (stay x) = decr x
inc→dec (high x) = same x
delete : (x : K)
→ Tree Val lb ub n
→ Decr (Tree Val lb ub) n
delete x (leaf l<u) = same (leaf l<u)
delete x (node y yv b l r) with compare x y
delete x (node y yv b l r) | eq _ = inc→dec (join l b r)
delete x (node y yv b l r) | lt a with delete x l
... | same l′ = same (node y yv b l′ r)
... | decr l′ with b
... | ll = decr (node y yv ee l′ r)
... | ee = same (node y yv rr l′ r)
... | rr = inc→dec (rotˡ y yv l′ r)
delete x (node y yv b l r) | gt c with delete x r
... | same r′ = same (node y yv b l r′)
... | decr r′ with b
... | ll = inc→dec (rotʳ y yv l r′)
... | ee = same (node y yv ll l r′)
... | rr = decr (node y yv ee l r′)
data Change {t} (T : ℕ → Type t) : ℕ → Type t where
up : T (suc n) → Change T n
ev : T n → Change T n
dn : T n → Change T (suc n)
inc→changeup : Inc N n → Change N (suc n)
inc→changeup (stay x) = dn x
inc→changeup (high x) = ev x
inc→changedn : Inc N n → Change N n
inc→changedn (stay x) = ev x
inc→changedn (high x) = up x
_<_<_ : [∙] → K → [∙] → Type _
l < x < u = l [<] [ x ] × [ x ] [<] u
alter : (x : K)
→ (Maybe (Val x) → Maybe (Val x))
→ Tree Val lb ub n
→ lb < x < ub
→ Change (Tree Val lb ub) n
alter x f (leaf l<u) (l , u) with f nothing
... | just xv = up (node x xv ee (leaf l) (leaf u))
... | nothing = ev (leaf l<u)
alter x f (node y yv b tl tr) (l , u) with compare x y
alter x f (node y yv b tl tr) (l , u)
| eq x≡y with f (just (subst _ (sym x≡y) yv))
... | just xv = ev (node y (subst _ x≡y xv) b tl tr)
... | nothing = inc→changeup (join tl b tr)
alter x f (node y yv b tl tr) (l , u)
| lt a with alter x f tl (l , a) | b
... | ev tl′ | _ = ev (node y yv b tl′ tr)
... | up tl′ | ll = inc→changedn (rotʳ y yv tl′ tr)
... | up tl′ | ee = up (node y yv ll tl′ tr)
... | up tl′ | rr = ev (node y yv ee tl′ tr)
... | dn tl′ | ll = dn (node y yv ee tl′ tr)
... | dn tl′ | ee = ev (node y yv rr tl′ tr)
... | dn tl′ | rr = inc→changeup (rotˡ y yv tl′ tr)
alter x f (node y yv b tl tr) (l , u)
| gt c with alter x f tr (c , u) | b
... | ev tr′ | _ = ev (node y yv b tl tr′)
... | up tr′ | ll = ev (node y yv ee tl tr′)
... | up tr′ | ee = up (node y yv rr tl tr′)
... | up tr′ | rr = inc→changedn (rotˡ y yv tl tr′)
... | dn tr′ | ll = inc→changeup (rotʳ y yv tl tr′)
... | dn tr′ | ee = ev (node y yv ll tl tr′)
... | dn tr′ | rr = dn (node y yv ee tl tr′)
open import Lens
alterF : (x : K) →
Tree Val lb ub n →
lb < x < ub →
LensPart (Change (Tree Val lb ub) n) (Maybe (Val x))
alterF x xs bnds = go (ev xs) x xs bnds id
where
go : A → (x : K) →
Tree Val lb ub n →
lb < x < ub →
(Change (Tree Val lb ub) n → A) →
LensPart A (Maybe (Val x))
go xs x (leaf lb<ub) (l , u) k = λ where
.get → nothing
.set nothing → xs
.set (just xv) → k (up (node x xv ee (leaf l) (leaf u)))
go xs x (node y yv bl yl yr) (l , u) k with compare x y
go xs x (node y yv bl yl yr) (l , u) k | eq x≡y = λ where
.get → just (subst _ (sym x≡y) yv)
.set nothing → k (inc→changeup (join yl bl yr))
.set (just xv) → k (ev (node y (subst _ x≡y xv) bl yl yr))
go xs x (node y yv bl yl yr) (l , u) k | lt x<y =
go xs x yl (l , x<y)
λ { (up yl′) → case bl of
λ { ll → k (inc→changedn (rotʳ y yv yl′ yr))
; ee → k (up (node y yv ll yl′ yr))
; rr → k (ev (node y yv ee yl′ yr))
}
; (ev yl′) → k (ev (node y yv bl yl′ yr))
; (dn yl′) → case bl of
λ { rr → k (inc→changeup (rotˡ y yv yl′ yr))
; ee → k (ev (node y yv rr yl′ yr))
; ll → k (dn (node y yv ee yl′ yr))
}
}
go xs x (node y yv bl yl yr) (l , u) k | gt x>y =
go xs x yr (x>y , u)
λ { (up yr′) → case bl of
λ { rr → k (inc→changedn (rotˡ y yv yl yr′))
; ee → k (up (node y yv rr yl yr′))
; ll → k (ev (node y yv ee yl yr′))
}
; (ev yr′) → k (ev (node y yv bl yl yr′))
; (dn yr′) → case bl of
λ { ll → k (inc→changeup (rotʳ y yv yl yr′))
; ee → k (ev (node y yv ll yl yr′))
; rr → k (dn (node y yv ee yl yr′))
}
}
open import Data.List
toList⊙ : Tree Val lb ub n → List (∃ x × Val x) → List (∃ x × Val x)
toList⊙ (leaf lb<ub) ks = ks
toList⊙ (node x xv bal xl xr) ks = toList⊙ xl ((x , xv) ∷ toList⊙ xr ks)
toList : Tree Val lb ub n → List (∃ x × Val x)
toList xs = toList⊙ xs []
| {
"alphanum_fraction": 0.5144595134,
"avg_line_length": 33.6510067114,
"ext": "agda",
"hexsha": "d1dc4973749fac1a0305091492f83002d6e52751",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/AVLTree/Internal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/AVLTree/Internal.agda",
"max_line_length": 129,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/AVLTree/Internal.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 3970,
"size": 10028
} |
{-# OPTIONS --guardedness #-}
module Stream where
import Lvl
open import Data.Boolean
open import Data.List as List using (List)
import Data.List.Functions as List
import Data.List.Proofs as List
import Data.List.Equiv.Id as List
open import Functional
open import Function.Iteration
open import Function.Iteration.Proofs
open import Logic
open import Logic.Propositional
open import Numeral.Natural
open import Relator.Equals
open import Relator.Equals.Proofs
open import Type
private variable ℓ : Lvl.Level
private variable T A B : Type{ℓ}
private variable a x init : T
private variable f : A → B
private variable n : ℕ
-- A countably infinite list
record Stream (T : Type{ℓ}) : Type{ℓ} where
coinductive
field
head : T
tail : Stream(T)
open Stream
module _ where
-- The n:th element of a stream.
-- Example: index(2)(0,1,2,…) = 2
index : Stream(T) → ℕ → T
index(l)(𝟎) = head(l)
index(l)(𝐒(n)) = index(tail(l))(n)
-- The constant stream, consisting of a single element repeated.
-- Example: repeat(x) = (x,x,x,..)
repeat : T → Stream(T)
head(repeat(x)) = x
tail(repeat(x)) = repeat(x)
-- The stream consisting of a list repeated (concatenated infinite many times).
-- Example: loop(1,2,3) = (1,2,3 , 1,2,3 , 1,2,3 , …)
loop : (l : List(T)) → (l ≢ List.∅) → Stream(T)
loop List.∅ p with () ← p [≡]-intro
head (loop (x List.⊰ l) p) = x
tail (loop (x List.⊰ l) p) = loop (List.postpend x l) List.[∅]-postpend-unequal
-- The stream of two interleaved streams.
-- Example: interleave₂(1,2,3,‥)(a,b,c,…) = (1,a , 2,b , 3,c , …)
interleave₂ : Stream(T) -> Stream(T) -> Stream(T)
head(interleave₂(a)(b)) = head(a)
tail(interleave₂(a)(b)) = interleave₂(b)(tail a)
-- A stream which skips the first n number of elements from the specified stream.
-- From the stream of (index 0 l , index 1 l , index 2 l , ..), the stream of (index n l , index (n+1) l , index (n+2) l , ..)
-- Example: skip(2)(1,2,3,4,…) = (3,4,…)
skip : ℕ → Stream(T) -> Stream(T)
head(skip 𝟎 l) = head(l)
tail(skip 𝟎 l) = tail(l)
head(skip (𝐒(n)) l) = head(skip n (tail(l)))
tail(skip (𝐒(n)) l) = tail(skip n (tail(l)))
-- From the stream of (index 0 l , index 1 l , index 2 l , ..), the stream of (index 0 l , index n l , index (2⋅n) l , ..)
-- Example: takeMultiples(3)(0,1,2,…) = (0,3,6,…)
takeMultiples : ℕ → Stream(T) -> Stream(T)
head(takeMultiples _ l) = head(l)
tail(takeMultiples n l) = takeMultiples n ((tail ^ n) l)
-- From the stream of (a,b,c,..), the stream of (x,a,b,c,..)
_⊰_ : T → Stream(T) -> Stream(T)
head(x ⊰ _) = x
tail(_ ⊰ l) = l
-- Stream of (init , f(init) , f(f(init)) , ..)
iterated : T -> (T → T) → Stream(T)
head(iterated init _) = init
tail(iterated init f) = iterated (f(init)) f
-- List from the initial part of the stream
take : ℕ → Stream(T) → List(T)
take(𝟎) (l) = List.∅
take(𝐒(n))(l) = head(l) List.⊰ take(n)(tail(l))
-- Example: indexIntervals(0,0,2,0,1,2,…)(0,1,2,3,…) = (0,0,2,2,3,5,…)
indexIntervals : Stream(ℕ) → Stream(T) → Stream(T)
head (indexIntervals i l) = index l (head i)
tail (indexIntervals i l) = indexIntervals (tail i) (skip (head i) l)
module _ where
-- From the stream of (a,b,c,..), the stream of (f(a),f(b),f(c),..)
map : (A → B) → Stream(A) → Stream(B)
head(map f(l)) = f(head(l))
tail(map f(l)) = map f(tail(l))
{- TODO: May not terminate. For example when P = const 𝐹
module _ {ℓ} {A : Type{ℓ}} where
filter : (A → Bool) → Stream(A) → Stream(A)
head(filter p(l)) with p(head(l))
... | 𝑇 = head(l)
... | 𝐹 = head(filter p(tail(l)))
tail(filter p(l)) = filter p(tail(l))
-}
module _ where
data _∈_ {T : Type{ℓ}} : T → Stream(T) → Stmt{ℓ} where
[∈]-head : ∀{l} → (head(l) ∈ l)
[∈]-tail : ∀{a l} → (a ∈ tail(l)) → (a ∈ l)
private variable l : Stream(T)
index-of-[∈] : (x ∈ l) → ℕ
index-of-[∈] [∈]-head = 𝟎
index-of-[∈] ([∈]-tail p) = 𝐒(index-of-[∈] p)
index-of-[∈]-correctness : ∀{p : (x ∈ l)} → (index l (index-of-[∈] p) ≡ x)
index-of-[∈]-correctness {x = .(head l)} {l} {[∈]-head} = [≡]-intro
index-of-[∈]-correctness {x = x} {l} {[∈]-tail p} = index-of-[∈]-correctness {x = x} {tail l} {p}
_⊆_ : Stream(T) → Stream(T) → Stmt
_⊆_ l₁ l₂ = ∀{a} → (a ∈ l₁) → (a ∈ l₂)
[∈]-tails : ((tail ^ n)(l) ⊆ l)
[∈]-tails {n = 𝟎} {l = l} {a} tailn = tailn
[∈]-tails {n = 𝐒 n} {l = l} {a} tailn = [∈]-tail ([∈]-tails {n = n} {l = tail l} {a} ([≡]-substitutionₗ ([^]-inner-value {f = tail}{x = l}{n}) {a ∈_} tailn))
[∈]-head-tail : (head(tail(l)) ∈ l)
[∈]-head-tail = [∈]-tail ([∈]-head)
[∈]-head-tails-membership : (head((tail ^ n)(l)) ∈ l)
[∈]-head-tails-membership{𝟎} = [∈]-head
[∈]-head-tails-membership{𝐒(n)}{l} = [∈]-tails {n = n} ([∈]-head-tail)
[∈]-disjunction : (x ∈ l) → ((x ≡ head(l)) ∨ (x ∈ tail(l)))
[∈]-disjunction ([∈]-head) = [∨]-introₗ [≡]-intro
[∈]-disjunction ([∈]-tail proof) = [∨]-introᵣ proof
[∈]-index : (index l n ∈ l)
[∈]-index {n = 𝟎} = [∈]-head
[∈]-index {n = 𝐒(n)} = [∈]-tail ([∈]-index {n = n})
repeat-[∈] : (x ∈ repeat(a)) ↔ (x ≡ a)
repeat-[∈] {x = x}{a = a} = [↔]-intro left right where
left : (x ∈ repeat(a)) ← (x ≡ a)
left ([≡]-intro) = [∈]-head
right : (x ∈ repeat(a)) → (x ≡ a)
right ([∈]-head) = [≡]-intro
right ([∈]-tail proof) = right(proof)
map-[∈] : (x ∈ l) → (f(x) ∈ map f(l))
map-[∈] ([∈]-head) = [∈]-head
map-[∈] {l = l} ([∈]-tail proof) = [∈]-tail (map-[∈] {l = tail l} (proof))
[⊰][∈] : (a ∈ (x ⊰ l)) ↔ ((x ≡ a) ∨ (a ∈ l))
[⊰][∈] {a = a}{x = x}{l = l} = [↔]-intro ll rr where
ll : (a ∈ (x ⊰ l)) ← ((x ≡ a) ∨ (a ∈ l))
ll ([∨]-introₗ ([≡]-intro)) = [∈]-head
ll ([∨]-introᵣ (proof)) = [∈]-tail (proof)
rr : (a ∈ (x ⊰ l)) → ((x ≡ a) ∨ (a ∈ l))
rr ([∈]-head) = [∨]-introₗ ([≡]-intro)
rr ([∈]-tail (proof)) = [∨]-introᵣ (proof)
iterated-init-[∈] : (init ∈ iterated(init)(f))
iterated-init-[∈] = [∈]-head
iterated-next-[∈] : (x ∈ iterated(init)(f)) → (f(x) ∈ iterated(init)(f))
iterated-next-[∈] ([∈]-head) = [∈]-tail ([∈]-head)
iterated-next-[∈] ([∈]-tail proof) = [∈]-tail (iterated-next-[∈] (proof))
-- First:
-- head(iterated(init)(f)) ∈ iterated(init)(f)
-- init ∈ iterated(init)(f)
-- ...
-- Second:
-- x ∈ tail(iterated(init)(f))
-- x ∈ iterated (f(init)) f
-- ...
iterated-[∈] : ((f ^ n)(init) ∈ iterated(init)(f))
iterated-[∈] {n = 𝟎} = iterated-init-[∈]
iterated-[∈] {n = 𝐒 n} = iterated-next-[∈] (iterated-[∈] {n = n})
-- Stream of (0,1,2,3,..)
[ℕ]-stream : Stream(ℕ)
[ℕ]-stream = iterated(𝟎)(𝐒)
[ℕ]-stream-[∈] : (n ∈ [ℕ]-stream)
[ℕ]-stream-[∈]{𝟎} = [∈]-head
[ℕ]-stream-[∈]{𝐒(n)} = iterated-next-[∈]([ℕ]-stream-[∈]{n})
-- Stream of (f(0),f(1),f(2),f(3),..)
[ℕ]-function-stream : (ℕ → T) → Stream(T)
[ℕ]-function-stream f = map f([ℕ]-stream)
module _ {ℓ} {T : Type{ℓ}} where
open import Logic.Predicate
open import Logic.Predicate.Theorems
open import Structure.Function.Domain
open import Type.Size.Countable
-- This provides another way of proving that a type is countable.
-- The method is: If a stream can enumerate every object of a certain type, then it is countable.
countable-equivalence : ∃(l ↦ ∀{x : T} → (x ∈ l)) ↔ Countable(T)
countable-equivalence = [↔]-intro left right where
left : ∃(l ↦ ∀{x : T} → (x ∈ l)) ← Countable(T)
∃.witness (left ([∃]-intro f ⦃ intro proof ⦄)) = [ℕ]-function-stream f
∃.proof (left ([∃]-intro f ⦃ intro proof ⦄)) {x} with proof{x}
... | [∃]-intro n ⦃ [≡]-intro ⦄ = map-[∈] [ℕ]-stream-[∈]
right : ∃(l ↦ ∀{x : T} → (x ∈ l)) → Countable(T)
∃.witness (right ([∃]-intro l ⦃ p ⦄)) = index l
∃.witness (Surjective.proof (∃.proof (right ([∃]-intro l ⦃ p ⦄))) {x}) = index-of-[∈] (p{x})
∃.proof (Surjective.proof (∃.proof (right ([∃]-intro l ⦃ p ⦄))) {x}) = index-of-[∈]-correctness {p = p}
| {
"alphanum_fraction": 0.5353738083,
"avg_line_length": 36.07239819,
"ext": "agda",
"hexsha": "eab37a366c4e69e69138f5a7b93c172dfc7b683d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Stream.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Stream.agda",
"max_line_length": 159,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Stream.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 3275,
"size": 7972
} |
module Oscar.Data.AList.properties {𝔣} (FunctionName : Set 𝔣) where
open import Oscar.Category.Category
open import Oscar.Category.Functor
open import Oscar.Category.Morphism
open import Oscar.Category.Semigroupoid
open import Oscar.Category.Semifunctor
open import Oscar.Category.Setoid
open import Oscar.Class.ThickAndThin
open import Oscar.Data.AList FunctionName
open import Oscar.Data.Equality
open import Oscar.Data.Equality.properties
open import Oscar.Data.Fin
open import Oscar.Data.Fin.ThickAndThin
open import Oscar.Data.Maybe
open import Oscar.Data.Nat
open import Oscar.Data.Product
open import Oscar.Data.Term FunctionName
import Oscar.Data.Term.internal.SubstituteAndSubstitution FunctionName as S
open import Oscar.Data.Term.ThickAndThin FunctionName
open import Oscar.Function
module 𝔊₂ = Category S.𝔾₁
module 𝔉◃ = Functor S.𝔽◂
𝕞₁ = ⇧ AList
module 𝔐₁ = Morphism 𝕞₁
private
_∙_ : ∀ {m n} → m 𝔐₁.↦ n → ∀ {l} → l 𝔐₁.↦ m → l 𝔐₁.↦ n
ρ ∙ anil = ρ
ρ ∙ (σ asnoc t' / x) = (ρ ∙ σ) asnoc t' / x
∙-associativity : ∀ {l m} (ρ : l 𝔐₁.↦ m) {n} (σ : n 𝔐₁.↦ _) {o} (τ : o 𝔐₁.↦ _) → (ρ ∙ σ) ∙ τ ≡ ρ ∙ (σ ∙ τ)
∙-associativity ρ σ anil = refl
∙-associativity ρ σ (τ asnoc t / x) = cong (λ s → s asnoc t / x) (∙-associativity ρ σ τ)
instance
IsSemigroupoid𝕞₁∙ : IsSemigroupoid 𝕞₁ _∙_
IsSemigroupoid.extensionality IsSemigroupoid𝕞₁∙ f₁≡f₂ g₁≡g₂ = cong₂ (λ ‵ → _∙_ ‵) g₁≡g₂ f₁≡f₂
IsSemigroupoid.associativity IsSemigroupoid𝕞₁∙ f g h = ∙-associativity h g f
𝕘₁ : Semigroupoid _ _ _
𝕘₁ = 𝕞₁ , _∙_
private
ε : ∀ {n} → n 𝔐₁.↦ n
ε = anil
∙-left-identity : ∀ {m n} (σ : AList m n) → ε ∙ σ ≡ σ
∙-left-identity anil = refl
∙-left-identity (σ asnoc t' / x) = cong (λ σ → σ asnoc t' / x) (∙-left-identity σ)
instance
IsCategory𝕘₁ε : IsCategory 𝕘₁ ε
IsCategory.left-identity IsCategory𝕘₁ε = ∙-left-identity
IsCategory.right-identity IsCategory𝕘₁ε _ = refl
𝔾₁ : Category _ _ _
𝔾₁ = 𝕘₁ , ε
𝕞₂ = 𝔊₂.𝔐
module 𝔐₂ = Morphism 𝕞₂
private
sub : ∀ {m n} → m 𝔐₁.↦ n → m 𝔊₂.↦ n
sub anil = i
sub (σ asnoc t' / x) = sub σ 𝔊₂.∙ (t' for x)
fact1 : ∀ {l m n} (ρ : AList m n) (σ : AList l m) → sub (ρ ∙ σ) ≡̇ (sub ρ 𝔊₂.∙ sub σ)
fact1 ρ anil v = refl
fact1 {suc l} {m} {n} r (s asnoc t' / x) v = trans hyp-on-terms ◃-assoc
where
t = (t' for x) v
hyp-on-terms = 𝔉◃.extensionality (fact1 r s) t
◃-assoc = 𝔉◃.distributivity (sub s) (sub r) t
𝕘₁,₂ : Semigroupoids _ _ _ _ _ _
𝕘₁,₂ = 𝕘₁ , 𝔊₂.semigroupoid
instance
IsSemifunctorSub∙◇ : IsSemifunctor 𝕘₁,₂ sub
IsSemifunctor.extensionality IsSemifunctorSub∙◇ refl _ = refl
IsSemifunctor.distributivity IsSemifunctorSub∙◇ f g x = fact1 g f x
semifunctorSub∙◇ : Semifunctor _ _ _ _ _ _
semifunctorSub∙◇ = 𝕘₁,₂ , sub
instance
IsFunctor𝔽 : IsFunctor (𝔾₁ , S.𝔾₁) sub
IsFunctor.identity IsFunctor𝔽 _ _ = refl
𝔽 : Functor _ _ _ _ _ _
𝔽 = (𝔾₁ , S.𝔾₁) , sub
-- fact1 : ∀ {l m n} (ρ : AList m n) (σ : AList l m) → sub (ρ ∙ σ) ≡̇ (sub ρ ◇ sub σ)
-- fact1 ρ anil v = refl
-- fact1 {suc l} {m} {n} r (s asnoc t' / x) v = trans hyp-on-terms ◃-assoc
-- where
-- t = (t' for x) v
-- hyp-on-terms = ◃-extensionality (fact1 r s) t
-- ◃-assoc = ◃-associativity (sub s) (sub r) t
-- _∃asnoc_/_ : ∀ {m} (a : ∃ (AList m)) (t' : Term m) (x : Fin (suc m))
-- → ∃ (AList (suc m))
-- (n , σ) ∃asnoc t' / x = n , σ asnoc t' / x
-- flexFlex : ∀ {m} (x y : Fin m) → ∃ (AList m)
-- flexFlex {suc m} x y with check x y
-- ... | just y' = m , anil asnoc i y' / x
-- ... | nothing = suc m , anil
-- flexFlex {zero} () _
-- flexRigid : ∀ {m} (x : Fin m) (t : Term m) → Maybe (∃(AList m))
-- flexRigid {suc m} x t with check x t
-- ... | just t' = just (m , anil asnoc t' / x)
-- ... | nothing = nothing
-- flexRigid {zero} () _
| {
"alphanum_fraction": 0.6130217905,
"avg_line_length": 29.7578125,
"ext": "agda",
"hexsha": "24fb4a65405f63c27ff347c0b980f88c8008d0ae",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Data/AList/properties.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Data/AList/properties.agda",
"max_line_length": 108,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Data/AList/properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1654,
"size": 3809
} |
{-# OPTIONS --without-K --safe #-}
-- Formalization of internal relations
-- (=congruences: https://ncatlab.org/nlab/show/congruence)
open import Categories.Category
module Categories.Object.InternalRelation {o ℓ e} (𝒞 : Category o ℓ e) where
open import Level hiding (zero)
open import Data.Unit
open import Data.Fin using (Fin; zero) renaming (suc to nzero)
import Categories.Morphism as Mor
import Categories.Morphism.Reasoning as MR
open import Categories.Morphism.Notation
open import Categories.Diagram.Pullback
open import Categories.Diagram.KernelPair
open import Categories.Category.Cartesian
open import Categories.Category.BinaryProducts 𝒞 using (BinaryProducts; module BinaryProducts)
private
module 𝒞 = Category 𝒞
open Category 𝒞
open Mor 𝒞
-- A relation is a span, "which is (-1)-truncated as a morphism into the cartesian product."
-- (https://ncatlab.org/nlab/show/span#correspondences)
isRelation : {X Y R : 𝒞.Obj} (f : R ⇒ X) (g : R ⇒ Y) → Set (o ⊔ ℓ ⊔ e)
isRelation{X}{Y}{R} f g = JointMono
(Fin 2)
(λ{zero → X; (nzero _) → Y})
(λ{zero → f; (nzero _) → g})
record Relation (X Y : 𝒞.Obj) : Set (suc (o ⊔ ℓ ⊔ e)) where
open Mor 𝒞
field
dom : 𝒞.Obj
p₁ : dom ⇒ X
p₂ : dom ⇒ Y
field
relation : isRelation p₁ p₂
record isEqSpan {X R : 𝒞.Obj} (f : R ⇒ X) (g : R ⇒ X) : Set (suc (o ⊔ ℓ ⊔ e)) where
field
R×R : Pullback 𝒞 f g
module R×R = Pullback R×R renaming (P to dom)
field
refl : X ⇒ R
sym : R ⇒ R
trans : R×R.dom ⇒ R
is-refl₁ : f ∘ refl ≈ id
is-refl₂ : g ∘ refl ≈ id
is-sym₁ : f ∘ sym ≈ g
is-sym₂ : g ∘ sym ≈ f
is-trans₁ : f ∘ trans ≈ f ∘ R×R.p₁
is-trans₂ : g ∘ trans ≈ g ∘ R×R.p₂
-- Internal equivalence
record Equivalence (X : 𝒞.Obj) : Set (suc (o ⊔ ℓ ⊔ e)) where
open Mor 𝒞
open BinaryProducts
field
R : Relation X X
open Relation R
module R = Relation R
field
eqspan : isEqSpan R.p₁ R.p₂
module _ where
open Pullback hiding (P)
KP⇒EqSpan : {X Y : 𝒞.Obj} (f : X ⇒ Y) → (kp : KernelPair 𝒞 f) → (p : Pullback 𝒞 (p₁ kp) (p₂ kp)) → isEqSpan (p₁ kp) (p₂ kp)
KP⇒EqSpan f kp p = record
{ R×R = p
; refl = universal kp {_} {id}{id} 𝒞.Equiv.refl
; sym = universal kp {_} {p₂ kp}{p₁ kp} (𝒞.Equiv.sym (commute kp))
; trans = universal kp {_}{p₁ kp ∘ p₁ p}{p₂ kp ∘ p₂ p} (∘-resp-≈ʳ (commute p))
; is-refl₁ = p₁∘universal≈h₁ kp
; is-refl₂ = p₂∘universal≈h₂ kp
; is-sym₁ = p₁∘universal≈h₁ kp
; is-sym₂ = p₂∘universal≈h₂ kp
; is-trans₁ = p₁∘universal≈h₁ kp
; is-trans₂ = p₂∘universal≈h₂ kp
}
KP⇒Relation : {X Y : 𝒞.Obj} (f : X ⇒ Y) → (kp : KernelPair 𝒞 f) → (p : Pullback 𝒞 (p₁ kp) (p₂ kp)) → isRelation (p₁ kp) (p₂ kp)
KP⇒Relation f kp _ _ _ eq = unique-diagram kp (eq zero) (eq (nzero zero))
| {
"alphanum_fraction": 0.6087873462,
"avg_line_length": 28.1683168317,
"ext": "agda",
"hexsha": "b2768a33119075d85acce1067d94d294d17c6310",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c202a616d4f376b11e8320e641c98db2ddc9d233",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Akshobhya1234/agda-categories",
"max_forks_repo_path": "src/Categories/Object/InternalRelation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c202a616d4f376b11e8320e641c98db2ddc9d233",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Akshobhya1234/agda-categories",
"max_issues_repo_path": "src/Categories/Object/InternalRelation.agda",
"max_line_length": 129,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c202a616d4f376b11e8320e641c98db2ddc9d233",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Akshobhya1234/agda-categories",
"max_stars_repo_path": "src/Categories/Object/InternalRelation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1081,
"size": 2845
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
module experimental.CubicalTypes where
data access : ℕ → ℕ → Type₀ where
[] : access O O
_#up : ∀ {n} {k} → access n k → access (S n) k
_#down : ∀ {n} {k} → access n k → access (S n) k
_#keep : ∀ {n} {k} → access n k → access (S n) (S k)
_a∙_ : ∀ {n k l} → access n k → access k l → access n l
_a∙_ [] a₂ = a₂
_a∙_ (a₁ #up) a₂ = (a₁ a∙ a₂) #up
_a∙_ (a₁ #down) a₂ = (a₁ a∙ a₂) #down
_a∙_ (a₁ #keep) (a₂ #up) = (a₁ a∙ a₂) #up
_a∙_ (a₁ #keep) (a₂ #down) = (a₁ a∙ a₂) #down
_a∙_ (a₁ #keep) (a₂ #keep) = (a₁ a∙ a₂) #keep
| {
"alphanum_fraction": 0.5375426621,
"avg_line_length": 27.9047619048,
"ext": "agda",
"hexsha": "c26fef43eff1c8e133c8335f5bbda482759c5ca5",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/stash/CubicalTypes.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/stash/CubicalTypes.agda",
"max_line_length": 55,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/stash/CubicalTypes.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 286,
"size": 586
} |
module Prelude.List where
open import Prelude.List.Base public
| {
"alphanum_fraction": 0.8153846154,
"avg_line_length": 13,
"ext": "agda",
"hexsha": "891e14e82e8826a7daa5d3ae16b0982b645a3337",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "t-more/agda-prelude",
"max_forks_repo_path": "src/Prelude/List.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "t-more/agda-prelude",
"max_issues_repo_path": "src/Prelude/List.agda",
"max_line_length": 36,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "t-more/agda-prelude",
"max_stars_repo_path": "src/Prelude/List.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 12,
"size": 65
} |
-- We can infer the type of a record by comparing the given
-- fields against the fields of the currently known records.
module InferRecordTypes where
data Nat : Set where
zero : Nat
suc : Nat → Nat
record _×_ (A B : Set) : Set where
field
fst : A
snd : B
pair = record { fst = zero; snd = zero }
record R₁ : Set where
field
x₁ : Nat
r₁ = record { x₁ = zero }
data T {A : Set} : A → Set where
mkT : ∀ n → T n
record R₂ A : Set where
field
{x₁} : A
x₂ : T x₁
r₂ = record { x₂ = mkT (suc zero) }
record R₃ : Set where
field
x₁ x₃ : Nat
r₃ = record { x₁ = zero; x₃ = suc zero } | {
"alphanum_fraction": 0.5984,
"avg_line_length": 17.3611111111,
"ext": "agda",
"hexsha": "18c9fe0ec542765f393e1206215ad5e1d421bc29",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/InferRecordTypes.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/InferRecordTypes.agda",
"max_line_length": 60,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/InferRecordTypes.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 220,
"size": 625
} |
{- 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
-}
-- This module contains properties that are only about the behavior of the handlers, nothing to do
-- with system state
open import Optics.All
open import LibraBFT.Prelude
open import LibraBFT.Base.ByteString
open import LibraBFT.Base.Types
open import LibraBFT.Hash
open import LibraBFT.Impl.Base.Types
open import LibraBFT.Impl.Consensus.Types
open import LibraBFT.Impl.Util.Util
module LibraBFT.Impl.Consensus.ChainedBFT.EventProcessor.Properties
(hash : BitString → Hash)
(hash-cr : ∀{x y} → hash x ≡ hash y → Collision hash x y ⊎ x ≡ y)
where
open import LibraBFT.Impl.Consensus.ChainedBFT.EventProcessor hash hash-cr
-- The quorum certificates sent in SyncInfo with votes are those from the peer state
procPMCerts≡ : ∀ {ts pm pre vm αs}
→ (SendVote vm αs) ∈ LBFT-outs (processProposalMsg ts pm) pre
→ vm ^∙ vmSyncInfo ≡ mkSyncInfo (₋epHighestQC pre) (₋epHighestCommitQC pre)
procPMCerts≡ (there x) = ⊥-elim (¬Any[] x) -- processProposalMsg sends only one vote
procPMCerts≡ (here refl) = refl
| {
"alphanum_fraction": 0.7378565921,
"avg_line_length": 40.53125,
"ext": "agda",
"hexsha": "dc2e62faae68467252b56000acc7ddcbdcdc801f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "haroldcarr/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Impl/Consensus/ChainedBFT/EventProcessor/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "haroldcarr/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Impl/Consensus/ChainedBFT/EventProcessor/Properties.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "haroldcarr/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Impl/Consensus/ChainedBFT/EventProcessor/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 374,
"size": 1297
} |
module unit where
open import level
open import eq
data ⊤ {ℓ : Level} : Set ℓ where
triv : ⊤
{-# COMPILE GHC ⊤ = data () (()) #-}
single-range : ∀{ℓ}{U : Set ℓ}{g : U → ⊤ {ℓ}} → ∀{u : U} → g u ≡ triv
single-range {_}{U}{g}{u} with g u
... | triv = refl
| {
"alphanum_fraction": 0.5250965251,
"avg_line_length": 18.5,
"ext": "agda",
"hexsha": "4bb7cff6a1fe984ea35cd1fd7e761a5ab2722c88",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "unit.agda",
"max_line_length": 69,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "unit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 106,
"size": 259
} |
-- Andreas, 2020-04-15, issue #4586
-- An unintended internal error.
test : Set₁
test = let ... | _ = Set
in Set
-- WAS:
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/Syntax/Translation/ConcreteToAbstract.hs:1417
-- EXPECTED:
-- Could not parse the left-hand side ... | _
-- Operators used in the grammar:
-- None
-- when scope checking let ... | _ = Set in Set
| {
"alphanum_fraction": 0.6674364896,
"avg_line_length": 25.4705882353,
"ext": "agda",
"hexsha": "bc2aaa21ea9bd8599d52ec55472d4ffd5c99b33d",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Fail/Issue4586LetEllipsis.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue4586LetEllipsis.agda",
"max_line_length": 85,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue4586LetEllipsis.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 121,
"size": 433
} |
{-# OPTIONS --copatterns #-}
module Control.Category.Slice where
open import Level using (suc; _⊔_)
open import Relation.Binary hiding (_⇒_)
open import Control.Category
open Category using () renaming (Obj to obj)
-- Given a category C and an object Tgt in C we can define a new category
-- whose objects S are pairs of an object Src in C
-- and a morphism out from Src to Tgt.
record SliceObj {o h e} (C : Category o h e) (Tgt : obj C) : Set (o ⊔ h ⊔ e) where
constructor sliceObj
open Category C -- public
field
Src : Obj
out : Src ⇒ Tgt
-- In the following, we fix a category C and an object Tgt.
module _ {o h e} {C : Category o h e} {Tgt : obj C} where
-- We use _⇒_ for C's morphisms and _∘_ for their composition.
private
open module C = Category C hiding (id; ops)
Slice = SliceObj C Tgt
open module Slice = SliceObj {C = C} {Tgt = Tgt}
-- A morphism in the slice category into Tgt
-- from slice (S, s) to (T, t)
-- is a morphism f : S ⇒ T such that t ∘ f ≡ s.
record SliceMorphism (S T : Slice) : Set (h ⊔ e)
where
constructor sliceMorphism
field
mor : Src S ⇒ Src T
triangle : (mor ⟫ out T) ≈ out S
-- Two morphisms in the slice category are equal
-- iff they are equal in the underlying category C.
SliceHom : (S T : Slice) → Setoid _ _
SliceHom S T = record
{ Carrier = SliceMorphism S T
; _≈_ = λ f g → SliceMorphism.mor f ≈ SliceMorphism.mor g
; isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
} where open IsEquivalence (≈-equiv {Src S} {Src T})
-- We write S ⇉ T for a morphism from slice S to slice T
open HomSet SliceHom using () renaming (_⇒_ to _⇉_; _≈_ to _≐_)
-- The identity slice morphism is just the identity morphism.
slice-id : ∀ {P} → P ⇉ P
slice-id = record { mor = C.id; triangle = C.id-first }
-- The composition of slice morphims is just the composition in C.
comp : ∀ {S T U} → S ⇉ T → T ⇉ U → S ⇉ U
comp (sliceMorphism f tri-f) (sliceMorphism g tri-g) = record
{ mor = f ⟫ g
; triangle = ≈-trans (C.∘-assoc f) (≈-trans (C.∘-cong ≈-refl tri-g) tri-f)
}
ops : CategoryOps SliceHom
ops = record { id = slice-id ; _⟫_ = comp}
sliceIsCategory : IsCategory SliceHom
sliceIsCategory = record
{ ops = ops
; laws = record
{ id-first = C.id-first -- id-first
; id-last = C.id-last
; ∘-assoc = λ f → C.∘-assoc _
; ∘-cong = C.∘-cong
}
}
-- The slice category.
module _ {o h e} (C : Category o h e) (Tgt : obj C) where
module C = Category C
_/_ : Category (o ⊔ h ⊔ e) (e ⊔ h) e
_/_ = record
{ Obj = SliceObj C Tgt
; Hom = SliceHom
; isCategory = sliceIsCategory
}
open Category _/_
-- The terminal object in C / Tgt is (Tgt, id).
terminalSlice : Obj
terminalSlice = record { Src = Tgt; out = C.id }
open IsFinal
isTerminalSlice : IsFinal Hom terminalSlice
final isTerminalSlice {sliceObj Src f}
= sliceMorphism f C.id-last
final-universal isTerminalSlice {sliceObj Src f} {sliceMorphism g tri}
= C.≈-trans (C.≈-sym C.id-last) tri
-- The initial object in C / Tgt is (0, initial)
module _ {⊥ : obj C} (⊥-initial : IsInitial C.Hom ⊥) where
open IsInitial ⊥-initial
renaming (initial to abort; initial-universal to abort-unique)
initialSlice : Obj
initialSlice = record { Src = ⊥; out = abort }
open IsInitial
isInitialSlice : IsInitial Hom initialSlice
initial isInitialSlice = sliceMorphism abort abort-unique
initial-universal isInitialSlice = abort-unique
| {
"alphanum_fraction": 0.6190866831,
"avg_line_length": 27.4962406015,
"ext": "agda",
"hexsha": "5f97bb5fcc88b0264f36fd5799872e2e4459e9e6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andreasabel/cubical",
"max_forks_repo_path": "src/Control/Category/Slice.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "andreasabel/cubical",
"max_issues_repo_path": "src/Control/Category/Slice.agda",
"max_line_length": 82,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "914f655c7c0417754c2ffe494d3f6ea7a357b1c3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andreasabel/cubical",
"max_stars_repo_path": "src/Control/Category/Slice.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1177,
"size": 3657
} |
open import Nat
open import Prelude
open import core
open import judgemental-erase
open import moveerase
module sensibility where
mutual
-- if an action transforms a ê in a synthetic posistion to another ê,
-- they have the same type up erasure of the cursor
actsense-synth : {Γ : ·ctx} {e e' : ê} {e◆ e'◆ : ė} {t t' : τ̇} {α : action} →
erase-e e e◆ →
erase-e e' e'◆ →
Γ ⊢ e => t ~ α ~> e' => t' →
Γ ⊢ e◆ => t →
Γ ⊢ e'◆ => t'
-- in the movement case, we defer to the movement erasure theorem
actsense-synth er er' (SAMove x) wt with erasee-det (moveerasee' er x) er'
... | refl = wt
-- in all the nonzipper cases, the cursor must be at the top for the
-- action rule to apply, so we just build the new derivation
-- directly. no recursion is needed; these are effectively base cases.
actsense-synth _ EETop SADel _ = SEHole
actsense-synth EETop (EEAscR ETTop) SAConAsc wt = SAsc (ASubsume wt TCRefl)
actsense-synth _ EETop (SAConVar p) _ = SVar p
actsense-synth EETop (EEAscR (ETArrL ETTop)) (SAConLam x) SEHole = SAsc (ALam x MAArr (ASubsume SEHole TCRefl))
actsense-synth EETop (EEApR EETop) (SAConApArr x) wt = SAp wt x (ASubsume SEHole TCHole1)
actsense-synth EETop (EEApR EETop) (SAConApOtw x) wt = SAp (SNEHole wt) MAHole (ASubsume SEHole TCRefl)
actsense-synth _ EETop SAConNumlit _ = SNum
actsense-synth EETop (EEPlusR EETop) (SAConPlus1 TCRefl) wt = SPlus (ASubsume wt TCRefl) (ASubsume SEHole TCHole1)
actsense-synth EETop (EEPlusR EETop) (SAConPlus1 TCHole2) wt = SPlus (ASubsume wt TCHole1) (ASubsume SEHole TCHole1)
actsense-synth EETop (EEPlusR EETop) (SAConPlus2 _) wt = SPlus (ASubsume (SNEHole wt) TCHole1) (ASubsume SEHole TCHole1)
actsense-synth EETop (EENEHole EETop) SAConNEHole wt = SNEHole wt
actsense-synth _ EETop (SAFinish x) _ = x
--- zipper cases. in each, we recur on the smaller action derivation
--- following the zipper structure, then reassemble the result
actsense-synth (EEAscL er) (EEAscL er') (SAZipAsc1 x) (SAsc x₁)
with actsense-ana er er' x x₁
... | ih = SAsc ih
actsense-synth (EEAscR x₁) (EEAscR x) (SAZipAsc2 x₂ x₃ x₄ x₅) (SAsc x₆)
with eraset-det x x₃
... | refl = SAsc x₅
actsense-synth er (EEApL er') (SAZipApArr x x₁ x₂ act x₃) wt
with actsense-synth x₁ er' act x₂
... | ih = SAp ih x x₃
actsense-synth (EEApR er) (EEApR er') (SAZipApAna x x₁ x₂) (SAp wt x₃ x₄)
with synthunicity x₁ wt
... | refl with matcharrunicity x x₃
... | refl with actsense-ana er er' x₂ x₄
... | ih = SAp wt x ih
actsense-synth (EEPlusL er) (EEPlusL er') (SAZipPlus1 x) (SPlus x₁ x₂)
with actsense-ana er er' x x₁
... | ih = SPlus ih x₂
actsense-synth (EEPlusR er) (EEPlusR er') (SAZipPlus2 x) (SPlus x₁ x₂)
with actsense-ana er er' x x₂
... | ih = SPlus x₁ ih
actsense-synth er (EENEHole er') (SAZipHole x x₁ act) wt
with actsense-synth x er' act x₁
... | ih = SNEHole ih
-- if an action transforms an ê in an analytic posistion to another ê,
-- they have the same type up erasure of the cursor.
actsense-ana : {Γ : ·ctx} {e e' : ê} {e◆ e'◆ : ė} {t : τ̇} {α : action} →
erase-e e e◆ →
erase-e e' e'◆ →
Γ ⊢ e ~ α ~> e' ⇐ t →
Γ ⊢ e◆ <= t →
Γ ⊢ e'◆ <= t
-- in the subsumption case, punt to the other theorem
actsense-ana er1 er2 (AASubsume x x₁ x₂ x₃) _ = ASubsume (actsense-synth x er2 x₂ x₁) x₃
-- for movement, appeal to the movement-erasure theorem
actsense-ana er1 er2 (AAMove x) wt with erasee-det (moveerasee' er1 x) er2
... | refl = wt
-- in the nonzipper cases, we again know where the hole must be, so we
-- force it and then build the relevant derivation directly.
actsense-ana EETop EETop AADel wt = ASubsume SEHole TCHole1
actsense-ana EETop (EEAscR ETTop) AAConAsc wt = ASubsume (SAsc wt) TCRefl
actsense-ana EETop (EENEHole EETop) (AAConVar x₁ p) wt = ASubsume (SNEHole (SVar p)) TCHole1
actsense-ana EETop (EELam EETop) (AAConLam1 x₁ x₂) wt = ALam x₁ x₂ (ASubsume SEHole TCHole1)
actsense-ana EETop (EENEHole EETop) (AAConNumlit x) wt = ASubsume (SNEHole SNum) TCHole1
actsense-ana EETop EETop (AAFinish x) wt = x
actsense-ana EETop (EENEHole (EEAscR (ETArrL ETTop))) (AAConLam2 x _) (ASubsume SEHole q) =
ASubsume (SNEHole (SAsc (ALam x MAArr (ASubsume SEHole TCRefl)))) q
-- all subsumptions in the right derivation are bogus, because there's no
-- rule for lambdas synthetically
actsense-ana (EELam _) (EELam _) (AAZipLam _ _ _) (ASubsume () _)
-- that leaves only the zipper cases for lambda, where we force the
-- forms and then recurr into the body of the lambda being checked.
actsense-ana (EELam er1) (EELam er2) (AAZipLam x₁ x₂ act) (ALam x₄ x₅ wt)
with matcharrunicity x₂ x₅
... | refl with actsense-ana er1 er2 act wt
... | ih = ALam x₄ x₅ ih
| {
"alphanum_fraction": 0.6399217221,
"avg_line_length": 50.0980392157,
"ext": "agda",
"hexsha": "654b9d35984c96845371fc432dcda44b7d92079b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-07-03T03:45:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-07-03T03:45:07.000Z",
"max_forks_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/agda-popl17",
"max_forks_repo_path": "sensibility.agda",
"max_issues_count": 37,
"max_issues_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7",
"max_issues_repo_issues_event_max_datetime": "2016-11-09T18:13:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-07-07T16:23:11.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/agda-popl17",
"max_issues_repo_path": "sensibility.agda",
"max_line_length": 124,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "db3d21a1e3f17ef77ad557ed12374979f381b6b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/agda-popl17",
"max_stars_repo_path": "sensibility.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-11T12:30:50.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-01T22:44:11.000Z",
"num_tokens": 1914,
"size": 5110
} |
open import Agda.Primitive
open import Agda.Builtin.List
open import Agda.Builtin.Maybe
data Coercible (A : Set) (B : Set) : Set where
TrustMe : Coercible A B
postulate coerce : {A B : Set} {{_ : Coercible A B}} → A → B
instance
coerce-fun : {A B : Set} {{_ : Coercible A B}}
→ {C D : Set} {{_ : Coercible C D}}
→ Coercible (B → C) (A → D)
coerce-fun = TrustMe
coerce-refl : {A : Set} → Coercible A A
coerce-refl = TrustMe
postulate
primCatMaybes : {A : Set} → List (Maybe A) → List A
catMaybes : {A : Set} → List (Maybe A) → List A
catMaybes = coerce (primCatMaybes {_})
| {
"alphanum_fraction": 0.6077795786,
"avg_line_length": 24.68,
"ext": "agda",
"hexsha": "10e8f90d8d74f16d43a01cd75daa2e6f142c4216",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Test4687.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Test4687.agda",
"max_line_length": 60,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Test4687.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 218,
"size": 617
} |
------------------------------------------------------------------------
-- Monotone functions
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
module Partiality-monad.Inductive.Monotone where
open import Equality.Propositional
open import Prelude
open import Bijection equality-with-J using (_↔_)
import Partiality-algebra.Monotone as M
open import Partiality-monad.Inductive
-- Definition of monotone functions.
[_⊥→_⊥]⊑ : ∀ {a b} → Type a → Type b → Type (a ⊔ b)
[ A ⊥→ B ⊥]⊑ = M.[ partiality-algebra A ⟶ partiality-algebra B ]⊑
module [_⊥→_⊥]⊑ {a b} {A : Type a} {B : Type b} (f : [ A ⊥→ B ⊥]⊑) =
M.[_⟶_]⊑ f
open [_⊥→_⊥]⊑
-- Identity.
id⊑ : ∀ {a} {A : Type a} → [ A ⊥→ A ⊥]⊑
id⊑ = M.id⊑
-- Composition.
infixr 40 _∘⊑_
_∘⊑_ : ∀ {a b c} {A : Type a} {B : Type b} {C : Type c} →
[ B ⊥→ C ⊥]⊑ → [ A ⊥→ B ⊥]⊑ → [ A ⊥→ C ⊥]⊑
_∘⊑_ = M._∘⊑_
-- Equality characterisation lemma for monotone functions.
equality-characterisation-monotone :
∀ {a b} {A : Type a} {B : Type b} {f g : [ A ⊥→ B ⊥]⊑} →
(∀ x → function f x ≡ function g x) ↔ f ≡ g
equality-characterisation-monotone =
M.equality-characterisation-monotone
-- Composition is associative.
∘⊑-assoc :
∀ {a b c d} {A : Type a} {B : Type b} {C : Type c} {D : Type d}
(f : [ C ⊥→ D ⊥]⊑) (g : [ B ⊥→ C ⊥]⊑) {h : [ A ⊥→ B ⊥]⊑} →
f ∘⊑ (g ∘⊑ h) ≡ (f ∘⊑ g) ∘⊑ h
∘⊑-assoc = M.∘⊑-assoc
module _ {a b} {A : Type a} {B : Type b} where
-- If a monotone function is applied to an increasing sequence,
-- then the result is another increasing sequence.
[_$_]-inc :
[ A ⊥→ B ⊥]⊑ → Increasing-sequence A → Increasing-sequence B
[_$_]-inc = M.[_$_]-inc
-- A lemma relating monotone functions and least upper bounds.
⨆$⊑$⨆ : (f : [ A ⊥→ B ⊥]⊑) →
∀ s → ⨆ [ f $ s ]-inc ⊑ function f (⨆ s)
⨆$⊑$⨆ = M.⨆$⊑$⨆
| {
"alphanum_fraction": 0.5098983414,
"avg_line_length": 26.7,
"ext": "agda",
"hexsha": "39ba9767b51f470e9fa6ca1011c57e205c0d0621",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Partiality-monad/Inductive/Monotone.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/partiality-monad",
"max_issues_repo_path": "src/Partiality-monad/Inductive/Monotone.agda",
"max_line_length": 72,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Partiality-monad/Inductive/Monotone.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 793,
"size": 1869
} |
{-# OPTIONS --without-K --safe #-}
module SDG.Extra.OrderedAlgebra where
open import Relation.Binary
open import Algebra.FunctionProperties
open import Level
open import SDG.Extra.OrderedAlgebra.Structures
record OrderedCommutativeRing c ℓ : Set (suc (c ⊔ ℓ)) where
infix 8 -_
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_<_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
-_ : Op₁ Carrier
0# : Carrier
1# : Carrier
isOrderedCommutativeRing : IsOrderedCommutativeRing _≈_ _<_ _+_ _*_ -_ 0# 1#
open IsOrderedCommutativeRing isOrderedCommutativeRing public
| {
"alphanum_fraction": 0.700617284,
"avg_line_length": 23.1428571429,
"ext": "agda",
"hexsha": "9153035cc0b55c63b3bd24f23d363d9d81dadfa4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6814e6f0baffff35efe14ef70d469343cd9b3ba0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "wrrnhttn/agda-sdg",
"max_forks_repo_path": "SDG/Extra/OrderedAlgebra.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "6814e6f0baffff35efe14ef70d469343cd9b3ba0",
"max_issues_repo_issues_event_max_datetime": "2019-09-18T15:47:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-07-18T20:00:23.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "wrrnhttn/agda-sdg",
"max_issues_repo_path": "SDG/Extra/OrderedAlgebra.agda",
"max_line_length": 80,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "6814e6f0baffff35efe14ef70d469343cd9b3ba0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wrrnhttn/agda-sdg",
"max_stars_repo_path": "SDG/Extra/OrderedAlgebra.agda",
"max_stars_repo_stars_event_max_datetime": "2020-11-13T09:36:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-11-13T09:36:38.000Z",
"num_tokens": 215,
"size": 648
} |
module Imports.ImportedDisplayForms where
open import Agda.Builtin.Nat
postulate
_plus_ : Set
{-# DISPLAY _+_ a b = a plus b #-}
| {
"alphanum_fraction": 0.7185185185,
"avg_line_length": 13.5,
"ext": "agda",
"hexsha": "502e4f0f48d5e5cf1c204b6d3977fa1c334a830b",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Imports/ImportedDisplayForms.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Imports/ImportedDisplayForms.agda",
"max_line_length": 41,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Imports/ImportedDisplayForms.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 39,
"size": 135
} |
module CP where
open import Level
open import Data.Nat
open import Relation.Nullary
-- open import Data.String using (String)
TypeVar : Set
TypeVar = ℕ
infixl 10 _⨂_
infixl 10 _⅋_
data Type : Set where
-- ‵_ : TypeVar → Type
-- _^ : Type → Type
_⨂_ : Type → Type → Type
_⅋_ : Type → Type → Type
-- _⨁_ : Type → Type → Type
-- _&_ : Type → Type → Type
-- !_ : Type → Type
-- ¿_ : Type → Type
-- ∃[_] : Type → Type
-- ∀[_] : Type → Type
𝟙 : Type
⊥ : Type
𝟘 : Type
⊤ : Type
infixl 11 _^
_^ : Type → Type
(A ⨂ B) ^ = A ^ ⅋ B ^
(A ⅋ B) ^ = A ^ ⨂ B ^
𝟙 ^ = ⊥
⊥ ^ = 𝟙
𝟘 ^ = ⊤
⊤ ^ = 𝟘
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary.Decidable
open import Relation.Nullary.Product
open import Data.Product
open import Agda.Builtin.Bool
-- _≟t_ : (A B : Type) → Dec (A ≡ B)
-- (A ⨂ B) ≟t (C ⨂ D) with A ≟t C | B ≟t D
-- ... | yes refl | yes refl = yes refl
-- ... | yes refl | no ¬q = no λ where refl → ¬q refl
-- ... | no ¬p | yes q = no λ where refl → ¬p refl
-- ... | no ¬p | no ¬q = no λ where refl → ¬p refl
-- (A ⨂ B) ≟t (C ⅋ D) = no (λ ())
-- (A ⨂ B) ≟t 𝟙 = no (λ ())
-- (A ⨂ B) ≟t ⊥ = no (λ ())
-- (A ⨂ B) ≟t 𝟘 = no (λ ())
-- (A ⨂ B) ≟t ⊤ = no (λ ())
-- (A ⅋ B) ≟t (C ⨂ D) = no (λ ())
-- (A ⅋ B) ≟t (C ⅋ D) with A ≟t C | B ≟t D
-- ... | yes refl | yes refl = yes refl
-- ... | yes refl | no ¬q = no λ where refl → ¬q refl
-- ... | no ¬p | yes q = no λ where refl → ¬p refl
-- ... | no ¬p | no ¬q = no λ where refl → ¬p refl
-- (A ⅋ B) ≟t 𝟙 = no (λ ())
-- (A ⅋ B) ≟t ⊥ = no (λ ())
-- (A ⅋ B) ≟t 𝟘 = no (λ ())
-- (A ⅋ B) ≟t ⊤ = no (λ ())
-- 𝟙 ≟t (B ⨂ C) = no (λ ())
-- 𝟙 ≟t (B ⅋ C) = no (λ ())
-- 𝟙 ≟t 𝟙 = yes refl
-- 𝟙 ≟t ⊥ = no (λ ())
-- 𝟙 ≟t 𝟘 = no (λ ())
-- 𝟙 ≟t ⊤ = no (λ ())
-- ⊥ ≟t (B ⨂ C) = no (λ ())
-- ⊥ ≟t (B ⅋ C) = no (λ ())
-- ⊥ ≟t 𝟙 = no (λ ())
-- ⊥ ≟t ⊥ = yes refl
-- ⊥ ≟t 𝟘 = no (λ ())
-- ⊥ ≟t ⊤ = no (λ ())
-- 𝟘 ≟t (B ⨂ C) = no (λ ())
-- 𝟘 ≟t (B ⅋ C) = no (λ ())
-- 𝟘 ≟t 𝟙 = no (λ ())
-- 𝟘 ≟t ⊥ = no (λ ())
-- 𝟘 ≟t 𝟘 = yes refl
-- 𝟘 ≟t ⊤ = no (λ ())
-- ⊤ ≟t (B ⨂ C) = no (λ ())
-- ⊤ ≟t (B ⅋ C) = no (λ ())
-- ⊤ ≟t 𝟙 = no (λ ())
-- ⊤ ≟t ⊥ = no (λ ())
-- ⊤ ≟t 𝟘 = no (λ ())
-- ⊤ ≟t ⊤ = yes refl
Chan : Set
Chan = ℕ
data Proc⁺ : Set
data Proc⁻ : Set
data Proc⁺ where
_↔_ : Chan → Chan → Proc⁺
ν_∶_∙_∣_ : Chan → Type → Proc⁻ → Proc⁻ → Proc⁺
-- infixl 7 _⟦⟧0
-- inherited types
data Proc⁻ where
-- x[y].(P|Q)
_⟦_⟧_∣_ : Chan → Chan → Proc⁻ → Proc⁻ → Proc⁻
-- x(y).(P|Q)
_⦅_⦆_ : Chan → Chan → Proc⁻ → Proc⁻
-- x[].0
_⟦⟧0 : Chan → Proc⁻
-- x().P
_⦅⦆_ : Chan → Proc⁻ → Proc⁻
-- x.case()
_case : Chan → Proc⁻
-- _[_/_] : Type → Type → TypeVar → Type
-- (‵ P) [ T / X ] with P ≟ X
-- ((‵ P) [ T / X ]) | yes p = T
-- ((‵ P) [ T / X ]) | no ¬p = ‵ P
-- (P ^) [ T / X ] = (P [ T / X ]) ^
-- (P ⨂ Q) [ T / X ] = (P [ T / X ]) ⨂ (Q [ T / X ])
-- (P ⅋ Q) [ T / X ] = (P [ T / X ]) ⅋ (Q [ T / X ])
-- (P ⨁ Q) [ T / X ] = (P [ T / X ]) ⨁ (Q [ T / X ])
-- (P & Q) [ T / X ] = (P [ T / X ]) & (Q [ T / X ])
-- (! P) [ T / X ] = ! (P [ T / X ])
-- (¿ P) [ T / X ] = ¿ (P [ T / X ])
-- ∃[ P ] [ T / zero ] = {! !}
-- ∃[ P ] [ T / suc X ] = {! !}
-- ∀[ P ] [ T / X ] = {! !}
-- 𝟙 [ T / X ] = {! !}
-- ⊥ [ T / X ] = {! !}
-- 𝟘 [ T / X ] = {! !}
-- ⊤ [ T / X ] = {! !}
-- infixl 5 _,_∶_
-- data Session : Set where
-- _,_∶_ : Session → Chan → Type → Session
-- _++_ : Session → Session → Session
-- ∅ : Session
-- infix 4 _⊢↓_
-- infix 4 _⊢↑_
-- data _⊢↑_ : Proc⁺ → Session → Set
-- data _⊢↓_ : Proc⁻ → Session → Set
-- data _⊢↑_ where
-- ⊢↔ : ∀ {w x A}
-- ---------------
-- → w ↔ x ⊢↑ ∅ , w ∶ A ^ , x ∶ A
-- ⊢Cut : ∀ {P Q Γ Δ x A}
-- → P ⊢↓ Γ , x ∶ A
-- → Q ⊢↓ Δ , x ∶ A ^
-- ---------------
-- → ν x ∶ A ∙ P ∣ Q ⊢↑ Γ ++ Δ
-- data _⊢↓_ where
-- ⊢⨂ : ∀ {P Q Γ Δ y x A B}
-- → P ⊢↓ Γ , y ∶ A
-- → Q ⊢↓ Δ , x ∶ B
-- ---------------
-- → x ⟦ y ⟧ P ∣ Q ⊢↓ ∅ , x ∶ 𝟙
-- ⊢⅋ : ∀ {R Θ y x A B}
-- → R ⊢↓ Θ , y ∶ A , x ∶ B
-- ---------------
-- → x ⦅ y ⦆ R ⊢↓ Θ , x ∶ A ⅋ B
-- ⊢𝟏 : ∀ {x}
-- ---------------
-- → x ⟦⟧0 ⊢↓ ∅ , x ∶ 𝟙
-- ⊢⊥ : ∀ {x P Γ}
-- → P ⊢↓ Γ
-- ---------------
-- → x ⦅⦆ P ⊢↓ Γ , x ∶ ⊥
-- ⊢⊤ : ∀ {x Γ}
-- ---------------
-- → x case ⊢↓ Γ , x ∶ ⊤
-- data Result (P : Proc⁺) : Set where
-- known : (Γ : Session) → P ⊢↑ Γ → Result P
-- cntx? : ((Γ : Session) → P ⊢↑ Γ) → Result P
-- type? : ((Γ : Session) → (x : Chan) → (T : Type) → P ⊢↑ Γ , x ∶ T) → Result P
-- wrong : Result P
-- infer : ∀ (P : Proc⁺) → Result P
-- infer (w ↔ x) = type? λ Γ x A → {! ⊢↔ {w} {x} {A} !}
-- infer (ν x ∶ x₁ ∙ x₂ ∣ x₃) = {! !}
-- open import Data.Bool hiding (_≟_)
open import Relation.Binary using (Decidable; DecSetoid)
ChanSetoid : DecSetoid _ _
ChanSetoid = ≡-decSetoid
where
open import Data.Nat.Properties using (≡-decSetoid)
module Example where
open import CP.Session3 ChanSetoid Type
Γ : Session
Γ = (0 ∶ 𝟙) ∷ (1 ∶ 𝟘) ∷ []
Δ : Session
Δ = (1 ∶ 𝟘) ∷ (0 ∶ 𝟙) ∷ []
open import Data.List.Relation.Binary.Subset.DecSetoid typeOfDecSetoid
-- _∋_ : Session → Chan → Bool
-- (Γ , y ∶ A) ∋ x with x ≟ y
-- ... | no ¬p = Γ ∋ x
-- ... | yes p = true
-- (Γ ++ Δ) ∋ x = (Γ ∋ x) ∨ (Δ ∋ x)
-- ∅ ∋ x = false
-- _≈_ : Session → Session → Set
-- Γ ≈ Δ = ∀ x → Γ ∋ x ≡ Δ ∋ x
-- empty : ∀ {Γ x A} → ¬ (∅ ≈ (Γ , x ∶ A))
-- empty {Γ} {x} {A} P with x ≟ x
-- ... | no ¬p = {! !}
-- ... | yes p = {! !}
-- lookup : (Γ : Session) (x : Chan) → Dec (∃[ Δ ] ∃[ A ] (Γ ≈ (Δ , x ∶ A)))
-- lookup (Γ , y ∶ A) x = {! !}
-- lookup (Γ ++ Δ) x with lookup Γ x
-- ... | yes p = {! !}
-- ... | no ¬p = {! !}
-- lookup ∅ x = no (λ where (Γ , A , P) → {! P x !})
-- infer : ∀ (P : Proc⁺) → Dec (∃[ Γ ] (P ⊢↑ Γ))
-- infer' : ∀ (P : Proc⁻) → Dec (∃[ Γ ] (P ⊢↓ Γ))
-- check : ∀ (P : Proc⁻) (Γ : Session) → Dec (P ⊢↓ Γ)
-- infer' (x ⟦ y ⟧ P ∣ Q) = {! !}
-- infer' (x ⦅ y ⦆ P) with infer' P
-- ... | no ¬p = no λ where ((Γ , x ∶ A ⅋ B) , ⊢⅋ P⊢Γ) → ¬p ((Γ , y ∶ A , x ∶ B) , P⊢Γ)
-- ... | yes (Γ , P⊢Γ) = yes ({! !} , (⊢⅋ {! !}))
-- infer' (x ⟦⟧0) = yes (∅ , x ∶ 𝟙 , ⊢𝟏)
-- infer' (x ⦅⦆ P) with infer' P
-- ... | no ¬p = no λ where ((Γ , x ∶ ⊥) , ⊢⊥ P⊢Γ) → ¬p (Γ , P⊢Γ)
-- ... | yes (Γ , P⊢Γ) = yes ((Γ , x ∶ ⊥) , (⊢⊥ P⊢Γ))
-- infer' (x case) = yes (∅ , x ∶ ⊤ , ⊢⊤)
-- infer (w ↔ x) = yes ((∅ , w ∶ {! !} , x ∶ {! !}) , ⊢↔)
-- infer (ν x ∶ A ∙ P ∣ Q) with infer' P | infer' Q
-- ... | no ¬p | no ¬q = {! !}
-- ... | no ¬p | yes q = no (λ where (.(_ ++ _) , ⊢Cut x _) → ¬p {! x !})
-- ... | yes p | no ¬q = {! !}
-- ... | yes (Γ , P⊢Γ) | yes (Δ , Q⊢Δ) = yes ({! !} , ⊢Cut {! P⊢Γ !} {! !})
-- -- = yes ({! !} , {! !})
-- check P Γ = {! !}
-- infixl 4 _∶_∈_
-- data _∶_∈_ : Channel → Type → Session → Set where
-- Z : ∀ {Γ x A}
-- ------------------
-- → x ∶ A ∈ Γ , x ∶ A
-- S_ : ∀ {Γ x y A B}
-- → x ∶ A ∈ Γ
-- ------------------
-- → x ∶ A ∈ Γ , x ∶ A , y ∶ B
-- ¿[_] : Session → Session
-- ¿[ Γ , x ∶ A ] = ¿[ Γ ] , x ∶ ¿ A
-- ¿[ Γ ++ Δ ] = ¿[ Γ ] ++ ¿[ Δ ]
-- ¿[ ∅ ] = ∅
-- infix 4 ⊢_
-- data ⊢_ : Session → Set where
-- Ax : ∀ {A w x}
-- ---------------------------
-- → ⊢ ∅ , w ∶ A ^ , x ∶ A
-- Cut : ∀ {Γ Δ x A}
-- → (P : ⊢ Γ , x ∶ A)
-- → (Q : ⊢ Δ , x ∶ A ^)
-- ---------------------------
-- → ⊢ Γ ++ Δ
-- Times : ∀ {Γ Δ x y A B}
-- → (P : ⊢ Γ , y ∶ A)
-- → (Q : ⊢ Δ , x ∶ B)
-- ---------------------------
-- → ⊢ Γ ++ Δ , x ∶ A ⨂ B
-- Par : ∀ {Θ x y A B}
-- → (R : ⊢ Θ , y ∶ A , x ∶ B)
-- ---------------------------
-- → ⊢ Θ , x ∶ A ⅋ B
-- PlusL : ∀ {Γ x A B}
-- → (P : ⊢ Γ , x ∶ A)
-- ---------------------------
-- → ⊢ Γ , x ∶ A ⨁ B
-- PlusR : ∀ {Γ x A B}
-- → (P : ⊢ Γ , x ∶ B)
-- ---------------------------
-- → ⊢ Γ , x ∶ A ⨁ B
-- With : ∀ {Δ x A B}
-- → (Q : ⊢ Δ , x ∶ A)
-- → (R : ⊢ Δ , x ∶ B)
-- ---------------------------
-- → ⊢ Δ , x ∶ A & B
-- OfCourse : ∀ {Γ x y A}
-- → (P : ⊢ ¿[ Γ ] , y ∶ A)
-- ---------------------------
-- → ⊢ ¿[ Γ ] , x ∶ ! A
-- WhyNot : ∀ {Δ x y A}
-- → (Q : ⊢ Δ , y ∶ A)
-- ---------------------------
-- → ⊢ Δ , x ∶ ¿ A
-- Weaken : ∀ {Δ x A}
-- → (Q : ⊢ Δ)
-- ---------------------------
-- → ⊢ Δ , x ∶ ¿ A
-- Contract : ∀ {Δ x x' A}
-- → (Q : ⊢ Δ , x ∶ ¿ A , x' ∶ ¿ A)
-- ---------------------------
-- → ⊢ Δ , x ∶ ¿ A
-- -- Exist : ∀ {Γ x x' A}
-- -- → (Q : ⊢ Δ , x ∶ ¿ A , x' ∶ ¿ A)
-- -- ---------------------------
-- -- → ⊢ Δ , x ∶ ¿ A | {
"alphanum_fraction": 0.3098250633,
"avg_line_length": 25.6028169014,
"ext": "agda",
"hexsha": "00684b59fa1148528eb62bc101051f3f515a3f21",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/bidirectional",
"max_forks_repo_path": "CP.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/bidirectional",
"max_issues_repo_path": "CP.agda",
"max_line_length": 87,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/bidirectional",
"max_stars_repo_path": "CP.agda",
"max_stars_repo_stars_event_max_datetime": "2020-08-25T14:05:01.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-08-25T07:34:40.000Z",
"num_tokens": 4254,
"size": 9089
} |
-- Currently modules are not allowed in mutual blocks.
-- This might change.
module ModuleInMutual where
mutual
module A where
T : Set -> Set
T A = A
module B where
U : Set -> Set
U B = B
| {
"alphanum_fraction": 0.6273584906,
"avg_line_length": 14.1333333333,
"ext": "agda",
"hexsha": "8bc6293d5057663e4dc171f9fb8f67a43e9faa81",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/ModuleInMutual.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/ModuleInMutual.agda",
"max_line_length": 54,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/ModuleInMutual.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 62,
"size": 212
} |
module lang-text where
open import Data.List
open import Data.String
open import Data.Char
open import Data.Char.Unsafe
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import logic
split : {Σ : Set} → (List Σ → Bool)
→ ( List Σ → Bool) → List Σ → Bool
split x y [] = x [] /\ y []
split x y (h ∷ t) = (x [] /\ y (h ∷ t)) \/
split (λ t1 → x ( h ∷ t1 )) (λ t2 → y t2 ) t
contains : String → String → Bool
contains x y = contains1 (toList x ) ( toList y ) where
contains1 : List Char → List Char → Bool
contains1 [] [] = false
contains1 [] ( cx ∷ ly ) = false
contains1 (cx ∷ lx) [] = true
contains1 (cx ∷ lx ) ( cy ∷ ly ) with cx ≟ cy
... | yes refl = contains1 lx ly
... | no n = false
-- w does not contain the substring ab
ex15a : Set
ex15a = (w : String ) → ¬ (contains w "ab" ≡ true )
-- w does not contains substring baba
ex15b : Set
ex15b = (w : String ) → ¬ (contains w "baba" ≡ true )
-- w contains neither the substing ab nor ba
ex15c : Set
-- w is any string not in a*b*
ex15c = (w : String ) → ( ¬ (contains w "ab" ≡ true ) /\ ( ¬ (contains w "ba" ≡ true )
ex15d : {!!}
ex15d = {!!}
ex15e : {!!}
ex15e = {!!}
ex15f : {!!}
ex15f = {!!}
ex15g : {!!}
ex15g = {!!}
ex15h : {!!}
ex15h = {!!}
| {
"alphanum_fraction": 0.5726495726,
"avg_line_length": 23.4,
"ext": "agda",
"hexsha": "a24a5425f16afffd23b955a93f15d9dee686974c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/automaton-in-agda",
"max_forks_repo_path": "src/lang-text.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/automaton-in-agda",
"max_issues_repo_path": "src/lang-text.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/automaton-in-agda",
"max_stars_repo_path": "src/lang-text.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 457,
"size": 1287
} |
open import Tutorials.Monday-Complete
module Tutorials.Tuesday-Complete where
-----------
-- Pi and Sigma types
-----------
module Product where
-- The open keyword opens a given module in the current namespace
-- By default all of the public names of the module are opened
-- The using keyword limits the imported definitions to those explicitly listed
open Fin
open Vec using (Vec; []; _∷_)
open Simple using (¬_)
variable
P Q : A → Set
-- Pi types: dependent function types
-- For every x of type A, the predicate P x holds
Π : (A : Set) → (Pred A) → Set
Π A P = (x : A) → P x
infix 5 _,_
-- Sigma types: dependent product types, existential types
-- For this x of type A, the predicate P x holds
record Σ (A : Set) (P : Pred A) : Set where
-- In the type P fst, fst refers to a previously introduced field
constructor _,_
field
fst : A
snd : P fst
open Σ public
-- By depending on a boolean we can use pi types to represent product types
Π-× : Set → Set → Set
Π-× A B = Π Bool λ where
true → A
false → B
-- By depending on a boolean we can use sigma types to represent sum types
Σ-⊎ : Set → Set → Set
Σ-⊎ A B = Σ Bool λ where
true → A
false → B
-- Use pi types to recover function types
Π-→ : Set → Set → Set
Π-→ A B = Π A λ where
_ → B
-- Use sigma types to recover product types
Σ-× : Set → Set → Set
Σ-× A B = Σ A λ where
_ → B
infix 5 _×_
_×_ : Set → Set → Set
_×_ = Σ-×
-- 1) If we can transform the witness and
-- 2) transform the predicate as per the transformation on the witness
-- ⇒) then we can transform a sigma type
map : (f : A → B) → (∀ {x} → P x → Q (f x)) → (Σ A P → Σ B Q)
map f g (x , y) = (f x , g y)
-- The syntax keyword introduces notation that can include binders
infix 4 Σ-syntax
Σ-syntax : (A : Set) → (A → Set) → Set
Σ-syntax = Σ
syntax Σ-syntax A (λ x → B) = Σ[ x ∈ A ] B
example₁ : Σ ℕ EvenData
example₁ = 0 , zero
one-is-not-even : ¬ EvenData 1
one-is-not-even ()
example₂ : ¬ Π ℕ EvenData
example₂ f = one-is-not-even (f 1)
¬∘ : Pred A → Pred A
¬∘ P = ¬_ ∘ P
-- These can be proven regardless of A
¬∃⇒∀¬ : ¬ (Σ A P) → Π A (¬∘ P)
¬∃⇒∀¬ f x px = f (x , px)
∃¬⇒¬∀ : Σ A (¬∘ P) → ¬ Π A P
∃¬⇒¬∀ (a , ¬pa) f = ¬pa (f a)
∀¬⇒¬∃ : Π A (¬∘ P) → ¬ Σ A P
∀¬⇒¬∃ f (a , pa) = f a pa
-- Works in classical, not in constructive mathematics
postulate ¬∀⇒∃¬ : ¬ Π A P → Σ A (¬∘ P)
-- Show that ≤ is antisymmetric
≤-≡ : n ≤ m → m ≤ n → n ≡ m
≤-≡ z≤n z≤n = refl
≤-≡ (s≤s x) (s≤s y) = cong suc (≤-≡ x y)
-- By using n ≤ m instead of Fin m we can mention n in the output
take : Vec A m → n ≤ m → Vec A n
take xs z≤n = []
take (x ∷ xs) (s≤s lte) = x ∷ take xs lte
Fin-to-≤ : (i : Fin m) → to-ℕ i < m
Fin-to-≤ zero = s≤s z≤n
Fin-to-≤ (suc i) = s≤s (Fin-to-≤ i)
-- Proof combining sigma types and equality
≤-to-Fin : n < m → Fin m
≤-to-Fin (s≤s z≤n) = zero
≤-to-Fin (s≤s (s≤s i)) = suc (≤-to-Fin (s≤s i))
Fin-≤-inv : (i : Fin m) → ≤-to-Fin (Fin-to-≤ i) ≡ i
Fin-≤-inv zero = refl
Fin-≤-inv (suc zero) = refl
Fin-≤-inv (suc (suc i)) = cong suc (Fin-≤-inv (suc i))
≤-Fin-inv : (lt : Σ[ n ∈ ℕ ] n < m)
→ (to-ℕ (≤-to-Fin (snd lt)) , Fin-to-≤ (≤-to-Fin (snd lt))) ≡ lt
≤-Fin-inv (.zero , s≤s z≤n) = refl
≤-Fin-inv (.(suc _) , s≤s (s≤s i)) =
cong (map suc s≤s) (≤-Fin-inv (_ , s≤s i))
| {
"alphanum_fraction": 0.5461649783,
"avg_line_length": 26.5769230769,
"ext": "agda",
"hexsha": "b40ee744f2aa1c26f6ee9a6a6943b29dde109ecc",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-11-24T10:50:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-23T08:50:13.000Z",
"max_forks_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "poncev/agda-bcam",
"max_forks_repo_path": "Tutorials/Tuesday-Complete.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "poncev/agda-bcam",
"max_issues_repo_path": "Tutorials/Tuesday-Complete.agda",
"max_line_length": 81,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "poncev/agda-bcam",
"max_stars_repo_path": "Tutorials/Tuesday-Complete.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-03T22:53:51.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-09-23T17:59:21.000Z",
"num_tokens": 1419,
"size": 3455
} |
{-# OPTIONS --two-level --no-sized-types --no-guardedness #-}
module Issue2487.e where
postulate admit : {A : Set} -> A
| {
"alphanum_fraction": 0.6611570248,
"avg_line_length": 24.2,
"ext": "agda",
"hexsha": "c85052c9281c60c5d9e70ee789ead732ca9dccdd",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Fail/Issue2487/e.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue2487/e.agda",
"max_line_length": 61,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue2487/e.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 34,
"size": 121
} |
module Type.Size.Finite where
import Lvl
open import Functional
open import Logic
open import Logic.Predicate
open import Numeral.Finite
open import Numeral.Finite.Equiv
open import Numeral.Natural
open import Structure.Setoid
open import Type
open import Type.Size
private variable ℓ ℓₑ : Lvl.Level
-- A finitely enumerable type is a type where its inhabitants are finitely enumerable (alternatively: listable, able to collect to a finite list (a list containing all inhabitants is constructible)).
-- There is a finite upper bound on the number of inhabitants in the sense that the inverse of a mapping from a type of finite numbers is a function (TODO: Not sure if the implementation actually states this. Maybe Invertible should be used instead of Surjective?).
-- Also called: Finitely indexed.
FinitelyEnumerable : (T : Type{ℓ}) → ⦃ equiv : Equiv{ℓₑ}(T) ⦄ → Stmt
FinitelyEnumerable(T) = ∃(n ↦ 𝕟(n) ≽ T)
-- A finite type have a finite number of inhabitants, and this number is constructable.
Finite : (T : Type{ℓ}) → ⦃ equiv : Equiv{ℓₑ}(T) ⦄ → Stmt
Finite(T) = ∃(n ↦ 𝕟(n) ≍ T)
-- Cardinality of a finite type in the form of a number. Number of inhabitants of a type.
-- The witness of Finite is the exact number of inhabitants of the type (the count).
#_ : (T : Type{ℓ}) → ⦃ equiv : Equiv{ℓₑ}(T) ⦄ → ⦃ fin : Finite(T) ⦄ → ℕ
#_ _ ⦃ fin = [∃]-intro(n) ⦄ = n
enum : ∀{T : Type{ℓ}} → ⦃ equiv : Equiv{ℓₑ}(T) ⦄ → ⦃ fin : Finite(T) ⦄ → 𝕟(# T) → T
enum ⦃ fin = [∃]-intro _ ⦃ [∃]-intro f ⦄ ⦄ = f
module Finite where
import Data.Either as Type
import Data.Either.Equiv as Either
import Data.Tuple as Type
import Data.Tuple.Equiv as Tuple
open import Numeral.Finite.Sequence
open import Structure.Function.Domain
import Numeral.Natural.Oper as ℕ
private variable A B : Type{ℓ}
private variable ⦃ equiv-A ⦄ : Equiv{ℓₑ}(A)
private variable ⦃ equiv-B ⦄ : Equiv{ℓₑ}(B)
private variable ⦃ equiv-A‖B ⦄ : Equiv{ℓₑ}(A Type.‖ B)
private variable ⦃ equiv-A⨯B ⦄ : Equiv{ℓₑ}(A Type.⨯ B)
_+_ : ⦃ ext : Either.Extensionality ⦃ equiv-A ⦄ ⦃ equiv-B ⦄ (equiv-A‖B) ⦄ → Finite(A) ⦃ equiv-A ⦄ → Finite(B) ⦃ equiv-B ⦄ → Finite(A Type.‖ B) ⦃ equiv-A‖B ⦄
_+_ ([∃]-intro a ⦃ [∃]-intro af ⦄) ([∃]-intro b ⦃ [∃]-intro bf ⦄) = [∃]-intro (a ℕ.+ b) ⦃ [∃]-intro (interleave af bf) ⦃ interleave-bijective ⦄ ⦄
-- TODO: Below
_⋅_ : ⦃ ext : Tuple.Extensionality ⦃ equiv-A ⦄ ⦃ equiv-B ⦄ (equiv-A⨯B) ⦄ → Finite(A) ⦃ equiv-A ⦄ → Finite(B) ⦃ equiv-B ⦄ → Finite(A Type.⨯ B) ⦃ equiv-A⨯B ⦄
_⋅_ ([∃]-intro a ⦃ [∃]-intro af ⦄) ([∃]-intro b ⦃ [∃]-intro bf ⦄) = [∃]-intro (a ℕ.⋅ b) ⦃ [∃]-intro (f af bf) ⦃ p ⦄ ⦄ where
postulate f : (𝕟(a) → _) → (𝕟(b) → _) → 𝕟(a ℕ.⋅ b) → (_ Type.⨯ _)
postulate p : Bijective(f af bf)
{-
_^_ : Finite(A) → Finite(B) → Finite(A ← B)
_^_ ([∃]-intro a ⦃ [∃]-intro af ⦄) ([∃]-intro b ⦃ [∃]-intro bf ⦄) = [∃]-intro (a ℕ.^ b) ⦃ [∃]-intro (f af bf) ⦃ p ⦄ ⦄ where
postulate f : (𝕟(a) → _) → (𝕟(b) → _) → 𝕟(a ℕ.^ b) → (_ ← _)
postulate p : Bijective(f af bf)
-}
| {
"alphanum_fraction": 0.6235177866,
"avg_line_length": 47.4375,
"ext": "agda",
"hexsha": "74f337aa6ba6c90afeae72e8cd34dc9d588c8daa",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Type/Size/Finite.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Type/Size/Finite.agda",
"max_line_length": 265,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Type/Size/Finite.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 1232,
"size": 3036
} |
module Interior where
open import Basics
open import Ix
open import All
open import Cutting
module INTERIOR {I}(C : I |> I) where
open _|>_ C
data Interior (P : I -> Set)(i : I) : Set where
tile : P i -> Interior P i
<_> : Cutting C (Interior P) i -> Interior P i
ifold : forall {P Q} ->
[ P -:> Q ] ->
[ Cutting C Q -:> Q ] ->
[ Interior P -:> Q ]
ifolds : forall {P Q} ->
[ P -:> Q ] ->
[ Cutting C Q -:> Q ] ->
[ All (Interior P) -:> All Q ]
ifold pq cq i (tile p) = pq i p
ifold pq cq i < c 8>< ps > = cq i (c 8>< ifolds pq cq _ ps)
ifolds pq cq [] <> = <>
ifolds pq cq (i ,- is) (x , xs) = ifold pq cq i x , ifolds pq cq is xs
-- tile : [ P -:> Interior P ]
extend : forall {P Q} ->
[ P -:> Interior Q ] ->
[ Interior P -:> Interior Q ]
extend k = ifold k (\ i x -> < x >)
-- and we have a monad, not in Set, but in I -> Set
open INTERIOR NatCut
{-
foo : Interior (\ n -> n == 3) 12
foo = < ((3 , 9 , refl _)) 8>< (tile (refl _) , {!!} , <>) >
-}
| {
"alphanum_fraction": 0.48,
"avg_line_length": 24.4318181818,
"ext": "agda",
"hexsha": "1fa158f0cff4b8da58d304d76db7e6caf496094c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pigworker/InteriorDesign",
"max_forks_repo_path": "Interior.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pigworker/InteriorDesign",
"max_issues_repo_path": "Interior.agda",
"max_line_length": 72,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "454cdd18f56db0b0d1643a1fcf36951b5ece395c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pigworker/InteriorDesign",
"max_stars_repo_path": "Interior.agda",
"max_stars_repo_stars_event_max_datetime": "2018-07-31T02:00:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-18T15:25:39.000Z",
"num_tokens": 368,
"size": 1075
} |
-- Andreas, 2021-12-22, issue #5706 reported by Trebor-Huang
-- In Agda <= 2.6.2.1, Int overflow can be exploited.
-- Basically just a modified version of Russell's paradox found at
-- http://liamoc.net/posts/2015-09-10-girards-paradox.html.
-- -- This 64bit Int overflow got us Set:Set.
-- WTF : Set₀
-- WTF = Set₁₈₄₄₆₇₄₄₀₇₃₇₀₉₅₅₁₆₁₅
-- -- 18446744073709551615 = 2^64 - 1
-- Some preliminaries, just to avoid any library imports:
data _≡_ {ℓ : _} {A : Set ℓ} : A → A → Set where
refl : ∀ {a} → a ≡ a
record ∃ {A : Set} (P : A → Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : P proj₁
open ∃
data ⊥ : Set where
-- The rest follows the linked development of Russell's paradox.
-- Naive sets (tree representation), accepted with --type-in-type.
data SET : Set where
set : (X : Set₁₈₄₄₆₇₄₄₀₇₃₇₀₉₅₅₁₆₁₅) → (X → SET) → SET
-- Elementhood
_∈_ : SET → SET → Set
a ∈ set X f = ∃ λ x → a ≡ f x
_∉_ : SET → SET → Set
a ∉ b = (a ∈ b) → ⊥
-- The set Δ of sets that do not contain themselves.
Δ : SET
Δ = set (∃ λ s → s ∉ s) proj₁
-- Any member of Δ does not contain itself.
x∈Δ→x∉x : ∀ {X} → X ∈ Δ → X ∉ X
x∈Δ→x∉x ((Y , Y∉Y) , refl) = Y∉Y
-- Δ does not contain itself.
Δ∉Δ : Δ ∉ Δ
Δ∉Δ Δ∈Δ = x∈Δ→x∉x Δ∈Δ Δ∈Δ
-- Any set that does not contain itself lives in Δ.
x∉x→x∈Δ : ∀ {X} → X ∉ X → X ∈ Δ
x∉x→x∈Δ {X} X∉X = (X , X∉X) , refl
-- So Δ must live in Δ, which is absurd.
falso : ⊥
falso = Δ∉Δ (x∉x→x∈Δ Δ∉Δ)
| {
"alphanum_fraction": 0.5946317963,
"avg_line_length": 22.3538461538,
"ext": "agda",
"hexsha": "7c5dbe7ecc603c9d74a30aa96135e0440177f4d6",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "Seanpm2001-Agda-lang/agda",
"max_forks_repo_path": "test/Fail/Issue5706.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "Seanpm2001-Agda-lang/agda",
"max_issues_repo_path": "test/Fail/Issue5706.agda",
"max_line_length": 66,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Fail/Issue5706.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 658,
"size": 1453
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Construction.Elements where
-- Category of Elements -- given a functor into Sets, construct the category of elements 'above' each object
-- see https://ncatlab.org/nlab/show/category+of+elements
open import Level
open import Data.Product using (Σ; _,_; Σ-syntax; proj₁; proj₂; map)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans; cong)
open import Function hiding (_∘_) renaming (id to idf)
open import Categories.Category using (Category)
open import Categories.Functor hiding (id)
open import Categories.Category.Instance.Sets
open import Categories.Category.Instance.Cats
open import Categories.Category.Construction.Functors
open import Categories.NaturalTransformation.NaturalIsomorphism hiding (refl; sym; trans)
open import Categories.NaturalTransformation hiding (id)
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ e o′ : Level
-- the first, most explicit definition is taken as 'canonical'.
Elements : {C : Category o ℓ e} → Functor C (Sets o′) → Category (o ⊔ o′) (ℓ ⊔ o′) e
Elements {C = C} F = record
{ Obj = Σ Obj F₀
; _⇒_ = λ { (c , x) (c′ , x′) → Σ (c ⇒ c′) (λ f → F₁ f x ≡ x′) }
; _≈_ = λ p q → proj₁ p ≈ proj₁ q
; id = id , identity
; _∘_ = λ { (f , Ff≡) (g , Fg≡) → f ∘ g , trans homomorphism (trans (cong (F₁ f) Fg≡) Ff≡)}
; assoc = assoc
; sym-assoc = sym-assoc
; identityˡ = identityˡ
; identityʳ = identityʳ
; identity² = identity²
; equiv = record { refl = Equiv.refl ; sym = Equiv.sym ; trans = Equiv.trans }
; ∘-resp-≈ = ∘-resp-≈
}
where
open Category C
open Functor F
-- This induces a functor. It is largely uninteresting as it is as close to 'strict'
-- as things get in this setting.
El : {C : Category o ℓ e} → Functor (Functors C (Sets o′)) (Cats (o ⊔ o′) (ℓ ⊔ o′) e)
El {C = C} = record
{ F₀ = Elements
; F₁ = λ A⇒B → record
{ F₀ = map idf (η A⇒B _)
; F₁ = map idf λ {f} eq → trans (sym $ commute A⇒B f) (cong (η A⇒B _) eq)
; identity = Equiv.refl
; homomorphism = Equiv.refl
; F-resp-≈ = idf
}
; identity = λ {P} → record
{ F⇒G = record
{ η = λ X → id , identity P
; commute = λ _ → MR.id-comm-sym C
; sym-commute = λ _ → MR.id-comm C
}
; F⇐G = record
{ η = λ X → id , identity P
; commute = λ _ → MR.id-comm-sym C
; sym-commute = λ _ → MR.id-comm C
}
; iso = λ X → record { isoˡ = identityˡ ; isoʳ = identityʳ } }
; homomorphism = λ {X₁} {Y₁} {Z₁} → record
{ F⇒G = record
{ η = λ X → id , identity Z₁
; commute = λ _ → MR.id-comm-sym C
; sym-commute = λ _ → MR.id-comm C
}
; F⇐G = record
{ η = λ X → id , identity Z₁
; commute = λ _ → MR.id-comm-sym C
; sym-commute = λ _ → MR.id-comm C
}
; iso = λ X → record { isoˡ = identityˡ ; isoʳ = identityʳ }
}
; F-resp-≈ = λ {_} {B₁} f≈g → record
{ F⇒G = record
{ η = λ _ → id , trans (identity B₁) f≈g
; commute = λ _ → MR.id-comm-sym C
; sym-commute = λ _ → MR.id-comm C
}
; F⇐G = record
{ η = λ _ → id , trans (identity B₁) (sym f≈g)
; commute = λ _ → MR.id-comm-sym C
; sym-commute = λ _ → MR.id-comm C
}
; iso = λ X → record { isoˡ = identityˡ ; isoʳ = identityʳ } }
}
where
open Category C
open Functor
open NaturalTransformation
-- But there are all sorts of interesting alternate definitions
-- note how this one is WAY less level polymorphic than the above!
-- it looks like it contains more information... but not really either.
{- Unfinished because it is super tedious and not informative!
module Alternate-Pullback {C : Category (suc o) o o} (F : Functor C (Sets o)) where
open import Categories.Category.Instance.PointedSets
open import Categories.Category.Instance.Cats
open import Categories.Diagram.Pullback (Cats (suc o) o o)
open import Categories.Category.Product using (_※_; πˡ)
open Category C
open Functor F
Pb : Pullback F Underlying
Pb = record
{ P = Elements F
; p₁ = record
{ F₀ = proj₁
; F₁ = proj₁
; identity = Equiv.refl
; homomorphism = Equiv.refl
; F-resp-≈ = idf
}
; p₂ = record
{ F₀ = map F₀ idf
; F₁ = map F₁ idf
; identity = λ x → identity {_} {x}
; homomorphism = λ _ → homomorphism
; F-resp-≈ = λ f≈g _ → F-resp-≈ f≈g
}
; commute = record
{ F⇒G = record { η = λ _ → idf ; commute = λ _ → refl }
; F⇐G = record { η = λ _ → idf ; commute = λ _ → refl }
; iso = λ X → record { isoˡ = refl ; isoʳ = refl }
}
; universal = λ {A} {h₁} {h₂} NI → record
{ F₀ = λ X → Functor.F₀ h₁ X , η (F⇐G NI) X (proj₂ $ Functor.F₀ h₂ X)
; F₁ = λ f → Functor.F₁ h₁ f ,
trans (sym $ commute (F⇐G NI) f) (cong (η (F⇐G NI) _) (proj₂ $ Functor.F₁ h₂ f))
; identity = Functor.identity h₁
; homomorphism = Functor.homomorphism h₁
; F-resp-≈ = Functor.F-resp-≈ h₁
}
; unique = λ πˡ∘i≃h₁ map∘i≃h₂ → record
{ F⇒G = record { η = λ X → {!!} ; commute = {!!} }
; F⇐G = record { η = {!!} ; commute = {!!} }
; iso = λ X → record { isoˡ = {!!} ; isoʳ = {!!} }
}
; p₁∘universal≈h₁ = {!!}
; p₂∘universal≈h₂ = {!!}
}
where
open NaturalTransformation
open NaturalIsomorphism
-}
| {
"alphanum_fraction": 0.5728881591,
"avg_line_length": 35.3612903226,
"ext": "agda",
"hexsha": "24d82943d6f29d7c3f6285fa6355cf31802e3cef",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Construction/Elements.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Construction/Elements.agda",
"max_line_length": 108,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Construction/Elements.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 1909,
"size": 5481
} |
{-# OPTIONS --without-K --rewriting #-}
open import Base using (Type; Type₀; _==_; idp)
module PathInductionSimplified where
{-<pathinduction>-}
record Coh {i} (A : Type i) : Type i where
field & : A
open Coh public
instance
J : ∀ {i j} {A : Type i} {a : A} {B : (a' : A) → a == a' → Type j}
→ Coh (B a idp)
→ Coh ({a' : A} (p : a == a') → B a' p)
& (J d) idp = & d
idp-Coh : ∀ {i} {A : Type i} {a : A} → Coh (a == a)
& idp-Coh = idp
path-induction : ∀ {i} {A : Type i} {{a : A}} → A
path-induction {{a}} = a
composition : ∀ {i} {A : Type i} {a : A}
→ Coh ({b : A} (p : a == b) {c : A} (q : b == c) → a == c)
composition = path-induction
postulate
A : Type₀
a b c : A
p : a == b
q : b == c
pq : a == c
pq = & composition p q
{-</>-}
| {
"alphanum_fraction": 0.4825355757,
"avg_line_length": 20.8918918919,
"ext": "agda",
"hexsha": "f57fd67c6140b08d6294649a7b0a07a95350f21b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guillaumebrunerie/JamesConstruction",
"max_forks_repo_path": "PathInductionSimplified.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "guillaumebrunerie/JamesConstruction",
"max_issues_repo_path": "PathInductionSimplified.agda",
"max_line_length": 68,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "89fbc29473d2d1ed1a45c3c0e56288cdcf77050b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guillaumebrunerie/JamesConstruction",
"max_stars_repo_path": "PathInductionSimplified.agda",
"max_stars_repo_stars_event_max_datetime": "2018-11-16T22:10:16.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-07T04:34:52.000Z",
"num_tokens": 319,
"size": 773
} |
open import Data.Bool using (Bool; false; true; _∧_)
open import Data.Maybe
open import Data.Nat
open import Data.Nat.Properties --using (_≟_; _<?_)
open import Data.Product
open import Relation.Binary.PropositionalEquality --using (_≡_; refl)
open import Relation.Nullary --using (Dec; yes; no)
--open import Relation.Nullary.Decidable --using (from-yes)
_ : Dec (0 ≡ 2)
_ = no (λ())
--_ = 0 ≟ 2
--_ = 0 ≟ 3
_ : Dec (2 ≡ 2)
_ = yes refl
fun : ℕ → ℕ → Maybe ℕ
fun x y with x <? y
... | yes _ = nothing
... | no _ = just y
_ : fun 3 5 ≡ nothing
_ = refl
_ : fun 3 2 ≡ just 2
_ = refl
--prop-:S : ∀ (x y)
-- → fun x y ≡ nothing
-- → x < y
--prop-:S 0 0 ()
--prop-:S 0 (suc y) refl = s≤s z≤n
--prop-:S (suc x) 0 ()
--prop-:S (suc x) (suc y) funsxsy≡nothing = s≤s (prop-:S x y ?)
--prop : ∀ (x y)
-- → fun x y ≡ nothing
-- → x < y
--prop x y with fun x y
--... | just _ = λ()
--... | nothing = λ{refl → ?} -- from-yes (x <? y)}
--
---- This fails because the pattern matching is incomplete,
---- but it shouldn't. There are no other cases
--prop' : ∀ (x y)
-- → fun x y ≡ nothing
-- → x < y
--prop' x y with fun x y | x <? y
--... | nothing | yes x<y = λ{refl → x<y}
--... | just _ | no _ = λ()
--... | _ | _ = ?
-- From: https://stackoverflow.com/a/63119870/1744344
prop : ∀ x y → fun x y ≡ nothing → x < y
prop x y with x <? y
... | yes p = λ _ → p
prop-old : ∀ x y → fun x y ≡ nothing → x < y
prop-old x y _ with x <? y
prop-old _ _ refl | yes p = p
prop-old _ _ () | no _
data Comp : Set where
greater equal less : Comp
compare' : ℕ → ℕ → Comp
compare' x y with x <ᵇ y
... | false with y <ᵇ x
... | false = equal
... | true = greater
compare' x y | true = less
--fun2 : Maybe (ℕ × ℕ) → Maybe ℕ
--fun2 pair with pair
--... | just (x , y) with x <? y
--... | just (x , y) | yes _ = nothing
--... | just (x , y) | no _ = just y
--fun2 _ | nothing = nothing
prop-comp : ∀ x y
→ compare' x y ≡ greater
→ (y <ᵇ x) ≡ true
prop-comp x y _ with x <ᵇ y
... | false with y <ᵇ x
... | true = refl
--same as
--prop-comp x y _ | false with y <ᵇ x
--prop-comp x y _ | false | true = refl
prop-comp← : ∀ x y
→ (y <ᵇ x) ≡ true
→ compare' x y ≡ greater
prop-comp← x y _ with x <ᵇ y
prop-comp← x y _ | true with y <ᵇ x
prop-comp← _ _ _ | true | true = ? -- This impossible!
prop-comp← _ _ () | true | false
prop-comp← x y _ | false with y <ᵇ x
prop-comp← _ _ _ | false | true = refl
--prop-comp← x y () | false | false
prop-new← : ∀ x y
→ (x <ᵇ y) ≡ false
→ (y <ᵇ x) ≡ false
→ compare' x y ≡ equal
--Why is this not possible?
--prop-new← x y _ with x <ᵇ y | y <ᵇ x
--... | false | false = refl
prop-new← x y _ _ with x <ᵇ y
... | false with y <ᵇ x
... | false = refl
--a : inspect 3 2
--a = ?
| {
"alphanum_fraction": 0.5212840195,
"avg_line_length": 24.9217391304,
"ext": "agda",
"hexsha": "053b4ae2c9e7ff82f06b56f6da7a9b0383c9124c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "helq/old_code",
"max_forks_repo_path": "proglangs-learning/Agda/general-exercises/with-abstraction-proofs.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_issues_repo_issues_event_max_datetime": "2021-06-07T15:39:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-10T19:20:21.000Z",
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "helq/old_code",
"max_issues_repo_path": "proglangs-learning/Agda/general-exercises/with-abstraction-proofs.agda",
"max_line_length": 69,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "helq/old_code",
"max_stars_repo_path": "proglangs-learning/Agda/general-exercises/with-abstraction-proofs.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1090,
"size": 2866
} |
{-# OPTIONS --without-K #-}
open import library.Basics hiding (Type ; Σ ; S)
open import library.types.Sigma
open import library.types.Bool
open import Sec2preliminaries
open import Sec3hedberg
open import Sec4hasConstToSplit
open import Sec5factorConst
open import Sec6populatedness
module Sec7taboos where
-- Subsection 7.1
-- Lemma 7.1
hasConst-family-dec : {X : Type} → (x₁ x₂ : X) → ((x : X) → hasConst ((x₁ == x) + (x₂ == x))) → (x₁ == x₂) + ¬(x₁ == x₂)
hasConst-family-dec {X} x₁ x₂ hasConst-fam = solution where
f₋ : (x : X) → (x₁ == x) + (x₂ == x) → (x₁ == x) + (x₂ == x)
f₋ x = fst (hasConst-fam x)
E₋ : X → Type
E₋ x = fix (f₋ x)
E : Type
E = Σ X λ x → (E₋ x)
E-fst-determines-eq : (e₁ e₂ : E) → (fst e₁ == fst e₂) → e₁ == e₂
E-fst-determines-eq e₁ e₂ p = second-comp-triv (λ x → fixed-point (f₋ x) (snd (hasConst-fam x))) _ _ p
r : Bool → E
r true = x₁ , to-fix (f₋ x₁) (snd (hasConst-fam x₁)) (inl idp)
r false = x₂ , to-fix (f₋ x₂) (snd (hasConst-fam x₂)) (inr idp)
about-r : (r true == r false) ↔ (x₁ == x₂)
about-r = (λ p → ap fst p) , (λ p → E-fst-determines-eq _ _ p)
s : E → Bool
s (_ , inl _ , _) = true
s (_ , inr _ , _) = false
s-section-of-r : (e : E) → r(s e) == e
s-section-of-r (x , inl p , q) = E-fst-determines-eq _ _ p
s-section-of-r (x , inr p , q) = E-fst-determines-eq _ _ p
about-s : (e₁ e₂ : E) → (s e₁ == s e₂) ↔ (e₁ == e₂)
about-s e₁ e₂ = one , two where
one : (s e₁ == s e₂) → (e₁ == e₂)
one p =
e₁ =⟨ ! (s-section-of-r e₁) ⟩
r(s(e₁)) =⟨ ap r p ⟩
r(s(e₂)) =⟨ s-section-of-r e₂ ⟩
e₂ ∎
two : (e₁ == e₂) → (s e₁ == s e₂)
two p = ap s p
combine : (s (r true) == s (r false)) ↔ (x₁ == x₂)
combine = (about-s _ _) ◎ about-r
check-bool : (s (r true) == s (r false)) + ¬(s (r true) == s (r false))
check-bool = Bool-has-dec-eq _ _
solution : (x₁ == x₂) + ¬(x₁ == x₂)
solution with check-bool
solution | inl p = inl (fst combine p)
solution | inr np = inr (λ p → np (snd combine p))
-- The assumption that we are discussing:
all-hasConst : Type₁
all-hasConst = (X : Type) → hasConst X
-- Theorem 7.2
all-hasConst→dec-eq : all-hasConst → (X : Type) → has-dec-eq X
all-hasConst→dec-eq ahc X x₁ x₂ = hasConst-family-dec x₁ x₂ (λ x → ahc _)
-- Theorem 7.3
module functional-subrelation (ac : all-hasConst) (X : Type) (R : X × X → Type) where
all-sets : (Y : Type) → is-set Y
all-sets Y = pathHasConst→isSet (λ y₁ y₂ → ac _)
R₋ : (x : X) → Type
R₋ x = Σ X λ y → R(x , y)
k : (x : X) → (R₋ x) → (R₋ x)
k x = fst (ac _)
kc : (x : X) → const (k x)
kc x = snd (ac _)
S : X × X → Type
S (x , y) = Σ (R(x , y)) λ a →
(y , a) == k x (y , a)
-- the relation S
S₋ : (x : X) → Type
S₋ x = Σ X λ y → S(x , y)
-- fix kₓ is equivalent to Sₓ
-- This is just Σ-assoc. We try to make it more readable by adding some (trivial) steps.
fixk-S : (x : X) → (fix (k x)) ≃ S₋ x
fixk-S x =
(fix (k x)) ≃⟨ ide _ ⟩
(Σ (Σ X λ y → R(x , y)) λ a → a == k x a) ≃⟨ Σ-assoc ⟩
(Σ X λ y → Σ (R(x , y)) λ r → (y , r) == k x (y , r)) ≃⟨ ide _ ⟩
(S₋ x) ≃∎
-- claim (0)
subrelation : (x y : X) → S(x , y) → R(x , y)
subrelation x y (r , _) = r
-- claim (1)
prop-Sx : (x : X) → is-prop (S₋ x)
prop-Sx x = equiv-preserves-level {A = fix (k x)} {B = (S₋ x)} (fixk-S x) (fixed-point _ (kc x))
-- claim (2)
same-domain : (x : X) → (R₋ x) ↔ (S₋ x)
same-domain x = rs , sr where
rs : (R₋ x) → (S₋ x)
rs a = –> (fixk-S x) (to-fix (k x) (kc x) a)
sr : (S₋ x) → (R₋ x)
sr (y , r , _) = y , r
-- claim (3)
prop-S : (x y : X) → is-prop (S (x , y))
prop-S x y = all-paths-is-prop all-paths where
all-paths : (s₁ s₂ : S(x , y)) → s₁ == s₂
all-paths s₁ s₂ = ss where
yss : (y , s₁) == (y , s₂)
yss = prop-has-all-paths (prop-Sx x) _ _
ss : s₁ == s₂
ss = set-lemma (all-sets _) y s₁ s₂ yss
-- intermediate definition
-- see the caveat about the notion 'epimorphism' in the article
is-split-epimorphism : {U V : Type} → (U → V) → Type
is-split-epimorphism {U} {V} e = Σ (V → U) λ s → (v : V) → e (s v) == v
is-epimorphism : {U V : Type} → (U → V) → Type₁
is-epimorphism {U} {V} e = (W : Type) → (f g : V → W) → ((u : U) → f (e u) == g (e u)) → (v : V) → f v == g v
-- Lemma 7.4
path-trunc-epi→set : {Y : Type} → ((y₁ y₂ : Y) → is-epimorphism (∣_∣ {X = y₁ == y₂})) → is-set Y
path-trunc-epi→set {Y} path-epi = reminder special-case where
f : (y₁ y₂ : Y) → Trunc (y₁ == y₂) → Y
f y₁ _ _ = y₁
g : (y₁ y₂ : Y) → Trunc (y₁ == y₂) → Y
g _ y₂ _ = y₂
special-case : (y₁ y₂ : Y) → Trunc (y₁ == y₂) → y₁ == y₂
special-case y₁ y₂ = path-epi y₁ y₂ Y (f y₁ y₂) (g y₁ y₂) (idf _)
reminder : hseparated Y → is-set Y
reminder = fst set-characterizations ∘ snd (snd set-characterizations)
-- Theorem 7.5 (1)
all-split→all-deceq : ((X : Type) → is-split-epimorphism (∣_∣ {X = X})) → (X : Type) → has-dec-eq X
all-split→all-deceq all-split = all-hasConst→dec-eq ac where
ac : (X : Type) → hasConst X
ac X = snd hasConst↔splitSup (fst (all-split X))
-- Theorem 7.5 (2)
all-epi→all-set : ((X : Type) → is-epimorphism (∣_∣ {X = X})) → (X : Type) → is-set X
all-epi→all-set all-epi X = path-trunc-epi→set (λ y₁ y₂ → all-epi (y₁ == y₂))
-- Subsection 7.2
-- Lemma 7.6, first proof
pop-splitSup-1 : {X : Type} → Pop (splitSup X)
pop-splitSup-1 {X} f c = to-fix f c (hasConst→splitSup (g , gc)) where
g : X → X
g x = f (λ _ → x) ∣ x ∣
gc : const g
gc x₁ x₂ =
g x₁ =⟨ idp ⟩
f (λ _ → x₁) ∣ x₁ ∣ =⟨ ap (λ k → k ∣ x₁ ∣) (c (λ _ → x₁) (λ _ → x₂)) ⟩
f (λ _ → x₂) ∣ x₁ ∣ =⟨ ap (f (λ _ → x₂)) (prop-has-all-paths (h-tr X) ∣ x₁ ∣ ∣ x₂ ∣) ⟩
f (λ _ → x₂) ∣ x₂ ∣ =⟨ idp ⟩
g x₂ ∎
-- Lemma 7.6, second proof
pop-splitSup-2 : {X : Type} → Pop (splitSup X)
pop-splitSup-2 {X} = snd (pop-alt₂ {splitSup X}) get-P where
get-P : (P : Type) → is-prop P → splitSup X ↔ P → P
get-P P pp (hstp , phst) = hstp free-hst where
xp : X → P
xp x = hstp (λ _ → x)
zp : Trunc X → P
zp = rec pp xp
free-hst : splitSup X
free-hst z = phst (zp z) z
-- Lemma 7.6, third proof
pop-splitSup-3 : {X : Type} → Pop (splitSup X)
pop-splitSup-3 {X} = snd pop-alt translation where
translation-aux : splitSup (splitSup X) → splitSup X
translation-aux = λ hsthst z → hsthst (trunc-functorial {X = X} {Y = splitSup X} (λ x _ → x) z) z
translation : Trunc (splitSup (splitSup X)) → Trunc (splitSup X)
translation = trunc-functorial translation-aux
-- Theorem 7.7
module thm77 where
One = (X : Type) → Pop X → Trunc X
Two = (X : Type) → Trunc (splitSup X)
Three = (P : Type) → is-prop P → (Y : P → Type) → ((p : P) → Trunc (Y p)) → Trunc ((p : P) → Y p)
Four = (X Y : Type) → (X → Y) → (Pop X → Pop Y)
One→Two : One → Two
One→Two poptr X = poptr (splitSup X) pop-splitSup-1
Two→One : Two → One
Two→One trhst X pop = fst pop-alt pop (trhst X)
One→Four : One → Four
One→Four poptr X Y f = Trunc→Pop ∘ (trunc-functorial f) ∘ (poptr X)
Four→One : Four → One
Four→One funct X px = snd (prop→hasConst×PopX→X (h-tr _)) pz where
pz : Pop (Trunc X)
pz = funct X (Trunc X) ∣_∣ px
-- only very slightly different to the proof in the article
One→Three : One → Three
One→Three poptr P pp Y = λ py → poptr _ (snd pop-alt' (λ hst p₀ → hst (contr-trick p₀ py) p₀)) where
contr-trick : (p₀ : P) → ((p : P) → Trunc (Y p)) → Trunc ((p : P) → Y p)
contr-trick p₀ py = rec {X = Y p₀}
{P = Trunc ((p : P) → Y p)}
(h-tr _)
(λ y₀ → ∣ <– (thm55aux.neutral-contr-exp {P = P} {Y = Y} pp p₀) y₀ ∣) (py p₀)
Three→Two : Three → Two
Three→Two proj X = proj (Trunc X) (h-tr _) (λ _ → X) (idf _)
-- Subsection 7.3
-- Some very simple lemmata
-- If P is a proposition, so is P + ¬ P
dec-is-prop : {P : Type} → (Funext {X = P} {Y = Empty}) → is-prop P → is-prop (P + ¬ P)
dec-is-prop {P} fext pp = all-paths-is-prop (λ { (inl p₁) (inl p₂) → ap inl (prop-has-all-paths pp _ _) ;
(inl p₁) (inr np₂) → Empty-elim {A = λ _ → inl p₁ == inr np₂} (np₂ p₁) ;
(inr np₁) (inl p₂) → Empty-elim {A = λ _ → inr np₁ == inl p₂} (np₁ p₂) ;
(inr np₁) (inr np₂) → ap inr (fext np₁ np₂ (λ p → prop-has-all-paths (λ ()) _ _)) })
-- Theorem 7.8
nonempty-pop→lem : ((X : Type) → Funext {X} {Empty})
→ ((X : Type) → (¬(¬ X) → Pop X)) → LEM
nonempty-pop→lem fext nn-pop P pp = from-fix {X = dec} (idf _) (nn-pop dec nndec (idf _) idc) where
dec : Type
dec = P + ¬ P
idc : const (idf dec)
idc = λ _ _ → prop-has-all-paths (dec-is-prop {P} (fext P) pp) _ _
nndec : ¬(¬ dec)
nndec ndec = (λ np → ndec (inr np)) λ p → ndec (inl p)
-- Corollary 7.9
nonempty-pop↔lem : ((X : Type) → Funext {X} {Empty})
→ ((X : Type) → (¬(¬ X) → Pop X)) ↔₁₁ LEM
nonempty-pop↔lem fext = nonempty-pop→lem fext , other where
other : LEM → ((X : Type) → (¬(¬ X) → Pop X))
other lem X nnX = p where
pnp : Pop X + ¬ (Pop X)
pnp = lem (Pop X) pop-property₂
p : Pop X
p = match pnp withl idf _ withr (λ np → Empty-elim {A = λ _ → Pop X} (nnX (λ x → np (pop-property₁ x))))
| {
"alphanum_fraction": 0.515007398,
"avg_line_length": 32.2935153584,
"ext": "agda",
"hexsha": "4f0d433fb92b90b8fc79621910bd7629ea286145",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "nicolai/anonymousExistence/Sec7taboos.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "nicolai/anonymousExistence/Sec7taboos.agda",
"max_line_length": 120,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nicolaikraus/HoTT-Agda",
"max_stars_repo_path": "nicolai/anonymousExistence/Sec7taboos.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 3950,
"size": 9462
} |
-- Andreas, 2017-08-23, issue #2712
--
-- GHC Pragmas like LANGUAGE have to appear at the top of the Haskell file.
{-# OPTIONS --no-main #-} -- Recognized as pragma option since #2714
module Issue2712 where
{-# FOREIGN GHC {-# LANGUAGE TupleSections #-} #-}
postulate
Pair : (A B : Set) → Set
pair : {A B : Set} → A → B → Pair A B
{-# COMPILE GHC Pair = type (,) #-}
{-# COMPILE GHC pair = \ _ _ a b -> (a,) b #-} -- Test the availability of TupleSections
| {
"alphanum_fraction": 0.6046025105,
"avg_line_length": 28.1176470588,
"ext": "agda",
"hexsha": "9ee270daf4eb48cd16cec17acb7b1a7cdcc7417d",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Compiler/simple/Issue2712.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Compiler/simple/Issue2712.agda",
"max_line_length": 89,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Compiler/simple/Issue2712.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 142,
"size": 478
} |
-- Andreas, 2016-02-02, issues 480, 1159, 1811
data Unit : Set where
unit : Unit
-- To make it harder for Agda, we make constructor unit ambiguous.
data Ambiguous : Set where
unit : Ambiguous
postulate
f : ∀{A : Set} → (A → A) → A
test : Unit
test = f \{ unit → unit }
-- Extended lambda checking should be postponed until
-- type A has been instantiated to Unit.
-- Should succeed.
| {
"alphanum_fraction": 0.6734177215,
"avg_line_length": 19.75,
"ext": "agda",
"hexsha": "1eb9e8a05172d10013f4fa9c8b1e6bba6d11a784",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue1159.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue1159.agda",
"max_line_length": 66,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1159.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 118,
"size": 395
} |
-- The sole purpose of this module is to ease compilation of everything.
module Everything where
import Generic
import Structures
import Instances
import FinMap
import CheckInsert
import GetTypes
import FreeTheorems
import BFF
import Bidir
import LiftGet
import Precond
import Examples
import BFFPlug
| {
"alphanum_fraction": 0.8476821192,
"avg_line_length": 17.7647058824,
"ext": "agda",
"hexsha": "5ca555074ae076e7a18a52f6457c7784a845a2d1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jvoigtlaender/bidiragda",
"max_forks_repo_path": "Everything.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jvoigtlaender/bidiragda",
"max_issues_repo_path": "Everything.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a5abbd177f032523d1d9d3fa4b9137aefe88dee0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jvoigtlaender/bidiragda",
"max_stars_repo_path": "Everything.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 69,
"size": 302
} |
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Library.Relation.Binary.Equality.Decidable where
open import Light.Library.Relation using (Base)
open import Light.Library.Relation.Binary.Equality using (Equality)
open import Light.Level using (Setω)
import Light.Library.Relation.Decidable as Decidable
open import Light.Package using (Package)
open import Light.Variable.Levels
record DecidableEquality (𝕒 : Set aℓ) (𝕓 : Set aℓ) : Setω where
constructor wrap
field ⦃ decidable‐package ⦄ : Package record { Decidable }
field ⦃ equals ⦄ : Equality 𝕒 𝕓
DecidableSelfEquality : ∀ (𝕒 : Set aℓ) → Setω
DecidableSelfEquality 𝕒 = DecidableEquality 𝕒 𝕒
open DecidableEquality ⦃ ... ⦄ public
| {
"alphanum_fraction": 0.7549933422,
"avg_line_length": 35.7619047619,
"ext": "agda",
"hexsha": "5a3a5ea0c07ffec0640b27f96cb8d5caa7946f2f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "Zambonifofex/lightlib",
"max_forks_repo_path": "Light/Library/Relation/Binary/Equality/Decidable.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "Zambonifofex/lightlib",
"max_issues_repo_path": "Light/Library/Relation/Binary/Equality/Decidable.agda",
"max_line_length": 79,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "zamfofex/lightlib",
"max_stars_repo_path": "Light/Library/Relation/Binary/Equality/Decidable.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z",
"num_tokens": 209,
"size": 751
} |
{-# OPTIONS --type-in-type #-}
module z where
{-
Generic Programming with Dependent Types
Stephanie Weirich and Chris Casinghino, University of Pennsylvania, {sweirich,ccasin}@cis.upenn.edu
[email protected]
2010 : https://www.seas.upenn.edu/~sweirich/papers/aritygen.pdf
2012 : https://www.cis.upenn.edu/~sweirich/papers/ssgip-journal.pdf
------------------------------------------------------------------------------
-- Abstract and Intro
2 types of genericity
- datatype
- operate on type structure of data
- so no need to define for each new type
- arity
- enables functions to be applied to a variable number of args.
e.g., generalize arity of map
repeat :: a → [a]
map :: (a → b) → [a] → [b]
zipWith :: (a → b → c) → [a] → [b] → [c]
zipWith3 :: (a → b → c → d) → [a] → [b] → [c] → [d]
code : http://www.seas.upenn.edu/~sweirich/papers/aritygen-lncs.tar.gz
tested with : Agda version 2.2.10
------------------------------------------------------------------------------
2 SIMPLE TYPE-GENERIC PROGRAMMING IN AGDA
using Agda with flags (which implies cannot do proofs)
{-# OPTIONS --type-in-type #-}
–no-termination-check
{-# OPTIONS --no-positivity-check #-}
-}
data Bool : Set where
true : Bool
false : Bool
¬ : Bool → Bool
¬ true = false
¬ false = true
_∧_ : Bool → Bool → Bool
true ∧ true = true
_ ∧ _ = false
if_then_else : ∀ {A : Set} → Bool → A → A → A
if true then a1 else a2 = a1
if false then a1 else a2 = a2
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
_+_ : ℕ → ℕ → ℕ
zero + m = m
suc n + m = suc (n + m)
infixl 40 _+_
data List (A : Set) : Set where
[] : List A
_::_ : A → List A → List A
infixr 5 _::_ -- https://agda.github.io/agda-stdlib/Data.Vec.Functional.html
replicate : ∀ {A} → ℕ → A → List A
replicate zero _ = []
replicate (suc n) x = x :: replicate n x
data Vec (A : Set) : ℕ → Set where
[] : Vec A zero
_::_ : ∀ {n} → A → (Vec A n) → Vec A (suc n)
repeat : ∀ {n} {A} → A → Vec A n
repeat {zero} x = []
repeat {suc n} x = x :: repeat x
------------------------------------------------------------------------------
-- 2.1 BASIC TYPE-GENERIC PROGRAMMING
eq-bool : Bool → Bool → Bool
eq-bool true true = true
eq-bool false false = true
eq-bool _ _ = false
eq-nat : ℕ → ℕ → Bool
eq-nat zero zero = true
eq-nat (suc n) (suc m) = eq-nat n m
eq-nat _ _ = false
{-
Structural equality functions, like above, motivate type-generic programming:
- enables defining functions that observe and use structure of types
In a dependently typed language, type-generic is accomplished using universes [17, 21].
E.G., universe of natural number, boolean and product types
-}
-- datatype 'Type', called a "universe"
data Type : Set where
TNat : Type
TBool : Type
TProd : Type → Type → Type
open import Data.Product
-- define an interpretation function '⟨_⟩'
-- maps elements of this universe to Agda types
⟨_⟩ : Type → Set
⟨ TNat ⟩ = ℕ
⟨ TBool ⟩ = Bool
⟨ TProd t1 t2 ⟩ = ⟨ t1 ⟩ × ⟨ t2 ⟩
geq : (t : Type) → ⟨ t ⟩ → ⟨ t ⟩ → Bool
geq TNat n1 n2 = eq-nat n1 n2
geq TBool b1 b2 = eq-bool b1 b2
geq (TProd a b) (a1 , b1) (a2 , b2) = geq a a1 a2 ∧ geq b b1 b2
geqEx : Bool
geqEx = geq (TProd TNat TBool) (1 , false) (1 , false)
{-
------------------------------------------------------------------------------
-- 3 ARITY-GENERIC PROGRAMMING : generalize over number of arguments
e.g., map-like (above), +, foldl, foldr
e.g., generalize following functions into one definition : maps for vectors
-}
-- infix zipping application, pronounced “zap” for “zip with apply”
_⊗_ : {A B : Set} {n : ℕ} → Vec (A → B) n → Vec A n → Vec B n
[] ⊗ [] = []
(a :: As) ⊗ (b :: Bs) = a b :: As ⊗ Bs
infixl 40 _⊗_
map0 : {m : ℕ} {A : Set} → A → Vec A m
map0 = repeat
map1 : {m : ℕ} {A B : Set} → (A → B) → Vec A m → Vec B m
map1 f x = repeat f ⊗ x
map2 : {m : ℕ} {A B C : Set} → (A → B → C) → Vec A m → Vec B m → Vec C m
map2 f x1 x2 = repeat f ⊗ x1 ⊗ x2
{-
Intuitively, each map defined by a application of repeat and n copies of _⊗_.
nvec-map f n v1 v2 ... vn = repeat f ⊗ v1 ⊗ v2 ⊗ ... ⊗ vn
-- recursion on n in accumulator style
-- after repeating f : have a vector of functions
-- then zap this vector across n argument vectors
-- NEEDS type declaration - given below (in Arity section)
nvec-map n f = g n (repeat f)
where
g0 a = a
g (suc n) f = (λ a → g n (f ⊗ a))
--------------------------------------------------
3.1 Typing Arity-Generic Vector Map
arity-generic map : instances have different types
Given arity n, generate corresponding type in the sequence
Part of the difficulty is that generic function is curried in both its type and term args.
This subsection starts with an initial def that takes
- all of the type args in a vector,
- curries term arguments
next subsection, shows how to uncurry type args
ℕ for arity
store types in vector of Agda types, Bool :: N :: [].
vector has type Vec Set 2, so can use standard vector operations (such as _⊗_)
(given in OPTIONS at top of file)
--type-in-type : gives Set the type Set
- simplifies presentation by hiding Agda’s infinite hierarchy of Set levels
- at cost of making Agda’s logic inconsistent
-}
-- folds arrow type constructor (→) over vector of types
-- used to construct the type of 1sr arg to nvec-map
arrTy : {n : ℕ} → Vec Set (suc n) → Set
arrTy {0} (A :: []) = A
arrTy {suc n} (A :: As) = A → arrTy As
arrTyTest : Set
arrTyTest = arrTy (ℕ :: ℕ :: Bool :: [])
-- C-c C-n arrTyTest
-- ℕ → ℕ → Bool
-- Constructs result type of arity-generic map for vectors.
-- Map Vec constructor onto the vector of types, then placing arrows between them.
-- There are two indices:
-- - n : number of types (the arity)
-- - m : length of vectors to be mapped over
arrTyVec : {n : ℕ} → ℕ → Vec Set (suc n) → Set
arrTyVec m As = arrTy (repeat (λ A → Vec A m) ⊗ As)
{- alternate type sigs of previous mapN examples:
map0' : {m : ℕ} {A : Set} → arrTy (A :: []) → arrTyVec m (A :: [])
map1' : {m : ℕ} {A B : Set} → arrTy (A :: B :: []) → arrTyVec m (A :: B :: [])
map2' : {m : ℕ} {A B C : Set} → arrTy (A :: B :: C :: []) → arrTyVec m (A :: B :: C :: [])
-}
nvec-map : {m : ℕ}
→ (n : ℕ) → {As : Vec Set (suc n)}
→ arrTy As → arrTyVec m As
nvec-map n f = g n (repeat f)
where
g : {m : ℕ}
→ (n : ℕ) → {As : Vec Set (suc n)}
→ Vec (arrTy As) m → arrTyVec m As
g 0 {A :: []} a = a
g (suc n) {A :: As} f = (λ a → g n (f ⊗ a))
nvec-map-Test : Vec ℕ 2 -- 11 :: 15 :: []
nvec-map-Test = nvec-map 1 { ℕ :: ℕ :: [] } (λ x → 10 + x) (1 :: 5 :: [])
{-
annoying : must explicitly supply types
next section : enable inference
--------------------------------------------------
3.2 A Curried Vector Map
Curry type args so they are supplied individually (rather than a ector).
Enables inference (usually).
-}
-- quantify : creates curried version of a type which depends on a vector
∀⇒ : {n : ℕ} {A : Set} → (Vec A n → Set)
→ Set
∀⇒ {zero} B = B []
∀⇒ {suc n} {A} B = (a : A) → ∀⇒ {n} (λ as → B (a :: as))
-- curry : creates curried version of a corresponding function term
λ⇒ : {n : ℕ} {A : Set} {B : Vec A n → Set}
→ ((X : Vec A n) → B X)
→ (∀⇒ B)
λ⇒ {zero} f = f []
λ⇒ {suc n} {A} f = (λ a → λ⇒ {n} (λ as → f (a :: as))) -- **** HERE
-- 'a' is implicit in paper
-- Victor says 'hidden' lambdas are magic.
-- see: Eliminating the problems of hidden-lambda insertion
-- https://www.cse.chalmers.se/~abela/MScThesisJohanssonLloyd.pdf
-- uncurry (from 2010 paper)
/⇒ : (n : ℕ) → {K : Set} {B : Vec K n → Set}
→ (∀⇒ B)
→ (A : Vec K n)
→ B A
/⇒ (zero) f [] = f
/⇒ (suc n) f (a :: as) = /⇒ n (f a) as
-- arity-generic map
nmap : {m : ℕ}
→ (n : ℕ) -- specifies arity
→ ∀⇒ (λ (As : Vec Set (suc n)) → arrTy As → arrTyVec m As)
nmap {m} n = λ⇒ (λ As → nvec-map {m} n {As})
{-
nmap 1
has type
{m : N} → {A B : Set} → (A → B) → (Vec A m) → (Vec B m)
C-c C-d
(a a₁ : Set) → (a → a₁) → arrTyVec _m_193 (a :: a₁ :: [])
nmap 1 (λ x → 10 + x) (10 :: 5 :: [])
evaluates to
11 :: 15 :: []
C-c C-d
(x : ℕ) → ℕ !=< Set
when checking that the expression λ x → 10 + x has type Set
nmap 2
has type
{m : N} → {ABC : Set} → (A → B → C) → Vec A m → Vec B m → Vec C m
C-c C-d
(a a₁ a₂ : Set) → (a → a₁ → a₂) → arrTyVec _m_193 (a :: a₁ :: a₂ :: [])
nmap 2 ( , ) (1 :: 2 :: 3 :: []) (4 :: 5 :: 6 :: [])
evaluates to
(1 , 4) :: (2 , 5) :: (3 , 6) :: []
now : do not need to explicitly specify type of data in vectors
-}
| {
"alphanum_fraction": 0.5513145756,
"avg_line_length": 28.5263157895,
"ext": "agda",
"hexsha": "37606314b2a1dc7c8b78d3f4c7cd65e883934c5c",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/paper/2012-Stephanie_Weirich_and_Casinghino-Generic_Programming_with_Dependent_Types/z.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/paper/2012-Stephanie_Weirich_and_Casinghino-Generic_Programming_with_Dependent_Types/z.agda",
"max_line_length": 99,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/paper/2012-Stephanie_Weirich_and_Casinghino-Generic_Programming_with_Dependent_Types/z.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 2989,
"size": 8672
} |
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Implementation.Standard.Data.Empty where
open import Light.Library.Data.Empty using (Library ; Dependencies)
instance dependencies : Dependencies
dependencies = record {}
instance library : Library dependencies
library = record { Implementation }
where
module Implementation where
open import Data.Empty using () renaming (⊥ to Empty ; ⊥-elim to eliminate) public
| {
"alphanum_fraction": 0.7422680412,
"avg_line_length": 32.3333333333,
"ext": "agda",
"hexsha": "a94651b1475507abb687783216643c3f0997ad82",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "Zambonifofex/lightlib",
"max_forks_repo_path": "bindings/stdlib/Light/Implementation/Standard/Data/Empty.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "Zambonifofex/lightlib",
"max_issues_repo_path": "bindings/stdlib/Light/Implementation/Standard/Data/Empty.agda",
"max_line_length": 94,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "zamfofex/lightlib",
"max_stars_repo_path": "bindings/stdlib/Light/Implementation/Standard/Data/Empty.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z",
"num_tokens": 92,
"size": 485
} |
module Tactic.Nat.Induction where
open import Prelude
nat-induction : (P : Nat → Set) → P 0 → (∀ n → P n → P (suc n)) → ∀ n → P n
nat-induction P base step zero = base
nat-induction P base step (suc n) = step n (nat-induction P base step n)
| {
"alphanum_fraction": 0.6437246964,
"avg_line_length": 27.4444444444,
"ext": "agda",
"hexsha": "9c5bddc2227b1c58ebe3029d8746dc1caa5a2622",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Tactic/Nat/Induction.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Tactic/Nat/Induction.agda",
"max_line_length": 75,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Tactic/Nat/Induction.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 86,
"size": 247
} |
open import Agda.Primitive using (lzero; lsuc; _⊔_ ;Level)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; setoid; cong; trans)
import Function.Equality
open import Relation.Binary using (Setoid)
import Categories.Category
import Categories.Functor
import Categories.Category.Instance.Setoids
import Categories.Monad.Relative
import Categories.Category.Equivalence
import Categories.Category.Cocartesian
import Categories.Category.Construction.Functors
import Categories.NaturalTransformation.Equivalence
import Relation.Binary.Core
import SecondOrder.Arity
import SecondOrder.Signature
import SecondOrder.Metavariable
import SecondOrder.VRenaming
import SecondOrder.MRenaming
import SecondOrder.Term
import SecondOrder.IndexedCategory
import SecondOrder.RelativeKleisli
import SecondOrder.Substitution
module SecondOrder.VRelativeMonad
{ℓ}
{𝔸 : SecondOrder.Arity.Arity}
(Σ : SecondOrder.Signature.Signature ℓ 𝔸)
where
open SecondOrder.Signature.Signature Σ
open SecondOrder.Metavariable Σ
open SecondOrder.Term Σ
open SecondOrder.VRenaming Σ
open SecondOrder.MRenaming Σ
open SecondOrder.Substitution Σ
-- TERMS FORM A RELATIVE MONAD
-- (FOR A FUNCTOR WHOSE DOMAIN IS THE
-- CATEGORY OF VARIABLE CONTEXTS AND RENAMINGS)
module _ where
open Categories.Category
open Categories.Functor using (Functor)
open Categories.Category.Instance.Setoids
open import SecondOrder.IndexedCategory
-- The embedding of contexts into setoids indexed by sorts
-- (seen as a "variable" functor)
Jⱽ : Functor VContexts (IndexedCategory sort (Setoids ℓ ℓ))
Jⱽ = slots
-- The relative monad over Jⱽ
module _ {Θ : MContext} where
open Categories.Category
open Categories.Functor using (Functor)
open Categories.Category.Instance.Setoids
open Categories.Category.Category (Setoids ℓ ℓ)
open Categories.Monad.Relative
open Function.Equality using () renaming (setoid to Π-setoid)
open Categories.Category.Equivalence using (StrongEquivalence)
open import SecondOrder.IndexedCategory
open import SecondOrder.RelativeKleisli
open Function.Equality using (_⟨$⟩_) renaming (cong to func-cong)
open import Relation.Binary.Reasoning.MultiSetoid
to-σ : ∀ {Γ Δ} → (IndexedCategory sort (Setoids ℓ ℓ) Category.⇒ Functor.₀ Jⱽ Γ) (λ A → Term-setoid Θ Δ A) → (Θ ⊕ Γ ⇒ˢ Δ)
to-σ ℱ {A} x = ℱ A ⟨$⟩ x
VMonad : Monad Jⱽ
VMonad = record
{ F₀ = λ Γ A → Term-setoid Θ Γ A
; unit = λ A →
record
{ _⟨$⟩_ = λ x → tm-var x
; cong = λ ξ → ≈-≡ (σ-resp-≡ {σ = tm-var} ξ) }
; extend = λ ℱ A →
record
{ _⟨$⟩_ = [ to-σ ℱ ]ˢ_
; cong = λ ξ → []ˢ-resp-≈ (λ {B} z → ℱ B ⟨$⟩ z) ξ }
; identityʳ = λ {Γ} {Δ} {ℱ} A {x} {y} ξ → func-cong (ℱ A) ξ
; identityˡ = λ A ξ → ≈-trans [idˢ] ξ
; assoc = λ {Γ} {Δ} {Ξ} {k} {l} A {x} {y} ξ →
begin⟨ Term-setoid Θ _ _ ⟩
( ([ (λ {B} r → [ (λ {A = B} z → l B ⟨$⟩ z) ]ˢ (k B ⟨$⟩ r)) ]ˢ x) ) ≈⟨ []ˢ-resp-≈ ((λ {B} r → [ (λ {A = B} z → l B ⟨$⟩ z) ]ˢ (k B ⟨$⟩ r))) ξ ⟩
([ (λ {B} r → [ (λ {A = A₁} z → l A₁ ⟨$⟩ z) ]ˢ (k B ⟨$⟩ r)) ]ˢ y) ≈⟨ [∘ˢ] y ⟩
(([ (λ {B} z → l B ⟨$⟩ z) ]ˢ ([ (λ {B} z → k B ⟨$⟩ z) ]ˢ y))) ∎
; extend-≈ = λ {Γ} {Δ} {k} {h} ξˢ A {x} {y} ξ →
begin⟨ Term-setoid Θ _ _ ⟩
([ (λ {B} z → k B ⟨$⟩ z) ]ˢ x) ≈⟨ []ˢ-resp-≈ ((λ {B} z → k B ⟨$⟩ z)) ξ ⟩
([ (λ {B} z → k B ⟨$⟩ z) ]ˢ y) ≈⟨ []ˢ-resp-≈ˢ y (λ {B} z → ξˢ B refl) ⟩
([ (λ {B} z → h B ⟨$⟩ z) ]ˢ y) ∎
}
| {
"alphanum_fraction": 0.5707715892,
"avg_line_length": 39.9387755102,
"ext": "agda",
"hexsha": "b7a97f86e5bf28cef91e761154d2e5e88765cd82",
"lang": "Agda",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z",
"max_forks_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cilinder/formaltt",
"max_forks_repo_path": "src/SecondOrder/VRelativeMonad.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb",
"max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cilinder/formaltt",
"max_issues_repo_path": "src/SecondOrder/VRelativeMonad.agda",
"max_line_length": 171,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cilinder/formaltt",
"max_stars_repo_path": "src/SecondOrder/VRelativeMonad.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z",
"num_tokens": 1291,
"size": 3914
} |
------------------------------------------------------------------------
-- The figure of eight
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
-- The module is parametrised by a notion of equality. The higher
-- constructor of the HIT defining the circle uses path equality, but
-- the supplied notion of equality is used for many other things.
import Equality.Path as P
module Figure-of-eight
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
import Equality.Path.Univalence as EPU
open import Prelude
open import Bijection equality-with-J using (_↔_)
import Bijection P.equality-with-J as PB
open import Circle eq as Circle using (𝕊¹; base; loopᴾ)
open import Equality.Decision-procedures equality-with-J
open import Equality.Path.Isomorphisms eq
import Equality.Tactic P.equality-with-J as PT
open import Equivalence equality-with-J as Eq using (_≃_)
import Equivalence P.equality-with-J as PE
open import Erased.Cubical eq
open import Function-universe equality-with-J hiding (_∘_)
open import Pushout eq as Pushout using (Wedge; inl; inr; glueᴾ)
import Univalence-axiom P.equality-with-J as PU
private
variable
a p : Level
A : Type a
P : A → Type p
e r x : A
------------------------------------------------------------------------
-- The type
-- The figure of eight
-- (https://topospaces.subwiki.org/wiki/Wedge_of_two_circles).
data ∞ : Type where
base : ∞
loop₁ᴾ loop₂ᴾ : base P.≡ base
-- The higher constructors.
loop₁ : base ≡ base
loop₁ = _↔_.from ≡↔≡ loop₁ᴾ
loop₂ : base ≡ base
loop₂ = _↔_.from ≡↔≡ loop₂ᴾ
------------------------------------------------------------------------
-- Eliminators
-- An eliminator, expressed using paths.
record Elimᴾ (P : ∞ → Type p) : Type p where
no-eta-equality
field
baseʳ : P base
loop₁ʳ : P.[ (λ i → P (loop₁ᴾ i)) ] baseʳ ≡ baseʳ
loop₂ʳ : P.[ (λ i → P (loop₂ᴾ i)) ] baseʳ ≡ baseʳ
open Elimᴾ public
elimᴾ : Elimᴾ P → (x : ∞) → P x
elimᴾ {P = P} e = helper
where
module E = Elimᴾ e
helper : (x : ∞) → P x
helper base = E.baseʳ
helper (loop₁ᴾ i) = E.loop₁ʳ i
helper (loop₂ᴾ i) = E.loop₂ʳ i
-- A non-dependent eliminator, expressed using paths.
record Recᴾ (A : Type a) : Type a where
no-eta-equality
field
baseʳ : A
loop₁ʳ loop₂ʳ : baseʳ P.≡ baseʳ
open Recᴾ public
recᴾ : Recᴾ A → ∞ → A
recᴾ r = elimᴾ λ where
.baseʳ → R.baseʳ
.loop₁ʳ → R.loop₁ʳ
.loop₂ʳ → R.loop₂ʳ
where
module R = Recᴾ r
-- An eliminator.
record Elim (P : ∞ → Type p) : Type p where
no-eta-equality
field
baseʳ : P base
loop₁ʳ : subst P loop₁ baseʳ ≡ baseʳ
loop₂ʳ : subst P loop₂ baseʳ ≡ baseʳ
open Elim public
elim : Elim P → (x : ∞) → P x
elim e = elimᴾ λ where
.baseʳ → E.baseʳ
.loop₁ʳ → subst≡→[]≡ E.loop₁ʳ
.loop₂ʳ → subst≡→[]≡ E.loop₂ʳ
where
module E = Elim e
-- Two "computation" rules.
elim-loop₁ : dcong (elim e) loop₁ ≡ e .Elim.loop₁ʳ
elim-loop₁ = dcong-subst≡→[]≡ (refl _)
elim-loop₂ : dcong (elim e) loop₂ ≡ e .Elim.loop₂ʳ
elim-loop₂ = dcong-subst≡→[]≡ (refl _)
-- A non-dependent eliminator.
record Rec (A : Type a) : Type a where
no-eta-equality
field
baseʳ : A
loop₁ʳ loop₂ʳ : baseʳ ≡ baseʳ
open Rec public
rec : Rec A → ∞ → A
rec r = recᴾ λ where
.baseʳ → R.baseʳ
.loop₁ʳ → _↔_.to ≡↔≡ R.loop₁ʳ
.loop₂ʳ → _↔_.to ≡↔≡ R.loop₂ʳ
where
module R = Rec r
-- Two "computation" rules.
rec-loop₁ : cong (rec r) loop₁ ≡ r .Rec.loop₁ʳ
rec-loop₁ = cong-≡↔≡ (refl _)
rec-loop₂ : cong (rec r) loop₂ ≡ r .Rec.loop₂ʳ
rec-loop₂ = cong-≡↔≡ (refl _)
------------------------------------------------------------------------
-- Some negative results
-- The two higher constructors are not equal.
--
-- The proof is based on the one from the HoTT book that shows that
-- the circle's higher constructor is not equal to reflexivity.
loop₁≢loop₂ : loop₁ ≢ loop₂
loop₁≢loop₂ =
Stable-¬
[ loop₁ ≡ loop₂ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (inverse ≡↔≡)) ⟩
loop₁ᴾ ≡ loop₂ᴾ ↔⟨ ≡↔≡ ⟩
loop₁ᴾ P.≡ loop₂ᴾ ↝⟨ PU.¬-Type-set EPU.univ ∘ Type-set ⟩□
⊥ □
]
where
module _ (hyp : loop₁ᴾ P.≡ loop₂ᴾ) where
refl≡ : (A : Type) (A≡A : A P.≡ A) → P.refl P.≡ A≡A
refl≡ A A≡A =
P.refl P.≡⟨⟩
P.cong F loop₁ᴾ P.≡⟨ P.cong (P.cong F) hyp ⟩
P.cong F loop₂ᴾ P.≡⟨⟩
A≡A P.∎
where
F : ∞ → Type
F base = A
F (loop₁ᴾ i) = P.refl i
F (loop₂ᴾ i) = A≡A i
Type-set : P.Is-set Type
Type-set {x = A} {y = B} =
P.elim¹ (λ p → ∀ q → p P.≡ q)
(refl≡ A)
-- The two higher constructors provide a counterexample to
-- commutativity of transitivity.
--
-- This proof is a minor variant of a proof due to Andrea Vezzosi.
trans-not-commutative : trans loop₁ loop₂ ≢ trans loop₂ loop₁
trans-not-commutative =
Stable-¬
[ trans loop₁ loop₂ ≡ trans loop₂ loop₁ ↝⟨ (λ hyp → trans (sym (_↔_.from-to ≡↔≡ (sym trans≡trans)))
(trans (cong (_↔_.to ≡↔≡) hyp) (_↔_.from-to ≡↔≡ (sym trans≡trans)))) ⟩
P.trans loop₁ᴾ loop₂ᴾ ≡ P.trans loop₂ᴾ loop₁ᴾ ↝⟨ cong (P.subst F) ⟩
P.subst F (P.trans loop₁ᴾ loop₂ᴾ) ≡
P.subst F (P.trans loop₂ᴾ loop₁ᴾ) ↝⟨ (λ hyp → trans (sym (_↔_.from ≡↔≡ lemma₁₂))
(trans hyp (_↔_.from ≡↔≡ lemma₂₁))) ⟩
PE._≃_.to eq₂ ∘ PE._≃_.to eq₁ ≡
PE._≃_.to eq₁ ∘ PE._≃_.to eq₂ ↝⟨ cong (_$ fzero) ⟩
fzero ≡ fsuc fzero ↝⟨ ⊎.inj₁≢inj₂ ⟩□
⊥ □
]
where
eq₁ : Fin 3 PE.≃ Fin 3
eq₁ = PE.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = λ where
fzero → fsuc (fsuc fzero)
(fsuc fzero) → fsuc fzero
(fsuc (fsuc fzero)) → fzero
; from = λ where
fzero → fsuc (fsuc fzero)
(fsuc fzero) → fsuc fzero
(fsuc (fsuc fzero)) → fzero
}
; right-inverse-of = λ where
fzero → P.refl
(fsuc fzero) → P.refl
(fsuc (fsuc fzero)) → P.refl
}
; left-inverse-of = λ where
fzero → P.refl
(fsuc fzero) → P.refl
(fsuc (fsuc fzero)) → P.refl
})
eq₂ : Fin 3 PE.≃ Fin 3
eq₂ = PE.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = λ where
fzero → fsuc fzero
(fsuc fzero) → fsuc (fsuc fzero)
(fsuc (fsuc fzero)) → fzero
; from = λ where
fzero → fsuc (fsuc fzero)
(fsuc fzero) → fzero
(fsuc (fsuc fzero)) → fsuc fzero
}
; right-inverse-of = λ where
fzero → P.refl
(fsuc fzero) → P.refl
(fsuc (fsuc fzero)) → P.refl
}
; left-inverse-of = λ where
fzero → P.refl
(fsuc fzero) → P.refl
(fsuc (fsuc fzero)) → P.refl
})
@0 F : ∞ → Type
F base = Fin 3
F (loop₁ᴾ i) = EPU.≃⇒≡ eq₁ i
F (loop₂ᴾ i) = EPU.≃⇒≡ eq₂ i
lemma₁₂ :
P.subst F (P.trans loop₁ᴾ loop₂ᴾ) P.≡
PE._≃_.to eq₂ ∘ PE._≃_.to eq₁
lemma₁₂ _ i@fzero = PE._≃_.to eq₂ (PE._≃_.to eq₁ i)
lemma₁₂ _ i@(fsuc fzero) = PE._≃_.to eq₂ (PE._≃_.to eq₁ i)
lemma₁₂ _ i@(fsuc (fsuc fzero)) = PE._≃_.to eq₂ (PE._≃_.to eq₁ i)
lemma₂₁ :
P.subst F (P.trans loop₂ᴾ loop₁ᴾ) P.≡
PE._≃_.to eq₁ ∘ PE._≃_.to eq₂
lemma₂₁ _ i@fzero = PE._≃_.to eq₁ (PE._≃_.to eq₂ i)
lemma₂₁ _ i@(fsuc fzero) = PE._≃_.to eq₁ (PE._≃_.to eq₂ i)
lemma₂₁ _ i@(fsuc (fsuc fzero)) = PE._≃_.to eq₁ (PE._≃_.to eq₂ i)
private
-- A lemma used below.
trans-sometimes-commutative′ :
{p q : x ≡ x} (f : (x : ∞) → x ≡ x) →
f x ≡ p →
trans p q ≡ trans q p
trans-sometimes-commutative′ {x = x} {p = p} {q = q} f f-x≡p =
trans p q ≡⟨ cong (flip trans _) $ sym f-x≡p ⟩
trans (f x) q ≡⟨ trans-sometimes-commutative f ⟩
trans q (f x) ≡⟨ cong (trans q) f-x≡p ⟩∎
trans q p ∎
-- There is no function of type (x : ∞) → x ≡ x which returns loop₁
-- when applied to base.
¬-base↦loop₁ : ¬ ∃ λ (f : (x : ∞) → x ≡ x) → f base ≡ loop₁
¬-base↦loop₁ (f , f-base≡loop₁) =
trans-not-commutative (
trans loop₁ loop₂ ≡⟨ trans-sometimes-commutative′ f f-base≡loop₁ ⟩∎
trans loop₂ loop₁ ∎)
-- There is no function of type (x : ∞) → x ≡ x which returns loop₂
-- when applied to base.
¬-base↦loop₂ : ¬ ∃ λ (f : (x : ∞) → x ≡ x) → f base ≡ loop₂
¬-base↦loop₂ (f , f-base≡loop₂) =
trans-not-commutative (
trans loop₁ loop₂ ≡⟨ sym $ trans-sometimes-commutative′ f f-base≡loop₂ ⟩∎
trans loop₂ loop₁ ∎)
-- There is no function of type (x : ∞) → x ≡ x which returns
-- trans loop₁ loop₂ when applied to base.
¬-base↦trans-loop₁-loop₂ :
¬ ∃ λ (f : (x : ∞) → x ≡ x) → f base ≡ trans loop₁ loop₂
¬-base↦trans-loop₁-loop₂ (f , f-base≡trans-loop₁-loop₂) =
trans-not-commutative (
trans loop₁ loop₂ ≡⟨ sym $ trans-reflˡ _ ⟩
trans (refl _) (trans loop₁ loop₂) ≡⟨ cong (flip trans _) $ sym $ trans-symˡ _ ⟩
trans (trans (sym loop₁) loop₁) (trans loop₁ loop₂) ≡⟨ trans-assoc _ _ _ ⟩
trans (sym loop₁) (trans loop₁ (trans loop₁ loop₂)) ≡⟨ cong (trans (sym loop₁)) $ sym $
trans-sometimes-commutative′ f f-base≡trans-loop₁-loop₂ ⟩
trans (sym loop₁) (trans (trans loop₁ loop₂) loop₁) ≡⟨ cong (trans (sym loop₁)) $ trans-assoc _ _ _ ⟩
trans (sym loop₁) (trans loop₁ (trans loop₂ loop₁)) ≡⟨ sym $ trans-assoc _ _ _ ⟩
trans (trans (sym loop₁) loop₁) (trans loop₂ loop₁) ≡⟨ cong (flip trans _) $ trans-symˡ _ ⟩
trans (refl _) (trans loop₂ loop₁) ≡⟨ trans-reflˡ _ ⟩∎
trans loop₂ loop₁ ∎)
-- There is no function of type (x : ∞) → x ≡ x which returns
-- trans loop₂ loop₁ when applied to base.
¬-base↦trans-loop₂-loop₁ :
¬ ∃ λ (f : (x : ∞) → x ≡ x) → f base ≡ trans loop₂ loop₁
¬-base↦trans-loop₂-loop₁ (f , f-base≡trans-loop₂-loop₁) =
trans-not-commutative (
trans loop₁ loop₂ ≡⟨ sym $ trans-reflˡ _ ⟩
trans (refl _) (trans loop₁ loop₂) ≡⟨ cong (flip trans _) $ sym $ trans-symˡ _ ⟩
trans (trans (sym loop₂) loop₂) (trans loop₁ loop₂) ≡⟨ trans-assoc _ _ _ ⟩
trans (sym loop₂) (trans loop₂ (trans loop₁ loop₂)) ≡⟨ cong (trans (sym loop₂)) $ sym $ trans-assoc _ _ _ ⟩
trans (sym loop₂) (trans (trans loop₂ loop₁) loop₂) ≡⟨ cong (trans (sym loop₂)) $
trans-sometimes-commutative′ f f-base≡trans-loop₂-loop₁ ⟩
trans (sym loop₂) (trans loop₂ (trans loop₂ loop₁)) ≡⟨ sym $ trans-assoc _ _ _ ⟩
trans (trans (sym loop₂) loop₂) (trans loop₂ loop₁) ≡⟨ cong (flip trans _) $ trans-symˡ _ ⟩
trans (refl _) (trans loop₂ loop₁) ≡⟨ trans-reflˡ _ ⟩∎
trans loop₂ loop₁ ∎)
-- TODO: Can one prove that functions of type (x : ∞) → x ≡ x must map
-- base to refl base?
------------------------------------------------------------------------
-- A positive result
-- The figure of eight can be expressed as a wedge of two circles.
--
-- This result was suggested to me by Anders Mörtberg.
∞≃Wedge-𝕊¹-𝕊¹ : ∞ ≃ Wedge (𝕊¹ , base) (𝕊¹ , base)
∞≃Wedge-𝕊¹-𝕊¹ = Eq.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = _↔_.from ≡↔≡ ∘ from∘to
})
where
lemma : inl base P.≡ inl base
lemma =
inl base P.≡⟨ glueᴾ tt ⟩
inr base P.≡⟨ P.sym (P.cong inr loopᴾ) ⟩
inr base P.≡⟨ P.sym (glueᴾ tt) ⟩∎
inl base ∎
Glue = PT.Lift (glueᴾ tt)
Loop = PT.Lift (P.cong inr loopᴾ)
Loop₂ = PT.Lift loop₂ᴾ
Lemma =
PT.Trans Glue $
PT.Trans (PT.Sym Loop) $
PT.Sym Glue
to : ∞ → Wedge (𝕊¹ , base) (𝕊¹ , base)
to base = inl base
to (loop₁ᴾ i) = P.cong inl loopᴾ i
to (loop₂ᴾ i) = P.sym lemma i
from : Wedge (𝕊¹ , base) (𝕊¹ , base) → ∞
from = Pushout.recᴾ
(Circle.recᴾ base loop₁ᴾ)
(Circle.recᴾ base loop₂ᴾ)
(λ _ → P.refl)
to∘from : ∀ x → to (from x) ≡ x
to∘from =
_↔_.from ≡↔≡ ∘
Pushout.elimᴾ _
(Circle.elimᴾ _ P.refl (λ _ → P.refl))
(Circle.elimᴾ _ (glueᴾ _)
(PB._↔_.from (P.heterogeneous↔homogeneous _)
(P.transport (λ i → P.sym lemma i P.≡ inr (loopᴾ i))
P.0̲ (glueᴾ tt) P.≡⟨ P.transport-≡ (glueᴾ tt) ⟩
P.trans lemma (P.trans (glueᴾ tt) (P.cong inr loopᴾ)) P.≡⟨ PT.prove
(PT.Trans Lemma (PT.Trans Glue Loop))
(PT.Trans Glue (PT.Trans (PT.Sym Loop)
(PT.Trans (PT.Trans (PT.Sym Glue) Glue) Loop)))
P.refl ⟩
P.trans (glueᴾ tt)
(P.trans (P.sym (P.cong inr loopᴾ))
(P.trans (P.trans (P.sym (glueᴾ tt)) (glueᴾ tt))
(P.cong inr loopᴾ))) P.≡⟨ P.cong (λ eq → P.trans (glueᴾ tt) (P.trans (P.sym (P.cong inr loopᴾ))
(P.trans eq (P.cong inr loopᴾ)))) $
P.trans-symˡ _ ⟩
P.trans (glueᴾ tt)
(P.trans (P.sym (P.cong inr loopᴾ))
(P.trans P.refl
(P.cong inr loopᴾ))) P.≡⟨ P.cong (λ eq → P.trans (glueᴾ tt)
(P.trans (P.sym (P.cong inr loopᴾ)) eq)) $
P.trans-reflˡ _ ⟩
P.trans (glueᴾ tt)
(P.trans (P.sym (P.cong inr loopᴾ))
(P.cong inr loopᴾ)) P.≡⟨ P.cong (P.trans (glueᴾ tt)) $ P.trans-symˡ _ ⟩
P.trans (glueᴾ tt) P.refl P.≡⟨ P.trans-reflʳ _ ⟩∎
glueᴾ tt ∎)))
(λ _ → PB._↔_.from (P.heterogeneous↔homogeneous _) (
P.subst (inl base P.≡_) (glueᴾ tt) P.refl P.≡⟨ P.sym $ P.trans-subst {x≡y = P.refl} ⟩
P.trans P.refl (glueᴾ tt) P.≡⟨ P.trans-reflˡ _ ⟩∎
glueᴾ tt ∎))
from∘to : ∀ x → from (to x) P.≡ x
from∘to base = P.refl
from∘to (loop₁ᴾ i) = P.refl
from∘to (loop₂ᴾ i) = lemma′ i
where
lemma′ : P.[ (λ i → P.cong from (P.sym lemma) i P.≡ loop₂ᴾ i) ]
P.refl ≡ P.refl
lemma′ = PB._↔_.from (P.heterogeneous↔homogeneous _) (
P.transport (λ i → P.cong from (P.sym lemma) i P.≡ loop₂ᴾ i)
P.0̲ P.refl P.≡⟨ P.transport-≡ P.refl ⟩
P.trans (P.cong from lemma) (P.trans P.refl loop₂ᴾ) P.≡⟨ PT.prove
(PT.Trans (PT.Cong from Lemma) (PT.Trans PT.Refl Loop₂))
(PT.Trans (PT.Trans (PT.Cong from Glue)
(PT.Trans (PT.Cong from (PT.Sym Loop))
(PT.Cong from (PT.Sym Glue))))
Loop₂)
P.refl ⟩
P.trans (P.trans (P.cong from (glueᴾ tt))
(P.trans (P.cong from (P.sym (P.cong inr loopᴾ)))
(P.cong from (P.sym (glueᴾ tt)))))
loop₂ᴾ P.≡⟨⟩
P.trans (P.trans P.refl (P.trans (P.sym loop₂ᴾ) P.refl)) loop₂ᴾ P.≡⟨ P.cong (flip P.trans loop₂ᴾ) $
P.trans-reflˡ (P.trans (P.sym loop₂ᴾ) P.refl) ⟩
P.trans (P.trans (P.sym loop₂ᴾ) P.refl) loop₂ᴾ P.≡⟨ P.cong (flip P.trans loop₂ᴾ) $
P.trans-reflʳ (P.sym loop₂ᴾ) ⟩
P.trans (P.sym loop₂ᴾ) loop₂ᴾ P.≡⟨ P.trans-symˡ _ ⟩∎
P.refl ∎)
| {
"alphanum_fraction": 0.4757775465,
"avg_line_length": 36.9615384615,
"ext": "agda",
"hexsha": "d55cf24ddfe56fe74d7cfe4785e60e590d87dae9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Figure-of-eight.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Figure-of-eight.agda",
"max_line_length": 142,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Figure-of-eight.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 6078,
"size": 17298
} |
open import Prelude
module Implicits.Resolution.Infinite.Algorithm.Soundness where
open import Data.Vec hiding (_∈_)
open import Data.List hiding (map)
open import Data.List.Any hiding (tail)
open Membership-≡
open import Data.Bool
open import Data.Unit.Base
open import Data.Maybe as Maybe hiding (All)
open import Coinduction
open import Data.Fin.Substitution
open import Implicits.Syntax
open import Implicits.Substitutions
open import Implicits.Substitutions.MetaType
open import Implicits.Substitutions.Lemmas
open import Implicits.Syntax.Type.Unification
open import Implicits.Syntax.Type.Unification.Lemmas renaming (sound to mgu-sound)
open import Implicits.Resolution.Infinite.Resolution
open import Implicits.Resolution.Infinite.Algorithm
open import Implicits.Resolution.Termination
open Inductive
open import Induction.WellFounded
open import Category.Functor
open import Category.Monad.Partiality as P
open import Category.Monad.Partiality.All using (All; module Alternative)
open Alternative renaming (sound to AllP-sound)
private module MaybeFunctor {f} = RawFunctor (functor {f})
open import Extensions.Bool as B hiding (All)
open import Relation.Binary.PropositionalEquality as PEq using (_≡_)
module PR = P.Reasoning (PEq.isEquivalence {A = Bool})
private
module M = MetaTypeMetaSubst
postulate lem₄ : ∀ {m ν} (a : MetaType m (suc ν)) u us →
from-meta (((M.open-meta a) M./ (us M.↑)) M./ (M.sub u))
≡ (from-meta (a M./ (us M.↑tp))) tp[/tp from-meta u ]
open-↓-∀ : ∀ {ν m} {Δ : ICtx ν} (a : MetaType m (suc ν)) τ u us →
Δ ⊢ (from-meta ((open-meta a) M./ (u ∷ us))) ↓ τ →
Δ ⊢ (from-meta (∀' a M./ us)) ↓ τ
open-↓-∀ {Δ = Δ} a τ u us p = (i-tabs (from-meta u) (subst (λ v → Δ ⊢ v ↓ τ) (begin
from-meta (M._/_ (open-meta a) (u ∷ us))
≡⟨ cong (λ v → from-meta (M._/_ (open-meta a) v)) (sym $ us↑-⊙-sub-u≡u∷us u us) ⟩
from-meta ((open-meta a) M./ (us M.↑ M.⊙ (M.sub u)))
≡⟨ cong from-meta (/-⊙ (open-meta a)) ⟩
from-meta ((open-meta a) M./ us M.↑ M./ (M.sub u))
≡⟨ lem₄ a u us ⟩
from-meta (M._/_ a (us M.↑tp)) tp[/tp from-meta u ] ∎) p))
where open MetaTypeMetaLemmas hiding (subst)
mutual
delayed-resolve-sound : ∀ {ν} (Δ : ICtx ν) (a : Type ν) →
AllP (B.All (Δ ⊢ᵣ a)) (delayed-resolve Δ a)
delayed-resolve-sound Δ a = later (♯ (resolve'-sound Δ a))
resolve-context-sound : ∀ {ν m} (Δ : ICtx ν) (a : MetaType m ν) b {τ v} →
Maybe.All (λ u → Δ ⊢ from-meta (b M./ u) ↓ τ) v →
AllP (Maybe.All (λ u →
(Δ ⊢ from-meta (a M./ u) ⇒ from-meta (b M./ u) ↓ τ))
) (resolve-context Δ a v)
resolve-context-sound Δ a b {τ = τ} (just {x = u} px) = _
≅⟨ resolve-context-comp Δ a u ⟩P delayed-resolve-sound Δ (from-meta (M._/_ a u)) >>=-congP lem
where
lem : ∀ {v} → B.All (Δ ⊢ᵣ from-meta (a M./ u)) v →
AllP (Maybe.All (λ u → Δ ⊢ from-meta (a M./ u) ⇒ from-meta (b M./ u) ↓ τ)) (map-bool u v)
lem (true x) = now (just (i-iabs x px))
lem (false) = now nothing
resolve-context-sound Δ a b nothing = now nothing
match-u-sound : ∀ {ν m} (Δ : ICtx ν) τ (r : MetaType m ν) → (r-acc : m<-Acc r) →
AllP (Maybe.All (λ u → (Δ ⊢ from-meta (r M./ u) ↓ τ))) (match-u Δ τ r r-acc)
match-u-sound Δ τ (a ⇒ b) (acc rs) = _ ≅⟨ match-u-iabs-comp Δ τ a b rs ⟩P
match-u-sound Δ τ b (rs _ (b-m<-a⇒b a b)) >>=-congP resolve-context-sound Δ a b
match-u-sound Δ τ (∀' r) (acc rs) = _ ≅⟨ match-u-tabs-comp Δ τ r rs ⟩P
match-u-sound Δ τ (open-meta r) _ >>=-congP lem
where
lem : ∀ {v} → Maybe.All (λ u → Δ ⊢ from-meta (open-meta r M./ u) ↓ τ) v →
AllP (Maybe.All (λ u → Δ ⊢ ∀' (from-meta (r M./ u M.↑tp)) ↓ τ ))
((now ∘ (MaybeFunctor._<$>_ tail)) v)
lem (just {x = u ∷ us} px) = now (just (open-↓-∀ r τ u us px))
lem nothing = now nothing
match-u-sound Δ τ (simpl x) (acc rs) with mgu (simpl x) τ | mgu-sound (simpl x) τ
match-u-sound Δ τ (simpl x) (acc rs) | just us | just x/us≡τ =
now (just (subst (λ z → Δ ⊢ z ↓ τ) (sym x/us≡τ) (i-simp τ)))
match-u-sound Δ τ (simpl x) (acc rs) | nothing | nothing = now nothing
match-sound : ∀ {ν} (Δ : ICtx ν) τ r →
AllP (B.All (Δ ⊢ r ↓ τ)) (match Δ τ r)
match-sound Δ τ r = _
≅⟨ match-comp Δ τ r ⟩P
match-u-sound Δ τ (to-meta {zero} r) (m<-well-founded _) >>=-congP lem
where
eq : ∀ {ν} {a : Type ν} {s} → from-meta (to-meta {zero} a M./ s) ≡ a
eq {a = a} {s = []} = begin
from-meta (M._/_ (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 ∎
lem : ∀ {v} → Maybe.All (λ u → (Δ ⊢ from-meta ((to-meta {zero} r) M./ u) ↓ τ)) v →
AllP (B.All (Δ ⊢ r ↓ τ)) ((now ∘ is-just) v)
lem (just px) = now (true (subst (λ z → Δ ⊢ z ↓ τ) eq px))
lem nothing = now false
match1st-recover-sound : ∀ {ν b} x (Δ ρs : ICtx ν) τ → B.All (Δ ⊢ x ↓ τ) b →
AllP (B.All (∃₂ λ r (r∈Δ : r ∈ (x ∷ ρs)) → Δ ⊢ r ↓ τ))
(match1st-recover Δ ρs τ b)
match1st-recover-sound x Δ ρs τ (true p) = now (true (x , (here refl) , p))
match1st-recover-sound x Δ ρs τ false = _
≅⟨ PR.sym (right-identity refl (match1st Δ ρs τ)) ⟩P
match1st'-sound Δ ρs τ >>=-congP lem
where
lem : ∀ {v} → B.All (∃₂ λ r (r∈Δ : r ∈ ρs)→ Δ ⊢ r ↓ τ) v →
AllP (B.All (∃₂ λ r (r∈Δ : r ∈ x ∷ ρs) → Δ ⊢ r ↓ τ)) (now v)
lem (true (r , r∈ρs , p)) = now (true (r , (there r∈ρs) , p))
lem false = now false
-- {!match1st'-sound Δ ρs τ!}
match1st'-sound : ∀ {ν} (Δ ρs : ICtx ν) τ →
AllP (B.All (∃₂ λ r (r∈Δ : r ∈ ρs) → Δ ⊢ r ↓ τ)) (match1st Δ ρs τ)
match1st'-sound Δ [] τ = now false
match1st'-sound Δ (x ∷ ρs) τ = _
≅⟨ match1st-comp Δ x ρs τ ⟩P
match-sound Δ τ x >>=-congP match1st-recover-sound x Δ ρs τ
resolve'-sound : ∀ {ν} (Δ : ICtx ν) r → AllP (B.All (Δ ⊢ᵣ r)) (resolve Δ r)
resolve'-sound Δ (simpl x) = _
≅⟨ PR.sym (right-identity refl (match1st Δ Δ x)) ⟩P
match1st'-sound Δ Δ x >>=-congP (λ x → now (B.all-map x (λ{ (r , r∈Δ , p) → r-simp r∈Δ p })))
resolve'-sound Δ (a ⇒ b) = _
≅⟨ PR.sym (right-identity refl (resolve (a ∷ Δ) b)) ⟩P
resolve'-sound (a ∷ Δ) b >>=-congP (λ x → now (B.all-map x r-iabs))
resolve'-sound Δ (∀' r) = _
≅⟨ PR.sym (right-identity refl (resolve (ictx-weaken Δ) r)) ⟩P
resolve'-sound (ictx-weaken Δ) r >>=-congP (λ x → now (B.all-map x r-tabs))
-- Soundness means:
-- for all terminating runs of the algorithm we have a finite resolution proof.
sound : ∀ {ν} (Δ : ICtx ν) r → All (B.All (Δ ⊢ᵣ r)) (resolve Δ r)
sound Δ r = AllP-sound (resolve'-sound Δ r)
| {
"alphanum_fraction": 0.5566445662,
"avg_line_length": 45.9470198675,
"ext": "agda",
"hexsha": "a00b9d0dc9ccc2677ea193dd709efa1293f20952",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/Infinite/Algorithm/Soundness.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/Infinite/Algorithm/Soundness.agda",
"max_line_length": 101,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/Infinite/Algorithm/Soundness.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 2615,
"size": 6938
} |
{-# OPTIONS --safe --experimental-lossy-unification #-}
{-
This file contains a proof that the generator of Π₃S² has
hopf invariant ±1.
-}
module Cubical.Homotopy.HopfInvariant.HopfMap where
open import Cubical.Homotopy.HopfInvariant.Base
open import Cubical.Homotopy.Hopf
open S¹Hopf
open import Cubical.Homotopy.Connected
open import Cubical.Homotopy.HSpace
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.Groups.Sn
open import Cubical.ZCohomology.RingStructure.CupProduct
open import Cubical.ZCohomology.RingStructure.RingLaws
open import Cubical.ZCohomology.Gysin
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Path
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Pointed.Homogeneous
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Data.Sum
open import Cubical.Data.Sigma
open import Cubical.Data.Int hiding (_+'_)
open import Cubical.Data.Nat renaming (_+_ to _+ℕ_ ; _·_ to _·ℕ_)
open import Cubical.Data.Unit
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.ZAction
open import Cubical.Algebra.Group.Exact
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.Instances.Int
open import Cubical.Algebra.Group.GroupPath
open import Cubical.HITs.Pushout
open import Cubical.HITs.Join
open import Cubical.HITs.S1 renaming (_·_ to _*_)
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp
open import Cubical.HITs.Truncation
renaming (rec to trRec ; elim to trElim)
open import Cubical.HITs.SetTruncation
renaming (rec to sRec ; rec2 to sRec2
; elim to sElim ; elim2 to sElim2 ; map to sMap)
open import Cubical.HITs.PropositionalTruncation
renaming (rec to pRec)
HopfMap : S₊∙ 3 →∙ S₊∙ 2
fst HopfMap x = JoinS¹S¹→TotalHopf (Iso.inv (IsoSphereJoin 1 1) x) .fst
snd HopfMap = refl
-- We use the Hopf fibration in order to connect it to the Gysin Sequence
module hopfS¹ =
Hopf S1-AssocHSpace (sphereElim2 _ (λ _ _ → squash₁) ∣ refl ∣₁)
S¹Hopf = hopfS¹.Hopf
E* = hopfS¹.TotalSpacePush²'
IsoE*join = hopfS¹.joinIso₂
IsoTotalHopf' = hopfS¹.joinIso₁
CP² = hopfS¹.TotalSpaceHopfPush²
fibr = hopfS¹.P
TotalHopf' : Type _
TotalHopf' = Σ (S₊ 2) S¹Hopf
IsoJoins : (join S¹ (join S¹ S¹)) ≡ join S¹ (S₊ 3)
IsoJoins = cong (join S¹) (isoToPath (IsoSphereJoin 1 1))
-- CP² is 1-connected
conCP² : (x y : CP²) → ∥ x ≡ y ∥₂
conCP² x y = sRec2 squash₂ (λ p q → ∣ p ∙ sym q ∣₂) (conCP²' x) (conCP²' y)
where
conCP²' : (x : CP²) → ∥ x ≡ inl tt ∥₂
conCP²' (inl x) = ∣ refl ∣₂
conCP²' (inr x) = sphereElim 1 {A = λ x → ∥ inr x ≡ inl tt ∥₂}
(λ _ → squash₂) ∣ sym (push (inl base)) ∣₂ x
conCP²' (push a i) = main a i
where
indLem : ∀ {ℓ} {A : hopfS¹.TotalSpaceHopfPush → Type ℓ}
→ ((a : _) → isProp (A a))
→ A (inl base)
→ ((a : hopfS¹.TotalSpaceHopfPush) → A a)
indLem {A = A} p b =
PushoutToProp p
(sphereElim 0 (λ _ → p _) b)
(sphereElim 0 (λ _ → p _) (subst A (push (base , base)) b))
main : (a : hopfS¹.TotalSpaceHopfPush)
→ PathP (λ i → ∥ Path CP² (push a i) (inl tt) ∥₂)
(conCP²' (inl tt)) (conCP²' (inr (hopfS¹.induced a)))
main = indLem (λ _ → isOfHLevelPathP' 1 squash₂ _ _)
λ j → ∣ (λ i → push (inl base) (~ i ∧ j)) ∣₂
module GysinS² = Gysin (CP² , inl tt) fibr conCP² 2 idIso refl
E'S⁴Iso : Iso GysinS².E' (S₊ 5)
E'S⁴Iso =
compIso IsoE*join
(compIso (Iso→joinIso idIso (IsoSphereJoin 1 1))
(IsoSphereJoin 1 3))
isContrH³E : isContr (coHom 3 (GysinS².E'))
isContrH³E =
subst isContr (sym (isoToPath
(fst (Hⁿ-Sᵐ≅0 2 4
λ p → snotz (sym (cong (predℕ ∘ predℕ) p)))))
∙ cong (coHom 3) (sym (isoToPath E'S⁴Iso)))
isContrUnit
isContrH⁴E : isContr (coHom 4 (GysinS².E'))
isContrH⁴E =
subst isContr (sym (isoToPath
(fst (Hⁿ-Sᵐ≅0 3 4
λ p → snotz (sym (cong (predℕ ∘ predℕ ∘ predℕ) p)))))
∙ cong (coHom 4) (sym (isoToPath E'S⁴Iso)))
isContrUnit
-- We will need a bunch of elimination principles
joinS¹S¹→Groupoid : ∀ {ℓ} (P : join S¹ S¹ → Type ℓ)
→ ((x : _) → isGroupoid (P x))
→ P (inl base)
→ (x : _) → P x
joinS¹S¹→Groupoid P grp b =
transport (λ i → (x : (isoToPath (invIso (IsoSphereJoin 1 1))) i)
→ P (transp (λ j → isoToPath (invIso (IsoSphereJoin 1 1)) (i ∨ j)) i x))
(sphereElim _ (λ _ → grp _) b)
TotalHopf→Gpd : ∀ {ℓ} (P : hopfS¹.TotalSpaceHopfPush → Type ℓ)
→ ((x : _) → isGroupoid (P x))
→ P (inl base)
→ (x : _) → P x
TotalHopf→Gpd P grp b =
transport (λ i → (x : sym (isoToPath IsoTotalHopf') i)
→ P (transp (λ j → isoToPath IsoTotalHopf' (~ i ∧ ~ j)) i x))
(joinS¹S¹→Groupoid _ (λ _ → grp _) b)
TotalHopf→Gpd' : ∀ {ℓ} (P : Σ (S₊ 2) hopfS¹.Hopf → Type ℓ)
→ ((x : _) → isGroupoid (P x))
→ P (north , base)
→ (x : _) → P x
TotalHopf→Gpd' P grp b =
transport (λ i → (x : ua (_ , hopfS¹.isEquivTotalSpaceHopfPush→TotalSpace) i)
→ P (transp (λ j → ua (_ , hopfS¹.isEquivTotalSpaceHopfPush→TotalSpace)
(i ∨ j)) i x))
(TotalHopf→Gpd _ (λ _ → grp _) b)
CP²→Groupoid : ∀ {ℓ} {P : CP² → Type ℓ}
→ ((x : _) → is2Groupoid (P x))
→ (b : P (inl tt))
→ (s2 : ((x : _) → P (inr x)))
→ PathP (λ i → P (push (inl base) i)) b (s2 north)
→ (x : _) → P x
CP²→Groupoid {P = P} grp b s2 pp (inl x) = b
CP²→Groupoid {P = P} grp b s2 pp (inr x) = s2 x
CP²→Groupoid {P = P} grp b s2 pp (push a i₁) = lem a i₁
where
lem : (a : hopfS¹.TotalSpaceHopfPush) → PathP (λ i → P (push a i)) b (s2 _)
lem = TotalHopf→Gpd _ (λ _ → isOfHLevelPathP' 3 (grp _) _ _) pp
-- The function inducing the iso H²(S²) ≅ H²(CP²)
H²S²→H²CP²-raw : (S₊ 2 → coHomK 2) → (CP² → coHomK 2)
H²S²→H²CP²-raw f (inl x) = 0ₖ _
H²S²→H²CP²-raw f (inr x) = f x -ₖ f north
H²S²→H²CP²-raw f (push a i) =
TotalHopf→Gpd (λ x → 0ₖ 2
≡ f (hopfS¹.TotalSpaceHopfPush→TotalSpace x .fst) -ₖ f north)
(λ _ → isOfHLevelTrunc 4 _ _)
(sym (rCancelₖ 2 (f north)))
a i
H²S²→H²CP² : coHomGr 2 (S₊ 2) .fst → coHomGr 2 CP² .fst
H²S²→H²CP² = sMap H²S²→H²CP²-raw
cancel-H²S²→H²CP² : (f : CP² → coHomK 2)
→ ∥ H²S²→H²CP²-raw (f ∘ inr) ≡ f ∥₁
cancel-H²S²→H²CP² f =
pRec squash₁
(λ p → pRec squash₁
(λ f → ∣ funExt f ∣₁)
(cancelLem p))
(connLem (f (inl tt)))
where
connLem : (x : coHomK 2) → ∥ x ≡ 0ₖ 2 ∥₁
connLem = coHomK-elim _ (λ _ → isOfHLevelSuc 1 squash₁) ∣ refl ∣₁
cancelLem : (p : f (inl tt) ≡ 0ₖ 2)
→ ∥ ((x : CP²) → H²S²→H²CP²-raw (f ∘ inr) x ≡ f x) ∥₁
cancelLem p = trRec squash₁ (λ pp →
∣ CP²→Groupoid (λ _ → isOfHLevelPath 4 (isOfHLevelTrunc 4) _ _)
(sym p)
(λ x → (λ i → f (inr x) -ₖ f (push (inl base) (~ i)))
∙∙ (λ i → f (inr x) -ₖ p i)
∙∙ rUnitₖ 2 (f (inr x))) pp ∣₁)
help
where
help :
hLevelTrunc 1
(PathP (λ i₁ → H²S²→H²CP²-raw (f ∘ inr) (push (inl base) i₁)
≡ f (push (inl base) i₁))
(sym p)
(((λ i₁ → f (inr north) -ₖ f (push (inl base) (~ i₁))) ∙∙
(λ i₁ → f (inr north) -ₖ p i₁) ∙∙ rUnitₖ 2 (f (inr north)))))
help = isConnectedPathP 1 (isConnectedPath 2 (isConnectedKn 1) _ _) _ _ .fst
H²CP²≅H²S² : GroupIso (coHomGr 2 CP²) (coHomGr 2 (S₊ 2))
Iso.fun (fst H²CP²≅H²S²) = sMap (_∘ inr)
Iso.inv (fst H²CP²≅H²S²) = H²S²→H²CP²
Iso.rightInv (fst H²CP²≅H²S²) =
sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → trRec {B = Iso.fun (fst H²CP²≅H²S²) (Iso.inv (fst H²CP²≅H²S²) ∣ f ∣₂)
≡ ∣ f ∣₂}
(isOfHLevelPath 2 squash₂ _ _)
(λ p → cong ∣_∣₂ (funExt λ x → cong (λ y → (f x) -ₖ y) p ∙ rUnitₖ 2 (f x)))
(Iso.fun (PathIdTruncIso _)
(isContr→isProp (isConnectedKn 1) ∣ f north ∣ ∣ 0ₖ 2 ∣))
Iso.leftInv (fst H²CP²≅H²S²) =
sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → pRec (squash₂ _ _) (cong ∣_∣₂) (cancel-H²S²→H²CP² f)
snd H²CP²≅H²S² =
makeIsGroupHom
(sElim2 (λ _ _ → isOfHLevelPath 2 squash₂ _ _) λ f g → refl)
H²CP²≅ℤ : GroupIso (coHomGr 2 CP²) ℤGroup
H²CP²≅ℤ = compGroupIso H²CP²≅H²S² (Hⁿ-Sⁿ≅ℤ 1)
-- ⌣ gives a groupEquiv H²(CP²) ≃ H⁴(CP²)
⌣Equiv : GroupEquiv (coHomGr 2 CP²) (coHomGr 4 CP²)
fst (fst ⌣Equiv) = GysinS².⌣-hom 2 .fst
snd (fst ⌣Equiv) = isEq⌣
where
isEq⌣ : isEquiv (GysinS².⌣-hom 2 .fst)
isEq⌣ =
SES→isEquiv
(GroupPath _ _ .fst (invGroupEquiv
(isContr→≃Unit isContrH³E
, makeIsGroupHom λ _ _ → refl)))
(GroupPath _ _ .fst (invGroupEquiv
(isContr→≃Unit isContrH⁴E
, makeIsGroupHom λ _ _ → refl)))
(GysinS².susp∘ϕ 1)
(GysinS².⌣-hom 2)
(GysinS².p-hom 4)
(GysinS².Ker-⌣e⊂Im-Susp∘ϕ _)
(GysinS².Ker-p⊂Im-⌣e _)
snd ⌣Equiv = GysinS².⌣-hom 2 .snd
-- The generator of H²(CP²)
genCP² : coHom 2 CP²
genCP² = ∣ CP²→Groupoid (λ _ → isOfHLevelTrunc 4)
(0ₖ _)
∣_∣
refl ∣₂
inrInjective : (f g : CP² → coHomK 2) → ∥ f ∘ inr ≡ g ∘ inr ∥₁
→ Path (coHom 2 CP²) ∣ f ∣₂ ∣ g ∣₂
inrInjective f g = pRec (squash₂ _ _)
(λ p → pRec (squash₂ _ _) (λ id → trRec (squash₂ _ _)
(λ pp → cong ∣_∣₂
(funExt (CP²→Groupoid
(λ _ → isOfHLevelPath 4 (isOfHLevelTrunc 4) _ _)
id
(funExt⁻ p)
(compPathR→PathP pp))))
(conn2 (f (inl tt)) (g (inl tt)) id
(cong f (push (inl base))
∙ (funExt⁻ p north) ∙ cong g (sym (push (inl base))))))
(conn (f (inl tt)) (g (inl tt))))
where
conn : (x y : coHomK 2) → ∥ x ≡ y ∥₁
conn = coHomK-elim _ (λ _ → isSetΠ λ _ → isOfHLevelSuc 1 squash₁)
(coHomK-elim _ (λ _ → isOfHLevelSuc 1 squash₁) ∣ refl ∣₁)
conn2 : (x y : coHomK 2) (p q : x ≡ y) → hLevelTrunc 1 (p ≡ q)
conn2 x y p q =
Iso.fun (PathIdTruncIso _)
(isContr→isProp (isConnectedPath _ (isConnectedKn 1) x y) ∣ p ∣ ∣ q ∣)
-- A couple of basic lemma concerning the hSpace structure on S¹
private
invLooperLem₁ : (a x : S¹)
→ (invEq (hopfS¹.μ-eq a) x) * a ≡ (invLooper a * x) * a
invLooperLem₁ a x =
secEq (hopfS¹.μ-eq a) x
∙∙ cong (_* x) (rCancelS¹ a)
∙∙ AssocHSpace.μ-assoc S1-AssocHSpace a (invLooper a) x
∙ commS¹ _ _
invLooperLem₂ : (a x : S¹) → invEq (hopfS¹.μ-eq a) x ≡ invLooper a * x
invLooperLem₂ a x = sym (retEq (hopfS¹.μ-eq a) (invEq (hopfS¹.μ-eq a) x))
∙∙ cong (invEq (hopfS¹.μ-eq a)) (invLooperLem₁ a x)
∙∙ retEq (hopfS¹.μ-eq a) (invLooper a * x)
rotLoop² : (a : S¹) → Path (a ≡ a) (λ i → rotLoop (rotLoop a i) (~ i)) refl
rotLoop² =
sphereElim 0 (λ _ → isGroupoidS¹ _ _ _ _)
λ i j → hcomp (λ {k → λ { (i = i1) → base
; (j = i0) → base
; (j = i1) → base}})
base
-- We prove that the generator of CP² given by Gysin is the same one
-- as genCP², which is much easier to work with
Gysin-e≡genCP² : GysinS².e ≡ genCP²
Gysin-e≡genCP² =
inrInjective _ _ ∣ funExt (λ x → funExt⁻ (cong fst (main x)) south) ∣₁
where
mainId : (x : Σ (S₊ 2) hopfS¹.Hopf)
→ Path (hLevelTrunc 4 _) ∣ fst x ∣ ∣ north ∣
mainId = uncurry λ { north → λ y → cong ∣_∣ₕ (merid base ∙ sym (merid y))
; south → λ y → cong ∣_∣ₕ (sym (merid y))
; (merid a i) → main a i}
where
main : (a : S¹) → PathP (λ i → (y : hopfS¹.Hopf (merid a i))
→ Path (HubAndSpoke (Susp S¹) 3) ∣ merid a i ∣ ∣ north ∣)
(λ y → cong ∣_∣ₕ (merid base ∙ sym (merid y)))
λ y → cong ∣_∣ₕ (sym (merid y))
main a =
toPathP
(funExt λ x →
cong (transport (λ i₁
→ Path (HubAndSpoke (Susp S¹) 3) ∣ merid a i₁ ∣ ∣ north ∣))
((λ i → (λ z → cong ∣_∣ₕ
(merid base
∙ sym (merid (transport
(λ j → uaInvEquiv (hopfS¹.μ-eq a) (~ i) j) x))) z))
∙ λ i → cong ∣_∣ₕ (merid base
∙ sym (merid (transportRefl (invEq (hopfS¹.μ-eq a) x) i))))
∙∙ (λ i → transp (λ i₁ → Path (HubAndSpoke (Susp S¹) 3)
∣ merid a (i₁ ∨ i) ∣ ∣ north ∣) i
(compPath-filler' (cong ∣_∣ₕ (sym (merid a)))
(cong ∣_∣ₕ (merid base
∙ sym (merid (invLooperLem₂ a x i)))) i))
∙∙ cong ((cong ∣_∣ₕ) (sym (merid a)) ∙_)
(cong (cong ∣_∣ₕ) (cong sym (symDistr (merid base)
(sym (merid (invLooper a * x)))))
∙ cong sym (SuspS¹-hom (invLooper a) x)
∙ symDistr ((cong ∣_∣ₕ) (merid (invLooper a) ∙ sym (merid base)))
((cong ∣_∣ₕ) (merid x ∙ sym (merid base)))
∙ isCommΩK 2 (sym (λ i₁ → ∣ (merid x
∙ (λ i₂ → merid base (~ i₂))) i₁ ∣))
(sym (λ i₁ → ∣ (merid (invLooper a)
∙ (λ i₂ → merid base (~ i₂))) i₁ ∣))
∙ cong₂ _∙_ (cong sym (SuspS¹-inv a)
∙ cong-∙ ∣_∣ₕ (merid a) (sym (merid base)))
(cong (cong ∣_∣ₕ) (symDistr (merid x) (sym (merid base)))
∙ cong-∙ ∣_∣ₕ (merid base) (sym (merid x))))
∙∙ (λ j → (λ i₁ → ∣ merid a (~ i₁ ∨ j) ∣) ∙ ((λ i₁ → ∣ merid a (i₁ ∨ j) ∣)
∙ (λ i₁ → ∣ merid base (~ i₁ ∨ j) ∣))
∙ (λ i₁ → ∣ merid base (i₁ ∨ j) ∣)
∙ (λ i₁ → ∣ merid x (~ i₁) ∣ₕ))
∙∙ sym (lUnit _)
∙∙ sym (assoc _ _ _)
∙∙ (sym (lUnit _) ∙ sym (lUnit _) ∙ sym (lUnit _)))
gen' : (x : S₊ 2) → preThom.Q (CP² , inl tt) fibr (inr x) →∙ coHomK-ptd 2
fst (gen' x) north = ∣ north ∣
fst (gen' x) south = ∣ x ∣
fst (gen' x) (merid a i₁) = mainId (x , a) (~ i₁)
snd (gen' x) = refl
gen'Id : GysinS².c (inr north) .fst ≡ gen' north .fst
gen'Id = cong fst (GysinS².cEq (inr north) ∣ push (inl base) ∣₂)
∙ (funExt lem)
where
lem : (qb : _) →
∣ (subst (fst ∘ preThom.Q (CP² , inl tt) fibr)
(sym (push (inl base))) qb) ∣
≡ gen' north .fst qb
lem north = refl
lem south = cong ∣_∣ₕ (sym (merid base))
lem (merid a i) j =
hcomp (λ k →
λ { (i = i0) → ∣ merid a (~ k ∧ j) ∣
; (i = i1) → ∣ merid base (~ j) ∣
; (j = i0) → ∣ transportRefl (merid a i) (~ k) ∣
; (j = i1) → ∣ compPath-filler
(merid base) (sym (merid a)) k (~ i) ∣ₕ})
(hcomp (λ k →
λ { (i = i0) → ∣ merid a (j ∨ ~ k) ∣
; (i = i1) → ∣ merid base (~ j ∨ ~ k) ∣
; (j = i0) → ∣ merid a (~ k ∨ i) ∣
; (j = i1) → ∣ merid base (~ i ∨ ~ k) ∣ₕ})
∣ south ∣)
setHelp : (x : S₊ 2)
→ isSet (preThom.Q (CP² , inl tt) fibr (inr x) →∙ coHomK-ptd 2)
setHelp = sphereElim _ (λ _ → isProp→isOfHLevelSuc 1 (isPropIsOfHLevel 2))
(isOfHLevel↑∙' 0 1)
main : (x : S₊ 2) → (GysinS².c (inr x) ≡ gen' x)
main = sphereElim _ (λ x → isOfHLevelPath 2 (setHelp x) _ _)
(→∙Homogeneous≡ (isHomogeneousKn _) gen'Id)
isGenerator≃ℤ : ∀ {ℓ} (G : Group ℓ) (g : fst G) → Type ℓ
isGenerator≃ℤ G g =
Σ[ e ∈ GroupIso G ℤGroup ] abs (Iso.fun (fst e) g) ≡ 1
isGenerator≃ℤ-e : isGenerator≃ℤ (coHomGr 2 CP²) GysinS².e
isGenerator≃ℤ-e =
subst (isGenerator≃ℤ (coHomGr 2 CP²)) (sym Gysin-e≡genCP²)
(H²CP²≅ℤ , refl)
-- Alternative definition of the hopfMap
HopfMap' : S₊ 3 → S₊ 2
HopfMap' x =
hopfS¹.TotalSpaceHopfPush→TotalSpace
(Iso.inv IsoTotalHopf'
(Iso.inv (IsoSphereJoin 1 1) x)) .fst
hopfMap≡HopfMap' : HopfMap ≡ (HopfMap' , refl)
hopfMap≡HopfMap' =
ΣPathP ((funExt (λ x →
cong (λ x → JoinS¹S¹→TotalHopf x .fst)
(sym (Iso.rightInv IsoTotalHopf'
(Iso.inv (IsoSphereJoin 1 1) x)))
∙ sym (lem (Iso.inv IsoTotalHopf'
(Iso.inv (IsoSphereJoin 1 1) x)))))
, flipSquare (sym (rUnit refl) ◁ λ _ _ → north))
where
lem : (x : _) → hopfS¹.TotalSpaceHopfPush→TotalSpace x .fst
≡ JoinS¹S¹→TotalHopf (Iso.fun IsoTotalHopf' x) .fst
lem (inl x) = refl
lem (inr x) = refl
lem (push (base , snd₁) i) = refl
lem (push (loop i₁ , a) i) k = merid (rotLoop² a (~ k) i₁) i
CP²' : Type _
CP²' = Pushout {A = S₊ 3} (λ _ → tt) HopfMap'
PushoutReplaceBase : ∀ {ℓ ℓ' ℓ''} {A B : Type ℓ} {C : Type ℓ'} {D : Type ℓ''}
{f : A → C} {g : A → D} (e : B ≃ A)
→ Pushout (f ∘ fst e) (g ∘ fst e) ≡ Pushout f g
PushoutReplaceBase {f = f} {g = g} =
EquivJ (λ _ e → Pushout (f ∘ fst e) (g ∘ fst e) ≡ Pushout f g) refl
CP2≡CP²' : CP²' ≡ CP²
CP2≡CP²' =
PushoutReplaceBase
(isoToEquiv (compIso (invIso (IsoSphereJoin 1 1)) (invIso IsoTotalHopf')))
-- packaging everything up:
⌣equiv→pres1 : ∀ {ℓ} {G H : Type ℓ} → (G ≡ H)
→ (g₁ : coHom 2 G) (h₁ : coHom 2 H)
→ (fstEq : (Σ[ ϕ ∈ GroupEquiv (coHomGr 2 G) ℤGroup ]
abs (fst (fst ϕ) g₁) ≡ 1))
→ (sndEq : ((Σ[ ϕ ∈ GroupEquiv (coHomGr 2 H) ℤGroup ]
abs (fst (fst ϕ) h₁) ≡ 1)))
→ isEquiv {A = coHom 2 G} {B = coHom 4 G} (_⌣ g₁)
→ (3rdEq : GroupEquiv (coHomGr 4 H) ℤGroup)
→ abs (fst (fst 3rdEq) (h₁ ⌣ h₁)) ≡ 1
⌣equiv→pres1 {G = G} = J (λ H _ → (g₁ : coHom 2 G) (h₁ : coHom 2 H)
→ (fstEq : (Σ[ ϕ ∈ GroupEquiv (coHomGr 2 G) ℤGroup ]
abs (fst (fst ϕ) g₁) ≡ 1))
→ (sndEq : ((Σ[ ϕ ∈ GroupEquiv (coHomGr 2 H) ℤGroup ]
abs (fst (fst ϕ) h₁) ≡ 1)))
→ isEquiv {A = coHom 2 G} {B = coHom 4 G} (_⌣ g₁)
→ (3rdEq : GroupEquiv (coHomGr 4 H) ℤGroup)
→ abs (fst (fst 3rdEq) (h₁ ⌣ h₁)) ≡ 1)
help
where
help : (g₁ h₁ : coHom 2 G)
→ (fstEq : (Σ[ ϕ ∈ GroupEquiv (coHomGr 2 G) ℤGroup ]
abs (fst (fst ϕ) g₁) ≡ 1))
→ (sndEq : ((Σ[ ϕ ∈ GroupEquiv (coHomGr 2 G) ℤGroup ]
abs (fst (fst ϕ) h₁) ≡ 1)))
→ isEquiv {A = coHom 2 G} {B = coHom 4 G} (_⌣ g₁)
→ (3rdEq : GroupEquiv (coHomGr 4 G) ℤGroup)
→ abs (fst (fst 3rdEq) (h₁ ⌣ h₁)) ≡ 1
help g h (ϕ , idg) (ψ , idh) ⌣eq ξ =
⊎→abs _ _
(groupEquivPresGen _
(compGroupEquiv main (compGroupEquiv (invGroupEquiv main) ψ))
h (abs→⊎ _ _ (cong abs (cong (fst (fst ψ)) (retEq (fst main) h))
∙ idh)) (compGroupEquiv main ξ))
where
lem₁ : ((fst (fst ψ) h) ≡ 1) ⊎ (fst (fst ψ) h ≡ -1)
→ abs (fst (fst ϕ) h) ≡ 1
lem₁ p = ⊎→abs _ _ (groupEquivPresGen _ ψ h p ϕ)
lem₂ : ((fst (fst ϕ) h) ≡ 1) ⊎ (fst (fst ϕ) h ≡ -1)
→ ((fst (fst ϕ) g) ≡ 1) ⊎ (fst (fst ϕ) g ≡ -1)
→ (h ≡ g) ⊎ (h ≡ (-ₕ g))
lem₂ (inl x) (inl x₁) =
inl (sym (retEq (fst ϕ) h)
∙∙ cong (invEq (fst ϕ)) (x ∙ sym x₁)
∙∙ retEq (fst ϕ) g)
lem₂ (inl x) (inr x₁) =
inr (sym (retEq (fst ϕ) h)
∙∙ cong (invEq (fst ϕ)) x
∙ IsGroupHom.presinv (snd (invGroupEquiv ϕ)) (negsuc zero)
∙∙ cong (-ₕ_) (cong (invEq (fst ϕ)) (sym x₁) ∙ (retEq (fst ϕ) g)))
lem₂ (inr x) (inl x₁) =
inr (sym (retEq (fst ϕ) h)
∙∙ cong (invEq (fst ϕ)) x
∙∙ (IsGroupHom.presinv (snd (invGroupEquiv ϕ)) 1
∙ cong (-ₕ_) (cong (invEq (fst ϕ)) (sym x₁) ∙ (retEq (fst ϕ) g))))
lem₂ (inr x) (inr x₁) =
inl (sym (retEq (fst ϕ) h)
∙∙ cong (invEq (fst ϕ)) (x ∙ sym x₁)
∙∙ retEq (fst ϕ) g)
-ₕeq : ∀ {ℓ} {A : Type ℓ} (n : ℕ) → Iso (coHom n A) (coHom n A)
Iso.fun (-ₕeq n) = -ₕ_
Iso.inv (-ₕeq n) = -ₕ_
Iso.rightInv (-ₕeq n) =
sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → -ₖ^2 (f x))
Iso.leftInv (-ₕeq n) =
sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → -ₖ^2 (f x))
theEq : coHom 2 G ≃ coHom 4 G
theEq = compEquiv (_ , ⌣eq) (isoToEquiv (-ₕeq 4))
lem₃ : (h ≡ g) ⊎ (h ≡ (-ₕ g)) → isEquiv {A = coHom 2 G} (_⌣ h)
lem₃ (inl x) = subst isEquiv (λ i → _⌣ (x (~ i))) ⌣eq
lem₃ (inr x) =
subst isEquiv (funExt (λ x → -ₕDistᵣ 2 2 x g) ∙ (λ i → _⌣ (x (~ i))))
(theEq .snd)
main : GroupEquiv (coHomGr 2 G) (coHomGr 4 G)
fst main = _ ,
(lem₃ (lem₂ (abs→⊎ _ _ (lem₁ (abs→⊎ _ _ idh))) (abs→⊎ _ _ idg)))
snd main =
makeIsGroupHom λ g1 g2 → rightDistr-⌣ _ _ g1 g2 h
-- The hopf invariant is ±1 for both definitions of the hopf map
HopfInvariant-HopfMap' :
abs (HopfInvariant zero (HopfMap' , λ _ → HopfMap' (snd (S₊∙ 3)))) ≡ 1
HopfInvariant-HopfMap' =
cong abs (cong (Iso.fun (fst (Hopfβ-Iso zero (HopfMap' , refl))))
(transportRefl (⌣-α 0 (HopfMap' , refl))))
∙ ⌣equiv→pres1 (sym CP2≡CP²')
GysinS².e (Hopfα zero (HopfMap' , refl))
(l isGenerator≃ℤ-e)
(GroupIso→GroupEquiv (Hopfα-Iso 0 (HopfMap' , refl)) , refl)
(snd (fst ⌣Equiv))
(GroupIso→GroupEquiv (Hopfβ-Iso zero (HopfMap' , refl)))
where
l : Σ[ ϕ ∈ GroupIso (coHomGr 2 CP²) ℤGroup ]
(abs (Iso.fun (fst ϕ) GysinS².e) ≡ 1)
→ Σ[ ϕ ∈ GroupEquiv (coHomGr 2 CP²) ℤGroup ]
(abs (fst (fst ϕ) GysinS².e) ≡ 1)
l p = (GroupIso→GroupEquiv (fst p)) , (snd p)
HopfInvariant-HopfMap : abs (HopfInvariant zero HopfMap) ≡ 1
HopfInvariant-HopfMap = cong abs (cong (HopfInvariant zero) hopfMap≡HopfMap')
∙ HopfInvariant-HopfMap'
| {
"alphanum_fraction": 0.5304913619,
"avg_line_length": 39.5825932504,
"ext": "agda",
"hexsha": "278c0641319440784bf0d931bc59f5ea656793f6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Homotopy/HopfInvariant/HopfMap.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Homotopy/HopfInvariant/HopfMap.agda",
"max_line_length": 81,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Homotopy/HopfInvariant/HopfMap.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 9320,
"size": 22285
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Lift where
open import Level
open import Categories.Category
liftC : ∀ {o ℓ e} o′ ℓ′ e′ → Category o ℓ e → Category (o ⊔ o′) (ℓ ⊔ ℓ′) (e ⊔ e′)
liftC o′ ℓ′ e′ C = record
{ Obj = Lift o′ Obj
; _⇒_ = λ X Y → Lift ℓ′ (lower X ⇒ lower Y)
; _≈_ = λ f g → Lift e′ (lower f ≈ lower g)
; id = lift id
; _∘_ = λ f g → lift (lower f ∘ lower g)
; assoc = lift assoc
; sym-assoc = lift sym-assoc
; identityˡ = lift identityˡ
; identityʳ = lift identityʳ
; identity² = lift identity²
; equiv = record
{ refl = lift Equiv.refl
; sym = λ eq → lift (Equiv.sym (lower eq))
; trans = λ eq eq′ → lift (Equiv.trans (lower eq) (lower eq′))
}
; ∘-resp-≈ = λ eq eq′ → lift (∘-resp-≈ (lower eq) (lower eq′))
}
where open Category C
| {
"alphanum_fraction": 0.5471478463,
"avg_line_length": 30.6785714286,
"ext": "agda",
"hexsha": "12710ad22d035df3dd0a1ffb83216335fb494499",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Lift.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "laMudri/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Lift.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Lift.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 323,
"size": 859
} |
-- Andreas, 2012-03-13
module Issue585t where
postulate
A : Set
a : A -- just so that A is not empty and the constraints are solvable
-- however, Agda picks the wrong solution
data B : Set where
inn : A -> B
out : B -> A
out (inn a) = a
postulate
P : (y : A) (z : B) → Set
p : (x : B) → P (out x) x
mutual
d : B
d = inn _ -- Y
g : P (out d) d
g = p _ -- X
-- Agda previously solved d = inn (out d)
--
-- out X = out d = out (inn Y) = Y
-- X = d
--
-- Now this does not pass the occurs check, so unsolved metas should remain.
| {
"alphanum_fraction": 0.5417376491,
"avg_line_length": 18.34375,
"ext": "agda",
"hexsha": "26a87ebed527a0656ad2261d36ad52b250337333",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Fail/Issue585t.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Fail/Issue585t.agda",
"max_line_length": 76,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue585t.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 207,
"size": 587
} |
postulate
ℤ : Set
n : ℤ
-_ _! : ℤ → ℤ
-- Note that an unrelated prefix/postfix operator can be combined with
-- itself:
ok : ℤ
ok = n ! ! ! !
also-ok : ℤ
also-ok = - - - - - - - n
| {
"alphanum_fraction": 0.5177664975,
"avg_line_length": 14.0714285714,
"ext": "agda",
"hexsha": "3b044928076d1c88cd20f74e9bd218381dd27ad3",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/By-default-no-fixity.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/By-default-no-fixity.agda",
"max_line_length": 70,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/By-default-no-fixity.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 76,
"size": 197
} |
open import Prelude
module Implicits.Resolution.Infinite.Resolution where
open import Coinduction
open import Data.Fin.Substitution
open import Data.List
open import Data.List.Any.Membership using (map-mono)
open import Data.List.Any
open Membership-≡
open import Implicits.Syntax
open import Implicits.Substitutions
module Coinductive where
infixl 5 _⊢ᵣ_ _⊢_↓_
mutual
data _⊢_↓_ {ν} (Δ : ICtx ν) : Type ν → SimpleType ν → Set where
i-simp : ∀ a → Δ ⊢ simpl a ↓ a
i-iabs : ∀ {ρ₁ ρ₂ a} → ∞ (Δ ⊢ᵣ ρ₁) → Δ ⊢ ρ₂ ↓ a → Δ ⊢ ρ₁ ⇒ ρ₂ ↓ a
i-tabs : ∀ {ρ a} b → Δ ⊢ ρ tp[/tp b ] ↓ a → Δ ⊢ ∀' ρ ↓ a
data _⊢ᵣ_ {ν} (Δ : ICtx ν) : Type ν → Set where
r-simp : ∀ {r τ} → (r ∈ Δ) → Δ ⊢ r ↓ τ → Δ ⊢ᵣ simpl τ
r-iabs : ∀ {ρ₁ ρ₂} → ((ρ₁ ∷ Δ) ⊢ᵣ ρ₂) → Δ ⊢ᵣ (ρ₁ ⇒ ρ₂)
r-tabs : ∀ {ρ} → (ictx-weaken Δ ⊢ᵣ ρ) → Δ ⊢ᵣ ∀' ρ
mutual
-- extending contexts is safe: it preserves the r ↓ a relation
-- (this is not true for Oliveira's deterministic calculus)
⊆-r↓a : ∀ {ν} {Δ Δ' : ICtx ν} {a r} → Δ ⊢ r ↓ a → Δ ⊆ Δ' → Δ' ⊢ r ↓ a
⊆-r↓a (i-simp a) _ = i-simp a
⊆-r↓a (i-iabs x₁ x₂) f = i-iabs (♯ (⊆-Δ⊢a (♭ x₁) f)) (⊆-r↓a x₂ f)
⊆-r↓a (i-tabs b x₁) f = i-tabs b (⊆-r↓a x₁ f)
-- extending contexts is safe: it preserves the ⊢ᵣ a relation
-- (this is not true for Oliveira's deterministic calculus)
⊆-Δ⊢a : ∀ {ν} {Δ Δ' : ICtx ν} {a} → Δ ⊢ᵣ a → Δ ⊆ Δ' → Δ' ⊢ᵣ a
⊆-Δ⊢a (r-simp x₁ x₂) f = r-simp (f x₁) (⊆-r↓a x₂ f)
⊆-Δ⊢a (r-iabs x₁) f =
r-iabs (⊆-Δ⊢a x₁ (λ{ (here px) → here px ; (there x₂) → there (f x₂) }))
⊆-Δ⊢a (r-tabs x) f = r-tabs (⊆-Δ⊢a x f')
where
f' = map-mono (flip TypeSubst._/_ TypeSubst.wk) f
module Inductive where
infixl 5 _⊢ᵣ_ _⊢_↓_
mutual
data _⊢_↓_ {ν} (Δ : ICtx ν) : Type ν → SimpleType ν → Set where
i-simp : ∀ a → Δ ⊢ simpl a ↓ a
i-iabs : ∀ {ρ₁ ρ₂ a} → (Δ ⊢ᵣ ρ₁) → Δ ⊢ ρ₂ ↓ a → Δ ⊢ ρ₁ ⇒ ρ₂ ↓ a
i-tabs : ∀ {ρ a} b → Δ ⊢ ρ tp[/tp b ] ↓ a → Δ ⊢ ∀' ρ ↓ a
data _⊢ᵣ_ {ν} (Δ : ICtx ν) : Type ν → Set where
r-simp : ∀ {r τ} → (r ∈ Δ) → Δ ⊢ r ↓ τ → Δ ⊢ᵣ simpl τ
r-iabs : ∀ {ρ₁ ρ₂} → ((ρ₁ ∷ Δ) ⊢ᵣ ρ₂) → Δ ⊢ᵣ (ρ₁ ⇒ ρ₂)
r-tabs : ∀ {ρ} → (ictx-weaken Δ ⊢ᵣ ρ) → Δ ⊢ᵣ ∀' ρ
mutual -- extending contexts is safe: it preserves the r ↓ a relation
-- (this is not true for Oliveira's deterministic calculus)
⊆-r↓a : ∀ {ν} {Δ Δ' : ICtx ν} {a r} → Δ ⊢ r ↓ a → Δ ⊆ Δ' → Δ' ⊢ r ↓ a
⊆-r↓a (i-simp a) _ = i-simp a
⊆-r↓a (i-iabs x₁ x₂) f = i-iabs (⊆-Δ⊢a x₁ f) (⊆-r↓a x₂ f)
⊆-r↓a (i-tabs b x₁) f = i-tabs b (⊆-r↓a x₁ f)
-- extending contexts is safe: it preserves the ⊢ᵣ a relation
-- (this is not true for Oliveira's deterministic calculus)
⊆-Δ⊢a : ∀ {ν} {Δ Δ' : ICtx ν} {a} → Δ ⊢ᵣ a → Δ ⊆ Δ' → Δ' ⊢ᵣ a
⊆-Δ⊢a (r-simp x₁ x₂) f = r-simp (f x₁) (⊆-r↓a x₂ f)
⊆-Δ⊢a (r-iabs x₁) f =
r-iabs (⊆-Δ⊢a x₁ (λ{ (here px) → here px ; (there x₂) → there (f x₂) }))
⊆-Δ⊢a (r-tabs x) f = r-tabs (⊆-Δ⊢a x f')
where
f' = map-mono (flip TypeSubst._/_ TypeSubst.wk) f
open Inductive public
| {
"alphanum_fraction": 0.5174437561,
"avg_line_length": 38.8227848101,
"ext": "agda",
"hexsha": "b9a041e708eb4e6c1753c172502ae47f84a8da7c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/Infinite/Resolution.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/Infinite/Resolution.agda",
"max_line_length": 78,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/Infinite/Resolution.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 1528,
"size": 3067
} |
{-# OPTIONS --safe #-}
module Cubical.Data.NatMinusOne where
open import Cubical.Data.NatMinusOne.Base public
open import Cubical.Data.NatMinusOne.Properties public
| {
"alphanum_fraction": 0.8072289157,
"avg_line_length": 27.6666666667,
"ext": "agda",
"hexsha": "f1838c6e8bf2dd3c5e70103cee7cf30e36444224",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Data/NatMinusOne.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Data/NatMinusOne.agda",
"max_line_length": 54,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Data/NatMinusOne.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 39,
"size": 166
} |
module Lang.Irrelevance where
open import Type
postulate .axiom : ∀{ℓ}{T : Type{ℓ}} -> .T -> T
| {
"alphanum_fraction": 0.6494845361,
"avg_line_length": 16.1666666667,
"ext": "agda",
"hexsha": "23abad321b5409d0ca27ecca42adf06419cfe11f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Lang/Irrelevance.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Lang/Irrelevance.agda",
"max_line_length": 47,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Lang/Irrelevance.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 36,
"size": 97
} |
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Library.Data.Both where
open import Light.Level using (Level ; Setω)
open import Light.Variable.Sets
open import Light.Variable.Levels
open import Light.Library.Relation.Binary
using (SelfTransitive ; SelfSymmetric ; Reflexive)
open import Light.Library.Relation.Binary.Equality.Decidable using (DecidableEquality ; DecidableSelfEquality)
record Dependencies : Setω where
record Library (dependencies : Dependencies) : Setω where
field
ℓf : Level → Level → Level
Both : Set aℓ → Set bℓ → Set (ℓf aℓ bℓ)
both : 𝕒 → 𝕓 → Both 𝕒 𝕓
first : Both 𝕒 𝕓 → 𝕒
second : Both 𝕒 𝕓 → 𝕓
⦃ equals ⦄ :
∀ ⦃ a‐c‐equals : DecidableEquality 𝕒 𝕔 ⦄ ⦃ b‐d‐equals : DecidableEquality 𝕓 𝕕 ⦄
→ DecidableEquality (Both 𝕒 𝕓) (Both 𝕔 𝕕)
open Library ⦃ ... ⦄ public
| {
"alphanum_fraction": 0.643533123,
"avg_line_length": 36.5769230769,
"ext": "agda",
"hexsha": "92252cd759e840f26725af6773771ac0d2ef1376",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "Zambonifofex/lightlib",
"max_forks_repo_path": "Light/Library/Data/Both.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "Zambonifofex/lightlib",
"max_issues_repo_path": "Light/Library/Data/Both.agda",
"max_line_length": 110,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "zamfofex/lightlib",
"max_stars_repo_path": "Light/Library/Data/Both.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z",
"num_tokens": 290,
"size": 951
} |
module Cats.Category.Fun where
open import Cats.Trans public using (Trans ; component ; natural ; id ; _∘_)
open import Relation.Binary using (Rel ; IsEquivalence ; _Preserves₂_⟶_⟶_)
open import Level
open import Cats.Category
open import Cats.Functor using (Functor)
module _ {lo la l≈ lo′ la′ l≈′}
(C : Category lo la l≈)
(D : Category lo′ la′ l≈′)
where
infixr 4 _≈_
private
module C = Category C
module D = Category D
open D.≈
open D.≈-Reasoning
Obj : Set (lo ⊔ la ⊔ l≈ ⊔ lo′ ⊔ la′ ⊔ l≈′)
Obj = Functor C D
_⇒_ : Obj → Obj → Set (lo ⊔ la ⊔ la′ ⊔ l≈′)
_⇒_ = Trans
record _≈_ {F G} (θ ι : F ⇒ G) : Set (lo ⊔ l≈′) where
constructor ≈-intro
field
≈-elim : ∀ {c} → component θ c D.≈ component ι c
open _≈_ public
equiv : ∀ {F G} → IsEquivalence (_≈_ {F} {G})
equiv = record
{ refl = ≈-intro refl
; sym = λ eq → ≈-intro (sym (≈-elim eq))
; trans = λ eq₁ eq₂ → ≈-intro (trans (≈-elim eq₁) (≈-elim eq₂))
}
Fun : Category (lo ⊔ la ⊔ l≈ ⊔ lo′ ⊔ la′ ⊔ l≈′) (lo ⊔ la ⊔ la′ ⊔ l≈′) (lo ⊔ l≈′)
Fun = record
{ Obj = Obj
; _⇒_ = _⇒_
; _≈_ = _≈_
; id = id
; _∘_ = _∘_
; equiv = equiv
; ∘-resp = λ θ≈θ′ ι≈ι′ → ≈-intro (D.∘-resp (≈-elim θ≈θ′) (≈-elim ι≈ι′))
; id-r = ≈-intro D.id-r
; id-l = ≈-intro D.id-l
; assoc = ≈-intro D.assoc
}
| {
"alphanum_fraction": 0.5140591204,
"avg_line_length": 21.671875,
"ext": "agda",
"hexsha": "8d35e9fc015a9cf2727c6738c8c87633cacd2b62",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alessio-b-zak/cats",
"max_forks_repo_path": "Cats/Category/Fun.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "alessio-b-zak/cats",
"max_issues_repo_path": "Cats/Category/Fun.agda",
"max_line_length": 82,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3b69911c4c6ec380ddf6a0f4510d3a755734b86",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alessio-b-zak/cats",
"max_stars_repo_path": "Cats/Category/Fun.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 605,
"size": 1387
} |
{-
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
| {
"alphanum_fraction": 0.5090937846,
"avg_line_length": 32.2602040816,
"ext": "agda",
"hexsha": "52d9c36f3612005abb9081d14d88b654bd473ebb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/Foundations/Isomorphism.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/Foundations/Isomorphism.agda",
"max_line_length": 95,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/Foundations/Isomorphism.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2547,
"size": 6323
} |
{-# OPTIONS --sized-types #-}
open import Relation.Binary.Core
module SelectSort.Correctness.Order {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_)
(trans≤ : Transitive _≤_) where
open import Data.List
open import Data.Product
open import Data.Sum
open import Function using (_∘_)
open import List.Sorted _≤_
open import Order.Total _≤_ tot≤
open import Size
open import SList
open import SList.Order _≤_
open import SList.Order.Properties _≤_
open import SelectSort _≤_ tot≤
lemma-select-≤ : {ι : Size}(x : A) → (xs : SList A {ι}) → proj₁ (select x xs) ≤ x
lemma-select-≤ x snil = refl≤
lemma-select-≤ x (y ∙ ys)
with tot≤ x y
... | inj₁ x≤y = lemma-select-≤ x ys
... | inj₂ y≤x = trans≤ (lemma-select-≤ y ys) y≤x
lemma-select-*≤ : {ι : Size}(x : A) → (xs : SList A {ι}) → proj₁ (select x xs) *≤ proj₂ (select x xs)
lemma-select-*≤ x snil = genx
lemma-select-*≤ x (y ∙ ys)
with tot≤ x y
... | inj₁ x≤y = gecx (trans≤ (lemma-select-≤ x ys) x≤y) (lemma-select-*≤ x ys)
... | inj₂ y≤x = gecx (trans≤ (lemma-select-≤ y ys) y≤x) (lemma-select-*≤ y ys)
lemma-select-≤-*≤ : {ι : Size}{b x : A}{xs : SList A {ι}} → b ≤ x → b *≤ xs → b ≤ proj₁ (select x xs) × b *≤ proj₂ (select x xs)
lemma-select-≤-*≤ b≤x genx = b≤x , genx
lemma-select-≤-*≤ {x = x} b≤x (gecx {x = y} b≤y b*≤ys)
with tot≤ x y
... | inj₁ x≤y = proj₁ (lemma-select-≤-*≤ b≤x b*≤ys) , gecx (trans≤ b≤x x≤y) (proj₂ (lemma-select-≤-*≤ b≤x b*≤ys))
... | inj₂ y≤x = proj₁ (lemma-select-≤-*≤ b≤y b*≤ys) , gecx (trans≤ b≤y y≤x) (proj₂ (lemma-select-≤-*≤ b≤y b*≤ys))
lemma-selectSort-*≤ : {ι : Size}{x : A}{xs : SList A {ι}} → x *≤ xs → x *≤ selectSort xs
lemma-selectSort-*≤ genx = genx
lemma-selectSort-*≤ (gecx x≤y x*≤ys)
with lemma-select-≤-*≤ x≤y x*≤ys
... | (x≤z , x*≤zs) = gecx x≤z (lemma-selectSort-*≤ x*≤zs)
lemma-selectSort-sorted : {ι : Size}(xs : SList A {ι}) → Sorted (unsize A (selectSort xs))
lemma-selectSort-sorted snil = nils
lemma-selectSort-sorted (x ∙ xs) = lemma-slist-sorted (lemma-selectSort-*≤ (lemma-select-*≤ x xs)) (lemma-selectSort-sorted (proj₂ (select x xs)))
theorem-selectSort-sorted : (xs : List A) → Sorted (unsize A (selectSort (size A xs)))
theorem-selectSort-sorted = lemma-selectSort-sorted ∘ (size A)
| {
"alphanum_fraction": 0.6001757469,
"avg_line_length": 41.3818181818,
"ext": "agda",
"hexsha": "897f934286bcc1798b6dcad213ab108d62a7cc0f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/SelectSort/Correctness/Order.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/SelectSort/Correctness/Order.agda",
"max_line_length": 146,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/SelectSort/Correctness/Order.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 932,
"size": 2276
} |
------------------------------------------------------------------------------
-- tptp4X yields an error because a duplicate formula
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
postulate
D : Set
true false : D
_≡_ : D → D → Set
data Bool : D → Set where
btrue : Bool true
bfalse : Bool false
{-# ATP axioms btrue false #-}
postulate foo : ∀ d → d ≡ d
{-# ATP prove foo btrue #-}
| {
"alphanum_fraction": 0.4019448947,
"avg_line_length": 28.0454545455,
"ext": "agda",
"hexsha": "ee87691dbb9233e5eed1b7f832071189d85de1ca",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Fail/Errors/DuplicateFormulaTPTP4XError.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Fail/Errors/DuplicateFormulaTPTP4XError.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Fail/Errors/DuplicateFormulaTPTP4XError.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 128,
"size": 617
} |
{-# OPTIONS --universe-polymorphism #-}
-- Check that unification can handle levels
module LevelUnification where
open import Common.Level
data _≡_ {a}{A : Set a}(x : A) : ∀ {b}{B : Set b} → B → Set where
refl : x ≡ x
sym₁ : ∀ a b (A : Set a)(B : Set b)(x : A)(y : B) → x ≡ y → y ≡ x
sym₁ a .a A .A x .x refl = refl
sym₂ : ∀ a b (A : Set (lsuc a))(B : Set b)(x : A)(y : B) → x ≡ y → y ≡ x
sym₂ a .(lsuc a) A .A x .x refl = refl
homogenous : ∀ a (A : Set a)(x y : A) → x ≡ y → Set₁
homogenous a A x .x refl = Set
| {
"alphanum_fraction": 0.5442307692,
"avg_line_length": 27.3684210526,
"ext": "agda",
"hexsha": "b73ebfd7b8db6ea42c8f9daa1a85dbf324d92d2f",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/LevelUnification.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/LevelUnification.agda",
"max_line_length": 72,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/LevelUnification.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 215,
"size": 520
} |
{-# OPTIONS --type-in-type #-} -- DANGER!
postulate HOLE : {A : Set} -> A -- MORE DANGER!
infixr 6 _\\ _/quad/
infixr 6 _\\&\indent
infixl 2 &_
infixr 3 [_
infixr 5 _,_
infixr 7 _]
infixr 5 _/xor/_ _/land/_ _/lor/_ _+_ _/ll/_ _/gg/_
infixr 5 /Sigma/ /Sigmap/ /Pi/ /Pip/ lambda tlambda
infixr 2 id
infixl 1 WHEN
infixl 1 AND
-- Definitions used in the main body
data ⊥ : Set where
record ⊤ : Set where
constructor /epsilon/
record Π (A : Set) (B : A -> Set) : Set where
constructor _,_
field fst : A
field snd : B(fst)
syntax Π A (\x -> B) = Π x ∈ A ∙ B
_×_ : Set → Set → Set
(A × B) = Π x ∈ A ∙ B
data 𝔹 : Set where
/false/ : 𝔹
/true/ : 𝔹
if_then_else_ : ∀ {A : 𝔹 -> Set} -> (b : 𝔹) -> A(/true/) -> A(/false/) -> A(b)
if /false/ then T else F = F
if /true/ then T else F = T
⟨_⟩ : 𝔹 → Set
⟨ /false/ ⟩ = ⊥
⟨ /true/ ⟩ = ⊤
data ℕ : Set where
zero : ℕ
succ : ℕ -> ℕ
one = succ zero
two = succ one
three = succ two
four = succ three
_+n_ : ℕ → ℕ → ℕ
zero +n k = k
(succ j) +n k = succ(j +n k)
_⊔_ : ℕ → ℕ → ℕ
zero ⊔ n = n
succ m ⊔ zero = succ m
succ m ⊔ succ n = succ (m ⊔ n)
_↑_ : Set → ℕ → Set
(A ↑ zero) = ⊤
(A ↑ (succ n)) = (A × (A ↑ n))
len : ∀ {k} → (𝔹 ↑ k) → ℕ
len {k} n = k
/IF/_/THEN/_/ELSE/_ : forall {A : 𝔹 -> Set} -> (b : 𝔹) -> A(/true/) -> A(/false/) -> A(b)
/IF/ /false/ /THEN/ T /ELSE/ F = F
/IF/ /true/ /THEN/ T /ELSE/ F = T
-- Binary arithmetic
indn : ∀ {k} {A : Set} → A → (A → A) → (𝔹 ↑ k) → A
indn {zero} e f n = e
indn {succ k} e f (/false/ , n) = indn e (λ x → f (f x)) n
indn {succ k} e f (/true/ , n) = f (indn e (λ x → f (f x)) n)
unary : ∀ {k} → (𝔹 ↑ k) → ℕ
unary = indn zero succ
/zerop/ : ∀ {k} → (𝔹 ↑ k)
/zerop/ {zero} = /epsilon/
/zerop/ {succ n} = (/false/ , /zerop/)
/epsilon/[_] : ∀ {k} → (n : 𝔹 ↑ k) → (𝔹 ↑ unary n)
/epsilon/[ n ] = /zerop/
/onep/ : ∀ {k} → (𝔹 ↑ succ k)
/onep/ = (/true/ , /zerop/)
/one/ : (𝔹 ↑ one)
/one/ = /onep/
/max/ : ∀ {k} → (𝔹 ↑ k)
/max/ {zero} = /epsilon/
/max/ {succ n} = (/true/ , /max/)
/IMPOSSIBLE/ : {A : Set} → {{p : ⊥}} → A
/IMPOSSIBLE/ {A} {{()}}
/not/ : 𝔹 → 𝔹
/not/ /false/ = /true/
/not/ /true/ = /false/
/extend/ : ∀ {k} → (𝔹 ↑ k) → (𝔹 ↑ succ k)
/extend/ {zero} _ = (/false/ , /epsilon/)
/extend/ {succ k} (b , n) = (b , /extend/ n)
/succp/ : ∀ {k} → (𝔹 ↑ k) → (𝔹 ↑ succ k)
/succp/ {zero} n = (/false/ , /epsilon/)
/succp/ {succ k} (/false/ , n) = (/true/ , /extend/ n)
/succp/ {succ k} (/true/ , n) = (/false/ , /succp/ n)
_/land/_ : 𝔹 → 𝔹 → 𝔹
(/false/ /land/ b) = /false/
(/true/ /land/ b) = b
_/lor/_ : 𝔹 → 𝔹 → 𝔹
(/false/ /lor/ b) = b
(/true/ /lor/ b) = /true/
/neg/ : 𝔹 → 𝔹
/neg/ /false/ = /true/
/neg/ /true/ = /false/
_/xor/_ : 𝔹 → 𝔹 → 𝔹
(/false/ /xor/ b) = b
(/true/ /xor/ /false/) = /true/
(/true/ /xor/ /true/) = /false/
/carry/ : 𝔹 → 𝔹 → 𝔹 → 𝔹
/carry/ /false/ a b = a /land/ b
/carry/ /true/ a b = a /lor/ b
addclen : ∀ {j k} → 𝔹 → (𝔹 ↑ j) → (𝔹 ↑ k) → ℕ
addclen {zero} {k} /false/ m n = k
addclen {zero} {zero} /true/ m n = one
addclen {zero} {succ k} /true/ m (b , n) = succ (addclen b m n)
addclen {succ j} {zero} /false/ m n = succ j
addclen {succ j} {zero} /true/ (a , m) n = succ (addclen a m n)
addclen {succ j} {succ k} c (a , m) (b , n) = succ (addclen (/carry/ c a b) m n)
addlen : ∀ {j k} → (𝔹 ↑ j) → (𝔹 ↑ k) → ℕ
addlen = addclen /false/
/addc/ : ∀ {j k} c → (m : 𝔹 ↑ j) → (n : 𝔹 ↑ k) → (𝔹 ↑ addclen c m n)
/addc/ {zero} {k} /false/ m n = n
/addc/ {zero} {zero} /true/ m n = /one/
/addc/ {zero} {succ k} /true/ m (b , n) = (/not/ b , /addc/ b m n)
/addc/ {succ j} {zero} /false/ (a , m) n = (a , m)
/addc/ {succ j} {zero} /true/ (a , m) n = (/not/ a , /addc/ a m n)
/addc/ {succ j} {succ k} c (a , m) (b , n) = ((c /xor/ a /xor/ b) , (/addc/ (/carry/ c a b) m n))
_+_ : ∀ {j k} → (m : 𝔹 ↑ j) → (n : 𝔹 ↑ k) → (𝔹 ↑ addlen m n)
_+_ = /addc/ /false/
/succ/ : ∀ {k} → (n : 𝔹 ↑ k) → (𝔹 ↑ addclen /true/ /epsilon/ n)
/succ/ = /addc/ /true/ /epsilon/
dindn : (A : ∀ {k} → (𝔹 ↑ k) → Set) → (∀ {k} → A(/zerop/ {k})) → (∀ {k} (n : 𝔹 ↑ k) → A(n) → A(/succ/(n))) → ∀ {k} → (n : 𝔹 ↑ k) → A(n)
dindn A e f {zero} n = e
dindn A e f {succ k} (/false/ , n) = dindn (λ {j} m → A (/false/ , m)) e (λ {j} m x → f (/true/ , m) (f (/false/ , m) x)) n
dindn A e f {succ k} (/true/ , n) = f (/false/ , n) (dindn (λ {j} m → A (/false/ , m)) e (λ {j} m x → f (/true/ , m) (f (/false/ , m) x)) n)
_++_ : ∀ {A j k} → (A ↑ j) → (A ↑ k) → (A ↑ (j +n k))
_++_ {A} {zero} xs ys = ys
_++_ {A} {succ j} (x , xs) ys = (x , xs ++ ys)
_/ll/_ : ∀ {j k} → (𝔹 ↑ j) → (n : 𝔹 ↑ k) → (𝔹 ↑ (unary n +n j))
(m /ll/ n) = (/zerop/ {unary n} ++ m)
_-n_ : ℕ → ℕ → ℕ
(m -n zero) = m
(zero -n n) = zero
(succ m -n succ n) = (m -n n)
drop : ∀ {A j} (k : ℕ) → (A ↑ j) → (A ↑ (j -n k))
drop zero xs = xs
drop {A} {zero} (succ k) xs = /epsilon/
drop {A} {succ j} (succ k) (x , xs) = drop k xs
_/gg/_ : ∀ {j k} → (𝔹 ↑ j) → (n : 𝔹 ↑ k) → (𝔹 ↑ (j -n unary n))
m /gg/ n = drop (unary n) m
/truncate/ : ∀ {j k} → (𝔹 ↑ j) → (𝔹 ↑ k)
/truncate/ {j} {zero} n = /epsilon/
/truncate/ {zero} {succ k} n = /zerop/
/truncate/ {succ j} {succ k} (a , n) = (a , /truncate/ n)
-- Finite sets
EncodableIn : ∀ {k} → Set → (𝔹 ↑ k) → Set
EncodableIn = HOLE
record FSet {k} (n : 𝔹 ↑ k) : Set where
field Carrier : Set
field .encodable : EncodableIn Carrier n
open FSet public
/sizeof/ : ∀ {k} → {n : 𝔹 ↑ k} → FSet(n) → (𝔹 ↑ k)
/sizeof/ {k} {n} A = n
data _≡_ {A : Set} (x : A) : A → Set where
refl : (x ≡ x)
data ℂ : Set where
less : ℂ
eq : ℂ
gtr : ℂ
isless : ℂ → Set
isless less = ⊤
isless _ = ⊥
isleq : ℂ → Set
isleq gtr = ⊥
isleq _ = ⊤
cmpb : 𝔹 → 𝔹 → ℂ
cmpb /false/ /false/ = eq
cmpb /false/ /true/ = less
cmpb /true/ /false/ = gtr
cmpb /true/ /true/ = eq
cmpcb : 𝔹 → 𝔹 → ℂ → ℂ
cmpcb /false/ /false/ c = c
cmpcb /false/ /true/ c = less
cmpcb /true/ /false/ c = gtr
cmpcb /true/ /true/ c = c
cmpc : ∀ {j k} → (𝔹 ↑ j) → (𝔹 ↑ k) → ℂ → ℂ
cmpc {zero} {zero} m n c = c
cmpc {zero} {succ k} m (b , n) c = cmpc m n (cmpcb /false/ b c)
cmpc {succ j} {zero} (a , m) n c = cmpc m n (cmpcb a /false/ c)
cmpc {succ j} {succ k} (a , m) (b , n) c = cmpc m n (cmpcb a b c)
cmp : ∀ {j k} → (𝔹 ↑ j) → (𝔹 ↑ k) → ℂ
cmp m n = cmpc m n eq
_<_ : ∀ {j k} → (𝔹 ↑ j) → (𝔹 ↑ k) → Set
(m < n) = isless (cmp m n)
_≤_ : ∀ {j k} → (𝔹 ↑ j) → (𝔹 ↑ k) → Set
(m ≤ n) with cmp m n
(m ≤ n) | gtr = ⊥
(m ≤ n) | _ = ⊤
borrow : 𝔹 → 𝔹 → 𝔹 → 𝔹
borrow /false/ /false/ c = c
borrow /false/ /true/ c = /true/
borrow /true/ /false/ c = /false/
borrow /true/ /true/ c = c
subc : ∀ {j k} → (m : 𝔹 ↑ j) → (n : 𝔹 ↑ k) → 𝔹 → (𝔹 ↑ j)
subc {zero} m n c = /epsilon/
subc {succ j} {zero} (a , m) n c = ((a /xor/ c) , (subc m n (borrow a /false/ c)))
subc {succ j} {succ k} (a , m) (b , n) c = ((a /xor/ b /xor/ c) , (subc m n (borrow a b c)))
_∸_ : ∀ {j k} → (m : 𝔹 ↑ j) → (n : 𝔹 ↑ k) → (𝔹 ↑ j)
(m ∸ n) = subc m n /false/
/FSetp/ : ∀ {j k} {m : 𝔹 ↑ j} -> (n : 𝔹 ↑ k) -> {p : n < m} -> FSet(m)
/FSetp/ n = record { Carrier = FSet(n); encodable = HOLE }
/FSet/ : ∀ {k} -> (n : 𝔹 ↑ k) -> FSet(/succp/ n)
/FSet/ n = record { Carrier = FSet(n); encodable = HOLE }
/nothingp/ : ∀ {k} {n : 𝔹 ↑ k} → FSet(n)
/nothingp/ = record { Carrier = ⊥; encodable = HOLE }
/nothing/ : FSet(/epsilon/)
/nothing/ = /nothingp/
/boolp/ : ∀ {k} {n : 𝔹 ↑ k} {p : /epsilon/ < n} → FSet(n)
/boolp/ = record { Carrier = 𝔹; encodable = HOLE }
/bool/ : FSet(/one/)
/bool/ = /boolp/
/unitp/ : ∀ {k} {n : 𝔹 ↑ k} → FSet(n)
/unitp/ = record { Carrier = ⊤; encodable = HOLE }
/unit/ : FSet(/epsilon/)
/unit/ = /unitp/
/bitsp/ : ∀ {j k} {m : 𝔹 ↑ j} → (n : 𝔹 ↑ k) -> {p : n ≤ m} -> FSet(m)
/bitsp/ n = record { Carrier = (𝔹 ↑ unary n); encodable = HOLE }
/bits/ : ∀ {k} (n : 𝔹 ↑ k) -> {p : n ≤ n} -> FSet(n)
/bits/ n {p} = /bitsp/ n {p}
/Pi/ : ∀ {j k} -> {m : 𝔹 ↑ j} {n : 𝔹 ↑ k} -> (A : FSet(m)) -> (Carrier(A) → FSet(n)) -> FSet(m + n)
/Pi/ A B = record { Carrier = Π x ∈ (Carrier A) ∙ Carrier (B x) ; encodable = HOLE }
syntax /Pi/ A (λ x → B) = /prod/ x /in/ A /cdot/ B
/Pip/ : ∀ {j k} -> {m : 𝔹 ↑ j} -> {n : 𝔹 ↑ k} -> (A : FSet(m)) -> {p : m ≤ n} → (Carrier(A) → FSet(n ∸ m)) -> FSet(n)
/Pip/ A B = record { Carrier = Π x ∈ (Carrier A) ∙ Carrier (B x) ; encodable = HOLE }
syntax /Pip/ A (λ x → B) = /prodp/ x /in/ A /cdot/ B
/Sigma/ : ∀ {j k} -> {m : 𝔹 ↑ j} {n : 𝔹 ↑ k} -> (A : FSet(m)) → ((Carrier A) → FSet(n)) -> FSet(n /ll/ m)
/Sigma/ A B = record { Carrier = (x : Carrier A) → (Carrier (B x)) ; encodable = HOLE }
syntax /Sigma/ A (λ x → B) = /sum/ x /in/ A /cdot/ B
/Sigmap/ : ∀ {j k} -> {m : 𝔹 ↑ j} {n : 𝔹 ↑ k} -> (A : FSet(m)) → {p : m ≤ n} → ((Carrier A) → FSet(n /gg/ m)) -> FSet(n)
/Sigmap/ A B = record { Carrier = (x : Carrier A) → (Carrier (B x)) ; encodable = HOLE }
syntax /Sigmap/ A (λ x → B) = /sump/ x /in/ A /cdot/ B
lambda : ∀ {A : Set} {B : A → Set} → (∀ x → B(x)) → (∀ x → B(x))
lambda f = f
syntax lambda (λ x → e) = /fn/ x /cdot/ e
tlambda : ∀ {k} {n : 𝔹 ↑ k} (A : FSet(n)) {B : Carrier A → Set} → (∀ x → B(x)) → (∀ x → B(x))
tlambda A f = f
syntax tlambda A (λ x → e) = /fn/ x /in/ A /cdot/ e
/indn/ :
{h : ∀ {k} → (𝔹 ↑ k) → ℕ} →
{g : ∀ {k} → (n : 𝔹 ↑ k) → (𝔹 ↑ h(n))} →
(A : ∀ {k} → (n : 𝔹 ↑ k) → FSet(g(n))) →
(∀ {k} → Carrier(A(/zerop/ {k}))) →
(∀ {k} (n : 𝔹 ↑ k) → Carrier(A(n)) → Carrier(A(/one/ + n))) →
∀ {k} → (n : 𝔹 ↑ k) → Carrier(A(n))
/indn/ A e f = dindn (λ n → Carrier(A(n))) e (λ n x → g n (f n x)) where
g : ∀ {k} → (n : 𝔹 ↑ k) → Carrier(A(/one/ + n)) → Carrier(A(/succ/(n)))
g {zero} n x = x
g {succ k} (/false/ , n) x = x
g {succ k} (/true/ , n) x = x
-- Stuff to help with LaTeX layout
id : ∀ {k} → {n : 𝔹 ↑ k} → (A : FSet(n)) → (Carrier A) → (Carrier A)
id A x = x
typeof : ∀ {k} → {n : 𝔹 ↑ k} → (A : FSet(n)) → (Carrier A) → Set
typeof A x = Carrier A
WHEN : ∀ {k} → {n : 𝔹 ↑ k} → (A : FSet(n)) → {B : Carrier A → Set} → (∀ x → B(x)) → (∀ x → B(x))
WHEN A F = F
AND : ∀ {k} → {n : 𝔹 ↑ k} → (A : FSet(n)) → {B : Carrier A → Set} → (∀ x → B(x)) → (∀ x → B(x))
AND A F = F
[_ : ∀ {A k} → (A ↑ k) → (A ↑ k)
[_ x = x
_] : ∀ {A} → A → (A ↑ one)
_] x = (x , /epsilon/)
_\\ : forall {A : Set} -> A -> A
x \\ = x
_/quad/ : forall {A : Set} -> A -> A
x /quad/ = x
_\\&\indent : forall {A : Set} -> A -> A
x \\&\indent = x
&_ : forall {A : Set} -> A -> A
& x = x
syntax id A x = x &/in/ A
syntax WHEN A (λ x → B) = B &/WHEN/ x /in/ A
syntax AND A (λ x → B) = B /AND/ x /in/ A
| {
"alphanum_fraction": 0.4602069432,
"avg_line_length": 27.5026595745,
"ext": "agda",
"hexsha": "7576d9a63e1785c81ae5ee5dac7a25804a7062cf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f7a0d4b54a7f1907fa2598cb65135cdbb3387514",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "asajeffrey/finite-dtypes",
"max_forks_repo_path": "prelude.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f7a0d4b54a7f1907fa2598cb65135cdbb3387514",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "asajeffrey/finite-dtypes",
"max_issues_repo_path": "prelude.agda",
"max_line_length": 140,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "f7a0d4b54a7f1907fa2598cb65135cdbb3387514",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "asajeffrey/finite-dtypes",
"max_stars_repo_path": "prelude.agda",
"max_stars_repo_stars_event_max_datetime": "2018-08-10T13:53:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-11T23:56:24.000Z",
"num_tokens": 5027,
"size": 10341
} |
{-# OPTIONS --universe-polymorphism #-}
module Categories.Graphs.Underlying where
open import Categories.Support.PropositionalEquality
open import Categories.Category
hiding (module Heterogeneous)
open import Categories.Categories
open import Categories.Graphs
open import Categories.Functor
using (Functor; module Functor; ≡⇒≣)
renaming (id to idF; _≡_ to _≡F_)
open import Data.Product
open import Graphs.Graph
open import Graphs.GraphMorphism
Underlying₀ : ∀ {o ℓ e} → Category o ℓ e → Graph o ℓ e
Underlying₀ C = record
{ Obj = Obj
; _↝_ = _⇒_
; _≈_ = _≡_
; equiv = equiv
} where open Category C
Underlying₁ : ∀ {o₁ ℓ₁ e₁ o₂ ℓ₂ e₂}
{X : Category o₁ ℓ₁ e₁}
{Y : Category o₂ ℓ₂ e₂}
→ Functor X Y
→ GraphMorphism (Underlying₀ X) (Underlying₀ Y)
Underlying₁ G = record
{ F₀ = G₀
; F₁ = G₁
; F-resp-≈ = G-resp-≡
}
where
open Functor G
renaming (F₀ to G₀; F₁ to G₁; F-resp-≡ to G-resp-≡)
Underlying : ∀ {o ℓ e} → Functor (Categories o ℓ e) (Graphs o ℓ e)
Underlying {o}{ℓ}{e} = record
{ F₀ = Underlying₀
; F₁ = Underlying₁
; identity = (λ x → ≣-refl) , (λ f → Heterogeneous.refl _)
; homomorphism = (λ x → ≣-refl) , (λ f → Heterogeneous.refl _)
; F-resp-≡ = λ {A B}{F G : Functor A B} → F-resp-≡ {A}{B}{F}{G}
}
where
module Graphs = Category (Graphs o ℓ e)
module Categories = Category (Categories o ℓ e)
.F-resp-≡ : ∀ {A B : Categories.Obj} {G H : Functor A B}
→ G ≡F H
→ Underlying₁ G ≈ Underlying₁ H
F-resp-≡ {A}{B}{G}{H} G≡H
= (≡⇒≣ G H G≡H) , (λ f → convert-~ (G≡H f))
where
open Heterogeneous (Underlying₀ B)
renaming (_~_ to _~₂_)
open Categories.Category.Heterogeneous B
renaming (_∼_ to _~₁_)
convert-~ : ∀ {a b c d}{x : B [ a , b ]}{y : B [ c , d ]} → x ~₁ y → x ~₂ y
convert-~ (≡⇒∼ foo) = ≈⇒~ foo | {
"alphanum_fraction": 0.5805785124,
"avg_line_length": 30.7301587302,
"ext": "agda",
"hexsha": "2876587b16e0edd96ea418d3c616b7c1273d8fde",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Graphs/Underlying.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Graphs/Underlying.agda",
"max_line_length": 83,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Graphs/Underlying.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 734,
"size": 1936
} |
import Algebra.FunctionProperties using (LeftZero; RightZero; _DistributesOverˡ_;_DistributesOverʳ_; Idempotent)
import Function using (_on_)
import Level
import Relation.Binary.EqReasoning as EqReasoning
import Relation.Binary.On using (isEquivalence)
import Algebra.Structures using (module IsCommutativeMonoid; IsCommutativeMonoid)
open import Relation.Binary using (module IsEquivalence; IsEquivalence; _Preserves₂_⟶_⟶_ ; Setoid)
open import Data.Product renaming (_,_ to _,,_) -- just to avoid clash with other commas
open import Preliminaries using (Rel; UniqueSolution; LowerBound)
module SemiNearRingRecords where
record SemiNearRing : Set₁ where -- \structure{1}{|SemiNearRing|}
field -- \structure{1.1}{Carriers, operators}
s : Set
_≃s_ : s → s → Set
zers : s
_+s_ : s → s → s
_*s_ : s → s → s
open Algebra.Structures using (IsCommutativeMonoid)
open Algebra.FunctionProperties _≃s_ using (LeftZero; RightZero)
field -- \structure{1.2}{Commutative monoid |(+,0)|}
isCommMon : IsCommutativeMonoid _≃s_ _+s_ zers
zeroˡ : LeftZero zers _*s_ -- expands to |∀ x → (zers *s x) ≃s zers|
zeroʳ : RightZero zers _*s_ -- expands to |∀ x → (x *s zers) ≃s zers|
_<*>_ : ∀ {x y u v} → (x ≃s y) → (u ≃s v) → (x *s u ≃s y *s v)
open Algebra.FunctionProperties _≃s_
using (Idempotent; _DistributesOverˡ_; _DistributesOverʳ_)
field -- \structure{1.3}{Distributive, idempotent, \ldots}
idem : Idempotent _+s_
distl : _*s_ DistributesOverˡ _+s_
distr : _*s_ DistributesOverʳ _+s_
-- expands to |∀ a b c → (a +s b) *s c ≃s (a *s c) +s (b *s c)|
infix 4 _≤s_
_≤s_ : s -> s -> Set
x ≤s y = x +s y ≃s y
infix 4 _≃s_; infixl 6 _+s_; infixl 7 _*s_
-- \structure{1.4}{Exporting commutative monoid operations}
open Algebra.Structures.IsCommutativeMonoid isCommMon public
hiding (refl)
renaming
( isEquivalence to isEquivs
; assoc to assocs
; comm to comms
; ∙-cong to _<+>_
; identityˡ to identityˡs
)
identityʳs = proj₂ identity
sSetoid : Setoid Level.zero Level.zero -- \structure{1.5}{Setoid, \ldots}
sSetoid = record { Carrier = s;
_≈_ = _≃s_;
isEquivalence = isEquivs }
open IsEquivalence isEquivs public
hiding (reflexive) renaming (refl to refls ; sym to syms ; trans to transs)
LowerBounds = LowerBound _≤s_ -- \structure{1.6}{Lower bounds}
record SemiNearRing2 : Set₁ where -- \structure{2}{|SemiNearRing2|}
field
snr : SemiNearRing
open SemiNearRing snr public -- public = export the "local" names from |SemiNearRing|
field -- \structure{2.1}{Plus and times for |u|, \ldots}
u : Set
_+u_ : u → u → u
_*u_ : u → u → u
u2s : u → s
_≃u_ : u → u → Set
_≃u_ = _≃s_ Function.on u2s
_u*s_ : u → s → s
_u*s_ u s = u2s u *s s
_s*u_ : s → u → s
_s*u_ s u = s *s u2s u
infix 4 _≃u_; infixl 6 _+u_; infixl 7 _*u_ _u*s_ _s*u_
uSetoid : Setoid Level.zero Level.zero
uSetoid = record { isEquivalence = Relation.Binary.On.isEquivalence u2s isEquivs }
_≤u_ : u → u → Set
_≤u_ = _≤s_ Function.on u2s
L : u → s → u → s → Set -- \structure{2.2}{Linear equation |L|}
L a y b x = y +s (a u*s x +s x s*u b) ≃s x
-- \structure{2.3}{Properties of |L|}
UniqueL = ∀ {a y b} → UniqueSolution _≃s_ (L a y b)
CongL = ∀ {a x b} -> ∀ {y y'} -> y ≃s y' -> L a y b x -> L a y' b x
| {
"alphanum_fraction": 0.5574272588,
"avg_line_length": 38.0388349515,
"ext": "agda",
"hexsha": "34d6dceddd0dea9f02a666554cae62944771323c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-29T04:53:48.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-29T04:53:48.000Z",
"max_forks_repo_head_hexsha": "43729ff822a0b05c6cb74016b04bdc93c627b0b1",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "DSLsofMath/ValiantAgda",
"max_forks_repo_path": "code/SemiNearRingRecords.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "43729ff822a0b05c6cb74016b04bdc93c627b0b1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "DSLsofMath/ValiantAgda",
"max_issues_repo_path": "code/SemiNearRingRecords.agda",
"max_line_length": 112,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "43729ff822a0b05c6cb74016b04bdc93c627b0b1",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "DSLsofMath/ValiantAgda",
"max_stars_repo_path": "code/SemiNearRingRecords.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-15T03:04:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-23T00:41:14.000Z",
"num_tokens": 1368,
"size": 3918
} |
{-# OPTIONS --cubical-compatible #-}
module NewWithoutK where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
infixl 20 _+_
_+_ : ℕ → ℕ → ℕ
zero + n = n
(suc m) + n = suc (m + n)
infixl 30 _*_
_*_ : ℕ → ℕ → ℕ
zero * n = zero
(suc m) * n = n + (m * n)
infixl 5 _⊎_
data _⊎_ (A B : Set) : Set where
inj₁ : A → A ⊎ B
inj₂ : B → A ⊎ B
infixl 10 _≡_
data _≡_ {A : Set} (a : A) : A → Set where
refl : a ≡ a
data _≤_ : ℕ → ℕ → Set where
z≤n : {n : ℕ} → zero ≤ n
s≤s : {m n : ℕ} → m ≤ n → suc m ≤ suc n
foo : (k l m : ℕ) → k ≡ l + m → ℕ
foo .(l + m) l m refl = zero
bar : (n : ℕ) → n ≤ n → ℕ
bar .zero z≤n = zero
bar .(suc m) (s≤s {m} p) = zero
baz : ∀ m n → m * n ≡ zero → m ≡ zero ⊎ n ≡ zero
baz zero n h = inj₁ refl
baz (suc m) zero h = inj₂ refl
baz (suc x) (suc x₁) ()
| {
"alphanum_fraction": 0.4817610063,
"avg_line_length": 18.488372093,
"ext": "agda",
"hexsha": "33048501685102f194c2523503b66c404c25e98f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/NewWithoutK.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/NewWithoutK.agda",
"max_line_length": 48,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/NewWithoutK.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 382,
"size": 795
} |
module Structure.Function.Domain where
import Lvl
open import Functional
import Structure.Function.Names as Names
open import Structure.Function
open import Lang.Instance
open import Logic
open import Logic.Propositional
open import Logic.Predicate
open import Structure.Setoid
open import Type
private variable ℓₒ ℓₒ₁ ℓₒ₂ ℓₗ ℓₗ₁ ℓₗ₂ : Lvl.Level
module _ {A : Type{ℓₒ₁}} ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ {B : Type{ℓₒ₂}} ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ (f : A → B) where
record Injective : Stmt{ℓₒ₁ Lvl.⊔ ℓₗ₁ Lvl.⊔ ℓₗ₂} where
constructor intro
field proof : Names.Injective(f)
injective = inst-fn Injective.proof
module _ {A : Type{ℓₒ₁}} {B : Type{ℓₒ₂}} ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ (f : A → B) where
record Surjective : Stmt{ℓₒ₁ Lvl.⊔ ℓₒ₂ Lvl.⊔ ℓₗ₂} where
constructor intro
field proof : Names.Surjective(f)
surjective = inst-fn Surjective.proof
module _ {A : Type{ℓₒ₁}} ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ {B : Type{ℓₒ₂}} ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ (f : A → B) where
record Bijective : Stmt{ℓₒ₁ Lvl.⊔ ℓₒ₂ Lvl.⊔ ℓₗ₁ Lvl.⊔ ℓₗ₂} where
constructor intro
field proof : Names.Bijective(f)
bijective = inst-fn Bijective.proof
module _ {A : Type{ℓₒ₁}} {B : Type{ℓₒ₂}} ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ (f : A → B) where
module _ (f⁻¹ : B → A) where
record Inverseᵣ : Stmt{ℓₒ₂ Lvl.⊔ ℓₗ₂} where
constructor intro
field proof : Names.Inverses(f)(f⁻¹)
inverseᵣ = inst-fn Inverseᵣ.proof
module _ ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ where
Invertibleᵣ = ∃(f⁻¹ ↦ Function(f⁻¹) ∧ Inverseᵣ(f⁻¹))
module _ {A : Type{ℓₒ₁}} ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ {B : Type{ℓₒ₂}} (f : A → B) where
module _ (f⁻¹ : B → A) where
Inverseₗ : Stmt
Inverseₗ = Inverseᵣ(f⁻¹)(f)
module Inverseₗ(inverseₗ) = Inverseᵣ{f = f⁻¹}{f⁻¹ = f}(inverseₗ)
inverseₗ : ⦃ inverseₗ : Inverseₗ ⦄ → Names.Inverses(f⁻¹)(f)
inverseₗ = inst-fn Inverseₗ.proof
module _ ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ where
Invertibleₗ = ∃(f⁻¹ ↦ Function(f⁻¹) ∧ Inverseₗ(f⁻¹))
module _ {A : Type{ℓₒ₁}} ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ {B : Type{ℓₒ₂}} ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ (f : A → B) where
module _ (f⁻¹ : B → A) where
Inverse = Inverseₗ(f)(f⁻¹) ∧ Inverseᵣ(f)(f⁻¹)
inverse-left : ⦃ inverse : Inverse ⦄ → Names.Inverses(f⁻¹)(f)
inverse-left = inst-fn(Inverseₗ.proof ∘ [∧]-elimₗ)
inverse-right : ⦃ inverse : Inverse ⦄ → Names.Inverses(f)(f⁻¹)
inverse-right = inst-fn(Inverseᵣ.proof ∘ [∧]-elimᵣ)
Invertible = ∃(f⁻¹ ↦ Function(f⁻¹) ∧ Inverse(f⁻¹))
module _ {A : Type{ℓₒ₁}} ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ {B : Type{ℓₒ₂}} ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ (([↔]-intro ba ab) : A ↔ B) where
record InversePair : Type{Lvl.of(A) Lvl.⊔ Lvl.of(B) Lvl.⊔ ℓₗ₁ Lvl.⊔ ℓₗ₂} where
constructor intro
l = ba
r = ab
field
⦃ left ⦄ : Inverseₗ(l)(r)
⦃ right ⦄ : Inverseᵣ(l)(r)
module _ {A : Type{ℓₒ₁}} {B : Type{ℓₒ₂}} ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ (f : A → B) where
record Constant : Stmt{ℓₒ₁ Lvl.⊔ ℓₗ₂} where
constructor intro
field proof : Names.Constant(f)
constant = inst-fn Constant.proof
module _ {A : Type{ℓₒ}} ⦃ _ : Equiv{ℓₗ}(A) ⦄ (f : A → A) where
module _ (x : A) where
record Fixpoint : Stmt{ℓₗ} where
constructor intro
field proof : Names.Fixpoint f(x)
fixpoint = inst-fn Fixpoint.proof
record Involution : Stmt{ℓₒ Lvl.⊔ ℓₗ} where
constructor intro
field proof : Names.Involution(f)
involution = inst-fn Involution.proof
record Idempotent : Stmt{ℓₒ Lvl.⊔ ℓₗ} where
constructor intro
field proof : Names.Idempotent(f)
idempotent = inst-fn Idempotent.proof
| {
"alphanum_fraction": 0.6276319585,
"avg_line_length": 36.1145833333,
"ext": "agda",
"hexsha": "75e8cecf095d688a9f840b475ec63d761c1774f1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Function/Domain.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Function/Domain.agda",
"max_line_length": 118,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Function/Domain.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 1620,
"size": 3467
} |
module TYPE where
data Pair (a b : Set1) : Set1 where
pair : a -> b -> Pair a b
data Unit : Set1 where
unit : Unit
| {
"alphanum_fraction": 0.6147540984,
"avg_line_length": 13.5555555556,
"ext": "agda",
"hexsha": "8bfd76e5fbe80d160e622fc3d94d078f7077ae3e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/AIM5/PolyDep/TYPE.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/AIM5/PolyDep/TYPE.agda",
"max_line_length": 35,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/AIM5/PolyDep/TYPE.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 41,
"size": 122
} |
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Experiments.NatMinusTwo.Base where
open import Cubical.Core.Primitives
open import Cubical.Data.Nat
open import Cubical.Data.Empty
record ℕ₋₂ : Type₀ where
constructor -2+_
field
n : ℕ
pattern neg2 = -2+ zero
pattern neg1 = -2+ (suc zero)
pattern ℕ→ℕ₋₂ n = -2+ (suc (suc n))
pattern -1+_ n = -2+ (suc n)
2+_ : ℕ₋₂ → ℕ
2+ (-2+ n) = n
pred₋₂ : ℕ₋₂ → ℕ₋₂
pred₋₂ neg2 = neg2
pred₋₂ neg1 = neg2
pred₋₂ (ℕ→ℕ₋₂ zero) = neg1
pred₋₂ (ℕ→ℕ₋₂ (suc n)) = (ℕ→ℕ₋₂ n)
suc₋₂ : ℕ₋₂ → ℕ₋₂
suc₋₂ (-2+ n) = -2+ (suc n)
-- Natural number and negative integer literals for ℕ₋₂
open import Cubical.Data.Nat.Literals public
instance
fromNatℕ₋₂ : HasFromNat ℕ₋₂
fromNatℕ₋₂ = record { Constraint = λ _ → Unit ; fromNat = ℕ→ℕ₋₂ }
instance
fromNegℕ₋₂ : HasFromNeg ℕ₋₂
fromNegℕ₋₂ = record { Constraint = λ { (suc (suc (suc _))) → ⊥ ; _ → Unit }
; fromNeg = λ { zero → 0 ; (suc zero) → neg1 ; (suc (suc zero)) → neg2 } }
| {
"alphanum_fraction": 0.6164383562,
"avg_line_length": 24.3333333333,
"ext": "agda",
"hexsha": "0754efcd4d18b9bacd336b94d79d9808bd6a09c9",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Experiments/NatMinusTwo/Base.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Experiments/NatMinusTwo/Base.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Experiments/NatMinusTwo/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 432,
"size": 1022
} |
{- Formal verification of authenticated append-only skiplists in Agda, version 1.0.
Copyright (c) 2020 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import Data.Unit.NonEta
open import Data.Empty
open import Data.Sum
open import Data.Product
open import Data.Product.Properties hiding (≡-dec)
open import Data.Nat renaming (_≟_ to _≟ℕ_; _≤?_ to _≤?ℕ_)
open import Data.Nat.Properties
open import Data.List renaming (map to List-map)
open import Data.List.Properties using (∷-injective; ≡-dec)
open import Data.List.Relation.Unary.Any
open import Data.List.Relation.Unary.All
open import Data.Bool hiding (_<_; _≤_) renaming (_≟_ to _≟Bool_)
open import Data.Maybe renaming (map to Maybe-map)
open import Function
open import Relation.Binary.PropositionalEquality
open import Relation.Binary.Core
open import Relation.Nullary
-- This module defins a type to represent hashes, functions for encoding
-- them, and properties about them
module AAOSL.Abstract.Hash where
open import AAOSL.Lemmas
-- We define a ByteString as a list of bits
ByteString : Set
ByteString = List Bool
-- TODO-1 : Hash -> Digest (to be consistent with the paper)? Or just comment?
Hash : Set
Hash = Σ ByteString (λ bs → length bs ≡ 32)
_≟Hash_ : (h₁ h₂ : Hash) → Dec (h₁ ≡ h₂)
(l , pl) ≟Hash (m , pm) with ≡-dec _≟Bool_ l m
...| yes refl = yes (cong (_,_ l) (≡-irrelevant pl pm))
...| no abs = no (abs ∘ ,-injectiveˡ)
encodeH : Hash → ByteString
encodeH (bs , _) = bs
encodeH-inj : ∀ i j → encodeH i ≡ encodeH j → i ≡ j
encodeH-inj (i , pi) (j , pj) refl = cong (_,_ i) (≡-irrelevant pi pj)
encodeH-len : ∀{h} → length (encodeH h) ≡ 32
encodeH-len { bs , p } = p
encodeH-len-lemma : ∀ i j → length (encodeH i) ≡ length (encodeH j)
encodeH-len-lemma i j = trans (encodeH-len {i}) (sym (encodeH-len {j}))
-- This means that we can make a helper function that combines
-- the necessary injections into one big injection
++b-2-inj : (h₁ h₂ : Hash){l₁ l₂ : Hash}
→ encodeH h₁ ++ encodeH l₁
≡ encodeH h₂ ++ encodeH l₂
→ h₁ ≡ h₂ × l₁ ≡ l₂
++b-2-inj h₁ h₂ {l₁} {l₂} hip
with ++-inj {m = encodeH h₁} {n = encodeH h₂} (encodeH-len-lemma h₁ h₂) hip
...| hh , ll = encodeH-inj h₁ h₂ hh , encodeH-inj l₁ l₂ ll
Collision : {A B : Set}(f : A → B)(a₁ a₂ : A) → Set
Collision f a₁ a₂ = a₁ ≢ a₂ × f a₁ ≡ f a₂
module WithCryptoHash
-- A Hash function maps a bytestring into a hash.
(hash : ByteString → Hash)
(hash-cr : ∀{x y} → hash x ≡ hash y → Collision hash x y ⊎ x ≡ y) where
HashBroke : Set
HashBroke = Σ ( ByteString × ByteString ) (λ { (x₁ , x₂) → Collision hash x₁ x₂ })
hash-concat : List Hash → Hash
hash-concat l = hash (concat (List-map encodeH l))
-- hash-concat isinjective, modulo hash collisions
hash-concat-inj : ∀{l₁ l₂} → hash-concat l₁ ≡ hash-concat l₂ → HashBroke ⊎ l₁ ≡ l₂
hash-concat-inj {[]} {x ∷ xs} h with hash-cr h
...| inj₁ col = inj₁ (([] , encodeH x ++ foldr _++_ [] (List-map encodeH xs)) , col)
...| inj₂ abs = ⊥-elim (++-abs (encodeH x) (subst (1 ≤_) (sym (encodeH-len {x})) (s≤s z≤n)) abs)
hash-concat-inj {x ∷ xs} {[]} h with hash-cr h
...| inj₁ col = inj₁ ((encodeH x ++ foldr _++_ [] (List-map encodeH xs) , []) , col)
...| inj₂ abs = ⊥-elim (++-abs (encodeH x) (subst (1 ≤_) (sym (encodeH-len {x})) (s≤s z≤n)) (sym abs))
hash-concat-inj {[]} {[]} h = inj₂ refl
hash-concat-inj {x ∷ xs} {y ∷ ys} h with hash-cr h
...| inj₁ col = inj₁ ((encodeH x ++ foldr _++_ [] (List-map encodeH xs) , encodeH y ++ foldr _++_ [] (List-map encodeH ys)) , col)
...| inj₂ res with ++-inj {m = encodeH x} {n = encodeH y} (encodeH-len-lemma x y) res
...| xy , xsys with hash-concat-inj {l₁ = xs} {l₂ = ys} (cong hash xsys)
...| inj₁ hb = inj₁ hb
...| inj₂ final = inj₂ (cong₂ _∷_ (encodeH-inj x y xy) final)
| {
"alphanum_fraction": 0.6390442298,
"avg_line_length": 40.1428571429,
"ext": "agda",
"hexsha": "994201e1f52ad6fa337491c07fb7fbb540cf8eab",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-02-18T04:33:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-12-22T00:01:03.000Z",
"max_forks_repo_head_hexsha": "318881fb24af06bbaafa33edeea0745eca1873f0",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/aaosl-agda",
"max_forks_repo_path": "AAOSL/Abstract/Hash.agda",
"max_issues_count": 5,
"max_issues_repo_head_hexsha": "318881fb24af06bbaafa33edeea0745eca1873f0",
"max_issues_repo_issues_event_max_datetime": "2021-02-12T04:16:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-01-04T03:45:34.000Z",
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/aaosl-agda",
"max_issues_repo_path": "AAOSL/Abstract/Hash.agda",
"max_line_length": 132,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "318881fb24af06bbaafa33edeea0745eca1873f0",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/aaosl-agda",
"max_stars_repo_path": "AAOSL/Abstract/Hash.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-31T10:16:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-22T00:01:00.000Z",
"num_tokens": 1364,
"size": 3934
} |
------------------------------------------------------------------------
-- Characters
------------------------------------------------------------------------
module Data.Char where
open import Data.Nat using (ℕ)
open import Data.Bool using (Bool; true; false)
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as PropEq using (_≡_)
------------------------------------------------------------------------
-- The type
postulate
Char : Set
{-# BUILTIN CHAR Char #-}
{-# COMPILED_TYPE Char Char #-}
------------------------------------------------------------------------
-- Operations
private
primitive
primCharToNat : Char → ℕ
primCharEquality : Char → Char → Bool
toNat : Char → ℕ
toNat = primCharToNat
infix 4 _==_
_==_ : Char → Char → Bool
_==_ = primCharEquality
_≟_ : Decidable {Char} _≡_
s₁ ≟ s₂ with s₁ == s₂
... | true = yes trustMe
where postulate trustMe : _
... | false = no trustMe
where postulate trustMe : _
setoid : Setoid
setoid = PropEq.setoid Char
decSetoid : DecSetoid
decSetoid = PropEq.decSetoid _≟_
| {
"alphanum_fraction": 0.5189530686,
"avg_line_length": 22.16,
"ext": "agda",
"hexsha": "1a8fed138a280298744ded9cda8f94ad1934a489",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Data/Char.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Data/Char.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Data/Char.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 258,
"size": 1108
} |
------------------------------------------------------------------------
-- A virtual machine
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Lambda.Simplified.Delay-monad.Virtual-machine where
open import Equality.Propositional
open import Prelude
open import Monad equality-with-J
open import Delay-monad
open import Delay-monad.Monad
open import Lambda.Simplified.Delay-monad.Interpreter
open import Lambda.Simplified.Syntax
open import Lambda.Simplified.Virtual-machine
open Closure Code
-- A functional semantics for the VM.
exec : ∀ {i} → State → Delay (Maybe Value) i
exec s with step s
... | continue s′ = later λ { .force → exec s′ }
... | done v = return (just v)
... | crash = return nothing
| {
"alphanum_fraction": 0.5923566879,
"avg_line_length": 26.1666666667,
"ext": "agda",
"hexsha": "d155cd11101f76197bb4c72c3a7a153ad3f18768",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Lambda/Simplified/Delay-monad/Virtual-machine.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/partiality-monad",
"max_issues_repo_path": "src/Lambda/Simplified/Delay-monad/Virtual-machine.agda",
"max_line_length": 72,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Lambda/Simplified/Delay-monad/Virtual-machine.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 153,
"size": 785
} |
{-# OPTIONS --safe #-}
module Cubical.Data.Maybe.Base where
open import Cubical.Core.Everything
private
variable
ℓ ℓA ℓB : Level
A : Type ℓA
B : Type ℓB
data Maybe (A : Type ℓ) : Type ℓ where
nothing : Maybe A
just : A → Maybe A
caseMaybe : (n j : B) → Maybe A → B
caseMaybe n _ nothing = n
caseMaybe _ j (just _) = j
map-Maybe : (A → B) → Maybe A → Maybe B
map-Maybe _ nothing = nothing
map-Maybe f (just x) = just (f x)
rec : B → (A → B) → Maybe A → B
rec n j nothing = n
rec n j (just a) = j a
elim : ∀ {A : Type ℓA} (B : Maybe A → Type ℓB) → B nothing → ((x : A) → B (just x)) → (mx : Maybe A) → B mx
elim B n j nothing = n
elim B n j (just a) = j a
| {
"alphanum_fraction": 0.5833333333,
"avg_line_length": 22.064516129,
"ext": "agda",
"hexsha": "1712b822ca0d67e5f447121216732791c9d643ba",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Data/Maybe/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Data/Maybe/Base.agda",
"max_line_length": 107,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Data/Maybe/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 259,
"size": 684
} |
module Issue833-2 where
-- Arbitrary data type
record unit : Set where
constructor tt
module Test ⦃ m : unit ⦄ { n : unit } where
open Test { tt }
| {
"alphanum_fraction": 0.6732026144,
"avg_line_length": 13.9090909091,
"ext": "agda",
"hexsha": "96eb1cf537e34564ddba7d7aa763ed9c3bc95442",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue833-2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/Issue833-2.agda",
"max_line_length": 43,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/succeed/Issue833-2.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 45,
"size": 153
} |
{-# OPTIONS --without-K #-}
module sets.fin.universe where
open import level
open import sum
open import decidable
open import equality.core
open import equality.calculus
open import equality.inspect
open import function.isomorphism
open import function.core
open import function.extensionality
open import function.fibration
open import function.overloading
open import sets.core
open import sets.properties
open import sets.nat.core
hiding (_≟_)
open import sets.nat.ordering
hiding (compare)
open import sets.fin.core
open import sets.fin.ordering
open import sets.fin.properties
open import sets.unit
open import sets.empty
open import sets.bool
open import sets.vec.dependent
open import hott.level.core
open import hott.level.closure
open import hott.level.sets
fin-struct-iso : ∀ {n} → Fin (suc n) ≅ (⊤ {lzero} ⊎ Fin n)
fin-struct-iso = record
{ to = λ { zero → inj₁ tt; (suc i) → inj₂ i }
; from = [ (λ _ → zero) ,⊎ (suc) ]
; iso₁ = λ { zero → refl ; (suc i) → refl }
; iso₂ = λ { (inj₁ _) → refl; (inj₂ i) → refl } }
fin0-empty : ⊥ ≅ Fin 0
fin0-empty = sym≅ (empty-⊥-iso (λ ()))
fin1-unit : ∀ {i} → ⊤ {i} ≅ Fin 1
fin1-unit = record
{ to = λ _ → zero
; from = λ { zero → tt ; (suc ()) }
; iso₁ = λ _ → refl
; iso₂ = λ { zero → refl ; (suc ()) } }
fin2-bool : Bool ≅ Fin 2
fin2-bool = record
{ to = λ b → if b then # 0 else # 1
; from = true ∷∷ false ∷∷ ⟦⟧
; iso₁ = λ { true → refl ; false → refl }
; iso₂ = refl ∷∷ refl ∷∷ ⟦⟧ }
fin-sum : ∀ {n m} → (Fin n ⊎ Fin m) ≅ Fin (n + m)
fin-sum {0} = record
{ to = λ { (inj₁ ()) ; (inj₂ j) → j }
; from = λ { j → inj₂ j }
; iso₁ = λ { (inj₁ ()); (inj₂ j) → refl }
; iso₂ = λ _ → refl }
fin-sum {suc n}{m} = begin
(Fin (suc n) ⊎ Fin m)
≅⟨ ⊎-ap-iso fin-struct-iso refl≅ ⟩
((⊤ ⊎ Fin n) ⊎ Fin m)
≅⟨ ⊎-assoc-iso ⟩
(⊤ ⊎ (Fin n ⊎ Fin m))
≅⟨ ⊎-ap-iso refl≅ fin-sum ⟩
(⊤ ⊎ Fin (n + m))
≅⟨ sym≅ fin-struct-iso ⟩
Fin (suc (n + m))
∎
where open ≅-Reasoning
fin-prod : ∀ {n m} → (Fin n × Fin m) ≅ Fin (n * m)
fin-prod {0} = iso (λ { (() , _) }) (λ ()) (λ { (() , _) }) (λ ())
fin-prod {suc n}{m} = begin
(Fin (suc n) × Fin m)
≅⟨ ×-ap-iso fin-struct-iso refl≅ ⟩
((⊤ ⊎ Fin n) × Fin m)
≅⟨ ⊎×-distr-iso ⟩
((⊤ × Fin m) ⊎ (Fin n × Fin m))
≅⟨ ⊎-ap-iso ×-left-unit fin-prod ⟩
(Fin m ⊎ (Fin (n * m)))
≅⟨ fin-sum ⟩
(Fin (m + (n * m)))
≡⟨ refl ⟩
Fin (suc n * m)
∎
where open ≅-Reasoning
fin-exp : ∀ {n m} → (Fin n → Fin m) ≅ Fin (m ^ n)
fin-exp {0} = record
{ to = λ f → zero
; from = (λ ()) ∷∷ ⟦⟧
; iso₁ = λ f → funext λ ()
; iso₂ = refl ∷∷ ⟦⟧ }
fin-exp {suc n}{m} = begin
(Fin (suc n) → Fin m)
≅⟨ (Π-ap-iso fin-struct-iso λ _ → refl≅) ⟩
((⊤ ⊎ Fin n) → Fin m)
≅⟨ iso (λ f → f (inj₁ tt) , f ∘' inj₂)
(λ { (i , _) (inj₁ _) → i
; (_ , g) (inj₂ i) → g i })
(λ f → funext λ { (inj₁ tt) → refl
; (inj₂ i) → refl })
(λ { (i , g) → refl }) ⟩
(Fin m × (Fin n → Fin m))
≅⟨ ×-ap-iso refl≅ fin-exp ⟩
(Fin m × Fin (m ^ n))
≅⟨ fin-prod ⟩
Fin (m ^ (suc n))
∎
where open ≅-Reasoning
factorial : ℕ → ℕ
factorial 0 = 1
factorial (suc n) = suc n * factorial n
fin-inj-iso : ∀ {n} → (Fin n ≅ Fin n) ≅ (Fin n ↣ Fin n)
fin-inj-iso {n} = record
{ to = λ f → (apply f , iso⇒inj f)
; from = λ { (f , inj) → inj⇒iso f inj }
; iso₁ = λ f → iso-eq-h2 (fin-set n) (fin-set n) refl
; iso₂ = λ { (f , inj) → inj-eq-h2 (fin-set n) refl } }
fin-iso-iso : ∀ {n} → (Fin n ↣ Fin n) ≅ Fin (factorial n)
fin-iso-iso {0} = record
{ to = λ { (f , _) → zero }
; from = λ _ → (λ ()) , (λ { {()} p })
; iso₁ = λ { (f , _) → inj-eq-h2 (fin-set _) (funext λ ()) }
; iso₂ = λ { zero → refl ; (suc ()) } }
fin-iso-iso {suc n} = begin
(X ↣ X)
≅⟨ sym≅ (total-iso classify) ⟩
(Σ X λ i → classify ⁻¹ i)
≅⟨ (Σ-ap-iso₂ λ i → trans≅ (sym≅ (const-fibre i)) fibre-zero-iso) ⟩
(Fin (suc n) × (Fin n ↣ Fin n))
≅⟨ ×-ap-iso refl≅ fin-iso-iso ⟩
(Fin (suc n) × Fin (factorial n))
≅⟨ fin-prod ⟩
Fin (factorial (suc n))
∎
where
X = Fin (suc n)
open ≅-Reasoning
classify : (X ↣ X) → X
classify (f , _) = f zero
const-fibre : (i : X) → classify ⁻¹ zero ≅ classify ⁻¹ i
const-fibre i = begin
( Σ (X ↣ X) λ { (f , _) → f zero ≡ zero } )
≅⟨ ( Σ-ap-iso (transpose-inj-iso' zero i) (λ { (f , inj)
→ mk-prop-iso (fin-set _ _ _) (fin-set _ _ _)
(ap (transpose zero i)) (u f) }) ) ⟩
( Σ (X ↣ X) λ { (f , _) → f zero ≡ i } )
∎
where
u : (f : X → X)
→ transpose zero i (f zero) ≡ i
→ f zero ≡ zero
u f p = sym (_≅_.iso₁ (transpose-iso zero i) (f zero))
· (ap (transpose zero i) p
· transpose-β₂ zero i)
fibre-zero-iso : classify ⁻¹ zero ≅ (Fin n ↣ Fin n)
fibre-zero-iso = record
{ to = λ { (f , z) → fin-inj-remove₀ f z }
; from = λ { g → fin-inj-add g , refl }
; iso₁ = λ { (f , p)
→ unapΣ (inj-eq-h2 (fin-set (suc n))
(funext (α f p ))
, h1⇒prop (fin-set (suc n) _ _) _ _) }
; iso₂ = λ g → inj-eq-h2 (fin-set n) refl }
where
α : (f : Fin (suc n) ↣ Fin (suc n))
→ (p : apply f zero ≡ zero)
→ (i : Fin (suc n))
→ apply (fin-inj-add (fin-inj-remove₀ f p)) i
≡ apply f i
α _ p zero = sym p
α (f , f-inj) p (suc i) = pred-β (f (suc i))
(λ q → fin-disj _ (f-inj (p · sym q)))
fin-subsets : ∀ {n} → (Fin n → Bool) ≅ Fin (2 ^ n)
fin-subsets = trans≅ (Π-ap-iso refl≅ λ _ → fin2-bool) fin-exp
| {
"alphanum_fraction": 0.489871411,
"avg_line_length": 30.1968085106,
"ext": "agda",
"hexsha": "85292646bb4e4117375eb599798c6647a603d494",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/sets/fin/universe.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/sets/fin/universe.agda",
"max_line_length": 69,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/sets/fin/universe.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 2341,
"size": 5677
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Instance.Properties.Setoids.Extensive where
open import Level
open import Data.Product using (∃; Σ; proj₁; proj₂; _,_; _×_)
open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂)
open import Data.Sum.Relation.Binary.Pointwise using (inj₁; inj₂; _⊎ₛ_; drop-inj₁; drop-inj₂)
open import Data.Unit.Polymorphic using (tt)
open import Function.Equality using (Π; _⟶_; _⇨_; _∘_)
open import Relation.Binary using (Setoid)
import Relation.Binary.Reasoning.Setoid as SetoidR
open import Categories.Category using (Category; _[_,_])
open import Categories.Category.Instance.Setoids using (Setoids)
open import Categories.Category.Extensive using (Extensive)
open import Categories.Category.Cocartesian using (Cocartesian)
open import Categories.Diagram.Pullback using (Pullback)
open import Categories.Category.Instance.Properties.Setoids.Limits.Canonical using (pullback; FiberProduct)
open import Categories.Category.Monoidal.Instance.Setoids using (Setoids-Cocartesian)
open Π
open Pullback
-- Note the Setoids is extensive if the two levels coincide. Whether it happens more generally
-- is unknown at this point.
Setoids-Extensive : (ℓ : Level) → Extensive (Setoids ℓ ℓ)
Setoids-Extensive ℓ = record
{ cocartesian = record { initial = initial ; coproducts = coproducts }
; pullback₁ = λ f → pullback ℓ ℓ f i₁
; pullback₂ = λ f → pullback ℓ ℓ f i₂
; pullback-of-cp-is-cp = λ f → record
{ [_,_] = λ g h → copair f g h
; inject₁ = λ {X g h z} eq →
trans (isEquivalence X) (copair-inject₁ f g h z) (cong g eq)
; inject₂ = λ {X g h z} eq →
trans (isEquivalence X) (copair-inject₂ f g h z) (cong h eq)
; unique = λ {X u g h} feq₁ feq₂ {z} eq →
trans (isEquivalence X) (copair-unique f g h u z (λ {z} → feq₁ {z}) (λ {z} → feq₂ {z})) (cong u eq)
}
; pullback₁-is-mono = λ _ _ eq x≈y → drop-inj₁ (eq x≈y)
; pullback₂-is-mono = λ _ _ eq x≈y → drop-inj₂ (eq x≈y)
; disjoint = λ {A B} → record
{ commute = λ { {()} _}
; universal = λ {C f g} eq → record
{ _⟨$⟩_ = λ z → conflict A B (eq {x = z} (refl (isEquivalence C)))
; cong = λ z → tt
}
; unique = λ _ _ _ → tt
; p₁∘universal≈h₁ = λ {_ _ _ eq} x≈y → conflict A B (eq x≈y)
; p₂∘universal≈h₂ = λ {_ _ _ eq} x≈y → conflict A B (eq x≈y)
}
}
where
open Cocartesian (Setoids-Cocartesian {ℓ} {ℓ})
open Relation.Binary.IsEquivalence
open Setoid renaming (_≈_ to [_][_≈_]; Carrier to ∣_∣) using (isEquivalence)
-- must be in the standard library. Maybe it is?
conflict : ∀ {ℓ ℓ' ℓ''} (X Y : Setoid ℓ ℓ') {Z : Set ℓ''}
{x : ∣ X ∣} {y : ∣ Y ∣} → [ X ⊎ₛ Y ][ inj₁ x ≈ inj₂ y ] → Z
conflict X Y ()
module Diagram {A B C X : Setoid ℓ ℓ} (f : C ⟶ A ⊎ₛ B)
(g : P (pullback ℓ ℓ f i₁) ⟶ X) (h : P (pullback ℓ ℓ f i₂) ⟶ X) where
private
module A = Setoid A
module B = Setoid B
module C = Setoid C
module X = Setoid X
A⊎B = A ⊎ₛ B
module A⊎B = Setoid (A ⊎ₛ B)
A′ = P (pullback ℓ ℓ f i₁)
B′ = P (pullback ℓ ℓ f i₂)
A⊎B′ = A′ ⊎ₛ B′
module A⊎B′ = Setoid A⊎B′
open SetoidR A⊎B′
_⊎⟶_ : {o₁ o₂ o₃ ℓ₁ ℓ₂ ℓ₃ : Level} {X : Setoid o₁ ℓ₁} {Y : Setoid o₂ ℓ₂} {Z : Setoid o₃ ℓ₃} →
(X ⟶ Z) → (Y ⟶ Z) → (X ⊎ₛ Y) ⟶ Z
f₁ ⊎⟶ f₂ = record
{ _⟨$⟩_ = Sum.[ f₁ ⟨$⟩_ , f₂ ⟨$⟩_ ]
; cong = λ { (inj₁ x) → cong f₁ x ; (inj₂ x) → cong f₂ x}
}
to-⊎ₛ : (z : ∣ C ∣) → (w : ∣ A ⊎ₛ B ∣) → (eq : [ A⊎B ][ f ⟨$⟩ z ≈ w ]) → ∣ A′ ⊎ₛ B′ ∣
to-⊎ₛ z (inj₁ x) eq = inj₁ (record { elem₁ = z ; elem₂ = x ; commute = eq })
to-⊎ₛ z (inj₂ y) eq = inj₂ (record { elem₁ = z ; elem₂ = y ; commute = eq })
to-⊎ₛ-cong : {z : ∣ C ∣} {w w′ : ∣ A ⊎ₛ B ∣ } → [ A⊎B ][ w ≈ w′ ] →
{eq : [ A⊎B ][ f ⟨$⟩ z ≈ w ]} → {eq′ : [ A⊎B ][ f ⟨$⟩ z ≈ w′ ]} → [ A⊎B′ ][ to-⊎ₛ z w eq ≈ to-⊎ₛ z w′ eq′ ]
to-⊎ₛ-cong (inj₁ x) = inj₁ (C.refl , x)
to-⊎ₛ-cong (inj₂ x) = inj₂ (C.refl , x)
f⟨$⟩→ : (z : ∣ C ∣) → ∣ A′ ⊎ₛ B′ ∣
f⟨$⟩→ z = to-⊎ₛ z (f ⟨$⟩ z) A⊎B.refl
f⟨$⟩-cong′ : {z z′ : ∣ C ∣} → (z≈z′ : [ C ][ z ≈ z′ ]) → (w w′ : ∣ A ⊎ₛ B ∣) →
[ A⊎B ][ f ⟨$⟩ z ≈ w ] → [ A⊎B ][ f ⟨$⟩ z′ ≈ w′ ] → [ A′ ⊎ₛ B′ ][ f⟨$⟩→ z ≈ f⟨$⟩→ z′ ]
f⟨$⟩-cong′ {z} {z′} z≈z′ (inj₁ x) (inj₁ x₁) fz≈w fz′≈w′ = begin
f⟨$⟩→ z ≈⟨ A⊎B′.refl ⟩
to-⊎ₛ z (f ⟨$⟩ z) A⊎B.refl ≈⟨ to-⊎ₛ-cong fz≈w ⟩
to-⊎ₛ z (inj₁ x) fz≈w ≈⟨ inj₁ (z≈z′ , (drop-inj₁ (A⊎B.trans (A⊎B.sym fz≈w) (A⊎B.trans (cong f z≈z′) fz′≈w′)))) ⟩
to-⊎ₛ z′ (inj₁ x₁) fz′≈w′ ≈⟨ to-⊎ₛ-cong (A⊎B.sym fz′≈w′) ⟩
to-⊎ₛ z′ (f ⟨$⟩ z′) A⊎B.refl ≈⟨ A⊎B′.refl ⟩
f⟨$⟩→ z′ ∎
f⟨$⟩-cong′ z≈z′ (inj₁ x) (inj₂ y) fz≈w fz′≈w′ = conflict A B (A⊎B.trans (A⊎B.sym fz≈w) (A⊎B.trans (cong f z≈z′) fz′≈w′))
f⟨$⟩-cong′ z≈z′ (inj₂ y) (inj₁ x) fz≈w fz′≈w′ = conflict A B (A⊎B.trans (A⊎B.sym fz′≈w′) (A⊎B.trans (cong f (C.sym z≈z′)) fz≈w))
f⟨$⟩-cong′ {z} {z′} z≈z′ (inj₂ y) (inj₂ y₁) fz≈w fz′≈w′ = begin
to-⊎ₛ z (f ⟨$⟩ z) A⊎B.refl ≈⟨ to-⊎ₛ-cong fz≈w ⟩
to-⊎ₛ z (inj₂ y) fz≈w ≈⟨ inj₂ (z≈z′ , (drop-inj₂ (A⊎B.trans (A⊎B.sym fz≈w) (A⊎B.trans (cong f z≈z′) fz′≈w′)))) ⟩
to-⊎ₛ z′ (inj₂ y₁) fz′≈w′ ≈⟨ to-⊎ₛ-cong (A⊎B.sym fz′≈w′) ⟩
to-⊎ₛ z′ (f ⟨$⟩ z′) A⊎B.refl ∎
f⟨$⟩-cong : {i j : ∣ C ∣} → i C.≈ j → [ A′ ⊎ₛ B′ ][ f⟨$⟩→ i ≈ f⟨$⟩→ j ]
f⟨$⟩-cong {i} {j} i≈j = f⟨$⟩-cong′ i≈j (f ⟨$⟩ i) (f ⟨$⟩ j) A⊎B.refl A⊎B.refl
f⟨$⟩ : C ⟶ A′ ⊎ₛ B′
f⟨$⟩ = record { _⟨$⟩_ = f⟨$⟩→ ; cong = f⟨$⟩-cong }
-- copairing of g : A′ → X and h : B′ → X, resulting in C → X
copair : C ⟶ X
copair = (g ⊎⟶ h) ∘ f⟨$⟩
copair-inject₁ : (z : FiberProduct f i₁) → [ X ][ copair ⟨$⟩ (FiberProduct.elem₁ z) ≈ g ⟨$⟩ z ]
copair-inject₁ record { elem₁ = z ; elem₂ = x ; commute = eq } = cong (g ⊎⟶ h) (to-⊎ₛ-cong eq)
copair-inject₂ : (z : FiberProduct f i₂) → [ X ][ copair ⟨$⟩ (FiberProduct.elem₁ z) ≈ h ⟨$⟩ z ]
copair-inject₂ record { elem₁ = z ; elem₂ = y ; commute = eq } = cong (g ⊎⟶ h) (to-⊎ₛ-cong eq)
copair-unique′ : (u : C ⟶ X) (z : ∣ C ∣) →
[ A′ ⇨ X ][ u ∘ p₁ (pullback ℓ ℓ f i₁) ≈ g ] →
[ B′ ⇨ X ][ u ∘ p₁ (pullback ℓ ℓ f i₂) ≈ h ] →
(w : ∣ A⊎B ∣) → [ A⊎B ][ f ⟨$⟩ z ≈ w ] →
[ X ][ copair ⟨$⟩ z ≈ u ⟨$⟩ z ]
copair-unique′ u z feq₁ feq₂ (inj₁ x) fz≈w = XR.begin
copair ⟨$⟩ z XR.≈⟨ X.refl ⟩
g ⊎⟶ h ⟨$⟩ (to-⊎ₛ z (f ⟨$⟩ z) A⊎B.refl) XR.≈⟨ cong (g ⊎⟶ h) (to-⊎ₛ-cong fz≈w) ⟩
g ⊎⟶ h ⟨$⟩ (to-⊎ₛ z (inj₁ x) fz≈w) XR.≈⟨ X.refl ⟩
g ⟨$⟩ fb XR.≈⟨ X.sym (feq₁ {x = fb} (C.refl , A.refl)) ⟩
u ⟨$⟩ z XR.∎
where
module XR = SetoidR X
fb = record {elem₁ = z ; elem₂ = x; commute = fz≈w }
copair-unique′ u z feq₁ feq₂ (inj₂ y) fz≈w = XR.begin
copair ⟨$⟩ z XR.≈⟨ X.refl ⟩
g ⊎⟶ h ⟨$⟩ (to-⊎ₛ z (f ⟨$⟩ z) A⊎B.refl) XR.≈⟨ cong (g ⊎⟶ h) (to-⊎ₛ-cong fz≈w) ⟩
g ⊎⟶ h ⟨$⟩ (to-⊎ₛ z (inj₂ y) fz≈w) XR.≈⟨ X.refl ⟩
h ⟨$⟩ fb XR.≈⟨ X.sym (feq₂ {x = fb} {y = fb} (C.refl , B.refl)) ⟩
u ⟨$⟩ z XR.∎
where
module XR = SetoidR X
fb = record {elem₁ = z ; elem₂ = y; commute = fz≈w }
copair-unique : (u : C ⟶ X) (z : ∣ C ∣) →
[ A′ ⇨ X ][ u ∘ p₁ (pullback ℓ ℓ f i₁) ≈ g ] →
[ B′ ⇨ X ][ u ∘ p₁ (pullback ℓ ℓ f i₂) ≈ h ] →
[ X ][ copair ⟨$⟩ z ≈ u ⟨$⟩ z ]
copair-unique u z feq₁ feq₂ = copair-unique′ u z (λ {x} {y} → feq₁ {x} {y}) (λ {x} {y} → feq₂ {x} {y}) (f ⟨$⟩ z) A⊎B.refl
open Diagram
| {
"alphanum_fraction": 0.4555082167,
"avg_line_length": 49.4879518072,
"ext": "agda",
"hexsha": "9879ce05c7587f1ac3a9c772ad1eb70c6957db4a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Instance/Properties/Setoids/Extensive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Instance/Properties/Setoids/Extensive.agda",
"max_line_length": 137,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Instance/Properties/Setoids/Extensive.agda",
"max_stars_repo_stars_event_max_datetime": "2019-05-22T03:54:24.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-05-21T17:07:19.000Z",
"num_tokens": 3761,
"size": 8215
} |
module A4 where
-- open import Data.Nat
open import Data.Empty
open import Data.Unit
open import Data.Sum
open import Data.Product
open import Groupoid
------------------------------------------------------------------------------
-- Level 0:
-- types are collections of points
-- equivalences are between points
module Pi0 where
infixr 10 _◎_
infixr 30 _⟷_
-- types
data U : Set where
ZERO : U
ONE : U
PLUS : U → U → U
TIMES : U → U → U
-- values
⟦_⟧ : U → Set
⟦ ZERO ⟧ = ⊥
⟦ ONE ⟧ = ⊤
⟦ PLUS t₁ t₂ ⟧ = ⟦ t₁ ⟧ ⊎ ⟦ t₂ ⟧
⟦ TIMES t₁ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧
-- Examples
BOOL : U
BOOL = PLUS ONE ONE
BOOL² : U
BOOL² = TIMES BOOL BOOL
TRUE : ⟦ BOOL ⟧
TRUE = inj₁ tt
FALSE : ⟦ BOOL ⟧
FALSE = inj₂ tt
-- combinators
data _⟷_ : U → U → Set where
unite₊ : {t : U} → PLUS ZERO t ⟷ t
uniti₊ : {t : U} → t ⟷ PLUS ZERO t
swap₊ : {t₁ t₂ : U} → PLUS t₁ t₂ ⟷ PLUS t₂ t₁
assocl₊ : {t₁ t₂ t₃ : U} → PLUS t₁ (PLUS t₂ t₃) ⟷ PLUS (PLUS t₁ t₂) t₃
assocr₊ : {t₁ t₂ t₃ : U} → PLUS (PLUS t₁ t₂) t₃ ⟷ PLUS t₁ (PLUS t₂ t₃)
unite⋆ : {t : U} → TIMES ONE t ⟷ t
uniti⋆ : {t : U} → t ⟷ TIMES ONE t
swap⋆ : {t₁ t₂ : U} → TIMES t₁ t₂ ⟷ TIMES t₂ t₁
assocl⋆ : {t₁ t₂ t₃ : U} → TIMES t₁ (TIMES t₂ t₃) ⟷ TIMES (TIMES t₁ t₂) t₃
assocr⋆ : {t₁ t₂ t₃ : U} → TIMES (TIMES t₁ t₂) t₃ ⟷ TIMES t₁ (TIMES t₂ t₃)
distz : {t : U} → TIMES ZERO t ⟷ ZERO
factorz : {t : U} → ZERO ⟷ TIMES ZERO t
dist : {t₁ t₂ t₃ : U} →
TIMES (PLUS t₁ t₂) t₃ ⟷ PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)
factor : {t₁ t₂ t₃ : U} →
PLUS (TIMES t₁ t₃) (TIMES t₂ t₃) ⟷ TIMES (PLUS t₁ t₂) t₃
id⟷ : {t : U} → t ⟷ t
sym⟷ : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₁)
_◎_ : {t₁ t₂ t₃ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃)
_⊕_ : {t₁ t₂ t₃ t₄ : U} →
(t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (PLUS t₁ t₂ ⟷ PLUS t₃ t₄)
_⊗_ : {t₁ t₂ t₃ t₄ : U} →
(t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (TIMES t₁ t₂ ⟷ TIMES t₃ t₄)
-- Examples
COND : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₁ ⟷ t₂) →
((TIMES BOOL t₁) ⟷ (TIMES BOOL t₂))
COND f g = dist ◎ ((id⟷ ⊗ f) ⊕ (id⟷ ⊗ g)) ◎ factor
CONTROLLED : {t : U} → (t ⟷ t) → ((TIMES BOOL t) ⟷ (TIMES BOOL t))
CONTROLLED f = COND f id⟷
CNOT : BOOL² ⟷ BOOL²
CNOT = CONTROLLED swap₊
------------------------------------------------------------------------------
-- Level 1
-- types are collections of paths (where paths are equivalences between points)
-- equivalences are between paths
module Pi1 where
-- types
data U : Set where
{-
LIFT : Pi0.U → U
PLUS : U → U → U
TIMES : U → U → U
-}
EQUIV : {t₁ t₂ : Pi0.U} → (t₁ Pi0.⟷ t₂) → Pi0.⟦ t₁ ⟧ → Pi0.⟦ t₂ ⟧ → U
-- extractor, dependently typed.
srcU : U → Σ Pi0.U Pi0.⟦_⟧
srcU (EQUIV {t₁} {t₂} c x y) = t₁ , x
-- values
data Path⊤ : Set where
pathtt : Path⊤
data Path⊎ (A B : Set) : Set where
pathLeft : A → Path⊎ A B
pathRight : B → Path⊎ A B
data Path× (A B : Set) : Set where
pathPair : A → B → Path× A B
data Unite₊ {t : Pi0.U} : Pi0.⟦ Pi0.PLUS Pi0.ZERO t ⟧ → Pi0.⟦ t ⟧ → Set where
pathUnite₊ : (v : Pi0.⟦ t ⟧) → Unite₊ (inj₂ v) v
data Uniti₊ {t : Pi0.U} : Pi0.⟦ t ⟧ → Pi0.⟦ Pi0.PLUS Pi0.ZERO t ⟧ → Set where
pathUniti₊ : (v : Pi0.⟦ t ⟧) → Uniti₊ v (inj₂ v)
data Swap₊ {t₁ t₂ : Pi0.U} :
Pi0.⟦ Pi0.PLUS t₁ t₂ ⟧ → Pi0.⟦ Pi0.PLUS t₂ t₁ ⟧ → Set where
path1Swap₊ : (v₁ : Pi0.⟦ t₁ ⟧) → Swap₊ (inj₁ v₁) (inj₂ v₁)
path2Swap₊ : (v₂ : Pi0.⟦ t₂ ⟧) → Swap₊ (inj₂ v₂) (inj₁ v₂)
data Assocl₊ {t₁ t₂ t₃ : Pi0.U} :
Pi0.⟦ Pi0.PLUS t₁ (Pi0.PLUS t₂ t₃) ⟧ →
Pi0.⟦ Pi0.PLUS (Pi0.PLUS t₁ t₂) t₃ ⟧ → Set where
path1Assocl₊ : (v₁ : Pi0.⟦ t₁ ⟧) → Assocl₊ (inj₁ v₁) (inj₁ (inj₁ v₁))
path2Assocl₊ : (v₂ : Pi0.⟦ t₂ ⟧) → Assocl₊ (inj₂ (inj₁ v₂)) (inj₁ (inj₂ v₂))
path3Assocl₊ : (v₃ : Pi0.⟦ t₃ ⟧) → Assocl₊ (inj₂ (inj₂ v₃)) (inj₂ v₃)
data Assocr₊ {t₁ t₂ t₃ : Pi0.U} :
Pi0.⟦ Pi0.PLUS (Pi0.PLUS t₁ t₂) t₃ ⟧ →
Pi0.⟦ Pi0.PLUS t₁ (Pi0.PLUS t₂ t₃) ⟧ → Set where
path1Assocr₊ : (v₁ : Pi0.⟦ t₁ ⟧) → Assocr₊ (inj₁ (inj₁ v₁)) (inj₁ v₁)
path2Assocr₊ : (v₂ : Pi0.⟦ t₂ ⟧) →
Assocr₊ (inj₁ (inj₂ v₂)) (inj₂ (inj₁ v₂))
path3Assocr₊ : (v₃ : Pi0.⟦ t₃ ⟧) → Assocr₊ (inj₂ v₃) (inj₂ (inj₂ v₃))
data Unite⋆ {t : Pi0.U} : Pi0.⟦ Pi0.TIMES Pi0.ONE t ⟧ → Pi0.⟦ t ⟧ → Set where
pathUnite⋆ : (v : Pi0.⟦ t ⟧) → Unite⋆ (tt , v) v
data Uniti⋆ {t : Pi0.U} : Pi0.⟦ t ⟧ → Pi0.⟦ Pi0.TIMES Pi0.ONE t ⟧ → Set where
pathUniti⋆ : (v : Pi0.⟦ t ⟧) → Uniti⋆ v (tt , v)
data Swap⋆ {t₁ t₂ : Pi0.U} :
Pi0.⟦ Pi0.TIMES t₁ t₂ ⟧ → Pi0.⟦ Pi0.TIMES t₂ t₁ ⟧ → Set where
pathSwap⋆ :
(v₁ : Pi0.⟦ t₁ ⟧) → (v₂ : Pi0.⟦ t₂ ⟧) → Swap⋆ (v₁ , v₂) (v₂ , v₁)
data Assocl⋆ {t₁ t₂ t₃ : Pi0.U} :
Pi0.⟦ Pi0.TIMES t₁ (Pi0.TIMES t₂ t₃) ⟧ →
Pi0.⟦ Pi0.TIMES (Pi0.TIMES t₁ t₂) t₃ ⟧ → Set where
pathAssocl⋆ :
(v₁ : Pi0.⟦ t₁ ⟧) → (v₂ : Pi0.⟦ t₂ ⟧) → (v₃ : Pi0.⟦ t₃ ⟧) →
Assocl⋆ (v₁ , (v₂ , v₃)) ((v₁ , v₂) , v₃)
data Assocr⋆ {t₁ t₂ t₃ : Pi0.U} :
Pi0.⟦ Pi0.TIMES (Pi0.TIMES t₁ t₂) t₃ ⟧ →
Pi0.⟦ Pi0.TIMES t₁ (Pi0.TIMES t₂ t₃) ⟧ → Set where
pathAssocr⋆ :
(v₁ : Pi0.⟦ t₁ ⟧) → (v₂ : Pi0.⟦ t₂ ⟧) → (v₃ : Pi0.⟦ t₃ ⟧) →
Assocr⋆ ((v₁ , v₂) , v₃) (v₁ , (v₂ , v₃))
data Dist {t₁ t₂ t₃ : Pi0.U} :
Pi0.⟦ Pi0.TIMES (Pi0.PLUS t₁ t₂) t₃ ⟧ →
Pi0.⟦ Pi0.PLUS (Pi0.TIMES t₁ t₃) (Pi0.TIMES t₂ t₃) ⟧ → Set where
path1Dist :
(v₁ : Pi0.⟦ t₁ ⟧) → (v₃ : Pi0.⟦ t₃ ⟧) →
Dist (inj₁ v₁ , v₃) (inj₁ (v₁ , v₃))
path2Dist :
(v₂ : Pi0.⟦ t₂ ⟧) → (v₃ : Pi0.⟦ t₃ ⟧) →
Dist (inj₂ v₂ , v₃) (inj₂ (v₂ , v₃))
data Factor {t₁ t₂ t₃ : Pi0.U} :
Pi0.⟦ Pi0.PLUS (Pi0.TIMES t₁ t₃) (Pi0.TIMES t₂ t₃) ⟧ →
Pi0.⟦ Pi0.TIMES (Pi0.PLUS t₁ t₂) t₃ ⟧ → Set where
path1Factor :
(v₁ : Pi0.⟦ t₁ ⟧) → (v₃ : Pi0.⟦ t₃ ⟧) →
Factor (inj₁ (v₁ , v₃)) (inj₁ v₁ , v₃)
path2Factor :
(v₂ : Pi0.⟦ t₂ ⟧) → (v₃ : Pi0.⟦ t₃ ⟧) →
Factor (inj₂ (v₂ , v₃)) (inj₂ v₂ , v₃)
data Id⟷ {t : Pi0.U} : Pi0.⟦ t ⟧ → Pi0.⟦ t ⟧ → Set where
pathId⟷ : (v : Pi0.⟦ t ⟧) → Id⟷ v v
data PathRev (A : Set) : Set where
pathRev : A → PathRev A
record PathTrans (A : Set) (B C : A → Set) : Set where
constructor pathTrans
field
anchor : A
pre : B anchor
post : C anchor
mutual
⟦_⟧ : U → Set
{-
⟦ LIFT u ⟧ = Pi0.⟦ u ⟧
⟦ ZERO ⟧ = ⊥
⟦ ONE ⟧ = Path⊤
⟦ PLUS t₁ t₂ ⟧ = Path⊎ ⟦ t₁ ⟧ ⟦ t₂ ⟧
⟦ TIMES t₁ t₂ ⟧ = Path× ⟦ t₁ ⟧ ⟦ t₂ ⟧
-}
⟦ EQUIV c v₁ v₂ ⟧ = Paths c v₁ v₂ -- space of paths from v₁ to v₂ using c
Paths : {t₁ t₂ : Pi0.U} → (t₁ Pi0.⟷ t₂) → Pi0.⟦ t₁ ⟧ → Pi0.⟦ t₂ ⟧ → Set
Paths Pi0.unite₊ (inj₁ ()) _
Paths Pi0.unite₊ (inj₂ v) v' = Unite₊ (inj₂ v) v'
Paths Pi0.uniti₊ v (inj₁ ())
Paths Pi0.uniti₊ v (inj₂ v') = Uniti₊ v (inj₂ v')
Paths Pi0.swap₊ v v' = Swap₊ v v'
Paths Pi0.assocl₊ v v' = Assocl₊ v v'
Paths Pi0.assocr₊ v v' = Assocr₊ v v'
Paths Pi0.unite⋆ v v' = Unite⋆ v v'
Paths Pi0.uniti⋆ v v' = Uniti⋆ v v'
Paths Pi0.swap⋆ v v' = Swap⋆ v v'
Paths Pi0.assocl⋆ v v' = Assocl⋆ v v'
Paths Pi0.assocr⋆ v v' = Assocr⋆ v v'
Paths Pi0.distz v ()
Paths Pi0.factorz () v'
Paths Pi0.dist v v' = Dist v v'
Paths Pi0.factor v v' = Factor v v'
Paths Pi0.id⟷ v v' = Id⟷ v v'
Paths (Pi0.sym⟷ c) v v' = PathRev (Paths c v' v)
Paths (Pi0._◎_ {t₂ = t₂} c₁ c₂) v₁ v₃ =
PathTrans Pi0.⟦ t₂ ⟧ (λ v₂ → Paths c₁ v₁ v₂) (λ v₂ → Paths c₂ v₂ v₃)
-- Σ[ v₂ ∈ Pi0.⟦ t₂ ⟧ ] (Paths c₁ v₁ v₂ × Paths c₂ v₂ v₃)
Paths (c₁ Pi0.⊕ c₂) (inj₁ v₁) (inj₁ v₁') = Path⊎ (Paths c₁ v₁ v₁') ⊥
Paths (c₁ Pi0.⊕ c₂) (inj₁ v₁) (inj₂ v₂') = ⊥
Paths (c₁ Pi0.⊕ c₂) (inj₂ v₂) (inj₁ v₁') = ⊥
Paths (c₁ Pi0.⊕ c₂) (inj₂ v₂) (inj₂ v₂') = Path⊎ ⊥ (Paths c₂ v₂ v₂')
Paths (c₁ Pi0.⊗ c₂) (v₁ , v₂) (v₁' , v₂') =
Path× (Paths c₁ v₁ v₁') (Paths c₂ v₂ v₂')
-- Examples
-- A few paths between FALSE and FALSE
p₁ : ⟦ EQUIV Pi0.id⟷ Pi0.FALSE Pi0.FALSE ⟧
p₁ = pathId⟷ Pi0.FALSE
p₂ : ⟦ EQUIV (Pi0.id⟷ Pi0.◎ Pi0.id⟷) Pi0.FALSE Pi0.FALSE ⟧
p₂ = pathTrans Pi0.FALSE p₁ p₁
p₃ : ⟦ EQUIV (Pi0.swap₊ Pi0.◎ Pi0.swap₊) Pi0.FALSE Pi0.FALSE ⟧
p₃ = pathTrans Pi0.TRUE (path2Swap₊ tt) (path1Swap₊ tt)
p₄ : ⟦ EQUIV (Pi0.id⟷ Pi0.⊕ Pi0.id⟷) Pi0.FALSE Pi0.FALSE ⟧
p₄ = pathRight (pathId⟷ tt)
-- A few paths between (TRUE,TRUE) and (TRUE,TRUE)
p₅ : ⟦ EQUIV Pi0.id⟷ (Pi0.TRUE , Pi0.TRUE) (Pi0.TRUE , Pi0.TRUE) ⟧
p₅ = pathId⟷ (Pi0.TRUE , Pi0.TRUE)
p₆ : ⟦ EQUIV (Pi0.id⟷ Pi0.⊗ Pi0.id⟷)
(Pi0.TRUE , Pi0.TRUE) (Pi0.TRUE , Pi0.TRUE) ⟧
p₆ = pathPair (pathId⟷ Pi0.TRUE) (pathId⟷ Pi0.TRUE)
-- A few paths between (TRUE,FALSE) and (TRUE,TRUE)
p₇ : ⟦ EQUIV (Pi0.id⟷ Pi0.⊗ Pi0.swap₊)
(Pi0.TRUE , Pi0.FALSE) (Pi0.TRUE , Pi0.TRUE) ⟧
p₇ = pathPair (pathId⟷ Pi0.TRUE) (path2Swap₊ tt)
p₇' : ⟦ EQUIV (Pi0.swap₊ Pi0.⊗ Pi0.id⟷)
(Pi0.FALSE , Pi0.TRUE) (Pi0.TRUE , Pi0.TRUE) ⟧
p₇' = pathPair (path2Swap₊ tt) (pathId⟷ Pi0.TRUE)
p₈ : ⟦ EQUIV Pi0.CNOT (Pi0.TRUE , Pi0.FALSE) (Pi0.TRUE , Pi0.TRUE) ⟧
p₈ = pathTrans (inj₁ (tt , Pi0.FALSE))
(path1Dist tt Pi0.FALSE)
(pathTrans (inj₁ (tt , Pi0.TRUE))
(pathLeft (pathPair (pathId⟷ tt) (path2Swap₊ tt)))
(path1Factor tt Pi0.TRUE))
-- Examples using sum and products of paths
{-
q₀ : ⟦ TIMES (LIFT Pi0.ONE) (EQUIV Pi0.id⟷ Pi0.FALSE Pi0.FALSE) ⟧
q₀ = pathPair pathtt p₁
q₁ : ⟦ (LIFT Pi0.PLUS) (EQUIV Pi0.id⟷ Pi0.FALSE Pi0.FALSE)
(EQUIV (Pi0.id⟷ Pi0.⊗ Pi0.swap₊)
(Pi0.TRUE , Pi0.FALSE) (Pi0.TRUE , Pi0.TRUE)) ⟧
q₁ = pathRight p₇
q₂ : ⟦ (LIFT Pi0.PLUS) (EQUIV Pi0.id⟷ Pi0.FALSE Pi0.FALSE) (LIFT Pi0.ZERO) ⟧
q₂ = pathLeft p₁
-}
-- combinators
-- the usual semiring combinators to reason about 0, 1, +, and *, and
-- the groupoid combinators to reason about id, rev, and trans
data _⟷_ : U → U → Set where
{-
unite₊ : {t : U} → PLUS ZERO t ⟷ t
uniti₊ : {t : U} → t ⟷ PLUS ZERO t
swap₊ : {t₁ t₂ : U} → PLUS t₁ t₂ ⟷ PLUS t₂ t₁
assocl₊ : {t₁ t₂ t₃ : U} → PLUS t₁ (PLUS t₂ t₃) ⟷ PLUS (PLUS t₁ t₂) t₃
assocr₊ : {t₁ t₂ t₃ : U} → PLUS (PLUS t₁ t₂) t₃ ⟷ PLUS t₁ (PLUS t₂ t₃)
unite⋆ : {t : U} → TIMES ONE t ⟷ t
uniti⋆ : {t : U} → t ⟷ TIMES ONE t
swap⋆ : {t₁ t₂ : U} → TIMES t₁ t₂ ⟷ TIMES t₂ t₁
assocl⋆ : {t₁ t₂ t₃ : U} → TIMES t₁ (TIMES t₂ t₃) ⟷ TIMES (TIMES t₁ t₂) t₃
assocr⋆ : {t₁ t₂ t₃ : U} → TIMES (TIMES t₁ t₂) t₃ ⟷ TIMES t₁ (TIMES t₂ t₃)
distz : {t : U} → TIMES ZERO t ⟷ ZERO
factorz : {t : U} → ZERO ⟷ TIMES ZERO t
dist : {t₁ t₂ t₃ : U} →
TIMES (PLUS t₁ t₂) t₃ ⟷ PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)
factor : {t₁ t₂ t₃ : U} →
PLUS (TIMES t₁ t₃) (TIMES t₂ t₃) ⟷ TIMES (PLUS t₁ t₂) t₃
-}
id⟷ : {t₁ t₂ : Pi0.U} {c : t₁ Pi0.⟷ t₂} {v₀ : Pi0.⟦ t₁ ⟧} {v₁ : Pi0.⟦ t₂ ⟧} → EQUIV c v₀ v₁ ⟷ EQUIV c v₀ v₁
sym⟷ : {t₁ t₂ : Pi0.U} {c d : t₁ Pi0.⟷ t₂} {v₀ : Pi0.⟦ t₁ ⟧} {v₁ : Pi0.⟦ t₂ ⟧} → EQUIV c v₀ v₁ ⟷ EQUIV d v₀ v₁ → EQUIV d v₀ v₁ ⟷ EQUIV c v₀ v₁
_◎_ : {t₁ t₂ : Pi0.U} {c d e : t₁ Pi0.⟷ t₂} {v₀ : Pi0.⟦ t₁ ⟧} {v₁ : Pi0.⟦ t₂ ⟧} → EQUIV c v₀ v₁ ⟷ EQUIV d v₀ v₁ → EQUIV d v₀ v₁ ⟷ EQUIV e v₀ v₁ → EQUIV c v₀ v₁ ⟷ EQUIV e v₀ v₁
{-
_⊕_ : {t₁ t₂ t₃ t₄ : U} →
(t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (PLUS t₁ t₂ ⟷ PLUS t₃ t₄)
_⊗_ : {t₁ t₂ t₃ t₄ : U} →
(t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (TIMES t₁ t₂ ⟷ TIMES t₃ t₄)
-}
lidl : {t₁ t₂ : Pi0.U}
{c : t₁ Pi0.⟷ t₂} {v₁ : Pi0.⟦ t₁ ⟧} {v₂ : Pi0.⟦ t₂ ⟧} →
EQUIV (Pi0.id⟷ Pi0.◎ c) v₁ v₂ ⟷ EQUIV c v₁ v₂
lidr : {t₁ t₂ : Pi0.U}
{c : t₁ Pi0.⟷ t₂} {v₁ : Pi0.⟦ t₁ ⟧} {v₂ : Pi0.⟦ t₂ ⟧} →
EQUIV c v₁ v₂ ⟷ EQUIV (Pi0.id⟷ Pi0.◎ c) v₁ v₂
ridl : {t₁ t₂ : Pi0.U}
{c : t₁ Pi0.⟷ t₂} {v₁ : Pi0.⟦ t₁ ⟧} {v₂ : Pi0.⟦ t₂ ⟧} →
EQUIV (c Pi0.◎ Pi0.id⟷) v₁ v₂ ⟷ EQUIV c v₁ v₂
ridr : {t₁ t₂ : Pi0.U}
{c : t₁ Pi0.⟷ t₂} {v₁ : Pi0.⟦ t₁ ⟧} {v₂ : Pi0.⟦ t₂ ⟧} →
EQUIV c v₁ v₂ ⟷ EQUIV (c Pi0.◎ Pi0.id⟷) v₁ v₂
invll : {t₁ t₂ : Pi0.U} {c : t₁ Pi0.⟷ t₂} {v₀ v₂ : Pi0.⟦ t₂ ⟧} →
EQUIV (Pi0.sym⟷ c Pi0.◎ c) v₀ v₂ ⟷ EQUIV Pi0.id⟷ v₀ v₂
invlr : {t₁ t₂ : Pi0.U} {c : t₁ Pi0.⟷ t₂} {v₀ v₂ : Pi0.⟦ t₂ ⟧} →
EQUIV Pi0.id⟷ v₀ v₂ ⟷ EQUIV (Pi0.sym⟷ c Pi0.◎ c) v₀ v₂
invrl : {t₁ t₂ : Pi0.U} {c : t₁ Pi0.⟷ t₂} {v₀ v₁ : Pi0.⟦ t₁ ⟧} →
EQUIV (c Pi0.◎ Pi0.sym⟷ c) v₀ v₁ ⟷ EQUIV Pi0.id⟷ v₀ v₁
invrr : {t₁ t₂ : Pi0.U} {c : t₁ Pi0.⟷ t₂} {v₀ v₁ : Pi0.⟦ t₁ ⟧} →
EQUIV Pi0.id⟷ v₀ v₁ ⟷ EQUIV (c Pi0.◎ Pi0.sym⟷ c) v₀ v₁
invinvl : {t₁ t₂ : Pi0.U}
{c : t₁ Pi0.⟷ t₂} {v₁ : Pi0.⟦ t₁ ⟧} {v₂ : Pi0.⟦ t₂ ⟧} →
EQUIV (Pi0.sym⟷ (Pi0.sym⟷ c)) v₁ v₂ ⟷ EQUIV c v₁ v₂
invinvr : {t₁ t₂ : Pi0.U}
{c : t₁ Pi0.⟷ t₂} {v₁ : Pi0.⟦ t₁ ⟧} {v₂ : Pi0.⟦ t₂ ⟧} →
EQUIV c v₁ v₂ ⟷ EQUIV (Pi0.sym⟷ (Pi0.sym⟷ c)) v₁ v₂
tassocl : {t₁ t₂ t₃ t₄ : Pi0.U}
{c₁ : t₁ Pi0.⟷ t₂} {c₂ : t₂ Pi0.⟷ t₃} {c₃ : t₃ Pi0.⟷ t₄}
{v₁ : Pi0.⟦ t₁ ⟧} {v₄ : Pi0.⟦ t₄ ⟧} →
EQUIV (c₁ Pi0.◎ (c₂ Pi0.◎ c₃)) v₁ v₄ ⟷
EQUIV ((c₁ Pi0.◎ c₂) Pi0.◎ c₃) v₁ v₄
tassocr : {t₁ t₂ t₃ t₄ : Pi0.U}
{c₁ : t₁ Pi0.⟷ t₂} {c₂ : t₂ Pi0.⟷ t₃} {c₃ : t₃ Pi0.⟷ t₄}
{v₁ : Pi0.⟦ t₁ ⟧} {v₄ : Pi0.⟦ t₄ ⟧} →
EQUIV ((c₁ Pi0.◎ c₂) Pi0.◎ c₃) v₁ v₄ ⟷
EQUIV (c₁ Pi0.◎ (c₂ Pi0.◎ c₃)) v₁ v₄
-- this is closely related to Eckmann-Hilton
resp◎ : {t₁ t₂ t₃ : Pi0.U}
{c₁ : t₁ Pi0.⟷ t₂} {c₂ : t₂ Pi0.⟷ t₃}
{c₃ : t₁ Pi0.⟷ t₂} {c₄ : t₂ Pi0.⟷ t₃}
{v₁ : Pi0.⟦ t₁ ⟧} {v₂ : Pi0.⟦ t₂ ⟧} {v₃ : Pi0.⟦ t₃ ⟧} →
(EQUIV c₁ v₁ v₂ ⟷ EQUIV c₃ v₁ v₂) →
(EQUIV c₂ v₂ v₃ ⟷ EQUIV c₄ v₂ v₃) →
EQUIV (c₁ Pi0.◎ c₂) v₁ v₃ ⟷ EQUIV (c₃ Pi0.◎ c₄) v₁ v₃
-- extractor for ⟷
src : {t₁ t₂ : U} → t₁ ⟷ t₂ → Pi0.U
src (id⟷ {t₁}) = t₁
src (sym⟷ {t₁} c) = t₁
src (_◎_ {t₁} _ _) = t₁
src (lidl {t₁}) = t₁
src (lidr {t₁}) = t₁
src (ridl {t₁}) = t₁
src (ridr {t₁}) = t₁
src (invll {t₁}) = t₁
src (invlr {t₁}) = t₁
src (invrl {t₁}) = t₁
src (invrr {t₁}) = t₁
src (invinvl {t₁}) = t₁
src (invinvr {t₁}) = t₁
src (tassocl {t₁}) = t₁
src (tassocr {t₁}) = t₁
src (resp◎ {t₁} _ _) = t₁
val : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) → Pi0.⟦ src c ⟧
val (id⟷ {v₀ = v₀}) = v₀
val (sym⟷ {v₀ = v₀} c) = v₀
val (c ◎ c₁) = {!!}
val lidl = {!!}
val lidr = {!!}
val ridl = {!!}
val ridr = {!!}
val invll = {!!}
val invlr = {!!}
val invrl = {!!}
val invrr = {!!}
val invinvl = {!!}
val invinvr = {!!}
val tassocl = {!!}
val tassocr = {!!}
val (resp◎ c c₅) = {!!}
-- Examples
-- id;swap₊ is equivalent to swap₊
e₁ : EQUIV (Pi0.id⟷ Pi0.◎ Pi0.swap₊) Pi0.FALSE Pi0.TRUE ⟷
EQUIV Pi0.swap₊ Pi0.FALSE Pi0.TRUE
e₁ = lidl
-- swap₊;id;swap₊ is equivalent to id
e₂ : EQUIV (Pi0.swap₊ Pi0.◎ (Pi0.id⟷ Pi0.◎ Pi0.swap₊)) Pi0.FALSE Pi0.FALSE ⟷
EQUIV Pi0.id⟷ Pi0.FALSE Pi0.FALSE
e₂ = {!!}
arr : {t₁ t₂ : Pi0.U} {c : t₁ Pi0.⟷ t₂} → Pi0.⟦ t₁ ⟧ → Pi0.⟦ t₂ ⟧ → Set
arr {t₁} {t₂} {c} v₁ v₂ = ⟦ EQUIV c v₁ v₂ ⟧
-- we have a 1Groupoid structure
G : 1Groupoid
G = record
{ set = Pi0.U
; _↝_ = Pi0._⟷_
; _≈_ = λ c₀ c₁ → ∀ {v₀ v₁} → EQUIV c₀ v₀ v₁ ⟷ EQUIV c₁ v₀ v₁
; id = Pi0.id⟷
; _∘_ = λ c₀ c₁ → c₁ Pi0.◎ c₀
; _⁻¹ = Pi0.sym⟷
; lneutr = λ α → ridl {c = α}
; rneutr = λ α → lidl { c = α}
; assoc = λ α β δ {v₁} {v₄} → tassocl
; equiv = record { refl = id⟷
; sym = λ c → sym⟷ c
; trans = λ c₀ c₁ → c₀ ◎ c₁ }
; linv = λ α → invrl {c = α}
; rinv = λ α → invll {c = α}
; ∘-resp-≈ = λ {_} {_} {_} {f} {h} {g} {i} f⟷h g⟷i {v₀} {v₁} →
resp◎ {v₂ = {!val f⟷h!}} g⟷i f⟷h
}
------------------------------------------------------------------------------
-- Level 2 explicitly...
{-
module Pi2 where
-- types
data U : Set where
ZERO : U
ONE : U
PLUS : U → U → U
TIMES : U → U → U
EQUIV : {t₁ t₂ : Pi1.U} → (t₁ Pi1.⟷ t₂) → Pi1.⟦ t₁ ⟧ → Pi1.⟦ t₂ ⟧ → U
data Unite₊ {t : Pi1.U} : Pi1.⟦ Pi1.PLUS Pi1.ZERO t ⟧ → Pi1.⟦ t ⟧ → Set where
pathUnite₊ : (v₁ : Pi1.⟦ Pi1.PLUS Pi1.ZERO t ⟧) → (v₂ : Pi1.⟦ t ⟧) → Unite₊ v₁ v₂
data Id⟷ {t : Pi1.U} : Pi1.⟦ t ⟧ → Pi1.⟦ t ⟧ → Set where
pathId⟷ : (v₁ : Pi1.⟦ t ⟧) → (v₂ : Pi1.⟦ t ⟧) → Id⟷ v₁ v₂
-- values
mutual
⟦_⟧ : U → Set
⟦ ZERO ⟧ = ⊥
⟦ ONE ⟧ = ⊤
⟦ PLUS t₁ t₂ ⟧ = ⟦ t₁ ⟧ ⊎ ⟦ t₂ ⟧
⟦ TIMES t₁ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧
⟦ EQUIV c v₁ v₂ ⟧ = f c v₁ v₂
f : {t₁ t₂ : Pi1.U} → (t₁ Pi1.⟷ t₂) → Pi1.⟦ t₁ ⟧ → Pi1.⟦ t₂ ⟧ → Set
f (Pi1.id⟷ {t}) v v' = Id⟷ {t} v v'
f (Pi1._◎_ {t₂ = t₂} c₁ c₂) v₁ v₃ =
Σ[ v₂ ∈ Pi1.⟦ t₂ ⟧ ] (f c₁ v₁ v₂ × f c₂ v₂ v₃)
-- f (Pi1.lidl {v₁ = v₁}) (pathTrans .v₁ (Pi1.pathId⟷ .v₁) q) q' = ⊥ -- todo
f c v₁ v₂ = ⊥ -- to do
-- combinators
data _⟷_ : U → U → Set where
unite₊ : {t : U} → PLUS ZERO t ⟷ t
uniti₊ : {t : U} → t ⟷ PLUS ZERO t
swap₊ : {t₁ t₂ : U} → PLUS t₁ t₂ ⟷ PLUS t₂ t₁
assocl₊ : {t₁ t₂ t₃ : U} → PLUS t₁ (PLUS t₂ t₃) ⟷ PLUS (PLUS t₁ t₂) t₃
assocr₊ : {t₁ t₂ t₃ : U} → PLUS (PLUS t₁ t₂) t₃ ⟷ PLUS t₁ (PLUS t₂ t₃)
unite⋆ : {t : U} → TIMES ONE t ⟷ t
uniti⋆ : {t : U} → t ⟷ TIMES ONE t
swap⋆ : {t₁ t₂ : U} → TIMES t₁ t₂ ⟷ TIMES t₂ t₁
assocl⋆ : {t₁ t₂ t₃ : U} → TIMES t₁ (TIMES t₂ t₃) ⟷ TIMES (TIMES t₁ t₂) t₃
assocr⋆ : {t₁ t₂ t₃ : U} → TIMES (TIMES t₁ t₂) t₃ ⟷ TIMES t₁ (TIMES t₂ t₃)
distz : {t : U} → TIMES ZERO t ⟷ ZERO
factorz : {t : U} → ZERO ⟷ TIMES ZERO t
dist : {t₁ t₂ t₃ : U} →
TIMES (PLUS t₁ t₂) t₃ ⟷ PLUS (TIMES t₁ t₃) (TIMES t₂ t₃)
factor : {t₁ t₂ t₃ : U} →
PLUS (TIMES t₁ t₃) (TIMES t₂ t₃) ⟷ TIMES (PLUS t₁ t₂) t₃
id⟷ : {t : U} → t ⟷ t
sym⟷ : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₁)
_◎_ : {t₁ t₂ t₃ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃)
_⊕_ : {t₁ t₂ t₃ t₄ : U} →
(t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (PLUS t₁ t₂ ⟷ PLUS t₃ t₄)
_⊗_ : {t₁ t₂ t₃ t₄ : U} →
(t₁ ⟷ t₃) → (t₂ ⟷ t₄) → (TIMES t₁ t₂ ⟷ TIMES t₃ t₄)
lid : {t₁ t₂ : Pi1.U} {v₁ : Pi1.⟦ t₁ ⟧} {v₂ : Pi1.⟦ t₂ ⟧}
{c : t₁ Pi1.⟷ t₂} →
EQUIV (Pi1.id⟷ Pi1.◎ c) v₁ v₂ ⟷ EQUIV c v₁ v₂
-}
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.4732100016,
"avg_line_length": 36.5633528265,
"ext": "agda",
"hexsha": "e91186edaf7476bdfd631a24a8bd1bd97a75173e",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/Obsolete/A4.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/Obsolete/A4.agda",
"max_line_length": 184,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/Obsolete/A4.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 9626,
"size": 18757
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.