Search is not available for this dataset
text
string | meta
dict |
---|---|
------------------------------------------------------------------------
-- The Agda standard library
--
-- A pointwise lifting of a relation to incorporate new extrema.
-------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
-- This module is designed to be used with
-- Relation.Nullary.Construct.Add.Extrema
open import Relation.Binary
module Relation.Binary.Construct.Add.Extrema.Equality
{a ℓ} {A : Set a} (_≈_ : Rel A ℓ) where
open import Function using (_∘′_)
import Relation.Binary.Construct.Add.Infimum.Equality as AddInfimum
import Relation.Binary.Construct.Add.Supremum.Equality as AddSupremum
open import Relation.Nullary.Construct.Add.Extrema
-------------------------------------------------------------------------
-- Definition
private
module Inf = AddInfimum _≈_
module Sup = AddSupremum (Inf._≈₋_)
open Sup using () renaming (_≈⁺_ to _≈±_) public
-------------------------------------------------------------------------
-- Useful pattern synonyms
pattern ⊥±≈⊥± = Sup.[ Inf.⊥₋≈⊥₋ ]
pattern [_] p = Sup.[ Inf.[ p ] ]
pattern ⊤±≈⊤± = Sup.⊤⁺≈⊤⁺
-------------------------------------------------------------------------
-- Relational properties
[≈]-injective : ∀ {k l} → [ k ] ≈± [ l ] → k ≈ l
[≈]-injective = Inf.[≈]-injective ∘′ Sup.[≈]-injective
≈±-refl : Reflexive _≈_ → Reflexive _≈±_
≈±-refl = Sup.≈⁺-refl ∘′ Inf.≈₋-refl
≈±-sym : Symmetric _≈_ → Symmetric _≈±_
≈±-sym = Sup.≈⁺-sym ∘′ Inf.≈₋-sym
≈±-trans : Transitive _≈_ → Transitive _≈±_
≈±-trans = Sup.≈⁺-trans ∘′ Inf.≈₋-trans
≈±-dec : Decidable _≈_ → Decidable _≈±_
≈±-dec = Sup.≈⁺-dec ∘′ Inf.≈₋-dec
≈±-irrelevant : Irrelevant _≈_ → Irrelevant _≈±_
≈±-irrelevant = Sup.≈⁺-irrelevant ∘′ Inf.≈₋-irrelevant
≈±-substitutive : ∀ {ℓ} → Substitutive _≈_ ℓ → Substitutive _≈±_ ℓ
≈±-substitutive = Sup.≈⁺-substitutive ∘′ Inf.≈₋-substitutive
-------------------------------------------------------------------------
-- Structures
≈±-isEquivalence : IsEquivalence _≈_ → IsEquivalence _≈±_
≈±-isEquivalence = Sup.≈⁺-isEquivalence ∘′ Inf.≈₋-isEquivalence
≈±-isDecEquivalence : IsDecEquivalence _≈_ → IsDecEquivalence _≈±_
≈±-isDecEquivalence = Sup.≈⁺-isDecEquivalence ∘′ Inf.≈₋-isDecEquivalence
| {
"alphanum_fraction": 0.5337807606,
"avg_line_length": 31.9285714286,
"ext": "agda",
"hexsha": "690f02962f2311fbdd7001aae7b3166a65513db6",
"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/Relation/Binary/Construct/Add/Extrema/Equality.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/Relation/Binary/Construct/Add/Extrema/Equality.agda",
"max_line_length": 73,
"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/Relation/Binary/Construct/Add/Extrema/Equality.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": 764,
"size": 2235
} |
{-# OPTIONS --cubical --no-import-sorts --allow-unsolved-metas #-}
module Number.Operations where
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Relation.Nullary.Base -- ¬_
open import Cubical.Data.Unit.Base -- Unit
open import Cubical.Data.Sigma.Base renaming (_×_ to infixr 4 _×_)
open import Cubical.Data.Empty renaming (elim to ⊥-elim) -- `⊥` and `elim`
open import Function.Base using (_$_)
open import Number.Postulates
open import Number.Base
open import Number.Coercions
open import Number.Operations.Specification
open import Number.Operations.Details
open import Number.Operations.Details using (_⁻¹; -_) public
open ℕⁿ
open ℤᶻ
open ℚᶠ
open ℝʳ
open ℂᶜ
-- infixl 6 _-_
infixl 7 _·_
infixl 6 _+_
infixl 4 _#_
infixl 4 _<_
infixl 4 _≤_
-- homogeneous operations
private
_+ʰ_ : ∀{l p q} → Number (l , p) → Number (l , q) → Number (l , +-Positivityʰ l p q)
_+ʰ_ {isNat } x y = (num x +ⁿ num y) ,, (x +ʰⁿ y)
_+ʰ_ {isInt } x y = (num x +ᶻ num y) ,, (x +ʰᶻ y)
_+ʰ_ {isRat } x y = (num x +ᶠ num y) ,, (x +ʰᶠ y)
_+ʰ_ {isReal } x y = (num x +ʳ num y) ,, (x +ʰʳ y)
_+ʰ_ {isComplex} x y = (num x +ᶜ num y) ,, (x +ʰᶜ y)
_·ʰ_ : ∀{l p q} → Number (l , p) → Number (l , q) → Number (l , ·-Positivityʰ l p q)
_·ʰ_ {isNat } x y = (num x ·ⁿ num y) ,, (x ·ʰⁿ y)
_·ʰ_ {isInt } x y = (num x ·ᶻ num y) ,, (x ·ʰᶻ y)
_·ʰ_ {isRat } x y = (num x ·ᶠ num y) ,, (x ·ʰᶠ y)
_·ʰ_ {isReal } x y = (num x ·ʳ num y) ,, (x ·ʰʳ y)
_·ʰ_ {isComplex} x y = (num x ·ᶜ num y) ,, (x ·ʰᶜ y)
_<ʰ_ : ∀{L} → (x y : NumberKindInterpretation L) → Type (NumberKindProplevel L)
_<ʰ_ {isNat} x y = x <ⁿ y
_<ʰ_ {isInt} x y = x <ᶻ y
_<ʰ_ {isRat} x y = x <ᶠ y
_<ʰ_ {isReal} x y = x <ʳ y
-- NOTE: this is some realization of a partial function, because `_<_` is defined on all numbers
-- one might already anticipate that this breaks something in the future ...
_<ʰ_ {isComplex} x y = {{p : ⊥}} → Lift ⊥
_≤ʰ_ : ∀{L} → (x y : NumberKindInterpretation L) → Type (NumberKindProplevel L)
_≤ʰ_ {isNat} x y = x ≤ⁿ y
_≤ʰ_ {isInt} x y = x ≤ᶻ y
_≤ʰ_ {isRat} x y = x ≤ᶠ y
_≤ʰ_ {isReal} x y = x ≤ʳ y
-- NOTE: this is some realization of a partial function, because `_≤_` is defined on all numbers
-- one might already anticipate that this breaks something in the future ...
_≤ʰ_ {isComplex} x y = {{p : ⊥}} → Lift ⊥
_#ʰ_ : ∀{L} → (x y : NumberKindInterpretation L) → Type (NumberKindProplevel L)
_#ʰ_ {isNat} x y = x #ⁿ y
_#ʰ_ {isInt} x y = x #ᶻ y
_#ʰ_ {isRat} x y = x #ᶠ y
_#ʰ_ {isReal} x y = x #ʳ y
_#ʰ_ {isComplex} x y = x #ᶜ y
{- NOTE: this creates a weird Number.L in the Have/Goal display
module _ {Lx Ly Px Py} (x : Number (Lx , Px)) (y : Number (Ly , Py)) where
private L = maxₙₗ' Lx Ly
_+_ : Number (L , +-Positivityʰ L (coerce-PositivityKind Lx L Px) (coerce-PositivityKind Ly L Py))
_+_ =
let (Lx≤L , Ly≤L) = max-implies-≤ₙₗ₂' Lx Ly
in coerce Lx L Lx≤L x +ʰ coerce Ly L Ly≤L y
-}
-- inhomogeneous operations
_+_ : ∀{Lx Ly Px Py} → (x : Number (Lx , Px)) (y : Number (Ly , Py))
→ let L = maxₙₗ Lx Ly
in Number (L , +-Positivityʰ L (coerce-PositivityKind Lx L Px) (coerce-PositivityKind Ly L Py))
_+_ {Lx} {Ly} {Px} {Py} x y =
let L = maxₙₗ Lx Ly
(Lx≤L , Ly≤L) = max-implies-≤ₙₗ₂ Lx Ly
in coerce Lx L Lx≤L x +ʰ coerce Ly L Ly≤L y
_·_ : ∀{Lx Ly Px Py} → (x : Number (Lx , Px)) (y : Number (Ly , Py))
→ let L = maxₙₗ Lx Ly
in Number (L , ·-Positivityʰ L (coerce-PositivityKind Lx L Px) (coerce-PositivityKind Ly L Py))
_·_ {Lx} {Ly} {Px} {Py} x y =
let L = maxₙₗ Lx Ly
(Lx≤L , Ly≤L) = max-implies-≤ₙₗ₂ Lx Ly
in coerce Lx L Lx≤L x ·ʰ coerce Ly L Ly≤L y
_<_ : ∀{Lx Ly Px Py} → (x : Number (Lx , Px)) (y : Number (Ly , Py)) → Type (NumberKindProplevel (maxₙₗ Lx Ly))
_<_ {Lx} {Ly} {Px} {Py} x y =
let L = maxₙₗ Lx Ly
(Lx≤L , Ly≤L) = max-implies-≤ₙₗ₂ Lx Ly
in num (coerce Lx L Lx≤L x) <ʰ num (coerce Ly L Ly≤L y)
_≤_ : ∀{Lx Ly Px Py} → (x : Number (Lx , Px)) (y : Number (Ly , Py)) → Type (NumberKindProplevel (maxₙₗ Lx Ly))
_≤_ {Lx} {Ly} {Px} {Py} x y =
let L = maxₙₗ Lx Ly
(Lx≤L , Ly≤L) = max-implies-≤ₙₗ₂ Lx Ly
in num (coerce Lx L Lx≤L x) ≤ʰ num (coerce Ly L Ly≤L y)
_#_ : ∀{Lx Ly Px Py} → (x : Number (Lx , Px)) (y : Number (Ly , Py)) → Type (NumberKindProplevel (maxₙₗ Lx Ly))
_#_ {Lx} {Ly} {Px} {Py} x y =
let L = maxₙₗ Lx Ly
(Lx≤L , Ly≤L) = max-implies-≤ₙₗ₂ Lx Ly
in num (coerce Lx L Lx≤L x) #ʰ num (coerce Ly L Ly≤L y)
| {
"alphanum_fraction": 0.5876963351,
"avg_line_length": 37.2682926829,
"ext": "agda",
"hexsha": "d9b1ffe51c1e03d00db9306bcac4676ee0944331",
"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": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "agda/Number/Operations.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"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": "mchristianl/synthetic-reals",
"max_issues_repo_path": "agda/Number/Operations.agda",
"max_line_length": 111,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "agda/Number/Operations.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 2113,
"size": 4584
} |
{-# OPTIONS --without-K --exact-split --safe #-}
module Fragment.Extensions.CSemigroup.Monomial where
open import Fragment.Equational.Theory.Bundles
open import Fragment.Algebra.Signature
open import Fragment.Algebra.Free Σ-magma hiding (_~_)
open import Fragment.Algebra.Homomorphism Σ-magma
open import Fragment.Algebra.Algebra Σ-magma
using (Algebra; IsAlgebra; Interpretation; Congruence)
open import Fragment.Equational.Model Θ-csemigroup
open import Fragment.Setoid.Morphism using (_↝_)
open import Fragment.Extensions.CSemigroup.Nat
open import Data.Nat using (ℕ; zero; suc; _≟_)
open import Data.Fin using (Fin; #_; zero; suc; toℕ; fromℕ)
open import Data.Vec using (Vec; []; _∷_)
open import Data.Vec.Relation.Binary.Pointwise.Inductive using ([]; _∷_)
open import Relation.Nullary using (yes ; no)
open import Relation.Binary.PropositionalEquality as PE using (_≡_)
open import Relation.Binary using (Setoid; IsEquivalence)
import Relation.Binary.Reasoning.Setoid as Reasoning
data Monomial : ℕ → Set where
leaf : ∀ {n} → ℕ⁺ → Monomial (suc n)
skip : ∀ {n} → Monomial n → Monomial (suc n)
cons : ∀ {n} → ℕ⁺ → Monomial n → Monomial (suc n)
lift : ∀ {n} → Monomial n → Monomial (suc n)
lift (leaf x) = leaf x
lift (skip x) = skip (lift x)
lift (cons x xs) = cons x (lift xs)
_⊗_ : ∀ {n} → Monomial n → Monomial n → Monomial n
leaf x ⊗ leaf y = leaf (x + y)
leaf x ⊗ skip y = cons x y
leaf x ⊗ cons y ys = cons (x + y) ys
skip x ⊗ leaf y = cons y x
skip x ⊗ skip y = skip (x ⊗ y)
skip x ⊗ cons y ys = cons y (x ⊗ ys)
cons x xs ⊗ leaf y = cons (x + y) xs
cons x xs ⊗ skip y = cons x (xs ⊗ y)
cons x xs ⊗ cons y ys = cons (x + y) (xs ⊗ ys)
⊗-cong : ∀ {n} {x y z w : Monomial n}
→ x ≡ y → z ≡ w → x ⊗ z ≡ y ⊗ w
⊗-cong = PE.cong₂ _⊗_
⊗-comm : ∀ {n} (x y : Monomial n) → x ⊗ y ≡ y ⊗ x
⊗-comm (leaf x) (leaf y) = PE.cong leaf (+-comm x y)
⊗-comm (leaf x) (skip y) = PE.refl
⊗-comm (leaf x) (cons y ys) = PE.cong₂ cons (+-comm x y) PE.refl
⊗-comm (skip x) (leaf y) = PE.refl
⊗-comm (skip x) (skip y) = PE.cong skip (⊗-comm x y)
⊗-comm (skip x) (cons y ys) = PE.cong (cons y) (⊗-comm x ys)
⊗-comm (cons x xs) (leaf y) = PE.cong₂ cons (+-comm x y) PE.refl
⊗-comm (cons x xs) (skip y) = PE.cong (cons x) (⊗-comm xs y)
⊗-comm (cons x xs) (cons y ys) = PE.cong₂ cons (+-comm x y) (⊗-comm xs ys)
⊗-assoc : ∀ {n} (x y z : Monomial n) → (x ⊗ y) ⊗ z ≡ x ⊗ (y ⊗ z)
⊗-assoc (leaf x) (leaf y) (leaf z) = PE.cong leaf (+-assoc x y z)
⊗-assoc (leaf x) (leaf y) (skip z) = PE.refl
⊗-assoc (leaf x) (leaf y) (cons z zs) = PE.cong₂ cons (+-assoc x y z) PE.refl
⊗-assoc (leaf x) (skip y) (leaf z) = PE.refl
⊗-assoc (leaf x) (skip y) (skip z) = PE.refl
⊗-assoc (leaf x) (skip y) (cons z zs) = PE.refl
⊗-assoc (leaf x) (cons y ys) (leaf z) = PE.cong₂ cons (+-assoc x y z) PE.refl
⊗-assoc (leaf x) (cons y ys) (skip z) = PE.refl
⊗-assoc (leaf x) (cons y ys) (cons z zs) = PE.cong₂ cons (+-assoc x y z) PE.refl
⊗-assoc (skip x) (leaf y) (leaf z) = PE.refl
⊗-assoc (skip x) (leaf y) (skip z) = PE.refl
⊗-assoc (skip x) (leaf y) (cons z zs) = PE.refl
⊗-assoc (skip x) (skip y) (leaf z) = PE.refl
⊗-assoc (skip x) (skip y) (skip z) = PE.cong skip (⊗-assoc x y z)
⊗-assoc (skip x) (skip y) (cons z zs) = PE.cong (cons z) (⊗-assoc x y zs)
⊗-assoc (skip x) (cons y ys) (leaf z) = PE.refl
⊗-assoc (skip x) (cons y ys) (skip z) = PE.cong (cons y) (⊗-assoc x ys z)
⊗-assoc (skip x) (cons y ys) (cons z zs) = PE.cong (cons (y + z)) (⊗-assoc x ys zs)
⊗-assoc (cons x xs) (leaf y) (leaf z) = PE.cong₂ cons (+-assoc x y z) PE.refl
⊗-assoc (cons x xs) (leaf y) (skip z) = PE.refl
⊗-assoc (cons x xs) (leaf y) (cons z zs) = PE.cong₂ cons (+-assoc x y z) PE.refl
⊗-assoc (cons x xs) (skip y) (leaf z) = PE.refl
⊗-assoc (cons x xs) (skip y) (skip z) = PE.cong (cons x) (⊗-assoc xs y z)
⊗-assoc (cons x xs) (skip y) (cons z zs) = PE.cong (cons (x + z)) (⊗-assoc xs y zs)
⊗-assoc (cons x xs) (cons y ys) (leaf z) = PE.cong₂ cons (+-assoc x y z) PE.refl
⊗-assoc (cons x xs) (cons y ys) (skip z) = PE.cong (cons (x + y)) (⊗-assoc xs ys z)
⊗-assoc (cons x xs) (cons y ys) (cons z zs) = PE.cong₂ cons (+-assoc x y z) (⊗-assoc xs ys zs)
module _ (n : ℕ) where
private
Monomial/≡ : Setoid _ _
Monomial/≡ = PE.setoid (Monomial n)
Monomial⟦_⟧ : Interpretation Monomial/≡
Monomial⟦ • ⟧ (x ∷ y ∷ []) = x ⊗ y
Monomial⟦_⟧-cong : Congruence Monomial/≡ Monomial⟦_⟧
Monomial⟦ • ⟧-cong (p ∷ q ∷ []) = PE.cong₂ _⊗_ p q
Monomial/≡-isAlgebra : IsAlgebra (Monomial/≡)
Monomial/≡-isAlgebra = record { ⟦_⟧ = Monomial⟦_⟧
; ⟦⟧-cong = Monomial⟦_⟧-cong
}
Monomial/≡-algebra : Algebra
Monomial/≡-algebra =
record { ∥_∥/≈ = Monomial/≡
; ∥_∥/≈-isAlgebra = Monomial/≡-isAlgebra
}
Monomial/≡-models : Models Monomial/≡-algebra
Monomial/≡-models comm θ = ⊗-comm (θ (# 0)) (θ (# 1))
Monomial/≡-models assoc θ = ⊗-assoc (θ (# 0)) (θ (# 1)) (θ (# 2))
Monomial/≡-isModel : IsModel Monomial/≡
Monomial/≡-isModel =
record { isAlgebra = Monomial/≡-isAlgebra
; models = Monomial/≡-models
}
J' : Model
J' = record { ∥_∥/≈ = Monomial/≡
; isModel = Monomial/≡-isModel
}
private
module _ {n : ℕ} where
open Setoid ∥ J n ∥/≈ using (_≈_)
_·_ : ∥ J n ∥ → ∥ J n ∥ → ∥ J n ∥
x · y = term • (x ∷ y ∷ [])
·-cong : ∀ {x y z w} → x ≈ y → z ≈ w → x · z ≈ y · w
·-cong p q = cong • (p ∷ q ∷ [])
·-comm : ∀ x y → x · y ≈ y · x
·-comm x y = axiom comm (env {A = ∥ J n ∥ₐ} (x ∷ y ∷ []))
·-assoc : ∀ x y z → (x · y) · z ≈ x · (y · z)
·-assoc x y z = axiom assoc (env {A = ∥ J n ∥ₐ} (x ∷ y ∷ z ∷ []))
module _ (n : ℕ) where
open Setoid ∥ J (suc n) ∥/≈ using (_≈_)
exp : ℕ⁺ → ∥ J (suc n) ∥
exp one = atomise n
exp (suc k) = atomise n · exp k
exp-hom : ∀ {j k} → exp j · exp k ≈ exp (j + k)
exp-hom {one} {k} = refl
exp-hom {suc j} {k} = begin
(atomise n · exp j) · exp k
≈⟨ ·-assoc (atomise n) (exp j) (exp k) ⟩
atomise n · (exp j · exp k)
≈⟨ ·-cong refl exp-hom ⟩
atomise n · exp (j + k)
∎
where open Reasoning ∥ J (suc n) ∥/≈
∣syn∣ : ∀ {n} → ∥ J' n ∥ → ∥ J n ∥
∣syn∣ {suc n} (leaf k) = exp n k
∣syn∣ {suc n} (skip x) = ∣ raise ∣ (∣syn∣ x)
∣syn∣ {suc n} (cons k xs) = exp n k · ∣ raise ∣ (∣syn∣ xs)
∣syn∣-cong : ∀ {n} → Congruent _≡_ ≈[ J n ] ∣syn∣
∣syn∣-cong {n} p = Setoid.reflexive ∥ J n ∥/≈ (PE.cong ∣syn∣ p)
∣syn∣⃗ : ∀ {n} → ∥ J' n ∥/≈ ↝ ∥ J n ∥/≈
∣syn∣⃗ {n} = record { ∣_∣ = ∣syn∣ {n}
; ∣_∣-cong = ∣syn∣-cong {n}
}
∣syn∣-hom : ∀ {n} → Homomorphic ∥ J' n ∥ₐ ∥ J n ∥ₐ ∣syn∣
∣syn∣-hom {suc n} • (leaf x ∷ leaf y ∷ []) = exp-hom n
∣syn∣-hom {suc n} • (leaf x ∷ skip y ∷ []) = refl
∣syn∣-hom {suc n} • (leaf x ∷ cons y ys ∷ []) = begin
exp n x · (exp n y · ∣ raise ∣ (∣syn∣ ys))
≈⟨ sym (·-assoc (exp n x) (exp n y) _) ⟩
(exp n x · exp n y) · ∣ raise ∣ (∣syn∣ ys)
≈⟨ ·-cong (exp-hom n) refl ⟩
exp n (x + y) · ∣ raise ∣ (∣syn∣ ys)
∎
where open Reasoning ∥ J (suc n) ∥/≈
∣syn∣-hom {suc n} • (skip x ∷ leaf y ∷ []) = ·-comm _ (exp n y)
∣syn∣-hom {suc n} • (skip x ∷ skip y ∷ []) = begin
∣ raise ∣ (∣syn∣ x) · ∣ raise ∣ (∣syn∣ y)
≈⟨ ∣ raise ∣-hom • (∣syn∣ x ∷ ∣syn∣ y ∷ []) ⟩
∣ raise ∣ (∣syn∣ x · ∣syn∣ y)
≈⟨ ∣ raise ∣-cong (∣syn∣-hom • (x ∷ y ∷ [])) ⟩
∣ raise ∣ (∣syn∣ (x ⊗ y))
∎
where open Reasoning ∥ J (suc n) ∥/≈
∣syn∣-hom {suc n} • (skip x ∷ cons y ys ∷ []) = begin
∣ raise ∣ (∣syn∣ x) · (exp n y · ∣ raise ∣ (∣syn∣ ys))
≈⟨ sym (·-assoc _ (exp n y) _) ⟩
(∣ raise ∣ (∣syn∣ x) · exp n y) · ∣ raise ∣ (∣syn∣ ys)
≈⟨ ·-cong (·-comm _ (exp n y)) refl ⟩
(exp n y · ∣ raise ∣ (∣syn∣ x)) · ∣ raise ∣ (∣syn∣ ys)
≈⟨ ·-assoc (exp n y) _ _ ⟩
exp n y · (∣ raise ∣ (∣syn∣ x) · ∣ raise ∣ (∣syn∣ ys))
≈⟨ ·-cong refl (∣ raise ∣-hom • (∣syn∣ x ∷ ∣syn∣ ys ∷ [])) ⟩
exp n y · ∣ raise ∣ (∣syn∣ x · ∣syn∣ ys)
≈⟨ ·-cong refl (∣ raise ∣-cong (∣syn∣-hom • (x ∷ ys ∷ []))) ⟩
exp n y · ∣ raise ∣ (∣syn∣ (x ⊗ ys))
∎
where open Reasoning ∥ J (suc n) ∥/≈
∣syn∣-hom {suc n} • (cons x xs ∷ leaf y ∷ []) = begin
(exp n x · ∣ raise ∣ (∣syn∣ xs)) · exp n y
≈⟨ ·-assoc (exp n x) _ (exp n y) ⟩
exp n x · (∣ raise ∣ (∣syn∣ xs) · exp n y)
≈⟨ ·-cong refl (·-comm _ (exp n y)) ⟩
exp n x · (exp n y · ∣ raise ∣ (∣syn∣ xs))
≈⟨ sym (·-assoc (exp n x) (exp n y) _) ⟩
(exp n x · exp n y) · ∣ raise ∣ (∣syn∣ xs)
≈⟨ ·-cong (exp-hom n) refl ⟩
exp n (x + y) · ∣ raise ∣ (∣syn∣ xs)
∎
where open Reasoning ∥ J (suc n) ∥/≈
∣syn∣-hom {suc n} • (cons x xs ∷ skip y ∷ []) = begin
(exp n x · ∣ raise ∣ (∣syn∣ xs)) · ∣ raise ∣ (∣syn∣ y)
≈⟨ ·-assoc (exp n x) _ _ ⟩
exp n x · (∣ raise ∣ (∣syn∣ xs) · ∣ raise ∣ (∣syn∣ y))
≈⟨ ·-cong refl (∣ raise ∣-hom • (∣syn∣ xs ∷ ∣syn∣ y ∷ [])) ⟩
exp n x · ∣ raise ∣ (∣syn∣ xs · ∣syn∣ y)
≈⟨ ·-cong refl (∣ raise ∣-cong (∣syn∣-hom • (xs ∷ y ∷ []))) ⟩
exp n x · ∣ raise ∣ (∣syn∣ (xs ⊗ y))
∎
where open Reasoning ∥ J (suc n) ∥/≈
∣syn∣-hom {suc n} • (cons x xs ∷ cons y ys ∷ []) = begin
(exp n x · ∣ raise ∣ (∣syn∣ xs)) · (exp n y · ∣ raise ∣ (∣syn∣ ys))
≈⟨ ·-assoc (exp n x) _ _ ⟩
exp n x · (∣ raise ∣ (∣syn∣ xs) · (exp n y · ∣ raise ∣ (∣syn∣ ys)))
≈⟨ ·-cong refl (sym (·-assoc _ (exp n y) _)) ⟩
exp n x · ((∣ raise ∣ (∣syn∣ xs) · exp n y) · ∣ raise ∣ (∣syn∣ ys))
≈⟨ ·-cong refl (·-cong (·-comm (∣ raise ∣ (∣syn∣ xs)) _) refl) ⟩
exp n x · ((exp n y · ∣ raise ∣ (∣syn∣ xs)) · ∣ raise ∣ (∣syn∣ ys))
≈⟨ ·-cong refl (·-assoc (exp n y) _ _) ⟩
exp n x · (exp n y · (∣ raise ∣ (∣syn∣ xs) · ∣ raise ∣ (∣syn∣ ys)))
≈⟨ sym (·-assoc (exp n x) (exp n y) _) ⟩
(exp n x · exp n y) · (∣ raise ∣ (∣syn∣ xs) · ∣ raise ∣ (∣syn∣ ys))
≈⟨ ·-cong (exp-hom n) (∣ raise ∣-hom • (∣syn∣ xs ∷ ∣syn∣ ys ∷ [])) ⟩
exp n (x + y) · ∣ raise ∣ (∣syn∣ xs · ∣syn∣ ys)
≈⟨ ·-cong refl (∣ raise ∣-cong (∣syn∣-hom • (xs ∷ ys ∷ []))) ⟩
exp n (x + y) · ∣ raise ∣ (∣syn∣ (xs ⊗ ys))
∎
where open Reasoning ∥ J (suc n) ∥/≈
syn : ∀ {n} → ∥ J' n ∥ₐ ⟿ ∥ J n ∥ₐ
syn = record { ∣_∣⃗ = ∣syn∣⃗
; ∣_∣-hom = ∣syn∣-hom
}
private
tab : ∀ {n} → Fin n → ∥ J' n ∥
tab {suc zero} zero = leaf one
tab {suc (suc n)} zero = skip (tab {suc n} zero)
tab {suc (suc n)} (suc k) = lift (tab {suc n} k)
norm : ∀ {n} → ∥ J n ∥ₐ ⟿ ∥ J' n ∥ₐ
norm {n} = interp (J' n) tab
private
step-exp : ∀ {n} → (k : ℕ⁺)
→ ≈[ J (suc (suc n)) ] (exp (suc n) k)
(∣ step ∣ (exp n k))
step-exp one = refl
step-exp (suc k) = ·-cong refl (step-exp k)
step-lift : ∀ {n} → (x : ∥ J' n ∥)
→ ≈[ J (suc n) ] (∣ syn ∣ (lift x))
(∣ step ∣ (∣ syn ∣ x))
step-lift {suc n} (leaf x) = step-exp x
step-lift {suc n} (skip x) = begin
∣ raise ∣ (∣ syn ∣ (lift x))
≈⟨ ∣ raise ∣-cong (step-lift x) ⟩
∣ raise ∣ (∣ step ∣ (∣ syn ∣ x))
≈⟨ sym (step-raise {x = ∣ syn ∣ x}) ⟩
∣ step ∣ (∣ raise ∣ (∣ syn ∣ x))
∎
where open Reasoning ∥ J (suc (suc n)) ∥/≈
step-lift {suc n} (cons x xs) = begin
exp (suc n) x · ∣ raise ∣ (∣ syn ∣ (lift xs))
≈⟨ ·-cong refl (∣ raise ∣-cong (step-lift xs)) ⟩
exp (suc n) x · ∣ raise ∣ (∣ step ∣ (∣ syn ∣ xs))
≈⟨ ·-cong (step-exp x) (sym (step-raise {x = ∣ syn ∣ xs})) ⟩
∣ step ∣ (exp n x) · ∣ step ∣ (∣ raise ∣ (∣ syn ∣ xs))
≈⟨ ∣ step ∣-hom • (exp n x ∷ (∣ raise ∣ (∣ syn ∣ xs)) ∷ []) ⟩
∣ step ∣ (exp n x · ∣ raise ∣ (∣ syn ∣ xs))
∎
where open Reasoning ∥ J (suc (suc n)) ∥/≈
syn-tab : ∀ {n} → (k : Fin n)
→ ≈[ J n ] (∣ syn ∣ (tab k)) (atom (dyn k))
syn-tab {suc zero} zero = refl
syn-tab {suc (suc n)} zero = ∣ raise ∣-cong (syn-tab zero)
syn-tab {suc (suc n)} (suc k) = begin
∣ syn ∣ (lift (tab {suc n} k))
≈⟨ step-lift (tab {suc n} k) ⟩
∣ step ∣ (∣ syn ∣ (tab {suc n} k))
≈⟨ ∣ step ∣-cong (syn-tab k) ⟩
∣ step ∣ (atom (dyn k))
∎
where open Reasoning ∥ J (suc (suc n)) ∥/≈
syn⊙norm≗id : ∀ {n} → syn {n} ⊙ norm {n} ≗ id
syn⊙norm≗id {n} {atom (dyn k)} = syn-tab k
syn⊙norm≗id {n} {term • (x ∷ y ∷ [])} = begin
∣ syn ∣ (∣ norm ∣ x ⊗ ∣ norm ∣ y)
≈⟨ sym (∣ syn ∣-hom • (∣ norm ∣ x ∷ ∣ norm ∣ y ∷ [])) ⟩
∣ syn ∣ (∣ norm ∣ x) · ∣ syn ∣ (∣ norm ∣ y)
≈⟨ ·-cong syn⊙norm≗id syn⊙norm≗id ⟩
x · y
∎
where open Reasoning ∥ J n ∥/≈
private
tab-diag : ∀ n → tab {suc n} (fromℕ n) ≡ leaf one
tab-diag zero = PE.refl
tab-diag (suc n) = PE.cong lift (tab-diag n)
norm-exp : ∀ {n} (k : ℕ⁺) → ∣ norm ∣ (exp n k) ≡ leaf k
norm-exp {n} one = tab-diag n
norm-exp {n} (suc k) = begin
∣ norm ∣ (atomise n · exp n k)
≈⟨ PE.sym (∣ norm ∣-hom • (atomise n ∷ exp n k ∷ [])) ⟩
∣ norm ∣ (atomise n) ⊗ ∣ norm ∣ (exp n k)
≈⟨ ⊗-cong (tab-diag n) (norm-exp k) ⟩
leaf one ⊗ leaf k
∎
where open Reasoning ∥ J' (suc n) ∥/≈
tab-skip : ∀ {n} → (k : Fin n) → tab {suc n} (up k) ≡ skip (tab {n} k)
tab-skip {suc zero} zero = PE.refl
tab-skip {suc (suc n)} zero = PE.refl
tab-skip {suc (suc n)} (suc k) = PE.cong lift (tab-skip k)
norm-raise : ∀ {n x} → ∣ norm {suc n} ∣ (∣ raise ∣ x) ≡ skip (∣ norm {n} ∣ x)
norm-raise {n} {atom (dyn k)} = tab-skip k
norm-raise {n} {term • (x ∷ y ∷ [])} = begin
∣ norm ∣ (∣ raise ∣ (x · y))
≡⟨ ∣ norm ∣-cong (sym (∣ raise ∣-hom • (x ∷ y ∷ []))) ⟩
∣ norm ∣ (∣ raise ∣ x · ∣ raise ∣ y)
≡⟨ PE.sym (∣ norm ∣-hom • (∣ raise ∣ x ∷ ∣ raise ∣ y ∷ [])) ⟩
∣ norm ∣ (∣ raise ∣ x) ⊗ ∣ norm ∣ (∣ raise ∣ y)
≡⟨ ⊗-cong (norm-raise {x = x}) (norm-raise {x = y}) ⟩
skip (∣ norm ∣ x ⊗ ∣ norm ∣ y)
≡⟨ PE.cong skip (∣ norm ∣-hom • (x ∷ y ∷ [])) ⟩
skip (∣ norm ∣ (x · y))
∎
where open PE.≡-Reasoning
norm⊙syn≗id : ∀ {n} → norm {n} ⊙ syn {n} ≗ id
norm⊙syn≗id {suc n} {leaf x} = norm-exp x
norm⊙syn≗id {suc n} {skip x} = begin
∣ norm ∣ (∣ raise ∣ (∣ syn ∣ x))
≈⟨ norm-raise {x = ∣ syn ∣ x} ⟩
skip (∣ norm ∣ (∣ syn ∣ x))
≈⟨ PE.cong skip norm⊙syn≗id ⟩
skip x
∎
where open Reasoning ∥ J' (suc n) ∥/≈
norm⊙syn≗id {suc n} {cons x xs} = begin
∣ norm ∣ (exp n x · ∣ raise ∣ (∣ syn ∣ xs))
≈⟨ PE.sym (∣ norm ∣-hom • (exp n x ∷ ∣ raise ∣ (∣ syn ∣ xs) ∷ [])) ⟩
∣ norm ∣ (exp n x) ⊗ ∣ norm ∣ (∣ raise ∣ (∣ syn ∣ xs))
≈⟨ ⊗-cong (norm-exp x) (norm-raise {x = ∣ syn ∣ xs}) ⟩
leaf x ⊗ skip (∣ norm ∣ (∣ syn ∣ xs))
≈⟨ ⊗-cong (PE.refl {x = leaf x}) (PE.cong skip (norm⊙syn≗id {x = xs})) ⟩
leaf x ⊗ skip xs
∎
where open Reasoning ∥ J' (suc n) ∥/≈
iso : ∀ {n} → ∥ J n ∥ₐ ≃ ∥ J' n ∥ₐ
iso = record { _⃗ = norm
; _⃖ = syn
; invˡ = norm⊙syn≗id
; invʳ = syn⊙norm≗id
}
| {
"alphanum_fraction": 0.4715500327,
"avg_line_length": 39.104859335,
"ext": "agda",
"hexsha": "64a3a4b47f13193529bcb0aad8526a5a891a1d17",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Extensions/CSemigroup/Monomial.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Extensions/CSemigroup/Monomial.agda",
"max_line_length": 94,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Extensions/CSemigroup/Monomial.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z",
"num_tokens": 7185,
"size": 15290
} |
-- Properties of (pre)additive categories
{-# OPTIONS --safe #-}
module Cubical.Categories.Additive.Properties where
open import Cubical.Algebra.AbGroup.Base
open import Cubical.Algebra.Group.Properties
open import Cubical.Categories.Additive.Base
open import Cubical.Foundations.Prelude
private
variable
ℓ ℓ' : Level
-- Some useful lemmas about preadditive categories
module PreaddCategoryTheory (C : PreaddCategory ℓ ℓ') where
open PreaddCategory C
-- Pure group theory lemmas
+idl = λ {x y} → AbGroupStr.+IdL (homAbStr x y)
+idr = λ {x y} → AbGroupStr.+IdR (homAbStr x y)
+invl = λ {x y} → AbGroupStr.+InvL (homAbStr x y)
+invr = λ {x y} → AbGroupStr.+InvR (homAbStr x y)
+assoc = λ {x y} → AbGroupStr.+Assoc (homAbStr x y)
+comm = λ {x y} → AbGroupStr.+Comm (homAbStr x y)
-dist+ : {x y : ob} (f g : Hom[ x , y ]) →
- (f + g) ≡ (- f) + (- g)
-dist+ {x} {y} f g =
let open GroupTheory (AbGroup→Group (Hom[ x , y ] , homAbStr x y)) in
(invDistr _ _) ∙ (+comm _ _)
+4assoc : {x y : ob} (a b c d : Hom[ x , y ]) →
(a + b) + (c + d) ≡ a + (b + c) + d
+4assoc a b c d = sym (+assoc _ _ _) ∙ cong (a +_) (+assoc _ _ _)
+4comm : {x y : ob} (a b c d : Hom[ x , y ]) →
(a + b) + (c + d) ≡ (a + c) + (b + d)
+4comm a b c d = +4assoc _ _ _ _ ∙
cong (λ u → a + (u + d)) (+comm _ _) ∙ sym (+4assoc _ _ _ _)
-- Interaction of categorical & group structure
⋆0hl : ∀ {w x y} (f : Hom[ x , y ]) → 0h ⋆ f ≡ 0h {w}
⋆0hl f =
0h ⋆ f ≡⟨ sym (+idr _) ⟩
0h ⋆ f + 0h ≡⟨ cong (0h ⋆ f +_) (sym (+invr _)) ⟩
0h ⋆ f + (0h ⋆ f - 0h ⋆ f) ≡⟨ +assoc _ _ _ ⟩
(0h ⋆ f + 0h ⋆ f) - 0h ⋆ f ≡⟨ cong (_- 0h ⋆ f) (sym (⋆distr+ _ _ _)) ⟩
(0h + 0h) ⋆ f - 0h ⋆ f ≡⟨ cong (λ a → a ⋆ f - 0h ⋆ f) (+idr _) ⟩
0h ⋆ f - 0h ⋆ f ≡⟨ +invr _ ⟩
0h ∎
⋆0hr : ∀ {x y z} (f : Hom[ x , y ]) → f ⋆ 0h ≡ 0h {x} {z}
⋆0hr f =
f ⋆ 0h ≡⟨ sym (+idr _) ⟩
f ⋆ 0h + 0h ≡⟨ cong (f ⋆ 0h +_) (sym (+invr _)) ⟩
f ⋆ 0h + (f ⋆ 0h - f ⋆ 0h) ≡⟨ +assoc _ _ _ ⟩
(f ⋆ 0h + f ⋆ 0h) - f ⋆ 0h ≡⟨ cong (_- f ⋆ 0h) (sym (⋆distl+ _ _ _)) ⟩
f ⋆ (0h + 0h) - f ⋆ 0h ≡⟨ cong (λ a → f ⋆ a - f ⋆ 0h) (+idr _) ⟩
f ⋆ 0h - f ⋆ 0h ≡⟨ +invr _ ⟩
0h ∎
-distl⋆ : ∀ {x y z} (f : Hom[ x , y ]) (g : Hom[ y , z ])
→ (- f) ⋆ g ≡ - (f ⋆ g)
-distl⋆ {x} {y} {z} f g =
let open GroupTheory (AbGroup→Group (Hom[ x , z ] , homAbStr x z)) in
invUniqueR (
f ⋆ g + (- f) ⋆ g ≡⟨ sym (⋆distr+ _ _ _) ⟩
(f - f) ⋆ g ≡⟨ cong (_⋆ g) (+invr _) ⟩
0h ⋆ g ≡⟨ ⋆0hl _ ⟩
0h ∎
)
-distr⋆ : ∀ {x y z} (f : Hom[ x , y ]) (g : Hom[ y , z ])
→ f ⋆ (- g) ≡ - (f ⋆ g)
-distr⋆ {x} {y} {z} f g =
let open GroupTheory (AbGroup→Group (Hom[ x , z ] , homAbStr x z)) in
invUniqueR (
f ⋆ g + f ⋆ (- g) ≡⟨ sym (⋆distl+ _ _ _) ⟩
f ⋆ (g - g) ≡⟨ cong (f ⋆_) (+invr _) ⟩
f ⋆ 0h ≡⟨ ⋆0hr _ ⟩
0h ∎
)
-- Matrix notation for morphisms (x₁ ⊕ ⋯ ⊕ xₙ) → (y₁ ⊕ ⋯ ⊕ yₘ)
-- in an additive category
module MatrixNotation (A : AdditiveCategory ℓ ℓ') where
open AdditiveCategory A
open PreaddCategoryTheory preaddcat
-- Polymorphic biproduct morphisms
i₁ = λ {x y} → Biproduct.i₁ (biprod x y)
i₂ = λ {x y} → Biproduct.i₂ (biprod x y)
π₁ = λ {x y} → Biproduct.π₁ (biprod x y)
π₂ = λ {x y} → Biproduct.π₂ (biprod x y)
-- and axioms
i₁⋆π₁ = λ {x y} → Biproduct.i₁⋆π₁ (biprod x y)
i₁⋆π₂ = λ {x y} → Biproduct.i₁⋆π₂ (biprod x y)
i₂⋆π₁ = λ {x y} → Biproduct.i₂⋆π₁ (biprod x y)
i₂⋆π₂ = λ {x y} → Biproduct.i₂⋆π₂ (biprod x y)
∑π⋆i = λ {x y} → Biproduct.∑π⋆i (biprod x y)
_∣_ : ∀ {x y y'} → Hom[ x , y ] → Hom[ x , y' ] → Hom[ x , y ⊕ y' ]
f ∣ f' = (f ⋆ i₁) + (f' ⋆ i₂)
infixr 5 _∣_
_`_ : ∀ {y y' z} → Hom[ y , z ] → Hom[ y' , z ] → Hom[ y ⊕ y' , z ]
g ` g' = (π₁ ⋆ g) + (π₂ ⋆ g')
infixr 6 _`_
-- Use the matrix notation like this:
private module _ (x y : ob) (f : Hom[ x , y ]) where
h : Hom[ x ⊕ x ⊕ x , y ⊕ y ⊕ y ⊕ y ]
h = f ` - f ` 0h ∣
0h ` 0h ` f ∣
f ` - f ` 0h ∣
0h ` f ` f + f
-- Exchange law
exchange : ∀ {x x' y y'} (a : Hom[ x , y ]) (b : Hom[ x' , y ])
(c : Hom[ x , y' ]) (d : Hom[ x' , y' ]) →
(a ` b ∣ c ` d) ≡ (a ∣ c) ` (b ∣ d)
exchange a b c d =
(π₁ ⋆ a + π₂ ⋆ b) ⋆ i₁ + (π₁ ⋆ c + π₂ ⋆ d) ⋆ i₂
≡⟨ cong₂ _+_ (⋆distr+ _ _ _) (⋆distr+ _ _ _) ⟩
((π₁ ⋆ a) ⋆ i₁ + (π₂ ⋆ b) ⋆ i₁) + ((π₁ ⋆ c) ⋆ i₂ + (π₂ ⋆ d) ⋆ i₂)
≡⟨ +4comm _ _ _ _ ⟩
((π₁ ⋆ a) ⋆ i₁ + (π₁ ⋆ c) ⋆ i₂) + ((π₂ ⋆ b) ⋆ i₁ + (π₂ ⋆ d) ⋆ i₂)
≡⟨ cong₂ _+_ (cong₂ _+_ (⋆Assoc _ _ _) (⋆Assoc _ _ _))
(cong₂ _+_ (⋆Assoc _ _ _) (⋆Assoc _ _ _)) ⟩
(π₁ ⋆ (a ⋆ i₁) + π₁ ⋆ (c ⋆ i₂)) + (π₂ ⋆ (b ⋆ i₁) + π₂ ⋆ (d ⋆ i₂))
≡⟨ sym (cong₂ _+_ (⋆distl+ _ _ _) (⋆distl+ _ _ _)) ⟩
π₁ ⋆ (a ⋆ i₁ + c ⋆ i₂) + π₂ ⋆ (b ⋆ i₁ + d ⋆ i₂)
∎
-- iₖ times a row
module _ {x x' y : ob} (a : Hom[ x , y ]) (b : Hom[ x' , y ]) where
i₁⋆row : i₁ ⋆ (a ` b) ≡ a
i₁⋆row =
i₁ ⋆ (π₁ ⋆ a + π₂ ⋆ b)
≡⟨ ⋆distl+ _ _ _ ⟩
i₁ ⋆ (π₁ ⋆ a) + i₁ ⋆ (π₂ ⋆ b)
≡⟨ cong₂ _+_ (sym (⋆Assoc _ _ _)) (sym (⋆Assoc _ _ _)) ⟩
(i₁ ⋆ π₁) ⋆ a + (i₁ ⋆ π₂) ⋆ b
≡⟨ cong₂ (λ u v → u ⋆ a + v ⋆ b) i₁⋆π₁ i₁⋆π₂ ⟩
id ⋆ a + 0h ⋆ b
≡⟨ cong₂ _+_ (⋆IdL _) (⋆0hl _) ⟩
a + 0h
≡⟨ +idr _ ⟩
a ∎
i₂⋆row : i₂ ⋆ (a ` b) ≡ b
i₂⋆row =
i₂ ⋆ (π₁ ⋆ a + π₂ ⋆ b)
≡⟨ ⋆distl+ _ _ _ ⟩
i₂ ⋆ (π₁ ⋆ a) + i₂ ⋆ (π₂ ⋆ b)
≡⟨ cong₂ _+_ (sym (⋆Assoc _ _ _)) (sym (⋆Assoc _ _ _)) ⟩
(i₂ ⋆ π₁) ⋆ a + (i₂ ⋆ π₂) ⋆ b
≡⟨ cong₂ (λ u v → u ⋆ a + v ⋆ b) i₂⋆π₁ i₂⋆π₂ ⟩
0h ⋆ a + id ⋆ b
≡⟨ cong₂ _+_ (⋆0hl _) (⋆IdL _) ⟩
0h + b
≡⟨ +idl _ ⟩
b ∎
-- A column times πₖ
module _ {x y y' : ob} (a : Hom[ x , y ]) (b : Hom[ x , y' ]) where
col⋆π₁ : (a ∣ b) ⋆ π₁ ≡ a
col⋆π₁ =
(a ⋆ i₁ + b ⋆ i₂) ⋆ π₁
≡⟨ ⋆distr+ _ _ _ ⟩
(a ⋆ i₁) ⋆ π₁ + (b ⋆ i₂) ⋆ π₁
≡⟨ cong₂ _+_ (⋆Assoc _ _ _) (⋆Assoc _ _ _) ⟩
a ⋆ (i₁ ⋆ π₁) + b ⋆ (i₂ ⋆ π₁)
≡⟨ cong₂ (λ u v → a ⋆ u + b ⋆ v) i₁⋆π₁ i₂⋆π₁ ⟩
a ⋆ id + b ⋆ 0h
≡⟨ cong₂ _+_ (⋆IdR _) (⋆0hr _) ⟩
a + 0h
≡⟨ +idr _ ⟩
a ∎
col⋆π₂ : (a ∣ b) ⋆ π₂ ≡ b
col⋆π₂ =
(a ⋆ i₁ + b ⋆ i₂) ⋆ π₂
≡⟨ ⋆distr+ _ _ _ ⟩
(a ⋆ i₁) ⋆ π₂ + (b ⋆ i₂) ⋆ π₂
≡⟨ cong₂ _+_ (⋆Assoc _ _ _) (⋆Assoc _ _ _) ⟩
a ⋆ (i₁ ⋆ π₂) + b ⋆ (i₂ ⋆ π₂)
≡⟨ cong₂ (λ u v → a ⋆ u + b ⋆ v) i₁⋆π₂ i₂⋆π₂ ⟩
a ⋆ 0h + b ⋆ id
≡⟨ cong₂ _+_ (⋆0hr _) (⋆IdR _) ⟩
0h + b
≡⟨ +idl _ ⟩
b ∎
-- iₖ / πₖ times a diagonal matrix
module _ {x x' y y'} (a : Hom[ x , y ]) (b : Hom[ x' , y' ]) where
i₁⋆diag : i₁ ⋆ (a ` 0h ∣ 0h ` b) ≡ a ⋆ i₁
i₁⋆diag =
i₁ ⋆ (a ` 0h ∣ 0h ` b) ≡⟨ cong (i₁ ⋆_) (exchange _ _ _ _) ⟩
i₁ ⋆ ((a ∣ 0h) ` (0h ∣ b)) ≡⟨ i₁⋆row _ _ ⟩
(a ∣ 0h) ≡⟨ cong (a ⋆ i₁ +_) (⋆0hl _) ⟩
a ⋆ i₁ + 0h ≡⟨ +idr _ ⟩
a ⋆ i₁ ∎
i₂⋆diag : i₂ ⋆ (a ` 0h ∣ 0h ` b) ≡ b ⋆ i₂
i₂⋆diag =
i₂ ⋆ (a ` 0h ∣ 0h ` b) ≡⟨ cong (i₂ ⋆_) (exchange _ _ _ _) ⟩
i₂ ⋆ ((a ∣ 0h) ` (0h ∣ b)) ≡⟨ i₂⋆row _ _ ⟩
(0h ∣ b) ≡⟨ cong (_+ b ⋆ i₂) (⋆0hl _) ⟩
0h + b ⋆ i₂ ≡⟨ +idl _ ⟩
b ⋆ i₂ ∎
diag⋆π₁ : (a ` 0h ∣ 0h ` b) ⋆ π₁ ≡ π₁ ⋆ a
diag⋆π₁ =
(a ` 0h ∣ 0h ` b) ⋆ π₁ ≡⟨ col⋆π₁ _ _ ⟩
a ` 0h ≡⟨ cong (π₁ ⋆ a +_) (⋆0hr _) ⟩
π₁ ⋆ a + 0h ≡⟨ +idr _ ⟩
π₁ ⋆ a ∎
diag⋆π₂ : (a ` 0h ∣ 0h ` b) ⋆ π₂ ≡ π₂ ⋆ b
diag⋆π₂ =
(a ` 0h ∣ 0h ` b) ⋆ π₂ ≡⟨ col⋆π₂ _ _ ⟩
0h ` b ≡⟨ cong (_+ π₂ ⋆ b) (⋆0hr _) ⟩
0h + π₂ ⋆ b ≡⟨ +idl _ ⟩
π₂ ⋆ b ∎
-- Matrix addition
addRow : ∀ {x y z}
(f f' : Hom[ x , z ]) (g g' : Hom[ y , z ]) →
(f ` g) + (f' ` g') ≡ (f + f') ` (g + g')
addRow f f' g g' =
(π₁ ⋆ f + π₂ ⋆ g) + (π₁ ⋆ f' + π₂ ⋆ g')
≡⟨ +4comm _ _ _ _ ⟩
(π₁ ⋆ f + π₁ ⋆ f') + (π₂ ⋆ g + π₂ ⋆ g')
≡⟨ sym (cong₂ _+_ (⋆distl+ _ _ _) (⋆distl+ _ _ _)) ⟩
π₁ ⋆ (f + f') + π₂ ⋆ (g + g')
∎
addCol : ∀ {x y z}
(f f' : Hom[ x , y ]) (g g' : Hom[ x , z ]) →
(f ∣ g) + (f' ∣ g') ≡ (f + f') ∣ (g + g')
addCol f f' g g' =
(f ⋆ i₁ + g ⋆ i₂) + (f' ⋆ i₁ + g' ⋆ i₂)
≡⟨ +4comm _ _ _ _ ⟩
(f ⋆ i₁ + f' ⋆ i₁) + (g ⋆ i₂ + g' ⋆ i₂)
≡⟨ sym (cong₂ _+_ (⋆distr+ _ _ _) (⋆distr+ _ _ _)) ⟩
(f + f') ⋆ i₁ + (g + g') ⋆ i₂
∎
private
⋆4assoc : ∀ {x y z w v} (a : Hom[ x , y ]) (b : Hom[ y , z ])
(c : Hom[ z , w ]) (d : Hom[ w , v ]) →
(a ⋆ b) ⋆ (c ⋆ d) ≡ a ⋆ (b ⋆ c) ⋆ d
⋆4assoc a b c d = (⋆Assoc _ _ _) ∙ cong (a ⋆_) (sym (⋆Assoc _ _ _))
⋆4assoc' : ∀ {x y z w v} (a : Hom[ x , y ]) (b : Hom[ y , z ])
(c : Hom[ z , w ]) (d : Hom[ w , v ]) →
(a ⋆ b) ⋆ (c ⋆ d) ≡ (a ⋆ (b ⋆ c)) ⋆ d
⋆4assoc' a b c d = sym (⋆Assoc _ _ _) ∙ cong (_⋆ d) (⋆Assoc _ _ _)
-- Matrix multiplication
innerProd : ∀ {x y₁ y₂ z} (f₁ : Hom[ x , y₁ ]) (g₁ : Hom[ y₁ , z ])
(f₂ : Hom[ x , y₂ ]) (g₂ : Hom[ y₂ , z ]) →
(f₁ ∣ f₂) ⋆ (g₁ ` g₂) ≡ (f₁ ⋆ g₁) + (f₂ ⋆ g₂)
innerProd f₁ g₁ f₂ g₂ =
(f₁ ⋆ i₁ + f₂ ⋆ i₂) ⋆ (π₁ ⋆ g₁ + π₂ ⋆ g₂)
≡⟨ ⋆distr+ _ _ _ ⟩
(f₁ ⋆ i₁) ⋆ (π₁ ⋆ g₁ + π₂ ⋆ g₂) + (f₂ ⋆ i₂) ⋆ (π₁ ⋆ g₁ + π₂ ⋆ g₂)
≡⟨ cong₂ _+_ (⋆distl+ _ _ _) (⋆distl+ _ _ _) ⟩
((f₁ ⋆ i₁) ⋆ (π₁ ⋆ g₁) + (f₁ ⋆ i₁) ⋆ (π₂ ⋆ g₂))
+ (f₂ ⋆ i₂) ⋆ (π₁ ⋆ g₁) + (f₂ ⋆ i₂) ⋆ (π₂ ⋆ g₂)
≡⟨ cong₂ _+_ (cong₂ _+_ eq₁₁ eq₁₂) (cong₂ _+_ eq₂₁ eq₂₂) ⟩
(f₁ ⋆ g₁ + 0h) + 0h + f₂ ⋆ g₂
≡⟨ cong₂ _+_ (+idr _) (+idl _) ⟩
(f₁ ⋆ g₁) + (f₂ ⋆ g₂)
∎
where
eq₁₁ = (f₁ ⋆ i₁) ⋆ (π₁ ⋆ g₁) ≡⟨ ⋆4assoc _ _ _ _ ⟩
f₁ ⋆ (i₁ ⋆ π₁) ⋆ g₁ ≡⟨ cong (λ u → _ ⋆ u ⋆ _) i₁⋆π₁ ⟩
f₁ ⋆ id ⋆ g₁ ≡⟨ cong (f₁ ⋆_) (⋆IdL _) ⟩
f₁ ⋆ g₁ ∎
eq₁₂ = (f₁ ⋆ i₁) ⋆ (π₂ ⋆ g₂) ≡⟨ ⋆4assoc _ _ _ _ ⟩
f₁ ⋆ (i₁ ⋆ π₂) ⋆ g₂ ≡⟨ cong (λ u → _ ⋆ u ⋆ _) i₁⋆π₂ ⟩
f₁ ⋆ 0h ⋆ g₂ ≡⟨ cong (f₁ ⋆_) (⋆0hl _) ⟩
f₁ ⋆ 0h ≡⟨ ⋆0hr _ ⟩
0h ∎
eq₂₁ = (f₂ ⋆ i₂) ⋆ (π₁ ⋆ g₁) ≡⟨ ⋆4assoc _ _ _ _ ⟩
f₂ ⋆ (i₂ ⋆ π₁) ⋆ g₁ ≡⟨ cong (λ u → _ ⋆ u ⋆ _) i₂⋆π₁ ⟩
f₂ ⋆ 0h ⋆ g₁ ≡⟨ cong (f₂ ⋆_) (⋆0hl _) ⟩
f₂ ⋆ 0h ≡⟨ ⋆0hr _ ⟩
0h ∎
eq₂₂ = (f₂ ⋆ i₂) ⋆ (π₂ ⋆ g₂) ≡⟨ ⋆4assoc _ _ _ _ ⟩
f₂ ⋆ (i₂ ⋆ π₂) ⋆ g₂ ≡⟨ cong (λ u → _ ⋆ u ⋆ _) i₂⋆π₂ ⟩
f₂ ⋆ id ⋆ g₂ ≡⟨ cong (f₂ ⋆_) (⋆IdL _) ⟩
f₂ ⋆ g₂ ∎
outerProd : ∀ {x₁ x₂ y z₁ z₂} (f₁ : Hom[ x₁ , y ]) (g₁ : Hom[ y , z₁ ])
(f₂ : Hom[ x₂ , y ]) (g₂ : Hom[ y , z₂ ]) →
(f₁ ` f₂) ⋆ (g₁ ∣ g₂) ≡ f₁ ⋆ g₁ ` f₂ ⋆ g₁ ∣
f₁ ⋆ g₂ ` f₂ ⋆ g₂
outerProd {y = y} f₁ g₁ f₂ g₂ =
(π₁ ⋆ f₁ + π₂ ⋆ f₂) ⋆ (g₁ ⋆ i₁ + g₂ ⋆ i₂)
≡⟨ ⋆distl+ _ _ _ ⟩
(π₁ ⋆ f₁ + π₂ ⋆ f₂) ⋆ (g₁ ⋆ i₁) + (π₁ ⋆ f₁ + π₂ ⋆ f₂) ⋆ (g₂ ⋆ i₂)
≡⟨ cong₂ _+_ (eq g₁ i₁) (eq g₂ i₂) ⟩
(π₁ ⋆ (f₁ ⋆ g₁) + π₂ ⋆ (f₂ ⋆ g₁)) ⋆ i₁
+ (π₁ ⋆ (f₁ ⋆ g₂) + π₂ ⋆ (f₂ ⋆ g₂)) ⋆ i₂
∎
where
eq = λ {z w} (g : Hom[ y , z ]) (i : Hom[ z , w ]) →
(π₁ ⋆ f₁ + π₂ ⋆ f₂) ⋆ (g ⋆ i)
≡⟨ ⋆distr+ _ _ _ ⟩
(π₁ ⋆ f₁) ⋆ (g ⋆ i) + (π₂ ⋆ f₂) ⋆ (g ⋆ i)
≡⟨ cong₂ _+_ (⋆4assoc' _ _ _ _) (⋆4assoc' _ _ _ _) ⟩
(π₁ ⋆ (f₁ ⋆ g)) ⋆ i + (π₂ ⋆ (f₂ ⋆ g)) ⋆ i
≡⟨ sym (⋆distr+ _ _ _) ⟩
(π₁ ⋆ (f₁ ⋆ g) + π₂ ⋆ (f₂ ⋆ g)) ⋆ i
∎
| {
"alphanum_fraction": 0.3311576262,
"avg_line_length": 38.5231213873,
"ext": "agda",
"hexsha": "fa21bfbd87878c048c7c4f486894165b53481058",
"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/Categories/Additive/Properties.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/Categories/Additive/Properties.agda",
"max_line_length": 85,
"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/Categories/Additive/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6998,
"size": 13329
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.RingSolver.AlmostRing where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Sigma
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Algebra.Semigroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.AbGroup
private
variable
ℓ : Level
record IsAlmostRing {R : Type ℓ}
(0r 1r : R) (_+_ _·_ : R → R → R) (-_ : R → R) : Type ℓ where
constructor isalmostring
field
+IsMonoid : IsMonoid 0r _+_
·IsMonoid : IsMonoid 1r _·_
+Comm : (x y : R) → x + y ≡ y + x
·Comm : (x y : R) → x · y ≡ y · x
·DistR+ : (x y z : R) → x · (y + z) ≡ (x · y) + (x · z)
·DistL+ : (x y z : R) → (x + y) · z ≡ (x · z) + (y · z)
-Comm· : (x y : R) → - (x · y) ≡ (- x) · y
-Dist+ : (x y : R) → - (x + y) ≡ (- x) + (- y)
0LeftAnnihilates : (x : R) → 0r · x ≡ 0r
0RightAnnihilates : (x : R) → x · 0r ≡ 0r
open IsMonoid +IsMonoid public
renaming
( assoc to +Assoc
; identity to +Identity
; lid to +Lid
; rid to +Rid
; isSemigroup to +IsSemigroup)
open IsMonoid ·IsMonoid public
renaming
( assoc to ·Assoc
; identity to ·Identity
; lid to ·Lid
; rid to ·Rid
; isSemigroup to ·IsSemigroup )
hiding
( is-set ) -- We only want to export one proof of this
record AlmostRing : Type (ℓ-suc ℓ) where
constructor almostring
field
Carrier : Type ℓ
0r : Carrier
1r : Carrier
_+_ : Carrier → Carrier → Carrier
_·_ : Carrier → Carrier → Carrier
-_ : Carrier → Carrier
isAlmostRing : IsAlmostRing 0r 1r _+_ _·_ -_
infixl 9 _^_
infixl 8 _·_
infixl 7 -_
infixl 6 _+_
infixl 6 _-_
open IsAlmostRing isAlmostRing public
_^_ : Carrier → ℕ → Carrier
x ^ 0 = 1r
x ^ ℕ.suc k = x · (x ^ k)
_-_ : Carrier → Carrier → Carrier
x - y = x + (- y)
-- Extractor for the carrier type
⟨_⟩ : AlmostRing → Type ℓ
⟨_⟩ = AlmostRing.Carrier
isSetAlmostRing : (R : AlmostRing {ℓ}) → isSet ⟨ R ⟩
isSetAlmostRing R = R .AlmostRing.isAlmostRing .IsAlmostRing.·IsMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set
module Theory (R : AlmostRing {ℓ}) where
open AlmostRing R
0IsSelfinverse : - 0r ≡ 0r
0IsSelfinverse = - 0r ≡⟨ cong -_ (sym (·Lid 0r)) ⟩
- (1r · 0r) ≡⟨ -Comm· 1r 0r ⟩
(- 1r) · 0r ≡⟨ 0RightAnnihilates (- 1r) ⟩
0r ∎
·CommRight : (x y z : ⟨ R ⟩)
→ x · y · z ≡ x · z · y
·CommRight x y z = x · y · z ≡⟨ sym (·Assoc _ _ _) ⟩
x · (y · z) ≡⟨ cong (λ u → x · u) (·Comm _ _) ⟩
x · (z · y) ≡⟨ ·Assoc _ _ _ ⟩
x · z · y ∎
+ShufflePairs : (a b c d : ⟨ R ⟩)
→ (a + b) + (c + d) ≡ (a + c) + (b + d)
+ShufflePairs a b c d =
(a + b) + (c + d) ≡⟨ +Assoc _ _ _ ⟩
((a + b) + c) + d ≡⟨ cong (λ u → u + d) (sym (+Assoc _ _ _)) ⟩
(a + (b + c)) + d ≡⟨ cong (λ u → (a + u) + d) (+Comm _ _) ⟩
(a + (c + b)) + d ≡⟨ cong (λ u → u + d) (+Assoc _ _ _) ⟩
((a + c) + b) + d ≡⟨ sym (+Assoc _ _ _) ⟩
(a + c) + (b + d) ∎
| {
"alphanum_fraction": 0.4979932078,
"avg_line_length": 28.9196428571,
"ext": "agda",
"hexsha": "de8a190be621d456523d609c3834d174057436fc",
"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": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Algebra/RingSolver/AlmostRing.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"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": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Algebra/RingSolver/AlmostRing.agda",
"max_line_length": 112,
"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/Algebra/RingSolver/AlmostRing.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1291,
"size": 3239
} |
-- Andreas, 2017-10-11, issue #2769
-- Patch https://github.com/agda/agda/commit/7fc73607703e0373beaf65ba05fb1911b6d84a5e
--
-- Re #2495: make mutual info safer by distinguishing Nothing and Just []
--
-- Nothing means: never computed.
-- Just [] means: computed, but non-recursive.
--
-- These two notions were conflated before.
--
-- introduced this regression because the projection-likeness check failed.
-- {-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v 10 #-}
-- {-# OPTIONS -v tc.signature:60 #-}
-- {-# OPTIONS -v tc.mod.apply:80 #-}
-- {-# OPTIONS -v tc.sig.param:90 #-}
-- {-# OPTIONS -v tc.display:100 #-}
module Issue2769 where
module M (_X : Set₁)
where
record R (_Y : Set₂) : Set₁ where
field A : Set
record S : Set₁ where
field r : R Set₁
module Rr = R r
ok : (s : M.S Set) → M.R.A (M.S.r s) -- M.S.Rr.A s
ok = {!!} -- goal displayed as (s : M.S Set) → M.R.A (M.S.r s)
module MSet = M Set
goal : (s : M.S Set) → M.R.A (M.S.r s) -- M.S.Rr.A s
goal = {!!} -- WAS: goal displayed as (s : MSet.S) → MSet.S.Rr.A
-- adding display form Issue2769.M.R.A --> Issue2769.MSet.S.Rr.A
-- Display {dfFreeVars = 1, dfPats = [Apply ru(Def Issue2769.M.S.r [Apply ru(Var 0 [])])], dfRHS = DTerm (Def Issue2769.MSet.S.Rr.A [])}
-- EXPECTED:
-- Should display goal 1 as
-- ?1 : (s : MSet.S) → M.R.A (MSet.S.r s)
| {
"alphanum_fraction": 0.6094674556,
"avg_line_length": 28.1666666667,
"ext": "agda",
"hexsha": "65045ba2ea9116bbc72a40be406f2ab01c39b65f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.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/interaction/Issue2769.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue2769.agda",
"max_line_length": 136,
"max_stars_count": 2,
"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/Issue2769.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 468,
"size": 1352
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Pi
open import lib.types.Pointed
open import lib.types.Sigma
open import lib.types.Span
open import lib.types.Paths
import lib.types.Generic1HIT as Generic1HIT
module lib.types.Pushout {i j k} where
module _ where
private
data #Pushout-aux (d : Span {i} {j} {k}) : Type (lmax (lmax i j) k) where
#left : Span.A d → #Pushout-aux d
#right : Span.B d → #Pushout-aux d
data #Pushout (d : Span) : Type (lmax (lmax i j) k) where
#pushout : #Pushout-aux d → (Unit → Unit) → #Pushout d
Pushout : (d : Span) → Type _
Pushout d = #Pushout d
left : {d : Span} → Span.A d → Pushout d
left a = #pushout (#left a) _
right : {d : Span} → Span.B d → Pushout d
right b = #pushout (#right b) _
postulate -- HIT
glue : {d : Span} → (c : Span.C d) → left (Span.f d c) == right (Span.g d c) :> Pushout d
module PushoutElim {d : Span} {l} {P : Pushout d → Type l}
(left* : (a : Span.A d) → P (left a))
(right* : (b : Span.B d) → P (right b))
(glue* : (c : Span.C d) → left* (Span.f d c) == right* (Span.g d c) [ P ↓ glue c ]) where
f : Π (Pushout d) P
f = f-aux phantom where
f-aux : Phantom glue* → Π (Pushout d) P
f-aux phantom (#pushout (#left y) _) = left* y
f-aux phantom (#pushout (#right y) _) = right* y
postulate -- HIT
glue-β : (c : Span.C d) → apd f (glue c) == glue* c
open PushoutElim public using () renaming (f to Pushout-elim)
module PushoutRec {d : Span} {l} {D : Type l}
(left* : Span.A d → D) (right* : Span.B d → D)
(glue* : (c : Span.C d) → left* (Span.f d c) == right* (Span.g d c)) where
private
module M = PushoutElim left* right* (λ c → ↓-cst-in (glue* c))
f : Pushout d → D
f = M.f
glue-β : (c : Span.C d) → ap f (glue c) == glue* c
glue-β c = apd=cst-in {f = f} (M.glue-β c)
module PushoutGeneric {d : Span {i} {j} {k}} where
open Span d renaming (f to g; g to h)
open Generic1HIT (Coprod A B) C (inl ∘ g) (inr ∘ h) public
module _ where
module To = PushoutRec (cc ∘ inl) (cc ∘ inr) pp
to : Pushout d → T
to = To.f
from-cc : Coprod A B → Pushout d
from-cc (inl a) = left a
from-cc (inr b) = right b
module From = Rec from-cc glue
from : T → Pushout d
from = From.f
abstract
to-from : (x : T) → to (from x) == x
to-from = elim to-from-cc to-from-pp where
to-from-cc : (x : Coprod A B)
→ to (from (cc x)) == cc x
to-from-cc (inl a) = idp
to-from-cc (inr b) = idp
to-from-pp :
(c : C) → idp == idp [ (λ z → to (from z) == z) ↓ pp c ]
to-from-pp c = ↓-∘=idf-in to from
(ap to (ap from (pp c)) =⟨ From.pp-β c |in-ctx ap to ⟩
ap to (glue c) =⟨ To.glue-β c ⟩
pp c ∎)
from-to : (x : Pushout d) → from (to x) == x
from-to = Pushout-elim (λ a → idp) (λ b → idp) (λ c → ↓-∘=idf-in from to
(ap from (ap to (glue c)) =⟨ To.glue-β c |in-ctx ap from ⟩
ap from (pp c) =⟨ From.pp-β c ⟩
glue c ∎))
generic-pushout : Pushout d ≃ T
generic-pushout = equiv to from to-from from-to
_⊔^[_]_/_ : (A : Type i) (C : Type k) (B : Type j)
(fg : (C → A) × (C → B)) → Type (lmax (lmax i j) k)
A ⊔^[ C ] B / (f , g) = Pushout (span A B C f g)
⊙Pushout : (d : ⊙Span {i} {j} {k}) → Ptd _
⊙Pushout d = ⊙[ Pushout (⊙span-out d) , left (snd (⊙Span.X d)) ]
module _ (d : ⊙Span {i} {j} {k}) where
open ⊙Span d
⊙left : fst (X ⊙→ ⊙Pushout d)
⊙left = (left , idp)
⊙right : fst (Y ⊙→ ⊙Pushout d)
⊙right =
(right , ap right (! (snd g)) ∙ ! (glue (snd Z)) ∙' ap left (snd f))
⊙glue : (⊙left ⊙∘ f) == (⊙right ⊙∘ g)
⊙glue = pair=
(λ= glue)
(↓-app=cst-in $
ap left (snd f) ∙ idp
=⟨ ∙-unit-r _ ⟩
ap left (snd f)
=⟨ lemma (glue (snd Z)) (ap right (snd g)) (ap left (snd f)) ⟩
glue (snd Z) ∙ ap right (snd g)
∙ ! (ap right (snd g)) ∙ ! (glue (snd Z)) ∙' ap left (snd f)
=⟨ !-ap right (snd g)
|in-ctx (λ w → glue (snd Z) ∙ ap right (snd g) ∙ w
∙ ! (glue (snd Z)) ∙' ap left (snd f)) ⟩
glue (snd Z) ∙ ap right (snd g)
∙ ap right (! (snd g)) ∙ ! (glue (snd Z)) ∙' ap left (snd f)
=⟨ ! (app=-β glue (snd Z))
|in-ctx (λ w → w ∙ ap right (snd g) ∙ ap right (! (snd g))
∙ ! (glue (snd Z)) ∙' ap left (snd f)) ⟩
app= (λ= glue) (snd Z) ∙ ap right (snd g)
∙ ap right (! (snd g)) ∙ ! (glue (snd Z)) ∙' ap left (snd f) ∎)
where
lemma : ∀ {i} {A : Type i} {x y z w : A}
(p : x == y) (q : y == z) (r : x == w)
→ r == p ∙ q ∙ ! q ∙ ! p ∙' r
lemma idp idp idp = idp
⊙pushout-J : ∀ {l} (P : ⊙Span → Type l)
→ ({A : Type i} {B : Type j} (Z : Ptd k) (f : fst Z → A) (g : fst Z → B)
→ P (⊙span (A , f (snd Z)) (B , g (snd Z)) Z (f , idp) (g , idp)))
→ ((ps : ⊙Span) → P ps)
⊙pushout-J P t (⊙span (_ , ._) (_ , ._) Z (f , idp) (g , idp)) = t Z f g
| {
"alphanum_fraction": 0.4921766686,
"avg_line_length": 31.1666666667,
"ext": "agda",
"hexsha": "e3e12e699d548033e376bd54d69537a54ce3e88e",
"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": "lib/types/Pushout.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": "lib/types/Pushout.agda",
"max_line_length": 93,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "lib/types/Pushout.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": 2058,
"size": 5049
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Sum.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Functions.Embedding
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Empty
open import Cubical.Data.Nat
open import Cubical.Data.Sum.Base
open Iso
private
variable
ℓa ℓb ℓc ℓd : Level
A : Type ℓa
B : Type ℓb
C : Type ℓc
D : Type ℓd
-- Path space of sum type
module ⊎Path {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} where
Cover : A ⊎ B → A ⊎ B → Type (ℓ-max ℓ ℓ')
Cover (inl a) (inl a') = Lift {j = ℓ-max ℓ ℓ'} (a ≡ a')
Cover (inl _) (inr _) = Lift ⊥
Cover (inr _) (inl _) = Lift ⊥
Cover (inr b) (inr b') = Lift {j = ℓ-max ℓ ℓ'} (b ≡ b')
reflCode : (c : A ⊎ B) → Cover c c
reflCode (inl a) = lift refl
reflCode (inr b) = lift refl
encode : ∀ c c' → c ≡ c' → Cover c c'
encode c _ = J (λ c' _ → Cover c c') (reflCode c)
encodeRefl : ∀ c → encode c c refl ≡ reflCode c
encodeRefl c = JRefl (λ c' _ → Cover c c') (reflCode c)
decode : ∀ c c' → Cover c c' → c ≡ c'
decode (inl a) (inl a') (lift p) = cong inl p
decode (inl a) (inr b') ()
decode (inr b) (inl a') ()
decode (inr b) (inr b') (lift q) = cong inr q
decodeRefl : ∀ c → decode c c (reflCode c) ≡ refl
decodeRefl (inl a) = refl
decodeRefl (inr b) = refl
decodeEncode : ∀ c c' → (p : c ≡ c') → decode c c' (encode c c' p) ≡ p
decodeEncode c _ =
J (λ c' p → decode c c' (encode c c' p) ≡ p)
(cong (decode c c) (encodeRefl c) ∙ decodeRefl c)
encodeDecode : ∀ c c' → (d : Cover c c') → encode c c' (decode c c' d) ≡ d
encodeDecode (inl a) (inl _) (lift d) =
J (λ a' p → encode (inl a) (inl a') (cong inl p) ≡ lift p) (encodeRefl (inl a)) d
encodeDecode (inr a) (inr _) (lift d) =
J (λ a' p → encode (inr a) (inr a') (cong inr p) ≡ lift p) (encodeRefl (inr a)) d
Cover≃Path : ∀ c c' → Cover c c' ≃ (c ≡ c')
Cover≃Path c c' =
isoToEquiv (iso (decode c c') (encode c c') (decodeEncode c c') (encodeDecode c c'))
isOfHLevelCover : (n : HLevel)
→ isOfHLevel (suc (suc n)) A
→ isOfHLevel (suc (suc n)) B
→ ∀ c c' → isOfHLevel (suc n) (Cover c c')
isOfHLevelCover n p q (inl a) (inl a') = isOfHLevelLift (suc n) (p a a')
isOfHLevelCover n p q (inl a) (inr b') =
isOfHLevelLift (suc n) (isProp→isOfHLevelSuc n isProp⊥)
isOfHLevelCover n p q (inr b) (inl a') =
isOfHLevelLift (suc n) (isProp→isOfHLevelSuc n isProp⊥)
isOfHLevelCover n p q (inr b) (inr b') = isOfHLevelLift (suc n) (q b b')
isEmbedding-inl : isEmbedding (inl {A = A} {B = B})
isEmbedding-inl w z = snd (compEquiv LiftEquiv (⊎Path.Cover≃Path (inl w) (inl z)))
isEmbedding-inr : isEmbedding (inr {A = A} {B = B})
isEmbedding-inr w z = snd (compEquiv LiftEquiv (⊎Path.Cover≃Path (inr w) (inr z)))
isOfHLevel⊎ : (n : HLevel)
→ isOfHLevel (suc (suc n)) A
→ isOfHLevel (suc (suc n)) B
→ isOfHLevel (suc (suc n)) (A ⊎ B)
isOfHLevel⊎ n lA lB c c' =
isOfHLevelRetract (suc n)
(⊎Path.encode c c')
(⊎Path.decode c c')
(⊎Path.decodeEncode c c')
(⊎Path.isOfHLevelCover n lA lB c c')
isSet⊎ : isSet A → isSet B → isSet (A ⊎ B)
isSet⊎ = isOfHLevel⊎ 0
isGroupoid⊎ : isGroupoid A → isGroupoid B → isGroupoid (A ⊎ B)
isGroupoid⊎ = isOfHLevel⊎ 1
is2Groupoid⊎ : is2Groupoid A → is2Groupoid B → is2Groupoid (A ⊎ B)
is2Groupoid⊎ = isOfHLevel⊎ 2
⊎Iso : Iso A C → Iso B D → Iso (A ⊎ B) (C ⊎ D)
fun (⊎Iso iac ibd) (inl x) = inl (iac .fun x)
fun (⊎Iso iac ibd) (inr x) = inr (ibd .fun x)
inv (⊎Iso iac ibd) (inl x) = inl (iac .inv x)
inv (⊎Iso iac ibd) (inr x) = inr (ibd .inv x)
rightInv (⊎Iso iac ibd) (inl x) = cong inl (iac .rightInv x)
rightInv (⊎Iso iac ibd) (inr x) = cong inr (ibd .rightInv x)
leftInv (⊎Iso iac ibd) (inl x) = cong inl (iac .leftInv x)
leftInv (⊎Iso iac ibd) (inr x) = cong inr (ibd .leftInv x)
⊎-swap-Iso : Iso (A ⊎ B) (B ⊎ A)
fun ⊎-swap-Iso (inl x) = inr x
fun ⊎-swap-Iso (inr x) = inl x
inv ⊎-swap-Iso (inl x) = inr x
inv ⊎-swap-Iso (inr x) = inl x
rightInv ⊎-swap-Iso (inl _) = refl
rightInv ⊎-swap-Iso (inr _) = refl
leftInv ⊎-swap-Iso (inl _) = refl
leftInv ⊎-swap-Iso (inr _) = refl
⊎-swap-≃ : A ⊎ B ≃ B ⊎ A
⊎-swap-≃ = isoToEquiv ⊎-swap-Iso
⊎-assoc-Iso : Iso ((A ⊎ B) ⊎ C) (A ⊎ (B ⊎ C))
fun ⊎-assoc-Iso (inl (inl x)) = inl x
fun ⊎-assoc-Iso (inl (inr x)) = inr (inl x)
fun ⊎-assoc-Iso (inr x) = inr (inr x)
inv ⊎-assoc-Iso (inl x) = inl (inl x)
inv ⊎-assoc-Iso (inr (inl x)) = inl (inr x)
inv ⊎-assoc-Iso (inr (inr x)) = inr x
rightInv ⊎-assoc-Iso (inl _) = refl
rightInv ⊎-assoc-Iso (inr (inl _)) = refl
rightInv ⊎-assoc-Iso (inr (inr _)) = refl
leftInv ⊎-assoc-Iso (inl (inl _)) = refl
leftInv ⊎-assoc-Iso (inl (inr _)) = refl
leftInv ⊎-assoc-Iso (inr _) = refl
⊎-assoc-≃ : (A ⊎ B) ⊎ C ≃ A ⊎ (B ⊎ C)
⊎-assoc-≃ = isoToEquiv ⊎-assoc-Iso
⊎-⊥-Iso : Iso (A ⊎ ⊥) A
fun ⊎-⊥-Iso (inl x) = x
inv ⊎-⊥-Iso x = inl x
rightInv ⊎-⊥-Iso x = refl
leftInv ⊎-⊥-Iso (inl x) = refl
⊎-⊥-≃ : A ⊎ ⊥ ≃ A
⊎-⊥-≃ = isoToEquiv ⊎-⊥-Iso
| {
"alphanum_fraction": 0.5921515033,
"avg_line_length": 32.8333333333,
"ext": "agda",
"hexsha": "ee87b7d7dcf2a7152d7f1ae56d96b7166382e4a6",
"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": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/Data/Sum/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"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": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/Data/Sum/Properties.agda",
"max_line_length": 88,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/Data/Sum/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2365,
"size": 5122
} |
module Data.Word32 where
open import Data.Bool
open import Data.Char
{-#
FOREIGN GHC
import Data.Bits
import Data.Word
data Byte = Byte Bool Bool Bool Bool Bool Bool Bool Bool
data Bytes = Bytes Byte Byte Byte Byte
byteToWord8 :: Byte -> Word8
byteToWord8 (Byte b0 b1 b2 b3 b4 b5 b6 b7) =
boolToBit b0 0 + boolToBit b1 1 + boolToBit b2 2 + boolToBit b3 3 +
boolToBit b4 4 + boolToBit b5 5 + boolToBit b6 6 + boolToBit b7 7
where
boolToBit b i = if b then bit i else 0
word8ToByte :: Word8 -> Byte
word8ToByte w =
Byte
(testBit w 0) (testBit w 1) (testBit w 2) (testBit w 3)
(testBit w 4) (testBit w 5) (testBit w 6) (testBit w 7)
bytesToWord32 :: Bytes -> Word32
bytesToWord32 (Bytes b0 b1 b2 b3) =
byteToWordShifted b0 0 + byteToWordShifted b1 1 + byteToWordShifted b2 2 + byteToWordShifted b3 3
where
byteToWordShifted :: Byte -> Int -> Word32
byteToWordShifted b i = shift (fromIntegral $ byteToWord8 b) (i * 8)
word32ToBytes :: Word32 -> Bytes
word32ToBytes w = Bytes (getByte w 0) (getByte w 1) (getByte w 2) (getByte w 3)
where
getByte :: Word32 -> Int -> Byte
getByte w i = word8ToByte $ fromIntegral (shift w (-i * 8))
bytesToChar :: Bytes -> Char
bytesToChar = toEnum . fromIntegral . bytesToWord32
charToBytes :: Char -> Bytes
charToBytes = word32ToBytes . fromIntegral . fromEnum
#-}
data Byte : Set where
mkByte : Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> Byte
data Word32 : Set where
mkWord32 : Byte -> Byte -> Byte -> Byte -> Word32
{-# COMPILE GHC Byte = data Byte (Byte) #-}
{-# COMPILE GHC Word32 = data Bytes (Bytes) #-}
postulate
bytesToChar : Word32 -> Char
charToBytes : Char -> Word32
{-# COMPILE GHC bytesToChar = bytesToChar #-}
{-# COMPILE GHC charToBytes = charToBytes #-}
word32ToChar : Word32 -> Char
word32ToChar = bytesToChar
charToWord32 : Char -> Word32
charToWord32 = charToBytes
| {
"alphanum_fraction": 0.66598778,
"avg_line_length": 28.4637681159,
"ext": "agda",
"hexsha": "4212ddbe2aff7659c933a97cc7f91f6f47d53988",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-10-20T10:46:20.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-27T23:12:48.000Z",
"max_forks_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "WhatisRT/meta-cedille",
"max_forks_repo_path": "stdlib-exts/Data/Word32.agda",
"max_issues_count": 10,
"max_issues_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_issues_repo_issues_event_max_datetime": "2020-04-25T15:29:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-13T17:44:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "WhatisRT/meta-cedille",
"max_issues_repo_path": "stdlib-exts/Data/Word32.agda",
"max_line_length": 101,
"max_stars_count": 35,
"max_stars_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "WhatisRT/meta-cedille",
"max_stars_repo_path": "stdlib-exts/Data/Word32.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-12T22:59:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-13T07:44:50.000Z",
"num_tokens": 666,
"size": 1964
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Natural numbers defined in terms of Data.Star
------------------------------------------------------------------------
module Data.Star.Nat where
open import Data.Star
open import Data.Unit
open import Function
open import Relation.Binary
open import Relation.Binary.Simple
-- Natural numbers.
ℕ : Set
ℕ = Star Always tt tt
-- Zero and successor.
zero : ℕ
zero = ε
suc : ℕ → ℕ
suc = _◅_ _
-- The length of a star-list.
length : ∀ {i t} {I : Set i} {T : Rel I t} {i j} → Star T i j → ℕ
length = gmap (const _) (const _)
-- Arithmetic.
infixl 7 _*_
infixl 6 _+_ _∸_
_+_ : ℕ → ℕ → ℕ
_+_ = _◅◅_
_*_ : ℕ → ℕ → ℕ
_*_ m = const m ⋆
_∸_ : ℕ → ℕ → ℕ
m ∸ ε = m
ε ∸ (_ ◅ n) = zero
(_ ◅ m) ∸ (_ ◅ n) = m ∸ n
-- Some constants.
0# = zero
1# = suc 0#
2# = suc 1#
3# = suc 2#
4# = suc 3#
5# = suc 4#
| {
"alphanum_fraction": 0.4832793959,
"avg_line_length": 16.2631578947,
"ext": "agda",
"hexsha": "a54a46517f45ced9a77944675dc4b650a226128b",
"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": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/Star/Nat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/Star/Nat.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/Star/Nat.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 306,
"size": 927
} |
module Issue1496 where
open import Common.Unit
open import Common.String
open import Common.Char
open import Common.List
open import Common.IO
-- Agda infers that the "a" level argument to return has to be
-- Agda.Primitive.lzero.
main : IO Unit
main = return unit
| {
"alphanum_fraction": 0.7790262172,
"avg_line_length": 20.5384615385,
"ext": "agda",
"hexsha": "7e3abd78698bb54f415600ddeb5de3bb0a84f803",
"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/Compiler/simple/Issue1496.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/Compiler/simple/Issue1496.agda",
"max_line_length": 62,
"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/Compiler/simple/Issue1496.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": 67,
"size": 267
} |
--
-- In this module we conclude our proof: we have shown that t, derive-dterm t
-- and produce related values (in the sense of the fundamental property,
-- rfundamental3), and for related values v1, dv and v2 we have v1 ⊕ dv ≡
-- v2 (because ⊕ agrees with validity, rrelV3→⊕).
--
-- We now put these facts together via derive-correct-si and derive-correct.
-- This is immediate, even though I spend so much code on it:
-- Indeed, all theorems are immediate corollaries of what we established (as
-- explained above); only the statements are longer, especially because I bother
-- expanding them.
module Thesis.SIRelBigStep.DeriveCorrect where
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Thesis.SIRelBigStep.IlcSILR
open import Thesis.SIRelBigStep.FundamentalProperty
-- Theorem statement. This theorem still mentions step-indexes explicitly.
derive-correct-si-type =
∀ {τ Γ k} (t : Term Γ τ) ρ1 dρ ρ2 → (ρρ : rrelρ3 Γ ρ1 dρ ρ2 k) →
rrelT3-skeleton (λ v1 dv v2 _ → v1 ⊕ dv ≡ v2) t (derive-dterm t) t ρ1 dρ ρ2 k
-- A verified expansion of the theorem statement.
derive-correct-si-type-means :
derive-correct-si-type ≡
∀ {τ Γ k} (t : Term Γ τ)
ρ1 dρ ρ2 (ρρ : rrelρ3 Γ ρ1 dρ ρ2 k) →
(v1 v2 : Val τ) →
∀ j (j<k : j < k) →
(ρ1⊢t1↓[j]v1 : ρ1 ⊢ t ↓[ i' j ] v1) →
(ρ2⊢t2↓[n2]v2 : ρ2 ⊢ t ↓[ no ] v2) →
Σ[ dv ∈ DVal τ ]
ρ1 D dρ ⊢ derive-dterm t ↓ dv ×
v1 ⊕ dv ≡ v2
derive-correct-si-type-means = refl
derive-correct-si : derive-correct-si-type
derive-correct-si t ρ1 dρ ρ2 ρρ = rrelT3→⊕ t (derive-dterm t) t ρ1 dρ ρ2 (rfundamental3 _ t ρ1 dρ ρ2 ρρ)
-- Infinitely related environments:
rrelρ3-inf : ∀ Γ (ρ1 : ⟦ Γ ⟧Context) (dρ : ChΔ Γ) (ρ2 : ⟦ Γ ⟧Context) → Set
rrelρ3-inf Γ ρ1 dρ ρ2 = ∀ k → rrelρ3 Γ ρ1 dρ ρ2 k
-- A theorem statement for infinitely-related environments. On paper, if we informally
-- omit the arbitrary derivation step-index as usual, we get a statement without
-- step-indexes.
derive-correct :
∀ {τ Γ} (t : Term Γ τ)
ρ1 dρ ρ2 (ρρ : rrelρ3-inf Γ ρ1 dρ ρ2) →
(v1 v2 : Val τ) →
∀ j →
(ρ1⊢t1↓[j]v1 : ρ1 ⊢ t ↓[ i' j ] v1) →
(ρ2⊢t2↓[n2]v2 : ρ2 ⊢ t ↓[ no ] v2) →
Σ[ dv ∈ DVal τ ]
ρ1 D dρ ⊢ derive-dterm t ↓ dv ×
v1 ⊕ dv ≡ v2
derive-correct t ρ1 dρ ρ2 ρρ v1 v2 j = derive-correct-si t ρ1 dρ ρ2 (ρρ (suc j)) v1 v2 j ≤-refl
open import Data.Unit
nilρ : ∀ {Γ n} (ρ : ⟦ Γ ⟧Context) → Σ[ dρ ∈ ChΔ Γ ] rrelρ3 Γ ρ dρ ρ n
nilV : ∀ {τ n} (v : Val τ) → Σ[ dv ∈ DVal τ ] rrelV3 τ v dv v n
nilV (closure t ρ) = let dρ , ρρ = nilρ ρ in dclosure (derive-dterm t) ρ dρ , rfundamental3svv _ (abs t) ρ dρ ρ ρρ
nilV (natV n₁) = dnatV zero , refl
nilV (pairV a b) = let 0a , aa = nilV a; 0b , bb = nilV b in dpairV 0a 0b , aa , bb
nilρ ∅ = ∅ , tt
nilρ (v • ρ) = let dv , vv = nilV v ; dρ , ρρ = nilρ ρ in dv • dρ , vv , ρρ
-- -- Try to prove to define validity-preserving change composition.
-- -- If we don't store proofs that environment changes in closures are valid, we
-- -- can't finish the proof for the closure case using the Fundamental property.
-- -- But it seems that's not the approach we need to use: we might need
-- -- environment validity elsewhere.
-- -- Moreover, the proof is annoying to do unless we build a datatype to invert
-- -- validity proofs (as suggested by Ezyang in
-- -- http://blog.ezyang.com/2013/09/induction-and-logical-relations/).
-- ocomposeρ : ∀ {Γ} n ρ1 dρ1 ρ2 dρ2 ρ3 → rrelρ3 Γ ρ1 dρ1 ρ2 n → rrelρ3 Γ ρ2 dρ2 ρ3 n → Σ[ dρ ∈ ChΔ Γ ] rrelρ3 Γ ρ1 dρ ρ3 n
-- ocomposev : ∀ {τ} n v1 dv1 v2 dv2 v3 → rrelV3 τ v1 dv1 v2 n → rrelV3 τ v2 dv2 v3 n → Σ[ dv ∈ DVal τ ] rrelV3 τ v1 dv v3 n
-- ocomposev n v1 dv1 v2 (bang v3) .v3 vv1 refl = bang v3 , refl
-- ocomposev n v1 (bang x) v2 (dclosure dt ρ dρ) v3 vv1 vv2 = {!!}
-- ocomposev n (closure t ρ) (dclosure .(derive-dterm t) .ρ dρ1) (closure .t .(ρ ⊕ρ dρ1)) (dclosure .(derive-dterm t) .(ρ ⊕ρ dρ1) dρ2) (closure .t .((ρ ⊕ρ dρ1) ⊕ρ dρ2)) ((refl , refl) , refl , refl , refl , refl , vv1) ((refl , refl) , refl , refl , refl , refl , vv2) =
-- let dρ , ρρ = ocomposeρ n ρ dρ1 (ρ ⊕ρ dρ1) dρ2 ((ρ ⊕ρ dρ1) ⊕ρ dρ2) {!!} {!!}
-- in dclosure (derive-dterm t) ρ dρ , (refl , refl) , refl , {!!} , refl , refl ,
-- λ { k (s≤s k≤n) v1 dv v2 vv →
-- let nilv2 , nilv2v = nilV v2
-- -- vv1 k ? v1 dv v2 vv
-- -- vv2 k ? v2 nilv2 v2 nilv2v
-- in {!!}
-- }
-- -- rfundamental3 k t (v1 • ρ) (dv • dρ) (v2 • ((ρ ⊕ρ dρ1) ⊕ρ dρ2)) (vv , rrelρ3-mono k n (≤-step k<n) _ ρ dρ ((ρ ⊕ρ dρ1) ⊕ρ dρ2) ρρ)}
-- -- p1 , p2 , p3 , p4 , p5
-- ocomposev n v1 dv1 v2 (dnatV n₁) v3 vv1 vv2 = {!!}
-- ocomposev n v1 dv1 v2 (dpairV dv2 dv3) v3 vv1 vv2 = {!!}
-- -- ocomposev n v1 (bang v2) .v2 dv2 v3 refl vv2 = bang (v2 ⊕ dv2) , rrelV3→⊕ v2 dv2 v3 vv2
-- -- ocomposev n v1 (dclosure dt ρ dρ) v2 dv2 v3 vv1 vv2 = {!!}
-- -- ocomposev n v1 (dnatV n₁) v2 dv2 v3 vv1 vv2 = {!!}
-- -- ocomposev n v1 (dpairV dv1 dv2) v2 dv3 v3 vv1 vv2 = {!!}
-- -- ocomposeV : ∀ {τ n} (v : Val τ) → Σ[ dv ∈ DVal τ ] rrelV3 τ v dv v n
-- ocomposeρ {∅} n ∅ dρ1 ρ2 dρ2 ∅ ρρ1 ρρ2 = ∅ , tt
-- ocomposeρ {τ • Γ} n (v1 • ρ1) (dv1 • dρ1) (v2 • ρ2) (dv2 • dρ2) (v3 • ρ3) (vv1 , ρρ1) (vv2 , ρρ2) =
-- let dv , vv = ocomposev n v1 dv1 v2 dv2 v3 vv1 vv2
-- dρ , ρρ = ocomposeρ n ρ1 dρ1 ρ2 dρ2 ρ3 ρρ1 ρρ2
-- in dv • dρ , vv , ρρ
-- -- But we sort of know how to store environments validity proofs in closures, you just need to use well-founded inductions, even if you're using types. Sad, yes, that's insanely tedious. Let's leave that to Coq.
-- -- What is also interesting: if that were fixed, could we prove correct
-- -- composition for change *terms* and rrelT3? And for *open expressions*? The
-- -- last is the main problem Ahmed run into.
-- 1: the proof of transitivity of rrelT by Ahmed is for the case where the second rrelT holds at arbitrary step counts :-)
-- 2: that proof doesn't go through for us. If de1 : e1 -> e2 and de2 : e2 ->
-- e3, we must show that if e1 and e3 evaluate something happens, but to use our
-- hypothesis we need that e2 also terminates, which in our case does not
-- follow. For Ahmed 2006, instead, e1 terminates and e1 ≤ e2 implies that e2
-- terminates.
--
-- Indeed, it seems that we can have a change from e1 to looping e2 and a change
-- from looping e2 to e3, and I don't expect the composition of such changes to
-- satisfy anything.
--
-- Indeed, "Imperative self-adjusting computation" does not mention any
-- transitivity result (even in the technical report).
| {
"alphanum_fraction": 0.637264005,
"avg_line_length": 49.7076923077,
"ext": "agda",
"hexsha": "ed3fa5bb854fe23d624d6a2d6e6501fea10bb9ee",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Thesis/SIRelBigStep/DeriveCorrect.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Thesis/SIRelBigStep/DeriveCorrect.agda",
"max_line_length": 270,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Thesis/SIRelBigStep/DeriveCorrect.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 2643,
"size": 6462
} |
{-# OPTIONS --safe #-}
module Cubical.HITs.SetCoequalizer where
open import Cubical.HITs.SetCoequalizer.Base public
open import Cubical.HITs.SetCoequalizer.Properties public
| {
"alphanum_fraction": 0.8125,
"avg_line_length": 29.3333333333,
"ext": "agda",
"hexsha": "b6ddc6459050c4e0bc523cea7b1a0cbb4fe96671",
"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/SetCoequalizer.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/SetCoequalizer.agda",
"max_line_length": 57,
"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/HITs/SetCoequalizer.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 49,
"size": 176
} |
module datatype-util where
open import constants
open import ctxt
open import syntax-util
open import general-util
open import type-util
open import cedille-types
open import subst
open import rename
open import free-vars
{-# TERMINATING #-}
decompose-arrows : ctxt → type → params × type
decompose-arrows Γ (TpAbs me x atk T) =
let x' = fresh-var-new Γ x in
case decompose-arrows (ctxt-var-decl x' Γ) (rename-var Γ x x' T) of λ where
(ps , T') → Param me x' atk :: ps , T'
decompose-arrows Γ T = [] , T
decompose-ctr-type : ctxt → type → type × params × 𝕃 tmtp
decompose-ctr-type Γ T with decompose-arrows Γ T
...| ps , Tᵣ with decompose-tpapps Tᵣ
...| Tₕ , as = Tₕ , ps , as
{-# TERMINATING #-}
kind-to-indices : ctxt → kind → indices
kind-to-indices Γ (KdAbs x atk k) =
let x' = fresh-var-new Γ x in
Index x' atk :: kind-to-indices (ctxt-var-decl x' Γ) (rename-var Γ x x' k)
kind-to-indices Γ _ = []
rename-indices-h : ctxt → renamectxt → indices → 𝕃 tmtp → indices
rename-indices-h Γ ρ (Index x atk :: is) (ty :: tys) =
Index x' atk' ::
rename-indices-h (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') is tys
where
x' = fresh-var-renamectxt Γ ρ (maybe-else x id (is-var-unqual ty))
atk' = subst-renamectxt Γ ρ -tk atk
rename-indices-h Γ ρ (Index x atk :: is) [] =
let x' = fresh-var-renamectxt Γ ρ x in
Index x' (subst-renamectxt Γ ρ -tk atk) ::
rename-indices-h (ctxt-var-decl x' Γ) (renamectxt-insert ρ x x') is []
rename-indices-h _ _ [] _ = []
rename-indices : ctxt → indices → 𝕃 tmtp → indices
rename-indices Γ = rename-indices-h Γ empty-renamectxt
positivity : Set
positivity = 𝔹 × 𝔹 -- occurs positively × occurs negatively
pattern occurs-nil = ff , ff
pattern occurs-pos = tt , ff
pattern occurs-neg = ff , tt
pattern occurs-all = tt , tt
--positivity-inc : positivity → positivity
--positivity-dec : positivity → positivity
positivity-neg : positivity → positivity
positivity-add : positivity → positivity → positivity
--positivity-inc = map-fst λ _ → tt
--positivity-dec = map-snd λ _ → tt
positivity-neg = uncurry $ flip _,_
positivity-add (+ₘ , -ₘ) (+ₙ , -ₙ) = (+ₘ || +ₙ) , (-ₘ || -ₙ)
-- just tt = negative occurrence; just ff = not in the return type; nothing = okay
module positivity (x : var) where
open import conversion
not-free : ∀ {ed} → ⟦ ed ⟧ → maybe 𝔹
not-free = maybe-map (λ _ → tt) ∘' maybe-if ∘' is-free-in x
if-free : ∀ {ed} → ⟦ ed ⟧ → positivity
if-free t with is-free-in x t
...| f = f , f
if-free-args : args → positivity
if-free-args as with stringset-contains (free-vars-args as) x
...| f = f , f
hnf' : ∀ {ed} → ctxt → ⟦ ed ⟧ → ⟦ ed ⟧
hnf' Γ T = hnf Γ unfold-no-defs T
mtt = maybe-else tt id
mff = maybe-else ff id
posₒ = fst
negₒ = snd
occurs : positivity → maybe 𝔹
occurs p = maybe-if (negₒ p) >> just tt
{-# TERMINATING #-}
arrs+ : ctxt → type → maybe 𝔹
type+ : ctxt → type → positivity
kind+ : ctxt → kind → positivity
tpkd+ : ctxt → tpkd → positivity
tpapp+ : ctxt → type → positivity
arrs+ Γ (TpAbs me x' atk T) =
let Γ' = ctxt-var-decl x' Γ in
occurs (tpkd+ Γ $ hnf' Γ -tk atk) maybe-or arrs+ Γ' (hnf' Γ' T)
arrs+ Γ (TpApp T tT) = occurs (tpapp+ Γ $ hnf' Γ (TpApp T tT))
--arrs+ Γ T maybe-or (not-free -tT' tT)
arrs+ Γ (TpLam x' atk T) =
let Γ' = ctxt-var-decl x' Γ in
occurs (tpkd+ Γ $ hnf' Γ -tk atk) maybe-or arrs+ Γ' (hnf' Γ' T)
arrs+ Γ (TpVar x') = maybe-if (~ x =string x') >> just ff
arrs+ Γ T = just ff
type+ Γ (TpAbs me x' atk T) =
let Γ' = ctxt-var-decl x' Γ in
positivity-add (positivity-neg $ tpkd+ Γ $ hnf' Γ -tk atk) (type+ Γ' $ hnf' Γ' T)
type+ Γ (TpIota x' T T') =
let Γ' = ctxt-var-decl x' Γ in
positivity-add (type+ Γ $ hnf' Γ T) (type+ Γ' $ hnf' Γ' T')
type+ Γ (TpApp T tT) = tpapp+ Γ $ hnf' Γ $ TpApp T tT
type+ Γ (TpEq tₗ tᵣ) = occurs-nil
type+ Γ (TpHole _) = occurs-nil
type+ Γ (TpLam x' atk T)=
let Γ' = ctxt-var-decl x' Γ in
positivity-add (positivity-neg $ tpkd+ Γ $ hnf' Γ -tk atk) (type+ Γ' (hnf' Γ' T))
type+ Γ (TpVar x') = x =string x' , ff
tpapp+ Γ T with decompose-tpapps T
...| TpVar x' , as =
let f = if-free-args (tmtps-to-args NotErased as) in
if x =string x'
then positivity-add occurs-pos f
else maybe-else' (data-lookup Γ x' as) f
λ {(mk-data-info x'' xₒ'' asₚ asᵢ ps kᵢ k cs csₚₛ eds gds) →
type+ Γ (hnf' Γ $ TpAbs tt x'' (Tkk k) $ foldr (uncurry λ cₓ cₜ → TpAbs ff ignored-var (Tkt cₜ)) (TpVar x'') (inst-ctrs Γ ps asₚ cs))}
...| _ , _ = if-free T
kind+ Γ (KdAbs x' atk k) =
let Γ' = ctxt-var-decl x' Γ in
positivity-add (positivity-neg $ tpkd+ Γ $ hnf' Γ -tk atk) (kind+ Γ' k)
kind+ Γ _ = occurs-nil
tpkd+ Γ (Tkt T) = type+ Γ (hnf' Γ T)
tpkd+ Γ (Tkk k) = kind+ Γ k
ctr-positive : ctxt → type → maybe 𝔹
ctr-positive Γ = arrs+ Γ ∘ hnf' Γ
| {
"alphanum_fraction": 0.6100757731,
"avg_line_length": 33.2176870748,
"ext": "agda",
"hexsha": "81f7b746172793cc05cd4b5c162123d344452ce8",
"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": "9df4b85b55b57f97466242fdbb499adbd3bca893",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "zmthy/cedille",
"max_forks_repo_path": "src/datatype-util.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9df4b85b55b57f97466242fdbb499adbd3bca893",
"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": "zmthy/cedille",
"max_issues_repo_path": "src/datatype-util.agda",
"max_line_length": 144,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9df4b85b55b57f97466242fdbb499adbd3bca893",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "zmthy/cedille",
"max_stars_repo_path": "src/datatype-util.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1820,
"size": 4883
} |
module DSyntax where
open import Data.List
open import Data.List.All
open import Data.Nat
open import Typing
data DExpr φ : Type → Set where
var : ∀ {t}
→ (x : t ∈ φ)
→ DExpr φ t
nat : (unr-φ : All Unr φ)
→ (i : ℕ)
→ DExpr φ TInt
unit : (unr-φ : All Unr φ)
→ DExpr φ TUnit
pair : ∀ {φ₁ φ₂ t₁ t₂}
→ (sp : Split φ φ₁ φ₂)
→ (e₁ : DExpr φ₁ t₁)
→ (e₂ : DExpr φ₂ t₂)
→ DExpr φ (TPair t₁ t₂)
letpair : ∀ {φ₁ φ₂ t₁ t₂ t}
→ (sp : Split φ φ₁ φ₂)
→ (epair : DExpr φ₁ (TPair t₁ t₂))
→ (ebody : DExpr (t₁ ∷ t₂ ∷ φ₂) t)
→ DExpr φ t
fork : (e : DExpr φ TUnit)
→ DExpr φ TUnit
new : (unr-φ : All Unr φ)
→ (s : SType)
→ DExpr φ (TPair (TChan (SType.force s)) (TChan (SType.force (dual s))))
send : ∀ {φ₁ φ₂ s t}
→ (sp : Split φ φ₁ φ₂)
→ (ech : DExpr φ₁ (TChan (send t s)))
→ (earg : DExpr φ₂ t)
→ DExpr φ (TChan (SType.force s))
recv : ∀ {s t}
→ (ech : DExpr φ (TChan (recv t s)))
→ DExpr φ (TPair (TChan (SType.force s)) t)
close : (ech : DExpr φ (TChan send!))
→ DExpr φ TUnit
wait : (ech : DExpr φ (TChan send?))
→ DExpr φ TUnit
select : ∀ {s₁ s₂}
→ (lab : Selector)
→ (ech : DExpr φ (TChan (sintern s₁ s₂)))
→ DExpr φ (TChan (selection lab (SType.force s₁) (SType.force s₂)))
branch : ∀ {s₁ s₂ φ₁ φ₂ t}
→ (sp : Split φ φ₁ φ₂)
→ (ech : DExpr φ₁ (TChan (sextern s₁ s₂)))
→ (eleft : DExpr (TChan (SType.force s₁) ∷ φ₂) t)
→ (erght : DExpr (TChan (SType.force s₂) ∷ φ₂) t)
→ DExpr φ t
ulambda : ∀ {t₁ t₂}
→ (unr-φ : All Unr φ)
→ (ebody : DExpr (t₁ ∷ φ) t₂)
→ DExpr φ (TFun UU t₁ t₂)
llambda : ∀ {t₁ t₂}
→ (ebody : DExpr (t₁ ∷ φ) t₂)
→ DExpr φ (TFun LL t₁ t₂)
app : ∀ {φ₁ φ₂ lu t₁ t₂}
→ (sp : Split φ φ₁ φ₂)
→ (efun : DExpr φ₁ (TFun lu t₁ t₂))
→ (earg : DExpr φ₂ t₁)
→ DExpr φ t₂
subsume : ∀ {t₁ t₂}
→ (e : DExpr φ t₁)
→ (t≤t' : SubT t₁ t₂)
→ DExpr φ t₂
| {
"alphanum_fraction": 0.4997542998,
"avg_line_length": 23.3908045977,
"ext": "agda",
"hexsha": "6f6e4d14537af71ec6d1883ba47d67f573b3604c",
"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/DSyntax.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/DSyntax.agda",
"max_line_length": 78,
"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/DSyntax.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": 856,
"size": 2035
} |
module Max where
open import Data.Empty using (⊥-elim)
open import Data.Fin
open import Data.Nat hiding (_≤_)
open import Function using (_∘_)
open import Relation.Nullary
variable
n : ℕ
-- from https://github.com/zmthy/recursive-types/tree/ftfjp16
-- RecursiveTypes.Inductive.Type
-- adapted to use "variable"
-- A proposition that the indexed number is the largest it can be, i.e. one less
-- than its exclusive upper bound.
data Max : Fin n → Set where
max : Max {suc n} (fromℕ n)
-- A lemma on Max: if a number is max, then one less than that number with a
-- simultaneously lowered upper bound is also max.
max-pre : {x : Fin (suc n)} → Max (suc x) → Max x
max-pre max = max
-- A lemma on Max: if a number is max, then one more than that number with a
-- simultaneously increased upper bound is also max.
max-suc : {x : Fin n} → Max x → Max (suc x)
max-suc max = max
-- Given a proof that a number is not max, reduce its lower bound by one,
-- keeping the value of the number the same.
reduce : {x : Fin (suc n)} → ¬ Max x → Fin n
reduce {zero} {zero} ¬p = ⊥-elim (¬p max)
reduce {zero} {suc ()} ¬p
reduce {suc n} {zero} ¬p = zero
reduce {suc n} {suc x} ¬p = suc (reduce {x = x} (¬p ∘ max-suc))
-- Max is a decidable proposition: just compare the number value to the value of
-- the upper bound.
max? : (x : Fin n) → Dec (Max x)
max? {zero} ()
max? {suc zero} zero = yes max
max? {suc zero} (suc ())
max? {suc (suc n)} zero = no (λ ())
max? {suc (suc n)} (suc x) with max? x
max? {suc (suc n)} (suc .(fromℕ n)) | yes max = yes max
max? {suc (suc n)} (suc x) | no ¬p = no (¬p ∘ max-pre)
-- The reduce function preserves ≤.
reduce₁ : ∀ {m} {x : Fin n} (¬p : ¬ Max (suc x))
→ m ≤ x → suc m ≤ inject₁ (reduce ¬p)
reduce₁ {m = zero} ¬p₁ z≤n = s≤s z≤n
reduce₁ {m = suc m} {zero} ¬p ()
reduce₁ {m = suc m₁} {suc x₁} ¬p₁ (s≤s q₁) =
s≤s (reduce₁ (λ z → ¬p₁ (max-suc z)) q₁)
-- Injection is compatible with ordering.
inject-≤ : {i j : Fin n} → inject₁ i ≤ inject₁ j → i ≤ j
inject-≤ {i = 0F} {0F} z≤n = z≤n
inject-≤ {i = 0F} {suc j} z≤n = z≤n
inject-≤ {i = suc i} {0F} ()
inject-≤ {i = suc i} {suc j} (s≤s ii≤ij) = s≤s (inject-≤ ii≤ij)
-- Technical lemma about reduce.
lemma-reduce : {i j : Fin (suc n)} →
(i≤j : inject₁ i ≤ inject₁ j) → (¬p : ¬ Max j) → i ≤ inject₁ (reduce ¬p)
lemma-reduce {i = 0F} i≤j ¬p = z≤n
lemma-reduce {i = suc i} {suc j} (s≤s i≤j) ¬p = reduce₁ ¬p (inject-≤ i≤j)
-- A lemma on ≤: if x ≤ y, then x ≤ suc y.
suc-≤ : {x y : Fin n} → x ≤ y → inject₁ x ≤ suc y
suc-≤ {x = zero} z≤n = z≤n
suc-≤ {x = suc x} {zero} ()
suc-≤ {x = suc x} {suc y} (s≤s p) = s≤s (suc-≤ p)
-- A lemma on ≤: if suc x ≤ y, then x ≤ y.
pred-≤ : {x y : Fin n} → suc x ≤ inject₁ y → inject₁ x ≤ inject₁ y
pred-≤ {y = zero} ()
pred-≤ {y = suc x} (s≤s p) = suc-≤ p
-- A lemma on ≤: if x ≤ y, then for any z < x, z ≤ y.
trans-< : {x y : Fin n} {z : Fin′ x} → x ≤ y → inject z ≤ y
trans-< {x = zero} {z = ()} p
trans-< {x = suc x} {zero} ()
trans-< {x = suc x} {suc y} {zero} (s≤s p) = z≤n
trans-< {x = suc x} {suc y} {suc z} (s≤s p) = s≤s (trans-< p)
| {
"alphanum_fraction": 0.5741395947,
"avg_line_length": 33.7934782609,
"ext": "agda",
"hexsha": "56c9bfdd93e637d2cf534252f1bdec34a05cbfb0",
"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": "cd41919582013e75463308c32750e2712cf2de86",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "kcaliban/dual-session",
"max_forks_repo_path": "src/Max.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cd41919582013e75463308c32750e2712cf2de86",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "kcaliban/dual-session",
"max_issues_repo_path": "src/Max.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cd41919582013e75463308c32750e2712cf2de86",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "kcaliban/dual-session",
"max_stars_repo_path": "src/Max.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1280,
"size": 3109
} |
{-
This file contains a summary of the proof that π₄(S³) ≡ ℤ/2ℤ
The --experimental-lossy-unification flag is used to speed up type checking.
The file still type checks without it, but it's a lot slower (about 10 times).
-}
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Homotopy.Group.Pi4S3.Summary where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Data.Nat.Base
open import Cubical.Data.Sigma.Base
open import Cubical.HITs.Sn
open import Cubical.HITs.SetTruncation
open import Cubical.Homotopy.HopfInvariant.Base
open import Cubical.Homotopy.HopfInvariant.Homomorphism
open import Cubical.Homotopy.HopfInvariant.HopfMap
open import Cubical.Homotopy.HopfInvariant.Brunerie
open import Cubical.Homotopy.Whitehead
open import Cubical.Homotopy.Group.Base hiding (π)
open import Cubical.Homotopy.Group.Pi3S2
open import Cubical.Homotopy.Group.Pi4S3.BrunerieNumber
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Instances.Bool
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.GroupPath
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.Instances.Int
open import Cubical.Algebra.Group.Instances.IntMod
open import Cubical.Algebra.Group.ZAction
-- Homotopy groups (shifted version of π'Gr to get nicer numbering)
π : ℕ → Pointed₀ → Group₀
π n X = π'Gr (predℕ n) X
-- Nicer notation for the spheres (as pointed types)
𝕊² 𝕊³ : Pointed₀
𝕊² = S₊∙ 2
𝕊³ = S₊∙ 3
-- The Brunerie number; defined in Cubical.Homotopy.Group.Pi4S3.BrunerieNumber
-- as "abs (HopfInvariant-π' 0 ([ (∣ idfun∙ _ ∣₂ , ∣ idfun∙ _ ∣₂) ]×))"
β : ℕ
β = Brunerie
-- The connection to π₄(S³) is then also proved in the BrunerieNumber
-- file following Corollary 3.4.5 in Guillaume Brunerie's PhD thesis.
βSpec : GroupEquiv (π 4 𝕊³) (ℤGroup/ β)
βSpec = BrunerieIso
-- Ideally one could prove that β is 2 by normalization, but this does
-- not seem to terminate before we run out of memory. To try normalize
-- this use "C-u C-c C-n β≡2" (which normalizes the term, ignoring
-- abstract's). So instead we prove this by hand as in the second half
-- of Guillaume's thesis.
β≡2 : β ≡ 2
β≡2 = Brunerie≡2
-- This involves a lot of theory, for example that π₃(S²) ≃ ℤGroup where
-- the underlying map is induced by the Hopf invariant (which involves
-- the cup product on cohomology).
_ : GroupEquiv (π 3 𝕊²) ℤGroup
_ = hopfInvariantEquiv
-- Which is a consequence of the fact that π₃(S²) is generated by the
-- Hopf map.
_ : gen₁-by (π 3 𝕊²) ∣ HopfMap ∣₂
_ = π₂S³-gen-by-HopfMap
-- etc. For more details see the proof of "Brunerie≡2".
-- Combining all of this gives us the desired equivalence of groups:
π₄S³≃ℤ/2ℤ : GroupEquiv (π 4 𝕊³) (ℤGroup/ 2)
π₄S³≃ℤ/2ℤ = subst (GroupEquiv (π 4 𝕊³)) (cong ℤGroup/_ β≡2) βSpec
-- By the SIP this induces an equality of groups:
π₄S³≡ℤ/2ℤ : π 4 𝕊³ ≡ ℤGroup/ 2
π₄S³≡ℤ/2ℤ = GroupPath _ _ .fst π₄S³≃ℤ/2ℤ
-- As a sanity check we also establish the equality with Bool:
π₄S³≡Bool : π 4 𝕊³ ≡ BoolGroup
π₄S³≡Bool = π₄S³≡ℤ/2ℤ ∙ GroupPath _ _ .fst (GroupIso→GroupEquiv ℤGroup/2≅Bool)
| {
"alphanum_fraction": 0.7526915769,
"avg_line_length": 31.898989899,
"ext": "agda",
"hexsha": "f9755bb09a2124c55adbd6b017dd0ec0d87144cd",
"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/Homotopy/Group/Pi4S3/Summary.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/Homotopy/Group/Pi4S3/Summary.agda",
"max_line_length": 78,
"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/Homotopy/Group/Pi4S3/Summary.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1098,
"size": 3158
} |
module BasicIS4.Metatheory.Hilbert-TarskiClosedOvergluedImplicit where
open import BasicIS4.Syntax.Hilbert public
open import BasicIS4.Semantics.TarskiClosedOvergluedImplicit public
open ImplicitSyntax (∅ ⊢_) public
-- Completeness with respect to a particular model, for closed terms only.
module _ {{_ : Model}} where
reify : ∀ {A} → ⊩ A → ∅ ⊢ A
reify {α P} s = syn s
reify {A ▻ B} s = syn s
reify {□ A} s = syn s
reify {A ∧ B} s = pair (reify (π₁ s)) (reify (π₂ s))
reify {⊤} s = unit
-- Additional useful equipment.
module _ {{_ : Model}} where
⟪K⟫ : ∀ {A B} → ⊩ A → ⊩ B ▻ A
⟪K⟫ a = app ck (reify a) ⅋ K a
⟪S⟫′ : ∀ {A B C} → ⊩ A ▻ B ▻ C → ⊩ (A ▻ B) ▻ A ▻ C
⟪S⟫′ s₁ = app cs (reify s₁) ⅋ λ s₂ →
app (app cs (reify s₁)) (reify s₂) ⅋ ⟪S⟫ s₁ s₂
_⟪D⟫_ : ∀ {A B} → ⊩ □ (A ▻ B) → ⊩ □ A → ⊩ □ B
(t ⅋ s) ⟪D⟫ (u ⅋ a) = app (app cdist t) u ⅋ s ⟪$⟫ a
_⟪D⟫′_ : ∀ {A B} → ⊩ □ (A ▻ B) → ⊩ □ A ▻ □ B
_⟪D⟫′_ s = app cdist (reify s) ⅋ _⟪D⟫_ s
⟪↑⟫ : ∀ {A} → ⊩ □ A → ⊩ □ □ A
⟪↑⟫ s = box (syn s) ⅋ s
_⟪,⟫′_ : ∀ {A B} → ⊩ A → ⊩ B ▻ A ∧ B
_⟪,⟫′_ a = app cpair (reify a) ⅋ _,_ a
-- Additional useful equipment, for sequents.
module _ {{_ : Model}} where
_⟦D⟧_ : ∀ {A B Γ} → ⊩ Γ ⇒ □ (A ▻ B) → ⊩ Γ ⇒ □ A → ⊩ Γ ⇒ □ B
(s₁ ⟦D⟧ s₂) γ = (s₁ γ) ⟪D⟫ (s₂ γ)
⟦↑⟧ : ∀ {A Γ} → ⊩ Γ ⇒ □ A → ⊩ Γ ⇒ □ □ A
⟦↑⟧ s γ = ⟪↑⟫ (s γ)
-- Soundness with respect to all models, or evaluation.
eval : ∀ {A Γ} → Γ ⊢ A → Γ ⊨ A
eval (var i) γ = lookup i γ
eval (app t u) γ = eval t γ ⟪$⟫ eval u γ
eval ci γ = ci ⅋ I
eval ck γ = ck ⅋ ⟪K⟫
eval cs γ = cs ⅋ ⟪S⟫′
eval (box t) γ = box t ⅋ eval t ∙
eval cdist γ = cdist ⅋ _⟪D⟫′_
eval cup γ = cup ⅋ ⟪↑⟫
eval cdown γ = cdown ⅋ ⟪↓⟫
eval cpair γ = cpair ⅋ _⟪,⟫′_
eval cfst γ = cfst ⅋ π₁
eval csnd γ = csnd ⅋ π₂
eval unit γ = ∙
-- Correctness of evaluation with respect to conversion.
eval✓ : ∀ {{_ : Model}} {A Γ} {t t′ : Γ ⊢ A} → t ⋙ t′ → eval t ≡ eval t′
eval✓ refl⋙ = refl
eval✓ (trans⋙ p q) = trans (eval✓ p) (eval✓ q)
eval✓ (sym⋙ p) = sym (eval✓ p)
eval✓ (congapp⋙ p q) = cong² _⟦$⟧_ (eval✓ p) (eval✓ q)
eval✓ (congi⋙ p) = cong I (eval✓ p)
eval✓ (congk⋙ p q) = cong² K (eval✓ p) (eval✓ q)
eval✓ (congs⋙ p q r) = cong³ ⟦S⟧ (eval✓ p) (eval✓ q) (eval✓ r)
eval✓ (congdist⋙ p q) = cong² _⟦D⟧_ (eval✓ p) (eval✓ q)
eval✓ (congup⋙ p) = cong ⟦↑⟧ (eval✓ p)
eval✓ (congdown⋙ p) = cong ⟦↓⟧ (eval✓ p)
eval✓ (congpair⋙ {A} {B} p q) = cong² (_⟦,⟧_ {A} {B}) (eval✓ p) (eval✓ q)
eval✓ (congfst⋙ {A} {B} p) = cong (⟦π₁⟧ {A} {B}) (eval✓ p)
eval✓ (congsnd⋙ {A} {B} p) = cong (⟦π₂⟧ {A} {B}) (eval✓ p)
eval✓ beta▻ₖ⋙ = refl
eval✓ beta▻ₛ⋙ = refl
eval✓ beta∧₁⋙ = refl
eval✓ beta∧₂⋙ = refl
eval✓ eta∧⋙ = refl
eval✓ eta⊤⋙ = refl
-- The canonical model.
private
instance
canon : Model
canon = record
{ ⊩ᵅ_ = λ P → ∅ ⊢ α P
}
-- Completeness with respect to all models, or quotation, for closed terms only.
quot₀ : ∀ {A} → ∅ ⊨ A → ∅ ⊢ A
quot₀ t = reify (t ∙)
-- Normalisation by evaluation, for closed terms only.
norm₀ : ∀ {A} → ∅ ⊢ A → ∅ ⊢ A
norm₀ = quot₀ ∘ eval
-- TODO: Correctness of normalisation with respect to conversion.
| {
"alphanum_fraction": 0.4809902741,
"avg_line_length": 28.7542372881,
"ext": "agda",
"hexsha": "650376ea430a46411581efb097c4c1a62faa366a",
"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": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "BasicIS4/Metatheory/Hilbert-TarskiClosedOvergluedImplicit.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "BasicIS4/Metatheory/Hilbert-TarskiClosedOvergluedImplicit.agda",
"max_line_length": 80,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "BasicIS4/Metatheory/Hilbert-TarskiClosedOvergluedImplicit.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 1629,
"size": 3393
} |
{-# OPTIONS --without-K #-}
open import HoTT.Base
open import HoTT.Equivalence
open import HoTT.Identity
module HoTT.Identity.NaturalNumber where
private variable m n : ℕ
_=ℕ_ : ℕ → ℕ → 𝒰₀
zero =ℕ zero = 𝟏
zero =ℕ (succ _) = 𝟎
succ _ =ℕ zero = 𝟎
succ m =ℕ succ n = m =ℕ n
private
r : (n : ℕ) → n =ℕ n
r zero = ★
r (succ n) = r n
=ℕ-elim : m == n → m =ℕ n
=ℕ-elim {m} p = transport (m =ℕ_) p (r m)
=ℕ-intro : m =ℕ n → m == n
=ℕ-intro {zero} {zero} _ = refl
=ℕ-intro {zero} {succ n} ()
=ℕ-intro {succ m} {zero} ()
=ℕ-intro {succ m} {succ n} = ap succ ∘ =ℕ-intro
=ℕ-equiv : {m n : ℕ} → m == n ≃ m =ℕ n
=ℕ-equiv {x} = f , qinv→isequiv (g , η , ε {x})
where
f = =ℕ-elim
g = =ℕ-intro
η : g ∘ f {m} {n} ~ id
η {zero} refl = refl
η {succ n} refl = ap (ap succ) (η refl)
ε : f ∘ g {m} {n} ~ id
ε {zero} {zero} ★ = refl
ε {zero} {succ n} ()
ε {succ m} {zero} ()
ε {succ m} {succ n} p = transport-ap (succ m =ℕ_) succ (g p) (r m) ∙ ε {m} p
| {
"alphanum_fraction": 0.5300207039,
"avg_line_length": 21.4666666667,
"ext": "agda",
"hexsha": "09c4c41b8dc0b844f1b70787325265baf3ca9860",
"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": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Identity/NaturalNumber.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"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": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Identity/NaturalNumber.agda",
"max_line_length": 78,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Identity/NaturalNumber.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 458,
"size": 966
} |
module Common.Reflect where
open import Common.Level
open import Common.Prelude renaming (Nat to ℕ)
postulate QName : Set
{-# BUILTIN QNAME QName #-}
primitive primQNameEquality : QName → QName → Bool
data Hiding : Set where
hidden visible instance : Hiding
{-# BUILTIN HIDING Hiding #-}
{-# BUILTIN HIDDEN hidden #-}
{-# BUILTIN VISIBLE visible #-}
{-# BUILTIN INSTANCE instance #-}
-- relevant the argument is (possibly) relevant at compile-time
-- irrelevant the argument is irrelevant at compile- and runtime
data Relevance : Set where
relevant irrelevant : Relevance
{-# BUILTIN RELEVANCE Relevance #-}
{-# BUILTIN RELEVANT relevant #-}
{-# BUILTIN IRRELEVANT irrelevant #-}
data ArgInfo : Set where
arginfo : Hiding → Relevance → ArgInfo
data Arg A : Set where
arg : ArgInfo → A → Arg A
{-# BUILTIN ARGINFO ArgInfo #-}
{-# BUILTIN ARG Arg #-}
{-# BUILTIN ARGARG arg #-}
{-# BUILTIN ARGARGINFO arginfo #-}
mutual
Args : Set
data Type : Set
data Sort : Set
data Term : Set where
var : ℕ → Args → Term
con : QName → Args → Term
def : QName → Args → Term
lam : Hiding → Term → Term
pi : Arg Type → Type → Term
sort : Sort → Term
unknown : Term
Args = List (Arg Term)
data Type where
el : Sort → Term → Type
data Sort where
set : Term → Sort
lit : ℕ → Sort
unknown : Sort
{-# BUILTIN AGDASORT Sort #-}
{-# BUILTIN AGDATERM Term #-}
{-# BUILTIN AGDATYPE Type #-}
{-# BUILTIN AGDATERMVAR var #-}
{-# BUILTIN AGDATERMCON con #-}
{-# BUILTIN AGDATERMDEF def #-}
{-# BUILTIN AGDATERMLAM lam #-}
{-# BUILTIN AGDATERMPI pi #-}
{-# BUILTIN AGDATERMSORT sort #-}
{-# BUILTIN AGDATERMUNSUPPORTED unknown #-}
{-# BUILTIN AGDATYPEEL el #-}
{-# BUILTIN AGDASORTSET set #-}
{-# BUILTIN AGDASORTLIT lit #-}
{-# BUILTIN AGDASORTUNSUPPORTED unknown #-}
postulate
FunDef : Set
DataDef : Set
RecordDef : Set
{-# BUILTIN AGDAFUNDEF FunDef #-}
{-# BUILTIN AGDADATADEF DataDef #-}
{-# BUILTIN AGDARECORDDEF RecordDef #-}
data Definition : Set where
funDef : FunDef → Definition
dataDef : DataDef → Definition
recordDef : RecordDef → Definition
dataConstructor : Definition
axiom : Definition
prim : Definition
{-# BUILTIN AGDADEFINITION Definition #-}
{-# BUILTIN AGDADEFINITIONFUNDEF funDef #-}
{-# BUILTIN AGDADEFINITIONDATADEF dataDef #-}
{-# BUILTIN AGDADEFINITIONRECORDDEF recordDef #-}
{-# BUILTIN AGDADEFINITIONDATACONSTRUCTOR dataConstructor #-}
{-# BUILTIN AGDADEFINITIONPOSTULATE axiom #-}
{-# BUILTIN AGDADEFINITIONPRIMITIVE prim #-}
primitive
primQNameType : QName → Type
primQNameDefinition : QName → Definition
--primFunClauses : FunDef → List Clause
primDataConstructors : DataDef → List QName
--primRecordConstructor : RecordDef → QName
--primRecordFields : RecordDef → List QName
| {
"alphanum_fraction": 0.6008703761,
"avg_line_length": 28.7232142857,
"ext": "agda",
"hexsha": "f2b65d931971a720801d9d3937ba4786fbc7dde7",
"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/Common/Reflect.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/Common/Reflect.agda",
"max_line_length": 66,
"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/Common/Reflect.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": 830,
"size": 3217
} |
{-# OPTIONS --cubical --safe #-}
module FreeReader where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Function.Base using (id; _$_)
open import Class
open Functor
variable
A B C : Set
-- The Reader monad, as a free monad
data FreeReader (R : Set) : Set → Set₁ where
Pure : A → FreeReader R A
Bind : FreeReader R A → (A → FreeReader R B) → FreeReader R B
Ask : FreeReader R R
-- Monad laws
LeftId : ∀ {A B}
→ (a : A)
→ (f : A → FreeReader R B)
→ Bind (Pure a) f ≡ f a
RightId : ∀ {A}
→ (m : FreeReader R A)
→ Bind m Pure ≡ m
Assoc : ∀ {A B C}
→ (m : FreeReader R A)
→ (f : A → FreeReader R B)
→ (g : B → FreeReader R C)
→ Bind (Bind m f) g ≡ Bind m (λ x → Bind (f x) g)
freereader-functor : ∀ {R} → Functor (FreeReader R)
freereader-functor .fmap f m = Bind m (Pure ∘ f)
freereader-functor .fmap-id-legit m i = RightId m i
freereader-functor .fmap-compose-legit m f g i
= hcomp (λ j → λ { (i = i0) → Bind m (Pure ∘ f ∘ g)
; (i = i1) → Assoc m (Pure ∘ g) (Pure ∘ f) (~ j)
})
(Bind m (λ x → LeftId (g x) (Pure ∘ f) (~ i)))
freereader-ap : ∀ {R} → Applicative (FreeReader R)
freereader-ap .Applicative.functor = freereader-functor
freereader-ap .Applicative.pure = Pure
freereader-ap .Applicative._<*>_ mf m = Bind mf (λ f → Bind m (Pure ∘ f))
freereader-ap .Applicative.app-identity v i
= hcomp (λ j → λ { (i = i0) → LeftId id (λ f → Bind v (Pure ∘ f)) (~ j)
; (i = i1) → v
})
(RightId v i)
freereader-ap .Applicative.app-compose u v w
-- For some reason, Agda doesn't like wildcards in cubical proofs. Oh well.
= Pure _∘_ <*> u <*> v <*> w
≡[ i ]⟨ LeftId _∘_ (λ f → Bind u (Pure ∘ f)) i <*> v <*> w ⟩
Bind u (λ u' → Pure (u' ∘_)) <*> v <*> w
≡[ i ]⟨ Assoc u (λ u' → Pure (u' ∘_)) (λ f → Bind v (Pure ∘ f)) i <*> w ⟩
Bind u (λ u' → Bind (Pure (u' ∘_)) (λ c → Bind v (Pure ∘ c))) <*> w
≡[ i ]⟨ Bind u (λ u' → LeftId (u' ∘_) (λ c → Bind v (Pure ∘ c)) i) <*> w ⟩
Bind u (λ u' → Bind v (λ v' → Pure (u' ∘ v'))) <*> w
≡[ i ]⟨ Assoc u (λ u' → Bind v (λ v' → Pure (u' ∘ v'))) (λ f → Bind w (Pure ∘ f)) i ⟩
Bind u (λ u' → Bind (Bind v (λ v' → Pure (u' ∘ v'))) (λ f → Bind w (Pure ∘ f)))
≡[ i ]⟨ Bind u (λ u' → Assoc v (λ v' → Pure (u' ∘ v')) (λ f → Bind w (Pure ∘ f)) i) ⟩
Bind u (λ u' → Bind v (λ v' → Bind (Pure (u' ∘ v')) (λ f → Bind w (Pure ∘ f))))
≡[ i ]⟨ Bind u (λ u' → Bind v (λ v' → LeftId (u' ∘ v') (λ f → Bind w (Pure ∘ f)) i)) ⟩
Bind u (λ u' → Bind v (λ v' → Bind w (Pure ∘ u' ∘ v')))
≡[ i ]⟨ Bind u (λ u' → Bind v (λ v' → Bind w (λ w' → LeftId (v' w') (Pure ∘ u') (~ i)))) ⟩
Bind u (λ u' → Bind v (λ v' → Bind w (λ w' → Bind (Pure (v' w')) (Pure ∘ u'))))
≡[ i ]⟨ Bind u (λ u' → Bind v (λ v' → Assoc w (Pure ∘ v') (Pure ∘ u') (~ i))) ⟩
Bind u (λ u' → Bind v (λ v' → Bind (Bind w (Pure ∘ v')) (Pure ∘ u')))
≡[ i ]⟨ Bind u (λ u' → Assoc v (λ f → Bind w (Pure ∘ f)) (Pure ∘ u') (~ i)) ⟩
Bind u (λ u' → Bind (Bind v (λ v' → Bind w (Pure ∘ v'))) (Pure ∘ u'))
∎
where open Applicative freereader-ap
freereader-ap .Applicative.app-homo f x
= LeftId f (λ f' → Bind (Pure x) (λ x' → Pure (f' x')))
∙ LeftId x (λ x' → Pure (f x'))
freereader-ap .Applicative.app-intchg u y
-- u <*> pure y
= Bind u (λ u' → Bind (Pure y) (Pure ∘ u'))
≡[ i ]⟨ Bind u (λ u' → LeftId y (Pure ∘ u') i) ⟩
Bind u (λ u' → Pure (u' y))
≡[ i ]⟨ LeftId (_$ y) (λ f → Bind u (Pure ∘ f)) (~ i) ⟩
Bind (Pure (_$ y)) (λ _y' → Bind u (λ u' → Pure (u' y')))
-- pure (_$ y) <*> u
∎
freereader-monad : ∀ {R} → Monad (FreeReader R)
freereader-monad .Monad.applicative = freereader-ap
freereader-monad .Monad._>>=_ = Bind
freereader-monad .Monad.monad-left-id = LeftId
freereader-monad .Monad.monad-right-id = RightId
freereader-monad .Monad.monad-assoc = Assoc
| {
"alphanum_fraction": 0.5026048127,
"avg_line_length": 41.9895833333,
"ext": "agda",
"hexsha": "8f033d6bccad762471b58981c5dc5a66b16657e0",
"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": "13364fa4af25720bf1d73bf960e8c04ebb34762f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mb64/cubical-free-monads",
"max_forks_repo_path": "FreeReader.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "13364fa4af25720bf1d73bf960e8c04ebb34762f",
"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": "mb64/cubical-free-monads",
"max_issues_repo_path": "FreeReader.agda",
"max_line_length": 92,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "13364fa4af25720bf1d73bf960e8c04ebb34762f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mb64/cubical-free-monads",
"max_stars_repo_path": "FreeReader.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-17T17:53:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-17T17:53:44.000Z",
"num_tokens": 1598,
"size": 4031
} |
module Ids where
id : {A : Set} -> A -> A
id x = x
slow : {A : Set} -> A -> A
slow = id id id id id id id id id id id id id id id id id id
-- The example above is based on one in "Implementing Typed
-- Intermediate Languages" by Shao, League and Monnier.
| {
"alphanum_fraction": 0.6395348837,
"avg_line_length": 23.4545454545,
"ext": "agda",
"hexsha": "6ea599f1e5db9a319b220a49959b77cb62ebfae9",
"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": "src/prototyping/term/examples/Ids.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": "src/prototyping/term/examples/Ids.agda",
"max_line_length": 60,
"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": "src/prototyping/term/examples/Ids.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": 82,
"size": 258
} |
{-# OPTIONS --cubical #-}
open import 17-number-theory
open import Cubical.Core.Everything
data circle-C : UU lzero where
base : circle-C
loop : Path circle-C base base
| {
"alphanum_fraction": 0.72,
"avg_line_length": 19.4444444444,
"ext": "agda",
"hexsha": "05452cf53282256dcb27693521f63d0dd3b509b6",
"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": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "tmoux/HoTT-Intro",
"max_forks_repo_path": "Agda/cubical-circle.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29",
"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": "tmoux/HoTT-Intro",
"max_issues_repo_path": "Agda/cubical-circle.agda",
"max_line_length": 35,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "22023fd35023cb6804424ce12cd10d252b80fd29",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "tmoux/HoTT-Intro",
"max_stars_repo_path": "Agda/cubical-circle.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 49,
"size": 175
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Modulo.FinEquiv where
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Prelude
open import Cubical.Data.Fin
open import Cubical.Data.Nat
open import Cubical.Data.Nat.Order
open import Cubical.HITs.Modulo.Base
-- For positive `k`, every `Modulo k` can be reduced to its
-- residue modulo `k`, given by a value of type `Fin k`. This
-- forms an equivalence between `Fin k` and `Modulo k`.
module Reduction {k₀ : ℕ} where
private
k = suc k₀
fembed : Fin k → Modulo k
fembed = embed ∘ toℕ
ResiduePath : ℕ → Type₀
ResiduePath n = Σ[ f ∈ Fin k ] fembed f ≡ embed n
rbase : ∀ n (n<k : n < k) → ResiduePath n
rbase n n<k = (n , n<k) , refl
rstep : ∀ n → ResiduePath n → ResiduePath (k + n)
rstep n (f , p) = f , p ∙ step n
rstep≡
: ∀ n (R : ResiduePath n)
→ PathP (λ i → fembed (fst R) ≡ step n i) (snd R) (snd (rstep n R))
rstep≡ n (f , p) = λ i j → compPath-filler p (step n) i j
residuePath : ∀ n → ResiduePath n
residuePath = +induction k₀ ResiduePath rbase rstep
lemma₁ : ∀ n → rstep n (residuePath n) ≡ residuePath (k + n)
lemma₁ = sym ∘ +inductionStep k₀ ResiduePath rbase rstep
residueStep₁
: ∀ n → fst (residuePath n) ≡ fst (residuePath (k + n))
residueStep₁ = cong fst ∘ lemma₁
residueStep₂
: ∀ n → PathP (λ i → fembed (residueStep₁ n i) ≡ step n i)
((snd ∘ residuePath) n)
((snd ∘ residuePath) (k + n))
residueStep₂ n i j
= hfill (λ ii → λ
{ (i = i0) → snd (residuePath n) j
; (j = i0) → fembed (residueStep₁ n (i ∧ ii))
; (i = i1) → snd (lemma₁ n ii) j
; (j = i1) → step n i
})
(inS (rstep≡ n (residuePath n) i j))
i1
residue : Modulo k → Fin k
residue (embed n) = fst (residuePath n)
residue (step n i) = residueStep₁ n i
sect : section residue fembed
sect (r , r<k) = cong fst (+inductionBase k₀ ResiduePath rbase rstep r r<k)
retr : retract residue fembed
retr (embed n) = snd (residuePath n)
retr (step n i) = residueStep₂ n i
Modulo≡Fin : Modulo k ≡ Fin k
Modulo≡Fin = isoToPath (iso residue fembed sect retr)
open Reduction using (fembed; residue; Modulo≡Fin) public
| {
"alphanum_fraction": 0.6190271201,
"avg_line_length": 29.7820512821,
"ext": "agda",
"hexsha": "9486df2c7957f73cdea6270647c7374c16151084",
"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/HITs/Modulo/FinEquiv.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/HITs/Modulo/FinEquiv.agda",
"max_line_length": 77,
"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/HITs/Modulo/FinEquiv.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 818,
"size": 2323
} |
{-# OPTIONS --without-K #-}
open import HoTT.Base
open import HoTT.Identity
open import HoTT.Equivalence
open import HoTT.Homotopy
module HoTT.Identity.Identity where
ap⁻¹ : ∀ {i j} {A : 𝒰 i} {B : 𝒰 j} ((f , _) : A ≃ B) {a a' : A} →
f a == f a' → a == a'
ap⁻¹ e {a} {a'} p = η a ⁻¹ ∙ ap g p ∙ η a'
where open Iso (eqv→iso e)
-- Theorem 2.11.1
ap≃ : ∀ {i j} {A : 𝒰 i} {B : 𝒰 j} →
((f , _) : A ≃ B) → (a a' : A) → (a == a') ≃ (f a == f a')
ap≃ e a a' = iso→eqv iso
where
open Iso (eqv→iso e)
iso : Iso _ _
Iso.f iso = ap f
Iso.g iso = ap⁻¹ e
Iso.η iso p =
η a ⁻¹ ∙ ap g (ap f p) ∙ η a' =⟨ _ ∙ₗ ap-∘ g f p ⁻¹ ∙ᵣ _ ⟩
η a ⁻¹ ∙ ap (g ∘ f) p ∙ η a' =⟨ assoc ⁻¹ ⟩
η a ⁻¹ ∙ (ap (g ∘ f) p ∙ η a') =⟨ pivotₗ (~-natural-id η p) ⁻¹ ⟩
p ∎
where open =-Reasoning
Iso.ε iso q =
ap f (η a ⁻¹ ∙ ap g q ∙ η a') =⟨ pivotₗ (~-natural (ε ∘ f) _) ⟩
ε (f a) ⁻¹ ∙ (ap (f ∘ g ∘ f) _ ∙ ε (f a')) =⟨ _ ∙ₗ (ap-∘ f (g ∘ f) _ ∙ᵣ _) ⟩
ε (f a) ⁻¹ ∙ (ap f (ap (g ∘ f) _) ∙ ε (f a')) =⟨ ap (λ p → _ ∙ (ap f p ∙ _)) inner ⟩
ε (f a) ⁻¹ ∙ (ap f (ap g q) ∙ ε (f a')) =⟨ _ ∙ₗ (ap-∘ f g q ⁻¹ ∙ᵣ _) ⟩
ε (f a) ⁻¹ ∙ (ap (f ∘ g) q ∙ ε (f a')) =⟨ pivotₗ (~-natural-id ε q) ⁻¹ ⟩
q ∎
where
open =-Reasoning
inner : ap (g ∘ f) (η a ⁻¹ ∙ ap g q ∙ η a') == ap g q
inner =
ap (g ∘ f) (η a ⁻¹ ∙ ap g q ∙ η a') =⟨ pivotᵣ (~-natural-id η _ ⁻¹) ⟩
η a ∙ (η a ⁻¹ ∙ ap g q ∙ η a') ∙ η a' ⁻¹ =⟨ assoc ∙ᵣ η a' ⁻¹ ⟩
η a ∙ (η a ⁻¹ ∙ ap g q) ∙ η a' ∙ η a' ⁻¹ =⟨ assoc ∙ᵣ _ ∙ᵣ _ ⟩
η a ∙ η a ⁻¹ ∙ ap g q ∙ η a' ∙ η a' ⁻¹ =⟨ invᵣ ∙ᵣ _ ∙ᵣ _ ∙ᵣ _ ⟩
refl ∙ ap g q ∙ η a' ∙ η a' ⁻¹ =⟨ unitₗ ⁻¹ ∙ᵣ _ ∙ᵣ _ ⟩
ap g q ∙ η a' ∙ η a' ⁻¹ =⟨ assoc ⁻¹ ⟩
ap g q ∙ (η a' ∙ η a' ⁻¹) =⟨ _ ∙ₗ invᵣ ⟩
ap g q ∙ refl =⟨ unitᵣ ⁻¹ ⟩
ap g q ∎
-- Theorem 2.11.3
=-transport : ∀ {i j} {A : 𝒰 i} {B : 𝒰 j} {a a' : A}
(f g : A → B) (p : a == a') (q : f a == g a) →
transport (λ x → f x == g x) p q == ap f p ⁻¹ ∙ q ∙ ap g p
=-transport _ _ refl q rewrite q = refl
module _ {i} {A : 𝒰 i} {x₁ x₂ : A} (a : A) (p : x₁ == x₂)
where
=-transportₗ : (q : a == x₁) → transport (a ==_) p q == q ∙ p
=-transportₗ q rewrite p = unitᵣ
=-transportᵣ : (q : x₁ == a) → transport (_== a) p q == p ⁻¹ ∙ q
=-transportᵣ q rewrite p = unitₗ
| {
"alphanum_fraction": 0.3841607565,
"avg_line_length": 40.2857142857,
"ext": "agda",
"hexsha": "4d9d1b83fdfebe0c2bcc6f881c5b3103d75b4819",
"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": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Identity/Identity.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"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": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Identity/Identity.agda",
"max_line_length": 88,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Identity/Identity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1319,
"size": 2538
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of the membership predicate for fresh lists
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Rel; Setoid)
module Data.List.Fresh.Membership.Setoid.Properties {c ℓ} (S : Setoid c ℓ) where
open import Level using (Level; _⊔_)
open import Data.Empty
open import Data.Nat.Base
open import Data.Nat.Properties
open import Data.Product using (∃; _×_; _,_)
open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂; fromInj₂)
open import Function using (id; _∘′_; _$_)
open import Relation.Nullary
open import Relation.Unary as U using (Pred)
import Relation.Binary as B
import Relation.Binary.PropositionalEquality as P
open import Relation.Nary
open import Data.List.Fresh
open import Data.List.Fresh.Properties
open import Data.List.Fresh.Membership.Setoid S
open import Data.List.Fresh.Relation.Unary.Any using (Any; here; there; _─_)
import Data.List.Fresh.Relation.Unary.Any.Properties as Anyₚ
import Data.List.Fresh.Relation.Unary.All.Properties as Allₚ
open Setoid S renaming (Carrier to A)
private
variable
p r : Level
------------------------------------------------------------------------
-- transport
module _ {R : Rel A r} where
≈-subst-∈ : ∀ {x y} {xs : List# A R} → x ≈ y → x ∈ xs → y ∈ xs
≈-subst-∈ x≈y (here x≈x′) = here (trans (sym x≈y) x≈x′)
≈-subst-∈ x≈y (there x∈xs) = there (≈-subst-∈ x≈y x∈xs)
------------------------------------------------------------------------
-- relationship to fresh
module _ {R : Rel A r} (R⇒≉ : ∀[ R ⇒ _≉_ ]) where
fresh⇒∉ : ∀ {x} {xs : List# A R} → x # xs → x ∉ xs
fresh⇒∉ (r , _) (here x≈y) = R⇒≉ r x≈y
fresh⇒∉ (_ , x#xs) (there x∈xs) = fresh⇒∉ x#xs x∈xs
------------------------------------------------------------------------
-- disjointness
module _ {R : Rel A r} where
distinct : ∀ {x y} {xs : List# A R} → x ∈ xs → y ∉ xs → x ≉ y
distinct x∈xs y∉xs x≈y = y∉xs (≈-subst-∈ x≈y x∈xs)
------------------------------------------------------------------------
-- remove
module _ {R : Rel A r} where
remove-inv : ∀ {x y} {xs : List# A R} (x∈xs : x ∈ xs) →
y ∈ xs → x ≈ y ⊎ y ∈ (xs ─ x∈xs)
remove-inv (here x≈z) (here y≈z) = inj₁ (trans x≈z (sym y≈z))
remove-inv (here _) (there y∈xs) = inj₂ y∈xs
remove-inv (there _) (here y≈z) = inj₂ (here y≈z)
remove-inv (there x∈xs) (there y∈xs) = Sum.map₂ there (remove-inv x∈xs y∈xs)
∈-remove : ∀ {x y} {xs : List# A R} (x∈xs : x ∈ xs) → y ∈ xs → x ≉ y → y ∈ (xs ─ x∈xs)
∈-remove x∈xs y∈xs x≉y = fromInj₂ (⊥-elim ∘′ x≉y) (remove-inv x∈xs y∈xs)
module _ {R : Rel A r} (R⇒≉ : ∀[ R ⇒ _≉_ ]) (≉⇒R : ∀[ _≉_ ⇒ R ]) where
private
R≈ : R B.Respectsˡ _≈_
R≈ x≈y Rxz = ≉⇒R (R⇒≉ Rxz ∘′ trans x≈y)
fresh-remove : ∀ {x} {xs : List# A R} (x∈xs : x ∈ xs) → x # (xs ─ x∈xs)
fresh-remove {xs = cons x xs pr} (here x≈y) = fresh-respectsˡ R≈ (sym x≈y) pr
fresh-remove {xs = cons x xs pr} (there x∈xs) =
≉⇒R (distinct x∈xs (fresh⇒∉ R⇒≉ pr)) , fresh-remove x∈xs
∉-remove : ∀ {x} {xs : List# A R} (x∈xs : x ∈ xs) → x ∉ (xs ─ x∈xs)
∉-remove x∈xs = fresh⇒∉ R⇒≉ (fresh-remove x∈xs)
------------------------------------------------------------------------
-- injection
module _ {R : Rel A r} (R⇒≉ : ∀[ R ⇒ _≉_ ]) where
injection : ∀ {xs ys : List# A R} (inj : ∀ {x} → x ∈ xs → x ∈ ys) →
length xs ≤ length ys
injection {[]} {ys} inj = z≤n
injection {xxs@(cons x xs pr)} {ys} inj = begin
length xxs ≤⟨ s≤s (injection step) ⟩
suc (length (ys ─ x∈ys)) ≡⟨ P.sym (Anyₚ.length-remove x∈ys) ⟩
length ys ∎
where
open ≤-Reasoning
x∉xs : x ∉ xs
x∉xs = fresh⇒∉ R⇒≉ pr
x∈ys : x ∈ ys
x∈ys = inj (here refl)
step : ∀ {y} → y ∈ xs → y ∈ (ys ─ x∈ys)
step {y} y∈xs = ∈-remove x∈ys (inj (there y∈xs)) (distinct y∈xs x∉xs ∘′ sym)
strict-injection : ∀ {xs ys : List# A R} (inj : ∀ {x} → x ∈ xs → x ∈ ys) →
(∃ λ x → x ∈ ys × x ∉ xs) → length xs < length ys
strict-injection {xs} {ys} inj (x , x∈ys , x∉xs) = begin
suc (length xs) ≤⟨ s≤s (injection step) ⟩
suc (length (ys ─ x∈ys)) ≡⟨ P.sym (Anyₚ.length-remove x∈ys) ⟩
length ys ∎
where
open ≤-Reasoning
step : ∀ {y} → y ∈ xs → y ∈ (ys ─ x∈ys)
step {y} y∈xs = fromInj₂ (λ x≈y → ⊥-elim (x∉xs (≈-subst-∈ (sym x≈y) y∈xs)))
$ remove-inv x∈ys (inj y∈xs)
------------------------------------------------------------------------
-- proof irrelevance
module _ {R : Rel A r} (R⇒≉ : ∀[ R ⇒ _≉_ ]) (≈-irrelevant : B.Irrelevant _≈_) where
∈-irrelevant : ∀ {x} {xs : List# A R} → Irrelevant (x ∈ xs)
-- positive cases
∈-irrelevant (here x≈y₁) (here x≈y₂) = P.cong here (≈-irrelevant x≈y₁ x≈y₂)
∈-irrelevant (there x∈xs₁) (there x∈xs₂) = P.cong there (∈-irrelevant x∈xs₁ x∈xs₂)
-- absurd cases
∈-irrelevant {xs = cons x xs pr} (here x≈y) (there x∈xs₂) =
⊥-elim (distinct x∈xs₂ (fresh⇒∉ R⇒≉ pr) x≈y)
∈-irrelevant {xs = cons x xs pr} (there x∈xs₁) (here x≈y) =
⊥-elim (distinct x∈xs₁ (fresh⇒∉ R⇒≉ pr) x≈y)
| {
"alphanum_fraction": 0.4964701393,
"avg_line_length": 34.7086092715,
"ext": "agda",
"hexsha": "7653bcaa2c1e7f39dd69678e2b24aae30354fbc3",
"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": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/List/Fresh/Membership/Setoid/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"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": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/List/Fresh/Membership/Setoid/Properties.agda",
"max_line_length": 88,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/List/Fresh/Membership/Setoid/Properties.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": 2047,
"size": 5241
} |
module Interpreter where
open import Data.Char
open import Data.Bool
open import Data.Nat
import Data.Unit as U
open import Data.Product
open import Data.Sum
open import Relation.Binary.PropositionalEquality as PropEq
open import Relation.Nullary.Core
import Data.String as Str
open import Data.Nat.Show
import Data.List as List
open import Data.Empty
infix 3 _:::_,_
infix 2 _∈_
infix 1 _⊢_
data `Set : Set where
`Nat : `Set
`Bool : `Set
`_⇨_ : `Set → `Set → `Set
`Unit : `Set
`_×_ : `Set → `Set → `Set
`_+_ : `Set → `Set → `Set
#_ : `Set → Set
# `Nat = ℕ
# `Bool = Bool
# (` t ⇨ s) = # t → # s
# `Unit = U.Unit
# (` t × s) = # t × # s
# (` t + s) = # t ⊎ # s
data Γ : Set where
· : Γ
_:::_,_ : Char → `Set → Γ → Γ
data _∈_ : Char → Γ → Set where
H : ∀ {x Δ t } → x ∈ x ::: t , Δ
TH : ∀ {x y Δ t } → {{prf : x ∈ Δ}} → x ∈ y ::: t , Δ
!Γ_[_] : ∀ {x} → (Δ : Γ) → x ∈ Δ → `Set
!Γ_[_] · ()
!Γ _ ::: t , Δ [ H ] = t
!Γ _ ::: _ , Δ [ TH {{prf = i}} ] = !Γ Δ [ i ]
data _⊢_ : Γ → `Set → Set where
`false : ∀ {Δ} → Δ ⊢ `Bool
`true : ∀ {Δ} → Δ ⊢ `Bool
`n_ : ∀ {Δ} → ℕ → Δ ⊢ `Nat
`v_ : ∀ {Δ} → (x : Char) → {{i : x ∈ Δ}} → Δ ⊢ !Γ Δ [ i ]
`_₋_ : ∀ {Δ t s} → Δ ⊢ ` t ⇨ s → Δ ⊢ t → Δ ⊢ s
`λ_`:_⇨_ : ∀ {Δ tr} → (x : Char) → (tx : `Set)
→ x ::: tx , Δ ⊢ tr → Δ ⊢ ` tx ⇨ tr
`_+_ : ∀ {Δ} → Δ ⊢ `Nat → Δ ⊢ `Nat → Δ ⊢ `Nat
`_*_ : ∀ {Δ} → Δ ⊢ `Nat → Δ ⊢ `Nat → Δ ⊢ `Nat
`_∧_ : ∀ {Δ} → Δ ⊢ `Bool → Δ ⊢ `Bool → Δ ⊢ `Bool
`_∨_ : ∀ {Δ} → Δ ⊢ `Bool → Δ ⊢ `Bool → Δ ⊢ `Bool
`_≤_ : ∀ {Δ} → Δ ⊢ `Nat → Δ ⊢ `Nat → Δ ⊢ `Bool
`¬_ : ∀ {Δ} → Δ ⊢ `Bool → Δ ⊢ `Bool
`_,_ : ∀ {Δ t s} → Δ ⊢ t → Δ ⊢ s → Δ ⊢ ` t × s
`fst : ∀ {Δ t s} → Δ ⊢ ` t × s → Δ ⊢ t
`snd : ∀ {Δ t s} → Δ ⊢ ` t × s → Δ ⊢ s
`left : ∀ {Δ t s} → Δ ⊢ t → Δ ⊢ ` t + s
`right : ∀ {Δ t s} → Δ ⊢ s → Δ ⊢ ` t + s
`case_`of_||_ : ∀ {Δ t s u} → Δ ⊢ ` t + s
→ Δ ⊢ ` t ⇨ u → Δ ⊢ ` s ⇨ u → Δ ⊢ u
`tt : ∀ {Δ} → Δ ⊢ `Unit
`let_`=_`in_ : ∀ {Δ th tb} → (x : Char)
→ Δ ⊢ th → x ::: th , Δ ⊢ tb → Δ ⊢ tb
`if_`then_`else_ : ∀ {Δ t} → Δ ⊢ `Bool → Δ ⊢ t → Δ ⊢ t → Δ ⊢ t
data ⟨_⟩ : Γ → Set₁ where
[] : ⟨ · ⟩
_∷_ : ∀ {x t Δ} → # t → ⟨ Δ ⟩ → ⟨ x ::: t , Δ ⟩
!_[_] : ∀ {x Δ} → ⟨ Δ ⟩ → (i : x ∈ Δ) → # !Γ Δ [ i ]
!_[_] [] ()
!_[_] (val ∷ env) H = val
!_[_] (val ∷ env) (TH {{prf = i}}) = ! env [ i ]
interpret : ∀ {t} → · ⊢ t → # t
interpret = interpret' []
where interpret' : ∀ {Δ t} → ⟨ Δ ⟩ → Δ ⊢ t → # t
interpret' env `true = true
interpret' env `false = false
interpret' env `tt = U.unit
interpret' env (`n n) = n
interpret' env ((`v x) {{i = idx}}) = ! env [ idx ]
interpret' env (` f ₋ x) = (interpret' env f) (interpret' env x)
interpret' env (`λ _ `: tx ⇨ body) = λ (x : # tx) → interpret' (x ∷ env) body
interpret' env (` l + r) = interpret' env l + interpret' env r
interpret' env (` l * r) = interpret' env l * interpret' env r
interpret' env (` l ∧ r) = interpret' env l ∧ interpret' env r
interpret' env (` l ∨ r) = interpret' env l ∨ interpret' env r
interpret' env (` l ≤ r) with interpret' env l ≤? interpret' env r
interpret' env (` l ≤ r) | yes p = true
interpret' env (` l ≤ r) | no ¬p = false
interpret' env (`¬ x) = not (interpret' env x)
interpret' env (` f , s) = interpret' env f ,′ interpret' env s
interpret' env (`fst p) with interpret' env p
interpret' env (`fst p) | f , s = f
interpret' env (`snd p) with interpret' env p
interpret' env (`snd p) | f , s = s
interpret' env (`left v) = inj₁ (interpret' env v)
interpret' env (`right v) = inj₂ (interpret' env v)
interpret' env (`case s `of le || re) with interpret' env s
interpret' env (`case s `of le || re) | inj₁ l = (interpret' env le) l
interpret' env (`case s `of le || re) | inj₂ r = (interpret' env re) r
interpret' env (`let _ `= h `in b) = let hval = interpret' env h in interpret' (hval ∷ env) b
interpret' env (`if b `then et `else ef) with interpret' env b
interpret' env (`if b `then et `else ef) | true = interpret' env et
interpret' env (`if b `then et `else ef) | false = interpret' env ef
testSimpleLambda : · ⊢ `Nat
testSimpleLambda = ` (`λ 'x' `: `Nat ⇨ ` `v 'x' + `v 'x') ₋ `n 10
testNestedLambda : · ⊢ `Nat
testNestedLambda = ` ` (`λ 'x' `: `Nat ⇨ (`λ 'y' `: `Nat ⇨ ` `v 'x' * `v 'y')) ₋ `n 10 ₋ `n 15
-- Should not work because the inner x is not bound to a boolean, and it should not be possible to refer to the outside x using Elem
-- TODO Fix this to not work with instance search
--testNamingNotWorking : · ⊢ `Bool
--testNamingNotWorking = ` ` `λ 'x' `: `Bool ⇨ (`λ 'x' `: `Unit ⇨ `v 'x') ₋ `true ₋ `tt
testNamingWorking : · ⊢ `Unit
testNamingWorking = ` ` `λ 'x' `: `Bool ⇨ (`λ 'x' `: `Unit ⇨ `v 'x') ₋ `true ₋ `tt
testSum1 : · ⊢ `Nat
testSum1 = `let 'n' `= `case `left (`n 10) `of
`λ 'n' `: `Nat ⇨ `v 'n'
|| `λ 'b' `: `Bool ⇨ `if `v 'b' `then `n 1 `else `n 0
`in `v 'n'
testSum2 : · ⊢ `Nat
testSum2 = `let 'n' `= `case `right `true `of
`λ 'n' `: `Nat ⇨ `v 'n'
|| `λ 'b' `: `Bool ⇨ `if `v 'b' `then `n 1 `else `n 0
`in `v 'n'
testProduct1 : · ⊢ `Bool
testProduct1 = `fst (` `true , (` `n 10 , `tt ))
testProduct2 : · ⊢ ` `Nat × `Unit
testProduct2 = `snd (` `true , (` `n 10 , `tt ))
testDeMorganFullOr : · ⊢ `Bool
testDeMorganFullOr = `let 's' `= `λ 'x' `: `Bool ⇨ `λ 'y' `: `Bool ⇨ `¬ (` `v 'x' ∨ `v 'y')
`in ` ` `v 's'₋ `true ₋ `true
testDeMorganBrokenAnd : · ⊢ `Bool
testDeMorganBrokenAnd = `let 's' `= `λ 'x' `: `Bool ⇨ `λ 'y' `: `Bool ⇨ ` `¬ `v 'x' ∧ `¬ `v 'y'
`in ` ` `v 's' ₋ `true ₋ `true
| {
"alphanum_fraction": 0.4415542188,
"avg_line_length": 39.6838709677,
"ext": "agda",
"hexsha": "8e0f3624168ba756abde0dbf262b314b819b17d4",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-04-20T01:22:35.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-08-22T10:30:57.000Z",
"max_forks_repo_head_hexsha": "e4529eb03a0a48f800a5fd2a36047195f1949ca9",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ahmadsalim/well-typed-agda-interpreter",
"max_forks_repo_path": "Interpreter.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e4529eb03a0a48f800a5fd2a36047195f1949ca9",
"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": "ahmadsalim/well-typed-agda-interpreter",
"max_issues_repo_path": "Interpreter.agda",
"max_line_length": 132,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "e4529eb03a0a48f800a5fd2a36047195f1949ca9",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ahmadsalim/well-typed-agda-interpreter",
"max_stars_repo_path": "Interpreter.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-16T00:52:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-31T21:18:56.000Z",
"num_tokens": 2472,
"size": 6151
} |
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.PropositionalEquality.Subst.Properties where
-- Properties of 'subst' onto binary relations.
open import Level
open import Function using (_$_; flip) renaming (id to idFun; _∘_ to _⊚_)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
private
variable
ℓ ℓ₁ ℓ₂ t t₁ t₂ o : Level
-- Two shorthands: transport the domain or codomain of a relation along an equality.
module Shorthands {O : Set o} (R : Rel O ℓ) where
infixr 9 _◂_
infixl 9 _▸_
_◂_ : ∀ {A B C} → A ≡ B → R B C → R A C
p ◂ f = subst (flip R _) (sym p) f
_▸_ : ∀ {A B C} → R A B → B ≡ C → R A C
f ▸ p = subst (R _) p f
-- Some simple properties of transports
module Transport {O : Set o} (R : Rel O ℓ) where
open Shorthands R public
◂-▸-id : ∀ {A} (f : R A A) → refl ◂ f ≡ f ▸ refl
◂-▸-id f = refl
◂-▸-comm : ∀ {A B C D} (p : A ≡ B) (f : R B C) (q : C ≡ D) →
(p ◂ (f ▸ q)) ≡ ((p ◂ f) ▸ q)
◂-▸-comm refl f refl = refl
◂-assocˡ : ∀ {A B C D} (p : A ≡ B) {q : B ≡ C} (f : R C D) →
p ◂ q ◂ f ≡ (trans p q) ◂ f
◂-assocˡ refl {refl} f = refl
▸-assocʳ : ∀ {A B C D} (f : R A B) {p : B ≡ C} (q : C ≡ D) →
f ▸ p ▸ q ≡ f ▸ trans p q
▸-assocʳ f {refl} refl = refl
-- If we have a relation Q over a relation R, we can transport over that too
module TransportOverQ {O : Set o} (R : Rel O ℓ) (Q : {X Y : O} → Rel (R X Y) t) where
open Transport R
◂-resp-≈ : ∀ {A B C} (p : A ≡ B) {f g : R B C} → Q f g → Q (p ◂ f) (p ◂ g)
◂-resp-≈ refl f≈g = f≈g
▸-resp-≈ : ∀ {A B C} {f g : R A B} → Q f g → (p : B ≡ C) → Q (f ▸ p) (g ▸ p)
▸-resp-≈ f≈g refl = f≈g
-- Given two relations and a homomorphism between them,
-- congruence properties over subst
module TransportMor {O₁ O₂ : Set o}
(R₁ : Rel O₁ ℓ) (R₂ : Rel O₂ t)
(M₀ : O₁ → O₂)
(M₁ : ∀ {A B} → R₁ A B → R₂ (M₀ A) (M₀ B)) where
open Shorthands R₁
open Shorthands R₂ renaming (_◂_ to _◃_; _▸_ to _▹_)
M-resp-▸ : ∀ {A B C} (f : R₁ A B) (p : B ≡ C) →
M₁ (f ▸ p) ≡ M₁ f ▹ cong M₀ p
M-resp-▸ f refl = refl
M-resp-◂ : ∀ {A B C} (p : A ≡ B) (f : R₁ B C) →
M₁ (p ◂ f) ≡ cong M₀ p ◃ M₁ f
M-resp-◂ refl f = refl
-- Transports on paths
module TransportStar {O : Set o} (R : Rel O ℓ) where
open Shorthands (Star R) public renaming
( _◂_ to _◂*_
; _▸_ to _▸*_
)
open Shorthands R
-- Lemmas relating transports to path operations.
◂*-▸*-ε : {A B : O} (p : A ≡ B) → ε ▸* p ≡ p ◂* ε
◂*-▸*-ε refl = refl
◂*-◅ : {A B C D : O} (p : A ≡ B) (f : R B C) (fs : Star R C D) →
p ◂* (f ◅ fs) ≡ (p ◂ f) ◅ fs
◂*-◅ refl f fs = refl
◅-▸* : {A B C D : O} (f : R A B) (fs : Star R B C) (p : C ≡ D) →
(f ◅ fs) ▸* p ≡ f ◅ (fs ▸* p)
◅-▸* f fs refl = refl
◅-◂*-▸ : {A B C D : O} (f : R A B) (p : B ≡ C) (fs : Star R C D) →
_≡_ {_} {Star R A D} (f ◅ (p ◂* fs)) ((f ▸ p) ◅ fs)
◅-◂*-▸ f refl fs = refl
| {
"alphanum_fraction": 0.5057660626,
"avg_line_length": 30.35,
"ext": "agda",
"hexsha": "629586589c0923fb7ba8a1c91d49f09685892d98",
"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/Relation/Binary/PropositionalEquality/Subst/Properties.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/Relation/Binary/PropositionalEquality/Subst/Properties.agda",
"max_line_length": 86,
"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/Relation/Binary/PropositionalEquality/Subst/Properties.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": 1388,
"size": 3035
} |
{-# OPTIONS --cubical #-}
module Computability.Enumeration.Univalence where
open import Cubical.Core.Everything
open import Computability.Prelude
open import Computability.Enumeration.Base
| {
"alphanum_fraction": 0.8186528497,
"avg_line_length": 19.3,
"ext": "agda",
"hexsha": "a1e2e612b5adc766d4a2f89f475492fe50b53b5a",
"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": "1b5cf338eb0adb90c1897383e05251ddd954efff",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jesyspa/computability-in-agda",
"max_forks_repo_path": "Computability/Enumeration/Univalence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b5cf338eb0adb90c1897383e05251ddd954efff",
"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": "jesyspa/computability-in-agda",
"max_issues_repo_path": "Computability/Enumeration/Univalence.agda",
"max_line_length": 49,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "1b5cf338eb0adb90c1897383e05251ddd954efff",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jesyspa/computability-in-agda",
"max_stars_repo_path": "Computability/Enumeration/Univalence.agda",
"max_stars_repo_stars_event_max_datetime": "2021-04-30T11:15:51.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-19T15:51:22.000Z",
"num_tokens": 40,
"size": 193
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of the sublist relation over setoid equality.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary hiding (Decidable)
module Data.List.Relation.Binary.Subset.Propositional.Properties
where
open import Category.Monad
open import Data.Bool.Base using (Bool; true; false; T)
open import Data.List
open import Data.List.Relation.Unary.Any using (Any; here; there)
open import Data.List.Relation.Unary.Any.Properties
open import Data.List.Categorical
open import Data.List.Membership.Propositional
open import Data.List.Membership.Propositional.Properties
import Data.List.Relation.Binary.Subset.Setoid.Properties as Setoidₚ
open import Data.List.Relation.Binary.Subset.Propositional
import Data.Product as Prod
import Data.Sum as Sum
open import Function using (_∘_; _∘′_; id; _$_)
open import Function.Equality using (_⟨$⟩_)
open import Function.Inverse as Inv using (_↔_; module Inverse)
open import Function.Equivalence using (module Equivalence)
open import Relation.Nullary using (¬_; yes; no)
open import Relation.Unary using (Decidable)
open import Relation.Binary using (_⇒_)
open import Relation.Binary.PropositionalEquality
using (_≡_; _≗_; isEquivalence; refl; setoid; module ≡-Reasoning)
import Relation.Binary.PreorderReasoning as PreorderReasoning
private
open module ListMonad {ℓ} = RawMonad (monad {ℓ = ℓ})
------------------------------------------------------------------------
-- Relational properties
module _ {a} {A : Set a} where
⊆-reflexive : _≡_ ⇒ (_⊆_ {A = A})
⊆-reflexive refl = id
⊆-refl : Reflexive {A = List A} _⊆_
⊆-refl x∈xs = x∈xs
⊆-trans : Transitive {A = List A} (_⊆_ {A = A})
⊆-trans xs⊆ys ys⊆zs x∈xs = ys⊆zs (xs⊆ys x∈xs)
module _ {a} (A : Set a) where
⊆-isPreorder : IsPreorder {A = List A} _≡_ _⊆_
⊆-isPreorder = record
{ isEquivalence = isEquivalence
; reflexive = ⊆-reflexive
; trans = ⊆-trans
}
⊆-preorder : Preorder _ _ _
⊆-preorder = record
{ isPreorder = ⊆-isPreorder
}
------------------------------------------------------------------------
-- Reasoning over subsets
module ⊆-Reasoning {a} (A : Set a) where
open Setoidₚ.⊆-Reasoning (setoid A) public
hiding (_≋⟨_⟩_; _≋˘⟨_⟩_; _≋⟨⟩_)
------------------------------------------------------------------------
-- Properties relating _⊆_ to various list functions
------------------------------------------------------------------------
-- Any
module _ {a p} {A : Set a} {P : A → Set p} {xs ys : List A} where
mono : xs ⊆ ys → Any P xs → Any P ys
mono xs⊆ys =
_⟨$⟩_ (Inverse.to Any↔) ∘′
Prod.map id (Prod.map xs⊆ys id) ∘
_⟨$⟩_ (Inverse.from Any↔)
------------------------------------------------------------------------
-- map
module _ {a b} {A : Set a} {B : Set b} (f : A → B) {xs ys} where
map-mono : xs ⊆ ys → map f xs ⊆ map f ys
map-mono xs⊆ys =
_⟨$⟩_ (Inverse.to (map-∈↔ f)) ∘
Prod.map id (Prod.map xs⊆ys id) ∘
_⟨$⟩_ (Inverse.from (map-∈↔ f))
------------------------------------------------------------------------
-- _++_
module _ {a} {A : Set a} {xs₁ xs₂ ys₁ ys₂ : List A} where
_++-mono_ : xs₁ ⊆ ys₁ → xs₂ ⊆ ys₂ → xs₁ ++ xs₂ ⊆ ys₁ ++ ys₂
_++-mono_ xs₁⊆ys₁ xs₂⊆ys₂ =
_⟨$⟩_ (Inverse.to ++↔) ∘
Sum.map xs₁⊆ys₁ xs₂⊆ys₂ ∘
_⟨$⟩_ (Inverse.from ++↔)
------------------------------------------------------------------------
-- concat
module _ {a} {A : Set a} {xss yss : List (List A)} where
concat-mono : xss ⊆ yss → concat xss ⊆ concat yss
concat-mono xss⊆yss =
_⟨$⟩_ (Inverse.to $ concat-∈↔ {a = a}) ∘
Prod.map id (Prod.map id xss⊆yss) ∘
_⟨$⟩_ (Inverse.from $ concat-∈↔ {a = a})
------------------------------------------------------------------------
-- _>>=_
module _ {ℓ} {A B : Set ℓ} (f g : A → List B) {xs ys} where
>>=-mono : xs ⊆ ys → (∀ {x} → f x ⊆ g x) → (xs >>= f) ⊆ (ys >>= g)
>>=-mono xs⊆ys f⊆g =
_⟨$⟩_ (Inverse.to $ >>=-∈↔ {ℓ = ℓ}) ∘
Prod.map id (Prod.map xs⊆ys f⊆g) ∘
_⟨$⟩_ (Inverse.from $ >>=-∈↔ {ℓ = ℓ})
------------------------------------------------------------------------
-- _⊛_
module _ {ℓ} {A B : Set ℓ} {fs gs : List (A → B)} {xs ys : List A} where
_⊛-mono_ : fs ⊆ gs → xs ⊆ ys → (fs ⊛ xs) ⊆ (gs ⊛ ys)
_⊛-mono_ fs⊆gs xs⊆ys =
_⟨$⟩_ (Inverse.to $ ⊛-∈↔ gs) ∘
Prod.map id (Prod.map id (Prod.map fs⊆gs (Prod.map xs⊆ys id))) ∘
_⟨$⟩_ (Inverse.from $ ⊛-∈↔ fs)
------------------------------------------------------------------------
-- _⊗_
module _ {ℓ} {A B : Set ℓ} {xs₁ ys₁ : List A} {xs₂ ys₂ : List B} where
_⊗-mono_ : xs₁ ⊆ ys₁ → xs₂ ⊆ ys₂ → (xs₁ ⊗ xs₂) ⊆ (ys₁ ⊗ ys₂)
xs₁⊆ys₁ ⊗-mono xs₂⊆ys₂ =
_⟨$⟩_ (Inverse.to $ ⊗-∈↔ {ℓ = ℓ}) ∘
Prod.map xs₁⊆ys₁ xs₂⊆ys₂ ∘
_⟨$⟩_ (Inverse.from $ ⊗-∈↔ {ℓ = ℓ})
------------------------------------------------------------------------
-- any
module _ {a} {A : Set a} (p : A → Bool) {xs ys} where
any-mono : xs ⊆ ys → T (any p xs) → T (any p ys)
any-mono xs⊆ys =
_⟨$⟩_ (Equivalence.to any⇔) ∘
mono xs⊆ys ∘
_⟨$⟩_ (Equivalence.from any⇔)
------------------------------------------------------------------------
-- map-with-∈
module _ {a b} {A : Set a} {B : Set b}
{xs : List A} {f : ∀ {x} → x ∈ xs → B}
{ys : List A} {g : ∀ {x} → x ∈ ys → B} where
map-with-∈-mono : (xs⊆ys : xs ⊆ ys) → (∀ {x} → f {x} ≗ g ∘ xs⊆ys) →
map-with-∈ xs f ⊆ map-with-∈ ys g
map-with-∈-mono xs⊆ys f≈g {x} =
_⟨$⟩_ (Inverse.to map-with-∈↔) ∘
Prod.map id (Prod.map xs⊆ys (λ {x∈xs} x≡fx∈xs → begin
x ≡⟨ x≡fx∈xs ⟩
f x∈xs ≡⟨ f≈g x∈xs ⟩
g (xs⊆ys x∈xs) ∎)) ∘
_⟨$⟩_ (Inverse.from map-with-∈↔)
where open ≡-Reasoning
------------------------------------------------------------------------
-- filter
module _ {a p} {A : Set a} {P : A → Set p} (P? : Decidable P) where
filter⁺ : ∀ xs → filter P? xs ⊆ xs
filter⁺ = Setoidₚ.filter⁺ (setoid A) P?
------------------------------------------------------------------------
-- DEPRECATED
------------------------------------------------------------------------
-- Version 0.16
boolFilter-⊆ : ∀ {a} {A : Set a} (p : A → Bool) →
(xs : List A) → boolFilter p xs ⊆ xs
boolFilter-⊆ _ [] = λ ()
boolFilter-⊆ p (x ∷ xs) with p x | boolFilter-⊆ p xs
... | false | hyp = there ∘ hyp
... | true | hyp =
λ { (here eq) → here eq
; (there ∈boolFilter) → there (hyp ∈boolFilter)
}
{-# WARNING_ON_USAGE boolFilter-⊆
"Warning: boolFilter was deprecated in v0.15.
Please use filter instead."
#-}
| {
"alphanum_fraction": 0.4715519809,
"avg_line_length": 31.8199052133,
"ext": "agda",
"hexsha": "bc185bb0e5c5ff2a8819e4a7ea35cdb224e873c0",
"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": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Subset/Propositional/Properties.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/Data/List/Relation/Binary/Subset/Propositional/Properties.agda",
"max_line_length": 72,
"max_stars_count": null,
"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/Data/List/Relation/Binary/Subset/Propositional/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2341,
"size": 6714
} |
{-# OPTIONS --cubical --prop #-}
module Issue2487.Infective where
| {
"alphanum_fraction": 0.7014925373,
"avg_line_length": 16.75,
"ext": "agda",
"hexsha": "5209f31731741dbaca5638114dc572dc7d23cf22",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.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/Issue2487/Infective.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue2487/Infective.agda",
"max_line_length": 32,
"max_stars_count": 2,
"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/Issue2487/Infective.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 18,
"size": 67
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- An equality postulate which evaluates
------------------------------------------------------------------------
{-# OPTIONS --with-K #-}
module Relation.Binary.PropositionalEquality.TrustMe where
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl)
open import Agda.Builtin.TrustMe
-- trustMe {x = x} {y = y} evaluates to refl if x and y are
-- definitionally equal.
trustMe : ∀ {a} {A : Set a} {x y : A} → x ≡ y
trustMe = primTrustMe
-- "Erases" a proof. The original proof is not inspected. The
-- resulting proof reduces to refl if the two sides are definitionally
-- equal. Note that checking for definitional equality can be slow.
erase : ∀ {a} {A : Set a} {x y : A} → x ≡ y → x ≡ y
erase _ = trustMe
-- A "postulate with a reduction": postulate[ a ↦ b ] a evaluates to b,
-- while postulate[ a ↦ b ] a' gets stuck if a' is not definitionally
-- equal to a. This can be used to define a postulate of type (x : A) → B x
-- by only specifying the behaviour at B t for some t : A. Introduced in
--
-- Alan Jeffrey, Univalence via Agda's primTrustMe again
-- 23 January 2015
-- https://lists.chalmers.se/pipermail/agda/2015/007418.html
postulate[_↦_] : ∀ {a b} {A : Set a}{B : A → Set b} →
(t : A) → B t → (x : A) → B x
postulate[ a ↦ b ] a' with trustMe {x = a} {a'}
postulate[ a ↦ b ] .a | refl = b
------------------------------------------------------------------------
-- DEPRECATION
------------------------------------------------------------------------
-- Version 0.18
{-# WARNING_ON_USAGE erase
"Warning: erase was deprecated in v0.18.
Please use the safe function ≡-erase defined in Relation.Binary.PropositionalEquality.WithK instead."
#-}
| {
"alphanum_fraction": 0.5616061606,
"avg_line_length": 34.3018867925,
"ext": "agda",
"hexsha": "df210fc3303199b3d4d56c18f383cf420b217dd2",
"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/Relation/Binary/PropositionalEquality/TrustMe.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/Relation/Binary/PropositionalEquality/TrustMe.agda",
"max_line_length": 101,
"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/Relation/Binary/PropositionalEquality/TrustMe.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": 478,
"size": 1818
} |
module Issue237 where
open import Common.Equality
data Unit : Set where
unit : Unit
f : Unit → Unit
f u with u
... | unit = unit
postulate
eq : ∀ u → f u ≡ unit
foo : Unit → Set₁
foo u rewrite eq u = Set
-- Bug.agda:20,1-25
-- Not implemented: type checking of with application
-- when checking that the expression f u | u has type _35 u
| {
"alphanum_fraction": 0.6733524355,
"avg_line_length": 15.8636363636,
"ext": "agda",
"hexsha": "68dfbfc6021dfccfdba5fe02079b65c6f1f6343e",
"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/Issue237.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/Issue237.agda",
"max_line_length": 59,
"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/Issue237.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": 349
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Monoid where
open import Cubical.Algebra.Monoid.Base public
| {
"alphanum_fraction": 0.7555555556,
"avg_line_length": 27,
"ext": "agda",
"hexsha": "27c64dfaf92cb7b67237958e7615ab67d8920e52",
"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": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Algebra/Monoid.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/Algebra/Monoid.agda",
"max_line_length": 50,
"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/Algebra/Monoid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 34,
"size": 135
} |
-- {-# OPTIONS -v reify:100 -v syntax.reify:100 #-}
module Issue857b where
data ⊥ : Set where
⊥-elim : {A : Set} → ⊥ → A
⊥-elim ()
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
_∋_ : (A : Set) → A → A
_ ∋ x = x
foo : {A B : Set} {x : ⊥} {y : B} →
((⊥ → A) ∋ λ()) x ≡ ((⊥ → B → A) ∋ λ()) x y
foo = refl
-- WAS: An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/TypeChecking/Conversion.hs:514
bar : {A B C : Set} {x : ⊥} {y : B} {z : C} →
((⊥ → B → A) ∋ λ()) x y ≡ ((⊥ → C → A) ∋ λ()) x z
bar = refl
-- WAS:
-- .y != .z of type .B
-- when checking that the expression refl has type
-- ((⊥ → .B → .A) ∋ .Test.absurdLambda) .x .y ≡
-- ((⊥ → .C → .A) ∋ .Test.absurdLambda) .x .z
-- Note that z has type C, not B.
baz : {A : Set} → _≡_ {A = ⊥ → A} ⊥-elim (λ())
baz = refl
-- WAS: An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/TypeChecking/Conversion.hs:51
-- ERROR: ⊥-elim x != (λ ()) x of type .A
-- when checking that the expression refl has type ⊥-elim ≡ (λ ())
| {
"alphanum_fraction": 0.5299455535,
"avg_line_length": 26.2380952381,
"ext": "agda",
"hexsha": "24766bf50d2b8401b65062f191c532f8821d3ddf",
"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/Issue857b.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/Issue857b.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/Fail/Issue857b.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": 453,
"size": 1102
} |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.Monoid.Instances.NatPlusBis where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat
open import Cubical.Algebra.Monoid
open PlusBis
NatPlusBis-Monoid : Monoid ℓ-zero
fst NatPlusBis-Monoid = ℕ
MonoidStr.ε (snd NatPlusBis-Monoid) = 0
MonoidStr._·_ (snd NatPlusBis-Monoid) = _+'_
MonoidStr.isMonoid (snd NatPlusBis-Monoid) = makeIsMonoid isSetℕ +'-assoc +'-rid +'-lid
| {
"alphanum_fraction": 0.7756410256,
"avg_line_length": 27.5294117647,
"ext": "agda",
"hexsha": "c98b5f8511c7ce03f4c2302ca6b95ed520f3cf93",
"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/Monoid/Instances/NatPlusBis.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/Monoid/Instances/NatPlusBis.agda",
"max_line_length": 87,
"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/Monoid/Instances/NatPlusBis.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 158,
"size": 468
} |
module Ints.Properties where
open import Ints
open import Equality
------------------------------------------------------------------------
-- internal stuffs
private
≡→≡ : ∀ {a b} → (+ a ≡ + b) → a ≡ b
≡→≡ refl = refl
≡→≡′ : ∀ {a b} → (-[1+ a ] ≡ -[1+ b ]) → a ≡ b
≡→≡′ refl = refl
≡←≡ : ∀ {a b} → a ≡ b → (+ a ≡ + b)
≡←≡ refl = refl
≡←≡′ : ∀ {a b} → a ≡ b → (-[1+ a ] ≡ -[1+ b ])
≡←≡′ refl = refl
------------------------------------------------------------------------
-- public aliases
eq-int-to-nat : ∀ {a b} → (+ a ≡ + b) → a ≡ b
eq-int-to-nat = ≡→≡
eq-neg-int-to-nat : ∀ {a b} → (-[1+ a ] ≡ -[1+ b ]) → a ≡ b
eq-neg-int-to-nat = ≡→≡′
eq-nat-to-int : ∀ {a b} → a ≡ b → (+ a ≡ + b)
eq-nat-to-int = ≡←≡
eq-neg-nat-to-int : ∀ {a b} → a ≡ b → (-[1+ a ] ≡ -[1+ b ])
eq-neg-nat-to-int = ≡←≡′
| {
"alphanum_fraction": 0.3308913309,
"avg_line_length": 22.75,
"ext": "agda",
"hexsha": "77a7154fb794fe9c38e9f70abe2e2b209f75768e",
"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": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ice1k/Theorems",
"max_forks_repo_path": "src/Ints/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ice1k/Theorems",
"max_issues_repo_path": "src/Ints/Properties.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7dc0ea4782a5ff960fe31bdcb8718ce478eaddbc",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ice1k/Theorems",
"max_stars_repo_path": "src/Ints/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-15T15:28:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-15T15:28:03.000Z",
"num_tokens": 360,
"size": 819
} |
{-# OPTIONS --no-universe-polymorphism #-}
module Issue202 where
open import Common.Level
open import Imports.Test
module Test2 {ℓ : Level} (F : Foo ℓ) where
-- Test2.agda:4,31-36
-- The metavariable _1 cannot depend on ℓ because it does not depend
-- on any variables
-- when checking that the expression Foo ℓ has type _1
-- The code is accepted if universe polymorphism is turned on in
-- Test2.agda.
| {
"alphanum_fraction": 0.7359413203,
"avg_line_length": 24.0588235294,
"ext": "agda",
"hexsha": "68ca5c8f92c9356cb844a19ba5fcd68c9606d723",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Fail/Issue202.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"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": "alhassy/agda",
"max_issues_repo_path": "test/Fail/Issue202.agda",
"max_line_length": 68,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Fail/Issue202.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 111,
"size": 409
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.CircleHSpace
open import homotopy.LoopSpaceCircle
open import homotopy.Pi2HSusp
open import homotopy.IterSuspensionStable
-- This summerizes all [πₙ Sⁿ]
module homotopy.PinSn where
private
π1S¹-iso-ℤ : πS 0 ⊙S¹ ≃ᴳ ℤ-group
π1S¹-iso-ℤ = ΩS¹-iso-ℤ ∘eᴳ unTrunc-iso ΩS¹-group-structure ΩS¹-is-set
private
πS-SphereS'-iso-ℤ : ∀ n → πS n (⊙Susp^ n ⊙S¹) ≃ᴳ ℤ-group
πS-SphereS'-iso-ℤ 0 = π1S¹-iso-ℤ
πS-SphereS'-iso-ℤ 1 =
πS 1 ⊙S²
≃ᴳ⟨ Pi2HSusp.π₂-Susp S¹-level S¹-conn ⊙S¹-hSpace ⟩
πS 0 ⊙S¹
≃ᴳ⟨ πS-SphereS'-iso-ℤ O ⟩
ℤ-group
≃ᴳ∎
πS-SphereS'-iso-ℤ (S (S n)) =
πS (S (S n)) (⊙Susp^ (S (S n)) ⊙S¹)
≃ᴳ⟨ Susp^StableSucc.stable ⊙S¹ S¹-conn
(S n) (S n) (≤-ap-S $ ≤-ap-S $ *2-increasing n) ⟩
πS (S n) (⊙Susp^ (S n) ⊙S¹)
≃ᴳ⟨ πS-SphereS'-iso-ℤ (S n) ⟩
ℤ-group
≃ᴳ∎
πS-SphereS-iso-ℤ : ∀ n → πS n (⊙Sphere (S n)) ≃ᴳ ℤ-group
πS-SphereS-iso-ℤ n = πS-SphereS'-iso-ℤ n
∘eᴳ πS-emap n (⊙Susp^-Susp-split-iso n ⊙S⁰)
| {
"alphanum_fraction": 0.5684870188,
"avg_line_length": 29.3947368421,
"ext": "agda",
"hexsha": "9bf8061456b36e73cab5a0a6a2b3dba538965948",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "theorems/homotopy/PinSn.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"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": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "theorems/homotopy/PinSn.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "theorems/homotopy/PinSn.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 571,
"size": 1117
} |
module InstanceArgumentsBraceSpaces where
postulate
A B : Set
test : {{a : A} } → B
| {
"alphanum_fraction": 0.6741573034,
"avg_line_length": 14.8333333333,
"ext": "agda",
"hexsha": "da35a3fa682b9b8430d044d13139e891846284ad",
"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/InstanceArgumentsBraceSpaces.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/InstanceArgumentsBraceSpaces.agda",
"max_line_length": 41,
"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/InstanceArgumentsBraceSpaces.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": 29,
"size": 89
} |
module Tactic.Nat.Subtract.Auto where
open import Prelude
open import Builtin.Reflection
open import Tactic.Reflection.Quote
open import Tactic.Reflection.Meta
open import Tactic.Nat.Reflect
open import Tactic.Nat.NF
open import Tactic.Nat.Auto
open import Tactic.Nat.Simpl.Lemmas
open import Tactic.Nat.Subtract.Exp
open import Tactic.Nat.Subtract.Reflect
open import Tactic.Nat.Subtract.Lemmas
open import Tactic.Nat.Less.Lemmas
autosub-proof : ∀ eqn ρ → Maybe (⟦ eqn ⟧eqn ρ)
autosub-proof (e₁ :≡ e₂) ρ with normSub e₁ == normSub e₂
autosub-proof (e₁ :≡ e₂) ρ | no _ = nothing
autosub-proof (e₁ :≡ e₂) ρ | yes eq = just (liftNFSubEq e₁ e₂ ρ (cong (λ n → ⟦ n ⟧sn ρ) eq))
autosub-proof (e₁ :< e₂) ρ with cancel (normSub e₁) (normSub e₂) | simplifySubLess e₁ e₂ ρ
autosub-proof (e₁ :< e₂) ρ | [] , (suc n , []) ∷ nf | simp =
let sk : SubNF
sk = (suc n , []) ∷ nf
k = ( n , []) ∷ nf in
just $ simp $ LessNat.diff (⟦ k ⟧sns ρ) $
ns-sound sk (atomEnvS ρ) ⟨≡⟩
auto ⟨≡⟩ʳ (λ z → suc (z + 0)) $≡ lem-eval-sns-nS k ρ
autosub-proof (e₁ :< e₂) ρ | _ , _ | simp = nothing
autosub-tactic : Type → TC Term
autosub-tactic t = do
ensureNoMetas t
just (eqn , Γ) ← termToSubEqn t
where nothing → typeError $ strErr "Invalid goal:" ∷ termErr t ∷ []
pure $
getProof (quote cantProve) t $
def (quote autosub-proof)
( vArg (` eqn)
∷ vArg (quotedEnv Γ)
∷ [] )
| {
"alphanum_fraction": 0.6416022488,
"avg_line_length": 33.0930232558,
"ext": "agda",
"hexsha": "c245aa48024a4a5cedc379b377d1592a6507edbb",
"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": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lclem/agda-prelude",
"max_forks_repo_path": "src/Tactic/Nat/Subtract/Auto.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"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": "lclem/agda-prelude",
"max_issues_repo_path": "src/Tactic/Nat/Subtract/Auto.agda",
"max_line_length": 92,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lclem/agda-prelude",
"max_stars_repo_path": "src/Tactic/Nat/Subtract/Auto.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 535,
"size": 1423
} |
{-# FOREIGN GHC import qualified Issue223 #-}
data A : Set
data B : Set
data A where
BA : B → A
data B where
AB : A → B
BB : B
{-# COMPILE GHC A = data Issue223.A (Issue223.BA) #-}
{-# COMPILE GHC B = data Issue223.B (Issue223.AB | Issue223.BB) #-}
| {
"alphanum_fraction": 0.61003861,
"avg_line_length": 17.2666666667,
"ext": "agda",
"hexsha": "a00e31a47e9720b70e50486b21e716f1a359f8f3",
"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/Issue223.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/Issue223.agda",
"max_line_length": 67,
"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/Issue223.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": 84,
"size": 259
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- de Bruijn-aware generic traversal of reflected terms.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Category.Applicative using (RawApplicative)
open import Category.Monad using (RawMonad)
module Leftovers.Everywhere {F : Set → Set} (MF : RawMonad F) where
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.List using (List; []; _∷_; _++_; reverse; length)
open import Data.Product using (_×_; _,_)
open import Data.String using (String)
open import Function using (_∘_)
open import Reflection
open RawMonad MF
------------------------------------------------------------------------
-- Context representation
-- Track both number of variables and actual context, to avoid having to
-- compute the length of the context everytime it's needed.
record Cxt : Set where
constructor _,,_
pattern
field
len : ℕ
context : List (String × Arg Term)
private
_∷cxt_ : String × Arg Term → Cxt → Cxt
e ∷cxt (n ,, Γ) = (suc n ,, (e ∷ Γ))
_++cxt_ : List (String × Arg Term) → Cxt → Cxt
es ++cxt (n ,, Γ) = ((length es + n) ,, (es ++ Γ))
------------------------------------------------------------------------
-- Actions
Action : Set → Set
Action A = Cxt → A → F A
-- A traversal gets to operate on variables, metas, and names.
record Actions : Set where
field
onVar : Action ℕ
onMeta : Action Meta
onCon : Action Name
onDef : Action Name
-- Default action: do nothing.
defaultActions : Actions
defaultActions .Actions.onVar _ = pure
defaultActions .Actions.onMeta _ = pure
defaultActions .Actions.onCon _ = pure
defaultActions .Actions.onDef _ = pure
------------------------------------------------------------------------
-- Traversal functions
private
module Params (actions : Actions) (everyAction : Action Term) where
open Actions actions
everywhereTerm : Action Term
everywhereTerm' : Action Term
everywhereSort : Action Sort
everywherePattern : Action Pattern
everywhereArgs : Action (List (Arg Term))
everywhereArg : Action (Arg Term)
everywherePats : Action (List (Arg Pattern))
everywhereAbs : Arg Term → Action (Abs Term)
everywhereClauses : Action Clauses
everywhereClause : Action Clause
everywhereTel : Action (List (String × Arg Term))
everywhereTerm Γ t = everyAction Γ =<< everywhereTerm' Γ t
everywhereTerm' Γ (var x args) = var <$> onVar Γ x ⊛ everywhereArgs Γ args
everywhereTerm' Γ (con c args) = con <$> onCon Γ c ⊛ everywhereArgs Γ args
everywhereTerm' Γ (def f args) = def <$> onDef Γ f ⊛ everywhereArgs Γ args
everywhereTerm' Γ (pat-lam cs args) = pat-lam <$> everywhereClauses Γ cs ⊛ everywhereArgs Γ args
everywhereTerm' Γ (pi a b) = pi <$> everywhereArg Γ a ⊛ everywhereAbs a Γ b
everywhereTerm' Γ (agda-sort s) = agda-sort <$> everywhereSort Γ s
everywhereTerm' Γ (meta x args) = meta <$> onMeta Γ x ⊛ everywhereArgs Γ args
everywhereTerm' Γ t@(lit _) = pure t
everywhereTerm' Γ t@unknown = pure t
everywhereTerm' Γ (lam v t) = lam v <$> everywhereAbs (arg (arg-info v m) unknown) Γ t
where
m = defaultModality
everywhereArg Γ (arg i t) = arg i <$> everywhereTerm Γ t
everywhereArgs Γ [] = pure []
everywhereArgs Γ (a ∷ as) = _∷_ <$> everywhereArg Γ a ⊛ everywhereArgs Γ as
everywhereAbs ty Γ (abs x t) = abs x <$> everywhereTerm ((x , ty) ∷cxt Γ) t
everywhereClauses Γ [] = pure []
everywhereClauses Γ (c ∷ cs) = _∷_ <$> everywhereClause Γ c ⊛ everywhereClauses Γ cs
everywhereClause Γ (Clause.clause tel ps t) =
Clause.clause <$> everywhereTel Γ tel
⊛ everywherePats Γ′ ps
⊛ everywhereTerm Γ′ t
where Γ′ = reverse tel ++cxt Γ
everywhereClause Γ (Clause.absurd-clause tel ps) =
Clause.absurd-clause <$> everywhereTel Γ tel
⊛ everywherePats Γ′ ps
where Γ′ = reverse tel ++cxt Γ
everywhereTel Γ [] = pure []
everywhereTel Γ ((x , ty) ∷ tel) =
_∷_ ∘ (x ,_) <$> everywhereArg Γ ty ⊛ everywhereTel ((x , ty) ∷cxt Γ) tel
everywhereSort Γ (Sort.set t) = Sort.set <$> everywhereTerm Γ t
everywhereSort Γ t@(Sort.lit _) = pure t
everywhereSort Γ (Sort.prop t) = Sort.prop <$> everywhereTerm Γ t
everywhereSort Γ t@(Sort.propLit _) = pure t
everywhereSort Γ t@(Sort.inf _) = pure t
everywhereSort Γ [email protected] = pure t
everywherePattern Γ (Pattern.con c ps) = Pattern.con <$> onCon Γ c ⊛ everywherePats Γ ps
everywherePattern Γ (Pattern.dot t) = Pattern.dot <$> everywhereTerm Γ t
everywherePattern Γ (Pattern.var x) = Pattern.var <$> onVar Γ x
everywherePattern Γ p@(Pattern.lit _) = pure p
everywherePattern Γ p@(Pattern.proj _) = pure p
everywherePattern Γ (Pattern.absurd x) = Pattern.absurd <$> onVar Γ x
everywherePats Γ [] = pure []
everywherePats Γ (arg i p ∷ ps) = _∷_ ∘ arg i <$> everywherePattern Γ p ⊛ everywherePats Γ ps
everywhere : (actions : Actions) → (everyAction : Action Term) → Term → F Term
everywhere actions every = Params.everywhereTerm actions every (0 ,, [])
| {
"alphanum_fraction": 0.6088014981,
"avg_line_length": 38.6956521739,
"ext": "agda",
"hexsha": "dab34e66866625608e525aa164f6e422613fee0f",
"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": "01b60b405009feaada181af175f019ceb89e42b2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "JoeyEremondi/AgdaLeftovers",
"max_forks_repo_path": "src/Leftovers/Everywhere.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "01b60b405009feaada181af175f019ceb89e42b2",
"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": "JoeyEremondi/AgdaLeftovers",
"max_issues_repo_path": "src/Leftovers/Everywhere.agda",
"max_line_length": 100,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "01b60b405009feaada181af175f019ceb89e42b2",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "JoeyEremondi/AgdaLeftovers",
"max_stars_repo_path": "src/Leftovers/Everywhere.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1414,
"size": 5340
} |
{-# OPTIONS --universe-polymorphism #-}
module Reflection where
open import Common.Prelude hiding (Unit; module Unit) renaming (Nat to ℕ; module Nat to ℕ)
open import Common.Reflection
open import Common.Equality
open import Agda.Builtin.TrustMe
data Id {A : Set}(x : A) : (B : Set) → B → Set where
course : Id x A x
open import Common.Level
set₀ : Type
set₀ = sort (lit 0)
unCheck : Term → Term
unCheck (def x (_ ∷ _ ∷ arg _ t ∷ [])) = t
unCheck t = unknown
infix 1 _is_of_
data Check {a}{A : Set a}(x : A) : Set where
_is_of_ : (t t′ : Term) →
Id (primTrustMe {x = unCheck t} {t′})
(t′ ≡ t′) refl → Check x
`Check : QName
`Check = quote Check
test₁ : Check ({A : Set} → A → A)
test₁ = quoteGoal t in
t is pi (hArg set₀) (abs "A" (pi (vArg (var 0 [])) (abs "_" (var 1 []))))
of course
test₂ : (X : Set) → Check (λ (x : X) → x)
test₂ X = quoteGoal t in
t is lam visible (abs "x" (var 0 [])) of course
infixr 5 _`∷_
pattern _`∷_ x xs = con (quote _∷_) (hArg unknown ∷ hArg unknown ∷ vArg x ∷ vArg xs ∷ [])
pattern `[] = con (quote []) (hArg unknown ∷ hArg unknown ∷ [])
pattern `true = con (quote true) []
pattern `false = con (quote false) []
test₃ : Check (true ∷ false ∷ [])
test₃ = quoteGoal t in
t is (`true `∷ `false `∷ `[]) of course
`List : Term → Term
`List A = def (quote List) (hArg (def (quote lzero) []) ∷ vArg A ∷ [])
`ℕ = def (quote ℕ) []
`Term : Term
`Term = def (quote Term) []
`Type : Term
`Type = def (quote Type) []
`Sort : Term
`Sort = def (quote Sort) []
test₄ : Check (List ℕ)
test₄ = quoteGoal t in
t is `List `ℕ of course
postulate
a : ℕ
test₁₄ : Check 1
test₁₄ = quoteGoal t in t is lit (nat 1) of course
record R : Set₁ where
field
A : Set
macro
RA : Term → TC _
RA goal = bindTC (getDefinition (quote R)) λ where
(recordDef _ (vArg A ∷ [])) → unify goal (def A [])
_ → typeError (strErr "Impossible" ∷ [])
test₁₅ : RA ≡ R.A
test₁₅ = refl
| {
"alphanum_fraction": 0.5799404171,
"avg_line_length": 23.9761904762,
"ext": "agda",
"hexsha": "5e4cd0be191ef54189b6fadb0f302b4a6697d737",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "hborum/agda",
"max_forks_repo_path": "test/Succeed/Reflection.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"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": "hborum/agda",
"max_issues_repo_path": "test/Succeed/Reflection.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Succeed/Reflection.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 710,
"size": 2014
} |
module Data.Real where
open import Data.Real.Base public
open import Data.Real.Order public
| {
"alphanum_fraction": 0.8085106383,
"avg_line_length": 15.6666666667,
"ext": "agda",
"hexsha": "b3c29944dab6d466fa615c66580cabc87a583cdf",
"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": "a193aeebf1326f960975b19d3e31b46fddbbfaa2",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "cspollard/reals",
"max_forks_repo_path": "src/Data/Real.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a193aeebf1326f960975b19d3e31b46fddbbfaa2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "cspollard/reals",
"max_issues_repo_path": "src/Data/Real.agda",
"max_line_length": 34,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a193aeebf1326f960975b19d3e31b46fddbbfaa2",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "cspollard/reals",
"max_stars_repo_path": "src/Data/Real.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 19,
"size": 94
} |
module MJ.Examples.While where
open import MJ.Examples.Integer
open import Prelude
open import MJ.Types
open import MJ.Classtable.Code Σ
open import MJ.Syntax Σ
open import MJ.Syntax.Program Σ
open import MJ.Semantics Σ Lib
open import MJ.Semantics.Values Σ
open import Data.List.Any
open import Data.List.Membership.Propositional
open import Data.Star
open import Data.Bool as Bools hiding (_≤?_)
open import Relation.Nullary.Decidable
-- a simple program that computes 10 using a while loop
p₁ : Prog int
p₁ = Lib ,
let
x = (here refl)
in body
(
loc int
◅ asgn x (num 1)
◅ while iop (λ x y → Bools.if ⌊ suc x ≤? y ⌋ then 0 else 1) (var x) (num 10) run (
asgn x (iop (λ x y → x + y) (var x) (num 1))
)
-- test simplest if-then-else and early return from statement
◅ if (num 0) then (ret (var x)) else (ret (num 0))
◅ ε
)
(num 0)
test1 : p₁ ⇓⟨ 100 ⟩ (λ {W} (v : Val W int) → v ≡ num 10)
test1 = refl
| {
"alphanum_fraction": 0.6475409836,
"avg_line_length": 25.6842105263,
"ext": "agda",
"hexsha": "8b3c6467bf4d83949c0e620a4951f02b1437a1db",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/MJ/Examples/While.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/MJ/Examples/While.agda",
"max_line_length": 88,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/MJ/Examples/While.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 327,
"size": 976
} |
{-# OPTIONS --cubical --safe #-}
module Function.Biconditional where
open import Level
open import Relation.Binary
open import Path as ≡ using (_;_; cong)
open import Function
infix 4 _↔_
record _↔_ {a b} (A : Type a) (B : Type b) : Type (a ℓ⊔ b) where
constructor _iff_
field
fun : A → B
inv : B → A
open _↔_ public
sym-↔ : (A ↔ B) → (B ↔ A)
fun (sym-↔ A↔B) = inv A↔B
inv (sym-↔ A↔B) = fun A↔B
refl-↔ : A ↔ A
fun refl-↔ = id
inv refl-↔ = id
trans-↔ : A ↔ B → B ↔ C → A ↔ C
fun (trans-↔ A↔B B↔C) = fun B↔C ∘ fun A↔B
inv (trans-↔ A↔B B↔C) = inv A↔B ∘ inv B↔C
| {
"alphanum_fraction": 0.5746527778,
"avg_line_length": 19.8620689655,
"ext": "agda",
"hexsha": "b7d9617eee7dcaa23b3975e3c642041059a564e2",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Function/Biconditional.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"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/combinatorics-paper",
"max_issues_repo_path": "agda/Function/Biconditional.agda",
"max_line_length": 64,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Function/Biconditional.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z",
"num_tokens": 267,
"size": 576
} |
module Reflexivity where
import PolyDepPrelude
open PolyDepPrelude using(Bool; True)
-- Local reflexivity
lref : {X : Set} -> (X -> X -> Bool) -> X -> Set
lref _R_ = \x -> True (x R x)
-- Reflexive = locally reflexive everywhere
data Refl {X : Set} (r : X -> X -> Bool) : Set where
refl : ((x : X) -> lref r x) -> Refl r
| {
"alphanum_fraction": 0.6146788991,
"avg_line_length": 23.3571428571,
"ext": "agda",
"hexsha": "890120f467507f71197ec36925e7ce94c02433f1",
"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": "examples/AIM5/PolyDep/Reflexivity.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": "examples/AIM5/PolyDep/Reflexivity.agda",
"max_line_length": 52,
"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": "examples/AIM5/PolyDep/Reflexivity.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": 111,
"size": 327
} |
{-# OPTIONS --type-in-type #-}
module Reactive where
open import Prelude
infixr 9 _∘ᵗ_ _∘ᵀ_ _∘ᵇ_ _∙_
infixl 9 _∘ʷ_
infix 4 _,ᵀ_ _,ᵗ_
infix 2 _×ᵀ_
-- Coinductive trees will represent protocols of interactions
record Tree : Set where
coinductive
field
Branch : Set
child : Branch → Tree
open Tree
constᵀ : Set → Tree
constᵀ A .Branch = A
constᵀ A .child _ = constᵀ A
_×ᵀ_ : Tree → Tree → Tree
(p ×ᵀ q) .Branch = p .Branch × q .Branch
(p ×ᵀ q) .child (ph , qh) = p .child ph ×ᵀ q .child qh
alter : Tree → Tree → Tree
alter p q .Branch = p .Branch
alter p q .child hp = alter q (p .child hp)
alter' = λ A B → alter (constᵀ A) (constᵀ B)
-- signals
Sig = λ A B → alter' (Maybe A) (Maybe B)
NoSig = Sig ⊥ ⊥
OutSig = λ A → Sig A ⊥
InSig = λ A → Sig ⊥ A
BiSig = λ A → Sig A A
{-
p: P₁ P₂ -> P₃ P₄ ...
| ^ | ^
v | v |
q: Q₁ -> Q₂ Q₃ -> Q₄ ...
-}
merge : Tree → Tree → Tree
merge p q .Branch = p .Branch
merge p q .child hp .Branch = q .Branch
merge p q .child hp .child hq = merge (q .child hq) (p .child hp)
union2 : Tree → Tree → Tree
union2 p q .Branch = p .Branch ⊎ q .Branch
union2 p q .child (inj₁ ph) with p .child ph
... | r = λ where .Branch → q .Branch
.child rh → union2 r (q .child rh)
union2 p q .child (inj₂ qh) with q .child qh
... | r = λ where .Branch → p .Branch
.child rh → union2 (p .child rh) r
-- TODO: express with simpler combinators?
union2mb : Tree → Tree → Tree
union2mb p q .Branch = Maybe (p .Branch ⊎ q .Branch)
union2mb p q .child (just (inj₁ ph)) with p .child ph
... | r = λ where .Branch → q .Branch
.child rh → union2mb r (q .child rh)
union2mb p q .child (just (inj₂ qh)) with q .child qh
... | r = λ where .Branch → p .Branch
.child rh → union2mb (p .child rh) r
union2mb p q .child nothing .Branch = ⊤
union2mb p q .child nothing .child _ = union2mb p q
-----------------------------
data I/O : Set where I O : I/O -- input and output phases
variable p q r s : Tree
variable i/o : I/O
opposite : I/O → I/O
opposite I = O
opposite O = I
ΠΣ : I/O → (A : Set) → (A → Set) → Set
ΠΣ I A P = (a : A) → P a
ΠΣ O A P = Σ A P
⟨_⟩ : I/O → (A → A → B) → A → A → B
⟨ I ⟩ = id
⟨ O ⟩ = flip
-- an interactive agent which communcates according to the protocol p
-- an agent can be called either in input or in output phase
record Agent (i/o : I/O) (p : Tree) : Set where
coinductive
field
step : ΠΣ i/o (p .Branch) λ a → Agent (opposite i/o) (p .child a)
open Agent
_,ᵀ_ : Agent i/o p → Agent i/o q → Agent i/o (p ×ᵀ q)
_,ᵀ_ {i/o = I} a b .step (k , l) = a .step k ,ᵀ b .step l
_,ᵀ_ {i/o = O} a b .step with a .step | b .step
... | i , j | k , l = (i , k) , (j ,ᵀ l)
_∘ᵗ_ : Agent I (alter p q) → Agent I (alter q r) → Agent I (alter p r)
(b ∘ᵗ a) .step ph .step with b .step ph .step
... | qh , bt with a .step qh .step
... | rh , at = rh , bt ∘ᵗ at
-- stream processors
SP = λ A B → Agent I (alter' A B)
-- same as Agent I (Sig A B)
SPM = λ A B → SP (Maybe A) (Maybe B)
arr : (A → B) → SP A B
arr f .step x .step = f x , arr f
accum : (A → B → B) → B → SP A B
accum f b .step a .step with f a b
... | b' = b' , accum f b'
maybefy : SP A B → SPM A B
maybefy f .step nothing .step = nothing , (maybefy f)
maybefy f .step (just a) .step with f .step a .step
... | x , y = just x , maybefy y
-- synchronous interaction transformers
IT = λ p q → Agent I (merge p q)
mapAgent : ⟨ i/o ⟩ IT q p → Agent i/o p → Agent i/o q
mapAgent {i/o = I} l i .step hq with l .step hq .step
... | a , l2 = mapAgent l2 (i .step a)
mapAgent {i/o = O} l i .step with i .step
... | a , b with l .step a .step
... | c , l2 = c , (mapAgent l2 b)
_∘ᵀ_ : IT p q → IT q r → IT p r
(b ∘ᵀ a) .step ph .step with b .step ph .step
... | qh , bt with a .step qh .step
... | rh , at = rh , at ∘ᵀ bt
_,ᵗ_ : IT p q → IT r s → IT (p ×ᵀ r) (q ×ᵀ s)
_,ᵗ_ a b .step (k , l) .step with a .step k .step | b .step l .step
... | c , d | e , f = (c , e) , (d ,ᵗ f)
idIT : IT p p
idIT .step a .step = a , idIT
swapIT : IT (p ×ᵀ q) (q ×ᵀ p)
swapIT .step (a , b) .step = (b , a) , swapIT
assocIT : ⟨ i/o ⟩ IT ((p ×ᵀ q) ×ᵀ r) (p ×ᵀ (q ×ᵀ r))
assocIT {i/o = I} .step ((a , b) , c) . step = (a , (b , c)) , assocIT {i/o = O}
assocIT {i/o = O} .step (a , (b , c)) . step = ((a , b) , c) , assocIT {i/o = I}
fstSig : IT (p ×ᵀ Sig A B) p
fstSig .step (x , y) .step = x , λ where .step x .step → (x , nothing) , fstSig
joinSig : A → B → ⟨ i/o ⟩ IT (⟨ i/o ⟩ Sig A C ×ᵀ ⟨ i/o ⟩ Sig B D) (⟨ i/o ⟩ Sig (A × B) (C × D))
joinSig {i/o = I} a b .step (nothing , nothing) .step = nothing , joinSig {i/o = O} a b
joinSig {i/o = I} a b .step (nothing , just y ) .step = just (a , y) , joinSig {i/o = O} a y
joinSig {i/o = I} a b .step (just x , nothing) .step = just (x , b) , joinSig {i/o = O} x b
joinSig {i/o = I} a b .step (just x , just y ) .step = just (x , y) , joinSig {i/o = O} x y
joinSig {i/o = O} a b .step nothing .step = (nothing , nothing) , joinSig {i/o = I} a b
joinSig {i/o = O} a b .step (just (x , y)) .step = (just x , just y ) , joinSig {i/o = I} a b
noInput : IT (Sig A B) (OutSig A)
noInput .step x .step = x , λ where .step y .step → nothing , noInput
noOutput : IT (Sig A B) (InSig B)
noOutput .step x .step = nothing , λ where .step y .step → y , noOutput
mkIT : Agent i/o p → ⟨ i/o ⟩ IT p NoSig
mkIT {i/o = I} a .step x .step = nothing , mkIT {i/o = O} (a .step x)
mkIT {i/o = O} a .step _ .step with a .step
... | b , c = b , mkIT {i/o = I} c
constIT = λ S T A B → IT (alter' S T) (alter' A B)
constITM = λ S T A B → IT (Sig S T) (Sig A B)
lensIT : Lens S T A B → constIT S T A B
lensIT k .step s .step with k s
... | a , bt = a , λ where .step b .step → bt b , lensIT k
prismIT : Prism S T A B → constITM S T A B
prismIT f = lensIT (prismToLens f)
mkIT' : SP S A → SP B T → constIT S T A B
mkIT' f g .step s .step with f .step s .step
... | a , cont = a , (mkIT' g cont)
isoIT : (S → A) → (B → T) → constIT S T A B
isoIT f g = lensIT λ x → (f x) , g
-- bidirectional connection
Bi = λ p q → Agent I (union2 p q)
_∘ᵇ_ : Bi p q → Bi q r → Bi p r
(a ∘ᵇ b) .step (inj₁ x) .step with a .step (inj₁ x) .step
... | c , d with b .step (inj₁ c) .step
... | e , f = e , d ∘ᵇ f
(a ∘ᵇ b) .step (inj₂ x) .step with b .step (inj₂ x) .step
... | c , d with a .step (inj₂ c) .step
... | e , f = e , f ∘ᵇ d
isoBi : Iso A A B B → Bi (constᵀ A) (constᵀ B)
isoBi i .step (inj₁ x) .step = (i .proj₁ x) , isoBi i
isoBi i .step (inj₂ x) .step = (i .proj₂ x) , isoBi i
mmb : Bi p q → Agent I (union2mb p q)
mmb x .step nothing .step = _ , mmb x
mmb x .step (just (inj₁ y)) .step with x .step (inj₁ y) .step
... | a , b = a , mmb b
mmb x .step (just (inj₂ y)) .step with x .step (inj₂ y) .step
... | a , b = a , mmb b
entangleBi : IT (Sig A A ×ᵀ Sig B B) (union2mb (constᵀ A) (constᵀ B))
entangleBi .step (nothing , nothing) .step = nothing , λ where .step _ .step → (nothing , nothing) , entangleBi
entangleBi .step (just x , nothing) .step = just (inj₁ x) , λ where .step z .step → (nothing , just z) , entangleBi
entangleBi .step (nothing , just x) .step = just (inj₂ x) , λ where .step z .step → (just z , nothing) , entangleBi
entangleBi .step (just x , just y) .step = nothing , λ where .step _ .step → (nothing , nothing) , entangleBi
entangle : IT (Sig A C ×ᵀ Sig C B) (Sig A B)
entangle .step (a , c) .step = a , λ where .step b .step → (c , b) , entangle
enta : SP A B → IT (Sig A C ×ᵀ Sig C B) NoSig
enta x = entangle ∘ᵀ mkIT (maybefy x)
entaBi : Bi (constᵀ A) (constᵀ B) → IT (Sig A A ×ᵀ Sig B B) NoSig
entaBi x = entangleBi ∘ᵀ mkIT (mmb x)
---------------------------------------------------------------------
data Direction : Set where horizontal vertical : Direction
data Abled : Set where enabled disabled : Abled
data Validity : Set where valid invalid : Validity
variable fin : Fin _
variable vec : Vec _ _
variable checked : Bool
variable size : ℕ
variable name str : String
variable en : Abled
variable dir : Direction
variable val : Validity
oppositeᵉ : Abled → Abled
oppositeᵉ enabled = disabled
oppositeᵉ disabled = enabled
oppositeᵛ : Validity → Validity
oppositeᵛ valid = invalid
oppositeᵛ invalid = valid
isEnabled : I/O → Abled → Set
isEnabled I enabled = ⊤
isEnabled I disabled = ⊥
isEnabled O _ = ⊤
-- abstract widget
data Widget : Set where
Button : Abled → String → Widget
CheckBox : Abled → Bool → Widget
ComboBox : Abled → Vec String n → Fin n → Widget
Entry : Abled → (size : ℕ)(name contents : String) → Validity → Widget
Label : String → Widget
Empty : Widget
Container : Direction → Widget → Widget → Widget
variable w w₁ w₂ : Widget
isInput : Widget → Maybe (Abled × Widget)
isInput (Button e x) = just (e , Button (oppositeᵉ e) x)
isInput (CheckBox e x) = just (e , CheckBox (oppositeᵉ e) x)
isInput (ComboBox e ss i) = just (e , ComboBox (oppositeᵉ e) ss i)
isInput (Entry e n s s' v) = just (e , Entry (oppositeᵉ e) n s s' v)
isInput _ = nothing
isJust : Maybe A → Set
isJust = maybe ⊥ (λ _ → ⊤)
-- possible edits of a widget (I: by the user; O: by the program)
data WidgetEdit : I/O → Widget → Set
-- ⟪_⟫ performs the edit
⟪_⟫ : {d : I/O} {a : Widget} (p : WidgetEdit d a) → Widget
data WidgetEdit where
toggle : {_ : isEnabled i/o en} → WidgetEdit i/o (CheckBox en checked)
click : WidgetEdit I (Button enabled str)
setLabel : String → WidgetEdit O (Label str)
setEntry : {_ : isEnabled i/o en} → String → WidgetEdit i/o (Entry en size name str val)
select : {vec : Vec String n}{_ : isEnabled i/o en} → Fin n → WidgetEdit i/o (ComboBox en vec fin)
toggleEnable : {_ : isJust (isInput w)} → WidgetEdit O w
toggleValidity : WidgetEdit O (Entry en size name str val)
replaceBy : Widget → WidgetEdit O w
modLeft : WidgetEdit i/o w₁ → WidgetEdit i/o (Container dir w₁ w₂)
modRight : WidgetEdit i/o w₂ → WidgetEdit i/o (Container dir w₁ w₂)
addToLeft addToRight : Direction → Widget → WidgetEdit O w
removeLeft removeRight : WidgetEdit O (Container dir w₁ w₂)
_∙_ : (p : WidgetEdit O w) → WidgetEdit O ⟪ p ⟫ → WidgetEdit O w
⟪ replaceBy x ⟫ = x
⟪ modLeft {dir = dir} {w₂ = w₂} p ⟫ = Container dir ⟪ p ⟫ w₂
⟪ modRight {dir = dir} {w₁ = w₁} p ⟫ = Container dir w₁ ⟪ p ⟫
⟪ toggle {en = en} {checked} ⟫ = CheckBox en (not checked)
⟪ select {en = en} {vec = vec} fin ⟫ = ComboBox en vec fin
⟪ setEntry {_} {en} {size} {name} {_} {val} {_} str ⟫ = Entry en size name str val
⟪ toggleValidity {en} {size} {name} {str} {val} ⟫ = Entry en size name str (oppositeᵛ val)
⟪ click {s} ⟫ = Button enabled s
⟪ setLabel l ⟫ = Label l
⟪ toggleEnable {w} {e} ⟫ with isInput w | e
... | just (_ , w') | tt = w' -- note: the JS backend cannot erase 'e', maybe because of the pattern maching on tt here
... | nothing | ()
⟪ addToLeft {r} dir w ⟫ = Container dir w r
⟪ addToRight {l} dir w ⟫ = Container dir l w
⟪ removeLeft {w₂ = w₂} ⟫ = w₂
⟪ removeRight {w₁ = w₁} ⟫ = w₁
⟪ p ∙ q ⟫ = ⟪ q ⟫
---------------------------------------
pw : I/O → Widget → Tree
pw i/o w .Branch = Maybe (WidgetEdit i/o w)
pw i/o w .child e = pw (opposite i/o) (maybe w ⟪_⟫ e)
-- GUI component (reactive widget)
WComp' = λ i/o w p → ⟨ i/o ⟩ IT (pw i/o w) p
WComp = λ i/o w A B → WComp' i/o w (⟨ i/o ⟩ Sig A B)
WC = λ p → Σ Widget λ w → WComp' I w p
processMain : WC (Sig A B) → Agent O (pw O Empty)
processMain (w , x) .step = just (replaceBy w) , mapAgent {i/o = I} (x ∘ᵀ noInput ∘ᵀ noOutput) (arr id)
-- enforcing no input ⇒ no output
ease : WComp i/o w A B → WComp i/o w A B
ease {i/o = I} b .step nothing .step = nothing , λ where .step x .step → nothing , ease {i/o = I} b
ease {i/o = I} b .step (just z) .step with b .step (just z) .step
... | x , y = x , ease {i/o = O} y
ease {i/o = O} b .step x .step with b .step x .step
... | c , d = c , ease {i/o = I} d
ease' : WC (Sig A B) → WC (Sig A B)
ease' (_ , x) = _ , ease {i/o = I} x
_∘ʷ_ : WC p → IT p q → WC q
(_ , x) ∘ʷ y = (_ , x ∘ᵀ y)
----------------------------------------------------------
button : ∀ i/o → WComp i/o (Button enabled str) ⊤ ⊥
button I .step nothing .step = nothing , button O
button I .step (just click) .step = just _ , button O
button O .step _ .step = nothing , button I
button' : String → WC (OutSig ⊤)
button' s = _ , button {s} I
checkbox : ∀ i/o → WComp i/o (CheckBox enabled checked) Bool Bool
checkbox I .step nothing .step = nothing , checkbox O
checkbox {b} I .step (just toggle) .step = just (not b) , checkbox O
checkbox O .step nothing .step = nothing , checkbox I
checkbox {b} O .step (just b') .step with b == b'
... | true = nothing , checkbox I
... | false = just toggle , checkbox I
checkbox' : Bool → WC (BiSig Bool)
checkbox' b = _ , checkbox {b} I
comboBox : ∀ {vec : Vec String n} i/o → WComp i/o (ComboBox enabled vec fin) (Fin n) (Fin n)
comboBox I .step nothing .step = nothing , comboBox O
comboBox I .step (just (select i)) .step = just i , comboBox O
comboBox O .step nothing .step = nothing , comboBox I
comboBox O .step (just i) .step = just (select i) , comboBox I
comboBox' : (vec : Vec String n)(fin : Fin n) → WC (Sig (Fin n) (Fin n))
comboBox' vec fin = _ , comboBox {fin = fin}{vec = vec} I
label : ∀ i/o → WComp i/o (Label str) ⊥ String
label I .step nothing .step = nothing , label O
label I .step (just ())
label O .step nothing .step = nothing , label I
label O .step (just m) .step = just (setLabel m) , label I
label' : String → WC (InSig String)
label' n = _ , label {n} I
label'' = λ n → label' n -- ∘ʷ discard
-- todo: refactoring (use less cases)
entry : Bool → ∀ i/o → WComp' i/o (Entry en size name str val) (⟨ i/o ⟩ Sig String (Maybe String) ×ᵀ ⟨ i/o ⟩ Sig ⊥ ⊤)
entry _ I .step nothing .step = (nothing , nothing) , entry false O
entry _ I .step (just (setEntry s)) .step = (just s , nothing) , entry true O
entry {val = v} v' O .step (ii , td) .step with td | ii | v | v'
... | nothing | nothing | invalid | true = just toggleValidity , entry false I
... | nothing | just nothing | valid | _ = just toggleValidity , entry false I
... | nothing | just (just ss) | valid | _ = just (setEntry ss) , entry false I
... | nothing | just (just ss) | invalid | _ = just (setEntry ss ∙ toggleValidity) , entry false I
... | nothing | _ | _ | _ = nothing , entry false I
... | just _ | nothing | invalid | true = just (toggleEnable ∙ toggleValidity) , entry false I
... | just _ | just nothing | valid | _ = just (toggleEnable ∙ toggleValidity) , entry false I
... | just _ | just (just ss) | valid | _ = just (toggleEnable ∙ setEntry ss) , entry false I
... | just _ | just (just ss) | invalid | _ = just (toggleEnable ∙ setEntry ss ∙ toggleValidity) , entry false I
... | just _ | _ | _ | _ = just toggleEnable , entry false I
entryF : ℕ → Abled → String → WC (Sig String (Maybe String) ×ᵀ InSig ⊤)
entryF size en name = _ , entry {en} {size} {name} {""} {valid} false I
container' : ∀ i/o → WComp' i/o (Container dir w₁ w₂) (pw i/o w₁ ×ᵀ pw i/o w₂)
container' I .step nothing .step = (nothing , nothing) , container' O
container' I .step (just (modLeft e)) .step = (just e , nothing) , container' O
container' I .step (just (modRight e)) .step = (nothing , just e) , container' O
container' O .step (nothing , nothing) .step = nothing , container' I
container' O .step (just x , nothing) .step = just (modLeft x) , container' I
container' O .step (nothing , just y) .step = just (modRight y) , container' I
container' O .step (just x , just y) .step = just (modLeft x ∙ modRight y) , container' I
container : (dir : Direction) → WComp' I w₁ r → WComp' I w₂ s → WComp' I (Container dir w₁ w₂) (r ×ᵀ s)
container _ p q = container' I ∘ᵀ (p ,ᵗ q)
fc : Direction → WC p → WC (Sig C D) → WC p
fc dir (_ , b) (_ , d) = _ , container' {dir} I ∘ᵀ ({-ease {I}-} b ,ᵗ ease {i/o = I} d) ∘ᵀ fstSig
infixr 3 _<->_
infixr 4 _<|>_
_<|>_ : WC p → WC (Sig C D) → WC p
_<|>_ = fc horizontal
_<->_ : WC p → WC (Sig C D) → WC p
_<->_ = fc vertical
infix 5 _⟦_⟧_
_⟦_⟧_ : WC p → IT (p ×ᵀ q) r → WC q → WC r
(_ , b) ⟦ t ⟧ (_ , d) = _ , container' {horizontal} I ∘ᵀ (b ,ᵗ d) ∘ᵀ t
entry'' : Abled → ℕ → String → WC (Sig String (Maybe String) ×ᵀ InSig ⊤)
entry'' en len name = entryF len en name ⟦ fstSig ⟧ label' name
entry' = λ len name → entry'' enabled len name ∘ʷ fstSig
addLabel : String → WC p → WC p
addLabel s x = x ⟦ fstSig ⟧ label'' s
---------------------------------------------------------------------------------------------------------------
counter = λ n → label' (showNat n) ⟦ swapIT ∘ᵀ enta (arr (const 1) ∘ᵗ accum _+_ n ∘ᵗ arr showNat) ⟧ button' "Count"
counter' = λ f b n → checkbox' b ∘ʷ noInput ⟦ enta (arr f ∘ᵗ accum _+_ n ∘ᵗ arr showNat) ⟧ label' (showNat n)
floatEntry = λ s → entry' 4 s ∘ʷ prismIT floatPrism
dateEntry = λ en s → entry'' en 4 s ∘ʷ (prismIT floatPrism ,ᵗ idIT)
showDates : (Float × Float) → String
showDates (a , b) = primStringAppend (primShowFloat a) (primStringAppend " -- " (primShowFloat b))
main = processMain (
label' "count clicks:"
<|> counter 0
<-> label' "count checks:"
<|> counter' (if_then 1 else 0) false 0
<-> label' "count checks and unchecks:"
<|> counter' (const 1) false 0
<-> label' "count unchecks:"
<|> counter' (if_then 0 else 1) false 0
<-> label' "copy input to label:"
<|> entry' 10 "" ∘ʷ noInput ⟦ enta (arr id) ⟧ label' ""
<-> label' "converter:"
<|> floatEntry "Celsius" ⟦ entaBi (isoBi (mulIso 1.8) ∘ᵇ isoBi (plusIso 32.0)) ⟧ floatEntry "Fahrenheit"
<-> label' "flight booker (unfinished):"
<|> ((comboBox' ("one-way" ∷ "return" ∷ []) zero
⟦ (mkIT' (arr ( maybe nothing (const (just _)) -- mapMaybe (const _) cannot be used because Agda bug #3380
)) (arr id) ,ᵗ (assocIT {i/o = O} ∘ᵀ swapIT))
∘ᵀ assocIT {i/o = O}
∘ᵀ (swapIT ∘ᵀ entangle ,ᵗ joinSig {i/o = I} 0.0 0.0) ∘ᵀ (swapIT ∘ᵀ fstSig)
⟧
(dateEntry enabled "start date" ∘ʷ fstSig ⟦ idIT ⟧ dateEntry disabled "return date")) ∘ʷ noInput)
⟦ {-(isoIT (showDates) (const nothing) ,ᵗ idIT) ∘ᵀ entangle-} enta (arr showDates)
⟧
(label' "")
)
| {
"alphanum_fraction": 0.5776045358,
"avg_line_length": 37.2825203252,
"ext": "agda",
"hexsha": "8355bc84421089c995e111b582bae692ce3c1106",
"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": "ac7e1758c86b48ff5d38797b61078b3085a4389d",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "divipp/frp_agda",
"max_forks_repo_path": "Reactive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ac7e1758c86b48ff5d38797b61078b3085a4389d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "divipp/frp_agda",
"max_issues_repo_path": "Reactive.agda",
"max_line_length": 123,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "ac7e1758c86b48ff5d38797b61078b3085a4389d",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "divipp/frp_agda",
"max_stars_repo_path": "Reactive.agda",
"max_stars_repo_stars_event_max_datetime": "2020-11-28T05:32:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-11-08T08:51:59.000Z",
"num_tokens": 6883,
"size": 18343
} |
import SOAS.Families.Core
-- Various properties of context map operations
module SOAS.ContextMaps.Properties {T : Set}
(open SOAS.Families.Core {T}) (𝒳 : Familyₛ) where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.ContextMaps.CategoryOfRenamings {T}
open import SOAS.ContextMaps.Combinators
open import Categories.Functor.Bifunctor
open import Categories.Object.Initial
open import Categories.Object.Coproduct
open import Categories.Category.Cocartesian
open import Categories.Category.Equivalence using (StrongEquivalence)
open import Categories.NaturalTransformation.NaturalIsomorphism
using (niHelper) renaming (refl to NI-refl)
private
variable
Γ Δ Θ Ξ : Ctx
α : T
-- Copairing and injection
copair∘i₁ : {σ : Γ ~[ 𝒳 ]↝ Θ}{ς : Δ ~[ 𝒳 ]↝ Θ} (v : ℐ α Γ)
→ copair 𝒳 σ ς (∔.i₁ v) ≡ σ v
copair∘i₁ new = refl
copair∘i₁ {σ = σ} (old v) = copair∘i₁ {σ = σ ∘ old} v
copair∘i₂ : {σ : Γ ~[ 𝒳 ]↝ Θ}{ς : Δ ~[ 𝒳 ]↝ Θ} (v : ℐ α Δ)
→ copair 𝒳 σ ς (∔.i₂ {Γ} v) ≡ ς v
copair∘i₂ {Γ = ∅} v = refl
copair∘i₂ {Γ = α ∙ Γ} {σ = σ} v = copair∘i₂ {σ = σ ∘ old} v
-- Push function into copairing
f∘copair : (𝒳 {𝒴} : Familyₛ) (f : Θ ~[ 𝒳 ➔ 𝒴 ]↝ Ξ)(σ : Γ ~[ 𝒳 ]↝ Θ)(ς : Δ ~[ 𝒳 ]↝ Θ)
(v : ℐ α (Γ ∔ Δ))
→ f (copair 𝒳 σ ς v) ≡ copair 𝒴 (f ∘ σ) (f ∘ ς) v
f∘copair {Γ = ∅} 𝒳 f σ ς v = refl
f∘copair {Γ = α ∙ Γ} 𝒳 f σ ς new = refl
f∘copair {Γ = α ∙ Γ} 𝒳 f σ ς (old v) = f∘copair 𝒳 f (σ ∘ old) ς v
| {
"alphanum_fraction": 0.6255088195,
"avg_line_length": 32.7555555556,
"ext": "agda",
"hexsha": "ae779b551173ace9ee5da9b78ebe453bd9752368",
"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": "b224d31e20cfd010b7c924ce940f3c2f417777e3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "k4rtik/agda-soas",
"max_forks_repo_path": "SOAS/ContextMaps/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b224d31e20cfd010b7c924ce940f3c2f417777e3",
"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": "k4rtik/agda-soas",
"max_issues_repo_path": "SOAS/ContextMaps/Properties.agda",
"max_line_length": 84,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b224d31e20cfd010b7c924ce940f3c2f417777e3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "k4rtik/agda-soas",
"max_stars_repo_path": "SOAS/ContextMaps/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 649,
"size": 1474
} |
open import Data.Sum
open import Data.Fin
open import Data.Product
open import Data.Maybe
open import Signature
Σ-N∞ : Sig
Σ-N∞ = record { ∥_∥ = Fin 2 ; ar = Σ-N∞-ar }
where
Σ-N∞-ar : Fin 2 → Set
Σ-N∞-ar zero = Fin 0
Σ-N∞-ar (suc zero) = Fin 1
Σ-N∞-ar (suc (suc ()))
D-N∞ : Set
D-N∞ = Fin 1
open import MixedTest Σ-N∞ D-N∞ as LP-N∞ renaming (Term to N∞μ; CoTerm to N∞)
stop' : N∞μ
stop' = cons (# 0 , λ())
step' : N∞ → N∞μ
step' x = (cons (# 1 , (λ _ → inj₂ x)))
-- Immediate stop -> 0
stop : N∞
destr stop zero = just (inj₁ stop')
destr stop (suc ())
-- Do a step -> successor
succ : N∞ → N∞
destr (succ x) zero = just (inj₁ (step' x))
destr (succ x) (suc ())
-- Not actually in N∞
foo : N∞
destr foo x = nothing
| {
"alphanum_fraction": 0.5710455764,
"avg_line_length": 19.1282051282,
"ext": "agda",
"hexsha": "ea2ced9a31e76aaa9d16fe663ce5704ef7067e19",
"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": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hbasold/Sandbox",
"max_forks_repo_path": "LP/ExampleMixedTest.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"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": "hbasold/Sandbox",
"max_issues_repo_path": "LP/ExampleMixedTest.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hbasold/Sandbox",
"max_stars_repo_path": "LP/ExampleMixedTest.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 327,
"size": 746
} |
module Base.Extensionality where
open import Level using (Level)
open import Relation.Binary.PropositionalEquality using (_≡_)
-- Postualting extensionality is consistent with agdas underlying theory.
postulate
ext : ∀ {ℓ ℓ′ : Level} {A : Set ℓ} {B : A → Set ℓ′} {f g : (x : A) → B x}
→ (∀ (x : A) → f x ≡ g x)
-----------------------
→ f ≡ g
| {
"alphanum_fraction": 0.5394402036,
"avg_line_length": 32.75,
"ext": "agda",
"hexsha": "d88add905e5c89a007be3e506efa2a9dbdff21ae",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-05-14T07:48:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-08T11:23:46.000Z",
"max_forks_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "FreeProving/free-compiler",
"max_forks_repo_path": "base/agda/Base/Extensionality.agda",
"max_issues_count": 120,
"max_issues_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_issues_repo_issues_event_max_datetime": "2020-12-08T07:46:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-04-09T09:40:39.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "FreeProving/free-compiler",
"max_issues_repo_path": "base/agda/Base/Extensionality.agda",
"max_line_length": 75,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "6931b9ca652a185a92dd824373f092823aea4ea9",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "FreeProving/free-compiler",
"max_stars_repo_path": "base/agda/Base/Extensionality.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-21T13:38:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-02-06T11:03:34.000Z",
"num_tokens": 115,
"size": 393
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.Magma.Construct.Unit where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.Magma
open import Cubical.Data.Unit
_◯_ : Op₂ ⊤
_ ◯ _ = tt
⊤-isMagma : IsMagma ⊤ _◯_
⊤-isMagma = record { is-set = isSet⊤ }
⊤-Magma : Magma ℓ-zero
⊤-Magma = record { isMagma = ⊤-isMagma }
| {
"alphanum_fraction": 0.7067669173,
"avg_line_length": 21,
"ext": "agda",
"hexsha": "1a38e91cc2ea9ffc047bcafb388e8ec25af2e608",
"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": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Algebra/Magma/Construct/Unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"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": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Algebra/Magma/Construct/Unit.agda",
"max_line_length": 50,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Algebra/Magma/Construct/Unit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 147,
"size": 399
} |
------------------------------------------------------------------------
-- A monad-like structure
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Delay-monad.Sized.Monad where
open import Prelude
open import Prelude.Size
open import Delay-monad.Sized
open import Delay-monad.Sized.Bisimilarity
------------------------------------------------------------------------
-- Monadic combinators
-- Return.
return : ∀ {i a} {A : Size → Type a} → A i → Delay A i
return = now
-- Map. Note the function argument's type.
map : ∀ {i a b} {A : Size → Type a} {B : Size → Type b} →
({j : Size< (ssuc i)} → A j → B j) → Delay A i → Delay B i
map f (now x) = now (f x)
map f (later x) = later λ { .force → map f (force x) }
-- Join.
join : ∀ {i a} {A : Size → Type a} →
Delay (Delay A) i → Delay A i
join (now x) = x
join (later x) = later λ { .force → join (force x) }
-- Bind. Note the function argument's type.
infixl 5 _>>=_
_>>=_ : ∀ {i a b} {A : Size → Type a} {B : Size → Type b} →
Delay A i → ({j : Size< (ssuc i)} → A j → Delay B j) →
Delay B i
x >>= f = join (map f x)
------------------------------------------------------------------------
-- Monad laws
left-identity :
∀ {a b} {A : Size → Type a} {B : Size → Type b}
x (f : ∀ {i} → A i → Delay B i) →
return x >>= f ∼ f x
left-identity x f = reflexive (f x)
right-identity : ∀ {a i} {A : Size → Type a} (x : Delay A ∞) →
[ i ] x >>= return ∼ x
right-identity (now x) = now
right-identity (later x) = later λ { .force →
right-identity (force x) }
associativity :
∀ {a b c i}
{A : Size → Type a} {B : Size → Type b} {C : Size → Type c} →
(x : Delay A ∞) (f : ∀ {i} → A i → Delay B i)
(g : ∀ {i} → B i → Delay C i) →
[ i ] x >>= (λ x → f x >>= g) ∼ x >>= f >>= g
associativity (now x) f g = reflexive (f x >>= g)
associativity (later x) f g = later λ { .force →
associativity (force x) f g }
------------------------------------------------------------------------
-- The functions map, join and _>>=_ preserve strong and weak
-- bisimilarity and expansion
map-cong : ∀ {k i a b} {A : Size → Type a} {B : Size → Type b}
(f : ∀ {i} → A i → B i) {x y : Delay A ∞} →
[ i ] x ⟨ k ⟩ y → [ i ] map f x ⟨ k ⟩ map f y
map-cong f now = now
map-cong f (later p) = later λ { .force → map-cong f (force p) }
map-cong f (laterˡ p) = laterˡ (map-cong f p)
map-cong f (laterʳ p) = laterʳ (map-cong f p)
join-cong : ∀ {k i a} {A : Size → Type a} {x y : Delay (Delay A) ∞} →
[ i ] x ⟨ k ⟩ y → [ i ] join x ⟨ k ⟩ join y
join-cong now = reflexive _
join-cong (later p) = later λ { .force → join-cong (force p) }
join-cong (laterˡ p) = laterˡ (join-cong p)
join-cong (laterʳ p) = laterʳ (join-cong p)
infixl 5 _>>=-cong_
_>>=-cong_ :
∀ {k i a b} {A : Size → Type a} {B : Size → Type b}
{x y : Delay A ∞} {f g : ∀ {i} → A i → Delay B i} →
[ i ] x ⟨ k ⟩ y → (∀ z → [ i ] f z ⟨ k ⟩ g z) →
[ i ] x >>= f ⟨ k ⟩ y >>= g
now >>=-cong q = q _
later p >>=-cong q = later λ { .force → force p >>=-cong q }
laterˡ p >>=-cong q = laterˡ (p >>=-cong q)
laterʳ p >>=-cong q = laterʳ (p >>=-cong q)
------------------------------------------------------------------------
-- A lemma
-- The function map can be expressed using _>>=′_ and now.
map∼>>=-now :
∀ {i a b} {A : Size → Type a} {B : Size → Type b}
{f : ∀ {i} → A i → B i} (x : Delay A ∞) →
[ i ] map f x ∼ x >>= now ∘ f
map∼>>=-now (now x) = now
map∼>>=-now (later x) = later λ { .force → map∼>>=-now (x .force) }
| {
"alphanum_fraction": 0.4471897909,
"avg_line_length": 32.592920354,
"ext": "agda",
"hexsha": "f721a318ab07c9a3079937a31273543a41da0414",
"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": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/delay-monad",
"max_forks_repo_path": "src/Delay-monad/Sized/Monad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"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/delay-monad",
"max_issues_repo_path": "src/Delay-monad/Sized/Monad.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/delay-monad",
"max_stars_repo_path": "src/Delay-monad/Sized/Monad.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1257,
"size": 3683
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Monoidal.Instance.Setoids where
open import Level
open import Data.Product
open import Data.Product.Relation.Binary.Pointwise.NonDependent
open import Function.Equality
open import Relation.Binary using (Setoid)
open import Categories.Category
open import Categories.Category.Instance.Setoids
open import Categories.Category.Cartesian
open import Categories.Category.Instance.SingletonSet
module _ {o ℓ} where
Setoids-Cartesian : Cartesian (Setoids o ℓ)
Setoids-Cartesian = record
{ terminal = SingletonSetoid-⊤
; products = record
{ product = λ {A B} →
let module A = Setoid A
module B = Setoid B
in record
{ A×B = ×-setoid A B -- the stdlib doesn't provide projections!
; π₁ = record
{ _⟨$⟩_ = proj₁
; cong = proj₁
}
; π₂ = record
{ _⟨$⟩_ = proj₂
; cong = proj₂
}
; ⟨_,_⟩ = λ f g → record
{ _⟨$⟩_ = λ x → f ⟨$⟩ x , g ⟨$⟩ x
; cong = λ eq → cong f eq , cong g eq
}
; project₁ = λ {_ h i} eq → cong h eq
; project₂ = λ {_ h i} eq → cong i eq
; unique = λ {W h i j} eq₁ eq₂ eq → A.sym (eq₁ (Setoid.sym W eq)) , B.sym (eq₂ (Setoid.sym W eq))
}
}
}
module Setoids-Cartesian = Cartesian Setoids-Cartesian
open Setoids-Cartesian renaming (monoidal to Setoids-Monoidal) public
| {
"alphanum_fraction": 0.5767195767,
"avg_line_length": 31.5,
"ext": "agda",
"hexsha": "9642b25bb77fc8a19f3094667e9c4ecd14e1676b",
"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/Category/Monoidal/Instance/Setoids.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/Category/Monoidal/Instance/Setoids.agda",
"max_line_length": 109,
"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/Category/Monoidal/Instance/Setoids.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 420,
"size": 1512
} |
{-# OPTIONS --without-K #-}
module Data.Inductive.Higher.Interval where
open import Relation.Equality
open import Relation.Path.Operation
-- The interval, which we denote I, is perhaps an even simpler higher inductive type than the
-- circle generated by:
module Interval where
private
data #I : Set where
#0 : #I
#1 : #I
I : Set
I = #I
-- A point 0ᵢ
0ᵢ : I
0ᵢ = #0
-- A point 1₁
1ᵢ : I
1ᵢ = #1
postulate -- A path segment
path-seg : 0ᵢ ≡ 1ᵢ
-- "The recursion principle for the interval says that given a type B along with
interval-rec : ∀ {b} {B : Set b} →
(b₀ b₁ : B) → -- points b₀, b₁ and
(p : b₀ ≡ b₁) → -- a path b₀ ≡ b₁
(i : I) → B -- there is a function f : I → B such that
interval-rec b₀ b₁ p #0 = b₀ -- f(0ᵢ) ≡ b₀
interval-rec b₀ b₁ p #1 = b₁ -- f(1ᵢ) ≡ b₁"
-- The induction principle says that given P : I → U along with
interval-ind : ∀ {b} (P : I → Set b)
(b₀ : P 0ᵢ) → -- a point b₀ : P(0ᵢ)
(b₁ : P 1ᵢ) → -- a point b₁ : P(1ᵢ) and
(p : transport {_}{_}{I}{P} path-seg b₀ ≡ b₁) →
∀ i → P i -- there is a function f : Π(x:I) P(x) such that
interval-ind P b₀ b₁ p #0 = b₀ -- f(0ᵢ) ≡ b₀
interval-ind P b₀ b₁ p #1 = b₁ -- f(1ᵢ) ≡ b₁"
open Interval public
| {
"alphanum_fraction": 0.5201149425,
"avg_line_length": 29.6170212766,
"ext": "agda",
"hexsha": "003a76380569ed7af22aa9c984585eb56c1856cc",
"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": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CodaFi/HoTT-Exercises",
"max_forks_repo_path": "Data/Inductive/Higher/Interval.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"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": "CodaFi/HoTT-Exercises",
"max_issues_repo_path": "Data/Inductive/Higher/Interval.agda",
"max_line_length": 93,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CodaFi/HoTT-Exercises",
"max_stars_repo_path": "Data/Inductive/Higher/Interval.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 518,
"size": 1392
} |
module Haskell.Prim.Either where
open import Haskell.Prim
open import Haskell.Prim.Bool
--------------------------------------------------
-- Either
data Either (a b : Set) : Set where
Left : a → Either a b
Right : b → Either a b
either : (a → c) → (b → c) → Either a b → c
either f g (Left x) = f x
either f g (Right y) = g y
testBool : (b : Bool) → Either (IsFalse b) (IsTrue b)
testBool false = Left itsFalse
testBool true = Right itsTrue
| {
"alphanum_fraction": 0.576754386,
"avg_line_length": 21.7142857143,
"ext": "agda",
"hexsha": "c6a7c84d2f36c755ea034c000c2ab917cc791c26",
"lang": "Agda",
"max_forks_count": 18,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:42:52.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-10-21T22:19:09.000Z",
"max_forks_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "seanpm2001/agda2hs",
"max_forks_repo_path": "lib/Haskell/Prim/Either.agda",
"max_issues_count": 63,
"max_issues_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_issues_repo_issues_event_max_datetime": "2022-02-25T15:47:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-10-22T05:19:27.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "seanpm2001/agda2hs",
"max_issues_repo_path": "lib/Haskell/Prim/Either.agda",
"max_line_length": 53,
"max_stars_count": 55,
"max_stars_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dxts/agda2hs",
"max_stars_repo_path": "lib/Haskell/Prim/Either.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-26T21:57:56.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-20T13:36:25.000Z",
"num_tokens": 139,
"size": 456
} |
module Rat where
open import Data.Empty
open import Data.Unit
import Data.Sign as S
open import Data.String
open import Data.Nat as ℕ using (ℕ; zero; suc)
open import Data.Nat.Coprimality renaming (sym to symCoprime)
open import Data.Nat.GCD
open import Data.Nat.Show renaming (show to ℕshow)
open import Data.Nat.Divisibility
open import Data.Integer hiding (_-_ ; -_)
renaming (_+_ to _ℤ+_ ; _*_ to _ℤ*_ ; _≟_ to _ℤ≟_ ; show to ℤshow)
open import Data.Integer.Properties
open import Data.Rational
open import Data.Product
open import Relation.Nullary.Decidable
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
infix 8 -_ 1/_
infixl 7 _*_ _/_
infixl 6 _-_ _+_
------------------------------------------------------------------------------
-- Two lemmas to help with operations on rationals
NonZero : ℕ → Set
NonZero 0 = ⊥
NonZero (suc _) = ⊤
-- normalize takes two natural numbers, say 6 and 21 and their gcd 3, and
-- returns them normalized as 2 and 7 and a proof that they are coprime
normalize : ∀ {m n g} → {n≢0 : NonZero n} → {g≢0 : NonZero g} →
GCD m n g → Σ[ p ∈ ℕ ] Σ[ q ∈ ℕ ] False (q ℕ.≟ 0) × Coprime p q
normalize {m} {n} {0} {_} {()} _
normalize {m} {n} {ℕ.suc g} {_} {_} G with Bézout.identity G
normalize {m} {.0} {ℕ.suc g} {()} {_}
(GCD.is (divides p m≡pg' , divides 0 refl) _) | _
normalize {m} {n} {ℕ.suc g} {_} {_}
(GCD.is (divides p m≡pg' , divides (ℕ.suc q) n≡qg') _) | Bézout.+- x y eq =
(p , ℕ.suc q , tt , Bézout-coprime {p} {ℕ.suc q} {g} (Bézout.+- x y
(begin
ℕ.suc g ℕ.+ y ℕ.* (ℕ.suc q ℕ.* ℕ.suc g)
≡⟨ cong (λ h → ℕ.suc g ℕ.+ y ℕ.* h) (sym n≡qg') ⟩
ℕ.suc g ℕ.+ y ℕ.* n
≡⟨ eq ⟩
x ℕ.* m
≡⟨ cong (λ h → x ℕ.* h) m≡pg' ⟩
x ℕ.* (p ℕ.* ℕ.suc g) ∎)))
normalize {m} {n} {ℕ.suc g} {_} {_}
(GCD.is (divides p m≡pg' , divides (ℕ.suc q) n≡qg') _) | Bézout.-+ x y eq =
(p , ℕ.suc q , tt , Bézout-coprime {p} {ℕ.suc q} {g} (Bézout.-+ x y
(begin
ℕ.suc g ℕ.+ x ℕ.* (p ℕ.* ℕ.suc g)
≡⟨ cong (λ h → ℕ.suc g ℕ.+ x ℕ.* h) (sym m≡pg') ⟩
ℕ.suc g ℕ.+ x ℕ.* m
≡⟨ eq ⟩
y ℕ.* n
≡⟨ cong (λ h → y ℕ.* h) n≡qg' ⟩
y ℕ.* (ℕ.suc q ℕ.* ℕ.suc g) ∎)))
-- a version of gcd that returns a proof that the result is non-zero given
-- that one of the inputs is non-zero
gcd≢0 : (m n : ℕ) → {m≢0 : NonZero m} → ∃ λ d → GCD m n d × NonZero d
gcd≢0 m n {m≢0} with gcd m n
gcd≢0 m n {m≢0} | (0 , GCD.is (0|m , _) _) with 0∣⇒≡0 0|m
gcd≢0 .0 n {()} | (0 , GCD.is (0|m , _) _) | refl
gcd≢0 m n {_} | (ℕ.suc d , G) = (ℕ.suc d , G , tt)
------------------------------------------------------------------------------
-- Operations on rationals: unary -, reciprocal, multiplication, addition
-- unary negation
--
-- Andreas Abel says: Agda's type-checker is incomplete when it has to handle
-- types with leading hidden quantification, such as the ones of Coprime m n
-- and c. A work around is to use hidden abstraction explicitly. In your
-- case, giving λ {i} -> c works. Not pretty, but unavoidable until we
-- improve on the current heuristics. I recorded this as a bug
-- http://code.google.com/p/agda/issues/detail?id=1079
-_ : ℚ → ℚ
-_ p with ℚ.numerator p | ℚ.denominator-1 p | toWitness (ℚ.isCoprime p)
... | -[1+ n ] | d | c = (+ ℕ.suc n ÷ ℕ.suc d) {fromWitness (λ {i} → c)}
... | + 0 | d | _ = p
... | + ℕ.suc n | d | c = (-[1+ n ] ÷ ℕ.suc d) {fromWitness (λ {i} → c)}
-- reciprocal: requires a proof that the numerator is not zero
1/_ : (p : ℚ) → {n≢0 : NonZero ∣ ℚ.numerator p ∣} → ℚ
1/_ p {n≢0} with ℚ.numerator p | ℚ.denominator-1 p | toWitness (ℚ.isCoprime p)
1/_ p {()} | + 0 | d | c
... | + (ℕ.suc n) | d | c =
((S.+ ◃ ℕ.suc d) ÷ ℕ.suc n)
{fromWitness (λ {i} →
subst (λ h → Coprime h (ℕ.suc n))
(sym (abs-◃ S.+ (ℕ.suc d)))
(symCoprime c))}
... | -[1+ n ] | d | c =
((S.- ◃ ℕ.suc d) ÷ ℕ.suc n)
{fromWitness (λ {i} →
subst (λ h → Coprime h (ℕ.suc n))
(sym (abs-◃ S.- (ℕ.suc d)))
(symCoprime c))}
-- multiplication
private
helper* : (n₁ : ℤ) → (d₁ : ℕ) → (n₂ : ℤ) → (d₂ : ℕ) →
{n≢0 : NonZero ∣ n₁ ℤ* n₂ ∣} →
{d≢0 : NonZero (d₁ ℕ.* d₂)} →
ℚ
helper* n₁ d₁ n₂ d₂ {n≢0} {d≢0} =
let n = n₁ ℤ* n₂
d = d₁ ℕ.* d₂
(g , G , g≢0) = gcd≢0 ∣ n ∣ d {n≢0}
(nn , nd , nd≢0 , nc) = normalize {∣ n ∣} {d} {g} {d≢0} {g≢0} G
in ((sign n ◃ nn) ÷ nd)
{fromWitness (λ {i} →
subst (λ h → Coprime h nd) (sym (abs-◃ (sign n) nn)) nc)}
{nd≢0}
_*_ : ℚ → ℚ → ℚ
p₁ * p₂ with ℚ.numerator p₁ | ℚ.numerator p₂
... | + 0 | _ = + 0 ÷ 1
... | _ | + 0 = + 0 ÷ 1
... | + ℕ.suc n₁ | + ℕ.suc n₂ =
helper* (+ ℕ.suc n₁) (ℕ.suc (ℚ.denominator-1 p₁))
(+ ℕ.suc n₂) (ℕ.suc (ℚ.denominator-1 p₂))
... | + ℕ.suc n₁ | -[1+ n₂ ] =
helper* (+ ℕ.suc n₁) (ℕ.suc (ℚ.denominator-1 p₁))
-[1+ n₂ ] (ℕ.suc (ℚ.denominator-1 p₂))
... | -[1+ n₁ ] | + ℕ.suc n₂ =
helper* -[1+ n₁ ] (ℕ.suc (ℚ.denominator-1 p₁))
(+ ℕ.suc n₂) (ℕ.suc (ℚ.denominator-1 p₂))
... | -[1+ n₁ ] | -[1+ n₂ ] =
helper* -[1+ n₁ ] (ℕ.suc (ℚ.denominator-1 p₁))
-[1+ n₂ ] (ℕ.suc (ℚ.denominator-1 p₂))
-- addition
private
helper+ : (n : ℤ) → (d : ℕ) → {d≢0 : NonZero d} → ℚ
helper+ (+ 0) d {d≢0} = + 0 ÷ 1
helper+ (+ ℕ.suc n) d {d≢0} =
let (g , G , g≢0) = gcd≢0 ∣ + ℕ.suc n ∣ d {tt}
(nn , nd , nd≢0 , nc) = normalize {∣ + ℕ.suc n ∣} {d} {g} {d≢0} {g≢0} G
in ((S.+ ◃ nn) ÷ nd)
{fromWitness (λ {i} →
subst (λ h → Coprime h nd) (sym (abs-◃ S.+ nn)) nc)}
{nd≢0}
helper+ -[1+ n ] d {d≢0} =
let (g , G , g≢0) = gcd≢0 ∣ -[1+ n ] ∣ d {tt}
(nn , nd , nd≢0 , nc) = normalize {∣ -[1+ n ] ∣} {d} {g} {d≢0} {g≢0} G
in ((S.- ◃ nn) ÷ nd)
{fromWitness (λ {i} →
subst (λ h → Coprime h nd) (sym (abs-◃ S.- nn)) nc)}
{nd≢0}
_+_ : ℚ → ℚ → ℚ
p₁ + p₂ =
let n₁ = ℚ.numerator p₁
d₁ = ℕ.suc (ℚ.denominator-1 p₁)
n₂ = ℚ.numerator p₂
d₂ = ℕ.suc (ℚ.denominator-1 p₂)
n = (n₁ ℤ* + d₂) ℤ+ (n₂ ℤ* + d₁)
d = d₁ ℕ.* d₂
in helper+ n d
-- subtraction and division
_-_ : ℚ → ℚ → ℚ
p₁ - p₂ = p₁ + (- p₂)
_/_ : (p₁ p₂ : ℚ) → {n≢0 : NonZero ∣ ℚ.numerator p₂ ∣} → ℚ
_/_ p₁ p₂ {n≢0} = p₁ * (1/_ p₂ {n≢0})
-- conventional printed representation
show : ℚ → String
show p = ℤshow (ℚ.numerator p) ++ "/" ++ ℕshow (ℕ.suc (ℚ.denominator-1 p))
------------------------------------------------------------------------------
-- A few constants and some small tests
0ℚ 1ℚ : ℚ
0ℚ = + 0 ÷ 1
1ℚ = + 1 ÷ 1
private
p₀ p₁ p₂ p₃ : ℚ
p₀ = + 1 ÷ 2
p₁ = + 1 ÷ 3
p₂ = -[1+ 2 ] ÷ 4
p₃ = + 3 ÷ 4
test₀ = show p₂
test₁ = show (- p₂)
test₂ = show (1/ p₂)
test₃ = show (p₀ + p₀)
test₄ = show (p₁ * p₂)
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.4789533561,
"avg_line_length": 33.4857142857,
"ext": "agda",
"hexsha": "b43a585062acc4b7e4c1c5359b2e0d6247d04931",
"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": "Rat.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": "Rat.agda",
"max_line_length": 79,
"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": "Rat.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": 2974,
"size": 7032
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.DescendingList where
open import Cubical.Data.DescendingList.Base public
open import Cubical.Data.DescendingList.Properties public
| {
"alphanum_fraction": 0.8108108108,
"avg_line_length": 30.8333333333,
"ext": "agda",
"hexsha": "0ece5c884cadcbc10ccb7846f8df14d3dfec964c",
"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": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Data/DescendingList.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"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": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Data/DescendingList.agda",
"max_line_length": 57,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/Data/DescendingList.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 40,
"size": 185
} |
{-# OPTIONS --cubical --safe #-}
module Algebra.Construct.Free.Semilattice.Relation.Unary where
open import Algebra.Construct.Free.Semilattice.Relation.Unary.All.Def public
open import Algebra.Construct.Free.Semilattice.Relation.Unary.All.Dec public
open import Algebra.Construct.Free.Semilattice.Relation.Unary.All.Properties public
open import Algebra.Construct.Free.Semilattice.Relation.Unary.All.Map public
open import Algebra.Construct.Free.Semilattice.Relation.Unary.Membership public
open import Algebra.Construct.Free.Semilattice.Relation.Unary.Any.Def public
open import Algebra.Construct.Free.Semilattice.Relation.Unary.Any.Dec public
open import Algebra.Construct.Free.Semilattice.Relation.Unary.Any.Properties public
open import Algebra.Construct.Free.Semilattice.Relation.Unary.Any.Map public
| {
"alphanum_fraction": 0.8477722772,
"avg_line_length": 57.7142857143,
"ext": "agda",
"hexsha": "46cf4a288840cb92e3005f00c7d1ec693364d4be",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Algebra/Construct/Free/Semilattice/Relation/Unary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"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/combinatorics-paper",
"max_issues_repo_path": "agda/Algebra/Construct/Free/Semilattice/Relation/Unary.agda",
"max_line_length": 83,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Algebra/Construct/Free/Semilattice/Relation/Unary.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": 186,
"size": 808
} |
open import Nat
open import Prelude
open import core
open import contexts
open import progress
open import lemmas-complete
module complete-progress where
-- as in progress, we define a datatype for the possible outcomes of
-- progress for readability.
data okc : (d : iexp) (Δ : hctx) → Set where
V : ∀{d Δ} → d val → okc d Δ
S : ∀{d Δ} → Σ[ d' ∈ iexp ] (d ↦ d') → okc d Δ
complete-progress : {Δ : hctx} {d : iexp} {τ : typ} →
Δ , ∅ ⊢ d :: τ →
d dcomplete →
okc d Δ
complete-progress wt comp with progress wt
complete-progress wt comp | S x = S x
complete-progress wt comp | I x = abort (lem-ind-comp comp x)
complete-progress wt comp | BV x = V (lem-comp-boxed-val wt comp x)
| {
"alphanum_fraction": 0.596377749,
"avg_line_length": 32.2083333333,
"ext": "agda",
"hexsha": "802c7ca5f6191b917ca53a6253f9b90b25c60305",
"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": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-livelits-agda",
"max_forks_repo_path": "complete-progress.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_issues_repo_issues_event_max_datetime": "2020-10-20T20:44:13.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-09-30T20:27:56.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazel-palette-agda",
"max_issues_repo_path": "complete-progress.agda",
"max_line_length": 70,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazel-palette-agda",
"max_stars_repo_path": "complete-progress.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T15:38:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-04T06:45:06.000Z",
"num_tokens": 228,
"size": 773
} |
open import Nat
open import Prelude
open import dynamics-core
open import contexts
open import lemmas-consistency
open import lemmas-ground
open import progress-checks
open import canonical-boxed-forms
open import canonical-value-forms
open import canonical-indeterminate-forms
open import ground-decidable
open import htype-decidable
module progress where
-- this is a little bit of syntactic sugar to avoid many layer nested Inl
-- and Inrs that you would get from the more literal transcription of the
-- consequent of progress
data ok : (d : ihexp) (Δ : hctx) → Set where
S : ∀{d Δ} → Σ[ d' ∈ ihexp ] (d ↦ d') → ok d Δ
I : ∀{d Δ} → d indet → ok d Δ
BV : ∀{d Δ} → d boxedval → ok d Δ
progress : {Δ : hctx} {d : ihexp} {τ : htyp} →
Δ , ∅ ⊢ d :: τ →
ok d Δ
-- constants
progress TANum = BV (BVVal VNum)
-- addition
progress (TAPlus wt1 wt2) with progress wt1 | progress wt2
-- if the left steps, the whole thing steps
... | S (_ , Step x y z) | _ = S (_ , Step (FHPlus1 x) y (FHPlus1 z))
... | I _ | S (_ , Step x y z) = S (_ , Step (FHPlus2 x) y (FHPlus2 z))
... | BV _ | S (_ , Step x y z) = S (_ , Step (FHPlus2 x) y (FHPlus2 z))
... | I x | I x₁ = I (IPlus1 x (FIndet x₁))
... | I x | BV x₁ = I (IPlus1 x (FBoxedVal x₁))
... | BV (BVVal VNum) | I x = I (IPlus2 (FBoxedVal (BVVal VNum)) x)
... | BV (BVVal VNum) | BV (BVVal VNum) = S (_ , Step FHOuter (ITPlus refl) FHOuter)
-- variables
progress (TAVar x₁) = abort (somenotnone (! x₁))
-- lambdas
progress (TALam _ wt) = BV (BVVal VLam)
-- applications
progress (TAAp wt1 wt2)
with progress wt1 | progress wt2
-- if the left steps, the whole thing steps
... | S (_ , Step x y z) | _ = S (_ , Step (FHAp1 x) y (FHAp1 z))
-- if the left is indeterminate, step the right
... | I i | S (_ , Step x y z) = S (_ , Step (FHAp2 x) y (FHAp2 z))
-- if they're both indeterminate, step when the cast steps and indet otherwise
... | I x | I y
with canonical-indeterminate-forms-arr wt1 x
... | CIFACast (_ , _ , _ , _ , _ , refl , _ , _ ) = S (_ , Step FHOuter ITApCast FHOuter)
... | CIFAEHole (_ , _ , _ , refl , _) = I (IAp (λ _ _ _ _ _ ()) x (FIndet y))
... | CIFANEHole (_ , _ , _ , _ , _ , refl , _) = I (IAp (λ _ _ _ _ _ ()) x (FIndet y))
... | CIFAAp (_ , _ , _ , _ , _ , refl , _) = I (IAp (λ _ _ _ _ _ ()) x (FIndet y))
... | CIFACastHole (_ , refl , refl , refl , _ ) = I (IAp (λ _ _ _ _ _ ()) x (FIndet y))
... | CIFAFailedCast (_ , _ , refl , _ ) = I (IAp (λ _ _ _ _ _ ()) x (FIndet y))
... | CIFACase (_ , _ , _ , _ , _ , _ , _ , refl , _ ) = I (IAp (λ _ _ _ _ _ ()) x (FIndet y))
... | CIFAFst (_ , _ , refl , _ , _ , _ , _) = I (IAp (λ _ _ _ _ _ ()) x (FIndet y))
... | CIFASnd (_ , _ , refl , _ , _ , _ , _) = I (IAp (λ _ _ _ _ _ ()) x (FIndet y))
-- similar if the left is indeterminate but the right is a boxed val
progress (TAAp wt1 wt2) | I x | BV y
with canonical-indeterminate-forms-arr wt1 x
... | CIFACast (_ , _ , _ , _ , _ , refl , _ , _ ) = S (_ , Step FHOuter ITApCast FHOuter)
... | CIFAEHole (_ , _ , _ , refl , _) = I (IAp (λ _ _ _ _ _ ()) x (FBoxedVal y))
... | CIFANEHole (_ , _ , _ , _ , _ , refl , _) = I (IAp (λ _ _ _ _ _ ()) x (FBoxedVal y))
... | CIFAAp (_ , _ , _ , _ , _ , refl , _) = I (IAp (λ _ _ _ _ _ ()) x (FBoxedVal y))
... | CIFACastHole (_ , refl , refl , refl , _ ) = I (IAp (λ _ _ _ _ _ ()) x (FBoxedVal y))
... | CIFAFailedCast (_ , _ , refl , _ ) = I (IAp (λ _ _ _ _ _ ()) x (FBoxedVal y))
... | CIFACase (_ , _ , _ , _ , _ , _ , _ , refl , _ ) = I (IAp (λ _ _ _ _ _ ()) x (FBoxedVal y))
... | CIFAFst (_ , _ , refl , _ , _ , _ , _) = I (IAp (λ _ _ _ _ _ ()) x (FBoxedVal y))
... | CIFASnd (_ , _ , refl , _ , _ , _ , _) = I (IAp (λ _ _ _ _ _ ()) x (FBoxedVal y))
-- if the left is a boxed value, inspect the right
progress (TAAp wt1 wt2) | BV v | S (_ , Step x y z) = S (_ , Step (FHAp2 x) y (FHAp2 z))
progress (TAAp wt1 wt2) | BV v | I i
with canonical-boxed-forms-arr wt1 v
... | CBFALam (_ , _ , refl , _) = S (_ , Step FHOuter ITLam FHOuter)
... | CBFACastArr (_ , _ , _ , refl , _ , _) = S (_ , Step FHOuter ITApCast FHOuter)
progress (TAAp wt1 wt2) | BV v | BV v₂
with canonical-boxed-forms-arr wt1 v
... | CBFALam (_ , _ , refl , _) = S (_ , Step FHOuter ITLam FHOuter)
... | CBFACastArr (_ , _ , _ , refl , _ , _) = S (_ , Step FHOuter ITApCast FHOuter)
-- sum types
progress (TAInl wt)
with progress wt
... | S (_ , Step x y z) = S (_ , Step (FHInl x) y (FHInl z))
... | I x = I (IInl x)
... | BV x = BV (BVInl x)
progress (TAInr wt)
with progress wt
... | S (_ , Step x y z) = S (_ , Step (FHInr x) y (FHInr z))
... | I x = I (IInr x)
... | BV x = BV (BVInr x)
progress (TACase wt _ wt₁ _ wt₂)
with progress wt
... | S (_ , Step x y z) = S (_ , Step (FHCase x) y (FHCase z))
progress (TACase () _ wt₁ _ wt₂) | BV (BVVal VNum)
progress (TACase () _ wt₁ _ wt₂) | BV (BVVal VLam)
progress (TACase () _ wt₁ _ wt₂) | BV (BVVal (VPair x x₁))
progress (TACase wt _ wt₁ _ wt₂) | BV (BVVal (VInl x)) = S (_ , Step FHOuter ITCaseInl FHOuter)
... | BV (BVVal (VInr x)) = S (_ , Step FHOuter ITCaseInr FHOuter)
... | BV (BVInl x) = S (_ , Step FHOuter ITCaseInl FHOuter)
... | BV (BVInr x) = S (_ , Step FHOuter ITCaseInr FHOuter)
... | BV (BVSumCast x x₁) = S (_ , Step FHOuter ITCaseCast FHOuter)
... | I (IAp x x₁ x₂) = I (ICase (λ _ _ ()) (λ _ _ ()) (λ _ _ _ _ _ ()) (IAp x x₁ x₂))
... | I (IInl x) = S (_ , Step FHOuter ITCaseInl FHOuter)
... | I (IInr x) = S (_ , Step FHOuter ITCaseInr FHOuter)
... | I (ICase x x₁ x₂ x₃) = I (ICase (λ _ _ ()) (λ _ _ ()) (λ _ _ _ _ _ ()) (ICase x x₁ x₂ x₃))
... | I (IFst x x₁ x₂) = I (ICase (λ _ _ ()) (λ _ _ ()) (λ _ _ _ _ _ ()) (IFst x x₁ x₂))
... | I (ISnd x x₁ x₂) = I (ICase (λ _ _ ()) (λ _ _ ()) (λ _ _ _ _ _ ()) (ISnd x x₁ x₂))
... | I IEHole = I (ICase (λ _ _ ()) (λ _ _ ()) (λ _ _ _ _ _ ()) IEHole)
... | I (INEHole x) = I (ICase (λ _ _ ()) (λ _ _ ()) (λ _ _ _ _ _ ()) (INEHole x))
... | I (ICastSum x x₁) = S (_ , Step FHOuter ITCaseCast FHOuter)
... | I (ICastHoleGround x x₁ x₂) = I (ICase (λ _ _ ()) (λ _ _ ()) (λ _ _ _ _ _ ()) (ICastHoleGround x x₁ x₂))
... | I (IFailedCast x x₁ x₂ x₃) = I (ICase (λ _ _ ()) (λ _ _ ()) (λ _ _ _ _ _ ()) (IFailedCast x x₁ x₂ x₃))
--product types
progress (TAPair wt₁ wt₂)
with progress wt₁ | progress wt₂
... | S (_ , Step x y z) | _ = S (_ , Step (FHPair1 x) y (FHPair1 z))
... | I _ | S (_ , Step x y z) = S (_ , Step (FHPair2 x) y (FHPair2 z))
... | BV _ | S (_ , Step x y z) = S (_ , Step (FHPair2 x) y (FHPair2 z))
... | I x | I x₁ = I (IPair1 x (FIndet x₁))
... | I x | BV x₁ = I (IPair1 x (FBoxedVal x₁))
... | BV x | I x₁ = I (IPair2 (FBoxedVal x) x₁)
... | BV x | BV x₁ = BV (BVPair x x₁)
progress (TAFst wt)
with progress wt
... | S (_ , Step x y z) = S (_ , Step (FHFst x) y (FHFst z))
... | I (IAp x x₁ x₂) = I (IFst (λ _ _ ()) (λ _ _ _ _ _()) (IAp x x₁ x₂))
... | I (ICase x x₁ x₂ x₃) = I (IFst (λ _ _ ()) (λ _ _ _ _ _ ()) (ICase x x₁ x₂ x₃))
... | I (IPair1 x x₁) = S (_ , Step FHOuter ITFstPair FHOuter)
... | I (IPair2 x x₁) = S (_ , Step FHOuter ITFstPair FHOuter)
... | I (IFst x x₁ x₂) = I (IFst (λ _ _ ()) (λ _ _ _ _ _ ()) (IFst x x₁ x₂))
... | I (ISnd x x₁ x₂) = I (IFst (λ _ _ ()) (λ _ _ _ _ _ ()) (ISnd x x₁ x₂))
... | I IEHole = I (IFst (λ _ _ ()) (λ _ _ _ _ _ ()) IEHole)
... | I (INEHole x) = I (IFst (λ _ _ ()) (λ _ _ _ _ _ ()) (INEHole x))
... | I (ICastProd x x₁) = S (_ , Step FHOuter ITFstCast FHOuter)
... | I (ICastHoleGround x x₁ x₂) = I (IFst (λ _ _ ()) (λ _ _ _ _ _ ()) (ICastHoleGround x x₁ x₂))
... | I (IFailedCast x x₁ x₂ x₃) = I (IFst (λ _ _ ()) (λ _ _ _ _ _ ()) (IFailedCast x x₁ x₂ x₃))
... | BV (BVVal (VPair x x₁)) = S (_ , Step FHOuter ITFstPair FHOuter)
... | BV (BVPair x x₁) = S (_ , Step FHOuter ITFstPair FHOuter)
... | BV (BVProdCast x x₁) = S (_ , Step FHOuter ITFstCast FHOuter)
progress (TASnd wt)
with progress wt
... | S (_ , Step x y z) = S (_ , Step (FHSnd x) y (FHSnd z))
... | I (IAp x x₁ x₂) = I (ISnd (λ _ _ ()) (λ _ _ _ _ _ ()) (IAp x x₁ x₂))
... | I (ICase x x₁ x₂ x₃) = I (ISnd (λ _ _ ()) (λ _ _ _ _ _ ()) (ICase x x₁ x₂ x₃))
... | I (IPair1 x x₁) = S (_ , Step FHOuter ITSndPair FHOuter)
... | I (IPair2 x x₁) = S (_ , Step FHOuter ITSndPair FHOuter)
... | I (IFst x x₁ x₂) = I (ISnd (λ _ _ ()) (λ _ _ _ _ _ ()) (IFst x x₁ x₂))
... | I (ISnd x x₁ x₂) = I (ISnd (λ _ _ ()) (λ _ _ _ _ _ ()) (ISnd x x₁ x₂))
... | I IEHole = I (ISnd (λ _ _ ()) (λ _ _ _ _ _ ()) IEHole)
... | I (INEHole x) = I (ISnd (λ _ _ ()) (λ _ _ _ _ _ ()) (INEHole x))
... | I (ICastProd x x₁) = S (_ , Step FHOuter ITSndCast FHOuter)
... | I (ICastHoleGround x x₁ x₂) = I (ISnd (λ _ _ ()) (λ _ _ _ _ _ ()) (ICastHoleGround x x₁ x₂))
... | I (IFailedCast x x₁ x₂ x₃) = I (ISnd (λ _ _ ()) (λ _ _ _ _ _ ()) (IFailedCast x x₁ x₂ x₃))
... | BV (BVVal (VPair x x₁)) = S (_ , Step FHOuter ITSndPair FHOuter)
... | BV (BVPair x x₁) = S (_ , Step FHOuter ITSndPair FHOuter)
... | BV (BVProdCast x x₁) = S (_ , Step FHOuter ITSndCast FHOuter)
-- empty holes are indeterminate
progress (TAEHole _ _ ) = I IEHole
-- nonempty holes step if the innards step, indet otherwise
progress (TANEHole xin wt x₁)
with progress wt
... | S (_ , Step x y z) = S (_ , Step (FHNEHole x) y (FHNEHole z))
... | I x = I (INEHole (FIndet x))
... | BV x = I (INEHole (FBoxedVal x))
-- casts
progress (TACast wt con)
with progress wt
-- step if the innards step
... | S (_ , Step x y z) = S (_ , Step (FHCast x) y (FHCast z))
-- if indet, inspect how the types in the cast are realted by consistency:
-- if they're the same, step by ID
progress (TACast wt TCRefl) | I x = S (_ , Step FHOuter ITCastID FHOuter)
-- if first type is hole
progress (TACast {τ1 = τ1} wt TCHole1) | I x
with τ1
... | num = I (ICastGroundHole GNum x)
... | ⦇-⦈ = S (_ , Step FHOuter ITCastID FHOuter)
... | τ11 ==> τ12
with ground-decidable (τ11 ==> τ12)
... | Inl GArrHole = I (ICastGroundHole GArrHole x)
... | Inr y = S (_ , Step FHOuter (ITGround (MGArr (π1 (ground-not-holes y)))) FHOuter)
progress (TACast {τ1 = τ1} wt TCHole1) | I x | τ11 ⊕ τ12
with ground-decidable (τ11 ⊕ τ12)
... | Inl GSumHole = I (ICastGroundHole GSumHole x)
... | Inr y = S (_ , Step FHOuter (ITGround (MGSum (π1 (π2 (ground-not-holes y))))) FHOuter)
progress (TACast {τ1 = τ1} wt TCHole1) | I x | τ11 ⊠ τ12
with ground-decidable (τ11 ⊠ τ12)
... | Inl GProdHole = I (ICastGroundHole GProdHole x)
... | Inr y = S (_ , Step FHOuter (ITGround (MGProd (π2 (π2 (ground-not-holes y))))) FHOuter)
-- if second type is hole
progress (TACast wt (TCHole2 {num})) | I x
with canonical-indeterminate-forms-hole wt x
... | CIFHEHole (_ , _ , _ , refl , f) = I (ICastHoleGround (λ _ _ ()) x GNum)
... | CIFHNEHole (_ , _ , _ , _ , _ , refl , _ ) = I (ICastHoleGround (λ _ _ ()) x GNum)
... | CIFHAp (_ , _ , _ , refl , _ ) = I (ICastHoleGround (λ _ _ ()) x GNum)
... | CIFHCase (_ , _ , _ , _ , _ , _ , _ , refl , _ ) = I (ICastHoleGround (λ _ _ ()) x GNum)
... | CIFHFst (_ , _ , refl , _ , _ , _ , _) = I (ICastHoleGround (λ _ _ ()) x GNum)
... | CIFHSnd (_ , _ , refl , _ , _ , _ , _) = I (ICastHoleGround (λ _ _ ()) x GNum)
... | CIFHCast (_ , τ , refl , _ , grn , _)
with htype-dec τ num
... | Inl refl = S (_ , Step FHOuter (ITCastSucceed grn ) FHOuter)
... | Inr y = S (_ , Step FHOuter (ITCastFail grn GNum y) FHOuter)
progress (TACast wt (TCHole2 {⦇-⦈}))| I x = S (_ , Step FHOuter ITCastID FHOuter)
progress (TACast wt (TCHole2 {τ11 ==> τ12})) | I x
with ground-decidable (τ11 ==> τ12)
... | Inr y = S (_ , Step FHOuter (ITExpand (MGArr (π1 (ground-not-holes y)))) FHOuter)
... | Inl GArrHole
with canonical-indeterminate-forms-hole wt x
... | CIFHEHole (_ , _ , _ , refl , _) = I (ICastHoleGround (λ _ _ ()) x GArrHole)
... | CIFHNEHole (_ , _ , _ , _ , _ , refl , _) = I (ICastHoleGround (λ _ _ ()) x GArrHole)
... | CIFHAp (_ , _ , _ , refl , _ ) = I (ICastHoleGround (λ _ _ ()) x GArrHole)
... | CIFHCase (_ , _ , _ , _ , _ , _ , _ , refl , _ ) = I (ICastHoleGround (λ _ _ ()) x GArrHole)
... | CIFHFst (_ , _ , refl , _ , _ , _ , _) = I (ICastHoleGround (λ _ _ ()) x GArrHole)
... | CIFHSnd (_ , _ , refl , _ , _ , _ , _) = I (ICastHoleGround (λ _ _ ()) x GArrHole)
... | CIFHCast (_ , ._ , refl , _ , GNum , _) = S (_ , Step FHOuter (ITCastFail GNum GArrHole (λ ())) FHOuter)
... | CIFHCast (_ , ._ , refl , _ , GArrHole , _) = S (_ , Step FHOuter (ITCastSucceed GArrHole) FHOuter)
... | CIFHCast (_ , _ , refl , _ , GSumHole , _) = S (_ , Step FHOuter (ITCastFail GSumHole GArrHole (λ ())) FHOuter)
... | CIFHCast (_ , ._ , refl , _ , GProdHole , _) = S (_ , Step FHOuter (ITCastFail GProdHole GArrHole (λ ())) FHOuter)
progress (TACast wt (TCHole2 {τ11 ⊕ τ12})) | I x
with ground-decidable (τ11 ⊕ τ12)
... | Inr y = S (_ , Step FHOuter (ITExpand (MGSum (π1 (π2 (ground-not-holes y))))) FHOuter)
... | Inl GSumHole
with canonical-indeterminate-forms-hole wt x
... | CIFHEHole (_ , _ , _ , refl , _) = I (ICastHoleGround (λ _ _ ()) x GSumHole)
... | CIFHNEHole (_ , _ , _ , _ , _ , refl , _) = I (ICastHoleGround (λ _ _ ()) x GSumHole)
... | CIFHAp (_ , _ , _ , refl , _ ) = I (ICastHoleGround (λ _ _ ()) x GSumHole)
... | CIFHCase (_ , _ , _ , _ , _ , _ , _ , refl , _ ) = I (ICastHoleGround (λ _ _ ()) x GSumHole)
... | CIFHFst (_ , _ , refl , _ , _ , _ , _) = I (ICastHoleGround (λ _ _ ()) x GSumHole)
... | CIFHSnd (_ , _ , refl , _ , _ , _ , _) = I (ICastHoleGround (λ _ _ ()) x GSumHole)
... | CIFHCast (_ , _ , refl , _ , GNum , _) = S (_ , Step FHOuter (ITCastFail GNum GSumHole (λ ())) FHOuter)
... | CIFHCast (_ , _ , refl , _ , GArrHole , _) = S (_ , Step FHOuter (ITCastFail GArrHole GSumHole (λ ())) FHOuter)
... | CIFHCast (_ , _ , refl , _ , GSumHole , _) = S (_ , Step FHOuter (ITCastSucceed GSumHole) FHOuter)
... | CIFHCast (_ , _ , refl , _ , GProdHole , _) = S (_ , Step FHOuter (ITCastFail GProdHole GSumHole λ ()) FHOuter)
progress (TACast wt (TCHole2 {τ11 ⊠ τ12})) | I x
with ground-decidable (τ11 ⊠ τ12)
... | Inr y = S (_ , Step FHOuter (ITExpand (MGProd (π2 (π2 (ground-not-holes y))))) FHOuter)
... | Inl GProdHole
with canonical-indeterminate-forms-hole wt x
... | CIFHEHole (_ , _ , _ , refl , _) = I (ICastHoleGround (λ _ _ ()) x GProdHole)
... | CIFHNEHole (_ , _ , _ , _ , _ , refl , _) = I (ICastHoleGround (λ _ _ ()) x GProdHole)
... | CIFHAp (_ , _ , _ , refl , _ ) = I (ICastHoleGround (λ _ _ ()) x GProdHole)
... | CIFHCase (_ , _ , _ , _ , _ , _ , _ , refl , _ ) = I (ICastHoleGround (λ _ _ ()) x GProdHole)
... | CIFHFst (_ , _ , refl , _ , _ , _ , _) = I (ICastHoleGround (λ _ _ ()) x GProdHole)
... | CIFHSnd (_ , _ , refl , _ , _ , _ , _) = I (ICastHoleGround (λ _ _ ()) x GProdHole)
... | CIFHCast (_ , _ , refl , _ , GNum , _) = S (_ , Step FHOuter (ITCastFail GNum GProdHole (λ ())) FHOuter)
... | CIFHCast (_ , _ , refl , _ , GArrHole , _) = S (_ , Step FHOuter (ITCastFail GArrHole GProdHole (λ ())) FHOuter)
... | CIFHCast (_ , _ , refl , _ , GSumHole , _) = S (_ , Step FHOuter (ITCastFail GSumHole GProdHole λ ()) FHOuter)
... | CIFHCast (_ , _ , refl , _ , GProdHole , _) = S (_ , Step FHOuter (ITCastSucceed GProdHole) FHOuter)
-- if both are arrows
progress (TACast wt (TCArr {τ1} {τ2} {τ1'} {τ2'} c1 c2)) | I x
with htype-dec (τ1 ==> τ2) (τ1' ==> τ2')
... | Inl refl = S (_ , Step FHOuter ITCastID FHOuter)
... | Inr y = I (ICastArr y x)
-- if both are sums
progress (TACast wt (TCSum {τ1} {τ2} {τ1'} {τ2'} c1 c2)) | I x
with htype-dec (τ1 ⊕ τ2) (τ1' ⊕ τ2')
... | Inl refl = S (_ , Step FHOuter ITCastID FHOuter)
... | Inr y = I (ICastSum y x)
progress (TACast wt (TCProd {τ1} {τ2} {τ1'} {τ2'} c1 c2)) | I x
with htype-dec (τ1 ⊠ τ2) (τ1' ⊠ τ2')
... | Inl refl = S (_ , Step FHOuter ITCastID FHOuter)
... | Inr y = I (ICastProd y x)
-- boxed value cases, inspect how the casts are related by consistency
-- step by ID if the casts are the same
progress (TACast wt TCRefl) | BV x = S (_ , Step FHOuter ITCastID FHOuter)
-- if left is hole
progress (TACast wt (TCHole1 {τ = τ})) | BV x
with τ | ground-decidable τ
... | τ | Inl g = BV (BVHoleCast g x)
... | num | Inr y = abort (y GNum)
... | ⦇-⦈ | Inr y = S (_ , Step FHOuter ITCastID FHOuter)
... | τ1 ==> τ2 | Inr y
with (htype-dec (τ1 ==> τ2) (⦇-⦈ ==> ⦇-⦈))
... | Inl refl = BV (BVHoleCast GArrHole x)
... | Inr y = S (_ , Step FHOuter (ITGround (MGArr y)) FHOuter)
progress (TACast wt (TCHole1 {τ = τ})) | BV x | τ1 ⊕ τ2 | Inr y
with (htype-dec (τ1 ⊕ τ2) (⦇-⦈ ⊕ ⦇-⦈))
... | Inl refl = BV (BVHoleCast GSumHole x)
... | Inr y = S (_ , Step FHOuter (ITGround (MGSum y)) FHOuter)
progress (TACast wt (TCHole1 {τ = τ})) | BV x | τ1 ⊠ τ2 | Inr y
with (htype-dec (τ1 ⊠ τ2) (⦇-⦈ ⊠ ⦇-⦈))
... | Inl refl = BV (BVHoleCast GProdHole x)
... | Inr y = S (_ , Step FHOuter (ITGround (MGProd y)) FHOuter)
-- if right is hole
progress {τ = τ} (TACast wt TCHole2) | BV x
with canonical-boxed-forms-hole wt x
... | d' , τ' , refl , gnd , wt'
with htype-dec τ τ'
... | Inl refl = S (_ , Step FHOuter (ITCastSucceed gnd) FHOuter)
... | Inr x₁
with ground-decidable τ
... | Inl y = S (_ , Step FHOuter (ITCastFail gnd y (flip x₁)) FHOuter)
... | Inr y
with not-ground y
... | Inl refl = S (_ , Step FHOuter ITCastID FHOuter)
... | Inr (Inl (τ1 , τ2 , refl)) = S (_ , Step FHOuter (ITExpand (MGArr (π1 (ground-not-holes y)))) FHOuter)
... | Inr (Inr (Inl (τ1 , τ2 , refl))) = S (_ , Step FHOuter (ITExpand (MGSum (π1 (π2 (ground-not-holes y))))) FHOuter)
... | Inr (Inr (Inr (τ1 , τ2 , refl))) = S (_ , Step FHOuter (ITExpand (MGProd (π2 (π2 (ground-not-holes y))))) FHOuter)
-- if both arrows
progress (TACast wt (TCArr {τ1} {τ2} {τ1'} {τ2'} c1 c2)) | BV x
with htype-dec (τ1 ==> τ2) (τ1' ==> τ2')
... | Inl refl = S (_ , Step FHOuter ITCastID FHOuter)
... | Inr y = BV (BVArrCast y x)
-- if both sums
progress (TACast wt (TCSum {τ1} {τ2} {τ1'} {τ2'} c1 c2)) | BV x
with htype-dec (τ1 ⊕ τ2) (τ1' ⊕ τ2')
... | Inl refl = S (_ , Step FHOuter ITCastID FHOuter)
... | Inr y = BV (BVSumCast y x)
progress (TACast wt (TCProd {τ1} {τ2} {τ1'} {τ2'} c1 c2)) | BV x
with htype-dec (τ1 ⊠ τ2) (τ1' ⊠ τ2')
... | Inl refl = S (_ , Step FHOuter ITCastID FHOuter)
... | Inr y = BV (BVProdCast y x)
-- failed casts
progress (TAFailedCast wt y z w)
with progress wt
... | S (d' , Step x a q) = S (_ , Step (FHFailedCast x) a (FHFailedCast q))
... | I x = I (IFailedCast (FIndet x) y z w)
... | BV x = I (IFailedCast (FBoxedVal x) y z w)
| {
"alphanum_fraction": 0.5415083537,
"avg_line_length": 56.3431085044,
"ext": "agda",
"hexsha": "2c0fe1e6e4af6e4504f1486c7a591b609eed08a5",
"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": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-agda",
"max_forks_repo_path": "progress.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"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": "hazelgrove/hazelnut-agda",
"max_issues_repo_path": "progress.agda",
"max_line_length": 122,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-agda",
"max_stars_repo_path": "progress.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7732,
"size": 19213
} |
{-# OPTIONS --type-in-type #-}
open import Data.Empty
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
open import Function.Base using (_∘_; id)
open import Relation.Nullary using (¬_)
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl; subst; cong; sym)
record _◁_ {ℓ} (A B : Set ℓ) : Set ℓ where
constructor _,_,_
field
ϕ : A → B
ψ : B → A
retract : ψ ∘ ϕ ≡ id
open _◁_
record _◁′_ {ℓ} (A B : Set ℓ) : Set ℓ where
constructor _,_,_
field
ϕ : A → B
ψ : B → A
retract : A ◁ B → ψ ∘ ϕ ≡ id
open _◁′_
postulate
EM : ∀ {ℓ} (A : Set ℓ) → A ⊎ (¬ A)
℘ : ∀ {ℓ} → Set ℓ → Set _
℘ X = X → Set
t : ∀ {ℓ} (A B : Set ℓ) → ℘ A ◁′ ℘ B
t A B with EM (℘ A ◁ ℘ B)
... | inj₁ ℘A◁℘B =
let ϕ , ψ , retract = ℘A◁℘B
in ϕ , ψ , λ _ → retract
... | inj₂ ¬℘A◁℘B =
(λ _ _ → ⊥) , (λ _ _ → ⊥) , λ ℘A◁℘B → ⊥-elim (¬℘A◁℘B ℘A◁℘B)
-- type-in-type allows U to be put into Set...
U : Set
U = ∀ X → ℘ X
-- ...so that u: U can be applied to U itself
projᵤ : U → ℘ U
projᵤ u = u U
injᵤ : ℘ U → U
injᵤ f X =
let _ , ψ , _ = t X U
ϕ , _ , _ = t U U
in ψ (ϕ f)
projᵤ∘injᵤ : projᵤ ∘ injᵤ ≡ id
projᵤ∘injᵤ = retract (t U U) (id , id , refl)
_∈_ : U → U → Set
u ∈ v = projᵤ u v
Russell : ℘ U
Russell u = ¬ u ∈ u
r : U
r = injᵤ Russell
-- up to here EM + impredicativity is enough,
-- as long as _≡_ itself is in the impredicative universe,
-- but to go further, large elimination (via subst) is required
r∈r≡r∉r : r ∈ r ≡ (¬ r ∈ r)
r∈r≡r∉r = cong (λ f → f Russell r) projᵤ∘injᵤ
r∉r : ¬ r ∈ r
r∉r r∈r =
let r∈r→r∉r = subst id r∈r≡r∉r
in r∈r→r∉r r∈r r∈r
false : ⊥
false =
let r∉r→r∈r = subst id (sym r∈r≡r∉r)
in r∉r (r∉r→r∈r r∉r)
| {
"alphanum_fraction": 0.5298287064,
"avg_line_length": 21.1625,
"ext": "agda",
"hexsha": "181e6c8d4453fc9b881090cd410cc1c358842807",
"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": "d54cdaf24391b2726e491a18cba2d2d8ae3ac20b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ionathanch/ionathanch.github.io",
"max_forks_repo_path": "_assets/agda/Berardi.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d54cdaf24391b2726e491a18cba2d2d8ae3ac20b",
"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": "ionathanch/ionathanch.github.io",
"max_issues_repo_path": "_assets/agda/Berardi.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d54cdaf24391b2726e491a18cba2d2d8ae3ac20b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ionathanch/ionathanch.github.io",
"max_stars_repo_path": "_assets/agda/Berardi.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 843,
"size": 1693
} |
module Preliminaries where
-- universe levels
postulate
Level : Set
lZ : Level
lS : Level -> Level
lmax : Level -> Level -> Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO lZ #-}
{-# BUILTIN LEVELSUC lS #-}
{-# BUILTIN LEVELMAX lmax #-}
-- ----------------------------------------------------------------------
-- functions
_o_ : {A B C : Set} → (B → C) → (A → B) → A → C
g o f = \ x → g (f x)
infixr 10 _o_
-- ----------------------------------------------------------------------
-- identity type
data _==_ {l : Level} {A : Set l} (M : A) : A → Set l where
Refl : M == M
{-# BUILTIN EQUALITY _==_ #-}
{-# BUILTIN REFL Refl #-}
transport : {l1 : Level} {l2 : Level} {A : Set l1} (B : A → Set l2)
{a1 a2 : A} → a1 == a2 → (B a1 → B a2)
transport B Refl = λ x → x
! : {l : Level} {A : Set l} {M N : A} → M == N → N == M
! Refl = Refl
_∘_ : {l : Level} {A : Set l} {M N P : A}
→ N == P → M == N → M == P
β ∘ Refl = β
ap : {l1 l2 : Level} {A : Set l1} {B : Set l2} {M N : A}
(f : A → B) → M == N → (f M) == (f N)
ap f Refl = Refl
ap2 : {l1 l2 l3 : Level} {A : Set l1} {B : Set l2} {C : Set l3} {M N : A} {M' N' : B} (f : A -> B -> C) -> M == N -> M' == N' -> (f M M') == (f N N')
ap2 f Refl Refl = Refl
postulate
-- function extensionality
λ= : {l1 l2 : Level} {A : Set l1} {B : A -> Set l2} {f g : (x : A) -> B x} -> ((x : A) -> (f x) == (g x)) -> f == g
-- function extensionality for implicit functions
λ=i : {l1 l2 : Level} {A : Set l1} {B : A -> Set l2} {f g : {x : A} -> B x} -> ((x : A) -> (f {x}) == (g {x})) -> _==_ {_}{ {x : A} → B x } f g
private primitive primTrustMe : {l : Level} {A : Set l} {x y : A} -> x == y
infixr 9 _==_
infix 2 _∎
infixr 2 _=〈_〉_
_=〈_〉_ : {l : Level} {A : Set l} (x : A) {y z : A} → x == y → y == z → x == z
_ =〈 p1 〉 p2 = (p2 ∘ p1)
_∎ : {l : Level} {A : Set l} (x : A) → x == x
_∎ _ = Refl
-- ----------------------------------------------------------------------
-- product types
record Unit : Set where
constructor <>
record Σ {l1 l2 : Level} {A : Set l1} (B : A -> Set l2) : Set (lmax l1 l2) where
constructor _,_
field
fst : A
snd : B fst
open Σ public
infixr 0 _,_
_×_ : {l1 l2 : Level} → Set l1 -> Set l2 -> Set (lmax l1 l2)
A × B = Σ (\ (_ : A) -> B)
infixr 10 _×_
-- ----------------------------------------------------------------------
-- booleans
data Bool : Set where
True : Bool
False : Bool
{-# COMPILED_DATA Bool Bool True False #-}
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE True #-}
{-# BUILTIN FALSE False #-}
-- ----------------------------------------------------------------------
-- order
data Order : Set where
Less : Order
Equal : Order
Greater : Order
-- ----------------------------------------------------------------------
-- sums
data Void : Set where
abort : {A : Set} → Void → A
abort ()
data Either (A B : Set) : Set where
Inl : A → Either A B
Inr : B → Either A B
DecEq : Set → Set
DecEq A = (x y : A) → Either (x == y) (x == y → Void)
-- ----------------------------------------------------------------------
-- natural numbers
module Nat where
data Nat : Set where
Z : Nat
S : Nat -> Nat
-- let's you use numerals for Nat
{-# BUILTIN NATURAL Nat #-}
{-# BUILTIN SUC S #-}
{-# BUILTIN ZERO Z #-}
_+_ : Nat → Nat → Nat
Z + n = n
(S m) + n = S (m + n)
max : Nat → Nat → Nat
max Z n = n
max m Z = m
max (S m) (S n) = S (max m n)
equal : Nat → Nat → Bool
equal Z Z = True
equal Z (S _) = False
equal (S _) Z = False
equal (S m) (S n) = equal m n
compare : Nat → Nat → Order
compare Z Z = Equal
compare Z (S m) = Less
compare (S n) Z = Greater
compare (S n) (S m) = compare n m
open Nat public using (Nat ; Z ; S)
-- ----------------------------------------------------------------------
-- monad
module Monad where
record Monad : Set1 where
field
T : Set → Set
return : ∀ {A} → A → T A
_>>=_ : ∀ {A B} → T A → (A → T B) -> T B
-- ----------------------------------------------------------------------
-- options
module Maybe where
data Maybe {l : Level} (A : Set l) : Set l where
Some : A → Maybe A
None : Maybe A
Monad : Monad.Monad
Monad = record { T = Maybe; return = Some; _>>=_ = (λ {None _ → None; (Some v) f → f v}) }
open Maybe public using (Maybe;Some;None)
-- ----------------------------------------------------------------------
-- lists
module List where
data List {l : Level} (A : Set l) : Set l where
[] : List A
_::_ : A -> List A -> List A
{-# COMPILED_DATA List [] [] (:) #-}
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _::_ #-}
infixr 99 _::_
_++_ : {A : Set} → List A → List A → List A
[] ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
infixr 10 _++_
map : {l1 l2 : Level} {A : Set l1} {B : Set l2} → (A → B) → List A → List B
map f [] = []
map f (x :: xs) = f x :: map f xs
map-id : {l : Level} {A : Set l} (l : List A) → map (\ (x : A) → x) l == l
map-id [] = Refl
map-id (x :: l) with map (\ x -> x) l | map-id l
... | ._ | Refl = Refl
module Uninformative where
-- simply typed version
peelOff : {A : Set} (eq : A → A → Bool) → List A → List A → Maybe (List A)
peelOff eq [] ys = Some ys
peelOff eq (_ :: _) [] = None
peelOff eq (x :: xs) (y :: ys) with eq x y
... | False = None
... | True = peelOff eq xs ys
peelOff : {A : Set} (eq : DecEq A) → (xs ys : List A) → Maybe (Σ \ zs → (xs ++ zs) == ys )
peelOff eq [] ys = Some (ys , Refl)
peelOff eq (_ :: _) [] = None
peelOff eq (x :: xs) (y :: ys) with eq x y
... | Inr xyneq = None
peelOff eq (x :: xs) (.x :: ys) | Inl Refl with peelOff eq xs ys
peelOff eq (x :: xs) (.x :: .(xs ++ zs)) | Inl Refl | Some (zs , Refl) = Some (zs , Refl)
... | None = None
[_] : {A : Set} → A → List A
[ c ] = c :: []
++-assoc : ∀ {A} (l1 l2 l3 : List A) → (l1 ++ l2) ++ l3 == l1 ++ (l2 ++ l3)
++-assoc [] l2 l3 = Refl
++-assoc (x :: xs) l2 l3 = ap (_::_ x) (++-assoc xs l2 l3)
open List public using (List ; [] ; _::_)
-- ----------------------------------------------------------------------
-- characters
module Char where
postulate {- Agda Primitive -}
Char : Set
{-# BUILTIN CHAR Char #-}
{-# COMPILED_TYPE Char Char #-}
private
primitive
primCharToNat : Char → Nat
primCharEquality : Char → Char → Bool
toNat : Char → Nat
toNat = primCharToNat
equalb : Char -> Char -> Bool
equalb = primCharEquality
-- need to go outside the real language a little to give the primitives good types,
-- but from the outside this should be safe
equal : DecEq Char
equal x y with equalb x y
... | True = Inl primTrustMe
... | False = Inr canthappen where
postulate canthappen : _
open Char public using (Char)
-- ----------------------------------------------------------------------
-- vectors
module Vector where
data Vec (A : Set) : Nat → Set where
[] : Vec A 0
_::_ : ∀ {n} → A → Vec A n → Vec A (S n)
infixr 99 _::_
Vec-elim : {A : Set} (P : {n : Nat} → Vec A n → Set)
→ (P [])
→ ({n : Nat} (x : A) (xs : Vec A n) → P xs → P (x :: xs))
→ {n : Nat} (v : Vec A n) → P v
Vec-elim P n c [] = n
Vec-elim P n c (y :: ys) = c y ys (Vec-elim P n c ys)
fromList : {A : Set} → List A → Σ \n → Vec A n
fromList [] = _ , []
fromList (x :: xs) = _ , x :: snd (fromList xs)
toList : {A : Set} {n : Nat} → Vec A n → List A
toList [] = []
toList (x :: xs) = x :: (toList xs)
toList' : {A : Set} → (Σ \ n → Vec A n) → List A
toList' (._ , []) = []
toList' (._ , (x :: xs)) = x :: (toList' (_ , xs))
to-from : {A : Set} (l : List A) → toList' (fromList l) == l
to-from [] = Refl
to-from (x :: l) with toList' (fromList l) | to-from l
to-from (x :: l) | .l | Refl = Refl
from-to : {A : Set} (l : Σ \n → Vec A n) → fromList (toList' l) == l
from-to (._ , []) = Refl
from-to (._ , x :: l) with fromList (toList' (_ , l)) | from-to (_ , l)
from-to (.(S n) , _::_ {n} x l) | .(n , l) | Refl = Refl
-- ----------------------------------------------------------------------
-- strings
module String where
postulate {- Agda Primitive -}
String : Set
{-# BUILTIN STRING String #-}
{-# COMPILED_TYPE String String #-}
private
primitive
primStringToList : String -> List Char
primStringFromList : List Char -> String
primStringAppend : String -> String -> String
primStringEquality : String -> String -> Bool
equal : String -> String -> Bool
equal = primStringEquality
toList = primStringToList
fromList = primStringFromList
append = primStringAppend
toVec : String -> Σ \ m → Vector.Vec Char m
toVec = Vector.fromList o toList
-- ----------------------------------------------------------------------
-- fancy order
module FancyOrder where
data FancyOrder {A : Set} {_≤_ : A → A → Set} (a1 a2 : A) : Set where
Less : a1 ≤ a2 -> (a1 == a2 -> Void) → FancyOrder a1 a2
Equal : a1 == a2 -> FancyOrder a1 a2
Greater : a2 ≤ a1 → (a1 == a2 -> Void) -> FancyOrder a1 a2
record DecidableOrder : Set1 where
field
A : Set
_≤_ : A → A → Set
≤-refl : ∀ {a} → a ≤ a
≤-trans : ∀ {a1 a2 a3} → a1 ≤ a2 -> a2 ≤ a3 -> a1 ≤ a3
≤-saturated : ∀ {a1 a2} -> a1 ≤ a2 -> a2 ≤ a1 -> a1 == a2
compare : (a1 a2 : A) → FancyOrder {A}{_≤_} a1 a2
≤-refl' : ∀ {a1 a2} → a1 == a2 -> a1 ≤ a2
≤-refl' Refl = ≤-refl
min : A → A → A
min a1 a2 with compare a1 a2
... | Less _ _ = a1
... | Equal _ = a1
... | Greater _ _ = a2
min-≤-1 : {a1 a2 : A} → min a1 a2 ≤ a1
min-≤-1 {a1}{a2} with compare a1 a2
... | Less lt _ = ≤-refl
... | Equal eq = ≤-refl
... | Greater gt _ = gt
min-≤-2 : {a1 a2 : A} → min a1 a2 ≤ a2
min-≤-2 {a1}{a2} with compare a1 a2
... | Less lt _ = lt
min-≤-2 | Equal Refl = ≤-refl
... | Greater gt _ = ≤-refl
min-sym : {a1 a2 : A} → min a1 a2 == min a2 a1
min-sym {a1}{a2} with compare a1 a2 | compare a2 a1
min-sym | Less lt12 _ | Less lt21 _ = ≤-saturated lt12 lt21
min-sym | Less lt12 _ | Equal Refl = Refl
min-sym | Less lt12 _ | Greater gt21 _ = Refl
min-sym | Equal eq12 | Less lt21 _ = eq12
min-sym | Equal eq12 | Equal eq21 = eq12
min-sym | Equal eq12 | Greater gt21 _ = Refl
min-sym | Greater gt12 _ | Less lt21 _ = Refl
min-sym | Greater gt12 _ | Equal eq21 = Refl
min-sym | Greater gt12 _ | Greater gt21 _ = ≤-saturated gt12 gt21
min-≤ : {a1 a2 : A} → a1 ≤ a2 -> (min a1 a2) == a1
min-≤ {a1} {a2} lt1 with compare a1 a2
... | Less lt _ = Refl
... | Equal eq = Refl
... | Greater gt _ = ≤-saturated gt lt1
max : A → A → A
max a1 a2 with compare a1 a2
... | Less _ _ = a2
... | Equal _ = a2
... | Greater _ _ = a1
max-≥-1 : {a1 a2 : A} → a1 ≤ max a1 a2
max-≥-1 {a1}{a2} with compare a1 a2
... | Less lt _ = lt
max-≥-1 | Equal Refl = ≤-refl
... | Greater gt _ = ≤-refl
max-≥-2 : {a1 a2 : A} → a2 ≤ max a1 a2
max-≥-2 {a1}{a2} with compare a1 a2
... | Less lt _ = ≤-refl
... | Equal eq = ≤-refl
... | Greater gt _ = gt
min-monotone : {a1 a1' a2 a2' : A} → a1 ≤ a1' -> a2 ≤ a2' -> min a1 a2 ≤ min a1' a2'
min-monotone {a1}{a1'}{a2}{a2'} lt1 lt2 with compare a1 a2 | compare a1' a2'
min-monotone lt1 lt2 | Less x x₁ | Less x₂ x₃ = lt1
min-monotone lt1 lt2 | Less x x₁ | Equal x₂ = lt1
min-monotone lt1 lt2 | Less x x₁ | Greater x₂ x₃ = ≤-trans x lt2
min-monotone lt1 lt2 | Equal x | Less x₁ x₂ = lt1
min-monotone lt1 lt2 | Equal x | Equal x₁ = lt1
min-monotone lt1 lt2 | Equal Refl | Greater x₁ x₂ = lt2
min-monotone lt1 lt2 | Greater x x₁ | Less x₂ x₃ = ≤-trans x lt1
min-monotone lt1 lt2 | Greater x x₁ | Equal x₂ = ≤-trans x lt1
min-monotone lt1 lt2 | Greater x x₁ | Greater x₂ x₃ = lt2
max-sym : {a1 a2 : A} → max a1 a2 == max a2 a1
max-sym {a1}{a2} with compare a1 a2 | compare a2 a1
max-sym | Less lt12 _ | Less lt21 _ = ≤-saturated lt21 lt12
max-sym | Less lt12 _ | Equal eq21 = eq21
max-sym | Less lt12 _ | Greater gt21 _ = Refl
max-sym | Equal eq12 | Less lt21 _ = ! eq12
max-sym | Equal eq12 | Equal eq21 = eq21
max-sym | Equal eq12 | Greater gt21 _ = Refl
max-sym | Greater gt12 _ | Less lt21 _ = Refl
max-sym | Greater gt12 _ | Equal eq21 = Refl
max-sym | Greater gt12 _ | Greater gt21 _ = ≤-saturated gt21 gt12
max-≤ : {a1 a2 : A} → a1 ≤ a2 -> (max a1 a2) == a2
max-≤ {a1} {a2} lt1 with compare a1 a2
... | Less lt _ = Refl
... | Equal eq = Refl
... | Greater gt _ = ≤-saturated lt1 gt
max-monotone : {a1 a1' a2 a2' : A} → a1 ≤ a1' -> a2 ≤ a2' -> max a1 a2 ≤ max a1' a2'
max-monotone {a1}{a1'}{a2}{a2'} lt1 lt2 with compare a1 a2 | compare a1' a2'
max-monotone lt1 lt2 | Less x x₁ | Less x₂ x₃ = lt2
max-monotone lt1 lt2 | Less x x₁ | Equal x₂ = lt2
max-monotone lt1 lt2 | Less x x₁ | Greater x₂ x₃ = ≤-trans lt2 x₂
max-monotone lt1 lt2 | Equal x | Less x₁ x₂ = lt2
max-monotone lt1 lt2 | Equal x | Equal x₁ = lt2
max-monotone lt1 lt2 | Equal Refl | Greater x₁ x₂ = lt1
max-monotone lt1 lt2 | Greater x x₁ | Less x₂ x₃ = ≤-trans lt1 x₂
max-monotone lt1 lt2 | Greater x x₁ | Equal Refl = lt1
max-monotone lt1 lt2 | Greater x x₁ | Greater x₂ x₃ = lt1 | {
"alphanum_fraction": 0.4581667719,
"avg_line_length": 30.7969762419,
"ext": "agda",
"hexsha": "3d8d71347aa28d33da9f0397149108b2f1382d48",
"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": "785c3d1f93ce2dac7801504b806abfd59f3875f6",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "ayberkt/system-t-normalization",
"max_forks_repo_path": "Preliminaries.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "785c3d1f93ce2dac7801504b806abfd59f3875f6",
"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": "ayberkt/system-t-normalization",
"max_issues_repo_path": "Preliminaries.agda",
"max_line_length": 151,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "785c3d1f93ce2dac7801504b806abfd59f3875f6",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "ayberkt/system-t-normalization",
"max_stars_repo_path": "Preliminaries.agda",
"max_stars_repo_stars_event_max_datetime": "2016-06-25T03:40:58.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-24T14:36:42.000Z",
"num_tokens": 5084,
"size": 14259
} |
{-# OPTIONS --without-K #-}
-- From nlab: FinSet is the category of finite sets and all functions
-- between them: the full subcategory of Set on finite sets. It is
-- easy (and thus common) to make FinSet skeletal; there is one object
-- for each natural number n (including n=0), and a morphism from m to
-- n is an m-tuple (f0,…,fm−1) of numbers satisfying 0≤fi<n. This
-- amounts to identifying n with the set {0,…,n−1}. (Sometimes {1,…,n}
-- is used instead.) This is exactly what we do below.
module SkFinSetCategory where
------------------------------------------------------------------------------
-- Categorical structure
import Level
open import Data.Nat using (ℕ; _+_; _*_)
open import Data.Fin using (Fin; inject+; raise; zero; suc)
open import Function using (_∘_; id)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; cong₂)
open import Relation.Binary.PropositionalEquality.Core using (isEquivalence)
open import Categories.Category using (Category; module Category)
open import Categories.Functor using (Functor; module Functor)
open import Categories.Bifunctor using (Bifunctor)
open import Categories.NaturalTransformation
using (module NaturalTransformation)
renaming (id to idn)
open import Categories.Monoidal using (Monoidal)
open import Categories.Monoidal.Helpers using (module MonoidalHelperFunctors)
open import Categories.Monoidal.Braided using (Braided; module Braided)
open import FinVec
open F
-- Objects are natural numbers which are proxies for finite sets of
-- the given size; morphisms between m and n are finite functions, Vec
-- (Fin n) m, mapping each element of Fin m to an element in Fin
-- n. Two morphisms are considered the same if they are ≡ to each other.
finVecC : Category Level.zero Level.zero Level.zero
finVecC = record {
Obj = ℕ ;
_⇒_ = FinVec ;
_≡_ = _≡_ ;
id = 1C ;
_∘_ = _∘̂_ ;
assoc = λ { {f = f} {g = g} {h = h} → sym (∘̂-assoc h g f) } ;
identityˡ = λ { {f = f} → ∘̂-lid f } ;
identityʳ = λ { {f = f} → ∘̂-rid f } ;
equiv = isEquivalence ;
∘-resp-≡ = cong₂ _∘̂_
}
⊕-bifunctor : Bifunctor finVecC finVecC finVecC
⊕-bifunctor = record {
F₀ = λ { (m , n) → m + n } ;
F₁ = λ { (f , g) → f ⊎c g } ;
identity = λ { { (m , n) } → 1C⊎1C≡1C {m} {n} } ;
homomorphism = λ { {(x₁ , x₂)} {(y₁ , y₂)} {(z₁ , z₂)} {(x₁y₁ , x₂y₂)} {(y₁z₁ , y₂z₂)} →
sym (⊎c-distrib {p₁ = y₁z₁} {p₂ = y₂z₂} {p₃ = x₁y₁} {p₄ = x₂y₂}) } ;
F-resp-≡ = λ { {(x₁ , x₂)} {(y₁ , y₂)} {(p₁ , p₂)} {(p₃ , p₄)} (p₁≡p₃ , p₂≡p₄) →
cong₂ _⊎c_ p₁≡p₃ p₂≡p₄ }
}
⊗-bifunctor : Bifunctor finVecC finVecC finVecC
⊗-bifunctor = record {
F₀ = λ { (m , n) → m * n } ;
F₁ = λ { (f , g) → f ×c g } ;
identity = λ { { (m , n) } → 1C×1C≡1C {m} {n} } ;
homomorphism = λ { {(x₁ , x₂)} {(y₁ , y₂)} {(z₁ , z₂)} {(x₁y₁ , x₂y₂)} {(y₁z₁ , y₂z₂)} →
sym (×c-distrib {p₁ = y₁z₁} {p₂ = y₂z₂} {p₃ = x₁y₁} {p₄ = x₂y₂}) } ;
F-resp-≡ = λ { {(x₁ , x₂)} {(y₁ , y₂)} {(p₁ , p₂)} {(p₃ , p₄)} (p₁≡p₃ , p₂≡p₄) →
cong₂ _×c_ p₁≡p₃ p₂≡p₄ }
}
{--
CommutativeSquare f g h i = h ∘ f ≡ i ∘ g
Functor (C D):
F₀ : C.Obj → D.Obj
F₁ : ∀ {A B} → C [ A , B ] → D [ F₀ A , F₀ B ]
identity : ∀ {A} → D [ F₁ (C.id {A}) ≡ D.id ]
homomorphism : ∀ {X Y Z} {f : C [ X , Y ]} {g : C [ Y , Z ]}
→ D [ F₁ (C [ g ∘ f ]) ≡ D [ F₁ g ∘ F₁ f ] ]
F-resp-≡ : ∀ {A B} {F G : C [ A , B ]} → C [ F ≡ G ] → D [ F₁ F ≡ F₁ G ]
NaturalTransformation (F G : Functor C D):
η : ∀ X → D [ F₀ X , G₀ X ]
commute : ∀ {X Y} (f : C [ X , Y ]) → D.CommutativeSquare (F₁ f) (η X) (η Y) (G₁ f)
NaturalIsomorphism (F G : Functor C D):
F⇒G : NaturalTransformation F G
F⇐G : NaturalTransformation G F
iso : ∀ X → Iso (⇒.η X) (⇐.η X)
Monoidal (C : Category):
identityˡ : NaturalIsomorphism id⊗x x
identityʳ : NaturalIsomorphism x⊗id x
assoc : NaturalIsomorphism [x⊗y]⊗z x⊗[y⊗z]
triangle : TriangleLeftSide ≡ⁿ (TriangleRightSide ∘₁ TriangleTopSide)
pentagon : (PentagonNESide ∘₁ PentagonNWSide) ≡ⁿ
(PentagonSESide ∘₁ (PentagonSSide ∘₁ PentagonSWSide))
--}
private module CFV = Category finVecC
private module MFunctors = MonoidalHelperFunctors finVecC ⊕-bifunctor 0
private module Fid⊗x = Functor MFunctors.id⊗x
private module Fx = Functor MFunctors.x
finVecAdditiveM : Monoidal finVecC -- power = Fin 1 (so apply everything to zero)
finVecAdditiveM = record {
⊗ = ⊕-bifunctor ;
id = 0 ;
identityˡ = record {
F⇒G = record { -- F, G : (0C ⊎ x) ⇒ x
η = λ X → 1C ;
commute = λ f → trans (∘̂-lid (1C ⊎c f zero)) (trans 1C₀⊎x≡x (sym (∘̂-rid (f zero)))) -- ntp ηY ∘̂ (0C ⊎ f) ≡ f ∘̂ ηX
} ;
F⇐G = record {
η = λ _ → 1C ;
commute = λ f → trans (∘̂-lid (f zero)) (trans (sym 1C₀⊎x≡x) (sym (∘̂-rid (1C ⊎c f zero))))
} ;
iso = λ X → record { isoˡ = ∘̂-rid 1C ; isoʳ = ∘̂-lid 1C }
} ;
identityʳ = record {
F⇒G = record {
η = λ X → uniti+ ;
commute = λ f → idʳ⊕ {x = f zero}
} ;
F⇐G = record {
η = λ X → unite+ ;
commute = λ f → {!!}
} ;
iso = λ X → record { isoˡ = unite+∘̂uniti+~id ; isoʳ = uniti+∘̂unite+~id }
} ;
assoc = record
{ F⇒G = record { η = λ X → assocl+ {m = X zero}
; commute = λ f → {!!} }
; F⇐G = record { η = λ X → assocr+ {m = X zero}
; commute = {!!} }
; iso = λ X → record { isoˡ = assocr+∘̂assocl+~id {m = X zero}
; isoʳ = assocl+∘̂assocr+~id {m = X zero}
}
} ;
triangle = {!!} ;
pentagon = {!!}
}
-- where
-- private module FVC = Category finVecC
-- private module MFunctors = MonoidalHelperFunctors finVecC ⊕-bifunctor 0
-- private module FF = Functor MFunctors.id⊗x
-- private module GF = Functor MFunctors.x
{--
-- Commutative semiring structure
import Level
open import Algebra
open import Algebra.Structures
open import Relation.Binary.Core
open import Relation.Binary.PropositionalEquality using (subst; sym; trans; cong₂)
open F
_cauchy≃_ : (m n : ℕ) → Set
m cauchy≃ n = FinVec m n
id-iso : {m : ℕ} → FinVec m m
id-iso = 1C
private
postulate sym-iso : {m n : ℕ} → FinVec m n → FinVec n m
trans-iso : {m n o : ℕ} → FinVec m n → FinVec n o → FinVec m o
trans-iso c₁ c₂ = c₂ ∘̂ c₁
cauchy≃IsEquiv : IsEquivalence {Level.zero} {Level.zero} {ℕ} _cauchy≃_
cauchy≃IsEquiv = record {
refl = id-iso ;
sym = sym-iso ;
trans = trans-iso
}
cauchyPlusIsSG : IsSemigroup {Level.zero} {Level.zero} {ℕ} _cauchy≃_ _+_
cauchyPlusIsSG = record {
isEquivalence = cauchy≃IsEquiv ;
assoc = λ m n o → assocl+ {m} {n} {o} ;
∙-cong = _⊎c_
}
cauchyTimesIsSG : IsSemigroup {Level.zero} {Level.zero} {ℕ} _cauchy≃_ _*_
cauchyTimesIsSG = record {
isEquivalence = cauchy≃IsEquiv ;
assoc = λ m n o → assocl* {m} {n} {o} ;
∙-cong = _×c_
}
cauchyPlusIsCM : IsCommutativeMonoid _cauchy≃_ _+_ 0
cauchyPlusIsCM = record {
isSemigroup = cauchyPlusIsSG ;
identityˡ = λ m → 1C ;
comm = λ m n → swap+cauchy n m
}
cauchyTimesIsCM : IsCommutativeMonoid _cauchy≃_ _*_ 1
cauchyTimesIsCM = record {
isSemigroup = cauchyTimesIsSG ;
identityˡ = λ m → uniti* {m} ;
comm = λ m n → swap⋆cauchy n m
}
cauchyIsCSR : IsCommutativeSemiring _cauchy≃_ _+_ _*_ 0 1
cauchyIsCSR = record {
+-isCommutativeMonoid = cauchyPlusIsCM ;
*-isCommutativeMonoid = cauchyTimesIsCM ;
distribʳ = λ o m n → factor*+ {m} {n} {o} ;
zeroˡ = λ m → 0C
}
cauchyCSR : CommutativeSemiring Level.zero Level.zero
cauchyCSR = record {
Carrier = ℕ ;
_≈_ = _cauchy≃_ ;
_+_ = _+_ ;
_*_ = _*_ ;
0# = 0 ;
1# = 1 ;
isCommutativeSemiring = cauchyIsCSR
}
------------------------------------------------------------------------------
-- Groupoid structure
open import Groupoid
private
postulate linv : {m n : ℕ} (c : FinVec m n) → (sym-iso c) ∘̂ c ≡ 1C
postulate rinv : {m n : ℕ} (c : FinVec m n) → c ∘̂ (sym-iso c) ≡ 1C
G : 1Groupoid
G = record {
set = ℕ ;
_↝_ = _cauchy≃_ ;
_≈_ = _≡_ ;
id = id-iso ;
_∘_ = λ c₁ c₂ → trans-iso c₂ c₁ ;
_⁻¹ = sym-iso ;
lneutr = ∘̂-lid ;
rneutr = ∘̂-rid ;
assoc = λ c₁ c₂ c₃ → sym (∘̂-assoc c₁ c₂ c₃) ;
equiv = record {
refl = refl ;
sym = sym ;
trans = trans
} ;
linv = linv ;
rinv = rinv ;
∘-resp-≈ = cong₂ _∘̂_
}
--}
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.5537548505,
"avg_line_length": 32.6940298507,
"ext": "agda",
"hexsha": "a4a62be140dec14f804e59fd242c01bef7934309",
"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/SkFinSetCategory.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/SkFinSetCategory.agda",
"max_line_length": 123,
"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/SkFinSetCategory.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": 3464,
"size": 8762
} |
open import Lemmachine
module Lemmachine.Lemmas (hooks : Hooks) where
import Lemmachine.Resolve
open import Data.Empty
open import Data.String
open import Data.Maybe
open import Data.Function
open import Data.Product hiding (map)
open import Data.List.Any hiding (map) renaming (any to any₂)
open import Relation.Nullary
open Membership-≡ public
open import Relation.Binary.PropositionalEquality public
open import Relation.Binary.PropositionalEquality.TrustMe
private
resource : Resource
resource = toResource hooks
open Request public
open Resource resource public
open Lemmachine.Resolve resource public
private
eqMethod-refl : ∀ m → eqMethod m m ≡ true
eqMethod-refl HEAD = refl
eqMethod-refl GET = refl
eqMethod-refl PUT = refl
eqMethod-refl DELETE = refl
eqMethod-refl POST = refl
eqMethod-refl TRACE = refl
eqMethod-refl CONNECT = refl
eqMethod-refl OPTIONS = refl
methodIsMember : ∀ r → (methods : List Method)
→ method r ∈ methods
→ any (eqMethod (method r))
methods ≡ true
methodIsMember _ [] ()
methodIsMember _ (x ∷ _) (here p) rewrite p with eqMethod-refl x
... | p₂ rewrite p₂ = refl
methodIsMember r (x ∷ xs) (there ps) with eqMethod (method r) x | methodIsMember r xs ps
... | true | _ = refl
... | false | p rewrite p = refl
methodIsKnown : ∀ r → method r ∈ knownMethods r
→ any (eqMethod (method r))
(knownMethods r) ≡ true
methodIsKnown r p = methodIsMember r (knownMethods r) p
methodIsAllowed : ∀ r → method r ∈ allowedMethods r
→ any (eqMethod (method r))
(allowedMethods r) ≡ true
methodIsAllowed r p = methodIsMember r (allowedMethods r) p
postulate
methodIsntAllowed : ∀ r → method r ∉ allowedMethods r
→ any (eqMethod (method r))
(allowedMethods r) ≡ false
notOptions : ∀ r → method r ≢ OPTIONS
→ eqMethod (method r) OPTIONS ≡ false
notOptions r p with method r
... | HEAD = refl
... | GET = refl
... | PUT = refl
... | DELETE = refl
... | POST = refl
... | TRACE = refl
... | CONNECT = refl
... | OPTIONS = ⊥-elim (p refl)
private
==-refl : ∀ s → (s == s) ≡ true
==-refl s = trustMe
headerIsMember : (header : String)
→ (headers : RequestHeaders)
→ header ∈ map headerKey headers
→ ∃ λ v → fetchHeader header headers ≡ just v
headerIsMember _ [] ()
headerIsMember _ ((k , v) ∷ _) (here p) rewrite p with ==-refl k
... | p₂ rewrite p₂ = v , refl
headerIsMember header ((k , v) ∷ xs) (there ps) with header ≟ k | headerIsMember header xs ps
... | yes _ | _ = v , refl
... | no _ | v₂ , p with any₂ (_≟_ header ∘ headerKey) xs
... | yes _ rewrite p = v₂ , refl
... | no _ = v₂ , p
acceptIsHeader : ∀ r → "Accept" ∈ map headerKey (headers r)
→ ∃ λ v → fetchHeader "Accept" (headers r) ≡ just v
acceptIsHeader r p with headerIsMember "Accept" (headers r) p
... | v , p₂ with fetchHeader "Accept" (headers r) | p₂
... | ._ | refl = v , refl
acceptLanguageIsHeader : ∀ r → "Accept-Language" ∈ map headerKey (headers r)
→ ∃ λ v → fetchHeader "Accept-Language" (headers r) ≡ just v
acceptLanguageIsHeader r p with headerIsMember "Accept-Language" (headers r) p
... | v , p₂ with fetchHeader "Accept-Language" (headers r) | p₂
... | ._ | refl = v , refl
| {
"alphanum_fraction": 0.6155612977,
"avg_line_length": 35.5408163265,
"ext": "agda",
"hexsha": "f58b2989ff048d7f84870dd72436828ba3052117",
"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": "src/Lemmachine/Lemmas.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": "src/Lemmachine/Lemmas.agda",
"max_line_length": 95,
"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": "src/Lemmachine/Lemmas.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": 973,
"size": 3483
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Equivalence.Properties where
open import Level
open import Categories.Adjoint.Equivalence using (⊣Equivalence)
open import Categories.Adjoint.TwoSided using (_⊣⊢_; withZig)
open import Categories.Category.Core
open import Categories.Category.Equivalence using (WeakInverse; StrongEquivalence)
import Categories.Morphism.Reasoning as MR
import Categories.Morphism.Properties as MP
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Properties using ([_]-resp-Iso)
open import Categories.NaturalTransformation using (ntHelper; _∘ᵥ_; _∘ˡ_; _∘ʳ_)
open import Categories.NaturalTransformation.NaturalIsomorphism as ≃
using (NaturalIsomorphism ; unitorˡ; unitorʳ; associator; _ⓘᵥ_; _ⓘˡ_; _ⓘʳ_)
private
variable
o ℓ e : Level
C D E : Category o ℓ e
module _ {F : Functor C D} {G : Functor D C} (W : WeakInverse F G) where
open WeakInverse W
private
module C = Category C
module D = Category D
module F = Functor F
module G = Functor G
-- adjoint equivalence
F⊣⊢G : F ⊣⊢ G
F⊣⊢G = withZig record
{ unit = ≃.sym G∘F≈id
; counit =
let open D
open HomReasoning
open MR D
open MP D
in record
{ F⇒G = ntHelper record
{ η = λ X → F∘G≈id.⇒.η X ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ X)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
; commute = λ {X Y} f → begin
(F∘G≈id.⇒.η Y ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ Y)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ Y))) ∘ F.F₁ (G.F₁ f)
≈⟨ pull-last (F∘G≈id.⇐.commute (F.F₁ (G.F₁ f))) ⟩
F∘G≈id.⇒.η Y ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ Y)) ∘ (F.F₁ (G.F₁ (F.F₁ (G.F₁ f))) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X)))
≈˘⟨ refl⟩∘⟨ pushˡ F.homomorphism ⟩
F∘G≈id.⇒.η Y ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ Y) C.∘ G.F₁ (F.F₁ (G.F₁ f))) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
≈⟨ refl⟩∘⟨ F.F-resp-≈ (G∘F≈id.⇒.commute (G.F₁ f)) ⟩∘⟨refl ⟩
F∘G≈id.⇒.η Y ∘ F.F₁ (G.F₁ f C.∘ G∘F≈id.⇒.η (G.F₀ X)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
≈⟨ refl⟩∘⟨ F.homomorphism ⟩∘⟨refl ⟩
F∘G≈id.⇒.η Y ∘ (F.F₁ (G.F₁ f) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ X))) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
≈⟨ center⁻¹ (F∘G≈id.⇒.commute f) Equiv.refl ⟩
(f ∘ F∘G≈id.⇒.η X) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ X)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
≈⟨ assoc ⟩
f ∘ F∘G≈id.⇒.η X ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ X)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
∎
}
; F⇐G = ntHelper record
{ η = λ X → (F∘G≈id.⇒.η (F.F₀ (G.F₀ X)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ X))) ∘ F∘G≈id.⇐.η X
; commute = λ {X Y} f → begin
((F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ Y))) ∘ F∘G≈id.⇐.η Y) ∘ f
≈⟨ pullʳ (F∘G≈id.⇐.commute f) ⟩
(F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ Y))) ∘ F.F₁ (G.F₁ f) ∘ F∘G≈id.⇐.η X
≈⟨ center (⟺ F.homomorphism) ⟩
F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ Y) C.∘ G.F₁ f) ∘ F∘G≈id.⇐.η X
≈⟨ refl⟩∘⟨ F.F-resp-≈ (G∘F≈id.⇐.commute (G.F₁ f)) ⟩∘⟨refl ⟩
F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ F.F₁ (G.F₁ (F.F₁ (G.F₁ f)) C.∘ G∘F≈id.⇐.η (G.F₀ X)) ∘ F∘G≈id.⇐.η X
≈⟨ refl⟩∘⟨ F.homomorphism ⟩∘⟨refl ⟩
F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ (F.F₁ (G.F₁ (F.F₁ (G.F₁ f))) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ X))) ∘ F∘G≈id.⇐.η X
≈⟨ center⁻¹ (F∘G≈id.⇒.commute _) Equiv.refl ⟩
(F.F₁ (G.F₁ f) ∘ F∘G≈id.⇒.η (F.F₀ (G.F₀ X))) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ X)) ∘ F∘G≈id.⇐.η X
≈⟨ center Equiv.refl ⟩
F.F₁ (G.F₁ f) ∘ (F∘G≈id.⇒.η (F.F₀ (G.F₀ X)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ X))) ∘ F∘G≈id.⇐.η X
∎
}
; iso = λ X → Iso-∘ (Iso-∘ (Iso-swap (F∘G≈id.iso _)) ([ F ]-resp-Iso (G∘F≈id.iso _)))
(F∘G≈id.iso X)
}
; zig = λ {A} →
let open D
open HomReasoning
open MR D
in begin
(F∘G≈id.⇒.η (F.F₀ A) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ (F.F₀ A))) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ (F.F₀ A))))
∘ F.F₁ (G∘F≈id.⇐.η A)
≈⟨ pull-last (F∘G≈id.⇐.commute (F.F₁ (G∘F≈id.⇐.η A))) ⟩
F∘G≈id.⇒.η (F.F₀ A) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ (F.F₀ A))) ∘
F.F₁ (G.F₁ (F.F₁ (G∘F≈id.⇐.η A))) ∘ F∘G≈id.⇐.η (F.F₀ A)
≈˘⟨ refl⟩∘⟨ pushˡ F.homomorphism ⟩
F∘G≈id.⇒.η (F.F₀ A) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ (F.F₀ A)) C.∘ G.F₁ (F.F₁ (G∘F≈id.⇐.η A))) ∘ F∘G≈id.⇐.η (F.F₀ A)
≈⟨ refl⟩∘⟨ F.F-resp-≈ (G∘F≈id.⇒.commute (G∘F≈id.⇐.η A)) ⟩∘⟨refl ⟩
F∘G≈id.⇒.η (F.F₀ A) ∘ F.F₁ (G∘F≈id.⇐.η A C.∘ G∘F≈id.⇒.η A) ∘ F∘G≈id.⇐.η (F.F₀ A)
≈⟨ refl⟩∘⟨ elimˡ ((F.F-resp-≈ (G∘F≈id.iso.isoˡ _)) ○ F.identity) ⟩
F∘G≈id.⇒.η (F.F₀ A) ∘ F∘G≈id.⇐.η (F.F₀ A)
≈⟨ F∘G≈id.iso.isoʳ _ ⟩
id
∎
}
module F⊣⊢G = _⊣⊢_ F⊣⊢G
module _ {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} (SE : StrongEquivalence C D) where
open StrongEquivalence SE
C≅D : ⊣Equivalence C D
C≅D = record
{ L = F
; R = G
; L⊣⊢R = F⊣⊢G weak-inverse
}
module C≅D = ⊣Equivalence C≅D
| {
"alphanum_fraction": 0.4703915011,
"avg_line_length": 43.8189655172,
"ext": "agda",
"hexsha": "1f4366a074c2037610853a3a60450314585cc6d2",
"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": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Equivalence/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"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": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Equivalence/Properties.agda",
"max_line_length": 114,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Equivalence/Properties.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": 2891,
"size": 5083
} |
-- MIT License
-- Copyright (c) 2021 Luca Ciccone and Luca Padovani
-- Permission is hereby granted, free of charge, to any person
-- obtaining a copy of this software and associated documentation
-- files (the "Software"), to deal in the Software without
-- restriction, including without limitation the rights to use,
-- copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the
-- Software is furnished to do so, subject to the following
-- conditions:
-- The above copyright notice and this permission notice shall be
-- included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-- OTHER DEALINGS IN THE SOFTWARE.
{-# OPTIONS --guardedness #-}
import Level
open import Data.Empty
open import Data.Product
open import Data.List using (_∷_; []; _++_)
open import Data.List.Properties using (∷-injectiveʳ)
open import Relation.Nullary
open import Relation.Unary
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; subst)
open import Common
module Semantics {ℙ : Set} (message : Message ℙ)
where
open import Trace message
open import HasTrace message
open import TraceSet message
open import SessionType message
open import Transitions message
record Semantics (X : TraceSet) : Set where
field
closed : PrefixClosed X
coherent : Coherent X
open Semantics public
data Classification : TraceSet -> Set where
emp : ∀{X} -> X ⊆ ∅ -> Classification X
eps : ∀{X} -> X ⊆⊇ { [] } -> Classification X
inp : ∀{X x} -> I x ∷ [] ∈ X -> Classification X
out : ∀{X x} -> O x ∷ [] ∈ X -> Classification X
is-emp : ∀{X} -> Semantics X -> [] ∉ X -> X ⊆ ∅
is-emp sem nxε xφ with closed sem none xφ
... | xε = ⊥-elim (nxε xε)
is-eps :
∀{X} ->
Semantics X ->
(¬ (∃[ x ] (I x ∷ [] ∈ X))) ->
(¬ (∃[ x ] (O x ∷ [] ∈ X))) ->
X ⊆ { [] }
is-eps sem nix nox {[]} xφ = refl
is-eps sem nix nox {I x ∷ φ} xφ with closed sem (some none) xφ
... | ix = ⊥-elim (nix (x , ix))
is-eps sem nix nox {O x ∷ φ} xφ with closed sem (some none) xφ
... | ox = ⊥-elim (nox (x , ox))
kind? : ∀{X} -> Semantics X -> Classification X
kind? {X} sem with excluded-middle {∃[ x ] (I x ∷ [] ∈ X)}
... | yes (_ , ix) = inp ix
... | no nix with excluded-middle {∃[ x ] (O x ∷ [] ∈ X)}
... | yes (_ , ox) = out ox
... | no nox with excluded-middle {[] ∈ X}
... | yes xε = eps (is-eps sem nix nox , λ { refl -> xε })
... | no nxε = emp (is-emp sem nxε)
sem-sound : (T : SessionType) -> Semantics ⟦ T ⟧
closed (sem-sound T) = ⊑-has-trace
coherent (sem-sound T) = trace-coherence
derive-semantics : ∀{X} -> Semantics X -> (α : Action) -> Semantics (X ∂ α)
closed (derive-semantics sem _) pre hasφ = closed sem (some pre) hasφ
coherent (derive-semantics {X} sem γ) {φ} {α} {β} hasφα hasφβ = coherent {X} sem {γ ∷ φ} hasφα hasφβ
co-semantics : ∀{X} -> Semantics X -> Semantics (CoSet X)
closed (co-semantics sem) le coφ = closed sem (⊑-co-trace le) coφ
coherent (co-semantics sem) {φ} {ψ₁} {ψ₂} {x} {y} iφx oφx
rewrite co-trace-++ φ (I x ∷ ψ₁) | co-trace-++ φ (O y ∷ ψ₂) =
coherent sem {co-trace φ} {co-trace ψ₂} {co-trace ψ₁} {y} {x} oφx iφx
non-empty-semantics-contains-[] : ∀{X : TraceSet}{φ} -> Semantics X -> φ ∈ X -> [] ∈ X
non-empty-semantics-contains-[] sem w = closed sem none w
decode : ∀{X} -> Semantics X -> ∞SessionType
force (decode sem) with kind? sem
... | emp _ = nil
... | eps _ = win
... | inp _ = inp λ x -> decode (derive-semantics sem (I x))
... | out _ = out λ x -> decode (derive-semantics sem (O x))
decode-sub : ∀{X} (sem : Semantics X) -> ⟦ decode sem .force ⟧ ⊆ X
decode-sub sem tφ with kind? sem
decode-sub _ (_ , () , refl) | emp _
decode-sub _ (_ , _ , step () _) | emp _
decode-sub _ (_ , _ , refl) | eps (_ , sup) = sup refl
decode-sub _ (_ , _ , step (out ()) _) | eps _
decode-sub sem (_ , _ , refl) | inp w = non-empty-semantics-contains-[] sem w
decode-sub sem (_ , def , step inp tr) | inp w =
decode-sub (derive-semantics sem (I _)) (_ , def , tr)
decode-sub sem (_ , _ , refl) | out w = non-empty-semantics-contains-[] sem w
decode-sub sem (_ , def , step (out !x) tr) | out w =
decode-sub (derive-semantics sem (O _)) (_ , def , tr)
decode-sup : ∀{X} (sem : Semantics X) -> X ⊆ ⟦ decode sem .force ⟧
decode-sup sem {φ} hasφ with kind? sem
... | emp sub = ⊥-elim (sub hasφ)
... | eps (sub , _) rewrite sym (sub hasφ) = _ , out , refl
decode-sup sem {[]} hasφ | inp _ = _ , inp , refl
decode-sup sem {I _ ∷ _} hasφ | inp _ =
let _ , def , tr = decode-sup (derive-semantics sem (I _)) hasφ in
_ , def , step inp tr
decode-sup sem {O _ ∷ _} hasφ | inp w = ⊥-elim (coherent sem {[]} w hasφ)
decode-sup sem {[]} hasφ | out _ = _ , out , refl
decode-sup sem {I _ ∷ _} hasφ | out w = ⊥-elim (coherent sem {[]} hasφ w)
decode-sup sem {O _ ∷ _} hasφ | out _ =
let _ , def , tr = decode-sup (derive-semantics sem (O _)) hasφ in
_ , def , step (out (transitions+defined->defined tr def)) tr
decode+maximal->win :
∀{X φ}
(sem : Semantics X)
(rφ : decode sem .force HasTrace φ) ->
φ ∈ Maximal X ->
Win (after rφ)
decode+maximal->win sem rφ comp with kind? sem
decode+maximal->win sem (_ , () , refl) comp | emp sub
decode+maximal->win sem (_ , _ , step () _) comp | emp sub
decode+maximal->win sem (_ , _ , refl) comp | eps _ = Win-win
decode+maximal->win sem (_ , _ , step (out ()) _) comp | eps _
decode+maximal->win sem (_ , def , refl) (maximal _ F) | inp w with F none w
... | ()
decode+maximal->win sem (_ , def , step inp tr) comp | inp _ =
decode+maximal->win (derive-semantics sem (I _)) (_ , def , tr) (derive-maximal comp)
decode+maximal->win sem (_ , def , refl) (maximal _ F) | out w with F none w
... | ()
decode+maximal->win sem (_ , def , step (out !x) tr) comp | out w =
decode+maximal->win (derive-semantics sem (O _)) (_ , def , tr) (derive-maximal comp)
win->maximal :
∀{T φ ψ} ->
φ ⊑ ψ ->
(tφ : T HasTrace φ) ->
T HasTrace ψ ->
Win (after tφ) ->
φ ≡ ψ
win->maximal le (_ , tdef , refl) (_ , sdef , refl) w = refl
win->maximal le (_ , tdef , refl) (_ , sdef , step (out !x) sr) (out U) = ⊥-elim (U _ !x)
win->maximal (some le) (_ , tdef , step inp tr) (_ , sdef , step inp sr) w
rewrite win->maximal le (_ , tdef , tr) (_ , sdef , sr) w = refl
win->maximal (some le) (_ , tdef , step (out _) tr) (_ , sdef , step (out _) sr) w
rewrite win->maximal le (_ , tdef , tr) (_ , sdef , sr) w = refl
decode+win->maximal :
∀{X φ}
(sem : Semantics X)
(rφ : decode sem .force HasTrace φ) ->
Win (after rφ) ->
φ ∈ Maximal X
decode+win->maximal {X} {φ} sem rφ w =
maximal (decode-sub sem rφ) λ le xψ -> let rψ = decode-sup sem xψ in
sym (win->maximal le rφ rψ w)
| {
"alphanum_fraction": 0.6208053691,
"avg_line_length": 39.2967032967,
"ext": "agda",
"hexsha": "6aebbc6af5c4deda4b1aa7e227ad11d6e2989034",
"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": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "boystrange/FairSubtypingAgda",
"max_forks_repo_path": "src/Semantics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"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": "boystrange/FairSubtypingAgda",
"max_issues_repo_path": "src/Semantics.agda",
"max_line_length": 100,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "boystrange/FairSubtypingAgda",
"max_stars_repo_path": "src/Semantics.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-24T14:38:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-29T14:32:30.000Z",
"num_tokens": 2401,
"size": 7152
} |
module Lemmachine.Response.Status where
{-# IMPORT Lemmachine.FFI #-}
open import Data.Nat
data Status : Set where
-- 1xx: Informational - Request received, continuing process
-- 2xx: Success - The action was successfully received, understood, and accepted
OK Created Accepted NoContent : Status
-- 3xx: Redirection - Further action must be taken in order to complete the request
MultipleChoices MovedPermanently SeeOther NotModified MovedTemporarily : Status
-- 4xx: Client Error - The request contains bad syntax or cannot be fulfilled
BadRequest Unauthorized Forbidden NotFound MethodNotAllowed : Status
NotAcceptable Conflict Gone PreconditionFailed : Status
RequestEntityTooLarge RequestURItooLong UnsupportedMediaType : Status
-- 5xx: Server Error - The server failed to fulfill an apparently valid request
NotImplemented ServiceUnavailable : Status
| {
"alphanum_fraction": 0.7997724687,
"avg_line_length": 51.7058823529,
"ext": "agda",
"hexsha": "92b445467ae3decc6225d564c026311339139cab",
"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": "src/Lemmachine/Response/Status.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": "src/Lemmachine/Response/Status.agda",
"max_line_length": 85,
"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": "src/Lemmachine/Response/Status.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": 188,
"size": 879
} |
open import Agda.Builtin.Equality using (_≡_; refl)
record ⊤ : Set where
no-eta-equality
constructor tt
data Box (A : Set) : Set where
[_] : A → Box A
Unit : Set
Unit = Box ⊤
F : Unit → Set → Set
F [ _ ] x = x
G : {P : Unit → Set} → ((x : ⊤) → P [ x ]) → ((x : Unit) → P x)
G f [ x ] = f x
record R : Set₁ where
no-eta-equality
field
f : (x : Unit) → Box (F x ⊤)
data ⊥ : Set where
r : R
r = record { f = G [_] }
open R r
H : ⊥ → Set₁
H _ rewrite refl {x = tt} = Set
| {
"alphanum_fraction": 0.5212981744,
"avg_line_length": 14.9393939394,
"ext": "agda",
"hexsha": "cb3f8ef4cb8b33eda4dbd94d1319bf90dbd7d504",
"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/Issue2727-1.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/Issue2727-1.agda",
"max_line_length": 63,
"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/Issue2727-1.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": 198,
"size": 493
} |
-- Andreas, 2015-07-13 Better parse errors for illegal type signatures
A | B : Set
| {
"alphanum_fraction": 0.7176470588,
"avg_line_length": 21.25,
"ext": "agda",
"hexsha": "f35319c07adcb388e1e27c9ff66500de6e26ed77",
"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/Issue1609c.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/Issue1609c.agda",
"max_line_length": 71,
"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/Issue1609c.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": 25,
"size": 85
} |
{-
This file shows Hⁿ⁺ᵐ(Sⁿ×Sᵐ)≅ℤ for n, m ≥ 1. This can be done in several
ways (e.g. Mayer-Vietoris). We give the iso as explicitly
as possible. The idea:
Step 1: Hⁿ⁺ᵐ(Sⁿ×Sᵐ)≅H¹⁺ⁿ⁺ᵐ(S¹⁺ⁿ×Sᵐ) (i.e. some form of suspension
axiom).
Step 2: H¹⁺ᵐ(S¹×Sᵐ)≅ℤ
Step 3: Conclude Hⁿ⁺ᵐ(Sⁿ×Sᵐ)≅ℤ by induction on n.
The iso as defined here has the advantage that it looks a lot like
the cup product, making it trivial to show that e.g. gₗ ⌣ gᵣ ≡ e, where
gₗ, gᵣ are the two generators of H²(S²×S²) and e is the generator of
H⁴(S²×S²) -- this of interest since it is used in π₄S³≅ℤ/2.
-}
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.Groups.SphereProduct where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Relation.Nullary
open import Cubical.Data.Unit
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.Instances.Int
open import Cubical.HITs.Truncation as T
open import Cubical.HITs.SetTruncation as ST
open import Cubical.HITs.PropositionalTruncation as PT
open import Cubical.HITs.S1
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp
open import Cubical.Homotopy.Loopspace
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 Iso
open PlusBis
private
¬lem : (n m : ℕ) → ¬ suc (n + m) ≡ m
¬lem n zero = snotz
¬lem n (suc m) p =
¬lem n m (sym (+-suc n m) ∙ cong predℕ p)
{- Step 1: Hⁿ⁺ᵐ(Sⁿ×Sᵐ)≅H¹⁺ⁿ⁺ᵐ(S¹⁺ⁿ×Sᵐ) -}
-- The functions back and forth (suspension on the left component)
↓Sⁿ×Sᵐ→Kₙ₊ₘ : (n m : ℕ)
→ (S₊ (suc (suc n)) → S₊ (suc m) → coHomK (suc (suc ((suc n) + m))))
→ S₊ (suc n) → S₊ (suc m) → coHomK (suc (suc (n + m)))
↓Sⁿ×Sᵐ→Kₙ₊ₘ n m f x y =
ΩKn+1→Kn ((suc ((suc n) + m)))
(sym (rCancelₖ _ (f north y))
∙∙ cong (λ x → f x y -ₖ f north y) (merid x ∙ sym (merid (ptSn (suc n))))
∙∙ rCancelₖ _ (f north y))
↑Sⁿ×Sᵐ→Kₙ₊ₘ : (n m : ℕ)
→ (S₊ (suc n) → S₊ (suc m) → coHomK (suc (suc (n + m))))
→ (S₊ (suc (suc n)) → S₊ (suc m) → coHomK (suc (suc ((suc n) + m))))
↑Sⁿ×Sᵐ→Kₙ₊ₘ n m f north y = 0ₖ _
↑Sⁿ×Sᵐ→Kₙ₊ₘ n m f south y = 0ₖ _
↑Sⁿ×Sᵐ→Kₙ₊ₘ n m f (merid a i) y =
Kn→ΩKn+1 _ (f a y) i
∥HⁿSᵐPath∥ : (n m : ℕ) → (f : S₊ (suc m) → coHomK (suc n))
→ ¬ (n ≡ m)
→ ∥ f ≡ (λ _ → 0ₖ (suc n)) ∥₁
∥HⁿSᵐPath∥ n m f p =
fun PathIdTrunc₀Iso
(isContr→isProp
(isOfHLevelRetractFromIso 0 (fst (Hⁿ-Sᵐ≅0 n m p)) isContrUnit)
∣ f ∣₂ (0ₕ _))
-- The iso
×leftSuspensionIso : (n m : ℕ)
→ GroupIso (coHomGr (suc (((suc n) + m)))
(S₊ (suc n) × S₊ (suc m)))
(coHomGr (suc (suc ((suc n) + m)))
(S₊ (suc (suc n)) × S₊ (suc m)))
fun (fst (×leftSuspensionIso n m)) =
ST.map (uncurry ∘ ↑Sⁿ×Sᵐ→Kₙ₊ₘ n m ∘ curry)
inv (fst (×leftSuspensionIso n m)) =
ST.map ((uncurry ∘ ↓Sⁿ×Sᵐ→Kₙ₊ₘ n m ∘ curry))
rightInv (fst (×leftSuspensionIso n m)) =
ST.elim (λ _ → isSetPathImplicit)
λ f → inv PathIdTrunc₀Iso
(PT.rec squash₁
(uncurry (λ g p
→ PT.map (λ gid → funExt λ {(x , y)
→ (λ i → uncurry (↑Sⁿ×Sᵐ→Kₙ₊ₘ n m
(↓Sⁿ×Sᵐ→Kₙ₊ₘ n m (curry (p (~ i))))) (x , y))
∙∙ main g gid x y
∙∙ funExt⁻ p (x , y)})
(∥Path∥ g)))
(rewrte f))
where
lem : (n m : ℕ) → ¬ suc (suc (n + m)) ≡ m
lem n zero = snotz
lem n (suc m) p = lem n m (cong suc (sym (+-suc n m)) ∙ cong predℕ p)
charac-fun :
(S₊ (suc n) → S₊ (suc m)
→ typ (Ω (coHomK-ptd (suc (suc (suc n + m))))))
→ S₊ (suc (suc n)) × S₊ (suc m) → coHomK (suc (suc (suc n + m)))
charac-fun g (north , y) = 0ₖ _
charac-fun g (south , y) = 0ₖ _
charac-fun g (merid c i , y) = g c y i
rewrte : (f : S₊ (suc (suc n)) × S₊ (suc m)
→ coHomK (suc (suc (suc n + m))))
→ ∃[ g ∈ (S₊ (suc n) → S₊ (suc m)
→ typ (Ω (coHomK-ptd (suc (suc (suc n + m)))))) ]
charac-fun g ≡ f
rewrte f =
PT.map (λ p
→ (λ x y → sym (funExt⁻ p y)
∙∙ (λ i → f ((merid x ∙ sym (merid (ptSn (suc n)))) i , y))
∙∙ funExt⁻ p y)
, funExt λ { (north , y) → sym (funExt⁻ p y)
; (south , y) → sym (funExt⁻ p y)
∙ λ i → f (merid (ptSn (suc n)) i , y)
; (merid a i , y) j
→ hcomp (λ k → λ { (i = i0) → p (~ j ∧ k) y
; (i = i1)
→ compPath-filler'
(sym (funExt⁻ p y))
(λ i → f (merid (ptSn (suc n)) i , y)) k j
; (j = i1) → f (merid a i , y) })
(f (compPath-filler (merid a)
(sym (merid (ptSn (suc n)))) (~ j) i
, y))})
(∥HⁿSᵐPath∥ _ _ (λ x → f (north , x))
(lem n m))
∥Path∥ :
(g : S₊ (suc n) → S₊ (suc m)
→ typ (Ω (coHomK-ptd (suc (suc (suc n + m))))))
→ ∥ (g (ptSn _)) ≡ (λ _ → refl) ∥₁
∥Path∥ g =
fun PathIdTrunc₀Iso
(isContr→isProp
(isOfHLevelRetractFromIso 0
((invIso (fst (coHom≅coHomΩ _ (S₊ (suc m))))))
(0ₕ _ , ST.elim (λ _ → isProp→isSet (squash₂ _ _))
λ f → PT.rec (squash₂ _ _) (sym ∘ cong ∣_∣₂)
(∥HⁿSᵐPath∥ _ _ f (¬lem n m))))
∣ g (ptSn (suc n)) ∣₂ ∣ (λ _ → refl) ∣₂)
main : (g : _) → (g (ptSn _)) ≡ (λ _ → refl)
→ (x : S₊ (suc (suc n))) (y : S₊ (suc m))
→ uncurry (↑Sⁿ×Sᵐ→Kₙ₊ₘ n m
(↓Sⁿ×Sᵐ→Kₙ₊ₘ n m (curry (charac-fun g)))) (x , y)
≡ charac-fun g (x , y)
main g gid north y = refl
main g gid south y = refl
main g gid (merid a i) y j = helper j i
where
helper : (λ i → uncurry (↑Sⁿ×Sᵐ→Kₙ₊ₘ n m
(↓Sⁿ×Sᵐ→Kₙ₊ₘ n m (curry (charac-fun g))))
(merid a i , y))
≡ g a y
helper = (λ i → rightInv (Iso-Kn-ΩKn+1 _)
((sym (rCancel≡refl _ i)
∙∙ cong-∙ (λ x → rUnitₖ _ (charac-fun g (x , y)) i)
(merid a) (sym (merid (ptSn (suc n)))) i
∙∙ rCancel≡refl _ i)) i)
∙∙ sym (rUnit _)
∙∙ (cong (g a y ∙_) (cong sym (funExt⁻ gid y))
∙ sym (rUnit (g a y)))
leftInv (fst (×leftSuspensionIso n m)) =
ST.elim (λ _ → isSetPathImplicit)
λ f → PT.rec (squash₂ _ _)
(λ id
→ cong ∣_∣₂
(funExt (λ {(x , y) → (λ i → ΩKn+1→Kn _ (sym (rCancel≡refl _ i)
∙∙ ((λ j → rUnitₖ _
(↑Sⁿ×Sᵐ→Kₙ₊ₘ n m (curry f)
((merid x ∙ sym (merid (ptSn (suc n)))) j) y) i))
∙∙ rCancel≡refl _ i))
∙ (λ i → ΩKn+1→Kn _ (rUnit
(cong-∙ (λ r → ↑Sⁿ×Sᵐ→Kₙ₊ₘ n m (curry f) r y)
(merid x) (sym (merid (ptSn (suc n)))) i) (~ i)))
∙ cong (ΩKn+1→Kn _) (cong (Kn→ΩKn+1 _ (f (x , y)) ∙_)
(cong sym (cong (Kn→ΩKn+1 _)
(funExt⁻ id y) ∙ (Kn→ΩKn+10ₖ _)))
∙ sym (rUnit _))
∙ leftInv (Iso-Kn-ΩKn+1 _) (f (x , y))})))
(∥HⁿSᵐPath∥ (suc n + m) m (λ x → f (ptSn _ , x))
(¬lem n m))
snd (×leftSuspensionIso n m) =
makeIsGroupHom (ST.elim2 (λ _ _ → isSetPathImplicit)
λ f g → cong ∣_∣₂
(funExt λ { (north , y) → refl
; (south , y) → refl
; (merid a i , y) j
→ (sym (∙≡+₂ _ (Kn→ΩKn+1 _ (f (a , y)))
(Kn→ΩKn+1 _ (g (a , y))))
∙ sym (Kn→ΩKn+1-hom _
(f (a , y)) (g (a , y)))) (~ j) i}))
{- Step 2: H¹⁺ᵐ(S¹×Sᵐ)≅ℤ -}
-- The functions back and forth
Hⁿ-S¹×Sⁿ→Hⁿ-Sⁿ : (m : ℕ)
→ (S₊ (suc m) → coHomK (suc m))
→ S₊ (suc zero) → S₊ (suc m) → coHomK (suc (suc m))
Hⁿ-S¹×Sⁿ→Hⁿ-Sⁿ m f base y = 0ₖ _
Hⁿ-S¹×Sⁿ→Hⁿ-Sⁿ m f (loop i) y = Kn→ΩKn+1 (suc m) (f y) i
Hⁿ-Sⁿ→Hⁿ-S¹×Sⁿ : (m : ℕ)
→ (S₊ (suc zero) → S₊ (suc m) → coHomK (suc (suc m)))
→ (S₊ (suc m) → coHomK (suc m))
Hⁿ-Sⁿ→Hⁿ-S¹×Sⁿ m f x =
ΩKn+1→Kn (suc m)
(sym (rCancelₖ _ (f base x))
∙∙ ((λ i → f (loop i) x -ₖ f base x))
∙∙ rCancelₖ _ (f base x))
Hⁿ-Sⁿ≅Hⁿ-S¹×Sⁿ : (m : ℕ)
→ GroupIso (coHomGr (suc m) (S₊ (suc m)))
(coHomGr (suc (suc m)) (S₊ (suc zero) × S₊ (suc m)))
fun (fst (Hⁿ-Sⁿ≅Hⁿ-S¹×Sⁿ m)) = ST.map (uncurry ∘ Hⁿ-S¹×Sⁿ→Hⁿ-Sⁿ m)
inv (fst (Hⁿ-Sⁿ≅Hⁿ-S¹×Sⁿ m)) = ST.map (Hⁿ-Sⁿ→Hⁿ-S¹×Sⁿ m ∘ curry)
rightInv (fst (Hⁿ-Sⁿ≅Hⁿ-S¹×Sⁿ m)) =
ST.elim (λ _ → isSetPathImplicit)
λ f → inv PathIdTrunc₀Iso
(PT.map (uncurry (λ g p
→ funExt λ {(x , y)
→ (λ i → uncurry
(Hⁿ-S¹×Sⁿ→Hⁿ-Sⁿ m
(Hⁿ-Sⁿ→Hⁿ-S¹×Sⁿ m (curry (p i)))) (x , y))
∙∙ main g x y
∙∙ sym (funExt⁻ p (x , y))}))
(rewrte f))
where
characFun : (x : S₊ (suc m) → coHomK (suc m))
→ S₊ 1 × S₊ (suc m) → coHomK (suc (suc m))
characFun f (base , y) = 0ₖ _
characFun f (loop i , y) = Kn→ΩKn+1 _ (f y) i
main : (g : _) (x : S¹) (y : S₊ (suc m))
→ uncurry (Hⁿ-S¹×Sⁿ→Hⁿ-Sⁿ m (Hⁿ-Sⁿ→Hⁿ-S¹×Sⁿ m (curry (characFun g))))
(x , y)
≡ characFun g (x , y)
main g base y = refl
main g (loop i) y j = help j i
where
help : cong (λ x → Hⁿ-S¹×Sⁿ→Hⁿ-Sⁿ m
(Hⁿ-Sⁿ→Hⁿ-S¹×Sⁿ m (curry (characFun g))) x y) loop
≡ Kn→ΩKn+1 _ (g y)
help = rightInv (Iso-Kn-ΩKn+1 (suc m))
(sym (rCancelₖ _ (0ₖ _))
∙∙ ((λ i → Kn→ΩKn+1 _ (g y) i -ₖ 0ₖ _))
∙∙ rCancelₖ _ (0ₖ _))
∙∙ (λ i → sym (rCancel≡refl _ i)
∙∙ (λ j → rUnitₖ _ (Kn→ΩKn+1 _ (g y) j) i)
∙∙ rCancel≡refl _ i)
∙∙ sym (rUnit _)
lem : (m : ℕ) → ¬ suc m ≡ m
lem zero = snotz
lem (suc m) p = lem m (cong predℕ p)
rewrte : (f : S₊ 1 × S₊ (suc m) → coHomK (suc (suc m)))
→ ∃[ g ∈ (S₊ (suc m) → coHomK (suc m)) ] f ≡ characFun g
rewrte f =
PT.map (λ p →
(λ x → ΩKn+1→Kn _
(sym (funExt⁻ p x) ∙∙ (λ i → f (loop i , x)) ∙∙ funExt⁻ p x))
, funExt λ { (base , y) → funExt⁻ p y
; (loop i , x) j →
hcomp (λ k → λ {(i = i0) → funExt⁻ p x j
; (i = i1) → funExt⁻ p x j
; (j = i0) → f (loop i , x)
; (j = i1) →
rightInv (Iso-Kn-ΩKn+1 (suc m))
(sym (funExt⁻ p x)
∙∙ (λ i → f (loop i , x))
∙∙ funExt⁻ p x) (~ k) i})
(doubleCompPath-filler
(sym (funExt⁻ p x))
(λ i → f (loop i , x))
(funExt⁻ p x) j i)})
(∥HⁿSᵐPath∥ (suc m) m (λ x → f (base , x)) (lem m))
leftInv (fst (Hⁿ-Sⁿ≅Hⁿ-S¹×Sⁿ m)) =
ST.elim (λ _ → isSetPathImplicit)
λ f
→ cong ∣_∣₂ (funExt λ x
→ cong (ΩKn+1→Kn (suc m))
((λ i → sym (rCancel≡refl _ i)
∙∙ cong (λ z → rUnitₖ _ (Hⁿ-S¹×Sⁿ→Hⁿ-Sⁿ m f z x) i) loop
∙∙ rCancel≡refl _ i) ∙ sym (rUnit (Kn→ΩKn+1 (suc m) (f x))))
∙ leftInv (Iso-Kn-ΩKn+1 _) (f x))
snd (Hⁿ-Sⁿ≅Hⁿ-S¹×Sⁿ m) =
makeIsGroupHom
(ST.elim2
(λ _ _ → isSetPathImplicit)
λ f g → cong ∣_∣₂
(funExt λ { (base , y) → refl
; (loop i , y) j →
(sym (∙≡+₂ _ (Kn→ΩKn+1 _ (f y)) (Kn→ΩKn+1 _ (g y)))
∙ sym (Kn→ΩKn+1-hom _ (f y) (g y))) (~ j) i}))
Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ : (n m : ℕ)
→ GroupIso (coHomGr ((suc n) +' (suc m))
(S₊ (suc n) × S₊ (suc m)))
ℤGroup
Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ zero m =
compGroupIso (invGroupIso (Hⁿ-Sⁿ≅Hⁿ-S¹×Sⁿ m)) (Hⁿ-Sⁿ≅ℤ m)
Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ (suc n) m =
compGroupIso
(invGroupIso (×leftSuspensionIso n m))
(Hⁿ⁺ᵐ-Sⁿ×Sᵐ≅ℤ n m)
-- Proof that ⌣ respects generators for H²×H²→H⁴
-- Todo: generalise
H²-S²×S²-genₗ : coHom 2 (S₊ 2 × S₊ 2)
H²-S²×S²-genₗ = ∣ (λ x → ∣ fst x ∣) ∣₂
H²-S²×S²-genᵣ : coHom 2 (S₊ 2 × S₊ 2)
H²-S²×S²-genᵣ = ∣ (λ x → ∣ snd x ∣) ∣₂
H²-S²≅H⁴-S²×S² : GroupIso (coHomGr 2 (S₊ 2)) (coHomGr 4 (S₊ 2 × S₊ 2))
H²-S²≅H⁴-S²×S² = (compGroupIso (Hⁿ-Sⁿ≅Hⁿ-S¹×Sⁿ 1) (×leftSuspensionIso 0 1))
H²-S²≅H⁴-S²×S²⌣ :
fun (fst (H²-S²≅H⁴-S²×S²)) ∣ ∣_∣ₕ ∣₂ ≡ H²-S²×S²-genₗ ⌣ H²-S²×S²-genᵣ
H²-S²≅H⁴-S²×S²⌣ =
cong ∣_∣₂ (funExt (uncurry
(λ { north y → refl
; south y → refl
; (merid a i) y j → Kn→ΩKn+1 3 (lem a y j) i})))
where
lem : (a : S¹) (y : S₊ 2)
→ Hⁿ-S¹×Sⁿ→Hⁿ-Sⁿ 1 ∣_∣ₕ a y ≡ _⌣ₖ_ {n = 1} {m = 2} ∣ a ∣ₕ ∣ y ∣ₕ
lem base y = refl
lem (loop i) y = refl
| {
"alphanum_fraction": 0.4668225004,
"avg_line_length": 37.0446927374,
"ext": "agda",
"hexsha": "2519139edea6ca4bf6fb97441e31411ea3e534f7",
"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/ZCohomology/Groups/SphereProduct.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/ZCohomology/Groups/SphereProduct.agda",
"max_line_length": 80,
"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/ZCohomology/Groups/SphereProduct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6039,
"size": 13262
} |
{-# OPTIONS --cubical --safe #-}
module Function where
open import Level
open import Path
infixr 9 _∘_ _∘′_
_∘_ : ∀ {A : Type a} {B : A → Type b} {C : {x : A} → B x → Type c} →
(∀ {x} (y : B x) → C y) → (g : (x : A) → B x) →
((x : A) → C (g x))
f ∘ g = λ x → f (g x)
_∘′_ : (B → C) → (A → B) → A → C
f ∘′ g = λ x → f (g x)
flip : ∀ {A : Type a} {B : Type b} {C : A → B → Type c} →
((x : A) (y : B) → C x y) → ((y : B) (x : A) → C x y)
flip f = λ y x → f x y
id : ∀ {A : Type a} → A → A
id x = x
const : A → B → A
const x _ = x
infixr -1 _$_
_$_ : ∀ {A : Type a} {B : A → Type b}
→ (∀ (x : A) → B x)
→ (x : A)
→ B x
f $ x = f x
infixl 1 _⟨_⟩_
_⟨_⟩_ : A → (A → B → C) → B → C
x ⟨ f ⟩ y = f x y
infixl 0 _∋_
_∋_ : (A : Type a) → A → A
A ∋ x = x
infix 0 case_of_
case_of_ : A → (A → B) → B
case x of f = f x
record Reveal_·_is_ {A : Type a} {B : A → Type b} (f : (x : A) → B x) (x : A) (y : B x) : Type b where
constructor 〖_〗
field eq : f x ≡ y
inspect : {A : Type a} {B : A → Type b} (f : (x : A) → B x) (x : A) → Reveal f · x is f x
inspect f x = 〖 refl 〗
| {
"alphanum_fraction": 0.4147217235,
"avg_line_length": 21.4230769231,
"ext": "agda",
"hexsha": "5de1aa121b36d6d4157de47866f0f8d26af8892c",
"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": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Function.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"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/combinatorics-paper",
"max_issues_repo_path": "agda/Function.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Function.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 552,
"size": 1114
} |
module Structure.Type.Identity.Proofs.Eliminator where
import Lvl
open import Functional using (_→ᶠ_ ; id ; _on₂_ ; swap ; apply)
open import Logic
open import Logic.Propositional
open import Logic.Propositional.Proofs.Structures
open import Structure.Categorical.Properties
open import Structure.Function
open import Structure.Operator
open import Structure.Groupoid
open import Structure.Setoid using (Equiv ; intro) renaming (_≡_ to _≡ₛ_)
open import Structure.Relator.Equivalence
open import Structure.Relator.Properties
open import Structure.Relator.Properties.Proofs
open import Structure.Relator
open import Structure.Type.Identity
open import Structure.Type.Identity.Proofs
open import Syntax.Function
open import Syntax.Transitivity
open import Syntax.Type
open import Type
private variable ℓ ℓ₁ ℓ₂ ℓₑ₁ ℓₑ₂ ℓₑ ℓₘₑ ℓₚ ℓₒ : Lvl.Level
private variable T A B : Type{ℓ}
private variable x y : T
private variable Id _≡_ _▫_ : T → T → Stmt{ℓ}
module Oper (Id : T → T → Type{ℓₑ}) ⦃ refl : Reflexivity(Id) ⦄ ⦃ identElim : IdentityEliminator{ℓₚ = ℓₑ}(Id) ⦄ where
open Symmetry (identity-eliminator-to-symmetry {Id = Id}) using () renaming (proof to sym) public
open Transitivity(identity-eliminator-to-transitivity {Id = Id}) using () renaming (proof to trans) public
ftrans = identity-eliminator-to-flipped-transitivityᵣ ⦃ refl ⦄ ⦃ identElim ⦄
module Oper2 (Id : A → A → Type{ℓₑ}) ⦃ refl : Reflexivity(Id) ⦄ ⦃ identElim : IdentityEliminator{ℓₚ = ℓₚ}(Id) ⦄ where
open Reflexivity (refl) using () renaming (proof to refl) public
module _ (_▫_ : A → A → Type{ℓₚ}) ⦃ [▫]-refl : Reflexivity(_▫_) ⦄ where
open _⊆₂_ identity-eliminator-to-reflexive-subrelation using () renaming (proof to sub) public
module _ (_▫_ : B → B → Type{ℓₚ}) ⦃ [▫]-refl : Reflexivity(_▫_) ⦄ (f : A → B) where
open _⊆₂_ (minimal-reflection-transport ⦃ minRefl = identity-eliminator-to-reflexive-subrelation ⦄ {_▫_ = _▫_} {f = f}) using () renaming (proof to transp) public
module _
{Id : T → T → Type{ℓₑ}} ⦃ refle-T : Reflexivity(Id) ⦄ ⦃ identElim-T : IdentityEliminator(Id) ⦄
{_≡_ : ∀{T : Type{ℓₑ}} → T → T → Type{ℓₘₑ}}
⦃ identElimOfIntro : IdentityEliminationOfIntro(Id)(_≡_) ⦄
where
open Oper(Id)
open Oper2{ℓₚ = ℓₑ}(Id)
identity-eliminator-symmetry-of-refl : ∀{x} → (sym refl ≡ refl{x})
identity-eliminator-symmetry-of-refl = idElimOfIntro(Id)(_≡_) (\{x y} _ → (Id y x)) refl
module _
{Id : T → T → Type{ℓₑ₁}} ⦃ refle-T : Reflexivity(Id) ⦄ ⦃ identElim-T : IdentityEliminator(Id) ⦄
{_≡_ : ∀{T : Type{ℓₑ₂}} → T → T → Type{ℓₘₑ}}
⦃ identElimOfIntro : IdentityEliminationOfIntro(Id)(_≡_) ⦄
{_▫_ : T → T → Type{ℓₑ₂}} ⦃ refl-op : Reflexivity(_▫_) ⦄
where
open Oper(Id)
open Oper2{ℓₚ = ℓₑ₂}(Id)
identity-eliminator-reflexive-subrelation-of-refl : ∀{x} → (sub(_▫_) refl ≡ reflexivity(_▫_){x})
identity-eliminator-reflexive-subrelation-of-refl = idElimOfIntro(Id)(_≡_) (\{x y} _ → (x ▫ y)) (reflexivity(_▫_))
module _
{Id : A → A → Type{ℓₑ₁}} ⦃ refle-A : Reflexivity(Id) ⦄ ⦃ identElim-A : IdentityEliminator(Id) ⦄
{_≡_ : ∀{T : Type{ℓₑ₂}} → T → T → Type{ℓₘₑ}}
⦃ identElimOfIntro : IdentityEliminationOfIntro(Id)(_≡_) ⦄
{_▫_ : B → B → Type{ℓₑ₂}} ⦃ refle-B : Reflexivity(_▫_) ⦄
{f : A → B}
where
open Oper(Id)
open Oper2{ℓₚ = ℓₑ₂}(Id)
identity-eliminator-transport-of-refl : ∀{a} → (transp(_▫_)(f) (refl{a}) ≡ reflexivity(_▫_) {f(a)})
identity-eliminator-transport-of-refl {a} = identity-eliminator-reflexive-subrelation-of-refl {_≡_ = _≡_} {_▫_ = (_▫_) on₂ f} ⦃ on₂-reflexivity ⦄ {x = a}
module _
{Id : T → T → Type{ℓₑ}}
⦃ refle-T : Reflexivity(Id) ⦄
⦃ identElim-T : IdentityEliminator(Id) ⦄
{_≡_ : ∀{T : Type{ℓₑ}} → T → T → Type{ℓₘₑ}}
⦃ refle-eq : ∀{T : Type} → Reflexivity(_≡_ {T = T}) ⦄
⦃ identElim-eq : ∀{T : Type} → IdentityEliminator{ℓₚ = ℓₘₑ}(_≡_ {T = T}) ⦄
⦃ identElimOfIntro : IdentityEliminationOfIntro(Id)(_≡_) ⦄
where
open Oper(Id)
open Oper2{ℓₚ = ℓₑ}(Id)
instance _ = identity-eliminator-to-reflexive-subrelation
identity-eliminator-flipped-transitivityᵣ-of-refl : ∀{x} → (ftrans refl refl ≡ refl{x})
identity-eliminator-flipped-transitivityᵣ-of-refl {z} = sub₂(_≡_)((_≡_) on₂ (apply refl)) ⦃ minimal-reflection-transport ⦄ identity-eliminator-transport-of-refl
identity-eliminator-transitivity-of-refl : ∀{x} → (trans refl refl ≡ refl{x})
identity-eliminator-transitivity-of-refl = transitivity(_≡_) ⦃ identity-eliminator-to-transitivity ⦄ p identity-eliminator-flipped-transitivityᵣ-of-refl where
p : trans refl refl ≡ ftrans refl refl
p = sub₂(_≡_)((_≡_) on₂ (p ↦ identity-eliminator-to-flipped-transitivityᵣ p refl)) ⦃ minimal-reflection-transport ⦄ identity-eliminator-symmetry-of-refl
module _
⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄
⦃ identElim-A : IdentityEliminator(Equiv._≡_ equiv-A) ⦄
⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄
{_≡_ : ∀{T : Type{ℓₑ₂}} → T → T → Type{ℓₘₑ}}
⦃ identElimOfIntro : IdentityEliminationOfIntro(Equiv._≡_ equiv-A)(_≡_) ⦄
where
open Reflexivity(Equiv.reflexivity equiv-A) using () renaming (proof to refl-A)
open Reflexivity(Equiv.reflexivity equiv-B) using () renaming (proof to refl-B)
instance _ = identity-eliminator-to-reflexive-subrelation
instance _ = minimal-reflection-to-function
identity-eliminator-function-of-refl : ∀{f : A → B}{a} → (congruence₁(f) (refl-A {a}) ≡ refl-B {f(a)})
identity-eliminator-function-of-refl = identity-eliminator-transport-of-refl
module _
⦃ equiv-T : Equiv{ℓₑ₁}(T) ⦄
⦃ identElim-T : IdentityEliminator(Equiv._≡_ equiv-T) ⦄
{_≡_ : ∀{T : Type{ℓₑ₂}} → T → T → Type{ℓₘₑ}}
⦃ refle-eq : ∀{T : Type} → Reflexivity(_≡_ {T = T}) ⦄
⦃ identElim-eq : ∀{T : Type} → IdentityEliminator{ℓₚ = ℓₘₑ}(_≡_ {T = T}) ⦄
⦃ identElimOfIntro : IdentityEliminationOfIntro(Equiv._≡_ equiv-T)(_≡_) ⦄
where
open Reflexivity(Equiv.reflexivity equiv-T) using () renaming (proof to refl)
instance _ = identity-eliminator-to-reflexive-subrelation
instance _ = minimal-reflection-to-relator
identity-eliminator-relator-of-refl : ∀{P : T → Stmt}{x}{p : P(x)} → (substitute₁(P) refl p ≡ p)
identity-eliminator-relator-of-refl {p = p} = sub₂(_≡_)((_≡_) on₂ (apply p)) ⦃ minimal-reflection-transport ⦄ identity-eliminator-transport-of-refl
module _
{Id : T → T → Type{ℓₑ}}
⦃ refle-T : Reflexivity(Id) ⦄
⦃ identElim-T : ∀{ℓₚ} → IdentityEliminator{ℓₚ = ℓₚ}(Id) ⦄
-- ⦃ identElim₁-T : IdentityEliminator{ℓₚ = ℓₑ}(Id) ⦄
-- ⦃ identElim₂-T : IdentityEliminator{ℓₚ = ℓₘₑ}(Id) ⦄
-- ⦃ identElim₃-T : IdentityEliminator{ℓₚ = ℓₑ Lvl.⊔ ℓₘₑ}(Id) ⦄
{_≡_ : ∀{T : Type{ℓₑ}} → T → T → Type{ℓₘₑ}}
⦃ refle-eq : ∀{T : Type} → Reflexivity(_≡_ {T = T}) ⦄
⦃ identElim-eq : ∀{T : Type} → IdentityEliminator{ℓₚ = ℓₘₑ}(_≡_ {T = T}) ⦄ -- TODO: Try to not have these and instead have the properties that are used
⦃ identElimOfIntro : IdentityEliminationOfIntro(Id)(_≡_) ⦄
where
open Reflexivity (refle-T) using () renaming (proof to refl)
open Symmetry (identity-eliminator-to-symmetry {Id = Id}) using () renaming (proof to sym)
open Transitivity(identity-eliminator-to-transitivity {Id = Id}) using () renaming (proof to trans)
instance _ = identity-eliminator-to-reflexive-subrelation
instance _ = \{T} → identity-eliminator-to-symmetry {Id = _≡_ {T = T}} ⦃ refl = refle-eq ⦄ ⦃ identElim = identElim-eq ⦄
instance _ = \{T} → identity-eliminator-to-transitivity {Id = _≡_ {T = T}} ⦃ refl = refle-eq ⦄ ⦃ identElim = identElim-eq ⦄
instance _ = \{T} → Structure.Setoid.intro(_) ⦃ identity-eliminator-to-equivalence {Id = _≡_ {T = T}} ⦃ refl = refle-eq ⦄ ⦃ identElim = identElim-eq ⦄ ⦄
identity-eliminator-identityₗ : ∀{x y}{p : Id x y} → (trans refl p ≡ p)
identity-eliminator-identityₗ {p = p} = idElim(Id) (p ↦ (trans refl p ≡ p)) identity-eliminator-transitivity-of-refl p
identity-eliminator-identityᵣ : ∀{x y}{p : Id x y} → (trans p refl ≡ p)
identity-eliminator-identityᵣ {p = p} = idElim(Id) (p ↦ (trans p refl ≡ p)) identity-eliminator-transitivity-of-refl p
identity-eliminator-associativity : ∀{x y z w}{p : Id x y}{q : Id y z}{r : Id z w} → (trans (trans p q) r ≡ trans p (trans q r))
identity-eliminator-associativity {p = p} {q = q} {r = r} =
idElim(Id)
(p ↦ ∀ q r → (trans (trans p q) r ≡ trans p (trans q r)))
(q ↦ r ↦ (
trans (trans refl q) r 🝖[ _≡_ ]-[ sub₂(_≡_)((_≡_) on₂ (expr ↦ trans expr r)) ⦃ identity-eliminator-to-reflexive-subrelation ⦃ refl = on₂-reflexivity ⦄ ⦄ identity-eliminator-identityₗ ]
trans q r 🝖[ _≡_ ]-[ identity-eliminator-identityₗ ]-sym
trans refl (trans q r) 🝖-end
))
p q r
identity-eliminator-inverseₗ : ∀{x y}{p : Id x y} → (trans (sym p) p ≡ refl)
identity-eliminator-inverseₗ {p = p} =
idElim(Id)
(p ↦ trans (sym p) p ≡ refl)
(
trans (sym refl) refl 🝖[ _≡_ ]-[ identity-eliminator-identityᵣ ]
sym refl 🝖[ _≡_ ]-[ identity-eliminator-symmetry-of-refl ]
refl 🝖-end
)
p
identity-eliminator-inverseᵣ : ∀{x y}{p : Id x y} → (trans p (sym p) ≡ refl)
identity-eliminator-inverseᵣ {p = p} =
idElim(Id)
(p ↦ trans p (sym p) ≡ refl)
(
trans refl (sym refl) 🝖[ _≡_ ]-[ identity-eliminator-identityₗ ]
sym refl 🝖[ _≡_ ]-[ identity-eliminator-symmetry-of-refl ]
refl 🝖-end
)
p
identity-eliminator-categorical-identityₗ : Morphism.Identityₗ{Obj = T} (\{x} → swap(trans{x})) (refl)
identity-eliminator-categorical-identityₗ = Morphism.intro identity-eliminator-identityᵣ
identity-eliminator-categorical-identityᵣ : Morphism.Identityᵣ{Obj = T} (\{x} → swap(trans{x})) (refl)
identity-eliminator-categorical-identityᵣ = Morphism.intro identity-eliminator-identityₗ
identity-eliminator-categorical-identity : Morphism.Identity{Obj = T} (\{x} → swap(trans{x})) (refl)
identity-eliminator-categorical-identity = [∧]-intro identity-eliminator-categorical-identityₗ identity-eliminator-categorical-identityᵣ
identity-eliminator-categorical-associativity : Morphism.Associativity{Obj = T} (\{x} → swap(trans{x}))
identity-eliminator-categorical-associativity = Morphism.intro (symmetry(_≡_) identity-eliminator-associativity)
identity-eliminator-categorical-inverterₗ : Polymorphism.Inverterₗ{Obj = T} (\{x} → swap(trans{x})) (refl) (sym)
identity-eliminator-categorical-inverterₗ = Polymorphism.intro identity-eliminator-inverseᵣ
identity-eliminator-categorical-inverterᵣ : Polymorphism.Inverterᵣ{Obj = T} (\{x} → swap(trans{x})) (refl) (sym)
identity-eliminator-categorical-inverterᵣ = Polymorphism.intro identity-eliminator-inverseₗ
identity-eliminator-categorical-inverter : Polymorphism.Inverter{Obj = T} (\{x} → swap(trans{x})) (refl) (sym)
identity-eliminator-categorical-inverter = [∧]-intro identity-eliminator-categorical-inverterₗ identity-eliminator-categorical-inverterᵣ
identity-eliminator-groupoid : Groupoid(Id)
Groupoid._∘_ identity-eliminator-groupoid = swap(trans)
Groupoid.id identity-eliminator-groupoid = refl
Groupoid.inv identity-eliminator-groupoid = sym
Groupoid.associativity identity-eliminator-groupoid = identity-eliminator-categorical-associativity
Groupoid.identity identity-eliminator-groupoid = identity-eliminator-categorical-identity
Groupoid.inverter identity-eliminator-groupoid = identity-eliminator-categorical-inverter
Groupoid.binaryOperator identity-eliminator-groupoid = intro a where postulate a : ∀{a} → a -- TODO
| {
"alphanum_fraction": 0.6717306862,
"avg_line_length": 52.1846846847,
"ext": "agda",
"hexsha": "0b036aa6eb8d83aa9c7cccc401a3e22c6395318c",
"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/Type/Identity/Proofs/Eliminator.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/Type/Identity/Proofs/Eliminator.agda",
"max_line_length": 192,
"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/Type/Identity/Proofs/Eliminator.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": 4256,
"size": 11585
} |
------------------------------------------------------------------------
-- Well-founded induction
------------------------------------------------------------------------
-- I want universe polymorphism.
open import Relation.Binary
module Induction1.WellFounded {a : Set} (_<_ : Rel a) where
open import Induction1
-- When using well-founded recursion you can recurse arbitrarily, as
-- long as the arguments become smaller, and "smaller" is
-- well-founded.
WfRec : RecStruct a
WfRec P x = ∀ y → y < x → P y
-- The accessibility predicate encodes what it means to be
-- well-founded; if all elements are accessible, then _<_ is
-- well-founded.
data Acc (x : a) : Set₁ where
acc : (rs : WfRec Acc x) → Acc x
-- Well-founded induction for the subset of accessible elements:
module Some where
wfRec-builder : SubsetRecursorBuilder Acc WfRec
wfRec-builder P f x (acc rs) = λ y y<x →
f y (wfRec-builder P f y (rs y y<x))
wfRec : SubsetRecursor Acc WfRec
wfRec = subsetBuild wfRec-builder
-- Well-founded induction for all elements, assuming they are all
-- accessible:
module All (allAcc : ∀ x → Acc x) where
wfRec-builder : RecursorBuilder WfRec
wfRec-builder P f x = Some.wfRec-builder P f x (allAcc x)
wfRec : Recursor WfRec
wfRec = build wfRec-builder
| {
"alphanum_fraction": 0.6308049536,
"avg_line_length": 26.9166666667,
"ext": "agda",
"hexsha": "ac88936f3bb71b48382cd02d15b81db4fa8b4dbd",
"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/Induction1/WellFounded.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/Induction1/WellFounded.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/Induction1/WellFounded.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": 329,
"size": 1292
} |
module HasDecidableSubstantiveDischarge where
open import OscarPrelude
open import HasSubstantiveDischarge
record HasDecidableSubstantiveDischarge (A : Set) : Set₁
where
field
⦃ hasSubstantiveDischarge ⦄ : HasSubstantiveDischarge A
_≽?_ : (+ - : A) → Dec $ + ≽ -
open HasDecidableSubstantiveDischarge ⦃ … ⦄ public
{-# DISPLAY HasDecidableSubstantiveDischarge._≽?_ _ = _≽?_ #-}
open import Membership
_⋆≽?_ : ∀ {A} ⦃ _ : HasDecidableSubstantiveDischarge A ⦄ → (+s : List A) → (- : A) → Dec (+s ⋆≽ -)
_⋆≽?_ [] - = no λ { (_ , () , _)}
_⋆≽?_ (+ ∷ +s) - with + ≽? -
… | yes +≽- = yes $ _ , zero , +≽-
… | no +⋡- with +s ⋆≽? -
… | yes (+' , +'∈+s , +'≽-) = yes $ _ , suc +'∈+s , +'≽-
… | no +s⋡- = no λ { (_ , zero , +≽-) → +⋡- +≽-
; (+' , suc +'∈+s , +'≽-) → +s⋡- $ _ , +'∈+s , +'≽- }
_≽⋆?_ : ∀ {A} ⦃ _ : HasDecidableSubstantiveDischarge A ⦄ → (+ : A) → (-s : List A) → Dec (+ ≽⋆ -s)
+ ≽⋆? [] = no (λ { (fst₁ , () , snd₁)})
+ ≽⋆? (- ∷ -s) with + ≽? -
… | yes +≽- = yes (_ , zero , +≽-)
… | no +⋡- with + ≽⋆? -s
… | yes (_ , i∈-s , +≽⋆i) = yes (_ , suc i∈-s , +≽⋆i)
… | no +⋡⋆-s = no (λ { (_ , zero , +≽-) → +⋡- +≽-
; (_ , suc -'∈-s , +≽-') → +⋡⋆-s (_ , -'∈-s , +≽-')})
_⋆≽⋆?_ : ∀ {A} ⦃ _ : HasDecidableSubstantiveDischarge A ⦄ → (+s : List A) → (-s : List A) → Dec (+s ⋆≽⋆ -s)
_⋆≽⋆?_ +s [] = yes λ _ ()
_⋆≽⋆?_ +s (- ∷ -s) with +s ⋆≽? -
… | no +s⋡- = no λ +s≽-∷-s → +s⋡- $ +s≽-∷-s (-) zero
… | yes +s≽- with +s ⋆≽⋆? -s
… | yes +s≽-s = yes λ { _ zero → +s≽-
; -' (suc -'∈-∷-s) → +s≽-s -' -'∈-∷-s }
… | no +s⋡-s = no λ +s≽-∷-s → +s⋡-s λ +' +'∈-s → +s≽-∷-s +' (suc +'∈-s)
open import HasNegation
◁?_ : ∀ {+} ⦃ _ : HasDecidableSubstantiveDischarge (+) ⦄
→ (+s : List +) → Dec $ ◁ +s
◁? [] = no λ {(_ , () , _)}
◁?_ (+ ∷ +s) with +s ⋆≽? ~ +
… | yes (_ , +'∈+s , +'≽~+) = yes $ _ , zero , _ , suc +'∈+s , +'≽~+
… | no +s⋆⋡~+ with ~ + ≽⋆? +s
… | yes (_ , c∈+s , ~+≽c) = yes (_ , suc c∈+s , _ , zero , ≽-contrapositive (+) _ ~+≽c)
… | no ~+⋡⋆+s with ◁? +s
… | yes (s , s∈+s , c , c∈+s , c≽~s) = yes $ _ , suc s∈+s , _ , suc c∈+s , c≽~s
… | no ⋪+s = no
λ { (_ , zero , _ , zero , c≽~s) → ≽-consistent (+) (+) (≽-reflexive +) c≽~s
; (_ , zero , c , suc c∈+s , c≽~s) → +s⋆⋡~+ (_ , c∈+s , c≽~s)
; (s , suc s∈+s , .+ , zero , +≽~s) → ~+⋡⋆+s (_ , s∈+s , ≽-contrapositive' (+) s +≽~s)
; (s , suc s∈+s , c , suc c∈+s , c≽~s) → ⋪+s (_ , s∈+s , _ , c∈+s , c≽~s) }
| {
"alphanum_fraction": 0.3946830266,
"avg_line_length": 39.435483871,
"ext": "agda",
"hexsha": "8104e9024dd2ecca95c9709583638d0c3ad013ef",
"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-1/HasDecidableSubstantiveDischarge.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-1/HasDecidableSubstantiveDischarge.agda",
"max_line_length": 107,
"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-1/HasDecidableSubstantiveDischarge.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1380,
"size": 2445
} |
module HasDecidableVacuousDischarge where
open import OscarPrelude
--open import HasVacuousDischarge
open import HasSubstantiveDischarge
open import HasNegation
record HasDecidableVacuousDischarge (A : Set) : Set₁
where
field
-- ⦃ hasVacuousDischarge ⦄ : HasVacuousDischarge A
⦃ hasNegation ⦄ : HasNegation A
⦃ hasSubstantiveDischarge ⦄ : HasSubstantiveDischarge A
◁?_ : (x : List A) → Dec $ ◁ x
open HasDecidableVacuousDischarge ⦃ … ⦄ public
{-# DISPLAY HasDecidableVacuousDischarge.◁?_ _ = ◁?_ #-}
| {
"alphanum_fraction": 0.7480916031,
"avg_line_length": 26.2,
"ext": "agda",
"hexsha": "bd0218cecb0414d3070e4f7d6187e7a69b1ffcf0",
"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-1/HasDecidableVacuousDischarge.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-1/HasDecidableVacuousDischarge.agda",
"max_line_length": 59,
"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-1/HasDecidableVacuousDischarge.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 179,
"size": 524
} |
-- Monoidal categories
{-# OPTIONS --safe #-}
module Cubical.Categories.Monoidal where
open import Cubical.Categories.Monoidal.Base public
open import Cubical.Categories.Monoidal.Enriched public
| {
"alphanum_fraction": 0.807106599,
"avg_line_length": 24.625,
"ext": "agda",
"hexsha": "bc2a153a1493ecf1fce7f6657fc7218e386b4d3b",
"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": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/Categories/Monoidal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"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": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/Categories/Monoidal.agda",
"max_line_length": 55,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Categories/Monoidal.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T21:49:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-05T21:49:23.000Z",
"num_tokens": 40,
"size": 197
} |
------------------------------------------------------------------------------
-- All the predicate logic modules
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOL.Everything where
open import FOL.Base
open import FOL.ExclusiveDisjunction.Base
open import FOL.ExclusiveDisjunction.TheoremsATP
open import FOL.ExclusiveDisjunction.TheoremsI
open import FOL.NonEmptyDomain.TheoremsATP
open import FOL.NonEmptyDomain.TheoremsI
open import FOL.NonIntuitionistic.TheoremsATP
open import FOL.NonIntuitionistic.TheoremsI
open import FOL.PropositionalLogic.TheoremsATP
open import FOL.PropositionalLogic.TheoremsI
open import FOL.SchemataATP
open import FOL.TheoremsATP
open import FOL.TheoremsI
| {
"alphanum_fraction": 0.6389811739,
"avg_line_length": 36.12,
"ext": "agda",
"hexsha": "9d4acb3936872b17e9e1e776de8c503d7cdfa89c",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOL/Everything.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOL/Everything.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOL/Everything.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 202,
"size": 903
} |
------------------------------------------------------------------------
-- Listed finite subsets
------------------------------------------------------------------------
-- Based on Frumin, Geuvers, Gondelman and van der Weide's "Finite
-- Sets in Homotopy Type Theory".
{-# OPTIONS --cubical --safe #-}
import Equality.Path as P
module Finite-subset.Listed
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq hiding (elim)
open import Dec
open import Logical-equivalence using (_⇔_)
open import Prelude as P hiding ([_,_]; swap)
open import Bag-equivalence equality-with-J as BE using (_∼[_]_; set)
open import Bijection equality-with-J as Bijection using (_↔_)
open import Equality.Decision-procedures equality-with-J
open import Equality.Path.Isomorphisms eq
open import Equality.Path.Isomorphisms.Univalence eq
open import Equivalence equality-with-J as Eq using (_≃_)
open import Erased.Cubical eq as EC
using (Erased; [_]; Dec-Erased; Dec→Dec-Erased)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as Trunc
using (∥_∥; ∣_∣; _∥⊎∥_)
open import Injection equality-with-J using (Injective)
import List equality-with-J as L
import Maybe equality-with-J as Maybe
open import Monad equality-with-J as M using (Raw-monad; Monad; _=<<_)
open import Nat equality-with-J as Nat using (_<_)
open import Quotient eq as Q using (_/_)
open import Surjection equality-with-J using (_↠_)
import Univalence-axiom equality-with-J as Univ
private
variable
a b : Level
A B : Type a
H ms p q x x₁ x₂ xs y y₁ y₂ ys z _≟_ : A
P : A → Type p
f g : (x : A) → P x
m n : ℕ
------------------------------------------------------------------------
-- Listed finite subsets
-- Listed finite subsets of a given type.
infixr 5 _∷_
data Finite-subset-of (A : Type a) : Type a where
[] : Finite-subset-of A
_∷_ : A → Finite-subset-of A → Finite-subset-of A
dropᴾ : x ∷ x ∷ y P.≡ x ∷ y
swapᴾ : x ∷ y ∷ z P.≡ y ∷ x ∷ z
is-setᴾ : P.Is-set (Finite-subset-of A)
-- Variants of some of the constructors.
drop :
{x : A} {y : Finite-subset-of A} →
x ∷ x ∷ y ≡ x ∷ y
drop = _↔_.from ≡↔≡ dropᴾ
swap :
{x y : A} {z : Finite-subset-of A} →
x ∷ y ∷ z ≡ y ∷ x ∷ z
swap = _↔_.from ≡↔≡ swapᴾ
is-set : Is-set (Finite-subset-of A)
is-set =
_↔_.from (H-level↔H-level 2) Finite-subset-of.is-setᴾ
------------------------------------------------------------------------
-- Eliminators
-- A dependent eliminator, expressed using paths.
record Elimᴾ {A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
no-eta-equality
field
[]ʳ : P []
∷ʳ : ∀ x → P y → P (x ∷ y)
dropʳ : ∀ x (p : P y) →
P.[ (λ i → P (dropᴾ {x = x} {y = y} i)) ]
∷ʳ x (∷ʳ x p) ≡ ∷ʳ x p
swapʳ : ∀ x y (p : P z) →
P.[ (λ i → P (swapᴾ {x = x} {y = y} {z = z} i)) ]
∷ʳ x (∷ʳ y p) ≡ ∷ʳ y (∷ʳ x p)
is-setʳ : ∀ x → P.Is-set (P x)
open Elimᴾ public
elimᴾ : Elimᴾ P → (x : Finite-subset-of A) → P x
elimᴾ {A = A} {P = P} e = helper
where
module E = Elimᴾ e
helper : (x : Finite-subset-of A) → P x
helper [] = E.[]ʳ
helper (x ∷ y) = E.∷ʳ x (helper y)
helper (dropᴾ {x = x} {y = y} i) =
E.dropʳ x (helper y) i
helper (swapᴾ {x = x} {y = y} {z = z} i) =
E.swapʳ x y (helper z) i
helper (is-setᴾ x y i j) =
P.heterogeneous-UIP
E.is-setʳ (Finite-subset-of.is-setᴾ x y)
(λ i → helper (x i)) (λ i → helper (y i)) i j
-- A non-dependent eliminator, expressed using paths.
record Recᴾ (A : Type a) (B : Type b) : Type (a ⊔ b) where
no-eta-equality
field
[]ʳ : B
∷ʳ : A → Finite-subset-of A → B → B
dropʳ : ∀ x y p →
∷ʳ x (x ∷ y) (∷ʳ x y p) P.≡ ∷ʳ x y p
swapʳ : ∀ x y z p →
∷ʳ x (y ∷ z) (∷ʳ y z p) P.≡ ∷ʳ y (x ∷ z) (∷ʳ x z p)
is-setʳ : P.Is-set B
open Recᴾ public
recᴾ : Recᴾ A B → Finite-subset-of A → B
recᴾ r = elimᴾ e
where
module R = Recᴾ r
e : Elimᴾ _
e .[]ʳ = R.[]ʳ
e .∷ʳ {y = y} x = R.∷ʳ x y
e .dropʳ {y = y} x = R.dropʳ x y
e .swapʳ {z = z} x y = R.swapʳ x y z
e .is-setʳ _ = R.is-setʳ
-- A dependent eliminator, expressed using equality.
record Elim {A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
no-eta-equality
field
[]ʳ : P []
∷ʳ : ∀ x → P y → P (x ∷ y)
dropʳ : ∀ x (p : P y) →
subst P (drop {x = x} {y = y}) (∷ʳ x (∷ʳ x p)) ≡ ∷ʳ x p
swapʳ : ∀ x y (p : P z) →
subst P (swap {x = x} {y = y} {z = z}) (∷ʳ x (∷ʳ y p)) ≡
∷ʳ y (∷ʳ x p)
is-setʳ : ∀ x → Is-set (P x)
open Elim public
elim : Elim P → (x : Finite-subset-of A) → P x
elim e = elimᴾ e′
where
module E = Elim e
e′ : Elimᴾ _
e′ .[]ʳ = E.[]ʳ
e′ .∷ʳ = E.∷ʳ
e′ .dropʳ x p = subst≡→[]≡ (E.dropʳ x p)
e′ .swapʳ x y p = subst≡→[]≡ (E.swapʳ x y p)
e′ .is-setʳ x = _↔_.to (H-level↔H-level 2) (E.is-setʳ x)
-- A non-dependent eliminator, expressed using equality.
record Rec (A : Type a) (B : Type b) : Type (a ⊔ b) where
no-eta-equality
field
[]ʳ : B
∷ʳ : A → Finite-subset-of A → B → B
dropʳ : ∀ x y p →
∷ʳ x (x ∷ y) (∷ʳ x y p) ≡ ∷ʳ x y p
swapʳ : ∀ x y z p →
∷ʳ x (y ∷ z) (∷ʳ y z p) ≡ ∷ʳ y (x ∷ z) (∷ʳ x z p)
is-setʳ : Is-set B
open Rec public
rec : Rec A B → Finite-subset-of A → B
rec r = recᴾ r′
where
module R = Rec r
r′ : Recᴾ _ _
r′ .[]ʳ = R.[]ʳ
r′ .∷ʳ = R.∷ʳ
r′ .dropʳ x y p = _↔_.to ≡↔≡ (R.dropʳ x y p)
r′ .swapʳ x y z p = _↔_.to ≡↔≡ (R.swapʳ x y z p)
r′ .is-setʳ = _↔_.to (H-level↔H-level 2) R.is-setʳ
-- A dependent eliminator for propositions.
record Elim-prop
{A : Type a} (P : Finite-subset-of A → Type p) :
Type (a ⊔ p) where
no-eta-equality
field
[]ʳ : P []
∷ʳ : ∀ x → P y → P (x ∷ y)
is-propositionʳ : ∀ x → Is-proposition (P x)
open Elim-prop public
elim-prop : Elim-prop P → (x : Finite-subset-of A) → P x
elim-prop e = elim e′
where
module E = Elim-prop e
e′ : Elim _
e′ .[]ʳ = E.[]ʳ
e′ .∷ʳ = E.∷ʳ
e′ .dropʳ _ _ = E.is-propositionʳ _ _ _
e′ .swapʳ _ _ _ = E.is-propositionʳ _ _ _
e′ .is-setʳ _ = mono₁ 1 (E.is-propositionʳ _)
-- A non-dependent eliminator for propositions.
record Rec-prop (A : Type a) (B : Type b) : Type (a ⊔ b) where
no-eta-equality
field
[]ʳ : B
∷ʳ : A → Finite-subset-of A → B → B
is-propositionʳ : Is-proposition B
open Rec-prop public
rec-prop : Rec-prop A B → Finite-subset-of A → B
rec-prop r = elim-prop e
where
module R = Rec-prop r
e : Elim-prop _
e .[]ʳ = R.[]ʳ
e .∷ʳ {y = y} x = R.∷ʳ x y
e .is-propositionʳ _ = R.is-propositionʳ
------------------------------------------------------------------------
-- Some operations
-- Singleton subsets.
singleton : A → Finite-subset-of A
singleton x = x ∷ []
-- The union of two finite subsets.
infixr 5 _∪_
_∪_ :
Finite-subset-of A → Finite-subset-of A →
Finite-subset-of A
[] ∪ y = y
(x ∷ y) ∪ z = x ∷ (y ∪ z)
dropᴾ {x = x} {y = y} i ∪ z =
dropᴾ {x = x} {y = y ∪ z} i
swapᴾ {x = x} {y = y} {z = z} i ∪ u =
swapᴾ {x = x} {y = y} {z = z ∪ u} i
is-setᴾ x y i j ∪ z =
is-setᴾ (λ i → x i ∪ z) (λ i → y i ∪ z) i j
-- [] is a right identity for _∪_.
∪[] :
(x : Finite-subset-of A) →
x ∪ [] ≡ x
∪[] = elim-prop e
where
e : Elim-prop _
e .is-propositionʳ _ = is-set
e .[]ʳ = refl _
e .∷ʳ {y = y} x hyp =
x ∷ y ∪ [] ≡⟨ cong (x ∷_) hyp ⟩∎
x ∷ y ∎
-- A lemma relating _∪_ and _∷_.
∪∷ :
(x : Finite-subset-of A) →
x ∪ (y ∷ z) ≡ y ∷ x ∪ z
∪∷ {y = y} {z = z} = elim-prop e
where
e : Elim-prop _
e .is-propositionʳ _ = is-set
e .[]ʳ = refl _
e .∷ʳ {y = u} x hyp =
(x ∷ u) ∪ (y ∷ z) ≡⟨⟩
x ∷ u ∪ (y ∷ z) ≡⟨ cong (x ∷_) hyp ⟩
x ∷ y ∷ u ∪ z ≡⟨ swap ⟩
y ∷ x ∷ u ∪ z ≡⟨⟩
y ∷ (x ∷ u) ∪ z ∎
-- Union is associative.
assoc :
(x : Finite-subset-of A) →
x ∪ (y ∪ z) ≡ (x ∪ y) ∪ z
assoc {y = y} {z = z} = elim-prop e
where
e : Elim-prop _
e .is-propositionʳ _ = is-set
e .[]ʳ = refl _
e .∷ʳ {y = u} x hyp =
x ∷ u ∪ (y ∪ z) ≡⟨ cong (x ∷_) hyp ⟩∎
x ∷ (u ∪ y) ∪ z ∎
-- Union is commutative.
comm :
(x : Finite-subset-of A) →
x ∪ y ≡ y ∪ x
comm {y = y} = elim-prop e
where
e : Elim-prop _
e .is-propositionʳ _ = is-set
e .[]ʳ =
[] ∪ y ≡⟨⟩
y ≡⟨ sym (∪[] y) ⟩∎
y ∪ [] ∎
e .∷ʳ {y = z} x hyp =
x ∷ z ∪ y ≡⟨ cong (x ∷_) hyp ⟩
x ∷ y ∪ z ≡⟨ sym (∪∷ y) ⟩∎
y ∪ (x ∷ z) ∎
-- Union is idempotent.
idem : (x : Finite-subset-of A) → x ∪ x ≡ x
idem = elim-prop e
where
e : Elim-prop _
e .[]ʳ =
[] ∪ [] ≡⟨⟩
[] ∎
e .∷ʳ {y = y} x hyp =
(x ∷ y) ∪ (x ∷ y) ≡⟨⟩
x ∷ y ∪ x ∷ y ≡⟨ cong (_ ∷_) (∪∷ y) ⟩
x ∷ x ∷ y ∪ y ≡⟨ drop ⟩
x ∷ y ∪ y ≡⟨ cong (_ ∷_) hyp ⟩∎
x ∷ y ∎
e .is-propositionʳ = λ _ → is-set
-- Union distributes from the left and right over union.
∪-distrib-left : ∀ x → x ∪ (y ∪ z) ≡ (x ∪ y) ∪ (x ∪ z)
∪-distrib-left {y = y} {z = z} x =
x ∪ (y ∪ z) ≡⟨ cong (_∪ _) $ sym (idem x) ⟩
(x ∪ x) ∪ (y ∪ z) ≡⟨ sym $ assoc x ⟩
x ∪ (x ∪ (y ∪ z)) ≡⟨ cong (x ∪_) $ assoc x ⟩
x ∪ ((x ∪ y) ∪ z) ≡⟨ cong ((x ∪_) ∘ (_∪ _)) $ comm x ⟩
x ∪ ((y ∪ x) ∪ z) ≡⟨ cong (x ∪_) $ sym $ assoc y ⟩
x ∪ (y ∪ (x ∪ z)) ≡⟨ assoc x ⟩∎
(x ∪ y) ∪ (x ∪ z) ∎
∪-distrib-right : ∀ x → (x ∪ y) ∪ z ≡ (x ∪ z) ∪ (y ∪ z)
∪-distrib-right {y = y} {z = z} x =
(x ∪ y) ∪ z ≡⟨ comm (x ∪ _) ⟩
z ∪ (x ∪ y) ≡⟨ ∪-distrib-left z ⟩
(z ∪ x) ∪ (z ∪ y) ≡⟨ cong₂ _∪_ (comm z) (comm z) ⟩∎
(x ∪ z) ∪ (y ∪ z) ∎
-- A map function.
map : (A → B) → Finite-subset-of A → Finite-subset-of B
map f = recᴾ r
where
r : Recᴾ _ _
r .[]ʳ = []
r .∷ʳ x _ y = f x ∷ y
r .dropʳ _ _ _ = dropᴾ
r .swapʳ _ _ _ _ = swapᴾ
r .is-setʳ = is-setᴾ
-- Join.
join : Finite-subset-of (Finite-subset-of A) → Finite-subset-of A
join = rec r
where
r : Rec _ _
r .[]ʳ = []
r .∷ʳ x _ = x ∪_
r .dropʳ x y z = x ∪ x ∪ z ≡⟨ assoc x ⟩
(x ∪ x) ∪ z ≡⟨ cong (_∪ _) (idem x) ⟩∎
x ∪ z ∎
r .swapʳ x y z u = x ∪ y ∪ u ≡⟨ assoc x ⟩
(x ∪ y) ∪ u ≡⟨ cong (_∪ _) (comm x) ⟩
(y ∪ x) ∪ u ≡⟨ sym (assoc y) ⟩∎
y ∪ x ∪ u ∎
r .is-setʳ = is-set
-- A universe-polymorphic variant of bind.
infixl 5 _>>=′_
_>>=′_ :
Finite-subset-of A → (A → Finite-subset-of B) → Finite-subset-of B
x >>=′ f = join (map f x)
-- Bind distributes from the right over union.
>>=-right-distributive :
∀ x → (x ∪ y) >>=′ f ≡ (x >>=′ f) ∪ (y >>=′ f)
>>=-right-distributive {y = y} {f = f} = elim-prop e
where
e : Elim-prop _
e .[]ʳ = refl _
e .is-propositionʳ _ = is-set
e .∷ʳ {y = z} x hyp =
((x ∷ z) ∪ y) >>=′ f ≡⟨⟩
f x ∪ ((z ∪ y) >>=′ f) ≡⟨ cong (f x ∪_) hyp ⟩
f x ∪ ((z >>=′ f) ∪ (y >>=′ f)) ≡⟨ assoc (f x) ⟩
(f x ∪ (z >>=′ f)) ∪ (y >>=′ f) ≡⟨⟩
((x ∷ z) >>=′ f) ∪ (y >>=′ f) ∎
-- Bind distributes from the left over union.
>>=-left-distributive :
∀ x → (x >>=′ λ x → f x ∪ g x) ≡ (x >>=′ f) ∪ (x >>=′ g)
>>=-left-distributive {f = f} {g = g} = elim-prop e
where
e : Elim-prop _
e .[]ʳ = refl _
e .is-propositionʳ _ = is-set
e .∷ʳ {y = y} x hyp =
(x ∷ y) >>=′ (λ x → f x ∪ g x) ≡⟨⟩
(f x ∪ g x) ∪ (y >>=′ λ x → f x ∪ g x) ≡⟨ cong ((f x ∪ g x) ∪_) hyp ⟩
(f x ∪ g x) ∪ ((y >>=′ f) ∪ (y >>=′ g)) ≡⟨ sym (assoc (f x)) ⟩
f x ∪ (g x ∪ ((y >>=′ f) ∪ (y >>=′ g))) ≡⟨ cong (f x ∪_) (assoc (g x)) ⟩
f x ∪ ((g x ∪ (y >>=′ f)) ∪ (y >>=′ g)) ≡⟨ cong ((f x ∪_) ∘ (_∪ (y >>=′ g))) (comm (g x)) ⟩
f x ∪ (((y >>=′ f) ∪ g x) ∪ (y >>=′ g)) ≡⟨ cong (f x ∪_) (sym (assoc (y >>=′ f))) ⟩
f x ∪ ((y >>=′ f) ∪ (g x ∪ (y >>=′ g))) ≡⟨ assoc (f x) ⟩
(f x ∪ (y >>=′ f)) ∪ (g x ∪ (y >>=′ g)) ≡⟨⟩
((x ∷ y) >>=′ f) ∪ ((x ∷ y) >>=′ g) ∎
-- Monad laws.
singleton->>= :
(f : A → Finite-subset-of B) →
singleton x >>=′ f ≡ f x
singleton->>= {x = x} f =
f x ∪ [] ≡⟨ ∪[] _ ⟩∎
f x ∎
>>=-singleton : x >>=′ singleton ≡ x
>>=-singleton = elim-prop e _
where
e : Elim-prop (λ x → x >>=′ singleton ≡ x)
e .[]ʳ = refl _
e .is-propositionʳ _ = is-set
e .∷ʳ {y = y} x hyp =
x ∷ (y >>=′ singleton) ≡⟨ cong (_ ∷_) hyp ⟩∎
x ∷ y ∎
>>=-assoc : ∀ x → x >>=′ (λ x → f x >>=′ g) ≡ x >>=′ f >>=′ g
>>=-assoc {f = f} {g = g} = elim-prop e
where
e : Elim-prop _
e .[]ʳ = refl _
e .is-propositionʳ _ = is-set
e .∷ʳ {y = y} x hyp =
(x ∷ y) >>=′ (λ x → f x >>=′ g) ≡⟨⟩
(f x >>=′ g) ∪ (y >>=′ λ x → f x >>=′ g) ≡⟨ cong ((f x >>=′ g) ∪_) hyp ⟩
(f x >>=′ g) ∪ (y >>=′ f >>=′ g) ≡⟨ sym (>>=-right-distributive (f x)) ⟩
(f x ∪ (y >>=′ f)) >>=′ g ≡⟨⟩
(x ∷ y) >>=′ f >>=′ g ∎
-- A monad instance.
instance
raw-monad : Raw-monad {d = a} Finite-subset-of
raw-monad .M.return = singleton
raw-monad .M._>>=_ = _>>=′_
monad : Monad {d = a} Finite-subset-of
monad .M.Monad.raw-monad = raw-monad
monad .M.Monad.left-identity _ = singleton->>=
monad .M.Monad.right-identity _ = >>=-singleton
monad .M.Monad.associativity x _ _ = >>=-assoc x
------------------------------------------------------------------------
-- Membership
private
-- Membership is used to define _∈_ and ∈-propositional below.
Membership : {A : Type a} → A → Finite-subset-of A → Proposition a
Membership x = rec r
where
r : Rec _ _
r .[]ʳ = ⊥ , ⊥-propositional
r .∷ʳ y z (x∈z , _) =
(x ≡ y ∥⊎∥ x∈z) , Trunc.truncation-is-proposition
r .dropʳ y z (P , P-prop) =
_↔_.to (ignore-propositional-component
(H-level-propositional ext 1)) $
Univ.≃⇒≡ univ
(x ≡ y ∥⊎∥ x ≡ y ∥⊎∥ P ↔⟨ Trunc.∥⊎∥-assoc ⟩
(x ≡ y ∥⊎∥ x ≡ y) ∥⊎∥ P ↔⟨ Trunc.idempotent Trunc.∥⊎∥-cong F.id ⟩
∥ x ≡ y ∥ ∥⊎∥ P ↔⟨ inverse Trunc.truncate-left-∥⊎∥ ⟩□
x ≡ y ∥⊎∥ P □)
r .swapʳ y z u (P , P-prop) =
_↔_.to (ignore-propositional-component
(H-level-propositional ext 1)) $
Univ.≃⇒≡ univ
(x ≡ y ∥⊎∥ x ≡ z ∥⊎∥ P ↔⟨ Trunc.∥⊎∥-assoc ⟩
(x ≡ y ∥⊎∥ x ≡ z) ∥⊎∥ P ↔⟨ (Trunc.∥⊎∥-comm Trunc.∥⊎∥-cong F.id) ⟩
(x ≡ z ∥⊎∥ x ≡ y) ∥⊎∥ P ↔⟨ inverse Trunc.∥⊎∥-assoc ⟩□
x ≡ z ∥⊎∥ x ≡ y ∥⊎∥ P □)
r .is-setʳ = Univ.∃-H-level-H-level-1+ ext univ 1
-- Membership.
--
-- The type is wrapped to make it easier for Agda to infer the subset
-- argument.
private
module Dummy where
infix 4 _∈_
record _∈_ {A : Type a} (x : A) (y : Finite-subset-of A) : Type a where
constructor box
field
unbox : proj₁ (Membership x y)
open Dummy public using (_∈_) hiding (module _∈_)
-- The negation of membership.
infix 4 _∉_
_∉_ : {A : Type a} → A → Finite-subset-of A → Type a
x ∉ y = ¬ x ∈ y
private
-- An unfolding lemma.
∈≃ : (x ∈ y) ≃ proj₁ (Membership x y)
∈≃ = Eq.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = Dummy._∈_.unbox
; from = Dummy.box
}
; right-inverse-of = refl
}
; left-inverse-of = refl
})
-- Membership is propositional.
∈-propositional : Is-proposition (x ∈ y)
∈-propositional {x = x} {y = y} = $⟨ proj₂ (Membership x y) ⟩
Is-proposition (proj₁ (Membership x y)) ↝⟨ H-level-cong _ 1 (inverse ∈≃) ⦂ (_ → _) ⟩□
Is-proposition (x ∈ y) □
-- A lemma characterising [].
∈[]≃ : (x ∈ []) ≃ ⊥₀
∈[]≃ {x = x} =
x ∈ [] ↝⟨ ∈≃ ⟩
⊥ ↔⟨ ⊥↔⊥ ⟩□
⊥₀ □
-- A lemma characterising _∷_.
∈∷≃ : (x ∈ y ∷ z) ≃ (x ≡ y ∥⊎∥ x ∈ z)
∈∷≃ {x = x} {y = y} {z = z} =
x ∈ y ∷ z ↝⟨ ∈≃ ⟩
x ≡ y ∥⊎∥ proj₁ (Membership x z) ↝⟨ F.id Trunc.∥⊎∥-cong inverse ∈≃ ⟩□
x ≡ y ∥⊎∥ x ∈ z □
-- A variant.
∈≢∷≃ : x ≢ y → (x ∈ y ∷ z) ≃ (x ∈ z)
∈≢∷≃ {x = x} {y = y} {z = z} x≢y =
x ∈ y ∷ z ↝⟨ ∈∷≃ ⟩
x ≡ y ∥⊎∥ x ∈ z ↔⟨ Trunc.drop-⊥-left-∥⊎∥ ∈-propositional x≢y ⟩□
x ∈ z □
-- A lemma characterising singleton.
∈singleton≃ :
(x ∈ singleton y) ≃ ∥ x ≡ y ∥
∈singleton≃ {x = x} {y = y} =
x ∈ singleton y ↝⟨ ∈∷≃ ⟩
x ≡ y ∥⊎∥ x ∈ [] ↔⟨ Trunc.∥∥-cong $ drop-⊥-right ∈[]≃ ⟩□
∥ x ≡ y ∥ □
-- Some "introduction rules" for _∈_.
∈→∈∷ : x ∈ z → x ∈ y ∷ z
∈→∈∷ {x = x} {z = z} {y = y} =
x ∈ z ↝⟨ ∣_∣ ∘ inj₂ ⟩
x ≡ y ∥⊎∥ x ∈ z ↔⟨ inverse ∈∷≃ ⟩□
x ∈ y ∷ z □
∥≡∥→∈∷ : ∥ x ≡ y ∥ → x ∈ y ∷ z
∥≡∥→∈∷ {x = x} {y = y} {z = z} =
∥ x ≡ y ∥ ↝⟨ Trunc.∥∥-map inj₁ ⟩
x ≡ y ∥⊎∥ x ∈ z ↔⟨ inverse ∈∷≃ ⟩□
x ∈ y ∷ z □
≡→∈∷ : x ≡ y → x ∈ y ∷ z
≡→∈∷ = ∥≡∥→∈∷ ∘ ∣_∣
∥≡∥→∈singleton : ∥ x ≡ y ∥ → x ∈ singleton y
∥≡∥→∈singleton = ∥≡∥→∈∷
≡→∈singleton : x ≡ y → x ∈ singleton y
≡→∈singleton = ≡→∈∷
-- Membership of a union of two subsets can be expressed in terms of
-- membership of the subsets.
∈∪≃ : (x ∈ y ∪ z) ≃ (x ∈ y ∥⊎∥ x ∈ z)
∈∪≃ {x = x} {y = y} {z = z} = elim-prop e y
where
e : Elim-prop (λ y → (x ∈ y ∪ z) ≃ (x ∈ y ∥⊎∥ x ∈ z))
e .[]ʳ =
x ∈ z ↔⟨ inverse $ Trunc.∥∥↔ ∈-propositional ⟩
∥ x ∈ z ∥ ↔⟨ Trunc.∥∥-cong (inverse $ drop-⊥-left ∈[]≃) ⟩□
x ∈ [] ∥⊎∥ x ∈ z □
e .∷ʳ {y = u} y hyp =
x ∈ y ∷ u ∪ z ↝⟨ ∈∷≃ ⟩
x ≡ y ∥⊎∥ x ∈ u ∪ z ↝⟨ F.id Trunc.∥⊎∥-cong hyp ⟩
x ≡ y ∥⊎∥ x ∈ u ∥⊎∥ x ∈ z ↔⟨ Trunc.∥⊎∥-assoc ⟩
(x ≡ y ∥⊎∥ x ∈ u) ∥⊎∥ x ∈ z ↝⟨ Trunc.∥∥-cong (inverse ∈∷≃ ⊎-cong F.id) ⟩□
x ∈ y ∷ u ∥⊎∥ x ∈ z □
e .is-propositionʳ _ =
Eq.left-closure ext 0 ∈-propositional
-- More "introduction rules".
∈→∈∪ˡ : x ∈ y → x ∈ y ∪ z
∈→∈∪ˡ {x = x} {y = y} {z = z} =
x ∈ y ↝⟨ ∣_∣ ∘ inj₁ ⟩
x ∈ y ∥⊎∥ x ∈ z ↔⟨ inverse ∈∪≃ ⟩□
x ∈ y ∪ z □
∈→∈∪ʳ : ∀ y → x ∈ z → x ∈ y ∪ z
∈→∈∪ʳ {x = x} {z = z} y =
x ∈ z ↝⟨ ∈→∈∪ˡ ⟩
x ∈ z ∪ y ↝⟨ ≡⇒↝ _ (cong (_ ∈_) (comm z)) ⟩□
x ∈ y ∪ z □
-- A lemma characterising join.
∈join≃ : (x ∈ join z) ≃ ∥ (∃ λ y → x ∈ y × y ∈ z) ∥
∈join≃ {x = x} = elim-prop e _
where
e : Elim-prop (λ z → (x ∈ join z) ≃ ∥ (∃ λ y → x ∈ y × y ∈ z) ∥)
e .[]ʳ =
x ∈ join [] ↔⟨⟩
x ∈ [] ↝⟨ ∈[]≃ ⟩
⊥ ↔⟨ inverse $ Trunc.∥∥↔ ⊥-propositional ⟩
∥ ⊥ ∥ ↔⟨ Trunc.∥∥-cong (inverse (×-right-zero {ℓ₁ = lzero} F.∘
∃-cong (λ _ → ×-right-zero))) ⟩
∥ (∃ λ y → x ∈ y × ⊥) ∥ ↝⟨ Trunc.∥∥-cong (∃-cong λ _ → ∃-cong λ _ → inverse ∈[]≃) ⟩□
∥ (∃ λ y → x ∈ y × y ∈ []) ∥ □
e .∷ʳ {y = z} u hyp =
x ∈ join (u ∷ z) ↔⟨⟩
x ∈ u ∪ join z ↝⟨ ∈∪≃ ⟩
x ∈ u ∥⊎∥ x ∈ join z ↝⟨ F.id Trunc.∥⊎∥-cong hyp ⟩
x ∈ u ∥⊎∥ ∥ (∃ λ y → x ∈ y × y ∈ z) ∥ ↔⟨ inverse Trunc.truncate-right-∥⊎∥ ⟩
x ∈ u ∥⊎∥ (∃ λ y → x ∈ y × y ∈ z) ↔⟨ ∃-intro _ _ Trunc.∥⊎∥-cong F.id ⟩
(∃ λ y → x ∈ y × y ≡ u) ∥⊎∥ (∃ λ y → x ∈ y × y ∈ z) ↔⟨ Trunc.∥∥-cong $ inverse $
∃-⊎-distrib-left F.∘
(∃-cong λ _ → ∃-⊎-distrib-left) ⟩
∥ (∃ λ y → x ∈ y × (y ≡ u ⊎ y ∈ z)) ∥ ↔⟨ inverse $
Trunc.flatten′
(λ F → ∃ λ y → x ∈ y × F (y ≡ u ⊎ y ∈ z))
(λ f → Σ-map id (Σ-map id f))
(λ (y , p , q) → Trunc.∥∥-map (λ q → y , p , q) q) ⟩
∥ (∃ λ y → x ∈ y × (y ≡ u ∥⊎∥ y ∈ z)) ∥ ↝⟨ (Trunc.∥∥-cong $ ∃-cong λ _ → ∃-cong λ _ → inverse ∈∷≃) ⟩□
∥ (∃ λ y → x ∈ y × y ∈ u ∷ z) ∥ □
e .is-propositionʳ _ =
Eq.left-closure ext 0 ∈-propositional
-- If truncated equality is decidable, then membership is also
-- decidable.
member? :
((x y : A) → Dec ∥ x ≡ y ∥) →
(x : A) (y : Finite-subset-of A) → Dec (x ∈ y)
member? equal? x = elim-prop e
where
e : Elim-prop _
e .[]ʳ = no λ ()
e .∷ʳ {y = z} y = case equal? x y of λ where
(yes ∥x≡y∥) _ → yes (∥≡∥→∈∷ ∥x≡y∥)
(no ¬∥x≡y∥) →
P.[ (λ x∈z → yes (∈→∈∷ x∈z))
, (λ x∉z → no (
x ∈ y ∷ z ↔⟨ ∈∷≃ ⟩
x ≡ y ∥⊎∥ x ∈ z ↝⟨ Trunc.∥∥-map P.[ ¬∥x≡y∥ ∘ ∣_∣ , x∉z ] ⟩
∥ ⊥ ∥ ↔⟨ Trunc.not-inhabited⇒∥∥↔⊥ id ⟩□
⊥ □))
]
e .is-propositionʳ y =
Dec-closure-propositional ext ∈-propositional
-- A variant that uses Dec-Erased instead of Dec.
member?ᴱ :
((x y : A) → Dec-Erased ∥ x ≡ y ∥) →
(x : A) (y : Finite-subset-of A) → Dec-Erased (x ∈ y)
member?ᴱ equal? x = elim-prop e
where
e : Elim-prop _
e .[]ʳ = no [ (λ ()) ]
e .∷ʳ {y = z} y = case equal? x y of λ where
(yes [ ∥x≡y∥ ]) _ → yes [ ∥≡∥→∈∷ ∥x≡y∥ ]
(no [ ¬∥x≡y∥ ]) →
P.[ (λ ([ x∈z ]) → yes [ ∈→∈∷ x∈z ])
, (λ ([ x∉z ]) → no [
x ∈ y ∷ z ↔⟨ ∈∷≃ ⟩
x ≡ y ∥⊎∥ x ∈ z ↝⟨ Trunc.∥∥-map P.[ ¬∥x≡y∥ ∘ ∣_∣ , x∉z ] ⟩
∥ ⊥ ∥ ↔⟨ Trunc.not-inhabited⇒∥∥↔⊥ id ⟩□
⊥ □ ])
]
e .is-propositionʳ y =
EC.Is-proposition-Dec-Erased ext ∈-propositional
-- If x is a member of y, then x ∷ y is equal to y.
∈→∷≡ : x ∈ y → x ∷ y ≡ y
∈→∷≡ {x = x} = elim-prop e _
where
e : Elim-prop (λ y → x ∈ y → x ∷ y ≡ y)
e .∷ʳ {y = y} z hyp =
x ∈ z ∷ y ↔⟨ ∈∷≃ ⟩
x ≡ z ∥⊎∥ x ∈ y ↝⟨ id Trunc.∥⊎∥-cong hyp ⟩
x ≡ z ∥⊎∥ x ∷ y ≡ y ↝⟨ Trunc.rec is-set
P.[ (λ x≡z →
x ∷ z ∷ y ≡⟨ cong (λ x → x ∷ _) x≡z ⟩
z ∷ z ∷ y ≡⟨ drop ⟩∎
z ∷ y ∎)
, (λ x∷y≡y →
x ∷ z ∷ y ≡⟨ swap ⟩
z ∷ x ∷ y ≡⟨ cong (_ ∷_) x∷y≡y ⟩∎
z ∷ y ∎)
] ⟩□
x ∷ z ∷ y ≡ z ∷ y □
e .is-propositionʳ _ =
Π-closure ext 1 λ _ →
is-set
------------------------------------------------------------------------
-- Subsets of subsets
-- Subsets.
infix 4 _⊆_
_⊆_ : {A : Type a} → Finite-subset-of A → Finite-subset-of A → Type a
x ⊆ y = ∀ z → z ∈ x → z ∈ y
-- _⊆_ is pointwise propositional.
⊆-propositional : Is-proposition (x ⊆ y)
⊆-propositional =
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
∈-propositional
-- The subset property can be expressed using _∪_ and _≡_.
⊆≃∪≡ : ∀ x → (x ⊆ y) ≃ (x ∪ y ≡ y)
⊆≃∪≡ {y = y} x =
_↠_.from
(Eq.≃↠⇔
(Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
∈-propositional)
is-set)
(record
{ to = elim-prop e x
; from = λ p z →
z ∈ x ↝⟨ ∈→∈∪ˡ ⟩
z ∈ x ∪ y ↝⟨ ≡⇒↝ _ (cong (z ∈_) p) ⟩□
z ∈ y □
})
where
e : Elim-prop (λ x → x ⊆ y → x ∪ y ≡ y)
e .[]ʳ _ =
[] ∪ y ≡⟨⟩
y ∎
e .∷ʳ {y = z} x hyp x∷z⊆y =
x ∷ z ∪ y ≡⟨ cong (x ∷_) (hyp (λ _ → x∷z⊆y _ ∘ ∈→∈∷)) ⟩
x ∷ y ≡⟨ ∈→∷≡ (x∷z⊆y x (≡→∈∷ (refl _))) ⟩∎
y ∎
e .is-propositionʳ _ =
Π-closure ext 1 λ _ →
is-set
-- Extensionality.
extensionality :
(x ≡ y) ≃ (∀ z → z ∈ x ⇔ z ∈ y)
extensionality {x = x} {y = y} =
_↠_.from
(Eq.≃↠⇔
is-set
(Π-closure ext 1 λ _ →
⇔-closure ext 1
∈-propositional
∈-propositional))
(record
{ to = λ x≡y z → ≡⇒↝ _ (cong (z ∈_) x≡y)
; from =
(∀ z → z ∈ x ⇔ z ∈ y) ↝⟨ (λ p → _⇔_.to ∘ p , _⇔_.from ∘ p) ⟩
x ⊆ y × y ⊆ x ↔⟨ ⊆≃∪≡ x ×-cong ⊆≃∪≡ y ⟩
x ∪ y ≡ y × y ∪ x ≡ x ↝⟨ (λ (p , q) → trans (sym q) (trans (comm y) p)) ⟩□
x ≡ y □
})
-- Another way to characterise equality.
≡≃⊆×⊇ : (x ≡ y) ≃ (x ⊆ y × y ⊆ x)
≡≃⊆×⊇ {x = x} {y = y} =
x ≡ y ↝⟨ extensionality ⟩
(∀ z → z ∈ x ⇔ z ∈ y) ↝⟨ Eq.⇔→≃
(Π-closure ext 1 λ _ →
⇔-closure ext 1
∈-propositional
∈-propositional)
(×-closure 1 ⊆-propositional ⊆-propositional)
(λ hyp → _⇔_.to ∘ hyp , _⇔_.from ∘ hyp)
(λ (x⊆y , y⊆x) z → record { to = x⊆y z ; from = y⊆x z }) ⟩□
x ⊆ y × y ⊆ x □
-- _⊆_ is a partial order.
⊆-refl : x ⊆ x
⊆-refl _ = id
⊆-trans : x ⊆ y → y ⊆ z → x ⊆ z
⊆-trans x⊆y y⊆z _ = y⊆z _ ∘ x⊆y _
⊆-antisymmetric : x ⊆ y → y ⊆ x → x ≡ y
⊆-antisymmetric = curry (_≃_.from ≡≃⊆×⊇)
-- If truncated equality is decidable, then _⊆_ is also decidable.
subset? :
((x y : A) → Dec ∥ x ≡ y ∥) →
(x y : Finite-subset-of A) → Dec (x ⊆ y)
subset? equal? x y = elim-prop r x
where
r : Elim-prop (λ x → Dec (x ⊆ y))
r .[]ʳ = yes λ z →
z ∈ [] ↔⟨ ∈[]≃ ⟩
⊥ ↝⟨ ⊥-elim ⟩□
z ∈ y □
r .∷ʳ {y = x} z =
Dec (x ⊆ y) ↝⟨ member? equal? z y ,_ ⟩
Dec (z ∈ y) × Dec (x ⊆ y) ↝⟨ uncurry
P.[ (λ u∈y → Dec-map (
x ⊆ y ↝⟨ record
{ to = λ x⊆y u →
P.[ (λ z≡u → subst (_∈ y) (sym z≡u) u∈y)
, x⊆y u
]
; from = λ hyp u → hyp u ∘ inj₂
} ⟩
(∀ u → u ≡ z ⊎ u ∈ x → u ∈ y) ↔⟨ (∀-cong ext λ _ → inverse $
Trunc.universal-property ∈-propositional) ⟩
(∀ u → u ≡ z ∥⊎∥ u ∈ x → u ∈ y) ↝⟨ (∀-cong _ λ _ → →-cong₁ _ (inverse ∈∷≃)) ⟩
(∀ u → u ∈ z ∷ x → u ∈ y) ↔⟨⟩
z ∷ x ⊆ y □))
, (λ u∉y _ → no (
z ∷ x ⊆ y ↝⟨ (λ u∷x⊆y → u∷x⊆y z (≡→∈∷ (refl _))) ⟩
z ∈ y ↝⟨ u∉y ⟩□
⊥ □))
] ⟩□
Dec (z ∷ x ⊆ y) □
r .is-propositionʳ _ =
Dec-closure-propositional ext ⊆-propositional
-- A variant of subset? that uses Dec-Erased.
subset?ᴱ :
((x y : A) → Dec-Erased ∥ x ≡ y ∥) →
(x y : Finite-subset-of A) → Dec-Erased (x ⊆ y)
subset?ᴱ equal? x y = elim-prop r x
where
r : Elim-prop (λ x → Dec-Erased (x ⊆ y))
r .[]ʳ = yes [ (λ z →
z ∈ [] ↔⟨ ∈[]≃ ⟩
⊥ ↝⟨ ⊥-elim ⟩□
z ∈ y □ )]
r .∷ʳ {y = x} z =
Dec-Erased (x ⊆ y) ↝⟨ member?ᴱ equal? z y ,_ ⟩
Dec-Erased (z ∈ y) × Dec-Erased (x ⊆ y) ↝⟨ uncurry
P.[ (λ ([ u∈y ]) → EC.Dec-Erased-map (
x ⊆ y ↝⟨ record
{ to = λ x⊆y u →
P.[ (λ z≡u → subst (_∈ y) (sym z≡u) u∈y)
, x⊆y u
]
; from = λ hyp u → hyp u ∘ inj₂
} ⟩
(∀ u → u ≡ z ⊎ u ∈ x → u ∈ y) ↔⟨ (∀-cong ext λ _ → inverse $
Trunc.universal-property ∈-propositional) ⟩
(∀ u → u ≡ z ∥⊎∥ u ∈ x → u ∈ y) ↝⟨ (∀-cong _ λ _ → →-cong₁ _ (inverse ∈∷≃)) ⟩
(∀ u → u ∈ z ∷ x → u ∈ y) ↔⟨⟩
z ∷ x ⊆ y □))
, (λ ([ u∉y ]) _ → no [
z ∷ x ⊆ y ↝⟨ (λ u∷x⊆y → u∷x⊆y z (≡→∈∷ (refl _))) ⟩
z ∈ y ↝⟨ u∉y ⟩□
⊥ □ ])
] ⟩□
Dec-Erased (z ∷ x ⊆ y) □
r .is-propositionʳ _ =
EC.Is-proposition-Dec-Erased ext ⊆-propositional
-- If truncated equality is decidable, then _≡_ is also decidable.
equal? :
((x y : A) → Dec ∥ x ≡ y ∥) →
(x y : Finite-subset-of A) → Dec (x ≡ y)
equal? eq? x y = $⟨ subset? eq? x y , subset? eq? y x ⟩
Dec (x ⊆ y) × Dec (y ⊆ x) ↝⟨ uncurry Dec-× ⟩
Dec (x ⊆ y × y ⊆ x) ↝⟨ Dec-map (from-equivalence $ inverse ≡≃⊆×⊇) ⟩□
Dec (x ≡ y) □
-- A variant of equal? that uses Dec-Erased.
equal?ᴱ :
((x y : A) → Dec-Erased ∥ x ≡ y ∥) →
(x y : Finite-subset-of A) → Dec-Erased (x ≡ y)
equal?ᴱ eq? x y = $⟨ subset?ᴱ eq? x y , subset?ᴱ eq? y x ⟩
Dec-Erased (x ⊆ y) × Dec-Erased (y ⊆ x) ↝⟨ EC.Dec-Erased↔Dec-Erased _ ×-cong EC.Dec-Erased↔Dec-Erased _ ⟩
Dec (Erased (x ⊆ y)) × Dec (Erased (y ⊆ x)) ↝⟨ uncurry Dec-× ⟩
Dec (Erased (x ⊆ y) × Erased (y ⊆ x)) ↝⟨ Dec-map (from-isomorphism $ inverse EC.Erased-Σ↔Σ) ⟩
Dec (Erased (x ⊆ y × y ⊆ x)) ↝⟨ _⇔_.from $ EC.Dec-Erased↔Dec-Erased _ ⟩
Dec-Erased (x ⊆ y × y ⊆ x) ↝⟨ EC.Dec-Erased-map (from-equivalence $ inverse ≡≃⊆×⊇) ⟩□
Dec-Erased (x ≡ y) □
------------------------------------------------------------------------
-- The functions map-Maybe, filter, minus and delete
private
-- A function used to define map-Maybe.
map-Maybe-cons : Maybe B → Finite-subset-of B → Finite-subset-of B
map-Maybe-cons nothing y = y
map-Maybe-cons (just x) y = x ∷ y
-- A combination of map and filter.
map-Maybe : (A → Maybe B) → Finite-subset-of A → Finite-subset-of B
map-Maybe f = rec r
where
r : Rec _ _
r .[]ʳ = []
r .∷ʳ x _ y = map-Maybe-cons (f x) y
r .is-setʳ = is-set
r .dropʳ x _ y = lemma (f x)
where
lemma :
∀ m → map-Maybe-cons m (map-Maybe-cons m y) ≡ map-Maybe-cons m y
lemma nothing = refl _
lemma (just _) = drop
r .swapʳ x y _ z = lemma (f x) (f y)
where
lemma :
∀ m₁ m₂ →
map-Maybe-cons m₁ (map-Maybe-cons m₂ z) ≡
map-Maybe-cons m₂ (map-Maybe-cons m₁ z)
lemma (just _) (just _) = swap
lemma _ nothing = refl _
lemma nothing _ = refl _
-- A lemma characterising map-Maybe.
∈map-Maybe≃ :
(x ∈ map-Maybe f y) ≃ ∥ (∃ λ z → z ∈ y × f z ≡ just x) ∥
∈map-Maybe≃ {x = x} {f = f} = elim-prop e _
where
e : Elim-prop (λ y → (x ∈ map-Maybe f y) ≃
∥ (∃ λ z → z ∈ y × f z ≡ just x) ∥)
e .[]ʳ =
x ∈ map-Maybe f [] ↝⟨ ∈[]≃ ⟩
⊥ ↔⟨ inverse $ Trunc.∥∥↔ ⊥-propositional ⟩
∥ ⊥ ∥ ↔⟨ Trunc.∥∥-cong (inverse (×-right-zero {ℓ₁ = lzero} F.∘
∃-cong (λ _ → ×-left-zero))) ⟩
∥ (∃ λ z → ⊥ × f z ≡ just x) ∥ ↝⟨ Trunc.∥∥-cong (∃-cong λ _ → inverse ∈[]≃ ×-cong F.id) ⟩□
∥ (∃ λ z → z ∈ [] × f z ≡ just x) ∥ □
e .∷ʳ {y = y} z hyp =
(x ∈ map-Maybe f (z ∷ y)) ↝⟨ lemma _ _ ⟩
f z ≡ just x ∥⊎∥ (x ∈ map-Maybe f y) ↝⟨ from-isomorphism (inverse Trunc.truncate-right-∥⊎∥) F.∘
(F.id Trunc.∥⊎∥-cong hyp) ⟩
f z ≡ just x ∥⊎∥ (∃ λ u → u ∈ y × f u ≡ just x) ↔⟨ inverse $
drop-⊤-left-Σ (_⇔_.to contractible⇔↔⊤ $ singleton-contractible _) F.∘
Σ-assoc
Trunc.∥⊎∥-cong
F.id ⟩
(∃ λ u → u ≡ z × f u ≡ just x) ∥⊎∥ (∃ λ u → u ∈ y × f u ≡ just x) ↔⟨ Trunc.∥∥-cong $ inverse ∃-⊎-distrib-left ⟩
∥ (∃ λ u → u ≡ z × f u ≡ just x ⊎ u ∈ y × f u ≡ just x) ∥ ↔⟨ Trunc.∥∥-cong (∃-cong λ _ → inverse ∃-⊎-distrib-right) ⟩
∥ (∃ λ u → (u ≡ z ⊎ u ∈ y) × f u ≡ just x) ∥ ↔⟨ inverse $
Trunc.flatten′
(λ F → (∃ λ u → F (u ≡ z ⊎ u ∈ y) × f u ≡ just x))
(λ f → Σ-map id (Σ-map f id))
(λ (u , p , q) → Trunc.∥∥-map (λ p → u , p , q) p) ⟩
∥ (∃ λ u → (u ≡ z ∥⊎∥ u ∈ y) × f u ≡ just x) ∥ ↝⟨ Trunc.∥∥-cong (∃-cong λ _ → ×-cong₁ λ _ → inverse ∈∷≃) ⟩□
∥ (∃ λ u → u ∈ z ∷ y × f u ≡ just x) ∥ □
where
lemma : ∀ m y → (x ∈ map-Maybe-cons m y) ≃ (m ≡ just x ∥⊎∥ x ∈ y)
lemma nothing y =
x ∈ map-Maybe-cons nothing y ↔⟨⟩
x ∈ y ↔⟨ inverse $ Trunc.drop-⊥-left-∥⊎∥ ∈-propositional ⊎.inj₁≢inj₂ ⟩□
(nothing ≡ just x ∥⊎∥ x ∈ y) □
lemma (just z) y =
x ∈ map-Maybe-cons (just z) y ↔⟨⟩
x ∈ z ∷ y ↝⟨ ∈∷≃ ⟩
x ≡ z ∥⊎∥ x ∈ y ↔⟨ (Bijection.≡↔inj₂≡inj₂ F.∘ ≡-comm) Trunc.∥⊎∥-cong F.id ⟩□
just z ≡ just x ∥⊎∥ x ∈ y □
e .is-propositionʳ y =
Eq.left-closure ext 0 ∈-propositional
-- The function map-Maybe f commutes with map-Maybe g if f commutes
-- with g in a certain way.
map-Maybe-comm :
{A : Type a} {f g : A → Maybe A} →
(∀ x → f =<< g x ≡ g =<< f x) →
∀ x → map-Maybe f (map-Maybe g x) ≡ map-Maybe g (map-Maybe f x)
map-Maybe-comm {A = A} {f = f} {g = g}
hyp x = _≃_.from extensionality λ y →
y ∈ map-Maybe f (map-Maybe g x) ↝⟨ lemma₂ ⟩
∥ (∃ λ u → u ∈ x × f =<< g u ≡ just y) ∥ ↝⟨ Trunc.∥∥-cong (∃-cong λ _ → ∃-cong λ _ → ≡⇒↝ _ $ cong (_≡ _) $ hyp _) ⟩
∥ (∃ λ u → u ∈ x × g =<< f u ≡ just y) ∥ ↝⟨ inverse lemma₂ ⟩
y ∈ map-Maybe g (map-Maybe f x) □
where
lemma₁ :
∀ (f {g} : A → Maybe A) {x z} →
(∃ λ y → f x ≡ just y × g y ≡ just z) ⇔ (g =<< f x ≡ just z)
lemma₁ f {g = g} {x = x} {z = z} = record
{ to = λ (y , f≡ , g≡) →
g =<< f x ≡⟨⟩
Maybe.maybe g nothing (f x) ≡⟨ cong (Maybe.maybe g nothing) f≡ ⟩
g y ≡⟨ g≡ ⟩∎
just z ∎
; from = from (f x)
}
where
from :
(fx : Maybe A) →
g =<< fx ≡ just z →
∃ λ y → fx ≡ just y × g y ≡ just z
from nothing = ⊥-elim ∘ ⊎.inj₁≢inj₂
from (just y) = (y ,_) ∘ (refl _ ,_)
lemma₂ :
{f g : A → Maybe A} →
y ∈ map-Maybe f (map-Maybe g x) ⇔
∥ (∃ λ u → u ∈ x × f =<< g u ≡ just y) ∥
lemma₂ {y = y} {f = f} {g = g} =
y ∈ map-Maybe f (map-Maybe g x) ↔⟨ Trunc.∥∥-cong (∃-cong λ _ → ∈map-Maybe≃ ×-cong F.id) F.∘ ∈map-Maybe≃ ⟩
∥ (∃ λ z → ∥ (∃ λ u → u ∈ x × g u ≡ just z) ∥ × f z ≡ just y) ∥ ↔⟨ Trunc.flatten′
(λ F → ∃ λ z → F (∃ λ u → u ∈ x × _) × _)
(λ f → Σ-map id (Σ-map f id))
(λ (z , p , q) → Trunc.∥∥-map (λ p → z , p , q) p) ⟩
∥ (∃ λ z → (∃ λ u → u ∈ x × g u ≡ just z) × f z ≡ just y) ∥ ↔⟨ Trunc.∥∥-cong (∃-cong λ _ → inverse $ Σ-assoc F.∘ ∃-cong λ _ → Σ-assoc) ⟩
∥ (∃ λ z → ∃ λ u → u ∈ x × g u ≡ just z × f z ≡ just y) ∥ ↔⟨ Trunc.∥∥-cong ((∃-cong λ _ → ∃-comm) F.∘ ∃-comm) ⟩
∥ (∃ λ u → u ∈ x × ∃ λ z → g u ≡ just z × f z ≡ just y) ∥ ↝⟨ Trunc.∥∥-cong (∃-cong λ _ → ∃-cong λ _ → lemma₁ g) ⟩□
∥ (∃ λ u → u ∈ x × f =<< g u ≡ just y) ∥ □
-- The function map-Maybe commutes with union.
map-Maybe-∪ :
∀ x → map-Maybe f (x ∪ y) ≡ map-Maybe f x ∪ map-Maybe f y
map-Maybe-∪ {f = f} {y = y} x = _≃_.from extensionality λ z →
z ∈ map-Maybe f (x ∪ y) ↔⟨ (Trunc.∥∥-cong (∃-cong λ _ → ∈∪≃ ×-cong F.id)) F.∘ ∈map-Maybe≃ ⟩
∥ (∃ λ u → (u ∈ x ∥⊎∥ u ∈ y) × f u ≡ just z) ∥ ↔⟨ Trunc.flatten′
(λ F → ∃ λ u → F (u ∈ x ⊎ u ∈ y) × _)
(λ f → Σ-map id (Σ-map f id))
(λ (u , p , q) → Trunc.∥∥-map (λ p → u , p , q) p) ⟩
∥ (∃ λ u → (u ∈ x ⊎ u ∈ y) × f u ≡ just z) ∥ ↔⟨ Trunc.∥∥-cong (∃-cong λ _ → ∃-⊎-distrib-right) ⟩
∥ (∃ λ u → u ∈ x × f u ≡ just z ⊎ u ∈ y × f u ≡ just z) ∥ ↔⟨ Trunc.∥∥-cong ∃-⊎-distrib-left ⟩
(∃ λ u → u ∈ x × f u ≡ just z) ∥⊎∥
(∃ λ u → u ∈ y × f u ≡ just z) ↔⟨ inverse $
Trunc.flatten′ (λ F → F _ ⊎ F _) (λ f → ⊎-map f f)
P.[ Trunc.∥∥-map inj₁ , Trunc.∥∥-map inj₂ ] ⟩
∥ (∃ λ u → u ∈ x × f u ≡ just z) ∥ ∥⊎∥
∥ (∃ λ u → u ∈ y × f u ≡ just z) ∥ ↔⟨ inverse $ (∈map-Maybe≃ Trunc.∥⊎∥-cong ∈map-Maybe≃) F.∘ ∈∪≃ ⟩□
z ∈ map-Maybe f x ∪ map-Maybe f y □
-- One can express map using map-Maybe.
map≡map-Maybe-just :
(x : Finite-subset-of A) →
map f x ≡ map-Maybe (just ∘ f) x
map≡map-Maybe-just {f = f} = elim-prop e
where
e : Elim-prop _
e .[]ʳ = refl _
e .∷ʳ x = cong (f x ∷_)
e .is-propositionʳ _ = is-set
-- A lemma characterising map.
∈map≃ : (x ∈ map f y) ≃ ∥ (∃ λ z → z ∈ y × f z ≡ x) ∥
∈map≃ {x = x} {f = f} {y = y} =
x ∈ map f y ↝⟨ ≡⇒↝ _ $ cong (_ ∈_) $ map≡map-Maybe-just y ⟩
x ∈ map-Maybe (just ∘ f) y ↝⟨ ∈map-Maybe≃ ⟩
∥ (∃ λ z → z ∈ y × just (f z) ≡ just x) ∥ ↔⟨ Trunc.∥∥-cong (∃-cong λ _ → ∃-cong λ _ → inverse Bijection.≡↔inj₂≡inj₂) ⟩□
∥ (∃ λ z → z ∈ y × f z ≡ x) ∥ □
-- Some consequences of the characterisation of map.
∈→∈map :
{f : A → B} →
x ∈ y → f x ∈ map f y
∈→∈map {x = x} {y = y} {f = f} =
x ∈ y ↝⟨ (λ x∈y → ∣ x , x∈y , refl _ ∣) ⟩
∥ (∃ λ z → z ∈ y × f z ≡ f x) ∥ ↔⟨ inverse ∈map≃ ⟩□
f x ∈ map f y □
Injective→∈map≃ :
{f : A → B} →
Injective f →
(f x ∈ map f y) ≃ (x ∈ y)
Injective→∈map≃ {x = x} {y = y} {f = f} inj =
f x ∈ map f y ↝⟨ ∈map≃ ⟩
∥ (∃ λ z → z ∈ y × f z ≡ f x) ∥ ↝⟨ (Trunc.∥∥-cong-⇔ $ ∃-cong λ _ → ∃-cong λ _ →
record { to = inj; from = cong f }) ⟩
∥ (∃ λ z → z ∈ y × z ≡ x) ∥ ↔⟨ Trunc.∥∥-cong $ inverse $ ∃-intro _ _ ⟩
∥ x ∈ y ∥ ↔⟨ Trunc.∥∥↔ ∈-propositional ⟩□
x ∈ y □
-- The function map commutes with union.
map-∪ : ∀ x → map f (x ∪ y) ≡ map f x ∪ map f y
map-∪ {f = f} {y = y} x =
map f (x ∪ y) ≡⟨ map≡map-Maybe-just (x ∪ y) ⟩
map-Maybe (just ∘ f) (x ∪ y) ≡⟨ map-Maybe-∪ x ⟩
map-Maybe (just ∘ f) x ∪ map-Maybe (just ∘ f) y ≡⟨ sym $ cong₂ _∪_ (map≡map-Maybe-just x) (map≡map-Maybe-just y) ⟩∎
map f x ∪ map f y ∎
-- A filter function.
filter : (A → Bool) → Finite-subset-of A → Finite-subset-of A
filter p = map-Maybe (λ x → if p x then just x else nothing)
-- A lemma characterising filter.
∈filter≃ :
∀ p → (x ∈ filter p y) ≃ (T (p x) × x ∈ y)
∈filter≃ {x = x} {y = y} p =
x ∈ map-Maybe (λ x → if p x then just x else nothing) y ↝⟨ ∈map-Maybe≃ ⟩
∥ (∃ λ z → z ∈ y × if p z then just z else nothing ≡ just x) ∥ ↝⟨ (Trunc.∥∥-cong $ ∃-cong λ _ → ∃-cong λ _ → lemma _ (refl _)) ⟩
∥ (∃ λ z → z ∈ y × T (p z) × z ≡ x) ∥ ↔⟨ (Trunc.∥∥-cong $ ∃-cong λ _ →
(×-cong₁ λ z≡x → ≡⇒↝ _ $ cong (λ z → z ∈ y × T (p z)) z≡x) F.∘
Σ-assoc) ⟩
∥ (∃ λ z → (x ∈ y × T (p x)) × z ≡ x) ∥ ↔⟨ inverse Σ-assoc F.∘
(×-cong₁ λ _ →
×-comm F.∘
Trunc.∥∥↔ (×-closure 1 ∈-propositional (T-propositional (p x)))) F.∘
inverse Trunc.∥∥×∥∥↔∥×∥ F.∘
Trunc.∥∥-cong ∃-comm ⟩
T (p x) × x ∈ y × ∥ (∃ λ z → z ≡ x) ∥ ↔⟨ (∃-cong λ _ → drop-⊤-right λ _ →
_⇔_.to contractible⇔↔⊤ (singleton-contractible _) F.∘
Trunc.∥∥↔ (mono₁ 0 $ singleton-contractible _)) ⟩□
T (p x) × x ∈ y □
where
lemma :
∀ b → p z ≡ b →
(if b then just z else nothing ≡ just x) ≃
(T b × z ≡ x)
lemma {z = z} true eq =
just z ≡ just x ↔⟨ inverse Bijection.≡↔inj₂≡inj₂ ⟩
z ≡ x ↔⟨ inverse ×-left-identity ⟩□
⊤ × z ≡ x □
lemma {z = z} false eq =
nothing ≡ just x ↔⟨ Bijection.≡↔⊎ ⟩
⊥ ↔⟨ inverse ×-left-zero ⟩□
⊥ × z ≡ x □
-- The result of filtering is a subset of the original subset.
filter⊆ : ∀ p → filter p x ⊆ x
filter⊆ {x = x} p z =
z ∈ filter p x ↔⟨ ∈filter≃ p ⟩
T (p z) × z ∈ x ↝⟨ proj₂ ⟩□
z ∈ x □
-- Filtering commutes with itself.
filter-comm :
∀ (p q : A → Bool) x →
filter p (filter q x) ≡ filter q (filter p x)
filter-comm p q x = _≃_.from extensionality λ y →
y ∈ filter p (filter q x) ↔⟨ from-isomorphism Σ-assoc F.∘ (F.id ×-cong ∈filter≃ q) F.∘ ∈filter≃ p ⟩
(T (p y) × T (q y)) × y ∈ x ↔⟨ ×-comm ×-cong F.id ⟩
(T (q y) × T (p y)) × y ∈ x ↔⟨ inverse $ from-isomorphism Σ-assoc F.∘ (F.id ×-cong ∈filter≃ p) F.∘ ∈filter≃ q ⟩□
y ∈ filter q (filter p x) □
-- Filtering commutes with union.
filter-∪ :
∀ p x → filter p (x ∪ y) ≡ filter p x ∪ filter p y
filter-∪ _ = map-Maybe-∪
-- If erased truncated equality is decidable, then one subset can be
-- removed from another.
minus :
((x y : A) → Dec-Erased ∥ x ≡ y ∥) →
Finite-subset-of A → Finite-subset-of A → Finite-subset-of A
minus _≟_ x y =
filter (λ z → if member?ᴱ _≟_ z y then false else true) x
-- A lemma characterising minus.
∈minus≃ : (x ∈ minus _≟_ y z) ≃ (x ∈ y × x ∉ z)
∈minus≃ {x = x} {_≟_ = _≟_} {y = y} {z = z} =
x ∈ minus _≟_ y z ↝⟨ ∈filter≃ (λ _ → if member?ᴱ _ _ z then _ else _) ⟩
T (if member?ᴱ _≟_ x z then false else true) × x ∈ y ↔⟨ lemma (member?ᴱ _≟_ x z) ×-cong F.id ⟩
x ∉ z × x ∈ y ↔⟨ ×-comm ⟩□
x ∈ y × x ∉ z □
where
lemma :
(d : Dec-Erased A) →
T (if d then false else true) ↔ ¬ A
lemma {A = A} d@(yes a) =
T (if d then false else true) ↔⟨⟩
⊥ ↝⟨ Bijection.⊥↔uninhabited (_$ a) ⟩
¬ EC.Erased A ↝⟨ EC.¬-Erased↔¬ ext ⟩□
¬ A □
lemma {A = A} d@(no ¬a) =
T (if d then false else true) ↔⟨⟩
⊤ ↝⟨ inverse $
_⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(¬-propositional ext)
(EC.Stable-¬ ¬a) ⟩□
¬ A □
-- The result of minus is a subset of the original subset.
minus⊆ : ∀ y → minus _≟_ x y ⊆ x
minus⊆ y =
filter⊆ (λ _ → if member?ᴱ _ _ y then _ else _)
-- Minus commutes with itself (in a certain sense).
minus-comm :
∀ x y z →
minus _≟_ (minus _≟_ x y) z ≡ minus _≟_ (minus _≟_ x z) y
minus-comm x y z =
filter-comm
(λ _ → if member?ᴱ _ _ z then _ else _)
(λ _ → if member?ᴱ _ _ y then _ else _)
x
-- Minus commutes with union (in a certain sense).
minus-∪ :
∀ x z →
minus _≟_ (x ∪ y) z ≡ minus _≟_ x z ∪ minus _≟_ y z
minus-∪ x z = filter-∪ (λ _ → if member?ᴱ _ _ z then _ else _) x
-- A lemma relating minus, _⊆_ and _∪_.
minus⊆≃ :
{_≟_ : (x y : A) → Dec ∥ x ≡ y ∥} →
∀ y →
(minus (λ x y → Dec→Dec-Erased (x ≟ y)) x y ⊆ z) ≃
(x ⊆ y ∪ z)
minus⊆≃ {x = x} {z = z} {_≟_ = _≟_} y =
_↠_.from (Eq.≃↠⇔ ⊆-propositional ⊆-propositional) $ record
{ to = λ x-y⊆z u →
u ∈ x ↝⟨ (λ u∈x →
case member? _≟_ u y of
P.[ Trunc.∣inj₁∣ , Trunc.∣inj₂∣ ∘ (u∈x ,_) ]) ⟩
u ∈ y ∥⊎∥ (u ∈ x × u ∉ y) ↔⟨ F.id Trunc.∥⊎∥-cong inverse ∈minus≃ ⟩
u ∈ y ∥⊎∥ u ∈ minus _≟′_ x y ↝⟨ id Trunc.∥⊎∥-cong x-y⊆z u ⟩
u ∈ y ∥⊎∥ u ∈ z ↔⟨ inverse ∈∪≃ ⟩□
u ∈ y ∪ z □
; from = λ x⊆y∪z u →
u ∈ minus _≟′_ x y ↔⟨ ∈minus≃ ⟩
u ∈ x × u ∉ y ↝⟨ Σ-map (x⊆y∪z _) id ⟩
u ∈ y ∪ z × u ∉ y ↔⟨ ∈∪≃ ×-cong F.id ⟩
(u ∈ y ∥⊎∥ u ∈ z) × u ∉ y ↔⟨ (×-cong₁ λ u∉y → Trunc.drop-⊥-left-∥⊎∥ ∈-propositional u∉y) ⟩
u ∈ z × u ∉ y ↝⟨ proj₁ ⟩□
u ∈ z □
}
where
_≟′_ = λ x y → Dec→Dec-Erased (x ≟ y)
-- If erased truncated equality is decidable, then elements can be
-- removed from a subset.
delete :
((x y : A) → Dec-Erased ∥ x ≡ y ∥) →
A → Finite-subset-of A → Finite-subset-of A
delete _≟_ x y = minus _≟_ y (singleton x)
-- A lemma characterising delete.
∈delete≃ : ∀ _≟_ → (x ∈ delete _≟_ y z) ≃ (x ≢ y × x ∈ z)
∈delete≃ {x = x} {y = y} {z = z} _≟_ =
x ∈ delete _≟_ y z ↝⟨ ∈minus≃ {_≟_ = _≟_} ⟩
x ∈ z × x ∉ singleton y ↝⟨ F.id ×-cong →-cong₁ ext ∈singleton≃ ⟩
x ∈ z × ¬ ∥ x ≡ y ∥ ↔⟨ F.id ×-cong Trunc.¬∥∥↔¬ ⟩
x ∈ z × x ≢ y ↔⟨ ×-comm ⟩□
x ≢ y × x ∈ z □
-- A deleted element is no longer a member of the set.
∉delete : ∀ _≟_ y → x ∉ delete _≟_ x y
∉delete {x = x} _≟_ y =
x ∈ delete _≟_ x y ↔⟨ ∈delete≃ _≟_ ⟩
x ≢ x × x ∈ y ↝⟨ (_$ refl _) ∘ proj₁ ⟩□
⊥ □
-- Deletion commutes with itself (in a certain sense).
delete-comm :
∀ _≟_ z →
delete _≟_ x (delete _≟_ y z) ≡ delete _≟_ y (delete _≟_ x z)
delete-comm _≟_ z =
minus-comm {_≟_ = _≟_} z (singleton _) (singleton _)
-- Deletion commutes with union.
delete-∪ :
∀ _≟_ y →
delete _≟_ x (y ∪ z) ≡ delete _≟_ x y ∪ delete _≟_ x z
delete-∪ _≟_ y = minus-∪ {_≟_ = _≟_} y (singleton _)
-- A lemma relating delete, _⊆_ and _∷_.
delete⊆≃ :
(_≟_ : (x y : A) → Dec ∥ x ≡ y ∥) →
(delete (λ x y → Dec→Dec-Erased (x ≟ y)) x y ⊆ z) ≃ (y ⊆ x ∷ z)
delete⊆≃ _≟_ = minus⊆≃ {_≟_ = _≟_} (singleton _)
------------------------------------------------------------------------
-- Some preservation lemmas for _⊆_
-- Various operations preserve _⊆_.
∷-cong-⊆ : y ⊆ z → x ∷ y ⊆ x ∷ z
∷-cong-⊆ {y = y} {z = z} {x = x} y⊆z u =
u ∈ x ∷ y ↔⟨ ∈∷≃ ⟩
u ≡ x ∥⊎∥ u ∈ y ↝⟨ id Trunc.∥⊎∥-cong y⊆z _ ⟩
u ≡ x ∥⊎∥ u ∈ z ↔⟨ inverse ∈∷≃ ⟩□
u ∈ x ∷ z □
∪-cong-⊆ : x₁ ⊆ x₂ → y₁ ⊆ y₂ → x₁ ∪ y₁ ⊆ x₂ ∪ y₂
∪-cong-⊆ {x₁ = x₁} {x₂ = x₂} {y₁ = y₁} {y₂ = y₂} x₁⊆x₂ y₁⊆y₂ z =
z ∈ x₁ ∪ y₁ ↔⟨ ∈∪≃ ⟩
z ∈ x₁ ∥⊎∥ z ∈ y₁ ↝⟨ x₁⊆x₂ _ Trunc.∥⊎∥-cong y₁⊆y₂ _ ⟩
z ∈ x₂ ∥⊎∥ z ∈ y₂ ↔⟨ inverse ∈∪≃ ⟩□
z ∈ x₂ ∪ y₂ □
filter-cong-⊆ :
(∀ z → T (p z) → T (q z)) →
x ⊆ y → filter p x ⊆ filter q y
filter-cong-⊆ {p = p} {q = q} {x = x} {y = y} p⇒q x⊆y z =
z ∈ filter p x ↔⟨ ∈filter≃ p ⟩
T (p z) × z ∈ x ↝⟨ Σ-map (p⇒q _) (x⊆y _) ⟩
T (q z) × z ∈ y ↔⟨ inverse $ ∈filter≃ q ⟩□
z ∈ filter q y □
minus-cong-⊆ : x₁ ⊆ x₂ → y₂ ⊆ y₁ → minus _≟_ x₁ y₁ ⊆ minus _≟_ x₂ y₂
minus-cong-⊆ {x₁ = x₁} {x₂ = x₂} {y₂ = y₂} {y₁ = y₁} {_≟_ = _≟_}
x₁⊆x₂ y₂⊆y₁ z =
z ∈ minus _≟_ x₁ y₁ ↔⟨ ∈minus≃ ⟩
z ∈ x₁ × z ∉ y₁ ↝⟨ Σ-map (x₁⊆x₂ _) (_∘ y₂⊆y₁ _) ⟩
z ∈ x₂ × z ∉ y₂ ↔⟨ inverse ∈minus≃ ⟩□
z ∈ minus _≟_ x₂ y₂ □
delete-cong-⊆ : ∀ _≟_ → y ⊆ z → delete _≟_ x y ⊆ delete _≟_ x z
delete-cong-⊆ _≟_ y⊆z =
minus-cong-⊆ {_≟_ = _≟_} y⊆z (⊆-refl {x = singleton _})
------------------------------------------------------------------------
-- Size
private
-- This definition is used to define ∣_∣≡ and ∣∣≡-propositional
-- below.
--
-- This definition is not taken from "Finite Sets in Homotopy Type
-- Theory", but it is based on the size function in that paper.
Size : {A : Type a} → Finite-subset-of A → ℕ → Proposition a
Size {a = a} {A = A} = rec r
where
mutual
-- The size of x ∷ y is equal to the size of y if x is a member
-- of y, and otherwise it is equal to the successor of the size
-- of y.
Cons′ :
A → Finite-subset-of A →
(ℕ → Proposition a) → (ℕ → Type a)
Cons′ x y ∣y∣≡ n =
x ∈ y × proj₁ (∣y∣≡ n)
⊎
Cons″ x y ∣y∣≡ n
Cons″ :
A → Finite-subset-of A →
(ℕ → Proposition a) → (ℕ → Type a)
Cons″ x y ∣y∣≡ zero = ⊥
Cons″ x y ∣y∣≡ (suc n) = x ∉ y × proj₁ (∣y∣≡ n)
Cons′-propositional :
∀ Hyp n → Is-proposition (Cons′ x y Hyp n)
Cons′-propositional Hyp zero =
⊎-closure-propositional
(λ _ ())
(×-closure 1 ∈-propositional (proj₂ (Hyp 0)))
⊥-propositional
Cons′-propositional Hyp (suc n) =
⊎-closure-propositional
(λ (x∈y , _) (x∉y , _) → x∉y x∈y)
(×-closure 1 ∈-propositional (proj₂ (Hyp (suc n))))
(×-closure 1 (¬-propositional ext) (proj₂ (Hyp n)))
Cons :
A → Finite-subset-of A →
(ℕ → Proposition a) → (ℕ → Proposition a)
Cons x y Hyp n =
Cons′ x y Hyp n
, Cons′-propositional _ _
drop-lemma :
Cons′ x (x ∷ y) (Cons x y H) n ≃ Cons′ x y H n
drop-lemma {x = x} {y = y} {H = H} {n = n} =
Cons′ x (x ∷ y) (Cons x y H) n ↔⟨⟩
x ∈ x ∷ y × Cons′ x y H n ⊎ C n ↔⟨ drop-⊥-right (C↔⊥ n) ⟩
x ∈ x ∷ y × Cons′ x y H n ↔⟨ drop-⊤-left-× (λ _ → x∈x∷y↔⊤) ⟩
Cons′ x y H n □
where
C = Cons″ x (x ∷ y) (Cons x y H)
x∈x∷y↔⊤ : x ∈ x ∷ y ↔ ⊤
x∈x∷y↔⊤ =
x ∈ x ∷ y ↔⟨ ∈∷≃ ⟩
x ≡ x ∥⊎∥ x ∈ y ↝⟨ Trunc.inhabited⇒∥∥↔⊤ ∣ inj₁ (refl _) ∣ ⟩□
⊤ □
C↔⊥ : ∀ n → C n ↔ ⊥
C↔⊥ zero = ⊥↔⊥
C↔⊥ (suc n) =
x ∉ x ∷ y × Cons′ x y H n ↝⟨ →-cong ext x∈x∷y↔⊤ F.id ×-cong F.id ⟩
¬ ⊤ × Cons′ x y H n ↝⟨ inverse (Bijection.⊥↔uninhabited (_$ _)) ×-cong F.id ⟩
⊥₀ × Cons′ x y H n ↝⟨ ×-left-zero ⟩□
⊥ □
swap-lemma′ :
∀ n →
x ∈ y ∷ z × Cons′ y z H n ⊎ Cons″ x (y ∷ z) (Cons y z H) n →
y ∈ x ∷ z × Cons′ x z H n ⊎ Cons″ y (x ∷ z) (Cons x z H) n
swap-lemma′ {x = x} {y = y} {z = z} {H = H} = λ where
n (inj₁ (x∈y∷z , inj₁ (y∈z , p))) →
inj₁ ( ∈→∈∷ y∈z
, inj₁
( ( $⟨ x∈y∷z ⟩
x ∈ y ∷ z ↔⟨ ∈∷≃ ⟩
x ≡ y ∥⊎∥ x ∈ z ↝⟨ Trunc.∥∥-map P.[ (flip (subst (_∈ z)) y∈z ∘ sym) , id ] ⟩
∥ x ∈ z ∥ ↔⟨ Trunc.∥∥↔ ∈-propositional ⟩□
x ∈ z □)
, p
)
)
(suc n) (inj₁ (x∈y∷z , inj₂ (y∉z , p))) →
Trunc.rec (Cons′-propositional (Cons x z H) _)
P.[ (λ x≡y →
inj₁ ( ≡→∈∷ (sym x≡y)
, inj₂ ( (x ∈ z ↝⟨ subst (_∈ z) x≡y ⟩
y ∈ z ↝⟨ y∉z ⟩□
⊥ □)
, p
)
))
, (λ x∈z →
inj₂ ( (y ∈ x ∷ z ↔⟨ ∈∷≃ ⟩
y ≡ x ∥⊎∥ y ∈ z ↝⟨ Trunc.∥∥-map P.[ flip (subst (_∈ z)) x∈z ∘ sym , id ] ⟩
∥ y ∈ z ∥ ↝⟨ Trunc.∥∥-map y∉z ⟩
∥ ⊥ ∥ ↔⟨ Trunc.∥∥↔ ⊥-propositional ⟩□
⊥ □)
, inj₁ (x∈z , p)
))
]
(_≃_.to ∈∷≃ x∈y∷z)
(suc n) (inj₂ (x∉y∷z , inj₁ (y∈z , p))) →
inj₁ ( ∈→∈∷ y∈z
, inj₂ ( (x ∈ z ↝⟨ ∈→∈∷ ⟩
x ∈ y ∷ z ↝⟨ x∉y∷z ⟩□
⊥ □)
, p
)
)
(suc (suc n)) (inj₂ (x∉y∷z , inj₂ (y∉z , p))) →
inj₂ ( (y ∈ x ∷ z ↔⟨ ∈∷≃ ⟩
y ≡ x ∥⊎∥ y ∈ z ↝⟨ ≡→∈∷ ∘ sym Trunc.∥⊎∥-cong id ⟩
x ∈ y ∷ z ∥⊎∥ y ∈ z ↝⟨ Trunc.∥∥-map P.[ x∉y∷z , y∉z ] ⟩
∥ ⊥ ∥ ↔⟨ Trunc.∥∥↔ ⊥-propositional ⟩□
⊥ □)
, inj₂ ( (x ∈ z ↝⟨ ∈→∈∷ ⟩
x ∈ y ∷ z ↝⟨ x∉y∷z ⟩□
⊥ □)
, p
)
)
swap-lemma :
Cons′ x (y ∷ z) (Cons y z H) n ≃
Cons′ y (x ∷ z) (Cons x z H) n
swap-lemma {x = x} {y = y} {z = z} {H = H} {n = n} =
_↠_.from
(Eq.≃↠⇔
(Cons′-propositional _ _)
(Cons′-propositional _ _))
(record { to = swap-lemma′ _; from = swap-lemma′ _ })
r : Rec A (ℕ → Proposition a)
r .[]ʳ n = ↑ _ (n ≡ 0) , ↑-closure 1 ℕ-set
r .∷ʳ = Cons
r .dropʳ x y Hyp = ⟨ext⟩ λ _ →
_↔_.to (ignore-propositional-component
(H-level-propositional ext 1)) $
Univ.≃⇒≡ univ drop-lemma
r .swapʳ x y z Hyp = ⟨ext⟩ λ _ →
_↔_.to (ignore-propositional-component
(H-level-propositional ext 1)) $
Univ.≃⇒≡ univ swap-lemma
r .is-setʳ =
Π-closure ext 2 λ _ →
Univ.∃-H-level-H-level-1+ ext univ 1
-- Size.
infix 4 ∣_∣≡_
∣_∣≡_ : {A : Type a} → Finite-subset-of A → ℕ → Type a
∣ x ∣≡ n = proj₁ (Size x n)
-- The size predicate is propositional.
∣∣≡-propositional :
(x : Finite-subset-of A) → Is-proposition (∣ x ∣≡ n)
∣∣≡-propositional x = proj₂ (Size x _)
-- Unit tests documenting the computational behaviour of ∣_∣≡_.
_ : (∣ [] {A = A} ∣≡ n) ≡ ↑ _ (n ≡ 0)
_ = refl _
_ : ∀ {A : Type a} {x : A} {y} →
(∣ x ∷ y ∣≡ zero) ≡ (x ∈ y × ∣ y ∣≡ zero ⊎ ⊥)
_ = refl _
_ : (∣ x ∷ y ∣≡ suc n) ≡ (x ∈ y × ∣ y ∣≡ suc n ⊎ x ∉ y × ∣ y ∣≡ n)
_ = refl _
-- The size predicate is functional.
∣∣≡-functional :
(x : Finite-subset-of A) → ∣ x ∣≡ m → ∣ x ∣≡ n → m ≡ n
∣∣≡-functional x = elim-prop e x _ _
where
e : Elim-prop (λ x → ∀ m n → ∣ x ∣≡ m → ∣ x ∣≡ n → m ≡ n)
e .[]ʳ m n (lift m≡0) (lift n≡0) =
m ≡⟨ m≡0 ⟩
0 ≡⟨ sym n≡0 ⟩∎
n ∎
e .∷ʳ {y = y} x hyp = λ where
m n (inj₁ (x∈y , ∣y∣≡m)) (inj₁ (x∈y′ , ∣y∣≡n)) →
hyp m n ∣y∣≡m ∣y∣≡n
(suc m) (suc n) (inj₂ (x∉y , ∣y∣≡m)) (inj₂ (x∉y′ , ∣y∣≡n)) →
cong suc (hyp m n ∣y∣≡m ∣y∣≡n)
_ (suc _) (inj₁ (x∈y , _)) (inj₂ (x∉y , _)) → ⊥-elim (x∉y x∈y)
(suc _) _ (inj₂ (x∉y , _)) (inj₁ (x∈y , _)) → ⊥-elim (x∉y x∈y)
e .is-propositionʳ _ =
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
ℕ-set
-- If truncated equality is decidable, then one can compute the size
-- of a finite subset.
size :
((x y : A) → Dec ∥ x ≡ y ∥) →
(x : Finite-subset-of A) → ∃ λ n → ∣ x ∣≡ n
size equal? = elim-prop e
where
e : Elim-prop _
e .[]ʳ = 0 , lift (refl _)
e .∷ʳ {y = y} x (n , ∣y∣≡n) =
case member? equal? x y of λ x∈?y →
if x∈?y then n else suc n
, lemma ∣y∣≡n x∈?y
where
lemma :
∣ y ∣≡ n →
(x∈?y : Dec (x ∈ y)) →
∣ x ∷ y ∣≡ if x∈?y then n else suc n
lemma ∣y∣≡n (yes x∈y) = inj₁ (x∈y , ∣y∣≡n)
lemma ∣y∣≡n (no x∉y) = inj₂ (x∉y , ∣y∣≡n)
e .is-propositionʳ x (m , ∣x∣≡m) (n , ∣x∣≡n) =
Σ-≡,≡→≡ (m ≡⟨ ∣∣≡-functional x ∣x∣≡m ∣x∣≡n ⟩∎
n ∎)
(∣∣≡-propositional x _ _)
-- A variant of size that uses Erased.
sizeᴱ :
((x y : A) → Dec-Erased ∥ x ≡ y ∥) →
(x : Finite-subset-of A) → ∃ λ n → Erased (∣ x ∣≡ n)
sizeᴱ equal? = elim-prop e
where
e : Elim-prop _
e .[]ʳ = 0 , [ lift (refl _) ]
e .∷ʳ {y = y} x (n , [ ∣y∣≡n ]) =
case member?ᴱ equal? x y of λ x∈?y →
if x∈?y then n else suc n
, [ lemma ∣y∣≡n x∈?y ]
where
@0 lemma :
∣ y ∣≡ n →
(x∈?y : Dec-Erased (x ∈ y)) →
∣ x ∷ y ∣≡ if x∈?y then n else suc n
lemma ∣y∣≡n (yes [ x∈y ]) = inj₁ (x∈y , ∣y∣≡n)
lemma ∣y∣≡n (no [ x∉y ]) = inj₂ (x∉y , ∣y∣≡n)
e .is-propositionʳ x (m , [ ∣x∣≡m ]) (n , [ ∣x∣≡n ]) =
Σ-≡,≡→≡ (m ≡⟨ EC.Very-stable→Stable 1
(EC.Decidable-equality→Very-stable-≡ Nat._≟_)
_ _
[ ∣∣≡-functional x ∣x∣≡m ∣x∣≡n ] ⟩∎
n ∎)
(EC.H-level-Erased 1 (∣∣≡-propositional x) _ _)
------------------------------------------------------------------------
-- Finite types
-- A type is finite if there is some finite subset of the type for
-- which every element of the type is a member of the subset.
is-finite : Type a → Type a
is-finite A = ∃ λ (s : Finite-subset-of A) → ∀ x → x ∈ s
-- The is-finite predicate is propositional.
is-finite-propositional : Is-proposition (is-finite A)
is-finite-propositional (x , p) (y , q) =
$⟨ (λ z → record { to = λ _ → q z; from = λ _ → p z }) ⟩
(∀ z → z ∈ x ⇔ z ∈ y) ↔⟨ inverse extensionality ⟩
x ≡ y ↝⟨ ignore-propositional-component (Π-closure ext 1 (λ _ → ∈-propositional)) ⟩□
(x , p) ≡ (y , q) □
------------------------------------------------------------------------
-- Lists can be converted to finite subsets
-- Converts lists to finite subsets.
from-List : List A → Finite-subset-of A
from-List = L.foldr _∷_ []
-- Membership in the resulting set is equivalent to truncated
-- membership in the list.
∥∈∥≃∈-from-List : ∥ x BE.∈ ys ∥ ≃ (x ∈ from-List ys)
∥∈∥≃∈-from-List {x = x} {ys = ys} = _↠_.from
(Eq.≃↠⇔
Trunc.truncation-is-proposition
∈-propositional)
(record { to = to _; from = from _ })
where
to : ∀ ys → ∥ x BE.∈ ys ∥ → x ∈ from-List ys
to [] = Trunc.rec ∈-propositional (λ ())
to (y ∷ ys) = Trunc.rec ∈-propositional
P.[ ≡→∈∷ , ∈→∈∷ ∘ to ys ∘ ∣_∣ ]
from : ∀ ys → x ∈ from-List ys → ∥ x BE.∈ ys ∥
from [] ()
from (y ∷ ys) =
Trunc.rec
Trunc.truncation-is-proposition
P.[ ∣_∣ ∘ inj₁ , Trunc.∥∥-map inj₂ ∘ from ys ] ∘
_≃_.to ∈∷≃
------------------------------------------------------------------------
-- Some definitions related to the definitions in Bag-equivalence
-- Finite subsets can be expressed as lists quotiented by set
-- equivalence.
≃List/∼ : Finite-subset-of A ≃ List A / _∼[ set ]_
≃List/∼ = from-bijection (record
{ surjection = record
{ logical-equivalence = record
{ to = to
; from = from
}
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
})
where
cons : A → List A / _∼[ set ]_ → List A / _∼[ set ]_
cons x = (x ∷_) Q./-map λ _ _ → refl _ BE.∷-cong_
to : Finite-subset-of A → List A / _∼[ set ]_
to = rec r
where
r : Rec _ _
r .[]ʳ = Q.[ [] ]
r .∷ʳ x _ y = cons x y
r .is-setʳ = Q./-is-set
r .dropʳ x _ = Q.elim-prop λ where
.Q.[]ʳ xs → Q.[]-respects-relation λ z →
z BE.∈ x ∷ x ∷ xs ↝⟨ record { to = P.[ inj₁ , id ]; from = inj₂ } ⟩□
z BE.∈ x ∷ xs □
.Q.is-propositionʳ _ → Q./-is-set
r .swapʳ x y _ = Q.elim-prop λ where
.Q.[]ʳ xs → Q.[]-respects-relation λ z →
z BE.∈ x ∷ y ∷ xs ↔⟨ BE.swap-first-two z ⟩□
z BE.∈ y ∷ x ∷ xs □
.Q.is-propositionʳ _ → Q./-is-set
from : List A / _∼[ set ]_ → Finite-subset-of A
from {A = A} = Q.rec λ where
.Q.[]ʳ → from-List
.Q.[]-respects-relationʳ {x = xs} {y = ys} xs∼ys →
_≃_.from extensionality λ z →
z ∈ from-List xs ↔⟨ inverse ∥∈∥≃∈-from-List ⟩
∥ z BE.∈ xs ∥ ↔⟨ Trunc.∥∥-cong-⇔ {k = bijection} (xs∼ys z) ⟩
∥ z BE.∈ ys ∥ ↔⟨ ∥∈∥≃∈-from-List ⟩□
z ∈ from-List ys □
.Q.is-setʳ → is-set
to∘from : ∀ x → to (from x) ≡ x
to∘from = Q.elim-prop λ where
.Q.[]ʳ → lemma
.Q.is-propositionʳ _ → Q./-is-set
where
lemma : ∀ xs → to (from-List xs) ≡ Q.[ xs ]
lemma [] = refl _
lemma (x ∷ xs) =
to (from-List (x ∷ xs)) ≡⟨⟩
((x ∷_) Q./-map _) (to (from-List xs)) ≡⟨ cong ((x ∷_) Q./-map _) (lemma xs) ⟩
((x ∷_) Q./-map λ _ _ → refl _ BE.∷-cong_) Q.[ xs ] ≡⟨⟩
Q.[ x ∷ xs ] ∎
from∘to : ∀ x → from (to x) ≡ x
from∘to = elim-prop e
where
e : Elim-prop _
e .[]ʳ = refl _
e .∷ʳ {y = y} x hyp =
from (to (x ∷ y)) ≡⟨⟩
from (cons x (to y)) ≡⟨ Q.elim-prop
{P = λ y → from (cons x y) ≡ x ∷ from y}
(λ where
.Q.[]ʳ _ → refl _
.Q.is-propositionʳ _ → is-set)
(to y) ⟩
x ∷ from (to y) ≡⟨ cong (x ∷_) hyp ⟩∎
x ∷ y ∎
e .is-propositionʳ _ = is-set
-- A truncated variant of the proof-relevant membership relation from
-- Bag-equivalence can be expressed in terms of _∈_.
∥∈∥≃∈ : ∥ x BE.∈ ys ∥ ≃ (x ∈ _≃_.from ≃List/∼ Q.[ ys ])
∥∈∥≃∈ = ∥∈∥≃∈-from-List
------------------------------------------------------------------------
-- Fresh numbers
-- One can always find a natural number that is distinct from those in
-- a given finite set of natural numbers.
fresh :
(ns : Finite-subset-of ℕ) →
∃ λ (n : ℕ) → n ∉ ns
fresh ns =
Σ-map id
(λ {m} →
Erased (∀ n → n ∈ ns → n < m) ↝⟨ EC.map (_$ m) ⟩
Erased (m ∈ ns → m < m) ↝⟨ EC.map (∀-cong _ λ _ → Nat.+≮ 0) ⟩
Erased (m ∉ ns) ↝⟨ EC.Stable-¬ ⟩□
m ∉ ns □)
(elim e ns)
where
OK : @0 Finite-subset-of ℕ → @0 ℕ → Type
OK ms m = Erased (∀ n → n ∈ ms → n < m)
prop : Is-proposition (OK ms m)
prop =
EC.H-level-Erased 1 (
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
≤-propositional)
∷-max-suc :
∀ {ms n m} →
OK ms n →
OK (m ∷ ms) (Nat.max (suc m) n)
∷-max-suc {ms = ms} {n = n} {m = m} [ ub ] =
[ (λ o →
o ∈ m ∷ ms ↔⟨ ∈∷≃ ⟩
o ≡ m ∥⊎∥ o ∈ ms ↝⟨ Nat.≤-refl′ ∘ cong suc ∘ id Trunc.∥⊎∥-cong ub o ⟩
o Nat.< suc m ∥⊎∥ o Nat.< n ↝⟨ Trunc.rec ≤-propositional
P.[ flip Nat.≤-trans (Nat.ˡ≤max _ n)
, flip Nat.≤-trans (Nat.ʳ≤max (suc m) _)
] ⟩□
o Nat.< Nat.max (suc m) n □)
]
e : Elim (λ ms → ∃ λ m → OK ms m)
e .[]ʳ =
0 , [ (λ _ ()) ]
e .∷ʳ m (n , ub) =
Nat.max (suc m) n , ∷-max-suc ub
e .dropʳ {y = ns} m (n , ub) =
_↔_.to (ignore-propositional-component prop)
(proj₁ (subst (λ ms → ∃ λ m → OK ms m)
(drop {x = m} {y = ns})
( Nat.max (suc m) (Nat.max (suc m) n)
, ∷-max-suc (∷-max-suc ub)
)) ≡⟨ cong proj₁ $
push-subst-pair-× {y≡z = drop {x = m} {y = ns}} _
(λ (ms , m) → OK ms m)
{p = _ , ∷-max-suc (∷-max-suc ub)} ⟩
Nat.max (suc m) (Nat.max (suc m) n) ≡⟨ Nat.max-assoc (suc m) {n = suc m} {o = n} ⟩
Nat.max (Nat.max (suc m) (suc m)) n ≡⟨ cong (λ m → Nat.max m n) $ Nat.max-idempotent (suc m) ⟩∎
Nat.max (suc m) n ∎)
e .swapʳ {z = ns} m n (o , ub) =
_↔_.to (ignore-propositional-component prop)
(proj₁ (subst (λ xs → ∃ λ m → OK xs m)
(swap {x = m} {y = n} {z = ns})
( Nat.max (suc m) (Nat.max (suc n) o)
, ∷-max-suc (∷-max-suc ub)
)) ≡⟨ cong proj₁ $
push-subst-pair-× {y≡z = swap {x = m} {y = n} {z = ns}} _
(λ (ms , m) → OK ms m)
{p = _ , ∷-max-suc (∷-max-suc ub)} ⟩
Nat.max (suc m) (Nat.max (suc n) o) ≡⟨ Nat.max-assoc (suc m) {n = suc n} {o = o} ⟩
Nat.max (Nat.max (suc m) (suc n)) o ≡⟨ cong (λ m → Nat.max m o) $ Nat.max-comm (suc m) (suc n) ⟩
Nat.max (Nat.max (suc n) (suc m)) o ≡⟨ sym $ Nat.max-assoc (suc n) {n = suc m} {o = o} ⟩∎
Nat.max (suc n) (Nat.max (suc m) o) ∎)
e .is-setʳ _ =
Σ-closure 2 ℕ-set λ _ →
mono₁ 1 prop
| {
"alphanum_fraction": 0.3867070392,
"avg_line_length": 34.387628866,
"ext": "agda",
"hexsha": "d97c859cff2375e95e6363d0961d23091439e0d2",
"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/Finite-subset/Listed.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/Finite-subset/Listed.agda",
"max_line_length": 145,
"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/Finite-subset/Listed.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": 28349,
"size": 66712
} |
open import Common.Level
open import Common.Reflection
open import Common.Equality
open import Common.Prelude
postulate
f : ∀ a → Set a
pattern expectedType =
pi (vArg (def (quote Level) []))
(abs "a" (sort (set (var 0 []))))
ok : ⊤
ok = _
notOk : String
notOk = "not ok"
macro
isExpected : QName → Tactic
isExpected x hole =
bindTC (getType x) λ
{ expectedType → give (quoteTerm ok) hole
; t → give (quoteTerm notOk) hole }
thm : ⊤
thm = isExpected f
| {
"alphanum_fraction": 0.6325301205,
"avg_line_length": 17.1724137931,
"ext": "agda",
"hexsha": "1e31af15ae24341e863925dcba5fd65a287a2a2c",
"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/Issue1221.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/Issue1221.agda",
"max_line_length": 50,
"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/Issue1221.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": 155,
"size": 498
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Sets.EquivalenceRelations
open import Functions
open import Lists.Definition
open import Lists.Fold.Fold
open import Lists.Concat
open import Lists.Length
open import Setoids.Setoids
open import Maybe
open import Numbers.Naturals.Semiring
module Lists.Permutations {a b : _} {A : Set a} (S : Setoid {a} {b} A) (decidable : (x y : A) → (Setoid._∼_ S x y) || ((Setoid._∼_ S x y) → False)) where
open Setoid S
open Equivalence eq
indexOf : (a : A) → (l : List A) → Maybe ℕ
indexOf a [] = no
indexOf a (x :: l) with decidable a x
... | inl eq = yes 0
... | inr noneq = mapMaybe succ (indexOf a l)
eltAt : (n : ℕ) → (l : List A) → Maybe A
eltAt n [] = no
eltAt zero (x :: l) = yes x
eltAt (succ n) (x :: l) = eltAt n l
indexOfIsIndexOf : (a : A) → (l : List A) → {n : ℕ} → indexOf a l ≡ yes n → Sg A (λ b → (eltAt n l ≡ yes b) && (b ∼ a))
indexOfIsIndexOf a (x :: l) {n} ind with decidable a x
indexOfIsIndexOf a (x :: l) {.0} refl | inl a=x = x , (refl ,, symmetric a=x)
indexOfIsIndexOf a (x :: l) {zero} ind | inr a!=x with indexOf a l
indexOfIsIndexOf a (x :: l) {zero} () | inr a!=x | no
indexOfIsIndexOf a (x :: l) {zero} () | inr a!=x | yes _
indexOfIsIndexOf a (x :: l) {succ n} ind | inr a!=x with mapMaybePreservesYes ind
... | m , (pr ,, z=n) = indexOfIsIndexOf a l (transitivity pr (applyEquality yes (succInjective z=n)))
Permutation : (List A) → (List A) → Set
Permutation [] [] = True
Permutation [] (x :: l2) = False
Permutation (x :: l1) [] = False
Permutation (a :: as) (b :: bs) with decidable a b
Permutation (a :: as) (b :: bs) | inl a=b = Permutation as bs
Permutation (a :: as) (b :: bs) | inr a!=b = {!!}
| {
"alphanum_fraction": 0.6271777003,
"avg_line_length": 37.4347826087,
"ext": "agda",
"hexsha": "e6f9dfef5957bae43ba6cc725c5330a85e2786e8",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Lists/Permutations.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Lists/Permutations.agda",
"max_line_length": 153,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Lists/Permutations.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 609,
"size": 1722
} |
module MixfixBinders where
postulate
M : Set → Set
return : ∀ {A} → A → M A
bind : ∀ {A B} → M A → (A → M B) → M B
infixr 40 bind
syntax bind m (λ x → m′) = x ← m , m′
postulate
X : Set
m₁ m₂ m₃ : M X
f : X → X → X
foo : M X
foo = x₁ ← m₁ ,
x₂ ← m₂ ,
x₃ ← m₃ ,
return (f x₁ (f x₂ x₃))
infixr 10 Σ _,_
syntax Σ A (λ x → B) = Σ x ∈ A , B
data Σ (A : Set)(B : A → Set) : Set where
_,_ : (x : A) → B x → Σ x ∈ A , B x
infix 50 _≤_
postulate
_≤_ : X → X → Set
x₁ x₂ : X
le : x₁ ≤ x₂
p : Σ x ∈ X , Σ y ∈ X , x ≤ y
p = x₁ , x₂ , le | {
"alphanum_fraction": 0.4548611111,
"avg_line_length": 16.9411764706,
"ext": "agda",
"hexsha": "7a25ea41008ade3fcc6129f39387faf544749099",
"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/MixfixBinders.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/MixfixBinders.agda",
"max_line_length": 42,
"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/MixfixBinders.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": 286,
"size": 576
} |
record _ : Set where
| {
"alphanum_fraction": 0.7142857143,
"avg_line_length": 10.5,
"ext": "agda",
"hexsha": "ec270c53db3d051cd86b078ffc9256c36b9797ef",
"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/Issue1465-record.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/Issue1465-record.agda",
"max_line_length": 20,
"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/Issue1465-record.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": 6,
"size": 21
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Functor.Profunctor where
open import Level
open import Categories.Category
open import Categories.Category.Instance.Setoids
open import Categories.Functor.Bifunctor
open import Categories.Functor.Hom
Profunctor : ∀ {o ℓ e} {o′ ℓ′ e′} → Category o ℓ e → Category o′ ℓ′ e′ → Set _
Profunctor {ℓ = ℓ} {e} {ℓ′ = ℓ′} {e′} C D = Bifunctor (Category.op D) C (Setoids (ℓ ⊔ ℓ′) (e ⊔ e′))
id : ∀ {o ℓ e} → {C : Category o ℓ e} → Profunctor C C
id {C = C} = Hom[ C ][-,-]
| {
"alphanum_fraction": 0.6512524085,
"avg_line_length": 30.5294117647,
"ext": "agda",
"hexsha": "1d731f744940e82a73db64c7f8ba9f65216c96d4",
"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": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/Functor/Profunctor.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"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": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/Functor/Profunctor.agda",
"max_line_length": 99,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/Functor/Profunctor.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": 191,
"size": 519
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Showing booleans
------------------------------------------------------------------------
module Data.Bool.Show where
open import Data.Bool
open import Data.String hiding (show)
show : Bool → String
show true = "true"
show false = "false"
| {
"alphanum_fraction": 0.4216524217,
"avg_line_length": 23.4,
"ext": "agda",
"hexsha": "19961a68045d0d6b7bb88d939ce85957d0e3c4fc",
"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": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/Bool/Show.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/Bool/Show.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/Bool/Show.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 55,
"size": 351
} |
{-# OPTIONS --universe-polymorphism #-}
module Categories.Discrete where
open import Level
open import Data.Unit using (⊤)
open import Function using (flip)
open import Categories.Category
open import Categories.Support.PropositionalEquality
Discrete : ∀ {o} (A : Set o) → Category o o zero
Discrete A = record
{ Obj = A
; _⇒_ = _≣_
; _≡_ = λ _ _ → ⊤
; _∘_ = flip ≣-trans
; id = ≣-refl
; assoc = _
; identityˡ = _
; identityʳ = _
; equiv = _
; ∘-resp-≡ = _
} | {
"alphanum_fraction": 0.6342975207,
"avg_line_length": 21.0434782609,
"ext": "agda",
"hexsha": "bc9eab100a3ffb5c2fbd0d47b178c183441836fe",
"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/Discrete.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/Discrete.agda",
"max_line_length": 52,
"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/Discrete.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": 167,
"size": 484
} |
open import Agda.Builtin.Reflection
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
open import Agda.Builtin.List
open import Agda.Builtin.Equality
magic : Nat
magic = 666
macro
by-magic : Term → TC ⊤
by-magic hole = unify hole (def (quote magic) [])
meta-magic : Term → TC ⊤
meta-magic hole = unify hole (def (quote by-magic) [])
test : Nat
test = meta-magic
check : test ≡ 666
check = refl
| {
"alphanum_fraction": 0.7050359712,
"avg_line_length": 18.1304347826,
"ext": "agda",
"hexsha": "6bb3fb5bb92de033f7f55e926ded11100ae0e1b7",
"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/Issue2130.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/Issue2130.agda",
"max_line_length": 56,
"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/Issue2130.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": 130,
"size": 417
} |
open import Agda.Builtin.Nat renaming (Nat to ℕ)
open import Agda.Builtin.Equality
data Vec (A : Set) : ℕ → Set where
[] : Vec A zero
_∷_ : ∀{n} (x : A) (xs : Vec A n) → Vec A (suc n)
data All₂ {A : Set} {B : Set} (R : A → B → Set) : ∀ {k} → Vec A k → Vec B k → Set where
[] : All₂ R [] []
_∷_ : ∀ {k x y} {xs : Vec A k} {ys : Vec B k}
(r : R x y) (rs : All₂ R xs ys) → All₂ R (x ∷ xs) (y ∷ ys)
Det : ∀ {A : Set} {B : Set} (R : A → B → Set) → Set
Det R = ∀{a b c} → R a b → R a c → b ≡ c
detAll₂ : ∀ {A : Set} {B : Set} (R : A → B → Set) (h : Det R) → Det (All₂ R)
detAll₂ R h rab rac = {!rab!}
| {
"alphanum_fraction": 0.4673046252,
"avg_line_length": 34.8333333333,
"ext": "agda",
"hexsha": "039b02d025e27497dd30943a1165c94683df3075",
"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/Issue2621.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/Issue2621.agda",
"max_line_length": 87,
"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/Issue2621.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": 284,
"size": 627
} |
-- FNF, 2019-02-06
-- Test the difference between --ignore-interfaces and --ignore-all-interfaces
-- See Issue641-all-interfaces.flags and compare with Issue641.flags
module Issue641-all-interfaces where
-- Provoke a scope checking error.
open NoSuchModule
-- Expected output is some debug messages about importing, plus the error,
-- but in particular re-typechecking Agda.Primitive
| {
"alphanum_fraction": 0.7835051546,
"avg_line_length": 29.8461538462,
"ext": "agda",
"hexsha": "b9cd7f1195f61b2624367460f760f7ac7e2b3fdf",
"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/Issue641-all-interfaces.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/Issue641-all-interfaces.agda",
"max_line_length": 78,
"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/Issue641-all-interfaces.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": 89,
"size": 388
} |
-- Andreas & James, 2016-04-18 pre-AIM XXIII
-- order of clauses should not matter here!
{-# OPTIONS --exact-split #-}
open import Common.Equality
open import Common.Prelude
open import Common.Product
thing : Bool → Bool × Bool
proj₁ (thing true) = false
proj₁ (thing false) = true
proj₂ (thing b) = b
test : ∀ b → proj₂ (thing b) ≡ b
test b = refl
| {
"alphanum_fraction": 0.6912181303,
"avg_line_length": 20.7647058824,
"ext": "agda",
"hexsha": "43196c0d0b30e52027468c53aebbed3889274f54",
"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/Issue1834b.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/Issue1834b.agda",
"max_line_length": 44,
"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/Issue1834b.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": 105,
"size": 353
} |
open import FRP.JS.RSet using ( ⟦_⟧ )
open import FRP.JS.Behaviour using ( Beh )
open import FRP.JS.DOM using ( DOM )
module FRP.JS.Main where
postulate
Main : Set
reactimate : ⟦ Beh DOM ⟧ → Main
{-# COMPILED_JS reactimate require("agda.frp").reactimate #-}
| {
"alphanum_fraction": 0.6943396226,
"avg_line_length": 22.0833333333,
"ext": "agda",
"hexsha": "5e722121e2272374451f9aa4a4fb5a0076e9213c",
"lang": "Agda",
"max_forks_count": 7,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-11-07T21:50:58.000Z",
"max_forks_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_forks_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_forks_repo_name": "agda/agda-frp-js",
"max_forks_repo_path": "src/agda/FRP/JS/Main.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_issues_repo_name": "agda/agda-frp-js",
"max_issues_repo_path": "src/agda/FRP/JS/Main.agda",
"max_line_length": 61,
"max_stars_count": 63,
"max_stars_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_stars_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_stars_repo_name": "agda/agda-frp-js",
"max_stars_repo_path": "src/agda/FRP/JS/Main.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T09:46:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-20T21:47:00.000Z",
"num_tokens": 86,
"size": 265
} |
------------------------------------------------------------------------------
-- Abelian group theory properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module GroupTheory.AbelianGroup.PropertiesATP where
open import GroupTheory.AbelianGroup.Base
------------------------------------------------------------------------------
postulate xyx⁻¹≡y : ∀ a b → a · b · a ⁻¹ ≡ b
{-# ATP prove xyx⁻¹≡y #-}
postulate x⁻¹y⁻¹≡[xy]⁻¹ : ∀ a b → a ⁻¹ · b ⁻¹ ≡ (a · b) ⁻¹
{-# ATP prove x⁻¹y⁻¹≡[xy]⁻¹ #-}
| {
"alphanum_fraction": 0.3767705382,
"avg_line_length": 33.619047619,
"ext": "agda",
"hexsha": "d3cc6fdebea549d57c057e2338e6a82ecec17b6f",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/GroupTheory/AbelianGroup/PropertiesATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/GroupTheory/AbelianGroup/PropertiesATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/GroupTheory/AbelianGroup/PropertiesATP.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 169,
"size": 706
} |
{-# OPTIONS --rewriting --prop #-}
open import common
open import syntx
open import derivability
{- Here are the structural rules, as derivation rules -}
module _ (Σ : Signature) where
{-
Γ ⊢ A (x : A) ∈ Γ
--------------------
Γ ⊢ x : A
-}
-- The version of the variable rule we use is that Γ ⊢ x : A if Γ ⊢ A holds, and if A is the type
-- corresponding to x in Γ.
VarRule : (k : ℕ) → DerivationRule Σ (([] , (0 , Ty)) , Tm)
rule (VarRule k) ↑ Γ ([] , ◇ ⊢ A) =
do
(k' , A') ← get k Γ
assume (A' ≡ A)
return (◇ ⊢ var k' :> A)
ConvRule : DerivationRule Σ (([] , (0 , Tm) , (0 , Ty=)) , Tm)
rule ConvRule ↑ Γ ([] , ◇ ⊢ u :> A , ◇ ⊢ A' == B) =
do
assume (A ≡ A')
return (◇ ⊢ u :> B)
ConvEqRule : DerivationRule Σ (([] , (0 , Tm=) , (0 , Ty=)) , Tm=)
rule ConvEqRule ↑ Γ ([] , ◇ ⊢ u == v :> A , ◇ ⊢ A' == B) =
do
assume (A ≡ A')
return (◇ ⊢ u == v :> B)
TyReflRule : DerivationRule Σ (([] , (0 , Ty)) , Ty=)
rule TyReflRule ↑ Γ ([] , ◇ ⊢ A) = return (◇ ⊢ A == A)
TySymmRule : DerivationRule Σ (([] , (0 , Ty=)) , Ty=)
rule TySymmRule ↑ Γ ([] , ◇ ⊢ A == B) = return (◇ ⊢ B == A)
TyTranRule : DerivationRule Σ (([] , (0 , Ty=) , (0 , Ty=)) , Ty=)
rule TyTranRule ↑ Γ ([] , ◇ ⊢ A == B , ◇ ⊢ B' == D) = -- Can’t use C as a bound variable as it’s a tag.
do
assume (B ≡ B')
return (◇ ⊢ A == D)
TmReflRule : DerivationRule Σ (([] , (0 , Tm)) , Tm=)
rule TmReflRule ↑ Γ ([] , ◇ ⊢ u :> A) = return (◇ ⊢ u == u :> A)
TmSymmRule : DerivationRule Σ (([] , (0 , Tm=)) , Tm=)
rule TmSymmRule ↑ Γ ([] , ◇ ⊢ u == v :> A) = return (◇ ⊢ v == u :> A)
TmTranRule : DerivationRule Σ (([] , (0 , Tm=) , (0 , Tm=)) , Tm=)
rule TmTranRule ↑ Γ ([] , ◇ ⊢ u == v :> A , ◇ ⊢ v' == w :> A') =
do
assume (v ≡ v')
assume (A ≡ A')
return (◇ ⊢ u == w :> A)
{-
Small hack to make our life easier, the implicit argument [ar] of [StructuralRulesType] is
automatically inferred from the definition of [StructuralRules], but for that they need to be
mutually recursive
-}
StructuralRules : DerivabilityStructure Σ
-- See #4366
private
ar1 = _
ar2 = _
ar3 = _
ar4 = _
ar5 = _
ar6 = _
ar7 = _
ar8 = _
ar9 = _
data StructuralRulesType : {ar : JudgmentArity} → Set where
var : ℕ → StructuralRulesType {ar1}
conv : StructuralRulesType {ar2}
convEq : StructuralRulesType {ar3}
tyRefl : StructuralRulesType {ar4}
tySymm : StructuralRulesType {ar5}
tyTran : StructuralRulesType {ar6}
tmRefl : StructuralRulesType {ar7}
tmSymm : StructuralRulesType {ar8}
tmTran : StructuralRulesType {ar9}
Rules StructuralRules S ar = StructuralRulesType {ar}
Rules StructuralRules T ar = Empty
Rules StructuralRules C ar = Empty
Rules StructuralRules Eq ar = Empty
derivationRule StructuralRules {t = S} (var k) = VarRule k
derivationRule StructuralRules {t = S} conv = ConvRule
derivationRule StructuralRules {t = S} convEq = ConvEqRule
derivationRule StructuralRules {t = S} tyRefl = TyReflRule
derivationRule StructuralRules {t = S} tySymm = TySymmRule
derivationRule StructuralRules {t = S} tyTran = TyTranRule
derivationRule StructuralRules {t = S} tmRefl = TmReflRule
derivationRule StructuralRules {t = S} tmSymm = TmSymmRule
derivationRule StructuralRules {t = S} tmTran = TmTranRule
| {
"alphanum_fraction": 0.5957512315,
"avg_line_length": 29.5272727273,
"ext": "agda",
"hexsha": "b534ddc65c21f95132d04af9ce50ad68e4a97a82",
"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": "f9bfefd0a70ae5bdc3906829ee1165c731882bca",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guillaumebrunerie/general-type-theories",
"max_forks_repo_path": "structuralrules.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca",
"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/general-type-theories",
"max_issues_repo_path": "structuralrules.agda",
"max_line_length": 104,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guillaumebrunerie/general-type-theories",
"max_stars_repo_path": "structuralrules.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1207,
"size": 3248
} |
open import Agda.Builtin.Float
_ : Float
_ = 1.0xA
| {
"alphanum_fraction": 0.7115384615,
"avg_line_length": 10.4,
"ext": "agda",
"hexsha": "edc8979e65dfb3f34404fd10c3330be90302d808",
"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/Issue4132.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/Issue4132.agda",
"max_line_length": 30,
"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/Issue4132.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": 20,
"size": 52
} |
module proofs where
open import univ
open import cwf
open import Base
open import Nat
open import help
{-
lem-id∘ : {Γ Δ : Con}(σ : Γ ─→ Δ) -> id ∘ σ == σ
lem-id∘ (el < σ , pσ >) = eq \x -> ref
lem-∘id : {Γ Δ : Con}(σ : Γ ─→ Δ) -> σ ∘ id == σ
lem-∘id (el < σ , pσ >) = eq \x -> ref
lem-∘assoc : {Γ Δ Θ Ξ : Con}(σ : Θ ─→ Ξ)(δ : Δ ─→ Θ)(θ : Γ ─→ Δ) ->
(σ ∘ δ) ∘ θ == σ ∘ (δ ∘ θ)
lem-∘assoc (el < σ , pσ >) (el < δ , pδ >) (el < θ , pθ >) = eq \x -> ref
-}
lem-/∘ : {Γ Δ Θ : Con}(A : Type Γ)(σ : Δ ─→ Γ)(δ : Θ ─→ Δ) ->
A / σ ∘ δ =Ty A / σ / δ
lem-/∘ A (el < _ , _ >) (el < _ , _ >) = eqTy \x -> refS
{-
lem-//id : {Γ : Con}{A : Type Γ}{u : Elem Γ A} -> u // id =El castElem lem-/id u
lem-//id {Γ}{A}{elem (el < u , pu >)} = eqEl (eq prf)
where
prf : (x : El Γ) -> _
prf x =
chain> u x
=== _ << u (refS << x) by pu (sym (ref<< x))
=== _ << u (refS << x) by pfi _ _ _
where open module C11 = Chain _==_ (ref {_}) (trans {_})
lem-//∘ : {Γ Δ Θ : Con}{A : Type Γ}(u : Elem Γ A)(σ : Δ ─→ Γ)(δ : Θ ─→ Δ) ->
u // σ ∘ δ =El castElem (lem-/∘ A σ δ) (u // σ // δ)
lem-//∘ {Γ}{Δ}{Θ} (elem (el < u , pu >)) σ'@(el < σ , _ >) δ'@(el < δ , _ >) = eqEl (eq prf)
where
prf : (x : El Θ) -> _
prf x =
chain> u (σ (δ x))
=== _ << u (σ (δ (refS << x))) by pu (p─→ σ' (p─→ δ' (sym (ref<< x))))
=== _ << u (σ (δ (refS << x))) by pfi _ _ _
where open module C12 = Chain _==_ (ref {_}) (trans {_})
lem-wk∘σ,,u : {Γ Δ : Con}{A : Type Γ}(σ : Δ ─→ Γ)(u : Elem Δ (A / σ)) ->
wk ∘ (σ ,, u) == σ
lem-wk∘σ,,u (el < σ , pσ >) (elem (el < u , pu >)) = eq \x -> ref
lem-/wk∘σ,,u : {Γ Δ : Con}(A : Type Γ)(σ : Δ ─→ Γ)(u : Elem Δ (A / σ)) ->
A / wk / (σ ,, u) =Ty A / σ
lem-/wk∘σ,,u A (el < σ , pσ >) (elem (el < u , pu >)) = eqTy \x -> refS
lem-vz/σ,,u : {Γ Δ : Con}{A : Type Γ}(σ : Δ ─→ Γ)(u : Elem Δ (A / σ)) ->
vz // (σ ,, u) =El castElem (lem-/wk∘σ,,u A σ u) u
lem-vz/σ,,u (el < σ , pσ >) (elem (el < u , pu >)) = eqEl (eq \x -> prf x)
where
prf : (x : El _) -> u x == _ << u (refS << x)
prf x =
chain> u x
=== _ << u (refS << x) by pu (sym (ref<< x))
=== _ << u (refS << x) by pfi _ _ _
where open module C15 = Chain _==_ (ref {_}) (trans {_})
lem-σ,,u∘ : {Γ Δ Θ : Con}{A : Type Γ}
(σ : Δ ─→ Γ)(u : Elem Δ (A / σ))(δ : Θ ─→ Δ) ->
(σ ,, u) ∘ δ == (σ ∘ δ ,, castElem (lem-/∘ A σ δ) (u // δ))
lem-σ,,u∘ (el < σ , _ >) (elem (el < u , pu >)) δ'@(el < δ , _ >) =
eq \x -> eq < ref , prf x >
where
prf : (x : El _) -> u (δ x) == _ << _ << u (δ (refS << x))
prf x =
chain> u (δ x)
=== _ << u (δ (refS << x)) by pu (p─→ δ' (sym (ref<< x)))
=== _ << _ << u (δ (refS << x)) by sym (casttrans _ _ _ _)
where open module C15 = Chain _==_ (ref {_}) (trans {_})
lem-wk,,vz : {Γ : Con}{A : Type Γ} -> (wk ,, vz) == id {Γ , A}
lem-wk,,vz {Γ}{A} = eq prf
where
prf : (x : El (Γ , A)) -> _
prf (el < x , y >) = ref
-}
lem-Π/ : {Γ Δ : Con}{A : Type Γ}(B : Type (Γ , A))(σ : Δ ─→ Γ) ->
Π A B / σ =Ty Π (A / σ) (B / (σ ∘ wk ,, castElem (lem-/∘ A σ wk) vz))
lem-Π/ B (el < σ , pσ >) =
eqTy \x -> eqS < refS , (\y -> pFam B (eq < ref , prf x y >)) >
where
postulate prf : (x : El _)(y : El _) -> y == _ << _ << _ << _ << y
-- prf x y =
-- chain> y
-- === _ << _ << y by sym (castref2 _ _ y)
-- === _ << _ << _ << y by trans<< _ _ _
-- === _ << _ << _ << _ << y by trans<< _ _ _
-- where open module C16 = Chain _==_ (ref {_}) (trans {_})
{-
lem-β : {Γ : Con}{A : Type Γ}{B : Type (Γ , A)}
(v : Elem (Γ , A) B)(u : Elem Γ A) ->
(ƛ v) ∙ u =El v // [ u ]
lem-β {Γ}{A}{B} (elem (el < v , pv >)) (elem (el < u , pu >)) = eqEl (eq \x -> prf x _ _)
where
prf : (x : El Γ)(q : _ =S _)(p : _ =S _) ->
p << v (el < x , u x >) == v (el < x , q << u (refS << x) >)
prf x q p =
chain> p << v (el < x , u x >)
=== p << q0 << v (el < x , q1 << u (refS << x) >)
by p<< p (pv (eqSnd (pu (sym (ref<< x)))))
=== q2 << v (el < x , q1 << u (refS << x) >)
by sym (trans<< p q0 _)
=== q2 << q3 << v (el < x , q << u (refS << x) >)
by p<< q2 (pv (eqSnd (pfi q1 q _)))
=== v (el < x , q << u (refS << x) >)
by castref2 q2 q3 _
where
open module C17 = Chain _==_ (ref {_}) (trans {_})
q0 = _
q1 = _
q2 = _
q3 = _
-}
| {
"alphanum_fraction": 0.3854283787,
"avg_line_length": 35.2936507937,
"ext": "agda",
"hexsha": "7be982896f1d739d708d4cc0a68084b44d127133",
"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": "examples/outdated-and-incorrect/univ/proofs.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/outdated-and-incorrect/univ/proofs.agda",
"max_line_length": 92,
"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/outdated-and-incorrect/univ/proofs.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": 2017,
"size": 4447
} |
module Prelude.String where
open import Agda.Primitive
open import Prelude.Unit
open import Prelude.Char
open import Prelude.Bool
open import Prelude.Nat
open import Prelude.List
open import Prelude.Maybe
open import Prelude.Equality
open import Prelude.Equality.Unsafe
open import Prelude.Decidable
open import Prelude.Ord
open import Prelude.Function
open import Prelude.Monad
open import Prelude.Semiring
open import Agda.Builtin.String public
open import Agda.Builtin.FromString public
unpackString = primStringToList
packString = primStringFromList
unpackString-inj : ∀ {x y} → unpackString x ≡ unpackString y → x ≡ y
unpackString-inj {x} p with unpackString x
unpackString-inj refl | ._ = unsafeEqual
infixr 5 _&_
_&_ = primStringAppend
-- Eq --
instance
EqString : Eq String
_==_ {{EqString}} x y with primStringEquality x y
... | true = yes unsafeEqual
... | false = no unsafeNotEqual
-- Ord --
instance
OrdString : Ord String
OrdString = OrdBy unpackString-inj
OrdLawsString : Ord/Laws String
OrdLawsString = OrdLawsBy unpackString-inj
-- Overloaded literals --
instance
StringIsString : IsString String
IsString.Constraint StringIsString _ = ⊤
IsString.fromString StringIsString s = s
ListIsString : IsString (List Char)
IsString.Constraint ListIsString _ = ⊤
IsString.fromString ListIsString s = unpackString s
-- Monoid --
instance
open import Prelude.Monoid
SemigroupString : Semigroup String
_<>_ {{SemigroupString}} = primStringAppend
MonoidString : Monoid String
Monoid.super MonoidString = it
mempty {{MonoidString}} = ""
-- More functions --
parseNat : String → Maybe Nat
parseNat = parseNat′ ∘ unpackString
where
pDigit : Char → Maybe Nat
pDigit c =
if isDigit c then just (charToNat c - charToNat '0')
else nothing
pNat : Nat → List Char → Maybe Nat
pNat n [] = just n
pNat n (c ∷ s) = pDigit c >>= λ d → pNat (n * 10 + d) s
parseNat′ : List Char → Maybe Nat
parseNat′ [] = nothing
parseNat′ (c ∷ s) = pDigit c >>= λ d → pNat d s
onChars : (List Char → List Char) → String → String
onChars f = packString ∘ f ∘ unpackString
words : String → List String
words = map packString ∘ wordsBy isSpace ∘ unpackString
ltrim : String → String
ltrim = onChars (dropWhile isSpace)
rtrim : String → String
rtrim = onChars (reverse ∘ dropWhile isSpace ∘ reverse)
trim : String → String
trim = rtrim ∘ ltrim
strTake : Nat → String → String
strTake n = onChars (take n)
strDrop : Nat → String → String
strDrop n = onChars (drop n)
strLength : String → Nat
strLength = length ∘ unpackString
strIsPrefixOf? : String → String → Bool
strIsPrefixOf? = isPrefixOf? on unpackString
strCommonPrefix : String → String → String
strCommonPrefix s₁ s₂ = packString $ (commonPrefix! on unpackString) s₁ s₂
| {
"alphanum_fraction": 0.7197317331,
"avg_line_length": 24.0084745763,
"ext": "agda",
"hexsha": "a14c5e4f4738a772a40baac94b0d98e05e90fc62",
"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/Prelude/String.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/Prelude/String.agda",
"max_line_length": 74,
"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/Prelude/String.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": 804,
"size": 2833
} |
------------------------------------------------------------------------
-- Streams
------------------------------------------------------------------------
module Data.Stream where
open import Coinduction
open import Data.Colist using (Colist; []; _∷_)
open import Data.Vec using (Vec; []; _∷_)
open import Data.Nat using (ℕ; zero; suc)
open import Relation.Binary
------------------------------------------------------------------------
-- The type
infixr 5 _∷_
data Stream (A : Set) : Set where
_∷_ : (x : A) (xs : ∞ (Stream A)) → Stream A
------------------------------------------------------------------------
-- Some operations
head : forall {A} -> Stream A -> A
head (x ∷ xs) = x
tail : forall {A} -> Stream A -> Stream A
tail (x ∷ xs) = ♭ xs
map : ∀ {A B} → (A → B) → Stream A → Stream B
map f (x ∷ xs) = f x ∷ ♯ map f (♭ xs)
zipWith : forall {A B C} ->
(A -> B -> C) -> Stream A -> Stream B -> Stream C
zipWith _∙_ (x ∷ xs) (y ∷ ys) = (x ∙ y) ∷ ♯ zipWith _∙_ (♭ xs) (♭ ys)
take : ∀ {A} (n : ℕ) → Stream A → Vec A n
take zero xs = []
take (suc n) (x ∷ xs) = x ∷ take n (♭ xs)
drop : ∀ {A} -> ℕ -> Stream A -> Stream A
drop zero xs = xs
drop (suc n) (x ∷ xs) = drop n (♭ xs)
repeat : forall {A} -> A -> Stream A
repeat x = x ∷ ♯ repeat x
iterate : ∀ {A} → (A → A) → A → Stream A
iterate f x = x ∷ ♯ iterate f (f x)
-- Interleaves the two streams.
infixr 5 _⋎_
_⋎_ : ∀ {A} → Stream A → Stream A → Stream A
(x ∷ xs) ⋎ ys = x ∷ ♯ (ys ⋎ ♭ xs)
toColist : ∀ {A} → Stream A → Colist A
toColist (x ∷ xs) = x ∷ ♯ toColist (♭ xs)
lookup : ∀ {A} → ℕ → Stream A → A
lookup zero (x ∷ xs) = x
lookup (suc n) (x ∷ xs) = lookup n (♭ xs)
infixr 5 _++_
_++_ : ∀ {A} → Colist A → Stream A → Stream A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ ♯ (♭ xs ++ ys)
------------------------------------------------------------------------
-- Equality and other relations
-- xs ≈ ys means that xs and ys are equal.
infix 4 _≈_
data _≈_ {A} : (xs ys : Stream A) → Set where
_∷_ : ∀ x {xs ys} (xs≈ : ∞ (♭ xs ≈ ♭ ys)) → x ∷ xs ≈ x ∷ ys
-- x ∈ xs means that x is a member of xs.
infix 4 _∈_
data _∈_ {A : Set} : A → Stream A → Set where
here : ∀ {x xs} → x ∈ x ∷ xs
there : ∀ {x y xs} (x∈xs : x ∈ ♭ xs) → x ∈ y ∷ xs
-- xs ⊑ ys means that xs is a prefix of ys.
infix 4 _⊑_
data _⊑_ {A : Set} : Colist A → Stream A → Set where
[] : ∀ {ys} → [] ⊑ ys
_∷_ : ∀ x {xs ys} (p : ∞ (♭ xs ⊑ ♭ ys)) → x ∷ xs ⊑ x ∷ ys
------------------------------------------------------------------------
-- Some proofs
setoid : Set → Setoid
setoid A = record
{ carrier = Stream A
; _≈_ = _≈_ {A}
; isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
}
where
refl : Reflexive _≈_
refl {x ∷ xs} = x ∷ ♯ refl
sym : Symmetric _≈_
sym (x ∷ xs≈) = x ∷ ♯ sym (♭ xs≈)
trans : Transitive _≈_
trans (x ∷ xs≈) (.x ∷ ys≈) = x ∷ ♯ trans (♭ xs≈) (♭ ys≈)
map-cong : ∀ {A B} (f : A → B) {xs ys : Stream A} →
xs ≈ ys → map f xs ≈ map f ys
map-cong f (x ∷ xs≈) = f x ∷ ♯ map-cong f (♭ xs≈)
| {
"alphanum_fraction": 0.4231136581,
"avg_line_length": 25.5365853659,
"ext": "agda",
"hexsha": "33709622c1db5afb7469bca1b0b36e24631aa170",
"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/Stream.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/Stream.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/Stream.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": 1167,
"size": 3141
} |
--------------------------------------------------------------------------------
-- This is part of Agda Inference Systems
{-# OPTIONS --sized-types #-}
open import Data.Nat
open import Data.Vec
open import Data.Fin
open import Data.Product
open import Data.Unit
open import Data.Empty
open import Relation.Nullary
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
open import Size
open import Codata.Thunk
open import Relation.Binary.PropositionalEquality as ≡
open import is-lib.SInfSys as IS
open import Examples.Lambda.Lambda
module Examples.Lambda.SmallStep where
U : Set
U = Term 0 × Term 0
data SmallStepRN : Set where
β L-APP R-APP : SmallStepRN
β-r : FinMetaRule U
β-r .Ctx = Term 1 × Value
β-r .comp (t , v) =
[] ,
-------------------------
(app (lambda t) (term v) , subst-0 t (term v))
l-app-r : FinMetaRule U
l-app-r .Ctx = Term 0 × Term 0 × Term 0
l-app-r .comp (t1 , t1' , t2) =
(t1 , t1') ∷ [] ,
-------------------------
((app t1 t2) , (app t1' t2))
r-app-r : FinMetaRule U
r-app-r .Ctx = Value × Term 0 × Term 0
r-app-r .comp (v , t2 , t2') =
(t2 , t2') ∷ [] ,
-------------------------
((app (term v) t2) , app (term v) t2')
SmallStepIS : IS U
SmallStepIS .Names = SmallStepRN
SmallStepIS .rules β = from β-r
SmallStepIS .rules L-APP = from l-app-r
SmallStepIS .rules R-APP = from r-app-r
_⇒_ : Term 0 → Term 0 → Set
t ⇒ t' = Ind⟦ SmallStepIS ⟧ (t , t')
_⇒*_ : Term 0 → Term 0 → Set
_⇒*_ = Star _⇒_
_ConvergesSS : Term 0 → Set
t ConvergesSS = Σ[ v ∈ Value ] (t ⇒* term v)
data ⇒∞ : Term 0 → Size → Set where
step : ∀{t t' i} → t ⇒ t' → Thunk (⇒∞ t') i → ⇒∞ t i
{- Properties -}
inj-l-app : ∀{t1 t1'} t2 → t1 ⇒* t1' → (app t1 t2) ⇒* (app t1' t2)
inj-l-app _ ε = ε
inj-l-app {t1} t2 (fold x ◅ red) =
apply-ind L-APP _ (λ {zero → IS.fold x}) ◅ inj-l-app t2 red
inj-r-app : ∀{t2 t2'} v → t2 ⇒* t2' → (app (term v) t2) ⇒* (app (term v) t2')
inj-r-app _ ε = ε
inj-r-app {t2} v (fold x ◅ red) =
apply-ind R-APP _ (λ {zero → IS.fold x}) ◅ inj-r-app v red
val-not-reduce⇒ : ∀{v e'} → ¬ (term v ⇒ e')
val-not-reduce⇒ {lambda _} (fold (β , c , () , pr))
val-not-reduce⇒ {lambda _} (fold (L-APP , c , () , pr))
val-not-reduce⇒ {lambda _} (fold (R-APP , c , () , pr))
⇒-deterministic : ∀{e e' e''} → e ⇒ e' → e ⇒ e'' → e' ≡ e''
⇒-deterministic (fold (β , (_ , lambda _) , refl , _)) (fold (β , (_ , lambda _) , refl , _)) = refl
⇒-deterministic (fold (β , (_ , lambda _) , refl , _)) (fold (L-APP , _ , refl , pr)) = ⊥-elim (val-not-reduce⇒ (pr zero))
⇒-deterministic (fold (β , (_ , lambda _) , refl , _)) (fold (R-APP , (lambda _ , _) , refl , pr)) = ⊥-elim (val-not-reduce⇒ (pr zero))
⇒-deterministic (fold (L-APP , _ , refl , pr)) (fold (β , _ , refl , _)) = ⊥-elim (val-not-reduce⇒ (pr zero))
⇒-deterministic (fold (L-APP , _ , refl , pr)) (fold (L-APP , _ , refl , pr')) = cong (λ x → app x _) (⇒-deterministic (pr zero) (pr' zero))
⇒-deterministic (fold (L-APP , _ , refl , pr)) (fold (R-APP , _ , refl , _)) = ⊥-elim (val-not-reduce⇒ (pr zero))
⇒-deterministic (fold (R-APP , (lambda _ , _) , refl , pr)) (fold (β , _ , refl , _)) = ⊥-elim (val-not-reduce⇒ (pr zero))
⇒-deterministic (fold (R-APP , (lambda _ , _) , refl , _)) (fold (L-APP , _ , refl , pr)) = ⊥-elim (val-not-reduce⇒ (pr zero))
⇒-deterministic (fold (R-APP , (lambda _ , _) , refl , pr)) (fold (R-APP , (lambda _ , _) , refl , pr')) = cong (λ x → app _ x) (⇒-deterministic (pr zero) (pr' zero))
⇒*-preserves-⇒∞ : ∀{e e'} → (∀{i} → ⇒∞ e i) → e ⇒* e' → (∀{i} → ⇒∞ e' i)
⇒*-preserves-⇒∞ ss ε = ss
⇒*-preserves-⇒∞ ss (x ◅ red-e) with ss
⇒*-preserves-⇒∞ ss (x ◅ red-e) | step x₁ x₂ =
let e'-eq = ⇒-deterministic x₁ x in
⇒*-preserves-⇒∞ (≡.subst (λ x → (∀{i} → ⇒∞ x i)) e'-eq (x₂ .force)) red-e
app-subst-⇒∞ : ∀{e v} → (∀{i} → ⇒∞ (app (lambda e) (term v)) i) → (∀{i} → ⇒∞ (subst-0 e (term v)) i)
app-subst-⇒∞ ss with ss
app-subst-⇒∞ {_} {lambda _} ss | step (fold (β , (_ , lambda _) , refl , _)) rec = rec .force
app-subst-⇒∞ {_} {lambda _} ss | step (fold (L-APP , _ , refl , pr)) _ = ⊥-elim (val-not-reduce⇒ (pr zero))
app-subst-⇒∞ {_} {lambda _} ss | step (fold (R-APP , (lambda _ , _) , refl , pr)) rec = ⊥-elim (val-not-reduce⇒ (pr zero))
app-subst-⇒∞₁ : ∀{e1 e1' e2 v} → e1 ⇒* lambda e1' → e2 ⇒* term v → (∀{i} → ⇒∞ (app e1 e2) i) → (∀{i} → ⇒∞ (subst-0 e1' (term v)) i)
app-subst-⇒∞₁ red-e1 red-e2 ss =
let red-left = ⇒*-preserves-⇒∞ ss (inj-l-app _ red-e1) in
let red-right = ⇒*-preserves-⇒∞ red-left (inj-r-app _ red-e2) in
app-subst-⇒∞ red-right
not-conv-next : ∀{e e'} → ¬ (Σ[ v ∈ Value ] e ⇒* term v) → e ⇒ e' → ¬ (Σ[ v ∈ Value ] e' ⇒* term v)
not-conv-next {e} {e'} n ss-e (v , ss-e') = ⊥-elim (n (v , ss-e ◅ ss-e'))
div-app-l-not-conv : ∀{e1 e2} → (∀{i} → ⇒∞ (app e1 e2) i) → ¬ (e1 ConvergesSS) → (∀{i} → ⇒∞ e1 i)
div-app-l-not-conv ss n-conv with ss
div-app-l-not-conv ss n-conv | step (fold (β , _ , refl , _)) _ = ⊥-elim (n-conv (_ , ε))
div-app-l-not-conv ss n-conv | step (fold (L-APP , _ , refl , pr)) x₁ =
step (pr zero) λ where .force → div-app-l-not-conv (x₁ .force) (not-conv-next n-conv (pr zero))
div-app-l-not-conv ss n-conv | step (fold (R-APP , _ , refl , _)) _ = ⊥-elim (n-conv (_ , ε))
div-app-r-not-conv : ∀{e1 e2 v} → (∀{i} → ⇒∞ (app e1 e2) i) → e1 ⇒* term v → ¬ (e2 ConvergesSS) → (∀{i} → ⇒∞ e2 i)
div-app-r-not-conv ss red-e1 ¬e2-conv with ss
div-app-r-not-conv ss red-e1 ¬e2-conv | step (fold (β , _ , refl , _)) _ = ⊥-elim (¬e2-conv (_ , ε))
div-app-r-not-conv ss ε ¬e2-conv | step (fold (L-APP , _ , refl , pr)) _ = ⊥-elim (val-not-reduce⇒ (pr zero))
div-app-r-not-conv ss (x ◅ red-e1) ¬e2-conv | step (fold (L-APP , _ , refl , pr)) x₁ =
div-app-r-not-conv (λ {i} → ≡.subst (λ x → ⇒∞ (app x _) i) (⇒-deterministic (pr zero) x) (x₁ .force)) red-e1 ¬e2-conv
div-app-r-not-conv ss red-e1 ¬e2-conv | step (fold (R-APP , (lambda _ , _) , refl , pr)) x₁ =
step (pr zero) λ where .force → div-app-r-not-conv (x₁ .force) red-e1 (not-conv-next ¬e2-conv (pr zero))
⇒∞-reduce-⇒ : ∀{e} → (∀{i} → ⇒∞ e i) → Σ[ e' ∈ Term 0 ] e ⇒ e' × (∀{i} → ⇒∞ e' i)
⇒∞-reduce-⇒ ss with ss
⇒∞-reduce-⇒ ss | step s s' = _ , s , s' .force
val-not-⇒∞ : ∀{e v} → e ⇒ term v → ¬ (∀{i} → ⇒∞ e i)
val-not-⇒∞ {e} {v} ss ss' with ss'
val-not-⇒∞ {.(app (lambda (var zero)) (lambda _))} {lambda _} (fold (β , (var zero , lambda _) , refl , _)) ss' | step (fold (β , (.(var zero) , lambda _) , refl , _)) rec =
⊥-elim (val-not-reduce⇒ (proj₁ (proj₂ (⇒∞-reduce-⇒ (rec .force)))))
val-not-⇒∞ {.(app (lambda (lambda _)) (lambda _))} {lambda _} (fold (β , (lambda _ , lambda _) , refl , _)) ss' | step (fold (β , (.(lambda _) , lambda _) , refl , _)) rec =
⊥-elim (val-not-reduce⇒ (proj₁ (proj₂ (⇒∞-reduce-⇒ (rec .force)))))
val-not-⇒∞ {.(app (lambda e1) e2)} {lambda _} (fold (β , (_ , lambda _) , _)) ss' | step (fold (L-APP , (lambda e1 , e1' , e2) , refl , pr)) rec =
⊥-elim (val-not-reduce⇒ (pr zero))
val-not-⇒∞ {.(app e1 e2)} {lambda _} (fold (L-APP , _ , () , _)) ss' | step (fold (L-APP , (e1 , e1' , e2) , refl , _)) _
val-not-⇒∞ {.(app e1 e2)} {lambda _} (fold (R-APP , (lambda _ , _) , () , _)) ss' | step (fold (L-APP , (e1 , e1' , e2) , refl , pr)) _
val-not-⇒∞ {.(app (lambda _) (lambda e2))} {lambda _} (fold (β , (_ , lambda _) , _)) ss' | step (fold (R-APP , (lambda _ , lambda e2 , e2') , refl , pr)) rec =
⊥-elim (val-not-reduce⇒ (pr zero)) | {
"alphanum_fraction": 0.5226790451,
"avg_line_length": 50.6040268456,
"ext": "agda",
"hexsha": "bebf0e90cb0eda064385b2f542f77d7b87c0a062",
"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": "b9043f99e4bf7211db4066a7a943401d127f0c8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "LcicC/inference-systems-agda",
"max_forks_repo_path": "Examples/Lambda/SmallStep.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b9043f99e4bf7211db4066a7a943401d127f0c8f",
"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": "LcicC/inference-systems-agda",
"max_issues_repo_path": "Examples/Lambda/SmallStep.agda",
"max_line_length": 175,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "b9043f99e4bf7211db4066a7a943401d127f0c8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "LcicC/inference-systems-agda",
"max_stars_repo_path": "Examples/Lambda/SmallStep.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-25T15:48:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-10T15:53:47.000Z",
"num_tokens": 3231,
"size": 7540
} |
{-# OPTIONS --allow-unsolved-metas #-}
record Sg (A : Set) (B : A → Set) : Set where
constructor _,_
field
fst : A
snd : B fst
app : {A : Set} {B : A → Set} → ((x' : A) → B x') → (x : A) → B x
app f x = f x
ppa : {A : Set} {B : A → Set} → (x : A) → ((x' : A) → B x') → B x
ppa x f = f x
postulate
Bool : Set
bar : ((Sg Bool (λ _ → Bool)) → Bool) → Bool
foo : Bool
-- foo = app bar (λ (_ , _) → {!!}) -- accepted
foo = ppa (λ (_ , _) → {!!}) bar -- rejected
| {
"alphanum_fraction": 0.4581589958,
"avg_line_length": 21.7272727273,
"ext": "agda",
"hexsha": "4f5eeb8cc9c4b3a3b0638f502b216174cf3a3ddd",
"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/Issue4261.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/Issue4261.agda",
"max_line_length": 65,
"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/Issue4261.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": 196,
"size": 478
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.