Search is not available for this dataset
text
string | meta
dict |
---|---|
{-
This file proves a variety of basic results about paths:
- refl, sym, cong and composition of paths. This is used to set up
equational reasoning.
- Transport, subst and functional extensionality
- J and its computation rule (up to a path)
- Σ-types and contractibility of singletons
- Converting PathP to and from a homogeneous path with transp
- Direct definitions of lower h-levels
- Export natural numbers
- Export universe lifting
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.Prelude where
open import Cubical.Core.Primitives public
infixr 30 _∙_
infix 3 _∎
infixr 2 _≡⟨_⟩_
infixr 2.5 _≡⟨_⟩≡⟨_⟩_
-- Basic theory about paths. These proofs should typically be
-- inlined. This module also makes equational reasoning work with
-- (non-dependent) paths.
private
variable
ℓ ℓ' : Level
A : Type ℓ
B : A → Type ℓ
x y z w : A
refl : x ≡ x
refl {x = x} = λ _ → x
{-# INLINE refl #-}
sym : x ≡ y → y ≡ x
sym p i = p (~ i)
{-# INLINE sym #-}
symP : {A : I → Type ℓ} → {x : A i0} → {y : A i1} →
(p : PathP A x y) → PathP (λ i → A (~ i)) y x
symP p j = p (~ j)
cong : ∀ (f : (a : A) → B a) (p : x ≡ y) →
PathP (λ i → B (p i)) (f x) (f y)
cong f p i = f (p i)
{-# INLINE cong #-}
cong₂ : ∀ {C : (a : A) → (b : B a) → Type ℓ} →
(f : (a : A) → (b : B a) → C a b) →
(p : x ≡ y) →
{u : B x} {v : B y} (q : PathP (λ i → B (p i)) u v) →
PathP (λ i → C (p i) (q i)) (f x u) (f y v)
cong₂ f p q i = f (p i) (q i)
{-# INLINE cong₂ #-}
{- The most natural notion of homogenous path composition
in a cubical setting is double composition:
x ∙ ∙ ∙ > w
^ ^
p⁻¹ | | r ^
| | j |
y — — — > z ∙ — >
q i
`p ∙∙ q ∙∙ r` gives the line at the top,
`doubleCompPath-filler p q r` gives the whole square
-}
doubleComp-faces : {x y z w : A } (p : x ≡ y) (r : z ≡ w)
→ (i : I) (j : I) → Partial (i ∨ ~ i) A
doubleComp-faces p r i j (i = i0) = p (~ j)
doubleComp-faces p r i j (i = i1) = r j
_∙∙_∙∙_ : w ≡ x → x ≡ y → y ≡ z → w ≡ z
(p ∙∙ q ∙∙ r) i =
hcomp (doubleComp-faces p r i) (q i)
doubleCompPath-filler : (p : x ≡ y) (q : y ≡ z) (r : z ≡ w)
→ PathP (λ j → p (~ j) ≡ r j) q (p ∙∙ q ∙∙ r)
doubleCompPath-filler p q r j i =
hfill (doubleComp-faces p r i) (inS (q i)) j
-- any two definitions of double composition are equal
compPath-unique : ∀ (p : x ≡ y) (q : y ≡ z) (r : z ≡ w)
→ (α β : Σ[ s ∈ x ≡ w ] PathP (λ j → p (~ j) ≡ r j) q s)
→ α ≡ β
compPath-unique p q r (α , α-filler) (β , β-filler) t
= (λ i → cb i1 i) , (λ j i → cb j i)
where cb : I → I → _
cb j i = hfill (λ j → λ { (t = i0) → α-filler j i
; (t = i1) → β-filler j i
; (i = i0) → p (~ j)
; (i = i1) → r j })
(inS (q i)) j
{- For single homogenous path composition, we take `p = refl`:
x ∙ ∙ ∙ > z
‖ ^
‖ | r ^
‖ | j |
x — — — > y ∙ — >
q i
`q ∙ r` gives the line at the top,
`compPath-filler q r` gives the whole square
-}
_∙_ : x ≡ y → y ≡ z → x ≡ z
p ∙ q = refl ∙∙ p ∙∙ q
compPath-filler : (p : x ≡ y) (q : y ≡ z) → PathP (λ j → x ≡ q j) p (p ∙ q)
compPath-filler p q = doubleCompPath-filler refl p q
-- We could have also defined single composition by taking `r = refl`:
_∙'_ : x ≡ y → y ≡ z → x ≡ z
p ∙' q = p ∙∙ q ∙∙ refl
compPath'-filler : (p : x ≡ y) (q : y ≡ z) → PathP (λ j → p (~ j) ≡ z) q (p ∙' q)
compPath'-filler p q = doubleCompPath-filler p q refl
-- It's easy to show that `p ∙ q` also has such a filler:
compPath-filler' : (p : x ≡ y) (q : y ≡ z) → PathP (λ j → p (~ j) ≡ z) q (p ∙ q)
compPath-filler' {z = z} p q j i =
hcomp (λ k → λ { (i = i0) → p (~ j)
; (i = i1) → q k
; (j = i0) → q (i ∧ k) })
(p (i ∨ ~ j))
-- Note: We can omit a (j = i1) case here since when (j = i1), the whole expression is
-- definitionally equal to `p ∙ q`. (Notice that `p ∙ q` is also an hcomp.) Nevertheless,
-- we could have given `compPath-filler p q k i` as the (j = i1) case.
-- From this, we can show that these two notions of composition are the same
compPath≡compPath' : (p : x ≡ y) (q : y ≡ z) → p ∙ q ≡ p ∙' q
compPath≡compPath' p q j =
compPath-unique p q refl (p ∙ q , compPath-filler' p q)
(p ∙' q , compPath'-filler p q) j .fst
-- Heterogeneous path composition and its filler:
compPathP : ∀ {A : I → Type ℓ} {x : A i0} {y : A i1} {B_i1 : Type ℓ} {B : (A i1) ≡ B_i1} {z : B i1}
→ PathP A x y → PathP (λ i → B i) y z → PathP (λ j → ((λ i → A i) ∙ B) j) x z
compPathP {A = A} {x = x} {B = B} p q i =
comp (λ j → compPath-filler (λ i → A i) B j i)
(λ j → λ { (i = i0) → x ;
(i = i1) → q j })
(p i)
compPathP' : ∀ {ℓ ℓ'} {A : Type ℓ} {B : A → Type ℓ'} {x y z : A} {x' : B x} {y' : B y} {z' : B z} {p : x ≡ y} {q : y ≡ z}
(P : PathP (λ i → B (p i)) x' y') (Q : PathP (λ i → B (q i)) y' z')
→ PathP (λ i → B ((p ∙ q) i)) x' z'
compPathP' {B = B} {x' = x'} {p = p} {q = q} P Q i =
comp (λ j → B (compPath-filler p q j i))
(λ j → λ { (i = i0) → x' ;
(i = i1) → Q j })
(P i)
compPathP-filler : ∀ {A : I → Type ℓ} {x : A i0} {y : A i1} {B_i1 : Type ℓ} {B : A i1 ≡ B_i1} {z : B i1}
→ (p : PathP A x y) (q : PathP (λ i → B i) y z)
→ PathP (λ j → PathP (λ k → (compPath-filler (λ i → A i) B j k)) x (q j)) p (compPathP p q)
compPathP-filler {A = A} {x = x} {B = B} p q j i =
fill (λ j → compPath-filler (λ i → A i) B j i)
(λ j → λ { (i = i0) → x ;
(i = i1) → q j })
(inS (p i)) j
compPathP'-filler : ∀ {ℓ ℓ'} {A : Type ℓ} {B : A → Type ℓ'} {x y z : A} {x' : B x} {y' : B y} {z' : B z} {p : x ≡ y} {q : y ≡ z}
(P : PathP (λ i → B (p i)) x' y') (Q : PathP (λ i → B (q i)) y' z')
→ PathP (λ j → PathP (λ i → B (compPath-filler p q j i)) x' (Q j)) P (compPathP' {x = x} {y = y} {x' = x'} {y' = y'} P Q)
compPathP'-filler {B = B} {x' = x'} {p = p} {q = q} P Q j i =
fill (λ j → B (compPath-filler p q j i))
(λ j → λ { (i = i0) → x' ;
(i = i1) → Q j })
(inS (P i))
j
_≡⟨_⟩_ : (x : A) → x ≡ y → y ≡ z → x ≡ z
_ ≡⟨ x≡y ⟩ y≡z = x≡y ∙ y≡z
≡⟨⟩-syntax : (x : A) → x ≡ y → y ≡ z → x ≡ z
≡⟨⟩-syntax = _≡⟨_⟩_
infixr 2 ≡⟨⟩-syntax
syntax ≡⟨⟩-syntax x (λ i → B) y = x ≡[ i ]⟨ B ⟩ y
≡⟨⟩⟨⟩-syntax : (x y : A) → x ≡ y → y ≡ z → z ≡ w → x ≡ w
≡⟨⟩⟨⟩-syntax x y p q r = p ∙∙ q ∙∙ r
infixr 3 ≡⟨⟩⟨⟩-syntax
syntax ≡⟨⟩⟨⟩-syntax x y B C = x ≡⟨ B ⟩≡ y ≡⟨ C ⟩≡
_≡⟨_⟩≡⟨_⟩_ : (x : A) → x ≡ y → y ≡ z → z ≡ w → x ≡ w
_ ≡⟨ x≡y ⟩≡⟨ y≡z ⟩ z≡w = x≡y ∙∙ y≡z ∙∙ z≡w
_∎ : (x : A) → x ≡ x
_ ∎ = refl
-- Transport, subst and functional extensionality
-- transport is a special case of transp
transport : {A B : Type ℓ} → A ≡ B → A → B
transport p a = transp (λ i → p i) i0 a
-- Transporting in a constant family is the identity function (up to a
-- path). If we would have regularity this would be definitional.
transportRefl : (x : A) → transport refl x ≡ x
transportRefl {A = A} x i = transp (λ _ → A) i x
transport-filler : ∀ {ℓ} {A B : Type ℓ} (p : A ≡ B) (x : A)
→ PathP (λ i → p i) x (transport p x)
transport-filler p x i = transp (λ j → p (i ∧ j)) (~ i) x
-- We want B to be explicit in subst
subst : (B : A → Type ℓ') (p : x ≡ y) → B x → B y
subst B p pa = transport (λ i → B (p i)) pa
subst2 : ∀ {ℓ' ℓ''} {B : Type ℓ'} {z w : B} (C : A → B → Type ℓ'')
(p : x ≡ y) (q : z ≡ w) → C x z → C y w
subst2 B p q b = transport (λ i → B (p i) (q i)) b
substRefl : (px : B x) → subst B refl px ≡ px
substRefl px = transportRefl px
funExt : {B : A → I → Type ℓ'}
{f : (x : A) → B x i0} {g : (x : A) → B x i1}
→ ((x : A) → PathP (B x) (f x) (g x))
→ PathP (λ i → (x : A) → B x i) f g
funExt p i x = p x i
implicitFunExt : {B : A → I → Type ℓ'}
{f : {x : A} → B x i0} {g : {x : A} → B x i1}
→ ({x : A} → PathP (B x) (f {x}) (g {x}))
→ PathP (λ i → {x : A} → B x i) f g
implicitFunExt p i {x} = p {x} i
-- the inverse to funExt (see Functions.FunExtEquiv), converting paths
-- between functions to homotopies; `funExt⁻` is called `happly` and
-- defined by path induction in the HoTT book (see function 2.9.2 in
-- section 2.9)
funExt⁻ : {B : A → I → Type ℓ'}
{f : (x : A) → B x i0} {g : (x : A) → B x i1}
→ PathP (λ i → (x : A) → B x i) f g
→ ((x : A) → PathP (B x) (f x) (g x))
funExt⁻ eq x i = eq i x
-- J for paths and its computation rule
module _ (P : ∀ y → x ≡ y → Type ℓ') (d : P x refl) where
J : (p : x ≡ y) → P y p
J p = transport (λ i → P (p i) (λ j → p (i ∧ j))) d
JRefl : J refl ≡ d
JRefl = transportRefl d
J-∙ : (p : x ≡ y) (q : y ≡ z)
→ J (p ∙ q) ≡ transport (λ i → P (q i) (λ j → compPath-filler p q i j)) (J p)
J-∙ p q k =
transp
(λ i → P (q (i ∨ ~ k))
(λ j → compPath-filler p q (i ∨ ~ k) j)) (~ k)
(J (λ j → compPath-filler p q (~ k) j))
-- Converting to and from a PathP
module _ {A : I → Type ℓ} {x : A i0} {y : A i1} where
toPathP : transp (\ i → A i) i0 x ≡ y → PathP A x y
toPathP p i = hcomp (λ j → λ { (i = i0) → x
; (i = i1) → p j })
(transp (λ j → A (i ∧ j)) (~ i) x)
fromPathP : PathP A x y → transp (\ i → A i) i0 x ≡ y
fromPathP p i = transp (λ j → A (i ∨ j)) i (p i)
-- Whiskering a dependent path by a path
_◁_ : ∀ {ℓ} {A : I → Type ℓ} {a₀ a₀' : A i0} {a₁ : A i1}
→ a₀ ≡ a₀' → PathP A a₀' a₁ → PathP A a₀ a₁
(p ◁ q) i =
hcomp (λ j → λ {(i = i0) → p (~ j); (i = i1) → q i1}) (q i)
_▷_ : ∀ {ℓ} {A : I → Type ℓ} {a₀ : A i0} {a₁ a₁' : A i1}
→ PathP A a₀ a₁ → a₁ ≡ a₁' → PathP A a₀ a₁'
(p ▷ q) i =
hcomp (λ j → λ {(i = i0) → p i0; (i = i1) → q j}) (p i)
-- Direct definitions of lower h-levels
isContr : Type ℓ → Type ℓ
isContr A = Σ[ x ∈ A ] (∀ y → x ≡ y)
isProp : Type ℓ → Type ℓ
isProp A = (x y : A) → x ≡ y
isSet : Type ℓ → Type ℓ
isSet A = (x y : A) → isProp (x ≡ y)
isGroupoid : Type ℓ → Type ℓ
isGroupoid A = ∀ a b → isSet (Path A a b)
is2Groupoid : Type ℓ → Type ℓ
is2Groupoid A = ∀ a b → isGroupoid (Path A a b)
-- Contractibility of singletons
singlP : (A : I → Type ℓ) (a : A i0) → Type _
singlP A a = Σ[ x ∈ A i1 ] PathP A a x
singl : (a : A) → Type _
singl {A = A} a = singlP (λ _ → A) a
isContrSingl : (a : A) → isContr (singl a)
isContrSingl a = (a , refl) , λ p i → p .snd i , λ j → p .snd (i ∧ j)
isContrSinglP : (A : I → Type ℓ) (a : A i0) → isContr (singlP A a)
isContrSinglP A a .fst = _ , transport-filler (λ i → A i) a
isContrSinglP A a .snd (x , p) i =
_ , λ j → fill (\ i → A i) (λ j → λ {(i = i0) → transport-filler (λ i → A i) a j; (i = i1) → p j}) (inS a) j
SquareP :
(A : I → I → Type ℓ)
{a₀₀ : A i0 i0} {a₀₁ : A i0 i1} (a₀₋ : PathP (λ j → A i0 j) a₀₀ a₀₁)
{a₁₀ : A i1 i0} {a₁₁ : A i1 i1} (a₁₋ : PathP (λ j → A i1 j) a₁₀ a₁₁)
(a₋₀ : PathP (λ i → A i i0) a₀₀ a₁₀) (a₋₁ : PathP (λ i → A i i1) a₀₁ a₁₁)
→ Type ℓ
SquareP A a₀₋ a₁₋ a₋₀ a₋₁ = PathP (λ i → PathP (λ j → A i j) (a₋₀ i) (a₋₁ i)) a₀₋ a₁₋
Square :
{a₀₀ a₀₁ : A} (a₀₋ : a₀₀ ≡ a₀₁)
{a₁₀ a₁₁ : A} (a₁₋ : a₁₀ ≡ a₁₁)
(a₋₀ : a₀₀ ≡ a₁₀) (a₋₁ : a₀₁ ≡ a₁₁)
→ Type _
Square a₀₋ a₁₋ a₋₀ a₋₁ = PathP (λ i → a₋₀ i ≡ a₋₁ i) a₀₋ a₁₋
isSet' : Type ℓ → Type ℓ
isSet' A =
{a₀₀ a₀₁ : A} (a₀₋ : a₀₀ ≡ a₀₁)
{a₁₀ a₁₁ : A} (a₁₋ : a₁₀ ≡ a₁₁)
(a₋₀ : a₀₀ ≡ a₁₀) (a₋₁ : a₀₁ ≡ a₁₁)
→ Square a₀₋ a₁₋ a₋₀ a₋₁
Cube :
{a₀₀₀ a₀₀₁ : A} {a₀₀₋ : a₀₀₀ ≡ a₀₀₁}
{a₀₁₀ a₀₁₁ : A} {a₀₁₋ : a₀₁₀ ≡ a₀₁₁}
{a₀₋₀ : a₀₀₀ ≡ a₀₁₀} {a₀₋₁ : a₀₀₁ ≡ a₀₁₁}
(a₀₋₋ : Square a₀₀₋ a₀₁₋ a₀₋₀ a₀₋₁)
{a₁₀₀ a₁₀₁ : A} {a₁₀₋ : a₁₀₀ ≡ a₁₀₁}
{a₁₁₀ a₁₁₁ : A} {a₁₁₋ : a₁₁₀ ≡ a₁₁₁}
{a₁₋₀ : a₁₀₀ ≡ a₁₁₀} {a₁₋₁ : a₁₀₁ ≡ a₁₁₁}
(a₁₋₋ : Square a₁₀₋ a₁₁₋ a₁₋₀ a₁₋₁)
{a₋₀₀ : a₀₀₀ ≡ a₁₀₀} {a₋₀₁ : a₀₀₁ ≡ a₁₀₁}
(a₋₀₋ : Square a₀₀₋ a₁₀₋ a₋₀₀ a₋₀₁)
{a₋₁₀ : a₀₁₀ ≡ a₁₁₀} {a₋₁₁ : a₀₁₁ ≡ a₁₁₁}
(a₋₁₋ : Square a₀₁₋ a₁₁₋ a₋₁₀ a₋₁₁)
(a₋₋₀ : Square a₀₋₀ a₁₋₀ a₋₀₀ a₋₁₀)
(a₋₋₁ : Square a₀₋₁ a₁₋₁ a₋₀₁ a₋₁₁)
→ Type _
Cube a₀₋₋ a₁₋₋ a₋₀₋ a₋₁₋ a₋₋₀ a₋₋₁ =
PathP (λ i → Square (a₋₀₋ i) (a₋₁₋ i) (a₋₋₀ i) (a₋₋₁ i)) a₀₋₋ a₁₋₋
isGroupoid' : Type ℓ → Type ℓ
isGroupoid' A =
{a₀₀₀ a₀₀₁ : A} {a₀₀₋ : a₀₀₀ ≡ a₀₀₁}
{a₀₁₀ a₀₁₁ : A} {a₀₁₋ : a₀₁₀ ≡ a₀₁₁}
{a₀₋₀ : a₀₀₀ ≡ a₀₁₀} {a₀₋₁ : a₀₀₁ ≡ a₀₁₁}
(a₀₋₋ : Square a₀₀₋ a₀₁₋ a₀₋₀ a₀₋₁)
{a₁₀₀ a₁₀₁ : A} {a₁₀₋ : a₁₀₀ ≡ a₁₀₁}
{a₁₁₀ a₁₁₁ : A} {a₁₁₋ : a₁₁₀ ≡ a₁₁₁}
{a₁₋₀ : a₁₀₀ ≡ a₁₁₀} {a₁₋₁ : a₁₀₁ ≡ a₁₁₁}
(a₁₋₋ : Square a₁₀₋ a₁₁₋ a₁₋₀ a₁₋₁)
{a₋₀₀ : a₀₀₀ ≡ a₁₀₀} {a₋₀₁ : a₀₀₁ ≡ a₁₀₁}
(a₋₀₋ : Square a₀₀₋ a₁₀₋ a₋₀₀ a₋₀₁)
{a₋₁₀ : a₀₁₀ ≡ a₁₁₀} {a₋₁₁ : a₀₁₁ ≡ a₁₁₁}
(a₋₁₋ : Square a₀₁₋ a₁₁₋ a₋₁₀ a₋₁₁)
(a₋₋₀ : Square a₀₋₀ a₁₋₀ a₋₀₀ a₋₁₀)
(a₋₋₁ : Square a₀₋₁ a₁₋₁ a₋₀₁ a₋₁₁)
→ Cube a₀₋₋ a₁₋₋ a₋₀₋ a₋₁₋ a₋₋₀ a₋₋₁
-- Essential consequences of isProp and isContr
isProp→PathP : ∀ {B : I → Type ℓ} → ((i : I) → isProp (B i))
→ (b0 : B i0) (b1 : B i1)
→ PathP (λ i → B i) b0 b1
isProp→PathP hB b0 b1 = toPathP (hB _ _ _)
isPropIsContr : isProp (isContr A)
isPropIsContr (c0 , h0) (c1 , h1) j =
h0 c1 j , λ y i → hcomp (λ k → λ { (i = i0) → h0 (h0 c1 j) k;
(i = i1) → h0 y k;
(j = i0) → h0 (h0 y i) k;
(j = i1) → h0 (h1 y i) k}) c0
isContr→isProp : isContr A → isProp A
isContr→isProp (x , p) a b i =
hcomp (λ j → λ { (i = i0) → p a j
; (i = i1) → p b j }) x
isProp→isSet : isProp A → isSet A
isProp→isSet h a b p q j i =
hcomp (λ k → λ { (i = i0) → h a a k
; (i = i1) → h a b k
; (j = i0) → h a (p i) k
; (j = i1) → h a (q i) k }) a
isProp→isSet' : isProp A → isSet' A
isProp→isSet' h {a} p q r s i j =
hcomp (λ k → λ { (i = i0) → h a (p j) k
; (i = i1) → h a (q j) k
; (j = i0) → h a (r i) k
; (j = i1) → h a (s i) k}) a
isPropIsProp : isProp (isProp A)
isPropIsProp f g i a b = isProp→isSet f a b (f a b) (g a b) i
isPropSingl : {a : A} → isProp (singl a)
isPropSingl = isContr→isProp (isContrSingl _)
isPropSinglP : {A : I → Type ℓ} {a : A i0} → isProp (singlP A a)
isPropSinglP = isContr→isProp (isContrSinglP _ _)
-- Universe lifting
record Lift {i j} (A : Type i) : Type (ℓ-max i j) where
constructor lift
field
lower : A
open Lift public
liftExt : ∀ {A : Type ℓ} {a b : Lift {ℓ} {ℓ'} A} → (lower a ≡ lower b) → a ≡ b
liftExt x i = lift (x i)
doubleCompPath-filler∙ : {a b c d : A} (p : a ≡ b) (q : b ≡ c) (r : c ≡ d)
→ PathP (λ i → p i ≡ r (~ i)) (p ∙ q ∙ r) q
doubleCompPath-filler∙ {A = A} {b = b} p q r j i =
hcomp (λ k → λ { (i = i0) → p j
; (i = i1) → side j k
; (j = i1) → q (i ∧ k)})
(p (j ∨ i))
where
side : I → I → A
side i j =
hcomp (λ k → λ { (i = i1) → q j
; (j = i0) → b
; (j = i1) → r (~ i ∧ k)})
(q j)
PathP→compPathL : {a b c d : A} {p : a ≡ c} {q : b ≡ d} {r : a ≡ b} {s : c ≡ d}
→ PathP (λ i → p i ≡ q i) r s
→ sym p ∙ r ∙ q ≡ s
PathP→compPathL {p = p} {q = q} {r = r} {s = s} P j i =
hcomp (λ k → λ { (i = i0) → p (j ∨ k)
; (i = i1) → q (j ∨ k)
; (j = i0) → doubleCompPath-filler∙ (sym p) r q (~ k) i
; (j = i1) → s i })
(P j i)
PathP→compPathR : {a b c d : A} {p : a ≡ c} {q : b ≡ d} {r : a ≡ b} {s : c ≡ d}
→ PathP (λ i → p i ≡ q i) r s
→ r ≡ p ∙ s ∙ sym q
PathP→compPathR {p = p} {q = q} {r = r} {s = s} P j i =
hcomp (λ k → λ { (i = i0) → p (j ∧ (~ k))
; (i = i1) → q (j ∧ (~ k))
; (j = i0) → r i
; (j = i1) → doubleCompPath-filler∙ p s (sym q) (~ k) i})
(P j i)
-- otherdir
compPathL→PathP : {a b c d : A} {p : a ≡ c} {q : b ≡ d} {r : a ≡ b} {s : c ≡ d}
→ sym p ∙ r ∙ q ≡ s
→ PathP (λ i → p i ≡ q i) r s
compPathL→PathP {p = p} {q = q} {r = r} {s = s} P j i =
hcomp (λ k → λ { (i = i0) → p (~ k ∨ j)
; (i = i1) → q (~ k ∨ j)
; (j = i0) → doubleCompPath-filler∙ (sym p) r q k i
; (j = i1) → s i})
(P j i)
compPathR→PathP : {a b c d : A} {p : a ≡ c} {q : b ≡ d} {r : a ≡ b} {s : c ≡ d}
→ r ≡ p ∙ s ∙ sym q
→ PathP (λ i → p i ≡ q i) r s
compPathR→PathP {p = p} {q = q} {r = r} {s = s} P j i =
hcomp (λ k → λ { (i = i0) → p (k ∧ j)
; (i = i1) → q (k ∧ j)
; (j = i0) → r i
; (j = i1) → doubleCompPath-filler∙ p s (sym q) k i})
(P j i)
| {
"alphanum_fraction": 0.4529682521,
"avg_line_length": 33.4901185771,
"ext": "agda",
"hexsha": "86290f97a7cd9a0c1af278d444cba29a336c7184",
"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/Foundations/Prelude.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/Foundations/Prelude.agda",
"max_line_length": 131,
"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/Foundations/Prelude.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 8025,
"size": 16946
} |
-- Andreas, 2012-11-18: abstract record values
module Issue759 where
import Common.Level
abstract
record Wrap (A : Set) : Set where
field wrapped : A
open Wrap public
wrap : {A : Set} → A → Wrap A
wrap a = record { wrapped = a }
-- caused 'Not in Scope: recCon-NOT-PRINTED'
-- during eta-contraction in serialization
-- should work now
| {
"alphanum_fraction": 0.6827195467,
"avg_line_length": 19.6111111111,
"ext": "agda",
"hexsha": "ed25dfc4f1cb4cd52153b5d160cfb8a43af1f590",
"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/Issue759.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/Issue759.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/Succeed/Issue759.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": 353
} |
module Structure.Operator.Group where
import Lvl
open import Logic
open import Logic.IntroInstances
open import Logic.Predicate
open import Structure.Setoid
open import Structure.Function
open import Structure.Operator.Monoid using (Monoid)
open import Structure.Operator.Properties hiding (commutativity)
open import Type
open import Type.Size
-- A type and a binary operator using this type is a group when:
-- • It is a monoid.
-- • The operator have an inverse in both directions.
record Group {ℓ ℓₑ} {T : Type{ℓ}} ⦃ _ : Equiv{ℓₑ}(T) ⦄ (_▫_ : T → T → T) : Stmt{ℓ Lvl.⊔ ℓₑ} where
constructor intro
field
⦃ monoid ⦄ : Monoid(_▫_)
open Monoid(monoid) public
field
⦃ inverse-existence ⦄ : ∃(InverseFunction(_▫_) ⦃ identity-existence ⦄)
inv = [∃]-witness inverse-existence
field
⦃ inv-function ⦄ : Function(inv)
instance
inverse : InverseFunction (_▫_) inv
inverse = [∃]-proof inverse-existence
instance
inverseₗ : InverseFunctionₗ (_▫_) inv
inverseₗ = InverseFunction.left(inverse)
instance
inverseᵣ : InverseFunctionᵣ (_▫_) inv
inverseᵣ = InverseFunction.right(inverse)
inv-op : T → T → T
inv-op x y = x ▫ inv y
record CommutativeGroup {ℓ ℓₑ} {T : Type{ℓ}} ⦃ _ : Equiv{ℓₑ}(T) ⦄ (_▫_ : T → T → T) : Stmt{ℓ Lvl.⊔ ℓₑ} where
constructor intro
field
⦃ group ⦄ : Group (_▫_)
⦃ commutativity ⦄ : Commutativity (_▫_)
open Group(group) public
{- TODO: See Monoid for how this should be rewritten to fit how it is done in Category
module Morphism where
module _ {ℓ₁ ℓ₂} {X : Type{ℓ₁}} ⦃ _ : Equiv(X) ⦄ {_▫X_ : X → X → X} ⦃ structureₗ : Group(_▫X_) ⦄ {Y : Type{ℓ₂}} ⦃ _ : Equiv(Y) ⦄ {_▫Y_ : Y → Y → Y} ⦃ structureᵣ : Group(_▫Y_) ⦄ (f : X → Y) where
-- Group homomorphism
record Homomorphism : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
idₗ = Group.id(structureₗ)
idᵣ = Group.id(structureᵣ)
invₗ = Group.inv(structureₗ)
invᵣ = Group.inv(structureᵣ)
field
preserve-op : ∀{x y : X} → (f(x ▫X y) ≡ f(x) ▫Y f(y))
-- TODO: These may be unneccessary because they follow from preserve-op when Function(f)
preserve-inv : ∀{x : X} → (f(invₗ x) ≡ invᵣ(f(x)))
preserve-id : (f(idₗ) ≡ idᵣ)
-- Group monomorphism (Injective homomorphism)
record Monomorphism : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field
⦃ homomorphism ⦄ : Homomorphism
⦃ size ⦄ : (X ≼ Y)
-- Group epimorphism (Surjective homomorphism)
record Epimorphism : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field
⦃ homomorphism ⦄ : Homomorphism
⦃ size ⦄ : (X ≽ Y)
-- Group isomorphism (Bijective homomorphism)
record Isomorphism : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field
⦃ homomorphism ⦄ : Homomorphism
⦃ size ⦄ : (X ≍ Y)
_↣_ : ∀{ℓ₁ ℓ₂} → {X : Type{ℓ₁}} → ⦃ _ : Equiv(X) ⦄ → (_▫X_ : X → X → X) → ⦃ structureₗ : Group(_▫X_) ⦄ → {Y : Type{ℓ₂}} → ⦃ _ : Equiv(Y) ⦄ → (_▫Y_ : Y → Y → Y) → ⦃ structureᵣ : Group(_▫Y_) ⦄ → Stmt{ℓ₁ Lvl.⊔ ℓ₂}
(_▫X_) ↣ (_▫Y_) = ∃(Monomorphism{_▫X_ = _▫X_}{_▫Y_ = _▫Y_})
_↠_ : ∀{ℓ₁ ℓ₂} → {X : Type{ℓ₁}} → ⦃ _ : Equiv(X) ⦄ → (_▫X_ : X → X → X) → ⦃ structureₗ : Group(_▫X_) ⦄ → {Y : Type{ℓ₂}} → ⦃ _ : Equiv(Y) ⦄ → (_▫Y_ : Y → Y → Y) → ⦃ structureᵣ : Group(_▫Y_) ⦄ → Stmt{ℓ₁ Lvl.⊔ ℓ₂}
(_▫X_) ↠ (_▫Y_) = ∃(Epimorphism{_▫X_ = _▫X_}{_▫Y_ = _▫Y_})
_⤖_ : ∀{ℓ₁ ℓ₂} → {X : Type{ℓ₁}} → ⦃ _ : Equiv(X) ⦄ → (_▫X_ : X → X → X) → ⦃ structureₗ : Group(_▫X_) ⦄ → {Y : Type{ℓ₂}} → ⦃ _ : Equiv(Y) ⦄ → (_▫Y_ : Y → Y → Y) → ⦃ structureᵣ : Group(_▫Y_) ⦄ → Stmt{ℓ₁ Lvl.⊔ ℓ₂}
(_▫X_) ⤖ (_▫Y_) = ∃(Isomorphism{_▫X_ = _▫X_}{_▫Y_ = _▫Y_})
-}
| {
"alphanum_fraction": 0.5867924528,
"avg_line_length": 36.3725490196,
"ext": "agda",
"hexsha": "08da31e18579c9e92373bcd8935616c4c2a80342",
"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/Operator/Group.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/Operator/Group.agda",
"max_line_length": 212,
"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/Operator/Group.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": 1595,
"size": 3710
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- A bunch of properties
------------------------------------------------------------------------
module Data.Bool.Properties where
open import Data.Bool as Bool
open import Data.Fin
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence
using (_⇔_; equivalence; module Equivalence)
open import Algebra
open import Algebra.Structures
import Algebra.RingSolver.Simple as Solver
import Algebra.RingSolver.AlmostCommutativeRing as ACR
open import Relation.Binary.PropositionalEquality as P
using (_≡_; _≢_; refl)
open P.≡-Reasoning
import Algebra.FunctionProperties as FP; open FP (_≡_ {A = Bool})
open import Data.Product
open import Data.Sum
open import Data.Empty
------------------------------------------------------------------------
-- Duality
-- Can we take advantage of duality in some (nice) way?
------------------------------------------------------------------------
-- (Bool, ∨, ∧, false, true) forms a commutative semiring
private
∨-assoc : Associative _∨_
∨-assoc true y z = refl
∨-assoc false y z = refl
∧-assoc : Associative _∧_
∧-assoc true y z = refl
∧-assoc false y z = refl
∨-comm : Commutative _∨_
∨-comm true true = refl
∨-comm true false = refl
∨-comm false true = refl
∨-comm false false = refl
∧-comm : Commutative _∧_
∧-comm true true = refl
∧-comm true false = refl
∧-comm false true = refl
∧-comm false false = refl
distrib-∧-∨ : _∧_ DistributesOver _∨_
distrib-∧-∨ = distˡ , distʳ
where
distˡ : _∧_ DistributesOverˡ _∨_
distˡ true y z = refl
distˡ false y z = refl
distʳ : _∧_ DistributesOverʳ _∨_
distʳ x y z =
begin
(y ∨ z) ∧ x
≡⟨ ∧-comm (y ∨ z) x ⟩
x ∧ (y ∨ z)
≡⟨ distˡ x y z ⟩
x ∧ y ∨ x ∧ z
≡⟨ P.cong₂ _∨_ (∧-comm x y) (∧-comm x z) ⟩
y ∧ x ∨ z ∧ x
∎
isCommutativeSemiring-∨-∧
: IsCommutativeSemiring _≡_ _∨_ _∧_ false true
isCommutativeSemiring-∨-∧ = record
{ +-isCommutativeMonoid = record
{ isSemigroup = record
{ isEquivalence = P.isEquivalence
; assoc = ∨-assoc
; ∙-cong = P.cong₂ _∨_
}
; identityˡ = λ _ → refl
; comm = ∨-comm
}
; *-isCommutativeMonoid = record
{ isSemigroup = record
{ isEquivalence = P.isEquivalence
; assoc = ∧-assoc
; ∙-cong = P.cong₂ _∧_
}
; identityˡ = λ _ → refl
; comm = ∧-comm
}
; distribʳ = proj₂ distrib-∧-∨
; zeroˡ = λ _ → refl
}
commutativeSemiring-∨-∧ : CommutativeSemiring _ _
commutativeSemiring-∨-∧ = record
{ _+_ = _∨_
; _*_ = _∧_
; 0# = false
; 1# = true
; isCommutativeSemiring = isCommutativeSemiring-∨-∧
}
module RingSolver =
Solver (ACR.fromCommutativeSemiring commutativeSemiring-∨-∧) _≟_
------------------------------------------------------------------------
-- (Bool, ∧, ∨, true, false) forms a commutative semiring
private
distrib-∨-∧ : _∨_ DistributesOver _∧_
distrib-∨-∧ = distˡ , distʳ
where
distˡ : _∨_ DistributesOverˡ _∧_
distˡ true y z = refl
distˡ false y z = refl
distʳ : _∨_ DistributesOverʳ _∧_
distʳ x y z =
begin
(y ∧ z) ∨ x
≡⟨ ∨-comm (y ∧ z) x ⟩
x ∨ (y ∧ z)
≡⟨ distˡ x y z ⟩
(x ∨ y) ∧ (x ∨ z)
≡⟨ P.cong₂ _∧_ (∨-comm x y) (∨-comm x z) ⟩
(y ∨ x) ∧ (z ∨ x)
∎
isCommutativeSemiring-∧-∨
: IsCommutativeSemiring _≡_ _∧_ _∨_ true false
isCommutativeSemiring-∧-∨ = record
{ +-isCommutativeMonoid = record
{ isSemigroup = record
{ isEquivalence = P.isEquivalence
; assoc = ∧-assoc
; ∙-cong = P.cong₂ _∧_
}
; identityˡ = λ _ → refl
; comm = ∧-comm
}
; *-isCommutativeMonoid = record
{ isSemigroup = record
{ isEquivalence = P.isEquivalence
; assoc = ∨-assoc
; ∙-cong = P.cong₂ _∨_
}
; identityˡ = λ _ → refl
; comm = ∨-comm
}
; distribʳ = proj₂ distrib-∨-∧
; zeroˡ = λ _ → refl
}
commutativeSemiring-∧-∨ : CommutativeSemiring _ _
commutativeSemiring-∧-∨ = record
{ _+_ = _∧_
; _*_ = _∨_
; 0# = true
; 1# = false
; isCommutativeSemiring = isCommutativeSemiring-∧-∨
}
------------------------------------------------------------------------
-- (Bool, ∨, ∧, not, true, false) is a boolean algebra
private
absorptive : Absorptive _∨_ _∧_
absorptive = abs-∨-∧ , abs-∧-∨
where
abs-∨-∧ : _∨_ Absorbs _∧_
abs-∨-∧ true y = refl
abs-∨-∧ false y = refl
abs-∧-∨ : _∧_ Absorbs _∨_
abs-∧-∨ true y = refl
abs-∧-∨ false y = refl
not-∧-inverse : Inverse false not _∧_
not-∧-inverse =
¬x∧x≡⊥ , (λ x → ∧-comm x (not x) ⟨ P.trans ⟩ ¬x∧x≡⊥ x)
where
¬x∧x≡⊥ : LeftInverse false not _∧_
¬x∧x≡⊥ false = refl
¬x∧x≡⊥ true = refl
not-∨-inverse : Inverse true not _∨_
not-∨-inverse =
¬x∨x≡⊤ , (λ x → ∨-comm x (not x) ⟨ P.trans ⟩ ¬x∨x≡⊤ x)
where
¬x∨x≡⊤ : LeftInverse true not _∨_
¬x∨x≡⊤ false = refl
¬x∨x≡⊤ true = refl
isBooleanAlgebra : IsBooleanAlgebra _≡_ _∨_ _∧_ not true false
isBooleanAlgebra = record
{ isDistributiveLattice = record
{ isLattice = record
{ isEquivalence = P.isEquivalence
; ∨-comm = ∨-comm
; ∨-assoc = ∨-assoc
; ∨-cong = P.cong₂ _∨_
; ∧-comm = ∧-comm
; ∧-assoc = ∧-assoc
; ∧-cong = P.cong₂ _∧_
; absorptive = absorptive
}
; ∨-∧-distribʳ = proj₂ distrib-∨-∧
}
; ∨-complementʳ = proj₂ not-∨-inverse
; ∧-complementʳ = proj₂ not-∧-inverse
; ¬-cong = P.cong not
}
booleanAlgebra : BooleanAlgebra _ _
booleanAlgebra = record
{ _∨_ = _∨_
; _∧_ = _∧_
; ¬_ = not
; ⊤ = true
; ⊥ = false
; isBooleanAlgebra = isBooleanAlgebra
}
------------------------------------------------------------------------
-- (Bool, xor, ∧, id, false, true) forms a commutative ring
private
xor-is-ok : ∀ x y → x xor y ≡ (x ∨ y) ∧ not (x ∧ y)
xor-is-ok true y = refl
xor-is-ok false y = P.sym $ proj₂ CS.*-identity _
where module CS = CommutativeSemiring commutativeSemiring-∨-∧
commutativeRing-xor-∧ : CommutativeRing _ _
commutativeRing-xor-∧ = commutativeRing
where
import Algebra.Properties.BooleanAlgebra as BA
open BA booleanAlgebra
open XorRing _xor_ xor-is-ok
module XorRingSolver =
Solver (ACR.fromCommutativeRing commutativeRing-xor-∧) _≟_
------------------------------------------------------------------------
-- Miscellaneous other properties
not-involutive : Involutive not
not-involutive true = refl
not-involutive false = refl
not-¬ : ∀ {x y} → x ≡ y → x ≢ not y
not-¬ {true} refl ()
not-¬ {false} refl ()
¬-not : ∀ {x y} → x ≢ y → x ≡ not y
¬-not {true} {true} x≢y = ⊥-elim (x≢y refl)
¬-not {true} {false} _ = refl
¬-not {false} {true} _ = refl
¬-not {false} {false} x≢y = ⊥-elim (x≢y refl)
⇔→≡ : {b₁ b₂ b : Bool} → b₁ ≡ b ⇔ b₂ ≡ b → b₁ ≡ b₂
⇔→≡ {true } {true } hyp = refl
⇔→≡ {true } {false} {true } hyp = P.sym (Equivalence.to hyp ⟨$⟩ refl)
⇔→≡ {true } {false} {false} hyp = Equivalence.from hyp ⟨$⟩ refl
⇔→≡ {false} {true } {true } hyp = Equivalence.from hyp ⟨$⟩ refl
⇔→≡ {false} {true } {false} hyp = P.sym (Equivalence.to hyp ⟨$⟩ refl)
⇔→≡ {false} {false} hyp = refl
T-≡ : ∀ {b} → T b ⇔ b ≡ true
T-≡ {false} = equivalence (λ ()) (λ ())
T-≡ {true} = equivalence (const refl) (const _)
T-not-≡ : ∀ {b} → T (not b) ⇔ b ≡ false
T-not-≡ {false} = equivalence (const refl) (const _)
T-not-≡ {true} = equivalence (λ ()) (λ ())
T-∧ : ∀ {b₁ b₂} → T (b₁ ∧ b₂) ⇔ (T b₁ × T b₂)
T-∧ {true} {true} = equivalence (const (_ , _)) (const _)
T-∧ {true} {false} = equivalence (λ ()) proj₂
T-∧ {false} {_} = equivalence (λ ()) proj₁
T-∨ : ∀ {b₁ b₂} → T (b₁ ∨ b₂) ⇔ (T b₁ ⊎ T b₂)
T-∨ {true} {b₂} = equivalence inj₁ (const _)
T-∨ {false} {true} = equivalence inj₂ (const _)
T-∨ {false} {false} = equivalence inj₁ [ id , id ]
proof-irrelevance : ∀ {b} (p q : T b) → p ≡ q
proof-irrelevance {true} _ _ = refl
proof-irrelevance {false} () ()
push-function-into-if :
∀ {a b} {A : Set a} {B : Set b} (f : A → B) x {y z} →
f (if x then y else z) ≡ (if x then f y else f z)
push-function-into-if _ true = P.refl
push-function-into-if _ false = P.refl
| {
"alphanum_fraction": 0.5038908312,
"avg_line_length": 29.0721311475,
"ext": "agda",
"hexsha": "e420c43930bf33c99931455a7dacb48038adeafd",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/Bool/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/Bool/Properties.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/Bool/Properties.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": 3254,
"size": 8867
} |
module x03-842Relations-hc-2 where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym) -- added sym
open import Data.Nat using (ℕ; zero; suc; _+_; _*_)
open import Data.Nat.Properties using (+-comm; *-comm; *-zeroʳ)
------------------------------------------------------------------------------
-- inequality : ≤
data _≤_ : ℕ → ℕ → Set where
z≤n : ∀ {n : ℕ}
--------
→ zero ≤ n
s≤s : ∀ {m n : ℕ}
→ m ≤ n
-------------
→ suc m ≤ suc n
infix 4 _≤_
_ : 2 ≤ 4 -- multiple 'refine' will do this automatically
_ = s≤s (s≤s z≤n)
_ : 2 ≤ 4 -- implicit args
_ = s≤s {1} {3} (s≤s {0} {2} z≤n)
_ : 2 ≤ 4 -- named implicit args
_ = s≤s {m = 1} {n = 3} (s≤s {m = 0} {n = 2} z≤n)
_ : 2 ≤ 4 -- some implicit named args
_ = s≤s {n = 3} (s≤s {m = 0} z≤n)
--------------------------------------------------
-- inversion
inv-s≤s : ∀ {m n : ℕ}
→ suc m ≤ suc n
-------------
→ m ≤ n
inv-s≤s (s≤s m≤n) = m≤n
inv-z≤n : ∀ {m : ℕ}
→ m ≤ zero
--------
→ m ≡ zero
inv-z≤n z≤n = refl
-- reflexive
≤-refl : ∀ {n : ℕ}
-----
→ n ≤ n
≤-refl {zero} = z≤n
≤-refl {suc n} = s≤s (≤-refl {n})
--------------------------------------------------
-- transitive
≤-trans : ∀ {m n p : ℕ} -- note implicit arguments
→ m ≤ n
→ n ≤ p
-----
→ m ≤ p
≤-trans z≤n n≤p = z≤n
≤-trans (s≤s m≤n) (s≤s n≤p) = s≤s (≤-trans m≤n n≤p)
≤-trans′ : ∀ (m n p : ℕ) -- without implicit arguments
→ m ≤ n
→ n ≤ p
-----
→ m ≤ p
≤-trans′ .0 _ _
z≤n n≤p = z≤n
≤-trans′ (suc m) (suc n) (suc p)
(s≤s m≤n) (s≤s n≤p) = s≤s (≤-trans′ m n p m≤n n≤p)
--------------------------------------------------
-- antisymmetry
≤-antisym : ∀ {m n : ℕ}
→ m ≤ n
→ n ≤ m
-----
→ m ≡ n
≤-antisym z≤n z≤n = refl
≤-antisym (s≤s m≤n) (s≤s n≤m) rewrite ≤-antisym m≤n n≤m = refl
--------------------------------------------------
-- total ordering def with parameters
data Total (m n : ℕ) : Set where
forward :
m ≤ n
---------
→ Total m n
flipped :
n ≤ m
---------
→ Total m n
-- equivalent def without parameters
data Total′ : ℕ → ℕ → Set where
forward′ : ∀ {m n : ℕ}
→ m ≤ n
----------
→ Total′ m n
flipped′ : ∀ {m n : ℕ}
→ n ≤ m
----------
→ Total′ m n
-- prove ≤ is a total order -- using WITH
≤-total : ∀ (m n : ℕ) → Total m n
≤-total zero n = forward z≤n
≤-total (suc m) zero = flipped z≤n
≤-total (suc m) (suc n) with ≤-total m n
... | forward x = forward (s≤s x)
... | flipped x = flipped (s≤s x)
≤-total′ : ∀ (m n : ℕ) → Total m n -- using helper defined in 'where'
≤-total′ zero n = forward z≤n
≤-total′ (suc m) zero = flipped z≤n
≤-total′ (suc m) (suc n) = helper (≤-total m n)
where
helper : Total m n → Total (suc m) (suc n)
helper (forward x) = forward (s≤s x)
helper (flipped x) = flipped (s≤s x)
-- same but split on n first
≤-totalN : ∀ (m n : ℕ) → Total m n
≤-totalN m zero = flipped z≤n
≤-totalN zero n = forward z≤n
≤-totalN (suc m) (suc n) with ≤-totalN m n
... | forward x = forward (s≤s x)
... | flipped x = flipped (s≤s x)
--------------------------------------------------
-- monotonicity of + with respect to ≤
-- inequality added on right
+-monoʳ-≤ : ∀ (m p q : ℕ)
→ p ≤ q
-------------
→ m + p ≤ m + q
+-monoʳ-≤ zero p q p≤q = p≤q
+-monoʳ-≤ (suc m) p q p≤q -- suc m + p ≤ suc m + q
-- suc (m + p) ≤ suc (m + q)
= s≤s (+-monoʳ-≤ m p q p≤q) -- can be done by refine then recurse
-- inequality added on left
+-monoˡ-≤ : ∀ (p q m : ℕ)
→ p ≤ q
-------------
→ p + m ≤ q + m
+-monoˡ-≤ p q m p≤q -- p + m ≤ q + m
rewrite
+-comm p m -- m + p ≤ q + m
| +-comm q m -- m + p ≤ m + q
= +-monoʳ-≤ m p q p≤q
-- combine above
+-mono-≤ : ∀ (m n p q : ℕ)
→ m ≤ n
→ p ≤ q
-------------
→ m + p ≤ n + q
+-mono-≤ m n p q m≤n p≤q = ≤-trans (+-monoʳ-≤ m p q p≤q ) (+-monoˡ-≤ m n q m≤n)
--------------------------------------------------
-- monotonicity of *
m≤n→n≡0→n≡0 : ∀ (m : ℕ) → m ≤ zero → m ≡ 0
m≤n→n≡0→n≡0 zero m≤0 = refl
-- inequality multiplied on right
*-monoʳ-≤ : ∀ (m p q : ℕ)
→ p ≤ q
-------------
→ m * p ≤ m * q
*-monoʳ-≤ zero p q p≤q = z≤n
*-monoʳ-≤ m zero q p≤q -- m * zero ≤ m * q
rewrite
*-zeroʳ m -- 0 ≤ m * q
= z≤n
*-monoʳ-≤ m p zero p≤q -- m * p ≤ m * zero
rewrite
*-zeroʳ m -- m * p ≤ 0
| m≤n→n≡0→n≡0 p p≤q -- m * 0 ≤ 0
| *-zeroʳ m -- 0 ≤ 0
= z≤n
*-monoʳ-≤ m (suc p) (suc q) p≤q -- m * suc p ≤ m * suc q
rewrite
*-comm m (suc p) -- m + p * m ≤ m * suc q
| *-comm m (suc q) -- m + p * m ≤ m + q * m
| *-comm p m -- m + m * p ≤ m + q * m
| *-comm q m -- m + m * p ≤ m + m * q
= +-monoʳ-≤ m (m * p) (m * q) (*-monoʳ-≤ m p q (inv-s≤s p≤q))
-- inequality multiplied on left
*-monoˡ-≤ : ∀ (p q m : ℕ)
→ p ≤ q
-------------
→ p * m ≤ q * m
*-monoˡ-≤ p q m p≤q -- p * m ≤ q * m
rewrite
*-comm p m -- m * p ≤ q * m
| *-comm q m -- m * p ≤ m * q
= *-monoʳ-≤ m p q p≤q
*-mono-≤ : ∀ (m n p q : ℕ)
→ m ≤ n
→ p ≤ q
-------------
→ m * p ≤ n * q
*-mono-≤ m n p q m≤n p≤q = ≤-trans (*-monoʳ-≤ m p q p≤q ) (*-monoˡ-≤ m n q m≤n)
------------------------------------------------------------------------------
-- strict inequality : <
infix 4 _<_
data _<_ : ℕ → ℕ → Set where
z<s : ∀ {n : ℕ}
------------
→ zero < suc n
s<s : ∀ {m n : ℕ}
→ m < n
-------------
→ suc m < suc n
<-trans : ∀ {m n p : ℕ}
→ m < n
→ n < p
-------
→ m < p
<-trans z<s (s<s y) = z<s
<-trans (s<s x) (s<s y) = s<s (<-trans x y)
------------------------------------------------------------------------------
data Trichotomy (m n : ℕ) : Set where
is-< : m < n → Trichotomy m n
is-≡ : m ≡ n → Trichotomy m n
is-> : n < m → Trichotomy m n
suc-injective : ∀ {m n : ℕ} → suc m ≡ suc n → m ≡ n
suc-injective refl = refl
m≡n→sucm≡sucn : ∀ (m n : ℕ) → m ≡ n → suc m ≡ suc n
m≡n→sucm≡sucn zero zero p = refl
m≡n→sucm≡sucn zero (suc n) ()
m≡n→sucm≡sucn (suc m) zero ()
m≡n→sucm≡sucn (suc m) (suc n) p = cong suc (m≡n→sucm≡sucn m n (suc-injective p))
<-trichotomy : ∀ (m n : ℕ) → Trichotomy m n
<-trichotomy zero zero = is-≡ refl
<-trichotomy zero (suc n) = is-< z<s
<-trichotomy (suc m) zero = is-> z<s
<-trichotomy (suc m) (suc n) with <-trichotomy m n
... | is-< m<n = is-< (s<s m<n)
... | is-≡ m≡n = is-≡ (m≡n→sucm≡sucn m n m≡n)
... | is-> n<m = is-> (s<s n<m)
------------------------------------------------------------------------------
-- monotonicity of + with respect to <
-- all I did was copy the +-monoʳ-≤ proof and replace ≤ with < - it worked
-- inequality added on right
+-monoʳ-< : ∀ (m p q : ℕ)
→ p < q
-------------
→ m + p < m + q
+-monoʳ-< zero p q p<q = p<q
+-monoʳ-< (suc m) p q p<q
= s<s (+-monoʳ-< m p q p<q)
-- inequality added on left
+-monoˡ-< : ∀ (p q m : ℕ)
→ p < q
-------------
→ p + m < q + m
+-monoˡ-< p q m p<q
rewrite
+-comm p m
| +-comm q m
= +-monoʳ-< m p q p<q
-- combine above
+-mono-< : ∀ (m n p q : ℕ)
→ m < n
→ p < q
-------------
→ m + p < n + q
+-mono-< m n p q m<n p<q = <-trans (+-monoʳ-< m p q p<q ) (+-monoˡ-< m n q m<n)
------------------------------------------------------------------------------
-- Proofs showing relation between strict inequality and inequality.
-- (Do the proofs in the order below, to avoid induction for two of the four proofs.)
--------------------------------------------------
-- turn ≤ into <
≤-<-to : ∀ {m n : ℕ}
→ m ≤ n
→ m < suc n
≤-<-to {zero} {zero} z≤n = z<s
≤-<-to {zero} {suc n} z≤n = z<s
≤-<-to {suc m} {suc n} (s≤s m≤n) = s<s (≤-<-to m≤n)
--- removing unneeded stuff
≤-<-to' : ∀ {m n : ℕ}
→ m ≤ n
→ m < suc n
≤-<-to' z≤n = z<s
≤-<-to' (s≤s m≤n) = s<s (≤-<-to' m≤n)
≤-<--to′ : ∀ {m n : ℕ}
→ suc m ≤ n
→ m < n
≤-<--to′ (s≤s sm≤n) = ≤-<-to sm≤n
--------------------------------------------------
-- turn < into ≤
≤-<-from : ∀ {m n : ℕ}
→ m < n
→ suc m ≤ n
≤-<-from z<s = s≤s z≤n
≤-<-from (s<s m<n) = s≤s (≤-<-from m<n)
≤-<-from′ : ∀ {m n : ℕ}
→ m < suc n
→ m ≤ n
≤-<-from′ z<s = z≤n
≤-<-from′ (s<s m<sn) = ≤-<-from m<sn
------------------------------------------------------------------------------
-- use the above to give a proof of <-trans that uses ≤-trans
m<n→m<sucn : ∀ {m n : ℕ} → m < n → m < suc n
m<n→m<sucn z<s = z<s
m<n→m<sucn (s<s m<n) = s<s (m<n→m<sucn m<n)
<-trans' : ∀ {m n p : ℕ}
→ m < n
→ n < p
-------
→ m < p
<-trans' m<n n<p = ≤-<--to′ (≤-trans (≤-<-from m<n) ( ≤-<-from′ (m<n→m<sucn n<p)))
------------------------------------------------------------------------------
-- Mutually recursive datatypes. Specify types first, then definitions.
data even : ℕ → Set
data odd : ℕ → Set
-- HC : added 'E' suffix to constructors
data even where
zeroE :
---------
even zero
sucE : ∀ {n : ℕ}
→ odd n
------------
→ even (suc n)
-- HC : added 'O' suffix to constructor
data odd where
sucO : ∀ {n : ℕ}
→ even n
-----------
→ odd (suc n)
-------------------------
-- Mutually recursive proofs. Specify types first, then implementations.
e+e≡e : ∀ {m n : ℕ}
→ even m
→ even n
------------
→ even (m + n)
o+e≡o : ∀ {m n : ℕ}
→ odd m
→ even n
-----------
→ odd (m + n)
e+e≡e zeroE en = en
e+e≡e (sucE x) en = sucE (o+e≡o x en)
o+e≡o (sucO x) en = sucO (e+e≡e x en)
-------------------------
o+o≡e : ∀ {m n : ℕ}
→ odd m
→ odd n
--------------
→ even (m + n)
e+o≡o : ∀ {m n : ℕ}
→ even m
→ odd n
-----------
→ odd (m + n)
e+o≡o zeroE on = on
e+o≡o (sucE m) (sucO n) = sucO (o+o≡e m (sucO n))
o+o≡e (sucO m) on = sucE (e+o≡o m on)
| {
"alphanum_fraction": 0.3789341572,
"avg_line_length": 24.1445221445,
"ext": "agda",
"hexsha": "ee558d98e3415e01ff115e636b5f9b7b38303468",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x03-842Relations-hc-2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x03-842Relations-hc-2.agda",
"max_line_length": 85,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/book/Programming_Language_Foundations_in_Agda/x03-842Relations-hc-2.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 4246,
"size": 10358
} |
-- Andreas, 2012-04-03, reported by pumpkingod
module Issue596 where
import Common.Irrelevance
open import Common.Level
open import Common.Equality
open import Common.Prelude renaming (Nat to ℕ)
infixl 7 _*_
_*_ : ℕ → ℕ → ℕ
zero * n = zero
suc m * n = n + (m * n)
-- inlined from Data.Product
record Σ {a b} (A : Set a) (B : A → Set b) : Set (a ⊔ b) where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
open Σ public
syntax Σ A (λ x → B) = Σ[ x ∶ A ] B
∃ : ∀ {a b} {A : Set a} → (A → Set b) → Set (a ⊔ b)
∃ = Σ _
infixr 2 _×_
_×_ : ∀ {a b} (A : Set a) (B : Set b) → Set (a ⊔ b)
A × B = Σ[ x ∶ A ] B
-- inlined from Data.Nat.Divisibility and Data.Nat.Coprimality
infix 4 _∣_
data _∣_ : ℕ → ℕ → Set where
divides : {m n : ℕ} (q : ℕ) (eq : n ≡ q * m) → m ∣ n
Coprime : (m n : ℕ) → Set
Coprime m n = ∀ {i} → i ∣ m × i ∣ n → i ≡ 1
record ℚ⁺ : Set where
constructor rat⁺
field
numerator : ℕ
denominator-1 : ℕ
denominator : ℕ
denominator = suc denominator-1
field
.coprime : Coprime numerator denominator
-- inlined from Data.Nat.LCM
record LCM (i j lcm : ℕ) : Set where
constructor is -- Andreas, 2012-04-02 added constructor
field
-- The lcm is a common multiple.
commonMultiple : i ∣ lcm × j ∣ lcm
-- The lcm divides all common multiples, i.e. the lcm is the least
-- common multiple according to the partial order _∣_.
least : ∀ {m} → i ∣ m × j ∣ m → lcm ∣ m
postulate
lcm : (i j : ℕ) → ∃ λ d → LCM i j d
undefined : ∀ {a}{A : Set a} → A
0#⁺ : ℚ⁺
0#⁺ = rat⁺ 0 0 undefined -- (∣1⇒≡1 ∘ proj₂)
_+⁺_ : ℚ⁺ → ℚ⁺ → ℚ⁺
_+⁺_ = undefined
-- the offending with-clause
+⁺-idˡ : ∀ q → 0#⁺ +⁺ q ≡ q
+⁺-idˡ (rat⁺ n d c) with lcm (suc zero) (suc d)
... | q = undefined
-- should succeed
| {
"alphanum_fraction": 0.569023569,
"avg_line_length": 21.2142857143,
"ext": "agda",
"hexsha": "3ed1dc2ce7fd7dca216e6a70552ee2ab6bb22640",
"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/Issue596.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/Issue596.agda",
"max_line_length": 70,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/succeed/Issue596.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": 725,
"size": 1782
} |
module Structure.Categorical.Properties where
import Functional.Dependent as Fn
open import Lang.Instance
import Lvl
open import Logic
open import Logic.Predicate
open import Logic.Propositional
open import Structure.Setoid
import Structure.Categorical.Names as Names
import Structure.Operator.Names as Names
import Structure.Relator.Names as Names
open import Structure.Relator.Properties
open import Syntax.Function
open import Type
open import Type.Properties.Singleton
private variable ℓₒ ℓₘ ℓₑ : Lvl.Level
private variable Obj : Type{ℓₒ}
module Object where
module _ (Morphism : Obj → Obj → Type{ℓₘ}) where
open Names.ArrowNotation(Morphism)
module _ ⦃ morphism-equiv : ∀{x y} → Equiv{ℓₑ}(x ⟶ y) ⦄ where
-- An initial object is an object in which there is an unique morphism from it to every object.
Initial : Obj → Stmt
Initial(x) = (∀{y} → IsUnit(x ⟶ y))
-- An terminal object is an object in which there is an unique morphism to it from every object.
Terminal : Obj → Stmt
Terminal(y) = (∀{x} → IsUnit(x ⟶ y))
module Morphism where
module _ {Morphism : Obj → Obj → Type{ℓₘ}} ⦃ equiv-morphism : ∀{x y} → Equiv{ℓₑ}(Morphism x y) ⦄ where
open Names.ArrowNotation(Morphism)
module OperModule (_▫_ : Names.SwappedTransitivity(_⟶_)) where
record Associativity : Stmt{Lvl.of(Obj) Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ} where
constructor intro
field proof : Names.Morphism.Associativity{Morphism = Morphism}(_▫_)
associativity = inst-fn Associativity.proof
module _ {x : Obj} (f : x ⟶ x) where
record Idempotent : Stmt{Lvl.of(Obj) Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ} where
constructor intro
field proof : Names.Morphism.Idempotent{Morphism = Morphism}(_▫_)(f)
idempotent = inst-fn Idempotent.proof
module IdModule (id : Names.Reflexivity(_⟶_)) where
record Identityₗ : Stmt{Lvl.of(Obj) Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ} where
constructor intro
field proof : Names.Morphism.Identityₗ(_▫_)(\{a} → id{a})
identityₗ = inst-fn Identityₗ.proof
record Identityᵣ : Stmt{Lvl.of(Obj) Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ} where
constructor intro
field proof : Names.Morphism.Identityᵣ(_▫_)(\{a} → id{a})
identityᵣ = inst-fn Identityᵣ.proof
Identity = Identityₗ ∧ Identityᵣ
identity-left = inst-fn{X = Identity}(Identityₗ.proof Fn.∘ [∧]-elimₗ{Q = Identityᵣ})
identity-right = inst-fn{X = Identity}(Identityᵣ.proof Fn.∘ [∧]-elimᵣ{P = Identityₗ})
module _ {x : Obj} (f : x ⟶ x) where
record Involution : Stmt{Lvl.of(Obj) Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ} where
constructor intro
field proof : Names.Morphism.Involution{Morphism = Morphism}(_▫_)(id)(f)
involution = inst-fn Involution.proof
module _ {x y : Obj} (f : x ⟶ y) where
module _ (f⁻¹ : y ⟶ x) where
-- A morphism have a right inverse morphism.
-- Also called: Split monomorphism, retraction
record Inverseₗ : Stmt{ℓₘ Lvl.⊔ ℓₑ} where
constructor intro
field proof : Names.Morphism.Inverseₗ(_▫_)(\{a} → id{a})(f)(f⁻¹)
inverseₗ = inst-fn Inverseₗ.proof
-- A morphism have a right inverse morphism.
-- Also called: Split epimorphism, section
record Inverseᵣ : Stmt{ℓₘ Lvl.⊔ ℓₑ} where
constructor intro
field proof : Names.Morphism.Inverseᵣ(_▫_)(\{a} → id{a})(f)(f⁻¹)
inverseᵣ = inst-fn Inverseᵣ.proof
Inverse = Inverseₗ ∧ Inverseᵣ
module Inverse(inverse : Inverse) where
instance
left : Inverseₗ
left = [∧]-elimₗ inverse
instance
right : Inverseᵣ
right = [∧]-elimᵣ inverse
Invertibleₗ = ∃(Inverseₗ)
Invertibleᵣ = ∃(Inverseᵣ)
-- A morphism is an isomorphism when it is invertible with respect to the operator.
-- For the set and functions category, it means that f is bijective.
Isomorphism : Stmt
Isomorphism = ∃(Inverse)
module Isomorphism ⦃ iso : Isomorphism ⦄ where
instance inverse = [∃]-proof iso
instance inverse-left = [∧]-elimₗ inverse
instance inverse-right = [∧]-elimᵣ inverse
inv : ⦃ Isomorphism ⦄ → (y ⟶ x)
inv ⦃ p ⦄ = [∃]-witness p
-- Proposition stating that two objects are isomorphic.
Isomorphic : Obj → Obj → Stmt
Isomorphic(x)(y) = ∃(Isomorphism{x}{y})
_⤖_ = Isomorphic
module _ {x : Obj} (f : ⟲ x) where
-- A morphism is an automorphism when it is an endomorphism and an isomorphism.
Automorphism : Stmt
Automorphism = Isomorphism(f)
Automorphic : Obj → Stmt
Automorphic(x) = ∃(Automorphism{x})
module _ {x y : Obj} (f : x ⟶ y) where
-- A morphism is an monomorphism when it is left-cancellable ("injective").
-- ∀{z}{g₁ g₂ : z ⟶ x} → (f ∘ g₁ ≡ f ∘ g₂) → (g₁ ≡ g₂)
record Monomorphism : Stmt{Lvl.of(Obj) Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ} where
constructor intro
field
proof : ∀{z} → Names.CancellationOnₗ {T₂ = z ⟶ x} (_▫_) (f)
cancellationₗ = inst-fn Monomorphism.proof
-- A morphism is an epimorphism when it is right-cancellable ("surjective").
-- ∀{z}{g₁ g₂ : y ⟶ z} → (g₁ ∘ f ≡ g₂ ∘ f) → (g₁ ≡ g₂)
record Epimorphism : Stmt{Lvl.of(Obj) Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ} where
constructor intro
field
proof : ∀{z} → Names.CancellationOnᵣ {T₁ = y ⟶ z} (_▫_) (f)
cancellationᵣ = inst-fn Epimorphism.proof
-- Proposition stating that two objects are monomorphic.
Monomorphic : Obj → Obj → Stmt
Monomorphic(x)(y) = ∃(Monomorphism{x}{y})
_↣_ = Monomorphic
-- Proposition stating that two objects are epimorphic.
Epimorphic : Obj → Obj → Stmt
Epimorphic(x)(y) = ∃(Epimorphism{x}{y})
_↠_ = Epimorphic
open OperModule public
open IdModule public
module Polymorphism where
module _ {Morphism : Obj → Obj → Type{ℓₘ}} ⦃ equiv-morphism : ∀{x y} → Equiv{ℓₑ}(Morphism x y) ⦄ where
open Names.ArrowNotation(Morphism)
module OperModule (_▫_ : Names.SwappedTransitivity(_⟶_)) where
module _ (x y : Obj) (f : ∀{x y} → (x ⟶ y)) where
record IdempotentOn : Stmt{Lvl.of(Obj) Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ} where
constructor intro
field proof : Names.Polymorphism.IdempotentOn{Morphism = Morphism}(_▫_)(x)(y)(f)
idempotent-on = inst-fn IdempotentOn.proof
module IdModule (id : Names.Reflexivity(_⟶_)) where
module _ (x y : Obj) (f : ∀{x y} → (x ⟶ y)) where
record InvolutionOn : Stmt{Lvl.of(Obj) Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ} where
constructor intro
field proof : Names.Polymorphism.InvolutionOn{Morphism = Morphism}(_▫_)(id) (x)(y) (f)
involution-on = inst-fn InvolutionOn.proof
module _ (f : ∀{x y} → (x ⟶ y)) where
record Involution : Stmt{Lvl.of(Obj) Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ} where
constructor intro
field proof : Names.Polymorphism.Involution{Morphism = Morphism}(_▫_)(id)(f)
involution = inst-fn Involution.proof
module _ (inv : ∀{x y : Obj} → (x ⟶ y) → (y ⟶ x)) where
-- A morphism have a right inverse morphism.
-- Also called: Split monomorphism, retraction
record Inverterₗ : Stmt{Lvl.of(Obj) Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ} where
constructor intro
field proof : ∀{x y : Obj}{f : x ⟶ y} → Names.Morphism.Inverseₗ(_▫_)(\{a} → id{a})(f)(inv f)
instance
inverseₗ : ∀{x y : Obj}{f : x ⟶ y} → Morphism.Inverseₗ(_▫_)(\{x} → id{x})(f)(inv f)
inverseₗ = Morphism.intro proof
inverterₗ = inst-fn Inverterₗ.proof
-- A morphism have a right inverse morphism.
-- Also called: Split epimorphism, section
record Inverterᵣ : Stmt{Lvl.of(Obj) Lvl.⊔ ℓₘ Lvl.⊔ ℓₑ} where
constructor intro
field proof : ∀{x y : Obj}{f : x ⟶ y} → Names.Morphism.Inverseᵣ(_▫_)(\{a} → id{a})(f)(inv f)
instance
inverseᵣ : ∀{x y : Obj}{f : x ⟶ y} → Morphism.Inverseᵣ(_▫_)(\{x} → id{x})(f)(inv f)
inverseᵣ = Morphism.intro proof
inverterᵣ = inst-fn Inverterᵣ.proof
Inverter = Inverterₗ ∧ Inverterᵣ
module Inverter(inverter : Inverter) where
instance
left : Inverterₗ
left = [∧]-elimₗ inverter
open Inverterₗ(left) public
instance
right : Inverterᵣ
right = [∧]-elimᵣ inverter
open Inverterᵣ(right) public
module _ {x y : Obj} {f : x ⟶ y} where
instance
inverse : Morphism.Inverse(_▫_)(\{x} → id{x})(f)(inv f)
inverse = [∧]-intro inverseₗ inverseᵣ
open Morphism.Inverse(_▫_)(\{x} → id{x})(f)(inv f)(inverse) renaming (left to inverseₗ ; right to inverseᵣ)
invertibleₗ : ∀{x y : Obj}{f : x ⟶ y} → Morphism.Invertibleₗ(_▫_)(\{x} → id{x})(f)
invertibleₗ {f = f} = [∃]-intro (inv f) ⦃ inverseₗ ⦄
invertibleᵣ : ∀{x y : Obj}{f : x ⟶ y} → Morphism.Invertibleᵣ(_▫_)(\{x} → id{x})(f)
invertibleᵣ {f = f} = [∃]-intro (inv f) ⦃ inverseᵣ ⦄
isomorphism : ∀{x y : Obj}{f : x ⟶ y} → Morphism.Isomorphism(_▫_)(\{x} → id{x})(f)
isomorphism {f = f} = [∃]-intro (inv f) ⦃ inverse ⦄
open OperModule public
open IdModule public
| {
"alphanum_fraction": 0.5807520978,
"avg_line_length": 41.9695652174,
"ext": "agda",
"hexsha": "44c769e539caebb422bb890de5f5df2fc39fbcb9",
"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/Categorical/Properties.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/Categorical/Properties.agda",
"max_line_length": 121,
"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/Categorical/Properties.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": 3228,
"size": 9653
} |
open import Relation.Unary
open import Relation.Ternary.Separation
module Relation.Ternary.Separation.Monad.Error {ℓ} {A : Set ℓ}
{{r : RawSep A}}
{u} {{_ : IsUnitalSep r u}}
where
open import Level
open import Function
open import Data.Unit
open import Data.Sum
open import Relation.Unary renaming (U to True)
open import Relation.Unary.PredicateTransformer using (PT; Pt)
open import Relation.Ternary.Separation.Morphisms
open import Relation.Ternary.Separation.Monad
open import Relation.Binary.PropositionalEquality
module _ where
record ExceptT (M : Pt A ℓ) (E : Set ℓ) (P : Pred A ℓ) (Φ : A) : Set ℓ where
constructor partial
field
runErr : M ((λ _ → E) ∪ P) Φ
open ExceptT public
open import Relation.Ternary.Separation.Monad.Identity
Except : ∀ E → Pt A ℓ
Except E = ExceptT Identity.Id E
pattern error e = partial (inj₁ e)
pattern ✓ x = partial (inj₂ x)
data Err : Set ℓ where
err : Err
ErrorT : (M : Pt A ℓ) {{monad : Monads.Monad ⊤ ℓ (λ _ _ → M) }} → Pt A ℓ
ErrorT M = ExceptT M Err
open import Relation.Ternary.Separation.Monad.Identity
Error : Pt A ℓ
Error = ErrorT Identity.Id
module ExceptTrans
(M : Pt A ℓ)
{{monad : Monads.Monad ⊤ ℓ (λ _ _ → M) }}
(Exc : Set ℓ) where
open Monads
instance
except-monad : Monad ⊤ ℓ (λ _ _ → ExceptT M Exc)
runErr (Monad.return except-monad px) =
return (inj₂ px)
runErr (app (Monad.bind except-monad f) (partial mpx) σ) = do
inj₂ px ×⟨ σ₂ ⟩ f ← mpx &⟨ _ ─✴ _ ∥ ⊎-comm σ ⟩ f
where
(inj₁ e ×⟨ σ₂ ⟩ f) → return (inj₁ e)
case app f px (⊎-comm σ₂) of λ where
(partial z) → z
mapExc : ∀ {E₁ E₂ P} → (E₁ → E₂) → ∀[ ExceptT M E₁ P ⇒ ExceptT M E₂ P ]
mapExc f (partial mc) = partial (mapM mc λ where (inj₁ e) → inj₁ (f e); (inj₂ px) → inj₂ px)
module ExceptMonad (Exc : Set ℓ) where
open import Relation.Ternary.Separation.Monad.Identity
open ExceptTrans Identity.Id {{ Identity.id-monad }} Exc public
module ErrorTrans (M : Pt A ℓ) {{monad : Monads.Monad ⊤ ℓ (λ _ _ → M) }} where
open import Relation.Ternary.Separation.Monad.Identity
open ExceptTrans M {{ monad }} Err public
renaming (except-monad to error-monad)
module ErrorMonad where
open import Relation.Ternary.Separation.Monad.Identity
open ExceptTrans Identity.Id {{ Identity.id-monad }} Err public
renaming (except-monad to error-monad)
| {
"alphanum_fraction": 0.6661115737,
"avg_line_length": 30.025,
"ext": "agda",
"hexsha": "218120a2971a2d4a006d7a209263a4ce30e10c0c",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z",
"max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/linear.agda",
"max_forks_repo_path": "src/Relation/Ternary/Separation/Monad/Error.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "laMudri/linear.agda",
"max_issues_repo_path": "src/Relation/Ternary/Separation/Monad/Error.agda",
"max_line_length": 94,
"max_stars_count": 34,
"max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/linear.agda",
"max_stars_repo_path": "src/Relation/Ternary/Separation/Monad/Error.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z",
"num_tokens": 791,
"size": 2402
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
{-
This is inspired by/copied from:
https://github.com/agda/agda-stdlib/blob/master/src/Tactic/MonoidSolver.agda
-}
module Cubical.Algebra.RingSolver.ReflectionSolving where
open import Cubical.Foundations.Prelude hiding (Type)
open import Cubical.Functions.Logic
open import Agda.Builtin.Reflection hiding (Type)
open import Agda.Builtin.String
open import Cubical.Reflection.Base
open import Cubical.Data.Maybe
open import Cubical.Data.Sigma
open import Cubical.Data.List
open import Cubical.Data.Nat.Literals public
open import Cubical.Data.Int using (fromNegInt; fromNatInt) public
open import Cubical.Data.Nat using (ℕ) renaming (_+_ to _+ℕ_)
open import Cubical.Data.FinData using () renaming (zero to fzero; suc to fsuc) public
open import Cubical.Data.Bool
open import Cubical.Data.Bool.SwitchStatement
open import Cubical.Data.Vec using (Vec) renaming ([] to emptyVec; _∷_ to _∷vec_) public
open import Cubical.Algebra.RingSolver.AlgebraExpression public
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.RingSolver.RawAlgebra
open import Cubical.Algebra.RingSolver.IntAsRawRing
open import Cubical.Algebra.RingSolver.CommRingSolver renaming (solve to ringSolve)
private
variable
ℓ : Level
_==_ = primQNameEquality
{-# INLINE _==_ #-}
record VarInfo : Type ℓ-zero where
field
varName : String
varType : Arg Term
index : ℕ
getArgs : Term → Maybe (Term × Term)
getArgs (def n xs) =
if n == (quote PathP)
then go xs
else nothing
where
go : List (Arg Term) → Maybe (Term × Term)
go (varg x ∷ varg y ∷ []) = just (x , y)
go (x ∷ xs) = go xs
go _ = nothing
getArgs _ = nothing
constructSolution : ℕ → List VarInfo → Term → Term → Term → Term
constructSolution n varInfos R lhs rhs =
encloseWithIteratedLambda (map VarInfo.varName varInfos) solverCall
where
encloseWithIteratedLambda : List String → Term → Term
encloseWithIteratedLambda (varName ∷ xs) t = lam visible (abs varName (encloseWithIteratedLambda xs t))
encloseWithIteratedLambda [] t = t
variableList : List VarInfo → Arg Term
variableList [] = varg (con (quote emptyVec) [])
variableList (varInfo ∷ varInfos)
= varg (con (quote _∷vec_) (varg (var (VarInfo.index varInfo) []) ∷ (variableList varInfos) ∷ []))
solverCall = def
(quote ringSolve)
(varg R ∷ varg lhs ∷ varg rhs
∷ variableList (rev varInfos)
∷ varg (def (quote refl) []) ∷ [])
module pr (R : CommRing {ℓ}) {n : ℕ} where
private
νR = CommRing→RawℤAlgebra R
open CommRingStr (snd R)
0' : Expr ℤAsRawRing (fst R) n
0' = K 0
1' : Expr ℤAsRawRing (fst R) n
1' = K 1
module _ (cring : Term) where
private
νR = def (quote CommRing→RawℤAlgebra) (varg cring ∷ [])
open pr
mutual
`0` : List (Arg Term) → Term
`0` [] = def (quote 0') (varg cring ∷ [])
`0` (varg fstcring ∷ xs) = `0` xs
`0` (harg _ ∷ xs) = `0` xs
`0` _ = unknown
`1` : List (Arg Term) → Term
`1` [] = def (quote 1') (varg cring ∷ [])
`1` (varg fstcring ∷ xs) = `1` xs
`1` (harg _ ∷ xs) = `1` xs
`1` _ = unknown
`_·_` : List (Arg Term) → Term
`_·_` (harg _ ∷ xs) = `_·_` xs
`_·_` (varg _ ∷ varg x ∷ varg y ∷ []) =
con
(quote _·'_) (varg (buildExpression x) ∷ varg (buildExpression y) ∷ [])
`_·_` _ = unknown
`_+_` : List (Arg Term) → Term
`_+_` (harg _ ∷ xs) = `_+_` xs
`_+_` (varg _ ∷ varg x ∷ varg y ∷ []) =
con
(quote _+'_) (varg (buildExpression x) ∷ varg (buildExpression y) ∷ [])
`_+_` _ = unknown
`-_` : List (Arg Term) → Term
`-_` (harg _ ∷ xs) = `-_` xs
`-_` (varg _ ∷ varg x ∷ []) =
con
(quote -'_) (varg (buildExpression x) ∷ [])
`-_` _ = unknown
K' : List (Arg Term) → Term
K' xs = con (quote K) xs
finiteNumberAsTerm : ℕ → Term
finiteNumberAsTerm ℕ.zero = con (quote fzero) []
finiteNumberAsTerm (ℕ.suc n) = con (quote fsuc) (varg (finiteNumberAsTerm n) ∷ [])
buildExpression : Term → Term
buildExpression (var index _) = con (quote ∣) (varg (finiteNumberAsTerm index) ∷ [])
buildExpression t@(def n xs) =
switch (n ==_) cases
case (quote CommRingStr.0r) ⇒ `0` xs break
case (quote CommRingStr.1r) ⇒ `1` xs break
case (quote CommRingStr._·_) ⇒ `_·_` xs break
case (quote CommRingStr._+_) ⇒ `_+_` xs break
case (quote (CommRingStr.-_)) ⇒ `-_` xs break
default⇒ (K' xs)
buildExpression t@(con n xs) =
switch (n ==_) cases
case (quote CommRingStr.0r) ⇒ `0` xs break
case (quote CommRingStr.1r) ⇒ `1` xs break
case (quote CommRingStr._·_) ⇒ `_·_` xs break
case (quote CommRingStr._+_) ⇒ `_+_` xs break
case (quote (CommRingStr.-_)) ⇒ `-_` xs break
default⇒ (K' xs)
buildExpression t = unknown
toAlgebraExpression : Maybe (Term × Term) → Maybe (Term × Term)
toAlgebraExpression nothing = nothing
toAlgebraExpression (just (lhs , rhs)) = just (buildExpression lhs , buildExpression rhs)
private
adjustDeBruijnIndex : (n : ℕ) → Term → Term
adjustDeBruijnIndex n (var k args) = var (k +ℕ n) args
adjustDeBruijnIndex n _ = unknown
getVarsAndEquation : Term → Maybe (List VarInfo × Term)
getVarsAndEquation t =
let
(rawVars , equationTerm) = extractVars t
maybeVars = addIndices (length rawVars) rawVars
in map-Maybe (_, equationTerm) maybeVars
where
extractVars : Term → List (String × Arg Term) × Term
extractVars (pi argType (abs varName t)) with extractVars t
... | xs , equation = (varName , argType) ∷ xs , equation
extractVars equation = [] , equation
addIndices : ℕ → List (String × Arg Term) → Maybe (List VarInfo)
addIndices ℕ.zero [] = just []
addIndices (ℕ.suc countVar) ((varName , argType) ∷ list) =
map-Maybe (λ varList → record { varName = varName ; varType = argType ; index = countVar }
∷ varList)
(addIndices countVar list)
addIndices _ _ = nothing
solve-macro : Term → Term → TC Unit
solve-macro cring hole = do
hole′ ← inferType hole >>= normalise
just (varInfos , equation) ← returnTC (getVarsAndEquation hole′)
where
nothing
→ typeError (strErr "Something went wrong when getting the variable names in "
∷ termErr hole′ ∷ [])
adjustedCring ← returnTC (adjustDeBruijnIndex (length varInfos) cring)
just (lhs , rhs) ← returnTC (toAlgebraExpression adjustedCring (getArgs equation))
where
nothing
→ typeError(
strErr "Error while trying to buils ASTs for the equation " ∷
termErr equation ∷ [])
let solution = constructSolution (length varInfos) varInfos adjustedCring lhs rhs
unify hole solution
macro
solve : Term → Term → TC _
solve = solve-macro
fromℤ : (R : CommRing {ℓ}) → ℤ → fst R
fromℤ = scalar
| {
"alphanum_fraction": 0.6111494411,
"avg_line_length": 34.6746411483,
"ext": "agda",
"hexsha": "ee5155d756287c2ce3333538e5809490a2da578c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Algebra/RingSolver/ReflectionSolving.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Algebra/RingSolver/ReflectionSolving.agda",
"max_line_length": 109,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Algebra/RingSolver/ReflectionSolving.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2241,
"size": 7247
} |
{-# OPTIONS --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Introductions.Empty {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Introductions.Universe
open import Definition.LogicalRelation.Substitution.Introductions.Pi
open import Definition.LogicalRelation.Substitution.MaybeEmbed
open import Tools.Unit as TU
open import Tools.Product
import Tools.PropositionalEquality as PE
-- Validity of the Empty type.
Emptyᵛ : ∀ {Γ ll l} ([Γ] : ⊩ᵛ Γ) → Γ ⊩ᵛ⟨ l ⟩ Empty ll ^ [ % , ι ll ] / [Γ]
Emptyᵛ [Γ] ⊢Δ [σ] = Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ))) , λ _ x₂ → id (univ (Emptyⱼ ⊢Δ))
-- Validity of the Empty type as a term.
Emptyᵗᵛ : ∀ {Γ l ll} ([Γ] : ⊩ᵛ Γ) → (l< : ι ll <∞ l)
→ Γ ⊩ᵛ⟨ l ⟩ Empty ll ∷ Univ % ll ^ [ ! , next ll ] / [Γ] / Uᵛ l< [Γ]
Emptyᵗᵛ {ll = ll} [Γ] emb< ⊢Δ [σ] = let ⊢Empty = Emptyⱼ ⊢Δ
in Uₜ (Empty ll) (idRedTerm:*: ⊢Empty) Emptyₙ (≅ₜ-Emptyrefl ⊢Δ) (λ x ⊢Δ' → Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ'))))
, λ x x₁ → Uₜ₌ -- Empty Empty (idRedTerm:*: ⊢Empty) (idRedTerm:*: ⊢Empty) Emptyₙ Emptyₙ
(Uₜ (Empty ll) (idRedTerm:*: ⊢Empty) Emptyₙ (≅ₜ-Emptyrefl ⊢Δ) (λ x₂ ⊢Δ' → Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ')))))
(Uₜ (Empty ll) (idRedTerm:*: ⊢Empty) Emptyₙ (≅ₜ-Emptyrefl ⊢Δ) (λ x₂ ⊢Δ' → Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ')))))
(≅ₜ-Emptyrefl ⊢Δ) λ [ρ] ⊢Δ' → id (univ (Emptyⱼ ⊢Δ'))
Emptyᵗᵛ {ll = ll} [Γ] ∞< ⊢Δ [σ] = let ⊢Empty = Emptyⱼ ⊢Δ
in Uₜ (Empty ll) (idRedTerm:*: ⊢Empty) Emptyₙ (≅ₜ-Emptyrefl ⊢Δ) (λ x ⊢Δ' → Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ'))))
, λ x x₁ → Uₜ₌ -- Empty Empty (idRedTerm:*: ⊢Empty) (idRedTerm:*: ⊢Empty) Emptyₙ Emptyₙ
(Uₜ (Empty ll) (idRedTerm:*: ⊢Empty) Emptyₙ (≅ₜ-Emptyrefl ⊢Δ) (λ x₂ ⊢Δ' → Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ')))))
(Uₜ (Empty ll) (idRedTerm:*: ⊢Empty) Emptyₙ (≅ₜ-Emptyrefl ⊢Δ) (λ x₂ ⊢Δ' → Emptyᵣ (idRed:*: (univ (Emptyⱼ ⊢Δ')))))
(≅ₜ-Emptyrefl ⊢Δ) λ [ρ] ⊢Δ' → id (univ (Emptyⱼ ⊢Δ'))
Unitᵗᵛ : ∀ {Γ l} ([Γ] : ⊩ᵛ Γ) → Γ ⊩ᵛ⟨ ∞ ⟩ Unit ∷ (SProp l) ^ [ ! , next l ] / [Γ] / maybeEmbᵛ {A = SProp l} [Γ] (Uᵛ (proj₂ (levelBounded _)) [Γ])
Unitᵗᵛ {Γ} {l} [Γ] = let [SProp] = maybeEmbᵛ {A = SProp l} [Γ] (Uᵛ {rU = %} (proj₂ (levelBounded _)) [Γ])
[Empty] = Emptyᵛ {ll = l} {l = ∞} [Γ]
[Γ∙Empty] = (_∙_ {Γ} {Empty l} [Γ] [Empty])
[SProp]₁ : Γ ∙ Empty l ^ [ % , ι l ] ⊩ᵛ⟨ ∞ ⟩ (SProp l) ^ [ ! , next l ] / [Γ∙Empty]
[SProp]₁ {Δ} {σ} = maybeEmbᵛ {A = SProp l} [Γ∙Empty] (λ {Δ} {σ} → Uᵛ (proj₂ (levelBounded _)) [Γ∙Empty] {Δ} {σ}) {Δ} {σ}
[Empty]₁ = maybeEmbTermᵛ {A = SProp l} {t = Empty l} [Γ] (Uᵛ {rU = %} (proj₂ (levelBounded _)) [Γ]) (Emptyᵗᵛ {ll = l} [Γ] (proj₂ (levelBounded _)))
[Empty]₂ = maybeEmbTermᵛ {A = SProp l} {t = Empty l} [Γ∙Empty] (λ {Δ} {σ} → Uᵛ (proj₂ (levelBounded _)) [Γ∙Empty] {Δ} {σ}) (Emptyᵗᵛ {ll = l} [Γ∙Empty] (proj₂ (levelBounded _)))
in maybeEmbTermᵛ {A = SProp l} {t = Unit} [Γ] [SProp]
(Πᵗᵛ {Empty l} {Empty l} (≡is≤ PE.refl) (≡is≤ PE.refl) [Γ] ( Emptyᵛ {ll = l} [Γ]) (λ {Δ} {σ} → [SProp]₁ {Δ} {σ}) [Empty]₁ (λ {Δ} {σ} → [Empty]₂ {Δ} {σ}))
Unit≡Unit : ∀ {Γ l} (⊢Γ : ⊢ Γ)
→ Γ ⊢ Unit {l} ≅ Unit {l} ∷ SProp l ^ [ ! , next l ]
Unit≡Unit ⊢Γ = ≅ₜ-Π-cong (≡is≤ PE.refl) (≡is≤ PE.refl) (univ (Emptyⱼ ⊢Γ)) (≅ₜ-Emptyrefl ⊢Γ) (≅ₜ-Emptyrefl (⊢Γ ∙ univ (Emptyⱼ ⊢Γ)))
Unitᵛ : ∀ {Γ l} ([Γ] : ⊩ᵛ Γ) → Γ ⊩ᵛ⟨ ι l ⟩ Unit ^ [ % , ι l ] / [Γ]
Unitᵛ {Γ} {l} [Γ] = univᵛ {A = Unit} [Γ] (≡is≤ PE.refl) (maybeEmbᵛ {A = SProp l} [Γ] (Uᵛ {rU = %} (proj₂ (levelBounded _)) [Γ])) (Unitᵗᵛ {l = l} [Γ])
UnitType : ∀ {Γ l} (⊢Γ : ⊢ Γ) → Γ ⊩⟨ ι l ⟩ Unit ^ [ % , ι l ]
UnitType {Γ} ⊢Γ = proj₁ (Unitᵛ ε {Γ} {idSubst} ⊢Γ TU.tt)
EmptyType : ∀ {Γ l} (⊢Γ : ⊢ Γ) → Γ ⊩⟨ ι l ⟩ Empty l ^ [ % , ι l ]
EmptyType {Γ} ⊢Γ = proj₁ (Emptyᵛ ε {Γ} {idSubst} ⊢Γ TU.tt)
| {
"alphanum_fraction": 0.5138951143,
"avg_line_length": 65.6176470588,
"ext": "agda",
"hexsha": "612b509cb60fcc35c74b636c1fb27f722f64ed78",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Empty.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Empty.agda",
"max_line_length": 201,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Empty.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 2106,
"size": 4462
} |
-- Andreas, 2016-02-02 postpone type checking of extended lambda
-- See also issue 480 and 1159
open import Common.Maybe
open import Common.String
record ⊤ : Set where
record IOInterface : Set₁ where
field Command : Set
Response : (m : Command) → Set
open IOInterface
data IO I A : Set where
act' : (c : Command I) (f : Response I c → IO I A) → IO I A
return : (a : A) → IO I A
-- Alias of constructor which is a function
act : ∀{I A} (c : Command I) (f : Response I c → IO I A) → IO I A
act c f = act' c f
data C : Set where
getLine : C
putStrLn : String → C
R : C → Set
R getLine = Maybe String
R (putStrLn s) = ⊤
I : IOInterface
Command I = C
Response I = R
works : IO I ⊤
works = act' getLine λ{ nothing → return _ ; (just line) →
act (putStrLn line) λ _ →
return _ }
test : IO I ⊤
test = act getLine λ{ nothing → return _ ; (just line) →
act (putStrLn line) λ _ →
return _ }
-- Test with do-notation
_>>=_ : ∀ {A B} → IO I A → (A → IO I B) → IO I B
act' c f >>= k = act' c λ x → f x >>= k
return a >>= k = k a
_>>_ : ∀ {A B} → IO I A → IO I B → IO I B
m >> m' = m >>= λ _ → m'
getLineIO : IO I (Maybe String)
getLineIO = act' getLine return
putStrLnIO : String → IO I ⊤
putStrLnIO s = act' (putStrLn s) return
works' : IO I ⊤
works' = do
just line ← getLineIO where nothing → return _
putStrLnIO line
return _
| {
"alphanum_fraction": 0.5514950166,
"avg_line_length": 23.515625,
"ext": "agda",
"hexsha": "8054ea985e6fb688c9763320b6afc66cee2b8df3",
"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": "7220bebfe9f64297880ecec40314c0090018fdd0",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "asr/eagda",
"max_forks_repo_path": "test/Succeed/Issue1811.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0",
"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": "asr/eagda",
"max_issues_repo_path": "test/Succeed/Issue1811.agda",
"max_line_length": 67,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "asr/eagda",
"max_stars_repo_path": "test/Succeed/Issue1811.agda",
"max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z",
"num_tokens": 514,
"size": 1505
} |
open import Prelude
module Implicits.Semantics where
open import Implicits.Syntax
open import Implicits.WellTyped
open import Implicits.Semantics.Type public
open import Implicits.Semantics.Context public
open import Implicits.Semantics.RewriteContext public
open import Implicits.Semantics.Term public
open import Implicits.Semantics.Preservation public
open import SystemF.Everything as F using ()
module Semantics
(_⊢ᵣ_ : ∀ {ν} → ICtx ν → Type ν → Set)
(⟦_,_⟧r : ∀ {ν n} {K : Ktx ν n} {a} → (proj₂ K) ⊢ᵣ a → K# K →
∃ λ t → ⟦ proj₁ K ⟧ctx→ F.⊢ t ∈ ⟦ a ⟧tp→) where
open TypingRules _⊢ᵣ_
open TermSemantics _⊢ᵣ_ ⟦_,_⟧r public
open Preservation _⊢ᵣ_ ⟦_,_⟧r public
| {
"alphanum_fraction": 0.7173913043,
"avg_line_length": 30,
"ext": "agda",
"hexsha": "ae59a5cacb9dd989a42d69d6d7a40b9659182558",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Semantics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Semantics.agda",
"max_line_length": 63,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Semantics.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": 258,
"size": 690
} |
{- 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
-}
{-# OPTIONS --allow-unsolved-metas #-}
-- This module provides some scaffolding to define the handlers for our fake/simple "implementation"
-- and connect them to the interface of the SystemModel.
open import Optics.All
open import LibraBFT.Prelude
open import LibraBFT.Lemmas
open import LibraBFT.Base.ByteString
open import LibraBFT.Base.Encode
open import LibraBFT.Base.KVMap
open import LibraBFT.Base.PKCS
open import LibraBFT.Hash
open import LibraBFT.Impl.Base.Types
open import LibraBFT.Impl.Consensus.RoundManager.Properties
open import LibraBFT.Impl.Consensus.Types
open import LibraBFT.Impl.Util.Crypto
open import LibraBFT.Impl.Util.Util
open import LibraBFT.Concrete.System
open import LibraBFT.Concrete.System.Parameters
open EpochConfig
open import LibraBFT.Yasm.Types
open import LibraBFT.Yasm.Yasm ℓ-RoundManager ℓ-VSFP ConcSysParms PeerCanSignForPK (λ {st} {part} {pk} → PeerCanSignForPK-stable {st} {part} {pk})
module LibraBFT.Impl.Handle.Properties where
open import LibraBFT.Impl.Consensus.RoundManager
open import LibraBFT.Impl.Handle
-- This proof is complete except for pieces that are directly about the handlers. Our
-- fake/simple handler does not yet obey the needed properties, so we can't finish this yet.
impl-sps-avp : StepPeerState-AllValidParts
-- In our fake/simple implementation, init and handling V and C msgs do not send any messages
impl-sps-avp _ hpk (step-init _) m∈outs part⊂m ver = ⊥-elim (¬Any[] m∈outs)
impl-sps-avp _ hpk (step-msg {sndr , V vm} _ _) m∈outs _ _ = ⊥-elim (¬Any[] m∈outs)
impl-sps-avp _ hpk (step-msg {sndr , C cm} _ _) m∈outs _ _ = ⊥-elim (¬Any[] m∈outs)
-- These aren't true yet, because processProposalMsgM sends fake votes that don't follow the rules for ValidPartForPK
impl-sps-avp preach hpk (step-msg {sndr , P pm} m∈pool ps≡) m∈outs v⊂m ver ¬init
with m∈outs
-- Handler sends at most one vote, so it can't be "there"
...| there {xs = xs} imp = ⊥-elim (¬Any[] imp)
...| here refl
with v⊂m
...| vote∈qc vs∈qc rbld≈ qc∈m
with qc∈m
...| xxx = {!x!} -- We will prove that votes represented in the SyncInfo of a
-- proposal message were sent before, so these will be inj₂.
-- This will be based on an invariant of the implementation, for
-- example that the QCs included in the SyncInfo of a VoteMsg have
-- been sent before. We will need to use hash injectivity and
-- signature injectivity to ensure a different vote was not sent
-- previously with the same signature.
impl-sps-avp {pk = pk} {α = α} {st = st} preach hpk (step-msg {sndr , P pm} m∈pool ps≡) m∈outs v⊂m ver ¬init
| here refl
| vote∈vm {si}
with MsgWithSig∈? {pk} {ver-signature ver} {msgPool st}
...| yes msg∈ = inj₂ msg∈
...| no msg∉ = inj₁ ( mkPCS4PK {! !} {!!} (inGenInfo refl) {!!} {!!} {!!}
-- The implementation will need to provide evidence that the peer is a member of
-- the epoch of the message it's sending and that it is assigned pk for that epoch.
, msg∉)
open Structural impl-sps-avp
----- Properties that bridge the system model gap to the handler -----
msgsToSendWereSent1 : ∀ {pid ts pm vm} {st : RoundManager}
→ send (V vm) ∈ proj₂ (peerStep pid (P pm) ts st)
→ ∃[ αs ] (SendVote vm αs ∈ LBFT-outs (handle pid (P pm) ts) st)
msgsToSendWereSent1 {pid} {ts} {pm} {vm} {st} send∈acts
with send∈acts
-- The fake handler sends only to node 0 (fakeAuthor), so this doesn't
-- need to be very general yet.
-- TODO-1: generalize this proof so it will work when the set of recipients is
-- not hard coded.
-- The system model allows any message sent to be received by any peer (so the list of
-- recipients it essentially ignored), meaning that our safety proofs will be for a slightly
-- stronger model. Progress proofs will require knowledge of recipients, though, so we will
-- keep the implementation model faithful to the implementation.
...| here refl = fakeAuthor ∷ [] , here refl
-- This captures which kinds of messages are sent by handling which kind of message. It will
-- require additional disjuncts when we implement processVote.
msgsToSendWereSent : ∀ {pid nm m} {st : RoundManager}
→ send m ∈ proj₂ (peerStepWrapper pid nm st)
→ send m ∈ proj₂ (peerStep pid nm 0 st)
× ∃[ vm ] ∃[ pm ] (m ≡ V vm × nm ≡ P pm)
msgsToSendWereSent {pid} {nm = nm} {m} {st} m∈outs
with nm
...| C _ = ⊥-elim (¬Any[] m∈outs)
...| V _ = ⊥-elim (¬Any[] m∈outs)
...| P pm
with m∈outs
...| here v∈outs
with m
...| P _ = ⊥-elim (P≢V (action-send-injective v∈outs))
...| C _ = ⊥-elim (C≢V (action-send-injective v∈outs))
...| V vm rewrite sym v∈outs = here refl , vm , pm , refl , refl
proposalHandlerSentVote : ∀ {pid ts pm vm} {st : RoundManager}
→ send (V vm) ∈ proj₂ (peerStepWrapper pid (P pm) st)
→ ∃[ αs ] (SendVote vm αs ∈ LBFT-outs (handle pid (P pm) ts) st)
proposalHandlerSentVote {pid} {ts} {pm} {vm} {st} m∈outs
with msgsToSendWereSent {pid} {P pm} {st = st} m∈outs
...| send∈ , vm , pm' , refl , refl
with msgsToSendWereSent1 {pid} {ts} {pm'} {st = st} send∈
...| αs , sv = αs , sv
----- Properties that relate handler to system state -----
data _∈RoundManager_ (qc : QuorumCert) (rm : RoundManager) : Set where
inHQC : qc ≡ ₋rmHighestQC rm → qc ∈RoundManager rm
inHCC : qc ≡ ₋rmHighestCommitQC rm → qc ∈RoundManager rm
postulate -- TODO-2: this will be proved for the implementation, confirming that honest
-- participants only store QCs comprising votes that have actually been sent.
-- Votes stored in highesQuorumCert and highestCommitCert were sent before.
-- Note that some implementations might not ensure this, but LibraBFT does
-- because even the leader of the next round sends its own vote to itself,
-- as opposed to using it to construct a QC using its own unsent vote.
qcVotesSentB4 : ∀{pid qc vs pk}{st : SystemState}
→ ReachableSystemState st
→ initialised st pid ≡ initd
→ qc ∈RoundManager (peerStates st pid)
→ vs ∈ qcVotes qc
→ ¬ (∈GenInfo (proj₂ vs))
→ MsgWithSig∈ pk (proj₂ vs) (msgPool st)
-- We can prove this easily because we don't yet do epoch changes,
-- so only the initial EC is relevant. Later, this will require us to use the fact that
-- epoch changes require proof of committing an epoch-changing transaction.
availEpochsConsistent :
∀{pid pid' v v' pk}{st : SystemState}
→ ReachableSystemState st
→ (pkvpf : PeerCanSignForPK st v pid pk)
→ (pkvpf' : PeerCanSignForPK st v' pid' pk)
→ PeerCanSignForPK.𝓔 pkvpf ≡ PeerCanSignForPK.𝓔 pkvpf'
availEpochsConsistent r (mkPCS4PK _ _ (inGenInfo refl) _ _ _)
(mkPCS4PK _ _ (inGenInfo refl) _ _ _) = refl
-- Always true, so far, as no epoch changes.
noEpochIdChangeYet : ∀ {pre : SystemState}{pid}{ppre ppost msgs}
→ ReachableSystemState pre
→ ppre ≡ peerStates pre pid
→ StepPeerState pid (msgPool pre) (initialised pre) ppre (ppost , msgs)
→ initialised pre pid ≡ initd
→ (₋rmEC ppre) ^∙ rmEpoch ≡ (₋rmEC ppost) ^∙ rmEpoch
noEpochIdChangeYet _ ppre≡ (step-init uni) ini = ⊥-elim (uninitd≢initd (trans (sym uni) ini))
noEpochIdChangeYet _ ppre≡ (step-msg {(_ , m)} _ _) ini
with m
...| P p = refl
...| V v = refl
...| C c = refl
open SyncInfo
-- QCs in VoteMsg come from RoundManager
VoteMsgQCsFromRoundManager :
∀ {pid s' outs pk}{pre : SystemState}
→ ReachableSystemState pre
-- For any honest call to /handle/ or /init/,
→ (sps : StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (s' , outs))
→ ∀{v vm qc} → Meta-Honest-PK pk
-- For every vote v represented in a message output by the call
→ v ⊂Msg (V vm)
→ send (V vm) ∈ outs
→ qc QC∈SyncInfo (vm ^∙ vmSyncInfo)
→ qc ∈RoundManager (peerStates pre pid)
VoteMsgQCsFromRoundManager r (step-init _) _ _ ()
VoteMsgQCsFromRoundManager {pid} {pre = pre} r (step-msg {_ , P pm} m∈pool pinit) {v} {vm}
hpk v⊂m m∈outs qc∈m
with peerStates pre pid
...| rm
with proposalHandlerSentVote {pid} {0} {pm} {vm} {rm} m∈outs
...| _ , v∈outs
with qc∈m
...| withVoteSIHighQC refl
= inHQC (cong ₋siHighestQuorumCert (procPMCerts≡ {0} {pm} {rm} v∈outs))
VoteMsgQCsFromRoundManager {pid} {pre = pre} r (step-msg {_ , P pm} m∈pool pinit) {v} {vm1}
hpk v⊂m m∈outs qc∈m
| rm
| _ , v∈outs
| withVoteSIHighCC hqcIsJust
with cong ₋siHighestCommitCert (procPMCerts≡ {0} {pm} {rm} v∈outs)
...| refl
with (rm ^∙ rmHighestQC) ≟QC (rm ^∙ rmHighestCommitQC)
...| true because (ofʸ refl) = ⊥-elim (maybe-⊥ hqcIsJust refl)
...| false because _ = inHCC (just-injective (sym hqcIsJust))
newVoteSameEpochGreaterRound : ∀ {pre : SystemState}{pid s' outs v m pk}
→ ReachableSystemState pre
→ StepPeerState pid (msgPool pre) (initialised pre) (peerStates pre pid) (s' , outs)
→ ¬ (∈GenInfo (₋vSignature v))
→ Meta-Honest-PK pk
→ v ⊂Msg m → send m ∈ outs → (sig : WithVerSig pk v)
→ ¬ MsgWithSig∈ pk (ver-signature sig) (msgPool pre)
→ v ^∙ vEpoch ≡ (₋rmEC (peerStates pre pid)) ^∙ rmEpoch
× suc ((₋rmEC (peerStates pre pid)) ^∙ rmLastVotedRound) ≡ v ^∙ vRound -- New vote for higher round than last voted
× v ^∙ vRound ≡ ((₋rmEC s') ^∙ rmLastVotedRound) -- Last voted round is round of new vote
newVoteSameEpochGreaterRound {pre = pre} {pid} {v = v} {m} {pk} r (step-msg {(_ , P pm)} msg∈pool pinit) ¬init hpk v⊂m m∈outs sig vnew
rewrite pinit
with msgsToSendWereSent {pid} {P pm} {m} {peerStates pre pid} m∈outs
...| _ , vm , _ , refl , refl
with proposalHandlerSentVote {pid} {0} {pm} {vm} {peerStates pre pid} m∈outs
...| _ , v∈outs
rewrite SendVote-inj-v (Any-singleton⁻ v∈outs)
| SendVote-inj-si (Any-singleton⁻ v∈outs)
with v⊂m
-- Rebuilding keeps the same signature, and the SyncInfo included with the
-- VoteMsg sent comprises QCs from the peer's state. Votes represented in
-- those QCS have signatures that have been sent before, contradicting the
-- assumption that v's signature has not been sent before.
...| vote∈vm {si} = refl , refl , refl
...| vote∈qc {vs = vs} {qc} vs∈qc v≈rbld (inV qc∈m)
rewrite cong ₋vSignature v≈rbld
| procPMCerts≡ {0} {pm} {peerStates pre pid} {vm} v∈outs
with qcVotesSentB4 r pinit (VoteMsgQCsFromRoundManager r (step-msg msg∈pool pinit) hpk v⊂m (here refl) qc∈m) vs∈qc ¬init
...| sentb4 = ⊥-elim (vnew sentb4)
-- We resist the temptation to combine this with the noEpochChangeYet because in future there will be epoch changes
lastVoteRound-mono : ∀ {pre : SystemState}{pid}{ppre ppost msgs}
→ ReachableSystemState pre
→ ppre ≡ peerStates pre pid
→ StepPeerState pid (msgPool pre) (initialised pre) ppre (ppost , msgs)
→ initialised pre pid ≡ initd
→ (₋rmEC ppre) ^∙ rmEpoch ≡ (₋rmEC ppost) ^∙ rmEpoch
→ (₋rmEC ppre) ^∙ rmLastVotedRound ≤ (₋rmEC ppost) ^∙ rmLastVotedRound
lastVoteRound-mono _ ppre≡ (step-init uni) ini = ⊥-elim (uninitd≢initd (trans (sym uni) ini))
lastVoteRound-mono _ ppre≡ (step-msg {(_ , m)} _ _) _
with m
...| P p = const (≤-step (≤-reflexive refl))
...| V v = const (≤-reflexive refl)
...| C c = const (≤-reflexive refl)
postulate -- TODO-1: prove it
¬genVotesRound≢0 : ∀ {pk sig}{st : SystemState}
→ ReachableSystemState st
→ Meta-Honest-PK pk
→ (mws : MsgWithSig∈ pk sig (msgPool st))
→ ¬ (∈GenInfo sig)
→ (msgPart mws) ^∙ vRound ≢ 0
| {
"alphanum_fraction": 0.6065801668,
"avg_line_length": 52,
"ext": "agda",
"hexsha": "1d0db41ef171ee0a6250ca7dff9a47d2d8348a1a",
"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": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "cwjnkins/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Impl/Handle/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"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": "cwjnkins/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Impl/Handle/Properties.agda",
"max_line_length": 147,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "cwjnkins/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Impl/Handle/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3960,
"size": 12948
} |
module _ where
open import Data.Nat using (_+_ ; _≤′_ ; suc)
open import Induction.Nat using (<-rec)
open import Esterel.Lang.CanFunction
open import Function using (_∋_ ; _∘_ ; id ; _$_)
open import Data.Nat.Properties.Simple using ( +-comm ; +-assoc)
open import utility
open import noetherian using (noetherian ; ∥_∥s)
open import Esterel.Lang
open import Esterel.Lang.Properties
open import Esterel.Environment as Env
open import Esterel.Context
open import Data.Product
open import Data.Sum
open import Data.Bool
open import Data.List using ([] ; [_] ; _∷_ ; List ; _++_)
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl ; sym ; subst ; cong ; trans ; module ≡-Reasoning ; cong₂ ; subst₂ ; inspect)
open import Data.Empty
open import sn-calculus
open import context-properties -- get view, E-views
open import Esterel.Lang.Binding
open import Data.Maybe using ( just )
-- open import coherence
open import Data.List.Any
open import Data.List.Any.Properties
open import Esterel.Lang.CanFunction.Base
open import eval
open import blocked
open import Data.List.All
open import eval
open ≡-Reasoning using (_≡⟨_⟩_ ; _≡⟨⟩_ ; _∎)
open import Relation.Nullary.Decidable
using (⌊_⌋)
open import Data.FiniteMap
import Data.OrderedListMap as OMap
open import Data.Nat as Nat using (ℕ)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar ; _ᵥ)
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import sn-calculus-compatconf using (1-step)
open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM
open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM
open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM
open import binding-preserve
open import sn-calculus-props
open import par-swap
open import par-swap.union-properties
open import calculus
open import calculus.properties
evalsn≡ₑ-consistent : ∀{output output'} θ p → CB (ρ⟨ θ , GO ⟩· p) → evalsn≡ₑ p θ output → evalsn≡ₑ p θ output' → output ≡ output'
evalsn≡ₑ-consistent θ p ⊢cb-p (evalsn-complete ρθ·p≡q complete-q) (evalsn-complete ρθ·p≡r complete-r)
with sn≡ₑ-consistent (proj₂ (sn≡ₑ-preserve-cb ⊢cb-p ρθ·p≡q)) (rtrn (rsym ρθ·p≡q ⊢cb-p) ρθ·p≡r)
... | (s , qsn⟶*s , rsn⟶*s)
with inescapability-of-complete-sn complete-q qsn⟶*s
... | complete-s
with ρ-stays-ρ-sn⟶* qsn⟶*s | ρ-stays-ρ-sn⟶* rsn⟶*s
... | θq , _ , _ , refl | θr , _ , _ , refl
with equality-of-complete-sn⟶* complete-q qsn⟶*s
| equality-of-complete-sn⟶* complete-r rsn⟶*s
... | refl , refl | refl , refl = refl
eval∥R∪sn≡ₑ-consistent : ∀ {output output'} θ p →
CB (ρ⟨ θ , GO ⟩· p) →
eval∥R∪sn≡ₑ p θ output →
eval∥R∪sn≡ₑ p θ output' →
output ≡ output'
eval∥R∪sn≡ₑ-consistent θ p ⊢cb-p (eval∥R∪sn-complete ρθ·p≡q complete-q) (eval∥R∪sn-complete ρθ·p≡r complete-r)
with ∥R∪sn≡ₑ-consistent (proj₂ (∥R∪sn≡ₑ-preserve-cb ⊢cb-p ρθ·p≡q)) (∪trn (∪sym ρθ·p≡q ⊢cb-p) ρθ·p≡r)
... | (s , qsn⟶*s , rsn⟶*s)
with inescapability-of-complete-∪ complete-q qsn⟶*s
... | complete-s
with ρ-stays-ρ-∪ qsn⟶*s | ρ-stays-ρ-∪ rsn⟶*s
... | θq , _ , _ , refl | θr , _ , _ , refl
with equality-of-complete-∪ complete-q qsn⟶*s
| equality-of-complete-∪ complete-r rsn⟶*s
... | refl , refl | refl , refl = refl
eval≡ₑ->eval∥R∪sn≡ : ∀ {p θ output} ->
eval≡ₑ p θ output →
eval∥R∪sn≡ₑ p θ output
eval≡ₑ->eval∥R∪sn≡ (eval-complete ρθ·p≡q complete-q) =
eval∥R∪sn-complete (≡ₑ-to-∥R∪sn≡ₑ ρθ·p≡q) complete-q
eval≡ₑ-consistent : ∀ {output output'} θ p →
CB (ρ⟨ θ , GO ⟩· p) →
eval≡ₑ p θ output →
eval≡ₑ p θ output' →
output ≡ output'
eval≡ₑ-consistent θ p CBρp eval≡₁ eval≡₂
= eval∥R∪sn≡ₑ-consistent θ p CBρp
(eval≡ₑ->eval∥R∪sn≡ eval≡₁)
(eval≡ₑ->eval∥R∪sn≡ eval≡₂)
sn≡ₑ=>eval : ∀ p θp outputp q θq outputq → CB (ρ⟨ θp , GO ⟩· p) → (ρ⟨ θp , GO ⟩· p) sn≡ₑ (ρ⟨ θq , GO ⟩· q) → evalsn≡ₑ p θp outputp → evalsn≡ₑ q θq outputq → outputp ≡ outputq
sn≡ₑ=>eval _ _ _ _ _ _ CB eq (evalsn-complete ρθ·p≡q complete-q) (evalsn-complete ρθ·p≡q₁ complete-q₁)
with sn≡ₑ-consistent (proj₂ (sn≡ₑ-preserve-cb CB ρθ·p≡q)) (rtrn (rsym ρθ·p≡q CB) (rtrn eq ρθ·p≡q₁))
... | (s , qsn⟶*s , rsn⟶*s)
with inescapability-of-complete-sn complete-q qsn⟶*s
... | complete-s
with ρ-stays-ρ-sn⟶* qsn⟶*s | ρ-stays-ρ-sn⟶* rsn⟶*s
... | θq , _ , _ , refl | θr , _ , _ , refl
with equality-of-complete-sn⟶* complete-q qsn⟶*s
| equality-of-complete-sn⟶* complete-q₁ rsn⟶*s
... | refl , refl | refl , refl = refl
∥R∪sn≡ₑ=>eval : ∀ p θp outputp q θq outputq →
CB (ρ⟨ θp , GO ⟩· p) →
(ρ⟨ θp , GO ⟩· p) ∥R∪sn≡ₑ (ρ⟨ θq , GO ⟩· q) →
eval∥R∪sn≡ₑ p θp outputp →
eval∥R∪sn≡ₑ q θq outputq →
outputp ≡ outputq
∥R∪sn≡ₑ=>eval _ _ _ _ _ _ CB eq (eval∥R∪sn-complete ρθ·p≡q complete-q) (eval∥R∪sn-complete ρθ·p≡q₁ complete-q₁)
with ∥R∪sn≡ₑ-consistent (proj₂ (∥R∪sn≡ₑ-preserve-cb CB ρθ·p≡q)) (∪trn (∪sym ρθ·p≡q CB) (∪trn eq ρθ·p≡q₁))
... | (s , qsn⟶*s , rsn⟶*s)
with inescapability-of-complete-∪ complete-q qsn⟶*s
... | complete-s
with ρ-stays-ρ-∪ qsn⟶*s | ρ-stays-ρ-∪ rsn⟶*s
... | θq , _ , _ , refl | θr , _ , _ , refl
with equality-of-complete-∪ complete-q qsn⟶*s
| equality-of-complete-∪ complete-q₁ rsn⟶*s
... | refl , refl | refl , refl = refl
≡ₑ=>eval : ∀ p θp outputp q θq outputq →
CB (ρ⟨ θp , GO ⟩· p) →
(ρ⟨ θp , GO ⟩· p) ≡ₑ (ρ⟨ θq , GO ⟩· q) # [] →
eval≡ₑ p θp outputp →
eval≡ₑ q θq outputq →
outputp ≡ outputq
≡ₑ=>eval p θp outputp q θq outputq CBρp ρp≡ₑρq eval≡₁ eval≡₂
= ∥R∪sn≡ₑ=>eval p θp outputp q θq outputq CBρp
(≡ₑ-to-∥R∪sn≡ₑ ρp≡ₑρq)
(eval≡ₑ->eval∥R∪sn≡ eval≡₁)
(eval≡ₑ->eval∥R∪sn≡ eval≡₂)
| {
"alphanum_fraction": 0.6582758621,
"avg_line_length": 39.4557823129,
"ext": "agda",
"hexsha": "fed18ca0449ad4749178e4e4db2be3bf079adeb3",
"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/eval-props.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/eval-props.agda",
"max_line_length": 174,
"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/eval-props.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": 2559,
"size": 5800
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.ListedFiniteSet.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Sum as ⊎ using (_⊎_; inl; inr)
open import Cubical.Functions.Logic
private
variable
ℓ : Level
A B : Type ℓ
infixr 20 _∷_
-- infix 30 _∈_
infixr 5 _++_
data LFSet (A : Type ℓ) : Type ℓ where
[] : LFSet A
_∷_ : (x : A) → (xs : LFSet A) → LFSet A
dup : ∀ x xs → x ∷ x ∷ xs ≡ x ∷ xs
comm : ∀ x y xs → x ∷ y ∷ xs ≡ y ∷ x ∷ xs
trunc : isSet (LFSet A)
-- Membership.
--
-- Doing some proofs with equational reasoning adds an extra "_∙ refl"
-- at the end.
-- We might want to avoid it, or come up with a more clever equational reasoning.
_∈_ : {A : Type ℓ} → A → LFSet A → hProp ℓ
z ∈ [] = Lift ⊥.⊥ , isOfHLevelLift 1 isProp⊥
z ∈ (y ∷ xs) = (z ≡ₚ y) ⊔ (z ∈ xs)
z ∈ dup x xs i = proof i
where
-- proof : z ∈ (x ∷ x ∷ xs) ≡ z ∈ (x ∷ xs)
proof = z ≡ₚ x ⊔ (z ≡ₚ x ⊔ z ∈ xs) ≡⟨ ⊔-assoc (z ≡ₚ x) (z ≡ₚ x) (z ∈ xs) ⟩
(z ≡ₚ x ⊔ z ≡ₚ x) ⊔ z ∈ xs ≡⟨ cong (_⊔ (z ∈ xs)) (⊔-idem (z ≡ₚ x)) ⟩
z ≡ₚ x ⊔ z ∈ xs ∎
z ∈ comm x y xs i = proof i
where
-- proof : z ∈ (x ∷ y ∷ xs) ≡ z ∈ (y ∷ x ∷ xs)
proof = z ≡ₚ x ⊔ (z ≡ₚ y ⊔ z ∈ xs) ≡⟨ ⊔-assoc (z ≡ₚ x) (z ≡ₚ y) (z ∈ xs) ⟩
(z ≡ₚ x ⊔ z ≡ₚ y) ⊔ z ∈ xs ≡⟨ cong (_⊔ (z ∈ xs)) (⊔-comm (z ≡ₚ x) (z ≡ₚ y)) ⟩
(z ≡ₚ y ⊔ z ≡ₚ x) ⊔ z ∈ xs ≡⟨ sym (⊔-assoc (z ≡ₚ y) (z ≡ₚ x) (z ∈ xs)) ⟩
z ≡ₚ y ⊔ (z ≡ₚ x ⊔ z ∈ xs) ∎
x ∈ trunc xs ys p q i j = isSetHProp (x ∈ xs) (x ∈ ys) (cong (x ∈_) p) (cong (x ∈_) q) i j
module Elim {ℓ}
{B : LFSet A → Type ℓ}
([]* : B [])
(_∷*_ : (x : A) {xs : LFSet A} → B xs → B (x ∷ xs))
(comm* : (x y : A) {xs : LFSet A} (b : B xs)
→ PathP (λ i → B (comm x y xs i)) (x ∷* (y ∷* b)) (y ∷* (x ∷* b)))
(dup* : (x : A) {xs : LFSet A} (b : B xs)
→ PathP (λ i → B (dup x xs i)) (x ∷* (x ∷* b)) (x ∷* b))
(trunc* : (xs : LFSet A) → isSet (B xs)) where
f : ∀ x → B x
f [] = []*
f (x ∷ xs) = x ∷* f xs
f (dup x xs i) = dup* x (f xs) i
f (comm x y xs i) = comm* x y (f xs) i
f (trunc x y p q i j) =
isOfHLevel→isOfHLevelDep 2 trunc*
(f x) (f y)
(λ i → f (p i)) (λ i → f (q i))
(trunc x y p q) i j
module Rec {ℓ} {B : Type ℓ}
([]* : B)
(_∷*_ : (x : A) → B → B)
(comm* : (x y : A) (xs : B) → (x ∷* (y ∷* xs)) ≡ (y ∷* (x ∷* xs)))
(dup* : (x : A) (b : B) → (x ∷* (x ∷* b)) ≡ (x ∷* b))
(trunc* : isSet B) where
f : LFSet A → B
f =
Elim.f
[]* (λ x xs → x ∷* xs)
(λ x y b → comm* x y b) (λ x b → dup* x b)
λ _ → trunc*
module PropElim {ℓ}
{B : LFSet A → Type ℓ}
([]* : B []) (_∷*_ : (x : A) {xs : LFSet A} → B xs → B (x ∷ xs))
(trunc* : (xs : LFSet A) → isProp (B xs)) where
f : ∀ x → B x
f =
Elim.f
[]* _∷*_
(λ _ _ _ → isOfHLevel→isOfHLevelDep 1 trunc* _ _ _)
(λ _ _ → isOfHLevel→isOfHLevelDep 1 trunc* _ _ _)
λ xs → isProp→isSet (trunc* xs)
_++_ : ∀ (xs ys : LFSet A) → LFSet A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
dup x xs i ++ ys = dup x (xs ++ ys) i
comm x y xs i ++ ys = comm x y (xs ++ ys) i
trunc xs zs p q i j ++ ys =
trunc (xs ++ ys) (zs ++ ys) (cong (_++ ys) p) (cong (_++ ys) q) i j
map : (A → B) → LFSet A → LFSet B
map f [] = []
map f (x ∷ xs) = f x ∷ map f xs
map f (dup x xs i) = dup (f x) (map f xs) i
map f (comm x y xs i) = comm (f x) (f y) (map f xs) i
map f (trunc xs ys p q i j) =
trunc (map f xs) (map f ys) (cong (map f) p) (cong (map f) q) i j
disj-union : LFSet A → LFSet B → LFSet (A ⊎ B)
disj-union xs ys = map ⊎.inl xs ++ map ⊎.inr ys
| {
"alphanum_fraction": 0.4530343008,
"avg_line_length": 32.6724137931,
"ext": "agda",
"hexsha": "f8e27e06ef153be063b073c7534157d28dd9bca8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/HITs/ListedFiniteSet/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/HITs/ListedFiniteSet/Base.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/HITs/ListedFiniteSet/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1794,
"size": 3790
} |
------------------------------------------------------------------------
-- Pointwise lifting of (binary) initial bag operators to parsers
------------------------------------------------------------------------
open import Data.List
open import Data.List.Membership.Propositional using (_∈_)
open import Data.List.Relation.Binary.BagAndSetEquality
using () renaming (_∼[_]_ to _List-∼[_]_)
open import Function.Related as Related using (Kind; SK-sym)
module TotalParserCombinators.Pointwise
(R₁ R₂ : Set) {R₃ : Set}
-- Some kinds of equality.
{K : Set} (⌊_⌋ : K → Kind)
-- An initial bag operator.
(_∙_ : List R₁ → List R₂ → List R₃)
-- The operator must preserve the given notions of equality.
(_∙-cong_ : ∀ {k xs₁ xs₁′ xs₂ xs₂′} →
xs₁ List-∼[ ⌊ k ⌋ ] xs₁′ → xs₂ List-∼[ ⌊ k ⌋ ] xs₂′ →
(xs₁ ∙ xs₂) List-∼[ ⌊ k ⌋ ] (xs₁′ ∙ xs₂′))
where
open import Codata.Musical.Notation
open import Function.Base
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (_⇔_; module Equivalence)
open import Function.Inverse using (_↔_; module Inverse)
open import TotalParserCombinators.Congruence as C using (_∼[_]P_; _≅P_)
import TotalParserCombinators.Congruence.Sound as CS
open import TotalParserCombinators.Derivative as D
import TotalParserCombinators.InitialBag as I
open import TotalParserCombinators.Laws
open import TotalParserCombinators.Lib
open import TotalParserCombinators.Parser
open import TotalParserCombinators.Semantics using (_∈_·_)
------------------------------------------------------------------------
-- Lift
-- A lifting of the initial bag operator _∙_ to the level of parsers.
--
-- Note that this definition is closely related to Theorem 4.4 in
-- Brzozowski's paper "Derivatives of Regular Expressions".
--
-- Note also that _∙_ is allowed to pattern match on the input
-- indices, so it may not be obvious that lift preserves equality.
-- This fact is established explicitly below (by making use of
-- _∙-cong_).
lift : ∀ {Tok xs₁ xs₂} →
Parser Tok R₁ xs₁ → Parser Tok R₂ xs₂ →
Parser Tok R₃ (xs₁ ∙ xs₂)
lift p₁ p₂ =
(token >>= λ t → ♯ lift (D t p₁) (D t p₂))
∣ return⋆ (initial-bag p₁ ∙ initial-bag p₂)
------------------------------------------------------------------------
-- Properties of lift
-- D distributes over lift.
D-lift : ∀ {Tok xs₁ xs₂ t}
(p₁ : Parser Tok R₁ xs₁) (p₂ : Parser Tok R₂ xs₂) →
D t (lift p₁ p₂) ≅P lift (D t p₁) (D t p₂)
D-lift {xs₁ = xs₁} {xs₂} {t} p₁ p₂ =
D t (lift p₁ p₂) ≅⟨ D t (lift p₁ p₂) ∎ ⟩
(return t >>= λ t → lift (D t p₁) (D t p₂)) ∣
D t (return⋆ (xs₁ ∙ xs₂)) ≅⟨ Monad.left-identity t (λ t → lift (D t p₁) (D t p₂)) ∣
D.D-return⋆ (xs₁ ∙ xs₂) ⟩
lift (D t p₁) (D t p₂) ∣ fail ≅⟨ AdditiveMonoid.right-identity (lift (D t p₁) (D t p₂)) ⟩
lift (D t p₁) (D t p₂) ∎
where open C using (_≅⟨_⟩_; _∎; _∣_)
-- lift preserves equality.
lift-cong : ∀ {k Tok xs₁ xs₁′ xs₂ xs₂′}
{p₁ : Parser Tok R₁ xs₁} {p₁′ : Parser Tok R₁ xs₁′}
{p₂ : Parser Tok R₂ xs₂} {p₂′ : Parser Tok R₂ xs₂′} →
p₁ ∼[ ⌊ k ⌋ ]P p₁′ → p₂ ∼[ ⌊ k ⌋ ]P p₂′ →
lift p₁ p₂ ∼[ ⌊ k ⌋ ]P lift p₁′ p₂′
lift-cong {k} {xs₁ = xs₁} {xs₁′} {xs₂} {xs₂′} {p₁} {p₁′} {p₂} {p₂′}
p₁≈p₁′ p₂≈p₂′ = lemma ∷ λ t → ♯ (
D t (lift p₁ p₂) ≅⟨ D-lift p₁ p₂ ⟩
lift (D t p₁) (D t p₂) ∼⟨ lift-cong (CS.D-cong p₁≈p₁′) (CS.D-cong p₂≈p₂′) ⟩
lift (D t p₁′) (D t p₂′) ≅⟨ sym (D-lift p₁′ p₂′) ⟩
D t (lift p₁′ p₂′) ∎)
where
open C using (_≅⟨_⟩_; _∼⟨_⟩_; _∎; sym; _∷_)
lemma : (xs₁ ∙ xs₂) List-∼[ ⌊ k ⌋ ] (xs₁′ ∙ xs₂′)
lemma = I.cong (CS.sound p₁≈p₁′) ∙-cong I.cong (CS.sound p₂≈p₂′)
-- Lifts a property from _∙_ to lift. For examples of its use, see
-- TotalParserCombinators.{And,AsymmetricChoice,Not}.
lift-property :
(P : ∀ {ℓ} → (R₁ → Set ℓ) → (R₂ → Set ℓ) → (R₃ → Set ℓ) → Set ℓ)
(P-cong :
∀ {ℓ} {F₁ : R₁ → Set ℓ} {F₂ : R₂ → Set ℓ} {F₃ : R₃ → Set ℓ}
{ℓ′} {F₁′ : R₁ → Set ℓ′} {F₂′ : R₂ → Set ℓ′} {F₃′ : R₃ → Set ℓ′} →
(∀ x → F₁ x ↔ F₁′ x) → (∀ x → F₂ x ↔ F₂′ x) → (∀ x → F₃ x ↔ F₃′ x) →
P F₁ F₂ F₃ ⇔ P F₁′ F₂′ F₃′) →
(P-∙ :
∀ {xs₁ xs₂} →
P (λ x → x ∈ xs₁) (λ x → x ∈ xs₂) (λ x → x ∈ (xs₁ ∙ xs₂))) →
∀ {Tok xs₁ xs₂ s}
(p₁ : Parser Tok R₁ xs₁) (p₂ : Parser Tok R₂ xs₂) →
P (λ x → x ∈ p₁ · s) (λ x → x ∈ p₂ · s) (λ x → x ∈ lift p₁ p₂ · s)
lift-property P P-cong P-∙ {s = []} p₁ p₂ =
Equivalence.from
(P (λ x → x ∈ p₁ · []) (λ x → x ∈ p₂ · [])
(λ x → x ∈ lift p₁ p₂ · []) ∼⟨ P-cong (λ _ → I.correct) (λ _ → I.correct) (λ _ → I.correct) ⟩
P (λ x → x ∈ initial-bag p₁) (λ x → x ∈ initial-bag p₂)
(λ x → x ∈ (initial-bag p₁ ∙ initial-bag p₂)) ∎
) ⟨$⟩ P-∙
where open Related.EquationalReasoning
lift-property P P-cong P-∙ {s = t ∷ s} p₁ p₂ =
Equivalence.from
(P (λ x → x ∈ p₁ · t ∷ s) (λ x → x ∈ p₂ · t ∷ s)
(λ x → x ∈ lift p₁ p₂ · t ∷ s) ∼⟨ SK-sym $ P-cong (λ _ → D.correct) (λ _ → D.correct) (λ _ → D.correct) ⟩
P (λ x → x ∈ D t p₁ · s) (λ x → x ∈ D t p₂ · s)
(λ x → x ∈ D t (lift p₁ p₂) · s) ∼⟨ P-cong (λ _ → _ ∎) (λ _ → _ ∎) (λ _ → CS.sound (D-lift p₁ p₂)) ⟩
P (λ x → x ∈ D t p₁ · s) (λ x → x ∈ D t p₂ · s)
(λ x → x ∈ lift (D t p₁) (D t p₂) · s) ∎
) ⟨$⟩ lift-property P P-cong P-∙ (D t p₁) (D t p₂)
where open Related.EquationalReasoning
| {
"alphanum_fraction": 0.5145822151,
"avg_line_length": 39.0839160839,
"ext": "agda",
"hexsha": "b5841dcfbe76d4e8f8f080fe9cec135de5493544",
"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": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "TotalParserCombinators/Pointwise.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"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/parser-combinators",
"max_issues_repo_path": "TotalParserCombinators/Pointwise.agda",
"max_line_length": 128,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/parser-combinators",
"max_stars_repo_path": "TotalParserCombinators/Pointwise.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z",
"num_tokens": 2224,
"size": 5589
} |
module Everything where
import Library
import Terms
import Substitution
import SN
import SN.AntiRename
import Reduction
import SAT3
import DeclSN
import Soundness
| {
"alphanum_fraction": 0.8545454545,
"avg_line_length": 12.6923076923,
"ext": "agda",
"hexsha": "e6dd1c184099ac1581bd5afd806c8af11fddcfe4",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2018-02-23T18:22:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-11-10T16:44:52.000Z",
"max_forks_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "ryanakca/strong-normalization",
"max_forks_repo_path": "agda-aplas14/Everything.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_issues_repo_issues_event_max_datetime": "2018-02-20T14:54:18.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-02-14T16:42:36.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "ryanakca/strong-normalization",
"max_issues_repo_path": "agda-aplas14/Everything.agda",
"max_line_length": 23,
"max_stars_count": 32,
"max_stars_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "ryanakca/strong-normalization",
"max_stars_repo_path": "agda-aplas14/Everything.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-05T12:12:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-22T14:33:27.000Z",
"num_tokens": 39,
"size": 165
} |
------------------------------------------------------------------------
-- Code related to the paper "Higher Inductive Type Eliminators
-- Without Paths"
--
-- Nils Anders Danielsson
------------------------------------------------------------------------
-- Note that the code does not follow the paper exactly, and that some
-- of the code has been changed after the paper was published.
{-# OPTIONS --cubical --safe #-}
module README.HITs-without-paths where
import Equality
import Equality.Id
import Equality.Instances-related
import Equality.Path
import Equality.Path.Isomorphisms
import Equality.Propositional
import Function-universe
import H-level
import H-level.Truncation.Propositional
import Quotient
import Suspension
------------------------------------------------------------------------
-- 1: Introduction
-- The propositional truncation operator.
∥_∥ = H-level.Truncation.Propositional.∥_∥
-- Equality defined as an inductive family with a single constructor
-- refl.
_≡_ = Equality.Propositional._≡_
------------------------------------------------------------------------
-- 2: An Axiomatisation of Equality With J
-- The code uses an axiomatisation of "equality with J", as discussed
-- in the text. The axiomatisation is a little convoluted in order to
-- support using equality at all universe levels. Furthermore, also as
-- discussed in the text, the axiomatisation supports choosing
-- specific definitions for other functions, like cong, to make the
-- code more usable when it is instantiated with Cubical Agda paths
-- (for which the canonical definition of cong computes in a different
-- way than typical definitions obtained using J).
-- Equality and reflexivity.
≡-refl = Equality.Reflexive-relation
-- The J rule and its computation rule.
J-J-refl = Equality.Equality-with-J₀
-- Extended variants of the two definitions above.
Equivalence-relation⁺ = Equality.Equivalence-relation⁺
Equality-with-J = Equality.Equality-with-J
Equality-with-paths = Equality.Path.Equality-with-paths
-- The extended variants are inhabited for all universe levels if the
-- basic ones are inhabited for all universe levels.
J₀⇒Equivalence-relation⁺ = Equality.J₀⇒Equivalence-relation⁺
J₀⇒J = Equality.J₀⇒J
Equality-with-J₀⇒Equality-with-paths =
Equality.Path.Equality-with-J₀⇒Equality-with-paths
-- To see how the code is axiomatised, see the module header of, say,
-- Circle.
import Circle
-- Any two notions of equality satisfying the axioms are pointwise
-- isomorphic, and the isomorphisms map canonical proofs of
-- reflexivity to canonical proofs of reflexivity.
--
-- Note that in some cases the code uses bijections (_↔_) instead of
-- equivalences (_≃_).
instances-isomorphic =
Equality.Instances-related.all-equality-types-isomorphic
-- Cubical Agda paths, the Cubical Agda identity type family, and a
-- definition of equality as an inductive family with a single
-- constructor refl are instances of the axioms. (The last instance is
-- for Equality-with-J rather than Equality-with-paths, because the
-- latter definition is defined in Cubical Agda, and the instance is
-- not.)
paths-instance = Equality.Path.equality-with-paths
id-instance = Equality.Id.equality-with-paths
inductive-family-instance = Equality.Propositional.equality-with-J
------------------------------------------------------------------------
-- 3: Homogeneous Paths
-- The path type constructor.
Path = Equality.Path._≡_
-- Zero and one.
0̲ = Equality.Path.0̲
1̲ = Equality.Path.1̲
-- Reflexivity.
reflᴾ = Equality.Path.refl
-- Minimum, maximum and negation.
min = Equality.Path.min
max = Equality.Path.max
-_ = Equality.Path.-_
-- The primitive transport operation.
open Equality.Path using (transport)
-- The J rule and transport-refl.
Jᴾ = Equality.Path.elim
transport-refl = Equality.Path.transport-refl
-- Transitivity (more general than in the paper).
transᴾ = Equality.Path.htransʳ
------------------------------------------------------------------------
-- 4: Heterogeneous Paths
-- Pathᴴ.
Pathᴴ = Equality.Path.[_]_≡_
-- The eliminator elimᴾ for the propositional truncation operator.
module ∥_∥ where
elimᴾ = H-level.Truncation.Propositional.elimᴾ′
-- Pathᴴ≡Path and Pathᴴ≃Path.
Pathᴴ≡Path = Equality.Path.heterogeneous≡homogeneous
Pathᴴ≃Path = Equality.Path.heterogeneous↔homogeneous
-- The lemma substᴾ.
substᴾ = Equality.Path.subst
-- The lemmas subst and subst-refl from the axiomatisation.
subst = Equality.Equality-with-J.subst
subst-refl = Equality.Equality-with-J.subst-refl
-- The axiomatisation makes it possible to choose the implementations
-- of to-path and from-path.
to-path = Equality.Path.Equality-with-paths.to-path
from-path = Equality.Path.Equality-with-paths.from-path
-- The code mostly uses a pointwise isomorphism between the arbitrary
-- notion of equality and paths instead of from-path and to-path.
≡↔≡ = Equality.Path.Derived-definitions-and-properties.≡↔≡
-- The lemmas subst≡substᴾ, subst≡≃Pathᴴ, subst≡→Pathᴴ and
-- subst≡→substᴾ≡ (which is formulated as a bijection).
subst≡substᴾ = Equality.Path.Isomorphisms.subst≡subst
subst≡≃Pathᴴ = Equality.Path.Isomorphisms.subst≡↔[]≡
subst≡→Pathᴴ = Equality.Path.Isomorphisms.subst≡→[]≡
subst≡→substᴾ≡ = Equality.Path.Isomorphisms.subst≡↔subst≡
-- The lemmas congᴰ and congᴰ-refl from the axiomatisation.
congᴰ = Equality.Equality-with-J.dcong
congᴰ-refl = Equality.Equality-with-J.dcong-refl
-- The lemmas congᴴ and congᴰᴾ.
congᴴ = Equality.Path.hcong
congᴰᴾ = Equality.Path.dcong
-- The proofs congᴰ≡congᴰᴾ, congᴰᴾ≡congᴴ, congᴰ≡congᴴ and
-- dependent‐computation‐rule‐lemma.
congᴰ≡congᴰᴾ = Equality.Path.Isomorphisms.dcong≡dcong
congᴰᴾ≡congᴴ = Equality.Path.dcong≡hcong
congᴰ≡congᴴ = Equality.Path.Isomorphisms.dcong≡hcong
dependent‐computation‐rule‐lemma =
Equality.Path.Isomorphisms.dcong-subst≡→[]≡
------------------------------------------------------------------------
-- 5: The Circle Without Paths
-- The circle and loop.
𝕊¹ = Circle.𝕊¹
loop = Circle.loop
-- The lemmas cong and cong-refl from the axiomatisation.
cong = Equality.Equality-with-J.cong
cong-refl = Equality.Equality-with-J.cong-refl
-- The lemma non-dependent-computation-rule-lemma.
non-dependent-computation-rule-lemma =
Equality.Path.Isomorphisms.cong-≡↔≡
-- The lemma trans, which is actually a part of the axiomatisation
-- that I use, but which can be proved using the J rule.
trans = Equality.Equivalence-relation⁺.trans
J₀⇒trans = Equality.J₀⇒Equivalence-relation⁺
-- The lemma subst-const.
subst-const = Equality.Derived-definitions-and-properties.subst-const
-- The lemma congᴰ≡→cong≡.
congᴰ≡→cong≡ = Equality.Derived-definitions-and-properties.dcong≡→cong≡
-- Eliminators and computation rules.
module 𝕊¹ where
elimᴾ = Circle.elimᴾ
recᴾ = Circle.recᴾ
elim = Circle.elim
elim-loop = Circle.elim-loop
rec = Circle.rec
rec-loop = Circle.rec-loop
rec′ = Circle.rec′
rec′-loop = Circle.rec′-loop
------------------------------------------------------------------------
-- 6: Set Quotients Without Paths
-- The definition of h-levels.
Contractible = Equality.Derived-definitions-and-properties.Contractible
H-level = H-level.H-level
Is-proposition = Equality.Derived-definitions-and-properties.Is-proposition
Is-set = Equality.Derived-definitions-and-properties.Is-set
-- Set quotients.
_/_ = Quotient._/_
-- Some lemmas.
H-levelᴾ-suc≃H-levelᴾ-Pathᴴ = Equality.Path.H-level-suc↔H-level[]≡
index-irrelevant = Equality.Path.index-irrelevant
transport-transport = Equality.Path.transport∘transport
heterogeneous-irrelevance = Equality.Path.heterogeneous-irrelevance
heterogeneous-UIP = Equality.Path.heterogeneous-UIP
H-level≃H-levelᴾ = Equality.Path.Isomorphisms.H-level↔H-level
-- A generalisation of Π-cong. Note that equality is provably
-- extensional in Cubical Agda.
Π-cong = Function-universe.Π-cong
extensionality = Equality.Path.ext
-- Variants of the constructors.
[]-respects-relation = Quotient.[]-respects-relation
/-is-set = Quotient./-is-set
-- Eliminators.
module _/_ where
elimᴾ′ = Quotient.elimᴾ′
elimᴾ = Quotient.elimᴾ
recᴾ = Quotient.recᴾ
elim = Quotient.elim
rec = Quotient.rec
------------------------------------------------------------------------
-- 7: More Examples
-- Suspensions.
module Susp where
Susp = Suspension.Susp
elimᴾ = Suspension.elimᴾ
recᴾ = Suspension.recᴾ
meridian = Suspension.meridian
elim = Suspension.elim
elim-meridian = Suspension.elim-meridian
rec = Suspension.rec
rec-meridian = Suspension.rec-meridian
-- The propositional truncation operator.
module Propositional-truncation where
elimᴾ′ = H-level.Truncation.Propositional.elimᴾ′
elimᴾ = H-level.Truncation.Propositional.elimᴾ
recᴾ = H-level.Truncation.Propositional.recᴾ
trivial = H-level.Truncation.Propositional.truncation-is-proposition
elim = H-level.Truncation.Propositional.elim
rec = H-level.Truncation.Propositional.rec
------------------------------------------------------------------------
-- 8: An Alternative Approach
-- Circle and Circleᴾ, combined into a single definition.
Circle = Circle.Circle
-- Circleᴾ≃Circle, circleᴾ and circle.
Circleᴾ≃Circle = Circle.Circle≃Circle
circleᴾ = Circle.circleᴾ
circle = Circle.circle
-- The computation rule for the higher constructor.
elim-loop-circle = Circle.elim-loop-circle
-- Alternative definitions of Circleᴾ≃Circle and circle that (at the
-- time of writing) do not give the "correct" computational behaviour
-- for the point constructor.
Circleᴾ≃Circle′ = Circle.Circle≃Circle′
circle′ = Circle.circle′
------------------------------------------------------------------------
-- 9: Discussion
-- The interval.
import Interval
-- Pushouts.
import Pushout
-- A general truncation operator.
import H-level.Truncation
-- The torus.
import Torus
| {
"alphanum_fraction": 0.679252704,
"avg_line_length": 28.487394958,
"ext": "agda",
"hexsha": "5d006937c70cf5a3f5935763713f458ff30f42a6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "README/HITs-without-paths.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "README/HITs-without-paths.agda",
"max_line_length": 75,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "README/HITs-without-paths.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 2760,
"size": 10170
} |
open import Prelude hiding (subst)
module Implicits.Substitutions.Term where
open import Implicits.Syntax.Type
open import Implicits.Syntax.Term
open import Data.Fin.Substitution
open import Data.Star as Star hiding (map)
open import Data.Star.Properties
open import Data.Vec hiding ([_])
open import Implicits.Substitutions.Type as TypeSubst using ()
module TermTypeSubst where
module TermTypeApp {T} (l : Lift T Type) where
open Lift l hiding (var)
open TypeSubst.TypeApp l renaming (_/_ to _/tp_)
infixl 8 _/_
-- Apply a type substitution to a term
_/_ : ∀ {ν μ n} → Term ν n → Sub T ν μ → Term μ n
var x / σ = var x
Λ t / σ = Λ (t / σ ↑)
λ' a t / σ = λ' (a /tp σ) (t / σ)
t [ a ] / σ = (t / σ) [ a /tp σ ]
s · t / σ = (s / σ) · (t / σ)
ρ a t / σ = ρ (a /tp σ) (t / σ)
r ⟨⟩ / σ = (r / σ) ⟨⟩
r with' e / σ = (r / σ) with' (e / σ)
open TypeSubst using (varLift; termLift; sub)
module Lifted {T} (lift : Lift T Type) {n} where
application : Application (λ ν → Term ν n) T
application = record { _/_ = TermTypeApp._/_ lift {n = n} }
open Application application public
open Lifted termLift public
-- apply a type variable substitution (renaming) to a term
_/Var_ : ∀ {ν μ n} → Term ν n → Sub Fin ν μ → Term μ n
_/Var_ = TermTypeApp._/_ varLift
-- weaken a term with an additional type variable
weaken : ∀ {ν n} → Term ν n → Term (suc ν) n
weaken t = t /Var VarSubst.wk
infix 8 _[/_]
-- shorthand for single-variable type substitutions in terms
_[/_] : ∀ {ν n} → Term (suc ν) n → Type ν → Term ν n
t [/ b ] = t / sub b
module TermTermSubst where
-- Substitutions of terms in terms
TermSub : (ℕ → ℕ → Set) → ℕ → ℕ → ℕ → Set
TermSub T ν m n = Sub (T ν) m n
record TermLift (T : ℕ → ℕ → Set) : Set where
infix 10 _↑tm _↑tp
field
lift : ∀ {ν n} → T ν n → Term ν n
_↑tm : ∀ {ν m n} → TermSub T ν m n → TermSub T ν (suc m) (suc n)
_↑tp : ∀ {ν m n} → TermSub T ν m n → TermSub T (suc ν) m n
module TermTermApp {T} (l : TermLift T) where
open TermLift l
infixl 8 _/_
-- Apply a term substitution to a term
_/_ : ∀ {ν m n} → Term ν m → TermSub T ν m n → Term ν n
var x / σ = lift $ lookup x σ
Λ t / σ = Λ (t / σ ↑tp)
λ' a t / σ = λ' a (t / σ ↑tm)
t [ a ] / σ = (t / σ) [ a ]
s · t / σ = (s / σ) · (t / σ)
ρ a t / σ = ρ a (t / σ ↑tm)
r ⟨⟩ / σ = (r / σ) ⟨⟩
r with' e / σ = (r / σ) with' (e / σ)
Fin′ : ℕ → ℕ → Set
Fin′ _ m = Fin m
varLift : TermLift Fin′
varLift = record { lift = var; _↑tm = VarSubst._↑; _↑tp = Prelude.id }
infixl 8 _/Var_
_/Var_ : ∀ {ν m n} → Term ν m → Sub Fin m n → Term ν n
_/Var_ = TermTermApp._/_ varLift
private
module ExpandSimple {n : ℕ} where
simple : Simple (Term n)
simple = record { var = var; weaken = λ t → t /Var VarSubst.wk }
open Simple simple public
open ExpandSimple using (_↑; simple)
open TermTypeSubst using () renaming (weaken to weakenTp)
termLift : TermLift Term
termLift = record
{ lift = Prelude.id; _↑tm = _↑ ; _↑tp = λ ρ → map weakenTp ρ }
private
module ExpandSubst {ν : ℕ} where
app : Application (Term ν) (Term ν)
app = record { _/_ = TermTermApp._/_ termLift {ν = ν} }
subst : Subst (Term ν)
subst = record
{ simple = simple
; application = app
}
open Subst subst public
open ExpandSubst public hiding (var; simple)
infix 8 _[/_]
-- Shorthand for single-variable term substitutions in terms
_[/_] : ∀ {ν n} → Term ν (suc n) → Term ν n → Term ν n
s [/ t ] = s / sub t
| {
"alphanum_fraction": 0.5603981706,
"avg_line_length": 28.1590909091,
"ext": "agda",
"hexsha": "c67a8e3270d3dbac642f5767daf42baa54cec0d3",
"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/Substitutions/Term.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Substitutions/Term.agda",
"max_line_length": 72,
"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/Substitutions/Term.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 1324,
"size": 3717
} |
{-# OPTIONS --universe-polymorphism #-}
module 13-implicitProofObligations where
module Imports where
module L where
open import Agda.Primitive public
using (Level; _⊔_) renaming (lzero to zero; lsuc to suc)
-- extract from Data.Unit
record ⊤ : Set where
constructor tt
-- extract from Data.Empty
data ⊥ : Set where
⊥-elim : ∀ {w} {Whatever : Set w} → ⊥ → Whatever
⊥-elim ()
-- extract from Function
id : ∀ {a} {A : Set a} → A → A
id x = x
_$_ : ∀ {a b} {A : Set a} {B : A → Set b} →
((x : A) → B x) → ((x : A) → B x)
f $ x = f x
_∘_ : ∀ {a b c}
{A : Set a} {B : A → Set b} {C : {x : A} → B x → Set c} →
(∀ {x} (y : B x) → C y) → (g : (x : A) → B x) →
((x : A) → C (g x))
f ∘ g = λ x → f (g x)
-- extract from Data.Bool
data Bool : Set where
true : Bool
false : Bool
not : Bool → Bool
not true = false
not false = true
T : Bool → Set
T true = ⊤
T false = ⊥
-- extract from Relation.Nullary.Decidable and friends
infix 3 ¬_
¬_ : ∀ {ℓ} → Set ℓ → Set ℓ
¬ P = P → ⊥
data Dec {p} (P : Set p) : Set p where
yes : ( p : P) → Dec P
no : (¬p : ¬ P) → Dec P
⌊_⌋ : ∀ {p} {P : Set p} → Dec P → Bool
⌊ yes _ ⌋ = true
⌊ no _ ⌋ = false
False : ∀ {p} {P : Set p} → Dec P → Set
False Q = T (not ⌊ Q ⌋)
-- extract from Relation.Binary.PropositionalEquality
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
refl : x ≡ x
cong : ∀ {a b} {A : Set a} {B : Set b}
(f : A → B) {x y} → x ≡ y → f x ≡ f y
cong f refl = refl
_≢_ : ∀ {a} {A : Set a} → A → A → Set a
x ≢ y = ¬ x ≡ y
-- extract from Data.Nat
data ℕ : Set where
zero : ℕ
suc : (n : ℕ) → ℕ
{-# BUILTIN NATURAL ℕ #-}
pred : ℕ → ℕ
pred zero = zero
pred (suc n) = n
infixl 6 _+_
_+_ : ℕ → ℕ → ℕ
-- zero + n = n
-- suc m + n = suc (m + n)
zero + n = n
suc m + n = suc (m + n)
_*_ : ℕ → ℕ → ℕ
zero * n = zero
suc m * n = n + m * n
_≟_ : (x y : ℕ) → Dec (x ≡ y)
zero ≟ zero = yes refl
suc m ≟ suc n with m ≟ n
suc m ≟ suc .m | yes refl = yes refl
suc m ≟ suc n | no prf = no (prf ∘ cong pred)
zero ≟ suc n = no λ()
suc m ≟ zero = no λ()
-- extract from Data.Fin
data Fin : ℕ → Set where
zero : {n : ℕ} → Fin (suc n)
suc : {n : ℕ} (i : Fin n) → Fin (suc n)
-- A conversion: toℕ "n" = n.
toℕ : ∀ {n} → Fin n → ℕ
toℕ zero = 0
toℕ (suc i) = suc (toℕ i)
-- extract from Data.Product
record Σ {a b} (A : Set a) (B : A → Set b) : Set (a L.⊔ b) where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
_×_ : ∀ {a b} (A : Set a) (B : Set b) → Set (a L.⊔ b)
A × B = Σ A (λ (_ : A) → B)
-- extract from Data.Nat.DivMod
data DivMod : ℕ → ℕ → Set where
result : {divisor : ℕ} (q : ℕ) (r : Fin divisor) →
DivMod (toℕ r + q * divisor) divisor
data DivMod' (dividend divisor : ℕ) : Set where
result : (q : ℕ) (r : Fin divisor)
(eq : dividend ≡ (toℕ r + q * divisor)) →
DivMod' dividend divisor
postulate
_div_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} → ℕ
_divMod_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} →
DivMod dividend divisor
_divMod'_ : (dividend divisor : ℕ) {≢0 : False (divisor ≟ 0)} →
DivMod' dividend divisor
open Imports
-- Begin of actual example!
postulate
d : ℕ
d≢0 : d ≢ 0
-- d≢0' : d ≢ 0
fromWitnessFalse : ∀ {p} {P : Set p} {Q : Dec P} → ¬ P → False Q
fromWitnessFalse {Q = yes p} ¬P = ⊥-elim $ ¬P p
fromWitnessFalse {Q = no ¬p} ¬P = tt
⋯ : {A : Set} → {{v : A}} → A
⋯ {{v}} = v
_divMod′_ : (dividend divisor : ℕ) {{ ≢0 : divisor ≢ 0 }} → ℕ × ℕ
_divMod′_ a d {{_}} with _divMod_ a d { fromWitnessFalse ⋯ }
._ divMod′ d | (result q r) = q , toℕ r
_div′_ : (dividend divisor : ℕ) {{ ≢0 : divisor ≢ 0 }} → ℕ
_div′_ a b {{_}} with a divMod′ b
a div′ b | (q , _) = q
--Agda can't resolve hiddens
-- test : {d≢0 : False (d ≟ 0)} → ℕ
-- test = 5 div d
-- test2 : {{d≢0 : d ≢ 0}} → ℕ
-- test2 = 5 div′ d
test3 = 5 div 2
test4 = 5 div′ 2
where nz : 2 ≢ 0
nz ()
| {
"alphanum_fraction": 0.4863953768,
"avg_line_length": 23.2011173184,
"ext": "agda",
"hexsha": "4fe89adef8ac13c6ad922e0352f76dcfe40f8d40",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/instance-arguments/13-implicitProofObligations.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/instance-arguments/13-implicitProofObligations.agda",
"max_line_length": 67,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "examples/instance-arguments/13-implicitProofObligations.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 1742,
"size": 4153
} |
------------------------------------------------------------------------------
-- Testing Agda internal term: @Var Nat Args@ when @Args ≠ []@
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --universal-quantified-functions #-}
{-# OPTIONS --without-K #-}
module NonFOLAgdaInternalTermsVarNonEmptyArgumentsTerm where
postulate
D : Set
_≡_ : D → D → Set
-- TODO: 2012-04-29. Are we using Koen's approach in the translation?
postulate f-refl : (f : D → D) → ∀ x → f x ≡ f x
{-# ATP prove f-refl #-}
| {
"alphanum_fraction": 0.4505988024,
"avg_line_length": 35.1578947368,
"ext": "agda",
"hexsha": "5da6fc8b494f7e9d94ea7fc4dcbc3b8544e10d74",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "issues/universal-quantified-functions-option/NonFOLAgdaInternalTermsVarNonEmptyArgumentsTerm.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "issues/universal-quantified-functions-option/NonFOLAgdaInternalTermsVarNonEmptyArgumentsTerm.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "issues/universal-quantified-functions-option/NonFOLAgdaInternalTermsVarNonEmptyArgumentsTerm.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 145,
"size": 668
} |
{-# OPTIONS --cubical --allow-unsolved-metas #-}
open import Agda.Primitive.Cubical
open import Agda.Builtin.Cubical.Path
module _ where
data D (A : Set) : Set where
c : D A
step : ∀ (x : D A) → c ≡ x
data _~_ {A : Set} : (x y : D A) → Set
record _~′_ {A : Set} (x y : D A) : Set where
coinductive
field
force : x ~ y
open _~′_
data _~_ {A} where
c~ : ∀ {x y : D A} → c ~ c
step~ : ∀ {x y} → (p : x ~′ y) → PathP (λ i → step x i ~ step y i) c~ (p .force)
foo : ∀ {A : Set} (x y : D A) → (x ~ y) → Set₁
foo _ _ (step~ _ _) = {!!}
foo _ _ c~ = {!!}
| {
"alphanum_fraction": 0.5077989601,
"avg_line_length": 20.6071428571,
"ext": "agda",
"hexsha": "e09f1d1fa2abe48150d85c33bebe4ed4e71e5908",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue3661.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/Issue3661.agda",
"max_line_length": 82,
"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/Issue3661.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": 245,
"size": 577
} |
{-# OPTIONS --safe --warning=error --without-K --guardedness #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Setoids.Setoids
open import Rings.Definition
open import Rings.Orders.Partial.Definition
open import Rings.Orders.Total.Definition
open import Groups.Definition
open import Groups.Lemmas
open import Fields.Fields
open import Sets.EquivalenceRelations
open import Sequences
open import Setoids.Orders.Partial.Definition
open import Setoids.Orders.Total.Definition
open import Functions.Definition
open import LogicalFormulae
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Numbers.Naturals.Order.Lemmas
open import Semirings.Definition
module Fields.CauchyCompletion.NearlyTotalOrder {m n o : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} {_*_ : A → A → A} {_<_ : Rel {m} {o} A} {pOrder : SetoidPartialOrder S _<_} {R : Ring S _+_ _*_} {pRing : PartiallyOrderedRing R pOrder} (order : TotallyOrderedRing pRing) (F : Field R) where
open Setoid S
open SetoidTotalOrder (TotallyOrderedRing.total order)
open SetoidPartialOrder pOrder
open Equivalence eq
open PartiallyOrderedRing pRing
open Ring R
open Group additiveGroup
open Field F
open import Fields.Orders.Lemmas {F = F} {pRing} (record { oRing = order })
open import Setoids.Orders.Partial.Sequences pOrder
open import Rings.InitialRing R
open import Rings.Orders.Partial.Lemmas pRing
open import Rings.Orders.Total.Lemmas order
open import Rings.Orders.Total.Cauchy order
open import Rings.Orders.Total.AbsoluteValue order
open import Fields.Lemmas F
open import Fields.CauchyCompletion.Definition order F
open import Fields.CauchyCompletion.Setoid order F
open import Fields.CauchyCompletion.Group order F
open import Fields.CauchyCompletion.Addition order F
open import Fields.CauchyCompletion.Approximation order F
open import Fields.CauchyCompletion.Comparison order F
open import Fields.CauchyCompletion.PartiallyOrderedRing order F
open import Fields.Orders.Total.Lemmas {F = F} (record { oRing = order })
makeIncreasingLemma : (a : A) (s : Sequence A) → Sequence A
Sequence.head (makeIncreasingLemma a s) with totality a (Sequence.head s)
... | inl (inl x) = Sequence.head s
... | inl (inr x) = a
... | inr x = a
Sequence.tail (makeIncreasingLemma a s) = makeIncreasingLemma (Sequence.head (makeIncreasingLemma a s)) (Sequence.tail s)
makeIncreasingLemmaIsIncreasing : (a : A) (s : Sequence A) → WeaklyIncreasing (makeIncreasingLemma a s)
makeIncreasingLemmaIsIncreasing a s zero with totality a (Sequence.head s)
makeIncreasingLemmaIsIncreasing a s zero | inl (inl x) with totality (Sequence.head s) (Sequence.head (Sequence.tail s))
makeIncreasingLemmaIsIncreasing a s zero | inl (inl x) | inl (inl y) = inl y
makeIncreasingLemmaIsIncreasing a s zero | inl (inl x) | inl (inr y) = inr reflexive
makeIncreasingLemmaIsIncreasing a s zero | inl (inl x) | inr y = inr reflexive
makeIncreasingLemmaIsIncreasing a s zero | inl (inr x) with totality a (Sequence.head (Sequence.tail s))
... | inl (inl y) = inl y
... | inl (inr y) = inr reflexive
... | inr y = inr reflexive
makeIncreasingLemmaIsIncreasing a s zero | inr x with totality a (Sequence.head (Sequence.tail s))
... | inl (inl y) = inl y
... | inl (inr y) = inr reflexive
... | inr y = inr reflexive
makeIncreasingLemmaIsIncreasing a s (succ m) = makeIncreasingLemmaIsIncreasing (Sequence.head (makeIncreasingLemma a s)) (Sequence.tail s) m
makeIncreasing : Sequence A → Sequence A
Sequence.head (makeIncreasing x) = Sequence.head x
Sequence.tail (makeIncreasing x) = makeIncreasingLemma (Sequence.head x) (Sequence.tail x)
makeIncreasingIsIncreasing : (a : Sequence A) → WeaklyIncreasing (makeIncreasing a)
makeIncreasingIsIncreasing a zero with totality (Sequence.head a) (Sequence.head (Sequence.tail a))
... | inl (inl x) = inl x
... | inl (inr x) = inr reflexive
... | inr x = inr reflexive
makeIncreasingIsIncreasing a (succ m) = makeIncreasingLemmaIsIncreasing _ _ m
approximateIncreasingSeqRaw : CauchyCompletion → Sequence A
approximateIncreasingSeqRaw a = funcToSequence f
where
f : ℕ → A
f n with allInvertible (fromN (succ n)) λ n=0 → irreflexive (<WellDefined reflexive n=0 (fromNPreservesOrder (0<1 nontrivial) (succIsPositive n)))
... | 1/n , prN = underlying (approximateBelow a 1/n (reciprocalPositive' (fromN (succ n)) 1/n (fromNPreservesOrder (0<1 nontrivial) (succIsPositive n)) prN))
approximateIncreasingSeq : CauchyCompletion → Sequence A
approximateIncreasingSeq a = makeIncreasing (approximateIncreasingSeqRaw a)
approximateIncreasingConverges : (a : CauchyCompletion) → cauchy (approximateIncreasingSeq a)
approximateIncreasingConverges a e 0<e = {!!}
approximateIncreasingIncreases : (a : CauchyCompletion) → WeaklyIncreasing (approximateIncreasingSeq a)
approximateIncreasingIncreases a = makeIncreasingIsIncreasing (approximateIncreasingSeqRaw a)
approximateIncreasing : CauchyCompletion → CauchyCompletion
approximateIncreasing a = record { elts = approximateIncreasingSeq a ; converges = approximateIncreasingConverges a }
approximateIncreasingEqual : (a : CauchyCompletion) → Setoid._∼_ cauchyCompletionSetoid (approximateIncreasing a) a
approximateIncreasingEqual a e 0<e = {!!}
decideSign : (a : CauchyCompletion) → (Setoid._∼_ cauchyCompletionSetoid a (injection 0R) → False) → (a <Cr 0R) || (0R r<C a)
decideSign a a!=0 = {!!}
where
private
lemma : (a b : CauchyCompletion) → Setoid._∼_ cauchyCompletionSetoid ((b +C (-C a)) +C a) b
lemma a b = Equivalence.transitive (Setoid.eq cauchyCompletionSetoid) {record { converges = CauchyCompletion.converges ((b +C (-C a)) +C a) }} {record { converges = CauchyCompletion.converges (b +C ((-C a) +C a)) }} {record { converges = CauchyCompletion.converges b }} (Group.+Associative' CGroup {record { converges = CauchyCompletion.converges b }} {record { converges = CauchyCompletion.converges (-C a) }} { record { converges = CauchyCompletion.converges a }}) (Equivalence.transitive (Setoid.eq cauchyCompletionSetoid) {record {converges = CauchyCompletion.converges (b +C ((-C a) +C a))}} {record { converges = CauchyCompletion.converges (b +C (injection 0R))}} {record {converges = CauchyCompletion.converges b}} (Group.+WellDefinedRight CGroup {record {converges = CauchyCompletion.converges b}} {record {converges = CauchyCompletion.converges ((-C a) +C a)}} {record { converges = CauchyCompletion.converges (injection 0R)}} (Group.invLeft CGroup {record { converges = CauchyCompletion.converges a }})) (Group.identRight CGroup {record { converges = CauchyCompletion.converges b }}))
nearlyTotal : (a b : CauchyCompletion) → (Setoid._∼_ cauchyCompletionSetoid a b → False) → (a <C b) || (b <C a)
nearlyTotal a b a!=b with decideSign (b +C (-C a)) λ bad → a!=b (Equivalence.symmetric (Setoid.eq cauchyCompletionSetoid) {record { converges = CauchyCompletion.converges b }} {record { converges = CauchyCompletion.converges a }} (transferToRight CGroup {record { converges = CauchyCompletion.converges b }} {record { converges = CauchyCompletion.converges a }} bad))
... | inl x = inr (<CWellDefined (lemma a b) (Group.identLeft CGroup {record { converges = CauchyCompletion.converges a }}) (PartiallyOrderedRing.orderRespectsAddition CpOrderedRing (<CRelaxR x) a))
... | inr x = inl (<CWellDefined (Group.identLeft CGroup {record { converges = CauchyCompletion.converges a }}) (lemma a b) (PartiallyOrderedRing.orderRespectsAddition CpOrderedRing (<CRelaxL x) a))
| {
"alphanum_fraction": 0.7620320856,
"avg_line_length": 63.3898305085,
"ext": "agda",
"hexsha": "43c6a8120de9a59139c5a587abfd3558888470cb",
"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": "Fields/CauchyCompletion/NearlyTotalOrder.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": "Fields/CauchyCompletion/NearlyTotalOrder.agda",
"max_line_length": 1096,
"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": "Fields/CauchyCompletion/NearlyTotalOrder.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": 2184,
"size": 7480
} |
------------------------------------------------------------------------
-- Identity and composition for higher lenses
------------------------------------------------------------------------
{-# OPTIONS --cubical #-}
import Equality.Path as P
module Lens.Non-dependent.Higher.Combinators
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
import Bi-invertibility
open import Logical-equivalence using (_⇔_)
open import Prelude as P hiding (id) renaming (_∘_ to _⊚_)
open import Bijection equality-with-J as Bij using (_↔_)
open import Category equality-with-J as C using (Category; Precategory)
import Circle eq as Circle
open import Equality.Path.Isomorphisms eq
open import Equivalence equality-with-J as Eq
using (_≃_; Is-equivalence)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J as H-level
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as Trunc
open import Surjection equality-with-J using (_↠_)
open import Univalence-axiom equality-with-J
open import Lens.Non-dependent.Higher eq
import Lens.Non-dependent.Traditional eq as Traditional
open import Lens.Non-dependent.Traditional.Combinators eq as TC
using (Naive-category; Univalent)
private
variable
a b c d : Level
A B C : Type a
------------------------------------------------------------------------
-- Lens combinators
-- The definition of the identity lens is unique, if the get
-- function is required to be the identity (assuming univalence).
id-unique :
{A : Type a} →
Univalence a →
(l₁ l₂ : Lens A A) →
Lens.get l₁ ≡ P.id →
Lens.get l₂ ≡ P.id →
l₁ ≡ l₂
id-unique {A = A} univ l₁ l₂ get-l₁≡id get-l₂≡id = $⟨ trans get-l₁≡id (sym get-l₂≡id) ⟩
_≃_.to (_≃_.from f l₁′) ≡ _≃_.to (_≃_.from f l₂′) ↝⟨ Eq.lift-equality ext ⟩
_≃_.from f l₁′ ≡ _≃_.from f l₂′ ↝⟨ _≃_.to $ Eq.≃-≡ (inverse f) {x = l₁′} {y = l₂′} ⟩
l₁′ ≡ l₂′ ↝⟨ cong proj₁ ⟩□
l₁ ≡ l₂ □
where
open Lens
f : (A ≃ A) ≃ (∃ λ (l : Lens A A) → Is-equivalence (Lens.get l))
f = ≃-≃-Σ-Lens-Is-equivalence-get univ
is-equiv :
(l : Lens A A) →
get l ≡ P.id → Is-equivalence (get l)
is-equiv _ get≡id =
Eq.respects-extensional-equality
(ext⁻¹ $ sym get≡id)
(_≃_.is-equivalence Eq.id)
l₁′ l₂′ : ∃ λ (l : Lens A A) → Is-equivalence (Lens.get l)
l₁′ = l₁ , is-equiv l₁ get-l₁≡id
l₂′ = l₂ , is-equiv l₂ get-l₂≡id
-- The result of composing two lenses is unique if the codomain type
-- is inhabited whenever it is merely inhabited, and we require that
-- the resulting setter function is defined in a certain way
-- (assuming univalence).
∘-unique :
let open Lens in
{A : Type a} {C : Type c} →
Univalence (a ⊔ c) →
(∥ C ∥ → C) →
((comp₁ , _) (comp₂ , _) :
∃ λ (comp : Lens B C → Lens A B → Lens A C) →
∀ l₁ l₂ a c →
set (comp l₁ l₂) a c ≡ set l₂ a (set l₁ (get l₂ a) c)) →
comp₁ ≡ comp₂
∘-unique {A = A} {C = C} univ ∥C∥→C
(comp₁ , set₁) (comp₂ , set₂) =
⟨ext⟩ λ l₁ → ⟨ext⟩ λ l₂ →
lenses-equal-if-setters-equal univ
(comp₁ l₁ l₂) (comp₂ l₁ l₂) (λ _ → ∥C∥→C) $
⟨ext⟩ λ a → ⟨ext⟩ λ c →
set (comp₁ l₁ l₂) a c ≡⟨ set₁ _ _ _ _ ⟩
set l₂ a (set l₁ (get l₂ a) c) ≡⟨ sym $ set₂ _ _ _ _ ⟩∎
set (comp₂ l₁ l₂) a c ∎
where
open Lens
-- Identity lens.
id : Block "id" → Lens A A
id {A = A} ⊠ = record
{ R = ∥ A ∥
; equiv = A ↔⟨ inverse ∥∥×↔ ⟩□
∥ A ∥ × A □
; inhabited = P.id
}
-- Composition of lenses.
--
-- Note that the domains are required to be at least as large as the
-- codomains; this should match many use-cases. Without this
-- restriction I failed to find a satisfactory definition of
-- composition. (I suspect that if Agda had had cumulativity, then
-- the domain and codomain could have lived in the same universe
-- without any problems.)
--
-- The composition operation matches on the lenses to ensure that it
-- does not unfold when applied to neutral lenses.
--
-- See also Lens.Non-dependent.Equivalent-preimages.⟨_⟩_⊚_.
infix 9 ⟨_,_⟩_∘_
⟨_,_⟩_∘_ :
∀ a b {A : Type (a ⊔ b ⊔ c)} {B : Type (b ⊔ c)} {C : Type c} →
Lens B C → Lens A B → Lens A C
⟨_,_⟩_∘_ _ _ {A = A} {B} {C} l₁@(⟨ _ , _ , _ ⟩) l₂@(⟨ _ , _ , _ ⟩) =
record
{ R = R l₂ × R l₁
; equiv = A ↝⟨ equiv l₂ ⟩
R l₂ × B ↝⟨ F.id ×-cong equiv l₁ ⟩
R l₂ × (R l₁ × C) ↔⟨ ×-assoc ⟩□
(R l₂ × R l₁) × C □
; inhabited = ∥∥-map (get l₁) ⊚ inhabited l₂ ⊚ proj₁
}
where
open Lens
-- The composition operation implements set in a certain way.
∘-set :
let open Lens in
∀ ℓa ℓb {A : Type (ℓa ⊔ ℓb ⊔ c)} {B : Type (ℓb ⊔ c)} {C : Type c}
(l₁ : Lens B C) (l₂ : Lens A B) a c →
set (⟨ ℓa , ℓb ⟩ l₁ ∘ l₂) a c ≡ set l₂ a (set l₁ (get l₂ a) c)
∘-set _ _ ⟨ _ , _ , _ ⟩ ⟨ _ , _ , _ ⟩ _ _ = refl _
-- A variant of composition for lenses between types with the same
-- universe level.
infixr 9 _∘_
_∘_ :
{A B C : Type a} →
Lens B C → Lens A B → Lens A C
l₁ ∘ l₂ = ⟨ lzero , lzero ⟩ l₁ ∘ l₂
-- Other definitions of composition match ⟨_,_⟩_∘_, if the codomain
-- type is inhabited whenever it is merely inhabited, and the
-- resulting setter function is defined in a certain way (assuming
-- univalence).
composition≡∘ :
let open Lens in
∀ a b {A : Type (a ⊔ b ⊔ c)} {B : Type (b ⊔ c)} {C : Type c} →
Univalence (a ⊔ b ⊔ c) →
(∥ C ∥ → C) →
(comp : Lens B C → Lens A B → Lens A C) →
(∀ l₁ l₂ a c →
set (comp l₁ l₂) a c ≡ set l₂ a (set l₁ (get l₂ a) c)) →
comp ≡ ⟨ a , b ⟩_∘_
composition≡∘ _ _ univ ∥C∥→C comp set-comp =
∘-unique univ ∥C∥→C (comp , set-comp)
(_ , λ { ⟨ _ , _ , _ ⟩ ⟨ _ , _ , _ ⟩ _ _ → refl _ })
-- Identity and composition form a kind of precategory (assuming
-- univalence).
associativity :
∀ a b c
{A : Type (a ⊔ b ⊔ c ⊔ d)} {B : Type (b ⊔ c ⊔ d)}
{C : Type (c ⊔ d)} {D : Type d} →
Univalence (a ⊔ b ⊔ c ⊔ d) →
(l₁ : Lens C D) (l₂ : Lens B C) (l₃ : Lens A B) →
⟨ a ⊔ b , c ⟩ l₁ ∘ (⟨ a , b ⟩ l₂ ∘ l₃) ≡
⟨ a , b ⊔ c ⟩ (⟨ b , c ⟩ l₁ ∘ l₂) ∘ l₃
associativity _ _ _ univ ⟨ _ , _ , _ ⟩ ⟨ _ , _ , _ ⟩ ⟨ _ , _ , _ ⟩ =
_↔_.from (equality-characterisation₁ ⊠ univ)
(Eq.↔⇒≃ (inverse ×-assoc) , λ _ → refl _)
left-identity :
∀ bi a {A : Type (a ⊔ b)} {B : Type b} →
Univalence (a ⊔ b) →
(l : Lens A B) →
⟨ a , lzero ⟩ id bi ∘ l ≡ l
left-identity ⊠ _ {B = B} univ l@(⟨ _ , _ , _ ⟩) =
_↔_.from (equality-characterisation₁ ⊠ univ)
( (R × ∥ B ∥ ↔⟨ lemma ⟩□
R □)
, λ _ → refl _
)
where
open Lens l
lemma : R × ∥ B ∥ ↔ R
lemma = record
{ surjection = record
{ logical-equivalence = record
{ to = proj₁
; from = λ r → r , inhabited r
}
; right-inverse-of = refl
}
; left-inverse-of = λ { (r , _) →
cong (λ x → r , x) $ truncation-is-proposition _ _ }
}
right-identity :
∀ bi a {A : Type (a ⊔ b)} {B : Type b} →
Univalence (a ⊔ b) →
(l : Lens A B) →
⟨ lzero , a ⟩ l ∘ id bi ≡ l
right-identity ⊠ _ {A = A} univ l@(⟨ _ , _ , _ ⟩) =
_↔_.from (equality-characterisation₁ ⊠ univ)
( (∥ A ∥ × R ↔⟨ lemma ⟩□
R □)
, λ _ → refl _
)
where
open Lens l
lemma : ∥ A ∥ × R ↔ R
lemma = record
{ surjection = record
{ logical-equivalence = record
{ to = proj₂
; from = λ r → ∥∥-map (λ b → _≃_.from equiv (r , b))
(inhabited r)
, r
}
; right-inverse-of = refl
}
; left-inverse-of = λ { (_ , r) →
cong (λ x → x , r) $ truncation-is-proposition _ _ }
}
------------------------------------------------------------------------
-- Isomorphisms expressed using lens quasi-inverses
private
module B {a} (b : Block "id") =
Bi-invertibility equality-with-J (Type a) Lens (id b) _∘_
module BM {a} (b : Block "id") (univ : Univalence a) = B.More
b
(left-identity b _ univ)
(right-identity b _ univ)
(associativity _ _ _ univ)
-- A form of isomorphism between types, expressed using lenses.
open B public
using ()
renaming (_≅_ to [_]_≅_;
Has-quasi-inverse to Has-quasi-inverse)
-- Lenses with quasi-inverses can be converted to equivalences.
≅→≃ : ∀ b → [ b ] A ≅ B → A ≃ B
≅→≃
⊠
(l@(⟨ _ , _ , _ ⟩) , l⁻¹@(⟨ _ , _ , _ ⟩) , l∘l⁻¹≡id , l⁻¹∘l≡id) =
Eq.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = get l
; from = get l⁻¹
}
; right-inverse-of = λ b → cong (λ l → get l b) l∘l⁻¹≡id
}
; left-inverse-of = λ a → cong (λ l → get l a) l⁻¹∘l≡id
})
where
open Lens
-- There is a split surjection from [ b ] A ≅ B to A ≃ B (assuming
-- univalence).
≅↠≃ :
{A B : Type a}
(b : Block "id") →
Univalence a →
([ b ] A ≅ B) ↠ (A ≃ B)
≅↠≃ {A = A} {B = B} b univ = record
{ logical-equivalence = record
{ to = ≅→≃ b
; from = from b
}
; right-inverse-of = ≅→≃∘from b
}
where
from : ∀ b → A ≃ B → [ b ] A ≅ B
from b A≃B = l , l⁻¹ , l∘l⁻¹≡id b , l⁻¹∘l≡id b
where
l = ≃→lens′ A≃B
l⁻¹ = ≃→lens′ (inverse A≃B)
l∘l⁻¹≡id : ∀ b → l ∘ l⁻¹ ≡ id b
l∘l⁻¹≡id ⊠ = _↔_.from (equality-characterisation₁ ⊠ univ)
( (∥ A ∥ × ∥ B ∥ ↝⟨ Eq.⇔→≃
(×-closure 1 truncation-is-proposition
truncation-is-proposition)
truncation-is-proposition
proj₂
(λ b → ∥∥-map (_≃_.from A≃B) b , b) ⟩
∥ B ∥ □)
, λ _ → cong₂ _,_
(truncation-is-proposition _ _)
(_≃_.right-inverse-of A≃B _)
)
l⁻¹∘l≡id : ∀ b → l⁻¹ ∘ l ≡ id b
l⁻¹∘l≡id ⊠ = _↔_.from (equality-characterisation₁ ⊠ univ)
( (∥ B ∥ × ∥ A ∥ ↝⟨ Eq.⇔→≃
(×-closure 1 truncation-is-proposition
truncation-is-proposition)
truncation-is-proposition
proj₂
(λ a → ∥∥-map (_≃_.to A≃B) a , a) ⟩
∥ A ∥ □)
, λ _ → cong₂ _,_
(truncation-is-proposition _ _)
(_≃_.left-inverse-of A≃B _)
)
≅→≃∘from : ∀ b A≃B → ≅→≃ b (from b A≃B) ≡ A≃B
≅→≃∘from ⊠ _ = Eq.lift-equality ext (refl _)
-- There is not necessarily a split surjection from
-- Is-equivalence (Lens.get l) to Has-quasi-inverse l, if l is a
-- lens between types in the same universe (assuming univalence).
¬Is-equivalence-get↠Has-quasi-inverse :
(b : Block "id") →
Univalence a →
¬ ({A B : Type a}
(l : Lens A B) →
Is-equivalence (Lens.get l) ↠ Has-quasi-inverse b l)
¬Is-equivalence-get↠Has-quasi-inverse b univ surj =
$⟨ ⊤-contractible ⟩
Contractible ⊤ ↝⟨ H-level.respects-surjection lemma₃ 0 ⟩
Contractible ((z : Z) → z ≡ z) ↝⟨ mono₁ 0 ⟩
Is-proposition ((z : Z) → z ≡ z) ↝⟨ ¬-prop ⟩□
⊥ □
where
open Lens
Z,¬-prop = Circle.¬-type-of-refl-propositional
Z = proj₁ Z,¬-prop
¬-prop = proj₂ Z,¬-prop
lemma₂ :
∀ b →
(∃ λ (eq : R (id b) ≃ R (id b)) →
(∀ z → _≃_.to eq (remainder (id b) z) ≡ remainder (id b) z)
×
((z : Z) → get (id b) z ≡ get (id b) z)) ≃
((z : Z) → z ≡ z)
lemma₂ ⊠ =
(∃ λ (eq : ∥ Z ∥ ≃ ∥ Z ∥) →
((z : Z) → _≃_.to eq ∣ z ∣ ≡ ∣ z ∣)
×
((z : Z) → z ≡ z)) ↔⟨ (∃-cong λ _ → drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $
Π-closure ext 0 λ _ →
+⇒≡ truncation-is-proposition) ⟩
(∥ Z ∥ ≃ ∥ Z ∥) × ((z : Z) → z ≡ z) ↔⟨ drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(Eq.left-closure ext 0 truncation-is-proposition)
F.id ⟩□
((z : Z) → z ≡ z) □
lemma₃ =
⊤ ↔⟨ inverse $ _⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(Eq.propositional ext _)
(_≃_.is-equivalence Eq.id) ⟩
Is-equivalence P.id ↔⟨ ≡⇒↝ equivalence $ cong Is-equivalence $
unblock b (λ b → _ ≡ get (id b)) (refl _) ⟩
Is-equivalence (get (id b)) ↝⟨ surj (id b) ⟩
Has-quasi-inverse b (id b) ↔⟨ BM.Has-quasi-inverse≃id≡id-domain b univ
(id b , left-identity b _ univ _ , right-identity b _ univ _) ⟩
id b ≡ id b ↔⟨ equality-characterisation₂ ⊠ univ ⟩
(∃ λ (eq : R (id b) ≃ R (id b)) →
(∀ z → _≃_.to eq (remainder (id b) z) ≡ remainder (id b) z)
×
(∀ z → get (id b) z ≡ get (id b) z)) ↔⟨ lemma₂ b ⟩□
((z : Z) → z ≡ z) □
-- See also ≃≃≅ below.
------------------------------------------------------------------------
-- Equivalences expressed using bi-invertibility for lenses
-- A form of equivalence between types, expressed using lenses.
open B public
using ()
renaming (_≊_ to [_]_≊_;
Has-left-inverse to Has-left-inverse;
Has-right-inverse to Has-right-inverse;
Is-bi-invertible to Is-bi-invertible)
open BM public
using ()
renaming (equality-characterisation-≊ to equality-characterisation-≊)
-- Lenses with left inverses have propositional remainder types.
has-left-inverse→remainder-propositional :
(b : Block "id")
(l : Lens A B) →
Has-left-inverse b l →
Is-proposition (Lens.R l)
has-left-inverse→remainder-propositional
⊠ l@(⟨ _ , _ , _ ⟩) (l⁻¹@(⟨ _ , _ , _ ⟩) , l⁻¹∘l≡id) =
$⟨ get≡id→remainder-propositional
(l⁻¹ ∘ l)
(λ a → cong (flip get a) l⁻¹∘l≡id) ⟩
Is-proposition (R (l⁻¹ ∘ l)) ↔⟨⟩
Is-proposition (R l × R l⁻¹) ↝⟨ H-level-×₁ (∥∥-map (remainder l⁻¹) ⊚ inhabited l) 1 ⟩□
Is-proposition (R l) □
where
open Lens
-- Lenses with right inverses have propositional remainder types.
has-right-inverse→remainder-propositional :
(b : Block "id")
(l : Lens A B) →
Has-right-inverse b l →
Is-proposition (Lens.R l)
has-right-inverse→remainder-propositional
⊠ l@(⟨ _ , _ , _ ⟩) (l⁻¹@(⟨ _ , _ , _ ⟩) , l∘l⁻¹≡id) =
$⟨ get≡id→remainder-propositional
(l ∘ l⁻¹)
(λ a → cong (flip get a) l∘l⁻¹≡id) ⟩
Is-proposition (R (l ∘ l⁻¹)) ↔⟨⟩
Is-proposition (R l⁻¹ × R l) ↝⟨ H-level-×₂ (∥∥-map (remainder l⁻¹) ⊚ inhabited l) 1 ⟩□
Is-proposition (R l) □
where
open Lens
-- There is an equivalence between A ≃ B and [ b ] A ≊ B (assuming
-- univalence).
≃≃≊ :
{A B : Type a}
(b : Block "id") →
Univalence a →
(A ≃ B) ≃ ([ b ] A ≊ B)
≃≃≊ {A = A} {B = B} b univ = Eq.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = to b
; from = from b
}
; right-inverse-of = to∘from b
}
; left-inverse-of = from∘to b
})
where
open Lens
to : ∀ b → A ≃ B → [ b ] A ≊ B
to b = B.≅→≊ b ⊚ _↠_.from (≅↠≃ b univ)
from : ∀ b → [ b ] A ≊ B → A ≃ B
from b = _↠_.to (≅↠≃ b univ) ⊚ _↠_.from (BM.≅↠≊ b univ)
to∘from : ∀ b A≊B → to b (from b A≊B) ≡ A≊B
to∘from b A≊B =
_≃_.from (equality-characterisation-≊ b univ _ _) $
_↔_.from (equality-characterisation₂ b univ)
( ∥B∥≃R b A≊B
, lemma₁ b A≊B
, lemma₂ b A≊B
)
where
l′ : ∀ b (A≊B : [ b ] A ≊ B) → Lens A B
l′ b A≊B = proj₁ (to b (from b A≊B))
∥B∥≃R : ∀ b (A≊B@(l , _) : [ b ] A ≊ B) → ∥ B ∥ ≃ R l
∥B∥≃R b (l , (l-inv@(l⁻¹ , _) , _)) = Eq.⇔→≃
truncation-is-proposition
R-prop
(Trunc.rec R-prop (remainder l ⊚ get l⁻¹))
(inhabited l)
where
R-prop = has-left-inverse→remainder-propositional b l l-inv
lemma₁ :
∀ b (A≊B@(l , _) : [ b ] A ≊ B) a →
_≃_.to (∥B∥≃R b A≊B) (remainder (l′ b A≊B) a) ≡ remainder l a
lemma₁
⊠
( l@(⟨ _ , _ , _ ⟩)
, (l⁻¹@(⟨ _ , _ , _ ⟩) , l⁻¹∘l≡id)
, (⟨ _ , _ , _ ⟩ , _)
) a =
remainder l (get l⁻¹ (get l a)) ≡⟨⟩
remainder l (get (l⁻¹ ∘ l) a) ≡⟨ cong (λ l′ → remainder l (get l′ a)) l⁻¹∘l≡id ⟩
remainder l (get (id ⊠) a) ≡⟨⟩
remainder l a ∎
lemma₂ :
∀ b (A≊B@(l , _) : [ b ] A ≊ B) a →
get (l′ b A≊B) a ≡ get l a
lemma₂ ⊠
(⟨ _ , _ , _ ⟩ , (⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) _ =
refl _
from∘to :
∀ b A≃B →
_↠_.to (≅↠≃ b univ) (_↠_.from (BM.≅↠≊ b univ)
(B.≅→≊ b (_↠_.from (≅↠≃ b univ) A≃B))) ≡
A≃B
from∘to ⊠ _ = Eq.lift-equality ext (refl _)
-- The right-to-left direction of ≃≃≊ maps bi-invertible lenses to
-- their getter functions.
to-from-≃≃≊≡get :
(b : Block "id")
(univ : Univalence a)
(A≊B@(l , _) : [ b ] A ≊ B) →
_≃_.to (_≃_.from (≃≃≊ b univ) A≊B) ≡ Lens.get l
to-from-≃≃≊≡get
⊠ _ (⟨ _ , _ , _ ⟩ , (⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) =
refl _
-- A variant of ≃≃≊ that works even if A and B live in different
-- universes.
--
-- This variant came up in a discussion with Andrea Vezzosi.
≃≃≊′ :
{A : Type a} {B : Type b}
(b-id : Block "id") →
Univalence (a ⊔ b) →
(A ≃ B) ≃ ([ b-id ] ↑ b A ≊ ↑ a B)
≃≃≊′ {a = a} {b = b} {A = A} {B = B} b-id univ =
A ≃ B ↔⟨ inverse $ Eq.≃-preserves-bijections ext Bij.↑↔ Bij.↑↔ ⟩
↑ b A ≃ ↑ a B ↝⟨ ≃≃≊ b-id univ ⟩□
[ b-id ] ↑ b A ≊ ↑ a B □
-- The right-to-left direction of ≃≃≊′ maps bi-invertible lenses to a
-- variant of their getter functions.
to-from-≃≃≊′≡get :
{A : Type a} {B : Type b}
(b-id : Block "id")
(univ : Univalence (a ⊔ b)) →
(A≊B@(l , _) : [ b-id ] ↑ b A ≊ ↑ a B) →
_≃_.to (_≃_.from (≃≃≊′ b-id univ) A≊B) ≡ lower ⊚ Lens.get l ⊚ lift
to-from-≃≃≊′≡get
⊠ _ (⟨ _ , _ , _ ⟩ , (⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) =
refl _
-- The getter function of a bi-invertible lens is an equivalence
-- (assuming univalence).
Is-bi-invertible→Is-equivalence-get :
{A : Type a}
(b : Block "id") →
Univalence a →
(l : Lens A B) →
Is-bi-invertible b l → Is-equivalence (Lens.get l)
Is-bi-invertible→Is-equivalence-get
b@⊠ univ l@(⟨ _ , _ , _ ⟩)
is-bi-inv@((⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) =
_≃_.is-equivalence (_≃_.from (≃≃≊ b univ) (l , is-bi-inv))
-- If l is a lens between types in the same universe, then there is an
-- equivalence between "l is bi-invertible" and "the getter of l is an
-- equivalence" (assuming univalence).
Is-bi-invertible≃Is-equivalence-get :
{A B : Type a}
(b : Block "id") →
Univalence a →
(l : Lens A B) →
Is-bi-invertible b l ≃ Is-equivalence (Lens.get l)
Is-bi-invertible≃Is-equivalence-get b univ l = Eq.⇔→≃
(BM.Is-bi-invertible-propositional b univ l)
(Eq.propositional ext _)
(Is-bi-invertible→Is-equivalence-get b univ l)
(λ is-equiv →
let l′ = ≃→lens′ Eq.⟨ get l , is-equiv ⟩ in
$⟨ proj₂ (_≃_.to (≃≃≊ b univ) Eq.⟨ _ , is-equiv ⟩) ⟩
Is-bi-invertible b l′ ↝⟨ subst (Is-bi-invertible b) (sym $ get-equivalence→≡≃→lens′ univ l is-equiv) ⟩□
Is-bi-invertible b l □)
where
open Lens
-- If A is a set, then there is an equivalence between [ b ] A ≊ B and
-- [ b ] A ≅ B (assuming univalence).
≊≃≅ :
{A B : Type a}
(b : Block "id") →
Univalence a →
Is-set A →
([ b ] A ≊ B) ≃ ([ b ] A ≅ B)
≊≃≅ b univ A-set =
∃-cong λ _ →
BM.Is-bi-invertible≃Has-quasi-inverse-domain
b univ
(Is-set-closed-domain univ A-set)
------------------------------------------------------------------------
-- A category
-- If A is a set, then there is an equivalence between A ≃ B and
-- [ b ] A ≅ B (assuming univalence).
≃≃≅ :
{A B : Type a}
(b : Block "≃≃≅") →
Univalence a →
Is-set A →
(A ≃ B) ≃ ([ b ] A ≅ B)
≃≃≅ {A = A} {B = B} b@⊠ univ A-set =
A ≃ B ↝⟨ ≃≃≊ b univ ⟩
[ b ] A ≊ B ↝⟨ ≊≃≅ b univ A-set ⟩□
[ b ] A ≅ B □
-- The equivalence ≃≃≅ maps identity to identity.
≃≃≅-id≡id :
{A : Type a}
(b : Block "≃≃≅") (univ : Univalence a) (A-set : Is-set A) →
proj₁ (_≃_.to (≃≃≅ b univ A-set) F.id) ≡ id b
≃≃≅-id≡id ⊠ univ _ =
_↔_.from (equality-characterisation₁ ⊠ univ)
(F.id , λ _ → refl _)
-- Lenses between sets in the same universe form a precategory
-- (assuming univalence).
private
precategory′ :
Block "id" →
Univalence a →
C.Precategory′ (lsuc a) (lsuc a)
precategory′ {a = a} b univ =
Set a
, (λ (A , A-set) (B , _) →
Lens A B
, Is-set-closed-domain univ A-set)
, id b
, _∘_
, left-identity b lzero univ _
, right-identity b lzero univ _
, (λ {_ _ _ _ l₁ l₂ l₃} →
associativity lzero lzero lzero univ l₃ l₂ l₁)
precategory :
Block "precategory" →
Univalence a →
Precategory (lsuc a) (lsuc a)
precategory ⊠ univ .C.Precategory.precategory =
block λ b → precategory′ b univ
-- Lenses between sets in the same universe form a category
-- (assuming univalence).
category :
Block "category" →
Univalence a →
Category (lsuc a) (lsuc a)
category ⊠ univ =
block λ b →
C.precategory-with-Set-to-category
ext
(λ _ _ → univ)
(proj₂ $ precategory′ b univ)
(λ (_ , A-set) _ → ≃≃≅ b univ A-set)
(λ (_ , A-set) → ≃≃≅-id≡id b univ A-set)
-- The precategory defined here is equal to the one defined in
-- Traditional, if the latter one is lifted (assuming univalence).
precategory≡precategory :
(b : Block "precategory") →
Univalence (lsuc a) →
(univ : Univalence a) →
precategory b univ ≡
C.lift-precategory-Hom _ TC.precategory
precategory≡precategory ⊠ univ⁺ univ =
block λ b →
_↔_.to (C.equality-characterisation-Precategory ext univ⁺ univ⁺)
( F.id
, (λ (X , X-set) (Y , _) →
Lens X Y ↔⟨ Lens↔Traditional-lens b univ X-set ⟩
Traditional.Lens X Y ↔⟨ inverse Bij.↑↔ ⟩□
↑ _ (Traditional.Lens X Y) □)
, (λ (_ , X-set) → cong lift $ _↔_.from
(Traditional.equality-characterisation-for-sets X-set)
(refl _))
, (λ (_ , X-set) (_ , Y-set) _ (lift l₁) (lift l₂) →
cong lift (∘-lemma b X-set Y-set l₁ l₂))
)
where
∘-lemma :
∀ b (A-set : Is-set A) (B-set : Is-set B)
(l₁ : Traditional.Lens B C) (l₂ : Traditional.Lens A B) →
Lens.traditional-lens
(_↠_.from (Lens↠Traditional-lens b B-set) l₁ ∘
_↠_.from (Lens↠Traditional-lens b A-set) l₂) ≡
l₁ TC.∘ l₂
∘-lemma ⊠ A-set _ _ _ =
_↔_.from (Traditional.equality-characterisation-for-sets A-set)
(refl _)
-- The category defined here is equal to the one defined in
-- Traditional, if the latter one is lifted (assuming univalence).
category≡category :
(b : Block "category") →
Univalence (lsuc a) →
(univ : Univalence a) →
category b univ ≡
C.lift-category-Hom _ (TC.category univ)
category≡category b univ⁺ univ =
_↔_.from (C.≡↔precategory≡precategory ext)
(Category.precategory (category b univ) ≡⟨ lemma b ⟩
precategory b univ ≡⟨ precategory≡precategory b univ⁺ univ ⟩∎
Category.precategory
(C.lift-category-Hom _ (TC.category univ)) ∎)
where
lemma :
∀ b →
Category.precategory (category b univ) ≡
precategory b univ
lemma ⊠ = refl _
-- Types in a fixed universe and higher lenses between them form a
-- naive category (assuming univalence).
naive-category :
Block "id" →
Univalence a →
Naive-category (lsuc a) (lsuc a)
naive-category {a = a} b univ =
Type a
, Lens
, id b
, _∘_
, left-identity b lzero univ
, right-identity b lzero univ
, associativity lzero lzero lzero univ
-- This category is univalent.
--
-- An anonymous reviewer asked if something like this could be proved,
-- given ≃≃≊. The proof of this result is due to Andrea Vezzosi.
univalent :
(b : Block "id")
(univ : Univalence a) →
Univalent (naive-category b univ)
univalent b univ =
BM.≡≃≊→Univalence-≊ b univ λ {A B} →
A ≡ B ↝⟨ ≡≃≃ univ ⟩
A ≃ B ↝⟨ ≃≃≊ b univ ⟩□
[ b ] A ≊ B □
| {
"alphanum_fraction": 0.4999600511,
"avg_line_length": 31.5662042875,
"ext": "agda",
"hexsha": "89bc669948aa7a089a907cdcbe8358a07b943e19",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-07-01T14:33:26.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-07-01T14:33:26.000Z",
"max_forks_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/dependent-lenses",
"max_forks_repo_path": "src/Lens/Non-dependent/Higher/Combinators.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"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/dependent-lenses",
"max_issues_repo_path": "src/Lens/Non-dependent/Higher/Combinators.agda",
"max_line_length": 136,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "f2da6f7e95b87ca525e8ea43929c6d6163a74811",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/dependent-lenses",
"max_stars_repo_path": "src/Lens/Non-dependent/Higher/Combinators.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:55:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T12:10:46.000Z",
"num_tokens": 9466,
"size": 25032
} |
------------------------------------------------------------------------------
-- Common stuff used by the gcd example
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Program.GCD.Partial.Definitions where
open import LTC-PCF.Base
open import LTC-PCF.Data.Nat.Divisibility.NotBy0
open import LTC-PCF.Data.Nat.Inequalities
open import LTC-PCF.Data.Nat.Type
------------------------------------------------------------------------------
-- Common divisor.
CD : D → D → D → Set
CD m n cd = cd ∣ m ∧ cd ∣ n
-- Divisible for any common divisor.
Divisible : D → D → D → Set
Divisible m n gcd = ∀ cd → N cd → CD m n cd → cd ∣ gcd
-- Greatest that any common divisor.
GACD : D → D → D → Set
GACD m n gcd = ∀ cd → N cd → CD m n cd → cd ≤ gcd
-- Greatest common divisor specification.
gcdSpec : D → D → D → Set
gcdSpec m n gcd = CD m n gcd ∧ GACD m n gcd
x≢0≢y : D → D → Set
x≢0≢y m n = ¬ (m ≡ zero ∧ n ≡ zero)
| {
"alphanum_fraction": 0.4840142096,
"avg_line_length": 31.2777777778,
"ext": "agda",
"hexsha": "d2034c48f81a3ea8c08c4fd122bbb0b12c33577f",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/LTC-PCF/Program/GCD/Partial/Definitions.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/LTC-PCF/Program/GCD/Partial/Definitions.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/LTC-PCF/Program/GCD/Partial/Definitions.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": 292,
"size": 1126
} |
-- MIT License
-- Copyright (c) 2021 Luca Ciccone and Luca Padovani
-- Permission is hereby granted, free of charge, to any person
-- obtaining a copy of this software and associated documentation
-- files (the "Software"), to deal in the Software without
-- restriction, including without limitation the rights to use,
-- copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the
-- Software is furnished to do so, subject to the following
-- conditions:
-- The above copyright notice and this permission notice shall be
-- included in all copies or substantial portions of the Software.
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-- OTHER DEALINGS IN THE SOFTWARE.
{-# OPTIONS --guardedness #-}
open import Data.Product
open import Data.Empty
open import Data.Sum
open import Data.Vec
open import Data.Fin
open import Data.Bool renaming (Bool to 𝔹)
open import Relation.Unary using (_∈_; _⊆_; _∉_)
open import Relation.Binary.Definitions
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Common
open import is-lib.InfSys
module FairCompliance-IS {𝕋 : Set} (message : Message 𝕋) where
open import SessionType message
open import Session message
open import Transitions message
private
U : Set
U = SessionType × SessionType
data FCompIS-RN : Set where
client-end : FCompIS-RN
oi io : FCompIS-RN
data FCompCOIS-RN : Set where
co-oi co-io : FCompCOIS-RN
client-end-r : FinMetaRule U
client-end-r .Ctx = Σ[ (S , T) ∈ SessionType × SessionType ] Win S × Defined T
client-end-r .comp ((S , T) , _) =
[] ,
--------------------
(S , T)
OI-r : MetaRule U
OI-r .Ctx = Σ[ (f , _) ∈ Continuation × Continuation ] Witness f
OI-r .Pos ((f , _) , _) = Σ[ t ∈ 𝕋 ] t ∈ dom f
OI-r .prems ((f , g) , _) (t , _) = f t .force , g t .force
OI-r .conclu ((f , g) , _) = out f , inp g
IO-r : MetaRule U
IO-r .Ctx = Σ[ (_ , g) ∈ Continuation × Continuation ] Witness g
IO-r .Pos ((_ , g) , _) = Σ[ t ∈ 𝕋 ] t ∈ dom g
IO-r .prems ((f , g) , _) (t , _) = f t .force , g t .force
IO-r .conclu ((f , g) , _) = inp f , out g
co-OI-r : FinMetaRule U
co-OI-r .Ctx = Σ[ (f , _ , x) ∈ Continuation × Continuation × 𝕋 ] x ∈ dom f
co-OI-r .comp ((f , g , x) , _) =
(f x .force , g x .force) ∷ [] ,
--------------------
(out f , inp g)
co-IO-r : FinMetaRule U
co-IO-r .Ctx = Σ[ (_ , g , x) ∈ Continuation × Continuation × 𝕋 ] x ∈ dom g
co-IO-r .comp ((f , g , x) , _) =
(f x .force , g x .force) ∷ [] ,
--------------------
(inp f , out g)
FCompIS : IS U
FCompIS .Names = FCompIS-RN
FCompIS .rules client-end = from client-end-r
FCompIS .rules oi = OI-r
FCompIS .rules io = IO-r
FCompCOIS : IS U
FCompCOIS .Names = FCompCOIS-RN
FCompCOIS .rules co-oi = from co-OI-r
FCompCOIS .rules co-io = from co-IO-r
_⊢_ : SessionType → SessionType → Set
S ⊢ T = FCoInd⟦ FCompIS , FCompCOIS ⟧ (S , T)
_⊢ᵢ_ : SessionType → SessionType → Set
S ⊢ᵢ T = Ind⟦ FCompIS ∪ FCompCOIS ⟧ (S , T)
{- Properties -}
¬nil-⊢ : ∀{S} → ¬ (nil ⊢ S)
¬nil-⊢ fc with fc .CoInd⟦_⟧.unfold
... | client-end , ((_ , (() , _)) , _) , refl , _
⊢ᵢ->succeed : ∀{S T} → S ⊢ᵢ T → MaySucceed (S # T)
⊢ᵢ->succeed (fold (inj₁ client-end , ((S , T) , (win , def)) , refl , _)) = (S # T) , ε , win#def win def
⊢ᵢ->succeed (fold (inj₁ oi , ((f , g) , (t , ok)) , refl , pr)) =
let Sys' , red-Sys' , Succ = ⊢ᵢ->succeed (pr (t , ok)) in
Sys' , sync (out ok) inp ◅ red-Sys' , Succ
⊢ᵢ->succeed (fold (inj₁ io , ((f , g) , (t , ok)) , refl , pr)) =
let Sys' , red-Sys' , Succ = ⊢ᵢ->succeed (pr (t , ok)) in
Sys' , sync inp (out ok) ◅ red-Sys' , Succ
⊢ᵢ->succeed (fold (inj₂ co-oi , (_ , ok-b) , refl , pr)) =
let Sys' , red-Sys' , Succ = ⊢ᵢ->succeed (pr zero) in
Sys' , sync (out ok-b) inp ◅ red-Sys' , Succ
⊢ᵢ->succeed (fold (inj₂ co-io , (_ , ok-b) , refl , pr)) =
let Sys' , red-Sys' , Succ = ⊢ᵢ->succeed (pr zero) in
Sys' , sync inp (out ok-b) ◅ red-Sys' , Succ
maysucceed->⊢ᵢ : ∀{S T Sys} → Reductions (S # T) Sys → Success Sys → S ⊢ᵢ T
maysucceed->⊢ᵢ ε (win#def win def) = apply-ind (inj₁ client-end) (_ , (win , def)) λ ()
maysucceed->⊢ᵢ (sync (out ok) inp ◅ red) Succ =
let rec = maysucceed->⊢ᵢ red Succ in
apply-ind (inj₂ co-oi) (_ , ok) λ{zero → rec}
maysucceed->⊢ᵢ (sync inp (out ok) ◅ red) Succ =
let rec = maysucceed->⊢ᵢ red Succ in
apply-ind (inj₂ co-io) (_ , ok) λ{zero → rec}
{- Soundness -}
fc-sound : ∀{S T} → S ⊢ T → FairComplianceS (S # T)
fc-sound fc ε = ⊢ᵢ->succeed (fcoind-to-ind fc)
fc-sound fc (x ◅ red) with fc .CoInd⟦_⟧.unfold
... | client-end , ((_ , (win , def)) , _) , refl , _ = ⊥-elim (success-not-reduce (win#def win def) x)
fc-sound fc (sync (out ok) (inp {x = t}) ◅ red) | oi , (((f , _) , _) , _) , refl , pr = fc-sound (pr (t , ok)) red
fc-sound fc (sync (inp {x = t}) (out ok) ◅ red) | io , (((_ , g) , _) , _) , refl , pr = fc-sound (pr (t , ok)) red
{- Boundedness -}
fc-bounded : ∀{S T} → FairComplianceS (S # T) → S ⊢ᵢ T
fc-bounded fc =
let _ , red-Sys , Succ = fc ε in
maysucceed->⊢ᵢ red-Sys Succ
{- Consistency -}
fc-consistent : ∀{S T} → FairComplianceS (S # T) → ISF[ FCompIS ] (λ{(S , T) → FairComplianceS (S # T)}) (S , T)
fc-consistent fc with fc ε
... | _ , ε , win#def win def = client-end , (_ , (win , def)) , refl , λ ()
... | _ , sync (out ok) (inp {x = t}) ◅ _ , _ =
oi , (_ , (t , ok)) , refl , λ (t' , ok') red → fc (sync (out ok') (inp {x = t'}) ◅ red)
... | _ , sync (inp {x = t}) (out ok) ◅ _ , _ =
io , (_ , (t , ok)) , refl , λ (t' , ok') red → fc (sync (inp {x = t'}) (out ok') ◅ red)
{- Completeness -}
fc-complete : ∀{S T} → FairComplianceS (S # T) → S ⊢ T
fc-complete =
let S = λ{(S , T) → FairComplianceS (S # T)} in
bounded-coind[ FCompIS , FCompCOIS ] S fc-bounded fc-consistent
{- Properties -}
fci->defined : ∀{S T} → S ⊢ᵢ T → Defined S × Defined T
fci->defined (fold (inj₁ client-end , (_ , (out _ , def)) , refl , _)) = out , def
fci->defined (fold (inj₁ oi , _ , refl , _)) = out , inp
fci->defined (fold (inj₁ io , _ , refl , _)) = inp , out
fci->defined (fold (inj₂ co-oi , _ , refl , _)) = out , inp
fci->defined (fold (inj₂ co-io , _ , refl , _)) = inp , out
fc->defined : ∀{S T} → S ⊢ T → Defined S × Defined T
fc->defined fc = fci->defined (fcoind-to-ind fc)
no-fc-with-nil : ∀{S} → ¬ (S ⊢ nil)
no-fc-with-nil fc with fc .CoInd⟦_⟧.unfold
... | client-end , ((_ , (_ , ())) , _) , refl , _
{- Auxiliary for FS -}
win⊢def : ∀{S} → Defined S → win ⊢ S
win⊢def ok = apply-fcoind client-end (_ , (Win-win , ok)) λ ()
⊢-after-out : ∀{f g t} → t ∈ dom f → out f ⊢ inp g → f t .force ⊢ g t .force
⊢-after-out ok fc with fc .CoInd⟦_⟧.unfold
... | client-end , ((_ , (out e , _)) , _) , refl , _ = ⊥-elim (e _ ok)
... | oi , _ , refl , pr = pr (_ , ok)
⊢-after-in : ∀{f g t} → t ∈ dom g → inp f ⊢ out g → f t .force ⊢ g t .force
⊢-after-in ok fc with fc .CoInd⟦_⟧.unfold
... | client-end , ((_ , (() , _)) , _) , refl , _
... | io , _ , refl , pr = pr (_ , ok) | {
"alphanum_fraction": 0.5725429017,
"avg_line_length": 37.7058823529,
"ext": "agda",
"hexsha": "88e1abed593b6eb6ff427ce6f177311b6815507b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "boystrange/FairSubtypingAgda",
"max_forks_repo_path": "src/FairCompliance-IS.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "boystrange/FairSubtypingAgda",
"max_issues_repo_path": "src/FairCompliance-IS.agda",
"max_line_length": 117,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c4b78e70c3caf68d509f4360b9171d9f80ecb825",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "boystrange/FairSubtypingAgda",
"max_stars_repo_path": "src/FairCompliance-IS.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-24T14:38:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-07-29T14:32:30.000Z",
"num_tokens": 2889,
"size": 7692
} |
{-# OPTIONS --without-K #-}
module container.m.from-nat.coalgebra where
open import level
open import sum
open import equality
open import function
open import sets.nat.core
open import sets.nat.struct
open import sets.unit
open import container.core
open import container.m.from-nat.core
open import container.m.from-nat.cone
open import hott.level
module _ {li la lb} (c : Container li la lb) where
open Container c
open import container.m.coalgebra c hiding (_≅_; module _≅_)
Xⁱ : ℕ → I → Set (la ⊔ lb)
Xⁱ zero = λ _ → ↑ _ ⊤
Xⁱ (suc n) = F (Xⁱ n)
πⁱ : ∀ n → Xⁱ (suc n) →ⁱ Xⁱ n
πⁱ zero = λ _ _ → lift tt
πⁱ (suc n) = imap (πⁱ n)
module _ (i : I) where
X : ℕ → Set (la ⊔ lb)
X n = Xⁱ n i
π : (n : ℕ) → X (suc n) → X n
π n = πⁱ n i
open Limit X π public
open Limit-shift X π public
open F-Limit c X π public
pⁱ : (n : ℕ) → L →ⁱ Xⁱ n
pⁱ n i = p i n
βⁱ : (n : ℕ) → πⁱ n ∘ⁱ pⁱ (suc n) ≡ pⁱ n
βⁱ n = funextⁱ (λ i → β i n)
abstract
outL-iso : ∀ i → F L i ≅ L i
outL-iso i = lim-iso i ·≅ shift-iso i
outL-lem₀ : (n : ℕ)(i : I)(x : F L i)
→ p i (suc n) (apply (outL-iso i) x) ≡ imap (pⁱ n) i x
outL-lem₀ n i x = refl
outL-lem₁' : (n : ℕ)(i : I)(x : F L i)
→ β i (suc n) (apply (outL-iso i) x)
≡ subst₂ (λ w₁ w₀ → π i (suc n) w₁ ≡ w₀)
(sym (outL-lem₀ (suc n) i x))
(sym (outL-lem₀ n i x))
(unapΣ (refl , funext λ b → proj₂ (proj₂ x b) n ))
outL-lem₁' n i x = refl
inL : F L →ⁱ L
inL i = apply (outL-iso i)
outL : L →ⁱ F L
outL i = invert (outL-iso i)
in-out : inL ∘ⁱ outL ≡ idⁱ
in-out = funext λ i → funext λ x → _≅_.iso₂ (outL-iso i) x
outL-lem₁ : (n : ℕ)(i : I)(x : F L i)
→ β i (suc n) (apply (outL-iso i) x)
≡ ap (π i (suc n)) (outL-lem₀ (suc n) i x)
· unapΣ (refl , funext λ b → proj₂ (proj₂ x b) n)
· sym (outL-lem₀ n i x)
outL-lem₁ n i x = outL-lem₁' n i x
· subst-lem (outL-lem₀ (suc n) i x) (outL-lem₀ n i x)
(unapΣ (refl , funext (λ b → proj₂ (proj₂ x b) n)))
where
P : X i (suc (suc n)) → X i (suc n) → Set _
P y x = π i (suc n) y ≡ x
subst-lem : {y₁ y₂ : X i (suc (suc n))}{x₁ x₂ : X i (suc n)}
→ (p : y₁ ≡ y₂)(q : x₁ ≡ x₂)
→ (z : P y₂ x₂)
→ subst₂ P (sym p) (sym q) z ≡ ap (π i (suc n)) p · z · sym q
subst-lem refl refl refl = refl
𝓛 : Coalg _
𝓛 = L , outL
module _ {ℓ} (𝓩 : Coalg ℓ) where
private
Z = proj₁ 𝓩; θ = proj₂ 𝓩
lim-coalg-iso : 𝓩 ⇒ 𝓛 ≅ ⊤
lim-coalg-iso = begin
( Σ (Z →ⁱ L) λ f → outL ∘ⁱ f ≡ step f )
≅⟨ Σ-ap-iso refl≅ eq-lem ⟩
( Σ (Z →ⁱ L) λ f → inL ∘ⁱ outL ∘ⁱ f ≡ inL ∘ⁱ step f )
≅⟨ Ψ-lem ⟩
( Σ (Z →ⁱ L) λ f → inL ∘ⁱ outL ∘ⁱ f ≡ Ψ f )
≅⟨ ( Σ-ap-iso refl≅ λ f → trans≡-iso (ap (λ h₁ → h₁ ∘ⁱ f) (sym in-out)) ) ⟩
( Σ (Z →ⁱ L) λ f → f ≡ Ψ f )
≅⟨ sym≅ (Σ-ap-iso isom λ _ → refl≅) ⟩
( Σ Cone λ c → apply isom c ≡ Ψ (apply isom c) )
≅⟨ ( Σ-ap-iso refl≅ λ c → trans≡-iso' (Φ-Ψ-comm c) ) ⟩
( Σ Cone λ c → apply isom c ≡ apply isom (Φ c) )
≅⟨ sym≅ (Σ-ap-iso refl≅ λ c → iso≡ isom ) ⟩
( Σ Cone λ c → c ≡ Φ c )
≅⟨ ( Σ-ap-iso refl≅ λ _ → refl≅ ) ⟩
( Σ Cone λ { (u , q) → (u , q) ≡ (Φ₀ u , Φ₁ u q) } )
≅⟨ (Σ-ap-iso refl≅ λ { (u , q) → sym≅ Σ-split-iso }) ⟩
( Σ Cone λ { (u , q) → Σ (u ≡ Φ₀ u) λ p → subst Cone₁ p q ≡ Φ₁ u q } )
≅⟨ record
{ to = λ { ((u , q) , p , r) → (u , p) , q , r }
; from = λ { ((u , p) , q , r) → (u , q) , p , r }
; iso₁ = λ { ((u , q) , p , r) → refl }
; iso₂ = λ { ((u , p) , q , r) → refl } } ⟩
( Σ (Σ Cone₀ λ u → u ≡ Φ₀ u) λ { (u , p)
→ Σ (Cone₁ u) λ q → subst Cone₁ p q ≡ Φ₁ u q } )
≅⟨ sym≅ ( Σ-ap-iso (sym≅ (contr-⊤-iso Fix₀-contr)) λ _ → refl≅ )
·≅ ×-left-unit ⟩
( Σ (Cone₁ u₀) λ q
→ subst Cone₁ (funext p₀) q ≡ Φ₁ u₀ q )
≅⟨ Fix₁-iso ⟩
⊤
∎
where
open cones c Xⁱ πⁱ 𝓩
X₀-contr : ∀ i → contr (X i 0)
X₀-contr i = ↑-level _ ⊤-contr
Z→X₀-contr : contr (Z →ⁱ Xⁱ 0)
Z→X₀-contr = Π-level λ i → Π-level λ _ → X₀-contr i
step : ∀ {ly}{Y : I → Set ly} → (Z →ⁱ Y) → (Z →ⁱ F Y)
step v = imap v ∘ⁱ θ
Φ₀ : Cone₀ → Cone₀
Φ₀ u 0 = λ _ _ → lift tt
Φ₀ u (suc n) = step (u n)
Φ₀' : Cone → Cone₀
Φ₀' (u , q) = Φ₀ u
Φ₁ : (u : Cone₀) → Cone₁ u → Cone₁ (Φ₀ u)
Φ₁ u q zero = refl
Φ₁ u q (suc n) = ap step (q n)
Φ₁' : (c : Cone) → Cone₁ (Φ₀ (proj₁ c))
Φ₁' (u , q) = Φ₁ u q
Φ : Cone → Cone
Φ (u , q) = (Φ₀ u , Φ₁ u q)
u₀ : Cone₀
u₀ zero = λ _ _ → lift tt
u₀ (suc n) = step (u₀ n)
p₀ : ∀ n → u₀ n ≡ Φ₀ u₀ n
p₀ zero = refl
p₀ (suc n) = refl
Fix₀ : Set (ℓ ⊔ la ⊔ lb ⊔ li)
Fix₀ = Σ Cone₀ λ u → u ≡ Φ₀ u
Fix₁ : Fix₀ → Set (ℓ ⊔ la ⊔ lb ⊔ li)
Fix₁ (u , p) = Σ (Cone₁ u) λ q → subst Cone₁ p q ≡ Φ₁ u q
Fix₀-center : Fix₀
Fix₀-center = u₀ , funext p₀
Fix₀-iso : Fix₀ ≅ (∀ i → Z i → X i 0)
Fix₀-iso = begin
( Σ Cone₀ λ u → u ≡ Φ₀ u )
≅⟨ ( Σ-ap-iso refl≅ λ u → sym≅ strong-funext-iso ·≅ ℕ-elim-shift ) ⟩
( Σ Cone₀ λ u → (u 0 ≡ λ _ _ → lift tt)
× (∀ n → u (suc n) ≡ step (u n)) )
≅⟨ ( Σ-ap-iso refl≅ λ u → (×-ap-iso (contr-⊤-iso (h↑ Z→X₀-contr _ _)) refl≅)
·≅ ×-left-unit ) ⟩
( Σ Cone₀ λ u → (∀ n → u (suc n) ≡ step (u n)) )
≅⟨ Limit-op.lim-contr (λ n → Z →ⁱ Xⁱ n) (λ n → step) ⟩
(∀ i → Z i → X i 0)
∎
where open ≅-Reasoning
Fix₀-contr : contr Fix₀
Fix₀-contr = Fix₀-center , contr⇒prop
(iso-level (sym≅ Fix₀-iso) Z→X₀-contr) _
Fix₁-iso : Fix₁ Fix₀-center ≅ ⊤
Fix₁-iso = begin
( Σ (Cone₁ u₀) λ q → subst Cone₁ (funext p₀) q ≡ Φ₁ u₀ q )
≅⟨ ( Σ-ap-iso refl≅ λ q → sym≅ strong-funext-iso ) ⟩
( Σ (Cone₁ u₀) λ q → ∀ n → subst Cone₁ (funext p₀) q n ≡ Φ₁ u₀ q n )
≅⟨ ( Σ-ap-iso refl≅ λ q → Π-ap-iso refl≅ λ n
→ sym≅ (trans≡-iso (subst-lem _ _ p₀ q n)) ) ⟩
( Σ (Cone₁ u₀) λ q → ∀ n
→ subst₂ (P n) (p₀ (suc n)) (p₀ n) (q n) ≡ Φ₁ u₀ q n )
≅⟨ ( Σ-ap-iso refl≅ λ q → ℕ-elim-shift ) ⟩
( Σ (Cone₁ u₀) λ q
→ (q 0 ≡ Φ₁ u₀ q 0)
× (∀ n → q (suc n) ≡ Φ₁ u₀ q (suc n)) )
≅⟨ ( Σ-ap-iso refl≅ λ q → ×-ap-iso (contr-⊤-iso (h↑ (h↑ Z→X₀-contr _ _) _ _))
refl≅
·≅ ×-left-unit ) ⟩
( Σ (Cone₁ u₀) λ q
→ ∀ n → q (suc n) ≡ ap step (q n) )
≅⟨ Limit-op.lim-contr (λ n → πⁱ n ∘ⁱ u₀ (suc n) ≡ u₀ n) (λ n → ap step) ⟩
( πⁱ 0 ∘ⁱ u₀ 1 ≡ u₀ 0 )
≅⟨ contr-⊤-iso (h↑ Z→X₀-contr _ _) ⟩
⊤
∎
where
P = λ m x y → πⁱ m ∘ⁱ x ≡ y
subst-lem₁ : (u v : Cone₀)(p : u ≡ v)(q : Cone₁ u)(n : ℕ)
→ subst Cone₁ p q n
≡ subst₂ (P n) (funext-inv p (suc n)) (funext-inv p n) (q n)
subst-lem₁ u .u refl q n = refl
subst-lem : (u v : Cone₀)(p : ∀ n → u n ≡ v n)(q : Cone₁ u)(n : ℕ)
→ subst Cone₁ (funext p) q n
≡ subst₂ (P n) (p (suc n)) (p n) (q n)
subst-lem u v p q n = subst-lem₁ u v (funext p) q n
· ap (λ p → subst₂ (P n) (p (suc n)) (p n) (q n))
(_≅_.iso₁ strong-funext-iso p)
open ≅-Reasoning
Ψ : (Z →ⁱ L) → (Z →ⁱ L)
Ψ f = inL ∘ⁱ step f
Ψ-lem : ( Σ (Z →ⁱ L) λ f → inL ∘ⁱ outL ∘ⁱ f ≡ inL ∘ⁱ step f)
≅ ( Σ (Z →ⁱ L) λ f → inL ∘ⁱ outL ∘ⁱ f ≡ Ψ f )
Ψ-lem = Σ-ap-iso refl≅ λ f → refl≅
Φ-Ψ-comm₀ : (f : Z →ⁱ L) → ∀ n i z
→ p i n (Ψ f i z)
≡ Φ₀' (invert isom f) n i z
Φ-Ψ-comm₀ f 0 i z = h1⇒prop (h↑ (X₀-contr i)) _ _
Φ-Ψ-comm₀ f (suc n) i z = outL-lem₀ n i (imap f i (θ i z))
Φ-Ψ-comm₁' : (f : Z →ⁱ L) → ∀ n i z
→ β i n (Ψ f i z)
≡ ap (π i n) (Φ-Ψ-comm₀ f (suc n) i z)
· funext-invⁱ (Φ₁' (invert isom f) n) i z
· sym (Φ-Ψ-comm₀ f n i z)
Φ-Ψ-comm₁' f 0 i z = h1⇒prop (h↑ (h↑ (X₀-contr i)) _ _) _ _
Φ-Ψ-comm₁' f (suc n) i z = begin
β i (suc n) (inL i (imap f i (θ i z)))
≡⟨ outL-lem₁ n i (imap f i (θ i z)) ⟩
( ap (π i (suc n)) (Φ-Ψ-comm₀ f (suc (suc n)) i z)
· unapΣ (refl , funext λ b → β (r b) n (proj₂ (imap f i (θ i z)) b))
· sym (Φ-Ψ-comm₀ f (suc n) i z) )
≡⟨ ap (λ ω → ap (π i (suc n)) (Φ-Ψ-comm₀ f (suc (suc n)) i z)
· ω · sym (Φ-Ψ-comm₀ f (suc n) i z))
(lem (λ i x → β i n x) i z) ⟩
( ap (π i (suc n)) (Φ-Ψ-comm₀ f (suc (suc n)) i z)
· funext-invⁱ (ap step (funextⁱ (λ i z → β i n (f i z)))) i z
· sym (Φ-Ψ-comm₀ f (suc n) i z) )
∎
where
open ≡-Reasoning
lem' : {u v : L →ⁱ Xⁱ n}(ω : u ≡ v)(i : I)(z : Z i)
→ unapΣ (refl , funext λ b → funext-invⁱ ω (r b) (proj₂ (imap f i (θ i z)) b))
≡ funext-invⁱ (ap step (funextⁱ (λ i z → funext-invⁱ ω i (f i z)))) i z
lem' refl i z = begin
unapΣ (refl , funext λ b → refl)
≡⟨ ap (λ ω → unapΣ (refl , ω)) (_≅_.iso₂ strong-funext-iso refl) ⟩
refl
≡⟨ sym (ap (λ ω → funext-invⁱ (ap step ω) i z)
(_≅_.iso₂ funext-isoⁱ refl)) ⟩
funext-invⁱ (ap step (funextⁱ (λ i z → refl))) i z
∎
where
open ≡-Reasoning
lem : {u v : L →ⁱ Xⁱ n}(ω : (i : I)(x : L i) → u i x ≡ v i x)(i : I)(z : Z i)
→ unapΣ (refl , funext λ b → ω (r b) (proj₂ (imap f i (θ i z)) b))
≡ funext-invⁱ (ap step (funextⁱ (λ i z → ω i (f i z)))) i z
lem {u}{v} = invert (Π-ap-iso funext-isoⁱ λ ω → refl≅) lem'
Φ-Ψ-comm₁ : (f : Z →ⁱ L) → ∀ n i z
→ funext-invⁱ (funextⁱ λ i z → β i n (Ψ f i z)) i z
≡ ap (π i n) (Φ-Ψ-comm₀ f (suc n) i z)
· funext-invⁱ (Φ₁' (invert isom f) n) i z
· sym (Φ-Ψ-comm₀ f n i z)
Φ-Ψ-comm₁ f n i z = ap (λ h → h i z)
(_≅_.iso₁ funext-isoⁱ (λ i z → β i n (Ψ f i z)))
· Φ-Ψ-comm₁' f n i z
Φ-Ψ-comm' : (f : Z →ⁱ L) → invert isom (Ψ f) ≡ Φ (invert isom f)
Φ-Ψ-comm' f = Cone-eq (Φ-Ψ-comm₀ f) (Φ-Ψ-comm₁ f)
Φ-Ψ-comm : (c : Cone) → Ψ (apply isom c) ≡ apply isom (Φ c)
Φ-Ψ-comm c = sym (_≅_.iso₂ isom (Ψ (apply isom c)))
· ap (apply isom)
(Φ-Ψ-comm' (apply isom c) · ap Φ (_≅_.iso₁ isom c))
cone-comp₀ : (f : Z →ⁱ L)(n : ℕ)(i : I)(z : Z i)
→ proj₁ (invert isom (Ψ f)) n i z
≡ p i n (Ψ f i z)
cone-comp₀ f n i z = refl
cone-comp₁ : (f : Z →ⁱ L)(n : ℕ)
→ proj₂ (invert isom (Ψ f)) n
≡ funextⁱ (λ i z → β i n (Ψ f i z))
cone-comp₁ f n = refl
eq-lem : (f : Z →ⁱ L) → (outL ∘ⁱ f ≡ step f)
≅ (inL ∘ⁱ outL ∘ⁱ f ≡ inL ∘ⁱ step f)
eq-lem f = iso≡ ( Π-ap-iso refl≅ λ i
→ Π-ap-iso refl≅ λ _
→ outL-iso i )
open ≅-Reasoning
lim-terminal : contr (𝓩 ⇒ 𝓛)
lim-terminal = iso-level (sym≅ lim-coalg-iso) ⊤-contr
m-final : Final _
m-final = 𝓛 , lim-terminal
-- Theorem 7 in Ahrens, Capriotti and Spadotti (arXiv:1504.02949v1 [cs.LO])
m-final-contr : contr (Final _)
m-final-contr = m-final , λ fin → Final-prop m-final fin
| {
"alphanum_fraction": 0.4141307008,
"avg_line_length": 37.1424242424,
"ext": "agda",
"hexsha": "d5fb85e096a207e850e2a324c1e9286e505db0cd",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "container/m/from-nat/coalgebra.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "container/m/from-nat/coalgebra.agda",
"max_line_length": 95,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "container/m/from-nat/coalgebra.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 5318,
"size": 12257
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties of the heterogeneous prefix relation
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Binary.Prefix.Heterogeneous.Properties where
open import Data.Empty
open import Data.List.Relation.Unary.All as All using (All; []; _∷_)
import Data.List.Relation.Unary.All.Properties as All
open import Data.List.Base as List hiding (map; uncons)
open import Data.List.Membership.Propositional.Properties using ([]∈inits)
open import Data.List.Relation.Binary.Pointwise using (Pointwise; []; _∷_)
open import Data.List.Relation.Binary.Prefix.Heterogeneous as Prefix hiding (PrefixView; _++_)
open import Data.Nat.Base using (ℕ; zero; suc; _≤_; z≤n; s≤s)
open import Data.Nat.Properties using (suc-injective)
open import Data.Product as Prod using (_×_; _,_; proj₁; proj₂; uncurry)
open import Function
open import Relation.Nullary using (yes; no; ¬_)
import Relation.Nullary.Decidable as Dec
open import Relation.Nullary.Product using (_×-dec_)
open import Relation.Unary as U using (Pred)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_)
------------------------------------------------------------------------
-- First as a decidable partial order (once made homogeneous)
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
fromPointwise : Pointwise R ⇒ Prefix R
fromPointwise [] = []
fromPointwise (r ∷ rs) = r ∷ fromPointwise rs
toPointwise : ∀ {as bs} → length as ≡ length bs →
Prefix R as bs → Pointwise R as bs
toPointwise {bs = []} eq [] = []
toPointwise {bs = _ ∷ _} () []
toPointwise eq (r ∷ rs) = r ∷ toPointwise (suc-injective eq) rs
module _ {a b c r s t} {A : Set a} {B : Set b} {C : Set c}
{R : REL A B r} {S : REL B C s} {T : REL A C t} where
trans : Trans R S T → Trans (Prefix R) (Prefix S) (Prefix T)
trans rs⇒t [] ss = []
trans rs⇒t (r ∷ rs) (s ∷ ss) = rs⇒t r s ∷ trans rs⇒t rs ss
module _ {a b r s e} {A : Set a} {B : Set b}
{R : REL A B r} {S : REL B A s} {E : REL A B e} where
antisym : Antisym R S E → Antisym (Prefix R) (Prefix S) (Pointwise E)
antisym rs⇒e [] [] = []
antisym rs⇒e (r ∷ rs) (s ∷ ss) = rs⇒e r s ∷ antisym rs⇒e rs ss
------------------------------------------------------------------------
-- length
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
length-mono : ∀ {as bs} → Prefix R as bs → length as ≤ length bs
length-mono [] = z≤n
length-mono (r ∷ rs) = s≤s (length-mono rs)
------------------------------------------------------------------------
-- _++_
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
++⁺ : ∀ {as bs cs ds} → Pointwise R as bs →
Prefix R cs ds → Prefix R (as ++ cs) (bs ++ ds)
++⁺ [] cs⊆ds = cs⊆ds
++⁺ (r ∷ rs) cs⊆ds = r ∷ (++⁺ rs cs⊆ds)
++⁻ : ∀ {as bs cs ds} → length as ≡ length bs →
Prefix R (as ++ cs) (bs ++ ds) → Prefix R cs ds
++⁻ {[]} {[]} eq rs = rs
++⁻ {_ ∷ _} {_ ∷ _} eq (_ ∷ rs) = ++⁻ (suc-injective eq) rs
++⁻ {[]} {_ ∷ _} ()
++⁻ {_ ∷ _} {[]} ()
------------------------------------------------------------------------
-- map
module _ {a b c d r} {A : Set a} {B : Set b} {C : Set c} {D : Set d}
{R : REL C D r} where
map⁺ : ∀ {as bs} (f : A → C) (g : B → D) →
Prefix (λ a b → R (f a) (g b)) as bs →
Prefix R (List.map f as) (List.map g bs)
map⁺ f g [] = []
map⁺ f g (r ∷ rs) = r ∷ map⁺ f g rs
map⁻ : ∀ {as bs} (f : A → C) (g : B → D) →
Prefix R (List.map f as) (List.map g bs) →
Prefix (λ a b → R (f a) (g b)) as bs
map⁻ {[]} {bs} f g rs = []
map⁻ {a ∷ as} {[]} f g ()
map⁻ {a ∷ as} {b ∷ bs} f g (r ∷ rs) = r ∷ map⁻ f g rs
------------------------------------------------------------------------
-- filter
module _ {a b r p q} {A : Set a} {B : Set b} {R : REL A B r}
{P : Pred A p} {Q : Pred B q} (P? : U.Decidable P) (Q? : U.Decidable Q)
(P⇒Q : ∀ {a b} → R a b → P a → Q b) (Q⇒P : ∀ {a b} → R a b → Q b → P a)
where
filter⁺ : ∀ {as bs} → Prefix R as bs → Prefix R (filter P? as) (filter Q? bs)
filter⁺ [] = []
filter⁺ {a ∷ as} {b ∷ bs} (r ∷ rs) with P? a | Q? b
... | yes pa | yes qb = r ∷ filter⁺ rs
... | yes pa | no ¬qb = ⊥-elim (¬qb (P⇒Q r pa))
... | no ¬pa | yes qb = ⊥-elim (¬pa (Q⇒P r qb))
... | no ¬pa | no ¬qb = filter⁺ rs
------------------------------------------------------------------------
-- take
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
take⁺ : ∀ {as bs} n → Prefix R as bs →
Prefix R (take n as) (take n bs)
take⁺ zero rs = []
take⁺ (suc n) [] = []
take⁺ (suc n) (r ∷ rs) = r ∷ take⁺ n rs
take⁻ : ∀ {as bs} n →
Prefix R (take n as) (take n bs) →
Prefix R (drop n as) (drop n bs) →
Prefix R as bs
take⁻ zero hds tls = tls
take⁻ {[]} (suc n) hds tls = []
take⁻ {a ∷ as} {[]} (suc n) () tls
take⁻ {a ∷ as} {b ∷ bs} (suc n) (r ∷ hds) tls = r ∷ take⁻ n hds tls
------------------------------------------------------------------------
-- drop
drop⁺ : ∀ {as bs} n → Prefix R as bs → Prefix R (drop n as) (drop n bs)
drop⁺ zero rs = rs
drop⁺ (suc n) [] = []
drop⁺ (suc n) (r ∷ rs) = drop⁺ n rs
drop⁻ : ∀ {as bs} n → Pointwise R (take n as) (take n bs) →
Prefix R (drop n as) (drop n bs) → Prefix R as bs
drop⁻ zero hds tls = tls
drop⁻ {[]} (suc n) hds tls = []
drop⁻ {_ ∷ _} {[]} (suc n) () tls
drop⁻ {_ ∷ _} {_ ∷ _} (suc n) (r ∷ hds) tls = r ∷ (drop⁻ n hds tls)
------------------------------------------------------------------------
-- replicate
replicate⁺ : ∀ {m n a b} → m ≤ n → R a b →
Prefix R (replicate m a) (replicate n b)
replicate⁺ z≤n r = []
replicate⁺ (s≤s m≤n) r = r ∷ replicate⁺ m≤n r
replicate⁻ : ∀ {m n a b} → m ≢ 0 →
Prefix R (replicate m a) (replicate n b) → R a b
replicate⁻ {zero} {n} m≢0 r = ⊥-elim (m≢0 P.refl)
replicate⁻ {suc m} {zero} m≢0 ()
replicate⁻ {suc m} {suc n} m≢0 rs = Prefix.head rs
------------------------------------------------------------------------
-- inits
module _ {a r} {A : Set a} {R : Rel A r} where
inits⁺ : ∀ {as} → Pointwise R as as → All (flip (Prefix R) as) (inits as)
inits⁺ [] = [] ∷ []
inits⁺ (r ∷ rs) = [] ∷ All.map⁺ (All.map (r ∷_) (inits⁺ rs))
inits⁻ : ∀ {as} → All (flip (Prefix R) as) (inits as) → Pointwise R as as
inits⁻ {as = []} rs = []
inits⁻ {as = a ∷ as} (r ∷ rs) =
let (hd , tls) = All.unzip (All.map uncons (All.map⁻ rs)) in
All.lookup hd ([]∈inits as) ∷ inits⁻ tls
------------------------------------------------------------------------
-- zip(With)
module _ {a b c} {A : Set a} {B : Set b} {C : Set c}
{d e f} {D : Set d} {E : Set e} {F : Set f}
{r s t} {R : REL A D r} {S : REL B E s} {T : REL C F t} where
zipWith⁺ : ∀ {as bs ds es} {f : A → B → C} {g : D → E → F} →
(∀ {a b c d} → R a c → S b d → T (f a b) (g c d)) →
Prefix R as ds → Prefix S bs es →
Prefix T (zipWith f as bs) (zipWith g ds es)
zipWith⁺ f [] ss = []
zipWith⁺ f (r ∷ rs) [] = []
zipWith⁺ f (r ∷ rs) (s ∷ ss) = f r s ∷ zipWith⁺ f rs ss
module _ {a b c d} {A : Set a} {B : Set b} {C : Set c} {D : Set d}
{r s} {R : REL A C r} {S : REL B D s} where
private
R×S : REL (A × B) (C × D) _
R×S (a , b) (c , d) = R a c × S b d
zip⁺ : ∀ {as bs cs ds} → Prefix R as cs → Prefix S bs ds →
Prefix R×S (zip as bs) (zip cs ds)
zip⁺ = zipWith⁺ _,_
------------------------------------------------------------------------
-- Irrelevance
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
irrelevant : Irrelevant R → Irrelevant (Prefix R)
irrelevant R-irr [] [] = P.refl
irrelevant R-irr (r ∷ rs) (r′ ∷ rs′) =
P.cong₂ _∷_ (R-irr r r′) (irrelevant R-irr rs rs′)
------------------------------------------------------------------------
-- Decidability
prefix? : Decidable R → Decidable (Prefix R)
prefix? R? [] bs = yes []
prefix? R? (a ∷ as) [] = no (λ ())
prefix? R? (a ∷ as) (b ∷ bs) = Dec.map′ (uncurry _∷_) uncons
$ R? a b ×-dec prefix? R? as bs
| {
"alphanum_fraction": 0.4422069608,
"avg_line_length": 37.6798245614,
"ext": "agda",
"hexsha": "9413d137301e5c86a4be009b24ae7d4de57101f1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Prefix/Heterogeneous/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Prefix/Heterogeneous/Properties.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Prefix/Heterogeneous/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3066,
"size": 8591
} |
module Golden.Index where
open import Agda.Builtin.Nat
open import Agda.Builtin.List
open import Agda.Builtin.Bool
lst : List Nat
lst = 1 ∷ 2 ∷ []
atDef : ∀ {a : Set} → a → List a -> Nat -> a
atDef def (x ∷ l) zero = x
atDef def (x ∷ l) (suc ix) = atDef def l ix
atDef def _ _ = def
l0 : Nat
l0 = atDef 0 lst 0
l1 : Nat
l1 = atDef 0 lst 1
l2 : Nat
l2 = atDef 0 lst 2
| {
"alphanum_fraction": 0.6300268097,
"avg_line_length": 16.2173913043,
"ext": "agda",
"hexsha": "2273b1cd8b9638cc22ea2ad88de02a6b3353e4b5",
"lang": "Agda",
"max_forks_count": 7,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:48.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-05-24T10:45:59.000Z",
"max_forks_repo_head_hexsha": "e38b699870ba638221828b07b12948d70a1bdaec",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "agda/agda-ocaml",
"max_forks_repo_path": "test/agda-ocaml/Golden/Index.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "e38b699870ba638221828b07b12948d70a1bdaec",
"max_issues_repo_issues_event_max_datetime": "2018-11-05T21:28:57.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-03-29T13:37:52.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "agda/agda-ocaml",
"max_issues_repo_path": "test/agda-ocaml/Golden/Index.agda",
"max_line_length": 44,
"max_stars_count": 48,
"max_stars_repo_head_hexsha": "e38b699870ba638221828b07b12948d70a1bdaec",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "agda/agda-ocaml",
"max_stars_repo_path": "test/agda-ocaml/Golden/Index.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-15T09:08:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-03-29T14:19:31.000Z",
"num_tokens": 155,
"size": 373
} |
{-
This second-order term syntax was created from the following second-order syntax description:
syntax TLC | Λ
type
N : 0-ary
_↣_ : 2-ary | r30
𝟙 : 0-ary
_⊗_ : 2-ary | l40
𝟘 : 0-ary
_⊕_ : 2-ary | l30
term
app : α ↣ β α -> β | _$_ l20
lam : α.β -> α ↣ β | ƛ_ r10
unit : 𝟙
pair : α β -> α ⊗ β | ⟨_,_⟩
fst : α ⊗ β -> α
snd : α ⊗ β -> β
abort : 𝟘 -> α
inl : α -> α ⊕ β
inr : β -> α ⊕ β
case : α ⊕ β α.γ β.γ -> γ
ze : N
su : N -> N
nrec : N α (α,N).α -> α
theory
(ƛβ) b : α.β a : α |> app (lam(x.b[x]), a) = b[a]
(ƛη) f : α ↣ β |> lam (x. app(f, x)) = f
(𝟙η) u : 𝟙 |> u = unit
(fβ) a : α b : β |> fst (pair(a, b)) = a
(sβ) a : α b : β |> snd (pair(a, b)) = b
(pη) p : α ⊗ β |> pair (fst(p), snd(p)) = p
(𝟘η) e : 𝟘 c : α |> abort(e) = c
(lβ) a : α f : α.γ g : β.γ |> case (inl(a), x.f[x], y.g[y]) = f[a]
(rβ) b : β f : α.γ g : β.γ |> case (inr(b), x.f[x], y.g[y]) = g[b]
(cη) s : α ⊕ β c : (α ⊕ β).γ |> case (s, x.c[inl(x)], y.c[inr(y)]) = c[s]
(zeβ) z : α s : (α,N).α |> nrec (ze, z, r m. s[r,m]) = z
(suβ) z : α s : (α,N).α n : N |> nrec (su (n), z, r m. s[r,m]) = s[nrec (n, z, r m. s[r,m]), n]
(ift) t f : α |> if (true, t, f) = t
(iff) t f : α |> if (false, t, f) = f
-}
module TLC.Syntax where
open import SOAS.Common
open import SOAS.Context
open import SOAS.Variable
open import SOAS.Families.Core
open import SOAS.Construction.Structure
open import SOAS.ContextMaps.Inductive
open import SOAS.Metatheory.Syntax
open import TLC.Signature
private
variable
Γ Δ Π : Ctx
α β γ : ΛT
𝔛 : Familyₛ
-- Inductive term declaration
module Λ:Terms (𝔛 : Familyₛ) where
data Λ : Familyₛ where
var : ℐ ⇾̣ Λ
mvar : 𝔛 α Π → Sub Λ Π Γ → Λ α Γ
_$_ : Λ (α ↣ β) Γ → Λ α Γ → Λ β Γ
ƛ_ : Λ β (α ∙ Γ) → Λ (α ↣ β) Γ
unit : Λ 𝟙 Γ
⟨_,_⟩ : Λ α Γ → Λ β Γ → Λ (α ⊗ β) Γ
fst : Λ (α ⊗ β) Γ → Λ α Γ
snd : Λ (α ⊗ β) Γ → Λ β Γ
abort : Λ 𝟘 Γ → Λ α Γ
inl : Λ α Γ → Λ (α ⊕ β) Γ
inr : Λ β Γ → Λ (α ⊕ β) Γ
case : Λ (α ⊕ β) Γ → Λ γ (α ∙ Γ) → Λ γ (β ∙ Γ) → Λ γ Γ
ze : Λ N Γ
su : Λ N Γ → Λ N Γ
nrec : Λ N Γ → Λ α Γ → Λ α (α ∙ N ∙ Γ) → Λ α Γ
infixl 20 _$_
infixr 10 ƛ_
open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛
Λᵃ : MetaAlg Λ
Λᵃ = record
{ 𝑎𝑙𝑔 = λ where
(appₒ ⋮ a , b) → _$_ a b
(lamₒ ⋮ a) → ƛ_ a
(unitₒ ⋮ _) → unit
(pairₒ ⋮ a , b) → ⟨_,_⟩ a b
(fstₒ ⋮ a) → fst a
(sndₒ ⋮ a) → snd a
(abortₒ ⋮ a) → abort a
(inlₒ ⋮ a) → inl a
(inrₒ ⋮ a) → inr a
(caseₒ ⋮ a , b , c) → case a b c
(zeₒ ⋮ _) → ze
(suₒ ⋮ a) → su a
(nrecₒ ⋮ a , b , c) → nrec a b c
; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) }
module Λᵃ = MetaAlg Λᵃ
module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where
open MetaAlg 𝒜ᵃ
𝕤𝕖𝕞 : Λ ⇾̣ 𝒜
𝕊 : Sub Λ Π Γ → Π ~[ 𝒜 ]↝ Γ
𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t
𝕊 (t ◂ σ) (old v) = 𝕊 σ v
𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε)
𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v
𝕤𝕖𝕞 (_$_ a b) = 𝑎𝑙𝑔 (appₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)
𝕤𝕖𝕞 (ƛ_ a) = 𝑎𝑙𝑔 (lamₒ ⋮ 𝕤𝕖𝕞 a)
𝕤𝕖𝕞 unit = 𝑎𝑙𝑔 (unitₒ ⋮ tt)
𝕤𝕖𝕞 (⟨_,_⟩ a b) = 𝑎𝑙𝑔 (pairₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b)
𝕤𝕖𝕞 (fst a) = 𝑎𝑙𝑔 (fstₒ ⋮ 𝕤𝕖𝕞 a)
𝕤𝕖𝕞 (snd a) = 𝑎𝑙𝑔 (sndₒ ⋮ 𝕤𝕖𝕞 a)
𝕤𝕖𝕞 (abort a) = 𝑎𝑙𝑔 (abortₒ ⋮ 𝕤𝕖𝕞 a)
𝕤𝕖𝕞 (inl a) = 𝑎𝑙𝑔 (inlₒ ⋮ 𝕤𝕖𝕞 a)
𝕤𝕖𝕞 (inr a) = 𝑎𝑙𝑔 (inrₒ ⋮ 𝕤𝕖𝕞 a)
𝕤𝕖𝕞 (case a b c) = 𝑎𝑙𝑔 (caseₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b , 𝕤𝕖𝕞 c)
𝕤𝕖𝕞 ze = 𝑎𝑙𝑔 (zeₒ ⋮ tt)
𝕤𝕖𝕞 (su a) = 𝑎𝑙𝑔 (suₒ ⋮ 𝕤𝕖𝕞 a)
𝕤𝕖𝕞 (nrec a b c) = 𝑎𝑙𝑔 (nrecₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b , 𝕤𝕖𝕞 c)
𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Λᵃ 𝒜ᵃ 𝕤𝕖𝕞
𝕤𝕖𝕞ᵃ⇒ = record
{ ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t }
; ⟨𝑣𝑎𝑟⟩ = refl
; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } }
where
open ≡-Reasoning
⟨𝑎𝑙𝑔⟩ : (t : ⅀ Λ α Γ) → 𝕤𝕖𝕞 (Λᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t)
⟨𝑎𝑙𝑔⟩ (appₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (lamₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (unitₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (pairₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (fstₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (sndₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (abortₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (inlₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (inrₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (caseₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (zeₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (suₒ ⋮ _) = refl
⟨𝑎𝑙𝑔⟩ (nrecₒ ⋮ _) = refl
𝕊-tab : (mε : Π ~[ Λ ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v)
𝕊-tab mε new = refl
𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v
module _ (g : Λ ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Λᵃ 𝒜ᵃ g) where
open MetaAlg⇒ gᵃ⇒
𝕤𝕖𝕞! : (t : Λ α Γ) → 𝕤𝕖𝕞 t ≡ g t
𝕊-ix : (mε : Sub Λ Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v)
𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x
𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v
𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε))
= trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε))
𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩
𝕤𝕖𝕞! (_$_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (ƛ_ a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! unit = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (⟨_,_⟩ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (fst a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (snd a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (abort a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (inl a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (inr a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (case a b c) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b | 𝕤𝕖𝕞! c = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! ze = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (su a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩
𝕤𝕖𝕞! (nrec a b c) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b | 𝕤𝕖𝕞! c = sym ⟨𝑎𝑙𝑔⟩
-- Syntax instance for the signature
Λ:Syn : Syntax
Λ:Syn = record
{ ⅀F = ⅀F
; ⅀:CS = ⅀:CompatStr
; mvarᵢ = Λ:Terms.mvar
; 𝕋:Init = λ 𝔛 → let open Λ:Terms 𝔛 in record
{ ⊥ = Λ ⋉ Λᵃ
; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ }
; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } }
-- Instantiation of the syntax and metatheory
open Syntax Λ:Syn public
open Λ:Terms public
open import SOAS.Families.Build public
open import SOAS.Syntax.Shorthands Λᵃ public
open import SOAS.Metatheory Λ:Syn public
-- Derived operations
true : Λ 𝔛 B Γ
true = inl unit
false : Λ 𝔛 B Γ
false = inr unit
if : Λ 𝔛 B Γ → Λ 𝔛 α Γ → Λ 𝔛 α Γ → Λ 𝔛 α Γ
if b t e = case b (Theory.𝕨𝕜 _ t) (Theory.𝕨𝕜 _ e)
plus : Λ 𝔛 (N ↣ N ↣ N) Γ
plus = ƛ (ƛ (nrec x₁ x₀ (su x₀)))
uncurry : Λ 𝔛 ((α ↣ β ↣ γ) ↣ (α ⊗ β) ↣ γ) Γ
uncurry = ƛ ƛ x₁ $ fst x₀ $ snd x₀
| {
"alphanum_fraction": 0.4533232628,
"avg_line_length": 29.9547511312,
"ext": "agda",
"hexsha": "3a0b1dc9ac44c7d84babdeeaeba5be710493e9c6",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "out/TLC/Syntax.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "out/TLC/Syntax.agda",
"max_line_length": 100,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "out/TLC/Syntax.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 4454,
"size": 6620
} |
{-# OPTIONS --without-K #-}
open import Base
module Integers where
succ : ℤ → ℤ
succ O = pos O
succ (pos n) = pos (S n)
succ (neg O) = O
succ (neg (S n)) = neg n
pred : ℤ → ℤ
pred O = neg O
pred (pos O) = O
pred (pos (S n)) = pos n
pred (neg n) = neg (S n)
abstract
succ-pred : (n : ℤ) → succ (pred n) ≡ n
succ-pred O = refl
succ-pred (pos O) = refl
succ-pred (pos (S n)) = refl
succ-pred (neg n) = refl
pred-succ : (n : ℤ) → pred (succ n) ≡ n
pred-succ O = refl
pred-succ (pos n) = refl
pred-succ (neg O) = refl
pred-succ (neg (S n)) = refl
succ-is-equiv : is-equiv succ
succ-is-equiv = iso-is-eq succ pred succ-pred pred-succ
succ-equiv : ℤ ≃ ℤ
succ-equiv = (succ , succ-is-equiv)
-- Equality on ℕ and ℤ is decidable and both are sets
private
ℕ-get-S : ℕ → ℕ
ℕ-get-S 0 = 42
ℕ-get-S (S n) = n
S-injective : (n m : ℕ) (p : S n ≡ S m) → n ≡ m
S-injective n m p = ap ℕ-get-S p
ℕ-S≢O-type : ℕ → Set
ℕ-S≢O-type O = ⊥
ℕ-S≢O-type (S n) = unit
-- Technical note: You need to write "0" and not "O" in the following types
-- because S and O are both overloaded so Agda is confused by [S n ≢ O]
abstract
ℕ-S≢O : (n : ℕ) → S n ≢ 0
ℕ-S≢O n p = transport ℕ-S≢O-type p tt
ℕ-S≢O#instance : {n : ℕ} → (S n ≢ 0)
ℕ-S≢O#instance {n} = ℕ-S≢O n
ℕ-O≢S : (n : ℕ) → (0 ≢ S n)
ℕ-O≢S n p = ℕ-S≢O n (! p)
ℕ-has-dec-eq : has-dec-eq ℕ
ℕ-has-dec-eq O O = inl refl
ℕ-has-dec-eq O (S n) = inr (ℕ-O≢S n)
ℕ-has-dec-eq (S n) O = inr (ℕ-S≢O n)
ℕ-has-dec-eq (S n) (S m) with ℕ-has-dec-eq n m
ℕ-has-dec-eq (S n) (S m) | inl p = inl (ap S p)
ℕ-has-dec-eq (S n) (S m) | inr p⊥ = inr (λ p → p⊥ (S-injective n m p))
ℕ-is-set : is-set ℕ
ℕ-is-set = dec-eq-is-set ℕ-has-dec-eq
data _<_ : ℕ → ℕ → Set where
<n : {n : ℕ} → n < S n
<S : {n m : ℕ} → (n < m) → (n < S m)
_+_ : ℕ → ℕ → ℕ
0 + m = m
S n + m = S (n + m)
+S-is-S+ : (n m : ℕ) → n + S m ≡ S n + m
+S-is-S+ O m = refl
+S-is-S+ (S n) m = ap S (+S-is-S+ n m)
+0-is-id : (n : ℕ) → n + 0 ≡ n
+0-is-id O = refl
+0-is-id (S n) = ap S (+0-is-id n)
private
ℤ-get-pos : ℤ → ℕ
ℤ-get-pos O = 0
ℤ-get-pos (pos n) = n
ℤ-get-pos (neg n) = 0
pos-injective : (n m : ℕ) (p : pos n ≡ pos m) → n ≡ m
pos-injective n m p = ap ℤ-get-pos p
ℤ-get-neg : ℤ → ℕ
ℤ-get-neg O = 0
ℤ-get-neg (pos n) = 0
ℤ-get-neg (neg n) = n
neg-injective : (n m : ℕ) (p : neg n ≡ neg m) → n ≡ m
neg-injective n m p = ap ℤ-get-neg p
ℤ-neg≢O≢pos-type : ℤ → Set
ℤ-neg≢O≢pos-type O = unit
ℤ-neg≢O≢pos-type (pos n) = ⊥
ℤ-neg≢O≢pos-type (neg n) = ⊥
ℤ-neg≢pos-type : ℤ → Set
ℤ-neg≢pos-type O = unit
ℤ-neg≢pos-type (pos n) = ⊥
ℤ-neg≢pos-type (neg n) = unit
abstract
ℤ-O≢pos : (n : ℕ) → O ≢ pos n
ℤ-O≢pos n p = transport ℤ-neg≢O≢pos-type p tt
ℤ-pos≢O : (n : ℕ) → pos n ≢ O
ℤ-pos≢O n p = transport ℤ-neg≢O≢pos-type (! p) tt
ℤ-O≢neg : (n : ℕ) → O ≢ neg n
ℤ-O≢neg n p = transport ℤ-neg≢O≢pos-type p tt
ℤ-neg≢O : (n : ℕ) → neg n ≢ O
ℤ-neg≢O n p = transport ℤ-neg≢O≢pos-type (! p) tt
ℤ-neg≢pos : (n m : ℕ) → neg n ≢ pos m
ℤ-neg≢pos n m p = transport ℤ-neg≢pos-type p tt
ℤ-pos≢neg : (n m : ℕ) → pos n ≢ neg m
ℤ-pos≢neg n m p = transport ℤ-neg≢pos-type (! p) tt
ℤ-has-dec-eq : has-dec-eq ℤ
ℤ-has-dec-eq O O = inl refl
ℤ-has-dec-eq O (pos n) = inr (ℤ-O≢pos n)
ℤ-has-dec-eq O (neg n) = inr (ℤ-O≢neg n)
ℤ-has-dec-eq (pos n) O = inr (ℤ-pos≢O n)
ℤ-has-dec-eq (pos n) (pos m) with ℕ-has-dec-eq n m
ℤ-has-dec-eq (pos n) (pos m) | inl p = inl (ap pos p)
ℤ-has-dec-eq (pos n) (pos m) | inr p⊥ = inr (λ p → p⊥ (pos-injective n m p))
ℤ-has-dec-eq (pos n) (neg m) = inr (ℤ-pos≢neg n m)
ℤ-has-dec-eq (neg n) O = inr (ℤ-neg≢O n)
ℤ-has-dec-eq (neg n) (pos m) = inr (ℤ-neg≢pos n m)
ℤ-has-dec-eq (neg n) (neg m) with ℕ-has-dec-eq n m
ℤ-has-dec-eq (neg n) (neg m) | inl p = inl (ap neg p)
ℤ-has-dec-eq (neg n) (neg m) | inr p⊥ = inr (λ p → p⊥ (neg-injective n m p))
ℤ-is-set : is-set ℤ
ℤ-is-set = dec-eq-is-set ℤ-has-dec-eq
| {
"alphanum_fraction": 0.533619818,
"avg_line_length": 25.6883116883,
"ext": "agda",
"hexsha": "84f015f7cb0a74ba3abf3f1b8300b65227213bae",
"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/Integers.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/Integers.agda",
"max_line_length": 78,
"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/Integers.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": 1948,
"size": 3956
} |
data Tm : Set where
tzero : Tm
tsucc : Tm → Tm
tdiff : Tm → Tm → Tm
variable
m n n' : Tm
data NotZero : Tm → Set where
nzsucc : NotZero (tsucc n)
nzdiff : NotZero (tdiff m n)
data Equal : Tm → Tm → Set where
esucc : NotZero n → Equal (tsucc (tdiff tzero n)) n
ediff : Equal n n' → Equal (tdiff m n) (tdiff m n')
data Foo : Tm → Set where
fleft : Foo m → Foo (tdiff m n)
frght : Foo n → Foo (tdiff m (tsucc n))
foo : Foo n → Equal n n' → Foo n'
foo (fleft f) e = {!!}
foo (frght (frght f)) (ediff (esucc nz)) = {!nz!} -- case-split on nz replaces nz with nzsucc
| {
"alphanum_fraction": 0.5962521295,
"avg_line_length": 23.48,
"ext": "agda",
"hexsha": "0ba222165823f2d8c10f51b2c77908b03df20a66",
"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/Issue3650.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/Issue3650.agda",
"max_line_length": 93,
"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/Issue3650.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": 235,
"size": 587
} |
module Data.QuadTree.Implementation.ValidTypes where
open import Haskell.Prelude renaming (zero to Z; suc to S)
open import Data.Lens.Lens
open import Data.Logic
open import Data.QuadTree.Implementation.Definition
{-# FOREIGN AGDA2HS
{-# LANGUAGE Safe #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE Rank2Types #-}
import Data.Nat
import Data.Lens.Lens
import Data.Logic
import Data.QuadTree.Implementation.Definition
#-}
---- Valid types
-- Calculates the depth of a quadrant
depth : {t : Set} -> Quadrant t -> Nat
depth (Leaf x) = 0
depth (Node a b c d) = 1 + max4 (depth a) (depth b) (depth c) (depth d)
{-# COMPILE AGDA2HS depth #-}
-- Calculates the maximum legal depth of a quadtree
maxDepth : {t : Set} -> QuadTree t -> Nat
maxDepth (Wrapper (w , h) _) = log2up (max w h)
{-# COMPILE AGDA2HS maxDepth #-}
-- Converts a tree to its root quadrant
treeToQuadrant : {t : Set} -> QuadTree t -> Quadrant t
treeToQuadrant (Wrapper _ qd) = qd
{-# COMPILE AGDA2HS treeToQuadrant #-}
-- Checks whether a quadrant is compressed
isCompressed : {t : Set} -> {{eqT : Eq t}} -> Quadrant t -> Bool
isCompressed (Leaf _) = true
isCompressed (Node (Leaf a) (Leaf b) (Leaf c) (Leaf d)) = not (a == b && b == c && c == d)
isCompressed (Node a b c d) = isCompressed a && isCompressed b && isCompressed c && isCompressed d
{-# COMPILE AGDA2HS isCompressed #-}
-- Checks whether the invariants of a quadrant hold
isValid : {t : Set} -> {{eqT : Eq t}} -> (dep : Nat) -> Quadrant t -> Bool
isValid dep qd = depth qd <= dep && isCompressed qd
{-# COMPILE AGDA2HS isValid #-}
-- A type that represents a valid quadrant
data VQuadrant (t : Set) {{eqT : Eq t}} {dep : Nat} : Set where
CVQuadrant : (qd : Quadrant t) -> {.(IsTrue (isValid dep qd))} -> VQuadrant t {dep}
{-# FOREIGN AGDA2HS
newtype VQuadrant t = CVQuadrant (Quadrant t)
#-}
-- A type that represents a valid quadtree
data VQuadTree (t : Set) {{eqT : Eq t}} {dep : Nat} : Set where
CVQuadTree : (qt : QuadTree t) -> {.(IsTrue (isValid dep (treeToQuadrant qt)))} -> {.(IsTrue (dep == maxDepth qt))} -> VQuadTree t {dep}
{-# FOREIGN AGDA2HS
newtype VQuadTree t = CVQuadTree (QuadTree t)
#-}
qtToSafe : {t : Set} {{eqT : Eq t}} {dep : Nat}
-> (qt : QuadTree t) -> {.(IsTrue (isValid dep (treeToQuadrant qt)))} -> {.(IsTrue (dep == maxDepth qt))}
-> VQuadTree t {maxDepth qt}
qtToSafe {dep = dep} qt {p} {q} = CVQuadTree qt {useEq (cong (λ g -> isValid g (treeToQuadrant qt)) (eqToEquiv dep (maxDepth qt) q)) p} {eqReflexivity (maxDepth qt)}
{-# COMPILE AGDA2HS qtToSafe #-}
qtFromSafe : {t : Set} {{eqT : Eq t}} -> {dep : Nat} -> VQuadTree t {dep} -> QuadTree t
qtFromSafe (CVQuadTree qt) = qt
{-# COMPILE AGDA2HS qtFromSafe #-} | {
"alphanum_fraction": 0.6615785555,
"avg_line_length": 37.8309859155,
"ext": "agda",
"hexsha": "c385f9437ce3ac41ce37ebbd3a4f629b9de19f42",
"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": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "JonathanBrouwer/research-project",
"max_forks_repo_path": "src/Data/QuadTree/Implementation/ValidTypes.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"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": "JonathanBrouwer/research-project",
"max_issues_repo_path": "src/Data/QuadTree/Implementation/ValidTypes.agda",
"max_line_length": 165,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "JonathanBrouwer/research-project",
"max_stars_repo_path": "src/Data/QuadTree/Implementation/ValidTypes.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-25T09:10:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-25T09:10:20.000Z",
"num_tokens": 882,
"size": 2686
} |
------------------------------------------------------------------------
-- Breadth-first labelling of trees
------------------------------------------------------------------------
module BreadthFirst where
open import Codata.Musical.Notation
open import Codata.Musical.Colist using ([]; _∷_; concat)
open import Function
open import Data.Unit
open import Data.List.NonEmpty using (_⁺++⁺_)
open import Relation.Binary.PropositionalEquality as PropEq
using () renaming (refl to ≡-refl)
open import BreadthFirst.Universe
open import BreadthFirst.Programs
open import BreadthFirst.Lemmas
open import Tree using (Tree; leaf; node; map)
open import Stream using (Stream; _≺_)
------------------------------------------------------------------------
-- Breadth-first labelling
label′ : ∀ {A B} → Tree A → Stream B →
ElP (tree ⌈ B ⌉ ⊗ stream ⌈ Stream B ⌉)
label′ t ls = lab t (↓ (⌈ ls ⌉ ≺ ♯ snd (label′ t ls)))
label : ∀ {A B} → Tree A → Stream B → Tree B
label t ls = ⟦ fst (label′ t ls) ⟧
------------------------------------------------------------------------
-- Breadth-first labelling preserves the shape of the tree
shape-preserved′ : ∀ {A B} (t : Tree A)
(lss : ElP (stream ⌈ Stream B ⌉)) →
Eq (tree ⌈ ⊤ ⌉) (map (const tt) ⟦ fst (lab t lss) ⟧)
(map (const tt) t)
shape-preserved′ leaf lss = leaf
shape-preserved′ (node l _ r) lss with whnf lss
... | ⌈ x ≺ ls ⌉ ≺ lss′ =
node (♯ shape-preserved′ (♭ l) (♭ lss′)) ⌈ ≡-refl ⌉
(♯ shape-preserved′ (♭ r) (snd (lab (♭ l) (♭ lss′))))
shape-preserved : ∀ {A B} (t : Tree A) (ls : Stream B) →
Eq (tree ⌈ ⊤ ⌉) (map (const tt) (label t ls))
(map (const tt) t)
shape-preserved t ls = shape-preserved′ t (↓ (⌈ ls ⌉ ≺ _))
------------------------------------------------------------------------
-- Breadth-first labelling uses the right labels
invariant : ∀ {A B} (t : Tree A) lss →
EqP (stream (stream ⌈ B ⌉))
⟦ lss ⟧
(zipWith _⁺++∞_ ⟦ flatten ⟦ fst (lab t lss) ⟧ ⟧
⟦ snd (lab t lss) ⟧)
invariant leaf lss = ⟦ lss ⟧ ∎
invariant (node l _ r) lss with whnf lss
... | ⌈ x ≺ ls ⌉ ≺ lss′ =
(⌈ ≡-refl ⌉ ≺ ♯ refl (♭ ls)) ≺ ♯ (
⟦ ♭ lss′ ⟧ ≊⟨ invariant (♭ l) (♭ lss′) ⟩
zipWith _⁺++∞_ ⟦ flatten ⟦ fst l′ ⟧ ⟧
⟦ snd l′ ⟧ ≊⟨ zipWith-cong ⁺++∞-cong
(⟦ flatten ⟦ fst l′ ⟧ ⟧ ∎)
(invariant (♭ r) (snd l′)) ⟩
zipWith _⁺++∞_
⟦ flatten ⟦ fst l′ ⟧ ⟧
(zipWith _⁺++∞_ ⟦ flatten ⟦ fst r′ ⟧ ⟧
⟦ snd r′ ⟧) ≈⟨ zip-++-assoc (flatten ⟦ fst l′ ⟧)
(flatten ⟦ fst r′ ⟧)
⟦ snd r′ ⟧ ⟩
zipWith _⁺++∞_
⟦ longZipWith _⁺++⁺_ (flatten ⟦ fst l′ ⟧)
(flatten ⟦ fst r′ ⟧) ⟧
⟦ snd r′ ⟧ ∎)
where
l′ = lab (♭ l) (♭ lss′)
r′ = lab (♭ r) (snd l′)
prefix-lemma : ∀ {a} xs xss yss →
Eq (stream (stream a))
(xs ≺ ♯ xss) (zipWith _⁺++∞_ yss xss) →
PrefixOfP a (concat yss) xs
prefix-lemma xs xss [] _ = []
prefix-lemma xs (xs′ ≺ xss) (ys ∷ yss) (xs≈ ≺ xss≈) =
concat (ys ∷ yss) ≋⟨ concat-lemma ys yss ⟩
ys ⁺++ concat (♭ yss) ⊑⟨ ⁺++-mono ys (♯ prefix-lemma xs′ (♭ xss) (♭ yss) ⟦ lemma ⟧≈) ⟩
ys ⁺++∞ xs′ ≈⟨ sym xs≈ ⟩
xs ∎
where
lemma =
xs′ ≺ _ {- ♯ ♭ xss -} ≈⟨ refl xs′ ≺ ♯ refl (♭ xss) ⟩
xs′ ≺ xss ≈⟨ ♭ xss≈ ⟩
zipWith _⁺++∞_ (♭ yss) (♭ xss) ∎
is-prefix : ∀ {A B} (t : Tree A) (ls : Stream B) →
PrefixOf ⌈ B ⌉ (concat ⟦ flatten (label t ls) ⟧) ls
is-prefix {B = B} t ls =
⟦ prefix-lemma ls ⟦ snd l ⟧ ⟦ flatten ⟦ fst l ⟧ ⟧
⟦ ls ≺ _ {- ♯ ⟦ snd l ⟧ -} ≈⟨ refl ls ≺ ♯ refl ⟦ snd l ⟧ ⟩
⟦ ↓ (⌈ ls ⌉ ≺ _) ⟧ ≊⟨ invariant t (↓ ⌈ ls ⌉ ≺ _) ⟩
zipWith _⁺++∞_ ⟦ flatten ⟦ fst l ⟧ ⟧ ⟦ snd l ⟧ ∎ ⟧≈ ⟧⊑
where l = label′ t ls
| {
"alphanum_fraction": 0.3941472337,
"avg_line_length": 42.0576923077,
"ext": "agda",
"hexsha": "95c665debf817cbe98cafaf464802ed3c9113710",
"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": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "BreadthFirst.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"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/codata",
"max_issues_repo_path": "BreadthFirst.agda",
"max_line_length": 89,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "BreadthFirst.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 1526,
"size": 4374
} |
module Compilation.Term where
open import Context
open import Type.Core
open import Type.NbE
import Term.Core as Core
open import Compilation.Data
open import Compilation.Encode.Core
open import Function
open import Data.Empty
open import Data.Sum.Base
open import Data.List.Base as List
infix 3 _⊢_
data Recursivity : Set where
NonRec Rec : Recursivity
caseRec : ∀ {ρ} {R : Set ρ} -> Recursivity -> R -> R -> R
caseRec NonRec x y = x
caseRec Rec x y = y
data _⊢_ {Θ} Γ : Star Θ -> Set where
letType : ∀ {σ β} -> (α : Θ ⊢ᵗ σ) -> shiftᶜ Γ ⊢ β -> Γ ⊢ β [ α ]ᵗ
letTerm : ∀ {α} Δ rec -> Seq (caseRec rec Γ (Γ ▻▻ Δ) ⊢_) Δ -> Γ ▻▻ Δ ⊢ α -> Γ ⊢ α
var : ∀ {α} -> α ∈ Γ -> Γ ⊢ α
Λ_ : ∀ {σ α} -> shiftᶜ Γ ⊢ α -> Γ ⊢ π σ α
_[_] : ∀ {σ β} -> Γ ⊢ π σ β -> (α : Θ ⊢ᵗ σ) -> Γ ⊢ β [ α ]ᵗ
ƛ_ : ∀ {α β} -> Γ ▻ α ⊢ β -> Γ ⊢ α ⇒ β
_·_ : ∀ {α β} -> Γ ⊢ α ⇒ β -> Γ ⊢ α -> Γ ⊢ β
iwrap : ∀ {κ ψ} {α : Θ ⊢ᵗ κ} -> Γ ⊢ Core.unfold ψ α -> Γ ⊢ μ ψ α
unwrap : ∀ {κ ψ} {α : Θ ⊢ᵗ κ} -> Γ ⊢ μ ψ α -> Γ ⊢ Core.unfold ψ α
mutual
compile : ∀ {Θ} {Γ : Con (Star Θ)} {α} -> Γ ⊢ α -> Γ Core.⊢ α
compile (letType α term) = (Core.Λ (compile term)) Core.[ α ]
compile (letTerm Δ rec env term) with rec
... | NonRec = Core.instNonRec (map-compile env) (compile term)
... | Rec = Core.instRec (map-compile env) (compile term)
compile (var v) = Core.var v
compile (Λ body) = Core.Λ (compile body)
compile (fun [ α ]) = compile fun Core.[ α ]
compile (ƛ body) = Core.ƛ (compile body)
compile (fun · arg) = compile fun Core.· compile arg
compile (iwrap term) = Core.iwrap (compile term)
compile (unwrap term) = Core.unwrap (compile term)
-- This is just `mapˢ compile` inlined to convince Agda there are no termination problems.
map-compile : ∀ {Θ} {Γ Δ : Con (Star Θ)} -> Seq (Γ ⊢_) Δ -> Seq (Γ Core.⊢_) Δ
map-compile ø = ø
map-compile (seq ▶ term) = map-compile seq ▶ compile term
| {
"alphanum_fraction": 0.5440669621,
"avg_line_length": 38.320754717,
"ext": "agda",
"hexsha": "10d45dbd29e809016392cda861751d755c19a315",
"lang": "Agda",
"max_forks_count": 399,
"max_forks_repo_forks_event_max_datetime": "2022-03-31T11:18:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-10-05T09:36:10.000Z",
"max_forks_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "AriFordsham/plutus",
"max_forks_repo_path": "papers/unraveling-recursion/code/src/Compilation/Term.agda",
"max_issues_count": 2493,
"max_issues_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T15:31:31.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-09-28T19:28:17.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "AriFordsham/plutus",
"max_issues_repo_path": "papers/unraveling-recursion/code/src/Compilation/Term.agda",
"max_line_length": 92,
"max_stars_count": 1299,
"max_stars_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "AriFordsham/plutus",
"max_stars_repo_path": "papers/unraveling-recursion/code/src/Compilation/Term.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-28T01:10:02.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-02T13:41:39.000Z",
"num_tokens": 785,
"size": 2031
} |
------------------------------------------------------------------------
-- Descending lists
--
-- We present some simple examples to demonstrate
--
-- 1. the concatenation operation on sorted lists obtained by
-- transporting the one on finite multisets, and
--
-- 2. "sorting" finite multisets by converting into sorted lists.
------------------------------------------------------------------------
{-# OPTIONS --cubical --safe #-}
module Cubical.Data.DescendingList.Examples where
open import Cubical.Foundations.Everything
open import Cubical.Data.Empty
open import Cubical.Data.Nat
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.DecidableEq
open import Cubical.HITs.FiniteMultiset
------------------------------------------------------------------------
-- The ordering relation on natural numbers
--
-- we work with the definition from the standard library.
infix 4 _≤_ _≥_
data _≤_ : ℕ → ℕ → Set where
z≤n : ∀ {n} → zero ≤ n
s≤s : ∀ {m n} (m≤n : m ≤ n) → suc m ≤ suc n
_≥_ : ℕ → ℕ → Set
m ≥ n = n ≤ m
≤pred : {n m : ℕ} → suc n ≤ suc m → n ≤ m
≤pred (s≤s r) = r
≥isPropValued : {n m : ℕ} → isProp (n ≥ m)
≥isPropValued z≤n z≤n = refl
≥isPropValued (s≤s p) (s≤s q) = cong s≤s (≥isPropValued p q)
≥dec : (x y : ℕ) → Dec (x ≥ y)
≥dec zero zero = yes z≤n
≥dec zero (suc y) = no (λ ())
≥dec (suc x) zero = yes z≤n
≥dec (suc x) (suc y) with ≥dec x y
≥dec (suc x) (suc y) | yes p = yes (s≤s p)
≥dec (suc x) (suc y) | no ¬p = no (λ r → ¬p (≤pred r))
≰→≥ : {x y : ℕ} → ¬ (x ≥ y) → y ≥ x
≰→≥ {zero} {y} f = z≤n
≰→≥ {suc x} {zero} f = ⊥-elim (f z≤n)
≰→≥ {suc x} {suc y} f = s≤s (≰→≥ λ g → f (s≤s g))
≥trans : {x y z : ℕ} → x ≥ y → y ≥ z → x ≥ z
≥trans z≤n z≤n = z≤n
≥trans (s≤s r) z≤n = z≤n
≥trans (s≤s r) (s≤s s) = s≤s (≥trans r s)
≤≥→≡ : {x y : ℕ} → x ≥ y → y ≥ x → x ≡ y
≤≥→≡ z≤n z≤n = refl
≤≥→≡ (s≤s r) (s≤s s) = cong suc (≤≥→≡ r s)
open import Cubical.Data.DescendingList.Base ℕ _≥_
open import Cubical.Data.DescendingList.Properties ℕ _≥_
open isSetDL ≥isPropValued discreteℕ
open IsoToFMSet discreteℕ ≥dec ≥isPropValued ≥trans ≰→≥ ≤≥→≡
------------------------------------------------------------------------
-- A simple example of concatenating sorted lists
l1 : DL
l1 = cons 4 (cons 3 (cons 2 [] ≥ᴴ[]) (≥ᴴcons (s≤s (s≤s z≤n)))) (≥ᴴcons (s≤s (s≤s (s≤s z≤n))))
l2 : DL
l2 = cons 2 (cons 0 [] ≥ᴴ[]) (≥ᴴcons z≤n)
l3 : DL
l3 = l1 ++ᴰᴸ l2
ValueOfl3 : l3 ≡ cons 4 (cons 3 (cons 2 (cons 2 (cons 0 _ _) _) _) _) _
ValueOfl3 = refl
l3=l2++l1 : l3 ≡ l2 ++ᴰᴸ l1
l3=l2++l1 = refl
LongerExample : l1 ++ᴰᴸ l2 ++ᴰᴸ l1 ++ᴰᴸ l1 ++ᴰᴸ l2
≡ l2 ++ᴰᴸ l1 ++ᴰᴸ l2 ++ᴰᴸ l1 ++ᴰᴸ l1
LongerExample = refl
------------------------------------------------------------------------
-- A simple example of sorting finite multisets
m1 : FMSet ℕ
m1 = 13 ∷ 9 ∷ 78 ∷ 31 ∷ 86 ∷ 3 ∷ 0 ∷ 99 ∷ []
m2 : FMSet ℕ
m2 = 3 ∷ 1 ∷ 4 ∷ 1 ∷ 5 ∷ 9 ∷ []
m3 : FMSet ℕ
m3 = toFMSet (toDL (m1 ++ m2))
ValueOfm3 :
m3 ≡ 99 ∷ 86 ∷ 78 ∷ 31 ∷ 13 ∷ 9 ∷ 9 ∷ 5 ∷ 4 ∷ 3 ∷ 3 ∷ 1 ∷ 1 ∷ 0 ∷ []
ValueOfm3 = refl
ValueOfm1++m2 :
m1 ++ m2 ≡ 13 ∷ 9 ∷ 78 ∷ 31 ∷ 86 ∷ 3 ∷ 0 ∷ 99 ∷ 3 ∷ 1 ∷ 4 ∷ 1 ∷ 5 ∷ 9 ∷ []
ValueOfm1++m2 = refl
m3=m1++m2 : m3 ≡ m1 ++ m2
m3=m1++m2 = toFMSet∘toDL≡id (m1 ++ m2)
| {
"alphanum_fraction": 0.5007727975,
"avg_line_length": 26.7355371901,
"ext": "agda",
"hexsha": "6f697ebf034d03e5225944756fbd8e072cc89ab3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Data/DescendingList/Examples.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Data/DescendingList/Examples.agda",
"max_line_length": 93,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/Data/DescendingList/Examples.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1459,
"size": 3235
} |
module UniDB where
open import UniDB.Morph.Depth public
open import UniDB.Morph.Pair public
open import UniDB.Morph.Reg public
open import UniDB.Morph.Shift public
open import UniDB.Morph.Shifts public
open import UniDB.Morph.ShiftsPrime public
open import UniDB.Morph.Sim public
open import UniDB.Morph.Star public
open import UniDB.Morph.StarPrime public
open import UniDB.Morph.Sub public
open import UniDB.Morph.Subs public
open import UniDB.Morph.Sum public
open import UniDB.Morph.Unit public
open import UniDB.Morph.Weaken public
open import UniDB.Morph.WeakenOne public
open import UniDB.Morph.WeakenPrime public
open import UniDB.Spec public
open import UniDB.Subst public
open import UniDB.Subst.Inst public
open import UniDB.Subst.Pair public
open import UniDB.Subst.Reg public
open import UniDB.Subst.Shifts public
open import UniDB.Subst.Star public
open import UniDB.Subst.StarPrime public
open import UniDB.Subst.Subs public
open import UniDB.Subst.Sum public
| {
"alphanum_fraction": 0.8372569089,
"avg_line_length": 32.5666666667,
"ext": "agda",
"hexsha": "b92f1e53f9b4a1b0934d1f602845028021922c1e",
"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.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.agda",
"max_line_length": 42,
"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.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 261,
"size": 977
} |
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module CombiningProofs.Eta where
infix 7 _≡_
infix 5 ∃
postulate
D : Set
∃ : (A : D → Set) → Set
_≡_ : D → D → Set
syntax ∃ (λ x → e) = ∃[ x ] e
postulate
t₁ : ∀ d → ∃[ e ] d ≡ e
t₂ : ∀ d → ∃ (_≡_ d)
| {
"alphanum_fraction": 0.4680306905,
"avg_line_length": 18.619047619,
"ext": "agda",
"hexsha": "554aa2d0e969fabdeb1232a7f10312c2a33bb893",
"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": "notes/thesis/report/CombiningProofs/Eta.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": "notes/thesis/report/CombiningProofs/Eta.agda",
"max_line_length": 42,
"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": "notes/thesis/report/CombiningProofs/Eta.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": 144,
"size": 391
} |
module WrongDotPattern where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data NonZero : Nat -> Set where
nonZ : (n : Nat) -> NonZero (suc n)
f : (n : Nat) -> NonZero n -> Nat
f .zero (nonZ n) = n
| {
"alphanum_fraction": 0.5868544601,
"avg_line_length": 15.2142857143,
"ext": "agda",
"hexsha": "1c55681cdb07269fca0fbfe10d738d4b0a97f291",
"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/WrongDotPattern.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/WrongDotPattern.agda",
"max_line_length": 37,
"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/WrongDotPattern.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": 77,
"size": 213
} |
-- {-# OPTIONS -v tc.polarity:15 #-}
module Issue166 where
open import Common.Size
open import Common.Prelude
module M (A : Set) where
data SizedNat : {i : Size} → Set where
zero : {i : Size} → SizedNat {↑ i}
suc : {i : Size} → SizedNat {i} → SizedNat {↑ i}
module M′ = M ⊥
| {
"alphanum_fraction": 0.6055363322,
"avg_line_length": 20.6428571429,
"ext": "agda",
"hexsha": "bb0595b307c71b52fb0ea1e73a127356ab775d22",
"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/Issue166.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/Issue166.agda",
"max_line_length": 53,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue166.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": 96,
"size": 289
} |
open import Prelude hiding (⊥)
module Implicits.Resolution.Infinite.Algorithm where
open import Data.Bool
open import Data.Unit.Base
open import Data.Maybe using (is-just; functor)
open import Coinduction
open import Data.Fin.Substitution
open import Data.Vec hiding (_>>=_)
open import Data.List hiding (monad)
open import Data.List.Any hiding (tail)
open import Data.Maybe hiding (monad; module Eq)
open import Implicits.Syntax
open import Implicits.Substitutions
open import Implicits.Substitutions.Lemmas
open import Implicits.Syntax.Type.Unification
open import Implicits.Resolution.Termination
open import Category.Monad
open import Category.Functor
open import Category.Monad.Partiality as P
open import Category.Monad.Partiality.All
private module M {f} = RawMonad (monad {f})
private module MaybeFunctor {f} = RawFunctor (functor {f})
open import Induction.WellFounded
open import Induction.Nat
module _ where
open P.Workaround
m<-Acc : ∀ {m ν} → MetaType m ν → Set
m<-Acc {m} {ν} r = Acc _m<_ (m , ν , r)
mutual
map-bool' : ∀ {A : Set} → A → Bool → Maybe A ⊥P
map-bool' u true = now (just u)
map-bool' u false = now nothing
delayed-resolve' : ∀ {ν} (Δ : ICtx ν) a → Bool ⊥P
delayed-resolve' Δ a = (later (♯ (resolve' Δ a)))
resolve-context' : ∀ {ν m} (Δ : ICtx ν) a → (Maybe (Sub (flip MetaType ν) m zero)) →
(Maybe (Sub (flip MetaType ν) m zero)) ⊥P
resolve-context' Δ a (just u) =
(delayed-resolve' Δ (from-meta (MetaTypeMetaSubst._/_ a u)))
>>= (map-bool' u)
resolve-context' Δ a nothing = now nothing
-- match' uses MetaType m ν instead of Type ν to be able to distinguish unification variables
-- from other, non-unifiable tvars.
-- The difference is subtle but the gist is that we can only unify variables that we open
-- during matching. Any variables that are already open in the context are fixed.
match-u' : ∀ {ν m} (Δ : ICtx ν) → (τ : SimpleType ν) → (r : MetaType m ν) →
m<-Acc r →
(Maybe (Sub (flip MetaType ν) m zero)) ⊥P
-- For rule types we first check if b matches our query τ.
-- If this is the case, we use the unifier to instantiate the unification vars in a and
-- recursively try to resolve the result.
match-u' {ν} {m} Δ τ (a ⇒ b) (acc f) =
(match-u' Δ τ b (f _ (b-m<-a⇒b a b))) >>= (resolve-context' Δ a)
-- On type vars we simply open it up, adding the tvar to the set of unification variables.
-- and recursively try to match.
match-u' Δ τ (∀' a) (acc f) = (match-u' Δ τ (open-meta a) (f _ (open-meta-a-m<-∀'a a))) >>=
(now ∘ (MaybeFunctor._<$>_ tail))
-- The only thing left to do is to try and unify τ and x.
match-u' Δ τ (simpl x) _ = now (mgu (simpl x) τ)
match' : ∀ {ν} (Δ : ICtx ν) → (τ : SimpleType ν) → Type ν → Bool ⊥P
match' {ν} Δ τ r = match-u' Δ τ (to-meta {zero} r) (m<-well-founded _) >>= (now ∘ is-just)
match1st-recover' : ∀ {ν} (Δ ρs : ICtx ν) → (τ : SimpleType ν) → Bool → Bool ⊥P
match1st-recover' _ _ _ true = now true
match1st-recover' Δ ρs τ false = match1st' Δ ρs τ
match1st' : ∀ {ν} (Δ : ICtx ν) → (ρs : ICtx ν) → (τ : SimpleType ν) → Bool ⊥P
match1st' Δ List.[] _ = now false
match1st' Δ (x List.∷ ρs) τ = match' Δ τ x >>= (match1st-recover' Δ ρs τ)
-- resolution in ResP
resolve' : ∀ {ν} (Δ : ICtx ν) (a : Type ν) → Bool ⊥P
resolve' Δ (simpl x) = match1st' Δ Δ x
resolve' Δ (a ⇒ b) = resolve' (a List.∷ Δ) b
resolve' Δ (∀' a) = resolve' (ictx-weaken Δ) a
module _ where
open P.Workaround using (⟦_⟧P)
open P.Workaround.Correct
open M
module Eq {l} {A : Set l} where
open import Relation.Binary.PropositionalEquality as PEq using (_≡_) public
open module Eq = P.Equality {A = A} _≡_ public
open module R = P.Reasoning (PEq.isEquivalence {A = A}) public
map-bool : ∀ {A : Set} → A → Bool → (Maybe A) ⊥
map-bool x b = ⟦ map-bool' x b ⟧P
delayed-resolve : ∀ {ν} (Δ : ICtx ν) a → Bool ⊥
delayed-resolve Δ a = ⟦ delayed-resolve' Δ a ⟧P
resolve-context : ∀ {ν m} (Δ : ICtx ν) a → (Maybe (Sub (flip MetaType ν) m zero)) →
(Maybe (Sub (flip MetaType ν) m zero)) ⊥
resolve-context Δ a p = ⟦ resolve-context' Δ a p ⟧P
match-u : ∀ {ν m} (Δ : ICtx ν) → SimpleType ν → (r : MetaType m ν) → m<-Acc r →
(Maybe (Sub (flip MetaType ν) m zero)) ⊥
match-u Δ τ r f = ⟦ match-u' Δ τ r f ⟧P
match : ∀ {ν} (Δ : ICtx ν) → (τ : SimpleType ν) → (r : Type ν) → Bool ⊥
match Δ τ r = ⟦ match' Δ τ r ⟧P
match1st-recover : ∀ {ν} (Δ : ICtx ν) → (ρs : ICtx ν) → (τ : SimpleType ν) → Bool → Bool ⊥
match1st-recover Δ ρs τ b = ⟦ match1st-recover' Δ ρs τ b ⟧P
match1st : ∀ {ν} (Δ : ICtx ν) → (ρs : ICtx ν) → (τ : SimpleType ν) → Bool ⊥
match1st Δ ρs τ = ⟦ match1st' Δ ρs τ ⟧P
resolve : ∀ {ν} (Δ : ICtx ν) (r : Type ν) → Bool ⊥
resolve Δ r = ⟦ resolve' Δ r ⟧P
--
-- compositionality of resolution functions
--
resolve-context-comp : ∀ {m ν} (Δ : ICtx ν) a u →
(resolve-context {ν} {m} Δ a (just u))
Eq.≅
(delayed-resolve Δ (from-meta (MetaTypeMetaSubst._/_ a u))
>>= (map-bool u))
resolve-context-comp {m} {ν} Δ a u =
(resolve-context {ν} {m} Δ a (just u))
Eq.≅⟨ >>=-hom (delayed-resolve' Δ (from-meta (MetaTypeMetaSubst._/_ a u))) _ ⟩
(delayed-resolve Δ (from-meta (MetaTypeMetaSubst._/_ a u)) >>= (map-bool u)) Eq.∎
match-u-iabs-comp : ∀ {m ν} (Δ : ICtx ν) τ (a b : MetaType m ν) f →
(match-u Δ τ (a ⇒ b) (acc f))
Eq.≅
((match-u Δ τ b (f _ (b-m<-a⇒b a b))) >>= (resolve-context Δ a))
match-u-iabs-comp Δ τ a b f =
(match-u Δ τ (a ⇒ b) (acc f))
Eq.≅⟨ >>=-hom (match-u' Δ τ b (f _ (b-m<-a⇒b a b))) _ ⟩
((match-u Δ τ b (f _ (b-m<-a⇒b a b))) >>= (resolve-context Δ a)) Eq.∎
match-u-tabs-comp : ∀ {m ν} (Δ : ICtx ν) τ (r : MetaType m (suc ν)) f →
(match-u Δ τ (∀' r) (acc f))
Eq.≅
((match-u Δ τ (open-meta r) (f _ (open-meta-a-m<-∀'a r))) >>=
(now ∘ (MaybeFunctor._<$>_ tail)))
match-u-tabs-comp Δ τ r f =
match-u Δ τ (∀' r) (acc f)
Eq.≅⟨ >>=-hom (match-u' Δ τ (open-meta r) (f _ (open-meta-a-m<-∀'a r))) _ ⟩
((match-u Δ τ (open-meta r) (f _ (open-meta-a-m<-∀'a r))) >>= (now ∘ (MaybeFunctor._<$>_ tail))) Eq.∎
match-comp : ∀ {ν} (Δ : ICtx ν) τ r →
match Δ τ r
Eq.≅
((match-u Δ τ (to-meta {zero} r) (m<-well-founded _)) >>= (now ∘ is-just))
match-comp Δ τ r =
match Δ τ r
Eq.≅⟨ >>=-hom (match-u' Δ τ (to-meta {zero} r) (m<-well-founded _)) _ ⟩
_>>=_ (match-u Δ τ (to-meta {zero} r) (m<-well-founded _)) (now ∘ is-just) Eq.∎
match1st-comp : ∀ {ν} (Δ : ICtx ν) x ρs τ → match1st Δ (x List.∷ ρs) τ Eq.≅ ((match Δ τ x) >>=
(match1st-recover Δ ρs τ))
match1st-comp Δ x ρs τ =
match1st Δ (x List.∷ ρs) τ
Eq.≅⟨ >>=-hom (match' Δ τ x) _ ⟩
((match Δ τ x) >>= (match1st-recover Δ ρs τ)) Eq.∎
| {
"alphanum_fraction": 0.5576789918,
"avg_line_length": 41.2628571429,
"ext": "agda",
"hexsha": "f26291b0d2b22fd01f7e02079c488c7c2613ec08",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/Infinite/Algorithm.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/Infinite/Algorithm.agda",
"max_line_length": 105,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/Infinite/Algorithm.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": 2595,
"size": 7221
} |
module RAdjunctions where
open import Library
open import Categories
open import Functors
open Cat
open Fun
record RAdj {a b c d e f}{C : Cat {a}{b}}{D : Cat {c}{d}}
(J : Fun C D)(E : Cat {e}{f}) : Set (a ⊔ b ⊔ c ⊔ d ⊔ e ⊔ f) where
constructor radjunction
field L : Fun C E
R : Fun E D
left : {X : Obj C}{Y : Obj E} →
Hom E (OMap L X) Y → Hom D (OMap J X) (OMap R Y)
right : {X : Obj C}{Y : Obj E} →
Hom D (OMap J X) (OMap R Y) → Hom E (OMap L X) Y
lawa : {X : Obj C}{Y : Obj E}(f : Hom E (OMap L X) Y) →
right (left f) ≅ f
lawb : {X : Obj C}{Y : Obj E}(f : Hom D (OMap J X) (OMap R Y)) →
left (right f) ≅ f
natleft : {X X' : Obj C}{Y Y' : Obj E}
(f : Hom C X' X)(g : Hom E Y Y')
(h : Hom E (OMap L X) Y) →
comp D (HMap R g) (comp D (left h) (HMap J f))
≅
left (comp E g (comp E h (HMap L f)))
natright : {X X' : Obj C}{Y Y' : Obj E}
(f : Hom C X' X)(g : Hom E Y Y')
(h : Hom D (OMap J X) (OMap R Y)) →
right (comp D (HMap R g) (comp D h (HMap J f)))
≅
comp E g (comp E (right h) (HMap L f))
| {
"alphanum_fraction": 0.3949090909,
"avg_line_length": 39.2857142857,
"ext": "agda",
"hexsha": "3ccd5264bfc5c969404bf6084a1cded11665608c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "RAdjunctions.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "RAdjunctions.agda",
"max_line_length": 77,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "RAdjunctions.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 479,
"size": 1375
} |
------------------------------------------------------------------------
-- Some negative results related to weak bisimilarity and expansion
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
open import Prelude
open import Prelude.Size
module Delay-monad.Sized.Bisimilarity.Negative
{a} {A : Size → Type a} where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Function-universe equality-with-J hiding (id; _∘_)
open import Delay-monad.Sized
open import Delay-monad.Sized.Bisimilarity
open import Delay-monad.Sized.Termination
------------------------------------------------------------------------
-- Lemmas stating that functions of certain types cannot be defined if
-- ∀ i → A i is inhabited
-- An abbreviation. (Note that, because pattern-matching lambdas like
-- the one in this definition are—at least at the time of
-- writing—compared by "name", Agda rejects the code that one gets if
-- this abbreviation is inlined below.)
later-now : (∀ i → A i) → ∀ {i} → Delay A i
later-now x = later λ { .force {j} → now (x j) }
-- If now (x ∞) is an expansion of later-now x for every
-- x : ∀ i → A i, then ∀ i → A i is uninhabited.
Now≳later-now = (x : ∀ i → A i) → now (x ∞) ≳ later-now x
now≳later-now→uninhabited : Now≳later-now → ¬ (∀ i → A i)
now≳later-now→uninhabited =
Now≳later-now ↝⟨ (λ hyp x → case hyp x of λ ()) ⟩□
¬ (∀ i → A i) □
-- If a variant of laterˡ⁻¹ for (fully defined) expansion can be
-- defined, then ∀ i → A i is uninhabited.
Laterˡ⁻¹-≳ = ∀ {x} {y : Delay A ∞} → later x ≳ y → force x ≳ y
laterˡ⁻¹-≳→uninhabited : Laterˡ⁻¹-≳ → ¬ (∀ i → A i)
laterˡ⁻¹-≳→uninhabited =
Laterˡ⁻¹-≳ ↝⟨ (λ hyp _ → hyp (reflexive _)) ⟩
Now≳later-now ↝⟨ now≳later-now→uninhabited ⟩□
¬ (∀ i → A i) □
-- If the following variants of transitivity can be proved, then
-- ∀ i → A i is uninhabited.
Transitivity-≈≳≳ = {x y z : Delay A ∞} → x ≈ y → y ≳ z → x ≳ z
Transitivity-≳≈≳ = {x y z : Delay A ∞} → x ≳ y → y ≈ z → x ≳ z
transitive-≈≳≳→uninhabited : Transitivity-≈≳≳ → ¬ (∀ i → A i)
transitive-≈≳≳→uninhabited =
Transitivity-≈≳≳ ↝⟨ (λ trans → trans (laterʳ (reflexive _))) ⟩
Laterˡ⁻¹-≳ ↝⟨ laterˡ⁻¹-≳→uninhabited ⟩□
¬ (∀ i → A i) □
transitive-≳≈≳→uninhabited : Transitivity-≳≈≳ → ¬ (∀ i → A i)
transitive-≳≈≳→uninhabited =
Transitivity-≳≈≳ ↝⟨ (λ trans x → later⁻¹ {y = λ { .force → later-now x }}
(trans (reflexive _) (laterʳ (reflexive _)))) ⟩
Now≳later-now ↝⟨ now≳later-now→uninhabited ⟩□
¬ (∀ i → A i) □
------------------------------------------------------------------------
-- Lemmas stating that certain size-preserving functions cannot be
-- defined if ∀ i → A i is inhabited, and related results
-- If a variant of laterˡ⁻¹ in which one occurrence of weak
-- bisimilarity is replaced by strong bisimilarity, and both arguments
-- are specialised, can be made size-preserving, then ∀ i → A i is
-- uninhabited.
--
-- This lemma is used to prove all other similar results below
-- (directly or indirectly).
Laterˡ⁻¹-∼≈ = ∀ {i} (x : ∀ i → A i) →
[ i ] later (λ { .force {j = j} → now (x j) }) ∼ never →
[ i ] now {A = A} (x ∞) ≈ never
size-preserving-laterˡ⁻¹-∼≈→uninhabited :
Laterˡ⁻¹-∼≈ → ¬ (∀ i → A i)
size-preserving-laterˡ⁻¹-∼≈→uninhabited laterˡ⁻¹-∼≈ x =
contradiction ∞
where
mutual
now≈never : ∀ {i} → [ i ] now (x ∞) ≈ never
now≈never = laterˡ⁻¹-∼≈ x (later now∼never)
now∼never : ∀ {i} → [ i ] now (x ∞) ∼′ never
force now∼never {j = j} = ⊥-elim (contradiction j)
contradiction : Size → ⊥
contradiction i = now≉never (now≈never {i = i})
-- A logically equivalent variant of Laterˡ⁻¹-∼≈ which it is sometimes
-- easier to work with.
Laterˡ⁻¹-∼≈′ = ∀ {i} (x : ∀ i → A i) →
[ i ] later (record { force = λ {j} → now (x j) }) ∼ never →
[ i ] now {A = A} (x ∞) ≈ never
size-preserving-laterˡ⁻¹-∼≈⇔size-preserving-laterˡ⁻¹-∼≈′ :
Laterˡ⁻¹-∼≈ ⇔ Laterˡ⁻¹-∼≈′
size-preserving-laterˡ⁻¹-∼≈⇔size-preserving-laterˡ⁻¹-∼≈′ = record
{ to = λ laterˡ⁻¹ x → laterˡ⁻¹ x ∘ transitive-∼ˡ (later λ { .force → now })
; from = λ laterˡ⁻¹ x → laterˡ⁻¹ x ∘ transitive-∼ˡ (later λ { .force → now })
}
-- The type Laterˡ⁻¹-∼≈′ is logically equivalent to the similar type
-- Laterʳ⁻¹-∼≈′.
Laterʳ⁻¹-∼≈′ = ∀ {i} (x : ∀ i → A i) →
[ i ] never ∼ later (record { force = λ {j} → now (x j) }) →
[ i ] never ≈ now {A = A} (x ∞)
size-preserving-laterˡ⁻¹-∼≈′⇔size-preserving-laterʳ⁻¹-∼≈′ :
Laterˡ⁻¹-∼≈′ ⇔ Laterʳ⁻¹-∼≈′
size-preserving-laterˡ⁻¹-∼≈′⇔size-preserving-laterʳ⁻¹-∼≈′ =
record { to = λ laterˡ⁻¹ {_} _ → symmetric ∘ laterˡ⁻¹ _ ∘ symmetric
; from = λ laterʳ⁻¹ {_} _ → symmetric ∘ laterʳ⁻¹ _ ∘ symmetric
}
-- The type Laterʳ⁻¹-∼≈′ is logically equivalent to the similar type
-- Laterʳ⁻¹-∼≳′.
Laterʳ⁻¹-∼≳′ = ∀ {i} (x : ∀ i → A i) →
[ i ] never ∼ later (record { force = λ {j} → now (x j) }) →
[ i ] never ≳ now {A = A} (x ∞)
size-preserving-laterʳ⁻¹-∼≈′⇔size-preserving-laterʳ⁻¹-∼≳′ :
Laterʳ⁻¹-∼≈′ ⇔ Laterʳ⁻¹-∼≳′
size-preserving-laterʳ⁻¹-∼≈′⇔size-preserving-laterʳ⁻¹-∼≳′ =
record { to = λ laterʳ⁻¹ {_} _ → ≈→-now ∘ laterʳ⁻¹ _
; from = λ laterʳ⁻¹ {_} _ → ≳→ ∘ laterʳ⁻¹ _
}
-- If Laterʳ⁻¹-∼≳′ is inhabited, then ∀ i → A i is uninhabited.
size-preserving-laterʳ⁻¹-∼≳′→uninhabited : Laterʳ⁻¹-∼≳′ → ¬ (∀ i → A i)
size-preserving-laterʳ⁻¹-∼≳′→uninhabited =
Laterʳ⁻¹-∼≳′ ↝⟨ _⇔_.from size-preserving-laterʳ⁻¹-∼≈′⇔size-preserving-laterʳ⁻¹-∼≳′ ⟩
Laterʳ⁻¹-∼≈′ ↝⟨ _⇔_.from size-preserving-laterˡ⁻¹-∼≈′⇔size-preserving-laterʳ⁻¹-∼≈′ ⟩
Laterˡ⁻¹-∼≈′ ↝⟨ _⇔_.from size-preserving-laterˡ⁻¹-∼≈⇔size-preserving-laterˡ⁻¹-∼≈′ ⟩
Laterˡ⁻¹-∼≈ ↝⟨ size-preserving-laterˡ⁻¹-∼≈→uninhabited ⟩□
¬ (∀ i → A i) □
-- Having a size-preserving variant of laterˡ⁻¹ is logically
-- equivalent to having a size-preserving variant of laterʳ⁻¹ (for
-- weak bisimilarity).
Laterˡ⁻¹-≈ = ∀ {i x} {y : Delay A ∞} →
[ i ] later x ≈ y →
[ i ] force x ≈ y
Laterʳ⁻¹-≈ = ∀ {i} {x : Delay A ∞} {y} →
[ i ] x ≈ later y →
[ i ] x ≈ force y
size-preserving-laterˡ⁻¹-≈⇔size-preserving-laterʳ⁻¹-≈ :
Laterˡ⁻¹-≈ ⇔ Laterʳ⁻¹-≈
size-preserving-laterˡ⁻¹-≈⇔size-preserving-laterʳ⁻¹-≈ = record
{ to = λ laterʳ⁻¹ → symmetric ∘ laterʳ⁻¹ ∘ symmetric
; from = λ laterˡ⁻¹ → symmetric ∘ laterˡ⁻¹ ∘ symmetric
}
-- If laterˡ⁻¹ can be made size-preserving, then ∀ i → A i is
-- uninhabited.
size-preserving-laterˡ⁻¹-≈→uninhabited : Laterˡ⁻¹-≈ → ¬ (∀ i → A i)
size-preserving-laterˡ⁻¹-≈→uninhabited =
Laterˡ⁻¹-≈ ↝⟨ (λ laterˡ⁻¹ _ → laterˡ⁻¹ ∘ ∼→) ⟩
Laterˡ⁻¹-∼≈ ↝⟨ size-preserving-laterˡ⁻¹-∼≈→uninhabited ⟩□
¬ (∀ i → A i) □
-- If laterʳ⁻¹ can be made size-preserving for expansion, then
-- ∀ i → A i is uninhabited.
Laterʳ⁻¹-≳ = ∀ {i} {x : Delay A ∞} {y} →
[ i ] x ≳ later y →
[ i ] x ≳ force y
size-preserving-laterʳ⁻¹-≳→uninhabited : Laterʳ⁻¹-≳ → ¬ (∀ i → A i)
size-preserving-laterʳ⁻¹-≳→uninhabited =
Laterʳ⁻¹-≳ ↝⟨ (λ laterʳ⁻¹ {_} _ p → laterʳ⁻¹ (∼→ p)) ⟩
Laterʳ⁻¹-∼≳′ ↝⟨ size-preserving-laterʳ⁻¹-∼≳′→uninhabited ⟩□
¬ (∀ i → A i) □
-- If a variant of ⇓-respects-≈ in which _≈_ is replaced by _∼_ can be
-- made size-preserving in the second argument, then ∀ i → A i is
-- uninhabited.
⇓-Respects-∼ʳ = ∀ {i} {x y : Delay A ∞} {z} →
x ⇓ z → [ i ] x ∼ y → Terminates i y z
size-preserving-⇓-respects-∼ʳ→uninhabited :
⇓-Respects-∼ʳ → ¬ (∀ i → A i)
size-preserving-⇓-respects-∼ʳ→uninhabited =
⇓-Respects-∼ʳ ↝⟨ (λ resp _ → resp (laterʳ now)) ⟩
Laterˡ⁻¹-∼≈ ↝⟨ size-preserving-laterˡ⁻¹-∼≈→uninhabited ⟩□
¬ (∀ i → A i) □
-- If ⇓-respects-≈ can be made size-preserving in the second argument,
-- then ∀ i → A i is uninhabited.
⇓-Respects-≈ʳ = ∀ {i} {x y : Delay A ∞} {z} →
x ⇓ z → [ i ] x ≈ y → Terminates i y z
size-preserving-⇓-respects-≈ʳ→uninhabited :
⇓-Respects-≈ʳ → ¬ (∀ i → A i)
size-preserving-⇓-respects-≈ʳ→uninhabited =
⇓-Respects-≈ʳ ↝⟨ (λ trans x⇓z → trans x⇓z ∘ ∼→) ⟩
⇓-Respects-∼ʳ ↝⟨ size-preserving-⇓-respects-∼ʳ→uninhabited ⟩□
¬ (∀ i → A i) □
-- Having a transitivity-like proof, taking weak bisimilarity and
-- strong bisimilarity to weak bisimilarity, that preserves the size
-- of the second argument, is logically equivalent to having a
-- transitivity-like proof, taking strong bisimilarity and weak
-- bisimilarity to weak bisimilarity, that preserves the size of the
-- first argument.
Transitivity-≈∼ʳ = ∀ {i} {x y z : Delay A ∞} →
x ≈ y → [ i ] y ∼ z → [ i ] x ≈ z
Transitivity-∼≈ˡ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ∼ y → y ≈ z → [ i ] x ≈ z
size-preserving-transitivity-≈∼ʳ⇔size-preserving-transitivity-∼≈ˡ :
Transitivity-≈∼ʳ ⇔ Transitivity-∼≈ˡ
size-preserving-transitivity-≈∼ʳ⇔size-preserving-transitivity-∼≈ˡ =
record
{ to = λ trans p q → symmetric (trans (symmetric q) (symmetric p))
; from = λ trans p q → symmetric (trans (symmetric q) (symmetric p))
}
-- If there is a transitivity-like proof, taking weak bisimilarity and
-- strong bisimilarity to weak bisimilarity, that preserves the size
-- of the second argument, then ∀ i → A i is uninhabited.
size-preserving-transitivity-≈∼ʳ→uninhabited :
Transitivity-≈∼ʳ → ¬ (∀ i → A i)
size-preserving-transitivity-≈∼ʳ→uninhabited =
Transitivity-≈∼ʳ ↝⟨ (λ trans → trans) ⟩
⇓-Respects-∼ʳ ↝⟨ size-preserving-⇓-respects-∼ʳ→uninhabited ⟩
¬ (∀ i → A i) □
-- If there is a transitivity-like proof, taking strong bisimilarity
-- and expansion to expansion, that preserves the size of the first
-- argument, then ∀ i → A i is uninhabited.
Transitivity-∼≳ˡ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ∼ y → y ≳ z → [ i ] x ≳ z
size-preserving-transitivity-∼≳ˡ→uninhabited :
Transitivity-∼≳ˡ → ¬ (∀ i → A i)
size-preserving-transitivity-∼≳ˡ→uninhabited =
Transitivity-∼≳ˡ ↝⟨ (λ trans _ p → trans p (laterˡ now)) ⟩
Laterʳ⁻¹-∼≳′ ↝⟨ size-preserving-laterʳ⁻¹-∼≳′→uninhabited ⟩
¬ (∀ i → A i) □
-- Having a transitivity proof for weak bisimilarity that preserves
-- the size of the first argument is logically equivalent to having
-- one that preserves the size of the second argument.
Transitivity-≈ˡ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≈ y → y ≈ z → [ i ] x ≈ z
Transitivity-≈ʳ = ∀ {i} {x y z : Delay A ∞} →
x ≈ y → [ i ] y ≈ z → [ i ] x ≈ z
size-preserving-transitivity-≈ˡ⇔size-preserving-transitivity-≈ʳ :
Transitivity-≈ˡ ⇔ Transitivity-≈ʳ
size-preserving-transitivity-≈ˡ⇔size-preserving-transitivity-≈ʳ = record
{ to = λ trans p q → symmetric (trans (symmetric q) (symmetric p))
; from = λ trans p q → symmetric (trans (symmetric q) (symmetric p))
}
-- If there is a transitivity proof for weak bisimilarity that
-- preserves the size of the second argument, then ∀ i → A i is
-- uninhabited.
size-preserving-transitivity-≈ʳ→uninhabited :
Transitivity-≈ʳ → ¬ (∀ i → A i)
size-preserving-transitivity-≈ʳ→uninhabited =
Transitivity-≈ʳ ↝⟨ (λ trans → trans) ⟩
⇓-Respects-≈ʳ ↝⟨ size-preserving-⇓-respects-≈ʳ→uninhabited ⟩□
¬ (∀ i → A i) □
-- If there is a transitivity proof for expansion that preserves the
-- size of the first argument, then ∀ i → A i is uninhabited.
Transitivity-≳ˡ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≳ y → y ≳ z → [ i ] x ≳ z
size-preserving-transitivity-≳ˡ→uninhabited :
Transitivity-≳ˡ → ¬ (∀ i → A i)
size-preserving-transitivity-≳ˡ→uninhabited =
Transitivity-≳ˡ ↝⟨ (λ trans → trans ∘ ∼→) ⟩
Transitivity-∼≳ˡ ↝⟨ size-preserving-transitivity-∼≳ˡ→uninhabited ⟩□
¬ (∀ i → A i) □
-- If there is a fully size-preserving transitivity proof for weak
-- bisimilarity, then ∀ i → A i is uninhabited.
Transitivity-≈ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≈ y → [ i ] y ≈ z → [ i ] x ≈ z
size-preserving-transitivity-≈→uninhabited :
Transitivity-≈ → ¬ (∀ i → A i)
size-preserving-transitivity-≈→uninhabited =
Transitivity-≈ ↝⟨ (λ trans → trans) ⟩
Transitivity-≈ʳ ↝⟨ size-preserving-transitivity-≈ʳ→uninhabited ⟩□
¬ (∀ i → A i) □
-- If there is a fully size-preserving transitivity proof for
-- expansion, then ∀ i → A i is uninhabited.
Transitivity-≳ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≳ y → [ i ] y ≳ z → [ i ] x ≳ z
size-preserving-transitivity-≳→uninhabited :
Transitivity-≳ → ¬ (∀ i → A i)
size-preserving-transitivity-≳→uninhabited =
Transitivity-≳ ↝⟨ (λ trans → trans) ⟩
Transitivity-≳ˡ ↝⟨ size-preserving-transitivity-≳ˡ→uninhabited ⟩□
¬ (∀ i → A i) □
-- There is a transitivity-like proof, taking expansion and weak
-- bisimilarity to weak bisimilarity, that preserves the size of the
-- first argument, iff there is a transitivity-like proof, taking weak
-- bisimilarity and the converse of expansion to weak bisimilarity,
-- that preserves the size of the second argument.
Transitivity-≳≈ˡ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≳ y → y ≈ z → [ i ] x ≈ z
Transitivity-≈≲ʳ = ∀ {i} {x y z : Delay A ∞} →
x ≈ y → [ i ] y ≲ z → [ i ] x ≈ z
size-preserving-transitivity-≳≈ˡ⇔size-preserving-transitivity-≈≲ʳ :
Transitivity-≳≈ˡ ⇔ Transitivity-≈≲ʳ
size-preserving-transitivity-≳≈ˡ⇔size-preserving-transitivity-≈≲ʳ =
record
{ to = λ trans x≈y y≲z → symmetric (trans y≲z (symmetric x≈y))
; from = λ trans x≳y y≈z → symmetric (trans (symmetric y≈z) x≳y)
}
-- If there is a transitivity-like proof, taking expansion and weak
-- bisimilarity to weak bisimilarity, that preserves the size of the
-- first argument, then ∀ i → A i is uninhabited.
size-preserving-transitivity-≳≈ˡ→uninhabited :
Transitivity-≳≈ˡ → ¬ (∀ i → A i)
size-preserving-transitivity-≳≈ˡ→uninhabited =
Transitivity-≳≈ˡ ↝⟨ _∘ ∼→ ⟩
Transitivity-∼≈ˡ ↝⟨ _⇔_.from size-preserving-transitivity-≈∼ʳ⇔size-preserving-transitivity-∼≈ˡ ⟩
Transitivity-≈∼ʳ ↝⟨ size-preserving-transitivity-≈∼ʳ→uninhabited ⟩□
¬ (∀ i → A i) □
-- There is a transitivity-like proof, taking expansion and weak
-- bisimilarity to weak bisimilarity, that preserves the size of both
-- arguments, iff there is a transitivity-like proof, taking weak
-- bisimilarity and the converse of expansion to weak bisimilarity,
-- that also preserves the size of both arguments.
Transitivity-≳≈ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≳ y → [ i ] y ≈ z → [ i ] x ≈ z
Transitivity-≈≲ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≈ y → [ i ] y ≲ z → [ i ] x ≈ z
size-preserving-transitivity-≳≈⇔size-preserving-transitivity-≈≲ :
Transitivity-≳≈ ⇔ Transitivity-≈≲
size-preserving-transitivity-≳≈⇔size-preserving-transitivity-≈≲ =
record
{ to = λ trans x≈y y≲z → symmetric (trans y≲z (symmetric x≈y))
; from = λ trans x≳y y≈z → symmetric (trans (symmetric y≈z) x≳y)
}
-- If there is a transitivity-like proof, taking expansion and weak
-- bisimilarity to weak bisimilarity, that preserves the size of both
-- arguments, then ∀ i → A i is uninhabited.
size-preserving-transitivity-≳≈→uninhabited :
Transitivity-≳≈ → ¬ (∀ i → A i)
size-preserving-transitivity-≳≈→uninhabited =
Transitivity-≳≈ ↝⟨ (λ trans → trans) ⟩
Transitivity-≳≈ˡ ↝⟨ size-preserving-transitivity-≳≈ˡ→uninhabited ⟩□
¬ (∀ i → A i) □
-- If there is a transitivity-like proof, taking weak bisimilarity and
-- expansion to weak bisimilarity, that preserves the size of the
-- first argument, then ∀ i → A i is uninhabited.
Transitivity-≈≳ˡ = ∀ {i} {x y z : Delay A ∞} →
[ i ] x ≈ y → y ≳ z → [ i ] x ≈ z
size-preserving-transitivity-≈≳ˡ→uninhabited :
Transitivity-≈≳ˡ → ¬ (∀ i → A i)
size-preserving-transitivity-≈≳ˡ→uninhabited =
Transitivity-≈≳ˡ ↝⟨ (λ trans {_ _ _} x≈ly → trans x≈ly (laterˡ (reflexive _))) ⟩
Laterʳ⁻¹-≈ ↝⟨ _⇔_.from size-preserving-laterˡ⁻¹-≈⇔size-preserving-laterʳ⁻¹-≈ ⟩
Laterˡ⁻¹-≈ ↝⟨ size-preserving-laterˡ⁻¹-≈→uninhabited ⟩
¬ (∀ i → A i) □
------------------------------------------------------------------------
-- Lemmas stating that certain types are inhabited if A ∞ is
-- uninhabited
-- If A ∞ is uninhabited, then Now≳later-now is inhabited.
uninhabited→now≳later-now : ¬ A ∞ → Now≳later-now
uninhabited→now≳later-now =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ trivial _ → trivial _ _) ⟩□
Now≳later-now □
-- If A ∞ is uninhabited, then a variant of laterˡ⁻¹ for (fully
-- defined) expansion can be defined.
uninhabited→laterˡ⁻¹-≳ : ¬ A ∞ → Laterˡ⁻¹-≳
uninhabited→laterˡ⁻¹-≳ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _} _ → trivial _ _) ⟩□
Laterˡ⁻¹-≳ □
-- If A ∞ is uninhabited, then a transitivity-like proof taking weak
-- bisimilarity and expansion to expansion can be defined.
uninhabited→transitivity-≈≳≳ : ¬ A ∞ → Transitivity-≈≳≳
uninhabited→transitivity-≈≳≳ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≈≳≳ □
-- If A ∞ is uninhabited, then a transitivity-like proof taking
-- expansion and weak bisimilarity to expansion can be defined.
uninhabited→transitivity-≳≈≳ : ¬ A ∞ → Transitivity-≳≈≳
uninhabited→transitivity-≳≈≳ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≳≈≳ □
-- If A ∞ is uninhabited, then Laterˡ⁻¹-∼≈ is inhabited.
uninhabited→size-preserving-laterˡ⁻¹-∼≈ : ¬ A ∞ → Laterˡ⁻¹-∼≈
uninhabited→size-preserving-laterˡ⁻¹-∼≈ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_} _ _ → trivial _ _) ⟩□
Laterˡ⁻¹-∼≈ □
-- If A ∞ is uninhabited, then laterˡ⁻¹ can be made size-preserving.
uninhabited→size-preserving-laterˡ⁻¹ : ¬ A ∞ → Laterˡ⁻¹-≈
uninhabited→size-preserving-laterˡ⁻¹ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _} _ → trivial _ _) ⟩□
Laterˡ⁻¹-≈ □
-- If A ∞ is uninhabited, then a variant of ⇓-respects-≈ in which _≈_
-- is replaced by _∼_ can be made size-preserving in the second
-- argument.
uninhabited→size-preserving-⇓-respects-∼ʳ : ¬ A ∞ → ⇓-Respects-∼ʳ
uninhabited→size-preserving-⇓-respects-∼ʳ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
⇓-Respects-∼ʳ □
-- If A ∞ is uninhabited, then ⇓-respects-≈ can be made
-- size-preserving in the second argument.
uninhabited→size-preserving-⇓-respects-≈ʳ : ¬ A ∞ → ⇓-Respects-≈ʳ
uninhabited→size-preserving-⇓-respects-≈ʳ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
⇓-Respects-≈ʳ □
-- If A ∞ is uninhabited, then there is a transitivity-like proof,
-- taking weak bisimilarity and strong bisimilarity to weak
-- bisimilarity, that preserves the size of the second argument.
uninhabited→size-preserving-transitivity-≈∼ʳ : ¬ A ∞ → Transitivity-≈∼ʳ
uninhabited→size-preserving-transitivity-≈∼ʳ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≈∼ʳ □
-- If A ∞ is uninhabited, then there is a transitivity-like proof,
-- taking strong bisimilarity and expansion to expansion, that
-- preserves the size of the first argument.
uninhabited→size-preserving-transitivity-∼≳ˡ : ¬ A ∞ → Transitivity-∼≳ˡ
uninhabited→size-preserving-transitivity-∼≳ˡ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-∼≳ˡ □
-- If A ∞ is uninhabited, then there is a transitivity proof for weak
-- bisimilarity that preserves the size of the second argument.
uninhabited→size-preserving-transitivity-≈ʳ : ¬ A ∞ → Transitivity-≈ʳ
uninhabited→size-preserving-transitivity-≈ʳ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≈ʳ □
-- If A ∞ is uninhabited, then there is a transitivity proof for
-- expansion that preserves the size of the first argument.
uninhabited→size-preserving-transitivity-≳ˡ : ¬ A ∞ → Transitivity-≳ˡ
uninhabited→size-preserving-transitivity-≳ˡ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≳ˡ □
-- If A ∞ is uninhabited, then there is a fully size-preserving
-- transitivity proof for weak bisimilarity.
uninhabited→size-preserving-transitivity-≈ : ¬ A ∞ → Transitivity-≈
uninhabited→size-preserving-transitivity-≈ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≈ □
-- If A ∞ is uninhabited, then there is a fully size-preserving
-- transitivity proof for expansion.
uninhabited→size-preserving-transitivity-≳ : ¬ A ∞ → Transitivity-≳
uninhabited→size-preserving-transitivity-≳ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≳ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≳ □
-- If A ∞ is uninhabited, then there is a transitivity-like proof,
-- taking expansion and weak bisimilarity to weak bisimilarity, that
-- preserves the size of the first argument.
uninhabited→size-preserving-transitivity-≳≈ˡ : ¬ A ∞ → Transitivity-≳≈ˡ
uninhabited→size-preserving-transitivity-≳≈ˡ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≳≈ˡ □
-- If A ∞ is uninhabited, then there is a transitivity-like proof,
-- taking expansion and weak bisimilarity to weak bisimilarity, that
-- preserves the size of both arguments.
uninhabited→size-preserving-transitivity-≳≈ : ¬ A ∞ → Transitivity-≳≈
uninhabited→size-preserving-transitivity-≳≈ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≳≈ □
-- If A ∞ is uninhabited, then there is a transitivity-like proof,
-- taking weak bisimilarity and expansion to weak bisimilarity, that
-- preserves the size of the first argument.
uninhabited→size-preserving-transitivity-≈≳ˡ : ¬ A ∞ → Transitivity-≈≳ˡ
uninhabited→size-preserving-transitivity-≈≳ˡ =
¬ A ∞ ↝⟨ uninhabited→trivial ⟩
(∀ x y → x ≈ y) ↝⟨ (λ trivial {_ _ _ _} _ _ → trivial _ _) ⟩□
Transitivity-≈≳ˡ □
| {
"alphanum_fraction": 0.6005238159,
"avg_line_length": 39.0415944541,
"ext": "agda",
"hexsha": "b18b6b47882027f86257c880fbf17f8d740a3f0c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/delay-monad",
"max_forks_repo_path": "src/Delay-monad/Sized/Bisimilarity/Negative.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/delay-monad",
"max_issues_repo_path": "src/Delay-monad/Sized/Bisimilarity/Negative.agda",
"max_line_length": 99,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/delay-monad",
"max_stars_repo_path": "src/Delay-monad/Sized/Bisimilarity/Negative.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 9312,
"size": 22527
} |
{-# OPTIONS --universe-polymorphism #-}
-- These examples should now go through with no unsolved metavariables.
-- They work since the conversion checker is a little less prone to
-- abort checking when there are constraints. In particular if the
-- constraints only affect the sorts of the things compared, then it keeps
-- going.
module Issue211 where
open import Common.Level
infixr 4 _,_
infixr 3 _×_
data _×_ {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where
_,_ : A → B → A × B
data D₀ : Set₀ where
data D₁ : Set₁ where
-- Works:
ex₁ : (D₁ → D₁) × (D₁ → D₁)
ex₁ = ((λ d → d) , (λ d → d))
-- Works:
ex₂ : (D₀ → D₀) × (D₀ → D₀) × (D₀ → D₀)
ex₂ = ((λ d → d) , (λ d → d) , (λ d → d))
-- Works:
ex₃ : (D₁ → D₁) × (D₁ → D₁) × (D₁ → D₁)
ex₃ = ((λ d → d) , (λ (d : D₁) → d) , (λ (d : D₁) → d))
-- Does not work:
ex₄ : Level × (D₁ → D₁) × (D₁ → D₁)
ex₄ = lzero , (λ d → d) , (λ d → d)
ex₅ : (D₁ → D₁) × (D₁ → D₁) × (D₁ → D₁)
ex₅ = (λ (d : _) → d) , (λ (d : _) → d) , (λ (d : _) → d)
-- Does not work:
ex₆ : (D₁ → D₁) × (D₁ → D₁) × (D₁ → D₁)
ex₆ = (λ d → d) , (λ d → d) , (λ d → d)
-- As far as I can tell there is an easily found unique solution for
-- the unsolved meta-variables above. Why does not the unification
-- machinery find it? Are the meta-variables solved in the wrong
-- order?
| {
"alphanum_fraction": 0.5654169855,
"avg_line_length": 25.1346153846,
"ext": "agda",
"hexsha": "49cb2ec1fa4fc05501e2827f8603cfd4dccd2bd5",
"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/Issue211.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/Issue211.agda",
"max_line_length": 74,
"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/Issue211.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": 517,
"size": 1307
} |
------------------------------------------------------------------------
-- This file contains the definition the category of functors indexed --
-- by two categories. --
------------------------------------------------------------------------
module Category.CatFunc where
open import Level
open import Category.NatTrans public
CatFunc : {l₁ l₂ : Level} → Cat {l₁} → Cat {l₂} → Cat {l₁ ⊔ l₂}
CatFunc ℂ₁ ℂ₂ = record
{ Obj = Functor ℂ₁ ℂ₂
; Hom = λ F G → record { el = NatTrans F G ; eq = λ α₁ α₂ → {!!} ; eqRpf = {!!} }
; comp = {!!}
; id = {!!}
; assocPf = {!!}
; idPfCom = {!!}
; idPf = {!!}
}
| {
"alphanum_fraction": 0.3400758534,
"avg_line_length": 37.6666666667,
"ext": "agda",
"hexsha": "aa54b4dc829c3ad03eb2f12d5d7fbdfb0d2ba59b",
"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/Category/CatFunc.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/Category/CatFunc.agda",
"max_line_length": 99,
"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/Category/CatFunc.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 173,
"size": 791
} |
open import FRP.LTL.Time using ( Time ; _≤_ ; _<_ )
module FRP.LTL.RSet.Core where
-- Reactive types
RSet : Set₁
RSet = Time → Set
⟨_⟩ : Set → RSet
⟨ A ⟩ t = A
⟦_⟧ : RSet → Set
⟦ A ⟧ = ∀ {t} → (A t)
-- Reactive sets over an interval
_[_,_] : RSet → Time → Time → Set
A [ s , u ] = ∀ {t} → s ≤ t → t ≤ u → A t
_[_,_⟩ : RSet → Time → Time → Set
A [ s , u ⟩ = ∀ {t} → s ≤ t → t < u → A t
| {
"alphanum_fraction": 0.4961832061,
"avg_line_length": 17.0869565217,
"ext": "agda",
"hexsha": "6ec4ca7495d4bc03c948ddf965824bb3e5d18c3a",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:04.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-01T07:33:00.000Z",
"max_forks_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-frp-ltl",
"max_forks_repo_path": "src/FRP/LTL/RSet/Core.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_issues_repo_issues_event_max_datetime": "2015-03-02T15:23:53.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-01T07:01:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-frp-ltl",
"max_issues_repo_path": "src/FRP/LTL/RSet/Core.agda",
"max_line_length": 51,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-frp-ltl",
"max_stars_repo_path": "src/FRP/LTL/RSet/Core.agda",
"max_stars_repo_stars_event_max_datetime": "2020-06-15T02:51:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-02T20:25:05.000Z",
"num_tokens": 172,
"size": 393
} |
module Progress where
open import Prelude
open import T
---- progress
module Progress where
-- Define a datatype representing that a term satisfies progress
data TProgress : ∀{A} → TCExp A → Set where
prog-val : ∀{A} {e : TCExp A} → (D : TVal e) → TProgress e
prog-step : ∀{A} {e e' : TCExp A} → (D : e ~> e') → TProgress e
-- prove that all terms satisfy progress
progress : ∀{A} (e : TCExp A) → TProgress e
progress (var ())
progress (Λ e) = prog-val val-lam
progress (e₁ $ e₂) with progress e₁
progress (e₁ $ e₂) | prog-step D = prog-step (step-app-l D)
progress (.(Λ e) $ e₂) | prog-val (val-lam {_} {_} {e}) = prog-step step-beta
progress zero = prog-val val-zero
progress (suc e) with progress e
... | prog-val D = prog-val (val-suc D)
... | prog-step D' = prog-step (step-suc D')
progress (rec e e₀ es) with progress e
progress (rec .zero e₀ es) | prog-val val-zero = prog-step step-rec-z
progress (rec .(suc _) e₀ es) | prog-val (val-suc y) = prog-step (step-rec-s y)
... | prog-step D = prog-step (step-rec D)
open Progress public
| {
"alphanum_fraction": 0.6290174472,
"avg_line_length": 34.03125,
"ext": "agda",
"hexsha": "b5ef8f11387206dd4f5669721de841971a7fb682",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-05-04T22:37:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-26T11:39:14.000Z",
"max_forks_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "msullivan/godels-t",
"max_forks_repo_path": "Progress.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"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": "msullivan/godels-t",
"max_issues_repo_path": "Progress.agda",
"max_line_length": 82,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "msullivan/godels-t",
"max_stars_repo_path": "Progress.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-22T00:28:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-25T01:52:57.000Z",
"num_tokens": 357,
"size": 1089
} |
module _ where
postulate
I : Set
data P (i : I) : Set where
p : P i → P i
data Q (i : I) : P i → Set where
q : (x : P i) → Q i (p x)
module _ (i : I) (x : P i) where
g : Q _ x → Set₁
g (q y) = Set
| {
"alphanum_fraction": 0.4741784038,
"avg_line_length": 13.3125,
"ext": "agda",
"hexsha": "78d760df639eac0a6ec858003e7524012d947e8f",
"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/Issue4259.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/Issue4259.agda",
"max_line_length": 33,
"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/Issue4259.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": 98,
"size": 213
} |
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
{-# OPTIONS --allow-unsolved-metas #-}
module Light.Implementation.Data.Product where
open import Light.Library.Data.Product using (Library ; Dependencies)
open import Light.Variable.Levels
open import Light.Level using (_⊔_)
open import Light.Library.Relation.Binary.Equality.Decidable using (DecidableEquality)
open import Light.Variable.Sets
open import Light.Library.Relation.Binary.Equality using (wrap)
instance dependencies : Dependencies
dependencies = record {}
instance library : Library dependencies
library = record { Implementation }
where
module Implementation where
record Σ (𝕒 : Set aℓ) (𝕓 : 𝕒 → Set bℓ) : Set (aℓ ⊔ bℓ) where
constructor both
field first : 𝕒
field second : 𝕓 first
open Σ public
equals :
∀ ⦃ a‐c‐equals : DecidableEquality 𝕒 𝕔 ⦄ ⦃ b‐d‐equals : DecidableEquality 𝕓 𝕕 ⦄
→ DecidableEquality (Σ 𝕒 (λ _ → 𝕓)) (Σ 𝕔 (λ _ → 𝕕))
equals = {!!}
| {
"alphanum_fraction": 0.6376681614,
"avg_line_length": 35.9677419355,
"ext": "agda",
"hexsha": "510da19965811e4f810d65976dd7f1d01164d252",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "Zambonifofex/lightlib",
"max_forks_repo_path": "Light/Implementation/Data/Product.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "Zambonifofex/lightlib",
"max_issues_repo_path": "Light/Implementation/Data/Product.agda",
"max_line_length": 97,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "zamfofex/lightlib",
"max_stars_repo_path": "Light/Implementation/Data/Product.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z",
"num_tokens": 287,
"size": 1115
} |
{-# OPTIONS --without-K --safe #-}
open import Level using (Level)
open import FLA.Algebra.Structures
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
module FLA.Algebra.Properties.Field {ℓ : Level } {A : Set ℓ} ⦃ F : Field A ⦄ where
open Field F
0ᶠ+0ᶠ≡0ᶠ : 0ᶠ + 0ᶠ ≡ 0ᶠ
0ᶠ+0ᶠ≡0ᶠ = +0ᶠ 0ᶠ
0ᶠ+ : (a : A) → 0ᶠ + a ≡ a
0ᶠ+ a rewrite +-comm 0ᶠ a = +0ᶠ a
a*0ᶠ≡0ᶠ : (a : A) → a * 0ᶠ ≡ 0ᶠ
a*0ᶠ≡0ᶠ a = begin
a * 0ᶠ ≡˘⟨ 0ᶠ+ (a * 0ᶠ) ⟩
0ᶠ + a * 0ᶠ ≡⟨ cong (_+ a * 0ᶠ) (sym (+-inv a)) ⟩
- a + a + a * 0ᶠ ≡⟨ cong (λ x → - a + x + a * 0ᶠ) (sym (*1ᶠ a)) ⟩
- a + a * 1ᶠ + a * 0ᶠ ≡˘⟨ +-assoc (- a) (a * 1ᶠ) (a * 0ᶠ) ⟩
- a + (a * 1ᶠ + a * 0ᶠ) ≡⟨ cong (- a +_) (sym (*-distr-+ a 1ᶠ 0ᶠ)) ⟩
- a + (a * (1ᶠ + 0ᶠ)) ≡⟨ cong (λ x → - a + (a * x)) (+0ᶠ 1ᶠ) ⟩
- a + (a * 1ᶠ) ≡⟨ cong (- a +_) (*1ᶠ a) ⟩
- a + a ≡⟨ +-inv a ⟩
0ᶠ ∎
0ᶠ*a≡0ᶠ : (a : A) → 0ᶠ * a ≡ 0ᶠ
0ᶠ*a≡0ᶠ a = trans (*-comm 0ᶠ a) (a*0ᶠ≡0ᶠ a)
-a≡-1ᶠ*a : (a : A) → - a ≡ - 1ᶠ * a
-a≡-1ᶠ*a a = begin
- a ≡˘⟨ +0ᶠ (- a) ⟩
- a + 0ᶠ ≡⟨ cong (- a +_) (sym (a*0ᶠ≡0ᶠ a)) ⟩
- a + (a * 0ᶠ) ≡⟨ cong (λ x → - a + (a * x)) (sym (+-inv 1ᶠ)) ⟩
- a + (a * (- 1ᶠ + 1ᶠ)) ≡⟨ cong (- a +_) (*-distr-+ a (- 1ᶠ) 1ᶠ) ⟩
- a + (a * - 1ᶠ + a * 1ᶠ) ≡⟨ cong (- a +_) (+-comm (a * - 1ᶠ) (a * 1ᶠ)) ⟩
- a + (a * 1ᶠ + a * - 1ᶠ ) ≡⟨ +-assoc (- a) (a * 1ᶠ) (a * - 1ᶠ) ⟩
- a + a * 1ᶠ + a * - 1ᶠ ≡⟨ cong (λ x → - a + x + a * - 1ᶠ) (*1ᶠ a) ⟩
- a + a + a * - 1ᶠ ≡⟨ cong (_+ a * - 1ᶠ) (+-inv a) ⟩
0ᶠ + a * - 1ᶠ ≡⟨ 0ᶠ+ (a * - 1ᶠ) ⟩
a * - 1ᶠ ≡⟨ *-comm a (- 1ᶠ) ⟩
- 1ᶠ * a ∎
-a*b≡-[a*b] : (a b : A) → - a * b ≡ - (a * b)
-a*b≡-[a*b] a b = begin
- a * b ≡⟨ cong (_* b) (-a≡-1ᶠ*a a) ⟩
(- 1ᶠ * a) * b ≡˘⟨ *-assoc (- 1ᶠ) a b ⟩
- 1ᶠ * (a * b) ≡˘⟨ -a≡-1ᶠ*a ((a * b)) ⟩
- (a * b) ∎
a*-b≡-[a*b] : (a b : A) → a * - b ≡ - (a * b)
a*-b≡-[a*b] a b = begin
a * - b ≡⟨ *-comm a (- b) ⟩
- b * a ≡⟨ -a*b≡-[a*b] b a ⟩
- (b * a) ≡⟨ cong -_ (*-comm b a) ⟩
- (a * b) ∎
| {
"alphanum_fraction": 0.3452935694,
"avg_line_length": 35.1803278689,
"ext": "agda",
"hexsha": "1ca4300ec7654b51b3cfd2bfc2c904178e5facc8",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-09-07T19:55:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-12T20:34:17.000Z",
"max_forks_repo_head_hexsha": "375475a2daa57b5995ceb78b4bffcbfcbb5d8898",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "turion/functional-linear-algebra",
"max_forks_repo_path": "src/FLA/Algebra/Properties/Field.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "375475a2daa57b5995ceb78b4bffcbfcbb5d8898",
"max_issues_repo_issues_event_max_datetime": "2022-01-07T05:27:53.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-09-01T01:42:12.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "turion/functional-linear-algebra",
"max_issues_repo_path": "src/FLA/Algebra/Properties/Field.agda",
"max_line_length": 82,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "375475a2daa57b5995ceb78b4bffcbfcbb5d8898",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "turion/functional-linear-algebra",
"max_stars_repo_path": "src/FLA/Algebra/Properties/Field.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-07T05:28:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-22T20:49:34.000Z",
"num_tokens": 1397,
"size": 2146
} |
------------------------------------------------------------------------
-- Collection of most needed import from standard library
------------------------------------------------------------------------
module Library where
open import Data.Empty public
open import Data.Unit hiding (_≟_; _≤_; _≤?_; decSetoid; decTotalOrder; setoid) public
open import Data.Sum public hiding (map)
open import Data.Bool hiding (_≟_) public
open import Data.Nat hiding (_⊔_) public
open import Data.Product hiding (map ; swap) public
open import Data.Vec using ([]; _∷_; Vec) public
open import Level renaming (zero to ℓ₀; suc to ℓ⁺) public
open import Function public
open import Size public
open import Relation.Binary.PropositionalEquality hiding (decSetoid; preorder; setoid) public
open import ContainerMonkeyPatched as Container renaming (map to fmap) public
| {
"alphanum_fraction": 0.6506447831,
"avg_line_length": 40.619047619,
"ext": "agda",
"hexsha": "3b7e34543acdbd03dc348cb36448c1f2348764fa",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-12-13T15:56:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-12-13T15:56:38.000Z",
"max_forks_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "zimbatm/condatis",
"max_forks_repo_path": "Library.agda",
"max_issues_count": 5,
"max_issues_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_issues_repo_issues_event_max_datetime": "2020-09-01T16:52:07.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-03T20:02:22.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "zimbatm/condatis",
"max_issues_repo_path": "Library.agda",
"max_line_length": 93,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "Aerate/condatis",
"max_stars_repo_path": "Library.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-13T16:52:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-13T16:52:28.000Z",
"num_tokens": 183,
"size": 853
} |
{-# OPTIONS --cubical-compatible --rewriting #-}
module Issue1719.Pushouts where
open import Issue1719.Common
open import Issue1719.Spans
postulate
Pushout : (d : Span) → Set
left : {d : Span} → (Span.A d) → Pushout d
right : {d : Span} → (Span.B d) → Pushout d
glue : {d : Span} → (c : Span.C d) → left (Span.f d c) == right (Span.g d c) :> Pushout d
module _ {d : Span} {l} {P : Pushout d → Set l}
(left* : (a : Span.A d) → P (left a))
(right* : (b : Span.B d) → P (right b))
(glue* : (c : Span.C d) → left* (Span.f d c) == right* (Span.g d c) [ P ↓ glue c ]) where
postulate
Pushout-elim : (x : Pushout d) → P x
Pushout-left-β : (a : Span.A d) → Pushout-elim (left a) ↦ left* a
{-# REWRITE Pushout-left-β #-}
Pushout-right-β : (b : Span.B d) → Pushout-elim (right b) ↦ right* b
{-# REWRITE Pushout-right-β #-}
Pushout-glue-β : (c : Span.C d) → ap Pushout-elim (glue c) ↦ glue* c
{-# REWRITE Pushout-glue-β #-}
| {
"alphanum_fraction": 0.5706860707,
"avg_line_length": 35.6296296296,
"ext": "agda",
"hexsha": "32a5cce15632a2dd2f855022b8460e5f59f78a51",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue1719/Pushouts.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue1719/Pushouts.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue1719/Pushouts.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 365,
"size": 962
} |
module examplesPaperJFP.Colists where
-- open import Function
-- Case expressions (to be used with pattern-matching lambdas, see
-- README.Case).
infix 0 case_return_of_ case_of_
case_return_of_ :
∀ {a b} {A : Set a}
(x : A) (B : A → Set b) → ((x : A) → B x) → B x
case x return B of f = f x
case_of_ : ∀ {a b} {A : Set a} {B : Set b} → A → (A → B) → B
case x of f = case x return _ of f
data ListF A S : Set where
nil : ListF A S
cons : (a : A) (s : S) → ListF A S
record Colist A : Set where
coinductive
field force : ListF A (Colist A)
open Colist using (force)
mapF : ∀{A S S′} (f : S → S′) → (ListF A S → ListF A S′)
mapF f nil = nil
mapF f (cons a s) = cons a (f s)
-- As an example, we define mapping over potentially infinite lists using
-- copattern matching:
map : ∀{A B} (f : A → B) (l : Colist A) → Colist B
force (map f l) with force l
... | nil = nil
... | cons x xs = cons (f x) (map f xs)
unfold : ∀{A S} (t : S → ListF A S) → (S → Colist A)
force (unfold t s) with t s
... | nil = nil
... | cons a s′ = cons a (unfold t s′)
fmap : ∀{A B} (f : A → B) (l : Colist A) → Colist B
fmap f = unfold λ l → case force l of λ
{ nil → nil
; (cons a s) → cons (f a) s
}
| {
"alphanum_fraction": 0.5509881423,
"avg_line_length": 24.3269230769,
"ext": "agda",
"hexsha": "dc0a68d2ab3854831a4e48f179e6ddf588f61862",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "examples/examplesPaperJFP/Colists.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/ooAgda",
"max_issues_repo_path": "examples/examplesPaperJFP/Colists.agda",
"max_line_length": 73,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "examples/examplesPaperJFP/Colists.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 482,
"size": 1265
} |
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
fst : A
snd : B fst
postulate
P : {X : Set} → X → Set
H : Set
R : H → Set
x : H
y : R x
help : (f : H) (p : R f) → P {X = Σ H R} (f , p)
record Category : Set₁ where
field
Hom : Set
id : Hom
comp : Hom → Hom
neut-l : P (comp id)
neut-r : Hom
slice : Category
slice = λ where
.Category.Hom → Σ H R
.Category.id → (x , y)
.Category.comp (f , p) → (f , p)
.Category.neut-l → help x _
.Category.neut-r → {!!}
| {
"alphanum_fraction": 0.5037593985,
"avg_line_length": 17.1612903226,
"ext": "agda",
"hexsha": "60a9d8fd8508a8d5ef6410a37e4a8cb65d0a34e4",
"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/Issue3069.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/Issue3069.agda",
"max_line_length": 50,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue3069.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": 212,
"size": 532
} |
module _ where
module A where
infix 2 _↑
infix 1 c
data D : Set where
● : D
_↑ : D → D
c : {x y : D} → D
syntax c {x = x} {y = y} = x ↓ y
module B where
infix 3 c
data D : Set where
c : {y x : D} → D
syntax c {y = y} {x = x} = y ↓ x
open A
open B
accepted : A.D → A.D
accepted (● ↑ ↓ x) = ● ↑ ↓ x
accepted _ = ● ↑ ↓ ●
| {
"alphanum_fraction": 0.4456521739,
"avg_line_length": 12.2666666667,
"ext": "agda",
"hexsha": "4b9e3bdbf1fc6a095c9c2a551ce299877d42db38",
"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/Issue1436-15.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/Issue1436-15.agda",
"max_line_length": 34,
"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/Issue1436-15.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": 156,
"size": 368
} |
{-# OPTIONS --without-K #-}
module Agda.Builtin.Unit where
record ⊤ : Set where
instance constructor tt
{-# BUILTIN UNIT ⊤ #-}
{-# COMPILE GHC ⊤ = data () (()) #-}
| {
"alphanum_fraction": 0.5976331361,
"avg_line_length": 16.9,
"ext": "agda",
"hexsha": "5c9cc09e52e04c80590caf80f01aacf46918ebf7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "src/data/lib/prim/Agda/Builtin/Unit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "src/data/lib/prim/Agda/Builtin/Unit.agda",
"max_line_length": 36,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "src/data/lib/prim/Agda/Builtin/Unit.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": 45,
"size": 169
} |
{-# OPTIONS --rewriting #-}
module Properties.ResolveOverloads where
open import FFI.Data.Either using (Left; Right)
open import Luau.ResolveOverloads using (Resolved; src; srcⁿ; resolve; resolveⁿ; resolveᶠ; resolveˢ; target; yes; no)
open import Luau.Subtyping using (_<:_; _≮:_; Language; ¬Language; witness; scalar; unknown; never; function; function-ok; function-err; function-tgt; function-scalar; function-ok₁; function-ok₂; scalar-scalar; scalar-function; scalar-function-ok; scalar-function-err; scalar-function-tgt; _,_; left; right)
open import Luau.Type using (Type ; Scalar; _⇒_; _∩_; _∪_; nil; boolean; number; string; unknown; never)
open import Luau.TypeSaturation using (saturate)
open import Luau.TypeNormalization using (normalize)
open import Properties.Contradiction using (CONTRADICTION)
open import Properties.DecSubtyping using (dec-subtyping; dec-subtypingⁿ; <:-impl-<:ᵒ)
open import Properties.Functions using (_∘_)
open import Properties.Subtyping using (<:-refl; <:-trans; <:-trans-≮:; ≮:-trans-<:; <:-∩-left; <:-∩-right; <:-∩-glb; <:-impl-¬≮:; <:-unknown; <:-function; function-≮:-never; <:-never; unknown-≮:-function; scalar-≮:-function; ≮:-∪-right; scalar-≮:-never; <:-∪-left; <:-∪-right; <:-impl-⊇; language-comp)
open import Properties.TypeNormalization using (Normal; FunType; normal; _⇒_; _∩_; _∪_; never; unknown; <:-normalize; normalize-<:; fun-≮:-never; unknown-≮:-fun; scalar-≮:-fun)
open import Properties.TypeSaturation using (Overloads; Saturated; _⊆ᵒ_; _<:ᵒ_; normal-saturate; saturated; <:-saturate; saturate-<:; defn; here; left; right)
-- Properties of src
function-err-srcⁿ : ∀ {T t} → (FunType T) → (¬Language (srcⁿ T) t) → Language T (function-err t)
function-err-srcⁿ (S ⇒ T) p = function-err p
function-err-srcⁿ (S ∩ T) (p₁ , p₂) = (function-err-srcⁿ S p₁ , function-err-srcⁿ T p₂)
¬function-err-srcᶠ : ∀ {T t} → (FunType T) → (Language (srcⁿ T) t) → ¬Language T (function-err t)
¬function-err-srcᶠ (S ⇒ T) p = function-err p
¬function-err-srcᶠ (S ∩ T) (left p) = left (¬function-err-srcᶠ S p)
¬function-err-srcᶠ (S ∩ T) (right p) = right (¬function-err-srcᶠ T p)
¬function-err-srcⁿ : ∀ {T t} → (Normal T) → (Language (srcⁿ T) t) → ¬Language T (function-err t)
¬function-err-srcⁿ never p = never
¬function-err-srcⁿ unknown (scalar ())
¬function-err-srcⁿ (S ⇒ T) p = function-err p
¬function-err-srcⁿ (S ∩ T) (left p) = left (¬function-err-srcᶠ S p)
¬function-err-srcⁿ (S ∩ T) (right p) = right (¬function-err-srcᶠ T p)
¬function-err-srcⁿ (S ∪ T) (scalar ())
¬function-err-src : ∀ {T t} → (Language (src T) t) → ¬Language T (function-err t)
¬function-err-src {T = S ⇒ T} p = function-err p
¬function-err-src {T = nil} p = scalar-function-err nil
¬function-err-src {T = never} p = never
¬function-err-src {T = unknown} (scalar ())
¬function-err-src {T = boolean} p = scalar-function-err boolean
¬function-err-src {T = number} p = scalar-function-err number
¬function-err-src {T = string} p = scalar-function-err string
¬function-err-src {T = S ∪ T} p = <:-impl-⊇ (<:-normalize (S ∪ T)) _ (¬function-err-srcⁿ (normal (S ∪ T)) p)
¬function-err-src {T = S ∩ T} p = <:-impl-⊇ (<:-normalize (S ∩ T)) _ (¬function-err-srcⁿ (normal (S ∩ T)) p)
src-¬function-errᶠ : ∀ {T t} → (FunType T) → Language T (function-err t) → (¬Language (srcⁿ T) t)
src-¬function-errᶠ (S ⇒ T) (function-err p) = p
src-¬function-errᶠ (S ∩ T) (p₁ , p₂) = (src-¬function-errᶠ S p₁ , src-¬function-errᶠ T p₂)
src-¬function-errⁿ : ∀ {T t} → (Normal T) → Language T (function-err t) → (¬Language (srcⁿ T) t)
src-¬function-errⁿ unknown p = never
src-¬function-errⁿ (S ⇒ T) (function-err p) = p
src-¬function-errⁿ (S ∩ T) (p₁ , p₂) = (src-¬function-errᶠ S p₁ , src-¬function-errᶠ T p₂)
src-¬function-errⁿ (S ∪ T) p = never
src-¬function-err : ∀ {T t} → Language T (function-err t) → (¬Language (src T) t)
src-¬function-err {T = S ⇒ T} (function-err p) = p
src-¬function-err {T = unknown} p = never
src-¬function-err {T = S ∪ T} p = src-¬function-errⁿ (normal (S ∪ T)) (<:-normalize (S ∪ T) _ p)
src-¬function-err {T = S ∩ T} p = src-¬function-errⁿ (normal (S ∩ T)) (<:-normalize (S ∩ T) _ p)
fun-¬scalar : ∀ {S T} (s : Scalar S) → FunType T → ¬Language T (scalar s)
fun-¬scalar s (S ⇒ T) = function-scalar s
fun-¬scalar s (S ∩ T) = left (fun-¬scalar s S)
¬fun-scalar : ∀ {S T t} (s : Scalar S) → FunType T → Language T t → ¬Language S t
¬fun-scalar s (S ⇒ T) function = scalar-function s
¬fun-scalar s (S ⇒ T) (function-ok₁ p) = scalar-function-ok s
¬fun-scalar s (S ⇒ T) (function-ok₂ p) = scalar-function-ok s
¬fun-scalar s (S ⇒ T) (function-err p) = scalar-function-err s
¬fun-scalar s (S ⇒ T) (function-tgt p) = scalar-function-tgt s
¬fun-scalar s (S ∩ T) (p₁ , p₂) = ¬fun-scalar s T p₂
fun-function : ∀ {T} → FunType T → Language T function
fun-function (S ⇒ T) = function
fun-function (S ∩ T) = (fun-function S , fun-function T)
srcⁿ-¬scalar : ∀ {S T t} (s : Scalar S) → Normal T → Language T (scalar s) → (¬Language (srcⁿ T) t)
srcⁿ-¬scalar s never (scalar ())
srcⁿ-¬scalar s unknown p = never
srcⁿ-¬scalar s (S ⇒ T) (scalar ())
srcⁿ-¬scalar s (S ∩ T) (p₁ , p₂) = CONTRADICTION (language-comp (scalar s) (fun-¬scalar s S) p₁)
srcⁿ-¬scalar s (S ∪ T) p = never
src-¬scalar : ∀ {S T t} (s : Scalar S) → Language T (scalar s) → (¬Language (src T) t)
src-¬scalar {T = nil} s p = never
src-¬scalar {T = T ⇒ U} s (scalar ())
src-¬scalar {T = never} s (scalar ())
src-¬scalar {T = unknown} s p = never
src-¬scalar {T = boolean} s p = never
src-¬scalar {T = number} s p = never
src-¬scalar {T = string} s p = never
src-¬scalar {T = T ∪ U} s p = srcⁿ-¬scalar s (normal (T ∪ U)) (<:-normalize (T ∪ U) (scalar s) p)
src-¬scalar {T = T ∩ U} s p = srcⁿ-¬scalar s (normal (T ∩ U)) (<:-normalize (T ∩ U) (scalar s) p)
srcⁿ-unknown-≮: : ∀ {T U} → (Normal U) → (T ≮: srcⁿ U) → (U ≮: (T ⇒ unknown))
srcⁿ-unknown-≮: never (witness t p q) = CONTRADICTION (language-comp t q unknown)
srcⁿ-unknown-≮: unknown (witness t p q) = witness (function-err t) unknown (function-err p)
srcⁿ-unknown-≮: (U ⇒ V) (witness t p q) = witness (function-err t) (function-err q) (function-err p)
srcⁿ-unknown-≮: (U ∩ V) (witness t p q) = witness (function-err t) (function-err-srcⁿ (U ∩ V) q) (function-err p)
srcⁿ-unknown-≮: (U ∪ V) (witness t p q) = witness (scalar V) (right (scalar V)) (function-scalar V)
src-unknown-≮: : ∀ {T U} → (T ≮: src U) → (U ≮: (T ⇒ unknown))
src-unknown-≮: {U = nil} (witness t p q) = witness (scalar nil) (scalar nil) (function-scalar nil)
src-unknown-≮: {U = T ⇒ U} (witness t p q) = witness (function-err t) (function-err q) (function-err p)
src-unknown-≮: {U = never} (witness t p q) = CONTRADICTION (language-comp t q unknown)
src-unknown-≮: {U = unknown} (witness t p q) = witness (function-err t) unknown (function-err p)
src-unknown-≮: {U = boolean} (witness t p q) = witness (scalar boolean) (scalar boolean) (function-scalar boolean)
src-unknown-≮: {U = number} (witness t p q) = witness (scalar number) (scalar number) (function-scalar number)
src-unknown-≮: {U = string} (witness t p q) = witness (scalar string) (scalar string) (function-scalar string)
src-unknown-≮: {U = T ∪ U} p = <:-trans-≮: (normalize-<: (T ∪ U)) (srcⁿ-unknown-≮: (normal (T ∪ U)) p)
src-unknown-≮: {U = T ∩ U} p = <:-trans-≮: (normalize-<: (T ∩ U)) (srcⁿ-unknown-≮: (normal (T ∩ U)) p)
unknown-src-≮: : ∀ {S T U} → (U ≮: S) → (T ≮: (U ⇒ unknown)) → (U ≮: src T)
unknown-src-≮: (witness t x x₁) (witness (scalar s) p (function-scalar s)) = witness t x (src-¬scalar s p)
unknown-src-≮: r (witness (function-ok s .(scalar s₁)) p (function-ok x (scalar-scalar s₁ () x₂)))
unknown-src-≮: r (witness (function-ok s .function) p (function-ok x (scalar-function ())))
unknown-src-≮: r (witness (function-ok s .(function-ok _ _)) p (function-ok x (scalar-function-ok ())))
unknown-src-≮: r (witness (function-ok s .(function-err _)) p (function-ok x (scalar-function-err ())))
unknown-src-≮: r (witness (function-err t) p (function-err q)) = witness t q (src-¬function-err p)
unknown-src-≮: r (witness (function-tgt t) p (function-tgt (scalar-function-tgt ())))
-- Properties of resolve
resolveˢ-<:-⇒ : ∀ {F V U} → (FunType F) → (Saturated F) → (FunType (V ⇒ U)) → (r : Resolved F V) → (F <: (V ⇒ U)) → (target r <: U)
resolveˢ-<:-⇒ Fᶠ Fˢ V⇒Uᶠ r F<:V⇒U with <:-impl-<:ᵒ Fᶠ Fˢ V⇒Uᶠ F<:V⇒U here
resolveˢ-<:-⇒ Fᶠ Fˢ V⇒Uᶠ (yes Sʳ Tʳ oʳ V<:Sʳ tgtʳ) F<:V⇒U | defn o o₁ o₂ = <:-trans (tgtʳ o o₁) o₂
resolveˢ-<:-⇒ Fᶠ Fˢ V⇒Uᶠ (no tgtʳ) F<:V⇒U | defn o o₁ o₂ = CONTRADICTION (<:-impl-¬≮: o₁ (tgtʳ o))
resolveⁿ-<:-⇒ : ∀ {F V U} → (Fⁿ : Normal F) → (Vⁿ : Normal V) → (Uⁿ : Normal U) → (F <: (V ⇒ U)) → (resolveⁿ Fⁿ Vⁿ <: U)
resolveⁿ-<:-⇒ (Sⁿ ⇒ Tⁿ) Vⁿ Uⁿ F<:V⇒U = resolveˢ-<:-⇒ (normal-saturate (Sⁿ ⇒ Tⁿ)) (saturated (Sⁿ ⇒ Tⁿ)) (Vⁿ ⇒ Uⁿ) (resolveˢ (normal-saturate (Sⁿ ⇒ Tⁿ)) (saturated (Sⁿ ⇒ Tⁿ)) Vⁿ (λ o → o)) F<:V⇒U
resolveⁿ-<:-⇒ (Fⁿ ∩ Gⁿ) Vⁿ Uⁿ F<:V⇒U = resolveˢ-<:-⇒ (normal-saturate (Fⁿ ∩ Gⁿ)) (saturated (Fⁿ ∩ Gⁿ)) (Vⁿ ⇒ Uⁿ) (resolveˢ (normal-saturate (Fⁿ ∩ Gⁿ)) (saturated (Fⁿ ∩ Gⁿ)) Vⁿ (λ o → o)) (<:-trans (saturate-<: (Fⁿ ∩ Gⁿ)) F<:V⇒U)
resolveⁿ-<:-⇒ (Sⁿ ∪ Tˢ) Vⁿ Uⁿ F<:V⇒U = CONTRADICTION (<:-impl-¬≮: F<:V⇒U (<:-trans-≮: <:-∪-right (scalar-≮:-function Tˢ)))
resolveⁿ-<:-⇒ never Vⁿ Uⁿ F<:V⇒U = <:-never
resolveⁿ-<:-⇒ unknown Vⁿ Uⁿ F<:V⇒U = CONTRADICTION (<:-impl-¬≮: F<:V⇒U unknown-≮:-function)
resolve-<:-⇒ : ∀ {F V U} → (F <: (V ⇒ U)) → (resolve F V <: U)
resolve-<:-⇒ {F} {V} {U} F<:V⇒U = <:-trans (resolveⁿ-<:-⇒ (normal F) (normal V) (normal U) (<:-trans (normalize-<: F) (<:-trans F<:V⇒U (<:-normalize (V ⇒ U))))) (normalize-<: U)
resolve-≮:-⇒ : ∀ {F V U} → (resolve F V ≮: U) → (F ≮: (V ⇒ U))
resolve-≮:-⇒ {F} {V} {U} FV≮:U with dec-subtyping F (V ⇒ U)
resolve-≮:-⇒ {F} {V} {U} FV≮:U | Left F≮:V⇒U = F≮:V⇒U
resolve-≮:-⇒ {F} {V} {U} FV≮:U | Right F<:V⇒U = CONTRADICTION (<:-impl-¬≮: (resolve-<:-⇒ F<:V⇒U) FV≮:U)
<:-resolveˢ-⇒ : ∀ {S T V} → (r : Resolved (S ⇒ T) V) → (V <: S) → T <: target r
<:-resolveˢ-⇒ (yes S T here _ _) V<:S = <:-refl
<:-resolveˢ-⇒ (no _) V<:S = <:-unknown
<:-resolveⁿ-⇒ : ∀ {S T V} → (Sⁿ : Normal S) → (Tⁿ : Normal T) → (Vⁿ : Normal V) → (V <: S) → T <: resolveⁿ (Sⁿ ⇒ Tⁿ) Vⁿ
<:-resolveⁿ-⇒ Sⁿ Tⁿ Vⁿ V<:S = <:-resolveˢ-⇒ (resolveˢ (Sⁿ ⇒ Tⁿ) (saturated (Sⁿ ⇒ Tⁿ)) Vⁿ (λ o → o)) V<:S
<:-resolve-⇒ : ∀ {S T V} → (V <: S) → T <: resolve (S ⇒ T) V
<:-resolve-⇒ {S} {T} {V} V<:S = <:-trans (<:-normalize T) (<:-resolveⁿ-⇒ (normal S) (normal T) (normal V) (<:-trans (normalize-<: V) (<:-trans V<:S (<:-normalize S))))
<:-resolveˢ : ∀ {F G V W} → (r : Resolved F V) → (s : Resolved G W) → (F <:ᵒ G) → (V <: W) → target r <: target s
<:-resolveˢ (yes Sʳ Tʳ oʳ V<:Sʳ tgtʳ) (yes Sˢ Tˢ oˢ W<:Sˢ tgtˢ) F<:G V<:W with F<:G oˢ
<:-resolveˢ (yes Sʳ Tʳ oʳ V<:Sʳ tgtʳ) (yes Sˢ Tˢ oˢ W<:Sˢ tgtˢ) F<:G V<:W | defn o o₁ o₂ = <:-trans (tgtʳ o (<:-trans (<:-trans V<:W W<:Sˢ) o₁)) o₂
<:-resolveˢ (no r) (yes Sˢ Tˢ oˢ W<:Sˢ tgtˢ) F<:G V<:W with F<:G oˢ
<:-resolveˢ (no r) (yes Sˢ Tˢ oˢ W<:Sˢ tgtˢ) F<:G V<:W | defn o o₁ o₂ = CONTRADICTION (<:-impl-¬≮: (<:-trans V<:W (<:-trans W<:Sˢ o₁)) (r o))
<:-resolveˢ r (no s) F<:G V<:W = <:-unknown
<:-resolveᶠ : ∀ {F G V W} → (Fᶠ : FunType F) → (Gᶠ : FunType G) → (Vⁿ : Normal V) → (Wⁿ : Normal W) → (F <: G) → (V <: W) → resolveᶠ Fᶠ Vⁿ <: resolveᶠ Gᶠ Wⁿ
<:-resolveᶠ Fᶠ Gᶠ Vⁿ Wⁿ F<:G V<:W = <:-resolveˢ
(resolveˢ (normal-saturate Fᶠ) (saturated Fᶠ) Vⁿ (λ o → o))
(resolveˢ (normal-saturate Gᶠ) (saturated Gᶠ) Wⁿ (λ o → o))
(<:-impl-<:ᵒ (normal-saturate Fᶠ) (saturated Fᶠ) (normal-saturate Gᶠ) (<:-trans (saturate-<: Fᶠ) (<:-trans F<:G (<:-saturate Gᶠ))))
V<:W
<:-resolveⁿ : ∀ {F G V W} → (Fⁿ : Normal F) → (Gⁿ : Normal G) → (Vⁿ : Normal V) → (Wⁿ : Normal W) → (F <: G) → (V <: W) → resolveⁿ Fⁿ Vⁿ <: resolveⁿ Gⁿ Wⁿ
<:-resolveⁿ (Rⁿ ⇒ Sⁿ) (Tⁿ ⇒ Uⁿ) Vⁿ Wⁿ F<:G V<:W = <:-resolveᶠ (Rⁿ ⇒ Sⁿ) (Tⁿ ⇒ Uⁿ) Vⁿ Wⁿ F<:G V<:W
<:-resolveⁿ (Rⁿ ⇒ Sⁿ) (Gⁿ ∩ Hⁿ) Vⁿ Wⁿ F<:G V<:W = <:-resolveᶠ (Rⁿ ⇒ Sⁿ) (Gⁿ ∩ Hⁿ) Vⁿ Wⁿ F<:G V<:W
<:-resolveⁿ (Eⁿ ∩ Fⁿ) (Tⁿ ⇒ Uⁿ) Vⁿ Wⁿ F<:G V<:W = <:-resolveᶠ (Eⁿ ∩ Fⁿ) (Tⁿ ⇒ Uⁿ) Vⁿ Wⁿ F<:G V<:W
<:-resolveⁿ (Eⁿ ∩ Fⁿ) (Gⁿ ∩ Hⁿ) Vⁿ Wⁿ F<:G V<:W = <:-resolveᶠ (Eⁿ ∩ Fⁿ) (Gⁿ ∩ Hⁿ) Vⁿ Wⁿ F<:G V<:W
<:-resolveⁿ (Fⁿ ∪ Sˢ) (Tⁿ ⇒ Uⁿ) Vⁿ Wⁿ F<:G V<:W = CONTRADICTION (<:-impl-¬≮: F<:G (≮:-∪-right (scalar-≮:-function Sˢ)))
<:-resolveⁿ unknown (Tⁿ ⇒ Uⁿ) Vⁿ Wⁿ F<:G V<:W = CONTRADICTION (<:-impl-¬≮: F<:G unknown-≮:-function)
<:-resolveⁿ (Fⁿ ∪ Sˢ) (Gⁿ ∩ Hⁿ) Vⁿ Wⁿ F<:G V<:W = CONTRADICTION (<:-impl-¬≮: F<:G (≮:-∪-right (scalar-≮:-fun (Gⁿ ∩ Hⁿ) Sˢ)))
<:-resolveⁿ unknown (Gⁿ ∩ Hⁿ) Vⁿ Wⁿ F<:G V<:W = CONTRADICTION (<:-impl-¬≮: F<:G (unknown-≮:-fun (Gⁿ ∩ Hⁿ)))
<:-resolveⁿ (Rⁿ ⇒ Sⁿ) never Vⁿ Wⁿ F<:G V<:W = CONTRADICTION (<:-impl-¬≮: F<:G (fun-≮:-never (Rⁿ ⇒ Sⁿ)))
<:-resolveⁿ (Eⁿ ∩ Fⁿ) never Vⁿ Wⁿ F<:G V<:W = CONTRADICTION (<:-impl-¬≮: F<:G (fun-≮:-never (Eⁿ ∩ Fⁿ)))
<:-resolveⁿ (Fⁿ ∪ Sˢ) never Vⁿ Wⁿ F<:G V<:W = CONTRADICTION (<:-impl-¬≮: F<:G (≮:-∪-right (scalar-≮:-never Sˢ)))
<:-resolveⁿ unknown never Vⁿ Wⁿ F<:G V<:W = F<:G
<:-resolveⁿ never Gⁿ Vⁿ Wⁿ F<:G V<:W = <:-never
<:-resolveⁿ Fⁿ (Gⁿ ∪ Uˢ) Vⁿ Wⁿ F<:G V<:W = <:-unknown
<:-resolveⁿ Fⁿ unknown Vⁿ Wⁿ F<:G V<:W = <:-unknown
<:-resolve : ∀ {F G V W} → (F <: G) → (V <: W) → resolve F V <: resolve G W
<:-resolve {F} {G} {V} {W} F<:G V<:W = <:-resolveⁿ (normal F) (normal G) (normal V) (normal W)
(<:-trans (normalize-<: F) (<:-trans F<:G (<:-normalize G)))
(<:-trans (normalize-<: V) (<:-trans V<:W (<:-normalize W)))
| {
"alphanum_fraction": 0.5956394695,
"avg_line_length": 70.2473684211,
"ext": "agda",
"hexsha": "8de4a875032068744c943929af167ea0f22b5b8f",
"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": "39fbd2146a379fb0878369b48764cd7e8772c0fb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "sthagen/Roblox-luau",
"max_forks_repo_path": "prototyping/Properties/ResolveOverloads.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "39fbd2146a379fb0878369b48764cd7e8772c0fb",
"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": "sthagen/Roblox-luau",
"max_issues_repo_path": "prototyping/Properties/ResolveOverloads.agda",
"max_line_length": 307,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f1b46f4b967f11fabe666da1de0e71b225368260",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Libertus-Lab/luau",
"max_stars_repo_path": "prototyping/Properties/ResolveOverloads.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-06T08:03:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-06T08:03:00.000Z",
"num_tokens": 6225,
"size": 13347
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Rationals.QuoQ where
open import Cubical.HITs.Rationals.QuoQ.Base public
open import Cubical.HITs.Rationals.QuoQ.Properties public
| {
"alphanum_fraction": 0.7843137255,
"avg_line_length": 29.1428571429,
"ext": "agda",
"hexsha": "6e4630ce59b76445baddb5744d4d000cc24af159",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/HITs/Rationals/QuoQ.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/HITs/Rationals/QuoQ.agda",
"max_line_length": 57,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/HITs/Rationals/QuoQ.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 60,
"size": 204
} |
{-# OPTIONS --safe #-}
module Cubical.Categories.Instances.Lattice where
open import Cubical.Foundations.Prelude
open import Cubical.Algebra.Lattice
open import Cubical.Categories.Category
open import Cubical.Categories.Instances.Semilattice
open Category
LatticeCategory : ∀ {ℓ} (L : Lattice ℓ) → Category ℓ ℓ
LatticeCategory L = SemilatticeCategory (Lattice→JoinSemilattice L)
| {
"alphanum_fraction": 0.8020833333,
"avg_line_length": 25.6,
"ext": "agda",
"hexsha": "f491afd6ac33bc65285d43704f32de36c7319a2f",
"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": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lpw25/cubical",
"max_forks_repo_path": "Cubical/Categories/Instances/Lattice.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"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": "lpw25/cubical",
"max_issues_repo_path": "Cubical/Categories/Instances/Lattice.agda",
"max_line_length": 67,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lpw25/cubical",
"max_stars_repo_path": "Cubical/Categories/Instances/Lattice.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 99,
"size": 384
} |
module plfa-code.Bin where
-- I collect code about Bin there. other definitions I use the std-lib version
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym; trans)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_; _≤_; z≤n; s≤s)
open import Data.Nat.Properties using (+-comm; +-suc; +-mono-≤)
infixr 2 _≡⟨_⟩_
_≡⟨_⟩_ : ∀ {A : Set} (x : A) {y z : A}
→ x ≡ y
→ y ≡ z
-------
→ x ≡ z
x ≡⟨ x≡y ⟩ y≡z = trans x≡y y≡z
data Bin : Set where
nil : Bin
x0_ : Bin → Bin
x1_ : Bin → Bin
inc : Bin → Bin
inc nil = x1 nil
inc (x0 t) = x1 t
inc (x1 t) = x0 (inc t)
to : ℕ → Bin
to zero = x0 nil
to (suc n) = inc (to n)
from : Bin → ℕ
from nil = 0
from (x0 t) = 2 * (from t)
from (x1 t) = suc (2 * (from t))
+1≡suc : ∀ {n : ℕ} → n + 1 ≡ suc n
+1≡suc {zero} = refl
+1≡suc {suc n} = cong suc +1≡suc
suc-from-inc : ∀ (x : Bin) → from (inc x) ≡ suc (from x)
suc-from-inc nil = refl
suc-from-inc (x0 x) rewrite +1≡suc {from x * 2} = refl
suc-from-inc (x1 x) rewrite suc-from-inc x
| +-suc (from x) (from x + 0) = refl
-- t4 is ⊥ , because `to (from nil) ≡ x0 nil ≢ nil`
-- t4 : ∀ (x : Bin) → to (from x) ≡ x
from-to-const : ∀ (n : ℕ) → from (to n) ≡ n
from-to-const zero = refl
from-to-const (suc n) rewrite suc-from-inc (to n)
| from-to-const n = refl
data Can : Bin → Set
data One : Bin → Set
data One where
one : One (x1 nil)
x0_ : ∀ {b : Bin} → One b → One(x0 b)
x1_ : ∀ {b : Bin} → One b → One(x1 b)
data Can where
zero : Can (x0 nil)
can-one : ∀ {b : Bin} → One b → Can b
one-inc : ∀ {x : Bin} → One x → One (inc x)
one-inc one = x0 one
one-inc (x0 x) = x1 x
one-inc (x1 x) = x0 (one-inc x)
can-inc : ∀ {x : Bin} → Can x → Can (inc x)
can-inc zero = can-one one
can-inc (can-one x) = can-one (one-inc x)
one-to-n : ∀ (n : ℕ) → One (to (suc n))
one-to-n zero = one
one-to-n (suc n) = one-inc (one-to-n n)
can-to-n : ∀ (n : ℕ) → Can (to n)
can-to-n zero = zero
can-to-n (suc n) = can-one (one-to-n n)
open Data.Nat.Properties using (+-identityʳ; +-suc)
l0 : ∀ (n) → to (suc n) ≡ inc (to n)
l0 zero = refl
l0 (suc n) = refl
2n-eq-x0 : ∀ (n) → 1 ≤ n → to (n + n) ≡ x0 (to n)
2n-eq-x0 zero ()
2n-eq-x0 (suc zero) (s≤s z≤n) = refl
2n-eq-x0 (suc (suc n)) (s≤s z≤n) =
begin to (suc (suc n) + suc (suc n))
≡⟨ cong (λ x → to x) (+-suc (suc (suc n)) (suc n)) ⟩ to (suc (suc (suc n + suc n)))
≡⟨⟩ inc (inc (to (suc n + suc n)))
≡⟨ cong (λ x → (inc (inc x))) (2n-eq-x0 (suc n) (s≤s z≤n)) ⟩ inc (inc (x0 (to (suc n))))
≡⟨⟩ x0 (inc (to (suc n)))
≡⟨⟩ x0 (to (suc (suc n)))
∎
one-b-iff-1≤b : ∀ (b) → One b → 1 ≤ from b
one-b-iff-1≤b (x0 b) (x0 ob)
rewrite +-identityʳ (from b) = +-mono-≤ (one-b-iff-1≤b b ob) z≤n
where n = from b
one-b-iff-1≤b (x1 .nil) one = s≤s z≤n
one-b-iff-1≤b (x1 b) (x1 ob) = s≤s z≤n
one-tf-eq : ∀ {b} → One b → to (from b) ≡ b
one-tf-eq {_} one = refl
one-tf-eq {x0 b} (x0 x) =
begin
to (from (x0 b))
≡⟨⟩
to (from b + (from b + zero))
≡⟨ cong (λ n → to (from b + n)) (+-identityʳ (from b)) ⟩
to (from b + from b)
≡⟨ 2n-eq-x0 (from b) (one-b-iff-1≤b b x) ⟩
x0 (to (from b))
≡⟨ cong x0_ (one-tf-eq x) ⟩
x0 b
∎
one-tf-eq {x1 b} (x1 x) =
begin
to (from (x1 b))
≡⟨⟩
inc (to (from b + (from b + zero)))
≡⟨ cong (λ n → inc (to (from b + n))) (+-identityʳ (from b)) ⟩
inc (to (from b + from b))
≡⟨ cong inc (2n-eq-x0 (from b) (one-b-iff-1≤b b x)) ⟩
inc (x0 (to (from b)))
≡⟨⟩
x1 (to (from b))
≡⟨ cong x1_ (one-tf-eq x) ⟩
x1 b
∎
can-tf-eq : ∀ {x} → Can x → to (from x) ≡ x
can-tf-eq {_} zero = refl
can-tf-eq {b} (can-one x) = one-tf-eq x
open import Function.LeftInverse using (_↞_)
ℕ-embedding-Bin : ℕ ↞ Bin
ℕ-embedding-Bin =
record
{ to = record { _⟨$⟩_ = to ; cong = cong to }
; from = record { _⟨$⟩_ = from ; cong = cong from }
; left-inverse-of = from-to-const
}
open import Function.Inverse using (_↔_)
open import Data.Product
using (Σ; ∃; Σ-syntax; ∃-syntax) renaming (_,_ to ⟨_,_⟩)
open import Function using (_∘_)
one-assim : ∀ {b : Bin} → (x : One b) → (y : One b) → x ≡ y
one-assim one one = refl
one-assim (x0 x) (x0 y) = sym (cong x0_ (one-assim y x))
one-assim (x1 x) (x1 y) = sym (cong x1_ (one-assim y x))
can-assim : ∀ {b : Bin} → (x : Can b) → (y : Can b) → x ≡ y
can-assim zero zero = refl
can-assim zero (can-one (x0 ()))
can-assim (can-one (x0 ())) zero
can-assim (can-one one) (can-one one) = refl
can-assim (can-one (x0 x)) (can-one (x0 y)) = cong (can-one ∘ x0_) (one-assim x y)
can-assim (can-one (x1 x)) (can-one (x1 y)) = cong (can-one ∘ x1_) (one-assim x y)
∃-proj₁ : {A : Set} {B : A → Set} → ∃[ x ] B x → A
∃-proj₁ ⟨ x , _ ⟩ = x
∃≡ : ∀ {A : Set} {B : A → Set} (p₁ : ∃[ x ](B x)) (p₂ : ∃[ y ](B y))
→ ∃-proj₁ p₁ ≡ ∃-proj₁ p₂ → (∀ (x) → (b₁ : B x) → (b₂ : B x) → b₁ ≡ b₂)
→ p₁ ≡ p₂
∃≡ ⟨ x , bx ⟩ ⟨ .x , by ⟩ refl f = sym (cong (⟨_,_⟩ x) (f x by bx))
Bin-isomorphism : ℕ ↔ ∃[ x ](Can x)
Bin-isomorphism =
record
{ to = record { _⟨$⟩_ = to′; cong = cong to′}
; from = record { _⟨$⟩_ = from′; cong = cong from′}
; inverse-of = record
{ left-inverse-of = from-to-const
; right-inverse-of = to∘from′
}
}
where
to′ : ℕ → ∃[ x ](Can x)
to′ n = ⟨ to n , can-to-n n ⟩
from′ : ∃[ x ](Can x) → ℕ
from′ ⟨ b , can-b ⟩ = from b
to∘from′ : ∀ y → to′ (from′ y) ≡ y
to∘from′ ⟨ b , can-b ⟩ = ∃≡ ⟨ to (from b) , can-to-n (from b) ⟩ ⟨ b , can-b ⟩ (can-tf-eq can-b) (λ x → can-assim {x})
| {
"alphanum_fraction": 0.4979224377,
"avg_line_length": 29.0251256281,
"ext": "agda",
"hexsha": "4067a346d2158d593eba1f2fa6f3d803e92ee39e",
"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": "ec5b359a8c22bf5268cae3c36a97e6737c75d5f3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "chirsz-ever/plfa-code",
"max_forks_repo_path": "src/plfa-code/Bin.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ec5b359a8c22bf5268cae3c36a97e6737c75d5f3",
"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": "chirsz-ever/plfa-code",
"max_issues_repo_path": "src/plfa-code/Bin.agda",
"max_line_length": 120,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ec5b359a8c22bf5268cae3c36a97e6737c75d5f3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "chirsz-ever/plfa-code",
"max_stars_repo_path": "src/plfa-code/Bin.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2606,
"size": 5776
} |
{-# OPTIONS --cubical --safe #-}
open import Algebra
open import Relation.Binary
open import Algebra.Monus
module Data.MonoidalHeap.Monad {s} (monus : TMAPOM s) where
open TMAPOM monus
open import Prelude
open import Data.List using (List; _∷_; []; foldr; _++_)
import Data.Nat as ℕ
import Data.Nat.Properties as ℕ
𝒮 : Type s
𝒮 = 𝑆 → 𝑆
⟦_⇑⟧ : 𝑆 → 𝒮
⟦_⇑⟧ = _∙_
⟦_⇓⟧ : 𝒮 → 𝑆
⟦ x ⇓⟧ = x ε
infixl 10 _⊙_
_⊙_ : (𝑆 → A) → 𝑆 → 𝑆 → A
f ⊙ x = λ y → f (x ∙ y)
mutual
data Node (V : 𝑆 → Type a) : Type (a ℓ⊔ s) where
leaf : V ε → Node V
_⋊_ : (w : 𝑆) → Heap (V ⊙ w) → Node V
Heap : (𝑆 → Type a) → Type (a ℓ⊔ s)
Heap V = List (Node V)
private
variable
v : Level
V : 𝑆 → Type v
Root : (𝑆 → Type v) → Type _
Root V = ∃ w × Heap (V ⊙ w)
partition : Heap V → List (V ε) × List (Root V)
partition = foldr f ([] , [])
where
f : Node V → List (V ε) × List (∃ w × Heap (V ⊙ w)) → List (V ε) × List (∃ w × Heap (V ⊙ w))
f (leaf x) (ls , hs) = (x ∷ ls) , hs
f (w ⋊ x) (ls , hs) = ls , ((w , x) ∷ hs)
module _ {V : 𝑆 → Type v} where
⊙-assoc : ∀ x y k → x ≡ y ∙ k → V ⊙ x ≡ V ⊙ y ⊙ k
⊙-assoc x y k x≡y∙k i z = V ((cong (_∙ z) x≡y∙k ; assoc y k z) i)
⊙ε : V ⊙ ε ≡ V
⊙ε i x = V (ε∙ x i)
⊙-rassoc : ∀ x y → V ⊙ (x ∙ y) ≡ V ⊙ x ⊙ y
⊙-rassoc x y i z = V (assoc x y z i)
merge : Root V → Root V → Root V
merge (x , xs) (y , ys) with x ≤|≥ y
... | inl (k , y≡x∙k) = x , (k ⋊ subst Heap (⊙-assoc y x k y≡x∙k) ys) ∷ xs
... | inr (k , x≡y∙k) = y , (k ⋊ subst Heap (⊙-assoc x y k x≡y∙k) xs) ∷ ys
merges⁺ : Root V → List (Root V) → Root V
merges⁺ x [] = x
merges⁺ x₁ (x₂ ∷ []) = merge x₁ x₂
merges⁺ x₁ (x₂ ∷ x₃ ∷ xs) = merge (merge x₁ x₂) (merges⁺ x₃ xs)
merges : List (Root V) → Maybe (Root V)
merges [] = nothing
merges (x ∷ xs) = just (merges⁺ x xs)
popMin : Heap V → List (V ε) × Maybe (Root V)
popMin = map₂ merges ∘ partition
return : V ε → Heap V
return x = leaf x ∷ []
weight : ∃ x × V x → Heap V
weight (w , x) = (w ⋊ (leaf (subst V (sym (∙ε w)) x) ∷ [])) ∷ []
_>>=_ : Heap V → (∀ {x} → V x → Heap (V ⊙ x)) → Heap V
_>>=_ [] k = []
_>>=_ (leaf x ∷ xs) k = subst Heap ⊙ε (k x) ++ (xs >>= k)
_>>=_ {V = V} ((w ⋊ x) ∷ xs) k = (w ⋊ (x >>= (subst Heap (⊙-rassoc {V = V} w _) ∘ k))) ∷ (xs >>= k)
| {
"alphanum_fraction": 0.484463895,
"avg_line_length": 25.3888888889,
"ext": "agda",
"hexsha": "69af5bfbf1a2b86d1ca69a76e585f4abbe5d1745",
"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/MonoidalHeap/Monad.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/MonoidalHeap/Monad.agda",
"max_line_length": 99,
"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/MonoidalHeap/Monad.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": 1107,
"size": 2285
} |
-- Integers modulo N
module Numeric.Nat.Modulo where
open import Prelude
open import Numeric.Nat.DivMod
open import Tactic.Nat
data IntMod (n : Nat) : Set where
modn : ∀ k → k < n → IntMod n
{-# DISPLAY modn k (LessNat.diff _ refl) = k #-}
negIntMod : ∀ {n} → IntMod n → IntMod n
negIntMod (modn 0 lt) = modn 0 lt
negIntMod (modn (suc k) (diff j eq)) = modn (suc j) (by (sym eq))
{-# DISPLAY negIntMod a = negate a #-}
instance
NumberIntMod : ∀ {n} → Number (IntMod (suc n))
Number.Constraint NumberIntMod _ = ⊤
fromNat {{NumberIntMod {n}}} k with k divmod suc n
... | qr _ r lt _ = modn r lt
NegativeIntMod : ∀ {n} → Negative (IntMod (suc n))
Negative.Constraint NegativeIntMod _ = ⊤
fromNeg {{NegativeIntMod}} k = negIntMod (fromNat k)
addIntMod : ∀ {n} → IntMod (suc n) → IntMod (suc n) → IntMod (suc n)
addIntMod {n} (modn a _) (modn b _) = force (a + b) λ a+b → fromNat a+b ofType IntMod (suc n)
mulIntMod : ∀ {n} → IntMod (suc n) → IntMod (suc n) → IntMod (suc n)
mulIntMod {n} (modn a _) (modn b _) = force (a * b) λ a*b → fromNat a*b ofType IntMod (suc n)
subIntMod : ∀ {n} → IntMod (suc n) → IntMod (suc n) → IntMod (suc n)
subIntMod a b = addIntMod a (negIntMod b)
{-# DISPLAY addIntMod a b = a + b #-}
{-# DISPLAY mulIntMod a b = a * b #-}
{-# DISPLAY subIntMod a b = a - b #-}
instance
SemiringIntMod : ∀ {n} → Semiring (IntMod (suc n))
zro {{SemiringIntMod}} = 0
one {{SemiringIntMod}} = 1
_+_ {{SemiringIntMod}} = addIntMod
_*_ {{SemiringIntMod}} = mulIntMod
SubtractiveIntMod : ∀ {n} → Subtractive (IntMod (suc n))
_-_ {{SubtractiveIntMod}} = subIntMod
negate {{SubtractiveIntMod}} = negIntMod
| {
"alphanum_fraction": 0.6338962606,
"avg_line_length": 31.2830188679,
"ext": "agda",
"hexsha": "e6c73af8673d20bbb0caa0dae02e485b6728cef7",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "t-more/agda-prelude",
"max_forks_repo_path": "src/Numeric/Nat/Modulo.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "t-more/agda-prelude",
"max_issues_repo_path": "src/Numeric/Nat/Modulo.agda",
"max_line_length": 93,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "t-more/agda-prelude",
"max_stars_repo_path": "src/Numeric/Nat/Modulo.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 613,
"size": 1658
} |
module Languages.FILL.TypeSyntax where
open import Utils.HaskellTypes
{-# IMPORT Languages.FILL.TypeSyntax #-}
data Type : Set where
TVar : String → Type
Top : Type
Bottom : Type
Imp : Type → Type → Type
Tensor : Type → Type → Type
Par : Type → Type → Type
{-# COMPILED_DATA Type Languages.FILL.TypeSyntax.Type
Languages.FILL.TypeSyntax.TVar
Languages.FILL.TypeSyntax.Top
Languages.FILL.TypeSyntax.Bottom
Languages.FILL.TypeSyntax.Imp
Languages.FILL.TypeSyntax.Tensor
Languages.FILL.TypeSyntax.Par #-}
| {
"alphanum_fraction": 0.5921450151,
"avg_line_length": 30.0909090909,
"ext": "agda",
"hexsha": "4b1ea372ff07c0017da7c001c6fe12632a5e0342",
"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": "c83f5d8201362b26a749138f6dbff2dd509f85b1",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "heades/Agda-LLS",
"max_forks_repo_path": "Source/ALL/Languages/FILL/TypeSyntax.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1",
"max_issues_repo_issues_event_max_datetime": "2017-04-05T17:30:16.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-03-27T14:52:46.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "heades/Agda-LLS",
"max_issues_repo_path": "Source/ALL/Languages/FILL/TypeSyntax.agda",
"max_line_length": 56,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "heades/Agda-LLS",
"max_stars_repo_path": "Source/ALL/Languages/FILL/TypeSyntax.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-02T23:41:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-09T20:53:53.000Z",
"num_tokens": 127,
"size": 662
} |
open import Agda.Primitive
variable
a : Level
A : Set a
P : A → Set a
x : A
open import Agda.Builtin.Equality
data Box (A : Set a) : Set a where
[_] : A → Box A
postulate
_ : P (λ (_ : x ≡ x) → [ x ])
| {
"alphanum_fraction": 0.5596330275,
"avg_line_length": 12.8235294118,
"ext": "agda",
"hexsha": "9696313aa2fc902f6c1ccfa945a57529a2c5792a",
"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/Issue4292.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/Issue4292.agda",
"max_line_length": 34,
"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/Issue4292.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": 85,
"size": 218
} |
-- Internal monoid in a strict monoidal category
{-# OPTIONS --safe #-}
open import Cubical.Categories.Category.Base
open import Cubical.Categories.Monoidal.Base
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Path
open import Cubical.Categories.Functor.Base
open import Cubical.Reflection.RecordEquiv hiding (unit)
module Cubical.Categories.Monoidal.Strict.Monoid {ℓ ℓ' : Level} (C : StrictMonCategory ℓ ℓ') where
module _ where
open StrictMonCategory C
record Monoid : Type (ℓ-max ℓ ℓ') where
constructor monoid
field
carrier : ob
η : Hom[ unit , carrier ]
μ : Hom[ carrier ⊗ carrier , carrier ]
assoc-μ : PathP (λ i → Hom[ assoc carrier carrier carrier i , carrier ]) (μ ∘ (id ⊗ₕ μ)) (μ ∘ (μ ⊗ₕ id))
idl-μ : PathP (λ i → Hom[ idl carrier i , carrier ]) (μ ∘ (η ⊗ₕ id)) id
idr-μ : PathP (λ i → Hom[ idr carrier i , carrier ]) (μ ∘ (id ⊗ₕ η)) id
open Monoid
record Monoid[_,_] (monA monB : Monoid) : Type ℓ' where
constructor monoidHom
field
carrierHom : Hom[ carrier monA , carrier monB ]
nat-η : carrierHom ∘ η monA ≡ η monB
nat-μ : carrierHom ∘ μ monA ≡ μ monB ∘ (carrierHom ⊗ₕ carrierHom)
open Monoid[_,_]
monoidHomExt : {monA monB : Monoid} (f g : Monoid[ monA , monB ]) → carrierHom f ≡ carrierHom g → f ≡ g
carrierHom (monoidHomExt f g p i) = p i
nat-η (monoidHomExt {monA} {monB} f g p i) = lemma i
where lemma : PathP (λ i₁ → p i₁ ∘ η monA ≡ η monB) (nat-η f) (nat-η g)
lemma = toPathP (isSetHom _ _ _ _)
nat-μ (monoidHomExt {monA} {monB} f g p i) = lemma i
where lemma : PathP (λ i₁ → p i₁ ∘ μ monA ≡ μ monB ∘ (p i₁ ⊗ₕ p i₁)) (nat-μ f) (nat-μ g)
lemma = toPathP (isSetHom _ _ _ _)
module C = StrictMonCategory C
open Category
open Monoid
open Monoid[_,_]
open Functor
monoidCategory : Category (ℓ-max ℓ ℓ') ℓ'
ob monoidCategory = Monoid
Hom[_,_] monoidCategory = Monoid[_,_]
carrierHom (id monoidCategory) = C.id
nat-η (id monoidCategory {monA}) = C.⋆IdR (η monA)
nat-μ (id monoidCategory {monA}) =
C.id C.∘ μ monA
≡⟨ C.⋆IdR (μ monA) ⟩
μ monA
≡⟨ sym (C.⋆IdL (μ monA)) ⟩
μ monA C.∘ id C.C
≡⟨ cong (μ monA C.∘_) (sym (F-id C.─⊗─)) ⟩
μ monA C.∘ (C.id C.⊗ₕ C.id) ∎
carrierHom (_⋆_ monoidCategory f g) = carrierHom g C.∘ carrierHom f
nat-η (_⋆_ monoidCategory {monA} {monB} {monC} f g) =
(carrierHom g C.∘ carrierHom f) C.∘ η monA
≡⟨ sym (C.⋆Assoc (η monA) (carrierHom f) (carrierHom g)) ⟩
carrierHom g C.∘ (carrierHom f C.∘ η monA)
≡⟨ cong (carrierHom g C.∘_) (nat-η f) ⟩
carrierHom g C.∘ η monB
≡⟨ nat-η g ⟩
η monC ∎
nat-μ (_⋆_ monoidCategory {monA} {monB} {monC} f g) =
(carrierHom g C.∘ carrierHom f) C.∘ μ monA
≡⟨ sym (C.⋆Assoc (μ monA) (carrierHom f) (carrierHom g)) ⟩
carrierHom g C.∘ (carrierHom f C.∘ μ monA)
≡⟨ cong (carrierHom g C.∘_) (nat-μ f) ⟩
carrierHom g C.∘ (μ monB C.∘ (carrierHom f C.⊗ₕ carrierHom f))
≡⟨ C.⋆Assoc (carrierHom f C.⊗ₕ carrierHom f) (μ monB) (carrierHom g) ⟩
(carrierHom g C.∘ μ monB) C.∘ (carrierHom f C.⊗ₕ carrierHom f)
≡⟨ cong (C._∘ (carrierHom f C.⊗ₕ carrierHom f)) (nat-μ g) ⟩
(μ monC C.∘ (carrierHom g C.⊗ₕ carrierHom g)) C.∘ (carrierHom f C.⊗ₕ carrierHom f)
≡⟨ sym (C.⋆Assoc (carrierHom f C.⊗ₕ carrierHom f) (carrierHom g C.⊗ₕ carrierHom g) (μ monC)) ⟩
μ monC C.∘ ((carrierHom g C.⊗ₕ carrierHom g) C.∘ (carrierHom f C.⊗ₕ carrierHom f))
≡⟨ cong (μ monC C.∘_) (sym (F-seq C.─⊗─ (carrierHom f , carrierHom f) (carrierHom g , carrierHom g))) ⟩
μ monC C.∘ ((carrierHom g C.∘ carrierHom f) C.⊗ₕ (carrierHom g C.∘ carrierHom f)) ∎
⋆IdL monoidCategory {monA} f = monoidHomExt _ _ (C.⋆IdL (carrierHom f))
⋆IdR monoidCategory {monA} f = monoidHomExt _ _ (C.⋆IdR (carrierHom f))
⋆Assoc monoidCategory {monA} {monB} {monC} {monD} f g h =
monoidHomExt _ _ (C.⋆Assoc (carrierHom f) (carrierHom g) (carrierHom h))
isSetHom monoidCategory {monA} {monB} =
isOfHLevelRetractFromIso 2 isoToΣ
(isSetΣ C.isSetHom λ _ → isProp→isSet (isProp× (C.isSetHom _ _) (C.isSetHom _ _)))
where
unquoteDecl isoToΣ = declareRecordIsoΣ isoToΣ (quote Monoid[_,_])
| {
"alphanum_fraction": 0.6324298621,
"avg_line_length": 42.9183673469,
"ext": "agda",
"hexsha": "16db85daf082f412a38682920736567a86012c74",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Categories/Monoidal/Strict/Monoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Categories/Monoidal/Strict/Monoid.agda",
"max_line_length": 112,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Categories/Monoidal/Strict/Monoid.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": 1762,
"size": 4206
} |
------------------------------------------------------------------------
-- Lifting of weak equality to canonical equality
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module FOmegaInt.Kinding.Canonical.WeakEquality where
open import Data.Product as Prod using (∃; _×_; _,_)
open import Relation.Binary.PropositionalEquality using (_≡_; subst; sym; trans)
open import FOmegaInt.Syntax
open import FOmegaInt.Syntax.HereditarySubstitution
open import FOmegaInt.Syntax.Normalization
open import FOmegaInt.Syntax.WeakEquality
open import FOmegaInt.Kinding.Canonical
open import FOmegaInt.Kinding.Canonical.HereditarySubstitution
------------------------------------------------------------------------
-- Lifting of weak kind/type equality into canonical equality.
--
-- The lemmas below state that a variant of reflexivity is admissible
-- in canonical subkinding, subtyping as well as kind and type
-- equality, which uses weak equality (instead of syntactic equality)
-- along with proofs of canonical well-formedness
-- resp. well-kindedness of *both* the kinds resp. types being
-- related.
open Syntax
open ElimCtx
open Kinding
open ContextNarrowing
-- Lifting of weak kind/type equality into canonical
-- subkinding/subtyping and type/kind equality.
mutual
≋-<∷ : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j kd → Γ ⊢ k kd → j ≋ k → Γ ⊢ j <∷ k
≋-<∷ (kd-⋯ a₁⇉a₁⋯a₁ b₁⇉b₁⋯b₁) (kd-⋯ a₂⇉a₂⋯a₂ b₂⇉b₂⋯b₂) (≋-⋯ a₁≈a₂ b₁≈b₂) =
<∷-⋯ (≈-<: a₂⇉a₂⋯a₂ a₁⇉a₁⋯a₁ (≈-sym a₁≈a₂)) (≈-<: b₁⇉b₁⋯b₁ b₂⇉b₂⋯b₂ b₁≈b₂)
≋-<∷ (kd-Π j₁-kd k₁-kd) (kd-Π j₂-kd k₂-kd) (≋-Π j₁≋j₂ k₁≋k₂) =
let j₂<∷j₁ = ≋-<∷ j₂-kd j₁-kd (≋-sym j₁≋j₂)
in <∷-Π j₂<∷j₁ (≋-<∷ (⇓-kd j₂-kd j₂<∷j₁ k₁-kd) k₂-kd k₁≋k₂)
(kd-Π j₁-kd k₁-kd)
≈-<: : ∀ {n} {Γ : Ctx n} {a a₁ a₂ b b₁ b₂} →
Γ ⊢Nf a ⇉ a₁ ⋯ a₂ → Γ ⊢Nf b ⇉ b₁ ⋯ b₂ → a ≈ b → Γ ⊢ a <: b
≈-<: (⇉-⊥-f Γ-ctx) (⇉-⊥-f _) (≈-∙ ≈-⊥ ≈-[]) = <:-⊥ (⇉-⊥-f Γ-ctx)
≈-<: (⇉-⊥-f _) (⇉-s-i ()) (≈-∙ ≈-⊥ ≈-[])
≈-<: (⇉-⊤-f Γ-ctx) (⇉-⊤-f _) (≈-∙ ≈-⊤ ≈-[]) = <:-⊤ (⇉-⊤-f Γ-ctx)
≈-<: (⇉-⊤-f _) (⇉-s-i ()) (≈-∙ ≈-⊤ ≈-[])
≈-<: (⇉-∀-f k₁-kd a₁⇉a₁⋯a₁) (⇉-∀-f k₂-kd a₂⇉a₂⋯a₂)
(≈-∙ (≈-∀ k₁≋k₂ a₁≈a₂) ≈-[]) =
let k₂<∷k₁ = ≋-<∷ k₂-kd k₁-kd (≋-sym k₁≋k₂)
in <:-∀ k₂<∷k₁ (≈-<: (⇓-Nf⇉ k₂-kd k₂<∷k₁ a₁⇉a₁⋯a₁) a₂⇉a₂⋯a₂ a₁≈a₂)
(⇉-∀-f k₁-kd a₁⇉a₁⋯a₁)
≈-<: (⇉-∀-f _ _) (⇉-s-i ()) (≈-∙ (≈-∀ _ _) ≈-[])
≈-<: (⇉-→-f a₁⇉a₁⋯a₁ b₁⇉b₁⋯b₁) (⇉-→-f a₂⇉a₂⋯a₂ b₂⇉b₂⋯b₂)
(≈-∙ (≈-→ a₁≈a₂ b₁≈b₂) ≈-[]) =
<:-→ (≈-<: a₂⇉a₂⋯a₂ a₁⇉a₁⋯a₁ (≈-sym a₁≈a₂)) (≈-<: b₁⇉b₁⋯b₁ b₂⇉b₂⋯b₂ b₁≈b₂)
≈-<: (⇉-→-f _ _) (⇉-s-i ()) (≈-∙ (≈-→ _ _) ≈-[])
≈-<: (⇉-s-i (∈-∙ x∈j₁ j₁⇉as₁⇉k₁)) (⇉-s-i (∈-∙ x∈j₂ j₂⇉as₂⇉k₂))
(≈-∙ (≈-var x) as₁≈as₂) =
let j , Γ[x]≡kd-j , j<∷j₁ , j-kd , _ = Var∈-inv x∈j₁
j′ , Γ[x]≡kd-j′ , j′<∷j₂ , _ , _ = Var∈-inv x∈j₂
j′≡j = kd-inj (trans (sym Γ[x]≡kd-j′) Γ[x]≡kd-j)
j<∷j₂ = subst (_ ⊢_<∷ _) j′≡j j′<∷j₂
c , d , j⇉as₁≃as₂⇉c⋯d = ≈Sp-Sp≃ j-kd j<∷j₁ j<∷j₂
j₁⇉as₁⇉k₁ j₂⇉as₂⇉k₂ as₁≈as₂
in <:-∙ (⇉-var x (Var∈-ctx x∈j₁) Γ[x]≡kd-j) j⇉as₁≃as₂⇉c⋯d
≈-<:⇇ : ∀ {n} {Γ : Ctx n} {a b j} →
Γ ⊢ j kd → Γ ⊢Nf a ⇇ j → Γ ⊢Nf b ⇇ j → a ≈ b → Γ ⊢ a <: b ⇇ j
≈-<:⇇ b⋯c-kd
(⇇-⇑ a₁⇉b₁⋯c₁ (<∷-⋯ b<:b₁ c₁<:c))
(⇇-⇑ a₂⇉b₂⋯c₂ (<∷-⋯ b<:b₂ c₂<:c)) a₁≈a₂ =
<:-⇇ (⇇-⇑ a₁⇉b₁⋯c₁ (<∷-⋯ b<:b₁ c₁<:c)) (⇇-⇑ a₂⇉b₂⋯c₂ (<∷-⋯ b<:b₂ c₂<:c))
(≈-<: (Nf⇉-s-i a₁⇉b₁⋯c₁) (Nf⇉-s-i a₂⇉b₂⋯c₂) a₁≈a₂)
≈-<:⇇ (kd-Π j-kd k-kd)
(⇇-⇑ (⇉-Π-i j₁-kd a₁⇉k₁) (<∷-Π j<∷j₁ k₁<∷k Πj₁k₁-kd))
(⇇-⇑ (⇉-Π-i j₂-kd a₂⇉k₂) (<∷-Π j<∷j₂ k₂<∷k Πj₂k₂-kd))
(≈-∙ (≈-Λ ⌊k₁⌋≡⌊k₂⌋ a₁≈a₂) ≈-[]) =
let a₁⇇k = ⇇-⇑ (⇓-Nf⇉ j-kd j<∷j₁ a₁⇉k₁) k₁<∷k
a₂⇇k = ⇇-⇑ (⇓-Nf⇉ j-kd j<∷j₂ a₂⇉k₂) k₂<∷k
a₁<:a₂⇇k = ≈-<:⇇ k-kd a₁⇇k a₂⇇k a₁≈a₂
in <:-λ a₁<:a₂⇇k
(⇇-⇑ (⇉-Π-i j₁-kd a₁⇉k₁) (<∷-Π j<∷j₁ k₁<∷k Πj₁k₁-kd))
(⇇-⇑ (⇉-Π-i j₂-kd a₂⇉k₂) (<∷-Π j<∷j₂ k₂<∷k Πj₂k₂-kd))
≈Sp-Sp≃ : ∀ {n} {Γ : Ctx n} {as₁ as₂ j j₁ j₂ b₁ b₂ c₁ c₂} →
Γ ⊢ j kd → Γ ⊢ j <∷ j₁ → Γ ⊢ j <∷ j₂ →
Γ ⊢ j₁ ⇉∙ as₁ ⇉ b₁ ⋯ c₁ → Γ ⊢ j₂ ⇉∙ as₂ ⇉ b₂ ⋯ c₂ → as₁ ≈Sp as₂ →
∃ λ b → ∃ λ c → Γ ⊢ j ⇉∙ as₁ ≃ as₂ ⇉ b ⋯ c
≈Sp-Sp≃ j-kd (<∷-⋯ b₁<:b c<:c₁) j<∷b₂⋯c₂ ⇉-[] ⇉-[] ≈-[] = _ , _ , ≃-[]
≈Sp-Sp≃ (kd-Π j-kd k-kd)
(<∷-Π j₁<∷j k<∷k₁ Πj₁k₁-kd) (<∷-Π j₂<∷j k<∷k₂ Πj₂k₂-kd)
(⇉-∷ a₁⇇j₁ j₁-kd k₁[a₁]⇉bs₁⇉c₁⋯d₁)
(⇉-∷ a₂⇇j₂ j₂-kd k₂[a₂]⇉bs₂⇉c₂⋯d₂) (≈-∷ a₁≈a₂ bs₁≈bs₂) =
let a₁⇇j = Nf⇇-⇑ a₁⇇j₁ j₁<∷j
k[a₁]-kd = TK.kd-/⟨⟩ k-kd (⇇-hsub a₁⇇j j-kd (⌊⌋-⌊⌋≡ _))
a₁≃a₂⇇j = ≈-≃ j-kd a₁⇇j (Nf⇇-⇑ a₂⇇j₂ j₂<∷j) a₁≈a₂
k[a₁]<∷k₁[a₁] = subst (λ l → _ ⊢ _ Kind[ _ ∈ l ] <∷ _) (<∷-⌊⌋ j₁<∷j)
(TK.<∷-/⟨⟩≃ k<∷k₁ (⇇-hsub a₁⇇j₁ j₁-kd (⌊⌋-⌊⌋≡ _)))
k[a₂]<∷k₂[a₂] = subst (λ l → _ ⊢ _ Kind[ _ ∈ l ] <∷ _) (<∷-⌊⌋ j₂<∷j)
(TK.<∷-/⟨⟩≃ k<∷k₂ (⇇-hsub a₂⇇j₂ j₂-kd (⌊⌋-⌊⌋≡ _)))
k[a₁]<∷k[a₂] = TK.kd-/⟨⟩≃-<∷ k-kd (≃-hsub a₁≃a₂⇇j (⌊⌋-⌊⌋≡ _))
k[a₁]<∷k₂[a₂] = <∷-trans k[a₁]<∷k[a₂] k[a₂]<∷k₂[a₂]
c , d , k[a₁]⇉bs₁≃bs₂⇉c⋯d = ≈Sp-Sp≃ k[a₁]-kd k[a₁]<∷k₁[a₁] k[a₁]<∷k₂[a₂]
k₁[a₁]⇉bs₁⇉c₁⋯d₁ k₂[a₂]⇉bs₂⇉c₂⋯d₂
bs₁≈bs₂
in c , d , ≃-∷ a₁≃a₂⇇j k[a₁]⇉bs₁≃bs₂⇉c⋯d
where
module TK = TrackSimpleKindsSubst
≈-≃ : ∀ {n} {Γ : Ctx n} {a b j} →
Γ ⊢ j kd → Γ ⊢Nf a ⇇ j → Γ ⊢Nf b ⇇ j → a ≈ b → Γ ⊢ a ≃ b ⇇ j
≈-≃ j-kd a⇇j b⇇j a≈b =
<:-antisym j-kd (≈-<:⇇ j-kd a⇇j b⇇j a≈b) (≈-<:⇇ j-kd b⇇j a⇇j (≈-sym a≈b))
≋-≅ : ∀ {n} {Γ : Ctx n} {j k} → Γ ⊢ j kd → Γ ⊢ k kd → j ≋ k → Γ ⊢ j ≅ k
≋-≅ j-kd k-kd j≋k =
<∷-antisym j-kd k-kd (≋-<∷ j-kd k-kd j≋k) (≋-<∷ k-kd j-kd (≋-sym j≋k))
| {
"alphanum_fraction": 0.4194325021,
"avg_line_length": 46.52,
"ext": "agda",
"hexsha": "8d733b3c2c5229aff0ca9d7ef80efee679a4234f",
"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": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Blaisorblade/f-omega-int-agda",
"max_forks_repo_path": "src/FOmegaInt/Kinding/Canonical/WeakEquality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"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": "Blaisorblade/f-omega-int-agda",
"max_issues_repo_path": "src/FOmegaInt/Kinding/Canonical/WeakEquality.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Blaisorblade/f-omega-int-agda",
"max_stars_repo_path": "src/FOmegaInt/Kinding/Canonical/WeakEquality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3847,
"size": 5815
} |
{-# OPTIONS --safe #-}
module Cubical.Data.Int.MoreInts.DeltaInt where
open import Cubical.Data.Int.MoreInts.DeltaInt.Base public
open import Cubical.Data.Int.MoreInts.DeltaInt.Properties public
| {
"alphanum_fraction": 0.8020304569,
"avg_line_length": 28.1428571429,
"ext": "agda",
"hexsha": "9c7ad092263176adee9a4a645f9e21a989f73ac1",
"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/Int/MoreInts/DeltaInt.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/Int/MoreInts/DeltaInt.agda",
"max_line_length": 64,
"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/Int/MoreInts/DeltaInt.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": 48,
"size": 197
} |
module Issue442 where
postulate
A : Set
f : (P : A → A → Set) → (∀ {x} → P x x) →
(∀ {x y z} → P y z → P x y → A) → A
P : A → A → Set
reflP : ∀ {x} → P x x
g : ∀ {x y z} → P y z → P x y → A
a : A
a = f _ (λ {x} → reflP {x}) g
-- Test case was:
-- {-# OPTIONS --allow-unsolved-metas #-}
-- a = f _ reflP g
| {
"alphanum_fraction": 0.4276923077,
"avg_line_length": 18.0555555556,
"ext": "agda",
"hexsha": "330b542b33e6a21fbeaed20f5188d4fd4a80c915",
"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/Issue442.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/Issue442.agda",
"max_line_length": 43,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue442.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": 150,
"size": 325
} |
module Numeric.Rational where
open import Prelude
open import Numeric.Nat.GCD
open import Numeric.Nat.GCD.Extended
open import Numeric.Nat.GCD.Properties
open import Numeric.Nat.Prime
open import Numeric.Nat.Prime.Properties
open import Numeric.Nat.Divide
open import Numeric.Nat.Divide.Properties
open import Numeric.Nat.Properties
open import Tactic.Nat
open import Tactic.Nat.Coprime
record Rational : Set where
no-eta-equality
constructor ratio
field numerator : Nat
denominator : Nat
⦃ d>0 ⦄ : NonZero denominator
n⊥d : Coprime numerator denominator
open Rational public using (numerator; denominator)
infixl 7 mkratio
syntax mkratio p q = p :/ q
mkratio : (p q : Nat) {{_ : NonZero q}} → Rational
mkratio p q = gcdReduce-r p q λ p′ q′ _ _ _ prf → ratio p′ q′ prf
mkratio-sound : (p q : Nat) {{_ : NonZero q}} → p * denominator (mkratio p q) ≡ q * numerator (mkratio p q)
mkratio-sound p q with gcd p q
... | gcd-res d (is-gcd (factor! p′) (factor! q′) _) = auto
NonZeroQ : Rational → Set
NonZeroQ x = NonZero (numerator x)
infixl 6 _+Q_ _-Q_
infixl 7 _*Q_ _/Q_
_+Q_ : Rational → Rational → Rational
ratio n₁ d₁ n₁/d₁ +Q ratio n₂ d₂ n₂/d₂ =
gcdReduce d₁ d₂ λ d₁′ d₂′ g eq₁ eq₂ d₁′/d₂′ →
gcdReduce-r (n₁ * d₂′ + n₂ * d₁′) g λ s′ g′ g₁ eqs eqg s′/g′ →
let instance _ = mul-nonzero d₁′ d₂′
_ = mul-nonzero (d₁′ * d₂′) g′
in ratio s′ (d₁′ * d₂′ * g′) $
let[ _ := lemma s′ n₁ d₁ n₂ d₂ d₁′ d₂′ g g₁ eqs eq₁ n₁/d₁ d₁′/d₂′ ]
let[ _ := lemma s′ n₂ d₂ n₁ d₁ d₂′ d₁′ g g₁ (by eqs) eq₂ n₂/d₂ auto-coprime ]
auto-coprime
where
lemma : ∀ s′ n₁ d₁ n₂ d₂ d₁′ d₂′ g g₁ →
s′ * g₁ ≡ n₁ * d₂′ + n₂ * d₁′ →
d₁′ * g ≡ d₁ →
Coprime n₁ d₁ → Coprime d₁′ d₂′ → Coprime s′ d₁′
lemma s′ n₁ d₁ n₂ d₂ d₁′ d₂′ g g₁ eqs refl n₁/d₁ d₁′/d₂′ =
coprimeByPrimes s′ d₁′ λ p isP p|s′ p|d₁′ →
let p|n₁d₂′ : p Divides (n₁ * d₂′)
p|n₁d₂′ = divides-sub-r {n₁ * d₂′} {n₂ * d₁′}
(transport (p Divides_) eqs (divides-mul-l g₁ p|s′))
(divides-mul-r n₂ p|d₁′)
p|d₁ : p Divides d₁
p|d₁ = divides-mul-l g p|d₁′
p/n₁ : Coprime p n₁
p/n₁ = case prime-coprime/divide p n₁ isP of λ where
(left p/n₁) → p/n₁
(right p|n₁) → ⊥-elim (prime-divide-coprime p n₁ d₁ isP n₁/d₁ p|n₁ p|d₁)
p|d₂′ : p Divides d₂′
p|d₂′ = coprime-divide-mul-l p n₁ d₂′ p/n₁ p|n₁d₂′
in divide-coprime p d₁′ d₂′ d₁′/d₂′ p|d₁′ p|d₂′
-- Specification for addition
slowAddQ : Rational → Rational → Rational
slowAddQ (ratio p q _) (ratio p₁ q₁ _) =
mkratio (p * q₁ + p₁ * q) (q * q₁) ⦃ mul-nonzero q q₁ ⦄
_-Q_ : Rational → Rational → Rational
ratio p q _ -Q ratio p₁ q₁ _ =
mkratio (p * q₁ - p₁ * q) (q * q₁) ⦃ mul-nonzero q q₁ ⦄
-- Fast multiplication based on the same technique as the fast addition, except it's much
-- simpler for multiplication.
_*Q_ : Rational → Rational → Rational
ratio n₁ d₁ _ *Q ratio n₂ d₂ _ =
gcdReduce-r n₁ d₂ λ n₁′ d₂′ g₁ n₁′g₁=n₁ d₂′g₁=d₂ _ →
gcdReduce-r n₂ d₁ λ n₂′ d₁′ g₂ n₂′g₂=n₂ d₁′g₂=d₁ _ →
let instance _ = mul-nonzero d₁′ d₂′ in
ratio (n₁′ * n₂′) (d₁′ * d₂′) $
case₄ n₁′g₁=n₁ , d₂′g₁=d₂ , n₂′g₂=n₂ , d₁′g₂=d₁ of λ where
refl refl refl refl → auto-coprime
-- Specification for multiplication
slowMulQ : Rational → Rational → Rational
slowMulQ (ratio p q _) (ratio p₁ q₁ _) = mkratio (p * p₁) (q * q₁) {{mul-nonzero q q₁}}
recip : (x : Rational) {{_ : NonZeroQ x}} → Rational
recip (ratio 0 q eq) {{}}
recip (ratio (suc p) q eq) = ratio q (suc p) auto-coprime
_/Q_ : (x y : Rational) {{_ : NonZeroQ y}} → Rational
x /Q y = x *Q recip y
instance
FracQ : Fractional Rational
Fractional.Constraint FracQ _ y = NonZeroQ y
Fractional._/_ FracQ x y = x /Q y
{-# DISPLAY _+Q_ a b = a + b #-}
{-# DISPLAY _-Q_ a b = a - b #-}
{-# DISPLAY _*Q_ a b = a * b #-}
{-# DISPLAY ratio a b refl = a / b #-}
instance
NumberRational : Number Rational
Number.Constraint NumberRational _ = ⊤
fromNat {{NumberRational}} n = n :/ 1
SemiringRational : Semiring Rational
zro {{SemiringRational}} = 0 :/ 1
one {{SemiringRational}} = 1 :/ 1
_+_ {{SemiringRational}} = _+Q_
_*_ {{SemiringRational}} = _*Q_
ShowRational : Show Rational
showsPrec {{ShowRational}} _ (ratio p 1 _) = shows p
showsPrec {{ShowRational}} _ (ratio p q _) = shows p ∘ showString "/" ∘ shows q
-- Ordering --
private
module _ {p q eq p₁ q₁ eq₁} {{_ : NonZero q}} {{_ : NonZero q₁}} where
ratio-inj₁ : ratio p q eq ≡ ratio p₁ q₁ eq₁ → p ≡ p₁
ratio-inj₁ refl = refl
ratio-inj₂ : ratio p q eq ≡ ratio p₁ q₁ eq₁ → q ≡ q₁
ratio-inj₂ refl = refl
cong-ratio : ∀ {p q eq p₁ q₁ eq₁} {nzq : NonZero q} {nzq₁ : NonZero q₁} →
p ≡ p₁ → q ≡ q₁ → ratio p q ⦃ nzq ⦄ eq ≡ ratio p₁ q₁ ⦃ nzq₁ ⦄ eq₁
cong-ratio {q = zero} {nzq = ()}
cong-ratio {q = suc q} refl refl = ratio _ _ $≡ smashed
instance
EqRational : Eq Rational
_==_ {{EqRational}} (ratio p q prf) (ratio p₁ q₁ prf₁) with p == p₁ | q == q₁
... | no p≠p₁ | _ = no (p≠p₁ ∘ ratio-inj₁)
... | yes _ | no q≠q₁ = no (q≠q₁ ∘ ratio-inj₂)
... | yes p=p₁ | yes q=q₁ = yes (cong-ratio p=p₁ q=q₁)
data LessQ (x y : Rational) : Set where
lessQ : numerator x * denominator y < numerator y * denominator x → LessQ x y
private
lem-unique : ∀ n₁ d₁ n₂ d₂ ⦃ _ : NonZero d₁ ⦄ ⦃ _ : NonZero d₂ ⦄ →
Coprime n₁ d₁ → Coprime n₂ d₂ →
n₁ * d₂ ≡ n₂ * d₁ → n₁ ≡ n₂ × d₁ ≡ d₂
lem-unique n₁ d₁ n₂ d₂ n₁⊥d₁ n₂⊥d₂ eq =
let n₁|n₂ : n₁ Divides n₂
n₁|n₂ = coprime-divide-mul-r n₁ n₂ d₁ n₁⊥d₁ (factor d₂ (by eq))
n₂|n₁ : n₂ Divides n₁
n₂|n₁ = coprime-divide-mul-r n₂ n₁ d₂ n₂⊥d₂ (factor d₁ (by eq))
d₁|d₂ : d₁ Divides d₂
d₁|d₂ = coprime-divide-mul-r d₁ d₂ n₁ auto-coprime (factor n₂ (by eq))
d₂|d₁ : d₂ Divides d₁
d₂|d₁ = coprime-divide-mul-r d₂ d₁ n₂ auto-coprime (factor n₁ (by eq))
in divides-antisym n₁|n₂ n₂|n₁ , divides-antisym d₁|d₂ d₂|d₁
compareQ : ∀ x y → Comparison LessQ x y
compareQ (ratio n₁ d₁ n₁⊥d₁) (ratio n₂ d₂ n₂⊥d₂) =
case compare (n₁ * d₂) (n₂ * d₁) of λ where
(less lt) → less (lessQ lt)
(equal eq) → equal (uncurry cong-ratio (lem-unique n₁ d₁ n₂ d₂ n₁⊥d₁ n₂⊥d₂ eq))
(greater gt) → greater (lessQ gt)
instance
OrdQ : Ord Rational
OrdQ = defaultOrd compareQ
| {
"alphanum_fraction": 0.5933190316,
"avg_line_length": 36.6629213483,
"ext": "agda",
"hexsha": "ceda205f02ea20312251f7ecabd83979f3fdd033",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lclem/agda-prelude",
"max_forks_repo_path": "src/Numeric/Rational.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "lclem/agda-prelude",
"max_issues_repo_path": "src/Numeric/Rational.agda",
"max_line_length": 107,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lclem/agda-prelude",
"max_stars_repo_path": "src/Numeric/Rational.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2635,
"size": 6526
} |
------------------------------------------------------------------------
-- Semantics of the simplified parsers
------------------------------------------------------------------------
module StructurallyRecursiveDescentParsing.Simplified.Semantics where
open import Algebra
open import Codata.Musical.Notation
open import Data.Bool
open import Data.List
import Data.List.Properties
private
module LM {Tok : Set} = Monoid (Data.List.Properties.++-monoid Tok)
open import Data.Product as Prod
open import Function
open import Data.Empty
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import StructurallyRecursiveDescentParsing.Simplified
open import TotalParserCombinators.Parser using (○; ◌)
open import TotalParserCombinators.Semantics as Semantics
using ([_-_]_>>=_) renaming (_∈_·_ to _∈′_·_)
open Semantics._∈_·_
------------------------------------------------------------------------
-- Semantics
-- The semantics of the parsers. x ∈ p · s means that x can be the
-- result of applying the parser p to the string s. Note that the
-- semantics is defined inductively.
infixl 10 _?>>=_ _!>>=_
infix 4 _∈_·_
data _∈_·_ {Tok} : ∀ {R e} → R → Parser Tok e R → List Tok → Set1 where
return : ∀ {R} {x : R} → x ∈ return x · []
token : ∀ {x} → x ∈ token · [ x ]
∣ˡ : ∀ {R x e₁ e₂ s} {p₁ : Parser Tok e₁ R} {p₂ : Parser Tok e₂ R}
(x∈p₁ : x ∈ p₁ · s) → x ∈ p₁ ∣ p₂ · s
∣ʳ : ∀ {R x e₂ s} e₁ {p₁ : Parser Tok e₁ R} {p₂ : Parser Tok e₂ R}
(x∈p₂ : x ∈ p₂ · s) → x ∈ p₁ ∣ p₂ · s
_?>>=_ : ∀ {R₁ R₂ x y e₂ s₁ s₂}
{p₁ : Parser Tok true R₁} {p₂ : R₁ → Parser Tok e₂ R₂}
(x∈p₁ : x ∈ p₁ · s₁) (y∈p₂x : y ∈ p₂ x · s₂) →
y ∈ p₁ ?>>= p₂ · s₁ ++ s₂
_!>>=_ : ∀ {R₁ R₂ x y} {e₂ : R₁ → Bool} {s₁ s₂}
{p₁ : Parser Tok false R₁}
{p₂ : (x : R₁) → ∞ (Parser Tok (e₂ x) R₂)}
(x∈p₁ : x ∈ p₁ · s₁) (y∈p₂x : y ∈ ♭ (p₂ x) · s₂) →
y ∈ p₁ !>>= p₂ · s₁ ++ s₂
------------------------------------------------------------------------
-- _∈_·_ is correct with respect to _∈′_·_
sound : ∀ {Tok e R} {p : Parser Tok e R} {x s} →
x ∈ p · s → x ∈′ ⟦ p ⟧ · s
sound return = return
sound token = token
sound (∣ˡ x∈p₁) = cast (∣-left (sound x∈p₁))
sound (∣ʳ _ {p₁} x∈p₂) = cast (∣-right (initial p₁) (sound x∈p₂))
sound (_?>>=_ {p₂ = p₂}
x∈p₁ y∈p₂x) = cast ([_-_]_>>=_ ○ ○ {p₂ = λ x → ⟦ p₂ x ⟧}
(sound x∈p₁) (sound y∈p₂x))
sound (x∈p₁ !>>= y∈p₂x) = [ ○ - ◌ ] sound x∈p₁ >>= sound y∈p₂x
complete : ∀ {Tok e R} (p : Parser Tok e R) {x s} →
x ∈′ ⟦ p ⟧ · s → x ∈ p · s
complete (return x) return = return
complete fail ()
complete token token = token
complete (p₁ ∣ p₂) (cast (∣-left x∈p₁)) = ∣ˡ (complete p₁ x∈p₁)
complete (_∣_ {e₁} p₁ p₂) (cast (∣-right ._ x∈p₂)) = ∣ʳ e₁ (complete p₂ x∈p₂)
complete (p₁ ?>>= p₂) (cast (x∈p₁ >>= y∈p₂x)) = complete p₁ x∈p₁ ?>>= complete (p₂ _) y∈p₂x
complete (p₁ !>>= p₂) (x∈p₁ >>= y∈p₂x) = complete p₁ x∈p₁ !>>= complete (♭ (p₂ _)) y∈p₂x
------------------------------------------------------------------------
-- A lemma
-- A simple cast lemma.
cast∈ : ∀ {Tok e R} {p p′ : Parser Tok e R} {x x′ s s′} →
x ≡ x′ → p ≡ p′ → s ≡ s′ → x ∈ p · s → x′ ∈ p′ · s′
cast∈ P.refl P.refl P.refl x∈ = x∈
------------------------------------------------------------------------
-- A variant of the semantics
-- The statement x ⊕ s₂ ∈ p · s means that there is some s₁ such that
-- s ≡ s₁ ++ s₂ and x ∈ p · s₁. This variant of the semantics is
-- perhaps harder to understand, but sometimes easier to work with
-- (and it is proved equivalent to the semantics above).
infix 4 _⊕_∈_·_
data _⊕_∈_·_ {Tok} : ∀ {R e} → R → List Tok →
Parser Tok e R → List Tok → Set1 where
return : ∀ {R} {x : R} {s} → x ⊕ s ∈ return x · s
token : ∀ {x s} → x ⊕ s ∈ token · x ∷ s
∣ˡ : ∀ {R x e₁ e₂ s s₁}
{p₁ : Parser Tok e₁ R} {p₂ : Parser Tok e₂ R}
(x∈p₁ : x ⊕ s₁ ∈ p₁ · s) → x ⊕ s₁ ∈ p₁ ∣ p₂ · s
∣ʳ : ∀ {R x e₂ s s₁} e₁
{p₁ : Parser Tok e₁ R} {p₂ : Parser Tok e₂ R}
(x∈p₂ : x ⊕ s₁ ∈ p₂ · s) → x ⊕ s₁ ∈ p₁ ∣ p₂ · s
_?>>=_ : ∀ {R₁ R₂ x y e₂ s s₁ s₂}
{p₁ : Parser Tok true R₁} {p₂ : R₁ → Parser Tok e₂ R₂}
(x∈p₁ : x ⊕ s₁ ∈ p₁ · s) (y∈p₂x : y ⊕ s₂ ∈ p₂ x · s₁) →
y ⊕ s₂ ∈ p₁ ?>>= p₂ · s
_!>>=_ : ∀ {R₁ R₂ x y} {e₂ : R₁ → Bool} {s s₁ s₂}
{p₁ : Parser Tok false R₁}
{p₂ : (x : R₁) → ∞ (Parser Tok (e₂ x) R₂)}
(x∈p₁ : x ⊕ s₁ ∈ p₁ · s) (y∈p₂x : y ⊕ s₂ ∈ ♭ (p₂ x) · s₁) →
y ⊕ s₂ ∈ p₁ !>>= p₂ · s
-- The definition is sound and complete with respect to the one above.
⊕-sound′ : ∀ {Tok R e x s₂ s} {p : Parser Tok e R} →
x ⊕ s₂ ∈ p · s → ∃ λ s₁ → (s ≡ s₁ ++ s₂) × (x ∈ p · s₁)
⊕-sound′ return = ([] , P.refl , return)
⊕-sound′ {x = x} token = ([ x ] , P.refl , token)
⊕-sound′ (∣ˡ x∈p₁) with ⊕-sound′ x∈p₁
⊕-sound′ (∣ˡ x∈p₁) | (s₁ , P.refl , x∈p₁′) = (s₁ , P.refl , ∣ˡ x∈p₁′)
⊕-sound′ (∣ʳ e₁ x∈p₁) with ⊕-sound′ x∈p₁
⊕-sound′ (∣ʳ e₁ x∈p₁) | (s₁ , P.refl , x∈p₁′) = (s₁ , P.refl , ∣ʳ e₁ x∈p₁′)
⊕-sound′ (x∈p₁ ?>>= y∈p₂x) with ⊕-sound′ x∈p₁ | ⊕-sound′ y∈p₂x
⊕-sound′ (x∈p₁ ?>>= y∈p₂x) | (s₁ , P.refl , x∈p₁′) | (s₂ , P.refl , y∈p₂x′) =
(s₁ ++ s₂ , P.sym (LM.assoc s₁ s₂ _)
, x∈p₁′ ?>>= y∈p₂x′)
⊕-sound′ (x∈p₁ !>>= y∈p₂x) with ⊕-sound′ x∈p₁ | ⊕-sound′ y∈p₂x
⊕-sound′ (x∈p₁ !>>= y∈p₂x) | (s₁ , P.refl , x∈p₁′) | (s₂ , P.refl , y∈p₂x′) =
(s₁ ++ s₂ , P.sym (LM.assoc s₁ s₂ _)
, x∈p₁′ !>>= y∈p₂x′)
⊕-sound : ∀ {Tok R e x s} {p : Parser Tok e R} →
x ⊕ [] ∈ p · s → x ∈ p · s
⊕-sound x∈p with ⊕-sound′ x∈p
⊕-sound x∈p | (s , P.refl , x∈p′) with s ++ [] | proj₂ LM.identity s
⊕-sound x∈p | (s , P.refl , x∈p′) | .s | P.refl = x∈p′
extend : ∀ {Tok R e x s s′ s″} {p : Parser Tok e R} →
x ⊕ s′ ∈ p · s → x ⊕ s′ ++ s″ ∈ p · s ++ s″
extend return = return
extend token = token
extend (∣ˡ x∈p₁) = ∣ˡ (extend x∈p₁)
extend (∣ʳ e₁ x∈p₂) = ∣ʳ e₁ (extend x∈p₂)
extend (x∈p₁ ?>>= y∈p₂x) = extend x∈p₁ ?>>= extend y∈p₂x
extend (x∈p₁ !>>= y∈p₂x) = extend x∈p₁ !>>= extend y∈p₂x
⊕-complete : ∀ {Tok R e x s} {p : Parser Tok e R} →
x ∈ p · s → x ⊕ [] ∈ p · s
⊕-complete return = return
⊕-complete token = token
⊕-complete (∣ˡ x∈p₁) = ∣ˡ (⊕-complete x∈p₁)
⊕-complete (∣ʳ e₁ x∈p₂) = ∣ʳ e₁ (⊕-complete x∈p₂)
⊕-complete (x∈p₁ ?>>= y∈p₂x) = extend (⊕-complete x∈p₁) ?>>=
⊕-complete y∈p₂x
⊕-complete (x∈p₁ !>>= y∈p₂x) = extend (⊕-complete x∈p₁) !>>=
⊕-complete y∈p₂x
⊕-complete′ : ∀ {Tok R e x s₂ s} {p : Parser Tok e R} →
(∃ λ s₁ → s ≡ s₁ ++ s₂ × x ∈ p · s₁) →
x ⊕ s₂ ∈ p · s
⊕-complete′ (s₁ , P.refl , x∈p) = extend (⊕-complete x∈p)
| {
"alphanum_fraction": 0.4440308795,
"avg_line_length": 44.2317073171,
"ext": "agda",
"hexsha": "36b4bf417ee4518bc210c2fae908010ddc2a7981",
"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": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "StructurallyRecursiveDescentParsing/Simplified/Semantics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"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/parser-combinators",
"max_issues_repo_path": "StructurallyRecursiveDescentParsing/Simplified/Semantics.agda",
"max_line_length": 100,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/parser-combinators",
"max_stars_repo_path": "StructurallyRecursiveDescentParsing/Simplified/Semantics.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z",
"num_tokens": 3058,
"size": 7254
} |
-- Interpretation of signature arities
module SOAS.Syntax.Arguments {T : Set} where
open import SOAS.Common
open import SOAS.Context {T}
open import SOAS.Variable
open import SOAS.Families.Core {T}
open import Data.List.Base using ([] ; _∷_ ; List)
open import Data.Product
open import Data.Unit
-- List of arities as a product of terms in extended contexts
Arg : List (Ctx × T) → Familyₛ → Family
Arg [] 𝒳 Γ = ⊤
Arg ((Θ , τ) ∷ []) 𝒳 Γ = 𝒳 τ (Θ ∔ Γ)
Arg ((Θ , τ) ∷ as) 𝒳 Γ = 𝒳 τ (Θ ∔ Γ) × Arg as 𝒳 Γ
-- Functorial action and laws
Arg₁ : {𝒳 𝒴 : Familyₛ} (as : List (Ctx × T))
→ (𝒳 ⇾̣ 𝒴) → Arg as 𝒳 ⇾ Arg as 𝒴
Arg₁ [] f tt = tt
Arg₁ ((Θ , τ) ∷ []) f t = f t
Arg₁ ((Θ , τ) ∷ (Θ′ , τ′) ∷ as) f (t , ts) = (f t) , (Arg₁ ((Θ′ , τ′) ∷ as) f ts)
Arg-id : {𝒳 : Familyₛ}{Γ : Ctx}(as : List (Ctx × T))(ts : Arg as 𝒳 Γ)
→ Arg₁ as id ts ≡ ts
Arg-id [] ts = refl
Arg-id (x ∷ []) t = refl
Arg-id (x ∷ y ∷ ys) (t , ts) = cong (_ ,_) (Arg-id (y ∷ ys) ts)
Arg-∘ : {𝒳 𝒴 𝒵 : Familyₛ}{Γ : Ctx}(as : List (Ctx × T))
→ {f : 𝒳 ⇾̣ 𝒴}{g : 𝒴 ⇾̣ 𝒵}
→ (ts : Arg as 𝒳 Γ)
→ Arg₁ as (g ∘ f) ts
≡ Arg₁ as g (Arg₁ as f ts)
Arg-∘ [] ts = refl
Arg-∘ (x ∷ []) t = refl
Arg-∘ (x ∷ y ∷ ys) (t , ts) = cong (_ ,_) (Arg-∘ (y ∷ ys) ts)
Arg-resp : {𝒳 𝒴 : Familyₛ}{Γ : Ctx}(as : List (Ctx × T))
→ {f g : 𝒳 ⇾̣ 𝒴}
→ ({τ : T}{Δ : Ctx}(x : 𝒳 τ Δ) → f x ≡ g x)
→ (ts : Arg as 𝒳 Γ)
→ Arg₁ as f ts ≡ Arg₁ as g ts
Arg-resp [] p ts = refl
Arg-resp (x ∷ []) p t = p t
Arg-resp (x ∷ y ∷ ys) p (t , ts) = cong₂ _,_ (p t) (Arg-resp (y ∷ ys) p ts)
ArgF : List (Ctx × T) → Functor 𝔽amiliesₛ 𝔽amilies
ArgF as = record
{ F₀ = Arg as
; F₁ = Arg₁ as
; identity = Arg-id as _
; homomorphism = Arg-∘ as _
; F-resp-≈ = λ p → Arg-resp as (λ _ → p) _
}
| {
"alphanum_fraction": 0.5061452514,
"avg_line_length": 30.3389830508,
"ext": "agda",
"hexsha": "3f5c2639bf3c44afb3e9b8dd5d0ca20c07f4d67a",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "SOAS/Syntax/Arguments.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "SOAS/Syntax/Arguments.agda",
"max_line_length": 81,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "SOAS/Syntax/Arguments.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 825,
"size": 1790
} |
------------------------------------------------------------------------
-- Definitions of functions that generate list or vector
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --exact-split #-}
module Math.Combinatorics.VecFunction where
-- agda-stdlib
open import Data.List
open import Data.List.NonEmpty as NE using (List⁺)
open import Data.Nat
import Data.Nat.Properties as ℕₚ
open import Data.Product as Prod using (_×_; _,_)
open import Data.Vec as Vec using (Vec; []; _∷_)
open import Function
open import Relation.Binary.PropositionalEquality hiding ([_])
-- agda-combinatorics
import Math.Combinatorics.ListFunction as ListFun
module _ {a} {A : Set a} where
applyEach : ∀ {n} → (A → A) → Vec A n → Vec (Vec A n) n
applyEach f [] = []
applyEach f (x ∷ xs) = (f x ∷ xs) ∷ Vec.map (x ∷_) (applyEach f xs)
module _ {a} {A : Set a} where
-- combinations
combinations : ∀ k → List A → List (Vec A k)
combinations 0 xs = [ [] ]
combinations (suc k) [] = []
combinations (suc k) (x ∷ xs) =
map (x ∷_) (combinations k xs) ++ combinations (suc k) xs
combinationsWithComplement : ∀ m {n} → Vec A (m + n) →
List (Vec A m × Vec A n)
combinationsWithComplement 0 xs = [ [] , xs ]
combinationsWithComplement m@(suc _) {0} xs =
[ subst (Vec A) (ℕₚ.+-identityʳ m) xs , [] ]
combinationsWithComplement (suc m) {suc n} (x ∷ xs) =
map (Prod.map₁ (x ∷_)) (combinationsWithComplement m xs) ++
map (Prod.map₂ (x ∷_)) (combinationsWithComplement (suc m) xs′)
where xs′ = subst (Vec A) (ℕₚ.+-suc m n) xs
splits₂ : ∀ {n} → Vec A n → Vec (List A × List A) (1 + n)
splits₂ [] = ([] , []) ∷ []
splits₂ xxs@(x ∷ xs) = ([] , Vec.toList xxs) ∷
Vec.map (Prod.map₁ (x ∷_)) (splits₂ xs)
splits : ∀ k → List A → List (Vec (List A) k)
splits 0 xs = []
splits 1 xs = [ xs ∷ [] ]
splits (suc (suc k)) xs = concatMap f (splits (suc k) xs)
where
f : Vec (List A) (suc k) → List (Vec (List A) (suc (suc k)))
f (ys ∷ yss) =
map (λ { (as , bs) → as ∷ bs ∷ yss }) (ListFun.splits₂ ys)
splits⁺₂ : ∀ {n} → Vec A (1 + n) → Vec (List⁺ A × List⁺ A) n
splits⁺₂ (x ∷ []) = []
splits⁺₂ (x ∷ y ∷ xs) =
(x NE.∷ [] , y NE.∷ Vec.toList xs) ∷
Vec.map (Prod.map₁ (x NE.∷⁺_)) (splits⁺₂ (y ∷ xs))
splits⁺ : ∀ k → List⁺ A → List (Vec (List⁺ A) k)
splits⁺ 0 xs = []
splits⁺ 1 xs = [ xs ∷ [] ]
splits⁺ (suc (suc k)) xs = concatMap f (splits⁺ (suc k) xs)
where
f : Vec (List⁺ A) (suc k) → List (Vec (List⁺ A) (suc (suc k)))
f (ys ∷ yss) =
map (λ { (as , bs) → as ∷ bs ∷ yss }) (ListFun.splits⁺₂ ys)
partitions : ∀ k → List A → List (Vec (List A) k)
partitions 0 [] = [ [] ]
partitions 0 (x ∷ xs) = []
partitions (suc k) [] = []
partitions (suc k) (x ∷ xs) =
map ([ x ] ∷_) (partitions k xs) ++
concatMap (Vec.toList ∘ applyEach (x ∷_)) (partitions (suc k) xs)
| {
"alphanum_fraction": 0.508681672,
"avg_line_length": 37.9268292683,
"ext": "agda",
"hexsha": "76f1d109daeb76425c1e07c1eff8aadde2faf1cd",
"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": "9fafa35c940ff7b893a80120f6a1f22b0a3917b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-combinatorics",
"max_forks_repo_path": "Math/Combinatorics/VecFunction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9fafa35c940ff7b893a80120f6a1f22b0a3917b7",
"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-combinatorics",
"max_issues_repo_path": "Math/Combinatorics/VecFunction.agda",
"max_line_length": 72,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "9fafa35c940ff7b893a80120f6a1f22b0a3917b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-combinatorics",
"max_stars_repo_path": "Math/Combinatorics/VecFunction.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-25T07:25:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-25T08:24:15.000Z",
"num_tokens": 1081,
"size": 3110
} |
module ListAppend where
open import Prelude
append : forall {A} -> List A -> List A -> List A
append xs ys = {!!}
appendP1 : forall {x l l'} -> append (cons x l) l' == cons x (append l l')
appendP1 = refl
appendP2 : forall {l} -> append nil l == l
appendP2 = refl
| {
"alphanum_fraction": 0.6305970149,
"avg_line_length": 20.6153846154,
"ext": "agda",
"hexsha": "756563353636edf1a8e2c7af5369684e756736e2",
"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": "baf979ef78b5ec0f4783240b03f9547490bc5d42",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "carlostome/martin",
"max_forks_repo_path": "data/test-files/ListAppend.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "baf979ef78b5ec0f4783240b03f9547490bc5d42",
"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": "carlostome/martin",
"max_issues_repo_path": "data/test-files/ListAppend.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "baf979ef78b5ec0f4783240b03f9547490bc5d42",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "carlostome/martin",
"max_stars_repo_path": "data/test-files/ListAppend.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 85,
"size": 268
} |
{-# OPTIONS --safe --warning=error --without-K #-}
module Lists.Definition where
data List {a : _} (A : Set a) : Set a where
[] : List A
_::_ : (x : A) (xs : List A) → List A
infixr 10 _::_
{-# BUILTIN LIST List #-}
[_] : {a : _} {A : Set a} → (a : A) → List A
[ a ] = a :: []
_++_ : {a : _} {A : Set a} → List A → List A → List A
[] ++ m = m
(x :: l) ++ m = x :: (l ++ m)
| {
"alphanum_fraction": 0.4607329843,
"avg_line_length": 21.2222222222,
"ext": "agda",
"hexsha": "ad98d878552c6f72035eea9d0dc746bf0605d272",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Lists/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": "Lists/Definition.agda",
"max_line_length": 53,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Lists/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": 152,
"size": 382
} |
record ⊤ : Set where
no-eta-equality
constructor tt
data D : ⊤ → Set where
d : (x : ⊤) → D x
test : (g : D tt) → Set
test (d tt) = ⊤
| {
"alphanum_fraction": 0.5281690141,
"avg_line_length": 12.9090909091,
"ext": "agda",
"hexsha": "6116b63ce6a1e8eacda39387c66acae7d8031025",
"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/Issue2894.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/Issue2894.agda",
"max_line_length": 23,
"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/Issue2894.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": 61,
"size": 142
} |
{-# OPTIONS --cubical --safe #-}
module Function.Fiber where
open import Level
open import Data.Sigma.Base
open import Path
open import Cubical.Foundations.Everything using (fiber) public
| {
"alphanum_fraction": 0.7789473684,
"avg_line_length": 21.1111111111,
"ext": "agda",
"hexsha": "48b473264cd60ebd25a33b7530ed1708e3f1347d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Function/Fiber.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Function/Fiber.agda",
"max_line_length": 63,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Function/Fiber.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": 46,
"size": 190
} |
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym)
module AKS.Nat.WellFounded where
open import AKS.Nat.Base using (ℕ; _+_; _∸_; _≤_; _<_; lte)
open ℕ
open import AKS.Nat.Properties using (+-identityʳ; +-suc; ∸-mono-<ˡ; ∸-mono-<ʳ; suc-injective)
data Acc {A : Set} (_≺_ : A → A → Set) (bound : A) : Set where
acc : (∀ {lower : A} → lower ≺ bound → Acc _≺_ lower)
→ Acc _≺_ bound
subrelation
: ∀ {A : Set} {B : Set}
{_≺₁_ : A → A → Set}
{_≺₂_ : B → B → Set}
{f : B → A}
{n : B}
→ (∀ {x y} → x ≺₂ y → f x ≺₁ f y)
→ Acc _≺₁_ (f n)
→ Acc _≺₂_ n
subrelation ≺₂⇒≺₁ (acc down) =
acc λ x≺₂n → subrelation ≺₂⇒≺₁ (down (≺₂⇒≺₁ x≺₂n))
data _≤ⁱ_ : ℕ → ℕ → Set where
≤-same : ∀ {n} → n ≤ⁱ n
≤-step : ∀ {n m} → n ≤ⁱ m → n ≤ⁱ suc m
_<ⁱ_ : ℕ → ℕ → Set
n <ⁱ m = suc n ≤ⁱ m
<⇒<ⁱ : ∀ {n m} → n < m → n <ⁱ m
<⇒<ⁱ {n} {m} (lte zero refl) rewrite +-identityʳ n = ≤-same
<⇒<ⁱ {n} {m} (lte (suc k) refl) = ≤-step (<⇒<ⁱ (lte k (sym (+-suc n k))))
<-well-founded : ∀ {n} → Acc _<_ n
<-well-founded {n} = wf₁ n
where
wf₁ : ∀ t → Acc _<_ t
wf₂ : ∀ t b → b <ⁱ t → Acc _<_ b
wf₁ t = acc λ {b} b<t → wf₂ t b (<⇒<ⁱ b<t)
wf₂ (suc t) b ≤-same = wf₁ t
wf₂ (suc t) b (≤-step b<ⁱt) = wf₂ t b b<ⁱt
record [_,_] (low : ℕ) (high : ℕ) : Set where
inductive
constructor acc
field
downward : ∀ {mid} → low ≤ mid → mid < high → [ low , mid ]
upward : ∀ {mid} → low < mid → mid ≤ high → [ mid , high ]
binary-search : ∀ {n m} → [ n , m ]
binary-search {n} {m} = loop n m <-well-founded
where
loop : ∀ low high → Acc _<_ (high ∸ low) → [ low , high ]
loop low high (acc next) = acc
(λ {mid} low≤mid mid<high → loop low mid (next {mid ∸ low} (∸-mono-<ˡ low≤mid mid<high)))
(λ {mid} low<mid mid≤high → loop mid high (next {high ∸ mid} (∸-mono-<ʳ mid≤high low<mid)))
open import AKS.Unsafe using (trustMe)
record Interval : Set where
constructor [_,_∣_]
field
inf : ℕ
sup : ℕ
inf≤sup : inf ≤ sup
open Interval
width : Interval → ℕ
width i = sup i ∸ inf i
data _⊂_ (i₁ : Interval) (i₂ : Interval) : Set where
downward : inf i₂ ≤ inf i₁ → sup i₁ < sup i₂ → i₁ ⊂ i₂
upward : inf i₂ < inf i₁ → sup i₁ ≤ sup i₂ → i₁ ⊂ i₂
∸-monoˡ-< : ∀ {l₁ h₁ l₂ h₂} → l₁ ≤ h₁ → l₂ ≤ h₂ → l₂ ≤ l₁ → h₁ < h₂ → h₁ ∸ l₁ < h₂ ∸ l₂
∸-monoˡ-< {l₁} {h₁} {l₂} {h₂} l₁≤h₁ l₂≤h₂ l₂≤l₁ h₁<h₂ = lte ((h₂ ∸ l₂) ∸ suc (h₁ ∸ l₁)) trustMe -- TODO: EVIL
∸-monoʳ-< : ∀ {l₁ h₁ l₂ h₂} → l₁ ≤ h₁ → l₂ ≤ h₂ → l₂ < l₁ → h₁ ≤ h₂ → h₁ ∸ l₁ < h₂ ∸ l₂
∸-monoʳ-< {l₁} {h₁} {l₂} {h₂} l₁≤h₁ l₂≤h₂ l₂<l₁ h₁≤h₂ = lte ((h₂ ∸ l₂) ∸ suc (h₁ ∸ l₁)) trustMe
⊂⇒< : ∀ {i₁ i₂} → i₁ ⊂ i₂ → width i₁ < width i₂
⊂⇒< {[ inf-i₁ , sup-i₁ ∣ inf-i₁≤sup-i₁ ]} {[ inf-i₂ , sup-i₂ ∣ inf-i₂≤sup-i₂ ]} (downward inf-i₂≤inf-i₁ sup-i₁<sup-i₂)
= ∸-monoˡ-< inf-i₁≤sup-i₁ inf-i₂≤sup-i₂ inf-i₂≤inf-i₁ sup-i₁<sup-i₂
⊂⇒< {[ inf-i₁ , sup-i₁ ∣ inf-i₁≤sup-i₁ ]} {[ inf-i₂ , sup-i₂ ∣ inf-i₂≤sup-i₂ ]} (upward inf-i₂<inf-i₁ sup-i₁≤sup-i₂)
= ∸-monoʳ-< inf-i₁≤sup-i₁ inf-i₂≤sup-i₂ inf-i₂<inf-i₁ sup-i₁≤sup-i₂
⊂-well-founded : ∀ {i} → Acc _⊂_ i
⊂-well-founded = subrelation ⊂⇒< <-well-founded
| {
"alphanum_fraction": 0.5339961514,
"avg_line_length": 33.8913043478,
"ext": "agda",
"hexsha": "6ad3f1bb806fe5fb883faaa4fe891f1fbbbb89aa",
"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": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mckeankylej/thesis",
"max_forks_repo_path": "proofs/AKS/Nat/WellFounded.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"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": "mckeankylej/thesis",
"max_issues_repo_path": "proofs/AKS/Nat/WellFounded.agda",
"max_line_length": 118,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mckeankylej/thesis",
"max_stars_repo_path": "proofs/AKS/Nat/WellFounded.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z",
"num_tokens": 1536,
"size": 3118
} |
{-# OPTIONS --without-K #-}
module NTypes where
open import Equivalence
open import FunExt
open import GroupoidStructure
open import NTypes.Contractible
open import PathOperations
open import Transport
open import Types
isProp : ∀ {a} → Set a → Set _
isProp A = (x y : A) → x ≡ y
isSet : ∀ {a} → Set a → Set _
isSet A = (x y : A) (p q : x ≡ y) → p ≡ q
set→id-prop : ∀ {a} {A : Set a} →
isSet A → {x y : A} → isProp (x ≡ y)
set→id-prop A-set = A-set _ _
id-prop→set : ∀ {a} {A : Set a} →
({x y : A} → isProp (x ≡ y)) → isSet A
id-prop→set f _ _ = f
prop-eq : ∀ {a b} {A : Set a} {B : Set b} → A ≃ B → isProp A → isProp B
prop-eq (f , (g , α) , (h , β)) A-prop x y =
tr id
( ap (λ z → z ≡ f (g y)) (α x)
· ap (λ z → x ≡ z) (α y)
)
(ap f (A-prop (g x) (g y)))
-- Levels.
is-[_-2]-type : ℕ → ∀ {a} → Set a → Set a
is-[ n -2]-type = ind (λ _ → Set _ → Set _)
(λ _ r A → (x y : A) → r (x ≡ y))
isContr
n
-- isProp and is-(-1)-type.
prop→-1-type : ∀ {a} {A : Set a} →
isProp A → is-[ 1 -2]-type A
prop→-1-type {A = A} A-prop x y
= A-prop x y
, path
where
split-path : {x y : A} (p : x ≡ y) →
A-prop x y ≡ p · A-prop y y
split-path = J
(λ x y p → A-prop x y ≡ p · A-prop y y)
(λ _ → refl) _ _
path : {x y : A} (p : x ≡ y) → A-prop x y ≡ p
path = J
(λ x y p → A-prop x y ≡ p)
(λ x → split-path (A-prop x x ⁻¹) · p⁻¹·p (A-prop x x))
_ _
-1-type→prop : ∀ {a} {A : Set a} →
is-[ 1 -2]-type A → isProp A
-1-type→prop A-1 x y = π₁ (A-1 x y)
-- isSet and is-0-type.
set→0-type : ∀ {a} {A : Set a} →
isSet A → is-[ 2 -2]-type A
set→0-type A-set x y = prop→-1-type (A-set x y)
0-type→set : ∀ {a} {A : Set a} →
is-[ 2 -2]-type A → isSet A
0-type→set A0 x y = -1-type→prop (A0 x y)
-- Cumulativity.
n-type-suc : ∀ n {a} {A : Set a} →
is-[ n -2]-type A → is-[ suc n -2]-type A
n-type-suc n = ind
(λ n → ∀ {A} → is-[ n -2]-type A → is-[ suc n -2]-type A)
(λ _ r h x y → r (h x y))
(λ h → prop→-1-type λ x y → π₂ h x ⁻¹ · π₂ h y)
n
-- From lectures.
prop→set : ∀ {a} {A : Set a} →
isProp A → isSet A
prop→set A-prop x y p q = lem p · lem q ⁻¹
where
g : _
g = A-prop x
lem : (p : x ≡ y) → p ≡ g x ⁻¹ · g y
lem p
= id·p p ⁻¹
· ap (λ z → z · p)
(p⁻¹·p (g x)) ⁻¹
· p·q·r (g x ⁻¹) (g x) p ⁻¹
· ap (λ z → g x ⁻¹ · z)
( tr-post x p (g x) ⁻¹
· apd g p
)
isProp-is-prop : ∀ {a} {A : Set a} →
isProp (isProp A)
isProp-is-prop f g =
funext λ x →
funext λ y →
prop→set f _ _ (f x y) (g x y)
isSet-is-prop : ∀ {a} {A : Set a} →
isProp (isSet A)
isSet-is-prop f g =
funext λ x →
funext λ y →
funext λ p →
funext λ q →
prop→set (f x y) _ _ (f x y p q) (g x y p q)
| {
"alphanum_fraction": 0.4830258303,
"avg_line_length": 23.3620689655,
"ext": "agda",
"hexsha": "1842fc52187acd383680a1444c5e1e7b97a0e9f3",
"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": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/NTypes.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"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": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/NTypes.agda",
"max_line_length": 71,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/NTypes.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1243,
"size": 2710
} |
module InstanceMeta where
data Bool : Set where
true false : Bool
data Maybe (A : Set) : Set where
Nothing : Maybe A
Just : A → Maybe A
record Eq (A : Set) : Set where
constructor eq
field
_==_ : A → A → Bool
open Eq {{...}} public
instance
eq-Bool : Eq Bool
eq-Bool = eq aux where
aux : Bool → Bool → Bool
aux true true = true
aux false false = true
aux _ _ = false
eq-Maybe : {A : Set} {{_ : Eq A}} → Eq (Maybe A)
eq-Maybe {A} = eq aux where
aux : Maybe A → Maybe A → Bool
aux Nothing Nothing = true
aux (Just y) (Just z) = (y == z)
aux _ _ = false
test : Bool
test = {!!} == {!!}
-- This should not loop, only produce unsolved metas
| {
"alphanum_fraction": 0.5814285714,
"avg_line_length": 19.4444444444,
"ext": "agda",
"hexsha": "b71396b035fd8146a89bb09f39f98d1557e634c2",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/InstanceMeta.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/InstanceMeta.agda",
"max_line_length": 52,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/InstanceMeta.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": 228,
"size": 700
} |
------------------------------------------------------------------------------
-- The alternating bit protocol (ABP) is correct
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- This module proves the correctness of the ABP following the
-- formalization in Dybjer and Sander (1989).
-- N.B This module does not contain combined proofs, but it imports
-- modules which contain combined proofs.
module FOTC.Program.ABP.CorrectnessProofATP where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.Bool
open import FOTC.Data.Bool.PropertiesATP using ( not-Bool )
open import FOTC.Data.Stream.Type
open import FOTC.Data.Stream.Equality.PropertiesATP
open import FOTC.Program.ABP.ABP
open import FOTC.Program.ABP.Lemma1ATP
open import FOTC.Program.ABP.Lemma2ATP
open import FOTC.Program.ABP.Fair.Type
open import FOTC.Program.ABP.Terms
open import FOTC.Relation.Binary.Bisimilarity.Type
------------------------------------------------------------------------------
-- Main theorem.
abpCorrect : ∀ {b os₁ os₂ is} → Bit b → Fair os₁ → Fair os₂ → Stream is →
is ≈ abpTransfer b os₁ os₂ is
abpCorrect {b} {os₁} {os₂} {is} Bb Fos₁ Fos₂ Sis = ≈-coind B h₁ h₂
where
postulate h₁ : ∀ {ks ls} → B ks ls →
∃[ k' ] ∃[ ks' ] ∃[ ls' ]
ks ≡ k' ∷ ks' ∧ ls ≡ k' ∷ ls' ∧ B ks' ls'
{-# ATP prove h₁ lemma₁ lemma₂ not-Bool #-}
postulate h₂ : B is (abpTransfer b os₁ os₂ is)
{-# ATP prove h₂ #-}
------------------------------------------------------------------------------
-- abpTransfer produces a Stream.
postulate
abpTransfer-Stream : ∀ {b os₁ os₂ is} →
Bit b →
Fair os₁ →
Fair os₂ →
Stream is →
Stream (abpTransfer b os₁ os₂ is)
{-# ATP prove abpTransfer-Stream ≈→Stream₂ abpCorrect #-}
------------------------------------------------------------------------------
-- References
--
-- Dybjer, Peter and Sander, Herbert P. (1989). A Functional
-- Programming Approach to the Specification and Verification of
-- Concurrent Systems. Formal Aspects of Computing 1, pp. 303–319.
| {
"alphanum_fraction": 0.5323193916,
"avg_line_length": 38.1774193548,
"ext": "agda",
"hexsha": "26eeff152dcad74d3bb5e9109ee0161f62914cd7",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/ABP/CorrectnessProofATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/ABP/CorrectnessProofATP.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/ABP/CorrectnessProofATP.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": 583,
"size": 2367
} |
module Sessions.Semantics.Expr where
open import Prelude
open import Data.Fin
open import Relation.Unary.PredicateTransformer hiding (_⊔_)
open import Relation.Ternary.Separation.Morphisms
open import Relation.Ternary.Separation.Monad
open import Relation.Ternary.Separation.Monad.Reader
open import Sessions.Syntax.Types
open import Sessions.Syntax.Values
open import Sessions.Syntax.Expr
open import Sessions.Semantics.Commands
open import Sessions.Semantics.Runtime
open import Relation.Ternary.Separation.Construct.List Type
open import Relation.Ternary.Separation.Monad.Free Cmd δ
hiding (⟪_⟫)
open import Relation.Ternary.Separation.Monad.Error
open ErrorTrans Free {{monad = free-monad}} public
open ReaderTransformer id-morph Val (ErrorT Free) {{error-monad}}
renaming (Reader to M)
public
open Monads using (Monad; str; _&_)
open Monad reader-monad
mutual
eval⊸ : ∀ {Γ} → ℕ → Exp (a ⊸ b) Γ → ∀[ Val a ⇒ⱼ M Γ [] (Val b) ]
eval⊸ n e v = do
(clos e env) ×⟨ σ₂ ⟩ v ← ►eval n e & v
empty ← append (cons (v ×⟨ ⊎-comm σ₂ ⟩ env))
►eval n e
►eval : ℕ → Exp a Γ → ε[ M Γ [] (Val a) ]
app (►eval zero e) _ _ = partial (pure (inj₁ err))
►eval (suc n) e = eval n e
⟪_⟫ : ∀ {Γ Φ} → (c : Cmd Φ) → M Γ Γ (δ c) Φ
app (⟪_⟫ c) (inj E) σ =
partial (impure (c ×⟨ σ ⟩
wand λ r σ' → pure (inj₂ (r ×⟨ ⊎-comm σ' ⟩ E))))
eval : ℕ → Exp a Γ → ε[ M Γ [] (Val a) ]
eval n unit = do
return tt
eval n (var refl) = do
(v :⟨ σ ⟩: nil) ← ask
case ⊎-id⁻ʳ σ of λ where
refl → return v
eval n (lam a e) = do
env ← ask
return (clos e env)
eval n (ap (f ×⟨ Γ≺ ⟩ e)) = do
v ← frame (⊎-comm Γ≺) (►eval n e)
eval⊸ n f v
eval n (pairs (e₁ ×⟨ Γ≺ ⟩ e₂)) = do
v₁ ← frame Γ≺ (►eval n e₁)
v₂⋆v₂ ← ►eval n e₂ & v₁
return (pairs (✴-swap v₂⋆v₂))
eval n (letunit (e₁ ×⟨ Γ≺ ⟩ e₂)) = do
tt ← frame Γ≺ (►eval n e₁)
►eval n e₂
eval n (letpair (e₁ ×⟨ Γ≺ ⟩ e₂)) = do
pairs (v₁ ×⟨ σ ⟩ v₂) ← frame Γ≺ (►eval n e₁)
empty ← prepend (cons (v₁ ×⟨ σ ⟩ singleton v₂))
►eval n e₂
eval n (send (e₁ ×⟨ Γ≺ ⟩ e₂)) = do
v₁ ← frame Γ≺ (►eval n e₁)
cref φ ×⟨ σ ⟩ v₁ ← ►eval n e₂ & v₁
φ' ← ⟪ send (φ ×⟨ σ ⟩ v₁) ⟫
return (cref φ')
eval n (recv e) = do
cref φ ← ►eval n e
v ×⟨ σ ⟩ φ' ← ⟪ receive φ ⟫
return (pairs (cref φ' ×⟨ ⊎-comm σ ⟩ v))
eval n (mkchan α) = do
φₗ ×⟨ σ ⟩ φᵣ ← ⟪ mkchan α ⟫
return (pairs (cref φₗ ×⟨ σ ⟩ cref φᵣ))
eval n (fork e) = do
clos body env ← ►eval n e
empty ←
⟪ fork (app (runReader (cons (tt ×⟨ ⊎-idˡ ⟩ env))) (►eval n body) ⊎-idʳ) ⟫
return tt
eval n (terminate e) = do
cref φ ← ►eval n e
empty ← ⟪ close φ ⟫
return tt
| {
"alphanum_fraction": 0.5737344094,
"avg_line_length": 26.7254901961,
"ext": "agda",
"hexsha": "10c98468dd70135bd5ff3ec0f98284cf4d934782",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z",
"max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/linear.agda",
"max_forks_repo_path": "src/Sessions/Semantics/Expr.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "laMudri/linear.agda",
"max_issues_repo_path": "src/Sessions/Semantics/Expr.agda",
"max_line_length": 80,
"max_stars_count": 34,
"max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/linear.agda",
"max_stars_repo_path": "src/Sessions/Semantics/Expr.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z",
"num_tokens": 1105,
"size": 2726
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Instance.Properties.Setoids where
open import Level
open import Relation.Binary using (Setoid; module Setoid; Preorder)
open import Relation.Binary.PropositionalEquality as ≡ using (_≡_)
import Relation.Binary.Reasoning.Setoid as RS
open import Function.Equality using (Π)
open import Relation.Binary.Indexed.Heterogeneous using (_=[_]⇒_)
open import Data.Product using (Σ; proj₁; proj₂; _,_; Σ-syntax; _×_)
import Relation.Binary.Construct.Symmetrize as Symmetrize
open Symmetrize hiding (setoid; trans; sym)
open import Data.Unit using (⊤; tt)
open import Categories.Category using (Category; _[_,_])
open import Categories.Functor
open import Categories.Category.Instance.Setoids
open import Categories.Diagram.Cocone
open import Categories.Category.Construction.Cocones hiding (Cocone)
open import Categories.Diagram.Cone
open import Categories.Category.Complete
open import Categories.Category.Cocomplete
Setoids-Cocomplete : (o ℓ e c ℓ′ : Level) → Cocomplete o ℓ e (Setoids (o ⊔ c) (o ⊔ ℓ ⊔ c ⊔ ℓ′))
Setoids-Cocomplete o ℓ e c ℓ′ {J} F = record { initial = record
{ ⊥ = record
{ N = ⇛-Setoid
; coapex = record
{ ψ = λ j → record
{ _⟨$⟩_ = j ,_
; cong = λ i≈k → disorient (slish (J.id , identity i≈k))
}
; commute = λ {X} X⇒Y x≈y → disorient (slash (X⇒Y , cong (F₁ X⇒Y) (Setoid.sym (F₀ X) x≈y)))
}
}
; ! = λ {A} → record
{ arr = record
{ _⟨$⟩_ = to-coapex A
; cong = λ eq → minimal ⇛-preorder (Cocone.N A) (to-coapex A) (coapex-cong A) eq
}
; commute = λ {X} x≈y → cong (Coapex.ψ (Cocone.coapex A) X) x≈y
}
; !-unique = λ {A} cocone⇒ x⇛y → Setoid.trans (Cocone.N A)
(Setoid.sym (Cocone.N A) (Cocone⇒.commute cocone⇒ (refl (F₀ _))))
(cong (Cocone⇒.arr cocone⇒) x⇛y)
} }
where
open Setoid
open Π
open Functor F
D = Cocones F
module J = Category J
C = Setoids _ _
setoid : J.Obj → Category.Obj C
setoid j = F₀ j
module S (j : J.Obj) = Setoid (setoid j)
open S using () renaming (_≈_ to _[_≈_])
vertex-carrier = Σ[ j ∈ J.Obj ] Carrier (setoid j)
_⇛_ : (x y : vertex-carrier) → Set _
(X , x) ⇛ (Y , y) = Σ[ f ∈ J [ X , Y ] ] ( Y [ (F₁ f ⟨$⟩ x) ≈ y ])
⇛-preorder : Preorder _ _ _
⇛-preorder = record
{ Carrier = vertex-carrier
; _≈_ = _≡_
; _∼_ = _⇛_
; isPreorder = record
{ isEquivalence = ≡.isEquivalence
; reflexive = λ { {i , Fi} {.i , .Fi} ≡.refl → J.id , Functor.identity F (refl (F₀ i))}
; trans = λ { {i , Fi} {j , Fj} {k , Fk} i≈j j≈k → proj₁ j≈k J.∘ proj₁ i≈j ,
let S = F₀ k in
let open RS S in begin
F₁ (proj₁ j≈k J.∘ proj₁ i≈j) ⟨$⟩ Fi ≈⟨ homomorphism (refl (F₀ i)) ⟩
F₁ (proj₁ j≈k) ⟨$⟩ (F₁ (proj₁ i≈j) ⟨$⟩ Fi) ≈⟨ cong (F₁ (proj₁ j≈k)) (proj₂ i≈j) ⟩
F₁ (proj₁ j≈k) ⟨$⟩ Fj ≈⟨ proj₂ j≈k ⟩
Fk ∎}
}
}
⇛-Setoid : Setoid (o ⊔ c) (o ⊔ ℓ ⊔ c ⊔ ℓ′)
⇛-Setoid = Symmetrize.setoid ⇛-preorder
to-coapex : (A : Cocone F) → vertex-carrier → Carrier (Cocone.N A)
to-coapex A (j , Fj) = Cocone.ψ A j ⟨$⟩ Fj
coapex-cong : (A : Cocone F) → _⇛_ =[ to-coapex A ]⇒ (_≈_ (Cocone.N A))
coapex-cong A {X , x} {Y , y} (f , fx≈y) = Setoid.trans A.N
(Setoid.sym A.N (A.commute f (refl (F₀ X))))
(cong (A.ψ Y) fx≈y)
where module A = Cocone A
Setoids-Complete : (o ℓ e c ℓ′ : Level) → Complete o ℓ e (Setoids (ℓ′ ⊔ ℓ ⊔ o) (o ⊔ ℓ′))
Setoids-Complete o ℓ e c ℓ′ {J} F = record { terminal = record
{ ⊤ = record
{ N = record
{ Carrier = Σ
((j : Category.Obj J) → Setoid.Carrier (F₀ j))
(λ P → ∀ {X Y} (f : J [ X , Y ]) → Setoid._≈_ (F₀ Y) (F₁ f Π.⟨$⟩ P X) (P Y))
; _≈_ = λ f g → ∀ (j : Category.Obj J) → Setoid._≈_ (F₀ j) (proj₁ f j) (proj₁ g j)
; isEquivalence = record
{ refl = λ j → Setoid.refl (F₀ j)
; sym = λ a≈b j → Setoid.sym (F₀ j) (a≈b j)
; trans = λ a≈b b≈c j → Setoid.trans (F₀ j) (a≈b j) (b≈c j)
}
}
; apex = record
{ ψ = λ j → record
{ _⟨$⟩_ = λ x → proj₁ x j
; cong = λ x → x j
}
; commute = λ {X} {Y} X⇒Y {x} {y} f≈g → Setoid.trans (F₀ Y) (proj₂ x X⇒Y) (f≈g Y)
}
}
; ! = λ {A} → record
{ arr = record
{ _⟨$⟩_ = λ x → (λ j → ψ A j Π.⟨$⟩ x) , λ {X} {Y} f → commute A f (Setoid.refl (N A))
; cong = λ a≈b j → Π.cong (ψ A j) a≈b
}
; commute = λ {j} x≈y → Π.cong (ψ A j) x≈y
}
; !-unique = λ {A} f x≈y j → Setoid.sym (F₀ j) (Cone⇒.commute f (Setoid.sym (N A) x≈y))
} }
where
open Functor F
S : Category (suc (c ⊔ ℓ)) (c ⊔ ℓ) (c ⊔ ℓ)
S = Setoids c ℓ
open Category S
open Cone
| {
"alphanum_fraction": 0.5372916667,
"avg_line_length": 37.7952755906,
"ext": "agda",
"hexsha": "5f0ee523914f067745f62db85fcacb432565abf7",
"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": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Categories/Category/Instance/Properties/Setoids.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"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": "Taneb/agda-categories",
"max_issues_repo_path": "Categories/Category/Instance/Properties/Setoids.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Categories/Category/Instance/Properties/Setoids.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1960,
"size": 4800
} |
module 040-monoid where
-- We need semigroups.
open import 030-semigroup
-- The next useful structure is a monoid, which is a semigroup with
-- (left and right) identity element.
record Monoid
{M : Set}
(_==_ : M -> M -> Set)
(_*_ : M -> M -> M)
(id : M)
: Set1 where
field
semigroup : SemiGroup _==_ _*_
r*id==r : ∀ {r} -> (r * id) == r
id*r==r : ∀ {r} -> (id * r) == r
open SemiGroup semigroup public
-- Should we define powers? We cannot do this yet: we need natural
-- numbers first, which we do not have yet.
-- Let us prove some facts.
-- Identity can occur on either side of the equality.
r==r*id : ∀ {r} -> r == (r * id)
r==r*id = symm r*id==r
r==id*r : ∀ {r} -> r == (id * r)
r==id*r = symm id*r==r
-- The identity element is unique (both left and right).
idleftunique : ∀ {r} -> (∀ {s} -> (r * s) == s) -> (r == id)
idleftunique r*s==s = trans r==r*id r*s==s
idrightunique : ∀ {r} -> (∀ {s} -> (s * r) == s) -> (r == id)
idrightunique s*r==s = trans r==id*r s*r==s
| {
"alphanum_fraction": 0.5500963391,
"avg_line_length": 25.3170731707,
"ext": "agda",
"hexsha": "3bb25b3ff0e2aa3e6794261ff400cd916318b5c2",
"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": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mcmtroffaes/agda-proofs",
"max_forks_repo_path": "040-monoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"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": "mcmtroffaes/agda-proofs",
"max_issues_repo_path": "040-monoid.agda",
"max_line_length": 68,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "76fe404b25210258810641cc6807feecf0ff8d6c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mcmtroffaes/agda-proofs",
"max_stars_repo_path": "040-monoid.agda",
"max_stars_repo_stars_event_max_datetime": "2016-08-17T16:15:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-09T22:51:55.000Z",
"num_tokens": 378,
"size": 1038
} |
open import Agda.Builtin.Coinduction
open import Agda.Builtin.Equality
record Reveal_·_is_ {A : Set} {B : A → Set}
(f : (x : A) → B x) (x : A) (y : B x) :
Set where
constructor [_]
field eq : f x ≡ y
inspect : {A : Set} {B : A → Set}
(f : (x : A) → B x) (x : A) → Reveal f · x is f x
inspect f x = [ refl ]
infixr 5 _∷_
data Stream (A : Set) : Set where
_∷_ : (x : A) (xs : ∞ (Stream A)) → Stream A
infix 4 _≈_
data _≈_ {A} : Stream A → Stream A → Set where
_∷_ : ∀ {x y xs ys}
(x≡ : x ≡ y) (xs≈ : ∞ (♭ xs ≈ ♭ ys)) → x ∷ xs ≈ y ∷ ys
map : ∀ {A B} → (A → B) → Stream A → Stream B
map f (x ∷ xs) = f x ∷ ♯ map f (♭ xs)
map₂ : ∀ {A B} → (A → B) → Stream A → Stream B
map₂ f (x ∷ xs) with ♭ xs
map₂ f (x ∷ xs) | y ∷ ys = f x ∷ ♯ (f y ∷ ♯ map₂ f (♭ ys))
map≈map₂ : ∀ {A B} →
(f : A → B) → (xs : Stream A) → map f xs ≈ map₂ f xs
map≈map₂ {A} f (x ∷ xs) with ♭ xs | inspect ♭ xs
map≈map₂ {A} f (x ∷ xs) | y ∷ ys | [ eq ] = refl ∷ ♯ helper eq
where
map-f-y∷ys = _
helper : ∀ {xs} → xs ≡ y ∷ ys → map f xs ≈ map-f-y∷ys
helper refl = refl ∷ ♯ map≈map₂ f (♭ ys)
| {
"alphanum_fraction": 0.465095986,
"avg_line_length": 27.9512195122,
"ext": "agda",
"hexsha": "a96aa047c638690c0f49583c4b14f172aa26f68e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/Issue2322.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/Issue2322.agda",
"max_line_length": 63,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/Issue2322.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": 524,
"size": 1146
} |
import Lvl
open import Structure.Setoid
open import Type
module Automaton.Deterministic where
open import Data.List renaming (∅ to ε ; _⊰_ to _·_)
open import Data.List.Setoid
open import Data.List.Functions using (postpend ; _++_)
open import Data.List.Proofs
open import Functional
open import Logic
open import Sets.ExtensionalPredicateSet using (PredSet ; intro ; _∈_ ; _∋_ ; ⊶ ; [∋]-binaryRelator)
import Structure.Function.Names as Names
open import Structure.Operator
open import Structure.Relator.Properties
-- According to http://www.cse.chalmers.se/edu/course/TMV027/lec5.pdf
private variable ℓₚ ℓₛ ℓₑ₁ ℓₐ ℓₑ₂ : Lvl.Level
module _
{ℓₚ}
(State : Type{ℓₛ}) ⦃ equiv-state : Equiv{ℓₑ₁}(State) ⦄
(Alphabet : Type{ℓₐ}) ⦃ equiv-alphabet : Equiv{ℓₑ₂}(Alphabet) ⦄
where
-- Deterministic Automata
-- `State` (Q) is the set of states.
-- `Alphabet` (Σ) is the set of symbols/the alphabet.
-- `transition` (δ) is the transition function.
-- `start` (q₀) is the start state.
-- `Final` (F) is the subset of State which are the final/accepting states.
record Deterministic : Type{ℓₛ Lvl.⊔ ℓₑ₁ Lvl.⊔ ℓₑ₂ Lvl.⊔ ℓₐ Lvl.⊔ Lvl.𝐒(ℓₚ)} where
constructor deterministic
field
transition : State → Alphabet → State
⦃ transition-binaryOperator ⦄ : BinaryOperator(transition)
start : State
Final : PredSet{ℓₚ}(State)
Word = List(Alphabet)
-- Chained transition using a word (list of characters).
wordTransition : State → Word → State
wordTransition initialState ε = initialState
wordTransition initialState (a · l) = wordTransition (transition initialState a) l
module LetterNotation where
Q = State
Σ = Alphabet
δ = transition
δ̂ = wordTransition
q₀ = start
F = Final
-- A word is accepted by the automaton when it can transition from the start state to a final state.
AcceptsWord : Word → Stmt
AcceptsWord = (_∈ Final) ∘ wordTransition start
transitionedAutomaton : Alphabet → Deterministic
transition (transitionedAutomaton _) = transition
start (transitionedAutomaton c) = transition start c
Final (transitionedAutomaton _) = Final
wordTransitionedAutomaton : Word → Deterministic
transition (wordTransitionedAutomaton _) = transition
start (wordTransitionedAutomaton w) = wordTransition start w
Final (wordTransitionedAutomaton _) = Final
module _
{State : Type{ℓₛ}} ⦃ equiv-state : Equiv{ℓₑ₁}(State) ⦄
{Alphabet : Type{ℓₐ}} ⦃ equiv-alphabet : Equiv{ℓₑ₂}(Alphabet) ⦄
{d : Deterministic{ℓₚ = ℓₚ}(State)(Alphabet)}
where
open import Data.List.Equiv
open import Structure.Operator.Properties
open import Syntax.Transitivity
open Deterministic(d)
instance
wordTransition-binaryOperator : BinaryOperator(wordTransition)
wordTransition-binaryOperator = intro p where
p : Names.Congruence₂(wordTransition)
p {x₂ = ε} {y₂ = ε} xy1 xy2 = xy1
p {x₂ = c₁ · w₁} {y₂ = c₂ · w₂} xy1 xy2 = p{x₂ = w₁}{y₂ = w₂} (congruence₂(transition) xy1 ([⊰]-generalized-cancellationᵣ xy2)) ([⊰]-generalized-cancellationₗ xy2)
wordTransition-postpend : ∀{s}{w}{a} → ((wordTransition s (postpend a w)) ≡ transition (wordTransition s w) a)
wordTransition-postpend {s}{ε} {a} = reflexivity(_≡_) {x = transition s a}
wordTransition-postpend {s}{x · w}{a} = wordTransition-postpend {transition s x}{w}{a}
-- Note: ((swap ∘ wordTransition) d (w₁ ++ w₂) ⊜ (swap ∘ wordTransition) d w₂ ∘ (swap ∘ wordTransition) d w₁)
wordTransition-[++] : ∀{s}{w₁ w₂} → (wordTransition s (w₁ ++ w₂) ≡ (wordTransition (wordTransition s w₁) w₂))
wordTransition-[++] {s = s} {w₁ = w₁} {w₂ = ε} =
wordTransition s (w₁ ++ ε) 🝖[ _≡_ ]-[ congruence₂ᵣ(wordTransition)(s) (identityᵣ(_++_)(ε) {w₁}) ]
wordTransition s w₁ 🝖[ _≡_ ]-[]
wordTransition (wordTransition s w₁) ε 🝖-end
wordTransition-[++] {s = s} {w₁ = w₁} {w₂ = c₂ · w₂} =
wordTransition s (w₁ ++ (c₂ · w₂)) 🝖[ _≡_ ]-[ congruence₂ᵣ(wordTransition)(s) ([++]-middle-prepend-postpend{l₁ = w₁}) ]-sym
wordTransition s (postpend c₂ w₁ ++ w₂) 🝖[ _≡_ ]-[ wordTransition-[++] {s = s}{w₁ = postpend c₂ w₁}{w₂ = w₂} ]
wordTransition (wordTransition s (postpend c₂ w₁)) w₂ 🝖[ _≡_ ]-[ congruence₂ₗ(wordTransition)(w₂) (wordTransition-postpend{s = s}{w = w₁}) ]
wordTransition (transition (wordTransition s w₁) c₂) w₂ 🝖-end
| {
"alphanum_fraction": 0.6589147287,
"avg_line_length": 43,
"ext": "agda",
"hexsha": "334a7c8be4aecf9d3e0598abd872370f7f91ca50",
"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": "Automaton/Deterministic.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": "Automaton/Deterministic.agda",
"max_line_length": 169,
"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": "Automaton/Deterministic.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": 1492,
"size": 4515
} |
module PiFrac.AuxLemmas where
open import Data.Empty
open import Data.Unit hiding (_≟_)
open import Data.Sum
open import Data.Product
open import Relation.Binary.Core
open import Relation.Binary
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Function using (_∘_)
open import PiFrac.Syntax
open import PiFrac.Opsem
Lemma₁ : ∀ {A B C D v v' κ κ'} {c : A ↔ B} {c' : C ↔ D}
→ ⟨ c ∣ v ∣ κ ⟩ ↦ [ c' ∣ v' ∣ κ' ]
→ (A ≡ C × B ≡ D)
Lemma₁ ↦₁ = refl , refl
Lemma₁ ↦₂ = refl , refl
Lemma₁ ↦η = refl , refl
Lemma₁ ↦ε₁ = refl , refl
Lemma₂ : ∀ {A B v v' κ κ'} {c c' : A ↔ B}
→ ⟨ c ∣ v ∣ κ ⟩ ↦ [ c' ∣ v' ∣ κ' ]
→ c ≡ c' × κ ≡ κ'
Lemma₂ ↦₁ = refl , refl
Lemma₂ ↦₂ = refl , refl
Lemma₂ ↦η = refl , refl
Lemma₂ ↦ε₁ = refl , refl
Lemma₃ : ∀ {A B v v' κ} {c : A ↔ B}
→ (r : ⟨ c ∣ v ∣ κ ⟩ ↦ [ c ∣ v' ∣ κ ])
→ base c ⊎ dual c ⊎ A ≡ B
Lemma₃ (↦₁ {b = b}) = inj₁ b
Lemma₃ ↦₂ = inj₂ (inj₂ refl)
Lemma₃ ↦η = inj₂ (inj₁ tt)
Lemma₃ ↦ε₁ = inj₂ (inj₁ tt)
Lemma₄ : ∀ {A v v' κ} {c : A ↔ A}
→ (r : ⟨ c ∣ v ∣ κ ⟩ ↦ [ c ∣ v' ∣ κ ])
→ base c ⊎ c ≡ id↔
Lemma₄ {c = swap₊} ↦₁ = inj₁ tt
Lemma₄ {c = swap⋆} ↦₁ = inj₁ tt
Lemma₄ ↦₂ = inj₂ refl
Lemma₅ : ∀ {A B v v' b κ} {c : A ↔ B ×ᵤ 𝟙/ b}
→ (r : ⟨ c ∣ v ∣ κ ⟩ ↦ [ c ∣ v' ∣ κ ])
→ base c ⊎ (b , ↻) ≡ v' ⊎ ¬ (dual c)
Lemma₅ (↦₁ {b = b}) = inj₁ b
Lemma₅ ↦₂ = inj₂ (inj₂ (λ ()))
Lemma₅ ↦η = inj₂ (inj₁ refl)
Lemma₆ : ∀ {A v v' κ} → v ≢ v' → ∄[ st' ] (st' ↦ [ ηₓ {A} v ∣ v' , ↻ ∣ κ ])
Lemma₆ neq (⟨ _ ∣ v ∣ _ ⟩ , r) with Lemma₁ r
... | refl , refl with Lemma₂ r
... | refl , refl with Lemma₅ r
... | inj₂ (inj₁ refl) = neq refl
... | inj₂ (inj₂ nd) = nd tt
| {
"alphanum_fraction": 0.5103857567,
"avg_line_length": 29.0517241379,
"ext": "agda",
"hexsha": "d78d4e4805fafa8d137cbc7da5dbefae4aaf82db",
"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": "PiFrac/AuxLemmas.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": "PiFrac/AuxLemmas.agda",
"max_line_length": 75,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "PiFrac/AuxLemmas.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": 802,
"size": 1685
} |
------------------------------------------------------------------------------
-- Testing anonymous module
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- No top-level module
postulate
D : Set
_≡_ : D → D → Set
postulate foo : ∀ t → t ≡ t
{-# ATP prove foo #-}
| {
"alphanum_fraction": 0.3438155136,
"avg_line_length": 26.5,
"ext": "agda",
"hexsha": "104feb59cdacc31b1c29909fd9684ec8f482b7a4",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Succeed/fol-theorems/NonTopLevelModuleName.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Succeed/fol-theorems/NonTopLevelModuleName.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Succeed/fol-theorems/NonTopLevelModuleName.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 85,
"size": 477
} |
module Tactic.Nat.Subtract.Lemmas where
open import Prelude
open import Tactic.Nat.NF
open import Tactic.Nat.Exp
open import Container.Bag
open import Tactic.Nat.Simpl
open import Prelude.Nat.Properties
open import Prelude.List.Properties
open import Tactic.Nat.Auto.Lemmas
open import Tactic.Nat.Simpl.Lemmas
open import Tactic.Nat.Auto
open import Tactic.Nat.Simpl
open import Tactic.Nat.Subtract.Exp
sub-cancel : (a : Nat) → a - a ≡ 0
sub-cancel zero = refl
sub-cancel (suc a) = sub-cancel a
sub-add-r : (a b c : Nat) → a - (b + c) ≡ a - b - c
sub-add-r a zero c = refl
sub-add-r zero (suc b) zero = refl
sub-add-r zero (suc b) (suc c) = refl
sub-add-r (suc a) (suc b) c = sub-add-r a b c
lem-sub-zero : (a b c : Nat) → b + c ≡ a → c ≡ a - b
lem-sub-zero ._ zero c refl = refl
lem-sub-zero ._ (suc b) c refl = lem-sub-zero _ b c refl
lem-zero-sub : (a b c : Nat) → b ≡ a + c → 0 ≡ a - b
lem-zero-sub zero ._ zero refl = refl
lem-zero-sub zero ._ (suc c) refl = refl
lem-zero-sub (suc a) ._ c refl = lem-zero-sub a _ c refl
lem-sub : (a b u v : Nat) → b + u ≡ a + v → u - v ≡ a - b
lem-sub zero zero u ._ refl = sub-cancel u
lem-sub zero (suc b) u ._ refl = sym $ lem-zero-sub u (suc b + u) (suc b) auto
lem-sub (suc a) zero ._ v refl = sym $ lem-sub-zero (suc a + v) v (suc a) auto
lem-sub (suc a) (suc b) u v eq = lem-sub a b u v (suc-inj eq)
sub-mul-distr-l : (a b c : Nat) → (a - b) * c ≡ a * c - b * c
sub-mul-distr-l zero b c = (_* c) $≡ lem-zero-sub 0 b b refl ʳ⟨≡⟩ lem-zero-sub 0 (b * c) (b * c) refl
sub-mul-distr-l (suc a) zero c = refl
sub-mul-distr-l (suc a) (suc b) c =
sub-mul-distr-l a b c ⟨≡⟩
lem-sub (suc a * c) (suc b * c) (a * c) (b * c) auto
sub-mul-distr-r : (a b c : Nat) → a * (b - c) ≡ a * b - a * c
sub-mul-distr-r a b c =
auto ⟨≡⟩ sub-mul-distr-l b c a
⟨≡⟩ cong₂ _-_ (mul-commute b a) (mul-commute c a)
-- The evaluator that doesn't generate x * 1 + 0 is the same as the
-- one that does.
lem-eval-sns-sn : ∀ n ρ → ⟦ n ⟧sns ρ ≡ ⟦ n ⟧sn ρ
private
lem-eval-sns-sn-t : ∀ t ρ → ⟦ t ⟧sts ρ ≡ ⟦ t ⟧st ρ
lem-eval-sns-sn-a : ∀ a ρ → ⟦ a ⟧sas ρ ≡ ⟦ a ⟧sa ρ
lem-eval-sns-sn-a (var x) ρ = refl
lem-eval-sns-sn-a (a ⟨-⟩ b) ρ = _-_ $≡ lem-eval-sns-sn a ρ *≡ lem-eval-sns-sn b ρ
lem-eval-sns-sn-t [] ρ = refl
lem-eval-sns-sn-t (x ∷ []) ρ = lem-eval-sns-sn-a x ρ ⟨≡⟩ auto
lem-eval-sns-sn-t (x ∷ y ∷ t) ρ = _*_ $≡ lem-eval-sns-sn-a x ρ *≡ lem-eval-sns-sn-t (y ∷ t) ρ
lem-eval-sns-sn [] ρ = refl
lem-eval-sns-sn ((k , t) ∷ []) ρ = _*_ k $≡ lem-eval-sns-sn-t t ρ ⟨≡⟩ auto
lem-eval-sns-sn ((k , t) ∷ t₁ ∷ n) ρ = _+_ $≡ (_*_ k $≡ lem-eval-sns-sn-t t ρ)
*≡ lem-eval-sns-sn (t₁ ∷ n) ρ
-- The evaluation that the termination checker lets us write is the
-- same as the one we want to write.
private
lem-eval-sn-n-t : ∀ t ρ → ⟦ t ⟧st ρ ≡ productR (map (atomEnv ρ) t)
lem-eval-sn-n-t [] ρ = refl
lem-eval-sn-n-t (x ∷ t) ρ = (⟦ x ⟧sa ρ *_) $≡ lem-eval-sn-n-t t ρ
lem-eval-sn-n : ∀ n ρ → ⟦ n ⟧sn ρ ≡ ⟦ n ⟧n (atomEnv ρ)
lem-eval-sn-n [] ρ = refl
lem-eval-sn-n ((k , t) ∷ n) ρ = _+_ $≡ (_*_ k $≡ lem-eval-sn-n-t t ρ) *≡ lem-eval-sn-n n ρ
private
lem-env : ∀ ρ x → atomEnvS ρ x ≡ atomEnv ρ x
lem-env ρ (var x) = refl
lem-env ρ (a ⟨-⟩ b) = _-_ $≡ lem-eval-sns-sn a ρ *≡ lem-eval-sns-sn b ρ
-- Combining the above equalities.
lem-eval-sn-nS : ∀ n ρ → ⟦ n ⟧sn ρ ≡ ⟦ n ⟧n (atomEnvS ρ)
lem-eval-sn-nS n ρ = lem-eval-sn-n n ρ ⟨≡⟩ʳ lem-eval-env (atomEnvS ρ) (atomEnv ρ) (lem-env ρ) n
lem-eval-sns-nS : ∀ n ρ → ⟦ n ⟧sns ρ ≡ ⟦ n ⟧n (atomEnvS ρ)
lem-eval-sns-nS n ρ = lem-eval-sns-sn n ρ ⟨≡⟩ lem-eval-sn-nS n ρ
lem-eval-sns-ns : ∀ n ρ → ⟦ n ⟧sns ρ ≡ ⟦ n ⟧ns (atomEnvS ρ)
lem-eval-sns-ns n ρ = lem-eval-sns-nS n ρ ⟨≡⟩ʳ ns-sound n (atomEnvS ρ)
⟨-⟩-sound′ : ∀ a b ρ → ⟦ a -nf′ b ⟧n (atomEnv ρ) ≡ ⟦ a ⟧n (atomEnv ρ) - ⟦ b ⟧n (atomEnv ρ)
⟨-⟩-sound′ a b ρ with cancel a b | λ i j → cancel-complete′ i j a b (atomEnv ρ)
⟨-⟩-sound′ a b ρ | d , [] | complete =
let u = ⟦ a ⟧n (atomEnv ρ)
v = ⟦ b ⟧n (atomEnv ρ)
k = ⟦ d ⟧n (atomEnv ρ) in
lem-sub-zero u v k (complete v u auto ⟨≡⟩ auto)
⟨-⟩-sound′ a b ρ | [] , d ∷ ds | complete =
let u = ⟦ a ⟧n (atomEnv ρ)
v = ⟦ b ⟧n (atomEnv ρ)
k = ⟦ d ∷ ds ⟧n (atomEnv ρ) in
lem-zero-sub u v k (auto ⟨≡⟩ complete v u auto)
⟨-⟩-sound′ a b ρ | u ∷ us , v ∷ vs | complete =
let eval = λ x → ⟦ x ⟧n (atomEnv ρ) in
(⟦ u ∷ us ⟧sn ρ - ⟦ v ∷ vs ⟧sn ρ) * 1 + 0 + 0
≡⟨ auto ⟩
⟦ u ∷ us ⟧sn ρ - ⟦ v ∷ vs ⟧sn ρ
≡⟨ cong₂ _-_ (lem-eval-sn-n (u ∷ us) ρ) (lem-eval-sn-n (v ∷ vs) ρ) ⟩
eval (u ∷ us) - eval (v ∷ vs)
≡⟨ lem-sub (eval a) (eval b) (eval (u ∷ us)) (eval (v ∷ vs)) (complete (eval b) (eval a) auto) ⟩
eval a - eval b ∎
⟨-⟩-sound : ∀ a b ρ → ⟦ a -nf b ⟧n (atomEnv ρ) ≡ ⟦ a ⟧n (atomEnv ρ) - ⟦ b ⟧n (atomEnv ρ)
⟨-⟩-sound a b ρ with is-subtraction a
⟨-⟩-sound a b ρ | no = ⟨-⟩-sound′ a b ρ
⟨-⟩-sound ._ c ρ | a ⟨-⟩ b =
let eval = λ x → ⟦ x ⟧n (atomEnv ρ) in
⟨-⟩-sound′ a (b +nf c) ρ ⟨≡⟩
(eval a -_) $≡ ⟨+⟩-sound b c (atomEnv ρ) ⟨≡⟩
sub-add-r (eval a) (eval b) (eval c) ⟨≡⟩
(_- eval c) $≡ (_-_ $≡ lem-eval-sn-n a ρ *≡ lem-eval-sn-n b ρ) ʳ⟨≡⟩
(_- eval c) $≡ auto
⟨*⟩-sound₁ : ∀ a b ρ → ⟦ a *nf₁ b ⟧n (atomEnv ρ) ≡ ⟦ a ⟧n (atomEnv ρ) * ⟦ b ⟧n (atomEnv ρ)
private
sound-mul-ktm′ : ∀ t a ρ → ⟦ t *ktm′ a ⟧n (atomEnv ρ) ≡ ⟦ t ⟧t (atomEnv ρ) * ⟦ a ⟧n (atomEnv ρ)
sound-mul-tm : ∀ s t ρ → ⟦ s *tm t ⟧n (atomEnv ρ) ≡ ⟦ s ⟧t (atomEnv ρ) * ⟦ t ⟧t (atomEnv ρ)
sound-mul-tm s t ρ with is-subtraction-tm t
sound-mul-tm (x , a) (y , b) ρ | no =
follows-from (x * y *_ $≡ map-merge a b (atomEnv ρ))
sound-mul-tm s ._ ρ | a ⟨-⟩ b =
let eval x = ⟦ x ⟧n (atomEnv ρ)
evalt x = ⟦ x ⟧t (atomEnv ρ) in
⟨-⟩-sound (s *ktm′ a) (s *ktm′ b) ρ ⟨≡⟩
_-_ $≡ sound-mul-ktm′ s a ρ *≡ sound-mul-ktm′ s b ρ ⟨≡⟩
sub-mul-distr-r (evalt s) (eval a) (eval b) ʳ⟨≡⟩
(evalt s *_) $≡ (_-_ $≡ lem-eval-sn-n a ρ *≡ lem-eval-sn-n b ρ) ʳ⟨≡⟩
auto
sound-mul-ktm′ t [] ρ = auto
sound-mul-ktm′ t (x ∷ a) ρ =
let eval x = ⟦ x ⟧n (atomEnv ρ)
evalt x = ⟦ x ⟧t (atomEnv ρ) in
⟨+⟩-sound (t *tm x) (t *ktm′ a) (atomEnv ρ) ⟨≡⟩
_+_ $≡ sound-mul-tm t x ρ *≡ sound-mul-ktm′ t a ρ ⟨≡⟩ʳ
mul-distr-l (evalt t) (evalt x) (eval a)
sound-mul-ktm : ∀ t a ρ → ⟦ t *ktm a ⟧n (atomEnv ρ) ≡ ⟦ t ⟧t (atomEnv ρ) * ⟦ a ⟧n (atomEnv ρ)
sound-mul-ktm t a ρ with is-subtraction-tm t
sound-mul-ktm t a ρ | no = sound-mul-ktm′ t a ρ
sound-mul-ktm ._ c ρ | a ⟨-⟩ b =
let eval x = ⟦ x ⟧n (atomEnv ρ) in
⟨-⟩-sound (a *nf₁ c) (b *nf₁ c) ρ ⟨≡⟩
_-_ $≡ ⟨*⟩-sound₁ a c ρ *≡ ⟨*⟩-sound₁ b c ρ ⟨≡⟩
sub-mul-distr-l (eval a) (eval b) (eval c) ʳ⟨≡⟩
(_* eval c) $≡ (_-_ $≡ lem-eval-sn-n a ρ *≡ lem-eval-sn-n b ρ) ʳ⟨≡⟩
auto
⟨*⟩-sound₁ [] b ρ = refl
⟨*⟩-sound₁ (t ∷ a) b ρ =
let eval x = ⟦ x ⟧n (atomEnv ρ)
evalt x = ⟦ x ⟧t (atomEnv ρ) in
⟨+⟩-sound (t *ktm b) (a *nf₁ b) (atomEnv ρ) ⟨≡⟩
_+_ $≡ sound-mul-ktm t b ρ *≡ ⟨*⟩-sound₁ a b ρ ⟨≡⟩ʳ
mul-distr-r (evalt t) (eval a) (eval b)
sound-sub : ∀ e ρ → ⟦ e ⟧se ρ ≡ ⟦ normSub e ⟧sn ρ
sound-sub (var x) ρ = auto
sound-sub (lit 0) ρ = refl
sound-sub (lit (suc n)) ρ = auto
sound-sub (e ⟨+⟩ e₁) ρ =
cong₂ _+_ (sound-sub e ρ ⟨≡⟩ lem-eval-sn-n (normSub e) ρ)
(sound-sub e₁ ρ ⟨≡⟩ lem-eval-sn-n (normSub e₁) ρ) ⟨≡⟩
⟨+⟩-sound (normSub e) (normSub e₁) (atomEnv ρ) ʳ⟨≡⟩ʳ
lem-eval-sn-n (normSub (e ⟨+⟩ e₁)) ρ
sound-sub (e ⟨*⟩ e₁) ρ =
cong₂ _*_ (sound-sub e ρ ⟨≡⟩ lem-eval-sn-n (normSub e) ρ)
(sound-sub e₁ ρ ⟨≡⟩ lem-eval-sn-n (normSub e₁) ρ) ⟨≡⟩
⟨*⟩-sound₁ (normSub e) (normSub e₁) ρ ʳ⟨≡⟩ʳ
lem-eval-sn-n (normSub (e ⟨*⟩ e₁)) ρ
sound-sub (e ⟨-⟩ e₁) ρ =
cong₂ _-_ (sound-sub e ρ ⟨≡⟩ lem-eval-sn-n (normSub e) ρ)
(sound-sub e₁ ρ ⟨≡⟩ lem-eval-sn-n (normSub e₁) ρ) ⟨≡⟩
⟨-⟩-sound (normSub e) (normSub e₁) ρ ʳ⟨≡⟩ʳ
lem-eval-sn-n (normSub (e ⟨-⟩ e₁)) ρ
liftNFSubEq : ∀ e₁ e₂ ρ → ⟦ normSub e₁ ⟧sn ρ ≡ ⟦ normSub e₂ ⟧sn ρ → ⟦ e₁ ⟧se ρ ≡ ⟦ e₂ ⟧se ρ
liftNFSubEq e₁ e₂ ρ eq = eraseEquality $ sound-sub e₁ ρ ⟨≡⟩ eq ⟨≡⟩ʳ sound-sub e₂ ρ
unliftNFSubEq : ∀ e₁ e₂ ρ → ⟦ e₁ ⟧se ρ ≡ ⟦ e₂ ⟧se ρ → ⟦ normSub e₁ ⟧sn ρ ≡ ⟦ normSub e₂ ⟧sn ρ
unliftNFSubEq e₁ e₂ ρ eq = eraseEquality $ sound-sub e₁ ρ ʳ⟨≡⟩ eq ⟨≡⟩ sound-sub e₂ ρ
SubExpEq : SubExp → SubExp → Env Var → Set
SubExpEq e₁ e₂ ρ = ⟦ e₁ ⟧se ρ ≡ ⟦ e₂ ⟧se ρ
CancelSubEq : SubExp → SubExp → Env Var → Set
CancelSubEq e₁ e₂ ρ = NFEqS (cancel (normSub e₁) (normSub e₂)) (atomEnvS ρ)
simplifySubEq : ∀ e₁ e₂ (ρ : Env Var) → CancelSubEq e₁ e₂ ρ → SubExpEq e₁ e₂ ρ
simplifySubEq e₁ e₂ ρ H = liftNFSubEq e₁ e₂ ρ $
lem-eval-sn-nS (normSub e₁) ρ ⟨≡⟩
cancel-sound (normSub e₁) (normSub e₂) (atomEnvS ρ) H ⟨≡⟩ʳ
lem-eval-sn-nS (normSub e₂) ρ
complicateSubEq : ∀ e₁ e₂ ρ → SubExpEq e₁ e₂ ρ → CancelSubEq e₁ e₂ ρ
complicateSubEq e₁ e₂ ρ H =
cancel-complete (normSub e₁) (normSub e₂) (atomEnvS ρ) $
lem-eval-sn-nS (normSub e₁) ρ ʳ⟨≡⟩
unliftNFSubEq e₁ e₂ ρ H ⟨≡⟩
lem-eval-sn-nS (normSub e₂) ρ
| {
"alphanum_fraction": 0.54062707,
"avg_line_length": 40.2577777778,
"ext": "agda",
"hexsha": "b4c063a4772baa1d9c658ceb3f0705aff4c84be0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "t-more/agda-prelude",
"max_forks_repo_path": "src/Tactic/Nat/Subtract/Lemmas.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "t-more/agda-prelude",
"max_issues_repo_path": "src/Tactic/Nat/Subtract/Lemmas.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "t-more/agda-prelude",
"max_stars_repo_path": "src/Tactic/Nat/Subtract/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4447,
"size": 9058
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.Unary.Properties where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Function using (id; _∘_)
open import Cubical.Data.Unit
open import Cubical.Data.Empty
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Relation.Unary
private
variable
ℓ ℓ₁ ℓ₂ ℓ₃ : Level
A : Type ℓ
------------------------------------------------------------------------
-- Special sets
Empty∅ : Empty {A = A} ∅
Empty∅ _ ()
UniversalU : Π[ U {A = A} ]
UniversalU _ = tt
∁∅≡U : ∁ ∅ ≡ U {A = A}
∁∅≡U = ⇔toPath _ _ ((λ _ → tt) , λ _ ())
∁U≡∅ : ∁ U ≡ ∅ {A = A}
∁U≡∅ = ⇔toPath _ _ ((λ f → f tt) , λ ())
------------------------------------------------------------------------
-- Propositions
module _ (P : Pred A ℓ₁) (Q : Pred A ℓ₂) where
isProp⊆ : isProp (P ⊆ Q)
isProp⊆ = isPropImplicitΠ λ _ → isPropΠ λ _ → isProp[ Q ] _
isProp⊂ : isProp (P ⊂ Q)
isProp⊂ = isProp× isProp⊆ (isPropΠ λ _ → isProp⊥)
isProp⇔ : isProp (P ⇔ Q)
isProp⇔ = isProp× isProp⊆ (isPropImplicitΠ λ _ → isPropΠ λ _ → isProp[ P ] _)
module _ (P : Pred A ℓ) where
isPropEmpty : isProp (Empty P)
isPropEmpty = isPropΠ2 λ _ _ → isProp⊥
isPropSatisfiable : isProp ∃⟨ P ⟩
isPropSatisfiable = squash
isPropUniversal : isProp Π[ P ]
isPropUniversal = isPropΠ isProp[ P ]
------------------------------------------------------------------------
-- Predicate equivalence
⇔-reflexive : (P : Pred A ℓ) → P ⇔ P
⇔-reflexive P = id , id
⇔-symmetric : (P : Pred A ℓ₁) (Q : Pred A ℓ₂) → P ⇔ Q → Q ⇔ P
⇔-symmetric P Q (x , y) = (y , x)
⇔-transitive : (P : Pred A ℓ₁) (Q : Pred A ℓ₂) (R : Pred A ℓ₃) →
P ⇔ Q → Q ⇔ R → P ⇔ R
⇔-transitive P Q R (x , y) (w , z) = w ∘ x , y ∘ z
| {
"alphanum_fraction": 0.5584545911,
"avg_line_length": 24.0120481928,
"ext": "agda",
"hexsha": "66b6dd76401404fe2827a46ba849ef11ce09e880",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Relation/Unary/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Relation/Unary/Properties.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Relation/Unary/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 741,
"size": 1993
} |
module EffectUtil where
open import Data.List
open import Data.List.All
open import Data.List.Any
open import Level
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Function
open import Category.Monad
open import Data.Product
-- open import EffectUtil
open import Membership-equality hiding (_⊆_; set)
infix 3 _⊆_
-- Sublist without re-ordering, to be improved later...
data _⊆_ {a}{A : Set a} : List A → List A → Set a where
[] : ∀ {ys} → [] ⊆ ys
keep : ∀ {x xs ys} → xs ⊆ ys → x ∷ xs ⊆ x ∷ ys
skip : ∀ {x xs ys} → xs ⊆ ys → xs ⊆ x ∷ ys
singleton-⊆ : ∀ {a} {A : Set a} {x : A} {xs : List A} → x ∈ xs → [ x ] ⊆ xs
singleton-⊆ (here refl) = keep []
singleton-⊆ (there mem) = skip (singleton-⊆ mem)
reflexive-⊆ : ∀ {a} {A : Set a} {xs : List A} → xs ⊆ xs
reflexive-⊆ {xs = []} = []
reflexive-⊆ {xs = x ∷ xs} = keep reflexive-⊆
| {
"alphanum_fraction": 0.6219653179,
"avg_line_length": 28.8333333333,
"ext": "agda",
"hexsha": "3d17c16ff7d4b02453742d2fb6e541d145a740ba",
"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": "unused/EffectUtil.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": "unused/EffectUtil.agda",
"max_line_length": 75,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zalastax/singly-typed-actors",
"max_stars_repo_path": "unused/EffectUtil.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-29T09:30:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:30:26.000Z",
"num_tokens": 319,
"size": 865
} |
-- Andreas, 2016-04-26 flight home from AIM XXIII
module _ where
module M (A : Set) where
record R : Set where
field f : A
module H {A} = M A
open M using (R)
open M.R using (f) -- f : {A : Set} → R A → A
open H.R using (f) -- f : {A : Set} → R A → A
r : ∀ A (a : A) → R A
f (r A a) = a
test : ∀ A (a : A) → A
test A a = f (r A a)
test' : ∀ A (a : A) → A
test' A a = f {A = _} (r A a)
| {
"alphanum_fraction": 0.4925,
"avg_line_length": 17.3913043478,
"ext": "agda",
"hexsha": "d702620dcd93dcfd1fda4ff51d9bf326a260ee4c",
"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/Issue1944-module-copy.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/Issue1944-module-copy.agda",
"max_line_length": 49,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1944-module-copy.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": 175,
"size": 400
} |
module Numeral.PositiveInteger.Oper where
open import Numeral.PositiveInteger
infixl 10010 _+_
infixl 10020 _⋅_
infixl 10030 _^_
-- Addition
_+_ : ℕ₊ → ℕ₊ → ℕ₊
x + 𝟏 = 𝐒(x)
x + 𝐒(y) = 𝐒(x + y)
-- Multiplication
_⋅_ : ℕ₊ → ℕ₊ → ℕ₊
x ⋅ 𝟏 = x
x ⋅ 𝐒(y) = x + (x ⋅ y)
-- Exponentiation
_^_ : ℕ₊ → ℕ₊ → ℕ₊
x ^ 𝟏 = x
x ^ 𝐒(y) = x ⋅ (x ^ y)
-- Factorial
_! : ℕ₊ → ℕ₊
𝟏 ! = 𝟏
𝐒(x) ! = 𝐒(x) ⋅ (x !)
open import Data.Option
open import Data.Option.Functions
-- Truncated subtraction
_−₀_ : ℕ₊ → ℕ₊ → Option(ℕ₊)
𝟏 −₀ _ = None
𝐒(x) −₀ 𝟏 = Some x
𝐒(x) −₀ 𝐒(y) = x −₀ y
open import Data.Boolean
open import Type
_≤?_ : ℕ₊ → ℕ₊ → Bool
𝟏 ≤? _ = 𝑇
𝐒(x) ≤? 𝟏 = 𝐹
𝐒(x) ≤? 𝐒(y) = x ≤? y
| {
"alphanum_fraction": 0.5213068182,
"avg_line_length": 16.3720930233,
"ext": "agda",
"hexsha": "d4c6172b98513180cb52dce565ed2ecbedb3e61e",
"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": "Numeral/PositiveInteger/Oper.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": "Numeral/PositiveInteger/Oper.agda",
"max_line_length": 41,
"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": "Numeral/PositiveInteger/Oper.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": 391,
"size": 704
} |
------------------------------------------------------------------------
-- Examples for modalities
------------------------------------------------------------------------
module CTL.ModalityExamples where
open import Library
open import FStream.Containers
open import FStream.Core
open import CTL.Modalities
readDouble : ⟦ ReaderC ℕ ⟧ ℕ
readDouble = fmap (_* 2) ask
readSuc : ⟦ ReaderC ℕ ⟧ ℕ
readSuc = fmap (suc) ask
alwaysPos : (n : ℕ) → runReader readSuc n > 0
alwaysPos n = s≤s z≤n
alwaysPosC : □ (_> 0) readSuc
alwaysPosC = λ p → s≤s z≤n
sometimes3 : ◇ (_≡ 3) readSuc
sometimes3 = suc (suc zero) , refl
sometimes5 : ◇ (_≡ 5) readSuc
sometimes5 = suc (suc (suc (suc zero))) , refl
-- It is always the case that constantly readSuc outputs ℕ > 0,
-- regardless of the environment
always>0 : AG (map (_> 0) (constantly readSuc))
nowA (always>0 p) = alwaysPos p
laterA (always>0 p) = {!!}
{-nowA always>0 = λ p → s≤s z≤n
laterA always>0 = λ p → always>0
-}
{-
nowA always>0 p = s≤s z≤n
laterA always>0 p = always>0
-}
-- Sums all values in the reader-environment
sumFrom : ℕ → FStream (ReaderC ℕ) ℕ
proj₁ (inF (sumFrom n0)) = tt
head (proj₂ (inF (sumFrom n0)) n) = n0 + n
tail (proj₂ (inF (sumFrom n0)) n) = sumFrom (n0 + n)
sum : FStream (ReaderC ℕ) ℕ
sum = sumFrom 0
-- Eventually the sum is greater than 2
eventuallysometimes>2 : EF (map (_> 2) sum)
-- ... having 3 as input, this is of course the case after 1 step
eventuallysometimes>2 = ? --alreadyE (suc (suc (suc zero)) , s≤s (s≤s (s≤s z≤n)))
-- Always somehow the sum is greater than 2
alwaysSomehow>2 : ∀ {i} → EG {i} (map (_> 2) sum)
alwaysSomehow>2 = {!!}
{-proj₁ alwaysSomehow>2 = suc (suc (suc zero))
nowE' (proj₂ alwaysSomehow>2) = s≤s (s≤s (s≤s z≤n))
proj₁ (laterE' (proj₂ alwaysSomehow>2)) = zero
proj₂ (laterE' (proj₂ alwaysSomehow>2)) = {! !}
-}
{-
nowE alwaysSomehow>2 = (ℕ.suc (ℕ.suc (ℕ.suc ℕ.zero)) , s≤s (s≤s (s≤s z≤n)))
laterE alwaysSomehow>2 = ℕ.zero , alwaysSomehow>2
-}
--
| {
"alphanum_fraction": 0.6054628225,
"avg_line_length": 24.4074074074,
"ext": "agda",
"hexsha": "b0780bfd57e74b630e2f68d859f046bc0e70c1c6",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-12-13T15:56:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-12-13T15:56:38.000Z",
"max_forks_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "zimbatm/condatis",
"max_forks_repo_path": "CTL/ModalityExamples.agda",
"max_issues_count": 5,
"max_issues_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_issues_repo_issues_event_max_datetime": "2020-09-01T16:52:07.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-03T20:02:22.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "zimbatm/condatis",
"max_issues_repo_path": "CTL/ModalityExamples.agda",
"max_line_length": 81,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "Aerate/condatis",
"max_stars_repo_path": "CTL/ModalityExamples.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-13T16:52:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-13T16:52:28.000Z",
"num_tokens": 723,
"size": 1977
} |
{-# OPTIONS --safe #-}
module Cubical.Categories.Instances.CommRings where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Powerset
open import Cubical.Data.Unit
open import Cubical.Data.Sigma
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.FiberedProduct
open import Cubical.Algebra.CommRing.Instances.Unit
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
open import Cubical.Categories.Instances.Sets
open import Cubical.Categories.Instances.Functors
open import Cubical.Categories.Limits.Terminal
open import Cubical.Categories.Limits.Pullback
open import Cubical.Categories.Limits.Limits
open import Cubical.HITs.PropositionalTruncation
open Category hiding (_∘_)
open isUnivalent
open CatIso
open Functor
open CommRingStr
open RingHoms
open IsRingHom
private
variable
ℓ ℓ' ℓ'' : Level
CommRingsCategory : Category (ℓ-suc ℓ) ℓ
ob CommRingsCategory = CommRing _
Hom[_,_] CommRingsCategory = CommRingHom
id CommRingsCategory {R} = idCommRingHom R
_⋆_ CommRingsCategory {R} {S} {T} = compCommRingHom R S T
⋆IdL CommRingsCategory {R} {S} = compIdCommRingHom {R = R} {S}
⋆IdR CommRingsCategory {R} {S} = idCompCommRingHom {R = R} {S}
⋆Assoc CommRingsCategory {R} {S} {T} {U} = compAssocCommRingHom {R = R} {S} {T} {U}
isSetHom CommRingsCategory = isSetRingHom _ _
forgetfulFunctor : Functor CommRingsCategory (SET ℓ)
F-ob forgetfulFunctor R = R .fst , CommRingStr.is-set (snd R)
F-hom forgetfulFunctor f x = f .fst x
F-id forgetfulFunctor = funExt (λ _ → refl)
F-seq forgetfulFunctor f g = funExt (λ _ → refl)
open Iso
CommRingIsoIsoCatIso : {R S : CommRing ℓ} → Iso (CommRingIso R S) (CatIso CommRingsCategory R S)
mor (fun CommRingIsoIsoCatIso e) = (e .fst .fun) , (e .snd)
inv (fun (CommRingIsoIsoCatIso {R = R} {S}) e) =
e .fst .inv
, makeIsRingHom (sym (cong (e .fst .inv) (pres1 (e .snd))) ∙ e .fst .leftInv _)
(λ x y → let rem = e .fst .rightInv _
∙∙ (λ i → S .snd ._+_ (e .fst .rightInv x (~ i)) (e .fst .rightInv y (~ i)))
∙∙ sym (pres+ (e .snd) _ _)
in injCommRingIso {R = R} {S} e _ _ rem)
(λ x y → let rem = e .fst .rightInv _
∙∙ (λ i → S .snd ._·_ (e .fst .rightInv x (~ i)) (e .fst .rightInv y (~ i)))
∙∙ sym (pres· (e .snd) _ _)
in injCommRingIso {R = R} {S} e _ _ rem)
sec (fun CommRingIsoIsoCatIso e) = RingHom≡ (funExt (e .fst .rightInv))
ret (fun CommRingIsoIsoCatIso e) = RingHom≡ (funExt (e .fst .leftInv))
fun (fst (inv CommRingIsoIsoCatIso e)) = e .mor .fst
inv (fst (inv CommRingIsoIsoCatIso e)) = e .inv .fst
rightInv (fst (inv CommRingIsoIsoCatIso e)) x i = fst (e .sec i) x
leftInv (fst (inv CommRingIsoIsoCatIso e)) x i = fst (e .ret i) x
snd (inv CommRingIsoIsoCatIso e) = e .mor .snd
rightInv CommRingIsoIsoCatIso x = CatIso≡ _ _ (RingHom≡ refl) (RingHom≡ refl)
leftInv (CommRingIsoIsoCatIso {R = R} {S}) x =
Σ≡Prop (λ x → isPropIsRingHom (CommRingStr→RingStr (R .snd))
(x .fun)
(CommRingStr→RingStr (S .snd)))
(Iso≡Set (is-set (snd R)) (is-set (snd S)) _ _ (λ _ → refl) (λ _ → refl))
isUnivalentCommRingsCategory : ∀ {ℓ} → isUnivalent {ℓ = ℓ-suc ℓ} CommRingsCategory
univ isUnivalentCommRingsCategory R S = subst isEquiv (funExt rem) (≡≃CatIso .snd)
where
CommRingEquivIso≡ : Iso (CommRingEquiv R S) (R ≡ S)
CommRingEquivIso≡ = equivToIso (CommRingPath R S)
≡≃CatIso : (R ≡ S) ≃ (CatIso CommRingsCategory R S)
≡≃CatIso = isoToEquiv (compIso (invIso CommRingEquivIso≡)
(compIso (CommRingEquivIsoCommRingIso R S) CommRingIsoIsoCatIso))
rem : ∀ p → ≡≃CatIso .fst p ≡ pathToIso p
rem p = CatIso≡ _ _
(RingHom≡ (funExt (λ x → cong (transport (λ i → fst (p i))) (sym (transportRefl x)))))
(RingHom≡ (funExt (λ x → sym (transportRefl _))))
TerminalCommRing : Terminal {ℓ-suc ℓ-zero} CommRingsCategory
fst TerminalCommRing = UnitCommRing
fst (fst (snd TerminalCommRing y)) _ = tt*
snd (fst (snd TerminalCommRing y)) = makeIsRingHom refl (λ _ _ → refl) (λ _ _ → refl)
snd (snd TerminalCommRing y) f = RingHom≡ (funExt (λ _ → refl))
open Pullback
{-
A x_C B -----> A
| |
| | α
| |
V V
B --------> C
β
-}
PullbackCommRingsCategory : Pullbacks {ℓ-suc ℓ} CommRingsCategory
pbOb (PullbackCommRingsCategory (cospan A C B α β)) = fiberedProduct A B C α β
pbPr₁ (PullbackCommRingsCategory (cospan A C B α β)) = fiberedProductPr₁ A B C α β
pbPr₂ (PullbackCommRingsCategory (cospan A C B α β)) = fiberedProductPr₂ A B C α β
pbCommutes (PullbackCommRingsCategory (cospan A C B α β)) = fiberedProductPr₁₂Commutes A B C α β
univProp (PullbackCommRingsCategory (cospan A C B α β)) {d = D} = fiberedProductUnivProp A B C α β D
-- General limits
module _ {ℓJ ℓJ' : Level} where
open LimCone
open Cone
LimitsCommRingsCategory : Limits {ℓJ} {ℓJ'} CommRingsCategory
fst (lim (LimitsCommRingsCategory J D)) =
lim {J = J} (completeSET J (funcComp forgetfulFunctor D)) .fst
0r (snd (lim (LimitsCommRingsCategory J D))) =
cone (λ v _ → 0r (snd (F-ob D v)))
(λ e → funExt (λ _ → F-hom D e .snd .pres0))
1r (snd (lim (LimitsCommRingsCategory J D))) =
cone (λ v _ → 1r (snd (F-ob D v)))
(λ e → funExt (λ _ → F-hom D e .snd .pres1))
_+_ (snd (lim (LimitsCommRingsCategory J D))) x y =
cone (λ v _ → _+_ (snd (F-ob D v)) _ _)
( λ e → funExt (λ _ → F-hom D e .snd .pres+ _ _
∙ λ i → _+_ (snd (F-ob D _)) (coneOutCommutes x e i tt*) (coneOutCommutes y e i tt*)))
_·_ (snd (lim (LimitsCommRingsCategory J D))) x y =
cone (λ v _ → _·_ (snd (F-ob D v)) _ _)
( λ e → funExt (λ _ → F-hom D e .snd .pres· _ _
∙ λ i → _·_ (snd (F-ob D _)) (coneOutCommutes x e i tt*) (coneOutCommutes y e i tt*)))
(- snd (lim (LimitsCommRingsCategory J D))) x =
cone (λ v _ → -_ (snd (F-ob D v)) _)
( λ e → funExt (λ z → F-hom D e .snd .pres- _
∙ λ i → -_ (snd (F-ob D _)) (coneOutCommutes x e i tt*)))
isCommRing (snd (lim (LimitsCommRingsCategory J D))) =
makeIsCommRing
(isSetCone (funcComp forgetfulFunctor D) (Unit* , _))
(λ _ _ _ → cone≡ (λ v → funExt (λ _ → snd (F-ob D v) .+Assoc _ _ _)))
(λ _ → cone≡ (λ v → funExt (λ _ → +Rid (snd (F-ob D v)) _)))
(λ _ → cone≡ (λ v → funExt (λ _ → +Rinv (snd (F-ob D v)) _)))
(λ _ _ → cone≡ (λ v → funExt (λ _ → snd (F-ob D v) .+Comm _ _)))
(λ _ _ _ → cone≡ (λ v → funExt (λ _ → snd (F-ob D v) .·Assoc _ _ _)))
(λ _ → cone≡ (λ v → funExt (λ _ → ·Rid (snd (F-ob D v)) _)))
(λ _ _ _ → cone≡ (λ v → funExt (λ _ → ·Rdist+ (snd (F-ob D v)) _ _ _)))
(λ _ _ → cone≡ (λ v → funExt (λ _ → snd (F-ob D v) .·Comm _ _)))
fst (coneOut (limCone (LimitsCommRingsCategory J D)) v) =
coneOut (limCone (completeSET J (funcComp forgetfulFunctor D))) v
pres0 (snd (coneOut (limCone (LimitsCommRingsCategory J D)) v)) = refl
pres1 (snd (coneOut (limCone (LimitsCommRingsCategory J D)) v)) = refl
pres+ (snd (coneOut (limCone (LimitsCommRingsCategory J D)) v)) = λ _ _ → refl
pres· (snd (coneOut (limCone (LimitsCommRingsCategory J D)) v)) = λ _ _ → refl
pres- (snd (coneOut (limCone (LimitsCommRingsCategory J D)) v)) = λ _ → refl
coneOutCommutes (limCone (LimitsCommRingsCategory J D)) e =
RingHom≡ (coneOutCommutes (limCone (completeSET J (funcComp forgetfulFunctor D))) e)
univProp (LimitsCommRingsCategory J D) c cc =
uniqueExists
( (λ x → limArrow (completeSET J (funcComp forgetfulFunctor D))
(fst c , snd c .is-set)
(cone (λ v _ → coneOut cc v .fst x)
(λ e → funExt (λ _ → funExt⁻ (cong fst (coneOutCommutes cc e)) x))) x)
, makeIsRingHom
(cone≡ (λ v → funExt (λ _ → coneOut cc v .snd .pres1)))
(λ x y → cone≡ (λ v → funExt (λ _ → coneOut cc v .snd .pres+ _ _)))
(λ x y → cone≡ (λ v → funExt (λ _ → coneOut cc v .snd .pres· _ _))))
(λ _ → RingHom≡ refl)
(isPropIsConeMor cc (limCone (LimitsCommRingsCategory J D)))
(λ a' x → Σ≡Prop (λ _ → isPropIsRingHom _ _ _)
(funExt (λ y → cone≡ λ v → funExt (λ _ → sym (funExt⁻ (cong fst (x v)) y)))))
| {
"alphanum_fraction": 0.607360578,
"avg_line_length": 47.1170212766,
"ext": "agda",
"hexsha": "25f5a47d054c858012da913334b8f0308ac694c1",
"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/Categories/Instances/CommRings.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/Categories/Instances/CommRings.agda",
"max_line_length": 110,
"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/Categories/Instances/CommRings.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3074,
"size": 8858
} |
module DualTail where
open import Data.Nat
open import Data.Fin hiding (_+_)
open import Data.Product
open import Data.Vec hiding (map)
open import Function
open import Relation.Binary.PropositionalEquality hiding (Extensionality)
open import Direction
open import Extensionality
open import DualCoinductive
-- session types restricted to tail recursion
-- can be recognized by type of TChan constructor
data Type : Set
data SType (n : ℕ) : Set
data GType (n : ℕ) : Set
data Type where
TUnit TInt : Type
TPair : (t₁ t₂ : Type) → Type
TChan : (s : SType 0) → Type
data SType n where
gdd : (g : GType n) → SType n
rec : (g : GType (suc n)) → SType n
var : (x : Fin n) → SType n
data GType n where
transmit : (d : Dir) (t : Type) (s : SType n) → GType n
choice : (d : Dir) (m : ℕ) (alt : Fin m → SType n) → GType n
end : GType n
-- naive definition of duality for tail recursive session types
-- message types are ignored as they are closed
dualS : SType n → SType n
dualG : GType n → GType n
dualS (gdd g) = gdd (dualG g)
dualS (rec g) = rec (dualG g)
dualS (var x) = var x
dualG (transmit d t s) = transmit (dual-dir d) t (dualS s)
dualG (choice d m alt) = choice (dual-dir d) m (dualS ∘ alt)
dualG end = end
-- instead of unrolling and substituting, we maintain a stack of bodies of recursive types
data Stack : ℕ → Set where
ε : Stack 0
⟪_,_⟫ : Stack n → GType (suc n) → Stack (suc n)
-- the dual of a stack
dual-stack : Stack n → Stack n
dual-stack ε = ε
dual-stack ⟪ σ , g ⟫ = ⟪ dual-stack σ , dualG g ⟫
-- obtain an entry from the stack
-- technically m = n - i, but we don't need to know
get : (i : Fin n) → Stack n → Σ ℕ λ m → Stack m × GType (suc m)
get 0F ⟪ σ , x ⟫ = _ , (σ , x)
get (suc i) ⟪ σ , x ⟫ = get i σ
-- relate a stack entry to the corresponding entry on the dual stack
get-dual-stack : (x : Fin n) (σ : Stack n) →
get x (dual-stack σ) ≡ map id (map dual-stack dualG) (get x σ)
get-dual-stack 0F ⟪ σ , x ⟫ = refl
get-dual-stack (suc x) ⟪ σ , x₁ ⟫ = get-dual-stack x σ
-- mapping tail recursive session types to coinductive session types
-- relies on a stack to unfold variables on the fly
tail2coiT : Type → COI.Type
tail2coiS : Stack n → SType n → COI.SType
tail2coiG : Stack n → GType n → COI.STypeF COI.SType
tail2coiT TUnit = COI.TUnit
tail2coiT TInt = COI.TInt
tail2coiT (TPair t t₁) = COI.TPair (tail2coiT t) (tail2coiT t₁)
tail2coiT (TChan s) = COI.TChan (tail2coiS ε s)
COI.SType.force (tail2coiS σ (gdd g)) = tail2coiG σ g
COI.SType.force (tail2coiS σ (rec g)) = tail2coiG ⟪ σ , g ⟫ g
COI.SType.force (tail2coiS σ (var x))
with get x σ
... | m , σ' , gxs = tail2coiG ⟪ σ' , gxs ⟫ gxs
tail2coiG σ (transmit d t s) = COI.transmit d (tail2coiT t) (tail2coiS σ s)
tail2coiG σ (choice d m alt) = COI.choice d m (tail2coiS σ ∘ alt)
tail2coiG σ end = COI.end
-- get coinductive bisimulation in scope
_≈_ = COI._≈_
_≈'_ = COI._≈'_
-- main proposition
dual-tailS : (σ : Stack n) (s : SType n) →
COI.dual (tail2coiS σ s) ≈ tail2coiS (dual-stack σ) (dualS s)
dual-tailG : (σ : Stack n) (g : GType n) →
COI.dualF (tail2coiG σ g) ≈' tail2coiG (dual-stack σ) (dualG g)
COI.Equiv.force (dual-tailS σ (gdd g)) = dual-tailG σ g
COI.Equiv.force (dual-tailS σ (rec g)) = dual-tailG ⟪ σ , g ⟫ g
COI.Equiv.force (dual-tailS σ (var x))
rewrite get-dual-stack x σ
with get x σ
... | m , σ' , g = dual-tailG ⟪ σ' , g ⟫ g
dual-tailG σ (transmit d t s) = COI.eq-transmit (dual-dir d) COI.≈ᵗ-refl (dual-tailS σ s)
dual-tailG σ (choice d m alt) = COI.eq-choice (dual-dir d) (dual-tailS σ ∘ alt)
dual-tailG σ end = COI.eq-end
-- corrolary for SType 0
dual-tail : ∀ s → COI.dual (tail2coiS ε s) ≈ tail2coiS ε (dualS s)
dual-tail = dual-tailS ε
| {
"alphanum_fraction": 0.6590234691,
"avg_line_length": 29.8951612903,
"ext": "agda",
"hexsha": "77785ca04f3a4a018168bc884e1e782be7381cea",
"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/DualTail.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/DualTail.agda",
"max_line_length": 90,
"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/DualTail.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1455,
"size": 3707
} |
{-# OPTIONS --without-K #-}
module sets.nat.ordering where
open import sets.nat.ordering.lt public
open import sets.nat.ordering.leq public
| {
"alphanum_fraction": 0.7659574468,
"avg_line_length": 23.5,
"ext": "agda",
"hexsha": "f3bf27d6995e35e04aa22fafddc1c75215e42424",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/sets/nat/ordering.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/sets/nat/ordering.agda",
"max_line_length": 40,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/sets/nat/ordering.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": 35,
"size": 141
} |
module CompilingCoinduction where
open import Common.Coinduction
data List (A : Set) : Set where
[] : List A
_∷_ : (x : A) (xs : List A) → List A
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _∷_ #-}
{-# COMPILED_DATA List [] [] (:) #-}
postulate
Char : Set
{-# BUILTIN CHAR Char #-}
{-# COMPILED_TYPE Char Char #-}
-- Strings --
postulate
String : Set
{-# BUILTIN STRING String #-}
{-# COMPILED_TYPE String String #-}
data Unit : Set where
unit : Unit
{-# COMPILED_DATA Unit () () #-}
postulate
IO : Set → Set
{-# COMPILED_TYPE IO IO #-}
{-# BUILTIN IO IO #-}
postulate
putStrLn : ∞ String → IO Unit
{-# COMPILED putStrLn putStrLn #-}
main = putStrLn (♯ "a")
| {
"alphanum_fraction": 0.5963687151,
"avg_line_length": 15.2340425532,
"ext": "agda",
"hexsha": "d21aec8ae764fa85f2270062f79ea0cd98c45cc1",
"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/CompilingCoinduction.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/CompilingCoinduction.agda",
"max_line_length": 38,
"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/CompilingCoinduction.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": 210,
"size": 716
} |
------------------------------------------------------------------------
-- Indexed monads
------------------------------------------------------------------------
-- Note that currently the monad laws are not included here.
module Category.Monad.Indexed where
open import Data.Function
open import Category.Applicative.Indexed
record RawIMonad {I : Set} (M : IFun I) : Set₁ where
infixl 1 _>>=_ _>>_
infixr 1 _=<<_
field
return : ∀ {i A} → A → M i i A
_>>=_ : ∀ {i j k A B} → M i j A → (A → M j k B) → M i k B
_>>_ : ∀ {i j k A B} → M i j A → M j k B → M i k B
m₁ >> m₂ = m₁ >>= λ _ → m₂
_=<<_ : ∀ {i j k A B} → (A → M j k B) → M i j A → M i k B
f =<< c = c >>= f
join : ∀ {i j k A} → M i j (M j k A) → M i k A
join m = m >>= id
rawIApplicative : RawIApplicative M
rawIApplicative = record
{ pure = return
; _⊛_ = λ f x → f >>= λ f' → x >>= λ x' → return (f' x')
}
open RawIApplicative rawIApplicative public
record RawIMonadZero {I : Set} (M : IFun I) : Set₁ where
field
monad : RawIMonad M
∅ : ∀ {i j A} → M i j A
open RawIMonad monad public
record RawIMonadPlus {I : Set} (M : IFun I) : Set₁ where
infixr 3 _∣_
field
monadZero : RawIMonadZero M
_∣_ : ∀ {i j A} → M i j A → M i j A → M i j A
open RawIMonadZero monadZero public
| {
"alphanum_fraction": 0.4935945742,
"avg_line_length": 26.0196078431,
"ext": "agda",
"hexsha": "86d2622654f1a585f948bd364e4a148dbeb9a5b5",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Category/Monad/Indexed.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Category/Monad/Indexed.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Category/Monad/Indexed.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": 482,
"size": 1327
} |
module Data.HSTrie where
open import Class.Map
open import Data.List
open import Data.String
open import Data.String.Instance
open import Data.Maybe
private
variable
A B : Set
{-#
FOREIGN GHC
import Data.Trie
import Data.Text.Encoding
#-}
postulate
HSTrie : Set -> Set
emptyTrie : HSTrie A
insertTrie : String -> A -> HSTrie A -> HSTrie A
deleteTrie : String -> HSTrie A -> HSTrie A
lookupTrie : String -> HSTrie A -> Maybe A
fmapTrie : (A -> B) -> HSTrie A -> HSTrie B
trieKeysPrim : HSTrie A -> List String
submapTrie : String -> HSTrie A -> HSTrie A
{-# COMPILE GHC HSTrie = type Trie #-}
{-# COMPILE GHC emptyTrie = \ _ -> empty #-}
{-# COMPILE GHC insertTrie = \ _ s -> insert (encodeUtf8 s) #-}
{-# COMPILE GHC deleteTrie = \ _ s -> delete (encodeUtf8 s) #-}
{-# COMPILE GHC lookupTrie = \ _ s -> Data.Trie.lookup (encodeUtf8 s) #-}
{-# COMPILE GHC fmapTrie = \ _ _ -> fmap #-}
{-# COMPILE GHC trieKeysPrim = \ _ -> fmap decodeUtf8 . keys #-}
{-# COMPILE GHC submapTrie = \ _ s -> submap (encodeUtf8 s) #-}
instance
NDTrie-Map : MapClass String HSTrie
NDTrie-Map = record
{ insert = insertTrie
; remove = deleteTrie
; lookup = lookupTrie
; mapSnd = fmapTrie
; emptyMap = emptyTrie
}
trieKeys : HSTrie A -> List String
trieKeys = trieKeysPrim
lookupHSTrie : String -> HSTrie A -> HSTrie A
lookupHSTrie = submapTrie
| {
"alphanum_fraction": 0.6367461431,
"avg_line_length": 26.9056603774,
"ext": "agda",
"hexsha": "3513b4b2a0503a25a4a8b5a1b7de052dd0090f50",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-10-20T10:46:20.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-27T23:12:48.000Z",
"max_forks_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "WhatisRT/meta-cedille",
"max_forks_repo_path": "stdlib-exts/Data/HSTrie.agda",
"max_issues_count": 10,
"max_issues_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_issues_repo_issues_event_max_datetime": "2020-04-25T15:29:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-13T17:44:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "WhatisRT/meta-cedille",
"max_issues_repo_path": "stdlib-exts/Data/HSTrie.agda",
"max_line_length": 73,
"max_stars_count": 35,
"max_stars_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "WhatisRT/meta-cedille",
"max_stars_repo_path": "stdlib-exts/Data/HSTrie.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-12T22:59:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-13T07:44:50.000Z",
"num_tokens": 446,
"size": 1426
} |
------------------------------------------------------------------------------
-- Equivalence: N as the least fixed-point and N using Agda's data constructor
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LFPs.N where
open import FOTC.Base
open import FOTC.Base.PropertiesI
------------------------------------------------------------------------------
-- Auxiliary definitions and properties
flip : {A B C : Set} → (A → B → C) → B → A → C
flip f b a = f a b
cong : (f : D → D) → ∀ {x y} → x ≡ y → f x ≡ f y
cong f refl = refl
------------------------------------------------------------------------------
module LFP where
infixl 9 _+_
-- N is a least fixed-point of a functor
-- The functor.
NatF : (D → Set) → D → Set
NatF A n = n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ A n')
-- The natural numbers are the least fixed-point of NatF.
postulate
N : D → Set
-- N is a pre-fixed point of NatF, i.e.
--
-- NatF N ≤ N.
--
-- Peter: It corresponds to the introduction rules.
N-in : ∀ {n} → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ N n') → N n
-- The higher-order version.
N-in-ho : ∀ {n} → NatF N n → N n
-- N is the least pre-fixed point of NatF, i.e.
--
-- ∀ A. NatF A ≤ A ⇒ N ≤ A.
--
-- Peter: It corresponds to the elimination rule of an inductively
-- defined predicate.
N-ind :
(A : D → Set) →
(∀ {n} → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ A n') → A n) →
∀ {n} → N n → A n
-- Higher-order version.
N-ind-ho :
(A : D → Set) → (∀ {n} → NatF A n → A n) → ∀ {n} → N n → A n
----------------------------------------------------------------------------
-- N-in and N-in-ho are equivalents
N-in₁ : ∀ {n} → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ N n') → N n
N-in₁ = N-in-ho
N-in-ho₁ : ∀ {n} → NatF N n → N n
N-in-ho₁ = N-in₁
----------------------------------------------------------------------------
-- N-ind and N-ind-ho are equivalents
N-ind-fo :
(A : D → Set) →
(∀ {n} → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ A n') → A n) →
∀ {n} → N n → A n
N-ind-fo = N-ind-ho
N-ind-ho' :
(A : D → Set) → (∀ {n} → NatF A n → A n) → ∀ {n} → N n → A n
N-ind-ho' = N-ind
----------------------------------------------------------------------------
-- The data constructors of N.
nzero : N zero
nzero = N-in (inj₁ refl)
nsucc : ∀ {n} → N n → N (succ₁ n)
nsucc Nn = N-in (inj₂ (_ , refl , Nn))
----------------------------------------------------------------------------
-- Because N is the least pre-fixed point of NatF (i.e. N-in and
-- N-ind), we can proof that N is also a post-fixed point of NatF.
-- N is a post-fixed point of NatF.
N-out : ∀ {n} → N n → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ N n')
N-out = N-ind A h
where
A : D → Set
A m = m ≡ zero ∨ (∃[ m' ] m ≡ succ₁ m' ∧ N m')
h : ∀ {m} → m ≡ zero ∨ (∃[ m' ] m ≡ succ₁ m' ∧ A m') → A m
h (inj₁ m≡0) = inj₁ m≡0
h (inj₂ (m' , prf , Am')) = inj₂ (m' , prf , helper Am')
where
helper : A m' → N m'
helper (inj₁ prf') = subst N (sym prf') nzero
helper (inj₂ (m'' , prf' , Am'')) = subst N (sym prf') (nsucc Am'')
-- The higher-order version.
N-out-ho : ∀ {n} → N n → NatF N n
N-out-ho = N-out
----------------------------------------------------------------------------
-- The induction principle for N *with* the hypothesis N n in the
-- induction step using N-ind.
N-ind₁ : (A : D → Set) →
A zero →
(∀ {n} → N n → A n → A (succ₁ n)) →
∀ {n} → N n → A n
N-ind₁ A A0 h Nn = ∧-proj₂ (N-ind B h' Nn)
where
B : D → Set
B n = N n ∧ A n
h' : ∀ {m} → m ≡ zero ∨ (∃[ m' ] m ≡ succ₁ m' ∧ B m') → B m
h' (inj₁ m≡0) = subst B (sym m≡0) (nzero , A0)
h' (inj₂ (m' , prf , Nm' , Am')) =
(subst N (sym prf) (nsucc Nm')) , subst A (sym prf) (h Nm' Am')
----------------------------------------------------------------------------
-- The induction principle for N *without* the hypothesis N n in the
-- induction step using N-ind
N-ind₂ : (A : D → Set) →
A zero →
(∀ {n} → A n → A (succ₁ n)) →
∀ {n} → N n → A n
N-ind₂ A A0 h = N-ind A h'
where
h' : ∀ {m} → m ≡ zero ∨ (∃[ m' ] m ≡ succ₁ m' ∧ A m') → A m
h' (inj₁ m≡0) = subst A (sym m≡0) A0
h' (inj₂ (m' , prf , Am')) = subst A (sym prf) (h Am')
----------------------------------------------------------------------------
-- Example: We will use N-ind as the induction principle on N.
postulate
_+_ : D → D → D
+-0x : ∀ d → zero + d ≡ d
+-Sx : ∀ d e → (succ₁ d) + e ≡ succ₁ (d + e)
+-leftIdentity : ∀ n → zero + n ≡ n
+-leftIdentity n = +-0x n
+-N : ∀ {m n} → N m → N n → N (m + n)
+-N {n = n} Nm Nn = N-ind A h Nm
where
A : D → Set
A i = N (i + n)
h : ∀ {m} → m ≡ zero ∨ (∃[ m' ] m ≡ succ₁ m' ∧ A m') → A m
h (inj₁ m≡0) = subst N (cong (flip _+_ n) (sym m≡0)) A0
where
A0 : A zero
A0 = subst N (sym (+-leftIdentity n)) Nn
h (inj₂ (m' , prf , Am')) =
subst N (cong (flip _+_ n) (sym prf)) (is Am')
where
is : ∀ {i} → A i → A (succ₁ i)
is {i} Ai = subst N (sym (+-Sx i n)) (nsucc Ai)
----------------------------------------------------------------------------
-- Example: A proof using N-out.
pred-N : ∀ {n} → N n → N (pred₁ n)
pred-N {n} Nn = case h₁ h₂ (N-out Nn)
where
h₁ : n ≡ zero → N (pred₁ n)
h₁ n≡0 = subst N (sym (trans (predCong n≡0) pred-0)) nzero
h₂ : ∃[ n' ] n ≡ succ₁ n' ∧ N n' → N (pred₁ n)
h₂ (n' , prf , Nn') = subst N (sym (trans (predCong prf) (pred-S n'))) Nn'
----------------------------------------------------------------------------
-- From/to N as a least fixed-point to/from N as data type.
data N' : D → Set where
nzero' : N' zero
nsucc' : ∀ {n} → N' n → N' (succ₁ n)
N'→N : ∀ {n} → N' n → N n
N'→N nzero' = nzero
N'→N (nsucc' Nn) = nsucc (N'→N Nn)
-- Using N-ind₁.
N→N' : ∀ {n} → N n → N' n
N→N' = N-ind₁ N' nzero' (λ _ → nsucc')
-- Using N-ind₂.
N→N'₁ : ∀ {n} → N n → N' n
N→N'₁ = N-ind₂ N' nzero' nsucc'
------------------------------------------------------------------------------
module Data where
data N : D → Set where
nzero : N zero
nsucc : ∀ {n} → N n → N (succ₁ n)
-- The induction principle for N *with* the hypothesis N n in the
-- induction step.
N-ind₁ : (A : D → Set) →
A zero →
(∀ {n} → N n → A n → A (succ₁ n)) →
∀ {n} → N n → A n
N-ind₁ A A0 h nzero = A0
N-ind₁ A A0 h (nsucc Nn) = h Nn (N-ind₁ A A0 h Nn)
-- The induction principle for N *without* the hypothesis N n in the
-- induction step.
N-ind₂ : (A : D → Set) →
A zero →
(∀ {n} → A n → A (succ₁ n)) →
∀ {n} → N n → A n
N-ind₂ A A0 h nzero = A0
N-ind₂ A A0 h (nsucc Nn) = h (N-ind₂ A A0 h Nn)
----------------------------------------------------------------------------
-- N-in.
N-in : ∀ {n} → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ N n') → N n
N-in {n} h = case prf₁ prf₂ h
where
prf₁ : n ≡ zero → N n
prf₁ n≡0 = subst N (sym n≡0) nzero
prf₂ : ∃[ n' ] n ≡ succ₁ n' ∧ N n' → N n
prf₂ (n' , prf , Nn') = subst N (sym prf) (nsucc Nn')
----------------------------------------------------------------------------
-- From N-ind₂ to N-ind.
N-ind' :
(A : D → Set) →
(∀ {n} → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ A n') → A n) →
∀ {n} → N n → A n
N-ind' A h = N-ind₂ A h₁ h₂
where
h₁ : A zero
h₁ = h (inj₁ refl)
h₂ : ∀ {m} → A m → A (succ₁ m)
h₂ {m} Am = h (inj₂ (m , refl , Am))
| {
"alphanum_fraction": 0.3892464975,
"avg_line_length": 30.5907335907,
"ext": "agda",
"hexsha": "cfad34fa139d7e68c1c0adf99c81654442191c9d",
"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": "notes/fixed-points/LFPs/N.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": "notes/fixed-points/LFPs/N.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": "notes/fixed-points/LFPs/N.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": 2832,
"size": 7923
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.