hexsha
stringlengths 40
40
| size
int64 3
1.05M
| ext
stringclasses 163
values | lang
stringclasses 53
values | max_stars_repo_path
stringlengths 3
945
| max_stars_repo_name
stringlengths 4
112
| max_stars_repo_head_hexsha
stringlengths 40
78
| max_stars_repo_licenses
listlengths 1
10
| max_stars_count
float64 1
191k
⌀ | max_stars_repo_stars_event_min_datetime
stringlengths 24
24
⌀ | max_stars_repo_stars_event_max_datetime
stringlengths 24
24
⌀ | max_issues_repo_path
stringlengths 3
945
| max_issues_repo_name
stringlengths 4
113
| max_issues_repo_head_hexsha
stringlengths 40
78
| max_issues_repo_licenses
listlengths 1
10
| max_issues_count
float64 1
116k
⌀ | max_issues_repo_issues_event_min_datetime
stringlengths 24
24
⌀ | max_issues_repo_issues_event_max_datetime
stringlengths 24
24
⌀ | max_forks_repo_path
stringlengths 3
945
| max_forks_repo_name
stringlengths 4
113
| max_forks_repo_head_hexsha
stringlengths 40
78
| max_forks_repo_licenses
listlengths 1
10
| max_forks_count
float64 1
105k
⌀ | max_forks_repo_forks_event_min_datetime
stringlengths 24
24
⌀ | max_forks_repo_forks_event_max_datetime
stringlengths 24
24
⌀ | content
stringlengths 3
1.05M
| avg_line_length
float64 1
966k
| max_line_length
int64 1
977k
| alphanum_fraction
float64 0
1
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
38f6a06370610af26b0777e5ed5f4221debf43f8
| 5,395
|
agda
|
Agda
|
Cubical/Algebra/DirectSum/DirectSumHIT/Properties.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/DirectSum/DirectSumHIT/Properties.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/DirectSum/DirectSumHIT/Properties.agda
|
thomas-lamiaux/cubical
|
58c0b83bb0fed0dc683f3d29b1709effe51c1689
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Algebra.DirectSum.DirectSumHIT.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Sigma
open import Cubical.Relation.Nullary
open import Cubical.Algebra.Group
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.DirectSum.DirectSumHIT.Base
private variable
ℓ ℓ' : Level
module AbGroupProperties
(Idx : Type ℓ)
(P : Idx → Type ℓ')
(AGP : (r : Idx) → AbGroupStr (P r))
where
inv : ⊕HIT Idx P AGP → ⊕HIT Idx P AGP
inv = DS-Rec-Set.f Idx P AGP (⊕HIT Idx P AGP) trunc
-- elements
neutral
(λ r a → base r (AbGroupStr.-_ (AGP r) a))
(λ xs ys → xs add ys)
-- eq group
(λ xs ys zs → addAssoc xs ys zs)
(λ xs → addRid xs)
(λ xs ys → addComm xs ys)
-- eq base
(λ r → let open AbGroupStr (AGP r) in
let open GroupTheory (P r , AbGroupStr→GroupStr (AGP r)) in
(cong (base r) inv1g) ∙ (base-neutral r))
(λ r a b → let open AbGroupStr (AGP r) in
let open GroupTheory (P r , AbGroupStr→GroupStr (AGP r)) in
((base r (- a) add base r (- b)) ≡⟨ (base-add r (- a) (- b)) ⟩
base r ((- a) + (- b)) ≡⟨ (cong (base r) (sym (invDistr b a))) ⟩
base r (- (b + a)) ≡⟨ cong (base r) (cong (-_) (+Comm b a)) ⟩
base r (- (a + b)) ∎))
rinv : (z : ⊕HIT Idx P AGP) → z add (inv z) ≡ neutral
rinv = DS-Ind-Prop.f Idx P AGP (λ z → z add (inv z) ≡ neutral) (λ _ → trunc _ _)
-- elements
(addRid neutral)
(λ r a → let open AbGroupStr (AGP r) in
((base r a add base r (- a)) ≡⟨ base-add r a (- a) ⟩
base r (a + - a) ≡⟨ cong (base r) (+InvR a) ⟩
base r 0g ≡⟨ base-neutral r ⟩
neutral ∎))
(λ {x} {y} p q →
(((x add y) add ((inv x) add (inv y))) ≡⟨ cong (λ X → X add ((inv x) add (inv y))) (addComm x y) ⟩
((y add x) add (inv x add inv y)) ≡⟨ sym (addAssoc y x (inv x add inv y)) ⟩
(y add (x add (inv x add inv y))) ≡⟨ cong (λ X → y add X) (addAssoc x (inv x) (inv y)) ⟩
(y add ((x add inv x) add inv y)) ≡⟨ cong (λ X → y add (X add (inv y))) (p) ⟩
(y add (neutral add inv y)) ≡⟨ cong (λ X → y add X) (addComm neutral (inv y)) ⟩
(y add (inv y add neutral)) ≡⟨ cong (λ X → y add X) (addRid (inv y)) ⟩
(y add inv y) ≡⟨ q ⟩
neutral ∎))
module SubstLemma
(Idx : Type ℓ)
(G : Idx → Type ℓ')
(Gstr : (r : Idx) → AbGroupStr (G r))
where
open AbGroupStr
subst0g : {l k : Idx} → (p : l ≡ k) → subst G p (0g (Gstr l)) ≡ 0g (Gstr k)
subst0g {l} {k} p = J (λ k p → subst G p (0g (Gstr l)) ≡ 0g (Gstr k)) (transportRefl _) p
subst+ : {l : Idx} → (a b : G l) → {k : Idx} → (p : l ≡ k) →
Gstr k ._+_ (subst G p a) (subst G p b) ≡ subst G p (Gstr l ._+_ a b)
subst+ {l} a b {k} p = J (λ k p → Gstr k ._+_ (subst G p a) (subst G p b) ≡ subst G p (Gstr l ._+_ a b))
(cong₂ (Gstr l ._+_) (transportRefl _) (transportRefl _) ∙ sym (transportRefl _))
p
module DecIndec-BaseProperties
(Idx : Type ℓ)
(decIdx : Discrete Idx)
(G : Idx → Type ℓ')
(Gstr : (r : Idx) → AbGroupStr (G r))
where
open AbGroupStr
open SubstLemma Idx G Gstr
πₖ : (k : Idx) → ⊕HIT Idx G Gstr → G k
πₖ k = DS-Rec-Set.f _ _ _ _ (is-set (Gstr k))
(0g (Gstr k))
base-trad
(_+_ (Gstr k))
(+Assoc (Gstr k))
(+IdR (Gstr k))
(+Comm (Gstr k))
base-neutral-eq
base-add-eq
where
base-trad : (l : Idx) → (a : G l) → G k
base-trad l a with decIdx l k
... | yes p = subst G p a
... | no ¬p = 0g (Gstr k)
base-neutral-eq : _
base-neutral-eq l with decIdx l k
... | yes p = subst0g p
... | no ¬p = refl
base-add-eq : _
base-add-eq l a b with decIdx l k
... | yes p = subst+ a b p
... | no ¬p = +IdR (Gstr k) _
πₖ-id : {k : Idx} → (a : G k) → πₖ k (base k a) ≡ a
πₖ-id {k} a with decIdx k k
... | yes p = cong (λ X → subst G X a) (Discrete→isSet decIdx _ _ _ _) ∙ transportRefl _
... | no ¬p = rec (¬p refl)
πₖ-0g : {k l : Idx} → (a : G l) → (p : k ≡ l → ⊥) → πₖ k (base l a) ≡ 0g (Gstr k)
πₖ-0g {k} {l} a ¬q with decIdx l k
... | yes p = rec (¬q (sym p))
... | no ¬p = refl
base-inj : {k : Idx} → {a b : G k} → base {AGP = Gstr} k a ≡ base k b → a ≡ b
base-inj {k} {a} {b} p = sym (πₖ-id a) ∙ cong (πₖ k) p ∙ πₖ-id b
base-≢ : {k : Idx} → {a : G k} → {l : Idx} → {b : G l} → (p : k ≡ l → ⊥) →
base {AGP = Gstr} k a ≡ base {AGP = Gstr} l b → (a ≡ 0g (Gstr k)) × (b ≡ 0g (Gstr l))
base-≢ {k} {a} {l} {b} ¬p q = helper1 , helper2
where
helper1 : a ≡ 0g (Gstr k)
helper1 = sym (πₖ-id a) ∙ cong (πₖ k) q ∙ πₖ-0g b ¬p
helper2 : b ≡ 0g (Gstr l)
helper2 = sym (πₖ-id b) ∙ cong (πₖ l) (sym q) ∙ πₖ-0g a (λ x → ¬p (sym x))
| 38.262411
| 124
| 0.457461
|
21745cd3dd0658a48c528e6cfec7f08eedbaef17
| 12,046
|
agda
|
Agda
|
Agda/06-universes.agda
|
hemangandhi/HoTT-Intro
|
09c710bf9c31ba88be144cc950bd7bc19c22a934
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/06-universes.agda
|
hemangandhi/HoTT-Intro
|
09c710bf9c31ba88be144cc950bd7bc19c22a934
|
[
"CC-BY-4.0"
] | null | null | null |
Agda/06-universes.agda
|
hemangandhi/HoTT-Intro
|
09c710bf9c31ba88be144cc950bd7bc19c22a934
|
[
"CC-BY-4.0"
] | null | null | null |
{-# OPTIONS --without-K --exact-split --allow-unsolved-metas #-}
module 06-universes where
import 05-identity-types
open 05-identity-types public
-- Section 6.3 Pointed types
-- Definition 6.3.1
UU-pt : (i : Level) → UU (lsuc i)
UU-pt i = Σ (UU i) (λ X → X)
type-UU-pt : {i : Level} → UU-pt i → UU i
type-UU-pt = pr1
pt-UU-pt : {i : Level} (A : UU-pt i) → type-UU-pt A
pt-UU-pt = pr2
-- Definition 6.3.2
_→*_ : {i j : Level} → UU-pt i → UU-pt j → UU-pt (i ⊔ j)
A →* B =
pair
( Σ (type-UU-pt A → type-UU-pt B) (λ f → Id (f (pt-UU-pt A)) (pt-UU-pt B)))
( pair
( const (type-UU-pt A) (type-UU-pt B) (pt-UU-pt B))
( refl))
-- Definition 6.3.3
Ω : {i : Level} → UU-pt i → UU-pt i
Ω A = pair (Id (pt-UU-pt A) (pt-UU-pt A)) refl
-- Definition 6.3.4
iterated-loop-space : {i : Level} → ℕ → UU-pt i → UU-pt i
iterated-loop-space zero-ℕ A = A
iterated-loop-space (succ-ℕ n) A = Ω (iterated-loop-space n A)
-- Section 6.4 Families and relations on the natural numbers
-- Definition 6.4.1
Fin : ℕ → UU lzero
Fin zero-ℕ = empty
Fin (succ-ℕ n) = coprod (Fin n) unit
-- Definition 6.4.2
-- Observational equality on the natural numbers
Eq-ℕ : ℕ → (ℕ → UU lzero)
Eq-ℕ zero-ℕ zero-ℕ = 𝟙
Eq-ℕ zero-ℕ (succ-ℕ n) = 𝟘
Eq-ℕ (succ-ℕ m) zero-ℕ = 𝟘
Eq-ℕ (succ-ℕ m) (succ-ℕ n) = Eq-ℕ m n
-- Lemma 6.4.3
refl-Eq-ℕ : (n : ℕ) → Eq-ℕ n n
refl-Eq-ℕ zero-ℕ = star
refl-Eq-ℕ (succ-ℕ n) = refl-Eq-ℕ n
succ-relation-ℕ :
{i : Level} (R : ℕ → ℕ → UU i) → ℕ → ℕ → UU i
succ-relation-ℕ R m n = R (succ-ℕ m) (succ-ℕ n)
succ-reflexivity-ℕ :
{i : Level} (R : ℕ → ℕ → UU i) (ρ : (n : ℕ) → R n n) →
(n : ℕ) → succ-relation-ℕ R n n
succ-reflexivity-ℕ R ρ n = ρ (succ-ℕ n)
{- In the book we suggest that first the order of the variables should be
swapped, in order to make the inductive hypothesis stronger. Agda's pattern
matching mechanism allows us to bypass this step and give a more direct
construction. -}
least-reflexive-Eq-ℕ :
{i : Level} (R : ℕ → ℕ → UU i) (ρ : (n : ℕ) → R n n) →
(m n : ℕ) → Eq-ℕ m n → R m n
least-reflexive-Eq-ℕ R ρ zero-ℕ zero-ℕ star = ρ zero-ℕ
least-reflexive-Eq-ℕ R ρ zero-ℕ (succ-ℕ n) ()
least-reflexive-Eq-ℕ R ρ (succ-ℕ m) zero-ℕ ()
least-reflexive-Eq-ℕ R ρ (succ-ℕ m) (succ-ℕ n) e =
least-reflexive-Eq-ℕ (succ-relation-ℕ R) (succ-reflexivity-ℕ R ρ) m n e
-- Exercises
-- Exercise 6.1
{- In this exercise we were asked to show that the observational equality on ℕ
is an equivalence relation. -}
symmetric-Eq-ℕ : (m n : ℕ) → Eq-ℕ m n → Eq-ℕ n m
symmetric-Eq-ℕ zero-ℕ zero-ℕ star = star
symmetric-Eq-ℕ (succ-ℕ m) (succ-ℕ n) t = symmetric-Eq-ℕ m n t
transitive-Eq-ℕ : (l m n : ℕ) → Eq-ℕ l m → Eq-ℕ m n → Eq-ℕ l n
transitive-Eq-ℕ zero-ℕ zero-ℕ zero-ℕ p q = star
transitive-Eq-ℕ (succ-ℕ l) (succ-ℕ m) (succ-ℕ n) p q =
transitive-Eq-ℕ l m n p q
-- Exercise 6.2
{- In this exercise we were asked to show that any function on the natural
numbers preserves observational equality. The quick solution uses the fact
that observational equality is the least reflexive relation. -}
preserve_Eq-ℕ : (f : ℕ → ℕ) (n m : ℕ) → (Eq-ℕ n m) → (Eq-ℕ (f n) (f m))
preserve_Eq-ℕ f =
least-reflexive-Eq-ℕ
( λ x y → Eq-ℕ (f x) (f y))
( λ x → refl-Eq-ℕ (f x))
-- Exercise 6.3
{- In this exercise we were asked to construct the relations ≤ and < on the
natural numbers, and show basic properties about them. -}
-- Exercise 6.3(a)
-- The definition of ≤
leq-ℕ : ℕ → ℕ → UU lzero
leq-ℕ zero-ℕ m = unit
leq-ℕ (succ-ℕ n) zero-ℕ = empty
leq-ℕ (succ-ℕ n) (succ-ℕ m) = leq-ℕ n m
_≤_ = leq-ℕ
leq-zero-ℕ :
(n : ℕ) → leq-ℕ zero-ℕ n
leq-zero-ℕ n = star
-- The definition of <
le-ℕ : ℕ → ℕ → UU lzero
le-ℕ m zero-ℕ = empty
le-ℕ zero-ℕ (succ-ℕ m) = unit
le-ℕ (succ-ℕ n) (succ-ℕ m) = le-ℕ n m
_<_ = le-ℕ
reflexive-leq-ℕ : (n : ℕ) → n ≤ n
reflexive-leq-ℕ zero-ℕ = star
reflexive-leq-ℕ (succ-ℕ n) = reflexive-leq-ℕ n
anti-reflexive-le-ℕ : (n : ℕ) → ¬ (n < n)
anti-reflexive-le-ℕ zero-ℕ = ind-empty
anti-reflexive-le-ℕ (succ-ℕ n) = anti-reflexive-le-ℕ n
transitive-leq-ℕ :
(n m l : ℕ) → (n ≤ m) → (m ≤ l) → (n ≤ l)
transitive-leq-ℕ zero-ℕ m l p q = star
transitive-leq-ℕ (succ-ℕ n) (succ-ℕ m) (succ-ℕ l) p q =
transitive-leq-ℕ n m l p q
transitive-le-ℕ : (n m l : ℕ) → (le-ℕ n m) → (le-ℕ m l) → (le-ℕ n l)
transitive-le-ℕ zero-ℕ (succ-ℕ m) (succ-ℕ l) p q = star
transitive-le-ℕ (succ-ℕ n) (succ-ℕ m) (succ-ℕ l) p q =
transitive-le-ℕ n m l p q
succ-leq-ℕ : (n : ℕ) → leq-ℕ n (succ-ℕ n)
succ-leq-ℕ zero-ℕ = star
succ-leq-ℕ (succ-ℕ n) = succ-leq-ℕ n
succ-le-ℕ : (n : ℕ) → le-ℕ n (succ-ℕ n)
succ-le-ℕ zero-ℕ = star
succ-le-ℕ (succ-ℕ n) = succ-le-ℕ n
anti-symmetric-leq-ℕ : (m n : ℕ) → leq-ℕ m n → leq-ℕ n m → Id m n
anti-symmetric-leq-ℕ zero-ℕ zero-ℕ p q = refl
anti-symmetric-leq-ℕ (succ-ℕ m) (succ-ℕ n) p q =
ap succ-ℕ (anti-symmetric-leq-ℕ m n p q)
anti-symmetric-le-ℕ : (m n : ℕ) → le-ℕ m n → le-ℕ n m → Id m n
anti-symmetric-le-ℕ (succ-ℕ m) (succ-ℕ n) p q =
ap succ-ℕ (anti-symmetric-le-ℕ m n p q)
-- Exercise 6.5
{- In this exercise we were asked to construct observational equality on the
booleans. This construction is analogous to, but simpler than, the
construction of observational equality on the natural numbers. -}
Eq-𝟚 : bool → bool → UU lzero
Eq-𝟚 true true = unit
Eq-𝟚 true false = empty
Eq-𝟚 false true = empty
Eq-𝟚 false false = unit
reflexive-Eq-𝟚 : (x : bool) → Eq-𝟚 x x
reflexive-Eq-𝟚 true = star
reflexive-Eq-𝟚 false = star
least-reflexive-Eq-𝟚 : {i : Level}
(R : bool → bool → UU i) (ρ : (x : bool) → R x x)
(x y : bool) → Eq-𝟚 x y → R x y
least-reflexive-Eq-𝟚 R ρ true true p = ρ true
least-reflexive-Eq-𝟚 R ρ true false p = ind-empty p
least-reflexive-Eq-𝟚 R ρ false true p = ind-empty p
least-reflexive-Eq-𝟚 R ρ false false p = ρ false
-- Exercise 6.6
{- In this exercise we were asked to define the relations ≤ and < on the
integers. As a criterion of correctness, we were then also asked to show
that the type of all integers l satisfying k ≤ l satisfy the induction
principle of the natural numbers. -}
diff-ℤ : ℤ → ℤ → ℤ
diff-ℤ k l = add-ℤ (neg-ℤ k) l
is-non-negative-ℤ : ℤ → UU lzero
is-non-negative-ℤ (inl x) = empty
is-non-negative-ℤ (inr k) = unit
leq-ℤ : ℤ → ℤ → UU lzero
leq-ℤ k l = is-non-negative-ℤ (diff-ℤ k l)
reflexive-leq-ℤ : (k : ℤ) → leq-ℤ k k
reflexive-leq-ℤ k =
tr is-non-negative-ℤ (inv (left-inverse-law-add-ℤ k)) star
is-non-negative-succ-ℤ :
(k : ℤ) → is-non-negative-ℤ k → is-non-negative-ℤ (succ-ℤ k)
is-non-negative-succ-ℤ (inr (inl star)) p = star
is-non-negative-succ-ℤ (inr (inr x)) p = star
is-non-negative-add-ℤ :
(k l : ℤ) →
is-non-negative-ℤ k → is-non-negative-ℤ l → is-non-negative-ℤ (add-ℤ k l)
is-non-negative-add-ℤ (inr (inl star)) (inr (inl star)) p q = star
is-non-negative-add-ℤ (inr (inl star)) (inr (inr n)) p q = star
is-non-negative-add-ℤ (inr (inr zero-ℕ)) (inr (inl star)) p q = star
is-non-negative-add-ℤ (inr (inr (succ-ℕ n))) (inr (inl star)) star star =
is-non-negative-succ-ℤ
( add-ℤ (inr (inr n)) (inr (inl star)))
( is-non-negative-add-ℤ (inr (inr n)) (inr (inl star)) star star)
is-non-negative-add-ℤ (inr (inr zero-ℕ)) (inr (inr m)) star star = star
is-non-negative-add-ℤ (inr (inr (succ-ℕ n))) (inr (inr m)) star star =
is-non-negative-succ-ℤ
( add-ℤ (inr (inr n)) (inr (inr m)))
( is-non-negative-add-ℤ (inr (inr n)) (inr (inr m)) star star)
triangle-diff-ℤ :
(k l m : ℤ) → Id (add-ℤ (diff-ℤ k l) (diff-ℤ l m)) (diff-ℤ k m)
triangle-diff-ℤ k l m =
( associative-add-ℤ (neg-ℤ k) l (diff-ℤ l m)) ∙
( ap
( add-ℤ (neg-ℤ k))
( ( inv (associative-add-ℤ l (neg-ℤ l) m)) ∙
( ( ap (λ x → add-ℤ x m) (right-inverse-law-add-ℤ l)) ∙
( left-unit-law-add-ℤ m))))
transitive-leq-ℤ : (k l m : ℤ) → leq-ℤ k l → leq-ℤ l m → leq-ℤ k m
transitive-leq-ℤ k l m p q =
tr is-non-negative-ℤ
( triangle-diff-ℤ k l m)
( is-non-negative-add-ℤ
( add-ℤ (neg-ℤ k) l)
( add-ℤ (neg-ℤ l) m)
( p)
( q))
succ-leq-ℤ : (k : ℤ) → leq-ℤ k (succ-ℤ k)
succ-leq-ℤ k =
tr is-non-negative-ℤ
( inv
( ( right-successor-law-add-ℤ (neg-ℤ k) k) ∙
( ap succ-ℤ (left-inverse-law-add-ℤ k))))
( star)
leq-ℤ-succ-leq-ℤ : (k l : ℤ) → leq-ℤ k l → leq-ℤ k (succ-ℤ l)
leq-ℤ-succ-leq-ℤ k l p = transitive-leq-ℤ k l (succ-ℤ l) p (succ-leq-ℤ l)
is-positive-ℤ : ℤ → UU lzero
is-positive-ℤ k = is-non-negative-ℤ (pred-ℤ k)
le-ℤ : ℤ → ℤ → UU lzero
le-ℤ (inl zero-ℕ) (inl x) = empty
le-ℤ (inl zero-ℕ) (inr y) = unit
le-ℤ (inl (succ-ℕ x)) (inl zero-ℕ) = unit
le-ℤ (inl (succ-ℕ x)) (inl (succ-ℕ y)) = le-ℤ (inl x) (inl y)
le-ℤ (inl (succ-ℕ x)) (inr y) = unit
le-ℤ (inr x) (inl y) = empty
le-ℤ (inr (inl star)) (inr (inl star)) = empty
le-ℤ (inr (inl star)) (inr (inr x)) = unit
le-ℤ (inr (inr x)) (inr (inl star)) = empty
le-ℤ (inr (inr zero-ℕ)) (inr (inr zero-ℕ)) = empty
le-ℤ (inr (inr zero-ℕ)) (inr (inr (succ-ℕ y))) = unit
le-ℤ (inr (inr (succ-ℕ x))) (inr (inr zero-ℕ)) = empty
le-ℤ (inr (inr (succ-ℕ x))) (inr (inr (succ-ℕ y))) =
le-ℤ (inr (inr x)) (inr (inr y))
-- Extra material
-- We show that ℕ is an ordered semi-ring
leq-eq-ℕ : {m m' n n' : ℕ} → Id m m' → Id n n' → leq-ℕ m n → leq-ℕ m' n'
leq-eq-ℕ refl refl = id
left-law-leq-add-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (add-ℕ m k) (add-ℕ n k)
left-law-leq-add-ℕ zero-ℕ m n = id
left-law-leq-add-ℕ (succ-ℕ k) m n H = left-law-leq-add-ℕ k m n H
right-law-leq-add-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (add-ℕ k m) (add-ℕ k n)
right-law-leq-add-ℕ k m n H =
leq-eq-ℕ
( commutative-add-ℕ m k)
( commutative-add-ℕ n k)
( left-law-leq-add-ℕ k m n H)
preserves-leq-add-ℕ :
{m m' n n' : ℕ} → leq-ℕ m m' → leq-ℕ n n' → leq-ℕ (add-ℕ m n) (add-ℕ m' n')
preserves-leq-add-ℕ {m} {m'} {n} {n'} H K =
transitive-leq-ℕ
( add-ℕ m n)
( add-ℕ m' n)
( add-ℕ m' n')
( left-law-leq-add-ℕ n m m' H)
( right-law-leq-add-ℕ m' n n' K)
right-law-leq-mul-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (mul-ℕ k m) (mul-ℕ k n)
right-law-leq-mul-ℕ zero-ℕ m n H = star
right-law-leq-mul-ℕ (succ-ℕ k) m n H = {!!}
{-
preserves-leq-add-ℕ
{ m = mul-ℕ k m}
{ m' = mul-ℕ k n}
( right-law-leq-mul-ℕ k m n H) H
left-law-leq-mul-ℕ : (k m n : ℕ) → leq-ℕ m n → leq-ℕ (mul-ℕ m k) (mul-ℕ n k)
left-law-leq-mul-ℕ k m n H =
leq-eq-ℕ
( commutative-mul-ℕ k m)
( commutative-mul-ℕ k n)
( right-law-leq-mul-ℕ k m n H)
-- We show that ℤ is an ordered ring
{-
leq-add-ℤ : (m k l : ℤ) → leq-ℤ k l → leq-ℤ (add-ℤ m k) (add-ℤ m l)
leq-add-ℤ (inl zero-ℕ) k l H = {!!}
leq-add-ℤ (inl (succ-ℕ x)) k l H = {!!}
leq-add-ℤ (inr m) k l H = {!!}
-}
-- Section 5.5 Identity systems
succ-fam-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i) →
(m n : ℕ) → Eq-ℕ m n → UU i
succ-fam-Eq-ℕ R m n e = R (succ-ℕ m) (succ-ℕ n) e
succ-refl-fam-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i)
(ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) →
(n : ℕ) → (succ-fam-Eq-ℕ R n n (refl-Eq-ℕ n))
succ-refl-fam-Eq-ℕ R ρ n = ρ (succ-ℕ n)
path-ind-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i)
( ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) →
( m n : ℕ) (e : Eq-ℕ m n) → R m n e
path-ind-Eq-ℕ R ρ zero-ℕ zero-ℕ star = ρ zero-ℕ
path-ind-Eq-ℕ R ρ zero-ℕ (succ-ℕ n) ()
path-ind-Eq-ℕ R ρ (succ-ℕ m) zero-ℕ ()
path-ind-Eq-ℕ R ρ (succ-ℕ m) (succ-ℕ n) e =
path-ind-Eq-ℕ (succ-fam-Eq-ℕ R) (succ-refl-fam-Eq-ℕ R ρ) m n e
comp-path-ind-Eq-ℕ :
{i : Level} (R : (m n : ℕ) → Eq-ℕ m n → UU i)
( ρ : (n : ℕ) → R n n (refl-Eq-ℕ n)) →
( n : ℕ) → Id (path-ind-Eq-ℕ R ρ n n (refl-Eq-ℕ n)) (ρ n)
comp-path-ind-Eq-ℕ R ρ zero-ℕ = refl
comp-path-ind-Eq-ℕ R ρ (succ-ℕ n) =
comp-path-ind-Eq-ℕ (succ-fam-Eq-ℕ R) (succ-refl-fam-Eq-ℕ R ρ) n
-}
{-
-- Graphs
Gph : (i : Level) → UU (lsuc i)
Gph i = Σ (UU i) (λ X → (X → X → (UU i)))
-- Reflexive graphs
rGph : (i : Level) → UU (lsuc i)
rGph i = Σ (UU i) (λ X → Σ (X → X → (UU i)) (λ R → (x : X) → R x x))
-}
-- Exercise 3.7
{- With the construction of the divisibility relation we open the door to basic
number theory. -}
divides : (d n : ℕ) → UU lzero
divides d n = Σ ℕ (λ m → Eq-ℕ (mul-ℕ d m) n)
| 30.0399
| 79
| 0.584343
|
197f2cfcce91b1d4c0df9db971e5bf574a7af0c3
| 617
|
agda
|
Agda
|
test/Succeed/Issue1281.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1281.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1281.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --allow-unsolved-metas #-}
{-# OPTIONS --termination-depth=2 #-}
module _ where
open import Common.Prelude
module A where
mutual
f : Nat → Nat
f zero = zero
f (suc zero) = suc zero
f (suc (suc x)) = g x
g : Nat → Nat
g x = f (suc ?)
-- This should not fail termination checking,
-- as ? := x is a terminating instance.
module B where
mutual
f : Nat → Nat
f zero = zero
f (suc zero) = suc zero
f (suc (suc x)) = g ?
g : Nat → Nat
g x = f (suc x)
-- This should not fail termination checking,
-- as ? := x is a terminating instance.
| 16.236842
| 47
| 0.567261
|
386d0ac7d8cb669a2540e4e5cfecc101ad728a02
| 1,017
|
agda
|
Agda
|
test/Fail/Issue543a.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue543a.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue543a.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, bug found 2011-12-31
{-# OPTIONS --irrelevant-projections #-}
module Issue543a where
import Common.Level
import Common.Irrelevance
open import Common.Equality
data ⊥ : Set where
record ⊤ : Set where
constructor tt
data Bool : Set where
true false : Bool
record Squash (A : Set) : Set where
constructor squash
field
.unsquash : A
open Squash
-- ok:
sqT≡sqF : squash true ≡ squash false
sqT≡sqF = refl
record Inhabited : Set1 where
constructor inhabited
field
Type : Set
elem : Type
open Inhabited
.bad1 : Inhabited
bad1 = inhabited (true ≡ unsquash (squash true)) refl
.bad2 : Inhabited
bad2 = inhabited (unsquash (squash false) ≡ false) refl
infixl 2 _∘_
_∘_ = trans
-- this should not be provable!!
.irrT≡F : true ≡ false
irrT≡F = elem bad1 ∘ cong unsquash sqT≡sqF ∘ elem bad2
-- the rest is easy
T : Bool → Set
T true = ⊤
T false = ⊥
T≠F : true ≡ false → ⊥
T≠F p = subst T p tt
.irr⊥ : ⊥
irr⊥ = T≠F irrT≡F
rel⊥ : .⊥ → ⊥
rel⊥ ()
absurd : ⊥
absurd = rel⊥ irr⊥
| 15.646154
| 55
| 0.662734
|
1238a4771a4da0e0fb0c6bbf6cf0217d83a8ab1c
| 2,227
|
agda
|
Agda
|
cohomology/SuspAdjointLoopIso.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
cohomology/SuspAdjointLoopIso.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
cohomology/SuspAdjointLoopIso.agda
|
UlrikBuchholtz/HoTT-Agda
|
f8fa68bf753d64d7f45556ca09d0da7976709afa
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.PtdAdjoint
open import homotopy.SuspAdjointLoop
open import cohomology.WithCoefficients
module cohomology.SuspAdjointLoopIso where
module SuspAdjointLoopIso {i} where
private
hadj : HomAdjoint {i} {i} Σ⊣Ω.SuspFunctor Σ⊣Ω.LoopFunctor
hadj = counit-unit-to-hom Σ⊣Ω.adj
module A = HomAdjoint hadj
module _ (X Y : Ptd i) where
abstract
pres-comp : (h₁ h₂ : fst (⊙Susp X ⊙→ ⊙Ω Y))
→ –> (A.eq X (⊙Ω Y)) (⊙conc ⊙∘ ⊙×-in h₁ h₂)
== ⊙conc ⊙∘ ⊙×-in (–> (A.eq X (⊙Ω Y)) h₁) (–> (A.eq X (⊙Ω Y)) h₂)
pres-comp h₁ h₂ =
B.nat-cod h₁ h₂ ⊙conc
∙ ap (λ w → w ⊙∘ ⊙×-in (–> (A.eq X (⊙Ω Y)) h₁) (–> (A.eq X (⊙Ω Y)) h₂))
arr2-lemma
where
module A× = RightAdjoint× hadj
module B = RightAdjointBinary hadj
ap2-lemma : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}
(f : A × B → C) {r s : A × B} (p : r == s)
→ ap f p == ap2 (curry f) (ap fst p) (ap snd p)
ap2-lemma f idp = idp
⊙ap2-lemma : ∀ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
(f : fst (X ⊙× Y ⊙→ Z))
→ ⊙ap f == ⊙ap2 f ⊙∘ ⊙×-in (⊙ap ⊙fst) (⊙ap ⊙snd)
⊙ap2-lemma (f , idp) = ⊙λ= (ap2-lemma f) idp
arr2-lemma : B.arr2 ⊙conc == ⊙conc
arr2-lemma =
⊙ap ⊙conc ⊙∘ A×.⊙out _ _
=⟨ ⊙ap2-lemma ⊙conc |in-ctx (λ w → w ⊙∘ A×.⊙out _ _) ⟩
(⊙ap2 ⊙conc ⊙∘ A×.⊙into _ _) ⊙∘ A×.⊙out _ _
=⟨ ⊙∘-assoc (⊙ap2 ⊙conc) (A×.⊙into _ _) (A×.⊙out _ _) ⟩
⊙ap2 ⊙conc ⊙∘ (A×.⊙into _ _ ⊙∘ A×.⊙out _ _)
=⟨ A×.⊙into-out _ _ |in-ctx (λ w → ⊙ap2 ⊙conc ⊙∘ w) ⟩
⊙ap2 ⊙conc
=⟨ ⊙ap2-conc-is-conc ⟩
⊙conc ∎
iso : →Ω-Group (⊙Susp X) Y ≃ᴳ →Ω-Group X (⊙Ω Y)
iso = Trunc-Group-iso
(–> (A.eq X (⊙Ω Y))) pres-comp (snd (A.eq X (⊙Ω Y)))
abstract
nat-dom : {X Y : Ptd i} (f : fst (X ⊙→ Y)) (Z : Ptd i)
→ fst (iso X Z) ∘ᴳ →Ω-Group-dom-act (⊙susp-fmap f) Z
== →Ω-Group-dom-act f (⊙Ω Z) ∘ᴳ fst (iso Y Z)
nat-dom f Z = hom= _ _ $ λ= $ Trunc-elim
(λ _ → =-preserves-level _ Trunc-level)
(λ g → ap [_] (! (A.nat-dom f (⊙Ω Z) g)))
| 34.261538
| 79
| 0.470139
|
37b2806292719dc215f5e6e6d7ad5d17c0f77719
| 8,166
|
agda
|
Agda
|
Algebra/Pregroup.agda
|
wenkokke/agda-pregroup
|
2cc4f28f23cc369d2582ad065739cabfa46ce799
|
[
"MIT"
] | 1
|
2017-03-02T01:23:52.000Z
|
2017-03-02T01:23:52.000Z
|
Algebra/Pregroup.agda
|
pepijnkokke/Algebra.Pregroup
|
2cc4f28f23cc369d2582ad065739cabfa46ce799
|
[
"MIT"
] | null | null | null |
Algebra/Pregroup.agda
|
pepijnkokke/Algebra.Pregroup
|
2cc4f28f23cc369d2582ad065739cabfa46ce799
|
[
"MIT"
] | null | null | null |
open import Level using (Level; suc; zero; _⊔_)
open import Function using (const)
open import Algebra
open import Algebra.Structures
open import Algebra.OrderedMonoid
open import Algebra.FunctionProperties as FunctionProperties using (Op₁; Op₂)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Relation.Binary
open import Relation.Binary.PartialOrderReasoning as ≤-Reasoning using ()
module Algebra.Pregroup where
-- Definition of the properties of left and right contraction and
-- expansion for usage in the below definition of pregroups.
module AdjointProperties {a ℓ} {A : Set a} (_≤_ : Rel A ℓ) (_∙_ : Op₂ A) (ε : A) where
LeftContract : Op₁ A → Set _
LeftContract _ˡ = ∀ x → (x ˡ ∙ x) ≤ ε
LeftExpand : Op₁ A → Set _
LeftExpand _ˡ = ∀ x → ε ≤ (x ∙ x ˡ)
RightContract : Op₁ A → Set _
RightContract _ʳ = ∀ x → (x ∙ x ʳ) ≤ ε
RightExpand : Op₁ A → Set _
RightExpand _ʳ = ∀ x → ε ≤ (x ʳ ∙ x)
-- define shorthand notation for a term being the left/right adjoint
-- of another term, which can be proven to be unique.
_LeftAdjointOf_ : ∀ y x → Set _
_LeftAdjointOf_ y x = (y ∙ x) ≤ ε × ε ≤ (x ∙ y)
_RightAdjointOf_ : ∀ y x → Set _
_RightAdjointOf_ y x = (x ∙ y) ≤ ε × ε ≤ (y ∙ x)
-- Definition of a pregroup, which adds a left and a right adjoint to
-- an ordered monoid.
record IsPregroup {a ℓ₁ ℓ₂} {A : Set a} (≈ : Rel A ℓ₁) (≤ : Rel A ℓ₂)
(∙ : Op₂ A) (ε : A) (ˡ : Op₁ A) (ʳ : Op₁ A) : Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
open AdjointProperties ≤ ∙ ε
field
isOrderedMonoid : IsOrderedMonoid ≈ ≤ ∙ ε
ˡ-cong : ˡ Preserves ≈ ⟶ ≈
ʳ-cong : ʳ Preserves ≈ ⟶ ≈
ˡ-contract : LeftContract ˡ
ˡ-expand : LeftExpand ˡ
ʳ-contract : RightContract ʳ
ʳ-expand : RightExpand ʳ
open IsOrderedMonoid isOrderedMonoid public
open AdjointProperties ≤ ∙ ε public
record Pregroup c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infixl 7 _∙_
infix 4 _≈_
infix 4 _≤_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ₁
_≤_ : Rel Carrier ℓ₂
_∙_ : Op₂ Carrier
_ˡ : Op₁ Carrier
_ʳ : Op₁ Carrier
ε : Carrier
isPregroup : IsPregroup _≈_ _≤_ _∙_ ε _ˡ _ʳ
open IsPregroup isPregroup public
private
-- for usage with ≤-Reasoning
poset : Poset c ℓ₁ ℓ₂
poset = record { isPartialOrder = isPartialOrder }
open ≤-Reasoning poset
-- for usage of substitutivity (which is not defined in IsPregroup)
orderedMonoid : OrderedMonoid _ _ _
orderedMonoid = record { isOrderedMonoid = isOrderedMonoid }
open OrderedMonoid orderedMonoid public using (substitutivity)
ˡ-unique : ∀ {x y} → y LeftAdjointOf x → y ≈ x ˡ
ˡ-unique {x} {y} (y-contract , y-expand) = antisym y≤xˡ xˡ≤y
where
y≤xˡ : y ≤ x ˡ
y≤xˡ =
begin
y ≈⟨ sym (proj₂ identity y) ⟩
y ∙ ε ≤⟨ compatibility ≤-refl (ˡ-expand x) ⟩
y ∙ (x ∙ x ˡ) ≈⟨ sym (assoc y x (x ˡ)) ⟩
(y ∙ x) ∙ x ˡ ≤⟨ compatibility y-contract ≤-refl ⟩
ε ∙ x ˡ ≈⟨ proj₁ identity (x ˡ) ⟩
x ˡ
∎
xˡ≤y : x ˡ ≤ y
xˡ≤y =
begin
x ˡ ≈⟨ sym (proj₂ identity (x ˡ)) ⟩
x ˡ ∙ ε ≤⟨ compatibility ≤-refl y-expand ⟩
x ˡ ∙ (x ∙ y) ≈⟨ sym (assoc (x ˡ) x y) ⟩
(x ˡ ∙ x) ∙ y ≤⟨ compatibility (ˡ-contract x) ≤-refl ⟩
ε ∙ y ≈⟨ proj₁ identity y ⟩
y
∎
ʳ-unique : ∀ {x y} → y RightAdjointOf x → y ≈ x ʳ
ʳ-unique {x} {y} (y-contract , y-expand) = antisym y≤xʳ xʳ≤y
where
xʳ≤y : x ʳ ≤ y
xʳ≤y =
begin
x ʳ ≈⟨ sym (proj₁ identity (x ʳ)) ⟩
ε ∙ x ʳ ≤⟨ compatibility y-expand ≤-refl ⟩
(y ∙ x) ∙ x ʳ ≈⟨ assoc y x (x ʳ) ⟩
y ∙ (x ∙ x ʳ) ≤⟨ compatibility ≤-refl (ʳ-contract x) ⟩
y ∙ ε ≈⟨ proj₂ identity y ⟩
y
∎
y≤xʳ : y ≤ x ʳ
y≤xʳ =
begin
y ≈⟨ sym (proj₁ identity y) ⟩
ε ∙ y ≤⟨ compatibility (ʳ-expand x) ≤-refl ⟩
(x ʳ ∙ x) ∙ y ≈⟨ assoc (x ʳ) x y ⟩
x ʳ ∙ (x ∙ y) ≤⟨ compatibility ≤-refl y-contract ⟩
x ʳ ∙ ε ≈⟨ proj₂ identity (x ʳ) ⟩
x ʳ
∎
ˡ-identity : ε ˡ ≈ ε
ˡ-identity = antisym εˡ≤ε ε≤εˡ
where
εˡ≤ε : ε ˡ ≤ ε
εˡ≤ε =
begin
ε ˡ ≈⟨ sym (proj₂ identity (ε ˡ)) ⟩
ε ˡ ∙ ε ≤⟨ ˡ-contract ε ⟩
ε
∎
ε≤εˡ : ε ≤ ε ˡ
ε≤εˡ =
begin
ε ≤⟨ ˡ-expand ε ⟩
ε ∙ ε ˡ ≈⟨ proj₁ identity (ε ˡ) ⟩
ε ˡ
∎
ʳ-identity : ε ʳ ≈ ε
ʳ-identity = antisym εʳ≤ε ε≤εʳ
where
εʳ≤ε : ε ʳ ≤ ε
εʳ≤ε =
begin
ε ʳ ≈⟨ sym (proj₁ identity (ε ʳ)) ⟩
ε ∙ ε ʳ ≤⟨ ʳ-contract ε ⟩
ε
∎
ε≤εʳ : ε ≤ ε ʳ
ε≤εʳ =
begin
ε ≤⟨ ʳ-expand ε ⟩
ε ʳ ∙ ε ≈⟨ proj₂ identity (ε ʳ) ⟩
ε ʳ
∎
ˡ-distrib : ∀ x y → y ˡ ∙ x ˡ ≈ (x ∙ y) ˡ
ˡ-distrib x y = ˡ-unique ([yˡxˡ][xy]≤ε , ε≤[xy][yˡxˡ])
where
[yˡxˡ][xy]≤ε : (y ˡ ∙ x ˡ) ∙ (x ∙ y) ≤ ε
[yˡxˡ][xy]≤ε =
begin
(y ˡ ∙ x ˡ) ∙ (x ∙ y) ≈⟨ sym (assoc (y ˡ ∙ x ˡ) x y) ⟩
((y ˡ ∙ x ˡ) ∙ x) ∙ y ≈⟨ ∙-cong (assoc (y ˡ) (x ˡ) x) refl ⟩
(y ˡ ∙ (x ˡ ∙ x)) ∙ y ≤⟨ compatibility (compatibility ≤-refl (ˡ-contract x)) ≤-refl ⟩
y ˡ ∙ ε ∙ y ≈⟨ ∙-cong (proj₂ identity (y ˡ)) refl ⟩
y ˡ ∙ y ≤⟨ ˡ-contract y ⟩
ε
∎
ε≤[xy][yˡxˡ] : ε ≤ (x ∙ y) ∙ (y ˡ ∙ x ˡ)
ε≤[xy][yˡxˡ] =
begin
ε ≤⟨ ˡ-expand x ⟩
x ∙ x ˡ ≈⟨ ∙-cong (sym (proj₂ identity x)) refl ⟩
x ∙ ε ∙ x ˡ ≤⟨ compatibility (compatibility ≤-refl (ˡ-expand y)) ≤-refl ⟩
(x ∙ (y ∙ y ˡ) ∙ x ˡ) ≈⟨ ∙-cong (sym (assoc x y (y ˡ))) refl ⟩
((x ∙ y) ∙ y ˡ) ∙ x ˡ ≈⟨ assoc (x ∙ y) (y ˡ) (x ˡ) ⟩
(x ∙ y) ∙ (y ˡ ∙ x ˡ)
∎
ʳ-distrib : ∀ x y → y ʳ ∙ x ʳ ≈ (x ∙ y) ʳ
ʳ-distrib x y = ʳ-unique ([xy][yʳxʳ]≤ε , ε≤[xy][yʳxʳ])
where
[xy][yʳxʳ]≤ε : (x ∙ y) ∙ (y ʳ ∙ x ʳ) ≤ ε
[xy][yʳxʳ]≤ε =
begin
(x ∙ y) ∙ (y ʳ ∙ x ʳ) ≈⟨ sym (assoc (x ∙ y) (y ʳ) (x ʳ)) ⟩
((x ∙ y) ∙ y ʳ) ∙ x ʳ ≈⟨ ∙-cong (assoc x y (y ʳ)) refl ⟩
(x ∙ (y ∙ y ʳ) ∙ x ʳ) ≤⟨ compatibility (compatibility ≤-refl (ʳ-contract y)) ≤-refl ⟩
x ∙ ε ∙ x ʳ ≈⟨ ∙-cong (proj₂ identity x) refl ⟩
x ∙ x ʳ ≤⟨ ʳ-contract x ⟩
ε
∎
ε≤[xy][yʳxʳ] : ε ≤ (y ʳ ∙ x ʳ) ∙ (x ∙ y)
ε≤[xy][yʳxʳ] =
begin
ε ≤⟨ ʳ-expand y ⟩
y ʳ ∙ y ≈⟨ ∙-cong refl (sym (proj₁ identity y)) ⟩
y ʳ ∙ (ε ∙ y) ≤⟨ compatibility ≤-refl (compatibility (ʳ-expand x) ≤-refl) ⟩
y ʳ ∙ ((x ʳ ∙ x) ∙ y) ≈⟨ ∙-cong refl (assoc (x ʳ) x y) ⟩
y ʳ ∙ (x ʳ ∙ (x ∙ y)) ≈⟨ sym (assoc (y ʳ) (x ʳ) (x ∙ y)) ⟩
(y ʳ ∙ x ʳ) ∙ (x ∙ y)
∎
ˡ-contra : ∀ {x y} → x ≤ y → y ˡ ≤ x ˡ
ˡ-contra {x} {y} x≤y =
begin
y ˡ ≈⟨ sym (proj₂ identity (y ˡ)) ⟩
y ˡ ∙ ε ≤⟨ compatibility ≤-refl (ˡ-expand x) ⟩
y ˡ ∙ (x ∙ x ˡ) ≈⟨ sym (assoc (y ˡ) x (x ˡ)) ⟩
(y ˡ ∙ x) ∙ x ˡ ≤⟨ substitutivity x≤y ⟩
(y ˡ ∙ y) ∙ x ˡ ≤⟨ compatibility (ˡ-contract y) ≤-refl ⟩
ε ∙ x ˡ ≈⟨ proj₁ identity (x ˡ) ⟩
x ˡ
∎
ʳ-contra : ∀ {x y} → x ≤ y → y ʳ ≤ x ʳ
ʳ-contra {x} {y} x≤y =
begin
y ʳ ≈⟨ sym (proj₁ identity (y ʳ)) ⟩
ε ∙ y ʳ ≤⟨ compatibility (ʳ-expand x) ≤-refl ⟩
(x ʳ ∙ x) ∙ y ʳ ≤⟨ substitutivity x≤y ⟩
(x ʳ ∙ y) ∙ y ʳ ≈⟨ assoc (x ʳ) y (y ʳ) ⟩
x ʳ ∙ (y ∙ y ʳ) ≤⟨ compatibility ≤-refl (ʳ-contract y) ⟩
x ʳ ∙ ε ≈⟨ proj₂ identity (x ʳ) ⟩
x ʳ
∎
ʳˡ-cancel : ∀ x → x ʳ ˡ ≈ x
ʳˡ-cancel x = sym (ˡ-unique (ʳ-contract x , ʳ-expand x))
ˡʳ-cancel : ∀ x → x ˡ ʳ ≈ x
ˡʳ-cancel x = sym (ʳ-unique (ˡ-contract x , ˡ-expand x))
| 33.195122
| 95
| 0.46314
|
3713d04b67aff16564da8a1e0d2861cec8497f5e
| 2,228
|
agda
|
Agda
|
agda-stdlib/src/Axiom/Extensionality/Propositional.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Axiom/Extensionality/Propositional.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Axiom/Extensionality/Propositional.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Results concerning function extensionality for propositional equality
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Axiom.Extensionality.Propositional where
open import Function.Base
open import Level using (Level; _⊔_; suc; lift)
open import Relation.Binary.Core
open import Relation.Binary.PropositionalEquality.Core
------------------------------------------------------------------------
-- Function extensionality states that if two functions are
-- propositionally equal for every input, then the functions themselves
-- must be propositionally equal.
Extensionality : (a b : Level) → Set _
Extensionality a b =
{A : Set a} {B : A → Set b} {f g : (x : A) → B x} →
(∀ x → f x ≡ g x) → f ≡ g
-- A variant for implicit function spaces.
ExtensionalityImplicit : (a b : Level) → Set _
ExtensionalityImplicit a b =
{A : Set a} {B : A → Set b} {f g : {x : A} → B x} →
(∀ {x} → f {x} ≡ g {x}) → (λ {x} → f {x}) ≡ (λ {x} → g {x})
------------------------------------------------------------------------
-- Properties
-- If extensionality holds for a given universe level, then it also
-- holds for lower ones.
lower-extensionality : ∀ {a₁ b₁} a₂ b₂ →
Extensionality (a₁ ⊔ a₂) (b₁ ⊔ b₂) →
Extensionality a₁ b₁
lower-extensionality a₂ b₂ ext f≡g = cong (λ h → Level.lower ∘ h ∘ lift) $
ext (cong (lift {ℓ = b₂}) ∘ f≡g ∘ Level.lower {ℓ = a₂})
-- Functional extensionality implies a form of extensionality for
-- Π-types.
∀-extensionality : ∀ {a b} → Extensionality a (suc b) →
{A : Set a} (B₁ B₂ : A → Set b) →
(∀ x → B₁ x ≡ B₂ x) →
(∀ x → B₁ x) ≡ (∀ x → B₂ x)
∀-extensionality ext B₁ B₂ B₁≡B₂ with ext B₁≡B₂
... | refl = refl
-- Extensionality for explicit function spaces implies extensionality
-- for implicit function spaces.
implicit-extensionality : ∀ {a b} →
Extensionality a b →
ExtensionalityImplicit a b
implicit-extensionality ext f≡g = cong _$- (ext (λ x → f≡g))
| 35.365079
| 74
| 0.530072
|
528511a0d14a983178803e4f449d4e35becada3c
| 782
|
agda
|
Agda
|
test/Succeed/ParenthesizedAlias.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/ParenthesizedAlias.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/ParenthesizedAlias.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2015-11-28
-- Aliases in parentheses should also parse.
-- Parenthesized aliases are accepted in lets.
-- With type annotation, parenthesized aliases are accepted in wheres.
id0 : {A : Set} → A → A
id0 {A} x = let z = y in z
where
y : A
y = x
id1 : {A : Set} → A → A
id1 {A} x = let (z) = y in z
where
y : A
(y) = x
id2 : {A : Set} → A → A
id2 {A} x = let ((z)) = y in z
where
y : A
((y)) = x
works0 : {A : Set} → A → A
works0 x = let z = y in z
where
y = x
-- Without type annotation, parenthesized aliases should also be accepted in wheres.
-- Should work:
test1 : {A : Set} → A → A
test1 x = let (z) = y in z
where
(y) = x
-- Should work:
test2 : {A : Set} → A → A
test2 x = let ((z)) = y in z
where
((y)) = x
| 17.772727
| 84
| 0.542199
|
cb8de75c462e3281d28c3085d5633902ac4e8754
| 3,730
|
agda
|
Agda
|
LibraBFT/Impl/Properties/Aux.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Impl/Properties/Aux.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
LibraBFT/Impl/Properties/Aux.agda
|
haroldcarr/bft-consensus-agda
|
34e4627855fb198665d0c98f377403a906ba75d7
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
{-# OPTIONS --allow-unsolved-metas #-}
open import LibraBFT.Prelude
open import LibraBFT.Base.PKCS
open import LibraBFT.Concrete.Obligations
open import LibraBFT.Concrete.System.Parameters
open import LibraBFT.Impl.Consensus.Types
open import LibraBFT.Impl.NetworkMsg
open import LibraBFT.Impl.Util.Crypto
open EpochConfig
open import LibraBFT.Yasm.Yasm (ℓ+1 0ℓ) EpochConfig epochId authorsN ConcSysParms NodeId-PK-OK
-- In this module, we will prove a structural property that any new signed message produced by an
-- honest handler from a reachable state correctly identifies the sender, and is for a valid epoch
-- of which that sender is a member. It is postulated for now, because the property does not yet
-- hold for our fake implementation that does not actually comply. A proof outline and notes are
-- included below, which we can finish once we do have a compliant implementation.
module LibraBFT.Impl.Properties.Aux where
-- 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 ix) 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
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
| here refl
| vote∈vm {si}
with MsgWithSig∈? {pk} {ver-signature ver} {msgPool st}
...| yes msg∈ = inj₂ msg∈
...| no msg∉ = inj₁ ((mkValidSenderForPK {! epoch !} -- We will need an invariant that says the epoch
-- used by a voter is "in range".
(EC-lookup' (availEpochs st) {!!})
refl
{! !} -- The implementation will need to check that the voter is a member of
-- the epoch of the message it's sending.
)
, msg∉)
| 61.147541
| 131
| 0.604558
|
0d2281c71c10ca617259b49a2213bcd5318e1872
| 2,635
|
agda
|
Agda
|
Syntax/Number.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Syntax/Number.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Syntax/Number.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Syntax.Number where
import Lvl
open import Logic.Propositional
open import Numeral.Natural
open import Type
record Numeral {ℓ} (T : Type{ℓ}) : Typeω where
field
{restriction-ℓ} : Lvl.Level
restriction : ℕ → Type{restriction-ℓ}
num : (n : ℕ) → ⦃ _ : restriction(n) ⦄ → T
open Numeral ⦃ ... ⦄ public using (num)
{-# BUILTIN FROMNAT num #-}
InfiniteNumeral = Numeral
module InfiniteNumeral {ℓ} {T : Type{ℓ}} where
intro : (ℕ → T) → InfiniteNumeral(T)
Numeral.restriction-ℓ (intro(_)) = Lvl.𝟎
Numeral.restriction (intro(_)) _ = ⊤
Numeral.num (intro(f)) n ⦃ _ ⦄ = f(n)
-- record InfiniteNumeral {ℓ} (T : Type{ℓ}) : Type{ℓ} where
-- record InfiniteNumeral {ℓ} (T : Type{ℓ}) : Type{ℓ} where
-- field
-- num : ℕ → T
-- instance
-- Numeral-from-InfiniteNumeral : ∀{ℓ}{T} → ⦃ _ : InfiniteNumeral{ℓ}(T) ⦄ → Numeral{ℓ}(T)
-- Numeral.restriction-ℓ ( Numeral-from-InfiniteNumeral ) = Lvl.𝟎
-- Numeral.restriction ( Numeral-from-InfiniteNumeral ) (_) = ⊤
-- num ⦃ Numeral-from-InfiniteNumeral ⦃ infNum ⦄ ⦄ (n) ⦃ _ ⦄ = InfiniteNumeral.num(infNum) (n)
instance
ℕ-InfiniteNumeral : InfiniteNumeral (ℕ)
ℕ-InfiniteNumeral = InfiniteNumeral.intro(id) where
id : ℕ → ℕ
id x = x
instance
Level-InfiniteNumeral : InfiniteNumeral (Lvl.Level)
Level-InfiniteNumeral = InfiniteNumeral.intro(f) where
f : ℕ → Lvl.Level
f(ℕ.𝟎) = Lvl.𝟎
f(ℕ.𝐒(n)) = Lvl.𝐒(f(n))
record NegativeNumeral {ℓ} (T : Type{ℓ}) : Typeω where
field
{restriction-ℓ} : Lvl.Level
restriction : ℕ → Type{restriction-ℓ}
num : (n : ℕ) → ⦃ _ : restriction(n) ⦄ → T
open NegativeNumeral ⦃ ... ⦄ public using () renaming (num to -num)
{-# BUILTIN FROMNEG -num #-}
InfiniteNegativeNumeral = NegativeNumeral
module InfiniteNegativeNumeral {ℓ} {T : Type{ℓ}} where
intro : (ℕ → T) → InfiniteNegativeNumeral(T)
NegativeNumeral.restriction-ℓ (intro(_)) = Lvl.𝟎
NegativeNumeral.restriction (intro(_)) _ = ⊤
NegativeNumeral.num (intro(f)) n ⦃ _ ⦄ = f(n)
-- record InfiniteNegativeNumeral {ℓ} (T : Type{ℓ}) : Type{ℓ} where
-- field
-- num : ℕ → T
-- open InfiniteNegativeNumeral ⦃ ... ⦄ public
-- instance
-- NegativeNumeral-from-InfiniteNegativeNumeral : ∀{ℓ}{T} → ⦃ _ : InfiniteNegativeNumeral{ℓ}(T) ⦄ → NegativeNumeral{ℓ}(T)
-- NegativeNumeral.restriction-ℓ ( NegativeNumeral-from-InfiniteNegativeNumeral ) = Lvl.𝟎
-- NegativeNumeral.restriction ( NegativeNumeral-from-InfiniteNegativeNumeral ) (_) = ⊤
-- -num ⦃ NegativeNumeral-from-InfiniteNegativeNumeral ⦃ infNegNum ⦄ ⦄ (n) ⦃ _ ⦄ = InfiniteNegativeNumeral.num(infNegNum) (n)
| 35.608108
| 127
| 0.650095
|
21e9db07e1a8f32aa672875550a3d411f5c90c75
| 7,800
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/Nat/Divisibility.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Nat/Divisibility.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Nat/Divisibility.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Divisibility
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.Divisibility where
open import Algebra
open import Data.Nat as Nat
open import Data.Nat.DivMod
open import Data.Nat.Properties
open import Data.Nat.Solver
open import Data.Fin using (Fin; zero; suc; toℕ)
import Data.Fin.Properties as FP
open import Data.Product
open import Function
open import Function.Equivalence using (_⇔_; equivalence)
open import Relation.Nullary
import Relation.Nullary.Decidable as Dec
open import Relation.Binary
import Relation.Binary.Reasoning.PartialOrder as POR
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; sym; trans; cong; cong₂; subst)
open +-*-Solver
------------------------------------------------------------------------
-- m ∣ n is inhabited iff m divides n. Some sources, like Hardy and
-- Wright's "An Introduction to the Theory of Numbers", require m to
-- be non-zero. However, some things become a bit nicer if m is
-- allowed to be zero. For instance, _∣_ becomes a partial order, and
-- the gcd of 0 and 0 becomes defined.
infix 4 _∣_ _∤_
record _∣_ (m n : ℕ) : Set where
constructor divides
field quotient : ℕ
equality : n ≡ quotient * m
open _∣_ using (quotient) public
_∤_ : Rel ℕ _
m ∤ n = ¬ (m ∣ n)
------------------------------------------------------------------------
-- _∣_ is a partial order
∣⇒≤ : ∀ {m n} → m ∣ suc n → m ≤ suc n
∣⇒≤ (divides zero ())
∣⇒≤ {m} {n} (divides (suc q) eq) = begin
m ≤⟨ m≤m+n m (q * m) ⟩
suc q * m ≡⟨ sym eq ⟩
suc n ∎
where open ≤-Reasoning
∣-reflexive : _≡_ ⇒ _∣_
∣-reflexive {n} refl = divides 1 (sym (*-identityˡ n))
∣-refl : Reflexive _∣_
∣-refl = ∣-reflexive refl
∣-trans : Transitive _∣_
∣-trans (divides p refl) (divides q refl) =
divides (q * p) (sym (*-assoc q p _))
∣-antisym : Antisymmetric _≡_ _∣_
∣-antisym {m} {0} _ (divides q eq) = trans eq (*-comm q 0)
∣-antisym {0} {n} (divides p eq) _ = sym (trans eq (*-comm p 0))
∣-antisym {suc m} {suc n} (divides p eq₁) (divides q eq₂) =
≤-antisym (∣⇒≤ (divides p eq₁)) (∣⇒≤ (divides q eq₂))
∣-isPreorder : IsPreorder _≡_ _∣_
∣-isPreorder = record
{ isEquivalence = PropEq.isEquivalence
; reflexive = ∣-reflexive
; trans = ∣-trans
}
∣-preorder : Preorder _ _ _
∣-preorder = record { isPreorder = ∣-isPreorder }
∣-isPartialOrder : IsPartialOrder _≡_ _∣_
∣-isPartialOrder = record
{ isPreorder = ∣-isPreorder
; antisym = ∣-antisym
}
poset : Poset _ _ _
poset = record
{ Carrier = ℕ
; _≈_ = _≡_
; _≤_ = _∣_
; isPartialOrder = ∣-isPartialOrder
}
module ∣-Reasoning = POR poset
hiding (_≈⟨_⟩_)
renaming (_≤⟨_⟩_ to _∣⟨_⟩_)
------------------------------------------------------------------------
-- Simple properties of _∣_
infix 10 1∣_ _∣0
1∣_ : ∀ n → 1 ∣ n
1∣ n = divides n (sym (*-identityʳ n))
_∣0 : ∀ n → n ∣ 0
n ∣0 = divides 0 refl
n∣n : ∀ {n} → n ∣ n
n∣n = ∣-refl
n∣m*n : ∀ m {n} → n ∣ m * n
n∣m*n m = divides m refl
m∣m*n : ∀ {m} n → m ∣ m * n
m∣m*n n = divides n (*-comm _ n)
0∣⇒≡0 : ∀ {n} → 0 ∣ n → n ≡ 0
0∣⇒≡0 {n} 0∣n = ∣-antisym (n ∣0) 0∣n
∣1⇒≡1 : ∀ {n} → n ∣ 1 → n ≡ 1
∣1⇒≡1 {n} n∣1 = ∣-antisym n∣1 (1∣ n)
------------------------------------------------------------------------
-- Operators and divisibility
module _ where
open PropEq.≡-Reasoning
∣m⇒∣m*n : ∀ {i m} n → i ∣ m → i ∣ m * n
∣m⇒∣m*n {i} {m} n (divides q eq) = divides (q * n) $ begin
m * n ≡⟨ cong (_* n) eq ⟩
q * i * n ≡⟨ *-assoc q i n ⟩
q * (i * n) ≡⟨ cong (q *_) (*-comm i n) ⟩
q * (n * i) ≡⟨ sym (*-assoc q n i) ⟩
q * n * i ∎
∣n⇒∣m*n : ∀ {i} m {n} → i ∣ n → i ∣ m * n
∣n⇒∣m*n {i} m {n} (divides q eq) = divides (m * q) $ begin
m * n ≡⟨ cong (m *_) eq ⟩
m * (q * i) ≡⟨ sym (*-assoc m q i) ⟩
m * q * i ∎
∣m∣n⇒∣m+n : ∀ {i m n} → i ∣ m → i ∣ n → i ∣ m + n
∣m∣n⇒∣m+n (divides p refl) (divides q refl) =
divides (p + q) (sym (*-distribʳ-+ _ p q))
∣m+n∣m⇒∣n : ∀ {i m n} → i ∣ m + n → i ∣ m → i ∣ n
∣m+n∣m⇒∣n {i} {m} {n} (divides p m+n≡p*i) (divides q m≡q*i) =
divides (p ∸ q) $ begin
n ≡⟨ sym (m+n∸n≡m n m) ⟩
n + m ∸ m ≡⟨ cong (_∸ m) (+-comm n m) ⟩
m + n ∸ m ≡⟨ cong₂ _∸_ m+n≡p*i m≡q*i ⟩
p * i ∸ q * i ≡⟨ sym (*-distribʳ-∸ i p q) ⟩
(p ∸ q) * i ∎
∣m∸n∣n⇒∣m : ∀ i {m n} → n ≤ m → i ∣ m ∸ n → i ∣ n → i ∣ m
∣m∸n∣n⇒∣m i {m} {n} n≤m (divides p m∸n≡p*i) (divides q n≡q*o) =
divides (p + q) $ begin
m ≡⟨ sym (m+n∸m≡n n≤m) ⟩
n + (m ∸ n) ≡⟨ +-comm n (m ∸ n) ⟩
m ∸ n + n ≡⟨ cong₂ _+_ m∸n≡p*i n≡q*o ⟩
p * i + q * i ≡⟨ sym (*-distribʳ-+ i p q) ⟩
(p + q) * i ∎
*-cong : ∀ {i j} k → i ∣ j → k * i ∣ k * j
*-cong {i} {j} k (divides q j≡q*i) = divides q $ begin
k * j ≡⟨ cong (_*_ k) j≡q*i ⟩
k * (q * i) ≡⟨ sym (*-assoc k q i) ⟩
(k * q) * i ≡⟨ cong (_* i) (*-comm k q) ⟩
(q * k) * i ≡⟨ *-assoc q k i ⟩
q * (k * i) ∎
/-cong : ∀ {i j} k → suc k * i ∣ suc k * j → i ∣ j
/-cong {i} {j} k (divides q eq) =
divides q (*-cancelʳ-≡ j (q * i) (begin
j * (suc k) ≡⟨ *-comm j (suc k) ⟩
(suc k) * j ≡⟨ eq ⟩
q * ((suc k) * i) ≡⟨ cong (q *_) (*-comm (suc k) i) ⟩
q * (i * (suc k)) ≡⟨ sym (*-assoc q i (suc k)) ⟩
(q * i) * (suc k) ∎))
m%n≡0⇒n∣m : ∀ m n → m % (suc n) ≡ 0 → suc n ∣ m
m%n≡0⇒n∣m m n eq = divides (m div (suc n)) (begin
m ≡⟨ a≡a%n+[a/n]*n m n ⟩
m % (suc n) + m div (suc n) * (suc n) ≡⟨ cong₂ _+_ eq refl ⟩
m div (suc n) * (suc n) ∎)
n∣m⇒m%n≡0 : ∀ m n → suc n ∣ m → m % (suc n) ≡ 0
n∣m⇒m%n≡0 m n (divides v eq) = begin
m % (suc n) ≡⟨ cong (_% (suc n)) eq ⟩
(v * suc n) % (suc n) ≡⟨ kn%n≡0 v n ⟩
0 ∎
m%n≡0⇔n∣m : ∀ m n → m % (suc n) ≡ 0 ⇔ suc n ∣ m
m%n≡0⇔n∣m m n = equivalence (m%n≡0⇒n∣m m n) (n∣m⇒m%n≡0 m n)
-- Divisibility is decidable.
infix 4 _∣?_
_∣?_ : Decidable _∣_
zero ∣? zero = yes (0 ∣0)
zero ∣? suc m = no ((λ()) ∘′ 0∣⇒≡0)
suc n ∣? m = Dec.map (m%n≡0⇔n∣m m n) (m % (suc n) ≟ 0)
------------------------------------------------------------------------
-- DEPRECATED - please use new names as continuing support for the old
-- names is not guaranteed.
∣-+ = ∣m∣n⇒∣m+n
{-# WARNING_ON_USAGE ∣-+
"Warning: ∣-+ was deprecated in v0.14.
Please use ∣m∣n⇒∣m+n instead."
#-}
∣-∸ = ∣m+n∣m⇒∣n
{-# WARNING_ON_USAGE ∣-∸
"Warning: ∣-∸ was deprecated in v0.14.
Please use ∣m+n∣m⇒∣n instead."
#-}
∣-* = n∣m*n
{-# WARNING_ON_USAGE ∣-*
"Warning: ∣-* was deprecated in v0.14.
Please use n∣m*n instead."
#-}
nonZeroDivisor-lemma : ∀ m q (r : Fin (1 + m)) → toℕ r ≢ 0 →
1 + m ∤ toℕ r + q * (1 + m)
nonZeroDivisor-lemma m zero r r≢zero (divides zero eq) = r≢zero $ begin
toℕ r ≡⟨ sym (*-identityˡ (toℕ r)) ⟩
1 * toℕ r ≡⟨ eq ⟩
0 ∎
where open PropEq.≡-Reasoning
nonZeroDivisor-lemma m zero r r≢zero (divides (suc q) eq) =
i+1+j≰i m $ begin
m + suc (q * suc m) ≡⟨ +-suc m (q * suc m) ⟩
suc (m + q * suc m) ≡⟨ sym eq ⟩
1 * toℕ r ≡⟨ *-identityˡ (toℕ r) ⟩
toℕ r ≤⟨ FP.toℕ≤pred[n] r ⟩
m ∎
where open ≤-Reasoning
nonZeroDivisor-lemma m (suc q) r r≢zero d =
nonZeroDivisor-lemma m q r r≢zero (∣m+n∣m⇒∣n d' ∣-refl)
where
lem = solve 3 (λ m r q → r :+ (m :+ q) := m :+ (r :+ q))
refl (suc m) (toℕ r) (q * suc m)
d' = subst (1 + m ∣_) lem d
{-# WARNING_ON_USAGE nonZeroDivisor-lemma
"Warning: nonZeroDivisor-lemma was deprecated in v0.17."
#-}
| 30.350195
| 72
| 0.470641
|
8b3f4f03c40f75e9d2edfa6a4ee7b550495b5152
| 630
|
agda
|
Agda
|
Pi/Everything.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
Pi/Everything.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
Pi/Everything.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
module Pi.Everything where
open import Pi.Syntax -- Syntax of Pi
open import Pi.Opsem -- Abstract machine semantics of Pi
open import Pi.AuxLemmas -- Some auxiliary lemmas about opsem for forward/backward deterministic proof
open import Pi.NoRepeat -- Forward/backward deterministic lemmas and Non-repeating lemma
open import Pi.Eval -- Evaluator for Pi
open import Pi.Interp -- Big-step intepreter of Pi
open import Pi.Invariants -- Some invariants about abstract machine semantics
open import Pi.Properties -- Properties of Pi
open import Pi.Examples -- Examples
open import Pi.Category -- Pi Category
| 52.5
| 103
| 0.768254
|
2eb52a30b59fc0bc6a8b1e7b681795f93e6ce7dd
| 19,154
|
agda
|
Agda
|
test/asset/agda-stdlib-1.0/Data/Fin/Substitution/Lemmas.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Fin/Substitution/Lemmas.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
test/asset/agda-stdlib-1.0/Data/Fin/Substitution/Lemmas.agda
|
omega12345/agda-mode
|
0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Substitution lemmas
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Fin.Substitution.Lemmas where
import Category.Applicative.Indexed as Applicative
open import Data.Fin.Substitution
open import Data.Nat hiding (_⊔_)
open import Data.Fin using (Fin; zero; suc; lift)
open import Data.Vec
import Data.Vec.Properties as VecProp
open import Function as Fun using (_∘_; _$_)
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; refl; sym; cong; cong₂)
open import Relation.Binary.Construct.Closure.ReflexiveTransitive
using (Star; ε; _◅_; _▻_)
open PropEq.≡-Reasoning
open import Level using (Level; _⊔_)
open import Relation.Unary using (Pred)
-- A lemma which does not refer to any substitutions.
lift-commutes : ∀ {n} k j (x : Fin (j + (k + n))) →
lift j suc (lift j (lift k suc) x) ≡
lift j (lift (suc k) suc) (lift j suc x)
lift-commutes k zero x = refl
lift-commutes k (suc j) zero = refl
lift-commutes k (suc j) (suc x) = cong suc (lift-commutes k j x)
-- The modules below prove a number of substitution lemmas, on the
-- assumption that the underlying substitution machinery satisfies
-- certain properties.
record Lemmas₀ {ℓ : Level} (T : Pred ℕ ℓ) : Set ℓ where
field simple : Simple T
open Simple simple
extensionality : ∀ {m n} {ρ₁ ρ₂ : Sub T m n} →
(∀ x → lookup ρ₁ x ≡ lookup ρ₂ x) → ρ₁ ≡ ρ₂
extensionality {ρ₁ = []} {[]} hyp = refl
extensionality {ρ₁ = t₁ ∷ ρ₁} { t₂ ∷ ρ₂} hyp with hyp zero
extensionality {ρ₁ = t₁ ∷ ρ₁} {.t₁ ∷ ρ₂} hyp | refl =
cong (_∷_ t₁) (extensionality (hyp ∘ suc))
id-↑⋆ : ∀ {n} k → id ↑⋆ k ≡ id {k + n}
id-↑⋆ zero = refl
id-↑⋆ (suc k) = begin
(id ↑⋆ k) ↑ ≡⟨ cong _↑ (id-↑⋆ k) ⟩
id ↑ ∎
lookup-map-weaken-↑⋆ : ∀ {m n} k x {ρ : Sub T m n} →
lookup (map weaken ρ ↑⋆ k) x ≡
lookup ((ρ ↑) ↑⋆ k) (lift k suc x)
lookup-map-weaken-↑⋆ zero x = refl
lookup-map-weaken-↑⋆ (suc k) zero = refl
lookup-map-weaken-↑⋆ (suc k) (suc x) {ρ} = begin
lookup (map weaken (map weaken ρ ↑⋆ k)) x ≡⟨ VecProp.lookup-map x weaken (map weaken ρ ↑⋆ k) ⟩
weaken (lookup (map weaken ρ ↑⋆ k) x) ≡⟨ cong weaken (lookup-map-weaken-↑⋆ k x) ⟩
weaken (lookup ((ρ ↑) ↑⋆ k) (lift k suc x)) ≡⟨ sym $ VecProp.lookup-map (lift k suc x) weaken ((ρ ↑) ↑⋆ k) ⟩
lookup (map weaken ((ρ ↑) ↑⋆ k)) (lift k suc x) ∎
record Lemmas₁ {ℓ} (T : Pred ℕ ℓ) : Set ℓ where
field lemmas₀ : Lemmas₀ T
open Lemmas₀ lemmas₀
open Simple simple
field weaken-var : ∀ {n} {x : Fin n} → weaken (var x) ≡ var (suc x)
lookup-map-weaken : ∀ {m n} x {y} {ρ : Sub T m n} →
lookup ρ x ≡ var y →
lookup (map weaken ρ) x ≡ var (suc y)
lookup-map-weaken x {y} {ρ} hyp = begin
lookup (map weaken ρ) x ≡⟨ VecProp.lookup-map x weaken ρ ⟩
weaken (lookup ρ x) ≡⟨ cong weaken hyp ⟩
weaken (var y) ≡⟨ weaken-var ⟩
var (suc y) ∎
mutual
lookup-id : ∀ {n} (x : Fin n) → lookup id x ≡ var x
lookup-id zero = refl
lookup-id (suc x) = lookup-wk x
lookup-wk : ∀ {n} (x : Fin n) → lookup wk x ≡ var (suc x)
lookup-wk x = lookup-map-weaken x {ρ = id} (lookup-id x)
lookup-↑⋆ : ∀ {m n} (f : Fin m → Fin n) {ρ : Sub T m n} →
(∀ x → lookup ρ x ≡ var (f x)) →
∀ k x → lookup (ρ ↑⋆ k) x ≡ var (lift k f x)
lookup-↑⋆ f hyp zero x = hyp x
lookup-↑⋆ f hyp (suc k) zero = refl
lookup-↑⋆ f {ρ = ρ} hyp (suc k) (suc x) =
lookup-map-weaken x {ρ = ρ ↑⋆ k} (lookup-↑⋆ f hyp k x)
lookup-lift-↑⋆ : ∀ {m n} (f : Fin n → Fin m) {ρ : Sub T m n} →
(∀ x → lookup ρ (f x) ≡ var x) →
∀ k x → lookup (ρ ↑⋆ k) (lift k f x) ≡ var x
lookup-lift-↑⋆ f hyp zero x = hyp x
lookup-lift-↑⋆ f hyp (suc k) zero = refl
lookup-lift-↑⋆ f {ρ = ρ} hyp (suc k) (suc x) =
lookup-map-weaken (lift k f x) {ρ = ρ ↑⋆ k} (lookup-lift-↑⋆ f hyp k x)
lookup-wk-↑⋆ : ∀ {n} k (x : Fin (k + n)) →
lookup (wk ↑⋆ k) x ≡ var (lift k suc x)
lookup-wk-↑⋆ = lookup-↑⋆ suc lookup-wk
lookup-wk-↑⋆-↑⋆ : ∀ {n} k j (x : Fin (j + (k + n))) →
lookup (wk ↑⋆ k ↑⋆ j) x ≡
var (lift j (lift k suc) x)
lookup-wk-↑⋆-↑⋆ k = lookup-↑⋆ (lift k suc) (lookup-wk-↑⋆ k)
lookup-sub-↑⋆ : ∀ {n t} k (x : Fin (k + n)) →
lookup (sub t ↑⋆ k) (lift k suc x) ≡ var x
lookup-sub-↑⋆ = lookup-lift-↑⋆ suc lookup-id
open Lemmas₀ lemmas₀ public
record Lemmas₂ {ℓ} (T : Pred ℕ ℓ) : Set ℓ where
field
lemmas₁ : Lemmas₁ T
application : Application T T
open Lemmas₁ lemmas₁
subst : Subst T
subst = record { simple = simple; application = application }
open Subst subst
field var-/ : ∀ {m n x} {ρ : Sub T m n} → var x / ρ ≡ lookup ρ x
suc-/-sub : ∀ {n x} {t : T n} → var (suc x) / sub t ≡ var x
suc-/-sub {x = x} {t} = begin
var (suc x) / sub t ≡⟨ var-/ ⟩
lookup (sub t) (suc x) ≡⟨ refl ⟩
lookup id x ≡⟨ lookup-id x ⟩
var x ∎
lookup-⊙ : ∀ {m n k} x {ρ₁ : Sub T m n} {ρ₂ : Sub T n k} →
lookup (ρ₁ ⊙ ρ₂) x ≡ lookup ρ₁ x / ρ₂
lookup-⊙ x {ρ₁} {ρ₂} = VecProp.lookup-map x (λ t → t / ρ₂) ρ₁
lookup-⨀ : ∀ {m n} x (ρs : Subs T m n) →
lookup (⨀ ρs) x ≡ var x /✶ ρs
lookup-⨀ x ε = lookup-id x
lookup-⨀ x (ρ ◅ ε) = sym var-/
lookup-⨀ x (ρ ◅ (ρ′ ◅ ρs′)) = begin
lookup (⨀ (ρ ◅ ρs)) x ≡⟨ refl ⟩
lookup (⨀ ρs ⊙ ρ) x ≡⟨ lookup-⊙ x {ρ₁ = ⨀ (ρ′ ◅ ρs′)} ⟩
lookup (⨀ ρs) x / ρ ≡⟨ cong₂ _/_ (lookup-⨀ x (ρ′ ◅ ρs′)) refl ⟩
var x /✶ ρs / ρ ∎
where ρs = ρ′ ◅ ρs′
id-⊙ : ∀ {m n} {ρ : Sub T m n} → id ⊙ ρ ≡ ρ
id-⊙ {ρ = ρ} = extensionality λ x → begin
lookup (id ⊙ ρ) x ≡⟨ lookup-⊙ x {ρ₁ = id} ⟩
lookup id x / ρ ≡⟨ cong₂ _/_ (lookup-id x) refl ⟩
var x / ρ ≡⟨ var-/ ⟩
lookup ρ x ∎
lookup-wk-↑⋆-⊙ : ∀ {m n} k {x} {ρ : Sub T (k + suc m) n} →
lookup (wk ↑⋆ k ⊙ ρ) x ≡ lookup ρ (lift k suc x)
lookup-wk-↑⋆-⊙ k {x} {ρ} = begin
lookup (wk ↑⋆ k ⊙ ρ) x ≡⟨ lookup-⊙ x {ρ₁ = wk ↑⋆ k} ⟩
lookup (wk ↑⋆ k) x / ρ ≡⟨ cong₂ _/_ (lookup-wk-↑⋆ k x) refl ⟩
var (lift k suc x) / ρ ≡⟨ var-/ ⟩
lookup ρ (lift k suc x) ∎
wk-⊙-sub′ : ∀ {n} {t : T n} k → wk ↑⋆ k ⊙ sub t ↑⋆ k ≡ id
wk-⊙-sub′ {t = t} k = extensionality λ x → begin
lookup (wk ↑⋆ k ⊙ sub t ↑⋆ k) x ≡⟨ lookup-wk-↑⋆-⊙ k ⟩
lookup (sub t ↑⋆ k) (lift k suc x) ≡⟨ lookup-sub-↑⋆ k x ⟩
var x ≡⟨ sym (lookup-id x) ⟩
lookup id x ∎
wk-⊙-sub : ∀ {n} {t : T n} → wk ⊙ sub t ≡ id
wk-⊙-sub = wk-⊙-sub′ zero
var-/-wk-↑⋆ : ∀ {n} k (x : Fin (k + n)) →
var x / wk ↑⋆ k ≡ var (lift k suc x)
var-/-wk-↑⋆ k x = begin
var x / wk ↑⋆ k ≡⟨ var-/ ⟩
lookup (wk ↑⋆ k) x ≡⟨ lookup-wk-↑⋆ k x ⟩
var (lift k suc x) ∎
wk-↑⋆-⊙-wk : ∀ {n} k j →
wk {n} ↑⋆ k ↑⋆ j ⊙ wk ↑⋆ j ≡
wk ↑⋆ j ⊙ wk ↑⋆ suc k ↑⋆ j
wk-↑⋆-⊙-wk k j = extensionality λ x → begin
lookup (wk ↑⋆ k ↑⋆ j ⊙ wk ↑⋆ j) x ≡⟨ lookup-⊙ x {ρ₁ = wk ↑⋆ k ↑⋆ j} ⟩
lookup (wk ↑⋆ k ↑⋆ j) x / wk ↑⋆ j ≡⟨ cong₂ _/_ (lookup-wk-↑⋆-↑⋆ k j x) refl ⟩
var (lift j (lift k suc) x) / wk ↑⋆ j ≡⟨ var-/-wk-↑⋆ j (lift j (lift k suc) x) ⟩
var (lift j suc (lift j (lift k suc) x)) ≡⟨ cong var (lift-commutes k j x) ⟩
var (lift j (lift (suc k) suc) (lift j suc x)) ≡⟨ sym (lookup-wk-↑⋆-↑⋆ (suc k) j (lift j suc x)) ⟩
lookup (wk ↑⋆ suc k ↑⋆ j) (lift j suc x) ≡⟨ sym var-/ ⟩
var (lift j suc x) / wk ↑⋆ suc k ↑⋆ j ≡⟨ cong₂ _/_ (sym (lookup-wk-↑⋆ j x)) refl ⟩
lookup (wk ↑⋆ j) x / wk ↑⋆ suc k ↑⋆ j ≡⟨ sym (lookup-⊙ x {ρ₁ = wk ↑⋆ j}) ⟩
lookup (wk ↑⋆ j ⊙ wk ↑⋆ suc k ↑⋆ j) x ∎
open Subst subst public hiding (simple; application)
open Lemmas₁ lemmas₁ public
record Lemmas₃ {ℓ} (T : Pred ℕ ℓ) : Set ℓ where
field lemmas₂ : Lemmas₂ T
open Lemmas₂ lemmas₂
field
/✶-↑✶ : ∀ {m n} (ρs₁ ρs₂ : Subs T m n) →
(∀ k x → var x /✶ ρs₁ ↑✶ k ≡ var x /✶ ρs₂ ↑✶ k) →
∀ k t → t /✶ ρs₁ ↑✶ k ≡ t /✶ ρs₂ ↑✶ k
/✶-↑✶′ : ∀ {m n} (ρs₁ ρs₂ : Subs T m n) →
(∀ k → ⨀ (ρs₁ ↑✶ k) ≡ ⨀ (ρs₂ ↑✶ k)) →
∀ k t → t /✶ ρs₁ ↑✶ k ≡ t /✶ ρs₂ ↑✶ k
/✶-↑✶′ ρs₁ ρs₂ hyp = /✶-↑✶ ρs₁ ρs₂ (λ k x → begin
var x /✶ ρs₁ ↑✶ k ≡⟨ sym (lookup-⨀ x (ρs₁ ↑✶ k)) ⟩
lookup (⨀ (ρs₁ ↑✶ k)) x ≡⟨ cong (Fun.flip lookup x) (hyp k) ⟩
lookup (⨀ (ρs₂ ↑✶ k)) x ≡⟨ lookup-⨀ x (ρs₂ ↑✶ k) ⟩
var x /✶ ρs₂ ↑✶ k ∎)
id-vanishes : ∀ {n} (t : T n) → t / id ≡ t
id-vanishes = /✶-↑✶′ (ε ▻ id) ε id-↑⋆ zero
⊙-id : ∀ {m n} {ρ : Sub T m n} → ρ ⊙ id ≡ ρ
⊙-id {ρ = ρ} = begin
map (λ t → t / id) ρ ≡⟨ VecProp.map-cong id-vanishes ρ ⟩
map Fun.id ρ ≡⟨ VecProp.map-id ρ ⟩
ρ ∎
open Lemmas₂ lemmas₂ public hiding (wk-⊙-sub′)
record Lemmas₄ {ℓ} (T : Pred ℕ ℓ) : Set ℓ where
field lemmas₃ : Lemmas₃ T
open Lemmas₃ lemmas₃
field /-wk : ∀ {n} {t : T n} → t / wk ≡ weaken t
private
↑-distrib′ : ∀ {m n k} {ρ₁ : Sub T m n} {ρ₂ : Sub T n k} →
(∀ t → t / ρ₂ / wk ≡ t / wk / ρ₂ ↑) →
(ρ₁ ⊙ ρ₂) ↑ ≡ ρ₁ ↑ ⊙ ρ₂ ↑
↑-distrib′ {ρ₁ = ρ₁} {ρ₂} hyp = begin
(ρ₁ ⊙ ρ₂) ↑ ≡⟨ refl ⟩
var zero ∷ map weaken (ρ₁ ⊙ ρ₂) ≡⟨ cong₂ _∷_ (sym var-/) lemma ⟩
var zero / ρ₂ ↑ ∷ map weaken ρ₁ ⊙ ρ₂ ↑ ≡⟨ refl ⟩
ρ₁ ↑ ⊙ ρ₂ ↑ ∎
where
lemma = begin
map weaken (map (λ t → t / ρ₂) ρ₁) ≡⟨ sym (VecProp.map-∘ _ _ _) ⟩
map (λ t → weaken (t / ρ₂)) ρ₁ ≡⟨ VecProp.map-cong (λ t → begin
weaken (t / ρ₂) ≡⟨ sym /-wk ⟩
t / ρ₂ / wk ≡⟨ hyp t ⟩
t / wk / ρ₂ ↑ ≡⟨ cong₂ _/_ /-wk refl ⟩
weaken t / ρ₂ ↑ ∎) ρ₁ ⟩
map (λ t → weaken t / ρ₂ ↑) ρ₁ ≡⟨ VecProp.map-∘ _ _ _ ⟩
map (λ t → t / ρ₂ ↑) (map weaken ρ₁) ∎
↑⋆-distrib′ : ∀ {m n o} {ρ₁ : Sub T m n} {ρ₂ : Sub T n o} →
(∀ k t → t / ρ₂ ↑⋆ k / wk ≡ t / wk / ρ₂ ↑⋆ suc k) →
∀ k → (ρ₁ ⊙ ρ₂) ↑⋆ k ≡ ρ₁ ↑⋆ k ⊙ ρ₂ ↑⋆ k
↑⋆-distrib′ hyp zero = refl
↑⋆-distrib′ {ρ₁ = ρ₁} {ρ₂} hyp (suc k) = begin
(ρ₁ ⊙ ρ₂) ↑⋆ suc k ≡⟨ cong _↑ (↑⋆-distrib′ hyp k) ⟩
(ρ₁ ↑⋆ k ⊙ ρ₂ ↑⋆ k) ↑ ≡⟨ ↑-distrib′ (hyp k) ⟩
ρ₁ ↑⋆ suc k ⊙ ρ₂ ↑⋆ suc k ∎
map-weaken : ∀ {m n} {ρ : Sub T m n} → map weaken ρ ≡ ρ ⊙ wk
map-weaken {ρ = ρ} = begin
map weaken ρ ≡⟨ VecProp.map-cong (λ _ → sym /-wk) ρ ⟩
map (λ t → t / wk) ρ ≡⟨ refl ⟩
ρ ⊙ wk ∎
private
⊙-wk′ : ∀ {m n} {ρ : Sub T m n} k →
ρ ↑⋆ k ⊙ wk ↑⋆ k ≡ wk ↑⋆ k ⊙ ρ ↑ ↑⋆ k
⊙-wk′ {ρ = ρ} k = sym (begin
wk ↑⋆ k ⊙ ρ ↑ ↑⋆ k ≡⟨ lemma ⟩
map weaken ρ ↑⋆ k ≡⟨ cong (λ ρ′ → ρ′ ↑⋆ k) map-weaken ⟩
(ρ ⊙ wk) ↑⋆ k ≡⟨ ↑⋆-distrib′ (λ k t →
/✶-↑✶′ (ε ▻ wk ↑⋆ k ▻ wk) (ε ▻ wk ▻ wk ↑⋆ suc k)
(wk-↑⋆-⊙-wk k) zero t) k ⟩
ρ ↑⋆ k ⊙ wk ↑⋆ k ∎)
where
lemma = extensionality λ x → begin
lookup (wk ↑⋆ k ⊙ ρ ↑ ↑⋆ k) x ≡⟨ lookup-wk-↑⋆-⊙ k ⟩
lookup (ρ ↑ ↑⋆ k) (lift k suc x) ≡⟨ sym (lookup-map-weaken-↑⋆ k x) ⟩
lookup (map weaken ρ ↑⋆ k) x ∎
⊙-wk : ∀ {m n} {ρ : Sub T m n} → ρ ⊙ wk ≡ wk ⊙ ρ ↑
⊙-wk = ⊙-wk′ zero
wk-commutes : ∀ {m n} {ρ : Sub T m n} t →
t / ρ / wk ≡ t / wk / ρ ↑
wk-commutes {ρ = ρ} = /✶-↑✶′ (ε ▻ ρ ▻ wk) (ε ▻ wk ▻ ρ ↑) ⊙-wk′ zero
↑⋆-distrib : ∀ {m n o} {ρ₁ : Sub T m n} {ρ₂ : Sub T n o} →
∀ k → (ρ₁ ⊙ ρ₂) ↑⋆ k ≡ ρ₁ ↑⋆ k ⊙ ρ₂ ↑⋆ k
↑⋆-distrib = ↑⋆-distrib′ (λ _ → wk-commutes)
/-⊙ : ∀ {m n k} {ρ₁ : Sub T m n} {ρ₂ : Sub T n k} t →
t / ρ₁ ⊙ ρ₂ ≡ t / ρ₁ / ρ₂
/-⊙ {ρ₁ = ρ₁} {ρ₂} t =
/✶-↑✶′ (ε ▻ ρ₁ ⊙ ρ₂) (ε ▻ ρ₁ ▻ ρ₂) ↑⋆-distrib zero t
⊙-assoc : ∀ {m n k o}
{ρ₁ : Sub T m n} {ρ₂ : Sub T n k} {ρ₃ : Sub T k o} →
ρ₁ ⊙ (ρ₂ ⊙ ρ₃) ≡ (ρ₁ ⊙ ρ₂) ⊙ ρ₃
⊙-assoc {ρ₁ = ρ₁} {ρ₂} {ρ₃} = begin
map (λ t → t / ρ₂ ⊙ ρ₃) ρ₁ ≡⟨ VecProp.map-cong /-⊙ ρ₁ ⟩
map (λ t → t / ρ₂ / ρ₃) ρ₁ ≡⟨ VecProp.map-∘ _ _ _ ⟩
map (λ t → t / ρ₃) (map (λ t → t / ρ₂) ρ₁) ∎
map-weaken-⊙-sub : ∀ {m n} {ρ : Sub T m n} {t} → map weaken ρ ⊙ sub t ≡ ρ
map-weaken-⊙-sub {ρ = ρ} {t} = begin
map weaken ρ ⊙ sub t ≡⟨ cong₂ _⊙_ map-weaken refl ⟩
ρ ⊙ wk ⊙ sub t ≡⟨ sym ⊙-assoc ⟩
ρ ⊙ (wk ⊙ sub t) ≡⟨ cong (_⊙_ ρ) wk-⊙-sub ⟩
ρ ⊙ id ≡⟨ ⊙-id ⟩
ρ ∎
sub-⊙ : ∀ {m n} {ρ : Sub T m n} t → sub t ⊙ ρ ≡ ρ ↑ ⊙ sub (t / ρ)
sub-⊙ {ρ = ρ} t = begin
sub t ⊙ ρ ≡⟨ refl ⟩
t / ρ ∷ id ⊙ ρ ≡⟨ cong (_∷_ (t / ρ)) id-⊙ ⟩
t / ρ ∷ ρ ≡⟨ cong (_∷_ (t / ρ)) (sym map-weaken-⊙-sub) ⟩
t / ρ ∷ map weaken ρ ⊙ sub (t / ρ) ≡⟨ cong₂ _∷_ (sym var-/) refl ⟩
ρ ↑ ⊙ sub (t / ρ) ∎
suc-/-↑ : ∀ {m n} {ρ : Sub T m n} x →
var (suc x) / ρ ↑ ≡ var x / ρ / wk
suc-/-↑ {ρ = ρ} x = begin
var (suc x) / ρ ↑ ≡⟨ var-/ ⟩
lookup (map weaken ρ) x ≡⟨ cong (Fun.flip lookup x) (map-weaken {ρ = ρ}) ⟩
lookup (ρ ⊙ wk) x ≡⟨ lookup-⊙ x {ρ₁ = ρ} ⟩
lookup ρ x / wk ≡⟨ cong₂ _/_ (sym var-/) refl ⟩
var x / ρ / wk ∎
open Lemmas₃ lemmas₃ public
hiding (/✶-↑✶; /✶-↑✶′; wk-↑⋆-⊙-wk;
lookup-wk-↑⋆-⊙; lookup-map-weaken-↑⋆)
-- For an example of how AppLemmas can be used, see
-- Data.Fin.Substitution.List.
record AppLemmas {ℓ₁ ℓ₂} (T₁ : Pred ℕ ℓ₁) (T₂ : Pred ℕ ℓ₂) : Set (ℓ₁ ⊔ ℓ₂) where
field
application : Application T₁ T₂
lemmas₄ : Lemmas₄ T₂
open Application application using (_/_; _/✶_)
open Lemmas₄ lemmas₄
using (id; _⊙_; wk; weaken; sub; _↑; ⨀) renaming (_/_ to _⊘_)
field
id-vanishes : ∀ {n} (t : T₁ n) → t / id ≡ t
/-⊙ : ∀ {m n k} {ρ₁ : Sub T₂ m n} {ρ₂ : Sub T₂ n k} t →
t / ρ₁ ⊙ ρ₂ ≡ t / ρ₁ / ρ₂
private module L₄ = Lemmas₄ lemmas₄
/-⨀ : ∀ {m n} t (ρs : Subs T₂ m n) → t / ⨀ ρs ≡ t /✶ ρs
/-⨀ t ε = id-vanishes t
/-⨀ t (ρ ◅ ε) = refl
/-⨀ t (ρ ◅ (ρ′ ◅ ρs′)) = begin
t / ⨀ ρs ⊙ ρ ≡⟨ /-⊙ t ⟩
t / ⨀ ρs / ρ ≡⟨ cong₂ _/_ (/-⨀ t (ρ′ ◅ ρs′)) refl ⟩
t /✶ ρs / ρ ∎
where ρs = ρ′ ◅ ρs′
⨀→/✶ : ∀ {m n} (ρs₁ ρs₂ : Subs T₂ m n) →
⨀ ρs₁ ≡ ⨀ ρs₂ → ∀ t → t /✶ ρs₁ ≡ t /✶ ρs₂
⨀→/✶ ρs₁ ρs₂ hyp t = begin
t /✶ ρs₁ ≡⟨ sym (/-⨀ t ρs₁) ⟩
t / ⨀ ρs₁ ≡⟨ cong (_/_ t) hyp ⟩
t / ⨀ ρs₂ ≡⟨ /-⨀ t ρs₂ ⟩
t /✶ ρs₂ ∎
wk-commutes : ∀ {m n} {ρ : Sub T₂ m n} t →
t / ρ / wk ≡ t / wk / ρ ↑
wk-commutes {ρ = ρ} = ⨀→/✶ (ε ▻ ρ ▻ wk) (ε ▻ wk ▻ ρ ↑) L₄.⊙-wk
sub-commutes : ∀ {m n} {t′} {ρ : Sub T₂ m n} t →
t / sub t′ / ρ ≡ t / ρ ↑ / sub (t′ ⊘ ρ)
sub-commutes {t′ = t′} {ρ} =
⨀→/✶ (ε ▻ sub t′ ▻ ρ) (ε ▻ ρ ↑ ▻ sub (t′ ⊘ ρ)) (L₄.sub-⊙ t′)
wk-sub-vanishes : ∀ {n t′} (t : T₁ n) → t / wk / sub t′ ≡ t
wk-sub-vanishes {t′ = t′} = ⨀→/✶ (ε ▻ wk ▻ sub t′) ε L₄.wk-⊙-sub
/-weaken : ∀ {m n} {ρ : Sub T₂ m n} t → t / map weaken ρ ≡ t / ρ / wk
/-weaken {ρ = ρ} = ⨀→/✶ (ε ▻ map weaken ρ) (ε ▻ ρ ▻ wk) L₄.map-weaken
open Application application public
open L₄ public
hiding (application; _⊙_; _/_; _/✶_;
id-vanishes; /-⊙; wk-commutes)
record Lemmas₅ {ℓ} (T : Pred ℕ ℓ) : Set ℓ where
field lemmas₄ : Lemmas₄ T
private module L₄ = Lemmas₄ lemmas₄
appLemmas : AppLemmas T T
appLemmas = record
{ application = L₄.application
; lemmas₄ = lemmas₄
; id-vanishes = L₄.id-vanishes
; /-⊙ = L₄./-⊙
}
open AppLemmas appLemmas public hiding (lemmas₄)
------------------------------------------------------------------------
-- Instantiations and code for facilitating instantiations
-- Lemmas about variable substitutions (renamings).
module VarLemmas where
open VarSubst
lemmas₃ : Lemmas₃ Fin
lemmas₃ = record
{ lemmas₂ = record
{ lemmas₁ = record
{ lemmas₀ = record
{ simple = simple
}
; weaken-var = refl
}
; application = application
; var-/ = refl
}
; /✶-↑✶ = λ _ _ hyp → hyp
}
private module L₃ = Lemmas₃ lemmas₃
lemmas₅ : Lemmas₅ Fin
lemmas₅ = record
{ lemmas₄ = record
{ lemmas₃ = lemmas₃
; /-wk = L₃.lookup-wk _
}
}
open Lemmas₅ lemmas₅ public hiding (lemmas₃)
-- Lemmas about "term" substitutions.
record TermLemmas (T : ℕ → Set) : Set₁ where
field
termSubst : TermSubst T
open TermSubst termSubst
field
app-var : ∀ {T′} {lift : Lift T′ T} {m n x} {ρ : Sub T′ m n} →
app lift (var x) ρ ≡ Lift.lift lift (lookup ρ x)
/✶-↑✶ : ∀ {T₁ T₂} {lift₁ : Lift T₁ T} {lift₂ : Lift T₂ T} →
let open Lifted lift₁
using () renaming (_↑✶_ to _↑✶₁_; _/✶_ to _/✶₁_)
open Lifted lift₂
using () renaming (_↑✶_ to _↑✶₂_; _/✶_ to _/✶₂_)
in
∀ {m n} (ρs₁ : Subs T₁ m n) (ρs₂ : Subs T₂ m n) →
(∀ k x → var x /✶₁ ρs₁ ↑✶₁ k ≡ var x /✶₂ ρs₂ ↑✶₂ k) →
∀ k t → t /✶₁ ρs₁ ↑✶₁ k ≡ t /✶₂ ρs₂ ↑✶₂ k
private module V = VarLemmas
lemmas₃ : Lemmas₃ T
lemmas₃ = record
{ lemmas₂ = record
{ lemmas₁ = record
{ lemmas₀ = record
{ simple = simple
}
; weaken-var = λ {_ x} → begin
var x /Var V.wk ≡⟨ app-var ⟩
var (lookup V.wk x) ≡⟨ cong var (V.lookup-wk x) ⟩
var (suc x) ∎
}
; application = Subst.application subst
; var-/ = app-var
}
; /✶-↑✶ = /✶-↑✶
}
private module L₃ = Lemmas₃ lemmas₃
lemmas₅ : Lemmas₅ T
lemmas₅ = record
{ lemmas₄ = record
{ lemmas₃ = lemmas₃
; /-wk = λ {_ t} → begin
t / wk ≡⟨ /✶-↑✶ (ε ▻ wk) (ε ▻ V.wk)
(λ k x → begin
var x / wk ↑⋆ k ≡⟨ L₃.var-/-wk-↑⋆ k x ⟩
var (lift k suc x) ≡⟨ cong var (sym (V.var-/-wk-↑⋆ k x)) ⟩
var (lookup (V._↑⋆_ V.wk k) x) ≡⟨ sym app-var ⟩
var x /Var V._↑⋆_ V.wk k ∎)
zero t ⟩
t /Var V.wk ≡⟨⟩
weaken t ∎
}
}
open Lemmas₅ lemmas₅ public hiding (lemmas₃)
| 36.763916
| 117
| 0.435679
|
7c01c767383c44ce70d11d36c1501e79c8054043
| 2,961
|
agda
|
Agda
|
Lambda/Syntax.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | 1
|
2021-02-13T14:48:45.000Z
|
2021-02-13T14:48:45.000Z
|
Lambda/Syntax.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | null | null | null |
Lambda/Syntax.agda
|
nad/codata
|
1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- The syntax of, and a type system for, the untyped λ-calculus with
-- constants
------------------------------------------------------------------------
module Lambda.Syntax where
open import Codata.Musical.Notation
open import Data.Nat
open import Data.Fin hiding (_≤?_)
open import Data.Vec
open import Relation.Nullary.Decidable
------------------------------------------------------------------------
-- Terms
-- Variables are represented using de Bruijn indices.
infixl 9 _·_
data Tm (n : ℕ) : Set where
con : (i : ℕ) → Tm n
var : (x : Fin n) → Tm n
ƛ : (t : Tm (suc n)) → Tm n
_·_ : (t₁ t₂ : Tm n) → Tm n
-- Convenient helper.
vr : ∀ m {n} {m<n : True (suc m ≤? n)} → Tm n
vr _ {m<n = m<n} = var (#_ _ {m<n = m<n})
------------------------------------------------------------------------
-- Values, potentially with free variables
module WHNF where
data Value (n : ℕ) : Set where
con : (i : ℕ) → Value n
ƛ : (t : Tm (suc n)) → Value n
⌜_⌝ : ∀ {n} → Value n → Tm n
⌜ con i ⌝ = con i
⌜ ƛ t ⌝ = ƛ t
------------------------------------------------------------------------
-- Closure-based definition of values
-- Environments and values. Defined in a module parametrised on the
-- type of terms.
module Closure (Tm : ℕ → Set) where
mutual
-- Environments.
Env : ℕ → Set
Env n = Vec Value n
-- Values. Lambdas are represented using closures, so values do
-- not contain any free variables.
data Value : Set where
con : (i : ℕ) → Value
ƛ : ∀ {n} (t : Tm (suc n)) (ρ : Env n) → Value
------------------------------------------------------------------------
-- Type system (following Leroy and Grall)
-- Recursive, simple types, defined coinductively.
infixr 8 _⇾_
data Ty : Set where
nat : Ty
_⇾_ : (σ τ : ∞ Ty) → Ty
-- Contexts.
Ctxt : ℕ → Set
Ctxt n = Vec Ty n
-- Type system.
infix 4 _⊢_∈_
data _⊢_∈_ {n} (Γ : Ctxt n) : Tm n → Ty → Set where
con : ∀ {i} → Γ ⊢ con i ∈ nat
var : ∀ {x} → Γ ⊢ var x ∈ lookup Γ x
ƛ : ∀ {t σ τ} (t∈ : ♭ σ ∷ Γ ⊢ t ∈ ♭ τ) → Γ ⊢ ƛ t ∈ σ ⇾ τ
_·_ : ∀ {t₁ t₂ σ τ} (t₁∈ : Γ ⊢ t₁ ∈ σ ⇾ τ) (t₂∈ : Γ ⊢ t₂ ∈ ♭ σ) →
Γ ⊢ t₁ · t₂ ∈ ♭ τ
------------------------------------------------------------------------
-- Example
-- A non-terminating term.
ω : Tm 0
ω = ƛ (vr 0 · vr 0)
Ω : Tm 0
Ω = ω · ω
-- Ω is well-typed.
Ω-well-typed : (τ : Ty) → [] ⊢ Ω ∈ τ
Ω-well-typed τ =
_·_ {σ = ♯ σ} {τ = ♯ τ} (ƛ (var · var)) (ƛ (var · var))
where σ = ♯ σ ⇾ ♯ τ
-- A call-by-value fix-point combinator.
Z : Tm 0
Z = ƛ (t · t)
where t = ƛ (vr 1 · ƛ (vr 1 · vr 1 · vr 0))
-- This combinator is also well-typed.
fix-well-typed :
∀ {σ τ} → [] ⊢ Z ∈ ♯ (♯ (σ ⇾ τ) ⇾ ♯ (σ ⇾ τ)) ⇾ ♯ (σ ⇾ τ)
fix-well-typed =
ƛ (_·_ {σ = υ} {τ = ♯ _}
(ƛ (var · ƛ (var · var · var)))
(ƛ (var · ƛ (var · var · var))))
where
υ : ∞ Ty
υ = ♯ (υ ⇾ ♯ _)
| 22.953488
| 72
| 0.437352
|
7c7c8ede4093135638fdb6356ad3b9a1bbef3934
| 1,716
|
agda
|
Agda
|
examples/AIM6/Path/Prelude.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/AIM6/Path/Prelude.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/AIM6/Path/Prelude.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module Prelude where
id : {A : Set} -> A -> A
id x = x
_·_ : {A B C : Set} -> (B -> C) -> (A -> B) -> (A -> C)
f · g = \ x -> f (g x)
flip : {A B C : Set} -> (A -> B -> C) -> B -> A -> C
flip f x y = f y x
Rel : Set -> Set1
Rel X = X -> X -> Set
data False : Set where
record True : Set where
tt : True
tt = _
! : {A : Set} -> A -> True
! = _
data _==_ {A : Set}(x : A) : A -> Set where
refl : x == x
subst : {A : Set}(P : A -> Set){x y : A} -> x == y -> P y -> P x
subst P refl p = p
cong : {A B : Set}(f : A -> B){x y : A} -> x == y -> f x == f y
cong f refl = refl
sym : {A : Set}{x y : A} -> x == y -> y == x
sym refl = refl
trans : {A : Set}{x y z : A} -> x == y -> y == z -> x == z
trans refl yz = yz
data _×_ (A B : Set) : Set where
_,_ : A -> B -> A × B
infixr 10 _,_
record Σ (A : Set)(B : A -> Set) : Set where
field
fst : A
snd : B fst
_,,_ : {A : Set}{B : A -> Set}(x : A) -> B x -> Σ A B
x ,, y = record { fst = x; snd = y }
private module Σp {A : Set}{B : A -> Set} = Σ {A}{B}
open Σp public
data _∨_ (A B : Set) : Set where
inl : A -> A ∨ B
inr : B -> A ∨ B
data Bool : Set where
false : Bool
true : Bool
IsTrue : Bool -> Set
IsTrue false = False
IsTrue true = True
IsFalse : Bool -> Set
IsFalse true = False
IsFalse false = True
data Inspect (b : Bool) : Set where
itsTrue : IsTrue b -> Inspect b
itsFalse : IsFalse b -> Inspect b
inspect : (b : Bool) -> Inspect b
inspect true = itsTrue _
inspect false = itsFalse _
data LeqBool : Rel Bool where
ref : {b : Bool} -> LeqBool b b
up : LeqBool false true
One : Rel True
One _ _ = True
_[×]_ : {A B : Set} -> Rel A -> Rel B -> Rel (A × B)
(R [×] S) (a₁ , b₁) (a₂ , b₂) = R a₁ a₂ × S b₁ b₂
| 19.280899
| 64
| 0.495338
|
373a1b5a5a279fff2b5955e1b4b08c03a053fd7b
| 1,224
|
agda
|
Agda
|
Prelude.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
Prelude.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | null | null | null |
Prelude.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --safe --cubical #-}
module Prelude where
open import Level public
open import Data.Sigma public
open import Function.Fiber public
open import Data.Empty public
open import Data.Unit public
open import Data.Nat public
using (ℕ; suc; zero)
open import Data.Bool public
using (Bool; true; false; bool; if_then_else_; T; _and_; _or_; not; bool′)
open import Data.Maybe public
using (Maybe; just; nothing; maybe)
open import HITs.PropositionalTruncation public
using (∥_∥; ∣_∣)
open import Function.Surjective public
using (Surjective; SplitSurjective; _↠!_; _↠_)
open import Data.Pi public
open import Function.Isomorphism public
open import Path public
open import Function public
open import Inspect public
open import Relation.Nullary.Decidable public
open import Relation.Nullary.Discrete public using (Discrete)
open import Relation.Nullary.Discrete.Properties public using (Discrete→isSet)
open import HLevels public
open import Data.Sum public
open import Equiv public
open import Data.Lift public
open import Function.Biconditional public
open import Relation.Unary public
open import Strict public
open import Strict.Properties public
open import Instance public
open import WellFounded public
| 32.210526
| 78
| 0.805556
|
436840a66be8004afd0a1565fe8d24ae6263a05a
| 16,764
|
agda
|
Agda
|
Cubical/Data/BinNat/BinNat.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Data/BinNat/BinNat.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/Data/BinNat/BinNat.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{- Binary natural numbers (Anders Mörtberg, Jan. 2019)
This file defines two representations of binary numbers. We prove that
they are equivalent to unary numbers and univalence is then used to
transport both programs and properties between the representations.
This is an example of how having computational univalence can be
useful for practical programming.
The first definition is [Binℕ] and the numbers are essentially lists
of 0/1 with no trailing zeroes (in little-endian format). The main
definitions and examples are:
- Equivalence between Binℕ and ℕ ([Binℕ≃ℕ]) with an equality obtained
using univalence ([Binℕ≡ℕ]).
- Addition on Binℕ defined by transporting addition on ℕ to Binℕ
([_+Binℕ_]) along Binℕ≡ℕ together with a proof that addition on Binℕ
is associative obtained by transporting the proof for ℕ ([+Binℕ-assoc]).
- Functions testing whether a binary number is odd or even in O(1)
([oddBinℕ], [evenBinℕ]) and the corresponding functions for ℕ
obtained by transport. Proof that odd numbers are not even
transported from Binℕ to ℕ ([oddℕnotEvenℕ]).
- An example of the structure identity principle for natural number
structures ([NatImpl]). We first prove that Binℕ≡ℕ lifts to natural
number structures ([NatImplℕ≡Binℕ]) and we then use this to
transport "+-suc : m + suc n ≡ suc (m + n)" from ℕ to Binℕ ([+Binℕ-suc]).
- An example of program/data refinement using the structure identity
principle where we transport a property that is infeasible to prove
by computation for ℕ ([propDoubleℕ]):
2^20 · 2^10 = 2^5 · (2^15 · 2^10)
from the corresponding result on Binℕ which is proved instantly by
refl ([propDoubleBinℕ]).
These examples are inspired from an old cubicaltt formalization:
https://github.com/mortberg/cubicaltt/blob/master/examples/binnat.ctt
which itself is based on an even older cubical formalization (from 2014):
https://github.com/simhu/cubical/blob/master/examples/binnat.cub
The second representation is more non-standard and inspired by:
https://github.com/RedPRL/redtt/blob/master/library/cool/nats.red
Only some of the experiments have been done for this representation,
but it has the virtue of being a bit simpler to prove equivalent to
ℕ. The same representation can be found in:
http://www.cs.bham.ac.uk/~mhe/agda-new/BinaryNaturals.html
-}
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Data.BinNat.BinNat where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Nat
open import Cubical.Data.Bool
open import Cubical.Data.Empty
open import Cubical.Relation.Nullary
data Binℕ : Type₀
data Pos : Type₀
-- Binary natural numbers
data Binℕ where
binℕ0 : Binℕ
binℕpos : Pos → Binℕ
-- Positive binary numbers
data Pos where
x0 : Pos → Pos
x1 : Binℕ → Pos
pattern pos1 = x1 binℕ0
pattern x1-pos n = x1 (binℕpos n)
-- Note on notation:
-- We use "⇒" for functions that are equivalences (and therefore
-- they don't preserve the numerical value where the ranges don't
-- match, as with Binℕ⇒Pos).
--
-- We use "→" for the opposite situation (numerical value is preserved,
-- but the function is not necessarily an equivalence)
Binℕ⇒Pos : Binℕ → Pos
sucPos : Pos → Pos
Binℕ⇒Pos binℕ0 = pos1
Binℕ⇒Pos (binℕpos n) = sucPos n
sucPos (x0 ps) = x1-pos ps
sucPos (x1 ps) = x0 (Binℕ⇒Pos ps)
Binℕ→ℕ : Binℕ → ℕ
Pos⇒ℕ : Pos → ℕ
Pos→ℕ : Pos → ℕ
Binℕ→ℕ binℕ0 = zero
Binℕ→ℕ (binℕpos x) = Pos→ℕ x
Pos→ℕ ps = suc (Pos⇒ℕ ps)
Pos⇒ℕ (x0 ps) = suc (doubleℕ (Pos⇒ℕ ps))
Pos⇒ℕ (x1 ps) = doubleℕ (Binℕ→ℕ ps)
posInd : {P : Pos → Type₀} → P pos1 → ((p : Pos) → P p → P (sucPos p)) → (p : Pos) → P p
posInd {P} h1 hs ps = f ps
where
H : (p : Pos) → P (x0 p) → P (x0 (sucPos p))
H p hx0p = hs (x1-pos p) (hs (x0 p) hx0p)
f : (ps : Pos) → P ps
f pos1 = h1
f (x0 ps) = posInd (hs pos1 h1) H ps
f (x1-pos ps) = hs (x0 ps) (posInd (hs pos1 h1) H ps)
Binℕ⇒Pos⇒ℕ : (p : Binℕ) → Pos⇒ℕ (Binℕ⇒Pos p) ≡ Binℕ→ℕ p
Binℕ⇒Pos⇒ℕ binℕ0 = refl
Binℕ⇒Pos⇒ℕ (binℕpos (x0 p)) = refl
Binℕ⇒Pos⇒ℕ (binℕpos (x1 x)) = λ i → suc (doubleℕ (Binℕ⇒Pos⇒ℕ x i))
Pos⇒ℕsucPos : (p : Pos) → Pos⇒ℕ (sucPos p) ≡ suc (Pos⇒ℕ p)
Pos⇒ℕsucPos p = Binℕ⇒Pos⇒ℕ (binℕpos p)
Pos→ℕsucPos : (p : Pos) → Pos→ℕ (sucPos p) ≡ suc (Pos→ℕ p)
Pos→ℕsucPos p = cong suc (Binℕ⇒Pos⇒ℕ (binℕpos p))
ℕ⇒Pos : ℕ → Pos
ℕ⇒Pos zero = pos1
ℕ⇒Pos (suc n) = sucPos (ℕ⇒Pos n)
ℕ→Pos : ℕ → Pos
ℕ→Pos zero = pos1
ℕ→Pos (suc n) = ℕ⇒Pos n
Pos⇒ℕ⇒Pos : (p : Pos) → ℕ⇒Pos (Pos⇒ℕ p) ≡ p
Pos⇒ℕ⇒Pos p = posInd refl hs p
where
hs : (p : Pos) → ℕ⇒Pos (Pos⇒ℕ p) ≡ p → ℕ⇒Pos (Pos⇒ℕ (sucPos p)) ≡ sucPos p
hs p hp =
ℕ⇒Pos (Pos⇒ℕ (sucPos p)) ≡⟨ cong ℕ⇒Pos (Pos⇒ℕsucPos p) ⟩
sucPos (ℕ⇒Pos (Pos⇒ℕ p)) ≡⟨ cong sucPos hp ⟩
sucPos p ∎
ℕ⇒Pos⇒ℕ : (n : ℕ) → Pos⇒ℕ (ℕ⇒Pos n) ≡ n
ℕ⇒Pos⇒ℕ zero = refl
ℕ⇒Pos⇒ℕ (suc n) =
Pos⇒ℕ (ℕ⇒Pos (suc n)) ≡⟨ Pos⇒ℕsucPos (ℕ⇒Pos n) ⟩
suc (Pos⇒ℕ (ℕ⇒Pos n)) ≡⟨ cong suc (ℕ⇒Pos⇒ℕ n) ⟩
suc n ∎
ℕ→Binℕ : ℕ → Binℕ
ℕ→Binℕ zero = binℕ0
ℕ→Binℕ (suc n) = binℕpos (ℕ⇒Pos n)
ℕ→Binℕ→ℕ : (n : ℕ) → Binℕ→ℕ (ℕ→Binℕ n) ≡ n
ℕ→Binℕ→ℕ zero = refl
ℕ→Binℕ→ℕ (suc n) = cong suc (ℕ⇒Pos⇒ℕ n)
Binℕ→ℕ→Binℕ : (n : Binℕ) → ℕ→Binℕ (Binℕ→ℕ n) ≡ n
Binℕ→ℕ→Binℕ binℕ0 = refl
Binℕ→ℕ→Binℕ (binℕpos p) = cong binℕpos (Pos⇒ℕ⇒Pos p)
Binℕ≃ℕ : Binℕ ≃ ℕ
Binℕ≃ℕ = isoToEquiv (iso Binℕ→ℕ ℕ→Binℕ ℕ→Binℕ→ℕ Binℕ→ℕ→Binℕ)
-- Use univalence (in fact only "ua") to get an equality from the
-- above equivalence
Binℕ≡ℕ : Binℕ ≡ ℕ
Binℕ≡ℕ = ua Binℕ≃ℕ
sucBinℕ : Binℕ → Binℕ
sucBinℕ x = binℕpos (Binℕ⇒Pos x)
Binℕ→ℕsuc : (x : Binℕ) → suc (Binℕ→ℕ x) ≡ Binℕ→ℕ (sucBinℕ x)
Binℕ→ℕsuc binℕ0 = refl
Binℕ→ℕsuc (binℕpos x) = sym (Pos→ℕsucPos x)
-- We can transport addition on ℕ to Binℕ
_+Binℕ_ : Binℕ → Binℕ → Binℕ
_+Binℕ_ = transport (λ i → Binℕ≡ℕ (~ i) → Binℕ≡ℕ (~ i) → Binℕ≡ℕ (~ i)) _+_
-- Test: 4 + 1 = 5
private
_ : binℕpos (x0 (x0 pos1)) +Binℕ binℕpos pos1 ≡ binℕpos (x1-pos (x0 pos1))
_ = refl
-- It is easy to test if binary numbers are odd
oddBinℕ : Binℕ → Bool
oddBinℕ binℕ0 = false
oddBinℕ (binℕpos (x0 _)) = false
oddBinℕ (binℕpos (x1 _)) = true
evenBinℕ : Binℕ → Bool
evenBinℕ n = oddBinℕ (sucBinℕ n)
-- And prove the following property (without induction)
oddBinℕnotEvenBinℕ : (n : Binℕ) → oddBinℕ n ≡ not (evenBinℕ n)
oddBinℕnotEvenBinℕ binℕ0 = refl
oddBinℕnotEvenBinℕ (binℕpos (x0 x)) = refl
oddBinℕnotEvenBinℕ (binℕpos (x1 x)) = refl
-- It is also easy to define and prove the property for unary numbers,
-- however the definition uses recursion and the proof induction
private
oddn : ℕ → Bool
oddn zero = true
oddn (suc x) = not (oddn x)
evenn : ℕ → Bool
evenn n = not (oddn n)
oddnSuc : (n : ℕ) → oddn n ≡ not (evenn n)
oddnSuc zero = refl
oddnSuc (suc n) = cong not (oddnSuc n)
-- So what we can do instead is to transport the odd test from Binℕ to
-- ℕ along the equality
oddℕ : ℕ → Bool
oddℕ = transport (λ i → Binℕ≡ℕ i → Bool) oddBinℕ
evenℕ : ℕ → Bool
evenℕ = transport (λ i → Binℕ≡ℕ i → Bool) evenBinℕ
-- We can then also transport the property
oddℕnotEvenℕ : (n : ℕ) → oddℕ n ≡ not (evenℕ n)
oddℕnotEvenℕ =
let -- We first build a path from oddBinℕ to oddℕ. When i=1 this is
-- "transp (λ j → Binℕ≡ℕ j → Bool) i0 oddBinℕ" (i.e. oddℕ)
oddp : PathP (λ i → Binℕ≡ℕ i → Bool) oddBinℕ oddℕ
oddp i = transp (λ j → Binℕ≡ℕ (i ∧ j) → Bool) (~ i) oddBinℕ
-- We then build a path from evenBinℕ to evenℕ
evenp : PathP (λ i → Binℕ≡ℕ i → Bool) evenBinℕ evenℕ
evenp i = transp (λ j → Binℕ≡ℕ (i ∧ j) → Bool) (~ i) evenBinℕ
in -- Then transport oddBinℕnotEvenBinℕ in a suitable equality type
-- When i=0 this is "(n : Binℕ) → oddBinℕ n ≡ not (evenBinℕ n)"
-- When i=1 this is "(n : ℕ) → oddℕ n ≡ not (evenℕ n)"
transport (λ i → (n : Binℕ≡ℕ i) → oddp i n ≡ not (evenp i n)) oddBinℕnotEvenBinℕ
-- We can do the same for natural numbers:
-- First construct the path
addp : PathP (λ i → Binℕ≡ℕ (~ i) → Binℕ≡ℕ (~ i) → Binℕ≡ℕ (~ i)) _+_ _+Binℕ_
addp i = transp (λ j → Binℕ≡ℕ (~ i ∨ ~ j) → Binℕ≡ℕ (~ i ∨ ~ j) → Binℕ≡ℕ (~ i ∨ ~ j)) (~ i) _+_
-- Then transport associativity:
+Binℕ-assoc : ∀ m n o → m +Binℕ (n +Binℕ o) ≡ (m +Binℕ n) +Binℕ o
+Binℕ-assoc =
transport (λ i → (m n o : Binℕ≡ℕ (~ i))
→ addp i m (addp i n o) ≡ addp i (addp i m n) o) +-assoc
-- We can also define what it means to be an implementation of natural
-- numbers and use this to transport properties between different
-- implementation of natural numbers. This can be seen as a special
-- case of the structure identity principle: any property that holds
-- for one structure also holds for an equivalent one.
-- An implementation of natural numbers (i.e. a "natural number
-- structure") has a zero and successor.
record NatImpl (A : Type₀) : Type₀ where
field
z : A
s : A → A
open NatImpl
NatImplℕ : NatImpl ℕ
z NatImplℕ = zero
s NatImplℕ = suc
NatImplBinℕ : NatImpl Binℕ
z NatImplBinℕ = binℕ0
s NatImplBinℕ = sucBinℕ
-- Using the equality between binary and unary numbers we can get an
-- equality between the two implementations of the NatImpl interface
NatImplℕ≡Binℕ : PathP (λ i → NatImpl (Binℕ≡ℕ (~ i))) NatImplℕ NatImplBinℕ
z (NatImplℕ≡Binℕ i) = transp (λ j → Binℕ≡ℕ (~ i ∨ ~ j)) (~ i) zero
s (NatImplℕ≡Binℕ i) =
λ x → glue (λ { (i = i0) → suc x
; (i = i1) → sucBinℕ x })
-- We need to do use and hcomp to do and endpoint
-- correction as "suc (unglue x)" connects "suc x"
-- with "suc (Binℕ→ℕ x)" along i (which makes sense as
-- x varies from ℕ to Binℕ along i), but we need
-- something from "suc x" to "Binℕ→ℕ (sucBinℕ x)" for
-- the glue to be well-formed
(hcomp (λ j → λ { (i = i0) → suc x
; (i = i1) → Binℕ→ℕsuc x j })
(suc (unglue (i ∨ ~ i) x)))
-- We then use this to transport +-suc from unary to binary numbers
+Binℕ-suc : ∀ m n → m +Binℕ sucBinℕ n ≡ sucBinℕ (m +Binℕ n)
+Binℕ-suc =
transport (λ i → (m n : Binℕ≡ℕ (~ i))
→ addp i m (NatImplℕ≡Binℕ i .s n) ≡ NatImplℕ≡Binℕ i .s (addp i m n)) +-suc
-- Doubling experiment: we define a notion of "doubling structure" and
-- transport a proof that is proved directly using refl for binary
-- numbers to unary numbers. This is an example of program/data
-- refinement: we can use univalence to prove properties about
-- inefficient data-structures using efficient ones.
-- Doubling structures
record Double {ℓ} (A : Type ℓ) : Type (ℓ-suc ℓ) where
field
-- doubling function computing 2 · x
double : A → A
-- element to double
elt : A
open Double
-- Compute: 2^n · x
doubles : ∀ {ℓ} {A : Type ℓ} (D : Double A) → ℕ → A → A
doubles D n x = iter n (double D) x
Doubleℕ : Double ℕ
double Doubleℕ = doubleℕ
elt Doubleℕ = n1024
where
-- 1024 = 2^8 · 2^2 = 2^10
n1024 : ℕ
n1024 = doublesℕ 8 4
-- The doubling operation on binary numbers is O(1), while for unary
-- numbers it is O(n). What is of course even more problematic is that
-- we cannot handle very big unary natural numbers, but with binary
-- there is no problem to represent very big numbers
doubleBinℕ : Binℕ → Binℕ
doubleBinℕ binℕ0 = binℕ0
doubleBinℕ (binℕpos x) = binℕpos (x0 x)
DoubleBinℕ : Double Binℕ
double DoubleBinℕ = doubleBinℕ
elt DoubleBinℕ = bin1024
where
-- 1024 = 2^10 = 10000000000₂
bin1024 : Binℕ
bin1024 = binℕpos (x0 (x0 (x0 (x0 (x0 (x0 (x0 (x0 (x0 (x0 pos1))))))))))
-- As these function don't commute strictly we have to prove it
-- separately and insert it in the proof of DoubleBinℕ≡Doubleℕ below
-- (just like we had to in NatImplℕ≡NatImplBinℕ
Binℕ→ℕdouble : (x : Binℕ) → doubleℕ (Binℕ→ℕ x) ≡ Binℕ→ℕ (doubleBinℕ x)
Binℕ→ℕdouble binℕ0 = refl
Binℕ→ℕdouble (binℕpos x) = refl
-- We use the equality between Binℕ and ℕ to get an equality of
-- doubling structures
DoubleBinℕ≡Doubleℕ : PathP (λ i → Double (Binℕ≡ℕ i)) DoubleBinℕ Doubleℕ
double (DoubleBinℕ≡Doubleℕ i) =
λ x → glue (λ { (i = i0) → doubleBinℕ x
; (i = i1) → doubleℕ x })
(hcomp (λ j → λ { (i = i0) → Binℕ→ℕdouble x j
; (i = i1) → doubleℕ x })
(doubleℕ (unglue (i ∨ ~ i) x)))
elt (DoubleBinℕ≡Doubleℕ i) = transp (λ j → Binℕ≡ℕ (i ∨ ~ j)) i (Doubleℕ .elt)
-- We can now use transport to prove a property that is too slow to
-- check with unary numbers. We define the property we want to check
-- as a record so that Agda does not try to unfold it eagerly.
record propDouble {ℓ} {A : Type ℓ} (D : Double A) : Type ℓ where
field
-- 2^20 · e = 2^5 · (2^15 · e)
proof : doubles D 20 (elt D) ≡ doubles D 5 (doubles D 15 (elt D))
open propDouble
-- The property we want to prove takes too long to typecheck for ℕ:
-- propDoubleℕ : propDouble Doubleℕ
-- propDoubleℕ = refl
-- With binary numbers it is instant
propDoubleBinℕ : propDouble DoubleBinℕ
proof propDoubleBinℕ = refl
-- By transporting the proof along the equality we then get it for
-- unary numbers
propDoubleℕ : propDouble Doubleℕ
propDoubleℕ = transport (λ i → propDouble (DoubleBinℕ≡Doubleℕ i)) propDoubleBinℕ
--------------------------------------------------------------------------------
--
-- Alternative encoding of binary natural numbers inspired by:
-- https://github.com/RedPRL/redtt/blob/master/library/cool/nats.red
--
-- This representation makes the equivalence with ℕ a bit easier to
-- prove, but the doubling example wouldn't work as nicely as we
-- cannot define it as an O(1) operation
data binnat : Type₀ where
zero : binnat -- 0
consOdd : binnat → binnat -- 2·n + 1
consEven : binnat → binnat -- 2·{n+1}
binnat→ℕ : binnat → ℕ
binnat→ℕ zero = 0
binnat→ℕ (consOdd n) = suc (doubleℕ (binnat→ℕ n))
binnat→ℕ (consEven n) = suc (suc (doubleℕ (binnat→ℕ n)))
suc-binnat : binnat → binnat
suc-binnat zero = consOdd zero
suc-binnat (consOdd n) = consEven n
suc-binnat (consEven n) = consOdd (suc-binnat n)
ℕ→binnat : ℕ → binnat
ℕ→binnat zero = zero
ℕ→binnat (suc n) = suc-binnat (ℕ→binnat n)
binnat→ℕ-suc : (n : binnat) → binnat→ℕ (suc-binnat n) ≡ suc (binnat→ℕ n)
binnat→ℕ-suc zero = refl
binnat→ℕ-suc (consOdd n) = refl
binnat→ℕ-suc (consEven n) = λ i → suc (doubleℕ (binnat→ℕ-suc n i))
ℕ→binnat→ℕ : (n : ℕ) → binnat→ℕ (ℕ→binnat n) ≡ n
ℕ→binnat→ℕ zero = refl
ℕ→binnat→ℕ (suc n) = (binnat→ℕ-suc (ℕ→binnat n)) ∙ (cong suc (ℕ→binnat→ℕ n))
suc-ℕ→binnat-double : (n : ℕ) → suc-binnat (ℕ→binnat (doubleℕ n)) ≡ consOdd (ℕ→binnat n)
suc-ℕ→binnat-double zero = refl
suc-ℕ→binnat-double (suc n) = λ i → suc-binnat (suc-binnat (suc-ℕ→binnat-double n i))
binnat→ℕ→binnat : (n : binnat) → ℕ→binnat (binnat→ℕ n) ≡ n
binnat→ℕ→binnat zero = refl
binnat→ℕ→binnat (consOdd n) =
(suc-ℕ→binnat-double (binnat→ℕ n)) ∙ (cong consOdd (binnat→ℕ→binnat n))
binnat→ℕ→binnat (consEven n) =
(λ i → suc-binnat (suc-ℕ→binnat-double (binnat→ℕ n) i)) ∙ (cong consEven (binnat→ℕ→binnat n))
ℕ≃binnat : ℕ ≃ binnat
ℕ≃binnat = isoToEquiv (iso ℕ→binnat binnat→ℕ binnat→ℕ→binnat ℕ→binnat→ℕ)
ℕ≡binnat : ℕ ≡ binnat
ℕ≡binnat = ua ℕ≃binnat
-- We can transport addition on ℕ to binnat
_+binnat_ : binnat → binnat → binnat
_+binnat_ = transport (λ i → ℕ≡binnat i → ℕ≡binnat i → ℕ≡binnat i) _+_
-- Test: 4 + 1 = 5
_ : consEven (consOdd zero) +binnat consOdd zero ≡ consOdd (consEven zero)
_ = refl
oddbinnat : binnat → Bool
oddbinnat zero = false
oddbinnat (consOdd _) = true
oddbinnat (consEven _) = false
oddℕ' : ℕ → Bool
oddℕ' = transport (λ i → ℕ≡binnat (~ i) → Bool) oddbinnat
-- The NatImpl example for this representation of binary numbers
private
NatImplbinnat : NatImpl binnat
z NatImplbinnat = zero
s NatImplbinnat = suc-binnat
-- Note that the s case is a bit simpler as no end-point correction
-- is necessary (things commute strictly)
NatImplℕ≡NatImplbinnat : PathP (λ i → NatImpl (ℕ≡binnat i)) NatImplℕ NatImplbinnat
z (NatImplℕ≡NatImplbinnat i) = transp (λ j → ℕ≡binnat (i ∨ ~ j)) i zero
s (NatImplℕ≡NatImplbinnat i) =
λ x → glue (λ { (i = i0) → suc x
; (i = i1) → suc-binnat x })
(suc-binnat (unglue (i ∨ ~ i) x))
oddSuc : (n : binnat) → oddbinnat n ≡ not (oddbinnat (suc-binnat n))
oddSuc zero = refl
oddSuc (consOdd _) = refl
oddSuc (consEven _) = refl
oddℕSuc' : (n : ℕ) → oddℕ' n ≡ not (oddℕ' (suc n))
oddℕSuc' =
let eq : (i : I) → ℕ≡binnat (~ i) → Bool
eq i = transp (λ j → ℕ≡binnat (~ i ∨ ~ j) → Bool) (~ i) oddbinnat
in transport
(λ i → (n : ℕ≡binnat (~ i)) → eq i n ≡ not (eq i (NatImplℕ≡NatImplbinnat (~ i) .NatImpl.s n)))
oddSuc
| 34.004057
| 104
| 0.645848
|
5209f31731741dbaca5638114dc572dc7d23cf22
| 67
|
agda
|
Agda
|
test/Succeed/Issue2487/Infective.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 2
|
2019-10-29T09:40:30.000Z
|
2020-09-20T00:28:57.000Z
|
test/Succeed/Issue2487/Infective.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/Succeed/Issue2487/Infective.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
{-# OPTIONS --cubical --prop #-}
module Issue2487.Infective where
| 16.75
| 32
| 0.701493
|
7cbf8000ab8ca91c9e2fbe658074d9b8a1489536
| 450
|
agda
|
Agda
|
zerepoch-metatheory/test/AddInteger.agda
|
Quantum-One-DLT/zerepoch
|
c8cf4619e6e496930c9092cf6d64493eff300177
|
[
"Apache-2.0"
] | null | null | null |
zerepoch-metatheory/test/AddInteger.agda
|
Quantum-One-DLT/zerepoch
|
c8cf4619e6e496930c9092cf6d64493eff300177
|
[
"Apache-2.0"
] | null | null | null |
zerepoch-metatheory/test/AddInteger.agda
|
Quantum-One-DLT/zerepoch
|
c8cf4619e6e496930c9092cf6d64493eff300177
|
[
"Apache-2.0"
] | 2
|
2021-11-13T21:25:19.000Z
|
2022-02-21T16:38:59.000Z
|
module test.AddInteger where
open import Type
open import Declarative
open import Builtin
open import Builtin.Constant.Type
open import Builtin.Constant.Term Ctx⋆ Kind * # _⊢⋆_ con size⋆
open import Agda.Builtin.Sigma
-- zerepoch/zerepoch-core/test/data/addInteger.plc
addI : ∀{Γ} →
Γ ⊢ con integer (size⋆ 8) ⇒ con integer (size⋆ 8) ⇒ con integer (size⋆ 8)
addI =
ƛ (ƛ (builtin addInteger (λ { Z → size⋆ 8 ; (S ())}) (` (S Z) Σ., ` Z Σ., _)))
| 28.125
| 80
| 0.68
|
37dc86c2917f7967c9a994e9bab8646443922a1c
| 3,777
|
agda
|
Agda
|
src/Categories/Functor/Cartesian.agda
|
yourboynico/agda-categories
|
6a087c592dbe58fc4bd9d02e1be9b94a9e138aca
|
[
"MIT"
] | 279
|
2019-06-01T14:36:40.000Z
|
2022-03-22T00:40:14.000Z
|
src/Categories/Functor/Cartesian.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 236
|
2019-06-01T14:53:54.000Z
|
2022-03-28T14:31:43.000Z
|
src/Categories/Functor/Cartesian.agda
|
seanpm2001/agda-categories
|
d9e4f578b126313058d105c61707d8c8ae987fa8
|
[
"MIT"
] | 64
|
2019-06-02T16:58:15.000Z
|
2022-03-14T02:00:59.000Z
|
{-# OPTIONS --without-K --safe #-}
-- A cartesian functor preserves products (of cartesian categories)
module Categories.Functor.Cartesian where
open import Level
open import Categories.Category.BinaryProducts
open import Categories.Category.Cartesian.Bundle using (CartesianCategory)
open import Categories.Functor using (Functor; _∘F_)
open import Categories.Functor.Properties
import Categories.Object.Product as P
import Categories.Object.Terminal as ⊤
import Categories.Morphism as M
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ e o′ ℓ′ e′ : Level
record IsCartesianF (C : CartesianCategory o ℓ e) (D : CartesianCategory o′ ℓ′ e′)
(F : Functor (CartesianCategory.U C) (CartesianCategory.U D)) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
private
module C = CartesianCategory C
module D = CartesianCategory D
open P D.U
open M D.U
open Functor F
module PC = BinaryProducts C.products
module PD = BinaryProducts D.products
module TC = ⊤.Terminal C.terminal
module TD = ⊤.Terminal D.terminal
field
F-resp-⊤ : ⊤.IsTerminal D.U (F₀ TC.⊤)
F-resp-× : ∀ {A B} → IsProduct {P = F₀ (A PC.× B)} (F₁ PC.π₁) (F₁ PC.π₂)
module F-resp-⊤ = ⊤.IsTerminal F-resp-⊤
module F-resp-× {A B} = IsProduct (F-resp-× {A} {B})
F-prod : ∀ A B → Product (F₀ A) (F₀ B)
F-prod _ _ = IsProduct⇒Product F-resp-×
module F-prod A B = Product (F-prod A B)
F-resp-⟨⟩ : ∀ {A B X} → (f : X C.⇒ A) (g : X C.⇒ B) → PD.⟨ F₁ PC.π₁ , F₁ PC.π₂ ⟩ D.∘ F₁ PC.⟨ f , g ⟩ D.≈ PD.⟨ F₁ f , F₁ g ⟩
F-resp-⟨⟩ f g = begin
PD.⟨ F₁ PC.π₁ , F₁ PC.π₂ ⟩ D.∘ F₁ PC.⟨ f , g ⟩ ≈⟨ PD.⟨⟩∘ ⟩
PD.⟨ F₁ PC.π₁ D.∘ F₁ PC.⟨ f , g ⟩ , F₁ PC.π₂ D.∘ F₁ PC.⟨ f , g ⟩ ⟩ ≈⟨ PD.⟨⟩-cong₂ ([ F ]-resp-∘ PC.project₁) ([ F ]-resp-∘ PC.project₂) ⟩
PD.⟨ F₁ f , F₁ g ⟩ ∎
where open D.HomReasoning
⊤-iso : F₀ TC.⊤ ≅ TD.⊤
⊤-iso = ⊤.up-to-iso D.U (record { ⊤-is-terminal = F-resp-⊤ }) D.terminal
module ⊤-iso = _≅_ ⊤-iso
×-iso : ∀ A B → F₀ (A PC.× B) ≅ F₀ A PD.× F₀ B
×-iso A B = record
{ from = PD.⟨ F₁ PC.π₁ , F₁ PC.π₂ ⟩
; to = F-resp-×.⟨ PD.π₁ , PD.π₂ ⟩
; iso = record
{ isoˡ = begin
F-resp-×.⟨ PD.π₁ , PD.π₂ ⟩ D.∘ PD.⟨ F₁ PC.π₁ , F₁ PC.π₂ ⟩ ≈⟨ [ F-prod A B ]⟨⟩∘ ⟩
F-resp-×.⟨ PD.π₁ D.∘ _ , PD.π₂ D.∘ _ ⟩ ≈⟨ F-prod.⟨⟩-cong₂ A B PD.project₁ PD.project₂ ⟩
F-resp-×.⟨ F₁ PC.π₁ , F₁ PC.π₂ ⟩ ≈⟨ F-prod.η A B ⟩
D.id ∎
; isoʳ = begin
PD.⟨ F₁ PC.π₁ , F₁ PC.π₂ ⟩ D.∘ F-resp-×.⟨ PD.π₁ , PD.π₂ ⟩ ≈⟨ PD.⟨⟩∘ ⟩
PD.⟨ F₁ PC.π₁ D.∘ _ , F₁ PC.π₂ D.∘ _ ⟩ ≈⟨ PD.⟨⟩-cong₂ (F-prod.project₁ A B) (F-prod.project₂ A B) ⟩
PD.⟨ PD.π₁ , PD.π₂ ⟩ ≈⟨ PD.η ⟩
D.id ∎
}
}
where open D.HomReasoning
module ×-iso A B = _≅_ (×-iso A B)
F-resp-⟨⟩′ : ∀ {A B X} → (f : X C.⇒ A) (g : X C.⇒ B) → F₁ PC.⟨ f , g ⟩ D.≈ F-resp-×.⟨ F₁ f , F₁ g ⟩
F-resp-⟨⟩′ f g = begin
F₁ PC.⟨ f , g ⟩ ≈⟨ switch-fromtoˡ (×-iso _ _) (F-resp-⟨⟩ f g) ⟩
×-iso.to _ _ D.∘ PD.⟨ F₁ f , F₁ g ⟩ ≈⟨ ([ F-prod _ _ ]⟨⟩∘ ○ F-prod.⟨⟩-cong₂ _ _ PD.project₁ PD.project₂) ⟩
F-resp-×.⟨ F₁ f , F₁ g ⟩ ∎
where open MR D.U
open D.HomReasoning
record CartesianF (C : CartesianCategory o ℓ e) (D : CartesianCategory o′ ℓ′ e′) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
private
module C = CartesianCategory C
module D = CartesianCategory D
field
F : Functor C.U D.U
isCartesian : IsCartesianF C D F
open Functor F public
open IsCartesianF isCartesian public
| 38.151515
| 141
| 0.516812
|
1b63bbbb83dccc2c1639f98f95dacb1df43f09ff
| 1,931
|
agda
|
Agda
|
src/Lambda/Delay-monad/Interpreter.agda
|
nad/partiality-monad
|
f69749280969f9093e5e13884c6feb0ad2506eae
|
[
"MIT"
] | 2
|
2020-05-21T22:59:18.000Z
|
2020-07-03T08:56:08.000Z
|
src/Lambda/Delay-monad/Interpreter.agda
|
nad/partiality-monad
|
f69749280969f9093e5e13884c6feb0ad2506eae
|
[
"MIT"
] | null | null | null |
src/Lambda/Delay-monad/Interpreter.agda
|
nad/partiality-monad
|
f69749280969f9093e5e13884c6feb0ad2506eae
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- A definitional interpreter
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Lambda.Delay-monad.Interpreter where
open import Equality.Propositional
open import Prelude
open import Prelude.Size
open import Maybe equality-with-J
open import Monad equality-with-J
open import Vec.Function equality-with-J
open import Delay-monad
open import Delay-monad.Bisimilarity
open import Delay-monad.Monad
open import Lambda.Syntax hiding ([_])
open Closure Tm
------------------------------------------------------------------------
-- An interpreter monad
-- The interpreter monad.
M : ∀ {ℓ} → Size → Type ℓ → Type ℓ
M i = MaybeT (λ A → Delay A i)
-- A variant of the interpreter monad.
M′ : ∀ {ℓ} → Size → Type ℓ → Type ℓ
M′ i = MaybeT (λ A → Delay′ A i)
-- A lifted variant of later.
laterM : ∀ {i a} {A : Type a} → M′ i A → M i A
run (laterM x) = later (run x)
-- A lifted variant of weak bisimilarity.
infix 4 _≈M_
_≈M_ : ∀ {a} {A : Type a} → M ∞ A → M ∞ A → Type a
x ≈M y = run x ≈ run y
------------------------------------------------------------------------
-- The interpreter
infix 10 _∙_
mutual
⟦_⟧ : ∀ {i n} → Tm n → Env n → M i Value
⟦ con i ⟧ ρ = return (con i)
⟦ var x ⟧ ρ = return (ρ x)
⟦ ƛ t ⟧ ρ = return (ƛ t ρ)
⟦ t₁ · t₂ ⟧ ρ = ⟦ t₁ ⟧ ρ >>= λ v₁ →
⟦ t₂ ⟧ ρ >>= λ v₂ →
v₁ ∙ v₂
_∙_ : ∀ {i} → Value → Value → M i Value
con i ∙ v₂ = fail
ƛ t₁ ρ ∙ v₂ = laterM (⟦ t₁ ⟧′ (cons v₂ ρ))
⟦_⟧′ : ∀ {i n} → Tm n → Env n → M′ i Value
force (run (⟦ t ⟧′ ρ)) = run (⟦ t ⟧ ρ)
------------------------------------------------------------------------
-- An example
-- The semantics of Ω is the non-terminating computation never.
Ω-loops : ∀ {i} → [ i ] run (⟦ Ω ⟧ nil) ∼ never
Ω-loops = later λ { .force → Ω-loops }
| 24.443038
| 72
| 0.472294
|
2105592114c3a8e94ecad73ce3e5775f81ddc517
| 4,769
|
agda
|
Agda
|
test/Succeed/Issue3399.agda
|
zliu41/agda
|
73405f70bced057d24dd4bf122d53f9548544aba
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue3399.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue3399.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --cubical #-}
module _ where
open import Agda.Primitive.Cubical renaming (primINeg to ~_; primIMax to _∨_; primIMin to _∧_)
open import Agda.Builtin.Cubical.Path
open import Agda.Builtin.Cubical.Sub
open import Agda.Builtin.Cubical.Sub using () renaming (Sub to _[_↦_]; primSubOut to ouc)
open import Agda.Primitive renaming (_⊔_ to ℓ-max)
open import Agda.Builtin.Sigma
transpFill : ∀ {ℓ} {A' : Set ℓ} (φ : I)
(A : (i : I) → Set ℓ [ φ ↦ (\ _ → A') ]) →
(u0 : ouc (A i0)) →
PathP (λ i → ouc (A i)) u0 (primTransp (λ i → ouc (A i)) φ u0)
transpFill φ A u0 i = primTransp (\ j → ouc (A (i ∧ j))) (~ i ∨ φ) u0
forward : (la : Level) (A : ∀ i → Set la) (r : I) → A r → A i1
forward la A r x = primTransp (\ i → A (i ∨ r)) r x
-- gcomp^i A [ phi -> u ] u0 = hcomp^i A(1/i) [ phi -> forward A i u, ~ phi -> forward A 0 u ] (forward A 0 u0)
gcomp : ∀ {l} (A : I → Set l) (φ : I) (u : ∀ i → Partial φ (A i)) (u0 : A i0 [ φ ↦ u i0 ]) -> A i1
gcomp A φ u u0 = primHComp {A = A i1} (\ i → \ { (φ = i1) → forward _ A i (u i itIsOne); (φ = i0) → forward _ A i0 (ouc u0) })
(forward _ A i0 (ouc u0))
-- private
-- internalFiber : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) (y : B) → Set (ℓ-max ℓ ℓ')
-- internalFiber {A = A} f y = Σ A \ x → y ≡ f x
-- infix 4 _≃_
-- postulate
-- _≃_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Set (ℓ-max ℓ ℓ')
-- equivFun : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} → A ≃ B → A → B
-- equivProof : ∀ {la lt} (T : Set la) (A : Set lt) → (w : T ≃ A) → (a : A)
-- → ∀ ψ → (Partial ψ (internalFiber (equivFun w) a)) → internalFiber (equivFun w) a
-- {-# BUILTIN EQUIV _≃_ #-}
-- {-# BUILTIN EQUIVFUN equivFun #-}
-- {-# BUILTIN EQUIVPROOF equivProof #-}
-- -- This is a module so we can easily rename the primitives.
-- module GluePrims where
-- primitive
-- primGlue : ∀ {ℓ ℓ'} (A : Set ℓ) {φ : I}
-- → (T : Partial φ (Set ℓ')) → (e : PartialP φ (λ o → T o ≃ A))
-- → Set ℓ'
-- prim^glue : ∀ {ℓ ℓ'} {A : Set ℓ} {φ : I}
-- → {T : Partial φ (Set ℓ')} → {e : PartialP φ (λ o → T o ≃ A)}
-- → PartialP φ T → A → primGlue A T e
-- prim^unglue : ∀ {ℓ ℓ'} {A : Set ℓ} {φ : I}
-- → {T : Partial φ (Set ℓ')} → {e : PartialP φ (λ o → T o ≃ A)}
-- → primGlue A T e → A
-- -- Needed for transp in Glue.
-- primFaceForall : (I → I) → I
open import Agda.Builtin.Cubical.Glue public
renaming ( prim^glue to glue
; prim^unglue to unglue)
-- We uncurry Glue to make it a bit more pleasant to use
Glue : ∀ {ℓ ℓ'} (A : Set ℓ) {φ : I}
→ (Te : Partial φ (Σ (Set ℓ') \ T → T ≃ A))
→ Set ℓ'
Glue A Te = primGlue A (λ x → Te x .fst) (λ x → Te x .snd)
-- Here we test that hcomp and transp for Glue compute as expected.
-- The current implementation in Agda.TypeChecking.Primitive does not
-- guarantee that the terms are well-typed, so making sure that those
-- primitives compute to some well-typed terms helps catching typing
-- bugs.
module TestHComp {ℓ ℓ'} (A : Set ℓ) {φ : I} (Te : Partial φ (Σ (Set ℓ') \ T → T ≃ A))
(ψ : I) (u : I → Partial ψ (Glue A Te)) (u0 : Sub (Glue A Te) ψ (u i0) ) where
result : Glue A Te
result = glue {φ = φ} (\ { (φ = i1) → primHComp {A = Te itIsOne .fst} u (primSubOut u0) })
(primHComp {A = A} (\ i → \ { (ψ = i1) → unglue {φ = φ} (u i itIsOne)
; (φ = i1) → equivFun (Te itIsOne .snd)
(primHComp (\ j → \ { (ψ = i1) → u (i ∧ j) itIsOne
; (i = i0) → primSubOut u0 })
(primSubOut u0)) })
(unglue {φ = φ} (primSubOut u0)))
test : primHComp {A = Glue A Te} {ψ} u (primSubOut u0) ≡ result
test i = primHComp {A = Glue A Te} {ψ} u (primSubOut u0)
module TestTransp {ℓ ℓ'} (A : Set ℓ) {φ : I} (Te : Partial φ (Σ (Set ℓ') \ T → T ≃ A))
(u0 : (Glue A Te)) where
ψ = i0
a0 = unglue {φ = φ} u0
a1 = gcomp (\ _ → A)
φ
(\ { i (φ = i1) → equivFun (Te itIsOne .snd) (transpFill {A' = Te itIsOne .fst} ψ (\ i → inc (Te itIsOne .fst)) u0 i) })
(inc a0)
pair : PartialP φ λ o → Helpers.fiber (Te o .snd .fst) a1
pair o = equivProof (Te o .fst) A (Te o .snd) a1 φ \ { (φ = i1) → _ , Helpers.refl }
result : Glue A Te
result = glue {φ = φ} (λ o → pair o .fst) (primHComp (\ { j (φ = i1) → pair itIsOne .snd j}) a1)
test : primTransp (\ _ → Glue A Te) ψ u0 ≡ result
test = Helpers.refl
| 44.570093
| 129
| 0.484588
|
378755eabb8bbadc32759a71b4edb23d46cdece2
| 3,952
|
agda
|
Agda
|
Cats/Displayed.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | 24
|
2017-11-03T15:18:57.000Z
|
2021-08-06T05:00:46.000Z
|
Cats/Displayed.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | null | null | null |
Cats/Displayed.agda
|
JLimperg/cats
|
1ad7b243acb622d46731e9ae7029408db6e561f1
|
[
"MIT"
] | 1
|
2019-03-18T15:35:07.000Z
|
2019-03-18T15:35:07.000Z
|
{-# OPTIONS --without-K --safe #-}
module Cats.Displayed where
open import Data.Product using (Σ ; Σ-syntax ; _,_)
open import Level using (_⊔_ ; suc)
open import Relation.Binary using
(Setoid ; IsEquivalence ; Rel ; REL ; _Preserves₂_⟶_⟶_)
open import Cats.Category
record DisplayedCategory {lo la l≈} (C : Category lo la l≈) lo′ la′ l≈′
: Set (lo ⊔ la ⊔ l≈ ⊔ suc (lo′ ⊔ la′ ⊔ l≈′)) where
infixr 9 _∘_
infix 4 _≈[_]_
infixr -1 _⇒[_]_
Base = C
module Base = Category Base
private
module C = Category C
field
Obj : (c : C.Obj) → Set lo′
_⇒[_]_ : ∀ {a b} (a⁺ : Obj a) (f : a C.⇒ b) (b⁺ : Obj b) → Set la′
_≈[_]_ : ∀ {a b} {f g : a C.⇒ b} {a⁺ : Obj a} {b⁺ : Obj b}
→ a⁺ ⇒[ f ] b⁺
→ f C.≈ g
→ a⁺ ⇒[ g ] b⁺
→ Set l≈′
id : ∀ {a} {a⁺ : Obj a} → a⁺ ⇒[ C.id ] a⁺
_∘_ : ∀ {a b c} {a⁺ : Obj a} {b⁺ : Obj b} {c⁺ : Obj c}
→ {f : b C.⇒ c} {g : a C.⇒ b}
→ (f⁺ : b⁺ ⇒[ f ] c⁺) (g⁺ : a⁺ ⇒[ g ] b⁺)
→ a⁺ ⇒[ f C.∘ g ] c⁺
≈-refl : ∀ {a b} {f : a C.⇒ b} {a⁺ : Obj a} {b⁺ : Obj b} {f⁺ : a⁺ ⇒[ f ] b⁺}
→ f⁺ ≈[ C.≈.refl ] f⁺
≈-sym : ∀ {a b} {f g : a C.⇒ b} {f≈g : f C.≈ g} {a⁺ : Obj a} {b⁺ : Obj b}
→ {f⁺ : a⁺ ⇒[ f ] b⁺} {g⁺ : a⁺ ⇒[ g ] b⁺}
→ f⁺ ≈[ f≈g ] g⁺
→ g⁺ ≈[ C.≈.sym f≈g ] f⁺
≈-trans : ∀ {a b}
→ {f g h : a C.⇒ b} {f≈g : f C.≈ g} {g≈h : g C.≈ h}
→ {a⁺ : Obj a} {b⁺ : Obj b}
→ {f⁺ : a⁺ ⇒[ f ] b⁺} {g⁺ : a⁺ ⇒[ g ] b⁺} {h⁺ : a⁺ ⇒[ h ] b⁺}
→ f⁺ ≈[ f≈g ] g⁺ → g⁺ ≈[ g≈h ] h⁺
→ f⁺ ≈[ C.≈.trans f≈g g≈h ] h⁺
∘-resp : ∀ {a b c} {f g : b C.⇒ c} {h i : a C.⇒ b}
→ {f≈g : f C.≈ g} {h≈i : h C.≈ i}
→ {a⁺ : Obj a} {b⁺ : Obj b} {c⁺ : Obj c}
→ {f⁺ : b⁺ ⇒[ f ] c⁺} {g⁺ : b⁺ ⇒[ g ] c⁺}
→ {h⁺ : a⁺ ⇒[ h ] b⁺} {i⁺ : a⁺ ⇒[ i ] b⁺}
→ f⁺ ≈[ f≈g ] g⁺
→ h⁺ ≈[ h≈i ] i⁺
→ f⁺ ∘ h⁺ ≈[ C.∘-resp f≈g h≈i ] g⁺ ∘ i⁺
id-r : ∀ {a b} {f : a C.⇒ b} {a⁺ : Obj a} {b⁺ : Obj b} {f⁺ : a⁺ ⇒[ f ] b⁺}
→ f⁺ ∘ id ≈[ C.id-r ] f⁺
id-l : ∀ {a b} {f : a C.⇒ b} {a⁺ : Obj a} {b⁺ : Obj b} {f⁺ : a⁺ ⇒[ f ] b⁺}
→ id ∘ f⁺ ≈[ C.id-l ] f⁺
assoc : ∀ {a b c d} {f : c C.⇒ d} {g : b C.⇒ c} {h : a C.⇒ b}
→ {a⁺ : Obj a} {b⁺ : Obj b} {c⁺ : Obj c} {d⁺ : Obj d}
→ {f⁺ : c⁺ ⇒[ f ] d⁺} {g⁺ : b⁺ ⇒[ g ] c⁺} {h⁺ : a⁺ ⇒[ h ] b⁺}
→ (f⁺ ∘ g⁺) ∘ h⁺ ≈[ C.assoc ] f⁺ ∘ (g⁺ ∘ h⁺)
module BuildTotal
{lo la l≈} {C : Category lo la l≈} {lo′ la′ l≈′}
(D : DisplayedCategory C lo′ la′ l≈′)
where
infixr 9 _∘_
infix 4 _≈_
infixr -1 _⇒_
private
module C = Category C
module D = DisplayedCategory D
Obj : Set (lo ⊔ lo′)
Obj = Σ[ c ∈ C.Obj ] D.Obj c
_⇒_ : (a b : Obj) → Set (la ⊔ la′)
(a , a⁺) ⇒ (b , b⁺) = Σ[ f ∈ a C.⇒ b ] (a⁺ D.⇒[ f ] b⁺)
_≈_ : ∀ {a b} → Rel (a ⇒ b) (l≈ ⊔ l≈′)
(f , f⁺) ≈ (g , g⁺) = Σ[ f≈g ∈ f C.≈ g ] f⁺ D.≈[ f≈g ] g⁺
id : ∀ {a} → a ⇒ a
id = C.id , D.id
_∘_ : ∀ {a b c} → b ⇒ c → a ⇒ b → a ⇒ c
(f , f⁺) ∘ (g , g⁺) = (f C.∘ g) , (f⁺ D.∘ g⁺)
equiv : ∀ {a b} → IsEquivalence (_≈_ {a} {b})
equiv = record
{ refl = C.≈.refl , D.≈-refl
; sym = λ where
(f≈g , f⁺≈g⁺) → C.≈.sym f≈g , D.≈-sym f⁺≈g⁺
; trans = λ where
(f≈g , f⁺≈g⁺) (g≈h , g⁺≈h⁺) → C.≈.trans f≈g g≈h , D.≈-trans f⁺≈g⁺ g⁺≈h⁺
}
∘-resp : ∀ {a b c} → (_∘_ {a} {b} {c} Preserves₂ _≈_ ⟶ _≈_ ⟶ _≈_)
∘-resp (f≈g , f⁺≈g⁺) (h≈i , h⁺≈i⁺) = C.∘-resp f≈g h≈i , D.∘-resp f⁺≈g⁺ h⁺≈i⁺
id-r : ∀ {a b} {f : a ⇒ b} → f ∘ id ≈ f
id-r = C.id-r , D.id-r
id-l : ∀ {a b} {f : a ⇒ b} → id ∘ f ≈ f
id-l = C.id-l , D.id-l
assoc : ∀ {a b c d} {f : c ⇒ d} {g : b ⇒ c} {h : a ⇒ b}
→ (f ∘ g) ∘ h ≈ f ∘ (g ∘ h)
assoc = C.assoc , D.assoc
Total : Category (lo ⊔ lo′) (la ⊔ la′) (l≈ ⊔ l≈′)
Total = record
{ Obj = Obj
; _⇒_ = _⇒_
; _≈_ = _≈_
; id = id
; _∘_ = _∘_
; equiv = equiv
; ∘-resp = ∘-resp
; id-r = id-r
; id-l = id-l
; assoc = assoc
}
open BuildTotal public using (Total)
| 27.830986
| 80
| 0.367915
|
7c77a2c22b5d71dc754fd6417bf5021c61d4b241
| 980
|
agda
|
Agda
|
Cats/Category/Sets.agda
|
alessio-b-zak/cats
|
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
|
[
"MIT"
] | null | null | null |
Cats/Category/Sets.agda
|
alessio-b-zak/cats
|
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
|
[
"MIT"
] | null | null | null |
Cats/Category/Sets.agda
|
alessio-b-zak/cats
|
a3b69911c4c6ec380ddf6a0f4510d3a755734b86
|
[
"MIT"
] | null | null | null |
module Cats.Category.Sets where
open import Data.Product using (Σ ; _×_ ; proj₁ ; proj₂)
open import Level
open import Relation.Binary using (Rel ; IsEquivalence ; _Preserves₂_⟶_⟶_)
open import Relation.Binary.PropositionalEquality as ≡ using (_≡_)
open import Cats.Category.Base
open import Cats.Util.Function
open import Cats.Util.Logic.Constructive
module _ {l} {A B : Set l} where
infixr 4 _≈_
_≈_ : (f g : A → B) → Set l
f ≈ g = ∀ x → f x ≡ g x
equiv : IsEquivalence _≈_
equiv = record
{ refl = λ x → ≡.refl
; sym = λ eq x → ≡.sym (eq x)
; trans = λ eq₁ eq₂ x → ≡.trans (eq₁ x) (eq₂ x)
}
instance Sets : ∀ l → Category (suc l) l l
Sets l = record
{ Obj = Set l
; _⇒_ = λ A B → A → B
; _≈_ = _≈_
; id = id
; _∘_ = _∘_
; equiv = equiv
; ∘-resp = λ {_} {_} {_} {f} eq₁ eq₂ x
→ ≡.trans (≡.cong f (eq₂ _)) (eq₁ _)
; id-r = λ _ → ≡.refl
; id-l = λ _ → ≡.refl
; assoc = λ _ → ≡.refl
}
| 22.272727
| 74
| 0.554082
|
35be5232de773aaea4e48557a71b7576806d8793
| 45,196
|
agda
|
Agda
|
Agda/17-number-theory.agda
|
EgbertRijke/HoTT-Intro
|
0802dc8605fa709ff03773dcd3b25aa27a9691d2
|
[
"CC-BY-4.0"
] | 333
|
2018-09-26T08:33:30.000Z
|
2022-03-22T23:50:15.000Z
|
Agda/17-number-theory.agda
|
EgbertRijke/HoTT-Intro
|
0802dc8605fa709ff03773dcd3b25aa27a9691d2
|
[
"CC-BY-4.0"
] | 8
|
2019-06-18T04:16:04.000Z
|
2020-10-16T15:27:01.000Z
|
Agda/17-number-theory.agda
|
EgbertRijke/HoTT-Intro
|
0802dc8605fa709ff03773dcd3b25aa27a9691d2
|
[
"CC-BY-4.0"
] | 30
|
2018-09-26T09:08:57.000Z
|
2022-03-16T00:33:50.000Z
|
{-# OPTIONS --without-K --exact-split #-}
module 17-number-theory where
import 16-sets
open 16-sets public
-- Section 10.1 Decidability.
{- Recall that a proposition P is decidable if P + (¬ P) holds. -}
classical-Prop :
(l : Level) → UU (lsuc l)
classical-Prop l = Σ (UU-Prop l) (λ P → is-decidable (pr1 P))
is-decidable-leq-ℕ :
(m n : ℕ) → is-decidable (leq-ℕ m n)
is-decidable-leq-ℕ zero-ℕ zero-ℕ = inl star
is-decidable-leq-ℕ zero-ℕ (succ-ℕ n) = inl star
is-decidable-leq-ℕ (succ-ℕ m) zero-ℕ = inr id
is-decidable-leq-ℕ (succ-ℕ m) (succ-ℕ n) = is-decidable-leq-ℕ m n
is-decidable-le-ℕ :
(m n : ℕ) → is-decidable (le-ℕ m n)
is-decidable-le-ℕ zero-ℕ zero-ℕ = inr id
is-decidable-le-ℕ zero-ℕ (succ-ℕ n) = inl star
is-decidable-le-ℕ (succ-ℕ m) zero-ℕ = inr id
is-decidable-le-ℕ (succ-ℕ m) (succ-ℕ n) = is-decidable-le-ℕ m n
{- We show that if A is a proposition, then so is is-decidable A. -}
is-prop-is-decidable :
{l : Level} {A : UU l} → is-prop A → is-prop (is-decidable A)
is-prop-is-decidable is-prop-A =
is-prop-coprod intro-dn is-prop-A is-prop-neg
{- Not every type is decidable. -}
case-elim :
{l1 l2 : Level} {A : UU l1} {B : UU l2} →
¬ B → coprod A B → A
case-elim nb (inl a) = a
case-elim nb (inr b) = ex-falso (nb b)
simplify-not-all-2-element-types-decidable :
{l : Level} →
((X : UU l) (p : type-trunc-Prop (bool ≃ X)) → is-decidable X) →
((X : UU l) (p : type-trunc-Prop (bool ≃ X)) → X)
simplify-not-all-2-element-types-decidable d X p =
case-elim
( map-universal-property-trunc-Prop
( dn-Prop' X)
( λ e → intro-dn (map-equiv e true))
( p))
( d X p)
{-
not-all-2-element-types-decidable :
{l : Level} → ¬ ((X : UU l) (p : type-trunc-Prop (bool ≃ X)) → is-decidable X)
not-all-2-element-types-decidable d = {!simplify-not-all-2-element-types-decidable d (raise _ bool) ?!}
not-all-types-decidable :
{l : Level} → ¬ ((X : UU l) → is-decidable X)
not-all-types-decidable d =
not-all-2-element-types-decidable (λ X p → d X)
-}
{- Types with decidable equality are closed under coproducts. -}
has-decidable-equality-coprod : {l1 l2 : Level} {A : UU l1} {B : UU l2} →
has-decidable-equality A → has-decidable-equality B →
has-decidable-equality (coprod A B)
has-decidable-equality-coprod dec-A dec-B (inl x) (inl y) =
functor-coprod
( ap inl)
( λ f p → f (inv-is-equiv (is-emb-inl _ _ x y) p))
( dec-A x y)
has-decidable-equality-coprod {A = A} {B = B} dec-A dec-B (inl x) (inr y) =
inr
( λ p →
inv-is-equiv
( is-equiv-map-raise _ empty)
( Eq-coprod-eq A B (inl x) (inr y) p))
has-decidable-equality-coprod {A = A} {B = B} dec-A dec-B (inr x) (inl y) =
inr
( λ p →
inv-is-equiv
( is-equiv-map-raise _ empty)
( Eq-coprod-eq A B (inr x) (inl y) p))
has-decidable-equality-coprod dec-A dec-B (inr x) (inr y) =
functor-coprod
( ap inr)
( λ f p → f (inv-is-equiv (is-emb-inr _ _ x y) p))
( dec-B x y)
{- Decidable equality of Fin n. -}
has-decidable-equality-empty : has-decidable-equality empty
has-decidable-equality-empty ()
has-decidable-equality-unit :
has-decidable-equality unit
has-decidable-equality-unit star star = inl refl
has-decidable-equality-Fin :
(n : ℕ) → has-decidable-equality (Fin n)
has-decidable-equality-Fin zero-ℕ = has-decidable-equality-empty
has-decidable-equality-Fin (succ-ℕ n) =
has-decidable-equality-coprod
( has-decidable-equality-Fin n)
( has-decidable-equality-unit)
decidable-Eq-Fin :
(n : ℕ) (i j : Fin n) → classical-Prop lzero
decidable-Eq-Fin n i j =
pair
( pair (Id i j) (is-set-Fin n i j))
( has-decidable-equality-Fin n i j)
{- Decidable equality of ℤ. -}
has-decidable-equality-ℤ : has-decidable-equality ℤ
has-decidable-equality-ℤ =
has-decidable-equality-coprod
has-decidable-equality-ℕ
( has-decidable-equality-coprod
has-decidable-equality-unit
has-decidable-equality-ℕ)
{- Next, we show that types with decidable equality are sets. To see this, we
will construct a fiberwise equivalence with the binary relation R that is
defined by R x y := unit if (x = y), and empty otherwise. In order to define
this relation, we first define a type family over ((x = y) + ¬(x = y)) that
returns unit on the left and empty on the right. -}
splitting-decidable-equality : {l : Level} (A : UU l) (x y : A) →
is-decidable (Id x y) → UU lzero
splitting-decidable-equality A x y (inl p) = unit
splitting-decidable-equality A x y (inr f) = empty
is-prop-splitting-decidable-equality : {l : Level} (A : UU l) (x y : A) →
(t : is-decidable (Id x y)) →
is-prop (splitting-decidable-equality A x y t)
is-prop-splitting-decidable-equality A x y (inl p) = is-prop-unit
is-prop-splitting-decidable-equality A x y (inr f) = is-prop-empty
reflexive-splitting-decidable-equality : {l : Level} (A : UU l) (x : A) →
(t : is-decidable (Id x x)) → splitting-decidable-equality A x x t
reflexive-splitting-decidable-equality A x (inl p) = star
reflexive-splitting-decidable-equality A x (inr f) =
ind-empty {P = λ t → splitting-decidable-equality A x x (inr f)} (f refl)
eq-splitting-decidable-equality : {l : Level} (A : UU l) (x y : A) →
(t : is-decidable (Id x y)) →
splitting-decidable-equality A x y t → Id x y
eq-splitting-decidable-equality A x y (inl p) t = p
eq-splitting-decidable-equality A x y (inr f) t =
ind-empty {P = λ s → Id x y} t
is-set-has-decidable-equality : {l : Level} (A : UU l) →
has-decidable-equality A → is-set A
is-set-has-decidable-equality A d =
is-set-prop-in-id
( λ x y → splitting-decidable-equality A x y (d x y))
( λ x y → is-prop-splitting-decidable-equality A x y (d x y))
( λ x → reflexive-splitting-decidable-equality A x (d x x))
( λ x y → eq-splitting-decidable-equality A x y (d x y))
{- Closure of decidable types under retracts and equivalences. -}
is-decidable-retract-of :
{l1 l2 : Level} {A : UU l1} {B : UU l2} →
A retract-of B → is-decidable B → is-decidable A
is-decidable-retract-of (pair i (pair r H)) (inl b) = inl (r b)
is-decidable-retract-of (pair i (pair r H)) (inr f) = inr (f ∘ i)
is-decidable-is-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} {f : A → B}
(is-equiv-f : is-equiv f) → is-decidable B → is-decidable A
is-decidable-is-equiv {f = f} (pair (pair g G) (pair h H)) =
is-decidable-retract-of (pair f (pair h H))
is-decidable-equiv :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) →
is-decidable B → is-decidable A
is-decidable-equiv e = is-decidable-is-equiv (is-equiv-map-equiv e)
is-decidable-equiv' :
{l1 l2 : Level} {A : UU l1} {B : UU l2} (e : A ≃ B) →
is-decidable A → is-decidable B
is-decidable-equiv' e = is-decidable-equiv (inv-equiv e)
has-decidable-equality-retract-of :
{l1 l2 : Level} {A : UU l1} {B : UU l2} →
A retract-of B → has-decidable-equality B → has-decidable-equality A
has-decidable-equality-retract-of (pair i (pair r H)) d x y =
is-decidable-retract-of
( Id-retract-of-Id (pair i (pair r H)) x y)
( d (i x) (i y))
{- The well-ordering principle. -}
is-minimal-element-ℕ :
{l : Level} (P : ℕ → UU l) (n : ℕ) (p : P n) → UU l
is-minimal-element-ℕ P n p =
(m : ℕ) → P m → (leq-ℕ n m)
minimal-element-ℕ :
{l : Level} (P : ℕ → UU l) → UU l
minimal-element-ℕ P = Σ ℕ (λ n → Σ (P n) (is-minimal-element-ℕ P n))
is-minimal-element-succ-ℕ :
{l : Level} (P : ℕ → UU l) (d : (n : ℕ) → is-decidable (P n))
(m : ℕ) (pm : P (succ-ℕ m))
(is-min-m : is-minimal-element-ℕ (λ x → P (succ-ℕ x)) m pm) →
¬ (P zero-ℕ) → is-minimal-element-ℕ P (succ-ℕ m) pm
is-minimal-element-succ-ℕ P d m pm is-min-m neg-p0 zero-ℕ p0 =
ind-empty (neg-p0 p0)
is-minimal-element-succ-ℕ P d zero-ℕ pm is-min-m neg-p0 (succ-ℕ n) psuccn =
leq-zero-ℕ n
is-minimal-element-succ-ℕ P d (succ-ℕ m) pm is-min-m neg-p0 (succ-ℕ n) psuccn =
is-minimal-element-succ-ℕ (λ x → P (succ-ℕ x)) (λ x → d (succ-ℕ x)) m pm
( λ m → is-min-m (succ-ℕ m))
( is-min-m zero-ℕ)
( n)
( psuccn)
well-ordering-principle-succ-ℕ :
{l : Level} (P : ℕ → UU l) (d : (n : ℕ) → is-decidable (P n))
(n : ℕ) (p : P (succ-ℕ n)) →
is-decidable (P zero-ℕ) →
minimal-element-ℕ (λ m → P (succ-ℕ m)) → minimal-element-ℕ P
well-ordering-principle-succ-ℕ P d n p (inl p0) _ =
pair zero-ℕ (pair p0 (λ m q → leq-zero-ℕ m))
well-ordering-principle-succ-ℕ P d n p
(inr neg-p0) (pair m (pair pm is-min-m)) =
pair
( succ-ℕ m)
( pair pm
( is-minimal-element-succ-ℕ P d m pm is-min-m neg-p0))
well-ordering-principle-ℕ :
{l : Level} (P : ℕ → UU l) (d : (n : ℕ) → is-decidable (P n)) →
Σ ℕ P → minimal-element-ℕ P
well-ordering-principle-ℕ P d (pair zero-ℕ p) =
pair zero-ℕ (pair p (λ m q → leq-zero-ℕ m))
well-ordering-principle-ℕ P d (pair (succ-ℕ n) p) =
well-ordering-principle-succ-ℕ P d n p (d zero-ℕ)
( well-ordering-principle-ℕ
( λ m → P (succ-ℕ m))
( λ m → d (succ-ℕ m))
( pair n p))
-- Exercise 6.7
-- We prove that the induction principle for ℕ implies strong induction.
-- We first prove some lemmas about inequality.
is-prop-leq-ℕ :
(m n : ℕ) → is-prop (leq-ℕ m n)
is-prop-leq-ℕ zero-ℕ zero-ℕ = is-prop-unit
is-prop-leq-ℕ zero-ℕ (succ-ℕ n) = is-prop-unit
is-prop-leq-ℕ (succ-ℕ m) zero-ℕ = is-prop-empty
is-prop-leq-ℕ (succ-ℕ m) (succ-ℕ n) = is-prop-leq-ℕ m n
neg-succ-leq-ℕ :
(n : ℕ) → ¬ (leq-ℕ (succ-ℕ n) n)
neg-succ-leq-ℕ zero-ℕ = id
neg-succ-leq-ℕ (succ-ℕ n) = neg-succ-leq-ℕ n
leq-eq-left-ℕ :
{m m' : ℕ} → Id m m' → (n : ℕ) → leq-ℕ m n → leq-ℕ m' n
leq-eq-left-ℕ refl n = id
leq-eq-right-ℕ :
(m : ℕ) {n n' : ℕ} → Id n n' → leq-ℕ m n → leq-ℕ m n'
leq-eq-right-ℕ m refl = id
-- Now we begin with the proof of the theorem
fam-strong-ind-ℕ :
{ l : Level} → (ℕ → UU l) → ℕ → UU l
fam-strong-ind-ℕ P n = (m : ℕ) → (leq-ℕ m n) → P m
-- We first take care of the zero case, with appropriate computation rule.
zero-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) → P zero-ℕ → fam-strong-ind-ℕ P zero-ℕ
zero-strong-ind-ℕ P p0 zero-ℕ t = p0
zero-strong-ind-ℕ P p0 (succ-ℕ m) ()
eq-zero-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) (p0 : P zero-ℕ) (t : leq-ℕ zero-ℕ zero-ℕ) →
Id (zero-strong-ind-ℕ P p0 zero-ℕ t) p0
eq-zero-strong-ind-ℕ P p0 t = refl
-- Next, we take care of the successor case, with appropriate computation rule.
{- In the successor case, we need to define a map
fam-strong-ind-ℕ P k → fam-strong-ind-ℕ P (succ-ℕ k).
The dependent function in the codomain is defined by case analysis, where
the cases are that either m ≤ k or m = k+1.
-}
-- We use the following definition to get a map (m≤k+1) → coprod (m≤k) (m=k+1).
cases-leq-succ-ℕ :
{m n : ℕ} → leq-ℕ m (succ-ℕ n) → coprod (leq-ℕ m n) (Id m (succ-ℕ n))
cases-leq-succ-ℕ {zero-ℕ} {n} star = inl star
cases-leq-succ-ℕ {succ-ℕ m} {zero-ℕ} p =
inr (ap succ-ℕ (anti-symmetric-leq-ℕ m zero-ℕ p star))
cases-leq-succ-ℕ {succ-ℕ m} {succ-ℕ n} p =
functor-coprod id (ap succ-ℕ) (cases-leq-succ-ℕ p)
cases-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( (n : ℕ) → (fam-strong-ind-ℕ P n) → P (succ-ℕ n)) →
( n : ℕ) (H : fam-strong-ind-ℕ P n) →
( m : ℕ) ( c : coprod (leq-ℕ m n) (Id m (succ-ℕ n))) → P m
cases-succ-strong-ind-ℕ P pS n H m (inl q) = H m q
cases-succ-strong-ind-ℕ P pS n H .(succ-ℕ n) (inr refl) = pS n H
succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( k : ℕ) → (fam-strong-ind-ℕ P k) → (fam-strong-ind-ℕ P (succ-ℕ k))
succ-strong-ind-ℕ P pS k H m p =
cases-succ-strong-ind-ℕ P pS k H m (cases-leq-succ-ℕ p)
-- We use a similar case analysis to obtain the computation rule.
{-
exclusive-coprod-leq-eq-succ-ℕ :
(m n : ℕ) → leq-ℕ m n → ¬ (Id m (succ-ℕ n))
exclusive-coprod-leq-eq-succ-ℕ zero-ℕ zero-ℕ star = {!Eq-eq-ℕ!}
exclusive-coprod-leq-eq-succ-ℕ zero-ℕ (succ-ℕ n) p = {!!}
exclusive-coprod-leq-eq-succ-ℕ (succ-ℕ m) (succ-ℕ n) p = {!!}
is-prop'-coprod-leq-eq-succ :
(m n : ℕ) → is-prop' (coprod (leq-ℕ m n) (Id m (succ-ℕ n)))
is-prop'-coprod-leq-eq-succ m n =
is-prop'-exclusive-coprod
( exclusive-coprod-leq-eq-succ-ℕ m n)
( is-prop'-is-prop (is-prop-leq-ℕ m n))
( is-prop'-is-prop (is-set-ℕ m (succ-ℕ n)))
tr-eq-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k))
( n : ℕ) (H : fam-strong-ind-ℕ P n)
( m : ℕ) (p : leq-ℕ m (succ-ℕ n))
( x : coprod (leq-ℕ m n) (Id m (succ-ℕ n))) (y : P m) →
Id (succ-strong-ind-ℕ P pS n H m p) y →
Id (cases-succ-strong-ind-ℕ P pS n H m x) y
tr-eq-succ-strong-ind-ℕ P pS n H m p x y =
tr ( λ t → Id (cases-succ-strong-ind-ℕ P pS n H m t) y)
( is-prop'-coprod-leq-eq-succ m n (cases-leq-succ-ℕ p) x)
-}
cases-htpy-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( k : ℕ) (H : fam-strong-ind-ℕ P k) (m : ℕ)
( c : coprod (leq-ℕ m k) (Id m (succ-ℕ k))) →
( q : leq-ℕ m k) →
Id
( cases-succ-strong-ind-ℕ P pS k H m c)
( H m q)
cases-htpy-succ-strong-ind-ℕ P pS k H m (inl p) q =
ap (H m) (is-prop'-is-prop (is-prop-leq-ℕ m k) p q)
cases-htpy-succ-strong-ind-ℕ P pS k H m (inr α) q =
ex-falso
( neg-succ-leq-ℕ k (leq-eq-left-ℕ α k q))
htpy-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( k : ℕ) (H : fam-strong-ind-ℕ P k) (m : ℕ)
( p : leq-ℕ m (succ-ℕ k)) →
( q : leq-ℕ m k) →
Id
( succ-strong-ind-ℕ P pS k H m p)
( H m q)
htpy-succ-strong-ind-ℕ P pS k H m p q =
cases-htpy-succ-strong-ind-ℕ P pS k H m (cases-leq-succ-ℕ p) q
cases-eq-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( k : ℕ) (H : fam-strong-ind-ℕ P k)
( c : coprod (leq-ℕ (succ-ℕ k) k) (Id (succ-ℕ k) (succ-ℕ k))) →
Id ( (cases-succ-strong-ind-ℕ P pS k H (succ-ℕ k) c))
( pS k H)
cases-eq-succ-strong-ind-ℕ P pS k H (inl p) = ex-falso (neg-succ-leq-ℕ k p)
cases-eq-succ-strong-ind-ℕ P pS k H (inr α) =
ap ( (cases-succ-strong-ind-ℕ P pS k H (succ-ℕ k)) ∘ inr)
( is-prop'-is-prop (is-set-ℕ (succ-ℕ k) (succ-ℕ k)) α refl)
eq-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( k : ℕ) (H : fam-strong-ind-ℕ P k)
( p : leq-ℕ (succ-ℕ k) (succ-ℕ k)) →
Id ( (succ-strong-ind-ℕ P pS k H (succ-ℕ k) p))
( pS k H)
eq-succ-strong-ind-ℕ P pS k H p =
cases-eq-succ-strong-ind-ℕ P pS k H (cases-leq-succ-ℕ p)
{- Now that we have the base case and inductive step covered, we can proceed
by induction. -}
induction-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( fam-strong-ind-ℕ P zero-ℕ) →
( (k : ℕ) → (fam-strong-ind-ℕ P k) → (fam-strong-ind-ℕ P (succ-ℕ k))) →
( n : ℕ) → fam-strong-ind-ℕ P n
induction-strong-ind-ℕ P q0 qS zero-ℕ = q0
induction-strong-ind-ℕ P q0 qS (succ-ℕ n) =
qS n (induction-strong-ind-ℕ P q0 qS n)
computation-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( q0 : fam-strong-ind-ℕ P zero-ℕ) →
( qS : (k : ℕ) → (fam-strong-ind-ℕ P k) → (fam-strong-ind-ℕ P (succ-ℕ k))) →
( n : ℕ) →
Id ( induction-strong-ind-ℕ P q0 qS (succ-ℕ n))
( qS n (induction-strong-ind-ℕ P q0 qS n))
computation-succ-strong-ind-ℕ P q0 qS n = refl
{- However, to obtain the conclusion we need to make one more small step. -}
conclusion-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( ( n : ℕ) → fam-strong-ind-ℕ P n) → (n : ℕ) → P n
conclusion-strong-ind-ℕ P f n = f n n (reflexive-leq-ℕ n)
{- We are finally ready to put things together and define strong-ind-ℕ. -}
strong-ind-ℕ :
{ l : Level} → (P : ℕ → UU l) (p0 : P zero-ℕ) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( n : ℕ) → P n
strong-ind-ℕ P p0 pS =
conclusion-strong-ind-ℕ P
( induction-strong-ind-ℕ P
( zero-strong-ind-ℕ P p0)
( succ-strong-ind-ℕ P pS))
{- The computation rule for the base case holds by definition. -}
comp-zero-strong-ind-ℕ :
{ l : Level} → (P : ℕ → UU l) (p0 : P zero-ℕ) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
Id (strong-ind-ℕ P p0 pS zero-ℕ) p0
comp-zero-strong-ind-ℕ P p0 pS = refl
{- For the computation rule of the inductive step, we use our hard work. -}
cases-leq-succ-reflexive-leq-ℕ :
{n : ℕ} → Id (cases-leq-succ-ℕ {succ-ℕ n} {n} (reflexive-leq-ℕ n)) (inr refl)
cases-leq-succ-reflexive-leq-ℕ {zero-ℕ} = refl
cases-leq-succ-reflexive-leq-ℕ {succ-ℕ n} =
ap (functor-coprod id (ap succ-ℕ)) cases-leq-succ-reflexive-leq-ℕ
cases-eq-comp-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) (p0 : P zero-ℕ) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( n : ℕ) →
( α :
( m : ℕ) (p : leq-ℕ m n) →
Id ( induction-strong-ind-ℕ P (zero-strong-ind-ℕ P p0)
( λ k z m₁ z₁ →
cases-succ-strong-ind-ℕ P pS k z m₁ (cases-leq-succ-ℕ z₁))
n m p)
( strong-ind-ℕ P p0 pS m)) →
( m : ℕ) (p : leq-ℕ m (succ-ℕ n)) →
( q : coprod (leq-ℕ m n) (Id m (succ-ℕ n))) →
Id ( succ-strong-ind-ℕ P pS n
( induction-strong-ind-ℕ P
( zero-strong-ind-ℕ P p0)
( succ-strong-ind-ℕ P pS) n) m p)
( strong-ind-ℕ P p0 pS m)
cases-eq-comp-succ-strong-ind-ℕ P p0 pS n α m p (inl x) =
( htpy-succ-strong-ind-ℕ P pS n
( induction-strong-ind-ℕ P
( zero-strong-ind-ℕ P p0)
( succ-strong-ind-ℕ P pS) n)
m p x) ∙
( α m x)
cases-eq-comp-succ-strong-ind-ℕ P p0 pS n α .(succ-ℕ n) p (inr refl) =
( eq-succ-strong-ind-ℕ P pS n
( induction-strong-ind-ℕ P
( zero-strong-ind-ℕ P p0)
( succ-strong-ind-ℕ P pS) n)
( p)) ∙
( inv
( ap
( cases-succ-strong-ind-ℕ P pS n
( induction-strong-ind-ℕ P
( zero-strong-ind-ℕ P p0)
( λ k H m p₁ →
cases-succ-strong-ind-ℕ P pS k H m (cases-leq-succ-ℕ p₁))
n)
( succ-ℕ n))
cases-leq-succ-reflexive-leq-ℕ))
eq-comp-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) (p0 : P zero-ℕ) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( n : ℕ) →
( m : ℕ) (p : leq-ℕ m n) →
Id ( induction-strong-ind-ℕ P (zero-strong-ind-ℕ P p0)
( λ k z m₁ z₁ →
cases-succ-strong-ind-ℕ P pS k z m₁ (cases-leq-succ-ℕ z₁))
n m p)
( strong-ind-ℕ P p0 pS m)
eq-comp-succ-strong-ind-ℕ P p0 pS zero-ℕ zero-ℕ star = refl
eq-comp-succ-strong-ind-ℕ P p0 pS zero-ℕ (succ-ℕ m) ()
eq-comp-succ-strong-ind-ℕ P p0 pS (succ-ℕ n) m p =
cases-eq-comp-succ-strong-ind-ℕ P p0 pS n
( eq-comp-succ-strong-ind-ℕ P p0 pS n) m p
( cases-leq-succ-ℕ p)
comp-succ-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) (p0 : P zero-ℕ) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
( n : ℕ) →
Id (strong-ind-ℕ P p0 pS (succ-ℕ n)) (pS n (λ m p → strong-ind-ℕ P p0 pS m))
comp-succ-strong-ind-ℕ P p0 pS n =
( eq-succ-strong-ind-ℕ P pS n
( induction-strong-ind-ℕ P
( zero-strong-ind-ℕ P p0)
( succ-strong-ind-ℕ P pS)
( n))
( reflexive-leq-ℕ n)) ∙
( ap ( pS n)
( eq-htpy
( λ m → eq-htpy
( λ p → eq-comp-succ-strong-ind-ℕ P p0 pS n m p))))
total-strong-ind-ℕ :
{ l : Level} (P : ℕ → UU l) (p0 : P zero-ℕ) →
( pS : (k : ℕ) → (fam-strong-ind-ℕ P k) → P (succ-ℕ k)) →
Σ ( (n : ℕ) → P n)
( λ h →
( Id (h zero-ℕ) p0) ×
( (n : ℕ) → Id (h (succ-ℕ n)) (pS n (λ m p → h m))))
total-strong-ind-ℕ P p0 pS =
pair
( strong-ind-ℕ P p0 pS)
( pair
( comp-zero-strong-ind-ℕ P p0 pS)
( comp-succ-strong-ind-ℕ P p0 pS))
-- The Euclidean algorithm
subtract-ℕ : ℕ → ℕ → ℕ
subtract-ℕ zero-ℕ zero-ℕ = zero-ℕ
subtract-ℕ zero-ℕ (succ-ℕ b) = zero-ℕ
subtract-ℕ (succ-ℕ a) zero-ℕ = succ-ℕ a
subtract-ℕ (succ-ℕ a) (succ-ℕ b) = subtract-ℕ a b
leq-subtract-ℕ : (a b : ℕ) → leq-ℕ (subtract-ℕ a b) a
leq-subtract-ℕ zero-ℕ zero-ℕ = star
leq-subtract-ℕ zero-ℕ (succ-ℕ b) = star
leq-subtract-ℕ (succ-ℕ a) zero-ℕ = reflexive-leq-ℕ a
leq-subtract-ℕ (succ-ℕ a) (succ-ℕ b) =
transitive-leq-ℕ (subtract-ℕ a b) a (succ-ℕ a)
( leq-subtract-ℕ a b)
( succ-leq-ℕ a)
decide-order-ℕ : (a b : ℕ) → coprod (leq-ℕ b a) (le-ℕ a b)
decide-order-ℕ zero-ℕ zero-ℕ = inl star
decide-order-ℕ zero-ℕ (succ-ℕ b) = inr star
decide-order-ℕ (succ-ℕ a) zero-ℕ = inl star
decide-order-ℕ (succ-ℕ a) (succ-ℕ b) = decide-order-ℕ a b
cases-gcd-euclid :
( a b : ℕ)
( F : (x : ℕ) (p : leq-ℕ x a) → ℕ → ℕ)
( G : (y : ℕ) (q : leq-ℕ y b) → ℕ) →
( coprod (leq-ℕ b a) (le-ℕ a b)) → ℕ
cases-gcd-euclid a b F G (inl t) =
F (subtract-ℕ a b) (leq-subtract-ℕ a b) (succ-ℕ b)
cases-gcd-euclid a b F G (inr t) =
G (subtract-ℕ b a) (leq-subtract-ℕ b a)
succ-gcd-euclid : (a : ℕ) (F : (x : ℕ) → (leq-ℕ x a) → ℕ → ℕ) → ℕ → ℕ
succ-gcd-euclid a F =
strong-ind-ℕ
( λ x → ℕ)
( succ-ℕ a)
( λ b G →
ind-coprod
{ A = leq-ℕ b a}
{ B = le-ℕ a b}
( λ x → ℕ)
( λ t → F (subtract-ℕ a b) (leq-subtract-ℕ a b) (succ-ℕ b))
( λ t → G (subtract-ℕ b a) (leq-subtract-ℕ b a))
( decide-order-ℕ a b))
comp-zero-succ-gcd-euclid :
(a : ℕ) (F : (x : ℕ) → (leq-ℕ x a) → ℕ → ℕ) →
Id (succ-gcd-euclid a F zero-ℕ) (succ-ℕ a)
comp-zero-succ-gcd-euclid a F =
comp-zero-strong-ind-ℕ
( λ x → ℕ)
( succ-ℕ a)
( λ b G →
ind-coprod
{ A = leq-ℕ b a}
{ B = le-ℕ a b}
( λ x → ℕ)
( λ t → F (subtract-ℕ a b) (leq-subtract-ℕ a b) (succ-ℕ b))
( λ t → G (subtract-ℕ b a) (leq-subtract-ℕ b a))
( decide-order-ℕ a b))
comp-succ-succ-gcd-euclid :
(a : ℕ) (F : (x : ℕ) → (leq-ℕ x a) → ℕ → ℕ) (b : ℕ) →
Id (succ-gcd-euclid a F (succ-ℕ b))
( ind-coprod
{ A = leq-ℕ b a}
{ B = le-ℕ a b}
( λ x → ℕ)
( λ t → F (subtract-ℕ a b) (leq-subtract-ℕ a b) (succ-ℕ b))
( λ t → succ-gcd-euclid a F (subtract-ℕ b a))
( decide-order-ℕ a b))
comp-succ-succ-gcd-euclid a F b =
comp-succ-strong-ind-ℕ
( λ x → ℕ)
( succ-ℕ a)
( λ k z →
ind-coprod (λ _ → ℕ)
(λ x → F (subtract-ℕ a k) (leq-subtract-ℕ a k) (succ-ℕ k))
(λ y → z (subtract-ℕ k a) (leq-subtract-ℕ k a))
(decide-order-ℕ a k))
( b)
gcd-euclid : ℕ → ℕ → ℕ
gcd-euclid =
strong-ind-ℕ
( λ x → ℕ → ℕ)
( id)
( succ-gcd-euclid)
comp-succ-gcd-euclid :
(a : ℕ) →
Id (gcd-euclid (succ-ℕ a)) (succ-gcd-euclid a (λ x p → gcd-euclid x))
comp-succ-gcd-euclid =
comp-succ-strong-ind-ℕ (λ x → ℕ → ℕ) id succ-gcd-euclid
-- Properties of the greatest common divisor
left-zero-law-gcd-euclid : (gcd-euclid zero-ℕ) ~ id
left-zero-law-gcd-euclid =
htpy-eq (comp-zero-strong-ind-ℕ (λ x → ℕ → ℕ) id succ-gcd-euclid)
right-zero-law-gcd-euclid : (a : ℕ) → Id (gcd-euclid a zero-ℕ) a
right-zero-law-gcd-euclid zero-ℕ = refl
right-zero-law-gcd-euclid (succ-ℕ a) =
( ap
( λ t →
cases-succ-strong-ind-ℕ (λ x → ℕ → ℕ) succ-gcd-euclid a
( induction-strong-ind-ℕ
( λ x → ℕ → ℕ)
( zero-strong-ind-ℕ (λ x → ℕ → ℕ) (λ a₁ → a₁))
( λ k H m p →
cases-succ-strong-ind-ℕ (λ x → ℕ → ℕ) succ-gcd-euclid k H m
(cases-leq-succ-ℕ p))
( a))
( succ-ℕ a) t zero-ℕ)
cases-leq-succ-reflexive-leq-ℕ) ∙
( comp-zero-succ-gcd-euclid a (λ x _ z → z))
is-prop-le-ℕ : (a b : ℕ) → is-prop (le-ℕ a b)
is-prop-le-ℕ zero-ℕ zero-ℕ = is-prop-empty
is-prop-le-ℕ zero-ℕ (succ-ℕ b) = is-prop-unit
is-prop-le-ℕ (succ-ℕ a) zero-ℕ = is-prop-empty
is-prop-le-ℕ (succ-ℕ a) (succ-ℕ b) = is-prop-le-ℕ a b
is-prop'-le-ℕ : (a b : ℕ) → is-prop' (le-ℕ a b)
is-prop'-le-ℕ a b = is-prop'-is-prop (is-prop-le-ℕ a b)
{-
left-lesser-law-gcd-euclid : (a b : ℕ) → (le-ℕ a b) →
Id (gcd-euclid a b) (gcd-euclid a (subtract-ℕ b a))
left-lesser-law-gcd-euclid zero-ℕ (succ-ℕ b) H = refl
left-lesser-law-gcd-euclid (succ-ℕ a) (succ-ℕ b) H =
( htpy-eq (comp-succ-gcd-euclid a) (succ-ℕ b)) ∙ {!!}
-}
{- ( (comp-succ-succ-gcd-euclid a (λ x t → gcd-euclid x) b) ∙
( ( {!!} ∙ apd (λ t → (ind-coprod (λ x → ℕ)
(λ t → gcd-euclid (subtract-ℕ a b) (succ-ℕ b))
(λ t → succ-gcd-euclid a (λ x t₁ → gcd-euclid x) (subtract-ℕ b a))
t)) (ap inr (is-prop'-le-ℕ a b {!!} {!!}))) ∙ {!!}
{- ( inv (ap (λ t → cases-succ-strong-ind-ℕ (λ x → ℕ → ℕ) succ-gcd-euclid a
(induction-strong-ind-ℕ (λ x → ℕ → ℕ)
(zero-strong-ind-ℕ (λ x → ℕ → ℕ) (λ a₁ → a₁))
(λ k H₁ m p →
cases-succ-strong-ind-ℕ (λ x → ℕ → ℕ) succ-gcd-euclid k H₁ m
(cases-leq-succ-ℕ p))
a)
(succ-ℕ a) t
(subtract-ℕ (succ-ℕ b) (succ-ℕ a))) cases-leq-succ-reflexive-leq-ℕ))-}))
-}
-- We show that induction on ℕ implies ordinal induction.
fam-ordinal-ind-ℕ :
{ l : Level} → (ℕ → UU l) → ℕ → UU l
fam-ordinal-ind-ℕ P n = (m : ℕ) → (le-ℕ m n) → P m
le-zero-ℕ :
(m : ℕ) → (le-ℕ m zero-ℕ) → empty
le-zero-ℕ zero-ℕ ()
le-zero-ℕ (succ-ℕ m) ()
zero-ordinal-ind-ℕ :
{ l : Level} (P : ℕ → UU l) → fam-ordinal-ind-ℕ P zero-ℕ
zero-ordinal-ind-ℕ P m t = ind-empty (le-zero-ℕ m t)
le-one-ℕ :
(n : ℕ) → le-ℕ (succ-ℕ n) one-ℕ → empty
le-one-ℕ zero-ℕ ()
le-one-ℕ (succ-ℕ n) ()
transitive-le-ℕ' :
(k l m : ℕ) → (le-ℕ k l) → (le-ℕ l (succ-ℕ m)) → le-ℕ k m
transitive-le-ℕ' zero-ℕ zero-ℕ m () s
transitive-le-ℕ' (succ-ℕ k) zero-ℕ m () s
transitive-le-ℕ' zero-ℕ (succ-ℕ l) zero-ℕ star s = ind-empty (le-one-ℕ l s)
transitive-le-ℕ' (succ-ℕ k) (succ-ℕ l) zero-ℕ t s = ind-empty (le-one-ℕ l s)
transitive-le-ℕ' zero-ℕ (succ-ℕ l) (succ-ℕ m) star s = star
transitive-le-ℕ' (succ-ℕ k) (succ-ℕ l) (succ-ℕ m) t s =
transitive-le-ℕ' k l m t s
succ-ordinal-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( (n : ℕ) → (fam-ordinal-ind-ℕ P n) → P n) →
( k : ℕ) → fam-ordinal-ind-ℕ P k → fam-ordinal-ind-ℕ P (succ-ℕ k)
succ-ordinal-ind-ℕ P f k g m t =
f m (λ m' t' → g m' (transitive-le-ℕ' m' m k t' t))
induction-ordinal-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( qS : (k : ℕ) → fam-ordinal-ind-ℕ P k → fam-ordinal-ind-ℕ P (succ-ℕ k))
( n : ℕ) → fam-ordinal-ind-ℕ P n
induction-ordinal-ind-ℕ P qS zero-ℕ = zero-ordinal-ind-ℕ P
induction-ordinal-ind-ℕ P qS (succ-ℕ n) =
qS n (induction-ordinal-ind-ℕ P qS n)
conclusion-ordinal-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
(( n : ℕ) → fam-ordinal-ind-ℕ P n) → (n : ℕ) → P n
conclusion-ordinal-ind-ℕ P f n = f (succ-ℕ n) n (succ-le-ℕ n)
ordinal-ind-ℕ :
{ l : Level} (P : ℕ → UU l) →
( (n : ℕ) → (fam-ordinal-ind-ℕ P n) → P n) →
( n : ℕ) → P n
ordinal-ind-ℕ P f =
conclusion-ordinal-ind-ℕ P
( induction-ordinal-ind-ℕ P (succ-ordinal-ind-ℕ P f))
{- The Pigeon hole principle. -}
{- First we write a function that counts the number of elements in a decidable
subset of a finite set. -}
count-Fin-succ-ℕ :
{l : Level} (n : ℕ) (P : Fin (succ-ℕ n) → classical-Prop l) →
ℕ → is-decidable (pr1 (pr1 (P (inr star)))) → ℕ
count-Fin-succ-ℕ n P m (inl x) = succ-ℕ m
count-Fin-succ-ℕ n P m (inr x) = m
count-Fin :
{l : Level} (n : ℕ) (P : Fin n → classical-Prop l) → ℕ
count-Fin zero-ℕ P = zero-ℕ
count-Fin (succ-ℕ n) P =
count-Fin-succ-ℕ n P
( count-Fin n (P ∘ inl))
( pr2 (P (inr star)))
{- Next we prove the pigeonhole principle. -}
max-Fin :
(n : ℕ) → Fin (succ-ℕ n)
max-Fin n = inr star
contraction-Fin-one-ℕ :
(t : Fin one-ℕ) → Id (inr star) t
contraction-Fin-one-ℕ (inr star) = refl
is-contr-Fin-one-ℕ :
is-contr (Fin one-ℕ)
is-contr-Fin-one-ℕ = pair (inr star) contraction-Fin-one-ℕ
skip :
(n : ℕ) → Fin (succ-ℕ n) → Fin n → Fin (succ-ℕ n)
skip (succ-ℕ n) (inl i) (inl j) = inl (skip n i j)
skip (succ-ℕ n) (inl i) (inr star) = inr star
skip (succ-ℕ n) (inr star) j = inl j
repeat :
(n : ℕ) → Fin n → Fin (succ-ℕ n) → Fin n
repeat (succ-ℕ n) (inl i) (inl j) = inl (repeat n i j)
repeat (succ-ℕ n) (inl j) (inr star) = inr star
repeat (succ-ℕ n) (inr star) (inl j) = j
repeat (succ-ℕ n) (inr star) (inr star) = inr star
repeat-repeat :
(n : ℕ) (i j : Fin n) →
((repeat n i) ∘ (repeat (succ-ℕ n) (skip n (inl i) j))) ~
((repeat n j) ∘ (repeat (succ-ℕ n) (skip n (inl j) i)))
repeat-repeat zero-ℕ () j k
repeat-repeat (succ-ℕ n) (inl i) (inl j) (inl k) =
ap inl (repeat-repeat n i j k)
repeat-repeat (succ-ℕ n) (inl i) (inl j) (inr star) = refl
repeat-repeat (succ-ℕ n) (inl i) (inr star) (inr star) = refl
repeat-repeat (succ-ℕ n) (inr star) (inl j) (inr star) = refl
repeat-repeat (succ-ℕ n) (inr star) (inr star) (inl k) = refl
repeat-repeat (succ-ℕ n) (inr star) (inr star) (inr star) = refl
repeat-repeat (succ-ℕ zero-ℕ) (inl ()) (inr star) (inl k)
repeat-repeat (succ-ℕ (succ-ℕ n)) (inl i) (inr star) (inl k) = refl
repeat-repeat (succ-ℕ zero-ℕ) (inr star) (inl ()) (inl k)
repeat-repeat (succ-ℕ (succ-ℕ n)) (inr star) (inl j) (inl k) = refl
{-
skip-repeat :
(n : ℕ) (i : Fin n) → ((skip n (inl i)) ∘ (repeat n i)) ~ id
skip-repeat (succ-ℕ n) (inl x) (inl y) = ap inl (skip-repeat n x y)
skip-repeat (succ-ℕ n) (inl x) (inr star) = refl
skip-repeat (succ-ℕ n) (inr star) (inl (inl x)) = ap inl {!ap (skip n) ?!}
skip-repeat (succ-ℕ n) (inr star) (inl (inr star)) = {!!}
skip-repeat (succ-ℕ n) (inr star) (inr star) = {!!}
-}
map-lift-Fin :
(m n : ℕ) (f : Fin (succ-ℕ m) → Fin (succ-ℕ n))
(i : Fin (succ-ℕ n)) (H : fib f i → empty) →
Fin m → Fin n
map-lift-Fin m n f (inl i) H = (repeat n i) ∘ (f ∘ inl)
map-lift-Fin m (succ-ℕ n) f (inr star) H =
( repeat (succ-ℕ n) (max-Fin n)) ∘
( f ∘ inl)
map-lift-Fin zero-ℕ zero-ℕ f (inr star) H = ind-empty
map-lift-Fin (succ-ℕ m) zero-ℕ f (inr star) H =
ex-falso
( H (pair (inr star) (inv (contraction-Fin-one-ℕ (f (inr star))))))
{-
is-lift-lift-Fin :
(m n : ℕ) (f : Fin (succ-ℕ m) → Fin (succ-ℕ n))
(i : Fin (succ-ℕ n)) (H : fib f i → empty) →
(f ∘ inl) ~ ((skip n i) ∘ (map-lift-Fin m n f i H))
is-lift-lift-Fin m n f (inl i) H x = {!!}
is-lift-lift-Fin m n f (inr i) H x = {!!}
-}
-- The greatest common divisor
{- First we show that mul-ℕ n is an embedding whenever n > 0. In order to do
this, we have to show that add-ℕ n is injective. -}
{- FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX
is-injective-add-ℕ' :
(n : ℕ) → is-injective is-set-ℕ is-set-ℕ (add-ℕ n)
is-injective-add-ℕ' n k l p = is-injective-add-ℕ' n k l
(((commutative-add-ℕ n k) ∙ ?) ∙ (commutative-add-ℕ l n))
is-emb-add-ℕ :
(n : ℕ) → is-emb (add-ℕ n)
is-emb-add-ℕ n =
is-emb-is-injective is-set-ℕ is-set-ℕ (add-ℕ n) (is-injective-add-ℕ n)
equiv-fib-add-fib-add-ℕ' :
(m n : ℕ) → fib (add-ℕ' m) n ≃ fib (add-ℕ m) n
equiv-fib-add-fib-add-ℕ' m n =
equiv-tot (λ k → equiv-concat (commutative-add-ℕ m k) n)
leq-fib-add-ℕ' :
(m n : ℕ) → fib (add-ℕ' m) n → (leq-ℕ m n)
leq-fib-add-ℕ' zero-ℕ n (pair k p) = leq-zero-ℕ n
leq-fib-add-ℕ' (succ-ℕ m) (succ-ℕ n) (pair k p) =
leq-fib-add-ℕ' m n (pair k (is-injective-succ-ℕ (add-ℕ k m) n p))
leq-fib-add-ℕ :
(m n : ℕ) → fib (add-ℕ m) n → (leq-ℕ m n)
leq-fib-add-ℕ m .m (pair zero-ℕ refl) = reflexive-leq-ℕ m
leq-fib-add-ℕ m .(add-ℕ m (succ-ℕ k)) (pair (succ-ℕ k) refl) =
transitive-leq-ℕ m (add-ℕ m k) (succ-ℕ (add-ℕ m k))
( leq-fib-add-ℕ m (add-ℕ m k) (pair k refl))
( succ-leq-ℕ (add-ℕ m k))
-}
{-
fib-add-leq-ℕ :
(m n : ℕ) → (leq-ℕ m n) → fib (add-ℕ m) n
fib-add-leq-ℕ zero-ℕ zero-ℕ star = pair zero-ℕ refl
fib-add-leq-ℕ zero-ℕ (succ-ℕ n) star = {!!}
fib-add-leq-ℕ (succ-ℕ m) (succ-ℕ n) p = {!!}
{-
fib-add-leq-ℕ zero-ℕ zero-ℕ H = pair zero-ℕ refl
fib-add-leq-ℕ zero-ℕ (succ-ℕ n) H = pair (succ-ℕ n) refl
fib-add-leq-ℕ (succ-ℕ m) (succ-ℕ n) H =
pair
( pr1 (fib-add-leq-ℕ m n H))
( ap succ-ℕ (pr2 (fib-add-leq-ℕ m n H)))
-}
is-equiv-leq-fib-add-ℕ :
(m n : ℕ) → is-equiv (leq-fib-add-ℕ m n)
is-equiv-leq-fib-add-ℕ m n =
is-equiv-is-prop
( is-prop-map-is-emb _ (is-emb-add-ℕ m) n)
( is-prop-leq-ℕ m n)
( fib-add-leq-ℕ m n)
is-equiv-fib-add-leq-ℕ :
(m n : ℕ) → is-equiv (fib-add-leq-ℕ m n)
is-equiv-fib-add-leq-ℕ m n =
is-equiv-is-prop
( is-prop-leq-ℕ m n)
( is-prop-map-is-emb _ (is-emb-add-ℕ m) n)
( leq-fib-add-ℕ m n)
-}
is-emb-mul-ℕ :
(n : ℕ) → is-emb (mul-ℕ' (succ-ℕ n))
is-emb-mul-ℕ n =
is-emb-is-injective is-set-ℕ is-set-ℕ
( mul-ℕ' (succ-ℕ n))
( is-injective-mul-ℕ n)
{- FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX
is-emb-mul-ℕ' :
(n : ℕ) → (le-ℕ zero-ℕ n) → is-emb (λ m → mul-ℕ m n)
is-emb-mul-ℕ' n t =
is-emb-htpy'
( mul-ℕ n)
( λ m → mul-ℕ m n)
( commutative-mul-ℕ n)
( is-emb-mul-ℕ n)
-}
{- We conclude that the division relation is a property. -}
{- FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX FIX
is-prop-div-ℕ :
(m n : ℕ) → (le-ℕ zero-ℕ m) → is-prop (div-ℕ m n)
is-prop-div-ℕ (succ-ℕ m) n star =
is-prop-map-is-emb
( λ z → mul-ℕ z (succ-ℕ m))
( is-emb-mul-ℕ' (succ-ℕ m) star)
n
-}
{- We now construct the division with remainder. -}
le-mul-ℕ :
(d n k : ℕ) → UU lzero
le-mul-ℕ d n k = le-ℕ n (mul-ℕ k d)
is-decidable-le-mul-ℕ :
(d n k : ℕ) → is-decidable (le-mul-ℕ d n k)
is-decidable-le-mul-ℕ d n k =
is-decidable-le-ℕ n (mul-ℕ k d)
order-preserving-succ-ℕ :
(n n' : ℕ) → (leq-ℕ n n') → (leq-ℕ (succ-ℕ n) (succ-ℕ n'))
order-preserving-succ-ℕ n n' H = H
{-
order-preserving-add-ℕ :
(m n m' n' : ℕ) →
(leq-ℕ m m') → (leq-ℕ n n') → (leq-ℕ (add-ℕ m n) (add-ℕ m' n'))
order-preserving-add-ℕ = {!!}
-}
{-
order-preserving-add-ℕ zero-ℕ zero-ℕ m' n' Hm Hn = star
order-preserving-add-ℕ zero-ℕ (succ-ℕ n) zero-ℕ (succ-ℕ n') Hm Hn = Hn
order-preserving-add-ℕ zero-ℕ (succ-ℕ n) (succ-ℕ m') (succ-ℕ n') Hm Hn =
leq-eq-right-ℕ n
( inv (right-successor-law-add-ℕ m' n'))
( order-preserving-add-ℕ zero-ℕ n (succ-ℕ m') n' Hm Hn)
order-preserving-add-ℕ (succ-ℕ m) n (succ-ℕ m') n' Hm Hn =
order-preserving-add-ℕ m n m' n' Hm Hn
-}
le-eq-right-ℕ :
(m : ℕ) {n n' : ℕ} → Id n n' → le-ℕ m n' → le-ℕ m n
le-eq-right-ℕ m refl = id
{-
le-add-ℕ :
(m n : ℕ) → (leq-ℕ one-ℕ n) → le-ℕ m (add-ℕ m n)
le-add-ℕ = {!!}
{-
le-add-ℕ zero-ℕ (succ-ℕ n) star = star
le-add-ℕ (succ-ℕ m) (succ-ℕ n) star = le-add-ℕ m (succ-ℕ n) star
-}
le-mul-self-ℕ :
(d n : ℕ) → (leq-ℕ one-ℕ d) → (leq-ℕ one-ℕ n) → le-mul-ℕ d n n
le-mul-self-ℕ (succ-ℕ d) (succ-ℕ n) star star =
le-eq-right-ℕ
( succ-ℕ n)
( right-successor-law-mul-ℕ (succ-ℕ n) d)
( le-add-ℕ (succ-ℕ n) (mul-ℕ (succ-ℕ n) d) {!leq-eq-right-ℕ !})
-}
{-
leq-multiple-ℕ :
(n m : ℕ) → (leq-ℕ one-ℕ m) → leq-ℕ n (mul-ℕ n m)
leq-multiple-ℕ n (succ-ℕ m) H =
leq-eq-right-ℕ n
( inv (right-successor-law-mul-ℕ n m))
( leq-fib-add-ℕ n (add-ℕ n (mul-ℕ n m)) (pair (mul-ℕ n m) refl))
least-factor-least-larger-multiple-ℕ :
(d n : ℕ) → (leq-ℕ one-ℕ d) →
minimal-element-ℕ (λ k → leq-ℕ n (mul-ℕ k d))
least-factor-least-larger-multiple-ℕ d n H =
well-ordering-principle-ℕ
( λ k → leq-ℕ n (mul-ℕ k d))
( λ k → is-decidable-leq-ℕ n (mul-ℕ k d))
( pair n (leq-multiple-ℕ n d H))
factor-least-larger-multiple-ℕ :
(d n : ℕ) → (leq-ℕ one-ℕ d) → ℕ
factor-least-larger-multiple-ℕ d n H =
pr1 (least-factor-least-larger-multiple-ℕ d n H)
least-larger-multiple-ℕ :
(d n : ℕ) → (leq-ℕ one-ℕ d) → ℕ
least-larger-multiple-ℕ d n H =
mul-ℕ (factor-least-larger-multiple-ℕ d n H) d
leq-least-larger-multiple-ℕ :
(d n : ℕ) (H : leq-ℕ one-ℕ d) →
leq-ℕ n (least-larger-multiple-ℕ d n H)
leq-least-larger-multiple-ℕ d n H =
pr1 (pr2 (least-factor-least-larger-multiple-ℕ d n H))
is-minimal-least-larger-multiple-ℕ :
(d n : ℕ) (H : leq-ℕ one-ℕ d) (k : ℕ) (K : leq-ℕ n (mul-ℕ k d)) →
leq-ℕ (factor-least-larger-multiple-ℕ d n H) k
is-minimal-least-larger-multiple-ℕ d n H =
pr2 (pr2 (least-factor-least-larger-multiple-ℕ d n H))
-}
{-
is-decidable-div-is-decidable-eq-least-larger-multiple-ℕ :
(d n : ℕ) (H : leq-ℕ one-ℕ d) →
is-decidable (Id (least-larger-multiple-ℕ d n H) n) → is-decidable (div-ℕ d n)
is-decidable-div-is-decidable-eq-least-larger-multiple-ℕ d n H (inl p) =
inl (pair (factor-least-larger-multiple-ℕ d n H) p)
is-decidable-div-is-decidable-eq-least-larger-multiple-ℕ d n H (inr f) =
inr (λ x → {!!})
is-decidable-div-ℕ' :
(d n : ℕ) → (leq-ℕ one-ℕ d) → is-decidable (div-ℕ d n)
is-decidable-div-ℕ' d n H = {!!}
is-decidable-div-ℕ :
(d n : ℕ) → is-decidable (div-ℕ d n)
is-decidable-div-ℕ zero-ℕ zero-ℕ = inl (pair zero-ℕ refl)
is-decidable-div-ℕ zero-ℕ (succ-ℕ n) =
inr ( λ p →
Eq-ℕ-eq {-zero-ℕ (succ-ℕ n)-} ((inv (right-zero-law-mul-ℕ (pr1 p))) ∙ (pr2 p)))
is-decidable-div-ℕ (succ-ℕ d) n =
is-decidable-div-ℕ' (succ-ℕ d) n (leq-zero-ℕ d)
-}
-- Operations on decidable bounded subsets of ℕ
iterated-operation-ℕ :
(strict-upper-bound : ℕ) (operation : ℕ → ℕ → ℕ) (base-value : ℕ) → ℕ
iterated-operation-ℕ zero-ℕ μ e = e
iterated-operation-ℕ (succ-ℕ b) μ e = μ (iterated-operation-ℕ b μ e) b
iterated-sum-ℕ :
(summand : ℕ → ℕ) (b : ℕ) → ℕ
iterated-sum-ℕ f zero-ℕ = zero-ℕ
iterated-sum-ℕ f (succ-ℕ b) = add-ℕ (iterated-sum-ℕ f b) (f (succ-ℕ b))
ranged-sum-ℕ :
(summand : ℕ → ℕ) (l u : ℕ) → ℕ
ranged-sum-ℕ f zero-ℕ u = iterated-sum-ℕ f u
ranged-sum-ℕ f (succ-ℕ l) zero-ℕ = zero-ℕ
ranged-sum-ℕ f (succ-ℕ l) (succ-ℕ u) =
ranged-sum-ℕ (f ∘ succ-ℕ) l u
succ-iterated-operation-fam-ℕ :
{ l : Level}
( P : ℕ → UU l) (is-decidable-P : (n : ℕ) → is-decidable (P n)) →
( predecessor-strict-upper-bound : ℕ) (operation : ℕ → ℕ → ℕ) →
is-decidable (P predecessor-strict-upper-bound) → ℕ → ℕ
succ-iterated-operation-fam-ℕ
P is-decidable-P b μ (inl p) m = μ m b
succ-iterated-operation-fam-ℕ
P is-decidable-P b μ (inr f) m = m
iterated-operation-fam-ℕ :
{ l : Level} (P : ℕ → UU l) (is-decidable-P : (n : ℕ) → is-decidable (P n)) →
( strict-upper-bound : ℕ) (operation : ℕ → ℕ → ℕ) (base-value : ℕ) → ℕ
iterated-operation-fam-ℕ P d zero-ℕ μ e = e
iterated-operation-fam-ℕ P d (succ-ℕ b) μ e =
succ-iterated-operation-fam-ℕ P d b μ (d b)
( iterated-operation-fam-ℕ P d b μ e)
Sum-fam-ℕ :
{ l : Level} (P : ℕ → UU l) (is-decidable-P : (n : ℕ) → is-decidable (P n)) →
( upper-bound : ℕ) ( summand : ℕ → ℕ) → ℕ
Sum-fam-ℕ P d b f = iterated-operation-fam-ℕ P d (succ-ℕ b) (λ x y → add-ℕ x (f y)) zero-ℕ
{-
iterated-operation-fam-ℕ
P is-decidable-P zero-ℕ is-bounded-P μ base-value =
base-value
iterated-operation-fam-ℕ
P is-decidable-P (succ-ℕ b) is-bounded-P μ base-value =
succ-iterated-operation-ℕ P is-decidable-P b is-bounded-P μ
( is-decidable-P b)
( iterated-operation-ℕ
( introduce-bound-on-fam-ℕ b P)
( is-decidable-introduce-bound-on-fam-ℕ b P is-decidable-P)
( b)
( is-bounded-introduce-bound-on-fam-ℕ b P)
( μ)
( base-value))
product-decidable-bounded-fam-ℕ :
{ l : Level} (P : ℕ → UU l) →
( is-decidable-P : (n : ℕ) → is-decidable (P n))
( b : ℕ) ( is-bounded-P : is-bounded-fam-ℕ b P) → ℕ
product-decidable-bounded-fam-ℕ P is-decidable-P b is-bounded-P =
iterated-operation-ℕ P is-decidable-P b is-bounded-P mul-ℕ one-ℕ
twenty-four-ℕ : ℕ
twenty-four-ℕ =
product-decidable-bounded-fam-ℕ
( λ x → le-ℕ x five-ℕ)
( λ x → is-decidable-le-ℕ x five-ℕ)
( five-ℕ)
( λ x → id)
-}
{-
test-zero-twenty-four-ℕ : Id twenty-four-ℕ zero-ℕ
test-zero-twenty-four-ℕ = refl
test-twenty-four-ℕ : Id twenty-four-ℕ (factorial four-ℕ)
test-twenty-four-ℕ = refl
-}
-- Exercises
-- Exercise 10.?
abstract
has-decidable-equality-𝟚 : has-decidable-equality bool
has-decidable-equality-𝟚 true true = inl refl
has-decidable-equality-𝟚 true false = inr (Eq-𝟚-eq true false)
has-decidable-equality-𝟚 false true = inr (Eq-𝟚-eq false true)
has-decidable-equality-𝟚 false false = inl refl
-- Exercise 10.?
abstract
has-decidable-equality-prod' : {l1 l2 : Level} {A : UU l1} {B : UU l2} →
(x x' : A) (y y' : B) → is-decidable (Id x x') → is-decidable (Id y y') →
is-decidable (Id (pair x y) (pair x' y'))
has-decidable-equality-prod' x x' y y' (inl p) (inl q) =
inl (eq-pair-triv (pair p q))
has-decidable-equality-prod' x x' y y' (inl p) (inr g) =
inr (λ h → g (ap pr2 h))
has-decidable-equality-prod' x x' y y' (inr f) (inl q) =
inr (λ h → f (ap pr1 h))
has-decidable-equality-prod' x x' y y' (inr f) (inr g) =
inr (λ h → f (ap pr1 h))
abstract
has-decidable-equality-prod : {l1 l2 : Level} {A : UU l1} {B : UU l2} →
has-decidable-equality A → has-decidable-equality B →
has-decidable-equality (A × B)
has-decidable-equality-prod dec-A dec-B (pair x y) (pair x' y') =
has-decidable-equality-prod' x x' y y' (dec-A x x') (dec-B y y')
{-
bounds-fam-ℕ :
{l : Level} (P : ℕ → UU l) → UU l
bounds-fam-ℕ P = Σ ℕ (λ n → is-bounded-fam-ℕ n P)
is-minimal-ℕ :
{l : Level} (P : ℕ → UU l) → Σ ℕ P → UU l
is-minimal-ℕ P (pair n p) = (t : Σ ℕ P) → leq-ℕ n (pr1 t)
fam-succ-ℕ :
{l : Level} → (ℕ → UU l) → (ℕ → UU l)
fam-succ-ℕ P n = P (succ-ℕ n)
is-decidable-fam-succ-ℕ :
{l : Level} (P : ℕ → UU l) →
((n : ℕ) → is-decidable (P n)) → ((n : ℕ) → is-decidable (P (succ-ℕ n)))
is-decidable-fam-succ-ℕ P d n = d (succ-ℕ n)
min-is-bounded-not-zero-ℕ :
{l : Level} (P : ℕ → UU l) → ((n : ℕ) → is-decidable (P n)) →
Σ ℕ (λ n → is-bounded-fam-ℕ n P) →
¬ (P zero-ℕ) →
Σ (Σ ℕ (fam-succ-ℕ P)) (is-minimal-ℕ (fam-succ-ℕ P)) →
Σ (Σ ℕ P) (is-minimal-ℕ P)
min-is-bounded-not-zero-ℕ P d b np0 t = {!!}
min-is-bounded-ℕ :
{l : Level} (P : ℕ → UU l) → ((n : ℕ) → is-decidable (P n)) →
Σ ℕ (λ n → is-bounded-fam-ℕ n P) →
Σ ℕ P → Σ (Σ ℕ P) (is-minimal-ℕ P)
min-is-bounded-ℕ P d (pair zero-ℕ b) t =
pair
( pair
( zero-ℕ)
( tr P (eq-zero-leq-zero-ℕ (pr1 t) (b (pr1 t) (pr2 t))) (pr2 t)))
( λ p → leq-zero-ℕ (pr1 p))
min-is-bounded-ℕ P d (pair (succ-ℕ n) b) t =
ind-coprod
( λ (t : is-decidable (P zero-ℕ)) → Σ (Σ ℕ P) (is-minimal-ℕ P))
( λ p0 → pair (pair zero-ℕ p0) (λ p → leq-zero-ℕ (pr1 p)))
( λ y → min-is-bounded-not-zero-ℕ P d (pair (succ-ℕ n) b) y
( min-is-bounded-ℕ
( fam-succ-ℕ P)
( is-decidable-fam-succ-ℕ P d)
{!!}
{!!}))
( d zero-ℕ)
{- We show that every non-empty decidable subset of ℕ has a least element. -}
least-ℕ :
{l : Level} (P : ℕ → UU l) → Σ ℕ P → UU l
least-ℕ P (pair n p) = (m : ℕ) → P m → leq-ℕ n m
least-element-non-empty-decidable-subset-ℕ :
{l : Level} (P : ℕ → UU l) (d : (n : ℕ) → is-decidable (P n)) →
Σ ℕ P → Σ (Σ ℕ P) (least-ℕ P)
least-element-non-empty-decidable-subset-ℕ P d (pair zero-ℕ p) =
pair (pair zero-ℕ p) {!!}
least-element-non-empty-decidable-subset-ℕ P d (pair (succ-ℕ n) p) = {!!}
-}
{-
zero-Fin :
(n : ℕ) → Fin (succ-ℕ n)
zero-Fin zero-ℕ = inr star
zero-Fin (succ-ℕ n) = inl (zero-Fin n)
succ-Fin :
(n : ℕ) → Fin n → Fin n
succ-Fin (succ-ℕ n) (inr star) = zero-Fin n
succ-Fin (succ-ℕ (succ-ℕ n)) (inl (inl x)) = inl (succ-Fin (succ-ℕ n) (inl x))
succ-Fin (succ-ℕ (succ-ℕ n)) (inl (inr star)) = inr star
iterated-succ-Fin :
(k : ℕ) → (n : ℕ) → Fin n → Fin n
iterated-succ-Fin zero-ℕ n = id
iterated-succ-Fin (succ-ℕ k) n = (succ-Fin n) ∘ (iterated-succ-Fin k n)
quotient-ℕ-Fin :
(n : ℕ) → Fin (succ-ℕ n)
quotient-ℕ-Fin n = iterated-succ-Fin n (succ-ℕ n) (zero-Fin n)
pred-Fin :
(n : ℕ) → Fin n → Fin n
pred-Fin (succ-ℕ zero-ℕ) (inr star) = inr star
pred-Fin (succ-ℕ (succ-ℕ n)) (inl x) = {!!}
pred-Fin (succ-ℕ (succ-ℕ n)) (inr star) = inl (inr star)
add-Fin :
(n : ℕ) → Fin n → Fin n → Fin n
add-Fin (succ-ℕ n) (inl x) j = {!!}
add-Fin (succ-ℕ n) (inr x) j = {!!}
idempotent-succ-Fin :
(n : ℕ) (i : Fin n) → Id (iterated-succ-Fin n n i) i
idempotent-succ-Fin (succ-ℕ zero-ℕ) (inr star) = refl
idempotent-succ-Fin (succ-ℕ (succ-ℕ n)) (inl x) = {!!}
idempotent-succ-Fin (succ-ℕ (succ-ℕ n)) (inr x) = {!!}
-}
in-nat-ℤ : ℕ → ℤ
in-nat-ℤ zero-ℕ = zero-ℤ
in-nat-ℤ (succ-ℕ n) = in-pos n
div-ℤ :
(k l : ℤ) → UU lzero
div-ℤ k l = Σ ℤ (λ x → Id (mul-ℤ x k) l)
_≡_mod_ :
(k l : ℤ) (n : ℕ) → UU lzero
k ≡ l mod n = div-ℤ (in-nat-ℤ n) (add-ℤ k (neg-ℤ l))
-- From before
is-even-ℕ : ℕ → UU lzero
is-even-ℕ n = div-ℕ two-ℕ n
is-prime : ℕ → UU lzero
is-prime n = (one-ℕ < n) × ((m : ℕ) → (one-ℕ < m) → (div-ℕ m n) → Id m n)
{- The Goldbach conjecture asserts that every even number above 2 is the sum
of two primes. -}
Goldbach-conjecture : UU lzero
Goldbach-conjecture =
( n : ℕ) → (two-ℕ < n) → (is-even-ℕ n) →
Σ ℕ (λ p → (is-prime p) × (Σ ℕ (λ q → (is-prime q) × Id (add-ℕ p q) n)))
is-twin-prime : ℕ → UU lzero
is-twin-prime n = (is-prime n) × (is-prime (succ-ℕ (succ-ℕ n)))
{- The twin prime conjecture asserts that there are infinitely many twin
primes. We assert that there are infinitely twin primes by asserting that
for every n : ℕ there is a twin prime that is larger than n. -}
Twin-prime-conjecture : UU lzero
Twin-prime-conjecture = (n : ℕ) → Σ ℕ (λ p → (is-twin-prime p) × (leq-ℕ n p))
-- Exercise
unit-classical-Prop : classical-Prop lzero
unit-classical-Prop =
pair unit-Prop (inl star)
raise-unit-classical-Prop :
(l : Level) → classical-Prop l
raise-unit-classical-Prop l =
pair
( pair
( raise l unit)
( is-prop-is-equiv' unit
( map-raise)
( is-equiv-map-raise l unit)
( is-prop-unit)))
( inl (map-raise star))
bool-classical-Prop :
(l : Level) → classical-Prop l → bool
bool-classical-Prop l (pair P (inl x)) = true
bool-classical-Prop l (pair P (inr x)) = false
{-
classical-Prop-bool :
(l : Level) → bool → classical-Prop l
classical-Prop-bool l true = raise-unit-classical-Prop l
classical-Prop-bool l false = {!!}
-}
| 32.989781
| 103
| 0.580361
|
30b75b0b6f1c04f6b6ab21797eaa68f22ec7641a
| 4,570
|
agda
|
Agda
|
Cubical/Foundations/SIP.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/SIP.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | null | null | null |
Cubical/Foundations/SIP.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | null | null | null |
{-
In this file we apply the cubical machinery to Martin Hötzel-Escardó's
structure identity principle:
https://www.cs.bham.ac.uk/~mhe/HoTT-UF-in-Agda-Lecture-Notes/HoTT-UF-Agda.html#sns
-}
{-# OPTIONS --safe #-}
module Cubical.Foundations.SIP where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence renaming (ua-pathToEquiv to ua-pathToEquiv')
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Function
open import Cubical.Foundations.Path
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Data.Sigma
open import Cubical.Foundations.Structure public
private
variable
ℓ ℓ₁ ℓ₂ ℓ₃ ℓ₄ ℓ₅ : Level
S : Type ℓ₁ → Type ℓ₂
-- Note that for any equivalence (f , e) : X ≃ Y the type ι (X , s) (Y , t) (f , e) need not to be
-- a proposition. Indeed this type should correspond to the ways s and t can be identified
-- as S-structures. This we call a standard notion of structure or SNS.
-- We will use a different definition, but the two definitions are interchangeable.
SNS : (S : Type ℓ₁ → Type ℓ₂) (ι : StrEquiv S ℓ₃) → Type (ℓ-max (ℓ-max (ℓ-suc ℓ₁) ℓ₂) ℓ₃)
SNS {ℓ₁} S ι = ∀ {X : Type ℓ₁} (s t : S X) → ι (X , s) (X , t) (idEquiv X) ≃ (s ≡ t)
-- We introduce the notation for structure preserving equivalences a
-- bit differently, but this definition doesn't actually change from
-- Escardó's notes.
_≃[_]_ : (A : TypeWithStr ℓ₁ S) (ι : StrEquiv S ℓ₂) (B : TypeWithStr ℓ₁ S) → Type (ℓ-max ℓ₁ ℓ₂)
A ≃[ ι ] B = Σ[ e ∈ typ A ≃ typ B ] (ι A B e)
-- The following PathP version of SNS is a bit easier to work with
-- for the proof of the SIP
UnivalentStr : (S : Type ℓ₁ → Type ℓ₂) (ι : StrEquiv S ℓ₃) → Type (ℓ-max (ℓ-max (ℓ-suc ℓ₁) ℓ₂) ℓ₃)
UnivalentStr {ℓ₁} S ι =
{A B : TypeWithStr ℓ₁ S} (e : typ A ≃ typ B)
→ ι A B e ≃ PathP (λ i → S (ua e i)) (str A) (str B)
-- A quick sanity-check that our definition is interchangeable with
-- Escardó's. The direction SNS→UnivalentStr corresponds more or less
-- to a dependent EquivJ formulation of Escardó's homomorphism-lemma.
UnivalentStr→SNS : (S : Type ℓ₁ → Type ℓ₂) (ι : StrEquiv S ℓ₃)
→ UnivalentStr S ι → SNS S ι
UnivalentStr→SNS S ι θ {X = X} s t =
ι (X , s) (X , t) (idEquiv X)
≃⟨ θ (idEquiv X) ⟩
PathP (λ i → S (ua (idEquiv X) i)) s t
≃⟨ transportEquiv (λ j → PathP (λ i → S (uaIdEquiv {A = X} j i)) s t) ⟩
s ≡ t
■
SNS→UnivalentStr : (ι : StrEquiv S ℓ₃) → SNS S ι → UnivalentStr S ι
SNS→UnivalentStr {S = S} ι θ {A = A} {B = B} e = EquivJ P C e (str A) (str B)
where
Y = typ B
P : (X : Type _) → X ≃ Y → Type _
P X e' = (s : S X) (t : S Y) → ι (X , s) (Y , t) e' ≃ PathP (λ i → S (ua e' i)) s t
C : (s t : S Y) → ι (Y , s) (Y , t) (idEquiv Y) ≃ PathP (λ i → S (ua (idEquiv Y) i)) s t
C s t =
ι (Y , s) (Y , t) (idEquiv Y)
≃⟨ θ s t ⟩
s ≡ t
≃⟨ transportEquiv (λ j → PathP (λ i → S (uaIdEquiv {A = Y} (~ j) i)) s t) ⟩
PathP (λ i → S (ua (idEquiv Y) i)) s t
■
TransportStr : {S : Type ℓ → Type ℓ₁} (α : EquivAction S) → Type (ℓ-max (ℓ-suc ℓ) ℓ₁)
TransportStr {ℓ} {S = S} α =
{X Y : Type ℓ} (e : X ≃ Y) (s : S X) → equivFun (α e) s ≡ subst S (ua e) s
TransportStr→UnivalentStr : {S : Type ℓ → Type ℓ₁} (α : EquivAction S)
→ TransportStr α → UnivalentStr S (EquivAction→StrEquiv α)
TransportStr→UnivalentStr {S = S} α τ {X , s} {Y , t} e =
equivFun (α e) s ≡ t
≃⟨ pathToEquiv (cong (_≡ t) (τ e s)) ⟩
subst S (ua e) s ≡ t
≃⟨ invEquiv (PathP≃Path _ _ _) ⟩
PathP (λ i → S (ua e i)) s t
■
UnivalentStr→TransportStr : {S : Type ℓ → Type ℓ₁} (α : EquivAction S)
→ UnivalentStr S (EquivAction→StrEquiv α) → TransportStr α
UnivalentStr→TransportStr {S = S} α θ e s =
invEq (θ e) (transport-filler (cong S (ua e)) s)
invTransportStr : {S : Type ℓ → Type ℓ₂} (α : EquivAction S) (τ : TransportStr α)
{X Y : Type ℓ} (e : X ≃ Y) (t : S Y) → invEq (α e) t ≡ subst⁻ S (ua e) t
invTransportStr {S = S} α τ e t =
sym (transport⁻Transport (cong S (ua e)) (invEq (α e) t))
∙∙ sym (cong (subst⁻ S (ua e)) (τ e (invEq (α e) t)))
∙∙ cong (subst⁻ S (ua e)) (retEq (α e) t)
--- We can now define an invertible function
---
--- sip : A ≃[ ι ] B → A ≡ B
module _ {S : Type ℓ₁ → Type ℓ₂} {ι : StrEquiv S ℓ₃}
(θ : UnivalentStr S ι) (A B : TypeWithStr ℓ₁ S)
where
sip : A ≃[ ι ] B → A ≡ B
sip (e , p) i = ua e i , θ e .fst p i
SIP : A ≃[ ι ] B ≃ (A ≡ B)
SIP =
sip , isoToIsEquiv (compIso (Σ-cong-iso (invIso univalenceIso) (equivToIso ∘ θ)) ΣPathIsoPathΣ)
sip⁻ : A ≡ B → A ≃[ ι ] B
sip⁻ = invEq SIP
| 36.56
| 99
| 0.61116
|
43aefb94d1eb82c794faf4184c1afafa793acf60
| 492
|
agda
|
Agda
|
homotopy/3x3/Commutes.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
homotopy/3x3/Commutes.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
homotopy/3x3/Commutes.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import homotopy.3x3.PushoutPushout
open import homotopy.3x3.Transpose
import homotopy.3x3.To as To
import homotopy.3x3.From as From
open import homotopy.3x3.Common
module homotopy.3x3.Commutes {i} (d : Span^2 {i}) where
open Span^2 d
open M using (Pushout^2)
open To d
open From d
open import homotopy.3x3.FromTo
open import homotopy.3x3.ToFrom
abstract
theorem : Pushout^2 d ≃ Pushout^2 (transpose d)
theorem = equiv to from (to-from d) (from-to d)
| 22.363636
| 55
| 0.745935
|
1b5a91fbd70cc871eca61d3b37d6c88654aeeb8b
| 1,197
|
agda
|
Agda
|
test/Succeed/Issue1719/Common.agda
|
zgrannan/agda
|
5953ce337eb6b77b29ace7180478f49c541aea1c
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/Issue1719/Common.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue1719/Common.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
{-# OPTIONS --without-K --rewriting #-}
module Issue1719.Common where
ofType : ∀ {i} (A : Set i) → A → A
ofType A x = x
syntax ofType A x = x :> A
infixr 3 ofType
postulate
_↦_ : ∀ {i} {A : Set i} → A → A → Set i
idr : ∀ {i} {A : Set i} {a : A} → a ↦ a
{-# BUILTIN REWRITE _↦_ #-}
infixr 3 _==_
data _==_ {i} {A : Set i} (a : A) : A → Set i where
idp : a == a
HetEq : ∀ {i} {A B : Set i} (e : A == B) (a : A) (b : B) → Set i
HetEq idp a b = (a == b)
PathOver : ∀ {i j} {A : Set i} (B : A → Set j)
{x y : A} (p : x == y) (u : B x) (v : B y) → Set j
PathOver B idp u v = (u == v)
syntax PathOver B p u v =
u == v [ B ↓ p ]
postulate
PathOver-rewr : ∀ {i j} {A : Set i} {B : Set j} {x y : A} (p : x == y) (u v : B) →
(PathOver (λ _ → B) p u v) ↦ (u == v)
{-# REWRITE PathOver-rewr #-}
-- Note that this is both [ap] and [apd], as a [PathOver] in a constant family
-- reduces to the usual identity type.
ap : ∀ {i j} {A : Set i} {B : A → Set j} (f : (a : A) → B a) {x y : A}
→ (p : x == y) → PathOver B p (f x) (f y)
ap f idp = idp
postulate
ap-cst : ∀ {i j} {A : Set i} {B : Set j} (b : B) {x y : A} (p : x == y) →
ap (λ _ → b) p ↦ idp
{-# REWRITE ap-cst #-}
| 25.468085
| 84
| 0.472849
|
34fe70707e94df1032e8c55c7d467ac21d3fc0f8
| 1,443
|
agda
|
Agda
|
hott/equivalence/properties.agda
|
HoTT/M-types
|
beebe176981953ab48f37de5eb74557cfc5402f4
|
[
"BSD-3-Clause"
] | 27
|
2015-04-14T15:47:03.000Z
|
2022-01-09T07:26:57.000Z
|
src/hott/equivalence/properties.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 4
|
2015-02-02T14:32:16.000Z
|
2016-10-26T11:57:26.000Z
|
src/hott/equivalence/properties.agda
|
pcapriotti/agda-base
|
bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c
|
[
"BSD-3-Clause"
] | 4
|
2015-02-02T12:17:00.000Z
|
2019-05-04T19:31:00.000Z
|
{-# OPTIONS --without-K #-}
module hott.equivalence.properties where
open import sum
open import equality.core
open import equality.calculus
open import function.core
open import function.isomorphism
open import function.extensionality
open import hott.equivalence.core
open import hott.equivalence.alternative
open import hott.univalence
open import hott.level
sym≈ : ∀ {i j}{X : Set i}{Y : Set j}
→ X ≈ Y → Y ≈ X
sym≈ = ≅'⇒≈ ∘ sym≅' ∘ ≈⇒≅'
-- being a weak equivalence is propositional
we-h1 : ∀ {i j}{X : Set i}{Y : Set j}
→ (f : X → Y)
→ h 1 (weak-equiv f)
we-h1 f = Π-level λ _ → contr-h1 _
apply≈-inj : ∀ {i j}{X : Set i}{Y : Set j}
→ injective (apply≈ {X = X}{Y = Y})
apply≈-inj {x = (f , w)}{.f , w'} refl =
unapΣ (refl , h1⇒prop (we-h1 f) w w')
abstract
univ-sym≈ : ∀ {i}{X Y : Set i}
→ (w : X ≈ Y)
→ sym (≈⇒≡ w)
≡ ≈⇒≡ (sym≈ w)
univ-sym≈ {i}{X}{Y} w = inverse-unique p q lem-inv
where
p : X ≡ Y
p = ≈⇒≡ w
q : Y ≡ X
q = ≈⇒≡ (sym≈ w)
p-β : coerce p ≡ apply≈ w
p-β = uni-coherence w
q-β : coerce q ≡ invert≈ w
q-β = uni-coherence (sym≈ w)
lem : coerce (p · q) ≡ coerce refl
lem = coerce-hom p q
· (ap (λ h → coerce q ∘ h) p-β
· ap (λ h → h ∘ apply≈ w) q-β
· funext (_≅_.iso₁ (≈⇒≅ w)))
lem-inv : p · q ≡ refl
lem-inv = iso⇒inj uni-iso (apply≈-inj lem)
| 24.87931
| 52
| 0.523909
|
0d2cfc25eeec28c616f54569f09e294a800720b9
| 2,111
|
agda
|
Agda
|
app/btls-certs.agda
|
semenov-vladyslav/asn1-agda
|
bbbeb679fa2c55a12f0cb345ad920c999c3f8fa8
|
[
"MIT"
] | null | null | null |
app/btls-certs.agda
|
semenov-vladyslav/asn1-agda
|
bbbeb679fa2c55a12f0cb345ad920c999c3f8fa8
|
[
"MIT"
] | null | null | null |
app/btls-certs.agda
|
semenov-vladyslav/asn1-agda
|
bbbeb679fa2c55a12f0cb345ad920c999c3f8fa8
|
[
"MIT"
] | null | null | null |
module btls-certs where
open import Data.Word8 using (Word8) renaming (primWord8fromNat to to𝕎)
open import Data.ByteString using (ByteString; Strict; Lazy; pack)
open import Data.ByteString.Primitive using (∣List∣≡∣Strict∣)
open import Data.ByteVec using (ByteVec)
open import Data.Nat using (ℕ; zero; suc; _<_; z≤n; s≤s; _≤?_; _∸_)
open import Data.Nat.DivMod using (_divMod_; result)
open import Data.Fin using (Fin; toℕ)
open import Data.Vec using (Vec; toList; tabulate)
open import Data.List using (List; []; _∷_; length; _++_; take)
open import Data.Product using (Σ; _,_; proj₁)
open import Relation.Nullary using (Dec; yes; no)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans)
import Data.ByteString.IO as BSIO
open import IO
open import Function using (_∘_)
open import ASN1.Util using (base256)
import ASN1.BER as BER
import ASN1.X509
open import Bee2.Crypto.Belt using (beltHash)
open import Bee2.Crypto.Bign using (Pri; Pub; Sig; bignCalcPubkey; bignSign2)
b : ℕ → List Word8
b n = toList (tabulate {n} (to𝕎 ∘ toℕ))
b256 = b 256
x : (len : ℕ) → ℕ → Σ (List Word8) (λ l → len ≡ length l)
x zero n = [] , refl
x (suc len) n with n divMod 256
... | result q r _ with x len q
... | ns , refl = (to𝕎 (toℕ r) ∷ ns) , refl
mkPri : ℕ → Pri
mkPri n with x 32 n
... | (ns , prf) = (pack ns) , sym (trans (∣List∣≡∣Strict∣ ns (p prf 32<2³¹)) (sym prf)) where
p : ∀ {u v k} → (u≡v : u ≡ v) → u < k → v < k
p refl u<k = u<k
32<2³¹ : 32 < _
32<2³¹ =
s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (
s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (
s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (
s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (s≤s (
s≤s z≤n))))))))))))))))))))))))))))))))
ca-pri : Pri
ca-pri = mkPri 17
ca-pub : Pub
ca-pub = bignCalcPubkey ca-pri
sign : Pri → ByteString Strict → ByteString Strict
sign pri = proj₁ ∘ bignSign2 pri ∘ beltHash
ca-cert : ByteString Lazy
ca-cert = BER.encode′ cert where
open ASN1.X509.mkCert "issuer" "subject" "20170101000000Z" "20190101000000Z" (proj₁ ca-pub) (sign ca-pri)
main = run (BSIO.writeBinaryFile "ca.pkc" ca-cert)
| 32.984375
| 107
| 0.645192
|
523feca90413ae1a158b72bb98f420972a7bade7
| 6,079
|
agda
|
Agda
|
Cubical/Algebra/RingSolver/CommRingHornerForms.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Algebra/RingSolver/CommRingHornerForms.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Algebra/RingSolver/CommRingHornerForms.agda
|
barrettj12/cubical
|
7b41b9171f90473efc98487cb2ea7a4d02320cb2
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.RingSolver.CommRingHornerForms where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat using (ℕ)
open import Cubical.Data.Int hiding (_+_ ; _·_ ; -_)
open import Cubical.Data.FinData
open import Cubical.Data.Vec
open import Cubical.Data.Bool
open import Cubical.Relation.Nullary.Base using (yes; no)
open import Cubical.Algebra.RingSolver.Utility
open import Cubical.Algebra.RingSolver.RawRing
open import Cubical.Algebra.RingSolver.IntAsRawRing
open import Cubical.Algebra.RingSolver.RawAlgebra renaming (⟨_⟩ to ⟨_⟩ₐ)
open import Cubical.Algebra.RingSolver.AlgebraExpression public
private
variable
ℓ ℓ′ : Level
{-
This defines the type of multivariate Polynomials over the RawRing R.
The construction is based on the algebraic fact
R[X₀][X₁]⋯[Xₙ] ≅ R[X₀,⋯,Xₙ]
BUT: Contrary to algebraic convetions, we will give 'Xₙ' the lowest index
in the definition of 'Variable' below. So if 'Variable n R k' is identified
with 'Xₖ', then the RawRing we construct should rather be denoted with
R[Xₙ][Xₙ₋₁]⋯[X₀]
or, to be precise about the evaluation order:
(⋯((R[Xₙ])[Xₙ₋₁])⋯)[X₀]
-}
data IteratedHornerForms (A : RawAlgebra ℤAsRawRing ℓ) : ℕ → Type ℓ where
const : ℤ → IteratedHornerForms A ℕ.zero
0H : {n : ℕ} → IteratedHornerForms A (ℕ.suc n)
_·X+_ : {n : ℕ} → IteratedHornerForms A (ℕ.suc n) → IteratedHornerForms A n
→ IteratedHornerForms A (ℕ.suc n)
{-
The following function returns true, if there is some
obvious reason that the Horner-Expression should be zero.
Since Equality is undecidable in a general RawAlgebra, we cannot
have a function that fully lives up to the name 'isZero'.
-}
module _ (A : RawAlgebra ℤAsRawRing ℓ) where
open RawRing ℤAsRawRing
isZero : {n : ℕ} → IteratedHornerForms A n
→ Bool
isZero (const (pos ℕ.zero)) = true
isZero (const (pos (ℕ.suc _))) = false
isZero (const (negsuc _)) = false
isZero 0H = true
isZero (P ·X+ Q) = (isZero P) and (isZero Q)
leftIsZero : {n : ℕ}
(P : IteratedHornerForms A (ℕ.suc n))
(Q : IteratedHornerForms A n)
→ isZero (P ·X+ Q) ≡ true
→ isZero P ≡ true
leftIsZero P Q isZeroSum with isZero P
... | true = refl
... | false = byBoolAbsurdity (fst (extractFromAnd _ _ isZeroSum))
rightIsZero : {n : ℕ}
(P : IteratedHornerForms A (ℕ.suc n))
(Q : IteratedHornerForms A n)
→ isZero (P ·X+ Q) ≡ true
→ isZero Q ≡ true
rightIsZero P Q isZeroSum with isZero Q
... | true = refl
... | false = byBoolAbsurdity (snd (extractFromAnd _ _ isZeroSum))
module IteratedHornerOperations (A : RawAlgebra ℤAsRawRing ℓ) where
open RawRing ℤAsRawRing
private
1H' : (n : ℕ) → IteratedHornerForms A n
1H' ℕ.zero = const 1r
1H' (ℕ.suc n) = 0H ·X+ 1H' n
0H' : (n : ℕ) → IteratedHornerForms A n
0H' ℕ.zero = const 0r
0H' (ℕ.suc n) = 0H
1ₕ : {n : ℕ} → IteratedHornerForms A n
1ₕ {n = n} = 1H' n
0ₕ : {n : ℕ} → IteratedHornerForms A n
0ₕ {n = n} = 0H' n
X : (n : ℕ) (k : Fin n) → IteratedHornerForms A n
X (ℕ.suc m) zero = 1ₕ ·X+ 0ₕ
X (ℕ.suc m) (suc k) = 0ₕ ·X+ X m k
_+ₕ_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
→ IteratedHornerForms A n
(const r) +ₕ (const s) = const (r + s)
0H +ₕ Q = Q
(P ·X+ r) +ₕ 0H = P ·X+ r
(P ·X+ r) +ₕ (Q ·X+ s) =
let left = (P +ₕ Q)
right = (r +ₕ s)
in if ((isZero A left) and (isZero A right))
then 0ₕ
else left ·X+ right
-ₕ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
-ₕ (const x) = const (- x)
-ₕ 0H = 0H
-ₕ (P ·X+ Q) = (-ₕ P) ·X+ (-ₕ Q)
_⋆_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A (ℕ.suc n)
→ IteratedHornerForms A (ℕ.suc n)
_·ₕ_ : {n : ℕ} → IteratedHornerForms A n → IteratedHornerForms A n
→ IteratedHornerForms A n
r ⋆ 0H = 0H
r ⋆ (P ·X+ Q) =
if (isZero A r)
then 0ₕ
else (r ⋆ P) ·X+ (r ·ₕ Q)
const x ·ₕ const y = const (x · y)
0H ·ₕ Q = 0H
(P ·X+ Q) ·ₕ S =
let
z = (P ·ₕ S)
in if (isZero A z)
then (Q ⋆ S)
else (z ·X+ 0ₕ) +ₕ (Q ⋆ S)
isZeroPresLeft⋆ :
{n : ℕ}
(r : IteratedHornerForms A n)
(P : IteratedHornerForms A (ℕ.suc n))
→ isZero A r ≡ true
→ isZero A (r ⋆ P) ≡ true
isZeroPresLeft⋆ r 0H isZero-r = refl
isZeroPresLeft⋆ r (P ·X+ Q) isZero-r with isZero A r
... | true = refl
... | false = byBoolAbsurdity isZero-r
isZeroPresLeft·ₕ :
{n : ℕ} (P Q : IteratedHornerForms A n)
→ isZero A P ≡ true
→ isZero A (P ·ₕ Q) ≡ true
isZeroPresLeft·ₕ (const (pos ℕ.zero)) (const _) isZeroP = refl
isZeroPresLeft·ₕ (const (pos (ℕ.suc n))) (const _) isZeroP = byBoolAbsurdity isZeroP
isZeroPresLeft·ₕ (const (negsuc n)) (const _) isZeroP = byBoolAbsurdity isZeroP
isZeroPresLeft·ₕ 0H Q isZeroP = refl
isZeroPresLeft·ₕ (P ·X+ Q) S isZeroSum with isZero A (P ·ₕ S) ≟ true
... | no p = byBoolAbsurdity (sym notZeroProd ∙ isZeroProd)
where notZeroProd = ¬true→false _ p
isZeroP = extractFromAndLeft isZeroSum
isZeroProd = isZeroPresLeft·ₕ P S isZeroP
... | yes p with isZero A (P ·ₕ S)
... | true = isZeroPresLeft⋆ Q S isZeroQ
where isZeroQ = extractFromAndRight isZeroSum
... | false = byBoolAbsurdity p
asRawRing : (n : ℕ) → RawRing ℓ
RawRing.Carrier (asRawRing n) = IteratedHornerForms A n
RawRing.0r (asRawRing n) = 0ₕ
RawRing.1r (asRawRing n) = 1ₕ
RawRing._+_ (asRawRing n) = _+ₕ_
RawRing._·_ (asRawRing n) = _·ₕ_
RawRing.- (asRawRing n) = -ₕ
Variable : (n : ℕ) (R : RawAlgebra ℤAsRawRing ℓ′) (k : Fin n) → IteratedHornerForms R n
Variable n R k = IteratedHornerOperations.X R n k
Constant : (n : ℕ) (R : RawAlgebra ℤAsRawRing ℓ′) (r : ℤ) → IteratedHornerForms R n
Constant ℕ.zero R r = const r
Constant (ℕ.suc n) R r = IteratedHornerOperations.0ₕ R ·X+ Constant n R r
| 32.859459
| 87
| 0.616878
|
30e3ab5f83fc55505c3d78139f2b213a67a27163
| 335
|
agda
|
Agda
|
test/Fail/LevelUnification.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/LevelUnification.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/LevelUnification.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Level suc is not a constructor, and doesn't behave as one
-- for unification.
module LevelUnification where
open import Common.Level
data _≡_ {a}{A : Set a}(x : A) : ∀ {b}{B : Set b} → B → Set where
refl : x ≡ x
sym : ∀ a b (A : Set (lsuc a)) (B : Set (lsuc b)) (x : A) (y : B) → x ≡ y → y ≡ x
sym a .a A .A x .x refl = refl
| 23.928571
| 81
| 0.567164
|
419c36a727202174e5b97de1f6e7c9448b3e40c2
| 483
|
agda
|
Agda
|
test/Succeed/Issue1203.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1203.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1203.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- {-# OPTIONS -v tc.conv.coerce:10 -v tc.conv.size:40 -v tc.size.solve:40 #-}
-- Andreas, 2014-06-16 Coercion for sizes
{-# OPTIONS --sized-types #-}
open import Common.Size
data Nat (i : Size) : Set where
zero : Nat i
suc : (j : Size< i) → Nat j → Nat i
three : (i : Size) → Nat (↑ ↑ ↑ i)
three i = suc _ (suc _ (suc i zero))
-- Should be ok, but we get the error:
-- ∞ !=< i of type Size
-- when checking that the expression _ has type Size< (↑ (↑ (↑ i)))
-- Works now.
| 25.421053
| 78
| 0.590062
|
5287462ff6b5e7736f61a23779313fc7aa75e5a8
| 512
|
agda
|
Agda
|
test/Succeed/Issue1484.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue1484.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue1484.agda
|
redfish64/autonomic-agda
|
c0ae7d20728b15d7da4efff6ffadae6fe4590016
|
[
"BSD-3-Clause"
] | null | null | null |
-- Andreas, 2015-05-06
module Issue1484 where
data ⊥ : Set where
-- Smörgåsbord of legal absurd lambdas
-- non-hidden
abs esabs eabs eabs2 eabs3 : ⊥ → Set
abs = λ()
esabs = λ{ ()}
eabs = λ{()}
eabs2 = λ{(())}
eabs3 = λ{((()))}
-- hidden
habs eshabs eshpabs eshpabs2 : {_ : ⊥} → Set
habs = λ{}
eshabs = λ{ {}}
eshpabs = λ{ {()}}
eshpabs2 = λ{ {(())}}
-- instance
iabs esiabs esipabs esipabs2 : {{_ : ⊥}} → Set
iabs = λ{{}}
esiabs = λ{ {{}}}
esipabs = λ{ {{()}}}
esipabs2 = λ{ {{(())}}}
| 14.222222
| 46
| 0.525391
|
2e9dedbb1f77dc92a93ea030e2d1ff432f1817db
| 3,160
|
agda
|
Agda
|
Sets/IterativeSet/Oper.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Sets/IterativeSet/Oper.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Sets/IterativeSet/Oper.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Sets.IterativeSet.Oper where
import Lvl
open import Data
open import Data.Boolean
open import Data.Boolean.Stmt
open import Data.Either as Either using (_‖_)
open import Data.Tuple as Tuple using ()
open import Functional
open import Logic
open import Numeral.Natural
open import Relator.Equals using () renaming (_≡_ to Id ; [≡]-intro to intro)
open import Sets.IterativeSet
open import Syntax.Function
open import Type.Dependent
module _ where
private variable {ℓ ℓ₁ ℓ₂} : Lvl.Level
open Iset
-- The empty set, consisting of no elements.
-- Index is the empty type, which means that there are no objects pointing to elements in the set.
∅ : Iset{ℓ}
∅ = set{Index = Empty} empty
-- The singleton set, consisting of one element.
-- Index is the unit type, which means that there are a single object pointing to a single element in the set.
singleton : Iset{ℓ} → Iset{ℓ}
singleton = set{Index = Unit} ∘ const
-- The pair set, consisting of two elements.
-- Index is the boolean type, which means that there are two objects pointing to two elements in the set.
pair : Iset{ℓ} → Iset{ℓ} → Iset{ℓ}
pair A B = set{Index = Lvl.Up(Bool)} ((if_then B else A) ∘ Lvl.Up.obj)
-- The union operator.
-- Index(A ∪ B) is the either type of two indices, which means that both objects from the A and the B index point to elements in the set.
_∪_ : Iset{ℓ} → Iset{ℓ} → Iset{ℓ}
A ∪ B = set{Index = Index(A) ‖ Index(B)} (Either.map1 (elem(A)) (elem(B)))
_,_ : Iset{ℓ} → Iset{ℓ} → Iset{ℓ}
A , B = pair (singleton A) (pair A B)
_⨯_ : Iset{ℓ} → Iset{ℓ} → Iset{ℓ}
A ⨯ B = set{Index = Index(A) Tuple.⨯ Index(B)} \{(ia Tuple., ib) → (elem(A)(ia) , elem(B)(ib))}
-- The big union operator.
-- Index(⋃ A) is the dependent sum type of an Index(A) and the index of the element this index points to.
⋃ : Iset{ℓ} → Iset{ℓ}
⋃ A = set{Index = Σ(Index(A)) (ia ↦ Index(elem(A)(ia)))} (\{(intro ia i) → elem(elem(A)(ia))(i)})
indexFilter : (A : Iset{ℓ}) → (Index(A) → Stmt{ℓ}) → Iset{ℓ}
indexFilter A P = set{Index = Σ(Index(A)) P} (elem(A) ∘ Σ.left)
filter : (A : Iset{ℓ}) → (Iset{ℓ} → Stmt{ℓ}) → Iset{ℓ}
filter{ℓ} A P = indexFilter A (P ∘ elem(A))
indexFilterBool : (A : Iset{ℓ}) → (Index(A) → Bool) → Iset{ℓ}
indexFilterBool A f = indexFilter A (Lvl.Up ∘ IsTrue ∘ f)
filterBool : (A : Iset{ℓ}) → (Iset{ℓ} → Bool) → Iset{ℓ}
filterBool A f = indexFilterBool A (f ∘ elem(A))
mapSet : (Iset{ℓ} → Iset{ℓ}) → (Iset{ℓ} → Iset{ℓ})
mapSet f(A) = set{Index = Index(A)} (f ∘ elem(A))
-- The power set operator.
-- Index(℘(A)) is a function type. An instance of such a function represents a subset, and essentially maps every element in A to a boolean which is interpreted as "in the subset of not".
-- Note: This only works properly in a classical setting. Trying to use indexFilter instead result in universe level problems.
℘ : Iset{ℓ} → Iset{ℓ}
℘(A) = set{Index = Index(A) → Bool} (indexFilterBool A)
-- The set of ordinal numbers of the first order.
ω : Iset{ℓ}
ω = set{Index = Lvl.Up ℕ} (N ∘ Lvl.Up.obj) where
N : ℕ → Iset{ℓ}
N(𝟎) = ∅
N(𝐒(n)) = N(n) ∪ singleton(N(n))
| 40
| 189
| 0.646203
|
1bfbc0cda3010c2978c2852809a99dfd4eece1f8
| 12,562
|
agda
|
Agda
|
lib/types/Pi.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | 1
|
2021-06-30T00:17:55.000Z
|
2021-06-30T00:17:55.000Z
|
lib/types/Pi.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
lib/types/Pi.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Paths
module lib.types.Pi where
abstract
Π-level : ∀ {i j} {A : Type i} {B : A → Type j} {n : ℕ₋₂}
→ (((x : A) → has-level n (B x)) → has-level n (Π A B))
Π-level {n = ⟨-2⟩} p =
((λ x → fst (p x)) , (λ f → λ= (λ x → snd (p x) (f x))))
Π-level {n = S n} p = λ f g →
equiv-preserves-level λ=-equiv
(Π-level (λ x → p x (f x) (g x)))
module _ {i j} {A : Type i} {B : A → Type j} where
abstract
Π-is-prop : ((x : A) → is-prop (B x)) → is-prop (Π A B)
Π-is-prop = Π-level
Π-is-set : ((x : A) → is-set (B x)) → is-set (Π A B)
Π-is-set = Π-level
module _ {i j} {A : Type i} {B : Type j} where
abstract
→-level : {n : ℕ₋₂} → (has-level n B → has-level n (A → B))
→-level p = Π-level (λ _ → p)
→-is-set : is-set B → is-set (A → B)
→-is-set = →-level
→-is-prop : is-prop B → is-prop (A → B)
→-is-prop = →-level
{- Equivalences in a Π-type -}
equiv-Π-l : ∀ {i j k} {A : Type i} {B : Type j} (P : B → Type k) {h : A → B}
→ is-equiv h → Π A (P ∘ h) ≃ Π B P
equiv-Π-l {A = A} {B = B} P {h = h} e = equiv f g f-g g-f where
w : A ≃ B
w = (h , e)
f : Π A (P ∘ h) → Π B P
f u b = transport P (<–-inv-r w b) (u (<– w b))
g : Π B P → Π A (P ∘ h)
g v a = v (–> w a)
f-g : ∀ v → f (g v) == v
f-g v = λ= λ b → to-transp (apd v (<–-inv-r w b))
g-f : ∀ u → g (f u) == u
g-f u = λ= λ a → to-transp $ transport (λ p → u _ == _ [ P ↓ p ])
(is-equiv.adj e a)
(↓-ap-in P (–> w)
(apd u $ <–-inv-l w a))
equiv-Π-r : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
→ (∀ x → B x ≃ C x) → Π A B ≃ Π A C
equiv-Π-r {A = A} {B = B} {C = C} k = equiv f g f-g g-f
where f : Π A B → Π A C
f c x = –> (k x) (c x)
g : Π A C → Π A B
g d x = <– (k x) (d x)
f-g : ∀ d → f (g d) == d
f-g d = λ= (λ x → <–-inv-r (k x) (d x))
g-f : ∀ c → g (f c) == c
g-f c = λ= (λ x → <–-inv-l (k x) (c x))
module _ {i₀ i₁ j₀ j₁} {A₀ : Type i₀} {A₁ : Type i₁}
{B₀ : A₀ → Type j₀} {B₁ : A₁ → Type j₁} where
equiv-Π : (u : A₀ ≃ A₁) (v : ∀ a → B₀ (<– u a) ≃ B₁ a) → Π A₀ B₀ ≃ Π A₁ B₁
equiv-Π u v = Π A₀ B₀ ≃⟨ equiv-Π-l _ (snd (u ⁻¹)) ⁻¹ ⟩
Π A₁ (B₀ ∘ <– u) ≃⟨ equiv-Π-r v ⟩
Π A₁ B₁ ≃∎
equiv-Π' : (u : A₀ ≃ A₁) (v : ∀ a → B₀ a ≃ B₁ (–> u a)) → Π A₀ B₀ ≃ Π A₁ B₁
equiv-Π' u v = Π A₀ B₀ ≃⟨ equiv-Π-r v ⟩
Π A₀ (B₁ ∘ –> u) ≃⟨ equiv-Π-l _ (snd u) ⟩
Π A₁ B₁ ≃∎
{- Coversions between functions with implicit and explicit arguments -}
expose-equiv : ∀ {i j} {A : Type i} {B : A → Type j}
→ ({x : A} → B x) ≃ ((x : A) → B x)
expose-equiv = (λ f a → f {a}) , is-eq
_
(λ f {a} → f a)
(λ _ → idp)
(λ _ → idp)
{- Dependent paths in a Π-type -}
module _ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k}
where
↓-Π-in : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')}
→ ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t' [ uncurry C ↓ pair= p q ])
→ (u == u' [ (λ x → Π (B x) (C x)) ↓ p ])
↓-Π-in {p = idp} f = λ= (λ x → f (idp {a = x}))
↓-Π-out : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')}
→ (u == u' [ (λ x → Π (B x) (C x)) ↓ p ])
→ ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t' [ uncurry C ↓ pair= p q ])
↓-Π-out {p = idp} q idp = app= q _
↓-Π-β : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')}
→ (f : {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t' [ uncurry C ↓ pair= p q ])
→ {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ ↓-Π-out (↓-Π-in f) q == f q
↓-Π-β {p = idp} f idp = app=-β (λ x → f (idp {a = x})) _
↓-Π-η : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')}
→ (q : (u == u' [ (λ x → Π (B x) (C x)) ↓ p ]))
→ ↓-Π-in (↓-Π-out q) == q
↓-Π-η {p = idp} q = ! (λ=-η q)
↓-Π-equiv : {x x' : A} {p : x == x'} {u : Π (B x) (C x)} {u' : Π (B x') (C x')}
→ ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t' [ uncurry C ↓ pair= p q ])
≃ (u == u' [ (λ x → Π (B x) (C x)) ↓ p ])
↓-Π-equiv {p = idp} = equiv ↓-Π-in ↓-Π-out ↓-Π-η
(λ u → <– (equiv-ap expose-equiv _ _)
(λ= (λ t → <– (equiv-ap expose-equiv _ _)
(λ= (λ t' → λ= (↓-Π-β u))))))
{- Dependent paths in a Π-type where the codomain is not dependent on anything
Right now, this is defined in terms of the previous one. Maybe it’s a good idea,
maybe not.
-}
module _ {i j k} {A : Type i} {B : A → Type j} {C : Type k} {x x' : A}
{p : x == x'} {u : B x → C} {u' : B x' → C} where
↓-app→cst-in :
({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t')
→ (u == u' [ (λ x → B x → C) ↓ p ])
↓-app→cst-in f = ↓-Π-in (λ q → ↓-cst-in (f q))
↓-app→cst-out :
(u == u' [ (λ x → B x → C) ↓ p ])
→ ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t')
↓-app→cst-out r q = ↓-cst-out (↓-Π-out r q)
↓-app→cst-β :
(f : ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t'))
→ {t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ ↓-app→cst-out (↓-app→cst-in f) q == f q
↓-app→cst-β f q =
↓-app→cst-out (↓-app→cst-in f) q
=⟨ idp ⟩
↓-cst-out (↓-Π-out (↓-Π-in (λ qq → ↓-cst-in (f qq))) q)
=⟨ ↓-Π-β (λ qq → ↓-cst-in (f qq)) q |in-ctx
↓-cst-out ⟩
↓-cst-out (↓-cst-in {p = pair= p q} (f q))
=⟨ ↓-cst-β (pair= p q) (f q) ⟩
f q ∎
{- Dependent paths in an arrow type -}
module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
{x x' : A} {p : x == x'} {u : B x → C x} {u' : B x' → C x'} where
↓-→-in :
({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t' [ C ↓ p ])
→ (u == u' [ (λ x → B x → C x) ↓ p ])
↓-→-in f = ↓-Π-in (λ q → ↓-cst2-in p q (f q))
↓-→-out :
(u == u' [ (λ x → B x → C x) ↓ p ])
→ ({t : B x} {t' : B x'} (q : t == t' [ B ↓ p ])
→ u t == u' t' [ C ↓ p ])
↓-→-out r q = ↓-cst2-out p q (↓-Π-out r q)
{- Transport form of dependent path in an arrow type -}
module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} where
↓-→-from-transp : {x x' : A} {p : x == x'}
{u : B x → C x} {u' : B x' → C x'}
→ transport C p ∘ u == u' ∘ transport B p
→ u == u' [ (λ x → B x → C x) ↓ p ]
↓-→-from-transp {p = idp} q = q
↓-→-to-transp : {x x' : A} {p : x == x'}
{u : B x → C x} {u' : B x' → C x'}
→ u == u' [ (λ x → B x → C x) ↓ p ]
→ transport C p ∘ u == u' ∘ transport B p
↓-→-to-transp {p = idp} q = q
-- Dependent paths in a Π-type where the domain is constant
module _ {i j k} {A : Type i} {B : Type j} {C : A → B → Type k} where
↓-cst→app-in : {x x' : A} {p : x == x'}
{u : (b : B) → C x b} {u' : (b : B) → C x' b}
→ ((b : B) → u b == u' b [ (λ x → C x b) ↓ p ])
→ (u == u' [ (λ x → (b : B) → C x b) ↓ p ])
↓-cst→app-in {p = idp} f = λ= f
↓-cst→app-out : {x x' : A} {p : x == x'}
{u : (b : B) → C x b} {u' : (b : B) → C x' b}
→ (u == u' [ (λ x → (b : B) → C x b) ↓ p ])
→ ((b : B) → u b == u' b [ (λ x → C x b) ↓ p ])
↓-cst→app-out {p = idp} q = app= q
split-ap2 : ∀ {i j k} {A : Type i} {B : A → Type j} {C : Type k} (f : Σ A B → C)
{x y : A} (p : x == y)
{u : B x} {v : B y} (q : u == v [ B ↓ p ])
→ ap f (pair= p q) == ↓-app→cst-out (apd (curry f) p) q
split-ap2 f idp idp = idp
{-
Interaction of [apd] with function composition.
The basic idea is that [apd (g ∘ f) p == apd g (apd f p)] but the version here
is well-typed. Note that we assume a propositional equality [r] between
[apd f p] and [q].
-}
apd-∘ : ∀ {i j k} {A : Type i} {B : A → Type j} {C : (a : A) → B a → Type k}
(g : {a : A} → Π (B a) (C a)) (f : Π A B) {x y : A} (p : x == y)
{q : f x == f y [ B ↓ p ]} (r : apd f p == q)
→ apd (g ∘ f) p == ↓-apd-out C r (apd↓ g q)
apd-∘ g f idp idp = idp
{- When [g] is nondependent, it’s much simpler -}
apd-∘' : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
(g : {a : A} → B a → C a) (f : Π A B) {x y : A} (p : x == y)
→ apd (g ∘ f) p == ap↓ g (apd f p)
apd-∘' g f idp = idp
∘'-apd : ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
(g : {a : A} → B a → C a) (f : Π A B) {x y : A} (p : x == y)
→ ap↓ g (apd f p) == apd (g ∘ f) p
∘'-apd g f idp = idp
{- And when [f] is nondependent, it’s also a bit simpler -}
apd-∘'' : ∀ {i j k} {A : Type i} {B : Type j} {C : (b : B) → Type k}
(g : Π B C) (f : A → B) {x y : A} (p : x == y)
{q : f x == f y} (r : ap f p == q)
→ apd (g ∘ f) p == ↓-ap-out= C f p r (apd g q) --(apd↓ g q)
apd-∘'' g f idp idp = idp
{- 2-dimensional coherence conditions -}
-- postulate
-- lhs :
-- ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {f g : Π A B}
-- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
-- (k : (u ◃ apd g p) == (apd f p ▹ v))
-- (h : {a : A} → B a → C a)
-- → ap h u ◃ apd (h ∘ g) p == ap↓ h (u ◃ apd g p)
-- rhs :
-- ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {f g : Π A B}
-- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
-- (k : (u ◃ apd g p) == (apd f p ▹ v))
-- (h : {a : A} → B a → C a)
-- → ap↓ h (apd f p ▹ v) == apd (h ∘ f) p ▹ ap h v
-- ap↓-↓-=-in :
-- ∀ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k} {f g : Π A B}
-- {x y : A} {p : x == y} {u : f x == g x} {v : f y == g y}
-- (k : (u ◃ apd g p) == (apd f p ▹ v))
-- (h : {a : A} → B a → C a)
-- → ap↓ (λ {a} → ap (h {a = a})) (↓-=-in {p = p} {u = u} {v = v} k)
-- == ↓-=-in (lhs {f = f} {g = g} k h ∙ ap (ap↓ (λ {a} → h {a = a})) k
-- ∙ rhs {f = f} {g = g} k h)
{-
Commutation of [ap↓ (ap h)] and [↓-swap!]. This is "just" J, but it’s not as
easy as it seems.
-}
-- module Ap↓-swap! {i j k ℓ} {A : Type i} {B : Type j} {C : Type k}
-- {D : Type ℓ} (h : C → D) (f : A → C) (g : B → C)
-- {a a' : A} {p : a == a'} {b b' : B} {q : b == b'}
-- (r : f a == g b') (s : f a' == g b)
-- (t : r == s ∙ ap g q [ (λ x → f x == g b') ↓ p ])
-- where
-- lhs : ap h (ap f p ∙' s) == ap (h ∘ f) p ∙' ap h s
-- lhs = ap-∙' h (ap f p) s ∙ (ap (λ u → u ∙' ap h s) (∘-ap h f p))
-- rhs : ap h (s ∙ ap g q) == ap h s ∙ ap (h ∘ g) q
-- rhs = ap-∙ h s (ap g q) ∙ (ap (λ u → ap h s ∙ u) (∘-ap h g q))
-- β : ap↓ (ap h) (↓-swap! f g r s t) ==
-- lhs ◃ ↓-swap! (h ∘ f) (h ∘ g) (ap h r) (ap h s) (ap↓ (ap h) t ▹ rhs)
-- β with a | a' | p | b | b' | q | r | s | t
-- β | a | .a | idp | b | .b | idp | r | s | t = coh r s t where
-- T : {x x' : C} (r s : x == x') (t : r == s ∙ idp) → Type _
-- T r s t =
-- ap (ap h) (∙'-unit-l s ∙ ! (∙-unit-r s) ∙ ! t) ==
-- (ap-∙' h idp s ∙ idp)
-- ∙
-- (∙'-unit-l (ap h s) ∙
-- ! (∙-unit-r (ap h s)) ∙
-- !
-- (ap (ap h) t ∙'
-- (ap-∙ h s idp ∙ idp)))
-- coh' : {x x' : C} {r s : x == x'} (t : r == s) → T r s (t ∙ ! (∙-unit-r s))
-- coh' {r = idp} {s = .idp} idp = idp
-- coh : {x x' : C} (r s : x == x') (t : r == s ∙ idp) → T r s t
-- coh r s t = transport (λ t → T r s t) (coh2 t (∙-unit-r s)) (coh' (t ∙ ∙-unit-r s)) where
-- coh2 : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z) → (p ∙ q) ∙ ! q == p
-- coh2 idp idp = idp
-- module _ {i j k} {A : Type i} {B B' : Type j} {C : Type k} (f : A → C) (g' : B' → B) (g : B → C) where
-- abc : {a a' : A} {p : a == a'} {c c' : B'} {q' : c == c'} {q : g' c == g' c'}
-- (r : f a == g (g' c')) (s : f a' == g (g' c))
-- (t : q == ap g' q')
-- (α : r == s ∙ ap g q [ (λ x → f x == g (g' c')) ↓ p ])
-- → {!(↓-swap! f g r s α ▹ ?) ∙'2ᵈ ?!} == ↓-swap! f (g ∘ g') {p = p} {q = q'} r s (α ▹ ap (λ u → s ∙ u) (ap (ap g) t ∙ ∘-ap g g' q'))
-- abc = {!!}
{- Functoriality of application and function extensionality -}
∙-app= : ∀ {i j} {A : Type i} {B : A → Type j} {f g h : Π A B}
(α : f == g) (β : g == h)
→ α ∙ β == λ= (λ x → app= α x ∙ app= β x)
∙-app= idp β = λ=-η β
∙-λ= : ∀ {i j} {A : Type i} {B : A → Type j} {f g h : Π A B}
(α : (x : A) → f x == g x) (β : (x : A) → g x == h x)
→ λ= α ∙ λ= β == λ= (λ x → α x ∙ β x)
∙-λ= α β = ∙-app= (λ= α) (λ= β)
∙ ap λ= (λ= (λ x → ap (λ w → w ∙ app= (λ= β) x) (app=-β α x)
∙ ap (λ w → α x ∙ w) (app=-β β x)))
| 36.411594
| 139
| 0.366821
|
d1bc19e731f762e475469ad6c287bd791b79e602
| 3,527
|
agda
|
Agda
|
src/fot/FOTC/Program/McCarthy91/AuxiliaryPropertiesATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 11
|
2015-09-03T20:53:42.000Z
|
2021-09-12T16:09:54.000Z
|
src/fot/FOTC/Program/McCarthy91/AuxiliaryPropertiesATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 2
|
2016-10-12T17:28:16.000Z
|
2017-01-01T14:34:26.000Z
|
src/fot/FOTC/Program/McCarthy91/AuxiliaryPropertiesATP.agda
|
asr/fotc
|
2fc9f2b81052a2e0822669f02036c5750371b72d
|
[
"MIT"
] | 3
|
2016-09-19T14:18:30.000Z
|
2018-03-14T08:50:00.000Z
|
------------------------------------------------------------------------------
-- Auxiliary properties of the McCarthy 91 function
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.McCarthy91.AuxiliaryPropertiesATP where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.PropertiesATP using ( x<y→y≤z→x<z )
open import FOTC.Data.Nat.PropertiesATP
using ( +-N
; ∸-N
)
open import FOTC.Data.Nat.UnaryNumbers
open import FOTC.Data.Nat.UnaryNumbers.Inequalities.PropertiesATP
using ( x<x+1 )
open import FOTC.Program.McCarthy91.ArithmeticATP
open import FOTC.Program.McCarthy91.McCarthy91
------------------------------------------------------------------------------
--- Auxiliary properties
postulate x>100→x<f₉₁-x+11 : ∀ {n} → N n → n > 100' → n < f₉₁ n + 11'
{-# ATP prove x>100→x<f₉₁-x+11 +-N ∸-N x<y→y≤z→x<z x<x+1 x+1≤x∸10+11 #-}
-- Case n ≡ 100 can be proved automatically
postulate f₉₁-100 : f₉₁ 100' ≡ 91'
{-# ATP prove f₉₁-100 100+11>100 100+11∸10>100 101≡100+11∸10 91≡100+11∸10∸10 #-}
postulate f₉₁x+11<f₉₁x+11 : ∀ n →
n ≯ 100' →
f₉₁ (n + 11') < f₉₁ (f₉₁ (n + 11')) + 11' →
f₉₁ (n + 11') < f₉₁ n + 11'
{-# ATP prove f₉₁x+11<f₉₁x+11 #-}
postulate f₉₁-x≯100-helper : ∀ m n →
m ≯ 100' →
f₉₁ (m + 11') ≡ n →
f₉₁ n ≡ 91' →
f₉₁ m ≡ 91'
{-# ATP prove f₉₁-x≯100-helper #-}
postulate
f₉₁-110 : f₉₁ (99' + 11') ≡ 100'
f₉₁-109 : f₉₁ (98' + 11') ≡ 99'
f₉₁-108 : f₉₁ (97' + 11') ≡ 98'
f₉₁-107 : f₉₁ (96' + 11') ≡ 97'
f₉₁-106 : f₉₁ (95' + 11') ≡ 96'
f₉₁-105 : f₉₁ (94' + 11') ≡ 95'
f₉₁-104 : f₉₁ (93' + 11') ≡ 94'
f₉₁-103 : f₉₁ (92' + 11') ≡ 93'
f₉₁-102 : f₉₁ (91' + 11') ≡ 92'
f₉₁-101 : f₉₁ (90' + 11') ≡ 91'
{-# ATP prove f₉₁-110 99+11>100 x+11∸10≡Sx #-}
{-# ATP prove f₉₁-109 98+11>100 x+11∸10≡Sx #-}
{-# ATP prove f₉₁-108 97+11>100 x+11∸10≡Sx #-}
{-# ATP prove f₉₁-107 96+11>100 x+11∸10≡Sx #-}
{-# ATP prove f₉₁-106 95+11>100 x+11∸10≡Sx #-}
{-# ATP prove f₉₁-105 94+11>100 x+11∸10≡Sx #-}
{-# ATP prove f₉₁-104 93+11>100 x+11∸10≡Sx #-}
{-# ATP prove f₉₁-103 92+11>100 x+11∸10≡Sx #-}
{-# ATP prove f₉₁-102 91+11>100 x+11∸10≡Sx #-}
{-# ATP prove f₉₁-101 90+11>100 x+11∸10≡Sx #-}
postulate
f₉₁-99 : f₉₁ 99' ≡ 91'
f₉₁-98 : f₉₁ 98' ≡ 91'
f₉₁-97 : f₉₁ 97' ≡ 91'
f₉₁-96 : f₉₁ 96' ≡ 91'
f₉₁-95 : f₉₁ 95' ≡ 91'
f₉₁-94 : f₉₁ 94' ≡ 91'
f₉₁-93 : f₉₁ 93' ≡ 91'
f₉₁-92 : f₉₁ 92' ≡ 91'
f₉₁-91 : f₉₁ 91' ≡ 91'
f₉₁-90 : f₉₁ 90' ≡ 91'
{-# ATP prove f₉₁-99 f₉₁-x≯100-helper f₉₁-110 f₉₁-100 #-}
{-# ATP prove f₉₁-98 f₉₁-x≯100-helper f₉₁-109 f₉₁-99 #-}
{-# ATP prove f₉₁-97 f₉₁-x≯100-helper f₉₁-108 f₉₁-98 #-}
{-# ATP prove f₉₁-96 f₉₁-x≯100-helper f₉₁-107 f₉₁-97 #-}
{-# ATP prove f₉₁-95 f₉₁-x≯100-helper f₉₁-106 f₉₁-96 #-}
{-# ATP prove f₉₁-94 f₉₁-x≯100-helper f₉₁-105 f₉₁-95 #-}
{-# ATP prove f₉₁-93 f₉₁-x≯100-helper f₉₁-104 f₉₁-94 #-}
{-# ATP prove f₉₁-92 f₉₁-x≯100-helper f₉₁-103 f₉₁-93 #-}
{-# ATP prove f₉₁-91 f₉₁-x≯100-helper f₉₁-102 f₉₁-92 #-}
{-# ATP prove f₉₁-90 f₉₁-x≯100-helper f₉₁-101 f₉₁-91 #-}
f₉₁-x≡y : ∀ {m n o} → f₉₁ m ≡ n → o ≡ m → f₉₁ o ≡ n
f₉₁-x≡y h refl = h
| 37.126316
| 80
| 0.522257
|
8b7a9af97386d44ac7a9a47e00692133f891394d
| 7,682
|
agda
|
Agda
|
core/lib/groups/QuotientGroup.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
core/lib/groups/QuotientGroup.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
core/lib/groups/QuotientGroup.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.types.Group
open import lib.types.Sigma
open import lib.types.Pi
open import lib.types.Truncation
open import lib.types.SetQuotient
open import lib.groups.Homomorphism
open import lib.groups.Subgroup
open import lib.groups.SubgroupProp
module lib.groups.QuotientGroup where
module _ {i j} {G : Group i} (P : NormalSubgroupProp G j) where
private
module G = Group G
module P = NormalSubgroupProp P
infix 80 _⊙_
_⊙_ = G.comp
quot-group-rel : Rel G.El j
quot-group-rel g₁ g₂ = P.prop (G.diff g₁ g₂)
quot-group-struct : GroupStructure (SetQuot quot-group-rel)
quot-group-struct = record {M} where
module M where
ident : SetQuot quot-group-rel
ident = q[ G.ident ]
abstract
inv-rel : ∀ {g₁ g₂ : G.El} (pg₁g₂⁻¹ : P.prop (G.diff g₁ g₂))
→ q[ G.inv g₁ ] == q[ G.inv g₂ ] :> SetQuot quot-group-rel
inv-rel {g₁} {g₂} pg₁g₂⁻¹ = ! $ quot-rel $
transport! (λ g → P.prop (G.inv g₂ ⊙ g))
(G.inv-inv g₁) $ P.comm g₁ (G.inv g₂) pg₁g₂⁻¹
inv : SetQuot quot-group-rel → SetQuot quot-group-rel
inv = SetQuot-rec (λ g → q[ G.inv g ]) inv-rel
abstract
comp-rel-r : ∀ g₁ {g₂ g₂' : G.El} (pg₂g₂'⁻¹ : P.prop (G.diff g₂ g₂'))
→ q[ g₁ ⊙ g₂ ] == q[ g₁ ⊙ g₂' ] :> SetQuot quot-group-rel
comp-rel-r g₁ {g₂} {g₂'} pg₂g₂'⁻¹ = quot-rel $ transport P.prop
( ap (_⊙ G.inv g₁) (! $ G.assoc g₁ g₂ (G.inv g₂'))
∙ G.assoc (g₁ ⊙ g₂) (G.inv g₂') (G.inv g₁)
∙ ap ((g₁ ⊙ g₂) ⊙_) (! $ G.inv-comp g₁ g₂'))
(P.conj g₁ pg₂g₂'⁻¹)
comp' : G.El → SetQuot quot-group-rel → SetQuot quot-group-rel
comp' g₁ = SetQuot-rec (λ g₂ → q[ g₁ ⊙ g₂ ]) (comp-rel-r g₁)
abstract
comp-rel-l : ∀ {g₁ g₁' : G.El} (pg₁g₁'⁻¹ : P.prop (G.diff g₁ g₁')) g₂
→ q[ g₁ ⊙ g₂ ] == q[ g₁' ⊙ g₂ ] :> SetQuot quot-group-rel
comp-rel-l {g₁} {g₁'} pg₁g₁'⁻¹ g₂ = quot-rel $ transport! P.prop
( ap ((g₁ ⊙ g₂) ⊙_) (G.inv-comp g₁' g₂)
∙ ! (G.assoc (g₁ ⊙ g₂) (G.inv g₂) (G.inv g₁') )
∙ ap (_⊙ G.inv g₁')
( G.assoc g₁ g₂ (G.inv g₂)
∙ ap (g₁ ⊙_) (G.inv-r g₂)
∙ G.unit-r g₁))
pg₁g₁'⁻¹
comp'-rel : ∀ {g₁ g₁' : G.El} (pg₁g₁'⁻¹ : P.prop (G.diff g₁ g₁'))
→ comp' g₁ == comp' g₁'
comp'-rel pg₁g₁'⁻¹ = λ= $ SetQuot-elim
(comp-rel-l pg₁g₁'⁻¹)
(λ _ → prop-has-all-paths-↓)
comp : SetQuot quot-group-rel → SetQuot quot-group-rel → SetQuot quot-group-rel
comp = SetQuot-rec comp' comp'-rel
abstract
unit-l : ∀ g → comp ident g == g
unit-l = SetQuot-elim
(ap q[_] ∘ G.unit-l)
(λ _ → prop-has-all-paths-↓)
assoc : ∀ g₁ g₂ g₃ → comp (comp g₁ g₂) g₃ == comp g₁ (comp g₂ g₃)
assoc = SetQuot-elim
(λ g₁ → SetQuot-elim
(λ g₂ → SetQuot-elim
(λ g₃ → ap q[_] $ G.assoc g₁ g₂ g₃)
(λ _ → prop-has-all-paths-↓))
(λ _ → prop-has-all-paths-↓))
(λ _ → prop-has-all-paths-↓)
inv-l : ∀ g → comp (inv g) g == ident
inv-l = SetQuot-elim
(ap q[_] ∘ G.inv-l)
(λ _ → prop-has-all-paths-↓)
QuotGroup : Group (lmax i j)
QuotGroup = group _ quot-group-struct
{- helper functions -}
module _ {i j} {G : Group i} {P : NormalSubgroupProp G j} where
private
module G = Group G
module P = NormalSubgroupProp P
infix 80 _⊙_
_⊙_ = G.comp
q[_]ᴳ : G →ᴳ QuotGroup P
q[_]ᴳ = group-hom q[_] λ _ _ → idp
quot-relᴳ : ∀ {g₁ g₂} → P.prop (G.diff g₁ g₂) → q[ g₁ ] == q[ g₂ ]
quot-relᴳ {g₁} {g₂} = quot-rel {R = quot-group-rel P} {a₁ = g₁} {a₂ = g₂}
private
abstract
quot-group-rel-is-refl : is-refl (quot-group-rel P)
quot-group-rel-is-refl g = transport! P.prop (G.inv-r g) P.ident
quot-group-rel-is-sym : is-sym (quot-group-rel P)
quot-group-rel-is-sym {g₁} {g₂} pg₁g₂⁻¹ =
transport P.prop (G.inv-comp g₁ (G.inv g₂) ∙ ap (_⊙ G.inv g₁) (G.inv-inv g₂)) (P.inv pg₁g₂⁻¹)
quot-group-rel-is-trans : is-trans (quot-group-rel P)
quot-group-rel-is-trans {g₁} {g₂} {g₃} pg₁g₂⁻¹ pg₂g₃⁻¹ =
transport P.prop
( G.assoc g₁ (G.inv g₂) (g₂ ⊙ G.inv g₃)
∙ ap (g₁ ⊙_) ( ! (G.assoc (G.inv g₂) g₂ (G.inv g₃))
∙ ap (_⊙ G.inv g₃) (G.inv-l g₂)
∙ G.unit-l (G.inv g₃)))
(P.comp pg₁g₂⁻¹ pg₂g₃⁻¹)
quot-relᴳ-equiv : {g₁ g₂ : G.El} → P.prop (g₁ ⊙ G.inv g₂) ≃ (q[ g₁ ] == q[ g₂ ])
quot-relᴳ-equiv = quot-rel-equiv {R = quot-group-rel P}
quot-group-rel-is-refl
quot-group-rel-is-sym
quot-group-rel-is-trans
module QuotGroup {i j} {G : Group i} (P : NormalSubgroupProp G j)
where
grp = QuotGroup P
open Group grp public
module _ {i j k} {G : Group i}
(P : SubgroupProp G j) (Q : NormalSubgroupProp G k) where
quot-of-sub : NormalSubgroupProp (Subgroup P) k
quot-of-sub = Q ∘nsubᴳ Subgroup.inject P
{- interactions between quotients and subgroups (work in progress) -}
{- So far not used.
-- QuotGroup rel-over-sub ≃ᴳ Subgroup prop-over-quot
module _ {i j k} {G : Group i}
(Q : NormalSubgroupProp G j) (P : SubgroupProp G k)
(prop-respects-quot : NormalSubgroupProp.subgrp-prop Q ⊆ᴳ P) where
private
module G = Group G
module Q = NormalSubgroupProp Q
module P = SubgroupProp P
prop-over-quot : SubgroupProp (QuotGroup Q) k
prop-over-quot = record {M; diff = λ {g₁} {g₂} → M.diff' g₁ g₂} where
module M where
module QG = Group (QuotGroup Q)
private
abstract
prop'-rel : ∀ {g₁ g₂} (qg₁g₂⁻¹ : quot-group-rel Q g₁ g₂)
→ P.prop g₁ == P.prop g₂
prop'-rel {g₁} {g₂} qg₁g₂⁻¹ = ua $
equiv (λ pg₁ → transport P.prop
( ap (λ g → G.comp g g₁) (G.inv-comp g₁ (G.inv g₂))
∙ G.assoc (G.inv (G.inv g₂)) (G.inv g₁) g₁
∙ ap2 G.comp (G.inv-inv g₂) (G.inv-l g₁)
∙ G.unit-r g₂)
(P.comp (P.inv pg₁g₂⁻¹) pg₁))
(λ pg₂ → transport P.prop
( G.assoc g₁ (G.inv g₂) g₂
∙ ap (G.comp g₁) (G.inv-l g₂)
∙ G.unit-r g₁)
(P.comp pg₁g₂⁻¹ pg₂))
(λ _ → prop-has-all-paths (P.level g₂) _ _)
(λ _ → prop-has-all-paths (P.level g₁) _ _)
where pg₁g₂⁻¹ : P.prop (G.diff g₁ g₂)
pg₁g₂⁻¹ = prop-respects-quot (G.diff g₁ g₂) qg₁g₂⁻¹
prop' : Group.El (QuotGroup Q) → hProp k
prop' = SetQuot-rec
(hProp-is-set k)
(λ g → P.prop g , P.level g)
(nType=-out ∘ prop'-rel)
prop : QG.El → Type k
prop g' = fst (prop' g')
abstract
level : ∀ g' → is-prop (prop g')
level g' = snd (prop' g')
ident : prop q[ G.ident ]
ident = P.ident
abstract
diff' : ∀ g₁' g₂' → prop g₁' → prop g₂' → prop (QG.diff g₁' g₂')
diff' = SetQuot-elim
{P = λ g₁' → ∀ g₂' → prop g₁' → prop g₂' → prop (QG.diff g₁' g₂')}
(λ g₁' → Π-is-set λ g₂' → →-is-set $ →-is-set $ raise-level -1 (level (QG.diff g₁' g₂')))
(λ g₁ → SetQuot-elim (λ g₂' → →-is-set $ →-is-set $ raise-level -1 (level (QG.diff q[ g₁ ] g₂')))
(λ g₂ pg₁ pg₂ → P.diff pg₁ pg₂)
(λ {_} {g₂} _ → prop-has-all-paths-↓ (→-is-prop $ →-is-prop $ level q[ G.diff g₁ g₂ ])))
(λ {_} {g₁} _ → prop-has-all-paths-↓ (Π-is-prop λ g₂' → →-is-prop $ →-is-prop $ level (QG.diff q[ g₁ ] g₂')))
-}
| 35.897196
| 119
| 0.525254
|
4deb622afcf0c357ffe691640063e401705c18d8
| 1,431
|
agda
|
Agda
|
src/LibraBFT/Impl/Types/LedgerInfoWithSignatures.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/LibraBFT/Impl/Types/LedgerInfoWithSignatures.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
src/LibraBFT/Impl/Types/LedgerInfoWithSignatures.agda
|
LaudateCorpus1/bft-consensus-agda
|
a4674fc473f2457fd3fe5123af48253cfb2404ef
|
[
"UPL-1.0"
] | null | null | null |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
import LibraBFT.Impl.OBM.Crypto as Crypto
open import LibraBFT.Impl.OBM.Logging.Logging
open import LibraBFT.Impl.Types.ValidatorVerifier as ValidatorVerifier
open import LibraBFT.ImplShared.Consensus.Types
open import Optics.All
import Util.KVMap as Map
open import Util.PKCS
open import Util.Prelude
module LibraBFT.Impl.Types.LedgerInfoWithSignatures where
obmNewNoSigs : LedgerInfo → LedgerInfoWithSignatures
obmNewNoSigs li = LedgerInfoWithSignatures∙new li Map.empty
-- HC-TODO : refactor this and TimeoutCertificate
addSignature : AccountAddress → Signature → LedgerInfoWithSignatures → LedgerInfoWithSignatures
addSignature validator sig liws =
case Map.lookup validator (liws ^∙ liwsSignatures) of λ where
(just _) → liws
nothing →
liws & liwsSignatures ∙~ Map.kvm-insert-Haskell validator sig (liws ^∙ liwsSignatures)
verifySignatures : LedgerInfoWithSignatures → ValidatorVerifier → Either ErrLog Unit
verifySignatures self validator = withErrCtx'
("LedgerInfoWithSignatures" ∷ "verify" ∷ [])
(ValidatorVerifier.batchVerifyAggregatedSignatures
validator (self ^∙ liwsLedgerInfo) (self ^∙ liwsSignatures))
| 40.885714
| 111
| 0.773585
|
52312d2559489c7f358c85f8261d4f0d0dbe69de
| 21,439
|
agda
|
Agda
|
agda-stdlib/src/Data/List/Relation/Binary/BagAndSetEquality.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/List/Relation/Binary/BagAndSetEquality.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/List/Relation/Binary/BagAndSetEquality.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Bag and set equality
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Binary.BagAndSetEquality where
open import Algebra using (Idempotent; CommutativeMonoid)
open import Algebra.Structures.Biased using (isCommutativeMonoidˡ)
open import Category.Monad using (RawMonad)
open import Data.Empty
open import Data.Fin.Base
open import Data.List.Base
open import Data.List.Categorical using (monad; module MonadProperties)
import Data.List.Properties as LP
open import Data.List.Relation.Unary.Any using (Any; here; there)
open import Data.List.Relation.Unary.Any.Properties
open import Data.List.Membership.Propositional using (_∈_)
open import Data.List.Relation.Binary.Subset.Propositional.Properties
using (⊆-preorder)
open import Data.Product as Prod hiding (map)
import Data.Product.Function.Dependent.Propositional as Σ
open import Data.Sum.Base as Sum hiding (map)
open import Data.Sum.Properties
open import Data.Sum.Function.Propositional using (_⊎-cong_)
open import Data.Unit
open import Function.Base
open import Function.Equality using (_⟨$⟩_)
import Function.Equivalence as FE
open import Function.Inverse as Inv using (_↔_; Inverse; inverse)
open import Function.Related as Related
using (↔⇒; ⌊_⌋; ⌊_⌋→; ⇒→; K-refl; SK-sym)
open import Function.Related.TypeIsomorphisms
open import Level using (Lift)
open import Relation.Binary
import Relation.Binary.Reasoning.Setoid as EqR
import Relation.Binary.Reasoning.Preorder as PreorderReasoning
open import Relation.Binary.PropositionalEquality as P
using (_≡_; _≢_; _≗_; refl)
open import Relation.Nullary
open import Data.List.Membership.Propositional.Properties
------------------------------------------------------------------------
-- Definitions
open Related public using (Kind; Symmetric-kind) renaming
( implication to subset
; reverse-implication to superset
; equivalence to set
; injection to subbag
; reverse-injection to superbag
; bijection to bag
)
[_]-Order : Kind → ∀ {a} → Set a → Preorder _ _ _
[ k ]-Order A = Related.InducedPreorder₂ k {A = A} _∈_
[_]-Equality : Symmetric-kind → ∀ {a} → Set a → Setoid _ _
[ k ]-Equality A = Related.InducedEquivalence₂ k {A = A} _∈_
infix 4 _∼[_]_
_∼[_]_ : ∀ {a} {A : Set a} → List A → Kind → List A → Set _
_∼[_]_ {A = A} xs k ys = Preorder._∼_ ([ k ]-Order A) xs ys
private
module Eq {k a} {A : Set a} = Setoid ([ k ]-Equality A)
module Ord {k a} {A : Set a} = Preorder ([ k ]-Order A)
open module ListMonad {ℓ} = RawMonad (monad {ℓ = ℓ})
module MP = MonadProperties
------------------------------------------------------------------------
-- Bag equality implies the other relations.
bag-=⇒ : ∀ {k a} {A : Set a} {xs ys : List A} →
xs ∼[ bag ] ys → xs ∼[ k ] ys
bag-=⇒ xs≈ys = ↔⇒ xs≈ys
------------------------------------------------------------------------
-- "Equational" reasoning for _⊆_ along with an additional relatedness
module ⊆-Reasoning where
private
module PreOrder {a} {A : Set a} = PreorderReasoning (⊆-preorder A)
open PreOrder public
hiding (step-≈; step-≈˘; step-∼)
infixr 2 step-∼ step-⊆
infix 1 step-∈
step-⊆ = PreOrder.step-∼
step-∈ : ∀ {a} {A : Set a} x {xs ys : List A} →
xs IsRelatedTo ys → x ∈ xs → x ∈ ys
step-∈ x xs⊆ys x∈xs = (begin xs⊆ys) x∈xs
step-∼ : ∀ {k a} {A : Set a} xs {ys zs : List A} →
ys IsRelatedTo zs → xs ∼[ ⌊ k ⌋→ ] ys → xs IsRelatedTo zs
step-∼ xs ys⊆zs xs≈ys = step-⊆ xs ys⊆zs (⇒→ xs≈ys)
syntax step-∈ x xs⊆ys x∈xs = x ∈⟨ x∈xs ⟩ xs⊆ys
syntax step-∼ xs ys⊆zs xs≈ys = xs ∼⟨ xs≈ys ⟩ ys⊆zs
syntax step-⊆ xs ys⊆zs xs⊆ys = xs ⊆⟨ xs⊆ys ⟩ ys⊆zs
------------------------------------------------------------------------
-- Congruence lemmas
------------------------------------------------------------------------
-- _∷_
module _ {a k} {A : Set a} {x y : A} {xs ys} where
∷-cong : x ≡ y → xs ∼[ k ] ys → x ∷ xs ∼[ k ] y ∷ ys
∷-cong refl xs≈ys {y} =
y ∈ x ∷ xs ↔⟨ SK-sym $ ∷↔ (y ≡_) ⟩
(y ≡ x ⊎ y ∈ xs) ∼⟨ (y ≡ x ∎) ⊎-cong xs≈ys ⟩
(y ≡ x ⊎ y ∈ ys) ↔⟨ ∷↔ (y ≡_) ⟩
y ∈ x ∷ ys ∎
where open Related.EquationalReasoning
------------------------------------------------------------------------
-- map
module _ {ℓ k} {A B : Set ℓ} {f g : A → B} {xs ys} where
map-cong : f ≗ g → xs ∼[ k ] ys → map f xs ∼[ k ] map g ys
map-cong f≗g xs≈ys {x} =
x ∈ map f xs ↔⟨ SK-sym $ map↔ ⟩
Any (λ y → x ≡ f y) xs ∼⟨ Any-cong (↔⇒ ∘ helper) xs≈ys ⟩
Any (λ y → x ≡ g y) ys ↔⟨ map↔ ⟩
x ∈ map g ys ∎
where
open Related.EquationalReasoning
helper : ∀ y → x ≡ f y ↔ x ≡ g y
helper y = record
{ to = P.→-to-⟶ (λ x≡fy → P.trans x≡fy ( f≗g y))
; from = P.→-to-⟶ (λ x≡gy → P.trans x≡gy (P.sym $ f≗g y))
; inverse-of = record
{ left-inverse-of = λ { P.refl → P.trans-symʳ (f≗g y) }
; right-inverse-of = λ { P.refl → P.trans-symˡ (f≗g y) }
}
}
------------------------------------------------------------------------
-- _++_
module _ {a k} {A : Set a} {xs₁ xs₂ ys₁ ys₂ : List A} where
++-cong : xs₁ ∼[ k ] xs₂ → ys₁ ∼[ k ] ys₂ →
xs₁ ++ ys₁ ∼[ k ] xs₂ ++ ys₂
++-cong xs₁≈xs₂ ys₁≈ys₂ {x} =
x ∈ xs₁ ++ ys₁ ↔⟨ SK-sym $ ++↔ ⟩
(x ∈ xs₁ ⊎ x ∈ ys₁) ∼⟨ xs₁≈xs₂ ⊎-cong ys₁≈ys₂ ⟩
(x ∈ xs₂ ⊎ x ∈ ys₂) ↔⟨ ++↔ ⟩
x ∈ xs₂ ++ ys₂ ∎
where open Related.EquationalReasoning
------------------------------------------------------------------------
-- concat
module _ {a k} {A : Set a} {xss yss : List (List A)} where
concat-cong : xss ∼[ k ] yss → concat xss ∼[ k ] concat yss
concat-cong xss≈yss {x} =
x ∈ concat xss ↔⟨ SK-sym concat↔ ⟩
Any (Any (x ≡_)) xss ∼⟨ Any-cong (λ _ → _ ∎) xss≈yss ⟩
Any (Any (x ≡_)) yss ↔⟨ concat↔ ⟩
x ∈ concat yss ∎
where open Related.EquationalReasoning
------------------------------------------------------------------------
-- _>>=_
module _ {ℓ k} {A B : Set ℓ} {xs ys} {f g : A → List B} where
>>=-cong : xs ∼[ k ] ys → (∀ x → f x ∼[ k ] g x) →
(xs >>= f) ∼[ k ] (ys >>= g)
>>=-cong xs≈ys f≈g {x} =
x ∈ (xs >>= f) ↔⟨ SK-sym >>=↔ ⟩
Any (λ y → x ∈ f y) xs ∼⟨ Any-cong (λ x → f≈g x) xs≈ys ⟩
Any (λ y → x ∈ g y) ys ↔⟨ >>=↔ ⟩
x ∈ (ys >>= g) ∎
where open Related.EquationalReasoning
------------------------------------------------------------------------
-- _⊛_
module _ {ℓ k} {A B : Set ℓ} {fs gs : List (A → B)} {xs ys} where
⊛-cong : fs ∼[ k ] gs → xs ∼[ k ] ys → (fs ⊛ xs) ∼[ k ] (gs ⊛ ys)
⊛-cong fs≈gs xs≈ys =
>>=-cong fs≈gs λ f →
>>=-cong xs≈ys λ x →
_ ∎
where open Related.EquationalReasoning
------------------------------------------------------------------------
-- _⊗_
module _ {ℓ k} {A B : Set ℓ} {xs₁ xs₂ : List A} {ys₁ ys₂ : List B} where
⊗-cong : xs₁ ∼[ k ] xs₂ → ys₁ ∼[ k ] ys₂ →
(xs₁ ⊗ ys₁) ∼[ k ] (xs₂ ⊗ ys₂)
⊗-cong xs₁≈xs₂ ys₁≈ys₂ =
⊛-cong (⊛-cong (Ord.refl {x = [ _,_ ]}) xs₁≈xs₂) ys₁≈ys₂
------------------------------------------------------------------------
-- Other properties
-- _++_ and [] form a commutative monoid, with either bag or set
-- equality as the underlying equality.
commutativeMonoid : ∀ {a} → Symmetric-kind → Set a →
CommutativeMonoid _ _
commutativeMonoid {a} k A = record
{ Carrier = List A
; _≈_ = _∼[ ⌊ k ⌋ ]_
; _∙_ = _++_
; ε = []
; isCommutativeMonoid = isCommutativeMonoidˡ record
{ isSemigroup = record
{ isMagma = record
{ isEquivalence = Eq.isEquivalence
; ∙-cong = ++-cong
}
; assoc = λ xs ys zs →
Eq.reflexive (LP.++-assoc xs ys zs)
}
; identityˡ = λ xs {x} → x ∈ xs ∎
; comm = λ xs ys {x} →
x ∈ xs ++ ys ↔⟨ ++↔++ xs ys ⟩
x ∈ ys ++ xs ∎
}
}
where open Related.EquationalReasoning
-- The only list which is bag or set equal to the empty list (or a
-- subset or subbag of the list) is the empty list itself.
empty-unique : ∀ {k a} {A : Set a} {xs : List A} →
xs ∼[ ⌊ k ⌋→ ] [] → xs ≡ []
empty-unique {xs = []} _ = refl
empty-unique {xs = _ ∷ _} ∷∼[] with ⇒→ ∷∼[] (here refl)
... | ()
-- _++_ is idempotent (under set equality).
++-idempotent : ∀ {a} {A : Set a} → Idempotent {A = List A} _∼[ set ]_ _++_
++-idempotent {a} xs {x} =
x ∈ xs ++ xs ∼⟨ FE.equivalence ([ id , id ]′ ∘ _⟨$⟩_ (Inverse.from $ ++↔))
(_⟨$⟩_ (Inverse.to $ ++↔) ∘ inj₁) ⟩
x ∈ xs ∎
where open Related.EquationalReasoning
-- The list monad's bind distributes from the left over _++_.
>>=-left-distributive :
∀ {ℓ} {A B : Set ℓ} (xs : List A) {f g : A → List B} →
(xs >>= λ x → f x ++ g x) ∼[ bag ] (xs >>= f) ++ (xs >>= g)
>>=-left-distributive {ℓ} xs {f} {g} {y} =
y ∈ (xs >>= λ x → f x ++ g x) ↔⟨ SK-sym $ >>=↔ ⟩
Any (λ x → y ∈ f x ++ g x) xs ↔⟨ SK-sym (Any-cong (λ _ → ++↔) (_ ∎)) ⟩
Any (λ x → y ∈ f x ⊎ y ∈ g x) xs ↔⟨ SK-sym $ ⊎↔ ⟩
(Any (λ x → y ∈ f x) xs ⊎ Any (λ x → y ∈ g x) xs) ↔⟨ >>=↔ ⟨ _⊎-cong_ ⟩ >>=↔ ⟩
(y ∈ (xs >>= f) ⊎ y ∈ (xs >>= g)) ↔⟨ ++↔ ⟩
y ∈ (xs >>= f) ++ (xs >>= g) ∎
where open Related.EquationalReasoning
-- The same applies to _⊛_.
⊛-left-distributive :
∀ {ℓ} {A B : Set ℓ} (fs : List (A → B)) xs₁ xs₂ →
(fs ⊛ (xs₁ ++ xs₂)) ∼[ bag ] (fs ⊛ xs₁) ++ (fs ⊛ xs₂)
⊛-left-distributive {B = B} fs xs₁ xs₂ = begin
fs ⊛ (xs₁ ++ xs₂) ≡⟨⟩
(fs >>= λ f → xs₁ ++ xs₂ >>= return ∘ f) ≡⟨ (MP.cong (refl {x = fs}) λ f →
MP.right-distributive xs₁ xs₂ (return ∘ f)) ⟩
(fs >>= λ f → (xs₁ >>= return ∘ f) ++
(xs₂ >>= return ∘ f)) ≈⟨ >>=-left-distributive fs ⟩
(fs >>= λ f → xs₁ >>= return ∘ f) ++
(fs >>= λ f → xs₂ >>= return ∘ f) ≡⟨⟩
(fs ⊛ xs₁) ++ (fs ⊛ xs₂) ∎
where open EqR ([ bag ]-Equality B)
private
-- If x ∷ xs is set equal to x ∷ ys, then xs and ys are not
-- necessarily set equal.
¬-drop-cons : ∀ {a} {A : Set a} {x : A} →
¬ (∀ {xs ys} → x ∷ xs ∼[ set ] x ∷ ys → xs ∼[ set ] ys)
¬-drop-cons {x = x} drop-cons
with FE.Equivalence.to x∼[] ⟨$⟩ here refl
where
x,x≈x : (x ∷ x ∷ []) ∼[ set ] [ x ]
x,x≈x = ++-idempotent [ x ]
x∼[] : [ x ] ∼[ set ] []
x∼[] = drop-cons x,x≈x
... | ()
-- However, the corresponding property does hold for bag equality.
drop-cons : ∀ {a} {A : Set a} {x : A} {xs ys} →
x ∷ xs ∼[ bag ] x ∷ ys → xs ∼[ bag ] ys
drop-cons {A = A} {x} {xs} {ys} x∷xs≈x∷ys =
⊎-left-cancellative
(∼→⊎↔⊎ x∷xs≈x∷ys)
(lemma x∷xs≈x∷ys)
(lemma (SK-sym x∷xs≈x∷ys))
where
-- TODO: Some of the code below could perhaps be exposed to users.
-- List membership can be expressed as "there is an index which
-- points to the element".
∈-index : ∀ {a} {A : Set a} {z}
(xs : List A) → z ∈ xs ↔ ∃ λ i → z ≡ lookup xs i
∈-index {z = z} [] =
z ∈ [] ↔⟨ SK-sym ⊥↔Any[] ⟩
⊥ ↔⟨ SK-sym $ inverse (λ { (() , _) }) (λ ()) (λ { (() , _) }) (λ ()) ⟩
(∃ λ (i : Fin 0) → z ≡ lookup [] i) ∎
where
open Related.EquationalReasoning
∈-index {z = z} (x ∷ xs) =
z ∈ x ∷ xs ↔⟨ SK-sym (∷↔ _) ⟩
(z ≡ x ⊎ z ∈ xs) ↔⟨ K-refl ⊎-cong ∈-index xs ⟩
(z ≡ x ⊎ ∃ λ i → z ≡ lookup xs i) ↔⟨ SK-sym $ inverse (λ { (zero , p) → inj₁ p; (suc i , p) → inj₂ (i , p) })
(λ { (inj₁ p) → zero , p; (inj₂ (i , p)) → suc i , p })
(λ { (zero , _) → refl; (suc _ , _) → refl })
(λ { (inj₁ _) → refl; (inj₂ _) → refl }) ⟩
(∃ λ i → z ≡ lookup (x ∷ xs) i) ∎
where
open Related.EquationalReasoning
-- The index which points to the element.
index-of : ∀ {a} {A : Set a} {z} {xs : List A} →
z ∈ xs → Fin (length xs)
index-of = proj₁ ∘ (Inverse.to (∈-index _) ⟨$⟩_)
-- The type ∃ λ z → z ∈ xs is isomorphic to Fin n, where n is the
-- length of xs.
--
-- Thierry Coquand pointed out that (a variant of) this statement is
-- a generalisation of the fact that singletons are contractible.
Fin-length : ∀ {a} {A : Set a}
(xs : List A) → (∃ λ z → z ∈ xs) ↔ Fin (length xs)
Fin-length xs =
(∃ λ z → z ∈ xs) ↔⟨ Σ.cong K-refl (∈-index xs) ⟩
(∃ λ z → ∃ λ i → z ≡ lookup xs i) ↔⟨ ∃∃↔∃∃ _ ⟩
(∃ λ i → ∃ λ z → z ≡ lookup xs i) ↔⟨ Σ.cong K-refl (inverse _ (λ _ → _ , refl) (λ { (_ , refl) → refl }) (λ _ → refl)) ⟩
(Fin (length xs) × Lift _ ⊤) ↔⟨ ×-identityʳ _ _ ⟩
Fin (length xs) ∎
where
open Related.EquationalReasoning
-- From this lemma we get that lists which are bag equivalent have
-- related lengths.
Fin-length-cong : ∀ {a} {A : Set a} {xs ys : List A} →
xs ∼[ bag ] ys → Fin (length xs) ↔ Fin (length ys)
Fin-length-cong {xs = xs} {ys} xs≈ys =
Fin (length xs) ↔⟨ SK-sym $ Fin-length xs ⟩
∃ (λ z → z ∈ xs) ↔⟨ Σ.cong K-refl xs≈ys ⟩
∃ (λ z → z ∈ ys) ↔⟨ Fin-length ys ⟩
Fin (length ys) ∎
where
open Related.EquationalReasoning
-- The index-of function commutes with applications of certain
-- inverses.
index-of-commutes :
∀ {a} {A : Set a} {z : A} {xs ys} →
(xs≈ys : xs ∼[ bag ] ys) (p : z ∈ xs) →
index-of (Inverse.to xs≈ys ⟨$⟩ p) ≡
Inverse.to (Fin-length-cong xs≈ys) ⟨$⟩ index-of p
index-of-commutes {z = z} {xs} {ys} xs≈ys p =
index-of (to xs≈ys ⟨$⟩ p) ≡⟨ lemma z p ⟩
index-of (to xs≈ys ⟨$⟩ proj₂
(from (Fin-length xs) ⟨$⟩ (to (Fin-length xs) ⟨$⟩ (z , p)))) ≡⟨⟩
index-of (proj₂ (Prod.map id (to xs≈ys ⟨$⟩_)
(from (Fin-length xs) ⟨$⟩ (to (Fin-length xs) ⟨$⟩ (z , p))))) ≡⟨⟩
to (Fin-length ys) ⟨$⟩ Prod.map id (to xs≈ys ⟨$⟩_)
(from (Fin-length xs) ⟨$⟩ index-of p) ≡⟨⟩
to (Fin-length-cong xs≈ys) ⟨$⟩ index-of p ∎
where
open P.≡-Reasoning
open Inverse
lemma :
∀ z p →
index-of (to xs≈ys ⟨$⟩ p) ≡
index-of (to xs≈ys ⟨$⟩ proj₂
(from (Fin-length xs) ⟨$⟩ (to (Fin-length xs) ⟨$⟩ (z , p))))
lemma z p with to (Fin-length xs) ⟨$⟩ (z , p)
| left-inverse-of (Fin-length xs) (z , p)
lemma .(lookup xs i) .(from (∈-index xs) ⟨$⟩ (i , refl)) | i | refl =
refl
-- Bag equivalence isomorphisms preserve index equality. Note that
-- this means that, even if the underlying equality is proof
-- relevant, a bag equivalence isomorphism cannot map two distinct
-- proofs, that point to the same position, to different positions.
index-equality-preserved :
∀ {a} {A : Set a} {z : A} {xs ys} {p q : z ∈ xs}
(xs≈ys : xs ∼[ bag ] ys) →
index-of p ≡ index-of q →
index-of (Inverse.to xs≈ys ⟨$⟩ p) ≡
index-of (Inverse.to xs≈ys ⟨$⟩ q)
index-equality-preserved {p = p} {q} xs≈ys eq =
index-of (Inverse.to xs≈ys ⟨$⟩ p) ≡⟨ index-of-commutes xs≈ys p ⟩
Inverse.to (Fin-length-cong xs≈ys) ⟨$⟩ index-of p ≡⟨ P.cong (Inverse.to (Fin-length-cong xs≈ys) ⟨$⟩_) eq ⟩
Inverse.to (Fin-length-cong xs≈ys) ⟨$⟩ index-of q ≡⟨ P.sym $ index-of-commutes xs≈ys q ⟩
index-of (Inverse.to xs≈ys ⟨$⟩ q) ∎
where
open P.≡-Reasoning
-- The old inspect idiom.
inspect : ∀ {a} {A : Set a} (x : A) → ∃ (x ≡_)
inspect x = x , refl
-- A function is "well-behaved" if any "left" element which is the
-- image of a "right" element is in turn not mapped to another
-- "left" element.
Well-behaved : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c} →
(A ⊎ B → A ⊎ C) → Set _
Well-behaved f =
∀ {b a a′} → f (inj₂ b) ≡ inj₁ a → f (inj₁ a) ≢ inj₁ a′
-- The type constructor _⊎_ is left cancellative for certain
-- well-behaved inverses.
⊎-left-cancellative :
∀ {a b c} {A : Set a} {B : Set b} {C : Set c}
(f : (A ⊎ B) ↔ (A ⊎ C)) →
Well-behaved (Inverse.to f ⟨$⟩_) →
Well-behaved (Inverse.from f ⟨$⟩_) →
B ↔ C
⊎-left-cancellative {A = A} = λ inv to-hyp from-hyp → inverse
(g (to inv ⟨$⟩_) to-hyp)
(g (from inv ⟨$⟩_) from-hyp)
(g∘g inv to-hyp from-hyp)
(g∘g (SK-sym inv) from-hyp to-hyp)
where
open Inverse
module _
{a b c} {A : Set a} {B : Set b} {C : Set c}
(f : A ⊎ B → A ⊎ C)
(hyp : Well-behaved f)
where
mutual
g : B → C
g b = g′ (inspect (f (inj₂ b)))
g′ : ∀ {b} → ∃ (f (inj₂ b) ≡_) → C
g′ (inj₂ c , _) = c
g′ (inj₁ a , eq) = g″ eq (inspect (f (inj₁ a)))
g″ : ∀ {a b} →
f (inj₂ b) ≡ inj₁ a → ∃ (f (inj₁ a) ≡_) → C
g″ _ (inj₂ c , _) = c
g″ eq₁ (inj₁ _ , eq₂) = ⊥-elim $ hyp eq₁ eq₂
g∘g : ∀ {b c} {B : Set b} {C : Set c}
(f : (A ⊎ B) ↔ (A ⊎ C)) →
(to-hyp : Well-behaved (to f ⟨$⟩_)) →
(from-hyp : Well-behaved (from f ⟨$⟩_)) →
∀ b → g (from f ⟨$⟩_) from-hyp (g (to f ⟨$⟩_) to-hyp b) ≡ b
g∘g f to-hyp from-hyp b = g∘g′
where
open P.≡-Reasoning
g∘g′ : g (from f ⟨$⟩_) from-hyp (g (to f ⟨$⟩_) to-hyp b) ≡ b
g∘g′ with inspect (to f ⟨$⟩ inj₂ b)
g∘g′ | inj₂ c , eq₁ with inspect (from f ⟨$⟩ inj₂ c)
g∘g′ | inj₂ c , eq₁ | inj₂ b′ , eq₂ = inj₂-injective (
inj₂ b′ ≡⟨ P.sym eq₂ ⟩
from f ⟨$⟩ inj₂ c ≡⟨ to-from f eq₁ ⟩
inj₂ b ∎)
g∘g′ | inj₂ c , eq₁ | inj₁ a , eq₂ with
inj₁ a ≡⟨ P.sym eq₂ ⟩
from f ⟨$⟩ inj₂ c ≡⟨ to-from f eq₁ ⟩
inj₂ b ∎
... | ()
g∘g′ | inj₁ a , eq₁ with inspect (to f ⟨$⟩ inj₁ a)
g∘g′ | inj₁ a , eq₁ | inj₁ a′ , eq₂ = ⊥-elim $ to-hyp eq₁ eq₂
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ with inspect (from f ⟨$⟩ inj₂ c)
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ | inj₂ b′ , eq₃ with
inj₁ a ≡⟨ P.sym $ to-from f eq₂ ⟩
from f ⟨$⟩ inj₂ c ≡⟨ eq₃ ⟩
inj₂ b′ ∎
... | ()
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ | inj₁ a′ , eq₃ with inspect (from f ⟨$⟩ inj₁ a′)
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ | inj₁ a′ , eq₃ | inj₁ a″ , eq₄ = ⊥-elim $ from-hyp eq₃ eq₄
g∘g′ | inj₁ a , eq₁ | inj₂ c , eq₂ | inj₁ a′ , eq₃ | inj₂ b′ , eq₄ = inj₂-injective (
let lemma =
inj₁ a′ ≡⟨ P.sym eq₃ ⟩
from f ⟨$⟩ inj₂ c ≡⟨ to-from f eq₂ ⟩
inj₁ a ∎
in
inj₂ b′ ≡⟨ P.sym eq₄ ⟩
from f ⟨$⟩ inj₁ a′ ≡⟨ P.cong ((from f ⟨$⟩_) ∘ inj₁) $ inj₁-injective lemma ⟩
from f ⟨$⟩ inj₁ a ≡⟨ to-from f eq₁ ⟩
inj₂ b ∎)
-- Some final lemmas.
∼→⊎↔⊎ :
∀ {x : A} {xs ys} →
x ∷ xs ∼[ bag ] x ∷ ys →
∀ {z} → (z ≡ x ⊎ z ∈ xs) ↔ (z ≡ x ⊎ z ∈ ys)
∼→⊎↔⊎ {x} {xs} {ys} x∷xs≈x∷ys {z} =
(z ≡ x ⊎ z ∈ xs) ↔⟨ ∷↔ _ ⟩
z ∈ x ∷ xs ↔⟨ x∷xs≈x∷ys ⟩
z ∈ x ∷ ys ↔⟨ SK-sym (∷↔ _) ⟩
(z ≡ x ⊎ z ∈ ys) ∎
where
open Related.EquationalReasoning
lemma : ∀ {xs ys} (inv : x ∷ xs ∼[ bag ] x ∷ ys) {z} →
Well-behaved (Inverse.to (∼→⊎↔⊎ inv {z}) ⟨$⟩_)
lemma {xs} inv {b = z∈xs} {a = p} {a′ = q} hyp₁ hyp₂ with
zero ≡⟨⟩
index-of {xs = x ∷ xs} (here p) ≡⟨⟩
index-of {xs = x ∷ xs} (to (∷↔ _) ⟨$⟩ inj₁ p) ≡⟨ P.cong (index-of ∘ (to (∷↔ (_ ≡_)) ⟨$⟩_)) $ P.sym $
to-from (∼→⊎↔⊎ inv) {x = inj₁ p} hyp₂ ⟩
index-of {xs = x ∷ xs} (to (∷↔ _) ⟨$⟩ (from (∼→⊎↔⊎ inv) ⟨$⟩ inj₁ q)) ≡⟨ P.cong index-of $
right-inverse-of (∷↔ _) (from inv ⟨$⟩ here q) ⟩
index-of {xs = x ∷ xs} (to (SK-sym inv) ⟨$⟩ here q) ≡⟨ index-equality-preserved (SK-sym inv) refl ⟩
index-of {xs = x ∷ xs} (to (SK-sym inv) ⟨$⟩ here p) ≡⟨ P.cong index-of $ P.sym $
right-inverse-of (∷↔ _) (from inv ⟨$⟩ here p) ⟩
index-of {xs = x ∷ xs} (to (∷↔ _) ⟨$⟩ (from (∼→⊎↔⊎ inv) ⟨$⟩ inj₁ p)) ≡⟨ P.cong (index-of ∘ (to (∷↔ (_ ≡_)) ⟨$⟩_)) $
to-from (∼→⊎↔⊎ inv) {x = inj₂ z∈xs} hyp₁ ⟩
index-of {xs = x ∷ xs} (to (∷↔ _) ⟨$⟩ inj₂ z∈xs) ≡⟨⟩
index-of {xs = x ∷ xs} (there z∈xs) ≡⟨⟩
suc (index-of {xs = xs} z∈xs) ∎
where
open Inverse
open P.≡-Reasoning
... | ()
| 38.147687
| 128
| 0.448855
|
215b3744b11d0787246c14e7982de37426b167e8
| 4,963
|
agda
|
Agda
|
another/Simple.agda
|
jaiyalas/ParametricLambda
|
ee174590136f7162af308502233e5317b009a858
|
[
"MIT"
] | 2
|
2015-10-15T05:57:05.000Z
|
2015-10-15T05:57:52.000Z
|
another/Simple.agda
|
jaiyalas/haha
|
ee174590136f7162af308502233e5317b009a858
|
[
"MIT"
] | null | null | null |
another/Simple.agda
|
jaiyalas/haha
|
ee174590136f7162af308502233e5317b009a858
|
[
"MIT"
] | null | null | null |
module Simple where
open import Data.Nat renaming (_≟_ to _≟ℕ_)
open import Data.Fin hiding (_+_; inject)
open import Data.String hiding (_++_) renaming (_≟_ to _≟S_)
open import Relation.Nullary using (¬_; yes; no)
open import Relation.Binary.PropositionalEquality using (refl; _≡_)
open import Data.List
open import Data.Sum using (_⊎_; inj₁; inj₂)
FName : Set
FName = String
FNames : Set
FNames = List FName
data Expr : ℕ → Set where
num : ∀ {n} → ℕ → Expr n
bv : ∀ {n} → (i : Fin n) → Expr n
fv : ∀ {n} → (x : FName) → Expr n
ƛ : ∀ {n} → (e : Expr (suc n)) → Expr n
_·_ : ∀ {n} → (f : Expr n) → (e : Expr n) → Expr n
-- This idx indicates the amount of existence of lambda
-- out of current express
Expr0 : Set
Expr0 = Expr zero
↓ℕ≠ℕ : ∀ {n m} {i : Fin m}
→ ¬ (suc n ≡ toℕ (suc i))
→ ¬ (n ≡ toℕ i)
↓ℕ≠ℕ {n} {m} {i} sn≠si n≡i rewrite n≡i = sn≠si refl
-- ↓ℕ≠ℕ {n} {m} {i} sn≠si n≡i with n≡i
-- ↓ℕ≠ℕ sn≠si n≡i | refl = sn≠si refl
↓fin : ∀ {n} → (i : Fin (suc n)) → ¬ (n ≡ toℕ i) → Fin n
↓fin {zero} zero 0≠0 with 0≠0 refl
↓fin {zero} zero 0≠0 | ()
↓fin {zero} (suc ()) 0≠n
↓fin {suc n} zero i≠0 = zero
↓fin {suc n} (suc i) sn≠si = suc (↓fin i (↓ℕ≠ℕ sn≠si))
↑expr : ∀ {n} → Expr n → Expr (suc n)
↑expr (num i) = num i
↑expr (bv i) = bv (inject₁ i)
-- inject₁ : ∀ {m} → Fin m → Fin (suc m)
↑expr (fv x) = fv x
↑expr (ƛ e) = ƛ (↑expr e)
↑expr (e · e₁) = ↑expr e · ↑expr e₁
{- substitution for bounded and free variable-}
[_↦_] : ∀ n → Expr n → Expr (suc n) → Expr n
[ m ↦ t ] (num i) = num i
[ m ↦ t ] (bv i) with m ≟ℕ toℕ i
... | yes m=i = t
... | no m≠i = bv (↓fin i m≠i)
[ m ↦ t ] (fv x) = fv x
[ m ↦ t ] (ƛ e) = ƛ ([ suc m ↦ ↑expr t ] e)
[ m ↦ t ] (e · e₁) = [ m ↦ t ] e · [ m ↦ t ] e₁
[_↤_] : ∀ n → FName → Expr n → Expr (suc n)
[ m ↤ name ] (num x) = num x
[ m ↤ name ] (bv i) = ↑expr (bv i)
[ m ↤ name ] (fv x) with x ≟S name
[ m ↤ name ] (fv x) | yes p = bv (fromℕ m)
[ m ↤ name ] (fv x) | no ¬p = fv x
[ m ↤ name ] (ƛ t) = ƛ ([ suc m ↤ name ] t)
[ m ↤ name ] (t · t₁) = [ m ↤ name ] t · [ m ↤ name ] t₁
[_↝_] : ∀ {n} → FName → Expr n → Expr n → Expr n
[ n ↝ t ] (num i) = num i
[ n ↝ t ] (bv i) = bv i
[ n ↝ t ] (fv x) with n ≟S x
[ n ↝ t ] (fv x) | yes p = t
[ n ↝ t ] (fv x) | no ¬p = fv x
[ n ↝ t ] (ƛ x) = ƛ ([ n ↝ ↑expr t ] x)
[ n ↝ t ] (x · y) = [ n ↝ t ] x · [ n ↝ t ] y
_₀↦_ : Expr 1 → Expr 0 → Expr 0
m ₀↦ t = [ 0 ↦ t ] m
_↦₀_ : FName → Expr 0 → Expr 1
name ↦₀ t = [ 0 ↤ name ] t
_₀↤_ : Expr 0 → FName → Expr 1
t ₀↤ x = [ 0 ↤ x ] t
_₀↝_ : Expr 1 → FName → Expr 0
x ₀↝ s = x ₀↦ (fv s)
fvars : ∀ {n} → Expr n → FNames
fvars (num x) = []
fvars (bv i) = []
fvars (fv x) = x ∷ []
fvars (ƛ f) = fvars f
fvars (f · x) = fvars f ++ fvars x
-- ############################## --
{- locally closed -}
-- ############################## --
open import Data.List.Any as Any
open Any.Membership-≡ using (_∈_; _∉_)
open import Data.Product
data LC : ∀ {n} → Expr n → Set where
numᶜ : ∀ {n} → (i : ℕ) → LC {n} (num i)
fvᶜ : ∀ {n}
→ (x : FName)
→ LC {n} (fv x)
_·ᶜ_ : ∀ {n} {f x}
→ LC {n} f
→ LC {n} x
→ LC {n} (f · x)
ƛᶜ : ∀ {e}
→ (ns : FNames)
→ ( ∀ {x} → x ∉ ns → LC {0} (e ₀↦ fv x) )
→ LC {0} (ƛ e)
postulate fresh-gen : FNames → FName
postulate fresh-gen-spec : ∀ ns → fresh-gen ns ∉ ns
genName : (ns : FNames) → ∃ (λ x → x ∉ ns)
genName ns = fresh-gen ns , fresh-gen-spec ns
orz : ∀ {e} {nn} → nn ↦₀ (e ₀↦ fv nn) ≡ e
orz = {! !}
foo : ∀ {nn} → (e : Expr 1) → LC {0} (e ₀↦ fv nn) → LC {1} e
foo (num i) lcp = {! !}
foo (bv i) lcp = {! !}
foo (fv y) lcp = {! !}
foo (ƛ e) lcp = {! !}
foo (f · x) lcp = {! !}
absᶜ : ∀ {e} → LC {0} (ƛ e) → LC {1} e
absᶜ (ƛᶜ ns lcex) = {! !}
where nn = proj₁ (genName ns)
nn∉ns = proj₂ (genName ns)
x = lcex {nn} nn∉ns
appᶜ₁ : ∀ {n} {f x} → LC {n} (f · x) → LC {n} f
appᶜ₁ (lcf ·ᶜ lcx) = lcf
appᶜ₂ : ∀ {n} {f x} → LC {n} (f · x) → LC {n} x
appᶜ₂ (lcf ·ᶜ lcx) = lcx
lc? : ∀ {n} → (e : Expr n) → (LC {n} e ⊎ ¬ LC {n} e)
lc? (num x) = inj₁ (numᶜ x)
lc? (bv i) = inj₂ (λ ())
lc? (fv x) = inj₁ (fvᶜ x)
lc? (ƛ e) with lc? e
lc? (ƛ e) | inj₁ x = inj₁ {! !}
lc? (ƛ e) | inj₂ y = inj₂ {! !}
lc? (f · x) with lc? f | lc? x
lc? (f · x) | inj₁ f' | inj₁ x' = inj₁ (f' ·ᶜ x')
lc? (f · x) | inj₁ f' | inj₂ x' = inj₂ (λ p → x' (appᶜ₂ p))
lc? (f · x) | inj₂ f' | _ = inj₂ (λ p → f' (appᶜ₁ p))
-- ############################## --
{- value and semantics -}
-- ############################## --
data Val : Expr0 → Set where
num⁰ : ∀ n → Val (num n)
ƛ⁰ : ∀ e → Val (ƛ e)
var? : (e : Expr0) → (Val e ⊎ ¬ (Val e))
var? (num i) = inj₁ (num⁰ i)
var? (bv i) = inj₂ (λ ())
var? (fv x) = inj₂ (λ ())
var? (ƛ x) = inj₁ (ƛ⁰ x)
var? (x · y) = inj₂ (λ ())
-- don't know what the hell this shit is
data _⟼_ : Expr 0 → Expr 0 → Set where
app : ∀ {body para}
→ ((ƛ body) · para) ⟼ (body ₀↦ para)
| 26.972826
| 67
| 0.455571
|
fdd2db16347b9556dc8e0e12f513e763a68d375e
| 2,765
|
agda
|
Agda
|
TotalParserCombinators/Recogniser.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 7
|
2016-12-13T05:23:14.000Z
|
2021-06-22T05:35:31.000Z
|
TotalParserCombinators/Recogniser.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 1
|
2018-01-22T22:21:41.000Z
|
2018-01-24T16:39:37.000Z
|
TotalParserCombinators/Recogniser.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Recognisers built on top of the parsers
------------------------------------------------------------------------
-- Note that these recognisers are different from the ones in
-- TotalRecognisers.LeftRecursion: these allow the use of fewer sharps.
-- (Compare the examples in TotalRecognisers.LeftRecursion.Expression
-- and TotalParserCombinators.Recogniser.Expression.)
module TotalParserCombinators.Recogniser where
open import Category.Monad
open import Coinduction
open import Data.Bool
open import Data.List as List
import Data.List.Categorical
open import Data.Maybe
open import Data.Unit
open import Level
open RawMonadPlus {f = zero} Data.List.Categorical.monadPlus
using () renaming (_⊛_ to _⊛′_)
open import TotalParserCombinators.Parser as Parser
using (Parser; flatten); open Parser.Parser
import TotalParserCombinators.Lib as Lib
------------------------------------------------------------------------
-- Helper function
infixl 4 _·′_
_·′_ : (mb₁ mb₂ : Maybe (List ⊤)) → List ⊤
mb₁ ·′ nothing = []
mb₁ ·′ just b₂ = List.map _ (flatten mb₁) ⊛′ b₂
------------------------------------------------------------------------
-- Recognisers
infixl 50 _·_
infixl 5 _∣_
-- Recognisers.
mutual
-- The index is non-empty if the corresponding language contains the
-- empty string (is nullable).
data P (Tok : Set) : List ⊤ → Set₁ where
-- Parsers can be turned into recognisers.
lift : ∀ {R n} (p : Parser Tok R n) → P Tok (List.map _ n)
-- Symmetric choice.
_∣_ : ∀ {n₁ n₂}
(p₁ : P Tok n₁) (p₂ : P Tok n₂) → P Tok (n₁ ++ n₂)
-- Sequencing.
_·_ : ∀ {n₁ n₂}
(p₁ : ∞⟨ n₂ ⟩P Tok (flatten n₁))
(p₂ : ∞⟨ n₁ ⟩P Tok (flatten n₂)) →
P Tok (n₁ ·′ n₂)
-- Delayed if the index is /nothing/.
∞⟨_⟩P : Maybe (List ⊤) → Set → List ⊤ → Set₁
∞⟨ nothing ⟩P Tok n = ∞ (P Tok n)
∞⟨ just _ ⟩P Tok n = P Tok n
------------------------------------------------------------------------
-- Helper function related to ∞⟨_⟩P
-- Is the argument parser forced? If the result is just something,
-- then it is.
forced? : ∀ {Tok m n} → ∞⟨ m ⟩P Tok n → Maybe (List ⊤)
forced? {m = m} _ = m
------------------------------------------------------------------------
-- The semantics of the recognisers is defined by translation
⟦_⟧ : ∀ {Tok n} (p : P Tok n) → Parser Tok ⊤ n
⟦ lift p ⟧ = _ <$> p
⟦ p₁ ∣ p₂ ⟧ = ⟦ p₁ ⟧ ∣ ⟦ p₂ ⟧
⟦ p₁ · p₂ ⟧ with forced? p₁ | forced? p₂
... | just xs | nothing = _ <$> ⟦ p₁ ⟧ ⊛ ♯ ⟦ ♭ p₂ ⟧
... | just xs | just ys = _ <$> ⟦ p₁ ⟧ ⊛ ⟦ p₂ ⟧
... | nothing | nothing = ♯ (_ <$> ⟦ ♭ p₁ ⟧) ⊛ ♯ ⟦ ♭ p₂ ⟧
... | nothing | just ys = ♯ (_ <$> ⟦ ♭ p₁ ⟧) ⊛ ⟦ p₂ ⟧
| 30.722222
| 72
| 0.511031
|
fd78ec0894db6397f0da21b284deb61cd90afb9f
| 8,197
|
agda
|
Agda
|
Cubical/Algebra/ZariskiLattice/Base.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/ZariskiLattice/Base.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/ZariskiLattice/Base.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.ZariskiLattice.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Transport
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_ ; _^_ to _^ℕ_
; +-comm to +ℕ-comm ; +-assoc to +ℕ-assoc
; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm
; ·-identityʳ to ·ℕ-rid)
open import Cubical.Data.Sigma.Base
open import Cubical.Data.Sigma.Properties
open import Cubical.Data.FinData
open import Cubical.Data.Unit
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary
open import Cubical.Relation.Binary.Poset
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Ring.Properties
open import Cubical.Algebra.Ring.BigOps
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.BinomialThm
open import Cubical.Algebra.CommRing.Ideal
open import Cubical.Algebra.CommRing.FGIdeal
open import Cubical.Algebra.CommRing.RadicalIdeal
open import Cubical.Algebra.RingSolver.Reflection
open import Cubical.Algebra.Semilattice
open import Cubical.Algebra.Lattice
open import Cubical.Algebra.DistLattice
open import Cubical.Algebra.Matrix
open import Cubical.HITs.SetQuotients as SQ
open Iso
open BinaryRelation
open isEquivRel
private
variable
ℓ ℓ' : Level
module ZarLat (R' : CommRing ℓ) where
open CommRingStr (snd R')
open RingTheory (CommRing→Ring R')
open Sum (CommRing→Ring R')
open CommRingTheory R'
open Exponentiation R'
open BinomialThm R'
open CommIdeal R'
open RadicalIdeal R'
open isCommIdeal
open ProdFin R'
private
R = fst R'
A = Σ[ n ∈ ℕ ] (FinVec R n)
⟨_⟩ : {n : ℕ} → FinVec R n → CommIdeal
⟨ V ⟩ = ⟨ V ⟩[ R' ]
_∼_ : A → A → Type (ℓ-suc ℓ)
(_ , α) ∼ (_ , β) = √ ⟨ α ⟩ ≡ √ ⟨ β ⟩
∼EquivRel : isEquivRel (_∼_)
reflexive ∼EquivRel _ = refl
symmetric ∼EquivRel _ _ = sym
transitive ∼EquivRel _ _ _ = _∙_
ZL : Type (ℓ-suc ℓ)
ZL = A / _∼_
0z : ZL
0z = [ 0 , (λ ()) ]
1z : ZL
1z = [ 1 , (replicateFinVec 1 1r) ]
_∨z_ : ZL → ZL → ZL
_∨z_ = setQuotSymmBinOp (reflexive ∼EquivRel) (transitive ∼EquivRel)
(λ (_ , α) (_ , β) → (_ , α ++Fin β))
(λ (_ , α) (_ , β) → cong √ (FGIdealAddLemma _ α β ∙∙ +iComm _ _ ∙∙ sym (FGIdealAddLemma _ β α)))
λ (_ , α) (_ , β) (_ , γ) α∼β → --need to show α∨γ ∼ β∨γ
√ ⟨ α ++Fin γ ⟩ ≡⟨ cong √ (FGIdealAddLemma _ α γ) ⟩
√ (⟨ α ⟩ +i ⟨ γ ⟩) ≡⟨ sym (√+LContr _ _) ⟩
√ (√ ⟨ α ⟩ +i ⟨ γ ⟩) ≡⟨ cong (λ I → √ (I +i ⟨ γ ⟩)) α∼β ⟩
√ (√ ⟨ β ⟩ +i ⟨ γ ⟩) ≡⟨ √+LContr _ _ ⟩
√ (⟨ β ⟩ +i ⟨ γ ⟩) ≡⟨ cong √ (sym (FGIdealAddLemma _ β γ)) ⟩
√ ⟨ β ++Fin γ ⟩ ∎
_∧z_ : ZL → ZL → ZL
_∧z_ = setQuotSymmBinOp (reflexive ∼EquivRel) (transitive ∼EquivRel)
(λ (_ , α) (_ , β) → (_ , α ··Fin β))
(λ (_ , α) (_ , β) → cong √ (FGIdealMultLemma _ α β ∙∙ ·iComm _ _ ∙∙ sym (FGIdealMultLemma _ β α)))
λ (_ , α) (_ , β) (_ , γ) α∼β → --need to show α∧γ ∼ β∧γ
√ ⟨ α ··Fin γ ⟩ ≡⟨ cong √ (FGIdealMultLemma _ α γ) ⟩
√ (⟨ α ⟩ ·i ⟨ γ ⟩) ≡⟨ sym (√·LContr _ _) ⟩
√ (√ ⟨ α ⟩ ·i ⟨ γ ⟩) ≡⟨ cong (λ I → √ (I ·i ⟨ γ ⟩)) α∼β ⟩
√ (√ ⟨ β ⟩ ·i ⟨ γ ⟩) ≡⟨ √·LContr _ _ ⟩
√ (⟨ β ⟩ ·i ⟨ γ ⟩) ≡⟨ cong √ (sym (FGIdealMultLemma _ β γ)) ⟩
√ ⟨ β ··Fin γ ⟩ ∎
-- join axioms
∨zAssoc : ∀ (𝔞 𝔟 𝔠 : ZL) → 𝔞 ∨z (𝔟 ∨z 𝔠) ≡ (𝔞 ∨z 𝔟) ∨z 𝔠
∨zAssoc = SQ.elimProp3 (λ _ _ _ → squash/ _ _)
λ (_ , α) (_ , β) (_ , γ) → eq/ _ _ (cong √ (IdealAddAssoc _ _ _ _))
∨zComm : ∀ (𝔞 𝔟 : ZL) → 𝔞 ∨z 𝔟 ≡ 𝔟 ∨z 𝔞
∨zComm = SQ.elimProp2 (λ _ _ → squash/ _ _)
λ (_ , α) (_ , β) → eq/ _ _
(cong √ (FGIdealAddLemma _ α β ∙∙ +iComm _ _ ∙∙ sym (FGIdealAddLemma _ β α)))
∨zLid : ∀ (𝔞 : ZL) → 0z ∨z 𝔞 ≡ 𝔞
∨zLid = SQ.elimProp (λ _ → squash/ _ _) λ _ → eq/ _ _ refl
∨zRid : ∀ (𝔞 : ZL) → 𝔞 ∨z 0z ≡ 𝔞
∨zRid _ = ∨zComm _ _ ∙ ∨zLid _
-- -- meet axioms
∧zAssoc : ∀ (𝔞 𝔟 𝔠 : ZL) → 𝔞 ∧z (𝔟 ∧z 𝔠) ≡ (𝔞 ∧z 𝔟) ∧z 𝔠
∧zAssoc = SQ.elimProp3 (λ _ _ _ → squash/ _ _)
λ (_ , α) (_ , β) (_ , γ) → eq/ _ _
(√ ⟨ α ··Fin (β ··Fin γ) ⟩ ≡⟨ cong √ (FGIdealMultLemma _ _ _) ⟩
√ (⟨ α ⟩ ·i ⟨ β ··Fin γ ⟩) ≡⟨ cong (λ x → √ (⟨ α ⟩ ·i x)) (FGIdealMultLemma _ _ _) ⟩
√ (⟨ α ⟩ ·i (⟨ β ⟩ ·i ⟨ γ ⟩)) ≡⟨ cong √ (·iAssoc _ _ _) ⟩
√ ((⟨ α ⟩ ·i ⟨ β ⟩) ·i ⟨ γ ⟩) ≡⟨ cong (λ x → √ (x ·i ⟨ γ ⟩)) (sym (FGIdealMultLemma _ _ _)) ⟩
√ (⟨ α ··Fin β ⟩ ·i ⟨ γ ⟩) ≡⟨ cong √ (sym (FGIdealMultLemma _ _ _)) ⟩
√ ⟨ (α ··Fin β) ··Fin γ ⟩ ∎)
∧zComm : ∀ (𝔞 𝔟 : ZL) → 𝔞 ∧z 𝔟 ≡ 𝔟 ∧z 𝔞
∧zComm = SQ.elimProp2 (λ _ _ → squash/ _ _)
λ (_ , α) (_ , β) → eq/ _ _
(cong √ (FGIdealMultLemma _ α β ∙∙ ·iComm _ _ ∙∙ sym (FGIdealMultLemma _ β α)))
∧zRid : ∀ (𝔞 : ZL) → 𝔞 ∧z 1z ≡ 𝔞
∧zRid = SQ.elimProp (λ _ → squash/ _ _)
λ (_ , α) → eq/ _ _ (cong √
(⟨ α ··Fin (replicateFinVec 1 1r) ⟩ ≡⟨ FGIdealMultLemma _ _ _ ⟩
⟨ α ⟩ ·i ⟨ (replicateFinVec 1 1r) ⟩ ≡⟨ cong (⟨ α ⟩ ·i_) (contains1Is1 _ (indInIdeal _ _ zero)) ⟩
⟨ α ⟩ ·i 1Ideal ≡⟨ ·iRid _ ⟩
⟨ α ⟩ ∎))
-- absorption and distributivity
∧zAbsorb∨z : ∀ (𝔞 𝔟 : ZL) → 𝔞 ∧z (𝔞 ∨z 𝔟) ≡ 𝔞
∧zAbsorb∨z = SQ.elimProp2 (λ _ _ → squash/ _ _)
λ (_ , α) (_ , β) → eq/ _ _
(√ ⟨ α ··Fin (α ++Fin β) ⟩ ≡⟨ cong √ (FGIdealMultLemma _ α (α ++Fin β)) ⟩
√ (⟨ α ⟩ ·i ⟨ α ++Fin β ⟩) ≡⟨ cong (λ x → √ (⟨ α ⟩ ·i x)) (FGIdealAddLemma _ α β) ⟩
√ (⟨ α ⟩ ·i (⟨ α ⟩ +i ⟨ β ⟩)) ≡⟨ √·Absorb+ _ _ ⟩
√ ⟨ α ⟩ ∎)
∧zLDist∨z : ∀ (𝔞 𝔟 𝔠 : ZL) → 𝔞 ∧z (𝔟 ∨z 𝔠) ≡ (𝔞 ∧z 𝔟) ∨z (𝔞 ∧z 𝔠)
∧zLDist∨z = SQ.elimProp3 (λ _ _ _ → squash/ _ _)
λ (_ , α) (_ , β) (_ , γ) → eq/ _ _
(√ ⟨ α ··Fin (β ++Fin γ) ⟩ ≡⟨ cong √ (FGIdealMultLemma _ _ _) ⟩
√ (⟨ α ⟩ ·i ⟨ β ++Fin γ ⟩) ≡⟨ cong (λ x → √ (⟨ α ⟩ ·i x)) (FGIdealAddLemma _ _ _) ⟩
√ (⟨ α ⟩ ·i (⟨ β ⟩ +i ⟨ γ ⟩)) ≡⟨ cong √ (·iRdist+i _ _ _) ⟩
-- L/R-dist are swapped
-- in Lattices vs Rings
√ (⟨ α ⟩ ·i ⟨ β ⟩ +i ⟨ α ⟩ ·i ⟨ γ ⟩) ≡⟨ cong₂ (λ x y → √ (x +i y))
(sym (FGIdealMultLemma _ _ _))
(sym (FGIdealMultLemma _ _ _)) ⟩
√ (⟨ α ··Fin β ⟩ +i ⟨ α ··Fin γ ⟩) ≡⟨ cong √ (sym (FGIdealAddLemma _ _ _)) ⟩
√ ⟨ (α ··Fin β) ++Fin (α ··Fin γ) ⟩ ∎)
ZariskiLattice : DistLattice (ℓ-suc ℓ)
fst ZariskiLattice = ZL
DistLatticeStr.0l (snd ZariskiLattice) = 0z
DistLatticeStr.1l (snd ZariskiLattice) = 1z
DistLatticeStr._∨l_ (snd ZariskiLattice) = _∨z_
DistLatticeStr._∧l_ (snd ZariskiLattice) = _∧z_
DistLatticeStr.isDistLattice (snd ZariskiLattice) =
makeIsDistLattice∧lOver∨l squash/ ∨zAssoc ∨zRid ∨zComm
∧zAssoc ∧zRid ∧zComm ∧zAbsorb∨z ∧zLDist∨z
-- An equivalent definition that doesn't bump up the unviverse level
module SmallZarLat (R' : CommRing ℓ) where
open CommRingStr (snd R')
open CommIdeal R'
open RadicalIdeal R'
open ZarLat R'
open Iso
private
R = fst R'
A = Σ[ n ∈ ℕ ] (FinVec R n)
⟨_⟩ : {n : ℕ} → FinVec R n → CommIdeal
⟨ V ⟩ = ⟨ V ⟩[ R' ]
-- This is small!
_≼_ : A → A → Type ℓ
(_ , α) ≼ (_ , β) = ∀ i → α i ∈ √ ⟨ β ⟩
_∼'_ : A → A → Type ℓ
α ∼' β = (α ≼ β) × (β ≼ α)
-- lives in the same universe as R
ZL' : Type ℓ
ZL' = A / (_∼'_)
IsoLarLatSmall : Iso ZL ZL'
IsoLarLatSmall = relBiimpl→TruncIso ~→∼' ~'→∼
where
~→∼' : ∀ {a b : A} → a ∼ b → a ∼' b
~→∼' r = √FGIdealCharLImpl _ ⟨ _ ⟩ (λ x h → subst (λ p → x ∈ p) r h)
, √FGIdealCharLImpl _ ⟨ _ ⟩ (λ x h → subst (λ p → x ∈ p) (sym r) h)
~'→∼ : ∀ {a b : A} → a ∼' b → a ∼ b
~'→∼ r = CommIdeal≡Char (√FGIdealCharRImpl _ ⟨ _ ⟩ (fst r))
(√FGIdealCharRImpl _ ⟨ _ ⟩ (snd r))
ZL≃ZL' : ZL ≃ ZL'
ZL≃ZL' = isoToEquiv IsoLarLatSmall
| 36.110132
| 102
| 0.518482
|
1b70a3a797e8affb007b27e2e3c37106740ed8f0
| 2,189
|
agda
|
Agda
|
src/Implicits/Semantics/Preservation.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | 4
|
2019-04-05T17:57:11.000Z
|
2021-05-07T04:08:41.000Z
|
src/Implicits/Semantics/Preservation.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
src/Implicits/Semantics/Preservation.agda
|
metaborg/ts.agda
|
7fe638b87de26df47b6437f5ab0a8b955384958d
|
[
"MIT"
] | null | null | null |
open import Prelude
module Implicits.Semantics.Preservation where
open import Implicits.Syntax
open import Implicits.WellTyped
open import Implicits.Semantics.Type
open import Implicits.Semantics.Context
open import Implicits.Semantics.Lemmas
open import Implicits.Semantics.RewriteContext
open import Implicits.Semantics.Term
open import SystemF.Everything as F using ()
module Preservation
(_⊢ᵣ_ : ∀ {ν} → 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
-- interpretation of well-typed terms in System F preserves type
⟦⟧-preserves-tp : ∀ {ν n} {K : Ktx ν n} {t a} → (wt-t : K ⊢ t ∈ a) → (m : K# K) →
⟦ proj₁ K ⟧ctx→ F.⊢ ⟦ wt-t , m ⟧ ∈ ⟦ a ⟧tp→
⟦⟧-preserves-tp {K = K} (var x) m = subst-wt-var (sym $ lookup-⟦⟧ctx→ (proj₁ K) x) (F.var x)
where
subst-wt-var = subst (λ a → ⟦ proj₁ K ⟧ctx→ F.⊢ (F.var x) ∈ a)
⟦⟧-preserves-tp {K = K} {a = ∀' a} (Λ wt-e) m with ⟦⟧-preserves-tp wt-e (#tvar m)
... | ih = F.Λ (subst-wt-ctx (⟦weaken⟧ctx→ (proj₁ K)) ih)
where
subst-wt-ctx = subst (λ c → c F.⊢ ⟦ wt-e , #tvar m ⟧ ∈ ⟦ a ⟧tp→)
⟦⟧-preserves-tp (λ' a wt-e) m with ⟦⟧-preserves-tp wt-e (#var a m)
⟦⟧-preserves-tp (λ' a wt-e) m | ih = F.λ' ⟦ a ⟧tp→ ih
⟦⟧-preserves-tp {K = K} (_[_] {a = a} wt-tc b) m with ⟦⟧-preserves-tp wt-tc m
... | ih = subst-tp (sym $ ⟦a/sub⟧tp→ a b) (ih F.[ ⟦ b ⟧tp→ ])
where
subst-tp = subst (λ c → ⟦ proj₁ K ⟧ctx→ F.⊢ ⟦ wt-tc [ b ] , m ⟧ ∈ c)
⟦⟧-preserves-tp (wt-f · wt-e) m with ⟦⟧-preserves-tp wt-f m | ⟦⟧-preserves-tp wt-e m
⟦⟧-preserves-tp (wt-f · wt-e) m | ih | y = ih F.· y
⟦⟧-preserves-tp (ρ {a = a} unamb-a wt-e) m with ⟦⟧-preserves-tp wt-e (#ivar a m)
⟦⟧-preserves-tp (ρ {a = a} unamb-a wt-e) m | ih = F.λ' ⟦ a ⟧tp→ ih
⟦⟧-preserves-tp (wt-r ⟨ e ⟩) m with ⟦⟧-preserves-tp wt-r m
⟦⟧-preserves-tp (wt-r ⟨ e ⟩) m | f-wt-r = f-wt-r F.· (proj₂ ⟦ e , m ⟧r)
⟦⟧-preserves-tp (wt-r with' wt-e ) m with ⟦⟧-preserves-tp wt-r m | ⟦⟧-preserves-tp wt-e m
⟦⟧-preserves-tp (wt-r with' wt-e ) m | f-wt-r | f-wt-e = f-wt-r F.· f-wt-e
| 46.574468
| 94
| 0.5619
|
1b42f2ffc35b424d03f6fa9dcba1385aec228af6
| 776
|
agda
|
Agda
|
Data/List/Sorting.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Data/List/Sorting.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Data/List/Sorting.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
import Lvl
open import Data.Boolean
open import Type
module Data.List.Sorting {ℓ} {T : Type{ℓ}} (_≤?_ : T → T → Bool) where
open import Functional using (_∘₂_)
open import Data.Boolean.Stmt
open import Data.List
import Data.List.Relation.Pairwise
open import Data.List.Relation.Permutation
open import Logic
open Data.List.Relation.Pairwise using (empty ; single ; step) public
Sorted = Data.List.Relation.Pairwise.AdjacentlyPairwise(IsTrue ∘₂ (_≤?_))
-- A sorting algorithm is a function that given a list, always return a sorted list which is a permutation of the original one.
record SortingAlgorithm (f : List(T) → List(T)) : Stmt{Lvl.𝐒(ℓ)} where
constructor intro
field
⦃ sorts ⦄ : ∀{l} → Sorted(f(l))
⦃ permutes ⦄ : ∀{l} → (f(l) permutes l)
| 33.73913
| 127
| 0.710052
|
1920a976046f38384f8624000f8128bea678d205
| 299
|
agda
|
Agda
|
test/Fail/Issue636.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue636.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue636.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2012-05-14, issue reported by Nisse
-- {-# OPTIONS -v term:20 #-}
{-# OPTIONS --guardedness #-}
module Issue636 where
open import Common.Coinduction
data ⊥ : Set where
data D : Set where
c : ∞ D → D
d : D
d = c (♯ d)
not-d : D → ⊥
not-d (c x) = not-d (♭ x)
bad : ⊥
bad = not-d d
| 14.238095
| 47
| 0.578595
|
34beefd68a464bbe99fdee6835315735066cd336
| 5,050
|
agda
|
Agda
|
examples/Introduction/Built-in.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/Introduction/Built-in.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/Introduction/Built-in.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- This module introduces built-in types and primitive functions.
module Introduction.Built-in where
{- Agda supports four built-in types :
- integers,
- floating point numbers,
- characters, and
- strings.
Note that strings are not defined as lists of characters (as is the case in
Haskell).
To use the built-in types they first have to be bound to Agda types. The
reason for this is that there are no predefined names in Agda.
-}
-- To be able to use the built-in types we first introduce a new set for each
-- built-in type.
postulate
Int : Set
Float : Set
Char : Set
String : Set
-- We can then bind the built-in types to these new sets using the BUILTIN
-- pragma.
{-# BUILTIN INTEGER Int #-}
{-# BUILTIN FLOAT Float #-}
{-# BUILTIN CHAR Char #-}
{-# BUILTIN STRING String #-}
pi : Float
pi = 3.141593
forAll : Char
forAll = '∀'
hello : String
hello = "Hello World!"
-- There are no integer literals. Instead there are natural number literals. To
-- use these you have to tell the type checker which type to use for natural
-- numbers.
data Nat : Set where
zero : Nat
suc : Nat -> Nat
{-# BUILTIN NATURAL Nat #-}
-- Now we can define
fortyTwo : Nat
fortyTwo = 42
-- To anything interesting with values of the built-in types we need functions
-- to manipulate them. To this end Agda provides a set of primitive functions.
-- To gain access to a primitive function one simply declares it. For instance,
-- the function for floating point addition is called primFloatPlus. See below
-- for a complete list of primitive functions. At the moment the name that you
-- bring into scope is always the name of the primitive function. In the future
-- we might allow a primitive function to be introduced with any name.
module FloatPlus where -- We put it in a module to prevent it from clashing with
-- the plus function in the complete list of primitive
-- functions below.
primitive
primFloatPlus : Float -> Float -> Float
twoPi = primFloatPlus pi pi
-- Some primitive functions returns elements of non-primitive types. For
-- instance, the integer comparison functions return booleans. To be able to
-- use these functions we have to explain which type to use for booleans.
data Bool : Set where
false : Bool
true : Bool
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE true #-}
{-# BUILTIN FALSE false #-}
module FloatLess where
primitive
primFloatLess : Float -> Float -> Bool
-- There are functions to convert a string to a list of characters, so we need
-- to say which list type to use.
data List (A : Set) : Set where
nil : List A
_::_ : A -> List A -> List A
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL nil #-}
{-# BUILTIN CONS _::_ #-}
module StringToList where
primitive
primStringToList : String -> List Char
-- Below is a partial version of the complete list of primitive
-- functions.
primitive
-- Integer functions
primIntegerPlus : Int -> Int -> Int
primIntegerMinus : Int -> Int -> Int
primIntegerTimes : Int -> Int -> Int
primIntegerDiv : Int -> Int -> Int -- partial
primIntegerMod : Int -> Int -> Int -- partial
primIntegerEquality : Int -> Int -> Bool
primIntegerLess : Int -> Int -> Bool
primIntegerAbs : Int -> Nat
primNatToInteger : Nat -> Int
primShowInteger : Int -> String
-- Floating point functions
primIntegerToFloat : Int -> Float
primFloatPlus : Float -> Float -> Float
primFloatMinus : Float -> Float -> Float
primFloatTimes : Float -> Float -> Float
primFloatNegate : Float -> Float
primFloatDiv : Float -> Float -> Float
primFloatLess : Float -> Float -> Bool
primRound : Float -> Int
primFloor : Float -> Int
primCeiling : Float -> Int
primExp : Float -> Float
primLog : Float -> Float -- partial
primSin : Float -> Float
primCos : Float -> Float
primTan : Float -> Float
primASin : Float -> Float
primACos : Float -> Float
primATan : Float -> Float
primATan2 : Float -> Float -> Float
primShowFloat : Float -> String
-- Character functions
primCharEquality : Char -> Char -> Bool
primIsLower : Char -> Bool
primIsDigit : Char -> Bool
primIsAlpha : Char -> Bool
primIsSpace : Char -> Bool
primIsAscii : Char -> Bool
primIsLatin1 : Char -> Bool
primIsPrint : Char -> Bool
primIsHexDigit : Char -> Bool
primToUpper : Char -> Char
primToLower : Char -> Char
primCharToNat : Char -> Nat
primNatToChar : Nat -> Char -- partial
primShowChar : Char -> String
-- String functions
primStringToList : String -> List Char
primStringFromList : List Char -> String
primStringAppend : String -> String -> String
primStringEquality : String -> String -> Bool
primShowString : String -> String
| 30.059524
| 81
| 0.646733
|
d11eb8b81cf384ae34c64b65f925297ed90da28a
| 276
|
agda
|
Agda
|
Data/PolyP.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 6
|
2020-09-11T17:45:41.000Z
|
2021-11-16T08:11:34.000Z
|
Data/PolyP.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | null | null | null |
Data/PolyP.agda
|
oisdk/agda-playground
|
97a3aab1282b2337c5f43e2cfa3fa969a94c11b7
|
[
"MIT"
] | 1
|
2021-11-11T12:30:21.000Z
|
2021-11-11T12:30:21.000Z
|
{-# OPTIONS --cubical --safe --guardedness #-}
module Data.PolyP where
open import Data.PolyP.RecursionSchemes public
open import Data.PolyP.Universe public
open import Data.PolyP.Composition public
open import Data.PolyP.Types public
open import Data.PolyP.Currying public
| 27.6
| 46
| 0.804348
|
348f81f7d54ac78d44738797cee4768415b9644c
| 877
|
agda
|
Agda
|
src/CategoryTheory/BCCCs.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | 4
|
2018-05-31T20:37:04.000Z
|
2022-01-04T09:33:48.000Z
|
src/CategoryTheory/BCCCs.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | null | null | null |
src/CategoryTheory/BCCCs.agda
|
DimaSamoz/temporal-type-systems
|
7d993ba55e502d5ef8707ca216519012121a08dd
|
[
"MIT"
] | null | null | null |
-- Module for BCCs, CCCs and BCCCs
module CategoryTheory.BCCCs where
open import CategoryTheory.Categories
open import CategoryTheory.BCCCs.Cartesian public
open import CategoryTheory.BCCCs.Cocartesian public
open import CategoryTheory.BCCCs.Closed public
-- Bicartesian categories
record Bicartesian {n} (ℂ : Category n) : Set (lsuc n) where
field
cart : Cartesian ℂ
cocart : Cocartesian ℂ
-- Cartesian closed categories
record CartesianClosed {n} (ℂ : Category n) : Set (lsuc n) where
field
cart : Cartesian ℂ
closed : Closed cart
-- Bicartesian closed categories
record BicartesianClosed {n} (ℂ : Category n) : Set (lsuc n) where
field
cart : Cartesian ℂ
cocart : Cocartesian ℂ
closed : Closed cart
open Cartesian cart public
open Cocartesian cocart public
open Closed closed public
| 28.290323
| 66
| 0.710376
|
0da564c633f7b7288f6456a3926a86958081b620
| 2,110
|
agda
|
Agda
|
Cubical/HITs/GroupoidTruncation/Properties.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | null | null | null |
Cubical/HITs/GroupoidTruncation/Properties.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | null | null | null |
Cubical/HITs/GroupoidTruncation/Properties.agda
|
maxdore/cubical
|
ef62b84397396d48135d73ba7400b71c721ddc94
|
[
"MIT"
] | 1
|
2021-03-12T20:08:45.000Z
|
2021-03-12T20:08:45.000Z
|
{-
This file contains:
- Properties of groupoid truncations
-}
{-# OPTIONS --safe #-}
module Cubical.HITs.GroupoidTruncation.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.HITs.GroupoidTruncation.Base
private
variable
ℓ : Level
A : Type ℓ
rec : ∀ {B : Type ℓ} → isGroupoid B → (A → B) → ∥ A ∥₃ → B
rec gB f ∣ x ∣₃ = f x
rec gB f (squash₃ x y p q r s i j k) =
gB _ _ _ _ (λ m n → rec gB f (r m n)) (λ m n → rec gB f (s m n)) i j k
elim : {B : ∥ A ∥₃ → Type ℓ}
(bG : (x : ∥ A ∥₃) → isGroupoid (B x))
(f : (x : A) → B ∣ x ∣₃) (x : ∥ A ∥₃) → B x
elim bG f (∣ x ∣₃) = f x
elim bG f (squash₃ x y p q r s i j k) =
isOfHLevel→isOfHLevelDep 3 bG _ _ _ _
(λ j k → elim bG f (r j k)) (λ j k → elim bG f (s j k))
(squash₃ x y p q r s)
i j k
elim2 : {B : ∥ A ∥₃ → ∥ A ∥₃ → Type ℓ}
(gB : ((x y : ∥ A ∥₃) → isGroupoid (B x y)))
(g : (a b : A) → B ∣ a ∣₃ ∣ b ∣₃)
(x y : ∥ A ∥₃) → B x y
elim2 gB g = elim (λ _ → isGroupoidΠ (λ _ → gB _ _))
(λ a → elim (λ _ → gB _ _) (g a))
elim3 : {B : (x y z : ∥ A ∥₃) → Type ℓ}
(gB : ((x y z : ∥ A ∥₃) → isGroupoid (B x y z)))
(g : (a b c : A) → B ∣ a ∣₃ ∣ b ∣₃ ∣ c ∣₃)
(x y z : ∥ A ∥₃) → B x y z
elim3 gB g = elim2 (λ _ _ → isGroupoidΠ (λ _ → gB _ _ _))
(λ a b → elim (λ _ → gB _ _ _) (g a b))
groupoidTruncIsGroupoid : isGroupoid ∥ A ∥₃
groupoidTruncIsGroupoid a b p q r s = squash₃ a b p q r s
groupoidTruncIdempotent≃ : isGroupoid A → ∥ A ∥₃ ≃ A
groupoidTruncIdempotent≃ {A = A} hA = isoToEquiv f
where
f : Iso ∥ A ∥₃ A
Iso.fun f = rec hA (idfun A)
Iso.inv f x = ∣ x ∣₃
Iso.rightInv f _ = refl
Iso.leftInv f = elim (λ _ → isGroupoid→is2Groupoid groupoidTruncIsGroupoid _ _) (λ _ → refl)
groupoidTruncIdempotent : isGroupoid A → ∥ A ∥₃ ≡ A
groupoidTruncIdempotent hA = ua (groupoidTruncIdempotent≃ hA)
| 31.029412
| 94
| 0.569194
|
7cfd524e637cb54ec2f0075791766b70b5a632f5
| 923
|
agda
|
Agda
|
test/Succeed/EtaInductiveRecord.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/EtaInductiveRecord.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/EtaInductiveRecord.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- 2014-02-08 Andreas
-- Eta-equality for records that are recursive via some data type
-- {-# OPTIONS -v tc.pos.record:10 #-}
module _ where
open import Common.Equality
module Nested where
data List (A : Set) : Set where
[] : List A
_∷_ : (x : A)(xs : List A) → List A
record Tree (A : Set) : Set where
inductive
constructor tree
field
elem : A
subtrees : List (Tree A)
open Tree
test : ∀ {A} (t : Tree A) → t ≡ tree (elem t) (subtrees t)
test t = refl
-- we should have eta for Tree!
module Mutual where
mutual
data TreeList (A : Set) : Set where
[] : TreeList A
_∷_ : (x : Tree A)(xs : TreeList A) → TreeList A
record Tree (A : Set) : Set where
inductive
constructor tree
field
elem : A
subtrees : TreeList A
open Tree
test : ∀ {A} (t : Tree A) → t ≡ tree (elem t) (subtrees t)
test t = refl
| 20.065217
| 65
| 0.572048
|
346bdc0ed962f3f6f891116411ec811d770ffff1
| 3,182
|
agda
|
Agda
|
agda/SN.agda
|
ryanakca/strong-normalization
|
79d97481f3312c2d30a823c3b1bcb8ae871c2fe2
|
[
"Unlicense"
] | 32
|
2017-05-22T14:33:27.000Z
|
2021-03-05T12:12:03.000Z
|
agda/SN.agda
|
ryanakca/strong-normalization
|
79d97481f3312c2d30a823c3b1bcb8ae871c2fe2
|
[
"Unlicense"
] | 2
|
2018-02-14T16:42:36.000Z
|
2018-02-20T14:54:18.000Z
|
agda/SN.agda
|
ryanakca/strong-normalization
|
79d97481f3312c2d30a823c3b1bcb8ae871c2fe2
|
[
"Unlicense"
] | 4
|
2017-11-10T16:44:52.000Z
|
2018-02-23T18:22:17.000Z
|
module SN where
open import Library
open import Syntax
open import RenamingAndSubstitution
-- Reduction
data _↦_ {Γ} : ∀{a} (t t' : Tm Γ a) → Set where
β : ∀{a b} {t : Tm (Γ , a) b} {u} → app (abs t) u ↦ sub0 t u
abs : ∀{a b} {t t' : Tm (Γ , a) b} (r : t ↦ t') → abs t ↦ abs t'
appl : ∀{a b} {t t' : Tm Γ (a ⇒ b)} {u} (r : t ↦ t') → app t u ↦ app t' u
appr : ∀{a b} {t : Tm Γ (a ⇒ b)} {u u'} (r : u ↦ u') → app t u ↦ app t u'
ren↦ : ∀{Γ Δ a} (ρ : Ren Γ Δ) {t t' : Tm Δ a} (r : t ↦ t') → ren ρ t ↦ ren ρ t'
-- ren↦ {Γ} {Δ} {a} ρ {t} {t'} r = {!r!}
ren↦ {Γ} {Δ} ρ β = {!!}
ren↦ {Γ} {Δ} ρ (abs r) = abs (ren↦ (liftr ρ) r)
ren↦ {Γ} {Δ} ρ (appl r) = {!!}
ren↦ {Γ} {Δ} ρ (appr r) = {!!}
ren↦inv : ∀{Γ Δ a} (ρ : Ren Γ Δ) (t : Tm Δ a) {t' : Tm Γ a} (r : ren ρ t ↦ t') →
∃ λ (u : Tm Δ a) → (t ↦ u) × (t' ≡ ren ρ u)
ren↦inv ρ (var x) ()
ren↦inv ρ (app (abs t) t₁) β = sub0 t t₁ , β , {!refl!}
ren↦inv ρ (abs t) (abs r) with ren↦inv (liftr ρ) t r
ren↦inv ρ (abs t) (abs r) | u , r' , e = abs u , abs r' , cong abs e
ren↦inv ρ (app t t₁) (appl r) with ren↦inv ρ t r
ren↦inv ρ (app t t₁) (appl r) | u , r' , refl = app u t₁ , appl r' , refl
ren↦inv ρ (app t t₁) (appr r) with ren↦inv ρ t₁ r
... | u , r' , refl = app t u , appr r' , refl
-- Strongly normalizing terms
data SN {Γ : Cxt} {a : Ty} (t : Tm Γ a) : Set where
sn : (∀ t' (r : t ↦ t') → SN t') → SN t
-- SN is closed under renaming
renSN : ∀{Γ Δ a} (ρ : Ren Γ Δ) {t : Tm Δ a} (s : SN t) → SN (ren ρ t)
renSN ρ (sn f) = sn λ _ r → case ren↦inv ρ _ r of
λ{ (t'' , r' , refl) → renSN ρ (f t'' r') }
-- Strong head reduction (weak head reduction that preserves SN under expansion)
data _s↦_ {Γ} : ∀{a} (t t' : Tm Γ a) → Set where
β : ∀{a b} {t : Tm (Γ , a) b} {u} (s : SN u) → app (abs t) u s↦ sub0 t u
appl : ∀{a b} {t t' : Tm Γ (a ⇒ b)} {u} (r : t s↦ t') → app t u s↦ app t' u
-- Strong head reduction is closed under renaming
rens↦ : ∀{Γ Δ a} (ρ : Ren Γ Δ) {t t' : Tm Δ a} (r : t s↦ t') → ren ρ t s↦ ren ρ t'
rens↦ ρ (β s) = {!β!}
-- Need lemma:
-- app (abs (ren (liftr ρ) .t)) (ren ρ .u) s↦
-- ren ρ (sub (subId , .u) .t)rens↦ ρ (appl r) = appl (rens↦ ρ r)
-- SN is closed under strong head expansion
s↦SN : ∀{Γ a}{t t' : Tm Γ a} (r : t s↦ t') (s : SN t') → SN t
-- s↦SN r s = sn λ t' → λ{ β → {!!} ; (abs r') → {!!} ; (appl r') → {!!} ; (appr r') → {!!}}
s↦SN (β s') s = sn (λ t' → λ{ β → s ; (appl (abs r)) → {!!} ; (appr r) → {!!}})
s↦SN (appl r) s = {!!}
-- Reducibility: Kripke logical predicate
Red : (a : Ty) {Γ : Cxt} (t : Tm Γ a) → Set
Red ★ {Γ} t = SN t
Red (a ⇒ b) {Γ} t = ∀{Γ'}(ρ : Ren Γ' Γ) u (s : Red a u) → Red b (app (ren ρ t) u)
-- Reducibility is closed under renaming
renRed : ∀{Γ Δ a} (ρ : Ren Γ Δ) {t : Tm Δ a} (p : Red a t) → Red a (ren ρ t)
renRed {Γ} {Δ} {★} ρ {t} p = renSN ρ p
renRed {Γ} {Δ} {a ⇒ b} ρ {t} p = λ ρ₁ u s →
subst (λ z → Red b (app z u)) (rencomp ρ₁ ρ t)
(p (renComp ρ₁ ρ) u s)
-- Reducibility is closed under strong head expansion
expRed : ∀{Γ a} {t t' : Tm Γ a} (r : t s↦ t') (p : Red a t') → Red a t
expRed {Γ} {★} {t} {t'} r p = s↦SN r p
expRed {Γ} {a ⇒ b} {t} {t'} r p ρ u s = expRed (appl {!!}) (p ρ u s)
| 37.880952
| 92
| 0.473287
|
1e38ac793e13e75cccf39948c8779d4b518e1e5e
| 357
|
agda
|
Agda
|
test/Succeed/Issue1552.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1552.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1552.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --rewriting --confluence-check #-}
-- {-# OPTIONS -v rewriting:100 #-}
postulate
_↦_ : ∀ {i} {A : Set i} → A → A → Set i
{-# BUILTIN REWRITE _↦_ #-}
postulate
Unit : Set
tt : Unit
module _ {i} (P : Unit → Set i) (tt* : P tt) where
postulate
Unit-elim : (x : Unit) → P x
Unit-β : Unit-elim tt ↦ tt*
{-# REWRITE Unit-β #-}
| 17.85
| 50
| 0.537815
|
3068da93d10bacba9fe4bcf79b488018e4f890ae
| 1,013
|
agda
|
Agda
|
agda/InsertSort/Impl1/Correctness/Order.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | 6
|
2015-05-21T12:50:35.000Z
|
2021-08-24T22:11:15.000Z
|
agda/InsertSort/Impl1/Correctness/Order.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
agda/InsertSort/Impl1/Correctness/Order.agda
|
bgbianchi/sorting
|
b8d428bccbdd1b13613e8f6ead6c81a8f9298399
|
[
"MIT"
] | null | null | null |
open import Relation.Binary.Core
module InsertSort.Impl1.Correctness.Order {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import Data.List
open import Data.Sum
open import InsertSort.Impl1 _≤_ tot≤
open import List.Sorted _≤_
lemma-insert-sorted : {xs : List A}(x : A) → Sorted xs → Sorted (insert x xs)
lemma-insert-sorted {xs = .[]} x nils = singls x
lemma-insert-sorted {xs = .([ y ])} x (singls y)
with tot≤ x y
... | inj₁ x≤y = conss x≤y (singls y)
... | inj₂ y≤x = conss y≤x (singls x)
lemma-insert-sorted x (conss {y} {z} {ys} y≤z szys)
with tot≤ x y
... | inj₁ x≤y = conss x≤y (conss y≤z szys)
... | inj₂ y≤x
with tot≤ x z | lemma-insert-sorted x szys
... | inj₁ x≤z | _ = conss y≤x (conss x≤z szys)
... | inj₂ z≤x | h = conss y≤z h
theorem-insertSort-sorted : (xs : List A) → Sorted (insertSort xs)
theorem-insertSort-sorted [] = nils
theorem-insertSort-sorted (x ∷ xs) = lemma-insert-sorted x (theorem-insertSort-sorted xs)
| 32.677419
| 90
| 0.614018
|
374cba69cd7865a07d8118f9a2294b09084d61ab
| 14,693
|
agda
|
Agda
|
src/STLC/Coquand/Substitution.agda
|
mietek/coquand-kovacs
|
bd626509948fbf8503ec2e31c1852e1ac6edcc79
|
[
"X11"
] | null | null | null |
src/STLC/Coquand/Substitution.agda
|
mietek/coquand-kovacs
|
bd626509948fbf8503ec2e31c1852e1ac6edcc79
|
[
"X11"
] | null | null | null |
src/STLC/Coquand/Substitution.agda
|
mietek/coquand-kovacs
|
bd626509948fbf8503ec2e31c1852e1ac6edcc79
|
[
"X11"
] | null | null | null |
module STLC.Coquand.Substitution where
open import STLC.Coquand.Renaming public
open import Category
--------------------------------------------------------------------------------
-- Substitutions
infix 3 _⊢⋆_
data _⊢⋆_ : 𝒞 → 𝒞 → Set
where
∅ : ∀ {Γ} → Γ ⊢⋆ ∅
_,_ : ∀ {Γ Ξ A} → (σ : Γ ⊢⋆ Ξ) (M : Γ ⊢ A)
→ Γ ⊢⋆ Ξ , A
putₛ : ∀ {Ξ Γ} → (∀ {A} → Ξ ⊢ A → Γ ⊢ A) → Γ ⊢⋆ Ξ
putₛ {∅} f = ∅
putₛ {Γ , A} f = putₛ (λ M → f (wk M)) , f 0
getₛ : ∀ {Γ Ξ A} → Γ ⊢⋆ Ξ → Ξ ∋ A → Γ ⊢ A
getₛ (σ , M) zero = M
getₛ (σ , M) (suc i) = getₛ σ i
wkₛ : ∀ {A Γ Ξ} → Γ ⊢⋆ Ξ → Γ , A ⊢⋆ Ξ
wkₛ ∅ = ∅
wkₛ (σ , M) = wkₛ σ , wk M
liftₛ : ∀ {A Γ Ξ} → Γ ⊢⋆ Ξ → Γ , A ⊢⋆ Ξ , A
liftₛ σ = wkₛ σ , 0
idₛ : ∀ {Γ} → Γ ⊢⋆ Γ
idₛ {∅} = ∅
idₛ {Γ , A} = liftₛ idₛ
sub : ∀ {Γ Ξ A} → Γ ⊢⋆ Ξ → Ξ ⊢ A → Γ ⊢ A
sub σ (𝓋 i) = getₛ σ i
sub σ (ƛ M) = ƛ (sub (liftₛ σ) M)
sub σ (M ∙ N) = sub σ M ∙ sub σ N
cut : ∀ {Γ A B} → Γ ⊢ A → Γ , A ⊢ B → Γ ⊢ B
cut M N = sub (idₛ , M) N
-- NOTE: _●_ = sub⋆
_●_ : ∀ {Γ Ξ Φ} → Γ ⊢⋆ Ξ → Ξ ⊢⋆ Φ → Γ ⊢⋆ Φ
σ₁ ● ∅ = ∅
σ₁ ● (σ₂ , M) = σ₁ ● σ₂ , sub σ₁ M
--------------------------------------------------------------------------------
-- (wkgetₛ)
natgetₛ : ∀ {Γ Ξ A B} → (σ : Γ ⊢⋆ Ξ) (i : Ξ ∋ A)
→ getₛ (wkₛ {B} σ) i ≡ (wk ∘ getₛ σ) i
natgetₛ (σ , M) zero = refl
natgetₛ (σ , M) (suc i) = natgetₛ σ i
idgetₛ : ∀ {Γ A} → (i : Γ ∋ A)
→ getₛ idₛ i ≡ 𝓋 i
idgetₛ zero = refl
idgetₛ (suc i) = natgetₛ idₛ i
⦙ wk & idgetₛ i
⦙ 𝓋 & ( natgetᵣ idᵣ i
⦙ suc & idgetᵣ i
)
idsub : ∀ {Γ A} → (M : Γ ⊢ A)
→ sub idₛ M ≡ M
idsub (𝓋 i) = idgetₛ i
idsub (ƛ M) = ƛ & idsub M
idsub (M ∙ N) = _∙_ & idsub M
⊗ idsub N
--------------------------------------------------------------------------------
⌊_⌋ : ∀ {Γ Γ′} → Γ′ ∋⋆ Γ → Γ′ ⊢⋆ Γ
⌊ ∅ ⌋ = ∅
⌊ η , i ⌋ = ⌊ η ⌋ , 𝓋 i
-- NOTE: _◐_ = getₛ⋆
_◐_ : ∀ {Γ Ξ Ξ′} → Γ ⊢⋆ Ξ′ → Ξ′ ∋⋆ Ξ → Γ ⊢⋆ Ξ
σ ◐ η = σ ● ⌊ η ⌋
-- NOTE: _◑_ = ren⋆
_◑_ : ∀ {Γ Γ′ Ξ} → Γ′ ∋⋆ Γ → Γ ⊢⋆ Ξ → Γ′ ⊢⋆ Ξ
η ◑ σ = ⌊ η ⌋ ● σ
⌊get⌋ : ∀ {Γ Γ′ A} → (η : Γ′ ∋⋆ Γ) (i : Γ ∋ A)
→ getₛ ⌊ η ⌋ i ≡ 𝓋 (getᵣ η i)
⌊get⌋ (η , j) zero = refl
⌊get⌋ (η , j) (suc i) = ⌊get⌋ η i
⌊wk⌋ : ∀ {Γ Γ′ A} → (η : Γ′ ∋⋆ Γ)
→ wkₛ {A} ⌊ η ⌋ ≡ ⌊ wkᵣ η ⌋
⌊wk⌋ ∅ = refl
⌊wk⌋ (η , i) = (wkₛ ⌊ η ⌋ ,_) & (𝓋 & natgetᵣ idᵣ i)
⦙ _,_ & ⌊wk⌋ η
⊗ 𝓋 ∘ suc & idgetᵣ i
⌊lift⌋ : ∀ {Γ Γ′ A} → (η : Γ′ ∋⋆ Γ)
→ liftₛ {A} ⌊ η ⌋ ≡ ⌊ liftᵣ η ⌋
⌊lift⌋ η = (_, 0) & ⌊wk⌋ η
⌊id⌋ : ∀ {Γ} → idₛ {Γ} ≡ ⌊ idᵣ ⌋
⌊id⌋ {∅} = refl
⌊id⌋ {Γ , A} = (_, 0) & ( wkₛ & ⌊id⌋
⦙ ⌊wk⌋ idᵣ
)
⌊sub⌋ : ∀ {Γ Γ′ A} → (η : Γ′ ∋⋆ Γ) (M : Γ ⊢ A)
→ sub ⌊ η ⌋ M ≡ ren η M
⌊sub⌋ η (𝓋 i) = ⌊get⌋ η i
⌊sub⌋ η (ƛ M) = ƛ & ( (λ σ → sub σ M) & ⌊lift⌋ η
⦙ ⌊sub⌋ (liftᵣ η) M
)
⌊sub⌋ η (M ∙ N) = _∙_ & ⌊sub⌋ η M
⊗ ⌊sub⌋ η N
⌊○⌋ : ∀ {Γ Γ′ Γ″} → (η₁ : Γ″ ∋⋆ Γ′) (η₂ : Γ′ ∋⋆ Γ)
→ ⌊ η₁ ○ η₂ ⌋ ≡ ⌊ η₁ ⌋ ● ⌊ η₂ ⌋
⌊○⌋ η₁ ∅ = refl
⌊○⌋ η₁ (η₂ , i) = _,_ & ⌊○⌋ η₁ η₂
⊗ (⌊get⌋ η₁ i ⁻¹)
--------------------------------------------------------------------------------
zap◐ : ∀ {Γ Ξ Ξ′ A} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ∋⋆ Ξ) (M : Γ ⊢ A)
→ (σ , M) ◐ wkᵣ η ≡ σ ◐ η
zap◐ σ ∅ M = refl
zap◐ σ (η , i) M = (_, getₛ σ i) & zap◐ σ η M
rid◐ : ∀ {Γ Ξ} → (σ : Γ ⊢⋆ Ξ)
→ σ ◐ idᵣ ≡ σ
rid◐ ∅ = refl
rid◐ (σ , M) = (_, M) & ( zap◐ σ idᵣ M
⦙ rid◐ σ
)
--------------------------------------------------------------------------------
get◐ : ∀ {Γ Ξ Ξ′ A} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ∋⋆ Ξ) (i : Ξ ∋ A)
→ getₛ (σ ◐ η) i ≡ (getₛ σ ∘ getᵣ η) i
get◐ σ (η , j) zero = refl
get◐ σ (η , j) (suc i) = get◐ σ η i
wk◐ : ∀ {Γ Ξ Ξ′ A} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ∋⋆ Ξ)
→ wkₛ {A} (σ ◐ η) ≡ wkₛ σ ◐ η
wk◐ σ ∅ = refl
wk◐ σ (η , i) = _,_ & wk◐ σ η
⊗ (natgetₛ σ i ⁻¹)
lift◐ : ∀ {Γ Ξ Ξ′ A} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ∋⋆ Ξ)
→ liftₛ {A} (σ ◐ η) ≡ liftₛ σ ◐ liftᵣ η
lift◐ σ η = (_, 0) & ( wk◐ σ η
⦙ zap◐ (wkₛ σ) η 0 ⁻¹
)
wkrid◐ : ∀ {Γ Ξ A} → (σ : Γ ⊢⋆ Ξ)
→ wkₛ {A} σ ◐ idᵣ ≡ wkₛ σ
wkrid◐ σ = wk◐ σ idᵣ ⁻¹
⦙ wkₛ & rid◐ σ
liftwkrid◐ : ∀ {Γ Ξ A} → (σ : Γ ⊢⋆ Ξ)
→ liftₛ {A} σ ◐ wkᵣ idᵣ ≡ wkₛ σ
liftwkrid◐ σ = zap◐ (wkₛ σ) idᵣ 0
⦙ wkrid◐ σ
mutual
sub◐ : ∀ {Γ Ξ Ξ′ A} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ∋⋆ Ξ) (M : Ξ ⊢ A)
→ sub (σ ◐ η) M ≡ (sub σ ∘ ren η) M
sub◐ σ η (𝓋 i) = get◐ σ η i
sub◐ σ η (ƛ M) = ƛ & sublift◐ σ η M
sub◐ σ η (M ∙ N) = _∙_ & sub◐ σ η M
⊗ sub◐ σ η N
sublift◐ : ∀ {Γ Ξ Ξ′ A B} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ∋⋆ Ξ) (M : Ξ , B ⊢ A)
→ sub (liftₛ {B} (σ ◐ η)) M ≡
(sub (liftₛ σ) ∘ ren (liftᵣ η)) M
sublift◐ σ η M = (λ σ′ → sub σ′ M) & lift◐ σ η
⦙ sub◐ (liftₛ σ) (liftᵣ η) M
subwk◐ : ∀ {Γ Ξ Ξ′ A B} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ∋⋆ Ξ) (M : Ξ ⊢ A)
→ sub (wkₛ {B} (σ ◐ η)) M ≡
(sub (wkₛ σ) ∘ ren η) M
subwk◐ σ η M = (λ σ′ → sub σ′ M) & wk◐ σ η
⦙ sub◐ (wkₛ σ) η M
subliftwk◐ : ∀ {Γ Ξ Ξ′ A B} → (σ : Γ ⊢⋆ Ξ′) (η : Ξ′ ∋⋆ Ξ) (M : Ξ ⊢ A)
→ sub (wkₛ {B} (σ ◐ η)) M ≡
(sub (liftₛ σ) ∘ ren (wkᵣ η)) M
subliftwk◐ σ η M = (λ σ′ → sub σ′ M) & ( wk◐ σ η
⦙ zap◐ (wkₛ σ) η 0 ⁻¹
)
⦙ sub◐ (liftₛ σ) (wkᵣ η) M
--------------------------------------------------------------------------------
zap◑ : ∀ {Γ Γ′ Ξ A} → (η : Γ′ ∋⋆ Γ) (σ : Γ ⊢⋆ Ξ) (i : Γ′ ∋ A)
→ (η , i) ◑ wkₛ σ ≡ η ◑ σ
zap◑ η ∅ i = refl
zap◑ η (σ , j) i = _,_ & zap◑ η σ i
⊗ ( sub◐ (⌊ η ⌋ , 𝓋 i) (wkᵣ idᵣ) j ⁻¹
⦙ (λ σ′ → sub σ′ j)
& ( zap◐ ⌊ η ⌋ idᵣ (𝓋 i)
⦙ rid◐ ⌊ η ⌋
)
)
lid◑ : ∀ {Γ Ξ} → (σ : Γ ⊢⋆ Ξ)
→ idᵣ ◑ σ ≡ σ
lid◑ ∅ = refl
lid◑ (σ , M) = _,_ & lid◑ σ
⊗ ( (λ σ′ → sub σ′ M) & ⌊id⌋ ⁻¹
⦙ idsub M
)
--------------------------------------------------------------------------------
zap● : ∀ {Γ Ξ Φ A} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (M : Γ ⊢ A)
→ (σ₁ , M) ● wkₛ σ₂ ≡ σ₁ ● σ₂
zap● σ₁ ∅ M = refl
zap● σ₁ (σ₂ , N) M = _,_ & zap● σ₁ σ₂ M
⊗ ( sub◐ (σ₁ , M) (wkᵣ idᵣ) N ⁻¹
⦙ (λ σ′ → sub σ′ N)
& ( zap◐ σ₁ idᵣ M
⦙ rid◐ σ₁
)
)
lid● : ∀ {Γ Ξ} → (σ : Γ ⊢⋆ Ξ)
→ idₛ ● σ ≡ σ
lid● ∅ = refl
lid● (σ , M) = _,_ & lid● σ
⊗ idsub M
rid● : ∀ {Γ Ξ} → (σ : Γ ⊢⋆ Ξ)
→ σ ● idₛ ≡ σ
rid● σ = (σ ●_) & ⌊id⌋ ⦙ rid◐ σ
--------------------------------------------------------------------------------
get◑ : ∀ {Γ Γ′ Ξ A} → (η : Γ′ ∋⋆ Γ) (σ : Γ ⊢⋆ Ξ) (i : Ξ ∋ A)
→ getₛ (η ◑ σ) i ≡ (ren η ∘ getₛ σ) i
get◑ η (σ , M) zero = ⌊sub⌋ η M
get◑ η (σ , M) (suc i) = get◑ η σ i
wk◑ : ∀ {Γ Γ′ Ξ A} → (η : Γ′ ∋⋆ Γ) (σ : Γ ⊢⋆ Ξ)
→ wkₛ {A} (η ◑ σ) ≡ wkᵣ η ◑ σ
wk◑ η ∅ = refl
wk◑ η (σ , M) = _,_ & wk◑ η σ
⊗ ( ren (wkᵣ idᵣ) & ⌊sub⌋ η M
⦙ ren○ (wkᵣ idᵣ) η M ⁻¹
⦙ (λ η′ → ren η′ M) & wklid○ η
⦙ ⌊sub⌋ (wkᵣ η) M ⁻¹
)
lift◑ : ∀ {Γ Γ′ Ξ A} → (η : Γ′ ∋⋆ Γ) (σ : Γ ⊢⋆ Ξ)
→ liftₛ {A} (η ◑ σ) ≡ liftᵣ η ◑ liftₛ σ
lift◑ η σ = (_, 0) & ( wk◑ η σ
⦙ zap● ⌊ wkᵣ η ⌋ σ 0 ⁻¹
)
wklid◑ : ∀ {Γ Ξ A} → (σ : Γ ⊢⋆ Ξ)
→ wkᵣ {A} idᵣ ◑ σ ≡ wkₛ σ
wklid◑ σ = wk◑ idᵣ σ ⁻¹
⦙ wkₛ & lid◑ σ
liftwklid◑ : ∀ {Γ Ξ A} → (σ : Γ ⊢⋆ Ξ)
→ (liftᵣ {A} idᵣ ◑ wkₛ σ) ≡ wkₛ σ
liftwklid◑ σ = zap◑ (wkᵣ idᵣ) σ 0
⦙ wklid◑ σ
mutual
sub◑ : ∀ {Γ Γ′ Ξ A} → (η : Γ′ ∋⋆ Γ) (σ : Γ ⊢⋆ Ξ) (M : Ξ ⊢ A)
→ sub (η ◑ σ) M ≡ (ren η ∘ sub σ) M
sub◑ η σ (𝓋 i) = get◑ η σ i
sub◑ η σ (ƛ M) = ƛ & sublift◑ η σ M
sub◑ η σ (M ∙ N) = _∙_ & sub◑ η σ M
⊗ sub◑ η σ N
sublift◑ : ∀ {Γ Γ′ Ξ A B} → (η : Γ′ ∋⋆ Γ) (σ : Γ ⊢⋆ Ξ) (M : Ξ , B ⊢ A)
→ sub (liftₛ {B} (η ◑ σ)) M ≡
(ren (liftᵣ η) ∘ sub (liftₛ σ)) M
sublift◑ η σ M = (λ σ′ → sub σ′ M) & lift◑ η σ
⦙ sub◑ (liftᵣ η) (liftₛ σ) M
subwk◑ : ∀ {Γ Γ′ Ξ A B} → (η : Γ′ ∋⋆ Γ) (σ : Γ ⊢⋆ Ξ) (M : Ξ ⊢ A)
→ sub (wkₛ {B} (η ◑ σ)) M ≡
(ren (wkᵣ η) ∘ sub σ) M
subwk◑ η σ M = (λ σ′ → sub σ′ M) & wk◑ η σ
⦙ sub◑ (wkᵣ η) σ M
subliftwk◑ : ∀ {Γ Γ′ Ξ A B} → (η : Γ′ ∋⋆ Γ) (σ : Γ ⊢⋆ Ξ) (M : Ξ ⊢ A)
→ sub (wkₛ {B} (η ◑ σ)) M ≡
(ren (liftᵣ η) ∘ sub (wkₛ σ)) M
subliftwk◑ η σ M = (λ σ′ → sub σ′ M) & ( wk◑ η σ
⦙ zap◑ (wkᵣ η) σ 0 ⁻¹
)
⦙ sub◑ (liftᵣ η) (wkₛ σ) M
--------------------------------------------------------------------------------
get● : ∀ {Γ Ξ Φ A} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (i : Φ ∋ A)
→ getₛ (σ₁ ● σ₂) i ≡ (sub σ₁ ∘ getₛ σ₂) i
get● σ₁ (σ₂ , M) zero = refl
get● σ₁ (σ₂ , M) (suc i) = get● σ₁ σ₂ i
wk● : ∀ {Γ Ξ Φ A} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ)
→ wkₛ {A} (σ₁ ● σ₂) ≡ wkₛ σ₁ ● σ₂
wk● σ₁ ∅ = refl
wk● σ₁ (σ₂ , M) = _,_ & wk● σ₁ σ₂
⊗ ( sub◑ (wkᵣ idᵣ) σ₁ M ⁻¹
⦙ (λ σ′ → sub σ′ M) & wklid◑ σ₁
)
lift● : ∀ {Γ Ξ Φ A} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ)
→ liftₛ {A} (σ₁ ● σ₂) ≡ liftₛ σ₁ ● liftₛ σ₂
lift● σ₁ σ₂ = (_, 0) & ( wk● σ₁ σ₂
⦙ zap● (wkₛ σ₁) σ₂ 0 ⁻¹
)
wklid● : ∀ {Γ Ξ A} → (σ : Γ ⊢⋆ Ξ)
→ wkₛ {A} idₛ ● σ ≡ wkₛ σ
wklid● σ = wk● idₛ σ ⁻¹
⦙ wkₛ & lid● σ
wkrid● : ∀ {Γ Ξ A} → (σ : Γ ⊢⋆ Ξ)
→ wkₛ {A} σ ● idₛ ≡ wkₛ σ
wkrid● σ = wk● σ idₛ ⁻¹
⦙ wkₛ & rid● σ
liftwkrid● : ∀ {Γ Ξ A} → (σ : Γ ⊢⋆ Ξ)
→ liftₛ {A} σ ● wkₛ idₛ ≡ wkₛ σ
liftwkrid● σ = zap● (wkₛ σ) idₛ 0
⦙ wkrid● σ
mutual
sub● : ∀ {Γ Ξ Φ A} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (M : Φ ⊢ A)
→ sub (σ₁ ● σ₂) M ≡ (sub σ₁ ∘ sub σ₂) M
sub● σ₁ σ₂ (𝓋 i) = get● σ₁ σ₂ i
sub● σ₁ σ₂ (ƛ M) = ƛ & sublift● σ₁ σ₂ M
sub● σ₁ σ₂ (M ∙ N) = _∙_ & sub● σ₁ σ₂ M
⊗ sub● σ₁ σ₂ N
sublift● : ∀ {Γ Ξ Φ A B} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (M : Φ , B ⊢ A)
→ sub (liftₛ {B} (σ₁ ● σ₂)) M ≡
(sub (liftₛ σ₁) ∘ sub (liftₛ σ₂)) M
sublift● σ₁ σ₂ M = (λ σ′ → sub σ′ M) & lift● σ₁ σ₂
⦙ sub● (liftₛ σ₁) (liftₛ σ₂) M
subwk● : ∀ {Γ Ξ Φ A B} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (M : Φ ⊢ A)
→ sub (wkₛ {B} (σ₁ ● σ₂)) M ≡
(sub (wkₛ σ₁) ∘ sub σ₂) M
subwk● σ₁ σ₂ M = (λ σ′ → sub σ′ M) & wk● σ₁ σ₂
⦙ sub● (wkₛ σ₁) σ₂ M
subliftwk● : ∀ {Γ Ξ Φ A B} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (M : Φ ⊢ A)
→ sub (wkₛ {B} (σ₁ ● σ₂)) M ≡
(sub (liftₛ σ₁) ∘ sub (wkₛ σ₂)) M
subliftwk● σ₁ σ₂ M = (λ σ′ → sub σ′ M) & ( wk● σ₁ σ₂
⦙ zap● (wkₛ σ₁) σ₂ 0 ⁻¹
)
⦙ sub● (liftₛ σ₁) (wkₛ σ₂) M
--------------------------------------------------------------------------------
comp◐○ : ∀ {Γ Ξ Ξ′ Ξ″} → (σ : Γ ⊢⋆ Ξ″) (η₁ : Ξ″ ∋⋆ Ξ′) (η₂ : Ξ′ ∋⋆ Ξ)
→ σ ◐ (η₁ ○ η₂) ≡ (σ ◐ η₁) ◐ η₂
comp◐○ σ η₁ ∅ = refl
comp◐○ σ η₁ (η₂ , i) = _,_ & comp◐○ σ η₁ η₂
⊗ (get◐ σ η₁ i ⁻¹)
comp◑○ : ∀ {Γ Γ′ Γ″ Ξ} → (η₁ : Γ″ ∋⋆ Γ′) (η₂ : Γ′ ∋⋆ Γ) (σ : Γ ⊢⋆ Ξ)
→ η₁ ◑ (η₂ ◑ σ) ≡ (η₁ ○ η₂) ◑ σ
comp◑○ η₁ η₂ ∅ = refl
comp◑○ η₁ η₂ (σ , M) = _,_ & comp◑○ η₁ η₂ σ
⊗ ( sub● ⌊ η₁ ⌋ ⌊ η₂ ⌋ M ⁻¹
⦙ (λ σ′ → sub σ′ M)
& ⌊○⌋ η₁ η₂ ⁻¹
)
comp◑◐ : ∀ {Γ Γ′ Ξ Ξ′} → (η₁ : Γ′ ∋⋆ Γ) (σ : Γ ⊢⋆ Ξ′) (η₂ : Ξ′ ∋⋆ Ξ)
→ η₁ ◑ (σ ◐ η₂) ≡ (η₁ ◑ σ) ◐ η₂
comp◑◐ η₁ σ ∅ = refl
comp◑◐ η₁ σ (η₂ , i) = _,_ & comp◑◐ η₁ σ η₂
⊗ ( ⌊sub⌋ η₁ (getₛ σ i)
⦙ get◑ η₁ σ i ⁻¹
)
comp◑● : ∀ {Γ Γ′ Ξ Φ} → (η : Γ′ ∋⋆ Γ) (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ)
→ η ◑ (σ₁ ● σ₂) ≡ (η ◑ σ₁) ● σ₂
comp◑● η σ₁ ∅ = refl
comp◑● η σ₁ (σ₂ , M) = _,_ & comp◑● η σ₁ σ₂
⊗ (sub● ⌊ η ⌋ σ₁ M ⁻¹)
comp●◐ : ∀ {Γ Ξ Φ Φ′} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ′) (η : Φ′ ∋⋆ Φ)
→ σ₁ ● (σ₂ ◐ η) ≡ (σ₁ ● σ₂) ◐ η
comp●◐ σ₁ σ₂ ∅ = refl
comp●◐ σ₁ σ₂ (η , i) = _,_ & comp●◐ σ₁ σ₂ η
⊗ (get● σ₁ σ₂ i ⁻¹)
comp●◑ : ∀ {Γ Ξ Ξ′ Φ} → (σ₁ : Γ ⊢⋆ Ξ′) (η : Ξ′ ∋⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ)
→ σ₁ ● (η ◑ σ₂) ≡ (σ₁ ◐ η) ● σ₂
comp●◑ σ₁ η ∅ = refl
comp●◑ σ₁ η (σ₂ , M) = _,_ & comp●◑ σ₁ η σ₂
⊗ (sub● σ₁ ⌊ η ⌋ M ⁻¹)
--------------------------------------------------------------------------------
assoc● : ∀ {Γ Ξ Φ Ψ} → (σ₁ : Γ ⊢⋆ Ξ) (σ₂ : Ξ ⊢⋆ Φ) (σ₃ : Φ ⊢⋆ Ψ)
→ σ₁ ● (σ₂ ● σ₃) ≡ (σ₁ ● σ₂) ● σ₃
assoc● σ₁ σ₂ ∅ = refl
assoc● σ₁ σ₂ (σ₃ , M) = _,_ & assoc● σ₁ σ₂ σ₃
⊗ (sub● σ₁ σ₂ M ⁻¹)
--------------------------------------------------------------------------------
𝗦𝗧𝗟𝗖 : Category 𝒞 _⊢⋆_
𝗦𝗧𝗟𝗖 =
record
{ idₓ = idₛ
; _⋄_ = flip _●_
; lid⋄ = rid●
; rid⋄ = lid●
; assoc⋄ = assoc●
}
subPsh : 𝒯 → Presheaf₀ 𝗦𝗧𝗟𝗖
subPsh A =
record
{ Fₓ = _⊢ A
; F = sub
; idF = fext! idsub
; F⋄ = λ σ₁ σ₂ → fext! (sub● σ₂ σ₁)
}
--------------------------------------------------------------------------------
| 31.530043
| 80
| 0.277955
|
52db52fb312f69cacb39f55b86783605d19d1d2f
| 11,773
|
agda
|
Agda
|
Cubical/Data/Nat/Order.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Data/Nat/Order.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
Cubical/Data/Nat/Order.agda
|
howsiyu/cubical
|
1b9c97a2140fe96fe636f4c66beedfd7b8096e8f
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --no-exact-split --safe #-}
module Cubical.Data.Nat.Order where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Sigma
open import Cubical.Data.Sum as ⊎
open import Cubical.Data.Nat.Base
open import Cubical.Data.Nat.Properties
open import Cubical.Induction.WellFounded
open import Cubical.Relation.Nullary
infix 4 _≤_ _<_ _≥_ _>_
_≤_ : ℕ → ℕ → Type₀
m ≤ n = Σ[ k ∈ ℕ ] k + m ≡ n
_<_ : ℕ → ℕ → Type₀
m < n = suc m ≤ n
_≥_ : ℕ → ℕ → Type₀
m ≥ n = n ≤ m
_>_ : ℕ → ℕ → Type₀
m > n = n < m
data Trichotomy (m n : ℕ) : Type₀ where
lt : m < n → Trichotomy m n
eq : m ≡ n → Trichotomy m n
gt : n < m → Trichotomy m n
private
variable
k l m n : ℕ
private
witness-prop : ∀ j → isProp (j + m ≡ n)
witness-prop {m} {n} j = isSetℕ (j + m) n
m≤n-isProp : isProp (m ≤ n)
m≤n-isProp {m} {n} (k , p) (l , q)
= Σ≡Prop witness-prop lemma
where
lemma : k ≡ l
lemma = inj-+m (p ∙ (sym q))
zero-≤ : 0 ≤ n
zero-≤ {n} = n , +-zero n
suc-≤-suc : m ≤ n → suc m ≤ suc n
suc-≤-suc (k , p) = k , (+-suc k _) ∙ (cong suc p)
≤-+k : m ≤ n → m + k ≤ n + k
≤-+k {m} {k = k} (i , p)
= i , +-assoc i m k ∙ cong (_+ k) p
≤-k+ : m ≤ n → k + m ≤ k + n
≤-k+ {m} {n} {k}
= subst (_≤ k + n) (+-comm m k)
∘ subst (m + k ≤_) (+-comm n k)
∘ ≤-+k
pred-≤-pred : suc m ≤ suc n → m ≤ n
pred-≤-pred (k , p) = k , injSuc ((sym (+-suc k _)) ∙ p)
≤-refl : m ≤ m
≤-refl = 0 , refl
≤-suc : m ≤ n → m ≤ suc n
≤-suc (k , p) = suc k , cong suc p
suc-< : suc m < n → m < n
suc-< p = pred-≤-pred (≤-suc p)
≤-sucℕ : n ≤ suc n
≤-sucℕ = ≤-suc ≤-refl
≤-predℕ : predℕ n ≤ n
≤-predℕ {zero} = ≤-refl
≤-predℕ {suc n} = ≤-suc ≤-refl
≤-trans : k ≤ m → m ≤ n → k ≤ n
≤-trans {k} {m} {n} (i , p) (j , q) = i + j , l2 ∙ (l1 ∙ q)
where
l1 : j + i + k ≡ j + m
l1 = (sym (+-assoc j i k)) ∙ (cong (j +_) p)
l2 : i + j + k ≡ j + i + k
l2 = cong (_+ k) (+-comm i j)
≤-antisym : m ≤ n → n ≤ m → m ≡ n
≤-antisym {m} (i , p) (j , q) = (cong (_+ m) l3) ∙ p
where
l1 : j + i + m ≡ m
l1 = (sym (+-assoc j i m)) ∙ ((cong (j +_) p) ∙ q)
l2 : j + i ≡ 0
l2 = m+n≡n→m≡0 l1
l3 : 0 ≡ i
l3 = sym (snd (m+n≡0→m≡0×n≡0 l2))
≤-+-≤ : m ≤ n → l ≤ k → m + l ≤ n + k
≤-+-≤ p q = ≤-trans (≤-+k p) (≤-k+ q)
≤-k+-cancel : k + m ≤ k + n → m ≤ n
≤-k+-cancel {k} {m} (l , p) = l , inj-m+ (sub k m ∙ p)
where
sub : ∀ k m → k + (l + m) ≡ l + (k + m)
sub k m = +-assoc k l m ∙ cong (_+ m) (+-comm k l) ∙ sym (+-assoc l k m)
≤-+k-cancel : m + k ≤ n + k → m ≤ n
≤-+k-cancel {m} {k} {n} (l , p) = l , cancelled
where
cancelled : l + m ≡ n
cancelled = inj-+m (sym (+-assoc l m k) ∙ p)
≤-·k : m ≤ n → m · k ≤ n · k
≤-·k {m} {n} {k} (d , r) = d · k , reason where
reason : d · k + m · k ≡ n · k
reason = d · k + m · k ≡⟨ ·-distribʳ d m k ⟩
(d + m) · k ≡⟨ cong (_· k) r ⟩
n · k ∎
<-k+-cancel : k + m < k + n → m < n
<-k+-cancel {k} {m} {n} = ≤-k+-cancel ∘ subst (_≤ k + n) (sym (+-suc k m))
¬-<-zero : ¬ m < 0
¬-<-zero (k , p) = snotz ((sym (+-suc k _)) ∙ p)
¬m<m : ¬ m < m
¬m<m {m} = ¬-<-zero ∘ ≤-+k-cancel {k = m}
≤0→≡0 : n ≤ 0 → n ≡ 0
≤0→≡0 {zero} ineq = refl
≤0→≡0 {suc n} ineq = ⊥.rec (¬-<-zero ineq)
predℕ-≤-predℕ : m ≤ n → (predℕ m) ≤ (predℕ n)
predℕ-≤-predℕ {zero} {zero} ineq = ≤-refl
predℕ-≤-predℕ {zero} {suc n} ineq = zero-≤
predℕ-≤-predℕ {suc m} {zero} ineq = ⊥.rec (¬-<-zero ineq)
predℕ-≤-predℕ {suc m} {suc n} ineq = pred-≤-pred ineq
¬m+n<m : ¬ m + n < m
¬m+n<m {m} {n} = ¬-<-zero ∘ <-k+-cancel ∘ subst (m + n <_) (sym (+-zero m))
<-weaken : m < n → m ≤ n
<-weaken (k , p) = suc k , sym (+-suc k _) ∙ p
≤<-trans : l ≤ m → m < n → l < n
≤<-trans p = ≤-trans (suc-≤-suc p)
<≤-trans : l < m → m ≤ n → l < n
<≤-trans = ≤-trans
<-trans : l < m → m < n → l < n
<-trans p = ≤<-trans (<-weaken p)
<-asym : m < n → ¬ n ≤ m
<-asym m<n = ¬m<m ∘ <≤-trans m<n
<-+k : m < n → m + k < n + k
<-+k p = ≤-+k p
<-k+ : m < n → k + m < k + n
<-k+ {m} {n} {k} p = subst (λ km → km ≤ k + n) (+-suc k m) (≤-k+ p)
<-+-< : m < n → k < l → m + k < n + l
<-+-< m<n k<l = <-trans (<-+k m<n) (<-k+ k<l)
<-+-≤ : m < n → k ≤ l → m + k < n + l
<-+-≤ p q = <≤-trans (<-+k p) (≤-k+ q)
<-·sk : m < n → m · suc k < n · suc k
<-·sk {m} {n} {k} (d , r) = (d · suc k + k) , reason where
reason : (d · suc k + k) + suc (m · suc k) ≡ n · suc k
reason = (d · suc k + k) + suc (m · suc k) ≡⟨ sym (+-assoc (d · suc k) k _) ⟩
d · suc k + (k + suc (m · suc k)) ≡[ i ]⟨ d · suc k + +-suc k (m · suc k) i ⟩
d · suc k + suc m · suc k ≡⟨ ·-distribʳ d (suc m) (suc k) ⟩
(d + suc m) · suc k ≡⟨ cong (_· suc k) r ⟩
n · suc k ∎
∸-≤ : ∀ m n → m ∸ n ≤ m
∸-≤ m zero = ≤-refl
∸-≤ zero (suc n) = ≤-refl
∸-≤ (suc m) (suc n) = ≤-trans (∸-≤ m n) (1 , refl)
≤-∸-+-cancel : m ≤ n → (n ∸ m) + m ≡ n
≤-∸-+-cancel {zero} {n} _ = +-zero _
≤-∸-+-cancel {suc m} {zero} m≤n = ⊥.rec (¬-<-zero m≤n)
≤-∸-+-cancel {suc m} {suc n} m+1≤n+1 = +-suc _ _ ∙ cong suc (≤-∸-+-cancel (pred-≤-pred m+1≤n+1))
≤-∸-suc : m ≤ n → suc (n ∸ m) ≡ suc n ∸ m
≤-∸-suc {zero} {n} m≤n = refl
≤-∸-suc {suc m} {zero} m≤n = ⊥.rec (¬-<-zero m≤n)
≤-∸-suc {suc m} {suc n} m+1≤n+1 = ≤-∸-suc (pred-≤-pred m+1≤n+1)
left-≤-max : m ≤ max m n
left-≤-max {zero} {n} = zero-≤
left-≤-max {suc m} {zero} = ≤-refl
left-≤-max {suc m} {suc n} = suc-≤-suc left-≤-max
right-≤-max : n ≤ max m n
right-≤-max {zero} {m} = zero-≤
right-≤-max {suc n} {zero} = ≤-refl
right-≤-max {suc n} {suc m} = suc-≤-suc right-≤-max
min-≤-left : min m n ≤ m
min-≤-left {zero} {n} = ≤-refl
min-≤-left {suc m} {zero} = zero-≤
min-≤-left {suc m} {suc n} = suc-≤-suc min-≤-left
min-≤-right : min m n ≤ n
min-≤-right {zero} {n} = zero-≤
min-≤-right {suc m} {zero} = ≤-refl
min-≤-right {suc m} {suc n} = suc-≤-suc min-≤-right
≤Dec : ∀ m n → Dec (m ≤ n)
≤Dec zero n = yes (n , +-zero _)
≤Dec (suc m) zero = no ¬-<-zero
≤Dec (suc m) (suc n) with ≤Dec m n
... | yes m≤n = yes (suc-≤-suc m≤n)
... | no m≰n = no λ m+1≤n+1 → m≰n (pred-≤-pred m+1≤n+1 )
<Dec : ∀ m n → Dec (m < n)
<Dec m n = ≤Dec (suc m) n
Trichotomy-suc : Trichotomy m n → Trichotomy (suc m) (suc n)
Trichotomy-suc (lt m<n) = lt (suc-≤-suc m<n)
Trichotomy-suc (eq m=n) = eq (cong suc m=n)
Trichotomy-suc (gt n<m) = gt (suc-≤-suc n<m)
_≟_ : ∀ m n → Trichotomy m n
zero ≟ zero = eq refl
zero ≟ suc n = lt (n , +-comm n 1)
suc m ≟ zero = gt (m , +-comm m 1)
suc m ≟ suc n = Trichotomy-suc (m ≟ n)
<-split : m < suc n → (m < n) ⊎ (m ≡ n)
<-split {n = zero} = inr ∘ snd ∘ m+n≡0→m≡0×n≡0 ∘ snd ∘ pred-≤-pred
<-split {zero} {suc n} = λ _ → inl (suc-≤-suc zero-≤)
<-split {suc m} {suc n} = ⊎.map suc-≤-suc (cong suc) ∘ <-split ∘ pred-≤-pred
≤-split : m ≤ n → (m < n) ⊎ (m ≡ n)
≤-split p = <-split (suc-≤-suc p)
≤→< : m ≤ n → ¬ m ≡ n → m < n
≤→< p q =
case (≤-split p) of
λ { (inl r) → r
; (inr r) → ⊥.rec (q r) }
≤-+-split : ∀ n m k → k ≤ n + m → (n ≤ k) ⊎ (m ≤ (n + m) ∸ k)
≤-+-split n m k k≤n+m with n ≟ k
... | eq p = inl (0 , p)
... | lt n<k = inl (<-weaken n<k)
... | gt k<n with m ≟ ((n + m) ∸ k)
... | eq p = inr (0 , p)
... | lt m<n+m∸k = inr (<-weaken m<n+m∸k)
... | gt n+m∸k<m =
⊥.rec (¬m<m (transport (λ i → ≤-∸-+-cancel k≤n+m i < +-comm m n i) (<-+-< n+m∸k<m k<n)))
<-asym'-case : Trichotomy m n → ¬ m < n → n ≤ m
<-asym'-case (lt p) q = ⊥.rec (q p)
<-asym'-case (eq p) _ = _ , sym p
<-asym'-case (gt p) _ = <-weaken p
<-asym' : ¬ m < n → n ≤ m
<-asym' = <-asym'-case (_≟_ _ _)
private
acc-suc : Acc _<_ n → Acc _<_ (suc n)
acc-suc a
= acc λ y y<sn
→ case <-split y<sn of λ
{ (inl y<n) → access a y y<n
; (inr y≡n) → subst _ (sym y≡n) a
}
<-wellfounded : WellFounded _<_
<-wellfounded zero = acc λ _ → ⊥.rec ∘ ¬-<-zero
<-wellfounded (suc n) = acc-suc (<-wellfounded n)
<→≢ : n < m → ¬ n ≡ m
<→≢ {n} {m} p q = ¬m<m (subst (_< m) q p)
module _
(b₀ : ℕ)
(P : ℕ → Type₀)
(base : ∀ n → n < suc b₀ → P n)
(step : ∀ n → P n → P (suc b₀ + n))
where
open WFI (<-wellfounded)
private
dichotomy : ∀ b n → (n < b) ⊎ (Σ[ m ∈ ℕ ] n ≡ b + m)
dichotomy b n
= case n ≟ b return (λ _ → (n < b) ⊎ (Σ[ m ∈ ℕ ] n ≡ b + m)) of λ
{ (lt o) → inl o
; (eq p) → inr (0 , p ∙ sym (+-zero b))
; (gt (m , p)) → inr (suc m , sym p ∙ +-suc m b ∙ +-comm (suc m) b)
}
dichotomy<≡ : ∀ b n → (n<b : n < b) → dichotomy b n ≡ inl n<b
dichotomy<≡ b n n<b
= case dichotomy b n return (λ d → d ≡ inl n<b) of λ
{ (inl x) → cong inl (m≤n-isProp x n<b)
; (inr (m , p)) → ⊥.rec (<-asym n<b (m , sym (p ∙ +-comm b m)))
}
dichotomy+≡ : ∀ b m n → (p : n ≡ b + m) → dichotomy b n ≡ inr (m , p)
dichotomy+≡ b m n p
= case dichotomy b n return (λ d → d ≡ inr (m , p)) of λ
{ (inl n<b) → ⊥.rec (<-asym n<b (m , +-comm m b ∙ sym p))
; (inr (m' , q))
→ cong inr (Σ≡Prop (λ x → isSetℕ n (b + x)) (inj-m+ {m = b} (sym q ∙ p)))
}
b = suc b₀
lemma₁ : ∀{x y z} → x ≡ suc z + y → y < x
lemma₁ {y = y} {z} p = z , +-suc z y ∙ sym p
subStep : (n : ℕ) → (∀ m → m < n → P m) → (n < b) ⊎ (Σ[ m ∈ ℕ ] n ≡ b + m) → P n
subStep n _ (inl l) = base n l
subStep n rec (inr (m , p))
= transport (cong P (sym p)) (step m (rec m (lemma₁ p)))
wfStep : (n : ℕ) → (∀ m → m < n → P m) → P n
wfStep n rec = subStep n rec (dichotomy b n)
wfStepLemma₀ : ∀ n (n<b : n < b) rec → wfStep n rec ≡ base n n<b
wfStepLemma₀ n n<b rec = cong (subStep n rec) (dichotomy<≡ b n n<b)
wfStepLemma₁ : ∀ n rec → wfStep (b + n) rec ≡ step n (rec n (lemma₁ refl))
wfStepLemma₁ n rec
= cong (subStep (b + n) rec) (dichotomy+≡ b n (b + n) refl)
∙ transportRefl _
+induction : ∀ n → P n
+induction = induction wfStep
+inductionBase : ∀ n → (l : n < b) → +induction n ≡ base n l
+inductionBase n l = induction-compute wfStep n ∙ wfStepLemma₀ n l _
+inductionStep : ∀ n → +induction (b + n) ≡ step n (+induction n)
+inductionStep n = induction-compute wfStep (b + n) ∙ wfStepLemma₁ n _
module <-Reasoning where
-- TODO: would it be better to mirror the way it is done in the agda-stdlib?
infixr 2 _<⟨_⟩_ _≤<⟨_⟩_ _≤⟨_⟩_ _<≤⟨_⟩_ _≡<⟨_⟩_ _≡≤⟨_⟩_ _<≡⟨_⟩_ _≤≡⟨_⟩_
_<⟨_⟩_ : ∀ k → k < n → n < m → k < m
_ <⟨ p ⟩ q = <-trans p q
_≤<⟨_⟩_ : ∀ k → k ≤ n → n < m → k < m
_ ≤<⟨ p ⟩ q = ≤<-trans p q
_≤⟨_⟩_ : ∀ k → k ≤ n → n ≤ m → k ≤ m
_ ≤⟨ p ⟩ q = ≤-trans p q
_<≤⟨_⟩_ : ∀ k → k < n → n ≤ m → k < m
_ <≤⟨ p ⟩ q = <≤-trans p q
_≡≤⟨_⟩_ : ∀ k → k ≡ l → l ≤ m → k ≤ m
_ ≡≤⟨ p ⟩ q = subst (λ k → k ≤ _) (sym p) q
_≡<⟨_⟩_ : ∀ k → k ≡ l → l < m → k < m
_ ≡<⟨ p ⟩ q = _ ≡≤⟨ cong suc p ⟩ q
_≤≡⟨_⟩_ : ∀ k → k ≤ l → l ≡ m → k ≤ m
_ ≤≡⟨ p ⟩ q = subst (λ l → _ ≤ l) q p
_<≡⟨_⟩_ : ∀ k → k < l → l ≡ m → k < m
_ <≡⟨ p ⟩ q = _ ≤≡⟨ p ⟩ q
-- Some lemmas about ∸
suc∸-fst : (n m : ℕ) → m < n → suc (n ∸ m) ≡ (suc n) ∸ m
suc∸-fst zero zero p = refl
suc∸-fst zero (suc m) p = ⊥.rec (¬-<-zero p)
suc∸-fst (suc n) zero p = refl
suc∸-fst (suc n) (suc m) p = (suc∸-fst n m (pred-≤-pred p))
n∸m≡0 : (n m : ℕ) → n < m → (n ∸ m) ≡ 0
n∸m≡0 zero zero p = refl
n∸m≡0 (suc n) zero p = ⊥.rec (¬-<-zero p)
n∸m≡0 zero (suc m) p = refl
n∸m≡0 (suc n) (suc m) p = n∸m≡0 n m (pred-≤-pred p)
n∸n≡0 : (n : ℕ) → n ∸ n ≡ 0
n∸n≡0 zero = refl
n∸n≡0 (suc n) = n∸n≡0 n
-- automation
≤-solver-type : (m n : ℕ) → Trichotomy m n → Type
≤-solver-type m n (lt p) = m ≤ n
≤-solver-type m n (eq p) = m ≤ n
≤-solver-type m n (gt p) = n < m
≤-solver-case : (m n : ℕ) → (p : Trichotomy m n) → ≤-solver-type m n p
≤-solver-case m n (lt p) = <-weaken p
≤-solver-case m n (eq p) = _ , p
≤-solver-case m n (gt p) = p
≤-solver : (m n : ℕ) → ≤-solver-type m n (m ≟ n)
≤-solver m n = ≤-solver-case m n (m ≟ n)
| 28.575243
| 96
| 0.458931
|
04bafb94ba90c4debc8181e0de4d78b3e392577b
| 8,392
|
agda
|
Agda
|
PiFrac/Eval.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
PiFrac/Eval.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
PiFrac/Eval.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
module PiFrac.Eval where
open import Data.Empty
open import Data.Unit hiding (_≟_)
open import Data.Sum
open import Data.Product
open import Data.List as L hiding (_∷_)
open import Data.Maybe
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
open import PiFrac.NoRepeat
-- Stuck states must be either of the form [ c ∣ v ∣ ☐ ] or ⊠
Stuck : ∀ {st} → is-stuck st
→ (Σ[ A ∈ 𝕌 ] Σ[ B ∈ 𝕌 ] Σ[ c ∈ A ↔ B ] Σ[ v ∈ ⟦ B ⟧ ] st ≡ [ c ∣ v ∣ ☐ ]) ⊎ st ≡ ⊠
Stuck {⟨ uniti₊l ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ unite₊l ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ swap₊ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ assocl₊ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ assocr₊ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ unite⋆l ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ uniti⋆l ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ swap⋆ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ assocl⋆ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ assocr⋆ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ dist ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ factor ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₁))
Stuck {⟨ id↔ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₂))
Stuck {⟨ ηₓ v ∣ tt ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦η))
Stuck {⟨ εₓ v ∣ v' , ↻ ∣ κ ⟩} stuck with v ≟ v'
... | yes eq = ⊥-elim (stuck (_ , ↦ε₁ {eq = eq}))
... | no neq = ⊥-elim (stuck (_ , ↦ε₂ {neq = neq}))
Stuck {⟨ c₁ ⨾ c₂ ∣ v ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₃))
Stuck {⟨ c₁ ⊕ c₂ ∣ inj₁ x ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₄))
Stuck {⟨ c₁ ⊕ c₂ ∣ inj₂ y ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₅))
Stuck {⟨ c₁ ⊗ c₂ ∣ (x , y) ∣ κ ⟩} stuck = ⊥-elim (stuck (_ , ↦₆))
Stuck {[ c ∣ v ∣ ☐ ]} stuck = inj₁ (_ , _ , _ , _ , refl)
Stuck {[ c ∣ v ∣ ☐⨾ c₂ • κ ]} stuck = ⊥-elim (stuck (_ , ↦₇))
Stuck {[ c ∣ v ∣ c₁ ⨾☐• κ ]} stuck = ⊥-elim (stuck (_ , ↦₁₀))
Stuck {[ c ∣ v ∣ ☐⊕ c₂ • κ ]} stuck = ⊥-elim (stuck (_ , ↦₁₁))
Stuck {[ c ∣ v ∣ c₁ ⊕☐• κ ]} stuck = ⊥-elim (stuck (_ , ↦₁₂))
Stuck {[ c ∣ v ∣ ☐⊗[ c₂ , y ]• κ ]} stuck = ⊥-elim (stuck (_ , ↦₈))
Stuck {[ c ∣ v ∣ [ c₁ , x ]⊗☐• κ ]} stuck = ⊥-elim (stuck (_ , ↦₉))
Stuck {⊠} stuck = inj₂ refl
-- Auxiliary function for forward evaluator
ev : ∀ {A B κ} → (c : A ↔ B) (v : ⟦ A ⟧)
→ Σ[ v' ∈ ⟦ B ⟧ ] ⟨ c ∣ v ∣ κ ⟩ ↦* [ c ∣ v' ∣ κ ]
⊎ ⟨ c ∣ v ∣ κ ⟩ ↦* ⊠
ev uniti₊l v = inj₁ ((inj₂ v) , ↦₁ ∷ ◾)
ev unite₊l (inj₂ y) = inj₁ (y , ↦₁ ∷ ◾)
ev swap₊ (inj₁ v) = inj₁ (inj₂ v , (↦₁ ∷ ◾))
ev swap₊ (inj₂ v) = inj₁ (inj₁ v , (↦₁ ∷ ◾))
ev assocl₊ (inj₁ v) = inj₁ (inj₁ (inj₁ v) , (↦₁ ∷ ◾))
ev assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₁ (inj₂ v) , (↦₁ ∷ ◾))
ev assocl₊ (inj₂ (inj₂ v)) = inj₁ (inj₂ v , (↦₁ ∷ ◾))
ev assocr₊ (inj₁ (inj₁ v)) = inj₁ (inj₁ v , (↦₁ ∷ ◾))
ev assocr₊ (inj₁ (inj₂ v)) = inj₁ (inj₂ (inj₁ v) , (↦₁ ∷ ◾))
ev assocr₊ (inj₂ v) = inj₁ (inj₂ (inj₂ v) , (↦₁ ∷ ◾))
ev unite⋆l (tt , v) = inj₁ (v , (↦₁ ∷ ◾))
ev uniti⋆l v = inj₁ ((tt , v) , (↦₁ ∷ ◾))
ev swap⋆ (x , y) = inj₁ ((y , x) , (↦₁ ∷ ◾))
ev assocl⋆ (x , (y , z)) = inj₁ (((x , y) , z) , (↦₁ ∷ ◾))
ev assocr⋆ ((x , y) , z) = inj₁ ((x , (y , z)) , (↦₁ ∷ ◾))
ev dist (inj₁ x , z) = inj₁ (inj₁ (x , z) , (↦₁ ∷ ◾))
ev dist (inj₂ y , z) = inj₁ (inj₂ (y , z) , (↦₁ ∷ ◾))
ev factor (inj₁ (x , z)) = inj₁ ((inj₁ x , z) , (↦₁ ∷ ◾))
ev factor (inj₂ (y , z)) = inj₁ ((inj₂ y , z) , (↦₁ ∷ ◾))
ev id↔ v = inj₁ (v , (↦₂ ∷ ◾))
ev {κ = κ} (c₁ ⨾ c₂) v₁ with ev {κ = ☐⨾ c₂ • κ} c₁ v₁
... | inj₁ (v₂ , c₁↦*) with ev {κ = c₁ ⨾☐• κ} c₂ v₂
... | inj₁ (v₃ , c₂↦*) = inj₁ (v₃ , ((↦₃ ∷ c₁↦* ++↦ (↦₇ ∷ ◾)) ++↦ (c₂↦* ++↦ (↦₁₀ ∷ ◾))))
... | inj₂ c₂↦* = inj₂ ((↦₃ ∷ c₁↦* ++↦ (↦₇ ∷ ◾)) ++↦ c₂↦*)
ev {κ = κ} (c₁ ⨾ c₂) v₁ | inj₂ c₁↦* = inj₂ (↦₃ ∷ c₁↦*)
ev {κ = κ} (c₁ ⊕ c₂) (inj₁ x) with ev {κ = ☐⊕ c₂ • κ} c₁ x
... | inj₁ (x' , c₁↦*) = inj₁ (inj₁ x' , ↦₄ ∷ c₁↦* ++↦ (↦₁₁ ∷ ◾))
... | inj₂ c₁↦* = inj₂ (↦₄ ∷ c₁↦*)
ev {κ = κ} (c₁ ⊕ c₂) (inj₂ y) with ev {κ = c₁ ⊕☐• κ} c₂ y
... | inj₁ (y' , c₂↦*) = inj₁ (inj₂ y' , ↦₅ ∷ c₂↦* ++↦ (↦₁₂ ∷ ◾))
... | inj₂ c₂↦* = inj₂ (↦₅ ∷ c₂↦*)
ev {κ = κ} (c₁ ⊗ c₂) (x , y) with ev {κ = ☐⊗[ c₂ , y ]• κ} c₁ x
... | inj₁ (x' , c₁↦*) with ev {κ = [ c₁ , x' ]⊗☐• κ} c₂ y
... | inj₁ (y' , c₂↦*) = inj₁ ((x' , y') , ((↦₆ ∷ c₁↦*) ++↦ ((↦₈ ∷ c₂↦*) ++↦ (↦₉ ∷ ◾))))
... | inj₂ c₂↦* = inj₂ ((↦₆ ∷ c₁↦*) ++↦ (↦₈ ∷ c₂↦*))
ev {κ = κ} (c₁ ⊗ c₂) (x , y) | inj₂ c₁↦* = inj₂ (↦₆ ∷ c₁↦*)
ev (ηₓ v) tt = inj₁ ((v , ↻) , (↦η ∷ ◾))
ev (εₓ v) (v' , ↻) with v ≟ v'
... | yes eq = inj₁ (tt , (↦ε₁ {eq = eq} ∷ ◾))
... | no neq = inj₂ (↦ε₂ {neq = neq} ∷ ◾)
-- Forward evaluator for PiFrac
eval : ∀ {A B} → (c : A ↔ B) → ⟦ A ⟧ → Maybe ⟦ B ⟧
eval c v = [ just ∘ proj₁ , (λ _ → nothing) ]′ (ev {κ = ☐} c v)
-- Forward evaluator which returns execution trace
evalₜᵣ : ∀ {A B} → (c : A ↔ B) → ⟦ A ⟧ → List State
evalₜᵣ c v = [ convert ∘ proj₂ , convert ]′ (ev {κ = ☐} c v)
where
convert : ∀ {st st'} → st ↦* st' → List State
convert (◾ {st}) = st L.∷ []
convert (_∷_ {st} r rs) = st L.∷ convert rs
-- Auxiliary function for backward evaluator
evᵣₑᵥ : ∀ {A B κ} → (c : A ↔ B) (v : ⟦ B ⟧)
→ Σ[ v' ∈ ⟦ A ⟧ ] [ c ∣ v ∣ κ ] ↦ᵣₑᵥ* ⟨ c ∣ v' ∣ κ ⟩
⊎ ∃[ A ] (∃[ v' ] (∃[ v'' ] (∃[ κ' ] (v' ≢ v'' × [ c ∣ v ∣ κ ] ↦ᵣₑᵥ* [ ηₓ {A} v' ∣ (v'' , ↻) ∣ κ' ]))))
evᵣₑᵥ uniti₊l (inj₂ v) = inj₁ (v , (↦₁ ᵣₑᵥ ∷ ◾))
evᵣₑᵥ unite₊l v = inj₁ ((inj₂ v) , (↦₁ ᵣₑᵥ ∷ ◾))
evᵣₑᵥ swap₊ (inj₁ x) = inj₁ (inj₂ x , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ swap₊ (inj₂ y) = inj₁ (inj₁ y , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocl₊ (inj₁ (inj₁ x)) = inj₁ (inj₁ x , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocl₊ (inj₁ (inj₂ y)) = inj₁ (inj₂ (inj₁ y) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocl₊ (inj₂ z) = inj₁ (inj₂ (inj₂ z) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocr₊ (inj₁ x) = inj₁ (inj₁ (inj₁ x) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocr₊ (inj₂ (inj₁ y)) = inj₁ (inj₁ (inj₂ y) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocr₊ (inj₂ (inj₂ z)) = inj₁ (inj₂ z , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ unite⋆l v = inj₁ ((tt , v) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ uniti⋆l (tt , v) = inj₁ (v , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ swap⋆ (x , y) = inj₁ ((y , x) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocl⋆ ((x , y) , z) = inj₁ ((x , (y , z)) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ assocr⋆ (x , (y , z)) = inj₁ (((x , y) , z) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ dist (inj₁ (x , z)) = inj₁ ((inj₁ x , z) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ dist (inj₂ (y , z)) = inj₁ ((inj₂ y , z) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ factor (inj₁ x , z) = inj₁ (inj₁ (x , z) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ factor (inj₂ y , z) = inj₁ (inj₂ (y , z) , (↦₁ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ id↔ v = inj₁ (v , (↦₂ ᵣₑᵥ) ∷ ◾)
evᵣₑᵥ {κ = κ} (c₁ ⨾ c₂) v₃ with evᵣₑᵥ {κ = c₁ ⨾☐• κ} c₂ v₃
... | inj₁ (v₂ , rs) with evᵣₑᵥ {κ = ☐⨾ c₂ • κ} c₁ v₂
... | inj₁ (v₁ , rs') = inj₁ (v₁ , ((↦₁₀ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₇ ᵣₑᵥ) ∷ ◾))) ++↦ᵣₑᵥ (rs' ++↦ᵣₑᵥ ((↦₃ ᵣₑᵥ) ∷ ◾)))
... | inj₂ (_ , _ , _ , _ , neq , rs') = inj₂ (_ , _ , _ , _ , neq , (((↦₁₀ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₇ ᵣₑᵥ) ∷ ◾))) ++↦ᵣₑᵥ rs'))
evᵣₑᵥ (c₁ ⨾ c₂) v₃ | inj₂ (_ , _ , _ , _ , neq , rs) = inj₂ (_ , _ , _ , _ , neq , (((↦₁₀ ᵣₑᵥ) ∷ ◾) ++↦ᵣₑᵥ rs))
evᵣₑᵥ {κ = κ} (c₁ ⊕ c₂) (inj₁ x) with evᵣₑᵥ {κ = ☐⊕ c₂ • κ} c₁ x
... | inj₁ (x' , rs) = inj₁ (inj₁ x' , (↦₁₁ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₄ ᵣₑᵥ) ∷ ◾)))
... | inj₂ (_ , _ , _ , _ , neq , rs) = inj₂ (_ , _ , _ , _ , neq , (↦₁₁ ᵣₑᵥ) ∷ rs)
evᵣₑᵥ {κ = κ} (c₁ ⊕ c₂) (inj₂ y) with evᵣₑᵥ {κ = c₁ ⊕☐• κ} c₂ y
... | inj₁ (y' , rs) = inj₁ (inj₂ y' , (↦₁₂ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₅ ᵣₑᵥ) ∷ ◾)))
... | inj₂ (_ , _ , _ , _ , neq , rs) = inj₂ (_ , _ , _ , _ , neq , (↦₁₂ ᵣₑᵥ) ∷ rs)
evᵣₑᵥ {κ = κ} (c₁ ⊗ c₂) (x , y) with evᵣₑᵥ {κ = [ c₁ , x ]⊗☐• κ} c₂ y
... | inj₁ (y' , rs) with evᵣₑᵥ {κ = ☐⊗[ c₂ , y' ]• κ} c₁ x
... | inj₁ (x' , rs') = inj₁ ((x' , y') , (((↦₉ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₈ ᵣₑᵥ) ∷ ◾))) ++↦ᵣₑᵥ (rs' ++↦ᵣₑᵥ ((↦₆ ᵣₑᵥ) ∷ ◾))))
... | inj₂ (_ , _ , _ , _ , neq , rs') = inj₂ (_ , _ , _ , _ , neq , (((↦₉ ᵣₑᵥ) ∷ (rs ++↦ᵣₑᵥ ((↦₈ ᵣₑᵥ) ∷ ◾))) ++↦ᵣₑᵥ rs'))
evᵣₑᵥ (c₁ ⊗ c₂) (x , y) | inj₂ (_ , _ , _ , _ , neq , rs) = inj₂ (_ , _ , _ , _ , neq , ((↦₉ ᵣₑᵥ) ∷ rs))
evᵣₑᵥ (ηₓ v) (v' , ↻) with v ≟ v'
... | yes refl = inj₁ (tt , ((↦η ᵣₑᵥ) ∷ ◾))
... | no neq = inj₂ (_ , _ , _ , _ , neq , ◾)
evᵣₑᵥ (εₓ v) tt = inj₁ ((v , ↻) , ((↦ε₁ {eq = refl} ᵣₑᵥ) ∷ ◾))
-- Backward evaluator for Pi
evalᵣₑᵥ : ∀ {A B} → (c : A ↔ B) → ⟦ B ⟧ → Maybe ⟦ A ⟧
evalᵣₑᵥ c v = [ just ∘ proj₁ , (λ _ → nothing) ]′ (evᵣₑᵥ {κ = ☐} c v)
| 54.141935
| 123
| 0.438275
|
1e4c83e6a38506f76c76d969a3ba260e2c7146b1
| 180
|
agda
|
Agda
|
test/Fail/Issue2446b.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Issue2446b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Issue2446b.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --cubical #-}
module _ where
open import Agda.Builtin.Equality
-- Option --cubical implies --without-K
uip : {A : Set} {x : A} (p : x ≡ x) → p ≡ refl
uip refl = refl
| 20
| 46
| 0.616667
|
19f70dccc2d2e8d66cc5103fefe1bc46e41e7164
| 209
|
agda
|
Agda
|
test/Succeed/Issue4784.agda
|
AntoineAllioux/agda
|
68ec2312961776e415c99d2839e41a92ffe464db
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue4784.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue4784.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --without-K #-}
postulate
A : Set
B : A → Set
@0 T : Set
T = (@0 x : A) → B x
_ : Set₁
_ = (@0 A : Set) → @0 A → (@0 x : A) → Set
data D : Set₁ where
@0 c : (@0 A : Set) → A → (x : A) → D
| 14.928571
| 42
| 0.421053
|
a090623f0948449392d80abeaa727efcdc9a2de0
| 307
|
agda
|
Agda
|
src/data/lib/prim/Agda/Builtin/Float/Properties.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2016-05-20T13:58:52.000Z
|
2016-05-20T13:58:52.000Z
|
src/data/lib/prim/Agda/Builtin/Float/Properties.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T15:49:15.000Z
|
2015-09-15T15:49:15.000Z
|
src/data/lib/prim/Agda/Builtin/Float/Properties.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
{-# OPTIONS --without-K --safe --no-sized-types --no-guardedness
--no-subtyping #-}
module Agda.Builtin.Float.Properties where
open import Agda.Builtin.Float
open import Agda.Builtin.Equality
primitive
primFloatToWord64Injective : ∀ a b → primFloatToWord64 a ≡ primFloatToWord64 b → a ≡ b
| 25.583333
| 88
| 0.723127
|
03014757dd1476190eb784c3f6d664e750355504
| 3,041
|
agda
|
Agda
|
test/Succeed/Issue1366.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Succeed/Issue1366.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Succeed/Issue1366.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
-- Andreas, 2014-11-25, issue reported by Peter Divianski (divipp)
{-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc:10 #-}
-- {-# OPTIONS -v tc.inj:49 #-}
-- {-# OPTIONS -v tc.polarity:49 #-}
-- {-# OPTIONS -v tc.lhs:40 #-}
-- After loading the following Agda code, the last occurrence of 'one' is yellow.
-- Remarks:
-- Probably not an error, but it is against my expectation.
-- The code was obtained by shrinking a more complex one.
-- I guess that the lifting of the local function 'f' happens not as I expect it.
-- The code is quite fragile, the any of following changes fix the problem:
-- - using record ⊤ instead of data Unit
-- - lifting 'f' to be a global function
-- - replacing 'unit' by '_' in the definition of 'f'
-- - giving the implicit argument {v = unit ∷ []} to g
-- Tested with Agda 2.4.2.1 and with the development version of Agda on GitHub (20 Nov 2014)
open import Common.Prelude using (Nat; zero; suc; Unit; unit)
data Vec (A : Set) : Nat → Set where
[] : Vec A zero
_∷_ : ∀ {n} → A → Vec A n → Vec A (suc n) -- n is forced
-- Singleton type
data Sg {A : Set} (x : A) : Set where
sg : Sg x
-- modified length function (counts till 1)
nonNil : ∀ {n} → Vec Unit n → Nat
nonNil [] = zero
nonNil (i ∷ is) = suc (f i) where
f : Unit → Nat
f unit = zero
g : ∀ {n} {v : Vec Unit n} → Sg (nonNil v) → Sg v
g sg = sg
one : Sg (suc zero)
one = sg
test : Sg (unit ∷ [])
test = g one -- `one' is yellow, a meta coming from the forced n
{- Analysis
g :=> Sg (nonNil {_n} _v) -> Sg _v
one :=> Sg (suc zero)
suc zero =?= nonNil {_n} _v
use injectivity
_n := suc _n'
_v := _∷_ {_nv} _i _is
zero =?= f {_nv} {_i} {_is} _i
using injectivity on f creates unsolved, because "forced" meta:
inverting injective function _.f :
({.n : Nat} (i : Unit) (is : Vec Unit .n) → Unit → Nat) for zero
(args = [$ {_32}, $ _33, $ _34, $ _33])
meta patterns [_35, _36, _37]
perm = x0,x1,x2 -> x0,x1,x2
tel = {.n : Nat} (i : Unit) (is : Vec Unit .n)
ps = [[]!{VarP ".n"}, []k(VarP "i"), []k(VarP "is"),
[]r(ConP Common.Prelude.Unit.unit(inductive)[] Nothing [])]
inversion
lhs = [$ {_35}, $ _36, $ _37, $ unit]
rhs = [$ {_32}, $ _33, $ _34, $ _33]
type = ({.n : Nat} (i : Unit) (is : Vec Unit .n) → Unit → Nat)
a = ({.n : Nat} (i : Unit) (is : Vec Unit .n) → Unit → Nat)
v = (_.f)
arg1 = {_35}
arg2 = {_32}
-- Here, the equality check is skipped as n is "forced", so the
-- assignment _35 := _32 does not happen
a = ((i : Unit) (is : Vec Unit _35) → Unit → Nat)
v = (_.f {_35})
arg1 = _36
arg2 = _33
term _36 := _33
term _36 := _33
solving _36 := _33
a = ((is : Vec Unit _35) → Unit → Nat)
v = (_.f {_35} _33)
arg1 = _37
arg2 = _34
term _37 := _34
term _37 := _34
solving _37 := _34
a = (Unit → Nat)
v = (_.f {_35} _33 _34)
arg1 = unit
arg2 = _33
compareTerm unit == _33 : Unit
term _33 := unit
term _33 := unit
solving _33 := unit
compareTerm zero == (_.f {_32} unit _34 unit) : Nat
-}
-- Should work without unsolved metas.
| 29.240385
| 92
| 0.586649
|
35dffb9e40dfa72b817c39135a963ad46fe5ed62
| 814
|
agda
|
Agda
|
test/succeed/SizedQuicksort.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/succeed/SizedQuicksort.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | null | null | null |
test/succeed/SizedQuicksort.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
-- 2014-04-24
module _ where
open import Common.Size
open import Common.Prelude using (Bool; true; false; if_then_else_)
open import Common.Product
-- sized lists
data List A {i} : Set where
[] : List A
_∷_ : {i' : Size< i} (x : A) (xs : List A {i'}) → List A
_++_ : ∀{A} → List A → List A → List A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
partition : ∀{A i} (p : A → Bool) (l : List A {i}) → List A {i} × List A {i}
partition p [] = [] , []
partition p (x ∷ xs) = let l , r = partition p xs in
if p x then (x ∷ l , r) else (l , x ∷ r)
module Sort {A : Set} (_≤_ : A → A → Bool) where
quicksort : ∀{i} → List A {i} → List A
quicksort [] = []
quicksort (x ∷ []) = x ∷ []
quicksort (x ∷ xs) = let x≤ , ≤x = partition (_≤_ x) xs in
quicksort ≤x ++ (x ∷ quicksort x≤)
| 26.258065
| 76
| 0.519656
|
9a0f5d67026ba16684d6c0080155d6aed3064c3c
| 2,415
|
agda
|
Agda
|
Data/Mod.agda
|
esoeylemez/agda-simple
|
d9245e5a8b2e902781736de09bd17e81022f6f13
|
[
"BSD-3-Clause"
] | 1
|
2019-10-07T17:36:42.000Z
|
2019-10-07T17:36:42.000Z
|
Data/Mod.agda
|
esoeylemez/agda-simple
|
d9245e5a8b2e902781736de09bd17e81022f6f13
|
[
"BSD-3-Clause"
] | null | null | null |
Data/Mod.agda
|
esoeylemez/agda-simple
|
d9245e5a8b2e902781736de09bd17e81022f6f13
|
[
"BSD-3-Clause"
] | null | null | null |
-- Copyright: (c) 2016 Ertugrul Söylemez
-- License: BSD3
-- Maintainer: Ertugrul Söylemez <esz@posteo.de>
module Data.Mod where
open import Core
open import Data.Int.Core hiding (module Props)
import Data.Int.Core as ℤ
open import Data.Nat.Core using (ℕ)
import Data.Nat.Core as ℕ
private module ℤP = ℤ.Props
ModEq : ℕ → Equiv ℤ
ModEq n =
record {
_≈_ = _≈_;
refl = λ {x} → 0 , ℤP.+-right-inv x;
sym = λ {x} {y} → sym' x y;
trans = λ {x} {y} {z} → trans' x y z
}
where
infix 4 _≈_
_≈_ : ℤ → ℤ → Set
x ≈ y = ∃ (λ k → x - y ≡ k * pos n)
sym' : ∀ x y → x ≈ y → y ≈ x
sym' x y (k , p) =
neg k ,
(begin
y - x || sym (ℤP.neg-flip x y) ::
neg (x - y) || cong neg p ::
neg (k * pos n) || sym (ℤP.*-assoc -1 k (pos n)) ::
neg k * pos n
qed)
where
open Equiv (PropEq ℤ)
trans' : ∀ x y z → x ≈ y → y ≈ z → x ≈ z
trans' x y z (k1 , p1) (k2 , p2) =
k1 + k2 ,
(begin
x - z || cong (x +_) (sym (ℤP.+-left-id (neg z))) ::
x + (0 - z) || cong (λ a → x + (a - z)) (sym (ℤP.+-left-inv y)) ::
x + (neg y + y - z) || cong (x +_) (ℤP.+-assoc (neg y) y (neg z)) ::
x + (neg y + (y - z)) || sym (ℤP.+-assoc x (neg y) (y + neg z)) ::
x + neg y + (y - z) || cong2 _+_ p1 p2 ::
k1 * pos n + k2 * pos n || sym (ℤP.*-+-right-dist k1 k2 (pos n)) ::
(k1 + k2) * pos n
qed)
where
open Equiv (PropEq ℤ)
module Props (n : ℕ) where
open Equiv (ModEq n) using (_≈_)
open Equiv (PropEq ℤ) hiding (_≈_)
+-cong : ∀ {x1 x2 y1 y2} → x1 ≈ x2 → y1 ≈ y2 → x1 + y1 ≈ x2 + y2
+-cong {x1} {x2} {y1} {y2} (k1 , p1) (k2 , p2) =
k1 + k2 ,
(begin
x1 + y1 - (x2 + y2) || ℤP.+-assoc x1 y1 _ ::
x1 + (y1 - (x2 + y2)) ||
cong (x1 +_) (
y1 - (x2 + y2) || cong (y1 +_) (ℤP.*-+-left-dist -1 x2 y2) ::
y1 + (neg x2 + neg y2) || sym (ℤP.+-assoc y1 (neg x2) (neg y2)) ::
(y1 + neg x2 + neg y2) || cong (_+ neg y2) (ℤP.+-comm y1 (neg x2)) ::
neg x2 + y1 + neg y2 || ℤP.+-assoc (neg x2) y1 _ ::
neg x2 + (y1 + neg y2)
qed) ::
x1 + (neg x2 + (y1 + neg y2)) || sym (ℤP.+-assoc x1 (neg x2) _) ::
x1 - x2 + (y1 - y2) || cong2 _+_ p1 p2 ::
k1 * pos n + k2 * pos n || sym (ℤP.*-+-right-dist k1 k2 (pos n)) ::
(k1 + k2) * pos n
qed)
| 28.75
| 84
| 0.44265
|
203011ed06635edc7194ae5254616ee0cc46eeff
| 2,998
|
agda
|
Agda
|
src/Categories/NaturalTransformation/NaturalIsomorphism/Properties.agda
|
turion/agda-categories
|
ad0f94b6cf18d8a448b844b021aeda58e833d152
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
src/Categories/NaturalTransformation/NaturalIsomorphism/Properties.agda
|
turion/agda-categories
|
ad0f94b6cf18d8a448b844b021aeda58e833d152
|
[
"MIT"
] | null | null | null |
src/Categories/NaturalTransformation/NaturalIsomorphism/Properties.agda
|
turion/agda-categories
|
ad0f94b6cf18d8a448b844b021aeda58e833d152
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
{-# OPTIONS --without-K --safe #-}
module Categories.NaturalTransformation.NaturalIsomorphism.Properties where
open import Level
open import Categories.Category
open import Categories.Category.Instance.Setoids
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Construction.LiftSetoids
open import Categories.NaturalTransformation.NaturalIsomorphism
open import Categories.NaturalTransformation.Properties
import Categories.Morphism as Mor
import Categories.Morphism.Properties as Morₚ
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ e : Level
C D : Category o ℓ e
module _ {F G : Functor C D} (α : NaturalIsomorphism F G) where
private module C = Category C
open Category D
open Mor D
open Functor F
open Functor G renaming (F₀ to G₀; F₁ to G₁)
open NaturalIsomorphism α
-- We can move equations along natural isomorphism.
module _ {A B} {f g : A C.⇒ B} where
push-eq : F₁ f ≈ F₁ g → G₁ f ≈ G₁ g
push-eq hyp = MR.push-eq D FX≅GX (⇒.commute f) (⇒.commute g) hyp
pull-eq : G₁ f ≈ G₁ g → F₁ f ≈ F₁ g
pull-eq hyp = MR.push-eq D (≅.sym FX≅GX) (⇐.commute f) (⇐.commute g) hyp
-- properties of natural isomorphisms over an endofunctor
module _ {F : Endofunctor C} where
private
module C = Category C
module F = Functor F
module MC = Mor C
module _ (α : F ≃ idF) where
open C
open HomReasoning
open F
open MC
open MR C
open Mor C
open Morₚ C
open NaturalIsomorphism α
F≃id-comm₁ : ∀ {A} → ⇒.η (F₀ A) ≈ F₁ (⇒.η A)
F≃id-comm₁ {A} = begin
⇒.η (F₀ A) ≈⟨ introʳ (F-resp-≈ (iso.isoˡ _) ○ identity) ⟩
⇒.η (F₀ A) ∘ F₁ (⇐.η A ∘ ⇒.η A) ≈⟨ refl⟩∘⟨ homomorphism ⟩
⇒.η (F₀ A) ∘ F₁ (⇐.η A) ∘ F₁ (⇒.η A) ≈⟨ cancelˡ (⇒.commute _ ○ iso.isoˡ _) ⟩
F₁ (⇒.η A) ∎
F≃id-comm₂ : ∀ {A} → ⇐.η (F₀ A) ≈ F₁ (⇐.η A)
F≃id-comm₂ {A} = begin
⇐.η (F₀ A) ≈⟨ introˡ (F-resp-≈ (iso.isoˡ _) ○ identity) ⟩
F₁ (⇐.η A ∘ ⇒.η A) ∘ ⇐.η (F₀ A) ≈⟨ homomorphism ⟩∘⟨refl ⟩
(F₁ (⇐.η A) ∘ F₁ (⇒.η A)) ∘ ⇐.η (F₀ A) ≈⟨ cancelʳ (⟺ (⇐.commute _) ○ iso.isoˡ _) ⟩
F₁ (⇐.η A) ∎
F≃id⇒id : ∀ {A} {f : A ⇒ A} → F₁ f ≈ id → f ≈ id
F≃id⇒id {A} {f} eq = Iso⇒Mono (Iso-swap (iso A)) _ _ helper
where helper : ⇐.η A ∘ f ≈ ⇐.η A ∘ id
helper = begin
⇐.η A ∘ f ≈⟨ ⇐.commute f ⟩
F₁ f ∘ ⇐.η A ≈⟨ eq ⟩∘⟨refl ⟩
id ∘ ⇐.η A ≈˘⟨ id-comm ⟩
⇐.η A ∘ id ∎
-- unlift universe level
module _ {c ℓ ℓ′ e} {F G : Functor C (Setoids c ℓ)} (α : LiftSetoids ℓ′ e ∘F F ≃ LiftSetoids ℓ′ e ∘F G) where
open NaturalIsomorphism α
unlift-≃ : F ≃ G
unlift-≃ = record
{ F⇒G = unlift-nat F⇒G
; F⇐G = unlift-nat F⇐G
; iso = λ X → record
{ isoˡ = λ eq → lower (iso.isoˡ X (lift eq))
; isoʳ = λ eq → lower (iso.isoʳ X (lift eq))
}
}
| 31.229167
| 109
| 0.55437
|
0d1dd1d921c8d0957b3eae149425ffc660d8ec8e
| 769
|
agda
|
Agda
|
test/Succeed/Issue1952.agda
|
alex-mckenna/agda
|
78b62cd24bbd570271a7153e44ad280e52ef3e29
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/Succeed/Issue1952.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | null | null | null |
test/Succeed/Issue1952.agda
|
andersk/agda
|
56928ff709dcb931cb9a48c4790e5ed3739e3032
|
[
"BSD-3-Clause"
] | 1
|
2019-03-05T20:02:38.000Z
|
2019-03-05T20:02:38.000Z
|
module _ where
record Structure : Set1 where
infixl 20 _×_
infix 8 _⟶_
infixl 20 _,_
infixr 40 _∘_
infix 5 _~_
field
Type : Set
_×_ : Type → Type → Type
_⟶_ : Type → Type → Set
_∘_ : ∀ {X Y Z} → Y ⟶ Z → X ⟶ Y → X ⟶ Z
_,_ : ∀ {X A B} → X ⟶ A → X ⟶ B → X ⟶ A × B
π₁ : ∀ {A B} → A × B ⟶ A
π₂ : ∀ {A B} → A × B ⟶ B
Op3 : ∀ {X} → X × X × X ⟶ X
_~_ : ∀ {X Y} → X ⟶ Y → X ⟶ Y → Set
record Map {{C : Structure}} {{D : Structure}} : Set1 where
open Structure {{...}}
field
Ty⟦_⟧ : Structure.Type C → Structure.Type D
Tm⟦_⟧ : ∀ {X A} → X ⟶ A → Ty⟦ X ⟧ ⟶ Ty⟦ A ⟧
×-inv : ∀ {X A} → Ty⟦ X ⟧ × Ty⟦ A ⟧ ⟶ Ty⟦ X × A ⟧
⟦Op3⟧ : ∀ {X} → Tm⟦ Op3 {X = X} ⟧ ∘ ×-inv ∘ (×-inv ∘ (π₁ ∘ π₁ , π₂ ∘ π₁) , π₂) ~ Op3
| 22.617647
| 88
| 0.418726
|
0dc711553662ff989fc327b4d531fbcb378c671d
| 8,508
|
agda
|
Agda
|
lib/types/PathSet.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
lib/types/PathSet.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
lib/types/PathSet.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.TLevel
open import lib.types.Pi
open import lib.types.Truncation
-- This module is dedicated to [Trunc ⟨0⟩ (x == y)]
module lib.types.PathSet where
_=₀_ : ∀ {i} {A : Type i} → A → A → Type i
_=₀_ x y = Trunc ⟨0⟩ (x == y)
_=0_ : ∀ {i} {A : Type i} → A → A → Type i
_=0_ = _=₀_
infix 8 _∙₀_ _∙₀'_ -- \.\0
_∙₀_ : ∀ {i} {A : Type i} {x y z : A} → x =₀ y → y =₀ z → x =₀ z
_∙₀_ = Trunc-fmap2 _∙_
_∙₀'_ : ∀ {i} {A : Type i} {x y z : A} → x =₀ y → y =₀ z → x =₀ z
_∙₀'_ = Trunc-fmap2 _∙'_
!₀ : ∀ {i} {A : Type i} {x y : A} → x =₀ y → y =₀ x
!₀ = Trunc-fmap !
idp₀ : ∀ {i} {A : Type i} {a : A} → a =₀ a
idp₀ = [ idp ]
ap₀ : ∀ {i j} {A : Type i} {B : Type j} {x y : A} (f : A → B)
→ x =₀ y → f x =₀ f y
ap₀ f = Trunc-rec Trunc-level ([_] ∘ ap f)
coe₀ : ∀ {i} {A B : Type i} (_ : is-set B) (p : A =₀ B) → A → B
coe₀ B-level = Trunc-rec (→-is-set B-level) coe
transport₀ : ∀ {i j} {A : Type i} (B : A → Type j) {x y : A}
(B-level : is-set (B y)) (p : x =₀ y) → (B x → B y)
transport₀ B B-level p = coe₀ B-level (ap₀ B p)
module _ {i} {A : Type i} where
abstract
∙₀-unit-r : ∀ {x y : A} (q : x =₀ y) → (q ∙₀ idp₀) == q
∙₀-unit-r = Trunc-elim
(λ _ → =-preserves-level ⟨0⟩ Trunc-level)
(λ p → ap [_] $ ∙-unit-r p)
∙₀-unit-l : ∀ {x y : A} (q : x =₀ y) → (idp₀ ∙₀ q) == q
∙₀-unit-l = Trunc-elim
(λ _ → =-preserves-level ⟨0⟩ Trunc-level)
(λ _ → idp)
∙₀-assoc : {x y z t : A} (p : x =₀ y) (q : y =₀ z) (r : z =₀ t)
→ (p ∙₀ q) ∙₀ r == p ∙₀ (q ∙₀ r)
∙₀-assoc = Trunc-elim
(λ _ → Π-is-set λ _ → Π-is-set λ _ → =-preserves-level ⟨0⟩ Trunc-level)
(λ p → Trunc-elim
(λ _ → Π-is-set λ _ → =-preserves-level ⟨0⟩ Trunc-level)
(λ q → Trunc-elim
(λ _ → =-preserves-level ⟨0⟩ Trunc-level)
(λ r → ap [_] $ ∙-assoc p q r)))
!₀-inv-l : {x y : A} (p : x =₀ y) → (!₀ p) ∙₀ p == idp₀
!₀-inv-l = Trunc-elim
(λ _ → =-preserves-level ⟨0⟩ Trunc-level)
(λ p → ap [_] $ !-inv-l p)
!₀-inv-r : {x y : A} (p : x =₀ y) → p ∙₀ (!₀ p) == idp₀
!₀-inv-r = Trunc-elim
(λ _ → =-preserves-level ⟨0⟩ Trunc-level)
(λ p → ap [_] $ !-inv-r p)
∙₀-ap₀ : ∀ {j} {B : Type j} (f : A → B) {x y z : A} (p : x =₀ y) (q : y =₀ z)
→ ap₀ f p ∙₀ ap₀ f q == ap₀ f (p ∙₀ q)
∙₀-ap₀ f = Trunc-elim
(λ _ → Π-is-set λ _ → =-preserves-level ⟨0⟩ Trunc-level)
(λ p → Trunc-elim
(λ _ → =-preserves-level ⟨0⟩ Trunc-level)
(λ q → ap [_] $ ∙-ap f p q))
ap₀-∘ : ∀ {j k} {B : Type j} {C : Type k} (g : B → C) (f : A → B)
{x y : A} (p : x =₀ y) → ap₀ (g ∘ f) p == ap₀ g (ap₀ f p)
ap₀-∘ f g = Trunc-elim
(λ _ → =-preserves-level ⟨0⟩ Trunc-level)
(λ p → ap [_] $ ap-∘ f g p)
coe₀-∙₀ : {B C : Type i} (B-level : is-set B) (C-level : is-set C)
→ (p : A =₀ B) (q : B =₀ C) (a : A)
→ coe₀ C-level (p ∙₀ q) a == coe₀ C-level q (coe₀ B-level p a)
coe₀-∙₀ B-level C-level = Trunc-elim
(λ _ → Π-is-set λ _ → Π-is-set λ _ → =-preserves-level ⟨0⟩ C-level)
(λ p → Trunc-elim
(λ _ → Π-is-set λ _ → =-preserves-level ⟨0⟩ C-level)
(λ q a → coe-∙ p q a))
trans₀-∙₀ : ∀ {j} {B : A → Type j}
→ (B-level : ∀ {a} → is-set (B a))
→ {x y z : A} (p : x =₀ y) (q : y =₀ z) (b : B x)
→ transport₀ B B-level (p ∙₀ q) b
== transport₀ B B-level q (transport₀ B B-level p b)
trans₀-∙₀ B-level = Trunc-elim
(λ _ → Π-is-set λ _ → Π-is-set λ _ → =-preserves-level ⟨0⟩ B-level)
(λ p → Trunc-elim
(λ _ → Π-is-set λ _ → =-preserves-level ⟨0⟩ B-level)
(λ q b → trans-∙ p q b))
trans₀-∙₀' : ∀ {j} {B : A → Type j}
→ (B-level : ∀ {a} → is-set (B a))
→ {x y z : A} (p : x =₀ y) (q : y =₀ z) (b : B x)
→ transport₀ B B-level (p ∙₀' q) b
== transport₀ B B-level q (transport₀ B B-level p b)
trans₀-∙₀' B-level = Trunc-elim
(λ _ → Π-is-set λ _ → Π-is-set λ _ → =-preserves-level ⟨0⟩ B-level)
(λ p → Trunc-elim
(λ _ → Π-is-set λ _ → =-preserves-level ⟨0⟩ B-level)
(λ q b → trans-∙' p q b))
{-
module _ {i} {A : Type i} where
trans-id≡₀cst : {a b c : A} (p : b ≡ c) (q : b ≡₀ a)
→ transport (λ x → x ≡₀ a) p q ≡ proj (! p) ∘₀ q
trans-id≡₀cst refl q = ! $ refl₀-left-unit q
trans-cst≡₀id : {a b c : A} (p : b ≡ c) (q : a ≡₀ b)
→ transport (λ x → a ≡₀ x) p q ≡ q ∘₀ proj p
trans-cst≡₀id refl q = ! $ refl₀-right-unit q
module _ {i} {A : Set i} where
homotopy₀-naturality : ∀ {j} {B : Set j} (f g : A → B)
(p : (x : A) → f x ≡₀ g x) {x y : A} (q : x ≡₀ y)
→ ap₀ f q ∘₀ p y ≡ p x ∘₀ ap₀ g q
homotopy₀-naturality f g p {x} {y} q = π₀-extend
⦃ λ q → ≡-is-set {x = ap₀ f q ∘₀ p y} {y = p x ∘₀ ap₀ g q}
$ π₀-is-set (f x ≡ g y) ⦄
(lemma {x} {y}) q
where
lemma : ∀ {x y : A} (q : x ≡ y) → ap₀ f (proj q) ∘₀ p y ≡ p x ∘₀ ap₀ g (proj q)
lemma refl =
refl₀ ∘₀ p _
≡⟨ refl₀-left-unit (p _) ⟩
p _
≡⟨ ! $ refl₀-right-unit _ ⟩∎
p _ ∘₀ refl₀
∎
-- Loop space commutes with truncation in the sense that
-- τ n (Ω X) = Ω (τ (S n) X)
-- (actually, this is true more generally for paths spaces and we need this
-- level of generality to prove it)
module _ {i} {n : ℕ₋₂} {A : Set i} where
private
to : (x y : A) → (τ n (x ≡ y)) → ((proj {n = S n} x) ≡ (proj y))
to x y = τ-extend-nondep ⦃ τ-is-truncated (S n) A _ _ ⦄ (ap proj)
-- [truncated-path-space (proj x) (proj y)] is [τ n (x ≡ y)]
truncated-path-space : (u v : τ (S n) A) → Type≤ n i
truncated-path-space = τ-extend-nondep
⦃ →-is-truncated (S n) (Type≤-is-truncated n _) ⦄
(λ x → τ-extend-nondep ⦃ Type≤-is-truncated n _ ⦄
(λ y → τ n (x ≡ y) , τ-is-truncated n _))
-- We now extend [to] to the truncation of [A], and this is why we needed to
-- first extend the return type of [to]
to' : (u v : τ (S n) A) → (π₁ (truncated-path-space u v) → u ≡ v)
to' = τ-extend ⦃ λ x → Π-is-truncated (S n) (λ a →
Π-is-truncated (S n) (λ b →
≡-is-truncated (S n)
(τ-is-truncated (S n) A)))⦄
(λ x → τ-extend ⦃ λ t → Π-is-truncated (S n) (λ a →
≡-is-truncated (S n)
(τ-is-truncated (S n) A))⦄
(λ y → to x y))
from'-refl : (u : τ (S n) A) → (π₁ (truncated-path-space u u))
from'-refl = τ-extend ⦃ λ x → truncated-is-truncated-S n
(π₂ (truncated-path-space x x))⦄
(λ x → proj refl)
from' : (u v : τ (S n) A) → (u ≡ v → π₁ (truncated-path-space u v))
from' u .u refl = from'-refl u
from : (x y : A) → (proj {n = S n} x ≡ proj y → τ n (x ≡ y))
from x y p = from' (proj x) (proj y) p
from-to : (x y : A) (p : τ n (x ≡ y)) → from x y (to x y p) ≡ p
from-to x y = τ-extend ⦃ λ _ → ≡-is-truncated n (τ-is-truncated n _)⦄
(from-to' x y) where
from-to' : (x y : A) (p : x ≡ y) → from x y (to x y (proj p)) ≡ proj p
from-to' x .x refl = refl
to'-from' : (u v : τ (S n) A) (p : u ≡ v) → to' u v (from' u v p) ≡ p
to'-from' x .x refl = to'-from'-refl x where
to'-from'-refl : (u : τ (S n) A) → to' u u (from' u u refl) ≡ refl
to'-from'-refl = τ-extend ⦃ λ _ → ≡-is-truncated (S n)
(≡-is-truncated (S n)
(τ-is-truncated (S n) A))⦄
(λ _ → refl)
to-from : (x y : A) (p : proj {n = S n} x ≡ proj y) → to x y (from x y p) ≡ p
to-from x y p = to'-from' (proj x) (proj y) p
τ-path-equiv-path-τ-S : {x y : A} → τ n (x ≡ y) ≃ (proj {n = S n} x ≡ proj y)
τ-path-equiv-path-τ-S {x} {y} =
(to x y , iso-is-eq _ (from x y) (to-from x y) (from-to x y))
module _ where
open import Homotopy.Connected
abstract
connected-has-connected-paths : is-connected (S n) A → (p q : A) → is-connected n (p ≡ q)
connected-has-connected-paths conn p q =
equiv-types-truncated ⟨-2⟩ (τ-path-equiv-path-τ-S ⁻¹) (contr-is-prop conn (proj p) (proj q))
connected-has-all-τ-paths : is-connected (S n) A → (p q : A) → τ n (p ≡ q)
connected-has-all-τ-paths conn p q = π₁ $ connected-has-connected-paths conn p q
-}
| 38.324324
| 100
| 0.461566
|
4bf19d54c99babd440f83b3ac712f847c9096ccb
| 2,138
|
agda
|
Agda
|
Fields/FieldOfFractions/Multiplication.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 4
|
2019-08-08T12:44:19.000Z
|
2022-01-28T06:04:15.000Z
|
Fields/FieldOfFractions/Multiplication.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 14
|
2019-01-06T21:11:59.000Z
|
2020-04-11T11:03:39.000Z
|
Fields/FieldOfFractions/Multiplication.agda
|
Smaug123/agdaproofs
|
0f4230011039092f58f673abcad8fb0652e6b562
|
[
"MIT"
] | 1
|
2021-11-29T13:23:07.000Z
|
2021-11-29T13:23:07.000Z
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Rings.Definition
open import Rings.IntegralDomains.Definition
open import Setoids.Setoids
open import Sets.EquivalenceRelations
module Fields.FieldOfFractions.Multiplication {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} (I : IntegralDomain R) where
open import Fields.FieldOfFractions.Setoid I
fieldOfFractionsTimes : fieldOfFractionsSet → fieldOfFractionsSet → fieldOfFractionsSet
fieldOfFractionsTimes (record { num = a ; denom = b ; denomNonzero = b!=0 }) (record { num = c ; denom = d ; denomNonzero = d!=0 }) = record { num = a * c ; denom = b * d ; denomNonzero = ans }
where
open Setoid S
open Ring R
ans : ((b * d) ∼ Ring.0R R) → False
ans pr with IntegralDomain.intDom I pr
ans pr | f = exFalso (d!=0 (f b!=0))
fieldOfFractionsTimesWellDefined : {a b c d : fieldOfFractionsSet} → (Setoid._∼_ fieldOfFractionsSetoid a c) → (Setoid._∼_ fieldOfFractionsSetoid b d) → (Setoid._∼_ fieldOfFractionsSetoid (fieldOfFractionsTimes a b) (fieldOfFractionsTimes c d))
fieldOfFractionsTimesWellDefined {record { num = a ; denom = b }} {record { num = c ; denom = d }} {record { num = e ; denom = f }} {record { num = g ; denom = h }} af=be ch=dg = need
where
open Setoid S
open Equivalence eq
need : ((a * c) * (f * h)) ∼ ((b * d) * (e * g))
need = transitive (Ring.*WellDefined R reflexive (Ring.*Commutative R)) (transitive (Ring.*Associative R) (transitive (Ring.*WellDefined R (symmetric (Ring.*Associative R)) reflexive) (transitive (Ring.*WellDefined R (Ring.*WellDefined R reflexive ch=dg) reflexive) (transitive (Ring.*Commutative R) (transitive (Ring.*Associative R) (transitive (Ring.*WellDefined R (Ring.*Commutative R) reflexive) (transitive (Ring.*WellDefined R af=be reflexive) (transitive (Ring.*Associative R) (transitive (Ring.*WellDefined R (transitive (symmetric (Ring.*Associative R)) (transitive (Ring.*WellDefined R reflexive (Ring.*Commutative R)) (Ring.*Associative R))) reflexive) (symmetric (Ring.*Associative R)))))))))))
| 71.266667
| 710
| 0.695042
|
37cda3f5f9593e08b8d3bbbdf01c862c65db9336
| 4,205
|
agda
|
Agda
|
test/interaction/Issue2076.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2015-03-28T14:51:03.000Z
|
2015-12-07T20:14:00.000Z
|
test/interaction/Issue2076.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 3
|
2018-11-14T15:31:44.000Z
|
2019-04-01T19:39:26.000Z
|
test/interaction/Issue2076.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1
|
2015-09-15T14:36:15.000Z
|
2015-09-15T14:36:15.000Z
|
-- Andrea(s), 2016-07-06, issue #2076 reported by Andrea
-- This is to test printing of extended lambdas
-- {-# OPTIONS -v tc.cc:60 -v tc.term.exlam:100 -v reify.clause:60 #-}
postulate
A : Set
_,_ : A → A → A
data Unit : Set where
true : Unit
bar : (p : A) (q : A) → Unit → A
bar p q = aux
where
aux : Unit → A
aux true = p , q
foo : (p : A) (q : A) → Unit → A
foo p q = \ { true → p , q}
test : (a : A) → Unit → A
test a = foo a a
-- Normalize me! Expected:
-- λ a → λ { true → a , a }
-- From test/interaction/ExtendedLambdaCase.agda
data Bool : Set where
true false : Bool
data Void : Set where
module M {A : Set}(B : A → Set) where
postulate
Bar : (Bool → Bool) → Set
Test : Set
Test = (y : Bool) → M.Bar {Bool} (λ _ → Void) (λ { true → true ; false → false })
-- Normalize me! Expected:
-- (y : Bool) → M.Bar (λ _ → Void) (λ { true → true ; false → false })
-- .extendedlambda1 y true = true
-- .extendedlambda1 y false = false
-- dropped args: []
-- hidden args: []
-- visible args: [y]
-- Extended lambda inside parameterized module
module PM (X : Set) where
extlam : (p : A) (q : A) → Unit → A
extlam p q = \ { true -> p , q}
-- ConcreteDef extended lambda's implementation ".extendedlambda1" has type:
-- Unit → A
-- dropped args: [X]
-- hidden args: []
-- visible args: [p, q]
-- clauses before compilation .extendedlambda1 p₁ q₁ true = p₁ , q₁
-- , clauseTel =
-- ExtendTel r(El {_getSort = Type (Max [ClosedLevel 1]), unEl = Sort (Type (Max []))}) (Abs "X"
-- ExtendTel r(El {_getSort = Type (Max []), unEl = Def Issue2076.A []}) (Abs "p"
-- ExtendTel r(El {_getSort = Type (Max []), unEl = Def Issue2076.A []}) (Abs "q"
-- EmptyTel)))
-- , namedClausePats =
-- [r(X = VarP (DBPatVar {dbPatVarName = "X", dbPatVarIndex = 2}))
-- ,r(p = VarP (DBPatVar {dbPatVarName = "p", dbPatVarIndex = 1}))
-- ,r(q = VarP (DBPatVar {dbPatVarName = "q", dbPatVarIndex = 0}))
-- ,r(x = ConP Issue2076.Unit.true(inductive)[] (ConPatternInfo {conPRecord = Nothing, conPType = Just r(El {_getSort = Type (Max []), unEl = Def Issue2076.Unit []})}) [])
-- ]
-- , clauseBody = Bind (Abs "h0" Bind (Abs "h1" Bind (Abs "h2" Body (Def Issue2076._,_ [Apply r(Var 1 []),Apply r(Var 0 [])]))))
-- clauses before compilation
-- , clauseTel =
-- ExtendTel r(El {_getSort = Type (Max [ClosedLevel 1]), unEl = Sort (Type (Max []))}) (Abs "X"
-- ExtendTel r(El {_getSort = Type (Max []), unEl = Def Issue2076.A []}) (Abs "p"
-- ExtendTel r(El {_getSort = Type (Max []), unEl = Def Issue2076.A []}) (Abs "q"
-- EmptyTel)))
-- , namedClausePats =
-- [r(X = VarP (DBPatVar {dbPatVarName = "X", dbPatVarIndex = 2}))
-- ,r(p = VarP (DBPatVar {dbPatVarName = "p", dbPatVarIndex = 1}))
-- ,r(q = VarP (DBPatVar {dbPatVarName = "q", dbPatVarIndex = 0}))]
-- , clauseBody = Bind (Abs "h0" Bind (Abs "h1" Bind (Abs "h2"
-- Body (Def Issue2076.PM..extendedlambda1
-- [Apply r(Var 2 []),Apply r(Var 1 []),Apply r(Var 0 [])]))))
-- wrong printing
-- clauses before compilation extlam p q = λ { q₁ true → p₁ , q₁ }
inside : (a : A) → Unit → A
inside a = extlam a a
bla : (a : A) → {!!}
bla a = {!inside a!}
-- Normalization of `inside a` here should yield
-- λ { true → a , a }
ptest : (a : A) → Unit → A
ptest a = PM.extlam Unit a a
-- ptest should normalize to λ a → λ { true → a , a }
module MM (Y : Set) where
open PM Y public
-- Normalizing MM.extlam should yield
-- λ Y p q → λ { true → p , q }
open MM Unit
opentest : (a : A) → Unit → A
opentest a = extlam a a
-- opentest should normalize to λ a → λ { true → a , a }
module Parent (Y : Set) where
module Child (X : Set) where
extlam2 : (p : A) (q : A) → Unit → A
extlam2 p q = \ { true -> p , q}
-- Normalizing Parent.Child.extlam2 should yield
-- λ Y X p q → λ { true → p , q }
open import Agda.Builtin.Nat
data Vec (A : Set) : Nat → Set where
[] : Vec A 0
_∷_ : ∀ {n} → A → Vec A n → Vec A (suc n)
postulate
h : (∀ {n} → Vec Nat n → Nat) → Nat
f : Nat → Nat
f n = h λ where [] → 0
(x ∷ xs) → n
-- Normalising f should yield
-- λ n → h (λ { [] → 0 ; (x ∷ xs) → n })
| 29.612676
| 175
| 0.566468
|
1ef8de03687edac624c588746be8e8fe7858aa93
| 5,101
|
agda
|
Agda
|
HT.agda
|
msullivan/godels-t
|
7412725cf27873b2b23f7e411a236a97dd99ef91
|
[
"MIT"
] | 4
|
2016-12-25T01:52:57.000Z
|
2021-03-22T00:28:03.000Z
|
HT.agda
|
msullivan/godels-t
|
7412725cf27873b2b23f7e411a236a97dd99ef91
|
[
"MIT"
] | null | null | null |
HT.agda
|
msullivan/godels-t
|
7412725cf27873b2b23f7e411a236a97dd99ef91
|
[
"MIT"
] | 3
|
2015-04-26T11:39:14.000Z
|
2021-05-04T22:37:18.000Z
|
module HT where
open import Prelude
open import T
open import SubstTheory
open import DynTheory
module HT where
---- Halting and Hereditary Termination
-- An old comment about lhs-halt
-- Mostly for fun, I didn't want to include "and it halts" as part
-- of the definition of HT for arrows, and I didn't want to define
-- it in terms of evaluating to a lambda and then substituting.
-- This seems to require being able to generate an inhabitant of an
-- arbitrary type as well as a proof that it is HT. The former is
-- easy in T and we accomplish the latter by appealing to all-HT,
-- although we could have also generated the proof along with the
-- inhabitant. This all seems to be handwaved away when doing it on
-- paper. Things get more unclear when in a system where not all
-- types are inhabited; if we know that either a type is inhabited or
-- it is not, then we are fine. But since we are constructive, we would
-- get tripped up by a language like System F in which type inhabitability
-- is undecidable. (Of course, the proof is easy to repair in a number of
-- ways by modifying the definition of HT.)
--
-- When I went to make the system deterministic, I found that I now depended
-- on HT-halts in all-HT, which broke the previous proof technique.
-- I decided that proving the inhabitant we construct is HT would be
-- annoying, so I decided to not bother and went back to hanging onto the
-- proof that arrows halt.
-- Extract that the lhs must halt if its application to something halts.
-- I think this isn't actually useful, though, since to use it we would
-- need to be able to produce an argument to the function.
{-
lhs-halt : {A B : TTp} {e : TCExp (A ⇒ B)} {e' : TCExp A} →
THalts (e $ e') → THalts e
lhs-halt (halts eval-refl ())
lhs-halt (halts (eval-cons (step-app-l S1) E) val) with lhs-halt (halts E val)
... | halts E' val' = halts (eval-cons S1 E') val'
lhs-halt (halts (eval-cons step-beta E) val) = halts eval-refl val-lam
-}
-- I think the induction principle for this datatype is the definition of
-- HTω from http://www.cs.cmu.edu/~rwh/courses/typesys/hw3/hw3-handout.pdf
data HTω : TNat → Set where
HT-z : {e : TNat} → (E : e ~>* zero) → HTω e
HT-s : {e e' : TNat} → (E : e ~>* suc e') → (HT : HTω e') → HTω e
-- definition of hereditary termination
HT : (A : TTp) → TCExp A → Set
HT nat e = THalts e
-- It is kind of ugly to have to hang on to the halting proof.
HT (A ⇒ B) e = THalts e × ((e' : TCExp A) → HT A e' → HT B (e $ e'))
-- proof that hereditary termination implies termination
HT-halts : ∀{A} → (e : TCExp A) → HT A e → THalts e
HT-halts {nat} e h = h
HT-halts {A ⇒ B} _ (h , _) = h
-- extend HT to substitutions
HTΓ : (Γ : Ctx) → TSubst Γ [] → Set
HTΓ Γ γ = ∀{A} (x : A ∈ Γ) -> HT A (γ x)
emptyHTΓ : ∀{γ : TSubst [] []} -> HTΓ [] γ
emptyHTΓ ()
extendHTΓ : ∀{Γ A} {e : TCExp A} {γ : TSubst Γ []} ->
HTΓ Γ γ -> HT A e -> HTΓ (A :: Γ) (extendγ γ e)
extendHTΓ η ht Z = ht
extendHTΓ {_} {_} {e} {γ} η ht {B} (S n) =
ID.coe1 (HT B) (extend-nofail-s γ e n) (η n)
-- head expansion lemma
head-expansion : ∀{A} {e e' : TCExp A} → (e ~>* e') → HT A e' → HT A e
head-expansion {nat} eval (halts eval₁ val) = halts (eval-trans eval eval₁) val
head-expansion {A ⇒ B} eval (halts eval' val , ht-logic) =
halts (eval-trans eval eval') val ,
(λ e' ht → head-expansion (eval-compat step-app-l eval) (ht-logic e' ht))
-- the main theorem
all-HT : ∀{Γ A} {γ : TSubst Γ []} → (e : TExp Γ A) → HTΓ Γ γ
→ HT A (ssubst γ e)
all-HT (var x) η = η x
all-HT (e₁ $ e₂) η with all-HT e₁ η
... | _ , HT₁ = HT₁ (ssubst _ e₂) (all-HT e₂ η)
all-HT zero η = halts eval-refl val-zero
all-HT (suc e) η with all-HT e η
... | halts eval val = halts (eval-compat step-suc eval) (val-suc val)
all-HT {Γ} {A ⇒ B} {γ} (Λ e) η =
(halts eval-refl val-lam) ,
lam-case
where lam-case : (e' : TCExp A) → HT A e' → HT B (Λ (ssubst (liftγ γ) e) $ e')
lam-case e' ht' with all-HT {γ = extendγ γ e'} e (extendHTΓ η ht')
... | ht with eval-step (step-beta {e = (ssubst (liftγ γ) e)})
... | steps-full with combine-subst-noob γ e e'
... | eq = head-expansion steps-full (ID.coe1 (HT B) eq ht)
all-HT {Γ} {A} {γ} (rec e e₀ es) η with all-HT e η
... | halts E val = head-expansion (eval-compat step-rec E) (inner val)
where inner : {n : TNat} → TVal n → HT A (rec n (ssubst γ e₀) (ssubst (liftγ γ) es))
inner val-zero = head-expansion (eval-step step-rec-z) (all-HT e₀ η)
inner (val-suc v) with all-HT es (extendHTΓ η (inner v))
... | ht with eval-step (step-rec-s v)
... | steps with combine-subst-noob γ es _
... | eq = head-expansion steps (ID.coe1 (HT A) eq ht)
-- Prove that all programs in Gödel's System T halt.
all-halt : ∀{A} → (e : TCExp A) → THalts e
all-halt {A} e = HT-halts e (ID.coe1 (HT A) (subid e) (all-HT e (emptyHTΓ {emptyγ})))
open HT public
| 43.228814
| 88
| 0.610665
|
21597be39a8f4ce3046955c64fb3b34c0ec2ba20
| 2,892
|
agda
|
Agda
|
src/Data/Vec/Any.agda
|
tizmd/agda-vector-any
|
1a60f72b9ea1dd61845311ee97dc380aa542b874
|
[
"MIT"
] | null | null | null |
src/Data/Vec/Any.agda
|
tizmd/agda-vector-any
|
1a60f72b9ea1dd61845311ee97dc380aa542b874
|
[
"MIT"
] | null | null | null |
src/Data/Vec/Any.agda
|
tizmd/agda-vector-any
|
1a60f72b9ea1dd61845311ee97dc380aa542b874
|
[
"MIT"
] | null | null | null |
module Data.Vec.Any {a} {A : Set a} where
open import Level using (_⊔_)
open import Relation.Nullary
open import Data.Fin
open import Data.Nat as ℕ hiding (_⊔_)
open import Data.Vec as Vec using (Vec; _∷_; [])
open import Relation.Unary renaming (_⊆_ to _⋐_) using (Decidable)
open import Function.Inverse using (_↔_)
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_)
import Relation.Binary.PropositionalEquality as P
open import Relation.Nullary using (¬_; yes; no)
import Relation.Nullary.Decidable as Dec
open import Data.Empty using (⊥-elim)
open import Data.Product using (∃ ; ,_ )
import Data.List.Any as ListAny
data Any {p}(P : A → Set p) : ∀ {n} → Vec A n → Set (a ⊔ p) where
here : ∀ {n x}{xs : Vec A n} → P x → Any P (x ∷ xs)
there : ∀ {n x}{xs : Vec A n} → Any P xs → Any P (x ∷ xs)
open Any public
map : ∀ {p q} {P : A → Set p} {Q : A → Set q} {n} {xs : Vec A n} →
P ⋐ Q → Any P xs → Any Q xs
map g (here px) = here (g px)
map g (there pxs) = there (map g pxs)
tail : ∀ {p} {P : A → Set p}{x n} {xs : Vec A n} → ¬ P x → Any P (x ∷ xs) → Any P xs
tail ¬px (here px) = ⊥-elim (¬px px)
tail ¬px (there pxs) = pxs
any : ∀ {p} {P : A → Set p} → Decidable P → ∀ {n} → Decidable (Any P {n})
any p [] = no λ()
any p (x ∷ xs) with p x
any p (x ∷ xs) | yes px = yes (here px)
any p (x ∷ xs) | no ¬px = Dec.map′ there (tail ¬px) (any p xs)
index : ∀ {p}{P : A → Set p}{n}{xs : Vec A n} → Any P xs → Fin n
index (here px) = zero
index (there pxs) = suc (index pxs)
satisfied : ∀ {p}{P : A → Set p}{n}{xs : Vec A n} → Any P xs → ∃ P
satisfied (here px) = , px
satisfied (there pxs) = satisfied pxs
Any↔ListAny : ∀ {p}{P : A → Set p}{n}{xs : Vec A n} →
Any P xs ↔ ListAny.Any P (Vec.toList xs)
Any↔ListAny {P = P} = record {
to = P.→-to-⟶ to
; from = P.→-to-⟶ from
; inverse-of = record {
left-inverse-of = left-inverse
; right-inverse-of = right-inverse
}
}
where
to : ∀ {n}{xs : Vec A n} → Any P xs → ListAny.Any P (Vec.toList xs)
to (here px) = ListAny.here px
to (there pxs) = ListAny.there (to pxs)
from : ∀ {n}{xs : Vec A n} → ListAny.Any P (Vec.toList xs) → Any P xs
from {xs = []} ()
from {xs = x ∷ xs} (ListAny.here px) = here px
from {xs = x ∷ xs} (ListAny.there pxs) = there (from pxs)
left-inverse : ∀ {n}{xs : Vec A n}(p : Any P xs) → from (to p) P.≡ p
left-inverse (here px) = P.refl
left-inverse (there pxs) = P.cong there (left-inverse pxs)
right-inverse : ∀ {n}{xs : Vec A n}(p : ListAny.Any P (Vec.toList xs)) → to (from p) P.≡ p
right-inverse {xs = []} ()
right-inverse {xs = x ∷ xs} (ListAny.here px) = P.refl
right-inverse {xs = x ∷ xs} (ListAny.there pxs) = P.cong ListAny.there (right-inverse pxs)
| 38.052632
| 96
| 0.554633
|
3559fbd514ceed955be15a364a3b8670e709407f
| 16,601
|
agda
|
Agda
|
LibraBFT/Impl/Consensus/SafetyRules/SafetyRules.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 4
|
2020-12-16T19:43:41.000Z
|
2021-12-18T19:24:05.000Z
|
LibraBFT/Impl/Consensus/SafetyRules/SafetyRules.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 72
|
2021-02-04T05:04:33.000Z
|
2022-03-25T05:36:11.000Z
|
LibraBFT/Impl/Consensus/SafetyRules/SafetyRules.agda
|
oracle/bft-consensus-agda
|
49f8b1b70823be805d84ffc3157c3b880edb1e92
|
[
"UPL-1.0"
] | 6
|
2020-12-16T19:43:52.000Z
|
2022-02-18T01:04:32.000Z
|
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
------------------------------------------------------------------------------
open import LibraBFT.Base.PKCS
open import LibraBFT.Base.Types
import LibraBFT.Impl.Consensus.ConsensusTypes.Block as Block
import LibraBFT.Impl.Consensus.ConsensusTypes.QuorumCert as QuorumCert
import LibraBFT.Impl.Consensus.ConsensusTypes.Vote as Vote
import LibraBFT.Impl.Consensus.ConsensusTypes.VoteData as VoteData
import LibraBFT.Impl.Consensus.SafetyRules.PersistentSafetyStorage as PersistentSafetyStorage
import LibraBFT.Impl.OBM.Crypto as Crypto
open import LibraBFT.Impl.OBM.Logging.Logging
import LibraBFT.Impl.Types.BlockInfo as BlockInfo
import LibraBFT.Impl.Types.EpochChangeProof as EpochChangeProof
import LibraBFT.Impl.Types.ValidatorSigner as ValidatorSigner
import LibraBFT.Impl.Types.ValidatorVerifier as ValidatorVerifier
open import LibraBFT.Impl.Types.Verifier
import LibraBFT.Impl.Types.Waypoint as Waypoint
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
import LibraBFT.ImplShared.Util.Crypto as Crypto
open import LibraBFT.ImplShared.Util.Util
open import LibraBFT.Prelude
open import Optics.All
------------------------------------------------------------------------------
open import Data.String using (String)
------------------------------------------------------------------------------
module LibraBFT.Impl.Consensus.SafetyRules.SafetyRules where
------------------------------------------------------------------------------
new : PersistentSafetyStorage → Bool → Either ErrLog SafetyRules
new persistentStorage exportConsensusKey = do
pure $ mkSafetyRules
persistentStorage
exportConsensusKey
nothing
nothing
------------------------------------------------------------------------------
signer : SafetyRules → Either ErrLog ValidatorSigner
signer self = maybeS (self ^∙ srValidatorSigner) (Left fakeErr {- error: signer not initialized -}) Right
------------------------------------------------------------------------------
extensionCheck : VoteProposal → Either ErrLog VoteData
extensionCheck voteProposal = do
let proposedBlock = voteProposal ^∙ vpBlock
obmAEP = voteProposal ^∙ vpAccumulatorExtensionProof
-- IMPL-TODO: verify .accumulator_extension_proof().verify ...
in pure
(VoteData.new
(Block.genBlockInfo
proposedBlock
-- OBM-LBFT-DIFF: completely different
(Crypto.obmHashVersion (obmAEP ^∙ aepObmNumLeaves))
(obmAEP ^∙ aepObmNumLeaves)
(voteProposal ^∙ vpNextEpochState))
(proposedBlock ^∙ bQuorumCert ∙ qcCertifiedBlock))
------------------------------------------------------------------------------
constructLedgerInfoM : Block → HashValue → LBFT (Either ErrLog LedgerInfo)
constructLedgerInfoM proposedBlock consensusDataHash = do
let block2 = proposedBlock ^∙ bRound
block1 = proposedBlock ^∙ bQuorumCert ∙ qcCertifiedBlock ∙ biRound
block0 = proposedBlock ^∙ bQuorumCert ∙ qcParentBlock ∙ biRound
commit = (block0 + 1 == block1) ∧ (block1 + 1 == block2)
commitInfo ←
if commit
then (do
let c = proposedBlock ^∙ bQuorumCert ∙ qcParentBlock
logInfo fakeInfo -- lSR (Info3ChainDetected proposedBlock c)
pure c)
else
pure BlockInfo.empty
ok (LedgerInfo∙new commitInfo consensusDataHash)
------------------------------------------------------------------------------
-- PREFERRED ROUND RULE (2nd VOTING RULE) : this avoids voting to commit a conflicting Block
verifyAndUpdatePreferredRoundM : QuorumCert → SafetyData → LBFT (Either ErrLog SafetyData)
verifyAndUpdatePreferredRoundM quorumCert safetyData = do
let preferredRound = safetyData ^∙ sdPreferredRound
oneChainRound = quorumCert ^∙ qcCertifiedBlock ∙ biRound
twoChainRound = quorumCert ^∙ qcParentBlock ∙ biRound
-- LBFT-ALGO v3:p6: "... votes in round k only if the QC inside the k proposal
-- is at least" PreferredRound."
ifD oneChainRound <? preferredRound
then bail fakeErr -- error: incorrect preferred round, QC round does not match preferred round
else do
updated ← case (compare twoChainRound preferredRound) of λ where
GT → do
logInfo fakeInfo -- updated preferred round
pure (safetyData & sdPreferredRound ∙~ twoChainRound)
LT → do
logInfo fakeInfo -- 2-chain round is lower than preferred round, but 1-chain is higher
pure safetyData
EQ →
pure safetyData
ok updated
------------------------------------------------------------------------------
verifyAuthorM : Maybe Author → LBFT (Either ErrLog Unit)
verifyAuthorM author = do
vs ← use (lSafetyRules ∙ srValidatorSigner)
maybeS vs (bail fakeErr) {-(ErrL (here' ["srValidatorSigner", "Nothing"]))-} $ λ validatorSigner →
maybeSD
author
(bail fakeErr) -- (ErrL (here' ["InvalidProposal", "No author found in the proposal"])))
(\a ->
ifD validatorSigner ^∙ vsAuthor /= a
then bail fakeErr -- (ErrL (here' ["InvalidProposal", "Proposal author is not validator signer"]))
else ok unit)
where
here' : List String → List String
here' t = "SafetyRules" ∷ "verifyAuthorM" ∷ t
------------------------------------------------------------------------------
verifyEpochM : Epoch → SafetyData → LBFT (Either ErrLog Unit)
verifyEpochM epoch safetyData =
ifD epoch /= safetyData ^∙ sdEpoch
then bail fakeErr -- incorrect epoch
else ok unit
------------------------------------------------------------------------------
-- INCREASING ROUND RULE (1st VOTING RULE) : ensures voting only ONCE per round
verifyAndUpdateLastVoteRoundM : Round → SafetyData → LBFT (Either ErrLog SafetyData)
verifyAndUpdateLastVoteRoundM round safetyData =
-- LBFT-ALGO v3:p6 : "... votes in round k it if is higher than" LastVotedRound
ifD round >? (safetyData ^∙ sdLastVotedRound)
then ok (safetyData & sdLastVotedRound ∙~ round )
else bail fakeErr -- incorrect last vote round
------------------------------------------------------------------------------
verifyQcM : QuorumCert → LBFT (Either ErrLog Unit)
verifyQcM qc = do
validatorVerifier ← use (lRoundManager ∙ srValidatorVerifier)
pure (QuorumCert.verify qc validatorVerifier) ∙^∙ withErrCtx ("InvalidQuorumCertificate" ∷ [])
------------------------------------------------------------------------------
consensusState : SafetyRules → ConsensusState
consensusState self =
ConsensusState∙new (self ^∙ srPersistentStorage ∙ pssSafetyData)
(self ^∙ srPersistentStorage ∙ pssWaypoint)
------------------------------------------------------------------------------
-- ** NOTE: PAY PARTICULAR ATTENTION TO THIS FUNCTION **
-- ** Because : it is long with lots of branches, so easy to transcribe wrong. **
-- ** And if initialization is wrong, everything is wrong. **
initialize : SafetyRules → EpochChangeProof → Either ErrLog SafetyRules
initialize self proof = do
let waypoint = self ^∙ srPersistentStorage ∙ pssWaypoint
lastLi ← withErrCtx' (here' ("EpochChangeProof.verify" ∷ []))
( EpochChangeProof.verify proof waypoint)
let ledgerInfo = lastLi ^∙ liwsLedgerInfo
epochState ← maybeS (ledgerInfo ^∙ liNextEpochState)
(Left fakeErr) -- ["last ledger info has no epoch state"]
pure
let currentEpoch = self ^∙ srPersistentStorage ∙ pssSafetyData ∙ sdEpoch
if-dec currentEpoch <? epochState ^∙ esEpoch
then (do
waypoint' ← withErrCtx' (here' ("Waypoint.newEpochBoundary" ∷ []))
( Waypoint.newEpochBoundary ledgerInfo)
continue1 (self & srPersistentStorage ∙ pssWaypoint ∙~ waypoint'
& srPersistentStorage ∙ pssSafetyData ∙~
SafetyData∙new (epochState ^∙ esEpoch) {-Round-} 0 {-Round-} 0 nothing)
epochState)
else continue1 self epochState
where
continue2 : SafetyRules → EpochState → Either ErrLog SafetyRules
here' : List String → List String
continue1 : SafetyRules → EpochState → Either ErrLog SafetyRules
continue1 self1 epochState =
continue2 (self1 & srEpochState ?~ epochState) epochState
continue2 self2 epochState = do
let author = self2 ^∙ srPersistentStorage ∙ pssAuthor
maybeS (ValidatorVerifier.getPublicKey (epochState ^∙ esVerifier) author)
(Left fakeErr) -- ["ValidatorNotInSet", lsA author] $
λ expectedKey → do
let currKey = eitherS (signer self2)
(const nothing)
(just ∘ ValidatorSigner.publicKey_USE_ONLY_AT_INIT)
grd‖ currKey == just expectedKey ≔
Right self2
‖ self2 ^∙ srExportConsensusKey ≔ (do
consensusKey ← withErrCtx' (here' ("ValidatorKeyNotFound" ∷ []))
(PersistentSafetyStorage.consensusKeyForVersion
(self2 ^∙ srPersistentStorage) expectedKey)
Right (self2 & srValidatorSigner ?~ ValidatorSigner∙new author consensusKey))
‖ otherwise≔
Left fakeErr -- ["srExportConsensusKey", "False", "NOT IMPLEMENTED"]
here' t = "SafetyRules" ∷ "initialize" ∷ t
------------------------------------------------------------------------------
constructAndSignVoteM-continue0 : VoteProposal → ValidatorSigner → LBFT (Either ErrLog Vote)
constructAndSignVoteM-continue1 : VoteProposal → ValidatorSigner → Block → SafetyData → LBFT (Either ErrLog Vote)
constructAndSignVoteM-continue2 : VoteProposal → ValidatorSigner → Block → SafetyData → LBFT (Either ErrLog Vote)
constructAndSignVoteM : MaybeSignedVoteProposal → LBFT (Either ErrLog Vote)
constructAndSignVoteM maybeSignedVoteProposal = do
vs ← use (lSafetyRules ∙ srValidatorSigner)
maybeS vs (bail fakeErr {- srValidatorSigner is nothing -}) λ validatorSigner → do
let voteProposal = maybeSignedVoteProposal ^∙ msvpVoteProposal
constructAndSignVoteM-continue0 voteProposal validatorSigner
module constructAndSignVoteM-continue0 (voteProposal : VoteProposal) (validatorSigner : ValidatorSigner) where
step₀ : LBFT (Either ErrLog Vote)
step₁ : SafetyData → LBFT (Either ErrLog Vote)
proposedBlock = voteProposal ^∙ vpBlock
step₀ = do
safetyData0 ← use (lPersistentSafetyStorage ∙ pssSafetyData)
verifyEpochM (proposedBlock ^∙ bEpoch) safetyData0 ∙?∙ λ _ → step₁ safetyData0
step₁ safetyData0 = do
caseMD (safetyData0 ^∙ sdLastVote) of λ where
(just vote) →
ifD vote ^∙ vVoteData ∙ vdProposed ∙ biRound == proposedBlock ^∙ bRound
then ok vote
else constructAndSignVoteM-continue1 voteProposal validatorSigner proposedBlock safetyData0
nothing → constructAndSignVoteM-continue1 voteProposal validatorSigner proposedBlock safetyData0
constructAndSignVoteM-continue0 = constructAndSignVoteM-continue0.step₀
module constructAndSignVoteM-continue1
(voteProposal : VoteProposal) (validatorSigner : ValidatorSigner)
(proposedBlock : Block) (safetyData0 : SafetyData) where
step₀ : LBFT (Either ErrLog Vote)
step₁ : LBFT (Either ErrLog Vote)
step₂ : ValidatorVerifier → LBFT (Either ErrLog Vote)
step₃ : LBFT (Either ErrLog Vote)
step₀ =
verifyQcM (proposedBlock ^∙ bQuorumCert) ∙?∙ λ _ → step₁
step₁ = do
validatorVerifier ← use (lRoundManager ∙ srValidatorVerifier)
step₂ validatorVerifier
step₂ validatorVerifier =
pure (Block.validateSignature proposedBlock validatorVerifier) ∙?∙ λ _ → step₃
step₃ =
verifyAndUpdatePreferredRoundM (proposedBlock ^∙ bQuorumCert) safetyData0 ∙?∙
constructAndSignVoteM-continue2 voteProposal validatorSigner proposedBlock
constructAndSignVoteM-continue1 = constructAndSignVoteM-continue1.step₀
module constructAndSignVoteM-continue2 (voteProposal : VoteProposal) (validatorSigner : ValidatorSigner)
(proposedBlock : Block) (safetyData : SafetyData) where
step₀ : LBFT (Either ErrLog Vote)
step₁ : SafetyData → LBFT (Either ErrLog Vote)
step₂ : SafetyData → VoteData → LBFT (Either ErrLog Vote)
step₃ : SafetyData → VoteData → Author → LedgerInfo → LBFT (Either ErrLog Vote)
step₀ =
verifyAndUpdateLastVoteRoundM (proposedBlock ^∙ bBlockData ∙ bdRound) safetyData ∙?∙ step₁
step₁ safetyData1 = do
pssSafetyData-rm ∙= safetyData1
pure (extensionCheck voteProposal) ∙?∙ (step₂ safetyData1)
step₂ safetyData1 voteData = do
let author = validatorSigner ^∙ vsAuthor
constructLedgerInfoM proposedBlock (Crypto.hashVD voteData)
∙^∙ withErrCtx ("" ∷ []) ∙?∙ (step₃ safetyData1 voteData author)
step₃ safetyData1 voteData author ledgerInfo = do
let signature = ValidatorSigner.sign validatorSigner ledgerInfo
vote = Vote.newWithSignature voteData author ledgerInfo signature
pssSafetyData-rm ∙= (safetyData1 & sdLastVote ?~ vote)
logInfo fakeInfo -- InfoUpdateLastVotedRound
ok vote
constructAndSignVoteM-continue2 = constructAndSignVoteM-continue2.step₀
------------------------------------------------------------------------------
signProposalM : BlockData → LBFT (Either ErrLog Block)
signProposalM blockData = do
vs ← use (lSafetyRules ∙ srValidatorSigner)
maybeS vs (bail fakeErr) {-ErrL (here' ["srValidatorSigner", "Nothing"])-} $ λ validatorSigner → do
safetyData ← use (lPersistentSafetyStorage ∙ pssSafetyData)
verifyAuthorM (blockData ^∙ bdAuthor) ∙?∙ λ _ →
verifyEpochM (blockData ^∙ bdEpoch) safetyData ∙?∙ λ _ →
ifD blockData ^∙ bdRound ≤?ℕ safetyData ^∙ sdLastVotedRound
then bail fakeErr
-- {- ErrL (here' [ "InvalidProposal"
-- , "Proposed round is not higher than last voted round "
-- , lsR (blockData ^∙ bdRound), lsR (safetyData ^∙ sdLastVotedRound) ])-}
else do
verifyQcM (blockData ^∙ bdQuorumCert) ∙?∙ λ _ →
verifyAndUpdatePreferredRoundM (blockData ^∙ bdQuorumCert) safetyData ∙?∙ λ safetyData1 → do
pssSafetyData-rm ∙= safetyData1
let signature = ValidatorSigner.sign validatorSigner blockData
ok (Block.newProposalFromBlockDataAndSignature blockData signature)
where
here' : List String → List String
here' t = "SafetyRules" ∷ "signProposalM" ∷ t
------------------------------------------------------------------------------
signTimeoutM : Timeout → LBFT (Either ErrLog Signature)
signTimeoutM timeout = do
vs ← use (lSafetyRules ∙ srValidatorSigner)
maybeS vs (bail fakeErr) {-"srValidatorSigner", "Nothing"-} $ λ validatorSigner → do
safetyData ← use (lPersistentSafetyStorage ∙ pssSafetyData)
verifyEpochM (timeout ^∙ toEpoch) safetyData ∙^∙ withErrCtx (here' []) ∙?∙ λ _ → do
ifD‖ timeout ^∙ toRound ≤? safetyData ^∙ sdPreferredRound ≔
bail fakeErr
--(ErrIncorrectPreferredRound (here []) (timeout ^∙ toRound) (safetyData ^∙ sdPreferredRound))
‖ timeout ^∙ toRound <? safetyData ^∙ sdLastVotedRound ≔
bail fakeErr
--(ErrIncorrectLastVotedRound (here []) (timeout ^∙ toRound) (safetyData ^∙ sdLastVotedRound))
‖ timeout ^∙ toRound >? safetyData ^∙ sdLastVotedRound ≔
verifyAndUpdateLastVoteRoundM (timeout ^∙ toRound) safetyData
∙^∙ withErrCtx (here' [])
∙?∙ (λ safetyData1 → do
pssSafetyData-rm ∙= safetyData1
logInfo fakeInfo -- (InfoUpdateLastVotedRound (timeout ^∙ toRound))
continue validatorSigner)
‖ otherwise≔
continue validatorSigner
where
continue : ValidatorSigner → LBFT (Either ErrLog Signature)
continue validatorSigner = do
let signature = ValidatorSigner.sign validatorSigner timeout
ok signature
here' : List String → List String
here' t = "SafetyRules" ∷ "signTimeoutM" ∷ {-lsTO timeout ∷-} t
| 47.028329
| 114
| 0.633576
|
37ed47d6376022b03efc61b827b59407be258059
| 4,680
|
agda
|
Agda
|
src/Categories/Category/CartesianClosed/Canonical.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/Category/CartesianClosed/Canonical.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
src/Categories/Category/CartesianClosed/Canonical.agda
|
MirceaS/agda-categories
|
58e5ec015781be5413bdf968f7ec4fdae0ab4b21
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category using (Category)
-- A "canonical" presentation of cartesian closed categories.
--
-- This presentation is equivalent to the one in
-- Categories.Category.CartesianClosed but it is easier to work with
-- in some circumstances.
--
-- Here, exponentials are not defined in terms of arbitrary products,
-- but in terms of a family of "canonical" products. Since products
-- are defined only up to isomorphism the choice of product does not
-- matter for the property of being cartesian closed, but working with
-- a fixed choice of representatives simplifies the constructions of
-- some instances of CCCs (e.g. Cats).
module Categories.Category.CartesianClosed.Canonical {o ℓ e} (𝒞 : Category o ℓ e) where
open import Level using (levelOfTerm)
open import Function using (flip)
open import Categories.Category.Cartesian 𝒞 using (Cartesian)
import Categories.Category.CartesianClosed 𝒞 as 𝒞-CC
open import Categories.Object.Exponential 𝒞 using (Exponential)
open import Categories.Object.Product 𝒞
open import Categories.Object.Terminal 𝒞 using (Terminal)
open import Categories.Morphism.Reasoning 𝒞
private
module 𝒞 = Category 𝒞
open Category 𝒞
open HomReasoning
variable
A B C : Obj
f g h f₁ f₂ g₁ g₂ : A ⇒ B
-- A (canonical) cartesian closed category is a category with all
-- (canonical) products and exponentials
--
-- This presentation is equivalent to the one in
-- Categories.Category.CartesianClosed.CartesianClosed.
record CartesianClosed : Set (levelOfTerm 𝒞) where
infixr 7 _×_
infixr 9 _^_
infix 10 ⟨_,_⟩
field
-- Canonical products
⊤ : Obj
_×_ : Obj → Obj → Obj
! : A ⇒ ⊤
π₁ : A × B ⇒ A
π₂ : A × B ⇒ B
⟨_,_⟩ : C ⇒ A → C ⇒ B → C ⇒ A × B
!-unique : (f : A ⇒ ⊤) → ! ≈ f
π₁-comp : π₁ ∘ ⟨ f , g ⟩ ≈ f
π₂-comp : π₂ ∘ ⟨ f , g ⟩ ≈ g
⟨,⟩-unique : ∀ {f g} {h : C ⇒ A × B} →
π₁ ∘ h ≈ f → π₂ ∘ h ≈ g → ⟨ f , g ⟩ ≈ h
-- The above defines canonical finite products, making 𝒞 cartesian.
⊤-terminal : Terminal
⊤-terminal = record { !-unique = !-unique }
×-product : ∀ {A B} → Product A B
×-product {A} {B} =
record { project₁ = π₁-comp; project₂ = π₂-comp; unique = ⟨,⟩-unique }
isCartesian : Cartesian
isCartesian = record
{ terminal = ⊤-terminal
; products = record { product = ×-product }
}
module cartesian = Cartesian isCartesian
open cartesian public
hiding (_×_; π₁; π₂; ⟨_,_⟩)
renaming (⟨⟩-cong₂ to ⟨,⟩-resp-≈)
field
-- Canonical exponentials (w.r.t. the canonical products)
_^_ : Obj → Obj → Obj
eval : B ^ A × A ⇒ B
curry : C × A ⇒ B → C ⇒ B ^ A
eval-comp : eval ∘ (curry f ⁂ id) ≈ f
curry-resp-≈ : f ≈ g → curry f ≈ curry g
curry-unique : eval ∘ (f ⁂ id) ≈ g → f ≈ curry g
-- The above defines canonical exponentials, making 𝒞 cartesian closed.
--
-- NOTE: below we use "⊗" to indicate "non-canonical" products.
^-exponential : ∀ {A B} → Exponential A B
^-exponential {A} {B} = record
{ B^A = B ^ A
; product = ×-product
; eval = eval
; λg = λ C⊗A f → curry (f ∘ repack ×-product C⊗A)
; β = λ {C} C⊗A {g} →
begin
eval ∘ [ C⊗A ⇒ ×-product ] curry (g ∘ repack ×-product C⊗A) ×id
≈˘⟨ pullʳ [ ×-product ⇒ ×-product ]×∘⟨⟩ ⟩
(eval ∘ (curry (g ∘ repack ×-product C⊗A) ⁂ id)) ∘ repack C⊗A ×-product
≈⟨ eval-comp ⟩∘⟨refl ⟩
(g ∘ repack ×-product C⊗A) ∘ repack C⊗A ×-product
≈⟨ cancelʳ (repack∘repack≈id ×-product C⊗A) ⟩
g
∎
; λ-unique = λ {C} C⊗A {g} {f} hyp →
curry-unique (begin
eval ∘ (f ⁂ id)
≈˘⟨ pullʳ [ C⊗A ⇒ ×-product ]×∘⟨⟩ ⟩
(eval ∘ [ C⊗A ⇒ ×-product ] f ×id) ∘ repack ×-product C⊗A
≈⟨ hyp ⟩∘⟨refl ⟩
g ∘ repack ×-product C⊗A
∎)
}
module Equivalence where
open 𝒞-CC using () renaming (CartesianClosed to CartesianClosed′)
-- The two presentations of CCCs are equivalent
fromCanonical : CartesianClosed → CartesianClosed′
fromCanonical cc = record
{ cartesian = CartesianClosed.isCartesian cc
; exp = CartesianClosed.^-exponential cc
}
toCanonical : CartesianClosed′ → CartesianClosed
toCanonical cc = record
{ ⊤ = ⊤
; _×_ = _×_
; ! = !
; π₁ = π₁
; π₂ = π₂
; ⟨_,_⟩ = ⟨_,_⟩
; !-unique = !-unique
; π₁-comp = project₁
; π₂-comp = project₂
; ⟨,⟩-unique = unique
; _^_ = _^_
; eval = eval′
; curry = λg
; eval-comp = β′
; curry-resp-≈ = λ-cong
; curry-unique = λ-unique′
}
where open CartesianClosed′ cc
| 28.711656
| 87
| 0.593162
|
7cac6d54bf13f83e300d8c1192fd499e2e903f5a
| 7,487
|
agda
|
Agda
|
Cubical/Algebra/Algebra/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:29:41.000Z
|
2022-03-05T00:29:41.000Z
|
Cubical/Algebra/Algebra/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/Algebra/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Algebra.Algebra.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
open import Cubical.Foundations.SIP
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.Path
open import Cubical.Data.Sigma
open import Cubical.Structures.Axioms
open import Cubical.Structures.Auto
open import Cubical.Structures.Macro
open import Cubical.Algebra.Module
open import Cubical.Algebra.Ring
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Group
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Algebra.Base
open Iso
private
variable
ℓ ℓ' ℓ'' ℓ''' : Level
module AlgebraTheory (R : Ring ℓ) (A : Algebra R ℓ') where
open RingStr (snd R) renaming (_+_ to _+r_ ; _·_ to _·r_)
open AlgebraStr (A .snd)
0-actsNullifying : (x : ⟨ A ⟩) → 0r ⋆ x ≡ 0a
0-actsNullifying x =
let idempotent-+ = 0r ⋆ x ≡⟨ cong (λ u → u ⋆ x) (sym (RingTheory.0Idempotent R)) ⟩
(0r +r 0r) ⋆ x ≡⟨ ⋆-ldist 0r 0r x ⟩
(0r ⋆ x) + (0r ⋆ x) ∎
in RingTheory.+Idempotency→0 (Algebra→Ring A) (0r ⋆ x) idempotent-+
⋆Dist· : (x y : ⟨ R ⟩) (a b : ⟨ A ⟩) → (x ·r y) ⋆ (a · b) ≡ (x ⋆ a) · (y ⋆ b)
⋆Dist· x y a b = (x ·r y) ⋆ (a · b) ≡⟨ ⋆-rassoc _ _ _ ⟩
a · ((x ·r y) ⋆ b) ≡⟨ cong (a ·_) (⋆-assoc _ _ _) ⟩
a · (x ⋆ (y ⋆ b)) ≡⟨ sym (⋆-rassoc _ _ _) ⟩
x ⋆ (a · (y ⋆ b)) ≡⟨ sym (⋆-lassoc _ _ _) ⟩
(x ⋆ a) · (y ⋆ b) ∎
module AlgebraHoms {R : Ring ℓ} where
open IsAlgebraHom
idAlgebraHom : (A : Algebra R ℓ') → AlgebraHom A A
fst (idAlgebraHom A) x = x
pres0 (snd (idAlgebraHom A)) = refl
pres1 (snd (idAlgebraHom A)) = refl
pres+ (snd (idAlgebraHom A)) x y = refl
pres· (snd (idAlgebraHom A)) x y = refl
pres- (snd (idAlgebraHom A)) x = refl
pres⋆ (snd (idAlgebraHom A)) r x = refl
compIsAlgebraHom : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''}
{g : ⟨ B ⟩ → ⟨ C ⟩} {f : ⟨ A ⟩ → ⟨ B ⟩}
→ IsAlgebraHom (B .snd) g (C .snd)
→ IsAlgebraHom (A .snd) f (B .snd)
→ IsAlgebraHom (A .snd) (g ∘ f) (C .snd)
compIsAlgebraHom {g = g} {f} gh fh .pres0 = cong g (fh .pres0) ∙ gh .pres0
compIsAlgebraHom {g = g} {f} gh fh .pres1 = cong g (fh .pres1) ∙ gh .pres1
compIsAlgebraHom {g = g} {f} gh fh .pres+ x y = cong g (fh .pres+ x y) ∙ gh .pres+ (f x) (f y)
compIsAlgebraHom {g = g} {f} gh fh .pres· x y = cong g (fh .pres· x y) ∙ gh .pres· (f x) (f y)
compIsAlgebraHom {g = g} {f} gh fh .pres- x = cong g (fh .pres- x) ∙ gh .pres- (f x)
compIsAlgebraHom {g = g} {f} gh fh .pres⋆ r x = cong g (fh .pres⋆ r x) ∙ gh .pres⋆ r (f x)
compAlgebraHom : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''}
→ AlgebraHom A B → AlgebraHom B C → AlgebraHom A C
compAlgebraHom f g .fst = g .fst ∘ f .fst
compAlgebraHom f g .snd = compIsAlgebraHom (g .snd) (f .snd)
syntax compAlgebraHom f g = g ∘a f
compIdAlgebraHom : {A B : Algebra R ℓ'} (φ : AlgebraHom A B) → compAlgebraHom (idAlgebraHom A) φ ≡ φ
compIdAlgebraHom φ = AlgebraHom≡ refl
idCompAlgebraHom : {A B : Algebra R ℓ'} (φ : AlgebraHom A B) → compAlgebraHom φ (idAlgebraHom B) ≡ φ
idCompAlgebraHom φ = AlgebraHom≡ refl
compAssocAlgebraHom : {A B C D : Algebra R ℓ'}
(φ : AlgebraHom A B) (ψ : AlgebraHom B C) (χ : AlgebraHom C D)
→ compAlgebraHom (compAlgebraHom φ ψ) χ ≡ compAlgebraHom φ (compAlgebraHom ψ χ)
compAssocAlgebraHom _ _ _ = AlgebraHom≡ refl
module AlgebraEquivs {R : Ring ℓ} where
open IsAlgebraHom
open AlgebraHoms
compIsAlgebraEquiv : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''}
{g : ⟨ B ⟩ ≃ ⟨ C ⟩} {f : ⟨ A ⟩ ≃ ⟨ B ⟩}
→ IsAlgebraEquiv (B .snd) g (C .snd)
→ IsAlgebraEquiv (A .snd) f (B .snd)
→ IsAlgebraEquiv (A .snd) (compEquiv f g) (C .snd)
compIsAlgebraEquiv {g = g} {f} gh fh = compIsAlgebraHom {g = g .fst} {f .fst} gh fh
compAlgebraEquiv : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''}
→ AlgebraEquiv A B → AlgebraEquiv B C → AlgebraEquiv A C
fst (compAlgebraEquiv f g) = compEquiv (f .fst) (g .fst)
snd (compAlgebraEquiv f g) = compIsAlgebraEquiv {g = g .fst} {f = f .fst} (g .snd) (f .snd)
-- the Algebra version of uaCompEquiv
module AlgebraUAFunctoriality {R : Ring ℓ} where
open AlgebraStr
open AlgebraEquivs
Algebra≡ : (A B : Algebra R ℓ') → (
Σ[ p ∈ ⟨ A ⟩ ≡ ⟨ B ⟩ ]
Σ[ q0 ∈ PathP (λ i → p i) (0a (snd A)) (0a (snd B)) ]
Σ[ q1 ∈ PathP (λ i → p i) (1a (snd A)) (1a (snd B)) ]
Σ[ r+ ∈ PathP (λ i → p i → p i → p i) (_+_ (snd A)) (_+_ (snd B)) ]
Σ[ r· ∈ PathP (λ i → p i → p i → p i) (_·_ (snd A)) (_·_ (snd B)) ]
Σ[ s- ∈ PathP (λ i → p i → p i) (-_ (snd A)) (-_ (snd B)) ]
Σ[ s⋆ ∈ PathP (λ i → ⟨ R ⟩ → p i → p i) (_⋆_ (snd A)) (_⋆_ (snd B)) ]
PathP (λ i → IsAlgebra R (q0 i) (q1 i) (r+ i) (r· i) (s- i) (s⋆ i)) (isAlgebra (snd A))
(isAlgebra (snd B)))
≃ (A ≡ B)
Algebra≡ A B = isoToEquiv theIso
where
open Iso
theIso : Iso _ _
fun theIso (p , q0 , q1 , r+ , r· , s- , s⋆ , t) i = p i
, algebrastr (q0 i) (q1 i) (r+ i) (r· i) (s- i) (s⋆ i) (t i)
inv theIso x = cong ⟨_⟩ x , cong (0a ∘ snd) x , cong (1a ∘ snd) x
, cong (_+_ ∘ snd) x , cong (_·_ ∘ snd) x , cong (-_ ∘ snd) x , cong (_⋆_ ∘ snd) x
, cong (isAlgebra ∘ snd) x
rightInv theIso _ = refl
leftInv theIso _ = refl
caracAlgebra≡ : {A B : Algebra R ℓ'} (p q : A ≡ B) → cong ⟨_⟩ p ≡ cong ⟨_⟩ q → p ≡ q
caracAlgebra≡ {A = A} {B = B} p q P =
sym (transportTransport⁻ (ua (Algebra≡ A B)) p)
∙∙ cong (transport (ua (Algebra≡ A B))) helper
∙∙ transportTransport⁻ (ua (Algebra≡ A B)) q
where
helper : transport (sym (ua (Algebra≡ A B))) p ≡ transport (sym (ua (Algebra≡ A B))) q
helper = Σ≡Prop
(λ _ → isPropΣ
(isOfHLevelPathP' 1 (is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ λ _ → is-set (snd B)) _ _)
λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _)
λ _ → isOfHLevelPathP 1 (isPropIsAlgebra _ _ _ _ _ _ _) _ _)
(transportRefl (cong ⟨_⟩ p) ∙ P ∙ sym (transportRefl (cong ⟨_⟩ q)))
uaCompAlgebraEquiv : {A B C : Algebra R ℓ'} (f : AlgebraEquiv A B) (g : AlgebraEquiv B C)
→ uaAlgebra (compAlgebraEquiv f g) ≡ uaAlgebra f ∙ uaAlgebra g
uaCompAlgebraEquiv f g = caracAlgebra≡ _ _ (
cong ⟨_⟩ (uaAlgebra (compAlgebraEquiv f g))
≡⟨ uaCompEquiv _ _ ⟩
cong ⟨_⟩ (uaAlgebra f) ∙ cong ⟨_⟩ (uaAlgebra g)
≡⟨ sym (cong-∙ ⟨_⟩ (uaAlgebra f) (uaAlgebra g)) ⟩
cong ⟨_⟩ (uaAlgebra f ∙ uaAlgebra g) ∎)
| 43.783626
| 102
| 0.555897
|
351d4d726c1a69d13fe00f11ba41910949ebaf45
| 1,173
|
agda
|
Agda
|
old/Type/Functions/Inverse/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
old/Type/Functions/Inverse/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
old/Type/Functions/Inverse/Proofs.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
import Lvl
open import Type
module Type.Functions.Inverse.Proofs {ℓₗ : Lvl.Level}{ℓₒ₁}{ℓₒ₂} {X : Type{ℓₒ₁}} {Y : Type{ℓₒ₂}} where
open import Function.Domains
open import Relator.Equals
open import Type.Functions {ℓₗ}
open import Type.Functions.Inverse {ℓₗ}
open import Type.Properties.Empty
open import Type.Properties.Singleton {ℓₒ₁}{ℓₒ₂}
postulate inv-bijective : ∀{f : X → Y} → ⦃ proof : Bijective(f) ⦄ → Bijective(inv f)
-- inv-bijective {f} ⦃ Bijective.intro(proof) ⦄
private
_≡₁_ = _≡_ {ℓₗ Lvl.⊔ ℓₒ₁}
invᵣ-is-inverseᵣ : (f : X → Y) → ⦃ _ : Surjective(f) ⦄ → ∀{y} → (f(invᵣ f(y)) ≡ y)
invᵣ-is-inverseᵣ f ⦃ Surjective.intro(proof) ⦄ {y} with proof{y}
... | ◊.intro ⦃ Unapply.intro _ ⦃ out ⦄ ⦄ = out
inv-is-inverseᵣ : (f : X → Y) → ⦃ _ : Bijective(f) ⦄ → ∀{y} → (f(inv f(y)) ≡ y)
inv-is-inverseᵣ f ⦃ Bijective.intro(proof) ⦄ {y} with proof{y}
... | IsUnit.intro (Unapply.intro _ ⦃ out ⦄) _ = out
inv-is-inverseₗ : (f : X → Y) → ⦃ _ : Bijective(f) ⦄ → ∀{x} → (inv f(f(x)) ≡₁ x)
inv-is-inverseₗ f ⦃ Bijective.intro(proof) ⦄ {x} with proof{f(x)}
... | IsUnit.intro _ uniqueness with uniqueness {Unapply.intro x ⦃ [≡]-intro ⦄}
... | [≡]-intro = [≡]-intro
| 35.545455
| 101
| 0.624041
|
521b24b60368f68bea4ee11eb0926f0d8aa14d1a
| 872
|
agda
|
Agda
|
src/BasicIO.agda
|
cruhland/agda-editor
|
c5ffd117f6d5a98f7c68a2a6b9be54a150c70945
|
[
"MIT"
] | null | null | null |
src/BasicIO.agda
|
cruhland/agda-editor
|
c5ffd117f6d5a98f7c68a2a6b9be54a150c70945
|
[
"MIT"
] | null | null | null |
src/BasicIO.agda
|
cruhland/agda-editor
|
c5ffd117f6d5a98f7c68a2a6b9be54a150c70945
|
[
"MIT"
] | null | null | null |
module BasicIO where
open import Agda.Builtin.IO public
open import Data.Char
open import Data.List
{-# FOREIGN GHC import Control.Exception #-}
{-# FOREIGN GHC import System.Environment #-}
-- This is easier than using the IO functions in the standard library,
-- but it's technically not as type-safe. And it bypasses the
-- termination checker.
postulate
return : {A : Set} → A → IO A
_>>_ : {A B : Set} → IO A → IO B → IO B
_>>=_ : {A B : Set} → IO A → (A → IO B) → IO B
fail : {A : Set} → List Char → IO A
bracket : {A B C : Set} → IO A → (A → IO B) → (A → IO C) → IO C
getArgs : IO (List (List Char))
{-# COMPILE GHC return = \_ -> return #-}
{-# COMPILE GHC _>>_ = \_ _ -> (>>) #-}
{-# COMPILE GHC _>>=_ = \_ _ -> (>>=) #-}
{-# COMPILE GHC fail = \_ -> fail #-}
{-# COMPILE GHC bracket = \ _ _ _ -> bracket #-}
{-# COMPILE GHC getArgs = getArgs #-}
| 32.296296
| 70
| 0.586009
|
196f6bafc83aaa54033a2126c382be225a13bd64
| 7,513
|
agda
|
Agda
|
IPC/Syntax/Gentzen.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 29
|
2016-07-03T18:51:56.000Z
|
2022-01-01T10:29:18.000Z
|
IPC/Syntax/Gentzen.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | 1
|
2018-06-10T09:11:22.000Z
|
2018-06-10T09:11:22.000Z
|
IPC/Syntax/Gentzen.agda
|
mietek/hilbert-gentzen
|
fcd187db70f0a39b894fe44fad0107f61849405c
|
[
"X11"
] | null | null | null |
-- Intuitionistic propositional calculus.
-- Gentzen-style formalisation of syntax.
-- Simple terms.
module IPC.Syntax.Gentzen where
open import IPC.Syntax.Common public
-- Derivations.
infix 3 _⊢_
data _⊢_ (Γ : Cx Ty) : Ty → Set where
var : ∀ {A} → A ∈ Γ → Γ ⊢ A
lam : ∀ {A B} → Γ , A ⊢ B → Γ ⊢ A ▻ B
app : ∀ {A B} → Γ ⊢ A ▻ B → Γ ⊢ A → Γ ⊢ B
pair : ∀ {A B} → Γ ⊢ A → Γ ⊢ B → Γ ⊢ A ∧ B
fst : ∀ {A B} → Γ ⊢ A ∧ B → Γ ⊢ A
snd : ∀ {A B} → Γ ⊢ A ∧ B → Γ ⊢ B
unit : Γ ⊢ ⊤
boom : ∀ {C} → Γ ⊢ ⊥ → Γ ⊢ C
inl : ∀ {A B} → Γ ⊢ A → Γ ⊢ A ∨ B
inr : ∀ {A B} → Γ ⊢ B → Γ ⊢ A ∨ B
case : ∀ {A B C} → Γ ⊢ A ∨ B → Γ , A ⊢ C → Γ , B ⊢ C → Γ ⊢ C
infix 3 _⊢⋆_
_⊢⋆_ : Cx Ty → Cx Ty → Set
Γ ⊢⋆ ∅ = 𝟙
Γ ⊢⋆ Ξ , A = Γ ⊢⋆ Ξ × Γ ⊢ A
-- Monotonicity with respect to context inclusion.
mono⊢ : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢ A → Γ′ ⊢ A
mono⊢ η (var i) = var (mono∈ η i)
mono⊢ η (lam t) = lam (mono⊢ (keep η) t)
mono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u)
mono⊢ η (pair t u) = pair (mono⊢ η t) (mono⊢ η u)
mono⊢ η (fst t) = fst (mono⊢ η t)
mono⊢ η (snd t) = snd (mono⊢ η t)
mono⊢ η unit = unit
mono⊢ η (boom t) = boom (mono⊢ η t)
mono⊢ η (inl t) = inl (mono⊢ η t)
mono⊢ η (inr t) = inr (mono⊢ η t)
mono⊢ η (case t u v) = case (mono⊢ η t) (mono⊢ (keep η) u) (mono⊢ (keep η) v)
mono⊢⋆ : ∀ {Γ″ Γ Γ′} → Γ ⊆ Γ′ → Γ ⊢⋆ Γ″ → Γ′ ⊢⋆ Γ″
mono⊢⋆ {∅} η ∙ = ∙
mono⊢⋆ {Γ″ , A} η (ts , t) = mono⊢⋆ η ts , mono⊢ η t
-- Shorthand for variables.
v₀ : ∀ {A Γ} → Γ , A ⊢ A
v₀ = var i₀
v₁ : ∀ {A B Γ} → Γ , A , B ⊢ A
v₁ = var i₁
v₂ : ∀ {A B C Γ} → Γ , A , B , C ⊢ A
v₂ = var i₂
-- Reflexivity.
refl⊢⋆ : ∀ {Γ} → Γ ⊢⋆ Γ
refl⊢⋆ {∅} = ∙
refl⊢⋆ {Γ , A} = mono⊢⋆ weak⊆ refl⊢⋆ , v₀
-- Deduction theorem is built-in.
lam⋆ : ∀ {Ξ Γ A} → Γ ⧺ Ξ ⊢ A → Γ ⊢ Ξ ▻⋯▻ A
lam⋆ {∅} = I
lam⋆ {Ξ , B} = lam⋆ {Ξ} ∘ lam
lam⋆₀ : ∀ {Γ A} → Γ ⊢ A → ∅ ⊢ Γ ▻⋯▻ A
lam⋆₀ {∅} = I
lam⋆₀ {Γ , B} = lam⋆₀ ∘ lam
-- Detachment theorem.
det : ∀ {A B Γ} → Γ ⊢ A ▻ B → Γ , A ⊢ B
det t = app (mono⊢ weak⊆ t) v₀
det⋆ : ∀ {Ξ Γ A} → Γ ⊢ Ξ ▻⋯▻ A → Γ ⧺ Ξ ⊢ A
det⋆ {∅} = I
det⋆ {Ξ , B} = det ∘ det⋆ {Ξ}
det⋆₀ : ∀ {Γ A} → ∅ ⊢ Γ ▻⋯▻ A → Γ ⊢ A
det⋆₀ {∅} = I
det⋆₀ {Γ , B} = det ∘ det⋆₀
-- Cut and multicut.
cut : ∀ {A B Γ} → Γ ⊢ A → Γ , A ⊢ B → Γ ⊢ B
cut t u = app (lam u) t
multicut : ∀ {Ξ A Γ} → Γ ⊢⋆ Ξ → Ξ ⊢ A → Γ ⊢ A
multicut {∅} ∙ u = mono⊢ bot⊆ u
multicut {Ξ , B} (ts , t) u = app (multicut ts (lam u)) t
-- Transitivity.
trans⊢⋆ : ∀ {Γ″ Γ′ Γ} → Γ ⊢⋆ Γ′ → Γ′ ⊢⋆ Γ″ → Γ ⊢⋆ Γ″
trans⊢⋆ {∅} ts ∙ = ∙
trans⊢⋆ {Γ″ , A} ts (us , u) = trans⊢⋆ ts us , multicut ts u
-- Contraction.
ccont : ∀ {A B Γ} → Γ ⊢ (A ▻ A ▻ B) ▻ A ▻ B
ccont = lam (lam (app (app v₁ v₀) v₀))
cont : ∀ {A B Γ} → Γ , A , A ⊢ B → Γ , A ⊢ B
cont t = det (app ccont (lam (lam t)))
-- Exchange, or Schönfinkel’s C combinator.
cexch : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C
cexch = lam (lam (lam (app (app v₂ v₀) v₁)))
exch : ∀ {A B C Γ} → Γ , A , B ⊢ C → Γ , B , A ⊢ C
exch t = det (det (app cexch (lam (lam t))))
-- Composition, or Schönfinkel’s B combinator.
ccomp : ∀ {A B C Γ} → Γ ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
ccomp = lam (lam (lam (app v₂ (app v₁ v₀))))
comp : ∀ {A B C Γ} → Γ , B ⊢ C → Γ , A ⊢ B → Γ , A ⊢ C
comp t u = det (app (app ccomp (lam t)) (lam u))
-- Useful theorems in combinatory form.
ci : ∀ {A Γ} → Γ ⊢ A ▻ A
ci = lam v₀
ck : ∀ {A B Γ} → Γ ⊢ A ▻ B ▻ A
ck = lam (lam v₁)
cs : ∀ {A B C Γ} → Γ ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C
cs = lam (lam (lam (app (app v₂ v₀) (app v₁ v₀))))
cpair : ∀ {A B Γ} → Γ ⊢ A ▻ B ▻ A ∧ B
cpair = lam (lam (pair v₁ v₀))
cfst : ∀ {A B Γ} → Γ ⊢ A ∧ B ▻ A
cfst = lam (fst v₀)
csnd : ∀ {A B Γ} → Γ ⊢ A ∧ B ▻ B
csnd = lam (snd v₀)
cboom : ∀ {C Γ} → Γ ⊢ ⊥ ▻ C
cboom = lam (boom v₀)
cinl : ∀ {A B Γ} → Γ ⊢ A ▻ A ∨ B
cinl = lam (inl v₀)
cinr : ∀ {A B Γ} → Γ ⊢ B ▻ A ∨ B
cinr = lam (inr v₀)
ccase : ∀ {A B C Γ} → Γ ⊢ A ∨ B ▻ (A ▻ C) ▻ (B ▻ C) ▻ C
ccase = lam (lam (lam (case v₂ (det v₁) (det v₀))))
-- Closure under context concatenation.
concat : ∀ {A B Γ} Γ′ → Γ , A ⊢ B → Γ′ ⊢ A → Γ ⧺ Γ′ ⊢ B
concat Γ′ t u = app (mono⊢ (weak⊆⧺₁ Γ′) (lam t)) (mono⊢ weak⊆⧺₂ u)
-- Substitution.
[_≔_]_ : ∀ {A B Γ} → (i : A ∈ Γ) → Γ ∖ i ⊢ A → Γ ⊢ B → Γ ∖ i ⊢ B
[ i ≔ s ] var j with i ≟∈ j
[ i ≔ s ] var .i | same = s
[ i ≔ s ] var ._ | diff j = var j
[ i ≔ s ] lam t = lam ([ pop i ≔ mono⊢ weak⊆ s ] t)
[ i ≔ s ] app t u = app ([ i ≔ s ] t) ([ i ≔ s ] u)
[ i ≔ s ] pair t u = pair ([ i ≔ s ] t) ([ i ≔ s ] u)
[ i ≔ s ] fst t = fst ([ i ≔ s ] t)
[ i ≔ s ] snd t = snd ([ i ≔ s ] t)
[ i ≔ s ] unit = unit
[ i ≔ s ] boom t = boom ([ i ≔ s ] t)
[ i ≔ s ] inl t = inl ([ i ≔ s ] t)
[ i ≔ s ] inr t = inr ([ i ≔ s ] t)
[ i ≔ s ] case t u v = case ([ i ≔ s ] t) ([ pop i ≔ mono⊢ weak⊆ s ] u) ([ pop i ≔ mono⊢ weak⊆ s ] v)
[_≔_]⋆_ : ∀ {Ξ A Γ} → (i : A ∈ Γ) → Γ ∖ i ⊢ A → Γ ⊢⋆ Ξ → Γ ∖ i ⊢⋆ Ξ
[_≔_]⋆_ {∅} i s ∙ = ∙
[_≔_]⋆_ {Ξ , B} i s (ts , t) = [ i ≔ s ]⋆ ts , [ i ≔ s ] t
-- Convertibility.
data _⋙_ {Γ : Cx Ty} : ∀ {A} → Γ ⊢ A → Γ ⊢ A → Set where
refl⋙ : ∀ {A} → {t : Γ ⊢ A}
→ t ⋙ t
trans⋙ : ∀ {A} → {t t′ t″ : Γ ⊢ A}
→ t ⋙ t′ → t′ ⋙ t″
→ t ⋙ t″
sym⋙ : ∀ {A} → {t t′ : Γ ⊢ A}
→ t ⋙ t′ → t′ ⋙ t
conglam⋙ : ∀ {A B} → {t t′ : Γ , A ⊢ B}
→ t ⋙ t′
→ lam t ⋙ lam t′
congapp⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ▻ B} → {u u′ : Γ ⊢ A}
→ t ⋙ t′ → u ⋙ u′
→ app t u ⋙ app t′ u′
congpair⋙ : ∀ {A B} → {t t′ : Γ ⊢ A} → {u u′ : Γ ⊢ B}
→ t ⋙ t′ → u ⋙ u′
→ pair t u ⋙ pair t′ u′
congfst⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ∧ B}
→ t ⋙ t′
→ fst t ⋙ fst t′
congsnd⋙ : ∀ {A B} → {t t′ : Γ ⊢ A ∧ B}
→ t ⋙ t′
→ snd t ⋙ snd t′
congboom⋙ : ∀ {C} → {t t′ : Γ ⊢ ⊥}
→ t ⋙ t′
→ boom {C = C} t ⋙ boom t′
conginl⋙ : ∀ {A B} → {t t′ : Γ ⊢ A}
→ t ⋙ t′
→ inl {B = B} t ⋙ inl t′
conginr⋙ : ∀ {A B} → {t t′ : Γ ⊢ B}
→ t ⋙ t′
→ inr {A = A} t ⋙ inr t′
congcase⋙ : ∀ {A B C} → {t t′ : Γ ⊢ A ∨ B} → {u u′ : Γ , A ⊢ C} → {v v′ : Γ , B ⊢ C}
→ t ⋙ t′ → u ⋙ u′ → v ⋙ v′
→ case t u v ⋙ case t′ u′ v′
beta▻⋙ : ∀ {A B} → {t : Γ , A ⊢ B} → {u : Γ ⊢ A}
→ app (lam t) u ⋙ ([ top ≔ u ] t)
eta▻⋙ : ∀ {A B} → {t : Γ ⊢ A ▻ B}
→ t ⋙ lam (app (mono⊢ weak⊆ t) v₀)
beta∧₁⋙ : ∀ {A B} → {t : Γ ⊢ A} → {u : Γ ⊢ B}
→ fst (pair t u) ⋙ t
beta∧₂⋙ : ∀ {A B} → {t : Γ ⊢ A} → {u : Γ ⊢ B}
→ snd (pair t u) ⋙ u
eta∧⋙ : ∀ {A B} → {t : Γ ⊢ A ∧ B}
→ t ⋙ pair (fst t) (snd t)
eta⊤⋙ : ∀ {t : Γ ⊢ ⊤} → t ⋙ unit
beta∨₁⋙ : ∀ {A B C} → {t : Γ ⊢ A} → {u : Γ , A ⊢ C} → {v : Γ , B ⊢ C}
→ case (inl t) u v ⋙ ([ top ≔ t ] u)
beta∨₂⋙ : ∀ {A B C} → {t : Γ ⊢ B} → {u : Γ , A ⊢ C} → {v : Γ , B ⊢ C}
→ case (inr t) u v ⋙ ([ top ≔ t ] v)
eta∨⋙ : ∀ {A B} → {t : Γ ⊢ A ∨ B}
→ t ⋙ case t (inl v₀) (inr v₀)
-- TODO: What about commuting conversions for ∨? What about ⊥?
| 27.122744
| 101
| 0.361773
|
35584f1bff6b91bbec0dd0e9afb8b94c92cbcd69
| 300
|
agda
|
Agda
|
Math/NumberTheory/Summation/Nat.agda
|
rei1024/agda-misc
|
37200ea91d34a6603d395d8ac81294068303f577
|
[
"MIT"
] | 3
|
2020-04-07T17:49:42.000Z
|
2020-04-21T00:03:43.000Z
|
Math/NumberTheory/Summation/Nat.agda
|
rei1024/agda-misc
|
37200ea91d34a6603d395d8ac81294068303f577
|
[
"MIT"
] | null | null | null |
Math/NumberTheory/Summation/Nat.agda
|
rei1024/agda-misc
|
37200ea91d34a6603d395d8ac81294068303f577
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K --safe #-}
module Math.NumberTheory.Summation.Nat where
-- agda-stdlib
open import Algebra
open import Data.Nat.Properties
-- agda-misc
open import Math.NumberTheory.Summation.Generic
-- DO NOT change this line
open MonoidSummation (Semiring.+-monoid *-+-semiring) public
| 21.428571
| 60
| 0.76
|
376a1d61edbaa0ee0fc6ed47fb6dfb74b7758ace
| 10,037
|
agda
|
Agda
|
test/bugs/univ.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | 1
|
2019-11-27T07:26:06.000Z
|
2019-11-27T07:26:06.000Z
|
test/bugs/univ.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
test/bugs/univ.agda
|
np/agda-git-experiment
|
20596e9dd9867166a64470dd24ea68925ff380ce
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --disable-positivity-check #-}
module univ where
import Logic.ChainReasoning
module Chain {A : Set}
( _==_ : A -> A -> Set)
(refl : {x : A} -> x == x)
(trans : {x y z : A} -> x == y -> y == z -> x == z) =
Logic.ChainReasoning.Mono.Homogenous _==_ (\x -> refl) (\x y z -> trans)
data N1 : Set where
T : N1
data N0 : Set where
data Sigma (A:Set)(B : A -> Set) : Set where
Pair : (x:A) -> B x -> Sigma A B
rel : Set -> Set1
rel A = A -> A -> Set
pred : Set -> Set1
pred A = A -> Set
Refl : {A:Set} -> rel A -> Set
Refl {A} R = {x : A} -> R x x
Sym : {A:Set} -> rel A -> Set
Sym {A} R = {x y : A} -> R x y -> R y x
Trans : {A:Set} -> rel A -> Set
Trans {A} R = {x y z : A} -> R x y -> R y z -> R x z
Map : (A:Set) -> rel A -> (B:Set) -> rel B -> pred (A -> B)
Map A _R_ B _S_ f = {x y : A} -> x R y -> f x S f y
postulate
N : Set
_=N_ : rel N
refN : Refl _=N_
symN : Sym _=N_
transN : Trans _=N_
-- mutual inductive recursive definition of S and the functions _=S_, El, eq, and all the
-- proofs on these functions
mutual
infix 40 _==_ _=S_
infixr 80 _<<_
data S : Set where
nat : S
pi : (A:S) -> (f:El A -> S) -> Map (El A) _==_ S _=S_ f -> S
_=S'_ : rel S
nat =S' nat = N1
nat =S' pi A f pf = N0
pi _ _ _ =S' nat = N0
pi A F pF =S' pi B G pG =
Sigma (A =S B) \ A=B -> (x : El B) -> F (A=B << x) =S G x
data _=S_ (A B : S) : Set where
eqS : A =S' B -> A =S B
El' : S -> Set
El' nat = N
El' (pi A F pF) =
Sigma ((x : El A) -> El (F x))
\f -> {x y : El A}(x=y : x == y) ->
f x == pF x=y << f y
data El (A : S) : Set where
el : El' A -> El A
_=='_ : {A : S} -> rel (El A)
_=='_ {nat} (el x) (el y) = x =N y
_=='_ {pi A F pF} (el (Pair f pf)) (el (Pair g pg)) =
(x : El A) -> f x == g x
data _==_ {A : S}(x y : El A) : Set where
eq : x ==' y -> x == y
_<<_ : {A B : S} -> A =S B -> El B -> El A
_<<_ {nat} {nat} p x = x
_<<_ {pi A F pF} {pi B G pG} (eqS (Pair A=B F=G)) (el (Pair g pg)) =
el (Pair f (\{x}{y} -> pf x y))
where
B=A = symS A=B
F=Gc : (x : El A) -> F x =S G (B=A << x)
F=Gc x =
transS (transS refS (symS (pF (castlem A=B (symS A=B) x))))
(F=G (symS A=B << x))
-- chain> F x
-- === F (A=B << B=A << x) by symS (pF (castlem A=B B=A x))
-- === G (B=A << x) by F=G (B=A << x)
-- where
-- open module C = Chain _=S_ refS transS
f : (x : El A) -> El (F x)
f x = F=Gc x << g (B=A << x)
pf : (x y : El A)(p : x == y) -> f x == pF p << f y
pf x y x=y = trans fx=ccgy ccgy=cfy
where
cx = B=A << x
cy = B=A << y
cx=cy : cx == cy
cx=cy = p<< B=A x=y
cgy : El (G cx)
cgy = pG cx=cy << g cy
gx=gy : g cx == cgy
gx=gy = pg cx=cy
ccgy : El (F x)
ccgy = F=Gc x << cgy
fx=ccgy : f x == ccgy
fx=ccgy = p<< (F=Gc x) gx=gy
cfy : El (F x)
cfy = pF x=y << f y
ccgy=cfy : ccgy == cfy
ccgy=cfy = castlem2 (F=Gc x) (pF x=y)
(pG cx=cy) (F=Gc y)
(g cy)
p<< : {A B : S}(A=B : A =S B) -> Map (El B) _==_ (El A) _==_ (_<<_ A=B)
p<< {nat}{nat} _ x=y = x=y
p<< {pi A F pF} {pi B G pG} (eqS (Pair A=B F=G))
{el (Pair f pf)} {el (Pair g pg)} (eq f=g) = eq cf=cg
where
open module C = Logic.ChainReasoning.Mono.Homogenous _=S_ (\x -> refS) (\x y z -> transS)
B=A = symS A=B
F=Gc : (x : El A) -> F x =S G (B=A << x)
F=Gc x =
chain> F x
=== F (A=B << B=A << x) by symS (pF (castlem A=B B=A x))
=== G (B=A << x) by F=G _
cf=cg : (x : El A) -> F=Gc x << f (B=A << x)
== F=Gc x << g (B=A << x)
cf=cg x = p<< (F=Gc x) (f=g (B=A << x))
p<< {nat} {pi _ _ _} (eqS ()) _
p<< {pi _ _ _} {nat} (eqS ()) _
refS : Refl _=S_
refS {nat} = eqS T
refS {pi A F pF} = eqS (Pair refS \(x : El A) -> pF (castref refS x))
transS : Trans _=S_
transS {nat}{nat}{nat} p q = p
transS {nat}{nat}{pi _ _ _} _ (eqS ())
transS {nat}{pi _ _ _}{_} (eqS ()) _
transS {pi _ _ _}{nat}{_} (eqS ()) _
transS {pi _ _ _}{pi _ _ _}{nat} _ (eqS ())
transS {pi A F pF}{pi B G pG}{pi C H pH}
(eqS (Pair A=B F=G)) (eqS (Pair B=C G=H)) =
eqS (Pair A=C F=H)
where
open module C = Chain _=S_ refS transS
A=C = transS A=B B=C
F=H : (x : El C) -> F (A=C << x) =S H x
F=H x =
chain> F (A=C << x)
=== F (A=B << B=C << x) by symS (pF (casttrans A=B B=C A=C x))
=== G (B=C << x) by F=G (B=C << x)
=== H x by G=H x
symS : Sym _=S_
symS {nat}{nat} p = p
symS {pi _ _ _}{nat} (eqS ())
symS {nat}{pi _ _ _} (eqS ())
symS {pi A F pF}{pi B G pg} (eqS (Pair A=B F=G)) = eqS (Pair B=A G=F)
where
open module C = Chain _=S_ refS transS
B=A = symS A=B
G=F : (x : El A) -> G (B=A << x) =S F x
G=F x =
chain> G (B=A << x)
=== F (A=B << B=A << x) by symS (F=G (B=A << x))
=== F x by pF (castlem A=B B=A x)
pfi : {A B : S}(p q : A =S B)(x : El B) -> p << x == q << x
pfi {nat}{nat} _ _ x = ref
pfi {nat}{pi _ _ _} (eqS ()) _ _
pfi {pi _ _ _}{nat} (eqS ()) _ _
pfi {pi A F pF}{pi B G pG} (eqS (Pair A=B1 F=G1)) (eqS (Pair A=B2 F=G2))
(el (Pair f pf)) = eq f1=f2
where
B=A1 = symS A=B1
B=A2 = symS A=B2
f1=f2 : (x : El A) -> _ << f (B=A1 << x) == _ << f (B=A2 << x)
f1=f2 x =
chain> _ << f (B=A1 << x)
=== _ << _ << f (B=A2 << x) by p<< _ lem2
=== _ << f (B=A2 << x) by casttrans _ _ _ _
where
open module C = Chain _==_ (ref {F x}) (trans {F x})
lem1 : B=A1 << x == B=A2 << x
lem1 = pfi B=A1 B=A2 x
lem2 : f (B=A1 << x) == _ << f (B=A2 << x)
lem2 = pf lem1
castref : {A : S}(p : A =S A)(x : El A) -> p << x == x
castref {nat} p x = ref
castref {pi A F pF} (eqS (Pair A=A F=F)) (el (Pair f pf)) = eq cf=f
where
A=A' = symS A=A
cf=f : (x : El A) -> _ << f (A=A' << x) == f x
cf=f x =
chain> Fx=Fcx << f (A=A' << x)
=== Fx=Fcx << _ << f x by p<< Fx=Fcx lem2
=== refS << f x by casttrans _ _ _ (f x)
=== f x by castref _ (f x)
where
Fx=Fcx = _
open module C = Chain _==_ (ref {F x}) (trans {F x})
lem1 : A=A' << x == x
lem1 = castref A=A' x
lem2 : f (A=A' << x) == _ << f x
lem2 = pf lem1
casttrans : {A B C : S}(A=B : A =S B)(B=C : B =S C)(A=C : A =S C)(x : El C) ->
A=B << B=C << x == A=C << x
casttrans {nat}{nat}{nat} _ _ _ x = ref
casttrans {nat}{nat}{pi _ _ _} _ (eqS ()) _ _
casttrans {nat}{pi _ _ _}{_} (eqS ()) _ _ _
casttrans {pi _ _ _}{nat}{_} (eqS ()) _ _ _
casttrans {pi _ _ _}{pi _ _ _}{nat} _ (eqS ()) _ _
casttrans {pi A F pF}{pi B G pG}{pi C H pH}
(eqS (Pair A=B F=G))(eqS (Pair B=C G=H))(eqS (Pair A=C F=H))
(el (Pair h ph)) = eq prf
where
B=A = symS A=B
C=B = symS B=C
C=A = symS A=C
prf : (x : El A) -> _ << _ << h (C=B << B=A << x) == _ << h (C=A << x)
prf x =
chain> Fx=Gcx << Gcx=Hccx << h (C=B << B=A << x)
=== Fx=Hccx << h (C=B << B=A << x) by casttrans _ _ _ _
=== Fx=Hccx << _ << h (C=A << x) by p<< _ (ph (casttrans C=B B=A C=A x))
=== Fx=Hcx << h (C=A << x) by casttrans _ _ _ _
where
Fx=Gcx = _
Gcx=Hccx = _
Fx=Hccx = transS (lemF=Gc A=B pF pG F=G _)
(lemF=Gc B=C pG pH G=H _)
Fx=Hcx = _
open module C = Chain _==_ (ref {F x}) (trans {F x})
lemF=Gc : {A B : S}(A=B : A =S B)
{F : El A -> S}(pF : Map (El A) _==_ S _=S_ F)
{G : El B -> S}(pG : Map (El B) _==_ S _=S_ G)
(F=G : (x : El B) -> F (A=B << x) =S G x)
(x : El A) -> F x =S G (symS A=B << x)
lemF=Gc A=B {F} pF {G} pG F=G x =
chain> F x
=== F (A=B << B=A << x) by symS (pF (castlem A=B B=A x))
=== G (B=A << x) by F=G _
where
open module C = Chain _=S_ refS transS
B=A = symS A=B
castlem : {A B : S}(p : A =S B)(q : B =S A)(x : El A) ->
p << q << x == x
castlem {A}{B} p q x =
chain> p << q << x
=== refS << x by casttrans p q refS x
=== x by castref refS x
where open module C = Chain _==_ (ref {A}) (trans {A})
castlem2 : {A B B' C : S}(A=B : A =S B)(A=B' : A =S B')(B=C : B =S C)(B'=C : B' =S C)
(x : El C) ->
A=B << B=C << x == A=B' << B'=C << x
castlem2 {A} p p' q q' x =
chain> p << q << x
=== transS p q << x by casttrans _ _ _ x
=== transS p' q' << x by pfi _ _ _
=== p' << q' << x by sym (casttrans _ _ _ x)
where open module C = Chain _==_ (ref {A}) (trans {A})
ref : {A:S} -> Refl {El A} _==_
ref {nat} {el n} = eq refN
ref {pi A F pF}{el (Pair f pf)} = eq f=f
where
f=f : (x : El A) -> f x == f x
f=f x = ref
trans : {A:S} -> Trans {El A} _==_
trans {nat}{el x}{el y}{el z} (eq p) (eq q) = eq (transN p q)
trans {pi A F pF}{el (Pair f pf)}{el (Pair g pg)}{el (Pair h ph)}
(eq f=g)(eq g=h) = eq f=h
where
f=h : (x : El A) -> f x == h x
f=h x = trans (f=g x) (g=h x)
sym : {A:S} -> Sym {El A} _==_
sym {nat}{el x}{el y} (eq p) = eq (symN p)
sym {pi A F pF}{el (Pair f pf)}{el (Pair g pg)}
(eq f=g) = eq g=f
where
g=f : (x : El A) -> g x == f x
g=f x = sym (f=g x)
| 30.883077
| 95
| 0.399323
|
236010f509616d05866b812877e743ce9bd1507c
| 227
|
agda
|
Agda
|
examples/ATPHint.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 10
|
2015-09-03T20:54:16.000Z
|
2019-12-03T13:44:25.000Z
|
examples/ATPHint.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 121
|
2015-01-25T13:22:12.000Z
|
2018-04-22T06:01:44.000Z
|
examples/ATPHint.agda
|
asr/apia
|
a66c5ddca2ab470539fd68c42c4fbd45f720d682
|
[
"MIT"
] | 4
|
2016-05-10T23:06:19.000Z
|
2016-08-03T03:54:55.000Z
|
-- The ATP pragma with the role <hint> can be used with functions.
module ATPHint where
postulate
D : Set
data _≡_ (x : D) : D → Set where
refl : x ≡ x
sym : ∀ {m n} → m ≡ n → n ≡ m
sym refl = refl
{-# ATP hint sym #-}
| 16.214286
| 66
| 0.585903
|
0d28dff3ae40258bb543b3046254c414b63f4c48
| 79
|
agda
|
Agda
|
examples/outdated-and-incorrect/Alonzo/PrintNat.agda
|
mdimjasevic/agda
|
8fb548356b275c7a1e79b768b64511ae937c738b
|
[
"BSD-3-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
examples/outdated-and-incorrect/Alonzo/PrintNat.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
examples/outdated-and-incorrect/Alonzo/PrintNat.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
module PrintNat where
import PreludeShow
open PreludeShow
mainS = showNat 42
| 11.285714
| 21
| 0.822785
|
35e9c7d666401a3a803003196d562eda9027a19e
| 216
|
agda
|
Agda
|
Cubical/HITs/Truncation.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/HITs/Truncation.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
Cubical/HITs/Truncation.agda
|
borsiemir/cubical
|
cefeb3669ffdaea7b88ae0e9dd258378418819ca
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.Truncation where
open import Cubical.HITs.Truncation.Base public
open import Cubical.HITs.Truncation.Properties public
import Cubical.HITs.Truncation.FromNegOne
| 27
| 53
| 0.810185
|
59eb2740be8beb0b25afd080cb0b0cda0d96df51
| 5,092
|
agda
|
Agda
|
lib/types/Group.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
lib/types/Group.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
lib/types/Group.agda
|
danbornside/HoTT-Agda
|
1695a7f3dc60177457855ae846bbd86fcd96983e
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Pi
module lib.types.Group where
record GroupStructure {i} (El : Type i) --(El-level : has-level ⟨0⟩ El)
: Type i where
constructor group-structure
field
ident : El
inv : El → El
comp : El → El → El
unitl : ∀ a → comp ident a == a
unitr : ∀ a → comp a ident == a
assoc : ∀ a b c → comp (comp a b) c == comp a (comp b c)
invl : ∀ a → (comp (inv a) a) == ident
invr : ∀ a → (comp a (inv a)) == ident
record Group i : Type (lsucc i) where
constructor group
field
El : Type i
El-level : has-level ⟨0⟩ El
group-struct : GroupStructure El
open GroupStructure group-struct public
⊙El : Σ (Type i) (λ A → A)
⊙El = (El , ident)
Group₀ : Type (lsucc lzero)
Group₀ = Group lzero
is-abelian : ∀ {i} → Group i → Type i
is-abelian G = (a b : Group.El G) → Group.comp G a b == Group.comp G b a
module _ where
open GroupStructure
abstract
group-structure= : ∀ {i} {A : Type i} (pA : has-level ⟨0⟩ A)
{id₁ id₂ : A} {inv₁ inv₂ : A → A} {comp₁ comp₂ : A → A → A}
→ ∀ {unitl₁ unitl₂} → ∀ {unitr₁ unitr₂} → ∀ {assoc₁ assoc₂}
→ ∀ {invr₁ invr₂} → ∀ {invl₁ invl₂}
→ (id₁ == id₂) → (inv₁ == inv₂) → (comp₁ == comp₂)
→ Path {A = GroupStructure A}
(group-structure id₁ inv₁ comp₁ unitl₁ unitr₁ assoc₁ invl₁ invr₁)
(group-structure id₂ inv₂ comp₂ unitl₂ unitr₂ assoc₂ invl₂ invr₂)
group-structure= pA {id₁ = id₁} {inv₁ = inv₁} {comp₁ = comp₁} idp idp idp =
ap5 (group-structure id₁ inv₁ comp₁)
(prop-has-all-paths (Π-level (λ _ → pA _ _)) _ _)
(prop-has-all-paths (Π-level (λ _ → pA _ _)) _ _)
(prop-has-all-paths
(Π-level (λ _ → Π-level (λ _ → Π-level (λ _ → pA _ _)))) _ _)
(prop-has-all-paths (Π-level (λ _ → pA _ _)) _ _)
(prop-has-all-paths (Π-level (λ _ → pA _ _)) _ _)
where
ap5 : ∀ {j} {C D E F G H : Type j}
{c₁ c₂ : C} {d₁ d₂ : D} {e₁ e₂ : E} {f₁ f₂ : F} {g₁ g₂ : G}
(f : C → D → E → F → G → H)
→ (c₁ == c₂) → (d₁ == d₂) → (e₁ == e₂) → (f₁ == f₂) → (g₁ == g₂)
→ f c₁ d₁ e₁ f₁ g₁ == f c₂ d₂ e₂ f₂ g₂
ap5 f idp idp idp idp idp = idp
↓-group-structure= : ∀ {i} {A B : Type i}
(A-level : has-level ⟨0⟩ A)
{GS : GroupStructure A} {HS : GroupStructure B} (p : A == B)
→ (ident GS == ident HS [ (λ C → C) ↓ p ])
→ (inv GS == inv HS [ (λ C → C → C) ↓ p ])
→ (comp GS == comp HS [ (λ C → C → C → C) ↓ p ])
→ GS == HS [ GroupStructure ↓ p ]
↓-group-structure= A-level idp = group-structure= A-level
module _ {i} (G : Group i) where
private
open Group G
_⊙_ = comp
group-inv-unique-l : (g h : El) → (g ⊙ h == ident) → inv h == g
group-inv-unique-l g h p =
inv h =⟨ ! (unitl (inv h)) ⟩
ident ⊙ inv h =⟨ ! p |in-ctx (λ w → w ⊙ inv h) ⟩
(g ⊙ h) ⊙ inv h =⟨ assoc g h (inv h) ⟩
g ⊙ (h ⊙ inv h) =⟨ invr h |in-ctx (λ w → g ⊙ w) ⟩
g ⊙ ident =⟨ unitr g ⟩
g ∎
group-inv-unique-r : (g h : El) → (g ⊙ h == ident) → inv g == h
group-inv-unique-r g h p =
inv g =⟨ ! (unitr (inv g)) ⟩
inv g ⊙ ident =⟨ ! p |in-ctx (λ w → inv g ⊙ w) ⟩
inv g ⊙ (g ⊙ h) =⟨ ! (assoc (inv g) g h) ⟩
(inv g ⊙ g) ⊙ h =⟨ invl g |in-ctx (λ w → w ⊙ h) ⟩
ident ⊙ h =⟨ unitl h ⟩
h ∎
group-inv-ident : inv ident == ident
group-inv-ident =
group-inv-unique-l ident ident (unitl ident)
group-inv-comp : (g₁ g₂ : El) → inv (g₁ ⊙ g₂) == inv g₂ ⊙ inv g₁
group-inv-comp g₁ g₂ =
group-inv-unique-r (g₁ ⊙ g₂) (inv g₂ ⊙ inv g₁) $
(g₁ ⊙ g₂) ⊙ (inv g₂ ⊙ inv g₁)
=⟨ assoc g₁ g₂ (inv g₂ ⊙ inv g₁) ⟩
g₁ ⊙ (g₂ ⊙ (inv g₂ ⊙ inv g₁))
=⟨ ! (assoc g₂ (inv g₂) (inv g₁)) |in-ctx (λ w → g₁ ⊙ w) ⟩
g₁ ⊙ ((g₂ ⊙ inv g₂) ⊙ inv g₁)
=⟨ invr g₂ |in-ctx (λ w → g₁ ⊙ (w ⊙ inv g₁)) ⟩
g₁ ⊙ (ident ⊙ inv g₁)
=⟨ unitl (inv g₁) |in-ctx (λ w → g₁ ⊙ w) ⟩
g₁ ⊙ inv g₁
=⟨ invr g₁ ⟩
ident ∎
group-inv-inv : (g : El) → inv (inv g) == g
group-inv-inv g = group-inv-unique-r (inv g) g (invl g)
group-cancel-l : (g : El) {h k : El} → g ⊙ h == g ⊙ k → h == k
group-cancel-l g {h} {k} p =
h =⟨ ! (unitl h) ⟩
ident ⊙ h =⟨ ap (λ w → w ⊙ h) (! (invl g)) ⟩
(inv g ⊙ g) ⊙ h =⟨ assoc (inv g) g h ⟩
inv g ⊙ (g ⊙ h) =⟨ ap (λ w → inv g ⊙ w) p ⟩
inv g ⊙ (g ⊙ k) =⟨ ! (assoc (inv g) g k) ⟩
(inv g ⊙ g) ⊙ k =⟨ ap (λ w → w ⊙ k) (invl g) ⟩
ident ⊙ k =⟨ unitl k ⟩
k ∎
group-cancel-r : (g : El) {h k : El} → h ⊙ g == k ⊙ g → h == k
group-cancel-r g {h} {k} p =
h =⟨ ! (unitr h) ⟩
h ⊙ ident =⟨ ap (λ w → h ⊙ w) (! (invr g)) ⟩
h ⊙ (g ⊙ inv g) =⟨ ! (assoc h g (inv g)) ⟩
(h ⊙ g) ⊙ inv g =⟨ ap (λ w → w ⊙ inv g) p ⟩
(k ⊙ g) ⊙ inv g =⟨ assoc k g (inv g) ⟩
k ⊙ (g ⊙ inv g) =⟨ ap (λ w → k ⊙ w) (invr g) ⟩
k ⊙ ident =⟨ unitr k ⟩
k ∎
| 36.113475
| 79
| 0.465632
|
a0a9173e15cbac47451a37938f53011897d99e13
| 325
|
agda
|
Agda
|
test/succeed/IndexInference.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | null | null | null |
test/succeed/IndexInference.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | null | null | null |
test/succeed/IndexInference.agda
|
asr/agda-kanso
|
aa10ae6a29dc79964fe9dec2de07b9df28b61ed5
|
[
"MIT"
] | null | null | null |
module IndexInference where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data Vec (A : Set) : Nat -> Set where
[] : Vec A zero
_::_ : {n : Nat} -> A -> Vec A n -> Vec A (suc n)
infixr 40 _::_
-- The length of the vector can be inferred from the pattern.
foo : Vec Nat _ -> Nat
foo (a :: b :: c :: []) = c
| 19.117647
| 61
| 0.563077
|
8b46bd2149b15838629b2db02b33b0f5015f9316
| 1,206
|
agda
|
Agda
|
Data/List/Setoid.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | 6
|
2020-04-07T17:58:13.000Z
|
2022-02-05T06:53:22.000Z
|
Data/List/Setoid.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
Data/List/Setoid.agda
|
Lolirofle/stuff-in-agda
|
70f4fba849f2fd779c5aaa5af122ccb6a5b271ba
|
[
"MIT"
] | null | null | null |
module Data.List.Setoid where
import Lvl
open import Data.List
open import Data.List.Equiv
open import Data.List.Relation.Quantification
open import Logic.Propositional
open import Structure.Operator
open import Structure.Setoid
open import Structure.Relator.Equivalence
import Structure.Relator.Names as Names
open import Structure.Relator.Properties
open import Type
private variable ℓ ℓₑ ℓₚ : Lvl.Level
private variable T : Type{ℓ}
instance
List-equiv : ⦃ Equiv{ℓₑ}(T) ⦄ → Equiv(List(T))
List-equiv = intro (AllElements₂(_≡_)) ⦃ intro ⦃ intro refl ⦄ ⦃ intro sym ⦄ ⦃ intro trans ⦄ ⦄ where
refl : Names.Reflexivity(AllElements₂(_≡_))
refl{∅} = ∅
refl{x ⊰ l} = reflexivity(_≡_) ⊰ refl{l}
sym : Names.Symmetry(AllElements₂(_≡_))
sym ∅ = ∅
sym (p ⊰ ps) = symmetry(_≡_) p ⊰ sym ps
trans : Names.Transitivity(AllElements₂(_≡_))
trans ∅ ∅ = ∅
trans (p ⊰ ps) (q ⊰ qs) = (transitivity(_≡_) p q) ⊰ (trans ps qs)
instance
List-equiv-extensionality : ⦃ equiv : Equiv{ℓₑ}(T) ⦄ → Extensionality(List-equiv ⦃ equiv ⦄)
List-equiv-extensionality ⦃ equiv ⦄ = intro ⦃ binaryOperator = intro(_⊰_) ⦄ (\{(p ⊰ _) → p}) (\{(_ ⊰ pl) → pl}) \()
| 33.5
| 117
| 0.657546
|
43e3d849151e016f0afb29e09f8fe2a588946efb
| 9,001
|
agda
|
Agda
|
Cubical/Structures/Relational/Auto.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | null | null | null |
Cubical/Structures/Relational/Auto.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/Structures/Relational/Auto.agda
|
cangiuli/cubical
|
d103ec455d41cccf9b13a4803e7d3cf462e00067
|
[
"MIT"
] | null | null | null |
{-
Macros (autoDesc, AutoStructure, AutoEquivStr, autoUnivalentStr) for automatically generating structure definitions.
For example:
autoDesc (λ (X : Type₀) → X → X × ℕ) ↦ function+ var (var , constant ℕ)
We prefer to use the constant structure whenever possible, e.g., [autoDesc (λ (X : Type₀) → ℕ → ℕ)]
is [constant (ℕ → ℕ)] rather than [function (constant ℕ) (constant ℕ)].
Writing [auto* (λ X → ⋯)] doesn't seem to work, but [auto* (λ (X : Type ℓ) → ⋯)] does.
-}
{-# OPTIONS --cubical --no-exact-split --safe #-}
module Cubical.Structures.Relational.Auto where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.Sigma
open import Cubical.Data.Nat
open import Cubical.Data.List
open import Cubical.Data.Bool
open import Cubical.Data.Maybe
open import Cubical.Structures.Relational.Macro as Macro
import Agda.Builtin.Reflection as R
-- Magic number
private
FUEL = 10000
-- Mark a constant type with a proof it is a set
abstract
Const[_] : ∀ {ℓ} → hSet ℓ → Type ℓ
Const[ A ] = A .fst
-- Some reflection utilities
private
_>>=_ = R.bindTC
_<|>_ = R.catchTC
_>>_ : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} → R.TC A → R.TC B → R.TC B
f >> g = f >>= λ _ → g
infixl 4 _>>=_ _>>_ _<|>_
varg : ∀ {ℓ} {A : Type ℓ} → A → R.Arg A
varg = R.arg (R.arg-info R.visible R.relevant)
tLevel = R.def (quote Level) []
tType : R.Term → R.Term
tType ℓ = R.def (quote Type) [ varg ℓ ]
thSet : R.Term → R.Term
thSet ℓ = R.def (quote hSet) [ varg ℓ ]
tPosRelDesc : R.Term → R.Term
tPosRelDesc ℓ = R.def (quote PosRelDesc) [ varg ℓ ]
tRelDesc : R.Term → R.Term
tRelDesc ℓ = R.def (quote RelDesc) [ varg ℓ ]
func : (ℓ ℓ' : Level) → Type (ℓ-suc (ℓ-max ℓ ℓ'))
func ℓ ℓ' = Type ℓ → Type ℓ'
tStruct : R.Term → R.Term → R.Term
tStruct ℓ ℓ' = R.def (quote func) (varg ℓ ∷ varg ℓ' ∷ [])
newMeta = R.checkType R.unknown
-- We try to build a descriptor by unifying the provided structure with combinators we're aware of. We
-- redefine the structure combinators as the *Shape terms below so that we don't depend on the specific way
-- these are defined in other files (order of implicit arguments and so on); the syntactic analysis that goes
-- on here means that we would get mysterious errors if those changed.
private
constantShape : ∀ {ℓ'} (ℓ : Level) (A : hSet ℓ') → (Type ℓ → Type ℓ')
constantShape _ A _ = Const[ A ]
pointedShape : (ℓ : Level) → Type ℓ → Type ℓ
pointedShape _ X = X
productShape : ∀ {ℓ₀ ℓ₁} (ℓ : Level)
→ (Type ℓ → Type ℓ₀) → (Type ℓ → Type ℓ₁) → Type ℓ → Type (ℓ-max ℓ₀ ℓ₁)
productShape _ A₀ A₁ X = A₀ X × A₁ X
paramShape : ∀ {ℓ₀ ℓ'} (ℓ : Level)
→ Type ℓ' → (Type ℓ → Type ℓ₀) → Type ℓ → Type (ℓ-max ℓ' ℓ₀)
paramShape _ A A₀ X = A → A₀ X
functionShape : ∀ {ℓ₀ ℓ₁} (ℓ : Level)
→ (Type ℓ → Type ℓ₀) → (Type ℓ → Type ℓ₁) → Type ℓ → Type (ℓ-max ℓ₀ ℓ₁)
functionShape _ A₀ A₁ X = A₀ X → A₁ X
maybeShape : ∀ {ℓ₀} (ℓ : Level)
→ (Type ℓ → Type ℓ₀) → Type ℓ → Type ℓ₀
maybeShape _ A₀ X = Maybe (A₀ X)
private
-- Build transport structure descriptor from a function [t : Type ℓ → Type ℓ']
buildPosRelDesc : ℕ → R.Term → R.Term → R.Term → R.TC R.Term
buildPosRelDesc zero ℓ ℓ' t = R.typeError (R.strErr "Ran out of fuel! at \n" ∷ R.termErr t ∷ [])
buildPosRelDesc (suc fuel) ℓ ℓ' t =
tryConstant t <|> tryPointed t <|> tryProduct t <|> tryMaybe t <|>
R.typeError (R.strErr "Can't automatically generate a positive structure for\n" ∷ R.termErr t ∷ [])
where
tryConstant : R.Term → R.TC R.Term
tryConstant t =
newMeta (thSet ℓ') >>= λ A →
R.unify t (R.def (quote constantShape) (varg ℓ ∷ varg A ∷ [])) >>
R.returnTC (R.con (quote PosRelDesc.constant) (varg A ∷ []))
tryPointed : R.Term → R.TC R.Term
tryPointed t =
R.unify t (R.def (quote pointedShape) (varg ℓ ∷ [])) >>
R.returnTC (R.con (quote PosRelDesc.var) [])
tryProduct : R.Term → R.TC R.Term
tryProduct t =
newMeta tLevel >>= λ ℓ₀ →
newMeta tLevel >>= λ ℓ₁ →
newMeta (tStruct ℓ ℓ₀) >>= λ A₀ →
newMeta (tStruct ℓ ℓ₁) >>= λ A₁ →
R.unify t (R.def (quote productShape) (varg ℓ ∷ varg A₀ ∷ varg A₁ ∷ [])) >>
buildPosRelDesc fuel ℓ ℓ₀ A₀ >>= λ d₀ →
buildPosRelDesc fuel ℓ ℓ₁ A₁ >>= λ d₁ →
R.returnTC (R.con (quote PosRelDesc._,_) (varg d₀ ∷ varg d₁ ∷ []))
tryMaybe : R.Term → R.TC R.Term
tryMaybe t =
newMeta tLevel >>= λ ℓ₀ →
newMeta (tStruct ℓ ℓ₀) >>= λ A₀ →
R.unify t (R.def (quote maybeShape) (varg ℓ ∷ varg A₀ ∷ [])) >>
buildPosRelDesc fuel ℓ ℓ₀ A₀ >>= λ d₀ →
R.returnTC (R.con (quote PosRelDesc.maybe) (varg d₀ ∷ []))
autoPosRelDesc' : R.Term → R.Term → R.TC Unit
autoPosRelDesc' t hole =
R.inferType hole >>= λ H →
newMeta tLevel >>= λ ℓ →
newMeta tLevel >>= λ ℓ' →
R.unify (tPosRelDesc ℓ) H >>
R.checkType t (tStruct ℓ ℓ') >>
buildPosRelDesc FUEL ℓ ℓ' t >>= R.unify hole
-- Build structure descriptor from a function [t : Type ℓ → Type ℓ']
buildRelDesc : ℕ → R.Term → R.Term → R.Term → R.TC R.Term
buildRelDesc zero ℓ ℓ' t = R.typeError (R.strErr "Ran out of fuel! at \n" ∷ R.termErr t ∷ [])
buildRelDesc (suc fuel) ℓ ℓ' t =
tryConstant t <|> tryPointed t <|> tryProduct t <|> tryParam t <|> tryFunction t <|>
tryMaybe t <|>
R.typeError (R.strErr "Can't automatically generate a structure for\n" ∷ R.termErr t ∷ [])
where
tryConstant : R.Term → R.TC R.Term
tryConstant t =
newMeta (thSet ℓ') >>= λ A →
R.unify t (R.def (quote constantShape) (varg ℓ ∷ varg A ∷ [])) >>
R.returnTC (R.con (quote RelDesc.constant) (varg A ∷ []))
tryPointed : R.Term → R.TC R.Term
tryPointed t =
R.unify t (R.def (quote pointedShape) (varg ℓ ∷ [])) >>
R.returnTC (R.con (quote RelDesc.var) [])
tryProduct : R.Term → R.TC R.Term
tryProduct t =
newMeta tLevel >>= λ ℓ₀ →
newMeta tLevel >>= λ ℓ₁ →
newMeta (tStruct ℓ ℓ₀) >>= λ A₀ →
newMeta (tStruct ℓ ℓ₁) >>= λ A₁ →
R.unify t (R.def (quote productShape) (varg ℓ ∷ varg A₀ ∷ varg A₁ ∷ [])) >>
buildRelDesc fuel ℓ ℓ₀ A₀ >>= λ d₀ →
buildRelDesc fuel ℓ ℓ₁ A₁ >>= λ d₁ →
R.returnTC (R.con (quote RelDesc._,_) (varg d₀ ∷ varg d₁ ∷ []))
tryParam : R.Term → R.TC R.Term
tryParam t =
newMeta (tType R.unknown) >>= λ A →
newMeta tLevel >>= λ ℓ₀ →
newMeta (tStruct ℓ ℓ₀) >>= λ A₀ →
R.unify t (R.def (quote paramShape) (varg ℓ ∷ varg A ∷ varg A₀ ∷ [])) >>
buildRelDesc fuel ℓ ℓ₀ A₀ >>= λ d₀ →
R.returnTC (R.con (quote RelDesc.param) (varg A ∷ varg d₀ ∷ []))
tryFunction : R.Term → R.TC R.Term
tryFunction t =
newMeta tLevel >>= λ ℓ₀ →
newMeta tLevel >>= λ ℓ₁ →
newMeta (tStruct ℓ ℓ₀) >>= λ A₀ →
newMeta (tStruct ℓ ℓ₁) >>= λ A₁ →
R.unify t (R.def (quote functionShape) (varg ℓ ∷ varg A₀ ∷ varg A₁ ∷ [])) >>
buildPosRelDesc fuel ℓ ℓ₀ A₀ >>= λ d₀ →
buildRelDesc fuel ℓ ℓ₁ A₁ >>= λ d₁ →
R.returnTC (R.con (quote RelDesc.function+) (varg d₀ ∷ varg d₁ ∷ []))
tryMaybe : R.Term → R.TC R.Term
tryMaybe t =
newMeta tLevel >>= λ ℓ₀ →
newMeta (tStruct ℓ ℓ₀) >>= λ A₀ →
R.unify t (R.def (quote maybeShape) (varg ℓ ∷ varg A₀ ∷ [])) >>
buildRelDesc fuel ℓ ℓ₀ A₀ >>= λ d₀ →
R.returnTC (R.con (quote RelDesc.maybe) (varg d₀ ∷ []))
autoRelDesc' : R.Term → R.Term → R.TC Unit
autoRelDesc' t hole =
R.inferType hole >>= λ H →
newMeta tLevel >>= λ ℓ →
newMeta tLevel >>= λ ℓ' →
R.unify (tRelDesc ℓ) H >>
R.checkType t (tStruct ℓ ℓ') >>
buildRelDesc FUEL ℓ ℓ' t >>= R.unify hole
macro
-- (Type ℓ → Type ℓ₁) → PosRelDesc ℓ
autoPosRelDesc : R.Term → R.Term → R.TC Unit
autoPosRelDesc = autoPosRelDesc'
-- (S : Type ℓ → Type ℓ₁) → RelDesc ℓ
autoRelDesc : R.Term → R.Term → R.TC Unit
autoRelDesc = autoRelDesc'
-- (S : Type ℓ → Type ℓ₁) → (Type ℓ → Type ℓ₁)
-- Sanity check: should be the identity
AutoStructure : R.Term → R.Term → R.TC Unit
AutoStructure t hole =
newMeta (tRelDesc R.unknown) >>= λ d →
R.unify hole (R.def (quote RelMacroStructure) [ varg d ]) >>
autoRelDesc' t d
-- (S : Type ℓ → Type ℓ₁) → StrRel S _
AutoRelStr : R.Term → R.Term → R.TC Unit
AutoRelStr t hole =
newMeta (tRelDesc R.unknown) >>= λ d →
R.unify hole (R.def (quote RelMacroRelStr) [ varg d ]) >>
autoRelDesc' t d
-- (S : Type ℓ → Type ℓ₁) → SuitableStrRel S (AutoStrRel S)
autoSuitableRel : R.Term → R.Term → R.TC Unit
autoSuitableRel t hole =
newMeta (tRelDesc R.unknown) >>= λ d →
R.unify hole (R.def (quote relMacroSuitableRel) [ varg d ]) >>
autoRelDesc' t d
-- (S : Type ℓ → Type ℓ₁) → StrRelMatchesEquiv (AutoRelStr S) (AutoEquivStr S)
autoMatchesEquiv : R.Term → R.Term → R.TC Unit
autoMatchesEquiv t hole =
newMeta (tRelDesc R.unknown) >>= λ d →
R.unify hole (R.def (quote relMacroMatchesEquiv) [ varg d ]) >>
autoRelDesc' t d
| 35.718254
| 116
| 0.603266
|
ad665eab19827a4368e0063bbd2525af9b9848c7
| 213
|
agda
|
Agda
|
test/Fail/Erased-cubical-Open-public/Cubical.agda
|
cagix/agda
|
cc026a6a97a3e517bb94bafa9d49233b067c7559
|
[
"BSD-2-Clause"
] | 1,989
|
2015-01-09T23:51:16.000Z
|
2022-03-30T18:20:48.000Z
|
test/Fail/Erased-cubical-Open-public/Cubical.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 4,066
|
2015-01-10T11:24:51.000Z
|
2022-03-31T21:14:49.000Z
|
test/Fail/Erased-cubical-Open-public/Cubical.agda
|
Seanpm2001-languages/agda
|
9911f73061e21a87fad76c662463257afe02c861
|
[
"BSD-2-Clause"
] | 371
|
2015-01-03T14:04:08.000Z
|
2022-03-30T19:00:30.000Z
|
{-# OPTIONS --cubical #-}
module Erased-cubical-Open-public.Cubical where
-- It instantiates and exports code from
-- Erased-cubical-Open-public.Erased.
open import Erased-cubical-Open-public.Erased Set public
| 23.666667
| 56
| 0.769953
|
30435bded91d95ba8cd89facd35a5ddbce4d6e0f
| 7,494
|
agda
|
Agda
|
Examples/Expression.agda
|
nad/pretty
|
b956803ba90b6c5f57bbbaab01bb18485d948492
|
[
"MIT"
] | null | null | null |
Examples/Expression.agda
|
nad/pretty
|
b956803ba90b6c5f57bbbaab01bb18485d948492
|
[
"MIT"
] | null | null | null |
Examples/Expression.agda
|
nad/pretty
|
b956803ba90b6c5f57bbbaab01bb18485d948492
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- Simple expressions
------------------------------------------------------------------------
-- Several examples based on Matsuda and Wang's "FliPpr: A Prettier
-- Invertible Printing System".
{-# OPTIONS --guardedness #-}
module Examples.Expression where
open import Algebra
open import Codata.Musical.Notation
open import Data.List
open import Data.List.Properties
open import Data.Product
open import Data.Unit
open import Function
open import Relation.Binary.PropositionalEquality as P using (_≡_; refl)
private
module LM {A : Set} = Monoid (++-monoid A)
open import Examples.Identifier
import Grammar.Infinite as Grammar
import Pretty
open import Renderer
open import Utilities
-- Very simple expressions.
module Expression₁ where
data Expr : Set where
one : Expr
sub : Expr → Expr → Expr
module _ where
open Grammar
mutual
expr : Grammar Expr
expr = term
∣ sub <$> ♯ expr
<⊛ whitespace ⋆
<⊛ string′ "-"
<⊛ whitespace ⋆
⊛ term
term : Grammar Expr
term = one <$ string′ "1"
∣ string′ "("
⊛> whitespace ⋆
⊛> ♯ expr
<⊛ whitespace ⋆
<⊛ string′ ")"
open Pretty
one-doc : Doc term one
one-doc = left (<$ text)
mutual
expr-printer : Pretty-printer expr
expr-printer one = left one-doc
expr-printer (sub e₁ e₂) =
group (right (<$> expr-printer e₁ <⊛-tt
nest 2 line⋆ <⊛ text <⊛ space ⊛
nest 2 (term-printer e₂)))
term-printer : Pretty-printer term
term-printer one = one-doc
term-printer e =
right (text ⊛> nil-⋆ ⊛> expr-printer e <⊛ nil-⋆ <⊛ text)
example : Expr
example = sub (sub one one) (sub one one)
test₁ : render 80 (expr-printer example) ≡ "1 - 1 - (1 - 1)"
test₁ = refl
test₂ : render 11 (expr-printer example) ≡ "1 - 1\n - (1 - 1)"
test₂ = refl
test₃ : render 8 (expr-printer example) ≡ "1 - 1\n - (1\n - 1)"
test₃ = refl
-- Expression₁.expr does not accept final whitespace. The grammar
-- below does.
module Expression₂ where
open Expression₁ using (Expr; one; sub; example)
module _ where
open Grammar
mutual
expr : Grammar Expr
expr = term
∣ sub <$> ♯ expr <⊛ symbol′ "-" ⊛ term
term : Grammar Expr
term = one <$ symbol′ "1"
∣ symbol′ "(" ⊛> ♯ expr <⊛ symbol′ ")"
private
-- A manual proof of Trailing-whitespace expr (included for
-- illustrative purposes; not used below).
Trailing-whitespace″ : ∀ {A} → Grammar A → Set₁
Trailing-whitespace″ g =
∀ {x s s₁ s₂} →
x ∈ g · s₁ → s ∈ whitespace ⋆ · s₂ → x ∈ g · s₁ ++ s₂
tw′-whitespace : Trailing-whitespace′ (whitespace ⋆)
tw′-whitespace ⋆-[]-sem w = _ , w
tw′-whitespace (⋆-+-sem (⊛-sem {s₁ = s₁} (<$>-sem p) q)) w
with tw′-whitespace q w
... | _ , r = _ , cast (P.sym $ LM.assoc s₁ _ _)
(⋆-+-sem (⊛-sem (<$>-sem p) r))
tw″-symbol : ∀ {s} → Trailing-whitespace″ (symbol s)
tw″-symbol (<⊛-sem {s₁ = s₁} p q) w =
cast (P.sym $ LM.assoc s₁ _ _)
(<⊛-sem p (proj₂ (tw′-whitespace q w)))
tw″-term : Trailing-whitespace″ term
tw″-term (left-sem (<$-sem p)) w =
left-sem (<$-sem (tw″-symbol p w))
tw″-term (right-sem (<⊛-sem {s₁ = s₁} p q)) w =
cast (P.sym $ LM.assoc s₁ _ _)
(right-sem (<⊛-sem p (tw″-symbol q w)))
tw″-expr : Trailing-whitespace″ expr
tw″-expr (left-sem p) w =
left-sem (tw″-term p w)
tw″-expr (right-sem (⊛-sem {s₁ = s₁} p q)) w =
cast (P.sym $ LM.assoc s₁ _ _)
(right-sem (⊛-sem p (tw″-term q w)))
tw-expr : Trailing-whitespace expr
tw-expr (<⊛-sem p w) = tw″-expr p w
open Pretty
one-doc : Doc term one
one-doc = left (<$ symbol)
mutual
expr-printer : Pretty-printer expr
expr-printer one = left one-doc
expr-printer (sub e₁ e₂) =
group (right (<$> final-line 6 (expr-printer e₁) 2 <⊛
symbol-space ⊛ nest 2 (term-printer e₂)))
term-printer : Pretty-printer term
term-printer one = one-doc
term-printer e = right (symbol ⊛> expr-printer e <⊛ symbol)
test₁ : render 80 (expr-printer example) ≡ "1 - 1 - (1 - 1)"
test₁ = refl
test₂ : render 11 (expr-printer example) ≡ "1 - 1\n - (1 - 1)"
test₂ = refl
test₃ : render 8 (expr-printer example) ≡ "1 - 1\n - (1\n - 1)"
test₃ = refl
-- A somewhat larger expression example.
module Expression₃ where
-- Expressions.
data Expr : Set where
one : Expr
sub : Expr → Expr → Expr
div : Expr → Expr → Expr
var : Identifier → Expr
-- Precedences.
data Prec : Set where
′5 ′6 ′7 : Prec
module _ where
open Grammar
-- One expression grammar for each precedence level.
expr : Prec → Grammar Expr
expr ′5 = ♯ expr ′6
∣ sub <$> ♯ expr ′5 <⊛ symbol′ "-" ⊛ ♯ expr ′6
expr ′6 = ♯ expr ′7
∣ div <$> ♯ expr ′6 <⊛ symbol′ "/" ⊛ ♯ expr ′7
expr ′7 = one <$ symbol′ "1"
∣ var <$> identifier-w
∣ symbol′ "(" ⊛> ♯ expr ′5 <⊛ symbol′ ")"
open Pretty
-- Document for one.
one-doc : Doc (expr ′7) one
one-doc = left (left (<$ symbol))
-- Documents for variables.
var-doc : ∀ x → Doc (expr ′7) (var x)
var-doc x = left (right (<$> identifier-w-printer x))
-- Adds parentheses to a document.
parens : ∀ {e} → Doc (expr ′5) e → Doc (expr ′7) e
parens d = right (symbol ⊛> d <⊛ symbol)
-- Adds parentheses only when necessary (when p₁ < p₂).
parens-if[_<_] : ∀ p₁ p₂ {e} → Doc (expr p₁) e → Doc (expr p₂) e
parens-if[ ′5 < ′5 ] = id
parens-if[ ′5 < ′6 ] = left ∘ parens
parens-if[ ′5 < ′7 ] = parens
parens-if[ ′6 < ′5 ] = left
parens-if[ ′6 < ′6 ] = id
parens-if[ ′6 < ′7 ] = parens ∘ left
parens-if[ ′7 < ′5 ] = left ∘ left
parens-if[ ′7 < ′6 ] = left
parens-if[ ′7 < ′7 ] = id
mutual
-- Pretty-printers.
expr-printer : ∀ p → Pretty-printer (expr p)
expr-printer p (sub e₁ e₂) = parens-if[ ′5 < p ] (sub-printer e₁ e₂)
expr-printer p (div e₁ e₂) = parens-if[ ′6 < p ] (div-printer e₁ e₂)
expr-printer p one = parens-if[ ′7 < p ] one-doc
expr-printer p (var x) = parens-if[ ′7 < p ] (var-doc x)
sub-printer : ∀ e₁ e₂ → Doc (expr ′5) (sub e₁ e₂)
sub-printer e₁ e₂ =
group (right (<$> final-line 10 (expr-printer ′5 e₁) 2 <⊛
symbol-space ⊛ nest 2 (expr-printer ′6 e₂)))
div-printer : ∀ e₁ e₂ → Doc (expr ′6) (div e₁ e₂)
div-printer e₁ e₂ =
group (right (<$> final-line 10 (expr-printer ′6 e₁) 2 <⊛
symbol-space ⊛ nest 2 (expr-printer ′7 e₂)))
-- Unit tests.
example : Expr
example = sub (div (var (str⁺ "x")) one) (sub one (var (str⁺ "y")))
test₁ : render 80 (expr-printer ′5 example) ≡ "x / 1 - (1 - y)"
test₁ = refl
test₂ : render 11 (expr-printer ′5 example) ≡ "x / 1\n - (1 - y)"
test₂ = refl
test₃ : render 8 (expr-printer ′5 example) ≡ "x / 1\n - (1\n - y)"
test₃ = refl
test₄ : render 11 (expr-printer ′6 example) ≡ "(x / 1\n - (1\n - y))"
test₄ = refl
test₅ : render 12 (expr-printer ′6 example) ≡ "(x / 1\n - (1 - y))"
test₅ = refl
| 26.956835
| 75
| 0.531759
|
352f0b57a955868d9ff4e3985cbe0d5375a54ee1
| 1,225
|
agda
|
Agda
|
Cubical/Categories/Limits/BinCoproduct.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-02-05T01:25:26.000Z
|
2022-02-05T01:25:26.000Z
|
Cubical/Categories/Limits/BinCoproduct.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Limits/BinCoproduct.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
-- Binary coproducts
{-# OPTIONS --safe #-}
module Cubical.Categories.Limits.BinCoproduct where
open import Cubical.Categories.Category.Base
open import Cubical.Data.Sigma.Base
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
open import Cubical.HITs.PropositionalTruncation.Base
private
variable
ℓ ℓ' : Level
module _ (C : Category ℓ ℓ') where
open Category C
module _ {x y x+y : ob}
(i₁ : Hom[ x , x+y ])
(i₂ : Hom[ y , x+y ]) where
isBinCoproduct : Type (ℓ-max ℓ ℓ')
isBinCoproduct = ∀ {z : ob} (f₁ : Hom[ x , z ]) (f₂ : Hom[ y , z ]) →
∃![ f ∈ Hom[ x+y , z ] ] (i₁ ⋆ f ≡ f₁) × (i₂ ⋆ f ≡ f₂)
isPropIsBinCoproduct : isProp (isBinCoproduct)
isPropIsBinCoproduct = isPropImplicitΠ (λ _ → isPropΠ2 (λ _ _ → isPropIsContr))
record BinCoproduct (x y : ob) : Type (ℓ-max ℓ ℓ') where
field
binCoprodOb : ob
binCoprodInj₁ : Hom[ x , binCoprodOb ]
binCoprodInj₂ : Hom[ y , binCoprodOb ]
univProp : isBinCoproduct binCoprodInj₁ binCoprodInj₂
BinCoproducts : Type (ℓ-max ℓ ℓ')
BinCoproducts = (x y : ob) → BinCoproduct x y
hasBinCoproducts : Type (ℓ-max ℓ ℓ')
hasBinCoproducts = ∥ BinCoproducts ∥
| 27.840909
| 83
| 0.647347
|
adabd33a1e0f4a06c87d63d7466615009b4b61b3
| 2,808
|
agda
|
Agda
|
Cubical/Codata/M/AsLimit/M/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 301
|
2018-10-17T18:00:24.000Z
|
2022-03-24T02:10:47.000Z
|
Cubical/Codata/M/AsLimit/M/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 584
|
2018-10-15T09:49:02.000Z
|
2022-03-30T12:09:17.000Z
|
Cubical/Codata/M/AsLimit/M/Properties.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 134
|
2018-11-16T06:11:03.000Z
|
2022-03-23T16:22:13.000Z
|
{-# OPTIONS --guardedness --safe #-}
module Cubical.Codata.M.AsLimit.M.Properties where
open import Cubical.Data.Unit
open import Cubical.Data.Prod
open import Cubical.Data.Nat as ℕ using (ℕ ; suc ; _+_ )
open import Cubical.Data.Sum
open import Cubical.Data.Sigma
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv using (_≃_)
open import Cubical.Foundations.Function using (_∘_)
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Functions.Embedding
open import Cubical.Codata.M.AsLimit.helper
open import Cubical.Codata.M.AsLimit.M.Base
open import Cubical.Codata.M.AsLimit.Container
-- in-fun and out-fun are inverse
open Iso
in-inverse-out : ∀ {ℓ} {S : Container ℓ} → (in-fun {S = S} ∘ out-fun {S = S}) ≡ idfun (M S)
in-inverse-out {S = S} = subst (λ inv → in-fun {S = S} ∘ inv ≡ idfun (M S)) idpath def where
-- substituting refl makes type-checking work a lot faster, but introduces a transport
-- TODO (2020-05-23): revisit this at some point to see if it's still needed in future versions of agda
def : (in-fun {S = S} ∘ inv (shift-iso S)) ≡ idfun (M S)
def = funExt (rightInv (shift-iso S))
idpath : inv (shift-iso S) ≡ out-fun {S = S}
idpath = refl
out-inverse-in : ∀ {ℓ} {S : Container ℓ} → (out-fun {S = S} ∘ in-fun {S = S}) ≡ idfun (P₀ S (M S))
out-inverse-in {S = S} = subst (λ fun → out-fun {S = S} ∘ fun ≡ idfun (P₀ S (M S))) idpath def where
def : (out-fun {S = S} ∘ fun (shift-iso S)) ≡ idfun (P₀ S (M S))
def = funExt (leftInv (shift-iso S))
idpath : fun (shift-iso S) ≡ in-fun {S = S}
idpath = refl
in-out-id : ∀ {ℓ} {S : Container ℓ} -> ∀ {x y : M S} → (in-fun (out-fun x) ≡ in-fun (out-fun y)) ≡ (x ≡ y)
in-out-id {x = x} {y} i = (in-inverse-out i x) ≡ (in-inverse-out i y)
-- constructor properties
in-inj : ∀ {ℓ} {S : Container ℓ} {Z : Type ℓ} → ∀ {f g : Z → P₀ S (M S)} → (in-fun ∘ f ≡ in-fun ∘ g) ≡ (f ≡ g)
in-inj {ℓ} {S = S} {Z = Z} {f = f} {g = g} = iso→fun-Injection-Path {ℓ = ℓ} {A = P₀ S (M S)} {B = M S} {C = Z} (shift-iso S) {f = f} {g = g}
out-inj : ∀ {ℓ} {S : Container ℓ} {Z : Type ℓ} → ∀ {f g : Z → M S} → (out-fun ∘ f ≡ out-fun ∘ g) ≡ (f ≡ g)
out-inj {ℓ} {S = S} {Z = Z} {f = f} {g = g} = iso→inv-Injection-Path {ℓ = ℓ} {A = P₀ S (M S)} {B = M S} {C = Z} (shift-iso S) {f = f} {g = g}
in-inj-x : ∀ {ℓ} {S : Container ℓ} → ∀ {x y : P₀ S (M S)} → (in-fun x ≡ in-fun y) ≡ (x ≡ y)
in-inj-x {ℓ} {S = S} {x = x} {y} = iso→fun-Injection-Path-x (shift-iso S) {x} {y}
out-inj-x : ∀ {ℓ} {S : Container ℓ} → ∀ {x y : M S} → (out-fun x ≡ out-fun y) ≡ (x ≡ y)
out-inj-x {ℓ} {S = S} {x = x} {y} = iso→inv-Injection-Path-x (shift-iso S) {x} {y}
| 45.290323
| 141
| 0.606838
|
fd361f3417af492ad7c98ed2d66faa4c9d1f6ff6
| 9,103
|
agda
|
Agda
|
core/lib/groups/GroupProduct.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 294
|
2015-01-09T16:23:23.000Z
|
2022-03-20T13:54:45.000Z
|
core/lib/groups/GroupProduct.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 31
|
2015-03-05T20:09:00.000Z
|
2021-10-03T19:15:25.000Z
|
core/lib/groups/GroupProduct.agda
|
AntoineAllioux/HoTT-Agda
|
1037d82edcf29b620677a311dcfd4fc2ade2faa6
|
[
"MIT"
] | 50
|
2015-01-10T01:48:08.000Z
|
2022-02-14T03:03:25.000Z
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Bool
open import lib.types.Group
open import lib.types.Nat
open import lib.types.Pi
open import lib.types.Sigma
open import lib.types.Coproduct
open import lib.types.Truncation
open import lib.groups.Homomorphism
open import lib.groups.Isomorphism
open import lib.groups.SubgroupProp
open import lib.groups.Lift
open import lib.groups.Unit
module lib.groups.GroupProduct where
{- binary product -}
×-group-struct : ∀ {i j} {A : Type i} {B : Type j}
(GS : GroupStructure A) (HS : GroupStructure B)
→ GroupStructure (A × B)
×-group-struct {A = A} {B = B} GS HS = record {M} where
module G = GroupStructure GS
module H = GroupStructure HS
module M where
ident : A × B
ident = G.ident , H.ident
inv : A × B → A × B
inv (g , h) = G.inv g , H.inv h
comp : A × B → A × B → A × B
comp (g₁ , h₁) (g₂ , h₂) = G.comp g₁ g₂ , H.comp h₁ h₂
abstract
unit-l : ∀ ab → comp ident ab == ab
unit-l (g , h) = pair×= (G.unit-l g) (H.unit-l h)
assoc : ∀ ab₁ ab₂ ab₃ → comp (comp ab₁ ab₂) ab₃ == comp ab₁ (comp ab₂ ab₃)
assoc (g₁ , h₁) (g₂ , h₂) (g₃ , h₃) =
pair×= (G.assoc g₁ g₂ g₃) (H.assoc h₁ h₂ h₃)
inv-l : ∀ ab → comp (inv ab) ab == ident
inv-l (g , h) = pair×= (G.inv-l g) (H.inv-l h)
infix 80 _×ᴳˢ_
_×ᴳˢ_ = ×-group-struct
infix 80 _×ᴳ_
_×ᴳ_ : ∀ {i j} → Group i → Group j → Group (lmax i j)
_×ᴳ_ (group A A-struct) (group B B-struct) =
group (A × B) (×-group-struct A-struct B-struct)
{- general product -}
Π-group-struct : ∀ {i j} {I : Type i} {A : I → Type j}
(FS : (i : I) → GroupStructure (A i))
→ GroupStructure (Π I A)
Π-group-struct FS = record {
ident = ident ∘ FS;
inv = λ f i → inv (FS i) (f i);
comp = λ f g i → comp (FS i) (f i) (g i);
unit-l = λ f → (λ= (λ i → unit-l (FS i) (f i)));
assoc = λ f g h → (λ= (λ i → assoc (FS i) (f i) (g i) (h i)));
inv-l = λ f → (λ= (λ i → inv-l (FS i) (f i)))}
where open GroupStructure
Πᴳ : ∀ {i j} (I : Type i) (F : I → Group j) → Group (lmax i j)
Πᴳ I F = group (Π I (El ∘ F)) {{Π-level (λ i → El-level (F i))}} -- TODO: how to get instance search to work?
(Π-group-struct (group-struct ∘ F))
where open Group
{- functorial behavior of [Πᴳ] -}
Πᴳ-emap-r : ∀ {i j k} (I : Type i) {F : I → Group j} {G : I → Group k}
→ (∀ i → F i ≃ᴳ G i) → Πᴳ I F ≃ᴳ Πᴳ I G
Πᴳ-emap-r I {F} {G} iso = ≃-to-≃ᴳ (Π-emap-r (GroupIso.f-equiv ∘ iso))
(λ f g → λ= λ i → GroupIso.pres-comp (iso i) (f i) (g i))
{- the product of abelian groups is abelian -}
×ᴳ-is-abelian : ∀ {i j} (G : Group i) (H : Group j)
→ is-abelian G → is-abelian H → is-abelian (G ×ᴳ H)
×ᴳ-is-abelian G H aG aH (g₁ , h₁) (g₂ , h₂) = pair×= (aG g₁ g₂) (aH h₁ h₂)
×ᴳ-abgroup : ∀ {i j} → AbGroup i → AbGroup j → AbGroup (lmax i j)
×ᴳ-abgroup (G , aG) (H , aH) = G ×ᴳ H , ×ᴳ-is-abelian G H aG aH
Πᴳ-is-abelian : ∀ {i j} {I : Type i} {F : I → Group j}
→ (∀ i → is-abelian (F i)) → is-abelian (Πᴳ I F)
Πᴳ-is-abelian aF f₁ f₂ = λ= (λ i → aF i (f₁ i) (f₂ i))
{- defining a homomorphism into a product -}
×ᴳ-fanout : ∀ {i j k} {G : Group i} {H : Group j} {K : Group k}
→ (G →ᴳ H) → (G →ᴳ K) → (G →ᴳ H ×ᴳ K)
×ᴳ-fanout (group-hom h h-comp) (group-hom k k-comp) =
group-hom (fanout h k) (λ x y → pair×= (h-comp x y) (k-comp x y))
Πᴳ-fanout : ∀ {i j k} {I : Type i} {G : Group j} {F : I → Group k}
→ ((i : I) → G →ᴳ F i) → (G →ᴳ Πᴳ I F)
Πᴳ-fanout h = group-hom
(λ x i → GroupHom.f (h i) x)
(λ x y → λ= (λ i → GroupHom.pres-comp (h i) x y))
{- projection homomorphisms -}
×ᴳ-fst : ∀ {i j} {G : Group i} {H : Group j} → (G ×ᴳ H →ᴳ G)
×ᴳ-fst = group-hom fst (λ _ _ → idp)
×ᴳ-snd : ∀ {i j} {G : Group i} {H : Group j} → (G ×ᴳ H →ᴳ H)
×ᴳ-snd = group-hom snd (λ _ _ → idp)
×ᴳ-snd-is-surj : ∀ {i j} {G : Group i} {H : Group j}
→ is-surjᴳ (×ᴳ-snd {G = G} {H = H})
×ᴳ-snd-is-surj {G = G} h = [ (Group.ident G , h) , idp ]
Πᴳ-proj : ∀ {i j} {I : Type i} {F : I → Group j} (i : I)
→ (Πᴳ I F →ᴳ F i)
Πᴳ-proj i = group-hom (λ f → f i) (λ _ _ → idp)
{- injection homomorphisms -}
module _ {i j} {G : Group i} {H : Group j} where
×ᴳ-inl : G →ᴳ G ×ᴳ H
×ᴳ-inl = ×ᴳ-fanout (idhom G) cst-hom
×ᴳ-inr : H →ᴳ G ×ᴳ H
×ᴳ-inr = ×ᴳ-fanout (cst-hom {H = G}) (idhom H)
×ᴳ-diag : ∀ {i} {G : Group i} → (G →ᴳ G ×ᴳ G)
×ᴳ-diag = ×ᴳ-fanout (idhom _) (idhom _)
{- when G is abelian, we can define a map H×K → G as a sum of maps
- H → G and K → G (that is, the product behaves as a sum) -}
module _ {i j k} {G : Group i} {H : Group j} {K : Group k}
(G-abelian : is-abelian G) where
private
module G = AbGroup (G , G-abelian)
module H = Group H
module K = Group K
×ᴳ-fanin : (H →ᴳ G) → (K →ᴳ G) → (H ×ᴳ K →ᴳ G)
×ᴳ-fanin φ ψ = group-hom (λ {(h , k) → G.comp (φ.f h) (ψ.f k)}) lemma
where
module φ = GroupHom φ
module ψ = GroupHom ψ
abstract
lemma : preserves-comp (Group.comp (H ×ᴳ K)) G.comp
(λ {(h , k) → G.comp (φ.f h) (ψ.f k)})
lemma (h₁ , k₁) (h₂ , k₂) =
G.comp (φ.f (H.comp h₁ h₂)) (ψ.f (K.comp k₁ k₂))
=⟨ φ.pres-comp h₁ h₂ |in-ctx (λ w → G.comp w (ψ.f (K.comp k₁ k₂))) ⟩
G.comp (G.comp (φ.f h₁) (φ.f h₂)) (ψ.f (K.comp k₁ k₂))
=⟨ ψ.pres-comp k₁ k₂
|in-ctx (λ w → G.comp (G.comp (φ.f h₁) (φ.f h₂)) w) ⟩
G.comp (G.comp (φ.f h₁) (φ.f h₂)) (G.comp (ψ.f k₁) (ψ.f k₂))
=⟨ G.interchange (φ.f h₁) (φ.f h₂) (ψ.f k₁) (ψ.f k₂) ⟩
G.comp (G.comp (φ.f h₁) (ψ.f k₁)) (G.comp (φ.f h₂) (ψ.f k₂)) =∎
abstract
×ᴳ-fanin-η : ∀ {i j} (G : Group i) (H : Group j)
(aGH : is-abelian (G ×ᴳ H))
→ ∀ gh → gh == GroupHom.f (×ᴳ-fanin {G = G ×ᴳ H} aGH ×ᴳ-inl ×ᴳ-inr) gh
×ᴳ-fanin-η G H aGH (g , h) =
! (pair×= (Group.unit-r G g) (Group.unit-l H h))
×ᴳ-fanin-pre∘ : ∀ {i j k l}
{G : Group i} {H : Group j} {K : Group k} {L : Group l}
(aK : is-abelian K) (aL : is-abelian L)
(φ : K →ᴳ L) (ψ : G →ᴳ K) (χ : H →ᴳ K)
→ ∀ kh → GroupHom.f (×ᴳ-fanin aL (φ ∘ᴳ ψ) (φ ∘ᴳ χ)) kh
== GroupHom.f (φ ∘ᴳ ×ᴳ-fanin aK ψ χ) kh
×ᴳ-fanin-pre∘ aK aL φ ψ χ (g , h) =
! (GroupHom.pres-comp φ (GroupHom.f ψ g) (GroupHom.f χ h))
{- define a homomorphism [G₁ × G₂ → H₁ × H₂] from homomorphisms
- [G₁ → H₁] and [G₂ → H₂] -}
×ᴳ-fmap : ∀ {i j k l} {G₁ : Group i} {G₂ : Group j}
{H₁ : Group k} {H₂ : Group l}
→ (G₁ →ᴳ H₁) → (G₂ →ᴳ H₂) → (G₁ ×ᴳ G₂ →ᴳ H₁ ×ᴳ H₂)
×ᴳ-fmap {G₁ = G₁} {G₂} {H₁} {H₂} φ ψ = group-hom (×-fmap φ.f ψ.f) lemma
where
module φ = GroupHom φ
module ψ = GroupHom ψ
abstract
lemma : preserves-comp (Group.comp (G₁ ×ᴳ G₂)) (Group.comp (H₁ ×ᴳ H₂))
(λ {(h₁ , h₂) → (φ.f h₁ , ψ.f h₂)})
lemma (h₁ , h₂) (h₁' , h₂') = pair×= (φ.pres-comp h₁ h₁') (ψ.pres-comp h₂ h₂')
×ᴳ-emap : ∀ {i j k l} {G₁ : Group i} {G₂ : Group j}
{H₁ : Group k} {H₂ : Group l}
→ (G₁ ≃ᴳ H₁) → (G₂ ≃ᴳ H₂) → (G₁ ×ᴳ G₂ ≃ᴳ H₁ ×ᴳ H₂)
×ᴳ-emap (φ , φ-is-equiv) (ψ , ψ-is-equiv) =
×ᴳ-fmap φ ψ , ×-isemap φ-is-equiv ψ-is-equiv
{- equivalences in Πᴳ -}
Πᴳ-emap-l : ∀ {i j k} {A : Type i} {B : Type j} (F : B → Group k)
→ (e : A ≃ B) → Πᴳ A (F ∘ –> e) ≃ᴳ Πᴳ B F
Πᴳ-emap-l {A = A} {B = B} F e = ≃-to-≃ᴳ (Π-emap-l (Group.El ∘ F) e) lemma
where abstract lemma = λ f g → λ= λ b → transp-El-pres-comp F (<–-inv-r e b) (f (<– e b)) (g (<– e b))
{- 0ᴳ is a unit for product -}
×ᴳ-unit-l : ∀ {i} (G : Group i) → 0ᴳ ×ᴳ G ≃ᴳ G
×ᴳ-unit-l _ = ×ᴳ-snd {G = 0ᴳ} , is-eq snd (λ g → (unit , g)) (λ _ → idp) (λ _ → idp)
×ᴳ-unit-r : ∀ {i} (G : Group i) → G ×ᴳ 0ᴳ ≃ᴳ G
×ᴳ-unit-r _ = ×ᴳ-fst , is-eq fst (λ g → (g , unit)) (λ _ → idp) (λ _ → idp)
{- A product Πᴳ indexed by Bool is the same as a binary product -}
module _ {i j k} {A : Type i} {B : Type j} (F : A ⊔ B → Group k) where
Πᴳ₁-⊔-iso-×ᴳ : Πᴳ (A ⊔ B) F ≃ᴳ Πᴳ A (F ∘ inl) ×ᴳ Πᴳ B (F ∘ inr)
Πᴳ₁-⊔-iso-×ᴳ = ≃-to-≃ᴳ (Π₁-⊔-equiv-× (Group.El ∘ F)) (λ _ _ → idp)
{- Commutativity of ×ᴳ -}
×ᴳ-comm : ∀ {i j} (H : Group i) (K : Group j) → H ×ᴳ K ≃ᴳ K ×ᴳ H
×ᴳ-comm H K =
group-hom (λ {(h , k) → (k , h)}) (λ _ _ → idp) ,
is-eq _ (λ {(k , h) → (h , k)}) (λ _ → idp) (λ _ → idp)
{- Associativity of ×ᴳ -}
×ᴳ-assoc : ∀ {i j k} (G : Group i) (H : Group j) (K : Group k)
→ ((G ×ᴳ H) ×ᴳ K) ≃ᴳ (G ×ᴳ (H ×ᴳ K))
×ᴳ-assoc G H K =
group-hom (λ {((g , h) , k) → (g , (h , k))}) (λ _ _ → idp) ,
is-eq _ (λ {(g , (h , k)) → ((g , h) , k)}) (λ _ → idp) (λ _ → idp)
module _ {i} where
infixl 80 _^ᴳ_
_^ᴳ_ : Group i → ℕ → Group i
H ^ᴳ O = Lift-group {j = i} 0ᴳ
H ^ᴳ (S n) = H ×ᴳ (H ^ᴳ n)
^ᴳ-+ : (H : Group i) (m n : ℕ) → H ^ᴳ (m + n) ≃ᴳ (H ^ᴳ m) ×ᴳ (H ^ᴳ n)
^ᴳ-+ H O n = ×ᴳ-emap (lift-iso {G = 0ᴳ}) (idiso (H ^ᴳ n)) ∘eᴳ ×ᴳ-unit-l (H ^ᴳ n) ⁻¹ᴳ
^ᴳ-+ H (S m) n = ×ᴳ-assoc H (H ^ᴳ m) (H ^ᴳ n) ⁻¹ᴳ ∘eᴳ ×ᴳ-emap (idiso H) (^ᴳ-+ H m n)
module _ where
Πᴳ-is-trivial : ∀ {i j} (I : Type i) (F : I → Group j)
→ (∀ (i : I) → is-trivialᴳ (F i)) → is-trivialᴳ (Πᴳ I F)
Πᴳ-is-trivial I F F-is-trivial = λ f → λ= λ i → F-is-trivial i (f i)
module _ {j} {F : Unit → Group j} where
Πᴳ₁-Unit : Πᴳ Unit F ≃ᴳ F unit
Πᴳ₁-Unit = ≃-to-≃ᴳ Π₁-Unit (λ _ _ → idp)
| 36.854251
| 109
| 0.509832
|
0d9688bb9573c684b5d6f5911aa9ece2ac7c88b1
| 1,195
|
agda
|
Agda
|
test/succeed/Issue1147.agda
|
larrytheliquid/agda
|
477c8c37f948e6038b773409358fd8f38395f827
|
[
"MIT"
] | 1
|
2018-10-10T17:08:44.000Z
|
2018-10-10T17:08:44.000Z
|
test/succeed/Issue1147.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | null | null | null |
test/succeed/Issue1147.agda
|
masondesu/agda
|
70c8a575c46f6a568c7518150a1a64fcd03aa437
|
[
"MIT"
] | 1
|
2022-03-12T11:35:18.000Z
|
2022-03-12T11:35:18.000Z
|
-- 2014-05-26 Andrea & Andreas, AIM XIX
-- Too eager pruning
module succeed.Issue1147 where
open import Common.Equality
open import Common.Product
open import Common.Prelude
postulate
A : Set
if_then_else1_ : ∀ {A : Set1} → Bool → A → A → A
if true then t else1 f = t
if false then t else1 f = f
test1 : let H : Set; H = _; M : Bool -> Set → Set; M = _ in {z : Set} → H ≡ (M true z) × M ≡ (\ b z → if b then A else1 z)
test1 = refl , refl
test2 : let H : Set; H = _; M : (Bool -> Bool) -> Set → Set; M = _ in {z : Set} → H ≡ (M (\ _ -> true) z) × M ≡ (\ b z → if b true then A else1 z)
test2 = refl , refl
test3 : let H : Set; H = _; M : (Bool × Bool) -> Set → Set; M = _ in {z : Set} {b : Bool} → H ≡ (M (true , b) z) × M ≡ (\ b z → if proj₁ b then A else1 z)
test3 = refl , refl
-- Also for defined functions
fun : Bool → Bool
fun true = true
fun false = false
works4 : let H : Set; H = _; M : (Bool -> Bool) -> Set → Set; M = _ in {z : Set} → M ≡ (\ b z → if b true then A else1 z) × H ≡ (M fun z)
works4 = refl , refl
test4 : let H : Set; H = _; M : (Bool -> Bool) -> Set → Set; M = _ in {z : Set} → H ≡ (M fun z) × M ≡ (\ b z → if b true then A else1 z)
test4 = refl , refl
| 31.447368
| 154
| 0.554812
|
211d10afce5b8e5ebb7a24f17ae2bb8fc67eb27d
| 7,647
|
agda
|
Agda
|
agda/Counterpoint.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 28
|
2017-04-21T09:08:52.000Z
|
2022-03-04T18:04:07.000Z
|
agda/Counterpoint.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 1
|
2020-11-13T01:26:20.000Z
|
2020-11-17T00:58:55.000Z
|
agda/Counterpoint.agda
|
halfaya/MusicTools
|
04896c61b603d46011b7d718fcb47dd756e66021
|
[
"MIT"
] | 3
|
2019-01-12T17:02:36.000Z
|
2020-11-10T04:04:40.000Z
|
{-# OPTIONS --cubical --safe #-}
-- First and second species counterpoint
module Counterpoint where
open import Data.Bool using (Bool; true; false; if_then_else_; _∨_; _∧_; not)
open import Data.Fin using (Fin; #_)
open import Data.Integer using (+_)
open import Data.List using (List; []; _∷_; mapMaybe; map; zip; _++_; concatMap)
open import Data.Maybe using (Maybe; just; nothing)
open import Data.Nat using (suc; _+_; _<ᵇ_; compare; _∸_; ℕ; zero) renaming (_≡ᵇ_ to _==_)
open import Data.Product using (_×_; _,_; proj₁; proj₂; uncurry)
open import Data.Vec using ([]; _∷_; Vec; lookup; drop; reverse)
open import Function using (_∘_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Music
open import Note
open import Pitch
open import Interval
open import Util using (pairs)
------------------------------------------------
-- First species
-- Beginning must be the 1st, 5th, or 8th
data BeginningError : Set where
not158 : PitchInterval → BeginningError
checkBeginning : PitchInterval → Maybe BeginningError
checkBeginning pi@(_ , i) =
if ((i == per1) ∨ (i == per5) ∨ (i == per8))
then nothing
else just (not158 pi)
------------------------------------------------
-- Intervals in middle bars must be consonant and non-unison
data IntervalError : Set where
dissonant : Upi → IntervalError
unison : Pitch → IntervalError
intervalCheck : PitchInterval → Maybe IntervalError
intervalCheck (p , i) with isConsonant i | isUnison i
intervalCheck (p , i) | false | _ = just (dissonant i)
intervalCheck (p , i) | _ | true = just (unison p)
intervalCheck (p , i) | _ | _ = nothing
checkIntervals : List PitchInterval → List IntervalError
checkIntervals = mapMaybe intervalCheck
------------------------------------------------
-- Perfect intervals must not approached by parallel or similar motion
data Motion : Set where
contrary : Motion
parallel : Motion
similar : Motion
oblique : Motion
motion : PitchInterval → PitchInterval → Motion
motion (p , i) (q , j) =
let p' = p + i; q' = q + j
in if i == j then parallel
else (if (p == q) ∨ (p' == q') then oblique
else (if p <ᵇ q then (if p' <ᵇ q' then similar else contrary)
else (if p' <ᵇ q' then contrary else similar)))
data MotionError : Set where
parallel : PitchInterval → PitchInterval → MotionError
similar : PitchInterval → PitchInterval → MotionError
motionCheck : PitchInterval → PitchInterval → Maybe MotionError
motionCheck i1 i2 with motion i1 i2 | isPerfect (proj₂ i2)
motionCheck i1 i2 | contrary | _ = nothing
motionCheck i1 i2 | oblique | _ = nothing
motionCheck i1 i2 | parallel | false = nothing
motionCheck i1 i2 | parallel | true = just (parallel i1 i2)
motionCheck i1 i2 | similar | false = nothing
motionCheck i1 i2 | similar | true = just (similar i1 i2)
checkMotion : List PitchInterval → List MotionError
checkMotion = mapMaybe (uncurry motionCheck) ∘ pairs
------------------------------------------------
-- Ending must be the 1st or 8th approached by a cadence
data EndingError : Set where
not18 : PitchInterval → EndingError
not27 : PitchInterval → EndingError
tooShort : List PitchInterval → EndingError
endingCheck : PitchInterval → PitchInterval → Maybe EndingError
endingCheck pi1@(p , i) (q , 0) =
if ((p + 1 == q) ∧ (i == min3)) then nothing else just (not27 pi1)
endingCheck pi1@(p , i) (q , 12) =
if ((q + 2 == p) ∧ (i == maj6) ∨ (p + 1 == q) ∧ (i == min10))
then nothing
else just (not27 pi1)
endingCheck pi1 pi2 =
just (not18 pi2)
checkEnding : List PitchInterval → PitchInterval → Maybe EndingError
checkEnding [] _ = just (tooShort [])
checkEnding (p ∷ []) q = endingCheck p q
checkEnding (p ∷ ps) q = checkEnding ps q
------------------------------------------------
-- Correct first species counterpoint
record FirstSpecies : Set where
constructor firstSpecies
field
firstBar : PitchInterval
middleBars : List PitchInterval
lastBar : PitchInterval
beginningOk : checkBeginning firstBar ≡ nothing
intervalsOk : checkIntervals middleBars ≡ []
motionOk : checkMotion (firstBar ∷ middleBars) ≡ []
-- no need to include the last bar,
-- since endingOK guarantees contrary motion in the ending
endingOk : checkEnding middleBars lastBar ≡ nothing
------------------------------------------------
-- Second Species
PitchInterval2 : Set
PitchInterval2 = Pitch × Upi × Upi
strongBeat : PitchInterval2 → PitchInterval
strongBeat (p , i , _) = p , i
weakBeat : PitchInterval2 → PitchInterval
weakBeat (p , _ , i) = p , i
expandPitchInterval2 : PitchInterval2 → List PitchInterval
expandPitchInterval2 (p , i , j) = (p , i) ∷ (p , j) ∷ []
expandPitchIntervals2 : List PitchInterval2 → List PitchInterval
expandPitchIntervals2 = concatMap expandPitchInterval2
------------------------------------------------
-- Beginning must be the 5th or 8th
data BeginningError2 : Set where
not58 : PitchInterval → BeginningError2
checkBeginning2 : PitchInterval → Maybe BeginningError2
checkBeginning2 pi@(_ , i) =
if ((i == per5) ∨ (i == per8))
then nothing
else just (not58 pi)
checkEnding2 : List PitchInterval2 → PitchInterval → Maybe EndingError
checkEnding2 [] _ = just (tooShort [])
checkEnding2 (p ∷ []) q = endingCheck (weakBeat p) q
checkEnding2 (_ ∷ p ∷ ps) q = checkEnding2 (p ∷ ps) q
------------------------------------------------
-- Strong beats must be consonant and non-unison
checkStrongBeats : List PitchInterval2 → List IntervalError
checkStrongBeats = checkIntervals ∘ map strongBeat
------------------------------------------------
-- Weak beats may be dissonant or unison
checkWeakBeat : PitchInterval2 → Pitch → Maybe IntervalError
checkWeakBeat (p , i , j) q with isConsonant j | isUnison j
checkWeakBeat (p , i , j) q | false | _ =
if isPassingTone (secondPitch (p , i)) (secondPitch (p , j)) q
then nothing
else just (dissonant j)
checkWeakBeat (p , i , j) q | _ | true =
if isOppositeStep (secondPitch (p , i)) (secondPitch (p , j)) q
then nothing
else just (unison p)
checkWeakBeat (p , i , j) q | _ | _ =
nothing
checkWeakBeats : List PitchInterval2 → Pitch → List IntervalError
checkWeakBeats [] p = []
checkWeakBeats pis@(_ ∷ qis) p =
mapMaybe (uncurry checkWeakBeat)
(zip pis
(map (λ {(q , i , j) → proj₂ (pitchIntervalToPitchPair (q , i))}) qis ++ (p ∷ [])))
------------------------------------------------
-- Perfect intervals on strong beats must not be approached by parallel or similar motion
checkMotion2 : List PitchInterval → List MotionError
checkMotion2 [] = []
checkMotion2 (_ ∷ []) = []
checkMotion2 (p ∷ q ∷ ps) = checkMotion (p ∷ q ∷ []) ++ checkMotion2 ps
------------------------------------------------
-- Correct second species counterpoint
record SecondSpecies : Set where
constructor secondSpecies
field
firstBar : PitchInterval -- require counterpont to start with a rest, which is preferred
middleBars : List PitchInterval2
lastBar : PitchInterval -- require counterpoint to end with only a single whole note, which is preferred
beginningOk : checkBeginning2 firstBar ≡ nothing
strongBeatsOk : checkStrongBeats middleBars ≡ []
weakBeatsOk : checkWeakBeats middleBars (secondPitch lastBar) ≡ []
motionOk : checkMotion2 (firstBar ∷ (expandPitchIntervals2 middleBars)) ≡ []
endingOk : checkEnding2 middleBars lastBar ≡ nothing
| 35.901408
| 114
| 0.637505
|
d108b1f6920e9b6c83fef46ae592d657cf710e6c
| 2,266
|
agda
|
Agda
|
Cubical/Categories/Instances/Cospan.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | 1
|
2022-03-05T00:29:41.000Z
|
2022-03-05T00:29:41.000Z
|
Cubical/Categories/Instances/Cospan.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
Cubical/Categories/Instances/Cospan.agda
|
FernandoLarrain/cubical
|
9acdecfa6437ec455568be4e5ff04849cc2bc13b
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --safe #-}
module Cubical.Categories.Instances.Cospan where
open import Cubical.Foundations.Prelude
open import Cubical.Categories.Category
open import Cubical.Data.Unit
open import Cubical.Data.Empty
open Category
data 𝟛 : Type ℓ-zero where
⓪ : 𝟛
① : 𝟛
② : 𝟛
CospanCat : Category ℓ-zero ℓ-zero
CospanCat .ob = 𝟛
CospanCat .Hom[_,_] ⓪ ① = Unit
CospanCat .Hom[_,_] ② ① = Unit
CospanCat .Hom[_,_] ⓪ ⓪ = Unit
CospanCat .Hom[_,_] ① ① = Unit
CospanCat .Hom[_,_] ② ② = Unit
CospanCat .Hom[_,_] _ _ = ⊥
CospanCat ._⋆_ {x = ⓪} {⓪} {⓪} f g = tt
CospanCat ._⋆_ {x = ①} {①} {①} f g = tt
CospanCat ._⋆_ {x = ②} {②} {②} f g = tt
CospanCat ._⋆_ {x = ⓪} {①} {①} f g = tt
CospanCat ._⋆_ {x = ②} {①} {①} f g = tt
CospanCat ._⋆_ {x = ⓪} {⓪} {①} f g = tt
CospanCat ._⋆_ {x = ②} {②} {①} f g = tt
CospanCat .id {⓪} = tt
CospanCat .id {①} = tt
CospanCat .id {②} = tt
CospanCat .⋆IdL {⓪} {①} _ = refl
CospanCat .⋆IdL {②} {①} _ = refl
CospanCat .⋆IdL {⓪} {⓪} _ = refl
CospanCat .⋆IdL {①} {①} _ = refl
CospanCat .⋆IdL {②} {②} _ = refl
CospanCat .⋆IdR {⓪} {①} _ = refl
CospanCat .⋆IdR {②} {①} _ = refl
CospanCat .⋆IdR {⓪} {⓪} _ = refl
CospanCat .⋆IdR {①} {①} _ = refl
CospanCat .⋆IdR {②} {②} _ = refl
CospanCat .⋆Assoc {⓪} {⓪} {⓪} {⓪} _ _ _ = refl
CospanCat .⋆Assoc {⓪} {⓪} {⓪} {①} _ _ _ = refl
CospanCat .⋆Assoc {⓪} {⓪} {①} {①} _ _ _ = refl
CospanCat .⋆Assoc {⓪} {①} {①} {①} _ _ _ = refl
CospanCat .⋆Assoc {①} {①} {①} {①} _ _ _ = refl
CospanCat .⋆Assoc {②} {②} {②} {②} _ _ _ = refl
CospanCat .⋆Assoc {②} {②} {②} {①} _ _ _ = refl
CospanCat .⋆Assoc {②} {②} {①} {①} _ _ _ = refl
CospanCat .⋆Assoc {②} {①} {①} {①} _ _ _ = refl
CospanCat .isSetHom {⓪} {⓪} = isSetUnit
CospanCat .isSetHom {⓪} {①} = isSetUnit
CospanCat .isSetHom {①} {①} = isSetUnit
CospanCat .isSetHom {②} {①} = isSetUnit
CospanCat .isSetHom {②} {②} = isSetUnit
-- makes it easier to write functors into CospanCat
isPropHomCospanCat : (x y : ob CospanCat) → isProp (CospanCat [ x , y ])
isPropHomCospanCat ⓪ ⓪ = isPropUnit
isPropHomCospanCat ⓪ ① = isPropUnit
isPropHomCospanCat ⓪ ② = isProp⊥
isPropHomCospanCat ① ⓪ = isProp⊥
isPropHomCospanCat ① ① = isPropUnit
isPropHomCospanCat ① ② = isProp⊥
isPropHomCospanCat ② ⓪ = isProp⊥
isPropHomCospanCat ② ① = isPropUnit
isPropHomCospanCat ② ② = isPropUnit
| 29.051282
| 72
| 0.635481
|
031cbdd612986c833417fd431dd22355fe964d89
| 213
|
agda
|
Agda
|
Cubical/HITs/S3/Base.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | 1
|
2020-03-23T23:52:11.000Z
|
2020-03-23T23:52:11.000Z
|
Cubical/HITs/S3/Base.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
Cubical/HITs/S3/Base.agda
|
limemloh/cubical
|
df4ef7edffd1c1deb3d4ff342c7178e9901c44f1
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.S3.Base where
open import Cubical.Foundations.Prelude
data S³ : Type₀ where
base : S³
surf : PathP (λ j → PathP (λ i → base ≡ base) refl refl) refl refl
| 21.3
| 68
| 0.680751
|
8b16fc86c9b0fb489e90f433feb65372bb660cdb
| 3,261
|
agda
|
Agda
|
agda-stdlib/src/Data/Maybe/Base.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 5
|
2020-10-07T12:07:53.000Z
|
2020-10-10T21:41:32.000Z
|
agda-stdlib/src/Data/Maybe/Base.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | null | null | null |
agda-stdlib/src/Data/Maybe/Base.agda
|
DreamLinuxer/popl21-artifact
|
fb380f2e67dcb4a94f353dbaec91624fcb5b8933
|
[
"MIT"
] | 1
|
2021-11-04T06:54:45.000Z
|
2021-11-04T06:54:45.000Z
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- The Maybe type and some operations
------------------------------------------------------------------------
-- The definitions in this file are reexported by Data.Maybe.
{-# OPTIONS --without-K --safe #-}
module Data.Maybe.Base where
open import Level
open import Data.Bool.Base using (Bool; true; false; not)
open import Data.Unit.Base using (⊤)
open import Data.These.Base using (These; this; that; these)
open import Data.Product as Prod using (_×_; _,_)
open import Function.Base
open import Relation.Nullary.Reflects
open import Relation.Nullary
private
variable
a b c : Level
A : Set a
B : Set b
C : Set c
------------------------------------------------------------------------
-- Definition
data Maybe (A : Set a) : Set a where
nothing : Maybe A
just : (x : A) → Maybe A
------------------------------------------------------------------------
-- Some operations
boolToMaybe : Bool → Maybe ⊤
boolToMaybe true = just _
boolToMaybe false = nothing
is-just : Maybe A → Bool
is-just (just _) = true
is-just nothing = false
is-nothing : Maybe A → Bool
is-nothing = not ∘ is-just
decToMaybe : Dec A → Maybe A
decToMaybe ( true because [a]) = just (invert [a])
decToMaybe (false because _ ) = nothing
-- A dependent eliminator.
maybe : ∀ {A : Set a} {B : Maybe A → Set b} →
((x : A) → B (just x)) → B nothing → (x : Maybe A) → B x
maybe j n (just x) = j x
maybe j n nothing = n
-- A non-dependent eliminator.
maybe′ : (A → B) → B → Maybe A → B
maybe′ = maybe
-- A defaulting mechanism
fromMaybe : A → Maybe A → A
fromMaybe = maybe′ id
-- A safe variant of "fromJust". If the value is nothing, then the
-- return type is the unit type.
module _ {a} {A : Set a} where
From-just : Maybe A → Set a
From-just (just _) = A
From-just nothing = Lift a ⊤
from-just : (x : Maybe A) → From-just x
from-just (just x) = x
from-just nothing = _
-- Functoriality: map
map : (A → B) → Maybe A → Maybe B
map f = maybe (just ∘ f) nothing
-- Applicative: ap
ap : Maybe (A → B) → Maybe A → Maybe B
ap nothing = const nothing
ap (just f) = map f
-- Monad: bind
infixl 1 _>>=_
_>>=_ : Maybe A → (A → Maybe B) → Maybe B
nothing >>= f = nothing
just a >>= f = f a
-- Alternative: <∣>
_<∣>_ : Maybe A → Maybe A → Maybe A
just x <∣> my = just x
nothing <∣> my = my
------------------------------------------------------------------------
-- Aligning and zipping
alignWith : (These A B → C) → Maybe A → Maybe B → Maybe C
alignWith f (just a) (just b) = just (f (these a b))
alignWith f (just a) nothing = just (f (this a))
alignWith f nothing (just b) = just (f (that b))
alignWith f nothing nothing = nothing
zipWith : (A → B → C) → Maybe A → Maybe B → Maybe C
zipWith f (just a) (just b) = just (f a b)
zipWith _ _ _ = nothing
align : Maybe A → Maybe B → Maybe (These A B)
align = alignWith id
zip : Maybe A → Maybe B → Maybe (A × B)
zip = zipWith _,_
------------------------------------------------------------------------
-- Injections.
thisM : A → Maybe B → These A B
thisM a = maybe′ (these a) (this a)
thatM : Maybe A → B → These A B
thatM = maybe′ these that
| 23.977941
| 72
| 0.544618
|
35c35b0463274eede2b9b837f1b9e6965c4a502d
| 8,855
|
agda
|
Agda
|
misc/RecursiveDescent/Hybrid/Lib.agda
|
yurrriq/parser-combinators
|
b396d35cc2cb7e8aea50b982429ee385f001aa88
|
[
"MIT"
] | 7
|
2016-12-13T05:23:14.000Z
|
2021-06-22T05:35:31.000Z
|
misc/RecursiveDescent/Hybrid/Lib.agda
|
nad/parser-combinators
|
76774f54f466cfe943debf2da731074fe0c33644
|
[
"MIT"
] | 1
|
2018-01-22T22:21:41.000Z
|
2018-01-24T16:39:37.000Z
|
misc/RecursiveDescent/Hybrid/Lib.agda
|
nad/parser-combinators
|
76774f54f466cfe943debf2da731074fe0c33644
|
[
"MIT"
] | null | null | null |
------------------------------------------------------------------------
-- A library of parser combinators
------------------------------------------------------------------------
-- This module also provides examples of parsers for which the indices
-- cannot be inferred.
module RecursiveDescent.Hybrid.Lib where
open import RecursiveDescent.Hybrid
import RecursiveDescent.Hybrid.Type as Type
open import RecursiveDescent.Index
open import Utilities
open import Data.Nat hiding (_≟_)
open import Data.Vec using (Vec; []; _∷_)
open import Data.Vec1 using (Vec₁; []; _∷_; map₀₁)
open import Data.List using (List; []; _∷_; foldr; reverse)
open import Data.Product.Record hiding (_×_)
open import Data.Product using (_×_) renaming (_,_ to pair)
open import Data.Bool hiding (_≟_)
open import Data.Function
open import Data.Maybe
open import Data.Unit hiding (_≟_)
open import Data.Bool.Properties as Bool
import Data.Char as Char
open Char using (Char; _==_)
open import Algebra
private
module BCS = CommutativeSemiring Bool.commutativeSemiring-∨-∧
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality using (refl)
------------------------------------------------------------------------
-- Applicative functor parsers
-- We could get these for free with better library support.
infixl 50 _⊛_ _⊛!_ _<⊛_ _⊛>_ _<$>_ _<$_ _⊗_ _⊗!_
_⊛_ : forall {tok nt i₁ i₂ r₁ r₂} ->
Parser tok nt i₁ (r₁ -> r₂) ->
Parser tok nt i₂ r₁ ->
Parser tok nt _ r₂
p₁ ⊛ p₂ = p₁ >>= \f -> p₂ >>= \x -> return (f x)
-- A variant: If the second parser does not accept the empty string,
-- then neither does the combination. (This is immediate for the first
-- parser, but for the second one a small lemma is needed, hence this
-- variant.)
_⊛!_ : forall {tok nt i₁ c₂ r₁ r₂} ->
Parser tok nt i₁ (r₁ -> r₂) ->
Parser tok nt (false , c₂) r₁ ->
Parser tok nt (false , _) r₂
_⊛!_ {i₁ = i₁} p₁ p₂ = cast (BCS.*-comm (proj₁ i₁) false) refl
(p₁ ⊛ p₂)
_<$>_ : forall {tok nt i r₁ r₂} ->
(r₁ -> r₂) ->
Parser tok nt i r₁ ->
Parser tok nt _ r₂
f <$> x = return f ⊛ x
_<⊛_ : forall {tok nt i₁ i₂ r₁ r₂} ->
Parser tok nt i₁ r₁ ->
Parser tok nt i₂ r₂ ->
Parser tok nt _ r₁
x <⊛ y = const <$> x ⊛ y
_⊛>_ : forall {tok nt i₁ i₂ r₁ r₂} ->
Parser tok nt i₁ r₁ ->
Parser tok nt i₂ r₂ ->
Parser tok nt _ r₂
x ⊛> y = flip const <$> x ⊛ y
_<$_ : forall {tok nt i r₁ r₂} ->
r₁ ->
Parser tok nt i r₂ ->
Parser tok nt _ r₁
x <$ y = const x <$> y
_⊗_ : forall {tok nt i₁ i₂ r₁ r₂} ->
Parser tok nt i₁ r₁ -> Parser tok nt i₂ r₂ ->
Parser tok nt _ (r₁ × r₂)
p₁ ⊗ p₂ = pair <$> p₁ ⊛ p₂
_⊗!_ : forall {tok nt i₁ c₂ r₁ r₂} ->
Parser tok nt i₁ r₁ -> Parser tok nt (false , c₂) r₂ ->
Parser tok nt (false , _) (r₁ × r₂)
p₁ ⊗! p₂ = pair <$> p₁ ⊛! p₂
------------------------------------------------------------------------
-- Parsing sequences
infix 55 _⋆ _+
-- Not accepted by the productivity checker:
-- mutual
-- _⋆ : forall {tok r d} ->
-- Parser tok (false , d) r ->
-- Parser tok _ (List r)
-- p ⋆ ~ return [] ∣ p +
-- _+ : forall {tok r d} ->
-- Parser tok (false , d) r ->
-- Parser tok _ (List r)
-- p + ~ _∷_ <$> p ⊛ p ⋆
-- By inlining some definitions we can show that the definitions are
-- productive, though. The following definitions have also been
-- simplified:
mutual
_⋆ : forall {tok nt r d} ->
Parser tok nt (false , d) r ->
Parser tok nt _ (List r)
p ⋆ ~ Type.alt _ _ (return []) (p +)
_+ : forall {tok nt r d} ->
Parser tok nt (false , d) r ->
Parser tok nt _ (List r)
p + ~ Type._!>>=_ p \x ->
Type._?>>=_ (p ⋆) \xs ->
return (x ∷ xs)
-- p sepBy sep parses one or more ps separated by seps.
_sepBy_ : forall {tok nt r r' i d} ->
Parser tok nt i r -> Parser tok nt (false , d) r' ->
Parser tok nt _ (List r)
p sepBy sep = _∷_ <$> p ⊛ (sep ⊛> p) ⋆
-- Note that the index of atLeast is only partly inferred; the
-- recursive structure of atLeast-index is given manually.
atLeast-index : Corners -> ℕ -> Index
atLeast-index c zero = _
atLeast-index c (suc n) = _
-- At least n occurrences of p.
atLeast : forall {tok nt c r} (n : ℕ) ->
Parser tok nt (false , c) r ->
Parser tok nt (atLeast-index c n) (List r)
atLeast zero p = p ⋆
atLeast (suc n) p = _∷_ <$> p ⊛ atLeast n p
-- Chains at least n occurrences of op, in an a-associative
-- manner. The ops are surrounded by ps.
chain≥ : forall {tok nt c₁ i₂ r} (n : ℕ) ->
Assoc ->
Parser tok nt (false , c₁) r ->
Parser tok nt i₂ (r -> r -> r) ->
Parser tok nt _ r
chain≥ n a p op = chain≥-combine a <$> p ⊛ atLeast n (op ⊗! p)
-- exactly n p parses n occurrences of p.
exactly-index : Index -> ℕ -> Index
exactly-index i zero = _
exactly-index i (suc n) = _
exactly : forall {tok nt i r} n ->
Parser tok nt i r ->
Parser tok nt (exactly-index i n) (Vec r n)
exactly zero p = return []
exactly (suc n) p = _∷_ <$> p ⊛ exactly n p
-- A function with a similar type:
sequence : forall {tok nt i r n} ->
Vec₁ (Parser tok nt i r) n ->
Parser tok nt (exactly-index i n) (Vec r n)
sequence [] = return []
sequence (p ∷ ps) = _∷_ <$> p ⊛ sequence ps
-- p between ps parses p repeatedly, between the elements of ps:
-- ∙ between (x ∷ y ∷ z ∷ []) ≈ x ∙ y ∙ z.
between-corners : Corners -> ℕ -> Corners
between-corners c′ zero = _
between-corners c′ (suc n) = _
_between_ : forall {tok nt i r c′ r′ n} ->
Parser tok nt i r ->
Vec₁ (Parser tok nt (false , c′) r′) (suc n) ->
Parser tok nt (false , between-corners c′ n) (Vec r n)
p between (x ∷ []) = [] <$ x
p between (x ∷ y ∷ xs) = _∷_ <$> (x ⊛> p) ⊛ (p between (y ∷ xs))
------------------------------------------------------------------------
-- N-ary variants of _∣_
-- choice ps parses one of the elements in ps.
choice-corners : Corners -> ℕ -> Corners
choice-corners c zero = _
choice-corners c (suc n) = _
choice : forall {tok nt c r n} ->
Vec₁ (Parser tok nt (false , c) r) n ->
Parser tok nt (false , choice-corners c n) r
choice [] = fail
choice (p ∷ ps) = p ∣ choice ps
-- choiceMap f xs ≈ choice (map f xs), but avoids use of Vec₁ and
-- fromList.
choiceMap-corners : forall {a} -> (a -> Corners) -> List a -> Corners
choiceMap-corners c [] = _
choiceMap-corners c (x ∷ xs) = _
choiceMap : forall {tok nt r a} {c : a -> Corners} ->
((x : a) -> Parser tok nt (false , c x) r) ->
(xs : List a) ->
Parser tok nt (false , choiceMap-corners c xs) r
choiceMap f [] = fail
choiceMap f (x ∷ xs) = f x ∣ choiceMap f xs
------------------------------------------------------------------------
-- sat and friends
sat : forall {tok nt r} ->
(tok -> Maybe r) -> Parser tok nt (0I ·I 1I) r
sat {tok} {nt} {r} p = symbol !>>= \c -> ok (p c)
where
okIndex : Maybe r -> Index
okIndex nothing = _
okIndex (just _) = _
ok : (x : Maybe r) -> Parser tok nt (okIndex x) r
ok nothing = fail
ok (just x) = return x
sat' : forall {tok nt} -> (tok -> Bool) -> Parser tok nt _ ⊤
sat' p = sat (boolToMaybe ∘ p)
any : forall {tok nt} -> Parser tok nt _ tok
any = sat just
------------------------------------------------------------------------
-- Token parsers
module Token (a : DecSetoid) where
open DecSetoid a using (_≟_) renaming (carrier to tok)
-- Parses a given token (or, really, a given equivalence class of
-- tokens).
sym : forall {nt} -> tok -> Parser tok nt _ tok
sym x = sat p
where
p : tok -> Maybe tok
p y with x ≟ y
... | yes _ = just y
... | no _ = nothing
-- Parses a sequence of tokens.
string : forall {nt n} -> Vec tok n -> Parser tok nt _ (Vec tok n)
string cs = sequence (map₀₁ sym cs)
------------------------------------------------------------------------
-- Character parsers
digit : forall {nt} -> Parser Char nt _ ℕ
digit = 0 <$ sym '0'
∣ 1 <$ sym '1'
∣ 2 <$ sym '2'
∣ 3 <$ sym '3'
∣ 4 <$ sym '4'
∣ 5 <$ sym '5'
∣ 6 <$ sym '6'
∣ 7 <$ sym '7'
∣ 8 <$ sym '8'
∣ 9 <$ sym '9'
where open Token Char.decSetoid
number : forall {nt} -> Parser Char nt _ ℕ
number = toNum <$> digit +
where
toNum = foldr (\n x -> 10 * x + n) 0 ∘ reverse
-- whitespace recognises an incomplete but useful list of whitespace
-- characters.
whitespace : forall {nt} -> Parser Char nt _ ⊤
whitespace = sat' isSpace
where
isSpace = \c ->
(c == ' ') ∨ (c == '\t') ∨ (c == '\n') ∨ (c == '\r')
| 29.615385
| 72
| 0.534613
|
341cc6a0a009aa465d19718e09e8558e0ad673b9
| 18,282
|
agda
|
Agda
|
Cubical/HITs/S1/Base.agda
|
mchristianl/cubical
|
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
|
[
"MIT"
] | null | null | null |
Cubical/HITs/S1/Base.agda
|
mchristianl/cubical
|
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
|
[
"MIT"
] | null | null | null |
Cubical/HITs/S1/Base.agda
|
mchristianl/cubical
|
cc6ad25d5ffbe4f20ea7020474f266d24b97caa0
|
[
"MIT"
] | null | null | null |
{-
Definition of the circle as a HIT with a proof that Ω(S¹) ≡ ℤ
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.S1.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Path
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Univalence
open import Cubical.Data.Nat
hiding (_+_ ; _·_ ; +-assoc ; +-comm)
open import Cubical.Data.Int
data S¹ : Type₀ where
base : S¹
loop : base ≡ base
-- Check that transp is the identity function for S¹
module _ where
transpS¹ : ∀ (φ : I) (u0 : S¹) → transp (λ _ → S¹) φ u0 ≡ u0
transpS¹ φ u0 = refl
compS1 : ∀ (φ : I) (u : ∀ i → Partial φ S¹) (u0 : S¹ [ φ ↦ u i0 ]) →
comp (λ _ → S¹) (\ i → u i) (outS u0) ≡ hcomp u (outS u0)
compS1 φ u u0 = refl
-- ΩS¹ ≡ Int
helix : S¹ → Type₀
helix base = Int
helix (loop i) = sucPathInt i
ΩS¹ : Type₀
ΩS¹ = base ≡ base
encode : ∀ x → base ≡ x → helix x
encode x p = subst helix p (pos zero)
winding : ΩS¹ → Int
winding = encode base
intLoop : Int → ΩS¹
intLoop (pos zero) = refl
intLoop (pos (suc n)) = intLoop (pos n) ∙ loop
intLoop (negsuc zero) = sym loop
intLoop (negsuc (suc n)) = intLoop (negsuc n) ∙ sym loop
decodeSquare : (n : Int) → PathP (λ i → base ≡ loop i) (intLoop (predInt n)) (intLoop n)
decodeSquare (pos zero) i j = loop (i ∨ ~ j)
decodeSquare (pos (suc n)) i j = hfill (λ k → λ { (j = i0) → base
; (j = i1) → loop k } )
(inS (intLoop (pos n) j)) i
decodeSquare (negsuc n) i j = hfill (λ k → λ { (j = i0) → base
; (j = i1) → loop (~ k) })
(inS (intLoop (negsuc n) j)) (~ i)
decode : (x : S¹) → helix x → base ≡ x
decode base = intLoop
decode (loop i) y j =
let n : Int
n = unglue (i ∨ ~ i) y
in hcomp (λ k → λ { (i = i0) → intLoop (predSuc y k) j
; (i = i1) → intLoop y j
; (j = i0) → base
; (j = i1) → loop i })
(decodeSquare n i j)
decodeEncode : (x : S¹) (p : base ≡ x) → decode x (encode x p) ≡ p
decodeEncode x p = J (λ y q → decode y (encode y q) ≡ q) (λ _ → refl) p
isSetΩS¹ : isSet ΩS¹
isSetΩS¹ p q r s j i =
hcomp (λ k → λ { (i = i0) → decodeEncode base p k
; (i = i1) → decodeEncode base q k
; (j = i0) → decodeEncode base (r i) k
; (j = i1) → decodeEncode base (s i) k })
(decode base (isSetInt (winding p) (winding q) (cong winding r) (cong winding s) j i))
-- This proof does not rely on rewriting hcomp with empty systems in
-- Int as ghcomp has been implemented!
windingIntLoop : (n : Int) → winding (intLoop n) ≡ n
windingIntLoop (pos zero) = refl
windingIntLoop (pos (suc n)) = cong sucInt (windingIntLoop (pos n))
windingIntLoop (negsuc zero) = refl
windingIntLoop (negsuc (suc n)) = cong predInt (windingIntLoop (negsuc n))
ΩS¹IsoInt : Iso ΩS¹ Int
Iso.fun ΩS¹IsoInt = winding
Iso.inv ΩS¹IsoInt = intLoop
Iso.rightInv ΩS¹IsoInt = windingIntLoop
Iso.leftInv ΩS¹IsoInt = decodeEncode base
ΩS¹≡Int : ΩS¹ ≡ Int
ΩS¹≡Int = isoToPath ΩS¹IsoInt
-- intLoop and winding are group homomorphisms
private
intLoop-sucInt : (z : Int) → intLoop (sucInt z) ≡ intLoop z ∙ loop
intLoop-sucInt (pos n) = refl
intLoop-sucInt (negsuc zero) = sym (lCancel loop)
intLoop-sucInt (negsuc (suc n)) =
rUnit (intLoop (negsuc n))
∙ (λ i → intLoop (negsuc n) ∙ lCancel loop (~ i))
∙ assoc (intLoop (negsuc n)) (sym loop) loop
intLoop-predInt : (z : Int) → intLoop (predInt z) ≡ intLoop z ∙ sym loop
intLoop-predInt (pos zero) = lUnit (sym loop)
intLoop-predInt (pos (suc n)) =
rUnit (intLoop (pos n))
∙ (λ i → intLoop (pos n) ∙ (rCancel loop (~ i)))
∙ assoc (intLoop (pos n)) loop (sym loop)
intLoop-predInt (negsuc n) = refl
intLoop-hom : (a b : Int) → (intLoop a) ∙ (intLoop b) ≡ intLoop (a + b)
intLoop-hom a (pos zero) = sym (rUnit (intLoop a))
intLoop-hom a (pos (suc n)) =
assoc (intLoop a) (intLoop (pos n)) loop
∙ (λ i → (intLoop-hom a (pos n) i) ∙ loop)
∙ sym (intLoop-sucInt (a + pos n))
intLoop-hom a (negsuc zero) = sym (intLoop-predInt a)
intLoop-hom a (negsuc (suc n)) =
assoc (intLoop a) (intLoop (negsuc n)) (sym loop)
∙ (λ i → (intLoop-hom a (negsuc n) i) ∙ (sym loop))
∙ sym (intLoop-predInt (a + negsuc n))
winding-hom : (a b : ΩS¹) → winding (a ∙ b) ≡ (winding a) + (winding b)
winding-hom a b i =
hcomp (λ t → λ { (i = i0) → winding (decodeEncode base a t ∙ decodeEncode base b t)
; (i = i1) → windingIntLoop (winding a + winding b) t })
(winding (intLoop-hom (winding a) (winding b) i))
-- Commutativity
comm-ΩS¹ : (p q : ΩS¹) → p ∙ q ≡ q ∙ p
comm-ΩS¹ p q = sym (cong₂ (_∙_) (decodeEncode base p) (decodeEncode base q))
∙ intLoop-hom (winding p) (winding q)
∙ cong intLoop (+-comm (winding p) (winding q))
∙ sym (intLoop-hom (winding q) (winding p))
∙ (cong₂ (_∙_) (decodeEncode base q) (decodeEncode base p))
-- Based homotopy group
basedΩS¹ : (x : S¹) → Type₀
basedΩS¹ x = x ≡ x
-- Proof that the homotopy group is actually independent on the basepoint
-- first, give a quasi-inverse to the basechange basedΩS¹→ΩS¹ for any loop i
-- (which does *not* match at endpoints)
private
ΩS¹→basedΩS¹-filler : I → I → ΩS¹ → I → S¹
ΩS¹→basedΩS¹-filler l i x j =
hfill (λ t → λ { (j = i0) → loop (i ∧ t)
; (j = i1) → loop (i ∧ t) })
(inS (x j)) l
basedΩS¹→ΩS¹-filler : (_ i : I) → basedΩS¹ (loop i) → I → S¹
basedΩS¹→ΩS¹-filler l i x j =
hfill (λ t → λ { (j = i0) → loop (i ∧ (~ t))
; (j = i1) → loop (i ∧ (~ t)) })
(inS (x j)) l
ΩS¹→basedΩS¹ : (i : I) → ΩS¹ → basedΩS¹ (loop i)
ΩS¹→basedΩS¹ i x j = ΩS¹→basedΩS¹-filler i1 i x j
basedΩS¹→ΩS¹ : (i : I) → basedΩS¹ (loop i) → ΩS¹
basedΩS¹→ΩS¹ i x j = basedΩS¹→ΩS¹-filler i1 i x j
basedΩS¹→ΩS¹→basedΩS¹ : (i : I) → (x : basedΩS¹ (loop i))
→ ΩS¹→basedΩS¹ i (basedΩS¹→ΩS¹ i x) ≡ x
basedΩS¹→ΩS¹→basedΩS¹ i x j k =
hcomp (λ t → λ { (j = i1) → basedΩS¹→ΩS¹-filler (~ t) i x k
; (j = i0) → ΩS¹→basedΩS¹ i (basedΩS¹→ΩS¹ i x) k
; (k = i0) → loop (i ∧ (t ∨ (~ j)))
; (k = i1) → loop (i ∧ (t ∨ (~ j))) })
(ΩS¹→basedΩS¹-filler (~ j) i (basedΩS¹→ΩS¹ i x) k)
ΩS¹→basedΩS¹→ΩS¹ : (i : I) → (x : ΩS¹)
→ basedΩS¹→ΩS¹ i (ΩS¹→basedΩS¹ i x) ≡ x
ΩS¹→basedΩS¹→ΩS¹ i x j k =
hcomp (λ t → λ { (j = i1) → ΩS¹→basedΩS¹-filler (~ t) i x k
; (j = i0) → basedΩS¹→ΩS¹ i (ΩS¹→basedΩS¹ i x) k
; (k = i0) → loop (i ∧ ((~ t) ∧ j))
; (k = i1) → loop (i ∧ ((~ t) ∧ j)) })
(basedΩS¹→ΩS¹-filler (~ j) i (ΩS¹→basedΩS¹ i x) k)
-- from the existence of our quasi-inverse, we deduce that the basechange is an equivalence
-- for all loop i
basedΩS¹→ΩS¹-isequiv : (i : I) → isEquiv (basedΩS¹→ΩS¹ i)
basedΩS¹→ΩS¹-isequiv i = isoToIsEquiv (iso (basedΩS¹→ΩS¹ i) (ΩS¹→basedΩS¹ i)
(ΩS¹→basedΩS¹→ΩS¹ i) (basedΩS¹→ΩS¹→basedΩS¹ i))
-- now extend the basechange so that both ends match
-- (and therefore we get a basechange for any x : S¹)
loop-conjugation : basedΩS¹→ΩS¹ i1 ≡ λ x → x
loop-conjugation i x =
let p = (doubleCompPath-elim loop x (sym loop))
∙ (λ i → (lUnit loop i ∙ x) ∙ sym loop)
in
((sym (decodeEncode base (basedΩS¹→ΩS¹ i1 x)))
∙ (λ t → intLoop (winding (p t)))
∙ (λ t → intLoop (winding-hom (intLoop (pos (suc zero)) ∙ x)
(intLoop (negsuc zero)) t))
∙ (λ t → intLoop ((winding-hom (intLoop (pos (suc zero))) x t)
+ (windingIntLoop (negsuc zero) t)))
∙ (λ t → intLoop (((windingIntLoop (pos (suc zero)) t) + (winding x)) + (negsuc zero)))
∙ (λ t → intLoop ((+-comm (pos (suc zero)) (winding x) t) + (negsuc zero)))
∙ (λ t → intLoop (+-assoc (winding x) (pos (suc zero)) (negsuc zero) (~ t)))
∙ (decodeEncode base x)) i
refl-conjugation : basedΩS¹→ΩS¹ i0 ≡ λ x → x
refl-conjugation i x j =
hfill (λ t → λ { (j = i0) → base
; (j = i1) → base })
(inS (x j)) (~ i)
basechange : (x : S¹) → basedΩS¹ x → ΩS¹
basechange base y = y
basechange (loop i) y =
hcomp (λ t → λ { (i = i0) → refl-conjugation t y
; (i = i1) → loop-conjugation t y })
(basedΩS¹→ΩS¹ i y)
-- for any loop i, the old basechange is equal to the new one
basedΩS¹→ΩS¹≡basechange : (i : I) → basedΩS¹→ΩS¹ i ≡ basechange (loop i)
basedΩS¹→ΩS¹≡basechange i j y =
hfill (λ t → λ { (i = i0) → refl-conjugation t y
; (i = i1) → loop-conjugation t y })
(inS (basedΩS¹→ΩS¹ i y)) j
-- so for any loop i, the extended basechange is an equivalence
basechange-isequiv-aux : (i : I) → isEquiv (basechange (loop i))
basechange-isequiv-aux i =
transport (λ j → isEquiv (basedΩS¹→ΩS¹≡basechange i j)) (basedΩS¹→ΩS¹-isequiv i)
-- as being an equivalence is contractible, basechange is an equivalence for all x : S¹
basechange-isequiv : (x : S¹) → isEquiv (basechange x)
basechange-isequiv base = basechange-isequiv-aux i0
basechange-isequiv (loop i) =
hcomp (λ t → λ { (i = i0) → basechange-isequiv-aux i0
; (i = i1) → isPropIsEquiv (basechange base) (basechange-isequiv-aux i1)
(basechange-isequiv-aux i0) t })
(basechange-isequiv-aux i)
basedΩS¹≡ΩS¹' : (x : S¹) → basedΩS¹ x ≡ ΩS¹
basedΩS¹≡ΩS¹' x = ua (basechange x , basechange-isequiv x)
basedΩS¹≡Int' : (x : S¹) → basedΩS¹ x ≡ Int
basedΩS¹≡Int' x = (basedΩS¹≡ΩS¹' x) ∙ ΩS¹≡Int
---- Alternative proof of the same thing -----
toPropElim : ∀ {ℓ} {B : S¹ → Type ℓ}
→ ((s : S¹) → isProp (B s))
→ B base
→ (s : S¹) → B s
toPropElim isprop b base = b
toPropElim isprop b (loop i) =
isOfHLevel→isOfHLevelDep 1 isprop b b loop i
toPropElim2 : ∀ {ℓ} {B : S¹ → S¹ → Type ℓ}
→ ((s t : S¹) → isProp (B s t))
→ B base base
→ (s t : S¹) → B s t
toPropElim2 isprop b base base = b
toPropElim2 isprop b base (loop i) =
isProp→PathP (λ i → isprop base (loop i)) b b i
toPropElim2 isprop b (loop i) base =
isProp→PathP (λ i → isprop (loop i) base) b b i
toPropElim2 {B = B} isprop b (loop i) (loop j) =
isSet→SquareP (λ _ _ → isOfHLevelSuc 1 (isprop _ _))
(isProp→PathP (λ i₁ → isprop base (loop i₁)) b b)
(isProp→PathP (λ i₁ → isprop base (loop i₁)) b b)
(isProp→PathP (λ i₁ → isprop (loop i₁) base) b b)
(isProp→PathP (λ i₁ → isprop (loop i₁) base) b b) i j
toSetElim2 : ∀ {ℓ} {B : S¹ → S¹ → Type ℓ}
→ ((s t : S¹) → isSet (B s t))
→ (x : B base base)
→ PathP (λ i → B base (loop i)) x x
→ PathP (λ i → B (loop i) base) x x
→ (s t : S¹) → B s t
toSetElim2 isset b right left base base = b
toSetElim2 isset b right left base (loop i) = right i
toSetElim2 isset b right left (loop i) base = left i
toSetElim2 isset b right left (loop i) (loop j) =
isSet→SquareP (λ _ _ → isset _ _) right right left left i j
isSetΩx : (x : S¹) → isSet (x ≡ x)
isSetΩx = toPropElim (λ _ → isPropIsSet) isSetΩS¹
basechange2 : (x : S¹) → ΩS¹ → (x ≡ x)
basechange2 base p = p
basechange2 (loop i) p =
hcomp (λ k → λ { (i = i0) → lUnit (rUnit p (~ k)) (~ k)
; (i = i1) → (cong ((sym loop) ∙_) (comm-ΩS¹ p loop)
∙ assoc (sym loop) loop p
∙ cong (_∙ p) (lCancel loop)
∙ sym (lUnit _)) k })
((λ j → loop (~ j ∧ i)) ∙ p ∙ λ j → loop (j ∧ i))
basechange2⁻ : (x : S¹) → (x ≡ x) → ΩS¹
basechange2⁻ base p = p
basechange2⁻ (loop i) p =
hcomp (λ k → λ { (i = i0) → lUnit (rUnit p (~ k)) (~ k)
; (i = i1) → (cong (loop ∙_) (comm-ΩS¹ p (sym loop))
∙ assoc loop (sym loop) p
∙ cong (_∙ p) (rCancel loop)
∙ sym (lUnit _)) k })
((λ j → loop (i ∧ j)) ∙ p ∙ λ j → loop (i ∧ (~ j)))
basechange2-sect : (x : S¹) → section (basechange2 x) (basechange2⁻ x)
basechange2-sect =
toPropElim (λ _ → isOfHLevelΠ 1 λ _ → isSetΩx _ _ _ )
λ _ → refl
basechange2-retr : (x : S¹) → retract (basechange2 x) (basechange2⁻ x)
basechange2-retr =
toPropElim (λ s → isOfHLevelΠ 1 λ x → isSetΩx _ _ _)
λ _ → refl
basedΩS¹≡ΩS¹ : (x : S¹) → basedΩS¹ x ≡ ΩS¹
basedΩS¹≡ΩS¹ x = isoToPath (iso (basechange2⁻ x)
(basechange2 x)
(basechange2-retr x)
(basechange2-sect x))
basedΩS¹≡Int : (x : S¹) → basedΩS¹ x ≡ Int
basedΩS¹≡Int x = (basedΩS¹≡ΩS¹ x) ∙ ΩS¹≡Int
-- baschange2⁻ is a morphism
basechange2⁻-morph : (x : S¹) (p q : x ≡ x) →
basechange2⁻ x (p ∙ q) ≡ basechange2⁻ x p ∙ basechange2⁻ x q
basechange2⁻-morph =
toPropElim {B = λ x → (p q : x ≡ x) → basechange2⁻ x (p ∙ q) ≡ basechange2⁻ x p ∙ basechange2⁻ x q}
(λ _ → isPropΠ2 λ _ _ → isSetΩS¹ _ _)
λ _ _ → refl
-- Some tests
module _ where
private
test-winding-pos : winding (intLoop (pos 5)) ≡ pos 5
test-winding-pos = refl
test-winding-neg : winding (intLoop (negsuc 5)) ≡ negsuc 5
test-winding-neg = refl
-- the inverse when S¹ is seen as a group
invLooper : S¹ → S¹
invLooper base = base
invLooper (loop i) = loop (~ i)
invInvolutive : section invLooper invLooper
invInvolutive base = refl
invInvolutive (loop i) = refl
invS¹Equiv : S¹ ≃ S¹
invS¹Equiv = isoToEquiv theIso
where
theIso : Iso S¹ S¹
Iso.fun theIso = invLooper
Iso.inv theIso = invLooper
Iso.rightInv theIso = invInvolutive
Iso.leftInv theIso = invInvolutive
invS¹Path : S¹ ≡ S¹
invS¹Path = ua invS¹Equiv
-- rot, used in the Hopf fibration
rotLoop : (a : S¹) → a ≡ a
rotLoop base = loop
rotLoop (loop i) j =
hcomp (λ k → λ { (i = i0) → loop (j ∨ ~ k)
; (i = i1) → loop (j ∧ k)
; (j = i0) → loop (i ∨ ~ k)
; (j = i1) → loop (i ∧ k)}) base
rot : S¹ → S¹ → S¹
rot base x = x
rot (loop i) x = rotLoop x i
_*_ : S¹ → S¹ → S¹
a * b = rot a b
infixl 30 _*_
-- rot i j = filler-rot i j i1
filler-rot : I → I → I → S¹
filler-rot i j = hfill (λ k → λ { (i = i0) → loop (j ∨ ~ k)
; (i = i1) → loop (j ∧ k)
; (j = i0) → loop (i ∨ ~ k)
; (j = i1) → loop (i ∧ k) }) (inS base)
isPropFamS¹ : ∀ {ℓ} (P : S¹ → Type ℓ) (pP : (x : S¹) → isProp (P x)) (b0 : P base) →
PathP (λ i → P (loop i)) b0 b0
isPropFamS¹ P pP b0 i = pP (loop i) (transp (λ j → P (loop (i ∧ j))) (~ i) b0)
(transp (λ j → P (loop (i ∨ ~ j))) i b0) i
rotIsEquiv : (a : S¹) → isEquiv (rot a)
rotIsEquiv base = idIsEquiv S¹
rotIsEquiv (loop i) = isPropFamS¹ (λ x → isEquiv (rot x))
(λ x → isPropIsEquiv (rot x))
(idIsEquiv _) i
-- more direct definition of the rot (loop i) equivalence
rotLoopInv : (a : S¹) → PathP (λ i → rotLoop (rotLoop a (~ i)) i ≡ a) refl refl
rotLoopInv a i j = homotopySymInv rotLoop a j i
rotLoopEquiv : (i : I) → S¹ ≃ S¹
rotLoopEquiv i =
isoToEquiv
(iso (λ a → rotLoop a i)
(λ a → rotLoop a (~ i))
(λ a → rotLoopInv a i)
(λ a → rotLoopInv a (~ i)))
-- some cancellation laws, used in the Hopf fibration
private
rotInv-aux-1 : I → I → I → I → S¹
rotInv-aux-1 j k i =
hfill (λ l → λ { (k = i0) → (loop (i ∧ ~ l)) * loop j
; (k = i1) → loop j
; (i = i0) → (loop k * loop j) * loop (~ k)
; (i = i1) → loop (~ k ∧ ~ l) * loop j })
(inS ((loop (k ∨ i) * loop j) * loop (~ k)))
rotInv-aux-2 : I → I → I → S¹
rotInv-aux-2 i j k =
hcomp (λ l → λ { (k = i0) → invLooper (filler-rot (~ i) (~ j) l)
; (k = i1) → loop (j ∧ l)
; (i = i0) → filler-rot k j l
; (i = i1) → loop (j ∧ l)
; (j = i0) → loop (i ∨ k ∨ (~ l))
; (j = i1) → loop ((i ∨ k) ∧ l) })
(base)
rotInv-aux-3 : I → I → I → I → S¹
rotInv-aux-3 j k i =
hfill (λ l → λ { (k = i0) → rotInv-aux-2 i j l
; (k = i1) → loop j
; (i = i0) → loop (k ∨ l) * loop j
; (i = i1) → loop k * (invLooper (loop (~ j) * loop k)) })
(inS (loop k * (invLooper (loop (~ j) * loop (k ∨ ~ i)))))
rotInv-aux-4 : I → I → I → I → S¹
rotInv-aux-4 j k i =
hfill (λ l → λ { (k = i0) → rotInv-aux-2 i j l
; (k = i1) → loop j
; (i = i0) → loop j * loop (k ∨ l)
; (i = i1) → (invLooper (loop (~ j) * loop k)) * loop k })
(inS ((invLooper (loop (~ j) * loop (k ∨ ~ i))) * loop k))
rotInv-1 : (a b : S¹) → b * a * invLooper b ≡ a
rotInv-1 base base i = base
rotInv-1 base (loop k) i = rotInv-aux-1 i0 k i i1
rotInv-1 (loop j) base i = loop j
rotInv-1 (loop j) (loop k) i = rotInv-aux-1 j k i i1
rotInv-2 : (a b : S¹) → invLooper b * a * b ≡ a
rotInv-2 base base i = base
rotInv-2 base (loop k) i = rotInv-aux-1 i0 (~ k) i i1
rotInv-2 (loop j) base i = loop j
rotInv-2 (loop j) (loop k) i = rotInv-aux-1 j (~ k) i i1
rotInv-3 : (a b : S¹) → b * (invLooper (invLooper a * b)) ≡ a
rotInv-3 base base i = base
rotInv-3 base (loop k) i = rotInv-aux-3 i0 k (~ i) i1
rotInv-3 (loop j) base i = loop j
rotInv-3 (loop j) (loop k) i = rotInv-aux-3 j k (~ i) i1
rotInv-4 : (a b : S¹) → invLooper (b * invLooper a) * b ≡ a
rotInv-4 base base i = base
rotInv-4 base (loop k) i = rotInv-aux-4 i0 k (~ i) i1
rotInv-4 (loop j) base i = loop j
rotInv-4 (loop j) (loop k) i = rotInv-aux-4 j k (~ i) i1
| 37.158537
| 101
| 0.535335
|
fde40973d328974b2f66dd7279a3b749ee782699
| 1,045
|
agda
|
Agda
|
src/System/FilePath.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 111
|
2015-01-05T11:28:15.000Z
|
2022-02-12T23:29:26.000Z
|
src/System/FilePath.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 59
|
2016-02-09T05:36:44.000Z
|
2022-01-14T07:32:36.000Z
|
src/System/FilePath.agda
|
t-more/agda-prelude
|
da4fca7744d317b8843f2bc80a923972f65548d3
|
[
"MIT"
] | 24
|
2015-03-12T18:03:45.000Z
|
2021-04-22T06:10:41.000Z
|
-- | NOTE: This module can only represent file paths which are valid strings.
-- On Linux, a file path may be an arbitrary sequence of bytes, but using anything
-- except utf8 for file paths is a terrible idea.
--
-- What should happen if we come across a non utf8 path from an untrusted source?
-- crash -> denial-of-service
-- ignore -> maybe security holes
--
-- Currently, the behaviour for non-textual file paths is undefined.
module System.FilePath where
open import Prelude.Unit
open import Prelude.String
data Kind : Set where
Rel : Kind
Abs : Kind
abstract
record Path (kind : Kind) : Set where
constructor mkPath
field
path : String
open import Prelude.Monoid
open Path
_//_ : ∀ {k} → Path k → Path Rel → Path k
x // y = mkPath (path x <> "/" <> path y)
_∙_ : ∀ {k} → Path k → String → Path k
p ∙ ext = mkPath (path p <> "." <> ext)
toString : ∀ {k} → Path k → String
toString p = path p
relative : String → Path Rel
relative = mkPath
absolute : String → Path Abs
absolute = mkPath
| 24.880952
| 82
| 0.665072
|
0df478257e6b77e5bb7942d5be2020a2f20ca363
| 18,830
|
agda
|
Agda
|
Definition/LogicalRelation/Substitution/Introductions/SingleSubst.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 30
|
2017-05-20T03:05:21.000Z
|
2022-03-30T18:01:07.000Z
|
Definition/LogicalRelation/Substitution/Introductions/SingleSubst.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 4
|
2017-06-22T12:49:23.000Z
|
2021-02-22T10:37:24.000Z
|
Definition/LogicalRelation/Substitution/Introductions/SingleSubst.agda
|
fhlkfy/logrel-mltt
|
ea83fc4f618d1527d64ecac82d7d17e2f18ac391
|
[
"MIT"
] | 8
|
2017-10-18T14:18:20.000Z
|
2021-11-27T15:58:33.000Z
|
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Introductions.SingleSubst {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped hiding (_∷_)
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Weakening using (id)
open import Definition.Typed.Properties
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Properties
open import Definition.LogicalRelation.Substitution.Conversion
open import Definition.LogicalRelation.Substitution.Weakening
open import Tools.Nat
open import Tools.Product
import Tools.PropositionalEquality as PE
private
variable
n : Nat
Γ : Con Term n
-- Validity of substitution of single variable in types.
substS : ∀ {F G t l} ([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([G] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G / [Γ] ∙ [F])
([t] : Γ ⊩ᵛ⟨ l ⟩ t ∷ F / [Γ] / [F])
→ Γ ⊩ᵛ⟨ l ⟩ G [ t ] / [Γ]
substS {F = F} {G} {t} [Γ] [F] [G] [t] {σ = σ} ⊢Δ [σ] =
let Geq = substConsId G
G[t] = proj₁ ([G] ⊢Δ ([σ] , (proj₁ ([t] ⊢Δ [σ]))))
G[t]′ = irrelevance′ Geq G[t]
in G[t]′
, (λ {σ′} [σ′] [σ≡σ′] →
irrelevanceEq″ Geq
(substConsId G)
G[t] G[t]′
(proj₂ ([G] ⊢Δ
([σ] , proj₁ ([t] ⊢Δ [σ])))
([σ′] , proj₁ ([t] ⊢Δ [σ′]))
(([σ≡σ′] , (proj₂ ([t] ⊢Δ [σ]) [σ′] [σ≡σ′])))))
-- Validity of substitution of single variable in type equality.
substSEq : ∀ {F F′ G G′ t t′ l} ([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([F′] : Γ ⊩ᵛ⟨ l ⟩ F′ / [Γ])
([F≡F′] : Γ ⊩ᵛ⟨ l ⟩ F ≡ F′ / [Γ] / [F])
([G] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G / [Γ] ∙ [F])
([G′] : Γ ∙ F′ ⊩ᵛ⟨ l ⟩ G′ / [Γ] ∙ [F′])
([G≡G′] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G ≡ G′ / [Γ] ∙ [F] / [G])
([t] : Γ ⊩ᵛ⟨ l ⟩ t ∷ F / [Γ] / [F])
([t′] : Γ ⊩ᵛ⟨ l ⟩ t′ ∷ F′ / [Γ] / [F′])
([t≡t′] : Γ ⊩ᵛ⟨ l ⟩ t ≡ t′ ∷ F / [Γ] / [F])
→ Γ ⊩ᵛ⟨ l ⟩ G [ t ] ≡ G′ [ t′ ] / [Γ]
/ substS {F = F} {G} {t} [Γ] [F] [G] [t]
substSEq {F = F} {F′} {G} {G′} {t} {t′}
[Γ] [F] [F′] [F≡F′] [G] [G′] [G≡G′] [t] [t′] [t≡t′] {σ = σ} ⊢Δ [σ] =
let Geq = substConsId G
G′eq = substConsId G′
G[t] = (proj₁ ([G] ⊢Δ ([σ] , (proj₁ ([t] ⊢Δ [σ])))))
G[t]′ = irrelevance′ Geq G[t]
[t]′ = convᵛ {t = t} {F} {F′} [Γ] [F] [F′] [F≡F′] [t]
G′[t] = (proj₁ ([G′] ⊢Δ ([σ] , proj₁ ([t]′ ⊢Δ [σ]))))
G[t]≡G′[t] = irrelevanceEq′ Geq G[t] G[t]′
([G≡G′] ⊢Δ ([σ] , proj₁ ([t] ⊢Δ [σ])))
G′[t]≡G′[t′] = irrelevanceEq″ PE.refl G′eq G′[t] G′[t]
(proj₂ ([G′] ⊢Δ ([σ] , proj₁ ([t]′ ⊢Δ [σ])))
([σ] , proj₁ ([t′] ⊢Δ [σ]))
(reflSubst [Γ] ⊢Δ [σ] ,
convEqᵛ {t = t} {t′} {F} {F′}
[Γ] [F] [F′] [F≡F′] [t≡t′] ⊢Δ [σ]))
G′[t′] = (proj₁ ([G′] ⊢Δ ([σ] , proj₁ ([t′] ⊢Δ [σ]))))
G′[t′]′ = irrelevance′ G′eq G′[t′]
in transEq G[t]′ G′[t] G′[t′]′ G[t]≡G′[t] G′[t]≡G′[t′]
-- Validity of substitution of single variable in terms.
substSTerm : ∀ {F G t f l} ([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([G] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G / [Γ] ∙ [F])
([f] : Γ ∙ F ⊩ᵛ⟨ l ⟩ f ∷ G / [Γ] ∙ [F] / [G])
([t] : Γ ⊩ᵛ⟨ l ⟩ t ∷ F / [Γ] / [F])
→ Γ ⊩ᵛ⟨ l ⟩ f [ t ] ∷ G [ t ] / [Γ]
/ substS {F = F} {G} {t} [Γ] [F] [G] [t]
substSTerm {F = F} {G} {t} {f} [Γ] [F] [G] [f] [t] {σ = σ} ⊢Δ [σ] =
let prfG = substConsId G
prff = substConsId f
G[t] = proj₁ ([G] ⊢Δ ([σ] , proj₁ ([t] ⊢Δ [σ])))
G[t]′ = irrelevance′ prfG G[t]
f[t] = proj₁ ([f] ⊢Δ ([σ] , proj₁ ([t] ⊢Δ [σ])))
f[t]′ = irrelevanceTerm″ prfG prff G[t] G[t]′ f[t]
in f[t]′
, (λ {σ′} [σ′] [σ≡σ′] →
irrelevanceEqTerm″
prff
(substConsId f)
prfG G[t] G[t]′
(proj₂ ([f] ⊢Δ ([σ] , proj₁ ([t] ⊢Δ [σ])))
([σ′] , proj₁ ([t] ⊢Δ [σ′]))
([σ≡σ′] , proj₂ ([t] ⊢Δ [σ]) [σ′] [σ≡σ′])))
-- Validity of substitution of single lifted variable in types.
subst↑S : ∀ {F G t l} ([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([G] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G / [Γ] ∙ [F])
([t] : Γ ∙ F ⊩ᵛ⟨ l ⟩ t ∷ wk1 F / [Γ] ∙ [F]
/ wk1ᵛ {A = F} {F} [Γ] [F] [F])
→ Γ ∙ F ⊩ᵛ⟨ l ⟩ G [ t ]↑ / [Γ] ∙ [F]
subst↑S {F = F} {G} {t} [Γ] [F] [G] [t] {σ = σ} ⊢Δ [σ] =
let [wk1F] = wk1ᵛ {A = F} {F} [Γ] [F] [F]
[σwk1F] = proj₁ ([wk1F] {σ = σ} ⊢Δ [σ])
[σwk1F]′ = proj₁ ([F] {σ = tail σ} ⊢Δ (proj₁ [σ]))
[t]′ = irrelevanceTerm′ (subst-wk F) [σwk1F] [σwk1F]′ (proj₁ ([t] ⊢Δ [σ]))
G[t] = proj₁ ([G] {σ = consSubst (tail σ) (subst σ t)} ⊢Δ
(proj₁ [σ] , [t]′))
G[t]′ = irrelevance′ (substConsTailId {σ = σ} {G} {t}) G[t]
in G[t]′
, (λ {σ′} [σ′] [σ≡σ′] →
let [σ′t] = irrelevanceTerm′ (subst-wk F)
(proj₁ ([wk1F] {σ = σ′} ⊢Δ [σ′]))
(proj₁ ([F] ⊢Δ (proj₁ [σ′])))
(proj₁ ([t] ⊢Δ [σ′]))
[σt≡σ′t] = irrelevanceEqTerm′ (subst-wk F) [σwk1F] [σwk1F]′
(proj₂ ([t] ⊢Δ [σ]) [σ′] [σ≡σ′])
[σG[t]≡σ′G[t]] = proj₂ ([G] ⊢Δ (proj₁ [σ] , [t]′))
(proj₁ [σ′] , [σ′t])
(proj₁ [σ≡σ′] , [σt≡σ′t])
in irrelevanceEq″ (substConsTailId {σ = σ} {G} {t} ) (substConsTailId {σ = σ′} {G} {t})
G[t] G[t]′ [σG[t]≡σ′G[t]])
-- Validity of substitution of single lifted variable in type equality.
subst↑SEq : ∀ {F G G′ t t′ l} ([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([G] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G / [Γ] ∙ [F])
([G′] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G′ / [Γ] ∙ [F])
([G≡G′] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G ≡ G′ / [Γ] ∙ [F] / [G])
([t] : Γ ∙ F ⊩ᵛ⟨ l ⟩ t ∷ wk1 F / [Γ] ∙ [F]
/ wk1ᵛ {A = F} {F} [Γ] [F] [F])
([t′] : Γ ∙ F ⊩ᵛ⟨ l ⟩ t′ ∷ wk1 F / [Γ] ∙ [F]
/ wk1ᵛ {A = F} {F} [Γ] [F] [F])
([t≡t′] : Γ ∙ F ⊩ᵛ⟨ l ⟩ t ≡ t′ ∷ wk1 F / [Γ] ∙ [F]
/ wk1ᵛ {A = F} {F} [Γ] [F] [F])
→ Γ ∙ F ⊩ᵛ⟨ l ⟩ G [ t ]↑ ≡ G′ [ t′ ]↑ / [Γ] ∙ [F]
/ subst↑S {F = F} {G} {t} [Γ] [F] [G] [t]
subst↑SEq {F = F} {G} {G′} {t} {t′}
[Γ] [F] [G] [G′] [G≡G′] [t] [t′] [t≡t′] {σ = σ} ⊢Δ [σ] =
let [wk1F] = wk1ᵛ {A = F} {F} [Γ] [F] [F]
[σwk1F] = proj₁ ([wk1F] {σ = σ} ⊢Δ [σ])
[σwk1F]′ = proj₁ ([F] {σ = tail σ} ⊢Δ (proj₁ [σ]))
[t]′ = irrelevanceTerm′ (subst-wk F) [σwk1F] [σwk1F]′ (proj₁ ([t] ⊢Δ [σ]))
[t′]′ = irrelevanceTerm′ (subst-wk F) [σwk1F] [σwk1F]′ (proj₁ ([t′] ⊢Δ [σ]))
[t≡t′]′ = irrelevanceEqTerm′ (subst-wk F) [σwk1F] [σwk1F]′ ([t≡t′] ⊢Δ [σ])
G[t] = proj₁ ([G] ⊢Δ (proj₁ [σ] , [t]′))
G[t]′ = irrelevance′ (substConsTailId {σ = σ} {G} {t}) G[t]
G′[t] = proj₁ ([G′] ⊢Δ (proj₁ [σ] , [t]′))
G′[t]′ = irrelevance′ (substConsTailId {σ = σ} {G′} {t}) G′[t]
G′[t′] = proj₁ ([G′] ⊢Δ (proj₁ [σ] , [t′]′))
G′[t′]′ = irrelevance′ (substConsTailId {σ = σ} {G′} {t′}) G′[t′]
G[t]≡G′[t] = irrelevanceEq″ (substConsTailId {σ = σ} {G} {t}) (substConsTailId {σ = σ} {G′} {t})
G[t] G[t]′ ([G≡G′] ⊢Δ (proj₁ [σ] , [t]′))
G′[t]≡G′[t′] = irrelevanceEq″ (substConsTailId {σ = σ} {G′} {t})
(substConsTailId {σ = σ} {G′} {t′})
G′[t] G′[t]′
(proj₂ ([G′] ⊢Δ (proj₁ [σ] , [t]′))
(proj₁ [σ] , [t′]′)
(reflSubst [Γ] ⊢Δ (proj₁ [σ]) , [t≡t′]′))
in transEq G[t]′ G′[t]′ G′[t′]′ G[t]≡G′[t] G′[t]≡G′[t′]
-- Helper function for reducible substitution of Π-types with specific typing derivations.
substSΠ₁′ : ∀ {F G t l l′} W
([ΠFG] : Γ ⊩⟨ l ⟩B⟨ W ⟩ ⟦ W ⟧ F ▹ G)
([F] : Γ ⊩⟨ l′ ⟩ F)
([t] : Γ ⊩⟨ l′ ⟩ t ∷ F / [F])
→ Γ ⊩⟨ l ⟩ G [ t ]
substSΠ₁′ {t = t} W (noemb (Bᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext)) [F]₁ [t] =
let F≡F′ , G≡G′ = B-PE-injectivity W (whnfRed* (red D) ⟦ W ⟧ₙ)
Feq = PE.trans F≡F′ (PE.sym (wk-id _))
Geq = PE.cong (λ x → x [ _ ]) (PE.trans (wk-lift-id _) (PE.sym G≡G′))
⊢Γ = wf (escape [F]₁)
[t]′ = irrelevanceTerm′ Feq [F]₁ ([F] id ⊢Γ) [t]
in irrelevance′ Geq ([G] id ⊢Γ [t]′)
substSΠ₁′ W (emb 0<1 x) [F]₁ [t] = emb 0<1 (substSΠ₁′ W x [F]₁ [t])
-- Reducible substitution of Π-types.
substSΠ₁ : ∀ {F G t l l′} W
([ΠFG] : Γ ⊩⟨ l ⟩ ⟦ W ⟧ F ▹ G)
([F] : Γ ⊩⟨ l′ ⟩ F)
([t] : Γ ⊩⟨ l′ ⟩ t ∷ F / [F])
→ Γ ⊩⟨ l ⟩ G [ t ]
substSΠ₁ W [ΠFG] [F] [t] = substSΠ₁′ W (B-elim W [ΠFG]) [F] [t]
-- Helper function for reducible substitution of Π-congruence with specific typing derivations.
substSΠ₂′ : ∀ {F F′ G G′ t t′ l l′ l″ l‴} W
([ΠFG] : Γ ⊩⟨ l ⟩B⟨ W ⟩ ⟦ W ⟧ F ▹ G)
([ΠFG≡ΠF′G′] : Γ ⊩⟨ l ⟩ ⟦ W ⟧ F ▹ G ≡ ⟦ W ⟧ F′ ▹ G′ / B-intr W [ΠFG])
([F] : Γ ⊩⟨ l′ ⟩ F)
([F′] : Γ ⊩⟨ l′ ⟩ F′)
([t] : Γ ⊩⟨ l′ ⟩ t ∷ F / [F])
([t′] : Γ ⊩⟨ l′ ⟩ t′ ∷ F′ / [F′])
([t≡t′] : Γ ⊩⟨ l′ ⟩ t ≡ t′ ∷ F / [F])
([G[t]] : Γ ⊩⟨ l″ ⟩ G [ t ])
([G′[t′]] : Γ ⊩⟨ l‴ ⟩ G′ [ t′ ])
→ Γ ⊩⟨ l″ ⟩ G [ t ] ≡ G′ [ t′ ] / [G[t]]
substSΠ₂′ W (noemb (Bᵣ F G D ⊢F ⊢G A≡A [F] [G] G-ext))
(B₌ F″ G″ D′ A≡B [F≡F′] [G≡G′])
[F]₁ [F′] [t] [t′] [t≡t′] [G[t]] [G′[t′]] =
let F≡F′ , G≡G′ = B-PE-injectivity W (whnfRed* (red D) (⟦ W ⟧ₙ))
F′≡F″ , G′≡G″ = B-PE-injectivity W (whnfRed* D′ ⟦ W ⟧ₙ)
Feq = PE.trans F≡F′ (PE.sym (wk-id _))
F′eq = PE.trans F′≡F″ (PE.sym (wk-id _))
Geq = PE.cong (λ x → x [ _ ]) (PE.trans (wk-lift-id _) (PE.sym G≡G′))
Geq′ = PE.cong (λ x → x [ _ ]) (PE.trans G′≡G″ (PE.sym (wk-lift-id _)))
⊢Γ = wf (escape [F]₁)
[t]′ = irrelevanceTerm′ Feq [F]₁ ([F] id ⊢Γ) [t]
[t′]′ = convTerm₂′ F′eq ([F] id ⊢Γ) [F′] ([F≡F′] id ⊢Γ) [t′]
[t≡t′]′ = irrelevanceEqTerm′ Feq [F]₁ ([F] id ⊢Γ) [t≡t′]
[Gt≡Gt′] = G-ext id ⊢Γ [t]′ [t′]′ [t≡t′]′
[Gt′≡G′t′] = [G≡G′] id ⊢Γ [t′]′
in irrelevanceEq′ Geq ([G] id ⊢Γ [t]′) [G[t]]
(transEq′ PE.refl Geq′ ([G] id ⊢Γ [t]′) ([G] id ⊢Γ [t′]′)
[G′[t′]] [Gt≡Gt′] [Gt′≡G′t′])
substSΠ₂′ W (emb 0<1 x) = substSΠ₂′ W x
-- Reducible substitution of Π-congruence.
substSΠ₂ : ∀ {F F′ G G′ t t′ l l′ l″ l‴} W
([ΠFG] : Γ ⊩⟨ l ⟩ ⟦ W ⟧ F ▹ G)
([ΠFG≡ΠF′G′] : Γ ⊩⟨ l ⟩ ⟦ W ⟧ F ▹ G ≡ ⟦ W ⟧ F′ ▹ G′ / [ΠFG])
([F] : Γ ⊩⟨ l′ ⟩ F)
([F′] : Γ ⊩⟨ l′ ⟩ F′)
([t] : Γ ⊩⟨ l′ ⟩ t ∷ F / [F])
([t′] : Γ ⊩⟨ l′ ⟩ t′ ∷ F′ / [F′])
([t≡t′] : Γ ⊩⟨ l′ ⟩ t ≡ t′ ∷ F / [F])
([G[t]] : Γ ⊩⟨ l″ ⟩ G [ t ])
([G′[t′]] : Γ ⊩⟨ l‴ ⟩ G′ [ t′ ])
→ Γ ⊩⟨ l″ ⟩ G [ t ] ≡ G′ [ t′ ] / [G[t]]
substSΠ₂ W [ΠFG] [ΠFG≡ΠF′G′] =
let [ΠFG≡ΠF′G′]′ = irrelevanceEq [ΠFG] (B-intr W (B-elim W [ΠFG])) [ΠFG≡ΠF′G′]
in substSΠ₂′ W (B-elim W [ΠFG]) [ΠFG≡ΠF′G′]′
-- Valid substitution of Π-types.
substSΠ : ∀ {F G t l} W
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([ΠFG] : Γ ⊩ᵛ⟨ l ⟩ ⟦ W ⟧ F ▹ G / [Γ])
([t] : Γ ⊩ᵛ⟨ l ⟩ t ∷ F / [Γ] / [F])
→ Γ ⊩ᵛ⟨ l ⟩ G [ t ] / [Γ]
substSΠ {F = F} {G} {t} BΠ [Γ] [F] [ΠFG] [t] ⊢Δ [σ] =
let ⊩σΠFG = [ΠFG] ⊢Δ [σ]
--[σΠFG] = PE.subst (λ x → _ ⊩⟨ _ ⟩ x) (B-subst _ W F G) (proj₁ ⊩σΠFG)
[σΠFG] = proj₁ ⊩σΠFG
[σG[t]] = substSΠ₁ BΠ [σΠFG]
(proj₁ ([F] ⊢Δ [σ]))
(proj₁ ([t] ⊢Δ [σ]))
[σG[t]]′ = irrelevance′ (PE.sym (singleSubstLift G t))
[σG[t]]
in [σG[t]]′
, (λ [σ′] [σ≡σ′] →
irrelevanceEq″ (PE.sym (singleSubstLift G t))
(PE.sym (singleSubstLift G t))
[σG[t]] [σG[t]]′
(substSΠ₂ BΠ
[σΠFG]
(proj₂ ⊩σΠFG [σ′] [σ≡σ′])
(proj₁ ([F] ⊢Δ [σ])) (proj₁ ([F] ⊢Δ [σ′]))
(proj₁ ([t] ⊢Δ [σ])) (proj₁ ([t] ⊢Δ [σ′]))
(proj₂ ([t] ⊢Δ [σ]) [σ′] [σ≡σ′]) [σG[t]]
(substSΠ₁ BΠ
(proj₁ ([ΠFG] ⊢Δ [σ′]))
(proj₁ ([F] ⊢Δ [σ′]))
(proj₁ ([t] ⊢Δ [σ′])))))
substSΠ {F = F} {G} {t} BΣ [Γ] [F] [ΠFG] [t] ⊢Δ [σ] =
let ⊩σΠFG = [ΠFG] ⊢Δ [σ]
[σΠFG] = proj₁ ⊩σΠFG
[σG[t]] = substSΠ₁ BΣ [σΠFG]
(proj₁ ([F] ⊢Δ [σ]))
(proj₁ ([t] ⊢Δ [σ]))
[σG[t]]′ = irrelevance′ (PE.sym (singleSubstLift G t))
[σG[t]]
in [σG[t]]′
, (λ [σ′] [σ≡σ′] →
irrelevanceEq″ (PE.sym (singleSubstLift G t))
(PE.sym (singleSubstLift G t))
[σG[t]] [σG[t]]′
(substSΠ₂ BΣ
[σΠFG]
(proj₂ ⊩σΠFG [σ′] [σ≡σ′])
(proj₁ ([F] ⊢Δ [σ])) (proj₁ ([F] ⊢Δ [σ′]))
(proj₁ ([t] ⊢Δ [σ])) (proj₁ ([t] ⊢Δ [σ′]))
(proj₂ ([t] ⊢Δ [σ]) [σ′] [σ≡σ′]) [σG[t]]
(substSΠ₁ BΣ
(proj₁ ([ΠFG] ⊢Δ [σ′]))
(proj₁ ([F] ⊢Δ [σ′]))
(proj₁ ([t] ⊢Δ [σ′])))))
-- Valid substitution of Π-congruence.
substSΠEq : ∀ {F G F′ G′ t u l} W
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([F′] : Γ ⊩ᵛ⟨ l ⟩ F′ / [Γ])
([ΠFG] : Γ ⊩ᵛ⟨ l ⟩ ⟦ W ⟧ F ▹ G / [Γ])
([ΠF′G′] : Γ ⊩ᵛ⟨ l ⟩ ⟦ W ⟧ F′ ▹ G′ / [Γ])
([ΠFG≡ΠF′G′] : Γ ⊩ᵛ⟨ l ⟩ ⟦ W ⟧ F ▹ G ≡ ⟦ W ⟧ F′ ▹ G′ / [Γ] / [ΠFG])
([t] : Γ ⊩ᵛ⟨ l ⟩ t ∷ F / [Γ] / [F])
([u] : Γ ⊩ᵛ⟨ l ⟩ u ∷ F′ / [Γ] / [F′])
([t≡u] : Γ ⊩ᵛ⟨ l ⟩ t ≡ u ∷ F / [Γ] / [F])
→ Γ ⊩ᵛ⟨ l ⟩ G [ t ] ≡ G′ [ u ] / [Γ]
/ substSΠ {F = F} {G} {t} W [Γ] [F] [ΠFG] [t]
substSΠEq {F = F} {G} {F′} {G′} {t} {u} BΠ [Γ] [F] [F′] [ΠFG] [ΠF′G′] [ΠFG≡ΠF′G′]
[t] [u] [t≡u] {Δ = Δ} {σ = σ} ⊢Δ [σ] =
let [σΠFG] = proj₁ ([ΠFG] ⊢Δ [σ])
_ , Bᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁ = extractMaybeEmb (Π-elim [σΠFG])
F≡F₁ , G≡G₁ = B-PE-injectivity BΠ (whnfRed* (red D₁) Πₙ)
[σΠF′G′] = proj₁ ([ΠF′G′] ⊢Δ [σ])
_ , Bᵣ F₂ G₂ D₂ ⊢F₂ ⊢G₂ A≡A₂ [F]₂ [G]₂ G-ext₂ = extractMaybeEmb (Π-elim [σΠF′G′])
F′≡F₂ , G′≡G₂ = B-PE-injectivity BΠ (whnfRed* (red D₂) Πₙ)
[σF] = proj₁ ([F] ⊢Δ [σ])
[σF′] = proj₁ ([F′] ⊢Δ [σ])
[σt] = proj₁ ([t] ⊢Δ [σ])
[σu] = proj₁ ([u] ⊢Δ [σ])
[σt]′ = irrelevanceTerm′ (PE.trans F≡F₁ (PE.sym (wk-id F₁)))
[σF] ([F]₁ id ⊢Δ) [σt]
[σu]′ = irrelevanceTerm′ (PE.trans F′≡F₂ (PE.sym (wk-id F₂)))
[σF′] ([F]₂ id ⊢Δ) [σu]
[σt≡σu] = [t≡u] ⊢Δ [σ]
[G[t]] = irrelevance′ (PE.cong (λ x → x [ subst σ t ])
(PE.trans (wk-lift-id G₁) (PE.sym G≡G₁)))
([G]₁ id ⊢Δ [σt]′)
[G′[u]] = irrelevance′ (PE.cong (λ x → x [ subst σ u ])
(PE.trans (wk-lift-id G₂) (PE.sym G′≡G₂)))
([G]₂ id ⊢Δ [σu]′)
in irrelevanceEq″ (PE.sym (singleSubstLift G t))
(PE.sym (singleSubstLift G′ u))
[G[t]]
(proj₁ (substSΠ {F = F} {G} {t} BΠ [Γ] [F] [ΠFG] [t] ⊢Δ [σ]))
(substSΠ₂ {F = subst σ F} {subst σ F′}
{subst (liftSubst σ) G}
{subst (liftSubst σ) G′}
BΠ
(proj₁ ([ΠFG] ⊢Δ [σ]))
([ΠFG≡ΠF′G′] ⊢Δ [σ])
[σF] [σF′] [σt] [σu] [σt≡σu] [G[t]] [G′[u]])
substSΠEq {F = F} {G} {F′} {G′} {t} {u} BΣ [Γ] [F] [F′] [ΣFG] [ΣF′G′] [ΣFG≡ΣF′G′]
[t] [u] [t≡u] {Δ = Δ} {σ = σ} ⊢Δ [σ] =
let [σΣFG] = proj₁ ([ΣFG] ⊢Δ [σ])
_ , Bᵣ F₁ G₁ D₁ ⊢F₁ ⊢G₁ A≡A₁ [F]₁ [G]₁ G-ext₁ = extractMaybeEmb (Σ-elim [σΣFG])
F≡F₁ , G≡G₁ = B-PE-injectivity BΣ (whnfRed* (red D₁) Σₙ)
[σΣF′G′] = proj₁ ([ΣF′G′] ⊢Δ [σ])
_ , Bᵣ F₂ G₂ D₂ ⊢F₂ ⊢G₂ A≡A₂ [F]₂ [G]₂ G-ext₂ = extractMaybeEmb (Σ-elim [σΣF′G′])
F′≡F₂ , G′≡G₂ = B-PE-injectivity BΣ (whnfRed* (red D₂) Σₙ)
[σF] = proj₁ ([F] ⊢Δ [σ])
[σF′] = proj₁ ([F′] ⊢Δ [σ])
[σt] = proj₁ ([t] ⊢Δ [σ])
[σu] = proj₁ ([u] ⊢Δ [σ])
[σt]′ = irrelevanceTerm′ (PE.trans F≡F₁ (PE.sym (wk-id F₁)))
[σF] ([F]₁ id ⊢Δ) [σt]
[σu]′ = irrelevanceTerm′ (PE.trans F′≡F₂ (PE.sym (wk-id F₂)))
[σF′] ([F]₂ id ⊢Δ) [σu]
[σt≡σu] = [t≡u] ⊢Δ [σ]
[G[t]] = irrelevance′ (PE.cong (λ x → x [ subst σ t ])
(PE.trans (wk-lift-id G₁) (PE.sym G≡G₁)))
([G]₁ id ⊢Δ [σt]′)
[G′[u]] = irrelevance′ (PE.cong (λ x → x [ subst σ u ])
(PE.trans (wk-lift-id G₂) (PE.sym G′≡G₂)))
([G]₂ id ⊢Δ [σu]′)
in irrelevanceEq″ (PE.sym (singleSubstLift G t))
(PE.sym (singleSubstLift G′ u))
[G[t]]
(proj₁ (substSΠ {F = F} {G} {t} BΣ [Γ] [F] [ΣFG] [t] ⊢Δ [σ]))
(substSΠ₂ {F = subst σ F} {subst σ F′}
{subst (liftSubst σ) G}
{subst (liftSubst σ) G′}
BΣ
(proj₁ ([ΣFG] ⊢Δ [σ]))
([ΣFG≡ΣF′G′] ⊢Δ [σ])
[σF] [σF′] [σt] [σu] [σt≡σu] [G[t]] [G′[u]])
| 49.036458
| 102
| 0.353372
|
1b32db3377590157b4966b6744d96767e770d0c2
| 137
|
agda
|
Agda
|
Cubical/Algebra/AbGroup.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
Cubical/Algebra/AbGroup.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | 1
|
2022-01-27T02:07:48.000Z
|
2022-01-27T02:07:48.000Z
|
Cubical/Algebra/AbGroup.agda
|
L-TChen/cubical
|
60226aacd7b386aef95d43a0c29c4eec996348a8
|
[
"MIT"
] | null | null | null |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Algebra.AbGroup where
open import Cubical.Algebra.AbGroup.Base public
| 27.4
| 50
| 0.759124
|
Subsets and Splits
HTML Code Excluding Scripts
The query retrieves a limited set of HTML content entries that are longer than 8 characters and do not contain script tags, offering only basic filtering with minimal analytical value.