Search is not available for this dataset
text
string | meta
dict |
---|---|
module VariableName where
open import OscarPrelude
record VariableName : Set
where
constructor ⟨_⟩
field
name : Nat
open VariableName public
instance EqVariableName : Eq VariableName
Eq._==_ EqVariableName _ = decEq₁ (cong name) ∘ (_≟_ on name $ _)
| {
"alphanum_fraction": 0.7414448669,
"avg_line_length": 16.4375,
"ext": "agda",
"hexsha": "fe47d8bfa746f1057fa6c36180ee4f7dbbe003d3",
"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/VariableName.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/VariableName.agda",
"max_line_length": 65,
"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/VariableName.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 76,
"size": 263
} |
------------------------------------------------------------------------
-- A self-interpreter (without correctness proof)
------------------------------------------------------------------------
module Self-interpreter where
open import Prelude hiding (const)
-- To simplify the development, let's work with actual natural numbers
-- as variables and constants (see
-- Atom.one-can-restrict-attention-to-χ-ℕ-atoms).
open import Atom
open import Chi χ-ℕ-atoms
open import Constants χ-ℕ-atoms
open import Free-variables χ-ℕ-atoms
open χ-atoms χ-ℕ-atoms
open import Combinators
-- Substitution.
internal-subst : Exp
internal-subst = lambda v-x (lambda v-new body)
module Internal-subst where
private
rec-or-lambda : _ → _
rec-or-lambda = λ c →
branch c (v-y ∷ v-e ∷ []) (
case (equal-ℕ (var v-x) (var v-y)) (
branch c-true [] (const c (var v-y ∷ var v-e ∷ [])) ∷
branch c-false [] (
const c (var v-y ∷ apply (var v-subst) (var v-e) ∷ [])) ∷
[]))
branches =
branch c-apply (v-e₁ ∷ v-e₂ ∷ []) (
const c-apply (apply (var v-subst) (var v-e₁) ∷
apply (var v-subst) (var v-e₂) ∷ [])) ∷
branch c-case (v-e ∷ v-bs ∷ []) (
const c-case (
apply (var v-subst) (var v-e) ∷
apply (var v-subst) (var v-bs) ∷ [])) ∷
rec-or-lambda c-rec ∷
rec-or-lambda c-lambda ∷
branch c-const (v-c ∷ v-es ∷ []) (
const c-const (var v-c ∷ apply (var v-subst) (var v-es) ∷ [])) ∷
branch c-var (v-y ∷ []) (
case (equal-ℕ (var v-x) (var v-y)) (
branch c-true [] (var v-new) ∷
branch c-false [] (const c-var (var v-y ∷ [])) ∷ [])) ∷
branch c-branch (v-c ∷ v-ys ∷ v-e ∷ []) (
const c-branch (
var v-c ∷
var v-ys ∷
case (member (var v-x) (var v-ys)) (
branch c-true [] (var v-e) ∷
branch c-false [] (apply (var v-subst) (var v-e)) ∷
[]) ∷ [])) ∷
branch c-nil [] (const c-nil []) ∷
branch c-cons (v-e ∷ v-es ∷ []) (
const c-cons (apply (var v-subst) (var v-e) ∷
apply (var v-subst) (var v-es) ∷ [])) ∷
[]
body = rec v-subst (lambda v-e (case (var v-e) branches))
-- Searches for a branch matching a given natural number.
internal-lookup : Exp
internal-lookup =
lambda v-c (rec v-lookup (lambda v-bs (case (var v-bs) (
branch c-cons (v-b ∷ v-bs ∷ []) (case (var v-b) (
branch c-branch (v-c′ ∷ v-underscore ∷ v-underscore ∷ []) (
case (equal-ℕ (var v-c) (var v-c′)) (
branch c-false [] (apply (var v-lookup) (var v-bs)) ∷
branch c-true [] (var v-b) ∷ [])) ∷ [])) ∷ []))))
-- Tries to apply multiple substitutions.
internal-substs : Exp
internal-substs =
rec v-substs (lambda v-xs (lambda v-es (lambda v-e′ (
case (var v-xs) (
branch c-nil [] (case (var v-es) (
branch c-nil [] (var v-e′) ∷ [])) ∷
branch c-cons (v-x ∷ v-xs ∷ []) (case (var v-es) (
branch c-cons (v-e ∷ v-es ∷ []) (
apply (apply (apply internal-subst (var v-x)) (var v-e))
(apply (apply (apply (var v-substs) (var v-xs))
(var v-es)) (var v-e′))) ∷ [])) ∷ [])))))
-- A map function. The application of map to the function is done at
-- the meta-level in order to simplify proofs.
map : Exp → Exp
map f = rec v-map (lambda v-xs (case (var v-xs) branches))
module Map where
branches =
branch c-nil [] (const c-nil []) ∷
branch c-cons (v-x ∷ v-xs ∷ []) (
const c-cons (apply f (var v-x) ∷
apply (var v-map) (var v-xs) ∷
[])) ∷
[]
-- The self-interpreter.
eval : Exp
eval =
rec v-eval (lambda v-p (case (var v-p) branches))
module Eval where
apply-branch =
branch c-lambda (v-x ∷ v-e ∷ []) (
apply (var v-eval) (
apply (apply (apply internal-subst (var v-x))
(apply (var v-eval) (var v-e₂)))
(var v-e))) ∷
[]
case-body₂ =
case (apply (apply internal-lookup (var v-c)) (var v-bs)) (
branch c-branch (v-underscore ∷ v-xs ∷ v-e ∷ []) (
apply (var v-eval) (
apply (apply (apply internal-substs (var v-xs))
(var v-es)) (var v-e))) ∷
[])
case-body₁ =
case (apply (var v-eval) (var v-e)) (
branch c-const (v-c ∷ v-es ∷ []) case-body₂ ∷
[])
branches =
branch c-apply (v-e₁ ∷ v-e₂ ∷ []) (
case (apply (var v-eval) (var v-e₁)) apply-branch) ∷
branch c-case (v-e ∷ v-bs ∷ []) case-body₁ ∷
branch c-rec (v-x ∷ v-e ∷ []) (
apply (var v-eval) (
apply (apply (apply internal-subst (var v-x))
(const c-rec (var v-x ∷ var v-e ∷ [])))
(var v-e))) ∷
branch c-lambda (v-x ∷ v-e ∷ []) (
const c-lambda (var v-x ∷ var v-e ∷ [])) ∷
branch c-const (v-c ∷ v-es ∷ []) (
const c-const (var v-c ∷
apply (map (var v-eval)) (var v-es) ∷
[])) ∷
[]
eval-closed : Closed eval
eval-closed = from-⊎ (closed? eval)
| {
"alphanum_fraction": 0.4990067541,
"avg_line_length": 32.4774193548,
"ext": "agda",
"hexsha": "d2c928b5dea6309ef5a17fc3ccac71df5393b7af",
"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": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/chi",
"max_forks_repo_path": "src/Self-interpreter.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/chi",
"max_issues_repo_path": "src/Self-interpreter.agda",
"max_line_length": 72,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/chi",
"max_stars_repo_path": "src/Self-interpreter.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z",
"num_tokens": 1643,
"size": 5034
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Core where
open import Level
open import Function.Base using (flip)
open import Relation.Binary using (Rel; IsEquivalence; Setoid)
import Relation.Binary.Reasoning.Setoid as SetoidR
-- Basic definition of a |Category| with a Hom setoid.
-- Also comes with some reasoning combinators (see HomReasoning)
record Category (o ℓ e : Level) : Set (suc (o ⊔ ℓ ⊔ e)) where
eta-equality
infix 4 _≈_ _⇒_
infixr 9 _∘_
field
Obj : Set o
_⇒_ : Rel Obj ℓ
_≈_ : ∀ {A B} → Rel (A ⇒ B) e
id : ∀ {A} → (A ⇒ A)
_∘_ : ∀ {A B C} → (B ⇒ C) → (A ⇒ B) → (A ⇒ C)
field
assoc : ∀ {A B C D} {f : A ⇒ B} {g : B ⇒ C} {h : C ⇒ D} → (h ∘ g) ∘ f ≈ h ∘ (g ∘ f)
-- We add a symmetric proof of associativity so that the opposite category of the
-- opposite category is definitionally equal to the original category. See how
-- `op` is implemented.
sym-assoc : ∀ {A B C D} {f : A ⇒ B} {g : B ⇒ C} {h : C ⇒ D} → h ∘ (g ∘ f) ≈ (h ∘ g) ∘ f
identityˡ : ∀ {A B} {f : A ⇒ B} → id ∘ f ≈ f
identityʳ : ∀ {A B} {f : A ⇒ B} → f ∘ id ≈ f
-- We add a proof of "neutral" identity proof, in order to ensure the opposite of
-- constant functor is definitionally equal to itself.
identity² : ∀ {A} → id ∘ id {A} ≈ id {A}
equiv : ∀ {A B} → IsEquivalence (_≈_ {A} {B})
∘-resp-≈ : ∀ {A B C} {f h : B ⇒ C} {g i : A ⇒ B} → f ≈ h → g ≈ i → f ∘ g ≈ h ∘ i
module Equiv {A B : Obj} = IsEquivalence (equiv {A} {B})
open Equiv
∘-resp-≈ˡ : ∀ {A B C} {f h : B ⇒ C} {g : A ⇒ B} → f ≈ h → f ∘ g ≈ h ∘ g
∘-resp-≈ˡ pf = ∘-resp-≈ pf refl
∘-resp-≈ʳ : ∀ {A B C} {f h : A ⇒ B} {g : B ⇒ C} → f ≈ h → g ∘ f ≈ g ∘ h
∘-resp-≈ʳ pf = ∘-resp-≈ refl pf
hom-setoid : ∀ {A B} → Setoid _ _
hom-setoid {A} {B} = record
{ Carrier = A ⇒ B
; _≈_ = _≈_
; isEquivalence = equiv
}
-- When a category is quatified, it is convenient to refer to the levels from a module,
-- so we do not have to explicitly quantify over a category when universe levels do not
-- play a big part in a proof (which is the case probably all the time).
o-level : Level
o-level = o
ℓ-level : Level
ℓ-level = ℓ
e-level : Level
e-level = e
-- Reasoning combinators. _≈⟨_⟩_ and _≈˘⟨_⟩_ from SetoidR.
-- Also some useful combinators for doing reasoning on _∘_ chains
module HomReasoning {A B : Obj} where
open SetoidR (hom-setoid {A} {B}) public
-- open Equiv {A = A} {B = B} public
infixr 4 _⟩∘⟨_ refl⟩∘⟨_
infixl 5 _⟩∘⟨refl
_⟩∘⟨_ : ∀ {M} {f h : M ⇒ B} {g i : A ⇒ M} → f ≈ h → g ≈ i → f ∘ g ≈ h ∘ i
_⟩∘⟨_ = ∘-resp-≈
refl⟩∘⟨_ : ∀ {M} {f : M ⇒ B} {g i : A ⇒ M} → g ≈ i → f ∘ g ≈ f ∘ i
refl⟩∘⟨_ = Equiv.refl ⟩∘⟨_
_⟩∘⟨refl : ∀ {M} {f h : M ⇒ B} {g : A ⇒ M} → f ≈ h → f ∘ g ≈ h ∘ g
_⟩∘⟨refl = _⟩∘⟨ Equiv.refl
-- convenient inline versions
infix 2 ⟺
infixr 3 _○_
⟺ : {f g : A ⇒ B} → f ≈ g → g ≈ f
⟺ = Equiv.sym
_○_ : {f g h : A ⇒ B} → f ≈ g → g ≈ h → f ≈ h
_○_ = Equiv.trans
op : Category o ℓ e
op = record
{ Obj = Obj
; _⇒_ = flip _⇒_
; _≈_ = _≈_
; _∘_ = flip _∘_
; id = id
; assoc = sym-assoc
; sym-assoc = assoc
; identityˡ = identityʳ
; identityʳ = identityˡ
; identity² = identity²
; equiv = equiv
; ∘-resp-≈ = flip ∘-resp-≈
}
| {
"alphanum_fraction": 0.5134739309,
"avg_line_length": 31.6111111111,
"ext": "agda",
"hexsha": "a0b484e32f40554d0d2c3c746fb349809d1eb5b7",
"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": "6cbfdf3f1be15ef513435e3b85faae92cb1ac36f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bond15/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6cbfdf3f1be15ef513435e3b85faae92cb1ac36f",
"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": "bond15/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Core.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6cbfdf3f1be15ef513435e3b85faae92cb1ac36f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bond15/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Core.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1449,
"size": 3414
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Adjoint.Equivalence where
open import Level
open import Categories.Adjoint
open import Categories.Adjoint.TwoSided
open import Categories.Adjoint.TwoSided.Compose
open import Categories.Category.Core using (Category)
open import Categories.Functor using (Functor; _∘F_) renaming (id to idF)
open import Categories.NaturalTransformation.NaturalIsomorphism as ≃ using (_≃_)
open import Relation.Binary using (Setoid; IsEquivalence)
private
variable
o ℓ e o′ ℓ′ e′ : Level
C D E : Category o ℓ e
record ⊣Equivalence (C : Category o ℓ e) (D : Category o′ ℓ′ e′) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
field
L : Functor C D
R : Functor D C
L⊣⊢R : L ⊣⊢ R
module L = Functor L
module R = Functor R
open _⊣⊢_ L⊣⊢R public
refl : ⊣Equivalence C C
refl = record
{ L = idF
; R = idF
; L⊣⊢R = id⊣⊢id
}
sym : ⊣Equivalence C D → ⊣Equivalence D C
sym e = record
{ L = R
; R = L
; L⊣⊢R = op₂
}
where open ⊣Equivalence e
trans : ⊣Equivalence C D → ⊣Equivalence D E → ⊣Equivalence C E
trans e e′ = record
{ L = e′.L ∘F e.L
; R = e.R ∘F e′.R
; L⊣⊢R = e.L⊣⊢R ∘⊣⊢ e′.L⊣⊢R
}
where module e = ⊣Equivalence e using (L; R; L⊣⊢R)
module e′ = ⊣Equivalence e′ using (L; R; L⊣⊢R)
isEquivalence : ∀ {o ℓ e} → IsEquivalence (⊣Equivalence {o} {ℓ} {e})
isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
setoid : ∀ o ℓ e → Setoid _ _
setoid o ℓ e = record
{ Carrier = Category o ℓ e
; _≈_ = ⊣Equivalence
; isEquivalence = isEquivalence
}
| {
"alphanum_fraction": 0.6082665022,
"avg_line_length": 23.4927536232,
"ext": "agda",
"hexsha": "dbf491141e73ab70256b1cfe5debee58b88ed0fc",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Adjoint/Equivalence.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Adjoint/Equivalence.agda",
"max_line_length": 103,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Adjoint/Equivalence.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": 655,
"size": 1621
} |
{-# OPTIONS --without-K #-}
module sets.properties where
open import sum
open import equality.core
open import equality.calculus
open import function.isomorphism
open import function.overloading
open import hott.level
open import hott.equivalence.core
open import hott.equivalence.alternative
open import sets.unit
mk-prop-iso : ∀ {i j}{A : Set i}{B : Set j}
→ h 1 A → h 1 B
→ (A → B) → (B → A)
→ A ≅ B
mk-prop-iso hA hB f g
= iso f g (λ x → h1⇒prop hA _ _)
(λ y → h1⇒prop hB _ _)
iso-coherence-h2 : ∀ {i j}(A : HSet i)(B : HSet j)
→ (proj₁ A ≅' proj₁ B)
≅ (proj₁ A ≅ proj₁ B)
iso-coherence-h2 (A , hA)(B , hB) = begin
(A ≅' B)
≅⟨ ( Σ-ap-iso₂ λ isom
→ contr-⊤-iso (Π-level λ x → hB _ _ _ _) ) ⟩
((A ≅ B) × ⊤)
≅⟨ ×-right-unit ⟩
(A ≅ B)
∎
where open ≅-Reasoning
iso-equiv-h2 : ∀ {i j}{A : Set i}{B : Set j}
→ h 2 A → h 2 B
→ (A ≈ B) ≅ (A ≅ B)
iso-equiv-h2 hA hB = trans≅ ≈⇔≅'
(iso-coherence-h2 (_ , hA) (_ , hB))
iso-eq-h2 : ∀ {i j}{A : Set i}{B : Set j}
→ h 2 A → h 2 B
→ {isom isom' : A ≅ B}
→ (apply isom ≡ apply isom')
→ isom ≡ isom'
iso-eq-h2 hA hB p =
subtype-eq (λ f → weak-equiv-h1 f)
(sym≅ (iso-equiv-h2 hA hB)) p
inj-eq-h2 : ∀ {i j}{A : Set i}{B : Set j}
→ h 2 A → {f f' : A ↣ B}
→ (apply f ≡ apply f')
→ f ≡ f'
inj-eq-h2 hA refl
= ap (_,_ _) (h1⇒prop (inj-level _ hA) _ _)
| {
"alphanum_fraction": 0.4917382683,
"avg_line_length": 27.0178571429,
"ext": "agda",
"hexsha": "649d3374747d695e35aec9a4b1896e97b90805bc",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/sets/properties.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/sets/properties.agda",
"max_line_length": 50,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/sets/properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 610,
"size": 1513
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
open import Sets.EquivalenceRelations
open import Setoids.Setoids
open import Setoids.Subset
module Setoids.Union.Lemmas {a b : _} {A : Set a} (S : Setoid {a} {b} A) {c d : _} {pred1 : A → Set c} {pred2 : A → Set d} (s1 : subset S pred1) (s2 : subset S pred2) where
open import Setoids.Union.Definition S
open import Setoids.Equality S
unionCommutative : union s1 s2 =S union s2 s1
unionCommutative i = ans1 ,, ans2
where
ans1 : unionPredicate s1 s2 i → unionPredicate s2 s1 i
ans1 (inl x) = inr x
ans1 (inr x) = inl x
ans2 : unionPredicate s2 s1 i → unionPredicate s1 s2 i
ans2 (inl x) = inr x
ans2 (inr x) = inl x
unionAssociative : {e : _} {pred3 : A → Set e} (s3 : subset S pred3) → union (union s1 s2) s3 =S union s1 (union s2 s3)
unionAssociative s3 x = ans1 ,, ans2
where
ans1 : unionPredicate (union s1 s2) s3 x → unionPredicate s1 (union s2 s3) x
ans1 (inl (inl x)) = inl x
ans1 (inl (inr x)) = inr (inl x)
ans1 (inr x) = inr (inr x)
ans2 : _
ans2 (inl x) = inl (inl x)
ans2 (inr (inl x)) = inl (inr x)
ans2 (inr (inr x)) = inr x
| {
"alphanum_fraction": 0.6433172303,
"avg_line_length": 35.4857142857,
"ext": "agda",
"hexsha": "e159623870a52e3ca88aa642ea1dbe333da3346e",
"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": "Setoids/Union/Lemmas.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": "Setoids/Union/Lemmas.agda",
"max_line_length": 172,
"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": "Setoids/Union/Lemmas.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": 484,
"size": 1242
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.Susp.Base where
open import Cubical.Core.Glue
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Bool
open import Cubical.HITs.S1
open import Cubical.HITs.S2
open import Cubical.HITs.S3
data Susp {ℓ} (A : Type ℓ) : Type ℓ where
north : Susp A
south : Susp A
merid : (a : A) → north ≡ south
SuspBool : Type₀
SuspBool = Susp Bool
SuspBool→S¹ : SuspBool → S¹
SuspBool→S¹ north = base
SuspBool→S¹ south = base
SuspBool→S¹ (merid false i) = loop i
SuspBool→S¹ (merid true i) = base
S¹→SuspBool : S¹ → SuspBool
S¹→SuspBool base = north
S¹→SuspBool (loop i) = (merid false ∙ (sym (merid true))) i
SuspBool→S¹→SuspBool : (x : SuspBool) → Path _ (S¹→SuspBool (SuspBool→S¹ x)) x
SuspBool→S¹→SuspBool north = refl
SuspBool→S¹→SuspBool south = merid true
SuspBool→S¹→SuspBool (merid false i) = λ j → hcomp (λ k → (λ { (j = i1) → merid false i
; (i = i0) → north
; (i = i1) → merid true (j ∨ ~ k)}))
(merid false i)
SuspBool→S¹→SuspBool (merid true i) = λ j → merid true (i ∧ j)
S¹→SuspBool→S¹ : (x : S¹) → SuspBool→S¹ (S¹→SuspBool x) ≡ x
S¹→SuspBool→S¹ base = refl
S¹→SuspBool→S¹ (loop i) = λ j →
hfill (λ k → λ { (i = i0) → base
; (i = i1) → base })
(inS (loop i)) (~ j)
S¹≃SuspBool : S¹ ≃ SuspBool
S¹≃SuspBool = isoToEquiv (iso S¹→SuspBool SuspBool→S¹ SuspBool→S¹→SuspBool S¹→SuspBool→S¹)
S¹≡SuspBool : S¹ ≡ SuspBool
S¹≡SuspBool = isoToPath (iso S¹→SuspBool SuspBool→S¹ SuspBool→S¹→SuspBool S¹→SuspBool→S¹)
-- Now the sphere
SuspS¹ : Type₀
SuspS¹ = Susp S¹
SuspS¹→S² : SuspS¹ → S²
SuspS¹→S² north = base
SuspS¹→S² south = base
SuspS¹→S² (merid base i) = base
SuspS¹→S² (merid (loop j) i) = surf i j
meridian-contraction : I → I → I → SuspS¹
meridian-contraction i j l = hfill (λ k → λ { (i = i0) → north
; (i = i1) → merid base (~ k)
; (j = i0) → merid base (~ k ∧ i)
; (j = i1) → merid base (~ k ∧ i) })
(inS (merid (loop j) i)) l
S²→SuspS¹ : S² → SuspS¹
S²→SuspS¹ base = north
S²→SuspS¹ (surf i j) = meridian-contraction i j i1
S²→SuspS¹→S² : ∀ x → SuspS¹→S² (S²→SuspS¹ x) ≡ x
S²→SuspS¹→S² base k = base
S²→SuspS¹→S² (surf i j) k = SuspS¹→S² (meridian-contraction i j (~ k))
SuspS¹→S²→SuspS¹ : ∀ x → S²→SuspS¹ (SuspS¹→S² x) ≡ x
SuspS¹→S²→SuspS¹ north k = north
SuspS¹→S²→SuspS¹ south k = merid base k
SuspS¹→S²→SuspS¹ (merid base j) k = merid base (k ∧ j)
SuspS¹→S²→SuspS¹ (merid (loop j) i) k = meridian-contraction i j (~ k)
S²≡SuspS¹ : S² ≡ SuspS¹
S²≡SuspS¹ = isoToPath (iso S²→SuspS¹ SuspS¹→S² SuspS¹→S²→SuspS¹ S²→SuspS¹→S²)
-- And the 3-sphere
SuspS² : Type₀
SuspS² = Susp S²
SuspS²→S³ : SuspS² → S³
SuspS²→S³ north = base
SuspS²→S³ south = base
SuspS²→S³ (merid base i) = base
SuspS²→S³ (merid (surf j k) i) = surf i j k
meridian-contraction-2 : I → I → I → I → SuspS²
meridian-contraction-2 i j k l = hfill (λ m → λ { (i = i0) → north
; (i = i1) → merid base (~ m)
; (j = i0) → merid base (~ m ∧ i)
; (j = i1) → merid base (~ m ∧ i)
; (k = i0) → merid base (~ m ∧ i)
; (k = i1) → merid base (~ m ∧ i) })
(inS (merid (surf j k) i)) l
S³→SuspS² : S³ → SuspS²
S³→SuspS² base = north
S³→SuspS² (surf i j k) = meridian-contraction-2 i j k i1
S³→SuspS²→S³ : ∀ x → SuspS²→S³ (S³→SuspS² x) ≡ x
S³→SuspS²→S³ base l = base
S³→SuspS²→S³ (surf i j k) l = SuspS²→S³ (meridian-contraction-2 i j k (~ l))
SuspS²→S³→SuspS² : ∀ x → S³→SuspS² (SuspS²→S³ x) ≡ x
SuspS²→S³→SuspS² north l = north
SuspS²→S³→SuspS² south l = merid base l
SuspS²→S³→SuspS² (merid base j) l = merid base (l ∧ j)
SuspS²→S³→SuspS² (merid (surf j k) i) l = meridian-contraction-2 i j k (~ l)
S³≡SuspS² : S³ ≡ SuspS²
S³≡SuspS² = isoToPath (iso S³→SuspS² SuspS²→S³ SuspS²→S³→SuspS² S³→SuspS²→S³)
| {
"alphanum_fraction": 0.5608477666,
"avg_line_length": 34.5511811024,
"ext": "agda",
"hexsha": "4de5abd870303d8925534445ff520d312fa0873d",
"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": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cj-xu/cubical",
"max_forks_repo_path": "Cubical/HITs/Susp/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"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": "cj-xu/cubical",
"max_issues_repo_path": "Cubical/HITs/Susp/Base.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cj-xu/cubical",
"max_stars_repo_path": "Cubical/HITs/Susp/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1705,
"size": 4388
} |
-- # A Reflexive Graph Model of Sized Types
-- This is the formalisation of my M.Sc. thesis, available at
-- https://limperg.de/paper/msc-thesis/
-- I define λST, a simply typed lambda calculus extended with sized types. I
-- then give a reflexive graph model of λST which incorporates a notion of size
-- irrelevance. This document lists all modules belonging to the development,
-- roughly in dependency order.
module index where
-- ## Object Language
-- The following modules define the syntax and type system of λST.
-- Sizes, size contexts, size comparison.
import Source.Size
-- First formulation of size substitutions.
import Source.Size.Substitution.Canonical
-- Second formulation of size substitutions.
import Source.Size.Substitution.Universe
-- An abstraction for things which size substitutions can be applied to.
import Source.Size.Substitution.Theory
-- Types.
import Source.Type
-- Terms.
import Source.Term
-- ## Model
-- The following modules define the reflexive graph model of λST.
-- Propositional reflexive graphs and their morphisms.
import Model.RGraph
-- Model of sizes, size contexts, size comparison.
import Model.Size
-- Families of propositional reflexive graphs (PRGraph families) and their
-- morphisms.
import Model.Type.Core
-- The terminal PRGraph family.
import Model.Terminal
-- Binary products of PRGraph families.
import Model.Product
-- Exponentials of PRGraph families (model of the function space).
import Model.Exponential
-- Model of size quantification.
import Model.Quantification
-- Model of the natural number type.
import Model.Nat
-- Model of the stream type.
import Model.Stream
-- Model of types and type contexts.
import Model.Type
-- Model of terms.
import Model.Term
-- ## Utility Library
-- The following modules contain utility code. The majority of this is an
-- implementation of (parts of) Homotopy Type Theory.
import Util.Data.Product
import Util.HoTT.Equiv
import Util.HoTT.Equiv.Core
import Util.HoTT.Equiv.Induction
import Util.HoTT.FunctionalExtensionality
import Util.HoTT.HLevel
import Util.HoTT.HLevel.Core
import Util.HoTT.Homotopy
import Util.HoTT.Section
import Util.HoTT.Singleton
import Util.HoTT.Univalence
import Util.HoTT.Univalence.Axiom
import Util.HoTT.Univalence.Beta
import Util.HoTT.Univalence.ContrFormulation
import Util.HoTT.Univalence.Statement
import Util.Induction.WellFounded
import Util.Prelude
import Util.Relation.Binary.Closure.SymmetricTransitive
import Util.Relation.Binary.LogicalEquivalence
import Util.Relation.Binary.PropositionalEquality
import Util.Vec
-- ## Miscellaneous
-- Some terms of λST and their typing derivations.
import Source.Examples
-- Experiments with a hypothetical Agda without the ∞ < ∞ rule.
import irreflexive-lt
-- Ordinals as defined in the HoTT book.
import Ordinal.HoTT
-- Plump ordinals as presented by Shulman.
import Ordinal.Shulman
| {
"alphanum_fraction": 0.7882758621,
"avg_line_length": 24.5762711864,
"ext": "agda",
"hexsha": "06f71e99950b70a4f45a9fb8ca5b93982607fe9c",
"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": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/msc-thesis-code",
"max_forks_repo_path": "src/index.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"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": "JLimperg/msc-thesis-code",
"max_issues_repo_path": "src/index.agda",
"max_line_length": 79,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/msc-thesis-code",
"max_stars_repo_path": "src/index.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-26T06:37:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-13T21:31:17.000Z",
"num_tokens": 676,
"size": 2900
} |
module New.Correctness where
open import Function hiding (const)
open import New.Lang
open import New.Changes
open import New.Derive
open import New.LangChanges
open import New.LangOps
open import New.FunctionLemmas
open import New.Unused
⟦Γ≼ΔΓ⟧ : ∀ {Γ} (ρ : ⟦ Γ ⟧Context) (dρ : ChΓ Γ) → validΓ ρ dρ →
ρ ≡ ⟦ Γ≼ΔΓ ⟧≼ dρ
⟦Γ≼ΔΓ⟧ ∅ ∅ tt = refl
⟦Γ≼ΔΓ⟧ (v • ρ) (dv • .v • dρ) (vdv , refl , ρdρ) = cong₂ _•_ refl (⟦Γ≼ΔΓ⟧ ρ dρ ρdρ)
fit-sound : ∀ {Γ τ} → (t : Term Γ τ) →
(ρ : ⟦ Γ ⟧Context) (dρ : ChΓ Γ) → validΓ ρ dρ →
⟦ t ⟧Term ρ ≡ ⟦ fit t ⟧Term dρ
fit-sound t ρ dρ ρdρ = trans
(cong ⟦ t ⟧Term (⟦Γ≼ΔΓ⟧ ρ dρ ρdρ))
(sym (weaken-sound t _))
correctDeriveConst : ∀ {τ} (c : Const τ) → ⟦ c ⟧Const ≡ ⟦ c ⟧Const ⊕ (⟦_⟧ΔConst c)
correctDeriveConst (lit n) = sym (right-id-int n)
correctDeriveConst plus = ext (λ m → ext (lemma m))
where
lemma : ∀ m n → m + n ≡ m + n + (m + - m + (n + - n))
lemma m n rewrite right-inv-int m | right-inv-int n | right-id-int (m + n) = refl
correctDeriveConst minus = ext (λ m → ext (λ n → lemma m n))
where
lemma : ∀ m n → m - n ≡ m - n + (m + - m - (n + - n))
lemma m n rewrite right-inv-int m | right-inv-int n | right-id-int (m - n) = refl
correctDeriveConst cons = ext (λ v1 → ext (λ v2 → sym (update-nil (v1 , v2))))
correctDeriveConst fst = ext (λ vp → sym (update-nil (proj₁ vp)))
correctDeriveConst snd = ext (λ vp → sym (update-nil (proj₂ vp)))
correctDeriveConst linj = ext (λ va → sym (cong inj₁ (update-nil va)))
correctDeriveConst rinj = ext (λ vb → sym (cong inj₂ (update-nil vb)))
correctDeriveConst (match {t1} {t2} {t3}) = ext³ lemma
where
lemma : ∀ s f g →
⟦ match {t1} {t2} {t3} ⟧Const s f g ≡
(⟦ match ⟧Const ⊕ ⟦ match ⟧ΔConst) s f g
lemma (inj₁ x) f g rewrite update-nil x | update-nil (f x) = refl
lemma (inj₂ y) f g rewrite update-nil y | update-nil (g y) = refl
validDeriveConst : ∀ {τ} (c : Const τ) → valid ⟦ c ⟧Const (⟦_⟧ΔConst c)
validDeriveConst (lit n) = tt
validDeriveConst {τ = t1 ⇒ t2 ⇒ pair .t1 .t2} cons = binary-valid (λ a da ada b db bdb → (ada , bdb)) dcons-eq
where
open BinaryValid ⟦ cons {t1} {t2} ⟧Const (⟦ cons ⟧ΔConst)
dcons-eq : binary-valid-eq-hp
dcons-eq a da ada b db bdb rewrite update-nil (a ⊕ da) | update-nil (b ⊕ db) = refl
validDeriveConst fst (a , b) (da , db) (ada , bdb) = ada , update-nil (a ⊕ da)
validDeriveConst snd (a , b) (da , db) (ada , bdb) = bdb , update-nil (b ⊕ db)
validDeriveConst plus = binary-valid (λ a da ada b db bdb → tt) dplus-eq
where
open BinaryValid ⟦ plus ⟧Const (⟦ plus ⟧ΔConst)
dplus-eq : binary-valid-eq-hp
dplus-eq a da ada b db bdb rewrite right-inv-int (a + da) | right-inv-int (b + db) | right-id-int (a + da + (b + db)) = mn·pq=mp·nq {a} {da} {b} {db}
validDeriveConst minus = binary-valid (λ a da ada b db bdb → tt) dminus-eq
where
open BinaryValid ⟦ minus ⟧Const (⟦ minus ⟧ΔConst)
dminus-eq : binary-valid-eq-hp
dminus-eq a da ada b db bdb rewrite right-inv-int (a + da) | right-inv-int (b + db) | right-id-int (a + da - (b + db)) | sym (-m·-n=-mn {b} {db}) = mn·pq=mp·nq {a} {da} { - b} { - db}
validDeriveConst linj a da ada = sv₁ a da ada , cong inj₁ (update-nil (a ⊕ da))
validDeriveConst rinj b db bdb = sv₂ b db bdb , cong inj₂ (update-nil (b ⊕ db))
validDeriveConst (match {t1} {t2} {t3}) =
ternary-valid dmatch-valid dmatch-eq
where
open TernaryValid {{chAlgt (sum t1 t2)}} {{chAlgt (t1 ⇒ t3)}} {{chAlgt (t2 ⇒ t3)}} {{chAlgt t3}} ⟦ match ⟧Const (⟦ match ⟧ΔConst)
dmatch-valid : ternary-valid-preserve-hp
dmatch-valid .(inj₁ a) .(inj₁ (inj₁ da)) (sv₁ a da ada) f df fdf g dg gdg = proj₁ (fdf a da ada)
dmatch-valid .(inj₂ b) .(inj₁ (inj₂ db)) (sv₂ b db bdb) f df fdf g dg gdg = proj₁ (gdg b db bdb)
dmatch-valid .(inj₁ a1) .(inj₂ (inj₂ b2)) (svrp₁ a1 b2) f df fdf g dg gdg
rewrite changeMatchSem-lem1 f df g dg a1 b2
= ⊝-valid (f a1) (g b2 ⊕ dg b2 (nil b2))
dmatch-valid .(inj₂ b1) .(inj₂ (inj₁ a2)) (svrp₂ b1 a2) f df fdf g dg gdg
rewrite changeMatchSem-lem2 f df g dg b1 a2
= ⊝-valid (g b1) (f a2 ⊕ df a2 (nil a2))
dmatch-eq : ternary-valid-eq-hp
dmatch-eq .(inj₁ a) .(inj₁ (inj₁ da)) (sv₁ a da ada) f df fdf g dg gdg
rewrite update-nil (a ⊕ da)
| update-nil (f (a ⊕ da) ⊕ df (a ⊕ da) (nil (a ⊕ da))) = proj₂ (fdf a da ada)
dmatch-eq .(inj₂ b) .(inj₁ (inj₂ db)) (sv₂ b db bdb) f df fdf g dg gdg
rewrite update-nil (b ⊕ db)
| update-nil (g (b ⊕ db) ⊕ dg (b ⊕ db) (nil (b ⊕ db))) = proj₂ (gdg b db bdb)
dmatch-eq .(inj₁ a1) .(inj₂ (inj₂ b2)) (svrp₁ a1 b2) f df fdf g dg gdg
rewrite changeMatchSem-lem1 f df g dg a1 b2
| update-nil b2
| update-diff (g b2 ⊕ dg b2 (nil b2)) (f a1)
| update-nil (g b2 ⊕ dg b2 (nil b2))
= refl
dmatch-eq .(inj₂ b1) .(inj₂ (inj₁ a2)) (svrp₂ b1 a2) f df fdf g dg gdg
rewrite changeMatchSem-lem2 f df g dg b1 a2
| update-nil a2
| update-diff (f a2 ⊕ df a2 (nil a2)) (g b1)
| update-nil (f a2 ⊕ df a2 (nil a2))
= refl
validDeriveVar : ∀ {Γ τ} → (x : Var Γ τ) →
(ρ : ⟦ Γ ⟧Context) (dρ : ChΓ Γ) →
validΓ ρ dρ → valid (⟦ x ⟧Var ρ) (⟦ x ⟧ΔVar ρ dρ)
validDeriveVar this (v • ρ) (dv • .v • dρ) (vdv , refl , ρdρ) = vdv
validDeriveVar (that x) (v • ρ) (dv • .v • dρ) (vdv , refl , ρdρ) = validDeriveVar x ρ dρ ρdρ
correctDeriveVar : ∀ {Γ τ} → (x : Var Γ τ) →
IsDerivative ⟦ x ⟧Var (⟦ x ⟧ΔVar)
correctDeriveVar this (v • ρ) (dv • v' • dρ) ρdρ = refl
correctDeriveVar (that x) (v • ρ) (dv • .v • dρ) (vdv , refl , ρdρ) = correctDeriveVar x ρ dρ ρdρ
validDerive : ∀ {Γ τ} → (t : Term Γ τ) →
(ρ : ⟦ Γ ⟧Context) (dρ : ChΓ Γ) → validΓ ρ dρ →
valid (⟦ t ⟧Term ρ) (⟦ t ⟧ΔTerm ρ dρ)
correctDerive : ∀ {Γ τ} → (t : Term Γ τ) →
IsDerivative ⟦ t ⟧Term ⟦ t ⟧ΔTerm
correctDerive (const c) ρ dρ ρdρ rewrite ⟦ c ⟧ΔConst-rewrite ρ dρ = correctDeriveConst c
correctDerive (var x) ρ dρ ρdρ = correctDeriveVar x ρ dρ ρdρ
correctDerive (app s t) ρ dρ ρdρ rewrite sym (fit-sound t ρ dρ ρdρ) =
let
open ≡-Reasoning
a0 = ⟦ t ⟧Term ρ
da0 = ⟦ derive t ⟧Term dρ
a0da0 = validDerive t ρ dρ ρdρ
in
begin
⟦ s ⟧Term (ρ ⊕ dρ) (⟦ t ⟧Term (ρ ⊕ dρ))
≡⟨ correctDerive s ρ dρ ρdρ ⟨$⟩ correctDerive t ρ dρ ρdρ ⟩
(⟦ s ⟧Term ρ ⊕ ⟦ s ⟧ΔTerm ρ dρ) (⟦ t ⟧Term ρ ⊕ ⟦ t ⟧ΔTerm ρ dρ)
≡⟨ proj₂ (validDerive s ρ dρ ρdρ a0 da0 a0da0) ⟩
⟦ s ⟧Term ρ (⟦ t ⟧Term ρ) ⊕ (⟦ s ⟧ΔTerm ρ dρ) (⟦ t ⟧Term ρ) (⟦ t ⟧ΔTerm ρ dρ)
∎
where
open import Theorem.CongApp
correctDerive (abs t) ρ dρ ρdρ = ext $ λ a →
let
open ≡-Reasoning
ρ1 = a • ρ
dρ1 = nil a • a • dρ
ρ1dρ1 = nil-valid a , refl , ρdρ
in
-- equal-future-expand-derivative ⟦ t ⟧Term ⟦ t ⟧ΔTerm (correctDerive t)
-- ρ1 dρ1 ρ1dρ1
-- (a • (ρ ⊕ dρ))
-- (cong (_• ρ ⊕ dρ) (sym (update-nil a)))
begin
⟦ t ⟧Term (a • ρ ⊕ dρ)
≡⟨ cong (λ a′ → ⟦ t ⟧Term (a′ • ρ ⊕ dρ)) (sym (update-nil a)) ⟩
⟦ t ⟧Term (ρ1 ⊕ dρ1)
≡⟨ correctDerive t ρ1 dρ1 ρ1dρ1 ⟩
⟦ t ⟧Term ρ1 ⊕ ⟦ t ⟧ΔTerm ρ1 dρ1
∎
validDerive (app s t) ρ dρ ρdρ =
let
f = ⟦ s ⟧Term ρ
df = ⟦ derive s ⟧Term dρ
v = ⟦ t ⟧Term ρ
dv = ⟦ derive t ⟧Term dρ
vdv = validDerive t ρ dρ ρdρ
fdf = validDerive s ρ dρ ρdρ
fvdfv = proj₁ (fdf v dv vdv)
in subst (λ v′ → valid (f v) (df v′ dv)) (fit-sound t ρ dρ ρdρ) fvdfv
validDerive (abs t) ρ dρ ρdρ =
λ a da ada →
let
ρ1 = a ⊕ da • ρ
dρ1 = nil (a ⊕ da) • (a ⊕ da) • dρ
ρ2 = a • ρ
dρ2 = da • a • dρ
ρ1dρ1 = nil-valid (a ⊕ da) , refl , ρdρ
ρ2dρ2 = ada , refl , ρdρ
rdr = validDerive t ρ2 dρ2 ρ2dρ2
open ≡-Reasoning
in
rdr ,
equal-future-derivative ⟦ t ⟧Term ⟦ t ⟧ΔTerm (correctDerive t)
ρ1 dρ1 ρ1dρ1
ρ2 dρ2 ρ2dρ2
(cong (λ a′ → (a′ • ρ ⊕ dρ)) (update-nil (a ⊕ da)))
validDerive (var x) ρ dρ ρdρ = validDeriveVar x ρ dρ ρdρ
validDerive (const c) ρ dρ ρdρ rewrite ⟦ c ⟧ΔConst-rewrite ρ dρ = validDeriveConst c
| {
"alphanum_fraction": 0.579458097,
"avg_line_length": 42.2074468085,
"ext": "agda",
"hexsha": "bd0be2fabc401ffc3c7dd439198ca217d8bedbbc",
"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": "New/Correctness.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": "New/Correctness.agda",
"max_line_length": 187,
"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": "New/Correctness.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": 3674,
"size": 7935
} |
module _ where
module M (X : Set₁) where
record Raw : Set₁ where
field return : Set
postulate fmap : Set
module Fails = Raw ⦃ … ⦄
module Works ⦃ r : Raw ⦄ = Raw r
open M
postulate r : Raw Set
fail : Set
fail = Fails.fmap Set ⦃ r ⦄
-- C-c C-n fail
-- M.Raw.fmap Set r
good : Set
good = Works.fmap Set ⦃ r ⦄
-- C-c C-n good
-- M.Raw.fmap r
-- Checking using reflection saves us an interaction test.
open import Agda.Builtin.Reflection renaming (bindTC to _>>=_)
open import Agda.Builtin.Equality
open import Agda.Builtin.List
open import Agda.Builtin.Unit
macro
`_ : Name → Term → TC ⊤
(` x) hole = do
v ← normalise (def x [])
`v ← quoteTC v
unify hole `v
pattern vArg x = arg (arg-info visible relevant) x
pattern hArg x = arg (arg-info hidden relevant) x
pattern `fmap x y = def (quote M.Raw.fmap) (x ∷ y ∷ [])
`Set = agda-sort (lit 0)
`r = def (quote r) []
check-good : ` good ≡ `fmap (hArg `Set) (vArg `r)
check-good = refl
check-bad : ` fail ≡ ` good
check-bad = refl
| {
"alphanum_fraction": 0.6359175662,
"avg_line_length": 19.5961538462,
"ext": "agda",
"hexsha": "510cce497e4af9e3f1dd9577830e39ead4ae6aa0",
"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/Succeed/Issue3079.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/Issue3079.agda",
"max_line_length": 62,
"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/Issue3079.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": 355,
"size": 1019
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use Data.List.Relation.Unary.All
-- directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.All where
open import Data.List.Relation.Unary.All public
| {
"alphanum_fraction": 0.4438502674,
"avg_line_length": 28.7692307692,
"ext": "agda",
"hexsha": "2439bc1bfaf03e7ed946a0c648ab2cbf70cf5b0d",
"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/All.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/All.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/All.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 57,
"size": 374
} |
{-# OPTIONS --safe #-}
module Cubical.Categories.Limits.Initial where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism renaming (Iso to _≅_)
open import Cubical.HITs.PropositionalTruncation.Base
open import Cubical.Data.Sigma
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
open import Cubical.Categories.Adjoint
private
variable
ℓ ℓ' : Level
ℓC ℓC' ℓD ℓD' : Level
module _ (C : Category ℓ ℓ') where
open Category C
isInitial : (x : ob) → Type (ℓ-max ℓ ℓ')
isInitial x = ∀ (y : ob) → isContr (C [ x , y ])
Initial : Type (ℓ-max ℓ ℓ')
Initial = Σ[ x ∈ ob ] isInitial x
initialOb : Initial → ob
initialOb = fst
initialArrow : (T : Initial) (y : ob) → C [ initialOb T , y ]
initialArrow T y = T .snd y .fst
initialArrowUnique : {T : Initial} {y : ob} (f : C [ initialOb T , y ])
→ initialArrow T y ≡ f
initialArrowUnique {T} {y} f = T .snd y .snd f
initialEndoIsId : (T : Initial) (f : C [ initialOb T , initialOb T ])
→ f ≡ id
initialEndoIsId T f = isContr→isProp (T .snd (initialOb T)) f id
hasInitial : Type (ℓ-max ℓ ℓ')
hasInitial = ∥ Initial ∥₁
-- Initiality of an object is a proposition.
isPropIsInitial : (x : ob) → isProp (isInitial x)
isPropIsInitial _ = isPropΠ λ _ → isPropIsContr
open CatIso
-- Objects that are initial are isomorphic.
initialToIso : (x y : Initial) → CatIso C (initialOb x) (initialOb y)
mor (initialToIso x y) = initialArrow x (initialOb y)
inv (initialToIso x y) = initialArrow y (initialOb x)
sec (initialToIso x y) = initialEndoIsId y _
ret (initialToIso x y) = initialEndoIsId x _
open isUnivalent
-- The type of initial objects of a univalent category is a proposition,
-- i.e. all initial objects are equal.
isPropInitial : (hC : isUnivalent C) → isProp Initial
isPropInitial hC x y =
Σ≡Prop isPropIsInitial (CatIsoToPath hC (initialToIso x y))
module _ {C : Category ℓC ℓC'} {D : Category ℓD ℓD'} (F : Functor C D) where
open Category
open Functor
open NaturalBijection
open _⊣_
open _≅_
preservesInitial : Type (ℓ-max (ℓ-max ℓC ℓC') (ℓ-max ℓD ℓD'))
preservesInitial = ∀ (x : ob C) → isInitial C x → isInitial D (F-ob F x)
isLeftAdjoint→preservesInitial : isLeftAdjoint F → preservesInitial
fst (isLeftAdjoint→preservesInitial (G , F⊣G) x initX y) = _♯ F⊣G (fst (initX (F-ob G y)))
snd (isLeftAdjoint→preservesInitial (G , F⊣G) x initX y) ψ =
_♯ F⊣G (fst (initX (F-ob G y)))
≡⟨ cong (F⊣G ♯) (snd (initX (F-ob G y)) (_♭ F⊣G ψ)) ⟩
_♯ F⊣G (_♭ F⊣G ψ)
≡⟨ leftInv (adjIso F⊣G) ψ ⟩
ψ ∎
| {
"alphanum_fraction": 0.6577777778,
"avg_line_length": 31.7647058824,
"ext": "agda",
"hexsha": "a5c06b6a42e24235610d503ff8d1bd9fab2691c8",
"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/Limits/Initial.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/Limits/Initial.agda",
"max_line_length": 92,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Categories/Limits/Initial.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 967,
"size": 2700
} |
{-# OPTIONS --without-K #-}
open import lib.Basics hiding (_⊔_)
open import lib.types.Sigma
open import lib.types.Bool
open import lib.types.Empty
open import Preliminaries
open import Truncation_Level_Criteria
open import Anonymous_Existence_CollSplit
open import Anonymous_Existence_Populatedness
module Anonymous_Existence_Comparison where
-- Chapter 4.3: Comparison of Notions of Existence
-- Section 4.3.1: Inhabited and Merely Inhabited
-- Lemma 4.3.1
coll-family-dec : ∀ {i} {X : Type i} → (x₁ x₂ : X) → ((x : X) → coll (Coprod (x₁ == x) (x₂ == x))) → Coprod (x₁ == x₂) (¬(x₁ == x₂))
coll-family-dec {i} {X} x₁ x₂ coll-fam = solution where
f₋ : (x : X) → Coprod (x₁ == x) (x₂ == x) → Coprod (x₁ == x) (x₂ == x)
f₋ x = fst (coll-fam x)
E₋ : X → Type i
E₋ x = fix (f₋ x)
E : Type i
E = Σ X λ x → (E₋ x)
E-fst-determines-eq : (e₁ e₂ : E) → (fst e₁ == fst e₂) → e₁ == e₂
E-fst-determines-eq e₁ e₂ p = second-comp-triv (λ x → fixed-point (f₋ x) (snd (coll-fam x))) _ _ p
r : Bool → E
r true = x₁ , to-fix (f₋ x₁) (snd (coll-fam x₁)) (inl idp)
r false = x₂ , to-fix (f₋ x₂) (snd (coll-fam x₂)) (inr idp)
about-r : (r true == r false) ↔ (x₁ == x₂)
about-r = (λ p → ap fst p) , (λ p → E-fst-determines-eq _ _ p)
s : E → Bool
s (_ , inl _ , _) = true
s (_ , inr _ , _) = false
s-section-of-r : (e : E) → r(s e) == e
s-section-of-r (x , inl p , q) = E-fst-determines-eq _ _ p
s-section-of-r (x , inr p , q) = E-fst-determines-eq _ _ p
about-s : (e₁ e₂ : E) → (s e₁ == s e₂) ↔ (e₁ == e₂)
about-s e₁ e₂ = one , two where
one : (s e₁ == s e₂) → (e₁ == e₂)
one p =
e₁ =⟨ ! (s-section-of-r e₁) ⟩
r(s(e₁)) =⟨ ap r p ⟩
r(s(e₂)) =⟨ s-section-of-r e₂ ⟩
e₂ ∎
two : (e₁ == e₂) → (s e₁ == s e₂)
two p = ap s p
combine : (s (r true) == s (r false)) ↔ (x₁ == x₂)
combine = (about-s _ _) ◎ about-r
check-bool : Coprod (s (r true) == s (r false)) (¬(s (r true) == s (r false)))
check-bool = Bool-has-dec-eq _ _
solution : Coprod (x₁ == x₂) (¬(x₁ == x₂))
solution with check-bool
solution | inl p = inl (fst combine p)
solution | inr np = inr (λ p → np (snd combine p))
-- definition: "all types have a weakly constant endofunction".
-- this assumption is, if we have ∣∣_∣∣, logically equivalent to saying that
-- every type has split support.
all-coll : ∀ {i} → Type (lsucc i)
all-coll {i} = (X : Type i) → coll X
-- Proposition 4.3.2
all-coll→dec-eq : ∀ {i} → all-coll {i} → (X : Type i) → has-dec-eq X
all-coll→dec-eq all-coll X x₁ x₂ = coll-family-dec x₁ x₂ (λ x → all-coll _)
open with-weak-trunc
open wtrunc
-- Proposition 4.3.3
module functional-subrelation {i : ULevel} (ac : all-coll {i}) (X : Type i) (R : X × X → Type i) where
all-sets : (Y : Type i) → is-set Y
all-sets Y = pathColl→isSet (λ y₁ y₂ → ac _)
R₋ : (x : X) → Type i
R₋ x = Σ X λ y → R(x , y)
k : (x : X) → (R₋ x) → (R₋ x)
k x = fst (ac _)
kc : (x : X) → const (k x)
kc x = snd (ac _)
SS : X × X → Type i
SS (x , y) = Σ (R(x , y)) λ a →
(y , a) == k x (y , a)
-- the relation S
SS₋ : (x : X) → Type i
SS₋ x = Σ X λ y → SS(x , y)
-- fix kₓ is equivalent to Sₓ
-- This is just Σ-assoc. We try to make it more readable by adding some (trivial) steps.
fixk-SS : (x : X) → (fix (k x)) ≃ SS₋ x
fixk-SS x =
(fix (k x)) ≃⟨ ide _ ⟩
(Σ (Σ X λ y → R(x , y)) λ a → a == k x a) ≃⟨ Σ-assoc ⟩
(Σ X λ y → Σ (R(x , y)) λ r → (y , r) == k x (y , r)) ≃⟨ ide _ ⟩
(SS₋ x) ≃∎
-- claim (0)
subrelation : (x y : X) → SS(x , y) → R(x , y)
subrelation x y (r , _) = r
-- claim (1)
prop-SSx : (x : X) → is-prop (SS₋ x)
prop-SSx x = equiv-preserves-level {A = fix (k x)} {B = (SS₋ x)} (fixk-SS x) (fixed-point _ (kc x))
-- claim (2)
same-domain : (x : X) → (R₋ x) ↔ (SS₋ x)
same-domain x = rs , sr where
rs : (R₋ x) → (SS₋ x)
rs a = –> (fixk-SS x) (to-fix (k x) (kc x) a)
sr : (SS₋ x) → (R₋ x)
sr (y , r , _) = y , r
-- claim (3)
prop-SS : (x y : X) → is-prop (SS (x , y))
prop-SS x y = all-paths-is-prop all-paths where
all-paths : (s₁ s₂ : SS(x , y)) → s₁ == s₂
all-paths s₁ s₂ = ss where
yss : (y , s₁) == (y , s₂)
yss = prop-has-all-paths (prop-SSx x) _ _
ss : s₁ == s₂
ss = set-lemma (all-sets _) y s₁ s₂ yss
-- intermediate definition
-- see the caveat about the notion 'epimorphism' in the article
is-split-epimorphism : ∀ {i j} {U : Type i} {V : Type j} → (U → V) → Type (i ⊔ j)
is-split-epimorphism {U = U} {V = V} e = Σ (V → U) λ s → (v : V) → e (s v) == v
is-epimorphism : ∀ {i j} {U : Type i} {V : Type j} → (U → V) → Type (lsucc (i ⊔ j))
is-epimorphism {i} {j} {U = U} {V = V} e = (W : Type (i ⊔ j)) → (f g : V → W) → ((u : U) → f (e u) == g (e u)) → (v : V) → f v == g v
-- Lemma 4.3.4
path-trunc-epi→set : ∀ {i} {Y : Type i} → ((y₁ y₂ : Y) → is-epimorphism (∣_∣ {X = y₁ == y₂})) → is-set Y
path-trunc-epi→set {Y = Y} path-epi = reminder special-case where
f : (y₁ y₂ : Y) → ∣∣ y₁ == y₂ ∣∣ → Y
f y₁ _ _ = y₁
g : (y₁ y₂ : Y) → ∣∣ y₁ == y₂ ∣∣ → Y
g _ y₂ _ = y₂
special-case : (y₁ y₂ : Y) → ∣∣ y₁ == y₂ ∣∣ → y₁ == y₂
special-case y₁ y₂ = path-epi y₁ y₂ Y (f y₁ y₂) (g y₁ y₂) (idf _)
-- we know that hSeparated(X) implies that X is a set,
-- from the previous Proposition 3.1.9;
-- however, we have proved it in such a way which forces
-- us to combine three directions:
reminder : hSeparated Y → is-set Y
reminder = (fst (set-characterisations Y)) ∘ (fst (snd (snd (set-characterisations Y)))) ∘ (snd (snd (snd (snd (set-characterisations Y)))))
-- Proposition 4.3.5 (1)
all-split→all-deceq : ∀ {i} → ((X : Type i) → is-split-epimorphism (∣_∣ {X = X})) → (X : Type i) → has-dec-eq X
all-split→all-deceq {i} all-split = all-coll→dec-eq ac where
ac : (X : Type i) → coll X
ac X = snd coll↔splitSup (fst (all-split X))
-- Proposition 4.3.5 (2)
all-epi→all-set : ∀ {i} → ((X : Type i) → is-epimorphism (∣_∣ {X = X})) → (X : Type i) → is-set X
all-epi→all-set all-epi X = path-trunc-epi→set (λ y₁ y₂ → all-epi (y₁ == y₂))
-- Section 4.3.2: Merely Inhabited and Populated
-- Lemma 4.3.6, first proof
pop-hstable-1 : ∀ {i} {X : Type i} → ⟪ splitSup X ⟫
pop-hstable-1 {X = X} f c = to-fix f c (coll→splitSup (g , gc)) where
g : X → X
g x = f (λ _ → x) ∣ x ∣
gc : const g
gc x₁ x₂ =
g x₁ =⟨ idp ⟩
f (λ _ → x₁) ∣ x₁ ∣ =⟨ ap (λ k → k ∣ x₁ ∣) (c (λ _ → x₁) (λ _ → x₂)) ⟩
f (λ _ → x₂) ∣ x₁ ∣ =⟨ ap (f (λ _ → x₂)) (prop-has-all-paths tr-is-prop ∣ x₁ ∣ ∣ x₂ ∣) ⟩
f (λ _ → x₂) ∣ x₂ ∣ =⟨ idp ⟩
g x₂ ∎
-- Lemma 4.3.6, second proof
pop-hstable-2 : ∀ {i} {X : Type i} → ⟪ splitSup X ⟫
pop-hstable-2 {i} {X} = snd (pop-alt₂ {X = splitSup X}) get-P where
get-P : (P : Type i) → is-prop P → splitSup X ↔ P → P
get-P P pp (hstp , phst) = hstp free-hst where
xp : X → P
xp x = hstp (λ _ → x)
zp : ∣∣ X ∣∣ → P
zp = tr-rec pp xp
free-hst : splitSup X
free-hst z = phst (zp z) z
-- Lemma 4.3.6, third proof
pop-hstable-3 : ∀ {i} {X : Type i} → ⟪ splitSup X ⟫
pop-hstable-3 {X = X} = snd pop-alt translation where
translation-aux : splitSup (splitSup X) → splitSup X
translation-aux = λ hsthst z → hsthst (trunc-functorial {X = X} {Y = splitSup X} (λ x _ → x) z) z
translation : ∣∣ splitSup (splitSup X) ∣∣ → ∣∣ splitSup X ∣∣
translation = trunc-functorial translation-aux
-- Lemma 4.3.7
module tlem437 {i : ULevel} where
One = (X : Type i) → ⟪ X ⟫ → ∣∣ X ∣∣
Two = (X : Type i) → ∣∣ splitSup X ∣∣
Three = (P : Type i) → is-prop P → (Y : P → Type i) → ((p : P) → ∣∣ Y p ∣∣) → ∣∣ ((p : P) → Y p) ∣∣
Four = (X Y : Type i) → (X → Y) → (⟪ X ⟫ → ⟪ Y ⟫)
One→Two : One → Two
One→Two poptr X = poptr (splitSup X) pop-hstable-1
Two→One : Two → One
Two→One trhst X pop = fst pop-alt pop (trhst X)
One→Four : One → Four
One→Four poptr X Y f = Trunc→Pop ∘ (trunc-functorial f) ∘ (poptr X)
Four→One : Four → One
Four→One funct X px = prop-pop tr-is-prop pz where -- (tr-rec _) pz where
pz : ⟪ ∣∣ X ∣∣ ⟫
pz = funct X (∣∣ X ∣∣) ∣_∣ px
-- only very slightly different to the proof in the article
One→Three : One → Three
One→Three poptr P pp Y = λ py → poptr _ (snd pop-alt' (λ hst p₀ → hst (contr-trick p₀ py) p₀)) where
contr-trick : (p₀ : P) → ((p : P) → ∣∣ Y p ∣∣) → ∣∣ ((p : P) → Y p) ∣∣
contr-trick p₀ py = tr-rec {X = Y p₀}
{P = ∣∣ ((p : P) → Y p) ∣∣}
tr-is-prop
(λ y₀ → ∣ (λ p → transport Y (prop-has-all-paths pp p₀ p) y₀) ∣)
(py p₀)
Three→Two : Three → Two
Three→Two proj X = proj (∣∣ X ∣∣) tr-is-prop (λ _ → X) (idf _)
-- Section 4.3.3: Populated and Non-Empty
-- We now need function extensionality. We
-- start with some very simple auxiliary
-- lemmata (not numbered in the thesis).
-- If P is a proposition, so is P + ¬ P
dec-is-prop : ∀ {i} {P : Type i} → is-prop P → is-prop (Coprod P (¬ P))
dec-is-prop {P = P} pp = all-paths-is-prop (λ { (inl p₁) (inl p₂) → ap inl (prop-has-all-paths pp _ _) ;
(inl p₁) (inr np₂) → Empty-elim {P = λ _ → inl p₁ == inr np₂} (np₂ p₁) ;
(inr np₁) (inl p₂) → Empty-elim {P = λ _ → inr np₁ == inl p₂} (np₁ p₂) ;
(inr np₁) (inr np₂) → ap inr (λ= (λ x → prop-has-all-paths Empty-is-prop _ _ )) })
-- Proposition 4.3.8
nonempty-pop→LEM : ∀ {i} → ((X : Type i) → (¬(¬ X) → ⟪ X ⟫)) → LEM {i}
nonempty-pop→LEM {i} nn-pop P pp = from-fix {X = dec} (idf _) (nn-pop dec nndec (idf _) idc) where
dec : Type i
dec = Coprod P (¬ P)
idc : const (idf dec)
idc = λ _ _ → prop-has-all-paths (dec-is-prop {P = P} pp) _ _
nndec : ¬(¬ dec)
nndec ndec = (λ np → ndec (inr np)) λ p → ndec (inl p)
-- Corollary 4.3.9
nonempty-pop↔lem : ∀ {i} → ((X : Type i) → (¬(¬ X) → ⟪ X ⟫)) ↔ LEM {i}
nonempty-pop↔lem {i} = nonempty-pop→LEM , other where
other : LEM {i} → ((X : Type i) → (¬(¬ X) → ⟪ X ⟫))
other lem X nnX = p where
pnp : Coprod ⟪ X ⟫ (¬ ⟪ X ⟫)
pnp = lem ⟪ X ⟫ pop-property₂
p : ⟪ X ⟫
p = match pnp withl idf _ withr (λ np → Empty-elim {P = λ _ → ⟪ X ⟫} (nnX (λ x → np (pop-property₁ x))))
| {
"alphanum_fraction": 0.5145631068,
"avg_line_length": 33.9967320261,
"ext": "agda",
"hexsha": "acdc7af860fe84e87e5b2cc8f86c91e0d874440f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "nicolai/thesis/Anonymous_Existence_Comparison.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "nicolai/thesis/Anonymous_Existence_Comparison.agda",
"max_line_length": 142,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nicolaikraus/HoTT-Agda",
"max_stars_repo_path": "nicolai/thesis/Anonymous_Existence_Comparison.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": 4419,
"size": 10403
} |
module Luau.RuntimeType where
open import Luau.Syntax using (Value; nil; addr; number; bool; string)
data RuntimeType : Set where
function : RuntimeType
number : RuntimeType
nil : RuntimeType
boolean : RuntimeType
string : RuntimeType
valueType : Value → RuntimeType
valueType nil = nil
valueType (addr a) = function
valueType (number n) = number
valueType (bool b) = boolean
valueType (string x) = string
| {
"alphanum_fraction": 0.7494033413,
"avg_line_length": 23.2777777778,
"ext": "agda",
"hexsha": "d585b51b92e090a41869ec67fcad16a9422cb829",
"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": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "XanderYZZ/luau",
"max_forks_repo_path": "prototyping/Luau/RuntimeType.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"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": "XanderYZZ/luau",
"max_issues_repo_path": "prototyping/Luau/RuntimeType.agda",
"max_line_length": 70,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "TheGreatSageEqualToHeaven/luau",
"max_stars_repo_path": "prototyping/Luau/RuntimeType.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-05T21:53:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-12-05T21:53:03.000Z",
"num_tokens": 113,
"size": 419
} |
{-# OPTIONS --allow-unsolved-metas #-}
module automaton-ex where
open import Data.Nat
open import Data.List
open import Data.Maybe
open import Relation.Binary.PropositionalEquality hiding ( [_] )
open import Relation.Binary.Definitions
open import Relation.Nullary using (¬_; Dec; yes; no)
open import logic
open import automaton
open Automaton
data StatesQ : Set where
q1 : StatesQ
q2 : StatesQ
q3 : StatesQ
data In2 : Set where
i0 : In2
i1 : In2
transitionQ : StatesQ → In2 → StatesQ
transitionQ q1 i0 = q1
transitionQ q1 i1 = q2
transitionQ q2 i0 = q3
transitionQ q2 i1 = q2
transitionQ q3 i0 = q2
transitionQ q3 i1 = q2
aendQ : StatesQ → Bool
aendQ q2 = true
aendQ _ = false
a1 : Automaton StatesQ In2
a1 = record {
δ = transitionQ
; aend = aendQ
}
test1 : accept a1 q1 ( i0 ∷ i1 ∷ i0 ∷ [] ) ≡ false
test1 = refl
test2 = accept a1 q1 ( i0 ∷ i1 ∷ i0 ∷ i1 ∷ [] )
test3 = trace a1 q1 ( i0 ∷ i1 ∷ i0 ∷ i1 ∷ [] )
data States1 : Set where
sr : States1
ss : States1
st : States1
transition1 : States1 → In2 → States1
transition1 sr i0 = sr
transition1 sr i1 = ss
transition1 ss i0 = sr
transition1 ss i1 = st
transition1 st i0 = sr
transition1 st i1 = st
fin1 : States1 → Bool
fin1 st = true
fin1 ss = false
fin1 sr = false
am1 : Automaton States1 In2
am1 = record { δ = transition1 ; aend = fin1 }
example1-1 = accept am1 sr ( i0 ∷ i1 ∷ i0 ∷ [] )
example1-2 = accept am1 sr ( i1 ∷ i1 ∷ i1 ∷ [] )
trace-2 = trace am1 sr ( i1 ∷ i1 ∷ i1 ∷ [] )
example1-3 = reachable am1 sr st ( i1 ∷ i1 ∷ i1 ∷ [] )
-- data Dec' (A : Set) : Set where
-- yes' : A → Dec' A
-- no' : ¬ A → Dec' A
--
-- ieq' : (i i' : In2 ) → Dec' ( i ≡ i' )
-- ieq' i0 i0 = yes' refl
-- ieq' i1 i1 = yes' refl
-- ieq' i0 i1 = no' ( λ () )
-- ieq' i1 i0 = no' ( λ () )
ieq : (i i' : In2 ) → Dec ( i ≡ i' )
ieq i0 i0 = yes refl
ieq i1 i1 = yes refl
ieq i0 i1 = no ( λ () )
ieq i1 i0 = no ( λ () )
-- p.83 problem 1.4
--
-- w has at least three i0's and at least two i1's
count-chars : List In2 → In2 → ℕ
count-chars [] _ = 0
count-chars (h ∷ t) x with ieq h x
... | yes y = suc ( count-chars t x )
... | no n = count-chars t x
test11 : count-chars ( i1 ∷ i1 ∷ i0 ∷ [] ) i0 ≡ 1
test11 = refl
ex1_4a : (x : List In2) → Bool
ex1_4a x = ( count-chars x i0 ≥b 3 ) /\ ( count-chars x i1 ≥b 2 )
language' : { Σ : Set } → Set
language' {Σ} = List Σ → Bool
lang14a : language' {In2}
lang14a = ex1_4a
open _∧_
am14a-tr : ℕ ∧ ℕ → In2 → ℕ ∧ ℕ
am14a-tr p i0 = record { proj1 = suc (proj1 p) ; proj2 = proj2 p }
am14a-tr p i1 = record { proj1 = proj1 p ; proj2 = suc (proj2 p) }
am14a : Automaton (ℕ ∧ ℕ) In2
am14a = record { δ = am14a-tr ; aend = λ x → ( proj1 x ≥b 3 ) /\ ( proj2 x ≥b 2 )}
data am14s : Set where
a00 : am14s
a10 : am14s
a20 : am14s
a30 : am14s
a01 : am14s
a11 : am14s
a21 : am14s
a31 : am14s
a02 : am14s
a12 : am14s
a22 : am14s
a32 : am14s
am14a-tr' : am14s → In2 → am14s
am14a-tr' a00 i0 = a10
am14a-tr' _ _ = a10
am14a' : Automaton am14s In2
am14a' = record { δ = am14a-tr' ; aend = λ x → {!!} }
| {
"alphanum_fraction": 0.5863389722,
"avg_line_length": 22.0633802817,
"ext": "agda",
"hexsha": "095fe1021808243ae66d37833159a4cdb5211fad",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/automaton-in-agda",
"max_forks_repo_path": "src/automaton-ex.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/automaton-in-agda",
"max_issues_repo_path": "src/automaton-ex.agda",
"max_line_length": 85,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/automaton-in-agda",
"max_stars_repo_path": "src/automaton-ex.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1352,
"size": 3133
} |
apply :
∀ {a b} {A : Set a} {B : A → Set b} →
((x : A) → B x) → (x : A) → B x
apply f x = f x
syntax apply f x = f x
| {
"alphanum_fraction": 0.4098360656,
"avg_line_length": 17.4285714286,
"ext": "agda",
"hexsha": "3c6091d5f11d52270917bdad916889cc8696e59e",
"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/Issue5201.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/Issue5201.agda",
"max_line_length": 39,
"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/Issue5201.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": 59,
"size": 122
} |
{-# OPTIONS --rewriting --without-K #-}
open import Agda.Primitive
open import Prelude
import GSeTT.Syntax
{- Syntax for a globular type theory, with arbitrary term constructors -}
module Globular-TT.Syntax {l} (index : Set l) where
data Pre-Ty : Set (lsuc l)
data Pre-Tm : Set (lsuc l)
data Pre-Sub : Set (lsuc l)
data Pre-Ctx : Set (lsuc l)
data Pre-Ty where
∗ : Pre-Ty
⇒ : Pre-Ty → Pre-Tm → Pre-Tm → Pre-Ty
data Pre-Tm where
Var : ℕ → Pre-Tm
Tm-constructor : ∀ (i : index) → Pre-Sub → Pre-Tm
data Pre-Sub where
<> : Pre-Sub
<_,_↦_> : Pre-Sub → ℕ → Pre-Tm → Pre-Sub
data Pre-Ctx where
⊘ : Pre-Ctx
_∙_#_ : Pre-Ctx → ℕ → Pre-Ty → Pre-Ctx
C-length : Pre-Ctx → ℕ
C-length ⊘ = O
C-length (Γ ∙ _ # _) = S (C-length Γ)
-- Equality elimination
⇒= : ∀ {A B t t' u u'} → A == B → t == t' → u == u' → ⇒ A t u == ⇒ B t' u'
⇒= idp idp idp = idp
=⇒ : ∀ {A B t t' u u'} → ⇒ A t u == ⇒ B t' u' → ((A == B) × (t == t')) × (u == u')
=⇒ idp = (idp , idp) , idp
Var= : ∀ {v w} → v == w → Var v == Var w
Var= idp = idp
Tm-constructor= : ∀ {i j γ δ} → i == j → γ == δ → (Tm-constructor i γ) == (Tm-constructor j δ)
Tm-constructor= idp idp = idp
=Tm-constructor : ∀ {i j γ δ} → (Tm-constructor i γ) == (Tm-constructor j δ) → i == j × γ == δ
=Tm-constructor idp = idp , idp
<,>= : ∀ {γ δ x y t u} → γ == δ → x == y → t == u → < γ , x ↦ t > == < δ , y ↦ u >
<,>= idp idp idp = idp
=<,> : ∀ {γ δ x y t u} → < γ , x ↦ t > == < δ , y ↦ u > → ((γ == δ) × (x == y)) × (t == u)
=<,> idp = (idp , idp) , idp
∙= : ∀ {Γ Δ x y A B} → Γ == Δ → x == y → A == B → (Γ ∙ x # A) == (Δ ∙ y # B)
∙= idp idp idp = idp
{- Action of substitutions on types and terms and substitutions on a syntactical level -}
_[_]Pre-Ty : Pre-Ty → Pre-Sub → Pre-Ty
_[_]Pre-Tm : Pre-Tm → Pre-Sub → Pre-Tm
_∘_ : Pre-Sub → Pre-Sub → Pre-Sub
∗ [ σ ]Pre-Ty = ∗
⇒ A t u [ σ ]Pre-Ty = ⇒ (A [ σ ]Pre-Ty) (t [ σ ]Pre-Tm) (u [ σ ]Pre-Tm)
Var x [ <> ]Pre-Tm = Var x
Var x [ < σ , v ↦ t > ]Pre-Tm = if x ≡ v then t else ((Var x) [ σ ]Pre-Tm)
Tm-constructor i γ [ σ ]Pre-Tm = Tm-constructor i (γ ∘ σ)
<> ∘ γ = <>
< γ , x ↦ t > ∘ δ = < γ ∘ δ , x ↦ t [ δ ]Pre-Tm >
_#_∈_ : ℕ → Pre-Ty → Pre-Ctx → Set (lsuc l)
_ # _ ∈ ⊘ = ⊥
x # A ∈ (Γ ∙ y # B) = (x # A ∈ Γ) + ((x == y) × (A == B))
{- dimension of types -}
dim : Pre-Ty → ℕ
dim ∗ = O
dim (⇒ A t u) = S (dim A)
dim[] : ∀ (A : Pre-Ty) (γ : Pre-Sub) → dim (A [ γ ]Pre-Ty) == dim A
dim[] ∗ γ = idp
dim[] (⇒ A x x₁) γ = S= (dim[] A γ)
dimC : Pre-Ctx → ℕ
dimC ⊘ = O
dimC (Γ ∙ x # A) = max (dimC Γ) (dim A)
{- Identity and canonical projection -}
Pre-id : ∀ (Γ : Pre-Ctx) → Pre-Sub
Pre-id ⊘ = <>
Pre-id (Γ ∙ x # A) = < Pre-id Γ , x ↦ Var x >
Pre-π : ∀ (Γ : Pre-Ctx) (x : ℕ) (A : Pre-Ty) → Pre-Sub
Pre-π Γ x A = Pre-id Γ
{- Translation of GSeTT to a globular-TT -}
GPre-Ctx : GSeTT.Syntax.Pre-Ctx → Pre-Ctx
GPre-Ty : GSeTT.Syntax.Pre-Ty → Pre-Ty
GPre-Tm : GSeTT.Syntax.Pre-Tm → Pre-Tm
GPre-Ctx nil = ⊘
GPre-Ctx (Γ :: (x , A)) = (GPre-Ctx Γ) ∙ x # (GPre-Ty A)
GPre-Ty GSeTT.Syntax.∗ = ∗
GPre-Ty (GSeTT.Syntax.⇒ A t u) = ⇒ (GPre-Ty A) (GPre-Tm t) (GPre-Tm u)
GPre-Tm (GSeTT.Syntax.Var x) = Var x
{- Depth of a term -}
depth : Pre-Tm → ℕ
depthS : Pre-Sub → ℕ
depth (Var x) = O
depth (Tm-constructor i γ) = S (depthS γ)
depthS <> = O
depthS < γ , x ↦ t > = max (depthS γ) (depth t)
| {
"alphanum_fraction": 0.4879953717,
"avg_line_length": 28.3360655738,
"ext": "agda",
"hexsha": "cbf9f17568abf9ad62bf139eb32a156a00e43c79",
"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": "3a02010a869697f4833c9bc6047d66ca27b87cf2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thibautbenjamin/catt-formalization",
"max_forks_repo_path": "Globular-TT/Syntax.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2",
"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": "thibautbenjamin/catt-formalization",
"max_issues_repo_path": "Globular-TT/Syntax.agda",
"max_line_length": 96,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3a02010a869697f4833c9bc6047d66ca27b87cf2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thibautbenjamin/catt-formalization",
"max_stars_repo_path": "Globular-TT/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1561,
"size": 3457
} |
{-# OPTIONS --without-K --safe #-}
module Cats.Category.Cones where
open import Relation.Binary using (Rel ; IsEquivalence ; _Preserves₂_⟶_⟶_)
open import Level using (_⊔_)
open import Cats.Category.Base
open import Cats.Category.Cat using (Cat)
open import Cats.Category.Fun as Fun using (Fun ; Trans)
open import Cats.Functor using (Functor) renaming (_∘_ to _∘F_)
open import Cats.Util.Conv
import Relation.Binary.PropositionalEquality as ≡
import Cats.Category.Constructions.Iso as Iso
import Cats.Util.Function as Fun
open Functor
open Trans
open Fun._≈_
module Build {lo la l≈ lo′ la′ l≈′}
{J : Category lo la l≈}
{Z : Category lo′ la′ l≈′}
(D : Functor J Z)
where
infixr 9 _∘_
infixr 4 _≈_
private
module Z = Category Z
module J = Category J
module D = Functor D
-- We could define cones in terms of wedges (and limits in terms of ends).
record Cone : Set (lo ⊔ la ⊔ la′ ⊔ lo′ ⊔ l≈′) where
field
Apex : Z.Obj
arr : ∀ j → Apex Z.⇒ D.fobj j
commute : ∀ {i j} (α : i J.⇒ j) → arr j Z.≈ D.fmap α Z.∘ arr i
open Cone public
instance
HasObj-Cone : HasObj Cone lo′ la′ l≈′
HasObj-Cone = record { Cat = Z ; _ᴼ = Cone.Apex }
Obj = Cone
record _⇒_ (A B : Obj) : Set (lo ⊔ la′ ⊔ l≈′) where
private
module A = Cone A ; module B = Cone B
field
arr : A.Apex Z.⇒ B.Apex
commute : ∀ j → B.arr j Z.∘ arr Z.≈ A.arr j
open _⇒_ public
instance
HasArrow-⇒ : ∀ {A B} → HasArrow (A ⇒ B) lo′ la′ l≈′
HasArrow-⇒ = record { Cat = Z ; _⃗ = _⇒_.arr }
_≈_ : ∀ {A B} → Rel (A ⇒ B) l≈′
_≈_ = Z._≈_ Fun.on arr
equiv : ∀ {A B} → IsEquivalence (_≈_ {A} {B})
equiv = Fun.on-isEquivalence _⇒_.arr Z.equiv
id : ∀ {A} → A ⇒ A
id = record
{ arr = Z.id
; commute = λ j → Z.id-r
}
_∘_ : ∀ {A B C} → B ⇒ C → A ⇒ B → A ⇒ C
_∘_ {A} {B} {C} f g = record
{ arr = f ⃗ Z.∘ g ⃗
; commute = λ j →
begin
arr C j Z.∘ f ⃗ Z.∘ g ⃗
≈⟨ Z.unassoc ⟩
(arr C j Z.∘ f ⃗) Z.∘ g ⃗
≈⟨ Z.∘-resp-l (commute f j) ⟩
arr B j Z.∘ g ⃗
≈⟨ commute g j ⟩
arr A j
∎
}
where
open Z.≈-Reasoning
Cones : Category (lo ⊔ la ⊔ lo′ ⊔ la′ ⊔ l≈′) (lo ⊔ la′ ⊔ l≈′) l≈′
Cones = record
{ Obj = Obj
; _⇒_ = _⇒_
; _≈_ = _≈_
; id = id
; _∘_ = _∘_
; equiv = equiv
; ∘-resp = Z.∘-resp
; id-r = Z.id-r
; id-l = Z.id-l
; assoc = Z.assoc
}
open Iso.Build Cones using (_≅_)
open Iso.Build Z using () renaming (_≅_ to _≅Z_)
cone-iso→obj-iso : ∀ {c d : Cone}
→ c ≅ d
→ c ᴼ ≅Z d ᴼ
cone-iso→obj-iso i = record
{ forth = forth i ⃗
; back = back i ⃗
; back-forth = back-forth i
; forth-back = forth-back i
}
where
open _≅_
open Build public hiding (HasObj-Cone ; HasArrow-⇒)
private
open module Build′ {lo la l≈ lo′ la′ l≈′}
{J : Category lo la l≈}
{Z : Category lo′ la′ l≈′}
{D : Functor J Z}
= Build D
public using (HasObj-Cone ; HasArrow-⇒)
-- TODO better name
apFunctor : ∀ {lo la l≈ lo′ la′ l≈′ lo″ la″ l≈″}
→ {Y : Category lo la l≈}
→ {Z : Category lo′ la′ l≈′}
→ (F : Functor Y Z)
→ {J : Category lo″ la″ l≈″}
→ {D : Functor J Y}
→ Cone D
→ Cone (F ∘F D)
apFunctor {Y = Y} {Z} F {J} {D} c = record
{ Apex = fobj F (c .Apex)
; arr = λ j → fmap F (c .arr j)
; commute = λ {i} {j} α → Z.≈.sym (
begin
fmap F (fmap D α) Z.∘ fmap F (c .arr i)
≈⟨ fmap-∘ F ⟩
fmap F (fmap D α Y.∘ c .arr i)
≈⟨ fmap-resp F (Y.≈.sym (c .commute α)) ⟩
fmap F (c .arr j)
∎
)
}
where
module Y = Category Y
module Z = Category Z
open Z.≈-Reasoning
module _ {lo la l≈ lo′ la′ l≈′}
{C : Category lo la l≈} {D : Category lo′ la′ l≈′}
where
module D = Category D
trans : {F G : Functor C D} → Trans F G → Cone F → Cone G
trans {F} {G} θ c = record
{ Apex = c .Apex
; arr = λ j → component θ j D.∘ c .arr j
; commute = λ {i} {j} α →
let open D.≈-Reasoning in
begin
component θ j D.∘ c .arr j
≈⟨ D.∘-resp-r (c .commute α) ⟩
component θ j D.∘ fmap F α D.∘ c .arr i
≈⟨ D.unassoc ⟩
(component θ j D.∘ fmap F α) D.∘ c .arr i
≈⟨ D.∘-resp-l (natural θ) ⟩
(fmap G α D.∘ component θ i) D.∘ c .arr i
≈⟨ D.assoc ⟩
fmap G α D.∘ component θ i D.∘ c .arr i
∎
}
ConesF : Functor (Fun C D) (Cat (lo ⊔ la ⊔ lo′ ⊔ la′ ⊔ l≈′) (lo ⊔ la′ ⊔ l≈′) l≈′)
ConesF = record
{ fobj = Cones
; fmap = λ {F} {G} ϑ → record
{ fobj = λ c → trans ϑ c
; fmap = λ f → record
{ arr = f .arr
; commute = λ j → D.≈.trans D.assoc (D.∘-resp-r (commute f j))
}
; fmap-resp = λ x → x
; fmap-id = D.≈.refl
; fmap-∘ = D.≈.refl
}
; fmap-resp = λ ϑ≈ι → record
{ iso = record
{ forth = record
{ arr = D.id
; commute = λ j → D.≈.trans D.id-r (D.∘-resp-l (D.≈.sym (≈-elim ϑ≈ι)))
}
; back = record
{ arr = D.id
; commute = λ j → D.≈.trans D.id-r (D.∘-resp-l (≈-elim ϑ≈ι))
}
; back-forth = D.id-l
; forth-back = D.id-l
}
; forth-natural = D.≈.trans D.id-l (D.≈.sym D.id-r)
}
; fmap-id = record
{ iso = record
{ forth = record
{ arr = D.id
; commute = λ j → D.≈.trans D.id-r (D.≈.sym D.id-l)
}
; back = record
{ arr = D.id
; commute = λ j → D.≈.trans D.id-r D.id-l
}
; back-forth = D.id-l
; forth-back = D.id-l
}
; forth-natural = D.≈.trans D.id-l (D.≈.sym D.id-r)
}
; fmap-∘ = record
{ iso = record
{ forth = record
{ arr = D.id
; commute = λ j → D.≈.trans D.id-r D.assoc
}
; back = record
{ arr = D.id
; commute = λ j → D.≈.trans D.id-r D.unassoc
}
; back-forth = D.id-l
; forth-back = D.id-l
}
; forth-natural = D.≈.trans D.id-l (D.≈.sym D.id-r)
}
}
| {
"alphanum_fraction": 0.4751211632,
"avg_line_length": 23.536121673,
"ext": "agda",
"hexsha": "92eac4d2c3817831de99849da3381069cd574cdf",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/cats",
"max_forks_repo_path": "Cats/Category/Cones.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"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": "JLimperg/cats",
"max_issues_repo_path": "Cats/Category/Cones.agda",
"max_line_length": 83,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/cats",
"max_stars_repo_path": "Cats/Category/Cones.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z",
"num_tokens": 2493,
"size": 6190
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Ints.QuoInt where
open import Cubical.HITs.Ints.QuoInt.Base public
open import Cubical.HITs.Ints.QuoInt.Properties public
| {
"alphanum_fraction": 0.7743589744,
"avg_line_length": 27.8571428571,
"ext": "agda",
"hexsha": "a4adcafac86b6b3ca0ba6c6c6649d3d06523f57a",
"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/Ints/QuoInt.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/Ints/QuoInt.agda",
"max_line_length": 54,
"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/Ints/QuoInt.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 57,
"size": 195
} |
-- Andreas, 2019-09-13, AIM XXX, test for #4050 by gallais
record Wrap : Set₂ where
field wrapped : Set₁
f : Wrap
f = record { M }
module M where
wrapped : Set₁
wrapped = Set
-- Should be accepted.
| {
"alphanum_fraction": 0.6478873239,
"avg_line_length": 16.3846153846,
"ext": "agda",
"hexsha": "7216db7c3a46653b0ef24f22a1f0d4916843afad",
"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": "c8a3cfa002e77acc5ae1993bae413fde42d4f93b",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "strake/agda",
"max_forks_repo_path": "test/Succeed/Issue4050.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "c8a3cfa002e77acc5ae1993bae413fde42d4f93b",
"max_issues_repo_issues_event_max_datetime": "2020-01-26T18:22:08.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-01-26T18:22:08.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "strake/agda",
"max_issues_repo_path": "test/Succeed/Issue4050.agda",
"max_line_length": 58,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "c8a3cfa002e77acc5ae1993bae413fde42d4f93b",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "strake/agda",
"max_stars_repo_path": "test/Succeed/Issue4050.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": 68,
"size": 213
} |
{-# OPTIONS --safe #-}
module Cubical.Categories.Instances.Sets where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.Properties
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Unit
open import Cubical.Data.Sigma
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
open import Cubical.Categories.NaturalTransformation
open import Cubical.Categories.Limits
open Category
module _ ℓ where
SET : Category (ℓ-suc ℓ) ℓ
ob SET = hSet ℓ
Hom[_,_] SET (A , _) (B , _) = A → B
id SET x = x
_⋆_ SET f g x = g (f x)
⋆IdL SET f = refl
⋆IdR SET f = refl
⋆Assoc SET f g h = refl
isSetHom SET {A} {B} = isSetΠ (λ _ → snd B)
private
variable
ℓ ℓ' : Level
open Functor
-- Hom functors
_[-,_] : (C : Category ℓ ℓ') → (c : C .ob) → Functor (C ^op) (SET ℓ')
(C [-, c ]) .F-ob x = (C [ x , c ]) , C .isSetHom
(C [-, c ]) .F-hom f k = f ⋆⟨ C ⟩ k
(C [-, c ]) .F-id = funExt λ _ → C .⋆IdL _
(C [-, c ]) .F-seq _ _ = funExt λ _ → C .⋆Assoc _ _ _
_[_,-] : (C : Category ℓ ℓ') → (c : C .ob)→ Functor C (SET ℓ')
(C [ c ,-]) .F-ob x = (C [ c , x ]) , C .isSetHom
(C [ c ,-]) .F-hom f k = k ⋆⟨ C ⟩ f
(C [ c ,-]) .F-id = funExt λ _ → C .⋆IdR _
(C [ c ,-]) .F-seq _ _ = funExt λ _ → sym (C .⋆Assoc _ _ _)
module _ {C : Category ℓ ℓ'} {F : Functor C (SET ℓ')} where
open NatTrans
-- natural transformations by pre/post composition
preComp : {x y : C .ob}
→ (f : C [ x , y ])
→ C [ x ,-] ⇒ F
→ C [ y ,-] ⇒ F
preComp f α .N-ob c k = (α ⟦ c ⟧) (f ⋆⟨ C ⟩ k)
preComp f α .N-hom {x = c} {d} k
= (λ l → (α ⟦ d ⟧) (f ⋆⟨ C ⟩ (l ⋆⟨ C ⟩ k)))
≡[ i ]⟨ (λ l → (α ⟦ d ⟧) (⋆Assoc C f l k (~ i))) ⟩
(λ l → (α ⟦ d ⟧) (f ⋆⟨ C ⟩ l ⋆⟨ C ⟩ k))
≡[ i ]⟨ (λ l → (α .N-hom k) i (f ⋆⟨ C ⟩ l)) ⟩
(λ l → (F ⟪ k ⟫) ((α ⟦ c ⟧) (f ⋆⟨ C ⟩ l)))
∎
-- properties
-- TODO: move to own file
open CatIso renaming (inv to cInv)
open Iso
module _ {A B : (SET ℓ) .ob } where
Iso→CatIso : Iso (fst A) (fst B)
→ CatIso (SET ℓ) A B
Iso→CatIso is .mor = is .fun
Iso→CatIso is .cInv = is .inv
Iso→CatIso is .sec = funExt λ b → is .rightInv b -- is .rightInv
Iso→CatIso is .ret = funExt λ b → is .leftInv b -- is .rightInv
CatIso→Iso : CatIso (SET ℓ) A B
→ Iso (fst A) (fst B)
CatIso→Iso cis .fun = cis .mor
CatIso→Iso cis .inv = cis .cInv
CatIso→Iso cis .rightInv = funExt⁻ λ b → cis .sec b
CatIso→Iso cis .leftInv = funExt⁻ λ b → cis .ret b
Iso-Iso-CatIso : Iso (Iso (fst A) (fst B)) (CatIso (SET ℓ) A B)
fun Iso-Iso-CatIso = Iso→CatIso
inv Iso-Iso-CatIso = CatIso→Iso
rightInv Iso-Iso-CatIso b = refl
fun (leftInv Iso-Iso-CatIso a i) = fun a
inv (leftInv Iso-Iso-CatIso a i) = inv a
rightInv (leftInv Iso-Iso-CatIso a i) = rightInv a
leftInv (leftInv Iso-Iso-CatIso a i) = leftInv a
Iso-CatIso-≡ : Iso (CatIso (SET ℓ) A B) (A ≡ B)
Iso-CatIso-≡ = compIso (invIso Iso-Iso-CatIso) (hSet-Iso-Iso-≡ _ _)
-- SET is univalent
isUnivalentSET : isUnivalent {ℓ' = ℓ} (SET _)
isUnivalent.univ isUnivalentSET (A , isSet-A) (B , isSet-B) =
precomposesToId→Equiv
pathToIso _ (funExt w) (isoToIsEquiv Iso-CatIso-≡)
where
w : _
w ci =
invEq
(congEquiv (isoToEquiv (invIso Iso-Iso-CatIso)))
(SetsIso≡-ext isSet-A isSet-B
(λ x i → transp (λ _ → B) i (ci .mor (transp (λ _ → A) i x)))
(λ x i → transp (λ _ → A) i (ci .cInv (transp (λ _ → B) i x))))
-- SET is complete
open LimCone
open Cone
completeSET : ∀ {ℓJ ℓJ'} → Limits {ℓJ} {ℓJ'} (SET (ℓ-max ℓJ ℓJ'))
lim (completeSET J D) = Cone D (Unit* , isOfHLevelLift 2 isSetUnit) , isSetCone D _
coneOut (limCone (completeSET J D)) j e = coneOut e j tt*
coneOutCommutes (limCone (completeSET J D)) j i e = coneOutCommutes e j i tt*
univProp (completeSET J D) c cc =
uniqueExists
(λ x → cone (λ v _ → coneOut cc v x) (λ e i _ → coneOutCommutes cc e i x))
(λ _ → funExt (λ _ → refl))
(λ x → isPropIsConeMor cc (limCone (completeSET J D)) x)
(λ x hx → funExt (λ d → cone≡ λ u → funExt (λ _ → sym (funExt⁻ (hx u) d))))
| {
"alphanum_fraction": 0.5729909653,
"avg_line_length": 32.106870229,
"ext": "agda",
"hexsha": "88fca1f33ef59549b6f8e83533dbf503e0837292",
"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/Instances/Sets.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/Instances/Sets.agda",
"max_line_length": 83,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Categories/Instances/Sets.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z",
"num_tokens": 1740,
"size": 4206
} |
module Inductive.Examples.Empty where
open import Inductive
open import Tuple
open import Data.Fin
open import Data.Product
open import Data.List
open import Data.Vec
⊥ : Set
⊥ = Inductive []
contradiction : {A : Set} → ⊥ → A
contradiction = rec []
| {
"alphanum_fraction": 0.7351778656,
"avg_line_length": 15.8125,
"ext": "agda",
"hexsha": "c149c39f545e1b2ab1ecfa199bcef32219937157",
"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": "dc157acda597a2c758e82b5637e4fd6717ccec3f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mr-ohman/general-induction",
"max_forks_repo_path": "Inductive/Examples/Empty.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dc157acda597a2c758e82b5637e4fd6717ccec3f",
"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": "mr-ohman/general-induction",
"max_issues_repo_path": "Inductive/Examples/Empty.agda",
"max_line_length": 37,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "dc157acda597a2c758e82b5637e4fd6717ccec3f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mr-ohman/general-induction",
"max_stars_repo_path": "Inductive/Examples/Empty.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 73,
"size": 253
} |
module CS410-Prelude where
open import Agda.Primitive
----------------------------------------------------------------------------
-- Zero -- the empty type (logically, a false proposition)
----------------------------------------------------------------------------
data Zero : Set where
magic : forall {l}{A : Set l} -> Zero -> A
magic ()
----------------------------------------------------------------------------
-- One -- the type with one value (logically, a true proposition)
----------------------------------------------------------------------------
record One : Set where
constructor <>
open One public
{-# COMPILED_DATA One () () #-}
----------------------------------------------------------------------------
-- Two -- the type of Boolean values
----------------------------------------------------------------------------
data Two : Set where tt ff : Two
{-# BUILTIN BOOL Two #-}
{-# BUILTIN TRUE tt #-}
{-# BUILTIN FALSE ff #-}
{-# COMPILED_DATA Two Bool True False #-}
-- nondependent conditional with traditional syntax
if_then_else_ : {l : Level}{X : Set l} -> Two -> X -> X -> X
if tt then t else e = t
if ff then t else e = e
-- dependent conditional cooked for partial application
caseTwo : forall {l}{P : Two -> Set l} -> P tt -> P ff -> (b : Two) -> P b
caseTwo t f tt = t
caseTwo t f ff = f
----------------------------------------------------------------------------
-- "Sigma" -- the type of dependent pairs, giving binary products and sums
----------------------------------------------------------------------------
record Sg {l : Level}(S : Set l)(T : S -> Set l) : Set l where
constructor _,_
field
fst : S
snd : T fst
open Sg public
_*_ : {l : Level} -> Set l -> Set l -> Set l
S * T = Sg S \ _ -> T
infixr 4 _,_ _*_
_+_ : Set -> Set -> Set
S + T = Sg Two (caseTwo S T)
pattern inl s = tt , s
pattern inr t = ff , t
----------------------------------------------------------------------------
-- "Equality" -- the type of evidence that things are the same
----------------------------------------------------------------------------
data _==_ {l}{X : Set l}(x : X) : X -> Set l where
refl : x == x
infix 1 _==_
{-# BUILTIN EQUALITY _==_ #-}
{-# BUILTIN REFL refl #-}
sym : forall {l}{X : Set l}{x y : X} -> x == y -> y == x
sym refl = refl
-- this proof principle is useful for proving laws, don't use it for
-- fixing type problems in your programs
postulate ext : forall {l m}{A : Set l}{B : Set m}{f g : A -> B} ->
(forall a -> f a == g a) -> f == g
----------------------------------------------------------------------------
-- functional plumbing
----------------------------------------------------------------------------
id : forall {l}{X : Set l} -> X -> X
id x = x
-- the type of composition can be generalized further
_o_ : forall {l}{X Y Z : Set l} -> (Y -> Z) -> (X -> Y) -> X -> Z
(f o g) x = f (g x)
_$_ : forall{l}{X Y : Set l} -> (X -> Y) -> X -> Y
f $ x = f x
----------------------------------------------------------------------------
-- lists
----------------------------------------------------------------------------
data List (X : Set) : Set where -- X scopes over the whole declaration...
[] : List X -- ...so you can use it here...
_::_ : X -> List X -> List X -- ...and here.
infixr 3 _::_
{-# COMPILED_DATA List [] [] (:) #-}
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _::_ #-}
----------------------------------------------------------------------------
-- chars and strings
----------------------------------------------------------------------------
postulate -- this means that we just suppose the following things exist...
Char : Set
String : Set
{-# BUILTIN CHAR Char #-}
{-# COMPILED_TYPE Char Char #-} -- ...and by the time we reach Haskell...
{-# BUILTIN STRING String #-}
{-# COMPILED_TYPE String String #-} -- ...they *do* exist!
primitive -- these are baked in; they even work!
primCharEquality : Char -> Char -> Two
primStringAppend : String -> String -> String
primStringToList : String -> List Char
primStringFromList : List Char -> String
---------------------------------------------------------------------------
-- COLOURS
---------------------------------------------------------------------------
-- We're going to be making displays from coloured text.
data Colour : Set where
black red green yellow blue magenta cyan white : Colour
{-# COMPILED_DATA Colour HaskellSetup.Colour
HaskellSetup.Black HaskellSetup.Red HaskellSetup.Green
HaskellSetup.Yellow HaskellSetup.Blue HaskellSetup.Magenta
HaskellSetup.Cyan HaskellSetup.White #-}
| {
"alphanum_fraction": 0.4278712977,
"avg_line_length": 32.1438356164,
"ext": "agda",
"hexsha": "5bcbb52a32d28e4dde3a1e4470b1509c008ae967",
"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": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "clarkdm/CS410",
"max_forks_repo_path": "notes/CS410-Prelude.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"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": "clarkdm/CS410",
"max_issues_repo_path": "notes/CS410-Prelude.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "clarkdm/CS410",
"max_stars_repo_path": "notes/CS410-Prelude.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1005,
"size": 4693
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Graph.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
private variable ℓv ℓv' ℓv'' ℓe ℓe' ℓe'' ℓd ℓd' : Level
-- The type of directed multigraphs (with loops)
record Graph ℓv ℓe : Type (ℓ-suc (ℓ-max ℓv ℓe)) where
field
Obj : Type ℓv
Hom : Obj → Obj → Type ℓe
open Graph public
_ᵒᵖ : Graph ℓv ℓe → Graph ℓv ℓe
Obj (G ᵒᵖ) = Obj G
Hom (G ᵒᵖ) x y = Hom G y x
TypeGr : ∀ ℓ → Graph (ℓ-suc ℓ) ℓ
Obj (TypeGr ℓ) = Type ℓ
Hom (TypeGr ℓ) A B = A → B
-- Graph functors/homomorphisms
record GraphHom (G : Graph ℓv ℓe ) (G' : Graph ℓv' ℓe')
: Type (ℓ-suc (ℓ-max (ℓ-max ℓv ℓe) (ℓ-max ℓv' ℓe'))) where
field
_$_ : Obj G → Obj G'
_<$>_ : ∀ {x y : Obj G} → Hom G x y → Hom G' (_$_ x) (_$_ y)
open GraphHom public
GraphGr : ∀ ℓv ℓe → Graph _ _
Obj (GraphGr ℓv ℓe) = Graph ℓv ℓe
Hom (GraphGr ℓv ℓe) G G' = GraphHom G G'
-- Diagrams are (graph) functors with codomain Type
Diag : ∀ ℓd (G : Graph ℓv ℓe) → Type (ℓ-suc (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc ℓd)))
Diag ℓd G = GraphHom G (TypeGr ℓd)
record DiagMor {G : Graph ℓv ℓe} (F : Diag ℓd G) (F' : Diag ℓd' G)
: Type (ℓ-suc (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc (ℓ-max ℓd ℓd')))) where
field
nat : ∀ (x : Obj G) → F $ x → F' $ x
comSq : ∀ {x y : Obj G} (f : Hom G x y) → nat y ∘ F <$> f ≡ F' <$> f ∘ nat x
open DiagMor public
DiagGr : ∀ ℓd (G : Graph ℓv ℓe) → Graph _ _
Obj (DiagGr ℓd G) = Diag ℓd G
Hom (DiagGr ℓd G) = DiagMor
| {
"alphanum_fraction": 0.5893089961,
"avg_line_length": 27.3928571429,
"ext": "agda",
"hexsha": "85a9c84ffeb7ad02ccc5a7c580ed9078aab3baae",
"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/Data/Graph/Base.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Data/Graph/Base.agda",
"max_line_length": 80,
"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/Data/Graph/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 704,
"size": 1534
} |
-- Andreas, 2017-12-16, issue #2871
-- If there is nothing to result-split, introduce trailing hidden args.
-- {-# OPTIONS -v interaction.case:40 #-}
data Fun (A : Set) : Set where
mkFun : (A → A) → Fun A
test : ∀ {A : Set} → Fun A
test = {!!} -- C-c C-x C-h C-c C-c RET
-- Works also with C-c C-c RET
--
-- Expected:
-- test {A} = {!!}
| {
"alphanum_fraction": 0.5710144928,
"avg_line_length": 20.2941176471,
"ext": "agda",
"hexsha": "68153c9631245daedee9c359025244450d441733",
"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/Issue2871.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/Issue2871.agda",
"max_line_length": 71,
"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/Issue2871.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": 117,
"size": 345
} |
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- Delta-observational equivalence - base definitions
------------------------------------------------------------------------
module Base.Change.Equivalence.Base where
open import Relation.Binary.PropositionalEquality
open import Base.Change.Algebra
open import Function
module _ {a} {A : Set a} {{ca : ChangeAlgebra A}} {x : A} where
-- Delta-observational equivalence: these asserts that two changes
-- give the same result when applied to a base value.
-- To avoid unification problems, use a one-field record (a Haskell "newtype")
-- instead of a "type synonym".
record _≙_ (dx dy : Δ x) : Set a where
-- doe = Delta-Observational Equivalence.
constructor doe
field
proof : x ⊞ dx ≡ x ⊞ dy
open _≙_ public
-- Same priority as ≡
infix 4 _≙_
open import Relation.Binary
-- _≙_ is indeed an equivalence relation:
≙-refl : ∀ {dx} → dx ≙ dx
≙-refl = doe refl
≙-sym : ∀ {dx dy} → dx ≙ dy → dy ≙ dx
≙-sym ≙ = doe $ sym $ proof ≙
≙-trans : ∀ {dx dy dz} → dx ≙ dy → dy ≙ dz → dx ≙ dz
≙-trans ≙₁ ≙₂ = doe $ trans (proof ≙₁) (proof ≙₂)
-- That's standard congruence applied to ≙
≙-cong : ∀ {b} {B : Set b}
(f : A → B) {dx dy} → dx ≙ dy → f (x ⊞ dx) ≡ f (x ⊞ dy)
≙-cong f da≙db = cong f $ proof da≙db
≙-isEquivalence : IsEquivalence (_≙_)
≙-isEquivalence = record
{ refl = ≙-refl
; sym = ≙-sym
; trans = ≙-trans
}
≙-setoid : Setoid a a
≙-setoid = record
{ Carrier = Δ x
; _≈_ = _≙_
; isEquivalence = ≙-isEquivalence
}
≙-syntax : ∀ {a} {A : Set a} {{ca : ChangeAlgebra A}} (x : A) (dx₁ dx₂ : Δ x) → Set a
≙-syntax x dx₁ dx₂ = _≙_ {x = x} dx₁ dx₂
syntax ≙-syntax x dx₁ dx₂ = dx₁ ≙₍ x ₎ dx₂
| {
"alphanum_fraction": 0.5420560748,
"avg_line_length": 28.873015873,
"ext": "agda",
"hexsha": "684d6b73d7744fc9211340ce70b39426309b6e9e",
"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": "Base/Change/Equivalence/Base.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": "Base/Change/Equivalence/Base.agda",
"max_line_length": 85,
"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": "Base/Change/Equivalence/Base.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": 637,
"size": 1819
} |
{-# OPTIONS --cubical --safe #-}
module Data.List.Kleene.Membership where
open import Prelude
open import Data.List.Kleene
open import Data.List.Kleene.Relation.Unary
infixr 5 _∈⋆_ _∈⁺_ _∉⋆_ _∉⁺_
_∈⋆_ _∉⋆_ : A → A ⋆ → Type _
x ∈⋆ xs = ◇⋆ (_≡ x) xs
x ∉⋆ xs = ¬ (x ∈⋆ xs)
_∈⁺_ _∉⁺_ : A → A ⁺ → Type _
x ∈⁺ xs = ◇⁺ (_≡ x) xs
x ∉⁺ xs = ¬ (x ∈⁺ xs)
| {
"alphanum_fraction": 0.5558739255,
"avg_line_length": 19.3888888889,
"ext": "agda",
"hexsha": "e9588932180947ca1fa2cdc5625392ad9f45a1dc",
"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/Data/List/Kleene/Membership.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/Data/List/Kleene/Membership.agda",
"max_line_length": 43,
"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/Data/List/Kleene/Membership.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": 187,
"size": 349
} |
open import Data.Product using ( _,_ )
open import FRP.LTL.ISet.Core using ( ISet ; _⇛_ ; mset ; M⟦_⟧ ; ⟦_⟧ ; [_] ; subsumM⟦_⟧ )
open import FRP.LTL.Time.Interval using ( ⊑-refl )
module FRP.LTL.ISet.Stateless where
infixr 2 _⇒_
_⇒_ : ISet → ISet → ISet
A ⇒ B = mset A ⇛ B
-- We could define $ as
-- f $ σ = i→m (λ j j⊑i → f j j⊑i [ subsumM⟦ A ⟧ j i j⊑i σ ])
-- but we inline i→m for efficiency
_$_ : ∀ {A B i} → M⟦ A ⇒ B ⟧ i → M⟦ A ⟧ i → M⟦ B ⟧ i
_$_ {A} {[ B ]} {i} f σ = f i ⊑-refl [ σ ]
_$_ {A} {B ⇛ C} {i} f σ = λ j j⊑i → f j j⊑i [ subsumM⟦ A ⟧ j i j⊑i σ ] | {
"alphanum_fraction": 0.5318021201,
"avg_line_length": 31.4444444444,
"ext": "agda",
"hexsha": "3108637958879ff8d6b952f0647bdcb3196b643b",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:04.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-01T07:33:00.000Z",
"max_forks_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-frp-ltl",
"max_forks_repo_path": "src/FRP/LTL/ISet/Stateless.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_issues_repo_issues_event_max_datetime": "2015-03-02T15:23:53.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-01T07:01:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-frp-ltl",
"max_issues_repo_path": "src/FRP/LTL/ISet/Stateless.agda",
"max_line_length": 89,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-frp-ltl",
"max_stars_repo_path": "src/FRP/LTL/ISet/Stateless.agda",
"max_stars_repo_stars_event_max_datetime": "2020-06-15T02:51:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-02T20:25:05.000Z",
"num_tokens": 287,
"size": 566
} |
{-# OPTIONS --without-K #-}
open import lib.Base
open import lib.PathGroupoid
open import lib.Relation
open import lib.NType
open import lib.types.Empty
module lib.types.Nat where
infixl 80 _+_
_+_ : ℕ → ℕ → ℕ
0 + n = n
(S m) + n = S (m + n)
{-# BUILTIN NATPLUS _+_ #-}
+-unit-r : (m : ℕ) → m + 0 == m
+-unit-r 0 = idp
+-unit-r (S m) = ap S (+-unit-r m)
+-βr : (m n : ℕ) → m + (S n) == S (m + n)
+-βr 0 n = idp
+-βr (S m) n = ap S (+-βr m n)
+-comm : (m n : ℕ) → m + n == n + m
+-comm m 0 = +-unit-r m
+-comm m (S n) = +-βr m n ∙ ap S (+-comm m n)
+-assoc : (k m n : ℕ) → (k + m) + n == k + (m + n)
+-assoc 0 m n = idp
+-assoc (S k) m n = ap S (+-assoc k m n)
infix 120 _*2
_*2 : ℕ → ℕ
O *2 = O
(S n) *2 = S (S (n *2))
ℕ-pred : ℕ → ℕ
ℕ-pred 0 = 0
ℕ-pred (S n) = n
ℕ-S-inj : (n m : ℕ) (p : S n == S m) → n == m
ℕ-S-inj n m p = ap ℕ-pred p
ℕ-S-≠ : ∀ {n m : ℕ} (p : n ≠ m) → S n ≠ S m
ℕ-S-≠ p = p ∘ ℕ-S-inj _ _
private
ℕ-S≠O-type : ℕ → Type₀
ℕ-S≠O-type O = Empty
ℕ-S≠O-type (S n) = Unit
abstract
ℕ-S≠O : (n : ℕ) → S n ≠ O
ℕ-S≠O n p = transport ℕ-S≠O-type p unit
ℕ-O≠S : (n : ℕ) → (O ≠ S n)
ℕ-O≠S n p = ℕ-S≠O n (! p)
ℕ-has-dec-eq : has-dec-eq ℕ
ℕ-has-dec-eq O O = inl idp
ℕ-has-dec-eq O (S n) = inr (ℕ-O≠S n)
ℕ-has-dec-eq (S n) O = inr (ℕ-S≠O n)
ℕ-has-dec-eq (S n) (S m) with ℕ-has-dec-eq n m
ℕ-has-dec-eq (S n) (S m) | inl p = inl (ap S p)
ℕ-has-dec-eq (S n) (S m) | inr p⊥ = inr (λ p → p⊥ (ℕ-S-inj n m p))
ℕ-is-set : is-set ℕ
ℕ-is-set = dec-eq-is-set ℕ-has-dec-eq
ℕ-level = ℕ-is-set
{- Inequalities -}
infix 40 _<_ _≤_
data _<_ : ℕ → ℕ → Type₀ where
ltS : {m : ℕ} → m < (S m)
ltSR : {m n : ℕ} → m < n → m < (S n)
_≤_ : ℕ → ℕ → Type₀
m ≤ n = Coprod (m == n) (m < n)
-- properties of [<]
instance
O<S : (m : ℕ) → O < S m
O<S O = ltS
O<S (S m) = ltSR (O<S m)
O≤ : (m : ℕ) → O ≤ m
O≤ O = inl idp
O≤ (S m) = inr (O<S m)
≮O : ∀ n → ¬ (n < O)
≮O _ ()
<-trans : {m n k : ℕ} → m < n → n < k → m < k
<-trans lt₁ ltS = ltSR lt₁
<-trans lt₁ (ltSR lt₂) = ltSR (<-trans lt₁ lt₂)
≤-refl : {m : ℕ} → m ≤ m
≤-refl = inl idp
≤-trans : {m n k : ℕ} → m ≤ n → n ≤ k → m ≤ k
≤-trans {k = k} (inl p₁) lte₂ = transport (λ t → t ≤ k) (! p₁) lte₂
≤-trans {m = m} lte₁ (inl p₂) = transport (λ t → m ≤ t) p₂ lte₁
≤-trans (inr lt₁) (inr lt₂) = inr (<-trans lt₁ lt₂)
<-ap-S : {m n : ℕ} → m < n → S m < S n
<-ap-S ltS = ltS
<-ap-S (ltSR lt) = ltSR (<-ap-S lt)
≤-ap-S : {m n : ℕ} → m ≤ n → S m ≤ S n
≤-ap-S (inl p) = inl (ap S p)
≤-ap-S (inr lt) = inr (<-ap-S lt)
<-cancel-S : {m n : ℕ} → S m < S n → m < n
<-cancel-S ltS = ltS
<-cancel-S (ltSR lt) = <-trans ltS lt
≤-cancel-S : {m n : ℕ} → S m ≤ S n → m ≤ n
≤-cancel-S (inl p) = inl (ap ℕ-pred p)
≤-cancel-S (inr lt) = inr (<-cancel-S lt)
<-dec : Decidable _<_
<-dec _ O = inr (≮O _)
<-dec O (S m) = inl (O<S m)
<-dec (S n) (S m) with <-dec n m
<-dec (S n) (S m) | inl p = inl (<-ap-S p)
<-dec (S n) (S m) | inr p⊥ = inr (p⊥ ∘ <-cancel-S)
≯-to-≤ : {m n : ℕ} → ¬ (n < m) → m ≤ n
≯-to-≤ {O} {O} _ = inl idp
≯-to-≤ {O} {S n} _ = inr (O<S n)
≯-to-≤ {S m} {O} neggt = ⊥-elim $ neggt (O<S m)
≯-to-≤ {S m} {S n} neggt = ≤-ap-S (≯-to-≤ (neggt ∘ <-ap-S))
<-+-l : {m n : ℕ} (k : ℕ) → m < n → (k + m) < (k + n)
<-+-l O lt = lt
<-+-l (S k) lt = <-ap-S (<-+-l k lt)
≤-+-l : {m n : ℕ} (k : ℕ) → m ≤ n → (k + m) ≤ (k + n)
≤-+-l k (inl p) = inl (ap (λ t → k + t) p)
≤-+-l k (inr lt) = inr (<-+-l k lt)
<-+-r : {m n : ℕ} (k : ℕ) → m < n → (m + k) < (n + k)
<-+-r k ltS = ltS
<-+-r k (ltSR lt) = ltSR (<-+-r k lt)
≤-+-r : {m n : ℕ} (k : ℕ) → m ≤ n → (m + k) ≤ (n + k)
≤-+-r k (inl p) = inl (ap (λ t → t + k) p)
≤-+-r k (inr lt) = inr (<-+-r k lt)
<-witness : {m n : ℕ} → (m < n) → Σ ℕ (λ k → S k + m == n)
<-witness ltS = (O , idp)
<-witness (ltSR lt) = let w' = <-witness lt in (S (fst w') , ap S (snd w'))
≤-witness : {m n : ℕ} → (m ≤ n) → Σ ℕ (λ k → k + m == n)
≤-witness (inl p) = (O , p)
≤-witness (inr lt) = let w' = <-witness lt in (S (fst w') , snd w')
*2-increasing : (m : ℕ) → (m ≤ m *2)
*2-increasing O = inl idp
*2-increasing (S m) = ≤-trans (≤-ap-S (*2-increasing m)) (inr ltS)
*2-monotone-< : {m n : ℕ} → m < n → m *2 < n *2
*2-monotone-< ltS = ltSR ltS
*2-monotone-< (ltSR lt) = ltSR (ltSR (*2-monotone-< lt))
*2-monotone-≤ : {m n : ℕ} → m ≤ n → m *2 ≤ n *2
*2-monotone-≤ (inl p) = inl (ap _*2 p)
*2-monotone-≤ (inr lt) = inr (*2-monotone-< lt)
| {
"alphanum_fraction": 0.4493482735,
"avg_line_length": 25.132183908,
"ext": "agda",
"hexsha": "765f3553f99078cfa7336150c4495cbd8b8b8169",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmknapp/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/Nat.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cmknapp/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/Nat.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmknapp/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/Nat.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2259,
"size": 4373
} |
{-# OPTIONS --safe #-} -- --without-K #-}
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; subst; cong; trans)
open Relation.Binary.PropositionalEquality.≡-Reasoning
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Decidable using (fromWitness)
import Data.Product as Product
import Data.Product.Properties as Productₚ
import Data.Unit as Unit
import Data.Nat as ℕ
import Data.Vec as Vec
import Data.Fin as Fin
import Data.Vec.Relation.Unary.All as All
open Unit using (⊤; tt)
open ℕ using (ℕ; zero; suc)
open Vec using (Vec; []; _∷_)
open All using (All; []; _∷_)
open Fin using (Fin ; zero ; suc)
open Product using (Σ-syntax; _×_; _,_; proj₁; proj₂)
open import PiCalculus.Syntax
open Scoped
open import PiCalculus.Semantics
open import PiCalculus.Semantics.Properties
open import PiCalculus.LinearTypeSystem.Algebras
module PiCalculus.LinearTypeSystem.SubjectCongruence (Ω : Algebras) where
open Algebras Ω
open import PiCalculus.LinearTypeSystem Ω
open import PiCalculus.LinearTypeSystem.ContextLemmas Ω
open import PiCalculus.LinearTypeSystem.Framing Ω
open import PiCalculus.LinearTypeSystem.Weakening Ω
open import PiCalculus.LinearTypeSystem.Strengthening Ω
open import PiCalculus.LinearTypeSystem.Exchange Ω
SubjectCongruence : Set
SubjectCongruence = {n : ℕ} {γ : PreCtx n} {idxs : Idxs n} {Γ Δ : Ctx idxs}
→ {r : RecTree} {P Q : Scoped n}
→ P ≅⟨ r ⟩ Q
→ γ ; Γ ⊢ P ▹ Δ
→ γ ; Γ ⊢ Q ▹ Δ
private
variable
n : ℕ
P Q : Scoped n
comp-comm : {γ : PreCtx n} {idxs : Idxs n} {Γ Ξ : Ctx idxs}
→ γ ; Γ ⊢ P ∥ Q ▹ Ξ
→ γ ; Γ ⊢ Q ∥ P ▹ Ξ
comp-comm (⊢P ∥ ⊢Q) with ⊢-⊗ ⊢P | ⊢-⊗ ⊢Q
comp-comm (⊢P ∥ ⊢Q) | _ , P≔ | _ , Q≔ =
let _ , (Q'≔ , P'≔) = ⊗-assoc (⊗-comm P≔) Q≔ in
⊢-frame Q≔ Q'≔ ⊢Q ∥ ⊢-frame P≔ (⊗-comm P'≔) ⊢P
subject-cong : SubjectCongruence
subject-cong (stop comp-assoc) (⊢P ∥ (⊢Q ∥ ⊢R)) = (⊢P ∥ ⊢Q) ∥ ⊢R
subject-cong (stop comp-symm) (⊢P ∥ ⊢Q) = comp-comm (⊢P ∥ ⊢Q)
subject-cong (stop comp-end) (⊢P ∥ 𝟘) = ⊢P
subject-cong (stop scope-end) (ν t c ._ 𝟘) = 𝟘
subject-cong (stop (scope-ext u)) (ν t c μ (_∥_ {Δ = _ -, _} ⊢P ⊢Q)) rewrite sym (⊢-unused _ u ⊢P) = ⊢-strengthen zero u ⊢P ∥ ν t c μ ⊢Q
subject-cong (stop scope-scope-comm) (ν t c μ (ν t₁ c₁ μ₁ ⊢P)) = ν t₁ c₁ μ₁ (ν t c μ (⊢-exchange zero ⊢P))
subject-cong (cong-symm (stop comp-assoc)) ((⊢P ∥ ⊢Q) ∥ ⊢R) = ⊢P ∥ (⊢Q ∥ ⊢R)
subject-cong (cong-symm (stop comp-symm)) (⊢P ∥ ⊢Q) = comp-comm (⊢P ∥ ⊢Q)
subject-cong (cong-symm (stop comp-end)) ⊢P = ⊢P ∥ 𝟘
subject-cong (cong-symm (stop scope-end)) 𝟘 = ν 𝟙 {∃Idx} (0∙ , 0∙) {∃Idx} 0∙ 𝟘
subject-cong (cong-symm (stop (scope-ext u))) (⊢P ∥ (ν t c μ ⊢Q)) = ν t c μ ((subst (λ ● → _ ; _ ⊢ ● ▹ _) (lift-lower zero _ u) (⊢-weaken zero ⊢P)) ∥ ⊢Q)
subject-cong (cong-symm (stop scope-scope-comm)) (ν t c μ (ν t₁ c₁ μ₁ ⊢P)) = ν _ _ _ (ν _ _ _ (subst (λ ● → _ ; _ ⊢ ● ▹ _) (exchange-exchange zero _) (⊢-exchange zero ⊢P)))
-- Equivalence and congruence
subject-cong cong-refl ⊢P = ⊢P
subject-cong (cong-trans P≅Q Q≅R) ⊢P = subject-cong Q≅R (subject-cong P≅Q ⊢P)
subject-cong (ν-cong P≅Q) (ν t m μ ⊢P) = ν t m μ (subject-cong P≅Q ⊢P)
subject-cong (comp-cong P≅Q) (⊢P ∥ ⊢R) = subject-cong P≅Q ⊢P ∥ ⊢R
subject-cong (input-cong P≅Q) (x ⦅⦆ ⊢P) = x ⦅⦆ subject-cong P≅Q ⊢P
subject-cong (output-cong P≅Q) (x ⟨ y ⟩ ⊢P) = x ⟨ y ⟩ subject-cong P≅Q ⊢P
subject-cong (cong-symm cong-refl) ⊢P = ⊢P
subject-cong (cong-symm (cong-symm P≅Q)) ⊢P = subject-cong P≅Q ⊢P
subject-cong (cong-symm cong-trans P≅Q P≅R) ⊢P = subject-cong (cong-symm P≅Q) (subject-cong (cong-symm P≅R) ⊢P)
subject-cong (cong-symm (ν-cong P≅Q)) (ν t m μ ⊢P) = ν t m μ (subject-cong (cong-symm P≅Q) ⊢P)
subject-cong (cong-symm (comp-cong P≅Q)) (⊢P ∥ ⊢R) = subject-cong (cong-symm P≅Q) ⊢P ∥ ⊢R
subject-cong (cong-symm (input-cong P≅Q)) (x ⦅⦆ ⊢P) = x ⦅⦆ subject-cong (cong-symm P≅Q) ⊢P
subject-cong (cong-symm (output-cong P≅Q)) (x ⟨ y ⟩ ⊢P) = x ⟨ y ⟩ subject-cong (cong-symm P≅Q) ⊢P
| {
"alphanum_fraction": 0.626503006,
"avg_line_length": 45.8850574713,
"ext": "agda",
"hexsha": "274fd120855d4882b6fcee0a115478c2a13f5697",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T16:24:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-25T13:57:13.000Z",
"max_forks_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guilhermehas/typing-linear-pi",
"max_forks_repo_path": "src/PiCalculus/LinearTypeSystem/SubjectCongruence.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_issues_repo_issues_event_max_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "guilhermehas/typing-linear-pi",
"max_issues_repo_path": "src/PiCalculus/LinearTypeSystem/SubjectCongruence.agda",
"max_line_length": 172,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guilhermehas/typing-linear-pi",
"max_stars_repo_path": "src/PiCalculus/LinearTypeSystem/SubjectCongruence.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-14T15:18:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-02T23:32:11.000Z",
"num_tokens": 1763,
"size": 3992
} |
-- We can let Agda infer the parameters of the constructor target
data List (A : Set) : Set where
nil : List _
cons : A → List A → List _
-- 2017-01-12, Andreas: we can even omit the whole target
-- (for parameterized data types, but not inductive families)
data Bool : Set where
true false : _
data Maybe (A : Set) : Set where
nothing : _
just : (x : A) → _
| {
"alphanum_fraction": 0.6604278075,
"avg_line_length": 23.375,
"ext": "agda",
"hexsha": "cb88ee1f0007354de506a4f1f99c4b6b541afaeb",
"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/UnderscoresAsDataParam.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/UnderscoresAsDataParam.agda",
"max_line_length": 65,
"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/UnderscoresAsDataParam.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": 110,
"size": 374
} |
{-
This module converts between the path equality
and the inductively define equality types.
- _≡c_ stands for "c"ubical equality.
- _≡p_ stands for "p"ropositional equality.
TODO: reconsider naming scheme.
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Equality where
open import Cubical.Foundations.Prelude
renaming ( _≡_ to _≡c_ ; refl to reflc )
public
open import Agda.Builtin.Equality
renaming ( _≡_ to _≡p_ ; refl to reflp )
public
open import Cubical.Foundations.Isomorphism
private
variable
ℓ : Level
A : Type ℓ
x y z : A
ptoc : x ≡p y → x ≡c y
ptoc reflp = reflc
ctop : x ≡c y → x ≡p y
ctop p = transport (cong (λ u → _ ≡p u) p) reflp
ptoc-ctop : (p : x ≡c y) → ptoc (ctop p) ≡c p
ptoc-ctop p =
J (λ _ h → ptoc (ctop h) ≡c h) (cong ptoc (transportRefl reflp)) p
ctop-ptoc : (p : x ≡p y) → ctop (ptoc p) ≡c p
ctop-ptoc {x = x} reflp = transportRefl reflp
p≅c : {x y : A} → Iso (x ≡c y) (x ≡p y)
p≅c = iso ctop ptoc ctop-ptoc ptoc-ctop
p-c : {x y : A} → (x ≡c y) ≡c (x ≡p y)
p-c = isoToPath p≅c
p=c : {x y : A} → (x ≡c y) ≡p (x ≡p y)
p=c = ctop p-c
| {
"alphanum_fraction": 0.6295964126,
"avg_line_length": 21.862745098,
"ext": "agda",
"hexsha": "783fef24a4942bfb889019b9422718c9474e87e8",
"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/Data/Equality.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/Data/Equality.agda",
"max_line_length": 68,
"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/Data/Equality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 472,
"size": 1115
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use the
-- Relation.Binary.Reasoning.Preorder module directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Relation.Binary.PreorderReasoning
{p₁ p₂ p₃} (P : Preorder p₁ p₂ p₃) where
open import Relation.Binary.Reasoning.Preorder P public
| {
"alphanum_fraction": 0.5182926829,
"avg_line_length": 30.75,
"ext": "agda",
"hexsha": "f253284275c8c23dc5e7f2d79b6ee9cc0bd79e2e",
"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/Relation/Binary/PreorderReasoning.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/PreorderReasoning.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/Relation/Binary/PreorderReasoning.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 92,
"size": 492
} |
{-# OPTIONS --without-K --safe #-}
open import Polynomial.Parameters
-- Here, we provide proofs of homomorphism between the operations
-- defined on polynomials and those on the underlying ring.
module Polynomial.Homomorphism
{c r₁ r₂ r₃}
(homo : Homomorphism c r₁ r₂ r₃)
where
-- The lemmas are the general-purpose proofs we reuse in each other section
open import Polynomial.Homomorphism.Lemmas homo using (pow-cong) public
-- Proofs which deal with variables and constants
open import Polynomial.Homomorphism.Semantics homo using (κ-hom; ι-hom) public
-- Proofs for each operation
open import Polynomial.Homomorphism.Addition homo using (⊞-hom) public
open import Polynomial.Homomorphism.Multiplication homo using (⊠-hom) public
open import Polynomial.Homomorphism.Negation homo using (⊟-hom) public
open import Polynomial.Homomorphism.Exponentiation homo using (⊡-hom) public
| {
"alphanum_fraction": 0.7655398037,
"avg_line_length": 38.2083333333,
"ext": "agda",
"hexsha": "5595a436536e5a449944e676f242a8e60cc2b891",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-20T07:07:11.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-04-16T02:23:16.000Z",
"max_forks_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mckeankylej/agda-ring-solver",
"max_forks_repo_path": "src/Polynomial/Homomorphism.agda",
"max_issues_count": 5,
"max_issues_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T01:55:42.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-17T20:48:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mckeankylej/agda-ring-solver",
"max_issues_repo_path": "src/Polynomial/Homomorphism.agda",
"max_line_length": 83,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mckeankylej/agda-ring-solver",
"max_stars_repo_path": "src/Polynomial/Homomorphism.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-15T00:57:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-25T16:40:52.000Z",
"num_tokens": 240,
"size": 917
} |
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Data.Queue.Finite where
open import Cubical.Foundations.Everything
open import Cubical.Foundations.SIP
open import Cubical.Structures.Queue
open import Cubical.Data.Maybe
open import Cubical.Data.List
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Data.Queue.1List
-- All finite queues are equal to 1List.Finite
private
variable
ℓ : Level
module _ (A : Type ℓ) (Aset : isSet A) where
open Queues-on A Aset
private
module One = 1List A Aset
open One renaming (Q to Q₁; emp to emp₁; enq to enq₁; deq to deq₁)
isContrFiniteQueue : isContr FiniteQueue
isContrFiniteQueue .fst = One.Finite
isContrFiniteQueue .snd (Q , (S@(emp , enq , deq) , _ , deq-emp , deq-enq , _) , fin) =
sip finiteQueueUnivalentStr _ _ ((f , fin) , f∘emp , f∘enq , sym ∘ f∘deq)
where
deq₁-enq₁ = str One.WithLaws .snd .snd .snd .fst
f : Q₁ → Q
f = foldr enq emp
f∘emp : f emp₁ ≡ emp
f∘emp = refl
f∘enq : ∀ a xs → f (enq₁ a xs) ≡ enq a (f xs)
f∘enq _ _ = refl
fA : Q₁ × A → Q × A
fA (q , a) = (f q , a)
f∘returnOrEnq : (x : A) (xsr : Maybe (List A × A)) →
returnOrEnq S x (deqMap f xsr) ≡ fA (returnOrEnq (str One.Raw) x xsr)
f∘returnOrEnq _ nothing = refl
f∘returnOrEnq _ (just _) = refl
f∘deq : ∀ xs → deq (f xs) ≡ deqMap f (deq₁ xs)
f∘deq [] = deq-emp
f∘deq (x ∷ xs) =
deq-enq x (f xs)
∙ cong (just ∘ returnOrEnq S x) (f∘deq xs)
∙ cong just (f∘returnOrEnq x (deq₁ xs))
∙ cong (deqMap f) (sym (deq₁-enq₁ x xs))
| {
"alphanum_fraction": 0.6410098522,
"avg_line_length": 27.5254237288,
"ext": "agda",
"hexsha": "13adbe0d4f9f6eb3628535a033a5b93fbdc4085b",
"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/Data/Queue/Finite.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/Data/Queue/Finite.agda",
"max_line_length": 88,
"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/Data/Queue/Finite.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 637,
"size": 1624
} |
-- Andreas, 2015-05-28 example by Andrea Vezzosi
open import Common.Size
data Nat (i : Size) : Set where
zero : ∀ {j : Size< i} → Nat i
suc : ∀ {j : Size< i} → Nat j → Nat i
{-# TERMINATING #-}
-- This definition is fine, the termination checker is too strict at the moment.
fix : ∀ {C : Size → Set}
→ (∀{i} → (∀ {j : Size< i} → Nat j -> C j) → Nat i → C i)
→ ∀{i} → Nat i → C i
fix t zero = t (fix t) zero
fix t (suc n) = t (fix t) (suc n)
case : ∀ {i} {C : Set} (n : Nat i) (z : C) (s : ∀ {j : Size< i} → Nat j → C) → C
case zero z s = z
case (suc n) z s = s n
applyfix : ∀ {C : Size → Set} {i} (n : Nat i)
→ (∀{i} → (∀ {j : Size< i} → Nat j -> C j) → Nat i → C i)
→ C i
applyfix n f = fix f n
module M (i0 : Size) (bot : ∀{i} → Nat i) (A : Set) (default : A) where
loops : A
loops = applyfix (zero {i = ↑ i0}) λ {i} r _ →
case {i} bot default λ n → -- Size< i is possibly empty, should be rejected
case n default λ _ →
r zero
-- loops
-- --> fix t zero
-- --> t (fix t) zero
-- --> case bot default λ n → case n default λ _ → fix t zero
-- and we have reproduced (modulo sizes) what we started with
| {
"alphanum_fraction": 0.5218135158,
"avg_line_length": 29.9743589744,
"ext": "agda",
"hexsha": "771bdff63cc9a2bef1f95eede68517d052b11a57",
"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/Fail/Issue1523a.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/Fail/Issue1523a.agda",
"max_line_length": 83,
"max_stars_count": 3,
"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/Issue1523a.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": 449,
"size": 1169
} |
----------------------------------------------------------------------
-- Copyright: 2013, Jan Stolarek, Lodz University of Technology --
-- --
-- License: See LICENSE file in root of the repo --
-- Repo address: https://github.com/jstolarek/dep-typed-wbl-heaps --
-- --
-- Weight biased leftist heap that proves to maintain priority --
-- invariant: priority at the node is not lower than priorities of --
-- its two children. Uses a two-pass merging algorithm. --
----------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module TwoPassMerge.PriorityProof where
open import Basics.Nat renaming (_≥_ to _≥ℕ_)
open import Basics
open import Sized
-- Priority invariant says that: for any node in the tree priority in
-- that node is higher than priority stored by its children. This
-- means that any path from root to leaf is ordered (highest priority
-- at the root, lowest at the leaf). This property allows us to
-- construct an efficient merging operation (see paper for more
-- details).
--
-- To prove this invariant we will index nodes using Priority. Index
-- of value n says that "this heap can store elements with priorities
-- n or lower" (remember that lower priority means larger Nat). In
-- other words Heap indexed with 0 can store any Priority, while Heap
-- indexed with 3 can store priorities 3, 4 and lower, but can't store
-- 0, 1 and 2.
--
-- As previously, Heap has two constructors:
--
-- 1) empty returns Heap n, where index n is not constrained in any
-- way. This means that empty heap can be given any restriction on
-- priorities of stored elements.
--
-- 2) node also creates Heap n, but this time n is constrained. If we
-- store priority p in a node then:
-- a) the resulting heap can only be restricted to store
-- priorities at least as high as p. For example, if we
-- create a node that stores priority 3 we cannot restrict
-- the resulting heap to store priorities 4 and lower,
-- because the fact that we store 3 in that node violates the
-- restriction. This restriction is expressed by the "p ≥ n"
-- parameter: if we can construct a value of type (p ≥ n)
-- then existance of such a value becomes a proof that p is
-- greater-equal to n. We must supply such proof to every
-- node.
-- b) children of a node can only be restricted to store
-- priorities that are not higher than p. Example: if we
-- restrict a node to store priorities 4 and lower we cannot
-- restrict its children to store priorities 3 and
-- higher. This restriction is expressed by index "p" in the
-- subheaps passed to node constructor.
data Heap : {i : Size} → Priority → Set where
empty : {i : Size} {n : Priority} → Heap {↑ i} n
node : {i : Size} {n : Priority} → (p : Priority) → Rank → p ≥ n →
Heap {i} p → Heap {i} p → Heap {↑ i} n
-- Let's demonstrate that priority invariant cannot be broken. Below
-- we construct a heap like this:
--
-- ?
-- / \
-- / \
-- E 0
--
-- where E means empty node and 0 means node storing Priority 0 (yes,
-- this heap violates the rank invariant!). We left out the root
-- element. The only value that can be supplied there is zero (try
-- giving one and see that typechecker will not accept it). This is
-- beacuse the value n with which 0 node can be index must obey the
-- restriction 0 ≥ n. This means that 0 node can only be indexed with
-- 0. When we try to construct ? node we are thus only allowed to
-- insert priority 0.
heap-broken : Heap zero
heap-broken = node {!!} (suc one) ge0 empty (node zero one ge0 empty empty)
-- Here is a correct heap. It stores one at the leaf and 0 at the
-- root. It still violates the rank invariant - we deal with that in
-- TwoPassMerge.RankProof.
heap-correct : Heap zero
heap-correct = node zero (suc one) ge0 empty (node one one ge0 empty empty)
-- Again, we need a function to extract rank from a node
rank : {b : Priority} → Heap b → Rank
rank empty = zero
rank (node _ r _ _ _) = r
-- The first question is how to create a singleton heap, ie. a Heap
-- storing one element. The question we need to answer is "what
-- Priorities can we later store in a singleton Heap?". "Any" seems to
-- be a reasonable answer. This means the resulting Heap will be
-- indexed with zero, meaning "Priorities lower or equal to zero can
-- be stored in this Heap" (remember that any priority is lower or
-- equal to zero). This leads us to following definition:
singleton : (p : Priority) → Heap zero
singleton p = node p one ge0 empty empty
-- We can imagine we would like to limit the range of priorities we
-- can insert into a singleton Heap. This means the resulting Heap
-- would be index with some b (the bound on allowed Priority
-- values). In such case however we are required to supply a proof
-- that p ≥ b. This would lead us to a definition like this:
--
-- singletonB : {b : Priority} → (p : Priority) → p ≥ b → Heap b
-- singletonB p p≥b = node p one p≥b empty empty
--
-- We'll return to that idea soon.
-- makeT now returns indexed heaps, so it requires one more parameter:
-- a proof that priorities stored in resulting heap are not lower than
-- in the subheaps.
makeT : {b : Nat} → (p : Priority) → p ≥ b → Heap p → Heap p → Heap b
makeT p p≥b l r with rank l ≥ℕ rank r
makeT p p≥b l r | true = node p (suc (rank l + rank r)) p≥b l r
makeT p p≥b l r | false = node p (suc (rank l + rank r)) p≥b r l
-- The important change in merge is that now we don't compare node
-- priorities using an operator that returns Bool. We compare them
-- using "order" function that not only returns result of comparison,
-- but also supplies a proof of the result. This proof tells us
-- something important about the relationship between p1, p2 and
-- priority bound of the merged Heap. Note that we use the new proof
-- to reconstruct one of the heaps that is passed in recursive call to
-- merge. We must do this because by comparing priorities p1 and p2 we
-- learned something new about restriction placed on priorities in one
-- of the heaps and we can now be more precise in expressing these
-- restrictions.
--
-- Note also that despite indexing our data types with Size the
-- termination checker complains that merge function does not
-- terminate. This is not a problem in our definitions but a bug in
-- Agda's implementation. I leave the code in this form in hope that
-- this bug will be fixed in a future release of Agda. For mor details
-- see http://code.google.com/p/agda/issues/detail?id=59#c23
merge : {i j : Size} {p : Nat} → Heap {i} p → Heap {j} p → Heap p
merge empty h2 = h2
merge h1 empty = h1
merge .{↑ i} .{↑ j}
(node {i} p1 l-rank p1≥p l1 r1)
(node {j} p2 r-rank p2≥p l2 r2)
with order p1 p2
merge .{↑ i} .{↑ j}
(node {i} p1 l-rank p1≥p l1 r1)
(node {j} p2 r-rank p2≥p l2 r2)
| le p1≤p2
= makeT p1 p1≥p l1 (merge {i} {↑ j} r1 (node p2 r-rank p1≤p2 l2 r2))
merge .{↑ i} .{↑ j}
(node {i} p1 l-rank p1≥p l1 r1)
(node {j} p2 r-rank p2≥p l2 r2)
| ge p1≥p2
= makeT p2 p2≥p l2 (merge {↑ i} {j} (node p1 l-rank p1≥p2 l1 r1) r2)
-- When writing indexed insert function we once again have to answer a
-- question of how to index input and output Heap. The easiest
-- solution is to be liberal: let us require that the input and output
-- Heap have no limitations on Priorities they can store. In other
-- words, let they be indexed by zero:
insert : Priority → Heap zero → Heap zero
insert p h = merge (singleton p) h
-- Now we can create an example heap. The only difference between this
-- heap and the heap without any proofs is that we need to explicitly
-- instantiate implicit Priority parameter of empty constructor.
heap : Heap zero
heap = insert (suc (suc zero))
(insert (suc zero)
(insert zero
(insert (suc (suc (suc zero))) (empty {n = zero}))))
-- But what if we want to insert into a heap that is not indexed with
-- 0? One solution is to be liberal and ``promote'' that heap so that
-- after insertion it can store elements with any priorities:
toZero : {b : Priority} → Heap b → Heap zero
toZero empty = empty
toZero (node p rank _ l r) = node p rank ge0 l r
insert0 : {b : Priority} → Priority → Heap b → Heap zero
insert0 p h = merge (singleton p) (toZero h)
-- But what if we actaully want to maintain bounds imposed on the heap
-- by its index? To achieve that we need a new singleton function that
-- constructs a singleton Heap with a bound equal to priority of a
-- single element stored by the heap. To construct a proof required by
-- node we use ≥sym, which proves that if p ≡ p then p ≥ p.
singletonB : (p : Priority) → Heap p
singletonB p = node p one (≥sym refl) empty empty
-- We can now write new insert function that uses singletonB function:
insertB : (p : Priority) → Heap p → Heap p
insertB p h = merge (singletonB p) h
-- However, that function is pretty much useless - it can insert
-- element with priority p only to a heap that has p as its bound. In
-- other words if we have Heap zero - ie. a heap that can store any
-- possible priority -- the only thing that we can insert into it
-- using insertB function is zero. That's clearly not what we want. We
-- need a way to manipulate resulting priority bound.
-- Let's try again. This time we will write functions with signatures:
--
-- singletonB' : {b : Priority} → (p : Priority) → p ≥ b → Heap b
-- insertB' : {b : Priority} → (p : Priority) → p ≥ b → Heap p → Heap b
--
-- Singleton allows to construct Heap containing priority p but
-- bounded by b. This of course requires proof that p ≥ b, ie. that
-- priority p can actually be stored in Heap b. insertB' is similar -
-- it can insert element of priority p into Heap bounded by p but the
-- resulting Heap can be bounded by b (provided that p ≥ b, for which
-- we must supply evidence). Let's implement that.
-- Implementing singletonB' is straightforward:
singletonB' : {b : Priority} → (p : Priority) → p ≥ b → Heap b
singletonB' p p≥b = node p one p≥b empty empty
-- To implement insertB' we need two additional functions. Firstly, we
-- need a proof of transitivity of ≥. We proceed by induction on
-- c. Our base case is:
--
-- a ≥ b ∧ b ≥ 0 ⇒ a ≥ 0
--
-- In other words if c is 0 then ge0 proves the property. If c is not
-- zero, then b is also not zero (by definitions of data constructors
-- of ≥) and hence a is also not zero. This gives us second equation
-- that is a recursive proof on ≥trans.
≥trans : {a b c : Nat} → a ≥ b → b ≥ c → a ≥ c
≥trans a≥b ge0 = ge0
≥trans (geS a≥b) (geS b≥c) = geS (≥trans a≥b b≥c)
-- Having proved the transitivity of ≥ we can construct a function
-- that loosens the bound we put on a heap. If we have a heap with a
-- bound p - meaning that all priorities in a heap are guaranteed to
-- be lower than or equal to p - and we also have evidence than n is a
-- priority higher than p then we can change the restriction on the
-- heap so that it accepts higher priorites. For example if we have
-- Heap 5, ie. all elements in the heap are 5 or greater, and we have
-- evidence that 5 ≥ 3, then we can convert Heap 5 to Heap 3. Note how
-- we are prevented from writing wrong code: if we have Heap 3 we
-- cannot convert it to Heap 5. This is not possible from theoretical
-- point of view: Heap 3 may contain 4, but Heap 5 is expected to
-- contain elements not smaller than 5. It is also not possible
-- practically: thanks to our definition of ≥ we can't orivide
-- evidence that 3 ≥ 5 because we cannot construct value of that type.
liftBound : {p b : Priority} → b ≥ p → Heap b → Heap p
liftBound b≥n empty = empty
liftBound b≥n (node p rank p≥b l r)
= node p rank (≥trans p≥b b≥n) l r
-- With singletonB and liftBound we can construct insert function that
-- allows to insert element with priority p into a Heap bound by b,
-- but only if we can supply evidence that p ≥ b, ie. that p can
-- actually be stored in the heap.
insertB' : {b : Priority} → (p : Priority) → p ≥ b → Heap p → Heap b
insertB' p p≥b h = merge (singletonB' p p≥b) (liftBound p≥b h)
-- But if we try to create an example Heap as we did previously we
-- quickly discover that this function isn't of much use either:
heap' : Heap zero
heap' = insertB' (suc (suc zero)) {!!}
(insertB' (suc zero) {!!}
(insertB' zero {!!}
(insertB' (suc (suc (suc zero))) {!!} (empty))))
-- In third hole we are required to supply evidence that 0 ≥ 1 and
-- that is not possible. The reason is that our insertB' function
-- allows us only to insert elements into a heap in decreasing order:
heap'' : Heap zero
heap'' = insertB' zero ge0
(insertB' (suc zero) ge0
(insertB' (suc (suc zero)) (geS ge0)
(insertB' (suc (suc (suc zero))) (geS (geS ge0)) (empty))))
-- This is a direct consequence of our requirement that priority of
-- element being inserted and bound on the Heap we insert into match.
-- Again, findMin and deletMin are incomplete
findMin : {b : Priority} → Heap b → Priority
findMin empty = {!!}
findMin (node p _ _ _ _) = p
-- deleteMin requires a bit more work than previously. First, notice
-- that the bound placed on the input and output heaps is the
-- same. This happens because relation between priorities in a node
-- and it's children is ≥, not > (ie. equality is allowed). We cannot
-- therefore guearantee that bound on priority will increase after
-- removing highest-priority element from the Heap. When we merge
-- left and right subtrees we need to lift their bounds so they are
-- now both b (not p).
deleteMin : {b : Priority} → Heap b → Heap b
deleteMin empty = {!!}
deleteMin (node p rank p≥b l r) = merge (liftBound p≥b l) (liftBound p≥b r)
| {
"alphanum_fraction": 0.673540745,
"avg_line_length": 47.3445945946,
"ext": "agda",
"hexsha": "5cf928c8679ea6e33a1350c4d73fb3f5a0b99895",
"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": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_forks_repo_path": "src/TwoPassMerge/PriorityProof.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"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": "jstolarek/dep-typed-wbl-heaps",
"max_issues_repo_path": "src/TwoPassMerge/PriorityProof.agda",
"max_line_length": 75,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_stars_repo_path": "src/TwoPassMerge/PriorityProof.agda",
"max_stars_repo_stars_event_max_datetime": "2018-05-02T21:48:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-02T21:48:43.000Z",
"num_tokens": 3820,
"size": 14014
} |
import cedille-options
open import general-util
module meta-vars (options : cedille-options.options) {mF : Set → Set} ⦃ _ : monad mF ⦄ where
open import cedille-types
open import constants
open import conversion
open import ctxt
open import free-vars
open import rename
open import spans options {mF}
open import subst
open import syntax-util
open import to-string options
-- misc
----------------------------------------------------------------------
-- Meta-variables, prototypes, decorated types
-- ==================================================
record meta-var-sol (A : Set) : Set where
constructor mk-meta-var-sol
field
sol : A
src : checking-mode
data meta-var-sort : Set where
meta-var-tp : (k : kind) → (mtp : maybe $ meta-var-sol type) → meta-var-sort
meta-var-tm : (tp : type) → (mtm : maybe $ meta-var-sol term) → meta-var-sort
record meta-var : Set where
constructor meta-var-mk
field
name : string
sort : meta-var-sort
loc : span-location
open meta-var
pattern meta-var-mk-tp x k mtp l = meta-var-mk x (meta-var-tp k mtp) l
record meta-vars : Set where
constructor meta-vars-mk
field
order : 𝕃 var
varset : trie meta-var
open meta-vars
data prototype : Set where
proto-maybe : maybe type → prototype
proto-arrow : erased? → prototype → prototype
data decortype : Set where
decor-type : type → decortype
decor-arrow : erased? → type → decortype → decortype
decor-decor : erased? → var → tpkd → meta-var-sort → decortype → decortype
decor-stuck : type → prototype → decortype
decor-error : type → prototype → decortype
-- Simple definitions and accessors
-- --------------------------------------------------
meta-var-name : meta-var → var
meta-var-name X = meta-var.name X
meta-vars-get-varlist : meta-vars → 𝕃 var
meta-vars-get-varlist Xs = map (name ∘ snd) (trie-mappings (varset Xs))
meta-var-solved? : meta-var → 𝔹
meta-var-solved? (meta-var-mk n (meta-var-tp k nothing) _) = ff
meta-var-solved? (meta-var-mk n (meta-var-tp k (just _)) _) = tt
meta-var-solved? (meta-var-mk n (meta-var-tm tp nothing) _) = ff
meta-var-solved? (meta-var-mk n (meta-var-tm tp (just _)) _) = tt
meta-vars-empty : meta-vars
meta-vars-empty = meta-vars-mk [] empty-trie
meta-vars-empty? : meta-vars → 𝔹
meta-vars-empty? Xs = ~ (trie-nonempty (varset Xs ))
meta-vars-solved? : meta-vars → 𝔹
meta-vars-solved? Xs = trie-all meta-var-solved? (varset Xs)
meta-vars-filter : (meta-var → 𝔹) → meta-vars → meta-vars
meta-vars-filter f Xs =
meta-vars-mk or vs
where
vs = trie-filter f (varset Xs)
or = filter (trie-contains vs) (order Xs)
meta-var-sort-eq? : ctxt → (=S =T : meta-var-sort) → 𝔹
meta-var-sort-eq? Γ (meta-var-tp k₁ mtp₁) (meta-var-tp k₂ mtp₂)
with conv-kind Γ k₁ k₂
... | ff = ff
... | tt =
maybe-equal? sol-eq mtp₁ mtp₂
where
sol-eq : (sol₁ sol₂ : meta-var-sol type) → 𝔹
sol-eq (mk-meta-var-sol sol₁ src) (mk-meta-var-sol sol₂ src₁) =
conv-type Γ sol₁ sol₂
meta-var-sort-eq? _ _ _ = ff
-- TODO terms not supported
-- meta-var-sol-eq? (meta-var-tm tp mtm) (meta-var-tm tp₁ mtm₁) = {!!}
meta-var-equal? : ctxt → (X Y : meta-var) → 𝔹
meta-var-equal? Γ (meta-var-mk name₁ sol₁ _) (meta-var-mk name₂ sol₂ _) =
name₁ =string name₂ && meta-var-sort-eq? Γ sol₁ sol₂
meta-vars-equal? : ctxt → (Xs Ys : meta-vars) → 𝔹
meta-vars-equal? Γ Xs Ys =
trie-equal? (meta-var-equal? Γ) (meta-vars.varset Xs) (meta-vars.varset Ys)
meta-vars-lookup : meta-vars → var → maybe meta-var
meta-vars-lookup Xs x = trie-lookup (varset Xs) x
meta-vars-lookup-with-kind : meta-vars → var → maybe (meta-var × kind)
meta-vars-lookup-with-kind Xs x
with meta-vars-lookup Xs x
... | nothing = nothing
... | (just X@(meta-var-mk-tp _ k _ _)) = just $ X , k
... | (just X) = nothing
meta-var-set-src : meta-var → checking-mode → meta-var
meta-var-set-src (meta-var-mk-tp name₁ k (just sol) loc₁) m =
meta-var-mk-tp name₁ k (just (record sol { src = m })) loc₁
meta-var-set-src (meta-var-mk-tp name₁ k nothing loc₁) m =
meta-var-mk-tp name₁ k nothing loc₁
meta-var-set-src (meta-var-mk name₁ (meta-var-tm tp (just sol)) loc₁) m =
meta-var-mk name₁ (meta-var-tm tp (just (record sol { src = m }))) loc₁
meta-var-set-src (meta-var-mk name₁ (meta-var-tm tp nothing) loc₁) m
= meta-var-mk name₁ (meta-var-tm tp nothing) loc₁
meta-vars-lookup-kind : meta-vars → var → maybe kind
meta-vars-lookup-kind Xs x with meta-vars-lookup Xs x
... | nothing = nothing
... | (just (meta-var-mk-tp _ k _ _)) = just k
... | (just X) = nothing
-- conversion to types, terms, tks
-- --------------------------------------------------
meta-var-sort-to-tk : meta-var-sort → tpkd
meta-var-sort-to-tk (meta-var-tp k mtp) = Tkk k
meta-var-sort-to-tk (meta-var-tm tp mtm) = Tkt tp
meta-var-to-type : meta-var → maybe type
meta-var-to-type (meta-var-mk-tp x k (just tp) _) = just (meta-var-sol.sol tp)
meta-var-to-type (meta-var-mk-tp x k nothing _) = just (TpVar x)
meta-var-to-type (meta-var-mk x (meta-var-tm tp mtm) _) = nothing
meta-var-to-term : meta-var → maybe term
meta-var-to-term (meta-var-mk-tp x k mtp _) = nothing
meta-var-to-term (meta-var-mk x (meta-var-tm tp (just tm)) _) = just (meta-var-sol.sol tm)
meta-var-to-term (meta-var-mk x (meta-var-tm tp nothing) _) = just (Var x)
meta-var-to-type-unsafe : meta-var → type
meta-var-to-type-unsafe X
with meta-var-to-type X
... | just tp = tp
... | nothing = TpVar (meta-var-name X)
meta-var-to-term-unsafe : meta-var → term
meta-var-to-term-unsafe X
with meta-var-to-term X
... | just tm = tm
... | nothing = Var (meta-var-name X)
-- if all meta-vars are solved, return their solutions as args
meta-vars-to-args : meta-vars → maybe args
meta-vars-to-args (meta-vars-mk or vs) =
flip 𝕃maybe-map or λ x → trie-lookup vs x ≫=maybe λ where
(meta-var-mk name (meta-var-tm tp tm?) loc) →
tm? >>= just ∘' ArgEr ∘' meta-var-sol.sol
(meta-var-mk name (meta-var-tp kd tp?) loc) →
tp? >>= just ∘' ArgTp ∘' meta-var-sol.sol
prototype-to-maybe : prototype → maybe type
prototype-to-maybe (proto-maybe mtp) = mtp
prototype-to-maybe (proto-arrow _ _) = nothing
prototype-to-checking : prototype → checking-mode
prototype-to-checking = maybe-to-checking ∘ prototype-to-maybe
decortype-to-type : decortype → type
decortype-to-type (decor-type tp) = tp
decortype-to-type (decor-arrow at tp dt) =
TpArrow tp at (decortype-to-type dt)
decortype-to-type (decor-decor b x tk sol dt) =
TpAbs b x tk (decortype-to-type dt)
decortype-to-type (decor-stuck tp pt) = tp
decortype-to-type (decor-error tp pt) = tp
-- hnf for decortype
-- --------------------------------------------------
hnf-decortype : ctxt → unfolding → decortype → (is-head : 𝔹) → decortype
hnf-decortype Γ uf (decor-type tp) ish =
decor-type (hnf Γ (record uf {unfold-defs = ish}) tp)
hnf-decortype Γ uf (decor-arrow e? tp dt) ish =
decor-arrow e? (hnf Γ (record uf {unfold-defs = ff}) tp) (hnf-decortype Γ uf dt ff)
hnf-decortype Γ uf (decor-decor e? x tk sol dt) ish =
decor-decor e? x tk sol (hnf-decortype Γ uf dt ff)
hnf-decortype Γ uf dt@(decor-stuck _ _) ish = dt
hnf-decortype Γ uf (decor-error tp pt) ish =
decor-error (hnf Γ (record uf {unfold-defs = ff}) tp) pt
-- substitutions
-- --------------------------------------------------
substh-meta-var-sort : substh-ret-t meta-var-sort
substh-meta-var-sort Γ ρ σ (meta-var-tp k mtp) =
meta-var-tp (substh Γ ρ σ k) ((flip maybe-map) mtp λ sol →
record sol { sol = substh Γ ρ σ (meta-var-sol.sol sol) })
substh-meta-var-sort Γ ρ σ (meta-var-tm tp mtm) =
meta-var-tm (substh Γ ρ σ tp) (flip maybe-map mtm λ sol →
record sol { sol = substh Γ ρ σ (meta-var-sol.sol sol) })
subst-meta-var-sort : subst-ret-t meta-var-sort
subst-meta-var-sort Γ t x (meta-var-tp k mtp) =
meta-var-tp (subst Γ t x k) $ (flip maybe-map) mtp λ sol →
record sol { sol = subst Γ t x $ meta-var-sol.sol sol }
subst-meta-var-sort Γ t x (meta-var-tm tp mtm) =
meta-var-tm (subst Γ t x tp) $ (flip maybe-map) mtm λ where
(mk-meta-var-sol sol src) → mk-meta-var-sol (subst Γ t x sol) src
meta-vars-get-sub : meta-vars → trie (Σi exprd ⟦_⟧)
meta-vars-get-sub Xs =
trie-catMaybe (trie-map (maybe-map ,_ ∘ meta-var-to-type) (varset Xs))
meta-vars-subst-type' : (unfold : 𝔹) → ctxt → meta-vars → type → type
meta-vars-subst-type' u Γ Xs tp =
let tp' = substs Γ (meta-vars-get-sub Xs) tp in
if u then hnf Γ unfold-head-elab tp' else tp'
meta-vars-subst-type : ctxt → meta-vars → type → type
meta-vars-subst-type = meta-vars-subst-type' tt
meta-vars-subst-kind : ctxt → meta-vars → kind → kind
meta-vars-subst-kind Γ Xs k
= hnf Γ unfold-head-elab (substh Γ empty-renamectxt (meta-vars-get-sub Xs) k)
-- string and span helpers
-- --------------------------------------------------
meta-var-to-string : meta-var → strM
meta-var-to-string (meta-var-mk-tp name k nothing sl)
= strMetaVar name sl
>>str strAdd " : " >>str to-stringe k
meta-var-to-string (meta-var-mk-tp name k (just tp) sl)
= strMetaVar name sl
>>str strAdd " : " >>str to-stringe k
>>str strAdd " = " >>str to-stringe (meta-var-sol.sol tp) -- tp
meta-var-to-string (meta-var-mk name (meta-var-tm tp nothing) sl)
= strMetaVar name sl
>>str strAdd " : " >>str to-stringe tp
meta-var-to-string (meta-var-mk name (meta-var-tm tp (just tm)) sl)
= strMetaVar name sl
>>str strAdd " : " >>str to-stringe tp
>>str strAdd " = " >>str to-stringe (meta-var-sol.sol tm) -- tm
meta-vars-to-stringe : 𝕃 meta-var → strM
meta-vars-to-stringe []
= strEmpty
meta-vars-to-stringe (v :: [])
= meta-var-to-string v
meta-vars-to-stringe (v :: vs)
= meta-var-to-string v >>str strAdd ", " >>str meta-vars-to-stringe vs
meta-vars-to-string : meta-vars → strM
meta-vars-to-string Xs =
meta-vars-to-stringe
((flip map) (order Xs) λ x →
case trie-lookup (varset Xs) x of λ where
nothing →
meta-var-mk
(x ^ "-missing!") (meta-var-tp KdStar nothing)
missing-span-location
(just X) → X)
prototype-to-string : prototype → strM
prototype-to-string (proto-maybe nothing) = strAdd "⁇"
prototype-to-string (proto-maybe (just tp)) = to-stringe tp
prototype-to-string (proto-arrow e? pt) =
strAdd "⁇" >>str strAdd (arrowtype-to-string e?)
>>str prototype-to-string pt
decortype-to-string : decortype → strM
decortype-to-string (decor-type tp) =
strAdd "[" >>str to-stringe tp >>str strAdd "]"
decortype-to-string (decor-arrow e? tp dt) =
to-stringe tp
>>str strAdd (arrowtype-to-string e?)
>>str decortype-to-string dt
decortype-to-string (decor-decor e? x tk sol dt) =
strAdd (binder e? sol) >>str meta-var-to-string (meta-var-mk x sol missing-span-location)
>>str strAdd "<" >>str tpkd-to-stringe tk >>str strAdd ">" >>str strAdd " . " >>str decortype-to-string dt
where
binder : erased? → meta-var-sort → string
binder Erased sol = "∀ "
binder Pi (meta-var-tm tp mtm) = "Π "
-- vv clause below "shouldn't" happen
binder Pi (meta-var-tp k mtp) = "∀ "
decortype-to-string (decor-stuck tp pt) =
strAdd "(" >>str to-stringe tp >>str strAdd " , " >>str prototype-to-string pt >>str strAdd ")"
decortype-to-string (decor-error tp pt) =
strAdd "([" >>str (to-stringe tp) >>str strAdd "] ‼ " >>str prototype-to-string pt >>str strAdd ")"
meta-vars-data-h : ctxt → string → kind ∨ (meta-var-sol type) → tagged-val
meta-vars-data-h Γ X (inj₁ k) =
strRunTag "meta-vars-intro" Γ
(strAdd (unqual-local X ^ " ") >>str to-stringe k)
meta-vars-data-h Γ X (inj₂ sol) =
strRunTag "meta-vars-sol" Γ $
strAdd (unqual-local X ^ " ") >>str
strAdd (checking-to-string (meta-var-sol.src sol) ^ " ") >>str
(to-stringe ∘ meta-var-sol.sol $ sol)
meta-vars-data-all : ctxt → meta-vars → 𝕃 tagged-val
meta-vars-data-all Γ = foldr
(uncurry λ where
_ (meta-var-mk X (meta-var-tp kd nothing) loc) xs →
meta-vars-data-h Γ X (inj₁ kd) :: xs
_ (meta-var-mk X (meta-var-tp kd (just tp)) loc) xs →
meta-vars-data-h Γ X (inj₁ kd)
:: meta-vars-data-h Γ X (inj₂ tp) :: xs
_ _ xs → xs)
[] ∘ (trie-mappings ∘ meta-vars.varset)
meta-vars-intro-data : ctxt → meta-vars → 𝕃 tagged-val
meta-vars-intro-data Γ = map (h ∘ snd) ∘ (trie-mappings ∘ meta-vars.varset)
where
h : meta-var → tagged-val
h (meta-var-mk X (meta-var-tp kd mtp) loc) = meta-vars-data-h Γ X (inj₁ kd)
h (meta-var-mk X (meta-var-tm tp mtm) loc) =
meta-vars-data-h Γ X
(inj₂ (mk-meta-var-sol (TpVar "unimplemented") untyped))
meta-vars-sol-data : ctxt → meta-vars → meta-vars → 𝕃 tagged-val
meta-vars-sol-data Γ Xsₒ Xsₙ = foldr (λ X xs → maybe-else xs (_:: xs) (h (snd X)))
[] (trie-mappings (meta-vars.varset Xsₙ))
where
h : meta-var → maybe tagged-val
h (meta-var-mk X (meta-var-tp kd (just tp)) loc) with trie-lookup (meta-vars.varset Xsₒ) X
...| just (meta-var-mk _ (meta-var-tp _ (just _)) _) = nothing
...| _ = just (meta-vars-data-h Γ X (inj₂ tp)
)
h (meta-var-mk X (meta-var-tp kd nothing) loc) = nothing
h (meta-var-mk X (meta-var-tm tp mtm) loc) =
just (meta-vars-data-h Γ X
(inj₂ (mk-meta-var-sol (TpVar "unimplemented") untyped)))
meta-vars-check-type-mismatch : ctxt → string → type → meta-vars → type
→ 𝕃 tagged-val × err-m
meta-vars-check-type-mismatch Γ s tp Xs tp'
= (expected-type Γ tp :: [ type-data Γ tp'' ]) ,
(if conv-type Γ tp tp''
then nothing
else just ("The expected type does not match the "
^ s ^ " type."))
where tp'' = meta-vars-subst-type' ff Γ Xs tp'
meta-vars-check-type-mismatch-if : maybe type → ctxt → string → meta-vars
→ type → 𝕃 tagged-val × err-m
meta-vars-check-type-mismatch-if (just tp) Γ s Xs tp'
= meta-vars-check-type-mismatch Γ s tp Xs tp'
meta-vars-check-type-mismatch-if nothing Γ s Xs tp'
= [ type-data Γ tp″ ] , nothing
where
tp″ = meta-vars-subst-type' ff Γ Xs tp'
decortype-data : ctxt → decortype → tagged-val
decortype-data Γ dt = strRunTag "head decoration" Γ (decortype-to-string dt)
prototype-data : ctxt → prototype → tagged-val
prototype-data Γ pt = strRunTag "head prototype" Γ (prototype-to-string pt)
-- collecting, merging, matching
-- --------------------------------------------------
meta-var-fresh-t : (S : Set) → Set
meta-var-fresh-t S = meta-vars → var → span-location → S → meta-var
meta-var-fresh : meta-var-fresh-t meta-var-sort
meta-var-fresh Xs x sl sol
with fresh-h (trie-contains (varset Xs)) (meta-var-pfx-str ^ x)
... | x' = meta-var-mk x' sol sl
meta-var-fresh-tp : meta-var-fresh-t (kind × maybe (meta-var-sol type))
meta-var-fresh-tp Xs x sl (k , msol) =
meta-var-fresh Xs x sl (meta-var-tp k msol)
meta-var-fresh-tm : meta-var-fresh-t (type × maybe (meta-var-sol term))
meta-var-fresh-tm Xs x sl (tp , mtm) = meta-var-fresh Xs x sl (meta-var-tm tp mtm)
private
meta-vars-set : meta-vars → meta-var → meta-vars
meta-vars-set Xs X = record Xs { varset = trie-insert (varset Xs) (name X) X }
-- add a meta-var
meta-vars-add : meta-vars → meta-var → meta-vars
meta-vars-add Xs X
= record (meta-vars-set Xs X) { order = (order Xs) ++ [ name X ] }
meta-vars-add* : meta-vars → 𝕃 meta-var → meta-vars
meta-vars-add* Xs [] = Xs
meta-vars-add* Xs (Y :: Ys) = meta-vars-add* (meta-vars-add Xs Y) Ys
meta-vars-from-list : 𝕃 meta-var → meta-vars
meta-vars-from-list Xs = meta-vars-add* meta-vars-empty Xs
meta-vars-remove : meta-vars → meta-var → meta-vars
meta-vars-remove (meta-vars-mk or vs) X =
let x = meta-var-name X
in meta-vars-mk (remove _=string_ x or) (trie-remove vs x)
meta-vars-in-type : meta-vars → type → meta-vars
meta-vars-in-type Xs tp =
let xs = free-vars tp in
meta-vars-filter (stringset-contains xs ∘ name) Xs
meta-vars-unsolved : meta-vars → meta-vars
meta-vars-unsolved = meta-vars-filter λ where
(meta-var-mk x (meta-var-tp k mtp) _) → ~ isJust mtp
(meta-var-mk x (meta-var-tm tp mtm) _) → ~ isJust mtm
meta-vars-are-free-in-type : meta-vars → type → 𝔹
meta-vars-are-free-in-type Xs tp =
let xs = free-vars tp in
list-any (stringset-contains xs) (order Xs)
-- Unfolding a type with meta-vars
-- ==================================================
-- ... in order to reveal a term or type application
-- "View" data structures
-- --------------------------------------------------
-- The decorated type is really an arrow
record is-tmabsd : Set where
constructor mk-tmabsd
field
is-tmabsd-dt : decortype
is-tmabsd-e? : erased?
is-tmabsd-var : var
is-tmabsd-dom : type
is-tmabsd-var-in-body : 𝔹
is-tmabsd-cod : decortype
open is-tmabsd public
is-tmabsd? = decortype ∨ is-tmabsd
pattern yes-tmabsd dt e? x dom occ cod = inj₂ (mk-tmabsd dt e? x dom occ cod)
pattern not-tmabsd tp = inj₁ tp
record is-tpabsd : Set where
constructor mk-tpabsd
field
is-tpabsd-dt : decortype
is-tpabsd-e? : erased?
is-tpabsd-var : var
is-tpabsd-kind : kind
is-tpabsd-sol : maybe type
is-tpabsd-body : decortype
open is-tpabsd public
is-tpabsd? = decortype ∨ is-tpabsd
pattern yes-tpabsd dt e? x k mtp dt' = inj₂ (mk-tpabsd dt e? x k mtp dt')
pattern not-tpabsd dt = inj₁ dt
{-# TERMINATING #-}
num-arrows-in-type : ctxt → type → ℕ
num-arrows-in-type Γ tp = nait Γ (hnf' Γ tp) 0 tt
where
hnf' : ctxt → type → type
hnf' Γ tp = hnf Γ unfold-head-elab tp
nait : ctxt → type → (acc : ℕ) → 𝔹 → ℕ
-- definitely another arrow
nait Γ (TpAbs _ _ (Tkk _) tp) acc uf = nait Γ tp acc ff
nait Γ (TpAbs _ _ (Tkt _) tp) acc uf = nait Γ tp (1 + acc) ff
-- definitely not another arrow
nait Γ (TpIota _ _ _) acc uf = acc
nait Γ (TpEq _ _) acc uf = acc
nait Γ (TpHole _) acc uf = acc
nait Γ (TpLam _ _ _) acc uf = acc
nait Γ (TpVar x) acc tt = acc
nait Γ (TpApp tp₁ tp₂) acc tt = acc
nait Γ tp acc ff = nait Γ (hnf' Γ tp) acc tt
-- Utilities for match-types in classify.agda
-- ==================================================
--
-- Match a type with meta-variables in it to one without
-- errors
-- --------------------------------------------------
match-error-data = string × 𝕃 tagged-val
match-error-t : ∀ {a} → Set a → Set a
match-error-t A = match-error-data ∨ A
pattern match-error e = inj₁ e
pattern match-ok a = inj₂ a
module meta-vars-match-errors where
-- boilerplate
match-error-msg = "Matching failed"
-- tagged values for error messages
match-lhs : {ed : exprd} → ctxt → ⟦ ed ⟧ → tagged-val
match-lhs = to-string-tag "expected lhs"
match-rhs : {ed : exprd} → ctxt → ⟦ ed ⟧ → tagged-val
match-rhs = to-string-tag "computed rhs"
the-meta-var : var → tagged-val
the-meta-var = strRunTag "the meta-var" empty-ctxt ∘ strAdd
the-solution : ctxt → type → tagged-val
the-solution = to-string-tag "the solution"
fst-snd-sol : {ed : exprd} → ctxt → (t₁ t₂ : ⟦ ed ⟧) → 𝕃 tagged-val
fst-snd-sol Γ t₁ t₂ =
to-string-tag "first solution" Γ t₁ :: [ to-string-tag "second solution" Γ t₂ ]
lhs-rhs : {ed : exprd} → ctxt → (t₁ t₂ : ⟦ ed ⟧) → 𝕃 tagged-val
lhs-rhs Γ t₁ t₂ = match-lhs Γ t₁ :: [ match-rhs Γ t₂ ]
-- error-data
e-solution-ineq : ctxt → (tp₁ tp₂ : type) → var → match-error-data
e-solution-ineq Γ tp₁ tp₂ X =
match-error-msg ^ " because it produced two incovertible solutions for a meta-variable"
, the-meta-var X :: fst-snd-sol Γ tp₁ tp₂
e-match-failure : match-error-data
e-match-failure =
"The expected argument type is not a (first-order) match of the computed type"
, []
e-matchk-failure : match-error-data
e-matchk-failure =
"The expected argument kind is not a (first-order) match of the computed kind"
, []
e-meta-scope : ctxt → (X tp : type) → match-error-data
-- e-meta-scope : ctxt → (x : var) → (tp₁ tp₂ : type) → match-error-data
e-meta-scope Γ X tp =
match-error-msg ^ " because the solution contains a bound variable of the computed argument type"
, to-string-tag "the meta var" Γ X :: [ to-string-tag "the solution" Γ tp ]
e-bad-sol-kind : ctxt → (X : var) → (sol : type) → match-error-data
e-bad-sol-kind Γ X sol =
"The meta-variable was matched to a type whose kind does not match its own"
, the-meta-var X :: [ the-solution Γ sol ]
open meta-vars-match-errors
-- meta-vars-match auxiliaries
-- --------------------------------------------------
local-vars = stringset
meta-vars-solve-tp : ctxt → meta-vars → var → type → checking-mode → match-error-t meta-vars
meta-vars-solve-tp Γ Xs x tp m with trie-lookup (varset Xs) x
... | nothing
= match-error $ x ^ " is not a meta-var!" , []
... | just (meta-var-mk _ (meta-var-tm tp' mtm) _)
= match-error $ x ^ " is a term meta-var!" , []
... | just (meta-var-mk-tp _ k nothing sl)
= match-ok (meta-vars-set Xs (meta-var-mk-tp x k (just (mk-meta-var-sol tp m)) sl))
... | just (meta-var-mk-tp _ k (just sol) _) =
let mk-meta-var-sol tp' src = sol in
err⊎-guard (~ conv-type Γ tp tp') (e-solution-ineq Γ tp tp x)
>> match-ok Xs
-- update the kinds of HO meta-vars with
-- solutions
meta-vars-update-kinds : ctxt → (Xs Xsₖ : meta-vars) → meta-vars
meta-vars-update-kinds Γ Xs Xsₖ =
record Xs { varset = (flip trie-map) (varset Xs) λ where
(meta-var-mk-tp x k mtp sl) → meta-var-mk-tp x (meta-vars-subst-kind Γ Xsₖ k) mtp sl
sol → sol
}
hnf-elab-if : {ed : exprd} → 𝔹 → ctxt → ⟦ ed ⟧ → 𝔹 → ⟦ ed ⟧
hnf-elab-if b Γ t b' = if b then hnf Γ (record unfold-head-elab {unfold-defs = b'}) t else t
meta-vars-add-from-tpabs : ctxt → span-location → meta-vars → erased? → var → kind → type → meta-var × meta-vars
meta-vars-add-from-tpabs Γ sl Xs e? x k tp =
let Y = meta-var-fresh-tp Xs x sl (k , nothing)
Xs' = meta-vars-add Xs Y
-- tp' = subst Γ (meta-var-to-type-unsafe Y) x tp
in Y , Xs'
{-
-- Legacy for elaboration.agda
-- ==================================================
-- TODO: remove dependency and delete code
{-# TERMINATING #-} -- subst of a meta-var does not increase distance to arrow
meta-vars-peel : ctxt → span-location → meta-vars → type → (𝕃 meta-var) × type
meta-vars-peel Γ sl Xs (Abs pi e? pi' x tk@(Tkk k) tp)
with meta-vars-add-from-tpabs Γ sl Xs (mk-tpabs e? x k tp)
... | (Y , Xs')
with subst Γ (meta-var-to-type-unsafe Y) x tp
... | tp' =
let ret = meta-vars-peel Γ sl Xs' tp' ; Ys = fst ret ; rtp = snd ret
in (Y :: Ys , rtp)
meta-vars-peel Γ sl Xs (NoSpans tp _) =
meta-vars-peel Γ sl Xs tp
meta-vars-peel Γ sl Xs (TpParens _ tp _) =
meta-vars-peel Γ sl Xs tp
meta-vars-peel Γ sl Xs tp = [] , tp
meta-vars-unfold-tpapp : ctxt → meta-vars → type → is-tpabs?
meta-vars-unfold-tpapp Γ Xs tp
with meta-vars-subst-type Γ Xs tp
... | Abs _ b _ x (Tkk k) tp' = yes-tpabs b x k tp'
... | tp' = not-tpabs tp'
meta-vars-unfold-tmapp : ctxt → span-location → meta-vars → type → 𝕃 meta-var × is-tmabs?
meta-vars-unfold-tmapp Γ sl Xs tp
with meta-vars-peel Γ sl Xs (meta-vars-subst-type Γ Xs tp)
... | Ys , Abs _ b _ x (Tkt dom) cod =
Ys , yes-tmabs b x dom (is-free-in check-erased x cod) cod
... | Ys , TpArrow dom e? cod =
Ys , yes-tmabs e? "_" dom ff cod
... | Ys , tp' = Ys , not-tmabs tp'
-}
| {
"alphanum_fraction": 0.6287075124,
"avg_line_length": 35.8618012422,
"ext": "agda",
"hexsha": "e5cacb49ad597f785bc1d707ed5715b2bfdfa80c",
"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": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ice1k/cedille",
"max_forks_repo_path": "src/meta-vars.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"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": "ice1k/cedille",
"max_issues_repo_path": "src/meta-vars.agda",
"max_line_length": 112,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bf62d3d338809a30bc21a1affed07936b1ac60ac",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ice1k/cedille",
"max_stars_repo_path": "src/meta-vars.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7505,
"size": 23095
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.Types
import LibraBFT.Impl.Types.EpochState as EpochState
import LibraBFT.Impl.Types.Waypoint as Waypoint
open import LibraBFT.ImplShared.Consensus.Types
open import Util.Encode
open import Util.PKCS hiding (verify)
open import Util.Prelude
module LibraBFT.Impl.Types.Verifier where
record Verifier (A : Set) : Set where
field
verify : A → LedgerInfoWithSignatures → Either ErrLog Unit
epochChangeVerificationRequired : A → Epoch → Bool
isLedgerInfoStale : A → LedgerInfo → Bool
⦃ encodeA ⦄ : Encoder A
open Verifier ⦃ ... ⦄ public
instance
VerifierEpochState : Verifier EpochState
VerifierEpochState = record
{ verify = EpochState.verify
; epochChangeVerificationRequired = EpochState.epochChangeVerificationRequired
; isLedgerInfoStale = EpochState.isLedgerInfoStale
}
instance
VerifierWaypoint : Verifier Waypoint
VerifierWaypoint = record
{ verify = Waypoint.verifierVerify
; epochChangeVerificationRequired = Waypoint.epochChangeVerificationRequired
; isLedgerInfoStale = Waypoint.isLedgerInfoStale
}
| {
"alphanum_fraction": 0.665598975,
"avg_line_length": 37.1666666667,
"ext": "agda",
"hexsha": "65814c394a4441fe588057bf35be38d1fc94775e",
"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": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/Types/Verifier.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/Types/Verifier.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/Types/Verifier.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 375,
"size": 1561
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Core.Everything
open import Cubical.Foundations.HLevels
module Cubical.Algebra.Magma.Construct.Left {ℓ} (Aˢ : hSet ℓ) where
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.Magma
private
A = ⟨ Aˢ ⟩
isSetA = Aˢ .snd
_◂_ : Op₂ A
x ◂ y = x
------------------------------------------------------------------------
-- Properties
◂-zeroˡ : ∀ x → LeftZero x _◂_
◂-zeroˡ _ _ = refl
◂-identityʳ : ∀ x → RightIdentity x _◂_
◂-identityʳ _ _ = refl
------------------------------------------------------------------------
-- Magma definition
Left-isMagma : IsMagma A _◂_
Left-isMagma = record { is-set = isSetA }
LeftMagma : Magma ℓ
LeftMagma = record { isMagma = Left-isMagma }
| {
"alphanum_fraction": 0.5594315245,
"avg_line_length": 20.9189189189,
"ext": "agda",
"hexsha": "4e28b21b72e36df0ae05505361a6a2c20920b1d5",
"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/Left.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/Left.agda",
"max_line_length": 72,
"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/Left.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 236,
"size": 774
} |
------------------------------------------------------------------------
-- A type soundness result
------------------------------------------------------------------------
{-# OPTIONS --cubical --sized-types #-}
module Lambda.Partiality-monad.Inductive.Type-soundness where
open import Equality.Propositional.Cubical
open import Prelude hiding (⊥)
open import Prelude.Size
open import Bijection equality-with-J using (_↔_)
open import Equality.Decision-procedures equality-with-J
open import Equivalence equality-with-J using (_≃_)
open import Function-universe equality-with-J hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional equality-with-paths
as Trunc
open import Maybe equality-with-J
open import Monad equality-with-J
open import Univalence-axiom equality-with-J
open import Vec.Function equality-with-J
open import Partiality-monad.Inductive
open import Partiality-monad.Inductive.Alternative-order
open import Partiality-monad.Inductive.Monad
open import Lambda.Partiality-monad.Inductive.Interpreter
open import Lambda.Syntax
open Closure Tm
-- A propositionally truncated variant of WF-MV.
∥WF-MV∥ : Ty ∞ → Maybe Value → Type
∥WF-MV∥ σ x = ∥ WF-MV σ x ∥
-- If we can prove □ (∥WF-MV∥ σ) (run x), then x does not "go wrong".
does-not-go-wrong : ∀ {σ} {x : M Value} →
□ (∥WF-MV∥ σ) (run x) → ¬ x ≡ fail
does-not-go-wrong {σ} {x} always =
x ≡ fail ↝⟨ cong MaybeT.run ⟩
run x ≡ now nothing ↝⟨ always _ ⟩
∥WF-MV∥ σ nothing ↝⟨ id ⟩
∥ ⊥₀ ∥ ↝⟨ _↔_.to (not-inhabited⇒∥∥↔⊥ id) ⟩□
⊥₀ □
-- Some "constructors" for □ ∘ ∥WF-MV∥.
return-wf :
∀ {σ v} →
WF-Value σ v →
□ (∥WF-MV∥ σ) (MaybeT.run (return v))
return-wf v-wf = □-now truncation-is-proposition ∣ v-wf ∣
_>>=-wf_ :
∀ {σ τ} {x : M Value} {f : Value → M Value} →
□ (∥WF-MV∥ σ) (run x) →
(∀ {v} → WF-Value σ v → □ (∥WF-MV∥ τ) (run (f v))) →
□ (∥WF-MV∥ τ) (MaybeT.run (x >>= f))
_>>=-wf_ {σ} {τ} {f = f} x-wf f-wf =
□->>= (λ _ → truncation-is-proposition) x-wf
λ { {nothing} → Trunc.rec prop ⊥-elim
; {just v} → Trunc.rec prop f-wf
}
where
prop : ∀ {x} → Is-proposition (□ (∥WF-MV∥ τ) x)
prop = □-closure 1 (λ _ → truncation-is-proposition)
-- Type soundness.
mutual
⟦⟧′-wf : ∀ {n Γ} (t : Tm n) {σ} → Γ ⊢ t ∈ σ →
∀ {ρ} → WF-Env Γ ρ →
∀ n → □ (∥WF-MV∥ σ) (run (⟦ t ⟧′ ρ n))
⟦⟧′-wf (con i) con ρ-wf n = return-wf con
⟦⟧′-wf (var x) var ρ-wf n = return-wf (ρ-wf x)
⟦⟧′-wf (ƛ t) (ƛ t∈) ρ-wf n = return-wf (ƛ t∈ ρ-wf)
⟦⟧′-wf (t₁ · t₂) (t₁∈ · t₂∈) {ρ} ρ-wf n =
⟦⟧′-wf t₁ t₁∈ ρ-wf n >>=-wf λ f-wf →
⟦⟧′-wf t₂ t₂∈ ρ-wf n >>=-wf λ v-wf →
∙-wf f-wf v-wf n
∙-wf : ∀ {σ τ f v} →
WF-Value (σ ⇾ τ) f → WF-Value (force σ) v →
∀ n → □ (∥WF-MV∥ (force τ)) (run ((f ∙ v) n))
∙-wf (ƛ t₁∈ ρ₁-wf) v₂-wf (suc n) = ⟦⟧′-wf _ t₁∈ (cons-wf v₂-wf ρ₁-wf) n
∙-wf (ƛ t₁∈ ρ₁-wf) v₂-wf zero = $⟨ □-never ⟩
□ (∥WF-MV∥ _) never ↝⟨ ≡⇒↝ bijection $ cong (□ (∥WF-MV∥ _)) (sym never->>=) ⟩□
□ (∥WF-MV∥ _) (never >>= return ∘ just) □
type-soundness : ∀ {t : Tm 0} {σ} →
nil ⊢ t ∈ σ → ¬ ⟦ t ⟧ nil ≡ fail
type-soundness {t} {σ} =
nil ⊢ t ∈ σ ↝⟨ (λ t∈ → ⟦⟧′-wf _ t∈ nil-wf) ⟩
(∀ n → □ (∥WF-MV∥ σ) (run (⟦ t ⟧′ nil n))) ↝⟨ □-⨆ (λ _ → truncation-is-proposition) ⟩
□ (∥WF-MV∥ σ) (run (⟦ t ⟧ nil)) ↝⟨ does-not-go-wrong ⟩□
¬ ⟦ t ⟧ nil ≡ fail □
| {
"alphanum_fraction": 0.5141990626,
"avg_line_length": 35.213592233,
"ext": "agda",
"hexsha": "68d7a0d72d63f8794f82affba02c4c93662d6660",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Lambda/Partiality-monad/Inductive/Type-soundness.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/partiality-monad",
"max_issues_repo_path": "src/Lambda/Partiality-monad/Inductive/Type-soundness.agda",
"max_line_length": 103,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Lambda/Partiality-monad/Inductive/Type-soundness.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 1491,
"size": 3627
} |
module Issue1760a where
-- Skipping a single record definition.
{-# NO_POSITIVITY_CHECK #-}
record U : Set where
field ap : U → U
| {
"alphanum_fraction": 0.7142857143,
"avg_line_length": 19,
"ext": "agda",
"hexsha": "f91f4a5946d4ce5e2abfa45eb4872543c834f861",
"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/Issue1760a.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/Issue1760a.agda",
"max_line_length": 39,
"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/Issue1760a.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": 35,
"size": 133
} |
module StrongRMonads where
open import Library
open import Categories
open import Functors
open import MonoidalCat
open import RMonads
record SRMonad {a b c d}{M : Monoidal {a}{b}}{M' : Monoidal {c}{d}}
(J : MonoidalFun M M') : Set (a ⊔ b ⊔ c ⊔ d) where
constructor srmonad
open MonoidalFun J
field RM : RMonad F
open RMonad RM
open Cat
open Monoidal
open Fun
field st : ∀{X Y} -> Hom (C M') (OMap (⊗ M') (T X , OMap F Y))
(T (OMap (⊗ M) (X , Y)))
-- laws later
| {
"alphanum_fraction": 0.5931558935,
"avg_line_length": 23.9090909091,
"ext": "agda",
"hexsha": "fe1abb8c226254b90b0790bb6eca85c05205f7c1",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "StrongRMonads.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "StrongRMonads.agda",
"max_line_length": 67,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "StrongRMonads.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 182,
"size": 526
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use
-- Data.Sum.Relation.Binary.LeftOrder directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Sum.Relation.LeftOrder where
open import Data.Sum.Relation.Binary.LeftOrder public
| {
"alphanum_fraction": 0.4775,
"avg_line_length": 30.7692307692,
"ext": "agda",
"hexsha": "ff276ea9107cb6ef3f6ab0388ad11439e9442945",
"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/Sum/Relation/LeftOrder.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/Sum/Relation/LeftOrder.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/Sum/Relation/LeftOrder.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 60,
"size": 400
} |
-- Andreas, 2017-02-27, issue #2477
{-# OPTIONS --show-irrelevant #-}
open import Agda.Builtin.Size
open import Agda.Builtin.Nat using (suc) renaming (Nat to ℕ)
_+_ : Size → ℕ → Size
s + 0 = s
s + suc n = ↑ (s + n)
data Nat : Size → Set where
zero : ∀ i → Nat (i + 1)
suc : ∀ i → Nat i → Nat (i + 1)
-- i + 1 should be reduced to ↑ i
-- to make Nat monotone in its size argument
pred : ∀ i → Nat i → Nat i
pred .(i + 1) (zero i) = zero i
pred .(i + 1) (suc i x) = x
-- Should succeed
| {
"alphanum_fraction": 0.5649606299,
"avg_line_length": 22.0869565217,
"ext": "agda",
"hexsha": "9c81b8b136702fb35befcb2950931214c66a768c",
"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/Succeed/Issue2477.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/Issue2477.agda",
"max_line_length": 60,
"max_stars_count": 3,
"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/Issue2477.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": 196,
"size": 508
} |
module RMonads.SpecialCase where
open import Categories
open import Functors
open import Naturals hiding (Iso)
open import Monads
open import RMonads
leftM : ∀{a}{b}{C : Cat {a}{b}} → Monad C → RMonad (IdF C)
leftM M = record {
T = T;
η = η;
bind = bind;
law1 = law1;
law2 = law2;
law3 = law3}
where open Monad M
rightM : ∀{a b}{C : Cat {a}{b}} → RMonad (IdF C) → Monad C
rightM {C = C} M = record {
T = T;
η = η;
bind = bind;
law1 = law1;
law2 = law2;
law3 = law3} where open RMonad M
open import Relation.Binary.HeterogeneousEquality
open import Isomorphism
isoM : ∀{a b}{C : Cat {a}{b}} → Iso (RMonad (IdF C)) (Monad C)
isoM = record {fun = rightM; inv = leftM; law1 = λ {(monad _ _ _ _ _ _) → refl}; law2 = λ {(rmonad _ _ _ _ _ _) → refl}}
open import Monads.MonadMorphs
open import RMonads.RMonadMorphs
leftMM : ∀{a b}{C : Cat {a}{b}}{M M' : Monad C} → MonadMorph M M' →
RMonadMorph (leftM M) (leftM M')
leftMM MM = record {
morph = morph;
lawη = lawη;
lawbind = lawbind} where open MonadMorph MM
rightMM : ∀{a b}{C : Cat {a}{b}}{M M' : RMonad (IdF C)} → RMonadMorph M M' →
MonadMorph (rightM M) (rightM M')
rightMM MM = record {
morph = morph;
lawη = lawη;
lawbind = lawbind} where open RMonadMorph MM
isoMM : ∀{a b}{C : Cat {a}{b}}{M M' : Monad C} →
Iso (RMonadMorph (leftM M) (leftM M')) (MonadMorph M M')
isoMM {M = monad _ _ _ _ _ _}{M' = monad _ _ _ _ _ _} = record {
fun = rightMM;
inv = leftMM;
law1 = λ {(monadmorph _ _ _) → refl};
law2 = λ {(rmonadmorph _ _ _) → refl}}
open import Adjunctions
open import RAdjunctions
leftA : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}} → Adj C D → RAdj (IdF C) D
leftA {C}{D} A = record{
L = L;
R = R;
left = left;
right = right;
lawa = lawa;
lawb = lawb;
natleft = natleft;
natright = natright} where open Adj A
rightA : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}} → RAdj (IdF C) D → Adj C D
rightA {C = C}{D = D} A = record{
L = L;
R = R;
left = left;
right = right;
lawa = lawa;
lawb = lawb;
natleft = natleft;
natright = natright} where open RAdj A
isoA : ∀{a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}} →
Iso (RAdj (IdF C) D) (Adj C D)
isoA = record {
fun = rightA;
inv = leftA;
law1 = λ {(adjunction _ _ _ _ _ _ _ _) → refl};
law2 = λ {(radjunction _ _ _ _ _ _ _ _) → refl}}
| {
"alphanum_fraction": 0.5603413247,
"avg_line_length": 26.1808510638,
"ext": "agda",
"hexsha": "e7e277499917ee6cc635f955b88cb57694c5325f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "RMonads/SpecialCase.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "RMonads/SpecialCase.agda",
"max_line_length": 120,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "RMonads/SpecialCase.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 964,
"size": 2461
} |
------------------------------------------------------------------------
-- Compiler correctness
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --sized-types #-}
module Lambda.Delay-monad.Compiler-correctness where
import Equality.Propositional as E
open import Prelude
open import Prelude.Size
open import Maybe E.equality-with-J hiding (_>>=′_)
open import Monad E.equality-with-J
open import Vec.Function E.equality-with-J
open import Delay-monad.Bisimilarity
open import Delay-monad.Monad
open import Lambda.Compiler
open import Lambda.Delay-monad.Interpreter
open import Lambda.Delay-monad.Virtual-machine
open import Lambda.Syntax hiding ([_])
open import Lambda.Virtual-machine
private
module C = Closure Code
module T = Closure Tm
-- Bind preserves strong bisimilarity.
infixl 5 _>>=-congM_
_>>=-congM_ :
∀ {i ℓ} {A B : Type ℓ} {x y : M ∞ A} {f g : A → M ∞ B} →
[ i ] run x ∼ run y →
(∀ z → [ i ] run (f z) ∼ run (g z)) →
[ i ] run (x >>= f) ∼ run (y >>= g)
p >>=-congM q = p >>=-cong [ (λ _ → run fail ∎) , q ]
-- Bind is associative.
associativityM :
∀ {ℓ} {A B C : Type ℓ} (x : M ∞ A) (f : A → M ∞ B) (g : B → M ∞ C) →
run (x >>= (λ x → f x >>= g)) ∼ run (x >>= f >>= g)
associativityM x f g =
run (x >>= λ x → f x >>= g) ∼⟨⟩
run x >>=′ maybe (λ x → run (f x >>= g)) (return nothing) ∼⟨ (run x ∎) >>=-cong [ (λ _ → run fail ∎) , (λ x → run (f x >>= g) ∎) ] ⟩
run x >>=′ (λ x → maybe (MaybeT.run ∘ f) (return nothing) x >>=′
maybe (MaybeT.run ∘ g) (return nothing)) ∼⟨ associativity′ (run x) _ _ ⟩
run x >>=′ maybe (MaybeT.run ∘ f) (return nothing)
>>=′ maybe (MaybeT.run ∘ g) (return nothing) ∼⟨⟩
run (x >>= f >>= g) ∎
-- Compiler correctness.
mutual
⟦⟧-correct :
∀ {i n} t {ρ : T.Env n} {c s} {k : T.Value → M ∞ C.Value} →
(∀ v → [ i ] run (exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩) ≈
run (k v)) →
[ i ] run (exec ⟨ comp t c , s , comp-env ρ ⟩) ≈ run (⟦ t ⟧ ρ >>= k)
⟦⟧-correct (con i) {ρ} {c} {s} {k} hyp =
run (exec ⟨ con i ∷ c , s , comp-env ρ ⟩) ≳⟨⟩
run (exec ⟨ c , val (comp-val (T.con i)) ∷ s , comp-env ρ ⟩) ≈⟨ hyp (T.con i) ⟩∼
run (k (T.con i)) ∼⟨⟩
run (⟦ con i ⟧ ρ >>= k) ∎
⟦⟧-correct (var x) {ρ} {c} {s} {k} hyp =
run (exec ⟨ var x ∷ c , s , comp-env ρ ⟩) ≳⟨⟩
run (exec ⟨ c , val (comp-val (ρ x)) ∷ s , comp-env ρ ⟩) ≈⟨ hyp (ρ x) ⟩∼
run (k (ρ x)) ∼⟨⟩
run (⟦ var x ⟧ ρ >>= k) ∎
⟦⟧-correct (ƛ t) {ρ} {c} {s} {k} hyp =
run (exec ⟨ clo (comp t (ret ∷ [])) ∷ c , s , comp-env ρ ⟩) ≳⟨⟩
run (exec ⟨ c , val (comp-val (T.ƛ t ρ)) ∷ s , comp-env ρ ⟩) ≈⟨ hyp (T.ƛ t ρ) ⟩∼
run (k (T.ƛ t ρ)) ∼⟨⟩
run (⟦ ƛ t ⟧ ρ >>= k) ∎
⟦⟧-correct (t₁ · t₂) {ρ} {c} {s} {k} hyp =
run (exec ⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩) ≈⟨ (⟦⟧-correct t₁ λ v₁ → ⟦⟧-correct t₂ λ v₂ → ∙-correct v₁ v₂ hyp) ⟩∼
run (⟦ t₁ ⟧ ρ >>= λ v₁ → ⟦ t₂ ⟧ ρ >>= λ v₂ → v₁ ∙ v₂ >>= k) ∼⟨ (run (⟦ t₁ ⟧ ρ) ∎) >>=-congM (λ _ → associativityM (⟦ t₂ ⟧ ρ) _ _) ⟩
run (⟦ t₁ ⟧ ρ >>= λ v₁ → (⟦ t₂ ⟧ ρ >>= λ v₂ → v₁ ∙ v₂) >>= k) ∼⟨ associativityM (⟦ t₁ ⟧ ρ) _ _ ⟩
run (⟦ t₁ · t₂ ⟧ ρ >>= k) ∎
∙-correct :
∀ {i n} v₁ v₂ {ρ : T.Env n} {c s} {k : T.Value → M ∞ C.Value} →
(∀ v → [ i ] run (exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩) ≈
run (k v)) →
[ i ] run (exec ⟨ app ∷ c
, val (comp-val v₂) ∷ val (comp-val v₁) ∷ s
, comp-env ρ
⟩) ≈
run (v₁ ∙ v₂ >>= k)
∙-correct (T.con i) v₂ {ρ} {c} {s} {k} hyp =
run (exec ⟨ app ∷ c
, val (comp-val v₂) ∷ val (C.con i) ∷ s
, comp-env ρ
⟩) ∼⟨⟩
run fail ∼⟨⟩
run (T.con i ∙ v₂ >>= k) ∎
∙-correct (T.ƛ t₁ ρ₁) v₂ {ρ} {c} {s} {k} hyp =
run (exec ⟨ app ∷ c
, val (comp-val v₂) ∷ val (comp-val (T.ƛ t₁ ρ₁)) ∷ s
, comp-env ρ
⟩) ≈⟨ later (λ { .force →
run (exec ⟨ comp t₁ (ret ∷ [])
, ret c (comp-env ρ) ∷ s
, cons (comp-val v₂) (comp-env ρ₁)
⟩) ≡⟨ E.cong (λ ρ′ → run (exec ⟨ comp t₁ (ret ∷ []) ,
ret c (comp-env ρ) ∷ s , ρ′ ⟩))
(E.sym comp-cons) ⟩
run (exec ⟨ comp t₁ (ret ∷ [])
, ret c (comp-env ρ) ∷ s
, comp-env (cons v₂ ρ₁)
⟩) ≈⟨ ⟦⟧-correct t₁ (λ v →
run (exec ⟨ ret ∷ []
, val (comp-val v) ∷ ret c (comp-env ρ) ∷ s
, comp-env (cons v₂ ρ₁)
⟩) ≳⟨⟩
run (exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩) ≈⟨ hyp v ⟩∎
run (k v) ∎) ⟩∼
run (⟦ t₁ ⟧ (cons v₂ ρ₁) >>= k) ∎ }) ⟩∎
run (T.ƛ t₁ ρ₁ ∙ v₂ >>= k) ∎
-- Note that the equality that is used here is syntactic.
correct :
∀ t →
exec ⟨ comp t [] , [] , nil ⟩ ≈M
⟦ t ⟧ nil >>= λ v → return (comp-val v)
correct t =
run (exec ⟨ comp t [] , [] , nil ⟩) ≡⟨ E.cong (λ ρ → run (exec ⟨ comp t [] , [] , ρ ⟩)) $ E.sym comp-nil ⟩
run (exec ⟨ comp t [] , [] , comp-env nil ⟩) ≈⟨ ⟦⟧-correct t (λ v → return (just (comp-val v)) ∎) ⟩
run (⟦ t ⟧ nil >>= λ v → return (comp-val v)) ∎
| {
"alphanum_fraction": 0.3644162033,
"avg_line_length": 40.6129032258,
"ext": "agda",
"hexsha": "2c4ef6523addfa70a15f83da309f307080174818",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Lambda/Delay-monad/Compiler-correctness.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/partiality-monad",
"max_issues_repo_path": "src/Lambda/Delay-monad/Compiler-correctness.agda",
"max_line_length": 142,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Lambda/Delay-monad/Compiler-correctness.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 2218,
"size": 6295
} |
{-# OPTIONS --without-K #-}
open import HoTT
-- Associativity of the join (work in progress)
module experimental.JoinAssoc2 where
import experimental.JoinAssoc as Assoc
module Assoc2 {i j k} (A : Type i) (B : Type j) (C : Type k) where
open Assoc A B C
{- Here are the steps, without the junk around:
apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c))
1 (From.glue-β)
apd (λ x → ap to (from-glue (a , x))) (glue (b , c))
2 (unfuse)
ap↓ (λ x → ap to {x = from-left a} {y = from-right x}) (apd (λ x → from-glue (a , x)) (glue (b , c)))
3 (FromGlue.glue-β)
ap↓ (λ x → ap to {x = from-left a} {y = from-right x}) (apd (λ x → glue (x , c)) (glue (a , b)))
4 (fuse)
apd (λ x → ap to (glue (x , c))) (glue (a , b))
5 (To.glue-β)
apd (λ x → to-glue (x , c)) (glue (a , b))
6 (ToGlue.glue-β)
apd (λ x → glue (a , x)) (glue (b , c))
-}
to-from-glue-glue' : (a : A) (b : B) (c : C)
→ (↯ to-from-glue-left' a b) == (↯ to-from-glue-right' a c) [ (λ x → ap to (ap from (glue (a , x))) ∙' to-from-right x == glue (a , x)) ↓ glue (b , c) ]
to-from-glue-glue' a b c =
↓-=-in (!(
apd (λ x → ap to (ap from (glue (a , x))) ∙' to-from-right x) (glue (b , c)) ▹ (↯ to-from-glue-right' a c)
=⟨ apd∙' (λ x → ap to (ap from (glue (a , x)))) to-from-right (glue (b , c)) |in-ctx (λ u → u ▹ (↯ to-from-glue-right' a c)) ⟩
((apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c))) ∙'2ᵈ (apd to-from-right (glue (b , c)))) ▹ (↯ to-from-glue-right' a c)
=⟨ ToFromRight.glue-β (b , c) |in-ctx
(λ u → ((apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c))) ∙'2ᵈ u) ▹ (↯ to-from-glue-right' a c)) ⟩
((apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c))) ∙'2ᵈ (to-from-right-glue (b , c))) ▹ (↯ to-from-glue-right' a c)
=⟨ ▹-∙'2ᵈ (apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c))) (to-from-right-glue (b , c)) (↯ to-from-glue-right' a c) idp ⟩
(apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c)) ▹ (↯ to-from-glue-right' a c)) ∙'2ᵈ (to-from-right-glue (b , c) ▹ idp)
=⟨ (▹idp (to-from-right-glue (b , c))) |in-ctx (λ u → (apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c)) ▹ (↯ to-from-glue-right' a c)) ∙'2ᵈ u) ⟩
(apd (λ x → ap to (ap from (glue (a , x)))) (glue (b , c)) ▹ (↯ to-from-glue-right' a c)) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ apd=-red (λ x → ap (ap to) (From.glue-β (a , x))) (glue (b , c)) (1! (to-from-glue-right' a c)) |in-ctx (λ u → u ∙'2ᵈ (to-from-right-glue (b , c))) ⟩
{- 1 -}
((↯ 1# (to-from-glue-left' a b)) ◃ (apd (λ x → ap to (from-glue (a , x))) (glue (b , c)) ▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ apd-∘' (ap to) (λ x → from-glue (a , x)) (glue (b , c)) |in-ctx (λ u → ((↯ 1# (to-from-glue-left' a b)) ◃ (u ▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))) ⟩
{- 2 -}
((↯ 1# (to-from-glue-left' a b)) ◃ (ap↓ (ap to) (apd (λ x → from-glue (a , x)) (glue (b , c))) ▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ FromGlue.glue-β a (b , c) |in-ctx (λ u → ((↯ 1# (to-from-glue-left' a b)) ◃ (ap↓ (ap to) u ▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))) ⟩
{- 3 -}
((↯ 1# (to-from-glue-left' a b)) ◃ (ap↓ (ap to) (from-glue-glue a (b , c)) ▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ idp ⟩
((↯ 1# (to-from-glue-left' a b)) ◃ (ap↓ (ap to) (↓-swap! left from-right _ idp
(apd (λ x → glue (x , c)) (glue (a , b)) ▹! (FromRight.glue-β (b , c))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ Ap↓-swap!.β to left from-right _ idp (apd (λ x → glue (x , c)) (glue (a , b)) ▹! (FromRight.glue-β (b , c)))
|in-ctx (λ u → ((↯ 1# (to-from-glue-left' a b)) ◃ (u ▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))) ⟩
((↯ 1# (to-from-glue-left' a b)) ◃ (((ap (λ u → u) (∘-ap to left (glue (a , b)))) ◃ ↓-swap! (to ∘ left) (to ∘ from-right) _ idp (ap↓ (ap to) (apd (λ x → glue (x , c)) (glue (a , b)) ▹! (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ ap-idf (∘-ap to left (glue (a , b))) |in-ctx (λ v → ((↯ 1# (to-from-glue-left' a b)) ◃ ((v ◃ ↓-swap! (to ∘ left) (to ∘ from-right) _ idp (ap↓ (ap to) (apd (λ x → glue (x , c)) (glue (a , b)) ▹! (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))) ⟩
((↯ 1# (to-from-glue-left' a b)) ◃ (((∘-ap to left (glue (a , b))) ◃ ↓-swap! (to ∘ left) (to ∘ from-right) _ idp (ap↓ (ap to) (apd (λ x → glue (x , c)) (glue (a , b)) ▹! (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ {!!} ⟩
((↯ 2# (to-from-glue-left' a b)) ◃ ((↓-swap! to-left (to ∘ from-right) _ idp (ap↓ (ap to) (apd (λ x → glue (x , c)) (glue (a , b)) ▹! (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ ap↓-▹! (ap to) (apd (λ x → glue (x , c)) (glue (a , b))) (FromRight.glue-β (b , c)) |in-ctx (λ v → ((↯ 2# (to-from-glue-left' a b)) ◃ ((↓-swap! to-left (to ∘ from-right) _ idp (v ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))) ⟩
((↯ 2# (to-from-glue-left' a b)) ◃ ((↓-swap! to-left (to ∘ from-right) _ idp ((ap↓ (ap to) (apd (λ x → glue (x , c)) (glue (a , b))) ▹! ap (ap to) (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ ∘'-apd (ap to) (λ x → glue (x , c)) (glue (a , b)) |in-ctx (λ v → ((↯ 2# (to-from-glue-left' a b)) ◃ ((↓-swap! to-left (to ∘ from-right) _ idp ((v ▹! ap (ap to) (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))) ⟩
{- 4 -}
((↯ 2# (to-from-glue-left' a b)) ◃ ((↓-swap! to-left (to ∘ from-right) _ idp ((apd (λ x → ap to (glue (x , c))) (glue (a , b)) ▹! ap (ap to) (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
=⟨ {!!} ⟩
{- 5 -}
-- ((↯ 2# (to-from-glue-left' a b)) ◃ ((↓-swap! to-left (to ∘ from-right) _ idp ((apd (λ x → to-glue (x , c)) (glue (a , b)) ▹! ap (ap to) (FromRight.glue-β (b , c))) ▹ (ap (λ u → u) (∘-ap to from-right (glue (b , c))))))
-- ▹ (↯ 1! (to-from-glue-right' a c)))) ∙'2ᵈ (to-from-right-glue (b , c))
-- =⟨ {!!} ⟩
-- {- 5 -}
-- (↯ 2# (to-from-glue-left' a b)) ◃ (↓-swap! to-left right _ idp (To.glue-β (left a , c) !◃ (apd (λ x → ap to (glue (x , c))) (glue (a , b)) ▹ To.glue-β (right b , c))))
-- =⟨ {!!} ⟩
(↯ 2# (to-from-glue-left' a b)) ◃ (↓-swap! to-left right _ idp (apd (λ x → to-glue (x , c)) (glue (a , b))))
=⟨ ToGlue.glue-β c (a , b) |in-ctx (λ v → (↯ 2# (to-from-glue-left' a b)) ◃ (↓-swap! to-left right _ idp v)) ⟩
{- 6 -}
(↯ 2# (to-from-glue-left' a b)) ◃ (↓-swap! to-left right _ idp (to-glue-glue c (a , b)))
=⟨ ↓-swap-β to-left right {p = glue (a , b)} (to-glue-left c a) idp (ToLeft.glue-β (a , b) ◃ apd (λ x → glue (a , x)) (glue (b , c))) |in-ctx (λ v → (↯ 2# (to-from-glue-left' a b)) ◃ v) ⟩
(↯ 2# (to-from-glue-left' a b)) ◃ (ToLeft.glue-β (a , b) ◃ apd (λ x → glue (a , x)) (glue (b , c)))
=⟨ {!!} ⟩ -- associativity
(↯ to-from-glue-left' a b) ◃ apd (λ x → glue (a , x)) (glue (b , c)) ∎))
-- ((↓-apd-out (λ a' _ → to (from (left a)) == to (from (right a'))) (λ x → glue (a , x)) (glue (b , c)) (apdd (ap to ∘ ap from) (glue (b , c)) (apd (λ x → (glue (a , x))) (glue (b , c))))) ∙'2ᵈ (to-from-right-glue (b , c))) ▹ to-from-glue-right' a c =⟨ {!!} ⟩
-- to-from-glue-glue : (a : A) (bc : B × C)
-- → to-from-glue-left a (fst bc) == to-from-glue-right a (snd bc) [ (λ x → to-from-left a == to-from-right x [ (λ y → to (from y) == y) ↓ glue (a , x) ]) ↓ glue bc ]
-- to-from-glue-glue a (b , c) = {!!} -- Should not be too hard
-- to-from-glue : (x : A × (B * C)) → to-from-left (fst x) == to-from-right (snd x) [ (λ x → to (from x) == x) ↓ glue x ]
-- to-from-glue (a , bc) = pushout-rec (to-from-glue-left a) (to-from-glue-right a) (to-from-glue-glue a) bc
-- to-from : (x : A * (B * C)) → to (from x) == x
-- to-from = pushout-rec to-from-left to-from-right to-from-glue
-- *-assoc : (A * B) * C ≃ A * (B * C)
-- *-assoc = equiv to from to-from from-to
| {
"alphanum_fraction": 0.4643330389,
"avg_line_length": 74.8429752066,
"ext": "agda",
"hexsha": "f29fa0789de7b8ddf643d9e9160241cd84d1f3ab",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmknapp/HoTT-Agda",
"max_forks_repo_path": "theorems/experimental/JoinAssoc2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cmknapp/HoTT-Agda",
"max_issues_repo_path": "theorems/experimental/JoinAssoc2.agda",
"max_line_length": 294,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmknapp/HoTT-Agda",
"max_stars_repo_path": "theorems/experimental/JoinAssoc2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4139,
"size": 9056
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some examples showing how the AVL tree module can be used
------------------------------------------------------------------------
module README.AVL where
------------------------------------------------------------------------
-- Setup
-- AVL trees are defined in Data.AVL.
import Data.AVL
-- This module is parametrised by keys, which have to form a (strict)
-- total order, and values, which are indexed by keys. Let us use
-- natural numbers as keys and vectors of strings as values.
import Data.Nat.Properties as ℕ
open import Data.String using (String)
open import Data.Vec using (Vec; _∷_; [])
open import Relation.Binary using (module StrictTotalOrder)
open Data.AVL (Vec String)
(StrictTotalOrder.isStrictTotalOrder ℕ.strictTotalOrder)
------------------------------------------------------------------------
-- Construction of trees
-- Some values.
v₁ = "cepa" ∷ []
v₁′ = "depa" ∷ []
v₂ = "apa" ∷ "bepa" ∷ []
-- Empty and singleton trees.
t₀ : Tree
t₀ = empty
t₁ : Tree
t₁ = singleton 2 v₂
-- Insertion of a key-value pair into a tree.
t₂ = insert 1 v₁ t₁
-- If you insert a key-value pair and the key already exists in the
-- tree, then the old value is thrown away.
t₂′ = insert 1 v₁′ t₂
-- Deletion of the mapping for a certain key.
t₃ = delete 2 t₂
-- Conversion of a list of key-value mappings to a tree.
open import Data.List using (_∷_; [])
open import Data.Product as Prod using (_,_; _,′_)
t₄ = fromList ((2 , v₂) ∷ (1 , v₁) ∷ [])
------------------------------------------------------------------------
-- Queries
-- Let us formulate queries as unit tests.
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
-- Searching for a key.
open import Data.Bool using (true; false)
open import Data.Maybe as Maybe using (just; nothing)
q₀ : lookup 2 t₂ ≡ just v₂
q₀ = refl
q₁ : lookup 2 t₃ ≡ nothing
q₁ = refl
q₂ : 3 ∈? t₂ ≡ false
q₂ = refl
q₃ : 1 ∈? t₄ ≡ true
q₃ = refl
-- Turning a tree into a sorted list of key-value pairs.
q₄ : toList t₁ ≡ (2 , v₂) ∷ []
q₄ = refl
q₅ : toList t₂ ≡ (1 , v₁) ∷ (2 , v₂) ∷ []
q₅ = refl
q₅′ : toList t₂′ ≡ (1 , v₁′) ∷ (2 , v₂) ∷ []
q₅′ = refl
------------------------------------------------------------------------
-- Views
-- Partitioning a tree into the smallest element plus the rest, or the
-- largest element plus the rest.
open import Function using (id)
v₆ : headTail t₀ ≡ nothing
v₆ = refl
v₇ : Maybe.map (Prod.map id toList) (headTail t₂) ≡
just ((1 , v₁) , ((2 , v₂) ∷ []))
v₇ = refl
v₈ : initLast t₀ ≡ nothing
v₈ = refl
v₉ : Maybe.map (Prod.map toList id) (initLast t₄) ≡
just (((1 , v₁) ∷ []) ,′ (2 , v₂))
v₉ = refl
------------------------------------------------------------------------
-- Further reading
-- Variations of the AVL tree module are available:
-- • Finite maps with indexed keys and values.
import Data.AVL.IndexedMap
-- • Finite sets.
import Data.AVL.Sets
| {
"alphanum_fraction": 0.5493236556,
"avg_line_length": 22.6194029851,
"ext": "agda",
"hexsha": "181a8dc0d8cea9bbf79aecac70cd1bbb50ba9499",
"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/README/AVL.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/README/AVL.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/README/AVL.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": 839,
"size": 3031
} |
{-# OPTIONS --type-in-type --rewriting #-}
module _ where
postulate
_≡_ : {A : Set} → A → A → Set
{-# BUILTIN REWRITE _≡_ #-}
record ⊤ : Set where
constructor []
open ⊤
postulate
ID : (Δ : Set) (δ₀ δ₁ : Δ) → Set
ID⊤ : (δ₀ δ₁ : ⊤) → ID ⊤ δ₀ δ₁ ≡ ⊤
Id : {Δ : Set} (A : Δ → Set) {δ₀ δ₁ : Δ} (δ₂ : ID Δ δ₀ δ₁) (a₀ : A δ₀) (a₁ : A δ₁) → Set
ap : {Δ : Set} {A : Δ → Set} (f : (δ : Δ) → A δ) {δ₀ δ₁ : Δ} (δ₂ : ID Δ δ₀ δ₁) → Id A δ₂ (f δ₀) (f δ₁)
AP : {Θ Δ : Set} (f : Θ → Δ) {t₀ t₁ : Θ} (t₂ : ID Θ t₀ t₁) → ID Δ (f t₀) (f t₁)
Id-AP : {Θ Δ : Set} (f : Θ → Δ) {t₀ t₁ : Θ} (t₂ : ID Θ t₀ t₁) (A : Δ → Set) (a₀ : A (f t₀)) (a₁ : A (f t₁)) →
Id A (AP f t₂) a₀ a₁ ≡ Id (λ w → A (f w)) t₂ a₀ a₁
Copy : Set → Set
uncopy : {A : Set} → Copy A → A
{-# REWRITE ID⊤ #-}
{-# REWRITE Id-AP #-}
postulate
utr→ : {Δ : Set} (A : Δ → Set) {δ₀ δ₁ : Δ} (δ₂ : ID Δ δ₀ δ₁) (a₁ a₁' : A δ₁) → Id {⊤} (λ _ → A δ₁) [] a₁ a₁'
IdU : {Δ : Set} {δ₀ δ₁ : Δ} (δ₂ : ID Δ δ₀ δ₁) (A B : Set) →
Id {Δ} (λ _ → Set) δ₂ A B ≡ Copy ((b₀ : B) (b₁ : B) → Id {⊤} (λ _ → B) [] b₀ b₁)
{-# REWRITE IdU #-}
postulate
apU : {Δ : Set} (A : Δ → Set) {δ₀ δ₁ : Δ} (δ₂ : ID Δ δ₀ δ₁) → uncopy (ap A δ₂) ≡ utr→ A δ₂
{-# REWRITE apU #-}
| {
"alphanum_fraction": 0.4490131579,
"avg_line_length": 31.1794871795,
"ext": "agda",
"hexsha": "57541db688aab5a75f2ad4bc90a653ca301dc51d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue5923-OP.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"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": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue5923-OP.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue5923-OP.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 645,
"size": 1216
} |
module Data.List.Properties.Pointwise where
open import Data.Nat
open import Data.List
open import Relation.Binary.List.Pointwise hiding (refl; map)
open import Relation.Binary.PropositionalEquality
pointwise-∷ʳ : ∀ {a b ℓ A B P l m x y} → Rel {a} {b} {ℓ} {A} {B} P l m → P x y →
Rel {a} {b} {ℓ} {A} {B} P (l ∷ʳ x) (m ∷ʳ y)
pointwise-∷ʳ [] q = q ∷ []
pointwise-∷ʳ (x∼y ∷ p) q = x∼y ∷ (pointwise-∷ʳ p q)
{-}
pointwise-[]≔ : ∀ {a b ℓ A B P l m i x y} →
Rel {a} {b} {ℓ} {A} {B} P l m → (p : l [ i ]= x) → P x y →
Rel {a} {b} {ℓ} {A} {B} P l (m [ fromℕ ([]=-length l p) ]≔ y)
pointwise-[]≔ r p q z = ?
postulate
pointwise-[]≔ [] () r
pointwise-[]≔ (x∼y ∷ r) here (s≤s z≤n) z = z ∷ r
pointwise-[]≔ (x∼y ∷ r) (there p) (s≤s q) z = subst (λ x → Rel _ _ x) {!!} (x∼y ∷ pointwise-[]≔ r p q z)
-}
pointwise-length : ∀ {a b ℓ A B P l m} → Rel {a} {b} {ℓ} {A} {B} P l m → length l ≡ length m
pointwise-length [] = refl
pointwise-length (x∼y ∷ p) = cong suc (pointwise-length p)
| {
"alphanum_fraction": 0.5240904621,
"avg_line_length": 37.6666666667,
"ext": "agda",
"hexsha": "4e491315c918d5549d338da0e27d0559cfd50e97",
"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/Data/List/Properties/Pointwise.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/Data/List/Properties/Pointwise.agda",
"max_line_length": 105,
"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/Data/List/Properties/Pointwise.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": 468,
"size": 1017
} |
-- Pattern synonyms are now allowed in parameterised modules.
module _ where
module L (A : Set) where
data List : Set where
nil : List
cons : A → List → List
pattern unit x = cons x nil
data Bool : Set where
true false : Bool
module LB = L Bool
open LB
init : List → List
init nil = nil
init (unit _) = nil
init (cons x xs) = cons x (init xs)
data _≡_ {A : Set}(x : A) : A → Set where
refl : x ≡ x
test : init (cons true (unit false)) ≡ unit true
test = refl
| {
"alphanum_fraction": 0.6361746362,
"avg_line_length": 18.5,
"ext": "agda",
"hexsha": "956f3f02a0ce4113b4c0c19febcf7aa7d7e71f5c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue941.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/Issue941.agda",
"max_line_length": 61,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/succeed/Issue941.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": 153,
"size": 481
} |
{- COMPLEXITY LANGUAGE -}
open import Preliminaries
open import Preorder-Max
module Complexity where
data CTp : Set where
unit : CTp
nat : CTp
_->c_ : CTp → CTp → CTp
_×c_ : CTp → CTp → CTp
list : CTp → CTp
bool : CTp
C : CTp
-- represent a context as a list of types
Ctx = List CTp
-- de Bruijn indices (for free variables)
data _∈_ : CTp → Ctx → Set where
i0 : ∀ {Γ τ}
→ τ ∈ (τ :: Γ)
iS : ∀ {Γ τ τ1}
→ τ ∈ Γ
→ τ ∈ (τ1 :: Γ)
data _|-_ : Ctx → CTp → Set where
unit : ∀ {Γ}
→ Γ |- unit
0C : ∀ {Γ}
→ Γ |- C
1C : ∀ {Γ}
→ Γ |- C
plusC : ∀ {Γ}
→ Γ |- C
→ Γ |- C
→ Γ |- C
var : ∀ {Γ τ}
→ τ ∈ Γ
→ Γ |- τ
z : ∀ {Γ}
→ Γ |- nat
suc : ∀ {Γ}
→ (e : Γ |- nat)
→ Γ |- nat
rec : ∀ {Γ τ}
→ Γ |- nat
→ Γ |- τ
→ (nat :: (τ :: Γ)) |- τ
→ Γ |- τ
lam : ∀ {Γ τ ρ}
→ (ρ :: Γ) |- τ
→ Γ |- (ρ ->c τ)
app : ∀ {Γ τ1 τ2}
→ Γ |- (τ2 ->c τ1)
→ Γ |- τ2
→ Γ |- τ1
prod : ∀ {Γ τ1 τ2}
→ Γ |- τ1
→ Γ |- τ2
→ Γ |- (τ1 ×c τ2)
l-proj : ∀ {Γ τ1 τ2}
→ Γ |- (τ1 ×c τ2)
→ Γ |- τ1
r-proj : ∀ {Γ τ1 τ2}
→ Γ |- (τ1 ×c τ2)
→ Γ |- τ2
nil : ∀ {Γ τ} → Γ |- list τ
_::c_ : ∀ {Γ τ} → Γ |- τ → Γ |- list τ → Γ |- list τ
listrec : ∀ {Γ τ τ'} → Γ |- list τ → Γ |- τ' → (τ :: (list τ :: (τ' :: Γ))) |- τ' → Γ |- τ'
true : ∀ {Γ} → Γ |- bool
false : ∀ {Γ} → Γ |- bool
_+C_ : ∀ {Γ τ} → Γ |- C → Γ |- (C ×c τ)→ Γ |- (C ×c τ)
c +C e = prod (plusC c (l-proj e)) (r-proj e)
------weakening and substitution lemmas
-- renaming = variable for variable substitution
--functional view:
--avoids induction,
--some associativity/unit properties for free
-- read: you can rename Γ' as Γ
rctx : Ctx → Ctx → Set
rctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → τ ∈ Γ
rename-var : ∀ {Γ Γ' τ} → rctx Γ Γ' → τ ∈ Γ' → τ ∈ Γ
rename-var ρ a = ρ a
idr : ∀ {Γ} → rctx Γ Γ
idr x = x
-- weakening with renaming
p∙ : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) Γ'
p∙ ρ = λ x → iS (ρ x)
p : ∀ {Γ τ} → rctx (τ :: Γ) Γ
p = p∙ idr
_∙rr_ : ∀ {A B C} → rctx A B → rctx B C → rctx A C
ρ1 ∙rr ρ2 = ρ1 o ρ2
-- free stuff
rename-var-ident : ∀ {Γ τ} → (x : τ ∈ Γ) → rename-var idr x == x
rename-var-ident _ = Refl
rename-var-∙ : ∀ {A B C τ} → (r1 : rctx A B) (r2 : rctx B C) (x : τ ∈ C)
→ rename-var r1 (rename-var r2 x) == rename-var (r1 ∙rr r2) x
rename-var-∙ _ _ _ = Refl
∙rr-assoc : ∀ {A B C D} → (r1 : rctx A B) (r2 : rctx B C) (r3 : rctx C D) → _==_ {_} {rctx A D} (r1 ∙rr (r2 ∙rr r3)) ((r1 ∙rr r2) ∙rr r3)
∙rr-assoc r1 r2 r3 = Refl
r-extend : ∀ {Γ Γ' τ} → rctx Γ Γ' → rctx (τ :: Γ) (τ :: Γ')
r-extend ρ i0 = i0
r-extend ρ (iS x) = iS (ρ x)
ren : ∀ {Γ Γ' τ} → Γ' |- τ → rctx Γ Γ' → Γ |- τ
ren unit ρ = unit
ren 0C ρ = 0C
ren 1C ρ = 1C
ren (plusC e e₁) ρ = plusC (ren e ρ) (ren e₁ ρ)
ren (var x) ρ = var (ρ x)
ren z ρ = z
ren (suc e) ρ = suc (ren e ρ)
ren (rec e e₁ e₂) ρ = rec (ren e ρ) (ren e₁ ρ) (ren e₂ (r-extend (r-extend ρ)))
ren (lam e) ρ = lam (ren e (r-extend ρ))
ren (app e e₁) ρ = app (ren e ρ) (ren e₁ ρ)
ren (prod e1 e2) ρ = prod (ren e1 ρ) (ren e2 ρ)
ren (l-proj e) ρ = l-proj (ren e ρ)
ren (r-proj e) ρ = r-proj (ren e ρ)
ren nil ρ = nil
ren (x ::c xs) ρ = ren x ρ ::c ren xs ρ
ren true ρ = true
ren false ρ = false
ren (listrec e e₁ e₂) ρ = listrec (ren e ρ) (ren e₁ ρ) (ren e₂ (r-extend (r-extend (r-extend ρ))))
extend-ren-comp-lemma : ∀ {Γ Γ' Γ'' τ τ'} → (x : τ ∈ τ' :: Γ'') (ρ1 : rctx Γ Γ') (ρ2 : rctx Γ' Γ'')
→ Id {_} {_} ((r-extend ρ1 ∙rr r-extend ρ2) x) (r-extend (ρ1 ∙rr ρ2) x)
extend-ren-comp-lemma i0 ρ1 ρ2 = Refl
extend-ren-comp-lemma (iS x) ρ1 ρ2 = Refl
extend-ren-comp : ∀ {Γ Γ' Γ'' τ} → (ρ1 : rctx Γ Γ') → (ρ2 : rctx Γ' Γ'')
→ Id {_} {rctx (τ :: Γ) (τ :: Γ'')} (r-extend ρ1 ∙rr r-extend ρ2) (r-extend (ρ1 ∙rr ρ2))
extend-ren-comp ρ1 ρ2 = λ=i (λ τ → λ= (λ x → extend-ren-comp-lemma x ρ1 ρ2))
ren-comp : ∀ {Γ Γ' Γ'' τ} → (ρ1 : rctx Γ Γ') → (ρ2 : rctx Γ' Γ'') → (e : Γ'' |- τ)
→ (ren (ren e ρ2) ρ1) == (ren e (ρ1 ∙rr ρ2))
ren-comp ρ1 ρ2 unit = Refl
ren-comp ρ1 ρ2 0C = Refl
ren-comp ρ1 ρ2 1C = Refl
ren-comp ρ1 ρ2 (plusC e e₁) = ap2 plusC (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
ren-comp ρ1 ρ2 (var x) = ap var (rename-var-∙ ρ1 ρ2 x)
ren-comp ρ1 ρ2 z = Refl
ren-comp ρ1 ρ2 (suc e) = ap suc (ren-comp ρ1 ρ2 e)
ren-comp ρ1 ρ2 (rec e e₁ e₂) = ap3 rec (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
(ap (ren e₂) (ap r-extend (extend-ren-comp ρ1 ρ2) ∘
extend-ren-comp (r-extend ρ1) (r-extend ρ2)) ∘
ren-comp (r-extend (r-extend ρ1)) (r-extend (r-extend ρ2)) e₂)
ren-comp ρ1 ρ2 (lam e) = ap lam ((ap (ren e) (extend-ren-comp ρ1 ρ2)) ∘ ren-comp (r-extend ρ1) (r-extend ρ2) e)
ren-comp ρ1 ρ2 (app e e₁) = ap2 app (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
ren-comp ρ1 ρ2 (prod e e₁) = ap2 prod (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
ren-comp ρ1 ρ2 (l-proj e) = ap l-proj (ren-comp ρ1 ρ2 e)
ren-comp ρ1 ρ2 (r-proj e) = ap r-proj (ren-comp ρ1 ρ2 e)
ren-comp ρ1 ρ2 nil = Refl
ren-comp ρ1 ρ2 (e ::c e₁) = ap2 _::c_ (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
ren-comp ρ1 ρ2 (listrec e e₁ e₂) = ap3 listrec (ren-comp ρ1 ρ2 e) (ren-comp ρ1 ρ2 e₁)
(ap (ren e₂) (ap r-extend (ap r-extend (extend-ren-comp ρ1 ρ2)) ∘
(ap r-extend (extend-ren-comp (r-extend ρ1) (r-extend ρ2)) ∘
extend-ren-comp (r-extend (r-extend ρ1)) (r-extend (r-extend ρ2)))) ∘
ren-comp (r-extend (r-extend (r-extend ρ1)))
(r-extend (r-extend (r-extend ρ2))) e₂)
ren-comp ρ1 ρ2 true = Refl
ren-comp ρ1 ρ2 false = Refl
-- weakening a context
wkn : ∀ {Γ τ1 τ2} → Γ |- τ2 → (τ1 :: Γ) |- τ2
wkn e = ren e iS
sctx : Ctx → Ctx → Set
sctx Γ Γ' = ∀ {τ} → τ ∈ Γ' → Γ |- τ
--lem2 (addvar)
s-extend : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) (τ :: Γ')
s-extend Θ i0 = var i0
s-extend Θ (iS x) = wkn (Θ x)
ids : ∀ {Γ} → sctx Γ Γ
ids x = var x
-- weakening with substitution
q∙ : ∀ {Γ Γ' τ} → sctx Γ Γ' → sctx (τ :: Γ) Γ'
q∙ Θ = λ x → wkn (Θ x)
lem3' : ∀ {Γ Γ' τ} → sctx Γ Γ' → Γ |- τ → sctx Γ (τ :: Γ')
lem3' Θ e i0 = e
lem3' Θ e (iS i) = Θ i
--lem3
q : ∀ {Γ τ} → Γ |- τ → sctx Γ (τ :: Γ)
q e = lem3' ids e
-- subst-var
svar : ∀ {Γ1 Γ2 τ} → sctx Γ1 Γ2 → τ ∈ Γ2 → Γ1 |- τ
svar Θ i = q (Θ i) i0
lem4' : ∀ {Γ Γ' τ1 τ2} → sctx Γ Γ' → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ'))
lem4' Θ a b = lem3' (lem3' Θ b) a
lem4 : ∀ {Γ τ1 τ2} → Γ |- τ1 → Γ |- τ2 → sctx Γ (τ1 :: (τ2 :: Γ))
lem4 e1 e2 = lem4' ids e1 e2
lem5' : ∀ {Γ Γ' τ1 τ2 τ3} → sctx Γ Γ' → Γ |- τ1 → Γ |- τ2 → Γ |- τ3 → sctx Γ (τ1 :: (τ2 :: (τ3 :: Γ')))
lem5' Θ a b c = lem3' (lem3' (lem3' Θ c) b) a
lem5 : ∀ {Γ τ1 τ2 τ3} → Γ |- τ1 → Γ |- τ2 → Γ |- τ3 → sctx Γ (τ1 :: (τ2 :: (τ3 :: Γ)))
lem5 e1 e2 e3 = lem5' ids e1 e2 e3
subst : ∀ {Γ Γ' τ} → Γ' |- τ → sctx Γ Γ' → Γ |- τ
subst unit Θ = unit
subst 0C Θ = 0C
subst 1C Θ = 1C
subst (plusC e e₁) Θ = plusC (subst e Θ) (subst e₁ Θ)
subst (var x) Θ = Θ x
subst z Θ = z
subst (suc e) Θ = suc (subst e Θ)
subst (rec e e₁ e₂) Θ = rec (subst e Θ) (subst e₁ Θ) (subst e₂ (s-extend (s-extend Θ)))
subst (lam e) Θ = lam (subst e (s-extend Θ))
subst (app e e₁) Θ = app (subst e Θ) (subst e₁ Θ)
subst (prod e1 e2) Θ = prod (subst e1 Θ) (subst e2 Θ)
subst (l-proj e) Θ = l-proj (subst e Θ)
subst (r-proj e) Θ = r-proj (subst e Θ)
subst nil Θ = nil
subst (x ::c xs) Θ = subst x Θ ::c subst xs Θ
subst true Θ = true
subst false Θ = false
subst (listrec e e₁ e₂) Θ = listrec (subst e Θ) (subst e₁ Θ) (subst e₂ (s-extend (s-extend (s-extend Θ))))
subst1 : ∀ {Γ τ τ1} → Γ |- τ1 → (τ1 :: Γ) |- τ → Γ |- τ
subst1 e e' = subst e' (q e)
_rs_ : ∀ {A B C} → rctx A B → sctx B C → sctx A C
_rs_ ρ Θ x = ren (subst (var x) Θ) ρ
_ss_ : ∀ {A B C} → sctx A B → sctx B C → sctx A C
_ss_ Θ1 Θ2 x = subst (subst (var x) Θ2) Θ1
_sr_ : ∀ {A B C} → sctx A B → rctx B C → sctx A C
_sr_ Θ ρ x = subst (ren (var x) ρ) Θ
--free stuff
svar-rs : ∀ {A B C τ} (ρ : rctx A B) (Θ : sctx B C) (x : τ ∈ C)
→ svar (ρ rs Θ) x == ren (svar Θ x) ρ
svar-rs = λ ρ Θ x → Refl
svar-ss : ∀ {A B C τ} (Θ1 : sctx A B) (Θ2 : sctx B C) (x : τ ∈ C)
→ svar (Θ1 ss Θ2) x == subst (svar Θ2 x) Θ1
svar-ss = λ Θ1 Θ2 x → Refl
svar-sr : ∀ {A B C τ} (Θ : sctx A B) (ρ : rctx B C) (x : τ ∈ C)
→ svar Θ (rename-var ρ x) == svar (Θ sr ρ) x
svar-sr = λ Θ ρ x → Refl
svar-id : ∀ {Γ τ} → (x : τ ∈ Γ) → var x == svar ids x
svar-id = λ x → Refl
rsr-assoc : ∀ {A B C D} → (ρ1 : rctx A B) (Θ : sctx B C) (ρ2 : rctx C D)
→ Id {_} {sctx A D} ((ρ1 rs Θ) sr ρ2) (ρ1 rs (Θ sr ρ2))
rsr-assoc = λ ρ1 Θ ρ2 → Refl
extend-id-once-lemma : ∀ {Γ τ τ'} → (x : τ ∈ τ' :: Γ) → _==_ {_} {τ' :: Γ |- τ}
(ids {τ' :: Γ} {τ} x) (s-extend {Γ} {Γ} {τ'} (ids {Γ}) {τ} x)
extend-id-once-lemma i0 = Refl
extend-id-once-lemma (iS x) = Refl
extend-id-once : ∀ {Γ τ} → Id {_} {sctx (τ :: Γ) (τ :: Γ)} (ids {τ :: Γ}) (s-extend ids)
extend-id-once = λ=i (λ τ → λ= (λ x → extend-id-once-lemma x))
extend-id-twice : ∀ {Γ τ1 τ2} → Id {_} {sctx (τ1 :: τ2 :: Γ) (τ1 :: τ2 :: Γ)} (ids {τ1 :: τ2 :: Γ}) (s-extend (s-extend ids))
extend-id-twice = ap s-extend extend-id-once ∘ extend-id-once
subst-id : ∀ {Γ τ} (e : Γ |- τ) → e == subst e ids
subst-id unit = Refl
subst-id 0C = Refl
subst-id 1C = Refl
subst-id (plusC e e₁) = ap2 plusC (subst-id e) (subst-id e₁)
subst-id (var x) = svar-id x
subst-id z = Refl
subst-id (suc e) = ap suc (subst-id e)
subst-id (rec e e₁ e₂) = ap3 rec (subst-id e) (subst-id e₁) (ap (subst e₂) extend-id-twice ∘ subst-id e₂)
subst-id (lam e) = ap lam (ap (subst e) extend-id-once ∘ subst-id e)
subst-id (app e e₁) = ap2 app (subst-id e) (subst-id e₁)
subst-id (prod e e₁) = ap2 prod (subst-id e) (subst-id e₁)
subst-id (l-proj e) = ap l-proj (subst-id e)
subst-id (r-proj e) = ap r-proj (subst-id e)
subst-id nil = Refl
subst-id (e ::c e₁) = ap2 _::c_ (subst-id e) (subst-id e₁)
subst-id true = Refl
subst-id false = Refl
subst-id (listrec e e₁ e₂) = ap3 listrec (subst-id e) (subst-id e₁) (ap (subst e₂) (ap s-extend (ap s-extend extend-id-once) ∘ extend-id-twice) ∘ subst-id e₂)
extend-rs-once-lemma : ∀ {A B C τ τ'} → (x : τ ∈ τ' :: B) (ρ : rctx C A) (Θ : sctx A B) → _==_ {_} {τ' :: C |- τ}
(_rs_ {τ' :: C} {τ' :: A} {τ' :: B} (r-extend {C} {A} {τ'} ρ)
(s-extend {A} {B} {τ'} Θ) {τ} x)
(s-extend {C} {B} {τ'} (_rs_ {C} {A} {B} ρ Θ) {τ} x)
extend-rs-once-lemma i0 ρ Θ = Refl
extend-rs-once-lemma (iS x) ρ Θ = ! (ren-comp iS ρ (Θ x)) ∘ ren-comp (r-extend ρ) iS (Θ x)
extend-rs-once : ∀ {A B C τ} → (ρ : rctx C A) (Θ : sctx A B)
→ Id {_} {sctx (τ :: C) (τ :: B)} (r-extend ρ rs s-extend Θ) (s-extend (ρ rs Θ))
extend-rs-once ρ Θ = λ=i (λ τ → λ= (λ x → extend-rs-once-lemma x ρ Θ))
extend-rs-twice : ∀ {A B C τ τ'} → (ρ : rctx C A) (Θ : sctx A B)
→ Id {_} {sctx (τ :: τ' :: C) (τ :: τ' :: B)} ((r-extend (r-extend ρ)) rs (s-extend (s-extend Θ))) ((s-extend (s-extend (ρ rs Θ))))
extend-rs-twice ρ Θ = ap s-extend (extend-rs-once ρ Θ) ∘ extend-rs-once (r-extend ρ) (s-extend Θ)
subst-rs : ∀ {A B C τ} → (ρ : rctx C A) (Θ : sctx A B) (e : B |- τ)
→ ren (subst e Θ) ρ == subst e (ρ rs Θ)
subst-rs ρ Θ unit = Refl
subst-rs ρ Θ 0C = Refl
subst-rs ρ Θ 1C = Refl
subst-rs ρ Θ (plusC e e₁) = ap2 plusC (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
subst-rs ρ Θ (var x) = svar-rs ρ Θ x
subst-rs ρ Θ z = Refl
subst-rs ρ Θ (suc e) = ap suc (subst-rs ρ Θ e)
subst-rs ρ Θ (rec e e₁ e₂) = ap3 rec (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
(ap (subst e₂) (extend-rs-twice ρ Θ) ∘
subst-rs (r-extend (r-extend ρ)) (s-extend (s-extend Θ)) e₂)
subst-rs ρ Θ (lam e) = ap lam (ap (subst e) (extend-rs-once ρ Θ) ∘ subst-rs (r-extend ρ) (s-extend Θ) e)
subst-rs ρ Θ (app e e₁) = ap2 app (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
subst-rs ρ Θ (prod e e₁) = ap2 prod (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
subst-rs ρ Θ (l-proj e) = ap l-proj (subst-rs ρ Θ e)
subst-rs ρ Θ (r-proj e) = ap r-proj (subst-rs ρ Θ e)
subst-rs ρ Θ nil = Refl
subst-rs ρ Θ (e ::c e₁) = ap2 _::c_ (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
subst-rs ρ Θ true = Refl
subst-rs ρ Θ false = Refl
subst-rs ρ Θ (listrec e e₁ e₂) = ap3 listrec (subst-rs ρ Θ e) (subst-rs ρ Θ e₁)
(ap (subst e₂) (ap s-extend (ap s-extend (extend-rs-once ρ Θ)) ∘
extend-rs-twice (r-extend ρ) (s-extend Θ)) ∘
subst-rs (r-extend (r-extend (r-extend ρ))) (s-extend (s-extend (s-extend Θ))) e₂)
rs-comp : ∀ {Γ Γ' Γ'' τ} → (ρ : rctx Γ Γ') → (Θ : sctx Γ' Γ'') → (e : Γ'' |- τ)
→ (ren (subst e Θ) ρ) == subst e (ρ rs Θ)
rs-comp ρ Θ unit = Refl
rs-comp ρ Θ 0C = Refl
rs-comp ρ Θ 1C = Refl
rs-comp ρ Θ (plusC e e₁) = ap2 plusC (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
rs-comp ρ Θ (var x) = svar-rs ρ Θ x
rs-comp ρ Θ z = Refl
rs-comp ρ Θ (suc e) = ap suc (rs-comp ρ Θ e)
rs-comp ρ Θ (rec e e₁ e₂) = ap3 rec (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
(ap (subst e₂) (extend-rs-twice ρ Θ) ∘ rs-comp (r-extend (r-extend ρ)) (s-extend (s-extend Θ)) e₂)
rs-comp ρ Θ (lam e) = ap lam (ap (subst e) (extend-rs-once ρ Θ) ∘ rs-comp (r-extend ρ) (s-extend Θ) e)
rs-comp ρ Θ (app e e₁) = ap2 app (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
rs-comp ρ Θ (prod e e₁) = ap2 prod (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
rs-comp ρ Θ (l-proj e) = ap l-proj (rs-comp ρ Θ e)
rs-comp ρ Θ (r-proj e) = ap r-proj (rs-comp ρ Θ e)
rs-comp ρ Θ nil = Refl
rs-comp ρ Θ (e ::c e₁) = ap2 _::c_ (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
rs-comp ρ Θ (listrec e e₁ e₂) = ap3 listrec (rs-comp ρ Θ e) (rs-comp ρ Θ e₁)
(ap (subst e₂) (ap s-extend (ap s-extend (extend-rs-once ρ Θ)) ∘
extend-rs-twice (r-extend ρ) (s-extend Θ)) ∘
rs-comp (r-extend (r-extend (r-extend ρ)))
(s-extend (s-extend (s-extend Θ))) e₂)
rs-comp ρ Θ true = Refl
rs-comp ρ Θ false = Refl
extend-sr-once-lemma : ∀ {A B C τ τ'} → (Θ : sctx A B) (ρ : rctx B C) (x : τ ∈ τ' :: C)
→ _==_ {_} {τ' :: A |- τ} (s-extend (_sr_ Θ ρ) x) (_sr_ (s-extend Θ) (r-extend ρ) x)
extend-sr-once-lemma Θ ρ i0 = Refl
extend-sr-once-lemma Θ ρ (iS x) = Refl
extend-sr-once : ∀ {A B C τ} → (Θ : sctx A B) (ρ : rctx B C)
→ Id {_} {sctx (τ :: A) (τ :: C)} (s-extend Θ sr r-extend ρ) (s-extend (Θ sr ρ))
extend-sr-once Θ ρ = λ=i (λ τ → λ= (λ x → ! (extend-sr-once-lemma Θ ρ x)))
extend-sr-twice : ∀ {A B C τ τ'} → (Θ : sctx A B) (ρ : rctx B C)
→ Id {_} {sctx (τ' :: τ :: A) (τ' :: τ :: C)}
(s-extend (s-extend Θ) sr r-extend (r-extend ρ)) (s-extend (s-extend (Θ sr ρ)))
extend-sr-twice Θ ρ = ap s-extend (extend-sr-once Θ ρ) ∘ extend-sr-once (s-extend Θ) (r-extend ρ)
sr-comp : ∀ {Γ Γ' Γ'' τ} → (Θ : sctx Γ Γ') → (ρ : rctx Γ' Γ'') → (e : Γ'' |- τ)
→ (subst (ren e ρ) Θ) == subst e (Θ sr ρ)
sr-comp Θ ρ unit = Refl
sr-comp Θ ρ 0C = Refl
sr-comp Θ ρ 1C = Refl
sr-comp Θ ρ (plusC e e₁) = ap2 plusC (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
sr-comp Θ ρ (var x) = svar-sr Θ ρ x
sr-comp Θ ρ z = Refl
sr-comp Θ ρ (suc e) = ap suc (sr-comp Θ ρ e)
sr-comp Θ ρ (rec e e₁ e₂) = ap3 rec (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
(ap (subst e₂) (ap s-extend (extend-sr-once Θ ρ) ∘
extend-sr-once (s-extend Θ) (r-extend ρ)) ∘
sr-comp (s-extend (s-extend Θ)) (r-extend (r-extend ρ)) e₂)
sr-comp Θ ρ (lam e) = ap lam (ap (subst e) (extend-sr-once Θ ρ) ∘ sr-comp (s-extend Θ) (r-extend ρ) e)
sr-comp Θ ρ (app e e₁) = ap2 app (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
sr-comp Θ ρ (prod e e₁) = ap2 prod (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
sr-comp Θ ρ (l-proj e) = ap l-proj (sr-comp Θ ρ e)
sr-comp Θ ρ (r-proj e) = ap r-proj (sr-comp Θ ρ e)
sr-comp Θ ρ nil = Refl
sr-comp Θ ρ (e ::c e₁) = ap2 _::c_ (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
sr-comp Θ ρ (listrec e e₁ e₂) = ap3 listrec (sr-comp Θ ρ e) (sr-comp Θ ρ e₁)
(ap (subst e₂) (ap s-extend (ap s-extend (extend-sr-once Θ ρ)) ∘
extend-sr-twice (s-extend Θ) (r-extend ρ)) ∘
sr-comp (s-extend (s-extend (s-extend Θ)))
(r-extend (r-extend (r-extend ρ))) e₂)
sr-comp Θ ρ true = Refl
sr-comp Θ ρ false = Refl
extend-ss-once-lemma : ∀ {A B C τ τ'} → (Θ1 : sctx A B) (Θ2 : sctx B C) (x : τ ∈ τ' :: C)
→ _==_ {_} {τ' :: A |- τ} (s-extend (_ss_ Θ1 Θ2) x) (_ss_ (s-extend Θ1) (s-extend Θ2) x)
extend-ss-once-lemma Θ1 Θ2 i0 = Refl
extend-ss-once-lemma Θ1 Θ2 (iS x) = ! (sr-comp (s-extend Θ1) iS (Θ2 x)) ∘ rs-comp iS Θ1 (Θ2 x)
extend-ss-once : ∀ {A B C τ} → (Θ1 : sctx A B) (Θ2 : sctx B C)
→ _==_ {_} {sctx (τ :: A) (τ :: C)} (s-extend (Θ1 ss Θ2))
((s-extend Θ1) ss
(s-extend Θ2))
extend-ss-once Θ1 Θ2 = λ=i (λ τ → λ= (λ x → extend-ss-once-lemma Θ1 Θ2 x))
subst-ss : ∀ {A B C τ} → (Θ1 : sctx A B) (Θ2 : sctx B C) (e : C |- τ)
→ subst e (Θ1 ss Θ2) == subst (subst e Θ2) Θ1
subst-ss Θ1 Θ2 unit = Refl
subst-ss Θ1 Θ2 0C = Refl
subst-ss Θ1 Θ2 1C = Refl
subst-ss Θ1 Θ2 (plusC e e₁) = ap2 plusC (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
subst-ss Θ1 Θ2 (var x) = svar-ss Θ1 Θ2 x
subst-ss Θ1 Θ2 z = Refl
subst-ss Θ1 Θ2 (suc e) = ap suc (subst-ss Θ1 Θ2 e)
subst-ss Θ1 Θ2 (rec e e₁ e₂) = ap3 rec (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
(subst-ss (s-extend (s-extend Θ1)) (s-extend (s-extend Θ2)) e₂ ∘
ap (subst e₂) (extend-ss-once (s-extend Θ1) (s-extend Θ2) ∘
ap s-extend (extend-ss-once Θ1 Θ2)))
subst-ss Θ1 Θ2 (lam e) = ap lam (subst-ss (s-extend Θ1) (s-extend Θ2) e ∘ ap (subst e) (extend-ss-once Θ1 Θ2))
subst-ss Θ1 Θ2 (app e e₁) = ap2 app (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
subst-ss Θ1 Θ2 (prod e e₁) = ap2 prod (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
subst-ss Θ1 Θ2 (l-proj e) = ap l-proj (subst-ss Θ1 Θ2 e)
subst-ss Θ1 Θ2 (r-proj e) = ap r-proj (subst-ss Θ1 Θ2 e)
subst-ss Θ1 Θ2 nil = Refl
subst-ss Θ1 Θ2 (e ::c e₁) = ap2 _::c_ (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
subst-ss Θ1 Θ2 true = Refl
subst-ss Θ1 Θ2 false = Refl
subst-ss Θ1 Θ2 (listrec e e₁ e₂) = ap3 listrec (subst-ss Θ1 Θ2 e) (subst-ss Θ1 Θ2 e₁)
(subst-ss (s-extend (s-extend (s-extend Θ1))) (s-extend (s-extend (s-extend Θ2))) e₂ ∘
ap (subst e₂) (extend-ss-once (s-extend (s-extend Θ1)) (s-extend (s-extend Θ2)) ∘
ap s-extend (extend-ss-once (s-extend Θ1) (s-extend Θ2) ∘
ap s-extend (extend-ss-once Θ1 Θ2))))
throw : ∀ {Γ Γ' τ} → sctx Γ (τ :: Γ') → sctx Γ Γ'
throw Θ x = Θ (iS x)
fuse1 : ∀ {Γ Γ' τ τ'} (v : Γ |- τ') (Θ : sctx Γ Γ') (x : τ ∈ Γ') → (q v ss q∙ Θ) x == Θ x
fuse1 v Θ x = subst (ren (Θ x) iS) (q v) =⟨ sr-comp (q v) iS (Θ x) ⟩
subst (Θ x) (q v sr iS) =⟨ Refl ⟩
subst (Θ x) ids =⟨ ! (subst-id (Θ x)) ⟩
(Θ x ∎)
subst-compose-lemma-lemma : ∀ {Γ Γ' τ τ'} (v : Γ |- τ') (Θ : sctx Γ Γ') (x : τ ∈ τ' :: Γ')
→ _==_ {_} {Γ |- τ} (_ss_ (q v) (s-extend Θ) x) (lem3' Θ v x)
subst-compose-lemma-lemma v Θ i0 = Refl
subst-compose-lemma-lemma v Θ (iS x) = fuse1 v Θ x
subst-compose-lemma : ∀ {Γ Γ' τ} (v : Γ |- τ) (Θ : sctx Γ Γ')
→ _==_ {_} {sctx Γ (τ :: Γ')} ((q v) ss (s-extend Θ)) (lem3' Θ v)
subst-compose-lemma v Θ = λ=i (λ τ → λ= (λ x → subst-compose-lemma-lemma v Θ x))
subst-compose : ∀ {Γ Γ' τ τ1} (Θ : sctx Γ Γ') (v : Γ |- τ) (e : (τ :: Γ' |- τ1) )
→ subst (subst e (s-extend Θ)) (q v) == subst e (lem3' Θ v)
subst-compose Θ v e = ap (subst e) (subst-compose-lemma v Θ) ∘ (! (subst-ss (q v) (s-extend Θ) e))
fuse2 : ∀ {Γ Γ' τ τ1 τ2} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (Θ : sctx Γ Γ') (x : τ ∈ τ2 :: Γ')
→ (lem4 v1 v2 ss throw (s-extend (s-extend Θ))) x == (lem3' Θ v2) x
fuse2 v1 v2 Θ x = subst (ren (s-extend Θ x) iS) (lem4 v1 v2) =⟨ sr-comp (lem4 v1 v2) iS (s-extend Θ x) ⟩
subst (s-extend Θ x) (lem4 v1 v2 sr iS) =⟨ Refl ⟩
subst (s-extend Θ x) (lem3' ids v2) =⟨ subst-compose-lemma-lemma v2 Θ x ⟩
(lem3' Θ v2 x ∎)
subst-compose2-lemma-lemma : ∀ {Γ Γ' τ τ1 τ2 τ'} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (e1 : τ1 :: τ2 :: Γ' |- τ) (Θ : sctx Γ Γ') (x : τ' ∈ τ1 :: τ2 :: Γ')
→ _==_ {_} {_} ((lem4 v1 v2 ss s-extend (s-extend Θ)) x) (lem4' Θ v1 v2 x)
subst-compose2-lemma-lemma v1 v2 e1 Θ i0 = Refl
subst-compose2-lemma-lemma v1 v2 e1 Θ (iS x) = fuse2 v1 v2 Θ x
subst-compose2-lemma : ∀ {Γ Γ' τ τ1 τ2} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (e1 : τ1 :: τ2 :: Γ' |- τ) (Θ : sctx Γ Γ')
→ _==_ {_} {sctx Γ (τ1 :: τ2 :: Γ')} (lem4 v1 v2 ss s-extend (s-extend Θ)) (lem4' Θ v1 v2)
subst-compose2-lemma v1 v2 e1 Θ = λ=i (λ τ → λ= (λ x → subst-compose2-lemma-lemma v1 v2 e1 Θ x))
fuse3 : ∀ {Γ Γ' τ1 τ2 τ'} (Θ : sctx Γ Γ') (v1 : Γ' |- τ1) (v2 : Γ' |- τ2) (x : τ' ∈ τ2 :: Γ')
→ subst (lem3' ids v2 x) Θ == lem3' Θ (subst v2 Θ) x
fuse3 Θ v1 v2 i0 = Refl
fuse3 Θ v1 v2 (iS x) = Refl
subst-compose3-lemma-lemma : ∀ {Γ Γ' τ τ1 τ2 τ'} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ' |- τ1) (v2 : Γ' |- τ2) (x : τ' ∈ τ1 :: τ2 :: Γ')
→ _==_ {_} {_} ((Θ ss lem4 v1 v2) x) (lem4' Θ (subst v1 Θ) (subst v2 Θ) x)
subst-compose3-lemma-lemma Θ e1 v1 v2 i0 = Refl
subst-compose3-lemma-lemma Θ e1 v1 v2 (iS x) = fuse3 Θ v1 v2 x
subst-compose3-lemma : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ' |- τ1) (v2 : Γ' |- τ2)
→ _==_ {_} {sctx Γ (τ1 :: τ2 :: Γ')} (Θ ss lem4 v1 v2) (lem4' Θ (subst v1 Θ) (subst v2 Θ))
subst-compose3-lemma Θ e1 v1 v2 = λ=i (λ τ → λ= (λ x → subst-compose3-lemma-lemma Θ e1 v1 v2 x))
subst-compose2 : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ |- τ1) (v2 : Γ |- τ2)
→ subst (subst e1 (s-extend (s-extend Θ))) (lem4 v1 v2) == subst e1 (lem4' Θ v1 v2)
subst-compose2 Θ e1 v1 v2 = ap (subst e1) (subst-compose2-lemma v1 v2 e1 Θ) ∘
! (subst-ss (lem4 v1 v2) (s-extend (s-extend Θ)) e1)
subst-compose3 : ∀ {Γ Γ' τ τ1 τ2} (Θ : sctx Γ Γ') (e1 : (τ1 :: (τ2 :: Γ')) |- τ) (v1 : Γ' |- τ1) (v2 : Γ' |- τ2)
→ subst (subst e1 (lem4 v1 v2)) Θ == subst e1 (lem4' Θ (subst v1 Θ) (subst v2 Θ))
subst-compose3 Θ e1 v1 v2 = ap (subst e1) (subst-compose3-lemma Θ e1 v1 v2) ∘ ! (subst-ss Θ (lem4 v1 v2) e1)
subst-compose4 : ∀ {Γ Γ' τ} (Θ : sctx Γ Γ') (v' : Γ |- nat) (r : Γ |- τ) (e2 : (nat :: (τ :: Γ')) |- τ)
→ subst (subst e2 (s-extend (s-extend Θ))) (lem4 v' r) == subst e2 (lem4' Θ v' r)
subst-compose4 Θ v' r e2 = subst-compose2 Θ e2 v' r
fuse4-lemma : ∀ {Γ Γ' τ τ1 τ2 τ3} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3) (Θ : sctx Γ Γ') (x : τ ∈ Γ')
→ (lem3' (lem3' ids v3) v2 ss q∙ (q∙ Θ)) x == Θ x
fuse4-lemma v1 v2 v3 Θ x = subst (ren (wkn (Θ x)) iS) (lem3' (q v3) v2) =⟨ sr-comp (lem3' (q v3) v2) iS (wkn (Θ x)) ⟩
subst (wkn (Θ x)) (lem3' (q v3) v2 sr iS) =⟨ Refl ⟩
subst (ren (Θ x) iS) (lem3' (q v3) v2 sr iS) =⟨ sr-comp (lem3' (q v3) v2 sr iS) iS (Θ x) ⟩
subst (Θ x) ((lem3' (q v3) v2 sr iS) sr iS) =⟨ Refl ⟩
subst (Θ x) ids =⟨ ! (subst-id (Θ x)) ⟩
(Θ x ∎)
fuse4 : ∀ {Γ Γ' τ τ1 τ2 τ3} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3) (Θ : sctx Γ Γ') (x : τ ∈ τ2 :: τ3 :: Γ')
→ subst (s-extend (s-extend Θ) x) (lem3' (lem3' ids v3) v2) == lem3' (lem3' Θ v3) v2 x
fuse4 v1 v2 v3 Θ i0 = Refl
fuse4 v1 v2 v3 Θ (iS i0) = Refl
fuse4 v1 v2 v3 Θ (iS (iS x)) = subst (wkn (wkn (Θ x))) (lem3' (lem3' ids v3) v2) =⟨ subst-ss (lem3' (lem3' ids v3) v2) (q∙ (q∙ Θ)) (var x) ⟩
subst (var x) (lem3' (lem3' ids v3) v2 ss q∙ (q∙ Θ)) =⟨ fuse4-lemma v1 v2 v3 Θ x ⟩
subst (var x) Θ =⟨ Refl ⟩
(Θ x ∎)
subst-compose5-lemma-lemma : ∀ {Γ Γ' τ τ1 τ2 τ3 τ'} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3) (e1 : τ1 :: τ2 :: τ3 :: Γ' |- τ) (Θ : sctx Γ Γ') (x : τ' ∈ τ1 :: τ2 :: τ3 :: Γ')
→ _==_ {_} {_} ((lem5 v1 v2 v3 ss s-extend (s-extend (s-extend Θ))) x) (lem5' Θ v1 v2 v3 x)
subst-compose5-lemma-lemma v1 v2 v3 e Θ i0 = Refl
subst-compose5-lemma-lemma v1 v2 v3 e Θ (iS x) = (lem5 v1 v2 v3 ss s-extend (s-extend (s-extend Θ))) (iS x) =⟨ sr-comp (lem5 v1 v2 v3) iS (s-extend (s-extend Θ) x) ⟩
subst (s-extend (s-extend Θ) x) (lem3' (lem3' ids v3) v2) =⟨ fuse4 v1 v2 v3 Θ x ⟩
(lem3' (lem3' Θ v3) v2 x ∎)
subst-compose5-lemma : ∀ {Γ Γ' τ τ1 τ2 τ3} (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3) (e : τ1 :: τ2 :: τ3 :: Γ' |- τ) (Θ : sctx Γ Γ')
→ _==_ {_} {sctx Γ (τ1 :: τ2 :: τ3 :: Γ')} (lem5 v1 v2 v3 ss (s-extend (s-extend (s-extend Θ)))) (lem5' Θ v1 v2 v3)
subst-compose5-lemma v1 v2 v3 e Θ = λ=i (λ τ → λ= (λ x → subst-compose5-lemma-lemma v1 v2 v3 e Θ x))
subst-compose5 : ∀ {Γ Γ' τ τ1 τ2 τ3} (Θ : sctx Γ Γ') (e : (τ1 :: (τ2 :: (τ3 :: Γ'))) |- τ) (v1 : Γ |- τ1) (v2 : Γ |- τ2) (v3 : Γ |- τ3)
→ subst (subst e (s-extend (s-extend (s-extend (Θ))))) (lem5 v1 v2 v3) == subst e (lem5' Θ v1 v2 v3)
subst-compose5 Θ e v1 v2 v3 = ap (subst e) (subst-compose5-lemma v1 v2 v3 e Θ) ∘
! (subst-ss (lem5 v1 v2 v3) (s-extend (s-extend (s-extend Θ))) e)
-------
-- define 'stepping' as a datatype (fig. 1 of proof)
data _≤s_ : ∀ {Γ T} → Γ |- T → Γ |- T → Set where
refl-s : ∀ {Γ T}
→ {e : Γ |- T}
→ e ≤s e
trans-s : ∀ {Γ T}
→ {e e' e'' : Γ |- T}
→ e ≤s e' → e' ≤s e''
→ e ≤s e''
plus-s : ∀ {Γ}
→ {e1 e2 n1 n2 : Γ |- C}
→ e1 ≤s n1 → e2 ≤s n2
→ (plusC e1 e2) ≤s (plusC n1 n2)
cong-refl : ∀ {Γ τ} {e e' : Γ |- τ} → e == e' → e ≤s e'
+-unit-l : ∀ {Γ} {e : Γ |- C} → (plusC 0C e) ≤s e
+-unit-l' : ∀ {Γ} {e : Γ |- C} → e ≤s (plusC 0C e)
+-unit-r : ∀ {Γ} {e : Γ |- C} → (plusC e 0C) ≤s e
+-unit-r' : ∀ {Γ} {e : Γ |- C} → e ≤s (plusC e 0C)
+-1-r : ∀ {Γ} {e : Γ |- C} → e ≤s (plusC e 1C)
+-assoc : ∀ {Γ} {e1 e2 e3 : Γ |- C} → (plusC e1 (plusC e2 e3)) ≤s (plusC (plusC e1 e2) e3)
+-assoc' : ∀ {Γ} {e1 e2 e3 : Γ |- C} → (plusC e1 (plusC e2 e3)) ≤s (plusC (plusC e1 e2) e3)
refl-+ : ∀ {Γ} {e0 e1 : Γ |- C} → (plusC e0 e1) ≤s (plusC e1 e0)
cong-+ : ∀ {Γ} {e0 e1 e0' e1' : Γ |- C} → e0 ≤s e0' → e1 ≤s e1' → (plusC e0 e1) ≤s (plusC e0' e1')
cong-lproj : ∀ {Γ τ τ'} {e e' : Γ |- (τ ×c τ')} → e ≤s e' → (l-proj e) ≤s (l-proj e')
cong-rproj : ∀ {Γ τ τ'} {e e' : Γ |- (τ ×c τ')} → e ≤s e' → (r-proj e) ≤s (r-proj e')
cong-app : ∀ {Γ τ τ'} {e e' : Γ |- (τ ->c τ')} {e1 : Γ |- τ} → e ≤s e' → (app e e1) ≤s (app e' e1)
cong-rec : ∀ {Γ τ} {e e' : Γ |- nat} {e0 : Γ |- τ} {e1 : (nat :: (τ :: Γ)) |- τ}
→ e ≤s e'
→ rec e e0 e1 ≤s rec e' e0 e1
cong-listrec : ∀ {Γ τ τ'} {e e' : Γ |- list τ} {e0 : Γ |- τ'} {e1 : (τ :: (list τ :: (τ' :: Γ))) |- τ'}
→ e ≤s e'
→ listrec e e0 e1 ≤s listrec e' e0 e1
lam-s : ∀ {Γ T T'}
→ {e : (T :: Γ) |- T'}
→ {e2 : Γ |- T}
→ subst e (q e2) ≤s app (lam e) e2
l-proj-s : ∀ {Γ T1 T2}
→ {e1 : Γ |- T1} {e2 : Γ |- T2}
→ e1 ≤s (l-proj (prod e1 e2))
r-proj-s : ∀ {Γ T1 T2}
→ {e1 : Γ |- T1} → {e2 : Γ |- T2}
→ e2 ≤s (r-proj (prod e1 e2))
rec-steps-z : ∀ {Γ T}
→ {e0 : Γ |- T}
→ {e1 : (nat :: (T :: Γ)) |- T}
→ e0 ≤s (rec z e0 e1)
rec-steps-s : ∀ {Γ T}
→ {e : Γ |- nat}
→ {e0 : Γ |- T}
→ {e1 : (nat :: (T :: Γ)) |- T}
→ subst e1 (lem4 e (rec e e0 e1)) ≤s (rec (suc e) e0 e1)
listrec-steps-nil : ∀ {Γ τ τ'}
→ {e0 : Γ |- τ'}
→ {e1 : (τ :: (list τ :: (τ' :: Γ))) |- τ'}
→ e0 ≤s (listrec nil e0 e1)
listrec-steps-cons : ∀ {Γ τ τ'}
→ {h : Γ |- τ} {t : Γ |- list τ}
→ {e0 : Γ |- τ'}
→ {e1 : (τ :: (list τ :: (τ' :: Γ))) |- τ'}
→ subst e1 (lem5 h t (listrec t e0 e1)) ≤s (listrec (h ::c t) e0 e1)
_trans_ : ∀ {Γ T}
→ {e e' e'' : Γ |- T}
→ e ≤s e' → e' ≤s e''
→ e ≤s e''
_trans_ = trans-s
infixr 10 _trans_
| {
"alphanum_fraction": 0.4611105559,
"avg_line_length": 48.3429951691,
"ext": "agda",
"hexsha": "18669f7511e4e7a85d6021c69a312010bdae1f1a",
"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": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "benhuds/Agda",
"max_forks_repo_path": "complexity/Complexity.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_issues_repo_issues_event_max_datetime": "2020-05-12T00:32:45.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-23T08:39:04.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "benhuds/Agda",
"max_issues_repo_path": "complexity/Complexity.agda",
"max_line_length": 179,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "benhuds/Agda",
"max_stars_repo_path": "complexity/Complexity.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-08T12:27:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-26T20:22:22.000Z",
"num_tokens": 13731,
"size": 30021
} |
-- Andreas, 2017-01-24, issue #2430, reported by nad
-- Regression introduced by updating module parameter substitution
-- when going underAbstraction (80794767db1aceaa78a72e06ad901cfa53f8346d).
record Σ (A : Set) (B : A → Set) : Set where
field
proj₁ : A
proj₂ : B proj₁
open Σ public
Σ-map : {A : Set} {B : Set} {P : A → Set} {Q : B → Set} →
(f : A → B) → (∀ {x} → P x → Q (f x)) →
Σ A P → Σ B Q
Σ-map f g p = record { proj₁ = f (proj₁ p); proj₂ = g (proj₂ p) }
postulate
_≡_ : {A : Set} → A → A → Set
refl : {A : Set} (x : A) → x ≡ x
cong : {A : Set} {B : Set} (f : A → B) {x y : A} →
x ≡ y → f x ≡ f y
cong-refl : {A : Set} {B : Set} (f : A → B) {x : A} →
refl (f x) ≡ cong f (refl x)
subst : {A : Set} (P : A → Set) {x y : A} →
x ≡ y → P x → P y
subst-refl : ∀ {A : Set} (P : A → Set) {x} (p : P x) →
subst P (refl x) p ≡ p
trans : {A : Set} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
module _ (_ : Set) where
postulate
Σ-≡,≡→≡ : {A : Set} {B : A → Set} {p₁ p₂ : Σ A B} →
(p : proj₁ p₁ ≡ proj₁ p₂) →
subst B p (proj₂ p₁) ≡ proj₂ p₂ →
p₁ ≡ p₂
Σ-≡,≡→≡-refl-subst-refl :
∀ {A : Set} {B : A → Set} {p} →
Σ-≡,≡→≡ (refl (proj₁ p)) (subst-refl B (proj₂ p)) ≡ refl p
rejected :
{A₁ A₂ : Set} {B₁ : A₁ → Set} {B₂ : A₂ → Set}
(f : A₁ → A₂) (g : ∀ x → B₁ x → B₂ (f x)) (x : Σ A₁ B₁) →
Σ-≡,≡→≡ (refl _) (subst-refl B₂ _) ≡ cong (Σ-map f (g _)) (refl x)
rejected {B₁ = B₁} {B₂} f g x =
trans {x = Σ-≡,≡→≡ (refl _) (subst-refl B₂ _)}
{z = cong (Σ-map f (g _)) (refl _)}
Σ-≡,≡→≡-refl-subst-refl
(cong-refl _)
| {
"alphanum_fraction": 0.4361763022,
"avg_line_length": 32.3518518519,
"ext": "agda",
"hexsha": "b2c8edce0b88ee9bda877e7b79c82d9d5b59e655",
"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/Issue2430.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/Issue2430.agda",
"max_line_length": 74,
"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/Issue2430.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": 799,
"size": 1747
} |
module Generic.Lib.Intro where
open import Level renaming (zero to lzero; suc to lsuc) public
open import Function public
open import Data.Bool.Base hiding (_<_; _≤_) public
infixl 10 _%
infixl 2 _>>>_
data ⊥ {α} : Set α where
record ⊤ {α} : Set α where
instance constructor tt
⊥₀ = ⊥ {lzero}
⊤₀ = ⊤ {lzero}
tt₀ : ⊤₀
tt₀ = tt
_% = _∘_
_>>>_ : ∀ {α β γ} {A : Set α} {B : A -> Set β} {C : ∀ {x} -> B x -> Set γ}
-> (f : ∀ x -> B x) -> (∀ {x} -> (y : B x) -> C y) -> ∀ x -> C (f x)
(f >>> g) x = g (f x)
| {
"alphanum_fraction": 0.5299806576,
"avg_line_length": 20.68,
"ext": "agda",
"hexsha": "7a3e0188ada5c8eb43ba0ce1f313f3534c51e4c8",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2021-01-27T12:57:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-07-17T07:23:39.000Z",
"max_forks_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "turion/Generic",
"max_forks_repo_path": "src/Generic/Lib/Intro.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_issues_repo_issues_event_max_datetime": "2022-01-04T15:43:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-04-06T18:58:09.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "turion/Generic",
"max_issues_repo_path": "src/Generic/Lib/Intro.agda",
"max_line_length": 74,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "turion/Generic",
"max_stars_repo_path": "src/Generic/Lib/Intro.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T10:19:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-19T21:10:54.000Z",
"num_tokens": 213,
"size": 517
} |
{-# OPTIONS --postfix-projections #-}
module UnSizedIO.Base where
open import Data.Maybe.Base
open import Data.Sum renaming (inj₁ to left; inj₂ to right; [_,_]′ to either)
open import Function
open import NativeIO
record IOInterface : Set₁ where
field
Command : Set
Response : (m : Command) → Set
open IOInterface public
module _ (I : IOInterface) (let C = Command I) (let R = Response I) (A : Set)
where
mutual
record IO : Set where
coinductive
constructor delay
field
force : IO'
data IO' : Set where
exec' : (c : C) (f : R c → IO) → IO'
return' : (a : A) → IO'
open IO public
module _ {I : IOInterface} (let C = Command I) (let R = Response I)
where
return : ∀{A} (a : A) → IO I A
return a .force = return' a
exec : ∀{A} (c : C) (f : R c → IO I A) → IO I A
exec c f .force = exec' c f
exec1 : (c : C) → IO I (R c)
exec1 c = exec c return
infixl 2 _>>=_ _>>='_ _>>_
mutual
_>>='_ : ∀{A B} (m : IO' I A) (k : A → IO I B) → IO' I B
exec' c f >>=' k = exec' c λ x → f x >>= k
return' a >>=' k = force (k a)
_>>=_ : ∀{A B} (m : IO I A) (k : A → IO I B) → IO I B
force (m >>= k) = force m >>=' k
_>>_ : ∀{B} (m : IO I Unit) (k : IO I B) → IO I B
m >> k = m >>= λ _ → k
module _ {I : IOInterface} (let C = Command I) (let R = Response I)
where
{-# NON_TERMINATING #-}
translateIO : ∀ {A}
→ (translateLocal : (c : C) → NativeIO (R c))
→ IO I A
→ NativeIO A
translateIO translateLocal m = case (m .force) of
λ{ (exec' c f) → (translateLocal c) native>>= λ r →
translateIO translateLocal (f r)
; (return' a) → nativeReturn a
}
-- Recursion
-- trampoline provides a generic form of loop (generalizing while/repeat).
-- Starting at state s : S, step function f is iterated until it returns
-- a result in A.
module _ (I : IOInterface)(let C = Command I) (let R = Response I)
where
data IO+ (A : Set) : Set where
exec' : (c : C) (f : R c → IO I A) → IO+ A
module _ {I : IOInterface}(let C = Command I) (let R = Response I)
where
fromIO+' : ∀{A} → IO+ I A → IO' I A
fromIO+' (exec' c f) = exec' c f
fromIO+ : ∀{A} → IO+ I A → IO I A
fromIO+ (exec' c f) .force = exec' c f
_>>=+'_ : ∀{A B} (m : IO+ I A) (k : A → IO I B) → IO' I B
exec' c f >>=+' k = exec' c λ x → f x >>= k
_>>=+_ : ∀{A B} (m : IO+ I A) (k : A → IO I B) → IO I B
force (m >>=+ k) = m >>=+' k
mutual
_>>+_ : ∀{A B} (m : IO I (A ⊎ B)) (k : A → IO I B) → IO I B
force (m >>+ k) = force m >>+' k
_>>+'_ : ∀{A B} (m : IO' I (A ⊎ B)) (k : A → IO I B) → IO' I B
exec' c f >>+' k = exec' c λ x → f x >>+ k
return' (left a) >>+' k = force (k a)
return' (right b) >>+' k = return' b
-- loop
{-# TERMINATING #-}
trampoline : ∀{A S} (f : S → IO+ I (S ⊎ A)) (s : S) → IO I A
force (trampoline f s) = case (f s) of
\{ (exec' c k) → exec' c λ r → k r >>+ trampoline f }
-- simple infinite loop
{-# TERMINATING #-}
forever : ∀{A B} → IO+ I A → IO I B
force (forever (exec' c f)) = exec' c λ r → f r >>= λ _ → forever (exec' c f)
whenJust : {A : Set} → Maybe A → (A → IO I Unit) → IO I Unit
whenJust nothing k = return _
whenJust (just a) k = k a
module _ (I : IOInterface )
(let C = I .Command)
(let R = I .Response)
where
data IOind (A : Set) : Set where
exec'' : (c : C) (f : (r : R c) → IOind A) → IOind A
return'' : (a : A) → IOind A
main : NativeIO Unit
main = nativePutStrLn "Hello, world!"
| {
"alphanum_fraction": 0.5083426029,
"avg_line_length": 26.2481751825,
"ext": "agda",
"hexsha": "456a07ff9bf41caca8631312e4aed951becf70d4",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "src/UnSizedIO/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/ooAgda",
"max_issues_repo_path": "src/UnSizedIO/Base.agda",
"max_line_length": 79,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "src/UnSizedIO/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 1348,
"size": 3596
} |
{-# OPTIONS --safe #-}
module Definition.Typed.Consequences.Reduction where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.EqRelInstance
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Fundamental.Reducibility
import Tools.PropositionalEquality as PE
open import Tools.Product
-- Helper function where all reducible types can be reduced to WHNF.
whNorm′ : ∀ {A rA Γ l} ([A] : Γ ⊩⟨ l ⟩ A ^ rA)
→ ∃ λ B → Whnf B × Γ ⊢ A :⇒*: B ^ rA
whNorm′ (Uᵣ′ _ _ r l _ e d) = Univ r l , Uₙ , PE.subst (λ ll → _ ⊢ _ :⇒*: Univ r l ^ [ ! , ll ]) e d
whNorm′ (ℕᵣ D) = ℕ , ℕₙ , D
whNorm′ (Emptyᵣ {l = l} D) = Empty l , Emptyₙ , D
whNorm′ (ne′ K D neK K≡K) = K , ne neK , D
whNorm′ (Πᵣ {l = l} (Πᵣ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext)) = Π F ^ rF ° lF ▹ G ° lG ° l , Πₙ , D
whNorm′ (∃ᵣ′ F G D ⊢F ⊢G A≡A [F] [G] G-ext) = ∃ F ▹ G , ∃ₙ , D
whNorm′ (emb emb< [A]) = whNorm′ [A]
whNorm′ (emb ∞< [A]) = whNorm′ [A]
-- Well-formed types can all be reduced to WHNF.
whNorm : ∀ {A rA Γ} → Γ ⊢ A ^ rA → ∃ λ B → Whnf B × Γ ⊢ A :⇒*: B ^ rA
whNorm A = whNorm′ (reducible A)
-- whNorm-conv : ∀ {A rA Γ} → Γ ⊢ A ≡ B ^ rA → ∃ λ B → Whnf B × Γ ⊢ A :⇒*: B ^ rA
-- whNorm-conv A = whNorm′ (reducible A)
-- Helper function where reducible all terms can be reduced to WHNF.
whNormTerm′ : ∀ {a A Γ l lA} ([A] : Γ ⊩⟨ l ⟩ A ^ [ ! , lA ]) → Γ ⊩⟨ l ⟩ a ∷ A ^ [ ! , lA ] / [A]
→ ∃ λ b → Whnf b × Γ ⊢ a :⇒*: b ∷ A ^ lA
whNormTerm′ (Uᵣ′ _ _ r l _ e dU) (Uₜ A d typeA A≡A [t]) = A , typeWhnf typeA ,
conv:⇒*: (PE.subst (λ ll → _ ⊢ _ :⇒*: _ ∷ _ ^ ll) e d)
(sym (subset* (red (PE.subst (λ ll → _ ⊢ _ :⇒*: Univ r l ^ [ ! , ll ]) e dU))))
whNormTerm′ (ℕᵣ x) (ℕₜ n d n≡n prop) =
let natN = natural prop
in n , naturalWhnf natN , convRed:*: d (sym (subset* (red x)))
whNormTerm′ (ne (ne K D neK K≡K)) (neₜ k d (neNfₜ neK₁ ⊢k k≡k)) =
k , ne neK₁ , convRed:*: d (sym (subset* (red D)))
whNormTerm′ (Πᵣ′ rF lF lG lF≤ lG≤ F G D ⊢F ⊢G A≡A [F] [G] G-ext) (Πₜ f d funcF f≡f [f] [f]₁) =
f , functionWhnf funcF , convRed:*: d (sym (subset* (red D)))
whNormTerm′ (emb emb< [A]) [a] = whNormTerm′ [A] [a]
whNormTerm′ (emb ∞< [A]) [a] = whNormTerm′ [A] [a]
-- Well-formed terms can all be reduced to WHNF.
whNormTerm : ∀ {a A Γ lA} → Γ ⊢ a ∷ A ^ [ ! , lA ] → ∃ λ b → Whnf b × Γ ⊢ a :⇒*: b ∷ A ^ lA
whNormTerm {a} {A} ⊢a =
let [A] , [a] = reducibleTerm ⊢a
in whNormTerm′ [A] [a]
| {
"alphanum_fraction": 0.5596078431,
"avg_line_length": 42.5,
"ext": "agda",
"hexsha": "8b644cd0c5275b3e95239ab5d6c99f0bde3af3d0",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/Typed/Consequences/Reduction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"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": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/Typed/Consequences/Reduction.agda",
"max_line_length": 110,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/Typed/Consequences/Reduction.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 1162,
"size": 2550
} |
-- Andreas, 2015-05-28 example by Andrea Vezzosi
open import Common.Size
data Nat (i : Size) : Set where
zero : ∀ (j : Size< i) → Nat i
suc : ∀ (j : Size< i) → Nat j → Nat i
{-# TERMINATING #-}
-- This definition is fine, the termination checker is too strict at the moment.
fix : ∀ {C : Size → Set} → (∀ i → (∀ (j : Size< i) → Nat j -> C j) → Nat i → C i) → ∀ i → Nat i → C i
fix t i (zero j) = t i (λ (j : Size< i) → fix t j) (zero j)
fix t i (suc j n) = t i (λ (j : Size< i) → fix t j) (suc j n)
case : ∀ i {C : Set} (n : Nat i) (z : C) (s : ∀ (j : Size< i) → Nat j → C) → C
case i (zero j) z s = z
case i (suc j n) z s = s j n
applyfix : ∀ {C : Size → Set} i (n : Nat i)
→ (∀ i → (∀ (j : Size< i) → Nat j -> C j) → Nat i → C i)
→ C i
applyfix i n f = fix f i n
module M (i0 : Size) (bot : ∀{i} → Nat i) (A : Set) (default : A) where
loops : A
loops = applyfix (↑ i0) (zero i0) λ i r (_ : Nat i) →
case i bot default λ (j : Size< i) (n : Nat j) → -- Size< i is possibly empty, should be rejected
case j n default λ (h : Size< j) (_ : Nat h) →
r (↑ h) (zero h)
-- loops
-- --> fix t (↑ i0) (zero i0)
-- --> t (↑ i0) (fix t) (zero i0)
-- --> case i0 bot default λ j n → case j n default λ h _ → fix t (↑ h) (zero h)
-- and we have reproduced (modulo [h/i0]) what we started with
-- The above needs this inference to typecheck
-- h < j, j < i
-- ---------------------
-- ↑ h < i
| {
"alphanum_fraction": 0.5017301038,
"avg_line_length": 34.4047619048,
"ext": "agda",
"hexsha": "2e1de514bd6366dbdf632352472476debefae43c",
"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/Fail/Issue1523.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/Fail/Issue1523.agda",
"max_line_length": 105,
"max_stars_count": 3,
"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/Issue1523.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": 570,
"size": 1445
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties satisfied by decidable total orders
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Relation.Binary.Properties.DecTotalOrder
{d₁ d₂ d₃} (DT : DecTotalOrder d₁ d₂ d₃) where
open Relation.Binary.DecTotalOrder DT hiding (trans)
open import Relation.Binary.Construct.NonStrictToStrict _≈_ _≤_
strictTotalOrder : StrictTotalOrder _ _ _
strictTotalOrder = record
{ isStrictTotalOrder = <-isStrictTotalOrder₂ isDecTotalOrder
}
open StrictTotalOrder strictTotalOrder public
| {
"alphanum_fraction": 0.6151645207,
"avg_line_length": 30.3913043478,
"ext": "agda",
"hexsha": "693ca8a791e9cfa04c873acbd77b49d863de94ad",
"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/Relation/Binary/Properties/DecTotalOrder.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/Properties/DecTotalOrder.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/Relation/Binary/Properties/DecTotalOrder.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 142,
"size": 699
} |
{-# OPTIONS --without-K --safe #-}
module Data.List.Kleene where
open import Data.List.Kleene.Base public
| {
"alphanum_fraction": 0.7222222222,
"avg_line_length": 18,
"ext": "agda",
"hexsha": "27e786260f340044609c18bdc349b2f826cef7d8",
"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": "a7e99bc288e12e83440c891dbd3e5077d9b1657e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-kleene-lists",
"max_forks_repo_path": "Data/List/Kleene.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a7e99bc288e12e83440c891dbd3e5077d9b1657e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-kleene-lists",
"max_issues_repo_path": "Data/List/Kleene.agda",
"max_line_length": 40,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a7e99bc288e12e83440c891dbd3e5077d9b1657e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-kleene-lists",
"max_stars_repo_path": "Data/List/Kleene.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 26,
"size": 108
} |
module Dave.Algebra.Naturals.Multiplication where
open import Dave.Algebra.Naturals.Addition public
_*_ : ℕ → ℕ → ℕ
zero * b = zero
suc a * b = (a * b) + b
infixl 7 _*_
*-zero : ∀ (m : ℕ) → m * zero ≡ zero
*-zero zero = refl
*-zero (suc m) = begin
suc m * zero ≡⟨⟩
m * zero + zero ≡⟨ +-right-identity (m * zero) ⟩
m * zero ≡⟨ *-zero m ⟩
zero ∎
{- Identity -}
ℕ-*-right-identity : ∀ (m : ℕ) → m * 1 ≡ m
ℕ-*-right-identity zero = refl
ℕ-*-right-identity (suc m) = begin
suc m * 1 ≡⟨⟩
m * 1 + 1 ≡⟨ cong (λ a → a + 1) (ℕ-*-right-identity m) ⟩
m + 1 ≡⟨ +-add1ᵣ m ⟩
suc m ∎
ℕ-*-left-identity : ∀ (m : ℕ) → 1 * m ≡ m
ℕ-*-left-identity m = refl
ℕ-*-HasIdentity : Identity _*_ 1
Identity.left ℕ-*-HasIdentity = ℕ-*-left-identity
Identity.right ℕ-*-HasIdentity = ℕ-*-right-identity
{- Distributivity -}
*-distrib-+ᵣ : ∀ (m n p : ℕ) → (m + n) * p ≡ m * p + n * p
*-distrib-+ᵣ zero n p = refl
*-distrib-+ᵣ (suc m) n p = begin
(suc m + n) * p ≡⟨⟩
suc (m + n) * p ≡⟨⟩
(m + n) * p + p ≡⟨ cong (λ a → a + p) (*-distrib-+ᵣ m n p) ⟩
m * p + n * p + p ≡⟨ IsCommutativeMonoid.swap021 ℕ-+-IsCommutativeMonoid (m * p) (n * p) p ⟩
m * p + p + n * p ≡⟨ cong (λ a → m * p + a + n * p) (ℕ-*-left-identity p) ⟩
m * p + 1 * p + n * p ≡⟨ cong (λ a → a + n * p) (sym (*-distrib-+ᵣ m 1 p)) ⟩
(m + 1) * p + n * p ≡⟨ cong (λ a → a * p + n * p) (+-add1ᵣ m) ⟩
suc m * p + n * p ∎
*-distrib1ᵣ-+ᵣ : ∀ (m p : ℕ) → (m + 1) * p ≡ m * p + p
*-distrib1ᵣ-+ᵣ m p = begin
(m + 1) * p ≡⟨ *-distrib-+ᵣ m 1 p ⟩
m * p + 1 * p ≡⟨⟩
m * p + p ∎
*-distrib1ₗ-+ᵣ : ∀ (m p : ℕ) → (1 + m) * p ≡ p + m * p
*-distrib1ₗ-+ᵣ m p = begin
(1 + m) * p ≡⟨ *-distrib-+ᵣ 1 m p ⟩
1 * p + m * p ≡⟨⟩
p + m * p ∎
*-distrib-+ₗ : ∀ (m n p : ℕ) → m * (n + p) ≡ m * n + m * p
*-distrib-+ₗ zero n p = refl
*-distrib-+ₗ (suc m) n p = begin
suc m * (n + p) ≡⟨⟩
m * (n + p) + (n + p) ≡⟨ cong (λ a → a + (n + p)) (*-distrib-+ₗ m n p) ⟩
m * n + m * p + (n + p) ≡⟨ IsCommutativeMonoid.swap021 ℕ-+-IsCommutativeMonoid (m * n) (m * p) (n + p) ⟩
m * n + (n + p) + m * p ≡⟨ cong (λ a → a + m * p) (sym (IsSemigroup.assoc ℕ-+-IsSemigroup (m * n) n p)) ⟩
m * n + n + p + m * p ≡⟨ IsCommutativeMonoid.swap021 ℕ-+-IsCommutativeMonoid (m * n + n) p (m * p) ⟩
m * n + n + m * p + p ≡⟨⟩
m * n + 1 * n + m * p + 1 * p ≡⟨ cong (λ a → a + m * p + 1 * p) (sym (*-distrib-+ᵣ m 1 n)) ⟩
(m + 1) * n + m * p + 1 * p ≡⟨ IsSemigroup.assoc ℕ-+-IsSemigroup ((m + 1) * n) (m * p) (1 * p) ⟩
(m + 1) * n + (m * p + 1 * p) ≡⟨ cong (λ a → (m + 1) * n + a) (sym (*-distrib-+ᵣ m 1 p)) ⟩
(m + 1) * n + (m + 1) * p ≡⟨ cong (λ a → a * n + (m + 1) * p) (+-add1ᵣ m) ⟩
suc m * n + (m + 1) * p ≡⟨ cong (λ a → suc m * n + a * p) (+-add1ᵣ m) ⟩
suc m * n + suc m * p ∎
{- Semigroup -}
*-assoc : associative _*_
*-assoc zero n p = refl
*-assoc (suc m) n p = begin
(suc m * n) * p ≡⟨⟩
(m * n + n) * p ≡⟨ *-distrib-+ᵣ (m * n) n p ⟩
m * n * p + n * p ≡⟨⟩
m * n * p + 1 * (n * p) ≡⟨ cong (λ a → a + 1 * (n * p)) (*-assoc m n p) ⟩
m * (n * p) + 1 * (n * p) ≡⟨ sym (*-distrib-+ᵣ m 1 (n * p)) ⟩
(m + 1) * (n * p) ≡⟨ cong (λ a → a * (n * p)) (+-add1ᵣ m) ⟩
suc m * (n * p) ∎
ℕ-*-IsSemigroup : IsSemigroup _*_
IsSemigroup.assoc ℕ-*-IsSemigroup = *-assoc
ℕ-*-Semigroup : Semigroup
Semigroup.Carrier ℕ-*-Semigroup = ℕ
Semigroup._·_ ℕ-*-Semigroup = _*_
Semigroup.isSemigroup ℕ-*-Semigroup = ℕ-*-IsSemigroup
{- Monoid -}
ℕ-*-IsMonoid : IsMonoid _*_ 1
IsMonoid.semigroup ℕ-*-IsMonoid = ℕ-*-IsSemigroup
IsMonoid.identity ℕ-*-IsMonoid = ℕ-*-HasIdentity
ℕ-*-Monoid : Monoid
Monoid.Carrier ℕ-*-Monoid = ℕ
Monoid._·_ ℕ-*-Monoid = _*_
Monoid.e ℕ-*-Monoid = 1
Monoid.isMonoid ℕ-*-Monoid = ℕ-*-IsMonoid
{- Commutative Monoid -}
ℕ-*-comm : commutative _*_
ℕ-*-comm zero n = begin
zero * n ≡⟨⟩
zero ≡⟨ sym (*-zero n) ⟩
n * zero ∎
ℕ-*-comm (suc m) n = begin
suc m * n ≡⟨⟩
m * n + n ≡⟨ +-comm (m * n) n ⟩
n + m * n ≡⟨ sym (cong (λ a → a + m * n) (ℕ-*-right-identity n)) ⟩
n * 1 + m * n ≡⟨ cong (λ a → n * 1 + a) (ℕ-*-comm m n) ⟩
n * 1 + n * m ≡⟨ sym (*-distrib-+ₗ n 1 m) ⟩
n * (1 + m) ≡⟨⟩
n * suc m ∎
ℕ-*-IsCommutativeMonoid : IsCommutativeMonoid _*_ 1
IsCommutativeMonoid.isSemigroup ℕ-*-IsCommutativeMonoid = ℕ-*-IsSemigroup
IsCommutativeMonoid.leftIdentity ℕ-*-IsCommutativeMonoid = ℕ-*-left-identity
IsCommutativeMonoid.comm ℕ-*-IsCommutativeMonoid = ℕ-*-comm
ℕ-*-CommutativeMonoid : CommutativeMonoid
CommutativeMonoid.Carrier ℕ-*-CommutativeMonoid = ℕ
CommutativeMonoid._·_ ℕ-*-CommutativeMonoid = _*_
CommutativeMonoid.e ℕ-*-CommutativeMonoid = 1
CommutativeMonoid.isCommutativeMonoid ℕ-*-CommutativeMonoid = ℕ-*-IsCommutativeMonoid
*-distrib1ᵣ-+ₗ : ∀ (m p : ℕ) → m * (p + 1) ≡ m * p + m
*-distrib1ᵣ-+ₗ m p = begin
m * (p + 1) ≡⟨ ℕ-*-comm m (p + 1) ⟩
(p + 1) * m ≡⟨ *-distrib1ᵣ-+ᵣ p m ⟩
p * m + m ≡⟨ cong (λ a → a + m) (ℕ-*-comm p m) ⟩
m * p + m ∎
*-distrib1ₗ-+ₗ : ∀ (m p : ℕ) → m * (1 + p) ≡ m + m * p
*-distrib1ₗ-+ₗ m p = begin
m * (1 + p) ≡⟨ ℕ-*-comm m (1 + p) ⟩
(1 + p) * m ≡⟨ *-distrib1ₗ-+ᵣ p m ⟩
m + p * m ≡⟨ cong (λ a → m + a) (ℕ-*-comm p m) ⟩
m + m * p ∎
| {
"alphanum_fraction": 0.4809721176,
"avg_line_length": 36.6068965517,
"ext": "agda",
"hexsha": "13a0e5f26f96ebc422c4ee7c37c2b8a6e5982760",
"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": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DavidStahl97/formal-proofs",
"max_forks_repo_path": "Dave/Algebra/Naturals/Multiplication.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"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": "DavidStahl97/formal-proofs",
"max_issues_repo_path": "Dave/Algebra/Naturals/Multiplication.agda",
"max_line_length": 109,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "05213fb6ab1f51f770f9858b61526ba950e06232",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DavidStahl97/formal-proofs",
"max_stars_repo_path": "Dave/Algebra/Naturals/Multiplication.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2650,
"size": 5308
} |
open import Structures --using (KS; SKS; ks; TCS; Prog; monadTC; _⊕_; Err; ok; error; list-has-el; lift-state; lift-mstate)
open import Reflection as RE hiding (return; _>>=_; _>>_)
open import Reflection.Show
module Extract (kompile-fun : Type → Term → Name → SKS Prog) where
open import Reflection.Term
import Reflection.Name as RN
open import Agda.Builtin.Reflection using (withReconstructed; dontReduceDefs; onlyReduceDefs)
open import Data.List as L hiding (_++_)
open import Data.Unit using (⊤)
open import Data.Product
open import Data.Bool
open import Data.String as S hiding (_++_)
open import Data.Maybe as M hiding (_>>=_)
open import Function --using (_$_; case_of_)
open import ReflHelper
open import Category.Monad using (RawMonad)
open import Category.Monad.State using (StateTMonadState; RawMonadState)
open RawMonad {{...}} public
{-# TERMINATING #-}
kompile-fold : TCS Prog
macro
-- Main entry point of the extractor.
-- `n` is a starting function of the extraction
-- `base` is the set of base functions that we never traverse into.
-- `skip` is the list of functions that we have traversed already.
-- The difference between the two is that `base` would be passed to
-- `dontReduceDefs`, hence never inlined; whereas `skip` mainly avoids
-- potential recursive extraction.
kompile : Name → Names → Names → Term → TC ⊤
kompile n base skip hole = do
(p , st) ← kompile-fold $ ks [ n ] base skip ε 1
--let p = KS.defs st ⊕ p
q ← quoteTC p
unify hole q
-- Traverse through the list of the functions we need to extract
-- and collect all the definitions.
kompile-fold = do
s@(ks fs ba done _ c) ← R.get
case fs of λ where
[] → return ε
(f ∷ fs) → case list-has-el (f RN.≟_) done of λ where
true → do
R.modify λ k → record k{ funs = fs }
kompile-fold
false → do
(ty , te) ← lift-state {RM = monadTC} $ do
ty ← getType f
ty ← withReconstructed $ dontReduceDefs ba $ normalise ty
te ← withReconstructed $ getDefinition f >>= λ where
(function cs) → return $ pat-lam cs []
-- FIXME: currently we do not extract data types, which
-- we should fix by parametrising this module by
-- kompile-type argument, and calling it in the
-- same way as we call kompile-fun now.
--(data-cons d) → return $ con d []
_ → return unknown
te ← pat-lam-norm te ba
return $ ty , te
case te of λ where
unknown →
return $ error $ "kompile: attempting to compile `" ++ showName f ++ "` as function"
_ → do
R.put (ks fs ba (f ∷ done) ε c)
-- Compile the function and make an error more specific in
-- case compilation fails.
(ok q) ← lift-mstate {RM = monadTC} $ kompile-fun ty te f
where (error x) → return $ error $ "in function " ++ showName f ++ ": " ++ x
defs ← KS.defs <$> R.get
let q = defs ⊕ q
--R.modify $! λ k → record k{ defs = ε }
kst ← R.get
--let q = KS.defs kst ⊕ q
R.put $! record kst{ defs = ε }
-- Do the rest of the functions
p ← kompile-fold
return $! p ⊕ "\n\n" ⊕ q
where
module R = RawMonadState (StateTMonadState KS monadTC)
| {
"alphanum_fraction": 0.5755033557,
"avg_line_length": 39.2967032967,
"ext": "agda",
"hexsha": "28db661c192e57e0cf4467e6c381d0ab48951da9",
"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": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "ashinkarov/agda-extractor",
"max_forks_repo_path": "Extract.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"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": "ashinkarov/agda-extractor",
"max_issues_repo_path": "Extract.agda",
"max_line_length": 123,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "ashinkarov/agda-extractor",
"max_stars_repo_path": "Extract.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-11T14:52:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-11T14:52:59.000Z",
"num_tokens": 919,
"size": 3576
} |
-- WARNING: This file was generated automatically by Vehicle
-- and should not be modified manually!
-- Metadata
-- - Agda version: 2.6.2
-- - AISEC version: 0.1.0.1
-- - Time generated: ???
{-# OPTIONS --allow-exec #-}
open import Vehicle
open import Data.Unit
open import Data.Integer as ℤ using (ℤ)
open import Data.List
open import Data.List.Relation.Unary.All as List
open import Relation.Binary.PropositionalEquality
module simple-quantifierIn-temp-output where
emptyList : List ℤ
emptyList = []
abstract
empty : List.All (λ (x : ℤ) → ⊤) emptyList
empty = checkSpecification record
{ proofCache = "/home/matthew/Code/AISEC/vehicle/proofcache.vclp"
}
abstract
double : List.All (λ (x : ℤ) → List.All (λ (y : ℤ) → x ≡ y) emptyList) emptyList
double = checkSpecification record
{ proofCache = "/home/matthew/Code/AISEC/vehicle/proofcache.vclp"
}
abstract
forallForallIn : ∀ (x : ℤ) → List.All (λ (y : ℤ) → x ≡ y) emptyList
forallForallIn = checkSpecification record
{ proofCache = "/home/matthew/Code/AISEC/vehicle/proofcache.vclp"
}
abstract
forallInForall : List.All (λ (x : ℤ) → ∀ (y : ℤ) → x ≡ y) emptyList
forallInForall = checkSpecification record
{ proofCache = "/home/matthew/Code/AISEC/vehicle/proofcache.vclp"
} | {
"alphanum_fraction": 0.6901626646,
"avg_line_length": 29.3409090909,
"ext": "agda",
"hexsha": "e405bdb77574ae5dfecf07f04640de433b595a0c",
"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": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vehicle-lang/vehicle",
"max_forks_repo_path": "test/Test/Compile/Golden/simple-quantifierIn/simple-quantifierIn-output.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T20:49:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-07T14:09:13.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vehicle-lang/vehicle",
"max_issues_repo_path": "test/Test/Compile/Golden/simple-quantifierIn/simple-quantifierIn-output.agda",
"max_line_length": 82,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vehicle-lang/vehicle",
"max_stars_repo_path": "test/Test/Compile/Golden/simple-quantifierIn/simple-quantifierIn-output.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-17T18:51:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-10T12:56:42.000Z",
"num_tokens": 403,
"size": 1291
} |
-- Issue reported by Sergei Meshvelliani
-- Simplified example by Guillaume Allais
-- When adding missing absurd clauses, dot patterns were accidentally
-- turned into variable patterns.
{-# OPTIONS --allow-unsolved-metas #-}
open import Agda.Builtin.List
open import Agda.Builtin.Equality
data Var (T : Set₂) (σ : T) : List T → Set₂ where
z : ∀ Γ → Var T σ (σ ∷ Γ)
s : ∀ τ Γ → Var T σ Γ → Var T σ (τ ∷ Γ)
eq : ∀ Γ (b c : Var _ Set Γ) → b ≡ c → Set
eq .(Set ∷ Γ) (z Γ) (z .Γ) _ = {!!}
eq .(τ ∷ Γ) (s τ Γ m) (s .τ .Γ n) _ = {!!}
-- WAS: Internal error in CompiledClause.Compile
-- SHOULD: Succeed
| {
"alphanum_fraction": 0.6194398682,
"avg_line_length": 26.3913043478,
"ext": "agda",
"hexsha": "d3424e3dbb0e74d548809c15f0fa683a4a009779",
"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/Issue3443.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/Issue3443.agda",
"max_line_length": 69,
"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/Issue3443.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 207,
"size": 607
} |
-- Forced constructor arguments don't count towards the size of the datatype
-- (only if not --withoutK).
data _≡_ {a} {A : Set a} : A → A → Set where
refl : ∀ x → x ≡ x
data Singleton {a} {A : Set a} : A → Set where
[_] : ∀ x → Singleton x
| {
"alphanum_fraction": 0.5967741935,
"avg_line_length": 24.8,
"ext": "agda",
"hexsha": "c93cb7234ea09dd012a710b75c6f30bbb5a8683e",
"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/LargeIndices.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/LargeIndices.agda",
"max_line_length": 76,
"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/LargeIndices.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": 248
} |
{-# OPTIONS --without-K --safe #-}
module Dodo.Unary.Disjoint where
-- Stdlib imports
open import Level using (Level; _⊔_)
open import Data.Empty using (⊥)
open import Relation.Unary using (Pred)
-- Local imports
open import Dodo.Unary.Empty
open import Dodo.Unary.Intersection
-- # Definitions
Disjoint₁ : ∀ {a ℓ₁ ℓ₂ : Level} {A : Set a}
→ Pred A ℓ₁ → Pred A ℓ₂ → Set _
Disjoint₁ P Q = Empty₁ (P ∩₁ Q)
| {
"alphanum_fraction": 0.6902439024,
"avg_line_length": 21.5789473684,
"ext": "agda",
"hexsha": "49950021b5b43ef67c57f64ba6fb75eb716c2265",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "sourcedennis/agda-dodo",
"max_forks_repo_path": "src/Dodo/Unary/Disjoint.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "sourcedennis/agda-dodo",
"max_issues_repo_path": "src/Dodo/Unary/Disjoint.agda",
"max_line_length": 43,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "sourcedennis/agda-dodo",
"max_stars_repo_path": "src/Dodo/Unary/Disjoint.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 131,
"size": 410
} |
------------------------------------------------------------------------------
-- A looping (error) combinator
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Loop where
open import LTC-PCF.Base
------------------------------------------------------------------------------
error : D
error = fix (λ f → f)
| {
"alphanum_fraction": 0.3043478261,
"avg_line_length": 29.3888888889,
"ext": "agda",
"hexsha": "00aea1591c1ea28282bb0300afcd60b42f97f37d",
"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/LTC-PCF/Loop.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/LTC-PCF/Loop.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/LTC-PCF/Loop.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": 77,
"size": 529
} |
{-# OPTIONS --without-K #-}
open import Level.NP
open import Type hiding (★)
open import Type.Identities
open import Function.NP
open import Function.Extensionality
open import Data.Product
open import Data.Sum
open import Relation.Binary.Logical
open import Relation.Binary.PropositionalEquality.NP
open import Relation.Binary.NP
open import HoTT
open Equivalences
open import Explore.Core
open import Explore.Properties
open import Explore.Explorable
import Explore.Monad
-- NOTE: it would be nice to have another module to change the definition of an exploration
-- function by an extensionally equivalent one. Combined with this module one could both
-- pick the reduction behavior we want and save some proof effort.
module Explore.Isomorphism
{-a-} {A B : ★₀ {-a-}} (e : A ≃ B) where
a = ₀
private
module M {ℓ} = Explore.Monad {a} ℓ
e⁻ = ≃-sym e
module E = Equiv e
e→ = E.·→
module _ {ℓ} (Aᵉ : Explore ℓ A) where
explore-iso : Explore ℓ B
explore-iso = M.map e→ Aᵉ
private
Bᵉ = explore-iso
module _ {ℓ p} {Aᵉ : Explore ℓ A} (Aⁱ : ExploreInd p Aᵉ) where
explore-iso-ind : ExploreInd p (Bᵉ Aᵉ)
explore-iso-ind = M.map-ind e→ Aⁱ
private
Bⁱ = explore-iso-ind
module _ {ℓ} {Aᵉ : Explore (ₛ ℓ) A} (Aˡ : Lookup {ℓ} Aᵉ) where
lookup-iso : Lookup {ℓ} (Bᵉ Aᵉ)
lookup-iso {C} d b = tr C (E.·←-inv-r b) (Aˡ d (E.·← b))
module _ {ℓ} {Aᵉ : Explore (ₛ ℓ) A} (Aᶠ : Focus {ℓ} Aᵉ) where
focus-iso : Focus {ℓ} (Bᵉ Aᵉ)
focus-iso {C} (b , c) = Aᶠ (E.·← b , c')
where c' = tr C (! (E.·←-inv-r b)) c
module _ (Aˢ : Sum A) where
sum-iso : Sum B
sum-iso h = Aˢ (h ∘ e→)
module _ (Aᵖ : Product A) where
product-iso : Product B
product-iso h = Aᵖ (h ∘ e→)
module FromExplore-iso
(Aᵉ : ∀ {ℓ} → Explore ℓ A)
= FromExplore (Bᵉ Aᵉ)
module FromExploreInd-iso
{Aᵉ : ∀ {ℓ} → Explore ℓ A}
(Aⁱ : ∀ {ℓ p} → ExploreInd {ℓ} p Aᵉ)
= FromExploreInd (Bⁱ Aⁱ)
module _ {ℓ} {Aᵉ : Explore (ₛ ℓ) A} (ΣAᵉ-ok : Adequate-Σ (Σᵉ Aᵉ)) {{_ : UA}} {{_ : FunExt}} where
Σ-iso-ok : Adequate-Σ (Σᵉ (Bᵉ Aᵉ))
Σ-iso-ok F = ΣAᵉ-ok (F ∘ e→) ∙ Σ-fst≃ e _
module _ {ℓ} {Aᵉ : Explore (ₛ ℓ) A} (ΠAᵉ-ok : Adequate-Π (Πᵉ Aᵉ)) {{_ : UA}} {{_ : FunExt}} where
Π-iso-ok : Adequate-Π (Πᵉ (Bᵉ Aᵉ))
Π-iso-ok F = ΠAᵉ-ok (F ∘ e→) ∙ Π-dom≃ e _
open Adequacy _≡_
module _ {Aˢ : Sum A} (Aˢ-ok : Adequate-sum Aˢ) {{_ : UA}} {{_ : FunExt}} where
sum-iso-ok : Adequate-sum (sum-iso Aˢ)
sum-iso-ok h = Aˢ-ok (h ∘ e→) ∙ Σ-fst≃ e _
module _ {Aᵖ : Product A} (Aᵖ-ok : Adequate-product Aᵖ) {{_ : UA}} {{_ : FunExt}} where
product-iso-ok : Adequate-product (product-iso Aᵖ)
product-iso-ok g = Aᵖ-ok (g ∘ e→) ∙ Π-dom≃ e _
module _
{ℓ₀ ℓ₁ ℓᵣ}
{aᵣ} {Aᵣ : ⟦★⟧ aᵣ A A}
{bᵣ} {Bᵣ : ⟦★⟧ bᵣ B B}
(e→ᵣ : (Aᵣ ⟦→⟧ Bᵣ) e→ e→)
{expᴬ₀ : Explore ℓ₀ A} {expᴬ₁ : Explore ℓ₁ A}(expᴬᵣ : ⟦Explore⟧ ℓᵣ Aᵣ expᴬ₀ expᴬ₁) where
⟦explore-iso⟧ : ⟦Explore⟧ ℓᵣ Bᵣ (explore-iso expᴬ₀) (explore-iso expᴬ₁)
⟦explore-iso⟧ P Pε P⊕ Pf = expᴬᵣ P Pε P⊕ (Pf ∘ e→ᵣ)
-- -}
-- -}
-- -}
| {
"alphanum_fraction": 0.6120546121,
"avg_line_length": 29.4411764706,
"ext": "agda",
"hexsha": "bfd188ee52e1a4eba78a91e42726e54354c9f766",
"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": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crypto-agda/explore",
"max_forks_repo_path": "lib/Explore/Isomorphism.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "crypto-agda/explore",
"max_issues_repo_path": "lib/Explore/Isomorphism.agda",
"max_line_length": 97,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crypto-agda/explore",
"max_stars_repo_path": "lib/Explore/Isomorphism.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z",
"num_tokens": 1405,
"size": 3003
} |
module Issue204.Dependency where
open import Common.Level public renaming (lsuc to suc)
record R (ℓ : Level) : Set (suc ℓ) where
data D (ℓ : Level) : Set (suc ℓ) where
module M {ℓ : Level} (d : D ℓ) where
| {
"alphanum_fraction": 0.6794258373,
"avg_line_length": 20.9,
"ext": "agda",
"hexsha": "9eed70b2b1f6d70ee792429b4877bdbd065e7c5a",
"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/Issue204/Dependency.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/Issue204/Dependency.agda",
"max_line_length": 54,
"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/Issue204/Dependency.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": 71,
"size": 209
} |
------------------------------------------------------------------------
-- Coherently constant functions
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
import Equality.Path as P
module Coherently-constant
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Prelude hiding (_+_)
import Bijection equality-with-J as B
open import Eilenberg-MacLane-space eq as K using (K[_]1; base; loop)
open import Embedding equality-with-J as Emb using (Embedding)
open import Equality.Decidable-UIP equality-with-J using (Constant)
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq using (_≃_)
open import Function-universe equality-with-J hiding (id; _∘_)
open import Group equality-with-J
open import Group.Cyclic eq as C using (ℤ/[1+_]ℤ; _≡_mod_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as T using (∥_∥; ∣_∣)
open import Injection equality-with-J using (Injective)
open import Integer equality-with-J
open import Pointed-type.Homotopy-group eq
open import Preimage equality-with-J using (_⁻¹_)
import Quotient eq as Q
open import Univalence-axiom equality-with-J
private
variable
a b : Level
A B C D : Type a
f : A → B
p : A
-- Coherently constant functions.
--
-- Shulman uses the term "conditionally constant" in "Not every weakly
-- constant function is conditionally constant"
-- (https://homotopytypetheory.org/2015/06/11/not-every-weakly-constant-function-is-conditionally-constant/).
-- I do not know who first came up with this definition.
Coherently-constant :
{A : Type a} {B : Type b} → (A → B) → Type (a ⊔ b)
Coherently-constant {A = A} {B = B} f =
∃ λ (g : ∥ A ∥ → B) → f ≡ g ∘ ∣_∣
-- Every coherently constant function is weakly constant.
--
-- This result is mentioned by Shulman.
Coherently-constant→Constant :
Coherently-constant f → Constant f
Coherently-constant→Constant {f = f} (g , eq) x y =
f x ≡⟨ cong (_$ x) eq ⟩
g ∣ x ∣ ≡⟨ cong g (T.truncation-is-proposition _ _) ⟩
g ∣ y ∣ ≡⟨ sym $ cong (_$ y) eq ⟩∎
f y ∎
-- Every weakly constant function with a stable domain is coherently
-- constant.
--
-- This result was proved by Kraus, Escardó, Coquand and Altenkirch in
-- "Notions of Anonymous Existence in Martin-Löf Type Theory".
Stable-domain→Constant→Coherently-constant :
{f : A → B} →
(∥ A ∥ → A) → Constant f → Coherently-constant f
Stable-domain→Constant→Coherently-constant {f = f} s c =
f ∘ s
, ⟨ext⟩ λ x →
f x ≡⟨ c _ _ ⟩∎
f (s ∣ x ∣) ∎
private
-- Definitions used in the proof of ¬-Constant→Coherently-constant.
module ¬-Constant→Coherently-constant
(ℓ : Level) (univ : Univalence lzero)
where
-- CCC B is the statement that every constant function from a
-- merely inhabited type in Type ℓ to B is coherently constant.
CCC : Type ℓ → Type (lsuc ℓ)
CCC B =
(A : Type ℓ) → ∥ A ∥ →
(f : A → B) → Constant f → Coherently-constant f
Has-retraction : {A B : Type a} → (B → A) → Type a
Has-retraction f = ∃ λ g → g ∘ f ≡ id
-- IR A is the statement that every injective, (-1)-connected
-- function from A to a type in Type ℓ has a retraction.
IR : Type ℓ → Type (lsuc ℓ)
IR A =
(B : Type ℓ) (f : A → B) → (∀ x → ∥ f ⁻¹ x ∥) →
Injective f → Has-retraction f
-- CCC C implies IR C.
CCC→IR : CCC C → IR C
CCC→IR {C = C} ccc A f conn inj =
(λ a → proj₁ (cc a) (conn a))
, ⟨ext⟩ λ c →
proj₁ (cc (f c)) (conn (f c)) ≡⟨ cong (proj₁ (cc (f c))) $ T.truncation-is-proposition _ _ ⟩
proj₁ (cc (f c)) ∣ c , refl _ ∣ ≡⟨ sym $ cong (_$ c , refl _) $ proj₂ (cc (f c)) ⟩∎
c ∎
where
cc : (a : A) → Coherently-constant {A = f ⁻¹ a} proj₁
cc a = ccc (f ⁻¹ a) (conn a) proj₁ λ (c₁ , p₁) (c₂ , p₂) →
inj (f c₁ ≡⟨ p₁ ⟩
a ≡⟨ sym p₂ ⟩∎
f c₂ ∎)
-- If there is an embedding from C to D, then CCC D implies CCC C.
CCC→CCC : Embedding C D → CCC D → CCC C
CCC→CCC emb ccc B ∥B∥ g c = proj₁ ∘ h , refl _
where
e = Embedding.to emb
cc : Coherently-constant (e ∘ g)
cc = ccc B ∥B∥ (e ∘ g) λ x y →
e (g x) ≡⟨ cong e (c x y) ⟩∎
e (g y) ∎
h : (b : ∥ B ∥) → ∃ λ c → e c ≡ proj₁ cc b
h = T.elim _ (λ _ → Emb.embedding→⁻¹-propositional
(Embedding.is-embedding emb) _) λ b →
g b , cong (_$ b) (proj₂ cc)
-- If CCC (A ≃ A) holds for every type A, then CCC (↑ ℓ K[ G ]1)
-- holds for every abelian group G of type Group lzero.
CCC-≃→CCC-K :
((B : Type ℓ) → CCC (B ≃ B)) →
(G : Group lzero) → Abelian G → CCC (↑ ℓ K[ G ]1)
CCC-≃→CCC-K ccc G abelian =
$⟨ ccc (↑ ℓ K[ G ]1) ⟩
CCC (↑ ℓ K[ G ]1 ≃ ↑ ℓ K[ G ]1) ↝⟨ CCC→CCC emb ⟩□
CCC (↑ ℓ K[ G ]1) □
where
Aut[K[G]] = (K[ G ]1 ≃ K[ G ]1) , Eq.id
Aut[K[G]]-groupoid : H-level 3 (K[ G ]1 ≃ K[ G ]1)
Aut[K[G]]-groupoid = Eq.left-closure ext 2 K.is-groupoid
Ω[Aut[K[G]]] =
Fundamental-group′ Aut[K[G]] Aut[K[G]]-groupoid
emb : Embedding (↑ ℓ K[ G ]1) (↑ ℓ K[ G ]1 ≃ ↑ ℓ K[ G ]1)
emb =
↑ ℓ K[ G ]1 ↔⟨ B.↑↔ ⟩
K[ G ]1 ↔⟨ inverse $ K.cong-≃ $ K.Fundamental-group′[K1≃K1]≃ᴳ univ abelian ⟩
K[ Ω[Aut[K[G]]] ]1 ↝⟨ proj₁ $ K.K[Fundamental-group′]1↣ᴮ univ Aut[K[G]]-groupoid ⟩
K[ G ]1 ≃ K[ G ]1 ↔⟨ inverse $ Eq.≃-preserves-bijections ext B.↑↔ B.↑↔ ⟩□
↑ ℓ K[ G ]1 ≃ ↑ ℓ K[ G ]1 □
-- The group of integers.
module ℤG = Group ℤ-group
-- The groups ℤ/2ℤ and ℤ/4ℤ.
ℤ/2ℤ = ℤ/[1+ 1 ]ℤ
ℤ/4ℤ = ℤ/[1+ 3 ]ℤ
module ℤ/2ℤ where
open Group ℤ/2ℤ public
renaming (_∘_ to infixl 6 _+_; _⁻¹ to infix 8 -_)
module ℤ/4ℤ where
open Group ℤ/4ℤ public
renaming (_∘_ to infixl 6 _+_; _⁻¹ to infix 8 -_)
-- Multiplication by two, as a function from ℤ/2ℤ to ℤ/4ℤ.
mul2 : ℤ/2ℤ.Carrier → ℤ/4ℤ.Carrier
mul2 = Q.rec λ where
.Q.[]ʳ i → Q.[ i *+ 2 ]
.Q.is-setʳ → Q./-is-set
.Q.[]-respects-relationʳ {x = i} {y = j} →
i ≡ j mod 2 ↝⟨ C.*+-cong {j = j} {n = 2} 2 ⟩
i *+ 2 ≡ j *+ 2 mod 4 ↝⟨ Q.[]-respects-relation ⟩□
Q.[ i *+ 2 ] ≡ Q.[ j *+ 2 ] □
-- The function mul2, expressed as a group homomorphism.
mul2ʰ : ℤ/2ℤ →ᴳ ℤ/4ℤ
mul2ʰ = λ where
.related → mul2
.homomorphic → Q.elim-prop λ where
.Q.is-propositionʳ _ → Π-closure ext 1 λ _ →
Group.Carrier-is-set ℤ/[1+ 3 ]ℤ
.Q.[]ʳ i → Q.elim-prop λ where
.Q.is-propositionʳ _ → Group.Carrier-is-set ℤ/[1+ 3 ]ℤ
.Q.[]ʳ j → cong Q.[_]
((i + j) *+ 2 ≡⟨ *+-distrib-+ {i = i} 2 ⟩∎
i *+ 2 + j *+ 2 ∎)
-- Integer division by 2, as a function from ℤ/4ℤ to ℤ/2ℤ.
div2 : ℤ/4ℤ.Carrier → ℤ/2ℤ.Carrier
div2 = Q.rec λ where
.Q.[]ʳ i → Q.[ ⌊ i /2⌋ ]
.Q.is-setʳ → Q./-is-set
.Q.[]-respects-relationʳ {x = i} {y = j} →
i ≡ j mod 4 ↝⟨ C.⌊/2⌋-cong j 2 ⟩
⌊ i /2⌋ ≡ ⌊ j /2⌋ mod 2 ↝⟨ Q.[]-respects-relation ⟩□
Q.[ ⌊ i /2⌋ ] ≡ Q.[ ⌊ j /2⌋ ] □
-- Some lemmas relating mul2 and div2.
mul2-div2-lemma₁ :
∀ i j → div2 (j ℤ/4ℤ.+ ℤ/4ℤ.- mul2 i) ≡ div2 j ℤ/2ℤ.+ ℤ/2ℤ.- i
mul2-div2-lemma₁ = Q.elim-prop λ where
.Q.is-propositionʳ _ →
Π-closure ext 1 λ _ →
Q./-is-set
.Q.[]ʳ i → Q.elim-prop λ where
.Q.is-propositionʳ _ → Q./-is-set
.Q.[]ʳ j → cong Q.[_]
(⌊ j - i *+ 2 /2⌋ ≡⟨ cong (⌊_/2⌋ ∘ _+_ j) $ ℤG.^+⁻¹ {p = i} 2 ⟩
⌊ j + - i *+ 2 /2⌋ ≡⟨ ⌊+*+2/2⌋≡ j ⟩∎
⌊ j /2⌋ + - i ∎)
mul2-div2-lemma₂ :
∀ i j → ℤ/2ℤ.- i ℤ/2ℤ.+ div2 (mul2 i ℤ/4ℤ.+ j) ≡ div2 j
mul2-div2-lemma₂ = Q.elim-prop λ where
.Q.is-propositionʳ _ →
Π-closure ext 1 λ _ →
Q./-is-set
.Q.[]ʳ i → Q.elim-prop λ where
.Q.is-propositionʳ _ → Q./-is-set
.Q.[]ʳ j → cong Q.[_]
(- i + ⌊ i *+ 2 + j /2⌋ ≡⟨ cong (_+_ (- i) ∘ ⌊_/2⌋) $ +-comm (i *+ 2) ⟩
- i + ⌊ j + i *+ 2 /2⌋ ≡⟨ cong (_+_ (- i)) $ ⌊+*+2/2⌋≡ j ⟩
- i + (⌊ j /2⌋ + i) ≡⟨ cong (_+_ (- i)) $ +-comm ⌊ j /2⌋ ⟩
- i + (i + ⌊ j /2⌋) ≡⟨ +-assoc (- i) ⟩
- i + i + ⌊ j /2⌋ ≡⟨ cong (_+ ⌊ j /2⌋) $ +-left-inverse i ⟩
+ 0 + ⌊ j /2⌋ ≡⟨ +-left-identity ⟩∎
⌊ j /2⌋ ∎)
-- The type K[ ℤ/4ℤ ]1 is (-1)-connected.
K[ℤ/4ℤ]-connected : (x : K[ ℤ/4ℤ ]1) → ∥ K.map mul2ʰ ⁻¹ x ∥
K[ℤ/4ℤ]-connected = K.elim-set λ where
.K.baseʳ → ∣ base , refl _ ∣
.K.loopʳ _ → T.truncation-is-proposition _ _
.K.is-setʳ _ → mono₁ 1 T.truncation-is-proposition
-- Two equivalences.
Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ : _≡_ {A = K[ ℤ/4ℤ ]1} base base ≃ ℤ/4ℤ.Carrier
Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ =
K.Fundamental-group′[K1]≃ᴳ univ K.is-groupoid .related
Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ : _≡_ {A = K[ ℤ/2ℤ ]1} base base ≃ ℤ/2ℤ.Carrier
Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ =
K.Fundamental-group′[K1]≃ᴳ univ K.is-groupoid .related
-- The function K.map mul2ʰ is injective.
map-mul2ʰ-injective : Injective (K.map mul2ʰ)
map-mul2ʰ-injective {x = x} {y = y} = K.elim-set e x y
where
lemma = K.elim-set λ where
.K.is-setʳ _ →
Π-closure ext 2 λ _ →
K.is-groupoid
.K.baseʳ →
base ≡ base ↔⟨ Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ ⟩
ℤ/4ℤ.Carrier ↝⟨ div2 ⟩
ℤ/2ℤ.Carrier ↔⟨ inverse Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ ⟩□
base ≡ base □
.K.loopʳ i → ⟨ext⟩ λ eq →
let j = _≃_.to Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ eq in
subst (λ y → base ≡ K.map mul2ʰ y → base ≡ y)
(loop i) (loop ∘ div2 ∘ _≃_.to Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ) eq ≡⟨ subst-→ ⟩
subst (base ≡_) (loop i)
(loop $ div2 $ _≃_.to Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ $
subst ((base ≡_) ∘ K.map mul2ʰ) (sym (loop i)) eq) ≡⟨ trans (sym trans-subst) $
cong (flip trans _) $
cong (loop ∘ div2 ∘ _≃_.to Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ) $
trans (subst-∘ _ _ _) $
trans (sym trans-subst) $
cong (trans _) $
trans (cong-sym _ _) $
cong sym $ K.rec-loop ⟩
trans
(loop $ div2 $ _≃_.to Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ $
trans eq (sym (loop (mul2 i))))
(loop i) ≡⟨ cong (flip trans _) $ cong (loop ∘ div2) $
K.Fundamental-group′[K1]≃ᴳ univ K.is-groupoid .homomorphic
eq (sym (loop (mul2 i))) ⟩
trans
(loop $ div2 $
j ℤ/4ℤ.+ _≃_.to Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ (sym (loop (mul2 i))))
(loop i) ≡⟨ cong (flip trans _) $ cong (loop ∘ div2 ∘ (j ℤ/4ℤ.+_)) $
→ᴳ-⁻¹ (K.Fundamental-group′[K1]≃ᴳ univ K.is-groupoid) _ ⟩
trans
(loop $ div2 $
j ℤ/4ℤ.+ ℤ/4ℤ.- _≃_.to Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ (loop (mul2 i)))
(loop i) ≡⟨ cong (flip trans _ ∘ loop ∘ div2 ∘ (j ℤ/4ℤ.+_) ∘ ℤ/4ℤ.-_) $
_≃_.right-inverse-of Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ _ ⟩
trans (loop (div2 (j ℤ/4ℤ.+ ℤ/4ℤ.- mul2 i))) (loop i) ≡⟨ cong (flip trans _) $ cong loop $ mul2-div2-lemma₁ i j ⟩
trans (loop (div2 j ℤ/2ℤ.+ ℤ/2ℤ.- i)) (loop i) ≡⟨ cong (flip trans _) $
≃ᴳ-sym {G₂ = ℤ/2ℤ} (K.Fundamental-group′[K1]≃ᴳ univ K.is-groupoid)
.homomorphic _ _ ⟩
trans (trans (loop (div2 j)) (loop (ℤ/2ℤ.- i))) (loop i) ≡⟨ cong (flip trans _) $ cong (trans _) $
→ᴳ-⁻¹ (≃ᴳ-sym $ K.Fundamental-group′[K1]≃ᴳ univ K.is-groupoid) _ ⟩
trans (trans (loop (div2 j)) (sym (loop i))) (loop i) ≡⟨ trans (trans-assoc _ _ _) $
trans (cong (trans _) $ trans-symˡ _) $
trans-reflʳ _ ⟩∎
loop (div2 j) ∎
e = λ where
.K.is-setʳ _ →
Π-closure ext 2 λ _ →
Π-closure ext 2 λ _ →
K.is-groupoid
.K.baseʳ → lemma
.K.loopʳ i → ⟨ext⟩ $ K.elim-prop λ where
.K.is-propositionʳ _ → Π-closure ext 2 λ _ →
K.is-groupoid
.K.baseʳ → ⟨ext⟩ λ eq →
let j = _≃_.to Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ eq in
subst (λ x → ∀ y → K.map mul2ʰ x ≡ K.map mul2ʰ y → x ≡ y)
(loop i) lemma base eq ≡⟨ trans (cong (_$ eq) $ sym $
push-subst-application _ _)
subst-→ ⟩
subst (_≡ base) (loop i)
(lemma base $
subst (λ x → K.map mul2ʰ x ≡ K.map mul2ʰ base)
(sym (loop i)) eq) ≡⟨ trans subst-trans-sym $
cong (trans _) $ cong (lemma base) $
trans (subst-∘ _ _ _) $
subst-trans-sym ⟩
trans (sym $ loop i)
(lemma base $
trans (sym (cong (K.map mul2ʰ) (sym (loop i)))) eq) ≡⟨ cong (trans _) $ cong (lemma base) $ cong (flip trans _) $
trans (sym $ cong-sym _ _) $
cong (cong _) $ sym-sym _ ⟩
trans (sym $ loop i)
(lemma base (trans (cong (K.map mul2ʰ) (loop i)) eq)) ≡⟨ cong (trans _) $ cong (lemma base) $ cong (flip trans _)
K.rec-loop ⟩
trans (sym $ loop i)
(lemma base (trans (loop (mul2 i)) eq)) ≡⟨⟩
trans (sym $ loop i)
(loop $ div2 $ _≃_.to Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ $
trans (loop (mul2 i)) eq) ≡⟨ cong₂ (λ p q → trans p (loop (div2 q)))
(sym $
→ᴳ-⁻¹ (≃ᴳ-sym $ K.Fundamental-group′[K1]≃ᴳ univ K.is-groupoid) _)
(K.Fundamental-group′[K1]≃ᴳ univ K.is-groupoid .homomorphic
(loop (mul2 i)) eq) ⟩
trans (loop (ℤ/2ℤ.- i))
(loop $ div2 $
_≃_.to Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ (loop (mul2 i)) ℤ/4ℤ.+ j) ≡⟨ cong (trans (loop (ℤ/2ℤ.- i)) ∘ loop ∘ div2 ∘ (ℤ/4ℤ._+ j)) $
_≃_.right-inverse-of Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ _ ⟩
trans (loop (ℤ/2ℤ.- i)) (loop (div2 (mul2 i ℤ/4ℤ.+ j))) ≡⟨ sym $
≃ᴳ-sym (K.Fundamental-group′[K1]≃ᴳ univ K.is-groupoid)
.homomorphic _ _ ⟩
loop (ℤ/2ℤ.- i ℤ/2ℤ.+ div2 (mul2 i ℤ/4ℤ.+ j)) ≡⟨ cong loop $ mul2-div2-lemma₂ i j ⟩
loop (div2 j) ≡⟨⟩
lemma base eq ∎
-- It is not the case that IR holds for ↑ ℓ K[ ℤ/2ℤ ]1.
¬IR : ¬ IR (↑ ℓ K[ ℤ/2ℤ ]1)
¬IR ir = contradiction
where
-- The function K.map mul2ʰ has a retraction.
map-mul2ʰ-has-retraction : Has-retraction (K.map mul2ʰ)
map-mul2ʰ-has-retraction =
let r , is-r = ir (↑ ℓ K[ ℤ/4ℤ ]1) mul2′ conn inj in
lower ∘ r ∘ lift
, (⟨ext⟩ λ x →
lower (r (lift (K.map mul2ʰ x))) ≡⟨ cong lower $ cong (_$ lift x) is-r ⟩∎
x ∎)
where
mul2′ : ↑ ℓ K[ ℤ/2ℤ ]1 → ↑ ℓ K[ ℤ/4ℤ ]1
mul2′ = lift ∘ K.map mul2ʰ ∘ lower
conn : (x : ↑ ℓ K[ ℤ/4ℤ ]1) → ∥ mul2′ ⁻¹ x ∥
conn =
T.∥∥-map (Σ-map lift (cong lift)) ∘
K[ℤ/4ℤ]-connected ∘ lower
inj : Injective mul2′
inj = cong lift ∘ map-mul2ʰ-injective ∘ cong lower
-- The retraction, and the proof showing that it is a
-- retraction.
r₁ : K[ ℤ/4ℤ ]1 → K[ ℤ/2ℤ ]1
r₁ = proj₁ map-mul2ʰ-has-retraction
r₁-retraction : r₁ ∘ K.map mul2ʰ ≡ id
r₁-retraction = proj₂ map-mul2ʰ-has-retraction
-- A lemma related to r₁.
r₁-lemma :
trans (sym $ cong (_$ base) r₁-retraction)
(trans (cong r₁ (cong (K.map mul2ʰ) p))
(cong (_$ base) r₁-retraction)) ≡
p
r₁-lemma {p = p} =
trans (sym $ cong (_$ base) r₁-retraction)
(trans (cong r₁ (cong (K.map mul2ʰ) p))
(cong (_$ base) r₁-retraction)) ≡⟨ cong (trans _) $ cong (flip trans _) $
cong-∘ _ _ _ ⟩
trans (sym $ cong (_$ base) r₁-retraction)
(trans (cong (r₁ ∘ K.map mul2ʰ) p)
(cong (_$ base) r₁-retraction)) ≡⟨ cong (trans _) $
naturality (λ x → cong (_$ x) r₁-retraction) ⟩
trans (sym $ cong (_$ base) r₁-retraction)
(trans (cong (_$ base) r₁-retraction)
(cong id p)) ≡⟨ trans-sym-[trans] _ _ ⟩
cong id p ≡⟨ sym $ cong-id _ ⟩∎
p ∎
-- A variant of r₁ that is definitionally equal to base for
-- base.
r₂ : K[ ℤ/4ℤ ]1 → K[ ℤ/2ℤ ]1
r₂ = K.rec λ where
.K.baseʳ → base
.K.loopʳ i →
base ≡⟨ sym $ cong (_$ base) r₁-retraction ⟩
r₁ base ≡⟨ cong r₁ (loop i) ⟩
r₁ base ≡⟨ cong (_$ base) r₁-retraction ⟩∎
base ∎
.K.loop-idʳ →
trans (sym $ cong (_$ base) r₁-retraction)
(trans (cong r₁ (loop ℤ/4ℤ.id))
(cong (_$ base) r₁-retraction)) ≡⟨ cong (trans _) $ cong (flip trans _) $ cong (cong r₁) $ sym
K.rec-loop ⟩
trans (sym $ cong (_$ base) r₁-retraction)
(trans (cong r₁ (cong (K.map mul2ʰ) (loop ℤ/2ℤ.id)))
(cong (_$ base) r₁-retraction)) ≡⟨ r₁-lemma ⟩
loop ℤ/2ℤ.id ≡⟨ K.loop-id ⟩∎
refl _ ∎
.K.loop-∘ʳ {x = x} {y = y} →
trans (sym $ cong (_$ base) r₁-retraction)
(trans (cong r₁ (loop (x ℤ/4ℤ.+ y)))
(cong (_$ base) r₁-retraction)) ≡⟨ cong (trans _) $ cong (flip trans _) $ cong (cong r₁) $
K.loop-∘ ⟩
trans (sym $ cong (_$ base) r₁-retraction)
(trans (cong r₁ (trans (loop x) (loop y)))
(cong (_$ base) r₁-retraction)) ≡⟨ trans (cong (trans _) $
trans (cong (flip trans _) $
cong-trans _ _ _) $
trans-assoc _ _ _) $
sym $ trans-assoc _ _ _ ⟩
trans
(trans (sym $ cong (_$ base) r₁-retraction)
(cong r₁ (loop x)))
(trans (cong r₁ (loop y))
(cong (_$ base) r₁-retraction)) ≡⟨ trans (cong (trans _) $ sym $
trans--[trans-sym] _ _) $
trans (sym $ trans-assoc _ _ _) $
cong (flip trans _) $
trans-assoc _ _ _ ⟩∎
trans
(trans (sym $ cong (_$ base) r₁-retraction)
(trans (cong r₁ (loop x))
(cong (_$ base) r₁-retraction)))
(trans (sym $ cong (_$ base) r₁-retraction)
(trans (cong r₁ (loop y))
(cong (_$ base) r₁-retraction))) ∎
.K.is-groupoidʳ → K.is-groupoid
-- The functions r₁ and r₂ are pointwise equal.
r₁≡r₂ : ∀ x → r₁ x ≡ r₂ x
r₁≡r₂ = K.elim-set λ where
.K.is-setʳ _ → K.is-groupoid
.K.baseʳ →
r₁ base ≡⟨ cong (_$ base) r₁-retraction ⟩∎
r₂ base ∎
.K.loopʳ i →
subst (λ x → r₁ x ≡ r₂ x) (loop i)
(cong (_$ base) r₁-retraction) ≡⟨ subst-in-terms-of-trans-and-cong ⟩
trans (sym (cong r₁ (loop i)))
(trans (cong (_$ base) r₁-retraction)
(cong r₂ (loop i))) ≡⟨ cong (trans _) $ cong (trans _)
K.rec-loop ⟩
trans (sym (cong r₁ (loop i)))
(trans (cong (_$ base) r₁-retraction)
(trans (sym $ cong (_$ base) r₁-retraction)
(trans (cong r₁ (loop i))
(cong (_$ base) r₁-retraction)))) ≡⟨ cong (trans _) $
trans--[trans-sym] _ _ ⟩
trans (sym (cong r₁ (loop i)))
(trans (cong r₁ (loop i))
(cong (_$ base) r₁-retraction)) ≡⟨ trans-sym-[trans] _ _ ⟩∎
cong (_$ base) r₁-retraction ∎
-- Thus r₂ is also a retraction of K.map mul2ʰ.
r₂-retraction : r₂ ∘ K.map mul2ʰ ≡ id
r₂-retraction =
r₂ ∘ K.map mul2ʰ ≡⟨ cong (_∘ K.map mul2ʰ) $ sym $ ⟨ext⟩ r₁≡r₂ ⟩
r₁ ∘ K.map mul2ʰ ≡⟨ r₁-retraction ⟩∎
id ∎
-- A group homomorphism from ℤ/4ℤ to ℤ/2ℤ.
r₃ : ℤ/4ℤ →ᴳ ℤ/2ℤ
r₃ .related =
ℤ/4ℤ.Carrier ↔⟨ inverse Ω[K[ℤ/4ℤ]]≃ℤ/4ℤ ⟩
base ≡ base ↝⟨ cong r₂ ⟩
base ≡ base ↔⟨ Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ ⟩□
ℤ/2ℤ.Carrier □
r₃ .homomorphic i j =
_≃_.to Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ (cong r₂ (loop (i ℤ/4ℤ.+ j))) ≡⟨ cong (_≃_.to Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ ∘ cong r₂) K.loop-∘ ⟩
_≃_.to Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ (cong r₂ (trans (loop i) (loop j))) ≡⟨ cong (_≃_.to Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ) $ cong-trans _ _ _ ⟩
_≃_.to Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ
(trans (cong r₂ (loop i)) (cong r₂ (loop j))) ≡⟨ K.Fundamental-group′[K1]≃ᴳ univ K.is-groupoid
.homomorphic _ _ ⟩∎
_≃_.to Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ (cong r₂ (loop i)) ℤ/2ℤ.+
_≃_.to Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ (cong r₂ (loop j)) ∎
-- The homomorphism r₃ is a retraction of mul2.
r₃-retraction : ∀ i → Homomorphic.to r₃ (mul2 i) ≡ i
r₃-retraction i =
_≃_.to Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ (cong r₂ (loop (mul2 i))) ≡⟨ cong (_≃_.to Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ) lemma ⟩
_≃_.to Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ (loop i) ≡⟨ _≃_.right-inverse-of Ω[K[ℤ/2ℤ]]≃ℤ/2ℤ _ ⟩∎
i ∎
where
lemma =
cong r₂ (loop (mul2 i)) ≡⟨ K.rec-loop ⟩
trans (sym $ cong (_$ base) r₁-retraction)
(trans (cong r₁ (loop (mul2 i)))
(cong (_$ base) r₁-retraction)) ≡⟨ cong (trans _) $ cong (flip trans _) $ cong (cong r₁) $ sym
K.rec-loop ⟩
trans (sym $ cong (_$ base) r₁-retraction)
(trans (cong r₁ (cong (K.map mul2ʰ) (loop i)))
(cong (_$ base) r₁-retraction)) ≡⟨ r₁-lemma ⟩∎
loop i ∎
-- 0 and 1 are equal when viewed as elements of ℤ/2ℤ.
0≡1 : _≡_ {A = ℤ/2ℤ.Carrier} Q.[ + 0 ] Q.[ + 1 ]
0≡1 =
Q.[ + 0 ] ≡⟨ sym $ C.ℤ/2ℤ-+≡0 (Homomorphic.to r₃ Q.[ + 1 ]) ⟩
Homomorphic.to r₃ Q.[ + 1 ] ℤ/2ℤ.+
Homomorphic.to r₃ Q.[ + 1 ] ≡⟨ sym $ r₃ .homomorphic Q.[ + 1 ] Q.[ + 1 ] ⟩
Homomorphic.to r₃ Q.[ + 2 ] ≡⟨⟩
Homomorphic.to r₃ (mul2 Q.[ + 1 ]) ≡⟨ r₃-retraction Q.[ + 1 ] ⟩∎
Q.[ + 1 ] ∎
-- However, this is contradictory.
contradiction : ⊥
contradiction = C.ℤ/ℤ-0≢1 0 0≡1
-- It is not the case that, for every type A : Type a and merely
-- inhabited type B : Type a, every weakly constant function from B to
-- A ≃ A is coherently constant (assuming univalence).
--
-- This result is due to Sattler (personal communication), building on
-- work by Shulman (see "Not every weakly constant function is
-- conditionally constant").
¬-Constant→Coherently-constant :
Univalence lzero →
¬ ((A B : Type a) → ∥ A ∥ →
(f : A → B ≃ B) → Constant f → Coherently-constant f)
¬-Constant→Coherently-constant {a = a} univ =
((A B : Type a) → ∥ A ∥ →
(f : A → B ≃ B) → Constant f → Coherently-constant f) ↝⟨ flip ⟩
((B : Type a) → CCC (B ≃ B)) ↝⟨ CCC-≃→CCC-K ⟩
((G : Group lzero) → Abelian G → CCC (↑ a K[ G ]1)) ↝⟨ (λ hyp G abelian → CCC→IR (hyp G abelian)) ⟩
((G : Group lzero) → Abelian G → IR (↑ a K[ G ]1)) ↝⟨ (λ hyp → hyp ℤ/2ℤ C.ℤ/ℤ-abelian) ⟩
IR (↑ a K[ ℤ/2ℤ ]1) ↝⟨ ¬IR ⟩□
⊥ □
where
open ¬-Constant→Coherently-constant a univ
| {
"alphanum_fraction": 0.4139959803,
"avg_line_length": 43.5748407643,
"ext": "agda",
"hexsha": "6d03952c2e02359743581537b0b0f06c6b5a2e50",
"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/Coherently-constant.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/Coherently-constant.agda",
"max_line_length": 142,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Coherently-constant.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": 9543,
"size": 27365
} |
{-
https://serokell.io/blog/playing-with-negation
Constructive and Non-Constructive Proofs in Agda (Part 3): Playing with Negation
Danya Rogozin Friday, November 30th, 2018
Present an empty type to work with constructive negation.
Discuss Markov’s principle and apply this principle for one use case.
Declare the double negation elimination as a postulate.
Some examples of non-constructive proofs in Agda.
------------------------------------------------------------------------------
Empty type
-}
-- Type with no constructors (so-called bottom).
-- Type that corresponds to an absurd statement or contradiction.
data ⊥ : Set where
-- ¬ defines negation. ¬A denotes that any proof of A yields a proof of a contradiction:
¬_ : Set → Set
¬ A = A → ⊥
-- elimination of ⊥ : derives an arbitrary statement from bottom
exFalso : {A : Set} → ⊥ → A
exFalso ()
-- examples of propositions with negation that are provable constructively.
-- Derives an arbitrary formula from a contradiction.
-- The first argument f has a type ¬ A (or A → ⊥).
-- The second argument x has a type A.
-- Thus f x is an object of type ⊥.
-- Hence exContr (f x) has a type B.
exContr : {A B : Set} → ¬ A → A → B
exContr f x = exFalso (f x)
exContr2 : {A B : Set} → (A → ⊥) → A → B
exContr2 f x = exFalso (f x)
-- g proves B → ⊥
-- f proves A → B
-- g ∘ f proves A → ⊥, i.e. ¬ A.
contraposition : {A B : Set} → (A → B) → (¬ B → ¬ A)
contraposition f g = g ∘ f
-- negation on formula A.
-- If possible to derive contradictionary consequences B and ¬ B from the statement A,
-- then any proof of A yields ⊥.
¬-intro : {A B : Set} → (A → B) → (A → ¬ B) → ¬ A
¬-intro f g x = g x (f x)
{-
disjImpl establishes a connection between disjunction and implication.
If prove ¬ A ∨ B and have a proof of A.
If have a proof of ¬ A, then we have proved B by ex-falso.
If have a proof of B, then we have already proved B trivially.
So, we have obtained a proof of B by case analysis (i.e., pattern-matching).
-}
disjImpl : {A B : Set} → ¬ A ⊎ B → A → B
disjImpl (inj₁ x) a = exContr x a
disjImpl (inj₂ y) a = y
| {
"alphanum_fraction": 0.6467209191,
"avg_line_length": 28.6164383562,
"ext": "agda",
"hexsha": "aebce9b9798bcec41bf26eae3703be86cc9ea018",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/paper/2018-11-danya-rogozin-serokell-constructive-and-non-cons-proofs-in-agda/src/Part3_Playing_with_Negation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/paper/2018-11-danya-rogozin-serokell-constructive-and-non-cons-proofs-in-agda/src/Part3_Playing_with_Negation.agda",
"max_line_length": 88,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/paper/2018-11-danya-rogozin-serokell-constructive-and-non-cons-proofs-in-agda/src/Part3_Playing_with_Negation.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 620,
"size": 2089
} |
{-# OPTIONS --without-K #-}
module semisimplicial where
open import Agda.Primitive
open import Data.Nat
open import big-endian
-- N-truncated, augmented semisimplicial types.
-- Universe polymorphism has not been added yet
-- (should be very easy, at the cost of even more bloat of type signatures).
-- There is a canonical bijection between natural numbers (thought of in big-endian encoding) and
-- simplices of Δ^∞. An *ideal* is a downward-closed set of simplices in this ordering.
-- Each nontrivial ideal is principal, so the ideals are well-ordered by inclusion,
-- or equivalently by looking at their last face (the generator of the ideal) and ordering as a natural number.
-- Not every simplicial subset of a simplex is an ideal, but among the ideals are the simplices themselves
-- (in binary, a simplex is 11...11), as well as the boundaries of simplices (11...10).
-- The definition here defines an N-truncated, augmented semismplicial type X by starting with
-- an N-1 -truncated, augmented semisimplicial type XUnd, and then inductively defining the set of maps
-- into X from each ideal in turn, until we reach the boundary of the N-simplex.
-- Then we supply a set of fillers for these boundaries, i.e. the set of N-simplices.
-- Along the way we keep track of face relationships to know how to glue to get from one ideal to the next.
-- A truncated augmented simplicial set which has simplices of augmented dimension =< N
data sSet : ∀ (N : ℕ) → Set₁
-- Filling data for spheres of augmented dimension N required to promote from sSet N to sSet (suc N)
record FillData {N : ℕ} (XUnd : sSet N) : Set₁
-- Build by induction on dimension.
data sSet where
Aug : Set → sSet 0
reedy : ∀ {N : ℕ} → ∀ (XUnd : sSet N) →
∀ (XFill : FillData XUnd) →
sSet (suc N)
-- Given X and F, tells you the set of ideals in X of the shape "weakly preceeding F"
-- Note that "a face with N+1 digits" is a sneaky equivalent to "a simplex with at most N+1 digits"
IdealIn : ∀ {N : ℕ} → ∀ (X : sSet N) →
∀ {d : ℕ} → ∀ (F : Face N d) →
Set
-- Given X G, x, x', tells you whether x' is the G-shaped face of x.
-- F' will be the pullback of F by G, but padded out with zeros to have N bits.
-- (It is not explicitly enforced that F' is the pullback, but the constructors will be such
-- that no "isFaceOf" relation ever gets built when that is not the case)
isFaceOf : ∀ {N : ℕ} → ∀ (X : sSet N) →
∀ {d : ℕ} → {F : Face N d} → ∀ (x : IdealIn X F ) →
∀ {d' : ℕ} → ∀ {F' : Face N d'} → ∀ (x' : IdealIn X F') →
∀ {n' : ℕ} → ∀ (G : Face N n') →
Set
-- The filling data just needs to tell you how to fill spheres.
record FillData {N} XUnd where
constructor fillData
field
FillX : IdealIn XUnd (PreDelta+ N) →
Set
-- The following type deals with wrapping issues.
-- When building an N-truncated semisimplicial type X, we will need to know
-- when one ideal x in X was constructed from another ideal y in X
-- via particular constructors. But this constructor could have been applied at *any*
-- earlier stage k, and so x and y will be wrapped N-k times in the passage from a
-- k-truncated semisimplicial set to an N-truncated one. Thus we won't be able to
-- directly look at the constructors used to form y from x.
-- The type isBuildOf keeps track of this information for us as we wrap things to increasing depth.
--
-- Let sx be of shape one bigger than x, let y be the last face of x,
-- and let sy be of shape one bigger than y.
-- Then isBuildOf x sx y sy will tell you if sx was built from x by attaching sy at y.
isBuildOf : ∀ {N : ℕ} → ∀ (X : sSet N) →
∀ {d : ℕ} → ∀ {F : Face N d} → ∀ (x : IdealIn X F) →
∀ {sd : ℕ} → ∀ {sF : Face N sd} →
-- ∀ (fsf : isSucF F sF) →
∀ (sx : IdealIn X sF) →
∀ {e : ℕ} → ∀ {G : Face N e} → ∀ (y : IdealIn X G) →
∀ {se : ℕ} → ∀ {sG : Face N se} →
-- ∀ (gsg : isSucF G sG) →
∀ (sy : IdealIn X sG) →
Set
--These things will be defined inductively, with special cases for N = 0.
data IdealIn0 (X0 : Set) :
∀ {d : ℕ} → ∀ (F : Face zero d) →
Set where
taut0 : ∀ (x : X0) → IdealIn0 X0 (inc emp)
data isFaceOf0 (X0 : Set) :
∀ {d : ℕ} → ∀ {F : Face zero d} → IdealIn0 X0 F →
∀ {d' : ℕ} → ∀ {F' : Face zero d'} → IdealIn0 X0 F' →
∀ {n' : ℕ} → ∀ (G : Face zero n') →
Set where
refl0 : ∀ (x : X0) → isFaceOf0 X0 (taut0 x) (taut0 x) (inc emp)
data isBuildOf0 (X0 : Set) :
∀ {d : ℕ} → ∀ {F : Face 0 d} → ∀ (x : IdealIn0 X0 F) →
∀ {sd : ℕ} → ∀ {sF : Face 0 sd} →
-- ∀ (fsf : isSucF F sF) →
∀ (sx : IdealIn0 X0 sF) →
∀ {e : ℕ} → ∀ {G : Face 0 e} → ∀ (y : IdealIn0 X0 G) →
∀ {se : ℕ} → ∀ {sG : Face 0 se} →
-- ∀ (gsg : isSucF G sG) →
∀ (sy : IdealIn0 X0 sG) →
Set where
-- In dimension N+1, the definitions will be more complicated.
data IdealInN {N : ℕ} (XUnd : sSet N) (XFill : FillData XUnd) :
∀ {d : ℕ} → ∀ (F : Face (suc N) d) →
Set
data isFaceOfN {N : ℕ} (XUnd : sSet N) (XFill : FillData XUnd) :
∀ {d : ℕ} → ∀ {F : Face (suc N) d} → IdealInN XUnd XFill F →
∀ {d' : ℕ} → ∀ {F' : Face (suc N) d'} → IdealInN XUnd XFill F' →
∀ {n' : ℕ} → ∀ (G : Face (suc N) n') →
Set
data isBuildOfN {N : ℕ} (XUnd : sSet N) (XFill : FillData XUnd) :
∀ {d : ℕ} → ∀ {F : Face (suc N) d} → ∀ (x : IdealInN XUnd XFill F) →
∀ {sd : ℕ} → ∀ {sF : Face (suc N) sd} →
-- ∀ (fsf : isSucF F sF) →
∀ (sx : IdealInN XUnd XFill sF) →
∀ {e : ℕ} → ∀ {G : Face (suc N) e} → ∀ (y : IdealInN XUnd XFill G) →
∀ {se : ℕ} → ∀ {sG : Face (suc N) se} →
-- ∀ (gsg : isSucF G sG) →
∀ (sy : IdealInN XUnd XFill sG) →
Set
--Inductive definitions of all of this data.
IdealIn (Aug X0) = IdealIn0 X0
IdealIn (reedy XUnd XFill) = IdealInN XUnd XFill
isFaceOf (Aug X0) = isFaceOf0 X0
isFaceOf (reedy XUnd XFill) = isFaceOfN XUnd XFill
-- isBuildOf (reedy XUnd XFill) = isBuildOfN XUnd XFill
isBuildOf (Aug X0) = isBuildOf0 X0
isBuildOf (reedy XUnd XFill) = isBuildOfN XUnd XFill
data IdealInN {N} XUnd XFill where
--Inherit ideals from the previous dimension. Need to tack on a leading zero.
oldN : ∀ {d : ℕ} → ∀ {F : Face N d} → ∀ (x : IdealIn XUnd F) →
IdealInN XUnd XFill (0x F)
-- Promote the ideal given by filling a sphere from the previous dimension.
fillN : ∀ {x : IdealIn XUnd (PreDelta+ N)} → ∀ (z : FillData.FillX XFill x) →
IdealInN XUnd XFill (0x (inc (Delta+ N)))
--Build a new closed ideal from an open ideal and some previously-constructed filling data.
-- sF is required to be a simplex, so that it is a *new* thing to build and not already previously constructed.
-- x is of shape "strictly below sF".
-- y is the sF-face of x, i.e. the boundary of the next simplex to be added to complete to "weakly below sF".
-- so y ought to be of shape "boundary of a simplex", but this is not enforced explicitly.
-- sy is an ideal (so should be in fact a simplex) filling y.
-- We obtain buildN z xy of shape "weakly below S" by gluing z onto x along y.
buildN : ∀ {d : ℕ} → ∀ {F : Face (suc N) d} → ∀ (x : IdealInN XUnd XFill F) →
∀ {sd : ℕ} → ∀ {sF : Simp (suc N) (suc sd)} → ∀ (fsf : isSucF F (inc sF)) →
∀ {e : ℕ} → ∀ {G : Face (suc N) e} → ∀ {y : IdealInN XUnd XFill G} → ∀ (xy : isFaceOfN XUnd XFill x y (inc sF)) →
∀ {se : ℕ} → ∀ {sG : Face (suc N) (suc se)} → ∀ (gsg : isSucF G sG) →
∀ (sy : IdealInN XUnd XFill sG) →
∀ (ysy : isBuildOfN XUnd XFill y sy y sy) →
IdealInN XUnd XFill (inc sF)
data isFaceOfN {N} XUnd XFill where
--Inherit face relations from the previous dimension. Need to tack on a leading zero.
-- If x' is a G - face of x in the previous dimension,
-- then oldN x' is a 0x G - face of oldN x, and also a 1x G -face of oldN x.
oldOld0N : ∀ {d : ℕ} → ∀ {F : Face N d} → ∀ {d' : ℕ} → ∀ {F' : Face N d'} → ∀ {n' : ℕ} → ∀ {G : Face N n'} →
∀ {x : IdealIn XUnd F} → ∀ {x' : IdealIn XUnd F'} → ∀ (xx' : isFaceOf XUnd x x' G) →
isFaceOfN XUnd XFill (oldN x) (oldN x') (0x G)
oldOld1N : ∀ {d : ℕ} → ∀ {F : Face N d} → ∀ {d' : ℕ} → ∀ {F' : Face N d'} → ∀ {n' : ℕ} → ∀ {G : Face N n'} →
∀ {x : IdealIn XUnd F} → ∀ {x' : IdealIn XUnd F'} → ∀ (xx' : isFaceOf XUnd x x' G) →
isFaceOfN XUnd XFill (oldN x) (oldN x') (inc (1x G))
-- When filling a top-dimensional sphere from the previous dimension, need to inherit faces from the boundary being filled.
-- If x is an N-sphere filled by z, and x' is an old G-face of x,
-- then oldN x' is a 0x G - face of fillN z, and also a 1x G - face of fillN z.
oldFill0N : ∀ {x : IdealIn XUnd (PreDelta+ N)} → ∀ (z : FillData.FillX XFill x) →
∀ {d : ℕ} → ∀ {F : Face N d} → ∀ {x' : IdealIn XUnd F} → ∀ {n' : ℕ} → ∀ {G : Face N n'} → ∀ (xx' : isFaceOf XUnd x x' G) →
isFaceOfN XUnd XFill (fillN z) (oldN x') (0x G)
oldFill1N : ∀ {x : IdealIn XUnd (PreDelta+ N)} → ∀ (z : FillData.FillX XFill x) →
∀ {d : ℕ} → ∀ {F : Face N d} → ∀ {x' : IdealIn XUnd F} → ∀ {n' : ℕ} → ∀ {G : Face N n'} → ∀ (xx' : isFaceOf XUnd x x' G) →
isFaceOfN XUnd XFill (fillN z) (oldN x') (inc (1x G))
-- When filling a top-dimensional sphere from the previous dimension, need to put in a reflexivity face relation.
-- There are actually two -- one for the face 111111 and one for the face 011111
reflFill0N : ∀ {x : IdealIn XUnd (PreDelta+ N)} → ∀ (z : FillData.FillX XFill x) →
isFaceOfN XUnd XFill (fillN z) (fillN z) (0x (inc (Delta+ N)))
reflFill1N : ∀ {x : IdealIn XUnd (PreDelta+ N)} → ∀ (z : FillData.FillX XFill x) →
isFaceOfN XUnd XFill (fillN z) (fillN z) (inc (1x (inc (Delta+ N))))
-- When building a new ideal, need to inherit faces from the open ideal being filled.
-- This function takes 21 arguments, 7 of them explicit. I believe it is the second-longest type signature in the file.
-- sF is required to be a simplex, so that it is a *new* thing to build and not already previously constructed.
-- x is of shape "strictly below sF".
-- y is the sF-face of x, i.e. the boundary of the next simplex to be added to complete to "weakly below sF".
-- so y ought to be of shape "boundary of a simplex", but this is not enforced explicitly.
-- sy is an ideal (so should be in fact a simplex) filling y.
-- x' is a face of x.
-- conclude that, when you glue sy to x along y, you have x' as a face.
oldBuildN : ∀ {d : ℕ} → ∀ {F : Face (suc N) d} → ∀ (x : IdealInN XUnd XFill F) →
∀ {sd : ℕ} → ∀ {sF : Simp (suc N) (suc sd)} → ∀ (fsf : isSucF F (inc sF)) →
∀ {e : ℕ} → ∀ {G : Face (suc N) e} → ∀ {y : IdealInN XUnd XFill G} → ∀ (xy : isFaceOfN XUnd XFill x y (inc sF)) →
∀ {se : ℕ} → ∀ {sG : Face (suc N) (suc se)} → ∀ (gsg : isSucF G sG) →
∀ (sy : IdealInN XUnd XFill sG) →
∀ (ysy : isBuildOfN XUnd XFill y sy y sy) →
∀ {d' : ℕ} → ∀ {F' : Face (suc N) d'} → ∀ {x' : IdealInN XUnd XFill F'} →
∀ {n' : ℕ} → ∀ {H : Face (suc N) n'} → ∀ (xx' : isFaceOfN XUnd XFill x x' H) →
isFaceOfN XUnd XFill (buildN x fsf xy gsg sy ysy) x' H
-- When building a new ideal, need to put in "mixed" faces, built from faces of the open ideal being filled and the filling data.
-- This constructor takes 32 arguments, 13 of them explicit. I believe that's the longest in the file.
-- sF is required to be a simplex, so that it is a *new* thing to build and not already previously constructed.
-- x is of shape "strictly below sF".
-- y is the sF-face of x, i.e. the boundary of the next simplex to be added to complete to "weakly below sF".
-- so y ought to be of shape "boundary of a simplex", but this is not enforced explicitly.
-- sy is an ideal (so should be in fact a simplex) filling y.
-- x' is a face of x.
-- conclude that when you glue sy to x along y, then sx' is a face.
mixBuildN : ∀ {d : ℕ} → ∀ {F : Face (suc N) d} → ∀ (x : IdealInN XUnd XFill F) →
∀ {sd : ℕ} → ∀ {sF : Simp (suc N) (suc sd)} → ∀ (fsf : isSucF F (inc sF)) →
∀ {e : ℕ} → ∀ {G : Face (suc N) e} → ∀ {y : IdealInN XUnd XFill G} → ∀ (xy : isFaceOfN XUnd XFill x y (inc sF)) →
∀ {se : ℕ} → ∀ {sG : Face (suc N) (suc se)} → ∀ (gsg : isSucF G sG) →
∀ (sy : IdealInN XUnd XFill sG) →
∀ (ysy : isBuildOfN XUnd XFill y sy y sy) →
∀ {d' : ℕ} → ∀ {F' : Face (suc N) d'} → ∀ {x' : IdealInN XUnd XFill F'} →
∀ {n' : ℕ} → ∀ {H : Face (suc N) n'} → ∀ (xx' : isFaceOfN XUnd XFill x x' H) →
∀ {sd' : ℕ} → ∀ {sF' : Simp (suc N) (suc sd)} → ∀ (f'sf' : isSucF F' (inc sF')) →
∀ (x'y : isFaceOfN XUnd XFill x' y (inc sF')) →
∀ {sx' : IdealInN XUnd XFill (inc sF')} → ∀ (x'sx'ysy : isBuildOfN XUnd XFill x' sx' y sy) →
∀ {n'' : ℕ} → ∀ {F'' : Face n' n''} → ∀ (shf'' : isPB (inc sF) H F'') →
∀ {00F'' : Face (suc N) n''} → ∀ (00f'' : isPadOf F'' 00F'') →
isFaceOfN XUnd XFill (buildN x fsf xy gsg sy ysy) sx' 00F''
data isBuildOfN {N} XUnd XFill where
-- Carry forward the old build relations from XUnd.
oldIsBuildN : ∀ {d : ℕ} → ∀ {F : Face N d} → ∀ (x : IdealIn XUnd F) →
∀ {sd : ℕ} → ∀ {sF : Face N (suc sd)} → ∀ (fsf : isSucF F sF) →
∀ (sx : IdealIn XUnd sF) →
∀ {e : ℕ} → ∀ {G : Face N e} → ∀ (y : IdealIn XUnd G) →
∀ {se : ℕ} → ∀ {sG : Face N (suc se)} → ∀ (gsg : isSucF G sG) →
∀ (sy : IdealIn XUnd sG) →
isBuildOf XUnd x sx y sy →
isBuildOfN XUnd XFill (oldN x) (oldN sx) (oldN y) (oldN sy)
-- When filling an N-boundary, we have a reflexive build relationship.
fillIsBuildN : ∀ {x : IdealIn XUnd (PreDelta+ N)} → ∀ (z : FillData.FillX XFill x) →
isBuildOfN XUnd XFill (oldN x) (fillN z) (oldN x) (fillN z)
-- When we build a new ideal, record it here.
buildIsBuildN : ∀ {d : ℕ} → ∀ {F : Face (suc N) d} → ∀ (x : IdealInN XUnd XFill F) →
∀ {sd : ℕ} → ∀ {sF : Simp (suc N) (suc sd)} → ∀ (fsf : isSucF F (inc sF)) →
∀ {e : ℕ} → ∀ {G : Face (suc N) e} → ∀ {y : IdealInN XUnd XFill G} → ∀ (xy : isFaceOfN XUnd XFill x y (inc sF)) →
∀ {se : ℕ} → ∀ {sG : Face (suc N) (suc se)} → ∀ (gsg : isSucF G sG) →
∀ (sy : IdealInN XUnd XFill sG) →
∀ (ysy : isBuildOfN XUnd XFill y sy y sy) →
isBuildOfN XUnd XFill x (buildN x fsf xy gsg sy ysy) y sy
| {
"alphanum_fraction": 0.5391550747,
"avg_line_length": 61.8645418327,
"ext": "agda",
"hexsha": "7d84f524232cc34bad2077329e13439a528ed9c6",
"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": "32e4befba7b51aa663bad4b1fd89777499f51ca1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "tcampion/Semisimplicial",
"max_forks_repo_path": "semisimplicial.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "32e4befba7b51aa663bad4b1fd89777499f51ca1",
"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": "tcampion/Semisimplicial",
"max_issues_repo_path": "semisimplicial.agda",
"max_line_length": 137,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "32e4befba7b51aa663bad4b1fd89777499f51ca1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "tcampion/Semisimplicial",
"max_stars_repo_path": "semisimplicial.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-22T18:40:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-16T18:34:08.000Z",
"num_tokens": 5346,
"size": 15528
} |
-- Andreas, 2020-04-15, issue #4586
-- Better error for invalid let pattern.
test : Set₁
test = let () = Set
in Set
-- WAS:
-- Set₁ should be empty, but that's not obvious to me
-- when checking that the pattern () has type Set₁
-- EXPECTED:
-- Not a valid let pattern
-- when scope checking let () = Set in Set
| {
"alphanum_fraction": 0.6563467492,
"avg_line_length": 21.5333333333,
"ext": "agda",
"hexsha": "14f2dc07d69c2735f88f25c992d2fe9491527fba",
"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/Issue4586LetPatternAbsurd.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/Issue4586LetPatternAbsurd.agda",
"max_line_length": 53,
"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/Issue4586LetPatternAbsurd.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": 93,
"size": 323
} |
{-# OPTIONS --without-K #-}
module Preliminaries where
open import lib.Basics hiding (_⊔_)
open import lib.NType2
open import lib.types.Nat hiding (_+_)
open import lib.types.Pi
open import lib.types.Sigma hiding (×-comm)
open import lib.types.Unit
open import lib.types.TLevel
open import lib.types.Paths
-- Most of the contents of Chapter 2.1 are in the library, e.g.
-- natural numbers. We only do the following two adaptions here:
-- A readable notation for the join of universe levels.
infixr 8 _⊔_
_⊔_ : ULevel → ULevel → ULevel
_⊔_ = lmax
-- Addition operator adjustment.
_+_ : ℕ → ℕ → ℕ
a + b = b lib.types.Nat.+ a -- n + 1 should mean S n (author preference)!
-- Chapter 2.2: We list the lemmata and other statements here.
-- Lemma 2.2.1
transport-is-comp : ∀ {i j} {X : Type i} {Y : Type j} → {x₁ x₂ : X}
→ (h k : X → Y) → (t : x₁ == x₂) → (p : h x₁ == k x₁)
→ (transport _ t p) == ! (ap h t) ∙ p ∙ ap k t
transport-is-comp h k idp p = ! (∙-unit-r _)
-- Lemma 2.2.2 is in the library:
-- lib.NType2.raise-level-<T
-- Lemma 2.2.3 is in the library as well:
-- lib.types.Sigma.Σ-level
-- ... and so is Definition 2.2.4:
-- lib.NType2._-Type_
-- Lemma 2.2.6 as well:
-- lib.types.Pi.Π-level
-- Lemma 2.2.7:
-- lib.NType2.has-level-is-prop
module _ {i j} {A : Type i} {B : A → Type j} where
module _ (h : (a : A) → is-contr (B a)) where
-- Lemma 2.2.8 (i)
Σ₂-contr : Σ A B ≃ A
Σ₂-contr = Σ₂-Unit ∘e equiv-Σ-snd (λ _ → contr-equiv-Unit (h _))
-- Lemma 2.2.8 (ii)
Π₂-contr : Π A B ≃ ⊤
Π₂-contr = Π₂-Unit ∘e equiv-Π-r (λ _ → contr-equiv-Unit (h _))
module _ (h : is-contr A) where
-- Lemma 2.2.9 (i)
Σ₁-contr : Σ A B ≃ B (fst h)
Σ₁-contr = Σ₁-Unit ∘e equiv-Σ-fst _ (snd (contr-equiv-Unit h ⁻¹)) ⁻¹
-- Lemma 2.2.9 (ii)
Π₁-contr : Π A B ≃ B (fst h)
Π₁-contr = Π₁-Unit ∘e equiv-Π-l _ (snd (contr-equiv-Unit h ⁻¹)) ⁻¹
-- Lemma 2.2.10 - we refer to the library again
-- lib.types.Sigma.Σ-level
-- and
-- lib.types.Sigma.×-level
-- Lemma 2.2.11
-- lib.Equivalences.equiv-ap
-- Lemma 2.2.12 and Remark 2.2.13
module TT-AC {i j k : ULevel} {A : Type i}
{B : A → Type j}
{C : (Σ A B) → Type k} where
-- the two types:
ONE = (a : A) → Σ (B a) λ b → C (a , b)
TWO = Σ ((a : A) -> B a) λ g → (a : A) → C (a , g a)
-- the two canonical functions:
f : ONE → TWO
f one = fst ∘ one , snd ∘ one
g : TWO → ONE
g two = λ a → (fst two) a , (snd two) a
-- the compositions are indeed pointwise judgmentally
-- the identity!
f∘g : (two : TWO) → f (g two) == two
f∘g two = idp
g∘f : (one : ONE) → g (f one) == one
g∘f one = idp
-- Lemma 2.2.14 is in the library:
-- lib.NType.pathto-is-contr
-- lib.NType.pathfrom-is-contr
-- This formalisation has a separated file for Pointed
-- types, called 'Pointed.agda', which contains
-- (among other things) Definition 2.2.15
-- and Lemma 2.2.17
-- Definition 2.2.19
LEM : ∀ {i} → Type (lsucc i)
LEM {i} = (X : Type i) → is-prop X → Coprod X (¬ X)
LEM∞ : ∀ {i} → Type (lsucc i)
LEM∞ {i} = (X : Type i) → Coprod X (¬ X)
-- The following are some auxiliary lemmata/definitions
-- (not numbered in the thesis)
{- The (function) exponentiation operator. For convenience, we
choose to define it via postcomposition in the recursion step. -}
infix 10 _^_
_^_ : ∀ {i} {A : Set i} → (A → A) → ℕ → A → A
f ^ 0 = idf _
f ^ S n = (f ^ n) ∘ f
-- Logical equivalence: maps in both directions
_↔_ : ∀ {i j} → Type i → Type j → Type (i ⊔ j)
X ↔ Y = (X → Y) × (Y → X)
-- Composition of ↔
_◎_ : ∀ {i j k} {X : Type i} {Y : Type j} {Z : Type k} → (X ↔ Y) → (Y ↔ Z) → (X ↔ Z)
e₁ ◎ e₂ = fst e₂ ∘ fst e₁ , snd e₁ ∘ snd e₂
-- Subsection 2.3.3
module wtrunc where
postulate
-- Definition 2.3.2
∣∣_∣∣ : ∀ {i} → (X : Type i) → Type i
tr-is-prop : ∀ {i} {X : Type i} → is-prop (∣∣ X ∣∣)
∣_∣ : ∀ {i} {X : Type i} → X → ∣∣ X ∣∣
tr-rec : ∀ {i j} {X : Type i} {P : Type j} → (is-prop P) → (X → P) → ∣∣ X ∣∣ → P
-- Lemma 2.3.4
-- the induction principle is derivable:
module _ {i j : _} {X : Type i} {P : ∣∣ X ∣∣ → Type j} (h : (z : ∣∣ X ∣∣) → is-prop (P z)) (k : (x : X) → P ∣ x ∣) where
total : Type (i ⊔ j)
total = Σ ∣∣ X ∣∣ P
jj : X → total
jj x = ∣ x ∣ , k x
total-prop : is-prop total
total-prop = Σ-level tr-is-prop h
total-map : ∣∣ X ∣∣ → total
total-map = tr-rec total-prop jj
tr-ind : (z : ∣∣ X ∣∣) → P z
tr-ind z = transport P (prop-has-all-paths tr-is-prop _ _) (snd (total-map z))
-- Remark 2.3.5
-- further, the propositional β-rule is derivable:
trunc-β : ∀ {i j} {X : Type i} {P : Type j} → (pp : is-prop P) → (f : X → P) → (x : X) → tr-rec pp f ∣ x ∣ == f x
trunc-β pp f x = prop-has-all-paths pp _ _
-- comment: Trunc is functorial
trunc-functorial : ∀ {i} {j} {X : Type i} {Y : Type j} → (X → Y) → ∣∣ X ∣∣ → ∣∣ Y ∣∣
trunc-functorial f = tr-rec tr-is-prop (∣_∣ ∘ f)
-- Proposition 2.3.6
impred : ∀ {i} {X : Type i} → ∣∣ X ∣∣ ↔ ((P : Type i) → is-prop P → (X → P) → P)
impred {X = X} = (λ z P pp f → tr-rec pp f z) , λ h → h ∣∣ X ∣∣ tr-is-prop ∣_∣
-- Proposition 2.3.6 (second part) - note that we use funext (in the form: Π preserves truncation level)
impr-equiv : ∀ {i} {X : Type i} → is-equiv (fst (impred {X = X}))
impr-equiv {i} {X} = is-eq (fst (impred {X = X})) (snd (impred {X = X}))
(λ top → prop-has-all-paths (Π-level (λ P → Π-level (λ pp → (Π-level (λ _ → pp))))) _ _)
(λ z → prop-has-all-paths tr-is-prop _ _)
-- The rest of the file contains various useful lemmata
-- and definitions that are NOT in the thesis (at least
-- not as numbered statements).
{- Since natural numbers and universe levels use
different types, we require a translation operation.
We will only make use of this in chapter 7: Higher
Homotopies in a Hierarchy of Univalent Universes. -}
「_」 : ℕ → ULevel
「 0 」 = lzero
「 S n 」 = lsucc 「 n 」
-- A trivial, but useful lemma. The only thing we do is hiding the arguments.
prop-eq-triv : ∀ {i} {P : Type i} → {p₁ p₂ : P} → is-prop P → p₁ == p₂
prop-eq-triv h = prop-has-all-paths h _ _
-- A second such useful lemma
second-comp-triv : ∀ {i} {X : Type i} → {P : X → Type i} → ((x : X) → is-prop (P x)) → (a b : Σ X P) → (fst a == fst b) → a == b
second-comp-triv {P = P} h a b q = pair= q (from-transp P q (prop-eq-triv (h (fst b))))
-- the following is the function which the univalence
-- axiom postulates to be an equivalence
-- (we define it ourselves as we do not want to
-- implicitly import the whole univalence library)
path-to-equiv : ∀ {i} {X : Type i} {Y : Type i} → X == Y → X ≃ Y
path-to-equiv {X = X} idp = ide X
-- some rather silly lemmata
delete-idp : ∀ {i} {X : Type i} → {x₁ x₂ : X} → (p q : x₁ == x₂) → (p ∙ idp == q) ≃ (p == q)
delete-idp idp q = ide _
add-path : ∀ {i} {X : Type i} → {x₁ x₂ x₃ : X} → (p q : x₁ == x₂) → (r : x₂ == x₃) → (p == q) == (p ∙ r == q ∙ r)
add-path idp q idp = transport (λ q₁ → (idp == q₁) == (idp == q ∙ idp)) {x = q ∙ idp} {y = q} (∙-unit-r _) idp
reverse-paths : ∀ {i} {X : Type i} → {x₁ x₂ : X} → (p : x₂ == x₁) → (q : x₁ == x₂) → (! p == q) ≃ (p == ! q)
reverse-paths p idp =
! p == idp ≃⟨ path-to-equiv (add-path _ _ _) ⟩
! p ∙ p == p ≃⟨ path-to-equiv (transport (λ p₁ → (! p ∙ p == p) == (p₁ == p)) (!-inv-l p) idp) ⟩
idp == p ≃⟨ !-equiv ⟩
p == idp ≃∎
switch-args : ∀ {i j k} {X : Type i} {Y : Type j} {Z : X → Y → Type k} → ((x : X) → (y : Y) → Z x y) ≃ ((y : Y) → (x : X) → Z x y)
switch-args = equiv f g h₁ h₂ where
f = λ k y x → k x y
g = λ i x y → i y x
h₁ = λ _ → idp
h₂ = λ _ → idp
-- another useful (but simple) lemma: if we have a proof of (x , y₁) == (x , y₂) and the type of x is a set, we get a proof of y₁ == y₂.
set-lemma : ∀ {i j} {X : Type i} → (is-set X) → {Y : X → Type j} → (x₀ : X) → (y₁ y₂ : Y x₀) → _==_ {A = Σ X Y} (x₀ , y₁) (x₀ , y₂) → y₁ == y₂
set-lemma {X = X} h {Y = Y} x₀ y₁ y₂ p =
y₁ =⟨ idp ⟩
transport Y idp y₁ =⟨ transport {A = x₀ == x₀} (λ q → y₁ == transport Y q y₁)
{x = idp} {y = ap fst p}
(prop-has-all-paths (h x₀ x₀) _ _)
idp ⟩
transport Y (ap fst p) y₁ =⟨ snd-of-p ⟩
y₂ ∎ where
pairs : =Σ {B = Y} (x₀ , y₁) (x₀ , y₂)
pairs = <– (=Σ-eqv _ _) p
paov : y₁ == y₂ [ Y ↓ fst (pairs) ]
paov = snd pairs
snd-of-p : transport Y (ap fst p) y₁ == y₂
snd-of-p = to-transp paov
×-comm : ∀ {i j} {A : Type i} {B : Type j} → (A × B) ≃ (B × A)
×-comm = equiv (λ {(a , b) → (b , a)})
(λ {(b , a) → (a , b)})
(λ _ → idp) (λ _ → idp)
Σ-comm-snd : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
→ Σ (Σ A B) (λ ab → C (fst ab)) ≃ Σ (Σ A C) (λ ac → B (fst ac))
Σ-comm-snd {A = A} {B} {C} =
Σ (Σ A B) (λ ab → C (fst ab)) ≃⟨ Σ-assoc ⟩
Σ A (λ a → B a × C a) ≃⟨ equiv-Σ-snd (λ _ → ×-comm) ⟩
Σ A (λ a → C a × B a) ≃⟨ Σ-assoc ⁻¹ ⟩
Σ (Σ A C) (λ ac → B (fst ac)) ≃∎
flip : ∀ {i j k} {A : Type i} {B : Type j} {C : A → B → Type k}
→ ((a : A) (b : B) → C a b) → ((b : B) (a : A) → C a b)
flip = –> (curry-equiv ∘e equiv-Π-l _ (snd ×-comm) ∘e curry-equiv ⁻¹)
module _ {i j k} {A : Type i} {B : Type j} {C : A → B → Type k} where
↓-cst→app-equiv : {x x' : A} {p : x == x'} {u : (b : B) → C x b} {u' : (b : B) → C x' b}
→ ((b : B) → u b == u' b [ (λ x → C x b) ↓ p ]) ≃ (u == u' [ (λ x → (b : B) → C x b) ↓ p ])
↓-cst→app-equiv {p = idp} = equiv λ= app= (! ∘ λ=-η) (λ= ∘ app=-β)
module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} where
↓-cst2-equiv : {x y : A} (p : x == y) {b : C x} {c : C y}
(q : b == c [ C ↓ p ]) {u : B x} {v : B y}
→ (u == v [ B ↓ p ]) ≃ (u == v [ (λ xy → B (fst xy)) ↓ (pair= p q) ])
↓-cst2-equiv idp idp = ide _
module _ {i} {A B : Type i} (e : A ≃ B) {u : A} {v : B} where
↓-idf-ua-equiv : (–> e u == v) ≃ (u == v [ (λ x → x) ↓ (ua e) ])
↓-idf-ua-equiv = to-transp-equiv _ _ ⁻¹ ∘e (_ , pre∙-is-equiv (ap (λ z → z u) (ap coe (ap-idf (ua e)) ∙ ap –> (coe-equiv-β e))))
-- On propositions, equivalence coincides with logical equivalence.
module _ {i j} {A : Type i} {B : Type j} where
prop-equiv' : (B → is-prop A) → (A → is-prop B) → (A → B) → (B → A) → A ≃ B
prop-equiv' h k f g = equiv f g (λ b → prop-has-all-paths (k (g b)) _ _)
(λ a → prop-has-all-paths (h (f a)) _ _)
prop-equiv : is-prop A → is-prop B → (A → B) → (B → A) → A ≃ B
prop-equiv h k f g = prop-equiv' (cst h) (cst k) f g
-- Equivalent types have equivalent truncatedness propositions.
equiv-level : ∀ {i j} {A : Type i} {B : Type j} {n : ℕ₋₂}
→ A ≃ B → has-level n A ≃ has-level n B
equiv-level u = prop-equiv has-level-is-prop
has-level-is-prop
(equiv-preserves-level u)
(equiv-preserves-level (u ⁻¹))
prop-equiv-inhab-to-contr : ∀ {i} {A : Type i} → is-prop A ≃ (A → is-contr A)
prop-equiv-inhab-to-contr = prop-equiv is-prop-is-prop
(Π-level (λ _ → is-contr-is-prop))
(flip inhab-prop-is-contr)
inhab-to-contr-is-prop
| {
"alphanum_fraction": 0.5084790673,
"avg_line_length": 35.8291139241,
"ext": "agda",
"hexsha": "85f0a7af9d1e1e1d41110ddb9b6f0154fc37f0f9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "nicolai/thesis/Preliminaries.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "nicolai/thesis/Preliminaries.agda",
"max_line_length": 142,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nicolaikraus/HoTT-Agda",
"max_stars_repo_path": "nicolai/thesis/Preliminaries.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": 4649,
"size": 11322
} |
{-# OPTIONS --type-in-type #-} -- NOT SOUND!
open import Data.Empty using (⊥)
open import Data.Nat renaming (ℕ to Nat)
open import Data.Nat.DivMod
open import Data.Product hiding (map)
open import Data.Unit using (⊤)
module x where
{-
https://webspace.science.uu.nl/~swier004/publications/2019-icfp-submission-a.pdf
A predicate transformer semantics for effects
WOUTER SWIERSTRA and TIM BAANEN, Universiteit Utrecht
abstract
reasoning about effectful code harder than pure code
predicate transformer (PT) semantics gives a refinement relation that can be used to
- relate a program to its specification, or
- calculate effectful programs that are correct by construction
INTRODUCTION
key techniques
- syntax of effectful computations represented as free monads
- assigning meaning to these monads gives meaning to the syntactic ops each effect provides
- paper shows how to assign PT semantics to computations arising
from Kleisli arrows on free monads
- enables computing the weakest precondition associated with a given postcondition
- using weakest precondition semantics
- define refinement on computations
- show how to
- use this refinement relation to show a program satisfies its specification, or
- calculate a program from its specification.
- show how programs and specifications may be mixed,
enabling verified programs to be calculated from their specification one step at a time
2 BACKGROUND
Free monads
-}
-- C : type of commands
-- Free C R : returns an 'a' or issues command c : C
-- For each c : C, there is a set of responses R c
-- 2nd arg of Step is continuation : how to proceed after receiving response R c
data Free (C : Set) (R : C → Set) (a : Set) : Set where
Pure : a → Free C R a
Step : (c : C) → (R c → Free C R a) → Free C R a
-- show that 'Free' is a monad:
map : ∀ {a b C : Set} {R : C → Set} → (a → b) → Free C R a → Free C R b
map f (Pure x) = Pure (f x)
map f (Step c k) = Step c (λ r → map f (k r))
return : ∀ {a C : Set} {R : C → Set} → a → Free C R a
return = Pure
_>>=_ : ∀ {a b C : Set} {R : C → Set} → Free C R a → (a → Free C R b) → Free C R b
Pure x >>= f = f x
Step c x >>= f = Step c (λ r → x r >>= f)
{-
different effects choose C and R differently, depending on their ops
Weakest precondition semantics
idea of associating weakest precondition semantics with imperative programs
dates to Dijkstra’s Guarded Command Language [1975]
ways to specify behaviour of function f : a → b
- reference implementation
- define a relation R : a → b → Set
- write contracts and test cases
- PT semantics
call values of type a → Set : predicate on type a
PTs are functions between predicates
e.g., weakest precondition:
-}
-- "maps"
-- function f : a → b and
-- desired postcondition on the function’s output, b → Set
-- to weakest precondition a → Set on function’s input that ensures postcondition satisfied
--
-- note: definition is just reverse function composition
-- wp0 : ∀ {a b : Set} → (f : a → b) → (b → Set) → (a → Set)
wp0 : ∀ {a : Set} {b : Set} (f : a → b) → (b → Set) → (a → Set)
wp0 f P = λ x → P (f x)
{-
above wp semantics is sometimes too restrictive
- no way to specify that output is related to input
- fix via making f dependent:
-}
wp : ∀ {a : Set} {b : a → Set} (f : (x : a) → b x) → ((x : a) → b x → Set) → (a → Set)
wp f P = λ x → P x (f x)
-- shorthand for working with predicates and predicates transformers
_⊆_ : ∀ {a : Set} → (a → Set) → (a → Set) → Set
P ⊆ Q = ∀ x → P x → Q x
-- refinement relation defined between PTs
_⊑_ : ∀ {a : Set} {b : a → Set} → (pt1 pt2 : ((x : a) → b x → Set) → (a → Set)) → Set₁
pt1 ⊑ pt2 = ∀ P → pt1 P ⊆ pt2 P
{-
use refinement relation
- to relate PT semantics between programs and specifications
- to show a program satisfies its specification; or
- to show that one program is somehow ‘better’ than another,
where ‘better’ is defined by choice of PT semantics
in pure setting, this refinement relation is not interesting:
the refinement relation corresponds to extensional equality between functions:
lemma follows from the ‘Leibniz rule’ for equality in intensional type theory:
refinement : ∀ (f g : a → b) → (wp f ⊑ wp g) ↔ (∀ x → f x ≡ g x)
this paper defines PT semantics for Kleisli arrows of form
a → Free C R b
could use 'wp' to assign semantics to these computations directly,
but typically not interested in syntactic equality between free monads
rather want to study semantics of effectful programs they represent
to define a PT semantics for effects
define a function with form:
-- how to lift a predicate on 'a' over effectful computation returning 'a'
pt : (a → Set) → Free C R a → Set
'pt' def depends on semantics desired for a particulr free monad
Crucially,
choice of pt and weakest precondition semantics, wp, together
give a way to assign weakest precondition semantics to Kleisli arrows
representing effectful computations
3 PARTIALITY
Partial computations : i.e., 'Maybe'
make choices for commands C and responses R
-}
data C : Set where
Abort : C -- no continuation
R : C → Set
R Abort = ⊥ -- since C has no continuation, valid responses is empty
Partial : Set → Set
Partial = Free C R
-- smart constructor for failure:
abort : ∀ {a : Set} → Partial a
abort = Step Abort (λ ())
{-
computation of type Partial a will either
- return a value of type a or
- fail, issuing abort command
Note that responses to Abort command are empty;
abort smart constructor abort uses this to discharge the continuation
in the second argument of the Step constructor
Example: division
expression language, closed under division and natural numbers:
-}
data Expr : Set where
Val : Nat → Expr
Div : Expr → Expr → Expr
-- semantics specified using inductively defined RELATION:
-- def rules out erroneous results by requiring the divisor evaluates to non-zero
data _⇓_ : Expr → Nat → Set where
Base : ∀ {x : Nat}
→ Val x ⇓ x
Step : ∀ {l r : Expr} {v1 v2 : Nat}
→ l ⇓ v1
→ r ⇓ (suc v2)
→ Div l r ⇓ (v1 div (suc v2))
-- Alternatively
-- evaluate Expr via monadic INTERPRETER, using Partial to handle division-by-zero
-- op used by ⟦_⟧ interpreter
_÷_ : Nat → Nat → Partial Nat
n ÷ zero = abort
n ÷ (suc k) = return (n div (suc k))
⟦_⟧ : Expr → Partial Nat
⟦ Val x ⟧ = return x
⟦ Div e1 e2 ⟧ = ⟦ e1 ⟧ >>= λ v1 → ⟦ e2 ⟧ >>= λ v2 → v1 ÷ v2
{-
std lib 'div' requires implicit proof that divisor is non-zero
when divisor is zero, interpreter fail explicitly with abort
How to relate these two definitions?
Assign a weakest precondition semantics to Kleisli arrows of the form
a → Partial b
-}
wpPartial : ∀ {a : Set} {b : a → Set}
→ (f : (x : a) → Partial (b x))
→ (P : (x : a) → b x → Set)
→ (a → Set)
wpPartial f P = wp f (mustPT P)
where
mustPT : ∀ {a : Set} {b : a → Set}
→ (P : (x : a) → b x → Set)
→ (x : a)
→ Partial (b x) → Set
mustPT P _ (Pure y) = P _ y
mustPT P _ (Step Abort _) = ⊥
{-
To call 'wp', must show how to transform
- predicate P : b → Set
- to a predicate on partial results : Partial b → Set
Done via proposition 'mustPT P c'
- holds when computation c of type Partial b successfully returns a 'b' that satisfies P
particular PT semantics of partial computations determined by def mustPT
here: rule out failure entirely
- so case Abort returns empty type
Given this PT semantics for Kleisli arrows in general,
can now study semantics of above monadic interpreter
via passing
- interpreter: ⟦_⟧
- desired postcondition : _⇓_
as arguments to wpPartial:
wpPartial ⟦_⟧ _⇓_ : Expr → Set
resulting in a predicate on expressions
for all expressions satisfying this predicate,
the monadic interpreter and the relational specification, _⇓_,
must agree on the result of evaluation
What does this say about correctness of interpreter?
To understand the predicate better, consider defining this predicate on expressions:
-}
SafeDiv : Expr → Set
SafeDiv (Val x) = ⊤
SafeDiv (Div e1 e2) = (e2 ⇓ zero → ⊥) {-∧-} × SafeDiv e1 {-∧-} × SafeDiv e2
{-
Expect : any expr e for which SafeDiv e holds
can be evaluated without division-by-zero
can prove SafeDiv is sufficient condition for two notions of evaluation to coincide:
-- lemma relates the two semantics
-- expressed as a relation and an evaluator
-- for those expressions that satisfy the SafeDiv property
correct : SafeDiv ⊆ wpPartial ⟦_⟧ _⇓_
Instead of manually defining SafeDiv, define more general predicate
characterising the domain of a partial function:
-}
dom : ∀ {a : Set} {b : a → Set}
→ ((x : a)
→ Partial (b x))
→ (a → Set)
dom f = wpPartial f (λ _ _ → ⊤)
{-
can show that the two semantics agree precisely on the domain of the interpreter:
sound : dom ⟦_⟧ ⊆ wpPartial ⟦_⟧ _⇓_
complete : wpPartial ⟦_⟧ _⇓_ ⊆ dom ⟦_⟧
both proofs proceed by induction on the argument expression
Refinement
weakest precondition semantics on partial computations give rise
to a refinement relation on Kleisli arrows of the form a → Partial b
can characterise this relation by proving:
refinement : (f g : a → Maybe b)
→ (wpPartial f ⊑ wpPartial g) ↔ (∀ x → (f x ≡ g x) ∨ (f x ≡ Nothing))
use refinement to relate Kleisli morphisms,
and to relate a program to a specification given by a pre- and postcondition
Example: Add (interpreter for stack machine)
add top two elements; can fail fail if stack has too few elements
below shows how to prove the definition meets its specification
Define specification in terms of a pre/post condition.
The specification of a function of type (x : a) → b x consists of
-}
record Spec (a : Set) (b : a → Set) : Set where
constructor [_,_]
field
pre : a → Set -- a precondition on a, and
post : (x : a) → b x → Set -- a postcondition relating inputs that satisfy this precondition
-- and the corresponding outputs
| {
"alphanum_fraction": 0.6772434308,
"avg_line_length": 31.1265432099,
"ext": "agda",
"hexsha": "43c965cb38852ebf903ccc463b33c324a5e6d5bf",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/paper/Dijkstra-monad/2019-03-Wouter-Swierstra_A_Predicate_Transformer_for_Effects/x.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/paper/Dijkstra-monad/2019-03-Wouter-Swierstra_A_Predicate_Transformer_for_Effects/x.agda",
"max_line_length": 96,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/paper/Dijkstra-monad/2019-03-Wouter-Swierstra_A_Predicate_Transformer_for_Effects/x.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 2777,
"size": 10085
} |
module Issue228 where
open import Common.Level
postulate
∞ : Level
data _×_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where
_,_ : A → B → A × B
data Large : Set ∞ where
large : Large
data Small : Set₁ where
small : Set → Small
P : Set
P = Large × Small
[_] : Set → P
[ A ] = (large , small A)
potentially-bad : P
potentially-bad = [ P ]
| {
"alphanum_fraction": 0.5842696629,
"avg_line_length": 13.6923076923,
"ext": "agda",
"hexsha": "abb71f4bdb4417c77e8f33529b366b6aa94f13d6",
"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/Issue228.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/Issue228.agda",
"max_line_length": 58,
"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/Issue228.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": 131,
"size": 356
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Papers.HigherGroupsViaDURG where
-- Johannes Schipp von Branitz,
-- "Higher Groups via Displayed Univalent Reflexive Graphs in Cubical Type Theory".
import Cubical.Algebra.Group as Group
import Cubical.Core.Glue as Glue
import Cubical.Data.Sigma.Properties as Sigma
import Cubical.Data.Unit as Unit
import Cubical.DStructures.Base as DSBase
import Cubical.DStructures.Meta.Properties as DSProperties
import Cubical.DStructures.Meta.Isomorphism as DSIsomorphism
import Cubical.DStructures.Structures.Action as DSAction
import Cubical.DStructures.Structures.Category as DSCategory
import Cubical.DStructures.Structures.Constant as DSConstant
import Cubical.DStructures.Structures.Group as DSGroup
import Cubical.DStructures.Structures.Higher as DSHigher
import Cubical.DStructures.Structures.Nat as DSNat
import Cubical.DStructures.Structures.PeifferGraph as DSPeifferGraph
import Cubical.DStructures.Structures.ReflGraph as DSReflGraph
import Cubical.DStructures.Structures.SplitEpi as DSSplitEpi
import Cubical.DStructures.Structures.Strict2Group as DSStrict2Group
import Cubical.DStructures.Structures.Type as DSType
import Cubical.DStructures.Structures.Universe as DSUniverse
import Cubical.DStructures.Structures.VertComp as DSVertComp
import Cubical.DStructures.Structures.XModule as DSXModule
import Cubical.DStructures.Equivalences.GroupSplitEpiAction as DSGroupSplitEpiAction
import Cubical.DStructures.Equivalences.PreXModReflGraph as DSPreXModReflGraph
import Cubical.DStructures.Equivalences.XModPeifferGraph as DSXModPeifferGraph
import Cubical.DStructures.Equivalences.PeifferGraphS2G as DSPeifferGraphS2G
import Cubical.Foundations.GroupoidLaws as GroupoidLaws
import Cubical.Foundations.Equiv as Equiv
import Cubical.Foundations.Equiv.Fiberwise as Fiberwise
import Cubical.Foundations.Filler as Filler
import Cubical.Foundations.HLevels as HLevels
import Cubical.Foundations.HLevels' as HLevels'
import Cubical.Foundations.Isomorphism as Isomorphism
import Cubical.Foundations.Prelude as Prelude
import Cubical.Foundations.Path as FPath
import Cubical.Foundations.Pointed as Pointed
import Cubical.Foundations.Univalence as Univalence
import Cubical.Foundations.Transport as Transport
import Cubical.Functions.FunExtEquiv as FunExtEquiv
import Cubical.Functions.Fibration as Fibration
import Cubical.Relation.Binary as Binary
import Cubical.HITs.EilenbergMacLane1 as EM1
import Cubical.Homotopy.Base as HomotopyBase
import Cubical.Homotopy.Connected as Connected
import Cubical.Homotopy.PointedFibration as PointedFibration
import Cubical.Homotopy.Loopspace as Loopspace
import Cubical.Structures.Subtype as Subtype
import Cubical.HITs.Truncation as Truncation
----------------------------------------------------------------------------
-- 2. Cubical Type Theory
-- 2.1 Dependent Type Theory
-- 2.2 Path Types
-- 2.3 Cubical Groupoid Laws
-- 2.4 Functions, Equivalences and Univalence
-- 2.5 Truncated and Connected Types
-- 2.6 Groups
----------------------------------------------------------------------------
-- 2.2 Path Types
-- Example 2.1
open Sigma using (ΣPath≡PathΣ) public
open Prelude using (transport) public
-- Proposition 2.2
open FPath using (PathP≡Path) public
-- 2.3 Cubical Groupoid Laws
open Prelude using (refl;
transportRefl;
subst;
J) public
renaming (cong to ap) public
open Prelude using (_∙∙_∙∙_;
doubleCompPath-filler;
compPath-unique) public
open Prelude using (_∙_) public
-- Lemma 2.5
open FPath using (PathP≡doubleCompPathˡ) public
-- Lemma 2.5
open GroupoidLaws using (doubleCompPath-elim) public
-- Lemma 2.6
open Filler using (cube-cong) public
-- 2.4 Functions, Equivalences and Univalence
open Unit renaming (Unit to 𝟙) public
open Prelude using (isContr) public
open Unit using (isContrUnit) public
-- Proposition 2.7
open Prelude using (singl;
isContrSingl) public
-- Definition 2.8
open Equiv renaming (fiber to fib) public
open Glue using (isEquiv;
_≃_;
equivFun) public
open Isomorphism using (Iso) public
-- Proposition 2.9
open Transport using (isEquivTransport) public
-- Proposition 2.10
open Fiberwise using (fiberEquiv;
totalEquiv) public
-- Proposition 2.11
open Sigma using (Σ-cong-equiv) public
-- Definition 2.12
open HomotopyBase using (_∼_) public
-- Theorem 2.13
open FunExtEquiv using (funExtEquiv) public
-- Theorem 2.14
open Univalence using (univalence) public
renaming (ua to idToEquiv⁻¹;
uaβ to idToEquiv-β;
uaη to idToEquiv-η) public
-- Lemma 2.15
open Univalence using (ua→) public
-- 2.5 Truncated and Connected Types
open Prelude using (isProp;
isSet) public
open HLevels using (isOfHLevel;
TypeOfHLevel) public
-- Lemma 2.16
open Sigma using (Σ-contractFst;
Σ-contractSnd) public
-- Lemma 2.17
open Prelude using (isProp→PathP) public
-- Lemma 2.18
open Subtype using (subtypeWitnessIrrelevance) public
open Sigma using (Σ≡Prop) public
-- Definition 2.19
open HLevels using (isOfHLevelDep) public
-- Proposition 2.20
open HLevels' using (truncSelfId→truncId) public
-- Proposition 2.21
open HLevels using (isOfHLevelΣ) public
-- Proposition 2.22
open HLevels using (isPropIsOfHLevel) public
-- Proposition 2.23
open HLevels using (isOfHLevelΠ) public
-- Theorem 2.24
open Truncation using (∥_∥_;
rec;
elim) public
-- Definition 2.25
open Connected using (isConnected;
isConnectedFun) public
-- Lemma 2.26
open Connected using (isConnectedPoint) public
-- 2.6 Groups
-- Proposition 2.28
open Group using (isPropIsGroupHom;
isSetGroupHom) public
-- Proposition 2.29
open Group.Kernel using (ker) public
-- Proposition 2.30
open Group using (GroupMorphismExt) public
-- Theorem 2.31
open Group using (GroupPath) public
-- Definition 2.32
open Group using (isGroupSplitEpi) public
-- Definition 2.33
open Group using (GroupAction;
IsGroupAction) public
-- Proposition 2.34
open Group using (semidirectProd) public
-----------------------------------------------------------------------------
-- 3. Displayed Structures
-- 3.1 Motivation
-- 3.2 Displayed Categories
-- 3.3 Univalent Reflexive Graphs
-- 3.4 Displayed Univalent Reflexive Graphs
-- 3.5 Operations on Displayed Univalent Reflexive Graphs
-- 3.6 Constructing Equivalences Using Displayed Univalent Reflexive Graphs
-----------------------------------------------------------------------------
-- 3.1 Motivation
-- Proposition 3.1
open Fibration using (dispTypeIso) public
-- 3.2 Displayed Categories
-- Definition 3.2
-- not implemented
-- Theorem 3.3
-- not implemented
-- 3.3 Univalent Reflexive Graphs
-- Definition 3.4, 3.5
open DSBase using (URGStr) public
-- Example 3.6
open DSGroup using (𝒮-group) public
-- Example 3.7
open DSCategory using (Cat→𝒮) public
-- Proposition 3.8
-- not implemented
-- Example 3.9
open DSNat using (𝒮-Nat) public
-- Theorem 3.10
open Binary using (contrRelSingl→isUnivalent;
isUnivalent→contrRelSingl) public
-- Example 3.11
open DSType using (𝒮-type) public
open DSUniverse using (𝒮-universe) public
-- Proposition 3.12
open DSType using (𝒮-uniqueness) public
-- 3.4 Displayed Univalent Reflexive Graphs
-- Proposition 3.13
open DSBase using (URGStrᴰ) public
open DSBase using (make-𝒮ᴰ) public
-- Proposition 3.14
open DSType using (Subtype→Sub-𝒮ᴰ) public
-- Example 3.15
open DSHigher using (𝒮ᴰ-connected;
𝒮ᴰ-truncated) public
-- 3.5 Operations on Displayed Univalent Reflexive Graphs
-- Theorem 3.16
open DSProperties using (∫⟨_⟩_) public
-- Corollary 3.17
open DSConstant using (𝒮ᴰ-const) public
-- Definition 3.18
open DSConstant using (_×𝒮_) public
-- Theorem 3.19
open DSProperties using (splitTotal-𝒮ᴰ) public
-- Proposition 3.20
open DSProperties using (VerticalLift-𝒮ᴰ) public
-- Corollary 3.21
open DSProperties using (combine-𝒮ᴰ) public
-- 3.6 Constructing Equivalences Using Displayed Univalent Reflexive Graphs
-- Definition 3.22
open Binary using (RelIso) public
-- Proposition 3.23
open DSIsomorphism using (𝒮-PIso;
𝒮-PIso→Iso) public
-- Definition 3.24, Theorem 3.25
open Binary using (RelFiberIsoOver→Iso) public
open DSIsomorphism using (𝒮ᴰ-♭PIso-Over→TotalIso) public
-----------------------------------------------------------------------------
-- 4. Equivalence of Strict 2-Groups and Crossed Modules
-- 4.1 Strict 2-Groups
-- 4.2 Crossed Modules
-- 4.3 Group Actions and Split Monomorphisms
-- 4.4 Precrossed Modules and Internal Reflexive Graphs
-- 4.5 Crossed Modules and Peiffer Graphs
-- 4.6 Peiffer Graphs and Strict 2-Groups
----------------------------------------------------------------------------
-- 4.1 Strict 2-Groups
-- Example 4.1
-- not implemented
-- 4.2 Crossed Modules
-- Definition 4.2, Example 4.3
-- not implemented
-- 4.3 Group Actions and Split Monomorphisms
-- Proposition 4.4
open DSGroup using (𝒮ᴰ-G²\F;
𝒮ᴰ-G²\B;
𝒮ᴰ-G²\FB) public
-- Lemma 4.5
open DSSplitEpi using (𝒮ᴰ-SplitEpi) public
-- Lemma 4.6
open DSAction using (𝒮ᴰ-G²\Las) public
-- Lemma 4.7
open DSAction using (𝒮ᴰ-G²Las\Action) public
-- Proposition 4.8, Proposition 4.9, Lemma 4.10, Theorem 4.11
open DSGroupSplitEpiAction using (𝒮ᴰ-Iso-GroupAct-SplitEpi-*;
IsoActionSplitEpi) public
-- 4.4 Precrossed Modules and Internal Reflexive Graphs
-- Lemma 4.12
open DSXModule using (𝒮ᴰ-Action\PreXModuleStr) public
-- Definition 4.13
open DSXModule using (isEquivariant;
isPropIsEquivariant;
PreXModule) public
-- Lemma 4.14
open DSSplitEpi using (𝒮ᴰ-G²FBSplit\B) public
-- Lemma 4.15
open DSReflGraph using (𝒮ᴰ-ReflGraph; ReflGraph) public
-- Lemma 4.16, Lemma 4.17, Lemma 4.18, Theorem 4.19
open DSPreXModReflGraph using (𝒮ᴰ-♭PIso-PreXModule'-ReflGraph';
Iso-PreXModule-ReflGraph) public
-- 4.5 Crossed Modules and Peiffer Graphs
-- Definition 4.20
open DSXModule using (XModule;
isPeiffer;
isPropIsPeiffer) public
-- Definition 4.21
open DSPeifferGraph using (isPeifferGraph;
isPropIsPeifferGraph) public
-- Lemma 4.22, Lemma 4.2.3, Theorem 4.24
open DSXModPeifferGraph public
-- 4.6 Peiffer Graphs and Strict 2-Groups
-- Definition 4.25
open DSVertComp using (VertComp) public
-- Proposition 4.26
open DSVertComp using (VertComp→+₁) public
-- Proposition 4.27
open DSVertComp using (isPropVertComp) public
-- Proposition 4.28, Proposition 4.29, Theorem 4.30
open DSPeifferGraphS2G public
--------------------------------------------------------
-- 5. Higher Groups in Cubical Type Theory
-- 5.1 Pointed Types
-- 5.2 Homotopy Groups
-- 5.3 Higher Groups
-- 5.4 Eilenberg-MacLane-Spaces
-- 5.5 Delooping Groups
-------------------------------------------------------
-- 5.1 Pointed Types
-- Proposition 5.1
open DSUniverse using (𝒮ᴰ-pointed) public
-- Definition 5.2
open Pointed using (Π∙) public
-- Definition 5.3
open Pointed using (_∙∼_;
_∙∼P_) public
-- Proposition 5.4
open Pointed using (∙∼≃∙∼P) public
-- Theorem 5.5
open Pointed using (funExt∙≃) public
-- Theorem 5.6
open PointedFibration using (sec∙Trunc') public
-- 5.2 Homotopy Groups
-- Definition 5.7
open Loopspace using (Ω) public
-- Definition 5.8
open Group using (π₁-1BGroup) public
-- 5.3 Higher Groups
-- Lemma 5.9
open DSHigher using (𝒮-BGroup) public
-- Definition 5.10
open Group using (BGroup) public
-- Proposition 5.11
open DSHigher using (𝒮ᴰ-BGroupHom) public
-- Corollary 5.12
-- not implemented
-- 5.4 Eilenberg-MacLane-Spaces
-- Definition 5.13
open EM1 using (EM₁) public
-- Lemma 5.14
open EM1 using (emloop-comp) public
-- Lemma 5.15
open EM1 using (elimEq) public
-- Theorem 5.16
open EM1 renaming (elim to EM₁-elim;
rec to EM₁-rec) public
-- Lemma 5.17
open Group using (emloop-id;
emloop-inv) public
-- Theorem 5.18
open Group using (π₁EM₁≃) public
-- 5.5 Delooping Groups
-- Proposition 5.19, Theorem 5.20
open DSHigher using (𝒮-Iso-BGroup-Group) public
| {
"alphanum_fraction": 0.6939934416,
"avg_line_length": 23.9063097514,
"ext": "agda",
"hexsha": "96441e8809db775de1dcbf659bd54d1d3986fd06",
"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": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Schippmunk/cubical",
"max_forks_repo_path": "Cubical/Papers/HigherGroupsViaDURG.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"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": "Schippmunk/cubical",
"max_issues_repo_path": "Cubical/Papers/HigherGroupsViaDURG.agda",
"max_line_length": 84,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Schippmunk/cubical",
"max_stars_repo_path": "Cubical/Papers/HigherGroupsViaDURG.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3758,
"size": 12503
} |
open import Mockingbird.Forest using (Forest)
-- Aristocratic Birds
module Mockingbird.Problems.Chapter19 {ℓb ℓ} (forest : Forest {ℓb} {ℓ}) where
open import Data.Product using (_×_; _,_; ∃-syntax)
open import Function using (_$_)
open import Level using (_⊔_)
open import Data.Vec using ([]; _∷_)
open import Relation.Unary using (Pred; _∈_; _⊆_; _⊇_)
open Forest forest
open import Mockingbird.Forest.Birds forest
open import Mockingbird.Forest.Combination.Vec forest
open import Mockingbird.Forest.Combination.Vec.Properties forest
open import Mockingbird.Forest.Extensionality forest
import Mockingbird.Problems.Chapter11 forest as Chapter₁₁
import Mockingbird.Problems.Chapter12 forest as Chapter₁₂
problem₁″ : ⦃ _ : HasEagle ⦄ ⦃ _ : HasCardinalOnceRemoved ⦄ ⦃ _ : HasCardinalTwiceRemoved ⦄ ⦃ _ : HasWarbler ⦄ → HasJaybird
problem₁″ = record
{ J = C** ∙ (W ∙ (C* ∙ E))
; isJaybird = λ x y z w → begin
C** ∙ (W ∙ (C* ∙ E)) ∙ x ∙ y ∙ z ∙ w ≈⟨ isCardinalTwiceRemoved (W ∙ (C* ∙ E)) x y z w ⟩
W ∙ (C* ∙ E) ∙ x ∙ y ∙ w ∙ z ≈⟨ congʳ $ congʳ $ congʳ $ isWarbler (C* ∙ E) x ⟩
C* ∙ E ∙ x ∙ x ∙ y ∙ w ∙ z ≈⟨ congʳ $ congʳ $ isCardinalOnceRemoved E x x y ⟩
E ∙ x ∙ y ∙ x ∙ w ∙ z ≈⟨ isEagle x y x w z ⟩
x ∙ y ∙ (x ∙ w ∙ z) ∎
}
problem₁′ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasCardinal ⦄ ⦃ _ : HasWarbler ⦄ → HasJaybird
problem₁′ = record
{ J = B ∙ (B ∙ C) ∙ (W ∙ (B ∙ C ∙ (B ∙ (B ∙ B ∙ B))))
; isJaybird = isJaybird ⦃ problem₁″ ⦄
} where
instance
hasEagle = Chapter₁₁.problem₇
hasCardinalOnceRemoved = Chapter₁₁.problem₃₁
hasCardinalTwiceRemoved = Chapter₁₁.problem₃₅-C**
problem₁ : ⦃ _ : HasBluebird ⦄ ⦃ _ : HasThrush ⦄ ⦃ _ : HasMockingbird ⦄ → HasJaybird
problem₁ = problem₁′
where
instance
hasCardinal = Chapter₁₁.problem₂₁′
hasWarbler = Chapter₁₂.problem₇
problem₂ : ⦃ _ : HasJaybird ⦄ ⦃ _ : HasIdentity ⦄ → HasQuixoticBird
problem₂ = record
{ Q₁ = J ∙ I
; isQuixoticBird = λ x y z → begin
J ∙ I ∙ x ∙ y ∙ z ≈⟨ isJaybird I x y z ⟩
I ∙ x ∙ (I ∙ z ∙ y) ≈⟨ congʳ $ isIdentity x ⟩
x ∙ (I ∙ z ∙ y) ≈⟨ congˡ $ congʳ $ isIdentity z ⟩
x ∙ (z ∙ y) ∎
}
problem₃ : ⦃ _ : HasQuixoticBird ⦄ ⦃ _ : HasIdentity ⦄ → HasThrush
problem₃ = record
{ T = Q₁ ∙ I
; isThrush = λ x y → begin
Q₁ ∙ I ∙ x ∙ y ≈⟨ isQuixoticBird I x y ⟩
I ∙ (y ∙ x) ≈⟨ isIdentity $ y ∙ x ⟩
y ∙ x ∎
}
problem₄ : ⦃ _ : HasJaybird ⦄ ⦃ _ : HasThrush ⦄ → HasRobin
problem₄ = record
{ R = J ∙ T
; isRobin = λ x y z → begin
J ∙ T ∙ x ∙ y ∙ z ≈⟨ isJaybird T x y z ⟩
T ∙ x ∙ (T ∙ z ∙ y) ≈⟨ isThrush x $ T ∙ z ∙ y ⟩
T ∙ z ∙ y ∙ x ≈⟨ congʳ $ isThrush z y ⟩
y ∙ z ∙ x ∎
}
problem₅-C* : ⦃ _ : HasCardinal ⦄ ⦃ _ : HasQuixoticBird ⦄ → HasCardinalOnceRemoved
problem₅-C* = record
{ C* = C ∙ (Q₁ ∙ C)
; isCardinalOnceRemoved = λ x y z w → begin
C ∙ (Q₁ ∙ C) ∙ x ∙ y ∙ z ∙ w ≈⟨ congʳ $ congʳ $ isCardinal (Q₁ ∙ C) x y ⟩
Q₁ ∙ C ∙ y ∙ x ∙ z ∙ w ≈⟨ congʳ $ congʳ $ isQuixoticBird C y x ⟩
C ∙ (x ∙ y) ∙ z ∙ w ≈⟨ isCardinal (x ∙ y) z w ⟩
x ∙ y ∙ w ∙ z ∎
}
problem₅ : ⦃ _ : HasRobin ⦄ ⦃ _ : HasQuixoticBird ⦄ → HasBluebird
problem₅ = record
{ B = C* ∙ Q₁
; isBluebird = λ x y z → begin
C* ∙ Q₁ ∙ x ∙ y ∙ z ≈⟨ isCardinalOnceRemoved Q₁ x y z ⟩
Q₁ ∙ x ∙ z ∙ y ≈⟨ isQuixoticBird x z y ⟩
x ∙ (y ∙ z) ∎
} where
instance
hasCardinal = Chapter₁₁.problem₂₁
hasCardinalOnceRemoved = problem₅-C*
problem₆ : ⦃ _ : HasJaybird ⦄ ⦃ _ : HasBluebird ⦄ ⦃ _ : HasThrush ⦄
→ ∃[ J₁ ] (∀ x y z w → J₁ ∙ x ∙ y ∙ z ∙ w ≈ y ∙ x ∙ (w ∙ x ∙ z))
problem₆ =
( B ∙ J ∙ T
, λ x y z w → begin
B ∙ J ∙ T ∙ x ∙ y ∙ z ∙ w ≈⟨ (congʳ $ congʳ $ congʳ $ isBluebird J T x) ⟩
J ∙ (T ∙ x) ∙ y ∙ z ∙ w ≈⟨ isJaybird (T ∙ x) y z w ⟩
T ∙ x ∙ y ∙ (T ∙ x ∙ w ∙ z) ≈⟨ congʳ $ isThrush x y ⟩
y ∙ x ∙ (T ∙ x ∙ w ∙ z) ≈⟨ congˡ $ congʳ $ isThrush x w ⟩
y ∙ x ∙ (w ∙ x ∙ z) ∎
)
problem₇ : ⦃ _ : HasCardinal ⦄ ⦃ _ : HasThrush ⦄
→ ∃[ J₁ ] (∀ x y z w → J₁ ∙ x ∙ y ∙ z ∙ w ≈ y ∙ x ∙ (w ∙ x ∙ z))
→ HasMockingbird
problem₇ (J₁ , isJ₁) = record
{ M = C ∙ (C ∙ (C ∙ J₁ ∙ T) ∙ T) ∙ T
; isMockingbird = λ x → begin
C ∙ (C ∙ (C ∙ J₁ ∙ T) ∙ T) ∙ T ∙ x ≈⟨ isCardinal _ T x ⟩
C ∙ (C ∙ J₁ ∙ T) ∙ T ∙ x ∙ T ≈⟨ congʳ $ isCardinal _ T x ⟩
C ∙ J₁ ∙ T ∙ x ∙ T ∙ T ≈⟨ congʳ $ congʳ $ isCardinal J₁ T x ⟩
J₁ ∙ x ∙ T ∙ T ∙ T ≈⟨ isJ₁ x T T T ⟩
T ∙ x ∙ (T ∙ x ∙ T) ≈⟨ isThrush x (T ∙ x ∙ T) ⟩
T ∙ x ∙ T ∙ x ≈⟨ congʳ $ isThrush x T ⟩
T ∙ x ∙ x ≈⟨ isThrush x x ⟩
x ∙ x ∎
}
module _ ⦃ _ : HasJaybird ⦄ ⦃ hasIdentity′ : HasIdentity ⦄ where
private
instance
hasQuixoticBird = problem₂
hasThrush : HasThrush
hasThrush = problem₃
private
instance
_ = hasThrush
hasRobin = problem₄
hasBluebird : HasBluebird
hasBluebird = problem₅
private
instance
_ = hasBluebird
hasCardinal = Chapter₁₁.problem₂₁′
hasMockingbird : HasMockingbird
hasMockingbird = problem₇ problem₆
hasIdentity : HasIdentity
hasIdentity = hasIdentity′
-- Equality of predicates.
infix 4 _≐_
_≐_ : ∀ {a ℓ} {A : Set a} (P Q : Pred A ℓ) → Set (a ⊔ ℓ)
P ≐ Q = P ⊆ Q × Q ⊆ P
module _ ⦃ _ : Extensional ⦄
⦃ _ : HasBluebird ⦄ ⦃ _ : HasMockingbird ⦄ ⦃ _ : HasThrush ⦄
⦃ _ : HasIdentity ⦄ ⦃ _ : HasJaybird ⦄ where
private
⟨B,M,T,I⟩ = ⟨ B ∷ M ∷ T ∷ I ∷ [] ⟩
⟨J,I⟩ = ⟨ J ∷ I ∷ [] ⟩
module _ where
private
instance
hasCardinal = Chapter₁₁.problem₂₁′
hasWarbler = Chapter₁₂.problem₇
b : B ∈ ⟨B,M,T,I⟩
b = [ here refl ]
m : M ∈ ⟨B,M,T,I⟩
m = [ there (here refl) ]
t : T ∈ ⟨B,M,T,I⟩
t = [ there (there (here refl)) ]
c : C ∈ ⟨B,M,T,I⟩
c = b ⟨∙⟩ b ⟨∙⟩ t ⟨∙⟩ (b ⟨∙⟩ b ⟨∙⟩ t) ⟨∙⟩ (b ⟨∙⟩ b ⟨∙⟩ t)
w : W ∈ ⟨B,M,T,I⟩
w = b ⟨∙⟩ (t ⟨∙⟩ (b ⟨∙⟩ m ⟨∙⟩ (b ⟨∙⟩ b ⟨∙⟩ t))) ⟨∙⟩ (b ⟨∙⟩ b ⟨∙⟩ t)
⟨J,I⟩⊆⟨B,M,T,I⟩ : ⟨J,I⟩ ⊆ ⟨B,M,T,I⟩
⟨J,I⟩⊆⟨B,M,T,I⟩ [ here x≈J ] = subst′
(trans x≈J $ ext′ $ ext′ $ ext′ $ ext′ $ trans
(isJaybird _ _ _ _)
(sym $ isJaybird ⦃ problem₁′ ⦄ _ _ _ _))
(b ⟨∙⟩ (b ⟨∙⟩ c) ⟨∙⟩ (w ⟨∙⟩ (b ⟨∙⟩ c ⟨∙⟩ (b ⟨∙⟩ (b ⟨∙⟩ b ⟨∙⟩ b)))))
⟨J,I⟩⊆⟨B,M,T,I⟩ [ there (here x≈I) ] = [ there (there (there (here x≈I))) ]
⟨J,I⟩⊆⟨B,M,T,I⟩ (x∈⟨J,I⟩ ⟨∙⟩ y∈⟨J,I⟩ ∣ xy≈z) = ⟨J,I⟩⊆⟨B,M,T,I⟩ x∈⟨J,I⟩ ⟨∙⟩ ⟨J,I⟩⊆⟨B,M,T,I⟩ y∈⟨J,I⟩ ∣ xy≈z
module _ where
private
instance
hasQuixoticBird = problem₂
hasRobin = problem₄
hasCardinal = Chapter₁₁.problem₂₁
hasCardinalOnceRemoved = problem₅-C*
j : J ∈ ⟨J,I⟩
j = [ here refl ]
i : I ∈ ⟨J,I⟩
i = [ there (here refl) ]
q₁ : Q₁ ∈ ⟨J,I⟩
q₁ = j ⟨∙⟩ i
t : T ∈ ⟨J,I⟩
t = subst′ (ext′ (ext′ (trans (isThrush _ _) (sym (isThrush ⦃ problem₃ ⦄ _ _))))) $
j ⟨∙⟩ i ⟨∙⟩ i
r : R ∈ ⟨J,I⟩
r = j ⟨∙⟩ t
c : C ∈ ⟨J,I⟩
c = r ⟨∙⟩ r ⟨∙⟩ r
c* : C* ∈ ⟨J,I⟩
c* = c ⟨∙⟩ (q₁ ⟨∙⟩ c)
b : B ∈ ⟨J,I⟩
b = subst′ (ext′ (ext′ (ext′ (trans (isBluebird _ _ _) (sym (isBluebird ⦃ problem₅ ⦄ _ _ _)))))) $
c* ⟨∙⟩ q₁
m : M ∈ ⟨J,I⟩
m = subst′ (ext′ (trans (isMockingbird _) (sym (isMockingbird ⦃ problem₇ problem₆ ⦄ _)))) $
c ⟨∙⟩ (c ⟨∙⟩ (c ⟨∙⟩ (b ⟨∙⟩ j ⟨∙⟩ t) ⟨∙⟩ t) ⟨∙⟩ t) ⟨∙⟩ t
⟨J,I⟩⊇⟨B,M,T,I⟩ : ⟨J,I⟩ ⊇ ⟨B,M,T,I⟩
⟨J,I⟩⊇⟨B,M,T,I⟩ [ here x≈B ] = subst′ x≈B b
⟨J,I⟩⊇⟨B,M,T,I⟩ [ there (here x≈M) ] = subst′ x≈M m
⟨J,I⟩⊇⟨B,M,T,I⟩ [ there (there (here x≈T)) ] = subst′ x≈T t
⟨J,I⟩⊇⟨B,M,T,I⟩ [ there (there (there (here x≈I))) ] = [ there (here x≈I) ]
⟨J,I⟩⊇⟨B,M,T,I⟩ (x∈⟨B,M,T,I⟩ ⟨∙⟩ y∈⟨B,M,T,I⟩ ∣ xy≈z) = ⟨J,I⟩⊇⟨B,M,T,I⟩ x∈⟨B,M,T,I⟩ ⟨∙⟩ ⟨J,I⟩⊇⟨B,M,T,I⟩ y∈⟨B,M,T,I⟩ ∣ xy≈z
⟨J,I⟩≐⟨B,M,T,I⟩ : ⟨ J ∷ I ∷ [] ⟩ ≐ ⟨ B ∷ M ∷ T ∷ I ∷ [] ⟩
⟨J,I⟩≐⟨B,M,T,I⟩ = (⟨J,I⟩⊆⟨B,M,T,I⟩ , ⟨J,I⟩⊇⟨B,M,T,I⟩)
| {
"alphanum_fraction": 0.4772894672,
"avg_line_length": 33.5226337449,
"ext": "agda",
"hexsha": "cc4013bfc2885663eb664d40624408c4680d66ae",
"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": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "splintah/combinatory-logic",
"max_forks_repo_path": "Mockingbird/Problems/Chapter19.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"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": "splintah/combinatory-logic",
"max_issues_repo_path": "Mockingbird/Problems/Chapter19.agda",
"max_line_length": 125,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "splintah/combinatory-logic",
"max_stars_repo_path": "Mockingbird/Problems/Chapter19.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-28T23:44:42.000Z",
"num_tokens": 3933,
"size": 8146
} |
{-
Define finitely generated ideals of commutative rings and
show that they are an ideal.
Parts of this should be reusable for explicit constructions
of free modules over a finite set.
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRing.FGIdeal where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Data.Vec
open import Cubical.Data.Nat using (ℕ)
open import Cubical.HITs.PropositionalTruncation hiding (map)
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Ideal
open import Cubical.Algebra.Ring.QuotientRing
open import Cubical.Algebra.Ring.Properties
open import Cubical.Algebra.RingSolver.ReflectionSolving
private
variable
ℓ : Level
module _ (Ring@(R , str) : CommRing ℓ) (r : R) where
infixr 5 _holds
_holds : hProp ℓ → Type ℓ
P holds = fst P
open CommRingStr str
open RingTheory (CommRing→Ring Ring)
linearCombination : {n : ℕ} → Vec R n → Vec R n → R
linearCombination [] [] = 0r
linearCombination (c ∷ coefficients) (x ∷ l) = c · x + linearCombination coefficients l
coefficientSum : {n : ℕ} → Vec R n → Vec R n → Vec R n
coefficientSum [] [] = []
coefficientSum (x ∷ c) (y ∷ c′) = x + y ∷ coefficientSum c c′
sumDist+ : (n : ℕ) (c c′ l : Vec R n)
→ linearCombination (coefficientSum c c′) l
≡ linearCombination c l + linearCombination c′ l
sumDist+ ℕ.zero [] [] [] = solve Ring
sumDist+ (ℕ.suc n) (x ∷ c) (y ∷ c′) (a ∷ l) =
linearCombination (coefficientSum (x ∷ c) (y ∷ c′)) (a ∷ l) ≡⟨ refl ⟩
(x + y) · a + linearCombination (coefficientSum c c′) l ≡⟨ step1 ⟩
(x + y) · a + (linearCombination c l + linearCombination c′ l) ≡⟨ step2 ⟩
(x · a + linearCombination c l) + (y · a + linearCombination c′ l) ≡⟨ refl ⟩
linearCombination (x ∷ c) (a ∷ l) + linearCombination (y ∷ c′) (a ∷ l) ∎
where
step1 = cong (λ z → (x + y) · a + z) (sumDist+ n c c′ l)
autoSolve : (x y a t1 t2 : R)
→ (x + y) · a + (t1 + t2) ≡ (x · a + t1) + (y · a + t2)
autoSolve = solve Ring
step2 = autoSolve x y a _ _
dist- : (n : ℕ) (c l : Vec R n)
→ linearCombination (map -_ c) l
≡ - linearCombination c l
dist- ℕ.zero [] [] = solve Ring
dist- (ℕ.suc n) (x ∷ c) (a ∷ l) =
- x · a + linearCombination (map -_ c) l ≡[ i ]⟨ - x · a + dist- n c l i ⟩
- x · a - linearCombination c l ≡⟨ step1 x a _ ⟩
- (x · a + linearCombination c l) ∎
where step1 : (x a t1 : R) → - x · a - t1 ≡ - (x · a + t1)
step1 = solve Ring
dist0 : (n : ℕ) (l : Vec R n)
→ linearCombination (replicate 0r) l ≡ 0r
dist0 ℕ.zero [] = refl
dist0 (ℕ.suc n) (a ∷ l) =
0r · a + linearCombination (replicate 0r) l ≡[ i ]⟨ 0r · a + dist0 n l i ⟩
0r · a + 0r ≡⟨ step1 a ⟩
0r ∎
where step1 : (a : R) → 0r · a + 0r ≡ 0r
step1 = solve Ring
isLinearCombination : {n : ℕ} → Vec R n → R → Type ℓ
isLinearCombination l x =
∥ Σ[ coefficients ∈ Vec R _ ] x ≡ linearCombination coefficients l ∥
{- If x and y are linear combinations of l, then (x + y) is
a linear combination. -}
isLinearCombination+ : {n : ℕ} {x y : R} → (l : Vec R n)
→ isLinearCombination l x
→ isLinearCombination l y
→ isLinearCombination l (x + y)
isLinearCombination+ l =
elim (λ _ → isOfHLevelΠ 1 (λ _ → isPropPropTrunc))
(λ {(cx , px) → elim (λ _ → isPropPropTrunc)
λ {(cy , py) →
∣ coefficientSum cx cy ,
(_ + _ ≡[ i ]⟨ px i + py i ⟩
linearCombination cx l + linearCombination cy l ≡⟨ sym (sumDist+ _ cx cy l) ⟩
linearCombination (coefficientSum cx cy) l ∎) ∣}})
{- If x is a linear combinations of l, then -x is
a linear combination. -}
isLinearCombination- : {n : ℕ} {x y : R} (l : Vec R n)
→ isLinearCombination l x
→ isLinearCombination l (- x)
isLinearCombination- l =
elim (λ _ → isPropPropTrunc)
λ {(cx , px) → ∣ map -_ cx ,
( - _ ≡⟨ cong -_ px ⟩
- linearCombination cx l ≡⟨ sym (dist- _ cx l) ⟩
linearCombination (map -_ cx) l ∎) ∣}
{- 0r is the trivial linear Combination -}
isLinearCombination0 : {n : ℕ} (l : Vec R n)
→ isLinearCombination l 0r
isLinearCombination0 l = ∣ replicate 0r , sym (dist0 _ l) ∣
{- Linear combinations are stable under left multiplication -}
isLinearCombinationL· : {n : ℕ} (l : Vec R n)
→ (r x : R)
→ isLinearCombination l x
→ isLinearCombination l (r · x)
isLinearCombinationL· l r x =
elim (λ _ → isPropPropTrunc)
λ {(cx , px) →
∣ map (r ·_) cx ,
(r · _ ≡[ i ]⟨ r · px i ⟩
r · linearCombination cx l ≡⟨ step1 _ cx l r ⟩
linearCombination (map (r ·_) cx) l ∎) ∣}
where
step2 : (r c a t1 : R) → r · (c · a + t1) ≡ r · (c · a) + r · t1
step2 = solve Ring
step3 : (r c a t1 : R) → r · (c · a) + t1 ≡ r · c · a + t1
step3 = solve Ring
step1 : (k : ℕ) (cx l : Vec R k)
→ (r : R)
→ r · linearCombination cx l ≡ linearCombination (map (r ·_) cx) l
step1 ℕ.zero [] [] r = 0RightAnnihilates _
step1 (ℕ.suc k) (c ∷ cx) (a ∷ l) r =
r · (c · a + linearCombination cx l) ≡⟨ step2 r c a _ ⟩
r · (c · a) + r · linearCombination cx l ≡[ i ]⟨ r · (c · a) + step1 _ cx l r i ⟩
r · (c · a) + linearCombination (map (_·_ r) cx) l ≡⟨ step3 r c a _ ⟩
r · c · a + linearCombination (map (_·_ r) cx) l ∎
generatedIdeal : {n : ℕ} → Vec R n → IdealsIn Ring
generatedIdeal l = makeIdeal Ring
(λ x → isLinearCombination l x , isPropPropTrunc)
(isLinearCombination+ l)
(isLinearCombination0 l)
λ r → isLinearCombinationL· l r _
| {
"alphanum_fraction": 0.5184954927,
"avg_line_length": 42.3289473684,
"ext": "agda",
"hexsha": "9e3467d1226f3b7bbfd652e7cd6bac5a1fb54537",
"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": "f2d74ae8e2e176963029a35bd886364480948214",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "kl-i/cubical-0.3",
"max_forks_repo_path": "Cubical/Algebra/CommRing/FGIdeal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f2d74ae8e2e176963029a35bd886364480948214",
"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": "kl-i/cubical-0.3",
"max_issues_repo_path": "Cubical/Algebra/CommRing/FGIdeal.agda",
"max_line_length": 99,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f2d74ae8e2e176963029a35bd886364480948214",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "kl-i/cubical-0.3",
"max_stars_repo_path": "Cubical/Algebra/CommRing/FGIdeal.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2160,
"size": 6434
} |
module Luau.Var where
open import Agda.Builtin.Bool using (true; false)
open import Agda.Builtin.Equality using (_≡_)
open import Agda.Builtin.String using (String; primStringEquality)
open import Agda.Builtin.TrustMe using (primTrustMe)
open import Properties.Dec using (Dec; yes; no)
open import Properties.Equality using (_≢_)
Var : Set
Var = String
_≡ⱽ_ : (a b : Var) → Dec (a ≡ b)
a ≡ⱽ b with primStringEquality a b
a ≡ⱽ b | false = no p where postulate p : (a ≢ b)
a ≡ⱽ b | true = yes primTrustMe
| {
"alphanum_fraction": 0.7272727273,
"avg_line_length": 29.7647058824,
"ext": "agda",
"hexsha": "23d8b56e3ca7c3dfcf0f2e9ce668e2386f54d46b",
"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": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "XanderYZZ/luau",
"max_forks_repo_path": "prototyping/Luau/Var.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"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": "XanderYZZ/luau",
"max_issues_repo_path": "prototyping/Luau/Var.agda",
"max_line_length": 66,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "TheGreatSageEqualToHeaven/luau",
"max_stars_repo_path": "prototyping/Luau/Var.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-05T21:53:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-12-05T21:53:03.000Z",
"num_tokens": 167,
"size": 506
} |
------------------------------------------------------------------------------
-- Testing the translation of the propositional functions
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module PropositionalFunction1 where
------------------------------------------------------------------------------
postulate
D : Set
A : D → Set
a : D
-- In this case, the propositional function does not use logical
-- constants.
postulate foo : A a → A a
{-# ATP prove foo #-}
| {
"alphanum_fraction": 0.3941176471,
"avg_line_length": 29.5652173913,
"ext": "agda",
"hexsha": "b402e4e063ee85bb68dacd6d2bc8211cc6692d33",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Succeed/fol-theorems/PropositionalFunction1.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Succeed/fol-theorems/PropositionalFunction1.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Succeed/fol-theorems/PropositionalFunction1.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 110,
"size": 680
} |
open import Prelude
module Implicits.Semantics.Term where
open import Implicits.Syntax
open import Implicits.WellTyped
open import Implicits.Semantics.Type
open import Implicits.Semantics.Context
open import Implicits.Semantics.Lemmas
open import Implicits.Semantics.RewriteContext
open import SystemF.Everything as F using ()
module TermSemantics
(_⊢ᵣ_ : ∀ {ν} → ICtx ν → Type ν → Set)
(⟦_,_⟧r : ∀ {ν n} {K : Ktx ν n} {a} → (proj₂ K) ⊢ᵣ a → K# K →
∃ λ t → ⟦ proj₁ K ⟧ctx→ F.⊢ t ∈ ⟦ a ⟧tp→) where
open TypingRules _⊢ᵣ_
-- denotational semantics of well-typed terms
⟦_,_⟧ : ∀ {ν n} {K : Ktx ν n} {t} {a : Type ν} → K ⊢ t ∈ a → K# K → F.Term ν n
⟦_,_⟧ (var x) m = F.var x
⟦_,_⟧ (Λ t) m = F.Λ ⟦ t , #tvar m ⟧
⟦_,_⟧ (λ' a x) m = F.λ' ⟦ a ⟧tp→ ⟦ x , #var a m ⟧
⟦_,_⟧ (f [ b ]) m = F._[_] ⟦ f , m ⟧ ⟦ b ⟧tp→
⟦_,_⟧ (f · e) m = ⟦ f , m ⟧ F.· ⟦ e , m ⟧
⟦_,_⟧ (ρ {a = a} _ x) m = F.λ' ⟦ a ⟧tp→ ⟦ x , #ivar a m ⟧
⟦_,_⟧ (f ⟨ e∈Δ ⟩) m = ⟦ f , m ⟧ F.· (proj₁ ⟦ e∈Δ , m ⟧r)
⟦_,_⟧ (_with'_ r e) m = ⟦ r , m ⟧ F.· ⟦ e , m ⟧
| {
"alphanum_fraction": 0.5361904762,
"avg_line_length": 35,
"ext": "agda",
"hexsha": "e766865fa6f23ca3661bfcfec5115e2ded9ae306",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Semantics/Term.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Semantics/Term.agda",
"max_line_length": 80,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Semantics/Term.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 531,
"size": 1050
} |
open import Agda.Builtin.String
open import Agda.Builtin.Equality
_ : primShowChar 'c' ≡ "'c'"
_ = refl
_ : primShowString "ccc" ≡ "\"ccc\""
_ = refl
| {
"alphanum_fraction": 0.6666666667,
"avg_line_length": 15.3,
"ext": "agda",
"hexsha": "ae4684df40e508e8b9a11b4f85c5fb546fd24f07",
"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/Issue3830.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/Issue3830.agda",
"max_line_length": 36,
"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/Issue3830.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": 52,
"size": 153
} |
module GGT.Bundles where
open import Level
open import Relation.Unary
open import Relation.Binary -- using (Rel)
open import Algebra.Core
open import Algebra.Bundles
open import GGT.Structures
open import Data.Product
-- do we need a left action definition?
-- parametrize over Op r/l?
record Action a b ℓ₁ ℓ₂ : Set (suc (a ⊔ b ⊔ ℓ₁ ⊔ ℓ₂)) where
infixl 6 _·_
infix 3 _≋_
open Group hiding (setoid)
field
G : Group a ℓ₁
Ω : Set b
_≋_ : Rel Ω ℓ₂
_·_ : Opᵣ (Carrier G) Ω
isAction : IsAction (_≈_ G) _≋_ _·_ (_∙_ G) (ε G) (_⁻¹ G)
open IsAction isAction public
-- the (raw) pointwise stabilizer
stab : Ω → Pred (Carrier G) ℓ₂
stab o = λ (g : Carrier G) → o · g ≋ o
-- Orbital relation
_ω_ : Rel Ω (a ⊔ ℓ₂)
o ω o' = ∃[ g ] (o · g ≋ o')
_·G : Ω → Pred Ω (a ⊔ ℓ₂)
o ·G = o ω_
-- Orbits
open import GGT.Setoid setoid (a ⊔ ℓ₂)
Orbit : Ω → Setoid (b ⊔ (a ⊔ ℓ₂)) ℓ₂
Orbit o = subSetoid (o ·G)
| {
"alphanum_fraction": 0.6122881356,
"avg_line_length": 23.0243902439,
"ext": "agda",
"hexsha": "eefc85226d1c645c106702f105e59817a795a19e",
"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": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "zampino/ggt",
"max_forks_repo_path": "src/ggt/Bundles.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"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": "zampino/ggt",
"max_issues_repo_path": "src/ggt/Bundles.agda",
"max_line_length": 61,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "zampino/ggt",
"max_stars_repo_path": "src/ggt/Bundles.agda",
"max_stars_repo_stars_event_max_datetime": "2020-11-28T05:48:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-17T11:10:00.000Z",
"num_tokens": 389,
"size": 944
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Support for reflection
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Reflection where
import Agda.Builtin.Reflection as Builtin
------------------------------------------------------------------------
-- Names, Metas, and Literals re-exported publicly
open import Reflection.Abstraction as Abstraction public
using (Abs; abs)
open import Reflection.Argument as Argument public
using (Arg; arg; Args; vArg; hArg; iArg)
open import Reflection.Definition as Definition public
using (Definition)
open import Reflection.Meta as Meta public
using (Meta)
open import Reflection.Name as Name public
using (Name; Names)
open import Reflection.Literal as Literal public
using (Literal)
open import Reflection.Pattern as Pattern public
using (Pattern)
open import Reflection.Term as Term public
using (Term; Type; Clause; Clauses; Sort)
import Reflection.Argument.Relevance as Relevance
import Reflection.Argument.Visibility as Visibility
import Reflection.Argument.Information as Information
open Definition.Definition public
open Information.ArgInfo public
open Literal.Literal public
open Relevance.Relevance public
open Term.Term public
open Visibility.Visibility public
------------------------------------------------------------------------
-- Fixity
open Builtin public
using (non-assoc; related; unrelated; fixity)
renaming
( left-assoc to assocˡ
; right-assoc to assocʳ
; primQNameFixity to getFixity
)
------------------------------------------------------------------------
-- Type checking monad
-- Type errors
open Builtin public using (ErrorPart; strErr; termErr; nameErr)
-- The monad
open Builtin public
using ( TC; bindTC; unify; typeError; inferType; checkType
; normalise; reduce
; catchTC; quoteTC; unquoteTC
; getContext; extendContext; inContext; freshName
; declareDef; declarePostulate; defineFun; getType; getDefinition
; blockOnMeta; commitTC; isMacro; withNormalisation
; debugPrint; noConstraints; runSpeculative)
renaming (returnTC to return)
-- Standard monad operators
open import Reflection.TypeChecking.MonadSyntax public
using (_>>=_; _>>_)
newMeta : Type → TC Term
newMeta = checkType unknown
------------------------------------------------------------------------
-- Show
open import Reflection.Show public
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 1.1
returnTC = return
{-# WARNING_ON_USAGE returnTC
"Warning: returnTC was deprecated in v1.1.
Please use return instead."
#-}
-- Version 1.3
Arg-info = Information.ArgInfo
{-# WARNING_ON_USAGE Arg-info
"Warning: Arg-info was deprecated in v1.3.
Please use Reflection.Argument.Information's ArgInfo instead."
#-}
infix 4 _≟-Lit_ _≟-Name_ _≟-Meta_ _≟-Visibility_ _≟-Relevance_ _≟-Arg-info_
_≟-Pattern_ _≟-ArgPatterns_
_≟-Lit_ = Literal._≟_
{-# WARNING_ON_USAGE _≟-Lit_
"Warning: _≟-Lit_ was deprecated in v1.3.
Please use Reflection.Literal's _≟_ instead."
#-}
_≟-Name_ = Name._≟_
{-# WARNING_ON_USAGE _≟-Name_
"Warning: _≟-Name_ was deprecated in v1.3.
Please use Reflection.Name's _≟_ instead."
#-}
_≟-Meta_ = Meta._≟_
{-# WARNING_ON_USAGE _≟-Meta_
"Warning: _≟-Meta_ was deprecated in v1.3.
Please use Reflection.Meta's _≟_ instead."
#-}
_≟-Visibility_ = Visibility._≟_
{-# WARNING_ON_USAGE _≟-Visibility_
"Warning: _≟-Visibility_ was deprecated in v1.3.
Please use Reflection.Argument.Visibility's _≟_ instead."
#-}
_≟-Relevance_ = Relevance._≟_
{-# WARNING_ON_USAGE _≟-Relevance_
"Warning: _≟-Relevance_ was deprecated in v1.3.
Please use Reflection.Argument.Relevance's _≟_ instead."
#-}
_≟-Arg-info_ = Information._≟_
{-# WARNING_ON_USAGE _≟-Arg-info_
"Warning: _≟-Arg-info_ was deprecated in v1.3.
Please use Reflection.Argument.Information's _≟_ instead."
#-}
_≟-Pattern_ = Pattern._≟_
{-# WARNING_ON_USAGE _≟-Pattern_
"Warning: _≟-Pattern_ was deprecated in v1.3.
Please use Reflection.Pattern's _≟_ instead."
#-}
_≟-ArgPatterns_ = Pattern._≟s_
{-# WARNING_ON_USAGE _≟-ArgPatterns_
"Warning: _≟-ArgPatterns_ was deprecated in v1.3.
Please use Reflection.Pattern's _≟s_ instead."
#-}
map-Abs = Abstraction.map
{-# WARNING_ON_USAGE map-Abs
"Warning: map-Abs was deprecated in v1.3.
Please use Reflection.Abstraction's map instead."
#-}
map-Arg = Argument.map
{-# WARNING_ON_USAGE map-Arg
"Warning: map-Arg was deprecated in v1.3.
Please use Reflection.Argument's map instead."
#-}
map-Args = Argument.map-Args
{-# WARNING_ON_USAGE map-Args
"Warning: map-Args was deprecated in v1.3.
Please use Reflection.Argument's map-Args instead."
#-}
visibility = Information.visibility
{-# WARNING_ON_USAGE visibility
"Warning: visibility was deprecated in v1.3.
Please use Reflection.Argument.Information's visibility instead."
#-}
relevance = Information.relevance
{-# WARNING_ON_USAGE relevance
"Warning: relevance was deprecated in v1.3.
Please use Reflection.Argument.Information's relevance instead."
#-}
infix 4 _≟-AbsTerm_ _≟-AbsType_ _≟-ArgTerm_ _≟-ArgType_ _≟-Args_
_≟-Clause_ _≟-Clauses_ _≟_
_≟-Sort_
_≟-AbsTerm_ = Term._≟-AbsTerm_
{-# WARNING_ON_USAGE _≟-AbsTerm_
"Warning: _≟-AbsTerm_ was deprecated in v1.3.
Please use Reflection.Term's _≟-AbsTerm_ instead."
#-}
_≟-AbsType_ = Term._≟-AbsType_
{-# WARNING_ON_USAGE _≟-AbsType_
"Warning: _≟-AbsType_ was deprecated in v1.3.
Please use Reflection.Term's _≟-AbsType_ instead."
#-}
_≟-ArgTerm_ = Term._≟-ArgTerm_
{-# WARNING_ON_USAGE _≟-ArgTerm_
"Warning: _≟-ArgTerm_ was deprecated in v1.3.
Please use Reflection.Term's _≟-ArgTerm_ instead."
#-}
_≟-ArgType_ = Term._≟-ArgType_
{-# WARNING_ON_USAGE _≟-ArgType_
"Warning: _≟-ArgType_ was deprecated in v1.3.
Please use Reflection.Term's _≟-ArgType_ instead."
#-}
_≟-Args_ = Term._≟-Args_
{-# WARNING_ON_USAGE _≟-Args_
"Warning: _≟-Args_ was deprecated in v1.3.
Please use Reflection.Term's _≟-Args_ instead."
#-}
_≟-Clause_ = Term._≟-Clause_
{-# WARNING_ON_USAGE _≟-Clause_
"Warning: _≟-Clause_ was deprecated in v1.3.
Please use Reflection.Term's _≟-Clause_ instead."
#-}
_≟-Clauses_ = Term._≟-Clauses_
{-# WARNING_ON_USAGE _≟-Clauses_
"Warning: _≟-Clauses_ was deprecated in v1.3.
Please use Reflection.Term's _≟-Clauses_ instead."
#-}
_≟_ = Term._≟_
{-# WARNING_ON_USAGE _≟_
"Warning: _≟_ was deprecated in v1.3.
Please use Reflection.Term's _≟_ instead."
#-}
_≟-Sort_ = Term._≟-Sort_
{-# WARNING_ON_USAGE _≟-Sort_
"Warning: _≟-Sort_ was deprecated in v1.3.
Please use Reflection.Term's _≟-Sort_ instead."
#-}
| {
"alphanum_fraction": 0.6756363636,
"avg_line_length": 27.8340080972,
"ext": "agda",
"hexsha": "12edc19b9a3b4ebdf84606d66810806116989f5d",
"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/Reflection.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/Reflection.agda",
"max_line_length": 75,
"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/Reflection.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": 1912,
"size": 6875
} |
{-# OPTIONS --without-K --safe #-}
open import Algebra
module Data.FingerTree.Structures
{r m}
(ℳ : Monoid r m)
where
open import Level using (_⊔_)
open import Data.Product
open import Relation.Unary
open import Data.FingerTree.Measures ℳ
open import Data.FingerTree.Reasoning ℳ
open Monoid ℳ renaming (Carrier to 𝓡)
open σ ⦃ ... ⦄
{-# DISPLAY σ.μ _ = μ #-}
data Digit {a} (Σ : Set a) : Set a where
D₁ : Σ → Digit Σ
D₂ : Σ → Σ → Digit Σ
D₃ : Σ → Σ → Σ → Digit Σ
D₄ : Σ → Σ → Σ → Σ → Digit Σ
instance
σ-Digit : ∀ {a} {Σ : Set a} → ⦃ _ : σ Σ ⦄ → σ (Digit Σ)
μ ⦃ σ-Digit ⦄ (D₁ x₁) = μ x₁
μ ⦃ σ-Digit ⦄ (D₂ x₁ x₂) = μ x₁ ∙ μ x₂
μ ⦃ σ-Digit ⦄ (D₃ x₁ x₂ x₃) = μ x₁ ∙ (μ x₂ ∙ μ x₃)
μ ⦃ σ-Digit ⦄ (D₄ x₁ x₂ x₃ x₄) = μ x₁ ∙ (μ x₂ ∙ (μ x₃ ∙ μ x₄))
data Node {a} (Σ : Set a) : Set a where
N₂ : Σ → Σ → Node Σ
N₃ : Σ → Σ → Σ → Node Σ
instance
σ-Node : ∀ {a} {Σ : Set a} → ⦃ _ : σ Σ ⦄ → σ (Node Σ)
μ ⦃ σ-Node ⦄ (N₂ x₁ x₂) = μ x₁ ∙ μ x₂
μ ⦃ σ-Node ⦄ (N₃ x₁ x₂ x₃) = μ x₁ ∙ (μ x₂ ∙ μ x₃)
mutual
infixr 5 _&_&_
record Deep {a} (Σ : Set a) ⦃ _ : σ Σ ⦄ : Set (r ⊔ a ⊔ m) where
constructor _&_&_
inductive
field
lbuff : Digit Σ
tree : Tree ⟪ Node Σ ⟫
rbuff : Digit Σ
data Tree {a} (Σ : Set a) ⦃ _ : σ Σ ⦄ : Set (r ⊔ a ⊔ m) where
empty : Tree Σ
single : Σ → Tree Σ
deep : ⟪ Deep Σ ⟫ → Tree Σ
μ-deep : ∀ {a} {Σ : Set a} ⦃ _ : σ Σ ⦄ → Deep Σ → 𝓡
μ-deep (l & x & r) = μ l ∙ (μ-tree x ∙ μ r)
μ-tree : ∀ {a} {Σ : Set a} ⦃ _ : σ Σ ⦄ → Tree Σ → 𝓡
μ-tree empty = ε
μ-tree (single x) = μ x
μ-tree (deep xs) = xs .𝔐
instance
σ-Deep : ∀ {a} {Σ : Set a} → ⦃ _ : σ Σ ⦄ → σ (Deep Σ)
μ ⦃ σ-Deep ⦄ = μ-deep
instance
σ-Tree : ∀ {a} {Σ : Set a} → ⦃ _ : σ Σ ⦄ → σ (Tree Σ)
μ ⦃ σ-Tree ⦄ = μ-tree
open Deep
{-# DISPLAY μ-tree _ x = μ x #-}
{-# DISPLAY μ-deep _ x = μ x #-}
nodeToDigit : ∀ {a} {Σ : Set a} ⦃ _ : σ Σ ⦄ → (xs : Node Σ) → μ⟨ Digit Σ ⟩≈ μ xs
nodeToDigit (N₂ x₁ x₂) = D₂ x₁ x₂ ⇑[ refl ]
nodeToDigit (N₃ x₁ x₂ x₃) = D₃ x₁ x₂ x₃ ⇑[ refl ]
digitToTree : ∀ {a} {Σ : Set a} ⦃ _ : σ Σ ⦄ → (xs : Digit Σ) → μ⟨ Tree Σ ⟩≈ μ xs
digitToTree (D₁ x₁) = single x₁ ⇑[ refl ]
digitToTree (D₂ x₁ x₂) = deep ⟪ D₁ x₁ & empty & D₁ x₂ ⇓⟫ ⇑[ μ x₁ ∙ (ε ∙ μ x₂) ↢ ℳ ↯ ]
digitToTree (D₃ x₁ x₂ x₃) = deep ⟪ D₂ x₁ x₂ & empty & D₁ x₃ ⇓⟫ ⇑[ μ (D₂ x₁ x₂) ∙ (ε ∙ μ x₃) ↢ ℳ ↯ ]
digitToTree (D₄ x₁ x₂ x₃ x₄) = deep ⟪ D₂ x₁ x₂ & empty & D₂ x₃ x₄ ⇓⟫ ⇑[ μ (D₂ x₁ x₂) ∙ (ε ∙ μ (D₂ x₃ x₄)) ↢ ℳ ↯ ]
open import Data.List using (List; _∷_; [])
nodeToList : ∀ {a} {Σ : Set a} ⦃ _ : σ Σ ⦄ → (xs : Node Σ) → μ⟨ List Σ ⟩≈ (μ xs)
nodeToList (N₂ x₁ x₂) = x₁ ∷ x₂ ∷ [] ⇑[ ℳ ↯ ]
nodeToList (N₃ x₁ x₂ x₃) = x₁ ∷ x₂ ∷ x₃ ∷ [] ⇑[ ℳ ↯ ]
digitToList : ∀ {a} {Σ : Set a} ⦃ _ : σ Σ ⦄ → (xs : Digit Σ) → μ⟨ List Σ ⟩≈ (μ xs)
digitToList (D₁ x₁) = x₁ ∷ [] ⇑[ ℳ ↯ ]
digitToList (D₂ x₁ x₂) = x₁ ∷ x₂ ∷ [] ⇑[ ℳ ↯ ]
digitToList (D₃ x₁ x₂ x₃) = x₁ ∷ x₂ ∷ x₃ ∷ [] ⇑[ ℳ ↯ ]
digitToList (D₄ x₁ x₂ x₃ x₄) = x₁ ∷ x₂ ∷ x₃ ∷ x₄ ∷ [] ⇑[ ℳ ↯ ]
| {
"alphanum_fraction": 0.5010067114,
"avg_line_length": 30.101010101,
"ext": "agda",
"hexsha": "5dac794248357f41bec92861fffe49e7edc01665",
"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": "39c3d96937384b052b782ffddf4fdec68c5d139f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-indexed-fingertree",
"max_forks_repo_path": "src/Data/FingerTree/Structures.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "39c3d96937384b052b782ffddf4fdec68c5d139f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-indexed-fingertree",
"max_issues_repo_path": "src/Data/FingerTree/Structures.agda",
"max_line_length": 113,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "39c3d96937384b052b782ffddf4fdec68c5d139f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-indexed-fingertree",
"max_stars_repo_path": "src/Data/FingerTree/Structures.agda",
"max_stars_repo_stars_event_max_datetime": "2019-02-26T07:04:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-02-26T07:04:54.000Z",
"num_tokens": 1621,
"size": 2980
} |
postulate
foo = Foo
-- Error message is:
-- A postulate block can only contain type signatures or instance blocks
| {
"alphanum_fraction": 0.7521367521,
"avg_line_length": 19.5,
"ext": "agda",
"hexsha": "fb17361c4890910cba9fd316a6f2069da1e05c08",
"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/Issue1698-postulate.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/Issue1698-postulate.agda",
"max_line_length": 72,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue1698-postulate.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": 27,
"size": 117
} |
module Haskell.Prim.Monoid where
open import Agda.Builtin.Unit
open import Haskell.Prim
open import Haskell.Prim.Bool
open import Haskell.Prim.List
open import Haskell.Prim.Maybe
open import Haskell.Prim.Either
open import Haskell.Prim.Tuple
--------------------------------------------------
-- Semigroup
record Semigroup (a : Set) : Set where
infixr 6 _<>_
field
_<>_ : a → a → a
open Semigroup ⦃ ... ⦄ public
instance
iSemigroupList : Semigroup (List a)
iSemigroupList ._<>_ = _++_
iSemigroupMaybe : ⦃ Semigroup a ⦄ → Semigroup (Maybe a)
iSemigroupMaybe ._<>_ Nothing m = m
iSemigroupMaybe ._<>_ m Nothing = m
iSemigroupMaybe ._<>_ (Just x) (Just y) = Just (x <> y)
iSemigroupEither : Semigroup (Either a b)
iSemigroupEither ._<>_ (Left _) e = e
iSemigroupEither ._<>_ e _ = e
iSemigroupFun : ⦃ Semigroup b ⦄ → Semigroup (a → b)
iSemigroupFun ._<>_ f g x = f x <> g x
iSemigroupUnit : Semigroup ⊤
iSemigroupUnit ._<>_ _ _ = tt
iSemigroupTuple₀ : Semigroup (Tuple [])
iSemigroupTuple₀ ._<>_ _ _ = []
iSemigroupTuple : ∀ {as} → ⦃ Semigroup a ⦄ → ⦃ Semigroup (Tuple as) ⦄ → Semigroup (Tuple (a ∷ as))
iSemigroupTuple ._<>_ (x ∷ xs) (y ∷ ys) = x <> y ∷ xs <> ys
--------------------------------------------------
-- Monoid
record Monoid (a : Set) : Set where
field
mempty : a
overlap ⦃ super ⦄ : Semigroup a
mappend : a → a → a
mappend = _<>_
mconcat : List a → a
mconcat [] = mempty
mconcat (x ∷ xs) = x <> mconcat xs
open Monoid ⦃ ... ⦄ public
instance
iMonoidList : Monoid (List a)
iMonoidList .mempty = []
iMonoidMaybe : ⦃ Semigroup a ⦄ → Monoid (Maybe a)
iMonoidMaybe .mempty = Nothing
iMonoidFun : ⦃ Monoid b ⦄ → Monoid (a → b)
iMonoidFun .mempty _ = mempty
iMonoidUnit : Monoid ⊤
iMonoidUnit .mempty = tt
iMonoidTuple₀ : Monoid (Tuple [])
iMonoidTuple₀ .mempty = []
iMonoidTuple : ∀ {as} → ⦃ Monoid a ⦄ → ⦃ Monoid (Tuple as) ⦄ → Monoid (Tuple (a ∷ as))
iMonoidTuple .mempty = mempty ∷ mempty
MonoidEndo : Monoid (a → a)
MonoidEndo .mempty = id
MonoidEndo .super ._<>_ = _∘_
MonoidEndoᵒᵖ : Monoid (a → a)
MonoidEndoᵒᵖ .mempty = id
MonoidEndoᵒᵖ .super ._<>_ = flip _∘_
MonoidConj : Monoid Bool
MonoidConj .mempty = true
MonoidConj .super ._<>_ = _&&_
MonoidDisj : Monoid Bool
MonoidDisj .mempty = false
MonoidDisj .super ._<>_ = _||_
| {
"alphanum_fraction": 0.6103950104,
"avg_line_length": 24.05,
"ext": "agda",
"hexsha": "f29f527d256ff21296e033e95a3d427ced476f88",
"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": "4cb28f1b5032948b19b977b390fa260be292abf6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "flupe/agda2hs",
"max_forks_repo_path": "lib/Haskell/Prim/Monoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4cb28f1b5032948b19b977b390fa260be292abf6",
"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": "flupe/agda2hs",
"max_issues_repo_path": "lib/Haskell/Prim/Monoid.agda",
"max_line_length": 100,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4cb28f1b5032948b19b977b390fa260be292abf6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "flupe/agda2hs",
"max_stars_repo_path": "lib/Haskell/Prim/Monoid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 880,
"size": 2405
} |
module RewriteAndUniversePolymorphism where
open import Common.Equality
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
test : (a b : ℕ) → a ≡ b → b ≡ a
test a b eq rewrite eq = refl
| {
"alphanum_fraction": 0.652173913,
"avg_line_length": 15.3333333333,
"ext": "agda",
"hexsha": "2e8d4394528fe2f8b444bcada87190c56c2c8b16",
"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/RewriteAndUniversePolymorphism.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/RewriteAndUniversePolymorphism.agda",
"max_line_length": 43,
"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/RewriteAndUniversePolymorphism.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": 64,
"size": 184
} |
-- Basic intuitionistic logic of proofs, without ∨, ⊥, or +.
-- Gentzen-style formalisation of syntax with context pairs.
-- Simple terms.
module BasicILP.Syntax.DyadicGentzen where
open import BasicILP.Syntax.Common public
-- Types, or propositions.
-- [ Ψ ⁏ Ω ⊢ t ] A means t is a proof of the fact that the type A is inhabited given assumptions in the context Ψ and the modal context Ω.
mutual
syntax □ Π A t = [ Π ⊢ t ] A
infixr 10 □
infixl 9 _∧_
infixr 7 _▻_
data Ty : Set where
α_ : Atom → Ty
_▻_ : Ty → Ty → Ty
□ : (Π : Cx² Ty Box) → (A : Ty) → Π ⊢ A → Ty
_∧_ : Ty → Ty → Ty
⊤ : Ty
-- Context/modal context/type/term quadruples.
record Box : Set where
inductive
constructor □
field
Π : Cx² Ty Box
A : Ty
x : Π ⊢ A
-- Derivations.
-- NOTE: Only var is an instance constructor, which allows the instance argument for mvar to be automatically inferred, in many cases.
infix 3 _⊢_
data _⊢_ : Cx² Ty Box → Ty → Set where
instance
var : ∀ {A Γ Δ} → A ∈ Γ → Γ ⁏ Δ ⊢ A
lam : ∀ {A B Γ Δ} → Γ , A ⁏ Δ ⊢ B → Γ ⁏ Δ ⊢ A ▻ B
app : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ▻ B → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ B
mvar : ∀ {Ψ Ω A x Γ Δ} → [ Ψ ⁏ Ω ⊢ x ] A ∈ Δ
→ {{_ : Γ ⁏ Δ ⊢⋆ Ψ}}
→ {{_ : Γ ⁏ Δ ⊢⍟ Ω}}
→ Γ ⁏ Δ ⊢ A
box : ∀ {Ψ Ω A Γ Δ} → (x : Ψ ⁏ Ω ⊢ A)
→ Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω ⊢ x ] A
unbox : ∀ {Ψ Ω A C x Γ Δ} → Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω ⊢ x ] A
→ Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A ⊢ C
→ Γ ⁏ Δ ⊢ C
pair : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ B → Γ ⁏ Δ ⊢ A ∧ B
fst : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ∧ B → Γ ⁏ Δ ⊢ A
snd : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ∧ B → Γ ⁏ Δ ⊢ B
unit : ∀ {Γ Δ} → Γ ⁏ Δ ⊢ ⊤
infix 3 _⊢⋆_
data _⊢⋆_ : Cx² Ty Box → Cx Ty → Set where
instance
∙ : ∀ {Γ Δ} → Γ ⁏ Δ ⊢⋆ ∅
_,_ : ∀ {Ξ A Γ Δ} → Γ ⁏ Δ ⊢⋆ Ξ → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢⋆ Ξ , A
infix 3 _⊢⍟_
data _⊢⍟_ : Cx² Ty Box → Cx Box → Set where
instance
∙ : ∀ {Γ Δ} → Γ ⁏ Δ ⊢⍟ ∅
_,_ : ∀ {Ξ Ψ Ω A x Γ Δ} → Γ ⁏ Δ ⊢⍟ Ξ
→ Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω ⊢ x ] A
→ Γ ⁏ Δ ⊢⍟ Ξ , [ Ψ ⁏ Ω ⊢ x ] A
-- Monotonicity with respect to context inclusion.
mutual
mono⊢ : ∀ {A Γ Γ′ Δ} → Γ ⊆ Γ′ → Γ ⁏ Δ ⊢ A → Γ′ ⁏ Δ ⊢ A
mono⊢ η (var i) = var (mono∈ η i)
mono⊢ η (lam t) = lam (mono⊢ (keep η) t)
mono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u)
mono⊢ η (mvar i {{ts}} {{us}}) = mvar i {{mono⊢⋆ η ts}} {{mono⊢⍟ η us}}
mono⊢ η (box t) = box t
mono⊢ η (unbox t u) = unbox (mono⊢ η t) (mono⊢ η u)
mono⊢ η (pair t u) = pair (mono⊢ η t) (mono⊢ η u)
mono⊢ η (fst t) = fst (mono⊢ η t)
mono⊢ η (snd t) = snd (mono⊢ η t)
mono⊢ η unit = unit
mono⊢⋆ : ∀ {Ξ Γ Γ′ Δ} → Γ ⊆ Γ′ → Γ ⁏ Δ ⊢⋆ Ξ → Γ′ ⁏ Δ ⊢⋆ Ξ
mono⊢⋆ η ∙ = ∙
mono⊢⋆ η (ts , t) = mono⊢⋆ η ts , mono⊢ η t
mono⊢⍟ : ∀ {Ξ Γ Γ′ Δ} → Γ ⊆ Γ′ → Γ ⁏ Δ ⊢⍟ Ξ → Γ′ ⁏ Δ ⊢⍟ Ξ
mono⊢⍟ η ∙ = ∙
mono⊢⍟ η (ts , t) = mono⊢⍟ η ts , mono⊢ η t
-- Monotonicity with respect to modal context inclusion.
mutual
mmono⊢ : ∀ {A Γ Δ Δ′} → Δ ⊆ Δ′ → Γ ⁏ Δ ⊢ A → Γ ⁏ Δ′ ⊢ A
mmono⊢ θ (var i) = var i
mmono⊢ θ (lam t) = lam (mmono⊢ θ t)
mmono⊢ θ (app t u) = app (mmono⊢ θ t) (mmono⊢ θ u)
mmono⊢ θ (mvar i {{ts}} {{us}}) = mvar (mono∈ θ i) {{mmono⊢⋆ θ ts}} {{mmono⊢⍟ θ us}}
mmono⊢ θ (box t) = box t
mmono⊢ θ (unbox t u) = unbox (mmono⊢ θ t) (mmono⊢ (keep θ) u)
mmono⊢ θ (pair t u) = pair (mmono⊢ θ t) (mmono⊢ θ u)
mmono⊢ θ (fst t) = fst (mmono⊢ θ t)
mmono⊢ θ (snd t) = snd (mmono⊢ θ t)
mmono⊢ θ unit = unit
mmono⊢⋆ : ∀ {Ξ Γ Δ Δ′} → Δ ⊆ Δ′ → Γ ⁏ Δ ⊢⋆ Ξ → Γ ⁏ Δ′ ⊢⋆ Ξ
mmono⊢⋆ θ ∙ = ∙
mmono⊢⋆ θ (ts , t) = mmono⊢⋆ θ ts , mmono⊢ θ t
mmono⊢⍟ : ∀ {Ξ Γ Δ Δ′} → Δ ⊆ Δ′ → Γ ⁏ Δ ⊢⍟ Ξ → Γ ⁏ Δ′ ⊢⍟ Ξ
mmono⊢⍟ θ ∙ = ∙
mmono⊢⍟ θ (ts , t) = mmono⊢⍟ θ ts , mmono⊢ θ t
-- Monotonicity using context pairs.
mono²⊢ : ∀ {A Π Π′} → Π ⊆² Π′ → Π ⊢ A → Π′ ⊢ A
mono²⊢ (η , θ) = mono⊢ η ∘ mmono⊢ θ
-- Shorthand for variables.
v₀ : ∀ {A Γ Δ} → Γ , A ⁏ Δ ⊢ A
v₀ = var i₀
v₁ : ∀ {A B Γ Δ} → Γ , A , B ⁏ Δ ⊢ A
v₁ = var i₁
v₂ : ∀ {A B C Γ Δ} → Γ , A , B , C ⁏ Δ ⊢ A
v₂ = var i₂
mv₀ : ∀ {Ψ Ω A x Γ Δ}
→ {{_ : Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A ⊢⋆ Ψ}}
→ {{_ : Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A ⊢⍟ Ω}}
→ Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A ⊢ A
mv₀ = mvar i₀
mv₁ : ∀ {Ψ Ψ′ Ω Ω′ A B x y Γ Δ}
→ {{_ : Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A , [ Ψ′ ⁏ Ω′ ⊢ y ] B ⊢⋆ Ψ}}
→ {{_ : Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A , [ Ψ′ ⁏ Ω′ ⊢ y ] B ⊢⍟ Ω}}
→ Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A , [ Ψ′ ⁏ Ω′ ⊢ y ] B ⊢ A
mv₁ = mvar i₁
mv₂ : ∀ {Ψ Ψ′ Ψ″ Ω Ω′ Ω″ A B C x y z Γ Δ}
→ {{_ : Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A , [ Ψ′ ⁏ Ω′ ⊢ y ] B , [ Ψ″ ⁏ Ω″ ⊢ z ] C ⊢⋆ Ψ}}
→ {{_ : Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A , [ Ψ′ ⁏ Ω′ ⊢ y ] B , [ Ψ″ ⁏ Ω″ ⊢ z ] C ⊢⍟ Ω}}
→ Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A , [ Ψ′ ⁏ Ω′ ⊢ y ] B , [ Ψ″ ⁏ Ω″ ⊢ z ] C ⊢ A
mv₂ = mvar i₂
-- Generalised reflexivity.
instance
refl⊢⋆ : ∀ {Γ Ψ Δ} → {{_ : Ψ ⊆ Γ}} → Γ ⁏ Δ ⊢⋆ Ψ
refl⊢⋆ {∅} {{done}} = ∙
refl⊢⋆ {Γ , A} {{skip η}} = mono⊢⋆ weak⊆ (refl⊢⋆ {{η}})
refl⊢⋆ {Γ , A} {{keep η}} = mono⊢⋆ weak⊆ (refl⊢⋆ {{η}}) , v₀
mrefl⊢⍟ : ∀ {Δ Ω Γ} → {{_ : Ω ⊆ Δ}} → Γ ⁏ Δ ⊢⍟ Ω
mrefl⊢⍟ {∅} {{done}} = ∙
mrefl⊢⍟ {Δ , [ Ψ ⁏ Ω ⊢ x ] A } {{skip θ}} = mmono⊢⍟ weak⊆ (mrefl⊢⍟ {{θ}})
mrefl⊢⍟ {Δ , [ Ψ ⁏ Ω ⊢ x ] A } {{keep θ}} = mmono⊢⍟ weak⊆ (mrefl⊢⍟ {{θ}}) , box x
-- Deduction theorem is built-in.
-- Modal deduction theorem.
mlam : ∀ {Ψ Ω A B x Γ Δ}
→ Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A ⊢ B
→ Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω ⊢ x ] A ▻ B
mlam t = lam (unbox v₀ (mono⊢ weak⊆ t))
-- Detachment theorems.
det : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ▻ B → Γ , A ⁏ Δ ⊢ B
det t = app (mono⊢ weak⊆ t) v₀
-- FIXME: Is this correct?
mdet : ∀ {Ψ Ω A B x Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω ⊢ x ] A ▻ B
→ Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A ⊢ B
mdet {x = x} t = app (mmono⊢ weak⊆ t) (box x)
-- Cut and multicut.
cut : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A → Γ , A ⁏ Δ ⊢ B → Γ ⁏ Δ ⊢ B
cut t u = app (lam u) t
mcut : ∀ {Ψ Ω A B x Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω ⊢ x ] A
→ Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A ⊢ B
→ Γ ⁏ Δ ⊢ B
mcut t u = app (mlam u) t
multicut : ∀ {Ξ A Γ Δ} → Γ ⁏ Δ ⊢⋆ Ξ → Ξ ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ A
multicut ∙ u = mono⊢ bot⊆ u
multicut (ts , t) u = app (multicut ts (lam u)) t
-- Contraction.
ccont : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ (A ▻ A ▻ B) ▻ A ▻ B
ccont = lam (lam (app (app v₁ v₀) v₀))
cont : ∀ {A B Γ Δ} → Γ , A , A ⁏ Δ ⊢ B → Γ , A ⁏ Δ ⊢ B
cont t = det (app ccont (lam (lam t)))
mcont : ∀ {Ψ Ω A B x Γ Δ}
→ Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A , [ Ψ ⁏ Ω ⊢ x ] A ⊢ B
→ Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A ⊢ B
mcont t = mdet (app ccont (mlam (mlam t)))
-- Exchange, or Schönfinkel’s C combinator.
cexch : ∀ {A B C Γ Δ} → Γ ⁏ Δ ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C
cexch = lam (lam (lam (app (app v₂ v₀) v₁)))
exch : ∀ {A B C Γ Δ} → Γ , A , B ⁏ Δ ⊢ C → Γ , B , A ⁏ Δ ⊢ C
exch t = det (det (app cexch (lam (lam t))))
mexch : ∀ {Ψ Ψ′ Ω Ω′ A B C x y Γ Δ}
→ Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A , [ Ψ′ ⁏ Ω′ ⊢ y ] B ⊢ C
→ Γ ⁏ Δ , [ Ψ′ ⁏ Ω′ ⊢ y ] B , [ Ψ ⁏ Ω ⊢ x ] A ⊢ C
mexch t = mdet (mdet (app cexch (mlam (mlam t))))
-- Composition, or Schönfinkel’s B combinator.
ccomp : ∀ {A B C Γ Δ} → Γ ⁏ Δ ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
ccomp = lam (lam (lam (app v₂ (app v₁ v₀))))
comp : ∀ {A B C Γ Δ} → Γ , B ⁏ Δ ⊢ C → Γ , A ⁏ Δ ⊢ B → Γ , A ⁏ Δ ⊢ C
comp t u = det (app (app ccomp (lam t)) (lam u))
mcomp : ∀ {Ψ Ψ′ Ψ″ Ω Ω′ Ω″ A B C x y z Γ Δ}
→ Γ ⁏ Δ , [ Ψ′ ⁏ Ω′ ⊢ y ] B ⊢ [ Ψ″ ⁏ Ω″ ⊢ z ] C
→ Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A ⊢ [ Ψ′ ⁏ Ω′ ⊢ y ] B
→ Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A ⊢ [ Ψ″ ⁏ Ω″ ⊢ z ] C
mcomp t u = mdet (app (app ccomp (mlam t)) (mlam u))
-- Useful theorems in functional form.
dist : ∀ {Ψ Ω A B x y Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω ⊢ x ] (A ▻ B)
→ Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω ⊢ y ] A
→ Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω , [ Ψ ⁏ Ω ⊢ x ] (A ▻ B) , [ Ψ ⁏ Ω ⊢ y ] A ⊢ app mv₁ mv₀ ] B
dist t u = unbox t (unbox (mmono⊢ weak⊆ u) (box
(app mv₁ mv₀)))
up : ∀ {Ψ Ω A x Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω ⊢ x ] A
→ Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω ⊢ box mv₀ ] [ Ψ ⁏ Ω , [ Ψ ⁏ Ω ⊢ x ] A ⊢ mv₀ ] A
up t = unbox t (box (box mv₀))
down : ∀ {Ψ Ω A x Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω ⊢ x ] A
→ {{_ : Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A ⊢⋆ Ψ}}
→ {{_ : Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ x ] A ⊢⍟ Ω}}
→ Γ ⁏ Δ ⊢ A
down t = unbox t mv₀
-- Useful theorems in combinatory form.
ci : ∀ {A Γ Δ} → Γ ⁏ Δ ⊢ A ▻ A
ci = lam v₀
ck : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ▻ B ▻ A
ck = lam (lam v₁)
cs : ∀ {A B C Γ Δ} → Γ ⁏ Δ ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
cs = lam (lam (lam (app (app v₂ v₀) (app v₁ v₀))))
cdist : ∀ {Ψ Ω A B t u Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω ⊢ t ] (A ▻ B) ▻
[ Ψ ⁏ Ω ⊢ u ] A ▻
[ Ψ ⁏ Ω , [ Ψ ⁏ Ω ⊢ t ] (A ▻ B) , [ Ψ ⁏ Ω ⊢ u ] A ⊢ app mv₁ mv₀ ] B
cdist = lam (lam (dist v₁ v₀))
cup : ∀ {Ψ Ω A t Γ Δ}
→ Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω ⊢ t ] A ▻
[ Ψ ⁏ Ω ⊢ box mv₀ ] [ Ψ ⁏ Ω , [ Ψ ⁏ Ω ⊢ t ] A ⊢ mv₀ ] A
cup = lam (up v₀)
cunbox : ∀ {Ψ Ω A C t Γ Δ} → Γ ⁏ Δ ⊢ [ Ψ ⁏ Ω ⊢ t ] A ▻ ([ Ψ ⁏ Ω ⊢ t ] A ▻ C) ▻ C
cunbox = lam (lam (app v₀ v₁))
cpair : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ▻ B ▻ A ∧ B
cpair = lam (lam (pair v₁ v₀))
cfst : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ∧ B ▻ A
cfst = lam (fst v₀)
csnd : ∀ {A B Γ Δ} → Γ ⁏ Δ ⊢ A ∧ B ▻ B
csnd = lam (snd v₀)
-- Closure under context concatenation.
concat : ∀ {A B Γ} Γ′ {Δ} → Γ , A ⁏ Δ ⊢ B → Γ′ ⁏ Δ ⊢ A → Γ ⧺ Γ′ ⁏ Δ ⊢ B
concat Γ′ t u = app (mono⊢ (weak⊆⧺₁ Γ′) (lam t)) (mono⊢ weak⊆⧺₂ u)
mconcat : ∀ {Ψ Ω A B t Γ Δ} Δ′ → Γ ⁏ Δ , [ Ψ ⁏ Ω ⊢ t ] A ⊢ B → Γ ⁏ Δ′ ⊢ [ Ψ ⁏ Ω ⊢ t ] A → Γ ⁏ Δ ⧺ Δ′ ⊢ B
mconcat Δ′ t u = app (mmono⊢ (weak⊆⧺₁ Δ′) (mlam t)) (mmono⊢ weak⊆⧺₂ u)
-- Substitution.
mutual
[_≔_]_ : ∀ {A C Γ Δ} → (i : A ∈ Γ) → Γ ∖ i ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢ C → Γ ∖ i ⁏ Δ ⊢ C
[ i ≔ s ] var j with i ≟∈ j
[ i ≔ s ] var .i | same = s
[ i ≔ s ] var ._ | diff j = var j
[ i ≔ s ] lam t = lam ([ pop i ≔ mono⊢ weak⊆ s ] t)
[ i ≔ s ] app t u = app ([ i ≔ s ] t) ([ i ≔ s ] u)
[ i ≔ s ] mvar j {{ts}} {{us}} = mvar j {{[ i ≔ s ]⋆ ts}} {{[ i ≔ s ]⍟ us}}
[ i ≔ s ] box t = box t
[ i ≔ s ] unbox t u = unbox ([ i ≔ s ] t) ([ i ≔ mmono⊢ weak⊆ s ] u)
[ i ≔ s ] pair t u = pair ([ i ≔ s ] t) ([ i ≔ s ] u)
[ i ≔ s ] fst t = fst ([ i ≔ s ] t)
[ i ≔ s ] snd t = snd ([ i ≔ s ] t)
[ i ≔ s ] unit = unit
[_≔_]⋆_ : ∀ {Ξ A Γ Δ} → (i : A ∈ Γ) → Γ ∖ i ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢⋆ Ξ → Γ ∖ i ⁏ Δ ⊢⋆ Ξ
[_≔_]⋆_ i s ∙ = ∙
[_≔_]⋆_ i s (ts , t) = [ i ≔ s ]⋆ ts , [ i ≔ s ] t
[_≔_]⍟_ : ∀ {Ξ A Γ Δ} → (i : A ∈ Γ) → Γ ∖ i ⁏ Δ ⊢ A → Γ ⁏ Δ ⊢⍟ Ξ → Γ ∖ i ⁏ Δ ⊢⍟ Ξ
[_≔_]⍟_ i s ∙ = ∙
[_≔_]⍟_ i s (ts , t) = [ i ≔ s ]⍟ ts , [ i ≔ s ] t
-- Modal substitution.
mutual
m[_≔_]_ : ∀ {Ψ Ω A C t Γ Δ} → (i : [ Ψ ⁏ Ω ⊢ t ] A ∈ Δ) → Ψ ⁏ Δ ∖ i ⊢ A → Γ ⁏ Δ ⊢ C → Γ ⁏ Δ ∖ i ⊢ C
m[ i ≔ s ] var j = var j
m[ i ≔ s ] lam t = lam (m[ i ≔ s ] t)
m[ i ≔ s ] app t u = app (m[ i ≔ s ] t) (m[ i ≔ s ] u)
m[ i ≔ s ] mvar j {{ts}} {{us}} with i ≟∈ j
m[ i ≔ s ] mvar .i {{ts}} {{us}} | same = multicut (m[ i ≔ s ]⋆ ts) s
m[ i ≔ s ] mvar ._ {{ts}} {{us}} | diff j = mvar j {{m[ i ≔ s ]⋆ ts}} {{m[ i ≔ s ]⍟ us}}
m[ i ≔ s ] box t = box t
m[ i ≔ s ] unbox t u = unbox (m[ i ≔ s ] t) (m[ pop i ≔ mmono⊢ weak⊆ s ] u)
m[ i ≔ s ] pair t u = pair (m[ i ≔ s ] t) (m[ i ≔ s ] u)
m[ i ≔ s ] fst t = fst (m[ i ≔ s ] t)
m[ i ≔ s ] snd t = snd (m[ i ≔ s ] t)
m[ i ≔ s ] unit = unit
m[_≔_]⋆_ : ∀ {Ξ Ψ Ω A t Γ Δ} → (i : [ Ψ ⁏ Ω ⊢ t ] A ∈ Δ) → Ψ ⁏ Δ ∖ i ⊢ A → Γ ⁏ Δ ⊢⋆ Ξ → Γ ⁏ Δ ∖ i ⊢⋆ Ξ
m[_≔_]⋆_ i s ∙ = ∙
m[_≔_]⋆_ i s (ts , t) = m[ i ≔ s ]⋆ ts , m[ i ≔ s ] t
m[_≔_]⍟_ : ∀ {Ξ Ψ Ω A t Γ Δ} → (i : [ Ψ ⁏ Ω ⊢ t ] A ∈ Δ) → Ψ ⁏ Δ ∖ i ⊢ A → Γ ⁏ Δ ⊢⍟ Ξ → Γ ⁏ Δ ∖ i ⊢⍟ Ξ
m[_≔_]⍟_ i s ∙ = ∙
m[_≔_]⍟_ i s (ts , t) = m[ i ≔ s ]⍟ ts , m[ i ≔ s ] t
-- TODO: Convertibility.
-- Examples from the Nanevski-Pfenning-Pientka paper.
-- NOTE: In many cases, the instance argument for mvar can be automatically inferred, but not always.
module Examples₁ where
e₁ : ∀ {A C D Γ Δ t}
→ Γ ⁏ Δ ⊢ [ ∅ , C ⁏ Δ ⊢ t ] A ▻
[ ∅ , C , D ⁏ Δ , [ ∅ , C ⁏ Δ ⊢ t ] A ⊢ mv₀ ] A
e₁ = lam (unbox v₀ (box mv₀))
e₂ : ∀ {A C Γ Δ t}
→ Γ ⁏ Δ ⊢ [ ∅ , C , C ⁏ Δ ⊢ t ] A ▻
[ ∅ , C ⁏ Δ , [ ∅ , C , C ⁏ Δ ⊢ t ] A ⊢ mv₀ ] A
e₂ = lam (unbox v₀ (box mv₀))
e₃ : ∀ {A Γ Δ}
→ Γ ⁏ Δ ⊢ [ ∅ , A ⁏ Δ ⊢ v₀ ] A
e₃ = box v₀
e₄ : ∀ {A B C Γ Δ t u v}
→ Γ ⁏ Δ ⊢ [ ∅ , A ⁏ Δ ⊢ t ] B ▻
[ ∅ , A ⁏ Δ ⊢ v ] [ ∅ , B ⁏ Δ ⊢ u ] C ▻
[ ∅ , A ⁏ Δ , [ ∅ , A ⁏ Δ ⊢ t ] B
, [ ∅ , A ⁏ Δ ⊢ v ] [ ∅ , B ⁏ Δ ⊢ u ] C
⊢ unbox mv₀ (mv₀ {{∙ , mv₂}}) ] C
e₄ = lam (lam (unbox v₁ (unbox v₀ (box
(unbox mv₀ (mv₀ {{∙ , mv₂}}))))))
e₅ : ∀ {A Γ Δ t}
→ Γ ⁏ Δ ⊢ [ ∅ ⁏ Δ ⊢ t ] A ▻ A
e₅ = lam (unbox v₀ mv₀)
e₆ : ∀ {A C D Γ Δ t}
→ Γ ⁏ Δ ⊢ [ ∅ , C ⁏ Δ ⊢ t ] A ▻
[ ∅ , D ⁏ Δ ⊢ box mv₀ ]
[ ∅ , C ⁏ Δ , [ ∅ , C ⁏ Δ ⊢ t ]
A ⊢ mv₀ ] A
e₆ = lam (unbox v₀ (box (box mv₀)))
e₇ : ∀ {A B C D Γ Δ t u}
→ Γ ⁏ Δ ⊢ [ ∅ , C ⁏ Δ ⊢ t ] (A ▻ B) ▻
[ ∅ , D ⁏ Δ ⊢ u ] A ▻
[ ∅ , C , D ⁏ Δ , [ ∅ , C ⁏ Δ ⊢ t ] (A ▻ B)
, [ ∅ , D ⁏ Δ ⊢ u ] A
⊢ app mv₁ mv₀ ] B
e₇ = lam (lam (unbox v₁ (unbox v₀ (box
(app mv₁ mv₀)))))
e₈ : ∀ {A B C Γ Δ t u}
→ Γ ⁏ Δ ⊢ [ ∅ , A ⁏ Δ ⊢ t ] (A ▻ B) ▻
[ ∅ , B ⁏ Δ ⊢ u ] C ▻
[ ∅ , A ⁏ Δ , [ ∅ , A ⁏ Δ ⊢ t ] (A ▻ B)
, [ ∅ , B ⁏ Δ ⊢ u ] C
⊢ mv₀ {{∙ , app mv₁ v₀}} ] C
e₈ = lam (lam (unbox v₁ (unbox v₀ (box
(mv₀ {{∙ , app mv₁ v₀}})))))
-- Examples from the Alt-Artemov paper.
module Examples₂ where
e₁ : ∀ {A Γ Δ t}
→ Γ ⁏ Δ ⊢ [ ∅ ⁏ Δ ⊢ lam (down v₀) ]
([ ∅ ⁏ Δ ⊢ t ] A ▻ A)
e₁ = box (lam (down v₀))
e₂ : ∀ {A Γ Δ t}
→ Γ ⁏ Δ ⊢ [ ∅ ⁏ Δ ⊢ lam (up v₀) ]
([ ∅ ⁏ Δ ⊢ t ] A ▻
[ ∅ ⁏ Δ ⊢ box mv₀ ]
[ ∅ ⁏ Δ , [ ∅ ⁏ Δ ⊢ t ]
A ⊢ mv₀ ] A)
e₂ = box (lam (up v₀))
e₃ : ∀ {A B Γ Δ}
→ Γ ⁏ Δ ⊢ [ ∅ ⁏ Δ ⊢ box (lam (lam (pair v₁ v₀))) ]
[ ∅ ⁏ Δ ⊢ lam (lam (pair v₁ v₀)) ]
(A ▻ B ▻ A ∧ B)
e₃ = box (box (lam (lam (pair v₁ v₀))))
e₄ : ∀ {A B Γ Δ t u}
→ Γ ⁏ Δ ⊢ [ ∅ ⁏ Δ ⊢ lam (lam (unbox v₁ (unbox v₀ (box
(box (pair mv₁ mv₀)))))) ]
([ ∅ ⁏ Δ ⊢ t ] A ▻
[ ∅ ⁏ Δ ⊢ u ] B ▻
[ ∅ ⁏ Δ ⊢ box (pair mv₁ mv₀) ]
[ ∅ ⁏ Δ , [ ∅ ⁏ Δ ⊢ t ] A
, [ ∅ ⁏ Δ ⊢ u ] B
⊢ pair mv₁ mv₀ ]
(A ∧ B))
e₄ = box (lam (lam (unbox v₁ (unbox v₀ (box
(box (pair mv₁ mv₀)))))))
| {
"alphanum_fraction": 0.3501698609,
"avg_line_length": 32.9135021097,
"ext": "agda",
"hexsha": "bd11b216b9322a3bdc47686de20e79ffaf417114",
"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": "BasicILP/Syntax/DyadicGentzen.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": "BasicILP/Syntax/DyadicGentzen.agda",
"max_line_length": 138,
"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": "BasicILP/Syntax/DyadicGentzen.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": 8034,
"size": 15601
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Consensus.Types.EpochDep
open import LibraBFT.ImplShared.Util.Crypto
open import Optics.All
open import Util.PKCS
open import Util.Prelude
open import LibraBFT.Abstract.Types.EpochConfig UID NodeId
open EpochConfig
open import Yasm.Base ℓ-RoundManager
-- In this module, we instantiate the system model with parameters to
-- model a system using the simple implementation model we have so
-- far, which aims to obey the VotesOnceRule, but not PreferredRoundRule
-- yet. This will evolve as we build out a model of a real
-- implementation.
module LibraBFT.Concrete.System.Parameters where
ConcSysParms : SystemTypeParameters
ConcSysParms = mkSysTypeParms
NodeId
_≟NodeId_
BootstrapInfo
∈BootstrapInfo-impl
RoundManager
NetworkMsg
Vote -- TODO-3: This should be a type that also allows Block, because
-- NetworkMsgs can include signed Blocks, raising the possibility of
-- the "masquerading" issue mentioned in
-- LibraBFT.ImplShared.Util.Crypto, which we will need to address by
-- using HashTags, as also discussed in the module.
sig-Vote
_⊂Msg_
open import Yasm.System ℓ-RoundManager ℓ-VSFP ConcSysParms
module ParamsWithInitAndHandlers (iiah : SystemInitAndHandlers ConcSysParms) where
open SystemInitAndHandlers iiah
open WithInitAndHandlers iiah
-- What EpochConfigs are known in the system? For now, only the
-- initial one. Later, we will add knowledge of subsequent
-- EpochConfigs known via EpochChangeProofs. In fact, the
-- implementation creates and stores and EpochChangeProof even for the
-- initial epoch, so longer term just the inECP constructor may suffice.
data EpochConfig∈Sys (st : SystemState) (𝓔 : EpochConfig) : Set ℓ-EC where
inBootstrapInfo : init-EC bootstrapInfo ≡ 𝓔 → EpochConfig∈Sys st 𝓔
-- inECP : ∀ {ecp} → ecp ECP∈Sys st → verify-ECP ecp 𝓔 → EpochConfig∈Sys
-- This is trivial for now, but will be nontrivial when we support epoch change
𝓔-∈sys-injective : ∀ {st 𝓔₁ 𝓔₂}
→ EpochConfig∈Sys st 𝓔₁
→ EpochConfig∈Sys st 𝓔₂
→ epoch 𝓔₁ ≡ epoch 𝓔₂
→ 𝓔₁ ≡ 𝓔₂
𝓔-∈sys-injective (inBootstrapInfo refl) (inBootstrapInfo refl) refl = refl
-- A peer pid can sign a new message for a given PK if pid is the owner of a PK in a known
-- EpochConfig.
record PeerCanSignForPKinEpoch (st : SystemState) (v : Vote) (pid : NodeId) (pk : PK)
(𝓔 : EpochConfig) (𝓔inSys : EpochConfig∈Sys st 𝓔)
: Set ℓ-VSFP where
constructor mkPCS4PKin𝓔
field
𝓔id≡ : epoch 𝓔 ≡ v ^∙ vEpoch
mbr : Member 𝓔
nid≡ : toNodeId 𝓔 mbr ≡ pid
pk≡ : getPubKey 𝓔 mbr ≡ pk
open PeerCanSignForPKinEpoch
record PeerCanSignForPK (st : SystemState) (v : Vote) (pid : NodeId) (pk : PK) : Set ℓ-VSFP where
constructor mkPCS4PK
field
pcs4𝓔 : EpochConfig
pcs4𝓔∈Sys : EpochConfig∈Sys st pcs4𝓔
pcs4in𝓔 : PeerCanSignForPKinEpoch st v pid pk pcs4𝓔 pcs4𝓔∈Sys
open PeerCanSignForPK
PCS4PK⇒NodeId-PK-OK : ∀ {st v pid pk 𝓔 𝓔∈Sys} → (pcs : PeerCanSignForPKinEpoch st v pid pk 𝓔 𝓔∈Sys) → NodeId-PK-OK 𝓔 pk pid
PCS4PK⇒NodeId-PK-OK (mkPCS4PKin𝓔 _ mbr n≡ pk≡) = mbr , n≡ , pk≡
-- This is super simple for now because the only known EpochConfig is dervied from bootstrapInfo, which is not state-dependent
PeerCanSignForPK-stable : ValidSenderForPK-stable-type PeerCanSignForPK
PeerCanSignForPK-stable _ _ (mkPCS4PK 𝓔₁ (inBootstrapInfo refl) (mkPCS4PKin𝓔 𝓔id≡₁ mbr₁ nid≡₁ pk≡₁)) =
(mkPCS4PK 𝓔₁ (inBootstrapInfo refl) (mkPCS4PKin𝓔 𝓔id≡₁ mbr₁ nid≡₁ pk≡₁))
peerCanSignEp≡ : ∀ {pid v v' pk s'}
→ PeerCanSignForPK s' v pid pk
→ v ^∙ vEpoch ≡ v' ^∙ vEpoch
→ PeerCanSignForPK s' v' pid pk
peerCanSignEp≡ (mkPCS4PK 𝓔₁ 𝓔inSys₁ (mkPCS4PKin𝓔 𝓔id≡₁ mbr₁ nid≡₁ pk≡₁)) refl
= (mkPCS4PK 𝓔₁ 𝓔inSys₁ (mkPCS4PKin𝓔 𝓔id≡₁ mbr₁ nid≡₁ pk≡₁))
| {
"alphanum_fraction": 0.6492281304,
"avg_line_length": 46.64,
"ext": "agda",
"hexsha": "95f045a9d9ae4f3240993a3e18ac5c290d5d6ed3",
"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": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Concrete/System/Parameters.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Concrete/System/Parameters.agda",
"max_line_length": 129,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Concrete/System/Parameters.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1467,
"size": 4664
} |
open import and-example public
open import ex-andreas-abel public
| {
"alphanum_fraction": 0.8333333333,
"avg_line_length": 22,
"ext": "agda",
"hexsha": "eb1b577733ce6377d11f0322a2340a24151b2193",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2017-12-01T17:01:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-03-30T16:41:56.000Z",
"max_forks_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jonaprieto/agda-prop",
"max_forks_repo_path": "test/test.agda",
"max_issues_count": 18,
"max_issues_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_issues_repo_issues_event_max_datetime": "2017-12-18T16:34:21.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-03-08T14:33:10.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jonaprieto/agda-prop",
"max_issues_repo_path": "test/test.agda",
"max_line_length": 34,
"max_stars_count": 13,
"max_stars_repo_head_hexsha": "a1730062a6aaced2bb74878c1071db06477044ae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jonaprieto/agda-prop",
"max_stars_repo_path": "test/test.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T03:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-01T16:45:41.000Z",
"num_tokens": 15,
"size": 66
} |
{-# OPTIONS --show-irrelevant #-}
postulate
A : Set
f : .A → A
data _≡_ (x : A) : A → Set where
refl : x ≡ x
mutual
X : .A → A
X = _
Y : A → A
Y = {!λ x → x!}
Z : A → A
Z = {!λ x → x!}
test : ∀ x → X (Y x) ≡ f (Z x)
test x = refl
| {
"alphanum_fraction": 0.4069767442,
"avg_line_length": 11.7272727273,
"ext": "agda",
"hexsha": "e01c770b1b7e99df8d9291772052177af4813d94",
"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/interaction/Issue4136.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue4136.agda",
"max_line_length": 33,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue4136.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 121,
"size": 258
} |
module Adjoint where
open import Level
open import Data.Product
open import Basic
open import Category
import Functor
import Nat
open Category.Category
open Functor.Functor
open Nat.Nat
open Nat.Export
record Adjoint {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} (F : Functor.Functor C D) (G : Functor.Functor D C) : Set (suc ℓ ⊔ suc C₁ ⊔ C₀ ⊔ suc ℓ′ ⊔ suc D₁ ⊔ D₀) where
field
adjunction : {x : Obj C} {a : Obj D} → Setoids [ LiftSetoid {b = C₁ ⊔ D₁} {ℓ′ = ℓ ⊔ ℓ′} (Homsetoid D (fobj F x) a) ≅ LiftSetoid {b = C₁ ⊔ D₁} {ℓ′ = ℓ ⊔ ℓ′} (Homsetoid C x (fobj G a)) ]
adjunct-→-Map : {x : Obj C} {a : Obj D} → Map.Map (Homsetoid D (fobj F x) a) (Homsetoid C x (fobj G a))
adjunct-→-Map {x} {a} = lowerMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (_[_≅_].map-→ (adjunction {x} {a}))
adjunct-←-Map : {x : Obj C} {a : Obj D} → Map.Map (Homsetoid C x (fobj G a)) (Homsetoid D (fobj F x) a)
adjunct-←-Map {x} {a} = lowerMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (_[_≅_].map-← (adjunction {x} {a}))
adjunct-→ : {x : Obj C} {a : Obj D} → Hom D (fobj F x) a → Hom C x (fobj G a)
adjunct-→ f = Map.mapping (lowerMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (_[_≅_].map-→ adjunction)) f
adjunct-← : {x : Obj C} {a : Obj D} → Hom C x (fobj G a) → Hom D (fobj F x) a
adjunct-← f = Map.mapping (lowerMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (_[_≅_].map-← adjunction)) f
adjunct-→←≈id : {x : Obj C} {a : Obj D} {f : Hom C x (fobj G a)} → C [ adjunct-→ (adjunct-← f) ≈ f ]
adjunct-→←≈id {x} {a} {f} = lower (proj₁ (_[_≅_].proof adjunction) (lift f))
adjunct-←→≈id : {x : Obj C} {a : Obj D} {f : Hom D (fobj F x) a} → D [ adjunct-← (adjunct-→ f) ≈ f ]
adjunct-←→≈id {x} {a} {f} = lower (proj₂ (_[_≅_].proof adjunction) (lift f))
field
natural-in-→-C : {x y : Obj C} {a : Obj D} {f : Hom C y x} →
Setoids [ Setoids [ liftMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (component HomNat[ C ][ f ,-] (fobj G a)) ∘ _[_≅_].map-→ adjunction ] ≈ Setoids [ _[_≅_].map-→ adjunction ∘ liftMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (component HomNat[ D ][ fmap F f ,-] a) ] ]
natural-in-→-D : {x : Obj C} {a b : Obj D} {f : Hom D a b} →
Setoids [ Setoids [ liftMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (component HomNat[ C ][-, fmap G f ] x) ∘ _[_≅_].map-→ adjunction ] ≈ Setoids [ _[_≅_].map-→ adjunction ∘ liftMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (component HomNat[ D ][-, f ] (fobj F x)) ] ]
natural-in-←-C : {x y : Obj C} {a : Obj D} {f : Hom C y x} →
Setoids [ Setoids [ liftMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (component HomNat[ D ][ fmap F f ,-] a) ∘ _[_≅_].map-← adjunction ] ≈ Setoids [ _[_≅_].map-← adjunction ∘ liftMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (component HomNat[ C ][ f ,-] (fobj G a)) ] ]
natural-in-←-C {x} {y} {a} {f} = begin⟨ Setoids ⟩
Setoids [ Ffa ∘ _[_≅_].map-← adjunction ] ≈⟨ ≈-composite Setoids {f = Ffa} {g = Setoids [ Setoids [ adj← ∘ fGa ] ∘ _[_≅_].map-→ adjunction ]} {h = adj→₂} {i = adj→₂} lem-1 (refl-hom Setoids {f = _[_≅_].map-← adjunction}) ⟩
Setoids [ Setoids [ adj← ∘ fGa ] ∘ Setoids [ _[_≅_].map-→ adjunction ∘ _[_≅_].map-← adjunction ] ] ≈⟨ ≈-composite Setoids {f = Setoids [ adj← ∘ fGa ]} {g = Setoids [ adj← ∘ fGa ]} {h = Setoids [ _[_≅_].map-→ adjunction ∘ _[_≅_].map-← adjunction ]} {i = id Setoids} (refl-hom Setoids {f = Setoids [ adj← ∘ fGa ]}) (proj₁ (_[_≅_].proof adjunction)) ⟩
Setoids [ adj← ∘ fGa ]
∎
where
Ffa = liftMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (component HomNat[ D ][ fmap F f ,-] a)
fGa = liftMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (component HomNat[ C ][ f ,-] (fobj G a))
adj← = _[_≅_].map-← adjunction
adj→₂ = _[_≅_].map-← adjunction
adj→ = _[_≅_].map-→ adjunction
lem-1 : Setoids [ Ffa ≈ Setoids [ Setoids [ adj← ∘ fGa ] ∘ _[_≅_].map-→ adjunction ] ]
lem-1 = begin⟨ Setoids ⟩
Ffa ≈⟨ leftId Setoids {f = Ffa} ⟩
Setoids [ id Setoids ∘ Ffa ] ≈⟨ ≈-composite Setoids {f = id Setoids} {g = Setoids [ adj← ∘ adj→ ]} {h = Ffa} {i = Ffa} (sym-hom Setoids {f = Setoids [ adj← ∘ adj→ ]} {g = id Setoids} (proj₂ (_[_≅_].proof adjunction))) (refl-hom Setoids {f = Ffa}) ⟩
Setoids [ adj← ∘ Setoids [ adj→ ∘ Ffa ] ] ≈⟨ ≈-composite Setoids {f = adj←} {g = adj←} {h = Setoids [ adj→ ∘ Ffa ]} {i = Setoids [ fGa ∘ _[_≅_].map-→ adjunction ]} (refl-hom Setoids {f = adj←}) (sym-hom Setoids {f = Setoids [ fGa ∘ _[_≅_].map-→ adjunction ]} {g = Setoids [ adj→ ∘ Ffa ]} natural-in-→-C) ⟩
Setoids [ Setoids [ _[_≅_].map-← adjunction ∘ liftMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (component HomNat[ C ][ f ,-] (fobj G a)) ] ∘ _[_≅_].map-→ adjunction ]
∎
natural-in-←-D : {x : Obj C} {a b : Obj D} {f : Hom D a b} →
Setoids [ Setoids [ liftMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (component HomNat[ D ][-, f ] (fobj F x)) ∘ _[_≅_].map-← adjunction ] ≈ Setoids [ _[_≅_].map-← adjunction ∘ liftMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (component HomNat[ C ][-, fmap G f ] x) ] ]
natural-in-←-D {x} {a} {b} {f} = begin⟨ Setoids ⟩
Setoids [ fFx ∘ adj←a ] ≈⟨ ≈-composite Setoids {f = fFx} {g = Setoids [ Setoids [ adj←b ∘ Gfx ] ∘ adj→a ]} {h = adj←a} {i = adj←a} lem-1 (refl-hom Setoids {f = adj←a}) ⟩
Setoids [ Setoids [ adj←b ∘ Gfx ] ∘ Setoids [ adj→a ∘ adj←a ] ] ≈⟨ ≈-composite Setoids {f = Setoids [ adj←b ∘ Gfx ]} {g = Setoids [ adj←b ∘ Gfx ]} {h = Setoids [ adj→a ∘ adj←a ]} {i = id Setoids} (refl-hom Setoids {f = Setoids [ adj←b ∘ Gfx ]}) (proj₁ (_[_≅_].proof adjunction)) ⟩
Setoids [ adj←b ∘ Gfx ]
∎
where
fFx = liftMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (component HomNat[ D ][-, f ] (fobj F x))
Gfx = liftMap {d = C₁ ⊔ D₁} {ℓ″ = ℓ ⊔ ℓ′} (component HomNat[ C ][-, fmap G f ] x)
adj←a = _[_≅_].map-← adjunction
adj←b = _[_≅_].map-← adjunction
adj→a = _[_≅_].map-→ adjunction
adj→b = _[_≅_].map-→ adjunction
lem-1 : Setoids [ fFx ≈ Setoids [ Setoids [ adj←b ∘ Gfx ] ∘ adj→a ] ]
lem-1 = begin⟨ Setoids ⟩
fFx ≈⟨ ≈-composite Setoids {f = id Setoids} {g = Setoids [ adj←b ∘ adj→b ]} {h = fFx} {i = fFx} (sym-hom Setoids {f = Setoids [ adj←b ∘ adj→b ]} {g = id Setoids} (proj₂ (_[_≅_].proof adjunction))) (refl-hom Setoids {f = fFx}) ⟩
Setoids [ adj←b ∘ Setoids [ adj→b ∘ fFx ] ] ≈⟨ ≈-composite Setoids {f = adj←b} {g = adj←b} {h = Setoids [ adj→b ∘ fFx ]} {i = Setoids [ Gfx ∘ adj→a ]} (refl-hom Setoids {f = adj←b}) (sym-hom Setoids {f = Setoids [ Gfx ∘ adj→a ]} {g = Setoids [ adj→b ∘ fFx ]} natural-in-→-D) ⟩
Setoids [ Setoids [ adj←b ∘ Gfx ] ∘ adj→a ]
∎
naturality-point-←-C : {x y : Obj C} {a : Obj D} {f : Hom C y x} {k : Hom C x (fobj G a)} → D [ D [ adjunct-← k ∘ fmap F f ] ≈ adjunct-← (C [ k ∘ f ]) ]
naturality-point-←-C = λ {x} {y} {a} {f} {k} → lower (natural-in-←-C (lift k))
naturality-point-→-C : {x y : Obj C} {a : Obj D} {f : Hom C y x} {k : Hom D (fobj F x) a} → C [ C [ adjunct-→ k ∘ f ] ≈ adjunct-→ (D [ k ∘ fmap F f ]) ]
naturality-point-→-C = λ {x} {y} {a} {f} {k} → lower (natural-in-→-C (lift k))
naturality-point-←-D : {x : Obj C} {a b : Obj D} {f : Hom D a b} {k : Hom C x (fobj G a)} → D [ D [ f ∘ adjunct-← k ] ≈ adjunct-← (C [ fmap G f ∘ k ]) ]
naturality-point-←-D = λ {x} {y} {a} {f} {k} → lower (natural-in-←-D (lift k))
naturality-point-→-D : {x : Obj C} {a b : Obj D} {f : Hom D a b} {k : Hom D (fobj F x) a} → C [ C [ fmap G f ∘ adjunct-→ k ] ≈ adjunct-→ (D [ f ∘ k ]) ]
naturality-point-→-D = λ {x} {y} {a} {f} {k} → lower (natural-in-→-D (lift k))
open Adjoint
unit : ∀ {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} {G : Functor.Functor D C} → Adjoint F G → Nat.Nat (Functor.identity C) (Functor.compose G F)
unit {C₀} {C₁} {ℓ} {D₀} {D₁} {ℓ′} {C} {D} {F} {G} F⊣G = record {
component = λ X → adjunct-→ F⊣G (id D) ;
naturality = λ {a} {b} {f} → begin⟨ C ⟩
C [ adjunct-→ F⊣G (id D) ∘ fmap (Functor.identity C) f ] ≈⟨ naturality-point-→-C F⊣G ⟩
adjunct-→ F⊣G (D [ id D ∘ fmap F (fmap (Functor.identity C) f) ]) ≈⟨ Map.preserveEq (adjunct-→-Map F⊣G) (leftId D) ⟩
adjunct-→ F⊣G (fmap F f) ≈⟨ Map.preserveEq (adjunct-→-Map F⊣G) (sym-hom D (rightId D)) ⟩
adjunct-→ F⊣G (D [ fmap F f ∘ id D ]) ≈⟨ sym-hom C (naturality-point-→-D F⊣G) ⟩
C [ fmap (Functor.compose G F) f ∘ adjunct-→ F⊣G (id D) ]
∎ }
counit : ∀ {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} {G : Functor.Functor D C} → Adjoint F G → Nat.Nat (Functor.compose F G) (Functor.identity D)
counit {C₀} {C₁} {ℓ} {D₀} {D₁} {ℓ′} {C} {D} {F} {G} F⊣G = record {
component = λ X → adjunct-← F⊣G (id C) ;
naturality = λ {a} {b} {f} → begin⟨ D ⟩
D [ adjunct-← F⊣G (id C) ∘ fmap (Functor.compose F G) f ] ≈⟨ naturality-point-←-C F⊣G ⟩
adjunct-← F⊣G (C [ id C ∘ fmap G f ]) ≈⟨ Map.preserveEq (adjunct-←-Map F⊣G) (leftId C) ⟩
adjunct-← F⊣G (fmap G f) ≈⟨ Map.preserveEq (adjunct-←-Map F⊣G) (sym-hom C (rightId C)) ⟩
adjunct-← F⊣G (C [ fmap G f ∘ id C ]) ≈⟨ sym-hom D (naturality-point-←-D F⊣G) ⟩
D [ fmap (Functor.identity D) f ∘ adjunct-← F⊣G (id C) ]
∎}
Unit-universal : ∀ {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} {G : Functor.Functor D C} → Adjoint F G → Set _
Unit-universal {C = C} {D} {F} {G} adj = ∀ {X : Obj C} {A : Obj D} (f : Hom C X (fobj G A)) → ∃! (λ x y → D [ x ≈ y ]) (λ (h : Hom D (fobj F X) A) → C [ C [ fmap G h ∘ component (unit adj) X ] ≈ f ])
unit-universality : ∀ {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} {G : Functor.Functor D C} → (adj : Adjoint F G) → Unit-universal adj
unit-universality {C = C} {D} {F} {G} F⊣G {X} {A} f =
adjunct-← F⊣G f , lem-1 , lem-2
where
lem-1 = begin⟨ C ⟩
C [ fmap G (adjunct-← F⊣G f) ∘ component (unit F⊣G) X ] ≈⟨ naturality-point-→-D F⊣G ⟩
adjunct-→ F⊣G (D [ adjunct-← F⊣G f ∘ id D ]) ≈⟨ Map.preserveEq (adjunct-→-Map F⊣G) (≈-composite D (refl-hom D) (sym-hom D (preserveId F))) ⟩
adjunct-→ F⊣G (D [ adjunct-← F⊣G f ∘ fmap F (id C) ]) ≈⟨ sym-hom C (naturality-point-→-C F⊣G) ⟩
C [ adjunct-→ F⊣G (adjunct-← F⊣G f) ∘ id C ] ≈⟨ rightId C ⟩
adjunct-→ F⊣G (adjunct-← F⊣G f) ≈⟨ adjunct-→←≈id F⊣G ⟩
f
∎
lem-2 = λ {y} eq → begin⟨ D ⟩
adjunct-← F⊣G f ≈⟨ Map.preserveEq (adjunct-←-Map F⊣G) (sym-hom C eq) ⟩
adjunct-← F⊣G (C [ fmap G y ∘ component (unit F⊣G) X ]) ≈⟨ sym-hom D (naturality-point-←-D (F⊣G)) ⟩
D [ y ∘ adjunct-← F⊣G (adjunct-→ F⊣G (id D)) ] ≈⟨ ≈-composite D (refl-hom D) (adjunct-←→≈id F⊣G) ⟩
D [ y ∘ id D ] ≈⟨ rightId D ⟩
y
∎
Counit-universal : ∀ {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} {G : Functor.Functor D C} → Adjoint F G → Set _
Counit-universal {C = C} {D} {F} {G} adj = ∀ {X : Obj C} {A : Obj D} (h : Hom D (fobj F X) A) → ∃! (λ x y → C [ x ≈ y ]) (λ (f : Hom C X (fobj G A)) → D [ D [ component (counit adj) A ∘ fmap F f ] ≈ h ])
counit-universality : ∀ {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} {G : Functor.Functor D C} → (adj : Adjoint F G) → Counit-universal adj
counit-universality {C = C} {D} {F} {G} F⊣G = λ {X} {A} h →
adjunct-→ F⊣G h , lem-1 , lem-2
where
lem-1 = λ {A} {h} → begin⟨ D ⟩
D [ component (counit F⊣G) A ∘ fmap F (adjunct-→ F⊣G h) ] ≈⟨ naturality-point-←-C F⊣G ⟩
adjunct-← F⊣G (C [ id C ∘ adjunct-→ F⊣G h ]) ≈⟨ Map.preserveEq (adjunct-←-Map F⊣G) (leftId C) ⟩
adjunct-← F⊣G (adjunct-→ F⊣G h) ≈⟨ adjunct-←→≈id F⊣G ⟩
h
∎
lem-2 = λ {A} {h} {y} eq → begin⟨ C ⟩
adjunct-→ F⊣G h ≈⟨ Map.preserveEq (adjunct-→-Map F⊣G) (sym-hom D eq) ⟩
adjunct-→ F⊣G (D [ component (counit F⊣G) A ∘ fmap F y ]) ≈⟨ sym-hom C (naturality-point-→-C F⊣G) ⟩
C [ adjunct-→ F⊣G (component (counit F⊣G) A) ∘ y ] ≈⟨ ≈-composite C (adjunct-→←≈id F⊣G) (refl-hom C) ⟩
C [ id C ∘ y ] ≈⟨ leftId C ⟩
y
∎
TriangularL : ∀ {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} {G : Functor.Functor D C} → Nat.Nat (Functor.identity C) (Functor.compose G F) → Nat.Nat (Functor.compose F G) (Functor.identity D) → Set _
TriangularL {C = C} {D} {F} {G} η ε = [ C , D ] [ Nat.compose (Nat.compose Nat.leftIdNat→ (ε N∘F F)) (Nat.compose (Nat.assocNat← {F = F} {G} {F}) (Nat.compose (F F∘N η) Nat.rightIdNat←)) ≈ id [ C , D ] ]
triangularL-point : ∀ {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} {G : Functor.Functor D C} → (η : Nat.Nat (Functor.identity C) (Functor.compose G F)) → (ε : Nat.Nat (Functor.compose F G) (Functor.identity D)) → {a : Obj C} → (triL : TriangularL {F = F} {G} η ε) → D [ D [ component (ε N∘F F) a ∘ component (F F∘N η) a ] ≈ id D {fobj F a} ]
triangularL-point {C = C} {D} {F} {G} η ε {a} triL = begin⟨ D ⟩
D [ component (ε N∘F F) a ∘ component (F F∘N η) a ] ≈⟨ sym-hom D (≈-composite D (leftId D) (trans-hom D (leftId D) (rightId D))) ⟩
D [ D [ id D ∘ component (ε N∘F F) a ] ∘ D [ id D ∘ D [ component (F F∘N η) a ∘ id D ] ] ] ≈⟨ triL {a} ⟩
id D
∎
triangularL : ∀ {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} {G : Functor.Functor D C} → (adj : Adjoint F G) → TriangularL {F = F} {G} (unit adj) (counit adj)
triangularL {C = C} {D} {F} {G} adj = λ {a} →
begin⟨ D ⟩
component (Nat.compose εF (Nat.compose (Nat.assocNat← {F = F} {G} {F}) Fη)) a
≈⟨ ≈-composite D (leftId D) (trans-hom D (leftId D) (rightId D)) ⟩
D [ component ε (fobj F a) ∘ fmap F (component η a) ]
≈⟨ proj₁ (proj₂ (counit-universality adj (id D))) ⟩
id D
≈⟨ refl-hom D ⟩
component (id [ C , D ] {F}) a
∎
where
ε = counit adj
η = unit adj
εF = Nat.compose Nat.leftIdNat→ (counit adj N∘F F)
Fη = Nat.compose {F = F} (F F∘N unit adj) Nat.rightIdNat←
TriangularR : ∀ {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} {G : Functor.Functor D C} → Nat.Nat (Functor.identity C) (Functor.compose G F) → Nat.Nat (Functor.compose F G) (Functor.identity D) → Set _
TriangularR {C = C} {D} {F} {G} η ε = [ D , C ] [ Nat.compose (Nat.compose Nat.rightIdNat→ (G F∘N ε)) (Nat.compose (Nat.assocNat→ {F = G} {F} {G}) (Nat.compose (η N∘F G) Nat.leftIdNat←)) ≈ id [ D , C ] ]
triangularR : ∀ {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} {G : Functor.Functor D C} → (adj : Adjoint F G) → TriangularR {F = F} (unit adj) (counit adj)
triangularR {C = C} {D} {F} {G} adj = λ {a} → begin⟨ C ⟩
component (Nat.compose Gε (Nat.compose (Nat.assocNat→ {F = G} {F} {G}) ηG)) a ≈⟨ ≈-composite C (leftId C) (trans-hom C (leftId C) (rightId C)) ⟩
C [ fmap G (component ε a) ∘ component η (fobj G a) ] ≈⟨ proj₁ (proj₂ (unit-universality adj (id C))) ⟩
id C ≈⟨ refl-hom C ⟩
component (id [ D , C ] {G}) a
∎
where
ε = counit adj
η = unit adj
Gε = Nat.compose {H = G} Nat.rightIdNat→ (G F∘N counit adj)
ηG = Nat.compose (unit adj N∘F G) Nat.leftIdNat←
triangularR-point : ∀ {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} {G : Functor.Functor D C} → (η : Nat.Nat (Functor.identity C) (Functor.compose G F)) → (ε : Nat.Nat (Functor.compose F G) (Functor.identity D)) → {a : Obj D} → (triR : TriangularR {F = F} {G} η ε) → C [ C [ component (G F∘N ε) a ∘ component (η N∘F G) a ] ≈ id C {fobj G a} ]
triangularR-point {C = C} {D} {F} {G} η ε {a} triR = begin⟨ C ⟩
C [ component (G F∘N ε) a ∘ component (η N∘F G) a ] ≈⟨ sym-hom C (≈-composite C (leftId C) (trans-hom C (leftId C) (rightId C))) ⟩
C [ C [ id C ∘ component (G F∘N ε) a ] ∘ C [ id C ∘ C [ component (η N∘F G) a ∘ id C ] ] ] ≈⟨ triR {a = a} ⟩
id C
∎
unit-triangular-holds-adjoint : ∀ {C₀ C₁ ℓ D₀ D₁ ℓ′} {C : Category C₀ C₁ ℓ} {D : Category D₀ D₁ ℓ′} {F : Functor.Functor C D} {G : Functor.Functor D C} → (η : Nat.Nat (Functor.identity C) (Functor.compose G F)) → (ε : Nat.Nat (Functor.compose F G) (Functor.identity D)) → TriangularL {F = F} η ε → TriangularR {F = F} η ε → Adjoint F G
unit-triangular-holds-adjoint {C = C} {D} {F} {G} η ε triL triR = record {
adjunction = λ {x} {a} → record {
map-→ = record {
mapping = λ Fx→a → lift (C [ fmap G (lower Fx→a) ∘ component η x ]) ;
preserveEq = λ {x′} {y} x₂ → lift (≈-composite C (Functor.preserveEq G (lower x₂)) (refl-hom C)) } ;
map-← = record {
mapping = λ x→Ga → lift (D [ component ε a ∘ fmap F (lower x→Ga) ]) ;
preserveEq = λ {x′} {y} x₂ → lift (≈-composite D (refl-hom D) (Functor.preserveEq F (lower x₂))) } ;
proof = p1 , p2 } ;
natural-in-→-C = λ {x} {y} {a} {f} Fx→a → lift (begin⟨ C ⟩
C [ C [ fmap G (lower Fx→a) ∘ component η x ] ∘ f ] ≈⟨ assoc C ⟩
C [ fmap G (lower Fx→a) ∘ C [ component η x ∘ f ] ] ≈⟨ ≈-composite C (refl-hom C) (naturality η) ⟩
C [ fmap G (lower Fx→a) ∘ C [ fmap G (fmap F f) ∘ component η y ] ] ≈⟨ sym-hom C (assoc C) ⟩
C [ C [ fmap G (lower Fx→a) ∘ fmap G (fmap F f) ] ∘ component η y ] ≈⟨ ≈-composite C (sym-hom C (preserveComp G)) (refl-hom C) ⟩
C [ fmap G (D [ lower Fx→a ∘ fmap F f ]) ∘ component η y ]
∎) ;
natural-in-→-D = λ {x} {a} {b} {f} Fx→a → lift (begin⟨ C ⟩
C [ fmap G f ∘ C [ fmap G (lower Fx→a) ∘ component η x ] ] ≈⟨ sym-hom C (assoc C) ⟩
C [ C [ fmap G f ∘ fmap G (lower Fx→a) ] ∘ component η x ] ≈⟨ ≈-composite C (sym-hom C (preserveComp G)) (refl-hom C) ⟩
C [ fmap G (D [ f ∘ lower Fx→a ]) ∘ component η x ]
∎) }
where
p1 = λ {x} {a} x→Ga → lift (begin⟨ C ⟩
C [ fmap G (D [ component ε a ∘ fmap F (lower x→Ga) ]) ∘ component η x ] ≈⟨ ≈-composite C (preserveComp G) (refl-hom C) ⟩
C [ C [ fmap G (component ε a) ∘ fmap G (fmap F (lower x→Ga)) ] ∘ component η x ] ≈⟨ assoc C ⟩
C [ fmap G (component ε a) ∘ C [ fmap G (fmap F (lower x→Ga)) ∘ component η x ] ] ≈⟨ ≈-composite C (refl-hom C) (sym-hom C (naturality η)) ⟩
C [ fmap G (component ε a) ∘ C [ component η (fobj G a) ∘ (lower x→Ga) ] ] ≈⟨ sym-hom C (assoc C) ⟩
C [ C [ fmap G (component ε a) ∘ component η (fobj G a) ] ∘ (lower x→Ga) ] ≈⟨ ≈-composite C (triangularR-point {F = F} η ε {a = a} triR) (refl-hom C) ⟩
C [ id C ∘ (lower x→Ga) ] ≈⟨ leftId C ⟩
lower x→Ga
∎)
p2 = λ {x} {a} Fx→a → lift (begin⟨ D ⟩
D [ component ε a ∘ fmap F (C [ fmap G (lower Fx→a) ∘ component η x ]) ] ≈⟨ ≈-composite D (refl-hom D) (preserveComp F) ⟩
D [ component ε a ∘ D [ fmap F (fmap G (lower Fx→a)) ∘ fmap F (component η x) ] ] ≈⟨ sym-hom D (assoc D) ⟩
D [ D [ component ε a ∘ fmap F (fmap G (lower Fx→a)) ] ∘ fmap F (component η x) ] ≈⟨ ≈-composite D (naturality ε) (refl-hom D) ⟩
D [ D [ lower Fx→a ∘ component ε (fobj F x) ] ∘ fmap F (component η x) ] ≈⟨ assoc D ⟩
D [ lower Fx→a ∘ D [ component ε (fobj F x) ∘ fmap F (component η x) ] ] ≈⟨ ≈-composite D (refl-hom D) (triangularL-point {F = F} η ε {a = x} triL) ⟩
D [ lower Fx→a ∘ id D ] ≈⟨ rightId D ⟩
lower Fx→a
∎)
module Export where
_⊣_ = Adjoint
| {
"alphanum_fraction": 0.5390777339,
"avg_line_length": 70.802238806,
"ext": "agda",
"hexsha": "e398670196188d4433782086eacae070e2693e5c",
"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": "59004994acdbc65fb4f8abf0baa1777a8dbe758e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "myuon/agda-cate",
"max_forks_repo_path": "src/Adjoint.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "59004994acdbc65fb4f8abf0baa1777a8dbe758e",
"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": "myuon/agda-cate",
"max_issues_repo_path": "src/Adjoint.agda",
"max_line_length": 388,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "59004994acdbc65fb4f8abf0baa1777a8dbe758e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "myuon/agda-cate",
"max_stars_repo_path": "src/Adjoint.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-02T07:30:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-07-28T04:59:31.000Z",
"num_tokens": 8910,
"size": 18975
} |
------------------------------------------------------------------------------
-- Properties for the equality on streams
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.Stream.Equality.PropertiesATP where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.Stream.Type
open import FOTC.Relation.Binary.Bisimilarity.PropertiesATP
open import FOTC.Relation.Binary.Bisimilarity.Type
------------------------------------------------------------------------------
postulate stream-≡→≈ : ∀ {xs ys} → Stream xs → Stream ys → xs ≡ ys → xs ≈ ys
{-# ATP prove stream-≡→≈ ≈-refl #-}
-- See Issue https://github.com/asr/apia/issues/81 .
≈→Stream₁A : D → Set
≈→Stream₁A ws = ∃[ zs ] ws ≈ zs
{-# ATP definition ≈→Stream₁A #-}
≈→Stream₁ : ∀ {xs ys} → xs ≈ ys → Stream xs
≈→Stream₁ {xs} {ys} h = Stream-coind ≈→Stream₁A h' (ys , h)
where
postulate h' : ∀ {xs} → ≈→Stream₁A xs →
∃[ x' ] ∃[ xs' ] xs ≡ x' ∷ xs' ∧ ≈→Stream₁A xs'
{-# ATP prove h' #-}
-- See Issue https://github.com/asr/apia/issues/81 .
≈→Stream₂A : D → Set
≈→Stream₂A zs = ∃[ ws ] ws ≈ zs
{-# ATP definition ≈→Stream₂A #-}
≈→Stream₂ : ∀ {xs ys} → xs ≈ ys → Stream ys
≈→Stream₂ {xs} {ys} h = Stream-coind ≈→Stream₂A h' (xs , h)
where
postulate h' : ∀ {ys} → ≈→Stream₂A ys →
∃[ y' ] ∃[ ys' ] ys ≡ y' ∷ ys' ∧ ≈→Stream₂A ys'
{-# ATP prove h' #-}
≈→Stream : ∀ {xs ys} → xs ≈ ys → Stream xs ∧ Stream ys
≈→Stream {xs} {ys} h = ≈→Stream₁ h , ≈→Stream₂ h
| {
"alphanum_fraction": 0.496151569,
"avg_line_length": 34.4693877551,
"ext": "agda",
"hexsha": "c6376793fd4a1193ee17b62fd11c105e19d59bf0",
"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/FOTC/Data/Stream/Equality/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/FOTC/Data/Stream/Equality/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/FOTC/Data/Stream/Equality/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": 539,
"size": 1689
} |
{-# OPTIONS --safe #-}
module Cubical.Categories.Limits.Terminal where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Sigma
open import Cubical.Foundations.HLevels
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
private
variable
ℓ ℓ' : Level
module _ (C : Precategory ℓ ℓ') where
open Precategory C
isInitial : (x : ob) → Type (ℓ-max ℓ ℓ')
isInitial x = ∀ (y : ob) → isContr (C [ x , y ])
isFinal : (x : ob) → Type (ℓ-max ℓ ℓ')
isFinal x = ∀ (y : ob) → isContr (C [ y , x ])
hasInitialOb : Type (ℓ-max ℓ ℓ')
hasInitialOb = Σ[ x ∈ ob ] isInitial x
hasFinalOb : Type (ℓ-max ℓ ℓ')
hasFinalOb = Σ[ x ∈ ob ] isFinal x
-- Initiality of an object is a proposition.
isPropIsInitial : (x : ob) → isProp (isInitial x)
isPropIsInitial x = isPropΠ λ y → isPropIsContr
-- Objects that are initial are isomorphic.
isInitialToIso : {x y : ob} (hx : isInitial x) (hy : isInitial y) →
CatIso {C = C} x y
isInitialToIso {x = x} {y = y} hx hy =
let x→y : C [ x , y ]
x→y = fst (hx y) -- morphism forwards
y→x : C [ y , x ]
y→x = fst (hy x) -- morphism backwards
x→y→x : x→y ⋆⟨ C ⟩ y→x ≡ id x
x→y→x = isContr→isProp (hx x) _ _ -- compose to id by uniqueness
y→x→y : y→x ⋆⟨ C ⟩ x→y ≡ id y
y→x→y = isContr→isProp (hy y) _ _ -- similar.
in catiso x→y y→x y→x→y x→y→x
open isUnivalent
-- The type of initial objects of a univalent precategory is a proposition,
-- i.e. all initial objects are equal.
isPropInitial : (hC : isUnivalent C) → isProp (hasInitialOb)
isPropInitial hC x y =
-- Being initial is a prop ∴ Suffices equal as objects in C.
Σ≡Prop (isPropIsInitial)
-- C is univalent ∴ Suffices isomorphic as objects in C.
(CatIsoToPath hC (isInitialToIso (snd x) (snd y)))
-- Now the dual argument for final objects.
-- Finality of an object is a proposition.
isPropIsFinal : (x : ob) → isProp (isFinal x)
isPropIsFinal x = isPropΠ λ y → isPropIsContr
-- Objects that are initial are isomorphic.
isFinalToIso : {x y : ob} (hx : isFinal x) (hy : isFinal y) →
CatIso {C = C} x y
isFinalToIso {x = x} {y = y} hx hy =
let x→y : C [ x , y ]
x→y = fst (hy x) -- morphism forwards
y→x : C [ y , x ]
y→x = fst (hx y) -- morphism backwards
x→y→x : x→y ⋆⟨ C ⟩ y→x ≡ id x
x→y→x = isContr→isProp (hx x) _ _ -- compose to id by uniqueness
y→x→y : y→x ⋆⟨ C ⟩ x→y ≡ id y
y→x→y = isContr→isProp (hy y) _ _ -- similar.
in catiso x→y y→x y→x→y x→y→x
-- The type of final objects of a univalent precategory is a proposition,
-- i.e. all final objects are equal.
isPropFinal : (hC : isUnivalent C) → isProp (hasFinalOb)
isPropFinal hC x y =
-- Being final is a prop ∴ Suffices equal as objects in C.
Σ≡Prop (isPropIsFinal)
-- C is univalent ∴ Suffices isomorphic as objects in C.
(CatIsoToPath hC (isFinalToIso (snd x) (snd y)))
| {
"alphanum_fraction": 0.6125041792,
"avg_line_length": 34.3793103448,
"ext": "agda",
"hexsha": "26a933671c1565948872793c4b56f8a4c07f4431",
"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": "0f4d9b6abc83e5c5bd0dbf21f9de1e8644acf282",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "kl-i/cubical-0.4",
"max_forks_repo_path": "Cubical/Categories/Limits/Terminal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0f4d9b6abc83e5c5bd0dbf21f9de1e8644acf282",
"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": "kl-i/cubical-0.4",
"max_issues_repo_path": "Cubical/Categories/Limits/Terminal.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0f4d9b6abc83e5c5bd0dbf21f9de1e8644acf282",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "kl-i/cubical-0.4",
"max_stars_repo_path": "Cubical/Categories/Limits/Terminal.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1083,
"size": 2991
} |
-- Andreas, 2017-01-13, issue #2403
open import Common.Nat
postulate
P : Nat → Set
f : ∀{n} → P n → P (pred n)
test : ∀ n → P n → Set
test zero p = Nat
test (suc n) p = test _ (f p)
-- WAS:
-- The meta-variable is solved to (pred (suc n))
-- Termination checking fails.
-- NOW: If the termination checker normalizes the argument and it passes.
| {
"alphanum_fraction": 0.6320224719,
"avg_line_length": 19.7777777778,
"ext": "agda",
"hexsha": "38258479c8eeaa4f974c80d2e97ba56803c99fa6",
"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/Issue2403.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/Issue2403.agda",
"max_line_length": 73,
"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/Issue2403.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": 117,
"size": 356
} |
module VecSN where
open import Data.Bool
infixr 20 _◎_
------------------------------------------------------------------------------
-- fix a field F_3 = {0, 1, -1}
-- types B (ZERO,ONE,PLUS,TIMES) determine the DIMENSION of a vector space over F_3
-- values of type B are INDICES for B-dimensional vectors
-- we do not allow superpositions (we have AT MOST one entry in the
-- vector that is non-zero), so we can identify the INDICES with the vectors
--
-- in particular:
-- - ZERO is not the empty type! it is like the 0-dimensional vector space
-- (i.e, the type containing one "annihilating value")
-- - ONE is like a 1-dimensional vector space; it is isomorphic to
-- the scalars (0,+1,-1)
-- - PLUS gives the direct sum of vector spaces (dimension is the sum)
-- - TIMES gives the tensor product of vector spaces (dimension is the product)
-- - DUAL gives the dual space (functionals that map vectors to scalars; i.e.
-- that maps values to scalars)
data B : Set where
ZERO : B
ONE : B
PLUS : B → B → B
TIMES : B → B → B
DUAL : B → B
-- now we describe the vectors for each B-dimensional vector space
-- the zero vector is everywhere
data BVAL : B → Set where
zero : {b : B} → BVAL b
unit : BVAL ONE
left : {b₁ b₂ : B} → BVAL b₁ → BVAL (PLUS b₁ b₂)
right : {b₁ b₂ : B} → BVAL b₂ → BVAL (PLUS b₁ b₂)
pair : {b₁ b₂ : B} → BVAL b₁ → BVAL b₂ → BVAL (TIMES b₁ b₂)
dual : {b : B} → BVAL b → BVAL (DUAL b)
-- syntactic equality on vectors
b= : { b : B } → BVAL b → BVAL b → Bool
b= zero zero = true
b= unit unit = true
b= (left v₁) (left v₂) = b= v₁ v₂
b= (right v₁) (right v₂) = b= v₁ v₂
b= (pair v₁ v₂) (pair v₁' v₂') = b= v₁ v₁' ∧ b= v₂ v₂'
b= (dual v₁) (dual v₂) = b= v₁ v₂
b= _ _ = false
data Iso : B → B → Set where
-- (+,0) commutative monoid
unite₊ : { b : B } → Iso (PLUS ZERO b) b
uniti₊ : { b : B } → Iso b (PLUS ZERO b)
swap₊ : { b₁ b₂ : B } → Iso (PLUS b₁ b₂) (PLUS b₂ b₁)
assocl₊ : { b₁ b₂ b₃ : B } → Iso (PLUS b₁ (PLUS b₂ b₃)) (PLUS (PLUS b₁ b₂) b₃)
assocr₊ : { b₁ b₂ b₃ : B } → Iso (PLUS (PLUS b₁ b₂) b₃) (PLUS b₁ (PLUS b₂ b₃))
-- (*,1) commutative monoid
unite⋆ : { b : B } → Iso (TIMES ONE b) b
uniti⋆ : { b : B } → Iso b (TIMES ONE b)
swap⋆ : { b₁ b₂ : B } → Iso (TIMES b₁ b₂) (TIMES b₂ b₁)
assocl⋆ : { b₁ b₂ b₃ : B } → Iso (TIMES b₁ (TIMES b₂ b₃)) (TIMES (TIMES b₁ b₂) b₃)
assocr⋆ : { b₁ b₂ b₃ : B } → Iso (TIMES (TIMES b₁ b₂) b₃) (TIMES b₁ (TIMES b₂ b₃))
-- * distributes over +
dist : { b₁ b₂ b₃ : B } →
Iso (TIMES (PLUS b₁ b₂) b₃) (PLUS (TIMES b₁ b₃) (TIMES b₂ b₃))
factor : { b₁ b₂ b₃ : B } →
Iso (PLUS (TIMES b₁ b₃) (TIMES b₂ b₃)) (TIMES (PLUS b₁ b₂) b₃)
-- closure
id⟷ : { b : B } → Iso b b
sym : { b₁ b₂ : B } → Iso b₁ b₂ → Iso b₂ b₁
_◎_ : { b₁ b₂ b₃ : B } → Iso b₁ b₂ → Iso b₂ b₃ → Iso b₁ b₃
_⊕_ : { b₁ b₂ b₃ b₄ : B } →
Iso b₁ b₃ → Iso b₂ b₄ → Iso (PLUS b₁ b₂) (PLUS b₃ b₄)
_⊗_ : { b₁ b₂ b₃ b₄ : B } →
Iso b₁ b₃ → Iso b₂ b₄ → Iso (TIMES b₁ b₂) (TIMES b₃ b₄)
-- multiplicative duality
refe⋆ : { b : B } → Iso (DUAL (DUAL b)) b
refi⋆ : { b : B } → Iso b (DUAL (DUAL b))
rile⋆ : { b : B } → Iso (TIMES b (TIMES b (DUAL b))) b
rili⋆ : { b : B } → Iso b (TIMES b (TIMES b (DUAL b)))
-- negatives: we have a circuit that requires the value to choose
-- the incoming value : b₁ can go left or right
choose : { b₁ b₂ : B } → Iso b₁ b₂ → Iso b₁ b₂ → Iso b₁ b₂
mutual
eval : {b₁ b₂ : B} → Iso b₁ b₂ → BVAL b₁ → BVAL b₂
eval unite₊ (left _) = zero
eval unite₊ (right v) = v
eval uniti₊ v = right v
eval swap₊ (left v) = right v
eval swap₊ (right v) = left v
eval assocl₊ (left v) = left (left v)
eval assocl₊ (right (left v)) = left (right v)
eval assocl₊ (right (right v)) = right v
eval assocr₊ (left (left v)) = left v
eval assocr₊ (left (right v)) = right (left v)
eval assocr₊ (right v) = right (right v)
eval unite⋆ (pair unit v) = v
eval uniti⋆ v = pair unit v
eval swap⋆ (pair v1 v2) = pair v2 v1
eval assocl⋆ (pair v1 (pair v2 v3)) = pair (pair v1 v2) v3
eval assocr⋆ (pair (pair v1 v2) v3) = pair v1 (pair v2 v3)
eval dist (pair (left v1) v3) = left (pair v1 v3)
eval dist (pair (right v2) v3) = right (pair v2 v3)
eval factor (left (pair v1 v3)) = pair (left v1) v3
eval factor (right (pair v2 v3)) = pair (right v2) v3
eval id⟷ v = v
eval (sym c) v = evalB c v
eval (c₁ ◎ c₂) v = eval c₂ (eval c₁ v)
eval (c₁ ⊕ c₂) (left v) = left (eval c₁ v)
eval (c₁ ⊕ c₂) (right v) = right (eval c₂ v)
eval (c₁ ⊗ c₂) (pair v₁ v₂) = pair (eval c₁ v₁) (eval c₂ v₂)
eval refe⋆ (dual (dual v)) = v
eval refi⋆ v = dual (dual v)
eval rile⋆ (pair v (pair v₁ (dual v₂))) with b= v₁ v₂
eval rile⋆ (pair v (pair v₁ (dual v₂))) | true = v
eval rile⋆ (pair v (pair v₁ (dual v₂))) | false = zero
eval rili⋆ v = pair v (pair v (dual v))
-- choose : { b₁ b₂ : B } → Iso b₁ b₂ → Iso b₁ b₂ → Iso b₁ b₂
eval (choose c₁ c₂) v = {!!}
eval _ _ = zero
evalB : {b₁ b₂ : B} → Iso b₁ b₂ → BVAL b₂ → BVAL b₁
evalB unite₊ v = right v
evalB uniti₊ (left _) = zero
evalB uniti₊ (right v) = v
evalB swap₊ (left v) = right v
evalB swap₊ (right v) = left v
evalB assocl₊ (left (left v)) = left v
evalB assocl₊ (left (right v)) = right (left v)
evalB assocl₊ (right v) = right (right v)
evalB assocr₊ (left v) = left (left v)
evalB assocr₊ (right (left v)) = left (right v)
evalB assocr₊ (right (right v)) = right v
evalB unite⋆ v = pair unit v
evalB uniti⋆ (pair unit v) = v
evalB swap⋆ (pair v1 v2) = pair v2 v1
evalB assocl⋆ (pair (pair v1 v2) v3) = pair v1 (pair v2 v3)
evalB assocr⋆ (pair v1 (pair v2 v3)) = pair (pair v1 v2) v3
evalB dist (left (pair v1 v3)) = pair (left v1) v3
evalB dist (right (pair v2 v3)) = pair (right v2) v3
evalB factor (pair (left v1) v3) = left (pair v1 v3)
evalB factor (pair (right v2) v3) = right (pair v2 v3)
evalB id⟷ v = v
evalB (sym c) v = eval c v
evalB (c₁ ◎ c₂) v = evalB c₁ (evalB c₂ v)
evalB (c₁ ⊕ c₂) (left v) = left (evalB c₁ v)
evalB (c₁ ⊕ c₂) (right v) = right (evalB c₂ v)
evalB (c₁ ⊗ c₂) (pair v₁ v₂) = pair (evalB c₁ v₁) (evalB c₂ v₂)
evalB refe⋆ v = dual (dual v)
evalB refi⋆ (dual (dual v)) = v
evalB rile⋆ v = pair v (pair v (dual v))
evalB rili⋆ (pair v (pair v₁ (dual v₂))) with b= v₁ v₂
evalB rili⋆ (pair v (pair v₁ (dual v₂))) | true = v
evalB rili⋆ (pair v (pair v₁ (dual v₂))) | false = zero
evalB _ _ = zero
------------------------------------------------------------------------------
-- example with duals
pibool : B
pibool = PLUS ONE ONE
pitrue : BVAL pibool
pitrue = left unit
pifalse : BVAL pibool
pifalse = right unit
-- swap clause 1 = (T => F)
clause1 : BVAL (TIMES (DUAL pibool) pibool)
clause1 = pair (dual pitrue) pifalse
-- swap clause 2 = (F => T)
clause2 : BVAL (TIMES (DUAL pibool) pibool)
clause2 = pair (dual pifalse) pitrue
-- swap clause 1 applied to true
ex1 : BVAL (TIMES pibool (TIMES (DUAL pibool) pibool))
ex1 = pair pitrue clause1
-- swap clause 1 applied to false
ex2 : BVAL (TIMES pibool (TIMES (DUAL pibool) pibool))
ex2 = pair pifalse clause1
-- swap clause 1 applied to true
ex3 : BVAL (TIMES pibool (TIMES (DUAL pibool) pibool))
ex3 = pair pitrue clause2
-- swap clause 1 applied to false
ex4 : BVAL (TIMES pibool (TIMES (DUAL pibool) pibool))
ex4 = pair pifalse clause2
-- applies one of the clauses to a value
c : Iso (TIMES pibool (TIMES (DUAL pibool) pibool)) pibool
c = -- (v,(1/t,f))
assocl⋆ ◎ -- ((v,1/t),f)
swap⋆ ◎ -- (f,(v,1/t))
rile⋆ -- f or zero
--
v1 = eval c ex1
v2 = eval c ex2
v3 = eval c ex3
v4 = eval c ex4
-- generalize
-- applies one of the clauses of a function : b -> b to a value : b
apply : {b : B} → Iso (TIMES b (TIMES (DUAL b) b)) b
apply = assocl⋆ ◎ swap⋆ ◎ rile⋆
{--
want:
value is True
in parallel apply clause1 to value and apply clause2 to value
one of these will return False and the other will return zero
merge the results to get False
better:
value is True
we create a new logic variable ALPHA which can be unified with either clause1 or clause2
we create a value (ALPHA - ALPHA) which we apply to evaluate
--}
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.5682004449,
"avg_line_length": 36.0379746835,
"ext": "agda",
"hexsha": "7fa1bf113127a7b2c5ae5617b730614ab48613ff",
"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": "agda/VecSN.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": "agda/VecSN.agda",
"max_line_length": 89,
"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": "agda/VecSN.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": 3418,
"size": 8541
} |
{-# OPTIONS --without-K --safe #-}
module Polynomial.Simple.AlmostCommutativeRing.Instances where
open import Polynomial.Simple.AlmostCommutativeRing
open import Level using (0ℓ)
open import Agda.Builtin.Reflection
module Nat where
open import Data.Nat using (zero; suc)
open import Relation.Binary.PropositionalEquality using (refl)
open import Data.Nat.Properties using (*-+-commutativeSemiring)
open import Data.Maybe using (just; nothing)
ring : AlmostCommutativeRing 0ℓ 0ℓ
ring =
fromCommutativeSemiring
*-+-commutativeSemiring
λ { zero → just refl; _ → nothing }
module Reflection where
open import Polynomial.Simple.Reflection using (solveOver-macro)
open import Data.Unit using (⊤)
macro
∀⟨_⟩ : Term → Term → TC ⊤
∀⟨ n ⟩ = solveOver-macro n (quote ring)
module Int where
open import Data.Nat using (zero)
open import Data.Integer using (+_)
open import Data.Integer.Properties using(+-*-commutativeRing)
open import Data.Maybe using (just; nothing)
open import Relation.Binary.PropositionalEquality using (refl)
ring : AlmostCommutativeRing 0ℓ 0ℓ
ring =
fromCommutativeRing
+-*-commutativeRing
λ { (+ zero) → just refl; _ → nothing }
module Reflection where
open import Polynomial.Simple.Reflection using (solveOver-macro)
open import Data.Unit using (⊤)
macro
∀⟨_⟩ : Term → Term → TC ⊤
∀⟨ n ⟩ = solveOver-macro n (quote ring)
| {
"alphanum_fraction": 0.7079037801,
"avg_line_length": 29.693877551,
"ext": "agda",
"hexsha": "ee1ee97f7b8d18842da8b3b6968138fb53ac177e",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-20T07:07:11.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-04-16T02:23:16.000Z",
"max_forks_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mckeankylej/agda-ring-solver",
"max_forks_repo_path": "src/Polynomial/Simple/AlmostCommutativeRing/Instances.agda",
"max_issues_count": 5,
"max_issues_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T01:55:42.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-17T20:48:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mckeankylej/agda-ring-solver",
"max_issues_repo_path": "src/Polynomial/Simple/AlmostCommutativeRing/Instances.agda",
"max_line_length": 68,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "f18d9c6bdfae5b4c3ead9a83e06f16a0b7204500",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mckeankylej/agda-ring-solver",
"max_stars_repo_path": "src/Polynomial/Simple/AlmostCommutativeRing/Instances.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-15T00:57:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-01-25T16:40:52.000Z",
"num_tokens": 396,
"size": 1455
} |
{-# OPTIONS --safe #-}
module Issue2487.b where
-- trying to import a cubical, non-safe module
open import Issue2487.c
| {
"alphanum_fraction": 0.725,
"avg_line_length": 20,
"ext": "agda",
"hexsha": "6ab8aaf100c288676b10724913c7a4de6cdc2140",
"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": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/Issue2487/b.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"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": "hborum/agda",
"max_issues_repo_path": "test/Fail/Issue2487/b.agda",
"max_line_length": 46,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Fail/Issue2487/b.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": 31,
"size": 120
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.