Search is not available for this dataset
text
string | meta
dict |
---|---|
-- Andreas, 2019-03-27
-- Do not run checkIApplyConfluence unless --cubical
-- The following verbosity options triggers a crash
-- in case checkIApplyConfluence_ runs.
-- {-# OPTIONS --cubical #-} -- Trigges the crash.
{-# OPTIONS -v tc.cover.iapply.confluence.crash:666 #-} -- Activate crashing program point.
open import Agda.Builtin.Nat
-- A harmless definition.
id : Nat → Nat
id zero = zero
id (suc x) = suc (id x)
-- Should succeed.
| {
"alphanum_fraction": 0.6940133038,
"avg_line_length": 22.55,
"ext": "agda",
"hexsha": "e8a8a078947c70ec4f71e9ae11906fbcbeb2ff3b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/CheckIApplyConfluenceOnlyWhenCubical.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/CheckIApplyConfluenceOnlyWhenCubical.agda",
"max_line_length": 92,
"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/CheckIApplyConfluenceOnlyWhenCubical.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": 129,
"size": 451
} |
{-# OPTIONS --without-K --safe #-}
module Util.Data.Product where
open import Data.Product public hiding (map₂)
map₂ : ∀ {α β γ} {A : Set α} {B : A → Set β} {C : A → Set γ}
→ (∀ a → B a → C a)
→ Σ A B → Σ A C
map₂ f (a , b) = a , f a b
| {
"alphanum_fraction": 0.5267489712,
"avg_line_length": 22.0909090909,
"ext": "agda",
"hexsha": "e4e4ad45b38900a72606824b6099a8ada7f5f569",
"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/Util/Data/Product.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/Util/Data/Product.agda",
"max_line_length": 60,
"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/Util/Data/Product.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": 94,
"size": 243
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.Strict2Group.Explicit.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Group.Base
open import Cubical.Data.Strict2Group.Explicit.Notation
record Strict2GroupExp ℓ : Type (ℓ-suc ℓ) where
constructor strict2groupexp
field
-- a group of objects and a group of morphisms
C₀ : Group ℓ
C₁ : Group ℓ
-- source and target morphisms
s : morph C₁ C₀
t : morph C₁ C₀
-- identity morphism
i : morph C₀ C₁
-- the composition map C₁×₀C₁→C₁
∘ : (g f : Group.type C₁) → (s .fst) g ≡ (t .fst f) → Group.type C₁
open S2GBaseNotation C₀ C₁ s t i ∘
field
si : (x : TC₀) → src (id x) ≡ x
ti : (x : TC₀) → tar (id x) ≡ x
s∘ : (g f : TC₁) → (c : CohCond g f) → src (∘ g f c) ≡ src f
t∘ : (g f : TC₁) → (c : CohCond g f) → tar (∘ g f c) ≡ tar g
-- composition operation defines a homomorphism that is associative and unital w.r.t. i
isMorph∘ : ∀ {g f g' f' : TC₁} (c : CohCond g f) (c' : CohCond g' f')
→ ∘ (g ∙₁ g') (f ∙₁ f') (∙c c c') ≡ (∘ g f c) ∙₁ (∘ g' f' c')
assoc∘ : ∀ {h g f : TC₁} → (c1 : CohCond g f) → (c2 : CohCond h g)
→ ∘ (∘ h g c2) f ((s∘ h g c2) ∙ c1) ≡ ∘ h (∘ g f c1) (c2 ∙ (sym (t∘ g f c1)))
lUnit∘ : (f : TC₁) → ∘ (id (tar f)) f (si (tar f)) ≡ f
rUnit∘ : (f : TC₁) → ∘ f (id (src f)) (sym (ti (src f))) ≡ f
| {
"alphanum_fraction": 0.5478073329,
"avg_line_length": 31.6136363636,
"ext": "agda",
"hexsha": "b4a89a64e4c7d2a9a2d789c3ada0a9f376b1e933",
"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/Data/Strict2Group/Explicit/Base.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/Data/Strict2Group/Explicit/Base.agda",
"max_line_length": 91,
"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/Data/Strict2Group/Explicit/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 590,
"size": 1391
} |
------------------------------------------------------------------------
-- An example showing that transitivity-like proofs that are not
-- size-preserving can sometimes be used in a compositional way
------------------------------------------------------------------------
-- One can use the technique from "Beating the Productivity Checker
-- Using Embedded Languages" to make it possible to use
-- transitivity-like proofs that are not size-preserving in
-- corecursive definitions. However, it is unclear if this is ever
-- useful: the example presented below is rather contrived.
{-# OPTIONS --sized-types #-}
open import Prelude
module Delay-monad.Bisimilarity.Transitivity-constructor
{a} {A : Type a} where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude.Size
open import Function-universe equality-with-J hiding (Kind)
open import Delay-monad
open import Delay-monad.Bisimilarity hiding (never≉now)
open import Delay-monad.Bisimilarity.Negative
------------------------------------------------------------------------
-- Proof programs
-- There are two kinds of proof "programs", corresponding to strong
-- and weak bisimilarity.
data Kind : Type where
strong weak : Kind
mutual
-- Proof "programs".
data Prog (i : Size) : Kind → Delay A ∞ → Delay A ∞ → Type a where
-- Congruences.
now : ∀ {k x} → Prog i k (now x) (now x)
later : ∀ {k x y} →
Prog′ i k (force x) (force y) →
Prog i k (later x) (later y)
-- Weak bisimilarity.
laterʳ : ∀ {x y} → Prog i weak x (force y) → Prog i weak x (later y)
laterˡ : ∀ {x y} → Prog i weak (force x) y → Prog i weak (later x) y
-- Equational reasoning.
--
-- Note that if A is inhabited, then there is no size-preserving
-- transitivity-like proof taking strong bisimilarity and weak
-- bisimilarity to weak bisimilarity (see
-- Delay-monad.Bisimilarity.Negative.size-preserving-transitivity-∼≈ˡ⇔uninhabited).
reflP : ∀ {k} x → Prog i k x x
symP : ∀ {k x y} → Prog i k x y → Prog i k y x
transP : ∀ {k x y z} →
Prog i strong x y → Prog i k y z → Prog i k x z
record Prog′ (i : Size) (k : Kind) (x y : Delay A ∞) : Type a where
coinductive
field
force : {j : Size< i} → Prog j k x y
open Prog′ public
------------------------------------------------------------------------
-- Completeness
-- Proof programs are complete with respect to strong and weak
-- bisimilarity. Note that these proofs are size-preserving.
complete-strong : ∀ {i x y} →
[ i ] x ∼ y → Prog i strong x y
complete-strong now = now
complete-strong (later p) =
later λ { .force → complete-strong (force p) }
complete-weak : ∀ {i x y} → [ i ] x ≈ y → Prog i weak x y
complete-weak now = now
complete-weak (laterʳ p) = laterʳ (complete-weak p)
complete-weak (laterˡ p) = laterˡ (complete-weak p)
complete-weak (later p) =
later λ { .force → complete-weak (force p) }
------------------------------------------------------------------------
-- Soundness
-- Proof WHNFs.
data WHNF (i : Size) : Kind → Delay A ∞ → Delay A ∞ → Type a where
now : ∀ {k x} → WHNF i k (now x) (now x)
later : ∀ {k x y} →
Prog′ i k (force x) (force y) →
WHNF i k (later x) (later y)
laterʳ : ∀ {x y} →
WHNF i weak x (force y) → WHNF i weak x (later y)
laterˡ : ∀ {x y} →
WHNF i weak (force x) y → WHNF i weak (later x) y
-- Reflexivity.
reflW : ∀ {i k} x → WHNF i k x x
reflW (now x) = now
reflW (later x) = later λ { .force → reflP (force x) }
-- Symmetry.
symW : ∀ {i k x y} → WHNF i k x y → WHNF i k y x
symW now = now
symW (later p) = later λ { .force → symP (force p) }
symW (laterʳ p) = laterˡ (symW p)
symW (laterˡ p) = laterʳ (symW p)
-- Transitivity for strong WHNFs.
trans∼∼W : ∀ {i x y z} →
WHNF i strong x y → WHNF i strong y z → WHNF i strong x z
trans∼∼W now q = q
trans∼∼W (later p) (later q) =
later λ { .force → transP (force p) (force q) }
-- Strong equality programs can be turned into WHNFs.
whnf∼ : ∀ {i x y} → Prog i strong x y → WHNF i strong x y
whnf∼ now = now
whnf∼ (later p) = later p
whnf∼ (reflP x) = reflW x
whnf∼ (symP p) = symW (whnf∼ p)
whnf∼ (transP p q) = trans∼∼W (whnf∼ p) (whnf∼ q)
-- Strong proof programs are sound with respect to strong
-- bisimilarity. Note that these proofs are size-preserving.
mutual
sound-strong : ∀ {i x y} →
Prog i strong x y → [ i ] x ∼ y
sound-strong p = soundW-strong (whnf∼ p)
soundW-strong : ∀ {i x y} →
WHNF i strong x y → [ i ] x ∼ y
soundW-strong now = now
soundW-strong (later p) =
later λ { .force → sound-strong (force p) }
-- Another transitivity lemma. This lemma cannot, in general, be made
-- fully size-preserving (see not-fully-size-preserving below).
trans∼-W : ∀ {i k x y z} →
WHNF ∞ strong x y → WHNF i k y z → WHNF i k x z
trans∼-W now q = q
trans∼-W p (laterʳ q) = laterʳ (trans∼-W p q)
trans∼-W (later p) (laterˡ q) = laterˡ (trans∼-W (whnf∼ (force p)) q)
trans∼-W (later p) (later q) =
later λ { .force → transP (force p) (force q) }
-- All fully defined programs can be turned into WHNFs.
whnf : ∀ {i k x y} → Prog ∞ k x y → WHNF i k x y
whnf now = now
whnf (later p) = later p
whnf (laterʳ p) = laterʳ (whnf p)
whnf (laterˡ p) = laterˡ (whnf p)
whnf (reflP x) = reflW x
whnf (symP p) = symW (whnf p)
whnf (transP p q) = trans∼-W (whnf p) (whnf q)
-- Weak proof programs are sound with respect to weak bisimilarity.
-- Note that these proofs are /not/ guaranteed to be size-preserving.
mutual
sound-weak : ∀ {i x y} → Prog ∞ weak x y → [ i ] x ≈ y
sound-weak p = soundW-weak (whnf p)
soundW-weak : ∀ {i x y} → WHNF ∞ weak x y → [ i ] x ≈ y
soundW-weak now = now
soundW-weak (laterʳ p) = laterʳ (soundW-weak p)
soundW-weak (laterˡ p) = laterˡ (soundW-weak p)
soundW-weak (later p) =
later λ { .force → sound-weak (force p) }
------------------------------------------------------------------------
-- Some negative results
-- The soundness proof for weak proof programs can be made
-- size-preserving iff A is uninhabited.
size-preserving⇔uninhabited :
(∀ {i x y} → Prog i weak x y → [ i ] x ≈ y) ⇔ ¬ A
size-preserving⇔uninhabited = record
{ to = (∀ {i x y} → Prog i weak x y → [ i ] x ≈ y) ↝⟨ (λ sound p q → sound (transP (complete-strong p) (complete-weak q))) ⟩
Transitivity-∼≈ˡ ↝⟨ _⇔_.to size-preserving-transitivity-∼≈ˡ⇔uninhabited ⟩□
¬ A □
; from = ¬ A ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _} _ → trivial _ _) ⟩□
(∀ {i x y} → Prog i weak x y → [ i ] x ≈ y) □
}
-- The lemma trans∼-W cannot be made fully size-preserving (assuming
-- that A is inhabited).
not-fully-size-preserving :
(∀ {i k x y z} →
WHNF i strong x y → WHNF i k y z → WHNF i k x z) →
¬ A
not-fully-size-preserving trans x = contradiction ∞
where
never≉now : ∀ {i} → ¬ WHNF i weak never (now x)
never≉now (laterˡ p) = never≉now p
mutual
never≈now : ∀ {i} → WHNF i weak never (now x)
never≈now =
trans (later {y = record { force = now x }} never∼now)
(laterˡ now)
never∼now : ∀ {i} → Prog′ i strong never (now x)
force never∼now {j = j} = ⊥-elim (contradiction j)
contradiction : Size → ⊥
contradiction i = never≉now (never≈now {i = i})
-- One might wonder why the counterexample above cannot be adapted so
-- that it also applies to programs, for which a size-preserving
-- transitivity constructor exists. The following lemma documents one
-- attempt at adapting the counterexample. Note that the new
-- counterexample is based on the assumption that one can convert a
-- strong bisimilarity program /of any size/ relating never and x to a
-- proof that x is /equal/ to never.
partially-adapted-counterexample :
(∀ {i x} → Prog i strong never x → x ≡ never) →
¬ A
partially-adapted-counterexample convert x = contradiction ∞
where
mutual
now∼→≡now : ∀ {i x y} → Prog i strong (now x) y → y ≡ now x
now∼→≡now now = refl
now∼→≡now (reflP _) = refl
now∼→≡now (symP p) = ∼now→≡now p
now∼→≡now (transP p q) rewrite now∼→≡now p = now∼→≡now q
∼now→≡now : ∀ {i x y} → Prog i strong x (now y) → x ≡ now y
∼now→≡now now = refl
∼now→≡now (reflP _) = refl
∼now→≡now (symP p) = now∼→≡now p
∼now→≡now (transP p q) rewrite ∼now→≡now q = ∼now→≡now p
mutual
now≉Pnever : ∀ {i} → ¬ Prog i weak (now x) never
now≉Pnever (laterʳ p) = now≉Pnever p
now≉Pnever (symP p) = never≉Pnow p
now≉Pnever (transP p q) rewrite now∼→≡now p = now≉Pnever q
never≉Pnow : ∀ {i} → ¬ Prog i weak never (now x)
never≉Pnow (laterˡ p) = never≉Pnow p
never≉Pnow (symP p) = now≉Pnever p
never≉Pnow (transP p q) rewrite convert p = never≉Pnow q
mutual
never≈Pnow : ∀ {i} → Prog i weak never (now x)
never≈Pnow =
transP (later {y = record { force = now x }} never∼Pnow)
(laterˡ now)
never∼Pnow : ∀ {i} → Prog′ i strong never (now x)
force never∼Pnow {j = j} = ⊥-elim (contradiction j)
contradiction : Size → ⊥
contradiction i = never≉Pnow (never≈Pnow {i = i})
------------------------------------------------------------------------
-- A contrived example
-- Note the use of a strong bisimilarity program of size i as the
-- first argument to transitivity in the following example; this is
-- not supported by transitive-∼ˡ, which requires the first argument
-- to have size ∞.
exampleP : ∀ {i} → Prog i weak never never
exampleP {i} =
transP (reflP {i = i} never) (later λ { .force → exampleP })
example : ∀ {i} → [ i ] never ≈ never
example = sound-weak exampleP
-- However, note that the first argument could just as well have been
-- given the size ∞, in which case transitive-∼ˡ works:
counterargument : ∀ {i} → [ i ] never ≈ never {A = A}
counterargument =
transitive-∼ˡ (reflexive never)
(later λ { .force → counterargument })
-- Are there any applications in which strong and weak bisimilarities
-- are proved simultaneously? One can observe that, if the first
-- argument is never, then weak bisimilarity is contained in strong
-- (in a size-preserving way), as witnessed by →∼-neverˡ. Perhaps one
-- can find some compelling application of the technique presented
-- above if it can be combined with a lemma like →∼-neverˡ. However,
-- it is unclear if such a combination is possible: the soundness
-- proof above relies on the fact that strong bisimilarity programs
-- contain no weak bisimilarity programs (in particular, no
-- transitivity proofs with a weak bisimilarity as the second
-- argument).
| {
"alphanum_fraction": 0.5845274805,
"avg_line_length": 34.3489096573,
"ext": "agda",
"hexsha": "cd1b21c0dd61332b3efe5ee686ae116fca62b6e9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/delay-monad",
"max_forks_repo_path": "src/Delay-monad/Bisimilarity/Transitivity-constructor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/delay-monad",
"max_issues_repo_path": "src/Delay-monad/Bisimilarity/Transitivity-constructor.agda",
"max_line_length": 129,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/delay-monad",
"max_stars_repo_path": "src/Delay-monad/Bisimilarity/Transitivity-constructor.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3594,
"size": 11026
} |
{-# OPTIONS --without-K --exact-split #-}
module 10-truncation-levels where
import 09-fundamental-theorem
open 09-fundamental-theorem public
-- Section 8.1 Propositions
is-prop :
{i : Level} (A : UU i) → UU i
is-prop A = (x y : A) → is-contr (Id x y)
{- We introduce the universe of all propositions. -}
UU-Prop :
(l : Level) → UU (lsuc l)
UU-Prop l = Σ (UU l) is-prop
type-Prop :
{l : Level} → UU-Prop l → UU l
type-Prop P = pr1 P
is-prop-type-Prop :
{l : Level} (P : UU-Prop l) → is-prop (type-Prop P)
is-prop-type-Prop P = pr2 P
{- The empty type is a proposition. -}
abstract
is-prop-empty : is-prop empty
is-prop-empty ()
abstract
is-prop-unit : is-prop unit
is-prop-unit = is-prop-is-contr is-contr-unit
unit-Prop : UU-Prop lzero
unit-Prop = pair unit is-prop-unit
is-prop' :
{i : Level} (A : UU i) → UU i
is-prop' A = (x y : A) → Id x y
abstract
is-prop-is-prop' :
{i : Level} {A : UU i} → is-prop' A → is-prop A
is-prop-is-prop' {i} {A} H x y =
pair
( (inv (H x x)) ∙ (H x y))
( ind-Id x
( λ z p → Id ((inv (H x x)) ∙ (H x z)) p)
( left-inv (H x x)) y)
abstract
is-prop'-is-prop :
{i : Level} {A : UU i} → is-prop A → is-prop' A
is-prop'-is-prop H x y = pr1 (H x y)
abstract
is-contr-is-prop-inh :
{i : Level} {A : UU i} → is-prop A → A → is-contr A
is-contr-is-prop-inh H a = pair a (is-prop'-is-prop H a)
abstract
is-prop-is-contr-if-inh :
{i : Level} {A : UU i} → (A → is-contr A) → is-prop A
is-prop-is-contr-if-inh H x y = is-prop-is-contr (H x) x y
is-subtype :
{i j : Level} {A : UU i} (B : A → UU j) → UU (i ⊔ j)
is-subtype B = (x : _) → is-prop (B x)
double-structure-swap :
{l1 l2 l3 : Level} (A : UU l1) (B : A → UU l2) (C : A → UU l3) →
Σ (Σ A B) (λ t → C (pr1 t)) → Σ (Σ A C) (λ t → B (pr1 t))
double-structure-swap A B C (pair (pair a b) c) = (pair (pair a c) b)
htpy-double-structure-swap :
{l1 l2 l3 : Level} (A : UU l1) (B : A → UU l2) (C : A → UU l3) →
((double-structure-swap A C B) ∘ (double-structure-swap A B C)) ~ id
htpy-double-structure-swap A B C (pair (pair a b) c) =
eq-pair (eq-pair refl refl) refl
is-equiv-double-structure-swap :
{l1 l2 l3 : Level} (A : UU l1) (B : A → UU l2) (C : A → UU l3) →
is-equiv (double-structure-swap A B C)
is-equiv-double-structure-swap A B C =
is-equiv-has-inverse
( double-structure-swap A C B)
( htpy-double-structure-swap A C B)
( htpy-double-structure-swap A B C)
{- The following is a general construction that will help us show that
the identity type of a subtype agrees with the identity type of the
original type. We already know that the first projection of a family of
propositions is an embedding, but the following lemma still has its uses. -}
abstract
is-contr-total-Eq-substructure :
{l1 l2 l3 : Level} {A : UU l1} {B : A → UU l2} {P : A → UU l3} →
is-contr (Σ A B) → (is-subtype P) → (a : A) (b : B a) (p : P a) →
is-contr (Σ (Σ A P) (λ t → B (pr1 t)))
is-contr-total-Eq-substructure {A = A} {B} {P}
is-contr-AB is-subtype-P a b p =
is-contr-is-equiv
( Σ (Σ A B) (λ t → P (pr1 t)))
( double-structure-swap A P B)
( is-equiv-double-structure-swap A P B)
( is-contr-is-equiv'
( P a)
( left-unit-law-Σ-map-gen (λ t → P (pr1 t)) is-contr-AB (pair a b))
( is-equiv-left-unit-law-Σ-map-gen _ is-contr-AB (pair a b))
( is-contr-is-prop-inh (is-subtype-P a) p))
Eq-total-subtype :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} → is-subtype B →
(Σ A B) → (Σ A B) → UU l1
Eq-total-subtype is-subtype-B p p' = Id (pr1 p) (pr1 p')
reflexive-Eq-total-subtype :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} (is-subtype-B : is-subtype B) →
(p : Σ A B) → Eq-total-subtype is-subtype-B p p
reflexive-Eq-total-subtype is-subtype-B (pair x y) = refl
Eq-total-subtype-eq :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} (is-subtype-B : is-subtype B) →
(p p' : Σ A B) → Id p p' → Eq-total-subtype is-subtype-B p p'
Eq-total-subtype-eq is-subtype-B p .p refl =
reflexive-Eq-total-subtype is-subtype-B p
is-contr-total-Eq-total-subtype :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} (is-subtype-B : is-subtype B) →
(p : Σ A B) → is-contr (Σ (Σ A B) (Eq-total-subtype is-subtype-B p))
is-contr-total-Eq-total-subtype is-subtype-B (pair x y) =
is-contr-total-Eq-substructure
( is-contr-total-path x)
( is-subtype-B)
x refl y
is-equiv-Eq-total-subtype-eq :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} (is-subtype-B : is-subtype B) →
(p p' : Σ A B) → is-equiv (Eq-total-subtype-eq is-subtype-B p p')
is-equiv-Eq-total-subtype-eq is-subtype-B p =
fundamental-theorem-id p
( reflexive-Eq-total-subtype is-subtype-B p)
( is-contr-total-Eq-total-subtype is-subtype-B p)
( Eq-total-subtype-eq is-subtype-B p)
eq-subtype :
{l1 l2 : Level} {A : UU l1} {B : A → UU l2} (is-subtype-B : is-subtype B) →
{p p' : Σ A B} → Eq-total-subtype is-subtype-B p p' → Id p p'
eq-subtype is-subtype-B {p} {p'} =
inv-is-equiv (is-equiv-Eq-total-subtype-eq is-subtype-B p p')
-- Section 8.2 Sets
is-set :
{i : Level} → UU i → UU i
is-set A = (x y : A) → is-prop (Id x y)
UU-Set :
(i : Level) → UU (lsuc i)
UU-Set i = Σ (UU i) is-set
type-Set :
{l : Level} → UU-Set l → UU l
type-Set X = pr1 X
is-set-type-Set :
{l : Level} (X : UU-Set l) → is-set (type-Set X)
is-set-type-Set X = pr2 X
axiom-K :
{i : Level} → UU i → UU i
axiom-K A = (x : A) (p : Id x x) → Id refl p
abstract
is-set-axiom-K :
{i : Level} (A : UU i) → axiom-K A → is-set A
is-set-axiom-K A H x y =
is-prop-is-prop' (ind-Id x (λ z p → (q : Id x z) → Id p q) (H x) y)
abstract
axiom-K-is-set :
{i : Level} (A : UU i) → is-set A → axiom-K A
axiom-K-is-set A H x p =
( inv (contraction (is-contr-is-prop-inh (H x x) refl) refl)) ∙
( contraction (is-contr-is-prop-inh (H x x) refl) p)
abstract
is-equiv-prop-in-id :
{i j : Level} {A : UU i}
(R : A → A → UU j)
(p : (x y : A) → is-prop (R x y))
(ρ : (x : A) → R x x)
(i : (x y : A) → R x y → Id x y) →
(x y : A) → is-equiv (i x y)
is-equiv-prop-in-id R p ρ i x =
fundamental-theorem-id-retr x (i x)
(λ y → pair
(ind-Id x (λ z p → R x z) (ρ x) y)
((λ r → is-prop'-is-prop (p x y) _ r)))
abstract
is-prop-is-equiv :
{i j : Level} {A : UU i} (B : UU j) (f : A → B) (E : is-equiv f) →
is-prop B → is-prop A
is-prop-is-equiv B f E H x y =
is-contr-is-equiv _ (ap f {x} {y}) (is-emb-is-equiv f E x y) (H (f x) (f y))
abstract
is-prop-is-equiv' :
{i j : Level} (A : UU i) {B : UU j} (f : A → B) (E : is-equiv f) →
is-prop A → is-prop B
is-prop-is-equiv' A f E H =
is-prop-is-equiv _ (inv-is-equiv E) (is-equiv-inv-is-equiv E) H
abstract
is-set-prop-in-id :
{i j : Level} {A : UU i} (R : A → A → UU j)
(p : (x y : A) → is-prop (R x y))
(ρ : (x : A) → R x x)
(i : (x y : A) → R x y → Id x y) →
is-set A
is-set-prop-in-id R p ρ i x y =
is-prop-is-equiv'
( R x y)
( i x y)
( is-equiv-prop-in-id R p ρ i x y) (p x y)
abstract
is-prop-Eq-ℕ :
(n m : ℕ) → is-prop (Eq-ℕ n m)
is-prop-Eq-ℕ zero-ℕ zero-ℕ = is-prop-unit
is-prop-Eq-ℕ zero-ℕ (succ-ℕ m) = is-prop-empty
is-prop-Eq-ℕ (succ-ℕ n) zero-ℕ = is-prop-empty
is-prop-Eq-ℕ (succ-ℕ n) (succ-ℕ m) = is-prop-Eq-ℕ n m
abstract
eq-Eq-ℕ : (n m : ℕ) → Eq-ℕ n m → Id n m
eq-Eq-ℕ = least-reflexive-Eq-ℕ Id (λ n → refl)
abstract
is-set-ℕ : is-set ℕ
is-set-ℕ =
is-set-prop-in-id
Eq-ℕ
is-prop-Eq-ℕ
refl-Eq-ℕ
eq-Eq-ℕ
set-ℕ : UU-Set lzero
set-ℕ = pair ℕ is-set-ℕ
-- Section 8.3 General truncation levels
data 𝕋 : UU lzero where
neg-two-𝕋 : 𝕋
succ-𝕋 : 𝕋 → 𝕋
neg-one-𝕋 : 𝕋
neg-one-𝕋 = succ-𝕋 (neg-two-𝕋)
zero-𝕋 : 𝕋
zero-𝕋 = succ-𝕋 (neg-one-𝕋)
one-𝕋 : 𝕋
one-𝕋 = succ-𝕋 (zero-𝕋)
ℕ-in-𝕋 : ℕ → 𝕋
ℕ-in-𝕋 zero-ℕ = zero-𝕋
ℕ-in-𝕋 (succ-ℕ n) = succ-𝕋 (ℕ-in-𝕋 n)
-- Probably it is better to define this where we first need it.
add-𝕋 : 𝕋 → 𝕋 → 𝕋
add-𝕋 neg-two-𝕋 neg-two-𝕋 = neg-two-𝕋
add-𝕋 neg-two-𝕋 (succ-𝕋 neg-two-𝕋) = neg-two-𝕋
add-𝕋 neg-two-𝕋 (succ-𝕋 (succ-𝕋 y)) = y
add-𝕋 (succ-𝕋 neg-two-𝕋) neg-two-𝕋 = neg-two-𝕋
add-𝕋 (succ-𝕋 neg-two-𝕋) (succ-𝕋 y) = y
add-𝕋 (succ-𝕋 (succ-𝕋 neg-two-𝕋)) y = y
add-𝕋 (succ-𝕋 (succ-𝕋 (succ-𝕋 x))) y = succ-𝕋 (add-𝕋 (succ-𝕋 (succ-𝕋 x)) y)
is-trunc : {i : Level} (k : 𝕋) → UU i → UU i
is-trunc neg-two-𝕋 A = is-contr A
is-trunc (succ-𝕋 k) A = (x y : A) → is-trunc k (Id x y)
1-type : (l : Level) → UU (lsuc l)
1-type l = Σ (UU l) (is-trunc one-𝕋)
_Truncated-Type_ : 𝕋 → (l : Level) → UU (lsuc l)
k Truncated-Type l = Σ (UU l) (is-trunc k)
abstract
is-trunc-succ-is-trunc :
{i : Level} (k : 𝕋) (A : UU i) →
is-trunc k A → is-trunc (succ-𝕋 k) A
is-trunc-succ-is-trunc neg-two-𝕋 A H = is-prop-is-contr H
is-trunc-succ-is-trunc (succ-𝕋 k) A H x y =
is-trunc-succ-is-trunc k (Id x y) (H x y)
truncated-type-succ-𝕋 :
(l : Level) (k : 𝕋) → k Truncated-Type l → (succ-𝕋 k) Truncated-Type l
truncated-type-succ-𝕋 l k (pair A is-trunc-A) =
pair A (is-trunc-succ-is-trunc k A is-trunc-A)
abstract
is-trunc-is-equiv :
{i j : Level} (k : 𝕋) {A : UU i} (B : UU j) (f : A → B) → is-equiv f →
is-trunc k B → is-trunc k A
is-trunc-is-equiv neg-two-𝕋 B f is-equiv-f H =
is-contr-is-equiv B f is-equiv-f H
is-trunc-is-equiv (succ-𝕋 k) B f is-equiv-f H x y =
is-trunc-is-equiv k (Id (f x) (f y)) (ap f {x} {y})
(is-emb-is-equiv f is-equiv-f x y) (H (f x) (f y))
abstract
is-set-is-equiv :
{i j : Level} {A : UU i} (B : UU j) (f : A → B) → is-equiv f →
is-set B → is-set A
is-set-is-equiv = is-trunc-is-equiv zero-𝕋
abstract
is-trunc-equiv :
{i j : Level} (k : 𝕋) {A : UU i} (B : UU j) (e : A ≃ B) →
is-trunc k B → is-trunc k A
is-trunc-equiv k B (pair f is-equiv-f) =
is-trunc-is-equiv k B f is-equiv-f
abstract
is-set-equiv :
{i j : Level} {A : UU i} (B : UU j) (e : A ≃ B) →
is-set B → is-set A
is-set-equiv = is-trunc-equiv zero-𝕋
abstract
is-trunc-is-equiv' :
{i j : Level} (k : 𝕋) (A : UU i) {B : UU j} (f : A → B) →
is-equiv f → is-trunc k A → is-trunc k B
is-trunc-is-equiv' k A f is-equiv-f is-trunc-A =
is-trunc-is-equiv k A
( inv-is-equiv is-equiv-f)
( is-equiv-inv-is-equiv is-equiv-f)
( is-trunc-A)
abstract
is-set-is-equiv' :
{i j : Level} (A : UU i) {B : UU j} (f : A → B) → is-equiv f →
is-set A → is-set B
is-set-is-equiv' = is-trunc-is-equiv' zero-𝕋
abstract
is-trunc-equiv' :
{i j : Level} (k : 𝕋) (A : UU i) {B : UU j} (e : A ≃ B) →
is-trunc k A → is-trunc k B
is-trunc-equiv' k A (pair f is-equiv-f) =
is-trunc-is-equiv' k A f is-equiv-f
abstract
is-set-equiv' :
{i j : Level} (A : UU i) {B : UU j} (e : A ≃ B) →
is-set A → is-set B
is-set-equiv' = is-trunc-equiv' zero-𝕋
abstract
is-trunc-succ-is-emb : {i j : Level} (k : 𝕋) {A : UU i} {B : UU j}
(f : A → B) → is-emb f → is-trunc (succ-𝕋 k) B → is-trunc (succ-𝕋 k) A
is-trunc-succ-is-emb k f Ef H x y =
is-trunc-is-equiv k (Id (f x) (f y)) (ap f {x} {y}) (Ef x y) (H (f x) (f y))
is-trunc-map :
{i j : Level} (k : 𝕋) {A : UU i} {B : UU j} → (A → B) → UU (i ⊔ j)
is-trunc-map k f = (y : _) → is-trunc k (fib f y)
trunc-map : {i j : Level} (k : 𝕋) (A : UU i) (B : UU j) → UU (i ⊔ j)
trunc-map k A B = Σ (A → B) (is-trunc-map k)
abstract
is-trunc-pr1-is-trunc-fam :
{i j : Level} (k : 𝕋) {A : UU i} (B : A → UU j) →
((x : A) → is-trunc k (B x)) → is-trunc-map k (pr1 {i} {j} {A} {B})
is-trunc-pr1-is-trunc-fam k B H x =
is-trunc-is-equiv k
( B x)
( fib-fam-fib-pr1 B x)
( is-equiv-fib-fam-fib-pr1 B x)
( H x)
trunc-pr1 :
{i j : Level} (k : 𝕋) {A : UU i} (B : A → k Truncated-Type j) →
trunc-map k (Σ A (λ x → pr1 (B x))) A
trunc-pr1 k B =
pair pr1 (is-trunc-pr1-is-trunc-fam k (λ x → pr1 (B x)) (λ x → pr2 (B x)))
abstract
is-trunc-fam-is-trunc-pr1 : {i j : Level} (k : 𝕋) {A : UU i} (B : A → UU j) →
is-trunc-map k (pr1 {i} {j} {A} {B}) → ((x : A) → is-trunc k (B x))
is-trunc-fam-is-trunc-pr1 k B is-trunc-pr1 x =
is-trunc-is-equiv k
( fib pr1 x)
( fib-pr1-fib-fam B x)
( is-equiv-fib-pr1-fib-fam B x)
( is-trunc-pr1 x)
abstract
is-trunc-map-is-trunc-ap : {i j : Level} (k : 𝕋) {A : UU i} {B : UU j}
(f : A → B) → ((x y : A) → is-trunc-map k (ap f {x = x} {y = y})) →
is-trunc-map (succ-𝕋 k) f
is-trunc-map-is-trunc-ap k f is-trunc-ap-f b (pair x p) (pair x' p') =
is-trunc-is-equiv k
( fib (ap f) (p ∙ (inv p')))
( fib-ap-eq-fib f (pair x p) (pair x' p'))
( is-equiv-fib-ap-eq-fib f (pair x p) (pair x' p'))
( is-trunc-ap-f x x' (p ∙ (inv p')))
abstract
is-trunc-ap-is-trunc-map : {i j : Level} (k : 𝕋) {A : UU i} {B : UU j}
(f : A → B) → is-trunc-map (succ-𝕋 k) f →
(x y : A) → is-trunc-map k (ap f {x = x} {y = y})
is-trunc-ap-is-trunc-map k f is-trunc-map-f x y p =
is-trunc-is-equiv' k
( Id (pair x p) (pair y refl))
( eq-fib-fib-ap f x y p)
( is-equiv-eq-fib-fib-ap f x y p)
( is-trunc-map-f (f y) (pair x p) (pair y refl))
is-prop-map : {i j : Level} {A : UU i} {B : UU j} (f : A → B) → UU (i ⊔ j)
is-prop-map f = (b : _) → is-trunc neg-one-𝕋 (fib f b)
abstract
is-emb-is-prop-map : {i j : Level} {A : UU i} {B : UU j} (f : A → B) →
is-prop-map f → is-emb f
is-emb-is-prop-map f is-prop-map-f x y =
is-equiv-is-contr-map
( is-trunc-ap-is-trunc-map neg-two-𝕋 f is-prop-map-f x y)
abstract
is-prop-map-is-emb : {i j : Level} {A : UU i} {B : UU j} (f : A → B) →
is-emb f → is-prop-map f
is-prop-map-is-emb f is-emb-f =
is-trunc-map-is-trunc-ap neg-two-𝕋 f
( λ x y → is-contr-map-is-equiv (is-emb-f x y))
abstract
is-emb-pr1-is-subtype : {i j : Level} {A : UU i} {B : A → UU j} →
is-subtype B → is-emb (pr1 {B = B})
is-emb-pr1-is-subtype {B = B} is-subtype-B =
is-emb-is-prop-map pr1
( λ x → is-trunc-is-equiv neg-one-𝕋
( B x)
( fib-fam-fib-pr1 _ x)
( is-equiv-fib-fam-fib-pr1 _ x)
( is-subtype-B x))
equiv-ap-pr1-is-subtype : {i j : Level} {A : UU i} {B : A → UU j} →
is-subtype B → {s t : Σ A B} → Id s t ≃ Id (pr1 s) (pr1 t)
equiv-ap-pr1-is-subtype is-subtype-B {s} {t} =
pair
( ap pr1)
( is-emb-pr1-is-subtype is-subtype-B s t)
abstract
is-subtype-is-emb-pr1 : {i j : Level} {A : UU i} {B : A → UU j} →
is-emb (pr1 {B = B}) → is-subtype B
is-subtype-is-emb-pr1 is-emb-pr1-B x =
is-trunc-is-equiv neg-one-𝕋
( fib pr1 x)
( fib-pr1-fib-fam _ x)
( is-equiv-fib-pr1-fib-fam _ x)
( is-prop-map-is-emb pr1 is-emb-pr1-B x)
is-fiberwise-trunc : {l1 l2 l3 : Level} (k : 𝕋) {A : UU l1} {B : A → UU l2}
{C : A → UU l3} (f : (x : A) → B x → C x) → UU (l1 ⊔ (l2 ⊔ l3))
is-fiberwise-trunc k f = (x : _) → is-trunc-map k (f x)
abstract
is-trunc-tot-is-fiberwise-trunc : {l1 l2 l3 : Level} (k : 𝕋)
{A : UU l1} {B : A → UU l2} {C : A → UU l3} (f : (x : A) → B x → C x) →
is-fiberwise-trunc k f → is-trunc-map k (tot f)
is-trunc-tot-is-fiberwise-trunc k f is-fiberwise-trunc-f (pair x z) =
is-trunc-is-equiv k
( fib (f x) z)
( fib-ftr-fib-tot f (pair x z))
( is-equiv-fib-ftr-fib-tot f (pair x z))
( is-fiberwise-trunc-f x z)
abstract
is-fiberwise-trunc-is-trunc-tot : {l1 l2 l3 : Level} (k : 𝕋)
{A : UU l1} {B : A → UU l2} {C : A → UU l3} (f : (x : A) → B x → C x) →
is-trunc-map k (tot f) → is-fiberwise-trunc k f
is-fiberwise-trunc-is-trunc-tot k f is-trunc-tot-f x z =
is-trunc-is-equiv k
( fib (tot f) (pair x z))
( fib-tot-fib-ftr f (pair x z))
( is-equiv-fib-tot-fib-ftr f (pair x z))
( is-trunc-tot-f (pair x z))
-- Exercises
-- Exercise 8.1
-- Exercise 8.1
diagonal : {l : Level} (A : UU l) → A → A × A
diagonal A x = pair x x
abstract
is-prop-is-equiv-diagonal : {l : Level} (A : UU l) →
is-equiv (diagonal A) → is-prop A
is-prop-is-equiv-diagonal A is-equiv-d =
is-prop-is-prop' ( λ x y →
let α = issec-inv-is-equiv is-equiv-d (pair x y) in
( inv (ap pr1 α)) ∙ (ap pr2 α))
eq-fib-diagonal : {l : Level} (A : UU l) (t : A × A) →
fib (diagonal A) t → Id (pr1 t) (pr2 t)
eq-fib-diagonal A (pair x y) (pair z α) = (inv (ap pr1 α)) ∙ (ap pr2 α)
fib-diagonal-eq : {l : Level} (A : UU l) (t : A × A) →
Id (pr1 t) (pr2 t) → fib (diagonal A) t
fib-diagonal-eq A (pair x y) β =
pair x (eq-pair-triv (pair refl β))
issec-fib-diagonal-eq : {l : Level} (A : UU l) (t : A × A) →
((eq-fib-diagonal A t) ∘ (fib-diagonal-eq A t)) ~ id
issec-fib-diagonal-eq A (pair x .x) refl = refl
isretr-fib-diagonal-eq : {l : Level} (A : UU l) (t : A × A) →
((fib-diagonal-eq A t) ∘ (eq-fib-diagonal A t)) ~ id
isretr-fib-diagonal-eq A .(pair z z) (pair z refl) = refl
abstract
is-equiv-eq-fib-diagonal : {l : Level} (A : UU l) (t : A × A) →
is-equiv (eq-fib-diagonal A t)
is-equiv-eq-fib-diagonal A t =
is-equiv-has-inverse
( fib-diagonal-eq A t)
( issec-fib-diagonal-eq A t)
( isretr-fib-diagonal-eq A t)
abstract
is-trunc-is-trunc-diagonal : {l : Level} (k : 𝕋) (A : UU l) →
is-trunc-map k (diagonal A) → is-trunc (succ-𝕋 k) A
is-trunc-is-trunc-diagonal k A is-trunc-d x y =
is-trunc-is-equiv' k
( fib (diagonal A) (pair x y))
( eq-fib-diagonal A (pair x y))
( is-equiv-eq-fib-diagonal A (pair x y))
( is-trunc-d (pair x y))
abstract
is-trunc-diagonal-is-trunc : {l : Level} (k : 𝕋) (A : UU l) →
is-trunc (succ-𝕋 k) A → is-trunc-map k (diagonal A)
is-trunc-diagonal-is-trunc k A is-trunc-A t =
is-trunc-is-equiv k
( Id (pr1 t) (pr2 t))
( eq-fib-diagonal A t)
( is-equiv-eq-fib-diagonal A t)
( is-trunc-A (pr1 t) (pr2 t))
-- Exercise 8.2
-- Exercise 8.2(a)
abstract
is-trunc-Σ : {l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : A → UU l2} →
is-trunc k A → ((x : A) → is-trunc k (B x)) → is-trunc k (Σ A B)
is-trunc-Σ neg-two-𝕋 is-trunc-A is-trunc-B =
is-contr-Σ is-trunc-A is-trunc-B
is-trunc-Σ (succ-𝕋 k) {B = B} is-trunc-A is-trunc-B s t =
is-trunc-is-equiv k
( Σ (Id (pr1 s) (pr1 t)) (λ p → Id (tr B p (pr2 s)) (pr2 t)))
( pair-eq)
( is-equiv-pair-eq s t)
( is-trunc-Σ k
( is-trunc-A (pr1 s) (pr1 t))
( λ p → is-trunc-B (pr1 t) (tr B p (pr2 s)) (pr2 t)))
abstract
is-trunc-prod : {l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : UU l2} →
is-trunc k A → is-trunc k B → is-trunc k (A × B)
is-trunc-prod k is-trunc-A is-trunc-B =
is-trunc-Σ k is-trunc-A (λ x → is-trunc-B)
abstract
is-prop-Σ : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} →
is-prop A → is-subtype B → is-prop (Σ A B)
is-prop-Σ = is-trunc-Σ neg-one-𝕋
Σ-Prop :
{l1 l2 : Level} (P : UU-Prop l1) (Q : type-Prop P → UU-Prop l2) →
UU-Prop (l1 ⊔ l2)
Σ-Prop P Q =
pair
( Σ (type-Prop P) (λ p → type-Prop (Q p)))
( is-prop-Σ
( is-prop-type-Prop P)
( λ p → is-prop-type-Prop (Q p)))
abstract
is-prop-prod : {l1 l2 : Level} {A : UU l1} {B : UU l2} →
is-prop A → is-prop B → is-prop (A × B)
is-prop-prod = is-trunc-prod neg-one-𝕋
prod-Prop : {l1 l2 : Level} → UU-Prop l1 → UU-Prop l2 → UU-Prop (l1 ⊔ l2)
prod-Prop P Q =
pair
( type-Prop P × type-Prop Q)
( is-prop-prod (is-prop-type-Prop P) (is-prop-type-Prop Q))
abstract
is-set-Σ : {l1 l2 : Level} {A : UU l1} {B : A → UU l2} →
is-set A → ((x : A) → is-set (B x)) → is-set (Σ A B)
is-set-Σ = is-trunc-Σ zero-𝕋
set-Σ :
{l1 l2 : Level} (A : UU-Set l1) (B : pr1 A → UU-Set l2) → UU-Set (l1 ⊔ l2)
set-Σ (pair A is-set-A) B =
pair
( Σ A (λ x → (pr1 (B x))))
( is-set-Σ is-set-A (λ x → pr2 (B x)))
abstract
is-set-prod : {l1 l2 : Level} {A : UU l1} {B : UU l2} →
is-set A → is-set B → is-set (A × B)
is-set-prod = is-trunc-prod zero-𝕋
set-prod :
{l1 l2 : Level} (A : UU-Set l1) (B : UU-Set l2) → UU-Set (l1 ⊔ l2)
set-prod (pair A is-set-A) (pair B is-set-B) =
pair (A × B) (is-set-prod is-set-A is-set-B)
-- Exercise 8.2 (b)
abstract
is-trunc-Id : {l : Level} (k : 𝕋) {A : UU l} →
is-trunc k A → (x y : A) → is-trunc k (Id x y)
is-trunc-Id neg-two-𝕋 is-trunc-A = is-prop-is-contr is-trunc-A
is-trunc-Id (succ-𝕋 k) is-trunc-A x y =
is-trunc-succ-is-trunc k (Id x y) (is-trunc-A x y)
-- Exercise 8.2 (c)
abstract
is-trunc-map-is-trunc-domain-codomain : {l1 l2 : Level} (k : 𝕋) {A : UU l1}
{B : UU l2} {f : A → B} → is-trunc k A → is-trunc k B → is-trunc-map k f
is-trunc-map-is-trunc-domain-codomain k {f = f} is-trunc-A is-trunc-B b =
is-trunc-Σ k is-trunc-A (λ x → is-trunc-Id k is-trunc-B (f x) b)
-- Exercise 8.2 (d)
abstract
is-trunc-fam-is-trunc-Σ :
{l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : A → UU l2} →
is-trunc k A → is-trunc k (Σ A B) → (x : A) → is-trunc k (B x)
is-trunc-fam-is-trunc-Σ k {B = B} is-trunc-A is-trunc-ΣAB x =
is-trunc-is-equiv' k
( fib pr1 x)
( fib-fam-fib-pr1 B x)
( is-equiv-fib-fam-fib-pr1 B x)
( is-trunc-map-is-trunc-domain-codomain k is-trunc-ΣAB is-trunc-A x)
-- Exercise 8.3
abstract
is-prop-Eq-𝟚 : (x y : bool) → is-prop (Eq-𝟚 x y)
is-prop-Eq-𝟚 true true = is-prop-unit
is-prop-Eq-𝟚 true false = is-prop-empty
is-prop-Eq-𝟚 false true = is-prop-empty
is-prop-Eq-𝟚 false false = is-prop-unit
abstract
eq-Eq-𝟚 : (x y : bool) → Eq-𝟚 x y → Id x y
eq-Eq-𝟚 true true star = refl
eq-Eq-𝟚 true false ()
eq-Eq-𝟚 false true ()
eq-Eq-𝟚 false false star = refl
abstract
is-set-bool : is-set bool
is-set-bool = is-set-prop-in-id Eq-𝟚 is-prop-Eq-𝟚 reflexive-Eq-𝟚 eq-Eq-𝟚
set-bool : UU-Set lzero
set-bool = pair bool is-set-bool
-- Exercise 8.4
abstract
is-trunc-succ-empty : (k : 𝕋) → is-trunc (succ-𝕋 k) empty
is-trunc-succ-empty k = ind-empty
abstract
is-trunc-coprod : {l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : UU l2} →
is-trunc (succ-𝕋 (succ-𝕋 k)) A → is-trunc (succ-𝕋 (succ-𝕋 k)) B →
is-trunc (succ-𝕋 (succ-𝕋 k)) (coprod A B)
is-trunc-coprod k {A} {B} is-trunc-A is-trunc-B (inl x) (inl y) =
is-trunc-is-equiv (succ-𝕋 k)
( Eq-coprod A B (inl x) (inl y))
( Eq-coprod-eq A B (inl x) (inl y))
( is-equiv-Eq-coprod-eq A B (inl x) (inl y))
( is-trunc-is-equiv' (succ-𝕋 k)
( Id x y)
( map-raise _ (Id x y))
( is-equiv-map-raise _ (Id x y))
( is-trunc-A x y))
is-trunc-coprod k {A} {B} is-trunc-A is-trunc-B (inl x) (inr y) =
is-trunc-is-equiv (succ-𝕋 k)
( Eq-coprod A B (inl x) (inr y))
( Eq-coprod-eq A B (inl x) (inr y))
( is-equiv-Eq-coprod-eq A B (inl x) (inr y))
( is-trunc-is-equiv' (succ-𝕋 k)
( empty)
( map-raise _ empty)
( is-equiv-map-raise _ empty)
( is-trunc-succ-empty k))
is-trunc-coprod k {A} {B} is-trunc-A is-trunc-B (inr x) (inl y) =
is-trunc-is-equiv (succ-𝕋 k)
( Eq-coprod A B (inr x) (inl y))
( Eq-coprod-eq A B (inr x) (inl y))
( is-equiv-Eq-coprod-eq A B (inr x) (inl y))
( is-trunc-is-equiv' (succ-𝕋 k)
( empty)
( map-raise _ empty)
( is-equiv-map-raise _ empty)
( is-trunc-succ-empty k))
is-trunc-coprod k {A} {B} is-trunc-A is-trunc-B (inr x) (inr y) =
is-trunc-is-equiv (succ-𝕋 k)
( Eq-coprod A B (inr x) (inr y))
( Eq-coprod-eq A B (inr x) (inr y))
( is-equiv-Eq-coprod-eq A B (inr x) (inr y))
( is-trunc-is-equiv' (succ-𝕋 k)
( Id x y)
( map-raise _ (Id x y))
( is-equiv-map-raise _ (Id x y))
( is-trunc-B x y))
abstract
is-set-coprod : {l1 l2 : Level} {A : UU l1} {B : UU l2} →
is-set A → is-set B → is-set (coprod A B)
is-set-coprod = is-trunc-coprod neg-two-𝕋
set-coprod :
{l1 l2 : Level} (A : UU-Set l1) (B : UU-Set l2) → UU-Set (l1 ⊔ l2)
set-coprod (pair A is-set-A) (pair B is-set-B) =
pair (coprod A B) (is-set-coprod is-set-A is-set-B)
abstract
is-set-unit : is-set unit
is-set-unit = is-trunc-succ-is-trunc neg-one-𝕋 unit is-prop-unit
set-unit : UU-Set lzero
set-unit = pair unit is-set-unit
abstract
is-set-ℤ : is-set ℤ
is-set-ℤ = is-set-coprod is-set-ℕ (is-set-coprod is-set-unit is-set-ℕ)
set-ℤ : UU-Set lzero
set-ℤ = pair ℤ is-set-ℤ
is-set-empty : is-set empty
is-set-empty ()
abstract
is-set-Fin :
(n : ℕ) → is-set (Fin n)
is-set-Fin zero-ℕ = is-set-empty
is-set-Fin (succ-ℕ n) =
is-set-coprod (is-set-Fin n) is-set-unit
set-Fin :
(n : ℕ) → UU-Set lzero
set-Fin n = pair (Fin n) (is-set-Fin n)
-- Exercise 8.7
abstract
is-trunc-retract-of : {l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : UU l2} →
A retract-of B → is-trunc k B → is-trunc k A
is-trunc-retract-of neg-two-𝕋 (pair i (pair r H)) is-trunc-B =
is-contr-retract-of _ (pair i (pair r H)) is-trunc-B
is-trunc-retract-of (succ-𝕋 k) (pair i retr-i) is-trunc-B x y =
is-trunc-retract-of k
( pair (ap i) (retr-ap i retr-i x y))
( is-trunc-B (i x) (i y))
-- Exercise 8.8
is-injective : {l1 l2 : Level} {A : UU l1} (is-set-A : is-set A) {B : UU l2}
(is-set-B : is-set B) (f : A → B) → UU (l1 ⊔ l2)
is-injective {A = A} is-set-A is-set-B f = (x y : A) → Id (f x) (f y) → Id x y
is-injective-const-true : is-injective is-set-unit is-set-bool
(const unit bool true)
is-injective-const-true x y p = center (is-prop-unit x y)
is-injective-const-false : is-injective is-set-unit is-set-bool
(const unit bool false)
is-injective-const-false x y p = center (is-prop-unit x y)
abstract
is-equiv-is-prop : {l1 l2 : Level} {A : UU l1} {B : UU l2} → is-prop A →
is-prop B → {f : A → B} → (B → A) → is-equiv f
is-equiv-is-prop is-prop-A is-prop-B {f} g =
is-equiv-has-inverse
( g)
( λ y → center (is-prop-B (f (g y)) y))
( λ x → center (is-prop-A (g (f x)) x))
equiv-prop :
{ l1 l2 : Level} {A : UU l1} {B : UU l2} → is-prop A → is-prop B →
( A → B) → (B → A) → A ≃ B
equiv-prop is-prop-A is-prop-B f g =
pair f (is-equiv-is-prop is-prop-A is-prop-B g)
equiv-total-subtype :
{ l1 l2 l3 : Level} {A : UU l1} {P : A → UU l2} {Q : A → UU l3} →
( is-subtype-P : is-subtype P) (is-subtype-Q : is-subtype Q) →
( f : (x : A) → P x → Q x) →
( g : (x : A) → Q x → P x) →
( Σ A P) ≃ (Σ A Q)
equiv-total-subtype is-subtype-P is-subtype-Q f g =
pair
( tot f)
( is-equiv-tot-is-fiberwise-equiv {f = f}
( λ x → is-equiv-is-prop (is-subtype-P x) (is-subtype-Q x) (g x)))
abstract
is-emb-is-injective : {l1 l2 : Level} {A : UU l1} (is-set-A : is-set A)
{B : UU l2} (is-set-B : is-set B) (f : A → B) →
is-injective is-set-A is-set-B f → is-emb f
is-emb-is-injective is-set-A is-set-B f is-injective-f x y =
is-equiv-is-prop
( is-set-A x y)
( is-set-B (f x) (f y))
( is-injective-f x y)
abstract
is-injective-is-emb : {l1 l2 : Level} {A : UU l1} {is-set-A : is-set A}
{B : UU l2} {is-set-B : is-set B} {f : A → B} →
is-emb f → is-injective is-set-A is-set-B f
is-injective-is-emb is-emb-f x y = inv-is-equiv (is-emb-f x y)
-- Exercise 8.9
abstract
is-trunc-const-is-trunc : {l : Level} (k : 𝕋) {A : UU l} →
is-trunc (succ-𝕋 k) A → (x : A) → is-trunc-map k (const unit A x)
is-trunc-const-is-trunc k is-trunc-A x y =
is-trunc-is-equiv' k
( Id x y)
( left-unit-law-Σ-map (λ t → Id x y) is-contr-unit)
( is-equiv-left-unit-law-Σ-map (λ t → Id x y) is-contr-unit)
( is-trunc-A x y)
abstract
is-trunc-is-trunc-const : {l : Level} (k : 𝕋) {A : UU l} →
((x : A) → is-trunc-map k (const unit A x)) → is-trunc (succ-𝕋 k) A
is-trunc-is-trunc-const k is-trunc-const x y =
is-trunc-is-equiv k
( Σ unit (λ t → Id x y))
( left-unit-law-Σ-map (λ t → Id x y) is-contr-unit)
( is-equiv-left-unit-law-Σ-map (λ t → Id x y) is-contr-unit)
( is-trunc-const x y)
-- Exercise 8.10
map-fib-comp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2}
{X : UU l3} (g : B → X) (h : A → B) →
(x : X) → fib (g ∘ h) x → Σ (fib g x) (λ t → fib h (pr1 t))
map-fib-comp g h x (pair a p) =
pair
( pair (h a) p)
( pair a refl)
inv-map-fib-comp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2}
{X : UU l3} (g : B → X) (h : A → B) →
(x : X) → Σ (fib g x) (λ t → fib h (pr1 t)) → fib (g ∘ h) x
inv-map-fib-comp g h c t =
pair (pr1 (pr2 t)) ((ap g (pr2 (pr2 t))) ∙ (pr2 (pr1 t)))
issec-inv-map-fib-comp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2}
{X : UU l3} (g : B → X) (h : A → B) →
(x : X) →
((map-fib-comp g h x) ∘ (inv-map-fib-comp g h x)) ~ id
issec-inv-map-fib-comp g h x
(pair (pair .(h a) refl) (pair a refl)) = refl
isretr-inv-map-fib-comp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2}
{X : UU l3} (g : B → X) (h : A → B) (x : X) →
((inv-map-fib-comp g h x) ∘ (map-fib-comp g h x)) ~ id
isretr-inv-map-fib-comp g h .(g (h a)) (pair a refl) = refl
abstract
is-equiv-map-fib-comp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2}
{X : UU l3} (g : B → X) (h : A → B) (x : X) →
is-equiv (map-fib-comp g h x)
is-equiv-map-fib-comp g h x =
is-equiv-has-inverse
( inv-map-fib-comp g h x)
( issec-inv-map-fib-comp g h x)
( isretr-inv-map-fib-comp g h x)
abstract
is-equiv-inv-map-fib-comp : {l1 l2 l3 : Level} {A : UU l1} {B : UU l2}
{X : UU l3} (g : B → X) (h : A → B) (x : X) →
is-equiv (inv-map-fib-comp g h x)
is-equiv-inv-map-fib-comp g h x =
is-equiv-has-inverse
( map-fib-comp g h x)
( isretr-inv-map-fib-comp g h x)
( issec-inv-map-fib-comp g h x)
abstract
is-trunc-map-htpy : {l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : UU l2}
(f g : A → B) → f ~ g → is-trunc-map k g → is-trunc-map k f
is-trunc-map-htpy k {A} f g H is-trunc-g b =
is-trunc-is-equiv k
( Σ A (λ z → Id (g z) b))
( fib-triangle f g id H b)
( is-fiberwise-equiv-is-equiv-triangle f g id H (is-equiv-id _) b)
( is-trunc-g b)
abstract
is-trunc-map-comp : {l1 l2 l3 : Level} (k : 𝕋) {A : UU l1} {B : UU l2}
{X : UU l3} (f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
is-trunc-map k g → is-trunc-map k h → is-trunc-map k f
is-trunc-map-comp k f g h H is-trunc-g is-trunc-h =
is-trunc-map-htpy k f (g ∘ h) H
( λ x → is-trunc-is-equiv k
( Σ (fib g x) (λ t → fib h (pr1 t)))
( map-fib-comp g h x)
( is-equiv-map-fib-comp g h x)
( is-trunc-Σ k
( is-trunc-g x)
( λ t → is-trunc-h (pr1 t))))
abstract
is-trunc-map-right-factor : {l1 l2 l3 : Level} (k : 𝕋) {A : UU l1} {B : UU l2}
{X : UU l3} (f : A → X) (g : B → X) (h : A → B) (H : f ~ (g ∘ h)) →
is-trunc-map k g → is-trunc-map k f → is-trunc-map k h
is-trunc-map-right-factor k {A} f g h H is-trunc-g is-trunc-f b =
is-trunc-fam-is-trunc-Σ k
( is-trunc-g (g b))
( is-trunc-is-equiv' k
( Σ A (λ z → Id (g (h z)) (g b)))
( map-fib-comp g h (g b))
( is-equiv-map-fib-comp g h (g b))
( is-trunc-map-htpy k (g ∘ h) f (htpy-inv H) is-trunc-f (g b)))
( pair b refl)
abstract
is-trunc-map-succ-is-trunc-map :
{l1 l2 : Level} (k : 𝕋) {A : UU l1} {B : UU l2}
(f : A → B) → is-trunc-map k f → is-trunc-map (succ-𝕋 k) f
is-trunc-map-succ-is-trunc-map k f is-trunc-f b =
is-trunc-succ-is-trunc k (fib f b) (is-trunc-f b)
| {
"alphanum_fraction": 0.5455098837,
"avg_line_length": 32.5474452555,
"ext": "agda",
"hexsha": "7a03e6f97aefa184d3cdffccdf817a4275c373e3",
"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": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "hemangandhi/HoTT-Intro",
"max_forks_repo_path": "Agda/10-truncation-levels.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "hemangandhi/HoTT-Intro",
"max_issues_repo_path": "Agda/10-truncation-levels.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "09c710bf9c31ba88be144cc950bd7bc19c22a934",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "hemangandhi/HoTT-Intro",
"max_stars_repo_path": "Agda/10-truncation-levels.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 13474,
"size": 31213
} |
module RevMachine where
open import Level
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Data.Product
record RevMachine {ℓ} : Set (suc ℓ) where
field
State : Set ℓ
_↦_ : Rel State ℓ
deterministic : ∀ {st st₁ st₂} → st ↦ st₁ → st ↦ st₂ → st₁ ≡ st₂
deterministicᵣₑᵥ : ∀ {st st₁ st₂} → st₁ ↦ st → st₂ ↦ st → st₁ ≡ st₂
record PartialRevMachine {ℓ} : Set (suc ℓ) where
field
State : Set ℓ
_↦_ : Rel State ℓ
is-fail : State → Set ℓ
is-fail? : (st : State) → Dec (is-fail st)
fail-is-stuck : ∀ {st} → is-fail st → ∄[ st' ] (st ↦ st')
deterministic : ∀ {st st₁ st₂} → st ↦ st₁ → st ↦ st₂ → st₁ ≡ st₂
deterministicᵣₑᵥ : ∀ {st st₁ st₂} → st₁ ↦ st → st₂ ↦ st → ¬ (is-fail st) → st₁ ≡ st₂
| {
"alphanum_fraction": 0.6129032258,
"avg_line_length": 29.8518518519,
"ext": "agda",
"hexsha": "b173e702095b009f19c1b3ab939bd513657368a8",
"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": "RevMachine.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": "RevMachine.agda",
"max_line_length": 88,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "RevMachine.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": 318,
"size": 806
} |
module Structure.Numeral.Natural where
open import Lang.Instance
import Lvl
open import Logic.Predicate
open import Logic.Propositional
open import Structure.Setoid
open import Structure.Function.Domain
open import Structure.Function
open import Structure.Operator
open import Structure.Relator
open import Structure.Setoid
open import Syntax.Function
open import Type
private variable ℓₒ ℓₗ ℓₑ ℓₗ₁ ℓₗ₂ : Lvl.Level
private variable N : Type{ℓₒ}
module _ ⦃ equiv : Equiv{ℓₑ}(N) ⦄ where
private variable 𝟎 : N
private variable 𝐒 : N → N
private variable _+_ _⋅_ _^_ : N → N → N
module _ {ℓ} (𝟎 : N) (𝐒 : N → N) where
record Induction : Type{ℓₑ Lvl.⊔ Lvl.of(N) Lvl.⊔ Lvl.𝐒(ℓ)} where
constructor intro
field proof : (P : N → Type{ℓ}) ⦃ rel : UnaryRelator(P) ⦄ → P(𝟎) → ((n : N) → P(n) → P(𝐒(n))) → ((n : N) → P(n))
induction = inst-fn Induction.proof
record Elemental (𝟎 : N) (𝐒 : N → N) : Type{ℓₑ Lvl.⊔ Lvl.of(N)} where
constructor intro
field
⦃ 𝐒-function ⦄ : Function(𝐒)
⦃ 𝐒-injectivity ⦄ : Injective(𝐒)
𝐒-positivity : ∀{x} → (𝐒(x) ≢ 𝟎)
record Addition ⦃ elemn : Elemental(𝟎)(𝐒) ⦄ (_+_ : N → N → N) : Type{ℓₑ Lvl.⊔ Lvl.of(N)} where
constructor intro
field
⦃ operator ⦄ : BinaryOperator(_+_)
base : ∀{a} → (a + 𝟎 ≡ a)
step : ∀{a b} → (a + 𝐒(b) ≡ 𝐒(a + b))
record Multiplication ⦃ elemn : Elemental(𝟎)(𝐒) ⦄ ⦃ addi : Addition(_+_) ⦄ (_⋅_ : N → N → N) : Type{ℓₑ Lvl.⊔ Lvl.of(N)} where
constructor intro
field
⦃ operator ⦄ : BinaryOperator(_⋅_)
base : ∀{a} → (a ⋅ 𝟎 ≡ 𝟎)
step : ∀{a b} → (a ⋅ 𝐒(b) ≡ a + (a ⋅ b))
record Exponentiation ⦃ elemn : Elemental(𝟎)(𝐒) ⦄ ⦃ addi : Addition(_+_) ⦄ ⦃ multi : Multiplication(_⋅_) ⦄ (_^_ : N → N → N) : Type{ℓₑ Lvl.⊔ Lvl.of(N)} where
constructor intro
field
⦃ operator ⦄ : BinaryOperator(_^_)
base : ∀{a} → (a ^ 𝟎 ≡ 𝐒(𝟎))
step : ∀{a b} → (a ^ 𝐒(b) ≡ a ⋅ (a ^ b))
record WeakOrdering ⦃ elemn : Elemental(𝟎)(𝐒) ⦄ {_+_ : N → N → N} ⦃ addi : Addition(_+_) ⦄ (_≤_ : N → N → Type{ℓₗ}) : Type{ℓₑ Lvl.⊔ Lvl.of(N) Lvl.⊔ ℓₗ} where
constructor intro
field
⦃ relator ⦄ : BinaryRelator(_≤_)
proof : ∀{a b} → (a ≤ b) ↔ ∃(c ↦ a + c ≡ b)
module _ ⦃ ind : Induction(𝟎)(𝐒) ⦄ ⦃ elem : Elemental(𝟎)(𝐒) ⦄ where
open import Structure.Relator.Proofs
open import Structure.Relator.Properties
open Elemental(elem)
open Induction(ind)
𝟎-or-𝐒 : ∀{x} → (x ≡ 𝟎) ∨ ∃(y ↦ x ≡ 𝐒(y))
𝟎-or-𝐒 {x} = induction(𝟎)(𝐒)
(x ↦ (x ≡ 𝟎) ∨ ∃(y ↦ x ≡ 𝐒(y))) ⦃ [∨]-unaryRelator ⦃ rel-P = BinaryRelator.left [≡]-binaryRelator ⦄ ⦃ rel-Q = [∃]-unaryRelator ⦃ rel-P = BinaryRelator.left [≡]-binaryRelator ⦄ ⦄ ⦄
([∨]-introₗ (reflexivity(_≡_)))
(x ↦ [∨]-elim
(p ↦ [∨]-introᵣ([∃]-intro 𝟎 ⦃ congruence₁(𝐒) p ⦄))
(\{([∃]-intro y ⦃ p ⦄) → [∨]-introᵣ([∃]-intro (𝐒(y)) ⦃ congruence₁(𝐒) p ⦄)})
)
x
{-
module _ ⦃ ind : Induction(𝟎)(𝐒) ⦄ where
import Data.Either as Either
open import Functional
open import Numeral.Natural as ℕ using (ℕ)
open import Relator.Equals renaming (_≡_ to _≡ₑ_)
open import Structure.Relator.Proofs
open import Syntax.Number
from-ℕ : ℕ → N
from-ℕ (ℕ.𝟎) = 𝟎
from-ℕ (ℕ.𝐒(n)) = 𝐒(from-ℕ n)
-}
-- TODO: Also include the definition of a "naturally ordered semigroup" here
{-
module _ (_<_ : T → T → Stmt{ℓₗ}) where
record Minimal : Type{Lvl.of(T) Lvl.⊔ ℓₗ} where
open From-[<][≡] (_<_) (_≡_)
field
⦃ elemental ⦄ : Elemental
[<]ₗ-𝟎 : ∀{x} → (𝟎 < x) ↔ (x ≢ 𝟎)
[<]ᵣ-𝟎 : ∀{x} → (𝟎 ≤ x) -- Minimum in the order (TODO: Is (∀x. x≥0) neccessary? Which means (0<x)∨(0=x))
[<]ₗ-𝐒 : ∀{x y} → (𝐒(x) < y) ↔ ((x < y)∧(𝐒(x) ≢ y)) -- TODO: Also the definition of (_≤_)?
[<]ᵣ-𝐒 : ∀{x y} → (x < 𝐒(y)) ↔ (x ≤ y)
-}
| {
"alphanum_fraction": 0.5506198347,
"avg_line_length": 35.2,
"ext": "agda",
"hexsha": "bfb60caf3665cf19aa2a0c9d425bb7dc50b63ba1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Numeral/Natural.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Numeral/Natural.agda",
"max_line_length": 185,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Numeral/Natural.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 1778,
"size": 3872
} |
{- 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
-}
------------------------------------------------------------------------------
import LibraBFT.Impl.OBM.Crypto as TODO
open import LibraBFT.Impl.OBM.Logging.Logging
open import LibraBFT.ImplShared.Consensus.Types
open import Optics.All
open import Util.PKCS
open import Util.Prelude
------------------------------------------------------------------------------
open import Data.String using (String)
------------------------------------------------------------------------------
module LibraBFT.Impl.Consensus.SafetyRules.PersistentSafetyStorage where
new : Author → Waypoint → SK → PersistentSafetyStorage
new author waypoint sk = mkPersistentSafetyStorage
{- _pssSafetyData =-} (SafetyData∙new
{- _sdEpoch = Epoch-} 1
{-, _sdLastVotedRound = Round-} 0
{-, _sdPreferredRound = Round-} 0
{-, _sdLastVote =-} nothing)
{-, _pssAuthor =-} author
{-, _pssWaypoint =-} waypoint
{-, _pssObmSK =-} (just sk)
consensusKeyForVersion : PersistentSafetyStorage → PK → Either ErrLog SK
consensusKeyForVersion self pk =
-- LBFT-OBM-DIFF
maybeS (self ^∙ pssObmSK) (Left fakeErr {-"pssObmSK Nothing"-}) $ λ sk →
if TODO.makePK sk /= pk
then Left fakeErr -- ["sk /= pk"]
else pure sk
where
here' : List String → List String
here' t = "PersistentSafetyStorage" ∷ "consensusKeyForVersion" ∷ t
| {
"alphanum_fraction": 0.5560022975,
"avg_line_length": 42.4634146341,
"ext": "agda",
"hexsha": "e1d73006e070988d80797349abe642633636b8d7",
"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/Consensus/SafetyRules/PersistentSafetyStorage.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/Consensus/SafetyRules/PersistentSafetyStorage.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/Consensus/SafetyRules/PersistentSafetyStorage.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 425,
"size": 1741
} |
module UniDB.Subst.Reg where
open import UniDB.Spec
open import UniDB.Subst.Core
open import UniDB.Morph.Reg
open import UniDB.Morph.WeakenPrime
module _ {T : STX} {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}} where
instance
iCompReg : Comp (Reg T)
_⊙_ {{iCompReg}} (baseR ξ) ζ = ξ ⊡ ζ
_⊙_ {{iCompReg}} (snocR {γ₁} {γ₂} ξ t) ζ = snocR (ξ ⊙ ζ) (ap {T} ζ t)
iWkmHomReg : WkmHom (Reg T)
wkm-zero {{iWkmHomReg}} = refl
wkm-suc {{iWkmHomReg}} δ = refl
iWkmBetaReg : WkmBeta T (Reg T)
wkm-beta {{iWkmBetaReg}} t = refl
reg-zero : (γ : Dom) → Reg T zero γ
reg-zero zero = baseR baseW
reg-zero (suc γ) = reg-zero γ ⊙ wkm {Reg T} 1
complete : (γ₁ γ₂ : Dom) (f : Ix γ₁ → T γ₂) → Reg T γ₁ γ₂
complete zero γ₂ f = reg-zero γ₂
complete (suc γ₁) γ₂ f = snocR (complete γ₁ γ₂ (f ∘ suc)) (f zero)
⊡-⊙-assoc : {γ₁ γ₂ γ₃ γ₄ : Dom} (ξ₁ : Weaken` γ₁ γ₂) (ξ₂ : Reg T γ₂ γ₃) (ξ₃ : Reg T γ₃ γ₄) →
ξ₁ ⊡ (ξ₂ ⊙ ξ₃) ≡ (ξ₁ ⊡ ξ₂) ⊙ ξ₃
⊡-⊙-assoc ξ₁ (baseR ξ₂) ξ₃ = ⊡-⊡-assoc ξ₁ ξ₂ ξ₃
⊡-⊙-assoc baseW ξ₂ ξ₃ rewrite idm-⊡ {Weaken`} {Reg T} (ξ₂ ⊙ ξ₃) | idm-⊡ {Weaken`} {Reg T} ξ₂ = refl
⊡-⊙-assoc (stepW ξ₁) (snocR ξ₂ t) ξ₃ = ⊡-⊙-assoc ξ₁ ξ₂ ξ₃
wk₁-⊡ : {γ₁ γ₂ γ₃ : Dom} (ξ₁ : Weaken` γ₁ γ₂) (ξ₂ : Reg T γ₂ γ₃) →
wk₁ (_⊡_ {Weaken`} {Reg T} {Reg T} ξ₁ ξ₂) ≡ ξ₁ ⊡ wk₁ ξ₂
wk₁-⊡ ξ₁ (baseR ξ) = refl
wk₁-⊡ baseW (snocR ξ₂ t) = refl
wk₁-⊡ (stepW ξ₁) (snocR ξ₂ t) = wk₁-⊡ ξ₁ ξ₂
module _
{T : STX} {{vrT : Vr T}} {{wkT : Wk T}} {{apTT : Ap T T}} {{wkVrT : WkVr T}}
where
instance
iCompIdmReg : {{apRelTT : ApRel T T}} {{apIdmTT : ApIdm T T}} → CompIdm (Reg T)
⊙-idm {{iCompIdmReg}} (baseR ξ) = refl
⊙-idm {{iCompIdmReg}} (snocR ξ t) = cong₂ snocR (⊙-idm {Reg T} ξ) (ap-idm` {T} t)
idm-⊙ {{iCompIdmReg}} ξ = idm-⊡ {Weaken`} {Reg T} ξ
lk-⊡ : {{apVr : ApVr T}}
{γ₁ γ₂ γ₃ : Dom} (ξ₁ : Weaken` γ₁ γ₂) (ξ₂ : Reg T γ₂ γ₃) →
(i : Ix γ₁) → lk {T} {Reg T} (ξ₁ ⊡ ξ₂) i ≡ ap {T} ξ₂ (lk {T} ξ₁ i)
lk-⊡ ξ₁ (baseR ξ₂) i = begin
lk (ξ₁ ⊙ ξ₂) i ≡⟨ lk-ren-comp {T} ξ₁ ξ₂ i ⟩
lk ξ₂ (lk ξ₁ i) ≡⟨ sym (ap-vr {T} (baseR ξ₂) (lk ξ₁ i)) ⟩
ap {T} (baseR ξ₂) (vr (lk ξ₁ i)) ≡⟨ cong (ap {T} (baseR ξ₂)) (sym (lk-ren {T} ξ₁ i)) ⟩
ap {T} (baseR ξ₂) (lk ξ₁ i) ∎
lk-⊡ baseW ξ₂ i = begin
lk {T} {Reg T} (baseW ⊡ ξ₂) i ≡⟨ cong₂ lk (idm-⊡ {Weaken`} ξ₂) refl ⟩
lk {T} {Reg T} ξ₂ i ≡⟨ sym (ap-vr {T} ξ₂ i) ⟩
ap {T} ξ₂ (vr i) ∎
lk-⊡ (stepW ξ₁) (snocR ξ₂ t) i = begin
lk {T} {Reg T} (ξ₁ ⊡ ξ₂) i ≡⟨ lk-⊡ ξ₁ ξ₂ i ⟩
ap {T} ξ₂ (vr (lk ξ₁ i)) ≡⟨ ap-vr {T} ξ₂ (lk ξ₁ i) ⟩
lk ξ₂ (lk ξ₁ i) ≡⟨ refl ⟩
lk (snocR ξ₂ t) (suc (lk ξ₁ i)) ≡⟨ sym (ap-vr {T} (snocR ξ₂ t) (suc (lk ξ₁ i))) ⟩
ap {T} (snocR ξ₂ t) (vr (suc (lk ξ₁ i))) ∎
instance
iLkCompApReg : {{apVr : ApVr T}} → LkCompAp T (Reg T)
lk-⊙-ap {{iLkCompApReg}} (baseR ξ₁) ξ₂ i = lk-⊡ ξ₁ ξ₂ i
lk-⊙-ap {{iLkCompApReg}} (snocR ξ₁ t) ξ₂ zero = refl
lk-⊙-ap {{iLkCompApReg}} (snocR ξ₁ t) ξ₂ (suc i) = lk-⊙-ap {T} ξ₁ ξ₂ i
wk₁-⊙ : {{apWkTT : ApWk T T}}
{γ₁ γ₂ γ₃ : Dom} (ξ₁ : Reg T γ₁ γ₂) (ξ₂ : Reg T γ₂ γ₃) →
wk₁ (ξ₁ ⊙ ξ₂) ≡ wk₁ ξ₁ ⊙ snocR (wk₁ ξ₂) (Vr.vr vrT zero)
wk₁-⊙ (baseR ξ) ξ₂ = wk₁-⊡ ξ ξ₂
wk₁-⊙ (snocR ξ₁ t) ξ₂ = cong₂ snocR (wk₁-⊙ ξ₁ ξ₂) (sym (ap-wk₁ {T} ξ₂ t))
instance
iUpCompReg : {{apVrT : ApVr T}} {{apWkTT : ApWk T T}} → UpComp (Reg T)
⊙-↑₁ {{iUpCompReg}} ξ₁ ξ₂ = cong₂ snocR
(wk₁-⊙ ξ₁ ξ₂)
(sym (ap-vr {T} (snocR (wk₁ ξ₂) (vr zero)) zero))
iCompAssocReg : {{apVrT : ApVr T}} {{apCompT : ApComp T T}} {{apWkTT : ApWk T T}} →
CompAssoc (Reg T)
⊙-assoc {{iCompAssocReg}} (baseR ξ₁) ξ₂ ξ₃ = ⊡-⊙-assoc ξ₁ ξ₂ ξ₃
⊙-assoc {{iCompAssocReg}} (snocR ξ₁ t) ξ₂ ξ₃ =
cong₂ snocR (⊙-assoc {Reg T} ξ₁ ξ₂ ξ₃) (ap-⊙ {T} ξ₂ ξ₃ t)
⊙-wkm₁-reg : {{apWkmWkTT : ApWkmWk T T}}
{γ₁ γ₂ : Dom} (ξ : Reg T γ₁ γ₂) →
ξ ⊙ wkm {Reg T} 1 ≡ wk₁ ξ
⊙-wkm₁-reg (baseR ξ) = refl
⊙-wkm₁-reg (snocR ξ t) rewrite sym (wk1-wk₁ t) =
cong₂ snocR (⊙-wkm₁-reg ξ) (ap-wkm-wk {T} 1 t)
instance
iWkmCommReg : {{apVr : ApVr T}} {{apCompT : ApComp T T}} {{apWkTT : ApWk T T}}
{{apWkmWkTT : ApWkmWk T T}} {{apRelTT : ApRel T T}} {{apIdmTT : ApIdm T T}} →
WkmComm (Reg T)
wkm₁-comm {{iWkmCommReg}} (baseR baseW) = refl
wkm₁-comm {{iWkmCommReg}} (baseR (stepW ξ)) rewrite idm-⊙ {Weaken`} ξ = refl
wkm₁-comm {{iWkmCommReg}} (snocR ξ t) = ⊙-wkm₁-reg (snocR ξ t)
| {
"alphanum_fraction": 0.5060111636,
"avg_line_length": 42.3454545455,
"ext": "agda",
"hexsha": "973864fbff95ea472b70207233501d698d205201",
"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": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "skeuchel/unidb-agda",
"max_forks_repo_path": "UniDB/Subst/Reg.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"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": "skeuchel/unidb-agda",
"max_issues_repo_path": "UniDB/Subst/Reg.agda",
"max_line_length": 116,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "skeuchel/unidb-agda",
"max_stars_repo_path": "UniDB/Subst/Reg.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2538,
"size": 4658
} |
{-# OPTIONS --safe --without-K #-}
module JVM.Builtins where
open import Data.List
open import JVM.Types
Object = "java/lang/Object"
Str = "java/lang/String"
jre : Constantpool
jre = staticref ("java/lang/System" / "out" ∶ ref "java/io/PrintStream")
∷ virtual ("java/io/PrintStream" / "println" :⟨ [ int ] ⟩ void)
∷ class (Object)
∷ virtual (Object / "<init>" :⟨ [] ⟩ void)
∷ []
| {
"alphanum_fraction": 0.5947242206,
"avg_line_length": 24.5294117647,
"ext": "agda",
"hexsha": "557068bd7f4e2d22d41193489f0c11675efabb4d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ajrouvoet/jvm.agda",
"max_forks_repo_path": "src/JVM/Builtins.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"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": "ajrouvoet/jvm.agda",
"max_issues_repo_path": "src/JVM/Builtins.agda",
"max_line_length": 79,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ajrouvoet/jvm.agda",
"max_stars_repo_path": "src/JVM/Builtins.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-28T21:49:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T14:07:17.000Z",
"num_tokens": 129,
"size": 417
} |
------------------------------------------------------------------------
-- Paolo Capriotti's variant of higher lenses
------------------------------------------------------------------------
{-# OPTIONS --cubical --safe #-}
import Equality.Path as P
module Lens.Non-dependent.Higher.Capriotti
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J as B using (_↔_)
open import Equality.Path.Isomorphisms eq hiding (univ)
open import Equivalence equality-with-J as Eq using (_≃_)
open import Function-universe equality-with-J as F hiding (_∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq
open import Preimage equality-with-J
open import Univalence-axiom equality-with-J
open import Lens.Non-dependent eq
import Lens.Non-dependent.Higher eq as Higher
import Lens.Non-dependent.Traditional eq as Traditional
private
variable
a b : Level
A B : Set a
------------------------------------------------------------------------
-- The lens type family
-- Higher lenses, as presented by Paolo Capriotti, who seems to have
-- been first to describe a notion of higher lens
-- (http://homotopytypetheory.org/2014/04/29/higher-lenses/).
Lens : Set a → Set b → Set (lsuc (a ⊔ b))
Lens {a = a} A B =
∃ λ (g : A → B) →
∃ λ (H : Pow a ∥ B ∥) →
(g ⁻¹_) ≡ H ∘ ∣_∣
-- Some derived definitions.
module Lens {A : Set a} {B : Set b} (l : Lens A B) where
-- A getter.
get : A → B
get = proj₁ l
-- A predicate.
H : Pow a ∥ B ∥
H = proj₁ (proj₂ l)
-- An equality.
get⁻¹-≡ : (get ⁻¹_) ≡ H ∘ ∣_∣
get⁻¹-≡ = proj₂ (proj₂ l)
-- A setter.
--
-- This definition is based on Paolo Capriotti's.
set : A → B → A
set a b = $⟨ truncation-is-proposition ∣ get a ∣ ∣ b ∣ ⟩
∣ get a ∣ ≡ ∣ b ∣ ↝⟨ cong H ⟩
H ∣ get a ∣ ≡ H ∣ b ∣ ↝⟨ subst (λ f → f (get a) ≡ f b) (sym get⁻¹-≡) ⟩
get ⁻¹ get a ≡ get ⁻¹ b ↝⟨ ≡⇒≃ ⟩
get ⁻¹ get a ≃ get ⁻¹ b ↝⟨ flip _≃_.to (a , refl _) ⟩
get ⁻¹ b ↝⟨ proj₁ ⟩□
A □
instance
-- The lenses defined above have getters and setters.
has-getter-and-setter :
Has-getter-and-setter (Lens {a = a} {b = b})
has-getter-and-setter = record
{ get = Lens.get
; set = Lens.set
}
------------------------------------------------------------------------
-- Equality characterisation lemmas
-- An equality characterisation lemma.
equality-characterisation₁ :
{l₁ l₂ : Lens A B} →
let open Lens in
(l₁ ≡ l₂)
≃
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
trans (sym (cong _⁻¹_ (⟨ext⟩ g)))
(trans (get⁻¹-≡ l₁) (⟨ext⟩ (h ∘ ∣_∣))) ≡
get⁻¹-≡ l₂)
equality-characterisation₁ {A = A} {B = B} {l₁ = l₁} {l₂ = l₂} =
l₁ ≡ l₂ ↝⟨ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ Σ-assoc ⟩
((get l₁ , H l₁) , get⁻¹-≡ l₁) ≡ ((get l₂ , H l₂) , get⁻¹-≡ l₂) ↔⟨ inverse B.Σ-≡,≡↔≡ ⟩
(∃ λ (eq : (get l₁ , H l₁) ≡ (get l₂ , H l₂)) →
subst (λ (g , H) → g ⁻¹_ ≡ H ∘ ∣_∣) eq (get⁻¹-≡ l₁) ≡ get⁻¹-≡ l₂) ↝⟨ (Σ-cong-contra ≡×≡↔≡ λ _ → F.id) ⟩
(∃ λ ((g , h) : get l₁ ≡ get l₂ × H l₁ ≡ H l₂) →
subst (λ (g , H) → g ⁻¹_ ≡ H ∘ ∣_∣) (cong₂ _,_ g h) (get⁻¹-≡ l₁) ≡
get⁻¹-≡ l₂) ↔⟨ inverse Σ-assoc ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (h : H l₁ ≡ H l₂) →
subst (λ (g , H) → g ⁻¹_ ≡ H ∘ ∣_∣) (cong₂ _,_ g h) (get⁻¹-≡ l₁) ≡
get⁻¹-≡ l₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ≡⇒↝ _ $ cong (_≡ _) $
lemma _ _) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (h : H l₁ ≡ H l₂) →
trans (sym (cong _⁻¹_ g)) (trans (get⁻¹-≡ l₁) (cong (_∘ ∣_∣) h)) ≡
get⁻¹-≡ l₂) ↝⟨ (Σ-cong-contra (Eq.extensionality-isomorphism bad-ext) λ _ →
Σ-cong-contra (Eq.extensionality-isomorphism bad-ext) λ _ →
F.id) ⟩
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
trans (sym (cong _⁻¹_ (⟨ext⟩ g)))
(trans (get⁻¹-≡ l₁) (cong (_∘ ∣_∣) (⟨ext⟩ h))) ≡
get⁻¹-≡ l₂) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ≡⇒↝ _ $
cong (λ eq → trans _ (trans _ eq) ≡ _) $
cong-pre-∘-ext _) ⟩□
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
trans (sym (cong _⁻¹_ (⟨ext⟩ g)))
(trans (get⁻¹-≡ l₁) (⟨ext⟩ (h ∘ ∣_∣))) ≡
get⁻¹-≡ l₂) □
where
open Lens
lemma : ∀ _ _ → _
lemma g h =
subst (λ (g , H) → g ⁻¹_ ≡ H ∘ ∣_∣) (cong₂ _,_ g h) (get⁻¹-≡ l₁) ≡⟨ subst-in-terms-of-trans-and-cong ⟩
trans (sym (cong (λ (g , _) → g ⁻¹_) (cong₂ _,_ g h)))
(trans (get⁻¹-≡ l₁) (cong (λ (_ , H) → H ∘ ∣_∣) (cong₂ _,_ g h))) ≡⟨ cong₂ (λ p q → trans (sym p) (trans (get⁻¹-≡ l₁) q))
(trans (sym $ cong-∘ _ _ _) $
cong (cong _⁻¹_) $ cong-proj₁-cong₂-, _ _)
(trans (sym $ cong-∘ _ _ _) $
cong (cong (_∘ ∣_∣)) $ cong-proj₂-cong₂-, _ _) ⟩∎
trans (sym (cong _⁻¹_ g)) (trans (get⁻¹-≡ l₁) (cong (_∘ ∣_∣) h)) ∎
-- Another equality characterisation lemma.
equality-characterisation₂ :
{A : Set a} {B : Set b} {l₁ l₂ : Lens A B}
(univ : Univalence (a ⊔ b)) →
let open Lens in
(l₁ ≡ l₂)
≃
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≃ H l₂ b) →
trans (sym (cong _⁻¹_ (⟨ext⟩ g)))
(trans (get⁻¹-≡ l₁) (⟨ext⟩ (≃⇒≡ univ ∘ h ∘ ∣_∣))) ≡
get⁻¹-≡ l₂)
equality-characterisation₂ {A = A} {B = B} {l₁ = l₁} {l₂ = l₂} univ =
l₁ ≡ l₂ ↝⟨ equality-characterisation₁ ⟩
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≡ H l₂ b) →
trans (sym (cong _⁻¹_ (⟨ext⟩ g)))
(trans (get⁻¹-≡ l₁) (⟨ext⟩ (h ∘ ∣_∣))) ≡
get⁻¹-≡ l₂) ↝⟨ (∃-cong λ _ →
Σ-cong-contra (∀-cong ext λ _ → inverse $ ≡≃≃ univ) λ _ → F.id) ⟩□
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (h : ∀ b → H l₁ b ≃ H l₂ b) →
trans (sym (cong _⁻¹_ (⟨ext⟩ g)))
(trans (get⁻¹-≡ l₁) (⟨ext⟩ (≃⇒≡ univ ∘ h ∘ ∣_∣))) ≡
get⁻¹-≡ l₂) □
where
open Lens
------------------------------------------------------------------------
-- Conversions between different kinds of lenses
-- The lenses defined above can be converted to the lenses defined in
-- Higher.
Lens→Higher-lens : Lens A B → Higher.Lens A B
Lens→Higher-lens {A = A} {B = B} (g , H , eq) = record
{ R = Σ ∥ B ∥ H
; equiv =
A ↔⟨ (inverse $ drop-⊤-right λ _ → _⇔_.to contractible⇔↔⊤ $
other-singleton-contractible _) ⟩
(∃ λ (a : A) → ∃ λ (b : B) → g a ≡ b) ↔⟨ ∃-comm ⟩
(∃ λ (b : B) → ∃ λ (a : A) → g a ≡ b) ↔⟨⟩
(∃ λ (b : B) → g ⁻¹ b) ↝⟨ (∃-cong λ b → ≡⇒↝ _ $ cong (_$ b) eq) ⟩
(∃ λ (b : B) → H ∣ b ∣) ↝⟨ (Σ-cong (inverse ∥∥×≃) λ _ → ≡⇒↝ _ $ cong H $ truncation-is-proposition _ _) ⟩
(∃ λ ((b , _) : ∥ B ∥ × B) → H b) ↔⟨ inverse Σ-assoc ⟩
(∃ λ (b : ∥ B ∥) → B × H b) ↔⟨ (∃-cong λ _ → ×-comm) ⟩
(∃ λ (b : ∥ B ∥) → H b × B) ↔⟨ Σ-assoc ⟩□
Σ ∥ B ∥ H × B □
; inhabited = proj₁
}
-- The conversion preserves getters and setters.
Lens→Higher-lens-preserves-getters-and-setters :
Preserves-getters-and-setters-→ A B Lens→Higher-lens
Lens→Higher-lens-preserves-getters-and-setters l@(g , H , eq) =
refl _
, ⟨ext⟩ λ a → ⟨ext⟩ λ b →
let h₁ = ≡⇒→ (cong (_$ g a) eq) (a , refl _)
h₂ =
_≃_.from (≡⇒↝ _ (cong H _))
(subst (H ∘ proj₁) (sym (_≃_.left-inverse-of ∥∥×≃ _))
(≡⇒→ (cong H _) h₁))
lemma =
h₂ ≡⟨ sym $ subst-in-terms-of-inverse∘≡⇒↝ equivalence _ _ _ ⟩
subst H _
(subst (H ∘ proj₁) (sym (_≃_.left-inverse-of ∥∥×≃ _))
(≡⇒→ (cong H _) h₁)) ≡⟨ cong (λ x → subst H (sym $ truncation-is-proposition _ _)
(subst (H ∘ proj₁)
(sym (_≃_.left-inverse-of ∥∥×≃ (∣ g a ∣ , b)))
x)) $ sym $
subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩
subst H _
(subst (H ∘ proj₁) (sym (_≃_.left-inverse-of ∥∥×≃ _))
(subst H _ h₁)) ≡⟨ cong (λ x → subst H (sym $ truncation-is-proposition _ _) x) $
subst-∘ _ _ _ ⟩
subst H _ (subst H _ (subst H _ h₁)) ≡⟨ cong (λ x → subst H (sym $ truncation-is-proposition _ _) x) $
subst-subst _ _ _ _ ⟩
subst H _ (subst H _ h₁) ≡⟨ subst-subst _ _ _ _ ⟩
subst H _ h₁ ≡⟨ cong (λ eq → subst H eq h₁) $
mono₁ 1 truncation-is-proposition _ _ ⟩
subst H _ h₁ ≡⟨ subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩∎
≡⇒→ (cong H _) h₁ ∎
in
(Higher.Lens.set (Lens→Higher-lens l) a b ≡⟨⟩
proj₁ (_≃_.from (≡⇒↝ _ (cong (_$ b) eq)) h₂) ≡⟨ cong (λ f → proj₁ (f h₂)) $ sym $
≡⇒↝-sym equivalence ⟩
proj₁ (≡⇒→ (sym (cong (_$ b) eq)) h₂) ≡⟨ cong (λ eq → proj₁ (≡⇒→ eq h₂)) $ sym $
cong-sym _ _ ⟩
proj₁ (≡⇒→ (cong (_$ b) (sym eq)) h₂) ≡⟨ cong (proj₁ ∘ ≡⇒→ (cong (_$ b) (sym eq)))
lemma ⟩
proj₁ (≡⇒→ (cong (_$ b) (sym eq)) (≡⇒→ (cong H _) h₁)) ≡⟨ cong (λ f → proj₁ (f h₁)) $ sym $
≡⇒↝-trans equivalence ⟩
proj₁ (≡⇒→ (trans (cong H _) (cong (_$ b) (sym eq))) h₁) ≡⟨⟩
proj₁ (≡⇒→ (trans (cong H _) (cong (_$ b) (sym eq)))
(≡⇒→ (cong (_$ g a) eq) (a , refl _))) ≡⟨ cong (λ f → proj₁ (f (a , refl _))) $ sym $
≡⇒↝-trans equivalence ⟩
proj₁ (≡⇒→ (trans (cong (_$ g a) eq)
(trans (cong H _) (cong (_$ b) (sym eq))))
(a , refl _)) ≡⟨ cong (λ p → proj₁
(≡⇒→ (trans p
(trans (cong H (truncation-is-proposition _ _))
(cong (_$ b) (sym eq))))
(a , refl _))) $
trans (cong (cong (_$ g a)) $ sym $ sym-sym _) $
cong-sym _ _ ⟩
proj₁ (≡⇒→ (trans (sym (cong (_$ g a) (sym eq)))
(trans (cong H _) (cong (_$ b) (sym eq))))
(a , refl _)) ≡⟨ cong (λ eq → proj₁ (≡⇒→ eq (a , refl _))) $ sym $
subst-in-terms-of-trans-and-cong ⟩
proj₁ (≡⇒→ (subst (λ f → f (g a) ≡ f b) (sym eq) (cong H _))
(a , refl _)) ≡⟨⟩
Lens.set l a b ∎)
-- Lens A B is equivalent to Higher.Lens A B (assuming univalence).
Lens≃Higher-lens :
{A : Set a} {B : Set b} →
Block "conversion" →
Univalence (a ⊔ b) →
Lens A B ≃ Higher.Lens A B
Lens≃Higher-lens {A = A} {B = B} ⊠ univ =
Eq.↔→≃ to from to∘from from∘to
where
to = Lens→Higher-lens
from : Higher.Lens A B → Lens A B
from l =
get
, (λ _ → R)
, ( $⟨ (λ b → inverse (Higher.remainder≃get⁻¹ l b)) ⟩
(∀ b → get ⁻¹ b ≃ R) ↝⟨ (∀-cong _ λ _ → ≃⇒≡ univ) ⟩
(∀ b → get ⁻¹ b ≡ R) ↝⟨ ⟨ext⟩ ⟩□
get ⁻¹_ ≡ const R □)
where
open Higher.Lens l
to∘from : ∀ l → to (from l) ≡ l
to∘from l = _↔_.from (Higher.equality-characterisation₃ univ)
( (∥ B ∥ × R ↔⟨ (drop-⊤-left-× λ r → _⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
truncation-is-proposition
(inhabited r)) ⟩□
R □)
, (λ a →
≡⇒→ (cong (λ _ → R) (truncation-is-proposition _ _))
(≡⇒→ (cong (_$ get a)
(⟨ext⟩ (≃⇒≡ univ ∘ inverse ∘
Higher.remainder≃get⁻¹ l)))
(a , refl _)) ≡⟨ cong (λ eq → ≡⇒→ eq (≡⇒→ (cong (_$ get a)
(⟨ext⟩ (≃⇒≡ univ ∘ inverse ∘
Higher.remainder≃get⁻¹ l)))
(a , refl _))) $
cong-const _ ⟩
≡⇒→ (refl _)
(≡⇒→ (cong (_$ get a)
(⟨ext⟩ (≃⇒≡ univ ∘ inverse ∘
Higher.remainder≃get⁻¹ l)))
(a , refl _)) ≡⟨ cong (_$ ≡⇒→ (cong (_$ get a)
(⟨ext⟩ (≃⇒≡ univ ∘ inverse ∘
Higher.remainder≃get⁻¹ l)))
(a , refl _))
≡⇒→-refl ⟩
≡⇒→ (cong (_$ get a)
(⟨ext⟩ (≃⇒≡ univ ∘ inverse ∘ Higher.remainder≃get⁻¹ l)))
(a , refl _) ≡⟨ cong (λ eq → ≡⇒→ eq (a , refl _)) $
cong-ext _ ⟩
≡⇒→ (≃⇒≡ univ (inverse (Higher.remainder≃get⁻¹ l (get a))))
(a , refl _) ≡⟨ cong (_$ a , refl _) $
≡⇒→-≃⇒≡ equivalence univ ⟩
_≃_.from (Higher.remainder≃get⁻¹ l (get a)) (a , refl _) ≡⟨⟩
remainder a ∎)
, (λ _ → refl _)
)
where
open Higher.Lens l
from∘to : ∀ l → from (to l) ≡ l
from∘to l = _≃_.from (equality-characterisation₂ univ)
( (λ _ → refl _)
, Σ∥B∥H≃H
, (trans (sym (cong _⁻¹_ (⟨ext⟩ λ _ → refl _)))
(trans
(⟨ext⟩ (≃⇒≡ univ ∘ inverse ∘ Higher.remainder≃get⁻¹ (to l)))
(⟨ext⟩ (≃⇒≡ univ ∘ Σ∥B∥H≃H ∘ ∣_∣))) ≡⟨ cong (flip trans _) $
trans (cong (sym ∘ cong _⁻¹_) ext-refl) $
trans (cong sym $ cong-refl _) $
sym-refl ⟩
trans (refl _)
(trans
(⟨ext⟩ (≃⇒≡ univ ∘ inverse ∘ Higher.remainder≃get⁻¹ (to l)))
(⟨ext⟩ (≃⇒≡ univ ∘ Σ∥B∥H≃H ∘ ∣_∣))) ≡⟨ trans-reflˡ _ ⟩
trans
(⟨ext⟩ (≃⇒≡ univ ∘ inverse ∘ Higher.remainder≃get⁻¹ (to l)))
(⟨ext⟩ (≃⇒≡ univ ∘ Σ∥B∥H≃H ∘ ∣_∣)) ≡⟨ sym $ ext-trans _ _ ⟩
(⟨ext⟩ λ b →
trans
(≃⇒≡ univ (inverse (Higher.remainder≃get⁻¹ (to l) b)))
(≃⇒≡ univ (Σ∥B∥H≃H ∣ b ∣))) ≡⟨ (cong ⟨ext⟩ $ ⟨ext⟩ λ _ → sym $
≃⇒≡-∘ univ ext _ _) ⟩
(⟨ext⟩ λ b →
≃⇒≡ univ (Σ∥B∥H≃H ∣ b ∣ F.∘
inverse (Higher.remainder≃get⁻¹ (to l) b))) ≡⟨ (cong ⟨ext⟩ $ ⟨ext⟩ λ _ → cong (≃⇒≡ univ) $ Eq.lift-equality ext $
⟨ext⟩ (lemma _)) ⟩
(⟨ext⟩ λ b → ≃⇒≡ univ (≡⇒≃ (ext⁻¹ get⁻¹-≡ b))) ≡⟨ (cong ⟨ext⟩ $ ⟨ext⟩ λ _ →
_≃_.left-inverse-of (≡≃≃ univ) _) ⟩
(⟨ext⟩ λ b → ext⁻¹ get⁻¹-≡ b) ≡⟨ _≃_.right-inverse-of (Eq.extensionality-isomorphism bad-ext) _ ⟩∎
get⁻¹-≡ ∎)
)
where
open Lens l
Σ∥B∥H≃H = λ b →
Σ ∥ B ∥ H ↔⟨ (drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
truncation-is-proposition b) ⟩□
H b □
lemma : ∀ b (p : get ⁻¹ b) → _
lemma b p@(a , get-a≡b) =
_≃_.to (Σ∥B∥H≃H ∣ b ∣)
(_≃_.from (Higher.remainder≃get⁻¹ (to l) b) p) ≡⟨⟩
subst H _
(≡⇒→ (cong H _)
(≡⇒→ (cong (_$ get a) get⁻¹-≡) (a , refl _))) ≡⟨ cong (subst H _) $ sym $
subst-in-terms-of-≡⇒↝ equivalence _ _ _ ⟩
subst H _ (subst H _ (≡⇒→ (cong (_$ get a) get⁻¹-≡) (a , refl _))) ≡⟨ subst-subst _ _ _ _ ⟩
subst H _ (≡⇒→ (cong (_$ get a) get⁻¹-≡) (a , refl _)) ≡⟨ cong (λ eq → subst H eq
(≡⇒→ (cong (_$ get a) get⁻¹-≡) (a , refl _))) $
mono₁ 1 truncation-is-proposition _ _ ⟩
subst H (cong ∣_∣ get-a≡b)
(≡⇒→ (cong (_$ get a) get⁻¹-≡) (a , refl _)) ≡⟨ elim¹
(λ {b} eq →
subst H (cong ∣_∣ eq)
(≡⇒→ (cong (_$ get a) get⁻¹-≡) (a , refl _)) ≡
≡⇒→ (cong (_$ b) get⁻¹-≡) (a , eq))
(
subst H (cong ∣_∣ (refl _))
(≡⇒→ (cong (_$ get a) get⁻¹-≡) (a , refl _)) ≡⟨ cong (λ eq → subst H eq
(≡⇒→ (cong (_$ get a) get⁻¹-≡) (a , refl _))) $
cong-refl _ ⟩
subst H (refl _)
(≡⇒→ (cong (_$ get a) get⁻¹-≡) (a , refl _)) ≡⟨ subst-refl _ _ ⟩∎
≡⇒→ (cong (_$ get a) get⁻¹-≡) (a , refl _) ∎)
get-a≡b ⟩
≡⇒→ (cong (_$ b) get⁻¹-≡) p ≡⟨⟩
≡⇒→ (ext⁻¹ get⁻¹-≡ b) p ∎
-- The equivalence preserves getters and setters.
Lens≃Higher-lens-preserves-getters-and-setters :
{A : Set a} {B : Set b}
(bc : Block "conversion")
(univ : Univalence (a ⊔ b)) →
Preserves-getters-and-setters-⇔ A B
(_≃_.logical-equivalence (Lens≃Higher-lens bc univ))
Lens≃Higher-lens-preserves-getters-and-setters ⊠ univ =
Preserves-getters-and-setters-→-↠-⇔
(_≃_.surjection (Lens≃Higher-lens ⊠ univ))
Lens→Higher-lens-preserves-getters-and-setters
-- An alternative proof showing that Lens A B is equivalent to
-- Higher.Lens A B (assuming univalence).
--
-- This proof was simplified following a suggestion by Paolo
-- Capriotti.
--
-- I have not proved that this equivalence preserves getters and
-- setters.
Lens≃Higher-lens′ :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
Lens A B ≃ Higher.Lens A B
Lens≃Higher-lens′ {a = a} {b = b} {A = A} {B = B} univ =
(∃ λ (g : A → B) → ∃ λ (H : Pow a ∥ B ∥) →
(g ⁻¹_) ≡ H ∘ ∣_∣) ↔⟨ Σ-cong lemma₂ (λ _ → ∃-cong (lemma₃ _)) ⟩
(∃ λ (p : ∃ λ (P : Pow a B) → A ≃ ∃ P) →
∃ λ (H : Pow a ∥ B ∥) →
proj₁ p ≡ H ∘ ∣_∣) ↔⟨ ∃-comm ⟩
(∃ λ (H : Pow a ∥ B ∥) →
∃ λ (p : ∃ λ (P : Pow a B) → A ≃ ∃ P) →
proj₁ p ≡ H ∘ ∣_∣) ↔⟨ (∃-cong λ _ → inverse Σ-assoc) ⟩
(∃ λ (H : Pow a ∥ B ∥) →
∃ λ (P : Pow a B) →
A ≃ ∃ P × P ≡ H ∘ ∣_∣) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ×-comm) ⟩
(∃ λ (H : Pow a ∥ B ∥) →
∃ λ (P : Pow a B) →
P ≡ H ∘ ∣_∣ × A ≃ ∃ P) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ eq →
Eq.≃-preserves ext F.id (∃-cong λ x → ≡⇒↝ _ (cong (_$ x) eq))) ⟩
(∃ λ (H : Pow a ∥ B ∥) →
∃ λ (P : Pow a B) →
P ≡ H ∘ ∣_∣ × A ≃ ∃ (H ∘ ∣_∣)) ↔⟨ (∃-cong λ _ → Σ-assoc) ⟩
(∃ λ (H : Pow a ∥ B ∥) →
(∃ λ (P : Pow a B) → P ≡ H ∘ ∣_∣) ×
A ≃ ∃ (H ∘ ∣_∣)) ↔⟨ (∃-cong λ _ →
drop-⊤-left-× λ _ →
_⇔_.to contractible⇔↔⊤ (singleton-contractible _)) ⟩
(∃ λ (H : Pow a ∥ B ∥) → A ≃ ∃ (H ∘ ∣_∣)) ↔⟨ inverse $
Σ-cong (inverse $ Pow↔Fam a ext univ) (λ _ →
Eq.≃-preserves ext F.id F.id) ⟩
(∃ λ (H : Fam a ∥ B ∥) → A ≃ ∃ ((proj₂ H ⁻¹_) ∘ ∣_∣)) ↔⟨ inverse Σ-assoc ⟩
(∃ λ (R : Set ℓ) →
∃ λ (f : R → ∥ B ∥) → A ≃ ∃ ((f ⁻¹_) ∘ ∣_∣)) ↔⟨ (∃-cong λ R → ∃-cong λ f →
Eq.≃-preserves ext F.id
(∃ ((f ⁻¹_) ∘ ∣_∣) ↔⟨ (∃-cong λ b → drop-⊤-right λ r →
_⇔_.to contractible⇔↔⊤ $
+⇒≡ truncation-is-proposition) ⟩
B × R ↔⟨ ×-comm ⟩□
R × B □)) ⟩
(∃ λ (R : Set ℓ) → (R → ∥ B ∥) × (A ≃ (R × B))) ↔⟨ (∃-cong λ _ → ×-comm) ⟩
(∃ λ (R : Set ℓ) → (A ≃ (R × B)) × (R → ∥ B ∥)) ↔⟨ inverse Higher.Lens-as-Σ ⟩□
Higher.Lens A B □
where
ℓ = a ⊔ b
lemma₁ : ∀ (g : A → B) b →
g ⁻¹ b ↔ (g ∘ lower {ℓ = ℓ}) ⁻¹ b
lemma₁ g b = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { (a , ga≡b) → lift a , ga≡b }
; from = λ { (lift a , ga≡b) → a , ga≡b }
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
abstract
lemma₂ : (A → B) ↔ ∃ λ (P : Pow a B) → A ≃ ∃ P
lemma₂ = →↔Σ≃Σ ℓ ext univ
lemma₃ :
(g : A → B) (H : Pow a ∥ B ∥) →
((g ⁻¹_) ≡ H ∘ ∣_∣)
≃
(proj₁ (_↔_.to lemma₂ g) ≡ H ∘ ∣_∣)
lemma₃ g H =
(g ⁻¹_) ≡ H ∘ ∣_∣ ↝⟨ inverse $ Eq.extensionality-isomorphism ext ⟩
(∀ b → g ⁻¹ b ≡ H ∣ b ∣) ↝⟨ ∀-cong ext (λ _ →
≡-preserves-≃ ext univ univ
(Eq.↔⇒≃ $ lemma₁ _ _) F.id) ⟩
(∀ b → (g ∘ lower) ⁻¹ b ≡ H ∣ b ∣) ↝⟨ Eq.extensionality-isomorphism ext ⟩
((g ∘ lower) ⁻¹_) ≡ H ∘ ∣_∣ ↝⟨ ≡⇒↝ _ $ cong (λ eq → (g ∘ lower ∘ _≃_.from eq ⁻¹_) ≡ H ∘ ∣_∣) lemma ⟩
(g ∘ lower ∘ _≃_.from (≡⇒↝ _ (sym (refl _))) ⁻¹_) ≡ H ∘ ∣_∣ ↔⟨⟩
proj₁ (_↔_.to lemma₂ g) ≡ H ∘ ∣_∣ □
where
lemma =
F.id ≡⟨ sym ≡⇒↝-refl ⟩
≡⇒↝ _ (refl _) ≡⟨ cong (≡⇒↝ _) $ sym sym-refl ⟩∎
≡⇒↝ _ (sym (refl _)) ∎
-- If the domain A is a set, then Traditional.Lens A B and Lens A B
-- are isomorphic (assuming univalence).
Lens↔Traditional-lens :
{A : Set a} {B : Set b} →
Block "conversion" →
Univalence (a ⊔ b) →
Is-set A →
Lens A B ↔ Traditional.Lens A B
Lens↔Traditional-lens {A = A} {B} bc univ A-set =
Lens A B ↔⟨ Lens≃Higher-lens bc univ ⟩
Higher.Lens A B ↝⟨ Higher.Lens↔Traditional-lens bc univ A-set ⟩□
Traditional.Lens A B □
-- The isomorphism preserves getters and setters.
Lens↔Traditional-lens-preserves-getters-and-setters :
{A : Set a} {B : Set b}
(bc : Block "conversion")
(univ : Univalence (a ⊔ b))
(s : Is-set A) →
Preserves-getters-and-setters-⇔ A B
(_↔_.logical-equivalence (Lens↔Traditional-lens bc univ s))
Lens↔Traditional-lens-preserves-getters-and-setters bc univ s =
Preserves-getters-and-setters-⇔-∘
{f = _↔_.logical-equivalence $
Higher.Lens↔Traditional-lens bc univ s}
{g = _≃_.logical-equivalence $ Lens≃Higher-lens bc univ}
(Higher.Lens↔Traditional-lens-preserves-getters-and-setters
bc univ s)
(Lens≃Higher-lens-preserves-getters-and-setters bc univ)
| {
"alphanum_fraction": 0.3429414766,
"avg_line_length": 46.5118644068,
"ext": "agda",
"hexsha": "6ef19029658652f76f385c70b7b7f6593b04c607",
"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": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Saizan/dependent-lenses",
"max_forks_repo_path": "src/Lens/Non-dependent/Higher/Capriotti.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062",
"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": "Saizan/dependent-lenses",
"max_issues_repo_path": "src/Lens/Non-dependent/Higher/Capriotti.agda",
"max_line_length": 145,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Saizan/dependent-lenses",
"max_stars_repo_path": "src/Lens/Non-dependent/Higher/Capriotti.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 9301,
"size": 27442
} |
module parse-test where
import parse
open import lib
open import cedille-types
import cedille
module parsem = parse cedille.gratr2-nt ptr
open parsem
open parsem.pnoderiv cedille.rrs cedille.cedille-rtn
open import run ptr
open noderiv {- from run.agda -}
process-start : start → string
process-start s = ""
process : Run → string
process (ParseTree (parsed-start p) :: []) = process-start p
process r = "Parsing failure (run with -" ^ "-showParsed).\n"
putStrRunIf : 𝔹 → Run → IO ⊤
putStrRunIf tt r = putStr (Run-to-string r) >> putStr "\n"
putStrRunIf ff r = return triv
parse-specific-nt : cedille.gratr2-nt → ℕ → (lc : 𝕃 char) → 𝕃 char ⊎ Run
parse-specific-nt nt starting-char-position lc with parse-filter lc lc [] [] (cedille.cedille-start nt) inj₁
...| inj₁ left = inj₁ left
...| inj₂ run = inj₂ (re-to-run starting-char-position (reverse run))
processArgs : (showRun : 𝔹) → (showParsed : 𝔹) → 𝕃 string → IO ⊤
processArgs showRun showParsed (input-filename :: []) = (readFiniteFile input-filename) >>= processText
where processText : string → IO ⊤
processText x with parse-specific-nt cedille._type 10 (string-to-𝕃char x)
processText x | s with s
processText x | s | inj₁ cs = putStr "Characters left before failure : " >> putStr (𝕃char-to-string cs) >> putStr "\nCannot proceed to parsing.\n"
processText x | s | inj₂ r with putStrRunIf showRun r | rewriteRun r
processText x | s | inj₂ r | sr | r' with putStrRunIf showParsed r'
processText x | s | inj₂ r | sr | r' | sr' = sr >> sr' >> putStr (process r')
processArgs showRun showParsed ("--showRun" :: xs) = processArgs tt showParsed xs
processArgs showRun showParsed ("--showParsed" :: xs) = processArgs showRun tt xs
processArgs showRun showParsed (x :: xs) = putStr ("Unknown option " ^ x ^ "\n")
processArgs showRun showParsed [] = putStr "Please run with the name of a file to process.\n"
main : IO ⊤
main = getArgs >>= processArgs ff ff
| {
"alphanum_fraction": 0.6753117207,
"avg_line_length": 41.7708333333,
"ext": "agda",
"hexsha": "29455105466e2c0710751d67a7c71130f1da17c3",
"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": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "xoltar/cedille",
"max_forks_repo_path": "src/parse-test.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"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": "xoltar/cedille",
"max_issues_repo_path": "src/parse-test.agda",
"max_line_length": 154,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "xoltar/cedille",
"max_stars_repo_path": "src/parse-test.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 602,
"size": 2005
} |
-- Andreas, 2019-03-18, issue #3122, AIM XXIX
-- Also pick up hidden record fields from a module.
record R : Set₂ where
field {f} : Set₁
module M where
f : Set₁
f = Set
r : R
r = record { M }
-- WAS: yellow
-- Should check.
| {
"alphanum_fraction": 0.6282051282,
"avg_line_length": 14.625,
"ext": "agda",
"hexsha": "326541abe6a49f2f28c52812a37a22e16e8f3d65",
"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/Issue3122.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/Issue3122.agda",
"max_line_length": 51,
"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/Issue3122.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": 81,
"size": 234
} |
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Semirings.Definition
open import Numbers.Naturals.Definition
open import Numbers.Naturals.Semiring
open import Orders.Total.Definition
open import Orders.Partial.Definition
module Numbers.Naturals.Order where
open Semiring ℕSemiring
open import Decidable.Lemmas ℕDecideEquality
private
infix 5 _<NLogical_
_<NLogical_ : ℕ → ℕ → Set
zero <NLogical zero = False
zero <NLogical (succ n) = True
(succ n) <NLogical zero = False
(succ n) <NLogical (succ m) = n <NLogical m
infix 5 _<N_
record _<N_ (a : ℕ) (b : ℕ) : Set where
constructor le
field
x : ℕ
proof : (succ x) +N a ≡ b
infix 5 _<N'_
record _<N'_ (a : ℕ) (b : ℕ) : Set where
constructor le'
field
x : ℕ
.proof : (succ x) +N a ≡ b
infix 5 _≤N_
_≤N_ : ℕ → ℕ → Set
a ≤N b = (a <N b) || (a ≡ b)
succIsPositive : (a : ℕ) → zero <N succ a
succIsPositive a = le a (applyEquality succ (Semiring.commutative ℕSemiring a 0))
aLessSucc : (a : ℕ) → (a <NLogical succ a)
aLessSucc zero = record {}
aLessSucc (succ a) = aLessSucc a
private
succPreservesInequalityLogical : {a b : ℕ} → (a <NLogical b) → (succ a <NLogical succ b)
succPreservesInequalityLogical {a} {b} prAB = prAB
lessTransitiveLogical : {a b c : ℕ} → (a <NLogical b) → (b <NLogical c) → (a <NLogical c)
lessTransitiveLogical {a} {zero} {zero} prAB prBC = prAB
lessTransitiveLogical {a} {(succ b)} {zero} prAB ()
lessTransitiveLogical {zero} {zero} {(succ c)} prAB prBC = record {}
lessTransitiveLogical {(succ a)} {zero} {(succ c)} () prBC
lessTransitiveLogical {zero} {(succ b)} {(succ c)} prAB prBC = record {}
lessTransitiveLogical {(succ a)} {(succ b)} {(succ c)} prAB prBC = lessTransitiveLogical {a} {b} {c} prAB prBC
aLessXPlusSuccA : (a x : ℕ) → (a <NLogical x +N succ a)
aLessXPlusSuccA a zero = aLessSucc a
aLessXPlusSuccA zero (succ x) = record {}
aLessXPlusSuccA (succ a) (succ x) = lessTransitiveLogical {a} {succ a} {x +N succ (succ a)} (aLessXPlusSuccA a zero) (aLessXPlusSuccA (succ a) x)
leImpliesLogical<N : {a b : ℕ} → (a <N b) → (a <NLogical b)
leImpliesLogical<N {zero} {zero} (le x ())
leImpliesLogical<N {zero} {(succ b)} (le x proof) = record {}
leImpliesLogical<N {(succ a)} {zero} (le x ())
leImpliesLogical<N {(succ a)} {(succ .(succ a))} (le zero refl) = aLessSucc a
leImpliesLogical<N {(succ a)} {(succ .(succ (x +N succ a)))} (le (succ x) refl) = succPreservesInequalityLogical {a} {succ (x +N succ a)} (lessTransitiveLogical {a} {succ a} {succ (x +N succ a)} (aLessSucc a) (aLessXPlusSuccA a x))
logical<NImpliesLe : {a b : ℕ} → (a <NLogical b) → (a <N b)
logical<NImpliesLe {zero} {zero} ()
_<N_.x (logical<NImpliesLe {zero} {succ b} prAB) = b
_<N_.proof (logical<NImpliesLe {zero} {succ b} prAB) = applyEquality succ (sumZeroRight b)
logical<NImpliesLe {(succ a)} {zero} ()
logical<NImpliesLe {(succ a)} {(succ b)} prAB with logical<NImpliesLe {a} prAB
logical<NImpliesLe {(succ a)} {(succ .(succ (x +N a)))} prAB | le x refl = le x (applyEquality succ (transitivity (commutative x _) (applyEquality succ (commutative a _))))
lessTransitive : {a b c : ℕ} → (a <N b) → (b <N c) → (a <N c)
lessTransitive {a} {b} {c} prab prbc = logical<NImpliesLe (lessTransitiveLogical {a} {b} {c} (leImpliesLogical<N prab) (leImpliesLogical<N prbc))
lessIrreflexive : {a : ℕ} → (a <N a) → False
lessIrreflexive {zero} pr = leImpliesLogical<N pr
lessIrreflexive {succ a} pr = lessIrreflexive {a} (logical<NImpliesLe {a} {a} (leImpliesLogical<N {succ a} {succ a} pr))
succPreservesInequality : {a b : ℕ} → (a <N b) → (succ a <N succ b)
succPreservesInequality {a} {b} prAB = logical<NImpliesLe (succPreservesInequalityLogical {a} {b} (leImpliesLogical<N prAB))
canRemoveSuccFrom<N : {a b : ℕ} → (succ a <N succ b) → (a <N b)
canRemoveSuccFrom<N {a} {b} (le x proof) rewrite commutative x (succ a) | commutative a x = le x (succInjective proof)
a<SuccA : (a : ℕ) → a <N succ a
a<SuccA a = le zero refl
<NWellDefined : {a b : ℕ} → (p1 : a <N b) → (p2 : a <N b) → _<N_.x p1 ≡ _<N_.x p2
<NWellDefined {a} {b} (le x proof) (le y proof1) = equalityCommutative r
where
q : y +N a ≡ x +N a
q = succInjective {y +N a} {x +N a} (transitivity proof1 (equalityCommutative proof))
r : y ≡ x
r = canSubtractFromEqualityRight q
canAddToOneSideOfInequality : {a b : ℕ} (c : ℕ) → a <N b → a <N (b +N c)
canAddToOneSideOfInequality {a} {b} c (le x proof) = le (x +N c) (transitivity (applyEquality succ (equalityCommutative (+Associative x c a))) (transitivity (applyEquality (λ i → (succ x) +N i) (commutative c a)) (transitivity (applyEquality succ (+Associative x a c)) (applyEquality (_+N c) proof))))
canAddToOneSideOfInequality' : {a b : ℕ} (c : ℕ) → a <N b → a <N (c +N b)
canAddToOneSideOfInequality' {a} {b} c (le x proof) = le (x +N c) ans
where
ans : succ ((x +N c) +N a) ≡ c +N b
ans rewrite (equalityCommutative (+Associative x c a)) | commutative c a | (+Associative x a c) = transitivity (applyEquality (_+N c) proof) (commutative b c)
addingIncreases : (a b : ℕ) → a <N a +N succ b
addingIncreases zero b = succIsPositive b
addingIncreases (succ a) b = succPreservesInequality (addingIncreases a b)
zeroNeverGreater : {a : ℕ} → (a <N zero) → False
zeroNeverGreater {a} (le x ())
noIntegersBetweenXAndSuccX : {a : ℕ} (x : ℕ) → (x <N a) → (a <N succ x) → False
noIntegersBetweenXAndSuccX {zero} x x<a a<sx = zeroNeverGreater x<a
noIntegersBetweenXAndSuccX {succ a} x (le y proof) (le z proof1) with succInjective proof1
... | ah rewrite (equalityCommutative proof) | (succExtracts z (y +N x)) | +Associative (succ z) y x | commutative (succ (z +N y)) x = lessIrreflexive {x} (le (z +N y) (transitivity (commutative _ x) ah))
private
orderIsTotal : (a b : ℕ) → ((a <N b) || (b <N a)) || (a ≡ b)
orderIsTotal zero zero = inr refl
orderIsTotal zero (succ b) = inl (inl (logical<NImpliesLe (record {})))
orderIsTotal (succ a) zero = inl (inr (logical<NImpliesLe (record {})))
orderIsTotal (succ a) (succ b) with orderIsTotal a b
orderIsTotal (succ a) (succ b) | inl (inl x) = inl (inl (logical<NImpliesLe (leImpliesLogical<N x)))
orderIsTotal (succ a) (succ b) | inl (inr x) = inl (inr (logical<NImpliesLe (leImpliesLogical<N x)))
orderIsTotal (succ a) (succ b) | inr x = inr (applyEquality succ x)
orderIsIrreflexive : {a b : ℕ} → (a <N b) → (b <N a) → False
orderIsIrreflexive {zero} {b} prAB (le x ())
orderIsIrreflexive {(succ a)} {zero} (le x ()) prBA
orderIsIrreflexive {(succ a)} {(succ b)} prAB prBA = orderIsIrreflexive {a} {b} (logical<NImpliesLe (leImpliesLogical<N prAB)) (logical<NImpliesLe (leImpliesLogical<N prBA))
orderIsTransitive : {a b c : ℕ} → (a <N b) → (b <N c) → (a <N c)
orderIsTransitive {a} {.(succ (x +N a))} {.(succ (y +N succ (x +N a)))} (le x refl) (le y refl) = le (y +N succ x) (applyEquality succ (equalityCommutative (+Associative y (succ x) a)))
ℕTotalOrder : TotalOrder ℕ
PartialOrder._<_ (TotalOrder.order ℕTotalOrder) = _<N_
PartialOrder.irreflexive (TotalOrder.order ℕTotalOrder) = lessIrreflexive
PartialOrder.<Transitive (TotalOrder.order ℕTotalOrder) = orderIsTransitive
TotalOrder.totality ℕTotalOrder = orderIsTotal
cannotAddAndEnlarge : (a b : ℕ) → a <N succ (a +N b)
cannotAddAndEnlarge a b = le b (applyEquality succ (commutative b a))
cannotAddAndEnlarge' : {a b : ℕ} → a +N b <N a → False
cannotAddAndEnlarge' {a} {zero} pr rewrite sumZeroRight a = lessIrreflexive pr
cannotAddAndEnlarge' {a} {succ b} pr rewrite (succExtracts a b) = lessIrreflexive {a} (lessTransitive {a} {succ (a +N b)} {a} (cannotAddAndEnlarge a b) pr)
cannotAddAndEnlarge'' : {a b : ℕ} → a +N succ b ≡ a → False
cannotAddAndEnlarge'' {a} {b} pr = naughtE (equalityCommutative inter)
where
inter : succ b ≡ 0
inter rewrite commutative a (succ b) = canSubtractFromEqualityRight pr
naturalsAreNonnegative : (a : ℕ) → (a <N zero) → False
naturalsAreNonnegative zero ()
naturalsAreNonnegative (succ x) ()
lessRespectsAddition : {a b : ℕ} (c : ℕ) → (a <N b) → ((a +N c) <N (b +N c))
lessRespectsAddition {a} {b} zero prAB rewrite commutative a 0 | commutative b 0 = prAB
lessRespectsAddition {a} {b} (succ c) prAB rewrite commutative a (succ c) | commutative b (succ c) | commutative c a | commutative c b = succPreservesInequality (lessRespectsAddition c prAB)
lessRespectsMultiplicationLeft : (a b c : ℕ) → (a <N b) → (zero <N c) → (c *N a <N c *N b)
lessRespectsMultiplicationLeft zero zero c (le x ()) cPos
lessRespectsMultiplicationLeft zero (succ b) zero prAB (le x ())
lessRespectsMultiplicationLeft zero (succ b) (succ c) prAB cPos = i
where
productNonzeroIsNonzero : {a b : ℕ} → zero <N a → zero <N b → zero <N a *N b
productNonzeroIsNonzero {zero} {b} prA prB = prA
productNonzeroIsNonzero {succ a} {zero} prA ()
productNonzeroIsNonzero {succ a} {succ b} prA prB = le (b +N a *N succ b) (applyEquality succ (Semiring.sumZeroRight ℕSemiring _))
j : zero <N succ c *N succ b
j = productNonzeroIsNonzero cPos prAB
i : succ c *N zero <N succ c *N succ b
i = identityOfIndiscernablesLeft _<N_ j (equalityCommutative (productZeroRight c))
lessRespectsMultiplicationLeft (succ a) zero c (le x ()) cPos
lessRespectsMultiplicationLeft (succ a) (succ b) c prAB cPos = m
where
h : c *N a <N c *N b
h = lessRespectsMultiplicationLeft a b c (canRemoveSuccFrom<N prAB) cPos
j : c *N a +N c <N c *N b +N c
j = lessRespectsAddition c h
i : c *N succ a <N c *N b +N c
i = identityOfIndiscernablesLeft _<N_ j (equalityCommutative (transitivity (multiplicationNIsCommutative c _) (transitivity (applyEquality (c +N_) (multiplicationNIsCommutative a _)) (commutative c _))))
m : c *N succ a <N c *N succ b
m = identityOfIndiscernablesRight _<N_ i (equalityCommutative (transitivity (multiplicationNIsCommutative c _) (transitivity (commutative c _) (applyEquality (_+N c) (multiplicationNIsCommutative b _)))))
canFlipMultiplicationsInIneq : {a b c d : ℕ} → (a *N b <N c *N d) → b *N a <N d *N c
canFlipMultiplicationsInIneq {a} {b} {c} {d} pr = identityOfIndiscernablesRight _<N_ (identityOfIndiscernablesLeft _<N_ pr (multiplicationNIsCommutative a b)) (multiplicationNIsCommutative c d)
lessRespectsMultiplication : (a b c : ℕ) → (a <N b) → (zero <N c) → (a *N c <N b *N c)
lessRespectsMultiplication a b c prAB cPos = canFlipMultiplicationsInIneq {c} {a} {c} {b} (lessRespectsMultiplicationLeft a b c prAB cPos)
squash<N : {a b : ℕ} → .(a <N b) → a <N b
squash<N {a} {b} a<b with orderIsTotal a b
... | inl (inl x) = x
... | inl (inr x) = exFalso (lessIrreflexive (orderIsTransitive x a<b))
squash<N {a} {b} a<b | inr refl = exFalso (lessIrreflexive a<b)
<NTo<N' : {a b : ℕ} → a <N b → a <N' b
<NTo<N' (le x proof) = le' x proof
<N'To<N : {a b : ℕ} → a <N' b → a <N b
<N'To<N {a} {b} (le' x proof) = le x (squash proof)
<N'Refl : {a b : ℕ} → (p1 p2 : a <N' b) → p1 ≡ p2
<N'Refl p1 p2 with <NWellDefined (<N'To<N p1) (<N'To<N p2)
... | refl = refl
| {
"alphanum_fraction": 0.6692670537,
"avg_line_length": 51.037037037,
"ext": "agda",
"hexsha": "120fa9396e7562912731a14c1bf4f3535500c7b5",
"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": "Numbers/Naturals/Order.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": "Numbers/Naturals/Order.agda",
"max_line_length": 301,
"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": "Numbers/Naturals/Order.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": 4090,
"size": 11024
} |
open import Common.List
open import Common.Equality
map-append : ∀{A B : Set}(f : A → B) (xs {ys} : List A) →
map f (xs ++ ys) ≡ map f xs ++ map f ys
map-append f [] = refl
map-append f (x ∷ xs) = {!cong (f x ∷_)!} -- Keep section on C-c C-r
map-append₂ : ∀{A B : Set}(f : A → B) (xs {ys} : List A) →
map f (xs ++ ys) ≡ map f xs ++ map f ys
map-append₂ f [] = refl
map-append₂ f (x ∷ xs) = {!cong (λ section → f x ∷ section)!} -- Keep lambda on C-c C-r
-- Check that we print sections in goals
postulate
_+_ : Set → Set → Set
μ : (Set → Set) → Set
foo : (A : Set) → μ (_+ A)
foo A = {!!}
bar : (A : Set) → μ (λ section → section + A)
bar A = {!!}
| {
"alphanum_fraction": 0.5211678832,
"avg_line_length": 27.4,
"ext": "agda",
"hexsha": "d6c47952be7b159f179e37e7af02960cb40af586",
"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/Issue2270.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/Issue2270.agda",
"max_line_length": 87,
"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/Issue2270.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": 256,
"size": 685
} |
-- Normalization by Evaluation for Intuitionistic Predicate Logic (IPL)
module Everything where
-- Imports from the standard library and simple definitions
import Library
-- Types and terms of IPL
import Formulas
import Derivations
-- Beth model
import TermModel
import NfModel
-- A variant where Cover : PSh → PSh
import NfModelCaseTree -- Presented at ITC 2018-07-19
import NfModelCaseTreeConv
-- A generalization to any CoverMonad which includes the
-- continuation monad used in Danvy's algorithm
import NfModelMonad
import Consistency
-- A monadic interpreter using shift/reset and an optimization
import DanvyShiftReset
import DanvyShiftResetLiftable
-- SET-interpretation and soundness of NbE
import Interpretation
import NbeModel
-- A general theory of sheaves over preorders
import PresheavesAndSheaves
| {
"alphanum_fraction": 0.8014354067,
"avg_line_length": 19.4418604651,
"ext": "agda",
"hexsha": "3ddb12ebc6aa8b5b43b0ce8fba6c7ab4085700f9",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-02-25T20:39:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-13T16:01:46.000Z",
"max_forks_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "andreasabel/ipl",
"max_forks_repo_path": "src/Everything.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a",
"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": "andreasabel/ipl",
"max_issues_repo_path": "src/Everything.agda",
"max_line_length": 71,
"max_stars_count": 19,
"max_stars_repo_head_hexsha": "9a6151ad1f0977674b8cc9e9cefb49ae83e8a42a",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "andreasabel/ipl",
"max_stars_repo_path": "src/Everything.agda",
"max_stars_repo_stars_event_max_datetime": "2021-04-27T19:10:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-16T08:08:51.000Z",
"num_tokens": 201,
"size": 836
} |
module HasNeitherNor where
record HasNeitherNor (A : Set) : Set
where
field
_⊗_ : A → A → A
open HasNeitherNor ⦃ … ⦄ public
| {
"alphanum_fraction": 0.6567164179,
"avg_line_length": 13.4,
"ext": "agda",
"hexsha": "0be2bf4cbaae8e6e9858d063887dba29c1fdd228",
"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/HasNeitherNor.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/HasNeitherNor.agda",
"max_line_length": 36,
"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/HasNeitherNor.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 50,
"size": 134
} |
{-# OPTIONS --guardedness #-}
module ky where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; _≢_; refl; cong; cong₂; sym)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)
open import Data.Rational using (ℚ; _+_; _*_; _-_)
open import Data.Bool
open import Data.Bool.Properties
open import Data.Rational
open import Data.Nat as ℕ using (ℕ; zero; suc)
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Agda.Builtin.Size
open import Data.Product
open import Data.Unit
open import Data.Maybe
data QRE : Set → Set → Set₁ where
⊥ : ∀{D C} → QRE D C
ε : ∀{D C} → C → QRE D C
α : ∀{D C}
→ (D → Bool) --φ
→ (D → C) --op
→ QRE D C
split : ∀{D C B A}
→ QRE D A --f
→ QRE D B --g
→ (A → B → C) --op
→ QRE D C
iter : ∀{D B A}
→ QRE D B --init
→ QRE D A --body
→ (B → A → B) --op
→ QRE D B
or : ∀{D C}
→ QRE D C
→ QRE D C
→ QRE D C
Event : Set
Event = ℕ
data Val : Set → Set where
VBool : Bool → Val Bool
VNat : ℕ → Val ℕ
data Exp : Set → Set where
EVal : ∀{t : Set} → Val t → Exp t
data Com : Set → Set where
CFlip : ∀{t} → Com t → Com t → Com t
CUpd : Exp Event → Com ⊤
CIte : ∀{t} → Exp Bool → Com t → Com t → Com t
CSeq : ∀{t} → Com ⊤ → Com t → Com t
is-true : Bool → Bool
is-true = λ{x → x}
data CoList (i : Size) (A : Set) : Set where
nil : CoList i A
cons : A → ∀{j : Size< i} → CoList j A → CoList i A
_++_ : ∀{A} → CoList ∞ A → CoList ∞ A → CoList ∞ A
nil ++ s₂ = s₂
(cons a s₁) ++ s₂ = cons a (s₁ ++ s₂)
interp : Com ⊤ → QRE Bool (CoList ∞ Event)
interp (CFlip c₁ c₂) =
or (split (α is-true λ{_ → nil}) (interp c₁) (_++_))
(split (α not λ{_ → nil}) (interp c₂) (_++_))
| {
"alphanum_fraction": 0.5455568054,
"avg_line_length": 23.3947368421,
"ext": "agda",
"hexsha": "c5afe5cb5f75f064c0d625fb2fc66b6684a3e147",
"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": "9243f9d77d0c8af99afa4f536156a3e23b1c40e1",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "OUPL/Zar",
"max_forks_repo_path": "theory/ky-qre.agda",
"max_issues_count": 5,
"max_issues_repo_head_hexsha": "9243f9d77d0c8af99afa4f536156a3e23b1c40e1",
"max_issues_repo_issues_event_max_datetime": "2019-10-06T16:32:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-09-13T15:40:08.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "OUPL/Zar",
"max_issues_repo_path": "theory/ky-qre.agda",
"max_line_length": 54,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9243f9d77d0c8af99afa4f536156a3e23b1c40e1",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "OUPL/Zar",
"max_stars_repo_path": "theory/ky-qre.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 702,
"size": 1778
} |
{-# OPTIONS --without-K --safe #-}
module Tools.Bool where
open import Data.Bool using (Bool; true; false; _∧_; if_then_else_) public
| {
"alphanum_fraction": 0.7058823529,
"avg_line_length": 22.6666666667,
"ext": "agda",
"hexsha": "4605bb31f86ff002af62d8ca0f8cd911d6454638",
"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": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Vtec234/logrel-mltt",
"max_forks_repo_path": "Tools/Bool.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"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": "Vtec234/logrel-mltt",
"max_issues_repo_path": "Tools/Bool.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Vtec234/logrel-mltt",
"max_stars_repo_path": "Tools/Bool.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 35,
"size": 136
} |
module Text.Greek.Script where
open import Data.Maybe
open import Data.Vec
open import Relation.Nullary using (¬_)
open import Relation.Binary.PropositionalEquality using (_≢_)
data Case : Set where
lower upper : Case
data Letter : Set where
α′ β′ γ′ δ′ ε′ ζ′ η′ θ′ ι′ κ′ λ′ μ′ ν′ ξ′ ο′ π′ ρ′ σ′ τ′ υ′ φ′ χ′ ψ′ ω′ : Letter
vowels : Vec _ _
vowels = α′ ∷ ε′ ∷ η′ ∷ ι′ ∷ ο′ ∷ υ′ ∷ ω′ ∷ []
always-short-letters : Vec _ _
always-short-letters = ε′ ∷ ο′ ∷ []
diaeresis-letters : Vec _ _
diaeresis-letters = ι′ ∷ υ′ ∷ []
iota-subscript-letters : Vec _ _
iota-subscript-letters = α′ ∷ η′ ∷ ω′ ∷ []
data _vowel : Letter → Set where
is-vowel : ∀ {v} → v ∈ vowels → v vowel
data _always-short : Letter → Set where
is-always-short : ∀ {v} → v vowel → v ∈ always-short-letters → v always-short
data _diaeresis : Letter → Set where
add-diaeresis : ∀ {v} → v vowel → v ∈ diaeresis-letters → v diaeresis
data _⟦_⟧-final : Letter → Case → Set where
make-final : σ′ ⟦ lower ⟧-final
data _⟦_⟧-smooth : Letter → Case → Set where
add-smooth-lower-vowel : ∀ {v} → v vowel → v ⟦ lower ⟧-smooth
add-smooth-ρ : ρ′ ⟦ lower ⟧-smooth
add-smooth-upper-vowel-not-Υ : ∀ {v} → v vowel → v ≢ υ′ → v ⟦ upper ⟧-smooth
data _with-rough : Letter → Set where
add-rough-vowel : ∀ {v} → v vowel → v with-rough
add-rough-ρ : ρ′ with-rough
data _iota-subscript : Letter → Set where
add-iota-subscript : ∀ {v} → v vowel → v ∈ iota-subscript-letters → v iota-subscript
data _⟦_⟧-breathing : Letter → Case → Set where
smooth : ∀ {ℓ c} → ℓ ⟦ c ⟧-smooth → ℓ ⟦ c ⟧-breathing
rough : ∀ {ℓ c} → ℓ with-rough → ℓ ⟦ c ⟧-breathing
data _long-vowel : Letter → Set where
make-long-vowel : ∀ {v} → v vowel → ¬ v always-short → v long-vowel
data _accent : Letter → Set where
acute : ∀ {ℓ} → ℓ vowel → ℓ accent
grave : ∀ {ℓ} → ℓ vowel → ℓ accent
circumflex : ∀ {ℓ} → ℓ long-vowel → ℓ accent
data Token : Set where
unmarked : (ℓ : Letter) → (c : Case) → Token
with-accent : (ℓ : Letter) → (c : Case) → ℓ accent → Token
with-breathing : (ℓ : Letter) → (c : Case) → ℓ ⟦ c ⟧-breathing → Token
with-accent-breathing : (ℓ : Letter) → (c : Case) → ℓ accent → ℓ ⟦ c ⟧-breathing → Token
with-accent-breathing-iota : (ℓ : Letter) → (c : Case) → ℓ accent → ℓ ⟦ c ⟧-breathing → ℓ iota-subscript → Token
with-diaeresis : (ℓ : Letter) → (c : Case) → ℓ diaeresis → Token
with-accent-diaeresis : (ℓ : Letter) → (c : Case) → ℓ accent → ℓ diaeresis → Token
with-accent-iota : (ℓ : Letter) → (c : Case) → ℓ accent → ℓ iota-subscript → Token
with-breathing-iota : (ℓ : Letter) → (c : Case) → ℓ ⟦ c ⟧-breathing → ℓ iota-subscript → Token
with-iota : (ℓ : Letter) → (c : Case) → ℓ iota-subscript → Token
final : (ℓ : Letter) → (c : Case) → ℓ ⟦ c ⟧-final → Token
-- Constructions
-- Α α
α-vowel : α′ vowel
α-vowel = is-vowel here
¬α-always-short : ¬ α′ always-short
¬α-always-short (is-always-short x (there (there ())))
α-long-vowel : α′ long-vowel
α-long-vowel = make-long-vowel α-vowel ¬α-always-short
α-smooth : α′ ⟦ lower ⟧-smooth
α-smooth = add-smooth-lower-vowel (is-vowel here)
Α-smooth : α′ ⟦ upper ⟧-smooth
Α-smooth = add-smooth-upper-vowel-not-Υ (is-vowel here) (λ ())
α-rough : α′ with-rough
α-rough = add-rough-vowel (is-vowel here)
α-iota-subscript : α′ iota-subscript
α-iota-subscript = add-iota-subscript (is-vowel here) here
-- Ε ε
ε-vowel : ε′ vowel
ε-vowel = is-vowel (there here)
ε-always-short : ε′ always-short
ε-always-short = is-always-short (is-vowel (there here)) here
ε-smooth : ε′ ⟦ lower ⟧-smooth
ε-smooth = add-smooth-lower-vowel (is-vowel (there here))
Ε-smooth : ε′ ⟦ upper ⟧-smooth
Ε-smooth = add-smooth-upper-vowel-not-Υ (is-vowel (there here)) (λ ())
ε-rough : ε′ with-rough
ε-rough = add-rough-vowel (is-vowel (there here))
-- Η η
η-vowel : η′ vowel
η-vowel = is-vowel (there (there here))
¬η-always-short : ¬ η′ always-short
¬η-always-short (is-always-short x (there (there ())))
η-long-vowel : η′ long-vowel
η-long-vowel = make-long-vowel (is-vowel (there (there here))) ¬η-always-short
η-smooth : η′ ⟦ lower ⟧-smooth
η-smooth = add-smooth-lower-vowel (is-vowel (there (there here)))
Η-smooth : η′ ⟦ upper ⟧-smooth
Η-smooth = add-smooth-upper-vowel-not-Υ (is-vowel (there (there here))) (λ ())
η-rough : η′ with-rough
η-rough = add-rough-vowel (is-vowel (there (there here)))
η-iota-subscript : η′ iota-subscript
η-iota-subscript = add-iota-subscript (is-vowel (there (there here))) (there here)
-- Ι ι
ι-vowel : ι′ vowel
ι-vowel = is-vowel (there (there (there here)))
¬ι-always-short : ¬ ι′ always-short
¬ι-always-short (is-always-short x (there (there ())))
ι-long-vowel : ι′ long-vowel
ι-long-vowel = make-long-vowel (is-vowel (there (there (there here)))) ¬ι-always-short
ι-smooth : ι′ ⟦ lower ⟧-smooth
ι-smooth = add-smooth-lower-vowel (is-vowel (there (there (there here))))
Ι-smooth : ι′ ⟦ upper ⟧-smooth
Ι-smooth = add-smooth-upper-vowel-not-Υ
(is-vowel (there (there (there here)))) (λ ())
ι-rough : ι′ with-rough
ι-rough = add-rough-vowel (is-vowel (there (there (there here))))
ι-diaeresis : ι′ diaeresis
ι-diaeresis = add-diaeresis (is-vowel (there (there (there here)))) here
-- Ο ο
ο-vowel : ο′ vowel
ο-vowel = is-vowel (there (there (there (there here))))
ο-always-short : ο′ always-short
ο-always-short = is-always-short (is-vowel (there (there (there (there here)))))
(there here)
ο-smooth : ο′ ⟦ lower ⟧-smooth
ο-smooth = add-smooth-lower-vowel
(is-vowel (there (there (there (there here)))))
Ο-smooth : ο′ ⟦ upper ⟧-smooth
Ο-smooth = add-smooth-upper-vowel-not-Υ
(is-vowel (there (there (there (there here))))) (λ ())
ο-rough : ο′ with-rough
ο-rough = add-rough-vowel (is-vowel (there (there (there (there here)))))
-- Ρ ρ
ρ-smooth : ρ′ ⟦ lower ⟧-smooth
ρ-smooth = add-smooth-ρ
ρ-rough : ρ′ with-rough
ρ-rough = add-rough-ρ
-- Σ σ
σ-final : σ′ ⟦ lower ⟧-final
σ-final = make-final
-- Υ υ
υ-vowel : υ′ vowel
υ-vowel = is-vowel (there (there (there (there (there here)))))
¬υ-always-short : ¬ υ′ always-short
¬υ-always-short (is-always-short x (there (there ())))
υ-long-vowel : υ′ long-vowel
υ-long-vowel = make-long-vowel υ-vowel ¬υ-always-short
υ-smooth : υ′ ⟦ lower ⟧-smooth
υ-smooth = add-smooth-lower-vowel
(is-vowel (there (there (there (there (there here))))))
υ-rough : υ′ with-rough
υ-rough = add-rough-vowel
(is-vowel (there (there (there (there (there here))))))
υ-diaeresis : υ′ diaeresis
υ-diaeresis = add-diaeresis
(is-vowel (there (there (there (there (there here))))))
(there here)
-- Ω ω
ω-vowel : ω′ vowel
ω-vowel = is-vowel (there (there (there (there (there (there here))))))
¬ω-always-short : ¬ ω′ always-short
¬ω-always-short (is-always-short x (there (there ())))
ω-long-vowel : ω′ long-vowel
ω-long-vowel = make-long-vowel ω-vowel ¬ω-always-short
ω-smooth : ω′ ⟦ lower ⟧-smooth
ω-smooth = add-smooth-lower-vowel
(is-vowel (there (there (there (there (there (there here)))))))
Ω-smooth : ω′ ⟦ upper ⟧-smooth
Ω-smooth = add-smooth-upper-vowel-not-Υ
(is-vowel (there (there (there (there (there (there here)))))))
(λ ())
ω-rough : ω′ with-rough
ω-rough = add-rough-vowel
(is-vowel (there (there (there (there (there (there here)))))))
ω-iota-subscript : ω′ iota-subscript
ω-iota-subscript = add-iota-subscript
(is-vowel (there (there (there (there (there (there here)))))))
(there (there here))
-- Mapping
get-letter : Token → Letter
get-letter (unmarked ℓ _) = ℓ
get-letter (with-accent ℓ _ _) = ℓ
get-letter (with-breathing ℓ _ _) = ℓ
get-letter (with-accent-breathing ℓ _ _ _) = ℓ
get-letter (with-accent-breathing-iota ℓ _ _ _ _) = ℓ
get-letter (with-diaeresis ℓ _ _) = ℓ
get-letter (with-accent-diaeresis ℓ _ _ _) = ℓ
get-letter (with-accent-iota ℓ _ _ _) = ℓ
get-letter (with-breathing-iota ℓ _ _ _) = ℓ
get-letter (with-iota ℓ _ _) = ℓ
get-letter (final ℓ _ _) = ℓ
get-case : Token → Case
get-case (unmarked _ c) = c
get-case (with-accent _ c _) = c
get-case (with-breathing _ c _) = c
get-case (with-accent-breathing _ c _ _) = c
get-case (with-accent-breathing-iota _ c _ _ _) = c
get-case (with-diaeresis _ c _) = c
get-case (with-accent-diaeresis _ c _ _) = c
get-case (with-accent-iota _ c _ _) = c
get-case (with-breathing-iota _ c _ _) = c
get-case (with-iota _ c _) = c
get-case (final _ c _) = c
data Accent : Set where
acute-mark grave-mark circumflex-mark : Accent
letter-to-accent : ∀ {v} → v accent → Accent
letter-to-accent (acute x) = acute-mark
letter-to-accent (grave x) = grave-mark
letter-to-accent (circumflex x) = circumflex-mark
get-accent : Token → Maybe Accent
get-accent (with-accent _ _ a) = just (letter-to-accent a)
get-accent (with-accent-breathing _ _ a _) = just (letter-to-accent a)
get-accent (with-accent-breathing-iota _ _ a _ _) = just (letter-to-accent a)
get-accent (with-accent-diaeresis _ _ a _) = just (letter-to-accent a)
get-accent (with-accent-iota _ _ a _) = just (letter-to-accent a)
get-accent _ = nothing
data Breathing : Set where
smooth-mark rough-mark : Breathing
letter-to-breathing : ∀ {ℓ c} → ℓ ⟦ c ⟧-breathing → Breathing
letter-to-breathing (smooth x) = smooth-mark
letter-to-breathing (rough x) = rough-mark
get-breathing : Token → Maybe Breathing
get-breathing (with-breathing _ _ x) = just (letter-to-breathing x)
get-breathing (with-accent-breathing _ _ _ x) = just (letter-to-breathing x)
get-breathing (with-accent-breathing-iota _ _ _ x _) = just (letter-to-breathing x)
get-breathing (with-breathing-iota _ _ x _) = just (letter-to-breathing x)
get-breathing _ = nothing
data IotaSubscript : Set where
iota-subscript-mark : IotaSubscript
get-iota-subscript : Token → Maybe IotaSubscript
get-iota-subscript (with-accent-breathing-iota _ _ _ _ _) = just iota-subscript-mark
get-iota-subscript (with-accent-iota _ _ _ _) = just iota-subscript-mark
get-iota-subscript (with-breathing-iota _ _ _ _) = just iota-subscript-mark
get-iota-subscript _ = nothing
data Diaeresis : Set where
diaeresis-mark : Diaeresis
get-diaeresis : Token → Maybe Diaeresis
get-diaeresis (with-diaeresis _ _ _) = just diaeresis-mark
get-diaeresis (with-accent-diaeresis _ _ _ _) = just diaeresis-mark
get-diaeresis _ = nothing
data FinalForm : Set where
final-form : FinalForm
get-final-form : Token → Maybe FinalForm
get-final-form (final _ _ _) = just final-form
get-final-form _ = nothing
| {
"alphanum_fraction": 0.653069005,
"avg_line_length": 32.3827160494,
"ext": "agda",
"hexsha": "3b207a228f6c8e035621923c28792b27c38087ef",
"lang": "Agda",
"max_forks_count": 5,
"max_forks_repo_forks_event_max_datetime": "2017-06-11T11:25:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-27T22:34:13.000Z",
"max_forks_repo_head_hexsha": "915c46c27c7f8aad5907474d8484f2685a4cd6a7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "scott-fleischman/GreekGrammar",
"max_forks_repo_path": "agda/Text/Greek/Script.agda",
"max_issues_count": 13,
"max_issues_repo_head_hexsha": "915c46c27c7f8aad5907474d8484f2685a4cd6a7",
"max_issues_repo_issues_event_max_datetime": "2020-09-07T11:58:38.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-28T20:04:08.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "scott-fleischman/GreekGrammar",
"max_issues_repo_path": "agda/Text/Greek/Script.agda",
"max_line_length": 114,
"max_stars_count": 44,
"max_stars_repo_head_hexsha": "915c46c27c7f8aad5907474d8484f2685a4cd6a7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "scott-fleischman/GreekGrammar",
"max_stars_repo_path": "agda/Text/Greek/Script.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-06T15:41:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-29T14:48:51.000Z",
"num_tokens": 3705,
"size": 10492
} |
module Partiality where
{- port from http://www.soimort.org/posts/programs-and-proofs/ -}
open import Data.Bool using (Bool; false; true)
open import Data.Maybe using (Maybe; just; nothing)
open import Data.Char using (_==_) renaming (Char to Symbol)
open import Coinduction using (∞; ♯_; ♭)
-- open import Category.Monad.Partiality renaming (monad to PM)
-- open import Category.Monad using (RawMonad; module RawMonad)
data Expr : Set where
var : Symbol → Expr
lambda : Symbol → Expr → Expr
app : Expr → Expr → Expr
data Function : Set where
def : Expr → Function
mutual
data Env : Set where
ε : Env
_↦_,_ : Symbol → Value → Env → Env
data Value : Set where
closure : Function → Env → Value
exception : Value
lookup : Symbol → Env → Maybe Value
lookup sym ε = nothing
lookup sym (sym′ ↦ val , env) with sym == sym′
... | true = just val
... | false = lookup sym env
-- partiality monad
data _⊥ (A : Set) : Set where
now : A → A ⊥
later : ∞ (A ⊥) → A ⊥
return : {a : Set} → a → a ⊥
return = now
_>>=_ : {a b : Set} → a ⊥ → (a → b ⊥) → b ⊥
(now x) >>= f = f x
(later x) >>= f = later (♯ (♭ x >>= f))
infixl 40 _>>=_
{-# TERMINATING #-}
force : Value ⊥ → Value
force (now x) = x
force (later x) = force (♭ x)
mutual
{-# TERMINATING #-} -- TODO: ???
interp : Expr → Env → Value ⊥
interp (var x) env with lookup x env
... | just val = now val
... | nothing = now exception
interp (lambda x e) env = now (closure (def (lambda x e)) env)
interp (app e₁ e₂) env = later (♯ apply (interp e₁ env) (interp e₂ env))
apply : Value ⊥ → Value ⊥ → Value ⊥
apply (later f) a = later (♯ apply (♭ f) a)
apply (now (closure (def (lambda x e)) env)) a =
a >>= \a′ → interp e (x ↦ a′ , env)
-- let open RawMonad PM in a >>= \a′ → interp e (x ↦ a′ , env)
apply _ _ = now exception
e0 = ε
t1 = lambda 'a' (var 'a')
t2 = app (lambda 'x' (var 'x')) (lambda 'a' (var 'a'))
t3 = app (app (lambda 'f' (lambda 'x' (app (var 'f') (var 'x'))))
(lambda 'a' (var 'a')))
(lambda 'b' (var 'b'))
t4 = app (lambda 'x' (app (var 'x') (var 'x')))
(lambda 'x' (app (var 'x') (var 'x')))
r1 = force (interp t1 e0)
r2 = force (interp t2 e0)
r3 = force (interp t3 e0)
r4 = force (interp t4 e0)
| {
"alphanum_fraction": 0.5705548274,
"avg_line_length": 27.25,
"ext": "agda",
"hexsha": "f4b92fd3172fd3bff220f0d5e7b6cb7b3d95afa8",
"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": "2c364c4e2a34ead9d99b303bad50f11e5c1ff706",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "scturtle/fun.hs",
"max_forks_repo_path": "Partiality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2c364c4e2a34ead9d99b303bad50f11e5c1ff706",
"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": "scturtle/fun.hs",
"max_issues_repo_path": "Partiality.agda",
"max_line_length": 74,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2c364c4e2a34ead9d99b303bad50f11e5c1ff706",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "scturtle/fun.hs",
"max_stars_repo_path": "Partiality.agda",
"max_stars_repo_stars_event_max_datetime": "2018-11-08T06:49:40.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-29T04:30:12.000Z",
"num_tokens": 788,
"size": 2289
} |
module Selective.Examples.Main-generated where
import Selective.Examples.PingPong as PingPong
import Selective.Examples.TestCall as Call
import Selective.Examples.TestCall2 as Call2
import Selective.Examples.Fibonacci as Fib
import Selective.Examples.Chat as Chat
import Selective.Examples.Bookstore as Bookstore
import Selective.Examples.TestAO as TestAO
import Selective.Examples.TestSelectiveReceive as SelectiveReceive
import Selective.Examples.TestSelectiveReceive-calc as SelectiveReceive-calc
open import Selective.Runtime
open import Selective.SimulationEnvironment
open import Selective.ActorMonad
import IO
open ∞ActorM
pingpongEntry = singleton-env (PingPong.spawner .force)
callEntry = singleton-env (Call.calltestActor .force)
call2Entry = singleton-env (Call2.calculator-test-actor .force)
fibEntry = singleton-env (Fib.spawner .force)
chatEntry = singleton-env (Chat.chat-supervisor .force)
bookstoreEntry = singleton-env (Bookstore.bookstore-supervisor .force)
testaoEntry = singleton-env (TestAO.calculator-test-actor .force)
testsrcalcEntry = singleton-env (SelectiveReceive-calc.calculator-test-actor .force)
testsrEntry = singleton-env (SelectiveReceive.receive-42-with-reference)
main = IO.run (run-env testsrcalcEntry)
| {
"alphanum_fraction": 0.8384244373,
"avg_line_length": 42.8965517241,
"ext": "agda",
"hexsha": "fe012dd13beba21357d7ee2906eebd9820b2b491",
"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": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Zalastax/singly-typed-actors",
"max_forks_repo_path": "src/Selective/Examples/Main-generated.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"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": "Zalastax/singly-typed-actors",
"max_issues_repo_path": "src/Selective/Examples/Main-generated.agda",
"max_line_length": 84,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zalastax/thesis",
"max_stars_repo_path": "src/Selective/Examples/Main-generated.agda",
"max_stars_repo_stars_event_max_datetime": "2018-02-02T16:44:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-02-02T16:44:43.000Z",
"num_tokens": 298,
"size": 1244
} |
open import Agda.Primitive
record Functor {a b} (F : Set a → Set b) : Set (lsuc a ⊔ b) where
field
fmap : ∀ {A B} → (A → B) → F A → F B
open Functor {{...}} public
module _ {a b} (F : Set a → Set b) where
record FunctorZero : Set (lsuc a ⊔ b) where
field
empty : ∀ {A} → F A
overlap {{super}} : Functor F
record Alternative : Set (lsuc a ⊔ b) where
infixl 3 _<|>_
field
_<|>_ : ∀ {A} → F A → F A → F A
overlap {{super}} : FunctorZero
open FunctorZero {{...}} public
open Alternative {{...}} public
record StateT {a} (S : Set a) (M : Set a → Set a) (A : Set a) : Set a where
no-eta-equality
constructor stateT
field runStateT : S → M A
open StateT public
module _ {a} {S : Set a} {M : Set a → Set a} where
instance
FunctorStateT : {{_ : Functor M}} → Functor {a = a} (StateT S M)
runStateT (fmap {{FunctorStateT}} f m) s = fmap f (runStateT m s)
FunctorZeroStateT : {{_ : FunctorZero M}} → FunctorZero {a = a} (StateT S M)
runStateT (empty {{FunctorZeroStateT}}) s = empty
AlternativeStateT : {{_ : Alternative M}} → Alternative {a = a} (StateT S M)
runStateT (_<|>_ {{AlternativeStateT}} x y) s = runStateT x s <|> runStateT y s
--- Example with some module parameter instantiations
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
data Vec (A : Set) : Nat → Set where
[] : Vec A 0
_∷_ : ∀ {n} → A → Vec A n → Vec A (suc n)
postulate
C₁ : Set → Set
record C₂ (A : Set) : Set where
field
f : A → A
overlap {{super}} : C₁ A
open C₂ {{...}}
postulate
T : (A : Set) → A → Set
module M (A : Set) (n : Nat) (xs : Vec A n) where
unpackT : Vec A n → Set
unpackT (x ∷ xs) = C₂ (T A x)
unpackT [] = ⊤
postulate instance C₁T : ∀ {x} {{C₁A : C₁ A}} → C₁ (T A x)
C₂T : {{C₂A : C₂ A}} (ys : Vec A n) → unpackT ys
C₂T [] = _
f {{C₂T (y ∷ ys)}} x = x
| {
"alphanum_fraction": 0.5696808511,
"avg_line_length": 24.1025641026,
"ext": "agda",
"hexsha": "416f8f55ead530629d8abcb8fc319a7e6c8e3bc8",
"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/Issue2288b.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/Issue2288b.agda",
"max_line_length": 83,
"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/Issue2288b.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": 701,
"size": 1880
} |
module Issue251 where
record Foo : Set₁ where
field
A : Set
B : Set
foo : Set → Set → Foo
foo = λ A B → record {A = A; B = B}
| {
"alphanum_fraction": 0.5652173913,
"avg_line_length": 13.8,
"ext": "agda",
"hexsha": "a71ded125d44493b8a2f7107ba756091eb3d2d7b",
"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/Issue251.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/Issue251.agda",
"max_line_length": 35,
"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/Issue251.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": 49,
"size": 138
} |
{-# OPTIONS --without-K #-}
module PathLemmas where
open import Relation.Binary.PropositionalEquality using
(_≡_; sym; refl)
------------------------------------------------------------------------------
-- These also follow from irrelevance, but this is nicer
sym-sym : {A : Set} {x y : A} {p : x ≡ y} → sym (sym p) ≡ p
sym-sym {_} {x} {.x} {refl} = refl
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.4054054054,
"avg_line_length": 29.6,
"ext": "agda",
"hexsha": "66ba03ee0820971dafcda1cce674b904de54ced2",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/PathLemmas.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/PathLemmas.agda",
"max_line_length": 78,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/PathLemmas.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": 101,
"size": 444
} |
{-# OPTIONS --erased-cubical --safe #-}
module Interval where
open import Cubical.Core.Everything using (_≡_; Level; Type; Σ; _,_; fst; snd; _≃_; ~_)
open import Cubical.Foundations.Prelude using (refl; sym; _∙_; cong; transport; subst; funExt; transp; I; i0; i1)
--open import Cubical.Foundations.Function using (_∘_)
open import Cubical.Foundations.Univalence using (ua)
open import Cubical.Foundations.Isomorphism using (iso; Iso; isoToPath; section; retract; isoToEquiv)
open import Data.Bool using (Bool; true; false; _∨_; _∧_; not; if_then_else_)
open import Data.Integer using (ℤ; +_; -[1+_]; _-_; ∣_∣; -_)
open import Data.Integer.DivMod using (_modℕ_)
open import Data.Fin using (Fin; toℕ; #_)
open import Data.List using (List; []; _∷_; foldl; map; reverse; length; _++_; take; drop)
open import Data.Nat using (ℕ; zero; suc; _⊓_; _∸_) renaming (_≡ᵇ_ to _==_)
open import Data.Nat.DivMod using (_mod_)
open import Data.Sign using (Sign)
open import Data.String using (String; intersperse) renaming (_++_ to _++s_)
open import Data.Product using (_×_; _,_; Σ; proj₁; proj₂)
open import Data.Vec using (Vec; []; _∷_; lookup; replicate; _[_]%=_; toList; updateAt) renaming (map to vmap)
open import Pitch
open import Util using (allPairs; ◯pairs; firstPairs; _∘_)
-- Maximum number of interval classes (0 to 6).
ic7 : ℕ
ic7 = 7
PitchPair : Type
PitchPair = Pitch × Pitch
PCPair : Type
PCPair = PC × PC
-- Unordered pitch interval
-- Absolute distance in semitones between two pitches.
Upi : Type
Upi = ℕ
-- Ordered pitch interval
-- Relative distance in semitones between two pitches.
Opi : Type
Opi = ℤ
-- Interval Class
-- Also known as unodered pitch-class interval (upci).
IC : Type
IC = Fin ic7
-- (Ordered) pitch-class interval (also abbreviated opci)
PCI : Type
PCI = Fin s12
intervalWithinOctave : Upi → Upi
intervalWithinOctave i = toℕ (i mod s12)
absoluteInterval : Opi → Upi
absoluteInterval i = ∣ i ∣
makeSigned : Sign → Upi → Opi
makeSigned Sign.- zero = + 0
makeSigned Sign.- (suc i) = -[1+ i ]
makeSigned Sign.+ i = + i
-- Names for intervals
per1 = 0
min2 = 1
maj2 = 2
min3 = 3
maj3 = 4
per4 = 5
aug4 = 6
per5 = 7
min6 = 8
maj6 = 9
min7 = 10
maj7 = 11
per8 = 12
min9 = 13
maj9 = 14
min10 = 15
maj10 = 16
per11 = 17
aug11 = 18
per12 = 19
isConsonant : Upi → Bool
isConsonant iv =
(i == per1) ∨
(i == min3) ∨
(i == maj3) ∨
(i == per5) ∨
(i == min6) ∨
(i == maj6) ∨
(i == per8)
where i = intervalWithinOctave iv
isDissonant : Upi → Bool
isDissonant = not ∘ isConsonant
isPerfect : Upi → Bool
isPerfect iv =
(i == per1) ∨
(i == per4) ∨
(i == per5) ∨
(i == per8)
where i = intervalWithinOctave iv
isUnison : Upi → Bool
isUnison i = i == per1
isThird : Upi → Bool
isThird i = (i == min3) ∨ (i == maj3)
-- Half or whole step.
isStep : Upi → Bool
isStep i =
(i == min2) ∨
(i == maj2)
PitchInterval : Type
PitchInterval = Pitch × Upi
pitchIntervalToPitchPair : PitchInterval → PitchPair
pitchIntervalToPitchPair (p , n) = (p , transposePitch (+ n) p)
secondPitch : PitchInterval → Pitch
secondPitch = proj₂ ∘ pitchIntervalToPitchPair
pitchPairToOpi : PitchPair → Opi
pitchPairToOpi (p , q) = (+ q) - (+ p)
toIC : PCPair → IC
toIC (p , q) =
let x = toℕ (∣ (+ (toℕ q)) - (+ (toℕ p)) ∣ mod s12)
in x ⊓ (s12 ∸ x) mod ic7
toPCI : PCPair → PCI
toPCI (p , q) =
(((+ (toℕ q)) - (+ (toℕ p))) modℕ s12) mod s12
-- Assumes p ≤ q
toPitchInterval : PitchPair → PitchInterval
toPitchInterval pq = proj₁ pq , absoluteInterval (pitchPairToOpi pq)
-- DEPRECATED? Note that the first and last pitches are compared in normal order, not circular order.
◯pcIntervals : List PC → List PCI
◯pcIntervals = map toPCI ∘ ◯pairs
-- Note that the first and last pitches are compared in normal order, not circular order.
pcIntervals : List PC → List PCI
pcIntervals = map toPCI ∘ reverse ∘ firstPairs
stepUp : Pitch → Pitch → Bool
stepUp p q with pitchPairToOpi (p , q)
... | +_ n = isStep n
... | -[1+_] n = false
stepDown : Pitch → Pitch → Bool
stepDown p q with pitchPairToOpi (p , q)
... | +_ n = false
... | -[1+_] n = isStep n
-- Check if q is a passing tone between p and r
-- The interval between end points need to be a 3rd
isPassingTone : Pitch → Pitch → Pitch → Bool
isPassingTone p q r =
(stepUp p q ∧ stepUp q r) ∨ (stepDown p q ∧ stepDown q r) ∨
(isThird (absoluteInterval (pitchPairToOpi (p , r))))
moveUp : Pitch → Pitch → Bool
moveUp p q with pitchPairToOpi (p , q)
... | +_ _ = true
... | -[1+_] _ = false
moveDown : Pitch → Pitch → Bool
moveDown p q = not (moveUp p q)
-- Check if q is left by step in the opposite direction from its approach
isOppositeStep : Pitch → Pitch → Pitch → Bool
isOppositeStep p q r = (moveUp p q ∧ stepDown q r) ∨ (moveDown p q ∧ stepUp q r)
transposePitchInterval : Opi → Pitch → Pitch
transposePitchInterval z p = transposePitch z p
-- transpose pitch class by pci
Tpci : PCI → PC → PC
Tpci n = Tp (toℕ n)
----------
-- Interval Class Vector
ICV : Type
ICV = Vec ℕ ic7
emptyICV : ICV
emptyICV = 0 ∷ 0 ∷ 0 ∷ 0 ∷ 0 ∷ 0 ∷ 0 ∷ []
icVector : List PC → ICV
icVector pcs =
foldl
(λ icv pc → updateAt (toIC pc) suc icv)
(updateAt (# 0) (λ _ → length pcs) emptyICV)
(allPairs pcs)
----------
--Construct matrix out of PC row
matrix : List PC → List (List PC)
matrix [] = []
matrix pcs@(pc ∷ _) =
let r0 = map ((Tpci ∘ Ip) pc) pcs -- start first row at 0
in map (λ p → map ((Tpci ∘ Ip) p) r0) r0
showMatrix : List (List PC) → String
showMatrix m = intersperse "\n" (map showPCs m)
{-
rr : List PC
rr = # 10 ∷ # 9 ∷ # 7 ∷ # 0 ∷ []
rp = rr ++ map (Tp 4) rr ++ map (Tp 8) rr
-- Belle's matrix
aa = showMatrix (matrix rp)
0 b 9 2 4 3 1 6 8 7 5 a
1 0 a 3 5 4 2 7 9 8 6 b
3 2 0 5 7 6 4 9 b a 8 1
a 9 7 0 2 1 b 4 6 5 3 8
8 7 5 a 0 b 9 2 4 3 1 6
9 8 6 b 1 0 a 3 5 4 2 7
b a 8 1 3 2 0 5 7 6 4 9
6 5 3 8 a 9 7 0 2 1 b 4
4 3 1 6 8 7 5 a 0 b 9 2
5 4 2 7 9 8 6 b 1 0 a 3
7 6 4 9 b a 8 1 3 2 0 5
2 1 b 4 6 5 3 8 a 9 7 0
rd : List PC
rd2 = reverse (map (Tp 4) rr)
rd3' = reverse (map (Tp 8) rr)
rd3 = reverse (take 2 rd3') ++ reverse (drop 2 rd3')
rd = rr ++ rd2 ++ rd3
-- Dan's matrix
ad = showMatrix (matrix rd)
0 b 9 2 6 1 3 4 5 a 8 7
1 0 a 3 7 2 4 5 6 b 9 8
3 2 0 5 9 4 6 7 8 1 b a
a 9 7 0 4 b 1 2 3 8 6 5
6 5 3 8 0 7 9 a b 4 2 1
b a 8 1 5 0 2 3 4 9 7 6
9 8 6 b 3 a 0 1 2 7 5 4
8 7 5 a 2 9 b 0 1 6 4 3
7 6 4 9 1 8 a b 0 5 3 2
2 1 b 4 8 3 5 6 7 0 a 9
4 3 1 6 a 5 7 8 9 2 0 b
5 4 2 7 b 6 8 9 a 3 1 0
-}
| {
"alphanum_fraction": 0.6307244601,
"avg_line_length": 24.545112782,
"ext": "agda",
"hexsha": "2457a0484f27dfbb524dc01461c30763ae790ac3",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z",
"max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/MusicTools",
"max_forks_repo_path": "agda/Interval.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/MusicTools",
"max_issues_repo_path": "agda/Interval.agda",
"max_line_length": 117,
"max_stars_count": 28,
"max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/MusicTools",
"max_stars_repo_path": "agda/Interval.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z",
"num_tokens": 2656,
"size": 6529
} |
{-# OPTIONS --without-K #-}
open import HoTT.Base
open import HoTT.Equivalence
open import HoTT.Identity.Pi
open import HoTT.Identity.Product
module HoTT.Product.Universal where
×-univ : ∀ {i j k} {X : 𝒰 i} (A : X → 𝒰 j) (B : X → 𝒰 k) →
((c : X) → A c × B c) ≃ Π X A × Π X B
×-univ {X = X} A B = let open Iso in iso→eqv λ where
.f f → pr₁ ∘ f , pr₂ ∘ f
.g f x → pr₁ f x , pr₂ f x
.η f → funext (×-uniq ∘ f)
.ε f → ×-pair⁼ (refl , refl)
| {
"alphanum_fraction": 0.5582417582,
"avg_line_length": 28.4375,
"ext": "agda",
"hexsha": "9a36a5f360b7c65aa6566ed4a77ec95b7313814f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "michaelforney/hott",
"max_forks_repo_path": "HoTT/Product/Universal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "michaelforney/hott",
"max_issues_repo_path": "HoTT/Product/Universal.agda",
"max_line_length": 58,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ef4d9fbb9cc0352657f1a6d0d3534d4c8a6fd508",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "michaelforney/hott",
"max_stars_repo_path": "HoTT/Product/Universal.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 196,
"size": 455
} |
{-# OPTIONS --without-K #-}
module Spaces.Spheres where
open import Base
open import Spaces.Suspension public
-- [Sⁿ n] is the sphere of dimension n
Sⁿ : ℕ → Set
Sⁿ 0 = bool
Sⁿ (S n) = suspension (Sⁿ n)
⋆Sⁿ : (n : ℕ) → Sⁿ n
⋆Sⁿ 0 = true
⋆Sⁿ (S n) = north (Sⁿ n) | {
"alphanum_fraction": 0.6301886792,
"avg_line_length": 17.6666666667,
"ext": "agda",
"hexsha": "608113cad22081fb51169db40eff492faa575ba9",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "old/Spaces/Spheres.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "old/Spaces/Spheres.agda",
"max_line_length": 38,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "old/Spaces/Spheres.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 116,
"size": 265
} |
-- Properties of natural number
{-# OPTIONS --without-K --safe #-}
-- agad-stdlib
open import Relation.Binary.PropositionalEquality
module TypeTheory.Nat.Properties
{a}
(N : Set a)
(zero : N)
(suc : N → N)
(ind : ∀ {p} (P : N → Set p) → P zero → (∀ k → P k → P (suc k)) → ∀ n → P n)
(ind-base : ∀ {p} (P : N → Set p) P-base P-step →
ind P P-base P-step zero ≡ P-base)
(ind-step : ∀ {p} (P : N → Set p) P-base P-step n →
ind P P-base P-step (suc n) ≡ P-step n (ind P P-base P-step n))
where
-- agda-stdlib
open import Axiom.UniquenessOfIdentityProofs
open import Level renaming (zero to lzero; suc to lsuc)
open import Data.Bool using (Bool; true; false)
open import Data.Empty
open import Data.Unit using (⊤ ; tt)
open import Data.Product
import Data.Product.Properties as Prodₚ
open import Data.Sum as Sum
open import Function.Base
import Relation.Binary as B
open import Relation.Nullary
import Relation.Nullary.Decidable as NDec
-- agda-misc
open import TypeTheory.Nat.Operations N zero suc ind ind-base ind-step
open ≡-Reasoning
private
variable
A : Set a
-- Properties of rec
rec-base : ∀ {A : Set a} (z : A) s → rec z s zero ≡ z
rec-base {A} z s = ind-base (λ _ → A) z λ k x → s x
rec-step : ∀ {A : Set a} (z : A) s n → rec z s (suc n) ≡ s (rec z s n)
rec-step {A} z s n = ind-step (λ _ → A) z (λ k x → s x) n
ind2-zz : ∀ {p} (P : N → N → Set p) Pzz Pmn→Pms Pmn→Psn →
ind2 P Pzz Pmn→Pms Pmn→Psn zero zero ≡ Pzz
ind2-zz P Pzz Pmn→Pms Pmn→Psn = begin
ind2 P Pzz Pmn→Pms Pmn→Psn zero zero
≡⟨⟩
ind
(λ o → P o zero)
(ind (λ p → P zero p) Pzz (λ k Pzk → Pmn→Pms zero k Pzk) zero)
(λ k Pkn → ind (λ r → P (suc k) r) (( λ k → ind (λ x → P x zero) Pzz (λ k₂ Pk₂zero → Pmn→Psn k₂ zero Pk₂zero) k) (suc k))
(λ k₁ P[1+k,k₁] → Pmn→Pms (suc k) k₁ P[1+k,k₁]) zero)
zero
≡⟨ ind-base _ _ _ ⟩
ind (λ p → P zero p) Pzz (Pmn→Pms zero) zero
≡⟨ ind-base _ _ _ ⟩
Pzz
∎
where open ≡-Reasoning
---------------------------------------------------------------------------
-- Properties of pred
pred-zero : pred zero ≡ zero
pred-zero = ind-base (λ _ → N) zero (λ k x → k)
pred-suc : ∀ n → pred (suc n) ≡ n
pred-suc n = ind-step (λ _ → N) zero (λ k x → k) n
-- Properties of suc
suc-injective : ∀ {m n} → suc m ≡ suc n → m ≡ n
suc-injective {m} {n} 1+m≡1+n = begin
m ≡⟨ sym $ pred-suc m ⟩
pred (suc m) ≡⟨ cong pred 1+m≡1+n ⟩
pred (suc n) ≡⟨ pred-suc n ⟩
n ∎
-- Properties of caseNat
caseNat-base : ∀ {l} {A : Set l} (z s : A) → caseNat z s zero ≡ z
caseNat-base z s = ind-base (λ x → _) z λ k x → s
caseNat-step : ∀ {l} {A : Set l} (z s : A) n → caseNat z s (suc n) ≡ s
caseNat-step z s n = ind-step (λ x → _) z (λ k x → s) n
NotZero : ∀ n → Set
NotZero n = caseNat ⊥ ⊤ n
NotZero[zero]≡⊥ : NotZero zero ≡ ⊥
NotZero[zero]≡⊥ = caseNat-base ⊥ ⊤
NotZero[suc[n]]≡⊤ : ∀ n → NotZero (suc n) ≡ ⊤
NotZero[suc[n]]≡⊤ n = caseNat-step ⊥ ⊤ n
private
transport : ∀ {a} {A B : Set a} → A ≡ B → A → B
transport eq = subst id eq
NotZero[suc[n]] : ∀ (n : N) → NotZero (suc n)
NotZero[suc[n]] n = transport (sym $ NotZero[suc[n]]≡⊤ n) tt
s≢z : ∀ (n : N) → suc n ≢ zero
s≢z n eq = transport NotZero[zero]≡⊥ $ subst NotZero eq (NotZero[suc[n]] n)
z≢s : ∀ (n : N) → zero ≢ suc n
z≢s n eq = s≢z n (sym eq)
1+n≢n : ∀ n → suc n ≢ n
1+n≢n n = ind (λ x → suc x ≢ x) (s≢z zero)
(λ k 1+k≢k 1+[1+k]≡1+k → 1+k≢k (suc-injective 1+[1+k]≡1+k)) n
caseNat-extract-zero : ∀ {l} {A : Set l} (z s : A) n →
z ≢ s →
caseNat z s n ≡ z → n ≡ zero
caseNat-extract-zero z s n z≢s =
ind (λ k → caseNat z s k ≡ z → k ≡ zero)
(λ x → refl)
(λ k c[z,s,k]≡z→k≡zero c[z,s,suc[k]]≡z → ⊥-elim $ z≢s
$ trans (sym c[z,s,suc[k]]≡z) (caseNat-step _ _ _) ) n
-- Properties of _+_
+-identityˡ : ∀ n → zero + n ≡ n
+-identityˡ n = rec-base n suc
suc-+ : ∀ m n → suc m + n ≡ suc (m + n)
suc-+ m n = rec-step n suc m
+-identityʳ : ∀ n → n + zero ≡ n
+-identityʳ n₀ = ind (λ n → n + zero ≡ n) (+-identityˡ zero) step n₀
where
step : ∀ k → k + zero ≡ k → suc k + zero ≡ suc k
step k k+zero≡k = begin
suc k + zero ≡⟨ suc-+ k zero ⟩
suc (k + zero) ≡⟨ cong suc k+zero≡k ⟩
suc k ∎
+-assoc : ∀ m n o → (m + n) + o ≡ m + (n + o)
+-assoc m₀ n o = ind (λ m → (m + n) + o ≡ m + (n + o)) base step m₀
where
base : (zero + n) + o ≡ zero + (n + o)
base = begin
(zero + n) + o ≡⟨ cong (_+ o) $ +-identityˡ n ⟩
n + o ≡⟨ sym $ +-identityˡ (n + o) ⟩
zero + (n + o) ∎
step : ∀ k → (k + n) + o ≡ k + (n + o) → (suc k + n) + o ≡ suc k + (n + o)
step k [k+n]+o≡k+[n+o] = begin
(suc k + n) + o ≡⟨ cong (_+ o) $ suc-+ k n ⟩
suc (k + n) + o ≡⟨ suc-+ (k + n) o ⟩
suc ((k + n) + o) ≡⟨ cong suc [k+n]+o≡k+[n+o] ⟩
suc (k + (n + o)) ≡⟨ sym $ suc-+ k (n + o) ⟩
suc k + (n + o) ∎
suc≡one+ : ∀ n → suc n ≡ one + n
suc≡one+ n = begin
suc n ≡⟨ cong suc (sym $ +-identityˡ n) ⟩
suc (zero + n) ≡⟨ sym $ suc-+ zero n ⟩
suc zero + n ∎
+-suc : ∀ m n → m + suc n ≡ suc m + n
+-suc m₀ n = ind (λ m → m + suc n ≡ suc m + n)
(begin
zero + suc n ≡⟨ +-identityˡ (suc n) ⟩
suc n ≡⟨ cong suc (sym $ +-identityˡ n) ⟩
suc (zero + n) ≡⟨ sym $ suc-+ zero n ⟩
suc zero + n ∎
)
(λ m m+[1+n]≡[1+m]+n → begin
suc m + suc n ≡⟨ suc-+ m (suc n) ⟩
suc (m + suc n) ≡⟨ cong suc m+[1+n]≡[1+m]+n ⟩
suc (suc m + n) ≡⟨ sym $ suc-+ (suc m) n ⟩
suc (suc m) + n ∎
)
m₀
+-comm : ∀ m n → m + n ≡ n + m
+-comm m₀ n =
ind (λ m → m + n ≡ n + m)
(begin
zero + n ≡⟨ +-identityˡ n ⟩
n ≡⟨ sym $ +-identityʳ n ⟩
n + zero ∎
)
(λ m m+n≡n+m → begin
suc m + n ≡⟨ suc-+ m n ⟩
suc (m + n) ≡⟨ cong suc m+n≡n+m ⟩
suc (n + m) ≡⟨ sym $ suc-+ n m ⟩
suc n + m ≡⟨ sym $ +-suc n m ⟩
n + suc m ∎
)
m₀
+-cancelˡ-≡ : ∀ m n o → (m + n) ≡ (m + o) → n ≡ o
+-cancelˡ-≡ m n o =
ind (λ k → k + n ≡ k + o → n ≡ o)
(λ zero+n≡zero+o → begin
n ≡⟨ sym $ +-identityˡ n ⟩
zero + n ≡⟨ zero+n≡zero+o ⟩
zero + o ≡⟨ +-identityˡ o ⟩
o ∎)
(λ k k+n≡k+o→n≡o suck+n≡suck+o → begin
n ≡⟨ k+n≡k+o→n≡o $ suc-injective $ (begin
suc (k + n) ≡⟨ sym $ suc-+ k n ⟩
suc k + n ≡⟨ suck+n≡suck+o ⟩
suc k + o ≡⟨ suc-+ k o ⟩
suc (k + o) ∎
) ⟩
o ∎)
m
+-cancelʳ-≡ : ∀ m n o → (m + n) ≡ (o + n) → m ≡ o
+-cancelʳ-≡ m n o m+n≡o+n = +-cancelˡ-≡ n m o (begin
n + m ≡⟨ +-comm n m ⟩
m + n ≡⟨ m+n≡o+n ⟩
o + n ≡⟨ +-comm o n ⟩
n + o ∎)
+-conicalˡ : ∀ m n → m + n ≡ zero → m ≡ zero
+-conicalˡ m n =
ind (λ k → k + n ≡ zero → k ≡ zero) (λ _ → refl)
(λ k k+n≡zero→k≡zero suck+n≡zero →
⊥-elim $ z≢s (k + n) $ trans (sym suck+n≡zero) (suc-+ k n))
m
+-conicalʳ : ∀ m n → m + n ≡ zero → n ≡ zero
+-conicalʳ m n m+n≡zero = +-conicalˡ n m (trans (+-comm n m) m+n≡zero)
-- Order
z≤n : ∀ {n} → zero ≤ n
z≤n {n} = n , +-identityˡ n
s≤s : ∀ {m n} → m ≤ n → suc m ≤ suc n
s≤s {m} {n} (o , m+o≡n) = o , trans (suc-+ m o) (cong suc m+o≡n)
≤-pred : ∀ {m n} → suc m ≤ suc n → m ≤ n
≤-pred {m} {n} (o , sucm+o≡sucn) =
o , suc-injective (trans (sym $ suc-+ m o) sucm+o≡sucn)
≤-refl : ∀ {n} → n ≤ n
≤-refl {n} = ind (λ n → n ≤ n) z≤n (λ k → s≤s) n
≤-reflexive : ∀ {m n} → m ≡ n → m ≤ n
≤-reflexive {m} {n} m≡n = subst (m ≤_) m≡n (≤-refl {m})
≤-step : ∀ {m n} → m ≤ n → m ≤ suc n
≤-step {m} {n} (o , m+o≡n) = suc o , (begin
m + suc o ≡⟨ +-suc m o ⟩
suc m + o ≡⟨ suc-+ m o ⟩
suc (m + o) ≡⟨ cong suc m+o≡n ⟩
suc n ∎)
≤-back : ∀ {m n} → suc m ≤ n → m ≤ n
≤-back {m} {n} (o , suc[m]+o≡n) = suc o , (begin
m + suc o ≡⟨ +-suc m o ⟩
suc m + o ≡⟨ suc[m]+o≡n ⟩
n ∎)
≤-steps : ∀ {m n} o → m ≤ n → m ≤ o + n
≤-steps {m} {n} o m≤n =
ind (λ k → m ≤ k + n)
(subst (m ≤_) (sym $ +-identityˡ n) m≤n)
(λ k m≤k+n → subst (m ≤_) (sym $ suc-+ k n) (≤-step m≤k+n))
o
≤-antisym : ∀ {m n} → m ≤ n → n ≤ m → m ≡ n
≤-antisym {m} {n} (o , m+o≡n) (p , n+p≡m) = begin
m ≡⟨ sym n+p≡m ⟩
n + p ≡⟨ cong (n +_) $ p≡zero ⟩
n + zero ≡⟨ +-identityʳ n ⟩
n ∎
where
m≡m+[o+p] : m ≡ m + (o + p)
m≡m+[o+p] = begin
m ≡⟨ sym n+p≡m ⟩
n + p ≡⟨ cong (_+ p) $ sym m+o≡n ⟩
(m + o) + p ≡⟨ +-assoc m o p ⟩
m + (o + p) ∎
zero≡o+p : zero ≡ o + p
zero≡o+p = +-cancelˡ-≡ m zero (o + p) (begin
m + zero ≡⟨ +-identityʳ m ⟩
m ≡⟨ m≡m+[o+p] ⟩
m + (o + p) ∎)
p≡zero : p ≡ zero
p≡zero = +-conicalʳ o p (sym zero≡o+p)
≤-trans : ∀ {m n o} → m ≤ n → n ≤ o → m ≤ o
≤-trans {m} {n} {o} (p , m+p≡n) (q , n+q≡o) = (p + q) , (begin
m + (p + q) ≡⟨ sym $ +-assoc m p q ⟩
(m + p) + q ≡⟨ cong (_+ q) m+p≡n ⟩
n + q ≡⟨ n+q≡o ⟩
o ∎)
n≤zero⇒n≡zero : ∀ {n} → n ≤ zero → n ≡ zero
n≤zero⇒n≡zero {n} (o , n+o≡zero) = +-conicalˡ n o n+o≡zero
-- +-mono-≤
zero<suc[n] : ∀ n → zero < suc n
zero<suc[n] n = s≤s z≤n
s<s : ∀ {m n} → m < n → suc m < suc n
s<s = s≤s
<-pred : ∀ {m n} → suc m < suc n → m < n
<-pred = ≤-pred
n≮zero : ∀ n → n ≮ zero
n≮zero n (m , sucn+m≡zero) = s≢z (n + m) $ trans (sym $ suc-+ n m) sucn+m≡zero
≤⇒≯ : ∀ {m n} → m ≤ n → m ≯ n
≤⇒≯ {m} {n} (o , m+o≡n) (p , suc[n]+p≡m) =
s≢z (p + o) $ +-cancelˡ-≡ n (suc (p + o)) zero $ begin
n + suc (p + o) ≡⟨ +-suc n (p + o) ⟩
suc n + (p + o) ≡⟨ sym $ +-assoc (suc n) p o ⟩
suc n + p + o ≡⟨ cong (_+ o) $ suc[n]+p≡m ⟩
m + o ≡⟨ m+o≡n ⟩
n ≡⟨ sym $ +-identityʳ n ⟩
n + zero ∎
<⇒≱ : ∀ {m n} → m < n → m ≱ n
<⇒≱ {m} {n} m<n n≤m = ≤⇒≯ n≤m m<n
n≮n : ∀ n → n ≮ n
n≮n n (m , sucn+m≡n) = z≢s m $ +-cancelˡ-≡ n zero (suc m) (begin
n + zero ≡⟨ +-identityʳ n ⟩
n ≡⟨ sym sucn+m≡n ⟩
suc n + m ≡⟨ sym $ +-suc n m ⟩
n + suc m ∎)
<⇒≢ : ∀ {m n} → m < n → m ≢ n
<⇒≢ {m} {n} m<n m≡n = n≮n m (subst (m <_) (sym m≡n) m<n)
>⇒≢ : ∀ {m n} → m > n → m ≢ n
>⇒≢ {m} {n} m>n m≡n = <⇒≢ m>n (sym m≡n)
≤⇒<∨≡ : ∀ {m n} → m ≤ n → m < n ⊎ m ≡ n
≤⇒<∨≡ {m} {n} (o , m+o≡n) =
ind (λ k → m + k ≡ n → m < n ⊎ m ≡ n)
(λ m+zero≡n → inj₂ (trans (sym $ +-identityʳ m) m+zero≡n))
(λ k _ m+suc[k]≡n → inj₁ (k , (begin
suc m + k ≡⟨ sym $ +-suc m k ⟩
m + suc k ≡⟨ m+suc[k]≡n ⟩
n ∎)))
o m+o≡n
<⇒≤ : ∀ {m n} → m < n → m ≤ n
<⇒≤ = ≤-back
n<suc[n] : ∀ n → n < suc n
n<suc[n] n = ≤-refl
<-step : ∀ {m} {n} → m < n → m < suc n
<-step {m} {n} m<n = ≤-step m<n
n∸zero≡n : ∀ n → n ∸ zero ≡ n
n∸zero≡n n = rec-base _ _
<⇒≯ : ∀ {m n} → m < n → m ≯ n
<⇒≯ {m} {n} m<n = ≤⇒≯ (<⇒≤ m<n)
m∸suc[n]≡pred[m∸n] : ∀ m n → m ∸ suc n ≡ pred (m ∸ n)
m∸suc[n]≡pred[m∸n] m n = rec-step _ _ _
zero∸n≡zero : ∀ n → zero ∸ n ≡ zero
zero∸n≡zero =
ind (λ n → zero ∸ n ≡ zero) (n∸zero≡n zero)
λ k zero∸k≡zero → (begin
zero ∸ suc k ≡⟨ m∸suc[n]≡pred[m∸n] zero k ⟩
pred (zero ∸ k) ≡⟨ cong pred zero∸k≡zero ⟩
pred zero ≡⟨ pred-zero ⟩
zero ∎)
suc[m]∸suc[n]≡m∸n : ∀ m n → suc m ∸ suc n ≡ m ∸ n
suc[m]∸suc[n]≡m∸n m =
ind (λ n → suc m ∸ suc n ≡ m ∸ n)
(begin
suc m ∸ suc zero ≡⟨ m∸suc[n]≡pred[m∸n] (suc m) zero ⟩
pred (suc m ∸ zero) ≡⟨ cong pred (n∸zero≡n (suc m)) ⟩
pred (suc m) ≡⟨ pred-suc m ⟩
m ≡⟨ sym $ n∸zero≡n m ⟩
m ∸ zero ∎)
λ k suc[m]∸suc[k]≡m∸k → begin
suc m ∸ suc (suc k) ≡⟨ m∸suc[n]≡pred[m∸n] (suc m) (suc k) ⟩
pred (suc m ∸ suc k) ≡⟨ cong pred suc[m]∸suc[k]≡m∸k ⟩
pred (m ∸ k) ≡⟨ sym $ m∸suc[n]≡pred[m∸n] m k ⟩
m ∸ suc k ∎
m+n∸m≡n : ∀ m n → m + n ∸ m ≡ n
m+n∸m≡n m n =
ind (λ k → (k + n) ∸ k ≡ n)
(begin
(zero + n) ∸ zero ≡⟨ cong (_∸ zero) $ +-identityˡ n ⟩
n ∸ zero ≡⟨ n∸zero≡n n ⟩
n ∎)
(λ k k+n∸k≡n → begin
suc k + n ∸ suc k ≡⟨ cong (_∸ suc k) $ suc-+ k n ⟩
suc (k + n) ∸ suc k ≡⟨ suc[m]∸suc[n]≡m∸n (k + n) k ⟩
k + n ∸ k ≡⟨ k+n∸k≡n ⟩
n ∎
)
m
m≤n⇒m+[n∸m]≡n : ∀ {m n} → m ≤ n → m + (n ∸ m) ≡ n
m≤n⇒m+[n∸m]≡n {m} {n} (o , m+o≡n) = begin
m + (n ∸ m) ≡⟨ cong (λ v → m + (v ∸ m)) (sym m+o≡n) ⟩
m + (m + o ∸ m) ≡⟨ cong (m +_) $ m+n∸m≡n m o ⟩
m + o ≡⟨ m+o≡n ⟩
n ∎
m∸[m+n]≡zero : ∀ m n → m ∸ (m + n) ≡ zero
m∸[m+n]≡zero m n =
ind (λ k → k ∸ (k + n) ≡ zero) (zero∸n≡zero (zero + n))
(λ k k∸[k+n]≡zero → begin
suc k ∸ (suc k + n) ≡⟨ cong (suc k ∸_) $ suc-+ k n ⟩
suc k ∸ suc (k + n) ≡⟨ suc[m]∸suc[n]≡m∸n k (k + n) ⟩
k ∸ (k + n) ≡⟨ k∸[k+n]≡zero ⟩
zero ∎) m
m≤n⇒m∸n≡zero : ∀ {m n} → m ≤ n → m ∸ n ≡ zero
m≤n⇒m∸n≡zero {m} {n} (o , m+o≡n) = begin
m ∸ n ≡⟨ cong (m ∸_) (sym m+o≡n) ⟩
m ∸ (m + o) ≡⟨ m∸[m+n]≡zero m o ⟩
zero ∎
pred[n]≡zero⇒n≡zero∨n≡one : ∀ n → pred n ≡ zero → n ≡ zero ⊎ n ≡ one
pred[n]≡zero⇒n≡zero∨n≡one =
ind (λ n → pred n ≡ zero → n ≡ zero ⊎ n ≡ suc zero)
(λ _ → inj₁ refl)
λ k pred[k]≡zero→k≡zero∨k≡one pred[suc[k]]≡zero → inj₂
(cong suc (trans (sym $ pred-suc k) pred[suc[k]]≡zero))
pred[m]≡suc[n]⇒m≡suc[suc[n]] : ∀ {m n} → pred m ≡ suc n → m ≡ suc (suc n)
pred[m]≡suc[n]⇒m≡suc[suc[n]] {m} {n} =
ind (λ k → pred k ≡ suc n → k ≡ suc (suc n))
(λ pred[zero]≡suc[n] → ⊥-elim $ z≢s n $ trans (sym pred-zero) pred[zero]≡suc[n] )
(λ k _ pred[suc[k]]≡suc[n] →
cong suc (trans (sym $ pred-suc k) pred[suc[k]]≡suc[n]))
m
≤⇒≤ᵇ : ∀ {m n} → m ≤ n → m ≤ᵇ n ≡ true
≤⇒≤ᵇ {m} {n} (o , m+o≡n) = begin
caseNat true false (m ∸ n)
≡⟨ cong (λ v → caseNat true false (m ∸ v)) $ sym m+o≡n ⟩
caseNat true false (m ∸ (m + o))
≡⟨ cong (caseNat true false) $ m∸[m+n]≡zero m o ⟩
caseNat true false zero
≡⟨ caseNat-base true false ⟩
true
∎
data Order (m n : N) : Set a where
lt : (m<n : m < n) → Order m n
eq : (m≡n : m ≡ n) → Order m n
gt : (m>n : m > n) → Order m n
private
order?-zero : ∀ n → Order zero n
order?-zero = ind (λ n → Order zero n) (eq refl) λ k _ → lt (zero<suc[n] k)
order?-suc : ∀ n k → Order k n → Order (suc k) n
order?-suc n k (lt k<n) with ≤⇒<∨≡ k<n
... | inj₁ suc[k]<n = lt suc[k]<n
... | inj₂ suc[k]≡n = eq suc[k]≡n
order?-suc n k (eq k≡n) = gt (subst (_< suc k) k≡n $ n<suc[n] k)
order?-suc n k (gt k>n) = gt (<-step k>n)
order? : ∀ m n → Order m n
order? m₀ n₀ =
ind (λ k → Order k n₀) (order?-zero n₀) (λ k → order?-suc n₀ k) m₀
_≟_ : ∀ m n → Dec (m ≡ n)
m ≟ n with order? m n
... | lt m<n = no (<⇒≢ m<n)
... | eq m≡n = yes m≡n
... | gt m>n = no (>⇒≢ m>n)
≡-irrelevant : ∀ {m n : N} (p q : m ≡ n) → p ≡ q
≡-irrelevant = M.≡-irrelevant
where module M = Decidable⇒UIP _≟_
≤-irrelevant : ∀ {m n : N} (p q : m ≤ n) → p ≡ q
≤-irrelevant {m} {n} (o , m+o≡n) (p , m+p≡n)
with +-cancelˡ-≡ m o p (trans m+o≡n (sym m+p≡n))
... | refl = cong (o ,_) (≡-irrelevant m+o≡n m+p≡n)
≤-proj₁-≡ : ∀ {m n : N} (p q : m ≤ n) → proj₁ p ≡ proj₁ q
≤-proj₁-≡ p q = Prodₚ.,-injectiveˡ (≤-irrelevant p q)
≰⇒> : ∀ {m n} → m ≰ n → m > n
≰⇒> {m} {n} m≰n with order? m n
... | lt m<n = ⊥-elim $ m≰n (<⇒≤ m<n)
... | eq m≡n = ⊥-elim $ m≰n (≤-reflexive m≡n)
... | gt m>n = m>n
≮⇒≥ : ∀ {m n} → m ≮ n → m ≥ n
≮⇒≥ {m} {n} m≮n with order? m n
... | lt m<n = ⊥-elim $ m≮n m<n
... | eq m≡n = ≤-reflexive (sym m≡n)
... | gt m>n = <⇒≤ m>n
_≤?_ : ∀ m n → Dec (m ≤ n)
m ≤? n with order? m n
... | lt m<n = yes (<⇒≤ m<n)
... | eq m≡n = yes (≤-reflexive m≡n)
... | gt m>n = no λ m≤n → ≤⇒≯ m≤n m>n
_<?_ : ∀ m n → Dec (m < n)
m <? n with order? m n
... | lt m<n = yes m<n
... | eq m≡n = no λ m<n → <⇒≢ m<n m≡n
... | gt m>n = no λ m<n → <⇒≯ m<n m>n
≤∧≢⇒< : ∀ {m n} → m ≤ n → m ≢ n → m < n
≤∧≢⇒< {m} {n} m≤n m≢n with order? m n
... | lt m<n = m<n
... | eq m≡n = ⊥-elim $ m≢n m≡n
... | gt m>n = ⊥-elim $ ≤⇒≯ m≤n m>n
private
subst-refl : ∀ {a b} {A : Set a} (B : A → Set b) {x : A} (y : B x) →
subst B refl y ≡ y
subst-refl _ _ = refl
subst-app : ∀ {a b} {A : Set a} {B : A → Set b}
(f : (x : A) → B x) {x y} (x≡y : x ≡ y) → subst B x≡y (f x) ≡ f y
subst-app f refl = refl
subst-cong-app : ∀ {a b c} {A : Set a} {B : Set b} {C : B → Set c}
(g : A → B) (f : (x : A) → C (g x)) {x y} (x≡y : x ≡ y) →
subst C (cong g x≡y) (f x) ≡ f y
subst-cong-app {C = C} g f {x} {y} x≡y = begin
subst C (cong g x≡y) (f x) ≡⟨ sym $ subst-∘ x≡y ⟩
subst (C ∘ g) x≡y (f x) ≡⟨ subst-app f x≡y ⟩
f y ∎
subst-other : ∀ {a b} {A : Set a} {B : A → Set b}
(f : (x : A) → B x) {x y z} (x≡z : x ≡ z) (y≡z : y ≡ z) →
subst B x≡z (f x) ≡ subst B y≡z (f y)
subst-other _ refl refl = refl
subst-other-g : ∀ {a b c} {A : Set a} {B : Set b} {C : B → Set c} →
B.Irrelevant (_≡_ {A = B}) →
∀ (g : A → B) (f : (x : A) → C (g x))
{x y z} (x≡y : x ≡ y) (gx≡z : g x ≡ z) (gy≡z : g y ≡ z) →
subst C gx≡z (f x) ≡ subst C gy≡z (f y)
subst-other-g B-irrelevant g f refl refl gy≡z with B-irrelevant gy≡z refl
subst-other-g B-irrelevant g f refl refl .refl | refl = refl
-- stdlib
-- variant of subst-application
subst-lemma : ∀ {a₁ a₂ b₁ b₂} {A₁ : Set a₁} {A₂ : Set a₂}
{B₁ : A₁ → Set b₁} {B₂ : A₂ → Set b₂}
(f : A₁ → A₂) (g : ∀ x → B₁ x → B₂ (f x))
{x₁ x₂ : A₁} (x₁≡x₂ : x₁ ≡ x₂) {y : B₁ x₁} →
subst B₂ (cong f x₁≡x₂) (g x₁ y) ≡ g x₂ (subst B₁ x₁≡x₂ y)
subst-lemma _ _ refl = refl
module _ {p} (P : N → N → Set p) where
inddiag-< : (∀ n → P zero (suc n)) → (∀ m n → P m n → P (suc m) (suc n)) →
∀ m o → P m (suc m + o)
inddiag-< Pzs Pss m o =
ind (λ k → P k (suc k + o))
(subst (P zero) (suc≡one+ o) (Pzs o))
(λ k P[k,suc[k]+o] → subst (P (suc k)) (sym $ suc-+ (suc k) o)
$ Pss k (suc k + o) P[k,suc[k]+o]) m
inddiag-≡ : P zero zero → (∀ m n → P m n → P (suc m) (suc n)) → ∀ n → P n n
inddiag-≡ Pzz Pss n = ind (λ k → P k k) Pzz (λ k Pkk → Pss k k Pkk) n
inddiag-> : (∀ n → P (suc n) zero) → (∀ m n → P m n → P (suc m) (suc n)) →
∀ n o → P (suc n + o) n
inddiag-> Psz Pss n o =
ind (λ k → P (suc k + o) k)
(subst (λ k → P k zero) (suc≡one+ o) (Psz o))
(λ k P[suc[k]+o,k] → subst (λ v → P v (suc k)) (sym $ suc-+ (suc k) o)
(Pss (suc k + o) k P[suc[k]+o,k]))
n
-- diagonal induction
inddiag : P zero zero →
(∀ n → P zero (suc n)) →
(∀ m → P (suc m) zero) →
(∀ m n → P m n → P (suc m) (suc n)) →
∀ m n → P m n
inddiag P-zz P-zs P-sz P-ss m n with order? m n
... | lt (o , sm+o≡n) = subst (P m) sm+o≡n (inddiag-< P-zs P-ss m o)
... | eq m≡n = subst (P m) m≡n (inddiag-≡ P-zz P-ss m)
... | gt (o , sn+o≡m) = subst (λ k → P k n) sn+o≡m (inddiag-> P-sz P-ss n o)
inddiag-zz : ∀ Pzz Pzs Psz Pss → inddiag Pzz Pzs Psz Pss zero zero ≡ Pzz
inddiag-zz Pzz Pzs Psz Pss with order? zero zero
... | lt m<n = ⊥-elim $ n≮n zero m<n
... | eq m≡n = begin
subst (P zero) m≡n (ind (λ k → P k k) Pzz (λ k → Pss k k) zero)
≡⟨ cong (λ v → subst (P zero) v _ ) (≡-irrelevant m≡n refl) ⟩
subst (P zero) refl (ind (λ k → P k k) Pzz (λ k → Pss k k) zero)
≡⟨ subst-refl (P zero) (ind (λ k → P k k) Pzz (λ k → Pss k k) zero) ⟩
ind (λ k → P k k) Pzz (λ k → Pss k k) zero
≡⟨ ind-base _ _ _ ⟩
Pzz
∎
... | gt m>n = ⊥-elim $ n≮n zero m>n
inddiag-zs : ∀ Pzz Pzs Psz Pss n → inddiag Pzz Pzs Psz Pss zero (suc n) ≡ Pzs n
inddiag-zs Pzz Pzs Psz Pss n with order? zero (suc n)
... | lt (o , one+o≡suc[n]) = begin
subst (P zero) one+o≡suc[n] (inddiag-< Pzs Pss zero o)
≡⟨ cong (subst (P zero) one+o≡suc[n]) $ ind-base _ _ _ ⟩
subst (P zero) one+o≡suc[n] (subst (P zero) (suc≡one+ o) (Pzs o))
≡⟨ subst-subst (suc≡one+ o) ⟩ -- suc o -> one + o -> suc n
subst (P zero) so≡sn (Pzs o)
≡⟨ cong (λ v → subst (P zero) v (Pzs o)) $ ≡-irrelevant so≡sn (cong suc o≡n) ⟩
subst (P zero) (cong suc o≡n) (Pzs o)
≡⟨ subst-cong-app suc Pzs o≡n ⟩
Pzs n
∎
where
so≡sn : suc o ≡ suc n
so≡sn = trans (suc≡one+ o) one+o≡suc[n]
o≡n : o ≡ n
o≡n = suc-injective so≡sn
... | eq m≡n = ⊥-elim $ z≢s n m≡n
... | gt m>n = ⊥-elim $ n≮zero (suc n) m>n
inddiag-sz : ∀ Pzz Pzs Psz Pss m → inddiag Pzz Pzs Psz Pss (suc m) zero ≡ Psz m
inddiag-sz Pzz Pzs Psz Pss m with order? (suc m) zero
... | lt m<n = ⊥-elim $ n≮zero (suc m) m<n
... | eq m≡n = ⊥-elim $ s≢z m m≡n
... | gt (o , one+o≡suc[m]) = begin
subst (λ k → P k zero) one+o≡suc[m] (inddiag-> Psz Pss zero o)
≡⟨ cong (subst (λ k → P k zero) one+o≡suc[m]) $ ind-base _ _ _ ⟩
subst (λ k → P k zero) one+o≡suc[m] (subst (λ k → P k zero) (suc≡one+ o) (Psz o))
≡⟨ subst-subst (suc≡one+ o) ⟩
subst (λ k → P k zero) so≡sm (Psz o)
≡⟨ cong (λ v → subst (λ k → P k zero) v (Psz o)) $ ≡-irrelevant so≡sm (cong suc o≡m) ⟩
subst (λ k → P k zero) (cong suc o≡m) (Psz o)
≡⟨ subst-cong-app suc Psz o≡m ⟩
Psz m
∎
where
so≡sm = trans (suc≡one+ o) one+o≡suc[m]
o≡m = suc-injective so≡sm
inddiag-ss : ∀ Pzz Pzs Psz Pss m n →
inddiag Pzz Pzs Psz Pss (suc m) (suc n) ≡
Pss m n (inddiag Pzz Pzs Psz Pss m n)
inddiag-ss Pzz Pzs Psz Pss m n with order? (suc m) (suc n) | order? m n
... | lt sm<sn@(o , ssm+o≡sn) | lt m<n@(p , sm+p≡n) =
begin
subst (P (suc m)) ssm+o≡sn (inddiag-< Pzs Pss (suc m) o)
≡⟨ cong (subst (P (suc m)) ssm+o≡sn) $ ind-step _ _ _ m ⟩
subst (P (suc m)) ssm+o≡sn (subst (P (suc m)) (sym $ suc-+ (suc m) o) $
Pss m (suc m + o) (inddiag-< Pzs Pss m o))
≡⟨ subst-subst (sym $ suc-+ (suc m) o) ⟩
subst (P (suc m)) suc[sm+o]≡sn
(Pss m (suc m + o) (inddiag-< Pzs Pss m o))
≡⟨ cong (λ v → subst (P (suc m)) v (Pss m (suc m + o) (inddiag-< Pzs Pss m o))) $
≡-irrelevant suc[sm+o]≡sn (cong suc sm+o≡n) ⟩
subst (P (suc m)) (cong suc sm+o≡n) (Pss m (suc m + o) (inddiag-< Pzs Pss m o))
≡⟨ subst-lemma suc (Pss m) sm+o≡n ⟩
Pss m n (subst (P m) sm+o≡n (inddiag-< Pzs Pss m o))
≡⟨ cong (Pss m n) $ subst-other-g ≡-irrelevant (suc m +_) (inddiag-< Pzs Pss m) o≡p sm+o≡n sm+p≡n ⟩
Pss m n (subst (P m) sm+p≡n (inddiag-< Pzs Pss m p))
∎
where
suc[sm+o]≡sn : suc (suc m + o) ≡ suc n
suc[sm+o]≡sn = trans (sym $ suc-+ (suc m) o) ssm+o≡sn
sm+o≡n : suc m + o ≡ n
sm+o≡n = suc-injective suc[sm+o]≡sn
o≡p : o ≡ p
o≡p = ≤-proj₁-≡ (<-pred sm<sn) m<n
... | lt sm<sn | eq m≡n = ⊥-elim $ <⇒≢ (<-pred sm<sn) m≡n
... | lt sm<sn | gt m>n = ⊥-elim $ <⇒≯ (<-pred sm<sn) m>n
... | eq sm≡sn | lt m<n = ⊥-elim $ <⇒≢ m<n (suc-injective sm≡sn)
... | eq sm≡sn | eq m≡n = begin
subst (P (suc m)) sm≡sn (i (suc m))
≡⟨ cong (subst (P (suc m)) sm≡sn) $ ind-step _ _ _ m ⟩
subst (P (suc m)) sm≡sn (Pss m m (i m))
≡⟨ cong (λ v → subst (P (suc m)) v (Pss m m (i m))) $ ≡-irrelevant sm≡sn (cong suc m≡n) ⟩
subst (P (suc m)) (cong suc m≡n) (Pss m m (i m))
≡⟨ subst-lemma suc (Pss m) m≡n ⟩
Pss m n (subst (P m) m≡n (i m))
∎
where
i = ind (λ k → P k k) Pzz (λ k → Pss k k)
... | eq sm≡sn | gt m>n = ⊥-elim $ >⇒≢ m>n (suc-injective sm≡sn)
... | gt sm>sn | lt m<n = ⊥-elim $ <⇒≯ (<-pred sm>sn) m<n
... | gt sm>sn | eq m≡n = ⊥-elim $ >⇒≢ (<-pred sm>sn) m≡n
... | gt sm>sn@(o , ssn+o≡sm) | gt m>n@(p , sn+p≡m) = begin
subst B₁ ssn+o≡sm (inddiag-> Psz Pss (suc n) o)
≡⟨ cong (subst B₁ ssn+o≡sm) $ ind-step _ _ _ n ⟩
subst B₁ ssn+o≡sm (subst B₁ (sym $ suc-+ (suc n) o) (Pss (suc n + o) n u))
≡⟨ subst-subst (sym $ suc-+ (suc n) o) ⟩
subst B₁ suc[sn+o]≡sm (Pss (suc n + o) n u)
≡⟨ cong (λ v → subst B₁ v (Pss (suc n + o) n u)) $ ≡-irrelevant suc[sn+o]≡sm (cong suc sn+o≡m) ⟩
subst B₁ (cong suc sn+o≡m) (Pss (suc n + o) n u)
≡⟨ subst-lemma suc (λ k → Pss k n) sn+o≡m ⟩
Pss m n (subst B₂ sn+o≡m (inddiag-> Psz Pss n o))
≡⟨ cong (Pss m n) $ subst-other-g ≡-irrelevant (suc n +_) (inddiag-> Psz Pss n) o≡p sn+o≡m sn+p≡m ⟩
Pss m n (subst B₂ sn+p≡m (inddiag-> Psz Pss n p))
∎
where
B₁ = λ k → P k (suc n)
B₂ = λ k → P k n
u = inddiag-> Psz Pss n o
suc[sn+o]≡sm : suc (suc n + o) ≡ suc m
suc[sn+o]≡sm = trans (sym $ suc-+ (suc n) o) ssn+o≡sm
sn+o≡m = suc-injective suc[sn+o]≡sm
o≡p : o ≡ p
o≡p = ≤-proj₁-≡ (<-pred sm>sn) m>n
| {
"alphanum_fraction": 0.4487116963,
"avg_line_length": 34.2701949861,
"ext": "agda",
"hexsha": "85eb6a0e12c96a3f682362068a80270f706d1f35",
"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": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "TypeTheory/Nat/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"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": "rei1024/agda-misc",
"max_issues_repo_path": "TypeTheory/Nat/Properties.agda",
"max_line_length": 127,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "TypeTheory/Nat/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 12443,
"size": 24606
} |
-- Andreas, 2012-07-31 no eager introduction of hidden abstractions
{-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc.conv.coerce:100 #-}
-- {-# OPTIONS -v tc.with:100 #-}
module Issue679 where
data Unit : Set where
unit : Unit
-- works also now:
test : {u : Unit} → Unit
test = λ {u} → u
T : Unit → Set
T unit = {u : Unit} → Unit
works : (u : Unit) → T u
works unit = λ {u} → u
fails : (u : Unit) → T u
fails unit with unit
... | _ = λ {u} → u
-- Error was:
-- {u : _14 _} → _16 _ !=< Unit of type Set
-- when checking that the expression λ {u} → u has type Unit
| {
"alphanum_fraction": 0.5902777778,
"avg_line_length": 20.5714285714,
"ext": "agda",
"hexsha": "cb04edf53b0fd2baf06b20321ebdbcb40b7a6e98",
"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/Issue679.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/Issue679.agda",
"max_line_length": 67,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Succeed/Issue679.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 193,
"size": 576
} |
------------------------------------------------------------------------
-- The two definitions of substitutions are isomorphic (assuming
-- extensionality)
------------------------------------------------------------------------
open import Data.Universe.Indexed
module deBruijn.Substitution.Isomorphic
{i u e} {Uni : IndexedUniverse i u e} where
import Axiom.Extensionality.Propositional as E
import deBruijn.Context; open deBruijn.Context Uni
open import deBruijn.Substitution.Data.Basics as D using (ε; _▻_; [_])
open import deBruijn.Substitution.Function.Basics as F
using (ε⇨; _▻⇨_) renaming (_▻⇨[_]_ to _▻⇨[_]F_)
open import Function using (_$_)
open import Function.Inverse using (Inverse)
open import Level using (_⊔_)
import Relation.Binary.PropositionalEquality as P
open P.≡-Reasoning
isomorphic :
∀ {t} {T : Term-like t} →
E.Extensionality (i ⊔ u ⊔ e) (i ⊔ u ⊔ e ⊔ t) →
∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} →
Inverse ([ Var ⟶ T ]-setoid ρ̂) (P.setoid $ D.Sub T ρ̂)
isomorphic {T = T} ext = record
{ to = record { _⟨$⟩_ = to _
; cong = λ ρ₁≅ρ₂ → D.≅-⇨-⇒-≡ $ to-cong ρ₁≅ρ₂
}
; from = P.→-to-⟶ from
; inverse-of = record
{ left-inverse-of = from∘to _
; right-inverse-of = λ ρ → D.≅-⇨-⇒-≡ $ to∘from ρ
}
}
where
to : ∀ Γ {Δ} {ρ̂ : Γ ⇨̂ Δ} → F.Sub T ρ̂ → D.Sub T ρ̂
to ε ρ = ε
to (Γ ▻ σ) {ρ̂ = ρ̂} ρ =
P.subst (λ v → D.Sub T (t̂ail ρ̂ ▻̂ v))
(≅-Value-⇒-≡ $ P.sym $ F.head-lemma ρ)
(to Γ (F.tail ρ) ▻ F.head ρ)
from : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → D.Sub T ρ̂ → F.Sub T ρ̂
from ε = ε⇨
from (ρ ▻ t) = from ρ ▻⇨ t
to-▻ : ∀ {Γ Δ σ} {ρ̂ : Γ ▻ σ ⇨̂ Δ} (ρ : F.Sub T ρ̂) →
D._≅-⇨_ (to (Γ ▻ σ) ρ) (to Γ (F.tail ρ) ▻ F.head ρ)
to-▻ {ρ̂ = ρ̂} ρ =
D.drop-subst-Sub (λ v → t̂ail ρ̂ ▻̂ v)
(≅-Value-⇒-≡ $ P.sym $ F.head-lemma ρ)
abstract
to-cong : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : F.Sub T ρ̂₁}
{Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : F.Sub T ρ̂₂} →
F._≅-⇨_ ρ₁ ρ₂ → D._≅-⇨_ (to Γ₁ ρ₁) (to Γ₂ ρ₂)
to-cong {Γ₁ = ε} {ρ₁ = _ , _} {ρ₂ = ._ , _} [ P.refl ] = P.refl
to-cong {Γ₁ = Γ ▻ σ} {ρ₁ = ρ₁} {ρ₂ = ._ , corr₂} [ P.refl ] =
let ρ₂ = [_⟶_].function ρ₁ , corr₂ in begin
[ to (Γ ▻ σ) ρ₁ ] ≡⟨ to-▻ ρ₁ ⟩
[ to Γ (F.tail ρ₁) ▻ F.head ρ₁ ] ≡⟨ D.▻⇨-cong P.refl (to-cong [ P.refl ]) P.refl ⟩
[ to Γ (F.tail ρ₂) ▻ F.head ρ₂ ] ≡⟨ P.sym $ to-▻ ρ₂ ⟩
[ to (Γ ▻ σ) ρ₂ ] ∎
from-cong : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : D.Sub T ρ̂₁}
{Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : D.Sub T ρ̂₂} →
D._≅-⇨_ ρ₁ ρ₂ → F._≅-⇨_ (from ρ₁) (from ρ₂)
from-cong P.refl = [ P.refl ]
abstract
from∘to : ∀ Γ {Δ} {ρ̂ : Γ ⇨̂ Δ} (ρ : F.Sub T ρ̂) →
F._≅-⇨_ (from (to Γ ρ)) ρ
from∘to ε ρ =
ε⇨ ≅-⟶⟨ sym-⟶ $ F.ηε ext ρ ⟩
ρ ∎-⟶
from∘to (Γ ▻ σ) {ρ̂ = ρ̂} ρ =
from (to (Γ ▻ σ) ρ) ≅-⟶⟨ from-cong $ to-▻ ρ ⟩
from (to Γ (F.tail ρ) ▻ F.head ρ) ≅-⟶⟨ _ ∎-⟶ ⟩
from (to Γ (F.tail ρ)) ▻⇨ F.head ρ ≅-⟶⟨ F.▻⇨-cong P.refl (from∘to Γ (F.tail ρ)) P.refl ⟩
F.tail ρ ▻⇨ F.head ρ ≅-⟶⟨ sym-⟶ $ F.η▻ ext ρ ⟩
ρ ∎-⟶
to∘from : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} (ρ : D.Sub T ρ̂) →
D._≅-⇨_ (to Γ (from ρ)) ρ
to∘from ε = P.refl
to∘from (_▻_ {σ = σ} ρ t) = begin
[ to (_ ▻ _) (from ρ ▻⇨ t) ] ≡⟨ to-▻ (from ρ ▻⇨ t) ⟩
[ to _ (F.tail (from ρ ▻⇨[ σ ]F t)) ▻
F.head (from ρ ▻⇨[ σ ]F t) ] ≡⟨ D.▻⇨-cong P.refl (to-cong [ P.refl ]) P.refl ⟩
[ to _ (from ρ) ▻ t ] ≡⟨ D.▻⇨-cong P.refl (to∘from ρ) P.refl ⟩
[ ρ ▻ t ] ∎
| {
"alphanum_fraction": 0.4183246073,
"avg_line_length": 39.381443299,
"ext": "agda",
"hexsha": "5cb80c322a7a4b2a34426be87c87d66b9374084c",
"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": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/dependently-typed-syntax",
"max_forks_repo_path": "deBruijn/Substitution/Isomorphic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"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/dependently-typed-syntax",
"max_issues_repo_path": "deBruijn/Substitution/Isomorphic.agda",
"max_line_length": 96,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/dependently-typed-syntax",
"max_stars_repo_path": "deBruijn/Substitution/Isomorphic.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-08T22:51:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T12:14:44.000Z",
"num_tokens": 1859,
"size": 3820
} |
------------------------------------------------------------------------
-- Overloaded "equational" reasoning combinators
------------------------------------------------------------------------
{-# OPTIONS --safe #-}
module Equational-reasoning where
open import Equality.Propositional
open import Prelude
infix -1 _■
finally₁ finally₁∽ finally₁→ finally₁←
finally₂ finally₂∽ finally₂→ finally₂←
finally₁-≡∼ finally₁-≡∽ finally₁-≡→ finally₁-≡←
finally₂-≡∼ finally₂-≡∽ finally₂-≡→ finally₂-≡←
infixr -2 step-⟨⟩∼ step-≡∼ step-≡→ step-∼ step-∼→ step-∼′ step-∼→′
infixl -2 step-⟨⟩∽ step-≡∽ step-≡← step-∽ step-∼← step-∽′ step-∼←′
------------------------------------------------------------------------
-- Reflexivity
record Reflexive {a p} {A : Type a}
(P : A → A → Type p) :
Type (a ⊔ p) where
constructor is-reflexive
field
reflexive : ∀ {x} → P x x
open Reflexive ⦃ … ⦄ public
_■ : ∀ {a p} {A : Type a} {P : A → A → Type p} ⦃ r : Reflexive P ⦄
(x : A) → P x x
_ ■ = reflexive
-- Transitivity-like combinators. These combinators can be used when
-- two arguments are definitionally equal. (The Reflexive instance
-- argument is used to make type inference easier.)
step-⟨⟩∼ step-⟨⟩∽ :
∀ {a p} {A : Type a} {P : A → A → Type p}
⦃ p : Reflexive P ⦄ x {y} →
P x y → P x y
step-⟨⟩∼ _ p = p
step-⟨⟩∽ = step-⟨⟩∼
syntax step-⟨⟩∼ x Pxy = x ∼⟨⟩ Pxy
syntax step-⟨⟩∽ x Pxy = Pxy ∽⟨⟩ x
-- Transitivity-like combinators. These combinators can be used when
-- two arguments are propositionally equal. (The Reflexive instance
-- argument is used to make type inference easier.)
-- It can be easier for Agda to type-check typical "equational"
-- reasoning chains if the transitivity proof gets the equality
-- arguments in the opposite order, because then the y argument is
-- (perhaps more) known once the proof of P x y is type-checked.
--
-- This optimisation can be quite effective for some examples, but did
-- not seem to have much effect when I applied it to the current code
-- base.
--
-- The idea behind this optimisation came up in discussions with Ulf
-- Norell.
step-≡∼ step-≡∽ step-≡→ step-≡← :
∀ {a p} {A : Type a} {P : A → A → Type p}
⦃ r : Reflexive P ⦄ x {y z} →
P y z → x ≡ y → P x z
step-≡∼ _ p refl = p
step-≡∽ = step-≡∼
step-≡→ = step-≡∼
step-≡← = step-≡∼
syntax step-≡∼ x Pyz x≡y = x ∼≡⟨ x≡y ⟩ Pyz
syntax step-≡∽ x Pyz x≡y = Pyz ∽≡⟨ x≡y ⟩ x
syntax step-≡→ x Pyz x≡y = x →≡⟨ x≡y ⟩ Pyz
syntax step-≡← x Pyz x≡y = Pyz ←≡⟨ x≡y ⟩ x
finally₂-≡∼ finally₂-≡∽ finally₂-≡→ finally₂-≡← :
∀ {a p} {A : Type a}
{P : A → A → Type p}
⦃ r : Reflexive P ⦄ x y →
x ≡ y → P x y
finally₂-≡∼ _ _ refl = reflexive
finally₂-≡∽ = finally₂-≡∼
finally₂-≡→ = finally₂-≡∼
finally₂-≡← = finally₂-≡∼
syntax finally₂-≡∼ x y x≡y = x ∼≡⟨ x≡y ⟩■ y
syntax finally₂-≡∽ x y x≡y = y ∽≡⟨ x≡y ⟩■ x
syntax finally₂-≡→ x y x≡y = x →≡⟨ x≡y ⟩■ y
syntax finally₂-≡← x y x≡y = y ←≡⟨ x≡y ⟩■ x
finally₁-≡∼ finally₁-≡∽ finally₁-≡→ finally₁-≡← :
∀ {a p} {A : Type a}
{P : A → A → Type p}
⦃ r : Reflexive P ⦄ x {y} →
x ≡ y → P x y
finally₁-≡∼ _ refl = reflexive
finally₁-≡∽ = finally₁-≡∼
finally₁-≡→ = finally₁-≡∼
finally₁-≡← = finally₁-≡∼
syntax finally₁-≡∼ x x≡y = x ∼≡⟨ x≡y ⟩■
syntax finally₁-≡∽ x x≡y = ∽≡⟨ x≡y ⟩■ x
syntax finally₁-≡→ x x≡y = x →≡⟨ x≡y ⟩■
syntax finally₁-≡← x x≡y = ←≡⟨ x≡y ⟩■ x
------------------------------------------------------------------------
-- Symmetry
record Symmetric {a p} {A : Type a}
(P : A → A → Type p) :
Type (a ⊔ p) where
constructor is-symmetric
field
symmetric : ∀ {x y} → P x y → P y x
open Symmetric ⦃ … ⦄ public
------------------------------------------------------------------------
-- Transitivity
-- One variant of transitivity.
--
-- Note that the combinator can (depending on the available instances)
-- be used to convert from one type to another, but only in its first
-- argument (in order to make instance resolution easier).
record Transitive {a b p q} {A : Type a} {B : Type b}
(P : A → A → Type p) (Q : A → B → Type q) :
Type (a ⊔ b ⊔ p ⊔ q) where
constructor is-transitive
field
transitive : ∀ {x y z} → P x y → Q y z → Q x z
open Transitive ⦃ … ⦄ public
step-∼ step-∽ step-∼→ step-∼← :
∀ {a b p q} {A : Type a} {B : Type b}
{P : A → A → Type p} {Q : A → B → Type q}
⦃ t : Transitive P Q ⦄ x {y z} →
Q y z → P x y → Q x z
step-∼ _ = flip transitive
step-∽ = step-∼
step-∼→ = step-∼
step-∼← = step-∼
syntax step-∼ x Qyz Pxy = x ∼⟨ Pxy ⟩ Qyz
syntax step-∽ x Qyz Pxy = Qyz ∽⟨ Pxy ⟩ x
syntax step-∼→ x Qyz Pxy = x →⟨ Pxy ⟩ Qyz
syntax step-∼← x Qyz Pxy = Qyz ←⟨ Pxy ⟩ x
-- Another variant of transitivity.
--
-- Note that the combinator can (depending on the available instances)
-- be used to convert from one type to another, but only in its second
-- argument (in order to make instance resolution easier).
record Transitive′ {a b p q} {A : Type a} {B : Type b}
(P : A → B → Type p) (Q : B → B → Type q) :
Type (a ⊔ b ⊔ p ⊔ q) where
constructor is-transitive
field
transitive′ : ∀ {x y z} → P x y → Q y z → P x z
open Transitive′ ⦃ … ⦄ public
step-∼′ step-∽′ step-∼→′ step-∼←′ :
∀ {a b p q} {A : Type a} {B : Type b}
{P : A → B → Type p} {Q : B → B → Type q}
⦃ t : Transitive′ P Q ⦄ x {y z} →
Q y z → P x y → P x z
step-∼′ _ = flip transitive′
step-∽′ = step-∼′
step-∼→′ = step-∼′
step-∼←′ = step-∼′
syntax step-∼′ x Qyz Pxy = x ∼′⟨ Pxy ⟩ Qyz
syntax step-∽′ x Qyz Pxy = Qyz ∽′⟨ Pxy ⟩ x
syntax step-∼→′ x Qyz Pxy = x →′⟨ Pxy ⟩ Qyz
syntax step-∼←′ x Qyz Pxy = Qyz ←′⟨ Pxy ⟩ x
------------------------------------------------------------------------
-- A finally combinator
-- This combinator is intended to be used in the last step of an
-- equational reasoning proof:
--
-- x ∼⟨ ? ⟩■
-- y
--
-- Note that the combinator can (depending on the available instances)
-- be used to convert from one type to another.
record Convertible {a b p q} {A : Type a} {B : Type b}
(P : A → B → Type p) (Q : A → B → Type q) :
Type (a ⊔ b ⊔ p ⊔ q) where
constructor is-convertible
field
convert : ∀ {x y} → P x y → Q x y
open Convertible ⦃ … ⦄ public
finally₂ finally₂∽ finally₂→ finally₂← :
∀ {a b p q} {A : Type a} {B : Type b}
{P : A → B → Type p} {Q : A → B → Type q}
⦃ c : Convertible P Q ⦄ x y →
P x y → Q x y
finally₂ _ _ = convert
finally₂∽ = finally₂
finally₂→ = finally₂
finally₂← = finally₂
syntax finally₂ x y x∼y = x ∼⟨ x∼y ⟩■ y
syntax finally₂∽ x y x∼y = y ∽⟨ x∼y ⟩■ x
syntax finally₂→ x y x→y = x →⟨ x→y ⟩■ y
syntax finally₂← x y x→y = y ←⟨ x→y ⟩■ x
finally₁ finally₁∽ finally₁→ finally₁← :
∀ {a b p q} {A : Type a} {B : Type b}
{P : A → B → Type p} {Q : A → B → Type q}
⦃ c : Convertible P Q ⦄ x {y} →
P x y → Q x y
finally₁ _ = convert
finally₁∽ = finally₁
finally₁→ = finally₁
finally₁← = finally₁
syntax finally₁ x x∼y = x ∼⟨ x∼y ⟩■
syntax finally₁∽ x x∼y = ∽⟨ x∼y ⟩■ x
syntax finally₁→ x x→y = x →⟨ x→y ⟩■
syntax finally₁← x x→y = ←⟨ x→y ⟩■ x
| {
"alphanum_fraction": 0.5261563877,
"avg_line_length": 30.9106382979,
"ext": "agda",
"hexsha": "f7422d6bf8a1b2759d24bd110acebaac1722ac83",
"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": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "src/Equational-reasoning.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"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/up-to",
"max_issues_repo_path": "src/Equational-reasoning.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "src/Equational-reasoning.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2900,
"size": 7264
} |
open import Prelude hiding (Bool)
module Implicits.Oliveira.Improved.Deterministic (TC' : Set) (_tc≟'_ : (a b : TC') → Dec (a ≡ b)) where
{-
open import Data.Fin.Substitution
open import Implicits.Oliveira.Types
open import Implicits.Oliveira.Types.Unification
open import Implicits.Oliveira.Terms
open import Implicits.Oliveira.Contexts
open import Implicits.Oliveira.Substitutions
open import Implicits.Oliveira.Improved.Resolution
open import Extensions.ListFirst
-}
-- This is more troublesome than I expected; the tricky thing is the rule r-simp.
-- r-simp requires an instance of first, which has 2 constructors:
-- (a) here: which relies on a proof that r can yield "a" (K ⊢ r ↓ a)
-- (b) there: which relies on a proof that r can NOT yield "a" (¬ K ⊢ r ↓ a)
-- Proving (b) deterministic is nonsensical. Check for example the example below:
-- (we give two ways to derive (b) for a single K, r and a)
-- Because (b) appears in _⊢ᵣ_, this makes _⊢ᵣ_ non-deterministic, which in turn makes
-- the r-iabs case of (a) non-deterministic.
-- The thing is that all non-determinism is situated in the "unhappy-path": (b).
-- Because the exact instance for (b) does not influence rule instantiation,
-- we should be able to give a weaker,
-- but still powerful enough, version of "equivalence" on derivations.
private
data TC : Set where
tc-int : TC
tc-bool : TC
_tc≟_ : (a b : TC) → Dec (a ≡ b)
tc-int tc≟ tc-int = yes refl
tc-int tc≟ tc-bool = no (λ ())
tc-bool tc≟ tc-int = no (λ ())
tc-bool tc≟ tc-bool = yes refl
open import Data.Fin.Substitution
open import Implicits.Oliveira.Types
open import Implicits.Oliveira.Types.Unification
open import Implicits.Oliveira.Terms
open import Implicits.Oliveira.Contexts
open import Implicits.Oliveira.Substitutions
open import Implicits.Oliveira.Improved.Resolution
open import Extensions.ListFirst
Bool : Type 0
Bool = simpl $ tc tc-bool
Int : ∀ {ν} → Type ν
Int = simpl $ tc tc-int
module Example₁ where
K : Ktx 0 1
K = (Int ⇒ Bool) ∷K nil
p₁ : ¬ (K ⊢ Int ⇒ Bool ↓ tc tc-int)
p₁ (i-iabs (r-simp (here (i-iabs _ ()) .List.[])) _)
p₁ (i-iabs (r-simp (there ._ _ ())) _)
p₂ : ¬ (K ⊢ Int ⇒ Bool ↓ tc tc-int)
p₂ (i-iabs x ())
| {
"alphanum_fraction": 0.6935412027,
"avg_line_length": 32.5362318841,
"ext": "agda",
"hexsha": "917d107f109fab0643e115852e9cd43bb2f8bf50",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/Undecidable/Deterministic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/Undecidable/Deterministic.agda",
"max_line_length": 103,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/Undecidable/Deterministic.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": 718,
"size": 2245
} |
{-# OPTIONS --rewriting #-}
module DualLM where
open import Data.Bool
open import Data.Nat hiding (compare)
open import Data.Nat.Properties
open import Data.Fin hiding (_+_)
open import Data.Product
open import Function
open import Relation.Binary.PropositionalEquality hiding (Extensionality)
open import Agda.Builtin.Equality.Rewrite
open import Extensionality
open import Direction
-- variables
variable
n m : ℕ
----------------------------------------------------------------------
-- auxiliaries for automatic rewriting
n+1=suc-n : n + 1 ≡ suc n
n+1=suc-n {zero} = refl
n+1=suc-n {suc n} = cong suc (n+1=suc-n {n})
{-# REWRITE n+1=suc-n #-}
n+0=n : n + 0 ≡ n
n+0=n {zero} = refl
n+0=n {suc n} = cong suc (n+0=n {n})
{-# REWRITE n+0=n #-}
inject+0-x=x : {x : Fin m} → inject+ 0 x ≡ x
inject+0-x=x {x = zero} = refl
inject+0-x=x {x = suc x} = cong suc inject+0-x=x
{-# REWRITE inject+0-x=x #-}
n+sucm : n + suc m ≡ suc (n + m)
n+sucm {0F} = refl
n+sucm {suc n} = cong suc (n+sucm{n})
{-# REWRITE n+sucm #-}
----------------------------------------------------------------------
-- session type inductively with explicit rec
module IND where
data Polarity : Set where
POS NEG : Polarity
mutual
data Type (n : ℕ) : Set where
TUnit TInt : Type n
TPair : (T₁ : Type n) (T₂ : Type n) → Type n
TChan : (S : SType n) → Type n
data SType (n : ℕ) : Set where
gdd : (G : GType n) → SType n
rec : (G : GType (suc n) ) → SType n
var : (p : Polarity) → (x : Fin n) → SType n
data GType (n : ℕ) : Set where
transmit : (d : Dir) (T : Type n) (S : SType n) → GType n
choice : (d : Dir) (m : ℕ) (alt : Fin m → SType n) → GType n
end : GType n
TType = Type
-- weakening
weakenS : (n : ℕ) → SType m → SType (m + n)
weakenG : (n : ℕ) → GType m → GType (m + n)
weakenT : (n : ℕ) → TType m → TType (m + n)
weakenS n (gdd gst) = gdd (weakenG n gst)
weakenS n (rec gst) = rec (weakenG n gst)
weakenS n (var p x) = var p (inject+ n x)
weakenG n (transmit d t s) = transmit d (weakenT n t) (weakenS n s)
weakenG n (choice d m alt) = choice d m (weakenS n ∘ alt)
weakenG n end = end
weakenT n TUnit = TUnit
weakenT n TInt = TInt
weakenT n (TPair ty ty₁) = TPair (weakenT n ty) (weakenT n ty₁)
weakenT n (TChan x) = TChan (weakenS n x)
weaken1 : SType m → SType (suc m)
weaken1{m} stm with weakenS 1 stm
... | r rewrite n+1=suc-n {m} = r
module CheckWeaken where
s0 : SType 0
s0 = rec (transmit SND TUnit (var POS zero))
s1 : SType 1
s1 = rec (transmit SND TUnit (var POS zero))
s2 : SType 2
s2 = rec (transmit SND TUnit (var POS zero))
check-weakenS1 : weakenS 1 s0 ≡ s1
check-weakenS1 = cong rec (cong (transmit SND TUnit) refl)
check-weakenS2 : weakenS 2 s0 ≡ s2
check-weakenS2 = cong rec (cong (transmit SND TUnit) refl)
weaken1'N : Fin (suc n) → Fin n → Fin (suc n)
weaken1'N zero x = suc x
weaken1'N (suc i) zero = zero
weaken1'N (suc i) (suc x) = suc (weaken1'N i x)
weaken1'S : Fin (suc n) → SType n → SType (suc n)
weaken1'G : Fin (suc n) → GType n → GType (suc n)
weaken1'T : Fin (suc n) → TType n → TType (suc n)
weaken1'S i (gdd gst) = gdd (weaken1'G i gst)
weaken1'S i (rec gst) = rec (weaken1'G (suc i) gst)
weaken1'S i (var p x) = var p (weaken1'N i x)
weaken1'G i (transmit d t s) = transmit d (weaken1'T i t) (weaken1'S i s)
weaken1'G i (choice d m alt) = choice d m (weaken1'S i ∘ alt)
weaken1'G i end = end
weaken1'T i TUnit = TUnit
weaken1'T i TInt = TInt
weaken1'T i (TPair t₁ t₂) = TPair (weaken1'T i t₁) (weaken1'T i t₂)
weaken1'T i (TChan x) = TChan (weaken1'S i x)
weaken1S : SType n → SType (suc n)
weaken1G : GType n → GType (suc n)
weaken1T : Type n → Type (suc n)
weaken1S = weaken1'S zero
weaken1G = weaken1'G zero
weaken1T = weaken1'T zero
module CheckWeaken1' where
sxy : ∀ n → Fin (suc n) → SType n
sxy n x = rec (transmit SND TUnit (var POS x))
s00 : SType 0
s00 = sxy 0 0F
s10 : SType 1
s10 = sxy 1 0F
s11 : SType 1
s11 = sxy 1 1F
s22 : SType 2
s22 = sxy 2 2F
check-weaken-s01 : weaken1'S 0F s00 ≡ s10
check-weaken-s01 = refl
check-weaken-s1-s2 : weaken1'S 0F s11 ≡ s22
check-weaken-s1-s2 = refl
check-weaken-s21 : weaken1'S 1F (sxy 2 1F) ≡ sxy 3 1F
check-weaken-s21 = refl
----------------------------------------------------------------------
dual-pol : Polarity → Polarity
dual-pol POS = NEG
dual-pol NEG = POS
dual-pol-inv : ∀ p → dual-pol (dual-pol p) ≡ p
dual-pol-inv POS = refl
dual-pol-inv NEG = refl
swap-polS : (i : Fin (suc n)) → SType (suc n) → SType (suc n)
swap-polG : (i : Fin (suc n)) → GType (suc n) → GType (suc n)
swap-polT : (i : Fin (suc n)) → Type (suc n) → Type (suc n)
swap-polG i (transmit d t st) = transmit d (swap-polT i t) (swap-polS i st)
swap-polG i (choice d m alt) = choice d m (swap-polS i ∘ alt)
swap-polG i end = end
swap-polS i (gdd gst) = gdd (swap-polG i gst)
swap-polS i (rec st) = rec (swap-polG (suc i) st)
swap-polS zero (var p zero) = var (dual-pol p) zero
swap-polS (suc i) (var p zero) = var p zero
swap-polS zero (var p (suc x)) = var p (suc x)
swap-polS {suc n} (suc i) (var p (suc x)) = weaken1S (swap-polS i (var p x))
swap-polT i TUnit = TUnit
swap-polT i TInt = TInt
swap-polT i (TPair t₁ t₂) = TPair (swap-polT i t₁) (swap-polT i t₂)
swap-polT i (TChan x) = TChan (swap-polS i x)
----------------------------------------------------------------------
weak-weakN : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (x : Fin n)
→ weaken1'N (suc i) (weaken1'N j x) ≡ weaken1'N (inject₁ j) (weaken1'N i x)
weak-weakG : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (g : GType n)
→ weaken1'G (suc i) (weaken1'G j g) ≡ weaken1'G (inject₁ j) (weaken1'G i g)
weak-weakS : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (s : SType n)
→ weaken1'S (suc i) (weaken1'S j s) ≡ weaken1'S (inject₁ j) (weaken1'S i s)
weak-weakT : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (t : Type n)
→ weaken1'T (suc i) (weaken1'T j t) ≡ weaken1'T (inject₁ j) (weaken1'T i t)
weak-weakN 0F 0F le x = refl
weak-weakN (suc i) 0F le x = refl
weak-weakN (suc i) (suc j) (s≤s le) zero = refl
weak-weakN{suc n} (suc i) (suc j) (s≤s le) (suc x) = cong suc (weak-weakN i j le x)
weak-weakG i j le (transmit d t s) = cong₂ (transmit d) (weak-weakT i j le t) (weak-weakS i j le s)
weak-weakG i j le (choice d m alt) = cong (choice d m) (ext (weak-weakS i j le ∘ alt))
weak-weakG i j le end = refl
weak-weakS i j le (gdd gst) = cong gdd (weak-weakG i j le gst)
weak-weakS i j le (rec gst) = cong rec (weak-weakG (suc i) (suc j) (s≤s le) gst)
weak-weakS i j le (var p x) = cong (var p) (weak-weakN i j le x)
weak-weakT i j le TUnit = refl
weak-weakT i j le TInt = refl
weak-weakT i j le (TPair t t₁) = cong₂ TPair (weak-weakT i j le t) (weak-weakT i j le t₁)
weak-weakT i j le (TChan s) = cong TChan (weak-weakS i j le s)
weaken1-weakenN : (m : ℕ) (j : Fin (suc n)) (x : Fin n)
→ inject+ m (weaken1'N j x) ≡ weaken1'N (inject+ m j) (inject+ m x)
weaken1-weakenN m 0F 0F = refl
weaken1-weakenN m 0F (suc x) = refl
weaken1-weakenN m (suc j) 0F = refl
weaken1-weakenN m (suc j) (suc x) = cong suc (weaken1-weakenN m j x)
weaken1-weakenS : (m : ℕ) (j : Fin (suc n)) (s : SType n)
→ weakenS m (weaken1'S j s) ≡ weaken1'S (inject+ m j) (weakenS m s)
weaken1-weakenG : (m : ℕ) (j : Fin (suc n)) (g : GType n)
→ weakenG m (weaken1'G j g) ≡ weaken1'G (inject+ m j) (weakenG m g)
weaken1-weakenT : (m : ℕ) (j : Fin (suc n)) (t : Type n)
→ weakenT m (weaken1'T j t) ≡ weaken1'T (inject+ m j) (weakenT m t)
weaken1-weakenS m j (gdd gst) = cong gdd (weaken1-weakenG m j gst)
weaken1-weakenS m j (rec gst) = cong rec (weaken1-weakenG m (suc j) gst)
weaken1-weakenS m 0F (var p 0F) = refl
weaken1-weakenS m 0F (var p (suc x)) = refl
weaken1-weakenS {suc n} m (suc j) (var p 0F) = refl
weaken1-weakenS {suc n} m (suc j) (var p (suc x)) = cong (var p) (cong suc (weaken1-weakenN m j x))
weaken1-weakenG m j (transmit d t s) = cong₂ (transmit d) (weaken1-weakenT m j t) (weaken1-weakenS m j s)
weaken1-weakenG m j (choice d m₁ alt) = cong (choice d m₁) (ext (weaken1-weakenS m j ∘ alt))
weaken1-weakenG m j end = refl
weaken1-weakenT m j TUnit = refl
weaken1-weakenT m j TInt = refl
weaken1-weakenT m j (TPair t t₁) = cong₂ TPair (weaken1-weakenT m j t) (weaken1-weakenT m j t₁)
weaken1-weakenT m j (TChan x) = cong TChan (weaken1-weakenS m j x)
----------------------------------------------------------------------
-- weakening of later index
swap-weaken1'G : (i : Fin (suc (suc n))) (j : Fin′ i) (gst : GType (suc n)) →
swap-polG (inject j) (weaken1'G i gst) ≡ weaken1'G i (swap-polG (inject! j) gst)
swap-weaken1'S : (i : Fin (suc (suc n))) (j : Fin′ i) (sst : SType (suc n)) →
swap-polS (inject j) (weaken1'S i sst) ≡ weaken1'S i (swap-polS (inject! j) sst)
swap-weaken1'T : (i : Fin (suc (suc n))) (j : Fin′ i) (t : Type (suc n)) →
swap-polT (inject j) (weaken1'T i t) ≡ weaken1'T i (swap-polT (inject! j) t)
swap-weaken1'G i j (transmit d t s) = cong₂ (transmit d) (swap-weaken1'T i j t) (swap-weaken1'S i j s)
swap-weaken1'G i j (choice d m alt) = cong (choice d m) (ext (swap-weaken1'S i j ∘ alt))
swap-weaken1'G i j end = refl
swap-weaken1'S i j (gdd gst) = cong gdd (swap-weaken1'G i j gst)
swap-weaken1'S i j (rec gst) = cong rec (swap-weaken1'G (suc i) (suc j) gst)
swap-weaken1'S zero () (var p x)
swap-weaken1'S (suc i) zero (var p zero) = refl
swap-weaken1'S (suc i) zero (var p (suc x)) = refl
swap-weaken1'S (suc i) (suc j) (var p zero) = refl
swap-weaken1'S{suc n} (suc i) (suc j) (var p (suc x)) rewrite (weak-weakS i 0F z≤n (swap-polS (inject! j) (var p x))) =
let sws = swap-weaken1'S{n} i j (var p x) in cong (weaken1'S 0F) sws
swap-weaken1'T i j TUnit = refl
swap-weaken1'T i j TInt = refl
swap-weaken1'T i j (TPair t₁ t₂) = cong₂ TPair (swap-weaken1'T i j t₁) (swap-weaken1'T i j t₂)
swap-weaken1'T i j (TChan s) = cong TChan (swap-weaken1'S i j s)
----------------------------------------------------------------------
-- weakening of earlier index
swap-weaken1'S< : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) → (s : SType (suc n)) →
swap-polS (suc i) (weaken1'S (inject₁ j) s) ≡ weaken1'S (inject₁ j) (swap-polS i s)
swap-weaken1'G< : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) → (g : GType (suc n)) →
swap-polG (suc i) (weaken1'G (inject₁ j) g) ≡ weaken1'G (inject₁ j) (swap-polG i g)
swap-weaken1'T< : (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) → (t : Type (suc n)) →
swap-polT (suc i) (weaken1'T (inject₁ j) t) ≡ weaken1'T (inject₁ j) (swap-polT i t)
swap-weaken1'S< i j le (gdd gst) = cong gdd (swap-weaken1'G< i j le gst)
swap-weaken1'S< i j le (rec gst) = cong rec (swap-weaken1'G< (suc i) (suc j) (s≤s le) gst)
swap-weaken1'S< 0F 0F le (var p x) = refl
swap-weaken1'S< (suc i) 0F le (var p x) = refl
swap-weaken1'S<{suc n} (suc i) (suc j) le (var p zero) = refl
swap-weaken1'S<{suc n} (suc i) (suc j) (s≤s le) (var p (suc x)) rewrite (weak-weakS (inject₁ j) 0F z≤n (swap-polS i (var p x))) =
let sws = swap-weaken1'S<{n} i j le (var p x) in cong (weaken1'S 0F) sws
swap-weaken1'G< i j le (transmit d t s) = cong₂ (transmit d) (swap-weaken1'T< i j le t) (swap-weaken1'S< i j le s)
swap-weaken1'G< i j le (choice d m alt) = cong (choice d m) (ext ((swap-weaken1'S< i j le) ∘ alt))
swap-weaken1'G< i j le end = refl
swap-weaken1'T< i j le TUnit = refl
swap-weaken1'T< i j le TInt = refl
swap-weaken1'T< i j le (TPair t t₁) = cong₂ (TPair) (swap-weaken1'T< i j le t) (swap-weaken1'T< i j le t₁)
swap-weaken1'T< i j le (TChan s) = cong (TChan) (swap-weaken1'S< i j le s)
swap-weakenS : (i : Fin (suc n)) → (s : SType (suc n)) →
swap-polS (suc i) (weaken1S s) ≡ weaken1S (swap-polS i s)
swap-weakenG : (i : Fin (suc n)) → (g : GType (suc n)) →
swap-polG (suc i) (weaken1G g) ≡ weaken1G (swap-polG i g)
swap-weakenT : (i : Fin (suc n)) → (t : Type (suc n)) →
swap-polT (suc i) (weaken1T t) ≡ weaken1T (swap-polT i t)
swap-weakenS i s = swap-weaken1'S< i 0F z≤n s
swap-weakenG i g = swap-weaken1'G< i 0F z≤n g
swap-weakenT i t = swap-weaken1'T< i 0F z≤n t
----------------------------------------------------------------------
-- swapping of general weakening
swap-weakenG' : (m : ℕ) (j : Fin (suc n)) (gst : GType (suc n))
→ swap-polG (inject+ m j) (weakenG m gst) ≡ weakenG m (swap-polG j gst)
swap-weakenS' : (m : ℕ) (j : Fin (suc n)) (s : SType (suc n))
→ swap-polS (inject+ m j) (weakenS m s) ≡ weakenS m (swap-polS j s)
swap-weakenT' : (m : ℕ) (j : Fin (suc n)) (t : Type (suc n))
→ swap-polT (inject+ m j) (weakenT m t) ≡ weakenT m (swap-polT j t)
swap-weakenG' m j (transmit d t s) = cong₂ (transmit d) (swap-weakenT' m j t) (swap-weakenS' m j s)
swap-weakenG' m j (choice d m₁ alt) = cong (choice d m₁) (ext (swap-weakenS' m j ∘ alt))
swap-weakenG' m j end = refl
swap-weakenS' m j (gdd gst) = cong gdd (swap-weakenG' m j gst)
swap-weakenS' m j (rec gst) = cong rec (swap-weakenG' m (suc j) gst)
swap-weakenS' m 0F (var p 0F) = refl
swap-weakenS' m (suc j) (var p 0F) = refl
swap-weakenS' m 0F (var p 1F) = refl
swap-weakenS' m 0F (var p (suc (suc x))) = refl
swap-weakenS' {suc n} m (suc j) (var p (suc x)) rewrite (weaken1-weakenS m 0F (swap-polS j (var p x))) =
let rst = swap-weakenS'{n} m j (var p x) in cong weaken1S rst
swap-weakenT' m j TUnit = refl
swap-weakenT' m j TInt = refl
swap-weakenT' m j (TPair t t₁) = cong₂ TPair (swap-weakenT' m j t) (swap-weakenT' m j t₁)
swap-weakenT' m j (TChan x) = cong TChan (swap-weakenS' m j x)
----------------------------------------------------------------------
swap-pol-invS : (i : Fin (suc n)) → (st : SType (suc n)) →
swap-polS i (swap-polS i st) ≡ st
swap-pol-invG : (i : Fin (suc n)) → (st : GType (suc n)) →
swap-polG i (swap-polG i st) ≡ st
swap-pol-invT : (i : Fin (suc n)) → (ty : Type (suc n)) →
swap-polT i (swap-polT i ty) ≡ ty
swap-pol-invS i (gdd gst) = cong gdd (swap-pol-invG i gst)
swap-pol-invS i (rec gst) = cong rec (swap-pol-invG (suc i) gst)
swap-pol-invS zero (var p zero) rewrite dual-pol-inv p = refl
swap-pol-invS (suc i) (var p zero) = refl
swap-pol-invS zero (var p (suc x)) rewrite dual-pol-inv p = refl
swap-pol-invS {suc n} (suc i) (var p (suc x))
rewrite swap-weakenS i (swap-polS i (var p x)) | swap-pol-invS i (var p x) = refl
-- extensionality needed
swap-pol-invG i (transmit d t s) = cong₂ (transmit d) (swap-pol-invT i t) (swap-pol-invS i s)
swap-pol-invG i (choice d m alt) = cong (choice d m) (ext R)
where R : ∀ x → swap-polS i (swap-polS i (alt x)) ≡ alt x
R x rewrite swap-pol-invS i (alt x) = refl
swap-pol-invG i end = refl
swap-pol-invT i TUnit = refl
swap-pol-invT i TInt = refl
swap-pol-invT i (TPair ty ty₁) = cong₂ TPair (swap-pol-invT i ty) (swap-pol-invT i ty₁)
swap-pol-invT i (TChan x) = cong TChan (swap-pol-invS i x)
dualS : SType n → SType n
dualG : GType n → GType n
dualG (transmit d t st) = transmit (dual-dir d) t (dualS st)
dualG (choice d m alt) = choice (dual-dir d) m (dualS ∘ alt)
dualG end = end
dualS (gdd gst) = gdd (dualG gst)
dualS (rec gst) = rec (swap-polG zero (dualG gst))
dualS (var p x) = var (dual-pol p) x
----------------------------------------------------------------------
dual-weakenS : (i : Fin (suc n)) (s : SType n) → dualS (weaken1'S i s) ≡ weaken1'S i (dualS s)
dual-weakenG : (i : Fin (suc n)) (g : GType n) → dualG (weaken1'G i g) ≡ weaken1'G i (dualG g)
dual-weakenS i (gdd gst) = cong gdd (dual-weakenG i gst)
dual-weakenS i (rec gst) rewrite (sym (swap-weaken1'G (suc i) 0F (dualG gst))) = cong rec (cong (swap-polG 0F) (dual-weakenG (suc i) gst))
dual-weakenS i (var p x) = refl
dual-weakenG i (transmit d t s) = cong₂ (transmit (dual-dir d)) refl (dual-weakenS i s)
dual-weakenG i (choice d m alt) = cong (choice (dual-dir d) m) (ext (dual-weakenS i ∘ alt))
dual-weakenG i end = refl
dual-weakenS' : (m : ℕ) (s : SType n) → dualS (weakenS m s) ≡ weakenS m (dualS s)
dual-weakenG' : (m : ℕ) (g : GType n) → dualG (weakenG m g) ≡ weakenG m (dualG g)
dual-weakenS' n (gdd gst) = cong gdd (dual-weakenG' n gst)
dual-weakenS' n (rec gst) rewrite (sym (swap-weakenG' n 0F (dualG gst))) = cong rec (cong (swap-polG 0F) (dual-weakenG' n gst))
dual-weakenS' n (var p x) = refl
dual-weakenG' n (transmit d t s) = cong₂ (transmit (dual-dir d)) refl (dual-weakenS' n s)
dual-weakenG' n (choice d m alt) = cong (choice (dual-dir d) m) (ext (dual-weakenS' n ∘ alt))
dual-weakenG' n end = refl
----------------------------------------------------------------------
aux : (i : Fin n) (x : Fin n) (p' : Polarity) →
var p' (suc (suc x)) ≡ weaken1S (var p' (suc x))
aux i x p = refl
var-suc : (i : Fin n) (x : Fin n) (p : Polarity) →
∃ λ p' → swap-polS (suc i) (var p (suc x)) ≡ var p' (suc x)
var-suc zero zero p = dual-pol p , refl
var-suc (suc i) zero p = p , refl
var-suc zero (suc x) p = p , refl
var-suc (suc i) (suc x) p
with var-suc i x p
... | p' , snd
rewrite sym (aux i x p') = p' , cong weaken1S snd
----------------------------------------------------------------------
swap-swapG : (gst : GType (suc n)) → (i : Fin (suc n)) (j : Fin′ i) →
swap-polG i (swap-polG (inject j) gst) ≡ swap-polG (inject j) (swap-polG i gst)
swap-swapT : (t : Type (suc n)) → (i : Fin (suc n)) (j : Fin′ i) →
swap-polT i (swap-polT (inject j) t) ≡ swap-polT (inject j) (swap-polT i t)
swap-swapS : (st : SType (suc n)) → (i : Fin (suc n)) (j : Fin′ i) →
swap-polS i (swap-polS (inject j) st) ≡ swap-polS (inject j) (swap-polS i st)
swap-swapG (transmit d t s) i j = cong₂ (transmit d) (swap-swapT t i j) (swap-swapS s i j)
swap-swapG (choice d m alt) i j = cong (choice d m) (ext (λ x → swap-swapS (alt x) i j))
swap-swapG end i j = refl
swap-swapT TUnit i j = refl
swap-swapT TInt i j = refl
swap-swapT (TPair t t₁) i j = cong₂ TPair (swap-swapT t i j) (swap-swapT t₁ i j)
swap-swapT (TChan x) i j = cong TChan (swap-swapS x i j)
swap-swapS (gdd gst) i j = cong gdd (swap-swapG gst i j)
swap-swapS (rec gst) i j = cong rec (swap-swapG gst (suc i) (suc j))
swap-swapS (var p zero) zero ()
swap-swapS (var p zero) (suc i) zero = refl
swap-swapS (var p zero) (suc i) (suc j) = refl
swap-swapS (var p (suc x)) zero ()
swap-swapS (var p (suc x)) (suc i) zero
with var-suc i x p
... | p' , snd rewrite snd = refl
swap-swapS {suc n} (var p (suc x)) (suc i) (suc j)
rewrite swap-weakenS i (swap-polS (inject j) (var p x))
with swap-swapS (var p x) i j
... | pxij rewrite swap-weakenS (inject j) (swap-polS i (var p x))
= cong weaken1S pxij
swap-pol-dualG : (i : Fin (suc n)) (gst : GType (suc n)) →
swap-polG i (dualG gst) ≡ dualG (swap-polG i gst)
swap-pol-dualS : (i : Fin (suc n)) (st : SType (suc n)) →
swap-polS i (dualS st) ≡ dualS (swap-polS i st)
swap-pol-dualG i (transmit d t s) = cong (transmit _ (swap-polT i t)) (swap-pol-dualS i s)
swap-pol-dualG i (choice d m alt) = cong (choice _ _) (ext (swap-pol-dualS i ∘ alt))
swap-pol-dualG i end = refl
swap-pol-dualS i (gdd gst) = cong gdd (swap-pol-dualG i gst)
swap-pol-dualS i (rec gst) rewrite sym (swap-pol-dualG (suc i) gst) =
cong rec (swap-swapG (dualG gst) (suc i) zero)
swap-pol-dualS zero (var p zero) = refl
swap-pol-dualS (suc i) (var p zero) = refl
swap-pol-dualS zero (var p (suc x)) = refl
swap-pol-dualS {suc n} (suc i) (var p (suc x))
rewrite (dual-weakenS 0F (swap-polS i (var p x))) = cong weaken1S (swap-pol-dualS i (var p x))
----------------------------------------------------------------------
dual-invS : (st : SType n) → st ≡ dualS (dualS st)
dual-invG : (gst : GType n) → gst ≡ dualG (dualG gst)
dual-invS (gdd gst) = cong gdd (dual-invG gst)
dual-invS (rec gst) rewrite sym (swap-pol-dualG zero (dualG gst)) | swap-pol-invG zero (dualG (dualG gst)) = cong rec (dual-invG gst)
dual-invS (var p x) rewrite dual-pol-inv p = refl
dual-invG (transmit d t s) rewrite dual-dir-inv d = cong₂ (transmit d) refl (dual-invS s)
dual-invG (choice d m alt) rewrite dual-dir-inv d = cong (choice d m) (ext R)
where R : (x : Fin m) → alt x ≡ dualS (dualS (alt x))
R x rewrite sym (dual-invS (alt x)) = refl
dual-invG end = refl
dual-if : Polarity → SType n → SType n
dual-if POS s = s
dual-if NEG s = dualS s
dual-if-dual : (p : Polarity) (ist : SType 0) → dual-if p ist ≡ dual-if (dual-pol p) (dualS ist)
dual-if-dual POS ist = (dual-invS ist)
dual-if-dual NEG ist = refl
----------------------------------------------------------------------
-- substitution
st-substS : SType (suc n) → Fin (suc n) → SType 0 → SType n
st-substG : GType (suc n) → Fin (suc n) → SType 0 → GType n
st-substT : Type (suc n) → Fin (suc n) → SType 0 → Type n
st-substS (gdd gst) i st0 = gdd (st-substG gst i st0)
st-substS (rec gst) i st0 = rec (st-substG gst (suc i) st0)
st-substS {n} (var p zero) zero st0 = weakenS n (dual-if p st0)
st-substS {suc n} (var p zero) (suc i) st0 = var p zero
st-substS {suc n} (var p (suc x)) zero st0 = var p x
st-substS {suc n} (var p (suc x)) (suc i) st0 = weaken1S (st-substS (var p x) i st0)
st-substG (transmit d t s) i st0 = transmit d (st-substT t i st0) (st-substS s i st0)
st-substG (choice d m alt) i st0 = choice d m (λ j → st-substS (alt j) i st0)
st-substG end i st0 = end
st-substT TUnit i st0 = TUnit
st-substT TInt i st0 = TInt
st-substT (TPair ty ty₁) i st0 = TPair (st-substT ty i st0) (st-substT ty₁ i st0)
st-substT (TChan st) i st0 = TChan (st-substS st i st0)
----------------------------------------------------------------------
trivial-subst-var : (p : Polarity) (x : Fin n) (ist₁ ist₂ : SType 0)
→ st-substS (var p (suc x)) 0F ist₁ ≡ st-substS (var p (suc x)) 0F ist₂
trivial-subst-var p 0F ist1 ist2 = refl
trivial-subst-var p (suc x) ist1 ist2 = refl
trivial-subst-var' : (p : Polarity) (i : Fin n) (ist₁ ist₂ : SType 0)
→ st-substS (var p 0F) (suc i) ist₁ ≡ st-substS (var p 0F) (suc i) ist₂
trivial-subst-var' p 0F ist1 ist2 = refl
trivial-subst-var' p (suc x) ist1 ist2 = refl
----------------------------------------------------------------------
-- equivalence
variable
t t₁ t₂ t₁' t₂' : Type n
s s₁ s₂ : SType n
g g₁ g₂ : GType n
unfold : SType 0 → GType 0
unfold (gdd gst) = gst
unfold (rec gst) = st-substG gst 0F (rec gst)
-- type equivalence
data EquivT (R : SType n → SType n → Set) : Type n → Type n → Set where
eq-unit : EquivT R TUnit TUnit
eq-int : EquivT R TInt TInt
eq-pair : EquivT R t₁ t₁' → EquivT R t₂ t₂' → EquivT R (TPair t₁ t₂) (TPair t₁' t₂')
eq-chan : R s₁ s₂ → EquivT R (TChan s₁) (TChan s₂)
-- session type equivalence
data EquivG (R : SType n → SType n → Set) : GType n → GType n → Set where
eq-transmit : (d : Dir) → EquivT R t₁ t₂ → R s₁ s₂ → EquivG R (transmit d t₁ s₁) (transmit d t₂ s₂)
eq-choice : ∀ {alt alt'} → (d : Dir) → ((i : Fin m) → R (alt i) (alt' i)) → EquivG R (choice d m alt) (choice d m alt')
eq-end : EquivG R end end
record Equiv (s₁ s₂ : SType 0) : Set where
coinductive
field force : EquivG Equiv (unfold s₁) (unfold s₂)
open Equiv
_≈_ = Equiv
_≈'_ = EquivG Equiv
_≈ᵗ_ = EquivT Equiv
-- reflexive
≈-refl : s ≈ s
≈'-refl : g ≈' g
≈ᵗ-refl : t ≈ᵗ t
force (≈-refl {s}) = ≈'-refl
≈'-refl {transmit d t s} = eq-transmit d ≈ᵗ-refl ≈-refl
≈'-refl {choice d m alt} = eq-choice d (λ i → ≈-refl)
≈'-refl {end} = eq-end
≈ᵗ-refl {TUnit} = eq-unit
≈ᵗ-refl {TInt} = eq-int
≈ᵗ-refl {TPair t t₁} = eq-pair ≈ᵗ-refl ≈ᵗ-refl
≈ᵗ-refl {TChan x} = eq-chan ≈-refl
-- symmetric
≈-symm : s₁ ≈ s₂ → s₂ ≈ s₁
≈'-symm : g₁ ≈' g₂ → g₂ ≈' g₁
≈ᵗ-symm : t₁ ≈ᵗ t₂ → t₂ ≈ᵗ t₁
force (≈-symm s₁≈s₂) = ≈'-symm (force s₁≈s₂)
≈'-symm (eq-transmit d x x₁) = eq-transmit d (≈ᵗ-symm x) (≈-symm x₁)
≈'-symm (eq-choice d x) = eq-choice d (≈-symm ∘ x)
≈'-symm eq-end = eq-end
≈ᵗ-symm eq-unit = eq-unit
≈ᵗ-symm eq-int = eq-int
≈ᵗ-symm (eq-pair t₁≈ᵗt₂ t₁≈ᵗt₃) = eq-pair (≈ᵗ-symm t₁≈ᵗt₂) (≈ᵗ-symm t₁≈ᵗt₃)
≈ᵗ-symm (eq-chan x) = eq-chan (≈-symm x)
----------------------------------------------------------------------
-- Proof of equivalence to coinductive definition
open import DualCoinductive hiding (n)
open COI
open IND hiding (_≈_ ; _≈'_ ; ≈-refl ; ≈'-refl ; ≈ᵗ-refl)
ind2coiT : IND.Type 0 → COI.Type
ind2coiS : IND.SType 0 → COI.SType
ind2coiG : IND.GType 0 → COI.STypeF COI.SType
ind2coiT TUnit = TUnit
ind2coiT TInt = TInt
ind2coiT (TPair it it₁) = TPair (ind2coiT it) (ind2coiT it₁)
ind2coiT (TChan st) = TChan (ind2coiS st)
ind2coiG (transmit d t ist) = transmit d (ind2coiT t) (ind2coiS ist)
ind2coiG (choice d m alt) = choice d m (ind2coiS ∘ alt)
ind2coiG end = end
SType.force (ind2coiS (gdd gst)) = ind2coiG gst
SType.force (ind2coiS (rec gst)) = ind2coiG (st-substG gst zero (rec gst))
----------------------------------------------------------------------
subst-weakenS : (s : IND.SType (suc n)) (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (s0 : IND.SType 0)
→ st-substS (weaken1'S (inject₁ j) s) (suc i) s0 ≡ weaken1'S j (st-substS s i s0)
subst-weakenG : (g : IND.GType (suc n)) (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (s0 : IND.SType 0)
→ st-substG (weaken1'G (inject₁ j) g) (suc i) s0 ≡ weaken1'G j (st-substG g i s0)
subst-weakenT : (t : IND.Type (suc n)) (i : Fin (suc n)) (j : Fin (suc n)) (le : Data.Fin._≤_ j i) (s0 : IND.SType 0)
→ st-substT (weaken1'T (inject₁ j) t) (suc i) s0 ≡ weaken1'T j (st-substT t i s0)
subst-weakenS (gdd gst) i j le s0 = cong gdd (subst-weakenG gst i j le s0)
subst-weakenS (rec gst) i j le s0 = cong rec (subst-weakenG gst (suc i) (suc j) (s≤s le) s0)
subst-weakenS (var p x) 0F 0F le s0 = refl
subst-weakenS {suc n} (var p x) (suc i) 0F le s0 = refl
subst-weakenS {suc n} (var p 0F) (suc i) (suc j) le s0 = refl
subst-weakenS {suc n} (var p (suc x)) (suc i) (suc j) (s≤s le) s0 rewrite (weak-weakS j 0F z≤n (st-substS (var p x) i s0))
= cong (weaken1'S 0F) (subst-weakenS (var p x) i j le s0)
subst-weakenG (transmit d t s) i j le s0 = cong₂ (transmit d) (subst-weakenT t i j le s0) (subst-weakenS s i j le s0)
subst-weakenG (choice d m alt) i j le s0 = cong (choice d m) (ext (λ m' → subst-weakenS (alt m') i j le s0 ))
subst-weakenG end i j le s0 = refl
subst-weakenT TUnit i j le s0 = refl
subst-weakenT TInt i j le s0 = refl
subst-weakenT (TPair t t₁) i j le s0 = cong₂ TPair (subst-weakenT t i j le s0) (subst-weakenT t₁ i j le s0)
subst-weakenT (TChan s) i j le s0 = cong TChan (subst-weakenS s i j le s0)
subst-swap-dualT : ∀ {ist} → (t : IND.Type (suc n)) (i : Fin (suc n)) →
st-substT t i ist ≡ st-substT (swap-polT i t) i (IND.dualS ist)
subst-swap-dualS : ∀ {ist} → (st : IND.SType (suc n)) (i : Fin (suc n)) →
st-substS st i ist ≡ st-substS (swap-polS i st) i (IND.dualS ist)
subst-swap-dualG : ∀ {ist} → (gst : IND.GType (suc n)) (i : Fin (suc n)) →
st-substG gst i ist ≡ st-substG (swap-polG i gst) i (IND.dualS ist)
subst-swap-dualT TUnit i = refl
subst-swap-dualT TInt i = refl
subst-swap-dualT (TPair ty ty₁) i = cong₂ TPair (subst-swap-dualT ty i) (subst-swap-dualT ty₁ i)
subst-swap-dualT (TChan x) i = cong TChan (subst-swap-dualS x i)
subst-swap-dualS (gdd gst) i = cong gdd (subst-swap-dualG gst i)
subst-swap-dualS (rec gst) i = cong rec (subst-swap-dualG gst (suc i))
subst-swap-dualS {n} {ist} (var p zero) zero = cong (weakenS n) (dual-if-dual p ist)
subst-swap-dualS {suc n} (var p zero) (suc i) = refl
subst-swap-dualS {suc n} (var p (suc x)) zero = refl
subst-swap-dualS {suc n}{ist} (var p (suc x)) (suc i)
rewrite subst-weakenS (swap-polS i (var p x)) i 0F z≤n (dualS ist)
= cong (weaken1'S 0F) (subst-swap-dualS ((var p x)) i)
subst-swap-dualG (transmit d t s) i = cong₂ (transmit d) (subst-swap-dualT t i) (subst-swap-dualS s i)
subst-swap-dualG (choice d m alt) i = cong (choice d m) (ext (λ x → subst-swap-dualS (alt x) i))
subst-swap-dualG end i = refl
----------------------------------------------------------------------
swap-i-weakenS : (i : Fin (suc n)) (s : IND.SType n) → swap-polS i (weaken1'S i s) ≡ weaken1'S i s
swap-i-weakenG : (i : Fin (suc n)) (g : IND.GType n) → swap-polG i (weaken1'G i g) ≡ weaken1'G i g
swap-i-weakenT : (i : Fin (suc n)) (t : IND.TType n) → swap-polT i (weaken1'T i t) ≡ weaken1'T i t
swap-i-weakenS i (gdd gst) = cong gdd (swap-i-weakenG i gst)
swap-i-weakenS i (rec gst) = cong rec (swap-i-weakenG (suc i) gst)
swap-i-weakenS zero (var p zero) = refl
swap-i-weakenS (suc i) (var p zero) = refl
swap-i-weakenS zero (var p (suc x)) = refl
swap-i-weakenS (suc i) (var p (suc x)) = cong weaken1S (swap-i-weakenS i (var p x))
swap-i-weakenG i (transmit d t s) = cong₂ (transmit d) (swap-i-weakenT i t) (swap-i-weakenS i s)
swap-i-weakenG i (choice d m alt) = cong (choice d m) (ext (swap-i-weakenS i ∘ alt))
swap-i-weakenG i end = refl
swap-i-weakenT i TUnit = refl
swap-i-weakenT i TInt = refl
swap-i-weakenT i (TPair t₁ t₂) = cong₂ TPair (swap-i-weakenT i t₁) (swap-i-weakenT i t₂)
swap-i-weakenT i (TChan x) = cong TChan (swap-i-weakenS i x)
subst-swapG : (ist : IND.SType 0) (i : Fin (suc (suc n))) (j : Fin′ i) (g : GType (suc (suc n))) →
st-substG (swap-polG (inject j) g) i ist ≡ swap-polG (inject! j) (st-substG g i ist)
subst-swapS : (ist : IND.SType 0) (i : Fin (suc (suc n))) (j : Fin′ i) (s : IND.SType (suc (suc n))) →
st-substS (swap-polS (inject j) s) i ist ≡ swap-polS (inject! j) (st-substS s i ist)
subst-swapT : (ist : IND.SType 0) (i : Fin (suc (suc n))) (j : Fin′ i) (g : IND.Type (suc (suc n))) →
st-substT (swap-polT (inject j) g) i ist ≡ swap-polT (inject! j) (st-substT g i ist)
subst-swapG ist i j (transmit d t s) = cong₂ (transmit d) (subst-swapT ist i j t) (subst-swapS ist i j s)
subst-swapG ist i j (choice d m alt) = cong (choice d m) (ext (λ x → subst-swapS ist i j (alt x)))
subst-swapG ist i j end = refl
subst-swapS ist i j (gdd gst) = cong gdd (subst-swapG ist i j gst)
subst-swapS ist i j (rec gst) = cong rec (subst-swapG ist (suc i) (suc j) gst)
subst-swapS{zero} ist zero () (var p zero)
subst-swapS {zero} ist (suc zero) zero (var p zero) = refl
subst-swapS {zero} ist (suc zero) zero (var p (suc x))
rewrite swap-i-weakenS zero (st-substS (var p x) zero ist) = refl
subst-swapS{suc n} ist (suc i) zero (var p zero) = refl
subst-swapS{suc n} ist (suc i) (suc j) (var p zero) = refl
subst-swapS{suc n} ist zero () (var p (suc x))
subst-swapS{suc n} ist (suc i) zero (var p (suc x))
rewrite swap-i-weakenS zero (st-substS (var p x) i ist) = refl
subst-swapS{suc n} ist (suc i) (suc j) (var p (suc x))
rewrite subst-weakenS (swap-polS (inject j) (var p x)) i 0F z≤n ist
| swap-weakenS (inject! j) (st-substS (var p x) i ist)
= cong weaken1S (subst-swapS ist i j (var p x))
subst-swapT ist i j TUnit = refl
subst-swapT ist i j TInt = refl
subst-swapT ist i j (TPair t t₁) = cong₂ TPair (subst-swapT ist i j t) (subst-swapT ist i j t₁)
subst-swapT ist i j (TChan x) = cong TChan (subst-swapS ist i j x)
----------------------------------------------------------------------
dual-recT' : (t : TType (suc n)) (i : Fin (suc n)) (ist : IND.SType 0)
→ st-substT (swap-polT i t) i (dualS ist) ≡ st-substT t i ist
dual-recG' : (g : GType (suc n)) (i : Fin (suc n)) (ist : IND.SType 0)
→ st-substG (swap-polG i g) i (dualS ist) ≡ st-substG g i ist
dual-recS' : (s : IND.SType (suc n)) (i : Fin (suc n)) (ist : IND.SType 0)
→ st-substS (swap-polS i s) i (dualS ist) ≡ st-substS s i ist
dual-recT' TUnit i ist = refl
dual-recT' TInt i ist = refl
dual-recT' (TPair t t₁) i ist = cong₂ TPair (dual-recT' t i ist) (dual-recT' t₁ i ist)
dual-recT' (TChan s) i ist = cong TChan (dual-recS' s i ist)
dual-recG' (transmit d t s) i ist = cong₂ (transmit d) (dual-recT' t i ist) (dual-recS' s i ist)
dual-recG' (choice d m alt) i ist = cong (choice d m) (ext (λ m' → dual-recS' (alt m') i ist))
dual-recG' end i ist = refl
dual-recS' (gdd gst) i ist = cong gdd (dual-recG' gst i ist)
dual-recS' (rec gst) i ist = cong rec (dual-recG' gst (suc i) ist)
dual-recS' (var p 0F) 0F ist rewrite (dual-if-dual p ist) = refl
dual-recS' (var p (suc x)) 0F ist = trivial-subst-var p x (dualS ist) (ist)
dual-recS' (var p 0F) (suc i) ist = trivial-subst-var' p i (dualS ist) (ist)
dual-recS' (var p (suc x)) (suc i) ist rewrite (subst-swap-dualS{ist = ist} (var p (suc x)) (suc i))
= refl
----------------------------------------------------------------------
-- show that the dualS function is compatible with unfolding
-- that is
-- COI.dual ∘ ind2coi ≈ ind2coi ∘ IND.dual
dual-lemmaS : (s : IND.SType (suc n)) (j : Fin (suc n)) (s0 : IND.SType 0)
→ st-substS (dualS s) j s0 ≡ dualS (st-substS s j s0)
dual-lemmaG : (g : IND.GType (suc n)) (j : Fin (suc n)) (s0 : IND.SType 0)
→ st-substG (dualG g) j s0 ≡ dualG (st-substG g j s0)
dual-lemmaS (gdd gst) j s0 = cong gdd (dual-lemmaG gst j s0)
dual-lemmaS (rec gst) j s0 rewrite (subst-swapG s0 (suc j) 0F (dualG gst)) =
let rst = dual-lemmaG gst (suc j) s0 in cong rec (cong (swap-polG 0F) rst)
dual-lemmaS {n} (var POS 0F) 0F s0 = sym (dual-weakenS' n s0)
dual-lemmaS {n} (var NEG 0F) 0F s0 rewrite (sym (dual-weakenS' n s0)) | (sym (dual-invS (weakenS n s0))) = refl
dual-lemmaS {suc n} (var POS 0F) (suc j) s0 = refl
dual-lemmaS {suc n} (var NEG 0F) (suc j) s0 = refl
dual-lemmaS {suc n} (var POS (suc x)) 0F s0 = refl
dual-lemmaS {suc n} (var NEG (suc x)) 0F s0 = refl
dual-lemmaS {suc n} (var POS (suc x)) (suc j) s0 rewrite (dual-weakenS 0F (st-substS (var POS x) j s0)) = cong (weaken1'S 0F) (dual-lemmaS (var POS x) j s0)
dual-lemmaS {suc n} (var NEG (suc x)) (suc j) s0 rewrite (dual-weakenS 0F (st-substS (var NEG x) j s0)) = cong (weaken1'S 0F) (dual-lemmaS (var NEG x) j s0)
dual-lemmaG (transmit d t s) j s0 = cong₂ (transmit (dual-dir d)) refl (dual-lemmaS s j s0)
dual-lemmaG (choice d m alt) j s0 = cong (choice (dual-dir d) m) (ext (λ m' → dual-lemmaS (alt m') j s0))
dual-lemmaG end j s0 = refl
dual-compatibleS : (ist : IND.SType 0) →
COI.dual (ind2coiS ist) ≈ ind2coiS (IND.dualS ist)
dual-compatibleG : (gst : IND.GType 0) →
COI.dualF (ind2coiG gst) ≈' ind2coiG (IND.dualG gst)
Equiv.force (dual-compatibleS (gdd gst)) = dual-compatibleG gst
Equiv.force (dual-compatibleS (rec gst))
rewrite (dual-recG' (dualG gst) 0F (rec gst)) | dual-lemmaG gst 0F (rec gst) = dual-compatibleG (st-substG gst zero (rec gst))
dual-compatibleG (transmit d t s) = eq-transmit (dual-dir d) ≈ᵗ-refl (dual-compatibleS s)
dual-compatibleG (choice d m alt) = eq-choice (dual-dir d) (dual-compatibleS ∘ alt)
dual-compatibleG end = eq-end
| {
"alphanum_fraction": 0.5872701556,
"avg_line_length": 44.2428035044,
"ext": "agda",
"hexsha": "662a5a1a15210da86b0008fab1b084dc1f3c9aa8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "cd41919582013e75463308c32750e2712cf2de86",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "kcaliban/dual-session",
"max_forks_repo_path": "src/DualLM.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cd41919582013e75463308c32750e2712cf2de86",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "kcaliban/dual-session",
"max_issues_repo_path": "src/DualLM.agda",
"max_line_length": 156,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cd41919582013e75463308c32750e2712cf2de86",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "kcaliban/dual-session",
"max_stars_repo_path": "src/DualLM.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 14508,
"size": 35350
} |
------------------------------------------------------------------------------
-- Axiomatic PA properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module PA.Axiomatic.Standard.PropertiesI where
open import Common.FOL.Relation.Binary.EqReasoning
open import PA.Axiomatic.Standard.Base
------------------------------------------------------------------------------
-- Congruence properties
succCong : ∀ {m n} → m ≡ n → succ m ≡ succ n
succCong refl = refl
+-leftCong : ∀ {m n o} → m ≡ n → m + o ≡ n + o
+-leftCong refl = refl
+-rightCong : ∀ {m n o} → n ≡ o → m + n ≡ m + o
+-rightCong refl = refl
------------------------------------------------------------------------------
+-leftIdentity : ∀ n → zero + n ≡ n
+-leftIdentity = PA₃
+-rightIdentity : ∀ n → n + zero ≡ n
+-rightIdentity = ℕ-ind A A0 is
where
A : ℕ → Set
A i = i + zero ≡ i
A0 : A zero
A0 = +-leftIdentity zero
is : ∀ i → A i → A (succ i)
is i ih = succ i + zero ≡⟨ PA₄ i zero ⟩
succ (i + zero) ≡⟨ succCong ih ⟩
succ i ∎
+-asocc : ∀ m n o → m + n + o ≡ m + (n + o)
+-asocc m n o = ℕ-ind A A0 is m
where
A : ℕ → Set
A i = i + n + o ≡ i + (n + o)
A0 : A zero
A0 = zero + n + o ≡⟨ +-leftCong (+-leftIdentity n) ⟩
n + o ≡⟨ sym (+-leftIdentity (n + o)) ⟩
zero + (n + o) ∎
is : ∀ i → A i → A (succ i)
is i ih = succ i + n + o ≡⟨ +-leftCong (PA₄ i n) ⟩
succ (i + n) + o ≡⟨ PA₄ (i + n) o ⟩
succ (i + n + o) ≡⟨ succCong ih ⟩
succ (i + (n + o)) ≡⟨ sym (PA₄ i (n + o)) ⟩
succ i + (n + o) ∎
x+Sy≡S[x+y] : ∀ m n → m + succ n ≡ succ (m + n)
x+Sy≡S[x+y] m n = ℕ-ind A A0 is m
where
A : ℕ → Set
A i = i + succ n ≡ succ (i + n)
A0 : A zero
A0 = zero + succ n ≡⟨ +-leftIdentity (succ n) ⟩
succ n ≡⟨ succCong (sym (+-leftIdentity n)) ⟩
succ (zero + n) ∎
is : ∀ i → A i → A (succ i)
is i ih = succ i + succ n ≡⟨ PA₄ i (succ n) ⟩
succ (i + succ n) ≡⟨ succCong ih ⟩
succ (succ (i + n)) ≡⟨ succCong (sym (PA₄ i n)) ⟩
succ (succ i + n) ∎
+-comm : ∀ m n → m + n ≡ n + m
+-comm m n = ℕ-ind A A0 is m
where
A : ℕ → Set
A i = i + n ≡ n + i
A0 : A zero
A0 = zero + n ≡⟨ +-leftIdentity n ⟩
n ≡⟨ sym (+-rightIdentity n) ⟩
n + zero ∎
is : ∀ i → A i → A (succ i)
is i ih = succ i + n ≡⟨ PA₄ i n ⟩
succ (i + n) ≡⟨ succCong ih ⟩
succ (n + i) ≡⟨ sym (x+Sy≡S[x+y] n i) ⟩
n + succ i ∎
| {
"alphanum_fraction": 0.4022570076,
"avg_line_length": 28.0306122449,
"ext": "agda",
"hexsha": "f884f7fa85c7226fc6b40bcbb94bcac94459118a",
"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/PA/Axiomatic/Standard/PropertiesI.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/PA/Axiomatic/Standard/PropertiesI.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/PA/Axiomatic/Standard/PropertiesI.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": 1004,
"size": 2747
} |
{-# OPTIONS --without-K #-}
open import HoTT
open import cohomology.Exactness
module cohomology.ExactPairIso where
{- An exact sequence 0 → G → H → 0 implies that G == H -}
module _ {i} {G H K L : Group i} {φ : H →ᴳ K}
(ex : is-exact-seq (G ⟨ cst-hom ⟩→ H ⟨ φ ⟩→ K ⟨ cst-hom ⟩→ L ⊣|)) where
private
inj : (h₁ h₂ : Group.El H) → GroupHom.f φ h₁ == GroupHom.f φ h₂ → h₁ == h₂
inj = zero-kernel-injective φ
(λ h p → Trunc-rec (Group.El-level H _ _) (λ s → ! (snd s))
(ktoi (exact-get ex 0) h p))
exact-pair-iso : H == K
exact-pair-iso = surj-inj-= φ inj (λ k → ktoi (exact-get ex 1) k idp)
module _ {i} {G H K J : Group i} {φ : G →ᴳ H} {ψ : H →ᴳ K}
{χ : K →ᴳ J} (p : G == 0ᴳ) (q : J == 0ᴳ)
(ex : is-exact-seq (G ⟨ φ ⟩→ H ⟨ ψ ⟩→ K ⟨ χ ⟩→ J ⊣|)) where
private
ex₁ : is-exact-seq (0ᴳ ⟨ cst-hom ⟩→ H ⟨ ψ ⟩→ K ⟨ χ ⟩→ J ⊣|)
ex₁ = transport
(λ {(G' , φ') → is-exact-seq (G' ⟨ φ' ⟩→ H ⟨ ψ ⟩→ K ⟨ χ ⟩→ J ⊣|)})
(pair= p (prop-has-all-paths-↓ {B = λ L → L →ᴳ H}
(raise-level -2 0ᴳ-hom-out-level)))
ex
ex₂ : is-exact-seq (0ᴳ ⟨ cst-hom ⟩→ H ⟨ ψ ⟩→ K ⟨ cst-hom ⟩→ 0ᴳ ⊣|)
ex₂ = transport
(λ {(J' , χ') → is-exact-seq (0ᴳ ⟨ cst-hom ⟩→ H ⟨ ψ ⟩→ K ⟨ χ' ⟩→ J' ⊣|)})
(pair= q (prop-has-all-paths-↓ {B = λ L → K →ᴳ L}
(raise-level _ 0ᴳ-hom-in-level)))
ex₁
exact-pair-path-iso : H == K
exact-pair-path-iso = exact-pair-iso ex₂
| {
"alphanum_fraction": 0.4899792674,
"avg_line_length": 33.6511627907,
"ext": "agda",
"hexsha": "08af547e16523dfef03b68332395108b37c7ea02",
"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/cohomology/ExactPairIso.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/cohomology/ExactPairIso.agda",
"max_line_length": 79,
"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/cohomology/ExactPairIso.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 654,
"size": 1447
} |
{-# OPTIONS --copatterns --sized-types #-}
{- | The purpose of this module is to demonstrate how observational type theory
can be implemented for arbitrary types in Agda through the use of tests
and a corresponding bisimulation proof method.
To use the equivalence for a type A, the type has to be made _testable_ by
creating an instance of Testable for it, see the accompanying module
TestsInstances. Such an instance effectively encodes A as inductive or
coinductive type, by giving an observation map to a coproduct of product
of components of A. For now, we do not pose any restrictions on this encoding,
hence it can be used to induce trivial equivalences.
Using such an instance of Testable for A, we can define _tests_ and
_observational equivalence_ for A. Moreover, we give a bisimulation proof
method and prove its soundness.
-}
module Tests where
open import Size
open import Level
open import Data.Product
open import Data.Bool
open import Function
open import Relation.Binary.PropositionalEquality as P
open ≡-Reasoning
open import Relation.Binary
open import Isomorphisms
-- | Write dependent functions as Π-type to make duality between
-- inductive and coinducitve types clearer.
record Π {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where
field
app : (x : A) → B x
open Π public
-- | Generalised copairing for coproducts:
-- Turn an I-indexed tuple of maps fᵢ : Bᵢ → C into a map Σ I B → C.
cotuple : {I C : Set} → {B : I → Set} → ((i : I) → B i → C) → (Σ I B → C)
cotuple f x = f (proj₁ x) (proj₂ x)
-- | Distinguish inductive and coinductive types
data Kind : Set where
ind : Kind
coind : Kind
--- | Make a type observable. An inductive type shall be represented by
--- a coproduct, whereas a coinductive type is represented by a product.
ObsTy : (I : Set) (B : I → Set) → Kind → Set
ObsTy I B ind = Σ I B
ObsTy I B coind = Π I B
-- | Make a type testable
record Testable (A : Set) : Set₁ where
coinductive
field
index : Set
parts : index → Set
kind : Kind
obs : A → ObsTy index parts kind
partsTestable : (i : index) → Testable (parts i)
open Testable public
record IsoTestable (A : Set) : Set₁ where
field
testable : Testable A
obsIso : IsIso (obs testable)
open IsoTestable public
SubTests : {l : Size} → {A : Set} → Testable A → Kind → Set
-- | Test formulae
data Test {i : Size} {A : Set} (T : Testable A) : Set where
⊤ : Test T
⊥ : Test T
nonTriv : {j : Size< i} → SubTests {j} T (kind T) → Test {i} {A} T
SubTests {l} T ind = Π (index T) (λ i → Test {l} (partsTestable T i))
SubTests {l} T coind = Σ (index T) (λ i → Test {l} (partsTestable T i))
-- | Satisfaction of subtests.
sat : {A : Set} {T : Testable A} {l : Size} →
(k : Kind) → SubTests {l} T k → ObsTy (index T) (parts T) k → Bool
-- | Test satisfaction
_⊨_ : {A : Set} {T : Testable A} → A → Test T → Bool
x ⊨ ⊤ = true
x ⊨ ⊥ = false
_⊨_ {A} {T} x (nonTriv nt) = sat (kind T) nt (obs T x)
sat ind φs o = cotuple (λ i y → y ⊨ app φs i) o
sat coind (i , φ) o = app o i ⊨ φ
-- | Observational equivalence: terms are equal if they satisfy the same tests.
record _≃⟨_⟩_ {A : Set} (x : A) (T : Testable A) (y : A) : Set₁ where
field
eqProof : (φ : Test T) → (x ⊨ φ ≡ y ⊨ φ)
open _≃⟨_⟩_ public
≡→≃ : {A : Set} → {T : Testable A} →
{a b : A} → a ≡ b → a ≃⟨ T ⟩ b
≡→≃ p = record { eqProof = λ φ → cong (λ x → x ⊨ φ) p }
≃-refl : {A : Set} → (T : Testable A) →
{a : A} → a ≃⟨ T ⟩ a
≃-refl T = record { eqProof = λ φ → refl }
≃-sym : {A : Set} → (T : Testable A) →
{a b : A} → a ≃⟨ T ⟩ b → b ≃⟨ T ⟩ a
≃-sym T p = record { eqProof = sym ∘ (eqProof p) }
≃-trans : {A : Set} → (T : Testable A) →
{a b c : A} → a ≃⟨ T ⟩ b → b ≃⟨ T ⟩ c → a ≃⟨ T ⟩ c
≃-trans T p₁ p₂ =
record { eqProof = λ φ → trans (eqProof p₁ φ) (eqProof p₂ φ) }
≃-setoid : {A : Set} → (T : Testable A) → Setoid _ _
≃-setoid {A} T = record
{ Carrier = A
;_≈_ = λ x y → x ≃⟨ T ⟩ y
; isEquivalence = record
{ refl = ≃-refl T
; sym = ≃-sym T
; trans = ≃-trans T }
}
-- Most likely impossible to prove within Agda.
-- Is it consistent with the system to postulate this for _IsoTestable_ ?
-- ≃-cong : {A B : Set} → {T₁ : Testable A} → {T₂ : Testable B} → {a b : A} →
-- (f : A → B) → a ≃⟨ T₁ ⟩ b → f a ≃⟨ T₂ ⟩ f b
-- If A is testable and there is a map B → A, then B is also testable.
comap-testable : {A B : Set} → (B → A) → Testable A → Testable B
comap-testable {A} {B} f T =
record
{ index = index T
; parts = parts T
; kind = kind T
; obs = (obs T) ∘ f
; partsTestable = partsTestable T
}
-- | If A is testable and A ≅ B, then B is iso-testable as well.
iso-testable : {A B : Set} → Iso B A → IsoTestable A → IsoTestable B
iso-testable {A} {B} I T =
record
{ testable = comap-testable (Iso.iso I) (testable T)
; obsIso = iso-comp (Iso.indeedIso I) (obsIso T)
}
-- | Heterogeneous
record _~⟨_∥_⟩_ {A B : Set}
(x : A) (T : Testable A) (I : Iso B A) (y : B) : Set₁ where
field
eqProofH : (φ : Test T) → (x ⊨ φ ≡ (Iso.iso I y) ⊨ φ)
open _~⟨_∥_⟩_ public
-- | Helper to match on Kind in construction of ≈.
≈-Proof : {A : Set} →
(k : Kind) →
(T : Testable A) →
(A → ObsTy (index T) (parts T) k) →
A → A → Set
-- | Bisimilarity induced from testable types.
record _≈⟨_⟩_ {A : Set} (x : A) (T : Testable A) (y : A) : Set where
coinductive
field
proof : ≈-Proof (kind T) T (obs T) x y
open _≈⟨_⟩_ public
-- | Helper to fiddle around with index in construction of IndProof.
ResolveIdx : {A : Set} → (T : Testable A) →
(i : index T) → (r s : ObsTy (index T) (parts T) ind) →
proj₁ r ≡ i → proj₁ s ≡ i → Set
ResolveIdx T i (.i , x') (.i , y') refl refl = x' ≈⟨ partsTestable T i ⟩ y'
-- | Proofs of bisimilarity on inductive types.
record IndProof {A : Set}
(T : Testable A)
(o : A → ObsTy (index T) (parts T) ind)
(x y : A) : Set where
coinductive
field
which : index T
eqIndex₁ : proj₁ (o x) ≡ which
eqIndex₂ : proj₁ (o y) ≡ which
eqTrans : ResolveIdx T which (o x) (o y) eqIndex₁ eqIndex₂
open IndProof public
-- | Proofs of bisimilarity on coinductive types.
record CoindProof {A : Set}
(T : Testable A)
(o : A → ObsTy (index T) (parts T) coind)
(x y : A) : Set where
coinductive
field
eqStep : (i : index T) → app (o x) i ≈⟨ partsTestable T i ⟩ app (o y) i
open CoindProof public
≈-Proof ind = IndProof
≈-Proof coind = CoindProof
-- | Lemma for induction to prove soundness of bisimilarity
lem-≈→≃-testInduct : {j : Size} {A : Set} → (T : Testable A) → (x y : A) →
x ≈⟨ T ⟩ y → (φ : Test {j} T) → x ⊨ φ ≡ y ⊨ φ
lem-≈→≃-testInduct _ _ _ _ ⊤ = refl
lem-≈→≃-testInduct _ _ _ _ ⊥ = refl
lem-≈→≃-testInduct {j} {A} T x y x≈y (nonTriv {l} nt)
= matchKind (kind T) nt (obs T) (proof x≈y)
where
matchKind : (k : Kind) →
(nt : SubTests {l} T k) →
(o : A → ObsTy (index T) (parts T) k) →
≈-Proof k T o x y →
sat k nt (o x) ≡ sat k nt (o y)
matchKind ind nt o p
= refine (which p) (o x) (o y) (eqIndex₁ p) (eqIndex₂ p) (eqTrans p)
where
--| Do pattern matching on IndProof
refine : (i : index T) → (r s : ObsTy (index T) (parts T) ind) →
(eqP₁ : proj₁ r ≡ i) → (eqP₂ : proj₁ s ≡ i) →
ResolveIdx T i r s eqP₁ eqP₂ →
(proj₂ r) ⊨ app nt (proj₁ r) ≡ (proj₂ s) ⊨ app nt (proj₁ s)
refine i (.i , x') (.i , y') refl refl p'
= lem-≈→≃-testInduct (partsTestable T i) x' y' p' (app nt i)
matchKind coind nt o p
= lem-≈→≃-testInduct (partsTestable T i) x' y' (eqStep p i) ψ
where
i : index T
i = proj₁ nt
ψ = proj₂ nt
x' = app (o x) i
y' = app (o y) i
-- | Bisimulation proofs are sound for observational equivalence.
≈→≃ : {A : Set} → (T : Testable A) → (x y : A) →
x ≈⟨ T ⟩ y → x ≃⟨ T ⟩ y
≈→≃ T x y x≈y = record { eqProof = lem-≈→≃-testInduct T x y x≈y }
{-
≃→≈ : {A : Set} → (T : Testable A) → (x y : A) →
x ≃⟨ T ⟩ y → x ≈⟨ T ⟩ y
≃→≈ {A} T x y x≃y = record { proof = matchKind (kind T) (obs T) }
where
matchKind : (k : Kind) →
(o : A → ObsTy (index T) (parts T) k) →
≈-Proof k T o x y
matchKind ind o = {!!}
matchKind coind o = {!!}
-}
| {
"alphanum_fraction": 0.5700879069,
"avg_line_length": 32.5019305019,
"ext": "agda",
"hexsha": "fd742115f00651c6698f9ffb0f5c695b867c1abb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hbasold/Sandbox",
"max_forks_repo_path": "OTTTests/Tests.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hbasold/Sandbox",
"max_issues_repo_path": "OTTTests/Tests.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hbasold/Sandbox",
"max_stars_repo_path": "OTTTests/Tests.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3210,
"size": 8418
} |
{-# OPTIONS --safe #-}
open import Generics.Prelude hiding (lookup)
open import Generics.Telescope
open import Generics.Desc
open import Generics.All
open import Generics.HasDesc
import Generics.Helpers as Helpers
module Generics.Constructions.Elim {P I ℓ} {A : Indexed P I ℓ} where
module _ (H : HasDesc A) (open HasDesc H)
{p c} (Pr : Pred′ I (λ i → A′ (p , i) → Set c))
where
private
variable
V : ExTele P
i : ⟦ I ⟧tel p
v : ⟦ V ⟧tel p
Pr′ : A′ (p , i) → Set c
Pr′ {i} = unpred′ I _ Pr i
--------------------------
-- Types of methods
levelElimIndArg levelElimCon : ConDesc P V I → Level
levelElimIndArg (var x) = c
levelElimIndArg (π {ℓ} i S C) = ℓ ⊔ levelElimIndArg C
levelElimIndArg (A ⊗ B) = levelElimIndArg A ⊔ levelElimIndArg B
levelElimCon (var x) = c
levelElimCon (π {ℓ′} i S C) = ℓ′ ⊔ levelElimCon C
levelElimCon (A ⊗ B) = levelIndArg A ℓ ⊔ levelElimIndArg A ⊔ levelElimCon B
MethodIndArg : (C : ConDesc P V I)
→ ⟦ C ⟧IndArg A′ (p , v)
→ Set (levelElimIndArg C)
MethodIndArg (var x ) X = Pr′ X
MethodIndArg (π ia S C) X = Π< ia > (S _) (MethodIndArg C ∘ app< ia > X)
MethodIndArg (A ⊗ B) (mA , mB) = MethodIndArg A mA × MethodIndArg B mB
MethodCon : (C : ConDesc P V I)
→ (∀ {i} → ⟦ C ⟧Con A′ (p , v , i) → Set c)
→ Set (levelElimCon C)
MethodCon (var x) f = f refl
MethodCon (π ia S C) f = Π< ia > (S _) (λ s → MethodCon C (f ∘ (s ,_)))
MethodCon (A ⊗ B) f = {g : ⟦ A ⟧IndArg A′ (p , _)}
(Pg : MethodIndArg A g)
→ MethodCon B (f ∘ (g ,_))
Methods : ∀ k → Set (levelElimCon (lookupCon D k))
Methods k = MethodCon (lookupCon D k) λ x → Pr′ (constr (k , x))
--------------------------
-- Eliminator
module _ (methods : Els Methods) where
elimData-wf
: (x : ⟦ D ⟧Data A′ (p , i))
→ AllDataω Acc D x
→ Pr′ (constr x)
elim-wf : (x : A′ (p , i)) → Acc x → Pr′ x
elim-wf x (acc a) = subst Pr′ (constr∘split x) (elimData-wf (split x) a)
elimData-wf (k , x) a
= elimCon (lookupCon D k) (methods k) x a
where
elimIndArg
: (C : ConDesc P V I)
→ (x : ⟦ C ⟧IndArg A′ (p , v))
→ AllIndArgω Acc C x
→ MethodIndArg C x
elimIndArg (var _) x a = elim-wf x a
elimIndArg (π ia S C) x a = fun< ia > (λ s → elimIndArg C (app< ia > x s) (a s))
elimIndArg (A ⊗ B) (xa , xb) (aa , ab)
= elimIndArg A xa aa
, elimIndArg B xb ab
elimCon
: (C : ConDesc P V I)
{mk : ∀ {i} → ⟦ C ⟧Con A′ (p , v , i) → ⟦ D ⟧Data A′ (p , i)}
(mot : MethodCon C (λ x → Pr′ (constr (mk x))))
(x : ⟦ C ⟧Con A′ (p , v , i))
→ AllConω Acc C x
→ Pr′ (constr (mk x))
elimCon (var _) mot refl a = mot
elimCon (π ia _ C) mot (s , x) a = elimCon C (app< ia > mot s) x a
elimCon (A ⊗ B) mot (xa , xb) (aa , ab)
= elimCon B (mot (elimIndArg A xa aa)) xb ab
elim′ : (x : A′ (p , i)) → Pr′ x
elim′ x = elim-wf x (wf x)
deriveElim : Arrows Methods (Pred′ I λ i → (x : A′ (p , i)) → Pr′ x)
deriveElim = curryₙ (λ m → pred′ I _ λ i → elim′ m)
elim : ∀ ⦃ H : HasDesc A ⦄ (open HasDesc H) {p c} (Pr : Pred′ I (λ i → A′ (p , i) → Set c))
→ Arrows (Methods H Pr) (Pred′ I λ i → (x : A′ (p , i)) → Pr′ H Pr x)
elim ⦃ H ⦄ Pr = deriveElim H Pr
| {
"alphanum_fraction": 0.4997147747,
"avg_line_length": 32.462962963,
"ext": "agda",
"hexsha": "ffb28275b924e7139f21be340676e4528e2a3638",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z",
"max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "flupe/generics",
"max_forks_repo_path": "src/Generics/Constructions/Elim.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "flupe/generics",
"max_issues_repo_path": "src/Generics/Constructions/Elim.agda",
"max_line_length": 91,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "flupe/generics",
"max_stars_repo_path": "src/Generics/Constructions/Elim.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z",
"num_tokens": 1318,
"size": 3506
} |
open import Theory
module Categories.Functor.Construction.Inclusion {ℓ₁ ℓ₂ ℓ₃} (Th : Theory ℓ₁ ℓ₂ ℓ₃) where
open import Syntax
open Theory.Theory Th
open Signature Sg
open Term Sg
open import Categories.Category.Construction.Renaming Sg as Renaming using (Ren; ren; _≐_)
open import Categories.Category.Construction.Classifying Th using (Cl; CC)
open import Categories.Functor
open import Categories.Category
open import Categories.Morphism Cl using (_≅_; Iso)
open import Categories.Category.CartesianClosed Cl
open import Categories.Category.Cartesian Cl
open import Categories.Category.BinaryProducts Cl
open import Data.List using (List; []; _∷_; _++_)
import Relation.Binary.Reasoning.Setoid as Reasoning
module TermReasoning {Γ A} = Reasoning (TermSetoid {Γ} {A})
inclusion : Functor Ren Cl
inclusion = record
{ F₀ = F₀
; F₁ = F₁
; identity = C.Equiv.refl
; homomorphism = λ {Γ₁} {Γ₂} {Γ₃} {f} {g} -> homomorphism f g
; F-resp-≈ = F-resp-≈
}
where
module C = Category Cl
open CartesianClosed CC
open Cartesian cartesian
open BinaryProducts products
open import Categories.Morphism.Reasoning Cl
id⁂id : forall {A B} -> C.id ⁂ C.id C.≈ C.id {A = A * B}
id⁂id = trans (⟨⟩-cong₂ C.identityˡ C.identityˡ) η
F₀ : Context -> Type
F₀ [] = Unit
F₀ (A ∷ Γ) = F₀ Γ * A
F₀/*⇒++ : forall {Γ Δ} -> F₀ Γ * F₀ Δ C.⇒ F₀ (Δ ++ Γ)
F₀/*⇒++ {Γ} {[]} = fst var
F₀/*⇒++ {Γ} {A ∷ Δ} = (F₀/*⇒++ ⁂ C.id) C.∘ assocʳ
F₀/++⇒* : forall {Γ Δ} -> F₀ (Δ ++ Γ) C.⇒ F₀ Γ * F₀ Δ
F₀/++⇒* {Γ} {[]} = pair var unit
F₀/++⇒* {Γ} {A ∷ Δ} = assocˡ C.∘ (F₀/++⇒* ⁂ C.id)
F₀/*≅++ : forall {Γ Δ} -> F₀ Γ * F₀ Δ ≅ F₀ (Δ ++ Γ)
F₀/*≅++ = record
{ from = F₀/*⇒++
; to = F₀/++⇒*
; iso = record { isoˡ = isoˡ ; isoʳ = isoʳ }
}
where
isoˡ : forall {Γ Δ} -> F₀/++⇒* C.∘ F₀/*⇒++ C.≈ C.id {A = F₀ Γ * F₀ Δ}
isoˡ {Γ} {[]} =
begin
pair var unit [ ext ! (fst var) ]
≈⟨ trans comm/pair (cong/pair (var/ext _ _) (comm/unit _ _ _)) ⟩
pair (fst var) unit
≈⟨ cong/pair refl (eta/Unit _) ⟩
pair (fst var) (snd var)
≈⟨ eta/* _ ⟩
var
∎
where open TermReasoning
isoˡ {Γ} {A ∷ Δ} =
begin
(assocˡ C.∘ (F₀/++⇒* ⁂ var)) C.∘ ((F₀/*⇒++ ⁂ var) C.∘ assocʳ)
≈⟨ C.assoc ⟩
assocˡ C.∘ (F₀/++⇒* ⁂ var) C.∘ (F₀/*⇒++ ⁂ var) C.∘ assocʳ
≈⟨ C.∘-resp-≈ʳ (pullˡ ⁂∘⁂) ⟩
assocˡ C.∘ (F₀/++⇒* C.∘ F₀/*⇒++ ⁂ var C.∘ var) C.∘ assocʳ
≈⟨ C.∘-resp-≈ʳ (C.∘-resp-≈ˡ (⁂-cong₂ isoˡ C.identity²)) ⟩
assocˡ C.∘ (var ⁂ var) C.∘ assocʳ
≈⟨ elim-center id⁂id ⟩
assocˡ C.∘ assocʳ
≈⟨ assocˡ∘assocʳ ⟩
var
∎
where open TermReasoning
isoʳ : forall {Γ Δ} -> F₀/*⇒++ C.∘ F₀/++⇒* {Γ = Γ} C.≈ C.id {A = F₀ (Δ ++ Γ)}
isoʳ {Γ} {[]} = trans comm/fst (trans (cong/fst (var/ext _ _)) (beta/*₁ _ _))
isoʳ {Γ} {A ∷ Δ} =
begin
((F₀/*⇒++ ⁂ var) C.∘ assocʳ) C.∘ (assocˡ C.∘ (F₀/++⇒* ⁂ var))
≈⟨ cancelInner assocʳ∘assocˡ ⟩
(F₀/*⇒++ ⁂ var) C.∘ (F₀/++⇒* ⁂ var)
≈⟨ ⁂∘⁂ ⟩
F₀/*⇒++ C.∘ F₀/++⇒* ⁂ var C.∘ var
≈⟨ ⁂-cong₂ isoʳ C.identity² ⟩
var ⁂ var
≈⟨ id⁂id ⟩
var
∎
where open TermReasoning
F₁p : forall {Γ Δ} -> F₀ (Δ ++ Γ) ∷ [] ⊢ F₀ Γ
F₁p = fst var C.∘ F₀/++⇒*
F₁q : forall {Γ Δ} -> F₀ (Δ ++ Γ) ∷ [] ⊢ F₀ Δ
F₁q = snd var C.∘ F₀/++⇒*
F₁ : forall {Γ Δ : Context} -> ren Γ Δ -> F₀ Γ ∷ [] ⊢ F₀ Δ
F₁ Renaming.id = C.id
F₁ (r Renaming.∙ r₁) = F₁ r C.∘ F₁ r₁
F₁ Renaming.! = unit
F₁ Renaming.⟪ r , r₁ ⟫ = F₀/*⇒++ C.∘ pair (F₁ r) (F₁ r₁)
F₁ Renaming.p = F₁p
F₁ Renaming.q = F₁q
homomorphism : forall {Γ₁ Γ₂ Γ₃} (f : ren Γ₁ Γ₂) (g : ren Γ₂ Γ₃)
-> F₀ Γ₁ ∷ [] ⊢ F₁ g [ ext ! (F₁ f) ] ≡ F₁ g [ ext ! (F₁ f) ]
homomorphism f g = refl
F-resp-≈ : forall {Γ Δ} {f g : ren Γ Δ} -> f ≐ g -> F₀ Γ ∷ [] ⊢ F₁ f ≡ F₁ g
F-resp-≈ _≐_.refl = refl
F-resp-≈ (_≐_.sym x) = sym (F-resp-≈ x)
F-resp-≈ (_≐_.trans x x₁) = trans (F-resp-≈ x) (F-resp-≈ x₁)
F-resp-≈ _≐_.identityˡ = var/ext _ _
F-resp-≈ _≐_.identityʳ = trans (cong/sub (trans (cong/ext !-unique refl) η-pair) refl) sub/id
F-resp-≈ _≐_.assoc = C.assoc
F-resp-≈ _≐_.!-unique = eta/Unit _
F-resp-≈ _≐_.β₁/⟪⟫ = trans (cancelInner (Iso.isoˡ (_≅_.iso F₀/*≅++))) project₁
F-resp-≈ _≐_.β₂/⟪⟫ = trans (cancelInner (Iso.isoˡ (_≅_.iso F₀/*≅++))) project₂
F-resp-≈ _≐_.η/⟪⟫ = trans (C.∘-resp-≈ʳ (trans (⟨⟩-cong₂ C.assoc C.assoc) g-η)) (cancelˡ (Iso.isoʳ (_≅_.iso F₀/*≅++)))
F-resp-≈ (_≐_.cong/∙ x x₁) = cong/sub (cong/ext refl (F-resp-≈ x₁)) (F-resp-≈ x)
F-resp-≈ (_≐_.cong/⟪⟫ x x₁) = cong/sub (cong/ext refl (cong/pair (F-resp-≈ x) (F-resp-≈ x₁))) refl
| {
"alphanum_fraction": 0.5001009489,
"avg_line_length": 36.1532846715,
"ext": "agda",
"hexsha": "06c383fde79daed4a15055a4fa9c8dc0c9daef5d",
"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": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "elpinal/exsub-ccc",
"max_forks_repo_path": "Categories/Functor/Construction/Inclusion.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"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": "elpinal/exsub-ccc",
"max_issues_repo_path": "Categories/Functor/Construction/Inclusion.agda",
"max_line_length": 121,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "elpinal/exsub-ccc",
"max_stars_repo_path": "Categories/Functor/Construction/Inclusion.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T13:30:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-05T06:16:32.000Z",
"num_tokens": 2275,
"size": 4953
} |
module Haskell.Prim.Double where
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
open import Agda.Builtin.Float public renaming (Float to Double)
open import Agda.Builtin.FromNat
open import Agda.Builtin.FromNeg
instance
iNumberDouble : Number Double
iNumberDouble .Number.Constraint _ = ⊤
iNumberDouble .fromNat n = primNatToFloat n
iNegativeDouble : Negative Double
iNegativeDouble .Negative.Constraint _ = ⊤
iNegativeDouble .fromNeg n = primFloatMinus 0.0 (fromNat n)
| {
"alphanum_fraction": 0.7931726908,
"avg_line_length": 27.6666666667,
"ext": "agda",
"hexsha": "e2898a67c1fbaf2c07d0cfb5306bd9a5b56de649",
"lang": "Agda",
"max_forks_count": 18,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:42:52.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-10-21T22:19:09.000Z",
"max_forks_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "seanpm2001/agda2hs",
"max_forks_repo_path": "lib/Haskell/Prim/Double.agda",
"max_issues_count": 63,
"max_issues_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_issues_repo_issues_event_max_datetime": "2022-02-25T15:47:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-10-22T05:19:27.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "seanpm2001/agda2hs",
"max_issues_repo_path": "lib/Haskell/Prim/Double.agda",
"max_line_length": 64,
"max_stars_count": 55,
"max_stars_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dxts/agda2hs",
"max_stars_repo_path": "lib/Haskell/Prim/Double.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-26T21:57:56.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-20T13:36:25.000Z",
"num_tokens": 135,
"size": 498
} |
module Structure.Numeral.Integer.Proofs where
open import Data.Either as Either using (Left ; Right)
import Data.Tuple as Tuple
open import Functional
open import Function.Proofs
open import Logic.IntroInstances
open import Logic.Predicate
open import Logic.Propositional
import Lvl
open import Structure.Function.Domain
open import Structure.Function
open import Structure.Numeral.Integer
open import Structure.Relator
open import Structure.Relator.Proofs
open import Structure.Relator.Properties
open import Structure.Setoid
open import Structure.Operator
open import Structure.Operator.Properties
open import Structure.Operator.Ring.Proofs
open import Structure.Operator.Ring
open import Structure.OrderedField
open import Syntax.Implication
open import Syntax.Transitivity
open import Type
private variable ℓₒ ℓₗ ℓₑ ℓₗ₁ ℓₗ₂ : Lvl.Level
private variable Z : Type{ℓₒ}
private variable _+_ _⋅_ : Z → Z → Z
private variable _≤_ : Z → Z → Type{ℓₗ}
module _ ⦃ equiv : Equiv{ℓₑ}(Z) ⦄ ⦃ int : Integer ⦃ equiv ⦄ (_+_)(_⋅_)(_≤_) ⦄ where
open Integer(int)
negative-induction : ∀{ℓ}{P : Z → Type{ℓ}} ⦃ rel-p : UnaryRelator(P) ⦄ → P(𝟎) → (∀{n} → (n ≤ 𝟎) → P(n) → P(𝐏(n))) → (∀{n} → (n ≤ 𝟎) → P(n))
negative-induction {P = P} pz ps {n} neg =
substitute₁(P) (involution(−_)) (positive-induction
{P = P ∘ (−_)}
⦃ [∘]-unaryRelator ⦄
(substitute₁ₗ(P) [−]-of-𝟎 pz)
(\{n} pos pnn → substitute₁ₗ(P) [+]-negation-distribution (ps{− n} ([↔]-to-[→] [≤]-flip-positive pos) pnn))
{− n}
([↔]-to-[→] [≤]-flip-negative neg)
)
induction : ∀{ℓ}{P : Z → Type{ℓ}} ⦃ rel-p : UnaryRelator(P) ⦄ → P(𝟎) → (∀{n} → (n ≤ 𝟎) → P(n) → P(𝐏(n))) → (∀{n} → (𝟎 ≤ n) → P(n) → P(𝐒(n))) → (∀{n} → P(n))
induction pz pp ps {n} with converseTotal(_≤_) {n}{𝟎}
... | Left neg = negative-induction pz pp neg
... | Right pos = positive-induction pz ps pos
[⋅]-commutativity : Commutativity(_⋅_)
[⋅]-commutativity = intro(induction{P = x ↦ ∀{y} → (x ⋅ y ≡ y ⋅ x)} ⦃ {!!} ⦄ base (const pred) (const succ)) where
base : ∀{y} → (𝟎 ⋅ y ≡ y ⋅ 𝟎)
base{y} =
𝟎 ⋅ y 🝖[ _≡_ ]-[ absorberₗ(_⋅_)(𝟎) ]
𝟎 🝖[ _≡_ ]-[ absorberᵣ(_⋅_)(𝟎) ]-sym
y ⋅ 𝟎 🝖-end
pred : ∀{x} → (∀{y} → (x ⋅ y ≡ y ⋅ x)) → (∀{y} → (𝐏(x) ⋅ y ≡ y ⋅ 𝐏(x)))
pred {x} p {y} =
𝐏(x) ⋅ y 🝖[ _≡_ ]-[]
(x − 𝟏) ⋅ y 🝖[ _≡_ ]-[ distributivityᵣ(_⋅_)(_−_) ⦃ [⋅][−]-distributivityᵣ ⦄ ]
(x ⋅ y) − (𝟏 ⋅ y) 🝖[ _≡_ ]-[ congruence₂ᵣ(_−_) ⦃ [−]-binaryOperator ⦄ (_) (identityₗ(_⋅_)(𝟏)) ]
(x ⋅ y) − y 🝖[ _≡_ ]-[ congruence₂ₗ(_−_) ⦃ [−]-binaryOperator ⦄ (_) p ]
(y ⋅ x) − y 🝖[ _≡_ ]-[ congruence₂ᵣ(_−_) ⦃ [−]-binaryOperator ⦄ (_) (identityᵣ(_⋅_)(𝟏)) ]-sym
(y ⋅ x) − (y ⋅ 𝟏) 🝖[ _≡_ ]-[ distributivityₗ(_⋅_)(_−_) ⦃ [⋅][−]-distributivityₗ ⦄ ]-sym
y ⋅ (x − 𝟏) 🝖[ _≡_ ]-[]
y ⋅ 𝐏(x) 🝖-end
succ : ∀{x} → (∀{y} → (x ⋅ y ≡ y ⋅ x)) → (∀{y} → (𝐒(x) ⋅ y ≡ y ⋅ 𝐒(x)))
succ {x} p {y} =
𝐒(x) ⋅ y 🝖[ _≡_ ]-[]
(x + 𝟏) ⋅ y 🝖[ _≡_ ]-[ distributivityᵣ(_⋅_)(_+_) ]
(x ⋅ y) + (𝟏 ⋅ y) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(_) (identityₗ(_⋅_)(𝟏)) ]
(x ⋅ y) + y 🝖[ _≡_ ]-[ congruence₂ₗ(_+_)(_) p ]
(y ⋅ x) + y 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(_) (identityᵣ(_⋅_)(𝟏)) ]-sym
(y ⋅ x) + (y ⋅ 𝟏) 🝖[ _≡_ ]-[ distributivityₗ(_⋅_)(_+_) ]-sym
y ⋅ (x + 𝟏) 🝖[ _≡_ ]-[]
y ⋅ 𝐒(x) 🝖-end
[≤]-identities : (𝟎 ≤ 𝟏)
[≤]-identities with converseTotal(_≤_) {𝟎}{− 𝟏}
... | Left omi =
omi ⇒
(𝟎 ≤ (− 𝟏)) ⇒-[ swap apply₂ [≤][⋅]-zero ]
(𝟎 ≤ ((− 𝟏) ⋅ (− 𝟏))) ⇒-[ _🝖 sub₂(_≡_)(_≤_) [⋅]-of-[−] ]
(𝟎 ≤ (𝟏 ⋅ 𝟏)) ⇒-[ _🝖 sub₂(_≡_)(_≤_) (identityₗ(_⋅_)(𝟏)) ]
(𝟎 ≤ 𝟏) ⇒-end
... | Right mio = [↔]-to-[←] [≤]-flip-positive mio
[<]-identities : (𝟎 < 𝟏)
[<]-identities = [≤][≢]-to-[<] [≤]-identities (NonZero.proof distinct-identities ∘ symmetry(_≡_))
𝐒-of-𝟎 : 𝐒(𝟎) ≡ 𝟏
𝐒-of-𝟎 =
𝐒(𝟎) 🝖[ _≡_ ]-[]
𝟎 + 𝟏 🝖[ _≡_ ]-[ identityₗ(_+_)(𝟎) ]
𝟏 🝖-end
instance
postulate 𝐒-function : Function(𝐒)
-- 𝐒-function = {!!}
instance
postulate [<]-relator : BinaryRelator(_<_)
-- [<]-relator = {![¬]-binaryRelator!}
[≤]-with-𝐒 : ∀{x y} → (x ≤ y) → (𝐒(x) ≤ 𝐒(y))
[≤]-with-𝐒 = [≤][+]ₗ-preserve
[<]-with-𝐒 : ∀{x y} → (x < y) → (𝐒(x) < 𝐒(y))
[<]-with-𝐒 = [<][+]-preserveₗ
[≤]-with-𝐏 : ∀{x y} → (x ≤ y) → (𝐏(x) ≤ 𝐏(y))
[≤]-with-𝐏 = [≤][−]ₗ-preserve
[<]-with-𝐏 : ∀{x y} → (x < y) → (𝐏(x) < 𝐏(y))
[<]-with-𝐏 = [<][+]-preserveₗ
𝐒-𝐏-inverse : ∀{x} → (𝐒(𝐏(x)) ≡ x)
𝐒-𝐏-inverse = associativity(_+_) 🝖 congruence₂ᵣ(_+_)(_) (inverseFunctionₗ(_+_)(−_)) 🝖 identityᵣ(_+_)(𝟎)
𝐏-𝐒-inverse : ∀{x} → (𝐏(𝐒(x)) ≡ x)
𝐏-𝐒-inverse = associativity(_+_) 🝖 congruence₂ᵣ(_+_)(_) (inverseFunctionᵣ(_+_)(−_)) 🝖 identityᵣ(_+_)(𝟎)
𝐒-order : ∀{x} → (x < 𝐒(x))
𝐒-order {x} = induction
{P = x ↦ x < 𝐒(x)}
⦃ binary-unaryRelator ⦃ rel-P = [∘]-binaryRelator ⦄ ⦄
(subtransitivityᵣ(_<_)(_≡_) [<]-identities (symmetry(_≡_) 𝐒-of-𝟎))
(const (p ↦ subtransitivityᵣ(_<_)(_≡_) ([<]-with-𝐏 p) (𝐏-𝐒-inverse 🝖 symmetry(_≡_) 𝐒-𝐏-inverse)))
(const [<]-with-𝐒)
𝐒-least-upper-bound : ∀{x m} → (x < m) → (𝐒(x) ≤ m)
𝐒-least-upper-bound {x}{m} xm with converseTotal(_≤_) {x}{m} | converseTotal(_≤_) {𝐒(x)}{m}
... | Left x₁ | Left x₂ = x₂
... | Left x₁ | Right x₂ = {!!} -- x<m x≤m m≤𝐒x
... | Right x₁ | Left x₂ = x₂
... | Right x₁ | Right x₂ with () ← xm x₁
{-... | Left 𝐒xm = {!!}
... | Right ¬m𝐒x = {!!}
-}
{-=
𝐒(x) 🝖[ _≤_ ]-[ {!!} ]
m 🝖-end-}
least-upper-bound-existence : ∃{Obj = Z → Z}(S ↦ (∀{x} → (x < S(x))) ∧ (∀{x m} → (x < m) → (S(x) ≤ m)))
∃.witness least-upper-bound-existence = 𝐒
Tuple.left (∃.proof least-upper-bound-existence) = 𝐒-order
Tuple.right (∃.proof least-upper-bound-existence) = 𝐒-least-upper-bound
{- TODO: Not here. Needs invertible mult
record Exponentiation(_^_ : Z → Z → Z) : Type{ℓₑ Lvl.⊔ Lvl.of(Z) Lvl.⊔ Lvl.of(𝟎 ≤ 𝟎)} where
field
base : ∀{a} → (a ^ 𝟎 ≡ 𝟏)
step : ∀{a b} → (𝟎 ≤ b) → (a ^ (b + 𝟏) ≡ a ⋅ (a ^ b))
neg : ∀{a b} → (𝟎 ≤ 𝟎) → (a ^ (− b) ≡ ⅟(a ^ b))
-}
| {
"alphanum_fraction": 0.5004045962,
"avg_line_length": 38.8616352201,
"ext": "agda",
"hexsha": "5ce38b3b54a3fdab53172e75048667dd86ade902",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Numeral/Integer/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Numeral/Integer/Proofs.agda",
"max_line_length": 158,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Numeral/Integer/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 3122,
"size": 6179
} |
{-# OPTIONS --without-K --safe #-}
module Data.Sum where
open import Level
open import Data.Bool.Base using (Bool; true; false)
open import Function using (const)
data _⊎_ (A : Type a) (B : Type b) : Type (a ℓ⊔ b) where
inl : A → A ⊎ B
inr : B → A ⊎ B
either : ∀ {ℓ} {C : A ⊎ B → Type ℓ} → ((a : A) → C (inl a)) → ((b : B) → C (inr b))
→ (x : A ⊎ B) → C x
either f _ (inl x) = f x
either _ g (inr y) = g y
⟦l_,r_⟧ = either
either′ : (A → C) → (B → C) → (A ⊎ B) → C
either′ = either
_▿_ : (A → C) → (B → C) → A ⊎ B → C
_▿_ = either
is-l : A ⊎ B → Bool
is-l = either′ (const true) (const false)
map-⊎ : ∀ {a₁ a₂ b₁ b₂} {A₁ : Type a₁} {A₂ : Type a₂} {B₁ : Type b₁} {B₂ : Type b₂} →
(A₁ → A₂) →
(B₁ → B₂) →
(A₁ ⊎ B₁) →
(A₂ ⊎ B₂)
map-⊎ f g (inl x) = inl (f x)
map-⊎ f g (inr x) = inr (g x)
mapˡ : (A → B) → A ⊎ C → B ⊎ C
mapˡ f (inl x) = inl (f x)
mapˡ f (inr x) = inr x
mapʳ : (A → B) → C ⊎ A → C ⊎ B
mapʳ f (inl x) = inl x
mapʳ f (inr x) = inr (f x)
| {
"alphanum_fraction": 0.4763819095,
"avg_line_length": 22.6136363636,
"ext": "agda",
"hexsha": "c70ad26fc5e4368cdcbfb336b06d92ecb6f3ce77",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/Sum.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/Sum.agda",
"max_line_length": 85,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/Sum.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": 497,
"size": 995
} |
-- Written by P. Hausmann
module Vec where
open import IO
open import Data.Vec
open import Data.Nat
open import Data.Nat.Show
open import Level using (0ℓ)
Matrix : Set -> ℕ -> ℕ -> Set
Matrix a n m = Vec (Vec a m) n
madd : {n m : ℕ} -> Matrix ℕ m n -> Matrix ℕ m n -> Matrix ℕ m n
madd a b = map (λ x → \y -> map _+_ x ⊛ y) a ⊛ b
idMatrix : {n : ℕ} -> Matrix ℕ n n
idMatrix {zero} = []
idMatrix {suc n} = (1 ∷ (replicate zero)) ∷ (map (λ x → zero ∷ x) idMatrix)
transposeM : {n m : ℕ} {a : Set} -> Matrix a m n -> Matrix a n m
transposeM {zero} {zero} a₁ = []
transposeM {zero} {suc m} {a} x = []
transposeM {suc n} {zero} a₁ = replicate []
transposeM {suc n} {suc m} {a} (_∷_ x₁ x₂) with map head (x₁ ∷ x₂)
... | vm = vm ∷ (map _∷_ (tail x₁) ⊛ transposeM (map tail x₂))
-- We use quite small numbers right now, as with big number the computation
-- gets very slow (at least in MAlonzo)
-- correct result : 109
compute : ℕ
compute = sum (map sum g)
where m : Matrix ℕ 3 3
m = (3 ∷ 5 ∷ 9 ∷ []) ∷
(12 ∷ 0 ∷ 7 ∷ []) ∷ (11 ∷ 2 ∷ 4 ∷ []) ∷ []
g : Matrix ℕ 3 3
g = madd (transposeM (transposeM m)) (transposeM (madd m idMatrix))
main = run {0ℓ} (putStrLn (show compute))
| {
"alphanum_fraction": 0.5800330033,
"avg_line_length": 31.0769230769,
"ext": "agda",
"hexsha": "ae8987dab2172f13b69c840394e9f31ba70221b1",
"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": "cb645fcad38f76a9bf37507583867595b5ce87a1",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "guilhermehas/agda",
"max_forks_repo_path": "test/Compiler/with-stdlib/Vec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cb645fcad38f76a9bf37507583867595b5ce87a1",
"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": "guilhermehas/agda",
"max_issues_repo_path": "test/Compiler/with-stdlib/Vec.agda",
"max_line_length": 75,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cb645fcad38f76a9bf37507583867595b5ce87a1",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "guilhermehas/agda",
"max_stars_repo_path": "test/Compiler/with-stdlib/Vec.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 461,
"size": 1212
} |
open import Oscar.Prelude
open import Oscar.Class.IsCategory
open import Oscar.Class.Reflexivity
open import Oscar.Class.Transitivity
module Oscar.Class.Category where
record Category 𝔬 𝔯 ℓ : Ø ↑̂ (𝔬 ∙̂ 𝔯 ∙̂ ℓ) where
constructor ∁
infix 4 _∼̇_
field
{𝔒} : Ø 𝔬
_∼_ : 𝔒 → 𝔒 → Ø 𝔯
_∼̇_ : ∀ {x y} → x ∼ y → x ∼ y → Ø ℓ
category-ε : Reflexivity.type _∼_
_↦_ : Transitivity.type _∼_
⦃ `IsCategory ⦄ : IsCategory _∼_ _∼̇_ category-ε _↦_
| {
"alphanum_fraction": 0.6349892009,
"avg_line_length": 24.3684210526,
"ext": "agda",
"hexsha": "a06e703a482369f8742009f95337fe517209cb14",
"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-3/src/Oscar/Class/Category.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-3/src/Oscar/Class/Category.agda",
"max_line_length": 56,
"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-3/src/Oscar/Class/Category.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 202,
"size": 463
} |
open import Common.Prelude
open import Common.Reflection
module TermSplicingLooping where
mutual
f : Set -> Set
f = unquote (give (def (quote f) []))
-- Expected error:
--
-- Termination checking failed for the following functions:
-- f
-- Problematic calls:
-- f
| {
"alphanum_fraction": 0.7018181818,
"avg_line_length": 17.1875,
"ext": "agda",
"hexsha": "3b65e5f4fe590ca61506e6e2a28ef2ac0b708601",
"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/TermSplicingLooping.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/TermSplicingLooping.agda",
"max_line_length": 59,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/TermSplicingLooping.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": 72,
"size": 275
} |
module _ where
open import Common.Prelude renaming (_∸_ to _-_) -- work-around for #1855
_<_ : Nat → Nat → Bool
a < b with b - a
... | zero = false
... | suc _ = true
insert : Nat → List Nat → List Nat
insert x [] = x ∷ []
insert x (y ∷ xs) = if x < y then x ∷ y ∷ xs else (y ∷ insert x xs)
sort : List Nat → List Nat
sort [] = []
sort (x ∷ xs) = insert x (sort xs)
downFrom : Nat → List Nat
downFrom zero = []
downFrom (suc n) = n ∷ downFrom n
mapM! : {A : Set} → (A → IO Unit) → List A → IO Unit
mapM! f [] = return unit
mapM! f (x ∷ xs) = f x >>= λ _ → mapM! f xs
main : IO Unit
main = mapM! printNat (sort (downFrom 1200))
-- 1000 0.6s
-- 2000 4.8s
-- 4000 36.2s
| {
"alphanum_fraction": 0.5680819912,
"avg_line_length": 20.696969697,
"ext": "agda",
"hexsha": "3e78f03a129675265809bb5c038f3718017af2ae",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Compiler/simple/Sort.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Compiler/simple/Sort.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/Compiler/simple/Sort.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": 269,
"size": 683
} |
{-# OPTIONS --cubical --no-import-sorts #-}
module Number.Definitions where
open import Agda.Primitive renaming (_⊔_ to ℓ-max; lsuc to ℓ-suc; lzero to ℓ-zero)
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Foundations.Logic
open import Utils
open import MoreLogic.Definitions
open import MoreLogic.Properties
open import MorePropAlgebra.Definitions
open import MorePropAlgebra.Consequences
open import MorePropAlgebra.Structures
| {
"alphanum_fraction": 0.8098159509,
"avg_line_length": 32.6,
"ext": "agda",
"hexsha": "90495f0e85f358ef356a2d88ab1f2e5747a0cb2b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "agda/Number/Definitions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mchristianl/synthetic-reals",
"max_issues_repo_path": "agda/Number/Definitions.agda",
"max_line_length": 83,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "agda/Number/Definitions.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 137,
"size": 489
} |
open import Agda.Primitive
open import Empty
open import Logic
open import Boolean
module Peano where
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
pred : ℕ → ℕ
pred zero = zero
pred (succ x) = x
_+_ : ℕ → ℕ → ℕ
zero + m = m
(succ n) + m = succ (n + m)
{-# BUILTIN NATPLUS _+_ #-}
_∘_ : ℕ → ℕ → ℕ
zero ∘ _ = zero
(succ n) ∘ m = (n ∘ m) + m
{-# BUILTIN NATTIMES _∘_ #-}
data _≡_ (x : ℕ) : ℕ → Set where
refl : x ≡ x
data _≢_ : ℕ → ℕ → Set where
z≢s : ∀ {n} → zero ≢ succ n
s≢z : ∀ {n} → succ n ≢ zero
s≢s : ∀ {m n} → m ≢ n → succ m ≢ succ n
data Equal? (m n : ℕ) : Set where
yes : m ≡ n → Equal? m n
no : m ≢ n → Equal? m n
_≟_ : (m n : ℕ) → Equal? m n
_≟_ zero zero = yes refl
_≟_ zero (succ _) = no z≢s
_≟_ (succ _) zero = no s≢z
_≟_ (succ m) (succ n) with m ≟ n
_≟_ (succ m) (succ .m) | yes refl = yes refl
_≟_ (succ m) (succ n) | no p = no (s≢s p)
equality-disjoint : (m n : ℕ) → m ≡ n → m ≢ n → ⊥
equality-disjoint zero zero refl ()
equality-disjoint zero (succ _) () z≢s
equality-disjoint (succ _) zero () s≢z
equality-disjoint (succ m) (succ .m) refl (s≢s e) = equality-disjoint m m refl e
private
-- to make the last `equality-disjoint` match clearer, verify that s≢s can be nested
test-s≢s : (succ (succ (succ zero))) ≢ (succ (succ zero))
test-s≢s = s≢s (s≢s s≢z)
data Ordering : Rel ℕ where
less : ∀ m k → Ordering m (succ (m + k))
equal : ∀ m → Ordering m m
greater : ∀ m k → Ordering (succ (m + k)) m
compare : ∀ m n → Ordering m n
compare zero zero = equal zero
compare (succ m) zero = greater zero m
compare zero (succ n) = less zero n
compare (succ m) (succ n) with compare m n
compare (succ .m) (succ .(succ m + k)) | less m k = less (succ m) k
compare (succ .m) (succ .m) | equal m = equal (succ m)
compare (succ .(succ m + k)) (succ .m) | greater m k = greater (succ m) k
infix 4 _≤_ _<_ _≥_ _>_ _≰_ _≮_ _≱_ _≯_
data _≤_ : Rel ℕ where
z≤n : ∀ {n} → zero ≤ n
s≤s : ∀ {m n} (m≤n : m ≤ n) → succ m ≤ succ n
_<_ : Rel ℕ
m < n = succ m ≤ n
_≥_ : Rel ℕ
m ≥ n = n ≤ m
_>_ : Rel ℕ
m > n = n < m
_≰_ : Rel ℕ
a ≰ b = ¬ (a ≤ b)
_≮_ : Rel ℕ
a ≮ b = ¬ (a < b)
_≱_ : Rel ℕ
a ≱ b = ¬ (a ≥ b)
_≯_ : Rel ℕ
a ≯ b = ¬ (a > b)
data _even : ℕ → Set where
ZERO : zero even
STEP : ∀ {x} → x even → succ (succ x) even
private
proof₁ : succ(succ(succ(succ(zero)))) even
proof₁ = STEP (STEP ZERO)
proof₂ : (A : Set) → A → A
proof₂ _ ν = ν
proof'₂ : ℕ → ℕ
proof'₂ = proof₂ ℕ
| {
"alphanum_fraction": 0.5209923664,
"avg_line_length": 23.3928571429,
"ext": "agda",
"hexsha": "9a174ec33f5122919f13f19a20dbc1fb28b72659",
"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": "382fcfae193079783621fc5cf54b6588e22ef759",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "cantsin/agda-experiments",
"max_forks_repo_path": "Peano.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "382fcfae193079783621fc5cf54b6588e22ef759",
"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": "cantsin/agda-experiments",
"max_issues_repo_path": "Peano.agda",
"max_line_length": 88,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "382fcfae193079783621fc5cf54b6588e22ef759",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "cantsin/agda-experiments",
"max_stars_repo_path": "Peano.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1100,
"size": 2620
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import cw.CW
module cw.examples.Empty where
cw-empty-skel : Skeleton {lzero} 0
cw-empty-skel = Empty , Empty-is-set
CWEmpty = ⟦ cw-empty-skel ⟧
CWEmpty-equiv-Empty : CWEmpty ≃ Empty
CWEmpty-equiv-Empty = ide _
| {
"alphanum_fraction": 0.7111913357,
"avg_line_length": 18.4666666667,
"ext": "agda",
"hexsha": "979c70fe24a0340852c9a55de721961a66bc6814",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/examples/Empty.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/examples/Empty.agda",
"max_line_length": 39,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/examples/Empty.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 82,
"size": 277
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Category.Construction.Pullbacks {o ℓ e} (C : Category o ℓ e) where
open import Level using (_⊔_)
open import Function using (_$_)
open import Data.Product using (_×_; _,_)
open import Categories.Diagram.Pullback C
open import Categories.Morphism.Reasoning C
open Category C
record PullbackObj W : Set (o ⊔ ℓ ⊔ e) where
field
{A} {B} : Obj
arr₁ : A ⇒ W
arr₂ : B ⇒ W
pullback : Pullback arr₁ arr₂
module pullback = Pullback pullback
open HomReasoning
record Pullback⇒ W (X Y : PullbackObj W) : Set (o ⊔ ℓ ⊔ e) where
module X = PullbackObj X
module Y = PullbackObj Y
field
mor₁ : X.A ⇒ Y.A
mor₂ : X.B ⇒ Y.B
commute₁ : Y.arr₁ ∘ mor₁ ≈ X.arr₁
commute₂ : Y.arr₂ ∘ mor₂ ≈ X.arr₂
pbarr : X.pullback.P ⇒ Y.pullback.P
pbarr = Y.pullback.universal $ begin
Y.arr₁ ∘ mor₁ ∘ X.pullback.p₁ ≈⟨ pullˡ commute₁ ⟩
X.arr₁ ∘ X.pullback.p₁ ≈⟨ X.pullback.commute ⟩
X.arr₂ ∘ X.pullback.p₂ ≈˘⟨ pullˡ commute₂ ⟩
Y.arr₂ ∘ mor₂ ∘ X.pullback.p₂ ∎
open Pullback⇒
Pullbacks : Obj → Category (o ⊔ ℓ ⊔ e) (o ⊔ ℓ ⊔ e) e
Pullbacks W = record
{ Obj = PullbackObj W
; _⇒_ = Pullback⇒ W
; _≈_ = λ f g → mor₁ f ≈ mor₁ g × mor₂ f ≈ mor₂ g
; id = record
{ mor₁ = id
; mor₂ = id
; commute₁ = identityʳ
; commute₂ = identityʳ
}
; _∘_ = λ f g → record
{ mor₁ = mor₁ f ∘ mor₁ g
; mor₂ = mor₂ f ∘ mor₂ g
; commute₁ = pullˡ (commute₁ f) ○ commute₁ g
; commute₂ = pullˡ (commute₂ f) ○ commute₂ g
}
; assoc = assoc , assoc
; sym-assoc = sym-assoc , sym-assoc
; identityˡ = identityˡ , identityˡ
; identityʳ = identityʳ , identityʳ
; identity² = identity² , identity²
; equiv = record
{ refl = refl , refl
; sym = λ { (eq₁ , eq₂) → sym eq₁ , sym eq₂ }
; trans = λ { (eq₁ , eq₂) (eq₃ , eq₄) → trans eq₁ eq₃ , trans eq₂ eq₄ }
}
; ∘-resp-≈ = λ { (eq₁ , eq₂) (eq₃ , eq₄) → ∘-resp-≈ eq₁ eq₃ , ∘-resp-≈ eq₂ eq₄ }
}
| {
"alphanum_fraction": 0.5789473684,
"avg_line_length": 28.2432432432,
"ext": "agda",
"hexsha": "aa727264e4c62bca40909ca06589b4a6901d9cf0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Construction/Pullbacks.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Construction/Pullbacks.agda",
"max_line_length": 84,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Construction/Pullbacks.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 816,
"size": 2090
} |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.GradedRing.Instances.PolynomialsFun where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Nat hiding (_·_) renaming (_+_ to _+n_)
open import Cubical.Data.Nat.Order
open import Cubical.Data.Sigma
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Ring
open import Cubical.Algebra.GradedRing.Base
open import Cubical.Algebra.GradedRing.DirectSumFun
private variable
ℓ : Level
module _
(ARing@(A , Astr) : Ring ℓ)
(n : ℕ)
where
open RingStr Astr
open RingTheory ARing
PolyGradedRing : GradedRing ℓ-zero ℓ
PolyGradedRing = ⊕Fun-GradedRing
_+n_ (makeIsMonoid isSetℕ +-assoc +-zero λ _ → refl) (λ _ _ → refl)
(λ _ → A)
(λ _ → snd (Ring→AbGroup ARing))
1r _·_ 0LeftAnnihilates 0RightAnnihilates
(λ a b c → ΣPathP ((+-assoc _ _ _) , (·Assoc _ _ _)))
(λ a → ΣPathP ((+-zero _) , (·IdR _)))
(λ a → ΣPathP (refl , (·IdL _)))
·DistR+
·DistL+
| {
"alphanum_fraction": 0.6142001711,
"avg_line_length": 30.7631578947,
"ext": "agda",
"hexsha": "8d79fe1b53b0a15df4a95a9c3527076e01a57375",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/GradedRing/Instances/PolynomialsFun.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/GradedRing/Instances/PolynomialsFun.agda",
"max_line_length": 86,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/GradedRing/Instances/PolynomialsFun.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 349,
"size": 1169
} |
postulate
List : Set
List-like : Set → Set
instance
postulate
List-is-list-like : List-like List
postulate
to-List : ∀ {F : Set} ⦃ list-like : ∀ {X : Set} → List-like F ⦄ → F → List
F : Set
f : ⦃ list-like : List-like F ⦄ → List
f = to-List _
| {
"alphanum_fraction": 0.5588235294,
"avg_line_length": 17,
"ext": "agda",
"hexsha": "6063c25b2ec5dc6397db796bf14b36e6d2322207",
"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/Issue4071.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/Issue4071.agda",
"max_line_length": 76,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue4071.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": 101,
"size": 272
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommRingSolver.Utility where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Bool
open import Cubical.Data.Empty using (⊥) renaming (rec to recEmpty)
open import Cubical.Data.Sigma
open import Cubical.Relation.Nullary.Base
private
variable
ℓ ℓ' : Level
byBoolAbsurdity : {Anything : Type ℓ} → false ≡ true → Anything
byBoolAbsurdity p = recEmpty (false≢true p)
byAbsurdity : {Anything : Type ℓ} → ⊥ → Anything
byAbsurdity x = recEmpty x
extractFromAnd : (P Q : Bool)
→ P and Q ≡ true
→ (P ≡ true) × (Q ≡ true)
extractFromAnd false false eq = byBoolAbsurdity eq
extractFromAnd false true eq = byBoolAbsurdity eq
extractFromAnd true false eq = byBoolAbsurdity eq
extractFromAnd true true eq = eq , eq
extractFromAndLeft : {P Q : Bool}
→ P and Q ≡ true
→ P ≡ true
extractFromAndLeft eq = fst (extractFromAnd _ _ eq)
extractFromAndRight : {P Q : Bool}
→ P and Q ≡ true
→ Q ≡ true
extractFromAndRight eq = snd (extractFromAnd _ _ eq)
| {
"alphanum_fraction": 0.6804788214,
"avg_line_length": 28.5789473684,
"ext": "agda",
"hexsha": "76878e38e26bf1686d9ad8ca96dab8495c405409",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommRingSolver/Utility.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommRingSolver/Utility.agda",
"max_line_length": 67,
"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/Algebra/CommRingSolver/Utility.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": 320,
"size": 1086
} |
{-
This file contains:
- Homotopy natural equivalences of pushout spans
Written by: Loïc Pujet, September 2019
- 3×3 lemma for pushouts
Written by: Loïc Pujet, April 2019
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.Pushout.Properties where
open import Cubical.Core.Glue
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HAEquiv
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Data.Prod.Base
open import Cubical.Data.Unit
open import Cubical.HITs.Pushout.Base
{-
Definition of pushout diagrams
-}
record 3-span : Type₁ where
field
A0 A2 A4 : Type₀
f1 : A2 → A0
f3 : A2 → A4
spanPushout : (s : 3-span) → Type₀
spanPushout s = Pushout (3-span.f1 s) (3-span.f3 s)
{-
Definition of a homotopy natural diagram equivalence
-}
record 3-span-equiv (s1 : 3-span) (s2 : 3-span) : Type₀ where
field
e0 : 3-span.A0 s1 ≃ 3-span.A0 s2
e2 : 3-span.A2 s1 ≃ 3-span.A2 s2
e4 : 3-span.A4 s1 ≃ 3-span.A4 s2
H1 : ∀ x → 3-span.f1 s2 (e2 .fst x) ≡ e0 .fst (3-span.f1 s1 x)
H3 : ∀ x → 3-span.f3 s2 (e2 .fst x) ≡ e4 .fst (3-span.f3 s1 x)
{-
Proof that homotopy equivalent spans are in fact equal
-}
spanEquivToPath : {s1 : 3-span} → {s2 : 3-span} → (e : 3-span-equiv s1 s2) → s1 ≡ s2
spanEquivToPath {s1} {s2} e = spanPath
where
open 3-span-equiv e
open 3-span
path0 : A0 s1 ≡ A0 s2
path0 = ua e0
path2 : A2 s1 ≡ A2 s2
path2 = ua e2
path4 : A4 s1 ≡ A4 s2
path4 = ua e4
spanPath1 : I → 3-span
spanPath1 i = record { A0 = path0 i ; A2 = path2 i ; A4 = path4 i ;
f1 = λ x → (transp (λ j → path0 (i ∧ j)) (~ i) (f1 s1 (transp (λ j → path2 (~ j ∧ i)) (~ i) x))) ;
f3 = λ x → (transp (λ j → path4 (i ∧ j)) (~ i) (f3 s1 (transp (λ j → path2 (~ j ∧ i)) (~ i) x))) }
spanPath2 : I → 3-span
spanPath2 i = record { A0 = A0 s2 ; A2 = A2 s2 ; A4 = A4 s2 ; f1 = f1Path i ; f3 = f3Path i }
where
f1Path : I → A2 s2 → A0 s2
f1Path i x = ((uaβ e0 (f1 s1 (transport (λ j → path2 (~ j)) x)))
∙ (H1 (transport (λ j → path2 (~ j)) x)) ⁻¹
∙ (λ j → f1 s2 (uaβ e2 (transport (λ j → path2 (~ j)) x) (~ j)))
∙ (λ j → f1 s2 (transportTransport⁻ path2 x j))) i
f3Path : I → A2 s2 → A4 s2
f3Path i x = ((uaβ e4 (f3 s1 (transport (λ j → path2 (~ j)) x)))
∙ (H3 (transport (λ j → path2 (~ j)) x)) ⁻¹
∙ (λ j → f3 s2 (uaβ e2 (transport (λ j → path2 (~ j)) x) (~ j)))
∙ (λ j → f3 s2 (transportTransport⁻ path2 x j))) i
spanPath : s1 ≡ s2
spanPath = (λ i → spanPath1 i) ∙ (λ i → spanPath2 i)
-- as a corollary, they have the same pushout
spanEquivToPushoutPath : {s1 : 3-span} → {s2 : 3-span} → (e : 3-span-equiv s1 s2)
→ spanPushout s1 ≡ spanPushout s2
spanEquivToPushoutPath {s1} {s2} e = cong spanPushout (spanEquivToPath e)
{-
3×3 lemma for pushouts
Let Aᵢⱼ denote a type, fᵢⱼ a map and Hᵢⱼ a homotopy. Given a diagram of the following shape:
A00 ←—f01—— A02 ——f03—→ A04
↑ ↑ ↑
f10 H11 f12 H13 f14
| | |
A20 ←—f21—— A22 ——f23—→ A24
| | |
f30 H31 f32 H33 f34
↓ ↓ ↓
A40 ←—f41—— A42 ——f43—→ A44
one can build its colimit from pushouts in two ways:
- either build pushouts A□0, A□2, A□4 of the lines and then build the pushout A□○ of the resulting
diagram A□0 ←—f□1—— A□2 ——f□3—→ A□4 ;
- or build pushouts of the columns and build the pushout A○□ of the resulting diagram A0□ ← A2□ → A4□.
Then the lemma states there is an equivalence A□○ ≃ A○□.
-}
record 3x3-span : Type₁ where
field
A00 A02 A04 A20 A22 A24 A40 A42 A44 : Type₀
f10 : A20 → A00
f12 : A22 → A02
f14 : A24 → A04
f30 : A20 → A40
f32 : A22 → A42
f34 : A24 → A44
f01 : A02 → A00
f21 : A22 → A20
f41 : A42 → A40
f03 : A02 → A04
f23 : A22 → A24
f43 : A42 → A44
H11 : ∀ x → f01 (f12 x) ≡ f10 (f21 x)
H13 : ∀ x → f03 (f12 x) ≡ f14 (f23 x)
H31 : ∀ x → f41 (f32 x) ≡ f30 (f21 x)
H33 : ∀ x → f43 (f32 x) ≡ f34 (f23 x)
-- pushouts of the lines
A□0 : Type₀
A□0 = Pushout f10 f30
A□2 : Type₀
A□2 = Pushout f12 f32
A□4 : Type₀
A□4 = Pushout f14 f34
-- maps between pushouts
f□1 : A□2 → A□0
f□1 (inl x) = inl (f01 x)
f□1 (inr x) = inr (f41 x)
f□1 (push a j) = ((λ i → inl (H11 a i))
∙∙ push (f21 a)
∙∙ (λ i → inr (H31 a (~ i)))) j
f□3 : A□2 → A□4
f□3 (inl x) = inl (f03 x)
f□3 (inr x) = inr (f43 x)
f□3 (push a j) = ((λ i → inl (H13 a i))
∙∙ push (f23 a)
∙∙ (λ i → inr (H33 a (~ i)))) j
-- total pushout
A□○ : Type₀
A□○ = Pushout f□1 f□3
-- pushouts of the columns
A0□ : Type₀
A0□ = Pushout f01 f03
A2□ : Type₀
A2□ = Pushout f21 f23
A4□ : Type₀
A4□ = Pushout f41 f43
-- maps between pushouts
f1□ : A2□ → A0□
f1□ (inl x) = inl (f10 x)
f1□ (inr x) = inr (f14 x)
f1□ (push a j) = ((λ i → inl (H11 a (~ i)))
∙∙ push (f12 a)
∙∙ (λ i → inr (H13 a i))) j
f3□ : A2□ → A4□
f3□ (inl x) = inl (f30 x)
f3□ (inr x) = inr (f34 x)
f3□ (push a j) = ((λ i → inl (H31 a (~ i)))
∙∙ push (f32 a)
∙∙ (λ i → inr (H33 a i))) j
-- total pushout
A○□ : Type₀
A○□ = Pushout f1□ f3□
-- the claimed result
3x3-lemma : A□○ ≡ A○□
3x3-lemma = isoToPath (iso A□○→A○□ A○□→A□○ A○□→A□○→A○□ A□○→A○□→A□○)
where
-- forward map of the equivalence A□○ ≃ A○□
forward-l : A□0 → A○□
forward-l (inl x) = inl (inl x)
forward-l (inr x) = inr (inl x)
forward-l (push a i) = push (inl a) i
forward-r : A□4 → A○□
forward-r (inl x) = inl (inr x)
forward-r (inr x) = inr (inr x)
forward-r (push a i) = push (inr a) i
forward-filler : A22 → I → I → I → A○□
forward-filler a i j = hfill (λ t → λ { (i = i0) → inl (doubleCompPath-filler (λ k → inl (H11 a (~ k))) (push (f12 a)) (λ k → inr (H13 a k)) j (~ t))
; (i = i1) → inr (doubleCompPath-filler (λ k → inl (H31 a (~ k))) (push (f32 a)) (λ k → inr (H33 a k)) j (~ t))
; (j = i0) → forward-l (doubleCompPath-filler (λ k → inl (H11 a k)) (push (f21 a)) (λ k → inr (H31 a (~ k))) i t)
; (j = i1) → forward-r (doubleCompPath-filler (λ k → inl (H13 a k)) (push (f23 a)) (λ k → inr (H33 a (~ k))) i t) })
(inS (push (push a j) i))
A□○→A○□ : A□○ → A○□
A□○→A○□ (inl x) = forward-l x
A□○→A○□ (inr x) = forward-r x
A□○→A○□ (push (inl x) i) = inl (push x i)
A□○→A○□ (push (inr x) i) = inr (push x i)
A□○→A○□ (push (push a i) j) = forward-filler a i j i1
-- backward map
backward-l : A0□ → A□○
backward-l (inl x) = inl (inl x)
backward-l (inr x) = inr (inl x)
backward-l (push a i) = push (inl a) i
backward-r : A4□ → A□○
backward-r (inl x) = inl (inr x)
backward-r (inr x) = inr (inr x)
backward-r (push a i) = push (inr a) i
backward-filler : A22 → I → I → I → A□○
backward-filler a i j = hfill (λ t → λ { (i = i0) → inl (doubleCompPath-filler (λ k → inl (H11 a k)) (push (f21 a)) (λ k → inr (H31 a (~ k))) j (~ t))
; (i = i1) → inr (doubleCompPath-filler (λ k → inl (H13 a k)) (push (f23 a)) (λ k → inr (H33 a (~ k))) j (~ t))
; (j = i0) → backward-l (doubleCompPath-filler (λ k → inl (H11 a (~ k))) (push (f12 a)) (λ k → inr (H13 a k)) i t)
; (j = i1) → backward-r (doubleCompPath-filler (λ k → inl (H31 a (~ k))) (push (f32 a)) (λ k → inr (H33 a k)) i t) })
(inS (push (push a j) i))
A○□→A□○ : A○□ → A□○
A○□→A□○ (inl x) = backward-l x
A○□→A□○ (inr x) = backward-r x
A○□→A□○ (push (inl x) i) = inl (push x i)
A○□→A□○ (push (inr x) i) = inr (push x i)
A○□→A□○ (push (push a i) j) = backward-filler a i j i1
-- first homotopy
homotopy1-l : ∀ x → A□○→A○□ (backward-l x) ≡ inl x
homotopy1-l (inl x) = refl
homotopy1-l (inr x) = refl
homotopy1-l (push a i) = refl
homotopy1-r : ∀ x → A□○→A○□ (backward-r x) ≡ inr x
homotopy1-r (inl x) = refl
homotopy1-r (inr x) = refl
homotopy1-r (push a i) = refl
A○□→A□○→A○□ : ∀ x → A□○→A○□ (A○□→A□○ x) ≡ x
A○□→A□○→A○□ (inl x) = homotopy1-l x
A○□→A□○→A○□ (inr x) = homotopy1-r x
A○□→A□○→A○□ (push (inl x) i) k = push (inl x) i
A○□→A□○→A○□ (push (inr x) i) k = push (inr x) i
A○□→A□○→A○□ (push (push a i) j) k =
hcomp (λ t → λ { (i = i0) → forward-l (doubleCompPath-filler (λ k → inl (H11 a k)) (push (f21 a)) (λ k → inr (H31 a (~ k))) j (~ t))
; (i = i1) → forward-r (doubleCompPath-filler (λ k → inl (H13 a k)) (push (f23 a)) (λ k → inr (H33 a (~ k))) j (~ t))
; (j = i0) → homotopy1-l (doubleCompPath-filler (λ k → inl (H11 a (~ k))) (push (f12 a)) (λ k → inr (H13 a k)) i t) k
; (j = i1) → homotopy1-r (doubleCompPath-filler (λ k → inl (H31 a (~ k))) (push (f32 a)) (λ k → inr (H33 a k)) i t) k
; (k = i0) → A□○→A○□ (backward-filler a i j t)
; (k = i1) → forward-filler a j i (~ t) })
(forward-filler a j i i1)
-- second homotopy
homotopy2-l : ∀ x → A○□→A□○ (forward-l x) ≡ inl x
homotopy2-l (inl x) = refl
homotopy2-l (inr x) = refl
homotopy2-l (push a i) = refl
homotopy2-r : ∀ x → A○□→A□○ (forward-r x) ≡ inr x
homotopy2-r (inl x) = refl
homotopy2-r (inr x) = refl
homotopy2-r (push a i) = refl
A□○→A○□→A□○ : ∀ x → A○□→A□○ (A□○→A○□ x) ≡ x
A□○→A○□→A□○ (inl x) = homotopy2-l x
A□○→A○□→A□○ (inr x) = homotopy2-r x
A□○→A○□→A□○ (push (inl x) i) k = push (inl x) i
A□○→A○□→A□○ (push (inr x) i) k = push (inr x) i
A□○→A○□→A□○ (push (push a i) j) k =
hcomp (λ t → λ { (i = i0) → backward-l (doubleCompPath-filler (λ k → inl (H11 a (~ k))) (push (f12 a)) (λ k → inr (H13 a k)) j (~ t))
; (i = i1) → backward-r (doubleCompPath-filler (λ k → inl (H31 a (~ k))) (push (f32 a)) (λ k → inr (H33 a k)) j (~ t))
; (j = i0) → homotopy2-l (doubleCompPath-filler (λ k → inl (H11 a k)) (push (f21 a)) (λ k → inr (H31 a (~ k))) i t) k
; (j = i1) → homotopy2-r (doubleCompPath-filler (λ k → inl (H13 a k)) (push (f23 a)) (λ k → inr (H33 a (~ k))) i t) k
; (k = i0) → A○□→A□○ (forward-filler a i j t)
; (k = i1) → backward-filler a j i (~ t) })
(backward-filler a j i i1)
| {
"alphanum_fraction": 0.4853759196,
"avg_line_length": 35.4968152866,
"ext": "agda",
"hexsha": "57100c5b6fe2e605dbe0d2031df93155b97cc16c",
"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/Pushout/Properties.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/Pushout/Properties.agda",
"max_line_length": 156,
"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/Pushout/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4934,
"size": 11146
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Convenient syntax for "equational reasoning" using a strict partial
-- order
------------------------------------------------------------------------
open import Relation.Binary
module Relation.Binary.StrictPartialOrderReasoning
{p₁ p₂ p₃} (S : StrictPartialOrder p₁ p₂ p₃) where
import Relation.Binary.PreorderReasoning as PreR
import Relation.Binary.Properties.StrictPartialOrder as SPO
open PreR (SPO.preorder S) public renaming (_∼⟨_⟩_ to _<⟨_⟩_)
| {
"alphanum_fraction": 0.5761821366,
"avg_line_length": 35.6875,
"ext": "agda",
"hexsha": "62a13eb6ebe14dfba782ae81cca9385b4b8902c1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Relation/Binary/StrictPartialOrderReasoning.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Relation/Binary/StrictPartialOrderReasoning.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Relation/Binary/StrictPartialOrderReasoning.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": 119,
"size": 571
} |
{-# OPTIONS --rewriting #-}
open import ExtractSac as ES using ()
open import Extract (ES.kompile-fun)
open import Data.Nat
open import Data.Nat.Properties
open import Data.List as L using (List; []; _∷_)
open import Data.Vec as V using (Vec; []; _∷_)
open import Data.Fin using (Fin; zero; suc; #_)
open import Relation.Binary.PropositionalEquality
open import Reflection
open import Structures
open import Function
{-# BUILTIN REWRITE _≡_ #-}
{-# REWRITE +-identityʳ #-}
test1-f : ℕ → ℕ
test1-f x = 1 + x
test₁ : kompile test1-f [] [] ≡ (ok $ "\n\n// Function Example-00.test1-f\n"
++ "int\n"
++ "Example_00_test1_f(int x_1) {\n"
++ "int __ret;\n"
++ "x = x_1;\n"
++ "__ret = (1 + x);\n"
++ "return __ret;\n"
++ "}\n\n")
test₁ = refl
test2-f : ℕ → ℕ
test2-f x = 0
test₂ : kompile test2-f [] [] ≡ (ok $ "\n\n// Function Example-00.test2-f\n"
++ "int\n"
++ "Example_00_test2_f(int x_1) {\n"
++ "int __ret;\n"
++ "x = x_1;\n"
++ "__ret = 0;\n"
++ "return __ret;\n"
++ "}\n\n")
test₂ = refl
-- Rewriting test
test3-f : ℕ → ℕ
test3-f x = x + 0
test₃ : kompile test3-f [] [] ≡ (ok $ "\n\n// Function Example-00.test3-f\n"
++ "int\n"
++ "Example_00_test3_f(int x_1) {\n"
++ "int __ret;\n"
++ "x = x_1;\n"
++ "__ret = x;\n"
++ "return __ret;\n"
++ "}\n\n")
test₃ = refl
-- Make sure that we can deal with functions inside
-- the type and properly collect them while extraction.
test-4h : ℕ → ℕ
test-4h x = 1 + x
test-4f : Fin (test-4h 3) → Fin 4
test-4f a = zero
test₄ : kompile test-4f (quote test-4h ∷ []) [] ≡ ok _
test₄ = refl
-- Test if we can deal with multiple patterns.
module _ where
test-5f : ℕ → ℕ
test-5f (suc (suc x)) = x
test-5f _ = 0
test₅ : kompile test-5f [] [] ≡ ok _
test₅ = refl
test-6f : Fin 5 → Fin 3
test-6f (suc (suc x)) = x
test-6f _ = zero
-- Make sure that we are compiling multi-argument function correctly
test-7f : (a b c : ℕ) → ℕ
test-7f a b c = c
test₇ : kompile test-7f [] [] ≡ (ok $ "\n\n// Function Example-00.test-7f\nint\nExample_00_test_7f(int x_1, int x_2, int x_3) {\n"
++ "int __ret;\na = x_1;\nb = x_2;\nc = x_3;\n__ret = c;\nreturn __ret;\n}\n\n")
test₇ = refl
-- With-clauses
test-8f : ℕ → ℕ
test-8f x with x
test-8f x | zero = 0
test-8f x | _ = 1
test₈ : kompile test-8f [] [] ≡ ok _
test₈ = refl
-- Testing lists
test-9f : List ℕ → List ℕ
test-9f [] = []
test-9f (x ∷ xs) = 1 + x ∷ test-9f xs
test₉ : kompile test-9f [] [] ≡ ok _
test₉ = refl
-- Test constraints accumulated from the list type.
module _ where
test-10f : (n : ℕ) → List (Fin n) → ℕ
test-10f n xs = 10
test₁₀ : kompile test-10f [] [] ≡ ok _
test₁₀ = refl
-- Higher-order functions are not allowed:
test-11f : ℕ → List (ℕ → ℕ)
test-11f n = []
test₁₁ : _≡_ {A = Prog} (kompile test-11f [] []) $ error _
test₁₁ = refl
-- Lists can bring per-element constraints, which we are currently
-- generating with foreach macro.
test-12f : (n : ℕ) → List (List $ Fin n) → ℕ
test-12f n xs = 10
test₁₂ : _≡_ {A = Prog} (kompile test-12f [] []) $ error _
test₁₂ = refl
| {
"alphanum_fraction": 0.4829485834,
"avg_line_length": 27.6231884058,
"ext": "agda",
"hexsha": "a6ee02d121ce0fc5bdd2d5c747fcf6e3a1d3aa06",
"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": "Example-00.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": "Example-00.agda",
"max_line_length": 130,
"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": "Example-00.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": 1197,
"size": 3812
} |
{-# OPTIONS --cubical --safe #-}
module ScaleDegree where
open import Data.Fin using (Fin; toℕ; #_)
open import Data.Nat using (ℕ; suc; _+_)
open import Data.Nat.DivMod using (_mod_; _div_)
open import Data.Product using (_×_; _,_)
open import Data.Vec using (lookup)
open import Pitch
ScaleDegree : ℕ → Set
ScaleDegree = Fin
ScaleDegreeOctave : ℕ → Set
ScaleDegreeOctave n = ScaleDegree n × Octave
transposeScaleDegree : {n : ℕ} → ℕ → ScaleDegreeOctave (suc n) → ScaleDegreeOctave (suc n)
transposeScaleDegree {n} k (d , o) =
let d' = (toℕ d) + k
in d' mod (suc n) , o + (d' div (suc n))
scaleDegreeToPC : {n : ℕ} → Scale n → ScaleDegree n → PC
scaleDegreeToPC scale d = lookup scale d
| {
"alphanum_fraction": 0.6652835408,
"avg_line_length": 26.7777777778,
"ext": "agda",
"hexsha": "9a26d03beabc45ce21303c3b7faaf7a36ca4726b",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z",
"max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/MusicTools",
"max_forks_repo_path": "agda/ScaleDegree.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/MusicTools",
"max_issues_repo_path": "agda/ScaleDegree.agda",
"max_line_length": 90,
"max_stars_count": 28,
"max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/MusicTools",
"max_stars_repo_path": "agda/ScaleDegree.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z",
"num_tokens": 230,
"size": 723
} |
open import Data.Product using ( _,_ ; proj₁ ; proj₂ )
open import Web.Semantic.DL.ABox.Interp using
( Interp ; _*_ ; ⌊_⌋ ; ind )
open import Web.Semantic.DL.ABox.Interp.Morphism using
( _≲_ ; _**_ ; ≲-refl )
open import Web.Semantic.DL.ABox.Model using
( _⊨a_ ; _⊨b_ ; *-resp-⟨ABox⟩ ; ⊨a-resp-≲ )
open import Web.Semantic.DL.Category.Object using
( Object ; _,_ ; IN ; fin ; iface )
open import Web.Semantic.DL.Category.Morphism using
( _⇒_ ; _,_ ; BN ; impl
; apply ; apply✓ ; apply-init )
open import Web.Semantic.DL.Category.Wiring using
( identity ; wires-≈ ; wires-≈⁻¹ )
open import Web.Semantic.DL.Category.Composition using
( _∙_ ; ⊨a-intro-⟫ ; ⊨b-intro-⟫ )
open import Web.Semantic.DL.Integrity using ( med-≲ ; init-med )
open import Web.Semantic.DL.KB using ( _,_ )
open import Web.Semantic.DL.KB.Model using ( _⊨_ )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using ( TBox ; _,_ )
open import Web.Semantic.DL.TBox.Interp using ( _⊨_≈_ )
open import Web.Semantic.Util using
( id ; _⊕_⊕_ ; inode ; bnode ; enode ; left ; right )
module Web.Semantic.DL.Category.Properties.Composition.Lemmas
{Σ : Signature} {S T : TBox Σ} where
identity-elim : ∀ (A : Object S T) I → (I ⊨a impl (identity A)) →
∀ x → (⌊ I ⌋ ⊨ ind I (inode x) ≈ ind I (enode x))
identity-elim (X , X∈Fin , A) I I⊨id x = wires-≈ id (proj₂ X∈Fin x) I⊨id
identity-intro : ∀ (A : Object S T) I →
(∀ x → (⌊ I ⌋ ⊨ ind I (inode x) ≈ ind I (enode x))) →
(I ⊨a impl (identity A))
identity-intro (X , X∈Fin , A) I ∀x∙x₁≈x₂ = wires-≈⁻¹ id ∀x∙x₁≈x₂ (proj₁ X∈Fin)
compose-left : ∀ {A B C : Object S T} (F : A ⇒ B) (G : B ⇒ C) I →
(I ⊨a impl (F ∙ G)) → (left * I ⊨a impl F)
compose-left {X , X∈Fin , A} {Y , Y∈Fin , B} {Z , Z∈Fin , C}
(V , F , F✓) (W , G , G✓) I (I⊨F , I⊨G) =
*-resp-⟨ABox⟩ left I F I⊨F
compose-right : ∀ {A B C : Object S T} (F : A ⇒ B) (G : B ⇒ C) I →
(I ⊨a impl (F ∙ G)) → (right * I ⊨a impl G)
compose-right {X , X∈Fin , A} {Y , Y∈Fin , B} {Z , Z∈Fin , C}
(V , F , F✓) (W , G , G✓) I (I⊨F , I⊨G) =
*-resp-⟨ABox⟩ right I G I⊨G
compose-mid : ∀ {A B C : Object S T} (F : A ⇒ B) (G : B ⇒ C)
(I : Interp Σ (IN A ⊕ (BN F ⊕ IN B ⊕ BN G) ⊕ IN C)) →
(inode * I ⊨ (S , T) , iface A) → (I ⊨a impl (F ∙ G)) →
(bnode * bnode * I ⊨ (S , T) , iface B)
compose-mid {A} {B} {C} F G I ((I⊨S , I⊨T) , I⊨A) I⊨F⟫G =
((I⊨S , I⊨T) , ⊨a-resp-≲ (enode ** J≲I) (iface B) J⊨B) where
J : Interp Σ (IN A ⊕ BN F ⊕ IN B)
J = apply F (inode * I) ((I⊨S , I⊨T) , I⊨A)
J⊨B : enode * J ⊨a iface B
J⊨B = proj₂ (apply✓ F (inode * I) ((I⊨S , I⊨T) , I⊨A))
J≲I : J ≲ left * I
J≲I = med-≲ (init-med (apply-init F (inode * I) ((I⊨S , I⊨T) , I⊨A))
(left * I) (≲-refl (inode * I)) (I⊨S , compose-left F G I I⊨F⟫G))
compose-resp-⊨a : ∀ {A B C : Object S T} (F : A ⇒ B) (G : B ⇒ C) I →
(left * I ⊨a impl F) → (right * I ⊨a impl G) → (I ⊨a impl (F ∙ G))
compose-resp-⊨a {X , X∈Fin , A} {Y , Y∈Fin , B} {Z , Z∈Fin , C}
(V , F , F✓) (W , G , G✓) I I⊨F I⊨G =
⊨a-intro-⟫ I F G I⊨F I⊨G
compose-resp-⊨b : ∀ {A B C : Object S T} {V W : Set} (F : A ⇒ B) (G : B ⇒ C)
(I : Interp Σ (IN A ⊕ (V ⊕ IN B ⊕ W) ⊕ IN C)) →
(left * I ⊨b impl F) → (right * I ⊨b impl G) → (I ⊨b impl (F ∙ G))
compose-resp-⊨b {X , X∈Fin , A} {Y , Y∈Fin , B} {Z , Z∈Fin , C}
(V , F , F✓) (W , G , G✓) I I⊨F I⊨G =
⊨b-intro-⟫ I F G I⊨F I⊨G
| {
"alphanum_fraction": 0.5295675199,
"avg_line_length": 43.0253164557,
"ext": "agda",
"hexsha": "b25c0d413e6dcab4342936815d6f90d2529d2804",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z",
"max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/Category/Properties/Composition/Lemmas.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/Category/Properties/Composition/Lemmas.agda",
"max_line_length": 79,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/Category/Properties/Composition/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z",
"num_tokens": 1688,
"size": 3399
} |
{-# OPTIONS --rewriting --confluence-check #-}
module Issue4333.N0 where
open import Issue4333.M
{-# REWRITE p₀ #-}
b₀' : B a₀'
b₀' = b
| {
"alphanum_fraction": 0.652173913,
"avg_line_length": 15.3333333333,
"ext": "agda",
"hexsha": "9af365e3f0f4a622791bcde32a027a264fd7c824",
"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/Issue4333/N0.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/Issue4333/N0.agda",
"max_line_length": 46,
"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/Issue4333/N0.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": 45,
"size": 138
} |
module Relation.Relation where
open import Level renaming (suc to lsuc)
open import Data.Product
-- Partial equivalence relations.
record ParRel {l l' : Level}{A : Set l}(R : A → A → Set l') : Set (l ⊔ l') where
field
symPf : ∀{x y} → R x y → R y x
transPf : ∀{x y z} → R x y → R y z → R x z
-- (Total) equivalence relation.
record EqRel {l l' : Level}{A : Set l}(R : A → A → Set l') : Set (l ⊔ l') where
field
parEqPf : ParRel R
refPf : ∀{x} → R x x
open ParRel public
open EqRel public
-- The product of two relations.
ProductRel : {l l' : Level}{A : Set l}{B : Set l'}
→ (R : A → A → Set l)
→ (R' : B → B → Set l')
→ (A × B → A × B → Set (l ⊔ l'))
ProductRel R R' a b = (R (proj₁ a) (proj₁ b)) × (R' (proj₂ a) (proj₂ b))
-- The product of two partial equivalence relations is also a partial
-- equivalence relation.
ProductRelIsParRel : {l l' : Level}{A : Set l}{B : Set l'}
→ (R : A → A → Set l)
→ (R' : B → B → Set l')
→ ParRel R
→ ParRel R'
→ ParRel (ProductRel R R')
ProductRelIsParRel R R' erPF₁ erPF₂ =
record { symPf = λ x₁ → symPf erPF₁ (proj₁ x₁) , symPf erPF₂ (proj₂ x₁);
transPf = λ x₁ x₂ → (transPf erPF₁ (proj₁ x₁) (proj₁ x₂)) , (transPf erPF₂ (proj₂ x₁) (proj₂ x₂)) }
-- The product of two (total) equivalence relations is also a (total)
-- equivalence relation.
ProductRelIsEqRel : {l l' : Level}{A : Set l}{B : Set l'}
→ (R : A → A → Set l)
→ (R' : B → B → Set l')
→ EqRel R
→ EqRel R'
→ EqRel (ProductRel R R')
ProductRelIsEqRel R R' erPF₁ erPF₂ =
record { parEqPf = ProductRelIsParRel R R' (parEqPf erPF₁) (parEqPf erPF₂);
refPf = λ {x} → (refPf erPF₁ {proj₁ x}) , (refPf erPF₂ {proj₂ x}) }
-- The restriction of a relation by a predicate.
_↓_ : {l l' : Level}
{A : Set l}
→ (R : A → A → Set l)
→ (P : A → Set l')
→ Set (l ⊔ l')
_↓_ {A = A} R P = Σ[ f ∈ A ] (P f)
-- The restriction of a paritial equivalence is also a partial
-- equivalence.
↓ParRel : {l l' : Level}
{A : Set l}
→ (R : A → A → Set l)
→ (P : A → Set l')
→ ParRel R
→ ParRel (λ (f g : R ↓ P) → R (proj₁ f) (proj₁ g))
↓ParRel R P prPF = record { symPf = λ x₁ → symPf prPF x₁; transPf = λ x₁ x₂ → transPf prPF x₁ x₂ }
-- The restriction of an equivalence relation is also an equivalence
-- relation.
↓EqRel : {l l' : Level}
{A : Set l}
→ (R : A → A → Set l)
→ (P : A → Set l')
→ EqRel R
→ EqRel (λ (f g : R ↓ P) → R (proj₁ f) (proj₁ g))
↓EqRel R P eqrPF = record { parEqPf = ↓ParRel R P (parEqPf eqrPF); refPf = refPf eqrPF }
| {
"alphanum_fraction": 0.550553224,
"avg_line_length": 33.1772151899,
"ext": "agda",
"hexsha": "78fbd97ac608303b619e98dbaf6660cf030c7ac1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "setoid-cats/Relation/Relation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "setoid-cats/Relation/Relation.agda",
"max_line_length": 110,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "setoid-cats/Relation/Relation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1023,
"size": 2621
} |
open import Agda.Primitive public
variable
ℓ ℓ' : Level
data _≡_ {X : Set ℓ} : X → X → Set ℓ where
refl : {x : X} → x ≡ x
ap : {X : Set ℓ} {Y : Set ℓ'} (f : X → Y) {x x' : X} → x ≡ x' → f x ≡ f x'
ap f refl = refl
_∙_ : {X : Set ℓ} {x y z : X} → x ≡ y → y ≡ z → x ≡ z
p ∙ refl = p
yoneda-elem-lc : {X : Set ℓ} {x : X} {A : X → Set ℓ'} (η θ : (y : X) → x ≡ y → A y)
→ η x refl ≡ θ x refl → ∀ y p → η y p ≡ θ y p
yoneda-elem-lc η θ q y refl = ap (λ a → a) q
ext-assoc : {X : Set ℓ} {z t : X} (r : z ≡ t)
→ (λ (x y : X) (p : x ≡ y) (q : y ≡ z) → (p ∙ q) ∙ r)
≡ (λ (x y : X) (p : x ≡ y) (q : y ≡ z) → p ∙ (q ∙ r))
ext-assoc {ℓ} {X} {z} {t} = yoneda-elem-lc
-- {A = λ - → (x y : X) (p : x ≡ y) (q : y ≡ z) → x ≡ - }
(λ z r x y p q → (p ∙ q) ∙ r)
(λ z r x y p q → p ∙ (q ∙ r))
refl
t
| {
"alphanum_fraction": 0.3291796469,
"avg_line_length": 33.2068965517,
"ext": "agda",
"hexsha": "3efae377466dd1daadb7108b78e59b3a82ff061f",
"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/Issue3960h.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/Issue3960h.agda",
"max_line_length": 85,
"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/Issue3960h.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": 450,
"size": 963
} |
{-# OPTIONS --type-in-type #-}
module Generic.Test.Experiment where
open import Generic.Lib.Prelude
data Desc (I : Set) : Set₁ where
ret : I -> Desc I
π : (A : Set) -> (A -> Desc I) -> Desc I
_⊕_ : Desc I -> Desc I -> Desc I
data RecDesc (I : Set) : Set₁ where
rec : ((I -> Set) -> Desc I) -> RecDesc I
⟦_⟧ : ∀ {I} -> Desc I -> (I -> Set) -> I -> Set
⟦ ret i ⟧ B j = i ≡ j
⟦ π A D ⟧ B j = ∃ λ x -> ⟦ D x ⟧ B j
⟦ D ⊕ E ⟧ B j = ⟦ D ⟧ B j ⊎ ⟦ E ⟧ B j
⟦_⟧ʳ : ∀ {I} -> RecDesc I -> (I -> Set) -> I -> Set
⟦ rec K ⟧ʳ B j = ⟦ K B ⟧ B j
{-# NO_POSITIVITY_CHECK #-}
data μ {I} (D : RecDesc I) j : Set where
node : ⟦ D ⟧ʳ (μ D) j -> μ D j
DescEq : ∀ {I} -> Desc I -> Set
DescEq (ret i) = ⊤
DescEq (π A D) = Eq A × ∀ x -> DescEq (D x)
DescEq (D ⊕ E) = DescEq D × DescEq E
RecDescEq : ∀ {I} -> RecDesc I -> Set₁
RecDescEq (rec K) = ∀ {B} {{eqB : ∀ {i} -> Eq (B i)}} -> DescEq (K B)
instance
{-# TERMINATING #-}
DataEq : ∀ {I} {D : RecDesc I} {j} {{recDescEq : RecDescEq D}} -> Eq (μ D j)
DataEq {D = D} {j} = record
{ _≟_ = eqMu
} where
node-inj : ∀ {I D j x y} -> node {I} {D} {j} x ≡ node y -> x ≡ y
node-inj refl = refl
eqSem : ∀ {j} D₀ D {{descEq : DescEq D}} -> IsSet (⟦ D ⟧ (μ D₀) j)
eqSem D₀ (ret i) refl refl = yes refl
eqSem D₀ (π A D) {{eqA , eqD}} p₁ p₂ =
decProd (_≟_ {{eqA}}) (eqSem D₀ (D _) {{eqD _}}) p₁ p₂
eqSem D₀ (D ⊕ E) {{eqD , eqE}} s₁ s₂ =
decSum (eqSem D₀ D {{eqD}}) (eqSem D₀ E {{eqE}}) s₁ s₂
eqMu : ∀ {D} {{recDescEq : RecDescEq D}} -> IsSet (μ D j)
eqMu {D@(rec K)} {{recDescEq}} (node d₁) (node d₂) =
dcong node node-inj (eqSem D _ {{recDescEq {{DataEq {D = D}}}}} d₁ d₂)
module Example1 where
open import Generic.Main using (deriveEqTo)
instance
ListEq : {A : Set} {{eqA : Eq A}} -> Eq (List A)
unquoteDef ListEq = deriveEqTo ListEq (quote List)
data Rose (A : Set) : Set where
rose : A -> List (Rose A) -> Rose A
Rose′ : Set -> Set
Rose′ A = flip μ tt $ rec λ Rose′ -> π A λ _ -> π (List (Rose′ tt)) λ _ -> ret tt
pattern rose′ x rs = node (x , rs , refl)
{-# TERMINATING #-}
Rose→Rose′ : ∀ {A} -> Rose A -> Rose′ A
Rose→Rose′ (rose x rs) = rose′ x (map Rose→Rose′ rs)
{-# TERMINATING #-}
Rose′→Rose : ∀ {A} -> Rose′ A -> Rose A
Rose′→Rose (rose′ x rs) = rose x (map Rose′→Rose rs)
arose : Rose′ ℕ
arose = rose′ 4 (rose′ 1 (rose′ 6 [] ∷ []) ∷ rose′ 2 [] ∷ [])
find : {A : Set} {{x : A}} -> A
find {{x}} = x
-- -- Instance search cannot be used to find elements in an explicit function type
-- test : _≟_ {{DataEq {{λ {_} -> find}}}} arose arose ≡ yes refl
-- test = refl
module Example2 where
-- If `A` is a parameter, then this definition would be strictly positive,
-- but I intentionally made it an index, because we can't make `A` a parameter
-- in the described version of `D`.
{-# NO_POSITIVITY_CHECK #-}
data D : Set -> Set where
ret : ∀ {A} -> A -> D A
rec : ∀ {A} -> D (D A) -> D A
D′ : Set -> Set
D′ = μ $ rec λ D′ -> (π Set λ A -> π A λ _ -> ret A)
⊕ (π Set λ A -> π (D′ (D′ A)) λ _ -> ret A)
pattern ret′ x = node (inj₁ (_ , x , refl))
pattern rec′ r = node (inj₂ (_ , r , refl))
Dⁿ : ℕ -> Set -> Set
Dⁿ 0 A = A
Dⁿ (suc n) A = D (Dⁿ n A)
D′ⁿ : ℕ -> Set -> Set
D′ⁿ 0 A = A
D′ⁿ (suc n) A = D′ (D′ⁿ n A)
⟨D→D′⟩ⁿ : ∀ {A} n -> D (Dⁿ n A) -> D′ (D′ⁿ n A)
⟨D→D′⟩ⁿ 0 (ret x) = ret′ x
⟨D→D′⟩ⁿ (suc n) (ret r) = ret′ (⟨D→D′⟩ⁿ n r)
⟨D→D′⟩ⁿ n (rec r) = rec′ (⟨D→D′⟩ⁿ (suc n) r)
⟨D′→D⟩ⁿ : ∀ {A} n -> D′ (D′ⁿ n A) -> D (Dⁿ n A)
⟨D′→D⟩ⁿ 0 (ret′ x) = ret x
⟨D′→D⟩ⁿ (suc n) (ret′ r) = ret (⟨D′→D⟩ⁿ n r)
⟨D′→D⟩ⁿ n (rec′ r) = rec (⟨D′→D⟩ⁿ (suc n) r)
D→D′ : ∀ {A} -> D A -> D′ A
D→D′ = ⟨D→D′⟩ⁿ 0
D′→D : ∀ {A} -> D′ A -> D A
D′→D = ⟨D′→D⟩ⁿ 0
| {
"alphanum_fraction": 0.4770689213,
"avg_line_length": 30.7322834646,
"ext": "agda",
"hexsha": "a7d444e7347795815c1baac5841f01b826827889",
"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/Test/Experiment.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/Test/Experiment.agda",
"max_line_length": 84,
"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/Test/Experiment.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": 1706,
"size": 3903
} |
{-# OPTIONS --universe-polymorphism #-}
open import Categories.Category
open import Categories.Object.Products
open import Categories.Object.Terminal
open import Level
module Categories.Object.Terminal.Exponentiating {o ℓ e : Level}
(C : Category o ℓ e)
(P : Products C) where
open Category C
open Products P
open Terminal terminal
open import Categories.Object.Exponentiating
import Categories.Object.Terminal.Exponentials
open Categories.Object.Terminal.Exponentials C terminal
⊤-exponentiating : Exponentiating C binary ⊤
⊤-exponentiating = record
{ exponential = λ {X : Obj} → [⊤↑ X ]-exponential
}
| {
"alphanum_fraction": 0.768115942,
"avg_line_length": 24.84,
"ext": "agda",
"hexsha": "fd1f5994531d569cb4864695a4da9c4b184a6c7a",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Object/Terminal/Exponentiating.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Object/Terminal/Exponentiating.agda",
"max_line_length": 64,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Object/Terminal/Exponentiating.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 156,
"size": 621
} |
{-# OPTIONS --safe #-}
module Cubical.Data.FinSet.Binary.Small where
open import Cubical.Data.FinSet.Binary.Small.Base public
open import Cubical.Data.FinSet.Binary.Small.Properties public
| {
"alphanum_fraction": 0.7958115183,
"avg_line_length": 27.2857142857,
"ext": "agda",
"hexsha": "72070faebd474a9e2a449f8ffbccc2cc7dff1d3d",
"lang": "Agda",
"max_forks_count": 134,
"max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z",
"max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "marcinjangrzybowski/cubical",
"max_forks_repo_path": "Cubical/Data/FinSet/Binary/Small.agda",
"max_issues_count": 584,
"max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "marcinjangrzybowski/cubical",
"max_issues_repo_path": "Cubical/Data/FinSet/Binary/Small.agda",
"max_line_length": 62,
"max_stars_count": 301,
"max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "marcinjangrzybowski/cubical",
"max_stars_repo_path": "Cubical/Data/FinSet/Binary/Small.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z",
"num_tokens": 42,
"size": 191
} |
{-# OPTIONS --without-K --safe #-}
module Fragment.Examples.CSemigroup.Arith.Atomic where
open import Fragment.Examples.CSemigroup.Arith.Base
-- Fully dynamic associativity
+-dyn-assoc₁ : ∀ {m n o} → (m + n) + o ≡ m + (n + o)
+-dyn-assoc₁ = fragment CSemigroupFrex +-csemigroup
+-dyn-assoc₂ : ∀ {m n o p} → ((m + n) + o) + p ≡ m + (n + (o + p))
+-dyn-assoc₂ = fragment CSemigroupFrex +-csemigroup
+-dyn-assoc₃ : ∀ {m n o p q} → (m + n) + o + (p + q) ≡ m + (n + o + p) + q
+-dyn-assoc₃ = fragment CSemigroupFrex +-csemigroup
*-dyn-assoc₁ : ∀ {m n o} → (m * n) * o ≡ m * (n * o)
*-dyn-assoc₁ = fragment CSemigroupFrex *-csemigroup
*-dyn-assoc₂ : ∀ {m n o p} → ((m * n) * o) * p ≡ m * (n * (o * p))
*-dyn-assoc₂ = fragment CSemigroupFrex *-csemigroup
*-dyn-assoc₃ : ∀ {m n o p q} → (m * n) * o * (p * q) ≡ m * (n * o * p) * q
*-dyn-assoc₃ = fragment CSemigroupFrex *-csemigroup
-- Fully dynamic commutativity
+-dyn-comm₁ : ∀ {m n} → m + n ≡ n + m
+-dyn-comm₁ = fragment CSemigroupFrex +-csemigroup
+-dyn-comm₂ : ∀ {m n o} → m + (n + o) ≡ (o + n) + m
+-dyn-comm₂ = fragment CSemigroupFrex +-csemigroup
+-dyn-comm₃ : ∀ {m n o p} → (m + n) + (o + p) ≡ (p + o) + (n + m)
+-dyn-comm₃ = fragment CSemigroupFrex +-csemigroup
*-dyn-comm₁ : ∀ {m n} → m * n ≡ n * m
*-dyn-comm₁ = fragment CSemigroupFrex *-csemigroup
*-dyn-comm₂ : ∀ {m n o} → m * (n * o) ≡ (o * n) * m
*-dyn-comm₂ = fragment CSemigroupFrex *-csemigroup
*-dyn-comm₃ : ∀ {m n o p} → (m * n) * (o * p) ≡ (p * o) * (n * m)
*-dyn-comm₃ = fragment CSemigroupFrex *-csemigroup
-- Fully dynamic associavity and commutativity
+-dyn-comm-assoc₁ : ∀ {m n o} → (m + n) + o ≡ n + (m + o)
+-dyn-comm-assoc₁ = fragment CSemigroupFrex +-csemigroup
+-dyn-comm-assoc₂ : ∀ {m n o p} → ((m + n) + o) + p ≡ p + (o + (n + m))
+-dyn-comm-assoc₂ = fragment CSemigroupFrex +-csemigroup
+-dyn-comm-assoc₃ : ∀ {m n o p q} → (m + n) + o + (p + q) ≡ q + (p + o + n) + m
+-dyn-comm-assoc₃ = fragment CSemigroupFrex +-csemigroup
*-dyn-comm-assoc₁ : ∀ {m n o} → (m * n) * o ≡ n * (m * o)
*-dyn-comm-assoc₁ = fragment CSemigroupFrex *-csemigroup
*-dyn-comm-assoc₂ : ∀ {m n o p} → ((m * n) * o) * p ≡ p * (o * (n * m))
*-dyn-comm-assoc₂ = fragment CSemigroupFrex *-csemigroup
*-dyn-comm-assoc₃ : ∀ {m n o p q} → (m * n) * o * (p * q) ≡ q * (p * o * n) * m
*-dyn-comm-assoc₃ = fragment CSemigroupFrex *-csemigroup
-- Partially static associativity
+-sta-assoc₁ : ∀ {m n} → (m + 2) + (3 + n) ≡ m + (5 + n)
+-sta-assoc₁ = fragment CSemigroupFrex +-csemigroup
+-sta-assoc₂ : ∀ {m n o p} → (((m + n) + 5) + o) + p ≡ m + (n + (2 + (3 + (o + p))))
+-sta-assoc₂ = fragment CSemigroupFrex +-csemigroup
+-sta-assoc₃ : ∀ {m n o p} → ((m + n) + 2) + (3 + (o + p)) ≡ m + ((n + 1) + (4 + o)) + p
+-sta-assoc₃ = fragment CSemigroupFrex +-csemigroup
*-sta-assoc₁ : ∀ {m n} → (m * 2) * (3 * n) ≡ m * (6 * n)
*-sta-assoc₁ = fragment CSemigroupFrex *-csemigroup
*-sta-assoc₂ : ∀ {m n o p} → (((m * n) * 6) * o) * p ≡ m * (n * (2 * (3 * (o * p))))
*-sta-assoc₂ = fragment CSemigroupFrex *-csemigroup
*-sta-assoc₃ : ∀ {m n o p} → ((m * n) * 2) * (6 * (o * p)) ≡ m * ((n * 2) * (6 * o)) * p
*-sta-assoc₃ = fragment CSemigroupFrex *-csemigroup
-- Partially static commutativity
+-sta-comm₁ : ∀ {m} → m + 1 ≡ 1 + m
+-sta-comm₁ = fragment CSemigroupFrex +-csemigroup
+-sta-comm₂ : ∀ {m n} → m + (2 + n) ≡ (n + 2) + m
+-sta-comm₂ = fragment CSemigroupFrex +-csemigroup
+-sta-comm₃ : ∀ {m n o p} → (1 + (m + n)) + ((o + p) + 2) ≡ ((p + o) + 2) + (1 + (n + m))
+-sta-comm₃ = fragment CSemigroupFrex +-csemigroup
*-sta-comm₁ : ∀ {m} → m * 4 ≡ 4 * m
*-sta-comm₁ = fragment CSemigroupFrex *-csemigroup
*-sta-comm₂ : ∀ {m n} → m * (2 * n) ≡ (n * 2) * m
*-sta-comm₂ = fragment CSemigroupFrex *-csemigroup
*-sta-comm₃ : ∀ {m n o p} → (4 * (m * n)) * ((o * p) * 2) ≡ ((p * o) * 2) * (4 * (n * m))
*-sta-comm₃ = fragment CSemigroupFrex *-csemigroup
-- Partially static associavity and commutativity
+-sta-comm-assoc₁ : ∀ {m n o} → 1 + (m + n) + o + 4 ≡ 5 + n + (m + o)
+-sta-comm-assoc₁ = fragment CSemigroupFrex +-csemigroup
+-sta-comm-assoc₂ : ∀ {m n o p} → 5 + ((m + n) + o) + p ≡ p + ((o + 1) + (n + m)) + 4
+-sta-comm-assoc₂ = fragment CSemigroupFrex +-csemigroup
+-sta-comm-assoc₃ : ∀ {m n o p q} → (m + n + 1) + o + (p + q + 4) ≡ (2 + q) + (p + o + n) + (m + 3)
+-sta-comm-assoc₃ = fragment CSemigroupFrex +-csemigroup
*-sta-comm-assoc₁ : ∀ {m n o} → 2 * (m * n) * o * 3 ≡ 6 * n * (m * o)
*-sta-comm-assoc₁ = fragment CSemigroupFrex *-csemigroup
*-sta-comm-assoc₂ : ∀ {m n o p} → 6 * ((m * n) * o) * p ≡ p * ((o * 2) * (n * m)) * 3
*-sta-comm-assoc₂ = fragment CSemigroupFrex *-csemigroup
*-sta-comm-assoc₃ : ∀ {m n o p q} → (m * n * 3) * o * (p * q * 4) ≡ (2 * q) * (p * o * n) * (m * 6)
*-sta-comm-assoc₃ = fragment CSemigroupFrex *-csemigroup
| {
"alphanum_fraction": 0.5436101234,
"avg_line_length": 37.9444444444,
"ext": "agda",
"hexsha": "6b64edfbd9378a71c7b1b9fb2000829b29274047",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Examples/CSemigroup/Arith/Atomic.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Examples/CSemigroup/Arith/Atomic.agda",
"max_line_length": 99,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Examples/CSemigroup/Arith/Atomic.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z",
"num_tokens": 2091,
"size": 4781
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Inductive pointwise lifting of relations to vectors
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Vec.Relation.Binary.Pointwise.Inductive where
open import Algebra.FunctionProperties
open import Data.Fin using (Fin; zero; suc)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Product using (_×_; _,_)
open import Data.Vec as Vec hiding ([_]; head; tail; map; lookup)
open import Data.Vec.Relation.Unary.All using (All; []; _∷_)
open import Level using (_⊔_)
open import Function using (_∘_)
open import Function.Equivalence using (_⇔_; equivalence)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Nullary
------------------------------------------------------------------------
-- Relation
infixr 5 _∷_
data Pointwise {a b ℓ} {A : Set a} {B : Set b} (_∼_ : REL A B ℓ) :
∀ {m n} (xs : Vec A m) (ys : Vec B n) → Set (a ⊔ b ⊔ ℓ)
where
[] : Pointwise _∼_ [] []
_∷_ : ∀ {m n x y} {xs : Vec A m} {ys : Vec B n}
(x∼y : x ∼ y) (xs∼ys : Pointwise _∼_ xs ys) →
Pointwise _∼_ (x ∷ xs) (y ∷ ys)
length-equal : ∀ {a b m n ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ}
{xs : Vec A m} {ys : Vec B n} →
Pointwise _∼_ xs ys → m ≡ n
length-equal [] = P.refl
length-equal (_ ∷ xs∼ys) = P.cong suc (length-equal xs∼ys)
------------------------------------------------------------------------
-- Operations
module _ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} where
head : ∀ {m n x y} {xs : Vec A m} {ys : Vec B n} →
Pointwise _∼_ (x ∷ xs) (y ∷ ys) → x ∼ y
head (x∼y ∷ xs∼ys) = x∼y
tail : ∀ {m n x y} {xs : Vec A m} {ys : Vec B n} →
Pointwise _∼_ (x ∷ xs) (y ∷ ys) → Pointwise _∼_ xs ys
tail (x∼y ∷ xs∼ys) = xs∼ys
lookup : ∀ {n} {xs : Vec A n} {ys : Vec B n} → Pointwise _∼_ xs ys →
∀ i → (Vec.lookup xs i) ∼ (Vec.lookup ys i)
lookup (x∼y ∷ _) zero = x∼y
lookup (_ ∷ xs∼ys) (suc i) = lookup xs∼ys i
map : ∀ {ℓ₂} {_≈_ : REL A B ℓ₂} →
_≈_ ⇒ _∼_ → ∀ {m n} → Pointwise _≈_ ⇒ Pointwise _∼_ {m} {n}
map ∼₁⇒∼₂ [] = []
map ∼₁⇒∼₂ (x∼y ∷ xs∼ys) = ∼₁⇒∼₂ x∼y ∷ map ∼₁⇒∼₂ xs∼ys
------------------------------------------------------------------------
-- Relational properties
refl : ∀ {a ℓ} {A : Set a} {_∼_ : Rel A ℓ} →
∀ {n} → Reflexive _∼_ → Reflexive (Pointwise _∼_ {n})
refl ∼-refl {[]} = []
refl ∼-refl {x ∷ xs} = ∼-refl ∷ refl ∼-refl
sym : ∀ {a b ℓ} {A : Set a} {B : Set b}
{P : REL A B ℓ} {Q : REL B A ℓ} {m n} →
Sym P Q → Sym (Pointwise P) (Pointwise Q {m} {n})
sym sm [] = []
sym sm (x∼y ∷ xs∼ys) = sm x∼y ∷ sym sm xs∼ys
trans : ∀ {a b c ℓ} {A : Set a} {B : Set b} {C : Set c}
{P : REL A B ℓ} {Q : REL B C ℓ} {R : REL A C ℓ} {m n o} →
Trans P Q R →
Trans (Pointwise P {m}) (Pointwise Q {n} {o}) (Pointwise R)
trans trns [] [] = []
trans trns (x∼y ∷ xs∼ys) (y∼z ∷ ys∼zs) =
trns x∼y y∼z ∷ trans trns xs∼ys ys∼zs
decidable : ∀ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} →
Decidable _∼_ → ∀ {m n} → Decidable (Pointwise _∼_ {m} {n})
decidable dec [] [] = yes []
decidable dec [] (y ∷ ys) = no λ()
decidable dec (x ∷ xs) [] = no λ()
decidable dec (x ∷ xs) (y ∷ ys) with dec x y
... | no ¬x∼y = no (¬x∼y ∘ head)
... | yes x∼y with decidable dec xs ys
... | no ¬xs∼ys = no (¬xs∼ys ∘ tail)
... | yes xs∼ys = yes (x∼y ∷ xs∼ys)
isEquivalence : ∀ {a ℓ} {A : Set a} {_∼_ : Rel A ℓ} →
IsEquivalence _∼_ → ∀ n →
IsEquivalence (Pointwise _∼_ {n})
isEquivalence equiv n = record
{ refl = refl (IsEquivalence.refl equiv)
; sym = sym (IsEquivalence.sym equiv)
; trans = trans (IsEquivalence.trans equiv)
}
isDecEquivalence : ∀ {a ℓ} {A : Set a} {_∼_ : Rel A ℓ} →
IsDecEquivalence _∼_ → ∀ n →
IsDecEquivalence (Pointwise _∼_ {n})
isDecEquivalence decEquiv n = record
{ isEquivalence = isEquivalence (IsDecEquivalence.isEquivalence decEquiv) n
; _≟_ = decidable (IsDecEquivalence._≟_ decEquiv)
}
setoid : ∀ {a ℓ} → Setoid a ℓ → ℕ → Setoid a (a ⊔ ℓ)
setoid S n = record
{ isEquivalence = isEquivalence (Setoid.isEquivalence S) n
}
decSetoid : ∀ {a ℓ} → DecSetoid a ℓ → ℕ → DecSetoid a (a ⊔ ℓ)
decSetoid S n = record
{ isDecEquivalence = isDecEquivalence (DecSetoid.isDecEquivalence S) n
}
------------------------------------------------------------------------
-- map
module _ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d} where
map⁺ : ∀ {ℓ₁ ℓ₂} {_∼₁_ : REL A B ℓ₁} {_∼₂_ : REL C D ℓ₂}
{f : A → C} {g : B → D} →
(∀ {x y} → x ∼₁ y → f x ∼₂ g y) →
∀ {m n xs ys} → Pointwise _∼₁_ {m} {n} xs ys →
Pointwise _∼₂_ (Vec.map f xs) (Vec.map g ys)
map⁺ ∼₁⇒∼₂ [] = []
map⁺ ∼₁⇒∼₂ (x∼y ∷ xs∼ys) = ∼₁⇒∼₂ x∼y ∷ map⁺ ∼₁⇒∼₂ xs∼ys
------------------------------------------------------------------------
-- _++_
module _ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} where
++⁺ : ∀ {m n p q}
{ws : Vec A m} {xs : Vec B p} {ys : Vec A n} {zs : Vec B q} →
Pointwise _∼_ ws xs → Pointwise _∼_ ys zs →
Pointwise _∼_ (ws ++ ys) (xs ++ zs)
++⁺ [] ys∼zs = ys∼zs
++⁺ (w∼x ∷ ws∼xs) ys∼zs = w∼x ∷ (++⁺ ws∼xs ys∼zs)
++ˡ⁻ : ∀ {m n}
(ws : Vec A m) (xs : Vec B m) {ys : Vec A n} {zs : Vec B n} →
Pointwise _∼_ (ws ++ ys) (xs ++ zs) → Pointwise _∼_ ws xs
++ˡ⁻ [] [] _ = []
++ˡ⁻ (w ∷ ws) (x ∷ xs) (w∼x ∷ ps) = w∼x ∷ ++ˡ⁻ ws xs ps
++ʳ⁻ : ∀ {m n}
(ws : Vec A m) (xs : Vec B m) {ys : Vec A n} {zs : Vec B n} →
Pointwise _∼_ (ws ++ ys) (xs ++ zs) → Pointwise _∼_ ys zs
++ʳ⁻ [] [] ys∼zs = ys∼zs
++ʳ⁻ (w ∷ ws) (x ∷ xs) (_ ∷ ps) = ++ʳ⁻ ws xs ps
++⁻ : ∀ {m n}
(ws : Vec A m) (xs : Vec B m) {ys : Vec A n} {zs : Vec B n} →
Pointwise _∼_ (ws ++ ys) (xs ++ zs) →
Pointwise _∼_ ws xs × Pointwise _∼_ ys zs
++⁻ ws xs ps = ++ˡ⁻ ws xs ps , ++ʳ⁻ ws xs ps
------------------------------------------------------------------------
-- concat
module _ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} where
concat⁺ : ∀ {m n p q}
{xss : Vec (Vec A m) n} {yss : Vec (Vec B p) q} →
Pointwise (Pointwise _∼_) xss yss →
Pointwise _∼_ (concat xss) (concat yss)
concat⁺ [] = []
concat⁺ (xs∼ys ∷ ps) = ++⁺ xs∼ys (concat⁺ ps)
concat⁻ : ∀ {m n} (xss : Vec (Vec A m) n) (yss : Vec (Vec B m) n) →
Pointwise _∼_ (concat xss) (concat yss) →
Pointwise (Pointwise _∼_) xss yss
concat⁻ [] [] [] = []
concat⁻ (xs ∷ xss) (ys ∷ yss) ps =
++ˡ⁻ xs ys ps ∷ concat⁻ xss yss (++ʳ⁻ xs ys ps)
------------------------------------------------------------------------
-- tabulate
module _ {a b ℓ} {A : Set a} {B : Set b} {_∼_ : REL A B ℓ} where
tabulate⁺ : ∀ {n} {f : Fin n → A} {g : Fin n → B} →
(∀ i → f i ∼ g i) →
Pointwise _∼_ (tabulate f) (tabulate g)
tabulate⁺ {zero} f∼g = []
tabulate⁺ {suc n} f∼g = f∼g zero ∷ tabulate⁺ (f∼g ∘ suc)
tabulate⁻ : ∀ {n} {f : Fin n → A} {g : Fin n → B} →
Pointwise _∼_ (tabulate f) (tabulate g) →
(∀ i → f i ∼ g i)
tabulate⁻ (f₀∼g₀ ∷ _) zero = f₀∼g₀
tabulate⁻ (_ ∷ f∼g) (suc i) = tabulate⁻ f∼g i
------------------------------------------------------------------------
-- Degenerate pointwise relations
module _ {a b ℓ} {A : Set a} {B : Set b} {P : A → Set ℓ} where
Pointwiseˡ⇒All : ∀ {m n} {xs : Vec A m} {ys : Vec B n} →
Pointwise (λ x y → P x) xs ys → All P xs
Pointwiseˡ⇒All [] = []
Pointwiseˡ⇒All (p ∷ ps) = p ∷ Pointwiseˡ⇒All ps
Pointwiseʳ⇒All : ∀ {n} {xs : Vec B n} {ys : Vec A n} →
Pointwise (λ x y → P y) xs ys → All P ys
Pointwiseʳ⇒All [] = []
Pointwiseʳ⇒All (p ∷ ps) = p ∷ Pointwiseʳ⇒All ps
All⇒Pointwiseˡ : ∀ {n} {xs : Vec A n} {ys : Vec B n} →
All P xs → Pointwise (λ x y → P x) xs ys
All⇒Pointwiseˡ {ys = []} [] = []
All⇒Pointwiseˡ {ys = _ ∷ _} (p ∷ ps) = p ∷ All⇒Pointwiseˡ ps
All⇒Pointwiseʳ : ∀ {n} {xs : Vec B n} {ys : Vec A n} →
All P ys → Pointwise (λ x y → P y) xs ys
All⇒Pointwiseʳ {xs = []} [] = []
All⇒Pointwiseʳ {xs = _ ∷ _} (p ∷ ps) = p ∷ All⇒Pointwiseʳ ps
------------------------------------------------------------------------
-- Pointwise _≡_ is equivalent to _≡_
module _ {a} {A : Set a} where
Pointwise-≡⇒≡ : ∀ {n} {xs ys : Vec A n} →
Pointwise _≡_ xs ys → xs ≡ ys
Pointwise-≡⇒≡ [] = P.refl
Pointwise-≡⇒≡ (P.refl ∷ xs∼ys) = P.cong (_ ∷_) (Pointwise-≡⇒≡ xs∼ys)
≡⇒Pointwise-≡ : ∀ {n} {xs ys : Vec A n} →
xs ≡ ys → Pointwise _≡_ xs ys
≡⇒Pointwise-≡ P.refl = refl P.refl
Pointwise-≡↔≡ : ∀ {n} {xs ys : Vec A n} →
Pointwise _≡_ xs ys ⇔ xs ≡ ys
Pointwise-≡↔≡ = equivalence Pointwise-≡⇒≡ ≡⇒Pointwise-≡
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.15
Pointwise-≡ = Pointwise-≡↔≡
{-# WARNING_ON_USAGE Pointwise-≡
"Warning: Pointwise-≡ was deprecated in v0.15.
Please use Pointwise-≡↔≡ instead."
#-}
| {
"alphanum_fraction": 0.4491184658,
"avg_line_length": 37.1609195402,
"ext": "agda",
"hexsha": "754999393f68c90fdfcf6ee508e9c640334d56c9",
"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/Vec/Relation/Binary/Pointwise/Inductive.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/Vec/Relation/Binary/Pointwise/Inductive.agda",
"max_line_length": 77,
"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/Vec/Relation/Binary/Pointwise/Inductive.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3858,
"size": 9699
} |
module map-++-distribute where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong)
open Eq.≡-Reasoning
open import lists using (List; []; _∷_; _++_; map)
-- リストの結合に関するmapの分配法則の証明
map-++-distribute : {A B : Set} → (f : A → B) → (xs ys : List A)
→ map f (xs ++ ys) ≡ map f xs ++ map f ys
map-++-distribute f [] ys =
begin
map f ([] ++ ys)
≡⟨⟩
map f ys
≡⟨⟩
map f [] ++ map f ys
∎
map-++-distribute f (x ∷ xs) ys =
begin
map f ((x ∷ xs) ++ ys)
≡⟨⟩
f x ∷ map f (xs ++ ys)
≡⟨ cong (f x ∷_) (map-++-distribute f xs ys) ⟩
f x ∷ map f xs ++ map f ys
≡⟨⟩
map f (x ∷ xs) ++ map f ys
∎
| {
"alphanum_fraction": 0.5267175573,
"avg_line_length": 22.5862068966,
"ext": "agda",
"hexsha": "fe56b00ced79c4a2a5fe6271f61e97095f15a3c6",
"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": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "akiomik/plfa-solutions",
"max_forks_repo_path": "part1/lists/map-++-distribute.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"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": "akiomik/plfa-solutions",
"max_issues_repo_path": "part1/lists/map-++-distribute.agda",
"max_line_length": 64,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "akiomik/plfa-solutions",
"max_stars_repo_path": "part1/lists/map-++-distribute.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z",
"num_tokens": 292,
"size": 655
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Floats
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Float where
open import Data.String.Base using (String)
------------------------------------------------------------------------
-- Re-export built-ins publically
open import Agda.Builtin.Float public
using
( Float
; primFloatEquality
; primShowFloat
)
------------------------------------------------------------------------
-- Operations
show : Float → String
show = primShowFloat
| {
"alphanum_fraction": 0.3811023622,
"avg_line_length": 22.6785714286,
"ext": "agda",
"hexsha": "d52733a5b127f2fcf66cec5c5b8b578233cc49c0",
"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/Float.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/Float.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/Float.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 95,
"size": 635
} |
{-
This file contains:
- Properties of set truncations
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.SetTruncation.Properties where
open import Cubical.HITs.SetTruncation.Base
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Univalence
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation
renaming (rec to pRec ; elim to pElim) hiding (elim2 ; elim3 ; rec2 ; map)
private
variable
ℓ ℓ' ℓ'' : Level
A B C D : Type ℓ
rec : isSet B → (A → B) → ∥ A ∥₂ → B
rec Bset f ∣ x ∣₂ = f x
rec Bset f (squash₂ x y p q i j) =
Bset _ _ (cong (rec Bset f) p) (cong (rec Bset f) q) i j
rec2 : isSet C → (A → B → C) → ∥ A ∥₂ → ∥ B ∥₂ → C
rec2 Cset f ∣ x ∣₂ ∣ y ∣₂ = f x y
rec2 Cset f ∣ x ∣₂ (squash₂ y z p q i j) =
Cset _ _ (cong (rec2 Cset f ∣ x ∣₂) p) (cong (rec2 Cset f ∣ x ∣₂) q) i j
rec2 Cset f (squash₂ x y p q i j) z =
Cset _ _ (cong (λ a → rec2 Cset f a z) p) (cong (λ a → rec2 Cset f a z) q) i j
-- Old version:
-- rec2 Cset f = rec (isSetΠ λ _ → Cset) λ x → rec Cset (f x)
-- lemma 6.9.1 in HoTT book
elim : {B : ∥ A ∥₂ → Type ℓ}
(Bset : (x : ∥ A ∥₂) → isSet (B x))
(f : (a : A) → B (∣ a ∣₂))
(x : ∥ A ∥₂) → B x
elim Bset f ∣ a ∣₂ = f a
elim Bset f (squash₂ x y p q i j) =
isOfHLevel→isOfHLevelDep 2 Bset _ _
(cong (elim Bset f) p) (cong (elim Bset f) q) (squash₂ x y p q) i j
elim2 : {C : ∥ A ∥₂ → ∥ B ∥₂ → Type ℓ}
(Cset : ((x : ∥ A ∥₂) (y : ∥ B ∥₂) → isSet (C x y)))
(f : (a : A) (b : B) → C ∣ a ∣₂ ∣ b ∣₂)
(x : ∥ A ∥₂) (y : ∥ B ∥₂) → C x y
elim2 Cset f ∣ x ∣₂ ∣ y ∣₂ = f x y
elim2 Cset f ∣ x ∣₂ (squash₂ y z p q i j) =
isOfHLevel→isOfHLevelDep 2 (λ a → Cset ∣ x ∣₂ a) _ _
(cong (elim2 Cset f ∣ x ∣₂) p) (cong (elim2 Cset f ∣ x ∣₂) q) (squash₂ y z p q) i j
elim2 Cset f (squash₂ x y p q i j) z =
isOfHLevel→isOfHLevelDep 2 (λ a → Cset a z) _ _
(cong (λ a → elim2 Cset f a z) p) (cong (λ a → elim2 Cset f a z) q) (squash₂ x y p q) i j
-- Old version:
-- elim2 Cset f = elim (λ _ → isSetΠ (λ _ → Cset _ _))
-- (λ a → elim (λ _ → Cset _ _) (f a))
-- TODO: generalize
elim3 : {B : (x y z : ∥ A ∥₂) → Type ℓ}
(Bset : ((x y z : ∥ A ∥₂) → isSet (B x y z)))
(g : (a b c : A) → B ∣ a ∣₂ ∣ b ∣₂ ∣ c ∣₂)
(x y z : ∥ A ∥₂) → B x y z
elim3 Bset g = elim2 (λ _ _ → isSetΠ (λ _ → Bset _ _ _))
(λ a b → elim (λ _ → Bset _ _ _) (g a b))
-- the recursor for maps into groupoids following the "HIT proof" in:
-- https://arxiv.org/abs/1507.01150
-- i.e. for any type A and groupoid B we can construct a map ∥ A ∥₂ → B
-- from a map A → B satisfying the condition
-- ∀ (a b : A) (p q : a ≡ b) → cong f p ≡ cong f q
-- TODO: prove that this is an equivalence
module rec→Gpd {A : Type ℓ} {B : Type ℓ'} (Bgpd : isGroupoid B) (f : A → B)
(congFConst : ∀ (a b : A) (p q : a ≡ b) → cong f p ≡ cong f q) where
data H : Type ℓ where
η : A → H
ε : ∀ (a b : A) → ∥ a ≡ b ∥ → η a ≡ η b -- prop. trunc. of a≡b
δ : ∀ (a b : A) (p : a ≡ b) → ε a b ∣ p ∣ ≡ cong η p
gtrunc : isGroupoid H
-- write elimination principle for H
module Helim {P : H → Type ℓ''} (Pgpd : ∀ h → isGroupoid (P h))
(η* : (a : A) → P (η a))
(ε* : ∀ (a b : A) (∣p∣ : ∥ a ≡ b ∥)
→ PathP (λ i → P (ε a b ∣p∣ i)) (η* a) (η* b))
(δ* : ∀ (a b : A) (p : a ≡ b)
→ PathP (λ i → PathP (λ j → P (δ a b p i j)) (η* a) (η* b))
(ε* a b ∣ p ∣) (cong η* p)) where
fun : (h : H) → P h
fun (η a) = η* a
fun (ε a b ∣p∣ i) = ε* a b ∣p∣ i
fun (δ a b p i j) = δ* a b p i j
fun (gtrunc x y p q α β i j k) = isOfHLevel→isOfHLevelDep 3 Pgpd
(fun x) (fun y)
(cong fun p) (cong fun q)
(cong (cong fun) α) (cong (cong fun) β)
(gtrunc x y p q α β) i j k
module Hrec {C : Type ℓ''} (Cgpd : isGroupoid C)
(η* : A → C)
(ε* : ∀ (a b : A) → ∥ a ≡ b ∥ → η* a ≡ η* b)
(δ* : ∀ (a b : A) (p : a ≡ b) → ε* a b ∣ p ∣ ≡ cong η* p) where
fun : H → C
fun (η a) = η* a
fun (ε a b ∣p∣ i) = ε* a b ∣p∣ i
fun (δ a b p i j) = δ* a b p i j
fun (gtrunc x y p q α β i j k) = Cgpd (fun x) (fun y) (cong fun p) (cong fun q)
(cong (cong fun) α) (cong (cong fun) β) i j k
module HelimProp {P : H → Type ℓ''} (Pprop : ∀ h → isProp (P h))
(η* : (a : A) → P (η a)) where
fun : ∀ h → P h
fun = Helim.fun (λ _ → isSet→isGroupoid (isProp→isSet (Pprop _))) η*
(λ a b ∣p∣ → isOfHLevel→isOfHLevelDep 1 Pprop _ _ (ε a b ∣p∣))
λ a b p → isOfHLevel→isOfHLevelDep 1
{B = λ p → PathP (λ i → P (p i)) (η* a) (η* b)}
(λ _ → isOfHLevelPathP 1 (Pprop _) _ _) _ _ (δ a b p)
-- The main trick: eliminating into hsets is easy
-- i.e. H has the universal property of set truncation...
module HelimSet {P : H → Type ℓ''} (Pset : ∀ h → isSet (P h))
(η* : ∀ a → P (η a)) where
fun : (h : H) → P h
fun = Helim.fun (λ _ → isSet→isGroupoid (Pset _)) η* ε*
λ a b p → isOfHLevel→isOfHLevelDep 1
{B = λ p → PathP (λ i → P (p i)) (η* a) (η* b)}
(λ _ → isOfHLevelPathP' 1 (Pset _) _ _) _ _ (δ a b p)
where
ε* : (a b : A) (∣p∣ : ∥ a ≡ b ∥) → PathP (λ i → P (ε a b ∣p∣ i)) (η* a) (η* b)
ε* a b = pElim (λ _ → isOfHLevelPathP' 1 (Pset _) (η* a) (η* b))
λ p → subst (λ x → PathP (λ i → P (x i)) (η* a) (η* b))
(sym (δ a b p)) (cong η* p)
-- Now we need to prove that H is a set.
-- We start with a little lemma:
localHedbergLemma : {X : Type ℓ''} (P : X → Type ℓ'')
→ (∀ x → isProp (P x))
→ ((x : X) → P x → (y : X) → P y → x ≡ y)
--------------------------------------------------
→ (x : X) → P x → (y : X) → isProp (x ≡ y)
localHedbergLemma {X = X} P Pprop P→≡ x px y = isPropRetract
(λ p → subst P p px) (λ py → sym (P→≡ x px x px) ∙ P→≡ x px y py)
isRetract (Pprop y)
where
isRetract : (p : x ≡ y) → (sym (P→≡ x px x px)) ∙ P→≡ x px y (subst P p px) ≡ p
isRetract = J (λ y' p' → (sym (P→≡ x px x px)) ∙ P→≡ x px y' (subst P p' px) ≡ p')
(subst (λ px' → sym (P→≡ x px x px) ∙ P→≡ x px x px' ≡ refl)
(sym (substRefl {B = P} px)) (lCancel (P→≡ x px x px)))
Hset : isSet H
Hset = HelimProp.fun (λ _ → isPropΠ λ _ → isPropIsProp) baseCaseLeft
where
baseCaseLeft : (a₀ : A) (y : H) → isProp (η a₀ ≡ y)
baseCaseLeft a₀ = localHedbergLemma (λ x → Q x .fst) (λ x → Q x .snd) Q→≡ _ ∣ refl ∣
where
Q : H → hProp ℓ
Q = HelimSet.fun (λ _ → isSetHProp) λ b → ∥ a₀ ≡ b ∥ , propTruncIsProp
-- Q (η b) = ∥ a ≡ b ∥
Q→≡ : (x : H) → Q x .fst → (y : H) → Q y .fst → x ≡ y
Q→≡ = HelimSet.fun (λ _ → isSetΠ3 λ _ _ _ → gtrunc _ _)
λ a p → HelimSet.fun (λ _ → isSetΠ λ _ → gtrunc _ _)
λ b q → sym (ε a₀ a p) ∙ ε a₀ b q
-- our desired function will split through H,
-- i.e. we get a function ∥ A ∥₂ → H → B
fun : ∥ A ∥₂ → B
fun = f₁ ∘ f₂
where
f₁ : H → B
f₁ = Hrec.fun Bgpd f εᶠ λ _ _ _ → refl
where
εᶠ : (a b : A) → ∥ a ≡ b ∥ → f a ≡ f b
εᶠ a b = rec→Set (Bgpd _ _) (cong f) λ p q → congFConst a b p q
-- this is the inductive step,
-- we use that maps ∥ A ∥ → B for an hset B
-- correspond to 2-Constant maps A → B (which cong f is by assumption)
f₂ : ∥ A ∥₂ → H
f₂ = rec Hset η
map : (A → B) → ∥ A ∥₂ → ∥ B ∥₂
map f = rec squash₂ λ x → ∣ f x ∣₂
setTruncUniversal : isSet B → (∥ A ∥₂ → B) ≃ (A → B)
setTruncUniversal {B = B} Bset =
isoToEquiv (iso (λ h x → h ∣ x ∣₂) (rec Bset) (λ _ → refl) rinv)
where
rinv : (f : ∥ A ∥₂ → B) → rec Bset (λ x → f ∣ x ∣₂) ≡ f
rinv f i x =
elim (λ x → isProp→isSet (Bset (rec Bset (λ x → f ∣ x ∣₂) x) (f x)))
(λ _ → refl) x i
setTruncIsSet : isSet ∥ A ∥₂
setTruncIsSet a b p q = squash₂ a b p q
setTruncIdempotentIso : isSet A → Iso ∥ A ∥₂ A
Iso.fun (setTruncIdempotentIso hA) = rec hA (idfun _)
Iso.inv (setTruncIdempotentIso hA) x = ∣ x ∣₂
Iso.rightInv (setTruncIdempotentIso hA) _ = refl
Iso.leftInv (setTruncIdempotentIso hA) = elim (λ _ → isSet→isGroupoid setTruncIsSet _ _) (λ _ → refl)
setTruncIdempotent≃ : isSet A → ∥ A ∥₂ ≃ A
setTruncIdempotent≃ {A = A} hA = isoToEquiv (setTruncIdempotentIso hA)
setTruncIdempotent : isSet A → ∥ A ∥₂ ≡ A
setTruncIdempotent hA = ua (setTruncIdempotent≃ hA)
isContr→isContrSetTrunc : isContr A → isContr (∥ A ∥₂)
isContr→isContrSetTrunc contr = ∣ fst contr ∣₂
, elim (λ _ → isOfHLevelPath 2 (setTruncIsSet) _ _)
λ a → cong ∣_∣₂ (snd contr a)
setTruncIso : Iso A B → Iso ∥ A ∥₂ ∥ B ∥₂
Iso.fun (setTruncIso is) = rec setTruncIsSet (λ x → ∣ Iso.fun is x ∣₂)
Iso.inv (setTruncIso is) = rec setTruncIsSet (λ x → ∣ Iso.inv is x ∣₂)
Iso.rightInv (setTruncIso is) =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ a → cong ∣_∣₂ (Iso.rightInv is a)
Iso.leftInv (setTruncIso is) =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ a → cong ∣_∣₂ (Iso.leftInv is a)
setSigmaIso : {B : A → Type ℓ} → Iso ∥ Σ A B ∥₂ ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂
setSigmaIso {A = A} {B = B} = iso fun funinv sect retr
where
{- writing it out explicitly to avoid yellow highlighting -}
fun : ∥ Σ A B ∥₂ → ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂
fun = rec setTruncIsSet λ {(a , p) → ∣ a , ∣ p ∣₂ ∣₂}
funinv : ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂ → ∥ Σ A B ∥₂
funinv = rec setTruncIsSet (λ {(a , p) → rec setTruncIsSet (λ p → ∣ a , p ∣₂) p})
sect : section fun funinv
sect = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ { (a , p) → elim {B = λ p → fun (funinv ∣ a , p ∣₂) ≡ ∣ a , p ∣₂}
(λ p → isOfHLevelPath 2 setTruncIsSet _ _) (λ _ → refl) p }
retr : retract fun funinv
retr = elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ { _ → refl }
sigmaElim : {B : ∥ A ∥₂ → Type ℓ} {C : Σ ∥ A ∥₂ B → Type ℓ'}
(Bset : (x : Σ ∥ A ∥₂ B) → isSet (C x))
(g : (a : A) (b : B ∣ a ∣₂) → C (∣ a ∣₂ , b))
(x : Σ ∥ A ∥₂ B) → C x
sigmaElim {B = B} {C = C} set g (x , y) =
elim {B = λ x → (y : B x) → C (x , y)} (λ _ → isSetΠ λ _ → set _) g x y
sigmaProdElim : {C : ∥ A ∥₂ × ∥ B ∥₂ → Type ℓ} {D : Σ (∥ A ∥₂ × ∥ B ∥₂) C → Type ℓ'}
(Bset : (x : Σ (∥ A ∥₂ × ∥ B ∥₂) C) → isSet (D x))
(g : (a : A) (b : B) (c : C (∣ a ∣₂ , ∣ b ∣₂)) → D ((∣ a ∣₂ , ∣ b ∣₂) , c))
(x : Σ (∥ A ∥₂ × ∥ B ∥₂) C) → D x
sigmaProdElim {B = B} {C = C} {D = D} set g ((x , y) , c) =
elim {B = λ x → (y : ∥ B ∥₂) (c : C (x , y)) → D ((x , y) , c)}
(λ _ → isSetΠ λ _ → isSetΠ λ _ → set _)
(λ x → elim (λ _ → isSetΠ λ _ → set _) (g x))
x y c
prodElim : {C : ∥ A ∥₂ × ∥ B ∥₂ → Type ℓ}
→ ((x : ∥ A ∥₂ × ∥ B ∥₂) → isSet (C x))
→ ((a : A) (b : B) → C (∣ a ∣₂ , ∣ b ∣₂))
→ (x : ∥ A ∥₂ × ∥ B ∥₂) → C x
prodElim setC f (a , b) = elim2 (λ x y → setC (x , y)) f a b
prodRec : {C : Type ℓ} → isSet C → (A → B → C) → ∥ A ∥₂ × ∥ B ∥₂ → C
prodRec setC f (a , b) = rec2 setC f a b
prodElim2 : {E : (∥ A ∥₂ × ∥ B ∥₂) → (∥ C ∥₂ × ∥ D ∥₂) → Type ℓ}
→ ((x : ∥ A ∥₂ × ∥ B ∥₂) (y : ∥ C ∥₂ × ∥ D ∥₂) → isSet (E x y))
→ ((a : A) (b : B) (c : C) (d : D) → E (∣ a ∣₂ , ∣ b ∣₂) (∣ c ∣₂ , ∣ d ∣₂))
→ ((x : ∥ A ∥₂ × ∥ B ∥₂) (y : ∥ C ∥₂ × ∥ D ∥₂) → (E x y))
prodElim2 isset f = prodElim (λ _ → isSetΠ λ _ → isset _ _)
λ a b → prodElim (λ _ → isset _ _)
λ c d → f a b c d
setTruncOfProdIso : Iso ∥ A × B ∥₂ (∥ A ∥₂ × ∥ B ∥₂)
Iso.fun setTruncOfProdIso = rec (isSet× setTruncIsSet setTruncIsSet) λ { (a , b) → ∣ a ∣₂ , ∣ b ∣₂ }
Iso.inv setTruncOfProdIso = prodRec setTruncIsSet λ a b → ∣ a , b ∣₂
Iso.rightInv setTruncOfProdIso =
prodElim (λ _ → isOfHLevelPath 2 (isSet× setTruncIsSet setTruncIsSet) _ _) λ _ _ → refl
Iso.leftInv setTruncOfProdIso =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _) λ {(a , b) → refl}
IsoSetTruncateSndΣ : {A : Type ℓ} {B : A → Type ℓ'} → Iso ∥ Σ A B ∥₂ ∥ Σ A (λ x → ∥ B x ∥₂) ∥₂
Iso.fun IsoSetTruncateSndΣ = map λ a → (fst a) , ∣ snd a ∣₂
Iso.inv IsoSetTruncateSndΣ = rec setTruncIsSet (uncurry λ x → map λ b → x , b)
Iso.rightInv IsoSetTruncateSndΣ =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
(uncurry λ a → elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ _ → refl)
Iso.leftInv IsoSetTruncateSndΣ =
elim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ _ → refl
PathIdTrunc₀Iso : {a b : A} → Iso (∣ a ∣₂ ≡ ∣ b ∣₂) ∥ a ≡ b ∥
Iso.fun (PathIdTrunc₀Iso {b = b}) p =
transport (λ i → rec {B = TypeOfHLevel _ 1} (isOfHLevelTypeOfHLevel 1)
(λ a → ∥ a ≡ b ∥ , squash) (p (~ i)) .fst)
∣ refl ∣
Iso.inv PathIdTrunc₀Iso = pRec (squash₂ _ _) (cong ∣_∣₂)
Iso.rightInv PathIdTrunc₀Iso _ = squash _ _
Iso.leftInv PathIdTrunc₀Iso _ = squash₂ _ _ _ _
| {
"alphanum_fraction": 0.4920115925,
"avg_line_length": 42.053125,
"ext": "agda",
"hexsha": "b6478557d14a3bd39c666ba3fc7099f7d68daf13",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/HITs/SetTruncation/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/HITs/SetTruncation/Properties.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/HITs/SetTruncation/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5904,
"size": 13457
} |
{-
Finite Structures over Finite Set
In short, the type of structures should be finite set itself.
This file contains:
- Definition and properties of finite sets equipped with finite structures;
- The type of finitely-structured finite sets is Rijke finite,
so that we can count their number up to equivalence/isomorphism.
-}
{-# OPTIONS --safe #-}
module Cubical.Data.FinType.FiniteStructure where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv renaming (_∙ₑ_ to _⋆_)
open import Cubical.HITs.PropositionalTruncation as Prop
open import Cubical.HITs.SetTruncation as Set
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.Data.FinSet
open import Cubical.Data.FinSet.Induction
open import Cubical.Data.FinSet.Cardinality
open import Cubical.Data.FinType
open import Cubical.Data.FinType.Sigma
private
variable
ℓ ℓ' : Level
n : ℕ
S : FinSet ℓ → FinSet ℓ'
-- type of finite sets with finite structure
FinSetWithStr : (S : FinSet ℓ → FinSet ℓ') → Type (ℓ-max (ℓ-suc ℓ) ℓ')
FinSetWithStr {ℓ = ℓ} S = Σ[ X ∈ FinSet ℓ ] S X .fst
-- type of finite sets with a fixed cardinal
FinSetOfCard : (ℓ : Level) (n : ℕ) → Type (ℓ-suc ℓ)
FinSetOfCard ℓ n = Σ[ X ∈ FinSet ℓ ] (card X ≡ n)
FinSetWithStrOfCard : (S : FinSet ℓ → FinSet ℓ') (n : ℕ) → Type (ℓ-max (ℓ-suc ℓ) ℓ')
FinSetWithStrOfCard {ℓ = ℓ} S n = Σ[ X ∈ FinSetOfCard ℓ n ] S (X .fst) .fst
FinSetOfCard≡ : (X Y : FinSetOfCard ℓ n) → (X .fst ≡ Y .fst) ≃ (X ≡ Y)
FinSetOfCard≡ _ _ = Σ≡PropEquiv (λ _ → isSetℕ _ _)
open Iso
∥FinSetOfCard∥₂≡ : (X Y : FinSetOfCard ℓ n) → ∥ X .fst ≡ Y .fst ∥ → ∣ X ∣₂ ≡ ∣ Y ∣₂
∥FinSetOfCard∥₂≡ _ _ =
Prop.rec (squash₂ _ _) (λ p → PathIdTrunc₀Iso .inv ∣ FinSetOfCard≡ _ _ .fst p ∣)
isPathConnectedFinSetOfCard : isContr ∥ FinSetOfCard ℓ n ∥₂
isPathConnectedFinSetOfCard {n = n} .fst = ∣ 𝔽in n , card𝔽in n ∣₂
isPathConnectedFinSetOfCard {n = n} .snd =
Set.elim (λ _ → isProp→isSet (squash₂ _ _)) (λ (X , p) → sym (∥FinSetOfCard∥₂≡ _ _ (card≡n p)))
isFinTypeFinSetOfCard : isFinType 1 (FinSetOfCard ℓ n)
isFinTypeFinSetOfCard .fst = isPathConnected→isFinType0 isPathConnectedFinSetOfCard
isFinTypeFinSetOfCard .snd X Y =
isFinSet→isFinType 0 (EquivPresIsFinSet (FinSet≡ _ _ ⋆ FinSetOfCard≡ _ _) (isFinSetType≡Eff (X .fst) (Y .fst)))
-- the type of finitely-structured finite sets is Rijke finite
-- in particular, we can count their number up to equivalence
isFinTypeFinSetWithStrOfCard :
(S : FinSet ℓ → FinSet ℓ') (n : ℕ)
→ isFinType 0 (FinSetWithStrOfCard S n)
isFinTypeFinSetWithStrOfCard S n =
isFinTypeΣ {n = 0} (_ , isFinTypeFinSetOfCard) (λ X → _ , isFinSet→isFinType 0 (S (X .fst) .snd))
| {
"alphanum_fraction": 0.7130242826,
"avg_line_length": 34.8461538462,
"ext": "agda",
"hexsha": "b34df802cd7f01efccbc37786fdc6bc6a43647e6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/Data/FinType/FiniteStructure.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/Data/FinType/FiniteStructure.agda",
"max_line_length": 113,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/Data/FinType/FiniteStructure.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1014,
"size": 2718
} |
open import List
open import Nat
open import Prelude
open import contexts
open import core
module statics-core where
open core public
-- zippered form of types
data ztyp : Set where
▹_◃ : htyp → ztyp
_==>₁_ : ztyp → htyp → ztyp
_==>₂_ : htyp → ztyp → ztyp
_⊕₁_ : ztyp → htyp → ztyp
_⊕₂_ : htyp → ztyp → ztyp
_⊠₁_ : ztyp → htyp → ztyp
_⊠₂_ : htyp → ztyp → ztyp
-- zippered form of expressions
data zexp : Set where
▹_◃ : hexp → zexp
_·:₁_ : zexp → htyp → zexp
_·:₂_ : hexp → ztyp → zexp
·λ : Nat → zexp → zexp
·λ_·[_]₁_ : Nat → ztyp → hexp → zexp
·λ_·[_]₂_ : Nat → htyp → zexp → zexp
_∘₁_ : zexp → hexp → zexp
_∘₂_ : hexp → zexp → zexp
_·+₁_ : zexp → hexp → zexp
_·+₂_ : hexp → zexp → zexp
⦇⌜_⌟⦈[_] : zexp → Nat → zexp
inl : zexp → zexp
inr : zexp → zexp
case₁ : zexp → Nat → hexp → Nat → hexp → zexp
case₂ : hexp → Nat → zexp → Nat → hexp → zexp
case₃ : hexp → Nat → hexp → Nat → zexp → zexp
⟨_,_⟩₁ : zexp → hexp → zexp
⟨_,_⟩₂ : hexp → zexp → zexp
fst : zexp → zexp
snd : zexp → zexp
-- erasure of cursor for types and expressions, judgementally. see
-- jugemental-erase.agda for an argument that this defines an isomorphic
-- object to the direct metafunction provided in the text of the paper
data erase-t : ztyp → htyp → Set where
ETTop : ∀{t} →
erase-t (▹ t ◃) t
ETArrL : ∀{t1 t1' t2} →
erase-t t1 t1' →
erase-t (t1 ==>₁ t2) (t1' ==> t2)
ETArrR : ∀{t1 t2 t2'} →
erase-t t2 t2' →
erase-t (t1 ==>₂ t2) (t1 ==> t2')
ETPlusL : ∀{t1 t1' t2} →
erase-t t1 t1' →
erase-t (t1 ⊕₁ t2) (t1' ⊕ t2)
ETPlusR : ∀{t1 t2 t2'} →
erase-t t2 t2' →
erase-t (t1 ⊕₂ t2) (t1 ⊕ t2')
ETProdL : ∀{t1 t1' t2} →
erase-t t1 t1' →
erase-t (t1 ⊠₁ t2) (t1' ⊠ t2)
ETProdR : ∀{t1 t2 t2'} →
erase-t t2 t2' →
erase-t (t1 ⊠₂ t2) (t1 ⊠ t2')
data erase-e : zexp → hexp → Set where
EETop : ∀{x} →
erase-e (▹ x ◃) x
EEPlusL : ∀{e1 e1' e2} →
erase-e e1 e1' →
erase-e (e1 ·+₁ e2) (e1' ·+ e2)
EEPlusR : ∀{e1 e2 e2'} →
erase-e e2 e2' →
erase-e (e1 ·+₂ e2) (e1 ·+ e2')
EEAscL : ∀{e e' t} →
erase-e e e' →
erase-e (e ·:₁ t) (e' ·: t)
EEAscR : ∀{e t t'} →
erase-t t t' →
erase-e (e ·:₂ t) (e ·: t')
EELam : ∀{x e e'} →
erase-e e e' →
erase-e (·λ x e) (·λ x e')
EEHalfLamL : ∀{x e t t'} →
erase-t t t' →
erase-e (·λ x ·[ t ]₁ e) (·λ x ·[ t' ] e)
EEHalfLamR : ∀{x e e' t} →
erase-e e e' →
erase-e (·λ x ·[ t ]₂ e) (·λ x ·[ t ] e')
EEApL : ∀{e1 e1' e2} →
erase-e e1 e1' →
erase-e (e1 ∘₁ e2) (e1' ∘ e2)
EEApR : ∀{e1 e2 e2'} →
erase-e e2 e2' →
erase-e (e1 ∘₂ e2) (e1 ∘ e2')
EEInl : ∀{e e'} →
erase-e e e' →
erase-e (inl e) (inl e')
EEInr : ∀{e e'} →
erase-e e e' →
erase-e (inr e) (inr e')
EECase1 : ∀{e e' x e1 y e2} →
erase-e e e' →
erase-e (case₁ e x e1 y e2) (case e' x e1 y e2)
EECase2 : ∀{e x e1 e1' y e2} →
erase-e e1 e1' →
erase-e (case₂ e x e1 y e2) (case e x e1' y e2)
EECase3 : ∀{e x e1 y e2 e2'} →
erase-e e2 e2' →
erase-e (case₃ e x e1 y e2) (case e x e1 y e2')
EEPairL : ∀{e1 e1' e2} →
erase-e e1 e1' →
erase-e ⟨ e1 , e2 ⟩₁ ⟨ e1' , e2 ⟩
EEPairR : ∀{e1 e2 e2'} →
erase-e e2 e2' →
erase-e ⟨ e1 , e2 ⟩₂ ⟨ e1 , e2' ⟩
EEFst : ∀{e e'} →
erase-e e e' →
erase-e (fst e) (fst e')
EESnd : ∀{e e'} →
erase-e e e' →
erase-e (snd e) (snd e')
EENEHole : ∀{e e' u} →
erase-e e e' →
erase-e ⦇⌜ e ⌟⦈[ u ] ⦇⌜ e' ⌟⦈[ u ]
-- the three grammars that define actions
data direction : Set where
child : Nat → direction
parent : direction
-- in contrast to the POPL 2017 hazelnut paper, we include named holes in static
-- semantics since they are required by the dynamic semantics. a given action
-- may introduce a different number of holes depending on the context it is
-- applied in, so the action must always supply enough names for every location
-- in the term where a hole could occur. moreover, care must be taken to have
-- the same hole names always correspond to the same hole locations. for example,
-- when we show that each derivation has an equivalently subsumption-minimal
-- derivation, this is needed to guarentee the same action (which includes hole names)
-- can be used in the minimal derivation.
data shape : Set where
arrow : shape
num : shape
asc : shape
var : Nat → Nat → shape
lam : Nat → Nat → Nat → shape
ap : Nat → Nat → shape
numlit : Nat → Nat → shape
plus : Nat → Nat → shape
nehole : Nat → shape
sum : shape
inl : Nat → Nat → shape
inr : Nat → Nat → shape
case : Nat → Nat → Nat → Nat → Nat → shape
prod : shape
pair : Nat → Nat → shape
fst : Nat → shape
snd : Nat → shape
data action : Set where
move : direction → action
construct : shape → action
del : Nat → action
finish : action
-- type actions
data _+_+>_ : (t : ztyp) → (α : action) → (t' : ztyp) → Set where
TMArrChild1 : {t1 t2 : htyp} →
▹ t1 ==> t2 ◃ + move (child 1) +> (▹ t1 ◃ ==>₁ t2)
TMArrChild2 : {t1 t2 : htyp} →
▹ t1 ==> t2 ◃ + move (child 2) +> (t1 ==>₂ ▹ t2 ◃)
TMArrParent1 : {t1 t2 : htyp} →
(▹ t1 ◃ ==>₁ t2) + move parent +> ▹ t1 ==> t2 ◃
TMArrParent2 : {t1 t2 : htyp} →
(t1 ==>₂ ▹ t2 ◃) + move parent +> ▹ t1 ==> t2 ◃
TMPlusChild1 : {t1 t2 : htyp} →
▹ t1 ⊕ t2 ◃ + move (child 1) +> (▹ t1 ◃ ⊕₁ t2)
TMPlusChild2 : {t1 t2 : htyp} →
▹ t1 ⊕ t2 ◃ + move (child 2) +> (t1 ⊕₂ ▹ t2 ◃)
TMPlusParent1 : {t1 t2 : htyp} →
(▹ t1 ◃ ⊕₁ t2) + move parent +> ▹ t1 ⊕ t2 ◃
TMPlusParent2 : {t1 t2 : htyp} →
(t1 ⊕₂ ▹ t2 ◃) + move parent +> ▹ t1 ⊕ t2 ◃
TMProdChild1 : {t1 t2 : htyp} →
▹ t1 ⊠ t2 ◃ + move (child 1) +> (▹ t1 ◃ ⊠₁ t2)
TMProdChild2 : {t1 t2 : htyp} →
▹ t1 ⊠ t2 ◃ + move (child 2) +> (t1 ⊠₂ ▹ t2 ◃)
TMProdParent1 : {t1 t2 : htyp} →
(▹ t1 ◃ ⊠₁ t2) + move parent +> ▹ t1 ⊠ t2 ◃
TMProdParent2 : {t1 t2 : htyp} →
(t1 ⊠₂ ▹ t2 ◃) + move parent +> ▹ t1 ⊠ t2 ◃
TMDel : {t : htyp} {u : Nat} →
(▹ t ◃) + del u +> (▹ ⦇-⦈ ◃)
TMConArrow : {t : htyp} →
(▹ t ◃) + construct arrow +> (t ==>₂ ▹ ⦇-⦈ ◃)
TMConPlus : {t : htyp} →
(▹ t ◃) + construct sum +> (t ⊕₂ ▹ ⦇-⦈ ◃)
TMConProd : {t : htyp} →
(▹ t ◃) + construct prod +> (t ⊠₂ ▹ ⦇-⦈ ◃)
TMConNum : (▹ ⦇-⦈ ◃) + construct num +> (▹ num ◃)
TMArrZip1 : {t1 t1' : ztyp} {t2 : htyp} {α : action} →
(t1 + α +> t1') →
((t1 ==>₁ t2) + α +> (t1' ==>₁ t2))
TMArrZip2 : {t2 t2' : ztyp} {t1 : htyp} {α : action} →
(t2 + α +> t2') →
((t1 ==>₂ t2) + α +> (t1 ==>₂ t2'))
TMPlusZip1 : {t1 t1' : ztyp} {t2 : htyp} {α : action} →
(t1 + α +> t1') →
((t1 ⊕₁ t2) + α +> (t1' ⊕₁ t2))
TMPlusZip2 : {t2 t2' : ztyp} {t1 : htyp} {α : action} →
(t2 + α +> t2') →
((t1 ⊕₂ t2) + α +> (t1 ⊕₂ t2'))
TMProdZip1 : {t1 t1' : ztyp} {t2 : htyp} {α : action} →
(t1 + α +> t1') →
((t1 ⊠₁ t2) + α +> (t1' ⊠₁ t2))
TMProdZip2 : {t2 t2' : ztyp} {t1 : htyp} {α : action} →
(t2 + α +> t2') →
((t1 ⊠₂ t2) + α +> (t1 ⊠₂ t2'))
-- expression movement
data _+_+>e_ : (e : zexp) → (α : action) → (e' : zexp) → Set where
EMPlusChild1 : {e1 e2 : hexp} →
(▹ e1 ·+ e2 ◃) + move (child 1) +>e (▹ e1 ◃ ·+₁ e2)
EMPlusChild2 : {e1 e2 : hexp} →
(▹ e1 ·+ e2 ◃) + move (child 2) +>e (e1 ·+₂ ▹ e2 ◃)
EMPlusParent1 : {e1 e2 : hexp} →
(▹ e1 ◃ ·+₁ e2) + move parent +>e (▹ e1 ·+ e2 ◃)
EMPlusParent2 : {e1 e2 : hexp} →
(e1 ·+₂ ▹ e2 ◃) + move parent +>e (▹ e1 ·+ e2 ◃)
EMAscChild1 : {e : hexp} {t : htyp} →
(▹ e ·: t ◃) + move (child 1) +>e (▹ e ◃ ·:₁ t)
EMAscChild2 : {e : hexp} {t : htyp} →
(▹ e ·: t ◃) + move (child 2) +>e (e ·:₂ ▹ t ◃)
EMAscParent1 : {e : hexp} {t : htyp} →
(▹ e ◃ ·:₁ t) + move parent +>e (▹ e ·: t ◃)
EMAscParent2 : {e : hexp} {t : htyp} →
(e ·:₂ ▹ t ◃) + move parent +>e (▹ e ·: t ◃)
EMLamChild1 : {e : hexp} {x : Nat} →
▹ (·λ x e) ◃ + move (child 1) +>e ·λ x (▹ e ◃)
EMLamParent : {e : hexp} {x : Nat} →
·λ x (▹ e ◃) + move parent +>e ▹ (·λ x e) ◃
EMHalfLamChild1 : {e : hexp} {t : htyp} {x : Nat} →
▹ (·λ x ·[ t ] e) ◃ + move (child 1) +>e (·λ x ·[ ▹ t ◃ ]₁ e)
EMHalfLamChild2 : {e : hexp} {t : htyp} {x : Nat} →
▹ (·λ x ·[ t ] e) ◃ + move (child 2) +>e (·λ x ·[ t ]₂ ▹ e ◃)
EMHalfLamParent1 : {e : hexp} {t : htyp} {x : Nat} →
(·λ x ·[ ▹ t ◃ ]₁ e) + move parent +>e ▹ (·λ x ·[ t ] e) ◃
EMHalfLamParent2 : {e : hexp} {t : htyp} {x : Nat} →
(·λ x ·[ t ]₂ ▹ e ◃) + move parent +>e ▹ (·λ x ·[ t ] e) ◃
EMApChild1 : {e1 e2 : hexp} →
(▹ e1 ∘ e2 ◃) + move (child 1)+>e (▹ e1 ◃ ∘₁ e2)
EMApChild2 : {e1 e2 : hexp} →
(▹ e1 ∘ e2 ◃) + move (child 2) +>e (e1 ∘₂ ▹ e2 ◃)
EMApParent1 : {e1 e2 : hexp} →
(▹ e1 ◃ ∘₁ e2) + move parent +>e (▹ e1 ∘ e2 ◃)
EMApParent2 : {e1 e2 : hexp} →
(e1 ∘₂ ▹ e2 ◃) + move parent +>e (▹ e1 ∘ e2 ◃)
EMInlChild1 : {e : hexp} →
▹ inl e ◃ + move (child 1) +>e inl ▹ e ◃
EMInlParent : {e : hexp} →
inl ▹ e ◃ + move parent +>e ▹ inl e ◃
EMInrChild1 : {e : hexp} →
▹ inr e ◃ + move (child 1) +>e inr ▹ e ◃
EMInrParent : {e : hexp} →
inr ▹ e ◃ + move parent +>e ▹ inr e ◃
EMCaseParent1 : {e e1 e2 : hexp} {x y : Nat} →
case₁ ▹ e ◃ x e1 y e2 + move parent +>e ▹ case e x e1 y e2 ◃
EMCaseParent2 : {e e1 e2 : hexp} {x y : Nat} →
case₂ e x ▹ e1 ◃ y e2 + move parent +>e ▹ case e x e1 y e2 ◃
EMCaseParent3 : {e e1 e2 : hexp} {x y : Nat} →
case₃ e x e1 y ▹ e2 ◃ + move parent +>e ▹ case e x e1 y e2 ◃
EMCaseChild1 : {e e1 e2 : hexp} {x y : Nat} →
▹ case e x e1 y e2 ◃ + move (child 1) +>e case₁ ▹ e ◃ x e1 y e2
EMCaseChild2 : {e e1 e2 : hexp} {x y : Nat} →
▹ case e x e1 y e2 ◃ + move (child 2) +>e case₂ e x ▹ e1 ◃ y e2
EMCaseChild3 : {e e1 e2 : hexp} {x y : Nat} →
▹ case e x e1 y e2 ◃ + move (child 3) +>e case₃ e x e1 y ▹ e2 ◃
EMPairChild1 : {e1 e2 : hexp} →
(▹ ⟨ e1 , e2 ⟩ ◃) + move (child 1)+>e ⟨ ▹ e1 ◃ , e2 ⟩₁
EMPairChild2 : {e1 e2 : hexp} →
(▹ ⟨ e1 , e2 ⟩ ◃) + move (child 2) +>e ⟨ e1 , ▹ e2 ◃ ⟩₂
EMPairParent1 : {e1 e2 : hexp} →
( ⟨ ▹ e1 ◃ , e2 ⟩₁ ) + move parent +>e (▹ ⟨ e1 , e2 ⟩ ◃)
EMPairParent2 : {e1 e2 : hexp} →
( ⟨ e1 , ▹ e2 ◃ ⟩₂ ) + move parent +>e (▹ ⟨ e1 , e2 ⟩ ◃)
EMFstChild1 : {e : hexp} →
▹ fst e ◃ + move (child 1) +>e fst ▹ e ◃
EMFstParent : {e : hexp} →
fst ▹ e ◃ + move parent +>e ▹ fst e ◃
EMSndChild1 : {e : hexp} →
▹ snd e ◃ + move (child 1) +>e snd ▹ e ◃
EMSndParent : {e : hexp} →
snd ▹ e ◃ + move parent +>e ▹ snd e ◃
EMNEHoleChild1 : {e : hexp} {u : Nat} →
(▹ ⦇⌜ e ⌟⦈[ u ] ◃) + move (child 1) +>e ⦇⌜ ▹ e ◃ ⌟⦈[ u ]
EMNEHoleParent : {e : hexp} {u : Nat} →
⦇⌜ ▹ e ◃ ⌟⦈[ u ] + move parent +>e (▹ ⦇⌜ e ⌟⦈[ u ] ◃)
mutual
-- synthetic action expressions.
data _⊢_=>_~_~>_=>_ : (Γ : tctx) → (e1 : zexp) → (t1 : htyp) → (α : action) →
(e2 : zexp) → (t2 : htyp) → Set where
SAFinish : {Γ : tctx} {e : hexp} {t : htyp} {u : Nat} →
Γ ⊢ e => t →
Γ ⊢ ▹ ⦇⌜ e ⌟⦈[ u ] ◃ => ⦇-⦈ ~ finish ~> ▹ e ◃ => t
SAMove : {δ : direction} {e e' : zexp} {Γ : tctx} {t : htyp} →
e + move δ +>e e' →
Γ ⊢ e => t ~ move δ ~> e' => t
SADel : {Γ : tctx} {e : hexp} {t : htyp} {u : Nat} →
Γ ⊢ ▹ e ◃ => t ~ del u ~> ▹ ⦇-⦈[ u ] ◃ => ⦇-⦈
SAConNumlit : {Γ : tctx} {n : Nat} {u u1 : Nat} →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ => ⦇-⦈ ~ construct (numlit n u1) ~> ▹ N n ◃ => num
SAConPlus1 : {Γ : tctx} {e : hexp} {t : htyp} {u1 u2 : Nat} →
t ~ num →
Γ ⊢ ▹ e ◃ => t ~ construct (plus u1 u2) ~> e ·+₂ ▹ ⦇-⦈[ u2 ] ◃ => num
SAConPlus2 : {Γ : tctx} {e : hexp} {t : htyp} {u1 u2 : Nat} →
t ~̸ num →
Γ ⊢ ▹ e ◃ => t ~ construct (plus u1 u2) ~>
⦇⌜ e ⌟⦈[ u1 ] ·+₂ ▹ ⦇-⦈[ u2 ] ◃ => num
SAConAsc : {Γ : tctx} {e : hexp} {t : htyp} →
Γ ⊢ ▹ e ◃ => t ~ construct asc ~> (e ·:₂ ▹ t ◃ ) => t
SAConVar : {Γ : tctx} {x : Nat} {t : htyp} {u u1 : Nat} →
(x , t) ∈ Γ →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ => ⦇-⦈ ~ construct (var x u1) ~> ▹ X x ◃ => t
SAConLam : {Γ : tctx} {x : Nat} {u u1 u2 : Nat} →
x # Γ →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ => ⦇-⦈ ~ construct (lam x u1 u2) ~>
(·λ x ·[ ▹ ⦇-⦈ ◃ ]₁ ⦇-⦈[ u2 ]) => (⦇-⦈ ==> ⦇-⦈)
SAConApArr : {Γ : tctx} {t t1 t2 : htyp} {e : hexp} {u1 u2 : Nat} →
t ▸arr (t1 ==> t2) →
Γ ⊢ ▹ e ◃ => t ~ construct (ap u1 u2) ~>
e ∘₂ ▹ ⦇-⦈[ u2 ] ◃ => t2
SAConApOtw : {Γ : tctx} {t : htyp} {e : hexp} {u1 u2 : Nat} →
t ~̸ (⦇-⦈ ==> ⦇-⦈) →
Γ ⊢ ▹ e ◃ => t ~ construct (ap u1 u2) ~>
⦇⌜ e ⌟⦈[ u1 ] ∘₂ ▹ ⦇-⦈[ u2 ] ◃ => ⦇-⦈
SAConInl : {Γ : tctx} {t : htyp} {u u1 u2 : Nat} →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ => t ~ construct (inl u1 u2) ~>
inl (⦇-⦈[ u2 ]) ·:₂ (▹ ⦇-⦈ ◃ ⊕₁ ⦇-⦈) => (⦇-⦈ ⊕ ⦇-⦈)
SAConInr : {Γ : tctx} {t : htyp} {u u1 u2 : Nat} →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ => t ~ construct (inr u1 u2) ~>
inr (⦇-⦈[ u2 ]) ·:₂ (⦇-⦈ ⊕₂ ▹ ⦇-⦈ ◃) => (⦇-⦈ ⊕ ⦇-⦈)
SAConCase1 : {Γ : tctx} {x y : Nat} {t t1 t2 : htyp} {e : hexp} {u1 u2 u3 : Nat} →
x # Γ →
y # Γ →
t ▸sum (t1 ⊕ t2) →
Γ ⊢ ▹ e ◃ => t ~ construct (case x y u1 u2 u3) ~>
(case₂ e x (▹ ⦇-⦈[ u2 ] ◃) y ⦇-⦈[ u3 ]) ·:₁ ⦇-⦈ => ⦇-⦈
SAConCase2 : {Γ : tctx} {x y : Nat} {t : htyp} {e : hexp} → {u1 u2 u3 : Nat} →
x # Γ →
y # Γ →
t ~̸ (⦇-⦈ ⊕ ⦇-⦈) →
Γ ⊢ ▹ e ◃ => t ~ construct (case x y u1 u2 u3) ~>
(case₁ (⦇⌜ ▹ e ◃ ⌟⦈[ u1 ]) x ⦇-⦈[ u2 ] y ⦇-⦈[ u3 ]) ·:₁ ⦇-⦈ => ⦇-⦈
SAConPair : {Γ : tctx} {t : htyp} {u u1 u2 : Nat} →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ => t ~ construct (pair u1 u2) ~>
⟨ ▹ ⦇-⦈[ u1 ] ◃ , ⦇-⦈[ u2 ] ⟩₁ => (⦇-⦈ ⊠ ⦇-⦈)
SAConFst1 : {Γ : tctx} {t t1 t2 : htyp} {e : hexp} {u : Nat} →
t ▸prod (t1 ⊠ t2) →
Γ ⊢ ▹ e ◃ => t ~ construct (fst u) ~> ▹ fst e ◃ => t1
SAConFst2 : {Γ : tctx} {t : htyp} {e : hexp} {u : Nat} →
t ~̸ (⦇-⦈ ⊠ ⦇-⦈) →
Γ ⊢ ▹ e ◃ => t ~ construct (fst u) ~> fst ⦇⌜ ▹ e ◃ ⌟⦈[ u ] => ⦇-⦈
SAConSnd1 : {Γ : tctx} {t t1 t2 : htyp} {e : hexp} {u : Nat} →
t ▸prod (t1 ⊠ t2) →
Γ ⊢ ▹ e ◃ => t ~ construct (snd u) ~> ▹ snd e ◃ => t2
SAConSnd2 : {Γ : tctx} {t : htyp} {e : hexp} {u : Nat} →
t ~̸ (⦇-⦈ ⊠ ⦇-⦈) →
Γ ⊢ ▹ e ◃ => t ~ construct (snd u) ~> snd ⦇⌜ ▹ e ◃ ⌟⦈[ u ] => ⦇-⦈
SAConNEHole : {Γ : tctx} {e : hexp} {t : htyp} {u : Nat} →
Γ ⊢ ▹ e ◃ => t ~ construct (nehole u) ~> ⦇⌜ ▹ e ◃ ⌟⦈[ u ] => ⦇-⦈
SAZipPlus1 : {Γ : tctx} {e : hexp} {eh eh' : zexp} {α : action} →
Γ ⊢ eh ~ α ~> eh' ⇐ num →
Γ ⊢ (eh ·+₁ e) => num ~ α ~> (eh' ·+₁ e) => num
SAZipPlus2 : {Γ : tctx} {e : hexp} {eh eh' : zexp} {α : action} →
Γ ⊢ eh ~ α ~> eh' ⇐ num →
Γ ⊢ (e ·+₂ eh) => num ~ α ~> (e ·+₂ eh') => num
SAZipAsc1 : {Γ : tctx} {e e' : zexp} {α : action} {t : htyp} →
Γ ⊢ e ~ α ~> e' ⇐ t →
Γ ⊢ (e ·:₁ t) => t ~ α ~> (e' ·:₁ t) => t
SAZipAsc2 : {Γ : tctx} {e : hexp} {α : action} {t t' : ztyp} {t◆ t'◆ : htyp} →
t + α +> t' →
erase-t t' t'◆ →
erase-t t t◆ →
Γ ⊢ e <= t'◆ →
Γ ⊢ (e ·:₂ t) => t◆ ~ α ~> (e ·:₂ t') => t'◆
SAZipLam1 : {Γ : tctx} {e : hexp} {t1 t1' : ztyp} {t1◆ t1'◆ t2 t2' : htyp} {x : Nat}
{α : action} →
x # Γ →
erase-t t1 t1◆ →
erase-t t1' t1'◆ →
t1 + α +> t1' →
(Γ ,, (x , t1◆)) ⊢ e => t2 →
(Γ ,, (x , t1'◆)) ⊢ e => t2' →
Γ ⊢ (·λ x ·[ t1 ]₁ e) => (t1◆ ==> t2) ~ α ~>
(·λ x ·[ t1' ]₁ e) => (t1'◆ ==> t2')
SAZipLam2 : {Γ : tctx} {e e' : zexp} {e◆ : hexp} {t1 t2 t2' : htyp} {x : Nat}
{α : action }→
x # Γ →
erase-e e e◆ →
(Γ ,, (x , t1)) ⊢ e◆ => t2 →
(Γ ,, (x , t1)) ⊢ e => t2 ~ α ~> e' => t2' →
Γ ⊢ (·λ x ·[ t1 ]₂ e) => (t1 ==> t2) ~ α ~>
(·λ x ·[ t1 ]₂ e') => (t1 ==> t2')
SAZipApArr : {Γ : tctx} {t t1 t2 t3 t4 : htyp} {α : action}
{eh eh' : zexp} {e eh◆ : hexp} →
t ▸arr (t3 ==> t4) →
erase-e eh eh◆ →
Γ ⊢ (eh◆) => t2 →
Γ ⊢ eh => t2 ~ α ~> eh' => t →
Γ ⊢ e <= t3 →
Γ ⊢ (eh ∘₁ e) => t1 ~ α ~> (eh' ∘₁ e) => t4
SAZipApAna : {Γ : tctx} {t' t2 t : htyp} {e : hexp}
{eh eh' : zexp} {α : action} →
t' ▸arr (t2 ==> t) →
Γ ⊢ e => t' →
Γ ⊢ eh ~ α ~> eh' ⇐ t2 →
Γ ⊢ (e ∘₂ eh) => t ~ α ~> (e ∘₂ eh') => t
SAZipPair1 : {Γ : tctx} {t1 t1' t2 : htyp} {α : action} {eh eh' : zexp}
{e eh◆ : hexp} →
erase-e eh eh◆ →
Γ ⊢ (eh◆) => t1 →
Γ ⊢ eh => t1 ~ α ~> eh' => t1' →
Γ ⊢ e => t2 →
Γ ⊢ ⟨ eh , e ⟩₁ => (t1 ⊠ t2) ~ α ~> ⟨ eh' , e ⟩₁ => (t1' ⊠ t2)
SAZipPair2 : {Γ : tctx} {t1 t2 t2' : htyp} {α : action} {eh eh' : zexp}
{e eh◆ : hexp} →
Γ ⊢ e => t1 →
erase-e eh eh◆ →
Γ ⊢ (eh◆) => t2 →
Γ ⊢ eh => t2 ~ α ~> eh' => t2' →
Γ ⊢ ⟨ e , eh ⟩₂ => (t1 ⊠ t2) ~ α ~> ⟨ e , eh' ⟩₂ => (t1 ⊠ t2')
SAZipFst : {Γ : tctx} {t× t×' t1 t1' t2 t2' : htyp} {α : action}
{eh eh' : zexp} {eh◆ : hexp} →
t× ▸prod (t1 ⊠ t2) →
t×' ▸prod (t1' ⊠ t2') →
erase-e eh eh◆ →
Γ ⊢ (eh◆) => t× →
Γ ⊢ eh => t× ~ α ~> eh' => t×' →
Γ ⊢ fst eh => t1 ~ α ~> fst eh' => t1'
SAZipSnd : {Γ : tctx} {t× t×' t1 t1' t2 t2' : htyp} {α : action}
{eh eh' : zexp} {eh◆ : hexp} →
t× ▸prod (t1 ⊠ t2) →
t×' ▸prod (t1' ⊠ t2') →
erase-e eh eh◆ →
Γ ⊢ (eh◆) => t× →
Γ ⊢ eh => t× ~ α ~> eh' => t×' →
Γ ⊢ snd eh => t2 ~ α ~> snd eh' => t2'
SAZipNEHole : {Γ : tctx} {e e' : zexp} {u : Nat} {t t' : htyp} {α : action}
{e◆ : hexp} →
erase-e e e◆ →
Γ ⊢ e◆ => t →
Γ ⊢ e => t ~ α ~> e' => t' →
Γ ⊢ ⦇⌜ e ⌟⦈[ u ] => ⦇-⦈ ~ α ~> ⦇⌜ e' ⌟⦈[ u ] => ⦇-⦈
-- analytic action expressions
data _⊢_~_~>_⇐_ : (Γ : tctx) → (e : zexp) → (α : action) →
(e' : zexp) → (t : htyp) → Set where
AASubsume : {Γ : tctx} {e e' : zexp} {t t' t'' : htyp} {α : action} {e◆ : hexp} →
erase-e e e◆ →
Γ ⊢ e◆ => t' →
Γ ⊢ e => t' ~ α ~> e' => t'' →
t ~ t'' →
Γ ⊢ e ~ α ~> e' ⇐ t
AAFinish : {Γ : tctx} {e : hexp} {t : htyp} {u : Nat} →
Γ ⊢ e <= t →
Γ ⊢ ▹ ⦇⌜ e ⌟⦈[ u ] ◃ ~ finish ~> ▹ e ◃ ⇐ t
AAMove : {e e' : zexp} {δ : direction} {Γ : tctx} {t : htyp} →
e + move δ +>e e' →
Γ ⊢ e ~ move δ ~> e' ⇐ t
AADel : {e : hexp} {Γ : tctx} {t : htyp} {u : Nat} →
Γ ⊢ ▹ e ◃ ~ del u ~> ▹ ⦇-⦈[ u ] ◃ ⇐ t
AAConNumlit : {Γ : tctx} {t : htyp} {n u u1 : Nat} →
t ~̸ num →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ ~ construct (numlit n u1) ~> ⦇⌜ ▹ (N n) ◃ ⌟⦈[ u1 ] ⇐ t
AAConAsc : {Γ : tctx} {e : hexp} {t : htyp} →
Γ ⊢ ▹ e ◃ ~ construct asc ~> (e ·:₂ ▹ t ◃) ⇐ t
AAConVar : {Γ : tctx} {t t' : htyp} {x u u1 : Nat} →
t ~̸ t' →
(x , t') ∈ Γ →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ ~ construct (var x u1) ~> ⦇⌜ ▹ X x ◃ ⌟⦈[ u1 ] ⇐ t
AAConLam1 : {Γ : tctx} {x : Nat} {t t1 t2 : htyp} {u u1 u2 : Nat} →
x # Γ →
t ▸arr (t1 ==> t2) →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ ~ construct (lam x u1 u2) ~>
·λ x (▹ ⦇-⦈[ u2 ] ◃) ⇐ t
AAConLam2 : {Γ : tctx} {x : Nat} {t : htyp} {u u1 u2 : Nat} →
x # Γ →
t ~̸ (⦇-⦈ ==> ⦇-⦈) →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ ~ construct (lam x u1 u2) ~>
⦇⌜ ·λ x ⦇-⦈[ u2 ] ·:₂ (▹ ⦇-⦈ ◃ ==>₁ ⦇-⦈) ⌟⦈[ u1 ] ⇐ t
AAConInl1 : {Γ : tctx} {t+ t1 t2 : htyp} {u u1 u2 : Nat} →
t+ ▸sum (t1 ⊕ t2) →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ ~ construct (inl u1 u2) ~> inl ▹ ⦇-⦈[ u2 ] ◃ ⇐ t+
AAConInl2 : {Γ : tctx} {t : htyp} {u u1 u2 : Nat} →
t ~̸ (⦇-⦈ ⊕ ⦇-⦈) →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ ~ construct (inl u1 u2) ~>
⦇⌜ inl ⦇-⦈[ u2 ] ·:₂ (▹ ⦇-⦈ ◃ ⊕₁ ⦇-⦈) ⌟⦈[ u1 ] ⇐ t
AAConInr1 : {Γ : tctx} {t+ t1 t2 : htyp} {u u1 u2 : Nat} →
t+ ▸sum (t1 ⊕ t2) →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ ~ construct (inr u1 u2) ~> inr ▹ ⦇-⦈[ u2 ] ◃ ⇐ t+
AAConInr2 : {Γ : tctx} {t : htyp} {u u1 u2 : Nat} →
t ~̸ (⦇-⦈ ⊕ ⦇-⦈) →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ ~ construct (inr u1 u2) ~>
⦇⌜ inr ⦇-⦈[ u2 ] ·:₂ (▹ ⦇-⦈ ◃ ⊕₁ ⦇-⦈) ⌟⦈[ u1 ] ⇐ t
AAConCase : {Γ : tctx} {x y : Nat} {t : htyp} {u u1 u2 u3 : Nat} →
x # Γ →
y # Γ →
Γ ⊢ ▹ ⦇-⦈[ u ] ◃ ~ construct (case x y u1 u2 u3) ~>
case₁ ▹ ⦇-⦈[ u1 ] ◃ x ⦇-⦈[ u2 ] y ⦇-⦈[ u3 ] ⇐ t
AAZipLam : {Γ : tctx} {x : Nat} {t t1 t2 : htyp} {e e' : zexp} {α : action} →
x # Γ →
t ▸arr (t1 ==> t2) →
(Γ ,, (x , t1)) ⊢ e ~ α ~> e' ⇐ t2 →
Γ ⊢ (·λ x e) ~ α ~> (·λ x e') ⇐ t
AAZipInl : {Γ : tctx} {t+ t1 t2 : htyp} {e e' : zexp} {α : action} →
t+ ▸sum (t1 ⊕ t2) →
Γ ⊢ e ~ α ~> e' ⇐ t1 →
Γ ⊢ inl e ~ α ~> inl e' ⇐ t+
AAZipInr : {Γ : tctx} {t+ t1 t2 : htyp} {e e' : zexp} {α : action} →
t+ ▸sum (t1 ⊕ t2) →
Γ ⊢ e ~ α ~> e' ⇐ t2 →
Γ ⊢ inr e ~ α ~> inr e' ⇐ t+
AAZipCase1 : {Γ : tctx} {e e' : zexp} {e◆ e1 e2 : hexp} {x y : Nat}
{t t0 t+ t1 t2 : htyp} {α : action} →
x # Γ →
y # Γ →
erase-e e e◆ →
Γ ⊢ e◆ => t0 →
Γ ⊢ e => t0 ~ α ~> e' => t+ →
t+ ▸sum (t1 ⊕ t2) →
(Γ ,, (x , t1)) ⊢ e1 <= t →
(Γ ,, (y , t2)) ⊢ e2 <= t →
Γ ⊢ case₁ e x e1 y e2 ~ α ~> case₁ e' x e1 y e2 ⇐ t
AAZipCase2 : {Γ : tctx} {e1 e1' : zexp} {e e2 : hexp} {x y : Nat}
{t t+ t1 t2 : htyp} {α : action} →
x # Γ →
y # Γ →
Γ ⊢ e => t+ →
t+ ▸sum (t1 ⊕ t2) →
(Γ ,, (x , t1)) ⊢ e1 ~ α ~> e1' ⇐ t →
Γ ⊢ case₂ e x e1 y e2 ~ α ~> case₂ e x e1' y e2 ⇐ t
AAZipCase3 : {Γ : tctx} {e2 e2' : zexp} {e e1 : hexp} {x y : Nat}
{t t+ t1 t2 : htyp} {α : action} →
x # Γ →
y # Γ →
Γ ⊢ e => t+ →
t+ ▸sum (t1 ⊕ t2) →
(Γ ,, (y , t2)) ⊢ e2 ~ α ~> e2' ⇐ t →
Γ ⊢ case₃ e x e1 y e2 ~ α ~> case₃ e x e1 y e2' ⇐ t
| {
"alphanum_fraction": 0.3343341117,
"avg_line_length": 48.6985559567,
"ext": "agda",
"hexsha": "ac06752414a222ab2ca96bec5babc807b1c171db",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-agda",
"max_forks_repo_path": "statics-core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-agda",
"max_issues_repo_path": "statics-core.agda",
"max_line_length": 92,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-agda",
"max_stars_repo_path": "statics-core.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 11714,
"size": 26979
} |
------------------------------------------------------------------------------
-- PA properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module PA.Axiomatic.Mendelson.PropertiesATP where
open import PA.Axiomatic.Mendelson.Base
------------------------------------------------------------------------------
+-leftIdentity : ∀ n → zero + n ≈ n
+-leftIdentity = S₅
-- See Issue https://github.com/asr/apia/issues/81 .
+-rightIdentityA : ℕ → Set
+-rightIdentityA i = i + zero ≈ i
{-# ATP definition +-rightIdentityA #-}
+-rightIdentity : ∀ n → n + zero ≈ n
+-rightIdentity = S₉ +-rightIdentityA A0 is
where
A0 : +-rightIdentityA zero
A0 = +-leftIdentity zero
postulate is : ∀ i → +-rightIdentityA i → +-rightIdentityA (succ i)
{-# ATP prove is #-}
-- See Issue https://github.com/asr/apia/issues/81 .
x+Sy≈S[x+y]A : ℕ → ℕ → Set
x+Sy≈S[x+y]A n i = i + succ n ≈ succ (i + n)
{-# ATP definition x+Sy≈S[x+y]A #-}
x+Sy≈S[x+y] : ∀ m n → m + succ n ≈ succ (m + n)
x+Sy≈S[x+y] m n = S₉ (x+Sy≈S[x+y]A n) A0 is m
where
postulate A0 : x+Sy≈S[x+y]A n zero
{-# ATP prove A0 #-}
postulate is : ∀ i → x+Sy≈S[x+y]A n i → x+Sy≈S[x+y]A n (succ i)
{-# ATP prove is #-}
-- See Issue https://github.com/asr/apia/issues/81 .
+-leftCongA : ℕ → ℕ → ℕ → Set
+-leftCongA m n i = m + i ≈ n + i
{-# ATP definition +-leftCongA #-}
+-leftCong : ∀ {m n o} → m ≈ n → m + o ≈ n + o
+-leftCong {m} {n} {o} h = S₉ (+-leftCongA m n) A0 is o
where
postulate A0 : +-leftCongA m n zero
{-# ATP prove A0 +-rightIdentity #-}
postulate is : ∀ i → +-leftCongA m n i → +-leftCongA m n (succ i)
{-# ATP prove is x+Sy≈S[x+y] #-}
-- See Issue https://github.com/asr/apia/issues/81 .
+-commA : ℕ → ℕ → Set
+-commA n i = i + n ≈ n + i
{-# ATP definition +-commA #-}
+-comm : ∀ m n → m + n ≈ n + m
+-comm m n = S₉ (+-commA n) A0 is m
where
postulate A0 : +-commA n zero
{-# ATP prove A0 +-rightIdentity #-}
postulate is : ∀ i → +-commA n i → +-commA n (succ i)
{-# ATP prove is x+Sy≈S[x+y] #-}
+-asocc : ∀ m n o → m + n + o ≈ m + (n + o)
+-asocc m n o = S₉ A A0 is m
where
A : ℕ → Set
A i = i + n + o ≈ i + (n + o)
{-# ATP definition A #-}
postulate A0 : A zero
{-# ATP prove A0 +-leftCong #-}
postulate is : ∀ i → A i → A (succ i)
{-# ATP prove is +-leftCong #-}
| {
"alphanum_fraction": 0.5024038462,
"avg_line_length": 28.6896551724,
"ext": "agda",
"hexsha": "67b82a28591c8f51cb9f79cd487a5330b514723d",
"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/PA/Axiomatic/Mendelson/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/PA/Axiomatic/Mendelson/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/PA/Axiomatic/Mendelson/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": 860,
"size": 2496
} |
{-# OPTIONS --prop --without-K --rewriting #-}
-- Definition of a cost monoid.
open import Relation.Binary using (Rel; _Preserves_⟶_; _Preserves₂_⟶_⟶_)
module Calf.CostMonoid where
open import Level using (Level; 0ℓ; suc; _⊔_)
open import Algebra.Core
open import Relation.Binary.PropositionalEquality using (_≡_; resp₂)
open import Data.Product
module _ {ℂ : Set} where
Relation = Rel ℂ 0ℓ
_≈_ : Relation
_≈_ = _≡_
open import Algebra.Definitions _≈_
open import Algebra.Structures _≈_ public
open import Relation.Binary.Structures _≈_
record IsCancellative (_∙_ : Op₂ ℂ) : Set where
field
∙-cancel-≡ : Cancellative _∙_
∙-cancelˡ-≡ : LeftCancellative _∙_
∙-cancelˡ-≡ = proj₁ ∙-cancel-≡
∙-cancelʳ-≡ : RightCancellative _∙_
∙-cancelʳ-≡ = proj₂ ∙-cancel-≡
record IsMonotone (_∙_ : Op₂ ℂ) (_≤_ : Relation) (isPreorder : IsPreorder _≤_) : Set where
field
∙-mono-≤ : _∙_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
open IsPreorder isPreorder
using ()
renaming (reflexive to ≤-reflexive; refl to ≤-refl; trans to ≤-trans)
∙-monoˡ-≤ : ∀ n → (_∙ n) Preserves _≤_ ⟶ _≤_
∙-monoˡ-≤ n m≤o = ∙-mono-≤ m≤o (≤-refl {n})
∙-monoʳ-≤ : ∀ n → (n ∙_) Preserves _≤_ ⟶ _≤_
∙-monoʳ-≤ n m≤o = ∙-mono-≤ (≤-refl {n}) m≤o
record IsCostMonoid (_+_ : Op₂ ℂ) (zero : ℂ) (_≤_ : Relation) : Set where
field
isMonoid : IsMonoid _+_ zero
isCancellative : IsCancellative _+_
isPreorder : IsPreorder _≤_
isMonotone : IsMonotone _+_ _≤_ isPreorder
open IsMonoid isMonoid public
using ()
renaming (
identityˡ to +-identityˡ;
identityʳ to +-identityʳ;
assoc to +-assoc
)
open IsCancellative isCancellative public
renaming (
∙-cancel-≡ to +-cancel-≡;
∙-cancelˡ-≡ to +-cancelˡ-≡;
∙-cancelʳ-≡ to +-cancelʳ-≡
)
open IsPreorder isPreorder public
using ()
renaming (reflexive to ≤-reflexive; refl to ≤-refl; trans to ≤-trans)
open IsMonotone isMonotone public
renaming (
∙-mono-≤ to +-mono-≤;
∙-monoˡ-≤ to +-monoˡ-≤;
∙-monoʳ-≤ to +-monoʳ-≤
)
record IsParCostMonoid (_⊕_ : Op₂ ℂ) (𝟘 : ℂ) (_⊗_ : Op₂ ℂ) (𝟙 : ℂ) (_≤_ : Relation) : Set where
field
isMonoid : IsMonoid _⊕_ 𝟘
isCommutativeMonoid : IsCommutativeMonoid _⊗_ 𝟙
isCancellative : IsCancellative _⊕_
isPreorder : IsPreorder _≤_
isMonotone-⊕ : IsMonotone _⊕_ _≤_ isPreorder
isMonotone-⊗ : IsMonotone _⊗_ _≤_ isPreorder
open IsMonoid isMonoid public
using ()
renaming (
identityˡ to ⊕-identityˡ;
identityʳ to ⊕-identityʳ;
assoc to ⊕-assoc
)
open IsCommutativeMonoid isCommutativeMonoid public
using ()
renaming (
identityˡ to ⊗-identityˡ;
identityʳ to ⊗-identityʳ;
assoc to ⊗-assoc;
comm to ⊗-comm
)
open IsCancellative isCancellative public
renaming (
∙-cancel-≡ to ⊕-cancel-≡;
∙-cancelˡ-≡ to ⊕-cancelˡ-≡;
∙-cancelʳ-≡ to ⊕-cancelʳ-≡
)
open IsPreorder isPreorder public
using ()
renaming (reflexive to ≤-reflexive; refl to ≤-refl; trans to ≤-trans)
open IsMonotone isMonotone-⊕ public
renaming (
∙-mono-≤ to ⊕-mono-≤;
∙-monoˡ-≤ to ⊕-monoˡ-≤;
∙-monoʳ-≤ to ⊕-monoʳ-≤
)
open IsMonotone isMonotone-⊗ public
renaming (
∙-mono-≤ to ⊗-mono-≤;
∙-monoˡ-≤ to ⊗-monoˡ-≤;
∙-monoʳ-≤ to ⊗-monoʳ-≤
)
record CostMonoid : Set₁ where
infixl 6 _+_
field
ℂ : Set
_+_ : Op₂ ℂ
zero : ℂ
_≤_ : Relation
isCostMonoid : IsCostMonoid _+_ zero _≤_
open IsCostMonoid isCostMonoid public
module ≤-Reasoning where
open import Relation.Binary.Reasoning.Base.Triple
isPreorder
≤-trans
(resp₂ _≤_)
(λ h → h)
≤-trans
≤-trans
public
hiding (step-≈; step-≈˘; step-<)
record ParCostMonoid : Set₁ where
infixl 7 _⊗_
infixl 6 _⊕_
field
ℂ : Set
_⊕_ : Op₂ ℂ
𝟘 : ℂ
_⊗_ : Op₂ ℂ
𝟙 : ℂ
_≤_ : Relation
isParCostMonoid : IsParCostMonoid _⊕_ 𝟘 _⊗_ 𝟙 _≤_
open IsParCostMonoid isParCostMonoid public
costMonoid : CostMonoid
costMonoid = record
{ ℂ = ℂ
; _+_ = _⊕_
; zero = 𝟘
; _≤_ = _≤_
; isCostMonoid = record
{ isMonoid = isMonoid
; isPreorder = isPreorder
; isCancellative = isCancellative
; isMonotone = isMonotone-⊕
}
}
module ≤-Reasoning where
open import Relation.Binary.Reasoning.Base.Triple
isPreorder
≤-trans
(resp₂ _≤_)
(λ h → h)
≤-trans
≤-trans
public
hiding (step-≈; step-≈˘; step-<)
| {
"alphanum_fraction": 0.5642857143,
"avg_line_length": 25.2577319588,
"ext": "agda",
"hexsha": "49587bb7ba7fe9c2bd9dd7973491abd724f056ff",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-01-29T08:12:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-10-06T10:28:24.000Z",
"max_forks_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "jonsterling/agda-calf",
"max_forks_repo_path": "src/Calf/CostMonoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"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": "jonsterling/agda-calf",
"max_issues_repo_path": "src/Calf/CostMonoid.agda",
"max_line_length": 97,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "e51606f9ca18d8b4cf9a63c2d6caa2efc5516146",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "jonsterling/agda-calf",
"max_stars_repo_path": "src/Calf/CostMonoid.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T20:35:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-14T03:18:28.000Z",
"num_tokens": 1928,
"size": 4900
} |
-- Minimal implicational logic, PHOAS approach, initial encoding
module Pi.ArrMp where
-- Types
infixr 0 _=>_
data Ty : Set where
UNIT : Ty
_=>_ : Ty -> Ty -> Ty
-- Context and truth judgement
Cx : Set1
Cx = Ty -> Set
isTrue : Ty -> Cx -> Set
isTrue a tc = tc a
-- Terms
module ArrMp where
infixl 1 _$_
data Tm (tc : Cx) : Ty -> Set where
var : forall {a} -> isTrue a tc -> Tm tc a
lam' : forall {a b} -> (isTrue a tc -> Tm tc b) -> Tm tc (a => b)
_$_ : forall {a b} -> Tm tc (a => b) -> Tm tc a -> Tm tc b
lam'' : forall {tc a b} -> (Tm tc a -> Tm tc b) -> Tm tc (a => b)
lam'' f = lam' \x -> f (var x)
syntax lam'' (\a -> b) = lam a => b
Thm : Ty -> Set1
Thm a = forall {tc} -> Tm tc a
open ArrMp public
-- Example theorems
aI : forall {a} -> Thm (a => a)
aI =
lam x => x
aK : forall {a b} -> Thm (a => b => a)
aK =
lam x =>
lam _ => x
aS : forall {a b c} -> Thm ((a => b => c) => (a => b) => a => c)
aS =
lam f =>
lam g =>
lam x => f $ x $ (g $ x)
tSKK : forall {a} -> Thm (a => a)
tSKK {a = a} =
aS {b = a => a} $ aK $ aK
| {
"alphanum_fraction": 0.4765279008,
"avg_line_length": 18.2096774194,
"ext": "agda",
"hexsha": "11c2f0f2753004a2ba0d4fff40915341c0997c04",
"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": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/formal-logic",
"max_forks_repo_path": "src/Pi/ArrMp.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/formal-logic",
"max_issues_repo_path": "src/Pi/ArrMp.agda",
"max_line_length": 70,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/formal-logic",
"max_stars_repo_path": "src/Pi/ArrMp.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z",
"num_tokens": 451,
"size": 1129
} |
{-# OPTIONS --without-K #-}
module container.m where
open import container.m.coalgebra public
open import container.m.from-nat public
-- open import container.m.core public
-- open import container.m.extensionality public
-- open import container.m.level public
| {
"alphanum_fraction": 0.7765151515,
"avg_line_length": 26.4,
"ext": "agda",
"hexsha": "cc9fc79b8341ff8119b41d88f4e4e84dedcc721e",
"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/container/m.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/container/m.agda",
"max_line_length": 48,
"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/container/m.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": 54,
"size": 264
} |
{-# OPTIONS --guardedness-preserving-type-constructors #-}
module TypeConstructorsWhichPreserveGuardedness2 where
record ⊤ : Set where
data _⊎_ (A B : Set) : Set where
inj₁ : A → A ⊎ B
inj₂ : B → A ⊎ B
-- This should not be allowed.
ℕ : Set
ℕ = ⊤ ⊎ ℕ
| {
"alphanum_fraction": 0.6576923077,
"avg_line_length": 17.3333333333,
"ext": "agda",
"hexsha": "32c71645ae7956573068ca89c044870ed9ba1b74",
"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/TypeConstructorsWhichPreserveGuardedness2.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/TypeConstructorsWhichPreserveGuardedness2.agda",
"max_line_length": 58,
"max_stars_count": 3,
"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/TypeConstructorsWhichPreserveGuardedness2.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": 91,
"size": 260
} |
{-# OPTIONS --without-K #-}
open import BaseOver
module Spaces.Flattening {i j k}
(A : Set i) (B : Set j) (f g : B → A)
(C : A → Set k) (D : (b : B) → C (f b) ≃ C (g b)) where
open import Spaces.FlatteningTypes A B f g C D
-- The family of paths used in the definition of [flatten]
paths-flatten : (b : B) → (cct (f b) == cct (g b) [ (λ w → (P w → Wt)) ↓ pp b ])
paths-flatten b =
↓-app→cst-in (λ q → ppt b _ ∘' ap (cct (g b)) (↓-pp-out q))
flatten-curried : (w : W) → (P w → Wt)
flatten-curried = W-rec _ cct paths-flatten
flatten : Σ W P → Wt
flatten (w , x) = flatten-curried w x
unflatten : Wt → Σ W P
unflatten = Wt-rec-nondep _ (λ a c → (cc a , c))
(λ b d → Σ-eq (pp b) (↓-pp-in refl))
--
flatten-unflatten : (w : Wt) → flatten (unflatten w) ≡ w
flatten-unflatten =
Wt-rec _
(λ _ _ → refl)
(λ b d → ↓-◯=id-in unflatten flatten
(ap flatten (ap unflatten (ppt b d))
≡⟨ Wt-rec-nondep-β _ (λ a c → (cc a , c)) (λ b d → Σ-eq (pp b) (↓-pp-in refl)) b d |in-ctx ap flatten ⟩
ap flatten (Σ-eq (pp b) (↓-pp-in refl))
≡⟨ split-ap2 flatten (pp b) (↓-pp-in refl) ⟩
↓-app→cst-out (apd flatten-curried (pp b)) (↓-pp-in refl)
≡⟨ W-rec-β _ cct paths-flatten b |in-ctx (λ u → ↓-app→cst-out u (↓-pp-in refl)) ⟩
↓-app→cst-out (paths-flatten b) (↓-pp-in refl)
≡⟨ refl ⟩
↓-app→cst-out (↓-app→cst-in
(λ q → ppt b _ ∘' ap (cct (g b)) (↓-pp-out q))) (↓-pp-in refl)
≡⟨ ↓-app→cst-β (λ q → ppt b _ ∘' ap (cct (g b)) (↓-pp-out q)) (↓-pp-in refl) ⟩
ppt b d ∘' ap (cct (g b)) (↓-pp-out (↓-pp-in refl))
≡⟨ ↓-pp-β refl |in-ctx (λ u → ppt b d ∘' ap (cct (g b)) u) ⟩
ppt b d ∎))
unflatten-flatten-curried : (w : W) (x : P w)
→ unflatten (flatten-curried w x) ≡ (w , x)
unflatten-flatten-curried =
W-rec _ (λ a x → refl)
(λ b → ↓-Π-in
(λ q → ↓-◯=id-in flatten unflatten
(ap unflatten (ap flatten (Σ-eq (pp b) q))
≡⟨ split-ap2 flatten (pp b) q |in-ctx ap unflatten ⟩
ap unflatten (↓-app→cst-out (apd flatten-curried (pp b)) q)
≡⟨ W-rec-β _ cct paths-flatten b |in-ctx (λ u → ap unflatten (↓-app→cst-out u q)) ⟩
ap unflatten (↓-app→cst-out (paths-flatten b) q)
≡⟨ refl ⟩
ap unflatten (↓-app→cst-out (↓-app→cst-in (λ qq → ppt b _ ∘' ap (cct (g b)) (↓-pp-out qq))) q)
≡⟨ ↓-app→cst-β (λ qq → ppt b _ ∘' ap (cct (g b)) (↓-pp-out qq)) q |in-ctx ap unflatten ⟩
ap unflatten (ppt b _ ∘' ap (cct (g b)) (↓-pp-out q))
≡⟨ ap-∘' unflatten (ppt b _) (ap (cct (g b)) (↓-pp-out q)) ⟩
ap unflatten (ppt b _) ∘' ap unflatten (ap (cct (g b)) (↓-pp-out q))
≡⟨ Wt-rec-nondep-β _ (λ a c → (cc a , c)) (λ b d → Σ-eq (pp b) (↓-pp-in refl)) b _ |in-ctx (λ u → u ∘' ap unflatten (ap (cct (g b)) (↓-pp-out q))) ⟩
Σ-eq (pp b) (↓-pp-in refl) ∘' ap unflatten (ap (cct (g b)) (↓-pp-out q))
≡⟨ compose-ap unflatten (cct (g b)) (↓-pp-out q) |in-ctx (λ u → (Σ-eq (pp b) (↓-pp-in refl) ∘' u)) ⟩
Σ-eq (pp b) (↓-pp-in refl) ∘' ap (unflatten ◯ cct (g b)) (↓-pp-out q)
≡⟨ refl ⟩
Σ-eq (pp b) (↓-pp-in refl) ∘' ap (λ x → (cc (g b), x)) (↓-pp-out q)
≡⟨ ap-cst,id P (↓-pp-out q) |in-ctx (λ u → Σ-eq (pp b) (↓-pp-in refl) ∘' u) ⟩
Σ-eq (pp b) (↓-pp-in refl) ∘' Σ-eq refl (↓-pp-out q)
≡⟨ Σ-∘' (↓-pp-in refl) (↓-pp-out q) ⟩
Σ-eq (pp b) (↓-pp-in refl ∘'dep ↓-pp-out q)
≡⟨ to-transp-weird q (pp-path _ _) |in-ctx Σ-eq (pp b) ⟩
Σ-eq (pp b) q ∎)))
unflatten-flatten : (wx : Σ W P) → unflatten (flatten wx) ≡ wx
unflatten-flatten (w , x) = unflatten-flatten-curried w x
eqv : Σ W P ≃ Wt
eqv = (flatten , iso-is-eq flatten unflatten flatten-unflatten unflatten-flatten)
| {
"alphanum_fraction": 0.4886773031,
"avg_line_length": 46.8192771084,
"ext": "agda",
"hexsha": "fdf8c689b57f4d8f0022bfe03508b7a220fcaae4",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "old/Spaces/Flattening.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "old/Spaces/Flattening.agda",
"max_line_length": 165,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "old/Spaces/Flattening.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 1634,
"size": 3886
} |
{-# OPTIONS --cubical #-}
open import Agda.Primitive.Cubical
open import Agda.Builtin.Cubical.Path
postulate
A : Set
B : Set
b : B
f : (\ {a : A} (x : B) → b) ≡ (\ _ → b)
f i x = b
| {
"alphanum_fraction": 0.5631578947,
"avg_line_length": 14.6153846154,
"ext": "agda",
"hexsha": "05b8f509f277dd94e45dcd3d929ee9077ae2279d",
"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/Issue2722.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/Issue2722.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/Succeed/Issue2722.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": 75,
"size": 190
} |
module RandomAccessList.Zeroless where
open import RandomAccessList.Zeroless.Core
open import RandomAccessList.Zeroless.Core.Properties
open import BuildingBlock.BinaryLeafTree using (BinaryLeafTree; Node; Leaf; split)
import BuildingBlock.BinaryLeafTree as BLT
open import Data.Fin using (Fin; fromℕ; fromℕ≤; reduce≥; toℕ)
import Data.Fin as Fin
open import Data.Nat
open import Data.Nat.DivMod
-- open import Data.Nat.Properties.Simple
open import Data.Nat.Etc
open import Data.Product
open import Function
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Negation using (contradiction; contraposition)
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; cong; trans; sym; inspect)
open PropEq.≡-Reasoning
--------------------------------------------------------------------------------
-- Operations
--------------------------------------------------------------------------------
-- cons
consₙ : ∀ {n A} → BinaryLeafTree A n → 1-2-RAL A n → 1-2-RAL A n
consₙ a ( []) = a 1∷ []
consₙ a (x 1∷ xs) = a , x 2∷ xs
consₙ a (x , y 2∷ xs) = a 1∷ consₙ (Node x y) xs
cons : ∀ {A} → A → 1-2-RAL A 0 → 1-2-RAL A 0
cons a xs = consₙ (Leaf a) xs
-- head
headₙ : ∀ {n A} → (xs : 1-2-RAL A n) → ⟦ xs ⟧ ≢ 0 → BinaryLeafTree A n
headₙ {n} {A} [] p = contradiction (⟦[]⟧≡0 ([] {A} {n}) refl) p
headₙ (x 1∷ xs) p = x
headₙ (x , y 2∷ xs) p = x
head : ∀ {A} → (xs : 1-2-RAL A 0) → ⟦ xs ⟧ ≢ 0 → A
head xs p = BLT.head (headₙ xs p)
-- tail
tailₙ : ∀ {n A} → (xs : 1-2-RAL A n) → ⟦ xs ⟧ ≢ 0 → 1-2-RAL A n
tailₙ [] p = []
tailₙ (x 1∷ xs) p with ⟦ xs ⟧ ≟ 0
tailₙ (x 1∷ xs) p | yes q = []
tailₙ (x 1∷ xs) p | no ¬q =
let y₀ = proj₁ (split (headₙ xs ¬q))
y₁ = proj₂ (split (headₙ xs ¬q))
in y₀ , y₁ 2∷ tailₙ xs ¬q
tailₙ (x , y 2∷ xs) p = y 1∷ xs
tail : ∀ {A} → (xs : 1-2-RAL A 0) → ⟦ xs ⟧ ≢ 0 → 1-2-RAL A 0
tail = tailₙ
--------------------------------------------------------------------------------
-- Searching
--------------------------------------------------------------------------------
{-
data Occurrence : ℕ → Set where
here : ∀ {n b} → ℕ → Fin (b * 2 ^ n) → Occurrence n
there : ∀ {n} → Occurrence n
transportFin : ∀ {a b} → a ≡ b → Fin a → Fin b
transportFin refl i = i
search : ∀ {n A} → (xs : 1-2-RAL A n) → ℕ → Occurrence n
search [] i = there
search {n} (x 1∷ xs) i with (1 * 2 ^ n) ≤? i
search (x 1∷ xs) i | yes p = there
search {n} (x 1∷ xs) i | no ¬p = here 0 (fromℕ≤ (m≰n⇒n<m (1 * 2 ^ n) i ¬p))
search {n} (x , y 2∷ xs) i with (2 * 2 ^ n) ≤? i
search (x , y 2∷ xs) i | yes p = there
search {n} (x , y 2∷ xs) i | no ¬p with i divMod (2 ^ n)
search (x , y 2∷ xs) i | no ¬p | result zero remainder _ = here zero {! !}
search (x , y 2∷ xs) i | no ¬p | result (suc quotient) remainder _ = {! !}
elemAt : ∀ {n A} → (xs : 1-2-RAL A n) → Fin ⟦ xs ⟧ → A
elemAt {n} {A} [] i = contradiction (transportFin (⟦[]⟧≡0 ([] {A} {n}) refl) i) (λ ())
elemAt (x 1∷ xs) i = {! !}
elemAt (x , y 2∷ xs) i = {! !}
splitIndex1∷ : ∀ {n A} → (x : BinaryLeafTree A n) → (xs : 1-2-RAL A (suc n)) → ⟦ x 1∷ xs ⟧ ≡ (2 ^ n) + ⟦ xs ⟧
splitIndex1∷ {n} x xs =
begin
⟦ x 1∷ xs ⟧
≡⟨ +-*-suc (2 ^ n) (2 * ⟦ xs ⟧ₙ) ⟩
2 ^ n + 2 ^ n * (2 * ⟦ xs ⟧ₙ)
≡⟨ cong (_+_ (2 ^ n)) (sym (*-assoc (2 ^ n) 2 ⟦ xs ⟧ₙ)) ⟩
2 ^ n + 2 ^ n * 2 * ⟦ xs ⟧ₙ
≡⟨ cong (λ w → 2 ^ n + w * ⟦ xs ⟧ₙ) (*-comm (2 ^ n) 2) ⟩
(2 ^ n) + ⟦ xs ⟧
∎
n+n≡2*n : (n : ℕ) → n + n ≡ 2 * n
n+n≡2*n n = cong (_+_ n) (sym (+-right-identity n))
splitIndex2∷ : ∀ {n A}
→ (x : BinaryLeafTree A n)
→ (y : BinaryLeafTree A n)
→ (xs : 1-2-RAL A (suc n)) → ⟦ x , y 2∷ xs ⟧ ≡ 2 * (2 ^ n) + ⟦ xs ⟧
splitIndex2∷ {n} x y xs =
begin
⟦ x , y 2∷ xs ⟧
≡⟨ +-*-suc (2 ^ n) (suc (2 * ⟦ xs ⟧ₙ)) ⟩
2 ^ n + 2 ^ n * suc (2 * ⟦ xs ⟧ₙ)
≡⟨ cong (_+_ (2 ^ n)) (+-*-suc (2 ^ n) (2 * ⟦ xs ⟧ₙ)) ⟩
2 ^ n + (2 ^ n + 2 ^ n * (2 * ⟦ xs ⟧ₙ))
≡⟨ sym (+-assoc (2 ^ n) (2 ^ n) (2 ^ n * (2 * ⟦ xs ⟧ₙ))) ⟩
2 ^ n + 2 ^ n + 2 ^ n * (2 * ⟦ xs ⟧ₙ)
≡⟨ cong (λ w → 2 ^ n + 2 ^ n + w) (sym (*-assoc (2 ^ n) 2 ⟦ xs ⟧ₙ)) ⟩
2 ^ n + 2 ^ n + 2 ^ n * 2 * ⟦ xs ⟧ₙ
≡⟨ cong (λ w → 2 ^ n + 2 ^ n + w * ⟦ xs ⟧ₙ) (*-comm (2 ^ n) 2) ⟩
2 ^ n + 2 ^ n + 2 * 2 ^ n * ⟦ xs ⟧ₙ
≡⟨ cong (λ w → w + 2 * 2 ^ n * ⟦ xs ⟧ₙ) (n+n≡2*n (2 ^ n)) ⟩
2 * 2 ^ n + ⟦ xs ⟧
∎
{-
elemAt : ∀ {n A} → (xs : 1-2-RAL A n) → Fin ⟦ xs ⟧ → A
elemAt ( []) ()
elemAt {n} (x 1∷ xs) i with (2 ^ n) ≤? toℕ i
elemAt {n} (x 1∷ xs) i | yes p rewrite splitIndex1∷ x xs = elemAt xs (reduce≥ i p)
elemAt (x 1∷ xs) i | no ¬p = BLT.elemAt x (fromℕ≤ (BLT.¬a≤b⇒b<a ¬p))
elemAt {n} (x , y 2∷ xs) i with (2 * (2 ^ n)) ≤? toℕ i
elemAt (x , y 2∷ xs) i | yes p rewrite splitIndex2∷ x y xs = elemAt xs (reduce≥ i p)
elemAt {n} (x , y 2∷ xs) i | no ¬p with (2 ^ n) ≤? toℕ i
elemAt (x , y 2∷ xs) i | no ¬p | yes q rewrite splitIndex2∷ x y xs = BLT.elemAt y {! !} -- y
elemAt (x , y 2∷ xs) i | no ¬p | no ¬q = BLT.elemAt x (fromℕ≤ (BLT.¬a≤b⇒b<a ¬q)) -- x
-}
-- reduce≥ : ∀ {m n} (i : Fin (m N+ n)) (i≥m : toℕ i N≥ m) → Fin n
-- i : 2 * 2 ^ n + (2 * 2 ^ n) * ⟦ xs ⟧ₙ
-- m : 2 ^ n
-}
| {
"alphanum_fraction": 0.4519924099,
"avg_line_length": 38.1884057971,
"ext": "agda",
"hexsha": "9958a1574bb998fe1f8520326a427b8198e7284b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "legacy/RandomAccessList/Zeroless.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "legacy/RandomAccessList/Zeroless.agda",
"max_line_length": 109,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "legacy/RandomAccessList/Zeroless.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 2413,
"size": 5270
} |
open import Nat
open import Prelude
open import Hazelnut-core
-- the obvious small step dynamics for complete expressions.
module Hazelnut-complete-dynamics where
value : (e : ė) (p : ecomplete e) (t : τ̇) (q : ∅ ⊢ e => t) → Set
value ._ _ _ (SAsc _) = ⊥
value ._ _ _ (SVar x) with x
... | ()
value ._ _ _ (SAp _ _) = ⊥
value ._ _ .num SNum = ⊤
value ._ _ .num (SPlus _ _) = ⊥
value .<||> () .<||> SEHole
value ._ () .<||> (SFHole _)
value ._ _ .<||> (SApHole _ _) = ⊥
-- "substitute e1 for x in e2". note that this only works on well typed
-- terms because of barendrecht's convention. that's a theorem we need to
-- prove. on non well typed terms, this is not correct.
[_/_]_ : ė → Nat → ė → ė
[ e1 / x ] (e2 ·: y) = ([ e1 / x ] e2) ·: y
[ e1 / x ] X y with natEQ x y
... | Inl p = e1
... | Inr _ = X y
[ e1 / x ] ·λ y e2 = ·λ y ([ e1 / x ] e2)
[ e1 / x ] N n = N n
[ e1 / x ] (e2 ·+ e3) = ([ e1 / x ] e2) ·+ ([ e1 / x ] e3)
[ e1 / x ] <||> = <||>
[ e1 / x ] <| e2 |> = <| [ e1 / x ] e2 |>
[ e1 / x ] (e2 ∘ e3) = ([ e1 / x ] e2) ∘ ([ e1 / x ] e3)
| {
"alphanum_fraction": 0.4750656168,
"avg_line_length": 35.71875,
"ext": "agda",
"hexsha": "3e4df99baeb71997d24e68e0f087e43d4a261dad",
"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": "86a755ca6749e080f9a03287e34d1cda889f1edb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ivoysey/agda-tfp16",
"max_forks_repo_path": "Hazelnut-complete-dynamics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "86a755ca6749e080f9a03287e34d1cda889f1edb",
"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": "ivoysey/agda-tfp16",
"max_issues_repo_path": "Hazelnut-complete-dynamics.agda",
"max_line_length": 75,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "86a755ca6749e080f9a03287e34d1cda889f1edb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ivoysey/agda-tfp16",
"max_stars_repo_path": "Hazelnut-complete-dynamics.agda",
"max_stars_repo_stars_event_max_datetime": "2016-04-14T02:19:58.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-09T13:35:22.000Z",
"num_tokens": 485,
"size": 1143
} |
module Data.Fin where
open import Data.Nat hiding (_==_; _<_)
open import Data.Bool
open import Logic.Identity
open import Logic.Base
data Fin : Nat -> Set where
fzero : {n : Nat} -> Fin (suc n)
fsuc : {n : Nat} -> Fin n -> Fin (suc n)
pred : {n : Nat} -> Fin (suc (suc n)) -> Fin (suc n)
pred fzero = fzero
pred (fsuc i) = i
fzero≠fsuc : {n : Nat}{i : Fin n} -> fzero ≢ fsuc i
fzero≠fsuc ()
fsuc-inj : {n : Nat}{i j : Fin n} -> fsuc i ≡ fsuc j -> i ≡ j
fsuc-inj refl = refl
_==_ : {n : Nat}(i j : Fin n) -> i ≡ j \/ i ≢ j
fzero == fzero = \/-IL refl
fzero == fsuc j = \/-IR fzero≠fsuc
fsuc i == fzero = \/-IR (sym≢ fzero≠fsuc)
fsuc i == fsuc j = aux i j (i == j)
where
aux : {n : Nat}(i j : Fin n) -> i ≡ j \/ i ≢ j -> fsuc i ≡ fsuc j \/ fsuc i ≢ fsuc j
aux i .i (\/-IL refl) = \/-IL refl
aux i j (\/-IR i≠j) = \/-IR \si=sj -> i≠j (fsuc-inj si=sj)
_<_ : {n : Nat} -> Fin n -> Fin n -> Bool
_ < fzero = false
fzero < fsuc j = true
fsuc i < fsuc j = i < j
fromNat : (n : Nat) -> Fin (suc n)
fromNat zero = fzero
fromNat (suc n) = fsuc (fromNat n)
liftSuc : {n : Nat} -> Fin n -> Fin (suc n)
liftSuc fzero = fzero
liftSuc (fsuc i) = fsuc (liftSuc i)
lift+ : {n : Nat}(m : Nat) -> Fin n -> Fin (m + n)
lift+ zero i = i
lift+ (suc m) i = liftSuc (lift+ m i)
thin : {n : Nat} -> Fin (suc n) -> Fin n -> Fin (suc n)
thin fzero i = fsuc i
thin (fsuc j) fzero = fzero
thin (fsuc j) (fsuc i) = fsuc (thin j i)
-- Two elements of Fin n are either the same or one is the thinning of
-- something with respect to the other.
data ThinView : {n : Nat}(i j : Fin n) -> Set where
same : {n : Nat}{i : Fin n} -> ThinView i i
diff : {n : Nat}{i : Fin (suc n)}(j : Fin n) -> ThinView i (thin i j)
thinView : {n : Nat}(i j : Fin n) -> ThinView i j
thinView fzero fzero = same
thinView fzero (fsuc j) = diff j
thinView {suc zero} (fsuc ()) fzero
thinView {suc (suc n)} (fsuc i) fzero = diff fzero
thinView (fsuc i) (fsuc j) = aux i j (thinView i j)
where
aux : {n : Nat}(i j : Fin n) -> ThinView i j -> ThinView (fsuc i) (fsuc j)
aux i .i same = same
aux i .(thin i j) (diff j) = diff (fsuc j)
thin-ij≠i : {n : Nat}(i : Fin (suc n))(j : Fin n) -> thin i j ≢ i
thin-ij≠i fzero j ()
thin-ij≠i (fsuc i) fzero ()
thin-ij≠i (fsuc i) (fsuc j) eq = thin-ij≠i i j (fsuc-inj eq)
-- Thickening.
-- thin i (thick i j) ≡ j ?
-- thick i (thin i j) ≡ j
thick : {n : Nat}(i j : Fin (suc n)) -> i ≢ j -> Fin n
thick i j i≠j = thick' i j i≠j (thinView i j) where
thick' : {n : Nat}(i j : Fin (suc n)) -> i ≢ j -> ThinView i j -> Fin n
thick' i .i i≠i same = elim-False (i≠i refl)
thick' i .(thin i j) _ (diff j) = j
-- thin∘thick=id : {n : Nat}(i j : Fin (suc n))(p : i ≢ j) ->
-- thin i (thick i j p) ≡ j
-- thin∘thick=id i j p = ?
--
-- thick∘thin=id : {n : Nat}(i : Fin (suc n))(j : Fin n) ->
-- thick i (thin i j) (sym≢ (thin-ij≠i i j)) ≡ j
-- thick∘thin=id i j = ?
--
| {
"alphanum_fraction": 0.5331325301,
"avg_line_length": 31.7872340426,
"ext": "agda",
"hexsha": "eeb59d8ef2b32ce5eb51660468715368e5024696",
"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": "477c8c37f948e6038b773409358fd8f38395f827",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Fin.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"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": "larrytheliquid/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Fin.agda",
"max_line_length": 88,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Fin.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1273,
"size": 2988
} |
-- Andreas, 2016-09-12
--
-- Underscores should also get meaningful names
-- (not just metas from omitted hidden arguments)
-- {-# OPTIONS -v tc.meta.name:100 #-}
postulate
F : (A : Set) → Set
G : {B : Set} → Set
test1 : Set
test1 = F _
-- name of this meta should be _A_0
test2 : Set
test2 = G
-- creates meta _B_1
test3 : Set
test3 = G {_}
-- name of this meta should be _B_2
| {
"alphanum_fraction": 0.6335877863,
"avg_line_length": 17.0869565217,
"ext": "agda",
"hexsha": "21de6a27822a7905ee15413c8d4ec418ee106a60",
"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/MetaNameSuggestion.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/MetaNameSuggestion.agda",
"max_line_length": 49,
"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/MetaNameSuggestion.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": 136,
"size": 393
} |
open import Agda.Primitive
open import Agda.Primitive.Cubical
record Wrap : Set (lsuc lzero) where
field
A : IUniv
| {
"alphanum_fraction": 0.7459016393,
"avg_line_length": 17.4285714286,
"ext": "agda",
"hexsha": "0b204ba88b7085415bd6fe6e277d901d76be033b",
"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/IUnivNotFibrant.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/IUnivNotFibrant.agda",
"max_line_length": 36,
"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/IUnivNotFibrant.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 39,
"size": 122
} |
{-
Basic theory about h-levels/n-types:
- Basic properties of isContr, isProp and isSet (definitions are in Prelude)
- Hedberg's theorem can be found in Cubical/Relation/Nullary/DecidableEq
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.HLevels where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Structure
open import Cubical.Functions.FunExtEquiv
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Path
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence using (ua ; univalence)
open import Cubical.Data.Sigma
open import Cubical.Data.Nat using (ℕ; zero; suc; _+_; +-zero; +-comm)
HLevel : Type₀
HLevel = ℕ
private
variable
ℓ ℓ' ℓ'' ℓ''' : Level
A : Type ℓ
B : A → Type ℓ
C : (x : A) → B x → Type ℓ
D : (x : A) (y : B x) → C x y → Type ℓ
E : (x : A) (y : B x) → (z : C x y) → D x y z → Type ℓ
x y : A
n : HLevel
isOfHLevel : HLevel → Type ℓ → Type ℓ
isOfHLevel 0 A = isContr A
isOfHLevel 1 A = isProp A
isOfHLevel (suc (suc n)) A = (x y : A) → isOfHLevel (suc n) (x ≡ y)
isOfHLevelFun : (n : HLevel) {A : Type ℓ} {B : Type ℓ'} (f : A → B) → Type (ℓ-max ℓ ℓ')
isOfHLevelFun n f = ∀ b → isOfHLevel n (fiber f b)
TypeOfHLevel : ∀ ℓ → HLevel → Type (ℓ-suc ℓ)
TypeOfHLevel ℓ n = TypeWithStr ℓ (isOfHLevel n)
hProp hSet hGroupoid h2Groupoid : ∀ ℓ → Type (ℓ-suc ℓ)
hProp ℓ = TypeOfHLevel ℓ 1
hSet ℓ = TypeOfHLevel ℓ 2
hGroupoid ℓ = TypeOfHLevel ℓ 3
h2Groupoid ℓ = TypeOfHLevel ℓ 4
-- lower h-levels imply higher h-levels
isOfHLevelSuc : (n : HLevel) → isOfHLevel n A → isOfHLevel (suc n) A
isOfHLevelSuc 0 = isContr→isProp
isOfHLevelSuc 1 = isProp→isSet
isOfHLevelSuc (suc (suc n)) h a b = isOfHLevelSuc (suc n) (h a b)
isSet→isGroupoid : isSet A → isGroupoid A
isSet→isGroupoid = isOfHLevelSuc 2
isGroupoid→is2Groupoid : isGroupoid A → is2Groupoid A
isGroupoid→is2Groupoid = isOfHLevelSuc 3
isOfHLevelPlus : (m : HLevel) → isOfHLevel n A → isOfHLevel (m + n) A
isOfHLevelPlus zero hA = hA
isOfHLevelPlus (suc m) hA = isOfHLevelSuc _ (isOfHLevelPlus m hA)
isContr→isOfHLevel : (n : HLevel) → isContr A → isOfHLevel n A
isContr→isOfHLevel {A = A} n cA = subst (λ m → isOfHLevel m A) (+-zero n) (isOfHLevelPlus n cA)
isProp→isOfHLevelSuc : (n : HLevel) → isProp A → isOfHLevel (suc n) A
isProp→isOfHLevelSuc {A = A} n pA = subst (λ m → isOfHLevel m A) (+-comm n 1) (isOfHLevelPlus n pA)
-- hlevel of path and dependent path types
isProp→isContrPath : isProp A → (x y : A) → isContr (x ≡ y)
isProp→isContrPath h x y = h x y , isProp→isSet h x y _
isContr→isContrPath : isContr A → (x y : A) → isContr (x ≡ y)
isContr→isContrPath cA = isProp→isContrPath (isContr→isProp cA)
isOfHLevelPath' : (n : HLevel) → isOfHLevel (suc n) A → (x y : A) → isOfHLevel n (x ≡ y)
isOfHLevelPath' 0 = isProp→isContrPath
isOfHLevelPath' (suc n) h x y = h x y
isOfHLevelPath'⁻ : (n : HLevel) → ((x y : A) → isOfHLevel n (x ≡ y)) → isOfHLevel (suc n) A
isOfHLevelPath'⁻ zero h x y = h x y .fst
isOfHLevelPath'⁻ (suc n) h = h
isOfHLevelPath : (n : HLevel) → isOfHLevel n A → (x y : A) → isOfHLevel n (x ≡ y)
isOfHLevelPath 0 h x y = isContr→isContrPath h x y
isOfHLevelPath (suc n) h x y = isOfHLevelSuc n (isOfHLevelPath' n h x y)
isOfHLevelPathP' : {A : I → Type ℓ} (n : HLevel)
→ isOfHLevel (suc n) (A i1)
→ (x : A i0) (y : A i1) → isOfHLevel n (PathP A x y)
isOfHLevelPathP' {A = A} n h x y = transport⁻ (λ i → isOfHLevel n (PathP≡Path A x y i))
(isOfHLevelPath' n h _ _)
isOfHLevelPathP : {A : I → Type ℓ} (n : HLevel)
→ isOfHLevel n (A i1)
→ (x : A i0) (y : A i1) → isOfHLevel n (PathP A x y)
isOfHLevelPathP {A = A} n h x y = transport⁻ (λ i → isOfHLevel n (PathP≡Path A x y i))
(isOfHLevelPath n h _ _)
isProp→isContrPathP : {A : I → Type ℓ} → (∀ i → isProp (A i))
→ (x : A i0) (y : A i1) → isContr (PathP A x y)
isProp→isContrPathP h x y = isProp→PathP h x y , isOfHLevelPathP 1 (h i1) x y _
-- h-level of isOfHLevel
isPropIsOfHLevel : (n : HLevel) → isProp (isOfHLevel n A)
isPropIsOfHLevel 0 = isPropIsContr
isPropIsOfHLevel 1 = isPropIsProp
isPropIsOfHLevel (suc (suc n)) f g i a b =
isPropIsOfHLevel (suc n) (f a b) (g a b) i
isPropIsSet : isProp (isSet A)
isPropIsSet = isPropIsOfHLevel 2
isPropIsGroupoid : isProp (isGroupoid A)
isPropIsGroupoid = isPropIsOfHLevel 3
isPropIs2Groupoid : isProp (is2Groupoid A)
isPropIs2Groupoid = isPropIsOfHLevel 4
-- Fillers for cubes from h-level
isSet→isSet' : isSet A → isSet' A
isSet→isSet' {A = A} Aset a₀₋ a₁₋ a₋₀ a₋₁ =
transport⁻ (PathP≡Path (λ i → a₋₀ i ≡ a₋₁ i) a₀₋ a₁₋) (Aset _ _ _ _)
isSet'→isSet : isSet' A → isSet A
isSet'→isSet {A = A} Aset' x y p q = Aset' p q refl refl
isGroupoid→isGroupoid' : isGroupoid A → isGroupoid' A
isGroupoid→isGroupoid' {A = A} Agpd a₀₋₋ a₁₋₋ a₋₀₋ a₋₁₋ a₋₋₀ a₋₋₁ =
transport⁻ (PathP≡Path (λ i → Square (a₋₀₋ i) (a₋₁₋ i) (a₋₋₀ i) (a₋₋₁ i)) a₀₋₋ a₁₋₋)
(isGroupoid→isPropSquare _ _ _ _ _ _)
where
isGroupoid→isPropSquare :
{a₀₀ a₀₁ : A} (a₀₋ : a₀₀ ≡ a₀₁)
{a₁₀ a₁₁ : A} (a₁₋ : a₁₀ ≡ a₁₁)
(a₋₀ : a₀₀ ≡ a₁₀) (a₋₁ : a₀₁ ≡ a₁₁)
→ isProp (Square a₀₋ a₁₋ a₋₀ a₋₁)
isGroupoid→isPropSquare a₀₋ a₁₋ a₋₀ a₋₁ =
transport⁻
(cong isProp (PathP≡Path (λ i → a₋₀ i ≡ a₋₁ i) a₀₋ a₁₋))
(Agpd _ _ _ _)
isGroupoid'→isGroupoid : isGroupoid' A → isGroupoid A
isGroupoid'→isGroupoid Agpd' x y p q r s = Agpd' r s refl refl refl refl
-- hlevels are preserved by retracts (and consequently equivalences)
isContrRetract
: ∀ {B : Type ℓ}
→ (f : A → B) (g : B → A)
→ (h : retract f g)
→ (v : isContr B) → isContr A
isContrRetract f g h (b , p) = (g b , λ x → (cong g (p (f x))) ∙ (h x))
isPropRetract
: {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isProp B → isProp A
isPropRetract f g h p x y i =
hcomp
(λ j → λ
{ (i = i0) → h x j
; (i = i1) → h y j})
(g (p (f x) (f y) i))
isOfHLevelRetract
: (n : HLevel) {B : Type ℓ}
(f : A → B) (g : B → A)
(h : (x : A) → g (f x) ≡ x)
→ isOfHLevel n B → isOfHLevel n A
isOfHLevelRetract 0 = isContrRetract
isOfHLevelRetract 1 = isPropRetract
isOfHLevelRetract (suc (suc n)) f g h ofLevel x y =
isOfHLevelRetract (suc n)
(cong f)
(λ q i →
hcomp
(λ j → λ
{ (i = i0) → h x j
; (i = i1) → h y j})
(g (q i)))
(λ p k i →
hcomp
(λ j → λ
{ (i = i0) → h x (j ∨ k)
; (i = i1) → h y (j ∨ k)
; (k = i1) → p i})
(h (p i) k))
(ofLevel (f x) (f y))
isOfHLevelRespectEquiv : {A : Type ℓ} {B : Type ℓ'} → (n : HLevel) → A ≃ B → isOfHLevel n A → isOfHLevel n B
isOfHLevelRespectEquiv n eq = isOfHLevelRetract n (invEq eq) (eq .fst) (retEq eq)
-- h-level of Σ-types
isContrΣ : isContr A → ((x : A) → isContr (B x)) → isContr (Σ A B)
isContrΣ {A = A} {B = B} (a , p) q =
let h : (x : A) (y : B x) → (q x) .fst ≡ y
h x y = (q x) .snd y
in (( a , q a .fst)
, ( λ x i → p (x .fst) i
, h (p (x .fst) i) (transp (λ j → B (p (x .fst) (i ∨ ~ j))) i (x .snd)) i))
isContrΣ′ : (ca : isContr A) → isContr (B (fst ca)) → isContr (Σ A B)
isContrΣ′ ca cb = isContrΣ ca (λ x → subst _ (snd ca x) cb)
Σ≡Prop-equiv
: (pB : (x : A) → isProp (B x)) {u v : Σ[ a ∈ A ] B a}
→ isEquiv (Σ≡Prop pB {u} {v})
Σ≡Prop-equiv {A = A} pB {u} {v} = isoToIsEquiv (iso (Σ≡Prop pB) (cong fst) sq (λ _ → refl))
where sq : (p : u ≡ v) → Σ≡Prop pB (cong fst p) ≡ p
sq p j i = (p i .fst) , isProp→PathP (λ i → isOfHLevelPath 1 (pB (fst (p i)))
(Σ≡Prop pB {u} {v} (cong fst p) i .snd)
(p i .snd) )
refl refl i j
isPropΣ : isProp A → ((x : A) → isProp (B x)) → isProp (Σ A B)
isPropΣ pA pB t u = Σ≡Prop pB (pA (t .fst) (u .fst))
isOfHLevelΣ : ∀ n → isOfHLevel n A → ((x : A) → isOfHLevel n (B x))
→ isOfHLevel n (Σ A B)
isOfHLevelΣ 0 = isContrΣ
isOfHLevelΣ 1 = isPropΣ
isOfHLevelΣ {B = B} (suc (suc n)) h1 h2 x y =
let h3 : isOfHLevel (suc n) (ΣPathTransport x y)
h3 = isOfHLevelΣ (suc n) (h1 (fst x) (fst y)) λ p → h2 (p i1)
(subst B p (snd x)) (snd y)
in transport (λ i → isOfHLevel (suc n) (ΣPathTransport≡PathΣ x y i)) h3
isSetΣ : isSet A → ((x : A) → isSet (B x)) → isSet (Σ A B)
isSetΣ = isOfHLevelΣ 2
isGroupoidΣ : isGroupoid A → ((x : A) → isGroupoid (B x)) → isGroupoid (Σ A B)
isGroupoidΣ = isOfHLevelΣ 3
is2GroupoidΣ : is2Groupoid A → ((x : A) → is2Groupoid (B x)) → is2Groupoid (Σ A B)
is2GroupoidΣ = isOfHLevelΣ 4
-- h-level of ×
isProp× : {A : Type ℓ} {B : Type ℓ'} → isProp A → isProp B → isProp (A × B)
isProp× pA pB = isPropΣ pA (λ _ → pB)
isProp×2 : {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''}
→ isProp A → isProp B → isProp C → isProp (A × B × C)
isProp×2 pA pB pC = isProp× pA (isProp× pB pC)
isProp×3 : {A : Type ℓ} {B : Type ℓ'} {C : Type ℓ''} {D : Type ℓ'''}
→ isProp A → isProp B → isProp C → isProp D → isProp (A × B × C × D)
isProp×3 pA pB pC pD = isProp×2 pA pB (isProp× pC pD)
isOfHLevel× : ∀ {A : Type ℓ} {B : Type ℓ'} n → isOfHLevel n A → isOfHLevel n B
→ isOfHLevel n (A × B)
isOfHLevel× n hA hB = isOfHLevelΣ n hA (λ _ → hB)
isSet× : ∀ {A : Type ℓ} {B : Type ℓ'} → isSet A → isSet B → isSet (A × B)
isSet× = isOfHLevel× 2
isGroupoid× : ∀ {A : Type ℓ} {B : Type ℓ'} → isGroupoid A → isGroupoid B
→ isGroupoid (A × B)
isGroupoid× = isOfHLevel× 3
is2Groupoid× : ∀ {A : Type ℓ} {B : Type ℓ'} → is2Groupoid A → is2Groupoid B
→ is2Groupoid (A × B)
is2Groupoid× = isOfHLevel× 4
-- h-level of Π-types
isOfHLevelΠ : ∀ n → ((x : A) → isOfHLevel n (B x))
→ isOfHLevel n ((x : A) → B x)
isOfHLevelΠ 0 h = (λ x → fst (h x)) , λ f i y → snd (h y) (f y) i
isOfHLevelΠ 1 h f g i x = (h x) (f x) (g x) i
isOfHLevelΠ (suc (suc n)) h f g =
subst (isOfHLevel (suc n)) funExtPath (isOfHLevelΠ (suc n) λ x → h x (f x) (g x))
isPropΠ : (h : (x : A) → isProp (B x)) → isProp ((x : A) → B x)
isPropΠ = isOfHLevelΠ 1
isPropΠ2 : (h : (x : A) (y : B x) → isProp (C x y))
→ isProp ((x : A) (y : B x) → C x y)
isPropΠ2 h = isPropΠ λ x → isPropΠ λ y → h x y
isPropΠ3 : (h : (x : A) (y : B x) (z : C x y) → isProp (D x y z))
→ isProp ((x : A) (y : B x) (z : C x y) → D x y z)
isPropΠ3 h = isPropΠ λ x → isPropΠ λ y → isPropΠ λ z → h x y z
isPropΠ4 : (h : (x : A) (y : B x) (z : C x y) (w : D x y z) → isProp (E x y z w))
→ isProp ((x : A) (y : B x) (z : C x y) (w : D x y z) → E x y z w)
isPropΠ4 h = isPropΠ λ _ → isPropΠ3 λ _ → h _ _
isPropImplicitΠ : (h : (x : A) → isProp (B x)) → isProp ({x : A} → B x)
isPropImplicitΠ h f g i {x} = h x (f {x}) (g {x}) i
isProp→ : {A : Type ℓ} {B : Type ℓ'} → isProp B → isProp (A → B)
isProp→ pB = isPropΠ λ _ → pB
isSetΠ : ((x : A) → isSet (B x)) → isSet ((x : A) → B x)
isSetΠ = isOfHLevelΠ 2
isSetΠ2 : (h : (x : A) (y : B x) → isSet (C x y))
→ isSet ((x : A) (y : B x) → C x y)
isSetΠ2 h = isSetΠ λ x → isSetΠ λ y → h x y
isGroupoidΠ : ((x : A) → isGroupoid (B x)) → isGroupoid ((x : A) → B x)
isGroupoidΠ = isOfHLevelΠ 3
isGroupoidΠ2 : (h : (x : A) (y : B x) → isGroupoid (C x y)) → isGroupoid ((x : A) (y : B x) → C x y)
isGroupoidΠ2 h = isGroupoidΠ λ _ → isGroupoidΠ λ _ → h _ _
isGroupoidΠ3 : (h : (x : A) (y : B x) (z : C x y) → isGroupoid (D x y z))
→ isGroupoid ((x : A) (y : B x) (z : C x y) → D x y z)
isGroupoidΠ3 h = isGroupoidΠ λ _ → isGroupoidΠ2 λ _ → h _ _
isGroupoidΠ4 : (h : (x : A) (y : B x) (z : C x y) (w : D x y z) → isGroupoid (E x y z w))
→ isGroupoid ((x : A) (y : B x) (z : C x y) (w : D x y z) → E x y z w)
isGroupoidΠ4 h = isGroupoidΠ λ _ → isGroupoidΠ3 λ _ → h _ _
is2GroupoidΠ : ((x : A) → is2Groupoid (B x)) → is2Groupoid ((x : A) → B x)
is2GroupoidΠ = isOfHLevelΠ 4
isOfHLevelΠ⁻ : ∀ {A : Type ℓ} {B : Type ℓ'} n
→ isOfHLevel n (A → B) → (A → isOfHLevel n B)
isOfHLevelΠ⁻ 0 h x = fst h x , λ y → funExt⁻ (snd h (const y)) x
isOfHLevelΠ⁻ 1 h x y z = funExt⁻ (h (const y) (const z)) x
isOfHLevelΠ⁻ (suc (suc n)) h x y z =
isOfHLevelΠ⁻ (suc n) (subst (isOfHLevel (suc n)) (sym funExtPath) (h (const y) (const z))) x
-- h-level of A ≃ B and A ≡ B
isOfHLevel≃ : ∀ n → {A B : Type ℓ} (hA : isOfHLevel n A) (hB : isOfHLevel n B) → isOfHLevel n (A ≃ B)
isOfHLevel≃ zero {A = A} {B = B} hA hB = A≃B , contr
where
A≃B : A ≃ B
A≃B = isoToEquiv (iso (λ _ → fst hB) (λ _ → fst hA) (snd hB ) (snd hA))
contr : (y : A ≃ B) → A≃B ≡ y
contr y = Σ≡Prop isPropIsEquiv (funExt (λ a → snd hB (fst y a)))
isOfHLevel≃ (suc n) hA hB =
isOfHLevelΣ (suc n) (isOfHLevelΠ (suc n) (λ _ → hB))
(λ a → subst (λ n → isOfHLevel n (isEquiv a)) (+-comm n 1) (isOfHLevelPlus n (isPropIsEquiv a)))
isOfHLevel≡ : ∀ n → {A B : Type ℓ} (hA : isOfHLevel n A) (hB : isOfHLevel n B) →
isOfHLevel n (A ≡ B)
isOfHLevel≡ n hA hB = isOfHLevelRespectEquiv n (invEquiv univalence) (isOfHLevel≃ n hA hB)
-- h-level of TypeOfHLevel
isPropHContr : isProp (TypeOfHLevel ℓ 0)
isPropHContr x y = Σ≡Prop (λ _ → isPropIsContr) (isOfHLevel≡ 0 (x .snd) (y .snd) .fst)
isOfHLevelTypeOfHLevel : ∀ n → isOfHLevel (suc n) (TypeOfHLevel ℓ n)
isOfHLevelTypeOfHLevel 0 = isPropHContr
isOfHLevelTypeOfHLevel (suc n) x y = subst (isOfHLevel (suc n)) eq (isOfHLevel≡ (suc n) (snd x) (snd y))
where eq : ∀ {A B : Type ℓ} {hA : isOfHLevel (suc n) A} {hB : isOfHLevel (suc n) B}
→ (A ≡ B) ≡ ((A , hA) ≡ (B , hB))
eq = ua (_ , Σ≡Prop-equiv (λ _ → isPropIsOfHLevel (suc n)))
isSetHProp : isSet (hProp ℓ)
isSetHProp = isOfHLevelTypeOfHLevel 1
-- h-level of lifted type
isOfHLevelLift : ∀ {ℓ ℓ'} (n : HLevel) {A : Type ℓ} → isOfHLevel n A → isOfHLevel n (Lift {j = ℓ'} A)
isOfHLevelLift n = isOfHLevelRetract n lower lift λ _ → refl
----------------------------
-- More consequences of isProp and isContr
inhProp→isContr : A → isProp A → isContr A
inhProp→isContr x h = x , h x
extend : isContr A → (∀ φ → (u : Partial φ A) → Sub A φ u)
extend (x , p) φ u = inS (hcomp (λ { j (φ = i1) → p (u 1=1) j }) x)
isContrPartial→isContr : ∀ {ℓ} {A : Type ℓ}
→ (extend : ∀ φ → Partial φ A → A)
→ (∀ u → u ≡ (extend i1 λ { _ → u}))
→ isContr A
isContrPartial→isContr {A = A} extend law
= ex , λ y → law ex ∙ (λ i → Aux.v y i) ∙ sym (law y)
where ex = extend i0 empty
module Aux (y : A) (i : I) where
φ = ~ i ∨ i
u : Partial φ A
u = λ { (i = i0) → ex ; (i = i1) → y }
v = extend φ u
-- Dependent h-level over a type
isOfHLevelDep : HLevel → {A : Type ℓ} (B : A → Type ℓ') → Type (ℓ-max ℓ ℓ')
isOfHLevelDep 0 {A = A} B = {a : A} → Σ[ b ∈ B a ] ({a' : A} (b' : B a') (p : a ≡ a') → PathP (λ i → B (p i)) b b')
isOfHLevelDep 1 {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) (p : a0 ≡ a1) → PathP (λ i → B (p i)) b0 b1
isOfHLevelDep (suc (suc n)) {A = A} B = {a0 a1 : A} (b0 : B a0) (b1 : B a1) → isOfHLevelDep (suc n) {A = a0 ≡ a1} (λ p → PathP (λ i → B (p i)) b0 b1)
isOfHLevel→isOfHLevelDep : (n : HLevel)
→ {A : Type ℓ} {B : A → Type ℓ'} (h : (a : A) → isOfHLevel n (B a)) → isOfHLevelDep n {A = A} B
isOfHLevel→isOfHLevelDep 0 h {a} =
(h a .fst , λ b' p → isProp→PathP (λ i → isContr→isProp (h (p i))) (h a .fst) b')
isOfHLevel→isOfHLevelDep 1 h = λ b0 b1 p → isProp→PathP (λ i → h (p i)) b0 b1
isOfHLevel→isOfHLevelDep (suc (suc n)) {A = A} {B} h {a0} {a1} b0 b1 =
isOfHLevel→isOfHLevelDep (suc n) (λ p → helper a1 p b1)
where
helper : (a1 : A) (p : a0 ≡ a1) (b1 : B a1) →
isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1)
helper a1 p b1 = J
(λ a1 p → ∀ b1 → isOfHLevel (suc n) (PathP (λ i → B (p i)) b0 b1))
(λ _ → h _ _ _) p b1
| {
"alphanum_fraction": 0.5590241504,
"avg_line_length": 38.1995305164,
"ext": "agda",
"hexsha": "864b4c0e594333f22aecd852ec9d4499a938f4c6",
"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": "f6771617374bfe65a7043d00731fed5a673aa729",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "knrafto/cubical",
"max_forks_repo_path": "Cubical/Foundations/HLevels.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729",
"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": "knrafto/cubical",
"max_issues_repo_path": "Cubical/Foundations/HLevels.agda",
"max_line_length": 150,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f6771617374bfe65a7043d00731fed5a673aa729",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "knrafto/cubical",
"max_stars_repo_path": "Cubical/Foundations/HLevels.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7235,
"size": 16273
} |
-- Andreas, 2017-03-10, issue #2493, reported by nad
-- {-# OPTIONS -v tc.meta.assign:10 -v tc.size:90 -v tc:30 #-}
A : Set
A = {!!}
P : A → Set
P = {!λ _ → ?!} -- give
-- Giving this made Agda loop as it solved ?0 := A.
-- Solution: don't assign metas during CheckInternal!
| {
"alphanum_fraction": 0.5949820789,
"avg_line_length": 23.25,
"ext": "agda",
"hexsha": "0da323d33d71ec847e5750707987fbe88285df36",
"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/Issue2493.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/Issue2493.agda",
"max_line_length": 62,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue2493.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": 97,
"size": 279
} |
{- 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 Haskell.Modules.RWS.RustAnyHow
import LibraBFT.Impl.Consensus.BlockStorage.BlockRetriever as BlockRetriever
import LibraBFT.Impl.Consensus.BlockStorage.BlockStore as BlockStore
import LibraBFT.Impl.Consensus.BlockStorage.BlockTree as BlockTree
import LibraBFT.Impl.OBM.ECP-LBFT-OBM-Diff.ECP-LBFT-OBM-Diff-1 as ECP-LBFT-OBM-Diff-1
import LibraBFT.Impl.Consensus.ConsensusTypes.Vote as Vote
import LibraBFT.Impl.Consensus.PersistentLivenessStorage as PersistentLivenessStorage
open import LibraBFT.Impl.OBM.Logging.Logging
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import Optics.All
open import Util.Hash
open import Util.Prelude
------------------------------------------------------------------------------
open import Data.String using (String)
module LibraBFT.Impl.Consensus.BlockStorage.SyncManager where
data NeedFetchResult : Set where
QCRoundBeforeRoot QCAlreadyExist QCBlockExist NeedFetch : NeedFetchResult
------------------------------------------------------------------------------
fastForwardSyncM : QuorumCert → BlockRetriever → LBFT (Either ErrLog RecoveryData)
fetchQuorumCertM : QuorumCert → BlockRetriever → LBFT (Either ErrLog Unit)
insertQuorumCertM : QuorumCert → BlockRetriever → LBFT (Either ErrLog Unit)
syncToHighestCommitCertM : QuorumCert → BlockRetriever → LBFT (Either ErrLog Unit)
------------------------------------------------------------------------------
needSyncForQuorumCert : QuorumCert → BlockStore → Either ErrLog Bool
needSyncForQuorumCert qc bs = maybeS (bs ^∙ bsRoot) (Left fakeErr) {-bsRootErrL here-} $ λ btr → Right
(not ( BlockStore.blockExists (qc ^∙ qcCommitInfo ∙ biId) bs
∨ ⌊ btr ^∙ ebRound ≥?ℕ qc ^∙ qcCommitInfo ∙ biRound ⌋ ))
where
here' : List String → List String
here' t = "SyncManager" ∷ "needSyncForQuorumCert" ∷ t
needFetchForQuorumCert : QuorumCert → BlockStore → Either ErrLog NeedFetchResult
needFetchForQuorumCert qc bs = maybeS (bs ^∙ bsRoot) (Left fakeErr) {-bsRootErrL here-} $ λ btr →
grd‖ qc ^∙ qcCertifiedBlock ∙ biRound <?ℕ btr ^∙ ebRound ≔
Right QCRoundBeforeRoot
‖ is-just (BlockStore.getQuorumCertForBlock (qc ^∙ qcCertifiedBlock ∙ biId) bs) ≔
Right QCAlreadyExist
‖ BlockStore.blockExists (qc ^∙ qcCertifiedBlock ∙ biId) bs ≔
Right QCBlockExist
‖ otherwise≔
Right NeedFetch
where
here' : List String → List String
here' t = "SyncManager" ∷ "needFetchForQuorumCert" ∷ t
------------------------------------------------------------------------------
addCertsM : SyncInfo → BlockRetriever → LBFT (Either ErrLog Unit)
addCertsM {-reason-} syncInfo retriever =
syncToHighestCommitCertM (syncInfo ^∙ siHighestCommitCert) retriever ∙?∙ \_ ->
insertQuorumCertM {-reason-} (syncInfo ^∙ siHighestCommitCert) retriever ∙?∙ \_ ->
insertQuorumCertM {-reason-} (syncInfo ^∙ siHighestQuorumCert) retriever ∙?∙ \_ ->
maybeSD (syncInfo ^∙ siHighestTimeoutCert) (ok unit) $
\tc -> BlockStore.insertTimeoutCertificateM tc
------------------------------------------------------------------------------
module insertQuorumCertM (qc : QuorumCert) (retriever : BlockRetriever) where
step₀ : LBFT (Either ErrLog Unit)
step₁ : BlockStore → LBFT (Either ErrLog Unit)
step₁-else : LBFT (Either ErrLog Unit)
step₂ : ExecutedBlock → LBFT (Either ErrLog Unit)
step₃ : LedgerInfoWithSignatures → LBFT (Either ErrLog Unit)
step₀ = do
bs ← use lBlockStore
_ ← case⊎D needFetchForQuorumCert qc bs of λ where
(Left e) →
bail e
(Right NeedFetch) →
fetchQuorumCertM qc retriever
∙^∙ withErrCtx ("" ∷ [])
(Right QCBlockExist) →
BlockStore.insertSingleQuorumCertM qc ∙^∙ withErrCtx ("" ∷ []) ∙?∙ λ _ → do
use lBlockStore >>= const (logInfo fakeInfo) -- InfoBlockStoreShort (here [lsQC qc])
ok unit
(Right _) →
ok unit
step₁ bs
step₁ bs = do
maybeSD (bs ^∙ bsRoot) (bail fakeErr) $ λ bsr →
ifD (bsr ^∙ ebRound) <?ℕ (qc ^∙ qcCommitInfo ∙ biRound)
then step₂ bsr
else
step₁-else
step₂ bsr = do
let finalityProof = qc ^∙ qcLedgerInfo
BlockStore.commitM finalityProof ∙?∙ λ xx →
step₃ finalityProof
step₃ finalityProof = do
ifD qc ^∙ qcEndsEpoch
then ECP-LBFT-OBM-Diff-1.e_SyncManager_insertQuorumCertM_commit finalityProof
else ok unit
step₁-else =
ok unit
insertQuorumCertM = insertQuorumCertM.step₀
------------------------------------------------------------------------------
loop1 : BlockRetriever → List Block → QuorumCert → LBFT (Either ErrLog (List Block))
loop2 : List Block → LBFT (Either ErrLog Unit)
hereFQCM' : List String → List String
fetchQuorumCertM qc retriever =
loop1 retriever [] qc ∙?∙ loop2
-- TODO-1 PROVE IT TERMINATES
{-# TERMINATING #-}
loop1 retriever pending retrieveQC = do
bs ← use lBlockStore
ifD (BlockStore.blockExists (retrieveQC ^∙ qcCertifiedBlock ∙ biId) bs)
then ok pending
else
BlockRetriever.retrieveBlockForQCM retriever retrieveQC 1
∙^∙ withErrCtx (hereFQCM' ("loop1" ∷ [])) ∙?∙ λ where
(block ∷ []) → loop1 retriever (block ∷ pending) (block ^∙ bQuorumCert)
(_ ∷ _ ∷ _) → errorCase
[] → errorCase
where
errorCase : LBFT (Either ErrLog (List Block))
errorCase = do
-- let msg = here ["loop1", "retrieveBlockForQCM returned more than asked for"]
-- logErrExit msg
bail fakeErr -- (ErrL msg)
loop2 = λ where
[] -> ok unit
(block ∷ bs) →
BlockStore.insertSingleQuorumCertM (block ^∙ bQuorumCert)
∙^∙ withErrCtx (hereFQCM' ("loop2" ∷ [])) ∙?∙ \_ ->
BlockStore.executeAndInsertBlockM block ∙?∙ \_ ->
loop2 bs
hereFQCM' t = "SyncManager" ∷ "fetchQuorumCertM" ∷ t
------------------------------------------------------------------------------
syncToHighestCommitCertM highestCommitCert retriever = do
bs ← use lBlockStore
eitherSD (needSyncForQuorumCert highestCommitCert bs) bail $ λ b →
if not b
then ok unit
else
fastForwardSyncM highestCommitCert retriever ∙?∙ \rd -> do
logInfo fakeInfo -- (here ["fastForwardSyncM success", lsRD rd])
BlockStore.rebuildM (rd ^∙ rdRoot) (rd ^∙ rdRootMetadata) (rd ^∙ rdBlocks) (rd ^∙ rdQuorumCerts)
∙^∙ withErrCtx (here' []) ∙?∙ λ _ -> do
whenD (highestCommitCert ^∙ qcEndsEpoch) $ do
me ← use (lRoundManager ∙ rmObmMe)
-- TODO-1 : Epoch Change Proof
-- let ecp = EpochChangeProof ∙ new [highestCommitCert ^∙ qcLedgerInfo] False
logInfo fakeInfo -- (here ["fastForwardSyncM detected an EpochChange"])
-- TODO-1 : uncomment this and remove pure unit when Epoch Change supported
-- act (BroadcastEpochChangeProof lEC ecp (mkNodesInOrder1 me))
pure unit
ok unit
where
here' : List String → List String
here' t = "SyncManager" ∷ "syncToHighestCommitCertM" ∷ t
------------------------------------------------------------------------------
fastForwardSyncM highestCommitCert retriever = do
logInfo fakeInfo -- (here' [ "start state sync with peer", lsA (retriever^.brPreferredPeer)
-- , "to block", lsBI (highestCommitCert^.qcCommitInfo) ])
BlockRetriever.retrieveBlockForQCM retriever highestCommitCert 3 ∙?∙ λ where
blocks@(_ ∷ _ ∷ i ∷ []) ->
if highestCommitCert ^∙ qcCommitInfo ∙ biId /= i ^∙ bId
then bail fakeErr -- (here' [ "should have a 3-chain"
-- , lsHV (highestCommitCert^.qcCommitInfo.biId), lsHV (i^.bId) ]))
else continue blocks
x -> bail fakeErr -- (here' ["incorrect number of blocks returned", show (length x)]))
where
here' : List String → List String
zipWithNatsFrom : {A : Set} → ℕ → List A → List (ℕ × A)
zipWithNatsFrom n = λ where
[] → []
(x ∷ xs) → (n , x) ∷ zipWithNatsFrom (n + 1) xs
checkBlocksMatchQCs : List QuorumCert → List (ℕ × Block) → LBFT (Either ErrLog Unit)
continue : List Block → LBFT (Either ErrLog RecoveryData)
continue blocks = do
logInfo fakeInfo -- (here' (["received blocks"] <> fmap (lsHV . (^.bId)) blocks))
let quorumCerts = highestCommitCert ∷ fmap (_^∙ bQuorumCert) blocks
logInfo fakeInfo -- (here' (["quorumCerts"] <> fmap (lsHV . (^.qcCommitInfo.biId)) quorumCerts))
checkBlocksMatchQCs quorumCerts (zipWithNatsFrom 0 blocks) ∙?∙ λ _ →
PersistentLivenessStorage.saveTreeM blocks quorumCerts ∙?∙ λ _ → do
-- TODO-1 : requires adding bsStorage to BlockStore
-- use (lBlockStore ∙ bsStorage) >>= λ x → logInfo fakeInfo -- (here' ["XXX", lsPLS x])
-- OBM NOT NEEDED: state_computer.sync_to
-- This returns recovery data
PersistentLivenessStorage.startM ∙^∙ withErrCtx (here' [])
checkBlocksMatchQCs quorumCerts = λ where
[] → ok unit
((i , block) ∷ xs) →
maybeSD (quorumCerts !? i)
(bail fakeErr) -- (here' ["checkBlocksMatchQCs", "!?"])
$ λ qc →
ifD (block ^∙ bId /= qc ^∙ qcCertifiedBlock ∙ biId)
then (do
logInfo fakeInfo -- [lsHV (block^.bId), lsB block]
logInfo fakeInfo -- [lsHV (quorumCerts Prelude.!! i ^.qcCertifiedBlock.biId)
-- ,lsQC (quorumCerts Prelude.!! i)]
bail fakeErr) -- (here' ("checkBlocksMatchQCs" ∷ "/=" ∷ []))
else checkBlocksMatchQCs quorumCerts xs
here' t = "SyncManager" ∷ "fastForwardSyncM" ∷ t
| {
"alphanum_fraction": 0.6030998627,
"avg_line_length": 43.9396551724,
"ext": "agda",
"hexsha": "c4f1d4a855becbe50ee1f4eb9e422630791b29fb",
"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/Consensus/BlockStorage/SyncManager.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/Consensus/BlockStorage/SyncManager.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/Consensus/BlockStorage/SyncManager.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2942,
"size": 10194
} |
open import Prelude
module Implicits.Oliveira.Deterministic.Decidable where
open import Data.Fin.Substitution
open import Implicits.Oliveira.Types
open import Implicits.Oliveira.Terms
open import Implicits.Oliveira.Contexts
open import Implicits.Oliveira.Substitutions
open import Implicits.Oliveira.Substitutions.Lemmas
open import Implicits.Oliveira.Deterministic.Resolution
open import Implicits.Oliveira.Types.Unification
open import Data.Star hiding (map)
MICtx : ℕ → ℕ → Set
MICtx m ν = List (MetaType m ν)
private
module M = MetaTypeMetaSubst
module T = MetaTypeTypeSubst
{-
{-# NO_TERMINATION_CHECK #-}
_,_amatch_ : ∀ {m ν} → (MetaType m ν) → (ρs : MICtx m ν) → (τ : SimpleType ν) → Maybe (ICtx ν)
(a ⇒ b) , ρs amatch τ = b , a List.∷ ρs amatch τ
∀' x , ρs amatch τ = open-meta x , (List.map meta-weaken ρs) amatch τ
(simpl x) , ρs amatch τ with mgu (simpl x) τ
(simpl x) , ρs amatch τ | just (u , proj₂) =
just $ List.map (λ r → from-meta $ substitute (asub u) r) ρs
(simpl x) , ρs amatch τ | nothing = nothing
_match_ : ∀ {ν} → (Type ν) → (SimpleType ν) → Maybe (ICtx ν)
r match a = (to-meta {zero} r) , List.[] amatch a
{-# NO_TERMINATION_CHECK #-}
lem-a6 : ∀ {m ν} {ρs ρs'} (a : MetaType m ν) (τ : SimpleType ν) → a , ρs amatch τ ≡ just ρs' →
(∃ λ (u : AList ν m zero) → (from-meta $ substitute (asub u) a) ◁ τ)
lem-a6 {ρs = ρs} (a ⇒ b) τ m
with _,_amatch_ b (a List.∷ ρs) τ | inspect (_,_amatch_ b (a List.∷ ρs)) τ
lem-a6 (a ⇒ b) τ refl | ._ | reveal[ eq ] with lem-a6 b τ eq
lem-a6 (a ⇒ b) τ refl | ._ | reveal[ eq ] | u , b/u◁τ = u , (m-iabs b/u◁τ)
lem-a6 {ρs = ρs} (∀' a) τ m
with open-meta a , (List.map meta-weaken ρs) amatch τ | inspect (_,_amatch_ (open-meta a) (List.map meta-weaken ρs)) τ
lem-a6 (∀' a) τ refl | ._ | reveal[ eq ] with lem-a6 (open-meta a) τ eq
lem-a6 (∀' a) τ refl | ._ | reveal[ eq ] | (t' // x ◅ u , b/u◁τ) = {!!} -- {!u!} , (m-tabs {!!})
lem-a6 (simpl x) τ m with mgu (simpl x) τ | inspect (mgu (simpl x)) τ
lem-a6 (simpl x) τ refl | just (u , proj₂) | reveal[ eq ] =
u , subst (λ u → u ◁ τ) (sym $ mgu-unifies (simpl x) τ {!!}) m-simp
lem-a6 (simpl x) τ () | nothing
_match1st_ : ∀ {ν} (Δ : ICtx ν) → (a : SimpleType ν) → Maybe (Type ν × ICtx ν)
List.[] match1st a = nothing
(x List.∷ Δ) match1st a with x match a
(x List.∷ Δ) match1st a | just z = just (x , z)
(x List.∷ Δ) match1st a | nothing = Δ match1st a
_⊢alg_ : ∀ {ν n} (K : Ktx ν n) → (a : Type ν) → Dec (K ⊢ᵣ a)
(Γ , Δ) ⊢alg simpl x with Δ match1st x
(Γ , Δ) ⊢alg simpl x | just (proj₁ , proj₂) = {!!}
(Γ , Δ) ⊢alg simpl x | nothing = {!!}
K ⊢alg (a ⇒ b) with (a ∷K K) ⊢alg b
K ⊢alg (a ⇒ b) | yes p = yes $ r-iabs a p
K ⊢alg (a ⇒ b) | no ¬p = no (λ{ (r-iabs .a x) → ¬p x })
K ⊢alg ∀' a with (ktx-weaken K) ⊢alg a
K ⊢alg ∀' a | yes p = yes (r-tabs p)
K ⊢alg ∀' a | no ¬p = no (λ{ (r-tabs p) → ¬p p })
-}
module relational where
data _⊢_amatch_↠_ {m ν} : (ρs : MICtx m ν) → MetaType m ν → SimpleType ν → (ICtx ν) → Set where
mtc-tabs : ∀ {r ρs ρs' a} → (List.map meta-weaken ρs) ⊢ (open-meta r) amatch a ↠ ρs' →
ρs ⊢ ∀' r amatch a ↠ ρs'
mtc-iabs : ∀ {ρs ρs' a b c} → (a List.∷ ρs) ⊢ b amatch c ↠ ρs' → ρs ⊢ a ⇒ b amatch c ↠ ρs'
mtc-simp : ∀ {ρs a b} → (u : Unifiable (simpl a) b) →
ρs ⊢ (simpl a) amatch b ↠ (List.map (λ r → from-meta $ r M./ (asub (proj₁ u))) ρs)
_⊢match_↠_ : ∀ {ν} → (Type ν) → (SimpleType ν) → ICtx ν → Set
r ⊢match a ↠ ρs = List.[] ⊢ (to-meta {zero} r) amatch a ↠ ρs
data _⊢match1st_↠_ {ν} : List (Type ν) → (a : SimpleType ν) → ICtx ν → Set where
m1-head : ∀ {rs ρs} {r : Type ν} {a} → r ⊢match a ↠ ρs → (r List.∷ rs) ⊢match1st a ↠ ρs
m1-tail : ∀ {rs ρs} {r : Type ν} {a} → ¬ r ⊢match a ↠ ρs → rs ⊢match1st a ↠ ρs →
(r List.∷ rs) ⊢match1st a ↠ ρs
{-}
gather : ∀ {ν} {ρs ρs' : ICtx ν} {a} → ρs ⊢match1st a ↠ ρs' → List (Type ν)
gather (m1-head x) = gather' x
where
gather' : ∀ {m ν} {ρs : MICtx m ν} {r a} → ρs ⊢ r amatch a ↠→ List (Type ν)
gather' (mtc-tabs x) = gather' x
gather' (mtc-iabs x) = gather' x
gather' {ρs = ρs} (mtc-simp {a = a} {b = b} u) =
(List.map (λ r → from-meta $ substitute (asub (proj₁ u)) r) ρs)
gather (m1-tail ¬x xs) = gather xs
-}
{-# NO_TERMINATION_CHECK #-}
amatch : ∀ {m ν} → (ρs : MICtx m ν) → (r : MetaType m ν) (a : SimpleType ν) →
Dec (∃ λ ρs' → ρs ⊢ r amatch a ↠ ρs')
amatch ρs (simpl x) a with mgu (simpl x) a | inspect (mgu (simpl x)) a
amatch ρs (simpl x) a | just mgu | _ = yes (, mtc-simp mgu)
amatch ρs (simpl x) a | nothing | reveal[ eq ] =
no (λ{ (._ , mtc-simp p) → (mgu-sound (simpl x) a eq) p})
amatch ρs (b ⇒ c) a with amatch (b List.∷ ρs) c a
amatch ρs (b ⇒ c) a | yes (_ , p) = yes $ , mtc-iabs p
amatch ρs (b ⇒ c) a | no ¬p = no (λ{ (._ , mtc-iabs x) → ¬p (, x)})
amatch ρs (∀' r) a with amatch (List.map meta-weaken ρs) (open-meta r) a
amatch ρs (∀' r) a | yes (_ , p) = yes $ , mtc-tabs p
amatch ρs (∀' r) a | no ¬p = no (λ{ (._ , mtc-tabs x) → ¬p (, x) })
match : ∀ {ν} → (r : Type ν) → (a : SimpleType ν) → Dec (∃ λ ρs → r ⊢match a ↠ ρs)
match r a = amatch List.[] (to-meta {zero} r) a
_match1st_ : ∀ {ν} (Δ : ICtx ν) → (a : SimpleType ν) → Dec (∃ λ ρs → Δ ⊢match1st a ↠ ρs)
List.[] match1st a = no (λ{ (_ , ()) })
(x List.∷ xs) match1st a with match x a
(x List.∷ xs) match1st a | yes (ρs , p) = yes (ρs , m1-head p)
(x List.∷ xs) match1st a | no ¬p with xs match1st a
(x List.∷ xs) match1st a | no ¬p | yes p = yes ? -- (, m1-tail ¬p p)
(x List.∷ xs) match1st a | no ¬p-head | no ¬p-tail =
no (λ{ (_ , m1-head p-head) → ¬p-head (, p-head) ; (_ , m1-tail _ p-tail) → ¬p-tail (, p-tail) })
module Lemmas where
lem-A3 : ∀ {ν n} (K : Ktx ν n) {a r} → proj₂ K ⟨ a ⟩= r → r List.∈ (proj₂ K)
lem-A3 f = proj₁ ∘ FirstLemmas.first⟶∈
lem-A6-1 : ∀ {m ν} → AList ν (suc m) zero → ASub ν (suc m) m × AList ν m zero
lem-A6-1 (t' // zero ◅ s) = t' // zero , s
lem-A6-1 {zero} (t' // suc () ◅ xs)
lem-A6-1 {suc m} (t' // x ◅ xs) with lem-A6-1 xs
lem-A6-1 {suc m} (t' // zero ◅ xs) | e , u = t' // zero , xs -- same case as above
lem-A6-1 {suc m} (t' // suc x ◅ xs) | e , u = asub-weaken e , t' // x ◅ u
lem-A6 : ∀ {m ν} {ρs ρs'} {a : MetaType m ν} {τ : SimpleType ν} → ρs ⊢ a amatch τ ↠ ρs' →
(∃ λ (u : AList ν m zero) → (from-meta $ a M./ (asub u)) ◁ τ)
lem-A6 {a = ∀' a} {τ = τ} (mtc-tabs x) with lem-A6 x
lem-A6 {a = ∀' a} {τ = τ} (mtc-tabs x) | u , p with lem-A6-1 u
lem-A6 {a = ∀' a} {τ = τ} (mtc-tabs x) | u , p | b , bs = bs , m-tabs {!p!}
where
-- q : from-meta (substitute (asub u) a []) ◁ τ
-- q = {!!}
lem-A6 (mtc-iabs x) with lem-A6 x
lem-A6 (mtc-iabs x) | u , p = u , (m-iabs p)
lem-A6 {τ = τ} (mtc-simp {a = a} (u , eq)) =
u , subst (flip _◁_ τ) (sym $ mgu-unifies (simpl a) τ (u , eq)) m-simp
lem-A6' : ∀ {ν} {ρs ρs' } {r : Type ν} {a} → r ◁ a → ρs ⊢ (to-meta {zero} r) amatch a ↠ ρs'
lem-A6' {a = a} m-simp = mtc-simp (mgu-id a)
lem-A6' (m-tabs r◁a) = mtc-tabs {!!}
lem-A6' (m-iabs r◁a) = mtc-iabs (lem-A6' r◁a)
-- p'haps counterintuitively the following proposition is NOT a theorem:
-- Δ⊢ᵣa⟶Δ≢Ø : ∀ {ν n} {K : Ktx ν n} {a} → K ⊢ᵣ a → ∃ λ b → b List.∈ (proj₂ K)
-- since [] ⊢ᵣ Nat ⇒ Nat through the r-iabs rule, but also:
-- [] ⊢ᵣ Nat ⇒ (Nat ⇒ Nat), etc; through recursion on r-iabs
lem-A7a : ∀ {ν} (Δ : ICtx ν) {a ρs} → Δ ⊢match1st a ↠ ρs → ∃ λ r → Δ ⟨ a ⟩= r
lem-A7a List.[] ()
lem-A7a (x List.∷ Δ) {a = a} (m1-head x₁) = , (l-head u Δ)
where
p = lem-A6 x₁
u = subst (λ u' → u' ◁ a) (alist-zero-vanishes (proj₁ p)) (proj₂ p)
lem-A7a (r List.∷ Δ) (m1-tail ¬pr y) =
, (l-tail (λ r◁a → ¬pr $ lem-A6' r◁a) (proj₂ $ lem-A7a Δ y))
open Lemmas
_⊢alg_ : ∀ {ν n} (K : Ktx ν n) → (a : Type ν) → Dec (K ⊢ᵣ a)
K ⊢alg simpl x with proj₂ K match1st x
K ⊢alg simpl x | yes p = yes (r-simp (proj₂ $ lem-A7a (proj₂ K) p) {!!})
K ⊢alg simpl x | no ¬p = no (λ{ (r-simp x₁ x₂) → {!!} })
K ⊢alg (a ⇒ b) with (a ∷K K) ⊢alg b
K ⊢alg (a ⇒ b) | yes p = yes $ r-iabs a p
K ⊢alg (a ⇒ b) | no ¬p = no (λ{ (r-iabs .a x) → ¬p x })
K ⊢alg ∀' a with (ktx-weaken K) ⊢alg a
K ⊢alg ∀' a | yes p = yes (r-tabs p)
K ⊢alg ∀' a | no ¬p = no (λ{ (r-tabs x) → ¬p x })
| {
"alphanum_fraction": 0.5279971285,
"avg_line_length": 46.4333333333,
"ext": "agda",
"hexsha": "ec0eec7c1d718e7ee4ac664719c71e7a2bdd4ca6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/Deterministic/Decidable.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/Deterministic/Decidable.agda",
"max_line_length": 121,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/Deterministic/Decidable.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": 3810,
"size": 8358
} |
-- Basic intuitionistic logic of proofs, without ∨, ⊥, or +.
-- Common syntax.
module BasicILP.Syntax.Common where
open import Common.ContextPair public
| {
"alphanum_fraction": 0.7548387097,
"avg_line_length": 22.1428571429,
"ext": "agda",
"hexsha": "536e086d4654cd96dd21a854c5e80a68bea76156",
"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/Common.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/Common.agda",
"max_line_length": 60,
"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/Common.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": 37,
"size": 155
} |
-- https://github.com/bitonic/tog/wiki/Implicit-Arguments
-- aj s popisom checkingu od Andreasa Abela
module ImplArg where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data Vec (A : Set) : Nat -> Set where
vnil : Vec A zero
vcons : {n : Nat} -> A -> Vec A n -> Vec A (suc n)
Cons = {A : Set} (a : A) {n : Nat} -> Vec A n -> Vec A (suc n)
cons : Cons
cons a = vcons a
| {
"alphanum_fraction": 0.6,
"avg_line_length": 22.6470588235,
"ext": "agda",
"hexsha": "41968710a075acce19690e811738511e56cfb2e2",
"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": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejtokarcik/agda-semantics",
"max_forks_repo_path": "tests/covered/ImplArg.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"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": "andrejtokarcik/agda-semantics",
"max_issues_repo_path": "tests/covered/ImplArg.agda",
"max_line_length": 62,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andrejtokarcik/agda-semantics",
"max_stars_repo_path": "tests/covered/ImplArg.agda",
"max_stars_repo_stars_event_max_datetime": "2018-12-06T17:24:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-10T15:33:56.000Z",
"num_tokens": 138,
"size": 385
} |
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
module Dipsy.Polarity where
data Polarity : Set where
pos : Polarity
neg : Polarity
open import Algebra.FunctionProperties {A = Polarity} _≡_
flip : Polarity → Polarity
flip pos = neg
flip neg = pos
flip-inv : Involutive flip
flip-inv pos = refl
flip-inv neg = refl
| {
"alphanum_fraction": 0.749271137,
"avg_line_length": 19.0555555556,
"ext": "agda",
"hexsha": "febf0d7a1e13e239ba888591444ca7a9909d7699",
"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": "06eec3f3325c71c81809ff19dfaf4fd43ba958ed",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "wenkokke/dipsy",
"max_forks_repo_path": "src/Dipsy/Polarity.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "06eec3f3325c71c81809ff19dfaf4fd43ba958ed",
"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": "wenkokke/dipsy",
"max_issues_repo_path": "src/Dipsy/Polarity.agda",
"max_line_length": 67,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "06eec3f3325c71c81809ff19dfaf4fd43ba958ed",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wenkokke/Dipsy",
"max_stars_repo_path": "src/Dipsy/Polarity.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-10T13:43:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-10T13:43:29.000Z",
"num_tokens": 95,
"size": 343
} |
postulate
A B C : Set
module M where
infixl 4 _+_
infixl 6 _*_
postulate
_+_ _*_ : Set → Set → Set
T : Set
T = A + B * C
open M renaming (_*_ to infix 2 _*_)
test : T → A + B * C
test x = x -- should use the updated fixity when printing the value of T !
| {
"alphanum_fraction": 0.5827338129,
"avg_line_length": 13.9,
"ext": "agda",
"hexsha": "637617ce49be5babf8552d3cc32c3a6bf5001425",
"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/Issue1346.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/Issue1346.agda",
"max_line_length": 75,
"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/Issue1346.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": 102,
"size": 278
} |
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Numbers.Naturals.Definition
open import Numbers.Naturals.Addition
module Numbers.Naturals.Multiplication where
infix 25 _*N_
_*N_ : ℕ → ℕ → ℕ
zero *N y = zero
(succ x) *N y = y +N (x *N y)
{-# BUILTIN NATTIMES _*N_ #-}
productZeroIsZeroLeft : (a : ℕ) → (zero *N a ≡ zero)
productZeroIsZeroLeft a = refl
productZeroIsZeroRight : (a : ℕ) → (a *N zero ≡ zero)
productZeroIsZeroRight zero = refl
productZeroIsZeroRight (succ a) = productZeroIsZeroRight a
productWithOneLeft : (a : ℕ) → ((succ zero) *N a) ≡ a
productWithOneLeft a = transitivity refl (transitivity (applyEquality (λ { m -> a +N m }) refl) (additionNIsCommutative a zero))
productWithOneRight : (a : ℕ) → a *N succ zero ≡ a
productWithOneRight zero = refl
productWithOneRight (succ a) = transitivity refl (addingPreservesEqualityLeft (succ zero) (productWithOneRight a))
productDistributes : (a b c : ℕ) → (a *N (b +N c)) ≡ a *N b +N a *N c
productDistributes zero b c = refl
productDistributes (succ a) b c = transitivity refl
(transitivity (addingPreservesEqualityLeft (b +N c) (productDistributes a b c))
(transitivity (equalityCommutative (additionNIsAssociative (b +N c) (a *N b) (a *N c)))
(transitivity (addingPreservesEqualityRight (a *N c) (additionNIsCommutative (b +N c) (a *N b)))
(transitivity (addingPreservesEqualityRight (a *N c) (equalityCommutative (additionNIsAssociative (a *N b) b c)))
(transitivity (addingPreservesEqualityRight (a *N c) (addingPreservesEqualityRight c (additionNIsCommutative (a *N b) b)))
(transitivity (addingPreservesEqualityRight (a *N c) (addingPreservesEqualityRight {b +N a *N b} {(succ a) *N b} c (refl)))
(transitivity (additionNIsAssociative ((succ a) *N b) c (a *N c))
(transitivity (addingPreservesEqualityLeft (succ a *N b) refl)
refl)
)
))))))
productPreservesEqualityLeft : (a : ℕ) → {b c : ℕ} → b ≡ c → a *N b ≡ a *N c
productPreservesEqualityLeft a {b} {.b} refl = refl
aSucB : (a b : ℕ) → a *N succ b ≡ a *N b +N a
aSucB a b = transitivity {_} {ℕ} {a *N succ b} {a *N (b +N succ zero)} (productPreservesEqualityLeft a (succIsAddOne b)) (transitivity {_} {ℕ} {a *N (b +N succ zero)} {a *N b +N a *N succ zero} (productDistributes a b (succ zero)) (addingPreservesEqualityLeft (a *N b) (productWithOneRight a)))
aSucBRight : (a b : ℕ) → (succ a) *N b ≡ a *N b +N b
aSucBRight a b = additionNIsCommutative b (a *N b)
multiplicationNIsCommutative : (a b : ℕ) → (a *N b) ≡ (b *N a)
multiplicationNIsCommutative zero b = transitivity (productZeroIsZeroLeft b) (equalityCommutative (productZeroIsZeroRight b))
multiplicationNIsCommutative (succ a) zero = multiplicationNIsCommutative a zero
multiplicationNIsCommutative (succ a) (succ b) = transitivity refl
(transitivity (addingPreservesEqualityLeft (succ b) (aSucB a b))
(transitivity (additionNIsCommutative (succ b) (a *N b +N a))
(transitivity (additionNIsAssociative (a *N b) a (succ b))
(transitivity (addingPreservesEqualityLeft (a *N b) (succCanMove a b))
(transitivity (addingPreservesEqualityLeft (a *N b) (additionNIsCommutative (succ a) b))
(transitivity (equalityCommutative (additionNIsAssociative (a *N b) b (succ a)))
(transitivity (addingPreservesEqualityRight (succ a) (equalityCommutative (aSucBRight a b)))
(transitivity (addingPreservesEqualityRight (succ a) (multiplicationNIsCommutative (succ a) b))
(transitivity (additionNIsCommutative (b *N (succ a)) (succ a))
refl
)))))))))
productDistributes' : (a b c : ℕ) → (a +N b) *N c ≡ a *N c +N b *N c
productDistributes' a b c rewrite multiplicationNIsCommutative (a +N b) c | productDistributes c a b | multiplicationNIsCommutative c a | multiplicationNIsCommutative c b = refl
flipProductsWithinSum : (a b c : ℕ) → (c *N a +N c *N b ≡ a *N c +N b *N c)
flipProductsWithinSum a b c = transitivity (addingPreservesEqualityRight (c *N b) (multiplicationNIsCommutative c a)) ((addingPreservesEqualityLeft (a *N c) (multiplicationNIsCommutative c b)))
productDistributesRight : (a b c : ℕ) → (a +N b) *N c ≡ a *N c +N b *N c
productDistributesRight a b c = transitivity (multiplicationNIsCommutative (a +N b) c) (transitivity (productDistributes c a b) (flipProductsWithinSum a b c))
multiplicationNIsAssociative : (a b c : ℕ) → (a *N (b *N c)) ≡ ((a *N b) *N c)
multiplicationNIsAssociative zero b c = refl
multiplicationNIsAssociative (succ a) b c =
transitivity refl
(transitivity refl
(transitivity (applyEquality ((λ x → b *N c +N x)) (multiplicationNIsAssociative a b c)) (transitivity (equalityCommutative (productDistributesRight b (a *N b) c)) refl)))
productOne : {a b : ℕ} → a ≡ a *N b → (a ≡ 0) || (b ≡ 1)
productOne {zero} {b} pr = inl refl
productOne {succ a} {zero} pr rewrite multiplicationNIsCommutative a 0 = exFalso (naughtE (equalityCommutative pr))
productOne {succ a} {succ zero} pr = inr refl
productOne {succ a} {succ (succ b)} pr rewrite multiplicationNIsCommutative a (succ (succ b)) | additionNIsCommutative (succ b) (a +N (a +N b *N a)) | additionNIsAssociative (succ a) (a +N b *N a) (succ b) | additionNIsCommutative (a +N b *N a) (succ b) = exFalso (bad pr)
where
bad' : {x : ℕ} → x ≡ succ x → False
bad' ()
bad : {x y : ℕ} → x ≡ x +N succ y → False
bad {succ x} {zero} pr rewrite additionNIsCommutative x 1 = bad' pr
bad {succ x} {succ y} pr = bad (succInjective pr)
| {
"alphanum_fraction": 0.6780687689,
"avg_line_length": 58.46875,
"ext": "agda",
"hexsha": "6acf7cc9533d0e5da986687478029cfaa107afad",
"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": "Numbers/Naturals/Multiplication.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": "Numbers/Naturals/Multiplication.agda",
"max_line_length": 294,
"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": "Numbers/Naturals/Multiplication.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": 1881,
"size": 5613
} |
open import Nat
open import Prelude
open import List
open import judgemental-erase
open import moveerase
open import sensibility
open import statics-checks
open import statics-core
module reachability where
-- algorithmically, we break reachability into two halves: first you
-- produce a list of actions that are all "move parent" to pull the cursor
-- to the very top of the expression in question. then, you go back down
-- into the expression with a sequence of move firstChild and move
-- nextSibs as appropriate. the append of these two lists will reach from
-- one expression to the other.
--
-- there may well be a shorter list of actions that does the same thing;
-- the expression with top-level cursor may not be the Least Common
-- Ancestor in the expression tree of the given pair. however, the work
-- of this less minimal thing and corresponding size of the proof term is
-- still bounded linearly by the size of the expression, and is far
-- easier to maniupulate judgementally.
reachup-type : {t : ztyp} {t' : htyp} →
erase-t t t' →
Σ[ L ∈ List action ] (runtype t L (▹ t' ◃) × movements L)
reachup-type ETTop = [] , DoRefl , AM[]
reachup-type (ETArrL er) with reachup-type er
... | (l , ih , m ) = l ++ [ move parent ] ,
runtype++ (ziplem-tmarr1 ih) (DoType TMArrParent1 DoRefl) ,
movements++ m (AM:: AM[])
reachup-type (ETArrR er) with reachup-type er
... | (l , ih , m ) = l ++ [ move parent ] ,
runtype++ (ziplem-tmarr2 ih) (DoType TMArrParent2 DoRefl) ,
movements++ m (AM:: AM[])
reachup-type (ETPlusL er) with reachup-type er
... | (l , ih , m ) = l ++ [ move parent ] ,
runtype++ (ziplem-tmplus1 ih) (DoType TMPlusParent1 DoRefl) ,
movements++ m (AM:: AM[])
reachup-type (ETPlusR er) with reachup-type er
... | (l , ih , m ) = l ++ [ move parent ] ,
runtype++ (ziplem-tmplus2 ih) (DoType TMPlusParent2 DoRefl) ,
movements++ m (AM:: AM[])
reachup-type (ETProdL er) with reachup-type er
... | (l , ih , m) = l ++ [ move parent ] ,
runtype++ (ziplem-tmprod1 ih) (DoType TMProdParent1 DoRefl) ,
movements++ m (AM:: AM[])
reachup-type (ETProdR er) with reachup-type er
... | (l , ih , m) = l ++ [ move parent ] ,
runtype++ (ziplem-tmprod2 ih) (DoType TMProdParent2 DoRefl) ,
movements++ m (AM:: AM[])
mutual
reachup-synth : {Γ : tctx} {e : zexp} {t : htyp} {e' : hexp} →
erase-e e e' →
Γ ⊢ e' => t →
Σ[ L ∈ List action ] (runsynth Γ e t L ▹ e' ◃ t × movements L)
reachup-synth (EELam _) ()
reachup-synth (EEInl er) ()
reachup-synth (EEInr er) ()
reachup-synth (EECase1 er) ()
reachup-synth (EECase2 er) ()
reachup-synth (EECase3 er) ()
reachup-synth EETop _ = [] , DoRefl , AM[]
reachup-synth (EEPlusL er) (SPlus x x₁) with reachup-ana er x
... | l , ih , m = l ++ [ move parent ] ,
runsynth++ (ziplem-plus1 ih) (DoSynth (SAMove EMPlusParent1) DoRefl) ,
movements++ m (AM:: AM[])
reachup-synth (EEPlusR er) (SPlus x x₁) with reachup-ana er x₁
... | l , ih , m = l ++ [ move parent ] ,
runsynth++ (ziplem-plus2 ih) (DoSynth (SAMove EMPlusParent2) DoRefl) ,
movements++ m (AM:: AM[])
reachup-synth (EEAscL er) (SAsc x) with reachup-ana er x
... | l , ih , m = l ++ [ move parent ] ,
runsynth++ (ziplem-asc1 ih) (DoSynth (SAMove EMAscParent1) DoRefl) ,
movements++ m (AM:: AM[])
reachup-synth (EEAscR er) (SAsc x₁) with reachup-type er
... | l , ih , m = l ++ [ move parent ] ,
runsynth++ {L1 = l} (ziplem-moves-asc2 m er x₁ ih)
(DoSynth (SAMove EMAscParent2) DoRefl) ,
movements++ m (AM:: AM[])
reachup-synth (EEHalfLamL er) (SLam x wt) with reachup-type er
... | l , ih , m = l ++ [ move parent ] ,
runsynth++ {L1 = l}
(ziplem-moves-halflam1 x er ETTop m ih wt wt)
(DoSynth (SAMove EMHalfLamParent1) DoRefl) ,
movements++ m (AM:: AM[])
reachup-synth (EEHalfLamR er) (SLam x wt) with reachup-synth er wt
... | l , ih , m = l ++ [ move parent ] ,
runsynth++ {L1 = l}
(ziplem-halflam2 x er wt ih)
(DoSynth (SAMove EMHalfLamParent2) DoRefl) ,
movements++ m (AM:: AM[])
reachup-synth (EEApL er) (SAp wt x x₁) with reachup-synth er wt
... | l , ih , m = l ++ [ move parent ] ,
runsynth++ {L1 = l}
(ziplem-moves-ap1 (lem-erase-synth er wt) x x₁ m ih)
(DoSynth (SAMove EMApParent1) DoRefl) ,
movements++ m (AM:: AM[])
reachup-synth (EEApR er) (SAp wt x x₁) with reachup-ana er x₁
... | l , ih , m = l ++ [ move parent ] ,
runsynth++ (ziplem-ap2 wt x ih) (DoSynth (SAMove EMApParent2) DoRefl) ,
movements++ m (AM:: AM[])
reachup-synth (EENEHole er) (SNEHole wt) with reachup-synth er wt
... | l , ih , m = l ++ [ move parent ] ,
runsynth++ (ziplem-nehole-a (lem-erase-synth er wt) ih)
(DoSynth (SAMove EMNEHoleParent) DoRefl) ,
movements++ m (AM:: AM[])
reachup-synth (EEFst er) (SFst wt pr) with reachup-synth er wt
... | l , ih , m = (l ++ [ move parent ]) ,
runsynth++ (ziplem-moves-fst pr pr er wt m ih)
(DoSynth (SAMove EMFstParent) DoRefl) ,
movements++ m (AM:: AM[])
reachup-synth (EESnd er) (SSnd wt pr) with reachup-synth er wt
... | l , ih , m = (l ++ [ move parent ]) ,
runsynth++ (ziplem-moves-snd pr pr er wt m ih)
(DoSynth (SAMove EMSndParent) DoRefl) ,
movements++ m (AM:: AM[])
reachup-synth (EEPairL er) (SPair wt wt₁) with reachup-synth er wt
... | l , ih , m = l ++ [ move parent ] ,
runsynth++ (ziplem-pair1 er wt ih wt₁)
(DoSynth (SAMove EMPairParent1) DoRefl) ,
movements++ m (AM:: AM[])
reachup-synth (EEPairR er) (SPair wt wt₁) with reachup-synth er wt₁
... | l , ih , m = l ++ [ move parent ] ,
runsynth++ (ziplem-pair2 wt er wt₁ ih)
(DoSynth (SAMove EMPairParent2) DoRefl) ,
movements++ m (AM:: AM[])
reachup-ana : {Γ : tctx} {e : zexp} {t : htyp} {e' : hexp} →
erase-e e e' →
Γ ⊢ e' <= t →
Σ[ L ∈ List action ] (runana Γ e L ▹ e' ◃ t × movements L)
reachup-ana EETop _ = [] , DoRefl , AM[]
reachup-ana er (ASubsume x x₁) with reachup-synth er x
... | l , ih , m = l ,
synthana-moves (lem-erase-synth er x) m x₁ ih ,
m
reachup-ana (EELam er) (ALam x₁ x₂ wt) with reachup-ana er wt
... | l , ih , m = l ++ [ move parent ] ,
runana++ (ziplem-lam x₁ x₂ ih) (DoAna (AAMove EMLamParent) DoRefl) ,
movements++ m (AM:: AM[])
reachup-ana (EEInl er) (AInl x wt) with reachup-ana er wt
... | l , ih , m = l ++ [ move parent ] ,
runana++ (ziplem-inl x ih) (DoAna (AAMove EMInlParent) DoRefl) ,
movements++ m (AM:: AM[])
reachup-ana (EEInr er) (AInr x wt) with reachup-ana er wt
... | l , ih , m = l ++ [ move parent ] ,
runana++ (ziplem-inr x ih) (DoAna (AAMove EMInrParent) DoRefl) ,
movements++ m (AM:: AM[])
reachup-ana (EECase1 er) (ACase x₁ x₂ x₃ x₄ wt wt₁) with reachup-synth er x₄
... | l , ih , m = l ++ [ move parent ] ,
runana++ {L1 = l} (ziplem-case1a x₁ x₂ er x₄ ih x₃ wt wt₁ m)
(DoAna (AAMove EMCaseParent1) DoRefl) ,
movements++ m (AM:: AM[])
reachup-ana (EECase2 er) (ACase x₁ x₂ x₃ x₄ wt wt₁) with reachup-ana er wt
... | l , ih , m = l ++ [ move parent ] ,
runana++ (ziplem-case2 x₁ x₂ x₄ wt₁ x₃ ih)
(DoAna (AAMove EMCaseParent2) DoRefl) ,
movements++ m (AM:: AM[])
reachup-ana (EECase3 er) (ACase x₁ x₂ x₃ x₄ wt wt₁) with reachup-ana er wt₁
... | l , ih , m = l ++ [ move parent ] ,
runana++ (ziplem-case3 x₁ x₂ x₄ wt x₃ ih)
(DoAna (AAMove EMCaseParent3) DoRefl) ,
movements++ m (AM:: AM[])
reachdown-type : {t : htyp} {t' : ztyp} → (p : erase-t t' t) →
Σ[ L ∈ List action ] (runtype (▹ t ◃) L t' × movements L)
reachdown-type ETTop = [] , DoRefl , AM[]
reachdown-type (ETArrL er) with reachdown-type er
... | (l , ih , m ) = move (child 1) :: l ,
DoType TMArrChild1 (ziplem-tmarr1 ih) ,
AM:: m
reachdown-type (ETArrR er) with reachdown-type er
... | (l , ih , m ) = move (child 2) :: l ,
DoType TMArrChild2 (ziplem-tmarr2 ih) ,
AM:: m
reachdown-type (ETPlusL er) with reachdown-type er
... | (l , ih , m ) = move (child 1) :: l ,
DoType TMPlusChild1 (ziplem-tmplus1 ih) ,
AM:: m
reachdown-type (ETPlusR er) with reachdown-type er
... | (l , ih , m ) = move (child 2) :: l ,
DoType TMPlusChild2 (ziplem-tmplus2 ih) ,
AM:: m
reachdown-type (ETProdL er) with reachdown-type er
... | (l , ih , m ) = move (child 1) :: l ,
DoType TMProdChild1 (ziplem-tmprod1 ih) ,
AM:: m
reachdown-type (ETProdR er) with reachdown-type er
... | (l , ih , m ) = move (child 2) :: l ,
DoType TMProdChild2 (ziplem-tmprod2 ih) ,
AM:: m
mutual
reachdown-synth : {Γ : tctx} {e : zexp} {t : htyp} {e' : hexp} →
(p : erase-e e e') →
(wt : Γ ⊢ e' => t) →
Σ[ L ∈ List action ] (runsynth Γ ▹ e' ◃ t L e t × movements L)
reachdown-synth (EELam _) ()
reachdown-synth (EEInl er) ()
reachdown-synth (EEInr er) ()
reachdown-synth (EECase1 er) ()
reachdown-synth (EECase2 er) ()
reachdown-synth (EECase3 er) ()
reachdown-synth EETop _ = [] , DoRefl , AM[]
reachdown-synth (EEAscL er) (SAsc x) with reachdown-ana er x
... | l , ih , m = move (child 1) :: l ,
DoSynth (SAMove EMAscChild1) (ziplem-asc1 ih) ,
AM:: m
reachdown-synth (EEAscR er) (SAsc x₁) with reachdown-type er
... | l , ih , m = move (child 2) :: l ,
DoSynth (SAMove EMAscChild2) (ziplem-moves-asc2 m ETTop x₁ ih) ,
AM:: m
reachdown-synth (EEHalfLamL er) (SLam x wt) with reachdown-type er
... | l , ih , m = move (child 1) :: l ,
DoSynth (SAMove EMHalfLamChild1)
(ziplem-moves-halflam1 x ETTop er m ih wt wt) ,
AM:: m
reachdown-synth (EEHalfLamR er) (SLam x wt) with reachdown-synth er wt
... | l , ih , m = move (child 2) :: l ,
DoSynth (SAMove EMHalfLamChild2) (ziplem-halflam2 x EETop wt ih) ,
AM:: m
reachdown-synth (EEApL er) (SAp wt x x₁) with reachdown-synth er wt
... | l , ih , m = move (child 1) :: l ,
DoSynth (SAMove EMApChild1) (ziplem-moves-ap1 wt x x₁ m ih) ,
AM:: m
reachdown-synth (EEApR er) (SAp wt x x₁) with reachdown-ana er x₁
... | l , ih , m = move (child 2) :: l ,
DoSynth (SAMove EMApChild2) (ziplem-ap2 wt x ih) ,
AM:: m
reachdown-synth (EEPlusL er) (SPlus x x₁) with reachdown-ana er x
... | l , ih , m = move (child 1) :: l ,
DoSynth (SAMove EMPlusChild1) (ziplem-plus1 ih) ,
AM:: m
reachdown-synth (EEPlusR er) (SPlus x x₁) with reachdown-ana er x₁
... | l , ih , m = move (child 2) :: l ,
DoSynth (SAMove EMPlusChild2) (ziplem-plus2 ih) ,
AM:: m
reachdown-synth (EENEHole er) (SNEHole wt) with reachdown-synth er wt
... | l , ih , m = move (child 1) :: l ,
DoSynth (SAMove EMNEHoleChild1) (ziplem-nehole-a wt ih) ,
AM:: m
reachdown-synth (EEPairL er) (SPair wt wt₁) with reachdown-synth er wt
... | l , ih , m = move (child 1) :: l ,
DoSynth (SAMove EMPairChild1) (ziplem-pair1 EETop wt ih wt₁) ,
AM:: m
reachdown-synth (EEPairR er) (SPair wt wt₁)
with reachdown-synth er wt₁
... | l , ih , m = move (child 2) :: l ,
DoSynth (SAMove EMPairChild2) (ziplem-pair2 wt EETop wt₁ ih) ,
AM:: m
reachdown-synth (EEFst er) (SFst wt pr) with reachdown-synth er wt
... | l , ih , m = move (child 1) :: l ,
DoSynth (SAMove EMFstChild1)
(ziplem-moves-fst pr pr EETop wt m ih) ,
AM:: m
reachdown-synth (EESnd er) (SSnd wt pr) with reachdown-synth er wt
... | l , ih , m = move (child 1) :: l ,
DoSynth (SAMove EMSndChild1)
(ziplem-moves-snd pr pr EETop wt m ih) ,
AM:: m
reachdown-ana : {Γ : tctx} {e : zexp} {t : htyp} {e' : hexp} →
(p : erase-e e e') →
(wt : Γ ⊢ e' <= t) →
Σ[ L ∈ List action ] (runana Γ ▹ e' ◃ L e t × movements L)
reachdown-ana EETop _ = [] , DoRefl , AM[]
reachdown-ana er (ASubsume x x₁) with reachdown-synth er x
... | l , ih , m = l ,
synthana-moves x m x₁ ih ,
m
reachdown-ana (EELam er) (ALam x₁ x₂ wt) with reachdown-ana er wt
... | l , ih , m = move (child 1) :: l ,
DoAna (AAMove EMLamChild1) (ziplem-lam x₁ x₂ ih) ,
AM:: m
reachdown-ana (EEInl er) (AInl x wt) with reachdown-ana er wt
... | l , ih , m = move (child 1) :: l ,
DoAna (AAMove EMInlChild1) (ziplem-inl x ih) ,
AM:: m
reachdown-ana (EEInr er) (AInr x wt) with reachdown-ana er wt
... | l , ih , m = move (child 1) :: l ,
DoAna (AAMove EMInrChild1) (ziplem-inr x ih) ,
AM:: m
reachdown-ana (EECase1 er) (ACase x₁ x₂ x₃ x₄ wt wt₁) with reachdown-synth er x₄
... | l , ih , m = move (child 1) :: l ,
DoAna (AAMove EMCaseChild1)
(ziplem-case1a x₁ x₂ EETop x₄ ih x₃ wt wt₁ m) ,
AM:: m
reachdown-ana (EECase2 er) (ACase x₁ x₂ x₃ x₄ wt wt₁) with reachdown-ana er wt
... | l , ih , m = move (child 2) :: l ,
DoAna (AAMove EMCaseChild2) (ziplem-case2 x₁ x₂ x₄ wt₁ x₃ ih) ,
AM:: m
reachdown-ana (EECase3 er) (ACase x₁ x₂ x₃ x₄ wt wt₁) with reachdown-ana er wt₁
... | l , ih , m = move (child 3) :: l ,
DoAna (AAMove EMCaseChild3) (ziplem-case3 x₁ x₂ x₄ wt x₃ ih) ,
AM:: m
-- this is the final statement of the reachability triplet. the movement
-- between judgemental and metafunctional erasure happens internally to
-- theses statements to present a consistent interface with the text of
-- the paper, while also allowing easy pattern matching in the proofs.
--
-- the intuition for these statements is that the cursor cannot change
-- the type of things because the typing judgement is defined on the
-- cursor-erased terms and types.
reachability-types : (t1 t2 : ztyp) → (t1 ◆t) == (t2 ◆t) →
Σ[ L ∈ List action ] (runtype t1 L t2 × movements L)
reachability-types t1 t2 eq
with ◆erase-t t1 (t2 ◆t) eq | ◆erase-t t2 (t1 ◆t) (! eq)
... | er1 | er2 with reachup-type er1 | reachdown-type er2
... | (lup , rup , mvup) | (ldwn , rdwn , mvdwn) =
lup ++ ldwn ,
runtype++ rup (tr (λ x → runtype ▹ x ◃ ldwn t2) eq rdwn) ,
movements++ mvup mvdwn
reachability-synth : (Γ : tctx) (t : htyp) (e1 e2 : zexp) →
Γ ⊢ e1 ◆e => t →
e1 ◆e == e2 ◆e →
Σ[ L ∈ List action ] (runsynth Γ e1 t L e2 t × movements L)
reachability-synth Γ t e1 e2 wt1 eq
with ◆erase-e e1 (e2 ◆e) eq | ◆erase-e e2 (e1 ◆e) (! eq)
... | er1 | er2 with reachup-synth er1 (tr (λ x → Γ ⊢ x => t) eq wt1)
| reachdown-synth er2 wt1
... | (lup , rup , mvup) | (ldwn , rdwn , mvdwn) =
(lup ++ ldwn) ,
runsynth++ rup (tr (λ x → runsynth Γ ▹ x ◃ t ldwn e2 t) eq rdwn) ,
movements++ mvup mvdwn
reachability-ana : (Γ : tctx) (t : htyp) (e1 e2 : zexp) →
Γ ⊢ e1 ◆e <= t →
e1 ◆e == e2 ◆e →
Σ[ L ∈ List action ] (runana Γ e1 L e2 t × movements L)
reachability-ana Γ t e1 e2 wt1 eq
with ◆erase-e e1 (e2 ◆e) eq | ◆erase-e e2 (e1 ◆e) (! eq)
... | er1 | er2 with reachup-ana er1 (tr (λ x → Γ ⊢ x <= t) eq wt1)
| reachdown-ana er2 wt1
... | (lup , rup , mvup) | (ldwn , rdwn , mvdwn) =
lup ++ ldwn ,
(runana++ rup (tr (λ x → runana Γ ▹ x ◃ ldwn e2 t) eq rdwn)) ,
(movements++ mvup mvdwn)
| {
"alphanum_fraction": 0.4927225792,
"avg_line_length": 52.7739130435,
"ext": "agda",
"hexsha": "6eb02f28d1ce996eb483043869dfddb4c3a2aef9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-agda",
"max_forks_repo_path": "reachability.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-agda",
"max_issues_repo_path": "reachability.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-agda",
"max_stars_repo_path": "reachability.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5766,
"size": 18207
} |
module UniDB.Morph.Star where
open import UniDB.Spec
infixl 4 _▻_
data Star (Ξ : MOR) : MOR where
ε : {γ : Dom} → Star Ξ γ γ
_▻_ : {γ₁ γ₂ γ₃ : Dom} (ξs : Star Ξ γ₁ γ₂) (ξ : Ξ γ₂ γ₃) → Star Ξ γ₁ γ₃
module _ {Ξ : MOR} where
instance
iIdmStar : Idm (Star Ξ)
idm {{iIdmStar}} _ = ε
iCompStar : Comp (Star Ξ)
_⊙_ {{iCompStar}} ξs ε = ξs
_⊙_ {{iCompStar}} ξs (ζs ▻ ζ) = (ξs ⊙ ζs) ▻ ζ
module _ {Ξ : MOR} {{upΞ : Up Ξ}} where
instance
iUpStar : Up (Star Ξ)
_↑₁ {{iUpStar}} ε = ε
_↑₁ {{iUpStar}} (ξs ▻ ξ) = (ξs ↑₁) ▻ (ξ ↑₁)
_↑_ {{iUpStar}} ξ 0 = ξ
_↑_ {{iUpStar}} ξ (suc δ⁺) = ξ ↑ δ⁺ ↑₁
↑-zero {{iUpStar}} ξ = refl
↑-suc {{iUpStar}} ξ δ⁺ = refl
iUpIdmStar : UpIdm (Star Ξ)
idm-↑₁ {{iUpIdmStar}} = refl
iUpCompStar : UpComp (Star Ξ)
⊙-↑₁ {{iUpCompStar}} ξs ε = refl
⊙-↑₁ {{iUpCompStar}} ξs (ζs ▻ ζ) =
cong₂ _▻_ (⊙-↑₁ {Star Ξ} ξs ζs ) (refl {x = ζ ↑₁})
| {
"alphanum_fraction": 0.5089567966,
"avg_line_length": 24.9736842105,
"ext": "agda",
"hexsha": "33556e85288fc45adcbbac19b6658684bf633f64",
"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": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "skeuchel/unidb-agda",
"max_forks_repo_path": "UniDB/Morph/Star.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"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": "skeuchel/unidb-agda",
"max_issues_repo_path": "UniDB/Morph/Star.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "skeuchel/unidb-agda",
"max_stars_repo_path": "UniDB/Morph/Star.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 498,
"size": 949
} |
module NoParseForLHS where
data X : Set where
_! : X -> X
z : X
right : X -> X
right (x !) = x
right z = z !
wrong : X -> X
wrong (! x) = x
wrong z = z !
| {
"alphanum_fraction": 0.4912280702,
"avg_line_length": 11.4,
"ext": "agda",
"hexsha": "5cdd71cc759061616647951c90242ba8d1e2398f",
"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/NoParseForLHS.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/NoParseForLHS.agda",
"max_line_length": 26,
"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/NoParseForLHS.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 67,
"size": 171
} |
module par-swap where
open import Esterel.Lang
open import Esterel.Lang.Binding
open import Esterel.Context
open import sn-calculus
data _∥R_ : Term -> Term -> Set where
∥Rstep : ∀ {C p q d} ->
(d≐C⟦p∥q⟧c : d ≐ C ⟦ (p ∥ q) ⟧c) ->
d ∥R (C ⟦ (q ∥ p) ⟧c)
data _∥R*_ : Term -> Term -> Set where
∥R0 : ∀ {p} -> p ∥R* p
∥Rn : ∀ {p q r} ->
(p∥Rq : p ∥R q) ->
(q∥R*r : q ∥R* r) ->
p ∥R* r
∥R*-concat : ∀ {p q r} -> p ∥R* q -> q ∥R* r -> p ∥R* r
∥R*-concat ∥R0 q∥R*r = q∥R*r
∥R*-concat (∥Rn p∥Rq p∥R*q) q∥R*r = ∥Rn p∥Rq (∥R*-concat p∥R*q q∥R*r)
data _∥R*∪sn⟶*_ : Term -> Term -> Set where
∪∥R* : ∀ {p q r} ->
(p∥R*q : p ∥R* q) ->
(q∥R∪sn⟶*r : q ∥R*∪sn⟶* r) ->
p ∥R*∪sn⟶* r
∪sn⟶* : ∀ {p q r} ->
(psn⟶*q : p sn⟶* q) ->
(q∥R∪sn⟶*r : q ∥R*∪sn⟶* r) ->
p ∥R*∪sn⟶* r
∪refl : ∀ {p} -> p ∥R*∪sn⟶* p
∥R*∪sn⟶*-concat : ∀ {p q r} -> p ∥R*∪sn⟶* q -> q ∥R*∪sn⟶* r -> p ∥R*∪sn⟶* r
∥R*∪sn⟶*-concat (∪∥R* p∥R*q a) b = ∪∥R* p∥R*q (∥R*∪sn⟶*-concat a b)
∥R*∪sn⟶*-concat (∪sn⟶* psn⟶*q a) b = ∪sn⟶* psn⟶*q (∥R*∪sn⟶*-concat a b)
∥R*∪sn⟶*-concat ∪refl b = b
data _∥R∪sn≡ₑ_ : Term → Term → Set where
∪stpsn : ∀{p q} → (psn⟶q : p sn⟶ q) → p ∥R∪sn≡ₑ q
∪stp∥ : ∀{p q} → (p∥Rq : p ∥R q) → p ∥R∪sn≡ₑ q
∪sym : ∀{p q BV FV} → (psn∪∥R≡ₑq : p ∥R∪sn≡ₑ q) → (CBp : CorrectBinding p BV FV) → q ∥R∪sn≡ₑ p
∪ref : ∀{p} → p ∥R∪sn≡ₑ p
∪trn : ∀{p r q} → (p∥R∪sn≡ₑr : p ∥R∪sn≡ₑ r) → (r∥R∪sn≡ₑq : r ∥R∪sn≡ₑ q) → p ∥R∪sn≡ₑ q
| {
"alphanum_fraction": 0.421509686,
"avg_line_length": 32.5434782609,
"ext": "agda",
"hexsha": "1637a63747f9eb5b51c82e2e865fc511d0199c11",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/par-swap.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"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": "florence/esterel-calculus",
"max_issues_repo_path": "agda/par-swap.agda",
"max_line_length": 96,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/par-swap.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 949,
"size": 1497
} |
-- DontCares shouldn't end up in the generated with functions.
module Issue337 where
data ℕ : Set where
zero : ℕ
suc : (n : ℕ) → ℕ
{-# BUILTIN NATURAL ℕ #-}
{-# BUILTIN ZERO zero #-}
{-# BUILTIN SUC suc #-}
data _≡_ {A : Set}(x : A) : A → Set where
refl : x ≡ x
postulate
_≤_ : ℕ → ℕ → Set
p₁ : 0 ≤ 1
p₂ : 0 ≤ 1
data SList (bound : ℕ) : Set where
[] : SList bound
scons : (head : ℕ) →
.(head ≤ bound) →
(tail : SList head) →
SList bound
l₁ : SList 1
l₁ = scons 0 p₁ []
l₂ : SList 1
l₂ = scons 0 p₂ []
l₁≡l₂ : l₁ ≡ l₂
l₁≡l₂ with Set
... | _ = refl
| {
"alphanum_fraction": 0.5194174757,
"avg_line_length": 17.1666666667,
"ext": "agda",
"hexsha": "a7bcee5c8c95a1b628a28b0fd5ec840c60731a5b",
"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": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "np/agda-git-experiment",
"max_forks_repo_path": "test/succeed/Issue337.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"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": "np/agda-git-experiment",
"max_issues_repo_path": "test/succeed/Issue337.agda",
"max_line_length": 62,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/succeed/Issue337.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T04:41:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T04:41:05.000Z",
"num_tokens": 251,
"size": 618
} |
open import Categories.Category
module Categories.End {o ℓ e o′ ℓ′ e′} {C : Category o ℓ e} {V : Category o′ ℓ′ e′} where
private
module C = Category C
module V = Category V
open import Categories.Bifunctor using (Bifunctor; Functor; module Functor)
open import Categories.DinaturalTransformation
open import Categories.Functor.Constant
open import Level
open import Categories.Morphisms V
open import Categories.Square
open import Data.Product
record End-data (F : Bifunctor C.op C V) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
field
E : V.Obj
π : DinaturalTransformation {C = C} (Constant E) F
module π = DinaturalTransformation π
open π using (α)
π∘_ : ∀ {Q} → Q V.⇒ E → End-data F
π∘_ {Q} g = record { π = record { α = λ c → α c ∘ g; commute = λ {c c′} f →
begin
F.F₁ (f , C.id) ∘ ((α c′ ∘ g) ∘ id)
↓⟨ ∘-resp-≡ʳ identityʳ ⟩
F.F₁ (f , C.id) ∘ (α c′ ∘ g)
↑⟨ assoc ⟩
(F.F₁ (f , C.id) ∘ α c′) ∘ g
↑⟨ ∘-resp-≡ʳ identityˡ ⟩
(F.F₁ (f , C.id) ∘ α c′) ∘ (id ∘ g)
↑⟨ assoc ⟩
((F.F₁ (f , C.id) ∘ α c′) ∘ id) ∘ g
↓⟨ ∘-resp-≡ˡ assoc ⟩
(F.F₁ (f , C.id) ∘ (α c′ ∘ id)) ∘ g
↓⟨ ∘-resp-≡ˡ (π.commute f) ⟩
(F.F₁ (C.id , f) ∘ (α c ∘ id)) ∘ g
↓⟨ assoc ⟩
F.F₁ (C.id , f) ∘ (α c ∘ id) ∘ g
↓⟨ ∘-resp-≡ʳ (∘-resp-≡ˡ identityʳ) ⟩
F.F₁ (C.id , f) ∘ α c ∘ g
↑⟨ ∘-resp-≡ʳ identityʳ ⟩
F.F₁ (C.id , f) ∘ (α c ∘ g) ∘ id ∎
{- begin
F.F₁ (f , C.id) ∘ (α c′ ∘ g) ∘ ID ↓⟨ Equiv.refl ⟩
(F.F₁ (f , C.id) ∙ α c′ ∙ ID) ∙ g ↓≡⟨ ∘-resp-≡ˡ (π.commute f) ⟩
(F.F₁ (C.id , f) ∙ α c ∙ ID) ∙ g ↓⟨ Equiv.refl ⟩
F.F₁ (C.id , f) ∙ (α c ∙ g) ∙ ID ∎ -} } }
where
-- open AUReasoning V
open V.HomReasoning
module F = Functor F
open V
.commute : ∀ {a b} (f : a C.⇒ b) -> Functor.F₁ F (f , C.id) V.∘ α b V.≡ Functor.F₁ F (C.id , f) V.∘ α a
commute {c} {c′} f = begin
F.F₁ (f , C.id) ∘ α c′ ↑⟨ ∘-resp-≡ʳ identityʳ ⟩
F.F₁ (f , C.id) ∘ α c′ ∘ id ↓⟨ π.commute f ⟩
F.F₁ (C.id , f) ∘ α c ∘ id ↓⟨ ∘-resp-≡ʳ identityʳ ⟩
F.F₁ (C.id , f) ∘ α c ∎
where
open V.HomReasoning
module F = Functor F
open V
open DinaturalTransformation using (α)
record End (F : Bifunctor C.op C V) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
field
Data : End-data F
open End-data Data
IsUni : (Q : End-data F) → (u : End-data.E Q V.⇒ E) → Set _
IsUni Q u = ∀ c → α π c V.∘ u V.≡ α (End-data.π Q) c
field
universal : (Q : End-data F) → End-data.E Q V.⇒ E
.π[c]∘universal≡δ[c] : {Q : End-data F} → IsUni Q (universal Q)
.universal-unique : {Q : End-data F} → ∀ u → IsUni Q u → u V.≡ universal Q
.eta-rule : universal Data V.≡ V.id
eta-rule = begin universal Data ↑⟨ universal-unique {Data} V.id (λ c → V.identityʳ) ⟩
V.id ∎
where
open V.HomReasoning
.π-mono : ∀ {Q} (g₁ g₂ : Q V.⇒ E) → (∀ c → α π c V.∘ g₁ V.≡ α π c V.∘ g₂) → g₁ V.≡ g₂
π-mono {Q} g₁ g₂ π∘g₁≡π∘g₂ = begin
g₁ ↓⟨ universal-unique {π∘ g₁} g₁ (λ c → V.Equiv.refl) ⟩
universal (π∘ g₁) ↑⟨ universal-unique {π∘ g₁} g₂ (λ c → V.Equiv.sym (π∘g₁≡π∘g₂ c)) ⟩
g₂ ∎
where
open V.HomReasoning
open End-data Data public
open import Data.Product
open import Categories.Product
open import Categories.FunctorCategory
import Categories.NaturalTransformation as NT
open NT.NaturalTransformation using (η)
endF : ∀ {o ℓ e} {A : Category o ℓ e}(F : Functor A (Functors (Product C.op C) V))
→ (∀ a → End (Functor.F₀ F a)) → Functor A V
endF {A = A} F mke = record {
F₀ = λ a → End.E (mke a);
F₁ = λ {a b} → F₁ {a} {b} ;
identity = λ {a} → V.Equiv.sym (End.universal-unique (mke a) V.id (λ c →
begin α (End.π (mke a)) c ∘ id ↓⟨ identityʳ ⟩
α (End.π (mke a)) c ↑⟨ identityˡ ⟩
id ∘ α (End.π (mke a)) c ↑⟨ ∘-resp-≡ˡ F.identity ⟩
η (F.F₁ A.id) (c , c) ∘ α (End.π (mke a)) c ∎ )) ;
homomorphism = λ {X Y Z f g} → V.Equiv.sym (End.universal-unique (mke Z) _ (λ c →
begin α (End.π (mke Z)) c ∘ F₁ g ∘ F₁ f
↑⟨ assoc ⟩
(α (End.π (mke Z)) c ∘ F₁ g) ∘ F₁ f
↓⟨ ∘-resp-≡ˡ (End.π[c]∘universal≡δ[c] (mke Z) {record {π = F.F₁ g <∘ End.π (mke Y)}} c) ⟩
(η (F.F₁ g) (c , c) ∘ α (End.π (mke Y)) c) ∘ F₁ f
↓⟨ assoc ⟩
η (F.F₁ g) (c , c) ∘ α (End.π (mke Y)) c ∘ F₁ f
↓⟨ ∘-resp-≡ʳ (End.π[c]∘universal≡δ[c] (mke Y) {record {π = F.F₁ f <∘ End.π (mke X)}} c) ⟩
η (F.F₁ g) (c , c) ∘ η (F.F₁ f) (c , c) ∘ α (End.π (mke X)) c
↑⟨ assoc ⟩
(η (F.F₁ g) (c , c) ∘ η (F.F₁ f) (c , c)) ∘ α (End.π (mke X)) c
↑⟨ ∘-resp-≡ˡ F.homomorphism ⟩
η (F.F₁ (A [ g ∘ f ])) (c , c) ∘ α (End.π (mke X)) c
∎ ));
F-resp-≡ = λ {a b f g} f≡g → End.universal-unique (mke b) _ (λ c →
begin α (End.π (mke b)) c ∘ F₁ f ↓⟨ End.π[c]∘universal≡δ[c] (mke b) c ⟩
η (F.F₁ f) (c , c) ∘ α (End.π (mke a)) c ↓⟨ ∘-resp-≡ˡ (F.F-resp-≡ f≡g) ⟩
η (F.F₁ g) (c , c) ∘ α (End.π (mke a)) c ∎ ) }
where
module A = Category A
module F = Functor F
open V
open V.HomReasoning
F₁ = λ {a b} f → End.universal (mke b) (record { E = _; π = (F.F₁ f) <∘ (End.π (mke a)) })
| {
"alphanum_fraction": 0.4181494662,
"avg_line_length": 43.2307692308,
"ext": "agda",
"hexsha": "05f7eb81842dc5de5dcf6d2f1696dffdcb2c1b90",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/End.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/End.agda",
"max_line_length": 124,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/End.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 2453,
"size": 6182
} |
module Lemmachine.Request where
{-# IMPORT Hack #-}
{-# IMPORT Lemmachine.FFI #-}
open import Data.Product
open import Data.List
open import Data.Maybe
open import Data.Bool
open import Data.Nat
open import Data.String
data Method : Set where
HEAD GET PUT DELETE POST : Method
TRACE CONNECT OPTIONS : Method
{-# COMPILED_DATA Method Hack.RequestMethod
Hack.OPTIONS Hack.GET Hack.HEAD Hack.POST
Hack.PUT Hack.DELETE Hack.TRACE Hack.CONNECT
#-}
eqMethod : Method → Method → Bool
eqMethod HEAD HEAD = true
eqMethod GET GET = true
eqMethod PUT PUT = true
eqMethod DELETE DELETE = true
eqMethod POST POST = true
eqMethod TRACE TRACE = true
eqMethod CONNECT CONNECT = true
eqMethod OPTIONS OPTIONS = true
eqMethod _ _ = false
Version = String
IP = String
LocalPath = String
Path = String
RawPath = String
PathToken = String
PathTokens = List PathToken
data RequestHeader : Set where
_,_ : String → String → RequestHeader
{-# COMPILED_DATA RequestHeader
Lemmachine.FFI.RequestHeader
Lemmachine.FFI.RequestHeader
#-}
headerKey : RequestHeader → String
headerKey (k , _) = k
headerValue : RequestHeader → String
headerValue (_ , v) = v
RequestHeaders = List RequestHeader
Body = Maybe String
Cookie = String
QueryString = String
Port = String
record Request : Set where
field
method : Method
version : Version
peer : IP
dispPath : LocalPath
path : Path
rawPath : RawPath
pathTokens : PathTokens
headers : RequestHeaders
reqBody : Body
cookie : Cookie
queryString : QueryString
port : Port
postulate isRedirect : Request → Bool
| {
"alphanum_fraction": 0.734082397,
"avg_line_length": 21.0789473684,
"ext": "agda",
"hexsha": "f26b338df483c5f40e228576626c1fc12664cca0",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "src/Lemmachine/Request.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "src/Lemmachine/Request.agda",
"max_line_length": 48,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "src/Lemmachine/Request.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 402,
"size": 1602
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Setoids.Setoids
open import Functions.Definition
open import Sets.EquivalenceRelations
open import Rings.Definition
open import Rings.IntegralDomains.Definition
module Rings.Associates.Definition {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} {R : Ring S _+_ _*_} (intDom : IntegralDomain R) where
open import Rings.Units.Definition R
open Setoid S
open Ring R
open Equivalence eq
Associates : Rel A
Associates x y = Sg A (λ z → Unit z && (x ∼ (y * z)))
| {
"alphanum_fraction": 0.7152899824,
"avg_line_length": 29.9473684211,
"ext": "agda",
"hexsha": "cd5429c8f08e51c27be6ac49f7aad0f631532cc4",
"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": "Rings/Associates/Definition.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": "Rings/Associates/Definition.agda",
"max_line_length": 156,
"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": "Rings/Associates/Definition.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": 170,
"size": 569
} |
Subsets and Splits